blob: 6e39665ecd89395965bd59ddc2d57ef304875a28 [file] [log] [blame]
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -08001/*
2 * Intel Wireless WiMAX Connection 2400m
3 * Linux driver model glue for the SDIO device, reset & fw upload
4 *
5 *
6 * Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com>
7 * Dirk Brandewie <dirk.j.brandewie@intel.com>
8 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
9 * Yanir Lubetkin <yanirx.lubetkin@intel.com>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License version
13 * 2 as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * 02110-1301, USA.
24 *
25 *
26 * See i2400m-sdio.h for a general description of this driver.
27 *
28 * This file implements driver model glue, and hook ups for the
29 * generic driver to implement the bus-specific functions (device
30 * communication setup/tear down, firmware upload and resetting).
31 *
32 * ROADMAP
33 *
34 * i2400m_probe()
35 * alloc_netdev()
36 * i2400ms_netdev_setup()
37 * i2400ms_init()
38 * i2400m_netdev_setup()
39 * i2400ms_enable_function()
40 * i2400m_setup()
41 *
42 * i2400m_remove()
43 * i2400m_release()
44 * free_netdev(net_dev)
45 *
46 * i2400ms_bus_reset() Called by i2400m->bus_reset
47 * __i2400ms_reset()
48 * __i2400ms_send_barker()
49 *
50 * i2400ms_bus_dev_start() Called by i2400m_dev_start() [who is
51 * i2400ms_tx_setup() called by i2400m_setup()]
52 * i2400ms_rx_setup()
53 *
54 * i2400ms_bus_dev_stop() Called by i2400m_dev_stop() [who is
55 * i2400ms_rx_release() is called by i2400m_release()]
56 * i2400ms_tx_release()
57 *
58 */
59
60#include <linux/debugfs.h>
Tomas Winkler51def0b2009-07-22 14:06:56 +000061#include <linux/mmc/sdio_ids.h>
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -080062#include <linux/mmc/sdio.h>
63#include <linux/mmc/sdio_func.h>
64#include "i2400m-sdio.h"
65#include <linux/wimax/i2400m.h>
66
67#define D_SUBMODULE main
68#include "sdio-debug-levels.h"
69
70/* IOE WiMAX function timeout in seconds */
71static int ioe_timeout = 2;
72module_param(ioe_timeout, int, 0);
73
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -070074static char i2400ms_debug_params[128];
75module_param_string(debug, i2400ms_debug_params, sizeof(i2400ms_debug_params),
76 0644);
77MODULE_PARM_DESC(debug,
78 "String of space-separated NAME:VALUE pairs, where NAMEs "
79 "are the different debug submodules and VALUE are the "
80 "initial debug value to set.");
81
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +000082/* Our firmware file name list */
83static const char *i2400ms_bus_fw_names[] = {
84#define I2400MS_FW_FILE_NAME "i2400m-fw-sdio-1.3.sbcf"
85 I2400MS_FW_FILE_NAME,
86 NULL
87};
88
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -080089
Dirk Brandewie1c0b2dd2009-05-21 11:56:35 -070090static const struct i2400m_poke_table i2400ms_pokes[] = {
91 I2400M_FW_POKE(0x6BE260, 0x00000088),
92 I2400M_FW_POKE(0x080550, 0x00000005),
93 I2400M_FW_POKE(0xAE0000, 0x00000000),
94 I2400M_FW_POKE(0x000000, 0x00000000), /* MUST be 0 terminated or bad
95 * things will happen */
96};
97
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -080098/*
99 * Enable the SDIO function
100 *
101 * Tries to enable the SDIO function; might fail if it is still not
102 * ready (in some hardware, the SDIO WiMAX function is only enabled
103 * when we ask it to explicitly doing). Tries until a timeout is
104 * reached.
105 *
Inaky Perez-Gonzalezc77ca952009-08-31 17:57:56 -0700106 * The @maxtries argument indicates how many times (at most) it should
107 * be tried to enable the function. 0 means forever. This acts along
108 * with the timeout (ie: it'll stop trying as soon as the maximum
109 * number of tries is reached _or_ as soon as the timeout is reached).
110 *
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800111 * The reverse of this is...sdio_disable_function()
112 *
113 * Returns: 0 if the SDIO function was enabled, < 0 errno code on
114 * error (-ENODEV when it was unable to enable the function).
115 */
116static
Inaky Perez-Gonzalezc77ca952009-08-31 17:57:56 -0700117int i2400ms_enable_function(struct sdio_func *func, unsigned maxtries)
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800118{
119 u64 timeout;
120 int err;
121 struct device *dev = &func->dev;
Inaky Perez-Gonzalezc77ca952009-08-31 17:57:56 -0700122 unsigned tries = 0;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800123
124 d_fnstart(3, dev, "(func %p)\n", func);
125 /* Setup timeout (FIXME: This needs to read the CIS table to
126 * get a real timeout) and then wait for the device to signal
127 * it is ready */
128 timeout = get_jiffies_64() + ioe_timeout * HZ;
129 err = -ENODEV;
130 while (err != 0 && time_before64(get_jiffies_64(), timeout)) {
131 sdio_claim_host(func);
Cindy H Kaof2696fb2009-08-17 19:17:58 -0700132 /*
133 * There is a sillicon bug on the IWMC3200, where the
134 * IOE timeout will cause problems on Moorestown
135 * platforms (system hang). We explicitly overwrite
136 * func->enable_timeout here to work around the issue.
137 */
138 if (func->device == SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX)
139 func->enable_timeout = IWMC3200_IOR_TIMEOUT;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800140 err = sdio_enable_func(func);
141 if (0 == err) {
142 sdio_release_host(func);
143 d_printf(2, dev, "SDIO function enabled\n");
144 goto function_enabled;
145 }
146 d_printf(2, dev, "SDIO function failed to enable: %d\n", err);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800147 sdio_release_host(func);
Inaky Perez-Gonzalezc77ca952009-08-31 17:57:56 -0700148 if (maxtries > 0 && ++tries >= maxtries) {
149 err = -ETIME;
150 break;
151 }
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800152 msleep(I2400MS_INIT_SLEEP_INTERVAL);
153 }
154 /* If timed out, device is not there yet -- get -ENODEV so
155 * the device driver core will retry later on. */
156 if (err == -ETIME) {
157 dev_err(dev, "Can't enable WiMAX function; "
158 " has the function been enabled?\n");
159 err = -ENODEV;
160 }
161function_enabled:
162 d_fnend(3, dev, "(func %p) = %d\n", func, err);
163 return err;
164}
165
166
167/*
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700168 * Setup minimal device communication infrastructure needed to at
169 * least be able to update the firmware.
170 */
171static
172int i2400ms_bus_setup(struct i2400m *i2400m)
173{
174 int result;
175 struct i2400ms *i2400ms =
176 container_of(i2400m, struct i2400ms, i2400m);
177 struct device *dev = i2400m_dev(i2400m);
178 struct sdio_func *func = i2400ms->func;
179
180 sdio_claim_host(func);
181 result = sdio_set_block_size(func, I2400MS_BLK_SIZE);
182 sdio_release_host(func);
183 if (result < 0) {
184 dev_err(dev, "Failed to set block size: %d\n", result);
185 goto error_set_blk_size;
186 }
187
188 result = i2400ms_enable_function(func, 1);
189 if (result < 0) {
190 dev_err(dev, "Cannot enable SDIO function: %d\n", result);
191 goto error_func_enable;
192 }
193
194 result = i2400ms_rx_setup(i2400ms);
195 if (result < 0)
196 goto error_rx_setup;
197 return 0;
198
199error_rx_setup:
200 sdio_claim_host(func);
201 sdio_disable_func(func);
202 sdio_release_host(func);
203error_func_enable:
204error_set_blk_size:
205 return result;
206}
207
208
209/*
210 * Tear down minimal device communication infrastructure needed to at
211 * least be able to update the firmware.
212 */
213static
214void i2400ms_bus_release(struct i2400m *i2400m)
215{
216 struct i2400ms *i2400ms =
217 container_of(i2400m, struct i2400ms, i2400m);
218 struct sdio_func *func = i2400ms->func;
219
220 i2400ms_rx_release(i2400ms);
221 sdio_claim_host(func);
222 sdio_disable_func(func);
223 sdio_release_host(func);
224}
225
226
227/*
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800228 * Setup driver resources needed to communicate with the device
229 *
230 * The fw needs some time to settle, and it was just uploaded,
231 * so give it a break first. I'd prefer to just wait for the device to
232 * send something, but seems the poking we do to enable SDIO stuff
233 * interferes with it, so just give it a break before starting...
234 */
235static
236int i2400ms_bus_dev_start(struct i2400m *i2400m)
237{
238 int result;
239 struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
240 struct sdio_func *func = i2400ms->func;
241 struct device *dev = &func->dev;
242
243 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
244 msleep(200);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800245 result = i2400ms_tx_setup(i2400ms);
246 if (result < 0)
247 goto error_tx_setup;
248 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
249 return result;
250
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800251error_tx_setup:
Inaky Perez-Gonzalez16820c12009-05-07 01:02:39 -0700252 i2400ms_tx_release(i2400ms);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800253 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
254 return result;
255}
256
257
258static
259void i2400ms_bus_dev_stop(struct i2400m *i2400m)
260{
261 struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
262 struct sdio_func *func = i2400ms->func;
263 struct device *dev = &func->dev;
264
265 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800266 i2400ms_tx_release(i2400ms);
267 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
268}
269
270
271/*
272 * Sends a barker buffer to the device
273 *
274 * This helper will allocate a kmalloced buffer and use it to transmit
275 * (then free it). Reason for this is that the SDIO host controller
276 * expects alignment (unknown exactly which) which the stack won't
277 * really provide and certain arches/host-controller combinations
278 * cannot use stack/vmalloc/text areas for DMA transfers.
279 */
280static
281int __i2400ms_send_barker(struct i2400ms *i2400ms,
282 const __le32 *barker, size_t barker_size)
283{
284 int ret;
285 struct sdio_func *func = i2400ms->func;
286 struct device *dev = &func->dev;
287 void *buffer;
288
289 ret = -ENOMEM;
290 buffer = kmalloc(I2400MS_BLK_SIZE, GFP_KERNEL);
291 if (buffer == NULL)
292 goto error_kzalloc;
293
294 memcpy(buffer, barker, barker_size);
295 sdio_claim_host(func);
296 ret = sdio_memcpy_toio(func, 0, buffer, I2400MS_BLK_SIZE);
297 sdio_release_host(func);
298
299 if (ret < 0)
300 d_printf(0, dev, "E: barker error: %d\n", ret);
301
302 kfree(buffer);
303error_kzalloc:
304 return ret;
305}
306
307
308/*
309 * Reset a device at different levels (warm, cold or bus)
310 *
311 * @i2400ms: device descriptor
312 * @reset_type: soft, warm or bus reset (I2400M_RT_WARM/SOFT/BUS)
313 *
314 * FIXME: not tested -- need to confirm expected effects
315 *
316 * Warm and cold resets get an SDIO reset if they fail (unimplemented)
317 *
318 * Warm reset:
319 *
320 * The device will be fully reset internally, but won't be
Dirk Brandewie81b182a2009-07-24 09:04:33 -0700321 * disconnected from the bus (so no reenumeration will
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800322 * happen). Firmware upload will be neccessary.
323 *
Dirk Brandewie81b182a2009-07-24 09:04:33 -0700324 * The device will send a reboot barker that will trigger the driver
325 * to reinitialize the state via __i2400m_dev_reset_handle.
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800326 *
Dirk Brandewie81b182a2009-07-24 09:04:33 -0700327 *
328 * Cold and bus reset:
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800329 *
330 * The device will be fully reset internally, disconnected from the
Dirk Brandewie81b182a2009-07-24 09:04:33 -0700331 * bus an a reenumeration will happen. Firmware upload will be
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800332 * neccessary. Thus, we don't do any locking or struct
333 * reinitialization, as we are going to be fully disconnected and
334 * reenumerated.
335 *
336 * Note we need to return -ENODEV if a warm reset was requested and we
337 * had to resort to a bus reset. See i2400m_op_reset(), wimax_reset()
338 * and wimax_dev->op_reset.
339 *
340 * WARNING: no driver state saved/fixed
341 */
342static
343int i2400ms_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
344{
Dirk Brandewie10b1de62009-05-12 07:54:00 -0700345 int result = 0;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800346 struct i2400ms *i2400ms =
347 container_of(i2400m, struct i2400ms, i2400m);
348 struct device *dev = i2400m_dev(i2400m);
349 static const __le32 i2400m_WARM_BOOT_BARKER[4] = {
Harvey Harrisonee437772009-02-01 00:43:54 -0800350 cpu_to_le32(I2400M_WARM_RESET_BARKER),
351 cpu_to_le32(I2400M_WARM_RESET_BARKER),
352 cpu_to_le32(I2400M_WARM_RESET_BARKER),
353 cpu_to_le32(I2400M_WARM_RESET_BARKER),
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800354 };
355 static const __le32 i2400m_COLD_BOOT_BARKER[4] = {
Harvey Harrisonee437772009-02-01 00:43:54 -0800356 cpu_to_le32(I2400M_COLD_RESET_BARKER),
357 cpu_to_le32(I2400M_COLD_RESET_BARKER),
358 cpu_to_le32(I2400M_COLD_RESET_BARKER),
359 cpu_to_le32(I2400M_COLD_RESET_BARKER),
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800360 };
361
362 if (rt == I2400M_RT_WARM)
363 result = __i2400ms_send_barker(i2400ms, i2400m_WARM_BOOT_BARKER,
364 sizeof(i2400m_WARM_BOOT_BARKER));
365 else if (rt == I2400M_RT_COLD)
366 result = __i2400ms_send_barker(i2400ms, i2400m_COLD_BOOT_BARKER,
367 sizeof(i2400m_COLD_BOOT_BARKER));
368 else if (rt == I2400M_RT_BUS) {
369do_bus_reset:
Dirk Brandewie10b1de62009-05-12 07:54:00 -0700370 /* call netif_tx_disable() before sending IOE disable,
371 * so that all the tx from network layer are stopped
372 * while IOE is being reset. Make sure it is called
373 * only after register_netdev() was issued.
374 */
375 if (i2400m->wimax_dev.net_dev->reg_state == NETREG_REGISTERED)
376 netif_tx_disable(i2400m->wimax_dev.net_dev);
377
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700378 i2400ms_bus_release(i2400m);
Dirk Brandewie10b1de62009-05-12 07:54:00 -0700379
380 /* Wait for the device to settle */
381 msleep(40);
382
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700383 result = i2400ms_bus_setup(i2400m);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800384 } else
385 BUG();
386 if (result < 0 && rt != I2400M_RT_BUS) {
387 dev_err(dev, "%s reset failed (%d); trying SDIO reset\n",
388 rt == I2400M_RT_WARM ? "warm" : "cold", result);
389 rt = I2400M_RT_BUS;
390 goto do_bus_reset;
391 }
392 return result;
393}
394
395
396static
397void i2400ms_netdev_setup(struct net_device *net_dev)
398{
399 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
400 struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
401 i2400ms_init(i2400ms);
402 i2400m_netdev_setup(net_dev);
403}
404
405
406/*
407 * Debug levels control; see debug.h
408 */
409struct d_level D_LEVEL[] = {
410 D_SUBMODULE_DEFINE(main),
411 D_SUBMODULE_DEFINE(tx),
412 D_SUBMODULE_DEFINE(rx),
413 D_SUBMODULE_DEFINE(fw),
414};
415size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
416
417
418#define __debugfs_register(prefix, name, parent) \
419do { \
420 result = d_level_register_debugfs(prefix, name, parent); \
421 if (result < 0) \
422 goto error; \
423} while (0)
424
425
426static
427int i2400ms_debugfs_add(struct i2400ms *i2400ms)
428{
429 int result;
430 struct dentry *dentry = i2400ms->i2400m.wimax_dev.debugfs_dentry;
431
432 dentry = debugfs_create_dir("i2400m-usb", dentry);
433 result = PTR_ERR(dentry);
434 if (IS_ERR(dentry)) {
435 if (result == -ENODEV)
436 result = 0; /* No debugfs support */
437 goto error;
438 }
439 i2400ms->debugfs_dentry = dentry;
440 __debugfs_register("dl_", main, dentry);
441 __debugfs_register("dl_", tx, dentry);
442 __debugfs_register("dl_", rx, dentry);
443 __debugfs_register("dl_", fw, dentry);
444
445 return 0;
446
447error:
448 debugfs_remove_recursive(i2400ms->debugfs_dentry);
449 return result;
450}
451
452
Marcel Holtmann384912e2009-08-31 21:08:19 +0000453static struct device_type i2400ms_type = {
454 .name = "wimax",
455};
456
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800457/*
458 * Probe a i2400m interface and register it
459 *
460 * @func: SDIO function
461 * @id: SDIO device ID
462 * @returns: 0 if ok, < 0 errno code on error.
463 *
464 * Alloc a net device, initialize the bus-specific details and then
465 * calls the bus-generic initialization routine. That will register
466 * the wimax and netdev devices, upload the firmware [using
467 * _bus_bm_*()], call _bus_dev_start() to finalize the setup of the
468 * communication with the device and then will start to talk to it to
469 * finnish setting it up.
470 *
471 * Initialization is tricky; some instances of the hw are packed with
472 * others in a way that requires a third driver that enables the WiMAX
473 * function. In those cases, we can't enable the SDIO function and
474 * we'll return with -ENODEV. When the driver that enables the WiMAX
475 * function does its thing, it has to do a bus_rescan_devices() on the
476 * SDIO bus so this driver is called again to enumerate the WiMAX
477 * function.
478 */
479static
480int i2400ms_probe(struct sdio_func *func,
481 const struct sdio_device_id *id)
482{
483 int result;
484 struct net_device *net_dev;
485 struct device *dev = &func->dev;
486 struct i2400m *i2400m;
487 struct i2400ms *i2400ms;
488
489 /* Allocate instance [calls i2400m_netdev_setup() on it]. */
490 result = -ENOMEM;
491 net_dev = alloc_netdev(sizeof(*i2400ms), "wmx%d",
492 i2400ms_netdev_setup);
493 if (net_dev == NULL) {
494 dev_err(dev, "no memory for network device instance\n");
495 goto error_alloc_netdev;
496 }
497 SET_NETDEV_DEV(net_dev, dev);
Marcel Holtmann384912e2009-08-31 21:08:19 +0000498 SET_NETDEV_DEVTYPE(net_dev, &i2400ms_type);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800499 i2400m = net_dev_to_i2400m(net_dev);
500 i2400ms = container_of(i2400m, struct i2400ms, i2400m);
501 i2400m->wimax_dev.net_dev = net_dev;
502 i2400ms->func = func;
503 sdio_set_drvdata(func, i2400ms);
504
505 i2400m->bus_tx_block_size = I2400MS_BLK_SIZE;
506 i2400m->bus_pl_size_max = I2400MS_PL_SIZE_MAX;
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700507 i2400m->bus_setup = i2400ms_bus_setup;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800508 i2400m->bus_dev_start = i2400ms_bus_dev_start;
509 i2400m->bus_dev_stop = i2400ms_bus_dev_stop;
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700510 i2400m->bus_release = i2400ms_bus_release;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800511 i2400m->bus_tx_kick = i2400ms_bus_tx_kick;
512 i2400m->bus_reset = i2400ms_bus_reset;
Inaky Perez-Gonzalezecddfd52009-06-03 16:13:14 +0800513 /* The iwmc3200-wimax sometimes requires the driver to try
514 * hard when we paint it into a corner. */
Dirk Brandewiec3083652009-08-13 13:48:29 -0700515 i2400m->bus_bm_retries = I2400M_SDIO_BOOT_RETRIES;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800516 i2400m->bus_bm_cmd_send = i2400ms_bus_bm_cmd_send;
517 i2400m->bus_bm_wait_for_ack = i2400ms_bus_bm_wait_for_ack;
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000518 i2400m->bus_fw_names = i2400ms_bus_fw_names;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800519 i2400m->bus_bm_mac_addr_impaired = 1;
Dirk Brandewie1c0b2dd2009-05-21 11:56:35 -0700520 i2400m->bus_bm_pokes_table = &i2400ms_pokes[0];
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800521
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700522 /*
523 * Before we are enabling the device interrupt register, make
524 * sure the buffer used during bootmode operation is setup so
525 * when the first D2H data interrupt comes, the memory is
526 * available for copying the D2H data.
527 */
528 result = i2400m_bm_buf_alloc(i2400m);
529 if (result < 0) {
530 dev_err(dev, "cannot allocate SDIO bootmode buffer\n");
531 goto error_bootmode_buf_setup;
532 }
533
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800534 result = i2400m_setup(i2400m, I2400M_BRI_NO_REBOOT);
535 if (result < 0) {
536 dev_err(dev, "cannot setup device: %d\n", result);
537 goto error_setup;
538 }
539
540 result = i2400ms_debugfs_add(i2400ms);
541 if (result < 0) {
542 dev_err(dev, "cannot create SDIO debugfs: %d\n",
543 result);
544 goto error_debugfs_add;
545 }
546 return 0;
547
548error_debugfs_add:
549 i2400m_release(i2400m);
550error_setup:
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700551 i2400m_bm_buf_free(i2400m);
552error_bootmode_buf_setup:
Inaky Perez-Gonzaleza0a4c4c2009-04-30 14:39:21 -0700553 sdio_set_drvdata(func, NULL);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800554 free_netdev(net_dev);
555error_alloc_netdev:
556 return result;
557}
558
559
560static
561void i2400ms_remove(struct sdio_func *func)
562{
563 struct device *dev = &func->dev;
564 struct i2400ms *i2400ms = sdio_get_drvdata(func);
565 struct i2400m *i2400m = &i2400ms->i2400m;
566 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
567
568 d_fnstart(3, dev, "SDIO func %p\n", func);
569 debugfs_remove_recursive(i2400ms->debugfs_dentry);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800570 i2400m_release(i2400m);
571 sdio_set_drvdata(func, NULL);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800572 free_netdev(net_dev);
573 d_fnend(3, dev, "SDIO func %p\n", func);
574}
575
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800576static
577const struct sdio_device_id i2400ms_sdio_ids[] = {
Tomas Winkler51def0b2009-07-22 14:06:56 +0000578 /* Intel: i2400m WiMAX (iwmc3200) over SDIO */
579 { SDIO_DEVICE(SDIO_VENDOR_ID_INTEL,
580 SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX) },
Cindy H Kaof8fc3292009-09-04 17:38:46 -0700581 { SDIO_DEVICE(SDIO_VENDOR_ID_INTEL,
582 SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX_2G5) },
Tomas Winkler51def0b2009-07-22 14:06:56 +0000583 { /* end: all zeroes */ },
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800584};
585MODULE_DEVICE_TABLE(sdio, i2400ms_sdio_ids);
586
587
588static
589struct sdio_driver i2400m_sdio_driver = {
590 .name = KBUILD_MODNAME,
591 .probe = i2400ms_probe,
592 .remove = i2400ms_remove,
593 .id_table = i2400ms_sdio_ids,
594};
595
596
597static
598int __init i2400ms_driver_init(void)
599{
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -0700600 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400ms_debug_params,
601 "i2400m_sdio.debug");
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800602 return sdio_register_driver(&i2400m_sdio_driver);
603}
604module_init(i2400ms_driver_init);
605
606
607static
608void __exit i2400ms_driver_exit(void)
609{
610 flush_scheduled_work(); /* for the stuff we schedule */
611 sdio_unregister_driver(&i2400m_sdio_driver);
612}
613module_exit(i2400ms_driver_exit);
614
615
616MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
617MODULE_DESCRIPTION("Intel 2400M WiMAX networking for SDIO");
618MODULE_LICENSE("GPL");
619MODULE_FIRMWARE(I2400MS_FW_FILE_NAME);