Lines Matching +full:retain +full:- +full:state +full:- +full:shutdown
1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright (C) 2005-2007 Richard Purdie <rpurdie@openedhand.com>
35 return sprintf(buf, "%u\n", led_cdev->brightness); in brightness_show()
42 unsigned long state; in brightness_store() local
45 mutex_lock(&led_cdev->led_access); in brightness_store()
48 ret = -EBUSY; in brightness_store()
52 ret = kstrtoul(buf, 10, &state); in brightness_store()
56 if (state == LED_OFF) in brightness_store()
58 led_set_brightness(led_cdev, state); in brightness_store()
59 flush_work(&led_cdev->set_brightness_work); in brightness_store()
63 mutex_unlock(&led_cdev->led_access); in brightness_store()
73 return sprintf(buf, "%u\n", led_cdev->max_brightness); in max_brightness_show()
112 if (led_cdev->brightness_hw_changed == -1) in brightness_hw_changed_show()
113 return -ENODATA; in brightness_hw_changed_show()
115 return sprintf(buf, "%u\n", led_cdev->brightness_hw_changed); in brightness_hw_changed_show()
122 struct device *dev = led_cdev->dev; in led_add_brightness_hw_changed()
131 led_cdev->brightness_hw_changed_kn = in led_add_brightness_hw_changed()
132 sysfs_get_dirent(dev->kobj.sd, "brightness_hw_changed"); in led_add_brightness_hw_changed()
133 if (!led_cdev->brightness_hw_changed_kn) { in led_add_brightness_hw_changed()
136 return -ENXIO; in led_add_brightness_hw_changed()
144 sysfs_put(led_cdev->brightness_hw_changed_kn); in led_remove_brightness_hw_changed()
145 device_remove_file(led_cdev->dev, &dev_attr_brightness_hw_changed); in led_remove_brightness_hw_changed()
150 if (WARN_ON(!led_cdev->brightness_hw_changed_kn)) in led_classdev_notify_brightness_hw_changed()
153 led_cdev->brightness_hw_changed = brightness; in led_classdev_notify_brightness_hw_changed()
154 sysfs_notify_dirent(led_cdev->brightness_hw_changed_kn); in led_classdev_notify_brightness_hw_changed()
168 * led_classdev_suspend - suspend an led_classdev.
173 led_cdev->flags |= LED_SUSPENDED; in led_classdev_suspend()
175 flush_work(&led_cdev->set_brightness_work); in led_classdev_suspend()
180 * led_classdev_resume - resume an led_classdev.
185 led_set_brightness_nopm(led_cdev, led_cdev->brightness); in led_classdev_resume()
187 if (led_cdev->flash_resume) in led_classdev_resume()
188 led_cdev->flash_resume(led_cdev); in led_classdev_resume()
190 led_cdev->flags &= ~LED_SUSPENDED; in led_classdev_resume()
199 if (led_cdev->flags & LED_CORE_SUSPENDRESUME) in led_suspend()
209 if (led_cdev->flags & LED_CORE_SUSPENDRESUME) in led_resume()
219 * of_led_get() - request a LED device via the LED framework
224 * property of a device tree node or a negative error-code on failure.
234 return ERR_PTR(-ENOENT); in of_led_get()
240 return ERR_PTR(-EPROBE_DEFER); in of_led_get()
244 if (!try_module_get(led_cdev->dev->parent->driver->owner)) in of_led_get()
245 return ERR_PTR(-ENODEV); in of_led_get()
252 * led_put() - release a LED device
257 module_put(led_cdev->dev->parent->driver->owner); in led_put()
269 * devm_of_led_get - Resource-managed request of a LED device
286 return ERR_PTR(-EINVAL); in devm_of_led_get()
288 led = of_led_get(dev->of_node, index); in devm_of_led_get()
296 return ERR_PTR(-ENOMEM); in devm_of_led_get()
322 return -ENOMEM; in led_classdev_next_name()
328 * led_classdev_register_ext - register a new object of led_classdev class
345 if (init_data->devname_mandatory && !init_data->devicename) { in led_classdev_register_ext()
347 return -EINVAL; in led_classdev_register_ext()
353 if (init_data->fwnode) { in led_classdev_register_ext()
354 fwnode_property_read_string(init_data->fwnode, in led_classdev_register_ext()
355 "linux,default-trigger", in led_classdev_register_ext()
356 &led_cdev->default_trigger); in led_classdev_register_ext()
358 if (fwnode_property_present(init_data->fwnode, in led_classdev_register_ext()
359 "retain-state-shutdown")) in led_classdev_register_ext()
360 led_cdev->flags |= LED_RETAIN_AT_SHUTDOWN; in led_classdev_register_ext()
363 proposed_name = led_cdev->name; in led_classdev_register_ext()
370 mutex_init(&led_cdev->led_access); in led_classdev_register_ext()
371 mutex_lock(&led_cdev->led_access); in led_classdev_register_ext()
372 led_cdev->dev = device_create_with_groups(leds_class, parent, 0, in led_classdev_register_ext()
373 led_cdev, led_cdev->groups, "%s", final_name); in led_classdev_register_ext()
374 if (IS_ERR(led_cdev->dev)) { in led_classdev_register_ext()
375 mutex_unlock(&led_cdev->led_access); in led_classdev_register_ext()
376 return PTR_ERR(led_cdev->dev); in led_classdev_register_ext()
378 if (init_data && init_data->fwnode) in led_classdev_register_ext()
379 device_set_node(led_cdev->dev, init_data->fwnode); in led_classdev_register_ext()
383 proposed_name, dev_name(led_cdev->dev)); in led_classdev_register_ext()
385 if (led_cdev->flags & LED_BRIGHT_HW_CHANGED) { in led_classdev_register_ext()
388 device_unregister(led_cdev->dev); in led_classdev_register_ext()
389 led_cdev->dev = NULL; in led_classdev_register_ext()
390 mutex_unlock(&led_cdev->led_access); in led_classdev_register_ext()
395 led_cdev->work_flags = 0; in led_classdev_register_ext()
397 init_rwsem(&led_cdev->trigger_lock); in led_classdev_register_ext()
400 led_cdev->brightness_hw_changed = -1; in led_classdev_register_ext()
404 list_add_tail(&led_cdev->node, &leds_list); in led_classdev_register_ext()
407 if (!led_cdev->max_brightness) in led_classdev_register_ext()
408 led_cdev->max_brightness = LED_FULL; in led_classdev_register_ext()
418 mutex_unlock(&led_cdev->led_access); in led_classdev_register_ext()
421 led_cdev->name); in led_classdev_register_ext()
428 * led_classdev_unregister - unregisters a object of led_properties class.
435 if (IS_ERR_OR_NULL(led_cdev->dev)) in led_classdev_unregister()
439 down_write(&led_cdev->trigger_lock); in led_classdev_unregister()
440 if (led_cdev->trigger) in led_classdev_unregister()
442 up_write(&led_cdev->trigger_lock); in led_classdev_unregister()
445 led_cdev->flags |= LED_UNREGISTERING; in led_classdev_unregister()
450 if (!(led_cdev->flags & LED_RETAIN_AT_SHUTDOWN)) in led_classdev_unregister()
453 flush_work(&led_cdev->set_brightness_work); in led_classdev_unregister()
455 if (led_cdev->flags & LED_BRIGHT_HW_CHANGED) in led_classdev_unregister()
458 device_unregister(led_cdev->dev); in led_classdev_unregister()
461 list_del(&led_cdev->node); in led_classdev_unregister()
464 mutex_destroy(&led_cdev->led_access); in led_classdev_unregister()
474 * devm_led_classdev_register_ext - resource managed led_classdev_register_ext()
489 return -ENOMEM; in devm_led_classdev_register_ext()
515 * devm_led_classdev_unregister() - resource managed led_classdev_unregister()
533 leds_class->pm = &leds_class_dev_pm_ops; in leds_init()
534 leds_class->dev_groups = led_groups; in leds_init()