leds: Add suspend/resume to the core class

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.
This commit is contained in:
Richard Purdie 2009-01-08 17:55:03 +00:00
parent 0081e8020e
commit 859cb7f2a4
13 changed files with 44 additions and 273 deletions

View file

@ -91,6 +91,26 @@ void led_classdev_resume(struct led_classdev *led_cdev)
} }
EXPORT_SYMBOL_GPL(led_classdev_resume); 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. * led_classdev_register - register a new object of led_classdev class.
* @parent: The device to register. * @parent: The device to register.
@ -174,6 +194,8 @@ static int __init leds_init(void)
leds_class = class_create(THIS_MODULE, "leds"); leds_class = class_create(THIS_MODULE, "leds");
if (IS_ERR(leds_class)) if (IS_ERR(leds_class))
return PTR_ERR(leds_class); return PTR_ERR(leds_class);
leds_class->suspend = led_suspend;
leds_class->resume = led_resume;
return 0; return 0;
} }

View 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) static int __init alix_led_probe(struct platform_device *pdev)
{ {
int i; int i;
int ret; int ret;
for (i = 0; i < ARRAY_SIZE(alix_leds); i++) { 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); ret = led_classdev_register(&pdev->dev, &alix_leds[i].cdev);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
@ -121,8 +95,6 @@ static int alix_led_remove(struct platform_device *pdev)
static struct platform_driver alix_led_driver = { static struct platform_driver alix_led_driver = {
.remove = alix_led_remove, .remove = alix_led_remove,
.suspend = alix_led_suspend,
.resume = alix_led_resume,
.driver = { .driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,

View 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) static int ams_delta_led_probe(struct platform_device *pdev)
{ {
int i, ret; int i, ret;
for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++) { 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, ret = led_classdev_register(&pdev->dev,
&ams_delta_leds[i].cdev); &ams_delta_leds[i].cdev);
if (ret < 0) 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 = { static struct platform_driver ams_delta_led_driver = {
.probe = ams_delta_led_probe, .probe = ams_delta_led_probe,
.remove = ams_delta_led_remove, .remove = ams_delta_led_remove,
.suspend = ams_delta_led_suspend,
.resume = ams_delta_led_resume,
.driver = { .driver = {
.name = "ams-delta-led", .name = "ams-delta-led",
.owner = THIS_MODULE, .owner = THIS_MODULE,

View file

@ -142,6 +142,7 @@ static struct led_classdev clevo_mail_led = {
.name = "clevo::mail", .name = "clevo::mail",
.brightness_set = clevo_mail_led_set, .brightness_set = clevo_mail_led_set,
.blink_set = clevo_mail_led_blink, .blink_set = clevo_mail_led_blink,
.flags = LED_CORE_SUSPENDRESUME,
}; };
static int __init clevo_mail_led_probe(struct platform_device *pdev) 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; 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 = { static struct platform_driver clevo_mail_led_driver = {
.probe = clevo_mail_led_probe, .probe = clevo_mail_led_probe,
.remove = clevo_mail_led_remove, .remove = clevo_mail_led_remove,
.suspend = clevo_mail_led_suspend,
.resume = clevo_mail_led_resume,
.driver = { .driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,

View file

@ -99,64 +99,43 @@ static void fsg_led_ring_set(struct led_classdev *led_cdev,
} }
static struct led_classdev fsg_wlan_led = { static struct led_classdev fsg_wlan_led = {
.name = "fsg:blue:wlan", .name = "fsg:blue:wlan",
.brightness_set = fsg_led_wlan_set, .brightness_set = fsg_led_wlan_set,
.flags = LED_CORE_SUSPENDRESUME,
}; };
static struct led_classdev fsg_wan_led = { static struct led_classdev fsg_wan_led = {
.name = "fsg:blue:wan", .name = "fsg:blue:wan",
.brightness_set = fsg_led_wan_set, .brightness_set = fsg_led_wan_set,
.flags = LED_CORE_SUSPENDRESUME,
}; };
static struct led_classdev fsg_sata_led = { static struct led_classdev fsg_sata_led = {
.name = "fsg:blue:sata", .name = "fsg:blue:sata",
.brightness_set = fsg_led_sata_set, .brightness_set = fsg_led_sata_set,
.flags = LED_CORE_SUSPENDRESUME,
}; };
static struct led_classdev fsg_usb_led = { static struct led_classdev fsg_usb_led = {
.name = "fsg:blue:usb", .name = "fsg:blue:usb",
.brightness_set = fsg_led_usb_set, .brightness_set = fsg_led_usb_set,
.flags = LED_CORE_SUSPENDRESUME,
}; };
static struct led_classdev fsg_sync_led = { static struct led_classdev fsg_sync_led = {
.name = "fsg:blue:sync", .name = "fsg:blue:sync",
.brightness_set = fsg_led_sync_set, .brightness_set = fsg_led_sync_set,
.flags = LED_CORE_SUSPENDRESUME,
}; };
static struct led_classdev fsg_ring_led = { static struct led_classdev fsg_ring_led = {
.name = "fsg:blue:ring", .name = "fsg:blue:ring",
.brightness_set = fsg_led_ring_set, .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) static int fsg_led_probe(struct platform_device *pdev)
{ {
int ret; int ret;
@ -232,10 +211,6 @@ static int fsg_led_remove(struct platform_device *pdev)
static struct platform_driver fsg_led_driver = { static struct platform_driver fsg_led_driver = {
.probe = fsg_led_probe, .probe = fsg_led_probe,
.remove = fsg_led_remove, .remove = fsg_led_remove,
#ifdef CONFIG_PM
.suspend = fsg_led_suspend,
.resume = fsg_led_resume,
#endif
.driver = { .driver = {
.name = "fsg-led", .name = "fsg-led",
}, },

View 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_set = gpio_led_set;
led_dat->cdev.brightness = LED_OFF; led_dat->cdev.brightness = LED_OFF;
led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
gpio_direction_output(led_dat->gpio, led_dat->active_low); 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; 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 = { static struct platform_driver gpio_led_driver = {
.probe = gpio_led_probe, .probe = gpio_led_probe,
.remove = __devexit_p(gpio_led_remove), .remove = __devexit_p(gpio_led_remove),
.suspend = gpio_led_suspend,
.resume = gpio_led_resume,
.driver = { .driver = {
.name = "leds-gpio", .name = "leds-gpio",
.owner = THIS_MODULE, .owner = THIS_MODULE,

View file

@ -68,25 +68,9 @@ static struct led_classdev hpled_led = {
.name = "hp:red:hddprotection", .name = "hp:red:hddprotection",
.default_trigger = "heartbeat", .default_trigger = "heartbeat",
.brightness_set = hpled_set, .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) static int hpled_add(struct acpi_device *device)
{ {
int ret; int ret;
@ -121,8 +105,6 @@ static struct acpi_driver leds_hp_driver = {
.ops = { .ops = {
.add = hpled_add, .add = hpled_add,
.remove = hpled_remove, .remove = hpled_remove,
.suspend = hpled_suspend,
.resume = hpled_resume,
} }
}; };

View file

@ -45,30 +45,16 @@ static struct led_classdev hp6xx_red_led = {
.name = "hp6xx:red", .name = "hp6xx:red",
.default_trigger = "hp6xx-charge", .default_trigger = "hp6xx-charge",
.brightness_set = hp6xxled_red_set, .brightness_set = hp6xxled_red_set,
.flags = LED_CORE_SUSPENDRESUME,
}; };
static struct led_classdev hp6xx_green_led = { static struct led_classdev hp6xx_green_led = {
.name = "hp6xx:green", .name = "hp6xx:green",
.default_trigger = "ide-disk", .default_trigger = "ide-disk",
.brightness_set = hp6xxled_green_set, .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) static int hp6xxled_probe(struct platform_device *pdev)
{ {
int ret; int ret;
@ -98,10 +84,6 @@ MODULE_ALIAS("platform:hp6xx-led");
static struct platform_driver hp6xxled_driver = { static struct platform_driver hp6xxled_driver = {
.probe = hp6xxled_probe, .probe = hp6xxled_probe,
.remove = hp6xxled_remove, .remove = hp6xxled_remove,
#ifdef CONFIG_PM
.suspend = hp6xxled_suspend,
.resume = hp6xxled_resume,
#endif
.driver = { .driver = {
.name = "hp6xx-led", .name = "hp6xx-led",
.owner = THIS_MODULE, .owner = THIS_MODULE,

View file

@ -33,26 +33,9 @@ static void net48xx_error_led_set(struct led_classdev *led_cdev,
static struct led_classdev net48xx_error_led = { static struct led_classdev net48xx_error_led = {
.name = "net48xx::error", .name = "net48xx::error",
.brightness_set = net48xx_error_led_set, .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) static int net48xx_led_probe(struct platform_device *pdev)
{ {
return led_classdev_register(&pdev->dev, &net48xx_error_led); 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 = { static struct platform_driver net48xx_led_driver = {
.probe = net48xx_led_probe, .probe = net48xx_led_probe,
.remove = net48xx_led_remove, .remove = net48xx_led_remove,
.suspend = net48xx_led_suspend,
.resume = net48xx_led_resume,
.driver = { .driver = {
.name = DRVNAME, .name = DRVNAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,

View file

@ -82,6 +82,7 @@ static int s3c24xx_led_probe(struct platform_device *dev)
led->cdev.brightness_set = s3c24xx_led_set; led->cdev.brightness_set = s3c24xx_led_set;
led->cdev.default_trigger = pdata->def_trigger; led->cdev.default_trigger = pdata->def_trigger;
led->cdev.name = pdata->name; led->cdev.name = pdata->name;
led->cdev.flags |= LED_CORE_SUSPENDRESUME;
led->pdata = pdata; led->pdata = pdata;
@ -111,33 +112,9 @@ static int s3c24xx_led_probe(struct platform_device *dev)
return ret; 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 = { static struct platform_driver s3c24xx_led_driver = {
.probe = s3c24xx_led_probe, .probe = s3c24xx_led_probe,
.remove = s3c24xx_led_remove, .remove = s3c24xx_led_remove,
.suspend = s3c24xx_led_suspend,
.resume = s3c24xx_led_resume,
.driver = { .driver = {
.name = "s3c24xx_led", .name = "s3c24xx_led",
.owner = THIS_MODULE, .owner = THIS_MODULE,

View file

@ -184,27 +184,6 @@ static void wm8350_led_set(struct led_classdev *led_cdev,
spin_unlock_irqrestore(&led->value_lock, flags); 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) static void wm8350_led_shutdown(struct platform_device *pdev)
{ {
struct wm8350_led *led = platform_get_drvdata(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.brightness_set = wm8350_led_set;
led->cdev.default_trigger = pdata->default_trigger; led->cdev.default_trigger = pdata->default_trigger;
led->cdev.name = pdata->name; led->cdev.name = pdata->name;
led->cdev.flags |= LED_CORE_SUSPENDRESUME;
led->enabled = regulator_is_enabled(isink); led->enabled = regulator_is_enabled(isink);
led->isink = isink; led->isink = isink;
led->dcdc = dcdc; led->dcdc = dcdc;
@ -311,8 +291,6 @@ static struct platform_driver wm8350_led_driver = {
.probe = wm8350_led_probe, .probe = wm8350_led_probe,
.remove = wm8350_led_remove, .remove = wm8350_led_remove,
.shutdown = wm8350_led_shutdown, .shutdown = wm8350_led_shutdown,
.suspend = wm8350_led_suspend,
.resume = wm8350_led_resume,
}; };
static int __devinit wm8350_led_init(void) static int __devinit wm8350_led_init(void)

View file

@ -56,40 +56,21 @@ static struct led_classdev wrap_power_led = {
.name = "wrap::power", .name = "wrap::power",
.brightness_set = wrap_power_led_set, .brightness_set = wrap_power_led_set,
.default_trigger = "default-on", .default_trigger = "default-on",
.flags = LED_CORE_SUSPENDRESUME,
}; };
static struct led_classdev wrap_error_led = { static struct led_classdev wrap_error_led = {
.name = "wrap::error", .name = "wrap::error",
.brightness_set = wrap_error_led_set, .brightness_set = wrap_error_led_set,
.flags = LED_CORE_SUSPENDRESUME,
}; };
static struct led_classdev wrap_extra_led = { static struct led_classdev wrap_extra_led = {
.name = "wrap::extra", .name = "wrap::extra",
.brightness_set = wrap_extra_led_set, .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) static int wrap_led_probe(struct platform_device *pdev)
{ {
int ret; int ret;
@ -127,8 +108,6 @@ static int wrap_led_remove(struct platform_device *pdev)
static struct platform_driver wrap_led_driver = { static struct platform_driver wrap_led_driver = {
.probe = wrap_led_probe, .probe = wrap_led_probe,
.remove = wrap_led_remove, .remove = wrap_led_remove,
.suspend = wrap_led_suspend,
.resume = wrap_led_resume,
.driver = { .driver = {
.name = DRVNAME, .name = DRVNAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,

View file

@ -32,7 +32,10 @@ struct led_classdev {
int brightness; int brightness;
int flags; int flags;
/* Lower 16 bits reflect status */
#define LED_SUSPENDED (1 << 0) #define LED_SUSPENDED (1 << 0)
/* Upper 16 bits reflect control information */
#define LED_CORE_SUSPENDRESUME (1 << 16)
/* Set LED brightness level */ /* Set LED brightness level */
/* Must not sleep, use a workqueue if needed */ /* Must not sleep, use a workqueue if needed */