public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/5] dm: led: add BCM6328 led support
@ 2017-05-03 13:08 Álvaro Fernández Rojas
  2017-05-03 13:08 ` [U-Boot] [PATCH 1/5] dm: led: add BCM6328 led driver Álvaro Fernández Rojas
                   ` (5 more replies)
  0 siblings, 6 replies; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-03 13:08 UTC (permalink / raw)
  To: u-boot

BCM6328 supports controlling LEDs both by using the GPIO controller and the
LED controller. However, LED controller allows HW blinking and supports serial
LEDs.

Álvaro Fernández Rojas (5):
  dm: led: add BCM6328 led driver
  mips: bmips: add bcm6328-led driver support for BCM6328
  mips: bmips: add bcm6328-led driver support for BCM63268
  mips: bmips: add Comtrend AR-5387un bcm6328-leds
  mips: bmips: add Comtrend VR-3032u bcm6328-leds

 arch/mips/dts/brcm,bcm63268.dtsi        |   9 ++
 arch/mips/dts/brcm,bcm6328.dtsi         |   9 ++
 arch/mips/dts/comtrend,ar-5387un.dts    |  30 ++++
 arch/mips/dts/comtrend,vr-3032u.dts     |  43 ++++++
 configs/comtrend_ar5387un_ram_defconfig |   4 +
 configs/comtrend_vr3032u_ram_defconfig  |   4 +
 drivers/led/Kconfig                     |   7 +
 drivers/led/Makefile                    |   1 +
 drivers/led/led_bcm6328.c               | 262 ++++++++++++++++++++++++++++++++
 9 files changed, 369 insertions(+)
 create mode 100644 drivers/led/led_bcm6328.c

-- 
2.1.4

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

