blob: 89e9d3a78c3c69fd849aea115b8ba3605d3e61de [file] [log] [blame]
Jouni Malinenff1d2762005-05-12 22:54:16 -04001#define PRISM2_PCCARD
2
Jouni Malinenff1d2762005-05-12 22:54:16 -04003#include <linux/module.h>
4#include <linux/init.h>
5#include <linux/if.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09006#include <linux/slab.h>
Jouni Malinenff1d2762005-05-12 22:54:16 -04007#include <linux/wait.h>
8#include <linux/timer.h>
9#include <linux/skbuff.h>
10#include <linux/netdevice.h>
11#include <linux/workqueue.h>
12#include <linux/wireless.h>
13#include <net/iw_handler.h>
14
Jouni Malinenff1d2762005-05-12 22:54:16 -040015#include <pcmcia/cistpl.h>
16#include <pcmcia/cisreg.h>
17#include <pcmcia/ds.h>
18
19#include <asm/io.h>
20
21#include "hostap_wlan.h"
22
23
Dominik Brodowskiac8b4222010-07-21 22:38:13 +020024static char *dev_info = "hostap_cs";
Jouni Malinenff1d2762005-05-12 22:54:16 -040025
26MODULE_AUTHOR("Jouni Malinen");
27MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN "
28 "cards (PC Card).");
29MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)");
30MODULE_LICENSE("GPL");
31
32
Jouni Malinenff1d2762005-05-12 22:54:16 -040033static int ignore_cis_vcc;
34module_param(ignore_cis_vcc, int, 0444);
35MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry");
36
37
Jouni Malinen67e0e472005-08-14 19:08:41 -070038/* struct local_info::hw_priv */
39struct hostap_cs_priv {
Dominik Brodowskifba395e2006-03-31 17:21:06 +020040 struct pcmcia_device *link;
Jouni Malinen67e0e472005-08-14 19:08:41 -070041 int sandisk_connectplus;
42};
43
44
Jouni Malinenff1d2762005-05-12 22:54:16 -040045#ifdef PRISM2_IO_DEBUG
46
47static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
48{
49 struct hostap_interface *iface;
50 local_info_t *local;
51 unsigned long flags;
52
53 iface = netdev_priv(dev);
54 local = iface->local;
55 spin_lock_irqsave(&local->lock, flags);
56 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
57 outb(v, dev->base_addr + a);
58 spin_unlock_irqrestore(&local->lock, flags);
59}
60
61static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
62{
63 struct hostap_interface *iface;
64 local_info_t *local;
65 unsigned long flags;
66 u8 v;
67
68 iface = netdev_priv(dev);
69 local = iface->local;
70 spin_lock_irqsave(&local->lock, flags);
71 v = inb(dev->base_addr + a);
72 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
73 spin_unlock_irqrestore(&local->lock, flags);
74 return v;
75}
76
77static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
78{
79 struct hostap_interface *iface;
80 local_info_t *local;
81 unsigned long flags;
82
83 iface = netdev_priv(dev);
84 local = iface->local;
85 spin_lock_irqsave(&local->lock, flags);
86 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
87 outw(v, dev->base_addr + a);
88 spin_unlock_irqrestore(&local->lock, flags);
89}
90
91static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
92{
93 struct hostap_interface *iface;
94 local_info_t *local;
95 unsigned long flags;
96 u16 v;
97
98 iface = netdev_priv(dev);
99 local = iface->local;
100 spin_lock_irqsave(&local->lock, flags);
101 v = inw(dev->base_addr + a);
102 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
103 spin_unlock_irqrestore(&local->lock, flags);
104 return v;
105}
106
107static inline void hfa384x_outsw_debug(struct net_device *dev, int a,
108 u8 *buf, int wc)
109{
110 struct hostap_interface *iface;
111 local_info_t *local;
112 unsigned long flags;
113
114 iface = netdev_priv(dev);
115 local = iface->local;
116 spin_lock_irqsave(&local->lock, flags);
117 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTSW, a, wc);
118 outsw(dev->base_addr + a, buf, wc);
119 spin_unlock_irqrestore(&local->lock, flags);
120}
121
122static inline void hfa384x_insw_debug(struct net_device *dev, int a,
123 u8 *buf, int wc)
124{
125 struct hostap_interface *iface;
126 local_info_t *local;
127 unsigned long flags;
128
129 iface = netdev_priv(dev);
130 local = iface->local;
131 spin_lock_irqsave(&local->lock, flags);
132 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INSW, a, wc);
133 insw(dev->base_addr + a, buf, wc);
134 spin_unlock_irqrestore(&local->lock, flags);
135}
136
137#define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
138#define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
139#define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
140#define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
141#define HFA384X_OUTSW(a, buf, wc) hfa384x_outsw_debug(dev, (a), (buf), (wc))
142#define HFA384X_INSW(a, buf, wc) hfa384x_insw_debug(dev, (a), (buf), (wc))
143
144#else /* PRISM2_IO_DEBUG */
145
146#define HFA384X_OUTB(v,a) outb((v), dev->base_addr + (a))
147#define HFA384X_INB(a) inb(dev->base_addr + (a))
148#define HFA384X_OUTW(v,a) outw((v), dev->base_addr + (a))
149#define HFA384X_INW(a) inw(dev->base_addr + (a))
150#define HFA384X_INSW(a, buf, wc) insw(dev->base_addr + (a), buf, wc)
151#define HFA384X_OUTSW(a, buf, wc) outsw(dev->base_addr + (a), buf, wc)
152
153#endif /* PRISM2_IO_DEBUG */
154
155
156static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
157 int len)
158{
159 u16 d_off;
160 u16 *pos;
161
162 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
163 pos = (u16 *) buf;
164
165 if (len / 2)
166 HFA384X_INSW(d_off, buf, len / 2);
167 pos += len / 2;
168
169 if (len & 1)
170 *((char *) pos) = HFA384X_INB(d_off);
171
172 return 0;
173}
174
175
176static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
177{
178 u16 d_off;
179 u16 *pos;
180
181 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
182 pos = (u16 *) buf;
183
184 if (len / 2)
185 HFA384X_OUTSW(d_off, buf, len / 2);
186 pos += len / 2;
187
188 if (len & 1)
189 HFA384X_OUTB(*((char *) pos), d_off);
190
191 return 0;
192}
193
194
195/* FIX: This might change at some point.. */
196#include "hostap_hw.c"
197
198
199
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100200static void prism2_detach(struct pcmcia_device *p_dev);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400201static void prism2_release(u_long arg);
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200202static int prism2_config(struct pcmcia_device *link);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400203
204
205static int prism2_pccard_card_present(local_info_t *local)
206{
Jouni Malinen67e0e472005-08-14 19:08:41 -0700207 struct hostap_cs_priv *hw_priv = local->hw_priv;
Dominik Brodowski9940ec32006-03-05 11:04:33 +0100208 if (hw_priv != NULL && hw_priv->link != NULL && pcmcia_dev_present(hw_priv->link))
Jouni Malinenff1d2762005-05-12 22:54:16 -0400209 return 1;
210 return 0;
211}
212
213
214/*
215 * SanDisk CompactFlash WLAN Flashcard - Product Manual v1.0
216 * Document No. 20-10-00058, January 2004
217 * http://www.sandisk.com/pdf/industrial/ProdManualCFWLANv1.0.pdf
218 */
219#define SANDISK_WLAN_ACTIVATION_OFF 0x40
220#define SANDISK_HCR_OFF 0x42
221
222
223static void sandisk_set_iobase(local_info_t *local)
224{
225 int res;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700226 struct hostap_cs_priv *hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400227
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200228 res = pcmcia_write_config_byte(hw_priv->link, 0x10,
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200229 hw_priv->link->resource[0]->start & 0x00ff);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200230 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400231 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -"
232 " res=%d\n", res);
233 }
234 udelay(10);
235
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200236 res = pcmcia_write_config_byte(hw_priv->link, 0x12,
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200237 (hw_priv->link->resource[0]->start >> 8) & 0x00ff);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200238 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400239 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -"
240 " res=%d\n", res);
241 }
242}
243
244
245static void sandisk_write_hcr(local_info_t *local, int hcr)
246{
247 struct net_device *dev = local->dev;
248 int i;
249
250 HFA384X_OUTB(0x80, SANDISK_WLAN_ACTIVATION_OFF);
251 udelay(50);
252 for (i = 0; i < 10; i++) {
253 HFA384X_OUTB(hcr, SANDISK_HCR_OFF);
254 }
255 udelay(55);
256 HFA384X_OUTB(0x45, SANDISK_WLAN_ACTIVATION_OFF);
257}
258
259
260static int sandisk_enable_wireless(struct net_device *dev)
261{
262 int res, ret = 0;
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +0200263 struct hostap_interface *iface = netdev_priv(dev);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400264 local_info_t *local = iface->local;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700265 struct hostap_cs_priv *hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400266
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200267 if (resource_size(hw_priv->link->resource[0]) < 0x42) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400268 /* Not enough ports to be SanDisk multi-function card */
269 ret = -ENODEV;
270 goto done;
271 }
272
Dominik Brodowskiefd50582006-10-25 21:28:53 -0400273 if (hw_priv->link->manf_id != 0xd601 || hw_priv->link->card_id != 0x0101) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400274 /* No SanDisk manfid found */
275 ret = -ENODEV;
276 goto done;
277 }
278
Dominik Brodowski7d2e8d02009-10-18 18:22:32 +0200279 if (hw_priv->link->socket->functions < 2) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400280 /* No multi-function links found */
281 ret = -ENODEV;
282 goto done;
283 }
284
285 printk(KERN_DEBUG "%s: Multi-function SanDisk ConnectPlus detected"
286 " - using vendor-specific initialization\n", dev->name);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700287 hw_priv->sandisk_connectplus = 1;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400288
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200289 res = pcmcia_write_config_byte(hw_priv->link, CISREG_COR,
290 COR_SOFT_RESET);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200291 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400292 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
293 dev->name, res);
294 goto done;
295 }
296 mdelay(5);
297
Jouni Malinenff1d2762005-05-12 22:54:16 -0400298 /*
299 * Do not enable interrupts here to avoid some bogus events. Interrupts
300 * will be enabled during the first cor_sreset call.
301 */
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200302 res = pcmcia_write_config_byte(hw_priv->link, CISREG_COR,
303 (COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE |
304 COR_FUNC_ENA));
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200305 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400306 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
307 dev->name, res);
308 goto done;
309 }
310 mdelay(5);
311
312 sandisk_set_iobase(local);
313
314 HFA384X_OUTB(0xc5, SANDISK_WLAN_ACTIVATION_OFF);
315 udelay(10);
316 HFA384X_OUTB(0x4b, SANDISK_WLAN_ACTIVATION_OFF);
317 udelay(10);
318
319done:
Jouni Malinenff1d2762005-05-12 22:54:16 -0400320 return ret;
321}
322
323
324static void prism2_pccard_cor_sreset(local_info_t *local)
325{
326 int res;
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200327 u8 val;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700328 struct hostap_cs_priv *hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400329
330 if (!prism2_pccard_card_present(local))
331 return;
332
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200333 res = pcmcia_read_config_byte(hw_priv->link, CISREG_COR, &val);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200334 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400335 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n",
336 res);
337 return;
338 }
339 printk(KERN_DEBUG "prism2_pccard_cor_sreset: original COR %02x\n",
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200340 val);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400341
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200342 val |= COR_SOFT_RESET;
343 res = pcmcia_write_config_byte(hw_priv->link, CISREG_COR, val);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200344 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400345 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n",
346 res);
347 return;
348 }
349
Jouni Malinen67e0e472005-08-14 19:08:41 -0700350 mdelay(hw_priv->sandisk_connectplus ? 5 : 2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400351
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200352 val &= ~COR_SOFT_RESET;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700353 if (hw_priv->sandisk_connectplus)
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200354 val |= COR_IREQ_ENA;
355 res = pcmcia_write_config_byte(hw_priv->link, CISREG_COR, val);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200356 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400357 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n",
358 res);
359 return;
360 }
361
Jouni Malinen67e0e472005-08-14 19:08:41 -0700362 mdelay(hw_priv->sandisk_connectplus ? 5 : 2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400363
Jouni Malinen67e0e472005-08-14 19:08:41 -0700364 if (hw_priv->sandisk_connectplus)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400365 sandisk_set_iobase(local);
366}
367
368
369static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
370{
371 int res;
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200372 u8 old_cor;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700373 struct hostap_cs_priv *hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400374
375 if (!prism2_pccard_card_present(local))
376 return;
377
Jouni Malinen67e0e472005-08-14 19:08:41 -0700378 if (hw_priv->sandisk_connectplus) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400379 sandisk_write_hcr(local, hcr);
380 return;
381 }
382
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200383 res = pcmcia_read_config_byte(hw_priv->link, CISREG_COR, &old_cor);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200384 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400385 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
386 "(%d)\n", res);
387 return;
388 }
389 printk(KERN_DEBUG "prism2_pccard_genesis_sreset: original COR %02x\n",
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200390 old_cor);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400391
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200392 res = pcmcia_write_config_byte(hw_priv->link, CISREG_COR,
393 old_cor | COR_SOFT_RESET);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200394 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400395 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
396 "(%d)\n", res);
397 return;
398 }
399
400 mdelay(10);
401
402 /* Setup Genesis mode */
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200403 res = pcmcia_write_config_byte(hw_priv->link, CISREG_CCSR, hcr);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200404 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400405 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
406 "(%d)\n", res);
407 return;
408 }
409 mdelay(10);
410
Dominik Brodowski1d5cc192010-07-24 12:23:21 +0200411 res = pcmcia_write_config_byte(hw_priv->link, CISREG_COR,
412 old_cor & ~COR_SOFT_RESET);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200413 if (res != 0) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400414 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
415 "(%d)\n", res);
416 return;
417 }
418
419 mdelay(10);
420}
421
422
Jouni Malinenff1d2762005-05-12 22:54:16 -0400423static struct prism2_helper_functions prism2_pccard_funcs =
424{
425 .card_present = prism2_pccard_card_present,
426 .cor_sreset = prism2_pccard_cor_sreset,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400427 .genesis_reset = prism2_pccard_genesis_reset,
428 .hw_type = HOSTAP_HW_PCCARD,
429};
430
431
432/* allocate local data and register with CardServices
433 * initialize dev_link structure, but do not configure the card yet */
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200434static int hostap_cs_probe(struct pcmcia_device *p_dev)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400435{
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200436 int ret;
437
Jouni Malinenff1d2762005-05-12 22:54:16 -0400438 PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400439
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200440 ret = prism2_config(p_dev);
441 if (ret) {
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100442 PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200443 }
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100444
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200445 return ret;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400446}
447
448
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200449static void prism2_detach(struct pcmcia_device *link)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400450{
Jouni Malinenff1d2762005-05-12 22:54:16 -0400451 PDEBUG(DEBUG_FLOW, "prism2_detach\n");
452
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100453 prism2_release((u_long)link);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400454
Jouni Malinenff1d2762005-05-12 22:54:16 -0400455 /* release net devices */
456 if (link->priv) {
Jouni Malinenc3551842005-10-02 17:19:00 -0700457 struct hostap_cs_priv *hw_priv;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700458 struct net_device *dev;
459 struct hostap_interface *iface;
460 dev = link->priv;
461 iface = netdev_priv(dev);
Jouni Malinenc3551842005-10-02 17:19:00 -0700462 hw_priv = iface->local->hw_priv;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700463 prism2_free_local_data(dev);
Jouni Malinenc3551842005-10-02 17:19:00 -0700464 kfree(hw_priv);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400465 }
Jouni Malinenff1d2762005-05-12 22:54:16 -0400466}
467
468
Dominik Brodowski00990e72010-07-30 13:13:46 +0200469static int prism2_config_check(struct pcmcia_device *p_dev, void *priv_data)
Dominik Brodowskib54bf942008-08-02 14:28:43 +0200470{
Dominik Brodowski00990e72010-07-30 13:13:46 +0200471 if (p_dev->config_index == 0)
472 return -EINVAL;
Dominik Brodowskib54bf942008-08-02 14:28:43 +0200473
Dominik Brodowski90abdc32010-07-24 17:23:51 +0200474 return pcmcia_request_io(p_dev);
Dominik Brodowskib54bf942008-08-02 14:28:43 +0200475}
476
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200477static int prism2_config(struct pcmcia_device *link)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400478{
479 struct net_device *dev;
480 struct hostap_interface *iface;
481 local_info_t *local;
482 int ret = 1;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700483 struct hostap_cs_priv *hw_priv;
Tim Gardnerd6a574f2010-06-08 11:33:02 -0600484 unsigned long flags;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400485
486 PDEBUG(DEBUG_FLOW, "prism2_config()\n");
487
Yan Burmanb0471bb72006-12-02 13:33:40 +0200488 hw_priv = kzalloc(sizeof(*hw_priv), GFP_KERNEL);
Dominik Brodowskib54bf942008-08-02 14:28:43 +0200489 if (hw_priv == NULL) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400490 ret = -ENOMEM;
491 goto failed;
492 }
493
Jouni Malinenff1d2762005-05-12 22:54:16 -0400494 /* Look for an appropriate configuration table entry in the CIS */
Dominik Brodowski440eed42010-07-30 09:51:52 +0200495 link->config_flags |= CONF_AUTO_SET_VPP | CONF_AUTO_AUDIO |
Dominik Brodowski00990e72010-07-30 13:13:46 +0200496 CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
Dominik Brodowski440eed42010-07-30 09:51:52 +0200497 if (ignore_cis_vcc)
498 link->config_flags &= ~CONF_AUTO_CHECK_VCC;
Dominik Brodowski2caff142009-10-24 15:53:36 +0200499 ret = pcmcia_loop_config(link, prism2_config_check, NULL);
500 if (ret) {
Dominik Brodowskib54bf942008-08-02 14:28:43 +0200501 if (!ignore_cis_vcc)
502 printk(KERN_ERR "GetNextTuple(): No matching "
503 "CIS configuration. Maybe you need the "
504 "ignore_cis_vcc=1 parameter.\n");
Dominik Brodowskib54bf942008-08-02 14:28:43 +0200505 goto failed;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400506 }
507
508 /* Need to allocate net_device before requesting IRQ handler */
Dave Hansen0cd545d2005-07-30 12:49:58 -0700509 dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100510 &link->dev);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400511 if (dev == NULL)
512 goto failed;
513 link->priv = dev;
514
Jouni Malinenfbff8682005-08-28 17:53:32 -0700515 iface = netdev_priv(dev);
516 local = iface->local;
517 local->hw_priv = hw_priv;
518 hw_priv->link = link;
Jouni Malinenfbff8682005-08-28 17:53:32 -0700519
Tim Gardnerd6a574f2010-06-08 11:33:02 -0600520 /*
Stanislaw Gruszka4e5518c2011-01-10 12:56:05 +0100521 * We enable IRQ here, but IRQ handler will not proceed
522 * until dev->base_addr is set below. This protect us from
523 * receive interrupts when driver is not initialized.
Tim Gardnerd6a574f2010-06-08 11:33:02 -0600524 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100525 ret = pcmcia_request_irq(link, prism2_interrupt);
526 if (ret)
Stanislaw Gruszka4e5518c2011-01-10 12:56:05 +0100527 goto failed;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400528
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200529 ret = pcmcia_enable_device(link);
Dominik Brodowski2caff142009-10-24 15:53:36 +0200530 if (ret)
Stanislaw Gruszka4e5518c2011-01-10 12:56:05 +0100531 goto failed;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400532
Stanislaw Gruszka4e5518c2011-01-10 12:56:05 +0100533 spin_lock_irqsave(&local->irq_init_lock, flags);
Dominik Brodowskieb141202010-03-07 12:21:16 +0100534 dev->irq = link->irq;
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200535 dev->base_addr = link->resource[0]->start;
Tim Gardnerd6a574f2010-06-08 11:33:02 -0600536 spin_unlock_irqrestore(&local->irq_init_lock, flags);
537
Jouni Malinenff1d2762005-05-12 22:54:16 -0400538 local->shutdown = 0;
539
540 sandisk_enable_wireless(dev);
541
542 ret = prism2_hw_config(dev, 1);
Dominik Brodowski317b6d62010-03-20 19:26:51 +0100543 if (!ret)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400544 ret = hostap_hw_ready(dev);
Dominik Brodowski317b6d62010-03-20 19:26:51 +0100545
Jouni Malinenff1d2762005-05-12 22:54:16 -0400546 return ret;
547
Jouni Malinenff1d2762005-05-12 22:54:16 -0400548 failed:
Jouni Malinen67e0e472005-08-14 19:08:41 -0700549 kfree(hw_priv);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400550 prism2_release((u_long)link);
551 return ret;
552}
553
554
555static void prism2_release(u_long arg)
556{
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200557 struct pcmcia_device *link = (struct pcmcia_device *)arg;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400558
559 PDEBUG(DEBUG_FLOW, "prism2_release\n");
560
561 if (link->priv) {
562 struct net_device *dev = link->priv;
563 struct hostap_interface *iface;
564
565 iface = netdev_priv(dev);
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100566 prism2_hw_shutdown(dev, 0);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400567 iface->local->shutdown = 1;
568 }
569
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200570 pcmcia_disable_device(link);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400571 PDEBUG(DEBUG_FLOW, "release - done\n");
572}
573
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200574static int hostap_cs_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100575{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100576 struct net_device *dev = (struct net_device *) link->priv;
577 int dev_open = 0;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100578 struct hostap_interface *iface = NULL;
579
John W. Linvillefcee7a02008-07-02 11:04:24 -0400580 if (!dev)
581 return -ENODEV;
582
583 iface = netdev_priv(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100584
585 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100586 if (iface && iface->local)
587 dev_open = iface->local->num_dev_open > 0;
588 if (dev_open) {
589 netif_stop_queue(dev);
590 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100591 }
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100592 prism2_suspend(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100593
594 return 0;
595}
596
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200597static int hostap_cs_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100598{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100599 struct net_device *dev = (struct net_device *) link->priv;
600 int dev_open = 0;
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100601 struct hostap_interface *iface = NULL;
602
John W. Linvillefcee7a02008-07-02 11:04:24 -0400603 if (!dev)
604 return -ENODEV;
605
606 iface = netdev_priv(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100607
608 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
609
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100610 if (iface && iface->local)
611 dev_open = iface->local->num_dev_open > 0;
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100612
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100613 prism2_hw_shutdown(dev, 1);
614 prism2_hw_config(dev, dev_open ? 0 : 1);
615 if (dev_open) {
616 netif_device_attach(dev);
617 netif_start_queue(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100618 }
619
620 return 0;
621}
Jouni Malinenff1d2762005-05-12 22:54:16 -0400622
Joe Perches25f8f542011-05-03 19:29:01 -0700623static const struct pcmcia_device_id hostap_cs_ids[] = {
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700624 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
625 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
626 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777),
627 PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000),
628 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
Stefan Lippers-Hollmann46232d22007-10-05 23:42:51 +0200629 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x3301),
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700630 PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002),
Richard Purdie1e4adbd2005-08-04 00:16:27 +0100631 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b),
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700632 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612),
633 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
634 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
635 PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
636 PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001),
637 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001),
638 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
Komurofd99ddd072006-04-17 21:41:21 +0900639/* PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000), conflict with pcnet_cs */
Pavel Roskin449fecc2008-05-16 17:52:57 -0400640 PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002),
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700641 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
642 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
643 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
Christian Steineck884d3a22006-09-08 23:51:34 +0200644 PCMCIA_DEVICE_MANF_CARD(0x0126, 0x0002),
Marcin Juszkiewicz25ac6c22007-03-30 15:34:14 +0200645 PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0xd601, 0x0005, "ADLINK 345 CF",
646 0x2d858104),
Pavel Roskin40e3cad2006-02-28 01:18:31 -0500647 PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "INTERSIL",
648 0x74c5e40d),
649 PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "Intersil",
650 0x4b801a17),
Pavel Roskin0a1013c2011-07-26 18:52:41 -0400651 PCMCIA_DEVICE_MANF_CARD_PROD_ID3(0x0156, 0x0002, "Version 01.02",
652 0x4b74baa0),
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700653 PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
654 0x7a954bd9, 0x74be00c6),
Pavel Roskin17f65f82008-01-09 22:16:58 -0500655 PCMCIA_DEVICE_PROD_ID123(
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700656 "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
657 0xe6ec52ce, 0x08649af2, 0x4b74baa0),
658 PCMCIA_DEVICE_PROD_ID123(
Veli-Pekka Peltola090891f2011-11-24 21:35:28 +0200659 "Canon", "Wireless LAN CF Card K30225", "Version 01.00",
660 0x96ef6fe2, 0x263fcbab, 0xa57adb8c),
661 PCMCIA_DEVICE_PROD_ID123(
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700662 "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02",
663 0x71b18589, 0xb6f1b0ab, 0x4b74baa0),
664 PCMCIA_DEVICE_PROD_ID123(
665 "Instant Wireless ", " Network PC CARD", "Version 01.02",
666 0x11d901af, 0x6e9bd926, 0x4b74baa0),
667 PCMCIA_DEVICE_PROD_ID123(
668 "SMC", "SMC2632W", "Version 01.02",
669 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
Richard Purdie1e4adbd2005-08-04 00:16:27 +0100670 PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G",
Jouni Malinen6c5b90d2005-08-28 10:51:36 -0700671 0x2decece3, 0x82067c18),
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700672 PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
673 0x54f7c49c, 0x15a75e5b),
674 PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
675 0x74c5e40d, 0xdb472a18),
676 PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card",
677 0x0733cc81, 0x0c52f395),
678 PCMCIA_DEVICE_PROD_ID12(
679 "ZoomAir 11Mbps High", "Rate wireless Networking",
680 0x273fe3db, 0x32a1eaee),
Marcin Juszkiewiczdf8ccb92006-05-22 10:56:55 +0200681 PCMCIA_DEVICE_PROD_ID123(
682 "Pretec", "CompactWLAN Card 802.11b", "2.5",
683 0x1cadd3e5, 0xe697636c, 0x7a5bfcf1),
684 PCMCIA_DEVICE_PROD_ID123(
685 "U.S. Robotics", "IEEE 802.11b PC-CARD", "Version 01.02",
686 0xc7b8df9d, 0x1700d087, 0x4b74baa0),
Dominik Brodowski01918d12006-07-02 21:21:51 +0200687 PCMCIA_DEVICE_PROD_ID123(
688 "Allied Telesyn", "AT-WCL452 Wireless PCMCIA Radio",
689 "Ver. 1.00",
690 0x5cd01705, 0x4271660f, 0x9d08ee12),
691 PCMCIA_DEVICE_PROD_ID123(
Marcin Juszkiewicz5d635ea2008-01-29 09:42:53 +0100692 "Wireless LAN" , "11Mbps PC Card", "Version 01.02",
693 0x4b8870ff, 0x70e946d1, 0x4b74baa0),
Pavel Roskinfbc87d62010-02-11 17:56:06 -0500694 PCMCIA_DEVICE_PROD_ID3("HFA3863", 0x355cb092),
695 PCMCIA_DEVICE_PROD_ID3("ISL37100P", 0x630d52b2),
696 PCMCIA_DEVICE_PROD_ID3("ISL37101P-10", 0xdd97a26b),
697 PCMCIA_DEVICE_PROD_ID3("ISL37300P", 0xc9049a39),
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700698 PCMCIA_DEVICE_NULL
699};
700MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids);
701
702
Jouni Malinenff1d2762005-05-12 22:54:16 -0400703static struct pcmcia_driver hostap_driver = {
Dominik Brodowski2e9b9812010-08-08 11:36:26 +0200704 .name = "hostap_cs",
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200705 .probe = hostap_cs_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100706 .remove = prism2_detach,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400707 .owner = THIS_MODULE,
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700708 .id_table = hostap_cs_ids,
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100709 .suspend = hostap_cs_suspend,
710 .resume = hostap_cs_resume,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400711};
712
713static int __init init_prism2_pccard(void)
714{
Jouni Malinenff1d2762005-05-12 22:54:16 -0400715 return pcmcia_register_driver(&hostap_driver);
716}
717
718static void __exit exit_prism2_pccard(void)
719{
720 pcmcia_unregister_driver(&hostap_driver);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400721}
722
723
724module_init(init_prism2_pccard);
725module_exit(exit_prism2_pccard);