Skip to content

Commit f3d8f29

Browse files
committed
Merge tag 'backlight-next-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight
Pull backlight updates from Lee Jones: "New Drivers: - Add support for Kinetic KTD2801 Backlight Fix-ups: - Fix include lists; alphabetise, remove unused, explicitly add used - Device Tree binding adaptions/conversions/creation - Use dev_err_probe() to clean-up error paths - Use/convert to new/better APIs/helpers/MACROs instead of hand-rolling implementations Bug Fixes: - Fix changes of NULL pointer dereference - Remedy a bunch of logic errors - Initialise (zero) Backlight properties data structures" * tag 'backlight-next-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight: (32 commits) backlight: pandora_bl: Drop unneeded ENOMEM error message backlight: lm3630a_bl: Simplify probe return on gpio request error backlight: lm3630a_bl: Handle deferred probe backlight: as3711_bl: Handle deferred probe backlight: bd6107: Handle deferred probe backlight: l4f00242t03: Simplify with dev_err_probe() backlight: gpio: Simplify with dev_err_probe() backlight: lp8788: Fully initialize backlight_properties during probe backlight: lm3639: Fully initialize backlight_properties during probe backlight: da9052: Fully initialize backlight_properties during probe backlight: lm3630a: Use backlight_get_brightness helper in update_status backlight: lm3630a: Don't set bl->props.brightness in get_brightness backlight: lm3630a: Initialize backlight_properties on init backlight: mp3309c: Fully initialize backlight_properties during probe backlight: mp3309c: Utilise temporary variable for struct device backlight: mp3309c: Use dev_err_probe() instead of dev_err() backlight: mp3309c: Make use of device properties dt-bindings: backlight: qcom-wled: Fix bouncing email addresses backlight: hx8357: Utilise temporary variable for struct device backlight: hx8357: Make use of dev_err_probe() ...
2 parents 8403ce7 + b49c1ca commit f3d8f29

24 files changed

+461
-248
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/leds/backlight/kinetic,ktd2801.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Kinetic Technologies KTD2801 one-wire backlight
8+
9+
maintainers:
10+
- Duje Mihanović <[email protected]>
11+
12+
description: |
13+
The Kinetic Technologies KTD2801 is a LED backlight driver controlled
14+
by a single GPIO line. The driver can be controlled with a PWM signal
15+
or by pulsing the GPIO line to set the backlight level. This is called
16+
"ExpressWire".
17+
18+
allOf:
19+
- $ref: common.yaml#
20+
21+
properties:
22+
compatible:
23+
const: kinetic,ktd2801
24+
25+
ctrl-gpios:
26+
maxItems: 1
27+
28+
default-brightness: true
29+
max-brightness: true
30+
31+
required:
32+
- compatible
33+
- ctrl-gpios
34+
35+
additionalProperties: false
36+
37+
examples:
38+
- |
39+
#include <dt-bindings/gpio/gpio.h>
40+
41+
backlight {
42+
compatible = "kinetic,ktd2801";
43+
ctrl-gpios = <&gpio 97 GPIO_ACTIVE_HIGH>;
44+
max-brightness = <210>;
45+
default-brightness = <100>;
46+
};

Documentation/devicetree/bindings/leds/backlight/qcom-wled.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ $schema: http://devicetree.org/meta-schemas/core.yaml#
77
title: Qualcomm Technologies, Inc. WLED driver
88

99
maintainers:
10-
- Bjorn Andersson <bjorn.andersson@linaro.org>
11-
- Kiran Gunda <[email protected]>
10+
- Bjorn Andersson <andersson@kernel.org>
11+
- Kiran Gunda <[email protected]>
1212

1313
description: |
1414
WLED (White Light Emitting Diode) driver is used for controlling display

MAINTAINERS

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8039,6 +8039,13 @@ S: Maintained
80398039
T: git git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat.git
80408040
F: fs/exfat/
80418041

8042+
EXPRESSWIRE PROTOCOL LIBRARY
8043+
M: Duje Mihanović <[email protected]>
8044+
8045+
S: Maintained
8046+
F: drivers/leds/leds-expresswire.c
8047+
F: include/linux/leds-expresswire.h
8048+
80428049
EXT2 FILE SYSTEM
80438050
M: Jan Kara <[email protected]>
80448051
@@ -12103,6 +12110,12 @@ S: Maintained
1210312110
F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktd253.yaml
1210412111
F: drivers/video/backlight/ktd253-backlight.c
1210512112

12113+
KTD2801 BACKLIGHT DRIVER
12114+
M: Duje Mihanović <[email protected]>
12115+
S: Maintained
12116+
F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktd2801.yaml
12117+
F: drivers/video/backlight/ktd2801-backlight.c
12118+
1210612119
KTEST
1210712120
M: Steven Rostedt <[email protected]>
1210812121
M: John Hawley <[email protected]>

drivers/leds/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ config LEDS_EL15203000
186186
To compile this driver as a module, choose M here: the module
187187
will be called leds-el15203000.
188188

189+
config LEDS_EXPRESSWIRE
190+
bool
191+
depends on GPIOLIB
192+
189193
config LEDS_TURRIS_OMNIA
190194
tristate "LED support for CZ.NIC's Turris Omnia"
191195
depends on LEDS_CLASS_MULTICOLOR

drivers/leds/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o
9191
obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o
9292
obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
9393

94+
# Kinetic ExpressWire Protocol
95+
obj-$(CONFIG_LEDS_EXPRESSWIRE) += leds-expresswire.o
96+
9497
# LED SPI Drivers
9598
obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.o
9699
obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o

drivers/leds/flash/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ config LEDS_AS3645A
2323
config LEDS_KTD2692
2424
tristate "LED support for Kinetic KTD2692 flash LED controller"
2525
depends on OF
26-
depends on GPIOLIB || COMPILE_TEST
26+
depends on GPIOLIB
27+
select LEDS_EXPRESSWIRE
2728
help
2829
This option enables support for Kinetic KTD2692 LED flash connected
2930
through ExpressWire interface.

drivers/leds/flash/leds-ktd2692.c

Lines changed: 27 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* Ingi Kim <[email protected]>
77
*/
88

9-
#include <linux/delay.h>
109
#include <linux/err.h>
1110
#include <linux/gpio/consumer.h>
11+
#include <linux/leds-expresswire.h>
1212
#include <linux/led-class-flash.h>
1313
#include <linux/module.h>
1414
#include <linux/mutex.h>
@@ -37,22 +37,9 @@
3737
#define KTD2692_REG_FLASH_CURRENT_BASE 0x80
3838
#define KTD2692_REG_MODE_BASE 0xA0
3939

40-
/* Set bit coding time for expresswire interface */
41-
#define KTD2692_TIME_RESET_US 700
42-
#define KTD2692_TIME_DATA_START_TIME_US 10
43-
#define KTD2692_TIME_HIGH_END_OF_DATA_US 350
44-
#define KTD2692_TIME_LOW_END_OF_DATA_US 10
45-
#define KTD2692_TIME_SHORT_BITSET_US 4
46-
#define KTD2692_TIME_LONG_BITSET_US 12
47-
4840
/* KTD2692 default length of name */
4941
#define KTD2692_NAME_LENGTH 20
5042

51-
enum ktd2692_bitset {
52-
KTD2692_LOW = 0,
53-
KTD2692_HIGH,
54-
};
55-
5643
/* Movie / Flash Mode Control */
5744
enum ktd2692_led_mode {
5845
KTD2692_MODE_DISABLE = 0, /* default */
@@ -71,7 +58,19 @@ struct ktd2692_led_config_data {
7158
enum led_brightness max_brightness;
7259
};
7360

61+
const struct expresswire_timing ktd2692_timing = {
62+
.poweroff_us = 700,
63+
.data_start_us = 10,
64+
.end_of_data_low_us = 10,
65+
.end_of_data_high_us = 350,
66+
.short_bitset_us = 4,
67+
.long_bitset_us = 12
68+
};
69+
7470
struct ktd2692_context {
71+
/* Common ExpressWire properties (ctrl GPIO and timing) */
72+
struct expresswire_common_props props;
73+
7574
/* Related LED Flash class device */
7675
struct led_classdev_flash fled_cdev;
7776

@@ -80,7 +79,6 @@ struct ktd2692_context {
8079
struct regulator *regulator;
8180

8281
struct gpio_desc *aux_gpio;
83-
struct gpio_desc *ctrl_gpio;
8482

8583
enum ktd2692_led_mode mode;
8684
enum led_brightness torch_brightness;
@@ -92,67 +90,6 @@ static struct ktd2692_context *fled_cdev_to_led(
9290
return container_of(fled_cdev, struct ktd2692_context, fled_cdev);
9391
}
9492

95-
static void ktd2692_expresswire_start(struct ktd2692_context *led)
96-
{
97-
gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH);
98-
udelay(KTD2692_TIME_DATA_START_TIME_US);
99-
}
100-
101-
static void ktd2692_expresswire_reset(struct ktd2692_context *led)
102-
{
103-
gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW);
104-
udelay(KTD2692_TIME_RESET_US);
105-
}
106-
107-
static void ktd2692_expresswire_end(struct ktd2692_context *led)
108-
{
109-
gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW);
110-
udelay(KTD2692_TIME_LOW_END_OF_DATA_US);
111-
gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH);
112-
udelay(KTD2692_TIME_HIGH_END_OF_DATA_US);
113-
}
114-
115-
static void ktd2692_expresswire_set_bit(struct ktd2692_context *led, bool bit)
116-
{
117-
/*
118-
* The Low Bit(0) and High Bit(1) is based on a time detection
119-
* algorithm between time low and time high
120-
* Time_(L_LB) : Low time of the Low Bit(0)
121-
* Time_(H_LB) : High time of the LOW Bit(0)
122-
* Time_(L_HB) : Low time of the High Bit(1)
123-
* Time_(H_HB) : High time of the High Bit(1)
124-
*
125-
* It can be simplified to:
126-
* Low Bit(0) : 2 * Time_(H_LB) < Time_(L_LB)
127-
* High Bit(1) : 2 * Time_(L_HB) < Time_(H_HB)
128-
* HIGH ___ ____ _.. _________ ___
129-
* |_________| |_.. |____| |__|
130-
* LOW <L_LB> <H_LB> <L_HB> <H_HB>
131-
* [ Low Bit (0) ] [ High Bit(1) ]
132-
*/
133-
if (bit) {
134-
gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW);
135-
udelay(KTD2692_TIME_SHORT_BITSET_US);
136-
gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH);
137-
udelay(KTD2692_TIME_LONG_BITSET_US);
138-
} else {
139-
gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW);
140-
udelay(KTD2692_TIME_LONG_BITSET_US);
141-
gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH);
142-
udelay(KTD2692_TIME_SHORT_BITSET_US);
143-
}
144-
}
145-
146-
static void ktd2692_expresswire_write(struct ktd2692_context *led, u8 value)
147-
{
148-
int i;
149-
150-
ktd2692_expresswire_start(led);
151-
for (i = 7; i >= 0; i--)
152-
ktd2692_expresswire_set_bit(led, value & BIT(i));
153-
ktd2692_expresswire_end(led);
154-
}
155-
15693
static int ktd2692_led_brightness_set(struct led_classdev *led_cdev,
15794
enum led_brightness brightness)
15895
{
@@ -163,14 +100,14 @@ static int ktd2692_led_brightness_set(struct led_classdev *led_cdev,
163100

164101
if (brightness == LED_OFF) {
165102
led->mode = KTD2692_MODE_DISABLE;
166-
gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
103+
gpiod_direction_output(led->aux_gpio, 0);
167104
} else {
168-
ktd2692_expresswire_write(led, brightness |
105+
expresswire_write_u8(&led->props, brightness |
169106
KTD2692_REG_MOVIE_CURRENT_BASE);
170107
led->mode = KTD2692_MODE_MOVIE;
171108
}
172109

173-
ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE);
110+
expresswire_write_u8(&led->props, led->mode | KTD2692_REG_MODE_BASE);
174111
mutex_unlock(&led->lock);
175112

176113
return 0;
@@ -187,17 +124,17 @@ static int ktd2692_led_flash_strobe_set(struct led_classdev_flash *fled_cdev,
187124

188125
if (state) {
189126
flash_tm_reg = GET_TIMEOUT_OFFSET(timeout->val, timeout->step);
190-
ktd2692_expresswire_write(led, flash_tm_reg
127+
expresswire_write_u8(&led->props, flash_tm_reg
191128
| KTD2692_REG_FLASH_TIMEOUT_BASE);
192129

193130
led->mode = KTD2692_MODE_FLASH;
194-
gpiod_direction_output(led->aux_gpio, KTD2692_HIGH);
131+
gpiod_direction_output(led->aux_gpio, 1);
195132
} else {
196133
led->mode = KTD2692_MODE_DISABLE;
197-
gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
134+
gpiod_direction_output(led->aux_gpio, 0);
198135
}
199136

200-
ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE);
137+
expresswire_write_u8(&led->props, led->mode | KTD2692_REG_MODE_BASE);
201138

202139
fled_cdev->led_cdev.brightness = LED_OFF;
203140
led->mode = KTD2692_MODE_DISABLE;
@@ -247,12 +184,12 @@ static void ktd2692_init_flash_timeout(struct led_classdev_flash *fled_cdev,
247184
static void ktd2692_setup(struct ktd2692_context *led)
248185
{
249186
led->mode = KTD2692_MODE_DISABLE;
250-
ktd2692_expresswire_reset(led);
251-
gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
187+
expresswire_power_off(&led->props);
188+
gpiod_direction_output(led->aux_gpio, 0);
252189

253-
ktd2692_expresswire_write(led, (KTD2692_MM_MIN_CURR_THRESHOLD_SCALE - 1)
190+
expresswire_write_u8(&led->props, (KTD2692_MM_MIN_CURR_THRESHOLD_SCALE - 1)
254191
| KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE);
255-
ktd2692_expresswire_write(led, KTD2692_FLASH_MODE_CURR_PERCENT(45)
192+
expresswire_write_u8(&led->props, KTD2692_FLASH_MODE_CURR_PERCENT(45)
256193
| KTD2692_REG_FLASH_CURRENT_BASE);
257194
}
258195

@@ -277,8 +214,8 @@ static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
277214
if (!np)
278215
return -ENXIO;
279216

280-
led->ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_ASIS);
281-
ret = PTR_ERR_OR_ZERO(led->ctrl_gpio);
217+
led->props.ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_ASIS);
218+
ret = PTR_ERR_OR_ZERO(led->props.ctrl_gpio);
282219
if (ret)
283220
return dev_err_probe(dev, ret, "cannot get ctrl-gpios\n");
284221

@@ -412,6 +349,7 @@ static struct platform_driver ktd2692_driver = {
412349

413350
module_platform_driver(ktd2692_driver);
414351

352+
MODULE_IMPORT_NS(EXPRESSWIRE);
415353
MODULE_AUTHOR("Ingi Kim <[email protected]>");
416354
MODULE_DESCRIPTION("Kinetic KTD2692 LED driver");
417355
MODULE_LICENSE("GPL v2");

drivers/leds/leds-expresswire.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Shared library for Kinetic's ExpressWire protocol.
4+
* This protocol works by pulsing the ExpressWire IC's control GPIO.
5+
* ktd2692 and ktd2801 are known to use this protocol.
6+
*/
7+
8+
#include <linux/bits.h>
9+
#include <linux/delay.h>
10+
#include <linux/export.h>
11+
#include <linux/gpio/consumer.h>
12+
#include <linux/types.h>
13+
14+
#include <linux/leds-expresswire.h>
15+
16+
void expresswire_power_off(struct expresswire_common_props *props)
17+
{
18+
gpiod_set_value_cansleep(props->ctrl_gpio, 0);
19+
usleep_range(props->timing.poweroff_us, props->timing.poweroff_us * 2);
20+
}
21+
EXPORT_SYMBOL_NS_GPL(expresswire_power_off, EXPRESSWIRE);
22+
23+
void expresswire_enable(struct expresswire_common_props *props)
24+
{
25+
gpiod_set_value(props->ctrl_gpio, 1);
26+
udelay(props->timing.detect_delay_us);
27+
gpiod_set_value(props->ctrl_gpio, 0);
28+
udelay(props->timing.detect_us);
29+
gpiod_set_value(props->ctrl_gpio, 1);
30+
}
31+
EXPORT_SYMBOL_NS_GPL(expresswire_enable, EXPRESSWIRE);
32+
33+
void expresswire_start(struct expresswire_common_props *props)
34+
{
35+
gpiod_set_value(props->ctrl_gpio, 1);
36+
udelay(props->timing.data_start_us);
37+
}
38+
EXPORT_SYMBOL_NS_GPL(expresswire_start, EXPRESSWIRE);
39+
40+
void expresswire_end(struct expresswire_common_props *props)
41+
{
42+
gpiod_set_value(props->ctrl_gpio, 0);
43+
udelay(props->timing.end_of_data_low_us);
44+
gpiod_set_value(props->ctrl_gpio, 1);
45+
udelay(props->timing.end_of_data_high_us);
46+
}
47+
EXPORT_SYMBOL_NS_GPL(expresswire_end, EXPRESSWIRE);
48+
49+
void expresswire_set_bit(struct expresswire_common_props *props, bool bit)
50+
{
51+
if (bit) {
52+
gpiod_set_value(props->ctrl_gpio, 0);
53+
udelay(props->timing.short_bitset_us);
54+
gpiod_set_value(props->ctrl_gpio, 1);
55+
udelay(props->timing.long_bitset_us);
56+
} else {
57+
gpiod_set_value(props->ctrl_gpio, 0);
58+
udelay(props->timing.long_bitset_us);
59+
gpiod_set_value(props->ctrl_gpio, 1);
60+
udelay(props->timing.short_bitset_us);
61+
}
62+
}
63+
EXPORT_SYMBOL_NS_GPL(expresswire_set_bit, EXPRESSWIRE);
64+
65+
void expresswire_write_u8(struct expresswire_common_props *props, u8 val)
66+
{
67+
expresswire_start(props);
68+
for (int i = 7; i >= 0; i--)
69+
expresswire_set_bit(props, val & BIT(i));
70+
expresswire_end(props);
71+
}
72+
EXPORT_SYMBOL_NS_GPL(expresswire_write_u8, EXPRESSWIRE);

0 commit comments

Comments
 (0)