* [U-Boot] [PATCH 1/5] dm: led: add BCM6328 led driver
  2017-05-03 13:08 [U-Boot] [PATCH 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
@ 2017-05-03 13:08 ` Álvaro Fernández Rojas
  2017-05-04 16:50   ` Simon Glass
  2017-05-03 13:08 ` [U-Boot] [PATCH 2/5] mips: bmips: add bcm6328-led driver support for BCM6328 Álvaro Fernández Rojas
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-03 13:08 UTC (permalink / raw)
  To: u-boot

This driver is a simplified version of linux/drivers/leds/leds-bcm6328.c,
simplified to remove HW leds and blink fallbacks.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 drivers/led/Kconfig       |   7 ++
 drivers/led/Makefile      |   1 +
 drivers/led/led_bcm6328.c | 262 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 270 insertions(+)
 create mode 100644 drivers/led/led_bcm6328.c

diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
index 309372a..50b27bd 100644
--- a/drivers/led/Kconfig
+++ b/drivers/led/Kconfig
@@ -9,6 +9,13 @@ config LED
 	  can provide access to board-specific LEDs. Use of the device tree
 	  for configuration is encouraged.
 
+config LED_BCM6328
+	bool "LED Support for BCM6328"
+	depends on LED && ARCH_BMIPS
+	help
+	  This option enables support for LEDs connected to the BCM6328
+	  LED HW controller accessed via MMIO registers.
+
 config LED_BLINK
 	bool "Support LED blinking"
 	depends on LED
diff --git a/drivers/led/Makefile b/drivers/led/Makefile
index 02367fd..d371ed5 100644
--- a/drivers/led/Makefile
+++ b/drivers/led/Makefile
@@ -6,4 +6,5 @@
 #
 
 obj-y += led-uclass.o
+obj-$(CONFIG_LED_BCM6328) += led_bcm6328.o
 obj-$(CONFIG_$(SPL_)LED_GPIO) += led_gpio.o
diff --git a/drivers/led/led_bcm6328.c b/drivers/led/led_bcm6328.c
new file mode 100644
index 0000000..b00640e
--- /dev/null
+++ b/drivers/led/led_bcm6328.c
@@ -0,0 +1,262 @@
+/*
+ * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <led.h>
+#include <asm/io.h>
+#include <dm/lists.h>
+
+#define LEDS_MAX			24
+
+/* LED Init register */
+#define LED_INIT_REG			0x00
+#define LED_INIT_FASTINTV_MS		20
+#define LED_INIT_FASTINTV_SHIFT		6
+#define LED_INIT_FASTINTV_MASK		(0x3f << LED_INIT_FASTINTV_SHIFT)
+#define LED_INIT_SLEDEN_SHIFT		12
+#define LED_INIT_SLEDEN_MASK		(1 << LED_INIT_SLEDEN_SHIFT)
+#define LED_INIT_SLEDMUX_SHIFT		13
+#define LED_INIT_SLEDMUX_MASK		(1 << LED_INIT_SLEDMUX_SHIFT)
+#define LED_INIT_SLEDCLKNPOL_SHIFT	14
+#define LED_INIT_SLEDCLKNPOL_MASK	(1 << LED_INIT_SLEDCLKNPOL_SHIFT)
+#define LED_INIT_SLEDDATAPPOL_SHIFT	15
+#define LED_INIT_SLEDDATANPOL_MASK	(1 << LED_INIT_SLEDDATAPPOL_SHIFT)
+#define LED_INIT_SLEDSHIFTDIR_SHIFT	16
+#define LED_INIT_SLEDSHIFTDIR_MASK	(1 << LED_INIT_SLEDSHIFTDIR_SHIFT)
+
+/* LED Mode registers */
+#define LED_MODE_REG_HI			0x04
+#define LED_MODE_REG_LO			0x08
+#define LED_MODE_ON			0
+#define LED_MODE_FAST			1
+#define LED_MODE_BLINK			2
+#define LED_MODE_OFF			3
+#define LED_MODE_MASK			0x3
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct bcm6328_led_priv {
+	void __iomem *regs;
+	void __iomem *mode;
+	uint8_t shift;
+	bool active_low;
+};
+
+static unsigned long bcm6328_led_get_mode(struct bcm6328_led_priv *priv)
+{
+	return ((readl_be(priv->mode) >> priv->shift) & LED_MODE_MASK);
+}
+
+static int bcm6328_led_set_mode(struct bcm6328_led_priv *priv, uint8_t mode)
+{
+	clrsetbits_be32(priv->mode, (LED_MODE_MASK << priv->shift),
+			(mode << priv->shift));
+
+	return 0;
+}
+
+static enum led_state_t bcm6328_led_get_state(struct udevice *dev)
+{
+	struct bcm6328_led_priv *priv = dev_get_priv(dev);
+	enum led_state_t state = LEDST_OFF;
+
+	switch (bcm6328_led_get_mode(priv)) {
+#ifdef CONFIG_LED_BLINK
+	case LED_MODE_BLINK:
+	case LED_MODE_FAST:
+		state = LEDST_BLINK;
+		break;
+#endif
+	case LED_MODE_OFF:
+		state = (priv->active_low ? LEDST_ON : LEDST_OFF);
+		break;
+	case LED_MODE_ON:
+		state = (priv->active_low ? LEDST_OFF : LEDST_ON);
+		break;
+	}
+
+	return state;
+}
+
+static int bcm6328_led_set_state(struct udevice *dev, enum led_state_t state)
+{
+	struct bcm6328_led_priv *priv = dev_get_priv(dev);
+	unsigned long mode;
+
+	switch (state) {
+#ifdef CONFIG_LED_BLINK
+	case LEDST_BLINK:
+		mode = LED_MODE_BLINK;
+		break;
+#endif
+	case LEDST_OFF:
+		mode = (priv->active_low ? LED_MODE_ON : LED_MODE_OFF);
+		break;
+	case LEDST_ON:
+		mode = (priv->active_low ? LED_MODE_OFF : LED_MODE_ON);
+		break;
+	case LEDST_TOGGLE:
+		if (bcm6328_led_get_state(dev) == LEDST_OFF)
+			return bcm6328_led_set_state(dev, LEDST_ON);
+		else
+			return bcm6328_led_set_state(dev, LEDST_OFF);
+		break;
+	default:
+		return -ENOSYS;
+	}
+
+	return bcm6328_led_set_mode(priv, mode);
+}
+
+#ifdef CONFIG_LED_BLINK
+static unsigned long bcm6328_blink_delay(int delay)
+{
+	unsigned long bcm6328_delay = delay;
+
+	bcm6328_delay += (LED_INIT_FASTINTV_MS / 2);
+	bcm6328_delay /= LED_INIT_FASTINTV_MS;
+	bcm6328_delay <<= LED_INIT_FASTINTV_SHIFT;
+
+	if (bcm6328_delay > LED_INIT_FASTINTV_MASK)
+		return LED_INIT_FASTINTV_MASK;
+	else
+		return bcm6328_delay;
+}
+
+static int bcm6328_led_set_period(struct udevice *dev, int period_ms)
+{
+	struct bcm6328_led_priv *priv = dev_get_priv(dev);
+
+	clrsetbits_be32(priv->regs + LED_INIT_REG, LED_INIT_FASTINTV_MASK,
+			bcm6328_blink_delay(period_ms));
+
+	return 0;
+}
+#endif
+
+static const struct led_ops bcm6328_led_ops = {
+	.get_state = bcm6328_led_get_state,
+	.set_state = bcm6328_led_set_state,
+#ifdef CONFIG_LED_BLINK
+	.set_period = bcm6328_led_set_period,
+#endif
+};
+
+static int bcm6328_led_probe(struct udevice *dev)
+{
+	struct led_uc_plat *uc_plat = dev_get_uclass_platdata(dev);
+	fdt_addr_t addr;
+	fdt_size_t size;
+
+	/* Top-level LED node */
+	if (!uc_plat->label) {
+		void __iomem *regs;
+		u32 set_bits = 0;
+
+		addr = dev_get_addr_size_index(dev, 0, &size);
+		if (addr == FDT_ADDR_T_NONE)
+			return -EINVAL;
+
+		regs = ioremap(addr, size);
+
+		if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
+				"brcm,serial-leds", NULL))
+			set_bits |= LED_INIT_SLEDEN_MASK;
+		if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
+				"brcm,serial-mux", NULL))
+			set_bits |= LED_INIT_SLEDMUX_MASK;
+		if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
+				"brcm,serial-clk-low", NULL))
+			set_bits |= LED_INIT_SLEDCLKNPOL_MASK;
+		if (!fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
+				 "brcm,serial-dat-low", NULL))
+			set_bits |= LED_INIT_SLEDDATANPOL_MASK;
+		if (!fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
+				 "brcm,serial-shift-inv", NULL))
+			set_bits |= LED_INIT_SLEDSHIFTDIR_MASK;
+
+		clrsetbits_be32(regs + LED_INIT_REG, ~0, set_bits);
+	} else {
+		struct bcm6328_led_priv *priv = dev_get_priv(dev);
+		unsigned int pin;
+
+		addr = dev_get_addr_size_index(dev_get_parent(dev), 0, &size);
+		if (addr == FDT_ADDR_T_NONE)
+			return -EINVAL;
+
+		pin = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), "reg",
+				      LEDS_MAX);
+		if (pin >= LEDS_MAX)
+			return -EINVAL;
+
+		priv->regs = ioremap(addr, size);
+		if (pin < 8) {
+			/* LEDs 0-7 (bits 47:32) */
+			priv->mode = priv->regs + LED_MODE_REG_HI;
+			priv->shift = (pin << 1);
+		} else {
+			/* LEDs 8-23 (bits 31:0) */
+			priv->mode = priv->regs + LED_MODE_REG_LO;
+			priv->shift = ((pin - 8) << 1);
+		}
+
+		if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "active-low",
+				NULL))
+			priv->active_low = true;
+	}
+
+	return 0;
+}
+
+static int bcm6328_led_bind(struct udevice *parent)
+{
+	const void *blob = gd->fdt_blob;
+	int node;
+
+	for (node = fdt_first_subnode(blob, dev_of_offset(parent));
+	     node > 0;
+	     node = fdt_next_subnode(blob, node)) {
+		struct led_uc_plat *uc_plat;
+		struct udevice *dev;
+		const char *label;
+		int ret;
+
+		label = fdt_getprop(blob, node, "label", NULL);
+		if (!label) {
+			debug("%s: node %s has no label\n", __func__,
+			      fdt_get_name(blob, node, NULL));
+			return -EINVAL;
+		}
+
+		ret = device_bind_driver_to_node(parent, "bcm6328-led",
+						 fdt_get_name(blob, node, NULL),
+						 node, &dev);
+		if (ret)
+			return ret;
+
+		uc_plat = dev_get_uclass_platdata(dev);
+		uc_plat->label = label;
+	}
+
+	return 0;
+}
+
+static const struct udevice_id bcm6328_led_ids[] = {
+	{ .compatible = "brcm,bcm6328-leds" },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(bcm6328_led) = {
+	.name = "bcm6328-led",
+	.id = UCLASS_LED,
+	.of_match = bcm6328_led_ids,
+	.ops = &bcm6328_led_ops,
+	.bind = bcm6328_led_bind,
+	.probe = bcm6328_led_probe,
+	.priv_auto_alloc_size = sizeof(struct bcm6328_led_priv),
+};
-- 
2.1.4

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

* [U-Boot] [PATCH 2/5] mips: bmips: add bcm6328-led driver support for BCM6328
  2017-05-03 13:08 [U-Boot] [PATCH 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
  2017-05-03 13:08 ` [U-Boot] [PATCH 1/5] dm: led: add BCM6328 led driver Álvaro Fernández Rojas
@ 2017-05-03 13:08 ` Álvaro Fernández Rojas
  2017-05-04 16:50   ` Simon Glass
  2017-05-03 13:08 ` [U-Boot] [PATCH 3/5] mips: bmips: add bcm6328-led driver support for BCM63268 Álvaro Fernández Rojas
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-03 13:08 UTC (permalink / raw)
  To: u-boot

This driver can control up to 24 LEDs and supports HW blinking and serial leds.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 arch/mips/dts/brcm,bcm6328.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/mips/dts/brcm,bcm6328.dtsi b/arch/mips/dts/brcm,bcm6328.dtsi
index 30c2ee8..a5b43ae 100644
--- a/arch/mips/dts/brcm,bcm6328.dtsi
+++ b/arch/mips/dts/brcm,bcm6328.dtsi
@@ -88,6 +88,15 @@
 			status = "disabled";
 		};
 
+		leds: led-controller at 10000800 {
+			compatible = "brcm,bcm6328-leds";
+			reg = <0x10000800 0x24>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			status = "disabled";
+		};
+
 		memory-controller at 10003000 {
 			compatible = "brcm,bcm6328-mc";
 			reg = <0x10003000 0x1000>;
-- 
2.1.4

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

* [U-Boot] [PATCH 3/5] mips: bmips: add bcm6328-led driver support for BCM63268
  2017-05-03 13:08 [U-Boot] [PATCH 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
  2017-05-03 13:08 ` [U-Boot] [PATCH 1/5] dm: led: add BCM6328 led driver Álvaro Fernández Rojas
  2017-05-03 13:08 ` [U-Boot] [PATCH 2/5] mips: bmips: add bcm6328-led driver support for BCM6328 Álvaro Fernández Rojas
@ 2017-05-03 13:08 ` Álvaro Fernández Rojas
  2017-05-04 16:51   ` Simon Glass
  2017-05-03 13:08 ` [U-Boot] [PATCH 4/5] mips: bmips: add Comtrend AR-5387un bcm6328-leds Álvaro Fernández Rojas
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-03 13:08 UTC (permalink / raw)
  To: u-boot

This driver can control up to 24 LEDs and supports HW blinking and serial leds.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 arch/mips/dts/brcm,bcm63268.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/mips/dts/brcm,bcm63268.dtsi b/arch/mips/dts/brcm,bcm63268.dtsi
index 3eda77d..11c6729 100644
--- a/arch/mips/dts/brcm,bcm63268.dtsi
+++ b/arch/mips/dts/brcm,bcm63268.dtsi
@@ -98,6 +98,15 @@
 			status = "disabled";
 		};
 
