Skip to contentSkip to conversation

dt-bindings: backlight: Add Texas Instruments LM3509

PATCH Superseded Patrick Gansterer 2 participants 4 messages Mar 10, 2024 – Mar 25, 2024

Subsystems (4)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 dt-bindings: backlight: Add Texas Instruments LM3509

Add Device Tree bindings for Texas Instruments LM3509 - a High Efficiency Boost for White LED's and/or OLED Displays

---
Changes in v4:
Use backlight_*() to access backlight_device
Do not set backlight_properties.power

v3: https://lore.kernel.org/all/[email protected]/

Changes in v3:
Improved device tree bindings documentation

v2: https://lore.kernel.org/all/[email protected]/

Changes in v2:
Add device tree nodes for each output
Addressed multiple smaller review comments

v1: https://lore.kernel.org/all/[email protected]/

 .../bindings/leds/backlight/ti,lm3509.yaml    | 139 ++++++++++++++++++
 1 file changed, 139 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/backlight/ti,lm3509.yaml
Documentation/devicetree/bindings/leds/backlight/ti,lm3509.yaml new file +139 -0
new file mode 100644
index 000000000000..b67f67648852
@@ -0,0 +1,139 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/backlight/ti,lm3509.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI LM3509 High Efficiency Boost for White LED's and/or OLED Displays
+
+maintainers:
+  - Patrick Gansterer <[email protected]>
+
+description:
+  The LM3509 current mode boost converter offers two separate outputs.
+  https://www.ti.com/product/LM3509
+
+properties:
+  compatible:
+    const: ti,lm3509
+
+  reg:
+    maxItems: 1
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  reset-gpios:
+    maxItems: 1
+
+  ti,brightness-rate-of-change-us:
+    description: Brightness Rate of Change in microseconds.
+    enum: [51, 13000, 26000, 52000]
+
+  ti,oled-mode:
+    description: Enable OLED mode.
+    type: boolean
+
+patternProperties:
+  "^led@[01]$":
+    type: object
+    description: Properties for a string of connected LEDs.
+
+    allOf:
+      - $ref: common.yaml#
+
+    properties:
+      reg:
+        description:
+          The control register that is used to program the two current sinks.
+          The LM3509 has two registers (BMAIN and BSUB) and are represented
+          as 0 or 1 in this property. The two current sinks can be controlled
+          independently with both registers, or register BMAIN can be
+          configured to control both sinks with the led-sources property.
+        minimum: 0
+        maximum: 1
+
+      label: true
+
+      led-sources:
+        allOf:
+          - minItems: 1
+            maxItems: 2
+            items:
+              minimum: 0
+              maximum: 1
+
+      default-brightness:
+        minimum: 0
+        maximum: 31
+        default: 18
+
+      max-brightness:
+        minimum: 0
+        maximum: 31
+        default: 31
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        backlight@36 {
+            compatible = "ti,lm3509";
+            reg = <0x36>;
+            reset-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>;
+
+            ti,oled-mode;
+            ti,brightness-rate-of-change-us = <52000>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            led@0 {
+                reg = <0>;
+                led-sources = <0 1>;
+                label = "lcd-backlight";
+                default-brightness = <12>;
+                max-brightness = <31>;
+            };
+        };
+    };
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        backlight@36 {
+            compatible = "ti,lm3509";
+            reg = <0x36>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            led@0 {
+                reg = <0>;
+                default-brightness = <12>;
+            };
+
+            led@1 {
+                reg = <1>;
+                default-brightness = <15>;
+            };
+        };
+    };
Signature · 1 line
2.44.0
#1 lore raw

PATCH v4 2/2 backlight: Add new lm3509 backlight driver

This is a general driver for LM3509 backlight chip of TI. LM3509 is High Efficiency Boost for White LEDs and/or OLED Displays with Dual Current Sinks. This driver supports OLED/White LED select, brightness control and sub/main control.
The datasheet can be found at http://www.ti.com/product/lm3509.

---
 drivers/video/backlight/Kconfig     |   7 +
 drivers/video/backlight/Makefile    |   1 +
 drivers/video/backlight/lm3509_bl.c | 338 ++++++++++++++++++++++++++++
 3 files changed, 346 insertions(+)
 create mode 100644 drivers/video/backlight/lm3509_bl.c
drivers/video/backlight/Kconfig +7 -0
index ea2d0d69bd8c..96ad5dc584b6 100644
@@ -366,6 +366,13 @@ config BACKLIGHT_AAT2870
 	  If you have a AnalogicTech AAT2870 say Y to enable the
 	  backlight driver.
 
+config BACKLIGHT_LM3509
+	tristate "Backlight Driver for LM3509"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  This supports TI LM3509 Backlight Driver
+
 config BACKLIGHT_LM3630A
 	tristate "Backlight Driver for LM3630A"
 	depends on I2C && PWM
drivers/video/backlight/Makefile +1 -0
index 06966cb20459..51a4ac5d0530 100644
@@ -35,6 +35,7 @@ obj-$(CONFIG_BACKLIGHT_HP700)		+= jornada720_bl.o
 obj-$(CONFIG_BACKLIGHT_IPAQ_MICRO)	+= ipaq_micro_bl.o
 obj-$(CONFIG_BACKLIGHT_KTD253)		+= ktd253-backlight.o
 obj-$(CONFIG_BACKLIGHT_KTZ8866)		+= ktz8866.o
+obj-$(CONFIG_BACKLIGHT_LM3509)		+= lm3509_bl.o
 obj-$(CONFIG_BACKLIGHT_LM3533)		+= lm3533_bl.o
 obj-$(CONFIG_BACKLIGHT_LM3630A)		+= lm3630a_bl.o
 obj-$(CONFIG_BACKLIGHT_LM3639)		+= lm3639_bl.o
drivers/video/backlight/lm3509_bl.c new file +338 -0

338 lines not on this page · raw message

Signature · 1 line
2.44.0
#2 lore raw

Re: [PATCH v4 2/2] backlight: Add new lm3509 backlight driver

^^^
Also not copied to LKML...

Quoted 7 lines · Patrick Gansterer

This is a general driver for LM3509 backlight chip of TI. LM3509 is High Efficiency Boost for White LEDs and/or OLED Displays with Dual Current Sinks. This driver supports OLED/White LED select, brightness control and sub/main control.
The datasheet can be found at http://www.ti.com/product/lm3509.

Overall looks good but there are some review comments inline below.

Quoted 6 lines
drivers/video/backlight/lm3509_bl.c new file +0 -0
new file mode 100644
index 000000000000..696ec8aab6aa

drivers/video/backlight/lm3509_bl.c line 39

Quoted 9 lines
drivers/video/backlight/lm3509_bl.c new file +8 -0
@@ -0,0 +1,338 @@
<snip>
+struct lm3509_bl {
+	struct regmap *regmap;
+	struct backlight_device *bl_main;
+	struct backlight_device *bl_sub;
+	struct gpio_desc *reset_gpio;
+};
+
+struct lm3509_bl_led_pdata {

What does the p stand for here?

(only asking because pdata was the idiomatic form for platform data and this driver only uses DT-only so I'm finding pdata values everywhere really confusing)

Quoted 24 lines
drivers/video/backlight/lm3509_bl.c new file +23 -0
+	const char *label;
+	int led_sources;
+	u32 brightness;
+	u32 max_brightness;
+};
+
+static void lm3509_reset(struct lm3509_bl *data)
+{
+	if (data->reset_gpio) {
+		gpiod_set_value(data->reset_gpio, 1);
+		udelay(1);
+		gpiod_set_value(data->reset_gpio, 0);
+		udelay(10);
+	}
+}
+
<snip>
+
+static struct backlight_device *
+lm3509_backlight_register(struct device *dev, const char *name_suffix,
+			  struct lm3509_bl *data,
+			  const struct backlight_ops *ops,
+			  const struct lm3509_bl_led_pdata *pdata)
+

drivers/video/backlight/lm3509_bl.c line 107

Quoted 10 lines
drivers/video/backlight/lm3509_bl.c new file +10 -0
+{
+	struct backlight_device *bd;
+	struct backlight_properties props;
+	const char *label = pdata->label;
+	char name[64];
+
+	memset(&props, 0, sizeof(props));
+	props.type = BACKLIGHT_RAW;
+	props.brightness = pdata->brightness;
+	props.max_brightness = pdata->max_brightness;

Please set props.scale appropriately for this device (given it only has 32 brightness levels I assume it is non-linear?).

Quoted 77 lines
drivers/video/backlight/lm3509_bl.c new file +76 -0
+
+	if (!label) {
+		snprintf(name, sizeof(name), "lm3509-%s-%s", dev_name(dev),
+			 name_suffix);
+		label = name;
+	}
+
+	bd = devm_backlight_device_register(dev, label, dev, data, ops, &props);
+	if (bd)
+		backlight_update_status(bd);
+
+	return bd;
+}
+
<snip>
+
+static int lm3509_probe(struct i2c_client *client)
+{
+	struct lm3509_bl *data;
+	struct device *dev = &client->dev;
+	int ret;
+	bool oled_mode = false;
+	unsigned int reg_gp_val = 0;
+	struct lm3509_bl_led_pdata pdata[LM3509_NUM_SINKS];
+	u32 rate_of_change = 0;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
+		dev_err(dev, "i2c functionality check failed\n");
+		return -EOPNOTSUPP;
+	}
+
+	data = devm_kzalloc(dev, sizeof(struct lm3509_bl), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->regmap = devm_regmap_init_i2c(client, &lm3509_regmap);
+	if (IS_ERR(data->regmap))
+		return PTR_ERR(data->regmap);
+	i2c_set_clientdata(client, data);
+
+	data->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(data->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(data->reset_gpio),
+				     "Failed to get 'reset' gpio\n");
+
+	lm3509_reset(data);
+
+	memset(pdata, 0, sizeof(pdata));
+	ret = lm3509_parse_dt_node(dev, pdata);
+	if (ret)
+		return ret;
+
+	oled_mode = of_property_read_bool(dev->of_node, "ti,oled-mode");
+
+	if (!of_property_read_u32(dev->of_node,
+				  "ti,brightness-rate-of-change-us",
+				  &rate_of_change)) {
+		switch (rate_of_change) {
+		case 51:
+			reg_gp_val = 0;
+			break;
+		case 13000:
+			reg_gp_val = BIT(REG_GP_RMP1_BIT);
+			break;
+		case 26000:
+			reg_gp_val = BIT(REG_GP_RMP0_BIT);
+			break;
+		case 52000:
+			reg_gp_val = BIT(REG_GP_RMP0_BIT) |
+				     BIT(REG_GP_RMP1_BIT);
+			break;
+		default:
+			dev_warn(dev, "invalid rate of change %u\n",
+				 rate_of_change);
+			break;
+		}
+	}

drivers/video/backlight/lm3509_bl.c line 280

Quoted 10 lines
drivers/video/backlight/lm3509_bl.c new file +10 -0
+
+	if (pdata[0].led_sources ==
+	    (BIT(LM3509_SINK_MAIN) | BIT(LM3509_SINK_SUB)))
+		reg_gp_val |= BIT(REG_GP_UNI_BIT);
+	if (oled_mode)
+		reg_gp_val |= BIT(REG_GP_OLED_BIT);
+
+	ret = regmap_write(data->regmap, REG_GP, reg_gp_val);
+	if (ret < 0)
+		return ret;

Is this the first time we write to the peripheral? If so the error path is probably worth a dev_err_probe() (I don't think regmap_write() logs anything on failure to write).

drivers/video/backlight/lm3509_bl.c line 287

Quoted 6 lines
drivers/video/backlight/lm3509_bl.c new file +6 -0
+	if (pdata[0].led_sources) {
+		data->bl_main = lm3509_backlight_register(
+			dev, "main", data, &lm3509_main_ops, &pdata[0]);
+		if (IS_ERR(data->bl_main)) {
+			dev_err(dev, "failed to register main backlight\n");
+			return PTR_ERR(data->bl_main);

This should use dev_err_probe().

drivers/video/backlight/lm3509_bl.c line 297

Quoted 10 lines
drivers/video/backlight/lm3509_bl.c new file +10 -0
+		}
+	}
+
+	if (pdata[1].led_sources) {
+		data->bl_sub = lm3509_backlight_register(
+			dev, "sub", data, &lm3509_sub_ops, &pdata[1]);
+		if (IS_ERR(data->bl_sub)) {
+			dev_err(dev,
+				"failed to register secondary backlight\n");
+			return PTR_ERR(data->bl_sub);

Another good place for dev_err_probe().

Daniel.

Reviewed-by on v4 1/2
#3 lore raw
In reply to Patrick Gansterer

^^^
Is there any reason this patch wasn't Cc:ed to LKML (it should have come up as part of scripts/get_maintainer.pl)?

Quoted 9 lines · Patrick Gansterer

Add Device Tree bindings for Texas Instruments LM3509 - a High Efficiency Boost for White LED's and/or OLED Displays

---
Changes in v4:
Use backlight_*() to access backlight_device
Do not set backlight_properties.power

This looks like a changelog for the patch set rather than for patch 1. Normally that would be posted in the covering letter rather than here.

Nevertheless:

Daniel.