pcmcia: use pcmcia_loop_config in misc pcmcia drivers
[pandora-kernel.git] / drivers / telephony / ixj_pcmcia.c
index dda0ca4..89c5e40 100644 (file)
@@ -3,7 +3,6 @@
 #include <linux/module.h>
 
 #include <linux/init.h>
-#include <linux/sched.h>
 #include <linux/kernel.h>      /* printk() */
 #include <linux/fs.h>          /* everything... */
 #include <linux/errno.h>       /* error codes */
@@ -46,11 +45,10 @@ static int ixj_probe(struct pcmcia_device *p_dev)
        p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
        p_dev->io.IOAddrLines = 3;
        p_dev->conf.IntType = INT_MEMORY_AND_IO;
-       p_dev->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
+       p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
        if (!p_dev->priv) {
                return -ENOMEM;
        }
-       memset(p_dev->priv, 0, sizeof(struct ixj_info_t));
 
        return ixj_config(p_dev);
 }
@@ -69,25 +67,21 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
 static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
 {
-       tuple_t tuple;
-       u_short buf[128];
        char *str;
-       int last_ret, last_fn, i, place;
+       int i, place;
        DEBUG(0, "ixj_get_serial(0x%p)\n", link);
-       tuple.TupleData = (cisdata_t *) buf;
-       tuple.TupleOffset = 0;
-       tuple.TupleDataMax = 80;
-       tuple.Attributes = 0;
-       tuple.DesiredTuple = CISTPL_VERS_1;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
-       str = (char *) buf;
-       printk("PCMCIA Version %d.%d\n", str[0], str[1]);
-       str += 2;
+
+       str = link->prod_id[0];
+       if (!str)
+               goto cs_failed;
        printk("%s", str);
-       str = str + strlen(str) + 1;
+       str = link->prod_id[1];
+       if (!str)
+               goto cs_failed;
        printk(" %s", str);
-       str = str + strlen(str) + 1;
+       str = link->prod_id[2];
+       if (!str)
+               goto cs_failed;
        place = 1;
        for (i = strlen(str) - 1; i >= 0; i--) {
                switch (str[i]) {
@@ -122,78 +116,65 @@ static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
                }
                place = place * 0x10;
        }
-       str = str + strlen(str) + 1;
+       str = link->prod_id[3];
+       if (!str)
+               goto cs_failed;
        printk(" version %s\n", str);
       cs_failed:
        return;
 }
 
+static int ixj_config_check(struct pcmcia_device *p_dev,
+                           cistpl_cftable_entry_t *cfg,
+                           void *priv_data)
+{
+       cistpl_cftable_entry_t *dflt = priv_data;
+
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               p_dev->conf.ConfigIndex = cfg->index;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+               if (io->nwin == 2) {
+                       p_dev->io.BasePort2 = io->win[1].base;
+                       p_dev->io.NumPorts2 = io->win[1].len;
+               }
+               if (pcmcia_request_io(p_dev, &p_dev->io)) {
+                       if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
+                               *dflt = *cfg;
+               } else
+                       return 0;
+       }
+       return -ENODEV;
+}
+
 static int ixj_config(struct pcmcia_device * link)
 {
        IXJ *j;
        ixj_info_t *info;
-       tuple_t tuple;
-       u_short buf[128];
-       cisparse_t parse;
-       cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
-       cistpl_cftable_entry_t dflt =
-       {
-               0
-       };
-       int last_ret, last_fn;
+       cistpl_cftable_entry_t dflt = { 0 };
+
        info = link->priv;
        DEBUG(0, "ixj_config(0x%p)\n", link);
-       tuple.TupleData = (cisdata_t *) buf;
-       tuple.TupleOffset = 0;
-       tuple.TupleDataMax = 255;
-       tuple.Attributes = 0;
-       tuple.DesiredTuple = CISTPL_CONFIG;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
-       CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
-       link->conf.ConfigBase = parse.config.base;
-       link->conf.Present = parse.config.rmask[0];
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       tuple.Attributes = 0;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-                               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-                       goto next_entry;
-               if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-                       cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-                       link->conf.ConfigIndex = cfg->index;
-                       link->io.BasePort1 = io->win[0].base;
-                       link->io.NumPorts1 = io->win[0].len;
-                       if (io->nwin == 2) {
-                               link->io.BasePort2 = io->win[1].base;
-                               link->io.NumPorts2 = io->win[1].len;
-                       }
-                       if (pcmcia_request_io(link, &link->io) != 0)
-                               goto next_entry;
-                       /* If we've got this far, we're done */
-                       break;
-               }
-             next_entry:
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
-                       dflt = *cfg;
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
-       }
 
-       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
+       if (pcmcia_loop_config(link, ixj_config_check, &dflt))
+               goto cs_failed;
+
+       if (pcmcia_request_configuration(link, &link->conf))
+               goto cs_failed;
 
        /*
         *      Register the card with the core.
-        */     
-       j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10);
+        */
+       j = ixj_pcmcia_probe(link->io.BasePort1, link->io.BasePort1 + 0x10);
 
        info->ndev = 1;
        info->node.major = PHONE_MAJOR;
        link->dev_node = &info->node;
        ixj_get_serial(link, j);
        return 0;
+
       cs_failed:
-       cs_error(link, last_fn, last_ret);
        ixj_cs_release(link);
        return -ENODEV;
 }