diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-12 07:40:48 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-12 07:40:48 +0300 |
commit | 2c487121e3c4f87e82cff493872675bde52e47fc (patch) | |
tree | c32f72d674c3503cff63063804de6b4e990d9545 /drivers/leds/leds-bcm6328.c | |
parent | d870a9d5e31ea69a1ceb7555d0d79364c442c5c0 (diff) | |
parent | 522f17e1214cf112e62cff56150964d8b68b94b2 (diff) | |
download | linux-2c487121e3c4f87e82cff493872675bde52e47fc.tar.xz |
Merge tag 'leds-for-4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds
Pull LED subsystem updates from Jacek Anaszewski:
"Besides regular driver updates, we introduce a portion of LED core
improvements, that allow to avoid the need for using work queues in
the LED class drivers, that set brightness in a blocking way.
Affected LED class drivers are being optimized accordingly.
- LED core improvements:
- use EXPORT_SYMBOL_GPL consistently,
- add two new LED_BLINK_ flags,
- rename brightness_set_sync op to brightness_set_blocking,
- add led_set_brightness_nosleep{nopm} functions,
- use set_brightness_work for the blocking op,
- drivers shouldn't enforce SYNC/ASYNC brightness setting,
- turn off the LED and wait for completion on unregistering LED
class device,
- add managed version of led_trigger_register,
- add description of brightness setting API to the LED class doc.
- Remove work queues from drivers: leds-tlc591xx, leds-88pm860x, leds-adp5520,
leds-bd2802, leds-blinkm, leds-lm3533, leds-lm3642, leds-pca9532,
leds-lp3944, leds-lp55xx, leds-lp8788, leds-lp8860, leds-pca955x,
leds-pca963x, leds-wm831x, leds-da903x, leds-da9052, leds-dac124d085,
leds-lt3593, leds-max8997, leds-mc13783, leds-regulator, leds-wm8350,
leds-max77693, leds-aat1290, leds-ktd2692, leds-gpio, leds-pwm,
leds-lm355x, leds-ns2.
- Replace brightness_set op with a new brightness_set_blocking op to
make the drivers compatible with led triggers: leds-ipaq-micro,
leds-powernv.
- Add missing of_node_put: leds-ktd2692, leds-aat1290, leds-max77693.
- Make the driver explicitly non-modular: ledtrig-cpu,
ledtrig-ide-disk, leds-syscon.
- Improvements to leds-bcm6328:
- reuse bcm6328_led_set() instead of copying its functionality,
- swap LED ON and OFF definitions,
- improve blink support,
- simplify duplicated unlock in bcm6328_blink_set,
- add little endian support,
- remove unneded lock when checking initial LED status,
- add HAS_IOMEM dependency,
- code cleaning.
- Improvements to leds-bcm6358:
- use bcm6358_led_set() in order to get rid of the lock,
- merge bcm6358_led_mode and bcm6358_led_set,
- add little endian support,
- remove unneded lock when checking initial LED status,
- add HAS_IOMEM dependency,
- remove unneeded busy status check.
- Call led_pwm_set() in leds-pwm to enforce default LED_OFF.
- Fix duration to be msec instead of jiffies: ledtrig-transient.
- Removing NULL check: leds-powernv.
- Use platform_register/unregister_drivers(): leds-sunfire.
- Fix module license specification: ledtrig-oneshot.
- Fix driver description and make license match the header: leds-pwm.
- Remove checking for state < 1 in flash_strobe_store():
led-class-flash.
- Use led_set_brightness_sync for torch brightness:
v4l2-flash-led-class"
* tag 'leds-for-4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds: (68 commits)
leds: add HAS_IOMEM dependency to LEDS_BCM6328/LEDS_BCM6358
leds: core: add managed version of led_trigger_register
leds: bcm6358: remove unneeded busy status check
leds: bcm6328: improve blink support
leds: bcm6358: merge bcm6358_led_mode and bcm6358_led_set
leds: bcm6328: simplify duplicated unlock in bcm6328_blink_set
leds: bcm6358: add little endian support
leds: bcm6328: add little endian support
leds: bcm6358: remove unneded lock when checking initial LED status
leds: bcm6358: Use bcm6358_led_set() in order to get rid of the lock
leds: bcm6328: remove unneded lock when checking initial LED
leds: bcm6328: code cleaning
leds: syscon: Make the driver explicitly non-modular
leds: ledtrig-ide-disk: Make the driver explicitly non-modular
leds: ledtrig-cpu: Make the driver explicitly non-modular
leds: sunfire: Use platform_register/unregister_drivers()
leds: max77693: Add missing of_node_put
leds: aat1290: Add missing of_node_put
leds: powernv: Implement brightness_set_blocking op
leds: ipaq-micro: Implement brightness_set_blocking op
...
Diffstat (limited to 'drivers/leds/leds-bcm6328.c')
-rw-r--r-- | drivers/leds/leds-bcm6328.c | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/drivers/leds/leds-bcm6328.c b/drivers/leds/leds-bcm6328.c index c7ea5c626331..1548259297c1 100644 --- a/drivers/leds/leds-bcm6328.c +++ b/drivers/leds/leds-bcm6328.c @@ -42,16 +42,16 @@ #define BCM6328_LED_SHIFT_TEST BIT(30) #define BCM6328_LED_TEST BIT(31) #define BCM6328_INIT_MASK (BCM6328_SERIAL_LED_EN | \ - BCM6328_SERIAL_LED_MUX | \ + BCM6328_SERIAL_LED_MUX | \ BCM6328_SERIAL_LED_CLK_NPOL | \ BCM6328_SERIAL_LED_DATA_PPOL | \ BCM6328_SERIAL_LED_SHIFT_DIR) #define BCM6328_LED_MODE_MASK 3 -#define BCM6328_LED_MODE_OFF 0 +#define BCM6328_LED_MODE_ON 0 #define BCM6328_LED_MODE_FAST 1 #define BCM6328_LED_MODE_BLINK 2 -#define BCM6328_LED_MODE_ON 3 +#define BCM6328_LED_MODE_OFF 3 #define BCM6328_LED_SHIFT(X) ((X) << 1) /** @@ -76,12 +76,20 @@ struct bcm6328_led { static void bcm6328_led_write(void __iomem *reg, unsigned long data) { +#ifdef CONFIG_CPU_BIG_ENDIAN iowrite32be(data, reg); +#else + writel(data, reg); +#endif } static unsigned long bcm6328_led_read(void __iomem *reg) { +#ifdef CONFIG_CPU_BIG_ENDIAN return ioread32be(reg); +#else + return readl(reg); +#endif } /** @@ -126,34 +134,45 @@ static void bcm6328_led_set(struct led_classdev *led_cdev, *(led->blink_leds) &= ~BIT(led->pin); if ((led->active_low && value == LED_OFF) || (!led->active_low && value != LED_OFF)) - bcm6328_led_mode(led, BCM6328_LED_MODE_OFF); - else bcm6328_led_mode(led, BCM6328_LED_MODE_ON); + else + bcm6328_led_mode(led, BCM6328_LED_MODE_OFF); spin_unlock_irqrestore(led->lock, flags); } +static unsigned long bcm6328_blink_delay(unsigned long delay) +{ + unsigned long bcm6328_delay; + + bcm6328_delay = delay + BCM6328_LED_INTERVAL_MS / 2; + bcm6328_delay = bcm6328_delay / BCM6328_LED_INTERVAL_MS; + if (bcm6328_delay == 0) + bcm6328_delay = 1; + + return bcm6328_delay; +} + static int bcm6328_blink_set(struct led_classdev *led_cdev, unsigned long *delay_on, unsigned long *delay_off) { struct bcm6328_led *led = container_of(led_cdev, struct bcm6328_led, cdev); unsigned long delay, flags; + int rc; if (!*delay_on) *delay_on = BCM6328_LED_DEF_DELAY; if (!*delay_off) *delay_off = BCM6328_LED_DEF_DELAY; - if (*delay_on != *delay_off) { + delay = bcm6328_blink_delay(*delay_on); + if (delay != bcm6328_blink_delay(*delay_off)) { dev_dbg(led_cdev->dev, "fallback to soft blinking (delay_on != delay_off)\n"); return -EINVAL; } - delay = *delay_on / BCM6328_LED_INTERVAL_MS; - if (delay == 0) - delay = 1; - else if (delay > BCM6328_LED_INTV_MASK) { + if (delay > BCM6328_LED_INTV_MASK) { dev_dbg(led_cdev->dev, "fallback to soft blinking (delay > %ums)\n", BCM6328_LED_INTV_MASK * BCM6328_LED_INTERVAL_MS); @@ -175,16 +194,15 @@ static int bcm6328_blink_set(struct led_classdev *led_cdev, bcm6328_led_write(led->mem + BCM6328_REG_INIT, val); bcm6328_led_mode(led, BCM6328_LED_MODE_BLINK); - - spin_unlock_irqrestore(led->lock, flags); + rc = 0; } else { - spin_unlock_irqrestore(led->lock, flags); dev_dbg(led_cdev->dev, "fallback to soft blinking (delay already set)\n"); - return -EINVAL; + rc = -EINVAL; } + spin_unlock_irqrestore(led->lock, flags); - return 0; + return rc; } static int bcm6328_hwled(struct device *dev, struct device_node *nc, u32 reg, @@ -264,7 +282,6 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg, unsigned long *blink_leds, unsigned long *blink_delay) { struct bcm6328_led *led; - unsigned long flags; const char *state; int rc; @@ -286,7 +303,6 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg, "linux,default-trigger", NULL); - spin_lock_irqsave(lock, flags); if (!of_property_read_string(nc, "default-state", &state)) { if (!strcmp(state, "on")) { led->cdev.brightness = LED_FULL; @@ -303,8 +319,8 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg, val = bcm6328_led_read(mode) >> BCM6328_LED_SHIFT(shift % 16); val &= BCM6328_LED_MODE_MASK; - if ((led->active_low && val == BCM6328_LED_MODE_ON) || - (!led->active_low && val == BCM6328_LED_MODE_OFF)) + if ((led->active_low && val == BCM6328_LED_MODE_OFF) || + (!led->active_low && val == BCM6328_LED_MODE_ON)) led->cdev.brightness = LED_FULL; else led->cdev.brightness = LED_OFF; @@ -315,12 +331,7 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg, led->cdev.brightness = LED_OFF; } - if ((led->active_low && led->cdev.brightness == LED_FULL) || - (!led->active_low && led->cdev.brightness == LED_OFF)) - bcm6328_led_mode(led, BCM6328_LED_MODE_ON); - else - bcm6328_led_mode(led, BCM6328_LED_MODE_OFF); - spin_unlock_irqrestore(lock, flags); + bcm6328_led_set(&led->cdev, led->cdev.brightness); led->cdev.brightness_set = bcm6328_led_set; led->cdev.blink_set = bcm6328_blink_set; @@ -341,7 +352,7 @@ static int bcm6328_leds_probe(struct platform_device *pdev) struct device_node *child; struct resource *mem_r; void __iomem *mem; - spinlock_t *lock; + spinlock_t *lock; /* memory lock */ unsigned long val, *blink_leds, *blink_delay; mem_r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |