backlight: Expose brightness curve type through sysfs
Subsystems (3)
v3 cover 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 is currently opaque to userspace, so userspace often relies on 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 a new sysfs attribute.
Matthias Kaehlcke (4):
MAINTAINERS: Add entry for stable backlight sysfs ABI documentation
backlight: Expose brightness curve type through sysfs
backlight: pwm_bl: Set scale type for CIE 1931 curves
backlight: pwm_bl: Set scale type for brightness curves specified in
the DT
.../ABI/testing/sysfs-class-backlight | 26 ++++++++++++++ MAINTAINERS | 2 ++ drivers/video/backlight/backlight.c | 19 ++++++++++ drivers/video/backlight/pwm_bl.c | 35 ++++++++++++++++++- include/linux/backlight.h | 8 +++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-class-backlight
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v3 1/4 MAINTAINERS: Add entry for stable backlight sysfs ABI documentation
Add an entry for the stable backlight sysfs ABI to the MAINTAINERS file.
---
Changes in v3:
- none
Changes in v2:
- added Daniel's 'Acked-by' tag
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -2857,6 +2857,7 @@ F: drivers/video/backlight/ F: include/linux/backlight.h F: include/linux/pwm_backlight.h F: Documentation/devicetree/bindings/leds/backlight +F: Documentation/ABI/stable/sysfs-class-backlight BATMAN ADVANCED M: Marek Lindner <[email protected]>
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Lee Jones
AppliedRe: [PATCH v3 1/4] MAINTAINERS: Add entry for stable backlight sysfs ABI documentation
Quoted 9 lines · Matthias Kaehlcke
Add an entry for the stable backlight sysfs ABI to the
MAINTAINERSfile.Signed-off-by Matthias Kaehlcke <[email protected]>Acked-by Daniel Thompson <[email protected]>---
Changes in v3:
- none
Quoted 5 lines
Changes in v2:
- added Daniel's 'Acked-by' tag--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
Applied, thanks.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH v3 2/4 backlight: Expose brightness curve type through sysfs
In reply to Matthias KaehlckeBacklight 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'.
---
Feel free to suggest improvements in the documentation :)
Changes in v3:
- removed composite strings, only keep 'linear', 'non-linear' and 'unknown'
- updated sysfs attribute documentation
- updated commit message
Changes in v2:
- changed order of brightness scale enums, explicitly make 'unknown' zero
- minor update of commit message
- deleted excess blank line after 'backlight_scale_types'
- s/curves/curve/ in sysfs doc
--- .../ABI/testing/sysfs-class-backlight | 26 +++++++++++++++++++ MAINTAINERS | 1 + drivers/video/backlight/backlight.c | 19 ++++++++++++++ include/linux/backlight.h | 8 ++++++ 4 files changed, 54 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-backlight
Documentation/ABI/testing/sysfs-class-backlight new file +26 -0
@@ -0,0 +1,26 @@ +What: /sys/class/backlight/<backlight>/scale +Date: July 2019 +KernelVersion: 5.4 +Contact: Daniel Thompson <[email protected]> +Description: + Description of the scale of the brightness curve. + + The human eye senses brightness approximately logarithmically, + hence linear changes in brightness are perceived as being + non-linear. To achieve a linear perception of brightness changes + controls like sliders need to apply a logarithmic mapping for + backlights with a linear brightness curve. + + Possible values of the attribute are: + + unknown + The scale of the brightness curve is unknown. + + linear + The brightness changes linearly with each step. Brightness + controls should apply a logarithmic mapping for a linear + perception. + + non-linear + The brightness changes non-linearly with each step. Brightness + controls should use a linear mapping for a linear perception.
MAINTAINERS +1 -0
@@ -2858,6 +2858,7 @@ F: include/linux/backlight.h F: include/linux/pwm_backlight.h F: Documentation/devicetree/bindings/leds/backlight F: Documentation/ABI/stable/sysfs-class-backlight +F: Documentation/ABI/testing/sysfs-class-backlight BATMAN ADVANCED M: Marek Lindner <[email protected]>
drivers/video/backlight/backlight.c +19 -0
@@ -32,6 +32,12 @@ static const char *const backlight_types[] = { [BACKLIGHT_FIRMWARE] = "firmware", }; +static const char *const backlight_scale_types[] = { + [BACKLIGHT_SCALE_UNKNOWN ] ="unknown" , + [BACKLIGHT_SCALE_LINEAR ] ="linear" , + [BACKLIGHT_SCALE_NON_LINEAR ] ="non-linear" , +}; +#if defined(CONFIG_FB ) || (defined(CONFIG_FB_MODULE ) && \ defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE ))/* This callback gets called when something important happens inside a
@@ -246,6 +252,18 @@ static ssize_t actual_brightness_show(struct device *dev, }static DEVICE_ATTR_RO (actual_brightness); +static ssize_t scale_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct backlight_device *bd =to_backlight_device (dev); + +if (WARN_ON (bd->props.scale >BACKLIGHT_SCALE_NON_LINEAR )) +return sprintf (buf,"unknown\n" ); + +return sprintf (buf,"%s\n" , backlight_scale_types[bd->props.scale]); +} +static DEVICE_ATTR_RO (scale); +static struct class *backlight_class;#ifdef CONFIG_PM_SLEEP
@@ -292,6 +310,7 @@ static struct attribute *bl_device_attrs[] = { &dev_attr_brightness.attr, &dev_attr_actual_brightness.attr, &dev_attr_max_brightness.attr, + &dev_attr_scale.attr, &dev_attr_type.attr, NULL, };
include/linux/backlight.h +8 -0
@@ -46,6 +46,12 @@ enum backlight_notification { BACKLIGHT_UNREGISTERED, }; +enum backlight_scale { +BACKLIGHT_SCALE_UNKNOWN =0 , +BACKLIGHT_SCALE_LINEAR , +BACKLIGHT_SCALE_NON_LINEAR , +}; +struct backlight_device ;struct fb_info ;
@@ -80,6 +86,8 @@ struct backlight_properties {enum backlight_type type;/* Flags used to signal drivers of state changes */ unsigned int state; +/* Type of the brightness scale (linear, non-linear, ...) */ +enum backlight_scale scale;#define BL_CORE_SUSPENDED (1 << 0)/* backlight is suspended */ #define BL_CORE_FBBLANK (1 << 1)/* backlight is under an fb blank event */
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Quoted 10 lines · Matthias Kaehlcke
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.
Quoted 6 lines
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'.
Signed-off-by Matthias Kaehlcke <[email protected]>
Daniel (et al): do you have any more comments on this patch/series or is it ready to land?
Thanks
Matthias
Daniel Thompson
Reviewed-byQuoted 16 lines · Matthias Kaehlcke
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>Daniel (et al): do you have any more comments on this patch/series or is it ready to land?
I decided to leave it for a long while for others to review since I'm still a tiny bit uneasy about the linear/non-linear terminology.
However that's my only concern, its fairly minor and I've dragged by feet for more then long enough, so:
Daniel.
Quoted 22 lines · Daniel Thompson
Quoted 16 lines · Matthias Kaehlcke
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>Daniel (et al): do you have any more comments on this patch/series or is it ready to land?
Quoted 6 lines
I decided to leave it for a long while for others to review since I'm still a tiny bit uneasy about the linear/non-linear terminology.
However that's my only concern, its fairly minor and I've dragged by feet for more then long enough, so:
Reviewed-by Daniel Thompson <[email protected]>
Thanks!
If you or someone else has another suggestion for the terminology that we can all agree on I'm happy to change it.
Quoted 26 lines · Matthias Kaehlcke
Quoted 25 lines · Daniel Thompson
Quoted 16 lines · Matthias Kaehlcke
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>Daniel (et al): do you have any more comments on this patch/series or is it ready to land?
I decided to leave it for a long while for others to review since I'm still a tiny bit uneasy about the linear/non-linear terminology.
Quoted 8 lines
Quoted 3 lines
However that's my only concern, its fairly minor and I've dragged by feet for more then long enough, so:
Reviewed-by Daniel Thompson <[email protected]>Thanks!
If you or someone else has another suggestion for the terminology that we can all agree on I'm happy to change it.
As you will see in my reply to Uwe. The term I tend to adopt when I want to be precise about userspace behaviour is "perceptual" (e.g. that a backlight can be mapped directly to a slider and it will feel right).
However that raises its own concerns: mostly about what is perceptual enough.
Clear the automatic brightness curve support in the PWM driver is perceptual.
To be honest I suspect that in most cases a true logarithmic curve (given a sane exponent) would be perceptual enough. In other words it will feel comfortable with a direct mapped slider and using it for animation won't be too bad.
However when we get right down to it *that* is the information that is actually most useful to userspace: explicit confirmation that the scale can be mapped directly to a slider. I think it also aligned better with Uwe's feedback (e.g. to start working towards having a preferred scale).
Daniel.
Hi Daniel,
Quoted 51 lines · Daniel Thompson
Quoted 26 lines · Matthias Kaehlcke
Quoted 25 lines · Daniel Thompson
Quoted 16 lines · Matthias Kaehlcke
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>Daniel (et al): do you have any more comments on this patch/series or is it ready to land?
I decided to leave it for a long while for others to review since I'm still a tiny bit uneasy about the linear/non-linear terminology.
Quoted 8 lines
Quoted 3 lines
However that's my only concern, its fairly minor and I've dragged by feet for more then long enough, so:
Reviewed-by Daniel Thompson <[email protected]>Thanks!
If you or someone else has another suggestion for the terminology that we can all agree on I'm happy to change it.
As you will see in my reply to Uwe. The term I tend to adopt when I want to be precise about userspace behaviour is "perceptual" (e.g. that a backlight can be mapped directly to a slider and it will feel right).
However that raises its own concerns: mostly about what is perceptual enough.
Clear the automatic brightness curve support in the PWM driver is perceptual.
To be honest I suspect that in most cases a true logarithmic curve (given a sane exponent) would be perceptual enough. In other words it will feel comfortable with a direct mapped slider and using it for animation won't be too bad.
Quoted 4 lines
However when we get right down to it *that* is the information that is actually most useful to userspace: explicit confirmation that the scale can be mapped directly to a slider. I think it also aligned better with Uwe's feedback (e.g. to start working towards having a preferred scale).
IIUC the conclusion is that there is no need for a string attribute because we only need to distinguish between 'perceptual' and 'non-perceptual'. If that is correct, do you have any preference for the attribute name ('perceptual_scale', 'perceptual', ...)?
Quoted 59 lines · Matthias Kaehlcke
Hi Daniel,
Quoted 51 lines · Daniel Thompson
Quoted 26 lines · Matthias Kaehlcke
Quoted 25 lines · Daniel Thompson
Quoted 16 lines · Matthias Kaehlcke
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>Daniel (et al): do you have any more comments on this patch/series or is it ready to land?
I decided to leave it for a long while for others to review since I'm still a tiny bit uneasy about the linear/non-linear terminology.
Quoted 8 lines
Quoted 3 lines
However that's my only concern, its fairly minor and I've dragged by feet for more then long enough, so:
Reviewed-by Daniel Thompson <[email protected]>Thanks!
If you or someone else has another suggestion for the terminology that we can all agree on I'm happy to change it.
As you will see in my reply to Uwe. The term I tend to adopt when I want to be precise about userspace behaviour is "perceptual" (e.g. that a backlight can be mapped directly to a slider and it will feel right).
However that raises its own concerns: mostly about what is perceptual enough.
Clear the automatic brightness curve support in the PWM driver is perceptual.
To be honest I suspect that in most cases a true logarithmic curve (given a sane exponent) would be perceptual enough. In other words it will feel comfortable with a direct mapped slider and using it for animation won't be too bad.
Quoted 4 lines
However when we get right down to it *that* is the information that is actually most useful to userspace: explicit confirmation that the scale can be mapped directly to a slider. I think it also aligned better with Uwe's feedback (e.g. to start working towards having a preferred scale).
Quoted 4 lines
IIUC the conclusion is that there is no need for a string attribute because we only need to distinguish between 'perceptual' and 'non-perceptual'. If that is correct, do you have any preference for the attribute name ('
perceptual_scale', 'perceptual', ...)?
More a summary than a conclusion! There is a reason I have left a bit or space for others to comment on this over the last month (and a bit).
To be clear my Reviewed-by: means that I believe that the kernel is better with "non-linear/linear/unknown" than without it and that I am comfortable the API isn't likely to be a millstone for us.
Lee, Jingoo: Either of you care to offer $0.02
Daniel.
[...]
Quoted 5 lines
Quoted 4 lines
IIUC the conclusion is that there is no need for a string attribute because we only need to distinguish between 'perceptual' and 'non-perceptual'. If that is correct, do you have any preference for the attribute name ('
perceptual_scale', 'perceptual', ...)?
Quoted 8 lines
More a summary than a conclusion! There is a reason I have left a bit or space for others to comment on this over the last month (and a bit).
To be clear my Reviewed-by: means that I believe that the kernel is better with "non-linear/linear/unknown" than without it and that I am comfortable the API isn't likely to be a millstone for us.
Lee, Jingoo: Either of you care to offer $0.02
No, not really. Happy to leave it to your good judgement.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 10 lines · Lee Jones
[...]
Quoted 8 lines
Quoted 4 lines
IIUC the conclusion is that there is no need for a string attribute because we only need to distinguish between 'perceptual' and 'non-perceptual'. If that is correct, do you have any preference for the attribute name ('
perceptual_scale', 'perceptual', ...)?More a summary than a conclusion! There is a reason I have left a bit or space for others to comment on this over the last month (and a bit).
Quoted 7 lines
Quoted 5 lines
To be clear my Reviewed-by: means that I believe that the kernel is better with "non-linear/linear/unknown" than without it and that I am comfortable the API isn't likely to be a millstone for us.
Lee, Jingoo: Either of you care to offer $0.02
No, not really. Happy to leave it to your good judgement.
In that case... the patch has my reviewed-by and although the concerns raised in the associated threads have merit I don't think they are enough to stop the patch.
Please merge.
Daniel.
Quoted 6 lines
Signature · 5 lines
-- Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 10 lines · Matthias Kaehlcke
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.
Quoted 6 lines
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'.
Signed-off-by Matthias Kaehlcke <[email protected]>
I wonder what kind of problem you are solving here. Can you describe that in a few words?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 16 lines · Uwe Kleine-König
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>I wonder what kind of problem you are solving here. Can you describe that in a few words?
The human eye perceives brightness in a logarithmic manner. For
backlights with a linear brightness curve brightness controls like
sliders need to use a mapping to achieve a behavior that is perceived
as linear-ish (more details: http://www.pathwaylighting.com/products/downloads/brochure/technical_materials_1466797044_Linear+vs+Logarithmic+Dimming+White+Paper.pdf)
As of now userspace doesn't have information about the type of the brightness curve, and often uses heuristics to make a guess, which may be right most of the time, but not always. The new attribute eliminates the need to guess.
Quoted 29 lines · Matthias Kaehlcke
Hi Uwe,
Quoted 16 lines · Uwe Kleine-König
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>I wonder what kind of problem you are solving here. Can you describe that in a few words?
The human eye perceives brightness in a logarithmic manner. For
backlights with a linear brightness curve brightness controls like
sliders need to use a mapping to achieve a behavior that is perceived
as linear-ish (more details: http://www.pathwaylighting.com/products/downloads/brochure/technical_materials_1466797044_Linear+vs+Logarithmic+Dimming+White+Paper.pdf)
Quoted 4 lines
As of now userspace doesn't have information about the type of the brightness curve, and often uses heuristics to make a guess, which may be right most of the time, but not always. The new attribute eliminates the need to guess.
This is about backlights right? So the kernel provides to userspace an interval [0, x] for some x and depending on the physics of the the backlight configuring x/2 (probably?) either means 50% measured light or 50% perceived light, right?
I wonder if it would be possible instead of giving different backlight implementations the freedom to use either linear or logarithmic (or quadratic?) scaling and tell userspace which of the options were picked require the drivers to provide a (say) linear scaling and then userspace wouldn't need to care about the exact physics.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Quoted 35 lines · Uwe Kleine-König
Quoted 29 lines · Matthias Kaehlcke
Hi Uwe,
Quoted 16 lines · Uwe Kleine-König
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>I wonder what kind of problem you are solving here. Can you describe that in a few words?
The human eye perceives brightness in a logarithmic manner. For
backlights with a linear brightness curve brightness controls like
sliders need to use a mapping to achieve a behavior that is perceived
as linear-ish (more details: http://www.pathwaylighting.com/products/downloads/brochure/technical_materials_1466797044_Linear+vs+Logarithmic+Dimming+White+Paper.pdf)Quoted 4 lines
As of now userspace doesn't have information about the type of the brightness curve, and often uses heuristics to make a guess, which may be right most of the time, but not always. The new attribute eliminates the need to guess.
Quoted 4 lines
This is about backlights right? So the kernel provides to userspace an interval [0, x] for some x and depending on the physics of the the backlight configuring x/2 (probably?) either means 50% measured light or 50% perceived light, right?
correct
Quoted 5 lines
I wonder if it would be possible instead of giving different backlight implementations the freedom to use either linear or logarithmic (or quadratic?) scaling and tell userspace which of the options were picked require the drivers to provide a (say) linear scaling and then userspace wouldn't need to care about the exact physics.
In an ideal world the backlight interface would be consistent as you suggest, however there are plenty of existing devices which use the 'other' scaling (regardless of which is chosen as the 'correct' one). Userspace still has to deal with these. And changing previously 'logarithmic' drivers to linear (or viceversa) may 'break' userspace, when it keeps using its 'old' scaling, which now isn't correct anymore.
Hello Matthias,
Quoted 49 lines · Matthias Kaehlcke
Quoted 35 lines · Uwe Kleine-König
Quoted 29 lines · Matthias Kaehlcke
Hi Uwe,
Quoted 16 lines · Uwe Kleine-König
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>I wonder what kind of problem you are solving here. Can you describe that in a few words?
The human eye perceives brightness in a logarithmic manner. For
backlights with a linear brightness curve brightness controls like
sliders need to use a mapping to achieve a behavior that is perceived
as linear-ish (more details: http://www.pathwaylighting.com/products/downloads/brochure/technical_materials_1466797044_Linear+vs+Logarithmic+Dimming+White+Paper.pdf)Quoted 4 lines
As of now userspace doesn't have information about the type of the brightness curve, and often uses heuristics to make a guess, which may be right most of the time, but not always. The new attribute eliminates the need to guess.
Quoted 4 lines
This is about backlights right? So the kernel provides to userspace an interval [0, x] for some x and depending on the physics of the the backlight configuring x/2 (probably?) either means 50% measured light or 50% perceived light, right?
correct
Quoted 5 lines
I wonder if it would be possible instead of giving different backlight implementations the freedom to use either linear or logarithmic (or quadratic?) scaling and tell userspace which of the options were picked require the drivers to provide a (say) linear scaling and then userspace wouldn't need to care about the exact physics.
Quoted 6 lines
In an ideal world the backlight interface would be consistent as you suggest, however there are plenty of existing devices which use the 'other' scaling (regardless of which is chosen as the 'correct' one). Userspace still has to deal with these. And changing previously 'logarithmic' drivers to linear (or viceversa) may 'break' userspace, when it keeps using its 'old' scaling, which now isn't correct anymore.
It might be subjective, or maybe I'm just too optimistic, but I think if there was no policy before about the meaning of
echo 17 > brightness
other than "brighter than lower values and darker than higher ones" introducing (say) the scale is intended to represent a linear brightness curve is ok.
Unless userspace jumps through hoops and tries to identify the actual device it is running on it is wrong on some machines anyhow and we're only shifting the set of affected machines with a tighter policy (until that userspace application is fixed).
And the big upside is that in the end (i.e. when all kernel drivers and userspace applications are adapted to provide/consume the "correct" curve) the result is simpler.
Just my 0.02€
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Quoted 64 lines · Uwe Kleine-König
Hello Matthias,
Quoted 49 lines · Matthias Kaehlcke
Quoted 35 lines · Uwe Kleine-König
Quoted 29 lines · Matthias Kaehlcke
Hi Uwe,
Quoted 16 lines · Uwe Kleine-König
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>I wonder what kind of problem you are solving here. Can you describe that in a few words?
The human eye perceives brightness in a logarithmic manner. For
backlights with a linear brightness curve brightness controls like
sliders need to use a mapping to achieve a behavior that is perceived
as linear-ish (more details: http://www.pathwaylighting.com/products/downloads/brochure/technical_materials_1466797044_Linear+vs+Logarithmic+Dimming+White+Paper.pdf)Quoted 4 lines
As of now userspace doesn't have information about the type of the brightness curve, and often uses heuristics to make a guess, which may be right most of the time, but not always. The new attribute eliminates the need to guess.
Quoted 4 lines
This is about backlights right? So the kernel provides to userspace an interval [0, x] for some x and depending on the physics of the the backlight configuring x/2 (probably?) either means 50% measured light or 50% perceived light, right?
correct
Quoted 5 lines
I wonder if it would be possible instead of giving different backlight implementations the freedom to use either linear or logarithmic (or quadratic?) scaling and tell userspace which of the options were picked require the drivers to provide a (say) linear scaling and then userspace wouldn't need to care about the exact physics.
Quoted 6 lines
In an ideal world the backlight interface would be consistent as you suggest, however there are plenty of existing devices which use the 'other' scaling (regardless of which is chosen as the 'correct' one). Userspace still has to deal with these. And changing previously 'logarithmic' drivers to linear (or viceversa) may 'break' userspace, when it keeps using its 'old' scaling, which now isn't correct anymore.
It might be subjective, or maybe I'm just too optimistic, but I think if there was no policy before about the meaning of
echo 17 > brightness
Quoted 8 lines
other than "brighter than lower values and darker than higher ones" introducing (say) the scale is intended to represent a linear brightness curve is ok.
Unless userspace jumps through hoops and tries to identify the actual device it is running on it is wrong on some machines anyhow and we're only shifting the set of affected machines with a tighter policy (until that userspace application is fixed).
I believe that there are two common approaches by userspace at present:
1. Assume the scale is perceptual and we can directly map a slider to the backlight value. This is common simply because most ACPI backlights are perceptual and therefore when tested in a laptop it works OK.
2. Assume that is max brightness is small (e.g. ACPI) then the scale is perceptual and if the max brightness is large (e.g. a PWM) then the scale is linear and apply a correction function between the slider and the control.
That historic baggage makes is diffcult to "just define a standardized scale"... especially given that if we selected a standardized scale we would probably want a perceptual scale with lots of steps (e.g. break the heuristic).
Quoted 3 lines
And the big upside is that in the end (i.e. when all kernel drivers and userspace applications are adapted to provide/consume the "correct" curve) the result is simpler.
My view is that this convergence will eventually be achieved but it will happen through the obsolescence of the backlight sysfs interface. The sysfs interface has other flaws, in particular no integration with the DRM connector API.
Thus I would expect an alternative interface to emerge, most likely as part of the DRM connector API. I'd expect such a new API to a perceptual scale and to have a fixed max brightness with enough steps to support animated backlight effects (IIRC 0..100 has been proposed in the past)
In the mean time getting the existing collection of backlight drivers marked up as linear/logarithmic/etc will ease the introduction of that API because, within the kernel, we might have gathered enough knowledge to have some hope of correctly mapping each backlight onto a standardized scale.
Daniel.
Hello Daniel,
Quoted 86 lines · Daniel Thompson
Quoted 64 lines · Uwe Kleine-König
Hello Matthias,
Quoted 49 lines · Matthias Kaehlcke
Quoted 35 lines · Uwe Kleine-König
Quoted 29 lines · Matthias Kaehlcke
Hi Uwe,
Quoted 16 lines · Uwe Kleine-König
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>I wonder what kind of problem you are solving here. Can you describe that in a few words?
The human eye perceives brightness in a logarithmic manner. For
backlights with a linear brightness curve brightness controls like
sliders need to use a mapping to achieve a behavior that is perceived
as linear-ish (more details: http://www.pathwaylighting.com/products/downloads/brochure/technical_materials_1466797044_Linear+vs+Logarithmic+Dimming+White+Paper.pdf)Quoted 4 lines
As of now userspace doesn't have information about the type of the brightness curve, and often uses heuristics to make a guess, which may be right most of the time, but not always. The new attribute eliminates the need to guess.
Quoted 4 lines
This is about backlights right? So the kernel provides to userspace an interval [0, x] for some x and depending on the physics of the the backlight configuring x/2 (probably?) either means 50% measured light or 50% perceived light, right?
correct
Quoted 5 lines
I wonder if it would be possible instead of giving different backlight implementations the freedom to use either linear or logarithmic (or quadratic?) scaling and tell userspace which of the options were picked require the drivers to provide a (say) linear scaling and then userspace wouldn't need to care about the exact physics.
Quoted 6 lines
In an ideal world the backlight interface would be consistent as you suggest, however there are plenty of existing devices which use the 'other' scaling (regardless of which is chosen as the 'correct' one). Userspace still has to deal with these. And changing previously 'logarithmic' drivers to linear (or viceversa) may 'break' userspace, when it keeps using its 'old' scaling, which now isn't correct anymore.
It might be subjective, or maybe I'm just too optimistic, but I think if there was no policy before about the meaning of
echo 17 > brightness
Quoted 8 lines
other than "brighter than lower values and darker than higher ones" introducing (say) the scale is intended to represent a linear brightness curve is ok.
Unless userspace jumps through hoops and tries to identify the actual device it is running on it is wrong on some machines anyhow and we're only shifting the set of affected machines with a tighter policy (until that userspace application is fixed).
I believe that there are two common approaches by userspace at present:
1. Assume the scale is perceptual and we can directly map a slider to the backlight value. This is common simply because most ACPI backlights are perceptual and therefore when tested in a laptop it works OK.
2. Assume that is max brightness is small (e.g. ACPI) then the scale is perceptual and if the max brightness is large (e.g. a PWM) then the scale is linear and apply a correction function between the slider and the control.
Quoted 4 lines
That historic baggage makes is diffcult to "just define a standardized scale"... especially given that if we selected a standardized scale we would probably want a perceptual scale with lots of steps (e.g. break the heuristic).
With "perceptual" you mean that logarithmic stuff, right?
I would tend to go for linear because this is easily measureable and also is straight forward to implement in the usual cases (attention: I assume that "usual" means something like PWM and I don't know much about the physics of backlights but just assume that a PWM will create a linear mapping).
Quoted 9 lines
Quoted 3 lines
And the big upside is that in the end (i.e. when all kernel drivers and userspace applications are adapted to provide/consume the "correct" curve) the result is simpler.
My view is that this convergence will eventually be achieved but it will happen through the obsolescence of the backlight sysfs interface. The sysfs interface has other flaws, in particular no integration with the DRM connector API.
Quoted 5 lines
Thus I would expect an alternative interface to emerge, most likely as part of the DRM connector API. I'd expect such a new API to a perceptual scale and to have a fixed max brightness with enough steps to support animated backlight effects (IIRC 0..100 has been proposed in the past)
Then work on the new stuff instead of making the old stuff (that is intended to die) harder to use correctly?
Quoted 5 lines
In the mean time getting the existing collection of backlight drivers marked up as linear/logarithmic/etc will ease the introduction of that API because, within the kernel, we might have gathered enough knowledge to have some hope of correctly mapping each backlight onto a standardized scale.
It would be enough to do this in a code comment then. That would come without the need to adapt the old userspace API. Also when the old solution works at 95% instead of 90% before, it will resist harder to dying.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Quoted 33 lines · Uwe Kleine-König
Quoted 33 lines
Quoted 12 lines
Quoted 6 lines
In an ideal world the backlight interface would be consistent as you suggest, however there are plenty of existing devices which use the 'other' scaling (regardless of which is chosen as the 'correct' one). Userspace still has to deal with these. And changing previously 'logarithmic' drivers to linear (or viceversa) may 'break' userspace, when it keeps using its 'old' scaling, which now isn't correct anymore.
It might be subjective, or maybe I'm just too optimistic, but I think if there was no policy before about the meaning of
echo 17 > brightness
Quoted 8 lines
other than "brighter than lower values and darker than higher ones" introducing (say) the scale is intended to represent a linear brightness curve is ok.
Unless userspace jumps through hoops and tries to identify the actual device it is running on it is wrong on some machines anyhow and we're only shifting the set of affected machines with a tighter policy (until that userspace application is fixed).
I believe that there are two common approaches by userspace at present:
1. Assume the scale is perceptual and we can directly map a slider to the backlight value. This is common simply because most ACPI backlights are perceptual and therefore when tested in a laptop it works OK.
2. Assume that is max brightness is small (e.g. ACPI) then the scale is perceptual and if the max brightness is large (e.g. a PWM) then the scale is linear and apply a correction function between the slider and the control.
Quoted 6 lines
Quoted 4 lines
That historic baggage makes is diffcult to "just define a standardized scale"... especially given that if we selected a standardized scale we would probably want a perceptual scale with lots of steps (e.g. break the heuristic).
With "perceptual" you mean that logarithmic stuff, right?
Human perception is fairly complex so it depends how strict you want to get. At the end of the day what it means is you can map a slider UI component directly to the backlight range and it will feel right. Thus a userspace that maps directly to a slider *is* assuming the scale is perceptual.
Logarithmic scales are often mentioned in this kind of conversation because they are hoped to be "perceptual enough". They are not strictly matched to human perception but with a sane exponent shouldn't feel as broken as a linear scale does.
Finally note that for people with an audio background then logarithmic and perceptual are used interchangably (based on the assumption that decibels are a preceptual scale).
Quoted 5 lines
I would tend to go for linear because this is easily measureable and also is straight forward to implement in the usual cases (attention: I assume that "usual" means something like PWM and I don't know much about the physics of backlights but just assume that a PWM will create a linear mapping).
Mandating a linear scale makes things difficult for ACPI systems (which are amoung the most common cases) since we would have to un-perceptualize it. Additionally it is not a particularly helpful scale to offer the userspace.
All proposals I have seen in this space assume we will map linear hardware to a perceptual scale rather than trying to unmap devices that are already perceptual.
Within the backlight space we are also moving (slowly) towards perceptual scales to align with this. For example pwm_bl.c will automatically generate a perceptual table unless the DT tells it not to.
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
And the big upside is that in the end (i.e. when all kernel drivers and userspace applications are adapted to provide/consume the "correct" curve) the result is simpler.
My view is that this convergence will eventually be achieved but it will happen through the obsolescence of the backlight sysfs interface. The sysfs interface has other flaws, in particular no integration with the DRM connector API.
Quoted 8 lines
Quoted 5 lines
Thus I would expect an alternative interface to emerge, most likely as part of the DRM connector API. I'd expect such a new API to a perceptual scale and to have a fixed max brightness with enough steps to support animated backlight effects (IIRC 0..100 has been proposed in the past)
Then work on the new stuff instead of making the old stuff (that is intended to die) harder to use correctly?
I do not accept this this change makes it harder to use the backlight correctly.
We know the current userspace heuristics are fragile and that as backlight animation becomes more popular will become unmaintainable (backlight animation encourages backlights with a perceptual scale to introduce more steps... resulting in them being mishandled by userspace).
Anyhow given we know sophisticated userspaces already have two code paths controls by heuristic and that this will break then we are simply providing a clear indication that allows their maintainers a non-heuristic solution when bug reports come in. It also means that userspaces that are currently naive (e.g. assume perceptual scale) need not introduce a heuristic if they get a bug report.
Quoted 10 lines
Quoted 5 lines
In the mean time getting the existing collection of backlight drivers marked up as linear/logarithmic/etc will ease the introduction of that API because, within the kernel, we might have gathered enough knowledge to have some hope of correctly mapping each backlight onto a standardized scale.
It would be enough to do this in a code comment then. That would come without the need to adapt the old userspace API. Also when the old solution works at 95% instead of 90% before, it will resist harder to dying.
To be honest I think the traction for the sysfs interface comes from the fact that, with or without the proposed change, it is good enough for the ACPI systems that dominate the landscape.
Daniel.
Quoted 39 lines · Daniel Thompson
Quoted 38 lines · Uwe Kleine-König
Quoted 37 lines
Quoted 12 lines
Quoted 6 lines
In an ideal world the backlight interface would be consistent as you suggest, however there are plenty of existing devices which use the 'other' scaling (regardless of which is chosen as the 'correct' one). Userspace still has to deal with these. And changing previously 'logarithmic' drivers to linear (or viceversa) may 'break' userspace, when it keeps using its 'old' scaling, which now isn't correct anymore.
It might be subjective, or maybe I'm just too optimistic, but I think if there was no policy before about the meaning of
echo 17 > brightness
Quoted 8 lines
other than "brighter than lower values and darker than higher ones" introducing (say) the scale is intended to represent a linear brightness curve is ok.
Unless userspace jumps through hoops and tries to identify the actual device it is running on it is wrong on some machines anyhow and we're only shifting the set of affected machines with a tighter policy (until that userspace application is fixed).
I believe that there are two common approaches by userspace at present:
1. Assume the scale is perceptual and we can directly map a slider to the backlight value. This is common simply because most ACPI backlights are perceptual and therefore when tested in a laptop it works OK.
2. Assume that is max brightness is small (e.g. ACPI) then the scale is perceptual and if the max brightness is large (e.g. a PWM) then the scale is linear and apply a correction function between the slider and the control.
That historic baggage makes is diffcult to "just define a standardized scale"... especially given that if we selected a standardized scale we would probably want a perceptual scale with lots of steps (e.g. break the heuristic).
Quoted 7 lines
Quoted 1 line
With "perceptual" you mean that logarithmic stuff, right?
Human perception is fairly complex so it depends how strict you want to get. At the end of the day what it means is you can map a slider UI component directly to the backlight range and it will feel right. Thus a userspace that maps directly to a slider *is* assuming the scale is perceptual.
I have problems to declare something as "the right thing to do" that depends on feeling of users. I much prefer to make a technical device authoritative here (in this case a device that measures emitted light).
Other than that I don't have enough experience with backlights to judge the decisions that have to be done and so will stop my participation in this thread now.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Quoted 108 lines · Daniel Thompson
Quoted 64 lines · Uwe Kleine-König
Hello Matthias,
Quoted 49 lines · Matthias Kaehlcke
Quoted 35 lines · Uwe Kleine-König
Quoted 29 lines · Matthias Kaehlcke
Hi Uwe,
Quoted 16 lines · Uwe Kleine-König
Quoted 15 lines · Matthias Kaehlcke
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'.
Quoted 4 lines
Quoted 1 line
Signed-off-by Matthias Kaehlcke <[email protected]>I wonder what kind of problem you are solving here. Can you describe that in a few words?
The human eye perceives brightness in a logarithmic manner. For
backlights with a linear brightness curve brightness controls like
sliders need to use a mapping to achieve a behavior that is perceived
as linear-ish (more details: http://www.pathwaylighting.com/products/downloads/brochure/technical_materials_1466797044_Linear+vs+Logarithmic+Dimming+White+Paper.pdf)Quoted 4 lines
As of now userspace doesn't have information about the type of the brightness curve, and often uses heuristics to make a guess, which may be right most of the time, but not always. The new attribute eliminates the need to guess.
Quoted 4 lines
This is about backlights right? So the kernel provides to userspace an interval [0, x] for some x and depending on the physics of the the backlight configuring x/2 (probably?) either means 50% measured light or 50% perceived light, right?
correct
Quoted 5 lines
I wonder if it would be possible instead of giving different backlight implementations the freedom to use either linear or logarithmic (or quadratic?) scaling and tell userspace which of the options were picked require the drivers to provide a (say) linear scaling and then userspace wouldn't need to care about the exact physics.
Quoted 6 lines
In an ideal world the backlight interface would be consistent as you suggest, however there are plenty of existing devices which use the 'other' scaling (regardless of which is chosen as the 'correct' one). Userspace still has to deal with these. And changing previously 'logarithmic' drivers to linear (or viceversa) may 'break' userspace, when it keeps using its 'old' scaling, which now isn't correct anymore.
It might be subjective, or maybe I'm just too optimistic, but I think if there was no policy before about the meaning of
echo 17 > brightness
Quoted 8 lines
other than "brighter than lower values and darker than higher ones" introducing (say) the scale is intended to represent a linear brightness curve is ok.
Unless userspace jumps through hoops and tries to identify the actual device it is running on it is wrong on some machines anyhow and we're only shifting the set of affected machines with a tighter policy (until that userspace application is fixed).
I believe that there are two common approaches by userspace at present:
1. Assume the scale is perceptual and we can directly map a slider to the backlight value. This is common simply because most ACPI backlights are perceptual and therefore when tested in a laptop it works OK.
2. Assume that is max brightness is small (e.g. ACPI) then the scale is perceptual and if the max brightness is large (e.g. a PWM) then the scale is linear and apply a correction function between the slider and the control.
That historic baggage makes is diffcult to "just define a standardized scale"... especially given that if we selected a standardized scale we would probably want a perceptual scale with lots of steps (e.g. break the heuristic).
Quoted 3 lines
And the big upside is that in the end (i.e. when all kernel drivers and userspace applications are adapted to provide/consume the "correct" curve) the result is simpler.
My view is that this convergence will eventually be achieved but it will happen through the obsolescence of the backlight sysfs interface. The sysfs interface has other flaws, in particular no integration with the DRM connector API.
Thus I would expect an alternative interface to emerge, most likely as part of the DRM connector API. I'd expect such a new API to a perceptual scale and to have a fixed max brightness with enough steps to support animated backlight effects (IIRC 0..100 has been proposed in the past)
Quoted 5 lines
In the mean time getting the existing collection of backlight drivers marked up as linear/logarithmic/etc will ease the introduction of that API because, within the kernel, we might have gathered enough knowledge to have some hope of correctly mapping each backlight onto a standardized scale.
In case people wonder why the drm connector based backlight interface hasn't happened ages ago, some more context:
- userspace (well libbacklight) selects the right backlight, using some priority search. Plus blacklists in drivers to make sure they're not overriding the real backlight driver (e.g. acpi has higher priority in libbacklight, but on modern system it's not the backlight driver you want. If we move that into the kernel it's going to be somewhat a mess, since defacto you never know when loading is complete and you actually have the right backlight driver.
This isn't a problem on DT platforms, but really just for x86/acpi platforms. But if we don't fix them, then userspace adoption of these new interfaces will likely be too low to matter.
- second issue is that right now the kms client is supposed to handle backlight around modeset, like fbdev does through the fb notifier. Except for drivers which do handle the backlight across modesets, but maybe not the right backlight. If we move the backlight interface to drm connectors then the right thing would be for the drm driver to handle backlight enable/disable across modesets. But to make that work, userspace needs to stop touching it (otherwise userspace first disables, then the kernel and then on restore the two fight and usually black screen wins), and that's a bit a tricky uapi problem of not breaking existing userspace.
- finally there's some userspace which assumes the lowest backlight setting is actually off, and uses that to do fast modesets. This doesn't work on most ACPI backlights, so I think that problem isn't widespread.
Anyway from watching from afar, I think this clarification on what the backlight scale means internally should at least help us somewhat in the long term. But the long term solution itself needs someone with way too much time I fear, so lets not hold up anything on that. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 55 lines · Daniel Vetter
Quoted 16 lines · Daniel Thompson
Quoted 3 lines · Uwe Kleine-König
And the big upside is that in the end (i.e. when all kernel drivers and userspace applications are adapted to provide/consume the "correct" curve) the result is simpler.
My view is that this convergence will eventually be achieved but it will happen through the obsolescence of the backlight sysfs interface. The sysfs interface has other flaws, in particular no integration with the DRM connector API.
Thus I would expect an alternative interface to emerge, most likely as part of the DRM connector API. I'd expect such a new API to a perceptual scale and to have a fixed max brightness with enough steps to support animated backlight effects (IIRC 0..100 has been proposed in the past)
Quoted 5 lines
In the mean time getting the existing collection of backlight drivers marked up as linear/logarithmic/etc will ease the introduction of that API because, within the kernel, we might have gathered enough knowledge to have some hope of correctly mapping each backlight onto a standardized scale.
In case people wonder why the drm connector based backlight interface hasn't happened ages ago, some more context:
- userspace (well libbacklight) selects the right backlight, using some priority search. Plus blacklists in drivers to make sure they're not overriding the real backlight driver (e.g. acpi has higher priority in libbacklight, but on modern system it's not the backlight driver you want. If we move that into the kernel it's going to be somewhat a mess, since defacto you never know when loading is complete and you actually have the right backlight driver.
This isn't a problem on DT platforms, but really just for x86/acpi platforms. But if we don't fix them, then userspace adoption of these new interfaces will likely be too low to matter.
- second issue is that right now the kms client is supposed to handle backlight around modeset, like fbdev does through the fb notifier. Except for drivers which do handle the backlight across modesets, but maybe not the right backlight. If we move the backlight interface to drm connectors then the right thing would be for the drm driver to handle backlight enable/disable across modesets. But to make that work, userspace needs to stop touching it (otherwise userspace first disables, then the kernel and then on restore the two fight and usually black screen wins), and that's a bit a tricky uapi problem of not breaking existing userspace.
- finally there's some userspace which assumes the lowest backlight setting is actually off, and uses that to do fast modesets. This doesn't work on most ACPI backlights, so I think that problem isn't widespread.
Quoted 4 lines
Anyway from watching from afar, I think this clarification on what the backlight scale means internally should at least help us somewhat in the long term. But the long term solution itself needs someone with way too much time I fear, so lets not hold up anything on that.
Thanks for sharing your views on this.
Daniel.
Lee Jones
AppliedQuoted 30 lines · Matthias Kaehlcke
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'.
Signed-off-by Matthias Kaehlcke <[email protected]>---
Feel free to suggest improvements in the documentation :)Changes in v3:
- removed composite strings, only keep 'linear', 'non-linear' and 'unknown'
- updated sysfs attribute documentation
- updated commit messageChanges in v2:
- changed order of brightness scale enums, explicitly make 'unknown' zero
- minor update of commit message
- deleted excess blank line after 'backlight_scale_types'
- s/curves/curve/ in sysfs doc
Quoted 7 lines
--- .../ABI/testing/sysfs-class-backlight | 26 +++++++++++++++++++ MAINTAINERS | 1 + drivers/video/backlight/backlight.c | 19 ++++++++++++++ include/linux/backlight.h | 8 ++++++ 4 files changed, 54 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-backlight
Applied, thanks.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH v3 3/4 backlight: pwm_bl: Set scale type for CIE 1931 curves
In reply to Matthias KaehlckeFor backlight curves calculated with the CIE 1931 algorithm set the brightness scale type to non-linear. This makes the scale type available to userspace via the 'scale' sysfs attribute.
---
Changes in v3:
- mark scale as non-linear instead of using the CIE1931 type which has been removed
- updated commit message
Changes in v2:
- added Enric's 'Tested-by' tag
- added Daniel's 'Acked-by' tag
--- drivers/video/backlight/pwm_bl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/video/backlight/pwm_bl.c +4 -1
@@ -553,6 +553,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) goto err_alloc; } +memset (&props,0 ,sizeof (struct backlight_properties )); +if (data->levels) {/* * For the DT case, only when brightness levels is defined
@@ -591,6 +593,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) pb->levels = data->levels; } + + props.scale =BACKLIGHT_SCALE_NON_LINEAR ; }else {/* * That only happens for the non-DT case, where platform data
@@ -601,7 +605,6 @@ static int pwm_backlight_probe(struct platform_device *pdev) pb->lth_brightness = data->lth_brightness * (state.period / pb->scale); -memset (&props,0 ,sizeof (struct backlight_properties )); props.type =BACKLIGHT_RAW ; props.max_brightness = data->max_brightness; bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb,
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Lee Jones
AppliedRe: [PATCH v3 3/4] backlight: pwm_bl: Set scale type for CIE 1931 curves
Quoted 13 lines · Matthias Kaehlcke
For backlight curves calculated with the CIE 1931 algorithm set the brightness scale type to non-linear. This makes the scale type available to userspace via the 'scale' sysfs attribute.
Signed-off-by Matthias Kaehlcke <[email protected]>Acked-by Daniel Thompson <[email protected]>---
Changes in v3:
- mark scale as non-linear instead of using the CIE1931 type which has been removed
- updated commit message
Quoted 6 lines
Changes in v2:
- added Enric's 'Tested-by' tag
- added Daniel's 'Acked-by' tag--- drivers/video/backlight/pwm_bl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Applied, thanks.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH v3 4/4 backlight: pwm_bl: Set scale type for brightness curves specified in the DT
In reply to Matthias KaehlckeCheck if a brightness curve specified in the device tree is linear or not and set the corresponding property accordingly. This makes the scale type available to userspace via the 'scale' sysfs attribute.
To determine if a curve is linear it is compared to a interpolated linear curve between min and max brightness. The curve is considered linear if no value deviates more than +/-5% of ${brightness_range} from their interpolated value.
---
Changes in v3:
- none
Changes in v2:
- use 128 (power of two) instead of 100 as factor for the slope
- add comment about max quantization error
- added Daniel's 'Acked-by' tag
--- drivers/video/backlight/pwm_bl.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/video/backlight/pwm_bl.c +30 -0
@@ -404,6 +404,31 @@ int pwm_backlight_brightness_default(struct device *dev, }#endif +static bool pwm_backlight_is_linear (struct platform_pwm_backlight_data *data) +{ +unsigned int nlevels = data->max_brightness +1 ; +unsigned int min_val = data->levels[0 ]; +unsigned int max_val = data->levels[nlevels -1 ]; +/* +* Multiplying by 128 means that even in pathological cases such +* as (max_val - min_val) == nlevels the error at max_val is less +* than 1%. +*/ +unsigned int slope = (128 * (max_val - min_val)) / nlevels; +unsigned int margin = (max_val - min_val) /20 ;/* 5% */ +int i; + +for (i =1 ; i < nlevels; i++) { +unsigned int linear_value = min_val + ((i * slope) /128 ); +unsigned int delta =abs (linear_value - data->levels[i]); + +if (delta > margin) +return false; + } + +return true; +} +static int pwm_backlight_initial_power_state (const struct pwm_bl_data *pb) {struct device_node *node = pb->dev->of_node;
@@ -567,6 +592,11 @@ static int pwm_backlight_probe(struct platform_device *pdev) pb->levels = data->levels; } + +if (pwm_backlight_is_linear (data)) + props.scale =BACKLIGHT_SCALE_LINEAR ; +else + props.scale =BACKLIGHT_SCALE_NON_LINEAR ; }else if (!data->max_brightness) {/* * If no brightness levels are provided and max_brightness is
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Lee Jones
AppliedRe: [PATCH v3 4/4] backlight: pwm_bl: Set scale type for brightness curves specified in the DT
Quoted 15 lines · Matthias Kaehlcke
Check if a brightness curve specified in the device tree is linear or not and set the corresponding property accordingly. This makes the scale type available to userspace via the 'scale' sysfs attribute.
To determine if a curve is linear it is compared to a interpolated linear curve between min and max brightness. The curve is considered linear if no value deviates more than +/-5% of ${brightness_range} from their interpolated value.
Signed-off-by Matthias Kaehlcke <[email protected]>Acked-by Daniel Thompson <[email protected]>---
Changes in v3:
- none
Quoted 7 lines
Changes in v2:
- use 128 (power of two) instead of 100 as factor for the slope
- add comment about max quantization error
- added Daniel's 'Acked-by' tag--- drivers/video/backlight/pwm_bl.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
Applied, thanks.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 19 lines · Matthias Kaehlcke
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 is currently opaque to userspace, so userspace often relies on 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 a new sysfs attribute.
Matthias Kaehlcke (4):
MAINTAINERS: Add entry for stable backlight sysfs ABI documentation
backlight: Expose brightness curve type through sysfs
backlight:pwm_bl: Set scale type for CIE 1931 curves
backlight:pwm_bl: Set scale type for brightness curves specified in
the DT
Quoted 7 lines
.../ABI/testing/sysfs-class-backlight | 26 ++++++++++++++ MAINTAINERS | 2 ++ drivers/video/backlight/backlight.c | 19 ++++++++++ drivers/video/backlight/pwm_bl.c | 35 ++++++++++++++++++- include/linux/backlight.h | 8 +++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-class-backlight
ping, any comments on v3?
Thanks
Matthias
Quoted 28 lines · Matthias Kaehlcke
Quoted 19 lines · Matthias Kaehlcke
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 is currently opaque to userspace, so userspace often relies on 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 a new sysfs attribute.
Matthias Kaehlcke (4):
MAINTAINERS: Add entry for stable backlight sysfs ABI documentation
backlight: Expose brightness curve type through sysfs
backlight:pwm_bl: Set scale type for CIE 1931 curves
backlight:pwm_bl: Set scale type for brightness curves specified in
the DTQuoted 7 lines
.../ABI/testing/sysfs-class-backlight | 26 ++++++++++++++ MAINTAINERS | 2 ++ drivers/video/backlight/backlight.c | 19 ++++++++++ drivers/video/backlight/pwm_bl.c | 35 ++++++++++++++++++- include/linux/backlight.h | 8 +++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-class-backlight
Quoted 1 line
ping, any comments on v3?
Looks like PATCH 2/4 still needs seeing to.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 30 lines · Lee Jones
Quoted 28 lines · Matthias Kaehlcke
Quoted 26 lines · Matthias Kaehlcke
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 is currently opaque to userspace, so userspace often relies on 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 a new sysfs attribute.
Matthias Kaehlcke (4):
MAINTAINERS: Add entry for stable backlight sysfs ABI documentation
backlight: Expose brightness curve type through sysfs
backlight:pwm_bl: Set scale type for CIE 1931 curves
backlight:pwm_bl: Set scale type for brightness curves specified in
the DT.../ABI/testing/sysfs-class-backlight | 26 ++++++++++++++ MAINTAINERS | 2 ++ drivers/video/backlight/backlight.c | 19 ++++++++++ drivers/video/backlight/pwm_bl.c | 35 ++++++++++++++++++- include/linux/backlight.h | 8 +++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-class-backlight
Quoted 3 lines
Quoted 1 line
ping, any comments on v3?
Looks like PATCH 2/4 still needs seeing to.
The patch currently doesn't have any comments.
Do you see any specific things that need improvement? If so, could you comment on the patch?
Thanks
Matthias
Quoted 31 lines · Matthias Kaehlcke
Quoted 30 lines · Lee Jones
Quoted 28 lines · Matthias Kaehlcke
Quoted 26 lines · Matthias Kaehlcke
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 is currently opaque to userspace, so userspace often relies on 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 a new sysfs attribute.
Matthias Kaehlcke (4):
MAINTAINERS: Add entry for stable backlight sysfs ABI documentation
backlight: Expose brightness curve type through sysfs
backlight:pwm_bl: Set scale type for CIE 1931 curves
backlight:pwm_bl: Set scale type for brightness curves specified in
the DT.../ABI/testing/sysfs-class-backlight | 26 ++++++++++++++ MAINTAINERS | 2 ++ drivers/video/backlight/backlight.c | 19 ++++++++++ drivers/video/backlight/pwm_bl.c | 35 ++++++++++++++++++- include/linux/backlight.h | 8 +++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-class-backlight
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
ping, any comments on v3?
Looks like PATCH 2/4 still needs seeing to.
The patch currently doesn't have any comments.
Do you see any specific things that need improvement? If so, could you comment on the patch?
It needs Daniel T's Ack.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog