mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 03:10:12 +00:00
leds: leds-mc13783: Use proper "max_brightness" value fo LEDs
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 <shc_work@mail.ru> Signed-off-by: Bryan Wu <cooloney@gmail.com>
This commit is contained in:
parent
02e9e11e24
commit
677d13f27e
1 changed files with 14 additions and 13 deletions
|
@ -45,11 +45,21 @@ struct mc13xxx_leds {
|
||||||
struct mc13xxx_led led[0];
|
struct mc13xxx_led led[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static unsigned int mc13xxx_max_brightness(int id)
|
||||||
|
{
|
||||||
|
if (id >= MC13783_LED_MD && id <= MC13783_LED_KP)
|
||||||
|
return 0x0f;
|
||||||
|
else if (id >= MC13783_LED_R1 && id <= MC13783_LED_B3)
|
||||||
|
return 0x1f;
|
||||||
|
|
||||||
|
return 0x3f;
|
||||||
|
}
|
||||||
|
|
||||||
static void mc13xxx_led_work(struct work_struct *work)
|
static void mc13xxx_led_work(struct work_struct *work)
|
||||||
{
|
{
|
||||||
struct mc13xxx_led *led = container_of(work, struct mc13xxx_led, work);
|
struct mc13xxx_led *led = container_of(work, struct mc13xxx_led, work);
|
||||||
struct mc13xxx_leds *leds = led->leds;
|
struct mc13xxx_leds *leds = led->leds;
|
||||||
unsigned int reg, mask, value, bank, off, shift;
|
unsigned int reg, bank, off, shift;
|
||||||
|
|
||||||
switch (led->id) {
|
switch (led->id) {
|
||||||
case MC13783_LED_MD:
|
case MC13783_LED_MD:
|
||||||
|
@ -57,8 +67,6 @@ static void mc13xxx_led_work(struct work_struct *work)
|
||||||
case MC13783_LED_KP:
|
case MC13783_LED_KP:
|
||||||
reg = 2;
|
reg = 2;
|
||||||
shift = 9 + (led->id - MC13783_LED_MD) * 4;
|
shift = 9 + (led->id - MC13783_LED_MD) * 4;
|
||||||
mask = 0x0f;
|
|
||||||
value = led->new_brightness >> 4;
|
|
||||||
break;
|
break;
|
||||||
case MC13783_LED_R1:
|
case MC13783_LED_R1:
|
||||||
case MC13783_LED_G1:
|
case MC13783_LED_G1:
|
||||||
|
@ -73,16 +81,12 @@ static void mc13xxx_led_work(struct work_struct *work)
|
||||||
bank = off / 3;
|
bank = off / 3;
|
||||||
reg = 3 + bank;
|
reg = 3 + bank;
|
||||||
shift = (off - bank * 3) * 5 + 6;
|
shift = (off - bank * 3) * 5 + 6;
|
||||||
value = led->new_brightness >> 3;
|
|
||||||
mask = 0x1f;
|
|
||||||
break;
|
break;
|
||||||
case MC13892_LED_MD:
|
case MC13892_LED_MD:
|
||||||
case MC13892_LED_AD:
|
case MC13892_LED_AD:
|
||||||
case MC13892_LED_KP:
|
case MC13892_LED_KP:
|
||||||
reg = (led->id - MC13892_LED_MD) / 2;
|
reg = (led->id - MC13892_LED_MD) / 2;
|
||||||
shift = 3 + (led->id - MC13892_LED_MD) * 12;
|
shift = 3 + (led->id - MC13892_LED_MD) * 12;
|
||||||
mask = 0x3f;
|
|
||||||
value = led->new_brightness >> 2;
|
|
||||||
break;
|
break;
|
||||||
case MC13892_LED_R:
|
case MC13892_LED_R:
|
||||||
case MC13892_LED_G:
|
case MC13892_LED_G:
|
||||||
|
@ -91,22 +95,19 @@ static void mc13xxx_led_work(struct work_struct *work)
|
||||||
bank = off / 2;
|
bank = off / 2;
|
||||||
reg = 2 + bank;
|
reg = 2 + bank;
|
||||||
shift = (off - bank * 2) * 12 + 3;
|
shift = (off - bank * 2) * 12 + 3;
|
||||||
value = led->new_brightness >> 2;
|
|
||||||
mask = 0x3f;
|
|
||||||
break;
|
break;
|
||||||
case MC34708_LED_R:
|
case MC34708_LED_R:
|
||||||
case MC34708_LED_G:
|
case MC34708_LED_G:
|
||||||
reg = 0;
|
reg = 0;
|
||||||
shift = 3 + (led->id - MC34708_LED_R) * 12;
|
shift = 3 + (led->id - MC34708_LED_R) * 12;
|
||||||
value = led->new_brightness >> 2;
|
|
||||||
mask = 0x3f;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BUG();
|
BUG();
|
||||||
}
|
}
|
||||||
|
|
||||||
mc13xxx_reg_rmw(leds->master, leds->devtype->ledctrl_base + reg,
|
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,
|
static void mc13xxx_led_set(struct led_classdev *led_cdev,
|
||||||
|
@ -186,7 +187,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)
|
||||||
leds->led[i].cdev.default_trigger = trig;
|
leds->led[i].cdev.default_trigger = trig;
|
||||||
leds->led[i].cdev.flags = LED_CORE_SUSPENDRESUME;
|
leds->led[i].cdev.flags = LED_CORE_SUSPENDRESUME;
|
||||||
leds->led[i].cdev.brightness_set = mc13xxx_led_set;
|
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);
|
INIT_WORK(&leds->led[i].work, mc13xxx_led_work);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue