Re: [PATCH v2 2/2] ARM: dts: qcom: msm8926-motorola-peregrine: Add initial device tree
Am Freitag, dem 15.12.2023 um 00:37 +0100 schrieb Konrad Dybcio: > > > On 12/14/23 21:59, André Apitzsch wrote: > > This dts adds support for Motorola Moto G 4G released in 2013. > > > > Add a device tree with initial support for: > > > > - GPIO keys > > - Hall sensor > > - SDHCI > > - Vibrator > > > > Signed-off-by: André Apitzsch > > --- > Excellent, thanks! > > Reviewed-by: Konrad Dybcio > > [...] > > > + pm8226_lvs1: lvs1 { > > + /* Pull-up for I2C lines */ > > + regulator-always-on; > > + }; > just one q: is this intended to stay a-on, or will it be bound > to some i2c host (presumably camera)? > > Konrad It's intended to stay always on. At least that's what downstream [1] did. André [1] https://github.com/LineageOS/android_kernel_motorola_msm8226/commit/bac97acacb0a868fa2cf96e53e18d6653c409a1b
[PATCH v2 1/2] dt-bindings: arm: qcom: Add Motorola Moto G 4G (2013)
Document the compatible for the MSM8926-based Motorola Moto G 4G smartphone released in 2013. Acked-by: Krzysztof Kozlowski Signed-off-by: André Apitzsch --- Documentation/devicetree/bindings/arm/qcom.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/arm/qcom.yaml b/Documentation/devicetree/bindings/arm/qcom.yaml index c968412d86b8..91dc3205d09e 100644 --- a/Documentation/devicetree/bindings/arm/qcom.yaml +++ b/Documentation/devicetree/bindings/arm/qcom.yaml @@ -185,6 +185,7 @@ properties: - enum: - microsoft,superman-lte - microsoft,tesla + - motorola,peregrine - const: qcom,msm8926 - const: qcom,msm8226 -- 2.43.0
[PATCH v2 0/2] ARM: dts: qcom: msm8926-motorola-peregrine: Add initial device tree
This dts adds support for Motorola Moto G 4G released in 2013. Add a device tree with initial support for: - GPIO keys - Hall sensor - SDHCI - Vibrator Signed-off-by: André Apitzsch --- Changes in v2: - Make clear it's about Moto G 4G released in 2013. - Add a-b to patch 1/2. - Combine nodes for gpio-keys. - Link to v1: https://lore.kernel.org/r/20231213-peregrine-v1-0-5229e21bc...@apitzsch.eu --- André Apitzsch (2): dt-bindings: arm: qcom: Add Motorola Moto G 4G (2013) ARM: dts: qcom: msm8926-motorola-peregrine: Add initial device tree Documentation/devicetree/bindings/arm/qcom.yaml| 1 + arch/arm/boot/dts/qcom/Makefile| 1 + .../dts/qcom/qcom-msm8926-motorola-peregrine.dts | 291 + 3 files changed, 293 insertions(+) --- base-commit: 11651f8cb2e88372d4ed523d909514dc9a613ea3 change-id: 20231208-peregrine-902ab2fb2cf5 Best regards, -- André Apitzsch
Re: [PATCH 0/2] ARM: dts: qcom: msm8926-motorola-peregrine: Add initial device tree
Am Mittwoch, dem 13.12.2023 um 21:44 +0100 schrieb Konrad Dybcio: > > > On 12/13/23 21:33, André Apitzsch wrote: > > This dts adds support for Motorola Moto G 4G released in 2013. > I have a similar one in my drawer.. not the 4g kind, titan IIRC? > Wasn't this one codenamed thea? > > Konrad Yes, thea is the 2nd generation of Moto G 4G, released in 2014. pregrine is the first generation, from 2013. Should > model = "Motorola Moto G 4G"; be updated, to reflect that it is 1st gen or should only "thea" (if it is added at all) have an addition in the model name? André
[PATCH 0/2] ARM: dts: qcom: msm8926-motorola-peregrine: Add initial device tree
This dts adds support for Motorola Moto G 4G released in 2013. Add a device tree with initial support for: - GPIO keys - Hall sensor - SDHCI - Vibrator Signed-off-by: André Apitzsch --- André Apitzsch (2): dt-bindings: arm: qcom: Add Motorola Moto G 4G ARM: dts: qcom: msm8926-motorola-peregrine: Add initial device tree Documentation/devicetree/bindings/arm/qcom.yaml| 1 + arch/arm/boot/dts/qcom/Makefile| 1 + .../dts/qcom/qcom-msm8926-motorola-peregrine.dts | 297 + 3 files changed, 299 insertions(+) --- base-commit: 48e8992e33abf054bcc0bb2e77b2d43bb899212e change-id: 20231208-peregrine-902ab2fb2cf5 Best regards, -- André Apitzsch
[PATCH 1/2] dt-bindings: arm: qcom: Add Motorola Moto G 4G
Document the compatible for the MSM8926-based Motorola Moto G 4G smartphone. Signed-off-by: André Apitzsch --- Documentation/devicetree/bindings/arm/qcom.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/arm/qcom.yaml b/Documentation/devicetree/bindings/arm/qcom.yaml index c968412d86b8..91dc3205d09e 100644 --- a/Documentation/devicetree/bindings/arm/qcom.yaml +++ b/Documentation/devicetree/bindings/arm/qcom.yaml @@ -185,6 +185,7 @@ properties: - enum: - microsoft,superman-lte - microsoft,tesla + - motorola,peregrine - const: qcom,msm8926 - const: qcom,msm8226 -- 2.43.0
[PATCH v2] arm64: dts: qcom: msm8939-longcheer-l9100: Add proximity-near-level
Consider an object near to the sensor when their distance is about 4 cm or below. Reviewed-by: Konrad Dybcio Signed-off-by: André Apitzsch --- Changes in v2: - add R-b - Link to v1: https://lore.kernel.org/r/20231016-bqm5_prox-v1-1-2acdc732b...@apitzsch.eu --- arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts b/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts index ff532fdc1826..e3404c4455cf 100644 --- a/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts +++ b/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts @@ -180,6 +180,7 @@ magnetometer@d { light-sensor@23 { compatible = "liteon,ltr559"; reg = <0x23>; + proximity-near-level = <75>; vdd-supply = <_l17>; vddio-supply = <_l5>; --- base-commit: 8c9660f6515396aba78d1168d2e17951d653ebf2 change-id: 20231016-bqm5_prox-4958ff602855 Best regards, -- André Apitzsch
Re: [PATCH] arm64: dts: qcom: msm8939-longcheer-l9100: Add proximity-near-level
Am Mittwoch, dem 18.10.2023 um 10:32 +0200 schrieb Konrad Dybcio: > > > On 10/17/23 22:03, André Apitzsch wrote: > > Am Dienstag, dem 17.10.2023 um 18:25 +0200 schrieb Konrad Dybcio: > > > > > > > > > On 10/16/23 22:18, André Apitzsch wrote: > > > > Consider an object near to the sensor when their distance is > > > > about > > > > 4 cm > > > > or below. > > > > > > > > Signed-off-by: André Apitzsch > > > > --- > > > Reviewed-by: Konrad Dybcio > > > > > > Out of interest, what is it set to by default? > > > > > > Konrad > > > > The default value is 0. > That much I could guess :) I was wondering if it meant more like "it > can detect movement from 1km away" or "disabled" > > Konrad I doubt that this sensor can detect anything from a distance of 50cm. The values returned by the sensor are all non-negative, i.e. zero means something like "disabled" as every raw proximity value would be considered 'near' to the sensor according to the description in iio/common.yaml. André
Re: [PATCH] arm64: dts: qcom: msm8939-longcheer-l9100: Add proximity-near-level
Am Dienstag, dem 17.10.2023 um 18:25 +0200 schrieb Konrad Dybcio: > > > On 10/16/23 22:18, André Apitzsch wrote: > > Consider an object near to the sensor when their distance is about > > 4 cm > > or below. > > > > Signed-off-by: André Apitzsch > > --- > Reviewed-by: Konrad Dybcio > > Out of interest, what is it set to by default? > > Konrad The default value is 0. André
[PATCH] arm64: dts: qcom: msm8939-longcheer-l9100: Add proximity-near-level
Consider an object near to the sensor when their distance is about 4 cm or below. Signed-off-by: André Apitzsch --- arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts b/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts index 6802714fda3f..43cadc826121 100644 --- a/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts +++ b/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts @@ -139,6 +139,7 @@ magnetometer@d { light-sensor@23 { compatible = "liteon,ltr559"; reg = <0x23>; + proximity-near-level = <75>; vdd-supply = <_l17>; vddio-supply = <_l5>; --- base-commit: 4d0515b235dec789578d135a5db586b25c5870cb change-id: 20231016-bqm5_prox-4958ff602855 Best regards, -- André Apitzsch
[PATCH 2/2] arm64: dts: qcom: msm8939-longcheer-l9100: Enable RGB LED
l9100 uses KTD2026 LED driver. Add it to the device tree. Signed-off-by: André Apitzsch --- .../boot/dts/qcom/msm8939-longcheer-l9100.dts | 51 ++ 1 file changed, 51 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts b/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts index 6802714fda3f..4eb33e36a8eb 100644 --- a/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts +++ b/arch/arm64/boot/dts/qcom/msm8939-longcheer-l9100.dts @@ -8,6 +8,7 @@ #include #include #include +#include #include / { @@ -120,6 +121,46 @@ usb_id: usb-id { }; +_i2c2 { + status = "okay"; + + led-controller@30 { + compatible = "kinetic,ktd2026"; + reg = <0x30>; + #address-cells = <1>; + #size-cells = <0>; + + vin-supply = <_l17>; + vio-supply = <_l6>; + + pinctrl-0 = <_led_default>; + pinctrl-names = "default"; + + multi-led { + color = ; + function = LED_FUNCTION_STATUS; + + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + }; + + led@1 { + reg = <1>; + color = ; + }; + + led@2 { + reg = <2>; + color = ; + }; + }; + }; +}; + _i2c3 { status = "okay"; @@ -184,6 +225,16 @@ _uart2 { status = "okay"; }; +_gpios { + status_led_default: status-led-default-state { + pins = "gpio3"; + function = PMIC_GPIO_FUNC_NORMAL; + power-source = ; + bias-disable; + output-high; + }; +}; + _mpps { pwm_out: mpp4-state { pins = "mpp4"; -- 2.42.0
[PATCH 0/2] arm64: dts: qcom: longcheer l8910 and l9100: Enable RGB LED
With the driver for ktd2026 recently applied to linux-leds[1], the LED can be enabled on longcheer l8910 and l9100. [1] https://lore.kernel.org/all/20231002-ktd202x-v6-0-26be8eefe...@apitzsch.eu/ Signed-off-by: André Apitzsch --- André Apitzsch (2): arm64: dts: qcom: msm8916-longcheer-l8910: Enable RGB LED arm64: dts: qcom: msm8939-longcheer-l9100: Enable RGB LED .../boot/dts/qcom/msm8916-longcheer-l8910.dts | 51 ++ .../boot/dts/qcom/msm8939-longcheer-l9100.dts | 51 ++ 2 files changed, 102 insertions(+) --- base-commit: beb63bee4857fd3661305eecd025a7c26c56 change-id: 20231013-bq_leds-0d8a9b15ec6a Best regards, -- André Apitzsch
[PATCH 1/2] arm64: dts: qcom: msm8916-longcheer-l8910: Enable RGB LED
l8910 uses KTD2026 LED driver. Add it to the device tree. Tested-by: Stephan Gerhold Signed-off-by: André Apitzsch --- .../boot/dts/qcom/msm8916-longcheer-l8910.dts | 51 ++ 1 file changed, 51 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/msm8916-longcheer-l8910.dts b/arch/arm64/boot/dts/qcom/msm8916-longcheer-l8910.dts index 41cadb906b98..68258cf4205f 100644 --- a/arch/arm64/boot/dts/qcom/msm8916-longcheer-l8910.dts +++ b/arch/arm64/boot/dts/qcom/msm8916-longcheer-l8910.dts @@ -6,6 +6,7 @@ #include #include #include +#include / { model = "BQ Aquaris X5 (Longcheer L8910)"; @@ -74,6 +75,46 @@ usb_id: usb-id { }; }; +_i2c2 { + status = "okay"; + + led-controller@30 { + compatible = "kinetic,ktd2026"; + reg = <0x30>; + #address-cells = <1>; + #size-cells = <0>; + + vin-supply = <_l17>; + vio-supply = <_l6>; + + pinctrl-0 = <_led_default>; + pinctrl-names = "default"; + + multi-led { + color = ; + function = LED_FUNCTION_STATUS; + + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + }; + + led@1 { + reg = <1>; + color = ; + }; + + led@2 { + reg = <2>; + color = ; + }; + }; + }; +}; + _i2c3 { status = "okay"; @@ -107,6 +148,16 @@ _uart2 { status = "okay"; }; +_gpios { + status_led_default: status-led-default-state { + pins = "gpio3"; + function = PMIC_GPIO_FUNC_NORMAL; + power-source = ; + bias-disable; + output-high; + }; +}; + _resin { status = "okay"; linux,code = ; -- 2.42.0
[PATCH v6 2/2] leds: add ktd202x driver
This commit adds support for Kinetic KTD2026/7 RGB/White LED driver. Signed-off-by: André Apitzsch --- drivers/leds/rgb/Kconfig| 13 + drivers/leds/rgb/Makefile | 1 + drivers/leds/rgb/leds-ktd202x.c | 625 3 files changed, 639 insertions(+) diff --git a/drivers/leds/rgb/Kconfig b/drivers/leds/rgb/Kconfig index 183bccc06cf3..a6a21f564673 100644 --- a/drivers/leds/rgb/Kconfig +++ b/drivers/leds/rgb/Kconfig @@ -14,6 +14,19 @@ config LEDS_GROUP_MULTICOLOR To compile this driver as a module, choose M here: the module will be called leds-group-multicolor. +config LEDS_KTD202X + tristate "LED support for KTD202x Chips" + depends on I2C + depends on OF + select REGMAP_I2C + help + This option enables support for the Kinetic KTD2026/KTD2027 + RGB/White LED driver found in different BQ mobile phones. + It is a 3 or 4 channel LED driver programmed via an I2C interface. + + To compile this driver as a module, choose M here: the module + will be called leds-ktd202x. + config LEDS_PWM_MULTICOLOR tristate "PWM driven multi-color LED Support" depends on PWM diff --git a/drivers/leds/rgb/Makefile b/drivers/leds/rgb/Makefile index c11cc56384e7..243f31e4d70d 100644 --- a/drivers/leds/rgb/Makefile +++ b/drivers/leds/rgb/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_LEDS_GROUP_MULTICOLOR)+= leds-group-multicolor.o +obj-$(CONFIG_LEDS_KTD202X) += leds-ktd202x.o obj-$(CONFIG_LEDS_PWM_MULTICOLOR) += leds-pwm-multicolor.o obj-$(CONFIG_LEDS_QCOM_LPG)+= leds-qcom-lpg.o obj-$(CONFIG_LEDS_MT6370_RGB) += leds-mt6370-rgb.o diff --git a/drivers/leds/rgb/leds-ktd202x.c b/drivers/leds/rgb/leds-ktd202x.c new file mode 100644 index ..514965795a10 --- /dev/null +++ b/drivers/leds/rgb/leds-ktd202x.c @@ -0,0 +1,625 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Kinetic KTD2026/7 RGB/White LED driver with I2C interface + * + * Copyright 2023 André Apitzsch + * + * Datasheet: https://www.kinet-ic.com/uploads/KTD2026-7-04h.pdf + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define KTD2026_NUM_LEDS 3 +#define KTD2027_NUM_LEDS 4 +#define KTD202X_MAX_LEDS 4 + +/* Register bank */ +#define KTD202X_REG_RESET_CONTROL 0x00 +#define KTD202X_REG_FLASH_PERIOD 0x01 +#define KTD202X_REG_PWM1_TIMER 0x02 +#define KTD202X_REG_PWM2_TIMER 0x03 +#define KTD202X_REG_CHANNEL_CTRL 0x04 +#define KTD202X_REG_TRISE_FALL 0x05 +#define KTD202X_REG_LED_IOUT(x)(0x06 + (x)) + +/* Register 0 */ +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT1 0x00 +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT2 0x01 +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT3 0x02 +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT4 0x03 +#define KTD202X_RSTR_RESET 0x07 + +#define KTD202X_ENABLE_CTRL_WAKE 0x00 /* SCL High & SDA High */ +#define KTD202X_ENABLE_CTRL_SLEEP 0x08 /* SCL High & SDA Toggling */ + +#define KTD202X_TRISE_FALL_SCALE_NORMAL0x00 +#define KTD202X_TRISE_FALL_SCALE_SLOW_X2 0x20 +#define KTD202X_TRISE_FALL_SCALE_SLOW_X4 0x40 +#define KTD202X_TRISE_FALL_SCALE_FAST_X8 0x60 + +/* Register 1 */ +#define KTD202X_FLASH_PERIOD_256_MS_LOG_RAMP 0x00 + +/* Register 2-3 */ +#define KTD202X_FLASH_ON_TIME_0_4_PERCENT 0x01 + +/* Register 4 */ +#define KTD202X_CHANNEL_CTRL_MASK(x) (BIT(2 * (x)) | BIT(2 * (x) + 1)) +#define KTD202X_CHANNEL_CTRL_OFF 0x00 +#define KTD202X_CHANNEL_CTRL_ON(x) BIT(2 * (x)) +#define KTD202X_CHANNEL_CTRL_PWM1(x) BIT(2 * (x) + 1) +#define KTD202X_CHANNEL_CTRL_PWM2(x) (BIT(2 * (x)) | BIT(2 * (x) + 1)) + +/* Register 5 */ +#define KTD202X_RAMP_TIMES_2_MS0x00 + +/* Register 6-9 */ +#define KTD202X_LED_CURRENT_10_mA 0x4f + +#define KTD202X_FLASH_PERIOD_MIN_MS 256 +#define KTD202X_FLASH_PERIOD_STEP_MS 128 +#define KTD202X_FLASH_PERIOD_MAX_STEPS 126 +#define KTD202X_FLASH_ON_MAX 256 + +#define KTD202X_MAX_BRIGHTNESS 192 + +static const struct reg_default ktd202x_reg_defaults[] = { + { KTD202X_REG_RESET_CONTROL, KTD202X_TIMER_SLOT_CONTROL_TSLOT1 | + KTD202X_ENABLE_CTRL_WAKE | KTD202X_TRISE_FALL_SCALE_NORMAL }, + { KTD202X_REG_FLASH_PERIOD, KTD202X_FLASH_PERIOD_256_MS_LOG_RAMP }, + { KTD202X_REG_PWM1_TIMER, KTD202X_FLASH_ON_TIME_0_4_PERCENT }, + { KTD202X_REG_PWM2_TIMER, KTD202X_FLASH_ON_TIME_0_4_PERCENT }, + { KTD202X_REG_CHANNEL_CTRL, KTD202X_CHANNEL_CTRL_OFF }, + { KTD202X_REG_TRISE_FALL, KTD202X_RAMP_TIMES_2_MS }, + { KTD202X_REG_LED_IOUT(0), KTD202X_LED_CURRENT_10_mA }, + { KTD202X_REG_LED_IOUT(1), KTD202X_LED_CURRENT_10_mA }, + { KTD202X_REG_LED_IOUT(2), KTD202X_LED_CURRENT_10_mA }, +
[PATCH v6 0/2] leds: Add a driver for KTD202x
Add the binding description and the corresponding driver for the Kinetic KTD2026 and KTD2027. Signed-off-by: André Apitzsch --- Changes in v6: - Remove un-needed inits - Narrow scope of variables - Release of_node references on early exit - Pass child node to dev_err() in ktd202x_setup_led_rgb() - Link to v5: https://lore.kernel.org/r/20231001-ktd202x-v5-0-f544a1d05...@apitzsch.eu Changes in v5: - Restructure brightness_set() + add comments to it to be easier understandable - Add some line breaks + remove little line-wraps to improve readability - Move parts of add_led() to setup_led_{rgb,single}() - Move mutex_init() to the end of probe to omit gotos - Fix grammar - Set initial intensity to max brightness to avoid LED staying off when brightness is changed after switching to timer trigger, because of zero intensity - Link to v4: https://lore.kernel.org/r/20230923-ktd202x-v4-0-14f724f6d...@apitzsch.eu Changes in v4: - Annotate struct ktd202x with __counted_by - Link to v3: https://lore.kernel.org/r/20230906-ktd202x-v3-0-7fcb91c65...@apitzsch.eu Changes in v3: - Add r-b to bindings patch - Replace .probe_new by .probe - Link to v2: https://lore.kernel.org/r/20230901-ktd202x-v2-0-3cb8b0ca0...@apitzsch.eu Changes in v2: - Make binding description filename match compatible - Address comments by Lee Jones - Extend driver description in Kconfig - Add copyright + link to datasheet - Add unit to definition/variable names, where needed - Define magic numbers - Remove forward declaration of 'struct ktd202x' - Remove superfluous comments - Get rid of struct ktd202x_info - Join ktd202x_chip_init() with ktd202x_chip_enable() - Return the error on ktd202x_chip_disable() - Remove unreachable case from chip_in_use() - Rename ktd202x_brightness_set() argument from num_colors to num_channels - Forward errors received in ktd202x_brightness_set() - Remove variable for 'num_channels = 1' - Add some explanations to blink time calculation - Remove unneeded lcdev from ktd202x_blink_*_set() - Add define for max brightness and replace deprecated LED_FULL by it - Move setting led_classdev.brightness to ktd202x_brightness_*_set() - Move mutex_lock inside ktd202x_blink_set() - Add comment that 'color' property is optional (allow EINVAL) - Replace escaped double quotes by single quotes - Avoid overloading variable 'color' - Do not lock during probe - Remove usage of 'of_match_ptr' - Document interrupt and pull-up supply, like done for aw2013[1] - Fix error in num_steps calculation - Link to v1: https://lore.kernel.org/r/20230618-ktd202x-v1-0-fc182fefa...@apitzsch.eu [1] https://lore.kernel.org/linux-leds/20230815-aw2013-vio-v3-0-2505296b0...@gerhold.net/ --- André Apitzsch (2): dt-bindings: leds: Add Kinetic KTD2026/2027 LED leds: add ktd202x driver .../devicetree/bindings/leds/kinetic,ktd202x.yaml | 171 ++ drivers/leds/rgb/Kconfig | 13 + drivers/leds/rgb/Makefile | 1 + drivers/leds/rgb/leds-ktd202x.c| 625 + 4 files changed, 810 insertions(+) --- base-commit: 165adeea3617ea22dc49f8880474ebf3a98b696d change-id: 20230618-ktd202x-546b2a7d240b Best regards, -- André Apitzsch
[PATCH v6 1/2] dt-bindings: leds: Add Kinetic KTD2026/2027 LED
Document Kinetic KTD2026/2027 LED driver devicetree bindings. Reviewed-by: Krzysztof Kozlowski Signed-off-by: André Apitzsch --- .../devicetree/bindings/leds/kinetic,ktd202x.yaml | 171 + 1 file changed, 171 insertions(+) diff --git a/Documentation/devicetree/bindings/leds/kinetic,ktd202x.yaml b/Documentation/devicetree/bindings/leds/kinetic,ktd202x.yaml new file mode 100644 index ..832c030a5acf --- /dev/null +++ b/Documentation/devicetree/bindings/leds/kinetic,ktd202x.yaml @@ -0,0 +1,171 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/kinetic,ktd202x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Kinetic KTD2026/7 RGB/White LED Driver + +maintainers: + - André Apitzsch + +description: | + The KTD2026/7 is a RGB/White LED driver with I2C interface. + + The data sheet can be found at: +https://www.kinet-ic.com/uploads/KTD2026-7-04h.pdf + +properties: + compatible: +enum: + - kinetic,ktd2026 + - kinetic,ktd2027 + + reg: +maxItems: 1 + + vin-supply: +description: Regulator providing power to the "VIN" pin. + + vio-supply: +description: Regulator providing power for pull-up of the I/O lines. + Note that this regulator does not directly connect to KTD2026, but is + needed for the correct operation of the status ("ST") and I2C lines. + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + + multi-led: +type: object +$ref: leds-class-multicolor.yaml# +unevaluatedProperties: false + +properties: + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^led@[0-3]$": +type: object +$ref: common.yaml# +unevaluatedProperties: false + +properties: + reg: +description: Index of the LED. +minimum: 0 +maximum: 3 + +required: + - reg + - color + +required: + - "#address-cells" + - "#size-cells" + +patternProperties: + "^led@[0-3]$": +type: object +$ref: common.yaml# +unevaluatedProperties: false + +properties: + reg: +description: Index of the LED. +minimum: 0 +maximum: 3 + +required: + - reg + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | +#include + +i2c { +#address-cells = <1>; +#size-cells = <0>; + +led-controller@30 { +compatible = "kinetic,ktd2026"; +reg = <0x30>; +#address-cells = <1>; +#size-cells = <0>; + +vin-supply = <_l17>; +vio-supply = <_l6>; + +led@0 { +reg = <0>; +function = LED_FUNCTION_STATUS; +color = ; +}; + +led@1 { +reg = <1>; +function = LED_FUNCTION_STATUS; +color = ; +}; + +led@2 { +reg = <2>; +function = LED_FUNCTION_STATUS; +color = ; +}; +}; +}; + - | +#include + +i2c { +#address-cells = <1>; +#size-cells = <0>; + +led-controller@30 { +compatible = "kinetic,ktd2026"; +reg = <0x30>; +#address-cells = <1>; +#size-cells = <0>; + +vin-supply = <_l17>; +vio-supply = <_l6>; + +multi-led { +color = ; +function = LED_FUNCTION_STATUS; + +#address-cells = <1>; +#size-cells = <0>; + +led@0 { +reg = <0>; +color = ; +}; + +led@1 { +reg = <1>; +color = ; +}; + +led@2 { +reg = <2>; +color = ; +}; +}; +}; +}; -- 2.42.0
Re: [PATCH v5 2/2] leds: add ktd202x driver
Am Sonntag, dem 01.10.2023 um 22:46 +0200 schrieb Christophe JAILLET: > Le 01/10/2023 à 18:56, André Apitzsch a écrit : > > Hi Christophe, > > > > Am Sonntag, dem 01.10.2023 um 17:15 +0200 schrieb Christophe > > JAILLET: > > > Le 01/10/2023 à 15:52, André Apitzsch a écrit : > > > > This commit adds support for Kinetic KTD2026/7 RGB/White LED > > > > driver. > > > > > > > > Signed-off-by: André Apitzsch > > > > > > > > > > ... > > > > > > > +static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct > > > > device_node *np, > > > > + struct ktd202x_led *led, > > > > struct > > > > led_init_data *init_data) > > > > +{ > > > > + struct led_classdev *cdev; > > > > + struct device_node *child; > > > > + struct mc_subled *info; > > > > + int num_channels; > > > > + int i = 0; > > > > + u32 reg; > > > > + int ret; > > > > + > > > > + num_channels = of_get_available_child_count(np); > > > > + if (!num_channels || num_channels > chip->num_leds) > > > > + return -EINVAL; > > > > + > > > > + info = devm_kcalloc(chip->dev, num_channels, > > > > sizeof(*info), > > > > GFP_KERNEL); > > > > + if (!info) > > > > + return -ENOMEM; > > > > + > > > > + for_each_available_child_of_node(np, child) { > > > > + u32 mono_color = 0; > > > > > > Un-needed init. > > > And, why is it defined here, while reg is defined out-side the > > > loop? > > > > I'll move it out-side the loop (without initialization). > > > > > > > > > + > > > > + ret = of_property_read_u32(child, "reg", ); > > > > + if (ret != 0 || reg >= chip->num_leds) { > > > > + dev_err(chip->dev, "invalid 'reg' of > > > > %pOFn\n", np); > > > > > > Mossing of_node_put(np);? > > > > It shouldn't be needed here if handled in the calling function, > > right? > > How can the caller do this? > > The goal of this of_node_put() is to release a reference taken by the > for_each_available_child_of_node() loop, in case of early exit. > > The caller can't know if np needs to be released or not. An error > code > is returned either if an error occurs within the for_each loop, or if > devm_led_classdev_multicolor_register_ext() fails. > > More over, in your case the caller is ktd202x_add_led(). > From there either ktd202x_setup_led_rgb() or > ktd202x_setup_led_single() > is called. > > ktd202x_setup_led_single() does not take any reference to np. > But if it fails, of_node_put() would still be called. > > Hello Christophe, It seems I misunderstood when of_node_put() is used. Thanks for the explanation. While checking the usage of of_node_put(), I noticed that dev_err() (and of_node_put()) should take "child" and not "np", here. André > > > > > > > + return -EINVAL; > > > > + } > > > > + > > > > + ret = of_property_read_u32(child, "color", > > > > _color); > > > > + if (ret < 0 && ret != -EINVAL) { > > > > + dev_err(chip->dev, "failed to parse > > > > 'color' > > > > of %pOF\n", np); > > > > > > Mossing of_node_put(np);? > > > > > > > + return ret; > > > > + } > > > > + > > > > + info[i].color_index = mono_color; > > > > + info[i].channel = reg; > > > > + info[i].intensity = KTD202X_MAX_BRIGHTNESS; > > > > + i++; > > > > + } > > > > + > > > > + led->mcdev.subled_info = info; > > > > + led->mcdev.num_colors = num_channels; > > > > + > > > > + cdev = >mcdev.led_cdev; > > > > + cdev->brightness_set_blocking = > > > > ktd202x_brightness_mc_set; > > > > + cdev->blink_set = ktd202x_blink_mc_set; > > > > + > > > > + return devm_led_classdev_multicolor_
Re: [PATCH v5 2/2] leds: add ktd202x driver
Hi Christophe, Am Sonntag, dem 01.10.2023 um 17:15 +0200 schrieb Christophe JAILLET: > Le 01/10/2023 à 15:52, André Apitzsch a écrit : > > This commit adds support for Kinetic KTD2026/7 RGB/White LED > > driver. > > > > Signed-off-by: André Apitzsch > > > > ... > > > +static int ktd202x_setup_led_rgb(struct ktd202x *chip, struct > > device_node *np, > > + struct ktd202x_led *led, struct > > led_init_data *init_data) > > +{ > > + struct led_classdev *cdev; > > + struct device_node *child; > > + struct mc_subled *info; > > + int num_channels; > > + int i = 0; > > + u32 reg; > > + int ret; > > + > > + num_channels = of_get_available_child_count(np); > > + if (!num_channels || num_channels > chip->num_leds) > > + return -EINVAL; > > + > > + info = devm_kcalloc(chip->dev, num_channels, sizeof(*info), > > GFP_KERNEL); > > + if (!info) > > + return -ENOMEM; > > + > > + for_each_available_child_of_node(np, child) { > > + u32 mono_color = 0; > > Un-needed init. > And, why is it defined here, while reg is defined out-side the loop? I'll move it out-side the loop (without initialization). > > > + > > + ret = of_property_read_u32(child, "reg", ); > > + if (ret != 0 || reg >= chip->num_leds) { > > + dev_err(chip->dev, "invalid 'reg' of > > %pOFn\n", np); > > Mossing of_node_put(np);? It shouldn't be needed here if handled in the calling function, right? > > > + return -EINVAL; > > + } > > + > > + ret = of_property_read_u32(child, "color", > > _color); > > + if (ret < 0 && ret != -EINVAL) { > > + dev_err(chip->dev, "failed to parse 'color' > > of %pOF\n", np); > > Mossing of_node_put(np);? > > > + return ret; > > + } > > + > > + info[i].color_index = mono_color; > > + info[i].channel = reg; > > + info[i].intensity = KTD202X_MAX_BRIGHTNESS; > > + i++; > > + } > > + > > + led->mcdev.subled_info = info; > > + led->mcdev.num_colors = num_channels; > > + > > + cdev = >mcdev.led_cdev; > > + cdev->brightness_set_blocking = ktd202x_brightness_mc_set; > > + cdev->blink_set = ktd202x_blink_mc_set; > > + > > + return devm_led_classdev_multicolor_register_ext(chip->dev, > > >mcdev, init_data); > > +} > > + > > +static int ktd202x_setup_led_single(struct ktd202x *chip, struct > > device_node *np, > > + struct ktd202x_led *led, struct > > led_init_data *init_data) > > +{ > > + struct led_classdev *cdev; > > + u32 reg; > > + int ret; > > + > > + ret = of_property_read_u32(np, "reg", ); > > + if (ret != 0 || reg >= chip->num_leds) { > > + dev_err(chip->dev, "invalid 'reg' of %pOFn\n", np); > > + return -EINVAL; > > + } > > + led->index = reg; > > + > > + cdev = >cdev; > > + cdev->brightness_set_blocking = > > ktd202x_brightness_single_set; > > + cdev->blink_set = ktd202x_blink_single_set; > > + > > + return devm_led_classdev_register_ext(chip->dev, > > >cdev, init_data); > > +} > > + > > +static int ktd202x_add_led(struct ktd202x *chip, struct > > device_node *np, unsigned int index) > > +{ > > + struct ktd202x_led *led = >leds[index]; > > + struct led_init_data init_data = {}; > > + struct led_classdev *cdev; > > + u32 color = 0; > Un-needed init. > > > + int ret; > > + > > + /* Color property is optional in single color case */ > > + ret = of_property_read_u32(np, "color", ); > > + if (ret < 0 && ret != -EINVAL) { > > + dev_err(chip->dev, "failed to parse 'color' of > > %pOF\n", np); > > + return ret; > > + } > > + > > + led->chip = chip; > > + init_data.fwnode = of_fwnode_handle(np); > > + > > + if (color
[PATCH v5 2/2] leds: add ktd202x driver
This commit adds support for Kinetic KTD2026/7 RGB/White LED driver. Signed-off-by: André Apitzsch --- drivers/leds/rgb/Kconfig| 13 + drivers/leds/rgb/Makefile | 1 + drivers/leds/rgb/leds-ktd202x.c | 619 3 files changed, 633 insertions(+) diff --git a/drivers/leds/rgb/Kconfig b/drivers/leds/rgb/Kconfig index 183bccc06cf3..a6a21f564673 100644 --- a/drivers/leds/rgb/Kconfig +++ b/drivers/leds/rgb/Kconfig @@ -14,6 +14,19 @@ config LEDS_GROUP_MULTICOLOR To compile this driver as a module, choose M here: the module will be called leds-group-multicolor. +config LEDS_KTD202X + tristate "LED support for KTD202x Chips" + depends on I2C + depends on OF + select REGMAP_I2C + help + This option enables support for the Kinetic KTD2026/KTD2027 + RGB/White LED driver found in different BQ mobile phones. + It is a 3 or 4 channel LED driver programmed via an I2C interface. + + To compile this driver as a module, choose M here: the module + will be called leds-ktd202x. + config LEDS_PWM_MULTICOLOR tristate "PWM driven multi-color LED Support" depends on PWM diff --git a/drivers/leds/rgb/Makefile b/drivers/leds/rgb/Makefile index c11cc56384e7..243f31e4d70d 100644 --- a/drivers/leds/rgb/Makefile +++ b/drivers/leds/rgb/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_LEDS_GROUP_MULTICOLOR)+= leds-group-multicolor.o +obj-$(CONFIG_LEDS_KTD202X) += leds-ktd202x.o obj-$(CONFIG_LEDS_PWM_MULTICOLOR) += leds-pwm-multicolor.o obj-$(CONFIG_LEDS_QCOM_LPG)+= leds-qcom-lpg.o obj-$(CONFIG_LEDS_MT6370_RGB) += leds-mt6370-rgb.o diff --git a/drivers/leds/rgb/leds-ktd202x.c b/drivers/leds/rgb/leds-ktd202x.c new file mode 100644 index ..57f69d2c30f8 --- /dev/null +++ b/drivers/leds/rgb/leds-ktd202x.c @@ -0,0 +1,619 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Kinetic KTD2026/7 RGB/White LED driver with I2C interface + * + * Copyright 2023 André Apitzsch + * + * Datasheet: https://www.kinet-ic.com/uploads/KTD2026-7-04h.pdf + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define KTD2026_NUM_LEDS 3 +#define KTD2027_NUM_LEDS 4 +#define KTD202X_MAX_LEDS 4 + +/* Register bank */ +#define KTD202X_REG_RESET_CONTROL 0x00 +#define KTD202X_REG_FLASH_PERIOD 0x01 +#define KTD202X_REG_PWM1_TIMER 0x02 +#define KTD202X_REG_PWM2_TIMER 0x03 +#define KTD202X_REG_CHANNEL_CTRL 0x04 +#define KTD202X_REG_TRISE_FALL 0x05 +#define KTD202X_REG_LED_IOUT(x)(0x06 + (x)) + +/* Register 0 */ +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT1 0x00 +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT2 0x01 +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT3 0x02 +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT4 0x03 +#define KTD202X_RSTR_RESET 0x07 + +#define KTD202X_ENABLE_CTRL_WAKE 0x00 /* SCL High & SDA High */ +#define KTD202X_ENABLE_CTRL_SLEEP 0x08 /* SCL High & SDA Toggling */ + +#define KTD202X_TRISE_FALL_SCALE_NORMAL0x00 +#define KTD202X_TRISE_FALL_SCALE_SLOW_X2 0x20 +#define KTD202X_TRISE_FALL_SCALE_SLOW_X4 0x40 +#define KTD202X_TRISE_FALL_SCALE_FAST_X8 0x60 + +/* Register 1 */ +#define KTD202X_FLASH_PERIOD_256_MS_LOG_RAMP 0x00 + +/* Register 2-3 */ +#define KTD202X_FLASH_ON_TIME_0_4_PERCENT 0x01 + +/* Register 4 */ +#define KTD202X_CHANNEL_CTRL_MASK(x) (BIT(2 * (x)) | BIT(2 * (x) + 1)) +#define KTD202X_CHANNEL_CTRL_OFF 0x00 +#define KTD202X_CHANNEL_CTRL_ON(x) BIT(2 * (x)) +#define KTD202X_CHANNEL_CTRL_PWM1(x) BIT(2 * (x) + 1) +#define KTD202X_CHANNEL_CTRL_PWM2(x) (BIT(2 * (x)) | BIT(2 * (x) + 1)) + +/* Register 5 */ +#define KTD202X_RAMP_TIMES_2_MS0x00 + +/* Register 6-9 */ +#define KTD202X_LED_CURRENT_10_mA 0x4f + +#define KTD202X_FLASH_PERIOD_MIN_MS 256 +#define KTD202X_FLASH_PERIOD_STEP_MS 128 +#define KTD202X_FLASH_PERIOD_MAX_STEPS 126 +#define KTD202X_FLASH_ON_MAX 256 + +#define KTD202X_MAX_BRIGHTNESS 192 + +static const struct reg_default ktd202x_reg_defaults[] = { + { KTD202X_REG_RESET_CONTROL, KTD202X_TIMER_SLOT_CONTROL_TSLOT1 | + KTD202X_ENABLE_CTRL_WAKE | KTD202X_TRISE_FALL_SCALE_NORMAL }, + { KTD202X_REG_FLASH_PERIOD, KTD202X_FLASH_PERIOD_256_MS_LOG_RAMP }, + { KTD202X_REG_PWM1_TIMER, KTD202X_FLASH_ON_TIME_0_4_PERCENT }, + { KTD202X_REG_PWM2_TIMER, KTD202X_FLASH_ON_TIME_0_4_PERCENT }, + { KTD202X_REG_CHANNEL_CTRL, KTD202X_CHANNEL_CTRL_OFF }, + { KTD202X_REG_TRISE_FALL, KTD202X_RAMP_TIMES_2_MS }, + { KTD202X_REG_LED_IOUT(0), KTD202X_LED_CURRENT_10_mA }, + { KTD202X_REG_LED_IOUT(1), KTD202X_LED_CURRENT_10_mA }, + { KTD202X_REG_LED_IOUT(2), KTD202X_LED_CURRENT_10_mA }, +
[PATCH v5 1/2] dt-bindings: leds: Add Kinetic KTD2026/2027 LED
Document Kinetic KTD2026/2027 LED driver devicetree bindings. Reviewed-by: Krzysztof Kozlowski Signed-off-by: André Apitzsch --- .../devicetree/bindings/leds/kinetic,ktd202x.yaml | 171 + 1 file changed, 171 insertions(+) diff --git a/Documentation/devicetree/bindings/leds/kinetic,ktd202x.yaml b/Documentation/devicetree/bindings/leds/kinetic,ktd202x.yaml new file mode 100644 index ..832c030a5acf --- /dev/null +++ b/Documentation/devicetree/bindings/leds/kinetic,ktd202x.yaml @@ -0,0 +1,171 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/kinetic,ktd202x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Kinetic KTD2026/7 RGB/White LED Driver + +maintainers: + - André Apitzsch + +description: | + The KTD2026/7 is a RGB/White LED driver with I2C interface. + + The data sheet can be found at: +https://www.kinet-ic.com/uploads/KTD2026-7-04h.pdf + +properties: + compatible: +enum: + - kinetic,ktd2026 + - kinetic,ktd2027 + + reg: +maxItems: 1 + + vin-supply: +description: Regulator providing power to the "VIN" pin. + + vio-supply: +description: Regulator providing power for pull-up of the I/O lines. + Note that this regulator does not directly connect to KTD2026, but is + needed for the correct operation of the status ("ST") and I2C lines. + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + + multi-led: +type: object +$ref: leds-class-multicolor.yaml# +unevaluatedProperties: false + +properties: + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^led@[0-3]$": +type: object +$ref: common.yaml# +unevaluatedProperties: false + +properties: + reg: +description: Index of the LED. +minimum: 0 +maximum: 3 + +required: + - reg + - color + +required: + - "#address-cells" + - "#size-cells" + +patternProperties: + "^led@[0-3]$": +type: object +$ref: common.yaml# +unevaluatedProperties: false + +properties: + reg: +description: Index of the LED. +minimum: 0 +maximum: 3 + +required: + - reg + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | +#include + +i2c { +#address-cells = <1>; +#size-cells = <0>; + +led-controller@30 { +compatible = "kinetic,ktd2026"; +reg = <0x30>; +#address-cells = <1>; +#size-cells = <0>; + +vin-supply = <_l17>; +vio-supply = <_l6>; + +led@0 { +reg = <0>; +function = LED_FUNCTION_STATUS; +color = ; +}; + +led@1 { +reg = <1>; +function = LED_FUNCTION_STATUS; +color = ; +}; + +led@2 { +reg = <2>; +function = LED_FUNCTION_STATUS; +color = ; +}; +}; +}; + - | +#include + +i2c { +#address-cells = <1>; +#size-cells = <0>; + +led-controller@30 { +compatible = "kinetic,ktd2026"; +reg = <0x30>; +#address-cells = <1>; +#size-cells = <0>; + +vin-supply = <_l17>; +vio-supply = <_l6>; + +multi-led { +color = ; +function = LED_FUNCTION_STATUS; + +#address-cells = <1>; +#size-cells = <0>; + +led@0 { +reg = <0>; +color = ; +}; + +led@1 { +reg = <1>; +color = ; +}; + +led@2 { +reg = <2>; +color = ; +}; +}; +}; +}; -- 2.42.0
[PATCH v5 0/2] leds: Add a driver for KTD202x
Add the binding description and the corresponding driver for the Kinetic KTD2026 and KTD2027. Signed-off-by: André Apitzsch --- Changes in v5: - Restructure brightness_set() + add comments to it to be easier understandable - Add some line breaks + remove little line-wraps to improve readability - Move parts of add_led() to setup_led_{rgb,single}() - Move mutex_init() to the end of probe to omit gotos - Fix grammar - Set initial intensity to max brightness to avoid LED staying off when brightness is changed after switching to timer trigger, because of zero intensity - Link to v4: https://lore.kernel.org/r/20230923-ktd202x-v4-0-14f724f6d...@apitzsch.eu Changes in v4: - Annotate struct ktd202x with __counted_by - Link to v3: https://lore.kernel.org/r/20230906-ktd202x-v3-0-7fcb91c65...@apitzsch.eu Changes in v3: - Add r-b to bindings patch - Replace .probe_new by .probe - Link to v2: https://lore.kernel.org/r/20230901-ktd202x-v2-0-3cb8b0ca0...@apitzsch.eu Changes in v2: - Make binding description filename match compatible - Address comments by Lee Jones - Extend driver description in Kconfig - Add copyright + link to datasheet - Add unit to definition/variable names, where needed - Define magic numbers - Remove forward declaration of 'struct ktd202x' - Remove superfluous comments - Get rid of struct ktd202x_info - Join ktd202x_chip_init() with ktd202x_chip_enable() - Return the error on ktd202x_chip_disable() - Remove unreachable case from chip_in_use() - Rename ktd202x_brightness_set() argument from num_colors to num_channels - Forward errors received in ktd202x_brightness_set() - Remove variable for 'num_channels = 1' - Add some explanations to blink time calculation - Remove unneeded lcdev from ktd202x_blink_*_set() - Add define for max brightness and replace deprecated LED_FULL by it - Move setting led_classdev.brightness to ktd202x_brightness_*_set() - Move mutex_lock inside ktd202x_blink_set() - Add comment that 'color' property is optional (allow EINVAL) - Replace escaped double quotes by single quotes - Avoid overloading variable 'color' - Do not lock during probe - Remove usage of 'of_match_ptr' - Document interrupt and pull-up supply, like done for aw2013[1] - Fix error in num_steps calculation - Link to v1: https://lore.kernel.org/r/20230618-ktd202x-v1-0-fc182fefa...@apitzsch.eu [1] https://lore.kernel.org/linux-leds/20230815-aw2013-vio-v3-0-2505296b0...@gerhold.net/ --- André Apitzsch (2): dt-bindings: leds: Add Kinetic KTD2026/2027 LED leds: add ktd202x driver .../devicetree/bindings/leds/kinetic,ktd202x.yaml | 171 ++ drivers/leds/rgb/Kconfig | 13 + drivers/leds/rgb/Makefile | 1 + drivers/leds/rgb/leds-ktd202x.c| 619 + 4 files changed, 804 insertions(+) --- base-commit: 165adeea3617ea22dc49f8880474ebf3a98b696d change-id: 20230618-ktd202x-546b2a7d240b Best regards, -- André Apitzsch
Re: [PATCH v4 2/2] leds: add ktd202x driver
Hi Lee Jones, Am Donnerstag, dem 28.09.2023 um 15:42 +0100 schrieb Lee Jones: > On Sat, 23 Sep 2023, André Apitzsch wrote: > > > This commit adds support for Kinetic KTD2026/7 RGB/White LED > > driver. > > > > Signed-off-by: André Apitzsch > > --- > > drivers/leds/rgb/Kconfig | 13 + > > drivers/leds/rgb/Makefile | 1 + > > drivers/leds/rgb/leds-ktd202x.c | 625 > > > > 3 files changed, 639 insertions(+) > > > > diff --git a/drivers/leds/rgb/Kconfig b/drivers/leds/rgb/Kconfig > > index 183bccc06cf3..a6a21f564673 100644 > > --- a/drivers/leds/rgb/Kconfig > > +++ b/drivers/leds/rgb/Kconfig > > @@ -14,6 +14,19 @@ config LEDS_GROUP_MULTICOLOR > > To compile this driver as a module, choose M here: the > > module > > will be called leds-group-multicolor. > > > > +config LEDS_KTD202X > > + tristate "LED support for KTD202x Chips" > > + depends on I2C > > + depends on OF > > + select REGMAP_I2C > > + help > > + This option enables support for the Kinetic > > KTD2026/KTD2027 > > + RGB/White LED driver found in different BQ mobile phones. > > + It is a 3 or 4 channel LED driver programmed via an I2C > > interface. > > + > > + To compile this driver as a module, choose M here: the > > module > > + will be called leds-ktd202x. > > + > > config LEDS_PWM_MULTICOLOR > > tristate "PWM driven multi-color LED Support" > > depends on PWM > > diff --git a/drivers/leds/rgb/Makefile b/drivers/leds/rgb/Makefile > > index c11cc56384e7..243f31e4d70d 100644 > > --- a/drivers/leds/rgb/Makefile > > +++ b/drivers/leds/rgb/Makefile > > @@ -1,6 +1,7 @@ > > # SPDX-License-Identifier: GPL-2.0 > > > > obj-$(CONFIG_LEDS_GROUP_MULTICOLOR)+= leds-group-multicolor.o > > +obj-$(CONFIG_LEDS_KTD202X) += leds-ktd202x.o > > obj-$(CONFIG_LEDS_PWM_MULTICOLOR) += leds-pwm-multicolor.o > > obj-$(CONFIG_LEDS_QCOM_LPG)+= leds-qcom-lpg.o > > obj-$(CONFIG_LEDS_MT6370_RGB) += leds-mt6370-rgb.o > > diff --git a/drivers/leds/rgb/leds-ktd202x.c > > b/drivers/leds/rgb/leds-ktd202x.c > > new file mode 100644 > > index ..b328ecd34664 > > --- /dev/null > > +++ b/drivers/leds/rgb/leds-ktd202x.c > > @@ -0,0 +1,625 @@ > > +// SPDX-License-Identifier: GPL-2.0-or-later > > +/* > > + * Kinetic KTD2026/7 RGB/White LED driver with I2C interface > > + * > > + * Copyright 2023 André Apitzsch > > + * > > + * Datasheet: https://www.kinet-ic.com/uploads/KTD2026-7-04h.pdf > > + */ > > + > > [..] > > + > > +static int ktd202x_probe_dt(struct ktd202x *chip) > > +{ > > + struct device_node *np = dev_of_node(chip->dev), *child; > > + unsigned int i; > > + int count, ret; > > + > > + chip->num_leds = (int)(unsigned > > long)of_device_get_match_data(chip->dev); > > There are a bunch of recent patches converting these to: > > i2c_get_match_data() > > ... is that also applicable here? > I don't think there is a benefit in using it here. i2c_get_match_data() requires a "struct i2c_client client", so we would have to pass that to ktd202x_probe_dt(). Only to replace chip->num_leds = (int)(unsigned long)of_device_get_match_data(chip->dev); by chip->num_leds = (int)(unsigned long)i2c_get_match_data(client); Best regards, André > > + count = of_get_available_child_count(np); > > + if (!count || count > chip->num_leds) > > + return -EINVAL; > > + > > + regmap_write(chip->regmap, KTD202X_REG_RESET_CONTROL, > > + KTD202X_RSTR_RESET); > > + > > + /* Allow the device to execute the complete reset */ > > + usleep_range(200, 300); > > + > > + i = 0; > > + for_each_available_child_of_node(np, child) { > > + ret = ktd202x_add_led(chip, child, i); > > + if (ret) > > + return ret; > > + i++; > > + } > > + > > + return 0; > > +} > > + > > +static const struct regmap_config ktd202x_regmap_config = { > > + .reg_bits = 8, > > + .val_bits = 8, > > + .max_register = 0x09, > > + .cache_type = REGCACHE_FLAT, > > + .reg_defaults = ktd202x_reg_de
[PATCH v4 2/2] leds: add ktd202x driver
This commit adds support for Kinetic KTD2026/7 RGB/White LED driver. Signed-off-by: André Apitzsch --- drivers/leds/rgb/Kconfig| 13 + drivers/leds/rgb/Makefile | 1 + drivers/leds/rgb/leds-ktd202x.c | 625 3 files changed, 639 insertions(+) diff --git a/drivers/leds/rgb/Kconfig b/drivers/leds/rgb/Kconfig index 183bccc06cf3..a6a21f564673 100644 --- a/drivers/leds/rgb/Kconfig +++ b/drivers/leds/rgb/Kconfig @@ -14,6 +14,19 @@ config LEDS_GROUP_MULTICOLOR To compile this driver as a module, choose M here: the module will be called leds-group-multicolor. +config LEDS_KTD202X + tristate "LED support for KTD202x Chips" + depends on I2C + depends on OF + select REGMAP_I2C + help + This option enables support for the Kinetic KTD2026/KTD2027 + RGB/White LED driver found in different BQ mobile phones. + It is a 3 or 4 channel LED driver programmed via an I2C interface. + + To compile this driver as a module, choose M here: the module + will be called leds-ktd202x. + config LEDS_PWM_MULTICOLOR tristate "PWM driven multi-color LED Support" depends on PWM diff --git a/drivers/leds/rgb/Makefile b/drivers/leds/rgb/Makefile index c11cc56384e7..243f31e4d70d 100644 --- a/drivers/leds/rgb/Makefile +++ b/drivers/leds/rgb/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_LEDS_GROUP_MULTICOLOR)+= leds-group-multicolor.o +obj-$(CONFIG_LEDS_KTD202X) += leds-ktd202x.o obj-$(CONFIG_LEDS_PWM_MULTICOLOR) += leds-pwm-multicolor.o obj-$(CONFIG_LEDS_QCOM_LPG)+= leds-qcom-lpg.o obj-$(CONFIG_LEDS_MT6370_RGB) += leds-mt6370-rgb.o diff --git a/drivers/leds/rgb/leds-ktd202x.c b/drivers/leds/rgb/leds-ktd202x.c new file mode 100644 index ..b328ecd34664 --- /dev/null +++ b/drivers/leds/rgb/leds-ktd202x.c @@ -0,0 +1,625 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Kinetic KTD2026/7 RGB/White LED driver with I2C interface + * + * Copyright 2023 André Apitzsch + * + * Datasheet: https://www.kinet-ic.com/uploads/KTD2026-7-04h.pdf + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define KTD2026_NUM_LEDS 3 +#define KTD2027_NUM_LEDS 4 +#define KTD202X_MAX_LEDS 4 + +/* Register bank */ +#define KTD202X_REG_RESET_CONTROL 0x00 +#define KTD202X_REG_FLASH_PERIOD 0x01 +#define KTD202X_REG_PWM1_TIMER 0x02 +#define KTD202X_REG_PWM2_TIMER 0x03 +#define KTD202X_REG_CHANNEL_CTRL 0x04 +#define KTD202X_REG_TRISE_FALL 0x05 +#define KTD202X_REG_LED_IOUT(x)(0x06 + (x)) + +/* Register 0 */ +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT1 0x00 +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT2 0x01 +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT3 0x02 +#define KTD202X_TIMER_SLOT_CONTROL_TSLOT4 0x03 +#define KTD202X_RSTR_RESET 0x07 + +#define KTD202X_ENABLE_CTRL_WAKE 0x00 /* SCL High & SDA High */ +#define KTD202X_ENABLE_CTRL_SLEEP 0x08 /* SCL High & SDA Toggling */ + +#define KTD202X_TRISE_FALL_SCALE_NORMAL0x00 +#define KTD202X_TRISE_FALL_SCALE_SLOW_X2 0x20 +#define KTD202X_TRISE_FALL_SCALE_SLOW_X4 0x40 +#define KTD202X_TRISE_FALL_SCALE_FAST_X8 0x60 + +/* Register 1 */ +#define KTD202X_FLASH_PERIOD_256_MS_LOG_RAMP 0x00 + +/* Register 2-3 */ +#define KTD202X_FLASH_ON_TIME_0_4_PERCENT 0x01 + +/* Register 4 */ +#define KTD202X_CHANNEL_CTRL_MASK(x) (BIT(2 * (x)) | BIT(2 * (x) + 1)) +#define KTD202X_CHANNEL_CTRL_OFF 0x00 +#define KTD202X_CHANNEL_CTRL_ON(x) BIT(2 * (x)) +#define KTD202X_CHANNEL_CTRL_PWM1(x) BIT(2 * (x) + 1) +#define KTD202X_CHANNEL_CTRL_PWM2(x) (BIT(2 * (x)) | BIT(2 * (x) + 1)) + +/* Register 5 */ +#define KTD202X_RAMP_TIMES_2_MS0x00 + +/* Register 6-9 */ +#define KTD202X_LED_CURRENT_10_mA 0x4f + +#define KTD202X_FLASH_PERIOD_MIN_MS 256 +#define KTD202X_FLASH_PERIOD_STEP_MS 128 +#define KTD202X_FLASH_PERIOD_MAX_STEPS 126 +#define KTD202X_FLASH_ON_MAX 256 + +#define KTD202X_MAX_BRIGHTNESS 192 + +static const struct reg_default ktd202x_reg_defaults[] = { + { KTD202X_REG_RESET_CONTROL, KTD202X_TIMER_SLOT_CONTROL_TSLOT1 | + KTD202X_ENABLE_CTRL_WAKE | KTD202X_TRISE_FALL_SCALE_NORMAL }, + { KTD202X_REG_FLASH_PERIOD, KTD202X_FLASH_PERIOD_256_MS_LOG_RAMP }, + { KTD202X_REG_PWM1_TIMER, KTD202X_FLASH_ON_TIME_0_4_PERCENT }, + { KTD202X_REG_PWM2_TIMER, KTD202X_FLASH_ON_TIME_0_4_PERCENT }, + { KTD202X_REG_CHANNEL_CTRL, KTD202X_CHANNEL_CTRL_OFF }, + { KTD202X_REG_TRISE_FALL, KTD202X_RAMP_TIMES_2_MS }, + { KTD202X_REG_LED_IOUT(0), KTD202X_LED_CURRENT_10_mA }, + { KTD202X_REG_LED_IOUT(1), KTD202X_LED_CURRENT_10_mA }, + { KTD202X_REG_LED_IOUT(2), KTD202X_LED_CURRENT_10_mA }, +
[PATCH v4 1/2] dt-bindings: leds: Add Kinetic KTD2026/2027 LED
Document Kinetic KTD2026/2027 LED driver devicetree bindings. Reviewed-by: Krzysztof Kozlowski Signed-off-by: André Apitzsch --- .../devicetree/bindings/leds/kinetic,ktd202x.yaml | 171 + 1 file changed, 171 insertions(+) diff --git a/Documentation/devicetree/bindings/leds/kinetic,ktd202x.yaml b/Documentation/devicetree/bindings/leds/kinetic,ktd202x.yaml new file mode 100644 index ..832c030a5acf --- /dev/null +++ b/Documentation/devicetree/bindings/leds/kinetic,ktd202x.yaml @@ -0,0 +1,171 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/kinetic,ktd202x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Kinetic KTD2026/7 RGB/White LED Driver + +maintainers: + - André Apitzsch + +description: | + The KTD2026/7 is a RGB/White LED driver with I2C interface. + + The data sheet can be found at: +https://www.kinet-ic.com/uploads/KTD2026-7-04h.pdf + +properties: + compatible: +enum: + - kinetic,ktd2026 + - kinetic,ktd2027 + + reg: +maxItems: 1 + + vin-supply: +description: Regulator providing power to the "VIN" pin. + + vio-supply: +description: Regulator providing power for pull-up of the I/O lines. + Note that this regulator does not directly connect to KTD2026, but is + needed for the correct operation of the status ("ST") and I2C lines. + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + + multi-led: +type: object +$ref: leds-class-multicolor.yaml# +unevaluatedProperties: false + +properties: + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^led@[0-3]$": +type: object +$ref: common.yaml# +unevaluatedProperties: false + +properties: + reg: +description: Index of the LED. +minimum: 0 +maximum: 3 + +required: + - reg + - color + +required: + - "#address-cells" + - "#size-cells" + +patternProperties: + "^led@[0-3]$": +type: object +$ref: common.yaml# +unevaluatedProperties: false + +properties: + reg: +description: Index of the LED. +minimum: 0 +maximum: 3 + +required: + - reg + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | +#include + +i2c { +#address-cells = <1>; +#size-cells = <0>; + +led-controller@30 { +compatible = "kinetic,ktd2026"; +reg = <0x30>; +#address-cells = <1>; +#size-cells = <0>; + +vin-supply = <_l17>; +vio-supply = <_l6>; + +led@0 { +reg = <0>; +function = LED_FUNCTION_STATUS; +color = ; +}; + +led@1 { +reg = <1>; +function = LED_FUNCTION_STATUS; +color = ; +}; + +led@2 { +reg = <2>; +function = LED_FUNCTION_STATUS; +color = ; +}; +}; +}; + - | +#include + +i2c { +#address-cells = <1>; +#size-cells = <0>; + +led-controller@30 { +compatible = "kinetic,ktd2026"; +reg = <0x30>; +#address-cells = <1>; +#size-cells = <0>; + +vin-supply = <_l17>; +vio-supply = <_l6>; + +multi-led { +color = ; +function = LED_FUNCTION_STATUS; + +#address-cells = <1>; +#size-cells = <0>; + +led@0 { +reg = <0>; +color = ; +}; + +led@1 { +reg = <1>; +color = ; +}; + +led@2 { +reg = <2>; +color = ; +}; +}; +}; +}; -- 2.42.0
[PATCH v4 0/2] leds: Add a driver for KTD202x
Add the binding description and the corresponding driver for the Kinetic KTD2026 and KTD2027. Signed-off-by: André Apitzsch --- Changes in v4: - Annotate struct ktd202x with __counted_by - Link to v3: https://lore.kernel.org/r/20230906-ktd202x-v3-0-7fcb91c65...@apitzsch.eu Changes in v3: - Add r-b to bindings patch - Replace .probe_new by .probe - Link to v2: https://lore.kernel.org/r/20230901-ktd202x-v2-0-3cb8b0ca0...@apitzsch.eu Changes in v2: - Make binding description filename match compatible - Address comments by Lee Jones - Extend driver description in Kconfig - Add copyright + link to datasheet - Add unit to definition/variable names, where needed - Define magic numbers - Remove forward declaration of 'struct ktd202x' - Remove superfluous comments - Get rid of struct ktd202x_info - Join ktd202x_chip_init() with ktd202x_chip_enable() - Return the error on ktd202x_chip_disable() - Remove unreachable case from chip_in_use() - Rename ktd202x_brightness_set() argument from num_colors to num_channels - Forward errors received in ktd202x_brightness_set() - Remove variable for 'num_channels = 1' - Add some explanations to blink time calculation - Remove unneeded lcdev from ktd202x_blink_*_set() - Add define for max brightness and replace deprecated LED_FULL by it - Move setting led_classdev.brightness to ktd202x_brightness_*_set() - Move mutex_lock inside ktd202x_blink_set() - Add comment that 'color' property is optional (allow EINVAL) - Replace escaped double quotes by single quotes - Avoid overloading variable 'color' - Do not lock during probe - Remove usage of 'of_match_ptr' - Document interrupt and pull-up supply, like done for aw2013[1] - Fix error in num_steps calculation - Link to v1: https://lore.kernel.org/r/20230618-ktd202x-v1-0-fc182fefa...@apitzsch.eu [1] https://lore.kernel.org/linux-leds/20230815-aw2013-vio-v3-0-2505296b0...@gerhold.net/ --- André Apitzsch (2): dt-bindings: leds: Add Kinetic KTD2026/2027 LED leds: add ktd202x driver .../devicetree/bindings/leds/kinetic,ktd202x.yaml | 171 ++ drivers/leds/rgb/Kconfig | 13 + drivers/leds/rgb/Makefile | 1 + drivers/leds/rgb/leds-ktd202x.c| 625 + 4 files changed, 810 insertions(+) --- base-commit: 9641a13970d832d821ad304e187b80dbe70bae30 change-id: 20230618-ktd202x-546b2a7d240b Best regards, -- André Apitzsch