iwlwifi: fix regulatory
[safe/jmp/linux-2.6] / drivers / net / wireless / atmel_cs.c
index 12617cd..3240791 100644 (file)
 
 #include "atmel.h"
 
-/*
-   All the PCMCIA modules use PCMCIA_DEBUG to control debugging.  If
-   you do not define PCMCIA_DEBUG at all, all the debug code will be
-   left out.  If you compile with PCMCIA_DEBUG=0, the debug code will
-   be present but disabled -- but it can then be enabled for specific
-   modules at load time with a 'pc_debug=#' option to insmod.
-*/
-
-#ifdef PCMCIA_DEBUG
-static int pc_debug = PCMCIA_DEBUG;
-module_param(pc_debug, int, 0);
-static char *version = "$Revision: 1.2 $";
-#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args);
-#else
-#define DEBUG(n, args...)
-#endif
 
 /*====================================================================*/
 
@@ -155,11 +139,10 @@ static int atmel_probe(struct pcmcia_device *p_dev)
 {
        local_info_t *local;
 
-       DEBUG(0, "atmel_attach()\n");
+       dev_dbg(&p_dev->dev, "atmel_attach()\n");
 
        /* Interrupt setup */
-       p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
-       p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
+       p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
        p_dev->irq.Handler = NULL;
 
        /*
@@ -194,7 +177,7 @@ static int atmel_probe(struct pcmcia_device *p_dev)
 
 static void atmel_detach(struct pcmcia_device *link)
 {
-       DEBUG(0, "atmel_detach(0x%p)\n", link);
+       dev_dbg(&link->dev, "atmel_detach\n");
 
        atmel_release(link);
 
@@ -209,9 +192,6 @@ static void atmel_detach(struct pcmcia_device *link)
 
   ======================================================================*/
 
-#define CS_CHECK(fn, ret) \
-do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
-
 /* Call-back function to interrogate PCMCIA-specific information
    about the current existance of the card */
 static int card_present(void *arg)
@@ -224,24 +204,64 @@ static int card_present(void *arg)
        return 0;
 }
 
