Lines Matching +full:led +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0+
3 // Driver for Panasonic AN30259A 3-channel LED driver
22 /* LED power registers */
24 #define AN30259A_LED_EN(x) BIT((x) - 1)
25 #define AN30259A_LED_SLOPE(x) BIT(((x) - 1) + 4)
27 #define AN30259A_REG_LEDCC(x) (0x03 + ((x) - 1))
30 #define AN30259A_REG_SLOPE(x) (0x06 + ((x) - 1))
34 #define AN30259A_REG_LEDCNT1(x) (0x09 + (4 * ((x) - 1)))
38 #define AN30259A_REG_LEDCNT2(x) (0x0A + (4 * ((x) - 1)))
43 #define AN30259A_REG_LEDCNT3(x) (0x0B + (4 * ((x) - 1)))
47 #define AN30259A_REG_LEDCNT4(x) (0x0C + (4 * ((x) - 1)))
59 #define STATE_KEEP 1
84 struct an30259a_led *led; in an30259a_brightness_set() local
88 led = container_of(cdev, struct an30259a_led, cdev); in an30259a_brightness_set()
89 mutex_lock(&led->chip->mutex); in an30259a_brightness_set()
91 ret = regmap_read(led->chip->regmap, AN30259A_REG_LED_ON, &led_on); in an30259a_brightness_set()
97 led_on &= ~AN30259A_LED_EN(led->num); in an30259a_brightness_set()
98 led_on &= ~AN30259A_LED_SLOPE(led->num); in an30259a_brightness_set()
99 led->sloping = false; in an30259a_brightness_set()
102 led_on |= AN30259A_LED_EN(led->num); in an30259a_brightness_set()
103 if (led->sloping) in an30259a_brightness_set()
104 led_on |= AN30259A_LED_SLOPE(led->num); in an30259a_brightness_set()
105 ret = regmap_write(led->chip->regmap, in an30259a_brightness_set()
106 AN30259A_REG_LEDCNT1(led->num), in an30259a_brightness_set()
114 ret = regmap_write(led->chip->regmap, AN30259A_REG_LED_ON, led_on); in an30259a_brightness_set()
118 ret = regmap_write(led->chip->regmap, AN30259A_REG_LEDCC(led->num), in an30259a_brightness_set()
122 mutex_unlock(&led->chip->mutex); in an30259a_brightness_set()
130 struct an30259a_led *led; in an30259a_blink_set() local
135 led = container_of(cdev, struct an30259a_led, cdev); in an30259a_blink_set()
137 mutex_lock(&led->chip->mutex); in an30259a_blink_set()
138 num = led->num; in an30259a_blink_set()
142 ret = -EINVAL; in an30259a_blink_set()
148 ret = -EINVAL; in an30259a_blink_set()
152 /* if no blink specified, default to 1 Hz. */ in an30259a_blink_set()
163 ret = regmap_write(led->chip->regmap, AN30259A_REG_LEDCNT2(num), in an30259a_blink_set()
169 ret = regmap_write(led->chip->regmap, AN30259A_REG_LEDCNT3(num), in an30259a_blink_set()
173 ret = regmap_write(led->chip->regmap, AN30259A_REG_LEDCNT4(num), in an30259a_blink_set()
179 ret = regmap_write(led->chip->regmap, AN30259A_REG_SLOPE(num), in an30259a_blink_set()
186 ret = regmap_read(led->chip->regmap, AN30259A_REG_LED_ON, &led_on); in an30259a_blink_set()
190 led_on |= AN30259A_LED_SLOPE(num) | AN30259A_LED_EN(led->num); in an30259a_blink_set()
192 ret = regmap_write(led->chip->regmap, AN30259A_REG_LED_ON, led_on); in an30259a_blink_set()
195 led->sloping = true; in an30259a_blink_set()
197 mutex_unlock(&led->chip->mutex); in an30259a_blink_set()
205 struct device_node *np = dev_of_node(&client->dev), *child; in an30259a_dt_init()
209 struct an30259a_led *led; in an30259a_dt_init() local
213 return -EINVAL; in an30259a_dt_init()
220 dev_err(&client->dev, "Couldn't read LED address: %d\n", in an30259a_dt_init()
222 count--; in an30259a_dt_init()
226 led = &chip->leds[i]; in an30259a_dt_init()
228 led->num = source; in an30259a_dt_init()
229 led->chip = chip; in an30259a_dt_init()
230 led->fwnode = of_fwnode_handle(child); in an30259a_dt_init()
232 if (!of_property_read_string(child, "default-state", &str)) { in an30259a_dt_init()
234 led->default_state = STATE_ON; in an30259a_dt_init()
236 led->default_state = STATE_KEEP; in an30259a_dt_init()
238 led->default_state = STATE_OFF; in an30259a_dt_init()
245 return -EINVAL; in an30259a_dt_init()
247 chip->num_leds = i; in an30259a_dt_init()
258 static void an30259a_init_default_state(struct an30259a_led *led) in an30259a_init_default_state() argument
260 struct an30259a *chip = led->chip; in an30259a_init_default_state()
263 switch (led->default_state) { in an30259a_init_default_state()
265 led->cdev.brightness = LED_FULL; in an30259a_init_default_state()
268 err = regmap_read(chip->regmap, AN30259A_REG_LED_ON, &led_on); in an30259a_init_default_state()
272 if (!(led_on & AN30259A_LED_EN(led->num))) { in an30259a_init_default_state()
273 led->cdev.brightness = LED_OFF; in an30259a_init_default_state()
276 regmap_read(chip->regmap, AN30259A_REG_LEDCC(led->num), in an30259a_init_default_state()
277 &led->cdev.brightness); in an30259a_init_default_state()
280 led->cdev.brightness = LED_OFF; in an30259a_init_default_state()
283 an30259a_brightness_set(&led->cdev, led->cdev.brightness); in an30259a_init_default_state()
291 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in an30259a_probe()
293 return -ENOMEM; in an30259a_probe()
299 mutex_init(&chip->mutex); in an30259a_probe()
300 chip->client = client; in an30259a_probe()
303 chip->regmap = devm_regmap_init_i2c(client, &an30259a_regmap_config); in an30259a_probe()
305 if (IS_ERR(chip->regmap)) { in an30259a_probe()
306 err = PTR_ERR(chip->regmap); in an30259a_probe()
307 dev_err(&client->dev, "Failed to allocate register map: %d\n", in an30259a_probe()
312 for (i = 0; i < chip->num_leds; i++) { in an30259a_probe()
315 an30259a_init_default_state(&chip->leds[i]); in an30259a_probe()
316 chip->leds[i].cdev.brightness_set_blocking = in an30259a_probe()
318 chip->leds[i].cdev.blink_set = an30259a_blink_set; in an30259a_probe()
320 init_data.fwnode = chip->leds[i].fwnode; in an30259a_probe()
324 err = devm_led_classdev_register_ext(&client->dev, in an30259a_probe()
325 &chip->leds[i].cdev, in an30259a_probe()
333 mutex_destroy(&chip->mutex); in an30259a_probe()
341 mutex_destroy(&chip->mutex); in an30259a_remove()
361 .name = "leds-an30259a",
372 MODULE_DESCRIPTION("AN30259A LED driver");