2019-05-30 02:57:44 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-07-17 01:49:55 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2007-2008 Extreme Engineering Solutions, Inc.
|
|
|
|
*
|
|
|
|
* Author: Nate Case <ncase@xes-inc.com>
|
|
|
|
*
|
|
|
|
* LED driver for various PCA955x I2C LED drivers
|
|
|
|
*
|
|
|
|
* Supported devices:
|
|
|
|
*
|
|
|
|
* Device Description 7-bit slave address
|
|
|
|
* ------ ----------- -------------------
|
|
|
|
* PCA9550 2-bit driver 0x60 .. 0x61
|
|
|
|
* PCA9551 8-bit driver 0x60 .. 0x67
|
|
|
|
* PCA9552 16-bit driver 0x60 .. 0x67
|
|
|
|
* PCA9553/01 4-bit driver 0x62
|
|
|
|
* PCA9553/02 4-bit driver 0x63
|
|
|
|
*
|
|
|
|
* Philips PCA955x LED driver chips follow a register map as shown below:
|
|
|
|
*
|
|
|
|
* Control Register Description
|
|
|
|
* ---------------- -----------
|
|
|
|
* 0x0 Input register 0
|
|
|
|
* ..
|
|
|
|
* NUM_INPUT_REGS - 1 Last Input register X
|
|
|
|
*
|
|
|
|
* NUM_INPUT_REGS Frequency prescaler 0
|
|
|
|
* NUM_INPUT_REGS + 1 PWM register 0
|
|
|
|
* NUM_INPUT_REGS + 2 Frequency prescaler 1
|
|
|
|
* NUM_INPUT_REGS + 3 PWM register 1
|
|
|
|
*
|
|
|
|
* NUM_INPUT_REGS + 4 LED selector 0
|
|
|
|
* NUM_INPUT_REGS + 4
|
|
|
|
* + NUM_LED_REGS - 1 Last LED selector
|
|
|
|
*
|
|
|
|
* where NUM_INPUT_REGS and NUM_LED_REGS vary depending on how many
|
|
|
|
* bits the chip supports.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/ctype.h>
|
2017-08-08 16:42:37 +03:00
|
|
|
#include <linux/delay.h>
|
2008-07-17 01:49:55 +04:00
|
|
|
#include <linux/err.h>
|
2020-06-27 01:47:35 +03:00
|
|
|
#include <linux/gpio/driver.h>
|
2008-07-17 01:49:55 +04:00
|
|
|
#include <linux/i2c.h>
|
2017-08-08 16:42:37 +03:00
|
|
|
#include <linux/leds.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
2019-03-25 17:05:00 +03:00
|
|
|
#include <linux/property.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2017-08-08 16:42:37 +03:00
|
|
|
#include <linux/string.h>
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-08-08 16:42:39 +03:00
|
|
|
#include <dt-bindings/leds/leds-pca955x.h>
|
|
|
|
|
2008-07-17 01:49:55 +04:00
|
|
|
/* LED select registers determine the source that drives LED outputs */
|
|
|
|
#define PCA955X_LS_LED_ON 0x0 /* Output LOW */
|
|
|
|
#define PCA955X_LS_LED_OFF 0x1 /* Output HI-Z */
|
|
|
|
#define PCA955X_LS_BLINK0 0x2 /* Blink at PWM0 rate */
|
|
|
|
#define PCA955X_LS_BLINK1 0x3 /* Blink at PWM1 rate */
|
|
|
|
|
leds: pca955x: Don't invert requested value in pca955x_gpio_set_value()
The PCA9552 lines can be used either for driving LEDs or as GPIOs. The
manual states that for LEDs, the operation is open-drain:
The LSn LED select registers determine the source of the LED data.
00 = output is set LOW (LED on)
01 = output is set high-impedance (LED off; default)
10 = output blinks at PWM0 rate
11 = output blinks at PWM1 rate
For GPIOs it suggests a pull-up so that the open-case drives the line
high:
For use as output, connect external pull-up resistor to the pin
and size it according to the DC recommended operating
characteristics. LED output pin is HIGH when the output is
programmed as high-impedance, and LOW when the output is
programmed LOW through the ‘LED selector’ register. The output
can be pulse-width controlled when PWM0 or PWM1 are used.
Now, I have a hardware design that uses the LED controller to control
LEDs. However, for $reasons, we're using the leds-gpio driver to drive
the them. The reasons are here are a tangent but lead to the discovery
of the inversion, which manifested as the LEDs being set to full
brightness at boot when we expected them to be off.
As we're driving the LEDs through leds-gpio, this means wending our way
through the gpiochip abstractions. So with that in mind we need to
describe an active-low GPIO configuration to drive the LEDs as though
they were GPIOs.
The set() gpiochip callback in leds-pca955x does the following:
...
if (val)
pca955x_led_set(&led->led_cdev, LED_FULL);
else
pca955x_led_set(&led->led_cdev, LED_OFF);
...
Where LED_FULL = 255. pca955x_led_set() in turn does:
...
switch (value) {
case LED_FULL:
ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_LED_ON);
break;
...
Where PCA955X_LS_LED_ON is defined as:
#define PCA955X_LS_LED_ON 0x0 /* Output LOW */
So here we have some type confusion: We've crossed domains from GPIO
behaviour to LED behaviour without accounting for possible inversions
in the process.
Stepping back to leds-gpio for a moment, during probe() we call
create_gpio_led(), which eventually executes:
if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP) {
state = gpiod_get_value_cansleep(led_dat->gpiod);
if (state < 0)
return state;
} else {
state = (template->default_state == LEDS_GPIO_DEFSTATE_ON);
}
...
ret = gpiod_direction_output(led_dat->gpiod, state);
In the devicetree the GPIO is annotated as active-low, and
gpiod_get_value_cansleep() handles this for us:
int gpiod_get_value_cansleep(const struct gpio_desc *desc)
{
int value;
might_sleep_if(extra_checks);
VALIDATE_DESC(desc);
value = _gpiod_get_raw_value(desc);
if (value < 0)
return value;
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
value = !value;
return value;
}
_gpiod_get_raw_value() in turn calls through the get() callback for the
gpiochip implementation, so returning to our get() implementation in
leds-pca955x we find we extract the raw value from hardware:
static int pca955x_gpio_get_value(struct gpio_chip *gc, unsigned int offset)
{
struct pca955x *pca955x = gpiochip_get_data(gc);
struct pca955x_led *led = &pca955x->leds[offset];
u8 reg = pca955x_read_input(pca955x->client, led->led_num / 8);
return !!(reg & (1 << (led->led_num % 8)));
}
This behaviour is not symmetric with that of set(), where the val is
inverted by the driver.
Closing the loop on the GPIO_ACTIVE_LOW inversions,
gpiod_direction_output(), like gpiod_get_value_cansleep(), handles it
for us:
int gpiod_direction_output(struct gpio_desc *desc, int value)
{
VALIDATE_DESC(desc);
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
value = !value;
else
value = !!value;
return _gpiod_direction_output_raw(desc, value);
}
All-in-all, with a value of 'keep' for default-state property in a
leds-gpio child node, the current state of the hardware will in-fact be
inverted; precisely the opposite of what was intended.
Rework leds-pca955x so that we avoid the incorrect inversion and clarify
the semantics with respect to GPIO.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Tested-by: Joel Stanley <joel@jms.id.au>
Tested-by: Matt Spinler <mspinler@linux.vnet.ibm.com>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
2017-09-01 08:38:58 +03:00
|
|
|
#define PCA955X_GPIO_INPUT LED_OFF
|
|
|
|
#define PCA955X_GPIO_HIGH LED_OFF
|
|
|
|
#define PCA955X_GPIO_LOW LED_FULL
|
|
|
|
|
2008-07-17 01:49:55 +04:00
|
|
|
enum pca955x_type {
|
|
|
|
pca9550,
|
|
|
|
pca9551,
|
|
|
|
pca9552,
|
2020-08-03 17:50:55 +03:00
|
|
|
ibm_pca9552,
|
2008-07-17 01:49:55 +04:00
|
|
|
pca9553,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pca955x_chipdef {
|
|
|
|
int bits;
|
|
|
|
u8 slv_addr; /* 7-bit slave address mask */
|
|
|
|
int slv_addr_shift; /* Number of bits to ignore */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pca955x_chipdef pca955x_chipdefs[] = {
|
|
|
|
[pca9550] = {
|
|
|
|
.bits = 2,
|
|
|
|
.slv_addr = /* 110000x */ 0x60,
|
|
|
|
.slv_addr_shift = 1,
|
|
|
|
},
|
|
|
|
[pca9551] = {
|
|
|
|
.bits = 8,
|
|
|
|
.slv_addr = /* 1100xxx */ 0x60,
|
|
|
|
.slv_addr_shift = 3,
|
|
|
|
},
|
|
|
|
[pca9552] = {
|
|
|
|
.bits = 16,
|
|
|
|
.slv_addr = /* 1100xxx */ 0x60,
|
|
|
|
.slv_addr_shift = 3,
|
|
|
|
},
|
2020-08-03 17:50:55 +03:00
|
|
|
[ibm_pca9552] = {
|
|
|
|
.bits = 16,
|
|
|
|
.slv_addr = /* 0110xxx */ 0x30,
|
|
|
|
.slv_addr_shift = 3,
|
|
|
|
},
|
2008-07-17 01:49:55 +04:00
|
|
|
[pca9553] = {
|
|
|
|
.bits = 4,
|
|
|
|
.slv_addr = /* 110001x */ 0x62,
|
|
|
|
.slv_addr_shift = 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct i2c_device_id pca955x_id[] = {
|
|
|
|
{ "pca9550", pca9550 },
|
|
|
|
{ "pca9551", pca9551 },
|
|
|
|
{ "pca9552", pca9552 },
|
2020-08-03 17:50:55 +03:00
|
|
|
{ "ibm-pca9552", ibm_pca9552 },
|
2008-07-17 01:49:55 +04:00
|
|
|
{ "pca9553", pca9553 },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, pca955x_id);
|
|
|
|
|
2012-05-30 02:07:30 +04:00
|
|
|
struct pca955x {
|
|
|
|
struct mutex lock;
|
|
|
|
struct pca955x_led *leds;
|
2008-07-17 01:49:55 +04:00
|
|
|
struct pca955x_chipdef *chipdef;
|
|
|
|
struct i2c_client *client;
|
2017-08-08 16:42:39 +03:00
|
|
|
#ifdef CONFIG_LEDS_PCA955X_GPIO
|
|
|
|
struct gpio_chip gpio;
|
|
|
|
#endif
|
2012-05-30 02:07:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pca955x_led {
|
|
|
|
struct pca955x *pca955x;
|
2008-07-17 01:49:55 +04:00
|
|
|
struct led_classdev led_cdev;
|
|
|
|
int led_num; /* 0 .. 15 potentially */
|
|
|
|
char name[32];
|
2017-08-08 16:42:39 +03:00
|
|
|
u32 type;
|
2017-08-08 16:42:37 +03:00
|
|
|
const char *default_trigger;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pca955x_platform_data {
|
|
|
|
struct pca955x_led *leds;
|
|
|
|
int num_leds;
|
2008-07-17 01:49:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 8 bits per input register */
|
|
|
|
static inline int pca95xx_num_input_regs(int bits)
|
|
|
|
{
|
|
|
|
return (bits + 7) / 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 4 bits per LED selector register */
|
|
|
|
static inline int pca95xx_num_led_regs(int bits)
|
|
|
|
{
|
|
|
|
return (bits + 3) / 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return an LED selector register value based on an existing one, with
|
|
|
|
* the appropriate 2-bit state value set for the given LED number (0-3).
|
|
|
|
*/
|
|
|
|
static inline u8 pca955x_ledsel(u8 oldval, int led_num, int state)
|
|
|
|
{
|
|
|
|
return (oldval & (~(0x3 << (led_num << 1)))) |
|
|
|
|
((state & 0x3) << (led_num << 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write to frequency prescaler register, used to program the
|
|
|
|
* period of the PWM output. period = (PSCx + 1) / 38
|
|
|
|
*/
|
2017-08-30 14:25:51 +03:00
|
|
|
static int pca955x_write_psc(struct i2c_client *client, int n, u8 val)
|
2008-07-17 01:49:55 +04:00
|
|
|
{
|
2012-05-30 02:07:30 +04:00
|
|
|
struct pca955x *pca955x = i2c_get_clientdata(client);
|
2017-08-30 14:25:51 +03:00
|
|
|
int ret;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-08-30 14:25:51 +03:00
|
|
|
ret = i2c_smbus_write_byte_data(client,
|
2008-07-17 01:49:55 +04:00
|
|
|
pca95xx_num_input_regs(pca955x->chipdef->bits) + 2*n,
|
|
|
|
val);
|
2017-08-30 14:25:51 +03:00
|
|
|
if (ret < 0)
|
|
|
|
dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
|
|
|
|
__func__, n, val, ret);
|
|
|
|
return ret;
|
2008-07-17 01:49:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write to PWM register, which determines the duty cycle of the
|
|
|
|
* output. LED is OFF when the count is less than the value of this
|
|
|
|
* register, and ON when it is greater. If PWMx == 0, LED is always OFF.
|
|
|
|
*
|
|
|
|
* Duty cycle is (256 - PWMx) / 256
|
|
|
|
*/
|
2017-08-30 14:25:51 +03:00
|
|
|
static int pca955x_write_pwm(struct i2c_client *client, int n, u8 val)
|
2008-07-17 01:49:55 +04:00
|
|
|
{
|
2012-05-30 02:07:30 +04:00
|
|
|
struct pca955x *pca955x = i2c_get_clientdata(client);
|
2017-08-30 14:25:51 +03:00
|
|
|
int ret;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-08-30 14:25:51 +03:00
|
|
|
ret = i2c_smbus_write_byte_data(client,
|
2008-07-17 01:49:55 +04:00
|
|
|
pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + 2*n,
|
|
|
|
val);
|
2017-08-30 14:25:51 +03:00
|
|
|
if (ret < 0)
|
|
|
|
dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
|
|
|
|
__func__, n, val, ret);
|
|
|
|
return ret;
|
2008-07-17 01:49:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write to LED selector register, which determines the source that
|
|
|
|
* drives the LED output.
|
|
|
|
*/
|
2017-08-30 14:25:51 +03:00
|
|
|
static int pca955x_write_ls(struct i2c_client *client, int n, u8 val)
|
2008-07-17 01:49:55 +04:00
|
|
|
{
|
2012-05-30 02:07:30 +04:00
|
|
|
struct pca955x *pca955x = i2c_get_clientdata(client);
|
2017-08-30 14:25:51 +03:00
|
|
|
int ret;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-08-30 14:25:51 +03:00
|
|
|
ret = i2c_smbus_write_byte_data(client,
|
2008-07-17 01:49:55 +04:00
|
|
|
pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n,
|
|
|
|
val);
|
2017-08-30 14:25:51 +03:00
|
|
|
if (ret < 0)
|
|
|
|
dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
|
|
|
|
__func__, n, val, ret);
|
|
|
|
return ret;
|
2008-07-17 01:49:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the LED selector register, which determines the source that
|
|
|
|
* drives the LED output.
|
|
|
|
*/
|
2017-08-30 14:25:51 +03:00
|
|
|
static int pca955x_read_ls(struct i2c_client *client, int n, u8 *val)
|
2008-07-17 01:49:55 +04:00
|
|
|
{
|
2012-05-30 02:07:30 +04:00
|
|
|
struct pca955x *pca955x = i2c_get_clientdata(client);
|
2017-08-30 14:25:51 +03:00
|
|
|
int ret;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-08-30 14:25:51 +03:00
|
|
|
ret = i2c_smbus_read_byte_data(client,
|
2008-07-17 01:49:55 +04:00
|
|
|
pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n);
|
2017-08-30 14:25:51 +03:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "%s: reg 0x%x, err %d\n",
|
|
|
|
__func__, n, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
*val = (u8)ret;
|
|
|
|
return 0;
|
2008-07-17 01:49:55 +04:00
|
|
|
}
|
|
|
|
|
2015-08-20 13:32:35 +03:00
|
|
|
static int pca955x_led_set(struct led_classdev *led_cdev,
|
|
|
|
enum led_brightness value)
|
2008-07-17 01:49:55 +04:00
|
|
|
{
|
2012-05-30 02:07:30 +04:00
|
|
|
struct pca955x_led *pca955x_led;
|
|
|
|
struct pca955x *pca955x;
|
2008-07-17 01:49:55 +04:00
|
|
|
u8 ls;
|
|
|
|
int chip_ls; /* which LSx to use (0-3 potentially) */
|
|
|
|
int ls_led; /* which set of bits within LSx to use (0-3) */
|
2017-08-30 14:25:51 +03:00
|
|
|
int ret;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2015-08-20 13:32:35 +03:00
|
|
|
pca955x_led = container_of(led_cdev, struct pca955x_led, led_cdev);
|
2012-05-30 02:07:30 +04:00
|
|
|
pca955x = pca955x_led->pca955x;
|
|
|
|
|
|
|
|
chip_ls = pca955x_led->led_num / 4;
|
|
|
|
ls_led = pca955x_led->led_num % 4;
|
|
|
|
|
|
|
|
mutex_lock(&pca955x->lock);
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-08-30 14:25:51 +03:00
|
|
|
ret = pca955x_read_ls(pca955x->client, chip_ls, &ls);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2015-08-20 13:32:35 +03:00
|
|
|
switch (value) {
|
2008-07-17 01:49:55 +04:00
|
|
|
case LED_FULL:
|
|
|
|
ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_LED_ON);
|
|
|
|
break;
|
|
|
|
case LED_OFF:
|
|
|
|
ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_LED_OFF);
|
|
|
|
break;
|
|
|
|
case LED_HALF:
|
|
|
|
ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_BLINK0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Use PWM1 for all other values. This has the unwanted
|
|
|
|
* side effect of making all LEDs on the chip share the
|
|
|
|
* same brightness level if set to a value other than
|
|
|
|
* OFF, HALF, or FULL. But, this is probably better than
|
|
|
|
* just turning off for all other values.
|
|
|
|
*/
|
2017-08-30 14:25:51 +03:00
|
|
|
ret = pca955x_write_pwm(pca955x->client, 1, 255 - value);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2008-07-17 01:49:55 +04:00
|
|
|
ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_BLINK1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-30 14:25:51 +03:00
|
|
|
ret = pca955x_write_ls(pca955x->client, chip_ls, ls);
|
2012-05-30 02:07:30 +04:00
|
|
|
|
2017-08-30 14:25:51 +03:00
|
|
|
out:
|
2012-05-30 02:07:30 +04:00
|
|
|
mutex_unlock(&pca955x->lock);
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-08-30 14:25:51 +03:00
|
|
|
return ret;
|
2008-07-17 01:49:55 +04:00
|
|
|
}
|
|
|
|
|
2017-08-08 16:42:39 +03:00
|
|
|
#ifdef CONFIG_LEDS_PCA955X_GPIO
|
|
|
|
/*
|
|
|
|
* Read the INPUT register, which contains the state of LEDs.
|
|
|
|
*/
|
2017-08-30 14:25:51 +03:00
|
|
|
static int pca955x_read_input(struct i2c_client *client, int n, u8 *val)
|
2017-08-08 16:42:39 +03:00
|
|
|
{
|
2017-08-30 14:25:51 +03:00
|
|
|
int ret = i2c_smbus_read_byte_data(client, n);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "%s: reg 0x%x, err %d\n",
|
|
|
|
__func__, n, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
*val = (u8)ret;
|
|
|
|
return 0;
|
|
|
|
|
2017-08-08 16:42:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pca955x_gpio_request_pin(struct gpio_chip *gc, unsigned int offset)
|
|
|
|
{
|
|
|
|
struct pca955x *pca955x = gpiochip_get_data(gc);
|
|
|
|
struct pca955x_led *led = &pca955x->leds[offset];
|
|
|
|
|
|
|
|
if (led->type == PCA955X_TYPE_GPIO)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2017-08-30 14:25:51 +03:00
|
|
|
static int pca955x_set_value(struct gpio_chip *gc, unsigned int offset,
|
|
|
|
int val)
|
2017-08-08 16:42:39 +03:00
|
|
|
{
|
|
|
|
struct pca955x *pca955x = gpiochip_get_data(gc);
|
|
|
|
struct pca955x_led *led = &pca955x->leds[offset];
|
|
|
|
|
|
|
|
if (val)
|
leds: pca955x: Don't invert requested value in pca955x_gpio_set_value()
The PCA9552 lines can be used either for driving LEDs or as GPIOs. The
manual states that for LEDs, the operation is open-drain:
The LSn LED select registers determine the source of the LED data.
00 = output is set LOW (LED on)
01 = output is set high-impedance (LED off; default)
10 = output blinks at PWM0 rate
11 = output blinks at PWM1 rate
For GPIOs it suggests a pull-up so that the open-case drives the line
high:
For use as output, connect external pull-up resistor to the pin
and size it according to the DC recommended operating
characteristics. LED output pin is HIGH when the output is
programmed as high-impedance, and LOW when the output is
programmed LOW through the ‘LED selector’ register. The output
can be pulse-width controlled when PWM0 or PWM1 are used.
Now, I have a hardware design that uses the LED controller to control
LEDs. However, for $reasons, we're using the leds-gpio driver to drive
the them. The reasons are here are a tangent but lead to the discovery
of the inversion, which manifested as the LEDs being set to full
brightness at boot when we expected them to be off.
As we're driving the LEDs through leds-gpio, this means wending our way
through the gpiochip abstractions. So with that in mind we need to
describe an active-low GPIO configuration to drive the LEDs as though
they were GPIOs.
The set() gpiochip callback in leds-pca955x does the following:
...
if (val)
pca955x_led_set(&led->led_cdev, LED_FULL);
else
pca955x_led_set(&led->led_cdev, LED_OFF);
...
Where LED_FULL = 255. pca955x_led_set() in turn does:
...
switch (value) {
case LED_FULL:
ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_LED_ON);
break;
...
Where PCA955X_LS_LED_ON is defined as:
#define PCA955X_LS_LED_ON 0x0 /* Output LOW */
So here we have some type confusion: We've crossed domains from GPIO
behaviour to LED behaviour without accounting for possible inversions
in the process.
Stepping back to leds-gpio for a moment, during probe() we call
create_gpio_led(), which eventually executes:
if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP) {
state = gpiod_get_value_cansleep(led_dat->gpiod);
if (state < 0)
return state;
} else {
state = (template->default_state == LEDS_GPIO_DEFSTATE_ON);
}
...
ret = gpiod_direction_output(led_dat->gpiod, state);
In the devicetree the GPIO is annotated as active-low, and
gpiod_get_value_cansleep() handles this for us:
int gpiod_get_value_cansleep(const struct gpio_desc *desc)
{
int value;
might_sleep_if(extra_checks);
VALIDATE_DESC(desc);
value = _gpiod_get_raw_value(desc);
if (value < 0)
return value;
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
value = !value;
return value;
}
_gpiod_get_raw_value() in turn calls through the get() callback for the
gpiochip implementation, so returning to our get() implementation in
leds-pca955x we find we extract the raw value from hardware:
static int pca955x_gpio_get_value(struct gpio_chip *gc, unsigned int offset)
{
struct pca955x *pca955x = gpiochip_get_data(gc);
struct pca955x_led *led = &pca955x->leds[offset];
u8 reg = pca955x_read_input(pca955x->client, led->led_num / 8);
return !!(reg & (1 << (led->led_num % 8)));
}
This behaviour is not symmetric with that of set(), where the val is
inverted by the driver.
Closing the loop on the GPIO_ACTIVE_LOW inversions,
gpiod_direction_output(), like gpiod_get_value_cansleep(), handles it
for us:
int gpiod_direction_output(struct gpio_desc *desc, int value)
{
VALIDATE_DESC(desc);
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
value = !value;
else
value = !!value;
return _gpiod_direction_output_raw(desc, value);
}
All-in-all, with a value of 'keep' for default-state property in a
leds-gpio child node, the current state of the hardware will in-fact be
inverted; precisely the opposite of what was intended.
Rework leds-pca955x so that we avoid the incorrect inversion and clarify
the semantics with respect to GPIO.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Tested-by: Joel Stanley <joel@jms.id.au>
Tested-by: Matt Spinler <mspinler@linux.vnet.ibm.com>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
2017-09-01 08:38:58 +03:00
|
|
|
return pca955x_led_set(&led->led_cdev, PCA955X_GPIO_HIGH);
|
|
|
|
|
|
|
|
return pca955x_led_set(&led->led_cdev, PCA955X_GPIO_LOW);
|
2017-08-30 14:25:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pca955x_gpio_set_value(struct gpio_chip *gc, unsigned int offset,
|
|
|
|
int val)
|
|
|
|
{
|
|
|
|
pca955x_set_value(gc, offset, val);
|
2017-08-08 16:42:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pca955x_gpio_get_value(struct gpio_chip *gc, unsigned int offset)
|
|
|
|
{
|
|
|
|
struct pca955x *pca955x = gpiochip_get_data(gc);
|
|
|
|
struct pca955x_led *led = &pca955x->leds[offset];
|
2017-08-30 14:25:51 +03:00
|
|
|
u8 reg = 0;
|
|
|
|
|
|
|
|
/* There is nothing we can do about errors */
|
|
|
|
pca955x_read_input(pca955x->client, led->led_num / 8, ®);
|
2017-08-08 16:42:39 +03:00
|
|
|
|
|
|
|
return !!(reg & (1 << (led->led_num % 8)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pca955x_gpio_direction_input(struct gpio_chip *gc,
|
|
|
|
unsigned int offset)
|
|
|
|
{
|
leds: pca955x: Don't invert requested value in pca955x_gpio_set_value()
The PCA9552 lines can be used either for driving LEDs or as GPIOs. The
manual states that for LEDs, the operation is open-drain:
The LSn LED select registers determine the source of the LED data.
00 = output is set LOW (LED on)
01 = output is set high-impedance (LED off; default)
10 = output blinks at PWM0 rate
11 = output blinks at PWM1 rate
For GPIOs it suggests a pull-up so that the open-case drives the line
high:
For use as output, connect external pull-up resistor to the pin
and size it according to the DC recommended operating
characteristics. LED output pin is HIGH when the output is
programmed as high-impedance, and LOW when the output is
programmed LOW through the ‘LED selector’ register. The output
can be pulse-width controlled when PWM0 or PWM1 are used.
Now, I have a hardware design that uses the LED controller to control
LEDs. However, for $reasons, we're using the leds-gpio driver to drive
the them. The reasons are here are a tangent but lead to the discovery
of the inversion, which manifested as the LEDs being set to full
brightness at boot when we expected them to be off.
As we're driving the LEDs through leds-gpio, this means wending our way
through the gpiochip abstractions. So with that in mind we need to
describe an active-low GPIO configuration to drive the LEDs as though
they were GPIOs.
The set() gpiochip callback in leds-pca955x does the following:
...
if (val)
pca955x_led_set(&led->led_cdev, LED_FULL);
else
pca955x_led_set(&led->led_cdev, LED_OFF);
...
Where LED_FULL = 255. pca955x_led_set() in turn does:
...
switch (value) {
case LED_FULL:
ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_LED_ON);
break;
...
Where PCA955X_LS_LED_ON is defined as:
#define PCA955X_LS_LED_ON 0x0 /* Output LOW */
So here we have some type confusion: We've crossed domains from GPIO
behaviour to LED behaviour without accounting for possible inversions
in the process.
Stepping back to leds-gpio for a moment, during probe() we call
create_gpio_led(), which eventually executes:
if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP) {
state = gpiod_get_value_cansleep(led_dat->gpiod);
if (state < 0)
return state;
} else {
state = (template->default_state == LEDS_GPIO_DEFSTATE_ON);
}
...
ret = gpiod_direction_output(led_dat->gpiod, state);
In the devicetree the GPIO is annotated as active-low, and
gpiod_get_value_cansleep() handles this for us:
int gpiod_get_value_cansleep(const struct gpio_desc *desc)
{
int value;
might_sleep_if(extra_checks);
VALIDATE_DESC(desc);
value = _gpiod_get_raw_value(desc);
if (value < 0)
return value;
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
value = !value;
return value;
}
_gpiod_get_raw_value() in turn calls through the get() callback for the
gpiochip implementation, so returning to our get() implementation in
leds-pca955x we find we extract the raw value from hardware:
static int pca955x_gpio_get_value(struct gpio_chip *gc, unsigned int offset)
{
struct pca955x *pca955x = gpiochip_get_data(gc);
struct pca955x_led *led = &pca955x->leds[offset];
u8 reg = pca955x_read_input(pca955x->client, led->led_num / 8);
return !!(reg & (1 << (led->led_num % 8)));
}
This behaviour is not symmetric with that of set(), where the val is
inverted by the driver.
Closing the loop on the GPIO_ACTIVE_LOW inversions,
gpiod_direction_output(), like gpiod_get_value_cansleep(), handles it
for us:
int gpiod_direction_output(struct gpio_desc *desc, int value)
{
VALIDATE_DESC(desc);
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
value = !value;
else
value = !!value;
return _gpiod_direction_output_raw(desc, value);
}
All-in-all, with a value of 'keep' for default-state property in a
leds-gpio child node, the current state of the hardware will in-fact be
inverted; precisely the opposite of what was intended.
Rework leds-pca955x so that we avoid the incorrect inversion and clarify
the semantics with respect to GPIO.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Tested-by: Joel Stanley <joel@jms.id.au>
Tested-by: Matt Spinler <mspinler@linux.vnet.ibm.com>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
2017-09-01 08:38:58 +03:00
|
|
|
struct pca955x *pca955x = gpiochip_get_data(gc);
|
|
|
|
struct pca955x_led *led = &pca955x->leds[offset];
|
|
|
|
|
|
|
|
/* To use as input ensure pin is not driven. */
|
|
|
|
return pca955x_led_set(&led->led_cdev, PCA955X_GPIO_INPUT);
|
2017-08-08 16:42:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pca955x_gpio_direction_output(struct gpio_chip *gc,
|
|
|
|
unsigned int offset, int val)
|
|
|
|
{
|
2017-08-30 14:25:51 +03:00
|
|
|
return pca955x_set_value(gc, offset, val);
|
2017-08-08 16:42:39 +03:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_LEDS_PCA955X_GPIO */
|
|
|
|
|
2017-08-08 16:42:37 +03:00
|
|
|
static struct pca955x_platform_data *
|
2019-03-25 17:05:00 +03:00
|
|
|
pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
|
2017-08-08 16:42:37 +03:00
|
|
|
{
|
|
|
|
struct pca955x_platform_data *pdata;
|
2019-03-25 17:05:00 +03:00
|
|
|
struct fwnode_handle *child;
|
2017-08-08 16:42:37 +03:00
|
|
|
int count;
|
|
|
|
|
2019-03-25 17:05:00 +03:00
|
|
|
count = device_get_child_node_count(&client->dev);
|
2017-08-08 16:42:37 +03:00
|
|
|
if (!count || count > chip->bits)
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
|
|
|
|
pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
|
|
|
|
if (!pdata)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 00:07:58 +03:00
|
|
|
pdata->leds = devm_kcalloc(&client->dev,
|
|
|
|
chip->bits, sizeof(struct pca955x_led),
|
2017-08-08 16:42:37 +03:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!pdata->leds)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2019-03-25 17:05:00 +03:00
|
|
|
device_for_each_child_node(&client->dev, child) {
|
2017-08-08 16:42:37 +03:00
|
|
|
const char *name;
|
|
|
|
u32 reg;
|
|
|
|
int res;
|
|
|
|
|
2019-03-25 17:05:00 +03:00
|
|
|
res = fwnode_property_read_u32(child, "reg", ®);
|
2017-08-08 16:42:37 +03:00
|
|
|
if ((res != 0) || (reg >= chip->bits))
|
|
|
|
continue;
|
|
|
|
|
2019-03-25 17:05:00 +03:00
|
|
|
res = fwnode_property_read_string(child, "label", &name);
|
|
|
|
if ((res != 0) && is_of_node(child))
|
|
|
|
name = to_of_node(child)->name;
|
2017-08-08 16:42:37 +03:00
|
|
|
|
|
|
|
snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name),
|
|
|
|
"%s", name);
|
|
|
|
|
2017-08-08 16:42:39 +03:00
|
|
|
pdata->leds[reg].type = PCA955X_TYPE_LED;
|
2019-03-25 17:05:00 +03:00
|
|
|
fwnode_property_read_u32(child, "type", &pdata->leds[reg].type);
|
|
|
|
fwnode_property_read_string(child, "linux,default-trigger",
|
2017-08-08 16:42:37 +03:00
|
|
|
&pdata->leds[reg].default_trigger);
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata->num_leds = chip->bits;
|
|
|
|
|
|
|
|
return pdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id of_pca955x_match[] = {
|
|
|
|
{ .compatible = "nxp,pca9550", .data = (void *)pca9550 },
|
|
|
|
{ .compatible = "nxp,pca9551", .data = (void *)pca9551 },
|
|
|
|
{ .compatible = "nxp,pca9552", .data = (void *)pca9552 },
|
2020-08-03 17:50:55 +03:00
|
|
|
{ .compatible = "ibm,pca9552", .data = (void *)ibm_pca9552 },
|
2017-08-08 16:42:37 +03:00
|
|
|
{ .compatible = "nxp,pca9553", .data = (void *)pca9553 },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, of_pca955x_match);
|
|
|
|
|
2012-11-19 22:23:02 +04:00
|
|
|
static int pca955x_probe(struct i2c_client *client,
|
2008-07-17 01:49:55 +04:00
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
2012-05-30 02:07:30 +04:00
|
|
|
struct pca955x *pca955x;
|
|
|
|
struct pca955x_led *pca955x_led;
|
2008-07-17 01:49:55 +04:00
|
|
|
struct pca955x_chipdef *chip;
|
|
|
|
struct i2c_adapter *adapter;
|
2008-10-04 02:23:48 +04:00
|
|
|
int i, err;
|
2017-08-08 16:42:37 +03:00
|
|
|
struct pca955x_platform_data *pdata;
|
2017-08-08 16:42:39 +03:00
|
|
|
int ngpios = 0;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2019-03-15 22:13:42 +03:00
|
|
|
chip = &pca955x_chipdefs[id->driver_data];
|
2019-06-08 13:55:43 +03:00
|
|
|
adapter = client->adapter;
|
2013-07-30 12:07:35 +04:00
|
|
|
pdata = dev_get_platdata(&client->dev);
|
2017-08-08 16:42:37 +03:00
|
|
|
if (!pdata) {
|
2019-03-25 17:05:00 +03:00
|
|
|
pdata = pca955x_get_pdata(client, chip);
|
2017-08-08 16:42:37 +03:00
|
|
|
if (IS_ERR(pdata))
|
|
|
|
return PTR_ERR(pdata);
|
|
|
|
}
|
2008-07-17 01:49:55 +04:00
|
|
|
|
|
|
|
/* Make sure the slave address / chip type combo given is possible */
|
|
|
|
if ((client->addr & ~((1 << chip->slv_addr_shift) - 1)) !=
|
|
|
|
chip->slv_addr) {
|
|
|
|
dev_err(&client->dev, "invalid slave address %02x\n",
|
|
|
|
client->addr);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2012-11-25 10:51:47 +04:00
|
|
|
dev_info(&client->dev, "leds-pca955x: Using %s %d-bit LED driver at "
|
2008-07-17 01:49:55 +04:00
|
|
|
"slave address 0x%02x\n",
|
2016-12-02 07:39:13 +03:00
|
|
|
client->name, chip->bits, client->addr);
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-05-22 12:19:20 +03:00
|
|
|
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
2008-07-17 01:49:55 +04:00
|
|
|
return -EIO;
|
|
|
|
|
2017-08-08 16:42:37 +03:00
|
|
|
if (pdata->num_leds != chip->bits) {
|
|
|
|
dev_err(&client->dev,
|
|
|
|
"board info claims %d LEDs on a %d-bit chip\n",
|
|
|
|
pdata->num_leds, chip->bits);
|
|
|
|
return -ENODEV;
|
2008-07-17 01:49:55 +04:00
|
|
|
}
|
|
|
|
|
2012-07-04 08:09:05 +04:00
|
|
|
pca955x = devm_kzalloc(&client->dev, sizeof(*pca955x), GFP_KERNEL);
|
2008-10-04 02:23:48 +04:00
|
|
|
if (!pca955x)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 00:07:58 +03:00
|
|
|
pca955x->leds = devm_kcalloc(&client->dev,
|
|
|
|
chip->bits, sizeof(*pca955x_led), GFP_KERNEL);
|
2012-07-04 08:09:05 +04:00
|
|
|
if (!pca955x->leds)
|
|
|
|
return -ENOMEM;
|
2012-05-30 02:07:30 +04:00
|
|
|
|
2008-10-04 02:23:48 +04:00
|
|
|
i2c_set_clientdata(client, pca955x);
|
|
|
|
|
2012-05-30 02:07:30 +04:00
|
|
|
mutex_init(&pca955x->lock);
|
|
|
|
pca955x->client = client;
|
|
|
|
pca955x->chipdef = chip;
|
|
|
|
|
2008-07-17 01:49:55 +04:00
|
|
|
for (i = 0; i < chip->bits; i++) {
|
2012-05-30 02:07:30 +04:00
|
|
|
pca955x_led = &pca955x->leds[i];
|
|
|
|
pca955x_led->led_num = i;
|
|
|
|
pca955x_led->pca955x = pca955x;
|
2017-08-08 16:42:39 +03:00
|
|
|
pca955x_led->type = pdata->leds[i].type;
|
|
|
|
|
|
|
|
switch (pca955x_led->type) {
|
|
|
|
case PCA955X_TYPE_NONE:
|
|
|
|
break;
|
|
|
|
case PCA955X_TYPE_GPIO:
|
|
|
|
ngpios++;
|
|
|
|
break;
|
|
|
|
case PCA955X_TYPE_LED:
|
|
|
|
/*
|
|
|
|
* Platform data can specify LED names and
|
|
|
|
* default triggers
|
|
|
|
*/
|
2017-08-17 23:16:48 +03:00
|
|
|
if (pdata->leds[i].name[0] == '\0')
|
|
|
|
snprintf(pdata->leds[i].name,
|
|
|
|
sizeof(pdata->leds[i].name), "%d", i);
|
|
|
|
|
|
|
|
snprintf(pca955x_led->name,
|
|
|
|
sizeof(pca955x_led->name), "pca955x:%s",
|
|
|
|
pdata->leds[i].name);
|
|
|
|
|
2008-07-17 01:49:55 +04:00
|
|
|
if (pdata->leds[i].default_trigger)
|
2012-05-30 02:07:30 +04:00
|
|
|
pca955x_led->led_cdev.default_trigger =
|
2008-07-17 01:49:55 +04:00
|
|
|
pdata->leds[i].default_trigger;
|
|
|
|
|
2017-08-08 16:42:39 +03:00
|
|
|
pca955x_led->led_cdev.name = pca955x_led->name;
|
|
|
|
pca955x_led->led_cdev.brightness_set_blocking =
|
|
|
|
pca955x_led_set;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-08-08 16:42:39 +03:00
|
|
|
err = devm_led_classdev_register(&client->dev,
|
|
|
|
&pca955x_led->led_cdev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-08-08 16:42:39 +03:00
|
|
|
/* Turn off LED */
|
2017-08-30 14:25:51 +03:00
|
|
|
err = pca955x_led_set(&pca955x_led->led_cdev, LED_OFF);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2017-08-08 16:42:39 +03:00
|
|
|
}
|
|
|
|
}
|
2008-07-17 01:49:55 +04:00
|
|
|
|
|
|
|
/* PWM0 is used for half brightness or 50% duty cycle */
|
2017-08-30 14:25:51 +03:00
|
|
|
err = pca955x_write_pwm(client, 0, 255 - LED_HALF);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
|
|
|
/* PWM1 is used for variable brightness, default to OFF */
|
2017-08-30 14:25:51 +03:00
|
|
|
err = pca955x_write_pwm(client, 1, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
|
|
|
/* Set to fast frequency so we do not see flashing */
|
2017-08-30 14:25:51 +03:00
|
|
|
err = pca955x_write_psc(client, 0, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
err = pca955x_write_psc(client, 1, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2008-07-17 01:49:55 +04:00
|
|
|
|
2017-08-08 16:42:39 +03:00
|
|
|
#ifdef CONFIG_LEDS_PCA955X_GPIO
|
|
|
|
if (ngpios) {
|
|
|
|
pca955x->gpio.label = "gpio-pca955x";
|
|
|
|
pca955x->gpio.direction_input = pca955x_gpio_direction_input;
|
|
|
|
pca955x->gpio.direction_output = pca955x_gpio_direction_output;
|
|
|
|
pca955x->gpio.set = pca955x_gpio_set_value;
|
|
|
|
pca955x->gpio.get = pca955x_gpio_get_value;
|
|
|
|
pca955x->gpio.request = pca955x_gpio_request_pin;
|
|
|
|
pca955x->gpio.can_sleep = 1;
|
|
|
|
pca955x->gpio.base = -1;
|
|
|
|
pca955x->gpio.ngpio = ngpios;
|
|
|
|
pca955x->gpio.parent = &client->dev;
|
|
|
|
pca955x->gpio.owner = THIS_MODULE;
|
|
|
|
|
|
|
|
err = devm_gpiochip_add_data(&client->dev, &pca955x->gpio,
|
|
|
|
pca955x);
|
|
|
|
if (err) {
|
|
|
|
/* Use data->gpio.dev as a flag for freeing gpiochip */
|
|
|
|
pca955x->gpio.parent = NULL;
|
|
|
|
dev_warn(&client->dev, "could not add gpiochip\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
dev_info(&client->dev, "gpios %i...%i\n",
|
|
|
|
pca955x->gpio.base, pca955x->gpio.base +
|
|
|
|
pca955x->gpio.ngpio - 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-07-17 01:49:55 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct i2c_driver pca955x_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "leds-pca955x",
|
2019-03-25 17:05:00 +03:00
|
|
|
.of_match_table = of_pca955x_match,
|
2008-07-17 01:49:55 +04:00
|
|
|
},
|
|
|
|
.probe = pca955x_probe,
|
|
|
|
.id_table = pca955x_id,
|
|
|
|
};
|
|
|
|
|
2012-01-11 03:09:27 +04:00
|
|
|
module_i2c_driver(pca955x_driver);
|
2008-07-17 01:49:55 +04:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Nate Case <ncase@xes-inc.com>");
|
|
|
|
MODULE_DESCRIPTION("PCA955x LED driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|