devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] leds: bcm63138: Add some new bindings and code
@ 2024-09-27 22:29 Linus Walleij
  2024-09-27 22:29 ` [PATCH v2 1/4] dt-bindings: leds: bcm63138: Add shift register bits Linus Walleij
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Linus Walleij @ 2024-09-27 22:29 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 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.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
Changes in v2:
- Drop the u32 $ref in the schema, -bits is a standard suffix.
- Fix algorithm for shift register configuration.
- Fix spelling errors and numbering errors.
- Link to v1: https://lore.kernel.org/r/20240920-bcm63138-leds-v1-0-c150871324a0@linaro.org

---
Linus Walleij (4):
      dt-bindings: leds: bcm63138: Add shift register bits
      leds: bcm63138: Use scopes and guards
      leds: bcm63138: Handle shift register config
      leds: bcm63138: Add some register defines

 .../devicetree/bindings/leds/leds-bcm63138.yaml    | 12 ++++++++++
 drivers/leds/blink/leds-bcm63138.c                 | 28 ++++++++++++----------
 2 files changed, 28 insertions(+), 12 deletions(-)
---
base-commit: 5724faee6be4109d7a3168625357e4127f42b5d2
change-id: 20240920-bcm63138-leds-1bc5f41c47cd

Best regards,
-- 
Linus Walleij <linus.walleij@linaro.org>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/4] dt-bindings: leds: bcm63138: Add shift register bits
  2024-09-27 22:29 [PATCH v2 0/4] leds: bcm63138: Add some new bindings and code Linus Walleij
@ 2024-09-27 22:29 ` Linus Walleij
  2024-09-28  8:05   ` Krzysztof Kozlowski
  2024-09-27 22:29 ` [PATCH v2 2/4] leds: bcm63138: Use scopes and guards Linus Walleij
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Linus Walleij @ 2024-09-27 22:29 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 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 | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml
index bb20394fca5c..b3d530c46061 100644
--- a/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml
+++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml
@@ -41,6 +41,17 @@ 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.
+
 patternProperties:
   "^led@[a-f0-9]+$":
     type: object
@@ -71,6 +82,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.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/4] leds: bcm63138: Use scopes and guards
  2024-09-27 22:29 [PATCH v2 0/4] leds: bcm63138: Add some new bindings and code Linus Walleij
  2024-09-27 22:29 ` [PATCH v2 1/4] dt-bindings: leds: bcm63138: Add shift register bits Linus Walleij
@ 2024-09-27 22:29 ` Linus Walleij
  2024-09-27 22:29 ` [PATCH v2 3/4] leds: bcm63138: Handle shift register config Linus Walleij
  2024-09-27 22:29 ` [PATCH v2 4/4] leds: bcm63138: Add some register defines Linus Walleij
  3 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2024-09-27 22:29 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.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/4] leds: bcm63138: Handle shift register config
  2024-09-27 22:29 [PATCH v2 0/4] leds: bcm63138: Add some new bindings and code Linus Walleij
  2024-09-27 22:29 ` [PATCH v2 1/4] dt-bindings: leds: bcm63138: Add shift register bits Linus Walleij
  2024-09-27 22:29 ` [PATCH v2 2/4] leds: bcm63138: Use scopes and guards Linus Walleij
@ 2024-09-27 22:29 ` Linus Walleij
  2024-09-27 22:29 ` [PATCH v2 4/4] leds: bcm63138: Add some register defines Linus Walleij
  3 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2024-09-27 22:29 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.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/4] leds: bcm63138: Add some register defines
  2024-09-27 22:29 [PATCH v2 0/4] leds: bcm63138: Add some new bindings and code Linus Walleij
                   ` (2 preceding siblings ...)
  2024-09-27 22:29 ` [PATCH v2 3/4] leds: bcm63138: Handle shift register config Linus Walleij
@ 2024-09-27 22:29 ` Linus Walleij
  3 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2024-09-27 22:29 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>
---
 drivers/leds/blink/leds-bcm63138.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/blink/leds-bcm63138.c b/drivers/leds/blink/leds-bcm63138.c
index 9fe1af156c80..190d9774164b 100644
--- a/drivers/leds/blink/leds-bcm63138.c
+++ b/drivers/leds/blink/leds-bcm63138.c
@@ -21,8 +21,9 @@
 #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_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 +36,7 @@
 #define BCM63138_BRIGHT_CTRL3				0x28
 #define BCM63138_BRIGHT_CTRL4				0x2c
 #define BCM63138_POWER_LED_CFG				0x30
+#define BCM63138_POWER_LUT				0x34 /* -> b0 */
 #define BCM63138_HW_POLARITY				0xb4
 #define BCM63138_SW_DATA				0xb8
 #define BCM63138_SW_POLARITY				0xbc

-- 
2.46.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/4] dt-bindings: leds: bcm63138: Add shift register bits
  2024-09-27 22:29 ` [PATCH v2 1/4] dt-bindings: leds: bcm63138: Add shift register bits Linus Walleij
