linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] backlight: ktz8866: improve it and support slave
@ 2025-04-07  9:51 Pengyu Luo
  2025-04-07  9:51 ` [PATCH 1/4] dt-bindings: backlight: kinetic,ktz8866: add ktz8866 slave compatible Pengyu Luo
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Pengyu Luo @ 2025-04-07  9:51 UTC (permalink / raw)
  To: Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han, Pavel Machek,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Helge Deller
  Cc: dri-devel, linux-leds, devicetree, linux-kernel, linux-fbdev,
	Pengyu Luo

Sending this patchset to support coming devices which are using dual
ktz8866, original driver would only handle half backlight region on
these devices, registering it twice is unreasonable,  and two devices
share the same resources(pinctrl) which is required for every single
node under recent dt-bindings, so adding new support. and improve
original driver. Details in every commit log.

Pengyu Luo (4):
  dt-bindings: backlight: kinetic,ktz8866: add ktz8866 slave compatible
  backlight: ktz8866: add slave handler
  backlight: ktz8866: improve current sinks setting
  backlight: ktz8866: add definitions to make it more readable

 .../leds/backlight/kinetic,ktz8866.yaml       | 29 +++++-
 drivers/video/backlight/ktz8866.c             | 99 ++++++++++++++++---
 2 files changed, 108 insertions(+), 20 deletions(-)

-- 
2.49.0


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

* [PATCH 1/4] dt-bindings: backlight: kinetic,ktz8866: add ktz8866 slave compatible
  2025-04-07  9:51 [PATCH 0/4] backlight: ktz8866: improve it and support slave Pengyu Luo
@ 2025-04-07  9:51 ` Pengyu Luo
  2025-04-07  9:57   ` Krzysztof Kozlowski
  2025-04-07  9:51 ` [PATCH 2/4] backlight: ktz8866: add slave handler Pengyu Luo
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Pengyu Luo @ 2025-04-07  9:51 UTC (permalink / raw)
  To: Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han, Pavel Machek,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Helge Deller
  Cc: dri-devel, linux-leds, devicetree, linux-kernel, linux-fbdev,
	Pengyu Luo

Kinetic ktz8866, found in many android devices, nowadays, some oem use
dual ktz8866 to support a larger panel and  higher brightness, add the
binding for slave case.

Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
---
 .../leds/backlight/kinetic,ktz8866.yaml       | 29 +++++++++++++++----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml b/Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml
index c914e1276..825a6fbf1 100644
--- a/Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml
+++ b/Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml
@@ -19,7 +19,9 @@ allOf:
 
 properties:
   compatible:
-    const: kinetic,ktz8866
+    enum:
+      - kinetic,ktz8866
+      - kinetic,ktz8866-slave
 
   reg:
     maxItems: 1
@@ -58,9 +60,16 @@ properties:
 required:
   - compatible
   - reg
-  - vddpos-supply
-  - vddneg-supply
-  - enable-gpios
+
+if:
+  properties:
+    compatible:
+      const: kinetic,ktz8866
+then:
+  required:
+    - vddpos-supply
+    - vddneg-supply
+    - enable-gpios
 
 unevaluatedProperties: false
 
@@ -68,7 +77,7 @@ examples:
   - |
     #include <dt-bindings/gpio/gpio.h>
 
-    i2c {
+    i2c0 {
         #address-cells = <1>;
         #size-cells = <0>;
 
@@ -84,3 +93,13 @@ examples:
             kinetic,enable-lcd-bias;
         };
     };
+
+    i2c1 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        backlight@11 {
+            compatible = "kinetic,ktz8866-slave";
+            reg = <0x11>;
+        };
+    };
-- 
2.49.0


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

* [PATCH 2/4] backlight: ktz8866: add slave handler
  2025-04-07  9:51 [PATCH 0/4] backlight: ktz8866: improve it and support slave Pengyu Luo
  2025-04-07  9:51 ` [PATCH 1/4] dt-bindings: backlight: kinetic,ktz8866: add ktz8866 slave compatible Pengyu Luo
@ 2025-04-07  9:51 ` Pengyu Luo
  2025-04-07 10:00   ` Krzysztof Kozlowski
  2025-04-07 16:27   ` Daniel Thompson
  2025-04-07  9:51 ` [PATCH 3/4] backlight: ktz8866: improve current sinks setting Pengyu Luo
  2025-04-07  9:51 ` [PATCH 4/4] backlight: ktz8866: add definitions to make it more readable Pengyu Luo
  3 siblings, 2 replies; 16+ messages in thread
From: Pengyu Luo @ 2025-04-07  9:51 UTC (permalink / raw)
  To: Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han, Pavel Machek,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Helge Deller
  Cc: dri-devel, linux-leds, devicetree, linux-kernel, linux-fbdev,
	Pengyu Luo

Kinetic ktz8866, found in many android devices, nowadays, some oem use
dual ktz8866 to support a larger panel and  higher brightness, original
driver would only handle half backlight region on these devices,
registering it twice is unreasonable, so adding the slave handler to
support it.

Note that, none of the devices supported by upstream require this, the
devices using this is porting.

Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
---
 drivers/video/backlight/ktz8866.c | 68 +++++++++++++++++++++++++++----
 1 file changed, 59 insertions(+), 9 deletions(-)

diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c
index 351c2b4d6..017ad80dd 100644
--- a/drivers/video/backlight/ktz8866.c
+++ b/drivers/video/backlight/ktz8866.c
@@ -3,6 +3,9 @@
  * Backlight driver for the Kinetic KTZ8866
  *
  * Copyright (C) 2022, 2023 Jianhua Lu <lujianhua000@gmail.com>
+ *
+ * Apr 2025 - Pengyu Luo <mitltlatltl@gmail.com>
+ *	Added handling for dual KTZ8866(master and slave)
  */
 
 #include <linux/backlight.h>
@@ -43,11 +46,17 @@
 #define LCD_BIAS_EN 0x9F
 #define PWM_HYST 0x5
 
