Lines Matching +full:led +full:- +full:s
1 // SPDX-License-Identifier: GPL-2.0-only
3 * LED Class Core
6 * Copyright (C) 2005-2007 Richard Purdie <rpurdie@openedhand.com>
36 return sprintf(buf, "%u\n", led_cdev->brightness); in brightness_show()
46 mutex_lock(&led_cdev->led_access); in brightness_store()
49 ret = -EBUSY; in brightness_store()
60 flush_work(&led_cdev->set_brightness_work); in brightness_store()
64 mutex_unlock(&led_cdev->led_access); in brightness_store()
74 return sprintf(buf, "%u\n", led_cdev->max_brightness); in max_brightness_show()
113 if (led_cdev->brightness_hw_changed == -1) in brightness_hw_changed_show()
114 return -ENODATA; in brightness_hw_changed_show()
116 return sprintf(buf, "%u\n", led_cdev->brightness_hw_changed); in brightness_hw_changed_show()
123 struct device *dev = led_cdev->dev; in led_add_brightness_hw_changed()
132 led_cdev->brightness_hw_changed_kn = in led_add_brightness_hw_changed()
133 sysfs_get_dirent(dev->kobj.sd, "brightness_hw_changed"); in led_add_brightness_hw_changed()
134 if (!led_cdev->brightness_hw_changed_kn) { in led_add_brightness_hw_changed()
137 return -ENXIO; in led_add_brightness_hw_changed()
145 sysfs_put(led_cdev->brightness_hw_changed_kn); in led_remove_brightness_hw_changed()
146 device_remove_file(led_cdev->dev, &dev_attr_brightness_hw_changed); in led_remove_brightness_hw_changed()
151 if (WARN_ON(!led_cdev->brightness_hw_changed_kn)) in led_classdev_notify_brightness_hw_changed()
154 led_cdev->brightness_hw_changed = brightness; in led_classdev_notify_brightness_hw_changed()
155 sysfs_notify_dirent(led_cdev->brightness_hw_changed_kn); in led_classdev_notify_brightness_hw_changed()
169 * led_classdev_suspend - suspend an led_classdev.
174 led_cdev->flags |= LED_SUSPENDED; in led_classdev_suspend()
176 flush_work(&led_cdev->set_brightness_work); in led_classdev_suspend()
181 * led_classdev_resume - resume an led_classdev.
186 led_set_brightness_nopm(led_cdev, led_cdev->brightness); in led_classdev_resume()
188 if (led_cdev->flash_resume) in led_classdev_resume()
189 led_cdev->flash_resume(led_cdev); in led_classdev_resume()
191 led_cdev->flags &= ~LED_SUSPENDED; in led_classdev_resume()
200 if (led_cdev->flags & LED_CORE_SUSPENDRESUME) in led_suspend()
210 if (led_cdev->flags & LED_CORE_SUSPENDRESUME) in led_resume()
224 return ERR_PTR(-EPROBE_DEFER); in led_module_get()
228 if (!try_module_get(led_cdev->dev->parent->driver->owner)) { in led_module_get()
229 put_device(led_cdev->dev); in led_module_get()
230 return ERR_PTR(-ENODEV); in led_module_get()
243 * of_led_get() - request a LED device via the LED framework
244 * @np: device node to get the LED device from
245 * @index: the index of the LED
247 * Returns the LED device parsed from the phandle specified in the "leds"
248 * property of a device tree node or a negative error-code on failure.
257 return ERR_PTR(-ENOENT); in of_led_get()
267 * led_put() - release a LED device
268 * @led_cdev: LED device
272 module_put(led_cdev->dev->parent->driver->owner); in led_put()
273 put_device(led_cdev->dev); in led_put()
284 static struct led_classdev *__devm_led_get(struct device *dev, struct led_classdev *led) in __devm_led_get() argument
290 led_put(led); in __devm_led_get()
291 return ERR_PTR(-ENOMEM); in __devm_led_get()
294 *dr = led; in __devm_led_get()
297 return led; in __devm_led_get()
301 * devm_of_led_get - Resource-managed request of a LED device
302 * @dev: LED consumer
303 * @index: index of the LED to obtain in the consumer
305 * The device node of the device is parse to find the request LED device.
306 * The LED device returned from this function is automatically released
309 * @return a pointer to a LED device or ERR_PTR(errno) on failure.
314 struct led_classdev *led; in devm_of_led_get() local
317 return ERR_PTR(-EINVAL); in devm_of_led_get()
319 led = of_led_get(dev->of_node, index); in devm_of_led_get()
320 if (IS_ERR(led)) in devm_of_led_get()
321 return led; in devm_of_led_get()
323 return __devm_led_get(dev, led); in devm_of_led_get()
328 * led_get() - request a LED device via the LED framework
329 * @dev: device for which to get the LED device
330 * @con_id: name of the LED from the device's point of view
332 * @return a pointer to a LED device or ERR_PTR(errno) on failure.
342 if (!strcmp(lookup->dev_id, dev_name(dev)) && in led_get()
343 !strcmp(lookup->con_id, con_id)) { in led_get()
344 provider = kstrdup_const(lookup->provider, GFP_KERNEL); in led_get()
351 return ERR_PTR(-ENOENT); in led_get()
361 * devm_led_get() - request a LED device via the LED framework
362 * @dev: device for which to get the LED device
363 * @con_id: name of the LED from the device's point of view
365 * The LED device returned from this function is automatically released
368 * @return a pointer to a LED device or ERR_PTR(errno) on failure.
372 struct led_classdev *led; in devm_led_get() local
374 led = led_get(dev, con_id); in devm_led_get()
375 if (IS_ERR(led)) in devm_led_get()
376 return led; in devm_led_get()
378 return __devm_led_get(dev, led); in devm_led_get()
383 * led_add_lookup() - Add a LED lookup table entry
386 * Add a LED lookup table entry. On systems without devicetree the lookup table
392 list_add_tail(&led_lookup->list, &leds_lookup_list); in led_add_lookup()
398 * led_remove_lookup() - Remove a LED lookup table entry
404 list_del(&led_lookup->list); in led_remove_lookup()
410 * devm_of_led_get_optional - Resource-managed request of an optional LED device
411 * @dev: LED consumer
412 * @index: index of the LED to obtain in the consumer
414 * The device node of the device is parsed to find the requested LED device.
415 * The LED device returned from this function is automatically released
418 * @return a pointer to a LED device, ERR_PTR(errno) on failure and NULL if the
419 * led was not found.
424 struct led_classdev *led; in devm_of_led_get_optional() local
426 led = devm_of_led_get(dev, index); in devm_of_led_get_optional()
427 if (IS_ERR(led) && PTR_ERR(led) == -ENOENT) in devm_of_led_get_optional()
430 return led; in devm_of_led_get_optional()
450 return -ENOMEM; in led_classdev_next_name()
456 * led_classdev_register_ext - register a new object of led_classdev class
459 * @parent: parent of LED device
461 * @init_data: LED class device initialization data
473 if (init_data->devname_mandatory && !init_data->devicename) { in led_classdev_register_ext()
475 return -EINVAL; in led_classdev_register_ext()
481 if (init_data->fwnode) { in led_classdev_register_ext()
482 fwnode_property_read_string(init_data->fwnode, in led_classdev_register_ext()
483 "linux,default-trigger", in led_classdev_register_ext()
484 &led_cdev->default_trigger); in led_classdev_register_ext()
486 if (fwnode_property_present(init_data->fwnode, in led_classdev_register_ext()
487 "retain-state-shutdown")) in led_classdev_register_ext()
488 led_cdev->flags |= LED_RETAIN_AT_SHUTDOWN; in led_classdev_register_ext()
490 fwnode_property_read_u32(init_data->fwnode, in led_classdev_register_ext()
491 "max-brightness", in led_classdev_register_ext()
492 &led_cdev->max_brightness); in led_classdev_register_ext()
494 if (fwnode_property_present(init_data->fwnode, "color")) in led_classdev_register_ext()
495 fwnode_property_read_u32(init_data->fwnode, "color", in led_classdev_register_ext()
496 &led_cdev->color); in led_classdev_register_ext()
499 proposed_name = led_cdev->name; in led_classdev_register_ext()
505 else if (ret && led_cdev->flags & LED_REJECT_NAME_CONFLICT) in led_classdev_register_ext()
506 return -EEXIST; in led_classdev_register_ext()
508 dev_warn(parent, "Led %s renamed to %s due to name collision\n", in led_classdev_register_ext()
511 if (led_cdev->color >= LED_COLOR_ID_MAX) in led_classdev_register_ext()
512 dev_warn(parent, "LED %s color identifier out of range\n", final_name); in led_classdev_register_ext()
514 mutex_init(&led_cdev->led_access); in led_classdev_register_ext()
515 mutex_lock(&led_cdev->led_access); in led_classdev_register_ext()
516 led_cdev->dev = device_create_with_groups(&leds_class, parent, 0, in led_classdev_register_ext()
517 led_cdev, led_cdev->groups, "%s", final_name); in led_classdev_register_ext()
518 if (IS_ERR(led_cdev->dev)) { in led_classdev_register_ext()
519 mutex_unlock(&led_cdev->led_access); in led_classdev_register_ext()
520 return PTR_ERR(led_cdev->dev); in led_classdev_register_ext()
522 if (init_data && init_data->fwnode) in led_classdev_register_ext()
523 device_set_node(led_cdev->dev, init_data->fwnode); in led_classdev_register_ext()
525 if (led_cdev->flags & LED_BRIGHT_HW_CHANGED) { in led_classdev_register_ext()
528 device_unregister(led_cdev->dev); in led_classdev_register_ext()
529 led_cdev->dev = NULL; in led_classdev_register_ext()
530 mutex_unlock(&led_cdev->led_access); in led_classdev_register_ext()
535 led_cdev->work_flags = 0; in led_classdev_register_ext()
537 init_rwsem(&led_cdev->trigger_lock); in led_classdev_register_ext()
540 led_cdev->brightness_hw_changed = -1; in led_classdev_register_ext()
544 list_add_tail(&led_cdev->node, &leds_list); in led_classdev_register_ext()
547 if (!led_cdev->max_brightness) in led_classdev_register_ext()
548 led_cdev->max_brightness = LED_FULL; in led_classdev_register_ext()
558 mutex_unlock(&led_cdev->led_access); in led_classdev_register_ext()
560 dev_dbg(parent, "Registered led device: %s\n", in led_classdev_register_ext()
561 led_cdev->name); in led_classdev_register_ext()
568 * led_classdev_unregister - unregisters a object of led_properties class.
569 * @led_cdev: the led device to unregister
575 if (IS_ERR_OR_NULL(led_cdev->dev)) in led_classdev_unregister()
579 down_write(&led_cdev->trigger_lock); in led_classdev_unregister()
580 if (led_cdev->trigger) in led_classdev_unregister()
582 up_write(&led_cdev->trigger_lock); in led_classdev_unregister()
585 led_cdev->flags |= LED_UNREGISTERING; in led_classdev_unregister()
590 if (!(led_cdev->flags & LED_RETAIN_AT_SHUTDOWN)) in led_classdev_unregister()
593 flush_work(&led_cdev->set_brightness_work); in led_classdev_unregister()
595 if (led_cdev->flags & LED_BRIGHT_HW_CHANGED) in led_classdev_unregister()
598 device_unregister(led_cdev->dev); in led_classdev_unregister()
601 list_del(&led_cdev->node); in led_classdev_unregister()
604 mutex_destroy(&led_cdev->led_access); in led_classdev_unregister()
614 * devm_led_classdev_register_ext - resource managed led_classdev_register_ext()
616 * @parent: parent of LED device
618 * @init_data: LED class device initialization data
629 return -ENOMEM; in devm_led_classdev_register_ext()
655 * devm_led_classdev_unregister() - resource managed led_classdev_unregister()
683 MODULE_DESCRIPTION("LED Class Interface");