* [PATCH v4 1/4] dt-bindings: leds: bcm63138: Add shift register bits
2024-10-10 14:10 [PATCH v4 0/4] leds: bcm63138: Add some new bindings and code Linus Walleij
@ 2024-10-10 14:10 ` Linus Walleij
2024-10-10 17:58 ` Rob Herring (Arm)
2024-10-10 17:59 ` Florian Fainelli
2024-10-10 14:10 ` [PATCH v4 2/4] leds: bcm63138: Use scopes and guards Linus Walleij
` (3 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Linus Walleij @ 2024-10-10 14:10 UTC (permalink / raw)
To: Pavel Machek, Lee Jones, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, William Zhang, Anand Gore, Kursad Oney,
Florian Fainelli, Rafał Miłecki,
Broadcom internal kernel review list
Cc: linux-leds, devicetree, Linus Walleij
The BCM63138 family of serial LED controllers has a register
where we can set up bits for the shift registers. These are
the number of rounds the bits need to be shifted before all
bits have been shifted through the external shift registers.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v2->v3:
- Mention that HW defaults will be used if the shift
register property is missing.
ChangeLog v1->v2:
- Drop the $ref to u32 since the new property is suffixed
with "-bits" and thus get standard treatment.
---
Documentation/devicetree/bindings/leds/leds-bcm63138.yaml | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml
index bb20394fca5c..62326507c1aa 100644
--- a/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml
+++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml
@@ -41,6 +41,16 @@ properties:
"#size-cells":
const: 0
+ brcm,serial-shift-bits:
+ minimum: 1
+ maximum: 32
+ description:
+ This describes the number of 8-bit serial shifters connected to the LED
+ controller block. The hardware is typically using 8-bit shift registers
+ with 8 LEDs per shift register, so 4 shifters results in 32 LEDs or 2
+ shifters give 16 LEDs etc, but the hardware supports any odd number of
+ registers. If left unspecified, the hardware boot-time default is used.
+
patternProperties:
"^led@[a-f0-9]+$":
type: object
@@ -71,6 +81,7 @@ examples:
leds@ff800800 {
compatible = "brcm,bcm4908-leds", "brcm,bcm63138-leds";
reg = <0xff800800 0xdc>;
+ brcm,serial-shift-bits = <16>;
#address-cells = <1>;
#size-cells = <0>;
--
2.46.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v4 1/4] dt-bindings: leds: bcm63138: Add shift register bits
2024-10-10 14:10 ` [PATCH v4 1/4] dt-bindings: leds: bcm63138: Add shift register bits Linus Walleij
@ 2024-10-10 17:58 ` Rob Herring (Arm)
2024-10-10 17:59 ` Florian Fainelli
1 sibling, 0 replies; 10+ messages in thread
From: Rob Herring (Arm) @ 2024-10-10 17:58 UTC (permalink / raw)
To: Linus Walleij
Cc: William Zhang, Broadcom internal kernel review list, Pavel Machek,
Florian Fainelli, devicetree, Rafał Miłecki,
Conor Dooley, Krzysztof Kozlowski, Anand Gore, Lee Jones,
Kursad Oney, linux-leds
On Thu, 10 Oct 2024 16:10:50 +0200, Linus Walleij wrote:
> The BCM63138 family of serial LED controllers has a register
> where we can set up bits for the shift registers. These are
> the number of rounds the bits need to be shifted before all
> bits have been shifted through the external shift registers.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v2->v3:
> - Mention that HW defaults will be used if the shift
> register property is missing.
> ChangeLog v1->v2:
> - Drop the $ref to u32 since the new property is suffixed
> with "-bits" and thus get standard treatment.
> ---
> Documentation/devicetree/bindings/leds/leds-bcm63138.yaml | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v4 1/4] dt-bindings: leds: bcm63138: Add shift register bits
2024-10-10 14:10 ` [PATCH v4 1/4] dt-bindings: leds: bcm63138: Add shift register bits Linus Walleij
2024-10-10 17:58 ` Rob Herring (Arm)
@ 2024-10-10 17:59 ` Florian Fainelli
1 sibling, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2024-10-10 17:59 UTC (permalink / raw)
To: Linus Walleij, Pavel Machek, Lee Jones, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, William Zhang, Anand Gore,
Kursad Oney, Rafał Miłecki,
Broadcom internal kernel review list
Cc: linux-leds, devicetree
On 10/10/24 07:10, Linus Walleij wrote:
> The BCM63138 family of serial LED controllers has a register
> where we can set up bits for the shift registers. These are
> the number of rounds the bits need to be shifted before all
> bits have been shifted through the external shift registers.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4 2/4] leds: bcm63138: Use scopes and guards
2024-10-10 14:10 [PATCH v4 0/4] leds: bcm63138: Add some new bindings and code Linus Walleij
2024-10-10 14:10 ` [PATCH v4 1/4] dt-bindings: leds: bcm63138: Add shift register bits Linus Walleij
@ 2024-10-10 14:10 ` Linus Walleij
2024-10-10 14:10 ` [PATCH v4 3/4] leds: bcm63138: Handle shift register config Linus Walleij
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Linus Walleij @ 2024-10-10 14:10 UTC (permalink / raw)
To: Pavel Machek, Lee Jones, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, William Zhang, Anand Gore, Kursad Oney,
Florian Fainelli, Rafał Miłecki,
Broadcom internal kernel review list
Cc: linux-leds, devicetree, Linus Walleij
Use scoped helpers and guards to handle DT node iterations
and spinlocks. This cuts some lines of code and eliminates
common mistakes (such as the missing of_node_put()).
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/leds/blink/leds-bcm63138.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/leds/blink/leds-bcm63138.c b/drivers/leds/blink/leds-bcm63138.c
index 3a5e0b98bfbc..374f68f4f277 100644
--- a/drivers/leds/blink/leds-bcm63138.c
+++ b/drivers/leds/blink/leds-bcm63138.c
@@ -2,6 +2,7 @@
/*
* Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
*/
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/leds.h>
@@ -125,17 +126,14 @@ static void bcm63138_leds_brightness_set(struct led_classdev *led_cdev,
{
struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev);
struct bcm63138_leds *leds = led->leds;
- unsigned long flags;
- spin_lock_irqsave(&leds->lock, flags);
+ guard(spinlock_irqsave)(&leds->lock);
bcm63138_leds_enable_led(leds, led, value);
if (!value)
bcm63138_leds_set_flash_rate(leds, led, 0);
else
bcm63138_leds_set_bright(leds, led, value);
-
- spin_unlock_irqrestore(&leds->lock, flags);
}
static int bcm63138_leds_blink_set(struct led_classdev *led_cdev,
@@ -144,7 +142,6 @@ static int bcm63138_leds_blink_set(struct led_classdev *led_cdev,
{
struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev);
struct bcm63138_leds *leds = led->leds;
- unsigned long flags;
u8 value;
if (!*delay_on && !*delay_off) {
@@ -179,13 +176,11 @@ static int bcm63138_leds_blink_set(struct led_classdev *led_cdev,
return -EINVAL;
}
- spin_lock_irqsave(&leds->lock, flags);
+ guard(spinlock_irqsave)(&leds->lock);
bcm63138_leds_enable_led(leds, led, BCM63138_MAX_BRIGHTNESS);
bcm63138_leds_set_flash_rate(leds, led, value);
- spin_unlock_irqrestore(&leds->lock, flags);
-
return 0;
}
@@ -259,7 +254,6 @@ static int bcm63138_leds_probe(struct platform_device *pdev)
struct device_node *np = dev_of_node(&pdev->dev);
struct device *dev = &pdev->dev;
struct bcm63138_leds *leds;
- struct device_node *child;
leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL);
if (!leds)
@@ -280,7 +274,7 @@ static int bcm63138_leds_probe(struct platform_device *pdev)
bcm63138_leds_write(leds, BCM63138_SERIAL_LED_POLARITY, 0);
bcm63138_leds_write(leds, BCM63138_PARALLEL_LED_POLARITY, 0);
- for_each_available_child_of_node(np, child) {
+ for_each_available_child_of_node_scoped(np, child) {
bcm63138_leds_create_led(leds, child);
}
--
2.46.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v4 3/4] leds: bcm63138: Handle shift register config
2024-10-10 14:10 [PATCH v4 0/4] leds: bcm63138: Add some new bindings and code Linus Walleij
2024-10-10 14:10 ` [PATCH v4 1/4] dt-bindings: leds: bcm63138: Add shift register bits Linus Walleij
2024-10-10 14:10 ` [PATCH v4 2/4] leds: bcm63138: Use scopes and guards Linus Walleij
@ 2024-10-10 14:10 ` Linus Walleij
2024-10-10 17:59 ` Florian Fainelli
2024-10-10 14:10 ` [PATCH v4 4/4] leds: bcm63138: Add some register defines Linus Walleij
2024-10-11 7:37 ` [PATCH v4 0/4] leds: bcm63138: Add some new bindings and code Lee Jones
4 siblings, 1 reply; 10+ messages in thread
From: Linus Walleij @ 2024-10-10 14:10 UTC (permalink / raw)
To: Pavel Machek, Lee Jones, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, William Zhang, Anand Gore, Kursad Oney,
Florian Fainelli, Rafał Miłecki,
Broadcom internal kernel review list
Cc: linux-leds, devicetree, Linus Walleij
This adds code to optionally read the width of the shift register
chain from the device tree and use it to set up the register
controlling the shifter hardware.
If the property is not present, the boot-time default is used so
existing device trees keep working as this is what they assume.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/leds/blink/leds-bcm63138.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/leds/blink/leds-bcm63138.c b/drivers/leds/blink/leds-bcm63138.c
index 374f68f4f277..9fe1af156c80 100644
--- a/drivers/leds/blink/leds-bcm63138.c
+++ b/drivers/leds/blink/leds-bcm63138.c
@@ -2,6 +2,7 @@
/*
* Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
*/
+#include <linux/bits.h>
#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/io.h>
@@ -254,6 +255,7 @@ static int bcm63138_leds_probe(struct platform_device *pdev)
struct device_node *np = dev_of_node(&pdev->dev);
struct device *dev = &pdev->dev;
struct bcm63138_leds *leds;
+ u32 shift_bits;
leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL);
if (!leds)
@@ -267,6 +269,12 @@ static int bcm63138_leds_probe(struct platform_device *pdev)
spin_lock_init(&leds->lock);
+ /* If this property is not present, we use boot defaults */
+ if (!of_property_read_u32(np, "brcm,serial-shift-bits", &shift_bits)) {
+ bcm63138_leds_write(leds, BCM63138_SERIAL_LED_SHIFT_SEL,
+ GENMASK(shift_bits - 1, 0));
+ }
+
bcm63138_leds_write(leds, BCM63138_GLB_CTRL,
BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL |
BCM63138_GLB_CTRL_SERIAL_LED_EN_POL);
--
2.46.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v4 3/4] leds: bcm63138: Handle shift register config
2024-10-10 14:10 ` [PATCH v4 3/4] leds: bcm63138: Handle shift register config Linus Walleij
@ 2024-10-10 17:59 ` Florian Fainelli
0 siblings, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2024-10-10 17:59 UTC (permalink / raw)
To: Linus Walleij, Pavel Machek, Lee Jones, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, William Zhang, Anand Gore,
Kursad Oney, Rafał Miłecki,
Broadcom internal kernel review list
Cc: linux-leds, devicetree
On 10/10/24 07:10, Linus Walleij wrote:
> This adds code to optionally read the width of the shift register
> chain from the device tree and use it to set up the register
> controlling the shifter hardware.
>
> If the property is not present, the boot-time default is used so
> existing device trees keep working as this is what they assume.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4 4/4] leds: bcm63138: Add some register defines
2024-10-10 14:10 [PATCH v4 0/4] leds: bcm63138: Add some new bindings and code Linus Walleij
` (2 preceding siblings ...)
2024-10-10 14:10 ` [PATCH v4 3/4] leds: bcm63138: Handle shift register config Linus Walleij
@ 2024-10-10 14:10 ` Linus Walleij
2024-10-10 18:00 ` Florian Fainelli
2024-10-11 7:37 ` [PATCH v4 0/4] leds: bcm63138: Add some new bindings and code Lee Jones
4 siblings, 1 reply; 10+ messages in thread
From: Linus Walleij @ 2024-10-10 14:10 UTC (permalink / raw)
To: Pavel Machek, Lee Jones, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, William Zhang, Anand Gore, Kursad Oney,
Florian Fainelli, Rafał Miłecki,
Broadcom internal kernel review list
Cc: linux-leds, devicetree, Linus Walleij
The Power LUT (Look-up Table) register base was missing, also
add the bit define for sending serial LED data in reverse order,
and use the BIT() macro to define the bits in the control
register.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v3->v4:
- Add define for BCM63138_GLB_CTRL_SERIAL_LED_CLK_POL
- Rename the BCM63138_POWER_LUT to BCM63138_POWER_LUT_BASE0
---
drivers/leds/blink/leds-bcm63138.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/leds/blink/leds-bcm63138.c b/drivers/leds/blink/leds-bcm63138.c
index 9fe1af156c80..ef2e511438cc 100644
--- a/drivers/leds/blink/leds-bcm63138.c
+++ b/drivers/leds/blink/leds-bcm63138.c
@@ -21,8 +21,10 @@
#define BCM63138_LEDS_PER_REG (32 / BCM63138_LED_BITS) /* 8 */
#define BCM63138_GLB_CTRL 0x00
-#define BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL 0x00000002
-#define BCM63138_GLB_CTRL_SERIAL_LED_EN_POL 0x00000008
+#define BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL BIT(1)
+#define BCM63138_GLB_CTRL_SERIAL_LED_CLK_POL BIT(2)
+#define BCM63138_GLB_CTRL_SERIAL_LED_EN_POL BIT(3)
+#define BCM63138_GLB_CTRL_SERIAL_LED_MSB_FIRST BIT(4)
#define BCM63138_MASK 0x04
#define BCM63138_HW_LED_EN 0x08
#define BCM63138_SERIAL_LED_SHIFT_SEL 0x0c
@@ -35,6 +37,7 @@
#define BCM63138_BRIGHT_CTRL3 0x28
#define BCM63138_BRIGHT_CTRL4 0x2c
#define BCM63138_POWER_LED_CFG 0x30
+#define BCM63138_POWER_LUT_BASE0 0x34 /* -> b0 */
#define BCM63138_HW_POLARITY 0xb4
#define BCM63138_SW_DATA 0xb8
#define BCM63138_SW_POLARITY 0xbc
--
2.46.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v4 4/4] leds: bcm63138: Add some register defines
2024-10-10 14:10 ` [PATCH v4 4/4] leds: bcm63138: Add some register defines Linus Walleij
@ 2024-10-10 18:00 ` Florian Fainelli
0 siblings, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2024-10-10 18:00 UTC (permalink / raw)
To: Linus Walleij, Pavel Machek, Lee Jones, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, William Zhang, Anand Gore,
Kursad Oney, Rafał Miłecki,
Broadcom internal kernel review list
Cc: linux-leds, devicetree
On 10/10/24 07:10, Linus Walleij wrote:
> The Power LUT (Look-up Table) register base was missing, also
> add the bit define for sending serial LED data in reverse order,
> and use the BIT() macro to define the bits in the control
> register.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v4 0/4] leds: bcm63138: Add some new bindings and code
2024-10-10 14:10 [PATCH v4 0/4] leds: bcm63138: Add some new bindings and code Linus Walleij
` (3 preceding siblings ...)
2024-10-10 14:10 ` [PATCH v4 4/4] leds: bcm63138: Add some register defines Linus Walleij
@ 2024-10-11 7:37 ` Lee Jones
4 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2024-10-11 7:37 UTC (permalink / raw)
To: Pavel Machek, Lee Jones, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, William Zhang, Anand Gore, Kursad Oney,
Florian Fainelli, Rafał Miłecki,
Broadcom internal kernel review list, Linus Walleij
Cc: linux-leds, devicetree
On Thu, 10 Oct 2024 16:10:49 +0200, Linus Walleij wrote:
> This brings over the few know-how items and little things
> I found about the BCMBCA LEDs in my previous duplicate driver.
>
> This was tested on the BCM6846-based Genexis XG6846B.
>
> The main addition is the ability to define the number shifting
> bits in the serial shift register which is necessary if the
> previous boot stages have not set up the hardware properly
> before.
>
> [...]
Applied, thanks!
[1/4] dt-bindings: leds: bcm63138: Add shift register bits
commit: d19261ffd077609e5d348f1c12894997807a64a8
[2/4] leds: bcm63138: Use scopes and guards
commit: 61574073e15cbaaab3fa1b2ad7df3ffe21e48509
[3/4] leds: bcm63138: Handle shift register config
commit: 5f312fdace9cee3fb8a7964469546fb4d8624ff7
[4/4] leds: bcm63138: Add some register defines
commit: def9c8b7bc0d9d7436cf29eb0106698e356f006d
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 10+ messages in thread