41199dd93e0aaacc63fac620a16f9f2576ab510f
[openwrt/staging/ansuel.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 diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
15 index 7087ca4592fc96..f0d841cb59fcc8 100644
16 --- a/drivers/leds/leds-pca955x.c
17 +++ b/drivers/leds/leds-pca955x.c
18 @@ -166,11 +166,10 @@ static inline u8 pca955x_ledsel(u8 oldval, int led_num, int state)
19 static int pca955x_write_psc(struct i2c_client *client, int n, u8 val)
20 {
21 struct pca955x *pca955x = i2c_get_clientdata(client);
22 + u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + (2 * n);
23 int ret;
24
25 - ret = i2c_smbus_write_byte_data(client,
26 - pca95xx_num_input_regs(pca955x->chipdef->bits) + 2*n,
27 - val);
28 + ret = i2c_smbus_write_byte_data(client, cmd, val);
29 if (ret < 0)
30 dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
31 __func__, n, val, ret);
32 @@ -187,11 +186,10 @@ static int pca955x_write_psc(struct i2c_client *client, int n, u8 val)
33 static int pca955x_write_pwm(struct i2c_client *client, int n, u8 val)
34 {
35 struct pca955x *pca955x = i2c_get_clientdata(client);
36 + u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + (2 * n);
37 int ret;
38
39 - ret = i2c_smbus_write_byte_data(client,
40 - pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + 2*n,
41 - val);
42 + ret = i2c_smbus_write_byte_data(client, cmd, val);
43 if (ret < 0)
44 dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
45 __func__, n, val, ret);
46 @@ -205,11 +203,10 @@ static int pca955x_write_pwm(struct i2c_client *client, int n, u8 val)
47 static int pca955x_write_ls(struct i2c_client *client, int n, u8 val)
48 {
49 struct pca955x *pca955x = i2c_get_clientdata(client);
50 + u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n;
51 int ret;
52
53 - ret = i2c_smbus_write_byte_data(client,
54 - pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n,
55 - val);
56 + ret = i2c_smbus_write_byte_data(client, cmd, val);
57 if (ret < 0)
58 dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
59 __func__, n, val, ret);
60 @@ -223,10 +220,10 @@ static int pca955x_write_ls(struct i2c_client *client, int n, u8 val)
61 static int pca955x_read_ls(struct i2c_client *client, int n, u8 *val)
62 {
63 struct pca955x *pca955x = i2c_get_clientdata(client);
64 + u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n;
65 int ret;
66
67 - ret = i2c_smbus_read_byte_data(client,
68 - pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n);
69 + ret = i2c_smbus_read_byte_data(client, cmd);
70 if (ret < 0) {
71 dev_err(&client->dev, "%s: reg 0x%x, err %d\n",
72 __func__, n, ret);
73 @@ -371,6 +368,7 @@ static struct pca955x_platform_data *
74 pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
75 {
76 struct pca955x_platform_data *pdata;
77 + struct pca955x_led *led;
78 struct fwnode_handle *child;
79 int count;
80
81 @@ -401,13 +399,13 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
82 if ((res != 0) && is_of_node(child))
83 name = to_of_node(child)->name;
84
85 - snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name),
86 - "%s", name);
87 + led = &pdata->leds[reg];
88 + snprintf(led->name, sizeof(led->name), "%s", name);
89
90 - pdata->leds[reg].type = PCA955X_TYPE_LED;
91 - fwnode_property_read_u32(child, "type", &pdata->leds[reg].type);
92 + led->type = PCA955X_TYPE_LED;
93 + fwnode_property_read_u32(child, "type", &led->type);
94 fwnode_property_read_string(child, "linux,default-trigger",
95 - &pdata->leds[reg].default_trigger);
96 + &led->default_trigger);
97 }
98
99 pdata->num_leds = chip->bits;
100 @@ -426,11 +424,12 @@ static const struct of_device_id of_pca955x_match[] = {
101 MODULE_DEVICE_TABLE(of, of_pca955x_match);
102
103 static int pca955x_probe(struct i2c_client *client,
104 - const struct i2c_device_id *id)
105 + const struct i2c_device_id *id)
106 {
107 struct pca955x *pca955x;
108 struct pca955x_led *pca955x_led;
109 struct pca955x_chipdef *chip;
110 + struct led_classdev *led;
111 struct i2c_adapter *adapter;
112 int i, err;
113 struct pca955x_platform_data *pdata;
114 @@ -449,13 +448,13 @@ static int pca955x_probe(struct i2c_client *client,
115 if ((client->addr & ~((1 << chip->slv_addr_shift) - 1)) !=
116 chip->slv_addr) {
117 dev_err(&client->dev, "invalid slave address %02x\n",
118 - client->addr);
119 + client->addr);
120 return -ENODEV;
121 }
122
123 dev_info(&client->dev, "leds-pca955x: Using %s %d-bit LED driver at "
124 - "slave address 0x%02x\n",
125 - client->name, chip->bits, client->addr);
126 + "slave address 0x%02x\n", client->name, chip->bits,
127 + client->addr);
128
129 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
130 return -EIO;
131 @@ -471,8 +470,8 @@ static int pca955x_probe(struct i2c_client *client,
132 if (!pca955x)
133 return -ENOMEM;
134
135 - pca955x->leds = devm_kcalloc(&client->dev,
136 - chip->bits, sizeof(*pca955x_led), GFP_KERNEL);
137 + pca955x->leds = devm_kcalloc(&client->dev, chip->bits,
138 + sizeof(*pca955x_led), GFP_KERNEL);
139 if (!pca955x->leds)
140 return -ENOMEM;
141
142 @@ -501,27 +500,25 @@ static int pca955x_probe(struct i2c_client *client,
143 */
144 if (pdata->leds[i].name[0] == '\0')
145 snprintf(pdata->leds[i].name,
146 - sizeof(pdata->leds[i].name), "%d", i);
147 + sizeof(pdata->leds[i].name), "%d", i);
148
149 - snprintf(pca955x_led->name,
150 - sizeof(pca955x_led->name), "pca955x:%s",
151 - pdata->leds[i].name);
152 + snprintf(pca955x_led->name, sizeof(pca955x_led->name),
153 + "pca955x:%s", pdata->leds[i].name);
154
155 + led = &pca955x_led->led_cdev;
156 if (pdata->leds[i].default_trigger)
157 - pca955x_led->led_cdev.default_trigger =
158 + led->default_trigger =
159 pdata->leds[i].default_trigger;
160
161 - pca955x_led->led_cdev.name = pca955x_led->name;
162 - pca955x_led->led_cdev.brightness_set_blocking =
163 - pca955x_led_set;
164 + led->name = pca955x_led->name;
165 + led->brightness_set_blocking = pca955x_led_set;
166
167 - err = devm_led_classdev_register(&client->dev,
168 - &pca955x_led->led_cdev);
169 + err = devm_led_classdev_register(&client->dev, led);
170 if (err)
171 return err;
172
173 /* Turn off LED */
174 - err = pca955x_led_set(&pca955x_led->led_cdev, LED_OFF);
175 + err = pca955x_led_set(led, LED_OFF);
176 if (err)
177 return err;
178 }