2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
18 * @file bcmsdh_linux.c
21 #define __UNDEF_NO_VERSION__
23 #include <linux/netdevice.h>
24 #include <linux/pci.h>
25 #include <linux/completion.h>
26 #include <linux/sched.h>
29 #include <brcm_hw_ids.h>
30 #include <brcmu_utils.h>
31 #include <brcmu_wifi.h>
32 #include "sdio_host.h"
34 #include "dngl_stats.h"
40 * SDIO Host Controller info
44 struct device
*dev
; /* platform device handle */
45 void *regs
; /* SDIO Host Controller address */
46 struct brcmf_sdio_card
*card
;
49 unsigned long oob_flags
; /* OOB Host specifiction
51 bool oob_irq_registered
;
53 static struct sdio_hc
*sdhcinfo
;
55 /* driver info, initialized when brcmf_sdio_register is called */
56 static struct brcmf_sdioh_driver drvinfo
= { NULL
, NULL
};
58 /* debugging macros */
62 * Checks to see if vendor and device IDs match a supported SDIO Host Controller.
64 bool brcmf_sdio_chipmatch(u16 vendor
, u16 device
)
66 /* Add other vendors and devices as required */
69 /* Check for Arasan host controller */
70 if (vendor
== VENDOR_SI_IMAGE
)
73 /* Check for BRCM 27XX Standard host controller */
74 if (device
== BCM27XX_SDIOH_ID
&& vendor
== PCI_VENDOR_ID_BROADCOM
)
77 /* Check for BRCM Standard host controller */
78 if (device
== SDIOH_FPGA_ID
&& vendor
== PCI_VENDOR_ID_BROADCOM
)
81 /* Check for TI PCIxx21 Standard host controller */
82 if (device
== PCIXX21_SDIOH_ID
&& vendor
== VENDOR_TI
)
85 if (device
== PCIXX21_SDIOH0_ID
&& vendor
== VENDOR_TI
)
88 /* Ricoh R5C822 Standard SDIO Host */
89 if (device
== R5C822_SDIOH_ID
&& vendor
== VENDOR_RICOH
)
92 /* JMicron Standard SDIO Host */
93 if (device
== JMICRON_SDIOH_ID
&& vendor
== VENDOR_JMICRON
)
95 #endif /* BCMSDIOH_STD */
97 /* This is the PciSpiHost. */
98 if (device
== SPIH_FPGA_ID
&& vendor
== PCI_VENDOR_ID_BROADCOM
) {
101 #endif /* BCMSDIOH_SPI */
106 /* forward declarations */
107 int brcmf_sdio_probe(struct device
*dev
);
108 EXPORT_SYMBOL(brcmf_sdio_probe
);
110 int brcmf_sdio_remove(struct device
*dev
);
111 EXPORT_SYMBOL(brcmf_sdio_remove
);
113 int brcmf_sdio_probe(struct device
*dev
)
115 struct sdio_hc
*sdhc
= NULL
;
116 unsigned long regs
= 0;
117 struct brcmf_sdio_card
*card
= NULL
;
120 unsigned long irq_flags
= 0;
122 /* allocate SDIO Host Controller state info */
123 sdhc
= kzalloc(sizeof(struct sdio_hc
), GFP_ATOMIC
);
125 SDLX_MSG(("%s: out of memory\n", __func__
));
128 sdhc
->dev
= (void *)dev
;
130 card
= brcmf_sdcard_attach((void *)0, (void **)®s
, irq
);
132 SDLX_MSG(("%s: attach failed\n", __func__
));
138 sdhc
->oob_flags
= irq_flags
;
139 sdhc
->oob_irq_registered
= false; /* to make sure.. */
141 /* chain SDIO Host Controller info together */
142 sdhc
->next
= sdhcinfo
;
144 /* Read the vendor/device ID from the CIS */
145 vendevid
= brcmf_sdcard_query_device(card
);
147 /* try to attach to the target device */
148 sdhc
->ch
= drvinfo
.attach((vendevid
>> 16), (vendevid
& 0xFFFF),
149 0, 0, 0, 0, (void *)regs
, card
);
151 SDLX_MSG(("%s: device attach failed\n", __func__
));
161 brcmf_sdcard_detach(sdhc
->card
);
168 int brcmf_sdio_remove(struct device
*dev
)
170 struct sdio_hc
*sdhc
, *prev
;
173 drvinfo
.detach(sdhc
->ch
);
174 brcmf_sdcard_detach(sdhc
->card
);
175 /* find the SDIO Host Controller state for this pdev
176 and take it out from the list */
177 for (sdhc
= sdhcinfo
, prev
= NULL
; sdhc
; sdhc
= sdhc
->next
) {
178 if (sdhc
->dev
== (void *)dev
) {
180 prev
->next
= sdhc
->next
;
188 SDLX_MSG(("%s: failed\n", __func__
));
192 /* release SDIO Host Controller info */
197 int brcmf_sdio_register(struct brcmf_sdioh_driver
*driver
)
201 SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
202 return brcmf_sdio_function_init();
205 void brcmf_sdio_unregister(void)
207 brcmf_sdio_function_cleanup();
210 /* Module parameters specific to each host-controller driver */
212 module_param(sd_msglevel
, uint
, 0);
214 extern uint sd_f2_blocksize
;
215 module_param(sd_f2_blocksize
, int, 0);
217 void brcmf_sdio_wdtmr_enable(bool enable
)
220 brcmf_sdbrcm_wd_timer(sdhcinfo
->ch
, brcmf_watchdog_ms
);
222 brcmf_sdbrcm_wd_timer(sdhcinfo
->ch
, 0);