Lines Matching +full:off +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)))
61 struct an30259a *chip; member
85 mutex_lock(&led->chip->mutex); in an30259a_brightness_set()
87 ret = regmap_read(led->chip->regmap, AN30259A_REG_LED_ON, &led_on); in an30259a_brightness_set()
93 led_on &= ~AN30259A_LED_EN(led->num); in an30259a_brightness_set()
94 led_on &= ~AN30259A_LED_SLOPE(led->num); in an30259a_brightness_set()
95 led->sloping = false; in an30259a_brightness_set()
98 led_on |= AN30259A_LED_EN(led->num); in an30259a_brightness_set()
99 if (led->sloping) in an30259a_brightness_set()
100 led_on |= AN30259A_LED_SLOPE(led->num); in an30259a_brightness_set()
101 ret = regmap_write(led->chip->regmap, in an30259a_brightness_set()
102 AN30259A_REG_LEDCNT1(led->num), in an30259a_brightness_set()
110 ret = regmap_write(led->chip->regmap, AN30259A_REG_LED_ON, led_on); in an30259a_brightness_set()
114 ret = regmap_write(led->chip->regmap, AN30259A_REG_LEDCC(led->num), in an30259a_brightness_set()
118 mutex_unlock(&led->chip->mutex); in an30259a_brightness_set()
129 unsigned long off = *delay_off, on = *delay_on; in an30259a_blink_set() local
133 mutex_lock(&led->chip->mutex); in an30259a_blink_set()
134 num = led->num; in an30259a_blink_set()
137 if (off % AN30259A_SLOPE_RESOLUTION || on % AN30259A_SLOPE_RESOLUTION) { in an30259a_blink_set()
138 ret = -EINVAL; in an30259a_blink_set()
143 if (off > AN30259A_BLINK_MAX_TIME || on > AN30259A_BLINK_MAX_TIME) { in an30259a_blink_set()
144 ret = -EINVAL; in an30259a_blink_set()
149 if (!off && !on) { in an30259a_blink_set()
150 *delay_off = off = 500; in an30259a_blink_set()
155 off /= AN30259A_SLOPE_RESOLUTION; in an30259a_blink_set()
158 /* duty min should be zero (=off), delay should be zero. */ in an30259a_blink_set()
159 ret = regmap_write(led->chip->regmap, AN30259A_REG_LEDCNT2(num), in an30259a_blink_set()
165 ret = regmap_write(led->chip->regmap, AN30259A_REG_LEDCNT3(num), in an30259a_blink_set()
169 ret = regmap_write(led->chip->regmap, AN30259A_REG_LEDCNT4(num), in an30259a_blink_set()
174 /* slope time controls on/off cycle length. */ in an30259a_blink_set()
175 ret = regmap_write(led->chip->regmap, AN30259A_REG_SLOPE(num), in an30259a_blink_set()
176 AN30259A_LED_SLOPETIME1(off) | in an30259a_blink_set()
182 ret = regmap_read(led->chip->regmap, AN30259A_REG_LED_ON, &led_on); in an30259a_blink_set()
186 led_on |= AN30259A_LED_SLOPE(num) | AN30259A_LED_EN(led->num); in an30259a_blink_set()
188 ret = regmap_write(led->chip->regmap, AN30259A_REG_LED_ON, led_on); in an30259a_blink_set()
191 led->sloping = true; in an30259a_blink_set()
193 mutex_unlock(&led->chip->mutex); in an30259a_blink_set()
199 struct an30259a *chip) in an30259a_dt_init() argument
201 struct device_node *np = dev_of_node(&client->dev), *child; in an30259a_dt_init()
208 return -EINVAL; in an30259a_dt_init()
215 dev_err(&client->dev, "Couldn't read LED address: %d\n", in an30259a_dt_init()
217 count--; in an30259a_dt_init()
221 led = &chip->leds[i]; in an30259a_dt_init()
223 led->num = source; in an30259a_dt_init()
224 led->chip = chip; in an30259a_dt_init()
225 led->fwnode = of_fwnode_handle(child); in an30259a_dt_init()
226 led->default_state = led_init_default_state_get(led->fwnode); in an30259a_dt_init()
232 return -EINVAL; in an30259a_dt_init()
234 chip->num_leds = i; in an30259a_dt_init()
247 struct an30259a *chip = led->chip; in an30259a_init_default_state() local
250 switch (led->default_state) { in an30259a_init_default_state()
252 led->cdev.brightness = LED_FULL; in an30259a_init_default_state()
255 err = regmap_read(chip->regmap, AN30259A_REG_LED_ON, &led_on); in an30259a_init_default_state()
259 if (!(led_on & AN30259A_LED_EN(led->num))) { in an30259a_init_default_state()
260 led->cdev.brightness = LED_OFF; in an30259a_init_default_state()
263 regmap_read(chip->regmap, AN30259A_REG_LEDCC(led->num), in an30259a_init_default_state()
264 &led->cdev.brightness); in an30259a_init_default_state()
267 led->cdev.brightness = LED_OFF; in an30259a_init_default_state()
270 an30259a_brightness_set(&led->cdev, led->cdev.brightness); in an30259a_init_default_state()
275 struct an30259a *chip; in an30259a_probe() local
278 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in an30259a_probe()
279 if (!chip) in an30259a_probe()
280 return -ENOMEM; in an30259a_probe()
282 err = an30259a_dt_init(client, chip); in an30259a_probe()
286 err = devm_mutex_init(&client->dev, &chip->mutex); in an30259a_probe()
290 chip->client = client; in an30259a_probe()
291 i2c_set_clientdata(client, chip); in an30259a_probe()
293 chip->regmap = devm_regmap_init_i2c(client, &an30259a_regmap_config); in an30259a_probe()
295 if (IS_ERR(chip->regmap)) { in an30259a_probe()
296 err = PTR_ERR(chip->regmap); in an30259a_probe()
297 dev_err(&client->dev, "Failed to allocate register map: %d\n", in an30259a_probe()
302 for (i = 0; i < chip->num_leds; i++) { in an30259a_probe()
305 an30259a_init_default_state(&chip->leds[i]); in an30259a_probe()
306 chip->leds[i].cdev.brightness_set_blocking = in an30259a_probe()
308 chip->leds[i].cdev.blink_set = an30259a_blink_set; in an30259a_probe()
310 init_data.fwnode = chip->leds[i].fwnode; in an30259a_probe()
314 err = devm_led_classdev_register_ext(&client->dev, in an30259a_probe()
315 &chip->leds[i].cdev, in an30259a_probe()
341 .name = "leds-an30259a",