bcmsdstd.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * 'Standard' SDIO HOST CONTROLLER driver
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id: bcmsdstd.h 663318 2016-10-04 19:02:16Z $
  30. */
  31. #ifndef _BCM_SD_STD_H
  32. #define _BCM_SD_STD_H
  33. /* global msglevel for debug messages - bitvals come from sdiovar.h */
  34. #define sd_err(x) do { if (sd_msglevel & SDH_ERROR_VAL) printf x; } while (0)
  35. #define sd_trace(x)
  36. #define sd_info(x)
  37. #define sd_debug(x)
  38. #define sd_data(x)
  39. #define sd_ctrl(x)
  40. #define sd_dma(x)
  41. #define sd_sync_dma(sd, read, nbytes)
  42. #define sd_init_dma(sd)
  43. #define sd_ack_intr(sd)
  44. #define sd_wakeup(sd);
  45. /* Allocate/init/free per-OS private data */
  46. extern int sdstd_osinit(sdioh_info_t *sd);
  47. extern void sdstd_osfree(sdioh_info_t *sd);
  48. #define sd_log(x)
  49. #define SDIOH_ASSERT(exp) \
  50. do { if (!(exp)) \
  51. printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \
  52. } while (0)
  53. #define BLOCK_SIZE_4318 64
  54. #define BLOCK_SIZE_4328 512
  55. /* internal return code */
  56. #define SUCCESS 0
  57. #define ERROR 1
  58. /* private bus modes */
  59. #define SDIOH_MODE_SPI 0
  60. #define SDIOH_MODE_SD1 1
  61. #define SDIOH_MODE_SD4 2
  62. #define MAX_SLOTS 6 /* For PCI: Only 6 BAR entries => 6 slots */
  63. #define SDIOH_REG_WINSZ 0x100 /* Number of registers in Standard Host Controller */
  64. #define SDIOH_TYPE_ARASAN_HDK 1
  65. #define SDIOH_TYPE_BCM27XX 2
  66. #define SDIOH_TYPE_TI_PCIXX21 4 /* TI PCIxx21 Standard Host Controller */
  67. #define SDIOH_TYPE_RICOH_R5C822 5 /* Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter */
  68. #define SDIOH_TYPE_JMICRON 6 /* JMicron Standard SDIO Host Controller */
  69. /* For linux, allow yielding for dongle */
  70. #define BCMSDYIELD
  71. /* Expected card status value for CMD7 */
  72. #define SDIOH_CMD7_EXP_STATUS 0x00001E00
  73. #define RETRIES_LARGE 100000
  74. #define sdstd_os_yield(sd) do {} while (0)
  75. #define RETRIES_SMALL 100
  76. #define USE_BLOCKMODE 0x2 /* Block mode can be single block or multi */
  77. #define USE_MULTIBLOCK 0x4
  78. #define USE_FIFO 0x8 /* Fifo vs non-fifo */
  79. #define CLIENT_INTR 0x100 /* Get rid of this! */
  80. #define HC_INTR_RETUNING 0x1000
  81. #ifdef BCMSDIOH_TXGLOM
  82. /* Total glom pkt can not exceed 64K
  83. * need one more slot for glom padding packet
  84. */
  85. #define SDIOH_MAXGLOM_SIZE (40+1)
  86. typedef struct glom_buf {
  87. uint32 count; /* Total number of pkts queued */
  88. void *dma_buf_arr[SDIOH_MAXGLOM_SIZE]; /* Frame address */
  89. ulong dma_phys_arr[SDIOH_MAXGLOM_SIZE]; /* DMA_MAPed address of frames */
  90. uint16 nbytes[SDIOH_MAXGLOM_SIZE]; /* Size of each frame */
  91. } glom_buf_t;
  92. #endif // endif
  93. struct sdioh_info {
  94. uint cfg_bar; /* pci cfg address for bar */
  95. uint32 caps; /* cached value of capabilities reg */
  96. uint32 curr_caps; /* max current capabilities reg */
  97. osl_t *osh; /* osh handler */
  98. volatile char *mem_space; /* pci device memory va */
  99. uint lockcount; /* nest count of sdstd_lock() calls */
  100. bool client_intr_enabled; /* interrupt connnected flag */
  101. bool intr_handler_valid; /* client driver interrupt handler valid */
  102. sdioh_cb_fn_t intr_handler; /* registered interrupt handler */
  103. void *intr_handler_arg; /* argument to call interrupt handler */
  104. bool initialized; /* card initialized */
  105. uint target_dev; /* Target device ID */
  106. uint16 intmask; /* Current active interrupts */
  107. void *sdos_info; /* Pointer to per-OS private data */
  108. void *bcmsdh; /* handler to upper layer stack (bcmsdh) */
  109. uint32 controller_type; /* Host controller type */
  110. uint8 version; /* Host Controller Spec Compliance Version */
  111. uint irq; /* Client irq */
  112. int intrcount; /* Client interrupts */
  113. int local_intrcount; /* Controller interrupts */
  114. bool host_init_done; /* Controller initted */
  115. bool card_init_done; /* Client SDIO interface initted */
  116. bool polled_mode; /* polling for command completion */
  117. bool sd_blockmode; /* sd_blockmode == FALSE => 64 Byte Cmd 53s. */
  118. /* Must be on for sd_multiblock to be effective */
  119. bool use_client_ints; /* If this is false, make sure to restore */
  120. /* polling hack in wl_linux.c:wl_timer() */
  121. int adapter_slot; /* Maybe dealing with multiple slots/controllers */
  122. int sd_mode; /* SD1/SD4/SPI */
  123. int client_block_size[SDIOD_MAX_IOFUNCS]; /* Blocksize */
  124. uint32 data_xfer_count; /* Current transfer */
  125. uint16 card_rca; /* Current Address */
  126. int8 sd_dma_mode; /* DMA Mode (PIO, SDMA, ... ADMA2) on CMD53 */
  127. uint8 num_funcs; /* Supported funcs on client */
  128. uint32 com_cis_ptr;
  129. uint32 func_cis_ptr[SDIOD_MAX_IOFUNCS];
  130. void *dma_buf; /* DMA Buffer virtual address */
  131. ulong dma_phys; /* DMA Buffer physical address */
  132. void *adma2_dscr_buf; /* ADMA2 Descriptor Buffer virtual address */
  133. ulong adma2_dscr_phys; /* ADMA2 Descriptor Buffer physical address */
  134. /* adjustments needed to make the dma align properly */
  135. void *dma_start_buf;
  136. ulong dma_start_phys;
  137. uint alloced_dma_size;
  138. void *adma2_dscr_start_buf;
  139. ulong adma2_dscr_start_phys;
  140. uint alloced_adma2_dscr_size;
  141. int r_cnt; /* rx count */
  142. int t_cnt; /* tx_count */
  143. bool got_hcint; /* local interrupt flag */
  144. uint16 last_intrstatus; /* to cache intrstatus */
  145. int host_UHSISupported; /* whether UHSI is supported for HC. */
  146. int card_UHSI_voltage_Supported; /* whether UHSI is supported for
  147. * Card in terms of Voltage [1.8 or 3.3].
  148. */
  149. int global_UHSI_Supp; /* type of UHSI support in both host and card.
  150. * HOST_SDR_UNSUPP: capabilities not supported/matched
  151. * HOST_SDR_12_25: SDR12 and SDR25 supported
  152. * HOST_SDR_50_104_DDR: one of SDR50/SDR104 or DDR50 supptd
  153. */
  154. volatile int sd3_dat_state; /* data transfer state used for retuning check */
  155. volatile int sd3_tun_state; /* tuning state used for retuning check */
  156. bool sd3_tuning_reqd; /* tuning requirement parameter */
  157. bool sd3_tuning_disable; /* tuning disable due to bus sleeping */
  158. uint32 caps3; /* cached value of 32 MSbits capabilities reg (SDIO 3.0) */
  159. #ifdef BCMSDIOH_TXGLOM
  160. glom_buf_t glom_info; /* pkt information used for glomming */
  161. uint txglom_mode; /* Txglom mode: 0 - copy, 1 - multi-descriptor */
  162. #endif // endif
  163. };
  164. #define DMA_MODE_NONE 0
  165. #define DMA_MODE_SDMA 1
  166. #define DMA_MODE_ADMA1 2
  167. #define DMA_MODE_ADMA2 3
  168. #define DMA_MODE_ADMA2_64 4
  169. #define DMA_MODE_AUTO -1
  170. #define USE_DMA(sd) ((bool)((sd->sd_dma_mode > 0) ? TRUE : FALSE))
  171. /* States for Tuning and corr data */
  172. #define TUNING_IDLE 0
  173. #define TUNING_START 1
  174. #define TUNING_START_AFTER_DAT 2
  175. #define TUNING_ONGOING 3
  176. #define DATA_TRANSFER_IDLE 0
  177. #define DATA_TRANSFER_ONGOING 1
  178. #define CHECK_TUNING_PRE_DATA 1
  179. #define CHECK_TUNING_POST_DATA 2
  180. #ifdef DHD_DEBUG
  181. #define SD_DHD_DISABLE_PERIODIC_TUNING 0x01
  182. #define SD_DHD_ENABLE_PERIODIC_TUNING 0x00
  183. #endif // endif
  184. /************************************************************
  185. * Internal interfaces: per-port references into bcmsdstd.c
  186. */
  187. /* Global message bits */
  188. extern uint sd_msglevel;
  189. /* OS-independent interrupt handler */
  190. extern bool check_client_intr(sdioh_info_t *sd);
  191. /* Core interrupt enable/disable of device interrupts */
  192. extern void sdstd_devintr_on(sdioh_info_t *sd);
  193. extern void sdstd_devintr_off(sdioh_info_t *sd);
  194. /* Enable/disable interrupts for local controller events */
  195. extern void sdstd_intrs_on(sdioh_info_t *sd, uint16 norm, uint16 err);
  196. extern void sdstd_intrs_off(sdioh_info_t *sd, uint16 norm, uint16 err);
  197. /* Wait for specified interrupt and error bits to be set */
  198. extern void sdstd_spinbits(sdioh_info_t *sd, uint16 norm, uint16 err);
  199. /**************************************************************
  200. * Internal interfaces: bcmsdstd.c references to per-port code
  201. */
  202. /* Register mapping routines */
  203. extern uint32 *sdstd_reg_map(osl_t *osh, ulong addr, int size);
  204. extern void sdstd_reg_unmap(osl_t *osh, ulong addr, int size);
  205. /* Interrupt (de)registration routines */
  206. extern int sdstd_register_irq(sdioh_info_t *sd, uint irq);
  207. extern void sdstd_free_irq(uint irq, sdioh_info_t *sd);
  208. /* OS-specific interrupt wrappers (atomic interrupt enable/disable) */
  209. extern void sdstd_lock(sdioh_info_t *sd);
  210. extern void sdstd_unlock(sdioh_info_t *sd);
  211. extern void sdstd_waitlockfree(sdioh_info_t *sd);
  212. /* OS-specific wrappers for safe concurrent register access */
  213. extern void sdstd_os_lock_irqsave(sdioh_info_t *sd, ulong* flags);
  214. extern void sdstd_os_unlock_irqrestore(sdioh_info_t *sd, ulong* flags);
  215. /* OS-specific wait-for-interrupt-or-status */
  216. extern int sdstd_waitbits(sdioh_info_t *sd, uint16 norm, uint16 err, bool yield, uint16 *bits);
  217. /* used by bcmsdstd_linux [implemented in sdstd] */
  218. extern void sdstd_3_enable_retuning_int(sdioh_info_t *sd);
  219. extern void sdstd_3_disable_retuning_int(sdioh_info_t *sd);
  220. extern bool sdstd_3_is_retuning_int_set(sdioh_info_t *sd);
  221. extern void sdstd_3_check_and_do_tuning(sdioh_info_t *sd, int tuning_param);
  222. extern bool sdstd_3_check_and_set_retuning(sdioh_info_t *sd);
  223. extern int sdstd_3_get_tune_state(sdioh_info_t *sd);
  224. extern int sdstd_3_get_data_state(sdioh_info_t *sd);
  225. extern void sdstd_3_set_tune_state(sdioh_info_t *sd, int state);
  226. extern void sdstd_3_set_data_state(sdioh_info_t *sd, int state);
  227. extern uint8 sdstd_3_get_tuning_exp(sdioh_info_t *sd);
  228. extern uint32 sdstd_3_get_uhsi_clkmode(sdioh_info_t *sd);
  229. extern int sdstd_3_clk_tuning(sdioh_info_t *sd, uint32 sd3ClkMode);
  230. /* used by sdstd [implemented in bcmsdstd_linux/ndis] */
  231. extern void sdstd_3_start_tuning(sdioh_info_t *sd);
  232. extern void sdstd_3_osinit_tuning(sdioh_info_t *sd);
  233. extern void sdstd_3_osclean_tuning(sdioh_info_t *sd);
  234. extern void sdstd_enable_disable_periodic_timer(sdioh_info_t * sd, uint val);
  235. extern sdioh_info_t *sdioh_attach(osl_t *osh, void *bar0, uint irq);
  236. extern SDIOH_API_RC sdioh_detach(osl_t *osh, sdioh_info_t *sd);
  237. #endif /* _BCM_SD_STD_H */