2 * IPWireless 3G PCMCIA Network Driver
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
23 #include <linux/delay.h>
24 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/sched.h>
29 #include <linux/slab.h>
31 #include <pcmcia/cisreg.h>
32 #include <pcmcia/device_id.h>
33 #include <pcmcia/ss.h>
34 #include <pcmcia/ds.h>
36 static struct pcmcia_device_id ipw_ids
[] = {
37 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100),
38 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0200),
41 MODULE_DEVICE_TABLE(pcmcia
, ipw_ids
);
43 static void ipwireless_detach(struct pcmcia_device
*link
);
48 /* Debug mode: more verbose, print sent/recv bytes */
50 int ipwireless_loopback
;
51 int ipwireless_out_queue
= 10;
53 module_param_named(debug
, ipwireless_debug
, int, 0);
54 module_param_named(loopback
, ipwireless_loopback
, int, 0);
55 module_param_named(out_queue
, ipwireless_out_queue
, int, 0);
56 MODULE_PARM_DESC(debug
, "switch on debug messages [0]");
57 MODULE_PARM_DESC(loopback
,
58 "debug: enable ras_raw channel [0]");
59 MODULE_PARM_DESC(out_queue
, "debug: set size of outgoing PPP queue [10]");
61 /* Executes in process context. */
62 static void signalled_reboot_work(struct work_struct
*work_reboot
)
64 struct ipw_dev
*ipw
= container_of(work_reboot
, struct ipw_dev
,
66 struct pcmcia_device
*link
= ipw
->link
;
67 pcmcia_reset_card(link
->socket
);
70 static void signalled_reboot_callback(void *callback_data
)
72 struct ipw_dev
*ipw
= (struct ipw_dev
*) callback_data
;
74 /* Delegate to process context. */
75 schedule_work(&ipw
->work_reboot
);
78 static int ipwireless_probe(struct pcmcia_device
*p_dev
, void *priv_data
)
80 struct ipw_dev
*ipw
= priv_data
;
81 struct resource
*io_resource
;
84 p_dev
->resource
[0]->flags
&= ~IO_DATA_PATH_WIDTH
;
85 p_dev
->resource
[0]->flags
|= IO_DATA_PATH_WIDTH_AUTO
;
87 /* 0x40 causes it to generate level mode interrupts. */
88 /* 0x04 enables IREQ pin. */
89 p_dev
->config_index
|= 0x44;
91 ret
= pcmcia_request_io(p_dev
);
95 io_resource
= request_region(p_dev
->resource
[0]->start
,
96 resource_size(p_dev
->resource
[0]),
97 IPWIRELESS_PCCARD_NAME
);
99 p_dev
->resource
[2]->flags
|=
100 WIN_DATA_WIDTH_16
| WIN_MEMORY_TYPE_CM
| WIN_ENABLE
;
102 ret
= pcmcia_request_window(p_dev
, p_dev
->resource
[2], 0);
106 ret
= pcmcia_map_mem_page(p_dev
, p_dev
->resource
[2], p_dev
->card_addr
);
110 ipw
->is_v2_card
= resource_size(p_dev
->resource
[2]) == 0x100;
112 ipw
->attr_memory
= ioremap(p_dev
->resource
[2]->start
,
113 resource_size(p_dev
->resource
[2]));
114 request_mem_region(p_dev
->resource
[2]->start
,
115 resource_size(p_dev
->resource
[2]),
116 IPWIRELESS_PCCARD_NAME
);
118 p_dev
->resource
[3]->flags
|= WIN_DATA_WIDTH_16
| WIN_MEMORY_TYPE_AM
|
120 p_dev
->resource
[3]->end
= 0; /* this used to be 0x1000 */
121 ret
= pcmcia_request_window(p_dev
, p_dev
->resource
[3], 0);
125 ret
= pcmcia_map_mem_page(p_dev
, p_dev
->resource
[3], 0);
129 ipw
->attr_memory
= ioremap(p_dev
->resource
[3]->start
,
130 resource_size(p_dev
->resource
[3]));
131 request_mem_region(p_dev
->resource
[3]->start
,
132 resource_size(p_dev
->resource
[3]),
133 IPWIRELESS_PCCARD_NAME
);
139 if (ipw
->common_memory
) {
140 release_mem_region(p_dev
->resource
[2]->start
,
141 resource_size(p_dev
->resource
[2]));
142 iounmap(ipw
->common_memory
);
145 release_resource(io_resource
);
146 pcmcia_disable_device(p_dev
);
150 static int config_ipwireless(struct ipw_dev
*ipw
)
152 struct pcmcia_device
*link
= ipw
->link
;
156 link
->config_flags
|= CONF_AUTO_SET_IO
| CONF_AUTO_SET_IOMEM
|
159 ret
= pcmcia_loop_config(link
, ipwireless_probe
, ipw
);
163 INIT_WORK(&ipw
->work_reboot
, signalled_reboot_work
);
165 ipwireless_init_hardware_v1(ipw
->hardware
, link
->resource
[0]->start
,
166 ipw
->attr_memory
, ipw
->common_memory
,
167 ipw
->is_v2_card
, signalled_reboot_callback
,
170 ret
= pcmcia_request_irq(link
, ipwireless_interrupt
);
174 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": Card type %s\n",
175 ipw
->is_v2_card
? "V2/V3" : "V1");
176 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
177 ": I/O ports %pR, irq %d\n", link
->resource
[0],
178 (unsigned int) link
->irq
);
179 if (ipw
->attr_memory
&& ipw
->common_memory
)
180 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
181 ": attr memory %pR, common memory %pR\n",
185 ipw
->network
= ipwireless_network_create(ipw
->hardware
);
189 ipw
->tty
= ipwireless_tty_create(ipw
->hardware
, ipw
->network
);
193 ipwireless_init_hardware_v2_v3(ipw
->hardware
);
196 * Do the RequestConfiguration last, because it enables interrupts.
197 * Then we don't get any interrupts before we're ready for them.
199 ret
= pcmcia_enable_device(link
);
206 if (ipw
->common_memory
) {
207 release_mem_region(link
->resource
[2]->start
,
208 resource_size(link
->resource
[2]));
209 iounmap(ipw
->common_memory
);
211 if (ipw
->attr_memory
) {
212 release_mem_region(link
->resource
[3]->start
,
213 resource_size(link
->resource
[3]));
214 iounmap(ipw
->attr_memory
);
216 pcmcia_disable_device(link
);
220 static void release_ipwireless(struct ipw_dev
*ipw
)
222 if (ipw
->common_memory
) {
223 release_mem_region(ipw
->link
->resource
[2]->start
,
224 resource_size(ipw
->link
->resource
[2]));
225 iounmap(ipw
->common_memory
);
227 if (ipw
->attr_memory
) {
228 release_mem_region(ipw
->link
->resource
[3]->start
,
229 resource_size(ipw
->link
->resource
[3]));
230 iounmap(ipw
->attr_memory
);
232 pcmcia_disable_device(ipw
->link
);
236 * ipwireless_attach() creates an "instance" of the driver, allocating
237 * local data structures for one device (one interface). The device
238 * is registered with Card Services.
240 * The pcmcia_device structure is initialized, but we don't actually
241 * configure the card at this point -- we wait until we receive a
242 * card insertion event.
244 static int ipwireless_attach(struct pcmcia_device
*link
)
249 ipw
= kzalloc(sizeof(struct ipw_dev
), GFP_KERNEL
);
256 ipw
->hardware
= ipwireless_hardware_create();
257 if (!ipw
->hardware
) {
261 /* RegisterClient will call config_ipwireless */
263 ret
= config_ipwireless(ipw
);
266 ipwireless_detach(link
);
274 * This deletes a driver "instance". The device is de-registered with
275 * Card Services. If it has been released, all local data structures
276 * are freed. Otherwise, the structures will be freed when the device
279 static void ipwireless_detach(struct pcmcia_device
*link
)
281 struct ipw_dev
*ipw
= link
->priv
;
283 release_ipwireless(ipw
);
285 if (ipw
->tty
!= NULL
)
286 ipwireless_tty_free(ipw
->tty
);
287 if (ipw
->network
!= NULL
)
288 ipwireless_network_free(ipw
->network
);
289 if (ipw
->hardware
!= NULL
)
290 ipwireless_hardware_free(ipw
->hardware
);
294 static struct pcmcia_driver me
= {
295 .owner
= THIS_MODULE
,
296 .probe
= ipwireless_attach
,
297 .remove
= ipwireless_detach
,
298 .name
= IPWIRELESS_PCCARD_NAME
,
303 * Module insertion : initialisation of the module.
304 * Register the card with cardmgr...
306 static int __init
init_ipwireless(void)
310 ret
= ipwireless_tty_init();
314 ret
= pcmcia_register_driver(&me
);
316 ipwireless_tty_release();
324 static void __exit
exit_ipwireless(void)
326 pcmcia_unregister_driver(&me
);
327 ipwireless_tty_release();
330 module_init(init_ipwireless
);
331 module_exit(exit_ipwireless
);
333 MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR
);
334 MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME
" " IPWIRELESS_PCMCIA_VERSION
);
335 MODULE_LICENSE("GPL");