Lines Matching +full:led +full:- +full:8
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
105 { .compatible = "si-en,sn3199", .data = &is31fl3199_cdef, },
113 struct is31fl319x_led *led = container_of(cdev, struct is31fl319x_led, in is31fl319x_brightness_set() local
115 struct is31fl319x_chip *is31 = led->chip; in is31fl319x_brightness_set()
116 int chan = led - is31->leds; in is31fl319x_brightness_set()
121 dev_dbg(&is31->client->dev, "%s %d: %d\n", __func__, chan, brightness); in is31fl319x_brightness_set()
123 mutex_lock(&is31->lock); in is31fl319x_brightness_set()
126 ret = regmap_write(is31->regmap, IS31FL319X_PWM(chan), brightness); in is31fl319x_brightness_set()
131 for (i = 0; i < is31->cdef->num_leds; i++) { in is31fl319x_brightness_set()
140 ret = regmap_read(is31->regmap, IS31FL319X_PWM(i), &pwm_value); in is31fl319x_brightness_set()
141 dev_dbg(&is31->client->dev, "%s read %d: ret=%d: %d\n", in is31fl319x_brightness_set()
150 ctrl2 |= on << (i - 6); /* 6..8 => bit 0..2 */ in is31fl319x_brightness_set()
154 dev_dbg(&is31->client->dev, "power up %02x %02x\n", in is31fl319x_brightness_set()
156 regmap_write(is31->regmap, IS31FL319X_CTRL1, ctrl1); in is31fl319x_brightness_set()
157 regmap_write(is31->regmap, IS31FL319X_CTRL2, ctrl2); in is31fl319x_brightness_set()
159 regmap_write(is31->regmap, IS31FL319X_DATA_UPDATE, 0x00); in is31fl319x_brightness_set()
161 ret = regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x01); in is31fl319x_brightness_set()
163 dev_dbg(&is31->client->dev, "power down\n"); in is31fl319x_brightness_set()
165 ret = regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x00); in is31fl319x_brightness_set()
169 mutex_unlock(&is31->lock); in is31fl319x_brightness_set()
176 struct is31fl319x_led *led) in is31fl319x_parse_child_dt() argument
178 struct led_classdev *cdev = &led->cdev; in is31fl319x_parse_child_dt()
181 if (of_property_read_string(child, "label", &cdev->name)) in is31fl319x_parse_child_dt()
182 cdev->name = child->name; in is31fl319x_parse_child_dt()
184 ret = of_property_read_string(child, "linux,default-trigger", in is31fl319x_parse_child_dt()
185 &cdev->default_trigger); in is31fl319x_parse_child_dt()
186 if (ret < 0 && ret != -EINVAL) /* is optional */ in is31fl319x_parse_child_dt()
189 led->max_microamp = IS31FL319X_CURRENT_DEFAULT; in is31fl319x_parse_child_dt()
190 ret = of_property_read_u32(child, "led-max-microamp", in is31fl319x_parse_child_dt()
191 &led->max_microamp); in is31fl319x_parse_child_dt()
193 if (led->max_microamp < IS31FL319X_CURRENT_MIN) in is31fl319x_parse_child_dt()
194 return -EINVAL; /* not supported */ in is31fl319x_parse_child_dt()
195 led->max_microamp = min(led->max_microamp, in is31fl319x_parse_child_dt()
210 return -ENODEV; in is31fl319x_parse_dt()
212 is31->shutdown_gpio = devm_gpiod_get_optional(dev, in is31fl319x_parse_dt()
215 if (IS_ERR(is31->shutdown_gpio)) { in is31fl319x_parse_dt()
216 ret = PTR_ERR(is31->shutdown_gpio); in is31fl319x_parse_dt()
221 is31->cdef = device_get_match_data(dev); in is31fl319x_parse_dt()
227 if (!count || count > is31->cdef->num_leds) { in is31fl319x_parse_dt()
229 is31->cdef->num_leds); in is31fl319x_parse_dt()
230 return -ENODEV; in is31fl319x_parse_dt()
234 struct is31fl319x_led *led; in is31fl319x_parse_dt() local
239 dev_err(dev, "Failed to read led 'reg' property\n"); in is31fl319x_parse_dt()
243 if (reg < 1 || reg > is31->cdef->num_leds) { in is31fl319x_parse_dt()
244 dev_err(dev, "invalid led reg %u\n", reg); in is31fl319x_parse_dt()
245 ret = -EINVAL; in is31fl319x_parse_dt()
249 led = &is31->leds[reg - 1]; in is31fl319x_parse_dt()
251 if (led->configured) { in is31fl319x_parse_dt()
252 dev_err(dev, "led %u is already configured\n", reg); in is31fl319x_parse_dt()
253 ret = -EINVAL; in is31fl319x_parse_dt()
257 ret = is31fl319x_parse_child_dt(dev, child, led); in is31fl319x_parse_dt()
259 dev_err(dev, "led %u DT parsing failed\n", reg); in is31fl319x_parse_dt()
263 led->configured = true; in is31fl319x_parse_dt()
266 is31->audio_gain_db = 0; in is31fl319x_parse_dt()
267 ret = of_property_read_u32(np, "audio-gain-db", &is31->audio_gain_db); in is31fl319x_parse_dt()
269 is31->audio_gain_db = min(is31->audio_gain_db, in is31fl319x_parse_dt()
290 return true; /* always write-through */ in is31fl319x_volatile_reg()
307 { IS31FL319X_PWM(8), 0x00},
311 .reg_bits = 8,
312 .val_bits = 8,
325 return ((IS31FL319X_CONFIG2_CS_STEP_REF - step) & in is31fl319x_microamp_to_cs()
339 struct device *dev = &client->dev; in is31fl319x_probe()
344 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in is31fl319x_probe()
345 return -EIO; in is31fl319x_probe()
347 is31 = devm_kzalloc(&client->dev, sizeof(*is31), GFP_KERNEL); in is31fl319x_probe()
349 return -ENOMEM; in is31fl319x_probe()
351 mutex_init(&is31->lock); in is31fl319x_probe()
353 err = is31fl319x_parse_dt(&client->dev, is31); in is31fl319x_probe()
357 if (is31->shutdown_gpio) { in is31fl319x_probe()
358 gpiod_direction_output(is31->shutdown_gpio, 0); in is31fl319x_probe()
360 gpiod_direction_output(is31->shutdown_gpio, 1); in is31fl319x_probe()
363 is31->client = client; in is31fl319x_probe()
364 is31->regmap = devm_regmap_init_i2c(client, ®map_config); in is31fl319x_probe()
365 if (IS_ERR(is31->regmap)) { in is31fl319x_probe()
366 dev_err(&client->dev, "failed to allocate register map\n"); in is31fl319x_probe()
367 err = PTR_ERR(is31->regmap); in is31fl319x_probe()
373 /* check for write-reply from chip (we can't read any registers) */ in is31fl319x_probe()
374 err = regmap_write(is31->regmap, IS31FL319X_RESET, 0x00); in is31fl319x_probe()
376 dev_err(&client->dev, "no response from chip write: err = %d\n", in is31fl319x_probe()
378 err = -EIO; /* does not answer */ in is31fl319x_probe()
383 * Kernel conventions require per-LED led-max-microamp property. in is31fl319x_probe()
387 for (i = 0; i < is31->cdef->num_leds; i++) in is31fl319x_probe()
388 if (is31->leds[i].configured && in is31fl319x_probe()
389 is31->leds[i].max_microamp < aggregated_led_microamp) in is31fl319x_probe()
390 aggregated_led_microamp = is31->leds[i].max_microamp; in is31fl319x_probe()
392 regmap_write(is31->regmap, IS31FL319X_CONFIG2, in is31fl319x_probe()
394 is31fl319x_db_to_gain(is31->audio_gain_db)); in is31fl319x_probe()
396 for (i = 0; i < is31->cdef->num_leds; i++) { in is31fl319x_probe()
397 struct is31fl319x_led *led = &is31->leds[i]; in is31fl319x_probe() local
399 if (!led->configured) in is31fl319x_probe()
402 led->chip = is31; in is31fl319x_probe()
403 led->cdev.brightness_set_blocking = is31fl319x_brightness_set; in is31fl319x_probe()
405 err = devm_led_classdev_register(&client->dev, &led->cdev); in is31fl319x_probe()
413 mutex_destroy(&is31->lock); in is31fl319x_probe()
421 mutex_destroy(&is31->lock); in is31fl319x_remove()
426 * i2c-core (and modalias) requires that id_table be properly filled,
442 .name = "leds-is31fl319x",
454 MODULE_DESCRIPTION("IS31FL319X LED driver");