@ 2024-09-28  8:05   ` Krzysztof Kozlowski
  2024-10-01 11:18     ` Linus Walleij
  0 siblings, 1 reply; 8+ messages in thread
From: Krzysztof Kozlowski @ 2024-09-28  8:05 UTC (permalink / raw)
  To: Linus Walleij
  Cc: 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, linux-leds, devicetree

On Sat, Sep 28, 2024 at 12:29:47AM +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 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 | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml
> index bb20394fca5c..b3d530c46061 100644
> --- a/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml
> +++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml
> @@ -41,6 +41,17 @@ properties:
>    "#size-cells":
>      const: 0
>  
> +  brcm,serial-shift-bits:

bits is an uint32-array, so you need to limit number of items, e.g.
items:
 - minimum: 1
   maximum: 32

default: [0]? or something else?

> +    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.

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/4] dt-bindings: leds: bcm63138: Add shift register bits
  2024-09-28  8:05   ` Krzysztof Kozlowski
@ 2024-10-01 11:18     ` Linus Walleij
  2024-10-02 19:30       ` Rob Herring
  0 siblings, 1 reply; 8+ messages in thread
From: Linus Walleij @ 2024-10-01 11:18 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: 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, linux-leds, devicetree

On Sat, Sep 28, 2024 at 10:05 AM Krzysztof Kozlowski <krzk@kernel.org> wrote:
> On Sat, Sep 28, 2024 at 12:29:47AM +0200, Linus Walleij wrote:
> > +  brcm,serial-shift-bits:
>
> bits is an uint32-array, so you need to limit number of items, e.g.
> items:
>  - minimum: 1
>    maximum: 32

OK this is what I do on the next lines:

> > +    minimum: 1
> > +    maximum: 32

Am I doing something wrong here? I see you have a dash
  - minimum in your comment but when I grep through the
existing bindings for stuff ending with -bits it seems they
do what I do.

> default: [0]? or something else?

Since we need to stay compatible with older device trees
the default is whatever is in the hardware after boot :/

I guess I could write something about it in the description.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/4] dt-bindings: leds: bcm63138: Add shift register bits
  2024-10-01 11:18     ` Linus Walleij
@ 2024-10-02 19:30       ` Rob Herring
  0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2024-10-02 19:30 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Krzysztof Kozlowski, Pavel Machek, Lee Jones, Krzysztof Kozlowski,
	Conor Dooley, William Zhang, Anand Gore, Kursad Oney,
	Florian Fainelli, Rafał Miłecki,
	Broadcom internal kernel review list, linux-leds, devicetree

On Tue, Oct 01, 2024 at 01:18:29PM +0200, Linus Walleij wrote:
> On Sat, Sep 28, 2024 at 10:05 AM Krzysztof Kozlowski <krzk@kernel.org> wrote:
> > On Sat, Sep 28, 2024 at 12:29:47AM +0200, Linus Walleij wrote:
> > > +  brcm,serial-shift-bits:
> >
> > bits is an uint32-array, so you need to limit number of items, e.g.
> > items:
> >  - minimum: 1
> >    maximum: 32
> 
> OK this is what I do on the next lines:
> 
> > > +    minimum: 1
> > > +    maximum: 32
> 
> Am I doing something wrong here? I see you have a dash
>   - minimum in your comment but when I grep through the
> existing bindings for stuff ending with -bits it seems they
> do what I do.

All the unit suffixes started as single values, but then we found some 
cases with more than 1 (and even a matrix for opp-hz) and had to extend 
them. 

I think what you have here is fine. We can imply it's 1 entry given the 
scalar constraints.

> 
> > default: [0]? or something else?
> 
> Since we need to stay compatible with older device trees
> the default is whatever is in the hardware after boot :/
> 
> I guess I could write something about it in the description.
> 
> Yours,
> Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-10-02 19:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-27 22:29 [PATCH v2 0/4] leds: bcm63138: Add some new bindings and code Linus Walleij
2024-09-27 22:29 ` [PATCH v2 1/4] dt-bindings: leds: bcm63138: Add shift register bits Linus Walleij
2024-09-28  8:05   ` Krzysztof Kozlowski
2024-10-01 11:18     ` Linus Walleij
2024-10-02 19:30       ` Rob Herring
2024-09-27 22:29 ` [PATCH v2 2/4] leds: bcm63138: Use scopes and guards Linus Walleij
2024-09-27 22:29 ` [PATCH v2 3/4] leds: bcm63138: Handle shift register config Linus Walleij
2024-09-27 22:29 ` [PATCH v2 4/4] leds: bcm63138: Add some register defines Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).