sdio_host.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef _BRCM_SDH_H_
  17. #define _BRCM_SDH_H_
  18. #include <linux/skbuff.h>
  19. #define SDIO_FUNC_0 0
  20. #define SDIO_FUNC_1 1
  21. #define SDIO_FUNC_2 2
  22. #define SDIOD_FBR_SIZE 0x100
  23. /* io_en */
  24. #define SDIO_FUNC_ENABLE_1 0x02
  25. #define SDIO_FUNC_ENABLE_2 0x04
  26. /* io_rdys */
  27. #define SDIO_FUNC_READY_1 0x02
  28. #define SDIO_FUNC_READY_2 0x04
  29. /* intr_status */
  30. #define INTR_STATUS_FUNC1 0x2
  31. #define INTR_STATUS_FUNC2 0x4
  32. /* Maximum number of I/O funcs */
  33. #define SDIOD_MAX_IOFUNCS 7
  34. /* mask of register map */
  35. #define REG_F0_REG_MASK 0x7FF
  36. #define REG_F1_MISC_MASK 0x1FFFF
  37. /* as of sdiod rev 0, supports 3 functions */
  38. #define SBSDIO_NUM_FUNCTION 3
  39. /* function 0 vendor specific CCCR registers */
  40. #define SDIO_CCCR_BRCM_CARDCAP 0xf0
  41. #define SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT 0x02
  42. #define SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT 0x04
  43. #define SDIO_CCCR_BRCM_CARDCAP_CMD_NODEC 0x08
  44. #define SDIO_CCCR_BRCM_CARDCTRL 0xf1
  45. #define SDIO_CCCR_BRCM_CARDCTRL_WLANRESET 0x02
  46. #define SDIO_CCCR_BRCM_SEPINT 0xf2
  47. #define SDIO_SEPINT_MASK 0x01
  48. #define SDIO_SEPINT_OE 0x02
  49. #define SDIO_SEPINT_ACT_HI 0x04
  50. /* function 1 miscellaneous registers */
  51. /* sprom command and status */
  52. #define SBSDIO_SPROM_CS 0x10000
  53. /* sprom info register */
  54. #define SBSDIO_SPROM_INFO 0x10001
  55. /* sprom indirect access data byte 0 */
  56. #define SBSDIO_SPROM_DATA_LOW 0x10002
  57. /* sprom indirect access data byte 1 */
  58. #define SBSDIO_SPROM_DATA_HIGH 0x10003
  59. /* sprom indirect access addr byte 0 */
  60. #define SBSDIO_SPROM_ADDR_LOW 0x10004
  61. /* sprom indirect access addr byte 0 */
  62. #define SBSDIO_SPROM_ADDR_HIGH 0x10005
  63. /* xtal_pu (gpio) output */
  64. #define SBSDIO_CHIP_CTRL_DATA 0x10006
  65. /* xtal_pu (gpio) enable */
  66. #define SBSDIO_CHIP_CTRL_EN 0x10007
  67. /* rev < 7, watermark for sdio device */
  68. #define SBSDIO_WATERMARK 0x10008
  69. /* control busy signal generation */
  70. #define SBSDIO_DEVICE_CTL 0x10009
  71. /* SB Address Window Low (b15) */
  72. #define SBSDIO_FUNC1_SBADDRLOW 0x1000A
  73. /* SB Address Window Mid (b23:b16) */
  74. #define SBSDIO_FUNC1_SBADDRMID 0x1000B
  75. /* SB Address Window High (b31:b24) */
  76. #define SBSDIO_FUNC1_SBADDRHIGH 0x1000C
  77. /* Frame Control (frame term/abort) */
  78. #define SBSDIO_FUNC1_FRAMECTRL 0x1000D
  79. /* ChipClockCSR (ALP/HT ctl/status) */
  80. #define SBSDIO_FUNC1_CHIPCLKCSR 0x1000E
  81. /* SdioPullUp (on cmd, d0-d2) */
  82. #define SBSDIO_FUNC1_SDIOPULLUP 0x1000F
  83. /* Write Frame Byte Count Low */
  84. #define SBSDIO_FUNC1_WFRAMEBCLO 0x10019
  85. /* Write Frame Byte Count High */
  86. #define SBSDIO_FUNC1_WFRAMEBCHI 0x1001A
  87. /* Read Frame Byte Count Low */
  88. #define SBSDIO_FUNC1_RFRAMEBCLO 0x1001B
  89. /* Read Frame Byte Count High */
  90. #define SBSDIO_FUNC1_RFRAMEBCHI 0x1001C
  91. /* MesBusyCtl (rev 11) */
  92. #define SBSDIO_FUNC1_MESBUSYCTRL 0x1001D
  93. /* Sdio Core Rev 12 */
  94. #define SBSDIO_FUNC1_WAKEUPCTRL 0x1001E
  95. #define SBSDIO_FUNC1_WCTRL_ALPWAIT_MASK 0x1
  96. #define SBSDIO_FUNC1_WCTRL_ALPWAIT_SHIFT 0
  97. #define SBSDIO_FUNC1_WCTRL_HTWAIT_MASK 0x2
  98. #define SBSDIO_FUNC1_WCTRL_HTWAIT_SHIFT 1
  99. #define SBSDIO_FUNC1_SLEEPCSR 0x1001F
  100. #define SBSDIO_FUNC1_SLEEPCSR_KSO_MASK 0x1
  101. #define SBSDIO_FUNC1_SLEEPCSR_KSO_SHIFT 0
  102. #define SBSDIO_FUNC1_SLEEPCSR_KSO_EN 1
  103. #define SBSDIO_FUNC1_SLEEPCSR_DEVON_MASK 0x2
  104. #define SBSDIO_FUNC1_SLEEPCSR_DEVON_SHIFT 1
  105. #define SBSDIO_FUNC1_MISC_REG_START 0x10000 /* f1 misc register start */
  106. #define SBSDIO_FUNC1_MISC_REG_LIMIT 0x1001F /* f1 misc register end */
  107. /* function 1 OCP space */
  108. /* sb offset addr is <= 15 bits, 32k */
  109. #define SBSDIO_SB_OFT_ADDR_MASK 0x07FFF
  110. #define SBSDIO_SB_OFT_ADDR_LIMIT 0x08000
  111. /* with b15, maps to 32-bit SB access */
  112. #define SBSDIO_SB_ACCESS_2_4B_FLAG 0x08000
  113. /* valid bits in SBSDIO_FUNC1_SBADDRxxx regs */
  114. #define SBSDIO_SBADDRLOW_MASK 0x80 /* Valid bits in SBADDRLOW */
  115. #define SBSDIO_SBADDRMID_MASK 0xff /* Valid bits in SBADDRMID */
  116. #define SBSDIO_SBADDRHIGH_MASK 0xffU /* Valid bits in SBADDRHIGH */
  117. /* Address bits from SBADDR regs */
  118. #define SBSDIO_SBWINDOW_MASK 0xffff8000
  119. #define SDIOH_READ 0 /* Read request */
  120. #define SDIOH_WRITE 1 /* Write request */
  121. #define SDIOH_DATA_FIX 0 /* Fixed addressing */
  122. #define SDIOH_DATA_INC 1 /* Incremental addressing */
  123. /* internal return code */
  124. #define SUCCESS 0
  125. #define ERROR 1
  126. /* Packet alignment for most efficient SDIO (can change based on platform) */
  127. #define BRCMF_SDALIGN (1 << 6)
  128. /* watchdog polling interval in ms */
  129. #define BRCMF_WD_POLL_MS 10
  130. struct brcmf_sdreg {
  131. int func;
  132. int offset;
  133. int value;
  134. };
  135. struct brcmf_sdio;
  136. struct brcmf_sdio_dev {
  137. struct sdio_func *func[SDIO_MAX_FUNCS];
  138. u8 num_funcs; /* Supported funcs on client */
  139. u32 func_cis_ptr[SDIOD_MAX_IOFUNCS];
  140. u32 sbwad; /* Save backplane window address */
  141. void *bus;
  142. atomic_t suspend; /* suspend flag */
  143. wait_queue_head_t request_byte_wait;
  144. wait_queue_head_t request_word_wait;
  145. wait_queue_head_t request_buffer_wait;
  146. struct device *dev;
  147. struct brcmf_bus *bus_if;
  148. struct brcmfmac_sdio_platform_data *pdata;
  149. bool oob_irq_requested;
  150. bool irq_en; /* irq enable flags */
  151. spinlock_t irq_en_lock;
  152. bool irq_wake; /* irq wake enable flags */
  153. };
  154. /* Register/deregister interrupt handler. */
  155. extern int brcmf_sdio_intr_register(struct brcmf_sdio_dev *sdiodev);
  156. extern int brcmf_sdio_intr_unregister(struct brcmf_sdio_dev *sdiodev);
  157. /* sdio device register access interface */
  158. extern u8 brcmf_sdio_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret);
  159. extern u32 brcmf_sdio_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret);
  160. extern void brcmf_sdio_regwb(struct brcmf_sdio_dev *sdiodev, u32 addr,
  161. u8 data, int *ret);
  162. extern void brcmf_sdio_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr,
  163. u32 data, int *ret);
  164. extern int brcmf_sdio_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr,
  165. void *data, bool write);
  166. /* Buffer transfer to/from device (client) core via cmd53.
  167. * fn: function number
  168. * addr: backplane address (i.e. >= regsva from attach)
  169. * flags: backplane width, address increment, sync/async
  170. * buf: pointer to memory data buffer
  171. * nbytes: number of bytes to transfer to/from buf
  172. * pkt: pointer to packet associated with buf (if any)
  173. * complete: callback function for command completion (async only)
  174. * handle: handle for completion callback (first arg in callback)
  175. * Returns 0 or error code.
  176. * NOTE: Async operation is not currently supported.
  177. */
  178. extern int
  179. brcmf_sdcard_send_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
  180. uint flags, struct sk_buff_head *pktq);
  181. extern int
  182. brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
  183. uint flags, u8 *buf, uint nbytes);
  184. extern int
  185. brcmf_sdcard_recv_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
  186. uint flags, struct sk_buff *pkt);
  187. extern int
  188. brcmf_sdcard_recv_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
  189. uint flags, u8 *buf, uint nbytes);
  190. extern int
  191. brcmf_sdcard_recv_chain(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
  192. uint flags, struct sk_buff_head *pktq);
  193. /* Flags bits */
  194. /* Four-byte target (backplane) width (vs. two-byte) */
  195. #define SDIO_REQ_4BYTE 0x1
  196. /* Fixed address (FIFO) (vs. incrementing address) */
  197. #define SDIO_REQ_FIXED 0x2
  198. /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
  199. * rw: read or write (0/1)
  200. * addr: direct SDIO address
  201. * buf: pointer to memory data buffer
  202. * nbytes: number of bytes to transfer to/from buf
  203. * Returns 0 or error code.
  204. */
  205. extern int brcmf_sdcard_rwdata(struct brcmf_sdio_dev *sdiodev, uint rw,
  206. u32 addr, u8 *buf, uint nbytes);
  207. extern int brcmf_sdio_ramrw(struct brcmf_sdio_dev *sdiodev, bool write,
  208. u32 address, u8 *data, uint size);
  209. /* Issue an abort to the specified function */
  210. extern int brcmf_sdcard_abort(struct brcmf_sdio_dev *sdiodev, uint fn);
  211. /* platform specific/high level functions */
  212. extern int brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev);
  213. extern int brcmf_sdio_remove(struct brcmf_sdio_dev *sdiodev);
  214. /* attach, return handler on success, NULL if failed.
  215. * The handler shall be provided by all subsequent calls. No local cache
  216. * cfghdl points to the starting address of pci device mapped memory
  217. */
  218. extern int brcmf_sdioh_attach(struct brcmf_sdio_dev *sdiodev);
  219. extern void brcmf_sdioh_detach(struct brcmf_sdio_dev *sdiodev);
  220. /* read or write one byte using cmd52 */
  221. extern int brcmf_sdioh_request_byte(struct brcmf_sdio_dev *sdiodev, uint rw,
  222. uint fnc, uint addr, u8 *byte);
  223. /* read or write 2/4 bytes using cmd53 */
  224. extern int
  225. brcmf_sdioh_request_word(struct brcmf_sdio_dev *sdiodev,
  226. uint rw, uint fnc, uint addr,
  227. u32 *word, uint nbyte);
  228. /* Watchdog timer interface for pm ops */
  229. extern void brcmf_sdio_wdtmr_enable(struct brcmf_sdio_dev *sdiodev,
  230. bool enable);
  231. extern void *brcmf_sdbrcm_probe(u32 regsva, struct brcmf_sdio_dev *sdiodev);
  232. extern void brcmf_sdbrcm_disconnect(void *ptr);
  233. extern void brcmf_sdbrcm_isr(void *arg);
  234. extern void brcmf_sdbrcm_wd_timer(struct brcmf_sdio *bus, uint wdtick);
  235. extern void brcmf_pm_resume_wait(struct brcmf_sdio_dev *sdiodev,
  236. wait_queue_head_t *wq);
  237. extern bool brcmf_pm_resume_error(struct brcmf_sdio_dev *sdiodev);
  238. #endif /* _BRCM_SDH_H_ */