1 /* 2 * Copyright 2008-2024 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 /*! \file mlan_sdio_api.h 9 * \brief SDIO Driver 10 * 11 * The SDIO driver is used to configure and do 12 * data transfer over the SDIO interface 13 * 14 * \section mlan_sdio_usage Usage 15 * 16 * Steps to use sdio with mlan: 17 * 18 * 1. Register gpio using \ref sdio_drv_init() 19 * 20 * 2. Open the device using sdio_drv_open() call. 21 * This will return a handler to gpio. 22 * 23 * 3. To do various SDIO related operations: 24 * 25 * - sdio_drv_write() : Write using CMD53 26 * - sdio_drv_read() : Read using CMD53 27 * - sdio_drv_creg_write() : Write using CMD52 28 * - sdio_drv_creg_read() : Read using CMD52 29 * 30 * Locking mechanism is implemented to provide atomic access. 31 * 32 * 4. Close the device using sdio_drv_close() call. 33 */ 34 35 #ifndef _MLAN_SDIO_API_H_ 36 #define _MLAN_SDIO_API_H_ 37 38 #include <wmlog.h> 39 40 #define sdio_e(...) wmlog_e("sdio", ##__VA_ARGS__) 41 42 #if CONFIG_WIFI_SDIO_DEBUG 43 #define sdio_d(...) wmlog("sdio", ##__VA_ARGS__) 44 #else 45 #define sdio_d(...) 46 #endif /* CONFIG_WIFI_SDIO_DEBUG */ 47 48 #define SDIO_GO_IDLE_STATE ((uint8_t)0) 49 #define SDIO_SET_REL_ADDR ((uint8_t)3) 50 #define SDIO_SDIO_SEN_OP_COND ((uint8_t)5) 51 #define SDIO_SEL_DESEL_CARD ((uint8_t)7) 52 #define SDIO_RW_DIRECT ((uint8_t)52) 53 #define SDIO_RW_DIRECT_EXTENDED ((uint8_t)53) 54 55 /* Depends on DMA_BUFSZ */ 56 #define DMA_BOUNDARY_SIZE (512 * 1024) 57 58 /** Read Card Register 59 * 60 * This is used to read card register using CMD52. 61 * This is a blocking call. 62 * 63 * \param addr Card Register Address 64 * \param fn Number of the function with the Card 65 * \param resp Response of CMD52 66 * \return true on success, false otherwise 67 */ 68 int sdio_drv_creg_read(int addr, int fn, uint32_t *resp); 69 70 /** Write to Card Register 71 * 72 * This is used to write to card register using CMD52. 73 * This is a blocking call. 74 * 75 * \param addr Card Register Address 76 * \param fn Number of the function with the Card 77 * \param data value to be written on register 78 * \param resp Response of CMD52 79 * \return true on success, false otherwise 80 */ 81 int sdio_drv_creg_write(int addr, int fn, uint8_t data, uint32_t *resp); 82 83 /** Read Data from SDIO 84 * 85 * This is used to read data from SDIO card using CMD53. 86 * This is a blocking call. 87 * 88 * \param addr Card Register Address 89 * \param fn Number of the function with the Card 90 * \param bcnt Number of blocks to be read 91 * \param bsize Size of each block 92 * \param buf Buffer to read the data into 93 * \param resp Response of CMD53 94 * \return true on success, false otherwise 95 */ 96 int sdio_drv_read(uint32_t addr, uint32_t fn, uint32_t bcnt, uint32_t bsize, uint8_t *buf, uint32_t *resp); 97 98 #if FSL_USDHC_ENABLE_SCATTER_GATHER_TRANSFER 99 void sg_init_table(); 100 void sg_set_num(size_t num_sg); 101 void sg_set_buf(uint32_t *buf, size_t len); 102 int sdio_drv_read_mb(uint32_t addr, uint32_t fn, uint32_t bcnt, uint32_t bsize); 103 #endif 104 105 /** Write Data to SDIO 106 * 107 * This is used to write data to SDIO card using CMD53. 108 * This is a blocking call. 109 * 110 * \param addr Card Register Address 111 * \param fn Number of the function with the Card 112 * \param bcnt Number of blocks to be written 113 * \param bsize Size of each block 114 * \param buf Buffer to write the data into 115 * \param resp Response of CMD53 116 * \return true on success, false otherwise 117 */ 118 int sdio_drv_write(uint32_t addr, uint32_t fn, uint32_t bcnt, uint32_t bsize, uint8_t *buf, uint32_t *resp); 119 120 /** Initialize the SDIO Driver 121 * 122 * This should be called once before using the driver. 123 * The callback for Card Interrupt can be registered using this call. 124 * 125 * \param cd_int Callback for Card Detect Interrupt 126 * \return WM_SUCCESS or -WM_FAIL 127 */ 128 int sdio_drv_init(void (*cd_int)(int)); 129 130 /** Deinitialize the SDIO Driver 131 * 132 * \return void 133 */ 134 void sdio_drv_deinit(void); 135 136 #endif /* !_MDEV_SDIO_API_H_ */ 137