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>
32 #if defined(OOB_INTR_ONLY)
33 #include <linux/irq.h>
34 extern void dhdsdio_isr(void *args);
36 #include <dngl_stats.h>
38 #endif /* defined(OOB_INTR_ONLY) */
39 #if defined(CONFIG_MACH_SANDGATE2G) || defined(CONFIG_MACH_LOGICPD_PXA270)
40 #if !defined(BCMPLATFORM_BUS)
41 #define BCMPLATFORM_BUS
42 #endif /* !defined(BCMPLATFORM_BUS) */
44 #include <linux/platform_device.h>
45 #endif /* CONFIG_MACH_SANDGATE2G */
48 * SDIO Host Controller info
50 typedef struct bcmsdh_hc bcmsdh_hc_t;
54 #ifdef BCMPLATFORM_BUS
55 struct device *dev; /* platform device handle */
57 struct pci_dev *dev; /* pci device handle */
58 #endif /* BCMPLATFORM_BUS */
60 void *regs; /* SDIO Host Controller address */
61 bcmsdh_info_t *sdh; /* SDIO Host Controller handle */
64 unsigned long oob_flags; /* OOB Host specifiction
66 bool oob_irq_registered;
67 #if defined(OOB_INTR_ONLY)
71 static bcmsdh_hc_t *sdhcinfo;
73 /* driver info, initialized when bcmsdh_register is called */
74 static bcmsdh_driver_t drvinfo = { NULL, NULL };
76 /* debugging macros */
80 * Checks to see if vendor and device IDs match a supported SDIO Host Controller.
82 bool bcmsdh_chipmatch(u16 vendor, u16 device)
84 /* Add other vendors and devices as required */
87 /* Check for Arasan host controller */
88 if (vendor == VENDOR_SI_IMAGE)
91 /* Check for BRCM 27XX Standard host controller */
92 if (device == BCM27XX_SDIOH_ID && vendor == VENDOR_BROADCOM)
95 /* Check for BRCM Standard host controller */
96 if (device == SDIOH_FPGA_ID && vendor == VENDOR_BROADCOM)
99 /* Check for TI PCIxx21 Standard host controller */
100 if (device == PCIXX21_SDIOH_ID && vendor == VENDOR_TI)
103 if (device == PCIXX21_SDIOH0_ID && vendor == VENDOR_TI)
106 /* Ricoh R5C822 Standard SDIO Host */
107 if (device == R5C822_SDIOH_ID && vendor == VENDOR_RICOH)
110 /* JMicron Standard SDIO Host */
111 if (device == JMICRON_SDIOH_ID && vendor == VENDOR_JMICRON)
113 #endif /* BCMSDIOH_STD */
115 /* This is the PciSpiHost. */
116 if (device == SPIH_FPGA_ID && vendor == VENDOR_BROADCOM) {
117 printf("Found PCI SPI Host Controller\n");
120 #endif /* BCMSDIOH_SPI */
125 #if defined(BCMPLATFORM_BUS)
126 #if defined(BCMLXSDMMC)
127 /* forward declarations */
128 int bcmsdh_probe(struct device *dev);
129 EXPORT_SYMBOL(bcmsdh_probe);
131 int bcmsdh_remove(struct device *dev);
132 EXPORT_SYMBOL(bcmsdh_remove);
135 /* forward declarations */
136 static int __devinit bcmsdh_probe(struct device *dev);
137 static int __devexit bcmsdh_remove(struct device *dev);
138 #endif /* BCMLXSDMMC */
142 #endif /* BCMLXSDMMC */
143 int bcmsdh_probe(struct device *dev)
145 struct osl_info *osh = NULL;
146 bcmsdh_hc_t *sdhc = NULL;
147 unsigned long regs = 0;
148 bcmsdh_info_t *sdh = NULL;
149 #if !defined(BCMLXSDMMC) && defined(BCMPLATFORM_BUS)
150 struct platform_device *pdev;
152 #endif /* BCMLXSDMMC */
155 unsigned long irq_flags = 0;
157 #if !defined(BCMLXSDMMC) && defined(BCMPLATFORM_BUS)
158 pdev = to_platform_device(dev);
159 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
160 irq = platform_get_irq(pdev, 0);
161 if (!r || irq == NO_IRQ)
163 #endif /* BCMLXSDMMC */
165 #if defined(OOB_INTR_ONLY)
168 IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL |
169 IORESOURCE_IRQ_SHAREABLE;
171 irq_flags = IRQF_TRIGGER_FALLING;
173 irq = dhd_customer_oob_irq_map(&irq_flags);
175 SDLX_MSG(("%s: Host irq is not defined\n", __func__));
178 #endif /* defined(OOB_INTR_ONLY) */
179 /* allocate SDIO Host Controller state info */
180 osh = osl_attach(dev, PCI_BUS);
182 SDLX_MSG(("%s: osl_attach failed\n", __func__));
185 sdhc = kzalloc(sizeof(bcmsdh_hc_t), GFP_ATOMIC);
187 SDLX_MSG(("%s: out of memory\n", __func__));
192 sdhc->dev = (void *)dev;
195 sdh = bcmsdh_attach(osh, (void *)0, (void **)®s, irq);
197 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
201 sdh = bcmsdh_attach(osh, (void *)r->start, (void **)®s, irq);
203 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
206 #endif /* BCMLXSDMMC */
209 sdhc->oob_flags = irq_flags;
210 sdhc->oob_irq_registered = false; /* to make sure.. */
211 #if defined(OOB_INTR_ONLY)
212 spin_lock_init(&sdhc->irq_lock);
215 /* chain SDIO Host Controller info together */
216 sdhc->next = sdhcinfo;
218 /* Read the vendor/device ID from the CIS */
219 vendevid = bcmsdh_query_device(sdh);
221 /* try to attach to the target device */
222 sdhc->ch = drvinfo.attach((vendevid >> 16), (vendevid & 0xFFFF),
223 0, 0, 0, 0, (void *)regs, NULL, sdh);
225 SDLX_MSG(("%s: device attach failed\n", __func__));
235 bcmsdh_detach(sdhc->osh, sdhc->sdh);
245 #endif /* BCMLXSDMMC */
246 int bcmsdh_remove(struct device *dev)
248 bcmsdh_hc_t *sdhc, *prev;
249 struct osl_info *osh;
252 drvinfo.detach(sdhc->ch);
253 bcmsdh_detach(sdhc->osh, sdhc->sdh);
254 /* find the SDIO Host Controller state for this pdev
255 and take it out from the list */
256 for (sdhc = sdhcinfo, prev = NULL; sdhc; sdhc = sdhc->next) {
257 if (sdhc->dev == (void *)dev) {
259 prev->next = sdhc->next;
267 SDLX_MSG(("%s: failed\n", __func__));
271 /* release SDIO Host Controller info */
276 #if !defined(BCMLXSDMMC)
277 dev_set_drvdata(dev, NULL);
278 #endif /* !defined(BCMLXSDMMC) */
282 #endif /* BCMPLATFORM_BUS */
284 extern int sdio_function_init(void);
286 int bcmsdh_register(bcmsdh_driver_t *driver)
290 SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
291 return sdio_function_init();
294 extern void sdio_function_cleanup(void);
296 void bcmsdh_unregister(void)
298 sdio_function_cleanup();
301 #if defined(OOB_INTR_ONLY)
302 void bcmsdh_oob_intr_set(bool enable)
304 static bool curstate = 1;
307 spin_lock_irqsave(&sdhcinfo->irq_lock, flags);
308 if (curstate != enable) {
310 enable_irq(sdhcinfo->oob_irq);
312 disable_irq_nosync(sdhcinfo->oob_irq);
315 spin_unlock_irqrestore(&sdhcinfo->irq_lock, flags);
318 static irqreturn_t wlan_oob_irq(int irq, void *dev_id)
322 dhdp = (dhd_pub_t *) dev_get_drvdata(sdhcinfo->dev);
324 bcmsdh_oob_intr_set(0);
327 SDLX_MSG(("Out of band GPIO interrupt fired way too early\n"));
331 WAKE_LOCK_TIMEOUT(dhdp, WAKE_LOCK_TMOUT, 25);
333 dhdsdio_isr((void *)dhdp->bus);
338 int bcmsdh_register_oob_intr(void *dhdp)
342 SDLX_MSG(("%s Enter\n", __func__));
344 sdhcinfo->oob_flags =
345 IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL |
346 IORESOURCE_IRQ_SHAREABLE;
347 dev_set_drvdata(sdhcinfo->dev, dhdp);
349 if (!sdhcinfo->oob_irq_registered) {
350 SDLX_MSG(("%s IRQ=%d Type=%X\n", __func__,
351 (int)sdhcinfo->oob_irq, (int)sdhcinfo->oob_flags));
352 /* Refer to customer Host IRQ docs about
353 proper irqflags definition */
355 request_irq(sdhcinfo->oob_irq, wlan_oob_irq,
356 sdhcinfo->oob_flags, "bcmsdh_sdmmc", NULL);
360 set_irq_wake(sdhcinfo->oob_irq, 1);
361 sdhcinfo->oob_irq_registered = true;
367 void bcmsdh_unregister_oob_intr(void)
369 SDLX_MSG(("%s: Enter\n", __func__));
371 set_irq_wake(sdhcinfo->oob_irq, 0);
372 disable_irq(sdhcinfo->oob_irq); /* just in case.. */
373 free_irq(sdhcinfo->oob_irq, NULL);
374 sdhcinfo->oob_irq_registered = false;
376 #endif /* defined(OOB_INTR_ONLY) */
377 /* Module parameters specific to each host-controller driver */
379 extern uint sd_msglevel; /* Debug message level */
380 module_param(sd_msglevel, uint, 0);
382 extern uint sd_power; /* 0 = SD Power OFF,
384 module_param(sd_power, uint, 0);
386 extern uint sd_clock; /* SD Clock Control, 0 = SD Clock OFF,
388 module_param(sd_clock, uint, 0);
390 extern uint sd_divisor; /* Divisor (-1 means external clock) */
391 module_param(sd_divisor, uint, 0);
393 extern uint sd_sdmode; /* Default is SD4, 0=SPI, 1=SD1, 2=SD4 */
394 module_param(sd_sdmode, uint, 0);
396 extern uint sd_hiok; /* Ok to use hi-speed mode */
397 module_param(sd_hiok, uint, 0);
399 extern uint sd_f2_blocksize;
400 module_param(sd_f2_blocksize, int, 0);