56e24350bedf36ebd5234f8ff97a7dcfc3c7e4af
[deliverable/linux.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 #include "dngl_stats.h"
35 #include "dhd.h"
36 #include "dhd_bus.h"
37 #include "bcmsdbus.h"
38
39 /**
40 * SDIO Host Controller info
41 */
42 struct sdio_hc {
43 struct sdio_hc *next;
44 struct device *dev; /* platform device handle */
45 void *regs; /* SDIO Host Controller address */
46 struct brcmf_sdio_card *card;
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 sdio_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 sdio_hc *sdhc = NULL;
116 unsigned long regs = 0;
117 struct brcmf_sdio_card *card = 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 sdio_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 card = brcmf_sdcard_attach((void *)0, (void **)&regs, irq);
131 if (!card) {
132 SDLX_MSG(("%s: attach failed\n", __func__));
133 goto err;
134 }
135
136 sdhc->card = card;
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(card);
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, card);
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->card)
161 brcmf_sdcard_detach(sdhc->card);
162 kfree(sdhc);
163 }
164
165 return -ENODEV;
166 }
167
168 int brcmf_sdio_remove(struct device *dev)
169 {
170 struct sdio_hc *sdhc, *prev;
171
172 sdhc = sdhcinfo;
173 drvinfo.detach(sdhc->ch);
174 brcmf_sdcard_detach(sdhc->card);
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 int brcmf_sdio_register(struct brcmf_sdioh_driver *driver)
198 {
199 drvinfo = *driver;
200
201 SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
202 return brcmf_sdio_function_init();
203 }
204
205 void brcmf_sdio_unregister(void)
206 {
207 brcmf_sdio_function_cleanup();
208 }
209
210 /* Module parameters specific to each host-controller driver */
211
212 module_param(sd_msglevel, uint, 0);
213
214 extern uint sd_f2_blocksize;
215 module_param(sd_f2_blocksize, int, 0);
216
217 void brcmf_sdio_wdtmr_enable(bool enable)
218 {
219 if (enable)
220 brcmf_sdbrcm_wd_timer(sdhcinfo->ch, brcmf_watchdog_ms);
221 else
222 brcmf_sdbrcm_wd_timer(sdhcinfo->ch, 0);
223 }
This page took 0.036721 seconds and 4 git commands to generate.