80257c2ea0687747f0458241892d4af173862c92
[openwrt/staging/ldir.git] / target / linux / generic / backport-5.10 / 840-v5.15-leds-pca955x-clean-up-code-formatting.patch
1 From 2420ae02ce0a926819ebe18f809a57bff3edeac2 Mon Sep 17 00:00:00 2001
2 From: Eddie James <eajames@linux.ibm.com>
3 Date: Fri, 16 Jul 2021 17:03:27 -0500
4 Subject: [PATCH] leds: pca955x: Clean up code formatting
5
6 Format the code. Add some variables to help shorten lines.
7
8 Signed-off-by: Eddie James <eajames@linux.ibm.com>
9 Signed-off-by: Pavel Machek <pavel@ucw.cz>
10 ---
11 drivers/leds/leds-pca955x.c | 63 ++++++++++++++++++-------------------
12 1 file changed, 30 insertions(+), 33 deletions(-)
13
14 --- a/drivers/leds/leds-pca955x.c
15 +++ b/drivers/leds/leds-pca955x.c
16 @@ -166,11 +166,10 @@ static inline u8 pca955x_ledsel(u8 oldva
17 static int pca955x_write_psc(struct i2c_client *client, int n, u8 val)
18 {
19 struct pca955x *pca955x = i2c_get_clientdata(client);
20 + u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + (2 * n);
21 int ret;
22
23 - ret = i2c_smbus_write_byte_data(client,
24 - pca95xx_num_input_regs(pca955x->chipdef->bits) + 2*n,
25 - val);
26 + ret = i2c_smbus_write_byte_data(client, cmd, val);
27 if (ret < 0)
28 dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
29 __func__, n, val, ret);
30 @@ -187,11 +186,10 @@ static int pca955x_write_psc(struct i2c_
31 static int pca955x_write_pwm(struct i2c_client *client, int n, u8 val)
32 {
33 struct pca955x *pca955x = i2c_get_clientdata(client);
34 + u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + (2 * n);
35 int ret;
36
37 - ret = i2c_smbus_write_byte_data(client,
38 - pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + 2*n,
39 - val);
40 + ret = i2c_smbus_write_byte_data(client, cmd, val);
41 if (ret < 0)
42 dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
43 __func__, n, val, ret);
44 @@ -205,11 +203,10 @@ static int pca955x_write_pwm(struct i2c_
45 static int pca955x_write_ls(struct i2c_client *client, int n, u8 val)
46 {
47 struct pca955x *pca955x = i2c_get_clientdata(client);
48 + u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n;
49 int ret;
50
51 - ret = i2c_smbus_write_byte_data(client,
52 - pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n,
53 - val);
54 + ret = i2c_smbus_write_byte_data(client, cmd, val);
55 if (ret < 0)
56 dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
57 __func__, n, val, ret);
58 @@ -223,10 +220,10 @@ static int pca955x_write_ls(struct i2c_c
59 static int pca955x_read_ls(struct i2c_client *client, int n, u8 *val)
60 {
61 struct pca955x *pca955x = i2c_get_clientdata(client);
62 + u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n;
63 int ret;
64
65 - ret = i2c_smbus_read_byte_data(client,
66 - pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n);
67 + ret = i2c_smbus_read_byte_data(client, cmd);
68 if (ret < 0) {
69 dev_err(&client->dev, "%s: reg 0x%x, err %d\n",
70 __func__, n, ret);
71 @@ -371,6 +368,7 @@ static struct pca955x_platform_data *
72 pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
73 {
74 struct pca955x_platform_data *pdata;
75 + struct pca955x_led *led;
76 struct fwnode_handle *child;
77 int count;
78
79 @@ -401,13 +399,13 @@ pca955x_get_pdata(struct i2c_client *cli
80 if ((res != 0) && is_of_node(child))
81 name = to_of_node(child)->name;
82
83 - snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name),
84 - "%s", name);
85 + led = &pdata->leds[reg];
86 + snprintf(led->name, sizeof(led->name), "%s", name);
87
88 - pdata->leds[reg].type = PCA955X_TYPE_LED;
89 - fwnode_property_read_u32(child, "type", &pdata->leds[reg].type);
90 + led->type = PCA955X_TYPE_LED;
91 + fwnode_property_read_u32(child, "type", &led->type);
92 fwnode_property_read_string(child, "linux,default-trigger",
93 - &pdata->leds[reg].default_trigger);
94 + &led->default_trigger);
95 }
96
97 pdata->num_leds = chip->bits;
98 @@ -426,11 +424,12 @@ static const struct of_device_id of_pca9
99 MODULE_DEVICE_TABLE(of, of_pca955x_match);
100
101 static int pca955x_probe(struct i2c_client *client,
102 - const struct i2c_device_id *id)
103 + const struct i2c_device_id *id)
104 {
105 struct pca955x *pca955x;
106 struct pca955x_led *pca955x_led;
107 struct pca955x_chipdef *chip;
108 + struct led_classdev *led;
109 struct i2c_adapter *adapter;
110 int i, err;
111 struct pca955x_platform_data *pdata;
112 @@ -449,13 +448,13 @@ static int pca955x_probe(struct i2c_clie
113 if ((client->addr & ~((1 << chip->slv_addr_shift) - 1)) !=
114 chip->slv_addr) {
115 dev_err(&client->dev, "invalid slave address %02x\n",
116 - client->addr);
117 + client->addr);
118 return -ENODEV;
119 }
120
121 dev_info(&client->dev, "leds-pca955x: Using %s %d-bit LED driver at "
122 - "slave address 0x%02x\n",
123 - client->name, chip->bits, client->addr);
124 + "slave address 0x%02x\n", client->name, chip->bits,
125 + client->addr);
126
127 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
128 return -EIO;
129 @@ -471,8 +470,8 @@ static int pca955x_probe(struct i2c_clie
130 if (!pca955x)
131 return -ENOMEM;
132
133 - pca955x->leds = devm_kcalloc(&client->dev,
134 - chip->bits, sizeof(*pca955x_led), GFP_KERNEL);
135 + pca955x->leds = devm_kcalloc(&client->dev, chip->bits,
136 + sizeof(*pca955x_led), GFP_KERNEL);
137 if (!pca955x->leds)
138 return -ENOMEM;
139
140 @@ -501,27 +500,25 @@ static int pca955x_probe(struct i2c_clie
141 */
142 if (pdata->leds[i].name[0] == '\0')
143 snprintf(pdata->leds[i].name,
144 - sizeof(pdata->leds[i].name), "%d", i);
145 + sizeof(pdata->leds[i].name), "%d", i);
146
147 - snprintf(pca955x_led->name,
148 - sizeof(pca955x_led->name), "pca955x:%s",
149 - pdata->leds[i].name);
150 + snprintf(pca955x_led->name, sizeof(pca955x_led->name),
151 + "pca955x:%s", pdata->leds[i].name);
152
153 + led = &pca955x_led->led_cdev;
154 if (pdata->leds[i].default_trigger)
155 - pca955x_led->led_cdev.default_trigger =
156 + led->default_trigger =
157 pdata->leds[i].default_trigger;
158
159 - pca955x_led->led_cdev.name = pca955x_led->name;
160 - pca955x_led->led_cdev.brightness_set_blocking =
161 - pca955x_led_set;
162 + led->name = pca955x_led->name;
163 + led->brightness_set_blocking = pca955x_led_set;
164
165 - err = devm_led_classdev_register(&client->dev,
166 - &pca955x_led->led_cdev);
167 + err = devm_led_classdev_register(&client->dev, led);
168 if (err)
169 return err;
170
171 /* Turn off LED */
172 - err = pca955x_led_set(&pca955x_led->led_cdev, LED_OFF);
173 + err = pca955x_led_set(led, LED_OFF);
174 if (err)
175 return err;
176 }