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);
35 #include <dngl_stats.h>
37 #endif /* defined(OOB_INTR_ONLY) */
38 #if defined(CONFIG_MACH_SANDGATE2G) || defined(CONFIG_MACH_LOGICPD_PXA270)
39 #if !defined(BCMPLATFORM_BUS)
40 #define BCMPLATFORM_BUS
41 #endif /* !defined(BCMPLATFORM_BUS) */
43 #include <linux/platform_device.h>
44 #endif /* CONFIG_MACH_SANDGATE2G */
46 #include "dngl_stats.h"
50 * SDIO Host Controller info
52 typedef struct bcmsdh_hc bcmsdh_hc_t;
56 #ifdef BCMPLATFORM_BUS
57 struct device *dev; /* platform device handle */
59 struct pci_dev *dev; /* pci device handle */
60 #endif /* BCMPLATFORM_BUS */
61 void *regs; /* SDIO Host Controller address */
62 bcmsdh_info_t *sdh; /* SDIO Host Controller handle */
65 unsigned long oob_flags; /* OOB Host specifiction
67 bool oob_irq_registered;
68 #if defined(OOB_INTR_ONLY)
72 static bcmsdh_hc_t *sdhcinfo;
74 /* driver info, initialized when bcmsdh_register is called */
75 static bcmsdh_driver_t drvinfo = { NULL, NULL };
77 /* debugging macros */
81 * Checks to see if vendor and device IDs match a supported SDIO Host Controller.
83 bool bcmsdh_chipmatch(u16 vendor, u16 device)
85 /* Add other vendors and devices as required */
88 /* Check for Arasan host controller */
89 if (vendor == VENDOR_SI_IMAGE)
92 /* Check for BRCM 27XX Standard host controller */
93 if (device == BCM27XX_SDIOH_ID && vendor == PCI_VENDOR_ID_BROADCOM)
96 /* Check for BRCM Standard host controller */
97 if (device == SDIOH_FPGA_ID && vendor == PCI_VENDOR_ID_BROADCOM)
100 /* Check for TI PCIxx21 Standard host controller */
101 if (device == PCIXX21_SDIOH_ID && vendor == VENDOR_TI)
104 if (device == PCIXX21_SDIOH0_ID && vendor == VENDOR_TI)
107 /* Ricoh R5C822 Standard SDIO Host */
108 if (device == R5C822_SDIOH_ID && vendor == VENDOR_RICOH)
111 /* JMicron Standard SDIO Host */
112 if (device == JMICRON_SDIOH_ID && vendor == VENDOR_JMICRON)
114 #endif /* BCMSDIOH_STD */
116 /* This is the PciSpiHost. */
117 if (device == SPIH_FPGA_ID && vendor == PCI_VENDOR_ID_BROADCOM) {
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 bcmsdh_hc_t *sdhc = NULL;
146 unsigned long regs = 0;
147 bcmsdh_info_t *sdh = NULL;
148 #if !defined(BCMLXSDMMC) && defined(BCMPLATFORM_BUS)
149 struct platform_device *pdev;
151 #endif /* BCMLXSDMMC */
154 unsigned long irq_flags = 0;
156 #if !defined(BCMLXSDMMC) && defined(BCMPLATFORM_BUS)
157 pdev = to_platform_device(dev);
158 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
159 irq = platform_get_irq(pdev, 0);
160 if (!r || irq == NO_IRQ)
162 #endif /* BCMLXSDMMC */
164 #if defined(OOB_INTR_ONLY)
167 IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL |
168 IORESOURCE_IRQ_SHAREABLE;
170 irq_flags = IRQF_TRIGGER_FALLING;
172 irq = dhd_customer_oob_irq_map(&irq_flags);
174 SDLX_MSG(("%s: Host irq is not defined\n", __func__));
177 #endif /* defined(OOB_INTR_ONLY) */
178 /* allocate SDIO Host Controller state info */
179 sdhc = kzalloc(sizeof(bcmsdh_hc_t), GFP_ATOMIC);
181 SDLX_MSG(("%s: out of memory\n", __func__));
184 sdhc->dev = (void *)dev;
187 sdh = bcmsdh_attach((void *)0, (void **)®s, irq);
189 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
193 sdh = bcmsdh_attach((void *)r->start, (void **)®s, irq);
195 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
198 #endif /* BCMLXSDMMC */
201 sdhc->oob_flags = irq_flags;
202 sdhc->oob_irq_registered = false; /* to make sure.. */
203 #if defined(OOB_INTR_ONLY)
204 spin_lock_init(&sdhc->irq_lock);
207 /* chain SDIO Host Controller info together */
208 sdhc->next = sdhcinfo;
210 /* Read the vendor/device ID from the CIS */
211 vendevid = bcmsdh_query_device(sdh);
213 /* try to attach to the target device */
214 sdhc->ch = drvinfo.attach((vendevid >> 16), (vendevid & 0xFFFF),
215 0, 0, 0, 0, (void *)regs, sdh);
217 SDLX_MSG(("%s: device attach failed\n", __func__));
227 bcmsdh_detach(sdhc->sdh);
236 #endif /* BCMLXSDMMC */
237 int bcmsdh_remove(struct device *dev)
239 bcmsdh_hc_t *sdhc, *prev;
242 drvinfo.detach(sdhc->ch);
243 bcmsdh_detach(sdhc->sdh);
244 /* find the SDIO Host Controller state for this pdev
245 and take it out from the list */
246 for (sdhc = sdhcinfo, prev = NULL; sdhc; sdhc = sdhc->next) {
247 if (sdhc->dev == (void *)dev) {
249 prev->next = sdhc->next;
257 SDLX_MSG(("%s: failed\n", __func__));
261 /* release SDIO Host Controller info */
264 #if !defined(BCMLXSDMMC)
265 dev_set_drvdata(dev, NULL);
266 #endif /* !defined(BCMLXSDMMC) */
270 #endif /* BCMPLATFORM_BUS */
272 extern int sdio_function_init(void);
274 int bcmsdh_register(bcmsdh_driver_t *driver)
278 SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
279 return sdio_function_init();
282 extern void sdio_function_cleanup(void);
284 void bcmsdh_unregister(void)
286 sdio_function_cleanup();
289 #if defined(OOB_INTR_ONLY)
290 void bcmsdh_oob_intr_set(bool enable)
292 static bool curstate = 1;
295 spin_lock_irqsave(&sdhcinfo->irq_lock, flags);
296 if (curstate != enable) {
298 enable_irq(sdhcinfo->oob_irq);
300 disable_irq_nosync(sdhcinfo->oob_irq);
303 spin_unlock_irqrestore(&sdhcinfo->irq_lock, flags);
306 static irqreturn_t wlan_oob_irq(int irq, void *dev_id)
310 dhdp = (dhd_pub_t *) dev_get_drvdata(sdhcinfo->dev);
312 bcmsdh_oob_intr_set(0);
315 SDLX_MSG(("Out of band GPIO interrupt fired way too early\n"));
319 dhdsdio_isr((void *)dhdp->bus);
324 int bcmsdh_register_oob_intr(void *dhdp)
328 SDLX_MSG(("%s Enter\n", __func__));
330 sdhcinfo->oob_flags =
331 IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL |
332 IORESOURCE_IRQ_SHAREABLE;
333 dev_set_drvdata(sdhcinfo->dev, dhdp);
335 if (!sdhcinfo->oob_irq_registered) {
336 SDLX_MSG(("%s IRQ=%d Type=%X\n", __func__,
337 (int)sdhcinfo->oob_irq, (int)sdhcinfo->oob_flags));
338 /* Refer to customer Host IRQ docs about
339 proper irqflags definition */
341 request_irq(sdhcinfo->oob_irq, wlan_oob_irq,
342 sdhcinfo->oob_flags, "bcmsdh_sdmmc", NULL);
346 irq_set_irq_wake(sdhcinfo->oob_irq, 1);
347 sdhcinfo->oob_irq_registered = true;
353 void bcmsdh_unregister_oob_intr(void)
355 SDLX_MSG(("%s: Enter\n", __func__));
357 irq_set_irq_wake(sdhcinfo->oob_irq, 0);
358 disable_irq(sdhcinfo->oob_irq); /* just in case.. */
359 free_irq(sdhcinfo->oob_irq, NULL);
360 sdhcinfo->oob_irq_registered = false;
362 #endif /* defined(OOB_INTR_ONLY) */
363 /* Module parameters specific to each host-controller driver */
365 extern uint sd_msglevel; /* Debug message level */
366 module_param(sd_msglevel, uint, 0);
368 extern uint sd_power; /* 0 = SD Power OFF,
370 module_param(sd_power, uint, 0);
372 extern uint sd_clock; /* SD Clock Control, 0 = SD Clock OFF,
374 module_param(sd_clock, uint, 0);
376 extern uint sd_divisor; /* Divisor (-1 means external clock) */
377 module_param(sd_divisor, uint, 0);
379 extern uint sd_sdmode; /* Default is SD4, 0=SPI, 1=SD1, 2=SD4 */
380 module_param(sd_sdmode, uint, 0);
382 extern uint sd_hiok; /* Ok to use hi-speed mode */
383 module_param(sd_hiok, uint, 0);
385 extern uint sd_f2_blocksize;
386 module_param(sd_f2_blocksize, int, 0);