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/char/pcmcia/cm4000_cs.c | 61 ++++++++++++++++++++++----------------- drivers/char/pcmcia/cm4040_cs.c | 50 ++++++++++++++++---------------- drivers/char/pcmcia/synclink_cs.c | 47 ++++++++++++++++++------------ 3 files changed, 88 insertions(+), 70 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c index 61681c9f3f7..05e93054c98 100644 --- a/drivers/char/pcmcia/cm4000_cs.c +++ b/drivers/char/pcmcia/cm4000_cs.c @@ -1893,33 +1893,6 @@ static int cm4000_event(event_t event, int priority, link->state &= ~DEV_PRESENT; stop_monitor(dev); break; - case CS_EVENT_PM_SUSPEND: - DEBUGP(5, dev, "CS_EVENT_PM_SUSPEND " - "(fall-through to CS_EVENT_RESET_PHYSICAL)\n"); - link->state |= DEV_SUSPEND; - /* fall-through */ - case CS_EVENT_RESET_PHYSICAL: - DEBUGP(5, dev, "CS_EVENT_RESET_PHYSICAL\n"); - if (link->state & DEV_CONFIG) { - DEBUGP(5, dev, "ReleaseConfiguration\n"); - pcmcia_release_configuration(link->handle); - } - stop_monitor(dev); - break; - case CS_EVENT_PM_RESUME: - DEBUGP(5, dev, "CS_EVENT_PM_RESUME " - "(fall-through to CS_EVENT_CARD_RESET)\n"); - link->state &= ~DEV_SUSPEND; - /* fall-through */ - case CS_EVENT_CARD_RESET: - DEBUGP(5, dev, "CS_EVENT_CARD_RESET\n"); - if ((link->state & DEV_CONFIG)) { - DEBUGP(5, dev, "RequestConfiguration\n"); - pcmcia_request_configuration(link->handle, &link->conf); - } - if (link->open) - start_monitor(dev); - break; default: DEBUGP(5, dev, "unknown event %.2x\n", event); break; @@ -1928,6 +1901,38 @@ static int cm4000_event(event_t event, int priority, return CS_SUCCESS; } +static int cm4000_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct cm4000_dev *dev; + + dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + stop_monitor(dev); + + return 0; +} + +static int cm4000_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct cm4000_dev *dev; + + dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + + if (link->open) + start_monitor(dev); + + return 0; +} + static void cm4000_release(dev_link_t *link) { cmm_cm4000_release(link->priv); /* delay release until device closed */ @@ -2044,6 +2049,8 @@ static struct pcmcia_driver cm4000_driver = { }, .attach = cm4000_attach, .detach = cm4000_detach, + .suspend = cm4000_suspend, + .resume = cm4000_resume, .event = cm4000_event, .id_table = cm4000_ids, }; diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c index 4c698d908ff..3622fd39c47 100644 --- a/drivers/char/pcmcia/cm4040_cs.c +++ b/drivers/char/pcmcia/cm4040_cs.c @@ -656,31 +656,7 @@ static int reader_event(event_t event, int priority, DEBUGP(5, dev, "CS_EVENT_CARD_REMOVAL\n"); link->state &= ~DEV_PRESENT; break; - case CS_EVENT_PM_SUSPEND: - DEBUGP(5, dev, "CS_EVENT_PM_SUSPEND " - "(fall-through to CS_EVENT_RESET_PHYSICAL)\n"); - link->state |= DEV_SUSPEND; - - case CS_EVENT_RESET_PHYSICAL: - DEBUGP(5, dev, "CS_EVENT_RESET_PHYSICAL\n"); - if (link->state & DEV_CONFIG) { - DEBUGP(5, dev, "ReleaseConfiguration\n"); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - DEBUGP(5, dev, "CS_EVENT_PM_RESUME " - "(fall-through to CS_EVENT_CARD_RESET)\n"); - link->state &= ~DEV_SUSPEND; - - case CS_EVENT_CARD_RESET: - DEBUGP(5, dev, "CS_EVENT_CARD_RESET\n"); - if ((link->state & DEV_CONFIG)) { - DEBUGP(5, dev, "RequestConfiguration\n"); - pcmcia_request_configuration(link->handle, - &link->conf); - } - break; + default: DEBUGP(5, dev, "reader_event: unknown event %.2x\n", event); @@ -690,6 +666,28 @@ static int reader_event(event_t event, int priority, return CS_SUCCESS; } +static int reader_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int reader_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} + static void reader_release(dev_link_t *link) { cm4040_reader_release(link->priv); @@ -806,6 +804,8 @@ static struct pcmcia_driver reader_driver = { }, .attach = reader_attach, .detach = reader_detach, + .suspend = reader_suspend, + .resume = reader_resume, .event = reader_event, .id_table = cm4040_ids, }; diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 2c326ea5342..776103e5604 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -773,11 +773,37 @@ static void mgslpc_detach(dev_link_t *link) mgslpc_remove_device((MGSLPC_INFO *)link->priv); } +static int mgslpc_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + MGSLPC_INFO *info = link->priv; + + link->state |= DEV_SUSPEND; + info->stop = 1; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int mgslpc_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + MGSLPC_INFO *info = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + info->stop = 0; + + return 0; +} + + static int mgslpc_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - MGSLPC_INFO *info = link->priv; if (debug_level >= DEBUG_LEVEL_INFO) printk("mgslpc_event(0x%06x)\n", event); @@ -794,23 +820,6 @@ static int mgslpc_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; mgslpc_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - /* Mark the device as stopped, to block IO until later */ - info->stop = 1; - 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 (link->state & DEV_CONFIG) - pcmcia_request_configuration(link->handle, &link->conf); - info->stop = 0; - break; } return 0; } @@ -3095,6 +3104,8 @@ static struct pcmcia_driver mgslpc_driver = { .event = mgslpc_event, .detach = mgslpc_detach, .id_table = mgslpc_ids, + .suspend = mgslpc_suspend, + .resume = mgslpc_resume, }; static struct tty_operations mgslpc_ops = { -- cgit v1.2.3