backlight: add ktd3137 support
Subsystems (4)
cover backlight: add ktd3137 support
This patch series adds support for Kinetic KTD3137 backlight IC. It supports linear brightness range from 0 to 2047.
While the chip supports PWM and MSB modes, they weren't included, since MSB mode supports only 8-bit brightness range, and PWM is not enabled on this board. I have checked other Xiaomi vendor kernels, and their configuration appear to be the same as on my board. I'm not aware if any device uses PWM mode with this chip.
This series was developed and tested on the Xiaomi Redmi Note 9 board.
---
Roman Vivchar (2):
dt-bindings: leds: backlight: add Kinetic KTD3137
backlight: add ktd3137 support
.../bindings/leds/backlight/kinetic,ktd3137.yaml | 64 +++++ MAINTAINERS | 6 + drivers/video/backlight/Kconfig | 11 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/ktd3137.c | 262 +++++++++++++++++++++ 5 files changed, 344 insertions(+)
---
base-commit: 5e6de6a2b522f659defacb1551d0465ba6ce13cf
change-id: 20261102-6768-ktd3137-4ec95068fb6a
Best regards,
Signature · 1 line
Roman Vivchar <[email protected]>
PATCH 1/2 dt-bindings: leds: backlight: add Kinetic KTD3137
Kinetic KTD3137 is an LED IC, used in various mobile devices for the display backlight. Add devicetree bindings documentation for this chip.
Datasheet: https://www.kinet-ic.com/uploads/KTD3137-04a.pdf
--- .../bindings/leds/backlight/kinetic,ktd3137.yaml | 64 ++++++++++++++++++++++ MAINTAINERS | 5 ++ 2 files changed, 69 insertions(+)
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml new file +64 -0
@@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/backlight/kinetic,ktd3137.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Kinetic Technologies KTD3137 LED Backlight + +maintainers: + - Roman Vivchar <[email protected]> + +description: + The Kinetic Technologies KTD3137 is an I2C LED backlight driver for medium + to large size LCD panels. + +allOf: + - $ref: common.yaml# + +properties: + compatible: + const: kinetic,ktd3137 + + reg: + maxItems: 1 + + default-brightness: + maximum: 2047 + default: 2047 + + enable-gpios: + maxItems: 1 + description: GPIO connected to the HWEN pin. + + led-max-microamp: + minimum: 5000 + maximum: 29800 + default: 20200 + + vin-supply: true + +required: + - compatible + - reg + - vin-supply + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + backlight@36 { + compatible = "kinetic,ktd3137"; + reg = <0x36>; + enable-gpios = <&pio 160 GPIO_ACTIVE_HIGH>; + led-max-microamp = <20200>; + default-brightness = <2047>; + vin-supply = <&vsys>; + }; + };
MAINTAINERS +5 -0
@@ -14618,6 +14618,11 @@ S: Maintained F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktd2801.yaml F: drivers/video/backlight/ktd2801-backlight.c +KTD3137 BACKLIGHT DRIVER +M: Roman Vivchar <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml + KTEST M: Steven Rostedt <[email protected]> M: John Hawley <[email protected]>
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 1/2] dt-bindings: leds: backlight: add Kinetic KTD3137
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
From: Roman Vivchar <[email protected]>
Kinetic KTD3137 is an LED IC, used in various mobile devices for the display backlight. Add devicetree bindings documentation for this chip.
Datasheet: https://www.kinet-ic.com/uploads/KTD3137-04a.pdf
Signed-off-by Roman Vivchar <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Daniel Thompson
maintainerRe: [PATCH 1/2] dt-bindings: leds: backlight: add Kinetic KTD3137
In reply to Roman VivcharQuoted 35 lines · On Mon, Nov 02, 2026 at 09:58:48PM +0200, Roman Vivchar via B4 Relay wrote:
From: Roman Vivchar <[email protected]>
Kinetic KTD3137 is an LED IC, used in various mobile devices for the display backlight. Add devicetree bindings documentation for this chip.
Datasheet: https://www.kinet-ic.com/uploads/KTD3137-04a.pdf
Signed-off-by Roman Vivchar <[email protected]>--- .../bindings/leds/backlight/kinetic,ktd3137.yaml | 64 ++++++++++++++++++++++ MAINTAINERS | 5 ++ 2 files changed, 69 insertions(+)Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml new file +15
-0@@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/backlight/kinetic,ktd3137.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Kinetic Technologies KTD3137 LED Backlight + +maintainers: + - Roman Vivchar <[email protected]> + +description: + The Kinetic Technologies KTD3137 is an I2C LED backlight driver for medium + to large size LCD panels. + led-max-microamp:
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml line 44
Quoted 10 lines
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml new file +10
-0+ minimum: 5000 + maximum: 29800 + default: 20200 + + vin-supply: true + +required: + - compatible + - reg + - vin-supply
Why is vin-supply required?
Daniel.
Re: [PATCH 1/2] dt-bindings: leds: backlight: add Kinetic KTD3137
Hi Daniel,
Quoted 40 lines · Daniel Thompson
Quoted 39 lines · On Mon, Nov 02, 2026 at 09:58:48PM +0200, Roman Vivchar via B4 Relay wrote:
From: Roman Vivchar <[email protected]>
Kinetic KTD3137 is an LED IC, used in various mobile devices for the display backlight. Add devicetree bindings documentation for this chip.
Datasheet: https://www.kinet-ic.com/uploads/KTD3137-04a.pdf
Signed-off-by Roman Vivchar <[email protected]>--- .../bindings/leds/backlight/kinetic,ktd3137.yaml | 64 ++++++++++++++++++++++ MAINTAINERS | 5 ++ 2 files changed, 69 insertions(+)Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml new file +19
-0@@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/backlight/kinetic,ktd3137.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Kinetic Technologies KTD3137 LED Backlight + +maintainers: + - Roman Vivchar <[email protected]> + +description: + The Kinetic Technologies KTD3137 is an I2C LED backlight driver for medium + to large size LCD panels. + led-max-microamp: + minimum: 5000 + maximum: 29800 + default: 20200 +
Quoted 9 lines
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml line 44
Quoted 6 lines
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml new file +6
-0+ vin-supply: true + +required: + - compatible + - reg + - vin-supplyWhy is vin-supply required?
The chip cannot function without VIN power supply. Even if it's on the always-on power rail on certain board, there's always a chance it might be accidentally left disabled on the other. It's better to document supply in the bindings as far as I understand.
Best regards,
Roman
Quoted 3 lines
Daniel.
Daniel Thompson
maintainerRe: [PATCH 1/2] dt-bindings: leds: backlight: add Kinetic KTD3137
Quoted 19 lines · Roman Vivchar
Hi Daniel,
Quoted 15 lines · Daniel Thompson
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml line 44
Quoted 11 lines · On Mon, Nov 02, 2026 at 09:58:48PM +0200, Roman Vivchar via B4 Relay wrote:
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml new file +11
-0+ led-max-microamp: + minimum: 5000 + maximum: 29800 + default: 20200 + + vin-supply: true + +required: + - compatible + - reg + - vin-supplyWhy is vin-supply required?
Quoted 4 lines
The chip cannot function without VIN power supply. Even if it's on the always-on power rail on certain board, there's always a chance it might be accidentally left disabled on the other. It's better to document supply in the bindings as far as I understand.
You haven't just documented the binding, you have also made the property mandatory by adding it to required.
So what I am asking is why is this property listed as required. You didn't implement the driver in a way that makes the supply mandatory.
Daniel.
Re: [PATCH 1/2] dt-bindings: leds: backlight: add Kinetic KTD3137
Quoted 25 lines · Daniel Thompson
Quoted 19 lines · Roman Vivchar
Hi Daniel,
Quoted 15 lines · Daniel Thompson
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml line 44
Quoted 11 lines · On Mon, Nov 02, 2026 at 09:58:48PM +0200, Roman Vivchar via B4 Relay wrote:
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml new file +11
-0+ led-max-microamp: + minimum: 5000 + maximum: 29800 + default: 20200 + + vin-supply: true + +required: + - compatible + - reg + - vin-supplyWhy is vin-supply required?
Quoted 4 lines
The chip cannot function without VIN power supply. Even if it's on the always-on power rail on certain board, there's always a chance it might be accidentally left disabled on the other. It's better to document supply in the bindings as far as I understand.
Quoted 5 lines
You haven't just documented the binding, you have also made the property mandatory by adding it to required.
So what I am asking is why is this property listed as required. You didn't implement the driver in a way that makes the supply mandatory.
Not sure I follow.
In the driver I've used devm_regulator_get_enable(), rather than _optional(), since my understanding is that the non-optional helper is a standard kernel API for required supplies (with regulator core warning and fallback to dummy regulator in case DT omits it).
Do you suggest dropping vin-supply from required: ? On my board it's connected to an always-on supply, though I can't tell about others. I can proceed with this if the DT maintainers are okay with that.
Quoted 3 lines
Daniel.
Daniel Thompson
maintainerRe: [PATCH 1/2] dt-bindings: leds: backlight: add Kinetic KTD3137
Quoted 33 lines · Roman Vivchar
Quoted 25 lines · Daniel Thompson
Quoted 19 lines · Roman Vivchar
Hi Daniel,
Quoted 15 lines · Daniel Thompson
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml line 44
Quoted 11 lines · On Mon, Nov 02, 2026 at 09:58:48PM +0200, Roman Vivchar via B4 Relay wrote:
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml new file +11
-0+ led-max-microamp: + minimum: 5000 + maximum: 29800 + default: 20200 + + vin-supply: true + +required: + - compatible + - reg + - vin-supplyWhy is vin-supply required?
Quoted 4 lines
The chip cannot function without VIN power supply. Even if it's on the always-on power rail on certain board, there's always a chance it might be accidentally left disabled on the other. It's better to document supply in the bindings as far as I understand.
Quoted 5 lines
You haven't just documented the binding, you have also made the property mandatory by adding it to required.
So what I am asking is why is this property listed as required. You didn't implement the driver in a way that makes the supply mandatory.
Quoted 6 lines
Not sure I follow.
In the driver I've used
devm_regulator_get_enable(), rather than_optional(), since my understanding is that the non-optional helper is a standard kernel API for required supplies (with regulator core warning and fallback to dummy regulator in case DT omits it).
That dummy fallback essentially makes it optional. On a board with an always-on supply then there is no need to include vin-supply in the DTB. The driver will work just fine without it.
Quoted 3 lines
Do you suggest dropping vin-supply from required: ? On my board it's connected to an always-on supply, though I can't tell about others. I can proceed with this if the DT maintainers are okay with that.
Given your answers then, yes, vin-supply should not be in the required:
list (e.g. we don't want DT validation to fail for a DT that does not include a vin-supply).
Daniel.
Re: [PATCH 1/2] dt-bindings: leds: backlight: add Kinetic KTD3137
Quoted 10 lines · Daniel Thompson
Quoted 5 lines · Roman Vivchar
In the driver I've used
devm_regulator_get_enable(), rather than_optional(), since my understanding is that the non-optional helper is a standard kernel API for required supplies (with regulator core warning and fallback to dummy regulator in case DT omits it).That dummy fallback essentially makes it optional. On a board with an always-on supply then there is no need to include vin-supply in the DTB. The driver will work just fine without it.
There is a need, because this device needs a supply. How you describe that supply in DTS is a different story - can be always-on, can be missing etc.
Best regards,
Krzysztof
Re: [PATCH 1/2] dt-bindings: leds: backlight: add Kinetic KTD3137
In reply to Daniel ThompsonQuoted 15 lines · Daniel Thompson
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml line 44
Quoted 12 lines · On Mon, Nov 02, 2026 at 09:58:48PM +0200, Roman Vivchar via B4 Relay wrote:
<snip>
Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml new file +11
-0+ led-max-microamp: + minimum: 5000 + maximum: 29800 + default: 20200 + + vin-supply: true + +required: + - compatible + - reg + - vin-supplyWhy is vin-supply required?
Device cannot operate without power. What driver needs is irrelevant in this particular case.
Best regards,
Krzysztof
PATCH 2/2 backlight: add ktd3137 support
In reply to Roman VivcharAdd support for the KTD3137 display backlight IC. It's used in various Xiaomi phones, such as Xiaomi Redmi Note 9.
--- MAINTAINERS | 1 + drivers/video/backlight/Kconfig | 11 ++ drivers/video/backlight/Makefile | 1 + drivers/video/backlight/ktd3137.c | 262 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 275 insertions(+)
MAINTAINERS +1 -0
@@ -14622,6 +14622,7 @@ KTD3137 BACKLIGHT DRIVER M: Roman Vivchar <[email protected]> S: Maintained F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml +F: drivers/video/backlight/ktd3137.c KTEST M: Steven Rostedt <[email protected]>
drivers/video/backlight/Kconfig +11 -0
@@ -199,6 +199,17 @@ config BACKLIGHT_KTD2801 Say Y to enable the backlight driver for the Kinetic KTD2801 1-wire GPIO-controlled backlight found in Samsung Galaxy Core Prime VE LTE. +config BACKLIGHT_KTD3137 + tristate "Backlight Driver for Kinetic KTD3137" + depends on I2C + select REGMAP_I2C + help + Say Y to enable the backlight driver for the Kinetic KTD3137 + found in various Xiaomi smartphones. + + To compile this driver as a module, choose M here: the module + will be called ktd3137. + config BACKLIGHT_KTZ8866 tristate "Backlight Driver for Kinetic KTZ8866" depends on I2C
drivers/video/backlight/Makefile +1 -0
@@ -38,6 +38,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_KTD2801) += ktd2801-backlight.o +obj-$(CONFIG_BACKLIGHT_KTD3137) += ktd3137.o obj-$(CONFIG_BACKLIGHT_KTZ8866) += ktz8866.o obj-$(CONFIG_BACKLIGHT_LM3509) += lm3509_bl.o obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o
drivers/video/backlight/ktd3137.c new file +262 -0
262 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] backlight: ktd3137: use named initializer in ktd3137_ids --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] backlight: ktd3137: use named initializer in ktd3137_ids
--
commit d3260d17f4919396b8ff6c1268dffef7e26e01cf
Author: Roman Vivchar <[email protected]>
backlight: add ktd3137 support
This commit adds a backlight driver for the Kinetic KTD3137 display backlight IC.
Quoted 6 lines
drivers/video/backlight/ktd3137.c new file +0
-0@@ -0,0 +1,262 @@
[ ... ]
drivers/video/backlight/ktd3137.c line 241
Quoted 4 lines
drivers/video/backlight/ktd3137.c new file +4
-0+static const struct i2c_device_id ktd3137_ids[] = { + {"ktd3137" }, + { } +};
[Severity: Low]
This isn't a bug, but in drivers/video/backlight/ktd3137.c, could the struct i2c_device_id entry in ktd3137_ids[] use a named initializer ({ .name = "ktd3137" }) instead of a positional initializer to match I2C subsystem conventions?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Daniel Thompson
maintainerQuoted 65 lines · On Mon, Nov 02, 2026 at 09:58:49PM +0200, Roman Vivchar via B4 Relay wrote:
From: Roman Vivchar <[email protected]>
Add support for the KTD3137 display backlight IC. It's used in various Xiaomi phones, such as Xiaomi Redmi Note 9.
Signed-off-by Roman Vivchar <[email protected]>--- MAINTAINERS | 1 + drivers/video/backlight/Kconfig | 11 ++ drivers/video/backlight/Makefile | 1 + drivers/video/backlight/ktd3137.c | 262 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 275 insertions(+)MAINTAINERS +1
-0@@ -14622,6 +14622,7 @@ KTD3137 BACKLIGHT DRIVER M: Roman Vivchar <[email protected]> S: Maintained F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktd3137.yaml +F: drivers/video/backlight/ktd3137.c KTEST M: Steven Rostedt <[email protected]>drivers/video/backlight/Kconfig +11
-0@@ -199,6 +199,17 @@ config BACKLIGHT_KTD2801 Say Y to enable the backlight driver for the Kinetic KTD2801 1-wire GPIO-controlled backlight found in Samsung Galaxy Core Prime VE LTE. +config BACKLIGHT_KTD3137 + tristate "Backlight Driver for Kinetic KTD3137" + depends on I2C + select REGMAP_I2C + help + Say Y to enable the backlight driver for the Kinetic KTD3137 + found in various Xiaomi smartphones. + + To compile this driver as a module, choose M here: the module + will be called ktd3137. + config BACKLIGHT_KTZ8866 tristate "Backlight Driver for Kinetic KTZ8866" depends on I2Cdrivers/video/backlight/Makefile +1
-0@@ -38,6 +38,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_KTD2801) += ktd2801-backlight.o +obj-$(CONFIG_BACKLIGHT_KTD3137) += ktd3137.o obj-$(CONFIG_BACKLIGHT_KTZ8866) += ktz8866.o obj-$(CONFIG_BACKLIGHT_LM3509) += lm3509_bl.o obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.odrivers/video/backlight/ktd3137.c new file +0
-0
drivers/video/backlight/ktd3137.c line 95
Quoted 7 lines
drivers/video/backlight/ktd3137.c new file +6
-0@@ -0,0 +1,262 @@ +static int ktd3137_init (struct ktd3137 *ktd) +{ +u32 val =KTD3137_CONTROL_DEFAULT |KTD3137_CONTROL_LINEAR ; +int ret; + + ret =regmap_write (ktd->regmap,KTD3137_REG_CONTROL , val);
Nitpicking but val seems a bit pointless here.
Quoted 60 lines
drivers/video/backlight/ktd3137.c new file +59
-0+if (ret) +return ret; + + ret =regmap_write (ktd->regmap,KTD3137_REG_PWM ,KTD3137_PWM_DEFAULT ); +if (ret) +return ret; + + ret =regmap_write (ktd->regmap,KTD3137_REG_RAMP_ON ,KTD3137_RAMP_DEFAULT ); +if (ret) +return ret; + + ret =regmap_write (ktd->regmap,KTD3137_REG_TRANS_RAMP ,0x00 ); +if (ret) +return ret; + +return regmap_update_bits (ktd->regmap,KTD3137_REG_MODE , +KTD3137_MODE_CURRENT_MASK , ktd->led_current); +} +static int ktd3137_probe (struct i2c_client *client) +{ +struct backlight_device *backlight_dev; +struct backlight_properties props = { }; +struct ktd3137 *ktd; +u32 val; +int ret; + + ktd =devm_kzalloc (&client->dev,sizeof (*ktd),GFP_KERNEL ); +if (!ktd) +return -ENOMEM ; + + ktd->dev = &client->dev; + + ret =devm_regulator_get_enable (ktd->dev,"vin" ); +if (ret) +return dev_err_probe (ktd->dev, ret,"failed to power up\n" ); + + ktd->enable_gpio =devm_gpiod_get_optional (ktd->dev,"enable" , +GPIOD_OUT_HIGH ); +if (IS_ERR (ktd->enable_gpio)) +return dev_err_probe (ktd->dev,PTR_ERR (ktd->enable_gpio), +"failed to get enable gpio\n" ); + +/* HWEN should stay HIGH for at least 150us before I2C can be used */ +fsleep (150 ); + + ktd->regmap =devm_regmap_init_i2c (client, &ktd3137_regmap_config); +if (IS_ERR (ktd->regmap)) +return dev_err_probe (ktd->dev,PTR_ERR (ktd->regmap), +"failed to init regmap\n" ); + + ret =regmap_read (ktd->regmap,KTD3137_REG_DEV_ID , &val); +if (ret) +return dev_err_probe (ktd->dev, ret,"failed to read chip id\n" ); + +if (val !=KTD3137_DEV_ID_A && val !=KTD3137_DEV_ID_B ) +return dev_err_probe (ktd->dev, -ENODEV , +"unsupported chip id: 0x%02x\n" , val); + + ret =ktd3137_parse_dt (ktd);
drivers/video/backlight/ktd3137.c line 210
Quoted 10 lines
drivers/video/backlight/ktd3137.c new file +10
-0+if (ret) +return ret; + + ret =ktd3137_init (ktd); +if (ret) +return dev_err_probe (ktd->dev, ret,"failed to init chip\n" ); + + props.type =BACKLIGHT_RAW ; + props.max_brightness =KTD3137_MAX_BRIGHTNESS ; + props.brightness =KTD3137_DEFAULT_BRIGHTNESS ;
No need for KTD3137_DEFAULT_BRIGHTNESS. Just use KTD3137_MAX_BRIGHTNESS.
drivers/video/backlight/ktd3137.c line 221
Quoted 11 lines
drivers/video/backlight/ktd3137.c new file +11
-0+ props.scale =BACKLIGHT_SCALE_LINEAR ; +device_property_read_u32 (ktd->dev,"default-brightness" , &props.brightness); + + backlight_dev =devm_backlight_device_register (ktd->dev, +"ktd3137-backlight" , + ktd->dev, ktd, + &ktd3137_backlight_ops, + &props); +if (IS_ERR (backlight_dev)) +return dev_err_probe (ktd->dev,PTR_ERR (backlight_dev), +"failed to register backlight device\n" );
dev_err_cast_probe()
Quoted 4 lines
drivers/video/backlight/ktd3137.c new file +4
-0+ +i2c_set_clientdata (client, backlight_dev); +return backlight_update_status (backlight_dev); +}
drivers/video/backlight/ktd3137.c line 235
Quoted 10 lines
drivers/video/backlight/ktd3137.c new file +10
-0+ +static void ktd3137_remove (struct i2c_client *client) +{ +struct backlight_device *backlight_dev =i2c_get_clientdata (client); +struct ktd3137 *ktd =bl_get_data (backlight_dev); + + backlight_dev->props.brightness =0 ; +backlight_update_status (backlight_dev); + +gpiod_set_value_cansleep (ktd->enable_gpio,0 );
Is this needed?
Quoted 1 line
+}
Daniel.
Quoted 5 lines · Daniel Thompson
Quoted 4 lines · On Mon, Nov 02, 2026 at 09:58:49PM +0200, Roman Vivchar via B4 Relay wrote:
From: Roman Vivchar <[email protected]>
Add support for the KTD3137 display backlight IC. It's used in various Xiaomi phones, such as Xiaomi Redmi Note 9.
...
Quoted 8 lines
drivers/video/backlight/ktd3137.c line 95
Quoted 6 lines
drivers/video/backlight/ktd3137.c new file +6
-0+static int ktd3137_init (struct ktd3137 *ktd) +{ +u32 val =KTD3137_CONTROL_DEFAULT |KTD3137_CONTROL_LINEAR ; +int ret; + + ret =regmap_write (ktd->regmap,KTD3137_REG_CONTROL , val);Nitpicking but val seems a bit pointless here.
Agreed.
Quoted 8 lines
Quoted 8 lines
drivers/video/backlight/ktd3137.c new file +6
-0+if (ret) +return ret; + + ret =regmap_write (ktd->regmap,KTD3137_REG_PWM ,KTD3137_PWM_DEFAULT ); +if (ret) +return ret;
...
Quoted 6 lines
drivers/video/backlight/ktd3137.c line 210
Quoted 4 lines
drivers/video/backlight/ktd3137.c new file +4
-0+ + props.type =BACKLIGHT_RAW ; + props.max_brightness =KTD3137_MAX_BRIGHTNESS ; + props.brightness =KTD3137_DEFAULT_BRIGHTNESS ;No need for
KTD3137_DEFAULT_BRIGHTNESS. Just useKTD3137_MAX_BRIGHTNESS.
Ack.
Quoted 15 lines
drivers/video/backlight/ktd3137.c line 221
Quoted 13 lines
drivers/video/backlight/ktd3137.c new file +11
-0+ props.scale =BACKLIGHT_SCALE_LINEAR ; +device_property_read_u32 (ktd->dev,"default-brightness" , &props.brightness); + + backlight_dev =devm_backlight_device_register (ktd->dev, +"ktd3137-backlight" , + ktd->dev, ktd, + &ktd3137_backlight_ops, + &props); +if (IS_ERR (backlight_dev)) +return dev_err_probe (ktd->dev,PTR_ERR (backlight_dev), +"failed to register backlight device\n" );
dev_err_cast_probe()
Didn't know about this one, thanks.
Quoted 18 lines
Quoted 6 lines
drivers/video/backlight/ktd3137.c new file +4
-0+ +i2c_set_clientdata (client, backlight_dev); +return backlight_update_status (backlight_dev); +}drivers/video/backlight/ktd3137.c line 235
Quoted 10 lines
drivers/video/backlight/ktd3137.c new file +10
-0+ +static void ktd3137_remove (struct i2c_client *client) +{ +struct backlight_device *backlight_dev =i2c_get_clientdata (client); +struct ktd3137 *ktd =bl_get_data (backlight_dev); + + backlight_dev->props.brightness =0 ; +backlight_update_status (backlight_dev); + +gpiod_set_value_cansleep (ktd->enable_gpio,0 );Is this needed?
The datasheet says "When HWEN is set high, ... if SCL/SDA’s pull up voltage is much less than VIN voltage, it can cause a small leakage current ..., there will be around 7uA additional leakage current from VIN in this standby mode."
It's better to put chip into shutdown mode, which won't cause power leakage according to the datasheet, and ensures that I2C registers will be reset in case chip needs to be cleanly re-initialized.
All other comments will be addressed in v2.
Best regards,
Roman
Quoted 6 lines
Quoted 2 lines
+}
Daniel.
Daniel Thompson
maintainerQuoted 14 lines · Roman Vivchar
Quoted 12 lines · Daniel Thompson
drivers/video/backlight/ktd3137.c line 235
Quoted 9 lines · On Mon, Nov 02, 2026 at 09:58:49PM +0200, Roman Vivchar via B4 Relay wrote:
drivers/video/backlight/ktd3137.c new file +9
-0+static void ktd3137_remove (struct i2c_client *client) +{ +struct backlight_device *backlight_dev =i2c_get_clientdata (client); +struct ktd3137 *ktd =bl_get_data (backlight_dev); + + backlight_dev->props.brightness =0 ; +backlight_update_status (backlight_dev); + +gpiod_set_value_cansleep (ktd->enable_gpio,0 );Is this needed?
Quoted 8 lines
The datasheet says "When HWEN is set high, ... if SCL/SDA’s pull up voltage is much less than VIN voltage, it can cause a small leakage current ..., there will be around 7uA additional leakage current from VIN in this standby mode."
It's better to put chip into shutdown mode, which won't cause power leakage according to the datasheet, and ensures that I2C registers will be reset in case chip needs to be cleanly re-initialized.
Right but this is the remove path which as about to free the gpiod anyway (allowing the GPIO driver to do whatever it likes and which will often be HiZ rather than pull-down).
Daniel.