diff options
Diffstat (limited to 'drivers/net/wireless/bcmdhd/bcmsdh_linux.c')
-rw-r--r-- | drivers/net/wireless/bcmdhd/bcmsdh_linux.c | 741 |
1 files changed, 741 insertions, 0 deletions
diff --git a/drivers/net/wireless/bcmdhd/bcmsdh_linux.c b/drivers/net/wireless/bcmdhd/bcmsdh_linux.c new file mode 100644 index 00000000000..d467e4b5630 --- /dev/null +++ b/drivers/net/wireless/bcmdhd/bcmsdh_linux.c | |||
@@ -0,0 +1,741 @@ | |||
1 | /* | ||
2 | * SDIO access interface for drivers - linux specific (pci only) | ||
3 | * | ||
4 | * Copyright (C) 1999-2011, Broadcom Corporation | ||
5 | * | ||
6 | * Unless you and Broadcom execute a separate written software license | ||
7 | * agreement governing use of this software, this software is licensed to you | ||
8 | * under the terms of the GNU General Public License version 2 (the "GPL"), | ||
9 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the | ||
10 | * following added to such license: | ||
11 | * | ||
12 | * As a special exception, the copyright holders of this software give you | ||
13 | * permission to link this software with independent modules, and to copy and | ||
14 | * distribute the resulting executable under terms of your choice, provided that | ||
15 | * you also meet, for each linked independent module, the terms and conditions of | ||
16 | * the license of that module. An independent module is a module which is not | ||
17 | * derived from this software. The special exception does not apply to any | ||
18 | * modifications of the software. | ||
19 | * | ||
20 | * Notwithstanding the above, under no circumstances may you combine this | ||
21 | * software in any way with any other Broadcom software provided under a license | ||
22 | * other than the GPL, without Broadcom's express prior written consent. | ||
23 | * | ||
24 | * $Id: bcmsdh_linux.c,v 1.72.6.5 2010-12-23 01:13:15 Exp $ | ||
25 | */ | ||
26 | |||
27 | /** | ||
28 | * @file bcmsdh_linux.c | ||
29 | */ | ||
30 | |||
31 | #define __UNDEF_NO_VERSION__ | ||
32 | |||
33 | #include <typedefs.h> | ||
34 | #include <linuxver.h> | ||
35 | |||
36 | #include <linux/pci.h> | ||
37 | #include <linux/completion.h> | ||
38 | #include <linux/mmc/sdio_func.h> | ||
39 | |||
40 | #include <osl.h> | ||
41 | #include <pcicfg.h> | ||
42 | #include <bcmdefs.h> | ||
43 | #include <bcmdevs.h> | ||
44 | |||
45 | #if defined(OOB_INTR_ONLY) | ||
46 | #include <linux/irq.h> | ||
47 | extern void dhdsdio_isr(void * args); | ||
48 | #include <bcmutils.h> | ||
49 | #include <dngl_stats.h> | ||
50 | #include <dhd.h> | ||
51 | #endif /* defined(OOB_INTR_ONLY) */ | ||
52 | |||
53 | /** | ||
54 | * SDIO Host Controller info | ||
55 | */ | ||
56 | typedef struct bcmsdh_hc bcmsdh_hc_t; | ||
57 | |||
58 | struct bcmsdh_hc { | ||
59 | bcmsdh_hc_t *next; | ||
60 | #ifdef BCMPLATFORM_BUS | ||
61 | struct device *dev; /* platform device handle */ | ||
62 | #else | ||
63 | struct pci_dev *dev; /* pci device handle */ | ||
64 | #endif /* BCMPLATFORM_BUS */ | ||
65 | osl_t *osh; | ||
66 | void *regs; /* SDIO Host Controller address */ | ||
67 | bcmsdh_info_t *sdh; /* SDIO Host Controller handle */ | ||
68 | void *ch; | ||
69 | unsigned int oob_irq; | ||
70 | unsigned long oob_flags; /* OOB Host specifiction as edge and etc */ | ||
71 | bool oob_irq_registered; | ||
72 | bool oob_irq_enable_flag; | ||
73 | #if defined(OOB_INTR_ONLY) | ||
74 | spinlock_t irq_lock; | ||
75 | #endif | ||
76 | }; | ||
77 | static bcmsdh_hc_t *sdhcinfo = NULL; | ||
78 | |||
79 | /* driver info, initialized when bcmsdh_register is called */ | ||
80 | static bcmsdh_driver_t drvinfo = {NULL, NULL}; | ||
81 | |||
82 | /* debugging macros */ | ||
83 | #define SDLX_MSG(x) | ||
84 | |||
85 | /** | ||
86 | * Checks to see if vendor and device IDs match a supported SDIO Host Controller. | ||
87 | */ | ||
88 | bool | ||
89 | bcmsdh_chipmatch(uint16 vendor, uint16 device) | ||
90 | { | ||
91 | /* Add other vendors and devices as required */ | ||
92 | |||
93 | #ifdef BCMSDIOH_STD | ||
94 | /* Check for Arasan host controller */ | ||
95 | if (vendor == VENDOR_SI_IMAGE) { | ||
96 | return (TRUE); | ||
97 | } | ||
98 | /* Check for BRCM 27XX Standard host controller */ | ||
99 | if (device == BCM27XX_SDIOH_ID && vendor == VENDOR_BROADCOM) { | ||
100 | return (TRUE); | ||
101 | } | ||
102 | /* Check for BRCM Standard host controller */ | ||
103 | if (device == SDIOH_FPGA_ID && vendor == VENDOR_BROADCOM) { | ||
104 | return (TRUE); | ||
105 | } | ||
106 | /* Check for TI PCIxx21 Standard host controller */ | ||
107 | if (device == PCIXX21_SDIOH_ID && vendor == VENDOR_TI) { | ||
108 | return (TRUE); | ||
109 | } | ||
110 | if (device == PCIXX21_SDIOH0_ID && vendor == VENDOR_TI) { | ||
111 | return (TRUE); | ||
112 | } | ||
113 | /* Ricoh R5C822 Standard SDIO Host */ | ||
114 | if (device == R5C822_SDIOH_ID && vendor == VENDOR_RICOH) { | ||
115 | return (TRUE); | ||
116 | } | ||
117 | /* JMicron Standard SDIO Host */ | ||
118 | if (device == JMICRON_SDIOH_ID && vendor == VENDOR_JMICRON) { | ||
119 | return (TRUE); | ||
120 | } | ||
121 | |||
122 | #endif /* BCMSDIOH_STD */ | ||
123 | #ifdef BCMSDIOH_SPI | ||
124 | /* This is the PciSpiHost. */ | ||
125 | if (device == SPIH_FPGA_ID && vendor == VENDOR_BROADCOM) { | ||
126 | printf("Found PCI SPI Host Controller\n"); | ||
127 | return (TRUE); | ||
128 | } | ||
129 | |||
130 | #endif /* BCMSDIOH_SPI */ | ||
131 | |||
132 | return (FALSE); | ||
133 | } | ||
134 | |||
135 | #if defined(BCMPLATFORM_BUS) | ||
136 | #if defined(BCMLXSDMMC) | ||
137 | /* forward declarations */ | ||
138 | int bcmsdh_probe_bcmdhd(struct device *dev); | ||
139 | int bcmsdh_remove_bcmdhd(struct device *dev); | ||
140 | |||
141 | EXPORT_SYMBOL(bcmsdh_probe_bcmdhd); | ||
142 | EXPORT_SYMBOL(bcmsdh_remove_bcmdhd); | ||
143 | |||
144 | #else | ||
145 | /* forward declarations */ | ||
146 | static int __devinit bcmsdh_probe_bcmdhd(struct device *dev); | ||
147 | static int __devexit bcmsdh_remove_bcmdhd(struct device *dev); | ||
148 | #endif /* BCMLXSDMMC */ | ||
149 | |||
150 | #ifndef BCMLXSDMMC | ||
151 | static struct device_driver bcmsdh_driver = { | ||
152 | .name = "pxa2xx-mci", | ||
153 | .bus = &platform_bus_type, | ||
154 | .probe = bcmsdh_probe_bcmdhd, | ||
155 | .remove = bcmsdh_remove_bcmdhd, | ||
156 | .suspend = NULL, | ||
157 | .resume = NULL, | ||
158 | }; | ||
159 | #endif /* BCMLXSDMMC */ | ||
160 | |||
161 | #ifndef BCMLXSDMMC | ||
162 | static | ||
163 | #endif /* BCMLXSDMMC */ | ||
164 | int bcmsdh_probe_bcmdhd(struct device *dev) | ||
165 | { | ||
166 | osl_t *osh = NULL; | ||
167 | bcmsdh_hc_t *sdhc = NULL; | ||
168 | ulong regs = 0; | ||
169 | bcmsdh_info_t *sdh = NULL; | ||
170 | struct sdio_func *func = container_of(dev, struct sdio_func, dev); | ||
171 | #if !defined(BCMLXSDMMC) && defined(BCMPLATFORM_BUS) | ||
172 | struct platform_device *pdev; | ||
173 | struct resource *r; | ||
174 | #endif /* BCMLXSDMMC */ | ||
175 | int irq = 0; | ||
176 | uint32 vendevid; | ||
177 | unsigned long irq_flags = 0; | ||
178 | |||
179 | #if !defined(BCMLXSDMMC) && defined(BCMPLATFORM_BUS) | ||
180 | pdev = to_platform_device(dev); | ||
181 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
182 | irq = platform_get_irq(pdev, 0); | ||
183 | if (!r || irq == NO_IRQ) | ||
184 | return -ENXIO; | ||
185 | #endif /* BCMLXSDMMC */ | ||
186 | |||
187 | #if defined(OOB_INTR_ONLY) | ||
188 | #ifdef HW_OOB | ||
189 | irq_flags = | ||
190 | IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL | IORESOURCE_IRQ_SHAREABLE; | ||
191 | #else | ||
192 | irq_flags = IRQF_TRIGGER_FALLING; | ||
193 | #endif /* HW_OOB */ | ||
194 | |||
195 | /* Get customer specific OOB IRQ parametres: IRQ number as IRQ type */ | ||
196 | irq = dhd_customer_oob_irq_map(&irq_flags); | ||
197 | if (irq < 0) { | ||
198 | SDLX_MSG(("%s: Host irq is not defined\n", __FUNCTION__)); | ||
199 | return 1; | ||
200 | } | ||
201 | #endif /* defined(OOB_INTR_ONLY) */ | ||
202 | /* allocate SDIO Host Controller state info */ | ||
203 | if (!(osh = osl_attach(dev, PCI_BUS, FALSE))) { | ||
204 | SDLX_MSG(("%s: osl_attach failed\n", __FUNCTION__)); | ||
205 | goto err; | ||
206 | } | ||
207 | if (!(sdhc = MALLOC(osh, sizeof(bcmsdh_hc_t)))) { | ||
208 | SDLX_MSG(("%s: out of memory, allocated %d bytes\n", | ||
209 | __FUNCTION__, | ||
210 | MALLOCED(osh))); | ||
211 | goto err; | ||
212 | } | ||
213 | bzero(sdhc, sizeof(bcmsdh_hc_t)); | ||
214 | sdhc->osh = osh; | ||
215 | |||
216 | sdhc->dev = (void *)dev; | ||
217 | |||
218 | #ifdef BCMLXSDMMC | ||
219 | if (!(sdh = bcmsdh_attach(osh, (void *)0, | ||
220 | (void **)®s, irq))) { | ||
221 | SDLX_MSG(("%s: bcmsdh_attach failed\n", __FUNCTION__)); | ||
222 | goto err; | ||
223 | } | ||
224 | #else | ||
225 | if (!(sdh = bcmsdh_attach(osh, (void *)r->start, | ||
226 | (void **)®s, irq))) { | ||
227 | SDLX_MSG(("%s: bcmsdh_attach failed\n", __FUNCTION__)); | ||
228 | goto err; | ||
229 | } | ||
230 | #endif /* BCMLXSDMMC */ | ||
231 | sdhc->sdh = sdh; | ||
232 | sdhc->oob_irq = irq; | ||
233 | sdhc->oob_flags = irq_flags; | ||
234 | sdhc->oob_irq_registered = FALSE; /* to make sure.. */ | ||
235 | sdhc->oob_irq_enable_flag = FALSE; | ||
236 | #if defined(OOB_INTR_ONLY) | ||
237 | spin_lock_init(&sdhc->irq_lock); | ||
238 | #endif | ||
239 | |||
240 | /* chain SDIO Host Controller info together */ | ||
241 | sdhc->next = sdhcinfo; | ||
242 | sdhcinfo = sdhc; | ||
243 | /* Read the vendor/device ID from the CIS */ | ||
244 | vendevid = bcmsdh_query_device(sdh); | ||
245 | |||
246 | |||
247 | /* try to attach to the target device */ | ||
248 | if (!(sdhc->ch = drvinfo.attach((vendevid >> 16), | ||
249 | func->device, 0, 0, 0, 0, | ||
250 | (void *)regs, NULL, sdh, dev))) { | ||
251 | SDLX_MSG(("%s: device attach failed\n", __FUNCTION__)); | ||
252 | goto err; | ||
253 | } | ||
254 | |||
255 | return 0; | ||
256 | |||
257 | /* error handling */ | ||
258 | err: | ||
259 | if (sdhc) { | ||
260 | if (sdhc->sdh) | ||
261 | bcmsdh_detach(sdhc->osh, sdhc->sdh); | ||
262 | MFREE(osh, sdhc, sizeof(bcmsdh_hc_t)); | ||
263 | } | ||
264 | if (osh) | ||
265 | osl_detach(osh); | ||
266 | return -ENODEV; | ||
267 | } | ||
268 | |||
269 | #ifndef BCMLXSDMMC | ||
270 | static | ||
271 | #endif /* BCMLXSDMMC */ | ||
272 | int bcmsdh_remove_bcmdhd(struct device *dev) | ||
273 | { | ||
274 | bcmsdh_hc_t *sdhc, *prev; | ||
275 | osl_t *osh; | ||
276 | |||
277 | sdhc = sdhcinfo; | ||
278 | drvinfo.detach(sdhc->ch); | ||
279 | bcmsdh_detach(sdhc->osh, sdhc->sdh); | ||
280 | /* find the SDIO Host Controller state for this pdev and take it out from the list */ | ||
281 | for (sdhc = sdhcinfo, prev = NULL; sdhc; sdhc = sdhc->next) { | ||
282 | if (sdhc->dev == (void *)dev) { | ||
283 | if (prev) | ||
284 | prev->next = sdhc->next; | ||
285 | else | ||
286 | sdhcinfo = NULL; | ||
287 | break; | ||
288 | } | ||
289 | prev = sdhc; | ||
290 | } | ||
291 | if (!sdhc) { | ||
292 | SDLX_MSG(("%s: failed\n", __FUNCTION__)); | ||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | |||
297 | /* release SDIO Host Controller info */ | ||
298 | osh = sdhc->osh; | ||
299 | MFREE(osh, sdhc, sizeof(bcmsdh_hc_t)); | ||
300 | osl_detach(osh); | ||
301 | |||
302 | #if !defined(BCMLXSDMMC) || defined(OOB_INTR_ONLY) | ||
303 | dev_set_drvdata(dev, NULL); | ||
304 | #endif /* !defined(BCMLXSDMMC) || defined(OOB_INTR_ONLY) */ | ||
305 | |||
306 | return 0; | ||
307 | } | ||
308 | |||
309 | #else /* BCMPLATFORM_BUS */ | ||
310 | |||
311 | #if !defined(BCMLXSDMMC) | ||
312 | /* forward declarations for PCI probe and remove functions. */ | ||
313 | static int __devinit bcmsdh_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent); | ||
314 | static void __devexit bcmsdh_pci_remove(struct pci_dev *pdev); | ||
315 | |||
316 | /** | ||
317 | * pci id table | ||
318 | */ | ||
319 | static struct pci_device_id bcmsdh_pci_devid[] __devinitdata = { | ||
320 | { vendor: PCI_ANY_ID, | ||
321 | device: PCI_ANY_ID, | ||
322 | subvendor: PCI_ANY_ID, | ||
323 | subdevice: PCI_ANY_ID, | ||
324 | class: 0, | ||
325 | class_mask: 0, | ||
326 | driver_data: 0, | ||
327 | }, | ||
328 | { 0, } | ||
329 | }; | ||
330 | MODULE_DEVICE_TABLE(pci, bcmsdh_pci_devid); | ||
331 | |||
332 | /** | ||
333 | * SDIO Host Controller pci driver info | ||
334 | */ | ||
335 | static struct pci_driver bcmsdh_pci_driver = { | ||
336 | node: {}, | ||
337 | name: "bcmsdh", | ||
338 | id_table: bcmsdh_pci_devid, | ||
339 | probe: bcmsdh_pci_probe, | ||
340 | remove: bcmsdh_pci_remove, | ||
341 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) | ||
342 | save_state: NULL, | ||
343 | #endif | ||
344 | suspend: NULL, | ||
345 | resume: NULL, | ||
346 | }; | ||
347 | |||
348 | |||
349 | extern uint sd_pci_slot; /* Force detection to a particular PCI */ | ||
350 | /* slot only . Allows for having multiple */ | ||
351 | /* WL devices at once in a PC */ | ||
352 | /* Only one instance of dhd will be */ | ||
353 | /* usable at a time */ | ||
354 | /* Upper word is bus number, */ | ||
355 | /* lower word is slot number */ | ||
356 | /* Default value of 0xffffffff turns this */ | ||
357 | /* off */ | ||
358 | module_param(sd_pci_slot, uint, 0); | ||
359 | |||
360 | |||
361 | /** | ||
362 | * Detect supported SDIO Host Controller and attach if found. | ||
363 | * | ||
364 | * Determine if the device described by pdev is a supported SDIO Host | ||
365 | * Controller. If so, attach to it and attach to the target device. | ||
366 | */ | ||
367 | static int __devinit | ||
368 | bcmsdh_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | ||
369 | { | ||
370 | osl_t *osh = NULL; | ||
371 | bcmsdh_hc_t *sdhc = NULL; | ||
372 | ulong regs; | ||
373 | bcmsdh_info_t *sdh = NULL; | ||
374 | int rc; | ||
375 | |||
376 | if (sd_pci_slot != 0xFFFFffff) { | ||
377 | if (pdev->bus->number != (sd_pci_slot>>16) || | ||
378 | PCI_SLOT(pdev->devfn) != (sd_pci_slot&0xffff)) { | ||
379 | SDLX_MSG(("%s: %s: bus %X, slot %X, vend %X, dev %X\n", | ||
380 | __FUNCTION__, | ||
381 | bcmsdh_chipmatch(pdev->vendor, pdev->device) | ||
382 | ?"Found compatible SDIOHC" | ||
383 | :"Probing unknown device", | ||
384 | pdev->bus->number, PCI_SLOT(pdev->devfn), pdev->vendor, | ||
385 | pdev->device)); | ||
386 | return -ENODEV; | ||
387 | } | ||
388 | SDLX_MSG(("%s: %s: bus %X, slot %X, vendor %X, device %X (good PCI location)\n", | ||
389 | __FUNCTION__, | ||
390 | bcmsdh_chipmatch(pdev->vendor, pdev->device) | ||
391 | ?"Using compatible SDIOHC" | ||
392 | :"WARNING, forced use of unkown device", | ||
393 | pdev->bus->number, PCI_SLOT(pdev->devfn), pdev->vendor, pdev->device)); | ||
394 | } | ||
395 | |||
396 | if ((pdev->vendor == VENDOR_TI) && ((pdev->device == PCIXX21_FLASHMEDIA_ID) || | ||
397 | (pdev->device == PCIXX21_FLASHMEDIA0_ID))) { | ||
398 | uint32 config_reg; | ||
399 | |||
400 | SDLX_MSG(("%s: Disabling TI FlashMedia Controller.\n", __FUNCTION__)); | ||
401 | if (!(osh = osl_attach(pdev, PCI_BUS, FALSE))) { | ||
402 | SDLX_MSG(("%s: osl_attach failed\n", __FUNCTION__)); | ||
403 | goto err; | ||
404 | } | ||
405 | |||
406 | config_reg = OSL_PCI_READ_CONFIG(osh, 0x4c, 4); | ||
407 | |||
408 | /* | ||
409 | * Set MMC_SD_DIS bit in FlashMedia Controller. | ||
410 | * Disbling the SD/MMC Controller in the FlashMedia Controller | ||
411 | * allows the Standard SD Host Controller to take over control | ||
412 | * of the SD Slot. | ||
413 | */ | ||
414 | config_reg |= 0x02; | ||
415 | OSL_PCI_WRITE_CONFIG(osh, 0x4c, 4, config_reg); | ||
416 | osl_detach(osh); | ||
417 | } | ||
418 | /* match this pci device with what we support */ | ||
419 | /* we can't solely rely on this to believe it is our SDIO Host Controller! */ | ||
420 | if (!bcmsdh_chipmatch(pdev->vendor, pdev->device)) { | ||
421 | return -ENODEV; | ||
422 | } | ||
423 | |||
424 | /* this is a pci device we might support */ | ||
425 | SDLX_MSG(("%s: Found possible SDIO Host Controller: bus %d slot %d func %d irq %d\n", | ||
426 | __FUNCTION__, | ||
427 | pdev->bus->number, PCI_SLOT(pdev->devfn), | ||
428 | PCI_FUNC(pdev->devfn), pdev->irq)); | ||
429 | |||
430 | /* use bcmsdh_query_device() to get the vendor ID of the target device so | ||
431 | * it will eventually appear in the Broadcom string on the console | ||
432 | */ | ||
433 | |||
434 | /* allocate SDIO Host Controller state info */ | ||
435 | if (!(osh = osl_attach(pdev, PCI_BUS, FALSE))) { | ||
436 | SDLX_MSG(("%s: osl_attach failed\n", __FUNCTION__)); | ||
437 | goto err; | ||
438 | } | ||
439 | if (!(sdhc = MALLOC(osh, sizeof(bcmsdh_hc_t)))) { | ||
440 | SDLX_MSG(("%s: out of memory, allocated %d bytes\n", | ||
441 | __FUNCTION__, | ||
442 | MALLOCED(osh))); | ||
443 | goto err; | ||
444 | } | ||
445 | bzero(sdhc, sizeof(bcmsdh_hc_t)); | ||
446 | sdhc->osh = osh; | ||
447 | |||
448 | sdhc->dev = pdev; | ||
449 | |||
450 | /* map to address where host can access */ | ||
451 | pci_set_master(pdev); | ||
452 | rc = pci_enable_device(pdev); | ||
453 | if (rc) { | ||
454 | SDLX_MSG(("%s: Cannot enable PCI device\n", __FUNCTION__)); | ||
455 | goto err; | ||
456 | } | ||
457 | if (!(sdh = bcmsdh_attach(osh, (void *)(uintptr)pci_resource_start(pdev, 0), | ||
458 | (void **)®s, pdev->irq))) { | ||
459 | SDLX_MSG(("%s: bcmsdh_attach failed\n", __FUNCTION__)); | ||
460 | goto err; | ||
461 | } | ||
462 | |||
463 | sdhc->sdh = sdh; | ||
464 | |||
465 | /* try to attach to the target device */ | ||
466 | if (!(sdhc->ch = drvinfo.attach(VENDOR_BROADCOM, /* pdev->vendor, */ | ||
467 | bcmsdh_query_device(sdh) & 0xFFFF, 0, 0, 0, 0, | ||
468 | (void *)regs, NULL, sdh, pdev->dev))) { | ||
469 | SDLX_MSG(("%s: device attach failed\n", __FUNCTION__)); | ||
470 | goto err; | ||
471 | } | ||
472 | |||
473 | /* chain SDIO Host Controller info together */ | ||
474 | sdhc->next = sdhcinfo; | ||
475 | sdhcinfo = sdhc; | ||
476 | |||
477 | return 0; | ||
478 | |||
479 | /* error handling */ | ||
480 | err: | ||
481 | if (sdhc) { | ||
482 | if (sdhc->sdh) | ||
483 | bcmsdh_detach(sdhc->osh, sdhc->sdh); | ||
484 | MFREE(osh, sdhc, sizeof(bcmsdh_hc_t)); | ||
485 | } | ||
486 | if (osh) | ||
487 | osl_detach(osh); | ||
488 | return -ENODEV; | ||
489 | } | ||
490 | |||
491 | |||
492 | /** | ||
493 | * Detach from target devices and SDIO Host Controller | ||
494 | */ | ||
495 | static void __devexit | ||
496 | bcmsdh_pci_remove(struct pci_dev *pdev) | ||
497 | { | ||
498 | bcmsdh_hc_t *sdhc, *prev; | ||
499 | osl_t *osh; | ||
500 | |||
501 | /* find the SDIO Host Controller state for this pdev and take it out from the list */ | ||
502 | for (sdhc = sdhcinfo, prev = NULL; sdhc; sdhc = sdhc->next) { | ||
503 | if (sdhc->dev == pdev) { | ||
504 | if (prev) | ||
505 | prev->next = sdhc->next; | ||
506 | else | ||
507 | sdhcinfo = NULL; | ||
508 | break; | ||
509 | } | ||
510 | prev = sdhc; | ||
511 | } | ||
512 | if (!sdhc) | ||
513 | return; | ||
514 | |||
515 | drvinfo.detach(sdhc->ch); | ||
516 | |||
517 | bcmsdh_detach(sdhc->osh, sdhc->sdh); | ||
518 | |||
519 | /* release SDIO Host Controller info */ | ||
520 | osh = sdhc->osh; | ||
521 | MFREE(osh, sdhc, sizeof(bcmsdh_hc_t)); | ||
522 | osl_detach(osh); | ||
523 | } | ||
524 | #endif /* BCMLXSDMMC */ | ||
525 | #endif /* BCMPLATFORM_BUS */ | ||
526 | |||
527 | extern int sdio_function_init(void); | ||
528 | |||
529 | int | ||
530 | bcmsdh_register(bcmsdh_driver_t *driver) | ||
531 | { | ||
532 | int error = 0; | ||
533 | |||
534 | drvinfo = *driver; | ||
535 | |||
536 | #if defined(BCMPLATFORM_BUS) | ||
537 | #if defined(BCMLXSDMMC) | ||
538 | SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n")); | ||
539 | error = sdio_function_init(); | ||
540 | #else | ||
541 | SDLX_MSG(("Intel PXA270 SDIO Driver\n")); | ||
542 | error = driver_register(&bcmsdh_driver); | ||
543 | #endif /* defined(BCMLXSDMMC) */ | ||
544 | return error; | ||
545 | #endif /* defined(BCMPLATFORM_BUS) */ | ||
546 | |||
547 | #if !defined(BCMPLATFORM_BUS) && !defined(BCMLXSDMMC) | ||
548 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) | ||
549 | if (!(error = pci_module_init(&bcmsdh_pci_driver))) | ||
550 | return 0; | ||
551 | #else | ||
552 | if (!(error = pci_register_driver(&bcmsdh_pci_driver))) | ||
553 | return 0; | ||
554 | #endif | ||
555 | |||
556 | SDLX_MSG(("%s: pci_module_init failed 0x%x\n", __FUNCTION__, error)); | ||
557 | #endif /* BCMPLATFORM_BUS */ | ||
558 | |||
559 | return error; | ||
560 | } | ||
561 | |||
562 | extern void sdio_function_cleanup(void); | ||
563 | |||
564 | void | ||
565 | bcmsdh_unregister(void) | ||
566 | { | ||
567 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)) | ||
568 | if (bcmsdh_pci_driver.node.next) | ||
569 | #endif | ||
570 | |||
571 | #if defined(BCMPLATFORM_BUS) && !defined(BCMLXSDMMC) | ||
572 | driver_unregister(&bcmsdh_driver); | ||
573 | #endif | ||
574 | #if defined(BCMLXSDMMC) | ||
575 | sdio_function_cleanup(); | ||
576 | #endif /* BCMLXSDMMC */ | ||
577 | #if !defined(BCMPLATFORM_BUS) && !defined(BCMLXSDMMC) | ||
578 | pci_unregister_driver(&bcmsdh_pci_driver); | ||
579 | #endif /* BCMPLATFORM_BUS */ | ||
580 | } | ||
581 | |||
582 | #if defined(OOB_INTR_ONLY) | ||
583 | void bcmsdh_oob_intr_set(bool enable) | ||
584 | { | ||
585 | static bool curstate = 1; | ||
586 | unsigned long flags; | ||
587 | |||
588 | spin_lock_irqsave(&sdhcinfo->irq_lock, flags); | ||
589 | if (curstate != enable) { | ||
590 | if (enable) | ||
591 | enable_irq(sdhcinfo->oob_irq); | ||
592 | else | ||
593 | disable_irq_nosync(sdhcinfo->oob_irq); | ||
594 | curstate = enable; | ||
595 | } | ||
596 | spin_unlock_irqrestore(&sdhcinfo->irq_lock, flags); | ||
597 | } | ||
598 | |||
599 | static irqreturn_t wlan_oob_irq(int irq, void *dev_id) | ||
600 | { | ||
601 | dhd_pub_t *dhdp; | ||
602 | |||
603 | dhdp = (dhd_pub_t *)dev_get_drvdata(sdhcinfo->dev); | ||
604 | |||
605 | bcmsdh_oob_intr_set(0); | ||
606 | |||
607 | if (dhdp == NULL) { | ||
608 | SDLX_MSG(("Out of band GPIO interrupt fired way too early\n")); | ||
609 | return IRQ_HANDLED; | ||
610 | } | ||
611 | |||
612 | dhdsdio_isr((void *)dhdp->bus); | ||
613 | |||
614 | return IRQ_HANDLED; | ||
615 | } | ||
616 | |||
617 | void *bcmsdh_get_drvdata(void) | ||
618 | { | ||
619 | if (!sdhcinfo) | ||
620 | return NULL; | ||
621 | return dev_get_drvdata(sdhcinfo->dev); | ||
622 | } | ||
623 | |||
624 | int bcmsdh_register_oob_intr(void * dhdp) | ||
625 | { | ||
626 | int error = 0; | ||
627 | |||
628 | SDLX_MSG(("%s Enter \n", __FUNCTION__)); | ||
629 | |||
630 | /* IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL | IORESOURCE_IRQ_SHAREABLE; */ | ||
631 | |||
632 | dev_set_drvdata(sdhcinfo->dev, dhdp); | ||
633 | |||
634 | if (!sdhcinfo->oob_irq_registered) { | ||
635 | SDLX_MSG(("%s IRQ=%d Type=%X \n", __FUNCTION__, | ||
636 | (int)sdhcinfo->oob_irq, (int)sdhcinfo->oob_flags)); | ||
637 | /* Refer to customer Host IRQ docs about proper irqflags definition */ | ||
638 | error = request_irq(sdhcinfo->oob_irq, wlan_oob_irq, sdhcinfo->oob_flags, | ||
639 | "bcmsdh_sdmmc", NULL); | ||
640 | if (error) | ||
641 | return -ENODEV; | ||
642 | |||
643 | enable_irq_wake(sdhcinfo->oob_irq); | ||
644 | sdhcinfo->oob_irq_registered = TRUE; | ||
645 | sdhcinfo->oob_irq_enable_flag = TRUE; | ||
646 | } | ||
647 | |||
648 | return 0; | ||
649 | } | ||
650 | |||
651 | void bcmsdh_set_irq(int flag) | ||
652 | { | ||
653 | if (sdhcinfo->oob_irq_registered && sdhcinfo->oob_irq_enable_flag != flag) { | ||
654 | SDLX_MSG(("%s Flag = %d", __FUNCTION__, flag)); | ||
655 | sdhcinfo->oob_irq_enable_flag = flag; | ||
656 | if (flag) { | ||
657 | enable_irq(sdhcinfo->oob_irq); | ||
658 | enable_irq_wake(sdhcinfo->oob_irq); | ||
659 | } else { | ||
660 | disable_irq_wake(sdhcinfo->oob_irq); | ||
661 | disable_irq(sdhcinfo->oob_irq); | ||
662 | } | ||
663 | } | ||
664 | } | ||
665 | |||
666 | void bcmsdh_unregister_oob_intr(void) | ||
667 | { | ||
668 | SDLX_MSG(("%s: Enter\n", __FUNCTION__)); | ||
669 | |||
670 | if (sdhcinfo->oob_irq_registered == TRUE) { | ||
671 | bcmsdh_set_irq(FALSE); | ||
672 | free_irq(sdhcinfo->oob_irq, NULL); | ||
673 | sdhcinfo->oob_irq_registered = FALSE; | ||
674 | } | ||
675 | } | ||
676 | #endif /* defined(OOB_INTR_ONLY) */ | ||
677 | /* Module parameters specific to each host-controller driver */ | ||
678 | |||
679 | extern uint sd_msglevel; /* Debug message level */ | ||
680 | module_param(sd_msglevel, uint, 0); | ||
681 | |||
682 | extern uint sd_power; /* 0 = SD Power OFF, 1 = SD Power ON. */ | ||
683 | module_param(sd_power, uint, 0); | ||
684 | |||
685 | extern uint sd_clock; /* SD Clock Control, 0 = SD Clock OFF, 1 = SD Clock ON */ | ||
686 | module_param(sd_clock, uint, 0); | ||
687 | |||
688 | extern uint sd_divisor; /* Divisor (-1 means external clock) */ | ||
689 | module_param(sd_divisor, uint, 0); | ||
690 | |||
691 | extern uint sd_sdmode; /* Default is SD4, 0=SPI, 1=SD1, 2=SD4 */ | ||
692 | module_param(sd_sdmode, uint, 0); | ||
693 | |||
694 | extern uint sd_hiok; /* Ok to use hi-speed mode */ | ||
695 | module_param(sd_hiok, uint, 0); | ||
696 | |||
697 | extern uint sd_f2_blocksize; | ||
698 | module_param(sd_f2_blocksize, int, 0); | ||
699 | |||
700 | |||
701 | #ifdef BCMSDH_MODULE | ||
702 | EXPORT_SYMBOL(bcmsdh_attach); | ||
703 | EXPORT_SYMBOL(bcmsdh_detach); | ||
704 | EXPORT_SYMBOL(bcmsdh_intr_query); | ||
705 | EXPORT_SYMBOL(bcmsdh_intr_enable); | ||
706 | EXPORT_SYMBOL(bcmsdh_intr_disable); | ||
707 | EXPORT_SYMBOL(bcmsdh_intr_reg); | ||
708 | EXPORT_SYMBOL(bcmsdh_intr_dereg); | ||
709 | |||
710 | #if defined(DHD_DEBUG) | ||
711 | EXPORT_SYMBOL(bcmsdh_intr_pending); | ||
712 | #endif | ||
713 | |||
714 | EXPORT_SYMBOL(bcmsdh_devremove_reg); | ||
715 | EXPORT_SYMBOL(bcmsdh_cfg_read); | ||
716 | EXPORT_SYMBOL(bcmsdh_cfg_write); | ||
717 | EXPORT_SYMBOL(bcmsdh_cis_read); | ||
718 | EXPORT_SYMBOL(bcmsdh_reg_read); | ||
719 | EXPORT_SYMBOL(bcmsdh_reg_write); | ||
720 | EXPORT_SYMBOL(bcmsdh_regfail); | ||
721 | EXPORT_SYMBOL(bcmsdh_send_buf); | ||
722 | EXPORT_SYMBOL(bcmsdh_recv_buf); | ||
723 | |||
724 | EXPORT_SYMBOL(bcmsdh_rwdata); | ||
725 | EXPORT_SYMBOL(bcmsdh_abort); | ||
726 | EXPORT_SYMBOL(bcmsdh_query_device); | ||
727 | EXPORT_SYMBOL(bcmsdh_query_iofnum); | ||
728 | EXPORT_SYMBOL(bcmsdh_iovar_op); | ||
729 | EXPORT_SYMBOL(bcmsdh_register); | ||
730 | EXPORT_SYMBOL(bcmsdh_unregister); | ||
731 | EXPORT_SYMBOL(bcmsdh_chipmatch); | ||
732 | EXPORT_SYMBOL(bcmsdh_reset); | ||
733 | EXPORT_SYMBOL(bcmsdh_waitlockfree); | ||
734 | |||
735 | EXPORT_SYMBOL(bcmsdh_get_dstatus); | ||
736 | EXPORT_SYMBOL(bcmsdh_cfg_read_word); | ||
737 | EXPORT_SYMBOL(bcmsdh_cfg_write_word); | ||
738 | EXPORT_SYMBOL(bcmsdh_cur_sbwad); | ||
739 | EXPORT_SYMBOL(bcmsdh_chipinfo); | ||
740 | |||
741 | #endif /* BCMSDH_MODULE */ | ||