Lines Matching +full:led +full:- +full:3

1 // SPDX-License-Identifier: GPL-2.0+
2 // Driver for Awinic AW2013 3-channel LED driver
12 #define AW2013_MAX_LEDS 3
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 */
38 #define AW2013_LEDT0(x) (0x37 + (x) * 3)
39 #define AW2013_LEDT0_T1(x) ((x) << 4) // Should be 0-7
40 #define AW2013_LEDT0_T2(x) (x) // Should be 0-5
42 #define AW2013_LEDT1(x) (0x38 + (x) * 3)
43 #define AW2013_LEDT1_T3(x) ((x) << 4) // Should be 0-7
44 #define AW2013_LEDT1_T4(x) (x) // Should be 0-7
46 #define AW2013_LEDT2(x) (0x39 + (x) * 3)
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_bulk_disable(ARRAY_SIZE(chip->regulators), in aw2013_chip_disable()
110 chip->regulators); in aw2013_chip_disable()
112 dev_err(&chip->client->dev, in aw2013_chip_disable()
117 chip->enabled = false; in aw2013_chip_disable()
124 if (chip->enabled) in aw2013_chip_enable()
127 ret = regulator_bulk_enable(ARRAY_SIZE(chip->regulators), in aw2013_chip_enable()
128 chip->regulators); in aw2013_chip_enable()
130 dev_err(&chip->client->dev, in aw2013_chip_enable()
134 chip->enabled = true; in aw2013_chip_enable()
147 for (i = 0; i < chip->num_leds; i++) in aw2013_chip_in_use()
148 if (chip->leds[i].cdev.brightness) in aw2013_chip_in_use()
157 struct aw2013_led *led = container_of(cdev, struct aw2013_led, cdev); in aw2013_brightness_set() local
160 mutex_lock(&led->chip->mutex); in aw2013_brightness_set()
162 if (aw2013_chip_in_use(led->chip)) { in aw2013_brightness_set()
163 ret = aw2013_chip_enable(led->chip); in aw2013_brightness_set()
168 num = led->num; in aw2013_brightness_set()
170 ret = regmap_write(led->chip->regmap, AW2013_REG_PWM(num), brightness); in aw2013_brightness_set()
175 ret = regmap_update_bits(led->chip->regmap, AW2013_LCTR, in aw2013_brightness_set()
178 ret = regmap_update_bits(led->chip->regmap, AW2013_LCTR, in aw2013_brightness_set()
182 ret = regmap_update_bits(led->chip->regmap, AW2013_LCFG(num), in aw2013_brightness_set()
188 if (!aw2013_chip_in_use(led->chip)) in aw2013_brightness_set()
189 aw2013_chip_disable(led->chip); in aw2013_brightness_set()
192 mutex_unlock(&led->chip->mutex); in aw2013_brightness_set()
200 struct aw2013_led *led = container_of(cdev, struct aw2013_led, cdev); in aw2013_blink_set() local
201 int ret, num = led->num; in aw2013_blink_set()
210 if (!led->cdev.brightness) { in aw2013_blink_set()
211 led->cdev.brightness = LED_FULL; in aw2013_blink_set()
212 ret = aw2013_brightness_set(&led->cdev, led->cdev.brightness); in aw2013_blink_set()
217 /* Never on - just set to off */ in aw2013_blink_set()
219 led->cdev.brightness = LED_OFF; in aw2013_blink_set()
220 return aw2013_brightness_set(&led->cdev, LED_OFF); in aw2013_blink_set()
223 mutex_lock(&led->chip->mutex); in aw2013_blink_set()
225 /* Never off - brightness is already set, disable blinking */ in aw2013_blink_set()
227 ret = regmap_update_bits(led->chip->regmap, AW2013_LCFG(num), in aw2013_blink_set()
233 off = min(5, ilog2((*delay_off - 1) / AW2013_TIME_STEP) + 1); in aw2013_blink_set()
234 on = min(7, ilog2((*delay_on - 1) / AW2013_TIME_STEP) + 1); in aw2013_blink_set()
240 ret = regmap_write(led->chip->regmap, in aw2013_blink_set()
244 ret = regmap_write(led->chip->regmap, in aw2013_blink_set()
249 /* Finally, enable the LED */ in aw2013_blink_set()
250 ret = regmap_update_bits(led->chip->regmap, AW2013_LCFG(num), in aw2013_blink_set()
255 ret = regmap_update_bits(led->chip->regmap, AW2013_LCTR, in aw2013_blink_set()
259 mutex_unlock(&led->chip->mutex); in aw2013_blink_set()
266 struct device_node *np = dev_of_node(&chip->client->dev); in aw2013_probe_dt()
268 struct aw2013_led *led; in aw2013_probe_dt() local
272 return -EINVAL; in aw2013_probe_dt()
274 regmap_write(chip->regmap, AW2013_RSTR, AW2013_RSTR_RESET); in aw2013_probe_dt()
283 dev_err(&chip->client->dev, in aw2013_probe_dt()
284 "Couldn't read LED address: %d\n", ret); in aw2013_probe_dt()
285 count--; in aw2013_probe_dt()
289 led = &chip->leds[i]; in aw2013_probe_dt()
290 led->num = source; in aw2013_probe_dt()
291 led->chip = chip; in aw2013_probe_dt()
294 if (!of_property_read_u32(child, "led-max-microamp", &imax)) { in aw2013_probe_dt()
295 led->imax = min_t(u32, imax / 5000, 3); in aw2013_probe_dt()
297 led->imax = 1; // 5mA in aw2013_probe_dt()
298 dev_info(&chip->client->dev, in aw2013_probe_dt()
299 "DT property led-max-microamp is missing\n"); in aw2013_probe_dt()
302 led->cdev.brightness_set_blocking = aw2013_brightness_set; in aw2013_probe_dt()
303 led->cdev.blink_set = aw2013_blink_set; in aw2013_probe_dt()
305 ret = devm_led_classdev_register_ext(&chip->client->dev, in aw2013_probe_dt()
306 &led->cdev, &init_data); in aw2013_probe_dt()
314 return -EINVAL; in aw2013_probe_dt()
316 chip->num_leds = i; in aw2013_probe_dt()
338 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in aw2013_probe()
340 return -ENOMEM; in aw2013_probe()
342 ret = devm_mutex_init(&client->dev, &chip->mutex); in aw2013_probe()
346 mutex_lock(&chip->mutex); in aw2013_probe()
348 chip->client = client; in aw2013_probe()
351 chip->regmap = devm_regmap_init_i2c(client, &aw2013_regmap_config); in aw2013_probe()
352 if (IS_ERR(chip->regmap)) { in aw2013_probe()
353 ret = PTR_ERR(chip->regmap); in aw2013_probe()
354 dev_err(&client->dev, "Failed to allocate register map: %d\n", in aw2013_probe()
359 chip->regulators[0].supply = "vcc"; in aw2013_probe()
360 chip->regulators[1].supply = "vio"; in aw2013_probe()
361 ret = devm_regulator_bulk_get(&client->dev, in aw2013_probe()
362 ARRAY_SIZE(chip->regulators), in aw2013_probe()
363 chip->regulators); in aw2013_probe()
365 if (ret != -EPROBE_DEFER) in aw2013_probe()
366 dev_err(&client->dev, in aw2013_probe()
371 ret = regulator_bulk_enable(ARRAY_SIZE(chip->regulators), in aw2013_probe()
372 chip->regulators); in aw2013_probe()
374 dev_err(&client->dev, in aw2013_probe()
379 ret = regmap_read(chip->regmap, AW2013_RSTR, &chipid); in aw2013_probe()
381 dev_err(&client->dev, "Failed to read chip ID: %d\n", in aw2013_probe()
387 dev_err(&client->dev, "Chip reported wrong ID: %x\n", in aw2013_probe()
389 ret = -ENODEV; in aw2013_probe()
393 ret = devm_add_action(&client->dev, aw2013_chip_disable_action, chip); in aw2013_probe()
401 ret = regulator_bulk_disable(ARRAY_SIZE(chip->regulators), in aw2013_probe()
402 chip->regulators); in aw2013_probe()
404 dev_err(&client->dev, in aw2013_probe()
409 mutex_unlock(&chip->mutex); in aw2013_probe()
414 regulator_bulk_disable(ARRAY_SIZE(chip->regulators), in aw2013_probe()
415 chip->regulators); in aw2013_probe()
418 mutex_unlock(&chip->mutex); in aw2013_probe()
431 .name = "leds-aw2013",
440 MODULE_DESCRIPTION("AW2013 LED driver");