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

1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/leds-pwm.c
9 * based on leds-gpio.c by Raphael Assenat <raph@8d.com>
42 enum led_brightness brightness) in led_pwm_set() argument
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()
49 duty *= brightness; 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()
57 * Disabling a PWM doesn't guarantee that it emits the inactive level. 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()
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()
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()
99 default: in led_pwm_add()
100 pwm_init_state(led_data->pwm, &led_data->pwmstate); in led_pwm_add()
104 /* set brightness */ 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()
111 uint64_t brightness; in led_pwm_add() local
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()
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()
132 led->name, ret); in led_pwm_add()
137 priv->num_leds++; in led_pwm_add()
152 led.name = to_of_node(fwnode)->name; in led_pwm_create_fwnode()
155 ret = -EINVAL; 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()
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", },
223 MODULE_ALIAS("platform:leds-pwm");