From: Frank Mori Hess Date: Sun, 11 Jun 2006 18:52:52 +0000 (+0000) Subject: Patch from abbotti@mev.co.uk (Ian Abbott) which ports pcmcia X-Git-Tag: r0_7_71~34 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=64373c4f2537eaa61aeb55d017764864f0d8a24c;p=comedi.git Patch from abbotti@mev.co.uk (Ian Abbott) which ports pcmcia drivers to 2.6.16 api. It also deals with the dropping of the "owner" member from the usb driver struct in 2.6.16. I will shortly drop support for pcmcia on kernels older than 2.6.16. --- diff --git a/comedi/drivers/cb_das16_cs.c b/comedi/drivers/cb_das16_cs.c index ca771579..52cf545a 100644 --- a/comedi/drivers/cb_das16_cs.c +++ b/comedi/drivers/cb_das16_cs.c @@ -650,12 +650,20 @@ MODULE_PARM(irq_list, "1-4i"); used to configure or release a socket, in response to card insertion and ejection events. They are invoked from the das08_pcmcia event handler. + + Kernel version 2.6.16 upwards uses suspend() and resume() functions + instead of an event() function. */ static void das16cs_pcmcia_config(dev_link_t *link); static void das16cs_pcmcia_release(u_long arg); +#ifdef COMEDI_PCMCIA_2_6_16 +static int das16cs_pcmcia_suspend(struct pcmcia_device *p_dev); +static int das16cs_pcmcia_resume(struct pcmcia_device *p_dev); +#else static int das16cs_pcmcia_event(event_t event, int priority, event_callback_args_t *args); +#endif /* The attach() and detach() entry points are used to create and destroy @@ -663,8 +671,13 @@ static int das16cs_pcmcia_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ +#ifdef COMEDI_PCMCIA_2_6_16 +static int das16cs_pcmcia_attach(struct pcmcia_device *); +static void das16cs_pcmcia_detach(struct pcmcia_device *); +#else static dev_link_t *das16cs_pcmcia_attach(void); static void das16cs_pcmcia_detach(dev_link_t *); +#endif /* You'll also need to prototype all the functions that will actually @@ -729,18 +742,29 @@ typedef struct local_info_t { ======================================================================*/ +#ifdef COMEDI_PCMCIA_2_6_16 +static int das16cs_pcmcia_attach(struct pcmcia_device *p_dev) +#else static dev_link_t *das16cs_pcmcia_attach(void) +#endif { local_info_t *local; dev_link_t *link; +#ifndef COMEDI_PCMCIA_2_6_16 client_reg_t client_reg; - int ret, i; + int ret; +#endif + int i; DEBUG(0, "das16cs_pcmcia_attach()\n"); /* Allocate space for private device-specific data */ local = kmalloc(sizeof(local_info_t), GFP_KERNEL); +#ifdef COMEDI_PCMCIA_2_6_16 + if (!local) return -ENOMEM; +#else if (!local) return NULL; +#endif memset(local, 0, sizeof(local_info_t)); link = &local->link; link->priv = local; @@ -770,16 +794,27 @@ static dev_link_t *das16cs_pcmcia_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ link->next = dev_list; dev_list = link; + +#ifdef COMEDI_PCMCIA_2_6_16 + link->handle = p_dev; + p_dev->instance = link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + das16cs_pcmcia_config(link); + + return 0; +#else + /* Register with Card Services */ client_reg.dev_info = &dev_info; client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) client_reg.EventMask = CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET | CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME; client_reg.event_handler = &das16cs_pcmcia_event; +#endif client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; ret = pcmcia_register_client(&link->handle, &client_reg); @@ -790,6 +825,7 @@ static dev_link_t *das16cs_pcmcia_attach(void) } return link; +#endif } /* das16cs_pcmcia_attach */ /*====================================================================== @@ -801,8 +837,15 @@ static dev_link_t *das16cs_pcmcia_attach(void) ======================================================================*/ +#ifdef COMEDI_PCMCIA_2_6_16 +static void das16cs_pcmcia_detach(struct pcmcia_device *p_dev) +#else static void das16cs_pcmcia_detach(dev_link_t *link) +#endif { +#ifdef COMEDI_PCMCIA_2_6_16 + dev_link_t *link = dev_to_instance(p_dev); +#endif dev_link_t **linkp; DEBUG(0, "das16cs_pcmcia_detach(0x%p)\n", link); @@ -811,7 +854,7 @@ static void das16cs_pcmcia_detach(dev_link_t *link) for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; if (*linkp == NULL) - return; + return; /* If the device is currently configured and active, we won't @@ -821,17 +864,24 @@ static void das16cs_pcmcia_detach(dev_link_t *link) */ if (link->state & DEV_CONFIG) { +#ifdef COMEDI_PCMCIA_2_6_16 + ((local_info_t *)link->priv)->stop = 1; + das16cs_pcmcia_release((u_long)link); +#else #ifdef PCMCIA_DEBUG printk(KERN_DEBUG "das16cs: detach postponed, '%s' " "still locked\n", link->dev->dev_name); #endif link->state |= DEV_STALE_LINK; return; +#endif } +#ifndef COMEDI_PCMCIA_2_6_16 /* Break the link with Card Services */ if (link->handle) pcmcia_deregister_client(link->handle); +#endif /* Unlink device structure, and free it */ *linkp = link->next; @@ -1038,6 +1088,7 @@ static void das16cs_pcmcia_release(u_long arg) DEBUG(0, "das16cs_pcmcia_release(0x%p)\n", link); +#ifndef COMEDI_PCMCIA_2_6_16 /* If the device is currently in use, we won't release until it is actually closed, because until then, we can't be sure that @@ -1050,6 +1101,7 @@ static void das16cs_pcmcia_release(u_long arg) link->state |= DEV_STALE_CONFIG; return; } +#endif /* Unlink the device chain */ link->dev = NULL; @@ -1069,8 +1121,10 @@ static void das16cs_pcmcia_release(u_long arg) pcmcia_release_irq(link->handle, &link->irq); link->state &= ~DEV_CONFIG; +#ifndef COMEDI_PCMCIA_2_6_16 if (link->state & DEV_STALE_LINK) das16cs_pcmcia_detach(link); +#endif } /* das16cs_pcmcia_release */ @@ -1086,6 +1140,7 @@ static void das16cs_pcmcia_release(u_long arg) ======================================================================*/ +#ifndef COMEDI_PCMCIA_2_6_16 static int das16cs_pcmcia_event(event_t event, int priority, event_callback_args_t *args) { @@ -1140,15 +1195,57 @@ the device state and restart IO. return 0; } /* das16cs_pcmcia_event */ +#endif + +#ifdef COMEDI_PCMCIA_2_6_16 +static int das16cs_pcmcia_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state |= DEV_SUSPEND; + /* Mark the device as stopped, to block IO until later */ + local->stop = 1; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} /* das16cs_pcmcia_suspend */ + +static int das16cs_pcmcia_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + local->stop = 0; + return 0; +} /* das16cs_pcmcia_resume */ +#endif /*====================================================================*/ struct pcmcia_driver das16cs_driver = { +#ifdef COMEDI_PCMCIA_2_6_16 + .probe = das16cs_pcmcia_attach, + .remove = das16cs_pcmcia_detach, + .suspend = das16cs_pcmcia_suspend, + .resume = das16cs_pcmcia_resume, +#else .attach = das16cs_pcmcia_attach, .detach = das16cs_pcmcia_detach, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) + .event = das16cs_pcmcia_event, +#endif +#endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) + .id_table = NULL, /* FIXME */ +#endif .owner = THIS_MODULE, .drv = { - .name = "cb_das16_cs", + .name = dev_info, }, }; @@ -1170,7 +1267,11 @@ static void __exit exit_das16cs_pcmcia_cs(void) #endif if (dev_list->state & DEV_CONFIG) das16cs_pcmcia_release((u_long)dev_list); +#ifndef COMEDI_PCMCIA_2_6_16 das16cs_pcmcia_detach(dev_list); +#else + das16cs_pcmcia_detach(dev_list->handle); +#endif } } diff --git a/comedi/drivers/das08_cs.c b/comedi/drivers/das08_cs.c index aa73f038..a9f07cd0 100644 --- a/comedi/drivers/das08_cs.c +++ b/comedi/drivers/das08_cs.c @@ -159,12 +159,20 @@ MODULE_PARM(irq_list, "1-4i"); used to configure or release a socket, in response to card insertion and ejection events. They are invoked from the das08_pcmcia event handler. + + Kernel version 2.6.16 upwards uses suspend() and resume() functions + instead of an event() function. */ static void das08_pcmcia_config(dev_link_t *link); static void das08_pcmcia_release(u_long arg); +#ifdef COMEDI_PCMCIA_2_6_16 +static int das08_pcmcia_suspend(struct pcmcia_device *p_dev); +static int das08_pcmcia_resume(struct pcmcia_device *p_dev); +#else static int das08_pcmcia_event(event_t event, int priority, event_callback_args_t *args); +#endif /* The attach() and detach() entry points are used to create and destroy @@ -172,8 +180,13 @@ static int das08_pcmcia_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ +#ifdef COMEDI_PCMCIA_2_6_16 +static int das08_pcmcia_attach(struct pcmcia_device *); +static void das08_pcmcia_detach(struct pcmcia_device *); +#else static dev_link_t *das08_pcmcia_attach(void); static void das08_pcmcia_detach(dev_link_t *); +#endif /* You'll also need to prototype all the functions that will actually @@ -238,18 +251,29 @@ typedef struct local_info_t { ======================================================================*/ +#ifdef COMEDI_PCMCIA_2_6_16 +static int das08_pcmcia_attach(struct pcmcia_device *p_dev) +#else static dev_link_t *das08_pcmcia_attach(void) +#endif { local_info_t *local; dev_link_t *link; +#ifndef COMEDI_PCMCIA_2_6_16 client_reg_t client_reg; - int ret, i; + int ret; +#endif + int i; DEBUG(0, "das08_pcmcia_attach()\n"); /* Allocate space for private device-specific data */ local = kmalloc(sizeof(local_info_t), GFP_KERNEL); +#ifdef COMEDI_PCMCIA_2_6_16 + if (!local) return -ENOMEM; +#else if (!local) return NULL; +#endif memset(local, 0, sizeof(local_info_t)); link = &local->link; link->priv = local; @@ -279,9 +303,18 @@ static dev_link_t *das08_pcmcia_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ link->next = dev_list; dev_list = link; + +#ifdef COMEDI_PCMCIA_2_6_16 + link->handle = p_dev; + p_dev->instance = link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + das08_pcmcia_config(link); + + return 0; +#else + /* Register with Card Services */ client_reg.dev_info = &dev_info; client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) @@ -301,6 +334,7 @@ static dev_link_t *das08_pcmcia_attach(void) } return link; +#endif } /* das08_pcmcia_attach */ /*====================================================================== @@ -312,8 +346,15 @@ static dev_link_t *das08_pcmcia_attach(void) ======================================================================*/ +#ifdef COMEDI_PCMCIA_2_6_16 +static void das08_pcmcia_detach(struct pcmcia_device *p_dev) +#else static void das08_pcmcia_detach(dev_link_t *link) +#endif { +#ifdef COMEDI_PCMCIA_2_6_16 + dev_link_t *link = dev_to_instance(p_dev); +#endif dev_link_t **linkp; DEBUG(0, "das08_pcmcia_detach(0x%p)\n", link); @@ -322,7 +363,7 @@ static void das08_pcmcia_detach(dev_link_t *link) for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; if (*linkp == NULL) - return; + return; /* If the device is currently configured and active, we won't @@ -332,17 +373,24 @@ static void das08_pcmcia_detach(dev_link_t *link) */ if (link->state & DEV_CONFIG) { +#ifdef COMEDI_PCMCIA_2_6_16 + ((local_info_t *)link->priv)->stop = 1; + das08_pcmcia_release((u_long)link); +#else #ifdef PCMCIA_DEBUG printk(KERN_DEBUG "das08: detach postponed, '%s' " "still locked\n", link->dev->dev_name); #endif link->state |= DEV_STALE_LINK; return; +#endif } +#ifndef COMEDI_PCMCIA_2_6_16 /* Break the link with Card Services */ if (link->handle) pcmcia_deregister_client(link->handle); +#endif /* Unlink device structure, and free it */ *linkp = link->next; @@ -550,6 +598,7 @@ static void das08_pcmcia_release(u_long arg) DEBUG(0, "das08_pcmcia_release(0x%p)\n", link); +#ifndef COMEDI_PCMCIA_2_6_16 /* If the device is currently in use, we won't release until it is actually closed, because until then, we can't be sure that @@ -562,6 +611,7 @@ static void das08_pcmcia_release(u_long arg) link->state |= DEV_STALE_CONFIG; return; } +#endif /* Unlink the device chain */ link->dev = NULL; @@ -581,8 +631,10 @@ static void das08_pcmcia_release(u_long arg) pcmcia_release_irq(link->handle, &link->irq); link->state &= ~DEV_CONFIG; +#ifndef COMEDI_PCMCIA_2_6_16 if (link->state & DEV_STALE_LINK) das08_pcmcia_detach(link); +#endif } /* das08_pcmcia_release */ @@ -598,6 +650,7 @@ static void das08_pcmcia_release(u_long arg) ======================================================================*/ +#ifndef COMEDI_PCMCIA_2_6_16 static int das08_pcmcia_event(event_t event, int priority, event_callback_args_t *args) { @@ -652,15 +705,54 @@ the device state and restart IO. return 0; } /* das08_pcmcia_event */ +#endif + +#ifdef COMEDI_PCMCIA_2_6_16 +static int das08_pcmcia_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state |= DEV_SUSPEND; + /* Mark the device as stopped, to block IO until later */ + local->stop = 1; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} /* das08_pcmcia_suspend */ + +static int das08_pcmcia_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + local->stop = 0; + return 0; +} /* das08_pcmcia_resume */ +#endif /*====================================================================*/ struct pcmcia_driver das08_cs_driver = { +#ifdef COMEDI_PCMCIA_2_6_16 + .probe = das08_pcmcia_attach, + .remove = das08_pcmcia_detach, + .suspend = das08_pcmcia_suspend, + .resume = das08_pcmcia_resume, +#else .attach = &das08_pcmcia_attach, .detach = &das08_pcmcia_detach, #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) .event = &das08_pcmcia_event, +#endif +#endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) + .id_table = NULL, /* FIXME */ #endif .owner = THIS_MODULE, .drv = { @@ -686,7 +778,11 @@ static void __exit exit_das08_pcmcia_cs(void) #endif if (dev_list->state & DEV_CONFIG) das08_pcmcia_release((u_long)dev_list); +#ifndef COMEDI_PCMCIA_2_6_16 das08_pcmcia_detach(dev_list); +#else + das08_pcmcia_detach(dev_list->handle); +#endif } } diff --git a/comedi/drivers/dt9812.c b/comedi/drivers/dt9812.c index 6acd7cd0..1f5862cb 100644 --- a/comedi/drivers/dt9812.c +++ b/comedi/drivers/dt9812.c @@ -664,7 +664,9 @@ static void dt9812_disconnect(struct usb_interface *interface) } static struct usb_driver dt9812_usb_driver = { +#ifdef COMEDI_HAVE_USB_DRIVER_OWNER .owner = THIS_MODULE, +#endif .name = "dt9812", .probe = dt9812_probe, .disconnect = dt9812_disconnect, diff --git a/comedi/drivers/ni_daq_dio24.c b/comedi/drivers/ni_daq_dio24.c index 1ef146e6..f19b3f58 100644 --- a/comedi/drivers/ni_daq_dio24.c +++ b/comedi/drivers/ni_daq_dio24.c @@ -240,12 +240,20 @@ MODULE_PARM(irq_list, "1-4i"); used to configure or release a socket, in response to card insertion and ejection events. They are invoked from the dummy event handler. + + Kernel version 2.6.16 upwards uses suspend() and resume() functions + instead of an event() function. */ static void dio24_config(dev_link_t *link); static void dio24_release(u_long arg); +#ifdef COMEDI_PCMCIA_2_6_16 +static int dio24_cs_suspend(struct pcmcia_device *p_dev); +static int dio24_cs_resume(struct pcmcia_device *p_dev); +#else static int dio24_event(event_t event, int priority, event_callback_args_t *args); +#endif /* The attach() and detach() entry points are used to create and destroy @@ -253,8 +261,13 @@ static int dio24_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ +#ifdef COMEDI_PCMCIA_2_6_16 +static int dio24_cs_attach(struct pcmcia_device *); +static void dio24_cs_detach(struct pcmcia_device *); +#else static dev_link_t *dio24_cs_attach(void); static void dio24_cs_detach(dev_link_t *); +#endif /* You'll also need to prototype all the functions that will actually @@ -319,12 +332,19 @@ typedef struct local_info_t { ======================================================================*/ +#ifdef COMEDI_PCMCIA_2_6_16 +static int dio24_cs_attach(struct pcmcia_device *p_dev) +#else static dev_link_t *dio24_cs_attach(void) +#endif { local_info_t *local; dev_link_t *link; +#ifndef COMEDI_PCMCIA_2_6_16 client_reg_t client_reg; - int ret, i; + int ret; +#endif + int i; printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO - CS-attach!\n"); @@ -332,7 +352,11 @@ static dev_link_t *dio24_cs_attach(void) /* Allocate space for private device-specific data */ local = kmalloc(sizeof(local_info_t), GFP_KERNEL); +#ifdef COMEDI_PCMCIA_2_6_16 + if (!local) return -ENOMEM; +#else if (!local) return NULL; +#endif memset(local, 0, sizeof(local_info_t)); link = &local->link; link->priv = local; @@ -362,9 +386,18 @@ static dev_link_t *dio24_cs_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ link->next = pcmcia_dev_list; pcmcia_dev_list = link; + +#ifdef COMEDI_PCMCIA_2_6_16 + link->handle = p_dev; + p_dev->instance = link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + dio24_config(link); + + return 0; +#else + /* Register with Card Services */ client_reg.dev_info = &dev_info; client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) @@ -384,6 +417,7 @@ static dev_link_t *dio24_cs_attach(void) } return link; +#endif } /* dio24_cs_attach */ /*====================================================================== @@ -395,8 +429,15 @@ static dev_link_t *dio24_cs_attach(void) ======================================================================*/ +#ifdef COMEDI_PCMCIA_2_6_16 +static void dio24_cs_detach(struct pcmcia_device *p_dev) +#else static void dio24_cs_detach(dev_link_t *link) +#endif { +#ifdef COMEDI_PCMCIA_2_6_16 + dev_link_t *link = dev_to_instance(p_dev); +#endif dev_link_t **linkp; printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO - cs-detach!\n"); @@ -416,17 +457,24 @@ static void dio24_cs_detach(dev_link_t *link) detach(). */ if (link->state & DEV_CONFIG) { +#ifdef COMEDI_PCMCIA_2_6_16 + ((local_info_t *)link->priv)->stop = 1; + dio24_release((u_long)link); +#else #ifdef PCMCIA_DEBUG printk(KERN_DEBUG "ni_daq_dio24: detach postponed, '%s' " "still locked\n", link->dev->dev_name); #endif link->state |= DEV_STALE_LINK; return; +#endif } +#ifndef COMEDI_PCMCIA_2_6_16 /* Break the link with Card Services */ if (link->handle) pcmcia_deregister_client(link->handle); +#endif /* Unlink device structure, and free it */ *linkp = link->next; @@ -685,6 +733,7 @@ static void dio24_release(u_long arg) DEBUG(0, "dio24_release(0x%p)\n", link); +#ifndef COMEDI_PCMCIA_2_6_16 /* If the device is currently in use, we won't release until it is actually closed, because until then, we can't be sure that @@ -696,6 +745,7 @@ static void dio24_release(u_long arg) link->state |= DEV_STALE_CONFIG; return; } +#endif /* Unlink the device chain */ link->dev = NULL; @@ -715,8 +765,10 @@ static void dio24_release(u_long arg) pcmcia_release_irq(link->handle, &link->irq); link->state &= ~DEV_CONFIG; +#ifndef COMEDI_PCMCIA_2_6_16 if (link->state & DEV_STALE_LINK) dio24_cs_detach(link); +#endif } /* dio24_release */ @@ -732,6 +784,7 @@ static void dio24_release(u_long arg) ======================================================================*/ +#ifndef COMEDI_PCMCIA_2_6_16 static int dio24_event(event_t event, int priority, event_callback_args_t *args) { @@ -781,19 +834,69 @@ static int dio24_event(event_t event, int priority, } return 0; } /* dio24_event */ +#endif + +#ifdef COMEDI_PCMCIA_2_6_16 +static int dio24_cs_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state |= DEV_SUSPEND; + /* Mark the device as stopped, to block IO until later */ + local->stop = 1; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} /* dio24_cs_suspend */ + +static int dio24_cs_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + local->stop = 0; + return 0; +} /* dio24_cs_resume */ +#endif /*====================================================================*/ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) +static struct pcmcia_device_id dio24_cs_ids[] = +{ + /* N.B. These IDs should match those in dio24_boards */ + PCMCIA_DEVICE_MANF_CARD(0x010b, 0x475c), /* daqcard-dio24 */ + PCMCIA_DEVICE_NULL +}; + +MODULE_DEVICE_TABLE(pcmcia, dio24_cs_ids); +#endif + struct pcmcia_driver dio24_cs_driver = { +#ifdef COMEDI_PCMCIA_2_6_16 + .probe = dio24_cs_attach, + .remove = dio24_cs_detach, + .suspend = dio24_cs_suspend, + .resume = dio24_cs_resume, +#else .attach = &dio24_cs_attach, .detach = &dio24_cs_detach, #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) .event = &dio24_event, +#endif +#endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) + .id_table = dio24_cs_ids, #endif .owner = THIS_MODULE, .drv = { - .name = "ni_daq_dio24", + .name = dev_info, }, }; @@ -815,7 +918,11 @@ static void __exit exit_dio24_cs(void) #endif if (pcmcia_dev_list->state & DEV_CONFIG) dio24_release((u_long)pcmcia_dev_list); +#ifndef COMEDI_PCMCIA_2_6_16 dio24_cs_detach(pcmcia_dev_list); +#else + dio24_cs_detach(pcmcia_dev_list->handle); +#endif } } diff --git a/comedi/drivers/ni_labpc_cs.c b/comedi/drivers/ni_labpc_cs.c index 9f39b3fd..a2223cf5 100644 --- a/comedi/drivers/ni_labpc_cs.c +++ b/comedi/drivers/ni_labpc_cs.c @@ -174,12 +174,20 @@ MODULE_PARM(irq_list, "1-4i"); used to configure or release a socket, in response to card insertion and ejection events. They are invoked from the dummy event handler. + + Kernel version 2.6.16 upwards uses suspend() and resume() functions + instead of an event() function. */ static void labpc_config(dev_link_t *link); static void labpc_release(u_long arg); +#ifdef COMEDI_PCMCIA_2_6_16 +static int labpc_cs_suspend(struct pcmcia_device *p_dev); +static int labpc_cs_resume(struct pcmcia_device *p_dev); +#else static int labpc_event(event_t event, int priority, event_callback_args_t *args); +#endif /* The attach() and detach() entry points are used to create and destroy @@ -187,8 +195,13 @@ static int labpc_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ +#ifdef COMEDI_PCMCIA_2_6_16 +static int labpc_cs_attach(struct pcmcia_device *); +static void labpc_cs_detach(struct pcmcia_device *); +#else static dev_link_t *labpc_cs_attach(void); static void labpc_cs_detach(dev_link_t *); +#endif /* You'll also need to prototype all the functions that will actually @@ -254,18 +267,29 @@ typedef struct local_info_t { ======================================================================*/ +#ifdef COMEDI_PCMCIA_2_6_16 +static int labpc_cs_attach(struct pcmcia_device *p_dev) +#else static dev_link_t *labpc_cs_attach(void) +#endif { local_info_t *local; dev_link_t *link; +#ifndef COMEDI_PCMCIA_2_6_16 client_reg_t client_reg; - int ret, i; + int ret; +#endif + int i; DEBUG(0, "labpc_cs_attach()\n"); /* Allocate space for private device-specific data */ local = kmalloc(sizeof(local_info_t), GFP_KERNEL); +#ifdef COMEDI_PCMCIA_2_6_16 + if (!local) return -ENOMEM; +#else if (!local) return NULL; +#endif memset(local, 0, sizeof(local_info_t)); link = &local->link; link->priv = local; @@ -294,9 +318,18 @@ static dev_link_t *labpc_cs_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ link->next = pcmcia_dev_list; pcmcia_dev_list = link; + +#ifdef COMEDI_PCMCIA_2_6_16 + link->handle = p_dev; + p_dev->instance = link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + labpc_config(link); + + return 0; +#else + /* Register with Card Services */ client_reg.dev_info = &dev_info; client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) @@ -316,6 +349,7 @@ static dev_link_t *labpc_cs_attach(void) } return link; +#endif } /* labpc_cs_attach */ /*====================================================================== @@ -327,8 +361,15 @@ static dev_link_t *labpc_cs_attach(void) ======================================================================*/ +#ifdef COMEDI_PCMCIA_2_6_16 +static void labpc_cs_detach(struct pcmcia_device *p_dev) +#else static void labpc_cs_detach(dev_link_t *link) +#endif { +#ifdef COMEDI_PCMCIA_2_6_16 + dev_link_t *link = dev_to_instance(p_dev); +#endif dev_link_t **linkp; DEBUG(0, "labpc_cs_detach(0x%p)\n", link); @@ -346,17 +387,24 @@ static void labpc_cs_detach(dev_link_t *link) detach(). */ if (link->state & DEV_CONFIG) { +#ifdef COMEDI_PCMCIA_2_6_16 + ((local_info_t *)link->priv)->stop = 1; + labpc_release((u_long)link); +#else #ifdef PCMCIA_DEBUG printk(KERN_DEBUG "ni_labpc: detach postponed, '%s' " "still locked\n", link->dev->dev_name); #endif link->state |= DEV_STALE_LINK; return; +#endif } +#ifndef COMEDI_PCMCIA_2_6_16 /* Break the link with Card Services */ if (link->handle) pcmcia_deregister_client(link->handle); +#endif /* Unlink device structure, and free it */ *linkp = link->next; @@ -609,6 +657,7 @@ static void labpc_release(u_long arg) DEBUG(0, "labpc_release(0x%p)\n", link); +#ifndef COMEDI_PCMCIA_2_6_16 /* If the device is currently in use, we won't release until it is actually closed, because until then, we can't be sure that @@ -620,6 +669,7 @@ static void labpc_release(u_long arg) link->state |= DEV_STALE_CONFIG; return; } +#endif /* Unlink the device chain */ link->dev = NULL; @@ -639,8 +689,10 @@ static void labpc_release(u_long arg) pcmcia_release_irq(link->handle, &link->irq); link->state &= ~DEV_CONFIG; +#ifndef COMEDI_PCMCIA_2_6_16 if (link->state & DEV_STALE_LINK) labpc_cs_detach(link); +#endif } /* labpc_release */ @@ -656,6 +708,7 @@ static void labpc_release(u_long arg) ======================================================================*/ +#ifndef COMEDI_PCMCIA_2_6_16 static int labpc_event(event_t event, int priority, event_callback_args_t *args) { @@ -705,6 +758,35 @@ static int labpc_event(event_t event, int priority, } return 0; } /* labpc_event */ +#endif + +#ifdef COMEDI_PCMCIA_2_6_16 +static int labpc_cs_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state |= DEV_SUSPEND; + /* Mark the device as stopped, to block IO until later */ + local->stop = 1; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} /* labpc_cs_suspend */ + +static int labpc_cs_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + local->stop = 0; + return 0; +} /* labpc_cs_resume */ +#endif /*====================================================================*/ @@ -721,15 +803,24 @@ MODULE_DEVICE_TABLE(pcmcia, labpc_cs_ids); struct pcmcia_driver labpc_cs_driver = { +#ifdef COMEDI_PCMCIA_2_6_16 + .probe = labpc_cs_attach, + .remove = labpc_cs_detach, + .suspend = labpc_cs_suspend, + .resume = labpc_cs_resume, +#else .attach = labpc_cs_attach, .detach = labpc_cs_detach, #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) .event = &labpc_event, +#endif +#endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) .id_table = labpc_cs_ids, #endif .owner = THIS_MODULE, .drv = { - .name = "daqcard-1200", + .name = dev_info, }, }; @@ -750,7 +841,11 @@ static void __exit exit_labpc_cs(void) #endif if (pcmcia_dev_list->state & DEV_CONFIG) labpc_release((u_long)pcmcia_dev_list); +#ifndef COMEDI_PCMCIA_2_6_16 labpc_cs_detach(pcmcia_dev_list); +#else + labpc_cs_detach(pcmcia_dev_list->handle); +#endif } } diff --git a/comedi/drivers/ni_mio_cs.c b/comedi/drivers/ni_mio_cs.c index 8a010040..9d35ac5d 100644 --- a/comedi/drivers/ni_mio_cs.c +++ b/comedi/drivers/ni_mio_cs.c @@ -251,7 +251,11 @@ static int mio_cs_detach(comedi_device *dev) static void mio_cs_config(dev_link_t *link); static void cs_release(u_long arg); +#ifdef COMEDI_PCMCIA_2_6_16 +static void cs_detach(struct pcmcia_device *); +#else static void cs_detach(dev_link_t *); +#endif static int irq_mask; static dev_link_t *dev_list = NULL; @@ -261,16 +265,28 @@ static dev_node_t dev_node = { COMEDI_MAJOR,0, NULL }; +#ifndef COMEDI_PCMCIA_2_6_16 static int mio_cs_event(event_t event, int priority, event_callback_args_t *args); +#endif +#ifdef COMEDI_PCMCIA_2_6_16 +static int cs_attach(struct pcmcia_device *p_dev) +#else static dev_link_t *cs_attach(void) +#endif { dev_link_t *link; +#ifndef COMEDI_PCMCIA_2_6_16 client_reg_t client_reg; int ret; +#endif link=kmalloc(sizeof(*link),GFP_KERNEL); +#ifdef COMEDI_PCMCIA_2_6_16 + if(!link)return -ENOMEM; +#else if(!link)return NULL; +#endif memset(link,0,sizeof(*link)); #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) @@ -289,6 +305,14 @@ static dev_link_t *cs_attach(void) link->next = dev_list; dev_list = link; +#ifdef COMEDI_PCMCIA_2_6_16 + link->handle = p_dev; + p_dev->instance = link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + mio_cs_config(link); + + return 0; +#else client_reg.dev_info = &dev_info; client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) @@ -309,6 +333,7 @@ static dev_link_t *cs_attach(void) } return link; +#endif } static void cs_release(u_long arg) @@ -322,8 +347,15 @@ static void cs_release(u_long arg) link->state &= ~DEV_CONFIG; } +#ifdef COMEDI_PCMCIA_2_6_16 +static void cs_detach(struct pcmcia_device *p_dev) +#else static void cs_detach(dev_link_t *link) +#endif { +#ifdef COMEDI_PCMCIA_2_6_16 + dev_link_t *link = dev_to_instance(p_dev); +#endif dev_link_t **linkp; DPRINTK("cs_detach(link=%p)\n",link); @@ -346,18 +378,26 @@ static void cs_detach(dev_link_t *link) if(link->state & DEV_CONFIG) { cs_release((u_long)link); +#ifndef COMEDI_PCMCIA_2_6_16 if(link->state & DEV_STALE_CONFIG) { link->state |= DEV_STALE_LINK; return; } +#endif } +#ifndef COMEDI_PCMCIA_2_6_16 if(link->handle){ pcmcia_deregister_client(link->handle); } +#endif + /* Unlink device structure, and free it */ + *linkp = link->next; + kfree(link); } +#ifndef COMEDI_PCMCIA_2_6_16 static int mio_cs_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; @@ -407,6 +447,34 @@ static int mio_cs_event(event_t event, int priority, event_callback_args_t *args } return 0; } +#endif + + +#ifdef COMEDI_PCMCIA_2_6_16 +static int mio_cs_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + + DPRINTK("pm suspend\n"); + link->state |= DEV_SUSPEND; + if(link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int mio_cs_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + + DPRINTK("pm resume\n"); + link->state &= ~DEV_SUSPEND; + if(DEV_OK(link)) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} +#endif @@ -627,15 +695,24 @@ MODULE_DEVICE_TABLE(pcmcia, ni_mio_cs_ids); struct pcmcia_driver ni_mio_cs_driver = { +#ifdef COMEDI_PCMCIA_2_6_16 + .probe = &cs_attach, + .remove = &cs_detach, + .suspend = &mio_cs_suspend, + .resume = &mio_cs_resume, +#else .attach = &cs_attach, .detach = &cs_detach, #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) .event = &mio_cs_event, +#endif +#endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) .id_table = ni_mio_cs_ids, #endif .owner = THIS_MODULE, .drv = { - .name = "ni_mio_cs", + .name = dev_info, }, }; @@ -651,7 +728,11 @@ void cleanup_module(void) pcmcia_unregister_driver(&ni_mio_cs_driver); #if 0 while(dev_list != NULL) +#ifndef COMEDI_PCMCIA_2_6_16 cs_detach(dev_list); +#else + cs_detach(dev_list->handle); +#endif #endif comedi_driver_unregister(&driver_ni_mio_cs); } diff --git a/comedi/drivers/quatech_daqp_cs.c b/comedi/drivers/quatech_daqp_cs.c index 9e75bf9e..611ee21a 100644 --- a/comedi/drivers/quatech_daqp_cs.c +++ b/comedi/drivers/quatech_daqp_cs.c @@ -1054,12 +1054,20 @@ static int daqp_detach(comedi_device *dev) event is received. The config() and release() entry points are used to configure or release a socket, in response to card insertion and ejection events. + + Kernel version 2.6.16 upwards uses suspend() and resume() functions + instead of an event() function. */ static void daqp_cs_config(dev_link_t *link); static void daqp_cs_release(u_long arg); +#ifdef COMEDI_PCMCIA_2_6_16 +static int daqp_cs_suspend(struct pcmcia_device *p_dev); +static int daqp_cs_resume(struct pcmcia_device *p_dev); +#else static int daqp_cs_event(event_t event, int priority, event_callback_args_t *args); +#endif /* The attach() and detach() entry points are used to create and destroy @@ -1067,8 +1075,13 @@ static int daqp_cs_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ +#ifdef COMEDI_PCMCIA_2_6_16 +static int daqp_cs_attach(struct pcmcia_device *); +static void daqp_cs_detach(struct pcmcia_device *); +#else static dev_link_t *daqp_cs_attach(void); static void daqp_cs_detach(dev_link_t *); +#endif /* The dev_info variable is the "key" that is used to match up this @@ -1091,12 +1104,19 @@ static dev_info_t dev_info = "quatech_daqp_cs"; ======================================================================*/ +#ifdef COMEDI_PCMCIA_2_6_16 +static int daqp_cs_attach(struct pcmcia_device *p_dev) +#else static dev_link_t *daqp_cs_attach(void) +#endif { local_info_t *local; dev_link_t *link; +#ifndef COMEDI_PCMCIA_2_6_16 client_reg_t client_reg; - int ret, i; + int ret; +#endif + int i; DEBUG(0, "daqp_cs_attach()\n"); @@ -1104,12 +1124,20 @@ static dev_link_t *daqp_cs_attach(void) if (dev_table[i] == NULL) break; if (i == MAX_DEV) { printk(KERN_NOTICE "daqp_cs: no devices available\n"); +#ifdef COMEDI_PCMCIA_2_6_16 + return -ENODEV; +#else return NULL; +#endif } /* Allocate space for private device-specific data */ local = kmalloc(sizeof(local_info_t), GFP_KERNEL); +#ifdef COMEDI_PCMCIA_2_6_16 + if (!local) return -ENOMEM; +#else if (!local) return NULL; +#endif memset(local, 0, sizeof(local_info_t)); local->table_index = i; @@ -1144,6 +1172,14 @@ static dev_link_t *daqp_cs_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; +#ifdef COMEDI_PCMCIA_2_6_16 + link->handle = p_dev; + p_dev->instance = link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + daqp_cs_config(link); + + return 0; +#else /* Register with Card Services */ client_reg.dev_info = &dev_info; client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; @@ -1164,6 +1200,7 @@ static dev_link_t *daqp_cs_attach(void) } return link; +#endif } /* daqp_cs_attach */ /*====================================================================== @@ -1175,8 +1212,15 @@ static dev_link_t *daqp_cs_attach(void) ======================================================================*/ +#ifdef COMEDI_PCMCIA_2_6_16 +static void daqp_cs_detach(struct pcmcia_device *p_dev) +#else static void daqp_cs_detach(dev_link_t *link) +#endif { +#ifdef COMEDI_PCMCIA_2_6_16 + dev_link_t *link = dev_to_instance(p_dev); +#endif local_info_t *dev = link->priv; DEBUG(0, "daqp_cs_detach(0x%p)\n", link); @@ -1188,17 +1232,24 @@ static void daqp_cs_detach(dev_link_t *link) detach(). */ if (link->state & DEV_CONFIG) { +#ifdef COMEDI_PCMCIA_2_6_16 + dev->stop = 1; + daqp_cs_release((u_long)link); +#else #ifdef PCMCIA_DEBUG printk(KERN_DEBUG "daqp_cs: detach postponed, '%s' " "still locked\n", link->dev->dev_name); #endif link->state |= DEV_STALE_LINK; return; +#endif } +#ifndef COMEDI_PCMCIA_2_6_16 /* Break the link with Card Services */ if (link->handle) pcmcia_deregister_client(link->handle); +#endif /* Unlink device structure, and free it */ dev_table[dev->table_index] = NULL; @@ -1419,6 +1470,7 @@ static void daqp_cs_release(u_long arg) DEBUG(0, "daqp_cs_release(0x%p)\n", link); +#ifndef COMEDI_PCMCIA_2_6_16 /* If the device is currently in use, we won't release until it is actually closed, because until then, we can't be sure that @@ -1430,6 +1482,7 @@ static void daqp_cs_release(u_long arg) link->state |= DEV_STALE_CONFIG; return; } +#endif /* Unlink the device chain */ link->dev = NULL; @@ -1448,8 +1501,10 @@ static void daqp_cs_release(u_long arg) pcmcia_release_irq(link->handle, &link->irq); link->state &= ~DEV_CONFIG; +#ifndef COMEDI_PCMCIA_2_6_16 if (link->state & DEV_STALE_LINK) daqp_cs_detach(link); +#endif } /* daqp_cs_release */ @@ -1465,6 +1520,7 @@ static void daqp_cs_release(u_long arg) ======================================================================*/ +#ifndef COMEDI_PCMCIA_2_6_16 static int daqp_cs_event(event_t event, int priority, event_callback_args_t *args) { @@ -1510,6 +1566,36 @@ static int daqp_cs_event(event_t event, int priority, } return 0; } /* daqp_cs_event */ +#endif + +#ifdef COMEDI_PCMCIA_2_6_16 +static int daqp_cs_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state |= DEV_SUSPEND; + /* Mark the device as stopped, to block IO until later */ + local->stop = 1; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int daqp_cs_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + local->stop = 0; + + return 0; +} +#endif /*====================================================================*/ @@ -1517,14 +1603,24 @@ static int daqp_cs_event(event_t event, int priority, struct pcmcia_driver daqp_cs_driver = { +#ifdef COMEDI_PCMCIA_2_6_16 + .probe = daqp_cs_attach, + .remove = daqp_cs_detach, + .suspend = daqp_cs_suspend, + .resume = daqp_cs_resume, +#else .attach = daqp_cs_attach, .detach = daqp_cs_detach, #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) .event = daqp_cs_event, +#endif +#endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) + .id_table = NULL, /* FIXME */ #endif .owner = THIS_MODULE, .drv = { - .name = "quatech_daqp_cs", + .name = dev_info, }, }; @@ -1552,8 +1648,13 @@ void cleanup_module(void) * a detach, which freed the memory, so make sure we don't * do it again or oops()... that's why this test is here */ - if (dev_table[i]) + if (dev_table[i]) { +#ifndef COMEDI_PCMCIA_2_6_16 daqp_cs_detach(&dev_table[i]->link); +#else + daqp_cs_detach(dev_table[i]->link.handle); +#endif + } } } } diff --git a/comedi/drivers/usbdux.c b/comedi/drivers/usbdux.c index 1d110324..38c39314 100644 --- a/comedi/drivers/usbdux.c +++ b/comedi/drivers/usbdux.c @@ -2763,7 +2763,7 @@ MODULE_DEVICE_TABLE (usb, usbduxsub_table); // The usbduxsub-driver static struct usb_driver usbduxsub_driver = { -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,19) +#ifdef COMEDI_HAVE_USB_DRIVER_OWNER owner: THIS_MODULE, #endif name: BOARDNAME, diff --git a/comedi/drivers/usbduxfast.c b/comedi/drivers/usbduxfast.c index dc88bcb8..2513a8ed 100644 --- a/comedi/drivers/usbduxfast.c +++ b/comedi/drivers/usbduxfast.c @@ -1857,7 +1857,7 @@ MODULE_DEVICE_TABLE (usb, usbduxfastsub_table); // The usbduxfastsub-driver static struct usb_driver usbduxfastsub_driver = { -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,19) +#ifdef COMEDI_HAVE_USB_DRIVER_OWNER owner: THIS_MODULE, #endif name: BOARDNAME, diff --git a/include/linux/usb.h b/include/linux/usb.h index 0bfced20..0ad40700 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -64,5 +64,14 @@ static inline int USB_BULK_MSG(struct usb_device *usb_dev, unsigned int pipe, #define USB_BULK_MSG usb_bulk_msg #endif +/* + * Determine whether we need the "owner" member of struct usb_driver and + * define COMEDI_HAVE_USB_DRIVER_OWNER if we need it. + */ +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,19) \ + && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) +#define COMEDI_HAVE_USB_DRIVER_OWNER +#endif + #endif