blob: e7ee5d155d347a1cf78c82e0389062fdd8ddb156 [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>
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020026#include <linux/vmalloc.h>
Felipe Balbi025aef82011-10-05 09:00:12 +030027#include <linux/platform_device.h>
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020028#include <linux/mmc/sdio_func.h>
29#include <linux/mmc/sdio_ids.h>
30#include <linux/mmc/card.h>
Ido Yariv11251e72011-02-28 00:13:58 +020031#include <linux/mmc/host.h>
Ohad Ben-Cohen19b87172010-05-13 12:43:24 +030032#include <linux/gpio.h>
Ohad Ben-Cohen09cecc32010-09-16 01:31:35 +020033#include <linux/wl12xx.h>
Ohad Ben-Cohen00cbb3c2010-10-08 16:16:16 +030034#include <linux/pm_runtime.h>
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020035
Shahar Levi00d20102010-11-08 11:20:10 +000036#include "wl12xx.h"
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020037#include "wl12xx_80211.h"
Shahar Levi00d20102010-11-08 11:20:10 +000038#include "io.h"
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020039
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020040#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
Felipe Balbifbe936b2011-10-04 23:10:28 +030048struct wl12xx_sdio_glue {
49 struct device *dev;
50 struct wl1271 *wl;
Felipe Balbi025aef82011-10-05 09:00:12 +030051 struct platform_device *core;
Felipe Balbifbe936b2011-10-04 23:10:28 +030052};
53
Felipe Balbi33dd74c2011-05-14 00:26:18 +030054static const struct sdio_device_id wl1271_devices[] __devinitconst = {
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020055 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
56 {}
57};
58MODULE_DEVICE_TABLE(sdio, wl1271_devices);
59
Ido Yariv0da13da2011-03-31 10:06:58 +020060static void wl1271_sdio_set_block_size(struct wl1271 *wl, unsigned int blksz)
Luciano Coelhoa81159e2011-03-14 14:05:13 +020061{
Luciano Coelhoa81159e2011-03-14 14:05:13 +020062 sdio_claim_host(wl->if_priv);
Ido Yariv0da13da2011-03-31 10:06:58 +020063 sdio_set_block_size(wl->if_priv, blksz);
Luciano Coelhoa81159e2011-03-14 14:05:13 +020064 sdio_release_host(wl->if_priv);
65}
66
Felipe Balbifbe936b2011-10-04 23:10:28 +030067static inline struct wl12xx_sdio_glue *wl_to_glue(struct wl1271 *wl)
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020068{
69 return wl->if_priv;
70}
71
72static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl)
73{
Felipe Balbifbe936b2011-10-04 23:10:28 +030074 return wl_to_glue(wl)->dev;
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020075}
76
Ido Yariva6208652011-03-01 15:14:41 +020077static irqreturn_t wl1271_hardirq(int irq, void *cookie)
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020078{
79 struct wl1271 *wl = cookie;
80 unsigned long flags;
81
82 wl1271_debug(DEBUG_IRQ, "IRQ");
83
84 /* complete the ELP completion */
85 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yariva6208652011-03-01 15:14:41 +020086 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +020087 if (wl->elp_compl) {
88 complete(wl->elp_compl);
89 wl->elp_compl = NULL;
90 }
Eliad Pellerf44e5862011-05-13 11:57:11 +030091
92 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
93 /* don't enqueue a work right now. mark it as pending */
94 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
95 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
96 disable_irq_nosync(wl->irq);
97 pm_wakeup_event(wl1271_sdio_wl_to_dev(wl), 0);
98 spin_unlock_irqrestore(&wl->wl_lock, flags);
99 return IRQ_HANDLED;
100 }
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200101 spin_unlock_irqrestore(&wl->wl_lock, flags);
102
Ido Yariva6208652011-03-01 15:14:41 +0200103 return IRQ_WAKE_THREAD;
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200104}
105
106static void wl1271_sdio_disable_interrupts(struct wl1271 *wl)
107{
108 disable_irq(wl->irq);
109}
110
111static void wl1271_sdio_enable_interrupts(struct wl1271 *wl)
112{
113 enable_irq(wl->irq);
114}
115
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200116static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf,
Teemu Paasikivia3b8ea72010-03-18 12:26:41 +0200117 size_t len, bool fixed)
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200118{
119 int ret;
Felipe Balbifbe936b2011-10-04 23:10:28 +0300120 struct wl12xx_sdio_glue *glue = wl_to_glue(wl);
121 struct sdio_func *func = dev_to_sdio_func(glue->dev);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200122
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200123 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
124 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
Teemu Paasikivia3b8ea72010-03-18 12:26:41 +0200125 wl1271_debug(DEBUG_SDIO, "sdio read 52 addr 0x%x, byte 0x%02x",
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200126 addr, ((u8 *)buf)[0]);
127 } else {
128 if (fixed)
129 ret = sdio_readsb(func, buf, addr, len);
130 else
131 ret = sdio_memcpy_fromio(func, buf, addr, len);
132
Teemu Paasikivi99e50312010-03-26 12:53:16 +0200133 wl1271_debug(DEBUG_SDIO, "sdio read 53 addr 0x%x, %zu bytes",
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200134 addr, len);
Teemu Paasikivia3b8ea72010-03-18 12:26:41 +0200135 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200136 }
137
138 if (ret)
139 wl1271_error("sdio read failed (%d)", ret);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200140}
141
142static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
Teemu Paasikivia3b8ea72010-03-18 12:26:41 +0200143 size_t len, bool fixed)
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200144{
145 int ret;
Felipe Balbifbe936b2011-10-04 23:10:28 +0300146 struct wl12xx_sdio_glue *glue = wl_to_glue(wl);
147 struct sdio_func *func = dev_to_sdio_func(glue->dev);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200148
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200149 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
150 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
Teemu Paasikivia3b8ea72010-03-18 12:26:41 +0200151 wl1271_debug(DEBUG_SDIO, "sdio write 52 addr 0x%x, byte 0x%02x",
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200152 addr, ((u8 *)buf)[0]);
153 } else {
Teemu Paasikivi99e50312010-03-26 12:53:16 +0200154 wl1271_debug(DEBUG_SDIO, "sdio write 53 addr 0x%x, %zu bytes",
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200155 addr, len);
Teemu Paasikivia3b8ea72010-03-18 12:26:41 +0200156 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200157
158 if (fixed)
159 ret = sdio_writesb(func, addr, buf, len);
160 else
161 ret = sdio_memcpy_toio(func, addr, buf, len);
162 }
Ohad Ben-Cohen49063a02010-09-07 04:24:21 +0300163
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200164 if (ret)
165 wl1271_error("sdio write failed (%d)", ret);
Ohad Ben-Cohen49063a02010-09-07 04:24:21 +0300166}
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200167
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200168static int wl1271_sdio_power_on(struct wl1271 *wl)
Ohad Ben-Cohen49063a02010-09-07 04:24:21 +0300169{
Ohad Ben-Cohen00cbb3c2010-10-08 16:16:16 +0300170 int ret;
Felipe Balbifbe936b2011-10-04 23:10:28 +0300171 struct wl12xx_sdio_glue *glue = wl_to_glue(wl);
172 struct sdio_func *func = dev_to_sdio_func(glue->dev);
Ohad Ben-Cohen00cbb3c2010-10-08 16:16:16 +0300173
Ohad Ben-Cohen86046da2011-05-29 16:36:03 +0300174 /* If enabled, tell runtime PM not to power off the card */
175 if (pm_runtime_enabled(&func->dev)) {
176 ret = pm_runtime_get_sync(&func->dev);
Ido Yariva15f1c42011-08-22 23:19:49 +0300177 if (ret < 0)
Ohad Ben-Cohen86046da2011-05-29 16:36:03 +0300178 goto out;
Ohad Ben-Cohenb5d6e5f2011-06-26 18:00:11 +0300179 } else {
180 /* Runtime PM is disabled: power up the card manually */
181 ret = mmc_power_restore_host(func->card->host);
182 if (ret < 0)
183 goto out;
Ohad Ben-Cohen86046da2011-05-29 16:36:03 +0300184 }
Ohad Ben-Cohen49063a02010-09-07 04:24:21 +0300185
186 sdio_claim_host(func);
187 sdio_enable_func(func);
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200188
Ohad Ben-Cohen00cbb3c2010-10-08 16:16:16 +0300189out:
190 return ret;
Ohad Ben-Cohen49063a02010-09-07 04:24:21 +0300191}
192
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200193static int wl1271_sdio_power_off(struct wl1271 *wl)
Ohad Ben-Cohen49063a02010-09-07 04:24:21 +0300194{
Ido Yariv11251e72011-02-28 00:13:58 +0200195 int ret;
Felipe Balbifbe936b2011-10-04 23:10:28 +0300196 struct wl12xx_sdio_glue *glue = wl_to_glue(wl);
197 struct sdio_func *func = dev_to_sdio_func(glue->dev);
Ohad Ben-Cohen49063a02010-09-07 04:24:21 +0300198
Ohad Ben-Cohen49063a02010-09-07 04:24:21 +0300199 sdio_disable_func(func);
200 sdio_release_host(func);
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200201
Ohad Ben-Cohenb5d6e5f2011-06-26 18:00:11 +0300202 /* Power off the card manually, even if runtime PM is enabled. */
Ido Yariv11251e72011-02-28 00:13:58 +0200203 ret = mmc_power_save_host(func->card->host);
204 if (ret < 0)
205 return ret;
206
Ohad Ben-Cohen86046da2011-05-29 16:36:03 +0300207 /* If enabled, let runtime PM know the card is powered off */
208 if (pm_runtime_enabled(&func->dev))
209 ret = pm_runtime_put_sync(&func->dev);
210
211 return ret;
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200212}
213
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200214static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable)
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200215{
Ohad Ben-Cohen49063a02010-09-07 04:24:21 +0300216 if (enable)
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200217 return wl1271_sdio_power_on(wl);
Ohad Ben-Cohen49063a02010-09-07 04:24:21 +0300218 else
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200219 return wl1271_sdio_power_off(wl);
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200220}
221
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200222static struct wl1271_if_operations sdio_ops = {
223 .read = wl1271_sdio_raw_read,
224 .write = wl1271_sdio_raw_write,
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200225 .power = wl1271_sdio_set_power,
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200226 .dev = wl1271_sdio_wl_to_dev,
227 .enable_irq = wl1271_sdio_enable_interrupts,
Luciano Coelhoa81159e2011-03-14 14:05:13 +0200228 .disable_irq = wl1271_sdio_disable_interrupts,
229 .set_block_size = wl1271_sdio_set_block_size,
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200230};
231
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200232static int __devinit wl1271_probe(struct sdio_func *func,
233 const struct sdio_device_id *id)
234{
235 struct ieee80211_hw *hw;
Ohad Ben-Cohen09cecc32010-09-16 01:31:35 +0200236 const struct wl12xx_platform_data *wlan_data;
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200237 struct wl1271 *wl;
Felipe Balbifbe936b2011-10-04 23:10:28 +0300238 struct wl12xx_sdio_glue *glue;
Felipe Balbi025aef82011-10-05 09:00:12 +0300239 struct resource res[1];
Ido Yariv341b7cd2011-03-31 10:07:01 +0200240 unsigned long irqflags;
Eliad Pellerf795ea82011-05-13 11:57:12 +0300241 mmc_pm_flag_t mmcflags;
Felipe Balbifbe936b2011-10-04 23:10:28 +0300242 int ret = -ENOMEM;
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200243
244 /* We are only able to handle the wlan function */
245 if (func->num != 0x02)
246 return -ENODEV;
247
Felipe Balbifbe936b2011-10-04 23:10:28 +0300248 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
249 if (!glue) {
250 wl1271_error("can't allocate glue");
251 goto out;
252 }
253
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200254 hw = wl1271_alloc_hw();
Felipe Balbifbe936b2011-10-04 23:10:28 +0300255 if (IS_ERR(hw)) {
256 wl1271_error("can't allocate hw");
257 ret = PTR_ERR(hw);
258 goto out_free_glue;
259 }
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200260
261 wl = hw->priv;
262
Felipe Balbifbe936b2011-10-04 23:10:28 +0300263 glue->dev = &func->dev;
264 glue->wl = wl;
265
266 wl->if_priv = glue;
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200267 wl->if_ops = &sdio_ops;
268
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200269 /* Grab access to FN0 for ELP reg. */
270 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
271
Arik Nemtsov1d732e82011-03-18 14:49:57 +0200272 /* Use block mode for transferring over one block size of data */
273 func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
274
Ohad Ben-Cohen09cecc32010-09-16 01:31:35 +0200275 wlan_data = wl12xx_get_platform_data();
276 if (IS_ERR(wlan_data)) {
277 ret = PTR_ERR(wlan_data);
278 wl1271_error("missing wlan platform data: %d", ret);
Felipe Balbifbe936b2011-10-04 23:10:28 +0300279 goto out_free_hw;
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200280 }
281
Ohad Ben-Cohen09cecc32010-09-16 01:31:35 +0200282 wl->irq = wlan_data->irq;
Ohad Ben-Cohen15cea992010-09-16 01:31:51 +0200283 wl->ref_clock = wlan_data->board_ref_clock;
Shahar Levi5ea417a2011-03-06 16:32:11 +0200284 wl->tcxo_clock = wlan_data->board_tcxo_clock;
Ido Yariv341b7cd2011-03-31 10:07:01 +0200285 wl->platform_quirks = wlan_data->platform_quirks;
286
287 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
288 irqflags = IRQF_TRIGGER_RISING;
289 else
290 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
Ohad Ben-Cohen09cecc32010-09-16 01:31:35 +0200291
Ido Yariva6208652011-03-01 15:14:41 +0200292 ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq,
Ido Yariv341b7cd2011-03-31 10:07:01 +0200293 irqflags,
Ido Yariva6208652011-03-01 15:14:41 +0200294 DRIVER_NAME, wl);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200295 if (ret < 0) {
296 wl1271_error("request_irq() failed: %d", ret);
Felipe Balbifbe936b2011-10-04 23:10:28 +0300297 goto out_free_hw;
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200298 }
299
Eliad Peller6bb04332011-06-06 12:21:55 +0300300 ret = enable_irq_wake(wl->irq);
301 if (!ret) {
302 wl->irq_wake_enabled = true;
303 device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 1);
Eliad Peller2c0f2462011-05-13 11:57:08 +0300304
Eliad Peller6bb04332011-06-06 12:21:55 +0300305 /* if sdio can keep power while host is suspended, enable wow */
306 mmcflags = sdio_get_host_pm_caps(func);
307 wl1271_debug(DEBUG_SDIO, "sdio PM caps = 0x%x", mmcflags);
308
309 if (mmcflags & MMC_PM_KEEP_POWER)
310 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
311 }
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200312 disable_irq(wl->irq);
313
314 ret = wl1271_init_ieee80211(wl);
315 if (ret)
316 goto out_irq;
317
318 ret = wl1271_register_hw(wl);
319 if (ret)
320 goto out_irq;
321
Felipe Balbifbe936b2011-10-04 23:10:28 +0300322 sdio_set_drvdata(func, glue);
Teemu Paasikivi49d7f6d2010-02-22 08:38:29 +0200323
Ohad Ben-Cohen00cbb3c2010-10-08 16:16:16 +0300324 /* Tell PM core that we don't need the card to be powered now */
325 pm_runtime_put_noidle(&func->dev);
326
Felipe Balbi025aef82011-10-05 09:00:12 +0300327 glue->core = platform_device_alloc("wl12xx-sdio", -1);
328 if (!glue->core) {
329 wl1271_error("can't allocate platform_device");
330 ret = -ENOMEM;
331 goto out_unreg_hw;
332 }
333
334 glue->core->dev.parent = &func->dev;
335
336 memset(res, 0x00, sizeof(res));
337
338 res[0].start = wlan_data->irq;
339 res[0].flags = IORESOURCE_IRQ;
340 res[0].name = "irq";
341
342 ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
343 if (ret) {
344 wl1271_error("can't add resources");
345 goto out_dev_put;
346 }
347
348 ret = platform_device_add_data(glue->core, wlan_data,
349 sizeof(*wlan_data));
350 if (ret) {
351 wl1271_error("can't add platform data");
352 goto out_dev_put;
353 }
354
355 ret = platform_device_add(glue->core);
356 if (ret) {
357 wl1271_error("can't add platform device");
358 goto out_dev_put;
359 }
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200360 return 0;
361
Felipe Balbi025aef82011-10-05 09:00:12 +0300362out_dev_put:
363 platform_device_put(glue->core);
364
365out_unreg_hw:
366 wl1271_unregister_hw(wl);
367
Felipe Balbifbe936b2011-10-04 23:10:28 +0300368out_irq:
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200369 free_irq(wl->irq, wl);
370
Felipe Balbifbe936b2011-10-04 23:10:28 +0300371out_free_hw:
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +0200372 wl1271_free_hw(wl);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200373
Felipe Balbifbe936b2011-10-04 23:10:28 +0300374out_free_glue:
375 kfree(glue);
376out:
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200377 return ret;
378}
379
380static void __devexit wl1271_remove(struct sdio_func *func)
381{
Felipe Balbifbe936b2011-10-04 23:10:28 +0300382 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
383 struct wl1271 *wl = glue->wl;
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200384
Ohad Ben-Cohen00cbb3c2010-10-08 16:16:16 +0300385 /* Undo decrement done above in wl1271_probe */
386 pm_runtime_get_noresume(&func->dev);
387
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +0200388 wl1271_unregister_hw(wl);
Eliad Peller6bb04332011-06-06 12:21:55 +0300389 if (wl->irq_wake_enabled) {
390 device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 0);
391 disable_irq_wake(wl->irq);
392 }
Juuso Oikarinen4e23b112010-08-13 04:46:48 +0200393 free_irq(wl->irq, wl);
Teemu Paasikivi801a6732010-03-18 12:26:42 +0200394 wl1271_free_hw(wl);
Felipe Balbi025aef82011-10-05 09:00:12 +0300395 platform_device_del(glue->core);
396 platform_device_put(glue->core);
Felipe Balbifbe936b2011-10-04 23:10:28 +0300397 kfree(glue);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200398}
399
Luciano Coelhof634a4e2011-05-18 16:51:26 -0400400#ifdef CONFIG_PM
Ohad Ben-Cohen674f3052010-10-08 16:16:27 +0300401static int wl1271_suspend(struct device *dev)
402{
403 /* Tell MMC/SDIO core it's OK to power down the card
404 * (if it isn't already), but not to remove it completely */
Eliad Peller039bdb12011-05-13 11:57:10 +0300405 struct sdio_func *func = dev_to_sdio_func(dev);
406 struct wl1271 *wl = sdio_get_drvdata(func);
407 mmc_pm_flag_t sdio_flags;
408 int ret = 0;
409
410 wl1271_debug(DEBUG_MAC80211, "wl1271 suspend. wow_enabled: %d",
411 wl->wow_enabled);
412
413 /* check whether sdio should keep power */
414 if (wl->wow_enabled) {
415 sdio_flags = sdio_get_host_pm_caps(func);
416
417 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
418 wl1271_error("can't keep power while host "
419 "is suspended");
420 ret = -EINVAL;
421 goto out;
422 }
423
424 /* keep power while host suspended */
425 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
426 if (ret) {
427 wl1271_error("error while trying to keep power");
428 goto out;
429 }
Eliad Pellerf44e5862011-05-13 11:57:11 +0300430
431 /* release host */
432 sdio_release_host(func);
Eliad Peller039bdb12011-05-13 11:57:10 +0300433 }
434out:
435 return ret;
Ohad Ben-Cohen674f3052010-10-08 16:16:27 +0300436}
437
438static int wl1271_resume(struct device *dev)
439{
Eliad Pellerf44e5862011-05-13 11:57:11 +0300440 struct sdio_func *func = dev_to_sdio_func(dev);
441 struct wl1271 *wl = sdio_get_drvdata(func);
442
443 wl1271_debug(DEBUG_MAC80211, "wl1271 resume");
444 if (wl->wow_enabled) {
445 /* claim back host */
446 sdio_claim_host(func);
447 }
448
Ohad Ben-Cohen674f3052010-10-08 16:16:27 +0300449 return 0;
450}
451
452static const struct dev_pm_ops wl1271_sdio_pm_ops = {
453 .suspend = wl1271_suspend,
454 .resume = wl1271_resume,
455};
Luciano Coelhof634a4e2011-05-18 16:51:26 -0400456#endif
Ohad Ben-Cohen674f3052010-10-08 16:16:27 +0300457
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200458static struct sdio_driver wl1271_sdio_driver = {
Luciano Coelhof4b5d8d2010-04-01 11:38:17 +0300459 .name = "wl1271_sdio",
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200460 .id_table = wl1271_devices,
461 .probe = wl1271_probe,
462 .remove = __devexit_p(wl1271_remove),
Luciano Coelhof634a4e2011-05-18 16:51:26 -0400463#ifdef CONFIG_PM
Ohad Ben-Cohen674f3052010-10-08 16:16:27 +0300464 .drv = {
465 .pm = &wl1271_sdio_pm_ops,
466 },
Luciano Coelhof634a4e2011-05-18 16:51:26 -0400467#endif
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200468};
469
470static int __init wl1271_init(void)
471{
Felipe Balbi6bdaf792011-05-14 00:26:20 +0300472 return sdio_register_driver(&wl1271_sdio_driver);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200473}
474
475static void __exit wl1271_exit(void)
476{
477 sdio_unregister_driver(&wl1271_sdio_driver);
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200478}
479
480module_init(wl1271_init);
481module_exit(wl1271_exit);
482
483MODULE_LICENSE("GPL");
Luciano Coelho5245e3a2011-03-30 21:31:39 +0300484MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
Teemu Paasikivi5129dff2010-02-22 08:38:27 +0200485MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
Arik Nemtsovc302b2c2011-08-17 10:45:48 +0300486MODULE_FIRMWARE(WL127X_FW_NAME);
Shahar Levi5aa42342011-03-06 16:32:07 +0200487MODULE_FIRMWARE(WL128X_FW_NAME);