Lines Matching +full:led +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0-only
3 * LP5562 LED driver
17 #include <linux/platform_data/leds-lp55xx.h>
20 #include "leds-lp55xx-common.h"
50 #define LP5562_ENG1_IS_LOADING(mode) \ argument
51 ((mode & LP5562_MODE_ENG1_M) == LP5562_LOAD_ENG1)
52 #define LP5562_ENG2_IS_LOADING(mode) \ argument
53 ((mode & LP5562_MODE_ENG2_M) == LP5562_LOAD_ENG2)
54 #define LP5562_ENG3_IS_LOADING(mode) \ argument
55 ((mode & LP5562_MODE_ENG3_M) == LP5562_LOAD_ENG3)
104 /* operation mode change needs to be longer than 153 us */ in lp5562_wait_opmode_done()
114 static void lp5562_set_led_current(struct lp55xx_led *led, u8 led_current) in lp5562_set_led_current() argument
123 led->led_current = led_current; in lp5562_set_led_current()
124 lp55xx_write(led->chip, addr[led->chan_nr], led_current); in lp5562_set_led_current()
129 enum lp55xx_engine_index idx = chip->engine_idx; in lp5562_load_engine()
156 u8 mode; in lp5562_run_engine() local
172 * operation mode and enable register should updated at the same time in lp5562_run_engine()
175 ret = lp55xx_read(chip, LP5562_REG_OP_MODE, &mode); in lp5562_run_engine()
183 /* change operation mode to RUN only when each engine is loading */ in lp5562_run_engine()
184 if (LP5562_ENG1_IS_LOADING(mode)) { in lp5562_run_engine()
185 mode = (mode & ~LP5562_MODE_ENG1_M) | LP5562_RUN_ENG1; in lp5562_run_engine()
189 if (LP5562_ENG2_IS_LOADING(mode)) { in lp5562_run_engine()
190 mode = (mode & ~LP5562_MODE_ENG2_M) | LP5562_RUN_ENG2; in lp5562_run_engine()
194 if (LP5562_ENG3_IS_LOADING(mode)) { in lp5562_run_engine()
195 mode = (mode & ~LP5562_MODE_ENG3_M) | LP5562_RUN_ENG3; in lp5562_run_engine()
199 lp55xx_write(chip, LP5562_REG_OP_MODE, mode); in lp5562_run_engine()
209 enum lp55xx_engine_index idx = chip->engine_idx; in lp5562_update_firmware()
229 while ((offset < size - 1) && (i < LP5562_PROGRAM_LENGTH)) { in lp5562_update_firmware()
255 dev_err(&chip->cl->dev, "wrong pattern format\n"); in lp5562_update_firmware()
256 return -EINVAL; in lp5562_update_firmware()
261 const struct firmware *fw = chip->fw; in lp5562_firmware_loaded()
267 if (fw->size > (LP5562_PROGRAM_LENGTH * 2)) { in lp5562_firmware_loaded()
268 dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", in lp5562_firmware_loaded()
269 fw->size); in lp5562_firmware_loaded()
275 * 1) set engine mode to "LOAD" in lp5562_firmware_loaded()
280 lp5562_update_firmware(chip, fw->data, fw->size); in lp5562_firmware_loaded()
288 /* Set all PWMs to direct control mode */ in lp5562_post_init_device()
303 /* Initialize all channels PWM to zero -> leds off */ in lp5562_post_init_device()
309 /* Set LED map as register PWM by default */ in lp5562_post_init_device()
315 static int lp5562_led_brightness(struct lp55xx_led *led) in lp5562_led_brightness() argument
317 struct lp55xx_chip *chip = led->chip; in lp5562_led_brightness()
326 mutex_lock(&chip->lock); in lp5562_led_brightness()
327 ret = lp55xx_write(chip, addr[led->chan_nr], led->brightness); in lp5562_led_brightness()
328 mutex_unlock(&chip->lock); in lp5562_led_brightness()
351 return ptn->size_r >= LP5562_PROGRAM_LENGTH || in _is_pc_overflow()
352 ptn->size_g >= LP5562_PROGRAM_LENGTH || in _is_pc_overflow()
353 ptn->size_b >= LP5562_PROGRAM_LENGTH; in _is_pc_overflow()
356 static int lp5562_run_predef_led_pattern(struct lp55xx_chip *chip, int mode) in lp5562_run_predef_led_pattern() argument
361 if (mode == LP5562_PATTERN_OFF) { in lp5562_run_predef_led_pattern()
366 ptn = chip->pdata->patterns + (mode - 1); in lp5562_run_predef_led_pattern()
368 dev_err(&chip->cl->dev, "invalid pattern data\n"); in lp5562_run_predef_led_pattern()
369 return -EINVAL; in lp5562_run_predef_led_pattern()
374 /* Set LED map as RGB */ in lp5562_run_predef_led_pattern()
379 chip->engine_idx = i; in lp5562_run_predef_led_pattern()
393 ptn->r, ptn->size_r); in lp5562_run_predef_led_pattern()
395 ptn->g, ptn->size_g); in lp5562_run_predef_led_pattern()
397 ptn->b, ptn->size_b); in lp5562_run_predef_led_pattern()
409 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); in lp5562_store_pattern() local
410 struct lp55xx_chip *chip = led->chip; in lp5562_store_pattern()
411 struct lp55xx_predef_pattern *ptn = chip->pdata->patterns; in lp5562_store_pattern()
412 int num_patterns = chip->pdata->num_patterns; in lp5562_store_pattern()
413 unsigned long mode; in lp5562_store_pattern() local
416 ret = kstrtoul(buf, 0, &mode); in lp5562_store_pattern()
420 if (mode > num_patterns || !ptn) in lp5562_store_pattern()
421 return -EINVAL; in lp5562_store_pattern()
423 mutex_lock(&chip->lock); in lp5562_store_pattern()
424 ret = lp5562_run_predef_led_pattern(chip, mode); in lp5562_store_pattern()
425 mutex_unlock(&chip->lock); in lp5562_store_pattern()
437 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); in lp5562_store_engine_mux() local
438 struct lp55xx_chip *chip = led->chip; in lp5562_store_engine_mux()
442 /* LED map in lp5562_store_engine_mux()
453 enum lp55xx_engine_index idx = chip->engine_idx; in lp5562_store_engine_mux()
467 return -EINVAL; in lp5562_store_engine_mux()
472 return -EINVAL; in lp5562_store_engine_mux()
475 mutex_lock(&chip->lock); in lp5562_store_engine_mux()
477 mutex_unlock(&chip->lock); in lp5562_store_engine_mux()
519 struct lp55xx_led *led; in lp5562_probe() local
520 struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); in lp5562_probe()
521 struct device_node *np = dev_of_node(&client->dev); in lp5562_probe()
523 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in lp5562_probe()
525 return -ENOMEM; in lp5562_probe()
527 chip->cfg = &lp5562_cfg; in lp5562_probe()
531 pdata = lp55xx_of_populate_pdata(&client->dev, np, in lp5562_probe()
536 dev_err(&client->dev, "no platform data\n"); in lp5562_probe()
537 return -EINVAL; in lp5562_probe()
542 led = devm_kcalloc(&client->dev, in lp5562_probe()
543 pdata->num_channels, sizeof(*led), GFP_KERNEL); in lp5562_probe()
544 if (!led) in lp5562_probe()
545 return -ENOMEM; in lp5562_probe()
547 chip->cl = client; in lp5562_probe()
548 chip->pdata = pdata; in lp5562_probe()
550 mutex_init(&chip->lock); in lp5562_probe()
552 i2c_set_clientdata(client, led); in lp5562_probe()
558 ret = lp55xx_register_leds(led, chip); in lp5562_probe()
564 dev_err(&client->dev, "registering sysfs failed\n"); in lp5562_probe()
578 struct lp55xx_led *led = i2c_get_clientdata(client); in lp5562_remove() local
579 struct lp55xx_chip *chip = led->chip; in lp5562_remove()
614 MODULE_DESCRIPTION("Texas Instruments LP5562 LED Driver");