From 28057acbedf3d01c4ab4ecbfb84a74c4b8ce4311 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Mon, 31 May 2004 23:01:10 +0000 Subject: [PATCH] port to 2.6 pcmcia api --- comedi/drivers/ni_daq_dio24.c | 141 +++++++++++++++++++++------------- 1 file changed, 87 insertions(+), 54 deletions(-) diff --git a/comedi/drivers/ni_daq_dio24.c b/comedi/drivers/ni_daq_dio24.c index ba86f0de..d328eda8 100644 --- a/comedi/drivers/ni_daq_dio24.c +++ b/comedi/drivers/ni_daq_dio24.c @@ -52,7 +52,6 @@ the PCMCIA interface. #include #include #include -#include /* A linked list of "instances" of the dummy device. Each actual @@ -302,14 +301,6 @@ typedef struct local_info_t { struct bus_operations *bus; } local_info_t; -/*====================================================================*/ - -static void my_cs_error(client_handle_t handle, int func, int ret) -{ - error_info_t err = { func, ret }; - CardServices(ReportError, handle, &err); -} - /*====================================================================== dio24_cs_attach() creates an "instance" of the driver, allocating @@ -339,10 +330,11 @@ static dev_link_t *dio24_cs_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 = &dio24_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; @@ -376,9 +368,9 @@ static dev_link_t *dio24_cs_attach(void) client_reg.event_handler = &dio24_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) { - my_cs_error(link->handle, RegisterClient, ret); + cs_error(link->handle, RegisterClient, ret); dio24_cs_detach(link); return NULL; } @@ -426,7 +418,7 @@ static void dio24_cs_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; @@ -443,11 +435,6 @@ static void dio24_cs_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 dio24_config(dev_link_t *link) { @@ -455,7 +442,7 @@ static void dio24_config(dev_link_t *link) local_info_t *dev = link->priv; tuple_t tuple; cisparse_t parse; - int last_fn, last_ret; + int last_ret; u_char buf[64]; config_info_t conf; win_req_t req; @@ -475,9 +462,21 @@ static void dio24_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); + if((last_ret = pcmcia_get_first_tuple(handle, &tuple)) != 0) + { + cs_error(handle, GetFirstTuple, last_ret); + goto cs_failed; + } + if((last_ret = pcmcia_get_tuple_data(handle, &tuple)) != 0) + { + cs_error(handle, GetTupleData, last_ret); + goto cs_failed; + } + if((last_ret = pcmcia_parse_tuple(handle, &tuple, &parse)) != 0) + { + cs_error(handle, ParseTuple, last_ret); + goto cs_failed; + } link->conf.ConfigBase = parse.config.base; link->conf.Present = parse.config.rmask[0]; @@ -485,7 +484,11 @@ static void dio24_config(dev_link_t *link) link->state |= DEV_CONFIG; /* Look up the current Vcc */ - CS_CHECK(GetConfigurationInfo, handle, &conf); + if((last_ret = pcmcia_get_configuration_info(handle, &conf)) != 0) + { + cs_error(handle, GetConfigurationInfo, last_ret); + goto cs_failed; + } link->conf.Vcc = conf.Vcc; /* @@ -501,11 +504,15 @@ static void dio24_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); + if((last_ret = pcmcia_get_first_tuple(handle, &tuple)) != 0) + { + cs_error(handle, GetFirstTuple, last_ret); + 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(pcmcia_get_tuple_data(handle, &tuple) != 0) goto next_entry; + if(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; @@ -556,7 +563,7 @@ static void dio24_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; } /* @@ -580,18 +587,21 @@ static void dio24_config(dev_link_t *link) if (req.Size < 0x1000) req.Size = 0x1000; req.AccessSpeed = 0; - link->win = (window_handle_t)link->handle; - CFG_CHECK(RequestWindow, &link->win, &req); + if(pcmcia_request_window(&link->handle, &req, &link->win)) goto next_entry; map.Page = 0; map.CardOffset = mem->win[0].card_addr; - CFG_CHECK(MapMemPage, link->win, &map); + if(pcmcia_map_mem_page(link->win, &map)) goto next_entry; } /* If we got this far, we're cool! */ break; next_entry: if (link->io.NumPorts1) - CardServices(ReleaseIO, link->handle, &link->io); - CS_CHECK(GetNextTuple, handle, &tuple); + pcmcia_release_io(link->handle, &link->io); + if((last_ret = pcmcia_get_next_tuple(link->handle, &tuple)) != 0) + { + cs_error(handle, GetNextTuple, last_ret); + goto cs_failed; + } } /* @@ -600,14 +610,22 @@ static void dio24_config(dev_link_t *link) irq structure is initialized. */ if (link->conf.Attributes & CONF_ENABLE_IRQ) - CS_CHECK(RequestIRQ, link->handle, &link->irq); + if((last_ret = pcmcia_request_irq(link->handle, &link->irq)) != 0) + { + cs_error(handle, RequestIRQ, last_ret); + 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); + if((last_ret = pcmcia_request_configuration(link->handle, &link->conf)) != 0) + { + cs_error(handle, RequestConfiguration, last_ret); + goto cs_failed; + } /* At this point, the dev_node_t structure(s) need to be @@ -640,7 +658,6 @@ static void dio24_config(dev_link_t *link) return; cs_failed: - my_cs_error(link->handle, last_fn, last_ret); printk(KERN_INFO "Fallo"); dio24_release((u_long)link); @@ -682,12 +699,12 @@ static void dio24_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) @@ -719,13 +736,17 @@ static int dio24_event(event_t event, int priority, case CS_EVENT_CARD_REMOVAL: link->state &= ~DEV_PRESENT; if (link->state & DEV_CONFIG) { - ((local_info_t *)link->priv)->stop = 1; - mod_timer(&link->release, jiffies + HZ/20); + ((local_info_t *)link->priv)->stop = 1; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) + mod_timer(&link->release, jiffies + HZ/20); +#else + dio24_release((u_long)pcmcia_dev_list); +#endif } break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - dev->bus = args->bus; +// dev->bus = args->bus; dio24_config(link); break; case CS_EVENT_PM_SUSPEND: @@ -735,14 +756,14 @@ static int dio24_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 @@ -755,30 +776,42 @@ static int dio24_event(event_t event, int priority, /*====================================================================*/ +struct pcmcia_driver dio24_cs_driver = +{ + .attach = dio24_cs_attach, + .detach = dio24_cs_detach, + .owner = THIS_MODULE, + .drv = { + .name = "ni_daq_dio24", + }, +}; + static int __init init_dio24_cs(void) { servinfo_t serv; printk("ni_daq_dio24: HOLA SOY YO!\n"); DEBUG(0, "%s\n", version); - CardServices(GetCardServicesInfo, &serv); + pcmcia_get_card_services_info(&serv); if (serv.Revision != CS_RELEASE_CODE) { - printk(KERN_NOTICE "ni_daq_dio24: Card Services release " - "does not match! Vaya putada\n"); - return -1; + printk(KERN_NOTICE "ni_daq_dio24: Card Services release " + "does not match! Vaya putada\n"); + return -1; } - register_pccard_driver(&dev_info, &dio24_cs_attach, &dio24_cs_detach); + pcmcia_register_driver(&dio24_cs_driver); return 0; } static void __exit exit_dio24_cs(void) { DEBUG(0, "ni_dio24: unloading\n"); - unregister_pccard_driver(&dev_info); + pcmcia_unregister_driver(&dio24_cs_driver); while (pcmcia_dev_list != NULL) { - del_timer(&pcmcia_dev_list->release); - if (pcmcia_dev_list->state & DEV_CONFIG) - dio24_release((u_long)pcmcia_dev_list); - dio24_cs_detach(pcmcia_dev_list); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) + del_timer(&pcmcia_dev_list->release); +#endif + if (pcmcia_dev_list->state & DEV_CONFIG) + dio24_release((u_long)pcmcia_dev_list); + dio24_cs_detach(pcmcia_dev_list); } } -- 2.26.2