+		leds: led-controller at 10001900 {
+			compatible = "brcm,bcm6328-leds";
+			reg = <0x10001900 0x24>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			status = "disabled";
+		};
+
 		memory-controller at 10003000 {
 			compatible = "brcm,bcm6328-mc";
 			reg = <0x10003000 0x1000>;
-- 
2.1.4

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

* [U-Boot] [PATCH 4/5] mips: bmips: add Comtrend AR-5387un bcm6328-leds
  2017-05-03 13:08 [U-Boot] [PATCH 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
                   ` (2 preceding siblings ...)
  2017-05-03 13:08 ` [U-Boot] [PATCH 3/5] mips: bmips: add bcm6328-led driver support for BCM63268 Álvaro Fernández Rojas
@ 2017-05-03 13:08 ` Álvaro Fernández Rojas
  2017-05-04 16:51   ` Simon Glass
  2017-05-03 13:08 ` [U-Boot] [PATCH 5/5] mips: bmips: add Comtrend VR-3032u bcm6328-leds Álvaro Fernández Rojas
  2017-05-07 18:10 ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
  5 siblings, 1 reply; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-03 13:08 UTC (permalink / raw)
  To: u-boot

This board has several LEDs attached to its BCM6328 led controller.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 arch/mips/dts/comtrend,ar-5387un.dts    | 30 ++++++++++++++++++++++++++++++
 configs/comtrend_ar5387un_ram_defconfig |  4 ++++
 2 files changed, 34 insertions(+)

diff --git a/arch/mips/dts/comtrend,ar-5387un.dts b/arch/mips/dts/comtrend,ar-5387un.dts
index 73f3be4..73f2b49 100644
--- a/arch/mips/dts/comtrend,ar-5387un.dts
+++ b/arch/mips/dts/comtrend,ar-5387un.dts
@@ -21,6 +21,36 @@
 	};
 };
 
+&leds {
+	status = "okay";
+
+	led at 1 {
+		reg = <1>;
+		label = "AR-5387un:red:inet";
+	};
+
+	led at 4 {
+		reg = <4>;
+		label = "AR-5387un:red:power";
+	};
+
+	led at 7 {
+		reg = <7>;
+		label = "AR-5387un:green:inet";
+	};
+
+	led at 8 {
+		reg = <8>;
+		label = "AR-5387un:green:power";
+	};
+
+	led at 11 {
+		reg = <11>;
+		active-low;
+		label = "AR-5387un:green:dsl";
+	};
+};
+
 &uart0 {
 	u-boot,dm-pre-reloc;
 	status = "okay";
diff --git a/configs/comtrend_ar5387un_ram_defconfig b/configs/comtrend_ar5387un_ram_defconfig
index c95a369..f8656c4 100644
--- a/configs/comtrend_ar5387un_ram_defconfig
+++ b/configs/comtrend_ar5387un_ram_defconfig
@@ -16,6 +16,7 @@ CONFIG_CMD_CPU=y
 # CONFIG_CMD_GPIO is not set
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_IMPORTENV is not set
+CONFIG_CMD_LED=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_LOADB=y
 # CONFIG_CMD_LOADS is not set
@@ -31,6 +32,9 @@ CONFIG_DISPLAY_CPUINFO=y
 CONFIG_DM_GPIO=y
 CONFIG_DM_SERIAL=y
 CONFIG_HUSH_PARSER=y
+CONFIG_LED=y
+CONFIG_LED_BCM6328=y
+CONFIG_LED_BLINK=y
 CONFIG_MIPS=y
 # CONFIG_MIPS_BOOT_CMDLINE_LEGACY is not set
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
-- 
2.1.4

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

* [U-Boot] [PATCH 5/5] mips: bmips: add Comtrend VR-3032u bcm6328-leds
  2017-05-03 13:08 [U-Boot] [PATCH 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
                   ` (3 preceding siblings ...)
  2017-05-03 13:08 ` [U-Boot] [PATCH 4/5] mips: bmips: add Comtrend AR-5387un bcm6328-leds Álvaro Fernández Rojas
@ 2017-05-03 13:08 ` Álvaro Fernández Rojas
  2017-05-04 16:51   ` Simon Glass
  2017-05-07 18:10 ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
  5 siblings, 1 reply; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-03 13:08 UTC (permalink / raw)
  To: u-boot

This board has several LEDs attached to its BCM6328 led controller.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 arch/mips/dts/comtrend,vr-3032u.dts    | 43 ++++++++++++++++++++++++++++++++++
 configs/comtrend_vr3032u_ram_defconfig |  4 ++++
 2 files changed, 47 insertions(+)

diff --git a/arch/mips/dts/comtrend,vr-3032u.dts b/arch/mips/dts/comtrend,vr-3032u.dts
index 6715304..54e738c 100644
--- a/arch/mips/dts/comtrend,vr-3032u.dts
+++ b/arch/mips/dts/comtrend,vr-3032u.dts
@@ -21,6 +21,49 @@
 	};
 };
 
+&leds {
+	status = "okay";
+	brcm,serial-leds;
+	brcm,serial-dat-low;
+	brcm,serial-shift-inv;
+
+	led at 2 {
+		reg = <2>;
+		active-low;
+		label = "VR-3032u:red:inet";
+	};
+
+	led at 3 {
+		reg = <3>;
+		active-low;
+		label = "VR-3032u:green:dsl";
+	};
+
+	led at 4 {
+		reg = <4>;
+		active-low;
+		label = "VR-3032u:green:usb";
+	};
+
+	led at 7 {
+		reg = <7>;
+		active-low;
+		label = "VR-3032u:green:wps";
+	};
+
+	led at 8 {
+		reg = <8>;
+		active-low;
+		label = "VR-3032u:green:inet";
+	};
+
+	led at 20 {
+		reg = <20>;
+		active-low;
+		label = "VR-3032u:green:power";
+	};
+};
+
 &uart0 {
 	u-boot,dm-pre-reloc;
 	status = "okay";
diff --git a/configs/comtrend_vr3032u_ram_defconfig b/configs/comtrend_vr3032u_ram_defconfig
index c62ef0c..a04b0e5 100644
--- a/configs/comtrend_vr3032u_ram_defconfig
+++ b/configs/comtrend_vr3032u_ram_defconfig
@@ -16,6 +16,7 @@ CONFIG_CMD_CPU=y
 # CONFIG_CMD_GPIO is not set
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_IMPORTENV is not set
+CONFIG_CMD_LED=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_LOADB=y
 # CONFIG_CMD_LOADS is not set
@@ -31,6 +32,9 @@ CONFIG_DISPLAY_CPUINFO=y
 CONFIG_DM_GPIO=y
 CONFIG_DM_SERIAL=y
 CONFIG_HUSH_PARSER=y
+CONFIG_LED=y
+CONFIG_LED_BCM6328=y
+CONFIG_LED_BLINK=y
 CONFIG_MIPS=y
 # CONFIG_MIPS_BOOT_CMDLINE_LEGACY is not set
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
-- 
2.1.4

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

* [U-Boot] [PATCH 1/5] dm: led: add BCM6328 led driver
  2017-05-03 13:08 ` [U-Boot] [PATCH 1/5] dm: led: add BCM6328 led driver Álvaro Fernández Rojas
@ 2017-05-04 16:50   ` Simon Glass
  0 siblings, 0 replies; 18+ messages in thread
From: Simon Glass @ 2017-05-04 16:50 UTC (permalink / raw)
  To: u-boot

On 3 May 2017 at 07:08, Álvaro Fernández Rojas <noltari@gmail.com> wrote:
> This driver is a simplified version of linux/drivers/leds/leds-bcm6328.c,
> simplified to remove HW leds and blink fallbacks.
>
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> ---
>  drivers/led/Kconfig       |   7 ++
>  drivers/led/Makefile      |   1 +
>  drivers/led/led_bcm6328.c | 262 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 270 insertions(+)
>  create mode 100644 drivers/led/led_bcm6328.c
>

Reviewed-by: Simon Glass <sjg@chromium.org>

But please see below.

Can you a DT binding file for this?

> diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
> index 309372a..50b27bd 100644
> --- a/drivers/led/Kconfig
> +++ b/drivers/led/Kconfig
> @@ -9,6 +9,13 @@ config LED
>           can provide access to board-specific LEDs. Use of the device tree
>           for configuration is encouraged.
>
> +config LED_BCM6328
> +       bool "LED Support for BCM6328"
> +       depends on LED && ARCH_BMIPS
> +       help
> +         This option enables support for LEDs connected to the BCM6328
> +         LED HW controller accessed via MMIO registers.

What features does it support? Flashing? How many LEDs?

[...]

> +static int bcm6328_led_probe(struct udevice *dev)
> +{
> +       struct led_uc_plat *uc_plat = dev_get_uclass_platdata(dev);
> +       fdt_addr_t addr;
> +       fdt_size_t size;
> +
> +       /* Top-level LED node */
> +       if (!uc_plat->label) {
> +               void __iomem *regs;
> +               u32 set_bits = 0;
> +
> +               addr = dev_get_addr_size_index(dev, 0, &size);
> +               if (addr == FDT_ADDR_T_NONE)
> +                       return -EINVAL;
> +
> +               regs = ioremap(addr, size);
> +
> +               if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
> +                               "brcm,serial-leds", NULL))

Can you use fdtdec_get_bool() ?

> +                       set_bits |= LED_INIT_SLEDEN_MASK;
> +               if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
> +                               "brcm,serial-mux", NULL))
> +                       set_bits |= LED_INIT_SLEDMUX_MASK;
> +               if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
> +                               "brcm,serial-clk-low", NULL))
> +                       set_bits |= LED_INIT_SLEDCLKNPOL_MASK;
> +               if (!fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
> +                                "brcm,serial-dat-low", NULL))
> +                       set_bits |= LED_INIT_SLEDDATANPOL_MASK;
> +               if (!fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
> +                                "brcm,serial-shift-inv", NULL))
> +                       set_bits |= LED_INIT_SLEDSHIFTDIR_MASK;
> +
> +               clrsetbits_be32(regs + LED_INIT_REG, ~0, set_bits);
> +       } else {
> +               struct bcm6328_led_priv *priv = dev_get_priv(dev);
> +               unsigned int pin;
> +
> +               addr = dev_get_addr_size_index(dev_get_parent(dev), 0, &size);
> +               if (addr == FDT_ADDR_T_NONE)
> +                       return -EINVAL;
> +
> +               pin = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), "reg",
> +                                     LEDS_MAX);
> +               if (pin >= LEDS_MAX)
> +                       return -EINVAL;
> +
> +               priv->regs = ioremap(addr, size);
> +               if (pin < 8) {
> +                       /* LEDs 0-7 (bits 47:32) */
> +                       priv->mode = priv->regs + LED_MODE_REG_HI;
> +                       priv->shift = (pin << 1);
> +               } else {
> +                       /* LEDs 8-23 (bits 31:0) */
> +                       priv->mode = priv->regs + LED_MODE_REG_LO;
> +                       priv->shift = ((pin - 8) << 1);
> +               }
> +
> +               if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "active-low",
> +                               NULL))
> +                       priv->active_low = true;
> +       }
> +
> +       return 0;
> +}
> +

[..]

Regards,
Simon

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

* [U-Boot] [PATCH 2/5] mips: bmips: add bcm6328-led driver support for BCM6328
  2017-05-03 13:08 ` [U-Boot] [PATCH 2/5] mips: bmips: add bcm6328-led driver support for BCM6328 Álvaro Fernández Rojas
@ 2017-05-04 16:50   ` Simon Glass
  0 siblings, 0 replies; 18+ messages in thread
From: Simon Glass @ 2017-05-04 16:50 UTC (permalink / raw)
  To: u-boot

On 3 May 2017 at 07:08, Álvaro Fernández Rojas <noltari@gmail.com> wrote:
> This driver can control up to 24 LEDs and supports HW blinking and serial leds.
>
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> ---
>  arch/mips/dts/brcm,bcm6328.dtsi | 9 +++++++++
>  1 file changed, 9 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 3/5] mips: bmips: add bcm6328-led driver support for BCM63268
  2017-05-03 13:08 ` [U-Boot] [PATCH 3/5] mips: bmips: add bcm6328-led driver support for BCM63268 Álvaro Fernández Rojas
@ 2017-05-04 16:51   ` Simon Glass
  0 siblings, 0 replies; 18+ messages in thread
From: Simon Glass @ 2017-05-04 16:51 UTC (permalink / raw)
  To: u-boot

On 3 May 2017 at 07:08, Álvaro Fernández Rojas <noltari@gmail.com> wrote:
> This driver can control up to 24 LEDs and supports HW blinking and serial leds.
>
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> ---
>  arch/mips/dts/brcm,bcm63268.dtsi | 9 +++++++++
>  1 file changed, 9 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 4/5] mips: bmips: add Comtrend AR-5387un bcm6328-leds
  2017-05-03 13:08 ` [U-Boot] [PATCH 4/5] mips: bmips: add Comtrend AR-5387un bcm6328-leds Álvaro Fernández Rojas
@ 2017-05-04 16:51   ` Simon Glass
  0 siblings, 0 replies; 18+ messages in thread
From: Simon Glass @ 2017-05-04 16:51 UTC (permalink / raw)
  To: u-boot

On 3 May 2017 at 07:08, Álvaro Fernández Rojas <noltari@gmail.com> wrote:
> This board has several LEDs attached to its BCM6328 led controller.
>
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> ---
>  arch/mips/dts/comtrend,ar-5387un.dts    | 30 ++++++++++++++++++++++++++++++
>  configs/comtrend_ar5387un_ram_defconfig |  4 ++++
>  2 files changed, 34 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 5/5] mips: bmips: add Comtrend VR-3032u bcm6328-leds
  2017-05-03 13:08 ` [U-Boot] [PATCH 5/5] mips: bmips: add Comtrend VR-3032u bcm6328-leds Álvaro Fernández Rojas
@ 2017-05-04 16:51   ` Simon Glass
  0 siblings, 0 replies; 18+ messages in thread
From: Simon Glass @ 2017-05-04 16:51 UTC (permalink / raw)
  To: u-boot

On 3 May 2017 at 07:08, Álvaro Fernández Rojas <noltari@gmail.com> wrote:
> This board has several LEDs attached to its BCM6328 led controller.
>
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> ---
>  arch/mips/dts/comtrend,vr-3032u.dts    | 43 ++++++++++++++++++++++++++++++++++
>  configs/comtrend_vr3032u_ram_defconfig |  4 ++++
>  2 files changed, 47 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support
  2017-05-03 13:08 [U-Boot] [PATCH 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
                   ` (4 preceding siblings ...)
  2017-05-03 13:08 ` [U-Boot] [PATCH 5/5] mips: bmips: add Comtrend VR-3032u bcm6328-leds Álvaro Fernández Rojas
@ 2017-05-07 18:10 ` Álvaro Fernández Rojas
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 1/5] dm: led: add BCM6328 led driver Álvaro Fernández Rojas
                     ` (5 more replies)
  5 siblings, 6 replies; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-07 18:10 UTC (permalink / raw)
  To: u-boot

BCM6328 supports controlling LEDs both by using the GPIO controller and the
LED controller. However, LED controller allows HW blinking and supports serial
LEDs.

v2: Introduce changes suggested by Simon Glass

Álvaro Fernández Rojas (5):
  dm: led: add BCM6328 led driver
  mips: bmips: add bcm6328-led driver support for BCM6328
  mips: bmips: add bcm6328-led driver support for BCM63268
  mips: bmips: add Comtrend AR-5387un bcm6328-leds
  mips: bmips: add Comtrend VR-3032u bcm6328-leds

 arch/mips/dts/brcm,bcm63268.dtsi               |   9 +
 arch/mips/dts/brcm,bcm6328.dtsi                |   9 +
 arch/mips/dts/comtrend,ar-5387un.dts           |  30 +++
 arch/mips/dts/comtrend,vr-3032u.dts            |  43 ++++
 configs/comtrend_ar5387un_ram_defconfig        |   4 +
 configs/comtrend_vr3032u_ram_defconfig         |   4 +
 doc/device-tree-bindings/leds/leds-bcm6328.txt | 106 ++++++++++
 drivers/led/Kconfig                            |  11 ++
 drivers/led/Makefile                           |   1 +
 drivers/led/led_bcm6328.c                      | 262 +++++++++++++++++++++++++
 10 files changed, 479 insertions(+)
 create mode 100644 doc/device-tree-bindings/leds/leds-bcm6328.txt
 create mode 100644 drivers/led/led_bcm6328.c

-- 
2.1.4

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

* [U-Boot] [PATCH v2 1/5] dm: led: add BCM6328 led driver
  2017-05-07 18:10 ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
@ 2017-05-07 18:10   ` Álvaro Fernández Rojas
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 2/5] mips: bmips: add bcm6328-led driver support for BCM6328 Álvaro Fernández Rojas
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-07 18:10 UTC (permalink / raw)
  To: u-boot

