From 98e4c28b7ec390c2dad6a4c69d69629c0f7e8b10 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Mon, 14 Nov 2005 21:21:18 +0100 Subject: [PATCH] pcmcia: new suspend core Move the suspend and resume methods out of the event handler, and into special functions. Also use these functions for pre- and post-reset, as almost all drivers already do, and the remaining ones can easily be converted. Bugfix to include/pcmcia/ds.c Signed-off-by: Andrew Morton Signed-off-by: Dominik Brodowski --- drivers/parport/parport_cs.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'drivers/parport/parport_cs.c') diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c index 24e6aac..4c89853 100644 --- a/drivers/parport/parport_cs.c +++ b/drivers/parport/parport_cs.c @@ -325,6 +325,28 @@ void parport_cs_release(dev_link_t *link) } /* parport_cs_release */ +static int parport_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 parport_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (DEV_OK(link)) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -349,20 +371,6 @@ int parport_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; parport_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (DEV_OK(link)) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; } /* parport_event */ @@ -383,7 +391,8 @@ static struct pcmcia_driver parport_cs_driver = { .event = parport_event, .detach = parport_detach, .id_table = parport_ids, - + .suspend = parport_suspend, + .resume = parport_resume, }; static int __init init_parport_cs(void) -- cgit v1.1 From cc3b4866bee996c922e875b8c8efe9f0d8803aae Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Mon, 14 Nov 2005 21:23:14 +0100 Subject: [PATCH] pcmcia: unify detach, REMOVAL_EVENT handlers into one remove callback Unify the "detach" and REMOVAL_EVENT handlers to one "remove" function. Old functionality is preserved, for the moment. Signed-off-by: Dominik Brodowski --- drivers/parport/parport_cs.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'drivers/parport/parport_cs.c') diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c index 4c89853..063d22d 100644 --- a/drivers/parport/parport_cs.c +++ b/drivers/parport/parport_cs.c @@ -88,7 +88,7 @@ typedef struct parport_info_t { } parport_info_t; static dev_link_t *parport_attach(void); -static void parport_detach(dev_link_t *); +static void parport_detach(struct pcmcia_device *p_dev); static void parport_config(dev_link_t *link); static void parport_cs_release(dev_link_t *); static int parport_event(event_t event, int priority, @@ -137,7 +137,7 @@ static dev_link_t *parport_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - parport_detach(link); + parport_detach(link->handle); return NULL; } @@ -153,13 +153,13 @@ static dev_link_t *parport_attach(void) ======================================================================*/ -static void parport_detach(dev_link_t *link) +static void parport_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; - int ret; DEBUG(0, "parport_detach(0x%p)\n", link); - + /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; @@ -168,17 +168,10 @@ static void parport_detach(dev_link_t *link) if (link->state & DEV_CONFIG) parport_cs_release(link); - - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); - } - + /* Unlink, free device structure */ *linkp = link->next; kfree(link->priv); - } /* parport_detach */ /*====================================================================== @@ -362,11 +355,6 @@ int parport_event(event_t event, int priority, DEBUG(1, "parport_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - parport_cs_release(link); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; parport_config(link); @@ -389,7 +377,7 @@ static struct pcmcia_driver parport_cs_driver = { }, .attach = parport_attach, .event = parport_event, - .detach = parport_detach, + .remove = parport_detach, .id_table = parport_ids, .suspend = parport_suspend, .resume = parport_resume, -- cgit v1.1 From b463581154f3f3eecda27cae60df813fefcd84d3 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Mon, 14 Nov 2005 21:25:35 +0100 Subject: [PATCH] pcmcia: remove dev_list from drivers The linked list of devices managed by each PCMCIA driver is, in very most cases, unused. Therefore, remove it from many drivers. Signed-off-by: Dominik Brodowski --- drivers/parport/parport_cs.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'drivers/parport/parport_cs.c') diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c index 063d22d..763f91a 100644 --- a/drivers/parport/parport_cs.c +++ b/drivers/parport/parport_cs.c @@ -95,7 +95,6 @@ static int parport_event(event_t event, int priority, event_callback_args_t *args); static dev_info_t dev_info = "parport_cs"; -static dev_link_t *dev_list = NULL; /*====================================================================== @@ -129,8 +128,7 @@ static dev_link_t *parport_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -156,21 +154,12 @@ static dev_link_t *parport_attach(void) static void parport_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; DEBUG(0, "parport_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->state & DEV_CONFIG) parport_cs_release(link); - /* Unlink, free device structure */ - *linkp = link->next; kfree(link->priv); } /* parport_detach */ @@ -391,7 +380,6 @@ static int __init init_parport_cs(void) static void __exit exit_parport_cs(void) { pcmcia_unregister_driver(&parport_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_parport_cs); -- cgit v1.1 From f8cfa618dccbdc6dab5297f75779566a388a98fd Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Mon, 14 Nov 2005 21:25:51 +0100 Subject: [PATCH] pcmcia: unify attach, EVENT_CARD_INSERTION handlers into one probe callback Unify the EVENT_CARD_INSERTION and "attach" callbacks to one unified probe() callback. As all in-kernel drivers are changed to this new callback, there will be no temporary backwards-compatibility. Inside a probe() function, each driver _must_ set struct pcmcia_device *p_dev->instance and instance->handle correctly. With these patches, the basic driver interface for 16-bit PCMCIA drivers now has the classic four callbacks known also from other buses: int (*probe) (struct pcmcia_device *dev); void (*remove) (struct pcmcia_device *dev); int (*suspend) (struct pcmcia_device *dev); int (*resume) (struct pcmcia_device *dev); Signed-off-by: Dominik Brodowski --- drivers/parport/parport_cs.c | 61 +++++++++----------------------------------- 1 file changed, 12 insertions(+), 49 deletions(-) (limited to 'drivers/parport/parport_cs.c') diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c index 763f91a..158d925 100644 --- a/drivers/parport/parport_cs.c +++ b/drivers/parport/parport_cs.c @@ -87,14 +87,9 @@ typedef struct parport_info_t { struct parport *port; } parport_info_t; -static dev_link_t *parport_attach(void); static void parport_detach(struct pcmcia_device *p_dev); static void parport_config(dev_link_t *link); static void parport_cs_release(dev_link_t *); -static int parport_event(event_t event, int priority, - event_callback_args_t *args); - -static dev_info_t dev_info = "parport_cs"; /*====================================================================== @@ -104,18 +99,16 @@ static dev_info_t dev_info = "parport_cs"; ======================================================================*/ -static dev_link_t *parport_attach(void) +static int parport_attach(struct pcmcia_device *p_dev) { parport_info_t *info; dev_link_t *link; - client_reg_t client_reg; - int ret; - + DEBUG(0, "parport_attach()\n"); /* Create new parport device */ info = kmalloc(sizeof(*info), GFP_KERNEL); - if (!info) return NULL; + if (!info) return -ENOMEM; memset(info, 0, sizeof(*info)); link = &info->link; link->priv = info; @@ -126,20 +119,14 @@ static dev_link_t *parport_attach(void) link->conf.Attributes = CONF_ENABLE_IRQ; link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - parport_detach(link->handle); - return NULL; - } - - return link; + + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + parport_config(link); + + return 0; } /* parport_attach */ /*====================================================================== @@ -329,29 +316,6 @@ static int parport_resume(struct pcmcia_device *dev) return 0; } -/*====================================================================== - - The card status event handler. Mostly, this schedules other - stuff to run after an event is received. - -======================================================================*/ - -int parport_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "parport_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - parport_config(link); - break; - } - return 0; -} /* parport_event */ - static struct pcmcia_device_id parport_ids[] = { PCMCIA_DEVICE_FUNC_ID(3), PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0003), @@ -364,8 +328,7 @@ static struct pcmcia_driver parport_cs_driver = { .drv = { .name = "parport_cs", }, - .attach = parport_attach, - .event = parport_event, + .probe = parport_attach, .remove = parport_detach, .id_table = parport_ids, .suspend = parport_suspend, -- cgit v1.1