hpm_sdmmc_sdio.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. /*
  2. * Copyright (c) 2024 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_SDMMC_SDIO_H
  8. #define HPM_SDMMC_SDIO_H
  9. /**
  10. *
  11. * @brief HPM SDIO driver APIs
  12. * @defgroup hpm_sdmmc HPM SDMMC stack
  13. * @ingroup hpm_sdmmc_interfaces
  14. * @{
  15. *
  16. */
  17. #include <stdint.h>
  18. #include "hpm_sdmmc_common.h"
  19. #define SDIO_CMD53_OP_MODE_FIXED_ADDR 0 /*!< Fixed Address in CMD53 */
  20. #define SDIO_CMD53_OP_MODE_INCR_ADDR 1 /*!< Incremental Address in CMD53 */
  21. #define SDIO_CMD_TIMEOUT_MS (1000UL) /*!< SDIO Command Timeout in milliseconds */
  22. #define SDIO_FBR_REG_BASE(fbr) ((fbr) * 0x100) /*!< FBR base address for specified function */
  23. #define SDIO_MAX_FUNC_NUM 7 /*!< Maximum supported functions */
  24. /**
  25. * @brief SDIO Speed definitions
  26. */
  27. #define SDIO_SPEED_DEFAULT_SPEED 0UL
  28. #define SDIO_SPEED_HIGH_SPEED 1UL
  29. #define SDIO_SPEED_SDR12 SDIO_SPEED_DEFAULT_SPEED
  30. #define SDIO_SPEED_SDR25 SDIO_SPEED_HIGH_SPEED
  31. #define SDIO_SPEED_SDR50 2UL
  32. #define SDIO_SPEED_SDR104 3UL
  33. #define SDIO_SPEED_DDR50 4UL
  34. /**
  35. * @brief SDIO Bus width definitions
  36. */
  37. #define SDIO_CCCR_BUS_WIDTH_1BIT 0UL
  38. #define SDIO_CCCR_BUS_WIDTH_4BIT 2UL
  39. /**
  40. * @brief SDIO BUS speed definitions in CCCR register
  41. */
  42. #define SDIO_CCCR_BUS_SPEED_MASK (0x7UL << 1)
  43. #define SDIO_CCCR_BUS_SPEED_SUPPORT_HIGHSPEED (1)
  44. #define SDIO_CCCR_BUS_SPEED_DEFAULT (SDIO_SPEED_DEFAULT_SPEED << 1)
  45. #define SDIO_CCCR_BUS_SPEED_HIGH (SDIO_SPEED_HIGH_SPEED << 1)
  46. #define SDIO_CCCR_BUS_SPEED_SDR12 (SDIO_CCCR_BUS_SPEED_DEFAULT)
  47. #define SDIO_CCCR_BUS_SPEED_SDR25 (SDIO_CCCR_BUS_SPEED_HIGH)
  48. #define SDIO_CCCR_BUS_SPEED_SDR50 (SDIO_SPEED_SDR50 << 1)
  49. #define SDIO_CCCR_BUS_SPEED_SDR104 (SDIO_SPEED_SDR104 << 1)
  50. #define SDIO_CCCR_BUS_SPEED_DDR50 (SDIO_SPEED_DDR50 << 1)
  51. /**
  52. * @brief CCCR register address
  53. */
  54. #define SDIO_REG_CCCR_SDIO_REV 0
  55. #define SDIO_REG_CCCR_SD_REV 1
  56. #define SDIO_REG_CCCR_IO_ENABLE 2
  57. #define SDIO_REG_CCCR_IO_READY 3
  58. #define SDIO_REG_CCCR_INT_ENABLE 4
  59. #define SDIO_REG_CCCR_INT_PENDING 5
  60. #define SDIO_REG_CCCR_IO_ABORT 6
  61. #define SDIO_REG_CCCR_BUS_IF_CTRL 7
  62. #define SDIO_REG_CCCR_CARD_CAP 8
  63. #define SDIO_REG_CCCR_COM_CIS_PTR 9
  64. #define SDIO_REG_CCCR_BUS_SUSPEND 0xC
  65. #define SDIO_REG_CCCR_FUNC_SEL 0xD
  66. #define SDIO_REG_CCCR_EXEC_FLAGS 0xE
  67. #define SDIO_REG_CCCR_READY_FLAGS 0xF
  68. #define SDIO_REG_CCCR_FN0_BLK_SIZE 0x10
  69. #define SDIO_REG_CCCR_POWER_CTRL 0x12
  70. #define SDIO_REG_CCCR_BUS_SPEED_SEL 0x13
  71. #define SDIO_REG_CCCR_UHS_SUPPORT 0x14
  72. #define SDIO_REG_CCCR_DRV_STRENGTH 0x15
  73. #define SDIO_REG_CCCR_INT_EXT 0x16
  74. /**
  75. * @brief CCCR register range definitions
  76. */
  77. #define SDIO_REG_CCCR_START SDIO_REG_CCCR_SDIO_REV
  78. #define SDIO_REG_CCCR_END SDIO_REG_CCCR_INT_EXT
  79. #define SDIO_REG_FBR_CIS_PTR_OFFSET 0x9
  80. #define SDIO_REG_FBR_CSR_PTR_OFFSET 0xC
  81. #define SDIO_REG_FBR_MAX_BLK_SIZE_OFFSET 0x10
  82. /**
  83. * @brief CISTPL type definitions
  84. */
  85. #define CISTPL_NULL (0)
  86. #define CISTPL_CHECKSUM (0x10)
  87. #define CISTPL_VERS_1 (0x15)
  88. #define CISTPL_ALTSTR (0x16)
  89. #define CISTPL_MANFID (0x20)
  90. #define CISTPL_FUNCID (0x21)
  91. #define CISTPL_FUNCE (0x22)
  92. #define CISTPL_SDIO_STD (0x91)
  93. #define CISTPL_SDIO_EXT (0x92)
  94. #define CISTPL_END (0xFF)
  95. /**
  96. * @brief CMD5 argument definition
  97. */
  98. typedef union {
  99. uint32_t value;
  100. struct {
  101. uint32_t : 8;
  102. uint32_t volt_2p0_2p1: 1;
  103. uint32_t volt_2p1_2p2: 1;
  104. uint32_t volt_2p2_2p3: 1;
  105. uint32_t volt_2p3_2p4: 1;
  106. uint32_t volt_2p4_2p5: 1;
  107. uint32_t volt_2p5_2p6: 1;
  108. uint32_t volt_2p6_2p7: 1;
  109. uint32_t volt_2p7_2p8: 1;
  110. uint32_t volt_2p8_2p9: 1;
  111. uint32_t volt_2p9_3p0: 1;
  112. uint32_t volt_3p0_3p1: 1;
  113. uint32_t volt_3p1_3p2: 1;
  114. uint32_t volt_3p2_3p3: 1;
  115. uint32_t volt_3p3_3p4: 1;
  116. uint32_t volt_3p4_3p5: 1;
  117. uint32_t volt_3p5_3p6: 1;
  118. uint32_t s18r: 1;
  119. uint32_t : 7;
  120. };
  121. } sdio_cmd5_arg_t;
  122. /**
  123. * @brief CMD5 response definition
  124. */
  125. typedef union {
  126. uint32_t value;
  127. struct {
  128. uint32_t : 8;
  129. uint32_t volt_2p0_2p1: 1;
  130. uint32_t volt_2p1_2p2: 1;
  131. uint32_t volt_2p2_2p3: 1;
  132. uint32_t volt_2p3_2p4: 1;
  133. uint32_t volt_2p4_2p5: 1;
  134. uint32_t volt_2p5_2p6: 1;
  135. uint32_t volt_2p6_2p7: 1;
  136. uint32_t volt_2p7_2p8: 1;
  137. uint32_t volt_2p8_2p9: 1;
  138. uint32_t volt_2p9_3p0: 1;
  139. uint32_t volt_3p0_3p1: 1;
  140. uint32_t volt_3p1_3p2: 1;
  141. uint32_t volt_3p2_3p3: 1;
  142. uint32_t volt_3p3_3p4: 1;
  143. uint32_t volt_3p4_3p5: 1;
  144. uint32_t volt_3p5_3p6: 1;
  145. uint32_t s18r: 1;
  146. uint32_t : 2;
  147. uint32_t memory_present: 1;
  148. uint32_t num_func: 3;
  149. uint32_t ready: 1;
  150. };
  151. } sdio_cmd5_resp_t;
  152. /**
  153. * @brief Response R5 definition
  154. */
  155. typedef union {
  156. uint32_t value;
  157. struct {
  158. uint8_t rw_data;
  159. uint8_t err_out_of_range: 1;
  160. uint8_t err_num_func: 1;
  161. uint8_t : 1;
  162. uint8_t err_general: 1;
  163. uint8_t io_current_state: 2;
  164. uint8_t err_illegal_cmd: 1;
  165. uint8_t err_com_crc: 1;
  166. uint8_t stuff[2];
  167. };
  168. } sdio_resp_r5_t;
  169. /**
  170. * @brief CMD5 argument definition
  171. */
  172. typedef union {
  173. uint32_t value;
  174. struct {
  175. uint32_t wr_data: 8;
  176. uint32_t : 1;
  177. uint32_t reg_addr: 17;
  178. uint32_t : 1;
  179. uint32_t read_afer_write: 1;
  180. uint32_t func_num: 3;
  181. uint32_t write: 1;
  182. };
  183. } sdio_cmd52_arg_t;
  184. /**
  185. * @brief CMD53 argument definition
  186. */
  187. typedef union {
  188. uint32_t value;
  189. struct {
  190. uint32_t count: 9;
  191. uint32_t reg_addr: 17;
  192. uint32_t op_code: 1;
  193. uint32_t block_mode: 1;
  194. uint32_t func_num: 3;
  195. uint32_t rw_flag: 1;
  196. };
  197. } sdio_cmd53_arg_t;
  198. /**
  199. * @brief CCCR register map
  200. */
  201. typedef struct {
  202. union {
  203. uint8_t sdio_version; /* offset: 0x00 */
  204. struct {
  205. uint8_t cccr_rev: 4;
  206. uint8_t sdio_rev: 4;
  207. };
  208. };
  209. uint8_t sd_version; /* offset: 0x01 */
  210. uint8_t io_enable; /* offset: 0x02 */
  211. uint8_t io_ready; /* offset: 0x03 */
  212. uint8_t int_enable; /* offset: 0x04 */
  213. uint8_t int_pending; /* offset: 0x05 */
  214. union {
  215. uint8_t io_abort; /* offset: 0x06 */
  216. struct {
  217. uint8_t abort_select: 3;
  218. uint8_t reset: 1;
  219. };
  220. };
  221. union {
  222. uint8_t bus_if_ctrl; /* offset: 0x07 */
  223. struct {
  224. uint8_t bus_width: 2;
  225. uint8_t support_8bit: 1;
  226. uint8_t : 4;
  227. uint8_t cd_disable: 1;
  228. };
  229. };
  230. union {
  231. uint8_t card_capability; /* offset: 0x08 */
  232. struct {
  233. uint8_t support_cmd52: 1;
  234. uint8_t support_multi_block_transfer: 1;
  235. uint8_t support_read_wait: 1;
  236. uint8_t support_bus_control: 1;
  237. uint8_t support_block_gap_interrupt: 1;
  238. uint8_t enable_block_gap_interrupt: 1;
  239. uint8_t low_speed_card: 1;
  240. uint8_t low_speed_card_4bit_mode: 1;
  241. };
  242. };
  243. uint8_t common_cis_pointer[3]; /* offset: 0x08 */
  244. union {
  245. uint8_t bus_suspend; /* offset: 0x0c */
  246. struct {
  247. uint8_t bus_status: 1;
  248. uint8_t bus_release_req: 1;
  249. };
  250. };
  251. uint8_t function_select; /* offset: 0x0d */
  252. uint8_t exec_flags; /* offset: 0x0e */
  253. uint8_t ready_flags; /* offset: 0x0f */
  254. uint8_t fn0_block_size[2]; /* offset: 0x10 */
  255. union {
  256. uint8_t power_control; /* offset: 0x12 */
  257. struct {
  258. uint8_t support_master_pwr_ctrl: 1;
  259. uint8_t enable_master_pwr_ctrl: 1;
  260. };
  261. };
  262. union {
  263. uint8_t bus_speed_select; /* offset: 0x13 */
  264. struct {
  265. uint8_t support_highspeed: 1;
  266. uint8_t bus_speed_sel: 3;
  267. uint8_t : 4;
  268. };
  269. };
  270. union {
  271. uint8_t uhs1_support; /* offset: 0x14 */
  272. struct {
  273. uint8_t support_sdr50: 1;
  274. uint8_t support_sdr104: 1;
  275. uint8_t support_ddr50: 1;
  276. };
  277. };
  278. union {
  279. uint8_t driver_strength; /* offset: 0x15 */
  280. };
  281. union {
  282. uint8_t interrupt_extension; /* offset: 0x16 */
  283. };
  284. } sdio_cccr_t;
  285. /**
  286. * @brief Standard SDIO Function Interface Code Definitions
  287. */
  288. #define STD_SDIO_FUNC_IF_CODE_NON_STD 0
  289. #define STD_SDIO_FUNC_IF_CODE_UART 1
  290. #define STD_SDIO_FUNC_IF_CODE_BT_TYPEA 2
  291. #define STD_SDIO_FUNC_IF_CODE_BT_TYPEB 3
  292. #define STD_SDIO_FUNC_IF_CODE_GPS 4
  293. #define STD_SDIO_FUNC_IF_CODE_CAMERA 5
  294. #define STD_SDIO_FUNC_IF_CODE_PHS 6
  295. #define STD_SDIO_FUNC_IF_CODE_WLAN 7
  296. #define STD_SDIO_FUNC_IF_CODE_ATA 8
  297. #define STD_SDIO_FUNC_IF_CODE_BT_TYPEA_AMP 9
  298. #define STD_SDIO_FUNC_IF_CODE_ISDIO 0xE
  299. #define STD_SDIO_FUNC_IF_CODE_EXT_STD 0xF
  300. /**
  301. * @brief FBR register map
  302. */
  303. typedef struct {
  304. uint8_t std_sdio_func_if_code: 4;
  305. uint8_t : 2;
  306. uint8_t support_csa: 1;
  307. uint8_t csa_enable: 1;
  308. uint8_t ext_std_sdio_func_if_code;
  309. uint8_t support_pwr_sel: 1;
  310. uint8_t enable_pwr_sel: 1;
  311. uint8_t : 2;
  312. uint8_t pwr_sel: 4;
  313. uint8_t std_isdio_func_if_code;
  314. uint16_t sda_mid_manf;
  315. uint16_t mid_card;
  316. uint8_t isdio_type_support_code;
  317. uint8_t cis_ptr[3];
  318. uint8_t csa_ptr[3];
  319. uint8_t data_acc_win_to_csa;
  320. uint16_t io_blk_size;
  321. } sdio_fbr_t;
  322. /**
  323. * @brief TPL block structure
  324. */
  325. typedef struct sdio_tpl_block {
  326. struct sdio_tpl_block *next;
  327. uint8_t tpl_code;
  328. uint8_t tpl_size;
  329. uint8_t *tpl_data;
  330. } *sdio_tpl_blk_t;
  331. /**
  332. * @brief SDIO Common In
  333. */
  334. typedef struct {
  335. sdio_tpl_blk_t tpl_link;
  336. } sdio_common_cis_t;
  337. /**
  338. * @brief SDIO Function extension structure
  339. */
  340. typedef struct {
  341. union {
  342. uint8_t func_info;
  343. struct {
  344. uint8_t support_wakeup: 1;
  345. uint8_t : 7;
  346. };
  347. };
  348. uint8_t std_io_rev;
  349. uint32_t psn;
  350. uint32_t csa_size;
  351. union {
  352. uint8_t csa_property;
  353. struct {
  354. uint8_t csa_wp: 1;
  355. uint8_t csa_nf: 1;
  356. uint8_t : 6;
  357. };
  358. };
  359. uint16_t max_blk_size;
  360. uint32_t ocr;
  361. uint8_t op_min_pwr;
  362. uint8_t op_avg_pwr;
  363. uint8_t op_max_pwr;
  364. uint8_t sb_min_pwr;
  365. uint8_t sb_avg_pwr;
  366. uint8_t sb_max_pwr;
  367. uint16_t min_bw;
  368. uint16_t opt_bw;
  369. uint16_t enable_timeout_val;
  370. uint16_t sp_avg_pwr_3v3;
  371. uint16_t sp_max_pwr_3v3;
  372. uint16_t hp_avg_pwr_3v3;
  373. uint16_t hp_max_pwr_3v3;
  374. uint16_t lp_avg_pwr_3v3;
  375. uint16_t lp_max_pwr_3v3;
  376. }
  377. ATTR_PACKED sdio_func_funce_t;
  378. /**
  379. * @brief SDIO CIS information
  380. */
  381. typedef struct {
  382. union {
  383. struct {
  384. uint16_t manufacturer;
  385. uint16_t product;
  386. uint16_t func0_blk_size;
  387. uint8_t max_tran_speed;
  388. };
  389. struct {
  390. uint8_t std_id;
  391. uint8_t std_type;
  392. bool support_wakeup;
  393. uint8_t std_io_rev;
  394. uint16_t max_blk_size;
  395. uint16_t timeout_val_in_10ms;
  396. bool csa_wp;
  397. bool csa_nf;
  398. uint32_t serial_num;
  399. uint32_t csa_size;
  400. uint32_t ocr;
  401. };
  402. };
  403. sdio_tpl_blk_t tpl_link;
  404. } sdio_cis_t;
  405. typedef struct _sdmmc_sdio sdio_card_t;
  406. /**
  407. * @brief SDIO Function information
  408. */
  409. typedef struct {
  410. sdio_card_t *card;
  411. uint8_t func_idx;
  412. uint32_t max_block_size;
  413. uint32_t current_block_size;
  414. uint8_t std_sdio_func_if_code;
  415. sdio_cis_t cis;
  416. sdio_fbr_t fbr;
  417. } sdio_func_t;
  418. /**
  419. * @brief SDIO Card context
  420. */
  421. struct _sdmmc_sdio {
  422. sdmmc_host_t *host;
  423. bool is_host_ready;
  424. sdmmc_operation_voltage_t operation_voltage;
  425. sdmmc_speed_mode_t current_timing;
  426. uint8_t num_of_functions;
  427. uint16_t relative_addr;
  428. uint32_t max_tran_speed_in_kbps;
  429. sdio_cccr_t cccr;
  430. sdio_cis_t common_cis;
  431. sdio_func_t *sdio_func[SDIO_MAX_FUNC_NUM + 1];
  432. };
  433. #ifdef __cplusplus
  434. extern "C" {
  435. #endif
  436. /**
  437. * @brief Get the CIS register address from raw register value
  438. * @param [in] reg_ptr Pointer to the register value
  439. * @return Converted CIS CSR address
  440. */
  441. static inline uint32_t sdio_cis_csr_addr(const uint8_t *reg_ptr)
  442. {
  443. uint32_t reg_addr = 0;
  444. for (uint32_t i = 0; i < 3; i++) {
  445. reg_addr |= ((uint32_t) reg_ptr[i]) << (i * 8);
  446. }
  447. return reg_addr;
  448. }
  449. /**
  450. * @brief Initialize SDIO device
  451. * @param [in,out] SDIO card context
  452. * @return SDIO device initialization status
  453. */
  454. hpm_stat_t sdio_init(sdio_card_t *card);
  455. /**
  456. * @brief De-initialize SDIO device
  457. * @param [in,out] SDIO card context
  458. */
  459. void sdio_deinit(sdio_card_t *card);
  460. /**
  461. * @brief Initialize SDIO card
  462. * @param [in,out] SDIO card context
  463. * @return SDIO card initialization status
  464. */
  465. hpm_stat_t sdio_card_init(sdio_card_t *card);
  466. /**
  467. * @brief De-Initialize SDIO card
  468. * @param [in,out] SDIO card context
  469. * @return SDIO card initialization status
  470. */
  471. hpm_stat_t sdio_card_deinit(sdio_card_t *card);
  472. /**
  473. * @brief Initialize SDIO host
  474. * @param [in,out] SDIO card context
  475. */
  476. hpm_stat_t sdio_host_init(sdio_card_t *card);
  477. /**
  478. * @brief De-initialize SDIO host
  479. * @param [in,out] SDIO card context
  480. *
  481. * @return De-initialization status
  482. */
  483. hpm_stat_t sdio_host_deinit(sdio_card_t *card);
  484. /**
  485. * @brief Execute SDIO_IO_RW_DIRECT command (CMD52)
  486. * @param [in,out] card SDIO card context
  487. * @param [in] write true: write, false: read
  488. * @param [in] func_idx SDIO function index
  489. * @param [in] reg_addr Register address
  490. * @param [in/out] pdata pass in data if write is true or read_after_write is true, output data if write is false
  491. * @param [in] read_after_write true: read data after write
  492. *
  493. * @return SDIO_IO_RW_DIRECT command status
  494. */
  495. hpm_stat_t sdio_io_rw_direct(sdio_card_t *card,
  496. bool write,
  497. uint32_t func_idx,
  498. uint32_t reg_addr,
  499. uint8_t *pdata,
  500. bool read_after_write);
  501. /**
  502. * @brief Set the Block size for specified Function
  503. * @param [in,out] card SDIO card context
  504. * @param [in] func_idx SDIO function index
  505. * @param [in] block_size Block size
  506. *
  507. * @return Command execution status
  508. */
  509. hpm_stat_t sdio_set_block_size(sdio_card_t *card, uint32_t func_idx, uint32_t block_size);
  510. /**
  511. * @brief Execute SDIO_IO_RW_EXTEND command (CMD53)
  512. * @param [in,out] card SDIO card context
  513. * @param [in] write true: write, false: read
  514. * @param [in] func_idx SDIO function index
  515. * @param [in] reg_addr Register address
  516. * @param [in] op_code Operation code, SDIO_CMD53_OP_MODE_FIXED_ADDR or SDIO_CMD53_OP_MODE_INCR_ADDR
  517. * @param [in,out] pbuf Pointer to data buffer
  518. * @param [in] blocks Number of blocks to be transferred
  519. * @param [in] block_size Block size in bytes
  520. *
  521. * @return Command execution status
  522. */
  523. hpm_stat_t sdio_io_rw_extend(sdio_card_t *card,
  524. bool write,
  525. uint32_t func_idx,
  526. uint32_t reg_addr,
  527. uint32_t op_code,
  528. uint8_t *pbuf,
  529. uint32_t blocks,
  530. uint32_t block_size);
  531. /**
  532. * @brief Write multiple bytes to the FIFO address for specified SDIO Function
  533. * @param [in,out] card SDIO card context
  534. * @param [in] func_idx SDIO function index
  535. * @param [in] reg_addr Register address
  536. * @param [in,out] pbuf Pointer to data buffer
  537. * @param [in] length bytes to be written
  538. *
  539. * @return Command execution status
  540. */
  541. hpm_stat_t sdio_io_write_multi_bytes_to_fifo(sdio_card_t *card,
  542. uint32_t func_idx,
  543. uint32_t reg_addr,
  544. uint8_t *pbuf,
  545. uint32_t length);
  546. /**
  547. * @brief Read multiple bytes from the FIFO address for specified SDIO Function
  548. * @param [in,out] card SDIO card context
  549. * @param [in] func_idx SDIO function index
  550. * @param [in] reg_addr Register address
  551. * @param [in,out] pbuf Pointer to data buffer
  552. * @param [in] length bytes to be read
  553. *
  554. * @return Command execution status
  555. */
  556. hpm_stat_t sdio_io_read_multi_bytes_from_fifo(sdio_card_t *card,
  557. uint32_t func_idx,
  558. uint32_t reg_addr,
  559. uint8_t *pbuf,
  560. uint32_t length);
  561. /**
  562. * @brief Write multiple bytes to the address for specified SDIO Function
  563. * @param [in,out] SDIO card context
  564. * @param [in] func_idx SDIO function index
  565. * @param [in] reg_addr Register address
  566. * @param [in,out] pbuf Pointer to data buffer
  567. * @param [in] length bytes to be written
  568. *
  569. * @return Command execution status
  570. */
  571. hpm_stat_t sdio_io_write_incr_multi_bytes(sdio_card_t *card,
  572. uint32_t func_idx,
  573. uint32_t reg_addr,
  574. uint8_t *pbuf,
  575. uint32_t length);
  576. /**
  577. * @brief Read multiple bytes from the address for specified SDIO Function
  578. * @param [in,out] card SDIO card context
  579. * @param [in] func_idx SDIO function index
  580. * @param [in] reg_addr Register address
  581. * @param [in,out] pbuf Pointer to data buffer
  582. * @param [in] length bytes to be read
  583. *
  584. * @return Command execution status
  585. */
  586. hpm_stat_t sdio_io_read_incr_multi_bytes(sdio_card_t *card,
  587. uint32_t func_idx,
  588. uint32_t reg_addr,
  589. uint8_t *pbuf,
  590. uint32_t length);
  591. /**
  592. * @brief Read 1 byte from the address for specified SDIO Function
  593. * @param [in,out] card SDIO card context
  594. * @param [in] func_idx SDIO function index
  595. * @param [in] reg_addr Register address
  596. * @param [out] pdata Pointer to data buffer
  597. *
  598. * @return Command execution status
  599. */
  600. hpm_stat_t sdio_io_read_byte(sdio_card_t *card, uint32_t func_idx, uint32_t reg_addr, uint8_t *pdata);
  601. /**
  602. * @brief Write 1 byte to the address for specified SDIO Function
  603. * @param [in,out] card SDIO card context
  604. * @param [in] func_idx SDIO function index
  605. * @param [in] reg_addr Register address
  606. * @param [in] byte_data data to be written
  607. *
  608. * @return Command execution status
  609. */
  610. hpm_stat_t sdio_io_write_byte(sdio_card_t *card, uint32_t func_idx, uint32_t reg_addr, uint8_t byte_data);
  611. /**
  612. * @brief Get the string for specified function interface code
  613. * @param [in] std_func_if_code Standard function interface code
  614. *
  615. * @return string for the specified function interface code
  616. */
  617. const char *sdio_get_func_if_code_str(uint8_t std_func_if_code);
  618. /**
  619. * @brief Read the specified Function Basic Register
  620. * @param [in,out] card SDIO card context
  621. * @param [in] func_idx SDIO function index
  622. * @param [out] fbr Pointer to FBR buffer
  623. *
  624. * @return Command execution status
  625. */
  626. hpm_stat_t sdio_read_fbr(sdio_card_t *card, uint32_t func_idx, sdio_fbr_t *fbr);
  627. /**
  628. * @brief Read Card Information Structure (CIS)
  629. * @param [in,out] card SDIO card context
  630. * @param [in] cis_ptr CIS pointer
  631. * @param [out] cis CIS buffer
  632. * @param [in] keep_tpl_raw_data true: keep the raw data of TPL, false: discard the raw data of TPL
  633. *
  634. * @return Command execution status
  635. */
  636. hpm_stat_t sdio_read_cis(sdio_card_t *card, uint32_t cis_ptr, sdio_cis_t *cis, bool keep_tpl_raw_data);
  637. /**
  638. * @brief Get the maximum transfer speed
  639. *
  640. * @param [in] card SDIO card context
  641. *
  642. * @return Command execution status
  643. */
  644. hpm_stat_t sdio_get_max_transfer_speed(sdio_card_t *card);
  645. /**
  646. * @brief Initialize SDIO functions
  647. * @param [in,out] card SDIO card context
  648. *
  649. * @return Command execution status
  650. */
  651. hpm_stat_t sdio_init_funcs(sdio_card_t *card);
  652. /**
  653. * @brief De-Initialize SDIO functions
  654. * @param [in,out] card SDIO card context
  655. *
  656. * @return Command execution status
  657. */
  658. hpm_stat_t sdio_deinit_funcs(sdio_card_t *card);
  659. /**
  660. * @brief Enables SDIO interrupts for the specified card.
  661. *
  662. * This function activates the SDIO interrupts by utilizing the host controller.
  663. * It is essential to ensure that the card and its associated host controller
  664. * are properly initialized before calling this function.
  665. *
  666. * @param [in,out] card A pointer to the sdio_card_t structure representing the SDIO card.
  667. * Must not be NULL and should have a valid host controller pointer.
  668. *
  669. * @return hpm_stat_t: Status of the operation.
  670. * - status_success: Interrupts were successfully enabled.
  671. * - status_invalid_argument: If the card pointer or its host controller is NULL.
  672. */
  673. hpm_stat_t sdio_enable_interrupt(sdio_card_t *card);
  674. /**
  675. * @brief Disables SDIO interrupts for the specified card.
  676. *
  677. * This function disables the SDIO interrupts associated with the given SDIO card.
  678. * It ensures that the card and its host are valid before proceeding to disable the interrupts.
  679. *
  680. * @param [in,out] card A pointer to the sdio_card_t structure representing the SDIO card.
  681. * @return Returns status_success if the interrupts were successfully disabled, or
  682. * status_invalid_argument if the card or its host is not properly initialized.
  683. */
  684. hpm_stat_t sdio_disable_interrupt(sdio_card_t *card);
  685. /**
  686. * @brief Registers an interrupt callback function for an SDIO card.
  687. *
  688. * This function allows the user to register a callback that will be invoked when an SDIO interrupt occurs.
  689. * The provided callback function should be designed to handle SDIO-specific events or data associated with the interrupt.
  690. *
  691. * @param [in,out] card A pointer to the SDIO card context structure. Must not be NULL.
  692. * @param [in] sdio_irq_callback A pointer to the user-defined interrupt callback function. This function will be called when an SDIO interrupt is detected.
  693. * The function signature should match `void (*)(void *)`, where the parameter is a generic pointer provided by the user.
  694. * @param [in] sdio_irq_param A pointer to any user-defined data that needs to be passed to the interrupt callback function. Can be NULL if no data needs to be passed.
  695. * @return hpm_stat_t: Status of the registration operation.
  696. * - status_success: Callback successfully registered.
  697. * - status_invalid_argument: If the card pointer is NULL or the card host is not initialized.
  698. *
  699. * @Note Ensure the SDIO card and host controller are properly initialized before calling this function.
  700. */
  701. hpm_stat_t sdio_register_irq_callback(sdio_card_t *card,
  702. void (*sdio_irq_callback)(void *param),
  703. void *sdio_irq_param);
  704. /*
  705. * @}
  706. */
  707. #ifdef __cplusplus
  708. }
  709. #endif
  710. #endif /* HPM_SDMMC_SDIO_H */