sdio_host.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. /* as of sdiod rev 0, supports 3 functions */
  35. #define SBSDIO_NUM_FUNCTION 3
  36. /* function 1 miscellaneous registers */
  37. /* sprom command and status */
  38. #define SBSDIO_SPROM_CS 0x10000
  39. /* sprom info register */
  40. #define SBSDIO_SPROM_INFO 0x10001
  41. /* sprom indirect access data byte 0 */
  42. #define SBSDIO_SPROM_DATA_LOW 0x10002
  43. /* sprom indirect access data byte 1 */
  44. #define SBSDIO_SPROM_DATA_HIGH 0x10003
  45. /* sprom indirect access addr byte 0 */
  46. #define SBSDIO_SPROM_ADDR_LOW 0x10004
  47. /* sprom indirect access addr byte 0 */
  48. #define SBSDIO_SPROM_ADDR_HIGH 0x10005
  49. /* xtal_pu (gpio) output */
  50. #define SBSDIO_CHIP_CTRL_DATA 0x10006
  51. /* xtal_pu (gpio) enable */
  52. #define SBSDIO_CHIP_CTRL_EN 0x10007
  53. /* rev < 7, watermark for sdio device */
  54. #define SBSDIO_WATERMARK 0x10008
  55. /* control busy signal generation */
  56. #define SBSDIO_DEVICE_CTL 0x10009
  57. /* SB Address Window Low (b15) */
  58. #define SBSDIO_FUNC1_SBADDRLOW 0x1000A
  59. /* SB Address Window Mid (b23:b16) */
  60. #define SBSDIO_FUNC1_SBADDRMID 0x1000B
  61. /* SB Address Window High (b31:b24) */
  62. #define SBSDIO_FUNC1_SBADDRHIGH 0x1000C
  63. /* Frame Control (frame term/abort) */
  64. #define SBSDIO_FUNC1_FRAMECTRL 0x1000D
  65. /* ChipClockCSR (ALP/HT ctl/status) */
  66. #define SBSDIO_FUNC1_CHIPCLKCSR 0x1000E
  67. /* SdioPullUp (on cmd, d0-d2) */
  68. #define SBSDIO_FUNC1_SDIOPULLUP 0x1000F
  69. /* Write Frame Byte Count Low */
  70. #define SBSDIO_FUNC1_WFRAMEBCLO 0x10019
  71. /* Write Frame Byte Count High */
  72. #define SBSDIO_FUNC1_WFRAMEBCHI 0x1001A
  73. /* Read Frame Byte Count Low */
  74. #define SBSDIO_FUNC1_RFRAMEBCLO 0x1001B
  75. /* Read Frame Byte Count High */
  76. #define SBSDIO_FUNC1_RFRAMEBCHI 0x1001C
  77. #define SBSDIO_FUNC1_MISC_REG_START 0x10000 /* f1 misc register start */
  78. #define SBSDIO_FUNC1_MISC_REG_LIMIT 0x1001C /* f1 misc register end */
  79. /* function 1 OCP space */
  80. /* sb offset addr is <= 15 bits, 32k */
  81. #define SBSDIO_SB_OFT_ADDR_MASK 0x07FFF
  82. #define SBSDIO_SB_OFT_ADDR_LIMIT 0x08000
  83. /* with b15, maps to 32-bit SB access */
  84. #define SBSDIO_SB_ACCESS_2_4B_FLAG 0x08000
  85. /* valid bits in SBSDIO_FUNC1_SBADDRxxx regs */
  86. #define SBSDIO_SBADDRLOW_MASK 0x80 /* Valid bits in SBADDRLOW */
  87. #define SBSDIO_SBADDRMID_MASK 0xff /* Valid bits in SBADDRMID */
  88. #define SBSDIO_SBADDRHIGH_MASK 0xffU /* Valid bits in SBADDRHIGH */
  89. /* Address bits from SBADDR regs */
  90. #define SBSDIO_SBWINDOW_MASK 0xffff8000
  91. #define SDIOH_READ 0 /* Read request */
  92. #define SDIOH_WRITE 1 /* Write request */
  93. #define SDIOH_DATA_FIX 0 /* Fixed addressing */
  94. #define SDIOH_DATA_INC 1 /* Incremental addressing */
  95. /* internal return code */
  96. #define SUCCESS 0
  97. #define ERROR 1
  98. struct brcmf_sdreg {
  99. int func;
  100. int offset;
  101. int value;
  102. };
  103. struct brcmf_sdio_dev {
  104. struct sdio_func *func[SDIO_MAX_FUNCS];
  105. u8 num_funcs; /* Supported funcs on client */
  106. u32 func_cis_ptr[SDIOD_MAX_IOFUNCS];
  107. u32 sbwad; /* Save backplane window address */
  108. bool regfail; /* status of last reg_r/w call */
  109. void *bus;
  110. atomic_t suspend; /* suspend flag */
  111. wait_queue_head_t request_byte_wait;
  112. wait_queue_head_t request_word_wait;
  113. wait_queue_head_t request_chain_wait;
  114. wait_queue_head_t request_buffer_wait;
  115. struct device *dev;
  116. };
  117. /* Register/deregister device interrupt handler. */
  118. extern int
  119. brcmf_sdcard_intr_reg(struct brcmf_sdio_dev *sdiodev);
  120. extern int brcmf_sdcard_intr_dereg(struct brcmf_sdio_dev *sdiodev);
  121. /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
  122. * fn: function number
  123. * addr: unmodified SDIO-space address
  124. * data: data byte to write
  125. * err: pointer to error code (or NULL)
  126. */
  127. extern u8 brcmf_sdcard_cfg_read(struct brcmf_sdio_dev *sdiodev, uint func,
  128. u32 addr, int *err);
  129. extern void brcmf_sdcard_cfg_write(struct brcmf_sdio_dev *sdiodev, uint func,
  130. u32 addr, u8 data, int *err);
  131. /* Synchronous access to device (client) core registers via CMD53 to F1.
  132. * addr: backplane address (i.e. >= regsva from attach)
  133. * size: register width in bytes (2 or 4)
  134. * data: data for register write
  135. */
  136. extern u32
  137. brcmf_sdcard_reg_read(struct brcmf_sdio_dev *sdiodev, u32 addr, uint size);
  138. extern u32
  139. brcmf_sdcard_reg_write(struct brcmf_sdio_dev *sdiodev, u32 addr, uint size,
  140. u32 data);
  141. /* Indicate if last reg read/write failed */
  142. extern bool brcmf_sdcard_regfail(struct brcmf_sdio_dev *sdiodev);
  143. /* Buffer transfer to/from device (client) core via cmd53.
  144. * fn: function number
  145. * addr: backplane address (i.e. >= regsva from attach)
  146. * flags: backplane width, address increment, sync/async
  147. * buf: pointer to memory data buffer
  148. * nbytes: number of bytes to transfer to/from buf
  149. * pkt: pointer to packet associated with buf (if any)
  150. * complete: callback function for command completion (async only)
  151. * handle: handle for completion callback (first arg in callback)
  152. * Returns 0 or error code.
  153. * NOTE: Async operation is not currently supported.
  154. */
  155. extern int
  156. brcmf_sdcard_send_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
  157. uint flags, struct sk_buff *pkt);
  158. extern int
  159. brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
  160. uint flags, u8 *buf, uint nbytes);
  161. extern int
  162. brcmf_sdcard_recv_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
  163. uint flags, struct sk_buff *pkt);
  164. extern int
  165. brcmf_sdcard_recv_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
  166. uint flags, u8 *buf, uint nbytes);
  167. extern int
  168. brcmf_sdcard_recv_chain(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
  169. uint flags, struct sk_buff_head *pktq);
  170. /* Flags bits */
  171. /* Four-byte target (backplane) width (vs. two-byte) */
  172. #define SDIO_REQ_4BYTE 0x1
  173. /* Fixed address (FIFO) (vs. incrementing address) */
  174. #define SDIO_REQ_FIXED 0x2
  175. /* Async request (vs. sync request) */
  176. #define SDIO_REQ_ASYNC 0x4
  177. /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
  178. * rw: read or write (0/1)
  179. * addr: direct SDIO address
  180. * buf: pointer to memory data buffer
  181. * nbytes: number of bytes to transfer to/from buf
  182. * Returns 0 or error code.
  183. */
  184. extern int brcmf_sdcard_rwdata(struct brcmf_sdio_dev *sdiodev, uint rw,
  185. u32 addr, u8 *buf, uint nbytes);
  186. /* Issue an abort to the specified function */
  187. extern int brcmf_sdcard_abort(struct brcmf_sdio_dev *sdiodev, uint fn);
  188. /* platform specific/high level functions */
  189. extern int brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev);
  190. extern int brcmf_sdio_remove(struct brcmf_sdio_dev *sdiodev);
  191. extern int brcmf_sdcard_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev,
  192. u32 address);
  193. /* attach, return handler on success, NULL if failed.
  194. * The handler shall be provided by all subsequent calls. No local cache
  195. * cfghdl points to the starting address of pci device mapped memory
  196. */
  197. extern int brcmf_sdioh_attach(struct brcmf_sdio_dev *sdiodev);
  198. extern void brcmf_sdioh_detach(struct brcmf_sdio_dev *sdiodev);
  199. /* read or write one byte using cmd52 */
  200. extern int brcmf_sdioh_request_byte(struct brcmf_sdio_dev *sdiodev, uint rw,
  201. uint fnc, uint addr, u8 *byte);
  202. /* read or write 2/4 bytes using cmd53 */
  203. extern int
  204. brcmf_sdioh_request_word(struct brcmf_sdio_dev *sdiodev,
  205. uint rw, uint fnc, uint addr,
  206. u32 *word, uint nbyte);
  207. /* read or write any buffer using cmd53 */
  208. extern int
  209. brcmf_sdioh_request_buffer(struct brcmf_sdio_dev *sdiodev,
  210. uint fix_inc, uint rw, uint fnc_num, u32 addr,
  211. struct sk_buff *pkt);
  212. extern int
  213. brcmf_sdioh_request_chain(struct brcmf_sdio_dev *sdiodev, uint fix_inc,
  214. uint write, uint func, uint addr,
  215. struct sk_buff_head *pktq);
  216. /* Watchdog timer interface for pm ops */
  217. extern void brcmf_sdio_wdtmr_enable(struct brcmf_sdio_dev *sdiodev,
  218. bool enable);
  219. extern void *brcmf_sdbrcm_probe(u32 regsva, struct brcmf_sdio_dev *sdiodev);
  220. extern void brcmf_sdbrcm_disconnect(void *ptr);
  221. extern void brcmf_sdbrcm_isr(void *arg);
  222. #endif /* _BRCM_SDH_H_ */