pcmcia: rework the irq_req_t typedef
[safe/jmp/linux-2.6] / drivers / scsi / pcmcia / aha152x_stub.c
index 21c6b10..528733b 100644 (file)
@@ -37,7 +37,6 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/ioport.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/ds.h>
 
-#ifdef PCMCIA_DEBUG
-static int pc_debug = PCMCIA_DEBUG;
-module_param(pc_debug, int, 0644);
-#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
-static char *version =
-"aha152x_cs.c 1.54 2000/06/12 21:27:25 (David Hinds)";
-#else
-#define DEBUG(n, args...)
-#endif
 
 /*====================================================================*/
 
@@ -96,46 +86,40 @@ typedef struct scsi_info_t {
 
 static void aha152x_release_cs(struct pcmcia_device *link);
 static void aha152x_detach(struct pcmcia_device *p_dev);
-static void aha152x_config_cs(struct pcmcia_device *link);
+static int aha152x_config_cs(struct pcmcia_device *link);
 
 static struct pcmcia_device *dev_list;
 
-static int aha152x_attach(struct pcmcia_device *link)
+static int aha152x_probe(struct pcmcia_device *link)
 {
     scsi_info_t *info;
 
-    DEBUG(0, "aha152x_attach()\n");
+    dev_dbg(&link->dev, "aha152x_attach()\n");
 
     /* Create new SCSI device */
-    info = kmalloc(sizeof(*info), GFP_KERNEL);
+    info = kzalloc(sizeof(*info), GFP_KERNEL);
     if (!info) return -ENOMEM;
-    memset(info, 0, sizeof(*info));
     info->p_dev = link;
     link->priv = info;
 
     link->io.NumPorts1 = 0x20;
     link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
     link->io.IOAddrLines = 10;
-    link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
-    link->irq.IRQInfo1 = IRQ_LEVEL_ID;
+    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
     link->conf.Present = PRESENT_OPTION;
 
-    link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-    aha152x_config_cs(link);
-
-    return 0;
+    return aha152x_config_cs(link);
 } /* aha152x_attach */
 
 /*====================================================================*/
 
 static void aha152x_detach(struct pcmcia_device *link)
 {
-    DEBUG(0, "aha152x_detach(0x%p)\n", link);
+    dev_dbg(&link->dev, "aha152x_detach\n");
 
-    if (link->state & DEV_CONFIG)
-       aha152x_release_cs(link);
+    aha152x_release_cs(link);
 
     /* Unlink device structure, free bits */
     kfree(link->priv);
@@ -143,57 +127,46 @@ static void aha152x_detach(struct pcmcia_device *link)
 
 /*====================================================================*/
 
-#define CS_CHECK(fn, ret) \
-do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
+static int aha152x_config_check(struct pcmcia_device *p_dev,
+                               cistpl_cftable_entry_t *cfg,
+                               cistpl_cftable_entry_t *dflt,
+                               unsigned int vcc,
+                               void *priv_data)
+{
+       /* For New Media T&J, look for a SCSI window */
+       if (cfg->io.win[0].len >= 0x20)
+               p_dev->io.BasePort1 = cfg->io.win[0].base;
+       else if ((cfg->io.nwin > 1) &&
+                (cfg->io.win[1].len >= 0x20))
+               p_dev->io.BasePort1 = cfg->io.win[1].base;
+       if ((cfg->io.nwin > 0) &&
+           (p_dev->io.BasePort1 < 0xffff)) {
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       }
+       return -EINVAL;
+}
 
-static void aha152x_config_cs(struct pcmcia_device *link)
+static int aha152x_config_cs(struct pcmcia_device *link)
 {
     scsi_info_t *info = link->priv;
     struct aha152x_setup s;
-    tuple_t tuple;
-    cisparse_t parse;
-    int i, last_ret, last_fn;
-    u_char tuple_data[64];
+    int ret;
     struct Scsi_Host *host;
-    
-    DEBUG(0, "aha152x_config(0x%p)\n", link);
-
-    tuple.DesiredTuple = CISTPL_CONFIG;
-    tuple.TupleData = tuple_data;
-    tuple.TupleDataMax = 64;
-    tuple.TupleOffset = 0;
-    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;
-
-    /* Configure card */
-    link->state |= DEV_CONFIG;
-
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    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;
-       /* For New Media T&J, look for a SCSI window */
-       if (parse.cftable_entry.io.win[0].len >= 0x20)
-           link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
-       else if ((parse.cftable_entry.io.nwin > 1) &&
-                (parse.cftable_entry.io.win[1].len >= 0x20))
-           link->io.BasePort1 = parse.cftable_entry.io.win[1].base;
-       if ((parse.cftable_entry.io.nwin > 0) &&
-           (link->io.BasePort1 < 0xffff)) {
-           link->conf.ConfigIndex = parse.cftable_entry.index;
-           i = pcmcia_request_io(link, &link->io);
-           if (i == CS_SUCCESS) break;
-       }
-    next_entry:
-       CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
-    }
-    
-    CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
-    CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
+
+    dev_dbg(&link->dev, "aha152x_config\n");
+
+    ret = pcmcia_loop_config(link, aha152x_config_check, NULL);
+    if (ret)
+           goto failed;
+
+    ret = pcmcia_request_irq(link, &link->irq);
+    if (ret)
+           goto failed;
+
+    ret = pcmcia_request_configuration(link, &link->conf);
+    if (ret)
+           goto failed;
     
     /* Set configuration options for the aha152x driver */
     memset(&s, 0, sizeof(s));
@@ -211,20 +184,18 @@ static void aha152x_config_cs(struct pcmcia_device *link)
     host = aha152x_probe_one(&s);
     if (host == NULL) {
        printk(KERN_INFO "aha152x_cs: no SCSI devices found\n");
-       goto cs_failed;
+       goto failed;
     }
 
     sprintf(info->node.dev_name, "scsi%d", host->host_no);
     link->dev_node = &info->node;
     info->host = host;
 
-    link->state &= ~DEV_CONFIG_PENDING;
-    return;
-    
-cs_failed:
-    cs_error(link, last_fn, last_ret);
+    return 0;
+
+failed:
     aha152x_release_cs(link);
-    return;
+    return -ENODEV;
 }
 
 static void aha152x_release_cs(struct pcmcia_device *link)
@@ -259,7 +230,7 @@ static struct pcmcia_driver aha152x_cs_driver = {
        .drv            = {
                .name   = "aha152x_cs",
        },
-       .probe          = aha152x_attach,
+       .probe          = aha152x_probe,
        .remove         = aha152x_detach,
        .id_table       = aha152x_ids,
        .resume         = aha152x_resume,
@@ -278,4 +249,3 @@ static void __exit exit_aha152x_cs(void)
 
 module_init(init_aha152x_cs);
 module_exit(exit_aha152x_cs);