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().
79 [BACKLIGHT_SCALE_NON_LINEAR] = "non-linear",
101 int node = evdata->info->node; in fb_notifier_callback()
109 mutex_lock(&bd->ops_lock); in fb_notifier_callback()
111 if (!bd->ops) in fb_notifier_callback()
113 if (bd->ops->check_fb && !bd->ops->check_fb(bd, evdata->info)) in fb_notifier_callback()
116 fb_blank = *(int *)evdata->data; in fb_notifier_callback()
117 if (fb_blank == FB_BLANK_UNBLANK && !bd->fb_bl_on[node]) { in fb_notifier_callback()
118 bd->fb_bl_on[node] = true; in fb_notifier_callback()
119 if (!bd->use_count++) { in fb_notifier_callback()
120 bd->props.state &= ~BL_CORE_FBBLANK; in fb_notifier_callback()
121 bd->props.fb_blank = FB_BLANK_UNBLANK; in fb_notifier_callback()
124 } else if (fb_blank != FB_BLANK_UNBLANK && bd->fb_bl_on[node]) { in fb_notifier_callback()
125 bd->fb_bl_on[node] = false; in fb_notifier_callback()
126 if (!(--bd->use_count)) { in fb_notifier_callback()
127 bd->props.state |= BL_CORE_FBBLANK; in fb_notifier_callback()
128 bd->props.fb_blank = fb_blank; in fb_notifier_callback()
133 mutex_unlock(&bd->ops_lock); in fb_notifier_callback()
139 memset(&bd->fb_notif, 0, sizeof(bd->fb_notif)); in backlight_register_fb()
140 bd->fb_notif.notifier_call = fb_notifier_callback; in backlight_register_fb()
142 return fb_register_client(&bd->fb_notif); in backlight_register_fb()
147 fb_unregister_client(&bd->fb_notif); in backlight_unregister_fb()
177 kobject_uevent_env(&bd->dev.kobj, KOBJ_CHANGE, envp); in backlight_generate_event()
178 sysfs_notify(&bd->dev.kobj, NULL, "actual_brightness"); in backlight_generate_event()
186 return sprintf(buf, "%d\n", bd->props.power); in bl_power_show()
200 rc = -ENXIO; in bl_power_store()
201 mutex_lock(&bd->ops_lock); in bl_power_store()
202 if (bd->ops) { in bl_power_store()
204 if (bd->props.power != power) { in bl_power_store()
205 old_power = bd->props.power; in bl_power_store()
206 bd->props.power = power; in bl_power_store()
209 bd->props.power = old_power; in bl_power_store()
216 mutex_unlock(&bd->ops_lock); in bl_power_store()
227 return sprintf(buf, "%d\n", bd->props.brightness); in brightness_show()
231 unsigned long brightness) in backlight_device_set_brightness() argument
233 int rc = -ENXIO; in backlight_device_set_brightness()
235 mutex_lock(&bd->ops_lock); in backlight_device_set_brightness()
236 if (bd->ops) { in backlight_device_set_brightness()
237 if (brightness > bd->props.max_brightness) in backlight_device_set_brightness()
238 rc = -EINVAL; in backlight_device_set_brightness()
240 pr_debug("set brightness to %lu\n", brightness); in backlight_device_set_brightness()
241 bd->props.brightness = brightness; in backlight_device_set_brightness()
245 mutex_unlock(&bd->ops_lock); in backlight_device_set_brightness()
258 unsigned long brightness; in brightness_store() local
260 rc = kstrtoul(buf, 0, &brightness); in brightness_store()
264 rc = backlight_device_set_brightness(bd, brightness); in brightness_store()
268 static DEVICE_ATTR_RW(brightness);
275 return sprintf(buf, "%s\n", backlight_types[bd->props.type]); in type_show()
284 return sprintf(buf, "%d\n", bd->props.max_brightness); in max_brightness_show()
291 int rc = -ENXIO; in actual_brightness_show()
294 mutex_lock(&bd->ops_lock); in actual_brightness_show()
295 if (bd->ops && bd->ops->get_brightness) { in actual_brightness_show()
296 rc = bd->ops->get_brightness(bd); in actual_brightness_show()
300 rc = sprintf(buf, "%d\n", bd->props.brightness); in actual_brightness_show()
302 mutex_unlock(&bd->ops_lock); in actual_brightness_show()
313 if (WARN_ON(bd->props.scale > BACKLIGHT_SCALE_NON_LINEAR)) in scale_show()
316 return sprintf(buf, "%s\n", backlight_scale_types[bd->props.scale]); in scale_show()
327 mutex_lock(&bd->ops_lock); in backlight_suspend()
328 if (bd->ops && bd->ops->options & BL_CORE_SUSPENDRESUME) { in backlight_suspend()
329 bd->props.state |= BL_CORE_SUSPENDED; in backlight_suspend()
332 mutex_unlock(&bd->ops_lock); in backlight_suspend()
341 mutex_lock(&bd->ops_lock); in backlight_resume()
342 if (bd->ops && bd->ops->options & BL_CORE_SUSPENDRESUME) { in backlight_resume()
343 bd->props.state &= ~BL_CORE_SUSPENDED; in backlight_resume()
346 mutex_unlock(&bd->ops_lock); in backlight_resume()
373 * backlight_force_update - tell the backlight subsystem that hardware state
381 * a hot-key. The updated brightness is read using get_brightness() and the
382 * brightness value is reported using an uevent.
387 int brightness; in backlight_force_update() local
389 mutex_lock(&bd->ops_lock); in backlight_force_update()
390 if (bd->ops && bd->ops->get_brightness) { in backlight_force_update()
391 brightness = bd->ops->get_brightness(bd); in backlight_force_update()
392 if (brightness >= 0) in backlight_force_update()
393 bd->props.brightness = brightness; in backlight_force_update()
395 dev_err(&bd->dev, in backlight_force_update()
396 "Could not update brightness from device: %pe\n", in backlight_force_update()
397 ERR_PTR(brightness)); in backlight_force_update()
399 mutex_unlock(&bd->ops_lock); in backlight_force_update()
404 /* deprecated - use devm_backlight_device_register() */
416 return ERR_PTR(-ENOMEM); in backlight_device_register()
418 mutex_init(&new_bd->update_lock); in backlight_device_register()
419 mutex_init(&new_bd->ops_lock); in backlight_device_register()
421 new_bd->dev.class = backlight_class; in backlight_device_register()
422 new_bd->dev.parent = parent; in backlight_device_register()
423 new_bd->dev.release = bl_device_release; in backlight_device_register()
424 dev_set_name(&new_bd->dev, "%s", name); in backlight_device_register()
425 dev_set_drvdata(&new_bd->dev, devdata); in backlight_device_register()
429 memcpy(&new_bd->props, props, in backlight_device_register()
431 if (props->type <= 0 || props->type >= BACKLIGHT_TYPE_MAX) { in backlight_device_register()
433 new_bd->props.type = BACKLIGHT_RAW; in backlight_device_register()
436 new_bd->props.type = BACKLIGHT_RAW; in backlight_device_register()
439 rc = device_register(&new_bd->dev); in backlight_device_register()
441 put_device(&new_bd->dev); in backlight_device_register()
447 device_unregister(&new_bd->dev); in backlight_device_register()
451 new_bd->ops = ops; in backlight_device_register()
461 list_add(&new_bd->entry, &backlight_dev_list); in backlight_device_register()
471 /** backlight_device_get_by_type - find first backlight device of a type
487 if (bd->props.type == type) { in backlight_device_get_by_type()
499 * backlight_device_get_by_name - Get backlight device by name
519 /* deprecated - use devm_backlight_device_unregister() */
526 list_del(&bd->entry); in backlight_device_unregister()
539 mutex_lock(&bd->ops_lock); in backlight_device_unregister()
540 bd->ops = NULL; in backlight_device_unregister()
541 mutex_unlock(&bd->ops_lock); in backlight_device_unregister()
544 device_unregister(&bd->dev); in backlight_device_unregister()
564 * backlight_register_notifier - get notified of backlight (un)registration
581 * backlight_unregister_notifier - unregister a backlight notifier
598 * devm_backlight_device_register - register a new backlight device
624 return ERR_PTR(-ENOMEM); in devm_backlight_device_register()
640 * devm_backlight_device_unregister - unregister backlight device
662 return dev->parent && dev->parent->of_node == data; in of_parent_match()
666 * of_find_backlight_by_node() - find backlight device by device-tree node
667 * @node: device-tree node of the backlight device
696 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in of_find_backlight()
697 np = of_parse_phandle(dev->of_node, "backlight", 0); in of_find_backlight()
702 return ERR_PTR(-EPROBE_DEFER); in of_find_backlight()
713 put_device(&bd->dev); in devm_backlight_release()
717 * devm_of_find_backlight - find backlight for a device
728 * Error pointer -EPROBE_DEFER if the DT property is set, but no backlight
761 backlight_class->dev_groups = bl_device_groups; in backlight_class_init()
762 backlight_class->pm = &backlight_class_dev_pm_ops; in backlight_class_init()