Lines Matching +full:led +full:-

1 // SPDX-License-Identifier: GPL-2.0
2 // TI LM3697 LED chip family driver
3 // Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
10 #include <linux/leds-ti-lmu-common.h>
42 * struct lm3697_led -
43 * @hvled_strings: Array of LED strings associated with a control bank
44 * @label: LED label
45 * @led_dev: LED class device
48 * @control_bank: Control bank the LED is associated to. 0 is control bank A
63 * struct lm3697 -
65 * @regulator: LED supply regulator pointer
70 * @leds: Array of LED strings
116 struct lm3697_led *led = container_of(led_cdev, struct lm3697_led, in lm3697_brightness_set() local
118 int ctrl_en_val = (1 << led->control_bank); in lm3697_brightness_set()
119 struct device *dev = led->priv->dev; in lm3697_brightness_set()
122 mutex_lock(&led->priv->lock); in lm3697_brightness_set()
125 ret = regmap_update_bits(led->priv->regmap, LM3697_CTRL_ENABLE, in lm3697_brightness_set()
132 led->enabled = LED_OFF; in lm3697_brightness_set()
134 ret = ti_lmu_common_set_brightness(&led->lmu_data, brt_val); in lm3697_brightness_set()
140 if (!led->enabled) { in lm3697_brightness_set()
141 ret = regmap_update_bits(led->priv->regmap, in lm3697_brightness_set()
149 led->enabled = brt_val; in lm3697_brightness_set()
154 mutex_unlock(&led->priv->lock); in lm3697_brightness_set()
160 struct device *dev = priv->dev; in lm3697_init()
161 struct lm3697_led *led; in lm3697_init() local
164 if (priv->enable_gpio) { in lm3697_init()
165 gpiod_direction_output(priv->enable_gpio, 1); in lm3697_init()
167 ret = regmap_write(priv->regmap, LM3697_RESET, LM3697_SW_RESET); in lm3697_init()
174 ret = regmap_write(priv->regmap, LM3697_CTRL_ENABLE, 0x0); in lm3697_init()
180 ret = regmap_write(priv->regmap, LM3697_OUTPUT_CONFIG, priv->bank_cfg); in lm3697_init()
184 for (i = 0; i < priv->num_banks; i++) { in lm3697_init()
185 led = &priv->leds[i]; in lm3697_init()
186 ret = ti_lmu_common_set_ramp(&led->lmu_data); in lm3697_init()
197 struct device *dev = priv->dev; in lm3697_probe_dt()
198 struct lm3697_led *led; in lm3697_probe_dt() local
199 int ret = -EINVAL; in lm3697_probe_dt()
204 priv->enable_gpio = devm_gpiod_get_optional(dev, "enable", in lm3697_probe_dt()
206 if (IS_ERR(priv->enable_gpio)) { in lm3697_probe_dt()
207 ret = PTR_ERR(priv->enable_gpio); in lm3697_probe_dt()
212 priv->regulator = devm_regulator_get(dev, "vled"); in lm3697_probe_dt()
213 if (IS_ERR(priv->regulator)) in lm3697_probe_dt()
214 priv->regulator = NULL; in lm3697_probe_dt()
228 ret = -EINVAL; in lm3697_probe_dt()
233 led = &priv->leds[i]; in lm3697_probe_dt()
235 ret = ti_lmu_common_get_brt_res(dev, child, &led->lmu_data); in lm3697_probe_dt()
240 led->control_bank = control_bank; in lm3697_probe_dt()
241 led->lmu_data.regmap = priv->regmap; in lm3697_probe_dt()
242 led->lmu_data.runtime_ramp_reg = LM3697_CTRL_A_RAMP + in lm3697_probe_dt()
244 led->lmu_data.msb_brightness_reg = LM3697_CTRL_A_BRT_MSB + in lm3697_probe_dt()
245 led->control_bank * 2; in lm3697_probe_dt()
246 led->lmu_data.lsb_brightness_reg = LM3697_CTRL_A_BRT_LSB + in lm3697_probe_dt()
247 led->control_bank * 2; in lm3697_probe_dt()
249 led->num_leds = fwnode_property_count_u32(child, "led-sources"); in lm3697_probe_dt()
250 if (led->num_leds > LM3697_MAX_LED_STRINGS) { in lm3697_probe_dt()
251 dev_err(dev, "Too many LED strings defined\n"); in lm3697_probe_dt()
255 ret = fwnode_property_read_u32_array(child, "led-sources", in lm3697_probe_dt()
256 led->hvled_strings, in lm3697_probe_dt()
257 led->num_leds); in lm3697_probe_dt()
259 dev_err(dev, "led-sources property missing\n"); in lm3697_probe_dt()
264 for (j = 0; j < led->num_leds; j++) in lm3697_probe_dt()
265 priv->bank_cfg |= in lm3697_probe_dt()
266 (led->control_bank << led->hvled_strings[j]); in lm3697_probe_dt()
268 ret = ti_lmu_common_get_ramp_params(dev, child, &led->lmu_data); in lm3697_probe_dt()
270 dev_warn(dev, "runtime-ramp properties missing\n"); in lm3697_probe_dt()
273 init_data.devicename = priv->client->name; in lm3697_probe_dt()
277 led->priv = priv; in lm3697_probe_dt()
278 led->led_dev.max_brightness = led->lmu_data.max_brightness; in lm3697_probe_dt()
279 led->led_dev.brightness_set_blocking = lm3697_brightness_set; in lm3697_probe_dt()
281 ret = devm_led_classdev_register_ext(dev, &led->led_dev, in lm3697_probe_dt()
284 dev_err(dev, "led register err: %d\n", ret); in lm3697_probe_dt()
299 struct device *dev = &client->dev; in lm3697_probe()
300 struct lm3697 *led; in lm3697_probe() local
307 return -ENODEV; in lm3697_probe()
310 led = devm_kzalloc(dev, struct_size(led, leds, count), GFP_KERNEL); in lm3697_probe()
311 if (!led) in lm3697_probe()
312 return -ENOMEM; in lm3697_probe()
314 mutex_init(&led->lock); in lm3697_probe()
315 i2c_set_clientdata(client, led); in lm3697_probe()
317 led->client = client; in lm3697_probe()
318 led->dev = dev; in lm3697_probe()
319 led->num_banks = count; in lm3697_probe()
320 led->regmap = devm_regmap_init_i2c(client, &lm3697_regmap_config); in lm3697_probe()
321 if (IS_ERR(led->regmap)) { in lm3697_probe()
322 ret = PTR_ERR(led->regmap); in lm3697_probe()
327 ret = lm3697_probe_dt(led); in lm3697_probe()
331 return lm3697_init(led); in lm3697_probe()
336 struct lm3697 *led = i2c_get_clientdata(client); in lm3697_remove() local
337 struct device *dev = &led->client->dev; in lm3697_remove()
340 ret = regmap_update_bits(led->regmap, LM3697_CTRL_ENABLE, in lm3697_remove()
347 if (led->enable_gpio) in lm3697_remove()
348 gpiod_direction_output(led->enable_gpio, 0); in lm3697_remove()
350 if (led->regulator) { in lm3697_remove()
351 ret = regulator_disable(led->regulator); in lm3697_remove()
356 mutex_destroy(&led->lock); in lm3697_remove()
384 MODULE_DESCRIPTION("Texas Instruments LM3697 LED driver");