port to 2.6 pcmcia api
authorFrank Mori Hess <fmhess@speakeasy.net>
Mon, 31 May 2004 22:31:45 +0000 (22:31 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Mon, 31 May 2004 22:31:45 +0000 (22:31 +0000)
comedi/drivers/das08_cs.c

index e977c5776c89a1f75d0db9a09b8ad552d13dd301..b2666b5dc759d6e96cdd7b9c7fbe93519270d16b 100644 (file)
@@ -226,14 +226,6 @@ typedef struct local_info_t {
     struct bus_operations *bus;
 } local_info_t;
 
-/*====================================================================*/
-
-static void cs_error(client_handle_t handle, int func, int ret)
-{
-    error_info_t err = { func, ret };
-    CardServices(ReportError, handle, &err);
-}
-
 /*======================================================================
 
     das08_pcmcia_attach() creates an "instance" of the driver, allocating
@@ -261,10 +253,11 @@ static dev_link_t *das08_pcmcia_attach(void)
     memset(local, 0, sizeof(local_info_t));
     link = &local->link; link->priv = local;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
     /* Initialize the dev_link_t structure */
     link->release.function = &das08_pcmcia_release;
     link->release.data = (u_long)link;
-
+#endif
     /* Interrupt setup */
     link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
     link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
@@ -298,7 +291,7 @@ static dev_link_t *das08_pcmcia_attach(void)
     client_reg.event_handler = &das08_pcmcia_event;
     client_reg.Version = 0x0210;
     client_reg.event_callback_args.client_data = link;
-    ret = CardServices(RegisterClient, &link->handle, &client_reg);
+    ret = pcmcia_register_client(&link->handle, &client_reg);
     if (ret != CS_SUCCESS) {
        cs_error(link->handle, RegisterClient, ret);
        das08_pcmcia_detach(link);
@@ -347,7 +340,7 @@ static void das08_pcmcia_detach(dev_link_t *link)
 
        /* Break the link with Card Services */
        if (link->handle)
-               CardServices(DeregisterClient, link->handle);
+               pcmcia_deregister_client(link->handle);
 
        /* Unlink device structure, and free it */
        *linkp = link->next;
@@ -364,12 +357,6 @@ static void das08_pcmcia_detach(dev_link_t *link)
 
 ======================================================================*/
 
-#define CS_CHECK(fn, args...) \
-while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed
-
-#define CFG_CHECK(fn, args...) \
-if (CardServices(fn, args) != 0) goto next_entry
-
 static void das08_pcmcia_config(dev_link_t *link)
 {
        client_handle_t handle = link->handle;
@@ -393,9 +380,12 @@ static void das08_pcmcia_config(dev_link_t *link)
        tuple.TupleData = buf;
        tuple.TupleDataMax = sizeof(buf);
        tuple.TupleOffset = 0;
-       CS_CHECK(GetFirstTuple, handle, &tuple);
-       CS_CHECK(GetTupleData, handle, &tuple);
-       CS_CHECK(ParseTuple, handle, &tuple, &parse);
+       last_fn = GetFirstTuple;
+       if((last_ret = pcmcia_get_first_tuple(handle, &tuple)) != 0) goto cs_failed;
+       last_fn = GetTupleData;
+       if((last_ret = pcmcia_get_tuple_data(handle, &tuple)) != 0) goto cs_failed;
+       last_fn = ParseTuple;
+       if((last_ret = pcmcia_parse_tuple(handle, &tuple, &parse)) != 0) goto cs_failed;
        link->conf.ConfigBase = parse.config.base;
        link->conf.Present = parse.config.rmask[0];
 
@@ -403,7 +393,8 @@ static void das08_pcmcia_config(dev_link_t *link)
        link->state |= DEV_CONFIG;
 
        /* Look up the current Vcc */
-       CS_CHECK(GetConfigurationInfo, handle, &conf);
+       last_fn = GetConfigurationInfo;
+       if((last_ret = pcmcia_get_configuration_info(handle, &conf)) != 0) goto cs_failed;
        link->conf.Vcc = conf.Vcc;
 
        /*
@@ -419,11 +410,12 @@ static void das08_pcmcia_config(dev_link_t *link)
        will only use the CIS to fill in implementation-defined details.
        */
        tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, handle, &tuple);
+       last_fn = GetFirstTuple;
+       if((last_ret = pcmcia_get_first_tuple(handle, &tuple)) != 0) goto cs_failed;
        while (1) {
        cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
-       CFG_CHECK(GetTupleData, handle, &tuple);
-       CFG_CHECK(ParseTuple, handle, &tuple, &parse);
+       if((last_ret = pcmcia_get_tuple_data(handle, &tuple)) != 0) goto next_entry;
+       if((last_ret = pcmcia_parse_tuple(handle, &tuple, &parse)) != 0) goto next_entry;
 
        if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
        if (cfg->index == 0) goto next_entry;
@@ -474,7 +466,7 @@ static void das08_pcmcia_config(dev_link_t *link)
                link->io.NumPorts2 = io->win[1].len;
                }
                /* This reserves IO space but doesn't actually enable it */
-               CFG_CHECK(RequestIO, link->handle, &link->io);
+               if(pcmcia_request_io(link->handle, &link->io) != 0) goto next_entry;
        }
 
        /* If we got this far, we're cool! */
@@ -482,8 +474,9 @@ static void das08_pcmcia_config(dev_link_t *link)
 
        next_entry:
        if (link->io.NumPorts1)
-               CardServices(ReleaseIO, link->handle, &link->io);
-       CS_CHECK(GetNextTuple, handle, &tuple);
+               pcmcia_release_io(link->handle, &link->io);
+       last_fn = GetNextTuple;
+       if((last_ret = pcmcia_get_next_tuple(handle, &tuple)) != 0) goto cs_failed;
        }
 
        /*
@@ -492,14 +485,18 @@ static void das08_pcmcia_config(dev_link_t *link)
                irq structure is initialized.
        */
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
-       CS_CHECK(RequestIRQ, link->handle, &link->irq);
+       {
+               last_fn = RequestIRQ;
+               if((last_ret = pcmcia_request_irq(handle, &link->irq)) != 0) goto cs_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, link->handle, &link->conf);
+       last_fn = RequestConfiguration;
+       if((last_ret = pcmcia_request_configuration(link->handle, &link->conf)) != 0) goto cs_failed;
 
        /*
                At this point, the dev_node_t structure(s) need to be
@@ -574,12 +571,12 @@ static void das08_pcmcia_release(u_long arg)
 
     /* Don't bother checking to see if these succeed or not */
        if (link->win)
-               CardServices(ReleaseWindow, link->win);
-       CardServices(ReleaseConfiguration, link->handle);
+               pcmcia_release_window(link->win);
+       pcmcia_release_configuration(link->handle);
        if (link->io.NumPorts1)
-               CardServices(ReleaseIO, link->handle, &link->io);
+               pcmcia_release_io(link->handle, &link->io);
        if (link->irq.AssignedIRQ)
-               CardServices(ReleaseIRQ, link->handle, &link->irq);
+               pcmcia_release_irq(link->handle, &link->irq);
        link->state &= ~DEV_CONFIG;
 
        if (link->state & DEV_STALE_LINK)
@@ -614,12 +611,18 @@ static int das08_pcmcia_event(event_t event, int priority,
                        if (link->state & DEV_CONFIG)
                        {
                                ((local_info_t *)link->priv)->stop = 1;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
                                mod_timer(&link->release, jiffies + HZ/20);
+#else
+                               das08_pcmcia_release((ulong)link);
+#endif
                        }
                        break;
                case CS_EVENT_CARD_INSERTION:
                        link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
                        dev->bus = args->bus;
+#endif                 
                        das08_pcmcia_config(link);
                        break;
                case CS_EVENT_PM_SUSPEND:
@@ -629,14 +632,14 @@ static int das08_pcmcia_event(event_t event, int priority,
                        /* Mark the device as stopped, to block IO until later */
                        dev->stop = 1;
                        if (link->state & DEV_CONFIG)
-                       CardServices(ReleaseConfiguration, link->handle);
+                               pcmcia_release_configuration(link->handle);
                        break;
                case CS_EVENT_PM_RESUME:
                        link->state &= ~DEV_SUSPEND;
                        /* Fall through... */
                case CS_EVENT_CARD_RESET:
                        if (link->state & DEV_CONFIG)
-                               CardServices(RequestConfiguration, link->handle, &link->conf);
+                               pcmcia_request_configuration(link->handle, &link->conf);
                        dev->stop = 0;
 /*
 In a normal driver, additional code may go here to restore
@@ -650,28 +653,40 @@ the device state and restart IO.
 
 /*====================================================================*/
 
+struct pcmcia_driver das08_cs_driver =
+{
+       .attach = das08_pcmcia_attach,
+       .detach = das08_pcmcia_detach,
+       .owner = THIS_MODULE,
+       .drv = {
+               .name = "das08_cs",
+       },      
+};
+
 static int __init init_das08_pcmcia_cs(void)
 {
        servinfo_t serv;
        DEBUG(0, "%s\n", version);
-       CardServices(GetCardServicesInfo, &serv);
+       pcmcia_get_card_services_info(&serv);
        if (serv.Revision != CS_RELEASE_CODE)
        {
                printk(KERN_NOTICE "das08: Card Services release "
                        "does not match!\n");
                return -1;
        }
-       register_pccard_driver(&dev_info, &das08_pcmcia_attach, &das08_pcmcia_detach);
+       pcmcia_register_driver(&das08_cs_driver);
        return 0;
 }
 
 static void __exit exit_das08_pcmcia_cs(void)
 {
        DEBUG(0, "das08_pcmcia_cs: unloading\n");
-       unregister_pccard_driver(&dev_info);
+       pcmcia_unregister_driver(&das08_cs_driver);
        while (dev_list != NULL)
        {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
                del_timer(&dev_list->release);
+#endif
                if (dev_list->state & DEV_CONFIG)
                        das08_pcmcia_release((u_long)dev_list);
                das08_pcmcia_detach(dev_list);