Lines Matching +full:led +full:- +full:current +full:- +full:microamp

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2015-16 Golden Delicious Computers
7 * LED driver for the IS31FL319{0,1,3,6,9} to drive 1, 3, 6 or 9 light
69 /* CS (Current Setting) in CONFIG2 register */
128 return true; /* always write-through */ in is31fl3190_volatile_reg()
160 return true; /* always write-through */ in is31fl3196_volatile_reg()
194 struct is31fl319x_led *led = container_of(cdev, struct is31fl319x_led, cdev); in is31fl3190_brightness_set() local
195 struct is31fl319x_chip *is31 = led->chip; in is31fl3190_brightness_set()
196 int chan = led - is31->leds; in is31fl3190_brightness_set()
201 dev_dbg(&is31->client->dev, "channel %d: %d\n", chan, brightness); in is31fl3190_brightness_set()
203 mutex_lock(&is31->lock); in is31fl3190_brightness_set()
206 ret = regmap_write(is31->regmap, IS31FL3190_PWM(chan), brightness); in is31fl3190_brightness_set()
210 /* read current brightness of all PWM channels */ in is31fl3190_brightness_set()
211 for (i = 0; i < is31->cdef->num_leds; i++) { in is31fl3190_brightness_set()
217 * the current setting, we read from the regmap cache in is31fl3190_brightness_set()
220 ret = regmap_read(is31->regmap, IS31FL3190_PWM(i), &pwm_value); in is31fl3190_brightness_set()
227 dev_dbg(&is31->client->dev, "power up %02x\n", ctrl); in is31fl3190_brightness_set()
228 regmap_write(is31->regmap, IS31FL3190_LEDCONTROL, ctrl); in is31fl3190_brightness_set()
230 regmap_write(is31->regmap, IS31FL3190_DATA_UPDATE, 0x00); in is31fl3190_brightness_set()
232 ret = regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x20); in is31fl3190_brightness_set()
234 dev_dbg(&is31->client->dev, "power down\n"); in is31fl3190_brightness_set()
236 ret = regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x01); in is31fl3190_brightness_set()
240 mutex_unlock(&is31->lock); in is31fl3190_brightness_set()
248 struct is31fl319x_led *led = container_of(cdev, struct is31fl319x_led, cdev); in is31fl3196_brightness_set() local
249 struct is31fl319x_chip *is31 = led->chip; in is31fl3196_brightness_set()
250 int chan = led - is31->leds; in is31fl3196_brightness_set()
255 dev_dbg(&is31->client->dev, "channel %d: %d\n", chan, brightness); in is31fl3196_brightness_set()
257 mutex_lock(&is31->lock); in is31fl3196_brightness_set()
260 ret = regmap_write(is31->regmap, IS31FL3196_PWM(chan), brightness); in is31fl3196_brightness_set()
264 /* read current brightness of all PWM channels */ in is31fl3196_brightness_set()
265 for (i = 0; i < is31->cdef->num_leds; i++) { in is31fl3196_brightness_set()
271 * the current setting, we read from the regmap cache in is31fl3196_brightness_set()
274 ret = regmap_read(is31->regmap, IS31FL3196_PWM(i), &pwm_value); in is31fl3196_brightness_set()
282 ctrl2 |= on << (i - 6); /* 6..8 => bit 0..2 */ in is31fl3196_brightness_set()
286 dev_dbg(&is31->client->dev, "power up %02x %02x\n", in is31fl3196_brightness_set()
288 regmap_write(is31->regmap, IS31FL3196_CTRL1, ctrl1); in is31fl3196_brightness_set()
289 regmap_write(is31->regmap, IS31FL3196_CTRL2, ctrl2); in is31fl3196_brightness_set()
291 regmap_write(is31->regmap, IS31FL3196_DATA_UPDATE, 0x00); in is31fl3196_brightness_set()
293 ret = regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x01); in is31fl3196_brightness_set()
295 dev_dbg(&is31->client->dev, "power down\n"); in is31fl3196_brightness_set()
297 ret = regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x00); in is31fl3196_brightness_set()
301 mutex_unlock(&is31->lock); in is31fl3196_brightness_set()
356 { .compatible = "si-en,sn3190", .data = &is31fl3190_cdef, },
357 { .compatible = "si-en,sn3191", .data = &is31fl3190_cdef, },
358 { .compatible = "si-en,sn3193", .data = &is31fl3193_cdef, },
359 { .compatible = "si-en,sn3196", .data = &is31fl3196_cdef, },
360 { .compatible = "si-en,sn3199", .data = &is31fl3199_cdef, },
367 struct is31fl319x_led *led, in is31fl319x_parse_child_fw() argument
370 struct led_classdev *cdev = &led->cdev; in is31fl319x_parse_child_fw()
373 if (fwnode_property_read_string(child, "label", &cdev->name)) in is31fl319x_parse_child_fw()
374 cdev->name = fwnode_get_name(child); in is31fl319x_parse_child_fw()
376 ret = fwnode_property_read_string(child, "linux,default-trigger", &cdev->default_trigger); in is31fl319x_parse_child_fw()
377 if (ret < 0 && ret != -EINVAL) /* is optional */ in is31fl319x_parse_child_fw()
380 led->max_microamp = is31->cdef->current_default; in is31fl319x_parse_child_fw()
381 ret = fwnode_property_read_u32(child, "led-max-microamp", &led->max_microamp); in is31fl319x_parse_child_fw()
383 if (led->max_microamp < is31->cdef->current_min) in is31fl319x_parse_child_fw()
384 return -EINVAL; /* not supported */ in is31fl319x_parse_child_fw()
385 led->max_microamp = min(led->max_microamp, in is31fl319x_parse_child_fw()
386 is31->cdef->current_max); in is31fl319x_parse_child_fw()
398 is31->shutdown_gpio = devm_gpiod_get_optional(dev, "shutdown", GPIOD_OUT_HIGH); in is31fl319x_parse_fw()
399 if (IS_ERR(is31->shutdown_gpio)) in is31fl319x_parse_fw()
400 return dev_err_probe(dev, PTR_ERR(is31->shutdown_gpio), in is31fl319x_parse_fw()
403 is31->cdef = device_get_match_data(dev); in is31fl319x_parse_fw()
411 if (!count || count > is31->cdef->num_leds) in is31fl319x_parse_fw()
412 return dev_err_probe(dev, -ENODEV, in is31fl319x_parse_fw()
414 is31->cdef->num_leds); in is31fl319x_parse_fw()
417 struct is31fl319x_led *led; in is31fl319x_parse_fw() local
422 ret = dev_err_probe(dev, ret, "Failed to read led 'reg' property\n"); in is31fl319x_parse_fw()
426 if (reg < 1 || reg > is31->cdef->num_leds) { in is31fl319x_parse_fw()
427 ret = dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg); in is31fl319x_parse_fw()
431 led = &is31->leds[reg - 1]; in is31fl319x_parse_fw()
433 if (led->configured) { in is31fl319x_parse_fw()
434 ret = dev_err_probe(dev, -EINVAL, "led %u is already configured\n", reg); in is31fl319x_parse_fw()
438 ret = is31fl319x_parse_child_fw(dev, child, led, is31); in is31fl319x_parse_fw()
440 ret = dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg); in is31fl319x_parse_fw()
444 led->configured = true; in is31fl319x_parse_fw()
447 is31->audio_gain_db = 0; in is31fl319x_parse_fw()
448 if (is31->cdef->is_3196or3199) { in is31fl319x_parse_fw()
449 ret = fwnode_property_read_u32(fwnode, "audio-gain-db", &is31->audio_gain_db); in is31fl319x_parse_fw()
451 is31->audio_gain_db = min(is31->audio_gain_db, in is31fl319x_parse_fw()
462 static inline int is31fl3190_microamp_to_cs(struct device *dev, u32 microamp) in is31fl3190_microamp_to_cs() argument
464 switch (microamp) { in is31fl3190_microamp_to_cs()
476 dev_warn(dev, "Unsupported current value: %d, using 5000 µA!\n", microamp); in is31fl3190_microamp_to_cs()
481 static inline int is31fl3196_microamp_to_cs(struct device *dev, u32 microamp) in is31fl3196_microamp_to_cs() argument
484 u32 step = microamp / IS31FL3196_CURRENT_uA_STEP; in is31fl3196_microamp_to_cs()
486 return ((IS31FL3196_CONFIG2_CS_STEP_REF - step) & in is31fl3196_microamp_to_cs()
500 struct device *dev = &client->dev; in is31fl319x_probe()
505 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in is31fl319x_probe()
506 return -EIO; in is31fl319x_probe()
508 is31 = devm_kzalloc(&client->dev, sizeof(*is31), GFP_KERNEL); in is31fl319x_probe()
510 return -ENOMEM; in is31fl319x_probe()
512 mutex_init(&is31->lock); in is31fl319x_probe()
513 err = devm_add_action(dev, (void (*)(void *))mutex_destroy, &is31->lock); in is31fl319x_probe()
517 err = is31fl319x_parse_fw(&client->dev, is31); in is31fl319x_probe()
521 if (is31->shutdown_gpio) { in is31fl319x_probe()
522 gpiod_direction_output(is31->shutdown_gpio, 0); in is31fl319x_probe()
524 gpiod_direction_output(is31->shutdown_gpio, 1); in is31fl319x_probe()
527 is31->client = client; in is31fl319x_probe()
528 is31->regmap = devm_regmap_init_i2c(client, is31->cdef->is31fl319x_regmap_config); in is31fl319x_probe()
529 if (IS_ERR(is31->regmap)) in is31fl319x_probe()
530 return dev_err_probe(dev, PTR_ERR(is31->regmap), "failed to allocate register map\n"); in is31fl319x_probe()
534 /* check for write-reply from chip (we can't read any registers) */ in is31fl319x_probe()
535 err = regmap_write(is31->regmap, is31->cdef->reset_reg, 0x00); in is31fl319x_probe()
540 * Kernel conventions require per-LED led-max-microamp property. in is31fl319x_probe()
544 aggregated_led_microamp = is31->cdef->current_max; in is31fl319x_probe()
545 for (i = 0; i < is31->cdef->num_leds; i++) in is31fl319x_probe()
546 if (is31->leds[i].configured && in is31fl319x_probe()
547 is31->leds[i].max_microamp < aggregated_led_microamp) in is31fl319x_probe()
548 aggregated_led_microamp = is31->leds[i].max_microamp; in is31fl319x_probe()
550 if (is31->cdef->is_3196or3199) in is31fl319x_probe()
551 regmap_write(is31->regmap, IS31FL3196_CONFIG2, in is31fl319x_probe()
553 is31fl3196_db_to_gain(is31->audio_gain_db)); in is31fl319x_probe()
555 regmap_update_bits(is31->regmap, IS31FL3190_CURRENT, IS31FL3190_CURRENT_MASK, in is31fl319x_probe()
558 for (i = 0; i < is31->cdef->num_leds; i++) { in is31fl319x_probe()
559 struct is31fl319x_led *led = &is31->leds[i]; in is31fl319x_probe() local
561 if (!led->configured) in is31fl319x_probe()
564 led->chip = is31; in is31fl319x_probe()
565 led->cdev.brightness_set_blocking = is31->cdef->brightness_set; in is31fl319x_probe()
567 err = devm_led_classdev_register(&client->dev, &led->cdev); in is31fl319x_probe()
576 * i2c-core (and modalias) requires that id_table be properly filled,
596 .name = "leds-is31fl319x",
607 MODULE_DESCRIPTION("IS31FL319X LED driver");