Lines Matching +full:led +full:-
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * LED driver for Mediatek MT6323 PMIC
18 * 32K clock common for LED device.
25 * individual clock for LED device.
62 /* Register to LED channel enablement. */
76 * struct mt6323_led - state container for the LED device
77 * @id: the identifier in MT6323 LED device
78 * @parent: the pointer to MT6323 LED controller
79 * @cdev: LED class device for this LED device
80 * @current_brightness: current state of the LED device
90 * struct mt6323_leds - state container for holding LED controller
96 * @led: the array that contains the state of individual
97 * LED device
104 struct mt6323_led *led[MT6323_MAX_LEDS]; member
110 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_hw_brightness() local
111 struct mt6323_leds *leds = led->parent; in mt6323_led_hw_brightness()
112 struct regmap *regmap = leds->hw->regmap; in mt6323_led_hw_brightness()
123 con2_val |= MT6323_ISINK_CH_STEP(brightness - 1) | in mt6323_led_hw_brightness()
127 ret = regmap_update_bits(regmap, MT6323_ISINK_CON2(led->id), in mt6323_led_hw_brightness()
134 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_hw_off() local
135 struct mt6323_leds *leds = led->parent; in mt6323_led_hw_off()
136 struct regmap *regmap = leds->hw->regmap; in mt6323_led_hw_off()
140 status = MT6323_ISINK_CH_EN(led->id); in mt6323_led_hw_off()
142 MT6323_ISINK_CH_EN_MASK(led->id), ~status); in mt6323_led_hw_off()
148 MT6323_RG_ISINK_CK_PDN_MASK(led->id), in mt6323_led_hw_off()
149 MT6323_RG_ISINK_CK_PDN(led->id)); in mt6323_led_hw_off()
159 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_get_led_hw_brightness() local
160 struct mt6323_leds *leds = led->parent; in mt6323_get_led_hw_brightness()
161 struct regmap *regmap = leds->hw->regmap; in mt6323_get_led_hw_brightness()
169 if (status & MT6323_RG_ISINK_CK_PDN_MASK(led->id)) in mt6323_get_led_hw_brightness()
176 if (!(status & MT6323_ISINK_CH_EN(led->id))) in mt6323_get_led_hw_brightness()
179 ret = regmap_read(regmap, MT6323_ISINK_CON2(led->id), &status); in mt6323_get_led_hw_brightness()
190 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_hw_on() local
191 struct mt6323_leds *leds = led->parent; in mt6323_led_hw_on()
192 struct regmap *regmap = leds->hw->regmap; in mt6323_led_hw_on()
202 MT6323_RG_ISINK_CK_SEL_MASK(led->id), 0); in mt6323_led_hw_on()
206 status = MT6323_RG_ISINK_CK_PDN(led->id); in mt6323_led_hw_on()
208 MT6323_RG_ISINK_CK_PDN_MASK(led->id), in mt6323_led_hw_on()
216 MT6323_ISINK_CH_EN_MASK(led->id), in mt6323_led_hw_on()
217 MT6323_ISINK_CH_EN(led->id)); in mt6323_led_hw_on()
225 ret = regmap_update_bits(regmap, MT6323_ISINK_CON0(led->id), in mt6323_led_hw_on()
231 ret = regmap_update_bits(regmap, MT6323_ISINK_CON1(led->id), in mt6323_led_hw_on()
244 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_set_blink() local
245 struct mt6323_leds *leds = led->parent; in mt6323_led_set_blink()
246 struct regmap *regmap = leds->hw->regmap; in mt6323_led_set_blink()
252 * LED subsystem requires a default user in mt6323_led_set_blink()
253 * friendly blink pattern for the LED so using in mt6323_led_set_blink()
269 return -EINVAL; in mt6323_led_set_blink()
273 * which the led is ON. in mt6323_led_set_blink()
279 return -EINVAL; in mt6323_led_set_blink()
281 mutex_lock(&leds->lock); in mt6323_led_set_blink()
286 if (!led->current_brightness) { in mt6323_led_set_blink()
287 ret = mt6323_led_hw_on(cdev, cdev->max_brightness); in mt6323_led_set_blink()
290 led->current_brightness = cdev->max_brightness; in mt6323_led_set_blink()
293 ret = regmap_update_bits(regmap, MT6323_ISINK_CON0(led->id), in mt6323_led_set_blink()
295 MT6323_ISINK_DIM_DUTY(duty_hw - 1)); in mt6323_led_set_blink()
299 ret = regmap_update_bits(regmap, MT6323_ISINK_CON1(led->id), in mt6323_led_set_blink()
301 MT6323_ISINK_DIM_FSEL(period - 1)); in mt6323_led_set_blink()
303 mutex_unlock(&leds->lock); in mt6323_led_set_blink()
311 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_set_brightness() local
312 struct mt6323_leds *leds = led->parent; in mt6323_led_set_brightness()
315 mutex_lock(&leds->lock); in mt6323_led_set_brightness()
317 if (!led->current_brightness && brightness) { in mt6323_led_set_brightness()
331 led->current_brightness = brightness; in mt6323_led_set_brightness()
333 mutex_unlock(&leds->lock); in mt6323_led_set_brightness()
341 struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev); in mt6323_led_set_dt_default() local
345 state = of_get_property(np, "default-state", NULL); in mt6323_led_set_dt_default()
351 led->current_brightness = ret; in mt6323_led_set_dt_default()
355 mt6323_led_set_brightness(cdev, cdev->max_brightness); in mt6323_led_set_dt_default()
366 struct device *dev = &pdev->dev; in mt6323_led_probe()
369 struct mt6397_chip *hw = dev_get_drvdata(dev->parent); in mt6323_led_probe()
371 struct mt6323_led *led; in mt6323_led_probe() local
378 return -ENOMEM; in mt6323_led_probe()
381 leds->dev = dev; in mt6323_led_probe()
384 * leds->hw points to the underlying bus for the register in mt6323_led_probe()
387 leds->hw = hw; in mt6323_led_probe()
388 mutex_init(&leds->lock); in mt6323_led_probe()
391 ret = regmap_update_bits(leds->hw->regmap, MT6323_TOP_CKPDN0, in mt6323_led_probe()
394 dev_err(leds->dev, in mt6323_led_probe()
404 dev_err(dev, "Failed to read led 'reg' property\n"); in mt6323_led_probe()
408 if (reg >= MT6323_MAX_LEDS || leds->led[reg]) { in mt6323_led_probe()
409 dev_err(dev, "Invalid led reg %u\n", reg); in mt6323_led_probe()
410 ret = -EINVAL; in mt6323_led_probe()
414 led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); in mt6323_led_probe()
415 if (!led) { in mt6323_led_probe()
416 ret = -ENOMEM; in mt6323_led_probe()
420 leds->led[reg] = led; in mt6323_led_probe()
421 leds->led[reg]->id = reg; in mt6323_led_probe()
422 leds->led[reg]->cdev.max_brightness = MT6323_MAX_BRIGHTNESS; in mt6323_led_probe()
423 leds->led[reg]->cdev.brightness_set_blocking = in mt6323_led_probe()
425 leds->led[reg]->cdev.blink_set = mt6323_led_set_blink; in mt6323_led_probe()
426 leds->led[reg]->cdev.brightness_get = in mt6323_led_probe()
428 leds->led[reg]->parent = leds; in mt6323_led_probe()
430 ret = mt6323_led_set_dt_default(&leds->led[reg]->cdev, child); in mt6323_led_probe()
432 dev_err(leds->dev, in mt6323_led_probe()
433 "Failed to LED set default from devicetree\n"); in mt6323_led_probe()
439 ret = devm_led_classdev_register_ext(dev, &leds->led[reg]->cdev, in mt6323_led_probe()
442 dev_err(dev, "Failed to register LED: %d\n", ret); in mt6323_led_probe()
460 for (i = 0 ; leds->led[i] ; i++) in mt6323_led_remove()
461 mt6323_led_hw_off(&leds->led[i]->cdev); in mt6323_led_remove()
463 regmap_update_bits(leds->hw->regmap, MT6323_TOP_CKPDN0, in mt6323_led_remove()
467 mutex_destroy(&leds->lock); in mt6323_led_remove()
473 { .compatible = "mediatek,mt6323-led" },
482 .name = "mt6323-led",
489 MODULE_DESCRIPTION("LED driver for Mediatek MT6323 PMIC");