17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/types.h>
20 #include <linux/netdevice.h>
27 #include <linux/errno.h>
28 #include <linux/sched.h>
29 #include <linux/module.h>
41 #define SDIO_VENDOR_ID_BROADCOM 0x02d0
43 #define DMA_ALIGN_MASK 0x03
45 #define SDIO_DEVICE_ID_BROADCOM_43241 0x4324
46 #define SDIO_DEVICE_ID_BROADCOM_4329 0x4329
47 #define SDIO_DEVICE_ID_BROADCOM_4330 0x4330
48 #define SDIO_DEVICE_ID_BROADCOM_4334 0x4334
50 #define SDIO_FUNC1_BLOCKSIZE 64
51 #define SDIO_FUNC2_BLOCKSIZE 512
63 #ifdef CONFIG_BRCMFMAC_SDIO_OOB
65 struct brcmf_sdio_oobirq {
76 #ifdef CONFIG_PM_SLEEP
85 #ifdef CONFIG_PM_SLEEP
92 static inline int brcmf_sdioh_f0_write_byte(
struct brcmf_sdio_dev *sdiodev,
104 sdfunc = sdiodev->
func[2];
111 "enable F2 failed:%d\n",
118 "Disable F2 failed:%d\n",
131 }
else if (regaddr < 0xF0) {
146 brcmf_dbg(
INFO,
"rw=%d, func=%d, addr=0x%05x\n", rw, func, regaddr);
149 if (brcmf_pm_resume_error(sdiodev))
152 if (rw && func == 0) {
154 err_ret = brcmf_sdioh_f0_write_byte(sdiodev, regaddr, byte);
159 else if (func == 0) {
170 rw ?
"write" :
"read", func, regaddr, *byte, err_ret);
187 rw, func, addr, nbytes);
190 if (brcmf_pm_resume_error(sdiodev))
197 else if (nbytes == 2)
205 else if (nbytes == 2)
214 rw ?
"write" :
"read", err_ret);
226 if ((write) && (!fifo)) {
228 ((
u8 *) (pkt->
data)), pktlen);
231 ((
u8 *) (pkt->
data)), pktlen);
234 ((
u8 *) (pkt->
data)), addr, pktlen);
262 if (brcmf_pm_resume_error(sdiodev))
265 skb_queue_walk(pktq, pkt) {
268 pkt_len &= 0xFFFFFFFC;
270 err_ret = brcmf_sdioh_request_data(sdiodev, write, fifo, func,
273 brcmf_dbg(
ERROR,
"%s FAILED %p[%d], addr=0x%05x, pkt_len=%d, ERR=0x%08x\n",
274 write ?
"TX" :
"RX", pkt, SGCount, addr,
278 write ?
"TX" :
"RX", pkt, SGCount, addr,
309 if (brcmf_pm_resume_error(sdiodev))
315 status = brcmf_sdioh_request_data(sdiodev, write, fifo, func,
318 brcmf_dbg(
ERROR,
"%s FAILED %p, addr=0x%05x, pkt_len=%d, ERR=0x%08x\n",
319 write ?
"TX" :
"RX", pkt, addr, pkt_len, status);
322 write ?
"TX" :
"RX", pkt, addr, pkt_len);
336 for (i = 0; i < 3; i++) {
341 *ptr++ = (
u8) regdata;
347 scratch &= 0x0001FFFF;
351 static int brcmf_sdioh_enablefuncs(
struct brcmf_sdio_dev *sdiodev)
360 sdiodev->
func_cis_ptr[0] = brcmf_sdioh_get_cisaddr(sdiodev,
369 brcmf_sdioh_get_cisaddr(sdiodev,
SDIO_FBR_CIS + fbraddr);
411 brcmf_sdioh_enablefuncs(sdiodev);
434 #ifdef CONFIG_BRCMFMAC_SDIO_OOB
437 struct brcmf_sdio_oobirq *oobirq_entry;
439 if (list_empty(&oobirq_lh)) {
447 sdiodev->irq = oobirq_entry->irq;
448 sdiodev->irq_flags = oobirq_entry->flags;
455 static inline int brcmf_sdio_getintrcfg(
struct brcmf_sdio_dev *sdiodev)
461 static int brcmf_ops_sdio_probe(
struct sdio_func *func,
474 if (func->
num == 1) {
502 if (func->
num == 2) {
504 if ((!sdiodev) || (sdiodev->
func[1]->card != func->
card))
507 ret = brcmf_sdio_getintrcfg(sdiodev);
513 sdiodev->
dev = &func->
dev;
523 static void brcmf_ops_sdio_remove(
struct sdio_func *func)
533 if (func->
num == 2) {
545 #ifdef CONFIG_PM_SLEEP
546 static int brcmf_sdio_suspend(
struct device *
dev)
574 static int brcmf_sdio_resume(
struct device *dev)
584 static const struct dev_pm_ops brcmf_sdio_pm_ops = {
586 .resume = brcmf_sdio_resume,
591 .probe = brcmf_ops_sdio_probe,
592 .remove = brcmf_ops_sdio_remove,
594 .id_table = brcmf_sdmmc_ids,
595 #ifdef CONFIG_PM_SLEEP
597 .pm = &brcmf_sdio_pm_ops,
602 #ifdef CONFIG_BRCMFMAC_SDIO_OOB
606 struct brcmf_sdio_oobirq *oobirq_entry;
609 INIT_LIST_HEAD(&oobirq_lh);
616 oobirq_entry = kzalloc(
sizeof(
struct brcmf_sdio_oobirq),
620 oobirq_entry->irq = res->
start;
636 .
probe = brcmf_sdio_pd_probe,
638 .name =
"brcmf_sdio_pd"