This driver is a simplified version of linux/drivers/leds/leds-bcm6328.c,
simplified to remove HW leds and blink fallbacks.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 v2: Introduce changes suggested by Simon Glass:
  - Add DT binding file.
  - Add features description.
  - Switch to fdtdec_get_bool().

 doc/device-tree-bindings/leds/leds-bcm6328.txt | 106 ++++++++++
 drivers/led/Kconfig                            |  11 ++
 drivers/led/Makefile                           |   1 +
 drivers/led/led_bcm6328.c                      | 262 +++++++++++++++++++++++++
 4 files changed, 380 insertions(+)
 create mode 100644 doc/device-tree-bindings/leds/leds-bcm6328.txt
 create mode 100644 drivers/led/led_bcm6328.c

diff --git a/doc/device-tree-bindings/leds/leds-bcm6328.txt b/doc/device-tree-bindings/leds/leds-bcm6328.txt
new file mode 100644
index 0000000..7f5597b
--- /dev/null
+++ b/doc/device-tree-bindings/leds/leds-bcm6328.txt
@@ -0,0 +1,106 @@
+LEDs connected to Broadcom BCM6328 controller
+
+This controller is present on BCM6318, BCM6328, BCM6362 and BCM63268.
+In these SoCs it's possible to control LEDs both as GPIOs or by hardware.
+However, on some devices there are Serial LEDs (LEDs connected to a 74x164
+controller), which can either be controlled by software (exporting the 74x164
+as spi-gpio. See Documentation/devicetree/bindings/gpio/gpio-74x164.txt), or
+by hardware using this driver.
+Some of these Serial LEDs are hardware controlled (e.g. ethernet LEDs) and
+exporting the 74x164 as spi-gpio prevents those LEDs to be hardware
+controlled, so the only chance to keep them working is by using this driver.
+
+Required properties:
+  - compatible : should be "brcm,bcm6328-leds".
+  - #address-cells : must be 1.
+  - #size-cells : must be 0.
+  - reg : BCM6328 LED controller address and size.
+
+Optional properties:
+  - brcm,serial-leds : Boolean, enables Serial LEDs.
+    Default : false
+  - brcm,serial-mux : Boolean, enables Serial LEDs multiplexing.
+    Default : false
+  - brcm,serial-clk-low : Boolean, makes clock signal active low.
+    Default : false
+  - brcm,serial-dat-low : Boolean, makes data signal active low.
+    Default : false
+  - brcm,serial-shift-inv : Boolean, inverts Serial LEDs shift direction.
+    Default : false
+
+Each LED is represented as a sub-node of the brcm,bcm6328-leds device.
+
+LED sub-node required properties:
+  - reg : LED pin number (only LEDs 0 to 23 are valid).
+
+LED sub-node optional properties:
+  - label : see Documentation/devicetree/bindings/leds/common.txt
+  - active-low : Boolean, makes LED active low.
+    Default : false
+
+Examples:
+Scenario 1 : BCM6328 with 4 GPIO LEDs
+	leds0: led-controller at 10000800 {
+		compatible = "brcm,bcm6328-leds";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <0x10000800 0x24>;
+
+		alarm_red at 2 {
+			reg = <2>;
+			active-low;
+			label = "red:alarm";
+		};
+		inet_green at 3 {
+			reg = <3>;
+			active-low;
+			label = "green:inet";
+		};
+		power_green at 4 {
+			reg = <4>;
+			active-low;
+			label = "green:power";
+		};
+	};
+
+Scenario 2 : BCM63268 with Serial LEDs
+	leds0: led-controller at 10001900 {
+		compatible = "brcm,bcm6328-leds";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <0x10001900 0x24>;
+		brcm,serial-leds;
+		brcm,serial-dat-low;
+		brcm,serial-shift-inv;
+
+		inet_red at 2 {
+			reg = <2>;
+			active-low;
+			label = "red:inet";
+		};
+		dsl_green at 3 {
+			reg = <3>;
+			active-low;
+			label = "green:dsl";
+		};
+		usb_green at 4 {
+			reg = <4>;
+			active-low;
+			label = "green:usb";
+		};
+		wps_green at 7 {
+			reg = <7>;
+			active-low;
+			label = "green:wps";
+		};
+		inet_green at 8 {
+			reg = <8>;
+			active-low;
+			label = "green:inet";
+		};
+		power_green at 20 {
+			reg = <20>;
+			active-low;
+			label = "green:power";
+		};
+	};
diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
index 309372a..dc19f4f 100644
--- a/drivers/led/Kconfig
+++ b/drivers/led/Kconfig
@@ -9,6 +9,17 @@ config LED
 	  can provide access to board-specific LEDs. Use of the device tree
 	  for configuration is encouraged.
 
