Skip to content

Commit 78cbcfd

Browse files
elkablolag-linaro
authored andcommitted
leds: turris-omnia: Fix brightness setting and trigger activating
I have improperly refactored commits 4d5ed26 ("leds: turris-omnia: Make set_brightness() more efficient") and aaf3827 ("leds: turris-omnia: Support HW controlled mode via private trigger") after Lee requested a change in API semantics of the new functions I introduced in commit 28350bc ("leds: turris-omnia: Do not use SMBUS calls"). Before the change, the function omnia_cmd_write_u8() returned 0 on success, and afterwards it returned a positive value (number of bytes written). The latter version was applied, but the following commits did not properly account for this change. This results in non-functional LED's .brightness_set_blocking() and trigger's .activate() methods. The main reasoning behind the semantics change was that read/write methods should return the number of read/written bytes on success. It was pointed to me [1] that this is not always true (for example the regmap API does not do so), and since the driver never uses this number of read/written bytes information, I decided to fix this issue by changing the functions to the original semantics (return 0 on success). [1] https://lore.kernel.org/linux-gpio/[email protected]/ Fixes: 28350bc ("leds: turris-omnia: Do not use SMBUS calls") Signed-off-by: Marek Behún <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 50be9e0 commit 78cbcfd

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

drivers/leds/leds-turris-omnia.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ struct omnia_leds {
6060
static int omnia_cmd_write_u8(const struct i2c_client *client, u8 cmd, u8 val)
6161
{
6262
u8 buf[2] = { cmd, val };
63+
int ret;
64+
65+
ret = i2c_master_send(client, buf, sizeof(buf));
6366

64-
return i2c_master_send(client, buf, sizeof(buf));
67+
return ret < 0 ? ret : 0;
6568
}
6669

6770
static int omnia_cmd_read_raw(struct i2c_adapter *adapter, u8 addr, u8 cmd,
@@ -81,7 +84,7 @@ static int omnia_cmd_read_raw(struct i2c_adapter *adapter, u8 addr, u8 cmd,
8184

8285
ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
8386
if (likely(ret == ARRAY_SIZE(msgs)))
84-
return len;
87+
return 0;
8588
else if (ret < 0)
8689
return ret;
8790
else
@@ -91,11 +94,11 @@ static int omnia_cmd_read_raw(struct i2c_adapter *adapter, u8 addr, u8 cmd,
9194
static int omnia_cmd_read_u8(const struct i2c_client *client, u8 cmd)
9295
{
9396
u8 reply;
94-
int ret;
97+
int err;
9598

96-
ret = omnia_cmd_read_raw(client->adapter, client->addr, cmd, &reply, 1);
97-
if (ret < 0)
98-
return ret;
99+
err = omnia_cmd_read_raw(client->adapter, client->addr, cmd, &reply, 1);
100+
if (err)
101+
return err;
99102

100103
return reply;
101104
}
@@ -236,7 +239,7 @@ static void omnia_hwtrig_deactivate(struct led_classdev *cdev)
236239

237240
mutex_unlock(&leds->lock);
238241

239-
if (err < 0)
242+
if (err)
240243
dev_err(cdev->dev, "Cannot put LED to software mode: %i\n",
241244
err);
242245
}
@@ -302,7 +305,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,
302305
ret = omnia_cmd_write_u8(client, CMD_LED_MODE,
303306
CMD_LED_MODE_LED(led->reg) |
304307
CMD_LED_MODE_USER);
305-
if (ret < 0) {
308+
if (ret) {
306309
dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np,
307310
ret);
308311
return ret;
@@ -311,7 +314,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,
311314
/* disable the LED */
312315
ret = omnia_cmd_write_u8(client, CMD_LED_STATE,
313316
CMD_LED_STATE_LED(led->reg));
314-
if (ret < 0) {
317+
if (ret) {
315318
dev_err(dev, "Cannot set LED %pOF brightness: %i\n", np, ret);
316319
return ret;
317320
}
@@ -364,17 +367,17 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *a,
364367
{
365368
struct i2c_client *client = to_i2c_client(dev);
366369
unsigned long brightness;
367-
int ret;
370+
int err;
368371

369372
if (kstrtoul(buf, 10, &brightness))
370373
return -EINVAL;
371374

372375
if (brightness > 100)
373376
return -EINVAL;
374377

375-
ret = omnia_cmd_write_u8(client, CMD_LED_SET_BRIGHTNESS, brightness);
378+
err = omnia_cmd_write_u8(client, CMD_LED_SET_BRIGHTNESS, brightness);
376379

377-
return ret < 0 ? ret : count;
380+
return err ?: count;
378381
}
379382
static DEVICE_ATTR_RW(brightness);
380383

@@ -403,17 +406,17 @@ static ssize_t gamma_correction_store(struct device *dev,
403406
struct i2c_client *client = to_i2c_client(dev);
404407
struct omnia_leds *leds = i2c_get_clientdata(client);
405408
bool val;
406-
int ret;
409+
int err;
407410

408411
if (!leds->has_gamma_correction)
409412
return -EOPNOTSUPP;
410413

411414
if (kstrtobool(buf, &val) < 0)
412415
return -EINVAL;
413416

414-
ret = omnia_cmd_write_u8(client, CMD_SET_GAMMA_CORRECTION, val);
417+
err = omnia_cmd_write_u8(client, CMD_SET_GAMMA_CORRECTION, val);
415418

416-
return ret < 0 ? ret : count;
419+
return err ?: count;
417420
}
418421
static DEVICE_ATTR_RW(gamma_correction);
419422

@@ -431,7 +434,7 @@ static int omnia_mcu_get_features(const struct i2c_client *client)
431434

432435
err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR,
433436
CMD_GET_STATUS_WORD, &reply, sizeof(reply));
434-
if (err < 0)
437+
if (err)
435438
return err;
436439

437440
/* Check whether MCU firmware supports the CMD_GET_FEAUTRES command */
@@ -440,7 +443,7 @@ static int omnia_mcu_get_features(const struct i2c_client *client)
440443

441444
err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR,
442445
CMD_GET_FEATURES, &reply, sizeof(reply));
443-
if (err < 0)
446+
if (err)
444447
return err;
445448

446449
return le16_to_cpu(reply);

0 commit comments

Comments
 (0)