Lines Matching full:led
3 * LED driver : leds-ktd2692.c
12 #include <linux/led-class-flash.h>
64 /* maximum LED current in movie mode */
66 /* maximum LED current in flash mode */
70 /* max LED brightness level */
75 /* Related LED Flash class device */
95 static void ktd2692_expresswire_start(struct ktd2692_context *led) in ktd2692_expresswire_start() argument
97 gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); in ktd2692_expresswire_start()
101 static void ktd2692_expresswire_reset(struct ktd2692_context *led) in ktd2692_expresswire_reset() argument
103 gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); in ktd2692_expresswire_reset()
107 static void ktd2692_expresswire_end(struct ktd2692_context *led) in ktd2692_expresswire_end() argument
109 gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); in ktd2692_expresswire_end()
111 gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); in ktd2692_expresswire_end()
115 static void ktd2692_expresswire_set_bit(struct ktd2692_context *led, bool bit) in ktd2692_expresswire_set_bit() argument
134 gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); in ktd2692_expresswire_set_bit()
136 gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); in ktd2692_expresswire_set_bit()
139 gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW); in ktd2692_expresswire_set_bit()
141 gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH); in ktd2692_expresswire_set_bit()
146 static void ktd2692_expresswire_write(struct ktd2692_context *led, u8 value) in ktd2692_expresswire_write() argument
150 ktd2692_expresswire_start(led); in ktd2692_expresswire_write()
152 ktd2692_expresswire_set_bit(led, value & BIT(i)); in ktd2692_expresswire_write()
153 ktd2692_expresswire_end(led); in ktd2692_expresswire_write()
160 struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); in ktd2692_led_brightness_set() local
162 mutex_lock(&led->lock); in ktd2692_led_brightness_set()
165 led->mode = KTD2692_MODE_DISABLE; in ktd2692_led_brightness_set()
166 gpiod_direction_output(led->aux_gpio, KTD2692_LOW); in ktd2692_led_brightness_set()
168 ktd2692_expresswire_write(led, brightness | in ktd2692_led_brightness_set()
170 led->mode = KTD2692_MODE_MOVIE; in ktd2692_led_brightness_set()
173 ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); in ktd2692_led_brightness_set()
174 mutex_unlock(&led->lock); in ktd2692_led_brightness_set()
182 struct ktd2692_context *led = fled_cdev_to_led(fled_cdev); in ktd2692_led_flash_strobe_set() local
186 mutex_lock(&led->lock); in ktd2692_led_flash_strobe_set()
190 ktd2692_expresswire_write(led, flash_tm_reg in ktd2692_led_flash_strobe_set()
193 led->mode = KTD2692_MODE_FLASH; in ktd2692_led_flash_strobe_set()
194 gpiod_direction_output(led->aux_gpio, KTD2692_HIGH); in ktd2692_led_flash_strobe_set()
196 led->mode = KTD2692_MODE_DISABLE; in ktd2692_led_flash_strobe_set()
197 gpiod_direction_output(led->aux_gpio, KTD2692_LOW); in ktd2692_led_flash_strobe_set()
200 ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE); in ktd2692_led_flash_strobe_set()
203 led->mode = KTD2692_MODE_DISABLE; in ktd2692_led_flash_strobe_set()
205 mutex_unlock(&led->lock); in ktd2692_led_flash_strobe_set()
247 static void ktd2692_setup(struct ktd2692_context *led) in ktd2692_setup() argument
249 led->mode = KTD2692_MODE_DISABLE; in ktd2692_setup()
250 ktd2692_expresswire_reset(led); in ktd2692_setup()
251 gpiod_direction_output(led->aux_gpio, KTD2692_LOW); in ktd2692_setup()
253 ktd2692_expresswire_write(led, (KTD2692_MM_MIN_CURR_THRESHOLD_SCALE - 1) in ktd2692_setup()
255 ktd2692_expresswire_write(led, KTD2692_FLASH_MODE_CURR_PERCENT(45) in ktd2692_setup()
262 struct ktd2692_context *led = dev_get_drvdata(dev); in regulator_disable_action() local
265 ret = regulator_disable(led->regulator); in regulator_disable_action()
270 static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev, in ktd2692_parse_dt() argument
280 led->ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_ASIS); in ktd2692_parse_dt()
281 ret = PTR_ERR_OR_ZERO(led->ctrl_gpio); in ktd2692_parse_dt()
285 led->aux_gpio = devm_gpiod_get_optional(dev, "aux", GPIOD_ASIS); in ktd2692_parse_dt()
286 if (IS_ERR(led->aux_gpio)) in ktd2692_parse_dt()
287 return dev_err_probe(dev, PTR_ERR(led->aux_gpio), "cannot get aux-gpios\n"); in ktd2692_parse_dt()
289 led->regulator = devm_regulator_get(dev, "vin"); in ktd2692_parse_dt()
290 if (IS_ERR(led->regulator)) in ktd2692_parse_dt()
291 led->regulator = NULL; in ktd2692_parse_dt()
293 if (led->regulator) { in ktd2692_parse_dt()
294 ret = regulator_enable(led->regulator); in ktd2692_parse_dt()
307 dev_err(dev, "No DT child node found for connected LED.\n"); in ktd2692_parse_dt()
311 led->fled_cdev.led_cdev.name = in ktd2692_parse_dt()
314 ret = of_property_read_u32(child_node, "led-max-microamp", in ktd2692_parse_dt()
317 dev_err(dev, "failed to parse led-max-microamp\n"); in ktd2692_parse_dt()
347 struct ktd2692_context *led; in ktd2692_probe() local
353 led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); in ktd2692_probe()
354 if (!led) in ktd2692_probe()
357 fled_cdev = &led->fled_cdev; in ktd2692_probe()
360 ret = ktd2692_parse_dt(led, &pdev->dev, &led_cfg); in ktd2692_probe()
373 mutex_init(&led->lock); in ktd2692_probe()
375 platform_set_drvdata(pdev, led); in ktd2692_probe()
379 dev_err(&pdev->dev, "can't register LED %s\n", led_cdev->name); in ktd2692_probe()
380 mutex_destroy(&led->lock); in ktd2692_probe()
384 ktd2692_setup(led); in ktd2692_probe()
391 struct ktd2692_context *led = platform_get_drvdata(pdev); in ktd2692_remove() local
393 led_classdev_flash_unregister(&led->fled_cdev); in ktd2692_remove()
395 mutex_destroy(&led->lock); in ktd2692_remove()
418 MODULE_DESCRIPTION("Kinetic KTD2692 LED driver");