History

backlight: Expose brightness curve type through sysfs

Backlight brightness curves can have different shapes. The two main types are linear and non-linear curves. The human eye doesn't perceive linearly increasing/decreasing brightness as linear (see also 88ba95bedb79 "backlight: pwm_bl: Compute brightness of LED linearly to human eye"), hence many backlights use non-linear (often logarithmic) brightness curves. The type of curve currently is opaque to userspace, so userspace often uses more or less reliable heuristics (like the number of brightness levels) to decide whether to treat a backlight device as linear or non-linear. Export the type of the brightness curve via the new sysfs attribute 'scale'. The value of the attribute can be 'linear', 'non-linear' or 'unknown'. For devices that don't provide information about the scale of their brightness curve the value of the 'scale' attribute is 'unknown'.

Matthias Kaehlcke committed 7 years ago

Commit d55c0281 parent 6451e124 files · +54 −0Browse files

Unified · Split

4 files
  1. Documentation/ABI/testing/sysfs-class-backlight +26 −0
  2. MAINTAINERS +1 −0
  3. drivers/video/backlight/backlight.c +19 −0
  4. include/linux/backlight.h +8 −0
Documentation/ABI/testing/sysfs-class-backlight+26−0
@@ -0,0 +1,26 @@
1What: /sys/class/backlight/<backlight>/scale
2Date: July 2019
3KernelVersion: 5.4
4Contact: Daniel Thompson <daniel.thompson@linaro.org>
5Description:
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+1−0
@@ -2907,6 +2907,7 @@ F: include/linux/backlight.h · 2906 unmodified lines
2907F: include/linux/pwm_backlight.h2907F: include/linux/pwm_backlight.h
2908F: Documentation/devicetree/bindings/leds/backlight2908F: Documentation/devicetree/bindings/leds/backlight
2909F: Documentation/ABI/stable/sysfs-class-backlight2909F: Documentation/ABI/stable/sysfs-class-backlight
2910F: Documentation/ABI/testing/sysfs-class-backlight
2910 2911
2911BATMAN ADVANCED2912BATMAN ADVANCED
2912M: Marek Lindner <mareklindner@neomailbox.ch>2913M: Marek Lindner <mareklindner@neomailbox.ch>
drivers/video/backlight/backlight.c+19−0
@@ -32,6 +32,12 @@ static const char *const backlight_types[] = { · 31 unmodified lines
32 [BACKLIGHT_FIRMWARE] = "firmware",32 [BACKLIGHT_FIRMWARE] = "firmware",
33};33};
34 34
35static 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
35#if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \41#if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \
36 defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE))42 defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE))
37/* This callback gets called when something important happens inside a43/* 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
246}252}
247static DEVICE_ATTR_RO(actual_brightness);253static DEVICE_ATTR_RO(actual_brightness);
248 254
255static 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}
265static DEVICE_ATTR_RO(scale);
266
249static struct class *backlight_class;267static struct class *backlight_class;
250 268
251#ifdef CONFIG_PM_SLEEP269#ifdef CONFIG_PM_SLEEP
@@ -292,6 +310,7 @@ static struct attribute *bl_device_attrs[] = { · 40 unmodified lines
292 &dev_attr_brightness.attr,310 &dev_attr_brightness.attr,
293 &dev_attr_actual_brightness.attr,311 &dev_attr_actual_brightness.attr,
294 &dev_attr_max_brightness.attr,312 &dev_attr_max_brightness.attr,
313 &dev_attr_scale.attr,
295 &dev_attr_type.attr,314 &dev_attr_type.attr,
296 NULL,315 NULL,
297};316};
include/linux/backlight.h+8−0
@@ -46,6 +46,12 @@ enum backlight_notification { · 45 unmodified lines
46 BACKLIGHT_UNREGISTERED,46 BACKLIGHT_UNREGISTERED,
47};47};
48 48
49enum backlight_scale {
50 BACKLIGHT_SCALE_UNKNOWN = 0,
51 BACKLIGHT_SCALE_LINEAR,
52 BACKLIGHT_SCALE_NON_LINEAR,
53};
54
49struct backlight_device;55struct backlight_device;
50struct fb_info;56struct fb_info;
51 57
@@ -80,6 +86,8 @@ struct backlight_properties { · 28 unmodified lines
80 enum backlight_type type;86 enum backlight_type type;
81 /* Flags used to signal drivers of state changes */87 /* Flags used to signal drivers of state changes */
82 unsigned int state;88 unsigned int state;
89 /* Type of the brightness scale (linear, non-linear, ...) */
90 enum backlight_scale scale;
83 91
84#define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */92#define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */
85#define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */93#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