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