Lines Matching +full:led +full:- +full:8
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2007-2008 Extreme Engineering Solutions, Inc.
5 * Author: Nate Case <ncase@xes-inc.com>
7 * LED driver for various PCA955x I2C LED drivers
11 * Device Description 7-bit slave address
12 * ------ ----------- -------------------
13 * PCA9550 2-bit driver 0x60 .. 0x61
14 * PCA9551 8-bit driver 0x60 .. 0x67
15 * PCA9552 16-bit driver 0x60 .. 0x67
16 * PCA9553/01 4-bit driver 0x62
17 * PCA9553/02 4-bit driver 0x63
19 * Philips PCA955x LED driver chips follow a register map as shown below:
22 * ---------------- -----------
25 * NUM_INPUT_REGS - 1 Last Input register X
32 * NUM_INPUT_REGS + 4 LED selector 0
34 * + NUM_LED_REGS - 1 Last LED selector
52 #include <dt-bindings/leds/leds-pca955x.h>
54 /* LED select registers determine the source that drives LED outputs */
56 #define PCA955X_LS_LED_OFF 0x1 /* Output HI-Z */
74 u8 slv_addr; /* 7-bit slave address mask */
85 .bits = 8,
110 { "ibm-pca9552", ibm_pca9552 },
140 /* 8 bits per input register */
143 return (bits + 7) / 8; in pca95xx_num_input_regs()
146 /* 4 bits per LED selector register */
153 * Return an LED selector register value based on an existing one, with
154 * the appropriate 2-bit state value set for the given LED number (0-3).
172 pca95xx_num_input_regs(pca955x->chipdef->bits) + 2*n, in pca955x_write_psc()
175 dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n", in pca955x_write_psc()
182 * output. LED is OFF when the count is less than the value of this
183 * register, and ON when it is greater. If PWMx == 0, LED is always OFF.
185 * Duty cycle is (256 - PWMx) / 256
193 pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + 2*n, in pca955x_write_pwm()
196 dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n", in pca955x_write_pwm()
202 * Write to LED selector register, which determines the source that
203 * drives the LED output.
211 pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n, in pca955x_write_ls()
214 dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n", in pca955x_write_ls()
220 * Read the LED selector register, which determines the source that
221 * drives the LED output.
229 pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n); in pca955x_read_ls()
231 dev_err(&client->dev, "%s: reg 0x%x, err %d\n", in pca955x_read_ls()
245 int chip_ls; /* which LSx to use (0-3 potentially) */ in pca955x_led_set()
246 int ls_led; /* which set of bits within LSx to use (0-3) */ in pca955x_led_set()
250 pca955x = pca955x_led->pca955x; in pca955x_led_set()
252 chip_ls = pca955x_led->led_num / 4; in pca955x_led_set()
253 ls_led = pca955x_led->led_num % 4; in pca955x_led_set()
255 mutex_lock(&pca955x->lock); in pca955x_led_set()
257 ret = pca955x_read_ls(pca955x->client, chip_ls, &ls); in pca955x_led_set()
279 ret = pca955x_write_pwm(pca955x->client, 1, 255 - value); in pca955x_led_set()
286 ret = pca955x_write_ls(pca955x->client, chip_ls, ls); in pca955x_led_set()
289 mutex_unlock(&pca955x->lock); in pca955x_led_set()
303 dev_err(&client->dev, "%s: reg 0x%x, err %d\n", in pca955x_read_input()
315 struct pca955x_led *led = &pca955x->leds[offset]; in pca955x_gpio_request_pin() local
317 if (led->type == PCA955X_TYPE_GPIO) in pca955x_gpio_request_pin()
320 return -EBUSY; in pca955x_gpio_request_pin()
327 struct pca955x_led *led = &pca955x->leds[offset]; in pca955x_set_value() local
330 return pca955x_led_set(&led->led_cdev, PCA955X_GPIO_HIGH); in pca955x_set_value()
332 return pca955x_led_set(&led->led_cdev, PCA955X_GPIO_LOW); in pca955x_set_value()
344 struct pca955x_led *led = &pca955x->leds[offset]; in pca955x_gpio_get_value() local
348 pca955x_read_input(pca955x->client, led->led_num / 8, ®); in pca955x_gpio_get_value()
350 return !!(reg & (1 << (led->led_num % 8))); in pca955x_gpio_get_value()
357 struct pca955x_led *led = &pca955x->leds[offset]; in pca955x_gpio_direction_input() local
360 return pca955x_led_set(&led->led_cdev, PCA955X_GPIO_INPUT); in pca955x_gpio_direction_input()
377 count = device_get_child_node_count(&client->dev); in pca955x_get_pdata()
378 if (!count || count > chip->bits) in pca955x_get_pdata()
379 return ERR_PTR(-ENODEV); in pca955x_get_pdata()
381 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); in pca955x_get_pdata()
383 return ERR_PTR(-ENOMEM); in pca955x_get_pdata()
385 pdata->leds = devm_kcalloc(&client->dev, in pca955x_get_pdata()
386 chip->bits, sizeof(struct pca955x_led), in pca955x_get_pdata()
388 if (!pdata->leds) in pca955x_get_pdata()
389 return ERR_PTR(-ENOMEM); in pca955x_get_pdata()
391 device_for_each_child_node(&client->dev, child) { in pca955x_get_pdata()
397 if ((res != 0) || (reg >= chip->bits)) in pca955x_get_pdata()
402 name = to_of_node(child)->name; in pca955x_get_pdata()
404 snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name), in pca955x_get_pdata()
407 pdata->leds[reg].type = PCA955X_TYPE_LED; in pca955x_get_pdata()
408 fwnode_property_read_u32(child, "type", &pdata->leds[reg].type); in pca955x_get_pdata()
409 fwnode_property_read_string(child, "linux,default-trigger", in pca955x_get_pdata()
410 &pdata->leds[reg].default_trigger); in pca955x_get_pdata()
413 pdata->num_leds = chip->bits; in pca955x_get_pdata()
439 chip = &pca955x_chipdefs[id->driver_data]; in pca955x_probe()
440 adapter = client->adapter; in pca955x_probe()
441 pdata = dev_get_platdata(&client->dev); in pca955x_probe()
449 if ((client->addr & ~((1 << chip->slv_addr_shift) - 1)) != in pca955x_probe()
450 chip->slv_addr) { in pca955x_probe()
451 dev_err(&client->dev, "invalid slave address %02x\n", in pca955x_probe()
452 client->addr); in pca955x_probe()
453 return -ENODEV; in pca955x_probe()
456 dev_info(&client->dev, "leds-pca955x: Using %s %d-bit LED driver at " in pca955x_probe()
458 client->name, chip->bits, client->addr); in pca955x_probe()
461 return -EIO; in pca955x_probe()
463 if (pdata->num_leds != chip->bits) { in pca955x_probe()
464 dev_err(&client->dev, in pca955x_probe()
465 "board info claims %d LEDs on a %d-bit chip\n", in pca955x_probe()
466 pdata->num_leds, chip->bits); in pca955x_probe()
467 return -ENODEV; in pca955x_probe()
470 pca955x = devm_kzalloc(&client->dev, sizeof(*pca955x), GFP_KERNEL); in pca955x_probe()
472 return -ENOMEM; in pca955x_probe()
474 pca955x->leds = devm_kcalloc(&client->dev, in pca955x_probe()
475 chip->bits, sizeof(*pca955x_led), GFP_KERNEL); in pca955x_probe()
476 if (!pca955x->leds) in pca955x_probe()
477 return -ENOMEM; in pca955x_probe()
481 mutex_init(&pca955x->lock); in pca955x_probe()
482 pca955x->client = client; in pca955x_probe()
483 pca955x->chipdef = chip; in pca955x_probe()
485 for (i = 0; i < chip->bits; i++) { in pca955x_probe()
486 pca955x_led = &pca955x->leds[i]; in pca955x_probe()
487 pca955x_led->led_num = i; in pca955x_probe()
488 pca955x_led->pca955x = pca955x; in pca955x_probe()
489 pca955x_led->type = pdata->leds[i].type; in pca955x_probe()
491 switch (pca955x_led->type) { in pca955x_probe()
499 * Platform data can specify LED names and in pca955x_probe()
502 if (pdata->leds[i].name[0] == '\0') in pca955x_probe()
503 snprintf(pdata->leds[i].name, in pca955x_probe()
504 sizeof(pdata->leds[i].name), "%d", i); in pca955x_probe()
506 snprintf(pca955x_led->name, in pca955x_probe()
507 sizeof(pca955x_led->name), "pca955x:%s", in pca955x_probe()
508 pdata->leds[i].name); in pca955x_probe()
510 if (pdata->leds[i].default_trigger) in pca955x_probe()
511 pca955x_led->led_cdev.default_trigger = in pca955x_probe()
512 pdata->leds[i].default_trigger; in pca955x_probe()
514 pca955x_led->led_cdev.name = pca955x_led->name; in pca955x_probe()
515 pca955x_led->led_cdev.brightness_set_blocking = in pca955x_probe()
518 err = devm_led_classdev_register(&client->dev, in pca955x_probe()
519 &pca955x_led->led_cdev); in pca955x_probe()
523 /* Turn off LED */ in pca955x_probe()
524 err = pca955x_led_set(&pca955x_led->led_cdev, LED_OFF); in pca955x_probe()
531 err = pca955x_write_pwm(client, 0, 255 - LED_HALF); in pca955x_probe()
550 pca955x->gpio.label = "gpio-pca955x"; in pca955x_probe()
551 pca955x->gpio.direction_input = pca955x_gpio_direction_input; in pca955x_probe()
552 pca955x->gpio.direction_output = pca955x_gpio_direction_output; in pca955x_probe()
553 pca955x->gpio.set = pca955x_gpio_set_value; in pca955x_probe()
554 pca955x->gpio.get = pca955x_gpio_get_value; in pca955x_probe()
555 pca955x->gpio.request = pca955x_gpio_request_pin; in pca955x_probe()
556 pca955x->gpio.can_sleep = 1; in pca955x_probe()
557 pca955x->gpio.base = -1; in pca955x_probe()
558 pca955x->gpio.ngpio = ngpios; in pca955x_probe()
559 pca955x->gpio.parent = &client->dev; in pca955x_probe()
560 pca955x->gpio.owner = THIS_MODULE; in pca955x_probe()
562 err = devm_gpiochip_add_data(&client->dev, &pca955x->gpio, in pca955x_probe()
565 /* Use data->gpio.dev as a flag for freeing gpiochip */ in pca955x_probe()
566 pca955x->gpio.parent = NULL; in pca955x_probe()
567 dev_warn(&client->dev, "could not add gpiochip\n"); in pca955x_probe()
570 dev_info(&client->dev, "gpios %i...%i\n", in pca955x_probe()
571 pca955x->gpio.base, pca955x->gpio.base + in pca955x_probe()
572 pca955x->gpio.ngpio - 1); in pca955x_probe()
581 .name = "leds-pca955x",
590 MODULE_AUTHOR("Nate Case <ncase@xes-inc.com>");
591 MODULE_DESCRIPTION("PCA955x LED driver");