]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/isdn/hisax/avma1_cs.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
[linux-2.6-omap-h63xx.git] / drivers / isdn / hisax / avma1_cs.c
index 969da40c42486cb83a27e5bb43b49f2b7ee79956..23560c897ec361d59526ffa1d36fad6264ddadcb 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <linux/kernel.h>
 #include <linux/init.h>
-#include <linux/sched.h>
 #include <linux/ptrace.h>
 #include <linux/slab.h>
 #include <linux/string.h>
@@ -67,8 +66,8 @@ module_param(isdnprot, int, 0);
    handler.
 */
 
-static void avma1cs_config(dev_link_t *link);
-static void avma1cs_release(dev_link_t *link);
+static int avma1cs_config(struct pcmcia_device *link);
+static void avma1cs_release(struct pcmcia_device *link);
 
 /*
    The attach() and detach() entry points are used to create and destroy
@@ -82,10 +81,10 @@ static void avma1cs_detach(struct pcmcia_device *p_dev);
 /*
    A linked list of "instances" of the skeleton device.  Each actual
    PCMCIA card corresponds to one device instance, and is described
-   by one dev_link_t structure (defined in ds.h).
+   by one struct pcmcia_device structure (defined in ds.h).
 
    You may not want to use a linked list for this -- for example, the
-   memory card driver uses an array of dev_link_t pointers, where minor
+   memory card driver uses an array of struct pcmcia_device pointers, where minor
    device numbers are used to derive the corresponding array index.
 */
 
@@ -95,7 +94,7 @@ static void avma1cs_detach(struct pcmcia_device *p_dev);
    example, ethernet cards, modems).  In other cases, there may be
    many actual or logical devices (SCSI adapters, memory cards with
    multiple partitions).  The dev_node_t structures need to be kept
-   in a linked list starting at the 'dev' field of a dev_link_t
+   in a linked list starting at the 'dev' field of a struct pcmcia_device
    structure.  We allocate them in the card's private data structure,
    because they generally can't be allocated dynamically.
 */
