]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/brcm80211/brcmfmac/bcmsdh_linux.c
c4b74ab336c623f384534db48e6db343e51a83f0
[mv-sheeva.git] / drivers / staging / brcm80211 / brcmfmac / bcmsdh_linux.c
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
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.
7  *
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.
15  */
16
17 /**
18  * @file bcmsdh_linux.c
19  */
20
21 #define __UNDEF_NO_VERSION__
22
23 #include <linux/netdevice.h>
24 #include <linux/pci.h>
25 #include <linux/completion.h>
26 #include <linux/sched.h>
27
28 #include <defs.h>
29 #include <brcm_hw_ids.h>
30 #include <brcmu_utils.h>
31 #include <brcmu_wifi.h>
32 #include "sdio_host.h"
33
34 extern void brcmf_sdbrcm_isr(void *args);
35
36 #include "dngl_stats.h"
37 #include "dhd.h"
38
39 /**
40  * SDIO Host Controller info
41  */
42 struct bcmsdh_hc {
43         struct bcmsdh_hc *next;
44         struct device *dev;     /* platform device handle */
45         void *regs;             /* SDIO Host Controller address */
46         struct brcmf_sdio *sdh; /* SDIO Host Controller handle */
47         void *ch;
48         unsigned int oob_irq;
49         unsigned long oob_flags;        /* OOB Host specifiction
50                                         as edge and etc */
51         bool oob_irq_registered;
52 };
53 static struct bcmsdh_hc *sdhcinfo;
54
55 /* driver info, initialized when brcmf_sdio_register is called */
56 static struct brcmf_sdioh_driver drvinfo = { NULL, NULL };
57
58 /* debugging macros */
59 #define SDLX_MSG(x)
60
61 /**
62  * Checks to see if vendor and device IDs match a supported SDIO Host Controller.
63  */
64 bool brcmf_sdio_chipmatch(u16 vendor, u16 device)
65 {
66         /* Add other vendors and devices as required */
67
68 #ifdef BCMSDIOH_STD
69         /* Check for Arasan host controller */
70         if (vendor == VENDOR_SI_IMAGE)
71                 return true;
72
73         /* Check for BRCM 27XX Standard host controller */
74         if (device == BCM27XX_SDIOH_ID && vendor == PCI_VENDOR_ID_BROADCOM)
75                 return true;
76
77         /* Check for BRCM Standard host controller */
78         if (device == SDIOH_FPGA_ID && vendor == PCI_VENDOR_ID_BROADCOM)
79                 return true;
80
81         /* Check for TI PCIxx21 Standard host controller */
82         if (device == PCIXX21_SDIOH_ID && vendor == VENDOR_TI)
83                 return true;
84
85         if (device == PCIXX21_SDIOH0_ID && vendor == VENDOR_TI)
86                 return true;
87
88         /* Ricoh R5C822 Standard SDIO Host */
89         if (device == R5C822_SDIOH_ID && vendor == VENDOR_RICOH)
90                 return true;
91
92         /* JMicron Standard SDIO Host */
93         if (device == JMICRON_SDIOH_ID && vendor == VENDOR_JMICRON)
94                 return true;
95 #endif                          /* BCMSDIOH_STD */
96 #ifdef BCMSDIOH_SPI
97         /* This is the PciSpiHost. */
98         if (device == SPIH_FPGA_ID && vendor == PCI_VENDOR_ID_BROADCOM) {
99                 return true;
100         }
101 #endif                          /* BCMSDIOH_SPI */
102
103         return false;
104 }
105
106 /* forward declarations */
107 int brcmf_sdio_probe(struct device *dev);
108 EXPORT_SYMBOL(brcmf_sdio_probe);
109
110 int brcmf_sdio_remove(struct device *dev);
111 EXPORT_SYMBOL(brcmf_sdio_remove);
112
113 int brcmf_sdio_probe(struct device *dev)
114 {
115         struct bcmsdh_hc *sdhc = NULL;
116         unsigned long regs = 0;
117         struct brcmf_sdio *sdh = NULL;
118         int irq = 0;
119         u32 vendevid;
120         unsigned long irq_flags = 0;
121
122         /* allocate SDIO Host Controller state info */
123         sdhc = kzalloc(sizeof(struct bcmsdh_hc), GFP_ATOMIC);
124         if (!sdhc) {
125                 SDLX_MSG(("%s: out of memory\n", __func__));
126                 goto err;
127         }
128         sdhc->dev = (void *)dev;
129
130         sdh = brcmf_sdcard_attach((void *)0, (void **)&regs, irq);
131         if (!sdh) {
132                 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
133                 goto err;
134         }
135
136         sdhc->sdh = sdh;
137         sdhc->oob_irq = irq;
138         sdhc->oob_flags = irq_flags;
139         sdhc->oob_irq_registered = false;       /* to make sure.. */
140
141         /* chain SDIO Host Controller info together */
142         sdhc->next = sdhcinfo;
143         sdhcinfo = sdhc;
144         /* Read the vendor/device ID from the CIS */
145         vendevid = brcmf_sdcard_query_device(sdh);
146
147         /* try to attach to the target device */
148         sdhc->ch = drvinfo.attach((vendevid >> 16), (vendevid & 0xFFFF),
149                                   0, 0, 0, 0, (void *)regs, sdh);
150         if (!sdhc->ch) {
151                 SDLX_MSG(("%s: device attach failed\n", __func__));
152                 goto err;
153         }
154
155         return 0;
156
157         /* error handling */
158 err:
159         if (sdhc) {
160                 if (sdhc->sdh)
161                         brcmf_sdcard_detach(sdhc->sdh);
162                 kfree(sdhc);
163         }
164
165         return -ENODEV;
166 }
167
168 int brcmf_sdio_remove(struct device *dev)
169 {
170         struct bcmsdh_hc *sdhc, *prev;
171
172         sdhc = sdhcinfo;
173         drvinfo.detach(sdhc->ch);
174         brcmf_sdcard_detach(sdhc->sdh);
175         /* find the SDIO Host Controller state for this pdev
176                  and take it out from the list */
177         for (sdhc = sdhcinfo, prev = NULL; sdhc; sdhc = sdhc->next) {
178                 if (sdhc->dev == (void *)dev) {
179                         if (prev)
180                                 prev->next = sdhc->next;
181                         else
182                                 sdhcinfo = NULL;
183                         break;
184                 }
185                 prev = sdhc;
186         }
187         if (!sdhc) {
188                 SDLX_MSG(("%s: failed\n", __func__));
189                 return 0;
190         }
191
192         /* release SDIO Host Controller info */
193         kfree(sdhc);
194         return 0;
195 }
196
197 extern int brcmf_sdio_function_init(void);
198
199 int brcmf_sdio_register(struct brcmf_sdioh_driver *driver)
200 {
201         drvinfo = *driver;
202
203         SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
204         return brcmf_sdio_function_init();
205 }
206
207 extern void brcmf_sdio_function_cleanup(void);
208
209 void brcmf_sdio_unregister(void)
210 {
211         brcmf_sdio_function_cleanup();
212 }
213
214 /* Module parameters specific to each host-controller driver */
215
216 extern uint sd_msglevel;        /* Debug message level */
217 module_param(sd_msglevel, uint, 0);
218
219 extern uint sd_f2_blocksize;
220 module_param(sd_f2_blocksize, int, 0);