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