bcmsdh.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * SDIO host client driver interface of Broadcom HNBU
  3. * export functions to client drivers
  4. * abstract OS and BUS specific details of SDIO
  5. *
  6. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  7. *
  8. * Copyright (C) 1999-2020, Broadcom Corporation
  9. *
  10. * Unless you and Broadcom execute a separate written software license
  11. * agreement governing use of this software, this software is licensed to you
  12. * under the terms of the GNU General Public License version 2 (the "GPL"),
  13. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  14. * following added to such license:
  15. *
  16. * As a special exception, the copyright holders of this software give you
  17. * permission to link this software with independent modules, and to copy and
  18. * distribute the resulting executable under terms of your choice, provided that
  19. * you also meet, for each linked independent module, the terms and conditions of
  20. * the license of that module. An independent module is a module which is not
  21. * derived from this software. The special exception does not apply to any
  22. * modifications of the software.
  23. *
  24. * Notwithstanding the above, under no circumstances may you combine this
  25. * software in any way with any other Broadcom software provided under a license
  26. * other than the GPL, without Broadcom's express prior written consent.
  27. *
  28. *
  29. * <<Broadcom-WL-IPTag/Open:>>
  30. *
  31. * $Id: bcmsdh.h 690946 2017-03-20 05:24:19Z $
  32. */
  33. /**
  34. * @file bcmsdh.h
  35. */
  36. #ifndef _bcmsdh_h_
  37. #define _bcmsdh_h_
  38. #define BCMSDH_ERROR_VAL 0x0001 /* Error */
  39. #define BCMSDH_INFO_VAL 0x0002 /* Info */
  40. extern const uint bcmsdh_msglevel;
  41. #define BCMSDH_ERROR(x)
  42. #define BCMSDH_INFO(x)
  43. #if defined(BCMSDIO) && (defined(BCMSDIOH_STD) || defined(BCMSDIOH_BCM) || \
  44. defined(BCMSDIOH_SPI))
  45. #define BCMSDH_ADAPTER
  46. #endif /* BCMSDIO && (BCMSDIOH_STD || BCMSDIOH_BCM || BCMSDIOH_SPI) */
  47. /* forward declarations */
  48. typedef struct bcmsdh_info bcmsdh_info_t;
  49. typedef void (*bcmsdh_cb_fn_t)(void *);
  50. #if defined(BT_OVER_SDIO)
  51. typedef enum {
  52. NO_HANG_STATE = 0,
  53. HANG_START_STATE = 1,
  54. HANG_RECOVERY_STATE = 2
  55. } dhd_hang_state_t;
  56. #endif // endif
  57. extern bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *sdioh, ulong *regsva);
  58. /**
  59. * BCMSDH API context
  60. */
  61. struct bcmsdh_info
  62. {
  63. bool init_success; /* underlying driver successfully attached */
  64. void *sdioh; /* handler for sdioh */
  65. uint32 vendevid; /* Target Vendor and Device ID on SD bus */
  66. osl_t *osh;
  67. bool regfail; /* Save status of last reg_read/reg_write call */
  68. uint32 sbwad; /* Save backplane window address */
  69. void *os_cxt; /* Pointer to per-OS private data */
  70. bool force_sbwad_calc; /* forces calculation of sbwad instead of using cached value */
  71. };
  72. /* Detach - freeup resources allocated in attach */
  73. extern int bcmsdh_detach(osl_t *osh, void *sdh);
  74. /* Query if SD device interrupts are enabled */
  75. extern bool bcmsdh_intr_query(void *sdh);
  76. /* Enable/disable SD interrupt */
  77. extern int bcmsdh_intr_enable(void *sdh);
  78. extern int bcmsdh_intr_disable(void *sdh);
  79. /* Register/deregister device interrupt handler. */
  80. extern int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
  81. extern int bcmsdh_intr_dereg(void *sdh);
  82. /* Enable/disable SD card interrupt forward */
  83. extern void bcmsdh_intr_forward(void *sdh, bool pass);
  84. #if defined(DHD_DEBUG)
  85. /* Query pending interrupt status from the host controller */
  86. extern bool bcmsdh_intr_pending(void *sdh);
  87. #endif // endif
  88. /* Register a callback to be called if and when bcmsdh detects
  89. * device removal. No-op in the case of non-removable/hardwired devices.
  90. */
  91. extern int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
  92. /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
  93. * fn: function number
  94. * addr: unmodified SDIO-space address
  95. * data: data byte to write
  96. * err: pointer to error code (or NULL)
  97. */
  98. extern uint8 bcmsdh_cfg_read(void *sdh, uint func, uint32 addr, int *err);
  99. extern void bcmsdh_cfg_write(void *sdh, uint func, uint32 addr, uint8 data, int *err);
  100. /* Read/Write 4bytes from/to cfg space */
  101. extern uint32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, uint32 addr, int *err);
  102. extern void bcmsdh_cfg_write_word(void *sdh, uint fnc_num, uint32 addr, uint32 data, int *err);
  103. /* Read CIS content for specified function.
  104. * fn: function whose CIS is being requested (0 is common CIS)
  105. * cis: pointer to memory location to place results
  106. * length: number of bytes to read
  107. * Internally, this routine uses the values from the cis base regs (0x9-0xB)
  108. * to form an SDIO-space address to read the data from.
  109. */
  110. extern int bcmsdh_cis_read(void *sdh, uint func, uint8 *cis, uint length);
  111. /* Synchronous access to device (client) core registers via CMD53 to F1.
  112. * addr: backplane address (i.e. >= regsva from attach)
  113. * size: register width in bytes (2 or 4)
  114. * data: data for register write
  115. */
  116. extern uint32 bcmsdh_reg_read(void *sdh, uintptr addr, uint size);
  117. extern uint32 bcmsdh_reg_write(void *sdh, uintptr addr, uint size, uint32 data);
  118. /* set sb address window */
  119. extern int bcmsdhsdio_set_sbaddr_window(void *sdh, uint32 address, bool force_set);
  120. /* Indicate if last reg read/write failed */
  121. extern bool bcmsdh_regfail(void *sdh);
  122. /* Buffer transfer to/from device (client) core via cmd53.
  123. * fn: function number
  124. * addr: backplane address (i.e. >= regsva from attach)
  125. * flags: backplane width, address increment, sync/async
  126. * buf: pointer to memory data buffer
  127. * nbytes: number of bytes to transfer to/from buf
  128. * pkt: pointer to packet associated with buf (if any)
  129. * complete: callback function for command completion (async only)
  130. * handle: handle for completion callback (first arg in callback)
  131. * Returns 0 or error code.
  132. * NOTE: Async operation is not currently supported.
  133. */
  134. typedef void (*bcmsdh_cmplt_fn_t)(void *handle, int status, bool sync_waiting);
  135. extern int bcmsdh_send_buf(void *sdh, uint32 addr, uint fn, uint flags,
  136. uint8 *buf, uint nbytes, void *pkt,
  137. bcmsdh_cmplt_fn_t complete_fn, void *handle);
  138. extern int bcmsdh_recv_buf(void *sdh, uint32 addr, uint fn, uint flags,
  139. uint8 *buf, uint nbytes, void *pkt,
  140. bcmsdh_cmplt_fn_t complete_fn, void *handle);
  141. extern void bcmsdh_glom_post(void *sdh, uint8 *frame, void *pkt, uint len);
  142. extern void bcmsdh_glom_clear(void *sdh);
  143. extern uint bcmsdh_set_mode(void *sdh, uint mode);
  144. extern bool bcmsdh_glom_enabled(void);
  145. /* Flags bits */
  146. #define SDIO_REQ_4BYTE 0x1 /* Four-byte target (backplane) width (vs. two-byte) */
  147. #define SDIO_REQ_FIXED 0x2 /* Fixed address (FIFO) (vs. incrementing address) */
  148. #define SDIO_REQ_ASYNC 0x4 /* Async request (vs. sync request) */
  149. #define SDIO_BYTE_MODE 0x8 /* Byte mode request(non-block mode) */
  150. /* Pending (non-error) return code */
  151. #define BCME_PENDING 1
  152. /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
  153. * rw: read or write (0/1)
  154. * addr: direct SDIO address
  155. * buf: pointer to memory data buffer
  156. * nbytes: number of bytes to transfer to/from buf
  157. * Returns 0 or error code.
  158. */
  159. extern int bcmsdh_rwdata(void *sdh, uint rw, uint32 addr, uint8 *buf, uint nbytes);
  160. /* Issue an abort to the specified function */
  161. extern int bcmsdh_abort(void *sdh, uint fn);
  162. /* Start SDIO Host Controller communication */
  163. extern int bcmsdh_start(void *sdh, int stage);
  164. /* Stop SDIO Host Controller communication */
  165. extern int bcmsdh_stop(void *sdh);
  166. /* Wait system lock free */
  167. extern int bcmsdh_waitlockfree(void *sdh);
  168. /* Returns the "Device ID" of target device on the SDIO bus. */
  169. extern int bcmsdh_query_device(void *sdh);
  170. /* Returns the number of IO functions reported by the device */
  171. extern uint bcmsdh_query_iofnum(void *sdh);
  172. /* Miscellaneous knob tweaker. */
  173. extern int bcmsdh_iovar_op(void *sdh, const char *name,
  174. void *params, uint plen, void *arg, uint len, bool set);
  175. /* Reset and reinitialize the device */
  176. extern int bcmsdh_reset(bcmsdh_info_t *sdh);
  177. /* helper functions */
  178. /* callback functions */
  179. typedef struct {
  180. /* probe the device */
  181. void *(*probe)(uint16 vend_id, uint16 dev_id, uint16 bus, uint16 slot,
  182. uint16 func, uint bustype, void * regsva, osl_t * osh,
  183. void * param);
  184. /* remove the device */
  185. void (*remove)(void *context);
  186. /* can we suspend now */
  187. int (*suspend)(void *context);
  188. /* resume from suspend */
  189. int (*resume)(void *context);
  190. } bcmsdh_driver_t;
  191. /* platform specific/high level functions */
  192. extern int bcmsdh_register(bcmsdh_driver_t *driver);
  193. extern void bcmsdh_unregister(void);
  194. extern bool bcmsdh_chipmatch(uint16 vendor, uint16 device);
  195. extern void bcmsdh_device_remove(void * sdh);
  196. extern int bcmsdh_reg_sdio_notify(void* semaphore);
  197. extern void bcmsdh_unreg_sdio_notify(void);
  198. #if defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID)
  199. extern int bcmsdh_oob_intr_register(bcmsdh_info_t *bcmsdh, bcmsdh_cb_fn_t oob_irq_handler,
  200. void* oob_irq_handler_context);
  201. extern void bcmsdh_oob_intr_unregister(bcmsdh_info_t *sdh);
  202. extern void bcmsdh_oob_intr_set(bcmsdh_info_t *sdh, bool enable);
  203. #endif /* defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) */
  204. extern void bcmsdh_dev_pm_stay_awake(bcmsdh_info_t *sdh);
  205. extern void bcmsdh_dev_relax(bcmsdh_info_t *sdh);
  206. extern bool bcmsdh_dev_pm_enabled(bcmsdh_info_t *sdh);
  207. int bcmsdh_suspend(bcmsdh_info_t *bcmsdh);
  208. int bcmsdh_resume(bcmsdh_info_t *bcmsdh);
  209. /* Function to pass device-status bits to DHD. */
  210. extern uint32 bcmsdh_get_dstatus(void *sdh);
  211. /* Function to return current window addr */
  212. extern uint32 bcmsdh_cur_sbwad(void *sdh);
  213. /* function to force sbwad calculation instead of using cached value */
  214. extern void bcmsdh_force_sbwad_calc(void *sdh, bool force);
  215. /* Function to pass chipid and rev to lower layers for controlling pr's */
  216. extern void bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev);
  217. #ifdef BCMSPI
  218. extern void bcmsdh_dwordmode(void *sdh, bool set);
  219. #endif /* BCMSPI */
  220. extern int bcmsdh_sleep(void *sdh, bool enab);
  221. /* GPIO support */
  222. extern int bcmsdh_gpio_init(void *sd);
  223. extern bool bcmsdh_gpioin(void *sd, uint32 gpio);
  224. extern int bcmsdh_gpioouten(void *sd, uint32 gpio);
  225. extern int bcmsdh_gpioout(void *sd, uint32 gpio, bool enab);
  226. #endif /* _bcmsdh_h_ */