Commit c0b64faf authored by Matthias Kaehlcke's avatar Matthias Kaehlcke Committed by Lee Jones

backlight: pwm_bl: Set scale type for brightness curves specified in the DT

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: default avatarMatthias Kaehlcke <mka@chromium.org>
Acked-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent 511a2046
...@@ -387,6 +387,31 @@ int pwm_backlight_brightness_default(struct device *dev, ...@@ -387,6 +387,31 @@ int pwm_backlight_brightness_default(struct device *dev,
} }
#endif #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) static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb)
{ {
struct device_node *node = pb->dev->of_node; struct device_node *node = pb->dev->of_node;
...@@ -550,6 +575,11 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -550,6 +575,11 @@ static int pwm_backlight_probe(struct platform_device *pdev)
pb->levels = data->levels; 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) { } else if (!data->max_brightness) {
/* /*
* If no brightness levels are provided and max_brightness is * If no brightness levels are provided and max_brightness is
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment