leds: backlight trigger: simplifications from core changes
Use the new module_led_trigger() helper. Also use attribute support from the trigger core. Drop error message on allocation failure as kzalloc() already screams loudly when failing. Use wrappers to get and set trigger data. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
This commit is contained in:
parent
13d698cbd9
commit
e4786ba0db
|
@ -64,8 +64,7 @@ static int fb_notifier_callback(struct notifier_block *p,
|
||||||
static ssize_t bl_trig_invert_show(struct device *dev,
|
static ssize_t bl_trig_invert_show(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct led_classdev *led = dev_get_drvdata(dev);
|
struct bl_trig_notifier *n = led_trigger_get_drvdata(dev);
|
||||||
struct bl_trig_notifier *n = led->trigger_data;
|
|
||||||
|
|
||||||
return sprintf(buf, "%u\n", n->invert);
|
return sprintf(buf, "%u\n", n->invert);
|
||||||
}
|
}
|
||||||
|
@ -73,8 +72,8 @@ static ssize_t bl_trig_invert_show(struct device *dev,
|
||||||
static ssize_t bl_trig_invert_store(struct device *dev,
|
static ssize_t bl_trig_invert_store(struct device *dev,
|
||||||
struct device_attribute *attr, const char *buf, size_t num)
|
struct device_attribute *attr, const char *buf, size_t num)
|
||||||
{
|
{
|
||||||
struct led_classdev *led = dev_get_drvdata(dev);
|
struct led_classdev *led = led_trigger_get_led(dev);
|
||||||
struct bl_trig_notifier *n = led->trigger_data;
|
struct bl_trig_notifier *n = led_trigger_get_drvdata(dev);
|
||||||
unsigned long invert;
|
unsigned long invert;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -97,6 +96,12 @@ static ssize_t bl_trig_invert_store(struct device *dev,
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR(inverted, 0644, bl_trig_invert_show, bl_trig_invert_store);
|
static DEVICE_ATTR(inverted, 0644, bl_trig_invert_show, bl_trig_invert_store);
|
||||||
|
|
||||||
|
static struct attribute *bl_trig_attrs[] = {
|
||||||
|
&dev_attr_inverted.attr,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
ATTRIBUTE_GROUPS(bl_trig);
|
||||||
|
|
||||||
static int bl_trig_activate(struct led_classdev *led)
|
static int bl_trig_activate(struct led_classdev *led)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -104,15 +109,9 @@ static int bl_trig_activate(struct led_classdev *led)
|
||||||
struct bl_trig_notifier *n;
|
struct bl_trig_notifier *n;
|
||||||
|
|
||||||
n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL);
|
n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL);
|
||||||
led->trigger_data = n;
|
if (!n)
|
||||||
if (!n) {
|
return -ENOMEM;
|
||||||
dev_err(led->dev, "unable to allocate backlight trigger\n");
|
led_set_trigger_data(led, n);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = device_create_file(led->dev, &dev_attr_inverted);
|
|
||||||
if (ret)
|
|
||||||
goto err_invert;
|
|
||||||
|
|
||||||
n->led = led;
|
n->led = led;
|
||||||
n->brightness = led->brightness;
|
n->brightness = led->brightness;
|
||||||
|
@ -122,48 +121,25 @@ static int bl_trig_activate(struct led_classdev *led)
|
||||||
ret = fb_register_client(&n->notifier);
|
ret = fb_register_client(&n->notifier);
|
||||||
if (ret)
|
if (ret)
|
||||||
dev_err(led->dev, "unable to register backlight trigger\n");
|
dev_err(led->dev, "unable to register backlight trigger\n");
|
||||||
led->activated = true;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err_invert:
|
|
||||||
led->trigger_data = NULL;
|
|
||||||
kfree(n);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bl_trig_deactivate(struct led_classdev *led)
|
static void bl_trig_deactivate(struct led_classdev *led)
|
||||||
{
|
{
|
||||||
struct bl_trig_notifier *n =
|
struct bl_trig_notifier *n = led_get_trigger_data(led);
|
||||||
(struct bl_trig_notifier *) led->trigger_data;
|
|
||||||
|
|
||||||
if (led->activated) {
|
fb_unregister_client(&n->notifier);
|
||||||
device_remove_file(led->dev, &dev_attr_inverted);
|
kfree(n);
|
||||||
fb_unregister_client(&n->notifier);
|
|
||||||
kfree(n);
|
|
||||||
led->activated = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct led_trigger bl_led_trigger = {
|
static struct led_trigger bl_led_trigger = {
|
||||||
.name = "backlight",
|
.name = "backlight",
|
||||||
.activate = bl_trig_activate,
|
.activate = bl_trig_activate,
|
||||||
.deactivate = bl_trig_deactivate
|
.deactivate = bl_trig_deactivate,
|
||||||
|
.groups = bl_trig_groups,
|
||||||
};
|
};
|
||||||
|
module_led_trigger(bl_led_trigger);
|
||||||
static int __init bl_trig_init(void)
|
|
||||||
{
|
|
||||||
return led_trigger_register(&bl_led_trigger);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __exit bl_trig_exit(void)
|
|
||||||
{
|
|
||||||
led_trigger_unregister(&bl_led_trigger);
|
|
||||||
}
|
|
||||||
|
|
||||||
module_init(bl_trig_init);
|
|
||||||
module_exit(bl_trig_exit);
|
|
||||||
|
|
||||||
MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
|
MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
|
||||||
MODULE_DESCRIPTION("Backlight emulation LED trigger");
|
MODULE_DESCRIPTION("Backlight emulation LED trigger");
|
||||||
|
|
Loading…
Reference in New Issue