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