blob: d43e0d41d439c501380dfe4b66313fc260d928a9 [file] [log] [blame]
Teemu Paasikivi5129dff2010-02-22 08:38:27 +02001/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009-2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/irq.h>
25#include <linux/module.h>
26#include <linux/crc7.h>
27#include <linux/vmalloc.h>
28#include <linux/mmc/sdio_func.h>
29#include <linux/mmc/sdio_ids.h>
30#include <linux/mmc/card.h>
31#include <plat/gpio.h>
32
33#include "wl1271.h"
34#include "wl12xx_80211.h"
35#include "wl1271_io.h"
36
37
38#define RX71_WL1271_IRQ_GPIO 42
39
40#ifndef SDIO_VENDOR_ID_TI
41#define SDIO_VENDOR_ID_TI 0x0097
42#endif
43
44#ifndef SDIO_DEVICE_ID_TI_WL1271
45#define SDIO_DEVICE_ID_TI_WL1271 0x4076
46#endif
47
48static const struct sdio_device_id wl1271_devices[] = {
49 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
50 {}
51};
52MODULE_DEVICE_TABLE(sdio, wl1271_devices);
53
54static inline struct sdio_func *wl_to_func(struct wl1271 *wl)
55{
56 return wl->if_priv;
57}
58
59static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl)
60{
61 return &(wl_to_func(wl)->dev);
62}
63
64static irqreturn_t wl1271_irq(int irq, void *cookie)
65{
66 struct wl1271 *wl = cookie;
67 unsigned long flags;
68
69 wl1271_debug(DEBUG_IRQ, "IRQ");
70
71 /* complete the ELP completion */
72 spin_lock_irqsave(&wl->wl_lock, flags);
73 if (wl->elp_compl) {
74 complete(wl->elp_compl);
75 wl->elp_compl = NULL;
76 }
77
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +020078 if (!test_and_set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags))
79 ieee80211_queue_work(wl->hw, &wl->irq_work);
80 set_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020081 spin_unlock_irqrestore(&wl->wl_lock, flags);
82
83 return IRQ_HANDLED;
84}
85
86static void wl1271_sdio_disable_interrupts(struct wl1271 *wl)
87{
88 disable_irq(wl->irq);
89}
90
91static void wl1271_sdio_enable_interrupts(struct wl1271 *wl)
92{
93 enable_irq(wl->irq);
94}
95
96static void wl1271_sdio_reset(struct wl1271 *wl)
97{
98}
99
100static void wl1271_sdio_init(struct wl1271 *wl)
101{
102}
103
104static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf,
105 size_t len, bool fixed)
106{
107 int ret;
108 struct sdio_func *func = wl_to_func(wl);
109
110 sdio_claim_host(func);
111 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
112 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
113 wl1271_debug(DEBUG_SPI, "sdio read 52 addr 0x%x, byte 0x%02x",
114 addr, ((u8 *)buf)[0]);
115 } else {
116 if (fixed)
117 ret = sdio_readsb(func, buf, addr, len);
118 else
119 ret = sdio_memcpy_fromio(func, buf, addr, len);
120
121 wl1271_debug(DEBUG_SPI, "sdio read 53 addr 0x%x, %d bytes",
122 addr, len);
123 wl1271_dump_ascii(DEBUG_SPI, "data: ", buf, len);
124 }
125
126 if (ret)
127 wl1271_error("sdio read failed (%d)", ret);
128
129 sdio_release_host(func);
130}
131
132static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
133 size_t len, bool fixed)
134{
135 int ret;
136 struct sdio_func *func = wl_to_func(wl);
137
138 sdio_claim_host(func);
139 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
140 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
141 wl1271_debug(DEBUG_SPI, "sdio write 52 addr 0x%x, byte 0x%02x",
142 addr, ((u8 *)buf)[0]);
143 } else {
144 wl1271_debug(DEBUG_SPI, "sdio write 53 addr 0x%x, %d bytes",
145 addr, len);
146 wl1271_dump_ascii(DEBUG_SPI, "data: ", buf, len);
147
148 if (fixed)
149 ret = sdio_writesb(func, addr, buf, len);
150 else
151 ret = sdio_memcpy_toio(func, addr, buf, len);
152 }
153 if (ret)
154 wl1271_error("sdio write failed (%d)", ret);
155
156 sdio_release_host(func);
157}
158
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200159static void wl1271_sdio_set_power(struct wl1271 *wl, bool enable)
160{
161}
162
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200163static struct wl1271_if_operations sdio_ops = {
164 .read = wl1271_sdio_raw_read,
165 .write = wl1271_sdio_raw_write,
166 .reset = wl1271_sdio_reset,
167 .init = wl1271_sdio_init,
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200168 .power = wl1271_sdio_set_power,
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200169 .dev = wl1271_sdio_wl_to_dev,
170 .enable_irq = wl1271_sdio_enable_interrupts,
171 .disable_irq = wl1271_sdio_disable_interrupts
172};
173
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200174static int __devinit wl1271_probe(struct sdio_func *func,
175 const struct sdio_device_id *id)
176{
177 struct ieee80211_hw *hw;
178 struct wl1271 *wl;
179 int ret;
180
181 /* We are only able to handle the wlan function */
182 if (func->num != 0x02)
183 return -ENODEV;
184
185 hw = wl1271_alloc_hw();
186 if (IS_ERR(hw))
187 return PTR_ERR(hw);
188
189 wl = hw->priv;
190
191 wl->if_priv = func;
192 wl->if_ops = &sdio_ops;
193
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200194 /* Grab access to FN0 for ELP reg. */
195 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
196
197 wl->irq = gpio_to_irq(RX71_WL1271_IRQ_GPIO);
198 if (wl->irq < 0) {
199 ret = wl->irq;
200 wl1271_error("could not get irq!");
201 goto out_free;
202 }
203
204 ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl);
205 if (ret < 0) {
206 wl1271_error("request_irq() failed: %d", ret);
207 goto out_free;
208 }
209
210 set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
211
212 disable_irq(wl->irq);
213
214 ret = wl1271_init_ieee80211(wl);
215 if (ret)
216 goto out_irq;
217
218 ret = wl1271_register_hw(wl);
219 if (ret)
220 goto out_irq;
221
222 sdio_claim_host(func);
Teemu Paasikivi49d7f6d2010-02-22 08:38:29 +0200223 sdio_set_drvdata(func, wl);
224
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200225 ret = sdio_enable_func(func);
226 if (ret)
227 goto out_release;
228
229 sdio_release_host(func);
230
231 wl1271_notice("initialized");
232
233 return 0;
234
235 out_release:
236 sdio_release_host(func);
237
238 out_irq:
239 free_irq(wl->irq, wl);
240
241
242 out_free:
243 ieee80211_free_hw(hw);
244
245 return ret;
246}
247
248static void __devexit wl1271_remove(struct sdio_func *func)
249{
250 struct wl1271 *wl = sdio_get_drvdata(func);
251
Teemu Paasikivi49d7f6d2010-02-22 08:38:29 +0200252 ieee80211_unregister_hw(wl->hw);
253
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200254 sdio_claim_host(func);
255 sdio_disable_func(func);
256 sdio_release_host(func);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200257
258 free_irq(wl->irq, wl);
259
260 kfree(wl->target_mem_map);
261 vfree(wl->fw);
262 wl->fw = NULL;
263 kfree(wl->nvs);
264 wl->nvs = NULL;
265
266 kfree(wl->fw_status);
267 kfree(wl->tx_res_if);
268
269 ieee80211_free_hw(wl->hw);
270}
271
272static struct sdio_driver wl1271_sdio_driver = {
273 .name = "wl1271",
274 .id_table = wl1271_devices,
275 .probe = wl1271_probe,
276 .remove = __devexit_p(wl1271_remove),
277};
278
279static int __init wl1271_init(void)
280{
281 int ret;
282
283 ret = sdio_register_driver(&wl1271_sdio_driver);
284 if (ret < 0) {
285 wl1271_error("failed to register sdio driver: %d", ret);
286 goto out;
287 }
288
289out:
290 return ret;
291}
292
293static void __exit wl1271_exit(void)
294{
295 sdio_unregister_driver(&wl1271_sdio_driver);
296
297 wl1271_notice("unloaded");
298}
299
300module_init(wl1271_init);
301module_exit(wl1271_exit);
302
303MODULE_LICENSE("GPL");
304MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
305MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
306MODULE_FIRMWARE(WL1271_FW_NAME);