Lines Matching +full:adc +full:- +full:startup +full:- +full:time

1 // SPDX-License-Identifier: GPL-2.0-only
3 * lp5523.c - LP5523, LP55231 LED Driver
19 #include <linux/platform_data/leds-lp55xx.h>
22 #include "leds-lp55xx-common.h"
123 led->led_current = led_current; in lp5523_set_led_current()
124 lp55xx_write(led->chip, LP5523_REG_LED_CURRENT_BASE + led->chan_nr, in lp5523_set_led_current()
137 /* Chip startup time is 500 us, 1 - 2 ms gives some margin */ in lp5523_post_init_device()
141 val |= (chip->pdata->charge_pump_mode << LP5523_CP_MODE_SHIFT) & LP5523_CP_MODE_MASK; in lp5523_post_init_device()
161 enum lp55xx_engine_index idx = chip->engine_idx; in lp5523_load_engine()
181 enum lp55xx_engine_index idx = chip->engine_idx; in lp5523_load_engine_and_select_page()
201 enum lp55xx_engine_index idx = chip->engine_idx; in lp5523_stop_engine()
236 * operation mode and enable register should updated at the same time in lp5523_run_engine()
297 chip->engine_idx = i; in lp5523_init_program_engine()
302 pattern[i - 1][j]); in lp5523_init_program_engine()
318 dev_err(&chip->cl->dev, in lp5523_init_program_engine()
321 ret = -1; in lp5523_init_program_engine()
340 while ((offset < size - 1) && (i < LP5523_PROGRAM_LENGTH)) { in lp5523_update_program_memory()
362 return -EINVAL; in lp5523_update_program_memory()
368 dev_err(&chip->cl->dev, "wrong pattern format\n"); in lp5523_update_program_memory()
369 return -EINVAL; in lp5523_update_program_memory()
374 const struct firmware *fw = chip->fw; in lp5523_firmware_loaded()
376 if (fw->size > LP5523_PROGRAM_LENGTH) { in lp5523_firmware_loaded()
377 dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n", in lp5523_firmware_loaded()
378 fw->size); in lp5523_firmware_loaded()
389 lp5523_update_program_memory(chip, fw->data, fw->size); in lp5523_firmware_loaded()
397 struct lp55xx_chip *chip = led->chip; in show_engine_mode()
398 enum lp55xx_engine_mode mode = chip->engines[nr - 1].mode; in show_engine_mode()
419 struct lp55xx_chip *chip = led->chip; in store_engine_mode()
420 struct lp55xx_engine *engine = &chip->engines[nr - 1]; in store_engine_mode()
422 mutex_lock(&chip->lock); in store_engine_mode()
424 chip->engine_idx = nr; in store_engine_mode()
428 engine->mode = LP55XX_ENGINE_RUN; in store_engine_mode()
432 engine->mode = LP55XX_ENGINE_LOAD; in store_engine_mode()
435 engine->mode = LP55XX_ENGINE_DISABLED; in store_engine_mode()
438 mutex_unlock(&chip->lock); in store_engine_mode()
464 return -1; in lp5523_mux_parse()
487 struct lp55xx_chip *chip = led->chip; in show_engine_leds()
490 lp5523_mux_to_array(chip->engines[nr - 1].led_mux, mux); in show_engine_leds()
500 struct lp55xx_engine *engine = &chip->engines[nr - 1]; in lp5523_load_mux()
522 engine->led_mux = mux; in lp5523_load_mux()
531 struct lp55xx_chip *chip = led->chip; in store_engine_leds()
532 struct lp55xx_engine *engine = &chip->engines[nr - 1]; in store_engine_leds()
537 return -EINVAL; in store_engine_leds()
539 mutex_lock(&chip->lock); in store_engine_leds()
541 chip->engine_idx = nr; in store_engine_leds()
542 ret = -EINVAL; in store_engine_leds()
544 if (engine->mode != LP55XX_ENGINE_LOAD) in store_engine_leds()
552 mutex_unlock(&chip->lock); in store_engine_leds()
564 struct lp55xx_chip *chip = led->chip; in store_engine_load()
567 mutex_lock(&chip->lock); in store_engine_load()
569 chip->engine_idx = nr; in store_engine_load()
573 mutex_unlock(&chip->lock); in store_engine_load()
586 struct lp55xx_chip *chip = led->chip; in lp5523_selftest()
587 struct lp55xx_platform_data *pdata = chip->pdata; in lp5523_selftest()
589 u8 status, adc, vdd, i; in lp5523_selftest() local
591 mutex_lock(&chip->lock); in lp5523_selftest()
598 if (pdata->clock_mode == LP55XX_CLOCK_EXT) { in lp5523_selftest()
605 usleep_range(3000, 6000); /* ADC conversion time is typically 2.7 ms */ in lp5523_selftest()
617 vdd--; /* There may be some fluctuation in measurement */ in lp5523_selftest()
619 for (i = 0; i < pdata->num_channels; i++) { in lp5523_selftest()
621 if (pdata->led_config[i].led_current == 0) in lp5523_selftest()
625 lp55xx_write(chip, LP5523_REG_LED_CURRENT_BASE + led->chan_nr, in lp5523_selftest()
626 pdata->led_config[i].led_current); in lp5523_selftest()
628 lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + led->chan_nr, in lp5523_selftest()
630 /* let current stabilize 2 - 4ms before measurements start */ in lp5523_selftest()
633 LP5523_EN_LEDTEST | led->chan_nr); in lp5523_selftest()
634 /* ADC conversion time is 2.7 ms typically */ in lp5523_selftest()
643 ret = lp55xx_read(chip, LP5523_REG_LED_TEST_ADC, &adc); in lp5523_selftest()
647 if (adc >= vdd || adc < LP5523_ADC_SHORTCIRC_LIM) in lp5523_selftest()
649 led->chan_nr); in lp5523_selftest()
651 lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + led->chan_nr, in lp5523_selftest()
655 lp55xx_write(chip, LP5523_REG_LED_CURRENT_BASE + led->chan_nr, in lp5523_selftest()
656 led->led_current); in lp5523_selftest()
666 mutex_unlock(&chip->lock); in lp5523_selftest()
692 struct lp55xx_chip *chip = led->chip; in show_master_fader()
696 mutex_lock(&chip->lock); in show_master_fader()
697 ret = lp55xx_read(chip, LP5523_REG_MASTER_FADER_BASE + nr - 1, &val); in show_master_fader()
698 mutex_unlock(&chip->lock); in show_master_fader()
714 struct lp55xx_chip *chip = led->chip; in store_master_fader()
719 return -EINVAL; in store_master_fader()
722 return -EINVAL; in store_master_fader()
724 mutex_lock(&chip->lock); in store_master_fader()
725 ret = lp55xx_write(chip, LP5523_REG_MASTER_FADER_BASE + nr - 1, in store_master_fader()
727 mutex_unlock(&chip->lock); in store_master_fader()
743 struct lp55xx_chip *chip = led->chip; in show_master_fader_leds()
747 mutex_lock(&chip->lock); in show_master_fader_leds()
757 ret = -EINVAL; in show_master_fader_leds()
765 mutex_unlock(&chip->lock); in show_master_fader_leds()
774 struct lp55xx_chip *chip = led->chip; in store_master_fader_leds()
780 mutex_lock(&chip->lock); in store_master_fader_leds()
784 val = (buf[i] - '0') << LP5523_FADER_MAPPING_SHIFT; in store_master_fader_leds()
792 ret = -EINVAL; in store_master_fader_leds()
798 mutex_unlock(&chip->lock); in store_master_fader_leds()
804 struct lp55xx_chip *chip = led->chip; in lp5523_multicolor_brightness()
808 mutex_lock(&chip->lock); in lp5523_multicolor_brightness()
809 for (i = 0; i < led->mc_cdev.num_colors; i++) { in lp5523_multicolor_brightness()
812 led->mc_cdev.subled_info[i].channel, in lp5523_multicolor_brightness()
813 led->mc_cdev.subled_info[i].brightness); in lp5523_multicolor_brightness()
817 mutex_unlock(&chip->lock); in lp5523_multicolor_brightness()
823 struct lp55xx_chip *chip = led->chip; in lp5523_led_brightness()
826 mutex_lock(&chip->lock); in lp5523_led_brightness()
827 ret = lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + led->chan_nr, in lp5523_led_brightness()
828 led->brightness); in lp5523_led_brightness()
829 mutex_unlock(&chip->lock); in lp5523_led_brightness()
900 struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev); in lp5523_probe()
901 struct device_node *np = dev_of_node(&client->dev); in lp5523_probe()
903 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in lp5523_probe()
905 return -ENOMEM; in lp5523_probe()
907 chip->cfg = &lp5523_cfg; in lp5523_probe()
911 pdata = lp55xx_of_populate_pdata(&client->dev, np, in lp5523_probe()
916 dev_err(&client->dev, "no platform data\n"); in lp5523_probe()
917 return -EINVAL; in lp5523_probe()
921 led = devm_kcalloc(&client->dev, in lp5523_probe()
922 pdata->num_channels, sizeof(*led), GFP_KERNEL); in lp5523_probe()
924 return -ENOMEM; in lp5523_probe()
926 chip->cl = client; in lp5523_probe()
927 chip->pdata = pdata; in lp5523_probe()
929 mutex_init(&chip->lock); in lp5523_probe()
937 dev_info(&client->dev, "%s Programmable led chip found\n", id->name); in lp5523_probe()
945 dev_err(&client->dev, "registering sysfs failed\n"); in lp5523_probe()
960 struct lp55xx_chip *chip = led->chip; in lp5523_remove()