leds: pca955x: mainline update and I2C error checking
cover leds: pca955x: mainline update and I2C error checking
Hi,
The GPIO extension to the pca955x driver should be part of 4.14-rc1 when the window opens. And so, the first patch of this series brings the current driver of the openbmc 4.10 kernel to the same level. The second patch adds I2C error checking which should help in detecting bogus devices or bogus device trees at probe time.
Andrew,
I made some changes in patch 2/2.
Cheers,
C.
Cédric Le Goater (2):
leds: pca955x: sync with mainline driver
leds: pca955x: check for I2C errors
drivers/leds/leds-pca955x.c | 142 ++++++++++++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 51 deletions(-)
Signature · 1 line
2.13.5
PATCH 1/2 leds: pca955x: sync with mainline driver
The result should be in sync with kernel 4.14 once the gpio extension is merged in the pca955x driver.
--- drivers/leds/leds-pca955x.c | 49 ++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 30 deletions(-)
drivers/leds/leds-pca955x.c +19 -30
@@ -342,7 +342,8 @@ pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip)return ERR_PTR (-ENOMEM ); pdata->leds =devm_kzalloc (&client->dev, -sizeof (struct pca955x_led ) * chip->bits,GFP_KERNEL ); +sizeof (struct pca955x_led ) * chip->bits, +GFP_KERNEL );if (!pdata->leds)return ERR_PTR (-ENOMEM );
@@ -430,16 +431,14 @@ static int pca955x_probe(struct i2c_client *client,"slave address 0x%02x\n" , client->name, chip->bits, client->addr); -if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) +if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA ))return -EIO ; -if (pdata) { -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 ; - } +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 ; } pca955x =devm_kzalloc (&client->dev,sizeof (*pca955x),GFP_KERNEL );
@@ -458,12 +457,10 @@ static int pca955x_probe(struct i2c_client *client, pca955x->chipdef = chip;for (i =0 ; i < chip->bits; i++) { -struct pca955x_led *pdata_led = &pdata->leds[i]; - pca955x_led = &pca955x->leds[i]; pca955x_led->led_num = i; pca955x_led->pca955x = pca955x; - pca955x_led->type = pdata_led->type; + pca955x_led->type = pdata->leds[i].type;switch (pca955x_led->type) {case PCA955X_TYPE_NONE :
@@ -476,27 +473,20 @@ static int pca955x_probe(struct i2c_client *client,* Platform data can specify LED names and * default triggers */ -if (pdata) { -if (pdata->leds[i].name) -snprintf (pca955x_led->name, -sizeof (pca955x_led->name), -"pca955x:%s" , - pdata->leds[i].name); -if (pdata->leds[i].default_trigger) - pca955x_led->led_cdev.default_trigger = - pdata->leds[i].default_trigger; - }else { +if (pdata->leds[i].name)snprintf (pca955x_led->name, -sizeof (pca955x_led->name), -"pca955x:%d" , i); - } +sizeof (pca955x_led->name),"pca955x:%s" , + pdata->leds[i].name); +if (pdata->leds[i].default_trigger) + pca955x_led->led_cdev.default_trigger = + pdata->leds[i].default_trigger; pca955x_led->led_cdev.name = pca955x_led->name; pca955x_led->led_cdev.brightness_set_blocking = pca955x_led_set; err =devm_led_classdev_register (&client->dev, - &pca955x_led->led_cdev); + &pca955x_led->led_cdev);if (err)return err;
@@ -536,11 +526,10 @@ static int pca955x_probe(struct i2c_client *client, pca955x->gpio.parent =NULL ;dev_warn (&client->dev,"could not add gpiochip\n" ); return err; - }else { -dev_info (&client->dev,"gpios %i...%i\n" , - pca955x->gpio.base, pca955x->gpio.base + - pca955x->gpio.ngpio -1 ); } +dev_info (&client->dev,"gpios %i...%i\n" , + pca955x->gpio.base, pca955x->gpio.base + + pca955x->gpio.ngpio -1 ); }#endif
Signature · 1 line
2.13.5
Andrew Jeffery
AppliedRe: [PATCH linux dev-4.10 1/2] leds: pca955x: sync with mainline driver
Quoted 4 lines · Cédric Le Goater
The result should be in sync with kernel 4.14 once the gpio extension is merged in the pca955x driver.
Signed-off-by Cédric Le Goater <[email protected]>
Thanks, applied to dev-4.10.
Andrew
Quoted 133 lines
---
drivers/leds/leds-pca955x.c | 49 ++++++++++++++++++-----------------
----------1 file changed, 19 insertions(+), 30 deletions(-)drivers/leds/leds- renamed from drivers/leds/leds-pca955x.c +0
-0
pca955x.c
index0217bac2f47b..f062d1e7640f100644drivers/leds/leds-pca955x.c +0
-0@@ -342,7 +342,8 @@ pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip) return ERR_PTR(-ENOMEM);
pdata->leds= devm_kzalloc(&client->dev,drivers/leds/leds-pca955x.c +0
-1- sizeof(struct pca955x_led) * chip->bits,
GFP_KERNEL);drivers/leds/leds-pca955x.c +1
-0+ sizeof(struct pca955x_led) *
chip->bits,drivers/leds/leds-pca955x.c +1
-0+ GFP_KERNEL);if (!pdata->leds)
returnERR_PTR(-ENOMEM);drivers/leds/leds-pca955x.c +0
-0@@ -430,16 +431,14 @@ static int pca955x_probe(struct i2c_client *client, "slave address 0x%02x\n", client->name, chip->bits, client->addr);drivers/leds/leds-pca955x.c +1
-1-if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) + if (!i2c_check_functionality(adapter,
I2C_FUNC_SMBUS_BYTE_DATA))
return-EIO;drivers/leds/leds-pca955x.c +0
-3-if (pdata) { -if (pdata->num_leds != chip->bits) { - dev_err(&client->dev, "board info claims %dLEDs"
drivers/leds/leds-pca955x.c +0
-2-" on a %d-bit chip\n" , - pdata->num_leds, chip-Quoted 1 line
bits);
drivers/leds/leds-pca955x.c +3
-2-return -ENODEV ; - } +if (pdata->num_leds != chip->bits) { + dev_err(&client->dev, + "board info claims %d LEDs on a %d-bitchip\n",
drivers/leds/leds-pca955x.c +2
-0+ pdata->num_leds, chip->bits); +return -ENODEV ;}
pca955x =devm_kzalloc(&client->dev, sizeof(*pca955x), GFP_KERNEL);drivers/leds/leds-pca955x.c +0
-0@@ -458,12 +457,10 @@ static int pca955x_probe(struct i2c_client *client, pca955x->chipdef = chip;
for (i = 0; i <chip->bits; i++) {drivers/leds/leds-pca955x.c +0
-2-struct pca955x_led *pdata_led = &pdata->leds[i]; -
pca955x_led= &pca955x->leds[i];
pca955x_led->led_num= i;
pca955x_led->pca955x= pca955x;drivers/leds/leds-pca955x.c +1
-1- pca955x_led->type = pdata_led->type; + pca955x_led->type = pdata->leds[i].type;
switch (pca955x_led->type) {
casePCA955X_TYPE_NONE:drivers/leds/leds-pca955x.c +0
-8@@ -476,27 +473,20 @@ static int pca955x_probe(struct i2c_client*client, * Platform data can specify LED names and * default triggers */ -if (pdata) { -if (pdata->leds[i].name) -snprintf (pca955x_led->name, - sizeof(pca955x_led- >name), - "pca955x:%s", - pdata- >leds[i].name); -if (pdata->leds[i].default_trigger) - pca955x_led-Quoted 1 line
led_cdev.default_trigger =
drivers/leds/leds-pca955x.c +0
-1- pdata-Quoted 1 line
leds[i].default_trigger;
drivers/leds/leds-pca955x.c +1
-1- }else { +if (pdata->leds[i].name)snprintf(pca955x_led->name,
drivers/leds/leds-pca955x.c +1
-3- sizeof(pca955x_led->name), - "pca955x:%d", i); - } + sizeof(pca955x_led->name),"pca955x:%s",
drivers/leds/leds-pca955x.c +3
-0+ pdata->leds[i].name); +if (pdata->leds[i].default_trigger) + pca955x_led-Quoted 1 line
led_cdev.default_trigger =
drivers/leds/leds-pca955x.c +1
-0+ pdata-Quoted 1 line
leds[i].default_trigger;
pca955x_led->led_cdev.name= pca955x_led-Quoted 1 line
name;
pca955x_led-
Quoted 1 line
led_cdev.brightness_set_blocking =
pca955x_led_set;
err = devm_led_classdev_register(&client-Quoted 1 line
dev,
drivers/leds/leds-pca955x.c +0
-1- &pca955x_led-Quoted 1 line
led_cdev);drivers/leds/leds-pca955x.c +1
-1+ &pca955x_led ->led_cdev);if (err)
return err;drivers/leds/leds-pca955x.c +0
-0@@ -536,11 +526,10 @@ static int pca955x_probe(struct i2c_client *client, pca955x->gpio.parent = NULL;
dev_warn(&client->dev, "could not add gpiochip\n");
return err;drivers/leds/leds-pca955x.c +0
-3- }else { - dev_info(&client->dev, "gpios %i...%i\n", - pca955x->gpio.base, pca955x-Quoted 1 line
gpio.base +
drivers/leds/leds-pca955x.c +0
-1- pca955x->gpio.ngpio - 1);}
drivers/leds/leds-pca955x.c +3
-0+dev_info (&client->dev,"gpios %i...%i\n" , + pca955x->gpio.base, pca955x->gpio.base + + pca955x->gpio.ngpio - 1);}
#endif
PATCH 2/2 leds: pca955x: check for I2C errors
In reply to Cédric Le GoaterThis should also allow probing to fail when a pca955x chip is not found on a I2C bus.
--- drivers/leds/leds-pca955x.c | 93 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 21 deletions(-)
drivers/leds/leds-pca955x.c +72 -21
@@ -165,13 +165,18 @@ static inline u8 pca955x_ledsel(u8 oldval, int led_num, int state)* Write to frequency prescaler register, used to program the * period of the PWM output. period = (PSCx + 1) / 38 */ -static void pca955x_write_psc (struct i2c_client *client,int n,u8 val) +static int pca955x_write_psc (struct i2c_client *client,int n,u8 val) {struct pca955x *pca955x =i2c_get_clientdata (client); +int ret; -i2c_smbus_write_byte_data (client, + ret =i2c_smbus_write_byte_data (client,pca95xx_num_input_regs (pca955x->chipdef->bits) +2 *n, val); +if (ret <0 ) +dev_err (&client->dev,"%s: reg 0x%x, val 0x%x, err %d\n" , + __func__, n, val, ret); +return ret; }/*
@@ -181,38 +186,57 @@ static void pca955x_write_psc(struct i2c_client *client, int n, u8 val)* * Duty cycle is (256 - PWMx) / 256 */ -static void pca955x_write_pwm (struct i2c_client *client,int n,u8 val) +static int pca955x_write_pwm (struct i2c_client *client,int n,u8 val) {struct pca955x *pca955x =i2c_get_clientdata (client); +int ret; -i2c_smbus_write_byte_data (client, + ret =i2c_smbus_write_byte_data (client,pca95xx_num_input_regs (pca955x->chipdef->bits) +1 +2 *n, val); +if (ret <0 ) +dev_err (&client->dev,"%s: reg 0x%x, val 0x%x, err %d\n" , + __func__, n, val, ret); +return ret; } +/* * Write to LED selector register, which determines the source that * drives the LED output. */ -static void pca955x_write_ls (struct i2c_client *client,int n,u8 val) +static int pca955x_write_ls (struct i2c_client *client,int n,u8 val) {struct pca955x *pca955x =i2c_get_clientdata (client); +int ret; -i2c_smbus_write_byte_data (client, + ret =i2c_smbus_write_byte_data (client,pca95xx_num_input_regs (pca955x->chipdef->bits) +4 + n, val); +if (ret <0 ) +dev_err (&client->dev,"%s: reg 0x%x, val 0x%x, err %d\n" , + __func__, n, val, ret); +return ret; }/* * Read the LED selector register, which determines the source that * drives the LED output. */ -static u8 pca955x_read_ls (struct i2c_client *client,int n) +static int pca955x_read_ls (struct i2c_client *client,int n,u8 *val) {struct pca955x *pca955x =i2c_get_clientdata (client); +int ret; -return (u8 )i2c_smbus_read_byte_data (client, + ret =i2c_smbus_read_byte_data (client,pca95xx_num_input_regs (pca955x->chipdef->bits) +4 + 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 ; } static int pca955x_led_set(struct led_classdev *led_cdev,
@@ -223,6 +247,7 @@ static int pca955x_led_set(struct led_classdev *led_cdev,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) */ +int ret; pca955x_led = container_of(led_cdev, struct pca955x_led, led_cdev); pca955x = pca955x_led->pca955x;
@@ -232,7 +257,9 @@ static int pca955x_led_set(struct led_classdev *led_cdev,mutex_lock (&pca955x->lock); - ls =pca955x_read_ls (pca955x->client, chip_ls); + ret =pca955x_read_ls (pca955x->client, chip_ls, &ls); +if (ret) + goto out;switch (value) {case LED_FULL :
@@ -252,26 +279,37 @@ static int pca955x_led_set(struct led_classdev *led_cdev,* OFF, HALF, or FULL. But, this is probably better than * just turning off for all other values. */ -pca955x_write_pwm (pca955x->client,1 , -255 - value); + ret =pca955x_write_pwm (pca955x->client,1 ,255 - value); +if (ret) + goto out; ls =pca955x_ledsel (ls, ls_led,PCA955X_LS_BLINK1 );break ; } -pca955x_write_ls (pca955x->client, chip_ls, ls); + ret =pca955x_write_ls (pca955x->client, chip_ls, ls); +out:mutex_unlock (&pca955x->lock); -return 0 ; +return ret; }#ifdef CONFIG_LEDS_PCA955X_GPIO /* * Read the INPUT register, which contains the state of LEDs. */ -static u8 pca955x_read_input (struct i2c_client *client,int n) +static int pca955x_read_input (struct i2c_client *client,int n,u8 *val) { -return (u8 )i2c_smbus_read_byte_data (client, n); +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 ; + }static int pca955x_gpio_request_pin (struct gpio_chip *gc,unsigned int offset)
@@ -301,7 +339,10 @@ 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 ); +u8 reg =0 ; + +/* There is nothing we can do about errors */ +pca955x_read_input (pca955x->client, led->led_num /8 , ®);return !!(reg & (1 << (led->led_num %8 ))); }
@@ -491,19 +532,29 @@ static int pca955x_probe(struct i2c_client *client,return err;/* Turn off LED */ -pca955x_led_set (&pca955x_led->led_cdev,LED_OFF ); + err =pca955x_led_set (&pca955x_led->led_cdev,LED_OFF ); +if (err) +return err; } }/* PWM0 is used for half brightness or 50% duty cycle */ -pca955x_write_pwm (client,0 ,255 -LED_HALF ); + err =pca955x_write_pwm (client,0 ,255 -LED_HALF ); +if (err) +return err;/* PWM1 is used for variable brightness, default to OFF */ -pca955x_write_pwm (client,1 ,0 ); + err =pca955x_write_pwm (client,1 ,0 ); +if (err) +return err;/* Set to fast frequency so we do not see flashing */ -pca955x_write_psc (client,0 ,0 ); -pca955x_write_psc (client,1 ,0 ); + err =pca955x_write_psc (client,0 ,0 ); +if (err) +return err; + err =pca955x_write_psc (client,1 ,0 ); +if (err) +return err;#ifdef CONFIG_LEDS_PCA955X_GPIO if (ngpios) {
Signature · 1 line
2.13.5
Re: [PATCH linux dev-4.10 2/2] leds: pca955x: check for I2C errors
Hi Cédric,
drivers/leds/leds-pca955x.c static int pca955x_gpio_get_value(struct gpio_chip *gc, unsigned int offset)
Quoted 161 lines · Cédric Le Goater
This should also allow probing to fail when a pca955x chip is not found on a I2C bus.
Quoted 1 line
Signed-off-by Cédric Le Goater <[email protected]>---
drivers/leds/leds-pca955x.c | 93 +++++++++++++++++++++++++++++++++++----------1 file changed, 72 insertions(+), 21 deletions(-)drivers/leds/leds-pca955x.c +1
-1@@ -165,13 +165,18 @@ static inline u8 pca955x_ledsel(u8 oldval, int led_num, int state)* Write to frequency prescaler register, used to program the * period of the PWM output. period = (PSCx + 1) / 38 */ -static void pca955x_write_psc (struct i2c_client *client,int n,u8 val) +static int pca955x_write_psc (struct i2c_client *client,int n,u8 val) { > struct pca955x *pca955x = i2c_get_clientdata(client); > + int ret;drivers/leds/leds-pca955x.c static inline u8 pca955x_ledsel(u8 oldval, int led_num, int state) · line 179
Quoted 8 lines
(quoted diff) +1
-1- i2c_smbus_write_byte_data(client, + ret = i2c_smbus_write_byte_data(client,
pca95xx_num_input_regs(pca955x->chipdef->bits)+ 2*n, val);drivers/leds/leds-pca955x.c +4
-0+if (ret <0 ) +dev_err (&client->dev,"%s: reg 0x%x, val 0x%x, err %d\n" , + __func__, n, val, ret); +return ret;}
/*drivers/leds/leds-pca955x.c +1
-1@@ -181,38 +186,57 @@ static void pca955x_write_psc(struct i2c_client *client, int n, u8 val)* * Duty cycle is (256 - PWMx) / 256 */ -static void pca955x_write_pwm (struct i2c_client *client,int n,u8 val) +static int pca955x_write_pwm (struct i2c_client *client,int n,u8 val) { > struct pca955x *pca955x = i2c_get_clientdata(client); > + int ret;drivers/leds/leds-pca955x.c static inline u8 pca955x_ledsel(u8 oldval, int led_num, int state) · line 179
Quoted 8 lines
(quoted diff) +1
-1- i2c_smbus_write_byte_data(client, + ret = i2c_smbus_write_byte_data(client,
pca95xx_num_input_regs(pca955x->chipdef->bits)+ 1 + 2*n, val);drivers/leds/leds-pca955x.c +4
-0+if (ret <0 ) +dev_err (&client->dev,"%s: reg 0x%x, val 0x%x, err %d\n" , + __func__, n, val, ret); +return ret;}
+
/*
* Write to LED selector register, which determines the source that
* drives the LED output.
*/drivers/leds/leds-pca955x.c +1
-1-static void pca955x_write_ls (struct i2c_client *client,int n,u8 val) +static int pca955x_write_ls (struct i2c_client *client,int n,u8 val){
Review
Quoted 2 lines
struct pca955x *pca955x =
i2c_get_clientdata(client);(quoted diff) +1
-0+ int ret;drivers/leds/leds-pca955x.c static inline u8 pca955x_ledsel(u8 oldval, int led_num, int state) · line 179
Quoted 8 lines
(quoted diff) +1
-1- i2c_smbus_write_byte_data(client, + ret = i2c_smbus_write_byte_data(client,
pca95xx_num_input_regs(pca955x->chipdef->bits)+ 4 + n, val);drivers/leds/leds-pca955x.c +4
-0+if (ret <0 ) +dev_err (&client->dev,"%s: reg 0x%x, val 0x%x, err %d\n" , + __func__, n, val, ret); +return ret;}
/*
* Read the LED selector register, which determines the source that
* drives the LED output.
*/drivers/leds/leds-pca955x.c +1
-1-static u8 pca955x_read_ls (struct i2c_client *client,int n) +static int pca955x_read_ls (struct i2c_client *client,int n,u8 *val){
Review
Quoted 2 lines
struct pca955x *pca955x =
i2c_get_clientdata(client);(quoted diff) +1
-0+ int ret;drivers/leds/leds-pca955x.c static void pca955x_write_psc(struct i2c_client *client, int n, u8 val) · line 239
Quoted 10 lines
drivers/leds/leds-pca955x.c +1
-1- return (u8) i2c_smbus_read_byte_data(client, + ret = i2c_smbus_read_byte_data(client,
pca95xx_num_input_regs(pca955x->chipdef->bits)+ 4 + n);drivers/leds/leds-pca955x.c +7
-0+if (ret <0 ) { +dev_err (&client->dev,"%s: reg 0x%x, err %d\n" , + __func__, n, ret); +return ret; + } + *val = (u8 ) ret; +return 0 ;}
static int pca955x_led_set(structled_classdev*led_cdev,drivers/leds/leds-pca955x.c +0
-0@@ -223,6 +247,7 @@ static int pca955x_led_set(struct led_classdev *led_cdev, > u8 ls;Review
Quoted 3 lines
Quoted 2 lines
int
chip_ls; /* which LSx to use (0-3 potentially) */
intls_led; /* which set of bits within LSx to use (0-3) */(quoted diff) +1
-0+ int ret;Quoted 2 lines
pca955x_led=container_of(led_cdev, struct pca955x_led, led_cdev); pca955x =pca955x_led->pca955x;drivers/leds/leds-pca955x.c +0
-0@@ -232,7 +257,9 @@ static int pca955x_led_set(struct led_classdev *led_cdev,Quoted 1 line
mutex_lock(&pca955x->lock);drivers/leds/leds-pca955x.c static int pca955x_led_set(struct led_classdev *led_cdev, · line 262
Quoted 4 lines
drivers/leds/leds-pca955x.c +3
-1- ls =pca955x_read_ls (pca955x->client, chip_ls); + ret =pca955x_read_ls (pca955x->client, chip_ls, &ls); +if (ret) + goto out;Quoted 2 lines
switch (value) {
caseLED_FULL:drivers/leds/leds-pca955x.c +0
-0@@ -252,26 +279,37 @@ static int pca955x_led_set(struct led_classdev *led_cdev,Quoted 11 lines
* OFF, HALF, or FULL. But, this is probably better than
* just turning off for all other values.
*/drivers/leds/leds-pca955x.c +3
-2-pca955x_write_pwm (pca955x->client,1 , -255 - value); + ret =pca955x_write_pwm (pca955x->client,1 ,255 - value); +if (ret) + goto out;ls =
pca955x_ledsel(ls, ls_led, PCA955X_LS_BLINK1); break;
}drivers/leds/leds-pca955x.c static int pca955x_led_set(struct led_classdev *led_cdev, · line 289
Quoted 2 lines
drivers/leds/leds-pca955x.c +1
-1-pca955x_write_ls (pca955x->client, chip_ls, ls); + ret =pca955x_write_ls (pca955x->client, chip_ls, ls);
+out:Quoted 1 line
mutex_unlock(&pca955x->lock);Review
Quoted 2 lines
(quoted diff) +1
-1- return 0; + return ret;}
#ifdefCONFIG_LEDS_PCA955X_GPIO
/*
* Read the INPUT register, which contains the state of LEDs. */drivers/leds/leds-pca955x.c +1
-1-static u8 pca955x_read_input (struct i2c_client *client,int n) +static int pca955x_read_input (struct i2c_client *client,int n,u8 *val){
drivers/leds/leds-pca955x.c static int pca955x_led_set(struct led_classdev *led_cdev, · line 303
Quoted 2 lines
drivers/leds/leds-pca955x.c +1
-1-return (u8 )i2c_smbus_read_byte_data (client, n); +int ret =i2c_smbus_read_byte_data (client, n);+
drivers/leds/leds-pca955x.c static void pca955x_write_psc(struct i2c_client *client, int n, u8 val) · line 239
Quoted 7 lines
drivers/leds/leds-pca955x.c +7
-0+if (ret <0 ) { +dev_err (&client->dev,"%s: reg 0x%x, err %d\n" , + __func__, n, ret); +return ret; + } + *val = (u8 ) ret; +return 0 ;+
}
static intpca955x_gpio_request_pin(struct gpio_chip *gc, unsigned int offset)drivers/leds/leds-pca955x.c +0
-0@@ -301,7 +339,10 @@ static int pca955x_gpio_get_value(struct gpio_chip *gc, unsigned int offset)
I don't see a corresponding change to pca955x_gpio_set_value(), though given it's hooked up as the gpiochip set() callback we would have to reimplement that interface. We should do that and return the error code rather than swallow it. This flows on to pca955x_gpio_direction_input() and pca955x_gpio_direction_output() where we currently just blindly return 0.
I think that's it though, looks good otherwise.
Andrew
Quoted 46 lines
drivers/leds/leds-pca955x.c +1
-0{ > 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); > + u8 reg = 0; +drivers/leds/leds-pca955x.c static int pca955x_gpio_get_value(struct gpio_chip *gc, unsigned int offset) · line 345
Quoted 2 lines
drivers/leds/leds-pca955x.c +2
-0+/* There is nothing we can do about errors */ +pca955x_read_input (pca955x->client, led->led_num /8 , ®);Quoted 1 line
return !!(reg & (1 << (
led->led_num% 8)));}
drivers/leds/leds-pca955x.c +0
-0@@ -491,19 +532,29 @@ static int pca955x_probe(struct i2c_client *client, > return err;Quoted 7 lines
/* Turn off LED */
drivers/leds/leds-pca955x.c +3
-1-pca955x_led_set (&pca955x_led->led_cdev,LED_OFF ); + err =pca955x_led_set (&pca955x_led->led_cdev,LED_OFF ); +if (err) +return err;}
}drivers/leds/leds-pca955x.c static int pca955x_probe(struct i2c_client *client, · line 544
Quoted 5 lines
/* PWM0 is used for half brightness or 50% duty cycle */
drivers/leds/leds-pca955x.c +3
-1-pca955x_write_pwm (client,0 ,255 -LED_HALF ); + err =pca955x_write_pwm (client,0 ,255 -LED_HALF ); +if (err) +return err;drivers/leds/leds-pca955x.c static int pca955x_probe(struct i2c_client *client, · line 549
Quoted 5 lines
/* PWM1 is used for variable brightness, default to OFF */
drivers/leds/leds-pca955x.c +3
-1-pca955x_write_pwm (client,1 ,0 ); + err =pca955x_write_pwm (client,1 ,0 ); +if (err) +return err;drivers/leds/leds-pca955x.c static int pca955x_probe(struct i2c_client *client, · line 557
Quoted 9 lines
/* Set to fast frequency so we do not see flashing */
drivers/leds/leds-pca955x.c +6
-2-pca955x_write_psc (client,0 ,0 ); -pca955x_write_psc (client,1 ,0 ); + err =pca955x_write_psc (client,0 ,0 ); +if (err) +return err; + err =pca955x_write_psc (client,1 ,0 ); +if (err) +return err;
#ifdefCONFIG_LEDS_PCA955X_GPIOQuoted 1 line
if (ngpios) {
Re: [PATCH linux dev-4.10 2/2] leds: pca955x: check for I2C errors
Hello,
Quoted 5 lines
I don't see a corresponding change to
pca955x_gpio_set_value(), though given it's hooked up as the gpiochipset()callback we would have to reimplement that interface. We should do that and return the error code rather than swallow it. This flows on topca955x_gpio_direction_input()andpca955x_gpio_direction_output()where we currently just blindly return 0.
yes. Let's do it right. Sending a v2.
Quoted 1 line
I think that's it though, looks good otherwise
Thanks,
C.