+config LED_BCM6328
+	bool "LED Support for BCM6328"
+	depends on LED && ARCH_BMIPS
+	help
+	  This option enables support for LEDs connected to the BCM6328
+	  LED HW controller accessed via MMIO registers.
+	  HW blinking is supported and up to 24 LEDs can be controlled.
+	  All LEDs can blink at the same time but the delay is shared, which
+	  means that if one LED is set to blink at 100ms and then a different
+	  LED is set to blink at 200ms, both will blink at 200ms.
+
 config LED_BLINK
 	bool "Support LED blinking"
 	depends on LED
diff --git a/drivers/led/Makefile b/drivers/led/Makefile
index 02367fd..d371ed5 100644
--- a/drivers/led/Makefile
+++ b/drivers/led/Makefile
@@ -6,4 +6,5 @@
 #
 
 obj-y += led-uclass.o
+obj-$(CONFIG_LED_BCM6328) += led_bcm6328.o
 obj-$(CONFIG_$(SPL_)LED_GPIO) += led_gpio.o
diff --git a/drivers/led/led_bcm6328.c b/drivers/led/led_bcm6328.c
new file mode 100644
index 0000000..ef8c6a7
--- /dev/null
+++ b/drivers/led/led_bcm6328.c
@@ -0,0 +1,262 @@
+/*
+ * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <led.h>
+#include <asm/io.h>
+#include <dm/lists.h>
+
+#define LEDS_MAX			24
+
+/* LED Init register */
+#define LED_INIT_REG			0x00
+#define LED_INIT_FASTINTV_MS		20
+#define LED_INIT_FASTINTV_SHIFT		6
+#define LED_INIT_FASTINTV_MASK		(0x3f << LED_INIT_FASTINTV_SHIFT)
+#define LED_INIT_SLEDEN_SHIFT		12
+#define LED_INIT_SLEDEN_MASK		(1 << LED_INIT_SLEDEN_SHIFT)
+#define LED_INIT_SLEDMUX_SHIFT		13
+#define LED_INIT_SLEDMUX_MASK		(1 << LED_INIT_SLEDMUX_SHIFT)
+#define LED_INIT_SLEDCLKNPOL_SHIFT	14
+#define LED_INIT_SLEDCLKNPOL_MASK	(1 << LED_INIT_SLEDCLKNPOL_SHIFT)
+#define LED_INIT_SLEDDATAPPOL_SHIFT	15
+#define LED_INIT_SLEDDATANPOL_MASK	(1 << LED_INIT_SLEDDATAPPOL_SHIFT)
+#define LED_INIT_SLEDSHIFTDIR_SHIFT	16
+#define LED_INIT_SLEDSHIFTDIR_MASK	(1 << LED_INIT_SLEDSHIFTDIR_SHIFT)
+
+/* LED Mode registers */
+#define LED_MODE_REG_HI			0x04
+#define LED_MODE_REG_LO			0x08
+#define LED_MODE_ON			0
+#define LED_MODE_FAST			1
+#define LED_MODE_BLINK			2
+#define LED_MODE_OFF			3
+#define LED_MODE_MASK			0x3
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct bcm6328_led_priv {
+	void __iomem *regs;
+	void __iomem *mode;
+	uint8_t shift;
+	bool active_low;
+};
+
+static unsigned long bcm6328_led_get_mode(struct bcm6328_led_priv *priv)
+{
+	return ((readl_be(priv->mode) >> priv->shift) & LED_MODE_MASK);
+}
+
+static int bcm6328_led_set_mode(struct bcm6328_led_priv *priv, uint8_t mode)
+{
+	clrsetbits_be32(priv->mode, (LED_MODE_MASK << priv->shift),
+			(mode << priv->shift));
+
+	return 0;
+}
+
+static enum led_state_t bcm6328_led_get_state(struct udevice *dev)
+{
+	struct bcm6328_led_priv *priv = dev_get_priv(dev);
+	enum led_state_t state = LEDST_OFF;
+
+	switch (bcm6328_led_get_mode(priv)) {
+#ifdef CONFIG_LED_BLINK
+	case LED_MODE_BLINK:
+	case LED_MODE_FAST:
+		state = LEDST_BLINK;
+		break;
+#endif
+	case LED_MODE_OFF:
+		state = (priv->active_low ? LEDST_ON : LEDST_OFF);
+		break;
+	case LED_MODE_ON:
+		state = (priv->active_low ? LEDST_OFF : LEDST_ON);
+		break;
+	}
+
+	return state;
+}
+
+static int bcm6328_led_set_state(struct udevice *dev, enum led_state_t state)
+{
+	struct bcm6328_led_priv *priv = dev_get_priv(dev);
+	unsigned long mode;
+
+	switch (state) {
+#ifdef CONFIG_LED_BLINK
+	case LEDST_BLINK:
+		mode = LED_MODE_BLINK;
+		break;
+#endif
+	case LEDST_OFF:
+		mode = (priv->active_low ? LED_MODE_ON : LED_MODE_OFF);
+		break;
+	case LEDST_ON:
+		mode = (priv->active_low ? LED_MODE_OFF : LED_MODE_ON);
+		break;
+	case LEDST_TOGGLE:
+		if (bcm6328_led_get_state(dev) == LEDST_OFF)
+			return bcm6328_led_set_state(dev, LEDST_ON);
+		else
+			return bcm6328_led_set_state(dev, LEDST_OFF);
+		break;
+	default:
+		return -ENOSYS;
+	}
+
+	return bcm6328_led_set_mode(priv, mode);
+}
+
+#ifdef CONFIG_LED_BLINK
+static unsigned long bcm6328_blink_delay(int delay)
+{
+	unsigned long bcm6328_delay = delay;
+
+	bcm6328_delay += (LED_INIT_FASTINTV_MS / 2);
+	bcm6328_delay /= LED_INIT_FASTINTV_MS;
+	bcm6328_delay <<= LED_INIT_FASTINTV_SHIFT;
+
+	if (bcm6328_delay > LED_INIT_FASTINTV_MASK)
+		return LED_INIT_FASTINTV_MASK;
+	else
+		return bcm6328_delay;
+}
+
+static int bcm6328_led_set_period(struct udevice *dev, int period_ms)
+{
+	struct bcm6328_led_priv *priv = dev_get_priv(dev);
+
+	clrsetbits_be32(priv->regs + LED_INIT_REG, LED_INIT_FASTINTV_MASK,
+			bcm6328_blink_delay(period_ms));
+
+	return 0;
+}
+#endif
+
+static const struct led_ops bcm6328_led_ops = {
+	.get_state = bcm6328_led_get_state,
+	.set_state = bcm6328_led_set_state,
+#ifdef CONFIG_LED_BLINK
+	.set_period = bcm6328_led_set_period,
+#endif
+};
+
+static int bcm6328_led_probe(struct udevice *dev)
+{
+	struct led_uc_plat *uc_plat = dev_get_uclass_platdata(dev);
+	fdt_addr_t addr;
+	fdt_size_t size;
+
+	/* Top-level LED node */
+	if (!uc_plat->label) {
+		void __iomem *regs;
+		u32 set_bits = 0;
+
+		addr = dev_get_addr_size_index(dev, 0, &size);
+		if (addr == FDT_ADDR_T_NONE)
+			return -EINVAL;
+
+		regs = ioremap(addr, size);
+
+		if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
+				    "brcm,serial-leds"))
+			set_bits |= LED_INIT_SLEDEN_MASK;
+		if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
+				    "brcm,serial-mux"))
+			set_bits |= LED_INIT_SLEDMUX_MASK;
+		if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
+				    "brcm,serial-clk-low"))
+			set_bits |= LED_INIT_SLEDCLKNPOL_MASK;
+		if (!fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
+				     "brcm,serial-dat-low"))
+			set_bits |= LED_INIT_SLEDDATANPOL_MASK;
+		if (!fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
+				     "brcm,serial-shift-inv"))
+			set_bits |= LED_INIT_SLEDSHIFTDIR_MASK;
+
+		clrsetbits_be32(regs + LED_INIT_REG, ~0, set_bits);
+	} else {
+		struct bcm6328_led_priv *priv = dev_get_priv(dev);
+		unsigned int pin;
+
+		addr = dev_get_addr_size_index(dev_get_parent(dev), 0, &size);
+		if (addr == FDT_ADDR_T_NONE)
+			return -EINVAL;
+
+		pin = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), "reg",
+				      LEDS_MAX);
+		if (pin >= LEDS_MAX)
+			return -EINVAL;
+
+		priv->regs = ioremap(addr, size);
+		if (pin < 8) {
+			/* LEDs 0-7 (bits 47:32) */
+			priv->mode = priv->regs + LED_MODE_REG_HI;
+			priv->shift = (pin << 1);
+		} else {
+			/* LEDs 8-23 (bits 31:0) */
+			priv->mode = priv->regs + LED_MODE_REG_LO;
+			priv->shift = ((pin - 8) << 1);
+		}
+
+		if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
+				    "active-low"))
+			priv->active_low = true;
+	}
+
+	return 0;
+}
+
+static int bcm6328_led_bind(struct udevice *parent)
+{
+	const void *blob = gd->fdt_blob;
+	int node;
+
+	for (node = fdt_first_subnode(blob, dev_of_offset(parent));
+	     node > 0;
+	     node = fdt_next_subnode(blob, node)) {
+		struct led_uc_plat *uc_plat;
+		struct udevice *dev;
+		const char *label;
+		int ret;
+
+		label = fdt_getprop(blob, node, "label", NULL);
+		if (!label) {
+			debug("%s: node %s has no label\n", __func__,
+			      fdt_get_name(blob, node, NULL));
+			return -EINVAL;
+		}
+
+		ret = device_bind_driver_to_node(parent, "bcm6328-led",
+						 fdt_get_name(blob, node, NULL),
+						 node, &dev);
+		if (ret)
+			return ret;
+
+		uc_plat = dev_get_uclass_platdata(dev);
+		uc_plat->label = label;
+	}
+
+	return 0;
+}
+
+static const struct udevice_id bcm6328_led_ids[] = {
+	{ .compatible = "brcm,bcm6328-leds" },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(bcm6328_led) = {
+	.name = "bcm6328-led",
+	.id = UCLASS_LED,
+	.of_match = bcm6328_led_ids,
+	.ops = &bcm6328_led_ops,
+	.bind = bcm6328_led_bind,
+	.probe = bcm6328_led_probe,
+	.priv_auto_alloc_size = sizeof(struct bcm6328_led_priv),
+};
-- 
2.1.4

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

* [U-Boot] [PATCH v2 2/5] mips: bmips: add bcm6328-led driver support for BCM6328
  2017-05-07 18:10 ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 1/5] dm: led: add BCM6328 led driver Álvaro Fernández Rojas
