Lines Matching +full:led +full:- +full:current +full:- +full:microamp
1 // SPDX-License-Identifier: GPL-2.0
3 * Awinic AW20036/AW20054/AW20072/AW20108 LED driver
23 #define AW200XX_DIM_MAX (BIT(6) - 1)
24 #define AW200XX_FADE_MAX (BIT(8) - 1)
41 AW200XX_REG(AW200XX_NUM_PAGES - 1, AW200XX_PAGE_SIZE - 1)
61 /* Global current configuration register */
76 ((x) + (((x) / (columns)) * (AW200XX_DSIZE_COLUMNS_MAX - (columns))))
78 /* DIM current configuration register on page 1 */
83 * DIM current configuration register (page 4).
84 * The even address for current DIM configuration.
85 * The odd address for current FADE configuration
130 struct aw200xx_led *led = container_of(cdev, struct aw200xx_led, cdev);
131 int dim = led->dim;
143 struct aw200xx_led *led = container_of(cdev, struct aw200xx_led, cdev);
144 struct aw200xx *chip = led->chip;
145 u32 columns = chip->cdef->display_size_columns;
150 dim = -1;
157 return -EINVAL;
160 mutex_lock(&chip->mutex);
163 ret = regmap_write(chip->regmap,
164 AW200XX_REG_DIM_PAGE1(led->num, columns),
170 led->dim = dim;
174 mutex_unlock(&chip->mutex);
188 struct aw200xx_led *led = container_of(cdev, struct aw200xx_led, cdev);
189 struct aw200xx *chip = led->chip;
194 mutex_lock(&chip->mutex);
196 reg = AW200XX_REG_DIM(led->num, chip->cdef->display_size_columns);
198 dim = led->dim;
202 ret = regmap_write(chip->regmap, reg, dim);
206 ret = regmap_write(chip->regmap,
210 mutex_unlock(&chip->mutex);
221 * The output current of each LED (see p.14 of datasheet for formula):
231 led_imax_uA = global_imax_uA * AW200XX_DUTY_RATIO(chip->display_rows);
240 u32 duty = AW200XX_DUTY_RATIO(chip->display_rows);
242 /* The output current of each LED (see p.14 of datasheet for formula) */
252 * The AW200XX has a 4-bit register (GCCR) to configure the global current,
254 * of the global current, divided into two parts:
256 * +-----------+-----------------+-----------+-----------------+
258 * +-----------+-----------------+-----------+-----------------+
267 * +-----------+-----------------+-----------+-----------------+
271 * So we have two formulas to calculate the global current:
309 return -EINVAL;
311 return regmap_update_bits(chip->regmap, AW200XX_REG_GCCR,
320 ret = regmap_write(chip->regmap, AW200XX_REG_RSTR, AW200XX_RSTR_RESET);
327 regcache_mark_dirty(chip->regmap);
328 return regmap_write(chip->regmap, AW200XX_REG_FCD, AW200XX_FCD_CLEAR);
335 ret = regmap_write(chip->regmap, AW200XX_REG_DSIZE,
336 chip->display_rows - 1);
340 ret = regmap_write(chip->regmap, AW200XX_REG_SLPCR,
345 return regmap_update_bits(chip->regmap, AW200XX_REG_GCCR,
351 struct device *dev = &chip->client->dev;
355 ret = regmap_read(chip->regmap, AW200XX_REG_IDR, &chipid);
360 return dev_err_probe(dev, -ENODEV,
368 gpiod_set_value_cansleep(chip->hwen, 1);
382 gpiod_set_value_cansleep(chip->hwen, 0);
396 if (ret || source >= chip->cdef->channels)
403 return -EINVAL;
405 chip->display_rows = max_source / chip->cdef->display_size_columns + 1;
419 "No valid led definitions found\n");
428 struct aw200xx_led *led;
434 chip->num_leds--;
438 if (source >= chip->cdef->channels) {
439 dev_err(dev, "LED reg %u out of range (max %u)\n",
440 source, chip->cdef->channels);
441 chip->num_leds--;
445 ret = fwnode_property_read_u32(child, "led-max-microamp",
448 dev_info(&chip->client->dev,
449 "DT property led-max-microamp is missing\n");
451 dev_err(dev, "Invalid value %u for led-max-microamp\n",
453 chip->num_leds--;
459 led = &chip->leds[i];
460 led->dim = -1;
461 led->num = source;
462 led->chip = chip;
463 led->cdev.brightness_set_blocking = aw200xx_brightness_set;
464 led->cdev.max_brightness = AW200XX_FADE_MAX;
465 led->cdev.groups = dim_groups;
468 ret = devm_led_classdev_register_ext(dev, &led->cdev,
476 if (!chip->num_leds)
477 return -EINVAL;
547 cdef = device_get_match_data(&client->dev);
549 return -ENODEV;
551 count = device_get_child_node_count(&client->dev);
552 if (!count || count > cdef->channels)
553 return dev_err_probe(&client->dev, -EINVAL,
556 chip = devm_kzalloc(&client->dev, struct_size(chip, leds, count),
559 return -ENOMEM;
561 chip->cdef = cdef;
562 chip->num_leds = count;
563 chip->client = client;
566 chip->regmap = devm_regmap_init_i2c(client, &aw200xx_regmap_config);
567 if (IS_ERR(chip->regmap))
568 return PTR_ERR(chip->regmap);
570 chip->hwen = devm_gpiod_get_optional(&client->dev, "enable",
572 if (IS_ERR(chip->hwen))
573 return dev_err_probe(&client->dev, PTR_ERR(chip->hwen),
578 ret = devm_add_action(&client->dev, aw200xx_disable_action, chip);
586 ret = devm_mutex_init(&client->dev, &chip->mutex);
591 mutex_lock(&chip->mutex);
597 ret = devm_add_action(&client->dev, aw200xx_chip_reset_action, chip);
601 ret = aw200xx_probe_fw(&client->dev, chip);
611 mutex_unlock(&chip->mutex);
668 MODULE_DESCRIPTION("AW200XX LED driver");