Lines Matching +full:led +full:- +full:s
1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/leds-pwm.c
5 * simple PWM based LED control
9 * based on leds-gpio.c by Raphael Assenat <raph@8d.com>
46 unsigned int max = led_dat->cdev.max_brightness; in led_pwm_set()
47 unsigned long long duty = led_dat->pwmstate.period; in led_pwm_set()
52 if (led_dat->active_low) in led_pwm_set()
53 duty = led_dat->pwmstate.period - duty; in led_pwm_set()
55 led_dat->pwmstate.duty_cycle = duty; in led_pwm_set()
60 * LED might stay (or even go) on. in led_pwm_set()
62 led_dat->pwmstate.enabled = !(led_cdev->flags & LED_SUSPENDED); in led_pwm_set()
63 return pwm_apply_might_sleep(led_dat->pwm, &led_dat->pwmstate); in led_pwm_set()
68 struct led_pwm *led, struct fwnode_handle *fwnode) in led_pwm_add() argument
70 struct led_pwm_data *led_data = &priv->leds[priv->num_leds]; in led_pwm_add()
74 led_data->active_low = led->active_low; in led_pwm_add()
75 led_data->cdev.name = led->name; in led_pwm_add()
76 led_data->cdev.brightness = LED_OFF; in led_pwm_add()
77 led_data->cdev.max_brightness = led->max_brightness; in led_pwm_add()
78 led_data->cdev.flags = LED_CORE_SUSPENDRESUME; in led_pwm_add()
80 led_data->pwm = devm_fwnode_pwm_get(dev, fwnode, NULL); in led_pwm_add()
81 if (IS_ERR(led_data->pwm)) in led_pwm_add()
82 return dev_err_probe(dev, PTR_ERR(led_data->pwm), in led_pwm_add()
83 "unable to request PWM for %s\n", in led_pwm_add()
84 led->name); in led_pwm_add()
86 led_data->cdev.brightness_set_blocking = led_pwm_set; in led_pwm_add()
89 switch (led->default_state) { in led_pwm_add()
91 pwm_get_state(led_data->pwm, &led_data->pwmstate); in led_pwm_add()
92 if (led_data->pwmstate.period) in led_pwm_add()
94 led->default_state = LEDS_DEFSTATE_OFF; in led_pwm_add()
96 "failed to read period for %s, default to off", in led_pwm_add()
97 led->name); in led_pwm_add()
100 pwm_init_state(led_data->pwm, &led_data->pwmstate); in led_pwm_add()
105 switch (led->default_state) { in led_pwm_add()
107 led_data->cdev.brightness = led->max_brightness; in led_pwm_add()
113 brightness = led->max_brightness; in led_pwm_add()
114 brightness *= led_data->pwmstate.duty_cycle; in led_pwm_add()
115 do_div(brightness, led_data->pwmstate.period); in led_pwm_add()
116 led_data->cdev.brightness = brightness; in led_pwm_add()
121 ret = devm_led_classdev_register_ext(dev, &led_data->cdev, &init_data); in led_pwm_add()
123 dev_err(dev, "failed to register PWM led for %s: %d\n", in led_pwm_add()
124 led->name, ret); in led_pwm_add()
128 if (led->default_state != LEDS_DEFSTATE_KEEP) { in led_pwm_add()
129 ret = led_pwm_set(&led_data->cdev, led_data->cdev.brightness); in led_pwm_add()
131 dev_err(dev, "failed to set led PWM value for %s: %d", in led_pwm_add()
132 led->name, ret); in led_pwm_add()
137 priv->num_leds++; in led_pwm_add()
144 struct led_pwm led; in led_pwm_create_fwnode() local
148 memset(&led, 0, sizeof(led)); in led_pwm_create_fwnode()
150 ret = fwnode_property_read_string(fwnode, "label", &led.name); in led_pwm_create_fwnode()
152 led.name = to_of_node(fwnode)->name; in led_pwm_create_fwnode()
154 if (!led.name) { in led_pwm_create_fwnode()
155 ret = -EINVAL; in led_pwm_create_fwnode()
159 led.active_low = fwnode_property_read_bool(fwnode, in led_pwm_create_fwnode()
160 "active-low"); in led_pwm_create_fwnode()
161 fwnode_property_read_u32(fwnode, "max-brightness", in led_pwm_create_fwnode()
162 &led.max_brightness); in led_pwm_create_fwnode()
164 led.default_state = led_init_default_state_get(fwnode); in led_pwm_create_fwnode()
166 ret = led_pwm_add(dev, priv, &led, fwnode); in led_pwm_create_fwnode()
184 count = device_get_child_node_count(&pdev->dev); in led_pwm_probe()
187 return -EINVAL; in led_pwm_probe()
189 priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds, count), in led_pwm_probe()
192 return -ENOMEM; in led_pwm_probe()
194 ret = led_pwm_create_fwnode(&pdev->dev, priv); in led_pwm_probe()
205 { .compatible = "pwm-leds", },
221 MODULE_DESCRIPTION("generic PWM LED driver");
223 MODULE_ALIAS("platform:leds-pwm");