Skip to content

Commit c0b64fa

Browse files
mkaehlckeLee Jones
authored andcommitted
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: Matthias Kaehlcke <mka@chromium.org> Acked-by: Daniel Thompson <daniel.thompson@linaro.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 511a204 commit c0b64fa

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎drivers/video/backlight/pwm_bl.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,31 @@ int pwm_backlight_brightness_default(struct device *dev,
387387
}
388388
#endif
389389

390+
static bool pwm_backlight_is_linear(struct platform_pwm_backlight_data *data)
391+
{
392+
unsigned int nlevels = data->max_brightness + 1;
393+
unsigned int min_val = data->levels[0];
394+
unsigned int max_val = data->levels[nlevels - 1];
395+
/*
396+
* Multiplying by 128 means that even in pathological cases such
397+
* as (max_val - min_val) == nlevels the error at max_val is less
398+
* than 1%.
399+
*/
400+
unsigned int slope = (128 * (max_val - min_val)) / nlevels;
401+
unsigned int margin = (max_val - min_val) / 20; /* 5% */
402+
int i;
403+
404+
for (i = 1; i < nlevels; i++) {
405+
unsigned int linear_value = min_val + ((i * slope) / 128);
406+
unsigned int delta = abs(linear_value - data->levels[i]);
407+
408+
if (delta > margin)
409+
return false;
410+
}
411+
412+
return true;
413+
}
414+
390415
static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb)
391416
{
392417
struct device_node *node = pb->dev->of_node;
@@ -550,6 +575,11 @@ static int pwm_backlight_probe(struct platform_device *pdev)
550575

551576
pb->levels = data->levels;
552577
}
578+
579+
if (pwm_backlight_is_linear(data))
580+
props.scale = BACKLIGHT_SCALE_LINEAR;
581+
else
582+
props.scale = BACKLIGHT_SCALE_NON_LINEAR;
553583
} else if (!data->max_brightness) {
554584
/*
555585
* If no brightness levels are provided and max_brightness is

0 commit comments

Comments
 (0)