@ 2017-05-07 18:10   ` Álvaro Fernández Rojas
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 3/5] mips: bmips: add bcm6328-led driver support for BCM63268 Álvaro Fernández Rojas
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-07 18:10 UTC (permalink / raw)
  To: u-boot

This driver can control up to 24 LEDs and supports HW blinking and serial leds.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 v2: no changes.

 arch/mips/dts/brcm,bcm6328.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/mips/dts/brcm,bcm6328.dtsi b/arch/mips/dts/brcm,bcm6328.dtsi
index 30c2ee8..a5b43ae 100644
--- a/arch/mips/dts/brcm,bcm6328.dtsi
+++ b/arch/mips/dts/brcm,bcm6328.dtsi
@@ -88,6 +88,15 @@
 			status = "disabled";
 		};
 
+		leds: led-controller at 10000800 {
+			compatible = "brcm,bcm6328-leds";
+			reg = <0x10000800 0x24>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			status = "disabled";
+		};
+
 		memory-controller at 10003000 {
 			compatible = "brcm,bcm6328-mc";
 			reg = <0x10003000 0x1000>;
-- 
2.1.4

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

* [U-Boot] [PATCH v2 3/5] mips: bmips: add bcm6328-led driver support for BCM63268
  2017-05-07 18:10 ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 1/5] dm: led: add BCM6328 led driver Álvaro Fernández Rojas
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 2/5] mips: bmips: add bcm6328-led driver support for BCM6328 Álvaro Fernández Rojas
@ 2017-05-07 18:10   ` Álvaro Fernández Rojas
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 4/5] mips: bmips: add Comtrend AR-5387un bcm6328-leds Álvaro Fernández Rojas
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-07 18:10 UTC (permalink / raw)
  To: u-boot

This driver can control up to 24 LEDs and supports HW blinking and serial leds.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 v2: no changes.

 arch/mips/dts/brcm,bcm63268.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/mips/dts/brcm,bcm63268.dtsi b/arch/mips/dts/brcm,bcm63268.dtsi
index 3eda77d..11c6729 100644
--- a/arch/mips/dts/brcm,bcm63268.dtsi
+++ b/arch/mips/dts/brcm,bcm63268.dtsi
@@ -98,6 +98,15 @@
 			status = "disabled";
 		};
 
+		leds: led-controller at 10001900 {
+			compatible = "brcm,bcm6328-leds";
+			reg = <0x10001900 0x24>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			status = "disabled";
+		};
+
 		memory-controller at 10003000 {
 			compatible = "brcm,bcm6328-mc";
 			reg = <0x10003000 0x1000>;
-- 
2.1.4

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

* [U-Boot] [PATCH v2 4/5] mips: bmips: add Comtrend AR-5387un bcm6328-leds
  2017-05-07 18:10 ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
                     ` (2 preceding siblings ...)
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 3/5] mips: bmips: add bcm6328-led driver support for BCM63268 Álvaro Fernández Rojas
@ 2017-05-07 18:10   ` Álvaro Fernández Rojas
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 5/5] mips: bmips: add Comtrend VR-3032u bcm6328-leds Álvaro Fernández Rojas
  2017-05-10 14:19   ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Daniel Schwierzeck
  5 siblings, 0 replies; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-07 18:10 UTC (permalink / raw)
  To: u-boot

This board has several LEDs attached to its BCM6328 led controller.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 v2: no changes.

 arch/mips/dts/comtrend,ar-5387un.dts    | 30 ++++++++++++++++++++++++++++++
 configs/comtrend_ar5387un_ram_defconfig |  4 ++++
 2 files changed, 34 insertions(+)

diff --git a/arch/mips/dts/comtrend,ar-5387un.dts b/arch/mips/dts/comtrend,ar-5387un.dts
index 73f3be4..73f2b49 100644
--- a/arch/mips/dts/comtrend,ar-5387un.dts
+++ b/arch/mips/dts/comtrend,ar-5387un.dts
@@ -21,6 +21,36 @@
 	};
 };
 
+&leds {
+	status = "okay";
+
+	led at 1 {
+		reg = <1>;
+		label = "AR-5387un:red:inet";
+	};
+
+	led at 4 {
+		reg = <4>;
+		label = "AR-5387un:red:power";
+	};
+
+	led at 7 {
+		reg = <7>;
+		label = "AR-5387un:green:inet";
+	};
+
+	led at 8 {
+		reg = <8>;
+		label = "AR-5387un:green:power";
+	};
+
+	led at 11 {
+		reg = <11>;
+		active-low;
+		label = "AR-5387un:green:dsl";
+	};
+};
+
 &uart0 {
 	u-boot,dm-pre-reloc;
 	status = "okay";
diff --git a/configs/comtrend_ar5387un_ram_defconfig b/configs/comtrend_ar5387un_ram_defconfig
index c95a369..f8656c4 100644
--- a/configs/comtrend_ar5387un_ram_defconfig
+++ b/configs/comtrend_ar5387un_ram_defconfig
@@ -16,6 +16,7 @@ CONFIG_CMD_CPU=y
 # CONFIG_CMD_GPIO is not set
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_IMPORTENV is not set
+CONFIG_CMD_LED=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_LOADB=y
 # CONFIG_CMD_LOADS is not set
@@ -31,6 +32,9 @@ CONFIG_DISPLAY_CPUINFO=y
 CONFIG_DM_GPIO=y
 CONFIG_DM_SERIAL=y
 CONFIG_HUSH_PARSER=y
+CONFIG_LED=y
+CONFIG_LED_BCM6328=y
+CONFIG_LED_BLINK=y
 CONFIG_MIPS=y
 # CONFIG_MIPS_BOOT_CMDLINE_LEGACY is not set
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
-- 
2.1.4

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

* [U-Boot] [PATCH v2 5/5] mips: bmips: add Comtrend VR-3032u bcm6328-leds
  2017-05-07 18:10 ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
                     ` (3 preceding siblings ...)
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 4/5] mips: bmips: add Comtrend AR-5387un bcm6328-leds Álvaro Fernández Rojas
@ 2017-05-07 18:10   ` Álvaro Fernández Rojas
  2017-05-10 14:19   ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Daniel Schwierzeck
  5 siblings, 0 replies; 18+ messages in thread
From: Álvaro Fernández Rojas @ 2017-05-07 18:10 UTC (permalink / raw)
  To: u-boot

This board has several LEDs attached to its BCM6328 led controller.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 v2: no changes.

 arch/mips/dts/comtrend,vr-3032u.dts    | 43 ++++++++++++++++++++++++++++++++++
 configs/comtrend_vr3032u_ram_defconfig |  4 ++++
 2 files changed, 47 insertions(+)

diff --git a/arch/mips/dts/comtrend,vr-3032u.dts b/arch/mips/dts/comtrend,vr-3032u.dts
index 6715304..54e738c 100644
--- a/arch/mips/dts/comtrend,vr-3032u.dts
+++ b/arch/mips/dts/comtrend,vr-3032u.dts
@@ -21,6 +21,49 @@
 	};
 };
 
