blob: 079f900e9ae5239cb561a2798142274249286ed7 [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 *
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +090046 * i2400ms_bus_reset() Called by i2400m_reset
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -080047 * __i2400ms_reset()
48 * __i2400ms_send_barker()
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -080049 */
50
51#include <linux/debugfs.h>
Tomas Winkler51def0b2009-07-22 14:06:56 +000052#include <linux/mmc/sdio_ids.h>
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -080053#include <linux/mmc/sdio.h>
54#include <linux/mmc/sdio_func.h>
55#include "i2400m-sdio.h"
56#include <linux/wimax/i2400m.h>
57
58#define D_SUBMODULE main
59#include "sdio-debug-levels.h"
60
61/* IOE WiMAX function timeout in seconds */
62static int ioe_timeout = 2;
63module_param(ioe_timeout, int, 0);
64
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -070065static char i2400ms_debug_params[128];
66module_param_string(debug, i2400ms_debug_params, sizeof(i2400ms_debug_params),
67 0644);
68MODULE_PARM_DESC(debug,
69 "String of space-separated NAME:VALUE pairs, where NAMEs "
70 "are the different debug submodules and VALUE are the "
71 "initial debug value to set.");
72
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +000073/* Our firmware file name list */
74static const char *i2400ms_bus_fw_names[] = {
75#define I2400MS_FW_FILE_NAME "i2400m-fw-sdio-1.3.sbcf"
76 I2400MS_FW_FILE_NAME,
77 NULL
78};
79
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -080080
Dirk Brandewie1c0b2dd2009-05-21 11:56:35 -070081static const struct i2400m_poke_table i2400ms_pokes[] = {
82 I2400M_FW_POKE(0x6BE260, 0x00000088),
83 I2400M_FW_POKE(0x080550, 0x00000005),
84 I2400M_FW_POKE(0xAE0000, 0x00000000),
85 I2400M_FW_POKE(0x000000, 0x00000000), /* MUST be 0 terminated or bad
86 * things will happen */
87};
88
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -080089/*
90 * Enable the SDIO function
91 *
92 * Tries to enable the SDIO function; might fail if it is still not
93 * ready (in some hardware, the SDIO WiMAX function is only enabled
94 * when we ask it to explicitly doing). Tries until a timeout is
95 * reached.
96 *
Inaky Perez-Gonzalezc77ca952009-08-31 17:57:56 -070097 * The @maxtries argument indicates how many times (at most) it should
98 * be tried to enable the function. 0 means forever. This acts along
99 * with the timeout (ie: it'll stop trying as soon as the maximum
100 * number of tries is reached _or_ as soon as the timeout is reached).
101 *
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800102 * The reverse of this is...sdio_disable_function()
103 *
104 * Returns: 0 if the SDIO function was enabled, < 0 errno code on
105 * error (-ENODEV when it was unable to enable the function).
106 */
107static
Inaky Perez-Gonzalez02eb41e2009-10-23 17:45:07 -0700108int i2400ms_enable_function(struct i2400ms *i2400ms, unsigned maxtries)
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800109{
Inaky Perez-Gonzalez02eb41e2009-10-23 17:45:07 -0700110 struct sdio_func *func = i2400ms->func;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800111 u64 timeout;
112 int err;
113 struct device *dev = &func->dev;
Inaky Perez-Gonzalezc77ca952009-08-31 17:57:56 -0700114 unsigned tries = 0;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800115
116 d_fnstart(3, dev, "(func %p)\n", func);
117 /* Setup timeout (FIXME: This needs to read the CIS table to
118 * get a real timeout) and then wait for the device to signal
119 * it is ready */
120 timeout = get_jiffies_64() + ioe_timeout * HZ;
121 err = -ENODEV;
122 while (err != 0 && time_before64(get_jiffies_64(), timeout)) {
123 sdio_claim_host(func);
Cindy H Kaof2696fb2009-08-17 19:17:58 -0700124 /*
125 * There is a sillicon bug on the IWMC3200, where the
126 * IOE timeout will cause problems on Moorestown
127 * platforms (system hang). We explicitly overwrite
128 * func->enable_timeout here to work around the issue.
129 */
Inaky Perez-Gonzalez02eb41e2009-10-23 17:45:07 -0700130 if (i2400ms->iwmc3200)
Cindy H Kaof2696fb2009-08-17 19:17:58 -0700131 func->enable_timeout = IWMC3200_IOR_TIMEOUT;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800132 err = sdio_enable_func(func);
133 if (0 == err) {
134 sdio_release_host(func);
135 d_printf(2, dev, "SDIO function enabled\n");
136 goto function_enabled;
137 }
138 d_printf(2, dev, "SDIO function failed to enable: %d\n", err);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800139 sdio_release_host(func);
Inaky Perez-Gonzalezc77ca952009-08-31 17:57:56 -0700140 if (maxtries > 0 && ++tries >= maxtries) {
141 err = -ETIME;
142 break;
143 }
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800144 msleep(I2400MS_INIT_SLEEP_INTERVAL);
145 }
146 /* If timed out, device is not there yet -- get -ENODEV so
147 * the device driver core will retry later on. */
148 if (err == -ETIME) {
149 dev_err(dev, "Can't enable WiMAX function; "
150 " has the function been enabled?\n");
151 err = -ENODEV;
152 }
153function_enabled:
154 d_fnend(3, dev, "(func %p) = %d\n", func, err);
155 return err;
156}
157
158
159/*
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700160 * Setup minimal device communication infrastructure needed to at
161 * least be able to update the firmware.
162 */
163static
164int i2400ms_bus_setup(struct i2400m *i2400m)
165{
166 int result;
167 struct i2400ms *i2400ms =
168 container_of(i2400m, struct i2400ms, i2400m);
169 struct device *dev = i2400m_dev(i2400m);
170 struct sdio_func *func = i2400ms->func;
171
172 sdio_claim_host(func);
173 result = sdio_set_block_size(func, I2400MS_BLK_SIZE);
174 sdio_release_host(func);
175 if (result < 0) {
176 dev_err(dev, "Failed to set block size: %d\n", result);
177 goto error_set_blk_size;
178 }
179
Inaky Perez-Gonzalez02eb41e2009-10-23 17:45:07 -0700180 result = i2400ms_enable_function(i2400ms, 1);
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700181 if (result < 0) {
182 dev_err(dev, "Cannot enable SDIO function: %d\n", result);
183 goto error_func_enable;
184 }
185
Inaky Perez-Gonzaleza8ee3032009-10-08 12:36:03 +0900186 result = i2400ms_tx_setup(i2400ms);
187 if (result < 0)
188 goto error_tx_setup;
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700189 result = i2400ms_rx_setup(i2400ms);
190 if (result < 0)
191 goto error_rx_setup;
192 return 0;
193
194error_rx_setup:
Inaky Perez-Gonzaleza8ee3032009-10-08 12:36:03 +0900195 i2400ms_tx_release(i2400ms);
196error_tx_setup:
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700197 sdio_claim_host(func);
198 sdio_disable_func(func);
199 sdio_release_host(func);
200error_func_enable:
201error_set_blk_size:
202 return result;
203}
204
205
206/*
207 * Tear down minimal device communication infrastructure needed to at
208 * least be able to update the firmware.
209 */
210static
211void i2400ms_bus_release(struct i2400m *i2400m)
212{
213 struct i2400ms *i2400ms =
214 container_of(i2400m, struct i2400ms, i2400m);
215 struct sdio_func *func = i2400ms->func;
216
217 i2400ms_rx_release(i2400ms);
Inaky Perez-Gonzaleza8ee3032009-10-08 12:36:03 +0900218 i2400ms_tx_release(i2400ms);
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700219 sdio_claim_host(func);
220 sdio_disable_func(func);
221 sdio_release_host(func);
222}
223
224
225/*
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800226 * Setup driver resources needed to communicate with the device
227 *
228 * The fw needs some time to settle, and it was just uploaded,
229 * so give it a break first. I'd prefer to just wait for the device to
230 * send something, but seems the poking we do to enable SDIO stuff
231 * interferes with it, so just give it a break before starting...
232 */
233static
234int i2400ms_bus_dev_start(struct i2400m *i2400m)
235{
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800236 struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
237 struct sdio_func *func = i2400ms->func;
238 struct device *dev = &func->dev;
239
240 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
241 msleep(200);
Inaky Perez-Gonzaleza8ee3032009-10-08 12:36:03 +0900242 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, 0);
243 return 0;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800244}
245
246
247/*
248 * Sends a barker buffer to the device
249 *
250 * This helper will allocate a kmalloced buffer and use it to transmit
251 * (then free it). Reason for this is that the SDIO host controller
252 * expects alignment (unknown exactly which) which the stack won't
253 * really provide and certain arches/host-controller combinations
254 * cannot use stack/vmalloc/text areas for DMA transfers.
255 */
256static
257int __i2400ms_send_barker(struct i2400ms *i2400ms,
258 const __le32 *barker, size_t barker_size)
259{
260 int ret;
261 struct sdio_func *func = i2400ms->func;
262 struct device *dev = &func->dev;
263 void *buffer;
264
265 ret = -ENOMEM;
266 buffer = kmalloc(I2400MS_BLK_SIZE, GFP_KERNEL);
267 if (buffer == NULL)
268 goto error_kzalloc;
269
270 memcpy(buffer, barker, barker_size);
271 sdio_claim_host(func);
272 ret = sdio_memcpy_toio(func, 0, buffer, I2400MS_BLK_SIZE);
273 sdio_release_host(func);
274
275 if (ret < 0)
276 d_printf(0, dev, "E: barker error: %d\n", ret);
277
278 kfree(buffer);
279error_kzalloc:
280 return ret;
281}
282
283
284/*
285 * Reset a device at different levels (warm, cold or bus)
286 *
287 * @i2400ms: device descriptor
288 * @reset_type: soft, warm or bus reset (I2400M_RT_WARM/SOFT/BUS)
289 *
290 * FIXME: not tested -- need to confirm expected effects
291 *
292 * Warm and cold resets get an SDIO reset if they fail (unimplemented)
293 *
294 * Warm reset:
295 *
296 * The device will be fully reset internally, but won't be
Dirk Brandewie81b182a2009-07-24 09:04:33 -0700297 * disconnected from the bus (so no reenumeration will
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800298 * happen). Firmware upload will be neccessary.
299 *
Dirk Brandewie81b182a2009-07-24 09:04:33 -0700300 * The device will send a reboot barker that will trigger the driver
301 * to reinitialize the state via __i2400m_dev_reset_handle.
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800302 *
Dirk Brandewie81b182a2009-07-24 09:04:33 -0700303 *
304 * Cold and bus reset:
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800305 *
306 * The device will be fully reset internally, disconnected from the
Dirk Brandewie81b182a2009-07-24 09:04:33 -0700307 * bus an a reenumeration will happen. Firmware upload will be
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800308 * neccessary. Thus, we don't do any locking or struct
309 * reinitialization, as we are going to be fully disconnected and
310 * reenumerated.
311 *
312 * Note we need to return -ENODEV if a warm reset was requested and we
313 * had to resort to a bus reset. See i2400m_op_reset(), wimax_reset()
314 * and wimax_dev->op_reset.
315 *
316 * WARNING: no driver state saved/fixed
317 */
318static
319int i2400ms_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
320{
Dirk Brandewie10b1de62009-05-12 07:54:00 -0700321 int result = 0;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800322 struct i2400ms *i2400ms =
323 container_of(i2400m, struct i2400ms, i2400m);
324 struct device *dev = i2400m_dev(i2400m);
325 static const __le32 i2400m_WARM_BOOT_BARKER[4] = {
Harvey Harrisonee437772009-02-01 00:43:54 -0800326 cpu_to_le32(I2400M_WARM_RESET_BARKER),
327 cpu_to_le32(I2400M_WARM_RESET_BARKER),
328 cpu_to_le32(I2400M_WARM_RESET_BARKER),
329 cpu_to_le32(I2400M_WARM_RESET_BARKER),
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800330 };
331 static const __le32 i2400m_COLD_BOOT_BARKER[4] = {
Harvey Harrisonee437772009-02-01 00:43:54 -0800332 cpu_to_le32(I2400M_COLD_RESET_BARKER),
333 cpu_to_le32(I2400M_COLD_RESET_BARKER),
334 cpu_to_le32(I2400M_COLD_RESET_BARKER),
335 cpu_to_le32(I2400M_COLD_RESET_BARKER),
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800336 };
337
338 if (rt == I2400M_RT_WARM)
339 result = __i2400ms_send_barker(i2400ms, i2400m_WARM_BOOT_BARKER,
340 sizeof(i2400m_WARM_BOOT_BARKER));
341 else if (rt == I2400M_RT_COLD)
342 result = __i2400ms_send_barker(i2400ms, i2400m_COLD_BOOT_BARKER,
343 sizeof(i2400m_COLD_BOOT_BARKER));
344 else if (rt == I2400M_RT_BUS) {
345do_bus_reset:
Dirk Brandewie10b1de62009-05-12 07:54:00 -0700346
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700347 i2400ms_bus_release(i2400m);
Dirk Brandewie10b1de62009-05-12 07:54:00 -0700348
349 /* Wait for the device to settle */
350 msleep(40);
351
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700352 result = i2400ms_bus_setup(i2400m);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800353 } else
354 BUG();
355 if (result < 0 && rt != I2400M_RT_BUS) {
356 dev_err(dev, "%s reset failed (%d); trying SDIO reset\n",
357 rt == I2400M_RT_WARM ? "warm" : "cold", result);
358 rt = I2400M_RT_BUS;
359 goto do_bus_reset;
360 }
361 return result;
362}
363
364
365static
366void i2400ms_netdev_setup(struct net_device *net_dev)
367{
368 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
369 struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
370 i2400ms_init(i2400ms);
371 i2400m_netdev_setup(net_dev);
372}
373
374
375/*
376 * Debug levels control; see debug.h
377 */
378struct d_level D_LEVEL[] = {
379 D_SUBMODULE_DEFINE(main),
380 D_SUBMODULE_DEFINE(tx),
381 D_SUBMODULE_DEFINE(rx),
382 D_SUBMODULE_DEFINE(fw),
383};
384size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
385
386
387#define __debugfs_register(prefix, name, parent) \
388do { \
389 result = d_level_register_debugfs(prefix, name, parent); \
390 if (result < 0) \
391 goto error; \
392} while (0)
393
394
395static
396int i2400ms_debugfs_add(struct i2400ms *i2400ms)
397{
398 int result;
399 struct dentry *dentry = i2400ms->i2400m.wimax_dev.debugfs_dentry;
400
401 dentry = debugfs_create_dir("i2400m-usb", dentry);
402 result = PTR_ERR(dentry);
403 if (IS_ERR(dentry)) {
404 if (result == -ENODEV)
405 result = 0; /* No debugfs support */
406 goto error;
407 }
408 i2400ms->debugfs_dentry = dentry;
409 __debugfs_register("dl_", main, dentry);
410 __debugfs_register("dl_", tx, dentry);
411 __debugfs_register("dl_", rx, dentry);
412 __debugfs_register("dl_", fw, dentry);
413
414 return 0;
415
416error:
417 debugfs_remove_recursive(i2400ms->debugfs_dentry);
418 return result;
419}
420
421
Marcel Holtmann384912e2009-08-31 21:08:19 +0000422static struct device_type i2400ms_type = {
423 .name = "wimax",
424};
425
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800426/*
427 * Probe a i2400m interface and register it
428 *
429 * @func: SDIO function
430 * @id: SDIO device ID
431 * @returns: 0 if ok, < 0 errno code on error.
432 *
433 * Alloc a net device, initialize the bus-specific details and then
434 * calls the bus-generic initialization routine. That will register
435 * the wimax and netdev devices, upload the firmware [using
436 * _bus_bm_*()], call _bus_dev_start() to finalize the setup of the
437 * communication with the device and then will start to talk to it to
438 * finnish setting it up.
439 *
440 * Initialization is tricky; some instances of the hw are packed with
441 * others in a way that requires a third driver that enables the WiMAX
442 * function. In those cases, we can't enable the SDIO function and
443 * we'll return with -ENODEV. When the driver that enables the WiMAX
444 * function does its thing, it has to do a bus_rescan_devices() on the
445 * SDIO bus so this driver is called again to enumerate the WiMAX
446 * function.
447 */
448static
449int i2400ms_probe(struct sdio_func *func,
450 const struct sdio_device_id *id)
451{
452 int result;
453 struct net_device *net_dev;
454 struct device *dev = &func->dev;
455 struct i2400m *i2400m;
456 struct i2400ms *i2400ms;
457
458 /* Allocate instance [calls i2400m_netdev_setup() on it]. */
459 result = -ENOMEM;
460 net_dev = alloc_netdev(sizeof(*i2400ms), "wmx%d",
461 i2400ms_netdev_setup);
462 if (net_dev == NULL) {
463 dev_err(dev, "no memory for network device instance\n");
464 goto error_alloc_netdev;
465 }
466 SET_NETDEV_DEV(net_dev, dev);
Marcel Holtmann384912e2009-08-31 21:08:19 +0000467 SET_NETDEV_DEVTYPE(net_dev, &i2400ms_type);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800468 i2400m = net_dev_to_i2400m(net_dev);
469 i2400ms = container_of(i2400m, struct i2400ms, i2400m);
470 i2400m->wimax_dev.net_dev = net_dev;
471 i2400ms->func = func;
472 sdio_set_drvdata(func, i2400ms);
473
474 i2400m->bus_tx_block_size = I2400MS_BLK_SIZE;
475 i2400m->bus_pl_size_max = I2400MS_PL_SIZE_MAX;
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700476 i2400m->bus_setup = i2400ms_bus_setup;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800477 i2400m->bus_dev_start = i2400ms_bus_dev_start;
Inaky Perez-Gonzaleza8ee3032009-10-08 12:36:03 +0900478 i2400m->bus_dev_stop = NULL;
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700479 i2400m->bus_release = i2400ms_bus_release;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800480 i2400m->bus_tx_kick = i2400ms_bus_tx_kick;
481 i2400m->bus_reset = i2400ms_bus_reset;
Inaky Perez-Gonzalezecddfd52009-06-03 16:13:14 +0800482 /* The iwmc3200-wimax sometimes requires the driver to try
483 * hard when we paint it into a corner. */
Dirk Brandewiec3083652009-08-13 13:48:29 -0700484 i2400m->bus_bm_retries = I2400M_SDIO_BOOT_RETRIES;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800485 i2400m->bus_bm_cmd_send = i2400ms_bus_bm_cmd_send;
486 i2400m->bus_bm_wait_for_ack = i2400ms_bus_bm_wait_for_ack;
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000487 i2400m->bus_fw_names = i2400ms_bus_fw_names;
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800488 i2400m->bus_bm_mac_addr_impaired = 1;
Dirk Brandewie1c0b2dd2009-05-21 11:56:35 -0700489 i2400m->bus_bm_pokes_table = &i2400ms_pokes[0];
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800490
Inaky Perez-Gonzalez02eb41e2009-10-23 17:45:07 -0700491 switch (func->device) {
492 case SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX:
493 case SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX_2G5:
494 i2400ms->iwmc3200 = 1;
495 break;
496 default:
497 i2400ms->iwmc3200 = 0;
498 }
499
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800500 result = i2400m_setup(i2400m, I2400M_BRI_NO_REBOOT);
501 if (result < 0) {
502 dev_err(dev, "cannot setup device: %d\n", result);
503 goto error_setup;
504 }
505
506 result = i2400ms_debugfs_add(i2400ms);
507 if (result < 0) {
508 dev_err(dev, "cannot create SDIO debugfs: %d\n",
509 result);
510 goto error_debugfs_add;
511 }
512 return 0;
513
514error_debugfs_add:
515 i2400m_release(i2400m);
516error_setup:
Inaky Perez-Gonzaleza0a4c4c2009-04-30 14:39:21 -0700517 sdio_set_drvdata(func, NULL);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800518 free_netdev(net_dev);
519error_alloc_netdev:
520 return result;
521}
522
523
524static
525void i2400ms_remove(struct sdio_func *func)
526{
527 struct device *dev = &func->dev;
528 struct i2400ms *i2400ms = sdio_get_drvdata(func);
529 struct i2400m *i2400m = &i2400ms->i2400m;
530 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
531
532 d_fnstart(3, dev, "SDIO func %p\n", func);
533 debugfs_remove_recursive(i2400ms->debugfs_dentry);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800534 i2400m_release(i2400m);
535 sdio_set_drvdata(func, NULL);
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800536 free_netdev(net_dev);
537 d_fnend(3, dev, "SDIO func %p\n", func);
538}
539
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800540static
541const struct sdio_device_id i2400ms_sdio_ids[] = {
Tomas Winkler51def0b2009-07-22 14:06:56 +0000542 /* Intel: i2400m WiMAX (iwmc3200) over SDIO */
543 { SDIO_DEVICE(SDIO_VENDOR_ID_INTEL,
544 SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX) },
Cindy H Kaof8fc3292009-09-04 17:38:46 -0700545 { SDIO_DEVICE(SDIO_VENDOR_ID_INTEL,
546 SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX_2G5) },
Tomas Winkler51def0b2009-07-22 14:06:56 +0000547 { /* end: all zeroes */ },
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800548};
549MODULE_DEVICE_TABLE(sdio, i2400ms_sdio_ids);
550
551
552static
553struct sdio_driver i2400m_sdio_driver = {
554 .name = KBUILD_MODNAME,
555 .probe = i2400ms_probe,
556 .remove = i2400ms_remove,
557 .id_table = i2400ms_sdio_ids,
558};
559
560
561static
562int __init i2400ms_driver_init(void)
563{
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -0700564 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400ms_debug_params,
565 "i2400m_sdio.debug");
Inaky Perez-Gonzaleza0848822008-12-20 16:57:55 -0800566 return sdio_register_driver(&i2400m_sdio_driver);
567}
568module_init(i2400ms_driver_init);
569
570
571static
572void __exit i2400ms_driver_exit(void)
573{
574 flush_scheduled_work(); /* for the stuff we schedule */
575 sdio_unregister_driver(&i2400m_sdio_driver);
576}
577module_exit(i2400ms_driver_exit);
578
579
580MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
581MODULE_DESCRIPTION("Intel 2400M WiMAX networking for SDIO");
582MODULE_LICENSE("GPL");
583MODULE_FIRMWARE(I2400MS_FW_FILE_NAME);