Lines Matching +full:brightness +full:- +full:level

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2003,2004 Hewlett-Packard Company
33 * When the core detect changes in for example brightness or power state
39 * - brightness R/W, set the requested brightness level
40 * - actual_brightness RO, the brightness level used by the HW
41 * - max_brightness RO, the maximum brightness level supported
43 * See Documentation/ABI/stable/sysfs-class-backlight for the full list.
47 * a hot-key or some other platform or firmware specific way.
51 * brightness, thus providing user-space access to the actual level
54 * When the backlight changes this is reported to user-space using
56 * When brightness is set by platform specific means, for example
57 * a hot-key to adjust backlight, the driver must notify the backlight
58 * core that brightness has changed using backlight_force_update().
78 [BACKLIGHT_SCALE_NON_LINEAR] = "non-linear",
100 struct fb_info *info = evdata->info; in fb_notifier_callback()
102 int node = info->node; in fb_notifier_callback()
110 mutex_lock(&bd->ops_lock); in fb_notifier_callback()
112 if (!bd->ops) in fb_notifier_callback()
114 if (bd->ops->controls_device && !bd->ops->controls_device(bd, info->device)) in fb_notifier_callback()
119 fb_blank = *(int *)evdata->data; in fb_notifier_callback()
120 if (fb_blank == FB_BLANK_UNBLANK && !bd->fb_bl_on[node]) { in fb_notifier_callback()
121 bd->fb_bl_on[node] = true; in fb_notifier_callback()
122 if (!bd->use_count++) { in fb_notifier_callback()
123 bd->props.state &= ~BL_CORE_FBBLANK; in fb_notifier_callback()
126 } else if (fb_blank != FB_BLANK_UNBLANK && bd->fb_bl_on[node]) { in fb_notifier_callback()
127 bd->fb_bl_on[node] = false; in fb_notifier_callback()
128 if (!(--bd->use_count)) { in fb_notifier_callback()
129 bd->props.state |= BL_CORE_FBBLANK; in fb_notifier_callback()
134 mutex_unlock(&bd->ops_lock); in fb_notifier_callback()
140 memset(&bd->fb_notif, 0, sizeof(bd->fb_notif)); in backlight_register_fb()
141 bd->fb_notif.notifier_call = fb_notifier_callback; in backlight_register_fb()
143 return fb_register_client(&bd->fb_notif); in backlight_register_fb()
148 fb_unregister_client(&bd->fb_notif); in backlight_unregister_fb()
178 kobject_uevent_env(&bd->dev.kobj, KOBJ_CHANGE, envp); in backlight_generate_event()
179 sysfs_notify(&bd->dev.kobj, NULL, "actual_brightness"); in backlight_generate_event()
187 return sprintf(buf, "%d\n", bd->props.power); in bl_power_show()
201 rc = -ENXIO; in bl_power_store()
202 mutex_lock(&bd->ops_lock); in bl_power_store()
203 if (bd->ops) { in bl_power_store()
205 if (bd->props.power != power) { in bl_power_store()
206 old_power = bd->props.power; in bl_power_store()
207 bd->props.power = power; in bl_power_store()
210 bd->props.power = old_power; in bl_power_store()
217 mutex_unlock(&bd->ops_lock); in bl_power_store()
228 return sprintf(buf, "%d\n", bd->props.brightness); in brightness_show()
232 unsigned long brightness) in backlight_device_set_brightness() argument
234 int rc = -ENXIO; in backlight_device_set_brightness()
236 mutex_lock(&bd->ops_lock); in backlight_device_set_brightness()
237 if (bd->ops) { in backlight_device_set_brightness()
238 if (brightness > bd->props.max_brightness) in backlight_device_set_brightness()
239 rc = -EINVAL; in backlight_device_set_brightness()
241 pr_debug("set brightness to %lu\n", brightness); in backlight_device_set_brightness()
242 bd->props.brightness = brightness; in backlight_device_set_brightness()
246 mutex_unlock(&bd->ops_lock); in backlight_device_set_brightness()
259 unsigned long brightness; in brightness_store() local
261 rc = kstrtoul(buf, 0, &brightness); in brightness_store()
265 rc = backlight_device_set_brightness(bd, brightness); in brightness_store()
269 static DEVICE_ATTR_RW(brightness);
276 return sprintf(buf, "%s\n", backlight_types[bd->props.type]); in type_show()
285 return sprintf(buf, "%d\n", bd->props.max_brightness); in max_brightness_show()
292 int rc = -ENXIO; in actual_brightness_show()
295 mutex_lock(&bd->ops_lock); in actual_brightness_show()
296 if (bd->ops && bd->ops->get_brightness) { in actual_brightness_show()
297 rc = bd->ops->get_brightness(bd); in actual_brightness_show()
301 rc = sprintf(buf, "%d\n", bd->props.brightness); in actual_brightness_show()
303 mutex_unlock(&bd->ops_lock); in actual_brightness_show()
314 if (WARN_ON(bd->props.scale > BACKLIGHT_SCALE_NON_LINEAR)) in scale_show()
317 return sprintf(buf, "%s\n", backlight_scale_types[bd->props.scale]); in scale_show()
326 mutex_lock(&bd->ops_lock); in backlight_suspend()
327 if (bd->ops && bd->ops->options & BL_CORE_SUSPENDRESUME) { in backlight_suspend()
328 bd->props.state |= BL_CORE_SUSPENDED; in backlight_suspend()
331 mutex_unlock(&bd->ops_lock); in backlight_suspend()
340 mutex_lock(&bd->ops_lock); in backlight_resume()
341 if (bd->ops && bd->ops->options & BL_CORE_SUSPENDRESUME) { in backlight_resume()
342 bd->props.state &= ~BL_CORE_SUSPENDED; in backlight_resume()
345 mutex_unlock(&bd->ops_lock); in backlight_resume()
378 * backlight_force_update - tell the backlight subsystem that hardware state
386 * a hot-key. The updated brightness is read using get_brightness() and the
387 * brightness value is reported using an uevent.
392 int brightness; in backlight_force_update() local
394 mutex_lock(&bd->ops_lock); in backlight_force_update()
395 if (bd->ops && bd->ops->get_brightness) { in backlight_force_update()
396 brightness = bd->ops->get_brightness(bd); in backlight_force_update()
397 if (brightness >= 0) in backlight_force_update()
398 bd->props.brightness = brightness; in backlight_force_update()
400 dev_err(&bd->dev, in backlight_force_update()
401 "Could not update brightness from device: %pe\n", in backlight_force_update()
402 ERR_PTR(brightness)); in backlight_force_update()
404 mutex_unlock(&bd->ops_lock); in backlight_force_update()
409 /* deprecated - use devm_backlight_device_register() */
421 return ERR_PTR(-ENOMEM); in backlight_device_register()
423 mutex_init(&new_bd->update_lock); in backlight_device_register()
424 mutex_init(&new_bd->ops_lock); in backlight_device_register()
426 new_bd->dev.class = &backlight_class; in backlight_device_register()
427 new_bd->dev.parent = parent; in backlight_device_register()
428 new_bd->dev.release = bl_device_release; in backlight_device_register()
429 dev_set_name(&new_bd->dev, "%s", name); in backlight_device_register()
430 dev_set_drvdata(&new_bd->dev, devdata); in backlight_device_register()
434 memcpy(&new_bd->props, props, in backlight_device_register()
436 if (props->type <= 0 || props->type >= BACKLIGHT_TYPE_MAX) { in backlight_device_register()
438 new_bd->props.type = BACKLIGHT_RAW; in backlight_device_register()
441 new_bd->props.type = BACKLIGHT_RAW; in backlight_device_register()
444 rc = device_register(&new_bd->dev); in backlight_device_register()
446 put_device(&new_bd->dev); in backlight_device_register()
452 device_unregister(&new_bd->dev); in backlight_device_register()
456 new_bd->ops = ops; in backlight_device_register()
466 list_add(&new_bd->entry, &backlight_dev_list); in backlight_device_register()
473 /** backlight_device_get_by_type - find first backlight device of a type
489 if (bd->props.type == type) { in backlight_device_get_by_type()
501 * backlight_device_get_by_name - Get backlight device by name
521 /* deprecated - use devm_backlight_device_unregister() */
528 list_del(&bd->entry); in backlight_device_unregister()
538 mutex_lock(&bd->ops_lock); in backlight_device_unregister()
539 bd->ops = NULL; in backlight_device_unregister()
540 mutex_unlock(&bd->ops_lock); in backlight_device_unregister()
543 device_unregister(&bd->dev); in backlight_device_unregister()
563 * devm_backlight_device_register - register a new backlight device
589 return ERR_PTR(-ENOMEM); in devm_backlight_device_register()
605 * devm_backlight_device_unregister - unregister backlight device
627 return dev->parent && dev->parent->of_node == data; in of_parent_match()
631 * of_find_backlight_by_node() - find backlight device by device-tree node
632 * @node: device-tree node of the backlight device
661 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in of_find_backlight()
662 np = of_parse_phandle(dev->of_node, "backlight", 0); in of_find_backlight()
667 return ERR_PTR(-EPROBE_DEFER); in of_find_backlight()
678 put_device(&bd->dev); in devm_backlight_release()
682 * devm_of_find_backlight - find backlight for a device
693 * Error pointer -EPROBE_DEFER if the DT property is set, but no backlight