Lines Matching +full:led +full:- +full:s

1 // SPDX-License-Identifier: GPL-2.0-only
3 * leds-lp3944.c - driver for National Semiconductor LP3944 Funlight Chip
14 * as a led controller.
18 * - period: from 0s to 1.6s
19 * - duty cycle: percentage of the period the led is on, from 0 to 100
30 #include <linux/leds-lp3944.h>
33 #define LP3944_REG_INPUT1 0x00 /* LEDs 0-7 InputRegister (Read Only) */
40 #define LP3944_REG_LS0 0x06 /* LEDs 0-3 Selector (R/W) */
41 #define LP3944_REG_LS1 0x07 /* LEDs 4-7 Selector (R/W) */
95 * lp3944_dim_set_period() - Set the period for DIM status
112 return -EINVAL; in lp3944_dim_set_period()
116 return -EINVAL; in lp3944_dim_set_period()
126 * lp3944_dim_set_dutycycle - Set the duty cycle for DIM status
130 * @duty_cycle: percentage of a period during which a led is ON
144 return -EINVAL; in lp3944_dim_set_dutycycle()
148 return -EINVAL; in lp3944_dim_set_dutycycle()
158 * lp3944_led_set() - Set the led status
160 * @led: a lp3944_led_data structure
166 static int lp3944_led_set(struct lp3944_led_data *led, u8 status) in lp3944_led_set() argument
168 struct lp3944_data *data = i2c_get_clientdata(led->client); in lp3944_led_set()
169 u8 id = led->id; in lp3944_led_set()
174 dev_dbg(&led->client->dev, "%s: %s, status before normalization:%d\n", in lp3944_led_set()
175 __func__, led->ldev.name, status); in lp3944_led_set()
188 id -= LP3944_LED4; in lp3944_led_set()
192 return -EINVAL; in lp3944_led_set()
196 return -EINVAL; in lp3944_led_set()
199 * Invert status only when it's < 2 (i.e. 0 or 1) which means it's in lp3944_led_set()
204 if (led->type == LP3944_LED_TYPE_LED_INVERTED && status < 2) in lp3944_led_set()
205 status = 1 - status; in lp3944_led_set()
207 mutex_lock(&data->lock); in lp3944_led_set()
208 lp3944_reg_read(led->client, reg, &val); in lp3944_led_set()
213 dev_dbg(&led->client->dev, "%s: %s, reg:%d id:%d status:%d val:%#x\n", in lp3944_led_set()
214 __func__, led->ldev.name, reg, id, status, val); in lp3944_led_set()
216 /* set led status */ in lp3944_led_set()
217 err = lp3944_reg_write(led->client, reg, val); in lp3944_led_set()
218 mutex_unlock(&data->lock); in lp3944_led_set()
227 struct lp3944_led_data *led = ldev_to_led(led_cdev); in lp3944_led_set_blink() local
234 return -EINVAL; in lp3944_led_set_blink()
238 * friendly blink pattern for the LED. Let's blink the led in lp3944_led_set_blink()
247 /* duty_cycle is the percentage of period during which the led is ON */ in lp3944_led_set_blink()
253 if (led->type == LP3944_LED_TYPE_LED_INVERTED) in lp3944_led_set_blink()
254 duty_cycle = 100 - duty_cycle; in lp3944_led_set_blink()
263 err = lp3944_dim_set_period(led->client, LP3944_DIM0, period); in lp3944_led_set_blink()
267 err = lp3944_dim_set_dutycycle(led->client, LP3944_DIM0, duty_cycle); in lp3944_led_set_blink()
271 dev_dbg(&led->client->dev, "%s: OK hardware accelerated blink!\n", in lp3944_led_set_blink()
274 lp3944_led_set(led, LP3944_LED_STATUS_DIM0); in lp3944_led_set_blink()
282 struct lp3944_led_data *led = ldev_to_led(led_cdev); in lp3944_led_set_brightness() local
284 dev_dbg(&led->client->dev, "%s: %s, %d\n", in lp3944_led_set_brightness()
285 __func__, led_cdev->name, brightness); in lp3944_led_set_brightness()
287 return lp3944_led_set(led, !!brightness); in lp3944_led_set_brightness()
296 for (i = 0; i < pdata->leds_size; i++) { in lp3944_configure()
297 struct lp3944_led *pled = &pdata->leds[i]; in lp3944_configure()
298 struct lp3944_led_data *led = &data->leds[i]; in lp3944_configure() local
299 led->client = client; in lp3944_configure()
300 led->id = i; in lp3944_configure()
302 switch (pled->type) { in lp3944_configure()
306 led->type = pled->type; in lp3944_configure()
307 led->ldev.name = pled->name; in lp3944_configure()
308 led->ldev.max_brightness = 1; in lp3944_configure()
309 led->ldev.brightness_set_blocking = in lp3944_configure()
311 led->ldev.blink_set = lp3944_led_set_blink; in lp3944_configure()
312 led->ldev.flags = LED_CORE_SUSPENDRESUME; in lp3944_configure()
314 err = led_classdev_register(&client->dev, &led->ldev); in lp3944_configure()
316 dev_err(&client->dev, in lp3944_configure()
317 "couldn't register LED %s\n", in lp3944_configure()
318 led->ldev.name); in lp3944_configure()
323 led->ldev.brightness = in lp3944_configure()
324 (enum led_brightness) pled->status; in lp3944_configure()
326 /* Set the default led status */ in lp3944_configure()
327 err = lp3944_led_set(led, pled->status); in lp3944_configure()
329 dev_err(&client->dev, in lp3944_configure()
330 "%s couldn't set STATUS %d\n", in lp3944_configure()
331 led->ldev.name, pled->status); in lp3944_configure()
346 for (i = i - 1; i >= 0; i--) in lp3944_configure()
347 switch (pdata->leds[i].type) { in lp3944_configure()
351 led_classdev_unregister(&data->leds[i].ldev); in lp3944_configure()
365 dev_get_platdata(&client->dev); in lp3944_probe()
370 dev_err(&client->dev, "no platform data\n"); in lp3944_probe()
371 return -EINVAL; in lp3944_probe()
374 /* Let's see whether this adapter can support what we need. */ in lp3944_probe()
375 if (!i2c_check_functionality(client->adapter, in lp3944_probe()
377 dev_err(&client->dev, "insufficient functionality!\n"); in lp3944_probe()
378 return -ENODEV; in lp3944_probe()
381 data = devm_kzalloc(&client->dev, sizeof(struct lp3944_data), in lp3944_probe()
384 return -ENOMEM; in lp3944_probe()
386 data->client = client; in lp3944_probe()
389 mutex_init(&data->lock); in lp3944_probe()
395 dev_info(&client->dev, "lp3944 enabled\n"); in lp3944_probe()
401 struct lp3944_platform_data *pdata = dev_get_platdata(&client->dev); in lp3944_remove()
405 for (i = 0; i < pdata->leds_size; i++) in lp3944_remove()
406 switch (data->leds[i].type) { in lp3944_remove()
409 led_classdev_unregister(&data->leds[i].ldev); in lp3944_remove()