Lines Matching +full:led +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0
2 // TI LM3692x LED chip family driver
3 // Copyright (C) 2017-18 Texas Instruments Incorporated - https://www.ti.com/
18 #define LM36923_MODEL 1
36 #define LM3692X_LED1_EN BIT(1)
45 #define LM3692X_RAMP_RATE_250us BIT(1)
47 #define LM3692X_RAMP_RATE_1ms (BIT(1) | BIT(2))
49 #define LM3692X_RAMP_RATE_4ms (BIT(3) | BIT(1))
51 #define LM3692X_RAMP_RATE_16ms (BIT(1) | BIT(2) | BIT(3))
61 #define LM3692X_PWM_FILTER_150 BIT(1)
62 #define LM3692X_PWM_FILTER_200 (BIT(0) | BIT(1))
75 #define LM3692X_OCP_PROT_1_25A BIT(1)
76 #define LM3692X_OCP_PROT_1_5A (BIT(0) | BIT(1))
86 #define LM3692X_FAULT_CTRL_OCP BIT(1)
92 #define LM3692X_FAULT_FLAG_OCP BIT(1)
101 * @led_dev: LED class device pointer
104 * @regulator: LED supply regulator pointer
105 * @led_enable: LED sync to be enabled
145 static int lm3692x_fault_check(struct lm3692x_led *led) in lm3692x_fault_check() argument
150 ret = regmap_read(led->regmap, LM3692X_FAULT_FLAGS, &read_buf); in lm3692x_fault_check()
155 dev_err(&led->client->dev, "Detected a fault 0x%X\n", read_buf); in lm3692x_fault_check()
160 regmap_read(led->regmap, LM3692X_FAULT_FLAGS, &read_buf); in lm3692x_fault_check()
162 dev_err(&led->client->dev, "Second read of fault flags 0x%X\n", in lm3692x_fault_check()
168 static int lm3692x_leds_enable(struct lm3692x_led *led) in lm3692x_leds_enable() argument
173 if (led->enabled) in lm3692x_leds_enable()
176 if (led->regulator) { in lm3692x_leds_enable()
177 ret = regulator_enable(led->regulator); in lm3692x_leds_enable()
179 dev_err(&led->client->dev, in lm3692x_leds_enable()
185 if (led->enable_gpio) in lm3692x_leds_enable()
186 gpiod_direction_output(led->enable_gpio, 1); in lm3692x_leds_enable()
188 ret = lm3692x_fault_check(led); in lm3692x_leds_enable()
190 dev_err(&led->client->dev, "Cannot read/clear faults: %d\n", in lm3692x_leds_enable()
195 ret = regmap_write(led->regmap, LM3692X_BRT_CTRL, 0x00); in lm3692x_leds_enable()
202 * bit is set to 1. in lm3692x_leds_enable()
205 ret = regmap_write(led->regmap, LM3692X_EN, LM3692X_DEVICE_EN); in lm3692x_leds_enable()
212 ret = regmap_write(led->regmap, LM3692X_BRT_MSB, 0); in lm3692x_leds_enable()
216 ret = regmap_write(led->regmap, LM3692X_BRT_LSB, 0); in lm3692x_leds_enable()
220 ret = regmap_write(led->regmap, LM3692X_PWM_CTRL, in lm3692x_leds_enable()
225 ret = regmap_write(led->regmap, LM3692X_BOOST_CTRL, led->boost_ctrl); in lm3692x_leds_enable()
229 ret = regmap_write(led->regmap, LM3692X_AUTO_FREQ_HI, 0x00); in lm3692x_leds_enable()
233 ret = regmap_write(led->regmap, LM3692X_AUTO_FREQ_LO, 0x00); in lm3692x_leds_enable()
237 ret = regmap_write(led->regmap, LM3692X_BL_ADJ_THRESH, 0x00); in lm3692x_leds_enable()
241 ret = regmap_write(led->regmap, LM3692X_BRT_CTRL, in lm3692x_leds_enable()
246 switch (led->led_enable) { in lm3692x_leds_enable()
249 if (led->model_id == LM36923_MODEL) in lm3692x_leds_enable()
256 case 1: in lm3692x_leds_enable()
264 if (led->model_id == LM36923_MODEL) { in lm3692x_leds_enable()
269 ret = -EINVAL; in lm3692x_leds_enable()
270 dev_err(&led->client->dev, in lm3692x_leds_enable()
275 ret = regmap_update_bits(led->regmap, LM3692X_EN, LM3692X_ENABLE_MASK, in lm3692x_leds_enable()
278 led->enabled = true; in lm3692x_leds_enable()
281 dev_err(&led->client->dev, "Fail writing initialization values\n"); in lm3692x_leds_enable()
283 if (led->enable_gpio) in lm3692x_leds_enable()
284 gpiod_direction_output(led->enable_gpio, 0); in lm3692x_leds_enable()
286 if (led->regulator) { in lm3692x_leds_enable()
287 reg_ret = regulator_disable(led->regulator); in lm3692x_leds_enable()
289 dev_err(&led->client->dev, in lm3692x_leds_enable()
296 static int lm3692x_leds_disable(struct lm3692x_led *led) in lm3692x_leds_disable() argument
300 if (!led->enabled) in lm3692x_leds_disable()
303 ret = regmap_update_bits(led->regmap, LM3692X_EN, LM3692X_DEVICE_EN, 0); in lm3692x_leds_disable()
305 dev_err(&led->client->dev, "Failed to disable regulator: %d\n", in lm3692x_leds_disable()
310 if (led->enable_gpio) in lm3692x_leds_disable()
311 gpiod_direction_output(led->enable_gpio, 0); in lm3692x_leds_disable()
313 if (led->regulator) { in lm3692x_leds_disable()
314 ret = regulator_disable(led->regulator); in lm3692x_leds_disable()
316 dev_err(&led->client->dev, in lm3692x_leds_disable()
320 led->enabled = false; in lm3692x_leds_disable()
327 struct lm3692x_led *led = in lm3692x_brightness_set() local
332 mutex_lock(&led->lock); in lm3692x_brightness_set()
335 ret = lm3692x_leds_disable(led); in lm3692x_brightness_set()
338 lm3692x_leds_enable(led); in lm3692x_brightness_set()
341 ret = lm3692x_fault_check(led); in lm3692x_brightness_set()
343 dev_err(&led->client->dev, "Cannot read/clear faults: %d\n", in lm3692x_brightness_set()
348 ret = regmap_write(led->regmap, LM3692X_BRT_MSB, brt_val); in lm3692x_brightness_set()
350 dev_err(&led->client->dev, "Cannot write MSB: %d\n", ret); in lm3692x_brightness_set()
354 ret = regmap_write(led->regmap, LM3692X_BRT_LSB, led_brightness_lsb); in lm3692x_brightness_set()
356 dev_err(&led->client->dev, "Cannot write LSB: %d\n", ret); in lm3692x_brightness_set()
360 mutex_unlock(&led->lock); in lm3692x_brightness_set()
364 static enum led_brightness lm3692x_max_brightness(struct lm3692x_led *led, in lm3692x_max_brightness() argument
370 max_code = ((max_cur * 1000) - 37806) / 12195; in lm3692x_max_brightness()
377 static int lm3692x_probe_dt(struct lm3692x_led *led) in lm3692x_probe_dt() argument
384 led->enable_gpio = devm_gpiod_get_optional(&led->client->dev, in lm3692x_probe_dt()
386 if (IS_ERR(led->enable_gpio)) { in lm3692x_probe_dt()
387 ret = PTR_ERR(led->enable_gpio); in lm3692x_probe_dt()
388 dev_err(&led->client->dev, "Failed to get enable gpio: %d\n", in lm3692x_probe_dt()
393 led->regulator = devm_regulator_get_optional(&led->client->dev, "vled"); in lm3692x_probe_dt()
394 if (IS_ERR(led->regulator)) { in lm3692x_probe_dt()
395 ret = PTR_ERR(led->regulator); in lm3692x_probe_dt()
396 if (ret != -ENODEV) in lm3692x_probe_dt()
397 return dev_err_probe(&led->client->dev, ret, in lm3692x_probe_dt()
400 led->regulator = NULL; in lm3692x_probe_dt()
403 led->boost_ctrl = LM3692X_BOOST_SW_1MHZ | in lm3692x_probe_dt()
406 ret = device_property_read_u32(&led->client->dev, in lm3692x_probe_dt()
407 "ti,ovp-microvolt", &ovp); in lm3692x_probe_dt()
409 led->boost_ctrl |= LM3692X_OVP_29V; in lm3692x_probe_dt()
415 led->boost_ctrl |= LM3692X_OVP_21V; in lm3692x_probe_dt()
418 led->boost_ctrl |= LM3692X_OVP_25V; in lm3692x_probe_dt()
421 led->boost_ctrl |= LM3692X_OVP_29V; in lm3692x_probe_dt()
424 dev_err(&led->client->dev, "Invalid OVP %d\n", ovp); in lm3692x_probe_dt()
425 return -EINVAL; in lm3692x_probe_dt()
429 child = device_get_next_child_node(&led->client->dev, child); in lm3692x_probe_dt()
431 dev_err(&led->client->dev, "No LED Child node\n"); in lm3692x_probe_dt()
432 return -ENODEV; in lm3692x_probe_dt()
435 ret = fwnode_property_read_u32(child, "reg", &led->led_enable); in lm3692x_probe_dt()
438 dev_err(&led->client->dev, "reg DT property missing\n"); in lm3692x_probe_dt()
442 ret = fwnode_property_read_u32(child, "led-max-microamp", &max_cur); in lm3692x_probe_dt()
443 led->led_dev.max_brightness = ret ? LED_FULL : in lm3692x_probe_dt()
444 lm3692x_max_brightness(led, max_cur); in lm3692x_probe_dt()
447 init_data.devicename = led->client->name; in lm3692x_probe_dt()
450 ret = devm_led_classdev_register_ext(&led->client->dev, &led->led_dev, in lm3692x_probe_dt()
453 dev_err(&led->client->dev, "led register err: %d\n", ret); in lm3692x_probe_dt()
462 struct lm3692x_led *led; in lm3692x_probe() local
465 led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); in lm3692x_probe()
466 if (!led) in lm3692x_probe()
467 return -ENOMEM; in lm3692x_probe()
469 mutex_init(&led->lock); in lm3692x_probe()
470 led->client = client; in lm3692x_probe()
471 led->led_dev.brightness_set_blocking = lm3692x_brightness_set; in lm3692x_probe()
472 led->model_id = id->driver_data; in lm3692x_probe()
473 i2c_set_clientdata(client, led); in lm3692x_probe()
475 led->regmap = devm_regmap_init_i2c(client, &lm3692x_regmap_config); in lm3692x_probe()
476 if (IS_ERR(led->regmap)) { in lm3692x_probe()
477 ret = PTR_ERR(led->regmap); in lm3692x_probe()
478 dev_err(&client->dev, "Failed to allocate register map: %d\n", in lm3692x_probe()
483 ret = lm3692x_probe_dt(led); in lm3692x_probe()
487 ret = lm3692x_leds_enable(led); in lm3692x_probe()
496 struct lm3692x_led *led = i2c_get_clientdata(client); in lm3692x_remove() local
498 lm3692x_leds_disable(led); in lm3692x_remove()
499 mutex_destroy(&led->lock); in lm3692x_remove()
527 MODULE_DESCRIPTION("Texas Instruments LM3692X LED driver");