+static int atmel_config_check(struct pcmcia_device *p_dev,
+                             cistpl_cftable_entry_t *cfg,
+                             cistpl_cftable_entry_t *dflt,
+                             unsigned int vcc,
+                             void *priv_data)
+{
+       if (cfg->index == 0)
+               return -ENODEV;
+
+       /* Does this card need audio output? */
+       if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
+               p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
+               p_dev->conf.Status = CCSR_AUDIO_ENA;
+       }
+
+       /* Use power settings for Vcc and Vpp if present */
+       /*  Note that the CIS values need to be rescaled */
+       if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
+       else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
+
+       /* Do we need to allocate an interrupt? */
+       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
+               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+
+       /* IO window settings */
+       p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+               if (!(io->flags & CISTPL_IO_8BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+               if (!(io->flags & CISTPL_IO_16BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+               if (io->nwin > 1) {
+                       p_dev->io.Attributes2 = p_dev->io.Attributes1;
+                       p_dev->io.BasePort2 = io->win[1].base;
+                       p_dev->io.NumPorts2 = io->win[1].len;
+               }
+       }
+
+       /* This reserves IO space but doesn't actually enable it */
+       return pcmcia_request_io(p_dev, &p_dev->io);
+}
+
 static int atmel_config(struct pcmcia_device *link)
 {
-       tuple_t tuple;
-       cisparse_t parse;
        local_info_t *dev;
-       int last_fn, last_ret;
-       u_char buf[64];
+       int ret;
        struct pcmcia_device_id *did;
 
        dev = link->priv;
-       did = handle_to_dev(link).driver_data;
-
-       DEBUG(0, "atmel_config(0x%p)\n", link);
+       did = dev_get_drvdata(&link->dev);
 
-       tuple.Attributes = 0;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = sizeof(buf);
-       tuple.TupleOffset = 0;
+       dev_dbg(&link->dev, "atmel_config\n");
 
        /*
          In this loop, we scan the CIS for configuration table entries,
@@ -255,97 +275,44 @@ static int atmel_config(struct pcmcia_device *link)
          these things without consulting the CIS, and most client drivers
          will only use the CIS to fill in implementation-defined details.
        */
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               cistpl_cftable_entry_t dflt = { 0 };
-               cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
-               if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-                               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-                       goto next_entry;
-
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
-               if (cfg->index == 0) goto next_entry;
-               link->conf.ConfigIndex = cfg->index;
-
-               /* Does this card need audio output? */
-               if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
-                       link->conf.Attributes |= CONF_ENABLE_SPKR;
-                       link->conf.Status = CCSR_AUDIO_ENA;
-               }
-
-               /* Use power settings for Vcc and Vpp if present */
-               /*  Note that the CIS values need to be rescaled */
-               if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                               cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
-               else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                               dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
-
-               /* Do we need to allocate an interrupt? */
-               if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
-                       link->conf.Attributes |= CONF_ENABLE_IRQ;
-
-               /* IO window settings */
-               link->io.NumPorts1 = link->io.NumPorts2 = 0;
-               if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-                       cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-                       if (!(io->flags & CISTPL_IO_8BIT))
-                               link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-                       if (!(io->flags & CISTPL_IO_16BIT))
-                               link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-                       link->io.BasePort1 = io->win[0].base;
-                       link->io.NumPorts1 = io->win[0].len;
-                       if (io->nwin > 1) {
-                               link->io.Attributes2 = link->io.Attributes1;
-                               link->io.BasePort2 = io->win[1].base;
-                               link->io.NumPorts2 = io->win[1].len;
-                       }
-               }
-
-               /* This reserves IO space but doesn't actually enable it */
-               if (pcmcia_request_io(link, &link->io) != 0)
-                       goto next_entry;
-
-               /* If we got this far, we're cool! */
-               break;
-
-       next_entry:
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
-       }
+       if (pcmcia_loop_config(link, atmel_config_check, NULL))
+               goto failed;
 
        /*
          Allocate an interrupt line.  Note that this does not assign a
          handler to the interrupt, unless the 'Handler' member of the
          irq structure is initialized.
        */
-       if (link->conf.Attributes & CONF_ENABLE_IRQ)
-               CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
+       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
+               ret = pcmcia_request_irq(link, &link->irq);
+               if (ret)
+                       goto failed;
+       }
 
        /*
          This actually configures the PCMCIA socket -- setting up
          the I/O windows and the interrupt mapping, and putting the
          card and host interface into "Memory and IO" mode.
        */
-       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
+       ret = pcmcia_request_configuration(link, &link->conf);
+       if (ret)
+               goto failed;
 
        if (link->irq.AssignedIRQ == 0) {
                printk(KERN_ALERT
                       "atmel: cannot assign IRQ: check that CONFIG_ISA is set in kernel config.");
-               goto cs_failed;
+               goto failed;
        }
 
        ((local_info_t*)link->priv)->eth_dev =
                init_atmel_card(link->irq.AssignedIRQ,
                                link->io.BasePort1,
                                did ? did->driver_info : ATMEL_FW_TYPE_NONE,
-                               &handle_to_dev(link),
+                               &link->dev,
                                card_present,
                                link);
        if (!((local_info_t*)link->priv)->eth_dev)
-                       goto cs_failed;
+                       goto failed;
 
 
        /*
@@ -358,8 +325,7 @@ static int atmel_config(struct pcmcia_device *link)
 
        return 0;
 
- cs_failed:
-       cs_error(link, last_fn, last_ret);
+ failed:
        atmel_release(link);
        return -ENODEV;
 }
@@ -376,7 +342,7 @@ static void atmel_release(struct pcmcia_device *link)
 {
        struct net_device *dev = ((local_info_t*)link->priv)->eth_dev;
 
-       DEBUG(0, "atmel_release(0x%p)\n", link);
+       dev_dbg(&link->dev, "atmel_release\n");
 
        if (dev)
                stop_atmel_card(dev);