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 */
47 * SDIO Host Controller info
49 typedef struct bcmsdh_hc bcmsdh_hc_t
;
53 #ifdef BCMPLATFORM_BUS
54 struct device
*dev
; /* platform device handle */
56 struct pci_dev
*dev
; /* pci device handle */
57 #endif /* BCMPLATFORM_BUS */
58 void *regs
; /* SDIO Host Controller address */
59 bcmsdh_info_t
*sdh
; /* SDIO Host Controller handle */
62 unsigned long oob_flags
; /* OOB Host specifiction
64 bool oob_irq_registered
;
65 #if defined(OOB_INTR_ONLY)
69 static bcmsdh_hc_t
*sdhcinfo
;
71 /* driver info, initialized when bcmsdh_register is called */
72 static bcmsdh_driver_t drvinfo
= { NULL
, NULL
};
74 /* debugging macros */
78 * Checks to see if vendor and device IDs match a supported SDIO Host Controller.
80 bool bcmsdh_chipmatch(u16 vendor
, u16 device
)
82 /* Add other vendors and devices as required */
85 /* Check for Arasan host controller */
86 if (vendor
== VENDOR_SI_IMAGE
)
89 /* Check for BRCM 27XX Standard host controller */
90 if (device
== BCM27XX_SDIOH_ID
&& vendor
== VENDOR_BROADCOM
)
93 /* Check for BRCM Standard host controller */
94 if (device
== SDIOH_FPGA_ID
&& vendor
== VENDOR_BROADCOM
)
97 /* Check for TI PCIxx21 Standard host controller */
98 if (device
== PCIXX21_SDIOH_ID
&& vendor
== VENDOR_TI
)
101 if (device
== PCIXX21_SDIOH0_ID
&& vendor
== VENDOR_TI
)
104 /* Ricoh R5C822 Standard SDIO Host */
105 if (device
== R5C822_SDIOH_ID
&& vendor
== VENDOR_RICOH
)
108 /* JMicron Standard SDIO Host */
109 if (device
== JMICRON_SDIOH_ID
&& vendor
== VENDOR_JMICRON
)
111 #endif /* BCMSDIOH_STD */
113 /* This is the PciSpiHost. */
114 if (device
== SPIH_FPGA_ID
&& vendor
== VENDOR_BROADCOM
) {
115 WL_NONE("Found PCI SPI Host Controller\n");
118 #endif /* BCMSDIOH_SPI */
123 #if defined(BCMPLATFORM_BUS)
124 #if defined(BCMLXSDMMC)
125 /* forward declarations */
126 int bcmsdh_probe(struct device
*dev
);
127 EXPORT_SYMBOL(bcmsdh_probe
);
129 int bcmsdh_remove(struct device
*dev
);
130 EXPORT_SYMBOL(bcmsdh_remove
);
133 /* forward declarations */
134 static int __devinit
bcmsdh_probe(struct device
*dev
);
135 static int __devexit
bcmsdh_remove(struct device
*dev
);
136 #endif /* BCMLXSDMMC */
140 #endif /* BCMLXSDMMC */
141 int bcmsdh_probe(struct device
*dev
)
143 bcmsdh_hc_t
*sdhc
= NULL
;
144 unsigned long regs
= 0;
145 bcmsdh_info_t
*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
= dhd_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(bcmsdh_hc_t
), GFP_ATOMIC
);
179 SDLX_MSG(("%s: out of memory\n", __func__
));
182 sdhc
->dev
= (void *)dev
;
185 sdh
= bcmsdh_attach((void *)0, (void **)®s
, irq
);
187 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__
));
191 sdh
= bcmsdh_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
= bcmsdh_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 bcmsdh_detach(sdhc
->sdh
);
234 #endif /* BCMLXSDMMC */
235 int bcmsdh_remove(struct device
*dev
)
237 bcmsdh_hc_t
*sdhc
, *prev
;
240 drvinfo
.detach(sdhc
->ch
);
241 bcmsdh_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 sdio_function_init(void);
272 int bcmsdh_register(bcmsdh_driver_t
*driver
)
276 SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
277 return sdio_function_init();
280 extern void sdio_function_cleanup(void);
282 void bcmsdh_unregister(void)
284 sdio_function_cleanup();
287 #if defined(OOB_INTR_ONLY)
288 void bcmsdh_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
wlan_oob_irq(int irq
, void *dev_id
)
308 dhdp
= (dhd_pub_t
*) dev_get_drvdata(sdhcinfo
->dev
);
310 bcmsdh_oob_intr_set(0);
313 SDLX_MSG(("Out of band GPIO interrupt fired way too early\n"));
317 dhdsdio_isr((void *)dhdp
->bus
);
322 int bcmsdh_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
, wlan_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 bcmsdh_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_power
; /* 0 = SD Power OFF,
368 module_param(sd_power
, uint
, 0);
370 extern uint sd_clock
; /* SD Clock Control, 0 = SD Clock OFF,
372 module_param(sd_clock
, uint
, 0);
374 extern uint sd_divisor
; /* Divisor (-1 means external clock) */
375 module_param(sd_divisor
, uint
, 0);
377 extern uint sd_sdmode
; /* Default is SD4, 0=SPI, 1=SD1, 2=SD4 */
378 module_param(sd_sdmode
, uint
, 0);
380 extern uint sd_hiok
; /* Ok to use hi-speed mode */
381 module_param(sd_hiok
, uint
, 0);
383 extern uint sd_f2_blocksize
;
384 module_param(sd_f2_blocksize
, int, 0);