Skip to content

Commit 2420ae0

Browse files
Eddie Jamespavelmachek
authored andcommitted
leds: pca955x: Clean up code formatting
Format the code. Add some variables to help shorten lines. Signed-off-by: Eddie James <[email protected]> Signed-off-by: Pavel Machek <[email protected]>
1 parent 4190663 commit 2420ae0

File tree

1 file changed

+30
-33
lines changed

1 file changed

+30
-33
lines changed

drivers/leds/leds-pca955x.c

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,10 @@ static inline u8 pca955x_ledsel(u8 oldval, int led_num, int state)
166166
static int pca955x_write_psc(struct i2c_client *client, int n, u8 val)
167167
{
168168
struct pca955x *pca955x = i2c_get_clientdata(client);
169+
u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + (2 * n);
169170
int ret;
170171

171-
ret = i2c_smbus_write_byte_data(client,
172-
pca95xx_num_input_regs(pca955x->chipdef->bits) + 2*n,
173-
val);
172+
ret = i2c_smbus_write_byte_data(client, cmd, val);
174173
if (ret < 0)
175174
dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
176175
__func__, n, val, ret);
@@ -187,11 +186,10 @@ static int pca955x_write_psc(struct i2c_client *client, int n, u8 val)
187186
static int pca955x_write_pwm(struct i2c_client *client, int n, u8 val)
188187
{
189188
struct pca955x *pca955x = i2c_get_clientdata(client);
189+
u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + (2 * n);
190190
int ret;
191191

192-
ret = i2c_smbus_write_byte_data(client,
193-
pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + 2*n,
194-
val);
192+
ret = i2c_smbus_write_byte_data(client, cmd, val);
195193
if (ret < 0)
196194
dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
197195
__func__, n, val, ret);
@@ -205,11 +203,10 @@ static int pca955x_write_pwm(struct i2c_client *client, int n, u8 val)
205203
static int pca955x_write_ls(struct i2c_client *client, int n, u8 val)
206204
{
207205
struct pca955x *pca955x = i2c_get_clientdata(client);
206+
u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n;
208207
int ret;
209208

210-
ret = i2c_smbus_write_byte_data(client,
211-
pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n,
212-
val);
209+
ret = i2c_smbus_write_byte_data(client, cmd, val);
213210
if (ret < 0)
214211
dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
215212
__func__, n, val, ret);
@@ -223,10 +220,10 @@ static int pca955x_write_ls(struct i2c_client *client, int n, u8 val)
223220
static int pca955x_read_ls(struct i2c_client *client, int n, u8 *val)
224221
{
225222
struct pca955x *pca955x = i2c_get_clientdata(client);
223+
u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n;
226224
int ret;
227225

228-
ret = i2c_smbus_read_byte_data(client,
229-
pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n);
226+
ret = i2c_smbus_read_byte_data(client, cmd);
230227
if (ret < 0) {
231228
dev_err(&client->dev, "%s: reg 0x%x, err %d\n",
232229
__func__, n, ret);
@@ -371,6 +368,7 @@ static struct pca955x_platform_data *
371368
pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
372369
{
373370
struct pca955x_platform_data *pdata;
371+
struct pca955x_led *led;
374372
struct fwnode_handle *child;
375373
int count;
376374

@@ -401,13 +399,13 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
401399
if ((res != 0) && is_of_node(child))
402400
name = to_of_node(child)->name;
403401

404-
snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name),
405-
"%s", name);
402+
led = &pdata->leds[reg];
403+
snprintf(led->name, sizeof(led->name), "%s", name);
406404

407-
pdata->leds[reg].type = PCA955X_TYPE_LED;
408-
fwnode_property_read_u32(child, "type", &pdata->leds[reg].type);
405+
led->type = PCA955X_TYPE_LED;
406+
fwnode_property_read_u32(child, "type", &led->type);
409407
fwnode_property_read_string(child, "linux,default-trigger",
410-
&pdata->leds[reg].default_trigger);
408+
&led->default_trigger);
411409
}
412410

413411
pdata->num_leds = chip->bits;
@@ -426,11 +424,12 @@ static const struct of_device_id of_pca955x_match[] = {
426424
MODULE_DEVICE_TABLE(of, of_pca955x_match);
427425

428426
static int pca955x_probe(struct i2c_client *client,
429-
const struct i2c_device_id *id)
427+
const struct i2c_device_id *id)
430428
{
431429
struct pca955x *pca955x;
432430
struct pca955x_led *pca955x_led;
433431
struct pca955x_chipdef *chip;
432+
struct led_classdev *led;
434433
struct i2c_adapter *adapter;
435434
int i, err;
436435
struct pca955x_platform_data *pdata;
@@ -449,13 +448,13 @@ static int pca955x_probe(struct i2c_client *client,
449448
if ((client->addr & ~((1 << chip->slv_addr_shift) - 1)) !=
450449
chip->slv_addr) {
451450
dev_err(&client->dev, "invalid slave address %02x\n",
452-
client->addr);
451+
client->addr);
453452
return -ENODEV;
454453
}
455454

456455
dev_info(&client->dev, "leds-pca955x: Using %s %d-bit LED driver at "
457-
"slave address 0x%02x\n",
458-
client->name, chip->bits, client->addr);
456+
"slave address 0x%02x\n", client->name, chip->bits,
457+
client->addr);
459458

460459
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
461460
return -EIO;
@@ -471,8 +470,8 @@ static int pca955x_probe(struct i2c_client *client,
471470
if (!pca955x)
472471
return -ENOMEM;
473472

474-
pca955x->leds = devm_kcalloc(&client->dev,
475-
chip->bits, sizeof(*pca955x_led), GFP_KERNEL);
473+
pca955x->leds = devm_kcalloc(&client->dev, chip->bits,
474+
sizeof(*pca955x_led), GFP_KERNEL);
476475
if (!pca955x->leds)
477476
return -ENOMEM;
478477

@@ -501,27 +500,25 @@ static int pca955x_probe(struct i2c_client *client,
501500
*/
502501
if (pdata->leds[i].name[0] == '\0')
503502
snprintf(pdata->leds[i].name,
504-
sizeof(pdata->leds[i].name), "%d", i);
503+
sizeof(pdata->leds[i].name), "%d", i);
505504

506-
snprintf(pca955x_led->name,
507-
sizeof(pca955x_led->name), "pca955x:%s",
508-
pdata->leds[i].name);
505+
snprintf(pca955x_led->name, sizeof(pca955x_led->name),
506+
"pca955x:%s", pdata->leds[i].name);
509507

508+
led = &pca955x_led->led_cdev;
510509
if (pdata->leds[i].default_trigger)
511-
pca955x_led->led_cdev.default_trigger =
510+
led->default_trigger =
512511
pdata->leds[i].default_trigger;
513512

514-
pca955x_led->led_cdev.name = pca955x_led->name;
515-
pca955x_led->led_cdev.brightness_set_blocking =
516-
pca955x_led_set;
513+
led->name = pca955x_led->name;
514+
led->brightness_set_blocking = pca955x_led_set;
517515

518-
err = devm_led_classdev_register(&client->dev,
519-
&pca955x_led->led_cdev);
516+
err = devm_led_classdev_register(&client->dev, led);
520517
if (err)
521518
return err;
522519

523520
/* Turn off LED */
524-
err = pca955x_led_set(&pca955x_led->led_cdev, LED_OFF);
521+
err = pca955x_led_set(led, LED_OFF);
525522
if (err)
526523
return err;
527524
}

0 commit comments

Comments
 (0)