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
70 /* CS (Current Setting) in CONFIG2 register */
129 return true; /* always write-through */ in is31fl3190_volatile_reg()
161 return true; /* always write-through */ in is31fl3196_volatile_reg()
195 struct is31fl319x_led *led = container_of(cdev, struct is31fl319x_led, cdev); in is31fl3190_brightness_set() local
196 struct is31fl319x_chip *is31 = led->chip; in is31fl3190_brightness_set()
197 int chan = led - is31->leds; in is31fl3190_brightness_set()
202 dev_dbg(&is31->client->dev, "channel %d: %d\n", chan, brightness); in is31fl3190_brightness_set()
204 mutex_lock(&is31->lock); in is31fl3190_brightness_set()
207 ret = regmap_write(is31->regmap, IS31FL3190_PWM(chan), brightness); in is31fl3190_brightness_set()
211 /* read current brightness of all PWM channels */ in is31fl3190_brightness_set()
212 for (i = 0; i < is31->cdef->num_leds; i++) { in is31fl3190_brightness_set()
218 * the current setting, we read from the regmap cache in is31fl3190_brightness_set()
221 ret = regmap_read(is31->regmap, IS31FL3190_PWM(i), &pwm_value); in is31fl3190_brightness_set()
228 dev_dbg(&is31->client->dev, "power up %02x\n", ctrl); in is31fl3190_brightness_set()
229 regmap_write(is31->regmap, IS31FL3190_LEDCONTROL, ctrl); in is31fl3190_brightness_set()
231 regmap_write(is31->regmap, IS31FL3190_DATA_UPDATE, 0x00); in is31fl3190_brightness_set()
233 ret = regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x20); in is31fl3190_brightness_set()
235 dev_dbg(&is31->client->dev, "power down\n"); in is31fl3190_brightness_set()
237 ret = regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x01); in is31fl3190_brightness_set()
241 mutex_unlock(&is31->lock); in is31fl3190_brightness_set()
249 struct is31fl319x_led *led = container_of(cdev, struct is31fl319x_led, cdev); in is31fl3196_brightness_set() local
250 struct is31fl319x_chip *is31 = led->chip; in is31fl3196_brightness_set()
251 int chan = led - is31->leds; in is31fl3196_brightness_set()
256 dev_dbg(&is31->client->dev, "channel %d: %d\n", chan, brightness); in is31fl3196_brightness_set()
258 mutex_lock(&is31->lock); in is31fl3196_brightness_set()
261 ret = regmap_write(is31->regmap, IS31FL3196_PWM(chan), brightness); in is31fl3196_brightness_set()
265 /* read current brightness of all PWM channels */ in is31fl3196_brightness_set()
266 for (i = 0; i < is31->cdef->num_leds; i++) { in is31fl3196_brightness_set()
272 * the current setting, we read from the regmap cache in is31fl3196_brightness_set()
275 ret = regmap_read(is31->regmap, IS31FL3196_PWM(i), &pwm_value); in is31fl3196_brightness_set()
283 ctrl2 |= on << (i - 6); /* 6..8 => bit 0..2 */ in is31fl3196_brightness_set()
287 dev_dbg(&is31->client->dev, "power up %02x %02x\n", in is31fl3196_brightness_set()
289 regmap_write(is31->regmap, IS31FL3196_CTRL1, ctrl1); in is31fl3196_brightness_set()
290 regmap_write(is31->regmap, IS31FL3196_CTRL2, ctrl2); in is31fl3196_brightness_set()
292 regmap_write(is31->regmap, IS31FL3196_DATA_UPDATE, 0x00); in is31fl3196_brightness_set()
294 ret = regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x01); in is31fl3196_brightness_set()
296 dev_dbg(&is31->client->dev, "power down\n"); in is31fl3196_brightness_set()
298 ret = regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x00); in is31fl3196_brightness_set()
302 mutex_unlock(&is31->lock); in is31fl3196_brightness_set()
357 { .compatible = "si-en,sn3190", .data = &is31fl3190_cdef, },
358 { .compatible = "si-en,sn3191", .data = &is31fl3190_cdef, },
359 { .compatible = "si-en,sn3193", .data = &is31fl3193_cdef, },
360 { .compatible = "si-en,sn3196", .data = &is31fl3196_cdef, },
361 { .compatible = "si-en,sn3199", .data = &is31fl3199_cdef, },
368 struct is31fl319x_led *led, in is31fl319x_parse_child_fw() argument
371 struct led_classdev *cdev = &led->cdev; in is31fl319x_parse_child_fw()
374 if (fwnode_property_read_string(child, "label", &cdev->name)) in is31fl319x_parse_child_fw()
375 cdev->name = fwnode_get_name(child); in is31fl319x_parse_child_fw()
377 ret = fwnode_property_read_string(child, "linux,default-trigger", &cdev->default_trigger); in is31fl319x_parse_child_fw()
378 if (ret < 0 && ret != -EINVAL) /* is optional */ in is31fl319x_parse_child_fw()
381 led->max_microamp = is31->cdef->current_default; in is31fl319x_parse_child_fw()
382 ret = fwnode_property_read_u32(child, "led-max-microamp", &led->max_microamp); in is31fl319x_parse_child_fw()
384 if (led->max_microamp < is31->cdef->current_min) in is31fl319x_parse_child_fw()
385 return -EINVAL; /* not supported */ in is31fl319x_parse_child_fw()
386 led->max_microamp = min(led->max_microamp, in is31fl319x_parse_child_fw()
387 is31->cdef->current_max); in is31fl319x_parse_child_fw()
399 is31->shutdown_gpio = devm_gpiod_get_optional(dev, "shutdown", GPIOD_OUT_HIGH); in is31fl319x_parse_fw()
400 if (IS_ERR(is31->shutdown_gpio)) in is31fl319x_parse_fw()
401 return dev_err_probe(dev, PTR_ERR(is31->shutdown_gpio), in is31fl319x_parse_fw()
404 is31->cdef = device_get_match_data(dev); in is31fl319x_parse_fw()
412 if (!count || count > is31->cdef->num_leds) in is31fl319x_parse_fw()
413 return dev_err_probe(dev, -ENODEV, in is31fl319x_parse_fw()
415 is31->cdef->num_leds); in is31fl319x_parse_fw()
418 struct is31fl319x_led *led; in is31fl319x_parse_fw() local
423 ret = dev_err_probe(dev, ret, "Failed to read led 'reg' property\n"); in is31fl319x_parse_fw()
427 if (reg < 1 || reg > is31->cdef->num_leds) { in is31fl319x_parse_fw()
428 ret = dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg); in is31fl319x_parse_fw()
432 led = &is31->leds[reg - 1]; in is31fl319x_parse_fw()
434 if (led->configured) { in is31fl319x_parse_fw()
435 ret = dev_err_probe(dev, -EINVAL, "led %u is already configured\n", reg); in is31fl319x_parse_fw()
439 ret = is31fl319x_parse_child_fw(dev, child, led, is31); in is31fl319x_parse_fw()
441 ret = dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg); in is31fl319x_parse_fw()
445 led->configured = true; in is31fl319x_parse_fw()
448 is31->audio_gain_db = 0; in is31fl319x_parse_fw()
449 if (is31->cdef->is_3196or3199) { in is31fl319x_parse_fw()
450 ret = fwnode_property_read_u32(fwnode, "audio-gain-db", &is31->audio_gain_db); in is31fl319x_parse_fw()
452 is31->audio_gain_db = min(is31->audio_gain_db, in is31fl319x_parse_fw()
463 static inline int is31fl3190_microamp_to_cs(struct device *dev, u32 microamp) in is31fl3190_microamp_to_cs() argument
465 switch (microamp) { in is31fl3190_microamp_to_cs()
477 dev_warn(dev, "Unsupported current value: %d, using 5000 µA!\n", microamp); in is31fl3190_microamp_to_cs()
482 static inline int is31fl3196_microamp_to_cs(struct device *dev, u32 microamp) in is31fl3196_microamp_to_cs() argument
485 u32 step = microamp / IS31FL3196_CURRENT_uA_STEP; in is31fl3196_microamp_to_cs()
487 return ((IS31FL3196_CONFIG2_CS_STEP_REF - step) & in is31fl3196_microamp_to_cs()
506 struct device *dev = &client->dev; in is31fl319x_probe()
511 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in is31fl319x_probe()
512 return -EIO; in is31fl319x_probe()
514 is31 = devm_kzalloc(&client->dev, sizeof(*is31), GFP_KERNEL); in is31fl319x_probe()
516 return -ENOMEM; in is31fl319x_probe()
518 mutex_init(&is31->lock); in is31fl319x_probe()
519 err = devm_add_action_or_reset(dev, is31f1319x_mutex_destroy, &is31->lock); in is31fl319x_probe()
523 err = is31fl319x_parse_fw(&client->dev, is31); in is31fl319x_probe()
527 if (is31->shutdown_gpio) { in is31fl319x_probe()
528 gpiod_direction_output(is31->shutdown_gpio, 0); in is31fl319x_probe()
530 gpiod_direction_output(is31->shutdown_gpio, 1); in is31fl319x_probe()
533 is31->client = client; in is31fl319x_probe()
534 is31->regmap = devm_regmap_init_i2c(client, is31->cdef->is31fl319x_regmap_config); in is31fl319x_probe()
535 if (IS_ERR(is31->regmap)) in is31fl319x_probe()
536 return dev_err_probe(dev, PTR_ERR(is31->regmap), "failed to allocate register map\n"); in is31fl319x_probe()
540 /* check for write-reply from chip (we can't read any registers) */ in is31fl319x_probe()
541 err = regmap_write(is31->regmap, is31->cdef->reset_reg, 0x00); in is31fl319x_probe()
546 * Kernel conventions require per-LED led-max-microamp property. in is31fl319x_probe()
550 aggregated_led_microamp = is31->cdef->current_max; in is31fl319x_probe()
551 for (i = 0; i < is31->cdef->num_leds; i++) in is31fl319x_probe()
552 if (is31->leds[i].configured && in is31fl319x_probe()
553 is31->leds[i].max_microamp < aggregated_led_microamp) in is31fl319x_probe()
554 aggregated_led_microamp = is31->leds[i].max_microamp; in is31fl319x_probe()
556 if (is31->cdef->is_3196or3199) in is31fl319x_probe()
557 regmap_write(is31->regmap, IS31FL3196_CONFIG2, in is31fl319x_probe()
559 is31fl3196_db_to_gain(is31->audio_gain_db)); in is31fl319x_probe()
561 regmap_update_bits(is31->regmap, IS31FL3190_CURRENT, IS31FL3190_CURRENT_MASK, in is31fl319x_probe()
564 for (i = 0; i < is31->cdef->num_leds; i++) { in is31fl319x_probe()
565 struct is31fl319x_led *led = &is31->leds[i]; in is31fl319x_probe() local
567 if (!led->configured) in is31fl319x_probe()
570 led->chip = is31; in is31fl319x_probe()
571 led->cdev.brightness_set_blocking = is31->cdef->brightness_set; in is31fl319x_probe()
573 err = devm_led_classdev_register(&client->dev, &led->cdev); in is31fl319x_probe()
582 * i2c-core (and modalias) requires that id_table be properly filled,
602 .name = "leds-is31fl319x",
613 MODULE_DESCRIPTION("IS31FL319X LED driver");