Skip to content

Commit

Permalink
leds: Add suspend/resume to the core class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rpurdie committed Jan 8, 2009
1 parent 0081e80 commit 859cb7f
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 273 deletions.
22 changes: 22 additions & 0 deletions drivers/leds/led-class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
30 changes: 1 addition & 29 deletions drivers/leds/leds-alix2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
29 changes: 1 addition & 28 deletions drivers/leds/leds-ams-delta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
21 changes: 1 addition & 20 deletions drivers/leds/leds-clevo-mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
37 changes: 6 additions & 31 deletions drivers/leds/leds-fsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
},
Expand Down
36 changes: 1 addition & 35 deletions drivers/leds/leds-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down
20 changes: 1 addition & 19 deletions drivers/leds/leds-hp-disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,8 +105,6 @@ static struct acpi_driver leds_hp_driver = {
.ops = {
.add = hpled_add,
.remove = hpled_remove,
.suspend = hpled_suspend,
.resume = hpled_resume,
}
};

Expand Down
22 changes: 2 additions & 20 deletions drivers/leds/leds-hp6xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 859cb7f

Please sign in to comment.