wl18xx: add a module parameter to control 11a support
[deliverable/linux.git] / drivers / net / wireless / ti / wlcore / sdio.c
CommitLineData
5129dffe
TP
1/*
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>
5129dffe 26#include <linux/vmalloc.h>
025aef8f 27#include <linux/platform_device.h>
197c6283 28#include <linux/mmc/sdio.h>
5129dffe
TP
29#include <linux/mmc/sdio_func.h>
30#include <linux/mmc/sdio_ids.h>
31#include <linux/mmc/card.h>
11251e7e 32#include <linux/mmc/host.h>
19b87173 33#include <linux/gpio.h>
09cecc34 34#include <linux/wl12xx.h>
00cbb3c5 35#include <linux/pm_runtime.h>
5129dffe 36
c31be25a 37#include "wlcore.h"
5129dffe 38#include "wl12xx_80211.h"
00d20100 39#include "io.h"
5129dffe 40
5129dffe
TP
41#ifndef SDIO_VENDOR_ID_TI
42#define SDIO_VENDOR_ID_TI 0x0097
43#endif
44
45#ifndef SDIO_DEVICE_ID_TI_WL1271
46#define SDIO_DEVICE_ID_TI_WL1271 0x4076
47#endif
48
fbe936bc
FB
49struct wl12xx_sdio_glue {
50 struct device *dev;
025aef8f 51 struct platform_device *core;
fbe936bc
FB
52};
53
33dd74c7 54static const struct sdio_device_id wl1271_devices[] __devinitconst = {
5129dffe
TP
55 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
56 {}
57};
58MODULE_DEVICE_TABLE(sdio, wl1271_devices);
59
a390e85c
FB
60static void wl1271_sdio_set_block_size(struct device *child,
61 unsigned int blksz)
a81159ed 62{
a390e85c
FB
63 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
64 struct sdio_func *func = dev_to_sdio_func(glue->dev);
5129dffe 65
a390e85c
FB
66 sdio_claim_host(func);
67 sdio_set_block_size(func, blksz);
68 sdio_release_host(func);
5129dffe
TP
69}
70
a390e85c 71static void wl12xx_sdio_raw_read(struct device *child, int addr, void *buf,
a3b8ea75 72 size_t len, bool fixed)
5129dffe
TP
73{
74 int ret;
a390e85c 75 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
fbe936bc 76 struct sdio_func *func = dev_to_sdio_func(glue->dev);
5129dffe 77
b4748306
EP
78 sdio_claim_host(func);
79
00782136 80 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG)) {
5129dffe 81 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
3c4d3868
LC
82 dev_dbg(child->parent, "sdio read 52 addr 0x%x, byte 0x%02x\n",
83 addr, ((u8 *)buf)[0]);
5129dffe
TP
84 } else {
85 if (fixed)
86 ret = sdio_readsb(func, buf, addr, len);
87 else
88 ret = sdio_memcpy_fromio(func, buf, addr, len);
89
3c4d3868
LC
90 dev_dbg(child->parent, "sdio read 53 addr 0x%x, %zu bytes\n",
91 addr, len);
5129dffe
TP
92 }
93
b4748306
EP
94 sdio_release_host(func);
95
5129dffe 96 if (ret)
3c4d3868 97 dev_err(child->parent, "sdio read failed (%d)\n", ret);
5129dffe
TP
98}
99
a390e85c 100static void wl12xx_sdio_raw_write(struct device *child, int addr, void *buf,
a3b8ea75 101 size_t len, bool fixed)
5129dffe
TP
102{
103 int ret;
a390e85c 104 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
fbe936bc 105 struct sdio_func *func = dev_to_sdio_func(glue->dev);
5129dffe 106
b4748306
EP
107 sdio_claim_host(func);
108
00782136 109 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG)) {
5129dffe 110 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
3c4d3868
LC
111 dev_dbg(child->parent, "sdio write 52 addr 0x%x, byte 0x%02x\n",
112 addr, ((u8 *)buf)[0]);
5129dffe 113 } else {
3c4d3868
LC
114 dev_dbg(child->parent, "sdio write 53 addr 0x%x, %zu bytes\n",
115 addr, len);
5129dffe
TP
116
117 if (fixed)
118 ret = sdio_writesb(func, addr, buf, len);
119 else
120 ret = sdio_memcpy_toio(func, addr, buf, len);
121 }
49063a0d 122
b4748306
EP
123 sdio_release_host(func);
124
5129dffe 125 if (ret)
3c4d3868 126 dev_err(child->parent, "sdio write failed (%d)\n", ret);
49063a0d
OBC
127}
128
a390e85c 129static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
49063a0d 130{
00cbb3c5 131 int ret;
fbe936bc 132 struct sdio_func *func = dev_to_sdio_func(glue->dev);
00cbb3c5 133
86046da4
OBC
134 /* If enabled, tell runtime PM not to power off the card */
135 if (pm_runtime_enabled(&func->dev)) {
136 ret = pm_runtime_get_sync(&func->dev);
a15f1c45 137 if (ret < 0)
86046da4 138 goto out;
b5d6e5f6
OBC
139 } else {
140 /* Runtime PM is disabled: power up the card manually */
141 ret = mmc_power_restore_host(func->card->host);
142 if (ret < 0)
143 goto out;
86046da4 144 }
5129dffe 145
49063a0d
OBC
146 sdio_claim_host(func);
147 sdio_enable_func(func);
b4748306 148 sdio_release_host(func);
2cc78ff7 149
00cbb3c5
OBC
150out:
151 return ret;
49063a0d
OBC
152}
153
a390e85c 154static int wl12xx_sdio_power_off(struct wl12xx_sdio_glue *glue)
49063a0d 155{
11251e7e 156 int ret;
fbe936bc 157 struct sdio_func *func = dev_to_sdio_func(glue->dev);
49063a0d 158
b4748306 159 sdio_claim_host(func);
49063a0d
OBC
160 sdio_disable_func(func);
161 sdio_release_host(func);
2cc78ff7 162
b5d6e5f6 163 /* Power off the card manually, even if runtime PM is enabled. */
11251e7e
IY
164 ret = mmc_power_save_host(func->card->host);
165 if (ret < 0)
166 return ret;
167
86046da4
OBC
168 /* If enabled, let runtime PM know the card is powered off */
169 if (pm_runtime_enabled(&func->dev))
170 ret = pm_runtime_put_sync(&func->dev);
171
172 return ret;
5129dffe
TP
173}
174
a390e85c 175static int wl12xx_sdio_set_power(struct device *child, bool enable)
becd551c 176{
a390e85c
FB
177 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
178
49063a0d 179 if (enable)
a390e85c 180 return wl12xx_sdio_power_on(glue);
49063a0d 181 else
a390e85c 182 return wl12xx_sdio_power_off(glue);
becd551c
TP
183}
184
5129dffe 185static struct wl1271_if_operations sdio_ops = {
a390e85c
FB
186 .read = wl12xx_sdio_raw_read,
187 .write = wl12xx_sdio_raw_write,
188 .power = wl12xx_sdio_set_power,
a81159ed 189 .set_block_size = wl1271_sdio_set_block_size,
5129dffe
TP
190};
191
5129dffe
TP
192static int __devinit wl1271_probe(struct sdio_func *func,
193 const struct sdio_device_id *id)
194{
a390e85c 195 struct wl12xx_platform_data *wlan_data;
fbe936bc 196 struct wl12xx_sdio_glue *glue;
025aef8f 197 struct resource res[1];
f795ea8b 198 mmc_pm_flag_t mmcflags;
fbe936bc 199 int ret = -ENOMEM;
197c6283 200 const char *chip_family;
5129dffe
TP
201
202 /* We are only able to handle the wlan function */
203 if (func->num != 0x02)
204 return -ENODEV;
205
fbe936bc
FB
206 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
207 if (!glue) {
3c4d3868 208 dev_err(&func->dev, "can't allocate glue\n");
fbe936bc
FB
209 goto out;
210 }
211
fbe936bc 212 glue->dev = &func->dev;
5129dffe 213
5129dffe
TP
214 /* Grab access to FN0 for ELP reg. */
215 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
216
1d732e8c
AN
217 /* Use block mode for transferring over one block size of data */
218 func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
219
09cecc34
OBC
220 wlan_data = wl12xx_get_platform_data();
221 if (IS_ERR(wlan_data)) {
222 ret = PTR_ERR(wlan_data);
3c4d3868 223 dev_err(glue->dev, "missing wlan platform data: %d\n", ret);
a390e85c 224 goto out_free_glue;
5129dffe
TP
225 }
226
a390e85c
FB
227 /* if sdio can keep power while host is suspended, enable wow */
228 mmcflags = sdio_get_host_pm_caps(func);
3c4d3868 229 dev_dbg(glue->dev, "sdio PM caps = 0x%x\n", mmcflags);
2c0f2463 230
a390e85c
FB
231 if (mmcflags & MMC_PM_KEEP_POWER)
232 wlan_data->pwr_in_suspend = true;
f795ea8b 233
a390e85c 234 wlan_data->ops = &sdio_ops;
5129dffe 235
fbe936bc 236 sdio_set_drvdata(func, glue);
49d7f6d8 237
00cbb3c5
OBC
238 /* Tell PM core that we don't need the card to be powered now */
239 pm_runtime_put_noidle(&func->dev);
240
197c6283
LC
241 /*
242 * Due to a hardware bug, we can't differentiate wl18xx from
243 * wl12xx, because both report the same device ID. The only
244 * way to differentiate is by checking the SDIO revision,
245 * which is 3.00 on the wl18xx chips.
246 */
247 if (func->card->cccr.sdio_vsn == SDIO_SDIO_REV_3_00)
248 chip_family = "wl18xx";
249 else
250 chip_family = "wl12xx";
251
252 glue->core = platform_device_alloc(chip_family, -1);
025aef8f 253 if (!glue->core) {
3c4d3868 254 dev_err(glue->dev, "can't allocate platform_device");
025aef8f 255 ret = -ENOMEM;
a390e85c 256 goto out_free_glue;
025aef8f
FB
257 }
258
259 glue->core->dev.parent = &func->dev;
260
261 memset(res, 0x00, sizeof(res));
262
263 res[0].start = wlan_data->irq;
264 res[0].flags = IORESOURCE_IRQ;
265 res[0].name = "irq";
266
267 ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
268 if (ret) {
3c4d3868 269 dev_err(glue->dev, "can't add resources\n");
025aef8f
FB
270 goto out_dev_put;
271 }
272
273 ret = platform_device_add_data(glue->core, wlan_data,
274 sizeof(*wlan_data));
275 if (ret) {
3c4d3868 276 dev_err(glue->dev, "can't add platform data\n");
025aef8f
FB
277 goto out_dev_put;
278 }
279
280 ret = platform_device_add(glue->core);
281 if (ret) {
3c4d3868 282 dev_err(glue->dev, "can't add platform device\n");
025aef8f
FB
283 goto out_dev_put;
284 }
5129dffe
TP
285 return 0;
286
025aef8f
FB
287out_dev_put:
288 platform_device_put(glue->core);
289
fbe936bc
FB
290out_free_glue:
291 kfree(glue);
a390e85c 292
fbe936bc 293out:
5129dffe
TP
294 return ret;
295}
296
297static void __devexit wl1271_remove(struct sdio_func *func)
298{
fbe936bc 299 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
5129dffe 300
00cbb3c5
OBC
301 /* Undo decrement done above in wl1271_probe */
302 pm_runtime_get_noresume(&func->dev);
303
025aef8f
FB
304 platform_device_del(glue->core);
305 platform_device_put(glue->core);
fbe936bc 306 kfree(glue);
5129dffe
TP
307}
308
f634a4e7 309#ifdef CONFIG_PM
674f3058
OBC
310static int wl1271_suspend(struct device *dev)
311{
312 /* Tell MMC/SDIO core it's OK to power down the card
313 * (if it isn't already), but not to remove it completely */
039bdb14 314 struct sdio_func *func = dev_to_sdio_func(dev);
b6932894
ES
315 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
316 struct wl1271 *wl = platform_get_drvdata(glue->core);
039bdb14
EP
317 mmc_pm_flag_t sdio_flags;
318 int ret = 0;
319
3c4d3868
LC
320 dev_dbg(dev, "wl1271 suspend. wow_enabled: %d\n",
321 wl->wow_enabled);
039bdb14
EP
322
323 /* check whether sdio should keep power */
324 if (wl->wow_enabled) {
325 sdio_flags = sdio_get_host_pm_caps(func);
326
327 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
3c4d3868
LC
328 dev_err(dev, "can't keep power while host "
329 "is suspended\n");
039bdb14
EP
330 ret = -EINVAL;
331 goto out;
332 }
333
334 /* keep power while host suspended */
335 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
336 if (ret) {
3c4d3868 337 dev_err(dev, "error while trying to keep power\n");
039bdb14
EP
338 goto out;
339 }
340 }
341out:
342 return ret;
674f3058
OBC
343}
344
345static int wl1271_resume(struct device *dev)
346{
3c4d3868 347 dev_dbg(dev, "wl1271 resume\n");
f44e5868 348
674f3058
OBC
349 return 0;
350}
351
352static const struct dev_pm_ops wl1271_sdio_pm_ops = {
353 .suspend = wl1271_suspend,
354 .resume = wl1271_resume,
355};
f634a4e7 356#endif
674f3058 357
5129dffe 358static struct sdio_driver wl1271_sdio_driver = {
f4b5d8d8 359 .name = "wl1271_sdio",
5129dffe
TP
360 .id_table = wl1271_devices,
361 .probe = wl1271_probe,
362 .remove = __devexit_p(wl1271_remove),
f634a4e7 363#ifdef CONFIG_PM
674f3058
OBC
364 .drv = {
365 .pm = &wl1271_sdio_pm_ops,
366 },
f634a4e7 367#endif
5129dffe
TP
368};
369
370static int __init wl1271_init(void)
371{
6bdaf796 372 return sdio_register_driver(&wl1271_sdio_driver);
5129dffe
TP
373}
374
375static void __exit wl1271_exit(void)
376{
377 sdio_unregister_driver(&wl1271_sdio_driver);
5129dffe
TP
378}
379
380module_init(wl1271_init);
381module_exit(wl1271_exit);
382
383MODULE_LICENSE("GPL");
5245e3a9 384MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
5129dffe 385MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
4549d09c
EP
386MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE);
387MODULE_FIRMWARE(WL127X_FW_NAME_MULTI);
3fcdab70 388MODULE_FIRMWARE(WL127X_PLT_FW_NAME);
4549d09c
EP
389MODULE_FIRMWARE(WL128X_FW_NAME_SINGLE);
390MODULE_FIRMWARE(WL128X_FW_NAME_MULTI);
3fcdab70 391MODULE_FIRMWARE(WL128X_PLT_FW_NAME);
This page took 0.289171 seconds and 5 git commands to generate.