linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / net / wireless / wl3501_cs.c
index 1433e5a..48e10b0 100644 (file)
@@ -49,7 +49,6 @@
 
 #include <net/iw_handler.h>
 
-#include <pcmcia/version.h>
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
@@ -106,7 +105,6 @@ module_param(pc_debug, int, 0);
  */
 static void wl3501_config(dev_link_t *link);
 static void wl3501_release(dev_link_t *link);
-static int wl3501_event(event_t event, int pri, event_callback_args_t *args);
 
 /*
  * The dev_info variable is the "key" that is used to match up this
@@ -297,7 +295,8 @@ static int wl3501_get_flash_mac_addr(struct wl3501_card *this)
  *
  * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
  */
-void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src, int size)
+static void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src,
+                             int size)
 {
        /* switch to SRAM Page 0 */
        wl3501_switch_page(this, (dest & 0x8000) ? WL3501_BSS_SPAGE1 :
@@ -318,8 +317,8 @@ void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src, int size)
  *
  * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
  */
-void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
-                        int size)
+static void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
+                               int size)
 {
        /* switch to SRAM Page 0 */
        wl3501_switch_page(this, (src & 0x8000) ? WL3501_BSS_SPAGE1 :
@@ -1439,14 +1438,14 @@ fail:
        goto out;
 }
 
-struct net_device_stats *wl3501_get_stats(struct net_device *dev)
+static struct net_device_stats *wl3501_get_stats(struct net_device *dev)
 {
        struct wl3501_card *this = dev->priv;
 
        return &this->stats;
 }
 
-struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev)
+static struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev)
 {
        struct wl3501_card *this = dev->priv;
        struct iw_statistics *wstats = &this->wstats;
@@ -1498,9 +1497,11 @@ static struct ethtool_ops ops = {
  * Services. If it has been released, all local data structures are freed.
  * Otherwise, the structures will be freed when the device is released.
  */
-static void wl3501_detach(dev_link_t *link)
+static void wl3501_detach(struct pcmcia_device *p_dev)
 {
+       dev_link_t *link = dev_to_instance(p_dev);
        dev_link_t **linkp;
+       struct net_device *dev = link->priv;
 
        /* Locate device structure */
        for (linkp = &wl3501_dev_list; *linkp; linkp = &(*linkp)->next)
@@ -1514,16 +1515,12 @@ static void wl3501_detach(dev_link_t *link)
         * function is called, that will trigger a proper detach(). */
 
        if (link->state & DEV_CONFIG) {
-#ifdef PCMCIA_DEBUG
-               printk(KERN_DEBUG "wl3501_cs: detach postponed, '%s' "
-                      "still locked\n", link->dev->dev_name);
-#endif
-               goto out;
-       }
+               while (link->open > 0)
+                       wl3501_close(dev);
 
-       /* Break the link with Card Services */
-       if (link->handle)
-               pcmcia_deregister_client(link->handle);
+               netif_device_detach(dev);
+               wl3501_release(link);
+       }
 
        /* Unlink device structure, free pieces */
        *linkp = link->next;
@@ -1944,7 +1941,7 @@ static const iw_handler   wl3501_handler[] = {
 static const struct iw_handler_def wl3501_handler_def = {
        .num_standard   = sizeof(wl3501_handler) / sizeof(iw_handler),
        .standard       = (iw_handler *)wl3501_handler,
-       .spy_offset     = offsetof(struct wl3501_card, spy_data),
+       .get_wireless_stats = wl3501_get_wireless_stats,
 };
 
 /**
@@ -1956,18 +1953,16 @@ static const struct iw_handler_def wl3501_handler_def = {
  * The dev_link structure is initialized, but we don't actually configure the
  * card at this point -- we wait until we receive a card insertion event.
  */
-static dev_link_t *wl3501_attach(void)
+static int wl3501_attach(struct pcmcia_device *p_dev)
 {
-       client_reg_t client_reg;
        dev_link_t *link;
        struct net_device *dev;
-       int ret;
+       struct wl3501_card *this;
 
        /* Initialize the dev_link_t structure */
-       link = kmalloc(sizeof(*link), GFP_KERNEL);
+       link = kzalloc(sizeof(*link), GFP_KERNEL);
        if (!link)
-               goto out;
-       memset(link, 0, sizeof(struct dev_link_t));
+               return -ENOMEM;
 
        /* The io structure describes IO port mapping */
        link->io.NumPorts1      = 16;
@@ -1995,37 +1990,25 @@ static dev_link_t *wl3501_attach(void)
        dev->tx_timeout         = wl3501_tx_timeout;
        dev->watchdog_timeo     = 5 * HZ;
        dev->get_stats          = wl3501_get_stats;
-       dev->get_wireless_stats = wl3501_get_wireless_stats;
+       this = dev->priv;
+       this->wireless_data.spy_data = &this->spy_data;
+       dev->wireless_data      = &this->wireless_data;
        dev->wireless_handlers  = (struct iw_handler_def *)&wl3501_handler_def;
        SET_ETHTOOL_OPS(dev, &ops);
        netif_stop_queue(dev);
        link->priv = link->irq.Instance = dev;
 
-       /* Register with Card Services */
-       link->next               = wl3501_dev_list;
-       wl3501_dev_list          = link;
-       client_reg.dev_info      = &wl3501_dev_info;
-       client_reg.EventMask     = CS_EVENT_CARD_INSERTION |
-                                  CS_EVENT_RESET_PHYSICAL |
-                                  CS_EVENT_CARD_RESET |
-                                  CS_EVENT_CARD_REMOVAL |
-                                  CS_EVENT_PM_SUSPEND |
-                                  CS_EVENT_PM_RESUME;
-       client_reg.event_handler = wl3501_event;
-       client_reg.Version       = 0x0210;
-       client_reg.event_callback_args.client_data = link;
-       ret = pcmcia_register_client(&link->handle, &client_reg);
-       if (ret) {
-               cs_error(link->handle, RegisterClient, ret);
-               wl3501_detach(link);
-               link = NULL;
-       }
-out:
-       return link;
+       link->handle = p_dev;
+       p_dev->instance = link;
+
+       link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
+       wl3501_config(link);
+
+       return 0;
 out_link:
        kfree(link);
        link = NULL;
-       goto out;
+       return -ENOMEM;
 }
 
 #define CS_CHECK(fn, ret) \
@@ -2178,74 +2161,57 @@ static void wl3501_release(dev_link_t *link)
        link->state &= ~DEV_CONFIG;
 }
 
-/**
- * wl3501_event - The card status event handler
- * @event - event
- * @pri - priority
- * @args - arguments for this event
- *
- * The card status event handler. Mostly, this schedules other stuff to run
- * after an event is received. A CARD_REMOVAL event also sets some flags to
- * discourage the net drivers from trying to talk to the card any more.
- *
- * When a CARD_REMOVAL event is received, we immediately set a flag to block
- * future accesses to this device. All the functions that actually access the
- * device should check this flag to make sure the card is still present.
- */
-static int wl3501_event(event_t event, int pri, event_callback_args_t *args)
+static int wl3501_suspend(struct pcmcia_device *p_dev)
 {
-       dev_link_t *link = args->client_data;
+       dev_link_t *link = dev_to_instance(p_dev);
        struct net_device *dev = link->priv;
 
-       switch (event) {
-       case CS_EVENT_CARD_REMOVAL:
-               link->state &= ~DEV_PRESENT;
-               if (link->state & DEV_CONFIG) {
-                       while (link->open > 0)
-                               wl3501_close(dev);
+       link->state |= DEV_SUSPEND;
+
+       wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND);
+       if (link->state & DEV_CONFIG) {
+               if (link->open)
                        netif_device_detach(dev);
-                       wl3501_release(link);
-               }
-               break;
-       case CS_EVENT_CARD_INSERTION:
-               link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-               wl3501_config(link);
-               break;
-       case CS_EVENT_PM_SUSPEND:
-               link->state |= DEV_SUSPEND;
-               wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND);
-               /* Fall through... */
-       case CS_EVENT_RESET_PHYSICAL:
-               if (link->state & DEV_CONFIG) {
-                       if (link->open)
-                               netif_device_detach(dev);
-                       pcmcia_release_configuration(link->handle);
-               }
-               break;
-       case CS_EVENT_PM_RESUME:
-               link->state &= ~DEV_SUSPEND;
-               wl3501_pwr_mgmt(dev->priv, WL3501_RESUME);
-               /* Fall through... */
-       case CS_EVENT_CARD_RESET:
-               if (link->state & DEV_CONFIG) {
-                       pcmcia_request_configuration(link->handle, &link->conf);
-                       if (link->open) {
-                               wl3501_reset(dev);
-                               netif_device_attach(dev);
-                       }
+               pcmcia_release_configuration(link->handle);
+       }
+
+       return 0;
+}
+
+static int wl3501_resume(struct pcmcia_device *p_dev)
+{
+       dev_link_t *link = dev_to_instance(p_dev);
+       struct net_device *dev = link->priv;
+
+       wl3501_pwr_mgmt(dev->priv, WL3501_RESUME);
+       if (link->state & DEV_CONFIG) {
+               pcmcia_request_configuration(link->handle, &link->conf);
+               if (link->open) {
+                       wl3501_reset(dev);
+                       netif_device_attach(dev);
                }
-               break;
        }
+
        return 0;
 }
 
+
+static struct pcmcia_device_id wl3501_ids[] = {
+       PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
+       PCMCIA_DEVICE_NULL
+};
+MODULE_DEVICE_TABLE(pcmcia, wl3501_ids);
+
 static struct pcmcia_driver wl3501_driver = {
-       .owner          = THIS_MODULE,
-       .drv            = {
-               .name   = "wl3501_cs",
+       .owner          = THIS_MODULE,
+       .drv            = {
+               .name   = "wl3501_cs",
        },
-       .attach         = wl3501_attach,
-       .detach         = wl3501_detach,
+       .probe          = wl3501_attach,
+       .remove         = wl3501_detach,
+       .id_table       = wl3501_ids,
+       .suspend        = wl3501_suspend,
+       .resume         = wl3501_resume,
 };
 
 static int __init wl3501_init_module(void)