Linux LED subsystem development
 help / color / mirror / Atom feed
* [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms
@ 2023-12-14 18:40 Andy Shevchenko
  2023-12-14 18:40 ` [PATCH v1 1/4] leds: max5970: Remove unused variable Andy Shevchenko
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Andy Shevchenko @ 2023-12-14 18:40 UTC (permalink / raw)
  To: Andy Shevchenko, Patrick Rudolph, linux-leds, linux-kernel
  Cc: Pavel Machek, Lee Jones

Allow to use driver on non-OF platforms and other cleanups.

Andy Shevchenko (4):
  leds: max5970: Remove unused variable
  leds: max5970: Make use of device properties
  leds: max5970: Make use of dev_err_probe()
  leds: max5970: Add missing headers

 drivers/leds/leds-max5970.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

-- 
2.43.0.rc1.1.gbec44491f096


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v1 1/4] leds: max5970: Remove unused variable
  2023-12-14 18:40 [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms Andy Shevchenko
@ 2023-12-14 18:40 ` Andy Shevchenko
  2023-12-14 18:40 ` [PATCH v1 2/4] leds: max5970: Make use of device properties Andy Shevchenko
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2023-12-14 18:40 UTC (permalink / raw)
  To: Andy Shevchenko, Patrick Rudolph, linux-leds, linux-kernel
  Cc: Pavel Machek, Lee Jones

leds-max5970.c:50:21: warning: variable 'num_leds' set but not used [-Wunused-but-set-variable]

Remove unused variable.

Fixes: 736214b4b02a ("leds: max5970: Add support for max5970")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-max5970.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/leds/leds-max5970.c b/drivers/leds/leds-max5970.c
index 456a16a47450..7959d079ae94 100644
--- a/drivers/leds/leds-max5970.c
+++ b/drivers/leds/leds-max5970.c
@@ -45,7 +45,7 @@ static int max5970_led_probe(struct platform_device *pdev)
 	struct regmap *regmap;
 	struct device_node *led_node, *child;
 	struct max5970_led *ddata;
-	int ret = -ENODEV, num_leds = 0;
+	int ret = -ENODEV;
 
 	regmap = dev_get_regmap(pdev->dev.parent, NULL);
 	if (!regmap)
@@ -89,7 +89,6 @@ static int max5970_led_probe(struct platform_device *pdev)
 			dev_err(dev, "Failed to initialize LED %u\n", reg);
 			return ret;
 		}
-		num_leds++;
 	}
 
 	return ret;
-- 
2.43.0.rc1.1.gbec44491f096


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 2/4] leds: max5970: Make use of device properties
  2023-12-14 18:40 [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms Andy Shevchenko
  2023-12-14 18:40 ` [PATCH v1 1/4] leds: max5970: Remove unused variable Andy Shevchenko
@ 2023-12-14 18:40 ` Andy Shevchenko
  2023-12-14 18:40 ` [PATCH v1 3/4] leds: max5970: Make use of dev_err_probe() Andy Shevchenko
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2023-12-14 18:40 UTC (permalink / raw)
  To: Andy Shevchenko, Patrick Rudolph, linux-leds, linux-kernel
  Cc: Pavel Machek, Lee Jones

Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.

Add mod_devicetable.h include.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-max5970.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/leds/leds-max5970.c b/drivers/leds/leds-max5970.c
index 7959d079ae94..de57b385b4f6 100644
--- a/drivers/leds/leds-max5970.c
+++ b/drivers/leds/leds-max5970.c
@@ -9,8 +9,9 @@
 
 #include <linux/leds.h>
 #include <linux/mfd/max5970.h>
-#include <linux/of.h>
+#include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 
 #define ldev_to_maxled(c)       container_of(c, struct max5970_led, cdev)
@@ -40,25 +41,24 @@ static int max5970_led_set_brightness(struct led_classdev *cdev,
 
 static int max5970_led_probe(struct platform_device *pdev)
 {
+	struct fwnode_handle *led_node, *child;
 	struct device *dev = &pdev->dev;
-	struct device_node *np = dev_of_node(dev->parent);
 	struct regmap *regmap;
-	struct device_node *led_node, *child;
 	struct max5970_led *ddata;
 	int ret = -ENODEV;
 
-	regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	regmap = dev_get_regmap(dev->parent, NULL);
 	if (!regmap)
 		return -ENODEV;
 
-	led_node = of_get_child_by_name(np, "leds");
+	led_node = device_get_named_child_node(dev->parent, "leds");
 	if (!led_node)
 		return -ENODEV;
 
-	for_each_available_child_of_node(led_node, child) {
+	fwnode_for_each_available_child_node(led_node, child) {
 		u32 reg;
 
-		if (of_property_read_u32(child, "reg", &reg))
+		if (fwnode_property_read_u32(child, "reg", &reg))
 			continue;
 
 		if (reg >= MAX5970_NUM_LEDS) {
@@ -68,7 +68,7 @@ static int max5970_led_probe(struct platform_device *pdev)
 
 		ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
 		if (!ddata) {
-			of_node_put(child);
+			fwnode_handle_put(child);
 			return -ENOMEM;
 		}
 
@@ -76,8 +76,8 @@ static int max5970_led_probe(struct platform_device *pdev)
 		ddata->regmap = regmap;
 		ddata->dev = dev;
 
-		if (of_property_read_string(child, "label", &ddata->cdev.name))
-			ddata->cdev.name = child->name;
+		if (fwnode_property_read_string(child, "label", &ddata->cdev.name))
+			ddata->cdev.name = fwnode_get_name(child);
 
 		ddata->cdev.max_brightness = 1;
 		ddata->cdev.brightness_set_blocking = max5970_led_set_brightness;
@@ -85,7 +85,7 @@ static int max5970_led_probe(struct platform_device *pdev)
 
 		ret = devm_led_classdev_register(dev, &ddata->cdev);
 		if (ret < 0) {
-			of_node_put(child);
+			fwnode_handle_put(child);
 			dev_err(dev, "Failed to initialize LED %u\n", reg);
 			return ret;
 		}
@@ -100,8 +100,8 @@ static struct platform_driver max5970_led_driver = {
 	},
 	.probe = max5970_led_probe,
 };
-
 module_platform_driver(max5970_led_driver);
+
 MODULE_AUTHOR("Patrick Rudolph <patrick.rudolph@9elements.com>");
 MODULE_AUTHOR("Naresh Solanki <Naresh.Solanki@9elements.com>");
 MODULE_DESCRIPTION("MAX5970_hot-swap controller LED driver");
-- 
2.43.0.rc1.1.gbec44491f096


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 3/4] leds: max5970: Make use of dev_err_probe()
  2023-12-14 18:40 [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms Andy Shevchenko
  2023-12-14 18:40 ` [PATCH v1 1/4] leds: max5970: Remove unused variable Andy Shevchenko
  2023-12-14 18:40 ` [PATCH v1 2/4] leds: max5970: Make use of device properties Andy Shevchenko
@ 2023-12-14 18:40 ` Andy Shevchenko
  2023-12-14 18:40 ` [PATCH v1 4/4] leds: max5970: Add missing headers Andy Shevchenko
  2023-12-21 14:44 ` [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms Lee Jones
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2023-12-14 18:40 UTC (permalink / raw)
  To: Andy Shevchenko, Patrick Rudolph, linux-leds, linux-kernel
  Cc: Pavel Machek, Lee Jones

Simplify the error handling in probe function by switching from
dev_err() to dev_err_probe().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-max5970.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/leds-max5970.c b/drivers/leds/leds-max5970.c
index de57b385b4f6..60db3c28d7d9 100644
--- a/drivers/leds/leds-max5970.c
+++ b/drivers/leds/leds-max5970.c
@@ -62,7 +62,7 @@ static int max5970_led_probe(struct platform_device *pdev)
 			continue;
 
 		if (reg >= MAX5970_NUM_LEDS) {
-			dev_err(dev, "invalid LED (%u >= %d)\n", reg, MAX5970_NUM_LEDS);
+			dev_err_probe(dev, -EINVAL, "invalid LED (%u >= %d)\n", reg, MAX5970_NUM_LEDS);
 			continue;
 		}
 
@@ -86,8 +86,7 @@ static int max5970_led_probe(struct platform_device *pdev)
 		ret = devm_led_classdev_register(dev, &ddata->cdev);
 		if (ret < 0) {
 			fwnode_handle_put(child);
-			dev_err(dev, "Failed to initialize LED %u\n", reg);
-			return ret;
+			return dev_err_probe(dev, ret, "Failed to initialize LED %u\n", reg);
 		}
 	}
 
-- 
2.43.0.rc1.1.gbec44491f096


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 4/4] leds: max5970: Add missing headers
  2023-12-14 18:40 [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms Andy Shevchenko
                   ` (2 preceding siblings ...)
  2023-12-14 18:40 ` [PATCH v1 3/4] leds: max5970: Make use of dev_err_probe() Andy Shevchenko
@ 2023-12-14 18:40 ` Andy Shevchenko
  2023-12-21 14:44 ` [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms Lee Jones
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2023-12-14 18:40 UTC (permalink / raw)
  To: Andy Shevchenko, Patrick Rudolph, linux-leds, linux-kernel
  Cc: Pavel Machek, Lee Jones

Don't inherit headers "by chance" from others.
Include the needed ones explicitly.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-max5970.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/leds/leds-max5970.c b/drivers/leds/leds-max5970.c
index 60db3c28d7d9..56a584311581 100644
--- a/drivers/leds/leds-max5970.c
+++ b/drivers/leds/leds-max5970.c
@@ -7,9 +7,13 @@
  * Author: Patrick Rudolph <patrick.rudolph@9elements.com>
  */
 
+#include <linux/bits.h>
+#include <linux/container_of.h>
+#include <linux/device.h>
 #include <linux/leds.h>
 #include <linux/mfd/max5970.h>
 #include <linux/mod_devicetable.h>
+#include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/regmap.h>
-- 
2.43.0.rc1.1.gbec44491f096


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms
  2023-12-14 18:40 [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms Andy Shevchenko
                   ` (3 preceding siblings ...)
  2023-12-14 18:40 ` [PATCH v1 4/4] leds: max5970: Add missing headers Andy Shevchenko
@ 2023-12-21 14:44 ` Lee Jones
  4 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2023-12-21 14:44 UTC (permalink / raw)
  To: Patrick Rudolph, linux-leds, linux-kernel, Andy Shevchenko
  Cc: Pavel Machek, Lee Jones

On Thu, 14 Dec 2023 20:40:07 +0200, Andy Shevchenko wrote:
> Allow to use driver on non-OF platforms and other cleanups.
> 
> Andy Shevchenko (4):
>   leds: max5970: Remove unused variable
>   leds: max5970: Make use of device properties
>   leds: max5970: Make use of dev_err_probe()
>   leds: max5970: Add missing headers
> 
> [...]

Applied, thanks!

[1/4] leds: max5970: Remove unused variable
      commit: d3578b4982e6ebccbd898806ac86b2db4b2bcc5e
[2/4] leds: max5970: Make use of device properties
      commit: 6d63d05e26f8d5e22308efc25793660101fd7602
[3/4] leds: max5970: Make use of dev_err_probe()
      commit: e7baa5b437a782308b86c1517ae252fd1353eb0b
[4/4] leds: max5970: Add missing headers
      commit: 808c7881876756dfcd8c4d0c3efc27c9262da822

--
Lee Jones [李琼斯]


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-12-21 14:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-14 18:40 [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms Andy Shevchenko
2023-12-14 18:40 ` [PATCH v1 1/4] leds: max5970: Remove unused variable Andy Shevchenko
2023-12-14 18:40 ` [PATCH v1 2/4] leds: max5970: Make use of device properties Andy Shevchenko
2023-12-14 18:40 ` [PATCH v1 3/4] leds: max5970: Make use of dev_err_probe() Andy Shevchenko
2023-12-14 18:40 ` [PATCH v1 4/4] leds: max5970: Add missing headers Andy Shevchenko
2023-12-21 14:44 ` [PATCH v1 0/4] leds: max5970: Allow to use on non-OF platforms Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox