History

Merge tag 'backlight-next-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight

Pull backlight updates from Lee Jones: "Core Frameworks - Obtain scale type through sysfs New Functionality: - Provide Device Tree functionality in rave-sp-backlight - Calculate if scale type is (non-)linear in pwm_bl Fix-ups: - Simplify code in lm3630a_bl - Trivial rename/whitespace/typo fixes in lms283gf05 - Remove superfluous NULL check in tosa_lcd - Fix power state initialisation in gpio_backlight - List supported file in MAINTAINERS Bug Fixes: - Kconfig - default to not building unless requested in {LED,BACKLIGHT}_CLASS_DEVICE" * tag 'backlight-next-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight: backlight: pwm_bl: Set scale type for brightness curves specified in the DT backlight: pwm_bl: Set scale type for CIE 1931 curves backlight: Expose brightness curve type through sysfs MAINTAINERS: Add entry for stable backlight sysfs ABI documentation backlight: gpio-backlight: Correct initial power state handling video: backlight: tosa_lcd: drop check because i2c_unregister_device() is NULL safe video: backlight: Drop default m for {LCD,BACKLIGHT_CLASS_DEVICE} backlight: lms283gf05: Fix a typo in the description passed to 'devm_gpio_request_one()' backlight: lm3630a: Switch to use fwnode_property_count_uXX() backlight: rave-sp: Leave initial state and register with correct device

Linus Torvalds committed 7 years ago

Commit d0b3cfe2 parents 299d14d c0b64fa11 files · +120 −14Browse files

Unified · Split

11 files
  1. Documentation/ABI/testing/sysfs-class-backlight +26 −0
  2. MAINTAINERS +2 −0
  3. drivers/video/backlight/Kconfig +0 −2
  4. drivers/video/backlight/backlight.c +19 −0
  5. drivers/video/backlight/gpio_backlight.c +20 −4
  6. drivers/video/backlight/lm3630a_bl.c +1 −2
  7. drivers/video/backlight/lms283gf05.c +1 −1
  8. drivers/video/backlight/pwm_bl.c +34 −1
  9. drivers/video/backlight/rave-sp-backlight.c +8 −2
  10. drivers/video/backlight/tosa_lcd.c +1 −2
  11. include/linux/backlight.h +8 −0
Documentation/ABI/testing/sysfs-class-backlight+26−0
@@ -0,0 +1,26 @@
1+What: /sys/class/backlight/<backlight>/scale
2+Date: July 2019
3+KernelVersion: 5.4
4+Contact: Daniel Thompson <daniel.thompson@linaro.org>
5+Description:
6+ Description of the scale of the brightness curve.
7+
8+ The human eye senses brightness approximately logarithmically,
9+ hence linear changes in brightness are perceived as being
10+ non-linear. To achieve a linear perception of brightness changes
11+ controls like sliders need to apply a logarithmic mapping for
12+ backlights with a linear brightness curve.
13+
14+ Possible values of the attribute are:
15+
16+ unknown
17+ The scale of the brightness curve is unknown.
18+
19+ linear
20+ The brightness changes linearly with each step. Brightness
21+ controls should apply a logarithmic mapping for a linear
22+ perception.
23+
24+ non-linear
25+ The brightness changes non-linearly with each step. Brightness
26+ controls should use a linear mapping for a linear perception.
MAINTAINERS+2−0
@@ -2921,6 +2921,8 @@ F: drivers/video/backlight/ · 2920 unmodified lines
29212921 F: include/linux/backlight.h
29222922 F: include/linux/pwm_backlight.h
29232923 F: Documentation/devicetree/bindings/leds/backlight
2924+F: Documentation/ABI/stable/sysfs-class-backlight
2925+F: Documentation/ABI/testing/sysfs-class-backlight
29242926
29252927 BATMAN ADVANCED
29262928 M: Marek Lindner <mareklindner@neomailbox.ch>
drivers/video/backlight/Kconfig+0−2
@@ -10,7 +10,6 @@ menu "Backlight & LCD device support" · 9 unmodified lines
1010 #
1111 config LCD_CLASS_DEVICE
1212 tristate "Lowlevel LCD controls"
13− default m
1413 help
1514 This framework adds support for low-level control of LCD.
1615 Some framebuffer devices connect to platform-specific LCD modules
@@ -143,7 +142,6 @@ endif # LCD_CLASS_DEVICE · 126 unmodified lines
143142 #
144143 config BACKLIGHT_CLASS_DEVICE
145144 tristate "Lowlevel Backlight controls"
146− default m
147145 help
148146 This framework adds support for low-level control of the LCD
149147 backlight. This includes support for brightness and power.
drivers/video/backlight/backlight.c+19−0
@@ -32,6 +32,12 @@ static const char *const backlight_types[] = { · 31 unmodified lines
3232 [BACKLIGHT_FIRMWARE] = "firmware",
3333 };
3434
35+static const char *const backlight_scale_types[] = {
36+ [BACKLIGHT_SCALE_UNKNOWN] = "unknown",
37+ [BACKLIGHT_SCALE_LINEAR] = "linear",
38+ [BACKLIGHT_SCALE_NON_LINEAR] = "non-linear",
39+};
40+
3541 #if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \
3642 defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE))
3743 /* This callback gets called when something important happens inside a
@@ -246,6 +252,18 @@ static ssize_t actual_brightness_show(struct device *dev, · 208 unmodified lines
246252 }
247253 static DEVICE_ATTR_RO(actual_brightness);
248254
255+static ssize_t scale_show(struct device *dev,
256+ struct device_attribute *attr, char *buf)
257+{
258+ struct backlight_device *bd = to_backlight_device(dev);
259+
260+ if (WARN_ON(bd->props.scale > BACKLIGHT_SCALE_NON_LINEAR))
261+ return sprintf(buf, "unknown\n");
262+
263+ return sprintf(buf, "%s\n", backlight_scale_types[bd->props.scale]);
264+}
265+static DEVICE_ATTR_RO(scale);
266+
249267 static struct class *backlight_class;
250268
251269 #ifdef CONFIG_PM_SLEEP
@@ -292,6 +310,7 @@ static struct attribute *bl_device_attrs[] = { · 40 unmodified lines
292310 &dev_attr_brightness.attr,
293311 &dev_attr_actual_brightness.attr,
294312 &dev_attr_max_brightness.attr,
313+ &dev_attr_scale.attr,
295314 &dev_attr_type.attr,
296315 NULL,
297316 };
drivers/video/backlight/gpio_backlight.c+20−4
@@ -59,13 +59,11 @@ static int gpio_backlight_probe_dt(struct platform_device *pdev, · 58 unmodified lines
5959 struct gpio_backlight *gbl)
6060 {
6161 struct device *dev = &pdev->dev;
62− enum gpiod_flags flags;
6362 int ret;
6463
6564 gbl->def_value = device_property_read_bool(dev, "default-on");
66− flags = gbl->def_value ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
6765
68− gbl->gpiod = devm_gpiod_get(dev, NULL, flags);
66+ gbl->gpiod = devm_gpiod_get(dev, NULL, GPIOD_ASIS);
6967 if (IS_ERR(gbl->gpiod)) {
7068 ret = PTR_ERR(gbl->gpiod);
7169
@@ -79,6 +77,22 @@ static int gpio_backlight_probe_dt(struct platform_device *pdev, · 7 unmodified lines
7977 return 0;
8078 }
8179
80+static int gpio_backlight_initial_power_state(struct gpio_backlight *gbl)
81+{
82+ struct device_node *node = gbl->dev->of_node;
83+
84+ /* Not booted with device tree or no phandle link to the node */
85+ if (!node || !node->phandle)
86+ return gbl->def_value ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
87+
88+ /* if the enable GPIO is disabled, do not enable the backlight */
89+ if (gpiod_get_value_cansleep(gbl->gpiod) == 0)
90+ return FB_BLANK_POWERDOWN;
91+
92+ return FB_BLANK_UNBLANK;
93+}
94+
95+
8296 static int gpio_backlight_probe(struct platform_device *pdev)
8397 {
8498 struct gpio_backlight_platform_data *pdata =
@@ -136,7 +150,9 @@ static int gpio_backlight_probe(struct platform_device *pdev) · 51 unmodified lines
136150 return PTR_ERR(bl);
137151 }
138152
139− bl->props.brightness = gbl->def_value;
153+ bl->props.power = gpio_backlight_initial_power_state(gbl);
154+ bl->props.brightness = 1;
155+
140156 backlight_update_status(bl);
141157
142158 platform_set_drvdata(pdev, bl);
drivers/video/backlight/lm3630a_bl.c+1−2
@@ -377,8 +377,7 @@ static int lm3630a_parse_led_sources(struct fwnode_handle *node, · 376 unmodified lines
377377 u32 sources[LM3630A_NUM_SINKS];
378378 int ret, num_sources, i;
379379
380− num_sources = fwnode_property_read_u32_array(node, "led-sources", NULL,
381− 0);
380+ num_sources = fwnode_property_count_u32(node, "led-sources");
382381 if (num_sources < 0)
383382 return default_led_sources;
384383 else if (num_sources > ARRAY_SIZE(sources))
drivers/video/backlight/lms283gf05.c+1−1
@@ -158,7 +158,7 @@ static int lms283gf05_probe(struct spi_device *spi) · 157 unmodified lines
158158 ret = devm_gpio_request_one(&spi->dev, pdata->reset_gpio,
159159 GPIOF_DIR_OUT | (!pdata->reset_inverted ?
160160 GPIOF_INIT_HIGH : GPIOF_INIT_LOW),
161− "LMS285GF05 RESET");
161+ "LMS283GF05 RESET");
162162 if (ret)
163163 return ret;
164164 }
drivers/video/backlight/pwm_bl.c+34−1
@@ -387,6 +387,31 @@ int pwm_backlight_brightness_default(struct device *dev, · 386 unmodified lines
387387 }
388388 #endif
389389
390+static bool pwm_backlight_is_linear(struct platform_pwm_backlight_data *data)
391+{
392+ unsigned int nlevels = data->max_brightness + 1;
393+ unsigned int min_val = data->levels[0];
394+ unsigned int max_val = data->levels[nlevels - 1];
395+ /*
396+ * Multiplying by 128 means that even in pathological cases such
397+ * as (max_val - min_val) == nlevels the error at max_val is less
398+ * than 1%.
399+ */
400+ unsigned int slope = (128 * (max_val - min_val)) / nlevels;
401+ unsigned int margin = (max_val - min_val) / 20; /* 5% */
402+ int i;
403+
404+ for (i = 1; i < nlevels; i++) {
405+ unsigned int linear_value = min_val + ((i * slope) / 128);
406+ unsigned int delta = abs(linear_value - data->levels[i]);
407+
408+ if (delta > margin)
409+ return false;
410+ }
411+
412+ return true;
413+}
414+
390415 static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb)
391416 {
392417 struct device_node *node = pb->dev->of_node;
@@ -536,6 +561,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) · 143 unmodified lines
536561 goto err_alloc;
537562 }
538563
564+ memset(&props, 0, sizeof(struct backlight_properties));
565+
539566 if (data->levels) {
540567 /*
541568 * For the DT case, only when brightness levels is defined
@@ -548,6 +575,11 @@ static int pwm_backlight_probe(struct platform_device *pdev) · 6 unmodified lines
548575
549576 pb->levels = data->levels;
550577 }
578+
579+ if (pwm_backlight_is_linear(data))
580+ props.scale = BACKLIGHT_SCALE_LINEAR;
581+ else
582+ props.scale = BACKLIGHT_SCALE_NON_LINEAR;
551583 } else if (!data->max_brightness) {
552584 /*
553585 * If no brightness levels are provided and max_brightness is
@@ -574,6 +606,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) · 20 unmodified lines
574606
575607 pb->levels = data->levels;
576608 }
609+
610+ props.scale = BACKLIGHT_SCALE_NON_LINEAR;
577611 } else {
578612 /*
579613 * That only happens for the non-DT case, where platform data
@@ -584,7 +618,6 @@ static int pwm_backlight_probe(struct platform_device *pdev) · 4 unmodified lines
584618
585619 pb->lth_brightness = data->lth_brightness * (state.period / pb->scale);
586620
587− memset(&props, 0, sizeof(struct backlight_properties));
588621 props.type = BACKLIGHT_RAW;
589622 props.max_brightness = data->max_brightness;
590623 bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb,
drivers/video/backlight/rave-sp-backlight.c+8−2
@@ -48,14 +48,20 @@ static int rave_sp_backlight_probe(struct platform_device *pdev) · 47 unmodified lines
4848 struct device *dev = &pdev->dev;
4949 struct backlight_device *bd;
5050
51− bd = devm_backlight_device_register(dev, pdev->name, dev->parent,
51+ bd = devm_backlight_device_register(dev, pdev->name, dev,
5252 dev_get_drvdata(dev->parent),
5353 &rave_sp_backlight_ops,
5454 &rave_sp_backlight_props);
5555 if (IS_ERR(bd))
5656 return PTR_ERR(bd);
5757
58− backlight_update_status(bd);
58+ /*
59+ * If there is a phandle pointing to the device node we can
60+ * assume that another device will manage the status changes.
61+ * If not we make sure the backlight is in a consistent state.
62+ */
63+ if (!dev->of_node->phandle)
64+ backlight_update_status(bd);
5965
6066 return 0;
6167 }
drivers/video/backlight/tosa_lcd.c+1−2
@@ -222,8 +222,7 @@ static int tosa_lcd_remove(struct spi_device *spi) · 221 unmodified lines
222222 {
223223 struct tosa_lcd_data *data = spi_get_drvdata(spi);
224224
225− if (data->i2c)
226− i2c_unregister_device(data->i2c);
225+ i2c_unregister_device(data->i2c);
227226
228227 tosa_lcd_tg_off(data);
229228
include/linux/backlight.h+8−0
@@ -46,6 +46,12 @@ enum backlight_notification { · 45 unmodified lines
4646 BACKLIGHT_UNREGISTERED,
4747 };
4848
49+enum backlight_scale {
50+ BACKLIGHT_SCALE_UNKNOWN = 0,
51+ BACKLIGHT_SCALE_LINEAR,
52+ BACKLIGHT_SCALE_NON_LINEAR,
53+};
54+
4955 struct backlight_device;
5056 struct fb_info;
5157
@@ -80,6 +86,8 @@ struct backlight_properties { · 28 unmodified lines
8086 enum backlight_type type;
8187 /* Flags used to signal drivers of state changes */
8288 unsigned int state;
89+ /* Type of the brightness scale (linear, non-linear, ...) */
90+ enum backlight_scale scale;
8391
8492 #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */
8593 #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t