Lines Matching +full:on +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0+
3 // Driver for Panasonic AN30259A 3-channel LED driver
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)))
65 struct an30259a *chip; member
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()
133 unsigned long off = *delay_off, on = *delay_on; in an30259a_blink_set() local
137 mutex_lock(&led->chip->mutex); in an30259a_blink_set()
138 num = led->num; in an30259a_blink_set()
141 if (off % AN30259A_SLOPE_RESOLUTION || on % AN30259A_SLOPE_RESOLUTION) { in an30259a_blink_set()
142 ret = -EINVAL; in an30259a_blink_set()
147 if (off > AN30259A_BLINK_MAX_TIME || on > AN30259A_BLINK_MAX_TIME) { in an30259a_blink_set()
148 ret = -EINVAL; in an30259a_blink_set()
153 if (!off && !on) { in an30259a_blink_set()
155 *delay_on = on = 500; in an30259a_blink_set()
160 on /= AN30259A_SLOPE_RESOLUTION; 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()
178 /* slope time controls on/off cycle length. */ in an30259a_blink_set()
179 ret = regmap_write(led->chip->regmap, AN30259A_REG_SLOPE(num), in an30259a_blink_set()
181 AN30259A_LED_SLOPETIME2(on)); 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()
203 struct an30259a *chip) in an30259a_dt_init() argument
205 struct device_node *np = dev_of_node(&client->dev), *child; in an30259a_dt_init()
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()
233 if (!strcmp(str, "on")) 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()
260 struct an30259a *chip = led->chip; in an30259a_init_default_state() local
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()
288 struct an30259a *chip; in an30259a_probe() local
291 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in an30259a_probe()
292 if (!chip) in an30259a_probe()
293 return -ENOMEM; in an30259a_probe()
295 err = an30259a_dt_init(client, chip); in an30259a_probe()
299 mutex_init(&chip->mutex); in an30259a_probe()
300 chip->client = client; in an30259a_probe()
301 i2c_set_clientdata(client, chip); 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()
339 struct an30259a *chip = i2c_get_clientdata(client); in an30259a_remove() local
341 mutex_destroy(&chip->mutex); in an30259a_remove()
359 .name = "leds-an30259a",