+&leds {
+	status = "okay";
+	brcm,serial-leds;
+	brcm,serial-dat-low;
+	brcm,serial-shift-inv;
+
+	led at 2 {
+		reg = <2>;
+		active-low;
+		label = "VR-3032u:red:inet";
+	};
+
+	led at 3 {
+		reg = <3>;
+		active-low;
+		label = "VR-3032u:green:dsl";
+	};
+
+	led at 4 {
+		reg = <4>;
+		active-low;
+		label = "VR-3032u:green:usb";
+	};
+
+	led at 7 {
+		reg = <7>;
+		active-low;
+		label = "VR-3032u:green:wps";
+	};
+
+	led at 8 {
+		reg = <8>;
+		active-low;
+		label = "VR-3032u:green:inet";
+	};
+
+	led at 20 {
+		reg = <20>;
+		active-low;
+		label = "VR-3032u:green:power";
+	};
+};
+
 &uart0 {
 	u-boot,dm-pre-reloc;
 	status = "okay";
diff --git a/configs/comtrend_vr3032u_ram_defconfig b/configs/comtrend_vr3032u_ram_defconfig
index c62ef0c..a04b0e5 100644
--- a/configs/comtrend_vr3032u_ram_defconfig
+++ b/configs/comtrend_vr3032u_ram_defconfig
@@ -16,6 +16,7 @@ CONFIG_CMD_CPU=y
 # CONFIG_CMD_GPIO is not set
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_IMPORTENV is not set
+CONFIG_CMD_LED=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_LOADB=y
 # CONFIG_CMD_LOADS is not set
@@ -31,6 +32,9 @@ CONFIG_DISPLAY_CPUINFO=y
 CONFIG_DM_GPIO=y
 CONFIG_DM_SERIAL=y
 CONFIG_HUSH_PARSER=y
+CONFIG_LED=y
+CONFIG_LED_BCM6328=y
+CONFIG_LED_BLINK=y
 CONFIG_MIPS=y
 # CONFIG_MIPS_BOOT_CMDLINE_LEGACY is not set
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
-- 
2.1.4

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

* [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support
  2017-05-07 18:10 ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
                     ` (4 preceding siblings ...)
  2017-05-07 18:10   ` [U-Boot] [PATCH v2 5/5] mips: bmips: add Comtrend VR-3032u bcm6328-leds Álvaro Fernández Rojas
@ 2017-05-10 14:19   ` Daniel Schwierzeck
  5 siblings, 0 replies; 18+ messages in thread
From: Daniel Schwierzeck @ 2017-05-10 14:19 UTC (permalink / raw)
  To: u-boot



Am 07.05.2017 um 20:10 schrieb Álvaro Fernández Rojas:
> BCM6328 supports controlling LEDs both by using the GPIO controller and the
> LED controller. However, LED controller allows HW blinking and supports serial
> LEDs.
> 
> v2: Introduce changes suggested by Simon Glass
> 
> Álvaro Fernández Rojas (5):
>   dm: led: add BCM6328 led driver
>   mips: bmips: add bcm6328-led driver support for BCM6328
>   mips: bmips: add bcm6328-led driver support for BCM63268
>   mips: bmips: add Comtrend AR-5387un bcm6328-leds
>   mips: bmips: add Comtrend VR-3032u bcm6328-leds
> 
>  arch/mips/dts/brcm,bcm63268.dtsi               |   9 +
>  arch/mips/dts/brcm,bcm6328.dtsi                |   9 +
>  arch/mips/dts/comtrend,ar-5387un.dts           |  30 +++
>  arch/mips/dts/comtrend,vr-3032u.dts            |  43 ++++
>  configs/comtrend_ar5387un_ram_defconfig        |   4 +
>  configs/comtrend_vr3032u_ram_defconfig         |   4 +
>  doc/device-tree-bindings/leds/leds-bcm6328.txt | 106 ++++++++++
>  drivers/led/Kconfig                            |  11 ++
>  drivers/led/Makefile                           |   1 +
>  drivers/led/led_bcm6328.c                      | 262 +++++++++++++++++++++++++
>  10 files changed, 479 insertions(+)
>  create mode 100644 doc/device-tree-bindings/leds/leds-bcm6328.txt
>  create mode 100644 drivers/led/led_bcm6328.c
> 

series applied to u-boot-mips/next, thanks

-- 
- Daniel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170510/bfdd8a90/attachment.sig>

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

end of thread, other threads:[~2017-05-10 14:19 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-03 13:08 [U-Boot] [PATCH 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
2017-05-03 13:08 ` [U-Boot] [PATCH 1/5] dm: led: add BCM6328 led driver Álvaro Fernández Rojas
2017-05-04 16:50   ` Simon Glass
2017-05-03 13:08 ` [U-Boot] [PATCH 2/5] mips: bmips: add bcm6328-led driver support for BCM6328 Álvaro Fernández Rojas
2017-05-04 16:50   ` Simon Glass
2017-05-03 13:08 ` [U-Boot] [PATCH 3/5] mips: bmips: add bcm6328-led driver support for BCM63268 Álvaro Fernández Rojas
2017-05-04 16:51   ` Simon Glass
2017-05-03 13:08 ` [U-Boot] [PATCH 4/5] mips: bmips: add Comtrend AR-5387un bcm6328-leds Álvaro Fernández Rojas
2017-05-04 16:51   ` Simon Glass
2017-05-03 13:08 ` [U-Boot] [PATCH 5/5] mips: bmips: add Comtrend VR-3032u bcm6328-leds Álvaro Fernández Rojas
2017-05-04 16:51   ` Simon Glass
2017-05-07 18:10 ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Álvaro Fernández Rojas
2017-05-07 18:10   ` [U-Boot] [PATCH v2 1/5] dm: led: add BCM6328 led driver Álvaro Fernández Rojas
2017-05-07 18:10   ` [U-Boot] [PATCH v2 2/5] mips: bmips: add bcm6328-led driver support for BCM6328 Álvaro Fernández Rojas
2017-05-07 18:10   ` [U-Boot] [PATCH v2 3/5] mips: bmips: add bcm6328-led driver support for BCM63268 Álvaro Fernández Rojas
2017-05-07 18:10   ` [U-Boot] [PATCH v2 4/5] mips: bmips: add Comtrend AR-5387un bcm6328-leds Álvaro Fernández Rojas
2017-05-07 18:10   ` [U-Boot] [PATCH v2 5/5] mips: bmips: add Comtrend VR-3032u bcm6328-leds Álvaro Fernández Rojas
2017-05-10 14:19   ` [U-Boot] [PATCH v2 0/5] dm: led: add BCM6328 led support Daniel Schwierzeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox