Lines Matching +full:brightness +full:- +full:levels
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2015-2019 Texas Instruments Incorporated - http://www.ti.com/
20 unsigned int *levels; member
30 if (priv->levels) in led_bl_set_brightness()
31 bkl_brightness = priv->levels[level]; in led_bl_set_brightness()
35 for (i = 0; i < priv->nb_leds; i++) in led_bl_set_brightness()
36 led_set_brightness(priv->leds[i], bkl_brightness); in led_bl_set_brightness()
38 priv->enabled = true; in led_bl_set_brightness()
45 if (!priv->enabled) in led_bl_power_off()
48 for (i = 0; i < priv->nb_leds; i++) in led_bl_power_off()
49 led_set_brightness(priv->leds[i], LED_OFF); in led_bl_power_off()
51 priv->enabled = false; in led_bl_power_off()
57 int brightness = backlight_get_brightness(bl); in led_bl_update_status() local
59 if (brightness > 0) in led_bl_update_status()
60 led_bl_set_brightness(priv, brightness); in led_bl_update_status()
75 struct device_node *node = dev->of_node; in led_bl_get_leds()
83 return -EINVAL; in led_bl_get_leds()
89 return -EINVAL; in led_bl_get_leds()
95 return -ENOMEM; in led_bl_get_leds()
103 /* check that the LEDs all have the same brightness range */ in led_bl_get_leds()
104 max_brightness = leds[0]->max_brightness; in led_bl_get_leds()
106 if (max_brightness != leds[i]->max_brightness) { in led_bl_get_leds()
108 return -EINVAL; in led_bl_get_leds()
112 /* get the default brightness from the first LED from the list */ in led_bl_get_leds()
113 default_brightness = leds[0]->brightness; in led_bl_get_leds()
115 priv->nb_leds = nb_leds; in led_bl_get_leds()
116 priv->leds = leds; in led_bl_get_leds()
117 priv->max_brightness = max_brightness; in led_bl_get_leds()
118 priv->default_brightness = default_brightness; in led_bl_get_leds()
126 struct device_node *node = dev->of_node; in led_bl_parse_levels()
132 return -ENODEV; in led_bl_parse_levels()
134 num_levels = of_property_count_u32_elems(node, "brightness-levels"); in led_bl_parse_levels()
138 u32 *levels = NULL; in led_bl_parse_levels() local
140 levels = devm_kzalloc(dev, sizeof(u32) * num_levels, in led_bl_parse_levels()
142 if (!levels) in led_bl_parse_levels()
143 return -ENOMEM; in led_bl_parse_levels()
145 ret = of_property_read_u32_array(node, "brightness-levels", in led_bl_parse_levels()
146 levels, in led_bl_parse_levels()
152 * Try to map actual LED brightness to backlight brightness in led_bl_parse_levels()
155 db = priv->default_brightness; in led_bl_parse_levels()
157 if ((i && db > levels[i-1]) && db <= levels[i]) in led_bl_parse_levels()
160 priv->default_brightness = i; in led_bl_parse_levels()
161 priv->max_brightness = num_levels - 1; in led_bl_parse_levels()
162 priv->levels = levels; in led_bl_parse_levels()
164 dev_warn(dev, "Not enough levels defined\n"); in led_bl_parse_levels()
166 ret = of_property_read_u32(node, "default-brightness-level", &value); in led_bl_parse_levels()
167 if (!ret && value <= priv->max_brightness) in led_bl_parse_levels()
168 priv->default_brightness = value; in led_bl_parse_levels()
169 else if (!ret && value > priv->max_brightness) in led_bl_parse_levels()
170 dev_warn(dev, "Invalid default brightness. Ignoring it\n"); in led_bl_parse_levels()
181 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in led_bl_probe()
183 return -ENOMEM; in led_bl_probe()
187 priv->dev = &pdev->dev; in led_bl_probe()
189 ret = led_bl_get_leds(&pdev->dev, priv); in led_bl_probe()
193 ret = led_bl_parse_levels(&pdev->dev, priv); in led_bl_probe()
195 dev_err(&pdev->dev, "Failed to parse DT data\n"); in led_bl_probe()
201 props.max_brightness = priv->max_brightness; in led_bl_probe()
202 props.brightness = priv->default_brightness; in led_bl_probe()
203 props.power = (priv->default_brightness > 0) ? BACKLIGHT_POWER_OFF : in led_bl_probe()
205 priv->bl_dev = backlight_device_register(dev_name(&pdev->dev), in led_bl_probe()
206 &pdev->dev, priv, &led_bl_ops, &props); in led_bl_probe()
207 if (IS_ERR(priv->bl_dev)) { in led_bl_probe()
208 dev_err(&pdev->dev, "Failed to register backlight\n"); in led_bl_probe()
209 return PTR_ERR(priv->bl_dev); in led_bl_probe()
212 for (i = 0; i < priv->nb_leds; i++) { in led_bl_probe()
213 mutex_lock(&priv->leds[i]->led_access); in led_bl_probe()
214 led_sysfs_disable(priv->leds[i]); in led_bl_probe()
215 mutex_unlock(&priv->leds[i]->led_access); in led_bl_probe()
218 backlight_update_status(priv->bl_dev); in led_bl_probe()
226 struct backlight_device *bl = priv->bl_dev; in led_bl_remove()
232 for (i = 0; i < priv->nb_leds; i++) in led_bl_remove()
233 led_sysfs_enable(priv->leds[i]); in led_bl_remove()
237 { .compatible = "led-backlight" },
245 .name = "led-backlight",
256 MODULE_ALIAS("platform:led-backlight");