]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
leds: Add suspend/resume to the core class
authorRichard Purdie <rpurdie@linux.intel.com>
Thu, 8 Jan 2009 17:55:03 +0000 (17:55 +0000)
committerRichard Purdie <rpurdie@linux.intel.com>
Thu, 8 Jan 2009 17:55:03 +0000 (17:55 +0000)
Add suspend/resume to the core class and remove all the now unneeded
code from various drivers. Originally the class code couldn't support
suspend/resume but since class_device can there is no reason for
each driver doing its own suspend/resume anymore.

13 files changed:
drivers/leds/led-class.c
drivers/leds/leds-alix2.c
drivers/leds/leds-ams-delta.c
drivers/leds/leds-clevo-mail.c
drivers/leds/leds-fsg.c
drivers/leds/leds-gpio.c
drivers/leds/leds-hp-disk.c
drivers/leds/leds-hp6xx.c
drivers/leds/leds-net48xx.c
drivers/leds/leds-s3c24xx.c
drivers/leds/leds-wm8350.c
drivers/leds/leds-wrap.c
include/linux/leds.h

index 1553d93b8c65ccb729c30c436c9f30681f7e96ee..52f82e3ea13aae5b04a603938fba9dbbd0654712 100644 (file)
@@ -91,6 +91,26 @@ void led_classdev_resume(struct led_classdev *led_cdev)
 }
 EXPORT_SYMBOL_GPL(led_classdev_resume);
 
+static int led_suspend(struct device *dev, pm_message_t state)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+
+       if (led_cdev->flags & LED_CORE_SUSPENDRESUME)
+               led_classdev_suspend(led_cdev);
+
+       return 0;
+}
+
+static int led_resume(struct device *dev)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+
+       if (led_cdev->flags & LED_CORE_SUSPENDRESUME)
+               led_classdev_resume(led_cdev);
+
+       return 0;
+}
+
 /**
  * led_classdev_register - register a new object of led_classdev class.
  * @parent: The device to register.
@@ -174,6 +194,8 @@ static int __init leds_init(void)
        leds_class = class_create(THIS_MODULE, "leds");
        if (IS_ERR(leds_class))
                return PTR_ERR(leds_class);
+       leds_class->suspend = led_suspend;
+       leds_class->resume = led_resume;
        return 0;
 }
 
index d7666e6cb425b35ccac3f751a47e9835fdca90db..ddbd7730dfc84dfdcb4e9c776f81fdeb8b5b877e 100644 (file)
@@ -65,39 +65,13 @@ static struct alix_led alix_leds[] = {
        },
 };
 
-#ifdef CONFIG_PM
-
-static int alix_led_suspend(struct platform_device *dev, pm_message_t state)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(alix_leds); i++)
-               led_classdev_suspend(&alix_leds[i].cdev);
-       return 0;
-}
-
-static int alix_led_resume(struct platform_device *dev)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(alix_leds); i++)
-               led_classdev_resume(&alix_leds[i].cdev);
-       return 0;
-}
-
-#else
-
-#define alix_led_suspend NULL
-#define alix_led_resume NULL
-
-#endif
-
 static int __init alix_led_probe(struct platform_device *pdev)
 {
        int i;
        int ret;
 
        for (i = 0; i < ARRAY_SIZE(alix_leds); i++) {
+               alix_leds[i].cdev.flags |= LED_CORE_SUSPENDRESUME;
                ret = led_classdev_register(&pdev->dev, &alix_leds[i].cdev);
                if (ret < 0)
                        goto fail;
@@ -121,8 +95,6 @@ static int alix_led_remove(struct platform_device *pdev)
 
 static struct platform_driver alix_led_driver = {
        .remove = alix_led_remove,
-       .suspend = alix_led_suspend,
-       .resume = alix_led_resume,
        .driver = {
                .name = KBUILD_MODNAME,
                .owner = THIS_MODULE,
index 072157c3ba72150c62f63d931b9ee919039b7ad8..446050759b4dfb93e18a7a3dcd5905cf2886785e 100644 (file)
@@ -79,37 +79,12 @@ static struct ams_delta_led ams_delta_leds[] = {
        },
 };
 
-#ifdef CONFIG_PM
-static int ams_delta_led_suspend(struct platform_device *dev,
-               pm_message_t state)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++)
-               led_classdev_suspend(&ams_delta_leds[i].cdev);
-
-       return 0;
-}
-
-static int ams_delta_led_resume(struct platform_device *dev)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++)
-               led_classdev_resume(&ams_delta_leds[i].cdev);
-
-       return 0;
-}
-#else
-#define ams_delta_led_suspend NULL
-#define ams_delta_led_resume NULL
-#endif
-
 static int ams_delta_led_probe(struct platform_device *pdev)
 {
        int i, ret;
 
        for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++) {
+               ams_delta_leds[i].cdev.flags |= LED_CORE_SUSPENDRESUME;
                ret = led_classdev_register(&pdev->dev,
                                &ams_delta_leds[i].cdev);
                if (ret < 0)
@@ -136,8 +111,6 @@ static int ams_delta_led_remove(struct platform_device *pdev)
 static struct platform_driver ams_delta_led_driver = {
        .probe          = ams_delta_led_probe,
        .remove         = ams_delta_led_remove,
-       .suspend        = ams_delta_led_suspend,
-       .resume         = ams_delta_led_resume,
        .driver         = {
                .name = "ams-delta-led",
                .owner = THIS_MODULE,
index eb3415e88f43e217fb8faa87a00b9c082773ce0f..1813c84ea5fccb10293e499a3721dacf94c54290 100644 (file)
@@ -142,6 +142,7 @@ static struct led_classdev clevo_mail_led = {
        .name                   = "clevo::mail",
        .brightness_set         = clevo_mail_led_set,
        .blink_set              = clevo_mail_led_blink,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
 static int __init clevo_mail_led_probe(struct platform_device *pdev)
@@ -155,29 +156,9 @@ static int clevo_mail_led_remove(struct platform_device *pdev)
        return 0;
 }
 
-#ifdef CONFIG_PM
-static int clevo_mail_led_suspend(struct platform_device *dev,
-                                 pm_message_t state)
-{
-       led_classdev_suspend(&clevo_mail_led);
-       return 0;
-}
-
-static int clevo_mail_led_resume(struct platform_device *dev)
-{
-       led_classdev_resume(&clevo_mail_led);
-       return 0;
-}
-#else
-#define clevo_mail_led_suspend    NULL
-#define clevo_mail_led_resume     NULL
-#endif
-
 static struct platform_driver clevo_mail_led_driver = {
        .probe          = clevo_mail_led_probe,
        .remove         = clevo_mail_led_remove,
-       .suspend        = clevo_mail_led_suspend,
-       .resume         = clevo_mail_led_resume,
        .driver         = {
                .name           = KBUILD_MODNAME,
                .owner          = THIS_MODULE,
index 34935155c1c00077b6e94201cb4c5e6a534f1fad..5f7c9c5c09b1306c35211ed024aed989c1592b61 100644 (file)
@@ -99,64 +99,43 @@ static void fsg_led_ring_set(struct led_classdev *led_cdev,
 }
 
 
-
 static struct led_classdev fsg_wlan_led = {
        .name                   = "fsg:blue:wlan",
        .brightness_set         = fsg_led_wlan_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
 static struct led_classdev fsg_wan_led = {
        .name                   = "fsg:blue:wan",
        .brightness_set         = fsg_led_wan_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
 static struct led_classdev fsg_sata_led = {
        .name                   = "fsg:blue:sata",
        .brightness_set         = fsg_led_sata_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
 static struct led_classdev fsg_usb_led = {
        .name                   = "fsg:blue:usb",
        .brightness_set         = fsg_led_usb_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
 static struct led_classdev fsg_sync_led = {
        .name                   = "fsg:blue:sync",
        .brightness_set         = fsg_led_sync_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
 static struct led_classdev fsg_ring_led = {
        .name                   = "fsg:blue:ring",
        .brightness_set         = fsg_led_ring_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
 
-
-#ifdef CONFIG_PM
-static int fsg_led_suspend(struct platform_device *dev, pm_message_t state)
-{
-       led_classdev_suspend(&fsg_wlan_led);
-       led_classdev_suspend(&fsg_wan_led);
-       led_classdev_suspend(&fsg_sata_led);
-       led_classdev_suspend(&fsg_usb_led);
-       led_classdev_suspend(&fsg_sync_led);
-       led_classdev_suspend(&fsg_ring_led);
-       return 0;
-}
-
-static int fsg_led_resume(struct platform_device *dev)
-{
-       led_classdev_resume(&fsg_wlan_led);
-       led_classdev_resume(&fsg_wan_led);
-       led_classdev_resume(&fsg_sata_led);
-       led_classdev_resume(&fsg_usb_led);
-       led_classdev_resume(&fsg_sync_led);
-       led_classdev_resume(&fsg_ring_led);
-       return 0;
-}
-#endif
-
-
 static int fsg_led_probe(struct platform_device *pdev)
 {
        int ret;
@@ -232,10 +211,6 @@ static int fsg_led_remove(struct platform_device *pdev)
 static struct platform_driver fsg_led_driver = {
        .probe          = fsg_led_probe,
        .remove         = fsg_led_remove,
-#ifdef CONFIG_PM
-       .suspend        = fsg_led_suspend,
-       .resume         = fsg_led_resume,
-#endif
        .driver         = {
                .name           = "fsg-led",
        },
index b13bd2950e956347b98bac9ed76e18efcabed612..2e3df08b649b6c2a3a2dd83b62233bc3505a1459 100644 (file)
@@ -105,6 +105,7 @@ static int gpio_led_probe(struct platform_device *pdev)
                }
                led_dat->cdev.brightness_set = gpio_led_set;
                led_dat->cdev.brightness = LED_OFF;
+               led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
 
                gpio_direction_output(led_dat->gpio, led_dat->active_low);
 
@@ -154,44 +155,9 @@ static int __devexit gpio_led_remove(struct platform_device *pdev)
        return 0;
 }
 
-#ifdef CONFIG_PM
-static int gpio_led_suspend(struct platform_device *pdev, pm_message_t state)
-{
-       struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
-       struct gpio_led_data *leds_data;
-       int i;
-
-       leds_data = platform_get_drvdata(pdev);
-
-       for (i = 0; i < pdata->num_leds; i++)
-               led_classdev_suspend(&leds_data[i].cdev);
-
-       return 0;
-}
-
-static int gpio_led_resume(struct platform_device *pdev)
-{
-       struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
-       struct gpio_led_data *leds_data;
-       int i;
-
-       leds_data = platform_get_drvdata(pdev);
-
-       for (i = 0; i < pdata->num_leds; i++)
-               led_classdev_resume(&leds_data[i].cdev);
-
-       return 0;
-}
-#else
-#define gpio_led_suspend NULL
-#define gpio_led_resume NULL
-#endif
-
 static struct platform_driver gpio_led_driver = {
        .probe          = gpio_led_probe,
        .remove         = __devexit_p(gpio_led_remove),
-       .suspend        = gpio_led_suspend,
-       .resume         = gpio_led_resume,
        .driver         = {
                .name   = "leds-gpio",
                .owner  = THIS_MODULE,
index 44fa757d82547ff82b705a29ee5d54bf8a3b179a..d786adc8c5e3616ecb8131f2b1d58d68d19a30c8 100644 (file)
@@ -68,25 +68,9 @@ static struct led_classdev hpled_led = {
        .name                   = "hp:red:hddprotection",
        .default_trigger        = "heartbeat",
        .brightness_set         = hpled_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
-#ifdef CONFIG_PM
-static int hpled_suspend(struct acpi_device *dev, pm_message_t state)
-{
-       led_classdev_suspend(&hpled_led);
-       return 0;
-}
-
-static int hpled_resume(struct acpi_device *dev)
-{
-       led_classdev_resume(&hpled_led);
-       return 0;
-}
-#else
-#define hpled_suspend NULL
-#define hpled_resume NULL
-#endif
-
 static int hpled_add(struct acpi_device *device)
 {
        int ret;
@@ -121,8 +105,6 @@ static struct acpi_driver leds_hp_driver = {
        .ops = {
                .add     = hpled_add,
                .remove  = hpled_remove,
-               .suspend = hpled_suspend,
-               .resume  = hpled_resume,
        }
 };
 
index e8fb1baf8a5072e3d3454b3366e32d1c2c015140..e4ce1fd46338122b6e93b39f102a81be4ea621cb 100644 (file)
@@ -45,30 +45,16 @@ static struct led_classdev hp6xx_red_led = {
        .name                   = "hp6xx:red",
        .default_trigger        = "hp6xx-charge",
        .brightness_set         = hp6xxled_red_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
 static struct led_classdev hp6xx_green_led = {
        .name                   = "hp6xx:green",
        .default_trigger        = "ide-disk",
        .brightness_set         = hp6xxled_green_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
-#ifdef CONFIG_PM
-static int hp6xxled_suspend(struct platform_device *dev, pm_message_t state)
-{
-       led_classdev_suspend(&hp6xx_red_led);
-       led_classdev_suspend(&hp6xx_green_led);
-       return 0;
-}
-
-static int hp6xxled_resume(struct platform_device *dev)
-{
-       led_classdev_resume(&hp6xx_red_led);
-       led_classdev_resume(&hp6xx_green_led);
-       return 0;
-}
-#endif
-
 static int hp6xxled_probe(struct platform_device *pdev)
 {
        int ret;
@@ -98,10 +84,6 @@ MODULE_ALIAS("platform:hp6xx-led");
 static struct platform_driver hp6xxled_driver = {
        .probe          = hp6xxled_probe,
        .remove         = hp6xxled_remove,
-#ifdef CONFIG_PM
-       .suspend        = hp6xxled_suspend,
-       .resume         = hp6xxled_resume,
-#endif
        .driver         = {
                .name           = "hp6xx-led",
                .owner          = THIS_MODULE,
index 054360473c9490ea6e4251188dcbf4cad92fa310..93987a12da494594881dde8c375d94a246cd2254 100644 (file)
@@ -33,26 +33,9 @@ static void net48xx_error_led_set(struct led_classdev *led_cdev,
 static struct led_classdev net48xx_error_led = {
        .name           = "net48xx::error",
        .brightness_set = net48xx_error_led_set,
+       .flags          = LED_CORE_SUSPENDRESUME,
 };
 
-#ifdef CONFIG_PM
-static int net48xx_led_suspend(struct platform_device *dev,
-               pm_message_t state)
-{
-       led_classdev_suspend(&net48xx_error_led);
-       return 0;
-}
-
-static int net48xx_led_resume(struct platform_device *dev)
-{
-       led_classdev_resume(&net48xx_error_led);
-       return 0;
-}
-#else
-#define net48xx_led_suspend NULL
-#define net48xx_led_resume NULL
-#endif
-
 static int net48xx_led_probe(struct platform_device *pdev)
 {
        return led_classdev_register(&pdev->dev, &net48xx_error_led);
@@ -67,8 +50,6 @@ static int net48xx_led_remove(struct platform_device *pdev)
 static struct platform_driver net48xx_led_driver = {
        .probe          = net48xx_led_probe,
        .remove         = net48xx_led_remove,
-       .suspend        = net48xx_led_suspend,
-       .resume         = net48xx_led_resume,
        .driver         = {
                .name           = DRVNAME,
                .owner          = THIS_MODULE,
index 25a07f2643ade687245f5f3e929207325e094da0..4d81131542ae68e71e203dae1f9e63194547ffef 100644 (file)
@@ -82,6 +82,7 @@ static int s3c24xx_led_probe(struct platform_device *dev)
        led->cdev.brightness_set = s3c24xx_led_set;
        led->cdev.default_trigger = pdata->def_trigger;
        led->cdev.name = pdata->name;
+       led->cdev.flags |= LED_CORE_SUSPENDRESUME;
 
        led->pdata = pdata;
 
@@ -111,33 +112,9 @@ static int s3c24xx_led_probe(struct platform_device *dev)
        return ret;
 }
 
-
-#ifdef CONFIG_PM
-static int s3c24xx_led_suspend(struct platform_device *dev, pm_message_t state)
-{
-       struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);
-
-       led_classdev_suspend(&led->cdev);
-       return 0;
-}
-
-static int s3c24xx_led_resume(struct platform_device *dev)
-{
-       struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);
-
-       led_classdev_resume(&led->cdev);
-       return 0;
-}
-#else
-#define s3c24xx_led_suspend NULL
-#define s3c24xx_led_resume NULL
-#endif
-
 static struct platform_driver s3c24xx_led_driver = {
        .probe          = s3c24xx_led_probe,
        .remove         = s3c24xx_led_remove,
-       .suspend        = s3c24xx_led_suspend,
-       .resume         = s3c24xx_led_resume,
        .driver         = {
                .name           = "s3c24xx_led",
                .owner          = THIS_MODULE,
index 846ed978103f13537af8b6b418f6fe921ff5a4ac..38c6bcb07e6c55e7113397911bae3fb0fb8a5221 100644 (file)
@@ -184,27 +184,6 @@ static void wm8350_led_set(struct led_classdev *led_cdev,
        spin_unlock_irqrestore(&led->value_lock, flags);
 }
 
-#ifdef CONFIG_PM
-static int wm8350_led_suspend(struct platform_device *pdev, pm_message_t state)
-{
-       struct wm8350_led *led = platform_get_drvdata(pdev);
-
-       led_classdev_suspend(&led->cdev);
-       return 0;
-}
-
-static int wm8350_led_resume(struct platform_device *pdev)
-{
-       struct wm8350_led *led = platform_get_drvdata(pdev);
-
-       led_classdev_resume(&led->cdev);
-       return 0;
-}
-#else
-#define wm8350_led_suspend NULL
-#define wm8350_led_resume NULL
-#endif
-
 static void wm8350_led_shutdown(struct platform_device *pdev)
 {
        struct wm8350_led *led = platform_get_drvdata(pdev);
@@ -255,6 +234,7 @@ static int wm8350_led_probe(struct platform_device *pdev)
        led->cdev.brightness_set = wm8350_led_set;
        led->cdev.default_trigger = pdata->default_trigger;
        led->cdev.name = pdata->name;
+       led->cdev.flags |= LED_CORE_SUSPENDRESUME;
        led->enabled = regulator_is_enabled(isink);
        led->isink = isink;
        led->dcdc = dcdc;
@@ -311,8 +291,6 @@ static struct platform_driver wm8350_led_driver = {
        .probe = wm8350_led_probe,
        .remove = wm8350_led_remove,
        .shutdown = wm8350_led_shutdown,
-       .suspend = wm8350_led_suspend,
-       .resume = wm8350_led_resume,
 };
 
 static int __devinit wm8350_led_init(void)
index 2f3aa87f2a1f60d86ab7c7d4ada902462c992ed2..2982c86ac4cffb9e93da0a252b232a573c02ac22 100644 (file)
@@ -56,40 +56,21 @@ static struct led_classdev wrap_power_led = {
        .name                   = "wrap::power",
        .brightness_set         = wrap_power_led_set,
        .default_trigger        = "default-on",
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
 static struct led_classdev wrap_error_led = {
        .name           = "wrap::error",
        .brightness_set = wrap_error_led_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
 static struct led_classdev wrap_extra_led = {
        .name           = "wrap::extra",
        .brightness_set = wrap_extra_led_set,
+       .flags                  = LED_CORE_SUSPENDRESUME,
 };
 
-#ifdef CONFIG_PM
-static int wrap_led_suspend(struct platform_device *dev,
-               pm_message_t state)
-{
-       led_classdev_suspend(&wrap_power_led);
-       led_classdev_suspend(&wrap_error_led);
-       led_classdev_suspend(&wrap_extra_led);
-       return 0;
-}
-
-static int wrap_led_resume(struct platform_device *dev)
-{
-       led_classdev_resume(&wrap_power_led);
-       led_classdev_resume(&wrap_error_led);
-       led_classdev_resume(&wrap_extra_led);
-       return 0;
-}
-#else
-#define wrap_led_suspend NULL
-#define wrap_led_resume NULL
-#endif
-
 static int wrap_led_probe(struct platform_device *pdev)
 {
        int ret;
@@ -127,8 +108,6 @@ static int wrap_led_remove(struct platform_device *pdev)
 static struct platform_driver wrap_led_driver = {
        .probe          = wrap_led_probe,
        .remove         = wrap_led_remove,
-       .suspend        = wrap_led_suspend,
-       .resume         = wrap_led_resume,
        .driver         = {
                .name           = DRVNAME,
                .owner          = THIS_MODULE,
index 3c1a8ce6a5ea21593eb7524aeca8baca1342315d..24489da701e331b1a4d1810b40afd7209775e265 100644 (file)
@@ -32,7 +32,10 @@ struct led_classdev {
        int                      brightness;
        int                      flags;
 
+       /* Lower 16 bits reflect status */
 #define LED_SUSPENDED          (1 << 0)
+       /* Upper 16 bits reflect control information */
+#define LED_CORE_SUSPENDRESUME (1 << 16)
 
        /* Set LED brightness level */
        /* Must not sleep, use a workqueue if needed */