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 @@
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+1−0
@@ -2907,6 +2907,7 @@ F: include/linux/backlight.h · 2906 unmodified lines
29072907 F: include/linux/pwm_backlight.h
29082908 F: Documentation/devicetree/bindings/leds/backlight
29092909 F: Documentation/ABI/stable/sysfs-class-backlight
2910+F: Documentation/ABI/testing/sysfs-class-backlight
29102911
29112912 BATMAN ADVANCED
29122913 M: 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
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 };
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