Lines Matching +full:led +full:- +full:7
1 // SPDX-License-Identifier: GPL-2.0+
2 // Driver for Awinic AW2013 3-channel LED driver
23 /* LED channel enable register */
27 /* LED channel control registers */
29 #define AW2013_LCFG_IMAX_MASK (BIT(0) | BIT(1)) // Should be 0-3
34 /* LED channel PWM registers */
37 /* LED channel timing registers */
39 #define AW2013_LEDT0_T1(x) ((x) << 4) // Should be 0-7
40 #define AW2013_LEDT0_T2(x) (x) // Should be 0-5
43 #define AW2013_LEDT1_T3(x) ((x) << 4) // Should be 0-7
44 #define AW2013_LEDT1_T4(x) (x) // Should be 0-7
47 #define AW2013_LEDT2_T0(x) ((x) << 4) // Should be 0-8
48 #define AW2013_LEDT2_REPEAT(x) (x) // Should be 0-15
77 ret = regmap_write(chip->regmap, AW2013_GCR, AW2013_GCR_ENABLE); in aw2013_chip_init()
79 dev_err(&chip->client->dev, "Failed to enable the chip: %d\n", in aw2013_chip_init()
84 for (i = 0; i < chip->num_leds; i++) { in aw2013_chip_init()
85 ret = regmap_update_bits(chip->regmap, in aw2013_chip_init()
86 AW2013_LCFG(chip->leds[i].num), in aw2013_chip_init()
88 chip->leds[i].imax); in aw2013_chip_init()
90 dev_err(&chip->client->dev, in aw2013_chip_init()
91 "Failed to set maximum current for led %d: %d\n", in aw2013_chip_init()
92 chip->leds[i].num, ret); in aw2013_chip_init()
104 if (!chip->enabled) in aw2013_chip_disable()
107 regmap_write(chip->regmap, AW2013_GCR, 0); in aw2013_chip_disable()
109 ret = regulator_disable(chip->vcc_regulator); in aw2013_chip_disable()
111 dev_err(&chip->client->dev, in aw2013_chip_disable()
116 chip->enabled = false; in aw2013_chip_disable()
123 if (chip->enabled) in aw2013_chip_enable()
126 ret = regulator_enable(chip->vcc_regulator); in aw2013_chip_enable()
128 dev_err(&chip->client->dev, in aw2013_chip_enable()
132 chip->enabled = true; in aw2013_chip_enable()
145 for (i = 0; i < chip->num_leds; i++) in aw2013_chip_in_use()
146 if (chip->leds[i].cdev.brightness) in aw2013_chip_in_use()
155 struct aw2013_led *led = container_of(cdev, struct aw2013_led, cdev); in aw2013_brightness_set() local
158 mutex_lock(&led->chip->mutex); in aw2013_brightness_set()
160 if (aw2013_chip_in_use(led->chip)) { in aw2013_brightness_set()
161 ret = aw2013_chip_enable(led->chip); in aw2013_brightness_set()
166 num = led->num; in aw2013_brightness_set()
168 ret = regmap_write(led->chip->regmap, AW2013_REG_PWM(num), brightness); in aw2013_brightness_set()
173 ret = regmap_update_bits(led->chip->regmap, AW2013_LCTR, in aw2013_brightness_set()
176 ret = regmap_update_bits(led->chip->regmap, AW2013_LCTR, in aw2013_brightness_set()
180 ret = regmap_update_bits(led->chip->regmap, AW2013_LCFG(num), in aw2013_brightness_set()
186 if (!aw2013_chip_in_use(led->chip)) in aw2013_brightness_set()
187 aw2013_chip_disable(led->chip); in aw2013_brightness_set()
190 mutex_unlock(&led->chip->mutex); in aw2013_brightness_set()
198 struct aw2013_led *led = container_of(cdev, struct aw2013_led, cdev); in aw2013_blink_set() local
199 int ret, num = led->num; in aw2013_blink_set()
208 if (!led->cdev.brightness) { in aw2013_blink_set()
209 led->cdev.brightness = LED_FULL; in aw2013_blink_set()
210 ret = aw2013_brightness_set(&led->cdev, led->cdev.brightness); in aw2013_blink_set()
215 /* Never on - just set to off */ in aw2013_blink_set()
217 led->cdev.brightness = LED_OFF; in aw2013_blink_set()
218 return aw2013_brightness_set(&led->cdev, LED_OFF); in aw2013_blink_set()
221 mutex_lock(&led->chip->mutex); in aw2013_blink_set()
223 /* Never off - brightness is already set, disable blinking */ in aw2013_blink_set()
225 ret = regmap_update_bits(led->chip->regmap, AW2013_LCFG(num), in aw2013_blink_set()
231 off = min(5, ilog2((*delay_off - 1) / AW2013_TIME_STEP) + 1); in aw2013_blink_set()
232 on = min(7, ilog2((*delay_on - 1) / AW2013_TIME_STEP) + 1); in aw2013_blink_set()
238 ret = regmap_write(led->chip->regmap, in aw2013_blink_set()
242 ret = regmap_write(led->chip->regmap, in aw2013_blink_set()
247 /* Finally, enable the LED */ in aw2013_blink_set()
248 ret = regmap_update_bits(led->chip->regmap, AW2013_LCFG(num), in aw2013_blink_set()
253 ret = regmap_update_bits(led->chip->regmap, AW2013_LCTR, in aw2013_blink_set()
257 mutex_unlock(&led->chip->mutex); in aw2013_blink_set()
264 struct device_node *np = dev_of_node(&chip->client->dev), *child; in aw2013_probe_dt()
266 struct aw2013_led *led; in aw2013_probe_dt() local
270 return -EINVAL; in aw2013_probe_dt()
272 regmap_write(chip->regmap, AW2013_RSTR, AW2013_RSTR_RESET); in aw2013_probe_dt()
281 dev_err(&chip->client->dev, in aw2013_probe_dt()
282 "Couldn't read LED address: %d\n", ret); in aw2013_probe_dt()
283 count--; in aw2013_probe_dt()
287 led = &chip->leds[i]; in aw2013_probe_dt()
288 led->num = source; in aw2013_probe_dt()
289 led->chip = chip; in aw2013_probe_dt()
292 if (!of_property_read_u32(child, "led-max-microamp", &imax)) { in aw2013_probe_dt()
293 led->imax = min_t(u32, imax / 5000, 3); in aw2013_probe_dt()
295 led->imax = 1; // 5mA in aw2013_probe_dt()
296 dev_info(&chip->client->dev, in aw2013_probe_dt()
297 "DT property led-max-microamp is missing\n"); in aw2013_probe_dt()
300 led->cdev.brightness_set_blocking = aw2013_brightness_set; in aw2013_probe_dt()
301 led->cdev.blink_set = aw2013_blink_set; in aw2013_probe_dt()
303 ret = devm_led_classdev_register_ext(&chip->client->dev, in aw2013_probe_dt()
304 &led->cdev, &init_data); in aw2013_probe_dt()
314 return -EINVAL; in aw2013_probe_dt()
316 chip->num_leds = i; in aw2013_probe_dt()
333 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in aw2013_probe()
335 return -ENOMEM; in aw2013_probe()
337 mutex_init(&chip->mutex); in aw2013_probe()
338 mutex_lock(&chip->mutex); in aw2013_probe()
340 chip->client = client; in aw2013_probe()
343 chip->regmap = devm_regmap_init_i2c(client, &aw2013_regmap_config); in aw2013_probe()
344 if (IS_ERR(chip->regmap)) { in aw2013_probe()
345 ret = PTR_ERR(chip->regmap); in aw2013_probe()
346 dev_err(&client->dev, "Failed to allocate register map: %d\n", in aw2013_probe()
351 chip->vcc_regulator = devm_regulator_get(&client->dev, "vcc"); in aw2013_probe()
352 ret = PTR_ERR_OR_ZERO(chip->vcc_regulator); in aw2013_probe()
354 if (ret != -EPROBE_DEFER) in aw2013_probe()
355 dev_err(&client->dev, in aw2013_probe()
360 ret = regulator_enable(chip->vcc_regulator); in aw2013_probe()
362 dev_err(&client->dev, in aw2013_probe()
367 ret = regmap_read(chip->regmap, AW2013_RSTR, &chipid); in aw2013_probe()
369 dev_err(&client->dev, "Failed to read chip ID: %d\n", in aw2013_probe()
375 dev_err(&client->dev, "Chip reported wrong ID: %x\n", in aw2013_probe()
377 ret = -ENODEV; in aw2013_probe()
385 ret = regulator_disable(chip->vcc_regulator); in aw2013_probe()
387 dev_err(&client->dev, in aw2013_probe()
392 mutex_unlock(&chip->mutex); in aw2013_probe()
397 regulator_disable(chip->vcc_regulator); in aw2013_probe()
400 mutex_destroy(&chip->mutex); in aw2013_probe()
410 mutex_destroy(&chip->mutex); in aw2013_remove()
424 .name = "leds-aw2013",
434 MODULE_DESCRIPTION("AW2013 LED driver");