sdio.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 BRCMFMAC_SDIO_H
  17. #define BRCMFMAC_SDIO_H
  18. #include <linux/skbuff.h>
  19. #include <linux/firmware.h>
  20. #include "firmware.h"
  21. #define SDIOD_FBR_SIZE 0x100
  22. /* io_en */
  23. #define SDIO_FUNC_ENABLE_1 0x02
  24. #define SDIO_FUNC_ENABLE_2 0x04
  25. /* io_rdys */
  26. #define SDIO_FUNC_READY_1 0x02
  27. #define SDIO_FUNC_READY_2 0x04
  28. /* intr_status */
  29. #define INTR_STATUS_FUNC1 0x2
  30. #define INTR_STATUS_FUNC2 0x4
  31. /* mask of register map */
  32. #define REG_F0_REG_MASK 0x7FF
  33. #define REG_F1_MISC_MASK 0x1FFFF
  34. /* function 0 vendor specific CCCR registers */
  35. #define SDIO_CCCR_BRCM_CARDCAP 0xf0
  36. #define SDIO_CCCR_BRCM_CARDCAP_CMD14_SUPPORT BIT(1)
  37. #define SDIO_CCCR_BRCM_CARDCAP_CMD14_EXT BIT(2)
  38. #define SDIO_CCCR_BRCM_CARDCAP_CMD_NODEC BIT(3)
  39. /* Interrupt enable bits for each function */
  40. #define SDIO_CCCR_IEN_FUNC0 BIT(0)
  41. #define SDIO_CCCR_IEN_FUNC1 BIT(1)
  42. #define SDIO_CCCR_IEN_FUNC2 BIT(2)
  43. #define SDIO_CCCR_BRCM_CARDCTRL 0xf1
  44. #define SDIO_CCCR_BRCM_CARDCTRL_WLANRESET BIT(1)
  45. #define SDIO_CCCR_BRCM_SEPINT 0xf2
  46. #define SDIO_CCCR_BRCM_SEPINT_MASK BIT(0)
  47. #define SDIO_CCCR_BRCM_SEPINT_OE BIT(1)
  48. #define SDIO_CCCR_BRCM_SEPINT_ACT_HI BIT(2)
  49. /* function 1 miscellaneous registers */
  50. /* sprom command and status */
  51. #define SBSDIO_SPROM_CS 0x10000
  52. /* sprom info register */
  53. #define SBSDIO_SPROM_INFO 0x10001
  54. /* sprom indirect access data byte 0 */
  55. #define SBSDIO_SPROM_DATA_LOW 0x10002
  56. /* sprom indirect access data byte 1 */
  57. #define SBSDIO_SPROM_DATA_HIGH 0x10003
  58. /* sprom indirect access addr byte 0 */
  59. #define SBSDIO_SPROM_ADDR_LOW 0x10004
  60. /* gpio select */
  61. #define SBSDIO_GPIO_SELECT 0x10005
  62. /* gpio output */
  63. #define SBSDIO_GPIO_OUT 0x10006
  64. /* gpio enable */
  65. #define SBSDIO_GPIO_EN 0x10007
  66. /* rev < 7, watermark for sdio device TX path */
  67. #define SBSDIO_WATERMARK 0x10008
  68. /* control busy signal generation */
  69. #define SBSDIO_DEVICE_CTL 0x10009
  70. /* SB Address Window Low (b15) */
  71. #define SBSDIO_FUNC1_SBADDRLOW 0x1000A
  72. /* SB Address Window Mid (b23:b16) */
  73. #define SBSDIO_FUNC1_SBADDRMID 0x1000B
  74. /* SB Address Window High (b31:b24) */
  75. #define SBSDIO_FUNC1_SBADDRHIGH 0x1000C
  76. /* Frame Control (frame term/abort) */
  77. #define SBSDIO_FUNC1_FRAMECTRL 0x1000D
  78. /* ChipClockCSR (ALP/HT ctl/status) */
  79. #define SBSDIO_FUNC1_CHIPCLKCSR 0x1000E
  80. /* SdioPullUp (on cmd, d0-d2) */
  81. #define SBSDIO_FUNC1_SDIOPULLUP 0x1000F
  82. /* Write Frame Byte Count Low */
  83. #define SBSDIO_FUNC1_WFRAMEBCLO 0x10019
  84. /* Write Frame Byte Count High */
  85. #define SBSDIO_FUNC1_WFRAMEBCHI 0x1001A
  86. /* Read Frame Byte Count Low */
  87. #define SBSDIO_FUNC1_RFRAMEBCLO 0x1001B
  88. /* Read Frame Byte Count High */
  89. #define SBSDIO_FUNC1_RFRAMEBCHI 0x1001C
  90. /* MesBusyCtl (rev 11) */
  91. #define SBSDIO_FUNC1_MESBUSYCTRL 0x1001D
  92. /* Watermark for sdio device RX path */
  93. #define SBSDIO_MESBUSY_RXFIFO_WM_MASK 0x7F
  94. #define SBSDIO_MESBUSY_RXFIFO_WM_SHIFT 0
  95. /* Enable busy capability for MES access */
  96. #define SBSDIO_MESBUSYCTRL_ENAB 0x80
  97. #define SBSDIO_MESBUSYCTRL_ENAB_SHIFT 7
  98. /* Sdio Core Rev 12 */
  99. #define SBSDIO_FUNC1_WAKEUPCTRL 0x1001E
  100. #define SBSDIO_FUNC1_WCTRL_ALPWAIT_MASK 0x1
  101. #define SBSDIO_FUNC1_WCTRL_ALPWAIT_SHIFT 0
  102. #define SBSDIO_FUNC1_WCTRL_HTWAIT_MASK 0x2
  103. #define SBSDIO_FUNC1_WCTRL_HTWAIT_SHIFT 1
  104. #define SBSDIO_FUNC1_SLEEPCSR 0x1001F
  105. #define SBSDIO_FUNC1_SLEEPCSR_KSO_MASK 0x1
  106. #define SBSDIO_FUNC1_SLEEPCSR_KSO_SHIFT 0
  107. #define SBSDIO_FUNC1_SLEEPCSR_KSO_EN 1
  108. #define SBSDIO_FUNC1_SLEEPCSR_DEVON_MASK 0x2
  109. #define SBSDIO_FUNC1_SLEEPCSR_DEVON_SHIFT 1
  110. #define SBSDIO_FUNC1_MISC_REG_START 0x10000 /* f1 misc register start */
  111. #define SBSDIO_FUNC1_MISC_REG_LIMIT 0x1001F /* f1 misc register end */
  112. /* function 1 OCP space */
  113. /* sb offset addr is <= 15 bits, 32k */
  114. #define SBSDIO_SB_OFT_ADDR_MASK 0x07FFF
  115. #define SBSDIO_SB_OFT_ADDR_LIMIT 0x08000
  116. /* with b15, maps to 32-bit SB access */
  117. #define SBSDIO_SB_ACCESS_2_4B_FLAG 0x08000
  118. /* Address bits from SBADDR regs */
  119. #define SBSDIO_SBWINDOW_MASK 0xffff8000
  120. #define SDIOH_READ 0 /* Read request */
  121. #define SDIOH_WRITE 1 /* Write request */
  122. #define SDIOH_DATA_FIX 0 /* Fixed addressing */
  123. #define SDIOH_DATA_INC 1 /* Incremental addressing */
  124. /* internal return code */
  125. #define SUCCESS 0
  126. #define ERROR 1
  127. /* Packet alignment for most efficient SDIO (can change based on platform) */
  128. #define BRCMF_SDALIGN (1 << 6)
  129. /* watchdog polling interval */
  130. #define BRCMF_WD_POLL msecs_to_jiffies(10)
  131. /**
  132. * enum brcmf_sdiod_state - the state of the bus.
  133. *
  134. * @BRCMF_SDIOD_DOWN: Device can be accessed, no DPC.
  135. * @BRCMF_SDIOD_DATA: Ready for data transfers, DPC enabled.
  136. * @BRCMF_SDIOD_NOMEDIUM: No medium access to dongle possible.
  137. */
  138. enum brcmf_sdiod_state {
  139. BRCMF_SDIOD_DOWN,
  140. BRCMF_SDIOD_DATA,
  141. BRCMF_SDIOD_NOMEDIUM
  142. };
  143. struct brcmf_sdreg {
  144. int func;
  145. int offset;
  146. int value;
  147. };
  148. struct brcmf_sdio;
  149. struct brcmf_sdiod_freezer;
  150. struct brcmf_sdio_dev {
  151. struct sdio_func *func1;
  152. struct sdio_func *func2;
  153. u32 sbwad; /* Save backplane window address */
  154. struct brcmf_core *cc_core; /* chipcommon core info struct */
  155. struct brcmf_sdio *bus;
  156. struct device *dev;
  157. struct brcmf_bus *bus_if;
  158. struct brcmf_mp_device *settings;
  159. bool oob_irq_requested;
  160. bool sd_irq_requested;
  161. bool irq_en; /* irq enable flags */
  162. spinlock_t irq_en_lock;
  163. bool irq_wake; /* irq wake enable flags */
  164. bool sg_support;
  165. uint max_request_size;
  166. ushort max_segment_count;
  167. uint max_segment_size;
  168. uint txglomsz;
  169. struct sg_table sgtable;
  170. char fw_name[BRCMF_FW_NAME_LEN];
  171. char nvram_name[BRCMF_FW_NAME_LEN];
  172. bool wowl_enabled;
  173. enum brcmf_sdiod_state state;
  174. struct brcmf_sdiod_freezer *freezer;
  175. };
  176. /* sdio core registers */
  177. struct sdpcmd_regs {
  178. u32 corecontrol; /* 0x00, rev8 */
  179. u32 corestatus; /* rev8 */
  180. u32 PAD[1];
  181. u32 biststatus; /* rev8 */
  182. /* PCMCIA access */
  183. u16 pcmciamesportaladdr; /* 0x010, rev8 */
  184. u16 PAD[1];
  185. u16 pcmciamesportalmask; /* rev8 */
  186. u16 PAD[1];
  187. u16 pcmciawrframebc; /* rev8 */
  188. u16 PAD[1];
  189. u16 pcmciaunderflowtimer; /* rev8 */
  190. u16 PAD[1];
  191. /* interrupt */
  192. u32 intstatus; /* 0x020, rev8 */
  193. u32 hostintmask; /* rev8 */
  194. u32 intmask; /* rev8 */
  195. u32 sbintstatus; /* rev8 */
  196. u32 sbintmask; /* rev8 */
  197. u32 funcintmask; /* rev4 */
  198. u32 PAD[2];
  199. u32 tosbmailbox; /* 0x040, rev8 */
  200. u32 tohostmailbox; /* rev8 */
  201. u32 tosbmailboxdata; /* rev8 */
  202. u32 tohostmailboxdata; /* rev8 */
  203. /* synchronized access to registers in SDIO clock domain */
  204. u32 sdioaccess; /* 0x050, rev8 */
  205. u32 PAD[3];
  206. /* PCMCIA frame control */
  207. u8 pcmciaframectrl; /* 0x060, rev8 */
  208. u8 PAD[3];
  209. u8 pcmciawatermark; /* rev8 */
  210. u8 PAD[155];
  211. /* interrupt batching control */
  212. u32 intrcvlazy; /* 0x100, rev8 */
  213. u32 PAD[3];
  214. /* counters */
  215. u32 cmd52rd; /* 0x110, rev8 */
  216. u32 cmd52wr; /* rev8 */
  217. u32 cmd53rd; /* rev8 */
  218. u32 cmd53wr; /* rev8 */
  219. u32 abort; /* rev8 */
  220. u32 datacrcerror; /* rev8 */
  221. u32 rdoutofsync; /* rev8 */
  222. u32 wroutofsync; /* rev8 */
  223. u32 writebusy; /* rev8 */
  224. u32 readwait; /* rev8 */
  225. u32 readterm; /* rev8 */
  226. u32 writeterm; /* rev8 */
  227. u32 PAD[40];
  228. u32 clockctlstatus; /* rev8 */
  229. u32 PAD[7];
  230. u32 PAD[128]; /* DMA engines */
  231. /* SDIO/PCMCIA CIS region */
  232. char cis[512]; /* 0x400-0x5ff, rev6 */
  233. /* PCMCIA function control registers */
  234. char pcmciafcr[256]; /* 0x600-6ff, rev6 */
  235. u16 PAD[55];
  236. /* PCMCIA backplane access */
  237. u16 backplanecsr; /* 0x76E, rev6 */
  238. u16 backplaneaddr0; /* rev6 */
  239. u16 backplaneaddr1; /* rev6 */
  240. u16 backplaneaddr2; /* rev6 */
  241. u16 backplaneaddr3; /* rev6 */
  242. u16 backplanedata0; /* rev6 */
  243. u16 backplanedata1; /* rev6 */
  244. u16 backplanedata2; /* rev6 */
  245. u16 backplanedata3; /* rev6 */
  246. u16 PAD[31];
  247. /* sprom "size" & "blank" info */
  248. u16 spromstatus; /* 0x7BE, rev2 */
  249. u32 PAD[464];
  250. u16 PAD[0x80];
  251. };
  252. /* Register/deregister interrupt handler. */
  253. int brcmf_sdiod_intr_register(struct brcmf_sdio_dev *sdiodev);
  254. void brcmf_sdiod_intr_unregister(struct brcmf_sdio_dev *sdiodev);
  255. /* SDIO device register access interface */
  256. /* Accessors for SDIO Function 0 */
  257. #define brcmf_sdiod_func0_rb(sdiodev, addr, r) \
  258. sdio_f0_readb((sdiodev)->func1, (addr), (r))
  259. #define brcmf_sdiod_func0_wb(sdiodev, addr, v, ret) \
  260. sdio_f0_writeb((sdiodev)->func1, (v), (addr), (ret))
  261. /* Accessors for SDIO Function 1 */
  262. #define brcmf_sdiod_readb(sdiodev, addr, r) \
  263. sdio_readb((sdiodev)->func1, (addr), (r))
  264. #define brcmf_sdiod_writeb(sdiodev, addr, v, ret) \
  265. sdio_writeb((sdiodev)->func1, (v), (addr), (ret))
  266. u32 brcmf_sdiod_readl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret);
  267. void brcmf_sdiod_writel(struct brcmf_sdio_dev *sdiodev, u32 addr, u32 data,
  268. int *ret);
  269. /* Buffer transfer to/from device (client) core via cmd53.
  270. * fn: function number
  271. * flags: backplane width, address increment, sync/async
  272. * buf: pointer to memory data buffer
  273. * nbytes: number of bytes to transfer to/from buf
  274. * pkt: pointer to packet associated with buf (if any)
  275. * complete: callback function for command completion (async only)
  276. * handle: handle for completion callback (first arg in callback)
  277. * Returns 0 or error code.
  278. * NOTE: Async operation is not currently supported.
  279. */
  280. int brcmf_sdiod_send_pkt(struct brcmf_sdio_dev *sdiodev,
  281. struct sk_buff_head *pktq);
  282. int brcmf_sdiod_send_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes);
  283. int brcmf_sdiod_recv_pkt(struct brcmf_sdio_dev *sdiodev, struct sk_buff *pkt);
  284. int brcmf_sdiod_recv_buf(struct brcmf_sdio_dev *sdiodev, u8 *buf, uint nbytes);
  285. int brcmf_sdiod_recv_chain(struct brcmf_sdio_dev *sdiodev,
  286. struct sk_buff_head *pktq, uint totlen);
  287. /* Flags bits */
  288. /* Four-byte target (backplane) width (vs. two-byte) */
  289. #define SDIO_REQ_4BYTE 0x1
  290. /* Fixed address (FIFO) (vs. incrementing address) */
  291. #define SDIO_REQ_FIXED 0x2
  292. /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
  293. * rw: read or write (0/1)
  294. * addr: direct SDIO address
  295. * buf: pointer to memory data buffer
  296. * nbytes: number of bytes to transfer to/from buf
  297. * Returns 0 or error code.
  298. */
  299. int brcmf_sdiod_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address,
  300. u8 *data, uint size);
  301. /* Issue an abort to the specified function */
  302. int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, struct sdio_func *func);
  303. void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev);
  304. void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
  305. enum brcmf_sdiod_state state);
  306. #ifdef CONFIG_PM_SLEEP
  307. bool brcmf_sdiod_freezing(struct brcmf_sdio_dev *sdiodev);
  308. void brcmf_sdiod_try_freeze(struct brcmf_sdio_dev *sdiodev);
  309. void brcmf_sdiod_freezer_count(struct brcmf_sdio_dev *sdiodev);
  310. void brcmf_sdiod_freezer_uncount(struct brcmf_sdio_dev *sdiodev);
  311. #else
  312. static inline bool brcmf_sdiod_freezing(struct brcmf_sdio_dev *sdiodev)
  313. {
  314. return false;
  315. }
  316. static inline void brcmf_sdiod_try_freeze(struct brcmf_sdio_dev *sdiodev)
  317. {
  318. }
  319. static inline void brcmf_sdiod_freezer_count(struct brcmf_sdio_dev *sdiodev)
  320. {
  321. }
  322. static inline void brcmf_sdiod_freezer_uncount(struct brcmf_sdio_dev *sdiodev)
  323. {
  324. }
  325. #endif /* CONFIG_PM_SLEEP */
  326. struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev);
  327. void brcmf_sdio_remove(struct brcmf_sdio *bus);
  328. void brcmf_sdio_isr(struct brcmf_sdio *bus);
  329. void brcmf_sdio_wd_timer(struct brcmf_sdio *bus, bool active);
  330. void brcmf_sdio_wowl_config(struct device *dev, bool enabled);
  331. int brcmf_sdio_sleep(struct brcmf_sdio *bus, bool sleep);
  332. void brcmf_sdio_trigger_dpc(struct brcmf_sdio *bus);
  333. #endif /* BRCMFMAC_SDIO_H */