Skip to contentSkip to conversation

dt-bindings: leds: Add Qualcomm Light Pulse Generator binding

PATCH Superseded Bjorn Andersson 7 participants 11 messages Jun 23, 2021 – Oct 6, 2021

Subsystems (5)

v9 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

PATCH v9 1/2 dt-bindings: leds: Add Qualcomm Light Pulse Generator binding

This adds the binding document describing the three hardware blocks related to the Light Pulse Generator found in a wide range of Qualcomm PMICs.

---

Changes since v8:
- None

Changes since v7:
- Added qcom,pmc8180c-lpg
- Defined constraints for qcom,power-source
- Changes qcom,dtest to matrix and added constraints
- Changed example from LED_COLOR_ID_MULTI to LED_COLOR_ID_RGB

 .../bindings/leds/leds-qcom-lpg.yaml          | 164 ++++++++++++++++++
 1 file changed, 164 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +164 -0
new file mode 100644
index 000000000000..10aee61a7ffc
@@ -0,0 +1,164 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-qcom-lpg.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Light Pulse Generator
+
+maintainers:
+  - Bjorn Andersson <[email protected]>
+
+description: >
+  The Qualcomm Light Pulse Generator consists of three different hardware blocks;
+  a ramp generator with lookup table, the light pulse generator and a three
+  channel current sink. These blocks are found in a wide range of Qualcomm PMICs.
+
+properties:
+  compatible:
+    enum:
+      - qcom,pm8150b-lpg
+      - qcom,pm8150l-lpg
+      - qcom,pm8916-pwm
+      - qcom,pm8941-lpg
+      - qcom,pm8994-lpg
+      - qcom,pmc8180c-lpg
+      - qcom,pmi8994-lpg
+      - qcom,pmi8998-lpg
+
+  "#pwm-cells":
+    const: 2
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  qcom,power-source:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      power-source used to drive the output, as defined in the datasheet.
+      Should be specified if the TRILED block is present
+    enum: [0, 1, 3]
+
+  qcom,dtest:
+    $ref: /schemas/types.yaml#/definitions/uint32-matrix
+    description: >
+      A list of integer pairs, where each pair represent the dtest line the
+      particular channel should be connected to and the flags denoting how the
+      value should be outputed, as defined in the datasheet. The number of
+      pairs should be the same as the number of channels.
+    items:
+      items:
+        - description: dtest line to attach
+        - description: flags for the attachment
+
+  multi-led:
+    type: object
+    $ref: leds-class-multicolor.yaml#
+    properties:
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+      "^led@[0-9a-f]$":
+        type: object
+        $ref: common.yaml#
+
+patternProperties:
+  "^led@[0-9a-f]$":
+    type: object
+    $ref: common.yaml#
+
+    properties:
+      reg: true
+
+    required:
+      - reg
+
+required:
+  - compatible
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/leds/common.h>
+
+    lpg {
+      compatible = "qcom,pmi8994-lpg";
+
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      qcom,power-source = <1>;
+
+      qcom,dtest = <0 0>,
+                   <0 0>,
+                   <0 0>,
+                   <4 1>;
+
+      led@1 {
+        reg = <1>;
+        label = "green:user1";
+      };
+
+      led@2 {
+        reg = <2>;
+        label = "green:user0";
+        default-state = "on";
+      };
+
+      led@3 {
+        reg = <3>;
+        label = "green:user2";
+      };
+
+      led@4 {
+        reg = <4>;
+        label = "green:user3";
+      };
+    };
+  - |
+    #include <dt-bindings/leds/common.h>
+
+    lpg {
+      compatible = "qcom,pmi8994-lpg";
+
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      qcom,power-source = <1>;
+
+      multi-led {
+        color = <LED_COLOR_ID_RGB>;
+        function = LED_FUNCTION_STATUS;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        led@1 {
+          reg = <1>;
+          color = <LED_COLOR_ID_RED>;
+        };
+
+        led@2 {
+          reg = <2>;
+          color = <LED_COLOR_ID_GREEN>;
+        };
+
+        led@3 {
+          reg = <3>;
+          color = <LED_COLOR_ID_BLUE>;
+        };
+      };
+    };
+  - |
+    lpg {
+      compatible = "qcom,pm8916-pwm";
+      #pwm-cells = <2>;
+    };
+...
Signature · 1 line
2.29.2
#1 lore raw

PATCH v9 2/2 leds: Add driver for Qualcomm LPG

The Light Pulse Generator (LPG) is a PWM-block found in a wide range of PMICs from Qualcomm. These PMICs typically comes with 1-8 LPG instances, with their output being routed to various other components, such as current sinks or GPIOs.

Each LPG instance can operate on fixed parameters or based on a shared lookup-table, altering the duty cycle over time. This provides the means for hardware assisted transitions of LED brightness.

A typical use case for the fixed parameter mode is to drive a PWM backlight control signal, the driver therefor allows each LPG instance to be exposed to the kernel either through the LED framework or the PWM framework.

A typical use case for the LED configuration is to drive RGB LEDs in smartphones etc, for which the driver support multiple channels to be ganged up to a MULTICOLOR LED. In this configuration the pattern generators will be synchronized, to allow for multi-color patterns.

---

Changes since v8:
- Dropped unused "pattern_len" variable
- Promoted NSEC_PER_SEC to u64 in lpg_calc_freq() to prevent overflow on 32-bit architectures
- Replaced all naive divisions with proper u64 versions
- Cap period to largest possible, to avoid integer overflows
- Fixed up missing kernel-doc entry in struct lpg

Changes since v7:
- Rewrote lpg_calc_freq() from scratch, to improve accuracy and only round period down
- Based duty cycle on actual period, rather than requested
- Ensured that PWM_DEBUG is happy wrt settings being idempotent and less than requested values
- Transitioned period and duty calculations to be done in nanoseconds
- Dropped 6-bit resolution, to simplify math and because the latest (yet to be added) doesn't support it anyways
- No more .base = -1 in the pwm_chip
- Update delay_o{n,ff} in blink_set to retun the programmed values
- Return error from pwm_chip apply function when too small period is requested

 drivers/leds/Kconfig             |    3 +
 drivers/leds/Makefile            |    3 +
 drivers/leds/rgb/Kconfig         |   13 +
 drivers/leds/rgb/Makefile        |    3 +
 drivers/leds/rgb/leds-qcom-lpg.c | 1302 ++++++++++++++++++++++++++++++
 5 files changed, 1324 insertions(+)
 create mode 100644 drivers/leds/rgb/Kconfig
 create mode 100644 drivers/leds/rgb/Makefile
 create mode 100644 drivers/leds/rgb/leds-qcom-lpg.c
drivers/leds/Kconfig +3 -0
index bdf16180f5ff..7e627922005c 100644
@@ -933,6 +933,9 @@ source "drivers/leds/blink/Kconfig"
 comment "Flash and Torch LED drivers"
 source "drivers/leds/flash/Kconfig"
 
+comment "RGB LED drivers"
+source "drivers/leds/rgb/Kconfig"
+
 comment "LED Triggers"
 source "drivers/leds/trigger/Kconfig"
 
drivers/leds/Makefile +3 -0
index 7e604d3028c8..8cad0465aae0 100644
@@ -106,6 +106,9 @@ obj-$(CONFIG_LEDS_USER)			+= uleds.o
 # Flash and Torch LED Drivers
 obj-$(CONFIG_LEDS_CLASS_FLASH)		+= flash/
 
+# RGB LED Drivers
+obj-$(CONFIG_LEDS_CLASS_MULTICOLOR)	+= rgb/
+
 # LED Triggers
 obj-$(CONFIG_LEDS_TRIGGERS)		+= trigger/
 
drivers/leds/rgb/Kconfig new file +13 -0
new file mode 100644
index 000000000000..20be3e11fe4a
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0
+
+if LEDS_CLASS_MULTICOLOR
+
+config LEDS_QCOM_LPG
+	tristate "LED support for Qualcomm LPG"
+	depends on OF
+	depends on SPMI
+	help
+	  This option enables support for the Light Pulse Generator found in a
+	  wide variety of Qualcomm PMICs.
+
+endif # LEDS_CLASS_MULTICOLOR
drivers/leds/rgb/Makefile new file +3 -0
new file mode 100644
index 000000000000..83114f44c4ea
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_LEDS_QCOM_LPG)	+= leds-qcom-lpg.o
drivers/leds/rgb/leds-qcom-lpg.c new file +1302 -0

1,302 lines not on this page · raw message

Signature · 1 line
2.29.2
#2 lore raw

Re: [PATCH v9 2/2] leds: Add driver for Qualcomm LPG

Hello Bjorn,

Quoted 26 lines · Bjorn Andersson
drivers/leds/rgb/leds-qcom-lpg.c new file +26 -0
+static const unsigned int lpg_clk_rates[] = {1024, 32768, 19200000};
+static const unsigned int lpg_pre_divs[] = {1, 3, 5, 6};
+
+static int lpg_calc_freq(struct lpg_channel *chan, uint64_t period)
+{
+	unsigned int clk, best_clk = 0;
+	unsigned int div, best_div = 0;
+	unsigned int m, best_m = 0;
+	unsigned int error;
+	unsigned int best_err = UINT_MAX;
+	u64 denom;
+	u64 best_period = 0;
+	u64 actual;
+	u64 ratio;
+	u64 nom;
+
+	/*
+	 * The PWM period is determined by:
+	 *
+	 *          resolution * pre_div * 2^M
+	 * period = --------------------------
+	 *                   refclk
+	 *
+	 * With resolution fixed at 2^9 bits, pre_div = {1, 3, 5, 6} and
+	 * M = [0..7].
+	 *

drivers/leds/rgb/leds-qcom-lpg.c line 283

Quoted 10 lines
drivers/leds/rgb/leds-qcom-lpg.c new file +10 -0
+	 * This allows for periods between 27uS and 381s, as the PWM framework
+	 * wants a period of equal or lower length than requested, reject
+	 * anything below 27uS.
+	 */
+	if (period <= (u64)NSEC_PER_SEC * LPG_RESOLUTION / 19200000)
+		return -EINVAL;
+
+	/* Limit period to largest possible value, to avoid overflows */
+	if (period > 381 * (u64)NSEC_PER_SEC)
+		period = 381 * (u64)NSEC_PER_SEC;

Where does the magic 381 come from? This would be more obviously correct if you write out the formula as you did for the check above.

drivers/leds/rgb/leds-qcom-lpg.c line 294

Quoted 10 lines
drivers/leds/rgb/leds-qcom-lpg.c new file +10 -0
+	/*
+	 * Search for the pre_div, clk and M by solving the rewritten formula
+	 * for each clk and pre_div value:
+	 *
+	 *                       period * clk
+	 * M = log2 -------------------------------------
+	 *           NSEC_PER_SEC * pre_div * resolution
+	 */
+	for (clk = 0; clk < ARRAY_SIZE(lpg_clk_rates); clk++) {
+		nom = period * lpg_clk_rates[clk];

nom is only used in this block, so the declaration can be put in here, too. Ditto for at least ratio and actual.

Quoted 28 lines
drivers/leds/rgb/leds-qcom-lpg.c new file +28 -0
+
+		for (div = 0; div < ARRAY_SIZE(lpg_pre_divs); div++) {
+			denom = (u64)NSEC_PER_SEC * lpg_pre_divs[div] * (1 << 9);
+
+			if (nom < denom)
+				continue;
+
+			ratio = div64_u64(nom, denom);
+			m = ilog2(ratio);
+			if (m > LPG_MAX_M)
+				m = LPG_MAX_M;
+
+			actual = DIV_ROUND_UP_ULL(denom * (1 << m), lpg_clk_rates[clk]);
+
+			error = period - actual;
+			if (error < best_err) {
+				best_err = error;
+
+				best_div = div;
+				best_m = m;
+				best_clk = clk;
+				best_period = actual;
+			}
+		}
+	}
+
+	chan->clk = best_clk;
+	chan->pre_div = best_div;

drivers/leds/rgb/leds-qcom-lpg.c line 332

Quoted 10 lines
drivers/leds/rgb/leds-qcom-lpg.c new file +10 -0
+	chan->pre_div_exp = best_m;
+	chan->period = best_period;
+
+	return 0;
+}
+
+static void lpg_calc_duty(struct lpg_channel *chan, uint64_t duty)
+{
+	unsigned int max = LPG_RESOLUTION - 1;
+	unsigned int val = div_u64(duty * max, chan->period);

You're losing precision here as chan->period is a rounded value.

duty * max might overflow.

drivers/leds/rgb/leds-qcom-lpg.c line 523

Quoted 6 lines
drivers/leds/rgb/leds-qcom-lpg.c new file +5 -0
+	chan->pwm_value = min(val, max);
+}
[...]
+static void lpg_apply(struct lpg_channel *chan)
+{
+	lpg_disable_glitch(chan);

Why do you have to do this?

Quoted 10 lines
(quoted diff) +9 -0
+	lpg_apply_freq(chan);
+	lpg_apply_pwm_value(chan);
+	lpg_apply_control(chan);
+	lpg_apply_sync(chan);
+	lpg_apply_lut_control(chan);
+	lpg_enable_glitch(chan);
+}
[...]
+/*
+ * Limitations:

Review

Quoted 10 lines
(quoted diff) +10 -0
+ * - Updating both duty and period is not done atomically, so the output signal
+ *   will momentarily be a mix of the settings.
+ */
+static int lpg_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
+			 const struct pwm_state *state)
+{
+	struct lpg *lpg = container_of(chip, struct lpg, pwm);
+	struct lpg_channel *chan = &lpg->channels[pwm->hwpwm];
+	int ret;
+

You have to care for state->polarity here.

Quoted 51 lines
drivers/leds/rgb/leds-qcom-lpg.c new file +50 -0
+	ret = lpg_calc_freq(chan, state->period);
+	if (ret < 0)
+		return ret;
+
+	lpg_calc_duty(chan, state->duty_cycle);
+	chan->enabled = state->enabled;
+
+	lpg_apply(chan);
+
+	triled_set(lpg, chan->triled_mask, chan->enabled ? chan->triled_mask : 0);
+
+	return 0;
+}
[...]
+static int lpg_probe(struct platform_device *pdev)
+{
+	struct device_node *np;
+	struct lpg *lpg;
+	int ret;
+	int i;
+
+	lpg = devm_kzalloc(&pdev->dev, sizeof(*lpg), GFP_KERNEL);
+	if (!lpg)
+		return -ENOMEM;
+
+	lpg->data = of_device_get_match_data(&pdev->dev);
+	if (!lpg->data)
+		return -EINVAL;
+
+	lpg->dev = &pdev->dev;
+
+	lpg->map = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!lpg->map) {
+		dev_err(&pdev->dev, "parent regmap unavailable\n");
+		return -ENXIO;
+	}
+
+	ret = lpg_init_channels(lpg);
+	if (ret < 0)
+		return ret;
+
+	ret = lpg_parse_dtest(lpg);
+	if (ret < 0)
+		return ret;
+
+	ret = lpg_init_triled(lpg);
+	if (ret < 0)
+		return ret;
+
+	ret = lpg_init_lut(lpg);
+	if (ret < 0)

drivers/leds/rgb/leds-qcom-lpg.c

Quoted 10 lines
drivers/leds/rgb/leds-qcom-lpg.c new file +10 -0
+		return ret;
+
+	for_each_available_child_of_node(pdev->dev.of_node, np) {
+		ret = lpg_add_led(lpg, np);
+		if (ret)
+			return ret;
+	}
+
+	for (i = 0; i < lpg->num_channels; i++)
+		lpg_apply_dtest(&lpg->channels[i]);

I wonder what all these register initialisations do. You should not do anything that modifies the PWM output here that the bootloader might have setup. Is this given?

drivers/leds/rgb/leds-qcom-lpg.c line 1139

Quoted 2 lines
drivers/leds/rgb/leds-qcom-lpg.c new file +2 -0
+
+	ret = lpg_add_pwm(lpg);

The patch would be easier to review if you split it into a led part and a pwm part. Then the responsibilities would be more clear, too.

drivers/leds/rgb/leds-qcom-lpg.c line 1145

Quoted 6 lines
drivers/leds/rgb/leds-qcom-lpg.c new file +6 -0
+	if (ret)
+		return ret;
+
+	platform_set_drvdata(pdev, lpg);
+
+	return 0;

If you do the platform_set_drvdata() earlier you can just

	return ret;

here.

Quoted 1 line

+}

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
maintainer Reviewed-by on v9 1/2
#3 lore raw
In reply to Bjorn Andersson
Quoted 16 lines · Bjorn Andersson

This adds the binding document describing the three hardware blocks related to the Light Pulse Generator found in a wide range of Qualcomm PMICs.

---

Changes since v8:
- None

Changes since v7:
- Added qcom,pmc8180c-lpg
- Defined constraints for qcom,power-source
- Changes qcom,dtest to matrix and added constraints
- Changed example from LED_COLOR_ID_MULTI to LED_COLOR_ID_RGB

Quoted 4 lines
 .../bindings/leds/leds-qcom-lpg.yaml          | 164 ++++++++++++++++++
 1 file changed, 164 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml
#4 lore raw
In reply to Bjorn Andersson
Quoted 1 line · On Tue, 22 Jun 2021 20:50:38 -0700 Bjorn Andersson…

+++ b/Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml

The file name should be based on one of the compatible strings, for example the first one:
qcom,pm8150b-lpg.yaml

Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml line 107

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +4 -0
+      led@1 {
+        reg = <1>;
+        label = "green:user1";
+      };

label is deprecated, please don't use in new bindings in examples. Instead use color, function and function-enumerator, i.e.

  color = <LED_COLOR_ID_GREEN>;
  function = LED_FUNCTION_xxx;
  function-enumerator = <N>;
#5 lore raw
Quoted 9 lines · Marek Behun
Quoted 1 line · On Tue, 22 Jun 2021 20:50:38 -0700 Bjorn Andersson…

+++ b/Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml

The file name should be based on one of the compatible strings, for example the first one:
qcom,pm8150b-lpg.yaml

The majority of the files in leds/ are named leds-*.yaml, is this a new scheme for LED bindings?

Quoted 6 lines

Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml line 107

Quoted 4 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +4 -0
+      led@1 {
+        reg = <1>;
+        label = "green:user1";
+      };

label is deprecated,

Sorry, I missed the comment in the middle of the description about this. Is there any particular reason why this isn't marked deprecated: true?

Quoted 7 lines

please don't use in new bindings in examples. Instead use color, function and function-enumerator, i.e.

  color = <LED_COLOR_ID_GREEN>;
  function = LED_FUNCTION_xxx;
  function-enumerator = <N>;

Can you point me to something helping me regarding what "function" to use?

For this particular devboard that the example comes from I have 4 LEDs that are named "user1", "user2", "user3" and "user4" in the board documentation. I can make up whatever for the example, but I would like to get the following dts additions follow the expected guidelines.

Regards,
Bjorn

#6 lore raw

Hello Bjorn,

Am Thu, Jun 24, 2021 at 06:44:54PM -0500 schrieb Bjorn Andersson:

Quoted 9 lines · Marek Behun
Quoted 7 lines

please don't use in new bindings in examples. Instead use color, function and function-enumerator, i.e.

  color = <LED_COLOR_ID_GREEN>;
  function = LED_FUNCTION_xxx;
  function-enumerator = <N>;
Quoted 7 lines

Can you point me to something helping me regarding what "function" to use?

For this particular devboard that the example comes from I have 4 LEDs that are named "user1", "user2", "user3" and "user4" in the board documentation. I can make up whatever for the example, but I would like to get the following dts additions follow the expected guidelines.

I asked myself the same question in the past. The wohle list is in 'include/dt-bindings/leds/common.h' and I in my personal project I opted for LED_FUNCTION_INDICATOR, but yes, the confusion is real.

Greets
Alex

#7 lore raw
In reply to Bjorn Andersson

Quoting Bjorn Andersson (2021-06-22 20:50:38)

Quoted 6 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +0 -0
new file mode 100644
index 000000000000..10aee61a7ffc
@@ -0,0 +1,164 @@

[....]

Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml line 91

Quoted 5 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +5 -0
+examples:
+  - |
+    #include <dt-bindings/leds/common.h>
+
+    lpg {

Should the node name be led or leds?

Quoted 1 line

+ compatible = "qcom,pmi8994-lpg";

Shouldn't there be a reg property? I see the driver has them hardcoded but if this is a child of the spmi node then it should have a reg property (or many reg properties).

#8 lore raw

Hei hei,

Am Wed, Sep 08, 2021 at 03:39:51AM +0000 schrieb Stephen Boyd:

Quoted 8 lines

Quoting Bjorn Andersson (2021-06-22 20:50:38)

Quoted 6 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +0 -0
new file mode 100644
index 000000000000..10aee61a7ffc
@@ -0,0 +1,164 @@

[....]

Quoted 7 lines

Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml line 91

Quoted 5 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +5 -0
+examples:
+  - |
+    #include <dt-bindings/leds/common.h>
+
+    lpg {

Should the node name be led or leds?

If I scan through Documentation/devicetree/bindings/leds and look at other devices, it should probably be named "led-controller", right?

At least that's what Rob suggested when I converted the leds-pwm binding last year, using generic node names:

https://lore.kernel.org/linux-leds/20200922155747.GA2734659@bogus/

Greets
Alex

Quoted 6 lines
Quoted 2 lines

+ compatible = "qcom,pmi8994-lpg";

Shouldn't there be a reg property? I see the driver has them hardcoded but if this is a child of the spmi node then it should have a reg property (or many reg properties).

#9 lore raw
In reply to Bjorn Andersson
Quoted 176 lines · Bjorn Andersson

This adds the binding document describing the three hardware blocks related to the Light Pulse Generator found in a wide range of Qualcomm PMICs.

---

Changes since v8:
- None

Changes since v7:
- Added qcom,pmc8180c-lpg
- Defined constraints for qcom,power-source
- Changes qcom,dtest to matrix and added constraints
- Changed example from LED_COLOR_ID_MULTI to LED_COLOR_ID_RGB

 .../bindings/leds/leds-qcom-lpg.yaml          | 164 ++++++++++++++++++
 1 file changed, 164 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +150 -0
new file mode 100644
index 000000000000..10aee61a7ffc
@@ -0,0 +1,164 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/leds-qcom-lpg.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Light Pulse Generator
+
+maintainers:
+  - Bjorn Andersson <[email protected]>
+
+description: >
+  The Qualcomm Light Pulse Generator consists of three different hardware blocks;
+  a ramp generator with lookup table, the light pulse generator and a three
+  channel current sink. These blocks are found in a wide range of Qualcomm PMICs.
+
+properties:
+  compatible:
+    enum:
+      - qcom,pm8150b-lpg
+      - qcom,pm8150l-lpg
+      - qcom,pm8916-pwm
+      - qcom,pm8941-lpg
+      - qcom,pm8994-lpg
+      - qcom,pmc8180c-lpg
+      - qcom,pmi8994-lpg
+      - qcom,pmi8998-lpg
+
+  "#pwm-cells":
+    const: 2
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  qcom,power-source:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      power-source used to drive the output, as defined in the datasheet.
+      Should be specified if the TRILED block is present
+    enum: [0, 1, 3]
+
+  qcom,dtest:
+    $ref: /schemas/types.yaml#/definitions/uint32-matrix
+    description: >
+      A list of integer pairs, where each pair represent the dtest line the
+      particular channel should be connected to and the flags denoting how the
+      value should be outputed, as defined in the datasheet. The number of
+      pairs should be the same as the number of channels.
+    items:
+      items:
+        - description: dtest line to attach
+        - description: flags for the attachment
+
+  multi-led:
+    type: object
+    $ref: leds-class-multicolor.yaml#
+    properties:
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+      "^led@[0-9a-f]$":
+        type: object
+        $ref: common.yaml#
+
+patternProperties:
+  "^led@[0-9a-f]$":
+    type: object
+    $ref: common.yaml#
+
+    properties:
+      reg: true
+
+    required:
+      - reg
+
+required:
+  - compatible
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/leds/common.h>
+
+    lpg {
+      compatible = "qcom,pmi8994-lpg";
+
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      qcom,power-source = <1>;
+
+      qcom,dtest = <0 0>,
+                   <0 0>,
+                   <0 0>,
+                   <4 1>;
+
+      led@1 {
+        reg = <1>;
+        label = "green:user1";
+      };
+
+      led@2 {
+        reg = <2>;
+        label = "green:user0";
+        default-state = "on";
+      };
+
+      led@3 {
+        reg = <3>;
+        label = "green:user2";
+      };
+
+      led@4 {
+        reg = <4>;
+        label = "green:user3";
+      };
+    };
+  - |
+    #include <dt-bindings/leds/common.h>
+
+    lpg {
+      compatible = "qcom,pmi8994-lpg";
+
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      qcom,power-source = <1>;
+
+      multi-led {
+        color = <LED_COLOR_ID_RGB>;
+        function = LED_FUNCTION_STATUS;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        led@1 {
+          reg = <1>;
+          color = <LED_COLOR_ID_RED>;
+        };
+
+        led@2 {
+          reg = <2>;
+          color = <LED_COLOR_ID_GREEN>;

Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml line 160

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +10 -0
+        };
+
+        led@3 {
+          reg = <3>;
+          color = <LED_COLOR_ID_BLUE>;
+        };
+      };
+    };
+  - |
+    lpg {

nit: should the node be named 'lpg-pwm'?

IIUC a PMIC .dtsi could have both a 'lpg' and a 'lpg-pwm' node, even though only one of them can be enabled at any time.

Quoted 3 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +3 -0
+      compatible = "qcom,pm8916-pwm";
+      #pwm-cells = <2>;
+    };
#10 lore raw
Quoted 1 line · Matthias Kaehlcke

On Tue, Jun 22, 2021 at 08:50:38PM -0700, Bjorn Andersson wrote:

[..]

Quoted 39 lines
Quoted 26 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +26 -0
+  - |
+    #include <dt-bindings/leds/common.h>
+
+    lpg {
+      compatible = "qcom,pmi8994-lpg";
+
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      qcom,power-source = <1>;
+
+      multi-led {
+        color = <LED_COLOR_ID_RGB>;
+        function = LED_FUNCTION_STATUS;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        led@1 {
+          reg = <1>;
+          color = <LED_COLOR_ID_RED>;
+        };
+
+        led@2 {
+          reg = <2>;
+          color = <LED_COLOR_ID_GREEN>;

Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml line 160

Quoted 10 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +10 -0
+        };
+
+        led@3 {
+          reg = <3>;
+          color = <LED_COLOR_ID_BLUE>;
+        };
+      };
+    };
+  - |
+    lpg {

nit: should the node be named 'lpg-pwm'?

Quoted 3 lines

IIUC a PMIC .dtsi could have both a 'lpg' and a 'lpg-pwm' node, even though only one of them can be enabled at any time.

No, there's only the one "LPG", with N channels. The lpg exposes a pwm chip and the child nodes may describe LEDs connected to the channels. So this example is the configuration where there's no LEDs attached.

The compatible is "pwm", because the PM8916 lacks the pattern and RGB blocks that makes up the LPG - and is hence named "PWM" in the datasheet instead. So perhaps the example should be generically named "pwm" instead.

In all other PMICs I know of the hardware block is named "lpg".

Regards,
Bjorn

Quoted 3 lines
Quoted 3 lines
Documentation/devicetree/bindings/leds/leds-qcom-lpg.yaml new file +3 -0
+      compatible = "qcom,pm8916-pwm";
+      #pwm-cells = <2>;
+    };