Diff markup
1 /*** -*- linux-c -*- ************************* 1 /*** -*- linux-c -*- **********************************************************
2 2
3 Driver for Atmel at76c502 at76c504 and at 3 Driver for Atmel at76c502 at76c504 and at76c506 wireless cards.
4 4
5 Copyright 2000-2001 ATMEL Corporation. 5 Copyright 2000-2001 ATMEL Corporation.
6 Copyright 2003 Simon Kelley. 6 Copyright 2003 Simon Kelley.
7 7
8 This code was developed from version 2.1.1 !! 8 This code was developed from version 2.1.1 of the Atmel drivers,
9 released by Atmel corp. under the GPL in D !! 9 released by Atmel corp. under the GPL in December 2002. It also
10 includes code from the Linux aironet drive !! 10 includes code from the Linux aironet drivers (C) Benjamin Reed,
11 and the Linux PCMCIA package, (C) David Hi !! 11 and the Linux PCMCIA package, (C) David Hinds.
12 12
13 For all queries about this code, please co !! 13 For all queries about this code, please contact the current author,
14 Simon Kelley <simon@thekelleys.org.uk> and 14 Simon Kelley <simon@thekelleys.org.uk> and not Atmel Corporation.
15 15
16 This program is free software; you can red 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Publ 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either versi 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This software is distributed in the hope t 21 This software is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULA 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more detail 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU 26 You should have received a copy of the GNU General Public License
27 along with Atmel wireless lan drivers; if 27 along with Atmel wireless lan drivers; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place, Suite 3 28 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 29
30 ********************************************** 30 ******************************************************************************/
31 31
32 #include <linux/config.h> <<
33 #ifdef __IN_PCMCIA_PACKAGE__ 32 #ifdef __IN_PCMCIA_PACKAGE__
34 #include <pcmcia/k_compat.h> 33 #include <pcmcia/k_compat.h>
35 #endif 34 #endif
36 #include <linux/init.h> 35 #include <linux/init.h>
37 #include <linux/kernel.h> 36 #include <linux/kernel.h>
38 #include <linux/module.h> 37 #include <linux/module.h>
39 #include <linux/ptrace.h> 38 #include <linux/ptrace.h>
40 #include <linux/slab.h> 39 #include <linux/slab.h>
41 #include <linux/string.h> 40 #include <linux/string.h>
42 #include <linux/netdevice.h> 41 #include <linux/netdevice.h>
43 #include <linux/moduleparam.h> 42 #include <linux/moduleparam.h>
44 #include <linux/device.h> 43 #include <linux/device.h>
45 44
46 #include <pcmcia/version.h> <<
47 #include <pcmcia/cs_types.h> 45 #include <pcmcia/cs_types.h>
48 #include <pcmcia/cs.h> 46 #include <pcmcia/cs.h>
49 #include <pcmcia/cistpl.h> 47 #include <pcmcia/cistpl.h>
50 #include <pcmcia/cisreg.h> 48 #include <pcmcia/cisreg.h>
51 #include <pcmcia/ds.h> 49 #include <pcmcia/ds.h>
52 #include <pcmcia/ciscode.h> 50 #include <pcmcia/ciscode.h>
53 51
54 #include <asm/io.h> 52 #include <asm/io.h>
55 #include <asm/system.h> 53 #include <asm/system.h>
56 #include <linux/wireless.h> 54 #include <linux/wireless.h>
57 55
>> 56 #include "atmel.h"
58 57
59 /* 58 /*
60 All the PCMCIA modules use PCMCIA_DEBUG to 59 All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
61 you do not define PCMCIA_DEBUG at all, all 60 you do not define PCMCIA_DEBUG at all, all the debug code will be
62 left out. If you compile with PCMCIA_DEBUG 61 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
63 be present but disabled -- but it can then 62 be present but disabled -- but it can then be enabled for specific
64 modules at load time with a 'pc_debug=#' op 63 modules at load time with a 'pc_debug=#' option to insmod.
65 */ 64 */
>> 65
66 #ifdef PCMCIA_DEBUG 66 #ifdef PCMCIA_DEBUG
67 static int pc_debug = PCMCIA_DEBUG; 67 static int pc_debug = PCMCIA_DEBUG;
68 module_param(pc_debug, int, 0); 68 module_param(pc_debug, int, 0);
69 static char *version = "$Revision: 1.2 $"; 69 static char *version = "$Revision: 1.2 $";
70 #define DEBUG(n, args...) if (pc_debug>(n)) pr 70 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args);
71 #else 71 #else
72 #define DEBUG(n, args...) 72 #define DEBUG(n, args...)
73 #endif 73 #endif
74 74
75 /*============================================ 75 /*====================================================================*/
76 76
77 MODULE_AUTHOR("Simon Kelley"); 77 MODULE_AUTHOR("Simon Kelley");
78 MODULE_DESCRIPTION("Support for Atmel at76c50x 78 MODULE_DESCRIPTION("Support for Atmel at76c50x 802.11 wireless ethernet cards.");
79 MODULE_LICENSE("GPL"); 79 MODULE_LICENSE("GPL");
80 MODULE_SUPPORTED_DEVICE("Atmel at76c50x PCMCIA 80 MODULE_SUPPORTED_DEVICE("Atmel at76c50x PCMCIA cards");
81 81
82 /*============================================ 82 /*====================================================================*/
83 83
84 /* 84 /*
85 The event() function is this driver's Card 85 The event() function is this driver's Card Services event handler.
86 It will be called by Card Services when an 86 It will be called by Card Services when an appropriate card status
87 event is received. The config() and releas 87 event is received. The config() and release() entry points are
88 used to configure or release a socket, in r 88 used to configure or release a socket, in response to card
89 insertion and ejection events. They are in 89 insertion and ejection events. They are invoked from the atmel_cs
90 event handler. !! 90 event handler.
91 */ 91 */
92 92
93 struct net_device *init_atmel_card(int, int, c !! 93 static int atmel_config(struct pcmcia_device *link);
94 int (*pres !! 94 static void atmel_release(struct pcmcia_device *link);
95 void stop_atmel_card( struct net_device *, int <<
96 int atmel_open( struct net_device * ); <<
97 <<
98 static void atmel_config(dev_link_t *link); <<
99 static void atmel_release(dev_link_t *link); <<
100 static int atmel_event(event_t event, int prio <<
101 event_callback_args_t * <<
102 95
103 /* 96 /*
104 The attach() and detach() entry points are 97 The attach() and detach() entry points are used to create and destroy
105 "instances" of the driver, where each insta 98 "instances" of the driver, where each instance represents everything
106 needed to manage one actual PCMCIA card. 99 needed to manage one actual PCMCIA card.
107 */ 100 */
108 101
109 static dev_link_t *atmel_attach(void); !! 102 static void atmel_detach(struct pcmcia_device *p_dev);
110 static void atmel_detach(dev_link_t *); <<
111 103
112 /* 104 /*
113 You'll also need to prototype all the funct 105 You'll also need to prototype all the functions that will actually
114 be used to talk to your device. See 'pcmem 106 be used to talk to your device. See 'pcmem_cs' for a good example
115 of a fully self-sufficient driver; the othe 107 of a fully self-sufficient driver; the other drivers rely more or
116 less on other parts of the kernel. 108 less on other parts of the kernel.
117 */ 109 */
118 110
119 /* 111 /*
120 The dev_info variable is the "key" that is <<
121 device driver with appropriate cards, throu <<
122 database. <<
123 */ <<
124 <<
125 static dev_info_t dev_info = "atmel_cs"; <<
126 <<
127 /* <<
128 A linked list of "instances" of the atmeln 112 A linked list of "instances" of the atmelnet device. Each actual
129 PCMCIA card corresponds to one device insta 113 PCMCIA card corresponds to one device instance, and is described
130 by one dev_link_t structure (defined in ds. !! 114 by one struct pcmcia_device structure (defined in ds.h).
131 115
132 You may not want to use a linked list for t 116 You may not want to use a linked list for this -- for example, the
133 memory card driver uses an array of dev_lin !! 117 memory card driver uses an array of struct pcmcia_device pointers, where minor
134 device numbers are used to derive the corre 118 device numbers are used to derive the corresponding array index.
135 */ 119 */
136 120
137 static dev_link_t *dev_list = NULL; <<
138 <<
139 /* 121 /*
140 A dev_link_t structure has fields for most <<
141 to keep track of a socket, but there will u <<
142 specific information that also needs to be <<
143 'priv' pointer in a dev_link_t structure ca <<
144 a device-specific private data structure, l <<
145 <<
146 A driver needs to provide a dev_node_t stru 122 A driver needs to provide a dev_node_t structure for each device
147 on a card. In some cases, there is only on 123 on a card. In some cases, there is only one device per card (for
148 example, ethernet cards, modems). In other 124 example, ethernet cards, modems). In other cases, there may be
149 many actual or logical devices (SCSI adapte 125 many actual or logical devices (SCSI adapters, memory cards with
150 multiple partitions). The dev_node_t struc 126 multiple partitions). The dev_node_t structures need to be kept
151 in a linked list starting at the 'dev' fiel !! 127 in a linked list starting at the 'dev' field of a struct pcmcia_device
152 structure. We allocate them in the card's 128 structure. We allocate them in the card's private data structure,
153 because they generally shouldn't be allocat 129 because they generally shouldn't be allocated dynamically.
154 130
155 In this case, we also provide a flag to ind 131 In this case, we also provide a flag to indicate if a device is
156 "stopped" due to a power management event, 132 "stopped" due to a power management event, or card ejection. The
157 device IO routines can use a flag like this 133 device IO routines can use a flag like this to throttle IO to a
158 card that is not ready to accept it. 134 card that is not ready to accept it.
159 */ 135 */
160 !! 136
161 typedef struct local_info_t { 137 typedef struct local_info_t {
162 dev_node_t node; 138 dev_node_t node;
163 struct net_device *eth_dev; 139 struct net_device *eth_dev;
164 } local_info_t; 140 } local_info_t;
165 141
166 /*============================================ 142 /*======================================================================
167 !! 143
168 atmel_attach() creates an "instance" of the 144 atmel_attach() creates an "instance" of the driver, allocating
169 local data structures for one device. The d 145 local data structures for one device. The device is registered
170 with Card Services. 146 with Card Services.
171 !! 147
172 The dev_link structure is initialized, but w 148 The dev_link structure is initialized, but we don't actually
173 configure the card at this point -- we wait 149 configure the card at this point -- we wait until we receive a
174 card insertion event. 150 card insertion event.
175 !! 151
176 ============================================ 152 ======================================================================*/
177 153
178 static dev_link_t *atmel_attach(void) !! 154 static int atmel_probe(struct pcmcia_device *p_dev)
179 { 155 {
180 client_reg_t client_reg; <<
181 dev_link_t *link; <<
182 local_info_t *local; 156 local_info_t *local;
183 int ret; !! 157
184 <<
185 DEBUG(0, "atmel_attach()\n"); 158 DEBUG(0, "atmel_attach()\n");
186 159
187 /* Initialize the dev_link_t structure <<
188 link = kmalloc(sizeof(struct dev_link_ <<
189 if (!link) { <<
190 printk(KERN_ERR "atmel_cs: no <<
191 return NULL; <<
192 } <<
193 memset(link, 0, sizeof(struct dev_link <<
194 <<
195 /* Interrupt setup */ 160 /* Interrupt setup */
196 link->irq.Attributes = IRQ_TYPE_EXCLUS !! 161 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
197 link->irq.IRQInfo1 = IRQ_LEVEL_ID; !! 162 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
198 link->irq.Handler = NULL; !! 163 p_dev->irq.Handler = NULL;
199 !! 164
200 /* 165 /*
201 General socket configuration default 166 General socket configuration defaults can go here. In this
202 client, we assume very little, and r 167 client, we assume very little, and rely on the CIS for almost
203 everything. In most clients, many d 168 everything. In most clients, many details (i.e., number, sizes,
204 and attributes of IO windows) are fi 169 and attributes of IO windows) are fixed by the nature of the
205 device, and can be hard-wired here. 170 device, and can be hard-wired here.
206 */ 171 */
207 link->conf.Attributes = 0; !! 172 p_dev->conf.Attributes = 0;
208 link->conf.Vcc = 50; !! 173 p_dev->conf.IntType = INT_MEMORY_AND_IO;
209 link->conf.IntType = INT_MEMORY_AND_IO !! 174
210 <<
211 /* Allocate space for private device-s 175 /* Allocate space for private device-specific data */
212 local = kmalloc(sizeof(local_info_t), !! 176 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
213 if (!local) { 177 if (!local) {
214 printk(KERN_ERR "atmel_cs: no 178 printk(KERN_ERR "atmel_cs: no memory for new device\n");
215 kfree (link); !! 179 return -ENOMEM;
216 return NULL; <<
217 } <<
218 memset(local, 0, sizeof(local_info_t)) <<
219 link->priv = local; <<
220 <<
221 /* Register with Card Services */ <<
222 link->next = dev_list; <<
223 dev_list = link; <<
224 client_reg.dev_info = &dev_info; <<
225 client_reg.EventMask = <<
226 CS_EVENT_CARD_INSERTION | CS_E <<
227 CS_EVENT_RESET_PHYSICAL | CS_E <<
228 CS_EVENT_PM_SUSPEND | CS_EVENT <<
229 client_reg.event_handler = &atmel_even <<
230 client_reg.Version = 0x0210; <<
231 client_reg.event_callback_args.client_ <<
232 ret = pcmcia_register_client(&link->ha <<
233 if (ret != 0) { <<
234 cs_error(link->handle, Registe <<
235 atmel_detach(link); <<
236 return NULL; <<
237 } 180 }
238 !! 181 p_dev->priv = local;
239 return link; !! 182
>> 183 return atmel_config(p_dev);
240 } /* atmel_attach */ 184 } /* atmel_attach */
241 185
242 /*============================================ 186 /*======================================================================
243 !! 187
244 This deletes a driver "instance". The devic 188 This deletes a driver "instance". The device is de-registered
245 with Card Services. If it has been released 189 with Card Services. If it has been released, all local data
246 structures are freed. Otherwise, the struct 190 structures are freed. Otherwise, the structures will be freed
247 when the device is released. 191 when the device is released.
248 !! 192
249 ============================================ 193 ======================================================================*/
250 194
251 static void atmel_detach(dev_link_t *link) !! 195 static void atmel_detach(struct pcmcia_device *link)
252 { 196 {
253 dev_link_t **linkp; <<
254 <<
255 DEBUG(0, "atmel_detach(0x%p)\n", link) 197 DEBUG(0, "atmel_detach(0x%p)\n", link);
256 !! 198
257 /* Locate device structure */ !! 199 atmel_release(link);
258 for (linkp = &dev_list; *linkp; linkp !! 200
259 if (*linkp == link) break; !! 201 kfree(link->priv);
260 if (*linkp == NULL) <<
261 return; <<
262 <<
263 if (link->state & DEV_CONFIG) <<
264 atmel_release(link); <<
265 <<
266 /* Break the link with Card Services * <<
267 if (link->handle) <<
268 pcmcia_deregister_client(link- <<
269 <<
270 /* Unlink device structure, free piece <<
271 *linkp = link->next; <<
272 if (link->priv) <<
273 kfree(link->priv); <<
274 kfree(link); <<
275 } 202 }
276 203
277 /*============================================ 204 /*======================================================================
278 !! 205
279 atmel_config() is scheduled to run after a C 206 atmel_config() is scheduled to run after a CARD_INSERTION event
280 is received, to configure the PCMCIA socket, 207 is received, to configure the PCMCIA socket, and to make the
281 device available to the system. 208 device available to the system.
282 !! 209
283 ============================================ 210 ======================================================================*/
284 211
285 #define CS_CHECK(fn, ret) \ 212 #define CS_CHECK(fn, ret) \
286 do { last_fn = (fn); if ((last_ret = (ret)) != 213 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
287 214
288 /* Call-back function to interrogate PCMCIA-sp 215 /* Call-back function to interrogate PCMCIA-specific information
289 about the current existance of the card */ 216 about the current existance of the card */
290 static int card_present(void *arg) 217 static int card_present(void *arg)
291 { !! 218 {
292 dev_link_t *link = (dev_link_t *)arg; !! 219 struct pcmcia_device *link = (struct pcmcia_device *)arg;
293 if (link->state & DEV_SUSPEND) !! 220
294 return 0; !! 221 if (pcmcia_dev_present(link))
295 else if (link->state & DEV_PRESENT) <<
296 return 1; 222 return 1;
297 !! 223
298 return 0; 224 return 0;
299 } 225 }
300 226
301 /* list of cards we know about and their firmw !! 227 static int atmel_config(struct pcmcia_device *link)
302 Go either by Manfid or version strings. <<
303 Cards not in this list will need a firmware <<
304 in all probability. Note that the SMC 2632 <<
305 manfids, so we ignore those and use the ver <<
306 <<
307 static struct { <<
308 int manf, card; <<
309 char *ver1; <<
310 char *firmware; <<
311 char *name; <<
312 } card_table[] = { <<
313 { 0, 0, "WLAN/802.11b PC CARD", "atmel <<
314 { 0, 0, "ATMEL/AT76C502AR", "atmel_at7 <<
315 { 0, 0, "ATMEL/AT76C502AR_D", "atmel_a <<
316 { 0, 0, "ATMEL/AT76C502AR_E", "atmel_a <<
317 { 0, 0, "ATMEL/AT76C504", "atmel_at76c <<
318 { 0, 0, "ATMEL/AT76C504A", "atmel_at76 <<
319 { 0, 0, "ATMEL/AT76C504_R", "atmel_at7 <<
320 { MANFID_3COM, 0x0620, NULL, "atmel_at <<
321 { MANFID_3COM, 0x0696, NULL, "atmel_at <<
322 { 0, 0, "SMC/2632W-V2", "atmel_at76c50 <<
323 { 0, 0, "SMC/2632W", "atmel_at76c502d% <<
324 { 0xd601, 0x0007, NULL, "atmel_at76c50 <<
325 { 0x01bf, 0x3302, NULL, "atmel_at76c50 <<
326 { 0, 0, "BT/Voyager 1020 Laptop Adapte <<
327 { 0, 0, "IEEE 802.11b/Wireless LAN PC <<
328 { 0, 0, "CNet/CNWLC 11Mbps Wireless PC <<
329 { 0, 0, "Wireless/PC_CARD", "atmel_at7 <<
330 { 0, 0, "OEM/11Mbps Wireless LAN PC Ca <<
331 { 0, 0, "11WAVE/11WP611AL-E", "atmel_a <<
332 }; <<
333 <<
334 static void atmel_config(dev_link_t *link) <<
335 { 228 {
336 client_handle_t handle; <<
337 tuple_t tuple; 229 tuple_t tuple;
338 cisparse_t parse; 230 cisparse_t parse;
339 local_info_t *dev; 231 local_info_t *dev;
340 int last_fn, last_ret; 232 int last_fn, last_ret;
341 u_char buf[64]; 233 u_char buf[64];
342 int card_index = -1, done = 0; !! 234 struct pcmcia_device_id *did;
343 !! 235
344 handle = link->handle; <<
345 dev = link->priv; 236 dev = link->priv;
>> 237 did = handle_to_dev(link).driver_data;
346 238
347 DEBUG(0, "atmel_config(0x%p)\n", link) 239 DEBUG(0, "atmel_config(0x%p)\n", link);
348 !! 240
349 tuple.Attributes = 0; 241 tuple.Attributes = 0;
350 tuple.TupleData = buf; 242 tuple.TupleData = buf;
351 tuple.TupleDataMax = sizeof(buf); 243 tuple.TupleDataMax = sizeof(buf);
352 tuple.TupleOffset = 0; 244 tuple.TupleOffset = 0;
353 <<
354 tuple.DesiredTuple = CISTPL_MANFID; <<
355 if (pcmcia_get_first_tuple(handle, &tu <<
356 int i; <<
357 cistpl_manfid_t *manfid; <<
358 CS_CHECK(GetTupleData, pcmcia_ <<
359 CS_CHECK(ParseTuple, pcmcia_pa <<
360 manfid = &(parse.manfid); <<
361 for (i = 0; i < sizeof(card_ta <<
362 if (!card_table[i].ver <<
363 manfid->manf == ca <<
364 manfid->card == ca <<
365 card_index = i <<
366 done = 1; <<
367 } <<
368 } <<
369 } <<
370 <<
371 tuple.DesiredTuple = CISTPL_VERS_1; <<
372 if (!done && (pcmcia_get_first_tuple(h <<
373 int i, j, k; <<
374 cistpl_vers_1_t *ver1; <<
375 CS_CHECK(GetTupleData, pcmcia_ <<
376 CS_CHECK(ParseTuple, pcmcia_pa <<
377 ver1 = &(parse.version_1); <<
378 <<
379 for (i = 0; i < sizeof(card_ta <<
380 for (j = 0; j < ver1-> <<
381 char *p = card <<
382 char *q = &ver <<
383 if (!p) <<
384 goto m <<
385 for (k = 0; k <<
386 while <<
387 if (*p <<
388 <<
389 <<
390 } else <<
391 <<
392 } <<
393 } <<
394 while((*q != ' <<
395 (*p != ' <<
396 if (((*p != '\ <<
397 goto m <<
398 } <<
399 card_index = i; <<
400 break; /* done */ <<
401 <<
402 mismatch: <<
403 j = 0; /* dummy stmt t <<
404 } <<
405 } <<
406 245
407 /* 246 /*
408 This reads the card's CONFIG tuple t <<
409 registers. <<
410 */ <<
411 tuple.DesiredTuple = CISTPL_CONFIG; <<
412 CS_CHECK(GetFirstTuple, pcmcia_get_fir <<
413 CS_CHECK(GetTupleData, pcmcia_get_tupl <<
414 CS_CHECK(ParseTuple, pcmcia_parse_tupl <<
415 link->conf.ConfigBase = parse.config.b <<
416 link->conf.Present = parse.config.rmas <<
417 <<
418 /* Configure card */ <<
419 link->state |= DEV_CONFIG; <<
420 <<
421 /* <<
422 In this loop, we scan the CIS for co 247 In this loop, we scan the CIS for configuration table entries,
423 each of which describes a valid card 248 each of which describes a valid card configuration, including
424 voltage, IO window, memory window, a 249 voltage, IO window, memory window, and interrupt settings.
425 !! 250
426 We make no assumptions about the car 251 We make no assumptions about the card to be configured: we use
427 just the information available in th 252 just the information available in the CIS. In an ideal world,
428 this would work for any PCMCIA card, 253 this would work for any PCMCIA card, but it requires a complete
429 and accurate CIS. In practice, a dr 254 and accurate CIS. In practice, a driver usually "knows" most of
430 these things without consulting the 255 these things without consulting the CIS, and most client drivers
431 will only use the CIS to fill in imp 256 will only use the CIS to fill in implementation-defined details.
432 */ 257 */
433 tuple.DesiredTuple = CISTPL_CFTABLE_EN 258 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
434 CS_CHECK(GetFirstTuple, pcmcia_get_fir !! 259 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
435 while (1) { 260 while (1) {
436 cistpl_cftable_entry_t dflt = 261 cistpl_cftable_entry_t dflt = { 0 };
437 cistpl_cftable_entry_t *cfg = 262 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
438 if (pcmcia_get_tuple_data(hand !! 263 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
439 pcmcia_parse_t !! 264 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
440 goto next_entry; 265 goto next_entry;
441 !! 266
442 if (cfg->flags & CISTPL_CFTABL 267 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
443 if (cfg->index == 0) goto next 268 if (cfg->index == 0) goto next_entry;
444 link->conf.ConfigIndex = cfg-> 269 link->conf.ConfigIndex = cfg->index;
445 !! 270
446 /* Does this card need audio o 271 /* Does this card need audio output? */
447 if (cfg->flags & CISTPL_CFTABL 272 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
448 link->conf.Attributes 273 link->conf.Attributes |= CONF_ENABLE_SPKR;
449 link->conf.Status = CC 274 link->conf.Status = CCSR_AUDIO_ENA;
450 } 275 }
451 !! 276
452 /* Use power settings for Vcc 277 /* Use power settings for Vcc and Vpp if present */
453 /* Note that the CIS values n 278 /* Note that the CIS values need to be rescaled */
454 if (cfg->vcc.present & (1<<CIS <<
455 link->conf.Vcc = cfg-> <<
456 else if (dflt.vcc.present & (1 <<
457 link->conf.Vcc = dflt. <<
458 <<
459 if (cfg->vpp1.present & (1<<CI 279 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
460 link->conf.Vpp1 = link !! 280 link->conf.Vpp =
461 cfg->vpp1.para 281 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
462 else if (dflt.vpp1.present & ( 282 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
463 link->conf.Vpp1 = link !! 283 link->conf.Vpp =
464 dflt.vpp1.para 284 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
465 !! 285
466 /* Do we need to allocate an i 286 /* Do we need to allocate an interrupt? */
467 if (cfg->irq.IRQInfo1 || dflt. 287 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
468 link->conf.Attributes 288 link->conf.Attributes |= CONF_ENABLE_IRQ;
469 !! 289
470 /* IO window settings */ 290 /* IO window settings */
471 link->io.NumPorts1 = link->io. 291 link->io.NumPorts1 = link->io.NumPorts2 = 0;
472 if ((cfg->io.nwin > 0) || (dfl 292 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
473 cistpl_io_t *io = (cfg 293 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
474 link->io.Attributes1 = 294 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
475 if (!(io->flags & CIST 295 if (!(io->flags & CISTPL_IO_8BIT))
476 link->io.Attri 296 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
477 if (!(io->flags & CIST 297 if (!(io->flags & CISTPL_IO_16BIT))
478 link->io.Attri 298 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
479 link->io.BasePort1 = i 299 link->io.BasePort1 = io->win[0].base;
480 link->io.NumPorts1 = i 300 link->io.NumPorts1 = io->win[0].len;
481 if (io->nwin > 1) { 301 if (io->nwin > 1) {
482 link->io.Attri 302 link->io.Attributes2 = link->io.Attributes1;
483 link->io.BaseP 303 link->io.BasePort2 = io->win[1].base;
484 link->io.NumPo 304 link->io.NumPorts2 = io->win[1].len;
485 } 305 }
486 } 306 }
487 !! 307
488 /* This reserves IO space but 308 /* This reserves IO space but doesn't actually enable it */
489 if (pcmcia_request_io(link->ha !! 309 if (pcmcia_request_io(link, &link->io) != 0)
490 goto next_entry; 310 goto next_entry;
491 311
492 /* If we got this far, we're c 312 /* If we got this far, we're cool! */
493 break; 313 break;
494 !! 314
495 next_entry: 315 next_entry:
496 CS_CHECK(GetNextTuple, pcmcia_ !! 316 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
497 } 317 }
498 !! 318
499 /* 319 /*
500 Allocate an interrupt line. Note th 320 Allocate an interrupt line. Note that this does not assign a
501 handler to the interrupt, unless the 321 handler to the interrupt, unless the 'Handler' member of the
502 irq structure is initialized. 322 irq structure is initialized.
503 */ 323 */
504 if (link->conf.Attributes & CONF_ENABL 324 if (link->conf.Attributes & CONF_ENABLE_IRQ)
505 CS_CHECK(RequestIRQ, pcmcia_re !! 325 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
506 !! 326
507 /* 327 /*
508 This actually configures the PCMCIA 328 This actually configures the PCMCIA socket -- setting up
509 the I/O windows and the interrupt ma 329 the I/O windows and the interrupt mapping, and putting the
510 card and host interface into "Memory 330 card and host interface into "Memory and IO" mode.
511 */ 331 */
512 CS_CHECK(RequestConfiguration, pcmcia_ !! 332 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
513 !! 333
514 if (link->irq.AssignedIRQ == 0) { 334 if (link->irq.AssignedIRQ == 0) {
515 printk(KERN_ALERT !! 335 printk(KERN_ALERT
516 "atmel: cannot assign I 336 "atmel: cannot assign IRQ: check that CONFIG_ISA is set in kernel config.");
517 goto cs_failed; 337 goto cs_failed;
518 } 338 }
519 !! 339
520 ((local_info_t*)link->priv)->eth_dev = !! 340 ((local_info_t*)link->priv)->eth_dev =
521 init_atmel_card(link->irq.Assi 341 init_atmel_card(link->irq.AssignedIRQ,
522 link->io.BaseP 342 link->io.BasePort1,
523 card_index == !! 343 did ? did->driver_info : ATMEL_FW_TYPE_NONE,
524 &handle_to_dev !! 344 &handle_to_dev(link),
525 card_present, !! 345 card_present,
526 link); 346 link);
527 if (!((local_info_t*)link->priv)->eth_ !! 347 if (!((local_info_t*)link->priv)->eth_dev)
528 goto cs_failed; !! 348 goto cs_failed;
529 !! 349
>> 350
530 /* 351 /*
531 At this point, the dev_node_t struct 352 At this point, the dev_node_t structure(s) need to be
532 initialized and arranged in a linked !! 353 initialized and arranged in a linked list at link->dev_node.
533 */ 354 */
534 strcpy(dev->node.dev_name, ((local_inf 355 strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name );
535 dev->node.major = dev->node.minor = 0; 356 dev->node.major = dev->node.minor = 0;
536 link->dev = &dev->node; !! 357 link->dev_node = &dev->node;
537 !! 358
538 /* Finally, report what we've done */ !! 359 return 0;
539 printk(KERN_INFO "%s: %s%sindex 0x%02x !! 360
540 dev->node.dev_name, <<
541 card_index == -1 ? "" : card_t <<
542 card_index == -1 ? "" : " ", <<
543 link->conf.ConfigIndex, <<
544 link->conf.Vcc/10, link->conf.V <<
545 if (link->conf.Vpp1) <<
546 printk(", Vpp %d.%d", link->co <<
547 if (link->conf.Attributes & CONF_ENABL <<
548 printk(", irq %d", link->irq.A <<
549 if (link->io.NumPorts1) <<
550 printk(", io 0x%04x-0x%04x", l <<
551 link->io.BasePort1+link <<
552 if (link->io.NumPorts2) <<
553 printk(" & 0x%04x-0x%04x", lin <<
554 link->io.BasePort2+link <<
555 printk("\n"); <<
556 <<
557 link->state &= ~DEV_CONFIG_PENDING; <<
558 return; <<
559 <<
560 cs_failed: 361 cs_failed:
561 cs_error(link->handle, last_fn, last_r !! 362 cs_error(link, last_fn, last_ret);
562 atmel_release(link); 363 atmel_release(link);
>> 364 return -ENODEV;
563 } 365 }
564 366
565 /*============================================ 367 /*======================================================================
566 !! 368
567 After a card is removed, atmel_release() wil 369 After a card is removed, atmel_release() will unregister the
568 device, and release the PCMCIA configuration 370 device, and release the PCMCIA configuration. If the device is
569 still open, this will be postponed until it 371 still open, this will be postponed until it is closed.
570 !! 372
571 ============================================ 373 ======================================================================*/
572 374
573 static void atmel_release(dev_link_t *link) !! 375 static void atmel_release(struct pcmcia_device *link)
574 { 376 {
575 struct net_device *dev = ((local_info_ 377 struct net_device *dev = ((local_info_t*)link->priv)->eth_dev;
576 !! 378
577 DEBUG(0, "atmel_release(0x%p)\n", link 379 DEBUG(0, "atmel_release(0x%p)\n", link);
578 !! 380
579 /* Unlink the device chain */ !! 381 if (dev)
580 link->dev = NULL; !! 382 stop_atmel_card(dev);
581 !! 383 ((local_info_t*)link->priv)->eth_dev = NULL;
582 if (dev) !! 384
583 stop_atmel_card(dev, 0); !! 385 pcmcia_disable_device(link);
584 ((local_info_t*)link->priv)->eth_dev = <<
585 <<
586 /* Don't bother checking to see if the <<
587 pcmcia_release_configuration(link->han <<
588 if (link->io.NumPorts1) <<
589 pcmcia_release_io(link->handle <<
590 if (link->irq.AssignedIRQ) <<
591 pcmcia_release_irq(link->handl <<
592 link->state &= ~DEV_CONFIG; <<
593 } 386 }
594 387
595 /*============================================ !! 388 static int atmel_suspend(struct pcmcia_device *link)
596 !! 389 {
597 The card status event handler. Mostly, this !! 390 local_info_t *local = link->priv;
598 stuff to run after an event is received. !! 391
599 !! 392 netif_device_detach(local->eth_dev);
600 When a CARD_REMOVAL event is received, we im !! 393
601 private flag to block future accesses to thi !! 394 return 0;
602 functions that actually access the device sh !! 395 }
603 to make sure the card is still present. <<
604 <<
605 ============================================ <<
606 396
607 static int atmel_event(event_t event, int prio !! 397 static int atmel_resume(struct pcmcia_device *link)
608 event_callback_args_t *a <<
609 { 398 {
610 dev_link_t *link = args->client_data; <<
611 local_info_t *local = link->priv; 399 local_info_t *local = link->priv;
612 !! 400
613 DEBUG(1, "atmel_event(0x%06x)\n", even !! 401 atmel_open(local->eth_dev);
614 !! 402 netif_device_attach(local->eth_dev);
615 switch (event) { !! 403
616 case CS_EVENT_CARD_REMOVAL: <<
617 link->state &= ~DEV_PRESENT; <<
618 if (link->state & DEV_CONFIG) <<
619 netif_device_detach(lo <<
620 atmel_release(link); <<
621 } <<
622 break; <<
623 case CS_EVENT_CARD_INSERTION: <<
624 link->state |= DEV_PRESENT | D <<
625 atmel_config(link); <<
626 break; <<
627 case CS_EVENT_PM_SUSPEND: <<
628 link->state |= DEV_SUSPEND; <<
629 /* Fall through... */ <<
630 case CS_EVENT_RESET_PHYSICAL: <<
631 if (link->state & DEV_CONFIG) <<
632 netif_device_detach(lo <<
633 pcmcia_release_configu <<
634 } <<
635 break; <<
636 case CS_EVENT_PM_RESUME: <<
637 link->state &= ~DEV_SUSPEND; <<
638 /* Fall through... */ <<
639 case CS_EVENT_CARD_RESET: <<
640 if (link->state & DEV_CONFIG) <<
641 pcmcia_request_configu <<
642 atmel_open(local->eth_ <<
643 netif_device_attach(lo <<
644 } <<
645 break; <<
646 } <<
647 return 0; 404 return 0;
648 } /* atmel_event */ !! 405 }
649 406
650 /*============================================ 407 /*====================================================================*/
>> 408 /* We use the driver_info field to store the correct firmware type for a card. */
>> 409
>> 410 #define PCMCIA_DEVICE_MANF_CARD_INFO(manf, card, info) { \
>> 411 .match_flags = PCMCIA_DEV_ID_MATCH_MANF_ID| \
>> 412 PCMCIA_DEV_ID_MATCH_CARD_ID, \
>> 413 .manf_id = (manf), \
>> 414 .card_id = (card), \
>> 415 .driver_info = (kernel_ulong_t)(info), }
>> 416
>> 417 #define PCMCIA_DEVICE_PROD_ID12_INFO(v1, v2, vh1, vh2, info) { \
>> 418 .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID1| \
>> 419 PCMCIA_DEV_ID_MATCH_PROD_ID2, \
>> 420 .prod_id = { (v1), (v2), NULL, NULL }, \
>> 421 .prod_id_hash = { (vh1), (vh2), 0, 0 }, \
>> 422 .driver_info = (kernel_ulong_t)(info), }
>> 423
>> 424 static struct pcmcia_device_id atmel_ids[] = {
>> 425 PCMCIA_DEVICE_MANF_CARD_INFO(0x0101, 0x0620, ATMEL_FW_TYPE_502_3COM),
>> 426 PCMCIA_DEVICE_MANF_CARD_INFO(0x0101, 0x0696, ATMEL_FW_TYPE_502_3COM),
>> 427 PCMCIA_DEVICE_MANF_CARD_INFO(0x01bf, 0x3302, ATMEL_FW_TYPE_502E),
>> 428 PCMCIA_DEVICE_MANF_CARD_INFO(0xd601, 0x0007, ATMEL_FW_TYPE_502),
>> 429 PCMCIA_DEVICE_PROD_ID12_INFO("11WAVE", "11WP611AL-E", 0x9eb2da1f, 0xc9a0d3f9, ATMEL_FW_TYPE_502E),
>> 430 PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C502AR", 0xabda4164, 0x41b37e1f, ATMEL_FW_TYPE_502),
>> 431 PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C502AR_D", 0xabda4164, 0x3675d704, ATMEL_FW_TYPE_502D),
>> 432 PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C502AR_E", 0xabda4164, 0x4172e792, ATMEL_FW_TYPE_502E),
>> 433 PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C504_R", 0xabda4164, 0x917f3d72, ATMEL_FW_TYPE_504_2958),
>> 434 PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C504", 0xabda4164, 0x5040670a, ATMEL_FW_TYPE_504),
>> 435 PCMCIA_DEVICE_PROD_ID12_INFO("ATMEL", "AT76C504A", 0xabda4164, 0xe15ed87f, ATMEL_FW_TYPE_504A_2958),
>> 436 PCMCIA_DEVICE_PROD_ID12_INFO("BT", "Voyager 1020 Laptop Adapter", 0xae49b86a, 0x1e957cd5, ATMEL_FW_TYPE_502),
>> 437 PCMCIA_DEVICE_PROD_ID12_INFO("CNet", "CNWLC 11Mbps Wireless PC Card V-5", 0xbc477dde, 0x502fae6b, ATMEL_FW_TYPE_502E),
>> 438 PCMCIA_DEVICE_PROD_ID12_INFO("IEEE 802.11b", "Wireless LAN PC Card", 0x5b878724, 0x122f1df6, ATMEL_FW_TYPE_502),
>> 439 PCMCIA_DEVICE_PROD_ID12_INFO("IEEE 802.11b", "Wireless LAN Card S", 0x5b878724, 0x5fba533a, ATMEL_FW_TYPE_504_2958),
>> 440 PCMCIA_DEVICE_PROD_ID12_INFO("OEM", "11Mbps Wireless LAN PC Card V-3", 0xfea54c90, 0x1c5b0f68, ATMEL_FW_TYPE_502),
>> 441 PCMCIA_DEVICE_PROD_ID12_INFO("SMC", "2632W", 0xc4f8b18b, 0x30f38774, ATMEL_FW_TYPE_502D),
>> 442 PCMCIA_DEVICE_PROD_ID12_INFO("SMC", "2632W-V2", 0xc4f8b18b, 0x172d1377, ATMEL_FW_TYPE_502),
>> 443 PCMCIA_DEVICE_PROD_ID12_INFO("Wireless", "PC_CARD", 0xa407ecdd, 0x119f6314, ATMEL_FW_TYPE_502D),
>> 444 PCMCIA_DEVICE_PROD_ID12_INFO("WLAN", "802.11b PC CARD", 0x575c516c, 0xb1f6dbc4, ATMEL_FW_TYPE_502D),
>> 445 PCMCIA_DEVICE_PROD_ID12_INFO("LG", "LW2100N", 0xb474d43a, 0x6b1fec94, ATMEL_FW_TYPE_502E),
>> 446 PCMCIA_DEVICE_NULL
>> 447 };
>> 448
>> 449 MODULE_DEVICE_TABLE(pcmcia, atmel_ids);
>> 450
651 static struct pcmcia_driver atmel_driver = { 451 static struct pcmcia_driver atmel_driver = {
652 .owner = THIS_MODULE, !! 452 .owner = THIS_MODULE,
653 .drv = { !! 453 .drv = {
654 .name = "atmel_cs", !! 454 .name = "atmel_cs",
655 }, 455 },
656 .attach = atmel_attach, !! 456 .probe = atmel_probe,
657 .detach = atmel_detach, !! 457 .remove = atmel_detach,
>> 458 .id_table = atmel_ids,
>> 459 .suspend = atmel_suspend,
>> 460 .resume = atmel_resume,
658 }; 461 };
659 462
660 static int atmel_cs_init(void) 463 static int atmel_cs_init(void)
661 { 464 {
662 return pcmcia_register_driver(&atmel_d 465 return pcmcia_register_driver(&atmel_driver);
663 } 466 }
664 467
665 static void atmel_cs_cleanup(void) 468 static void atmel_cs_cleanup(void)
666 { 469 {
667 pcmcia_unregister_driver(&atmel_driver 470 pcmcia_unregister_driver(&atmel_driver);
668 BUG_ON(dev_list != NULL); <<
669 } 471 }
670 472
671 /* 473 /*
672 This program is free software; you can red 474 This program is free software; you can redistribute it and/or
673 modify it under the terms of the GNU Gener 475 modify it under the terms of the GNU General Public License
674 as published by the Free Software Foundati 476 as published by the Free Software Foundation; either version 2
675 of the License, or (at your option) any la 477 of the License, or (at your option) any later version.
676 478
677 This program is distributed in the hope th 479 This program is distributed in the hope that it will be useful,
678 but WITHOUT ANY WARRANTY; without even the 480 but WITHOUT ANY WARRANTY; without even the implied warranty of
679 MERCHANTABILITY or FITNESS FOR A PARTICULA 481 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
680 GNU General Public License for more detail 482 GNU General Public License for more details.
681 483
682 In addition: 484 In addition:
683 485
684 Redistribution and use in source and binar 486 Redistribution and use in source and binary forms, with or without
685 modification, are permitted provided that 487 modification, are permitted provided that the following conditions
686 are met: 488 are met:
687 489
688 1. Redistributions of source code must ret 490 1. Redistributions of source code must retain the above copyright
689 notice, this list of conditions and the 491 notice, this list of conditions and the following disclaimer.
690 2. Redistributions in binary form must rep 492 2. Redistributions in binary form must reproduce the above copyright
691 notice, this list of conditions and the 493 notice, this list of conditions and the following disclaimer in the
692 documentation and/or other materials pr 494 documentation and/or other materials provided with the distribution.
693 3. The name of the author may not be used 495 3. The name of the author may not be used to endorse or promote
694 products derived from this software wit 496 products derived from this software without specific prior written
695 permission. 497 permission.
696 498
697 THIS SOFTWARE IS PROVIDED BY THE AUTHOR `` 499 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
698 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM 500 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
699 WARRANTIES OF MERCHANTABILITY AND FITNESS 501 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
700 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTH 502 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
701 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 503 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
702 (INCLUDING, BUT NOT LIMITED TO, PROCUREMEN 504 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
703 SERVICES; LOSS OF USE, DATA, OR PROFITS; O 505 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
704 HOWEVER CAUSED AND ON ANY THEORY OF LIABIL 506 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
705 STRICT LIABILITY, OR TORT (INCLUDING NEGLI 507 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
706 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE 508 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
707 POSSIBILITY OF SUCH DAMAGE. !! 509 POSSIBILITY OF SUCH DAMAGE.
708 */ 510 */
709 511
710 module_init(atmel_cs_init); 512 module_init(atmel_cs_init);
711 module_exit(atmel_cs_cleanup); 513 module_exit(atmel_cs_cleanup);
712 514
|
This page was automatically generated by the
LXR engine.
|