Lines Matching +full:led +full:- +full:cur

1 // SPDX-License-Identifier: GPL-2.0-only
9 * Derived from leds-lp5521.c, leds-lp5523.c
18 #include <linux/platform_data/leds-lp55xx.h>
21 #include <dt-bindings/leds/leds-lp55xx.h>
23 #include "leds-lp55xx-common.h"
45 struct lp55xx_device_config *cfg = chip->cfg; in lp55xx_reset_device()
46 u8 addr = cfg->reset.addr; in lp55xx_reset_device()
47 u8 val = cfg->reset.val; in lp55xx_reset_device()
55 struct lp55xx_device_config *cfg = chip->cfg; in lp55xx_detect_device()
56 u8 addr = cfg->enable.addr; in lp55xx_detect_device()
57 u8 val = cfg->enable.val; in lp55xx_detect_device()
70 if (val != cfg->enable.val) in lp55xx_detect_device()
71 return -ENODEV; in lp55xx_detect_device()
78 struct lp55xx_device_config *cfg = chip->cfg; in lp55xx_post_init_device()
80 if (!cfg->post_init_device) in lp55xx_post_init_device()
83 return cfg->post_init_device(chip); in lp55xx_post_init_device()
90 struct lp55xx_led *led = dev_to_lp55xx_led(dev); in led_current_show() local
92 return sysfs_emit(buf, "%d\n", led->led_current); in led_current_show()
99 struct lp55xx_led *led = dev_to_lp55xx_led(dev); in led_current_store() local
100 struct lp55xx_chip *chip = led->chip; in led_current_store()
104 return -EINVAL; in led_current_store()
106 if (curr > led->max_current) in led_current_store()
107 return -EINVAL; in led_current_store()
109 if (!chip->cfg->set_led_current) in led_current_store()
112 mutex_lock(&chip->lock); in led_current_store()
113 chip->cfg->set_led_current(led, (u8)curr); in led_current_store()
114 mutex_unlock(&chip->lock); in led_current_store()
123 struct lp55xx_led *led = dev_to_lp55xx_led(dev); in max_current_show() local
125 return sysfs_emit(buf, "%d\n", led->max_current); in max_current_show()
142 struct lp55xx_led *led = mcled_cdev_to_led(mc_dev); in lp55xx_set_mc_brightness() local
143 struct lp55xx_device_config *cfg = led->chip->cfg; in lp55xx_set_mc_brightness()
145 led_mc_calc_color_components(&led->mc_cdev, brightness); in lp55xx_set_mc_brightness()
146 return cfg->multicolor_brightness_fn(led); in lp55xx_set_mc_brightness()
153 struct lp55xx_led *led = cdev_to_lp55xx_led(cdev); in lp55xx_set_brightness() local
154 struct lp55xx_device_config *cfg = led->chip->cfg; in lp55xx_set_brightness()
156 led->brightness = (u8)brightness; in lp55xx_set_brightness()
157 return cfg->brightness_fn(led); in lp55xx_set_brightness()
160 static int lp55xx_init_led(struct lp55xx_led *led, in lp55xx_init_led() argument
163 struct lp55xx_platform_data *pdata = chip->pdata; in lp55xx_init_led()
164 struct lp55xx_device_config *cfg = chip->cfg; in lp55xx_init_led()
165 struct device *dev = &chip->cl->dev; in lp55xx_init_led()
166 int max_channel = cfg->max_channel; in lp55xx_init_led()
175 return -EINVAL; in lp55xx_init_led()
178 if (pdata->led_config[chan].led_current == 0) in lp55xx_init_led()
181 if (pdata->led_config[chan].name) { in lp55xx_init_led()
182 led->cdev.name = pdata->led_config[chan].name; in lp55xx_init_led()
185 pdata->label ? : chip->cl->name, chan); in lp55xx_init_led()
186 led->cdev.name = name; in lp55xx_init_led()
189 if (pdata->led_config[chan].num_colors > 1) { in lp55xx_init_led()
191 pdata->led_config[chan].num_colors, in lp55xx_init_led()
194 return -ENOMEM; in lp55xx_init_led()
196 led_cdev = &led->mc_cdev.led_cdev; in lp55xx_init_led()
197 led_cdev->name = led->cdev.name; in lp55xx_init_led()
198 led_cdev->brightness_set_blocking = lp55xx_set_mc_brightness; in lp55xx_init_led()
199 led->mc_cdev.num_colors = pdata->led_config[chan].num_colors; in lp55xx_init_led()
200 for (i = 0; i < led->mc_cdev.num_colors; i++) { in lp55xx_init_led()
202 pdata->led_config[chan].color_id[i]; in lp55xx_init_led()
204 pdata->led_config[chan].output_num[i]; in lp55xx_init_led()
207 led->mc_cdev.subled_info = mc_led_info; in lp55xx_init_led()
209 led->cdev.brightness_set_blocking = lp55xx_set_brightness; in lp55xx_init_led()
212 led->cdev.groups = lp55xx_led_groups; in lp55xx_init_led()
213 led->cdev.default_trigger = pdata->led_config[chan].default_trigger; in lp55xx_init_led()
214 led->led_current = pdata->led_config[chan].led_current; in lp55xx_init_led()
215 led->max_current = pdata->led_config[chan].max_current; in lp55xx_init_led()
216 led->chan_nr = pdata->led_config[chan].chan_nr; in lp55xx_init_led()
218 if (led->chan_nr >= max_channel) { in lp55xx_init_led()
220 max_channel - 1); in lp55xx_init_led()
221 return -EINVAL; in lp55xx_init_led()
224 if (pdata->led_config[chan].num_colors > 1) in lp55xx_init_led()
225 ret = devm_led_classdev_multicolor_register(dev, &led->mc_cdev); in lp55xx_init_led()
227 ret = devm_led_classdev_register(dev, &led->cdev); in lp55xx_init_led()
230 dev_err(dev, "led register err: %d\n", ret); in lp55xx_init_led()
240 struct device *dev = &chip->cl->dev; in lp55xx_firmware_loaded()
241 enum lp55xx_engine_index idx = chip->engine_idx; in lp55xx_firmware_loaded()
249 mutex_lock(&chip->lock); in lp55xx_firmware_loaded()
251 chip->engines[idx - 1].mode = LP55XX_ENGINE_LOAD; in lp55xx_firmware_loaded()
252 chip->fw = fw; in lp55xx_firmware_loaded()
253 if (chip->cfg->firmware_cb) in lp55xx_firmware_loaded()
254 chip->cfg->firmware_cb(chip); in lp55xx_firmware_loaded()
256 mutex_unlock(&chip->lock); in lp55xx_firmware_loaded()
259 release_firmware(chip->fw); in lp55xx_firmware_loaded()
260 chip->fw = NULL; in lp55xx_firmware_loaded()
265 const char *name = chip->cl->name; in lp55xx_request_firmware()
266 struct device *dev = &chip->cl->dev; in lp55xx_request_firmware()
276 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); in select_engine_show() local
277 struct lp55xx_chip *chip = led->chip; in select_engine_show()
279 return sprintf(buf, "%d\n", chip->engine_idx); in select_engine_show()
286 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); in select_engine_store() local
287 struct lp55xx_chip *chip = led->chip; in select_engine_store()
292 return -EINVAL; in select_engine_store()
300 mutex_lock(&chip->lock); in select_engine_store()
301 chip->engine_idx = val; in select_engine_store()
303 mutex_unlock(&chip->lock); in select_engine_store()
307 return -EINVAL; in select_engine_store()
320 if (chip->cfg->run_engine) in lp55xx_run_engine()
321 chip->cfg->run_engine(chip, start); in lp55xx_run_engine()
328 struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); in run_engine_store() local
329 struct lp55xx_chip *chip = led->chip; in run_engine_store()
333 return -EINVAL; in run_engine_store()
342 mutex_lock(&chip->lock); in run_engine_store()
344 mutex_unlock(&chip->lock); in run_engine_store()
364 return i2c_smbus_write_byte_data(chip->cl, reg, val); in lp55xx_write()
372 ret = i2c_smbus_read_byte_data(chip->cl, reg); in lp55xx_read()
402 clk = devm_clk_get(&chip->cl->dev, "32k_clk"); in lp55xx_is_extclk_used()
415 dev_info(&chip->cl->dev, "%dHz external clock used\n", LP55XX_CLK_32K); in lp55xx_is_extclk_used()
417 chip->clk = clk; in lp55xx_is_extclk_used()
421 dev_info(&chip->cl->dev, "internal clock used\n"); in lp55xx_is_extclk_used()
430 struct device *dev = &chip->cl->dev; in lp55xx_init_device()
435 pdata = chip->pdata; in lp55xx_init_device()
436 cfg = chip->cfg; in lp55xx_init_device()
439 return -EINVAL; in lp55xx_init_device()
441 if (pdata->enable_gpiod) { in lp55xx_init_device()
442 gpiod_direction_output(pdata->enable_gpiod, 0); in lp55xx_init_device()
444 gpiod_set_consumer_name(pdata->enable_gpiod, "LP55xx enable"); in lp55xx_init_device()
445 gpiod_set_value(pdata->enable_gpiod, 0); in lp55xx_init_device()
447 gpiod_set_value(pdata->enable_gpiod, 1); in lp55xx_init_device()
454 * Exact value is not available. 10 - 20ms in lp55xx_init_device()
483 struct lp55xx_platform_data *pdata = chip->pdata; in lp55xx_deinit_device()
485 if (chip->clk) in lp55xx_deinit_device()
486 clk_disable_unprepare(chip->clk); in lp55xx_deinit_device()
488 if (pdata->enable_gpiod) in lp55xx_deinit_device()
489 gpiod_set_value(pdata->enable_gpiod, 0); in lp55xx_deinit_device()
493 int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip) in lp55xx_register_leds() argument
495 struct lp55xx_platform_data *pdata = chip->pdata; in lp55xx_register_leds()
496 struct lp55xx_device_config *cfg = chip->cfg; in lp55xx_register_leds()
497 int num_channels = pdata->num_channels; in lp55xx_register_leds()
503 if (!cfg->brightness_fn) { in lp55xx_register_leds()
504 dev_err(&chip->cl->dev, "empty brightness configuration\n"); in lp55xx_register_leds()
505 return -EINVAL; in lp55xx_register_leds()
511 if (pdata->led_config[i].led_current == 0) in lp55xx_register_leds()
514 led_current = pdata->led_config[i].led_current; in lp55xx_register_leds()
515 each = led + i; in lp55xx_register_leds()
520 chip->num_leds++; in lp55xx_register_leds()
521 each->chip = chip; in lp55xx_register_leds()
523 /* setting led current at each channel */ in lp55xx_register_leds()
524 if (cfg->set_led_current) in lp55xx_register_leds()
525 cfg->set_led_current(each, led_current); in lp55xx_register_leds()
537 struct device *dev = &chip->cl->dev; in lp55xx_register_sysfs()
538 struct lp55xx_device_config *cfg = chip->cfg; in lp55xx_register_sysfs()
541 if (!cfg->run_engine || !cfg->firmware_cb) in lp55xx_register_sysfs()
544 ret = sysfs_create_group(&dev->kobj, &lp55xx_engine_attr_group); in lp55xx_register_sysfs()
549 return cfg->dev_attr_group ? in lp55xx_register_sysfs()
550 sysfs_create_group(&dev->kobj, cfg->dev_attr_group) : 0; in lp55xx_register_sysfs()
556 struct device *dev = &chip->cl->dev; in lp55xx_unregister_sysfs()
557 struct lp55xx_device_config *cfg = chip->cfg; in lp55xx_unregister_sysfs()
559 if (cfg->dev_attr_group) in lp55xx_unregister_sysfs()
560 sysfs_remove_group(&dev->kobj, cfg->dev_attr_group); in lp55xx_unregister_sysfs()
562 sysfs_remove_group(&dev->kobj, &lp55xx_engine_attr_group); in lp55xx_unregister_sysfs()
572 of_property_read_string(np, "chan-name", in lp55xx_parse_common_child()
574 of_property_read_u8(np, "led-cur", in lp55xx_parse_common_child()
576 of_property_read_u8(np, "max-cur", in lp55xx_parse_common_child()
636 of_get_property(np, "linux,default-trigger", NULL); in lp55xx_parse_logical_led()
667 return ERR_PTR(-ENOMEM); in lp55xx_of_populate_pdata()
671 dev_err(dev, "no LED channels\n"); in lp55xx_of_populate_pdata()
672 return ERR_PTR(-EINVAL); in lp55xx_of_populate_pdata()
677 return ERR_PTR(-ENOMEM); in lp55xx_of_populate_pdata()
679 pdata->led_config = &cfg[0]; in lp55xx_of_populate_pdata()
680 pdata->num_channels = num_channels; in lp55xx_of_populate_pdata()
681 cfg->max_channel = chip->cfg->max_channel; in lp55xx_of_populate_pdata()
687 return ERR_PTR(-EINVAL); in lp55xx_of_populate_pdata()
692 if (of_property_read_u32(np, "ti,charge-pump-mode", &pdata->charge_pump_mode)) in lp55xx_of_populate_pdata()
693 pdata->charge_pump_mode = LP55XX_CP_AUTO; in lp55xx_of_populate_pdata()
695 if (pdata->charge_pump_mode > LP55XX_CP_AUTO) { in lp55xx_of_populate_pdata()
696 dev_err(dev, "invalid charge pump mode %d\n", pdata->charge_pump_mode); in lp55xx_of_populate_pdata()
697 return ERR_PTR(-EINVAL); in lp55xx_of_populate_pdata()
700 of_property_read_string(np, "label", &pdata->label); in lp55xx_of_populate_pdata()
701 of_property_read_u8(np, "clock-mode", &pdata->clock_mode); in lp55xx_of_populate_pdata()
703 pdata->enable_gpiod = devm_gpiod_get_optional(dev, "enable", in lp55xx_of_populate_pdata()
705 if (IS_ERR(pdata->enable_gpiod)) in lp55xx_of_populate_pdata()
706 return ERR_CAST(pdata->enable_gpiod); in lp55xx_of_populate_pdata()
709 of_property_read_u8(np, "pwr-sel", (u8 *)&pdata->pwr_sel); in lp55xx_of_populate_pdata()