Skip to contentSkip to conversation

v7 EL15203000

PATCH Superseded Oleh Kravchenko 3 participants 6 messages Sep 9, 2019 – Sep 11, 2019

Subsystems (2)

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

[PATCH v7 1/2] dt-bindings: Add docs for EL15203000 [PATCH v7 2/2] leds: add LED driver for EL15203000 board

Fixed compilation error missing variable led.
Compiled and checked on real device.

#1 lore raw

PATCH v7 1/2 dt-bindings: Add docs for EL15203000

Add documentation and example for dt-bindings EL15203000. LED board (aka RED LED board) from Crane Merchandising Systems.

---
 .../bindings/leds/leds-el15203000.txt         | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-el15203000.txt
Documentation/devicetree/bindings/leds/leds-el15203000.txt new file +54 -0
new file mode 100644
index 000000000000..c00e1b55db97
@@ -0,0 +1,54 @@
+Crane Merchandising System - el15203000 LED driver
+--------------------------------------------------
+
+This LED Board (aka RED LEDs board) is widely used in
+coffee vending machines produced by Crane Merchandising Systems.
+
+Required properties:
+- compatible : "crane,el15203000"
+- reg :
+	see Documentation/devicetree/bindings/spi/spi-bus.txt
+- spi-max-frequency : (optional)
+	see Documentation/devicetree/bindings/spi/spi-bus.txt
+
+Optional LED sub-node properties:
+- function:
+	see Documentation/devicetree/bindings/leds/common.txt
+- color:
+	see Documentation/devicetree/bindings/leds/common.txt
+- label:
+	see Documentation/devicetree/bindings/leds/common.txt (deprecated)
+
+Example
+-------
+
+#include <dt-bindings/leds/common.h>
+
+led-controller@0 {
+	compatible = "crane,el15203000";
+	reg = <0>;
+	spi-max-frequency = <50000>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+
+	/* water pipe */
+	led@50 {
+		reg = <0x50>;
+		function = "pipe";
+		color = <LED_COLOR_ID_RED>;
+	};
+
+	/* screen frame */
+	led@53 {
+		reg = <0x53>;
+		function = "screen";
+		color = <LED_COLOR_ID_RED>;
+	};
+
+	/* vending area */
+	led@56 {
+		reg = <0x56>;
+		function = "vend";
+		color = <LED_COLOR_ID_RED>;
+	};
+};
Signature · 1 line
2.21.0
#2 lore raw

Re: [PATCH v7 1/2] dt-bindings: Add docs for EL15203000

Oleh

Quoted 16 lines · Oleh Kravchenko

Add documentation and example for dt-bindings EL15203000. LED board (aka RED LED board) from Crane Merchandising Systems.

---
  .../bindings/leds/leds-el15203000.txt         | 54 +++++++++++++++++++
  1 file changed, 54 insertions(+)

create mode 100644 Documentation/devicetree/bindings/leds/leds-el15203000.txt

Documentation/devicetree/bindings/leds/leds-el15203000.txt new file +0 -0
new file mode 100644
index 000000000000..c00e1b55db97

Documentation/devicetree/bindings/leds/leds-el15203000.txt line 10

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-el15203000.txt new file +10 -0
@@ -0,0 +1,54 @@
+Crane Merchandising System - el15203000 LED driver
+--------------------------------------------------
+
+This LED Board (aka RED LEDs board) is widely used in
+coffee vending machines produced by Crane Merchandising Systems.
+
+Required properties:
+- compatible : "crane,el15203000"
+- reg :
+	see Documentation/devicetree/bindings/spi/spi-bus.txt

FYI this binding Documentation/devicetree/bindings/spi/spi-bus.txt points to spi-controller.yaml binding

so maybe update it to the correct binding.

Documentation/devicetree/bindings/leds/leds-el15203000.txt line 12

Quoted 2 lines
Documentation/devicetree/bindings/leds/leds-el15203000.txt new file +2 -0
+- spi-max-frequency : (optional)
+	see Documentation/devicetree/bindings/spi/spi-bus.txt

Your driver does not read spi-max-frequency, this is a property of the spi driver so I am not sure you

need to mention that here unless this property needs to be set specifically for this device.  If it does then it is not optional

for this device and it should be documented what the max freq is.

Documentation/devicetree/bindings/leds/leds-el15203000.txt line 16

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-el15203000.txt new file +4 -0
+
+Optional LED sub-node properties:
+- function:
+	see Documentation/devicetree/bindings/leds/common.txt

You point the user to the common file but you use hard coded function names in the example.

The leds/common.txt file points to the include/dt-bindings/leds/common.h file and the binding says

"If there is no matching LED_FUNCTION available, add a new one."