@@ -116,55 +115,39 @@ typedef struct local_info_t {
     
 ======================================================================*/
 
-static int avma1cs_attach(struct pcmcia_device *p_dev)
+static int avma1cs_probe(struct pcmcia_device *p_dev)
 {
-    dev_link_t *link;
     local_info_t *local;
 
     DEBUG(0, "avma1cs_attach()\n");
 
-    /* Initialize the dev_link_t structure */
-    link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
-    if (!link)
-       return -ENOMEM;
-    memset(link, 0, sizeof(struct dev_link_t));
-
     /* Allocate space for private device-specific data */
-    local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
-    if (!local) {
-       kfree(link);
+    local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
+    if (!local)
        return -ENOMEM;
-    }
-    memset(local, 0, sizeof(local_info_t));
-    link->priv = local;
+
+    p_dev->priv = local;
 
     /* The io structure describes IO port mapping */
-    link->io.NumPorts1 = 16;
-    link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-    link->io.NumPorts2 = 16;
-    link->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
-    link->io.IOAddrLines = 5;
+    p_dev->io.NumPorts1 = 16;
+    p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+    p_dev->io.NumPorts2 = 16;
+    p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
+    p_dev->io.IOAddrLines = 5;
 
     /* Interrupt setup */
-    link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
+    p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
+    p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
 
-    link->irq.IRQInfo1 = IRQ_LEVEL_ID;
+    p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
 
     /* General socket configuration */
-    link->conf.Attributes = CONF_ENABLE_IRQ;
-    link->conf.Vcc = 50;
-    link->conf.IntType = INT_MEMORY_AND_IO;
-    link->conf.ConfigIndex = 1;
-    link->conf.Present = PRESENT_OPTION;
-
-    link->handle = p_dev;
-    p_dev->instance = link;
-
-    link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-    avma1cs_config(link);
+    p_dev->conf.Attributes = CONF_ENABLE_IRQ;
+    p_dev->conf.IntType = INT_MEMORY_AND_IO;
+    p_dev->conf.ConfigIndex = 1;
+    p_dev->conf.Present = PRESENT_OPTION;
 
-    return 0;
+    return avma1cs_config(p_dev);
 } /* avma1cs_attach */
 
 /*======================================================================
@@ -176,17 +159,11 @@ static int avma1cs_attach(struct pcmcia_device *p_dev)
 
 ======================================================================*/
 
-static void avma1cs_detach(struct pcmcia_device *p_dev)
+static void avma1cs_detach(struct pcmcia_device *link)
 {
-    dev_link_t *link = dev_to_instance(p_dev);
-
-    DEBUG(0, "avma1cs_detach(0x%p)\n", link);
-
-    if (link->state & DEV_CONFIG)
-           avma1cs_release(link);
-
-    kfree(link->priv);
-    kfree(link);
+       DEBUG(0, "avma1cs_detach(0x%p)\n", link);
+       avma1cs_release(link);
+       kfree(link->priv);
 } /* avma1cs_detach */
 
 /*======================================================================
@@ -197,134 +174,63 @@ static void avma1cs_detach(struct pcmcia_device *p_dev)
     
 ======================================================================*/
 
-static int get_tuple(client_handle_t handle, tuple_t *tuple,
-                    cisparse_t *parse)
-{
-    int i = pcmcia_get_tuple_data(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return pcmcia_parse_tuple(handle, tuple, parse);
-}
-
-static int first_tuple(client_handle_t handle, tuple_t *tuple,
-                    cisparse_t *parse)
+static int avma1cs_configcheck(struct pcmcia_device *p_dev,
+                              cistpl_cftable_entry_t *cf,
+                              cistpl_cftable_entry_t *dflt,
+                              unsigned int vcc,
+                              void *priv_data)
 {
-    int i = pcmcia_get_first_tuple(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return get_tuple(handle, tuple, parse);
+       if (cf->io.nwin <= 0)
+               return -ENODEV;
+
+       p_dev->io.BasePort1 = cf->io.win[0].base;
+       p_dev->io.NumPorts1 = cf->io.win[0].len;
+       p_dev->io.NumPorts2 = 0;
+       printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
+              p_dev->io.BasePort1,
+              p_dev->io.BasePort1+p_dev->io.NumPorts1-1);
+       return pcmcia_request_io(p_dev, &p_dev->io);
 }
 
-static int next_tuple(client_handle_t handle, tuple_t *tuple,
-                    cisparse_t *parse)
-{
-    int i = pcmcia_get_next_tuple(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return get_tuple(handle, tuple, parse);
-}
 
-static void avma1cs_config(dev_link_t *link)
+static int avma1cs_config(struct pcmcia_device *link)
 {
-    client_handle_t handle;
-    tuple_t tuple;
-    cisparse_t parse;
-    cistpl_cftable_entry_t *cf = &parse.cftable_entry;
     local_info_t *dev;
     int i;
-    u_char buf[64];
     char devname[128];
     IsdnCard_t icard;
     int busy = 0;
-    
-    handle = link->handle;
+
     dev = link->priv;
 
     DEBUG(0, "avma1cs_config(0x%p)\n", link);
 
-    /*
-       This reads the card's CONFIG tuple to find its configuration
-       registers.
-    */
-    do {
-       tuple.DesiredTuple = CISTPL_CONFIG;
-       i = pcmcia_get_first_tuple(handle, &tuple);
-       if (i != CS_SUCCESS) break;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = 64;
-       tuple.TupleOffset = 0;
-       i = pcmcia_get_tuple_data(handle, &tuple);
-       if (i != CS_SUCCESS) break;
-       i = pcmcia_parse_tuple(handle, &tuple, &parse);
-       if (i != CS_SUCCESS) break;
-       link->conf.ConfigBase = parse.config.base;
-    } while (0);
-    if (i != CS_SUCCESS) {
-       cs_error(link->handle, ParseTuple, i);
-       link->state &= ~DEV_CONFIG_PENDING;
-       return;
-    }
-    
-    /* Configure card */
-    link->state |= DEV_CONFIG;
-
-    do {
+    devname[0] = 0;
+    if (link->prod_id[1])
+           strlcpy(devname, link->prod_id[1], sizeof(devname));
 
-       tuple.Attributes = 0;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = 254;
-       tuple.TupleOffset = 0;
-       tuple.DesiredTuple = CISTPL_VERS_1;
+    if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
+           return -ENODEV;
 
-       devname[0] = 0;
-       if( !first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 1 ) {
-           strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1], 
-                       sizeof(devname));
-       }
-       /*
-         * find IO port
-         */
-       tuple.TupleData = (cisdata_t *)buf;
-       tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
-       tuple.Attributes = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       i = first_tuple(handle, &tuple, &parse);
-       while (i == CS_SUCCESS) {
-           if (cf->io.nwin > 0) {
-               link->conf.ConfigIndex = cf->index;
-               link->io.BasePort1 = cf->io.win[0].base;
-               link->io.NumPorts1 = cf->io.win[0].len;
-               link->io.NumPorts2 = 0;
-               printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
-                       link->io.BasePort1,
-                       link->io.BasePort1+link->io.NumPorts1 - 1);
-               i = pcmcia_request_io(link->handle, &link->io);
-               if (i == CS_SUCCESS) goto found_port;
-           }
-           i = next_tuple(handle, &tuple, &parse);
-       }
-
-found_port:
-       if (i != CS_SUCCESS) {
-           cs_error(link->handle, RequestIO, i);
-           break;
-       }
-       
+    do {
        /*
         * allocate an interrupt line
         */
-       i = pcmcia_request_irq(link->handle, &link->irq);
-       if (i != CS_SUCCESS) {
-           cs_error(link->handle, RequestIRQ, i);
-           pcmcia_release_io(link->handle, &link->io);
+       i = pcmcia_request_irq(link, &link->irq);
+       if (i != 0) {
+           cs_error(link, RequestIRQ, i);
+           /* undo */
+           pcmcia_disable_device(link);
            break;
        }
-       
+
        /*
         * configure the PCMCIA socket
         */
-       i = pcmcia_request_configuration(link->handle, &link->conf);
-       if (i != CS_SUCCESS) {
-           cs_error(link->handle, RequestConfiguration, i);
-           pcmcia_release_io(link->handle, &link->io);
-           pcmcia_release_irq(link->handle, &link->irq);
+       i = pcmcia_request_configuration(link, &link->conf);
+       if (i != 0) {
+           cs_error(link, RequestConfiguration, i);
+           pcmcia_disable_device(link);
            break;
        }
 
@@ -336,13 +242,12 @@ found_port:
     strcpy(dev->node.dev_name, "A1");
     dev->node.major = 45;
     dev->node.minor = 0;
-    link->dev = &dev->node;
-    
-    link->state &= ~DEV_CONFIG_PENDING;
+    link->dev_node = &dev->node;
+
     /* If any step failed, release any partially configured state */
     if (i != 0) {
        avma1cs_release(link);
-       return;
+       return -ENODEV;
     }
 
     printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
@@ -357,10 +262,11 @@ found_port:
     if (i < 0) {
        printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 PCMCIA %d at i/o %#x\n", i, link->io.BasePort1);
        avma1cs_release(link);
-       return;
+       return -ENODEV;
     }
     dev->node.minor = i;
 
+    return 0;
 } /* avma1cs_config */
 
 /*======================================================================
@@ -371,47 +277,18 @@ found_port:
     
 ======================================================================*/
 
-static void avma1cs_release(dev_link_t *link)
+static void avma1cs_release(struct pcmcia_device *link)
 {
-    local_info_t *local = link->priv;
+       local_info_t *local = link->priv;
 
-    DEBUG(0, "avma1cs_release(0x%p)\n", link);
+       DEBUG(0, "avma1cs_release(0x%p)\n", link);
 
-    /* no unregister function with hisax */
-    HiSax_closecard(local->node.minor);
+       /* now unregister function with hisax */
+       HiSax_closecard(local->node.minor);
 
-    /* Unlink the device chain */
-    link->dev = NULL;
-    
-    /* Don't bother checking to see if these succeed or not */
-    pcmcia_release_configuration(link->handle);
-    pcmcia_release_io(link->handle, &link->io);
-    pcmcia_release_irq(link->handle, &link->irq);
-    link->state &= ~DEV_CONFIG;
+       pcmcia_disable_device(link);
 } /* avma1cs_release */
 
-static int avma1cs_suspend(struct pcmcia_device *dev)
-{
-       dev_link_t *link = dev_to_instance(dev);
-
-       link->state |= DEV_SUSPEND;
-       if (link->state & DEV_CONFIG)
-               pcmcia_release_configuration(link->handle);
-
-       return 0;
-}
-
-static int avma1cs_resume(struct pcmcia_device *dev)
-{
-       dev_link_t *link = dev_to_instance(dev);
-
-       link->state &= ~DEV_SUSPEND;
-       if (link->state & DEV_CONFIG)
-               pcmcia_request_configuration(link->handle, &link->conf);
-
-       return 0;
-}
-
 
 static struct pcmcia_device_id avma1cs_ids[] = {
        PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
@@ -425,13 +302,11 @@ static struct pcmcia_driver avma1cs_driver = {
        .drv            = {
                .name   = "avma1_cs",
        },
-       .probe          = avma1cs_attach,
+       .probe          = avma1cs_probe,
        .remove         = avma1cs_detach,
        .id_table       = avma1cs_ids,
-       .suspend        = avma1cs_suspend,
-       .resume         = avma1cs_resume,
 };
+
 /*====================================================================*/
 
 static int __init init_avma1_cs(void)