History

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.

Matthias Kaehlcke committed 7 years ago

Commit c0b64fa1 parent 511a2041 file · +30 −0Browse files

Unified · Split

drivers/video/backlight/pwm_bl.c+30−0
@@ -387,6 +387,31 @@ int pwm_backlight_brightness_default(struct device *dev, · 386 unmodified lines
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) · 157 unmodified lines
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

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