Lines Matching +full:led +full:- +full:2

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * LED driver for Mediatek MT6323 PMIC
18 * 32K clock common for LED device.
30 * individual clock for LED device.
60 /* Register to LED channel enablement. */
69 * struct mt6323_led - state container for the LED device
70 * @id: the identifier in MT6323 LED device
71 * @parent: the pointer to MT6323 LED controller
72 * @cdev: LED class device for this LED device
73 * @current_brightness: current state of the LED device
83 * struct mt6323_regs - register spec for the LED device
107 * struct mt6323_hwspec - hardware specific parameters
123 * struct mt6323_data - device specific data
133 * struct mt6323_leds - state container for holding LED controller
140 * @led: the array that contains the state of individual
141 * LED device
149 struct mt6323_led *led[MAX_SUPPORTED_LEDS]; member
155 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_hw_brightness() local
156 struct mt6323_leds *leds = led->parent; in mt6323_led_hw_brightness()
157 const struct mt6323_regs *regs = leds->pdata->regs; in mt6323_led_hw_brightness()
158 struct regmap *regmap = leds->hw->regmap; in mt6323_led_hw_brightness()
169 con2_val |= ISINK_CH_STEP(brightness - 1) | in mt6323_led_hw_brightness()
170 ISINK_SFSTR0_TC(2) | in mt6323_led_hw_brightness()
173 ret = regmap_update_bits(regmap, ISINK_CON(regs->isink_con[2], led->id), in mt6323_led_hw_brightness()
180 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_hw_off() local
181 struct mt6323_leds *leds = led->parent; in mt6323_led_hw_off()
182 const struct mt6323_regs *regs = leds->pdata->regs; in mt6323_led_hw_off()
183 struct regmap *regmap = leds->hw->regmap; in mt6323_led_hw_off()
187 status = ISINK_CH_EN(led->id); in mt6323_led_hw_off()
188 ret = regmap_update_bits(regmap, regs->isink_en_ctrl, in mt6323_led_hw_off()
189 ISINK_CH_EN_MASK(led->id), ~status); in mt6323_led_hw_off()
194 ret = regmap_update_bits(regmap, regs->top_ckpdn[2], in mt6323_led_hw_off()
195 RG_ISINK_CK_PDN_MASK(led->id), in mt6323_led_hw_off()
196 RG_ISINK_CK_PDN(led->id)); in mt6323_led_hw_off()
206 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_get_led_hw_brightness() local
207 struct mt6323_leds *leds = led->parent; in mt6323_get_led_hw_brightness()
208 const struct mt6323_regs *regs = leds->pdata->regs; in mt6323_get_led_hw_brightness()
209 struct regmap *regmap = leds->hw->regmap; in mt6323_get_led_hw_brightness()
213 ret = regmap_read(regmap, regs->top_ckpdn[2], &status); in mt6323_get_led_hw_brightness()
217 if (status & RG_ISINK_CK_PDN_MASK(led->id)) in mt6323_get_led_hw_brightness()
220 ret = regmap_read(regmap, regs->isink_en_ctrl, &status); in mt6323_get_led_hw_brightness()
224 if (!(status & ISINK_CH_EN(led->id))) in mt6323_get_led_hw_brightness()
227 ret = regmap_read(regmap, ISINK_CON(regs->isink_con[2], led->id), &status); in mt6323_get_led_hw_brightness()
238 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_hw_on() local
239 struct mt6323_leds *leds = led->parent; in mt6323_led_hw_on()
240 const struct mt6323_regs *regs = leds->pdata->regs; in mt6323_led_hw_on()
241 struct regmap *regmap = leds->hw->regmap; in mt6323_led_hw_on()
250 ret = regmap_update_bits(regmap, regs->top_ckcon[1], in mt6323_led_hw_on()
251 RG_ISINK_CK_SEL_MASK(led->id), 0); in mt6323_led_hw_on()
255 status = RG_ISINK_CK_PDN(led->id); in mt6323_led_hw_on()
256 ret = regmap_update_bits(regmap, regs->top_ckpdn[2], in mt6323_led_hw_on()
257 RG_ISINK_CK_PDN_MASK(led->id), in mt6323_led_hw_on()
264 ret = regmap_update_bits(regmap, regs->isink_en_ctrl, in mt6323_led_hw_on()
265 ISINK_CH_EN_MASK(led->id), in mt6323_led_hw_on()
266 ISINK_CH_EN(led->id)); in mt6323_led_hw_on()
274 ret = regmap_update_bits(regmap, ISINK_CON(regs->isink_con[0], led->id), in mt6323_led_hw_on()
280 ret = regmap_update_bits(regmap, ISINK_CON(regs->isink_con[1], led->id), in mt6323_led_hw_on()
293 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_set_blink() local
294 struct mt6323_leds *leds = led->parent; in mt6323_led_set_blink()
295 const struct mt6323_regs *regs = leds->pdata->regs; in mt6323_led_set_blink()
296 const struct mt6323_hwspec *spec = leds->pdata->spec; in mt6323_led_set_blink()
297 struct regmap *regmap = leds->hw->regmap; in mt6323_led_set_blink()
303 * LED subsystem requires a default user in mt6323_led_set_blink()
304 * friendly blink pattern for the LED so using in mt6323_led_set_blink()
319 if (period > spec->max_period) in mt6323_led_set_blink()
320 return -EINVAL; in mt6323_led_set_blink()
324 * which the led is ON. in mt6323_led_set_blink()
326 duty_hw = DIV_ROUND_CLOSEST(*delay_on * 100000ul, period * spec->unit_duty); in mt6323_led_set_blink()
330 return -EINVAL; in mt6323_led_set_blink()
332 mutex_lock(&leds->lock); in mt6323_led_set_blink()
337 if (!led->current_brightness) { in mt6323_led_set_blink()
338 ret = mt6323_led_hw_on(cdev, cdev->max_brightness); in mt6323_led_set_blink()
341 led->current_brightness = cdev->max_brightness; in mt6323_led_set_blink()
344 ret = regmap_update_bits(regmap, ISINK_CON(regs->isink_con[0], led->id), in mt6323_led_set_blink()
346 ISINK_DIM_DUTY(duty_hw - 1)); in mt6323_led_set_blink()
350 ret = regmap_update_bits(regmap, ISINK_CON(regs->isink_con[1], led->id), in mt6323_led_set_blink()
352 ISINK_DIM_FSEL(period - 1)); in mt6323_led_set_blink()
354 mutex_unlock(&leds->lock); in mt6323_led_set_blink()
362 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_set_brightness() local
363 struct mt6323_leds *leds = led->parent; in mt6323_led_set_brightness()
366 mutex_lock(&leds->lock); in mt6323_led_set_brightness()
368 if (!led->current_brightness && brightness) { in mt6323_led_set_brightness()
382 led->current_brightness = brightness; in mt6323_led_set_brightness()
384 mutex_unlock(&leds->lock); in mt6323_led_set_brightness()
391 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mtk_wled_hw_on() local
392 struct mt6323_leds *leds = led->parent; in mtk_wled_hw_on()
393 const struct mt6323_regs *regs = leds->pdata->regs; in mtk_wled_hw_on()
394 struct regmap *regmap = leds->hw->regmap; in mtk_wled_hw_on()
397 ret = regmap_clear_bits(regmap, regs->top_ckpdn[0], RG_VWLED_32K_CK_PDN); in mtk_wled_hw_on()
401 ret = regmap_clear_bits(regmap, regs->top_ckpdn[0], RG_VWLED_6M_CK_PDN); in mtk_wled_hw_on()
405 ret = regmap_clear_bits(regmap, regs->top_ckpdn[0], RG_VWLED_1M_CK_PDN); in mtk_wled_hw_on()
412 ret = regmap_set_bits(regmap, regs->iwled_en_ctrl, BIT(led->id)); in mtk_wled_hw_on()
416 ret = regmap_set_bits(regmap, regs->iwled_en_ctrl, BIT(led->id + 1)); in mtk_wled_hw_on()
425 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mtk_wled_hw_off() local
426 struct mt6323_leds *leds = led->parent; in mtk_wled_hw_off()
427 const struct mt6323_regs *regs = leds->pdata->regs; in mtk_wled_hw_off()
428 struct regmap *regmap = leds->hw->regmap; in mtk_wled_hw_off()
431 ret = regmap_clear_bits(regmap, regs->iwled_en_ctrl, BIT(led->id + 1)); in mtk_wled_hw_off()
435 ret = regmap_clear_bits(regmap, regs->iwled_en_ctrl, BIT(led->id)); in mtk_wled_hw_off()
439 ret = regmap_set_bits(regmap, regs->top_ckpdn[0], RG_VWLED_32K_CK_PDN); in mtk_wled_hw_off()
443 ret = regmap_set_bits(regmap, regs->top_ckpdn[0], RG_VWLED_6M_CK_PDN); in mtk_wled_hw_off()
447 ret = regmap_set_bits(regmap, regs->top_ckpdn[0], RG_VWLED_1M_CK_PDN); in mtk_wled_hw_off()
456 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_get_wled_brightness() local
457 struct mt6323_leds *leds = led->parent; in mt6323_get_wled_brightness()
458 const struct mt6323_regs *regs = leds->pdata->regs; in mt6323_get_wled_brightness()
459 struct regmap *regmap = leds->hw->regmap; in mt6323_get_wled_brightness()
463 ret = regmap_read(regmap, regs->iwled_en_ctrl, &status); in mt6323_get_wled_brightness()
468 status &= BIT(led->id) | BIT(led->id + 1); in mt6323_get_wled_brightness()
470 return status ? led->current_brightness : 0; in mt6323_get_wled_brightness()
476 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_wled_set_brightness() local
477 struct mt6323_leds *leds = led->parent; in mt6323_wled_set_brightness()
480 mutex_lock(&leds->lock); in mt6323_wled_set_brightness()
483 if (!led->current_brightness) in mt6323_wled_set_brightness()
493 led->current_brightness = brightness; in mt6323_wled_set_brightness()
495 mutex_unlock(&leds->lock); in mt6323_wled_set_brightness()
503 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_set_dt_default() local
510 ret = mt6323_led_set_brightness(cdev, cdev->max_brightness); in mt6323_led_set_dt_default()
516 led->current_brightness = ret; in mt6323_led_set_dt_default()
528 struct device *dev = &pdev->dev; in mt6323_led_probe()
531 struct mt6397_chip *hw = dev_get_drvdata(dev->parent); in mt6323_led_probe()
533 struct mt6323_led *led; in mt6323_led_probe() local
543 return -ENOMEM; in mt6323_led_probe()
546 leds->dev = dev; in mt6323_led_probe()
547 leds->pdata = device_get_match_data(dev); in mt6323_led_probe()
548 regs = leds->pdata->regs; in mt6323_led_probe()
549 spec = leds->pdata->spec; in mt6323_led_probe()
550 max_leds = spec->max_leds + spec->max_wleds; in mt6323_led_probe()
553 * leds->hw points to the underlying bus for the register in mt6323_led_probe()
556 leds->hw = hw; in mt6323_led_probe()
557 mutex_init(&leds->lock); in mt6323_led_probe()
560 ret = regmap_update_bits(leds->hw->regmap, regs->top_ckpdn[0], in mt6323_led_probe()
563 dev_err(leds->dev, in mt6323_led_probe()
574 dev_err(dev, "Failed to read led 'reg' property\n"); in mt6323_led_probe()
579 leds->led[reg]) { in mt6323_led_probe()
580 dev_err(dev, "Invalid led reg %u\n", reg); in mt6323_led_probe()
581 ret = -EINVAL; in mt6323_led_probe()
585 led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); in mt6323_led_probe()
586 if (!led) { in mt6323_led_probe()
587 ret = -ENOMEM; in mt6323_led_probe()
591 is_wled = of_property_read_bool(child, "mediatek,is-wled"); in mt6323_led_probe()
593 leds->led[reg] = led; in mt6323_led_probe()
594 leds->led[reg]->id = reg; in mt6323_led_probe()
595 leds->led[reg]->cdev.max_brightness = spec->max_brightness; in mt6323_led_probe()
598 leds->led[reg]->cdev.brightness_set_blocking = in mt6323_led_probe()
600 leds->led[reg]->cdev.brightness_get = in mt6323_led_probe()
603 leds->led[reg]->cdev.brightness_set_blocking = in mt6323_led_probe()
605 leds->led[reg]->cdev.blink_set = mt6323_led_set_blink; in mt6323_led_probe()
606 leds->led[reg]->cdev.brightness_get = in mt6323_led_probe()
609 leds->led[reg]->parent = leds; in mt6323_led_probe()
611 ret = mt6323_led_set_dt_default(&leds->led[reg]->cdev, child); in mt6323_led_probe()
613 dev_err(leds->dev, in mt6323_led_probe()
614 "Failed to LED set default from devicetree\n"); in mt6323_led_probe()
620 ret = devm_led_classdev_register_ext(dev, &leds->led[reg]->cdev, in mt6323_led_probe()
623 dev_err(dev, "Failed to register LED: %d\n", ret); in mt6323_led_probe()
638 const struct mt6323_regs *regs = leds->pdata->regs; in mt6323_led_remove()
642 for (i = 0 ; leds->led[i] ; i++) in mt6323_led_remove()
643 mt6323_led_hw_off(&leds->led[i]->cdev); in mt6323_led_remove()
645 regmap_update_bits(leds->hw->regmap, regs->top_ckpdn[0], in mt6323_led_remove()
649 mutex_destroy(&leds->lock); in mt6323_led_remove()
658 .num_top_ckcon = 2,
669 .num_top_ckcon = 2,
680 .num_top_ckcon = 2,
683 .isink_max_regs = 12, /* IWLED[0..2, 3..9] */
717 { .compatible = "mediatek,mt6323-led", .data = &mt6323_pdata},
718 { .compatible = "mediatek,mt6331-led", .data = &mt6331_pdata },
719 { .compatible = "mediatek,mt6332-led", .data = &mt6332_pdata },
728 .name = "mt6323-led",
735 MODULE_DESCRIPTION("LED driver for Mediatek MT6323 PMIC");