Now I know we don't want to add the pipe, screen or vend so you probably do not want to have the user

going to that header.

Not sure how to fix this but the documentation is misleading. Jacek?

Documentation/devicetree/bindings/leds/leds-el15203000.txt line 20

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-el15203000.txt new file +4 -0
+- color:
+	see Documentation/devicetree/bindings/leds/common.txt
+- label:
+	see Documentation/devicetree/bindings/leds/common.txt (deprecated)

Not sure if someone asked for this here but since this is a new driver it should not even speak of the "label" property.

Dan

<snip>

#3 lore raw

Re: [PATCH v7 1/2] dt-bindings: Add docs for EL15203000

Quoted 40 lines · Dan Murphy

Oleh

Quoted 19 lines · Oleh Kravchenko

Add documentation and example for dt-bindings EL15203000. LED board (aka RED LED board) from Crane Merchandising Systems.

---
  .../bindings/leds/leds-el15203000.txt         | 54 +++++++++++++++++++

  1 file changed, 54 insertions(+)

  create mode 100644 Documentation/devicetree/bindings/leds/leds-el15203000.txt

diff --git a/Documentation/devicetree/bindings/leds/leds-el15203000.txt b/Documentation/devicetree/bindings/leds/leds-el15203000.txt new file mode 100644
index 000000000000..c00e1b55db97

Documentation/devicetree/bindings/leds/leds-el15203000.txt line 10

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-el15203000.txt new file +10 -0
@@ -0,0 +1,54 @@
+Crane Merchandising System - el15203000 LED driver
+--------------------------------------------------
+
+This LED Board (aka RED LEDs board) is widely used in
+coffee vending machines produced by Crane Merchandising Systems.
+
+Required properties:
+- compatible : "crane,el15203000"
+- reg :
+    see Documentation/devicetree/bindings/spi/spi-bus.txt

FYI this binding Documentation/devicetree/bindings/spi/spi-bus.txt points to spi-controller.yaml binding

so maybe update it to the correct binding.

Documentation/devicetree/bindings/leds/leds-el15203000.txt line 12

Quoted 2 lines
Documentation/devicetree/bindings/leds/leds-el15203000.txt new file +2 -0
+- spi-max-frequency : (optional)
+    see Documentation/devicetree/bindings/spi/spi-bus.txt
Quoted 7 lines

Your driver does not read spi-max-frequency, this is a property of the spi driver so I am not sure you

need to mention that here unless this property needs to be set specifically for this device.  If it does then it is not optional

for this device and it should be documented what the max freq is.

Right, this should have different form. We have two similar occurrences in other LED bindings and in a few bindings pertinent to other subsystems. This property is parsed in spi.c for each child node of parent spi node.

It should be like below:

Property rules described in Documentation/devicetree/bindings/spi/spi-bus.txt
apply. In particular, "reg" and "spi-max-frequency" properties must be given.

Quoted 11 lines

Documentation/devicetree/bindings/leds/leds-el15203000.txt line 16

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-el15203000.txt new file +4 -0
+
+Optional LED sub-node properties:
+- function:
+    see Documentation/devicetree/bindings/leds/common.txt

You point the user to the common file but you use hard coded function names in the example.

The leds/common.txt file points to the include/dt-bindings/leds/common.h file and the binding says

Quoted 8 lines

"If there is no matching LED_FUNCTION available, add a new one."

Now I know we don't want to add the pipe, screen or vend so you probably do not want to have the user

going to that header.

Not sure how to fix this but the documentation is misleading. Jacek?

I'd just resort to common sense. If the function seems to be generic enough then it deserves its own definition. We might change it to:

"If there is no matching LED_FUNCTION available and it is plausible that it will be in demand in the future, add a new one."

Quoted 8 lines

Documentation/devicetree/bindings/leds/leds-el15203000.txt line 20

Quoted 5 lines
Documentation/devicetree/bindings/leds/leds-el15203000.txt new file +4 -0
+- color:
+    see Documentation/devicetree/bindings/leds/common.txt
+- label:
+    see Documentation/devicetree/bindings/leds/common.txt (deprecated)

Not sure if someone asked for this here but since this is a new driver it should not even speak of the "label" property.

Agreed.

Signature · 2 lines
Best regards,
Jacek Anaszewski
#4 lore raw

PATCH v7 2/2 leds: add LED driver for EL15203000 board

In reply to Oleh Kravchenko

This patch adds a LED class driver for the LEDs found on the Crane Merchandising System EL15203000 LEDs board (aka RED LEDs board).

---
 .../testing/sysfs-class-led-driver-el15203000 |  32 ++
 drivers/leds/Kconfig                          |  13 +
 drivers/leds/Makefile                         |   1 +
 drivers/leds/leds-el15203000.c                | 356 ++++++++++++++++++
 4 files changed, 402 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-led-driver-el15203000
 create mode 100644 drivers/leds/leds-el15203000.c
Documentation/ABI/testing/sysfs-class-led-driver-el15203000 new file +32 -0
new file mode 100644
index 000000000000..5e9cbf49da59
@@ -0,0 +1,32 @@
+What:		/sys/class/leds/<led>/hw_pattern
+Date:		September 2019
+KernelVersion:	5.5
+Description:
+		Specify a hardware pattern for the EL15203000 LED.
+		The LEDs board supports only predefined patterns by firmware
+		for specific LEDs.
+
+		Breathing mode for Screen frame light tube:
+		"0 4000 1 4000"
+
+		Cascade mode for Pipe LED:
+		"1 800 2 800 4 800 8 800 16 800"
+
+		Inverted cascade mode for Pipe LED:
+		"30 800 29 800 27 800 23 800 15 800"
+
+		Bounce mode for Pipe LED:
+		"1 800 2 800 4 800 8 800 16 800 16 800 8 800 4 800 2 800 1 800"
+
+		Inverted bounce mode for Pipe LED:
+		"30 800 29 800 27 800 23 800 15 800 15 800 23 800 27 800 29 800 30 800"
+
+What:		/sys/class/leds/<led>/repeat
+Date:		September 2019
+KernelVersion:	5.5
+Description:
+		EL15203000 supports only indefinitely patterns,
+		so this file should always store -1.
+
+		For more info, please see:
+		Documentation/ABI/testing/sysfs-class-led-trigger-pattern
drivers/leds/Kconfig +13 -0
index 1988de1d64c0..6e7703fd03d0 100644
@@ -132,6 +132,19 @@ config LEDS_CR0014114
 	  To compile this driver as a module, choose M here: the module
 	  will be called leds-cr0014114.
 
+config LEDS_EL15203000
+	tristate "LED Support for Crane EL15203000"
+	depends on LEDS_CLASS
+	depends on SPI
+	depends on OF
+	help
+	  This option enables support for EL15203000 LED Board
+	  (aka RED LED board) which is widely used in coffee vending
+	  machines produced by Crane Merchandising Systems.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called leds-el15203000.
+
 config LEDS_LM3530
 	tristate "LCD Backlight driver for LM3530"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index 41fb073a39c1..2da39e896ce8 100644
@@ -89,6 +89,7 @@ obj-$(CONFIG_LEDS_LM36274)		+= leds-lm36274.o
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_CR0014114)		+= leds-cr0014114.o
 obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
+obj-$(CONFIG_LEDS_EL15203000)		+= leds-el15203000.o
 
 # LED Userspace Drivers
 obj-$(CONFIG_LEDS_USER)			+= uleds.o
drivers/leds/leds-el15203000.c new file +356 -0

356 lines not on this page · raw message

Signature · 1 line
2.21.0
Reviewed-by on v7 2/2
#5 lore raw

Re: [PATCH v7 2/2] leds: add LED driver for EL15203000 board

Oleh

Quoted 12 lines · Oleh Kravchenko

This patch adds a LED class driver for the LEDs found on the Crane Merchandising System EL15203000 LEDs board (aka RED LEDs board).

---
  .../testing/sysfs-class-led-driver-el15203000 |  32 ++
  drivers/leds/Kconfig                          |  13 +
  drivers/leds/Makefile                         |   1 +
  drivers/leds/leds-el15203000.c                | 356 ++++++++++++++++++
  4 files changed, 402 insertions(+)

create mode 100644 Documentation/ABI/testing/sysfs-class-led-driver-el15203000 create mode 100644 drivers/leds/leds-el15203000.c

[...]