+struct ktz8866_slave {
+	struct i2c_client *client;
+	struct regmap *regmap;
+};
+
 struct ktz8866 {
 	struct i2c_client *client;
 	struct regmap *regmap;
-	bool led_on;
 	struct gpio_desc *enable_gpio;
+	struct ktz8866_slave *slave;
+	bool led_on;
 };
 
 static const struct regmap_config ktz8866_regmap_config = {
@@ -56,16 +65,22 @@ static const struct regmap_config ktz8866_regmap_config = {
 	.max_register = REG_MAX,
 };
 
-static int ktz8866_write(struct ktz8866 *ktz, unsigned int reg,
-			 unsigned int val)
+static void ktz8866_write(struct ktz8866 *ktz, unsigned int reg,
+			  unsigned int val)
 {
-	return regmap_write(ktz->regmap, reg, val);
+	regmap_write(ktz->regmap, reg, val);
+
+	if (ktz->slave)
+		regmap_write(ktz->slave->regmap, reg, val);
 }
 
-static int ktz8866_update_bits(struct ktz8866 *ktz, unsigned int reg,
-			       unsigned int mask, unsigned int val)
+static void ktz8866_update_bits(struct ktz8866 *ktz, unsigned int reg,
+				unsigned int mask, unsigned int val)
 {
-	return regmap_update_bits(ktz->regmap, reg, mask, val);
+	regmap_update_bits(ktz->regmap, reg, mask, val);
+
+	if (ktz->slave)
+		regmap_update_bits(ktz->slave->regmap, reg, mask, val);
 }
 
 static int ktz8866_backlight_update_status(struct backlight_device *backlight_dev)
@@ -124,10 +139,41 @@ static void ktz8866_init(struct ktz8866 *ktz)
 		ktz8866_write(ktz, LCD_BIAS_CFG1, LCD_BIAS_EN);
 }
 
+static int ktz8866_slave_register(struct ktz8866 *ktz)
+{
+	struct device *dev = &ktz->client->dev;
+	struct ktz8866_slave *slave;
+	struct i2c_client *client;
+	struct device_node *np;
+
+	np = of_find_compatible_node(NULL, NULL, "kinetic,ktz8866-slave");
+	if (!np)
+		return 0;
+
+	client = of_find_i2c_device_by_node(np);
+	of_node_put(np);
+	if (!client)
+		return 0;
+
+	slave = devm_kzalloc(dev, sizeof(*slave), GFP_KERNEL);
+	if (!slave)
+		return -ENOMEM;
+
+	slave->client = client;
+	slave->regmap = devm_regmap_init_i2c(client, &ktz8866_regmap_config);
+	if (IS_ERR(slave->regmap))
+		return dev_err_probe(&client->dev, PTR_ERR(slave->regmap),
+				     "failed to init regmap\n");
+
+	ktz->slave = slave;
+
+	return 0;
+}
+
 static int ktz8866_probe(struct i2c_client *client)
 {
 	struct backlight_device *backlight_dev;
-	struct backlight_properties props;
+	struct backlight_properties props = {};
 	struct ktz8866 *ktz;
 	int ret = 0;
 
@@ -151,7 +197,6 @@ static int ktz8866_probe(struct i2c_client *client)
 	if (IS_ERR(ktz->enable_gpio))
 		return PTR_ERR(ktz->enable_gpio);
 
-	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
 	props.max_brightness = MAX_BRIGHTNESS;
 	props.brightness = DEFAULT_BRIGHTNESS;
@@ -163,6 +208,11 @@ static int ktz8866_probe(struct i2c_client *client)
 		return dev_err_probe(&client->dev, PTR_ERR(backlight_dev),
 				"failed to register backlight device\n");
 
+	ret = ktz8866_slave_register(ktz);
+	if (ret)
+		return dev_err_probe(&client->dev, ret,
+				     "failed to register slave\n");
+
 	ktz8866_init(ktz);
 
 	i2c_set_clientdata(client, backlight_dev);
-- 
2.49.0


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

* [PATCH 3/4] backlight: ktz8866: improve current sinks setting
  2025-04-07  9:51 [PATCH 0/4] backlight: ktz8866: improve it and support slave Pengyu Luo
  2025-04-07  9:51 ` [PATCH 1/4] dt-bindings: backlight: kinetic,ktz8866: add ktz8866 slave compatible Pengyu Luo
  2025-04-07  9:51 ` [PATCH 2/4] backlight: ktz8866: add slave handler Pengyu Luo
@ 2025-04-07  9:51 ` Pengyu Luo
  2025-04-07 16:13   ` Daniel Thompson
                     ` (2 more replies)
  2025-04-07  9:51 ` [PATCH 4/4] backlight: ktz8866: add definitions to make it more readable Pengyu Luo
  3 siblings, 3 replies; 16+ messages in thread
From: Pengyu Luo @ 2025-04-07  9:51 UTC (permalink / raw)
  To: Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han, Pavel Machek,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Helge Deller
  Cc: dri-devel, linux-leds, devicetree, linux-kernel, linux-fbdev,
	Pengyu Luo

I polled all registers when the module was loading, found that
current sinks have already been configured. Bootloader would set
when booting. So checking it before setting the all channels.

Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
---
 drivers/video/backlight/ktz8866.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c
index 017ad80dd..b67ca136d 100644
--- a/drivers/video/backlight/ktz8866.c
+++ b/drivers/video/backlight/ktz8866.c
@@ -46,6 +46,8 @@
 #define LCD_BIAS_EN 0x9F
 #define PWM_HYST 0x5
 
+#define CURRENT_SINKS_MASK GENMASK(5, 0)
+
 struct ktz8866_slave {
 	struct i2c_client *client;
 	struct regmap *regmap;
@@ -65,6 +67,12 @@ static const struct regmap_config ktz8866_regmap_config = {
 	.max_register = REG_MAX,
 };
 
+static inline void ktz8866_read(struct ktz8866 *ktz, unsigned int reg,
+				unsigned int *val)
+{
+	regmap_read(ktz->regmap, reg, &val);
+}
+
 static void ktz8866_write(struct ktz8866 *ktz, unsigned int reg,
 			  unsigned int val)
 {
@@ -112,11 +120,18 @@ static void ktz8866_init(struct ktz8866 *ktz)
 {
 	unsigned int val = 0;
 
-	if (!of_property_read_u32(ktz->client->dev.of_node, "current-num-sinks", &val))
+	if (!of_property_read_u32(ktz->client->dev.of_node, "current-num-sinks", &val)) {
 		ktz8866_write(ktz, BL_EN, BIT(val) - 1);
-	else
-		/* Enable all 6 current sinks if the number of current sinks isn't specified. */
-		ktz8866_write(ktz, BL_EN, BIT(6) - 1);
+	} else {
+		/*
+		 * Enable all 6 current sinks if the number of current
+		 * sinks isn't specified and the bootloader didn't set
+		 * the value.
+		 */
+		ktz8866_read(ktz, BL_EN, &val);
+		if (!(val && CURRENT_SINKS_MASK))
+			ktz8866_write(ktz, BL_EN, CURRENT_SINKS_MASK);
+	}
 
 	if (!of_property_read_u32(ktz->client->dev.of_node, "kinetic,current-ramp-delay-ms", &val)) {
 		if (val <= 128)
-- 
2.49.0


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

* [PATCH 4/4] backlight: ktz8866: add definitions to make it more readable
  2025-04-07  9:51 [PATCH 0/4] backlight: ktz8866: improve it and support slave Pengyu Luo
                   ` (2 preceding siblings ...)
  2025-04-07  9:51 ` [PATCH 3/4] backlight: ktz8866: improve current sinks setting Pengyu Luo
@ 2025-04-07  9:51 ` Pengyu Luo
  2025-04-07 16:18   ` Daniel Thompson
  2025-04-08  5:19   ` kernel test robot
  3 siblings, 2 replies; 16+ messages in thread
From: Pengyu Luo @ 2025-04-07  9:51 UTC (permalink / raw)
  To: Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han, Pavel Machek,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Helge Deller
  Cc: dri-devel, linux-leds, devicetree, linux-kernel, linux-fbdev,
	Pengyu Luo

LSB, MSB and their handling are slightly confused, so improve it.

Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
---
 drivers/video/backlight/ktz8866.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c
index b67ca136d..5364ecfc0 100644
--- a/drivers/video/backlight/ktz8866.c
+++ b/drivers/video/backlight/ktz8866.c
@@ -24,7 +24,9 @@
 #define DEVICE_ID 0x01
 #define BL_CFG1 0x02
 #define BL_CFG2 0x03
+/* least significant byte */
 #define BL_BRT_LSB 0x04
+/* most significant byte */
 #define BL_BRT_MSB 0x05
 #define BL_EN 0x08
 #define LCD_BIAS_CFG1 0x09
@@ -47,6 +49,8 @@
 #define PWM_HYST 0x5
 
 #define CURRENT_SINKS_MASK GENMASK(5, 0)
+#define LOWER_BYTE GENMASK(2, 0)
+#define HIGHER_BYTE GENMASK(10, 3)
 
 struct ktz8866_slave {
 	struct i2c_client *client;
@@ -105,8 +109,8 @@ static int ktz8866_backlight_update_status(struct backlight_device *backlight_de
 	}
 
 	/* Set brightness */
-	ktz8866_write(ktz, BL_BRT_LSB, brightness & 0x7);
-	ktz8866_write(ktz, BL_BRT_MSB, (brightness >> 3) & 0xFF);
+	ktz8866_write(ktz, BL_BRT_LSB, FIELD_GET(LOWER_BYTE, brightness);
+	ktz8866_write(ktz, BL_BRT_MSB, FIELD_GET(HIGHER_BYTE, brightness);
 
 	return 0;
 }
-- 
2.49.0


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

* Re: [PATCH 1/4] dt-bindings: backlight: kinetic,ktz8866: add ktz8866 slave compatible
  2025-04-07  9:51 ` [PATCH 1/4] dt-bindings: backlight: kinetic,ktz8866: add ktz8866 slave compatible Pengyu Luo
@ 2025-04-07  9:57   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2025-04-07  9:57 UTC (permalink / raw)
  To: Pengyu Luo, Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han,
	Pavel Machek, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Helge Deller
  Cc: dri-devel, linux-leds, devicetree, linux-kernel, linux-fbdev

On 07/04/2025 11:51, Pengyu Luo wrote:
> Kinetic ktz8866, found in many android devices, nowadays, some oem use
> dual ktz8866 to support a larger panel and  higher brightness, add the

Just one space after 'and'.

> binding for slave case.
> 
> Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
> ---
>  .../leds/backlight/kinetic,ktz8866.yaml       | 29 +++++++++++++++----
>  1 file changed, 24 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml b/Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml
> index c914e1276..825a6fbf1 100644
> --- a/Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml
> +++ b/Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml
> @@ -19,7 +19,9 @@ allOf:
>  
>  properties:
>    compatible:
> -    const: kinetic,ktz8866
> +    enum:
> +      - kinetic,ktz8866
> +      - kinetic,ktz8866-slave

Does not look right. That's the same device. Same devices have same
compatible.

>  
>    reg:
>      maxItems: 1
> @@ -58,9 +60,16 @@ properties:
>  required:
>    - compatible
>    - reg
> -  - vddpos-supply
> -  - vddneg-supply
> -  - enable-gpios
> +
> +if:
> +  properties:
> +    compatible:
> +      const: kinetic,ktz8866
> +then:
> +  required:
> +    - vddpos-supply
> +    - vddneg-supply
> +    - enable-gpios

I don't understand why other device does not need power.

>  
>  unevaluatedProperties: false
>  
> @@ -68,7 +77,7 @@ examples:
>    - |
>      #include <dt-bindings/gpio/gpio.h>
>  
> -    i2c {
> +    i2c0 {

No, don't change.

>          #address-cells = <1>;
>          #size-cells = <0>;
>  
> @@ -84,3 +93,13 @@ examples:
>              kinetic,enable-lcd-bias;
>          };
>      };
> +
> +    i2c1 {
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +
> +        backlight@11 {
> +            compatible = "kinetic,ktz8866-slave";
> +            reg = <0x11>;

No real differences here, so drop the example. Anyway, new examples
would start from - | (see other bindings).



Best regards,
Krzysztof

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

* Re: [PATCH 2/4] backlight: ktz8866: add slave handler
  2025-04-07  9:51 ` [PATCH 2/4] backlight: ktz8866: add slave handler Pengyu Luo
@ 2025-04-07 10:00   ` Krzysztof Kozlowski
  2025-04-18 18:14     ` Pengyu Luo
  2025-04-18 18:17     ` Pengyu Luo
  2025-04-07 16:27   ` Daniel Thompson
  1 sibling, 2 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2025-04-07 10:00 UTC (permalink / raw)
  To: Pengyu Luo, Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han,
	Pavel Machek, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Helge Deller
  Cc: dri-devel, linux-leds, devicetree, linux-kernel, linux-fbdev

On 07/04/2025 11:51, Pengyu Luo wrote:
> Kinetic ktz8866, found in many android devices, nowadays, some oem use
> dual ktz8866 to support a larger panel and  higher brightness, original
> driver would only handle half backlight region on these devices,
> registering it twice is unreasonable, so adding the slave handler to
> support it.
> 
> Note that, none of the devices supported by upstream require this, the
> devices using this is porting.
> 
> Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
> ---
>  drivers/video/backlight/ktz8866.c | 68 +++++++++++++++++++++++++++----
>  1 file changed, 59 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c
> index 351c2b4d6..017ad80dd 100644
> --- a/drivers/video/backlight/ktz8866.c
> +++ b/drivers/video/backlight/ktz8866.c
> @@ -3,6 +3,9 @@
>   * Backlight driver for the Kinetic KTZ8866
>   *
>   * Copyright (C) 2022, 2023 Jianhua Lu <lujianhua000@gmail.com>
> + *
> + * Apr 2025 - Pengyu Luo <mitltlatltl@gmail.com>
> + *	Added handling for dual KTZ8866(master and slave)
>   */
>  
>  #include <linux/backlight.h>
> @@ -43,11 +46,17 @@
>  #define LCD_BIAS_EN 0x9F
>  #define PWM_HYST 0x5
>  
> +struct ktz8866_slave {
> +	struct i2c_client *client;
> +	struct regmap *regmap;
> +};
> +
>  struct ktz8866 {
>  	struct i2c_client *client;
>  	struct regmap *regmap;
> -	bool led_on;
>  	struct gpio_desc *enable_gpio;
> +	struct ktz8866_slave *slave;
> +	bool led_on;
>  };
>  
>  static const struct regmap_config ktz8866_regmap_config = {
> @@ -56,16 +65,22 @@ static const struct regmap_config ktz8866_regmap_config = {
>  	.max_register = REG_MAX,
>  };
>  
> -static int ktz8866_write(struct ktz8866 *ktz, unsigned int reg,
> -			 unsigned int val)
> +static void ktz8866_write(struct ktz8866 *ktz, unsigned int reg,
> +			  unsigned int val)
>  {
> -	return regmap_write(ktz->regmap, reg, val);
> +	regmap_write(ktz->regmap, reg, val);
> +
> +	if (ktz->slave)
> +		regmap_write(ktz->slave->regmap, reg, val);
>  }
>  
> -static int ktz8866_update_bits(struct ktz8866 *ktz, unsigned int reg,
> -			       unsigned int mask, unsigned int val)
> +static void ktz8866_update_bits(struct ktz8866 *ktz, unsigned int reg,
> +				unsigned int mask, unsigned int val)
>  {
> -	return regmap_update_bits(ktz->regmap, reg, mask, val);
> +	regmap_update_bits(ktz->regmap, reg, mask, val);
> +
> +	if (ktz->slave)
> +		regmap_update_bits(ktz->slave->regmap, reg, mask, val);
>  }
>  
>  static int ktz8866_backlight_update_status(struct backlight_device *backlight_dev)
> @@ -124,10 +139,41 @@ static void ktz8866_init(struct ktz8866 *ktz)
>  		ktz8866_write(ktz, LCD_BIAS_CFG1, LCD_BIAS_EN);
>  }
>  
> +static int ktz8866_slave_register(struct ktz8866 *ktz)
> +{
> +	struct device *dev = &ktz->client->dev;
> +	struct ktz8866_slave *slave;
> +	struct i2c_client *client;
> +	struct device_node *np;
> +
> +	np = of_find_compatible_node(NULL, NULL, "kinetic,ktz8866-slave");
> +	if (!np)
> +		return 0;
> +
> +	client = of_find_i2c_device_by_node(np);


I wrote on IRC - phandle to express the relationship between hardware -
and I do not see it implemented.

If you have devices depending on each other, you need to express it -
for links, for resource dependencies etc. phandle is for that usually.
Or OF graph. Or parent-child relationship.

You did not provide any description of the hardware in the binding, so I
really do not have any idea what is this setup thus how to represent it.
Use hardware terms, diagrams etc to explain the hardware in the bindings
commit. What are the addresses? Are there any shared resources? What
buses are devices sitting on, etc.

Best regards,
Krzysztof

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

* Re: [PATCH 3/4] backlight: ktz8866: improve current sinks setting
  2025-04-07  9:51 ` [PATCH 3/4] backlight: ktz8866: improve current sinks setting Pengyu Luo
@ 2025-04-07 16:13   ` Daniel Thompson
  2025-04-08  3:45   ` kernel test robot
  2025-04-08  3:55   ` kernel test robot
  2 siblings, 0 replies; 16+ messages in thread
From: Daniel Thompson @ 2025-04-07 16:13 UTC (permalink / raw)
  To: Pengyu Luo
  Cc: Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han, Pavel Machek,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Helge Deller,
	dri-devel, linux-leds, devicetree, linux-kernel, linux-fbdev

On Mon, Apr 07, 2025 at 05:51:18PM +0800, Pengyu Luo wrote:
> I polled all registers when the module was loading, found that
> current sinks have already been configured. Bootloader would set
> when booting. So checking it before setting the all channels.

Can you rephrase this so the problem and solution are more clearly
expressed. Perhaps template Ingo suggests here would be good:
https://www.spinics.net/lists/kernel/msg1633438.html


> Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
> ---
>  drivers/video/backlight/ktz8866.c | 23 +++++++++++++++++++----
>  1 file changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c
> index 017ad80dd..b67ca136d 100644
> --- a/drivers/video/backlight/ktz8866.c
> +++ b/drivers/video/backlight/ktz8866.c
> @@ -46,6 +46,8 @@
>  #define LCD_BIAS_EN 0x9F
>  #define PWM_HYST 0x5
>
> +#define CURRENT_SINKS_MASK GENMASK(5, 0)
> +

Call this BL_EN_CURRENT_SINKS_MASK and keep it next to the register it
applies to.


>  struct ktz8866_slave {
>  	struct i2c_client *client;
>  	struct regmap *regmap;
> @@ -112,11 +120,18 @@ static void ktz8866_init(struct ktz8866 *ktz)
>  {
>  	unsigned int val = 0;
>
> -	if (!of_property_read_u32(ktz->client->dev.of_node, "current-num-sinks", &val))
> +	if (!of_property_read_u32(ktz->client->dev.of_node, "current-num-sinks", &val)) {
>  		ktz8866_write(ktz, BL_EN, BIT(val) - 1);
> -	else
> -		/* Enable all 6 current sinks if the number of current sinks isn't specified. */
> -		ktz8866_write(ktz, BL_EN, BIT(6) - 1);
> +	} else {
> +		/*
> +		 * Enable all 6 current sinks if the number of current
> +		 * sinks isn't specified and the bootloader didn't set
> +		 * the value.
> +		 */
> +		ktz8866_read(ktz, BL_EN, &val);
> +		if (!(val && CURRENT_SINKS_MASK))

This is the wrong form of AND.

> +			ktz8866_write(ktz, BL_EN, CURRENT_SINKS_MASK);
> +	}


Daniel.

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

* Re: [PATCH 4/4] backlight: ktz8866: add definitions to make it more readable
  2025-04-07  9:51 ` [PATCH 4/4] backlight: ktz8866: add definitions to make it more readable Pengyu Luo
@ 2025-04-07 16:18   ` Daniel Thompson
  2025-04-08  5:19   ` kernel test robot
  1 sibling, 0 replies; 16+ messages in thread
From: Daniel Thompson @ 2025-04-07 16:18 UTC (permalink / raw)
  To: Pengyu Luo
  Cc: Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han, Pavel Machek,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Helge Deller,
	dri-devel, linux-leds, devicetree, linux-kernel, linux-fbdev

On Mon, Apr 07, 2025 at 05:51:19PM +0800, Pengyu Luo wrote:
> LSB, MSB and their handling are slightly confused, so improve it.
>
> Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
> ---
>  drivers/video/backlight/ktz8866.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c
> index b67ca136d..5364ecfc0 100644
> --- a/drivers/video/backlight/ktz8866.c
> +++ b/drivers/video/backlight/ktz8866.c
> @@ -24,7 +24,9 @@
>  #define DEVICE_ID 0x01
>  #define BL_CFG1 0x02
>  #define BL_CFG2 0x03
> +/* least significant byte */
>  #define BL_BRT_LSB 0x04
> +/* most significant byte */

I'm not convinced these comments are necessary.


>  #define BL_BRT_MSB 0x05
>  #define BL_EN 0x08
>  #define LCD_BIAS_CFG1 0x09
> @@ -47,6 +49,8 @@
>  #define PWM_HYST 0x5
>
>  #define CURRENT_SINKS_MASK GENMASK(5, 0)
> +#define LOWER_BYTE GENMASK(2, 0)

I like using masks and FIELD_GET() but this is not a byte. These are
the least significant bits.


Daniel.

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

* Re: [PATCH 2/4] backlight: ktz8866: add slave handler
  2025-04-07  9:51 ` [PATCH 2/4] backlight: ktz8866: add slave handler Pengyu Luo
  2025-04-07 10:00   ` Krzysztof Kozlowski
@ 2025-04-07 16:27   ` Daniel Thompson
  2025-04-18 18:19     ` Pengyu Luo
  1 sibling, 1 reply; 16+ messages in thread
From: Daniel Thompson @ 2025-04-07 16:27 UTC (permalink / raw)
  To: Pengyu Luo
  Cc: Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han, Pavel Machek,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Helge Deller,
	dri-devel, linux-leds, devicetree, linux-kernel, linux-fbdev

On Mon, Apr 07, 2025 at 05:51:17PM +0800, Pengyu Luo wrote:
> Kinetic ktz8866, found in many android devices, nowadays, some oem use
> dual ktz8866 to support a larger panel and  higher brightness, original
> driver would only handle half backlight region on these devices,
> registering it twice is unreasonable, so adding the slave handler to
> support it.

Is there anything unique about KTZ8866 that allows it to be used like
this? I think it would be better to add support for secondary backlight
controllers into the backlight framework, rather than having to
implement driver specific hacks for every backlight controller that
appears in a primary/secondary configuration.

Also, the kernel seeks to avoid adding new instances of master/slave
terminology. See the coding style doc for suggested alternatives:
https://www.kernel.org/doc/html/latest/process/coding-style.html#naming


Daniel.

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

* Re: [PATCH 3/4] backlight: ktz8866: improve current sinks setting
  2025-04-07  9:51 ` [PATCH 3/4] backlight: ktz8866: improve current sinks setting Pengyu Luo
  2025-04-07 16:13   ` Daniel Thompson
@ 2025-04-08  3:45   ` kernel test robot
  2025-04-08  3:55   ` kernel test robot
  2 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2025-04-08  3:45 UTC (permalink / raw)
  To: Pengyu Luo, Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han,
	Pavel Machek, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Helge Deller
  Cc: llvm, oe-kbuild-all, dri-devel, linux-leds, devicetree,
	linux-kernel, linux-fbdev, Pengyu Luo

Hi Pengyu,

kernel test robot noticed the following build errors:

[auto build test ERROR on lee-backlight/for-backlight-next]
[also build test ERROR on lee-leds/for-leds-next lee-backlight/for-backlight-fixes linus/master v6.15-rc1 next-20250407]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pengyu-Luo/dt-bindings-backlight-kinetic-ktz8866-add-ktz8866-slave-compatible/20250407-175635
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight.git for-backlight-next
patch link:    https://lore.kernel.org/r/20250407095119.588920-4-mitltlatltl%40gmail.com
patch subject: [PATCH 3/4] backlight: ktz8866: improve current sinks setting
config: riscv-randconfig-002-20250408 (https://download.01.org/0day-ci/archive/20250408/202504081109.E7PjHxpa-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 92c93f5286b9ff33f27ff694d2dc33da1c07afdd)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250408/202504081109.E7PjHxpa-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504081109.E7PjHxpa-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

>> drivers/video/backlight/ktz8866.c:73:32: error: incompatible pointer types passing 'unsigned int **' to parameter of type 'unsigned int *'; remove & [-Werror,-Wincompatible-pointer-types]
      73 |         regmap_read(ktz->regmap, reg, &val);
         |                                       ^~~~
   include/linux/regmap.h:1297:69: note: passing argument to parameter 'val' here
    1297 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
         |                                                                     ^
>> drivers/video/backlight/ktz8866.c:132:13: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
     132 |                 if (!(val && CURRENT_SINKS_MASK))
         |                           ^  ~~~~~~~~~~~~~~~~~~
   drivers/video/backlight/ktz8866.c:132:13: note: use '&' for a bitwise operation
     132 |                 if (!(val && CURRENT_SINKS_MASK))
         |                           ^~
         |                           &
   drivers/video/backlight/ktz8866.c:132:13: note: remove constant to silence this warning
     132 |                 if (!(val && CURRENT_SINKS_MASK))
         |                           ^~~~~~~~~~~~~~~~~~~~~
   1 warning and 1 error generated.


vim +73 drivers/video/backlight/ktz8866.c

    69	
    70	static inline void ktz8866_read(struct ktz8866 *ktz, unsigned int reg,
    71					unsigned int *val)
    72	{
  > 73		regmap_read(ktz->regmap, reg, &val);
    74	}
    75	
    76	static void ktz8866_write(struct ktz8866 *ktz, unsigned int reg,
    77				  unsigned int val)
    78	{
    79		regmap_write(ktz->regmap, reg, val);
    80	
    81		if (ktz->slave)
    82			regmap_write(ktz->slave->regmap, reg, val);
    83	}
    84	
    85	static void ktz8866_update_bits(struct ktz8866 *ktz, unsigned int reg,
    86					unsigned int mask, unsigned int val)
    87	{
    88		regmap_update_bits(ktz->regmap, reg, mask, val);
    89	
    90		if (ktz->slave)
    91			regmap_update_bits(ktz->slave->regmap, reg, mask, val);
    92	}
    93	
    94	static int ktz8866_backlight_update_status(struct backlight_device *backlight_dev)
    95	{
    96		struct ktz8866 *ktz = bl_get_data(backlight_dev);
    97		unsigned int brightness = backlight_get_brightness(backlight_dev);
    98	
    99		if (!ktz->led_on && brightness > 0) {
   100			ktz8866_update_bits(ktz, BL_EN, BL_EN_BIT, BL_EN_BIT);
   101			ktz->led_on = true;
   102		} else if (brightness == 0) {
   103			ktz8866_update_bits(ktz, BL_EN, BL_EN_BIT, 0);
   104			ktz->led_on = false;
   105		}
   106	
   107		/* Set brightness */
   108		ktz8866_write(ktz, BL_BRT_LSB, brightness & 0x7);
   109		ktz8866_write(ktz, BL_BRT_MSB, (brightness >> 3) & 0xFF);
   110	
   111		return 0;
   112	}
   113	
   114	static const struct backlight_ops ktz8866_backlight_ops = {
   115		.options = BL_CORE_SUSPENDRESUME,
   116		.update_status = ktz8866_backlight_update_status,
   117	};
   118	
   119	static void ktz8866_init(struct ktz8866 *ktz)
   120	{
   121		unsigned int val = 0;
   122	
   123		if (!of_property_read_u32(ktz->client->dev.of_node, "current-num-sinks", &val)) {
   124			ktz8866_write(ktz, BL_EN, BIT(val) - 1);
   125		} else {
   126			/*
   127			 * Enable all 6 current sinks if the number of current
   128			 * sinks isn't specified and the bootloader didn't set
   129			 * the value.
   130			 */
   131			ktz8866_read(ktz, BL_EN, &val);
 > 132			if (!(val && CURRENT_SINKS_MASK))
   133				ktz8866_write(ktz, BL_EN, CURRENT_SINKS_MASK);
   134		}
   135	
   136		if (!of_property_read_u32(ktz->client->dev.of_node, "kinetic,current-ramp-delay-ms", &val)) {
   137			if (val <= 128)
   138				ktz8866_write(ktz, BL_CFG2, BIT(7) | (ilog2(val) << 3) | PWM_HYST);
   139			else
   140				ktz8866_write(ktz, BL_CFG2, BIT(7) | ((5 + val / 64) << 3) | PWM_HYST);
   141		}
   142	
   143		if (!of_property_read_u32(ktz->client->dev.of_node, "kinetic,led-enable-ramp-delay-ms", &val)) {
   144			if (val == 0)
   145				ktz8866_write(ktz, BL_DIMMING, 0);
   146			else {
   147				unsigned int ramp_off_time = ilog2(val) + 1;
   148				unsigned int ramp_on_time = ramp_off_time << 4;
   149				ktz8866_write(ktz, BL_DIMMING, ramp_on_time | ramp_off_time);
   150			}
   151		}
   152	
   153		if (of_property_read_bool(ktz->client->dev.of_node, "kinetic,enable-lcd-bias"))
   154			ktz8866_write(ktz, LCD_BIAS_CFG1, LCD_BIAS_EN);
   155	}
   156	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH 3/4] backlight: ktz8866: improve current sinks setting
  2025-04-07  9:51 ` [PATCH 3/4] backlight: ktz8866: improve current sinks setting Pengyu Luo
  2025-04-07 16:13   ` Daniel Thompson
  2025-04-08  3:45   ` kernel test robot
@ 2025-04-08  3:55   ` kernel test robot
  2 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2025-04-08  3:55 UTC (permalink / raw)
  To: Pengyu Luo, Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han,
	Pavel Machek, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Helge Deller
  Cc: oe-kbuild-all, dri-devel, linux-leds, devicetree, linux-kernel,
	linux-fbdev, Pengyu Luo

Hi Pengyu,

kernel test robot noticed the following build errors:

[auto build test ERROR on lee-backlight/for-backlight-next]
[also build test ERROR on lee-leds/for-leds-next lee-backlight/for-backlight-fixes linus/master v6.15-rc1 next-20250407]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pengyu-Luo/dt-bindings-backlight-kinetic-ktz8866-add-ktz8866-slave-compatible/20250407-175635
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight.git for-backlight-next
patch link:    https://lore.kernel.org/r/20250407095119.588920-4-mitltlatltl%40gmail.com
patch subject: [PATCH 3/4] backlight: ktz8866: improve current sinks setting
config: sparc64-randconfig-002-20250408 (https://download.01.org/0day-ci/archive/20250408/202504081106.mAYfJsQj-lkp@intel.com/config)
compiler: sparc64-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250408/202504081106.mAYfJsQj-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504081106.mAYfJsQj-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/video/backlight/ktz8866.c: In function 'ktz8866_read':
>> drivers/video/backlight/ktz8866.c:73:39: error: passing argument 3 of 'regmap_read' from incompatible pointer type [-Wincompatible-pointer-types]
      73 |         regmap_read(ktz->regmap, reg, &val);
         |                                       ^~~~
         |                                       |
         |                                       unsigned int **
   In file included from drivers/video/backlight/ktz8866.c:17:
   include/linux/regmap.h:1297:69: note: expected 'unsigned int *' but argument is of type 'unsigned int **'
    1297 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
         |                                                       ~~~~~~~~~~~~~~^~~


vim +/regmap_read +73 drivers/video/backlight/ktz8866.c

    69	
    70	static inline void ktz8866_read(struct ktz8866 *ktz, unsigned int reg,
    71					unsigned int *val)
    72	{
  > 73		regmap_read(ktz->regmap, reg, &val);
    74	}
    75	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH 4/4] backlight: ktz8866: add definitions to make it more readable
  2025-04-07  9:51 ` [PATCH 4/4] backlight: ktz8866: add definitions to make it more readable Pengyu Luo
  2025-04-07 16:18   ` Daniel Thompson
@ 2025-04-08  5:19   ` kernel test robot
  1 sibling, 0 replies; 16+ messages in thread
From: kernel test robot @ 2025-04-08  5:19 UTC (permalink / raw)
  To: Pengyu Luo, Jianhua Lu, Lee Jones, Daniel Thompson, Jingoo Han,
	Pavel Machek, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Helge Deller
  Cc: llvm, oe-kbuild-all, dri-devel, linux-leds, devicetree,
	linux-kernel, linux-fbdev, Pengyu Luo

Hi Pengyu,

kernel test robot noticed the following build errors:

[auto build test ERROR on lee-backlight/for-backlight-next]
[also build test ERROR on lee-leds/for-leds-next lee-backlight/for-backlight-fixes linus/master v6.15-rc1 next-20250407]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pengyu-Luo/dt-bindings-backlight-kinetic-ktz8866-add-ktz8866-slave-compatible/20250407-175635
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight.git for-backlight-next
patch link:    https://lore.kernel.org/r/20250407095119.588920-5-mitltlatltl%40gmail.com
patch subject: [PATCH 4/4] backlight: ktz8866: add definitions to make it more readable
config: riscv-randconfig-002-20250408 (https://download.01.org/0day-ci/archive/20250408/202504081215.rL4DExNA-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 92c93f5286b9ff33f27ff694d2dc33da1c07afdd)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250408/202504081215.rL4DExNA-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504081215.rL4DExNA-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/video/backlight/ktz8866.c:77:32: error: incompatible pointer types passing 'unsigned int **' to parameter of type 'unsigned int *'; remove & [-Werror,-Wincompatible-pointer-types]
      77 |         regmap_read(ktz->regmap, reg, &val);
         |                                       ^~~~
   include/linux/regmap.h:1297:69: note: passing argument to parameter 'val' here
    1297 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
         |                                                                     ^
>> drivers/video/backlight/ktz8866.c:112:66: error: expected ')'
     112 |         ktz8866_write(ktz, BL_BRT_LSB, FIELD_GET(LOWER_BYTE, brightness);
         |                                                                         ^
   drivers/video/backlight/ktz8866.c:112:15: note: to match this '('
     112 |         ktz8866_write(ktz, BL_BRT_LSB, FIELD_GET(LOWER_BYTE, brightness);
         |                      ^
   drivers/video/backlight/ktz8866.c:113:67: error: expected ')'
     113 |         ktz8866_write(ktz, BL_BRT_MSB, FIELD_GET(HIGHER_BYTE, brightness);
         |                                                                          ^
   drivers/video/backlight/ktz8866.c:113:15: note: to match this '('
     113 |         ktz8866_write(ktz, BL_BRT_MSB, FIELD_GET(HIGHER_BYTE, brightness);
         |                      ^
   drivers/video/backlight/ktz8866.c:136:13: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
     136 |                 if (!(val && CURRENT_SINKS_MASK))
         |                           ^  ~~~~~~~~~~~~~~~~~~
   drivers/video/backlight/ktz8866.c:136:13: note: use '&' for a bitwise operation
     136 |                 if (!(val && CURRENT_SINKS_MASK))
         |                           ^~
         |                           &
   drivers/video/backlight/ktz8866.c:136:13: note: remove constant to silence this warning
     136 |                 if (!(val && CURRENT_SINKS_MASK))
         |                           ^~~~~~~~~~~~~~~~~~~~~
   1 warning and 3 errors generated.


vim +112 drivers/video/backlight/ktz8866.c

    97	
    98	static int ktz8866_backlight_update_status(struct backlight_device *backlight_dev)
    99	{
   100		struct ktz8866 *ktz = bl_get_data(backlight_dev);
   101		unsigned int brightness = backlight_get_brightness(backlight_dev);
   102	
   103		if (!ktz->led_on && brightness > 0) {
   104			ktz8866_update_bits(ktz, BL_EN, BL_EN_BIT, BL_EN_BIT);
   105			ktz->led_on = true;
   106		} else if (brightness == 0) {
   107			ktz8866_update_bits(ktz, BL_EN, BL_EN_BIT, 0);
   108			ktz->led_on = false;
   109		}
   110	
   111		/* Set brightness */
 > 112		ktz8866_write(ktz, BL_BRT_LSB, FIELD_GET(LOWER_BYTE, brightness);
   113		ktz8866_write(ktz, BL_BRT_MSB, FIELD_GET(HIGHER_BYTE, brightness);
   114	
   115		return 0;
   116	}
   117	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH 2/4] backlight: ktz8866: add slave handler
  2025-04-07 10:00   ` Krzysztof Kozlowski
@ 2025-04-18 18:14     ` Pengyu Luo
  2025-04-18 18:17     ` Pengyu Luo
  1 sibling, 0 replies; 16+ messages in thread
From: Pengyu Luo @ 2025-04-18 18:14 UTC (permalink / raw)
  To: krzk
  Cc: conor+dt, danielt, deller, devicetree, dri-devel, jingoohan1,
	krzk+dt, lee, linux-fbdev, linux-kernel, linux-leds, lujianhua000,
	mitltlatltl, pavel, robh

On Mon, Apr 7, 2025 at 6:00 PM Krzysztof Kozlowski <krzk@kernel.org> wrote:
> On 07/04/2025 11:51, Pengyu Luo wrote:
> > Kinetic ktz8866, found in many android devices, nowadays, some oem use
> > dual ktz8866 to support a larger panel and  higher brightness, original
> > driver would only handle half backlight region on these devices,
> > registering it twice is unreasonable, so adding the slave handler to
> > support it.

[...]

> 
> I wrote on IRC - phandle to express the relationship between hardware -
> and I do not see it implemented.
> 
> If you have devices depending on each other, you need to express it -
> for links, for resource dependencies etc. phandle is for that usually.
> Or OF graph. Or parent-child relationship.
> 

I got you now, as a non-native speaker, I often misunderstood the first
time, you expected that accessing node phandle in relationship or graph
way, I did only access node phandle regardless of relationship or graph
description, I only implied it in compatible string, but there would be
a better way.

> You did not provide any description of the hardware in the binding, so I
> really do not have any idea what is this setup thus how to represent it.
> Use hardware terms, diagrams etc to explain the hardware in the bindings
> commit. What are the addresses? Are there any shared resources? What
> buses are devices sitting on, etc.

Agree.

Best wishes,
Pengyu

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

* Re: [PATCH 2/4] backlight: ktz8866: add slave handler
  2025-04-07 10:00   ` Krzysztof Kozlowski
  2025-04-18 18:14     ` Pengyu Luo
@ 2025-04-18 18:17     ` Pengyu Luo
  1 sibling, 0 replies; 16+ messages in thread
From: Pengyu Luo @ 2025-04-18 18:17 UTC (permalink / raw)
  To: krzk
  Cc: conor+dt, danielt, deller, devicetree, dri-devel, jingoohan1,
	krzk+dt, lee, linux-fbdev, linux-kernel, linux-leds, lujianhua000,
	mitltlatltl, pavel, robh

On Tue, Apr 8, 2025 at 12:27 AM Daniel Thompson <daniel@riscstar.com> wrote:
> On Mon, Apr 07, 2025 at 05:51:17PM +0800, Pengyu Luo wrote:
> > Kinetic ktz8866, found in many android devices, nowadays, some oem use
> > dual ktz8866 to support a larger panel and  higher brightness, original
> > driver would only handle half backlight region on these devices,
> > registering it twice is unreasonable, so adding the slave handler to
> > support it.
> 
> Is there anything unique about KTZ8866 that allows it to be used like
> this? I think it would be better to add support for secondary backlight
> controllers into the backlight framework, rather than having to
> implement driver specific hacks for every backlight controller that
> appears in a primary/secondary configuration.
> 

According to my understanding, if I add the new api to backlight framework,
with a minimal modification, then I either do A or do B(I doubt it is my
fixed mindset)

A:
Tied two devices, registering the primary and the secondary device during
one probe, to do that, I access another KTZ8866 when probing. Those hack
is still here, that doesn't seem to help.

B:
Uncoupled, probing separately, the later one is registered as the
secondary one. Brightness control is a little uncoupled, there are two
sysfs, I doubt if userspace programs will write brightness to two
devices. Then we need synchronization, write primary => write primary
and write secondary, viceversa.

> Also, the kernel seeks to avoid adding new instances of master/slave
> terminology. See the coding style doc for suggested alternatives:
> https://www.kernel.org/doc/html/latest/process/coding-style.html#naming
> 

Agree.

Best wishes,
Pengyu

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

* Re: [PATCH 2/4] backlight: ktz8866: add slave handler
  2025-04-07 16:27   ` Daniel Thompson
@ 2025-04-18 18:19     ` Pengyu Luo
  0 siblings, 0 replies; 16+ messages in thread
From: Pengyu Luo @ 2025-04-18 18:19 UTC (permalink / raw)
  To: daniel
  Cc: conor+dt, danielt, deller, devicetree, dri-devel, jingoohan1,
	krzk+dt, lee, linux-fbdev, linux-kernel, linux-leds, lujianhua000,
	mitltlatltl, pavel, robh

On Tue, Apr 8, 2025 at 12:27 AM Daniel Thompson <daniel@riscstar.com> wrote:
> On Mon, Apr 07, 2025 at 05:51:17PM +0800, Pengyu Luo wrote:
> > Kinetic ktz8866, found in many android devices, nowadays, some oem use
> > dual ktz8866 to support a larger panel and  higher brightness, original
> > driver would only handle half backlight region on these devices,
> > registering it twice is unreasonable, so adding the slave handler to
> > support it.
> 
> Is there anything unique about KTZ8866 that allows it to be used like
> this? I think it would be better to add support for secondary backlight
> controllers into the backlight framework, rather than having to
> implement driver specific hacks for every backlight controller that
> appears in a primary/secondary configuration.
> 

According to my understanding, if I add the new api to backlight framework,
with a minimal modification, then I either do A or do B(I doubt it is my
fixed mindset)

A:
Tied two devices, registering the primary and the secondary device during
one probe, to do that, I access another KTZ8866 when probing. Those hack
is still here, that doesn't seem to help.

B:
Uncoupled, probing separately, the later one is registered as the
secondary one. Brightness control is a little uncoupled, there are two
sysfs, I doubt if userspace programs will write brightness to two
devices. Then we need synchronization, write primary => write primary
and write secondary, viceversa.

> Also, the kernel seeks to avoid adding new instances of master/slave
> terminology. See the coding style doc for suggested alternatives:
> https://www.kernel.org/doc/html/latest/process/coding-style.html#naming
> 

Agree.

Best wishes,
Pengyu

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

end of thread, other threads:[~2025-04-18 18:21 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-07  9:51 [PATCH 0/4] backlight: ktz8866: improve it and support slave Pengyu Luo
2025-04-07  9:51 ` [PATCH 1/4] dt-bindings: backlight: kinetic,ktz8866: add ktz8866 slave compatible Pengyu Luo
2025-04-07  9:57   ` Krzysztof Kozlowski
2025-04-07  9:51 ` [PATCH 2/4] backlight: ktz8866: add slave handler Pengyu Luo
2025-04-07 10:00   ` Krzysztof Kozlowski
2025-04-18 18:14     ` Pengyu Luo
2025-04-18 18:17     ` Pengyu Luo
2025-04-07 16:27   ` Daniel Thompson
2025-04-18 18:19     ` Pengyu Luo
2025-04-07  9:51 ` [PATCH 3/4] backlight: ktz8866: improve current sinks setting Pengyu Luo
2025-04-07 16:13   ` Daniel Thompson
2025-04-08  3:45   ` kernel test robot
2025-04-08  3:55   ` kernel test robot
2025-04-07  9:51 ` [PATCH 4/4] backlight: ktz8866: add definitions to make it more readable Pengyu Luo
2025-04-07 16:18   ` Daniel Thompson
2025-04-08  5:19   ` kernel test robot

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