* [PATCH v1 2/7] leds: lp50xx: Switch to new style i2c-driver probe function
2021-02-16 15:50 [PATCH v1 1/7] leds: lp50xx: Don't spam logs when probe is deferred Andy Shevchenko
@ 2021-02-16 15:50 ` Andy Shevchenko
2021-02-16 15:50 ` [PATCH v1 3/7] leds: lp50xx: Reduce level of dereferences Andy Shevchenko
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2021-02-16 15:50 UTC (permalink / raw)
To: Andy Shevchenko, Dan Murphy, linux-leds, linux-kernel; +Cc: Pavel Machek
Switch to the new style i2c-driver probe_new probe function.
Note we do not have any old style board files using this but
user still has a possibility to instantiate device from sysfs.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/leds/leds-lp50xx.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index a2d18ec8fd2b..19aec80e527a 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -526,8 +526,7 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
return ret;
}
-static int lp50xx_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
+static int lp50xx_probe(struct i2c_client *client)
{
struct lp50xx *led;
int count;
@@ -547,7 +546,7 @@ static int lp50xx_probe(struct i2c_client *client,
mutex_init(&led->lock);
led->client = client;
led->dev = &client->dev;
- led->chip_info = &lp50xx_chip_info_tbl[id->driver_data];
+ led->chip_info = device_get_match_data(&client->dev);
i2c_set_clientdata(client, led);
led->regmap = devm_regmap_init_i2c(client,
led->chip_info->lp50xx_regmap_config);
@@ -593,24 +592,24 @@ static int lp50xx_remove(struct i2c_client *client)
}
static const struct i2c_device_id lp50xx_id[] = {
- { "lp5009", LP5009 },
- { "lp5012", LP5012 },
- { "lp5018", LP5018 },
- { "lp5024", LP5024 },
- { "lp5030", LP5030 },
- { "lp5036", LP5036 },
+ { "lp5009", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5009] },
+ { "lp5012", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5012] },
+ { "lp5018", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5018] },
+ { "lp5024", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5024] },
+ { "lp5030", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5030] },
+ { "lp5036", (kernel_ulong_t)&lp50xx_chip_info_tbl[LP5036] },
{ }
};
MODULE_DEVICE_TABLE(i2c, lp50xx_id);
static const struct of_device_id of_lp50xx_leds_match[] = {
- { .compatible = "ti,lp5009", .data = (void *)LP5009 },
- { .compatible = "ti,lp5012", .data = (void *)LP5012 },
- { .compatible = "ti,lp5018", .data = (void *)LP5018 },
- { .compatible = "ti,lp5024", .data = (void *)LP5024 },
- { .compatible = "ti,lp5030", .data = (void *)LP5030 },
- { .compatible = "ti,lp5036", .data = (void *)LP5036 },
- {},
+ { .compatible = "ti,lp5009", .data = &lp50xx_chip_info_tbl[LP5009] },
+ { .compatible = "ti,lp5012", .data = &lp50xx_chip_info_tbl[LP5012] },
+ { .compatible = "ti,lp5018", .data = &lp50xx_chip_info_tbl[LP5018] },
+ { .compatible = "ti,lp5024", .data = &lp50xx_chip_info_tbl[LP5024] },
+ { .compatible = "ti,lp5030", .data = &lp50xx_chip_info_tbl[LP5030] },
+ { .compatible = "ti,lp5036", .data = &lp50xx_chip_info_tbl[LP5036] },
+ {}
};
MODULE_DEVICE_TABLE(of, of_lp50xx_leds_match);
@@ -619,7 +618,7 @@ static struct i2c_driver lp50xx_driver = {
.name = "lp50xx",
.of_match_table = of_lp50xx_leds_match,
},
- .probe = lp50xx_probe,
+ .probe_new = lp50xx_probe,
.remove = lp50xx_remove,
.id_table = lp50xx_id,
};
--
2.30.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 3/7] leds: lp50xx: Reduce level of dereferences
2021-02-16 15:50 [PATCH v1 1/7] leds: lp50xx: Don't spam logs when probe is deferred Andy Shevchenko
2021-02-16 15:50 ` [PATCH v1 2/7] leds: lp50xx: Switch to new style i2c-driver probe function Andy Shevchenko
@ 2021-02-16 15:50 ` Andy Shevchenko
2021-02-16 15:50 ` [PATCH v1 4/7] leds: lp50xx: Get rid of redundant explicit casting Andy Shevchenko
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2021-02-16 15:50 UTC (permalink / raw)
To: Andy Shevchenko, Dan Murphy, linux-leds, linux-kernel; +Cc: Pavel Machek
The priv->dev is effectively the same as &priv->client->dev.
So, drop the latter for the former.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/leds/leds-lp50xx.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 19aec80e527a..0723b2688552 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -322,7 +322,7 @@ static int lp50xx_brightness_set(struct led_classdev *cdev,
ret = regmap_write(led->priv->regmap, reg_val, brightness);
if (ret) {
- dev_err(&led->priv->client->dev,
+ dev_err(led->priv->dev,
"Cannot write brightness value %d\n", ret);
goto out;
}
@@ -338,7 +338,7 @@ static int lp50xx_brightness_set(struct led_classdev *cdev,
ret = regmap_write(led->priv->regmap, reg_val,
mc_dev->subled_info[i].intensity);
if (ret) {
- dev_err(&led->priv->client->dev,
+ dev_err(led->priv->dev,
"Cannot write intensity value %d\n", ret);
goto out;
}
@@ -404,7 +404,7 @@ static int lp50xx_probe_leds(struct fwnode_handle *child, struct lp50xx *priv,
if (num_leds > 1) {
if (num_leds > priv->chip_info->max_modules) {
- dev_err(&priv->client->dev, "reg property is invalid\n");
+ dev_err(priv->dev, "reg property is invalid\n");
return -EINVAL;
}
@@ -412,13 +412,13 @@ static int lp50xx_probe_leds(struct fwnode_handle *child, struct lp50xx *priv,
ret = fwnode_property_read_u32_array(child, "reg", led_banks, num_leds);
if (ret) {
- dev_err(&priv->client->dev, "reg property is missing\n");
+ dev_err(priv->dev, "reg property is missing\n");
return ret;
}
ret = lp50xx_set_banks(priv, led_banks);
if (ret) {
- dev_err(&priv->client->dev, "Cannot setup banked LEDs\n");
+ dev_err(priv->dev, "Cannot setup banked LEDs\n");
return ret;
}
@@ -426,12 +426,12 @@ static int lp50xx_probe_leds(struct fwnode_handle *child, struct lp50xx *priv,
} else {
ret = fwnode_property_read_u32(child, "reg", &led_number);
if (ret) {
- dev_err(&priv->client->dev, "led reg property missing\n");
+ dev_err(priv->dev, "led reg property missing\n");
return ret;
}
if (led_number > priv->chip_info->num_leds) {
- dev_err(&priv->client->dev, "led-sources property is invalid\n");
+ dev_err(priv->dev, "led-sources property is invalid\n");
return -EINVAL;
}
@@ -467,7 +467,7 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
led = &priv->leds[i];
ret = fwnode_property_count_u32(child, "reg");
if (ret < 0) {
- dev_err(&priv->client->dev, "reg property is invalid\n");
+ dev_err(priv->dev, "reg property is invalid\n");
goto child_out;
}
@@ -507,12 +507,11 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
led_cdev = &led->mc_cdev.led_cdev;
led_cdev->brightness_set_blocking = lp50xx_brightness_set;
- ret = devm_led_classdev_multicolor_register_ext(&priv->client->dev,
+ ret = devm_led_classdev_multicolor_register_ext(priv->dev,
&led->mc_cdev,
&init_data);
if (ret) {
- dev_err(&priv->client->dev, "led register err: %d\n",
- ret);
+ dev_err(priv->dev, "led register err: %d\n", ret);
goto child_out;
}
i++;
@@ -575,15 +574,14 @@ static int lp50xx_remove(struct i2c_client *client)
ret = lp50xx_enable_disable(led, 0);
if (ret) {
- dev_err(&led->client->dev, "Failed to disable chip\n");
+ dev_err(led->dev, "Failed to disable chip\n");
return ret;
}
if (led->regulator) {
ret = regulator_disable(led->regulator);
if (ret)
- dev_err(&led->client->dev,
- "Failed to disable regulator\n");
+ dev_err(led->dev, "Failed to disable regulator\n");
}
mutex_destroy(&led->lock);
--
2.30.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 4/7] leds: lp50xx: Get rid of redundant explicit casting
2021-02-16 15:50 [PATCH v1 1/7] leds: lp50xx: Don't spam logs when probe is deferred Andy Shevchenko
2021-02-16 15:50 ` [PATCH v1 2/7] leds: lp50xx: Switch to new style i2c-driver probe function Andy Shevchenko
2021-02-16 15:50 ` [PATCH v1 3/7] leds: lp50xx: Reduce level of dereferences Andy Shevchenko
@ 2021-02-16 15:50 ` Andy Shevchenko
2021-02-16 15:50 ` [PATCH v1 5/7] leds: lp50xx: Get rid of redundant check in lp50xx_enable_disable() Andy Shevchenko
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2021-02-16 15:50 UTC (permalink / raw)
To: Andy Shevchenko, Dan Murphy, linux-leds, linux-kernel; +Cc: Pavel Machek
In the line like
u32 bar = ...;
u8 foo = (u8)(bar >> 8) & 0xff;
is no need to have neither explicit casting nor ' & 0xff' part.
Get rid of them.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/leds/leds-lp50xx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 0723b2688552..58cd25fe565d 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -360,8 +360,8 @@ static int lp50xx_set_banks(struct lp50xx *priv, u32 led_banks[])
bank_enable_mask |= (1 << led_banks[i]);
}
- led_config_lo = (u8)(bank_enable_mask & 0xff);
- led_config_hi = (u8)(bank_enable_mask >> 8) & 0xff;
+ led_config_lo = bank_enable_mask;
+ led_config_hi = bank_enable_mask >> 8;
ret = regmap_write(priv->regmap, LP50XX_LED_CFG0, led_config_lo);
if (ret)
--
2.30.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 5/7] leds: lp50xx: Get rid of redundant check in lp50xx_enable_disable()
2021-02-16 15:50 [PATCH v1 1/7] leds: lp50xx: Don't spam logs when probe is deferred Andy Shevchenko
` (2 preceding siblings ...)
2021-02-16 15:50 ` [PATCH v1 4/7] leds: lp50xx: Get rid of redundant explicit casting Andy Shevchenko
@ 2021-02-16 15:50 ` Andy Shevchenko
2021-02-16 15:50 ` [PATCH v1 6/7] leds: lp50xx: Add missed bits.h and convert to BIT() Andy Shevchenko
2021-02-16 15:50 ` [PATCH v1 7/7] leds: lp50xx: Update headers block to reflect reality Andy Shevchenko
5 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2021-02-16 15:50 UTC (permalink / raw)
To: Andy Shevchenko, Dan Murphy, linux-leds, linux-kernel; +Cc: Pavel Machek
Since GPIO is optional the API is NULL aware and will check descriptor anyway.
Remove duplicate redundant check in lp50xx_enable_disable().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/leds/leds-lp50xx.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 58cd25fe565d..2b4981b5778d 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -382,11 +382,9 @@ static int lp50xx_enable_disable(struct lp50xx *priv, int enable_disable)
{
int ret;
- if (priv->enable_gpio) {
- ret = gpiod_direction_output(priv->enable_gpio, enable_disable);
- if (ret)
- return ret;
- }
+ ret = gpiod_direction_output(priv->enable_gpio, enable_disable);
+ if (ret)
+ return ret;
if (enable_disable)
return regmap_write(priv->regmap, LP50XX_DEV_CFG0, LP50XX_CHIP_EN);
--
2.30.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 6/7] leds: lp50xx: Add missed bits.h and convert to BIT()
2021-02-16 15:50 [PATCH v1 1/7] leds: lp50xx: Don't spam logs when probe is deferred Andy Shevchenko
` (3 preceding siblings ...)
2021-02-16 15:50 ` [PATCH v1 5/7] leds: lp50xx: Get rid of redundant check in lp50xx_enable_disable() Andy Shevchenko
@ 2021-02-16 15:50 ` Andy Shevchenko
2021-02-19 11:27 ` Pavel Machek
2021-02-16 15:50 ` [PATCH v1 7/7] leds: lp50xx: Update headers block to reflect reality Andy Shevchenko
5 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2021-02-16 15:50 UTC (permalink / raw)
To: Andy Shevchenko, Dan Murphy, linux-leds, linux-kernel; +Cc: Pavel Machek
Add missed bits.h and convert to BIT() in lp50xx_set_banks().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/leds/leds-lp50xx.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 2b4981b5778d..0c6a5a9dd162 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -2,6 +2,7 @@
// TI LP50XX LED chip family driver
// Copyright (C) 2018-20 Texas Instruments Incorporated - https://www.ti.com/
+#include <linux/bits.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/init.h>
@@ -357,7 +358,7 @@ static int lp50xx_set_banks(struct lp50xx *priv, u32 led_banks[])
for (i = 0; i < priv->chip_info->max_modules; i++) {
if (led_banks[i])
- bank_enable_mask |= (1 << led_banks[i]);
+ bank_enable_mask |= BIT(led_banks[i]);
}
led_config_lo = bank_enable_mask;
--
2.30.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v1 6/7] leds: lp50xx: Add missed bits.h and convert to BIT()
2021-02-16 15:50 ` [PATCH v1 6/7] leds: lp50xx: Add missed bits.h and convert to BIT() Andy Shevchenko
@ 2021-02-19 11:27 ` Pavel Machek
2021-02-19 13:42 ` Andy Shevchenko
0 siblings, 1 reply; 9+ messages in thread
From: Pavel Machek @ 2021-02-19 11:27 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Dan Murphy, linux-leds, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 312 bytes --]
Hi!
> Add missed bits.h and convert to BIT() in lp50xx_set_banks().
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Thanks, I applied whole series except this one...
<< is well known C, it can stay.
Best regards,
Pavel
--
http://www.livejournal.com/~pavelmachek
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 6/7] leds: lp50xx: Add missed bits.h and convert to BIT()
2021-02-19 11:27 ` Pavel Machek
@ 2021-02-19 13:42 ` Andy Shevchenko
0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2021-02-19 13:42 UTC (permalink / raw)
To: Pavel Machek; +Cc: Dan Murphy, linux-leds, linux-kernel
On Fri, Feb 19, 2021 at 12:27:55PM +0100, Pavel Machek wrote:
> Hi!
>
> > Add missed bits.h and convert to BIT() in lp50xx_set_banks().
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Thanks,
Thanks!
> I applied whole series except this one...
>
> << is well known C, it can stay.
Shall we drop BIT() in the other place?
Otherwise it is inconsistency.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v1 7/7] leds: lp50xx: Update headers block to reflect reality
2021-02-16 15:50 [PATCH v1 1/7] leds: lp50xx: Don't spam logs when probe is deferred Andy Shevchenko
` (4 preceding siblings ...)
2021-02-16 15:50 ` [PATCH v1 6/7] leds: lp50xx: Add missed bits.h and convert to BIT() Andy Shevchenko
@ 2021-02-16 15:50 ` Andy Shevchenko
5 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2021-02-16 15:50 UTC (permalink / raw)
To: Andy Shevchenko, Dan Murphy, linux-leds, linux-kernel; +Cc: Pavel Machek
The OF is not used in the driver, thus the OF headers are not needed,
but mod_devicetable.h is missed.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/leds/leds-lp50xx.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 0c6a5a9dd162..43c9ac1d4b1c 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -7,10 +7,9 @@
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/leds.h>
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/mutex.h>
-#include <linux/of.h>
-#include <linux/of_gpio.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
--
2.30.0
^ permalink raw reply related [flat|nested] 9+ messages in thread