Pull backlight updates from Lee Jones: "Core Frameworks - Obtain scale type through sysfs New Functionality: - Provide Device Tree functionality in rave-sp-backlight - Calculate if scale type is (non-)linear in pwm_bl Fix-ups: - Simplify code in lm3630a_bl - Trivial rename/whitespace/typo fixes in lms283gf05 - Remove superfluous NULL check in tosa_lcd - Fix power state initialisation in gpio_backlight - List supported file in MAINTAINERS Bug Fixes: - Kconfig - default to not building unless requested in {LED,BACKLIGHT}_CLASS_DEVICE" * tag 'backlight-next-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight: backlight: pwm_bl: Set scale type for brightness curves specified in the DT backlight: pwm_bl: Set scale type for CIE 1931 curves backlight: Expose brightness curve type through sysfs MAINTAINERS: Add entry for stable backlight sysfs ABI documentation backlight: gpio-backlight: Correct initial power state handling video: backlight: tosa_lcd: drop check because i2c_unregister_device() is NULL safe video: backlight: Drop default m for {LCD,BACKLIGHT_CLASS_DEVICE} backlight: lms283gf05: Fix a typo in the description passed to 'devm_gpio_request_one()' backlight: lm3630a: Switch to use fwnode_property_count_uXX() backlight: rave-sp: Leave initial state and register with correct device
Unified · Split
| @@ -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. | ||
| @@ -2921,6 +2921,8 @@ F: drivers/video/backlight/ · 2920 unmodified lines | |||
| 2921 | F: include/linux/backlight.h | 2921 | F: include/linux/backlight.h |
| 2922 | F: include/linux/pwm_backlight.h | 2922 | F: include/linux/pwm_backlight.h |
| 2923 | F: Documentation/devicetree/bindings/leds/backlight | 2923 | F: Documentation/devicetree/bindings/leds/backlight |
| 2924 | F: Documentation/ABI/stable/sysfs-class-backlight | ||
| 2925 | F: Documentation/ABI/testing/sysfs-class-backlight | ||
| 2924 | 2926 | ||
| 2925 | BATMAN ADVANCED | 2927 | BATMAN ADVANCED |
| 2926 | M: Marek Lindner <mareklindner@neomailbox.ch> | 2928 | M: Marek Lindner <mareklindner@neomailbox.ch> |
| @@ -10,7 +10,6 @@ menu "Backlight & LCD device support" · 9 unmodified lines | |||
| 10 | # | 10 | # |
| 11 | config LCD_CLASS_DEVICE | 11 | config LCD_CLASS_DEVICE |
| 12 | tristate "Lowlevel LCD controls" | 12 | tristate "Lowlevel LCD controls" |
| 13 | default m | ||
| 14 | help | 13 | help |
| 15 | This framework adds support for low-level control of LCD. | 14 | This framework adds support for low-level control of LCD. |
| 16 | Some framebuffer devices connect to platform-specific LCD modules | 15 | Some framebuffer devices connect to platform-specific LCD modules |
| @@ -143,7 +142,6 @@ endif # LCD_CLASS_DEVICE · 126 unmodified lines | |||
| 143 | # | 142 | # |
| 144 | config BACKLIGHT_CLASS_DEVICE | 143 | config BACKLIGHT_CLASS_DEVICE |
| 145 | tristate "Lowlevel Backlight controls" | 144 | tristate "Lowlevel Backlight controls" |
| 146 | default m | ||
| 147 | help | 145 | help |
| 148 | This framework adds support for low-level control of the LCD | 146 | This framework adds support for low-level control of the LCD |
| 149 | backlight. This includes support for brightness and power. | 147 | backlight. This includes support for brightness and power. |
| @@ -32,6 +32,12 @@ static const char *const backlight_types[] = { · 31 unmodified lines | |||
| 32 | [BACKLIGHT_FIRMWARE] = "firmware", | 32 | [BACKLIGHT_FIRMWARE] = "firmware", |
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| 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 | |||
| 35 | #if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \ | 41 | #if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \ |
| 36 | defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)) | 42 | defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)) |
| 37 | /* This callback gets called when something important happens inside a | 43 | /* 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 | |||
| 246 | } | 252 | } |
| 247 | static DEVICE_ATTR_RO(actual_brightness); | 253 | static DEVICE_ATTR_RO(actual_brightness); |
| 248 | 254 | ||
| 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 | |||
| 249 | static struct class *backlight_class; | 267 | static struct class *backlight_class; |
| 250 | 268 | ||
| 251 | #ifdef CONFIG_PM_SLEEP | 269 | #ifdef CONFIG_PM_SLEEP |
| @@ -292,6 +310,7 @@ static struct attribute *bl_device_attrs[] = { · 40 unmodified lines | |||
| 292 | &dev_attr_brightness.attr, | 310 | &dev_attr_brightness.attr, |
| 293 | &dev_attr_actual_brightness.attr, | 311 | &dev_attr_actual_brightness.attr, |
| 294 | &dev_attr_max_brightness.attr, | 312 | &dev_attr_max_brightness.attr, |
| 313 | &dev_attr_scale.attr, | ||
| 295 | &dev_attr_type.attr, | 314 | &dev_attr_type.attr, |
| 296 | NULL, | 315 | NULL, |
| 297 | }; | 316 | }; |
| @@ -59,13 +59,11 @@ static int gpio_backlight_probe_dt(struct platform_device *pdev, · 58 unmodified lines | |||
| 59 | struct gpio_backlight *gbl) | 59 | struct gpio_backlight *gbl) |
| 60 | { | 60 | { |
| 61 | struct device *dev = &pdev->dev; | 61 | struct device *dev = &pdev->dev; |
| 62 | enum gpiod_flags flags; | ||
| 63 | int ret; | 62 | int ret; |
| 64 | 63 | ||
| 65 | gbl->def_value = device_property_read_bool(dev, "default-on"); | 64 | gbl->def_value = device_property_read_bool(dev, "default-on"); |
| 66 | flags = gbl->def_value ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; | ||
| 67 | 65 | ||
| 68 | gbl->gpiod = devm_gpiod_get(dev, NULL, flags); | 66 | gbl->gpiod = devm_gpiod_get(dev, NULL, GPIOD_ASIS); |
| 69 | if (IS_ERR(gbl->gpiod)) { | 67 | if (IS_ERR(gbl->gpiod)) { |
| 70 | ret = PTR_ERR(gbl->gpiod); | 68 | ret = PTR_ERR(gbl->gpiod); |
| 71 | 69 | ||
| @@ -79,6 +77,22 @@ static int gpio_backlight_probe_dt(struct platform_device *pdev, · 7 unmodified lines | |||
| 79 | return 0; | 77 | return 0; |
| 80 | } | 78 | } |
| 81 | 79 | ||
| 80 | static int gpio_backlight_initial_power_state(struct gpio_backlight *gbl) | ||
| 81 | { | ||
| 82 | struct device_node *node = gbl->dev->of_node; | ||
| 83 | |||
| 84 | /* Not booted with device tree or no phandle link to the node */ | ||
| 85 | if (!node || !node->phandle) | ||
| 86 | return gbl->def_value ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; | ||
| 87 | |||
| 88 | /* if the enable GPIO is disabled, do not enable the backlight */ | ||
| 89 | if (gpiod_get_value_cansleep(gbl->gpiod) == 0) | ||
| 90 | return FB_BLANK_POWERDOWN; | ||
| 91 | |||
| 92 | return FB_BLANK_UNBLANK; | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 82 | static int gpio_backlight_probe(struct platform_device *pdev) | 96 | static int gpio_backlight_probe(struct platform_device *pdev) |
| 83 | { | 97 | { |
| 84 | struct gpio_backlight_platform_data *pdata = | 98 | struct gpio_backlight_platform_data *pdata = |
| @@ -136,7 +150,9 @@ static int gpio_backlight_probe(struct platform_device *pdev) · 51 unmodified lines | |||
| 136 | return PTR_ERR(bl); | 150 | return PTR_ERR(bl); |
| 137 | } | 151 | } |
| 138 | 152 | ||
| 139 | bl->props.brightness = gbl->def_value; | 153 | bl->props.power = gpio_backlight_initial_power_state(gbl); |
| 154 | bl->props.brightness = 1; | ||
| 155 | |||
| 140 | backlight_update_status(bl); | 156 | backlight_update_status(bl); |
| 141 | 157 | ||
| 142 | platform_set_drvdata(pdev, bl); | 158 | platform_set_drvdata(pdev, bl); |
| @@ -377,8 +377,7 @@ static int lm3630a_parse_led_sources(struct fwnode_handle *node, · 376 unmodified lines | |||
| 377 | u32 sources[LM3630A_NUM_SINKS]; | 377 | u32 sources[LM3630A_NUM_SINKS]; |
| 378 | int ret, num_sources, i; | 378 | int ret, num_sources, i; |
| 379 | 379 | ||
| 380 | num_sources = fwnode_property_read_u32_array(node, "led-sources", NULL, | 380 | num_sources = fwnode_property_count_u32(node, "led-sources"); |
| 381 | 0); | ||
| 382 | if (num_sources < 0) | 381 | if (num_sources < 0) |
| 383 | return default_led_sources; | 382 | return default_led_sources; |
| 384 | else if (num_sources > ARRAY_SIZE(sources)) | 383 | else if (num_sources > ARRAY_SIZE(sources)) |
| @@ -158,7 +158,7 @@ static int lms283gf05_probe(struct spi_device *spi) · 157 unmodified lines | |||
| 158 | ret = devm_gpio_request_one(&spi->dev, pdata->reset_gpio, | 158 | ret = devm_gpio_request_one(&spi->dev, pdata->reset_gpio, |
| 159 | GPIOF_DIR_OUT | (!pdata->reset_inverted ? | 159 | GPIOF_DIR_OUT | (!pdata->reset_inverted ? |
| 160 | GPIOF_INIT_HIGH : GPIOF_INIT_LOW), | 160 | GPIOF_INIT_HIGH : GPIOF_INIT_LOW), |
| 161 | "LMS285GF05 RESET"); | 161 | "LMS283GF05 RESET"); |
| 162 | if (ret) | 162 | if (ret) |
| 163 | return ret; | 163 | return ret; |
| 164 | } | 164 | } |
| @@ -387,6 +387,31 @@ int pwm_backlight_brightness_default(struct device *dev, · 386 unmodified lines | |||
| 387 | } | 387 | } |
| 388 | #endif | 388 | #endif |
| 389 | 389 | ||
| 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 | |||
| 390 | static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) | 415 | static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) |
| 391 | { | 416 | { |
| 392 | struct device_node *node = pb->dev->of_node; | 417 | struct device_node *node = pb->dev->of_node; |
| @@ -536,6 +561,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) · 143 unmodified lines | |||
| 536 | goto err_alloc; | 561 | goto err_alloc; |
| 537 | } | 562 | } |
| 538 | 563 | ||
| 564 | memset(&props, 0, sizeof(struct backlight_properties)); | ||
| 565 | |||
| 539 | if (data->levels) { | 566 | if (data->levels) { |
| 540 | /* | 567 | /* |
| 541 | * For the DT case, only when brightness levels is defined | 568 | * For the DT case, only when brightness levels is defined |
| @@ -548,6 +575,11 @@ static int pwm_backlight_probe(struct platform_device *pdev) · 6 unmodified lines | |||
| 548 | 575 | ||
| 549 | pb->levels = data->levels; | 576 | pb->levels = data->levels; |
| 550 | } | 577 | } |
| 578 | |||
| 579 | if (pwm_backlight_is_linear(data)) | ||
| 580 | props.scale = BACKLIGHT_SCALE_LINEAR; | ||
| 581 | else | ||
| 582 | props.scale = BACKLIGHT_SCALE_NON_LINEAR; | ||
| 551 | } else if (!data->max_brightness) { | 583 | } else if (!data->max_brightness) { |
| 552 | /* | 584 | /* |
| 553 | * If no brightness levels are provided and max_brightness is | 585 | * If no brightness levels are provided and max_brightness is |
| @@ -574,6 +606,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) · 20 unmodified lines | |||
| 574 | 606 | ||
| 575 | pb->levels = data->levels; | 607 | pb->levels = data->levels; |
| 576 | } | 608 | } |
| 609 | |||
| 610 | props.scale = BACKLIGHT_SCALE_NON_LINEAR; | ||
| 577 | } else { | 611 | } else { |
| 578 | /* | 612 | /* |
| 579 | * That only happens for the non-DT case, where platform data | 613 | * That only happens for the non-DT case, where platform data |
| @@ -584,7 +618,6 @@ static int pwm_backlight_probe(struct platform_device *pdev) · 4 unmodified lines | |||
| 584 | 618 | ||
| 585 | pb->lth_brightness = data->lth_brightness * (state.period / pb->scale); | 619 | pb->lth_brightness = data->lth_brightness * (state.period / pb->scale); |
| 586 | 620 | ||
| 587 | memset(&props, 0, sizeof(struct backlight_properties)); | ||
| 588 | props.type = BACKLIGHT_RAW; | 621 | props.type = BACKLIGHT_RAW; |
| 589 | props.max_brightness = data->max_brightness; | 622 | props.max_brightness = data->max_brightness; |
| 590 | bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb, | 623 | bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb, |
| @@ -48,14 +48,20 @@ static int rave_sp_backlight_probe(struct platform_device *pdev) · 47 unmodified lines | |||
| 48 | struct device *dev = &pdev->dev; | 48 | struct device *dev = &pdev->dev; |
| 49 | struct backlight_device *bd; | 49 | struct backlight_device *bd; |
| 50 | 50 | ||
| 51 | bd = devm_backlight_device_register(dev, pdev->name, dev->parent, | 51 | bd = devm_backlight_device_register(dev, pdev->name, dev, |
| 52 | dev_get_drvdata(dev->parent), | 52 | dev_get_drvdata(dev->parent), |
| 53 | &rave_sp_backlight_ops, | 53 | &rave_sp_backlight_ops, |
| 54 | &rave_sp_backlight_props); | 54 | &rave_sp_backlight_props); |
| 55 | if (IS_ERR(bd)) | 55 | if (IS_ERR(bd)) |
| 56 | return PTR_ERR(bd); | 56 | return PTR_ERR(bd); |
| 57 | 57 | ||
| 58 | backlight_update_status(bd); | 58 | /* |
| 59 | * If there is a phandle pointing to the device node we can | ||
| 60 | * assume that another device will manage the status changes. | ||
| 61 | * If not we make sure the backlight is in a consistent state. | ||
| 62 | */ | ||
| 63 | if (!dev->of_node->phandle) | ||
| 64 | backlight_update_status(bd); | ||
| 59 | 65 | ||
| 60 | return 0; | 66 | return 0; |
| 61 | } | 67 | } |
| @@ -222,8 +222,7 @@ static int tosa_lcd_remove(struct spi_device *spi) · 221 unmodified lines | |||
| 222 | { | 222 | { |
| 223 | struct tosa_lcd_data *data = spi_get_drvdata(spi); | 223 | struct tosa_lcd_data *data = spi_get_drvdata(spi); |
| 224 | 224 | ||
| 225 | if (data->i2c) | 225 | i2c_unregister_device(data->i2c); |
| 226 | i2c_unregister_device(data->i2c); | ||
| 227 | 226 | ||
| 228 | tosa_lcd_tg_off(data); | 227 | tosa_lcd_tg_off(data); |
| 229 | 228 | ||
| @@ -46,6 +46,12 @@ enum backlight_notification { · 45 unmodified lines | |||
| 46 | BACKLIGHT_UNREGISTERED, | 46 | BACKLIGHT_UNREGISTERED, |
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | enum backlight_scale { | ||
| 50 | BACKLIGHT_SCALE_UNKNOWN = 0, | ||
| 51 | BACKLIGHT_SCALE_LINEAR, | ||
| 52 | BACKLIGHT_SCALE_NON_LINEAR, | ||
| 53 | }; | ||
| 54 | |||
| 49 | struct backlight_device; | 55 | struct backlight_device; |
| 50 | struct fb_info; | 56 | struct fb_info; |
| 51 | 57 | ||
| @@ -80,6 +86,8 @@ struct backlight_properties { · 28 unmodified lines | |||
| 80 | enum backlight_type type; | 86 | enum backlight_type type; |
| 81 | /* Flags used to signal drivers of state changes */ | 87 | /* Flags used to signal drivers of state changes */ |
| 82 | unsigned int state; | 88 | unsigned int state; |
| 89 | /* Type of the brightness scale (linear, non-linear, ...) */ | ||
| 90 | enum backlight_scale scale; | ||
| 83 | 91 | ||
| 84 | #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */ | 92 | #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */ |
| 85 | #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */ | 93 | #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */ |