ext4: add ext4_split_extent_at() and ext4_split_extent()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / brcm80211 / brcmfmac / bcmsdh_linux.c
blobac5bbc8722e5ac586d5a7d6af361bc0c343e5b56
1 /*
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.
17 /**
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>
27 #include <pcicfg.h>
28 #include <bcmdefs.h>
29 #include <bcmdevs.h>
30 #include <bcmutils.h>
32 #if defined(OOB_INTR_ONLY)
33 #include <linux/irq.h>
34 extern void dhdsdio_isr(void *args);
35 #include <dngl_stats.h>
36 #include <dhd.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 /**
47 * SDIO Host Controller info
49 typedef struct bcmsdh_hc bcmsdh_hc_t;
51 struct bcmsdh_hc {
52 bcmsdh_hc_t *next;
53 #ifdef BCMPLATFORM_BUS
54 struct device *dev; /* platform device handle */
55 #else
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 */
60 void *ch;
61 unsigned int oob_irq;
62 unsigned long oob_flags; /* OOB Host specifiction
63 as edge and etc */
64 bool oob_irq_registered;
65 #if defined(OOB_INTR_ONLY)
66 spinlock_t irq_lock;
67 #endif
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 */
75 #define SDLX_MSG(x)
77 /**
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 */
84 #ifdef BCMSDIOH_STD
85 /* Check for Arasan host controller */
86 if (vendor == VENDOR_SI_IMAGE)
87 return true;
89 /* Check for BRCM 27XX Standard host controller */
90 if (device == BCM27XX_SDIOH_ID && vendor == VENDOR_BROADCOM)
91 return true;
93 /* Check for BRCM Standard host controller */
94 if (device == SDIOH_FPGA_ID && vendor == VENDOR_BROADCOM)
95 return true;
97 /* Check for TI PCIxx21 Standard host controller */
98 if (device == PCIXX21_SDIOH_ID && vendor == VENDOR_TI)
99 return true;
101 if (device == PCIXX21_SDIOH0_ID && vendor == VENDOR_TI)
102 return true;
104 /* Ricoh R5C822 Standard SDIO Host */
105 if (device == R5C822_SDIOH_ID && vendor == VENDOR_RICOH)
106 return true;
108 /* JMicron Standard SDIO Host */
109 if (device == JMICRON_SDIOH_ID && vendor == VENDOR_JMICRON)
110 return true;
111 #endif /* BCMSDIOH_STD */
112 #ifdef BCMSDIOH_SPI
113 /* This is the PciSpiHost. */
114 if (device == SPIH_FPGA_ID && vendor == VENDOR_BROADCOM) {
115 WL_NONE("Found PCI SPI Host Controller\n");
116 return true;
118 #endif /* BCMSDIOH_SPI */
120 return false;
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);
132 #else
133 /* forward declarations */
134 static int __devinit bcmsdh_probe(struct device *dev);
135 static int __devexit bcmsdh_remove(struct device *dev);
136 #endif /* BCMLXSDMMC */
138 #ifndef BCMLXSDMMC
139 static
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;
148 struct resource *r;
149 #endif /* BCMLXSDMMC */
150 int irq = 0;
151 u32 vendevid;
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)
159 return -ENXIO;
160 #endif /* BCMLXSDMMC */
162 #if defined(OOB_INTR_ONLY)
163 #ifdef HW_OOB
164 irq_flags =
165 IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL |
166 IORESOURCE_IRQ_SHAREABLE;
167 #else
168 irq_flags = IRQF_TRIGGER_FALLING;
169 #endif /* HW_OOB */
170 irq = dhd_customer_oob_irq_map(&irq_flags);
171 if (irq < 0) {
172 SDLX_MSG(("%s: Host irq is not defined\n", __func__));
173 return 1;
175 #endif /* defined(OOB_INTR_ONLY) */
176 /* allocate SDIO Host Controller state info */
177 sdhc = kzalloc(sizeof(bcmsdh_hc_t), GFP_ATOMIC);
178 if (!sdhc) {
179 SDLX_MSG(("%s: out of memory\n", __func__));
180 goto err;
182 sdhc->dev = (void *)dev;
184 #ifdef BCMLXSDMMC
185 sdh = bcmsdh_attach((void *)0, (void **)&regs, irq);
186 if (!sdh) {
187 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
188 goto err;
190 #else
191 sdh = bcmsdh_attach((void *)r->start, (void **)&regs, irq);
192 if (!sdh) {
193 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
194 goto err;
196 #endif /* BCMLXSDMMC */
197 sdhc->sdh = sdh;
198 sdhc->oob_irq = irq;
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);
203 #endif
205 /* chain SDIO Host Controller info together */
206 sdhc->next = sdhcinfo;
207 sdhcinfo = sdhc;
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);
214 if (!sdhc->ch) {
215 SDLX_MSG(("%s: device attach failed\n", __func__));
216 goto err;
219 return 0;
221 /* error handling */
222 err:
223 if (sdhc) {
224 if (sdhc->sdh)
225 bcmsdh_detach(sdhc->sdh);
226 kfree(sdhc);
229 return -ENODEV;
232 #ifndef BCMLXSDMMC
233 static
234 #endif /* BCMLXSDMMC */
235 int bcmsdh_remove(struct device *dev)
237 bcmsdh_hc_t *sdhc, *prev;
239 sdhc = sdhcinfo;
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) {
246 if (prev)
247 prev->next = sdhc->next;
248 else
249 sdhcinfo = NULL;
250 break;
252 prev = sdhc;
254 if (!sdhc) {
255 SDLX_MSG(("%s: failed\n", __func__));
256 return 0;
259 /* release SDIO Host Controller info */
260 kfree(sdhc);
262 #if !defined(BCMLXSDMMC)
263 dev_set_drvdata(dev, NULL);
264 #endif /* !defined(BCMLXSDMMC) */
266 return 0;
268 #endif /* BCMPLATFORM_BUS */
270 extern int sdio_function_init(void);
272 int bcmsdh_register(bcmsdh_driver_t *driver)
274 drvinfo = *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;
291 unsigned long flags;
293 spin_lock_irqsave(&sdhcinfo->irq_lock, flags);
294 if (curstate != enable) {
295 if (enable)
296 enable_irq(sdhcinfo->oob_irq);
297 else
298 disable_irq_nosync(sdhcinfo->oob_irq);
299 curstate = enable;
301 spin_unlock_irqrestore(&sdhcinfo->irq_lock, flags);
304 static irqreturn_t wlan_oob_irq(int irq, void *dev_id)
306 dhd_pub_t *dhdp;
308 dhdp = (dhd_pub_t *) dev_get_drvdata(sdhcinfo->dev);
310 bcmsdh_oob_intr_set(0);
312 if (dhdp == NULL) {
313 SDLX_MSG(("Out of band GPIO interrupt fired way too early\n"));
314 return IRQ_HANDLED;
317 dhdsdio_isr((void *)dhdp->bus);
319 return IRQ_HANDLED;
322 int bcmsdh_register_oob_intr(void *dhdp)
324 int error = 0;
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 */
338 error =
339 request_irq(sdhcinfo->oob_irq, wlan_oob_irq,
340 sdhcinfo->oob_flags, "bcmsdh_sdmmc", NULL);
341 if (error)
342 return -ENODEV;
344 irq_set_irq_wake(sdhcinfo->oob_irq, 1);
345 sdhcinfo->oob_irq_registered = true;
348 return 0;
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,
367 1 = SD Power ON. */
368 module_param(sd_power, uint, 0);
370 extern uint sd_clock; /* SD Clock Control, 0 = SD Clock OFF,
371 1 = SD Clock ON */
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);