2020-08-06 06:52:55 +00:00
|
|
|
From e190f57df3c7e7713687905c14e72fbcbd81c5e4 Mon Sep 17 00:00:00 2001
|
|
|
|
From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <noltari@gmail.com>
|
|
|
|
Date: Thu, 4 Jun 2020 15:59:05 +0200
|
|
|
|
Subject: [PATCH] leds-bcm6328: support second hw blinking interval
|
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
Right now the driver uses only 3 LED modes:
|
|
|
|
0: On
|
|
|
|
1: HW Blinking (Interval 1)
|
|
|
|
3: Off
|
|
|
|
|
|
|
|
However, the controller supports a second HW blinking interval, which results
|
|
|
|
in 4 possible LED modes:
|
|
|
|
0: On
|
|
|
|
1: HW Blinking (Interval 1)
|
|
|
|
2: HW Blinking (Interval 2)
|
|
|
|
3: Off
|
|
|
|
|
|
|
|
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
|
|
|
|
Signed-off-by: Pavel Machek <pavel@ucw.cz>
|
|
|
|
---
|
|
|
|
drivers/leds/leds-bcm6328.c | 97 ++++++++++++++++++++++++++++---------
|
|
|
|
1 file changed, 75 insertions(+), 22 deletions(-)
|
|
|
|
|
2020-05-19 08:55:42 +00:00
|
|
|
--- a/drivers/leds/leds-bcm6328.c
|
|
|
|
+++ b/drivers/leds/leds-bcm6328.c
|
2020-08-06 06:52:55 +00:00
|
|
|
@@ -24,12 +24,17 @@
|
2020-05-19 08:55:42 +00:00
|
|
|
|
|
|
|
#define BCM6328_LED_MAX_COUNT 24
|
|
|
|
#define BCM6328_LED_DEF_DELAY 500
|
2020-08-06 06:52:55 +00:00
|
|
|
-#define BCM6328_LED_INTERVAL_MS 20
|
2020-05-19 08:55:42 +00:00
|
|
|
|
2020-08-06 06:52:55 +00:00
|
|
|
-#define BCM6328_LED_INTV_MASK 0x3f
|
2020-05-19 08:55:42 +00:00
|
|
|
-#define BCM6328_LED_FAST_INTV_SHIFT 6
|
|
|
|
-#define BCM6328_LED_FAST_INTV_MASK (BCM6328_LED_INTV_MASK << \
|
|
|
|
- BCM6328_LED_FAST_INTV_SHIFT)
|
2020-08-06 06:52:55 +00:00
|
|
|
+#define BCM6328_LED_BLINK_DELAYS 2
|
|
|
|
+#define BCM6328_LED_BLINK_MS 20
|
|
|
|
+
|
|
|
|
+#define BCM6328_LED_BLINK_MASK 0x3f
|
|
|
|
+#define BCM6328_LED_BLINK1_SHIFT 0
|
|
|
|
+#define BCM6328_LED_BLINK1_MASK (BCM6328_LED_BLINK_MASK << \
|
|
|
|
+ BCM6328_LED_BLINK1_SHIFT)
|
|
|
|
+#define BCM6328_LED_BLINK2_SHIFT 6
|
|
|
|
+#define BCM6328_LED_BLINK2_MASK (BCM6328_LED_BLINK_MASK << \
|
|
|
|
+ BCM6328_LED_BLINK2_SHIFT)
|
2020-05-19 08:55:42 +00:00
|
|
|
#define BCM6328_SERIAL_LED_EN BIT(12)
|
|
|
|
#define BCM6328_SERIAL_LED_MUX BIT(13)
|
|
|
|
#define BCM6328_SERIAL_LED_CLK_NPOL BIT(14)
|
2020-08-06 06:52:55 +00:00
|
|
|
@@ -45,8 +50,8 @@
|
2020-05-19 08:55:42 +00:00
|
|
|
|
|
|
|
#define BCM6328_LED_MODE_MASK 3
|
|
|
|
#define BCM6328_LED_MODE_ON 0
|
|
|
|
-#define BCM6328_LED_MODE_FAST 1
|
|
|
|
-#define BCM6328_LED_MODE_BLINK 2
|
2020-08-06 06:52:55 +00:00
|
|
|
+#define BCM6328_LED_MODE_BLINK1 1
|
|
|
|
+#define BCM6328_LED_MODE_BLINK2 2
|
2020-05-19 08:55:42 +00:00
|
|
|
#define BCM6328_LED_MODE_OFF 3
|
|
|
|
#define BCM6328_LED_SHIFT(X) ((X) << 1)
|
|
|
|
|
2020-08-06 06:52:55 +00:00
|
|
|
@@ -127,12 +132,18 @@ static void bcm6328_led_set(struct led_c
|
2020-05-19 08:55:42 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(led->lock, flags);
|
|
|
|
- *(led->blink_leds) &= ~BIT(led->pin);
|
|
|
|
+
|
|
|
|
+ /* Remove LED from cached HW blinking intervals */
|
|
|
|
+ led->blink_leds[0] &= ~BIT(led->pin);
|
|
|
|
+ led->blink_leds[1] &= ~BIT(led->pin);
|
|
|
|
+
|
|
|
|
+ /* Set LED on/off */
|
|
|
|
if ((led->active_low && value == LED_OFF) ||
|
|
|
|
(!led->active_low && value != LED_OFF))
|
|
|
|
bcm6328_led_mode(led, BCM6328_LED_MODE_ON);
|
|
|
|
else
|
|
|
|
bcm6328_led_mode(led, BCM6328_LED_MODE_OFF);
|
|
|
|
+
|
|
|
|
spin_unlock_irqrestore(led->lock, flags);
|
|
|
|
}
|
|
|
|
|
2020-08-06 06:52:55 +00:00
|
|
|
@@ -140,8 +151,8 @@ static unsigned long bcm6328_blink_delay
|
|
|
|
{
|
|
|
|
unsigned long bcm6328_delay;
|
|
|
|
|
|
|
|
- bcm6328_delay = delay + BCM6328_LED_INTERVAL_MS / 2;
|
|
|
|
- bcm6328_delay = bcm6328_delay / BCM6328_LED_INTERVAL_MS;
|
|
|
|
+ bcm6328_delay = delay + BCM6328_LED_BLINK_MS / 2;
|
|
|
|
+ bcm6328_delay = bcm6328_delay / BCM6328_LED_BLINK_MS;
|
|
|
|
if (bcm6328_delay == 0)
|
|
|
|
bcm6328_delay = 1;
|
|
|
|
|
|
|
|
@@ -168,28 +179,68 @@ static int bcm6328_blink_set(struct led_
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (delay > BCM6328_LED_INTV_MASK) {
|
|
|
|
+ if (delay > BCM6328_LED_BLINK_MASK) {
|
|
|
|
dev_dbg(led_cdev->dev,
|
|
|
|
"fallback to soft blinking (delay > %ums)\n",
|
|
|
|
- BCM6328_LED_INTV_MASK * BCM6328_LED_INTERVAL_MS);
|
|
|
|
+ BCM6328_LED_BLINK_MASK * BCM6328_LED_BLINK_MS);
|
|
|
|
return -EINVAL;
|
2020-05-19 08:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(led->lock, flags);
|
|
|
|
- if (*(led->blink_leds) == 0 ||
|
|
|
|
- *(led->blink_leds) == BIT(led->pin) ||
|
|
|
|
- *(led->blink_delay) == delay) {
|
|
|
|
+ /*
|
|
|
|
+ * Check if any of the two configurable HW blinking intervals is
|
|
|
|
+ * available:
|
|
|
|
+ * 1. No LEDs assigned to the HW blinking interval.
|
2020-08-06 06:52:55 +00:00
|
|
|
+ * 2. Only this LED is assigned to the HW blinking interval.
|
|
|
|
+ * 3. LEDs with the same delay assigned.
|
2020-05-19 08:55:42 +00:00
|
|
|
+ */
|
|
|
|
+ if (led->blink_leds[0] == 0 ||
|
|
|
|
+ led->blink_leds[0] == BIT(led->pin) ||
|
|
|
|
+ led->blink_delay[0] == delay) {
|
2020-08-06 06:52:55 +00:00
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
- *(led->blink_leds) |= BIT(led->pin);
|
|
|
|
- *(led->blink_delay) = delay;
|
2020-05-19 08:55:42 +00:00
|
|
|
+ /* Add LED to the first HW blinking interval cache */
|
|
|
|
+ led->blink_leds[0] |= BIT(led->pin);
|
|
|
|
+
|
|
|
|
+ /* Remove LED from the second HW blinking interval cache */
|
|
|
|
+ led->blink_leds[1] &= ~BIT(led->pin);
|
2020-08-06 06:52:55 +00:00
|
|
|
|
|
|
|
+ /* Cache first HW blinking interval delay */
|
2020-05-19 08:55:42 +00:00
|
|
|
+ led->blink_delay[0] = delay;
|
|
|
|
+
|
|
|
|
+ /* Update the delay for the first HW blinking interval */
|
2020-08-06 06:52:55 +00:00
|
|
|
val = bcm6328_led_read(led->mem + BCM6328_REG_INIT);
|
|
|
|
- val &= ~BCM6328_LED_FAST_INTV_MASK;
|
|
|
|
- val |= (delay << BCM6328_LED_FAST_INTV_SHIFT);
|
|
|
|
+ val &= ~BCM6328_LED_BLINK1_MASK;
|
|
|
|
+ val |= (delay << BCM6328_LED_BLINK1_SHIFT);
|
|
|
|
bcm6328_led_write(led->mem + BCM6328_REG_INIT, val);
|
|
|
|
|
|
|
|
- bcm6328_led_mode(led, BCM6328_LED_MODE_BLINK);
|
2020-05-19 08:55:42 +00:00
|
|
|
+ /* Set the LED to first HW blinking interval */
|
2020-08-06 06:52:55 +00:00
|
|
|
+ bcm6328_led_mode(led, BCM6328_LED_MODE_BLINK1);
|
2020-05-19 08:55:42 +00:00
|
|
|
+
|
|
|
|
+ rc = 0;
|
|
|
|
+ } else if (led->blink_leds[1] == 0 ||
|
|
|
|
+ led->blink_leds[1] == BIT(led->pin) ||
|
|
|
|
+ led->blink_delay[1] == delay) {
|
2020-08-06 06:52:55 +00:00
|
|
|
+ unsigned long val;
|
|
|
|
+
|
2020-05-19 08:55:42 +00:00
|
|
|
+ /* Remove LED from the first HW blinking interval */
|
|
|
|
+ led->blink_leds[0] &= ~BIT(led->pin);
|
|
|
|
+
|
|
|
|
+ /* Add LED to the second HW blinking interval */
|
|
|
|
+ led->blink_leds[1] |= BIT(led->pin);
|
2020-08-06 06:52:55 +00:00
|
|
|
+
|
|
|
|
+ /* Cache second HW blinking interval delay */
|
2020-05-19 08:55:42 +00:00
|
|
|
+ led->blink_delay[1] = delay;
|
|
|
|
+
|
|
|
|
+ /* Update the delay for the second HW blinking interval */
|
2020-08-06 06:52:55 +00:00
|
|
|
+ val = bcm6328_led_read(led->mem + BCM6328_REG_INIT);
|
|
|
|
+ val &= ~BCM6328_LED_BLINK2_MASK;
|
|
|
|
+ val |= (delay << BCM6328_LED_BLINK2_SHIFT);
|
|
|
|
+ bcm6328_led_write(led->mem + BCM6328_REG_INIT, val);
|
|
|
|
+
|
2020-05-19 08:55:42 +00:00
|
|
|
+ /* Set the LED to second HW blinking interval */
|
2020-08-06 06:52:55 +00:00
|
|
|
+ bcm6328_led_mode(led, BCM6328_LED_MODE_BLINK2);
|
2020-05-19 08:55:42 +00:00
|
|
|
+
|
|
|
|
rc = 0;
|
|
|
|
} else {
|
|
|
|
dev_dbg(led_cdev->dev,
|
2020-08-06 06:52:55 +00:00
|
|
|
@@ -363,11 +414,13 @@ static int bcm6328_leds_probe(struct pla
|
2020-05-19 08:55:42 +00:00
|
|
|
if (!lock)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
- blink_leds = devm_kzalloc(dev, sizeof(*blink_leds), GFP_KERNEL);
|
2020-08-06 06:52:55 +00:00
|
|
|
+ blink_leds = devm_kcalloc(dev, BCM6328_LED_BLINK_DELAYS,
|
2020-05-19 08:55:42 +00:00
|
|
|
+ sizeof(*blink_leds), GFP_KERNEL);
|
|
|
|
if (!blink_leds)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
- blink_delay = devm_kzalloc(dev, sizeof(*blink_delay), GFP_KERNEL);
|
2020-08-06 06:52:55 +00:00
|
|
|
+ blink_delay = devm_kcalloc(dev, BCM6328_LED_BLINK_DELAYS,
|
2020-05-19 08:55:42 +00:00
|
|
|
+ sizeof(*blink_delay), GFP_KERNEL);
|
|
|
|
if (!blink_delay)
|
|
|
|
return -ENOMEM;
|
|
|
|
|