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 #if defined(OOB_INTR_ONLY)
35 #include <linux/irq.h>
36 extern void brcmf_sdbrcm_isr(void *args);
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
53 struct bcmsdh_hc *next;
54 #ifdef BCMPLATFORM_BUS
55 struct device *dev; /* platform device handle */
57 struct pci_dev *dev; /* pci device handle */
58 #endif /* BCMPLATFORM_BUS */
59 void *regs; /* SDIO Host Controller address */
60 struct brcmf_sdio *sdh; /* SDIO Host Controller handle */
63 unsigned long oob_flags; /* OOB Host specifiction
65 bool oob_irq_registered;
66 #if defined(OOB_INTR_ONLY)
70 static struct bcmsdh_hc *sdhcinfo;
72 /* driver info, initialized when brcmf_sdio_register is called */
73 static struct brcmf_sdioh_driver drvinfo = { NULL, NULL };
75 /* debugging macros */
79 * Checks to see if vendor and device IDs match a supported SDIO Host Controller.
81 bool brcmf_sdio_chipmatch(u16 vendor, u16 device)
83 /* Add other vendors and devices as required */
86 /* Check for Arasan host controller */
87 if (vendor == VENDOR_SI_IMAGE)
90 /* Check for BRCM 27XX Standard host controller */
91 if (device == BCM27XX_SDIOH_ID && vendor == PCI_VENDOR_ID_BROADCOM)
94 /* Check for BRCM Standard host controller */
95 if (device == SDIOH_FPGA_ID && vendor == PCI_VENDOR_ID_BROADCOM)
98 /* Check for TI PCIxx21 Standard host controller */
99 if (device == PCIXX21_SDIOH_ID && vendor == VENDOR_TI)
102 if (device == PCIXX21_SDIOH0_ID && vendor == VENDOR_TI)
105 /* Ricoh R5C822 Standard SDIO Host */
106 if (device == R5C822_SDIOH_ID && vendor == VENDOR_RICOH)
109 /* JMicron Standard SDIO Host */
110 if (device == JMICRON_SDIOH_ID && vendor == VENDOR_JMICRON)
112 #endif /* BCMSDIOH_STD */
114 /* This is the PciSpiHost. */
115 if (device == SPIH_FPGA_ID && vendor == PCI_VENDOR_ID_BROADCOM) {
118 #endif /* BCMSDIOH_SPI */
123 #if defined(BCMPLATFORM_BUS)
124 #if defined(BCMLXSDMMC)
125 /* forward declarations */
126 int brcmf_sdio_probe(struct device *dev);
127 EXPORT_SYMBOL(brcmf_sdio_probe);
129 int brcmf_sdio_remove(struct device *dev);
130 EXPORT_SYMBOL(brcmf_sdio_remove);
133 /* forward declarations */
134 static int __devinit brcmf_sdio_probe(struct device *dev);
135 static int __devexit brcmf_sdio_remove(struct device *dev);
136 #endif /* BCMLXSDMMC */
140 #endif /* BCMLXSDMMC */
141 int brcmf_sdio_probe(struct device *dev)
143 struct bcmsdh_hc *sdhc = NULL;
144 unsigned long regs = 0;
145 struct brcmf_sdio *sdh = NULL;
146 #if !defined(BCMLXSDMMC) && defined(BCMPLATFORM_BUS)
147 struct platform_device *pdev;
149 #endif /* BCMLXSDMMC */
152 unsigned long irq_flags = 0;
154 #if !defined(BCMLXSDMMC) && defined(BCMPLATFORM_BUS)
155 pdev = to_platform_device(dev);
156 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
157 irq = platform_get_irq(pdev, 0);
158 if (!r || irq == NO_IRQ)
160 #endif /* BCMLXSDMMC */
162 #if defined(OOB_INTR_ONLY)
165 IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL |
166 IORESOURCE_IRQ_SHAREABLE;
168 irq_flags = IRQF_TRIGGER_FALLING;
170 irq = brcmf_customer_oob_irq_map(&irq_flags);
172 SDLX_MSG(("%s: Host irq is not defined\n", __func__));
175 #endif /* defined(OOB_INTR_ONLY) */
176 /* allocate SDIO Host Controller state info */
177 sdhc = kzalloc(sizeof(struct bcmsdh_hc), GFP_ATOMIC);
179 SDLX_MSG(("%s: out of memory\n", __func__));
182 sdhc->dev = (void *)dev;
185 sdh = brcmf_sdcard_attach((void *)0, (void **)®s, irq);
187 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
191 sdh = brcmf_sdcard_attach((void *)r->start, (void **)®s, irq);
193 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
196 #endif /* BCMLXSDMMC */
199 sdhc->oob_flags = irq_flags;
200 sdhc->oob_irq_registered = false; /* to make sure.. */
201 #if defined(OOB_INTR_ONLY)
202 spin_lock_init(&sdhc->irq_lock);
205 /* chain SDIO Host Controller info together */
206 sdhc->next = sdhcinfo;
208 /* Read the vendor/device ID from the CIS */
209 vendevid = brcmf_sdcard_query_device(sdh);
211 /* try to attach to the target device */
212 sdhc->ch = drvinfo.attach((vendevid >> 16), (vendevid & 0xFFFF),
213 0, 0, 0, 0, (void *)regs, sdh);
215 SDLX_MSG(("%s: device attach failed\n", __func__));
225 brcmf_sdcard_detach(sdhc->sdh);
234 #endif /* BCMLXSDMMC */
235 int brcmf_sdio_remove(struct device *dev)
237 struct bcmsdh_hc *sdhc, *prev;
240 drvinfo.detach(sdhc->ch);
241 brcmf_sdcard_detach(sdhc->sdh);
242 /* find the SDIO Host Controller state for this pdev
243 and take it out from the list */
244 for (sdhc = sdhcinfo, prev = NULL; sdhc; sdhc = sdhc->next) {
245 if (sdhc->dev == (void *)dev) {
247 prev->next = sdhc->next;
255 SDLX_MSG(("%s: failed\n", __func__));
259 /* release SDIO Host Controller info */
262 #if !defined(BCMLXSDMMC)
263 dev_set_drvdata(dev, NULL);
264 #endif /* !defined(BCMLXSDMMC) */
268 #endif /* BCMPLATFORM_BUS */
270 extern int brcmf_sdio_function_init(void);
272 int brcmf_sdio_register(struct brcmf_sdioh_driver *driver)
276 SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
277 return brcmf_sdio_function_init();
280 extern void brcmf_sdio_function_cleanup(void);
282 void brcmf_sdio_unregister(void)
284 brcmf_sdio_function_cleanup();
287 #if defined(OOB_INTR_ONLY)
288 void brcmf_sdio_oob_intr_set(bool enable)
290 static bool curstate = 1;
293 spin_lock_irqsave(&sdhcinfo->irq_lock, flags);
294 if (curstate != enable) {
296 enable_irq(sdhcinfo->oob_irq);
298 disable_irq_nosync(sdhcinfo->oob_irq);
301 spin_unlock_irqrestore(&sdhcinfo->irq_lock, flags);
304 static irqreturn_t brcmf_sdio_oob_irq(int irq, void *dev_id)
308 dhdp = (dhd_pub_t *) dev_get_drvdata(sdhcinfo->dev);
310 brcmf_sdio_oob_intr_set(0);
313 SDLX_MSG(("Out of band GPIO interrupt fired way too early\n"));
317 brcmf_sdbrcm_isr((void *)dhdp->bus);
322 int brcmf_sdio_register_oob_intr(void *dhdp)
326 SDLX_MSG(("%s Enter\n", __func__));
328 sdhcinfo->oob_flags =
329 IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL |
330 IORESOURCE_IRQ_SHAREABLE;
331 dev_set_drvdata(sdhcinfo->dev, dhdp);
333 if (!sdhcinfo->oob_irq_registered) {
334 SDLX_MSG(("%s IRQ=%d Type=%X\n", __func__,
335 (int)sdhcinfo->oob_irq, (int)sdhcinfo->oob_flags));
336 /* Refer to customer Host IRQ docs about
337 proper irqflags definition */
339 request_irq(sdhcinfo->oob_irq, brcmf_sdio_oob_irq,
340 sdhcinfo->oob_flags, "bcmsdh_sdmmc", NULL);
344 irq_set_irq_wake(sdhcinfo->oob_irq, 1);
345 sdhcinfo->oob_irq_registered = true;
351 void brcmf_sdio_unregister_oob_intr(void)
353 SDLX_MSG(("%s: Enter\n", __func__));
355 irq_set_irq_wake(sdhcinfo->oob_irq, 0);
356 disable_irq(sdhcinfo->oob_irq); /* just in case.. */
357 free_irq(sdhcinfo->oob_irq, NULL);
358 sdhcinfo->oob_irq_registered = false;
360 #endif /* defined(OOB_INTR_ONLY) */
361 /* Module parameters specific to each host-controller driver */
363 extern uint sd_msglevel; /* Debug message level */
364 module_param(sd_msglevel, uint, 0);
366 extern uint sd_f2_blocksize;
367 module_param(sd_f2_blocksize, int, 0);