leds: leds-mc13783: Add MC34708 LED support
Subsystems (2)
PATCH 3/5 leds: leds-mc13783: Use proper "max_brightness" value for LEDs
In reply to Alexander ShiyanInstead of using maximum value of 255 and shift it to appropriate LED duty cycle, this patch introduce a helper to use proper maximum value for each LED.
--- drivers/leds/leds-mc13783.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-)
drivers/leds/leds-mc13783.c +28 -13
@@ -45,11 +45,35 @@ struct mc13xxx_leds {struct mc13xxx_led led[0 ]; }; +static unsigned int mc13xxx_max_brightness (int id) +{ +switch (id) { +case MC13783_LED_MD : +case MC13783_LED_AD : +case MC13783_LED_KP : +return 0x0f ; +case MC13783_LED_R1 : +case MC13783_LED_G1 : +case MC13783_LED_B1 : +case MC13783_LED_R2 : +case MC13783_LED_G2 : +case MC13783_LED_B2 : +case MC13783_LED_R3 : +case MC13783_LED_G3 : +case MC13783_LED_B3 : +return 0x1f ; +default : +break ; + } + +return 0x3f ; +} +static void mc13xxx_led_work (struct work_struct *work) { struct mc13xxx_led *led = container_of(work, struct mc13xxx_led, work);struct mc13xxx_leds *leds = led->leds; -unsigned int reg, mask, value, bank, off, shift; +unsigned int reg, bank, off, shift;switch (led->id) {case MC13783_LED_MD :
@@ -57,8 +81,6 @@ static void mc13xxx_led_work(struct work_struct *work)case MC13783_LED_KP : reg =2 ; shift =9 + (led->id -MC13783_LED_MD ) *4 ; - mask =0x0f ; - value = led->new_brightness >>4 ;break ;case MC13783_LED_R1 :case MC13783_LED_G1 :
@@ -73,16 +95,12 @@ static void mc13xxx_led_work(struct work_struct *work) bank = off /3 ; reg =3 + bank; shift = (off - bank *3 ) *5 +6 ; - value = led->new_brightness >>3 ; - mask =0x1f ;break ;case MC13892_LED_MD :case MC13892_LED_AD :case MC13892_LED_KP : reg = (led->id -MC13892_LED_MD ) /2 ; shift =3 + (led->id -MC13892_LED_MD ) *12 ; - mask =0x3f ; - value = led->new_brightness >>2 ;break ;case MC13892_LED_R :case MC13892_LED_G :
@@ -91,22 +109,19 @@ static void mc13xxx_led_work(struct work_struct *work) bank = off /2 ; reg =2 + bank; shift = (off - bank *2 ) *12 +3 ; - value = led->new_brightness >>2 ; - mask =0x3f ;break ;case MC34708_LED_R :case MC34708_LED_G : reg =0 ; shift =3 + (led->id -MC34708_LED_R ) *12 ; - value = led->new_brightness >>2 ; - mask =0x3f ;break ;default :BUG (); }mc13xxx_reg_rmw (leds->master, leds->devtype->ledctrl_base + reg, - mask << shift, value << shift); +mc13xxx_max_brightness (led->id) << shift, + led->new_brightness << shift); } static void mc13xxx_led_set(struct led_classdev *led_cdev,
@@ -186,7 +201,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev) leds->led[i].cdev.default_trigger = trig; leds->led[i].cdev.flags |=LED_CORE_SUSPENDRESUME ; leds->led[i].cdev.brightness_set = mc13xxx_led_set; - leds->led[i].cdev.brightness =LED_OFF ; + leds->led[i].cdev.max_brightness =mc13xxx_max_brightness (id);INIT_WORK (&leds->led[i].work, mc13xxx_led_work);
Signature · 1 line
1.8.3.2
PATCH 2/5 leds: leds-mc13783: Use LED core PM functions
In reply to Alexander Shiyan--- drivers/leds/leds-mc13783.c | 1 + 1 file changed, 1 insertion(+)
drivers/leds/leds-mc13783.c +1 -0
@@ -184,6 +184,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev) leds->led[i].leds = leds; leds->led[i].cdev.name = name; leds->led[i].cdev.default_trigger = trig; + leds->led[i].cdev.flags |=LED_CORE_SUSPENDRESUME ; leds->led[i].cdev.brightness_set = mc13xxx_led_set; leds->led[i].cdev.brightness =LED_OFF ;
Signature · 1 line
1.8.3.2
PATCH 4/5 leds: leds-mc13783: Remove unnecessary cleaning of registers on exit
In reply to Alexander ShiyanLED core switches each LED to OFF-state on exit, so there is no need for resetting registers.
--- drivers/leds/leds-mc13783.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/leds/leds-mc13783.c +0 -4
@@ -224,7 +224,6 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)static int mc13xxx_led_remove (struct platform_device *pdev) {struct mc13xxx_leds *leds =platform_get_drvdata (pdev); -struct mc13xxx *mcdev = leds->master;int i;for (i =0 ; i < leds->num_leds; i++) {
@@ -232,9 +231,6 @@ static int mc13xxx_led_remove(struct platform_device *pdev)cancel_work_sync (&leds->led[i].work); } -for (i =0 ; i < leds->devtype->num_regs; i++) -mc13xxx_reg_write (mcdev, leds->devtype->ledctrl_base + i,0 ); -return 0 ; }
Signature · 1 line
1.8.3.2
PATCH 1/5 leds: leds-mc13783: Add MC34708 LED support
This patch adds support for two LEDs on MC34708 PMIC.
--- drivers/leds/Kconfig | 2 +- drivers/leds/leds-mc13783.c | 98 ++++++++++++++++++++++----------------------- include/linux/mfd/mc13xxx.h | 6 +++ 3 files changed, 55 insertions(+), 51 deletions(-)
drivers/leds/Kconfig +1 -1
@@ -413,7 +413,7 @@ config LEDS_MC13783 depends on MFD_MC13XXX help This option enable support for on-chip LED drivers found - on Freescale Semiconductor MC13783/MC13892 PMIC. + on Freescale Semiconductor MC13783/MC13892/MC34708 PMIC. config LEDS_NS2 tristate "LED support for Network Space v2 GPIO LEDs"
drivers/leds/leds-mc13783.c +48 -50
242 lines not on this page · raw message
include/linux/mfd/mc13xxx.h +6 -0
@@ -106,6 +106,9 @@ enum {MC13892_LED_R ,MC13892_LED_G ,MC13892_LED_B , +/* MC34708 LED IDs */ +MC34708_LED_R , + MC34708_LED_G, }; struct mc13xxx_led_platform_data {
@@ -165,6 +168,9 @@ struct mc13xxx_leds_platform_data {#define MC13892_LED_C2_CURRENT_G (x) (((x) & 0x7) << 21)/* MC13892 LED Control 3 */ #define MC13892_LED_C3_CURRENT_B (x) (((x) & 0x7) << 9) +/* MC34708 LED Control 0 */ +#define MC34708_LED_C0_CURRENT_R (x) (((x) & 0x3) << 9) +#define MC34708_LED_C0_CURRENT_G (x) (((x) & 0x3) << 21)u32 led_control[MAX_LED_CONTROL_REGS ]; };
Signature · 1 line
1.8.3.2
Quoted 221 lines · Alexander Shiyan
This patch adds support for two LEDs on MC34708 PMIC.
Signed-off-by Alexander Shiyan <[email protected]>--- drivers/leds/Kconfig | 2 +- drivers/leds/leds-mc13783.c | 98 ++++++++++++++++++++++----------------------- include/linux/mfd/mc13xxx.h | 6 +++ 3 files changed, 55 insertions(+), 51 deletions(-)drivers/leds/Kconfig +1
-1@@ -413,7 +413,7 @@ config LEDS_MC13783 depends on MFD_MC13XXX help This option enable support for on-chip LED drivers found - on Freescale Semiconductor MC13783/MC13892 PMIC. + on Freescale Semiconductor MC13783/MC13892/MC34708 PMIC. config LEDS_NS2 tristate "LED support for Network Space v2 GPIO LEDs"drivers/leds/leds-mc13783.c +34
-45@@ -1,5 +1,5 @@/* -* LEDs driver for Freescale MC13783/MC13892 +* LEDs driver for Freescale MC13783/MC13892/MC34708 * * Copyright (C) 2010 Philippe Rétornaz * @@ -23,23 +23,23 @@#include <linux/workqueue.h> #include <linux/mfd/mc13xxx.h> -#define MC13XXX_REG_LED_CONTROL (x) (51 + (x)) -struct mc13xxx_led_devtype {int led_min;int led_max;int num_regs; +u32 ledctrl_base; };struct mc13xxx_led {struct led_classdev cdev;struct work_struct work; -struct mc13xxx *master;enum led_brightness new_brightness;int id; +struct mc13xxx_leds *leds; };struct mc13xxx_leds { +struct mc13xxx *master;struct mc13xxx_led_devtype *devtype;int num_leds;struct mc13xxx_led led[0 ];@@ -48,24 +48,15 @@ struct mc13xxx_leds {static void mc13xxx_led_work (struct work_struct *work) { struct mc13xxx_led *led = container_of(work, struct mc13xxx_led, work); -int reg, mask, value, bank, off, shift; +struct mc13xxx_leds *leds = led->leds; +unsigned int reg, mask, value, bank, off, shift;switch (led->id) {case MC13783_LED_MD : - reg =MC13XXX_REG_LED_CONTROL (2 ); - shift =9 ; - mask =0x0f ; - value = led->new_brightness >>4 ; -break ;case MC13783_LED_AD : - reg =MC13XXX_REG_LED_CONTROL (2 ); - shift =13 ; - mask =0x0f ; - value = led->new_brightness >>4 ; -break ;case MC13783_LED_KP : - reg =MC13XXX_REG_LED_CONTROL (2 ); - shift =17 ; + reg =2 ; + shift =9 + (led->id -MC13783_LED_MD ) *4 ; mask =0x0f ; value = led->new_brightness >>4 ;break ;@@ -80,26 +71,16 @@ static void mc13xxx_led_work(struct work_struct *work)case MC13783_LED_B3 : off = led->id -MC13783_LED_R1 ; bank = off /3 ; - reg =MC13XXX_REG_LED_CONTROL (3 ) + bank; + reg =3 + bank; shift = (off - bank *3 ) *5 +6 ; value = led->new_brightness >>3 ; mask =0x1f ;break ;case MC13892_LED_MD : - reg =MC13XXX_REG_LED_CONTROL (0 ); - shift =3 ; - mask =0x3f ; - value = led->new_brightness >>2 ; -break ;case MC13892_LED_AD : - reg =MC13XXX_REG_LED_CONTROL (0 ); - shift =15 ; - mask =0x3f ; - value = led->new_brightness >>2 ; -break ;case MC13892_LED_KP : - reg =MC13XXX_REG_LED_CONTROL (1 ); - shift =3 ; + reg = (led->id -MC13892_LED_MD ) /2 ; + shift =3 + (led->id -MC13892_LED_MD ) *12 ; mask =0x3f ; value = led->new_brightness >>2 ;break ;@@ -108,16 +89,24 @@ static void mc13xxx_led_work(struct work_struct *work)case MC13892_LED_B : off = led->id -MC13892_LED_R ; bank = off /2 ; - reg =MC13XXX_REG_LED_CONTROL (2 ) + bank; + reg =2 + bank; shift = (off - bank *2 ) *12 +3 ; value = led->new_brightness >>2 ; mask =0x3f ;break ; +case MC34708_LED_R : +case MC34708_LED_G : + reg =0 ; + shift =3 + (led->id -MC34708_LED_R ) *12 ; + value = led->new_brightness >>2 ; + mask =0x3f ; +break ;default :BUG (); } -mc13xxx_reg_rmw (led->master, reg, mask << shift, value << shift); +mc13xxx_reg_rmw (leds->master, leds->devtype->ledctrl_base + reg, + mask << shift, value << shift); } static void mc13xxx_led_set(struct led_classdev *led_cdev,@@ -132,16 +121,17 @@ static void mc13xxx_led_set(struct led_classdev *led_cdev,static int __init mc13xxx_led_probe (struct platform_device *pdev) { -struct mc13xxx_leds_platform_data *pdata =dev_get_platdata (&pdev->dev); -struct mc13xxx *mcdev =dev_get_drvdata (pdev->dev.parent); +struct device *dev = &pdev->dev; +struct mc13xxx_leds_platform_data *pdata =dev_get_platdata (dev); +struct mc13xxx *mcdev =dev_get_drvdata (dev->parent);struct mc13xxx_led_devtype *devtype = (struct mc13xxx_led_devtype *)pdev->id_entry->driver_data;struct mc13xxx_leds *leds;int i, id, num_leds, ret = -ENODATA ; -u32 reg, init_led =0 ; +u32 init_led =0 ;if (!pdata) { -dev_err (&pdev->dev,"Missing platform data\n" ); +dev_err (dev,"Missing platform data\n" );return -ENODEV ; }@@ -149,23 +139,23 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)if ((num_leds <1 ) || (num_leds > (devtype->led_max - devtype->led_min +1 ))) { -dev_err (&pdev->dev,"Invalid LED count %d\n" , num_leds); +dev_err (dev,"Invalid LED count %d\n" , num_leds);return -EINVAL ; } - leds =devm_kzalloc (&pdev->dev, num_leds *sizeof (struct mc13xxx_led ) + + leds =devm_kzalloc (dev, num_leds *sizeof (struct mc13xxx_led ) +sizeof (struct mc13xxx_leds ),GFP_KERNEL );if (!leds)return -ENOMEM ; leds->devtype = devtype; leds->num_leds = num_leds; + leds->master = mcdev;platform_set_drvdata (pdev, leds);for (i =0 ; i < devtype->num_regs; i++) { - reg = pdata->led_control[i]; -WARN_ON (reg >= (1 <<24 )); - ret =mc13xxx_reg_write (mcdev,MC13XXX_REG_LED_CONTROL (i), reg); + ret =mc13xxx_reg_write (mcdev, leds->devtype->ledctrl_base + i, + pdata->led_control[i]);if (ret)return ret; }@@ -180,19 +170,18 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev) trig = pdata->led[i].default_trigger;if ((id > devtype->led_max) || (id < devtype->led_min)) { -dev_err (&pdev->dev,"Invalid ID %i\n" , id); +dev_err (dev,"Invalid ID %i\n" , id);break ; }if (init_led & (1 << id)) { -dev_warn (&pdev->dev, -"LED %i already initialized\n" , id); +dev_warn (dev,"LED %i already initialized\n" , id);break ; } init_led |=1 << id; leds->led[i].id = id; - leds->led[i].master = mcdev; + leds->led[i].leds = leds; leds->led[i].cdev.name = name; leds->led[i].cdev.default_trigger = trig; leds->led[i].cdev.brightness_set = mc13xxx_led_set;
drivers/leds/leds-mc13783.c static int __init mc13xxx_led_probe(struct platform_device *pdev) · line 192
Quoted 6 lines
drivers/leds/leds-mc13783.c +1
-2@@ -200,10 +189,9 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)INIT_WORK (&leds->led[i].work, mc13xxx_led_work); - ret =led_classdev_register (pdev->dev.parent, - &leds->led[i].cdev); + ret =led_classdev_register (dev, &leds->led[i].cdev);
Is this correct changing? I think it should be
ret = led_classdev_register(dev->parent, &leds->led[i].cdev);
Besides this, this patch is good to me.
Thanks,
-Bryan
Quoted 80 lines
drivers/leds/leds-mc13783.c +13
-3if (ret) { -dev_err (&pdev->dev,"Failed to register LED %i\n" , id); +dev_err (dev,"Failed to register LED %i\n" , id);break ; } }@@ -219,8 +207,8 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)static int mc13xxx_led_remove (struct platform_device *pdev) { -struct mc13xxx *mcdev =dev_get_drvdata (pdev->dev.parent);struct mc13xxx_leds *leds =platform_get_drvdata (pdev); +struct mc13xxx *mcdev = leds->master;int i;for (i =0 ; i < leds->num_leds; i++) {@@ -229,7 +217,7 @@ static int mc13xxx_led_remove(struct platform_device *pdev) }for (i =0 ; i < leds->devtype->num_regs; i++) -mc13xxx_reg_write (mcdev,MC13XXX_REG_LED_CONTROL (i),0 ); +mc13xxx_reg_write (mcdev, leds->devtype->ledctrl_base + i,0 );return 0 ; }@@ -238,17 +226,27 @@ static const struct mc13xxx_led_devtype mc13783_led_devtype = { .led_min = MC13783_LED_MD, .led_max = MC13783_LED_B3, .num_regs = 6, + .ledctrl_base = 51, };static const struct mc13xxx_led_devtype mc13892_led_devtype = { .led_min =MC13892_LED_MD , .led_max =MC13892_LED_B , .num_regs =4 , + .ledctrl_base =51 , +}; + +static const struct mc13xxx_led_devtype mc34708_led_devtype = { + .led_min =MC34708_LED_R , + .led_max =MC34708_LED_G , + .num_regs =1 , + .ledctrl_base =54 , };static const struct platform_device_id mc13xxx_led_id_table[] = { {"mc13783-led" , (kernel_ulong_t)&mc13783_led_devtype, }, {"mc13892-led" , (kernel_ulong_t)&mc13892_led_devtype, }, + {"mc34708-led" , (kernel_ulong_t)&mc34708_led_devtype, }, { } };MODULE_DEVICE_TABLE (platform, mc13xxx_led_id_table);include/linux/mfd/mc13xxx.h +6
-1@@ -106,6 +106,9 @@ enum {MC13892_LED_R ,MC13892_LED_G ,MC13892_LED_B , +/* MC34708 LED IDs */ +MC34708_LED_R , + MC34708_LED_G, }; struct mc13xxx_led_platform_data {@@ -165,6 +168,9 @@ struct mc13xxx_leds_platform_data {#define MC13892_LED_C2_CURRENT_G (x) (((x) & 0x7) << 21)/* MC13892 LED Control 3 */ #define MC13892_LED_C3_CURRENT_B (x) (((x) & 0x7) << 9) +/* MC34708 LED Control 0 */ +#define MC34708_LED_C0_CURRENT_R (x) (((x) & 0x3) << 9) +#define MC34708_LED_C0_CURRENT_G (x) (((x) & 0x3) << 21)u32 led_control[MAX_LED_CONTROL_REGS ]; }; --1.8.3.2
Re: [PATCH 2/5] leds: leds-mc13783: Use LED core PM functions
In reply to Alexander ShiyanQuoted 10 lines · Alexander Shiyan
Signed-off-by Alexander Shiyan <[email protected]>--- drivers/leds/leds-mc13783.c | 1 + 1 file changed, 1 insertion(+)drivers/leds/leds-mc13783.c +0
-0
drivers/leds/leds-mc13783.c static int __init mc13xxx_led_probe(struct platform_device *pdev) · line 187
Quoted 4 lines
drivers/leds/leds-mc13783.c +1
-0@@ -184,6 +184,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev) leds->led[i].leds = leds; leds->led[i].cdev.name = name; leds->led[i].cdev.default_trigger = trig; + leds->led[i].cdev.flags |=LED_CORE_SUSPENDRESUME ;
Looks good, I will merge that later.
-Bryan
Quoted 6 lines
drivers/leds/leds-mc13783.c +0
-1leds->led[i].cdev.brightness_set = mc13xxx_led_set; leds->led[i].cdev.brightness =LED_OFF ; --1.8.3.2
Re: [PATCH 2/5] leds: leds-mc13783: Use LED core PM functions
Quoted 6 lines · Alexander Shiyan
Quoted 5 lines
Signed-off-by Alexander Shiyan <[email protected]>--- drivers/leds/leds-mc13783.c | 1 + 1 file changed, 1 insertion(+)
Quoted 11 lines
drivers/leds/leds-mc13783.c static int __init mc13xxx_led_probe(struct platform_device *pdev) · line 187
Quoted 9 lines
drivers/leds/leds-mc13783.c +1
-0@@ -184,6 +184,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev) leds->led[i].leds = leds; leds->led[i].cdev.name = name; leds->led[i].cdev.default_trigger = trig; + leds->led[i].cdev.flags |=LED_CORE_SUSPENDRESUME ;Looks good, I will merge that later.
Now I see useless "|" (OR) in assignment. Can you drop it during merge?
---
Re: [PATCH 2/5] leds: leds-mc13783: Use LED core PM functions
Quoted 18 lines · Alexander Shiyan
Quoted 6 lines · Alexander Shiyan
Quoted 5 lines
Signed-off-by Alexander Shiyan <[email protected]>--- drivers/leds/leds-mc13783.c | 1 + 1 file changed, 1 insertion(+)Quoted 11 lines
drivers/leds/leds-mc13783.c static int __init mc13xxx_led_probe(struct platform_device *pdev) · line 187
Quoted 9 lines
drivers/leds/leds-mc13783.c +1
-0@@ -184,6 +184,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev) leds->led[i].leds = leds; leds->led[i].cdev.name = name; leds->led[i].cdev.default_trigger = trig; + leds->led[i].cdev.flags |=LED_CORE_SUSPENDRESUME ;Looks good, I will merge that later.
Quoted 2 lines
Now I see useless "|" (OR) in assignment. Can you drop it during merge?
Sure, please update this patchset. I will review it later.
-Bryan
Hello.
Quoted 5 lines · Alexander Shiyan
Quoted 4 lines
This patch adds support for two LEDs on MC34708 PMIC.
Signed-off-by Alexander Shiyan <[email protected]>---
...
Quoted 4 lines
Quoted 4 lines
drivers/leds/leds-mc13783.c +0
-0
...
Quoted 8 lines
drivers/leds/leds-mc13783.c static int __init mc13xxx_led_probe(struct platform_device *pdev) · line 192
Quoted 3 lines
drivers/leds/leds-mc13783.c +1
-2- ret =led_classdev_register (pdev->dev.parent, - &leds->led[i].cdev); + ret =led_classdev_register (dev, &leds->led[i].cdev);Is this correct changing? I think it should be
ret =led_classdev_register(dev->parent, &leds->led[i].cdev);Besides this, this patch is good to me.
Yes. LEDs parent should be our new platform device i.e. &pdev->dev, not the mc13xxx MFD core device. I think it was a typo initially. Is not it?
Thanks.
---
Re: [PATCH 3/5] leds: leds-mc13783: Use proper "max_brightness" value for LEDs
In reply to Alexander ShiyanQuoted 29 lines · Alexander Shiyan
Instead of using maximum value of 255 and shift it to appropriate LED duty cycle, this patch introduce a helper to use proper maximum value for each LED.
Signed-off-by Alexander Shiyan <[email protected]>--- drivers/leds/leds-mc13783.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-)drivers/leds/leds-mc13783.c +12
-0@@ -45,11 +45,35 @@ struct mc13xxx_leds {struct mc13xxx_led led[0 ]; }; +static unsigned int mc13xxx_max_brightness (int id) +{ +switch (id) { +case MC13783_LED_MD : +case MC13783_LED_AD : +case MC13783_LED_KP : +return 0x0f ; +case MC13783_LED_R1 : +case MC13783_LED_G1 : +case MC13783_LED_B1 : +case MC13783_LED_R2 : +case MC13783_LED_G2 :
drivers/leds/leds-mc13783.c struct mc13xxx_leds { · line 69
Quoted 10 lines
drivers/leds/leds-mc13783.c +10
-0+case MC13783_LED_B2 : +case MC13783_LED_R3 : +case MC13783_LED_G3 : +case MC13783_LED_B3 : +return 0x1f ; +default : +break ; + } + +return 0x3f ;
I think we can do this:
if (id >= MC13783_LED_MD && id <= MC13783_LED_KP)
return 0x0f;
else if (id >= MC13783_LED_R1 && id <= MC13783_LED_B3)
return 0x1f;
else
return 0x3f;Thanks,
-Bryan
Quoted 74 lines
drivers/leds/leds-mc13783.c +6
-14+} +static void mc13xxx_led_work (struct work_struct *work) { struct mc13xxx_led *led = container_of(work, struct mc13xxx_led, work);struct mc13xxx_leds *leds = led->leds; -unsigned int reg, mask, value, bank, off, shift; +unsigned int reg, bank, off, shift;switch (led->id) {case MC13783_LED_MD :@@ -57,8 +81,6 @@ static void mc13xxx_led_work(struct work_struct *work)case MC13783_LED_KP : reg =2 ; shift =9 + (led->id -MC13783_LED_MD ) *4 ; - mask =0x0f ; - value = led->new_brightness >>4 ;break ;case MC13783_LED_R1 :case MC13783_LED_G1 :@@ -73,16 +95,12 @@ static void mc13xxx_led_work(struct work_struct *work) bank = off /3 ; reg =3 + bank; shift = (off - bank *3 ) *5 +6 ; - value = led->new_brightness >>3 ; - mask =0x1f ;break ;case MC13892_LED_MD :case MC13892_LED_AD :case MC13892_LED_KP : reg = (led->id -MC13892_LED_MD ) /2 ; shift =3 + (led->id -MC13892_LED_MD ) *12 ; - mask =0x3f ; - value = led->new_brightness >>2 ;break ;case MC13892_LED_R :case MC13892_LED_G :@@ -91,22 +109,19 @@ static void mc13xxx_led_work(struct work_struct *work) bank = off /2 ; reg =2 + bank; shift = (off - bank *2 ) *12 +3 ; - value = led->new_brightness >>2 ; - mask =0x3f ;break ;case MC34708_LED_R :case MC34708_LED_G : reg =0 ; shift =3 + (led->id -MC34708_LED_R ) *12 ; - value = led->new_brightness >>2 ; - mask =0x3f ;break ;default :BUG (); }mc13xxx_reg_rmw (leds->master, leds->devtype->ledctrl_base + reg, - mask << shift, value << shift); +mc13xxx_max_brightness (led->id) << shift, + led->new_brightness << shift); } static void mc13xxx_led_set(struct led_classdev *led_cdev,@@ -186,7 +201,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev) leds->led[i].cdev.default_trigger = trig; leds->led[i].cdev.flags |=LED_CORE_SUSPENDRESUME ; leds->led[i].cdev.brightness_set = mc13xxx_led_set; - leds->led[i].cdev.brightness =LED_OFF ; + leds->led[i].cdev.max_brightness =mc13xxx_max_brightness (id);INIT_WORK (&leds->led[i].work, mc13xxx_led_work); --1.8.3.2
Re: [PATCH 4/5] leds: leds-mc13783: Remove unnecessary cleaning of registers on exit
In reply to Alexander ShiyanQuoted 21 lines · Alexander Shiyan
LED core switches each LED to OFF-state on exit, so there is no need for resetting registers.
Signed-off-by Alexander Shiyan <[email protected]>--- drivers/leds/leds-mc13783.c | 4 ---- 1 file changed, 4 deletions(-)drivers/leds/leds-mc13783.c +0
-1@@ -224,7 +224,6 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)static int mc13xxx_led_remove (struct platform_device *pdev) {struct mc13xxx_leds *leds =platform_get_drvdata (pdev); -struct mc13xxx *mcdev = leds->master;int i;for (i =0 ; i < leds->num_leds; i++) {
drivers/leds/leds-mc13783.c static int mc13xxx_led_remove(struct platform_device *pdev) · line 237
Quoted 6 lines
drivers/leds/leds-mc13783.c +0
-3@@ -232,9 +231,6 @@ static int mc13xxx_led_remove(struct platform_device *pdev)cancel_work_sync (&leds->led[i].work); } -for (i =0 ; i < leds->devtype->num_regs; i++) -mc13xxx_reg_write (mcdev, leds->devtype->ledctrl_base + i,0 ); -
This one looks good to me,
-Bryan
Quoted 6 lines
drivers/leds/leds-mc13783.c +0
-1return 0 ; } --1.8.3.2