Quoted 24 lines
drivers/leds/leds-el15203000.c new file +24 -0
+
+static int el15203000_pattern_set_P(struct led_classdev *ldev,
+				    struct led_pattern *pattern,
+				    u32 len, int repeat)
+{
+	struct el15203000_led	*led = container_of(ldev,
+						    struct el15203000_led,
+						    ldev);
+
+	if (repeat > 0)
+		return -EINVAL;
+
+	if (is_cascade(pattern, len, false, false)) {
+		dev_dbg(led->priv->dev, "Cascade mode for 0x%02x(%c)",
+			led->reg, led->reg);
+
+		return el15203000_cmd(led, EL_PIPE_CASCADE);
+	} else if (is_cascade(pattern, len, true, false)) {
+		dev_dbg(led->priv->dev, "Inverse cascade mode for 0x%02x(%c)",
+			led->reg, led->reg);
+
+		return el15203000_cmd(led, EL_PIPE_INV_CASCADE);
+	} else if (is_bounce(pattern, len, false)) {
+		dev_dbg(led->priv->dev, "Bounce mode for 0x%02x(%c)",

drivers/leds/leds-el15203000.c line 223

Quoted 10 lines
drivers/leds/leds-el15203000.c new file +10 -0
+			led->reg, led->reg);
+
+		return el15203000_cmd(led, EL_PIPE_BOUNCE);
+	} else if (is_bounce(pattern, len, true)) {
+		dev_dbg(led->priv->dev, "Inverse bounce mode for 0x%02x(%c)",
+			led->reg, led->reg);
+
+		return el15203000_cmd(led, EL_PIPE_INV_BOUNCE);
+	}
+

nitpicking a bit not a blocker just some clean up

maybe remove the dev_dbg statements and just set a local variable to the pipe cmd

if (is_cascade(pattern, len, false, false))

    pipe_cmd = EL_PIPE_CASCADE;

else if (is_cascade(pattern, len, true, false))

    pipe_cmd = EL_PIPE_INV_CASCADE;

else

    return -EINVAL;

return el15203000_cmd(led, pipe_cmd0:

Quoted 90 lines
drivers/leds/leds-el15203000.c new file +90 -0
+	return -EINVAL;
+}
+
+static int el15203000_pattern_clear(struct led_classdev *ldev)
+{
+	struct el15203000_led	*led = container_of(ldev,
+						    struct el15203000_led,
+						    ldev);
+
+	return el15203000_cmd(led, EL_OFF);
+}
+
+static int el15203000_probe_dt(struct el15203000 *priv)
+{
+	struct el15203000_led	*led = priv->leds;
+	struct fwnode_handle	*child;
+	int			ret;
+
+	device_for_each_child_node(priv->dev, child) {
+		struct led_init_data	init_data = {};
+
+		ret = fwnode_property_read_u32(child, "reg", &led->reg);
+		if (ret) {
+			dev_err(priv->dev, "LED without ID number");
+			fwnode_handle_put(child);
+
+			return ret;
+		}
+
+		if (led->reg > U8_MAX) {
+			dev_err(priv->dev, "LED value %d is invalid", led->reg);
+			fwnode_handle_put(child);
+
+			return -EINVAL;
+		}
+
+		fwnode_property_read_string(child, "linux,default-trigger",
+					    &led->ldev.default_trigger);
+
+		led->priv			  = priv;
+		led->ldev.max_brightness	  = LED_ON;
+		led->ldev.brightness_set_blocking = el15203000_set_blocking;
+
+		if (led->reg == 'S') {
+			led->ldev.pattern_set	= el15203000_pattern_set_S;
+			led->ldev.pattern_clear	= el15203000_pattern_clear;
+		} else if (led->reg == 'P') {
+			led->ldev.pattern_set	= el15203000_pattern_set_P;
+			led->ldev.pattern_clear	= el15203000_pattern_clear;
+		}
+
+		init_data.fwnode = child;
+		ret = devm_led_classdev_register_ext(priv->dev, &led->ldev,
+						     &init_data);
+		if (ret) {
+			dev_err(priv->dev,
+				"failed to register LED device %s, err %d",
+				led->ldev.name, ret);
+			fwnode_handle_put(child);
+
+			return ret;
+		}
+
+		led++;
+	}
+
+	return ret;
+}
+
+static int el15203000_probe(struct spi_device *spi)
+{
+	struct el15203000	*priv;
+	size_t			count;
+	int			ret;
+
+	count = device_get_child_node_count(&spi->dev);
+	if (!count) {
+		dev_err(&spi->dev, "LEDs are not defined in device tree!");
+		return -ENODEV;
+	}
+
+	priv = devm_kzalloc(&spi->dev, struct_size(priv, leds, count),
+			    GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	mutex_init(&priv->lock);
+	priv->count	= count;
+	priv->dev	= &spi->dev;
+	priv->spi	= spi;

drivers/leds/leds-el15203000.c line 323

Quoted 10 lines
drivers/leds/leds-el15203000.c new file +10 -0
+	priv->delay	= jiffies -
+			  usecs_to_jiffies(EL_FW_DELAY_USEC);
+
+	ret = el15203000_probe_dt(priv);
+	if (ret)
+		return ret;
+
+	spi_set_drvdata(spi, priv);
+
+	return 0;

Another nitpick again just some clean up.

Set spi_set_drvdata before you call the probe_dt then return on el15203000_probe_dt this will allow you to eliminate the local ret variable.

so it would look like this:

spi_set_drvdata(spi, priv);

return el15203000_probe_dt(priv);

Otherwise

<snip>