Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1 | #define PRISM2_PCCARD |
| 2 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 3 | #include <linux/module.h> |
| 4 | #include <linux/init.h> |
| 5 | #include <linux/if.h> |
| 6 | #include <linux/wait.h> |
| 7 | #include <linux/timer.h> |
| 8 | #include <linux/skbuff.h> |
| 9 | #include <linux/netdevice.h> |
| 10 | #include <linux/workqueue.h> |
| 11 | #include <linux/wireless.h> |
| 12 | #include <net/iw_handler.h> |
| 13 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 14 | #include <pcmcia/cs_types.h> |
| 15 | #include <pcmcia/cs.h> |
| 16 | #include <pcmcia/cistpl.h> |
| 17 | #include <pcmcia/cisreg.h> |
| 18 | #include <pcmcia/ds.h> |
| 19 | |
| 20 | #include <asm/io.h> |
| 21 | |
| 22 | #include "hostap_wlan.h" |
| 23 | |
| 24 | |
| 25 | static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)"; |
| 26 | static dev_info_t dev_info = "hostap_cs"; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 27 | |
| 28 | MODULE_AUTHOR("Jouni Malinen"); |
| 29 | MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN " |
| 30 | "cards (PC Card)."); |
| 31 | MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)"); |
| 32 | MODULE_LICENSE("GPL"); |
Jouni Malinen | f06ac31 | 2005-07-30 12:50:00 -0700 | [diff] [blame] | 33 | MODULE_VERSION(PRISM2_VERSION); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 34 | |
| 35 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 36 | static int ignore_cis_vcc; |
| 37 | module_param(ignore_cis_vcc, int, 0444); |
| 38 | MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry"); |
| 39 | |
| 40 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 41 | /* struct local_info::hw_priv */ |
| 42 | struct hostap_cs_priv { |
| 43 | dev_node_t node; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 44 | struct pcmcia_device *link; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 45 | int sandisk_connectplus; |
| 46 | }; |
| 47 | |
| 48 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 49 | #ifdef PRISM2_IO_DEBUG |
| 50 | |
| 51 | static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v) |
| 52 | { |
| 53 | struct hostap_interface *iface; |
| 54 | local_info_t *local; |
| 55 | unsigned long flags; |
| 56 | |
| 57 | iface = netdev_priv(dev); |
| 58 | local = iface->local; |
| 59 | spin_lock_irqsave(&local->lock, flags); |
| 60 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v); |
| 61 | outb(v, dev->base_addr + a); |
| 62 | spin_unlock_irqrestore(&local->lock, flags); |
| 63 | } |
| 64 | |
| 65 | static inline u8 hfa384x_inb_debug(struct net_device *dev, int a) |
| 66 | { |
| 67 | struct hostap_interface *iface; |
| 68 | local_info_t *local; |
| 69 | unsigned long flags; |
| 70 | u8 v; |
| 71 | |
| 72 | iface = netdev_priv(dev); |
| 73 | local = iface->local; |
| 74 | spin_lock_irqsave(&local->lock, flags); |
| 75 | v = inb(dev->base_addr + a); |
| 76 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v); |
| 77 | spin_unlock_irqrestore(&local->lock, flags); |
| 78 | return v; |
| 79 | } |
| 80 | |
| 81 | static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v) |
| 82 | { |
| 83 | struct hostap_interface *iface; |
| 84 | local_info_t *local; |
| 85 | unsigned long flags; |
| 86 | |
| 87 | iface = netdev_priv(dev); |
| 88 | local = iface->local; |
| 89 | spin_lock_irqsave(&local->lock, flags); |
| 90 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v); |
| 91 | outw(v, dev->base_addr + a); |
| 92 | spin_unlock_irqrestore(&local->lock, flags); |
| 93 | } |
| 94 | |
| 95 | static inline u16 hfa384x_inw_debug(struct net_device *dev, int a) |
| 96 | { |
| 97 | struct hostap_interface *iface; |
| 98 | local_info_t *local; |
| 99 | unsigned long flags; |
| 100 | u16 v; |
| 101 | |
| 102 | iface = netdev_priv(dev); |
| 103 | local = iface->local; |
| 104 | spin_lock_irqsave(&local->lock, flags); |
| 105 | v = inw(dev->base_addr + a); |
| 106 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v); |
| 107 | spin_unlock_irqrestore(&local->lock, flags); |
| 108 | return v; |
| 109 | } |
| 110 | |
| 111 | static inline void hfa384x_outsw_debug(struct net_device *dev, int a, |
| 112 | u8 *buf, int wc) |
| 113 | { |
| 114 | struct hostap_interface *iface; |
| 115 | local_info_t *local; |
| 116 | unsigned long flags; |
| 117 | |
| 118 | iface = netdev_priv(dev); |
| 119 | local = iface->local; |
| 120 | spin_lock_irqsave(&local->lock, flags); |
| 121 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTSW, a, wc); |
| 122 | outsw(dev->base_addr + a, buf, wc); |
| 123 | spin_unlock_irqrestore(&local->lock, flags); |
| 124 | } |
| 125 | |
| 126 | static inline void hfa384x_insw_debug(struct net_device *dev, int a, |
| 127 | u8 *buf, int wc) |
| 128 | { |
| 129 | struct hostap_interface *iface; |
| 130 | local_info_t *local; |
| 131 | unsigned long flags; |
| 132 | |
| 133 | iface = netdev_priv(dev); |
| 134 | local = iface->local; |
| 135 | spin_lock_irqsave(&local->lock, flags); |
| 136 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INSW, a, wc); |
| 137 | insw(dev->base_addr + a, buf, wc); |
| 138 | spin_unlock_irqrestore(&local->lock, flags); |
| 139 | } |
| 140 | |
| 141 | #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v)) |
| 142 | #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a)) |
| 143 | #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v)) |
| 144 | #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a)) |
| 145 | #define HFA384X_OUTSW(a, buf, wc) hfa384x_outsw_debug(dev, (a), (buf), (wc)) |
| 146 | #define HFA384X_INSW(a, buf, wc) hfa384x_insw_debug(dev, (a), (buf), (wc)) |
| 147 | |
| 148 | #else /* PRISM2_IO_DEBUG */ |
| 149 | |
| 150 | #define HFA384X_OUTB(v,a) outb((v), dev->base_addr + (a)) |
| 151 | #define HFA384X_INB(a) inb(dev->base_addr + (a)) |
| 152 | #define HFA384X_OUTW(v,a) outw((v), dev->base_addr + (a)) |
| 153 | #define HFA384X_INW(a) inw(dev->base_addr + (a)) |
| 154 | #define HFA384X_INSW(a, buf, wc) insw(dev->base_addr + (a), buf, wc) |
| 155 | #define HFA384X_OUTSW(a, buf, wc) outsw(dev->base_addr + (a), buf, wc) |
| 156 | |
| 157 | #endif /* PRISM2_IO_DEBUG */ |
| 158 | |
| 159 | |
| 160 | static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf, |
| 161 | int len) |
| 162 | { |
| 163 | u16 d_off; |
| 164 | u16 *pos; |
| 165 | |
| 166 | d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF; |
| 167 | pos = (u16 *) buf; |
| 168 | |
| 169 | if (len / 2) |
| 170 | HFA384X_INSW(d_off, buf, len / 2); |
| 171 | pos += len / 2; |
| 172 | |
| 173 | if (len & 1) |
| 174 | *((char *) pos) = HFA384X_INB(d_off); |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len) |
| 181 | { |
| 182 | u16 d_off; |
| 183 | u16 *pos; |
| 184 | |
| 185 | d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF; |
| 186 | pos = (u16 *) buf; |
| 187 | |
| 188 | if (len / 2) |
| 189 | HFA384X_OUTSW(d_off, buf, len / 2); |
| 190 | pos += len / 2; |
| 191 | |
| 192 | if (len & 1) |
| 193 | HFA384X_OUTB(*((char *) pos), d_off); |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | /* FIX: This might change at some point.. */ |
| 200 | #include "hostap_hw.c" |
| 201 | |
| 202 | |
| 203 | |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 204 | static void prism2_detach(struct pcmcia_device *p_dev); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 205 | static void prism2_release(u_long arg); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 206 | static int prism2_config(struct pcmcia_device *link); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 207 | |
| 208 | |
| 209 | static int prism2_pccard_card_present(local_info_t *local) |
| 210 | { |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 211 | struct hostap_cs_priv *hw_priv = local->hw_priv; |
Dominik Brodowski | 9940ec3 | 2006-03-05 11:04:33 +0100 | [diff] [blame] | 212 | if (hw_priv != NULL && hw_priv->link != NULL && pcmcia_dev_present(hw_priv->link)) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 213 | return 1; |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | /* |
| 219 | * SanDisk CompactFlash WLAN Flashcard - Product Manual v1.0 |
| 220 | * Document No. 20-10-00058, January 2004 |
| 221 | * http://www.sandisk.com/pdf/industrial/ProdManualCFWLANv1.0.pdf |
| 222 | */ |
| 223 | #define SANDISK_WLAN_ACTIVATION_OFF 0x40 |
| 224 | #define SANDISK_HCR_OFF 0x42 |
| 225 | |
| 226 | |
| 227 | static void sandisk_set_iobase(local_info_t *local) |
| 228 | { |
| 229 | int res; |
| 230 | conf_reg_t reg; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 231 | struct hostap_cs_priv *hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 232 | |
| 233 | reg.Function = 0; |
| 234 | reg.Action = CS_WRITE; |
| 235 | reg.Offset = 0x10; /* 0x3f0 IO base 1 */ |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 236 | reg.Value = hw_priv->link->io.BasePort1 & 0x00ff; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 237 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 238 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 239 | if (res != CS_SUCCESS) { |
| 240 | printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -" |
| 241 | " res=%d\n", res); |
| 242 | } |
| 243 | udelay(10); |
| 244 | |
| 245 | reg.Function = 0; |
| 246 | reg.Action = CS_WRITE; |
| 247 | reg.Offset = 0x12; /* 0x3f2 IO base 2 */ |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 248 | reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 249 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 250 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 251 | if (res != CS_SUCCESS) { |
| 252 | printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -" |
| 253 | " res=%d\n", res); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | |
| 258 | static void sandisk_write_hcr(local_info_t *local, int hcr) |
| 259 | { |
| 260 | struct net_device *dev = local->dev; |
| 261 | int i; |
| 262 | |
| 263 | HFA384X_OUTB(0x80, SANDISK_WLAN_ACTIVATION_OFF); |
| 264 | udelay(50); |
| 265 | for (i = 0; i < 10; i++) { |
| 266 | HFA384X_OUTB(hcr, SANDISK_HCR_OFF); |
| 267 | } |
| 268 | udelay(55); |
| 269 | HFA384X_OUTB(0x45, SANDISK_WLAN_ACTIVATION_OFF); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | static int sandisk_enable_wireless(struct net_device *dev) |
| 274 | { |
| 275 | int res, ret = 0; |
| 276 | conf_reg_t reg; |
| 277 | struct hostap_interface *iface = dev->priv; |
| 278 | local_info_t *local = iface->local; |
| 279 | tuple_t tuple; |
| 280 | cisparse_t *parse = NULL; |
| 281 | u_char buf[64]; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 282 | struct hostap_cs_priv *hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 283 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 284 | if (hw_priv->link->io.NumPorts1 < 0x42) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 285 | /* Not enough ports to be SanDisk multi-function card */ |
| 286 | ret = -ENODEV; |
| 287 | goto done; |
| 288 | } |
| 289 | |
| 290 | parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL); |
| 291 | if (parse == NULL) { |
| 292 | ret = -ENOMEM; |
| 293 | goto done; |
| 294 | } |
| 295 | |
| 296 | tuple.DesiredTuple = CISTPL_MANFID; |
| 297 | tuple.Attributes = TUPLE_RETURN_COMMON; |
| 298 | tuple.TupleData = buf; |
| 299 | tuple.TupleDataMax = sizeof(buf); |
| 300 | tuple.TupleOffset = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 301 | if (pcmcia_get_first_tuple(hw_priv->link, &tuple) || |
| 302 | pcmcia_get_tuple_data(hw_priv->link, &tuple) || |
| 303 | pcmcia_parse_tuple(hw_priv->link, &tuple, parse) || |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 304 | parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) { |
| 305 | /* No SanDisk manfid found */ |
| 306 | ret = -ENODEV; |
| 307 | goto done; |
| 308 | } |
| 309 | |
| 310 | tuple.DesiredTuple = CISTPL_LONGLINK_MFC; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 311 | if (pcmcia_get_first_tuple(hw_priv->link, &tuple) || |
| 312 | pcmcia_get_tuple_data(hw_priv->link, &tuple) || |
| 313 | pcmcia_parse_tuple(hw_priv->link, &tuple, parse) || |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 314 | parse->longlink_mfc.nfn < 2) { |
| 315 | /* No multi-function links found */ |
| 316 | ret = -ENODEV; |
| 317 | goto done; |
| 318 | } |
| 319 | |
| 320 | printk(KERN_DEBUG "%s: Multi-function SanDisk ConnectPlus detected" |
| 321 | " - using vendor-specific initialization\n", dev->name); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 322 | hw_priv->sandisk_connectplus = 1; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 323 | |
| 324 | reg.Function = 0; |
| 325 | reg.Action = CS_WRITE; |
| 326 | reg.Offset = CISREG_COR; |
| 327 | reg.Value = COR_SOFT_RESET; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 328 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 329 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 330 | if (res != CS_SUCCESS) { |
| 331 | printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", |
| 332 | dev->name, res); |
| 333 | goto done; |
| 334 | } |
| 335 | mdelay(5); |
| 336 | |
| 337 | reg.Function = 0; |
| 338 | reg.Action = CS_WRITE; |
| 339 | reg.Offset = CISREG_COR; |
| 340 | /* |
| 341 | * Do not enable interrupts here to avoid some bogus events. Interrupts |
| 342 | * will be enabled during the first cor_sreset call. |
| 343 | */ |
| 344 | reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 345 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 346 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 347 | if (res != CS_SUCCESS) { |
| 348 | printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", |
| 349 | dev->name, res); |
| 350 | goto done; |
| 351 | } |
| 352 | mdelay(5); |
| 353 | |
| 354 | sandisk_set_iobase(local); |
| 355 | |
| 356 | HFA384X_OUTB(0xc5, SANDISK_WLAN_ACTIVATION_OFF); |
| 357 | udelay(10); |
| 358 | HFA384X_OUTB(0x4b, SANDISK_WLAN_ACTIVATION_OFF); |
| 359 | udelay(10); |
| 360 | |
| 361 | done: |
| 362 | kfree(parse); |
| 363 | return ret; |
| 364 | } |
| 365 | |
| 366 | |
| 367 | static void prism2_pccard_cor_sreset(local_info_t *local) |
| 368 | { |
| 369 | int res; |
| 370 | conf_reg_t reg; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 371 | struct hostap_cs_priv *hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 372 | |
| 373 | if (!prism2_pccard_card_present(local)) |
| 374 | return; |
| 375 | |
| 376 | reg.Function = 0; |
| 377 | reg.Action = CS_READ; |
| 378 | reg.Offset = CISREG_COR; |
| 379 | reg.Value = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 380 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 381 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 382 | if (res != CS_SUCCESS) { |
| 383 | printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n", |
| 384 | res); |
| 385 | return; |
| 386 | } |
| 387 | printk(KERN_DEBUG "prism2_pccard_cor_sreset: original COR %02x\n", |
| 388 | reg.Value); |
| 389 | |
| 390 | reg.Action = CS_WRITE; |
| 391 | reg.Value |= COR_SOFT_RESET; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 392 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 393 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 394 | if (res != CS_SUCCESS) { |
| 395 | printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n", |
| 396 | res); |
| 397 | return; |
| 398 | } |
| 399 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 400 | mdelay(hw_priv->sandisk_connectplus ? 5 : 2); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 401 | |
| 402 | reg.Value &= ~COR_SOFT_RESET; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 403 | if (hw_priv->sandisk_connectplus) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 404 | reg.Value |= COR_IREQ_ENA; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 405 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 406 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 407 | if (res != CS_SUCCESS) { |
| 408 | printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n", |
| 409 | res); |
| 410 | return; |
| 411 | } |
| 412 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 413 | mdelay(hw_priv->sandisk_connectplus ? 5 : 2); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 414 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 415 | if (hw_priv->sandisk_connectplus) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 416 | sandisk_set_iobase(local); |
| 417 | } |
| 418 | |
| 419 | |
| 420 | static void prism2_pccard_genesis_reset(local_info_t *local, int hcr) |
| 421 | { |
| 422 | int res; |
| 423 | conf_reg_t reg; |
| 424 | int old_cor; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 425 | struct hostap_cs_priv *hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 426 | |
| 427 | if (!prism2_pccard_card_present(local)) |
| 428 | return; |
| 429 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 430 | if (hw_priv->sandisk_connectplus) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 431 | sandisk_write_hcr(local, hcr); |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | reg.Function = 0; |
| 436 | reg.Action = CS_READ; |
| 437 | reg.Offset = CISREG_COR; |
| 438 | reg.Value = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 439 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 440 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 441 | if (res != CS_SUCCESS) { |
| 442 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 " |
| 443 | "(%d)\n", res); |
| 444 | return; |
| 445 | } |
| 446 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset: original COR %02x\n", |
| 447 | reg.Value); |
| 448 | old_cor = reg.Value; |
| 449 | |
| 450 | reg.Action = CS_WRITE; |
| 451 | reg.Value |= COR_SOFT_RESET; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 452 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 453 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 454 | if (res != CS_SUCCESS) { |
| 455 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 " |
| 456 | "(%d)\n", res); |
| 457 | return; |
| 458 | } |
| 459 | |
| 460 | mdelay(10); |
| 461 | |
| 462 | /* Setup Genesis mode */ |
| 463 | reg.Action = CS_WRITE; |
| 464 | reg.Value = hcr; |
| 465 | reg.Offset = CISREG_CCSR; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 466 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 467 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 468 | if (res != CS_SUCCESS) { |
| 469 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 " |
| 470 | "(%d)\n", res); |
| 471 | return; |
| 472 | } |
| 473 | mdelay(10); |
| 474 | |
| 475 | reg.Action = CS_WRITE; |
| 476 | reg.Offset = CISREG_COR; |
| 477 | reg.Value = old_cor & ~COR_SOFT_RESET; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 478 | res = pcmcia_access_configuration_register(hw_priv->link, |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 479 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 480 | if (res != CS_SUCCESS) { |
| 481 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 " |
| 482 | "(%d)\n", res); |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | mdelay(10); |
| 487 | } |
| 488 | |
| 489 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 490 | static struct prism2_helper_functions prism2_pccard_funcs = |
| 491 | { |
| 492 | .card_present = prism2_pccard_card_present, |
| 493 | .cor_sreset = prism2_pccard_cor_sreset, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 494 | .genesis_reset = prism2_pccard_genesis_reset, |
| 495 | .hw_type = HOSTAP_HW_PCCARD, |
| 496 | }; |
| 497 | |
| 498 | |
| 499 | /* allocate local data and register with CardServices |
| 500 | * initialize dev_link structure, but do not configure the card yet */ |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 501 | static int hostap_cs_probe(struct pcmcia_device *p_dev) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 502 | { |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 503 | int ret; |
| 504 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 505 | PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info); |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 506 | p_dev->conf.IntType = INT_MEMORY_AND_IO; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 507 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 508 | ret = prism2_config(p_dev); |
| 509 | if (ret) { |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 510 | PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n"); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 511 | } |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 512 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 513 | return ret; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 517 | static void prism2_detach(struct pcmcia_device *link) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 518 | { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 519 | PDEBUG(DEBUG_FLOW, "prism2_detach\n"); |
| 520 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 521 | prism2_release((u_long)link); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 522 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 523 | /* release net devices */ |
| 524 | if (link->priv) { |
Jouni Malinen | c355184 | 2005-10-02 17:19:00 -0700 | [diff] [blame] | 525 | struct hostap_cs_priv *hw_priv; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 526 | struct net_device *dev; |
| 527 | struct hostap_interface *iface; |
| 528 | dev = link->priv; |
| 529 | iface = netdev_priv(dev); |
Jouni Malinen | c355184 | 2005-10-02 17:19:00 -0700 | [diff] [blame] | 530 | hw_priv = iface->local->hw_priv; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 531 | prism2_free_local_data(dev); |
Jouni Malinen | c355184 | 2005-10-02 17:19:00 -0700 | [diff] [blame] | 532 | kfree(hw_priv); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 533 | } |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | |
| 537 | #define CS_CHECK(fn, ret) \ |
| 538 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) |
| 539 | |
| 540 | #define CFG_CHECK2(fn, retf) \ |
| 541 | do { int ret = (retf); \ |
| 542 | if (ret != 0) { \ |
| 543 | PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 544 | cs_error(link, fn, ret); \ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 545 | goto next_entry; \ |
| 546 | } \ |
| 547 | } while (0) |
| 548 | |
| 549 | |
| 550 | /* run after a CARD_INSERTION event is received to configure the PCMCIA |
| 551 | * socket and make the device available to the system */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 552 | static int prism2_config(struct pcmcia_device *link) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 553 | { |
| 554 | struct net_device *dev; |
| 555 | struct hostap_interface *iface; |
| 556 | local_info_t *local; |
| 557 | int ret = 1; |
| 558 | tuple_t tuple; |
| 559 | cisparse_t *parse; |
| 560 | int last_fn, last_ret; |
| 561 | u_char buf[64]; |
| 562 | config_info_t conf; |
| 563 | cistpl_cftable_entry_t dflt = { 0 }; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 564 | struct hostap_cs_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 565 | |
| 566 | PDEBUG(DEBUG_FLOW, "prism2_config()\n"); |
| 567 | |
| 568 | parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 569 | hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL); |
| 570 | if (parse == NULL || hw_priv == NULL) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 571 | ret = -ENOMEM; |
| 572 | goto failed; |
| 573 | } |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 574 | memset(hw_priv, 0, sizeof(*hw_priv)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 575 | |
| 576 | tuple.DesiredTuple = CISTPL_CONFIG; |
| 577 | tuple.Attributes = 0; |
| 578 | tuple.TupleData = buf; |
| 579 | tuple.TupleDataMax = sizeof(buf); |
| 580 | tuple.TupleOffset = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 581 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
| 582 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); |
| 583 | CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, parse)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 584 | link->conf.ConfigBase = parse->config.base; |
| 585 | link->conf.Present = parse->config.rmask[0]; |
| 586 | |
| 587 | CS_CHECK(GetConfigurationInfo, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 588 | pcmcia_get_configuration_info(link, &conf)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 589 | |
| 590 | /* Look for an appropriate configuration table entry in the CIS */ |
| 591 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 592 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 593 | for (;;) { |
| 594 | cistpl_cftable_entry_t *cfg = &(parse->cftable_entry); |
| 595 | CFG_CHECK2(GetTupleData, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 596 | pcmcia_get_tuple_data(link, &tuple)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 597 | CFG_CHECK2(ParseTuple, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 598 | pcmcia_parse_tuple(link, &tuple, parse)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 599 | |
| 600 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) |
| 601 | dflt = *cfg; |
| 602 | if (cfg->index == 0) |
| 603 | goto next_entry; |
| 604 | link->conf.ConfigIndex = cfg->index; |
| 605 | PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X " |
| 606 | "(default 0x%02X)\n", cfg->index, dflt.index); |
Jeff Garzik | 74fae82 | 2005-07-31 13:08:32 -0400 | [diff] [blame] | 607 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 608 | /* Does this card need audio output? */ |
| 609 | if (cfg->flags & CISTPL_CFTABLE_AUDIO) { |
| 610 | link->conf.Attributes |= CONF_ENABLE_SPKR; |
| 611 | link->conf.Status = CCSR_AUDIO_ENA; |
| 612 | } |
Jeff Garzik | 74fae82 | 2005-07-31 13:08:32 -0400 | [diff] [blame] | 613 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 614 | /* Use power settings for Vcc and Vpp if present */ |
| 615 | /* Note that the CIS values need to be rescaled */ |
| 616 | if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) { |
| 617 | if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / |
| 618 | 10000 && !ignore_cis_vcc) { |
| 619 | PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping" |
| 620 | " this entry\n"); |
| 621 | goto next_entry; |
| 622 | } |
| 623 | } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) { |
| 624 | if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / |
| 625 | 10000 && !ignore_cis_vcc) { |
| 626 | PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch " |
| 627 | "- skipping this entry\n"); |
| 628 | goto next_entry; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 633 | link->conf.Vpp = |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 634 | cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; |
| 635 | else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 636 | link->conf.Vpp = |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 637 | dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; |
| 638 | |
| 639 | /* Do we need to allocate an interrupt? */ |
| 640 | if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) |
| 641 | link->conf.Attributes |= CONF_ENABLE_IRQ; |
| 642 | else if (!(link->conf.Attributes & CONF_ENABLE_IRQ)) { |
| 643 | /* At least Compaq WL200 does not have IRQInfo1 set, |
| 644 | * but it does not work without interrupts.. */ |
| 645 | printk("Config has no IRQ info, but trying to enable " |
| 646 | "IRQ anyway..\n"); |
| 647 | link->conf.Attributes |= CONF_ENABLE_IRQ; |
| 648 | } |
| 649 | |
| 650 | /* IO window settings */ |
| 651 | PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d " |
| 652 | "dflt.io.nwin=%d\n", |
| 653 | cfg->io.nwin, dflt.io.nwin); |
| 654 | link->io.NumPorts1 = link->io.NumPorts2 = 0; |
| 655 | if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { |
| 656 | cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; |
| 657 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; |
| 658 | PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, " |
| 659 | "io.base=0x%04x, len=%d\n", io->flags, |
| 660 | io->win[0].base, io->win[0].len); |
| 661 | if (!(io->flags & CISTPL_IO_8BIT)) |
| 662 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; |
| 663 | if (!(io->flags & CISTPL_IO_16BIT)) |
| 664 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; |
| 665 | link->io.IOAddrLines = io->flags & |
| 666 | CISTPL_IO_LINES_MASK; |
| 667 | link->io.BasePort1 = io->win[0].base; |
| 668 | link->io.NumPorts1 = io->win[0].len; |
| 669 | if (io->nwin > 1) { |
| 670 | link->io.Attributes2 = link->io.Attributes1; |
| 671 | link->io.BasePort2 = io->win[1].base; |
| 672 | link->io.NumPorts2 = io->win[1].len; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | /* This reserves IO space but doesn't actually enable it */ |
| 677 | CFG_CHECK2(RequestIO, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 678 | pcmcia_request_io(link, &link->io)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 679 | |
| 680 | /* This configuration table entry is OK */ |
| 681 | break; |
| 682 | |
| 683 | next_entry: |
| 684 | CS_CHECK(GetNextTuple, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 685 | pcmcia_get_next_tuple(link, &tuple)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | /* Need to allocate net_device before requesting IRQ handler */ |
Dave Hansen | 0cd545d | 2005-07-30 12:49:58 -0700 | [diff] [blame] | 689 | dev = prism2_init_local_data(&prism2_pccard_funcs, 0, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 690 | &handle_to_dev(link)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 691 | if (dev == NULL) |
| 692 | goto failed; |
| 693 | link->priv = dev; |
| 694 | |
Jouni Malinen | fbff868 | 2005-08-28 17:53:32 -0700 | [diff] [blame] | 695 | iface = netdev_priv(dev); |
| 696 | local = iface->local; |
| 697 | local->hw_priv = hw_priv; |
| 698 | hw_priv->link = link; |
| 699 | strcpy(hw_priv->node.dev_name, dev->name); |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 700 | link->dev_node = &hw_priv->node; |
Jouni Malinen | fbff868 | 2005-08-28 17:53:32 -0700 | [diff] [blame] | 701 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 702 | /* |
| 703 | * Allocate an interrupt line. Note that this does not assign a |
| 704 | * handler to the interrupt, unless the 'Handler' member of the |
| 705 | * irq structure is initialized. |
| 706 | */ |
| 707 | if (link->conf.Attributes & CONF_ENABLE_IRQ) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 708 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; |
Jar | 0ef79ee | 2005-07-30 12:49:57 -0700 | [diff] [blame] | 709 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 710 | link->irq.Handler = prism2_interrupt; |
| 711 | link->irq.Instance = dev; |
| 712 | CS_CHECK(RequestIRQ, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 713 | pcmcia_request_irq(link, &link->irq)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | /* |
| 717 | * This actually configures the PCMCIA socket -- setting up |
| 718 | * the I/O windows and the interrupt mapping, and putting the |
| 719 | * card and host interface into "Memory and IO" mode. |
| 720 | */ |
| 721 | CS_CHECK(RequestConfiguration, |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 722 | pcmcia_request_configuration(link, &link->conf)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 723 | |
| 724 | dev->irq = link->irq.AssignedIRQ; |
| 725 | dev->base_addr = link->io.BasePort1; |
| 726 | |
| 727 | /* Finally, report what we've done */ |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 728 | printk(KERN_INFO "%s: index 0x%02x: ", |
| 729 | dev_info, link->conf.ConfigIndex); |
| 730 | if (link->conf.Vpp) |
| 731 | printk(", Vpp %d.%d", link->conf.Vpp / 10, |
| 732 | link->conf.Vpp % 10); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 733 | if (link->conf.Attributes & CONF_ENABLE_IRQ) |
| 734 | printk(", irq %d", link->irq.AssignedIRQ); |
| 735 | if (link->io.NumPorts1) |
| 736 | printk(", io 0x%04x-0x%04x", link->io.BasePort1, |
| 737 | link->io.BasePort1+link->io.NumPorts1-1); |
| 738 | if (link->io.NumPorts2) |
| 739 | printk(" & 0x%04x-0x%04x", link->io.BasePort2, |
| 740 | link->io.BasePort2+link->io.NumPorts2-1); |
| 741 | printk("\n"); |
| 742 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 743 | local->shutdown = 0; |
| 744 | |
| 745 | sandisk_enable_wireless(dev); |
| 746 | |
| 747 | ret = prism2_hw_config(dev, 1); |
| 748 | if (!ret) { |
| 749 | ret = hostap_hw_ready(dev); |
| 750 | if (ret == 0 && local->ddev) |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 751 | strcpy(hw_priv->node.dev_name, local->ddev->name); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 752 | } |
| 753 | kfree(parse); |
| 754 | return ret; |
| 755 | |
| 756 | cs_failed: |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 757 | cs_error(link, last_fn, last_ret); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 758 | |
| 759 | failed: |
| 760 | kfree(parse); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 761 | kfree(hw_priv); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 762 | prism2_release((u_long)link); |
| 763 | return ret; |
| 764 | } |
| 765 | |
| 766 | |
| 767 | static void prism2_release(u_long arg) |
| 768 | { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 769 | struct pcmcia_device *link = (struct pcmcia_device *)arg; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 770 | |
| 771 | PDEBUG(DEBUG_FLOW, "prism2_release\n"); |
| 772 | |
| 773 | if (link->priv) { |
| 774 | struct net_device *dev = link->priv; |
| 775 | struct hostap_interface *iface; |
| 776 | |
| 777 | iface = netdev_priv(dev); |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 778 | prism2_hw_shutdown(dev, 0); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 779 | iface->local->shutdown = 1; |
| 780 | } |
| 781 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 782 | pcmcia_disable_device(link); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 783 | PDEBUG(DEBUG_FLOW, "release - done\n"); |
| 784 | } |
| 785 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 786 | static int hostap_cs_suspend(struct pcmcia_device *link) |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 787 | { |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 788 | struct net_device *dev = (struct net_device *) link->priv; |
| 789 | int dev_open = 0; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 790 | struct hostap_interface *iface = NULL; |
| 791 | |
| 792 | if (dev) |
| 793 | iface = netdev_priv(dev); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 794 | |
| 795 | PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info); |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 796 | if (iface && iface->local) |
| 797 | dev_open = iface->local->num_dev_open > 0; |
| 798 | if (dev_open) { |
| 799 | netif_stop_queue(dev); |
| 800 | netif_device_detach(dev); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 801 | } |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 802 | prism2_suspend(dev); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 803 | |
| 804 | return 0; |
| 805 | } |
| 806 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 807 | static int hostap_cs_resume(struct pcmcia_device *link) |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 808 | { |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 809 | struct net_device *dev = (struct net_device *) link->priv; |
| 810 | int dev_open = 0; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 811 | struct hostap_interface *iface = NULL; |
| 812 | |
| 813 | if (dev) |
| 814 | iface = netdev_priv(dev); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 815 | |
| 816 | PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info); |
| 817 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 818 | if (iface && iface->local) |
| 819 | dev_open = iface->local->num_dev_open > 0; |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 820 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 821 | prism2_hw_shutdown(dev, 1); |
| 822 | prism2_hw_config(dev, dev_open ? 0 : 1); |
| 823 | if (dev_open) { |
| 824 | netif_device_attach(dev); |
| 825 | netif_start_queue(dev); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | return 0; |
| 829 | } |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 830 | |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 831 | static struct pcmcia_device_id hostap_cs_ids[] = { |
| 832 | PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100), |
| 833 | PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300), |
| 834 | PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777), |
| 835 | PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000), |
| 836 | PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002), |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 837 | PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002), |
Richard Purdie | 1e4adbd | 2005-08-04 00:16:27 +0100 | [diff] [blame] | 838 | PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b), |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 839 | PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612), |
| 840 | PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613), |
| 841 | PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002), |
| 842 | PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002), |
| 843 | PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001), |
| 844 | PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001), |
| 845 | PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300), |
Komuro | fd99ddd07 | 2006-04-17 21:41:21 +0900 | [diff] [blame] | 846 | /* PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000), conflict with pcnet_cs */ |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 847 | PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002), |
| 848 | PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005), |
| 849 | PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010), |
Christian Steineck | 884d3a2 | 2006-09-08 23:51:34 +0200 | [diff] [blame^] | 850 | PCMCIA_DEVICE_MANF_CARD(0x0126, 0x0002), |
Pavel Roskin | 40e3cad | 2006-02-28 01:18:31 -0500 | [diff] [blame] | 851 | PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "INTERSIL", |
| 852 | 0x74c5e40d), |
| 853 | PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "Intersil", |
| 854 | 0x4b801a17), |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 855 | PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus", |
| 856 | 0x7a954bd9, 0x74be00c6), |
| 857 | PCMCIA_DEVICE_PROD_ID1234( |
| 858 | "Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P", |
| 859 | "Eval-RevA", |
| 860 | 0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e), |
| 861 | PCMCIA_DEVICE_PROD_ID123( |
| 862 | "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02", |
| 863 | 0xe6ec52ce, 0x08649af2, 0x4b74baa0), |
| 864 | PCMCIA_DEVICE_PROD_ID123( |
| 865 | "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02", |
| 866 | 0x71b18589, 0xb6f1b0ab, 0x4b74baa0), |
| 867 | PCMCIA_DEVICE_PROD_ID123( |
| 868 | "Instant Wireless ", " Network PC CARD", "Version 01.02", |
| 869 | 0x11d901af, 0x6e9bd926, 0x4b74baa0), |
| 870 | PCMCIA_DEVICE_PROD_ID123( |
| 871 | "SMC", "SMC2632W", "Version 01.02", |
| 872 | 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0), |
Richard Purdie | 1e4adbd | 2005-08-04 00:16:27 +0100 | [diff] [blame] | 873 | PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G", |
Jouni Malinen | 6c5b90d | 2005-08-28 10:51:36 -0700 | [diff] [blame] | 874 | 0x2decece3, 0x82067c18), |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 875 | PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card", |
| 876 | 0x54f7c49c, 0x15a75e5b), |
| 877 | PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE", |
| 878 | 0x74c5e40d, 0xdb472a18), |
| 879 | PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card", |
| 880 | 0x0733cc81, 0x0c52f395), |
| 881 | PCMCIA_DEVICE_PROD_ID12( |
| 882 | "ZoomAir 11Mbps High", "Rate wireless Networking", |
| 883 | 0x273fe3db, 0x32a1eaee), |
Marcin Juszkiewicz | df8ccb9 | 2006-05-22 10:56:55 +0200 | [diff] [blame] | 884 | PCMCIA_DEVICE_PROD_ID123( |
| 885 | "Pretec", "CompactWLAN Card 802.11b", "2.5", |
| 886 | 0x1cadd3e5, 0xe697636c, 0x7a5bfcf1), |
| 887 | PCMCIA_DEVICE_PROD_ID123( |
| 888 | "U.S. Robotics", "IEEE 802.11b PC-CARD", "Version 01.02", |
| 889 | 0xc7b8df9d, 0x1700d087, 0x4b74baa0), |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 890 | PCMCIA_DEVICE_NULL |
| 891 | }; |
| 892 | MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids); |
| 893 | |
| 894 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 895 | static struct pcmcia_driver hostap_driver = { |
| 896 | .drv = { |
| 897 | .name = "hostap_cs", |
| 898 | }, |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 899 | .probe = hostap_cs_probe, |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 900 | .remove = prism2_detach, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 901 | .owner = THIS_MODULE, |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 902 | .id_table = hostap_cs_ids, |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 903 | .suspend = hostap_cs_suspend, |
| 904 | .resume = hostap_cs_resume, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 905 | }; |
| 906 | |
| 907 | static int __init init_prism2_pccard(void) |
| 908 | { |
| 909 | printk(KERN_INFO "%s: %s\n", dev_info, version); |
| 910 | return pcmcia_register_driver(&hostap_driver); |
| 911 | } |
| 912 | |
| 913 | static void __exit exit_prism2_pccard(void) |
| 914 | { |
| 915 | pcmcia_unregister_driver(&hostap_driver); |
| 916 | printk(KERN_INFO "%s: Driver unloaded\n", dev_info); |
| 917 | } |
| 918 | |
| 919 | |
| 920 | module_init(init_prism2_pccard); |
| 921 | module_exit(exit_prism2_pccard); |