aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/wl12xx/sdio.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/wl12xx/sdio.c')
-rw-r--r--drivers/net/wireless/wl12xx/sdio.c259
1 files changed, 109 insertions, 150 deletions
diff --git a/drivers/net/wireless/wl12xx/sdio.c b/drivers/net/wireless/wl12xx/sdio.c
index 516a8980723c..468a50553fac 100644
--- a/drivers/net/wireless/wl12xx/sdio.c
+++ b/drivers/net/wireless/wl12xx/sdio.c
@@ -24,6 +24,7 @@
24#include <linux/irq.h> 24#include <linux/irq.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <linux/platform_device.h>
27#include <linux/mmc/sdio_func.h> 28#include <linux/mmc/sdio_func.h>
28#include <linux/mmc/sdio_ids.h> 29#include <linux/mmc/sdio_ids.h>
29#include <linux/mmc/card.h> 30#include <linux/mmc/card.h>
@@ -44,107 +45,67 @@
44#define SDIO_DEVICE_ID_TI_WL1271 0x4076 45#define SDIO_DEVICE_ID_TI_WL1271 0x4076
45#endif 46#endif
46 47
48struct wl12xx_sdio_glue {
49 struct device *dev;
50 struct platform_device *core;
51};
52
47static const struct sdio_device_id wl1271_devices[] __devinitconst = { 53static const struct sdio_device_id wl1271_devices[] __devinitconst = {
48 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) }, 54 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
49 {} 55 {}
50}; 56};
51MODULE_DEVICE_TABLE(sdio, wl1271_devices); 57MODULE_DEVICE_TABLE(sdio, wl1271_devices);
52 58
53static void wl1271_sdio_set_block_size(struct wl1271 *wl, unsigned int blksz) 59static void wl1271_sdio_set_block_size(struct device *child,
54{ 60 unsigned int blksz)
55 sdio_claim_host(wl->if_priv);
56 sdio_set_block_size(wl->if_priv, blksz);
57 sdio_release_host(wl->if_priv);
58}
59
60static inline struct sdio_func *wl_to_func(struct wl1271 *wl)
61{
62 return wl->if_priv;
63}
64
65static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl)
66{
67 return &(wl_to_func(wl)->dev);
68}
69
70static irqreturn_t wl1271_hardirq(int irq, void *cookie)
71{ 61{
72 struct wl1271 *wl = cookie; 62 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
73 unsigned long flags; 63 struct sdio_func *func = dev_to_sdio_func(glue->dev);
74 64
75 wl1271_debug(DEBUG_IRQ, "IRQ"); 65 sdio_claim_host(func);
76 66 sdio_set_block_size(func, blksz);
77 /* complete the ELP completion */ 67 sdio_release_host(func);
78 spin_lock_irqsave(&wl->wl_lock, flags);
79 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
80 if (wl->elp_compl) {
81 complete(wl->elp_compl);
82 wl->elp_compl = NULL;
83 }
84
85 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
86 /* don't enqueue a work right now. mark it as pending */
87 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
88 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
89 disable_irq_nosync(wl->irq);
90 pm_wakeup_event(wl1271_sdio_wl_to_dev(wl), 0);
91 spin_unlock_irqrestore(&wl->wl_lock, flags);
92 return IRQ_HANDLED;
93 }
94 spin_unlock_irqrestore(&wl->wl_lock, flags);
95
96 return IRQ_WAKE_THREAD;
97}
98
99static void wl1271_sdio_disable_interrupts(struct wl1271 *wl)
100{
101 disable_irq(wl->irq);
102}
103
104static void wl1271_sdio_enable_interrupts(struct wl1271 *wl)
105{
106 enable_irq(wl->irq);
107} 68}
108 69
109static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf, 70static void wl12xx_sdio_raw_read(struct device *child, int addr, void *buf,
110 size_t len, bool fixed) 71 size_t len, bool fixed)
111{ 72{
112 int ret; 73 int ret;
113 struct sdio_func *func = wl_to_func(wl); 74 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
75 struct sdio_func *func = dev_to_sdio_func(glue->dev);
114 76
115 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { 77 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
116 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret); 78 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
117 wl1271_debug(DEBUG_SDIO, "sdio read 52 addr 0x%x, byte 0x%02x", 79 dev_dbg(child->parent, "sdio read 52 addr 0x%x, byte 0x%02x\n",
118 addr, ((u8 *)buf)[0]); 80 addr, ((u8 *)buf)[0]);
119 } else { 81 } else {
120 if (fixed) 82 if (fixed)
121 ret = sdio_readsb(func, buf, addr, len); 83 ret = sdio_readsb(func, buf, addr, len);
122 else 84 else
123 ret = sdio_memcpy_fromio(func, buf, addr, len); 85 ret = sdio_memcpy_fromio(func, buf, addr, len);
124 86
125 wl1271_debug(DEBUG_SDIO, "sdio read 53 addr 0x%x, %zu bytes", 87 dev_dbg(child->parent, "sdio read 53 addr 0x%x, %zu bytes\n",
126 addr, len); 88 addr, len);
127 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
128 } 89 }
129 90
130 if (ret) 91 if (ret)
131 wl1271_error("sdio read failed (%d)", ret); 92 dev_err(child->parent, "sdio read failed (%d)\n", ret);
132} 93}
133 94
134static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf, 95static void wl12xx_sdio_raw_write(struct device *child, int addr, void *buf,
135 size_t len, bool fixed) 96 size_t len, bool fixed)
136{ 97{
137 int ret; 98 int ret;
138 struct sdio_func *func = wl_to_func(wl); 99 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
100 struct sdio_func *func = dev_to_sdio_func(glue->dev);
139 101
140 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { 102 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
141 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret); 103 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
142 wl1271_debug(DEBUG_SDIO, "sdio write 52 addr 0x%x, byte 0x%02x", 104 dev_dbg(child->parent, "sdio write 52 addr 0x%x, byte 0x%02x\n",
143 addr, ((u8 *)buf)[0]); 105 addr, ((u8 *)buf)[0]);
144 } else { 106 } else {
145 wl1271_debug(DEBUG_SDIO, "sdio write 53 addr 0x%x, %zu bytes", 107 dev_dbg(child->parent, "sdio write 53 addr 0x%x, %zu bytes\n",
146 addr, len); 108 addr, len);
147 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
148 109
149 if (fixed) 110 if (fixed)
150 ret = sdio_writesb(func, addr, buf, len); 111 ret = sdio_writesb(func, addr, buf, len);
@@ -153,13 +114,13 @@ static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
153 } 114 }
154 115
155 if (ret) 116 if (ret)
156 wl1271_error("sdio write failed (%d)", ret); 117 dev_err(child->parent, "sdio write failed (%d)\n", ret);
157} 118}
158 119
159static int wl1271_sdio_power_on(struct wl1271 *wl) 120static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
160{ 121{
161 struct sdio_func *func = wl_to_func(wl);
162 int ret; 122 int ret;
123 struct sdio_func *func = dev_to_sdio_func(glue->dev);
163 124
164 /* If enabled, tell runtime PM not to power off the card */ 125 /* If enabled, tell runtime PM not to power off the card */
165 if (pm_runtime_enabled(&func->dev)) { 126 if (pm_runtime_enabled(&func->dev)) {
@@ -180,10 +141,10 @@ out:
180 return ret; 141 return ret;
181} 142}
182 143
183static int wl1271_sdio_power_off(struct wl1271 *wl) 144static int wl12xx_sdio_power_off(struct wl12xx_sdio_glue *glue)
184{ 145{
185 struct sdio_func *func = wl_to_func(wl);
186 int ret; 146 int ret;
147 struct sdio_func *func = dev_to_sdio_func(glue->dev);
187 148
188 sdio_disable_func(func); 149 sdio_disable_func(func);
189 sdio_release_host(func); 150 sdio_release_host(func);
@@ -200,46 +161,43 @@ static int wl1271_sdio_power_off(struct wl1271 *wl)
200 return ret; 161 return ret;
201} 162}
202 163
203static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable) 164static int wl12xx_sdio_set_power(struct device *child, bool enable)
204{ 165{
166 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
167
205 if (enable) 168 if (enable)
206 return wl1271_sdio_power_on(wl); 169 return wl12xx_sdio_power_on(glue);
207 else 170 else
208 return wl1271_sdio_power_off(wl); 171 return wl12xx_sdio_power_off(glue);
209} 172}
210 173
211static struct wl1271_if_operations sdio_ops = { 174static struct wl1271_if_operations sdio_ops = {
212 .read = wl1271_sdio_raw_read, 175 .read = wl12xx_sdio_raw_read,
213 .write = wl1271_sdio_raw_write, 176 .write = wl12xx_sdio_raw_write,
214 .power = wl1271_sdio_set_power, 177 .power = wl12xx_sdio_set_power,
215 .dev = wl1271_sdio_wl_to_dev,
216 .enable_irq = wl1271_sdio_enable_interrupts,
217 .disable_irq = wl1271_sdio_disable_interrupts,
218 .set_block_size = wl1271_sdio_set_block_size, 178 .set_block_size = wl1271_sdio_set_block_size,
219}; 179};
220 180
221static int __devinit wl1271_probe(struct sdio_func *func, 181static int __devinit wl1271_probe(struct sdio_func *func,
222 const struct sdio_device_id *id) 182 const struct sdio_device_id *id)
223{ 183{
224 struct ieee80211_hw *hw; 184 struct wl12xx_platform_data *wlan_data;
225 const struct wl12xx_platform_data *wlan_data; 185 struct wl12xx_sdio_glue *glue;
226 struct wl1271 *wl; 186 struct resource res[1];
227 unsigned long irqflags;
228 mmc_pm_flag_t mmcflags; 187 mmc_pm_flag_t mmcflags;
229 int ret; 188 int ret = -ENOMEM;
230 189
231 /* We are only able to handle the wlan function */ 190 /* We are only able to handle the wlan function */
232 if (func->num != 0x02) 191 if (func->num != 0x02)
233 return -ENODEV; 192 return -ENODEV;
234 193
235 hw = wl1271_alloc_hw(); 194 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
236 if (IS_ERR(hw)) 195 if (!glue) {
237 return PTR_ERR(hw); 196 dev_err(&func->dev, "can't allocate glue\n");
238 197 goto out;
239 wl = hw->priv; 198 }
240 199
241 wl->if_priv = func; 200 glue->dev = &func->dev;
242 wl->if_ops = &sdio_ops;
243 201
244 /* Grab access to FN0 for ELP reg. */ 202 /* Grab access to FN0 for ELP reg. */
245 func->card->quirks |= MMC_QUIRK_LENIENT_FN0; 203 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
@@ -250,80 +208,79 @@ static int __devinit wl1271_probe(struct sdio_func *func,
250 wlan_data = wl12xx_get_platform_data(); 208 wlan_data = wl12xx_get_platform_data();
251 if (IS_ERR(wlan_data)) { 209 if (IS_ERR(wlan_data)) {
252 ret = PTR_ERR(wlan_data); 210 ret = PTR_ERR(wlan_data);
253 wl1271_error("missing wlan platform data: %d", ret); 211 dev_err(glue->dev, "missing wlan platform data: %d\n", ret);
254 goto out_free; 212 goto out_free_glue;
255 } 213 }
256 214
257 wl->irq = wlan_data->irq; 215 /* if sdio can keep power while host is suspended, enable wow */
258 wl->ref_clock = wlan_data->board_ref_clock; 216 mmcflags = sdio_get_host_pm_caps(func);
259 wl->tcxo_clock = wlan_data->board_tcxo_clock; 217 dev_dbg(glue->dev, "sdio PM caps = 0x%x\n", mmcflags);
260 wl->platform_quirks = wlan_data->platform_quirks;
261 218
262 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) 219 if (mmcflags & MMC_PM_KEEP_POWER)
263 irqflags = IRQF_TRIGGER_RISING; 220 wlan_data->pwr_in_suspend = true;
264 else 221
265 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; 222 wlan_data->ops = &sdio_ops;
266
267 ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq,
268 irqflags,
269 DRIVER_NAME, wl);
270 if (ret < 0) {
271 wl1271_error("request_irq() failed: %d", ret);
272 goto out_free;
273 }
274 223
275 ret = enable_irq_wake(wl->irq); 224 sdio_set_drvdata(func, glue);
276 if (!ret) {
277 wl->irq_wake_enabled = true;
278 device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 1);
279 225
280 /* if sdio can keep power while host is suspended, enable wow */ 226 /* Tell PM core that we don't need the card to be powered now */
281 mmcflags = sdio_get_host_pm_caps(func); 227 pm_runtime_put_noidle(&func->dev);
282 wl1271_debug(DEBUG_SDIO, "sdio PM caps = 0x%x", mmcflags);
283 228
284 if (mmcflags & MMC_PM_KEEP_POWER) 229 glue->core = platform_device_alloc("wl12xx", -1);
285 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; 230 if (!glue->core) {
231 dev_err(glue->dev, "can't allocate platform_device");
232 ret = -ENOMEM;
233 goto out_free_glue;
286 } 234 }
287 disable_irq(wl->irq);
288 235
289 ret = wl1271_init_ieee80211(wl); 236 glue->core->dev.parent = &func->dev;
290 if (ret)
291 goto out_irq;
292 237
293 ret = wl1271_register_hw(wl); 238 memset(res, 0x00, sizeof(res));
294 if (ret)
295 goto out_irq;
296 239
297 sdio_set_drvdata(func, wl); 240 res[0].start = wlan_data->irq;
241 res[0].flags = IORESOURCE_IRQ;
242 res[0].name = "irq";
298 243
299 /* Tell PM core that we don't need the card to be powered now */ 244 ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
300 pm_runtime_put_noidle(&func->dev); 245 if (ret) {
246 dev_err(glue->dev, "can't add resources\n");
247 goto out_dev_put;
248 }
301 249
250 ret = platform_device_add_data(glue->core, wlan_data,
251 sizeof(*wlan_data));
252 if (ret) {
253 dev_err(glue->dev, "can't add platform data\n");
254 goto out_dev_put;
255 }
256
257 ret = platform_device_add(glue->core);
258 if (ret) {
259 dev_err(glue->dev, "can't add platform device\n");
260 goto out_dev_put;
261 }
302 return 0; 262 return 0;
303 263
304 out_irq: 264out_dev_put:
305 free_irq(wl->irq, wl); 265 platform_device_put(glue->core);
306 266
307 out_free: 267out_free_glue:
308 wl1271_free_hw(wl); 268 kfree(glue);
309 269
270out:
310 return ret; 271 return ret;
311} 272}
312 273
313static void __devexit wl1271_remove(struct sdio_func *func) 274static void __devexit wl1271_remove(struct sdio_func *func)
314{ 275{
315 struct wl1271 *wl = sdio_get_drvdata(func); 276 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
316 277
317 /* Undo decrement done above in wl1271_probe */ 278 /* Undo decrement done above in wl1271_probe */
318 pm_runtime_get_noresume(&func->dev); 279 pm_runtime_get_noresume(&func->dev);
319 280
320 wl1271_unregister_hw(wl); 281 platform_device_del(glue->core);
321 if (wl->irq_wake_enabled) { 282 platform_device_put(glue->core);
322 device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 0); 283 kfree(glue);
323 disable_irq_wake(wl->irq);
324 }
325 free_irq(wl->irq, wl);
326 wl1271_free_hw(wl);
327} 284}
328 285
329#ifdef CONFIG_PM 286#ifdef CONFIG_PM
@@ -332,20 +289,21 @@ static int wl1271_suspend(struct device *dev)
332 /* Tell MMC/SDIO core it's OK to power down the card 289 /* Tell MMC/SDIO core it's OK to power down the card
333 * (if it isn't already), but not to remove it completely */ 290 * (if it isn't already), but not to remove it completely */
334 struct sdio_func *func = dev_to_sdio_func(dev); 291 struct sdio_func *func = dev_to_sdio_func(dev);
335 struct wl1271 *wl = sdio_get_drvdata(func); 292 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
293 struct wl1271 *wl = platform_get_drvdata(glue->core);
336 mmc_pm_flag_t sdio_flags; 294 mmc_pm_flag_t sdio_flags;
337 int ret = 0; 295 int ret = 0;
338 296
339 wl1271_debug(DEBUG_MAC80211, "wl1271 suspend. wow_enabled: %d", 297 dev_dbg(dev, "wl1271 suspend. wow_enabled: %d\n",
340 wl->wow_enabled); 298 wl->wow_enabled);
341 299
342 /* check whether sdio should keep power */ 300 /* check whether sdio should keep power */
343 if (wl->wow_enabled) { 301 if (wl->wow_enabled) {
344 sdio_flags = sdio_get_host_pm_caps(func); 302 sdio_flags = sdio_get_host_pm_caps(func);
345 303
346 if (!(sdio_flags & MMC_PM_KEEP_POWER)) { 304 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
347 wl1271_error("can't keep power while host " 305 dev_err(dev, "can't keep power while host "
348 "is suspended"); 306 "is suspended\n");
349 ret = -EINVAL; 307 ret = -EINVAL;
350 goto out; 308 goto out;
351 } 309 }
@@ -353,7 +311,7 @@ static int wl1271_suspend(struct device *dev)
353 /* keep power while host suspended */ 311 /* keep power while host suspended */
354 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); 312 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
355 if (ret) { 313 if (ret) {
356 wl1271_error("error while trying to keep power"); 314 dev_err(dev, "error while trying to keep power\n");
357 goto out; 315 goto out;
358 } 316 }
359 317
@@ -367,9 +325,10 @@ out:
367static int wl1271_resume(struct device *dev) 325static int wl1271_resume(struct device *dev)
368{ 326{
369 struct sdio_func *func = dev_to_sdio_func(dev); 327 struct sdio_func *func = dev_to_sdio_func(dev);
370 struct wl1271 *wl = sdio_get_drvdata(func); 328 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
329 struct wl1271 *wl = platform_get_drvdata(glue->core);
371 330
372 wl1271_debug(DEBUG_MAC80211, "wl1271 resume"); 331 dev_dbg(dev, "wl1271 resume\n");
373 if (wl->wow_enabled) { 332 if (wl->wow_enabled) {
374 /* claim back host */ 333 /* claim back host */
375 sdio_claim_host(func); 334 sdio_claim_host(func);