2020-09-17 22:35:24

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 00/50] Start moving parsing of `linux,default-trigger` to LED core (a cleanup of LED drivers)

Hi,

this series is also available at [1].

This is v2, you can read cover letter of v1 at [2] (togehter with
explanation of why I did this).

Changes since v1:
- split big changes into several patches of little changes
- added many cosmetic fixes (helper variables, reversal christmas tree
variables declaration, ...)
- fixed some bugs in various drivers (memory leaks, iteration over
unavailable OF nodes)
- made some drivers compilable when COMPILE_TEST=y (since allyesconfig
did not compile them). Not all though, some still don't compile with
allyesconfig
- the commit that moves parsing of `linux,default-trigger` property from
drivers to LED core is now last in the series, instead of first

Marek

[1] https://git.kernel.org/pub/scm/linux/kernel/git/kabel/linux.git/log/?h=leds-cleanup-for-pavel
[2] https://lore.kernel.org/linux-leds/[email protected]/T/#m826493318174b0f38a3d4ba107092b5420ce440c

Cc: Álvaro Fernández Rojas <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: Andrey Utkin <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Bjorn Andersson <[email protected]>
Cc: Christian Mauderer <[email protected]>
Cc: Chunyan Zhang <[email protected]>
Cc: Daniel Mack <[email protected]>
Cc: Dan Murphy <[email protected]>
Cc: David Rivshin <[email protected]>
Cc: Grant Feng <[email protected]>
Cc: Haojian Zhuang <[email protected]>
Cc: H. Nikolaus Schaller <[email protected]>
Cc: Jaedon Shin <[email protected]>
Cc: John Crispin <[email protected]>
Cc: Kevin Cernekee <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Matthias Brugger <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Milo Kim <[email protected]>
Cc: NeilBrown <[email protected]>
Cc: Nikita Travkin <[email protected]>
Cc: Orson Zhai <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: Philippe Retornaz <[email protected]>
Cc: Riku Voipio <[email protected]>
Cc: Rod Whitby <[email protected]>
Cc: Ryder Lee <[email protected]>
Cc: Sakari Ailus <[email protected]>
Cc: Sean Wang <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Shields <[email protected]>
Cc: Thierry Reding <[email protected]>
Cc: Thomas Bogendoerfer <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Vasant Hegde <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Xiaotong Lu <[email protected]>

Marek Behún (50):
leds: various: compile if COMPILE_TEST=y
leds: ip30: compile if COMPILE_TEST=y
leds: fsg: compile if COMPILE_TEST=y
leds: various: use device_get_match_data
leds: various: guard of_match_table member value with of_match_ptr
leds: various: use dev_of_node(dev) instead of dev->of_node
leds: lt3593: do not rewrite .of_node of new LED device to wrong value
leds: various: use only available OF children
leds: various: fix OF node leaks
leds: bcm6328, bcm6358: use devres LED registering function
leds: bcm6328, bcm6358: use struct led_init_data when registering
leds: bcm6328: cosmetic: use reverse christmas tree
leds: bcm6358: cosmetic: use reverse christmas tree
leds: lm3697: use struct led_init_data when registering
leds: lm3697: cosmetic change: use helper variable, reverse christmas
tree
leds: max77650: use struct led_init_data when registering
leds: max77650: use reverse christmas tree
leds: mt6323: use struct led_init_data when registering
leds: mt6323: cosmetic change: use helper variable
leds: pm8058: use struct led_init_data when registering
leds: pm8058: cosmetic change: use helper variable
leds: pm8058: cosmetic change: no need to return in if guard
leds: pm8058: cosmetic: use reverse christmas tree
leds: is31fl32xx: use struct led_init_data when registering
leds: is31fl319x: compute aggregated max current separately
leds: is31fl319x: don't store shutdown gpio descriptor
leds: is31fl319x: don't store audio gain value, simply set it
leds: is31fl319x: refactor to register LEDs while parsing DT
leds: is31fl319x: cosmetic: use reverse christmas tree
leds: is31fl319x: use struct led_init_data when registering
leds: lm36274: use devres LED registering function
leds: lm36274: cosmetic: rename lm36274_data to chip
leds: lm36274: don't iterate through children since there is only one
leds: lm36274: use struct led_init_data when registering
leds: lm36274: do not set chip settings in DT parsing function
leds: ns2: use devres LED registering function
leds: ns2: alloc simple array instead of struct ns2_led_priv
leds: ns2: support OF probing only, forget platdata
leds: ns2: move parsing of one LED into separate function
leds: ns2: use devres API for getting GPIO descriptors
leds: ns2: cosmetic structure rename
leds: ns2: cosmetic variable rename
leds: ns2: cosmetic change
leds: ns2: cosmetic change: use helper variable
leds: ns2: register LED immediately after parsing DT properties
leds: ns2: remove unneeded variable
leds: ns2: cosmetic: use reverse christmas tree
leds: ns2: reorder headers alphabetically
leds: ns2: use struct led_init_data when registering
leds: parse linux,default-trigger DT property in LED core

drivers/leds/Kconfig | 14 +-
drivers/leds/led-class.c | 5 +
drivers/leds/leds-88pm860x.c | 6 +-
drivers/leds/leds-aat1290.c | 4 +-
drivers/leds/leds-an30259a.c | 7 +-
drivers/leds/leds-as3645a.c | 2 +-
drivers/leds/leds-aw2013.c | 11 +-
drivers/leds/leds-bcm6328.c | 28 ++-
drivers/leds/leds-bcm6358.c | 20 +-
drivers/leds/leds-cpcap.c | 9 +-
drivers/leds/leds-cr0014114.c | 5 +-
drivers/leds/leds-el15203000.c | 5 +-
drivers/leds/leds-fsg.c | 6 +
drivers/leds/leds-gpio.c | 5 +-
drivers/leds/leds-ip30.c | 1 +
drivers/leds/leds-is31fl319x.c | 260 +++++++++++-----------
drivers/leds/leds-is31fl32xx.c | 35 ++-
drivers/leds/leds-ktd2692.c | 6 +-
drivers/leds/leds-lm3532.c | 5 +-
drivers/leds/leds-lm3601x.c | 2 +-
drivers/leds/leds-lm36274.c | 122 +++++------
drivers/leds/leds-lm3692x.c | 5 +-
drivers/leds/leds-lm3697.c | 96 ++++----
drivers/leds/leds-lp50xx.c | 2 +-
drivers/leds/leds-lp5521.c | 2 +-
drivers/leds/leds-lp5523.c | 2 +-
drivers/leds/leds-lp5562.c | 2 +-
drivers/leds/leds-lp55xx-common.c | 14 +-
drivers/leds/leds-lp8501.c | 2 +-
drivers/leds/leds-lp8860.c | 8 +-
drivers/leds/leds-lt3593.c | 6 +-
drivers/leds/leds-max77650.c | 28 +--
drivers/leds/leds-max77693.c | 4 +-
drivers/leds/leds-mc13783.c | 8 +-
drivers/leds/leds-mt6323.c | 22 +-
drivers/leds/leds-netxbig.c | 8 +-
drivers/leds/leds-ns2.c | 349 ++++++++++--------------------
drivers/leds/leds-pca9532.c | 4 +-
drivers/leds/leds-pca955x.c | 2 +-
drivers/leds/leds-pca963x.c | 2 +-
drivers/leds/leds-pm8058.c | 43 ++--
drivers/leds/leds-powernv.c | 4 +-
drivers/leds/leds-pwm.c | 2 +-
drivers/leds/leds-sc27xx-bltc.c | 8 +-
drivers/leds/leds-sgm3140.c | 2 +-
drivers/leds/leds-spi-byte.c | 13 +-
drivers/leds/leds-syscon.c | 6 +-
drivers/leds/leds-tca6507.c | 8 +-
drivers/leds/leds-tlc591xx.c | 16 +-
drivers/leds/leds-turris-omnia.c | 10 +-
50 files changed, 511 insertions(+), 725 deletions(-)

--
2.26.2


2020-09-17 22:35:29

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 14/50] leds: lm3697: use struct led_init_data when registering

By using struct led_init_data when registering we do not need to parse
`label` DT property. Moreover `label` is deprecated and if it is not
present but `color` and `function` are, LED core will compose a name
from these properties instead.

Previously if the `label` DT property was not present, the code composed
name for the LED in the form
"parent_name::"
For backwards compatibility we therefore set
init_data->default_label = ":";
so that the LED will not get a different name if `label` property is not
present.

Signed-off-by: Marek Behún <[email protected]>
Cc: Dan Murphy <[email protected]>
---
drivers/leds/leds-lm3697.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/leds/leds-lm3697.c b/drivers/leds/leds-lm3697.c
index 5d14f3d2220af..479776ac36c35 100644
--- a/drivers/leds/leds-lm3697.c
+++ b/drivers/leds/leds-lm3697.c
@@ -194,7 +194,6 @@ static int lm3697_probe_dt(struct lm3697 *priv)
{
struct fwnode_handle *child = NULL;
struct lm3697_led *led;
- const char *name;
int control_bank;
size_t i = 0;
int ret = -EINVAL;
@@ -214,6 +213,8 @@ static int lm3697_probe_dt(struct lm3697 *priv)
priv->regulator = NULL;

device_for_each_child_node(priv->dev, child) {
+ struct led_init_data init_data = {};
+
ret = fwnode_property_read_u32(child, "reg", &control_bank);
if (ret) {
dev_err(&priv->client->dev, "reg property missing\n");
@@ -271,20 +272,17 @@ static int lm3697_probe_dt(struct lm3697 *priv)
fwnode_property_read_string(child, "linux,default-trigger",
&led->led_dev.default_trigger);

- ret = fwnode_property_read_string(child, "label", &name);
- if (ret)
- snprintf(led->label, sizeof(led->label),
- "%s::", priv->client->name);
- else
- snprintf(led->label, sizeof(led->label),
- "%s:%s", priv->client->name, name);
+ init_data.fwnode = child;
+ init_data.devicename = priv->client->name;
+ /* for backwards compatibility if `label` is not present */
+ init_data.default_label = ":";

led->priv = priv;
- led->led_dev.name = led->label;
led->led_dev.max_brightness = led->lmu_data.max_brightness;
led->led_dev.brightness_set_blocking = lm3697_brightness_set;

- ret = devm_led_classdev_register(priv->dev, &led->led_dev);
+ ret = devm_led_classdev_register_ext(priv->dev, &led->led_dev,
+ &init_data);
if (ret) {
dev_err(&priv->client->dev, "led register err: %d\n",
ret);
--
2.26.2

2020-09-17 22:35:45

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 25/50] leds: is31fl319x: compute aggregated max current separately

Parse `led-max-current` property of child nodes and compute aggregated
value in a separate function. The controller cannot set this value
separately for every LED, so there is no need to store this value for
every LED.

Signed-off-by: Marek Behún <[email protected]>
Cc: H. Nikolaus Schaller <[email protected]>
---
drivers/leds/leds-is31fl319x.c | 61 ++++++++++++++++++++++------------
1 file changed, 39 insertions(+), 22 deletions(-)

diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c
index 4161b9dd7e488..ba1a5da5521b5 100644
--- a/drivers/leds/leds-is31fl319x.c
+++ b/drivers/leds/leds-is31fl319x.c
@@ -71,7 +71,6 @@ struct is31fl319x_chip {
struct is31fl319x_led {
struct is31fl319x_chip *chip;
struct led_classdev cdev;
- u32 max_microamp;
bool configured;
} leds[IS31FL319X_MAX_LEDS];
};
@@ -171,6 +170,35 @@ static int is31fl319x_brightness_set(struct led_classdev *cdev,
return ret;
}

+static int is31fl319x_parse_max_current(struct device *dev, u32 *aggregated)
+{
+ struct device_node *np;
+ u32 value;
+ int ret;
+
+ *aggregated = IS31FL319X_CURRENT_MAX;
+
+ for_each_available_child_of_node(dev_of_node(dev), np) {
+ value = IS31FL319X_CURRENT_DEFAULT;
+ ret = of_property_read_u32(np, "led-max-microamp", &value);
+ if (!ret)
+ value = min(value, IS31FL319X_CURRENT_MAX);
+
+ if (value < IS31FL319X_CURRENT_MIN) {
+ dev_err(dev,
+ "Value of led-max-microamp too low for %pOF\n",
+ np);
+ of_node_put(np);
+ return -EINVAL;
+ }
+
+ if (value < *aggregated)
+ *aggregated = value;
+ }
+
+ return 0;
+}
+
static int is31fl319x_parse_child_dt(const struct device *dev,
const struct device_node *child,
struct is31fl319x_led *led)
@@ -186,16 +214,6 @@ static int is31fl319x_parse_child_dt(const struct device *dev,
if (ret < 0 && ret != -EINVAL) /* is optional */
return ret;

- led->max_microamp = IS31FL319X_CURRENT_DEFAULT;
- ret = of_property_read_u32(child, "led-max-microamp",
- &led->max_microamp);
- if (!ret) {
- if (led->max_microamp < IS31FL319X_CURRENT_MIN)
- return -EINVAL; /* not supported */
- led->max_microamp = min(led->max_microamp,
- IS31FL319X_CURRENT_MAX);
- }
-
return 0;
}

@@ -339,11 +357,20 @@ static int is31fl319x_probe(struct i2c_client *client,
struct device *dev = &client->dev;
int err;
int i = 0;
- u32 aggregated_led_microamp = IS31FL319X_CURRENT_MAX;
+ u32 aggregated_led_microamp;

if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
return -EIO;

+ /*
+ * Kernel conventions require per-LED led-max-microamp property.
+ * But the chip does not allow to limit individual LEDs.
+ * So we take minimum from all subnodes for safety of hardware.
+ */
+ err = is31fl319x_parse_max_current(dev, &aggregated_led_microamp);
+ if (err)
+ return err;
+
is31 = devm_kzalloc(&client->dev, sizeof(*is31), GFP_KERNEL);
if (!is31)
return -ENOMEM;
@@ -379,16 +406,6 @@ static int is31fl319x_probe(struct i2c_client *client,
goto free_mutex;
}

- /*
- * Kernel conventions require per-LED led-max-microamp property.
- * But the chip does not allow to limit individual LEDs.
- * So we take minimum from all subnodes for safety of hardware.
- */
- for (i = 0; i < is31->cdef->num_leds; i++)
- if (is31->leds[i].configured &&
- is31->leds[i].max_microamp < aggregated_led_microamp)
- aggregated_led_microamp = is31->leds[i].max_microamp;
-
regmap_write(is31->regmap, IS31FL319X_CONFIG2,
is31fl319x_microamp_to_cs(dev, aggregated_led_microamp) |
is31fl319x_db_to_gain(is31->audio_gain_db));
--
2.26.2

2020-09-17 22:35:50

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 23/50] leds: pm8058: cosmetic: use reverse christmas tree

Only a cosmetic change: use reverse christmas tree variables
declaration.

Signed-off-by: Marek Behún <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Bjorn Andersson <[email protected]>
---
drivers/leds/leds-pm8058.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-pm8058.c b/drivers/leds/leds-pm8058.c
index 193780a8c0522..80db7e2de420c 100644
--- a/drivers/leds/leds-pm8058.c
+++ b/drivers/leds/leds-pm8058.c
@@ -29,9 +29,9 @@ static void pm8058_led_set(struct led_classdev *cled,
enum led_brightness value)
{
struct pm8058_led *led;
- int ret = 0;
unsigned int mask = 0;
unsigned int val = 0;
+ int ret = 0;

led = container_of(cled, struct pm8058_led, cdev);
switch (led->ledtype) {
@@ -56,8 +56,8 @@ static void pm8058_led_set(struct led_classdev *cled,
static enum led_brightness pm8058_led_get(struct led_classdev *cled)
{
struct pm8058_led *led;
- int ret;
unsigned int val;
+ int ret;

led = container_of(cled, struct pm8058_led, cdev);

@@ -89,12 +89,12 @@ static int pm8058_led_probe(struct platform_device *pdev)
{
struct led_init_data init_data = {};
struct device *dev = &pdev->dev;
+ enum led_brightness maxbright;
struct pm8058_led *led;
struct device_node *np;
- int ret;
struct regmap *map;
const char *state;
- enum led_brightness maxbright;
+ int ret;

led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
if (!led)
--
2.26.2

2020-09-17 22:35:53

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 20/50] leds: pm8058: use struct led_init_data when registering

By using struct led_init_data when registering we do not need to parse
`label` DT property. Moreover `label` is deprecated and if it is not
present but `color` and `function` are, LED core will compose a name
from these properties instead.

Signed-off-by: Marek Behún <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Bjorn Andersson <[email protected]>
---
drivers/leds/leds-pm8058.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/leds-pm8058.c b/drivers/leds/leds-pm8058.c
index dcd7d8c3d6b44..e085bf9ffc1de 100644
--- a/drivers/leds/leds-pm8058.c
+++ b/drivers/leds/leds-pm8058.c
@@ -87,6 +87,7 @@ static enum led_brightness pm8058_led_get(struct led_classdev *cled)

static int pm8058_led_probe(struct platform_device *pdev)
{
+ struct led_init_data init_data = {};
struct pm8058_led *led;
struct device_node *np = dev_of_node(&pdev->dev);
int ret;
@@ -113,8 +114,6 @@ static int pm8058_led_probe(struct platform_device *pdev)
return -EINVAL;
}

- /* Use label else node name */
- led->cdev.name = of_get_property(np, "label", NULL) ? : np->name;
led->cdev.default_trigger =
of_get_property(np, "linux,default-trigger", NULL);
led->cdev.brightness_set = pm8058_led_set;
@@ -142,10 +141,12 @@ static int pm8058_led_probe(struct platform_device *pdev)
led->ledtype == PM8058_LED_TYPE_FLASH)
led->cdev.flags = LED_CORE_SUSPENDRESUME;

- ret = devm_led_classdev_register(&pdev->dev, &led->cdev);
+ init_data.fwnode = of_fwnode_handle(np);
+
+ ret = devm_led_classdev_register_ext(&pdev->dev, &led->cdev,
+ &init_data);
if (ret) {
- dev_err(&pdev->dev, "unable to register led \"%s\"\n",
- led->cdev.name);
+ dev_err(&pdev->dev, "Failed to register LED for %pOF\n", np);
return ret;
}

--
2.26.2

2020-09-17 22:36:01

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 38/50] leds: ns2: support OF probing only, forget platdata

Move forward from platform data to device tree only.

Since commit c7896490dd1a ("leds: ns2: Absorb platform data") the
platform data structure is absorbed into the driver, because nothing
else in the source tree uses it. Since nobody complained and all usage
of this driver is via device tree, change the code to work with device
tree only. As Linus Walleij wrote, the device tree should be the
preferred way forward anyway.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 40 +++++++++++++++-------------------------
1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 8cd020b340840..0e9c2f49b6350 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -39,7 +39,7 @@ struct ns2_led {
struct ns2_led_modval *modval;
};

-struct ns2_led_platform_data {
+struct ns2_led_of {
int num_leds;
struct ns2_led *leds;
};
@@ -230,12 +230,11 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
return devm_led_classdev_register(&pdev->dev, &led_dat->cdev);
}

-#ifdef CONFIG_OF_GPIO
/*
* Translate OpenFirmware node properties into platform_data.
*/
static int
-ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
+ns2_leds_parse_of(struct device *dev, struct ns2_led_of *ofdata)
{
struct device_node *np = dev_of_node(dev);
struct device_node *child;
@@ -317,8 +316,8 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
led++;
}

- pdata->leds = leds;
- pdata->num_leds = num_leds;
+ ofdata->leds = leds;
+ ofdata->num_leds = num_leds;

return 0;

@@ -332,40 +331,31 @@ static const struct of_device_id of_ns2_leds_match[] = {
{},
};
MODULE_DEVICE_TABLE(of, of_ns2_leds_match);
-#endif /* CONFIG_OF_GPIO */

static int ns2_led_probe(struct platform_device *pdev)
{
- struct ns2_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
+ struct ns2_led_of *ofdata;
struct ns2_led_data *leds;
int i;
int ret;

-#ifdef CONFIG_OF_GPIO
- if (!pdata) {
- pdata = devm_kzalloc(&pdev->dev,
- sizeof(struct ns2_led_platform_data),
- GFP_KERNEL);
- if (!pdata)
- return -ENOMEM;
+ ofdata = devm_kzalloc(&pdev->dev, sizeof(struct ns2_led_of),
+ GFP_KERNEL);
+ if (!ofdata)
+ return -ENOMEM;

- ret = ns2_leds_get_of_pdata(&pdev->dev, pdata);
- if (ret)
- return ret;
- }
-#else
- if (!pdata)
- return -EINVAL;
-#endif /* CONFIG_OF_GPIO */
+ ret = ns2_leds_parse_of(&pdev->dev, ofdata);
+ if (ret)
+ return ret;

leds = devm_kzalloc(&pdev->dev, array_size(sizeof(*leds),
- pdata->num_leds),
+ ofdata->num_leds),
GFP_KERNEL);
if (!leds)
return -ENOMEM;

- for (i = 0; i < pdata->num_leds; i++) {
- ret = create_ns2_led(pdev, &leds[i], &pdata->leds[i]);
+ for (i = 0; i < ofdata->num_leds; i++) {
+ ret = create_ns2_led(pdev, &leds[i], &ofdata->leds[i]);
if (ret < 0)
return ret;
}
--
2.26.2

2020-09-17 22:36:03

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 34/50] leds: lm36274: use struct led_init_data when registering

By using struct led_init_data when registering we do not need to parse
`label` DT property. Moreover `label` is deprecated and if it is not
present but `color` and `function` are, LED core will compose a name
from these properties instead.

Previously if the `label` DT property was not present, the code composed
name for the LED in the form
"parent_name::"
For backwards compatibility we therefore set
init_data->default_label = ":";
so that the LED will not get a different name if `label` property is not
present, nor are `color` and `function`.

Signed-off-by: Marek Behún <[email protected]>
Cc: Dan Murphy <[email protected]>
---
drivers/leds/leds-lm36274.c | 43 ++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c
index 4282b7392f2b5..294edcc054bea 100644
--- a/drivers/leds/leds-lm36274.c
+++ b/drivers/leds/leds-lm36274.c
@@ -66,12 +66,11 @@ static int lm36274_init(struct lm36274 *chip)
return regmap_write(chip->regmap, LM36274_REG_BL_EN, enable_val);
}

-static int lm36274_parse_dt(struct lm36274 *chip)
+static int lm36274_parse_dt(struct lm36274 *chip,
+ struct led_init_data *init_data)
{
- struct fwnode_handle *child = NULL;
- char label[LED_MAX_NAME_SIZE];
struct device *dev = &chip->pdev->dev;
- const char *name;
+ struct fwnode_handle *child;
int ret;

/* There should only be 1 node */
@@ -80,43 +79,45 @@ static int lm36274_parse_dt(struct lm36274 *chip)

child = device_get_next_child_node(dev, NULL);

- ret = fwnode_property_read_string(child, "label", &name);
- if (ret)
- snprintf(label, sizeof(label), "%s::", chip->pdev->name);
- else
- snprintf(label, sizeof(label), "%s:%s", chip->pdev->name, name);
+ init_data->fwnode = child;
+ init_data->devicename = chip->pdev->name;
+ /* for backwards compatibility when `label` property is not present */
+ init_data->default_label = ":";

chip->num_leds = fwnode_property_count_u32(child, "led-sources");
- if (chip->num_leds <= 0)
- return -ENODEV;
+ if (chip->num_leds <= 0) {
+ ret = -ENODEV;
+ goto err;
+ }

ret = fwnode_property_read_u32_array(child, "led-sources",
chip->led_sources, chip->num_leds);
if (ret) {
dev_err(dev, "led-sources property missing\n");
- return ret;
+ goto err;
}

fwnode_property_read_string(child, "linux,default-trigger",
&chip->led_dev.default_trigger);

- fwnode_handle_put(child);
-
chip->lmu_data.regmap = chip->regmap;
chip->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
chip->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;
chip->lmu_data.lsb_brightness_reg = LM36274_REG_BRT_LSB;

- chip->led_dev.name = label;
chip->led_dev.max_brightness = MAX_BRIGHTNESS_11BIT;
chip->led_dev.brightness_set_blocking = lm36274_brightness_set;

return 0;
+err:
+ fwnode_handle_put(child);
+ return ret;
}

static int lm36274_probe(struct platform_device *pdev)
{
struct ti_lmu *lmu = dev_get_drvdata(pdev->dev.parent);
+ struct led_init_data init_data = {};
struct lm36274 *chip;
int ret;

@@ -129,7 +130,7 @@ static int lm36274_probe(struct platform_device *pdev)
chip->regmap = lmu->regmap;
platform_set_drvdata(pdev, chip);

- ret = lm36274_parse_dt(chip);
+ ret = lm36274_parse_dt(chip, &init_data);
if (ret) {
dev_err(chip->dev, "Failed to parse DT node\n");
return ret;
@@ -141,7 +142,15 @@ static int lm36274_probe(struct platform_device *pdev)
return ret;
}

- return devm_led_classdev_register(chip->dev, &chip->led_dev);
+ ret = devm_led_classdev_register_ext(chip->dev, &chip->led_dev,
+ &init_data);
+ if (ret)
+ dev_err(chip->dev, "Failed to register LED for node %pfw\n",
+ init_data.fwnode);
+
+ fwnode_handle_put(init_data.fwnode);
+
+ return ret;
}

static const struct of_device_id of_lm36274_leds_match[] = {
--
2.26.2

2020-09-17 22:36:09

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 50/50] leds: parse linux,default-trigger DT property in LED core

Do parsing of `linux,default-trigger` DT property to LED core. Currently
it is done in many different drivers and the code is repeated.

This patch removes the parsing from 21 drivers:
an30259a, aw2013, bcm6328, bcm6358, cr0014114, el15203000, gpio,
is31fl319x, is31fl32xx, lm3532, lm36274, lm3692x, lm3697, lp8860,
lt3593, max77650, mt6323, ns2, pm8058, tlc591xx and turris-omnia.

There are still 11 drivers that parse this property on their own because
they do not pass the led_init_data structure to the registering
function. I will try to refactor those in the future.

Signed-off-by: Marek Behún <[email protected]>
---
drivers/leds/led-class.c | 5 +++++
drivers/leds/leds-an30259a.c | 3 ---
drivers/leds/leds-aw2013.c | 3 ---
drivers/leds/leds-bcm6328.c | 4 ----
drivers/leds/leds-bcm6358.c | 4 ----
drivers/leds/leds-cr0014114.c | 3 ---
drivers/leds/leds-el15203000.c | 3 ---
drivers/leds/leds-gpio.c | 3 ---
drivers/leds/leds-is31fl319x.c | 5 -----
drivers/leds/leds-is31fl32xx.c | 3 ---
drivers/leds/leds-lm3532.c | 3 ---
drivers/leds/leds-lm36274.c | 3 ---
drivers/leds/leds-lm3692x.c | 3 ---
drivers/leds/leds-lm3697.c | 3 ---
drivers/leds/leds-lp8860.c | 4 ----
drivers/leds/leds-lt3593.c | 3 ---
drivers/leds/leds-max77650.c | 3 ---
drivers/leds/leds-mt6323.c | 4 ----
drivers/leds/leds-ns2.c | 3 ---
drivers/leds/leds-pm8058.c | 2 --
drivers/leds/leds-tlc591xx.c | 3 ---
drivers/leds/leds-turris-omnia.c | 2 --
22 files changed, 5 insertions(+), 67 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index cc3929f858b68..131ca83f5fb38 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -354,6 +354,11 @@ int led_classdev_register_ext(struct device *parent,
ret = led_compose_name(parent, init_data, composed_name);
if (ret < 0)
return ret;
+
+ if (init_data->fwnode)
+ fwnode_property_read_string(init_data->fwnode,
+ "linux,default-trigger",
+ &led_cdev->default_trigger);
} else {
proposed_name = led_cdev->name;
}
diff --git a/drivers/leds/leds-an30259a.c b/drivers/leds/leds-an30259a.c
index 9749f1cc3e15f..a0df1fb28774d 100644
--- a/drivers/leds/leds-an30259a.c
+++ b/drivers/leds/leds-an30259a.c
@@ -238,9 +238,6 @@ static int an30259a_dt_init(struct i2c_client *client,
led->default_state = STATE_OFF;
}

- of_property_read_string(child, "linux,default-trigger",
- &led->cdev.default_trigger);
-
i++;
}

diff --git a/drivers/leds/leds-aw2013.c b/drivers/leds/leds-aw2013.c
index 927c5ba32592f..80d937454aeef 100644
--- a/drivers/leds/leds-aw2013.c
+++ b/drivers/leds/leds-aw2013.c
@@ -297,9 +297,6 @@ static int aw2013_probe_dt(struct aw2013 *chip)
"DT property led-max-microamp is missing\n");
}

- of_property_read_string(child, "linux,default-trigger",
- &led->cdev.default_trigger);
-
led->cdev.brightness_set_blocking = aw2013_brightness_set;
led->cdev.blink_set = aw2013_blink_set;

diff --git a/drivers/leds/leds-bcm6328.c b/drivers/leds/leds-bcm6328.c
index 38bf820372528..f89ca2143b95d 100644
--- a/drivers/leds/leds-bcm6328.c
+++ b/drivers/leds/leds-bcm6328.c
@@ -346,10 +346,6 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg,
if (of_property_read_bool(nc, "active-low"))
led->active_low = true;

- led->cdev.default_trigger = of_get_property(nc,
- "linux,default-trigger",
- NULL);
-
if (!of_property_read_string(nc, "default-state", &state)) {
if (!strcmp(state, "on")) {
led->cdev.brightness = LED_FULL;
diff --git a/drivers/leds/leds-bcm6358.c b/drivers/leds/leds-bcm6358.c
index 71c49d5fa811f..aabf68d276216 100644
--- a/drivers/leds/leds-bcm6358.c
+++ b/drivers/leds/leds-bcm6358.c
@@ -110,10 +110,6 @@ static int bcm6358_led(struct device *dev, struct device_node *nc, u32 reg,
if (of_property_read_bool(nc, "active-low"))
led->active_low = true;

- led->cdev.default_trigger = of_get_property(nc,
- "linux,default-trigger",
- NULL);
-
if (!of_property_read_string(nc, "default-state", &state)) {
if (!strcmp(state, "on")) {
led->cdev.brightness = LED_FULL;
diff --git a/drivers/leds/leds-cr0014114.c b/drivers/leds/leds-cr0014114.c
index a2f5638eda5f7..e0be7603d4791 100644
--- a/drivers/leds/leds-cr0014114.c
+++ b/drivers/leds/leds-cr0014114.c
@@ -188,9 +188,6 @@ static int cr0014114_probe_dt(struct cr0014114 *priv)
device_for_each_child_node(priv->dev, child) {
led = &priv->leds[i];

- fwnode_property_read_string(child, "linux,default-trigger",
- &led->ldev.default_trigger);
-
led->priv = priv;
led->ldev.max_brightness = CR_MAX_BRIGHTNESS;
led->ldev.brightness_set_blocking = cr0014114_set_sync;
diff --git a/drivers/leds/leds-el15203000.c b/drivers/leds/leds-el15203000.c
index bcd13a7fc9d02..f8a56ebd87060 100644
--- a/drivers/leds/leds-el15203000.c
+++ b/drivers/leds/leds-el15203000.c
@@ -263,9 +263,6 @@ static int el15203000_probe_dt(struct el15203000 *priv)
return -EINVAL;
}

- fwnode_property_read_string(child, "linux,default-trigger",
- &led->ldev.default_trigger);
-
led->priv = priv;
led->ldev.max_brightness = LED_ON;
led->ldev.brightness_set_blocking = el15203000_set_blocking;
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index aa740267eb232..09fd6b1e8fc38 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -160,9 +160,6 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)

led_dat->gpiod = led.gpiod;

- fwnode_property_read_string(child, "linux,default-trigger",
- &led.default_trigger);
-
if (!fwnode_property_read_string(child, "default-state",
&state)) {
if (!strcmp(state, "keep"))
diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c
index ef5b3e08c7313..23616dded8284 100644
--- a/drivers/leds/leds-is31fl319x.c
+++ b/drivers/leds/leds-is31fl319x.c
@@ -293,11 +293,6 @@ static int is31fl319x_led_register(struct device *dev,
return -EEXIST;
}

- ret = of_property_read_string(np, "linux,default-trigger",
- &led->cdev.default_trigger);
- if (ret < 0 && ret != -EINVAL) /* is optional */
- return ret;
-
led->configured = true;
led->chip = is31;
led->cdev.brightness_set_blocking = is31fl319x_brightness_set;
diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c
index 279f52931a177..d21b333a17e8e 100644
--- a/drivers/leds/leds-is31fl32xx.c
+++ b/drivers/leds/leds-is31fl32xx.c
@@ -341,9 +341,6 @@ static int is31fl32xx_parse_child_dt(const struct device *dev,
}
led_data->channel = reg;

- of_property_read_string(child, "linux,default-trigger",
- &cdev->default_trigger);
-
cdev->brightness_set_blocking = is31fl32xx_brightness_set;

return 0;
diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c
index 3670cc64eee7b..610168dc7ad77 100644
--- a/drivers/leds/leds-lm3532.c
+++ b/drivers/leds/leds-lm3532.c
@@ -643,9 +643,6 @@ static int lm3532_parse_node(struct lm3532_data *priv)
goto child_out;
}

- fwnode_property_read_string(child, "linux,default-trigger",
- &led->led_dev.default_trigger);
-
ret = fwnode_property_read_string(child, "label", &name);
if (ret)
snprintf(led->label, sizeof(led->label),
diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c
index b61c97ed26603..b49b85207fd8a 100644
--- a/drivers/leds/leds-lm36274.c
+++ b/drivers/leds/leds-lm36274.c
@@ -97,9 +97,6 @@ static int lm36274_parse_dt(struct lm36274 *chip,
goto err;
}

- fwnode_property_read_string(child, "linux,default-trigger",
- &chip->led_dev.default_trigger);
-
return 0;
err:
fwnode_handle_put(child);
diff --git a/drivers/leds/leds-lm3692x.c b/drivers/leds/leds-lm3692x.c
index ba535ee8fd252..27327bf6ea025 100644
--- a/drivers/leds/leds-lm3692x.c
+++ b/drivers/leds/leds-lm3692x.c
@@ -433,9 +433,6 @@ static int lm3692x_probe_dt(struct lm3692x_led *led)
return -ENODEV;
}

- fwnode_property_read_string(child, "linux,default-trigger",
- &led->led_dev.default_trigger);
-
ret = fwnode_property_read_u32(child, "reg", &led->led_enable);
if (ret) {
dev_err(&led->client->dev, "reg DT property missing\n");
diff --git a/drivers/leds/leds-lm3697.c b/drivers/leds/leds-lm3697.c
index 0c5c29730c407..50338ae0b7857 100644
--- a/drivers/leds/leds-lm3697.c
+++ b/drivers/leds/leds-lm3697.c
@@ -268,9 +268,6 @@ static int lm3697_probe_dt(struct lm3697 *priv)
if (ret)
dev_warn(dev, "runtime-ramp properties missing\n");

- fwnode_property_read_string(child, "linux,default-trigger",
- &led->led_dev.default_trigger);
-
init_data.fwnode = child;
init_data.devicename = priv->client->name;
/* for backwards compatibility if `label` is not present */
diff --git a/drivers/leds/leds-lp8860.c b/drivers/leds/leds-lp8860.c
index b69ed81d52ab4..f9b8abaac6b73 100644
--- a/drivers/leds/leds-lp8860.c
+++ b/drivers/leds/leds-lp8860.c
@@ -392,10 +392,6 @@ static int lp8860_probe(struct i2c_client *client,
if (!child_node)
return -EINVAL;

- led->led_dev.default_trigger = of_get_property(child_node,
- "linux,default-trigger",
- NULL);
-
led->enable_gpio = devm_gpiod_get_optional(&client->dev,
"enable", GPIOD_OUT_LOW);
if (IS_ERR(led->enable_gpio)) {
diff --git a/drivers/leds/leds-lt3593.c b/drivers/leds/leds-lt3593.c
index 061f02e3995ae..68e06434ac087 100644
--- a/drivers/leds/leds-lt3593.c
+++ b/drivers/leds/leds-lt3593.c
@@ -86,9 +86,6 @@ static int lt3593_led_probe(struct platform_device *pdev)

child = device_get_next_child_node(dev, NULL);

- fwnode_property_read_string(child, "linux,default-trigger",
- &led_data->cdev.default_trigger);
-
if (!fwnode_property_read_string(child, "default-state", &tmp)) {
if (!strcmp(tmp, "on"))
state = LEDS_GPIO_DEFSTATE_ON;
diff --git a/drivers/leds/leds-max77650.c b/drivers/leds/leds-max77650.c
index bed620fc1b82e..169686a205000 100644
--- a/drivers/leds/leds-max77650.c
+++ b/drivers/leds/leds-max77650.c
@@ -100,9 +100,6 @@ static int max77650_led_probe(struct platform_device *pdev)
led->cdev.brightness_set_blocking = max77650_led_brightness_set;
led->cdev.max_brightness = MAX77650_LED_MAX_BRIGHTNESS;

- fwnode_property_read_string(child, "linux,default-trigger",
- &led->cdev.default_trigger);
-
init_data.fwnode = child;
init_data.devicename = "max77650";
/* for backwards compatibility if `label` is not present */
diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c
index 5119dcc0aef24..b46661b4c36b2 100644
--- a/drivers/leds/leds-mt6323.c
+++ b/drivers/leds/leds-mt6323.c
@@ -342,10 +342,6 @@ static int mt6323_led_set_dt_default(struct led_classdev *cdev,
const char *state;
int ret = 0;

- led->cdev.default_trigger = of_get_property(np,
- "linux,default-trigger",
- NULL);
-
state = of_get_property(np, "default-state", NULL);
if (state) {
if (!strcmp(state, "keep")) {
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index b021e94d512c9..d033c4e08d45b 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -189,9 +189,6 @@ static int ns2_led_register(struct device *dev, struct device_node *np,
if (IS_ERR(led->slow))
return PTR_ERR(led->slow);

- of_property_read_string(np, "linux,default-trigger",
- &led->cdev.default_trigger);
-
ret = of_property_count_u32_elems(np, "modes-map");
if (ret < 0 || ret % 3) {
dev_err(dev, "Missing or malformed modes-map for %pOF\n", np);
diff --git a/drivers/leds/leds-pm8058.c b/drivers/leds/leds-pm8058.c
index 80db7e2de420c..bcb0a214f6eff 100644
--- a/drivers/leds/leds-pm8058.c
+++ b/drivers/leds/leds-pm8058.c
@@ -117,8 +117,6 @@ static int pm8058_led_probe(struct platform_device *pdev)
return -EINVAL;
}

- led->cdev.default_trigger =
- of_get_property(np, "linux,default-trigger", NULL);
led->cdev.brightness_set = pm8058_led_set;
led->cdev.brightness_get = pm8058_led_get;
if (led->ledtype == PM8058_LED_TYPE_COMMON)
diff --git a/drivers/leds/leds-tlc591xx.c b/drivers/leds/leds-tlc591xx.c
index 5e84a0c7aacbd..f24271337bd84 100644
--- a/drivers/leds/leds-tlc591xx.c
+++ b/drivers/leds/leds-tlc591xx.c
@@ -199,9 +199,6 @@ tlc591xx_probe(struct i2c_client *client,
led = &priv->leds[reg];

led->active = true;
- led->ldev.default_trigger =
- of_get_property(child, "linux,default-trigger", NULL);
-
led->priv = priv;
led->led_no = reg;
led->ldev.brightness_set_blocking = tlc591xx_brightness_set;
diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index c276969137d7f..ad941dd1484fa 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -121,8 +121,6 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,
cdev->max_brightness = 255;
cdev->brightness_set_blocking = omnia_led_brightness_set_blocking;

- of_property_read_string(np, "linux,default-trigger", &cdev->default_trigger);
-
/* put the LED into software mode */
ret = i2c_smbus_write_byte_data(client, CMD_LED_MODE,
CMD_LED_MODE_LED(led->reg) |
--
2.26.2

2020-09-17 22:36:17

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 47/50] leds: ns2: cosmetic: use reverse christmas tree

Only a cosmetic change: use reverse christmas tree variables
declaration.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index e94bb8535f0a7..40f36c53d9e87 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -50,9 +50,9 @@ struct ns2_led {

static int ns2_led_get_mode(struct ns2_led *led, enum ns2_led_modes *mode)
{
- int i;
- int cmd_level;
int slow_level;
+ int cmd_level;
+ int i;

cmd_level = gpiod_get_value_cansleep(led->cmd);
slow_level = gpiod_get_value_cansleep(led->slow);
@@ -70,8 +70,8 @@ static int ns2_led_get_mode(struct ns2_led *led, enum ns2_led_modes *mode)

static void ns2_led_set_mode(struct ns2_led *led, enum ns2_led_modes mode)
{
- int i;
unsigned long flags;
+ int i;

for (i = 0; i < led->num_modes; i++)
if (mode == led->modval[i].mode)
@@ -123,9 +123,11 @@ static ssize_t ns2_led_sata_store(struct device *dev,
const char *buff, size_t count)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
- struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);
- int ret;
unsigned long enable;
+ struct ns2_led *led;
+ int ret;
+
+ led = container_of(led_cdev, struct ns2_led, cdev);

ret = kstrtoul(buff, 10, &enable);
if (ret < 0)
@@ -154,7 +156,9 @@ static ssize_t ns2_led_sata_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
- struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);
+ struct ns2_led *led;
+
+ led = container_of(led_cdev, struct ns2_led, cdev);

return sprintf(buf, "%d\n", led->sata);
}
--
2.26.2

2020-09-17 22:36:19

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 45/50] leds: ns2: register LED immediately after parsing DT properties

Register each LED immediately after parsing OF properties. This
simplifies the driver.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 143 +++++++++++-----------------------------
1 file changed, 40 insertions(+), 103 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 801b7f851be7a..9d9c9ff4dce61 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -30,20 +30,6 @@ struct ns2_led_modval {
int slow_level;
};

-struct ns2_led_of_one {
- const char *name;
- const char *default_trigger;
- struct gpio_desc *cmd;
- struct gpio_desc *slow;
- int num_modes;
- struct ns2_led_modval *modval;
-};
-
-struct ns2_led_of {
- int num_leds;
- struct ns2_led_of_one *leds;
-};
-
/*
* The Network Space v2 dual-GPIO LED is wired to a CPLD. Three different LED
* modes are available: off, on and SATA activity blinking. The LED modes are
@@ -184,63 +170,29 @@ static struct attribute *ns2_led_attrs[] = {
};
ATTRIBUTE_GROUPS(ns2_led);

-static int
-create_ns2_led(struct device *dev, struct ns2_led *led,
- const struct ns2_led_of_one *template)
-{
- int ret;
- enum ns2_led_modes mode;
-
- rwlock_init(&led->rw_lock);
-
- led->cdev.name = template->name;
- led->cdev.default_trigger = template->default_trigger;
- led->cdev.blink_set = NULL;
- led->cdev.flags |= LED_CORE_SUSPENDRESUME;
- led->cdev.groups = ns2_led_groups;
- led->cmd = template->cmd;
- led->slow = template->slow;
- led->can_sleep = gpiod_cansleep(led->cmd) | gpiod_cansleep(led->slow);
- if (led->can_sleep)
- led->cdev.brightness_set_blocking = ns2_led_set_blocking;
- else
- led->cdev.brightness_set = ns2_led_set;
- led->modval = template->modval;
- led->num_modes = template->num_modes;
-
- ret = ns2_led_get_mode(led, &mode);
- if (ret < 0)
- return ret;
-
- /* Set LED initial state. */
- led->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
- led->cdev.brightness = (mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;
-
- return devm_led_classdev_register(dev, &led->cdev);
-}
-
-static int ns2_leds_parse_one(struct device *dev, struct device_node *np,
- struct ns2_led_of_one *led)
+static int ns2_led_register(struct device *dev, struct device_node *np,
+ struct ns2_led *led)
{
struct ns2_led_modval *modval;
+ enum ns2_led_modes mode;
int nmodes, ret, i;

- ret = of_property_read_string(np, "label", &led->name);
+ ret = of_property_read_string(np, "label", &led->cdev.name);
if (ret)
- led->name = np->name;
+ led->cdev.name = np->name;

led->cmd = devm_gpiod_get_from_of_node(dev, np, "cmd-gpio", 0,
- GPIOD_ASIS, led->name);
+ GPIOD_ASIS, np->name);
if (IS_ERR(led->cmd))
return PTR_ERR(led->cmd);

led->slow = devm_gpiod_get_from_of_node(dev, np, "slow-gpio", 0,
- GPIOD_ASIS, led->name);
+ GPIOD_ASIS, np->name);
if (IS_ERR(led->slow))
return PTR_ERR(led->slow);

of_property_read_string(np, "linux,default-trigger",
- &led->default_trigger);
+ &led->cdev.default_trigger);

ret = of_property_count_u32_elems(np, "modes-map");
if (ret < 0 || ret % 3) {
@@ -264,45 +216,32 @@ static int ns2_leds_parse_one(struct device *dev, struct device_node *np,
modval[i].slow_level = val;
}

+ rwlock_init(&led->rw_lock);
+
+ led->cdev.blink_set = NULL;
+ led->cdev.flags |= LED_CORE_SUSPENDRESUME;
+ led->cdev.groups = ns2_led_groups;
+ led->can_sleep = gpiod_cansleep(led->cmd) || gpiod_cansleep(led->slow);
+ if (led->can_sleep)
+ led->cdev.brightness_set_blocking = ns2_led_set_blocking;
+ else
+ led->cdev.brightness_set = ns2_led_set;
led->num_modes = nmodes;
led->modval = modval;

- return 0;
-}
-
-/*
- * Translate OpenFirmware node properties into platform_data.
- */
-static int
-ns2_leds_parse_of(struct device *dev, struct ns2_led_of *ofdata)
-{
- struct device_node *np = dev_of_node(dev);
- struct device_node *child;
- struct ns2_led_of_one *led, *leds;
- int ret, num_leds = 0;
-
- num_leds = of_get_available_child_count(np);
- if (!num_leds)
- return -ENODEV;
-
- leds = devm_kcalloc(dev, num_leds, sizeof(struct ns2_led),
- GFP_KERNEL);
- if (!leds)
- return -ENOMEM;
+ ret = ns2_led_get_mode(led, &mode);
+ if (ret < 0)
+ return ret;

- led = leds;
- for_each_available_child_of_node(np, child) {
- ret = ns2_leds_parse_one(dev, child, led++);
- if (ret < 0) {
- of_node_put(child);
- return ret;
- }
- }
+ /* Set LED initial state. */
+ led->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
+ led->cdev.brightness = (mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;

- ofdata->leds = leds;
- ofdata->num_leds = num_leds;
+ ret = devm_led_classdev_register(dev, &led->cdev);
+ if (ret)
+ dev_err(dev, "Failed to register LED for node %pOF\n", np);

- return 0;
+ return ret;
}

static const struct of_device_id of_ns2_leds_match[] = {
@@ -314,28 +253,26 @@ MODULE_DEVICE_TABLE(of, of_ns2_leds_match);
static int ns2_led_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct ns2_led_of *ofdata;
+ struct device_node *np, *child;
struct ns2_led *leds;
- int i;
+ int count;
int ret;

- ofdata = devm_kzalloc(dev, sizeof(struct ns2_led_of), GFP_KERNEL);
- if (!ofdata)
- return -ENOMEM;
-
- ret = ns2_leds_parse_of(dev, ofdata);
- if (ret)
- return ret;
+ np = dev_of_node(dev);
+ count = of_get_available_child_count(np);
+ if (!count)
+ return -ENODEV;

- leds = devm_kzalloc(dev, array_size(sizeof(*leds), ofdata->num_leds),
- GFP_KERNEL);
+ leds = devm_kzalloc(dev, array_size(sizeof(*leds), count), GFP_KERNEL);
if (!leds)
return -ENOMEM;

- for (i = 0; i < ofdata->num_leds; i++) {
- ret = create_ns2_led(dev, &leds[i], &ofdata->leds[i]);
- if (ret < 0)
+ for_each_available_child_of_node(np, child) {
+ ret = ns2_led_register(dev, child, leds++);
+ if (ret) {
+ of_node_put(child);
return ret;
+ }
}

return 0;
--
2.26.2

2020-09-17 22:36:29

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 44/50] leds: ns2: cosmetic change: use helper variable

Use helper variable dev instead of always writing &pdev->dev.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 912db40c51183..801b7f851be7a 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -185,7 +185,7 @@ static struct attribute *ns2_led_attrs[] = {
ATTRIBUTE_GROUPS(ns2_led);

static int
-create_ns2_led(struct platform_device *pdev, struct ns2_led *led,
+create_ns2_led(struct device *dev, struct ns2_led *led,
const struct ns2_led_of_one *template)
{
int ret;
@@ -216,7 +216,7 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led *led,
led->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
led->cdev.brightness = (mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;

- return devm_led_classdev_register(&pdev->dev, &led->cdev);
+ return devm_led_classdev_register(dev, &led->cdev);
}

static int ns2_leds_parse_one(struct device *dev, struct device_node *np,
@@ -313,28 +313,27 @@ MODULE_DEVICE_TABLE(of, of_ns2_leds_match);

static int ns2_led_probe(struct platform_device *pdev)
{
+ struct device *dev = &pdev->dev;
struct ns2_led_of *ofdata;
struct ns2_led *leds;
int i;
int ret;

- ofdata = devm_kzalloc(&pdev->dev, sizeof(struct ns2_led_of),
- GFP_KERNEL);
+ ofdata = devm_kzalloc(dev, sizeof(struct ns2_led_of), GFP_KERNEL);
if (!ofdata)
return -ENOMEM;

- ret = ns2_leds_parse_of(&pdev->dev, ofdata);
+ ret = ns2_leds_parse_of(dev, ofdata);
if (ret)
return ret;

- leds = devm_kzalloc(&pdev->dev, array_size(sizeof(*leds),
- ofdata->num_leds),
+ leds = devm_kzalloc(dev, array_size(sizeof(*leds), ofdata->num_leds),
GFP_KERNEL);
if (!leds)
return -ENOMEM;

for (i = 0; i < ofdata->num_leds; i++) {
- ret = create_ns2_led(pdev, &leds[i], &ofdata->leds[i]);
+ ret = create_ns2_led(dev, &leds[i], &ofdata->leds[i]);
if (ret < 0)
return ret;
}
--
2.26.2

2020-09-17 22:36:34

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 48/50] leds: ns2: reorder headers alphabetically

Reorder #includes alphabetically.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 40f36c53d9e87..01c54ab0aa00e 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -9,13 +9,13 @@
* Based on leds-gpio.c by Raphael Assenat <[email protected]>
*/

-#include <linux/kernel.h>
-#include <linux/platform_device.h>
-#include <linux/slab.h>
#include <linux/gpio/consumer.h>
+#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
#include "leds.h"

enum ns2_led_modes {
--
2.26.2

2020-09-17 22:36:42

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 43/50] leds: ns2: cosmetic change

Return directly instead of setting result and breaking.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index dde476420a733..912db40c51183 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -65,7 +65,6 @@ struct ns2_led {
static int ns2_led_get_mode(struct ns2_led *led, enum ns2_led_modes *mode)
{
int i;
- int ret = -EINVAL;
int cmd_level;
int slow_level;

@@ -76,12 +75,11 @@ static int ns2_led_get_mode(struct ns2_led *led, enum ns2_led_modes *mode)
if (cmd_level == led->modval[i].cmd_level &&
slow_level == led->modval[i].slow_level) {
*mode = led->modval[i].mode;
- ret = 0;
- break;
+ return 0;
}
}

- return ret;
+ return -EINVAL;
}

static void ns2_led_set_mode(struct ns2_led *led, enum ns2_led_modes mode)
--
2.26.2

2020-09-17 22:36:50

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 46/50] leds: ns2: remove unneeded variable

No need to use variable found, we can determine whether the mode was
found by comparing iterator variable to its limit.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 9d9c9ff4dce61..e94bb8535f0a7 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -71,16 +71,13 @@ static int ns2_led_get_mode(struct ns2_led *led, enum ns2_led_modes *mode)
static void ns2_led_set_mode(struct ns2_led *led, enum ns2_led_modes mode)
{
int i;
- bool found = false;
unsigned long flags;

for (i = 0; i < led->num_modes; i++)
- if (mode == led->modval[i].mode) {
- found = true;
+ if (mode == led->modval[i].mode)
break;
- }

- if (!found)
+ if (i == led->num_modes)
return;

write_lock_irqsave(&led->rw_lock, flags);
--
2.26.2

2020-09-17 22:36:58

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 42/50] leds: ns2: cosmetic variable rename

Rename variable led_dat to led in various functions.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 103 ++++++++++++++++++----------------------
1 file changed, 47 insertions(+), 56 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 6dba6208433ca..dde476420a733 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -62,21 +62,20 @@ struct ns2_led {
struct ns2_led_modval *modval;
};

-static int ns2_led_get_mode(struct ns2_led *led_dat,
- enum ns2_led_modes *mode)
+static int ns2_led_get_mode(struct ns2_led *led, enum ns2_led_modes *mode)
{
int i;
int ret = -EINVAL;
int cmd_level;
int slow_level;

- cmd_level = gpiod_get_value_cansleep(led_dat->cmd);
- slow_level = gpiod_get_value_cansleep(led_dat->slow);
+ cmd_level = gpiod_get_value_cansleep(led->cmd);
+ slow_level = gpiod_get_value_cansleep(led->slow);

- for (i = 0; i < led_dat->num_modes; i++) {
- if (cmd_level == led_dat->modval[i].cmd_level &&
- slow_level == led_dat->modval[i].slow_level) {
- *mode = led_dat->modval[i].mode;
+ for (i = 0; i < led->num_modes; i++) {
+ if (cmd_level == led->modval[i].cmd_level &&
+ slow_level == led->modval[i].slow_level) {
+ *mode = led->modval[i].mode;
ret = 0;
break;
}
@@ -85,15 +84,14 @@ static int ns2_led_get_mode(struct ns2_led *led_dat,
return ret;
}

-static void ns2_led_set_mode(struct ns2_led *led_dat,
- enum ns2_led_modes mode)
+static void ns2_led_set_mode(struct ns2_led *led, enum ns2_led_modes mode)
{
int i;
bool found = false;
unsigned long flags;

- for (i = 0; i < led_dat->num_modes; i++)
- if (mode == led_dat->modval[i].mode) {
+ for (i = 0; i < led->num_modes; i++)
+ if (mode == led->modval[i].mode) {
found = true;
break;
}
@@ -101,38 +99,35 @@ static void ns2_led_set_mode(struct ns2_led *led_dat,
if (!found)
return;

- write_lock_irqsave(&led_dat->rw_lock, flags);
+ write_lock_irqsave(&led->rw_lock, flags);

- if (!led_dat->can_sleep) {
- gpiod_set_value(led_dat->cmd,
- led_dat->modval[i].cmd_level);
- gpiod_set_value(led_dat->slow,
- led_dat->modval[i].slow_level);
+ if (!led->can_sleep) {
+ gpiod_set_value(led->cmd, led->modval[i].cmd_level);
+ gpiod_set_value(led->slow, led->modval[i].slow_level);
goto exit_unlock;
}

- gpiod_set_value_cansleep(led_dat->cmd, led_dat->modval[i].cmd_level);
- gpiod_set_value_cansleep(led_dat->slow, led_dat->modval[i].slow_level);
+ gpiod_set_value_cansleep(led->cmd, led->modval[i].cmd_level);
+ gpiod_set_value_cansleep(led->slow, led->modval[i].slow_level);

exit_unlock:
- write_unlock_irqrestore(&led_dat->rw_lock, flags);
+ write_unlock_irqrestore(&led->rw_lock, flags);
}

static void ns2_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
- struct ns2_led *led_dat =
- container_of(led_cdev, struct ns2_led, cdev);
+ struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);
enum ns2_led_modes mode;

if (value == LED_OFF)
mode = NS_V2_LED_OFF;
- else if (led_dat->sata)
+ else if (led->sata)
mode = NS_V2_LED_SATA;
else
mode = NS_V2_LED_ON;

- ns2_led_set_mode(led_dat, mode);
+ ns2_led_set_mode(led, mode);
}

static int ns2_led_set_blocking(struct led_classdev *led_cdev,
@@ -147,8 +142,7 @@ static ssize_t ns2_led_sata_store(struct device *dev,
const char *buff, size_t count)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
- struct ns2_led *led_dat =
- container_of(led_cdev, struct ns2_led, cdev);
+ struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);
int ret;
unsigned long enable;

@@ -158,18 +152,18 @@ static ssize_t ns2_led_sata_store(struct device *dev,

enable = !!enable;

- if (led_dat->sata == enable)
+ if (led->sata == enable)
goto exit;

- led_dat->sata = enable;
+ led->sata = enable;

if (!led_get_brightness(led_cdev))
goto exit;

if (enable)
- ns2_led_set_mode(led_dat, NS_V2_LED_SATA);
+ ns2_led_set_mode(led, NS_V2_LED_SATA);
else
- ns2_led_set_mode(led_dat, NS_V2_LED_ON);
+ ns2_led_set_mode(led, NS_V2_LED_ON);

exit:
return count;
@@ -179,10 +173,9 @@ static ssize_t ns2_led_sata_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
- struct ns2_led *led_dat =
- container_of(led_cdev, struct ns2_led, cdev);
+ struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);

- return sprintf(buf, "%d\n", led_dat->sata);
+ return sprintf(buf, "%d\n", led->sata);
}

static DEVICE_ATTR(sata, 0644, ns2_led_sata_show, ns2_led_sata_store);
@@ -194,40 +187,38 @@ static struct attribute *ns2_led_attrs[] = {
ATTRIBUTE_GROUPS(ns2_led);

static int
-create_ns2_led(struct platform_device *pdev, struct ns2_led *led_dat,
+create_ns2_led(struct platform_device *pdev, struct ns2_led *led,
const struct ns2_led_of_one *template)
{
int ret;
enum ns2_led_modes mode;

- rwlock_init(&led_dat->rw_lock);
-
- led_dat->cdev.name = template->name;
- led_dat->cdev.default_trigger = template->default_trigger;
- led_dat->cdev.blink_set = NULL;
- led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
- led_dat->cdev.groups = ns2_led_groups;
- led_dat->cmd = template->cmd;
- led_dat->slow = template->slow;
- led_dat->can_sleep = gpiod_cansleep(led_dat->cmd) |
- gpiod_cansleep(led_dat->slow);
- if (led_dat->can_sleep)
- led_dat->cdev.brightness_set_blocking = ns2_led_set_blocking;
+ rwlock_init(&led->rw_lock);
+
+ led->cdev.name = template->name;
+ led->cdev.default_trigger = template->default_trigger;
+ led->cdev.blink_set = NULL;
+ led->cdev.flags |= LED_CORE_SUSPENDRESUME;
+ led->cdev.groups = ns2_led_groups;
+ led->cmd = template->cmd;
+ led->slow = template->slow;
+ led->can_sleep = gpiod_cansleep(led->cmd) | gpiod_cansleep(led->slow);
+ if (led->can_sleep)
+ led->cdev.brightness_set_blocking = ns2_led_set_blocking;
else
- led_dat->cdev.brightness_set = ns2_led_set;
- led_dat->modval = template->modval;
- led_dat->num_modes = template->num_modes;
+ led->cdev.brightness_set = ns2_led_set;
+ led->modval = template->modval;
+ led->num_modes = template->num_modes;

- ret = ns2_led_get_mode(led_dat, &mode);
+ ret = ns2_led_get_mode(led, &mode);
if (ret < 0)
return ret;

/* Set LED initial state. */
- led_dat->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
- led_dat->cdev.brightness =
- (mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;
+ led->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
+ led->cdev.brightness = (mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;

- return devm_led_classdev_register(&pdev->dev, &led_dat->cdev);
+ return devm_led_classdev_register(&pdev->dev, &led->cdev);
}

static int ns2_leds_parse_one(struct device *dev, struct device_node *np,
--
2.26.2

2020-09-17 22:37:10

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 41/50] leds: ns2: cosmetic structure rename

Rename structures:
ns2_led -> ns2_led_of_one
ns2_led_data -> ns2_led.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index fa06ab40ee143..6dba6208433ca 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -30,7 +30,7 @@ struct ns2_led_modval {
int slow_level;
};

-struct ns2_led {
+struct ns2_led_of_one {
const char *name;
const char *default_trigger;
struct gpio_desc *cmd;
@@ -40,8 +40,8 @@ struct ns2_led {
};

struct ns2_led_of {
- int num_leds;
- struct ns2_led *leds;
+ int num_leds;
+ struct ns2_led_of_one *leds;
};

/*
@@ -51,7 +51,7 @@ struct ns2_led_of {
* for the command/slow GPIOs corresponds to a LED mode.
*/

-struct ns2_led_data {
+struct ns2_led {
struct led_classdev cdev;
struct gpio_desc *cmd;
struct gpio_desc *slow;
@@ -62,7 +62,7 @@ struct ns2_led_data {
struct ns2_led_modval *modval;
};

-static int ns2_led_get_mode(struct ns2_led_data *led_dat,
+static int ns2_led_get_mode(struct ns2_led *led_dat,
enum ns2_led_modes *mode)
{
int i;
@@ -85,7 +85,7 @@ static int ns2_led_get_mode(struct ns2_led_data *led_dat,
return ret;
}

-static void ns2_led_set_mode(struct ns2_led_data *led_dat,
+static void ns2_led_set_mode(struct ns2_led *led_dat,
enum ns2_led_modes mode)
{
int i;
@@ -121,8 +121,8 @@ static void ns2_led_set_mode(struct ns2_led_data *led_dat,
static void ns2_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
- struct ns2_led_data *led_dat =
- container_of(led_cdev, struct ns2_led_data, cdev);
+ struct ns2_led *led_dat =
+ container_of(led_cdev, struct ns2_led, cdev);
enum ns2_led_modes mode;

if (value == LED_OFF)
@@ -147,8 +147,8 @@ static ssize_t ns2_led_sata_store(struct device *dev,
const char *buff, size_t count)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
- struct ns2_led_data *led_dat =
- container_of(led_cdev, struct ns2_led_data, cdev);
+ struct ns2_led *led_dat =
+ container_of(led_cdev, struct ns2_led, cdev);
int ret;
unsigned long enable;

@@ -179,8 +179,8 @@ static ssize_t ns2_led_sata_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
- struct ns2_led_data *led_dat =
- container_of(led_cdev, struct ns2_led_data, cdev);
+ struct ns2_led *led_dat =
+ container_of(led_cdev, struct ns2_led, cdev);

return sprintf(buf, "%d\n", led_dat->sata);
}
@@ -194,8 +194,8 @@ static struct attribute *ns2_led_attrs[] = {
ATTRIBUTE_GROUPS(ns2_led);

static int
-create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
- const struct ns2_led *template)
+create_ns2_led(struct platform_device *pdev, struct ns2_led *led_dat,
+ const struct ns2_led_of_one *template)
{
int ret;
enum ns2_led_modes mode;
@@ -231,7 +231,7 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
}

static int ns2_leds_parse_one(struct device *dev, struct device_node *np,
- struct ns2_led *led)
+ struct ns2_led_of_one *led)
{
struct ns2_led_modval *modval;
int nmodes, ret, i;
@@ -289,7 +289,7 @@ ns2_leds_parse_of(struct device *dev, struct ns2_led_of *ofdata)
{
struct device_node *np = dev_of_node(dev);
struct device_node *child;
- struct ns2_led *led, *leds;
+ struct ns2_led_of_one *led, *leds;
int ret, num_leds = 0;

num_leds = of_get_available_child_count(np);
@@ -325,7 +325,7 @@ MODULE_DEVICE_TABLE(of, of_ns2_leds_match);
static int ns2_led_probe(struct platform_device *pdev)
{
struct ns2_led_of *ofdata;
- struct ns2_led_data *leds;
+ struct ns2_led *leds;
int i;
int ret;

--
2.26.2

2020-09-17 22:37:14

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 39/50] leds: ns2: move parsing of one LED into separate function

Move parsing of DT properties of one LED into separate function. This
saves indentation level and is nicer to read.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 120 ++++++++++++++++++----------------------
1 file changed, 55 insertions(+), 65 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 0e9c2f49b6350..46d4f7e963c04 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -230,6 +230,57 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
return devm_led_classdev_register(&pdev->dev, &led_dat->cdev);
}

+static int ns2_leds_parse_one(struct device *dev, struct device_node *np,
+ struct ns2_led *led)
+{
+ struct ns2_led_modval *modval;
+ int nmodes, ret, i;
+
+ ret = of_property_read_string(np, "label", &led->name);
+ if (ret)
+ led->name = np->name;
+
+ led->cmd = gpiod_get_from_of_node(np, "cmd-gpio", 0, GPIOD_ASIS,
+ led->name);
+ if (IS_ERR(led->cmd))
+ return PTR_ERR(led->cmd);
+
+ led->slow = gpiod_get_from_of_node(np, "slow-gpio", 0, GPIOD_ASIS,
+ led->name);
+ if (IS_ERR(led->slow))
+ return PTR_ERR(led->slow);
+
+ of_property_read_string(np, "linux,default-trigger",
+ &led->default_trigger);
+
+ ret = of_property_count_u32_elems(np, "modes-map");
+ if (ret < 0 || ret % 3) {
+ dev_err(dev, "Missing or malformed modes-map for %pOF\n", np);
+ return -EINVAL;
+ }
+
+ nmodes = ret / 3;
+ modval = devm_kcalloc(dev, nmodes, sizeof(*modval), GFP_KERNEL);
+ if (!modval)
+ return -ENOMEM;
+
+ for (i = 0; i < nmodes; i++) {
+ u32 val;
+
+ of_property_read_u32_index(np, "modes-map", 3 * i, &val);
+ modval[i].mode = val;
+ of_property_read_u32_index(np, "modes-map", 3 * i + 1, &val);
+ modval[i].cmd_level = val;
+ of_property_read_u32_index(np, "modes-map", 3 * i + 2, &val);
+ modval[i].slow_level = val;
+ }
+
+ led->num_modes = nmodes;
+ led->modval = modval;
+
+ return 0;
+}
+
/*
* Translate OpenFirmware node properties into platform_data.
*/
@@ -252,78 +303,17 @@ ns2_leds_parse_of(struct device *dev, struct ns2_led_of *ofdata)

led = leds;
for_each_available_child_of_node(np, child) {
- const char *string;
- int i, num_modes;
- struct ns2_led_modval *modval;
- struct gpio_desc *gd;
-
- ret = of_property_read_string(child, "label", &string);
- led->name = (ret == 0) ? string : child->name;
-
- gd = gpiod_get_from_of_node(child, "cmd-gpio", 0,
- GPIOD_ASIS, led->name);
- if (IS_ERR(gd)) {
- ret = PTR_ERR(gd);
- goto err_node_put;
- }
- led->cmd = gd;
- gd = gpiod_get_from_of_node(child, "slow-gpio", 0,
- GPIOD_ASIS, led->name);
- if (IS_ERR(gd)) {
- ret = PTR_ERR(gd);
- goto err_node_put;
- }
- led->slow = gd;
-
- ret = of_property_read_string(child, "linux,default-trigger",
- &string);
- if (ret == 0)
- led->default_trigger = string;
-
- ret = of_property_count_u32_elems(child, "modes-map");
- if (ret < 0 || ret % 3) {
- dev_err(dev,
- "Missing or malformed modes-map property\n");
- ret = -EINVAL;
- goto err_node_put;
- }
-
- num_modes = ret / 3;
- modval = devm_kcalloc(dev,
- num_modes,
- sizeof(struct ns2_led_modval),
- GFP_KERNEL);
- if (!modval) {
- ret = -ENOMEM;
- goto err_node_put;
- }
-
- for (i = 0; i < num_modes; i++) {
- of_property_read_u32_index(child,
- "modes-map", 3 * i,
- (u32 *) &modval[i].mode);
- of_property_read_u32_index(child,
- "modes-map", 3 * i + 1,
- (u32 *) &modval[i].cmd_level);
- of_property_read_u32_index(child,
- "modes-map", 3 * i + 2,
- (u32 *) &modval[i].slow_level);
+ ret = ns2_leds_parse_one(dev, child, led++);
+ if (ret < 0) {
+ of_node_put(child);
+ return ret;
}
-
- led->num_modes = num_modes;
- led->modval = modval;
-
- led++;
}

ofdata->leds = leds;
ofdata->num_leds = num_leds;

return 0;
-
-err_node_put:
- of_node_put(child);
- return ret;
}

static const struct of_device_id of_ns2_leds_match[] = {
--
2.26.2

2020-09-17 22:37:20

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 26/50] leds: is31fl319x: don't store shutdown gpio descriptor

Since the shutdown gpio descriptor is only accessed in device probe
method there is no need to store it in the private structure.

Signed-off-by: Marek Behún <[email protected]>
Cc: H. Nikolaus Schaller <[email protected]>
Cc: Grant Feng <[email protected]>
---
drivers/leds/leds-is31fl319x.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c
index ba1a5da5521b5..595112958617e 100644
--- a/drivers/leds/leds-is31fl319x.c
+++ b/drivers/leds/leds-is31fl319x.c
@@ -63,7 +63,6 @@
struct is31fl319x_chip {
const struct is31fl319x_chipdef *cdef;
struct i2c_client *client;
- struct gpio_desc *shutdown_gpio;
struct regmap *regmap;
struct mutex lock;
u32 audio_gain_db;
@@ -227,15 +226,6 @@ static int is31fl319x_parse_dt(struct device *dev,
if (!np)
return -ENODEV;

- is31->shutdown_gpio = devm_gpiod_get_optional(dev,
- "shutdown",
- GPIOD_OUT_HIGH);
- if (IS_ERR(is31->shutdown_gpio)) {
- ret = PTR_ERR(is31->shutdown_gpio);
- dev_err(dev, "Failed to get shutdown gpio: %d\n", ret);
- return ret;
- }
-
is31->cdef = device_get_match_data(dev);

count = of_get_available_child_count(np);
@@ -355,6 +345,7 @@ static int is31fl319x_probe(struct i2c_client *client,
{
struct is31fl319x_chip *is31;
struct device *dev = &client->dev;
+ struct gpio_desc *shutdown_gpio;
int err;
int i = 0;
u32 aggregated_led_microamp;
@@ -375,18 +366,26 @@ static int is31fl319x_probe(struct i2c_client *client,
if (!is31)
return -ENOMEM;

+ shutdown_gpio = gpiod_get_optional(dev, "shutdown", GPIOD_OUT_HIGH);
+ if (IS_ERR(shutdown_gpio)) {
+ err = PTR_ERR(shutdown_gpio);
+ dev_err(dev, "Failed to get shutdown gpio: %d\n", err);
+ return err;
+ }
+
+ if (shutdown_gpio) {
+ gpiod_direction_output(shutdown_gpio, 0);
+ mdelay(5);
+ gpiod_direction_output(shutdown_gpio, 1);
+ gpiod_put(shutdown_gpio);
+ }
+
mutex_init(&is31->lock);

err = is31fl319x_parse_dt(&client->dev, is31);
if (err)
goto free_mutex;

- if (is31->shutdown_gpio) {
- gpiod_direction_output(is31->shutdown_gpio, 0);
- mdelay(5);
- gpiod_direction_output(is31->shutdown_gpio, 1);
- }
-
is31->client = client;
is31->regmap = devm_regmap_init_i2c(client, &regmap_config);
if (IS_ERR(is31->regmap)) {
--
2.26.2

2020-09-17 22:37:25

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 40/50] leds: ns2: use devres API for getting GPIO descriptors

This drivers leaks GPIO descriptors on driver removal. Use devres API
function devm_gpiod_get_from_of_node instead of gpiod_get_from_of_node
to avoid this.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 46d4f7e963c04..fa06ab40ee143 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -240,13 +240,13 @@ static int ns2_leds_parse_one(struct device *dev, struct device_node *np,
if (ret)
led->name = np->name;

- led->cmd = gpiod_get_from_of_node(np, "cmd-gpio", 0, GPIOD_ASIS,
- led->name);
+ led->cmd = devm_gpiod_get_from_of_node(dev, np, "cmd-gpio", 0,
+ GPIOD_ASIS, led->name);
if (IS_ERR(led->cmd))
return PTR_ERR(led->cmd);

- led->slow = gpiod_get_from_of_node(np, "slow-gpio", 0, GPIOD_ASIS,
- led->name);
+ led->slow = devm_gpiod_get_from_of_node(dev, np, "slow-gpio", 0,
+ GPIOD_ASIS, led->name);
if (IS_ERR(led->slow))
return PTR_ERR(led->slow);

--
2.26.2

2020-09-17 22:37:26

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 36/50] leds: ns2: use devres LED registering function

By using devres version of LED registering function we can remove the
.remove method from this driver. The probe method also gets simpler.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 30 ++----------------------------
1 file changed, 2 insertions(+), 28 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 22d38c83b6dca..1a7ef66464b5d 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -227,16 +227,7 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
led_dat->cdev.brightness =
(mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;

- ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
- if (ret < 0)
- return ret;
-
- return 0;
-}
-
-static void delete_ns2_led(struct ns2_led_data *led_dat)
-{
- led_classdev_unregister(&led_dat->cdev);
+ return devm_led_classdev_register(&pdev->dev, &led_dat->cdev);
}

#ifdef CONFIG_OF_GPIO
@@ -380,11 +371,8 @@ static int ns2_led_probe(struct platform_device *pdev)
for (i = 0; i < priv->num_leds; i++) {
ret = create_ns2_led(pdev, &priv->leds_data[i],
&pdata->leds[i]);
- if (ret < 0) {
- for (i = i - 1; i >= 0; i--)
- delete_ns2_led(&priv->leds_data[i]);
+ if (ret < 0)
return ret;
- }
}

platform_set_drvdata(pdev, priv);
@@ -392,22 +380,8 @@ static int ns2_led_probe(struct platform_device *pdev)
return 0;
}

-static int ns2_led_remove(struct platform_device *pdev)
-{
- int i;
- struct ns2_led_priv *priv;
-
- priv = platform_get_drvdata(pdev);
-
- for (i = 0; i < priv->num_leds; i++)
- delete_ns2_led(&priv->leds_data[i]);
-
- return 0;
-}
-
static struct platform_driver ns2_led_driver = {
.probe = ns2_led_probe,
- .remove = ns2_led_remove,
.driver = {
.name = "leds-ns2",
.of_match_table = of_match_ptr(of_ns2_leds_match),
--
2.26.2

2020-09-17 22:37:34

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 35/50] leds: lm36274: do not set chip settings in DT parsing function

These settings are not parsed from DT and therefore semantically should
not be set in function with a name lm36274_parse_dt.

Signed-off-by: Marek Behún <[email protected]>
Cc: Dan Murphy <[email protected]>
---
drivers/leds/leds-lm36274.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c
index 294edcc054bea..b61c97ed26603 100644
--- a/drivers/leds/leds-lm36274.c
+++ b/drivers/leds/leds-lm36274.c
@@ -100,14 +100,6 @@ static int lm36274_parse_dt(struct lm36274 *chip,
fwnode_property_read_string(child, "linux,default-trigger",
&chip->led_dev.default_trigger);

- chip->lmu_data.regmap = chip->regmap;
- chip->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
- chip->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;
- chip->lmu_data.lsb_brightness_reg = LM36274_REG_BRT_LSB;
-
- chip->led_dev.max_brightness = MAX_BRIGHTNESS_11BIT;
- chip->led_dev.brightness_set_blocking = lm36274_brightness_set;
-
return 0;
err:
fwnode_handle_put(child);
@@ -142,6 +134,14 @@ static int lm36274_probe(struct platform_device *pdev)
return ret;
}

+ chip->lmu_data.regmap = chip->regmap;
+ chip->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
+ chip->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;
+ chip->lmu_data.lsb_brightness_reg = LM36274_REG_BRT_LSB;
+
+ chip->led_dev.max_brightness = MAX_BRIGHTNESS_11BIT;
+ chip->led_dev.brightness_set_blocking = lm36274_brightness_set;
+
ret = devm_led_classdev_register_ext(chip->dev, &chip->led_dev,
&init_data);
if (ret)
--
2.26.2

2020-09-17 22:37:39

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 27/50] leds: is31fl319x: don't store audio gain value, simply set it

Since this value is only used in device probe, don't store it in private
structure. Simply parse the value and set it.

Signed-off-by: Marek Behún <[email protected]>
Cc: H. Nikolaus Schaller <[email protected]>
Cc: Grant Feng <[email protected]>
---
drivers/leds/leds-is31fl319x.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c
index 595112958617e..8e3e02d959989 100644
--- a/drivers/leds/leds-is31fl319x.c
+++ b/drivers/leds/leds-is31fl319x.c
@@ -65,7 +65,6 @@ struct is31fl319x_chip {
struct i2c_client *client;
struct regmap *regmap;
struct mutex lock;
- u32 audio_gain_db;

struct is31fl319x_led {
struct is31fl319x_chip *chip;
@@ -198,6 +197,18 @@ static int is31fl319x_parse_max_current(struct device *dev, u32 *aggregated)
return 0;
}

+static u32 is31fl319x_parse_audio_gain(struct device *dev)
+{
+ u32 result;
+
+ if (!of_property_read_u32(dev_of_node(dev), "audio-gain-db", &result))
+ result = min(result, IS31FL319X_AUDIO_GAIN_DB_MAX);
+ else
+ result = 0;
+
+ return result;;
+}
+
static int is31fl319x_parse_child_dt(const struct device *dev,
const struct device_node *child,
struct is31fl319x_led *led)
@@ -271,12 +282,6 @@ static int is31fl319x_parse_dt(struct device *dev,
led->configured = true;
}

- is31->audio_gain_db = 0;
- ret = of_property_read_u32(np, "audio-gain-db", &is31->audio_gain_db);
- if (!ret)
- is31->audio_gain_db = min(is31->audio_gain_db,
- IS31FL319X_AUDIO_GAIN_DB_MAX);
-
return 0;

put_child_node:
@@ -346,6 +351,7 @@ static int is31fl319x_probe(struct i2c_client *client,
struct is31fl319x_chip *is31;
struct device *dev = &client->dev;
struct gpio_desc *shutdown_gpio;
+ u32 audio_gain_db;
int err;
int i = 0;
u32 aggregated_led_microamp;
@@ -405,9 +411,11 @@ static int is31fl319x_probe(struct i2c_client *client,
goto free_mutex;
}

+ audio_gain_db = is31fl319x_parse_audio_gain(dev);
+
regmap_write(is31->regmap, IS31FL319X_CONFIG2,
is31fl319x_microamp_to_cs(dev, aggregated_led_microamp) |
- is31fl319x_db_to_gain(is31->audio_gain_db));
+ is31fl319x_db_to_gain(audio_gain_db));

for (i = 0; i < is31->cdef->num_leds; i++) {
struct is31fl319x_led *led = &is31->leds[i];
--
2.26.2

2020-09-17 22:37:50

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 32/50] leds: lm36274: cosmetic: rename lm36274_data to chip

Rename this variable so that it is easier to read and easier to write in
80 columns.

Signed-off-by: Marek Behún <[email protected]>
Cc: Dan Murphy <[email protected]>
---
drivers/leds/leds-lm36274.c | 73 ++++++++++++++++++-------------------
1 file changed, 35 insertions(+), 38 deletions(-)

diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c
index 1390c71267cc2..2569659836e8f 100644
--- a/drivers/leds/leds-lm36274.c
+++ b/drivers/leds/leds-lm36274.c
@@ -48,30 +48,29 @@ static int lm36274_brightness_set(struct led_classdev *led_cdev,
return ti_lmu_common_set_brightness(&led->lmu_data, brt_val);
}

-static int lm36274_init(struct lm36274 *lm36274_data)
+static int lm36274_init(struct lm36274 *chip)
{
int enable_val = 0;
int i;

- for (i = 0; i < lm36274_data->num_leds; i++)
- enable_val |= (1 << lm36274_data->led_sources[i]);
+ for (i = 0; i < chip->num_leds; i++)
+ enable_val |= (1 << chip->led_sources[i]);

if (!enable_val) {
- dev_err(lm36274_data->dev, "No LEDs were enabled\n");
+ dev_err(chip->dev, "No LEDs were enabled\n");
return -EINVAL;
}

enable_val |= LM36274_BL_EN;

- return regmap_write(lm36274_data->regmap, LM36274_REG_BL_EN,
- enable_val);
+ return regmap_write(chip->regmap, LM36274_REG_BL_EN, enable_val);
}

-static int lm36274_parse_dt(struct lm36274 *lm36274_data)
+static int lm36274_parse_dt(struct lm36274 *chip)
{
struct fwnode_handle *child = NULL;
char label[LED_MAX_NAME_SIZE];
- struct device *dev = &lm36274_data->pdev->dev;
+ struct device *dev = &chip->pdev->dev;
const char *name;
int child_cnt;
int ret = -EINVAL;
@@ -84,37 +83,37 @@ static int lm36274_parse_dt(struct lm36274 *lm36274_data)
device_for_each_child_node(dev, child) {
ret = fwnode_property_read_string(child, "label", &name);
if (ret)
- snprintf(label, sizeof(label),
- "%s::", lm36274_data->pdev->name);
+ snprintf(label, sizeof(label), "%s::",
+ chip->pdev->name);
else
- snprintf(label, sizeof(label),
- "%s:%s", lm36274_data->pdev->name, name);
+ snprintf(label, sizeof(label), "%s:%s", chip->pdev->name,
+ name);

- lm36274_data->num_leds = fwnode_property_count_u32(child, "led-sources");
- if (lm36274_data->num_leds <= 0)
+ chip->num_leds = fwnode_property_count_u32(child, "led-sources");
+ if (chip->num_leds <= 0)
return -ENODEV;

ret = fwnode_property_read_u32_array(child, "led-sources",
- lm36274_data->led_sources,
- lm36274_data->num_leds);
+ chip->led_sources,
+ chip->num_leds);
if (ret) {
dev_err(dev, "led-sources property missing\n");
return ret;
}

fwnode_property_read_string(child, "linux,default-trigger",
- &lm36274_data->led_dev.default_trigger);
+ &chip->led_dev.default_trigger);

}

- lm36274_data->lmu_data.regmap = lm36274_data->regmap;
- lm36274_data->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
- lm36274_data->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;
- lm36274_data->lmu_data.lsb_brightness_reg = LM36274_REG_BRT_LSB;
+ chip->lmu_data.regmap = chip->regmap;
+ chip->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
+ chip->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;
+ chip->lmu_data.lsb_brightness_reg = LM36274_REG_BRT_LSB;

- lm36274_data->led_dev.name = label;
- lm36274_data->led_dev.max_brightness = MAX_BRIGHTNESS_11BIT;
- lm36274_data->led_dev.brightness_set_blocking = lm36274_brightness_set;
+ chip->led_dev.name = label;
+ chip->led_dev.max_brightness = MAX_BRIGHTNESS_11BIT;
+ chip->led_dev.brightness_set_blocking = lm36274_brightness_set;

return 0;
}
@@ -122,33 +121,31 @@ static int lm36274_parse_dt(struct lm36274 *lm36274_data)
static int lm36274_probe(struct platform_device *pdev)
{
struct ti_lmu *lmu = dev_get_drvdata(pdev->dev.parent);
- struct lm36274 *lm36274_data;
+ struct lm36274 *chip;
int ret;

- lm36274_data = devm_kzalloc(&pdev->dev, sizeof(*lm36274_data),
- GFP_KERNEL);
- if (!lm36274_data)
+ chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
+ if (!chip)
return -ENOMEM;

- lm36274_data->pdev = pdev;
- lm36274_data->dev = lmu->dev;
- lm36274_data->regmap = lmu->regmap;
- platform_set_drvdata(pdev, lm36274_data);
+ chip->pdev = pdev;
+ chip->dev = lmu->dev;
+ chip->regmap = lmu->regmap;
+ platform_set_drvdata(pdev, chip);

- ret = lm36274_parse_dt(lm36274_data);
+ ret = lm36274_parse_dt(chip);
if (ret) {
- dev_err(lm36274_data->dev, "Failed to parse DT node\n");
+ dev_err(chip->dev, "Failed to parse DT node\n");
return ret;
}

- ret = lm36274_init(lm36274_data);
+ ret = lm36274_init(chip);
if (ret) {
- dev_err(lm36274_data->dev, "Failed to init the device\n");
+ dev_err(chip->dev, "Failed to init the device\n");
return ret;
}

- return devm_led_classdev_register(lm36274_data->dev,
- &lm36274_data->led_dev);
+ return devm_led_classdev_register(chip->dev, &chip->led_dev);
}

static const struct of_device_id of_lm36274_leds_match[] = {
--
2.26.2

2020-09-17 22:37:50

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 15/50] leds: lm3697: cosmetic change: use helper variable, reverse christmas tree

Use helper variable dev instead of always writing &client->dev, or
&priv->client->dev, or even &led->priv->client->dev.

With one more line moved reverse christmas tree is also achieved.

Signed-off-by: Marek Behún <[email protected]>
Cc: Dan Murphy <[email protected]>
---
drivers/leds/leds-lm3697.c | 75 ++++++++++++++++++--------------------
1 file changed, 36 insertions(+), 39 deletions(-)

diff --git a/drivers/leds/leds-lm3697.c b/drivers/leds/leds-lm3697.c
index 479776ac36c35..0c5c29730c407 100644
--- a/drivers/leds/leds-lm3697.c
+++ b/drivers/leds/leds-lm3697.c
@@ -115,6 +115,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev,
struct lm3697_led *led = container_of(led_cdev, struct lm3697_led,
led_dev);
int ctrl_en_val = (1 << led->control_bank);
+ struct device *dev = led->priv->dev;
int ret;

mutex_lock(&led->priv->lock);
@@ -123,7 +124,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev,
ret = regmap_update_bits(led->priv->regmap, LM3697_CTRL_ENABLE,
ctrl_en_val, ~ctrl_en_val);
if (ret) {
- dev_err(&led->priv->client->dev, "Cannot write ctrl register\n");
+ dev_err(dev, "Cannot write ctrl register\n");
goto brightness_out;
}

@@ -131,8 +132,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev,
} else {
ret = ti_lmu_common_set_brightness(&led->lmu_data, brt_val);
if (ret) {
- dev_err(&led->priv->client->dev,
- "Cannot write brightness\n");
+ dev_err(dev, "Cannot write brightness\n");
goto brightness_out;
}

@@ -141,8 +141,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev,
LM3697_CTRL_ENABLE,
ctrl_en_val, ctrl_en_val);
if (ret) {
- dev_err(&led->priv->client->dev,
- "Cannot enable the device\n");
+ dev_err(dev, "Cannot enable the device\n");
goto brightness_out;
}

@@ -157,6 +156,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev,

static int lm3697_init(struct lm3697 *priv)
{
+ struct device *dev = priv->dev;
struct lm3697_led *led;
int i, ret;

@@ -165,26 +165,26 @@ static int lm3697_init(struct lm3697 *priv)
} else {
ret = regmap_write(priv->regmap, LM3697_RESET, LM3697_SW_RESET);
if (ret) {
- dev_err(&priv->client->dev, "Cannot reset the device\n");
+ dev_err(dev, "Cannot reset the device\n");
goto out;
}
}

ret = regmap_write(priv->regmap, LM3697_CTRL_ENABLE, 0x0);
if (ret) {
- dev_err(&priv->client->dev, "Cannot write ctrl enable\n");
+ dev_err(dev, "Cannot write ctrl enable\n");
goto out;
}

ret = regmap_write(priv->regmap, LM3697_OUTPUT_CONFIG, priv->bank_cfg);
if (ret)
- dev_err(&priv->client->dev, "Cannot write OUTPUT config\n");
+ dev_err(dev, "Cannot write OUTPUT config\n");

for (i = 0; i < LM3697_MAX_CONTROL_BANKS; i++) {
led = &priv->leds[i];
ret = ti_lmu_common_set_ramp(&led->lmu_data);
if (ret)
- dev_err(&priv->client->dev, "Setting the ramp rate failed\n");
+ dev_err(dev, "Setting the ramp rate failed\n");
}
out:
return ret;
@@ -193,37 +193,37 @@ static int lm3697_init(struct lm3697 *priv)
static int lm3697_probe_dt(struct lm3697 *priv)
{
struct fwnode_handle *child = NULL;
+ struct device *dev = priv->dev;
struct lm3697_led *led;
+ int ret = -EINVAL;
int control_bank;
size_t i = 0;
- int ret = -EINVAL;
int j;

- priv->enable_gpio = devm_gpiod_get_optional(&priv->client->dev,
- "enable", GPIOD_OUT_LOW);
+ priv->enable_gpio = devm_gpiod_get_optional(dev, "enable",
+ GPIOD_OUT_LOW);
if (IS_ERR(priv->enable_gpio)) {
ret = PTR_ERR(priv->enable_gpio);
- dev_err(&priv->client->dev, "Failed to get enable gpio: %d\n",
- ret);
+ dev_err(dev, "Failed to get enable gpio: %d\n", ret);
return ret;
}

- priv->regulator = devm_regulator_get(&priv->client->dev, "vled");
+ priv->regulator = devm_regulator_get(dev, "vled");
if (IS_ERR(priv->regulator))
priv->regulator = NULL;

- device_for_each_child_node(priv->dev, child) {
+ device_for_each_child_node(dev, child) {
struct led_init_data init_data = {};

ret = fwnode_property_read_u32(child, "reg", &control_bank);
if (ret) {
- dev_err(&priv->client->dev, "reg property missing\n");
+ dev_err(dev, "reg property missing\n");
fwnode_handle_put(child);
goto child_out;
}

if (control_bank > LM3697_CONTROL_B) {
- dev_err(&priv->client->dev, "reg property is invalid\n");
+ dev_err(dev, "reg property is invalid\n");
ret = -EINVAL;
fwnode_handle_put(child);
goto child_out;
@@ -231,10 +231,10 @@ static int lm3697_probe_dt(struct lm3697 *priv)

led = &priv->leds[i];

- ret = ti_lmu_common_get_brt_res(&priv->client->dev,
- child, &led->lmu_data);
+ ret = ti_lmu_common_get_brt_res(dev, child, &led->lmu_data);
if (ret)
- dev_warn(&priv->client->dev, "brightness resolution property missing\n");
+ dev_warn(dev,
+ "brightness resolution property missing\n");

led->control_bank = control_bank;
led->lmu_data.regmap = priv->regmap;
@@ -247,7 +247,7 @@ static int lm3697_probe_dt(struct lm3697 *priv)

led->num_leds = fwnode_property_count_u32(child, "led-sources");
if (led->num_leds > LM3697_MAX_LED_STRINGS) {
- dev_err(&priv->client->dev, "Too many LED strings defined\n");
+ dev_err(dev, "Too many LED strings defined\n");
continue;
}

@@ -255,7 +255,7 @@ static int lm3697_probe_dt(struct lm3697 *priv)
led->hvled_strings,
led->num_leds);
if (ret) {
- dev_err(&priv->client->dev, "led-sources property missing\n");
+ dev_err(dev, "led-sources property missing\n");
fwnode_handle_put(child);
goto child_out;
}
@@ -264,10 +264,9 @@ static int lm3697_probe_dt(struct lm3697 *priv)
priv->bank_cfg |=
(led->control_bank << led->hvled_strings[j]);

- ret = ti_lmu_common_get_ramp_params(&priv->client->dev,
- child, &led->lmu_data);
+ ret = ti_lmu_common_get_ramp_params(dev, child, &led->lmu_data);
if (ret)
- dev_warn(&priv->client->dev, "runtime-ramp properties missing\n");
+ dev_warn(dev, "runtime-ramp properties missing\n");

fwnode_property_read_string(child, "linux,default-trigger",
&led->led_dev.default_trigger);
@@ -281,11 +280,10 @@ static int lm3697_probe_dt(struct lm3697 *priv)
led->led_dev.max_brightness = led->lmu_data.max_brightness;
led->led_dev.brightness_set_blocking = lm3697_brightness_set;

- ret = devm_led_classdev_register_ext(priv->dev, &led->led_dev,
+ ret = devm_led_classdev_register_ext(dev, &led->led_dev,
&init_data);
if (ret) {
- dev_err(&priv->client->dev, "led register err: %d\n",
- ret);
+ dev_err(dev, "led register err: %d\n", ret);
fwnode_handle_put(child);
goto child_out;
}
@@ -300,18 +298,18 @@ static int lm3697_probe_dt(struct lm3697 *priv)
static int lm3697_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ struct device *dev = &client->dev;
struct lm3697 *led;
int count;
int ret;

- count = device_get_child_node_count(&client->dev);
+ count = device_get_child_node_count(dev);
if (!count) {
- dev_err(&client->dev, "LEDs are not defined in device tree!");
+ dev_err(dev, "LEDs are not defined in device tree!");
return -ENODEV;
}

- led = devm_kzalloc(&client->dev, struct_size(led, leds, count),
- GFP_KERNEL);
+ led = devm_kzalloc(dev, struct_size(led, leds, count), GFP_KERNEL);
if (!led)
return -ENOMEM;

@@ -319,12 +317,11 @@ static int lm3697_probe(struct i2c_client *client,
i2c_set_clientdata(client, led);

led->client = client;
- led->dev = &client->dev;
+ led->dev = dev;
led->regmap = devm_regmap_init_i2c(client, &lm3697_regmap_config);
if (IS_ERR(led->regmap)) {
ret = PTR_ERR(led->regmap);
- dev_err(&client->dev, "Failed to allocate register map: %d\n",
- ret);
+ dev_err(dev, "Failed to allocate register map: %d\n", ret);
return ret;
}

@@ -338,12 +335,13 @@ static int lm3697_probe(struct i2c_client *client,
static int lm3697_remove(struct i2c_client *client)
{
struct lm3697 *led = i2c_get_clientdata(client);
+ struct device *dev = &led->client->dev;
int ret;

ret = regmap_update_bits(led->regmap, LM3697_CTRL_ENABLE,
LM3697_CTRL_A_B_EN, 0);
if (ret) {
- dev_err(&led->client->dev, "Failed to disable the device\n");
+ dev_err(dev, "Failed to disable the device\n");
return ret;
}

@@ -353,8 +351,7 @@ static int lm3697_remove(struct i2c_client *client)
if (led->regulator) {
ret = regulator_disable(led->regulator);
if (ret)
- dev_err(&led->client->dev,
- "Failed to disable regulator\n");
+ dev_err(dev, "Failed to disable regulator\n");
}

mutex_destroy(&led->lock);
--
2.26.2

2020-09-17 22:38:06

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 17/50] leds: max77650: use reverse christmas tree

Only a cosmetic change: use reverse christmas tree variables
declaration.

Signed-off-by: Marek Behún <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
---
drivers/leds/leds-max77650.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/leds/leds-max77650.c b/drivers/leds/leds-max77650.c
index f2090d3ebfd53..bed620fc1b82e 100644
--- a/drivers/leds/leds-max77650.c
+++ b/drivers/leds/leds-max77650.c
@@ -62,8 +62,8 @@ static int max77650_led_brightness_set(struct led_classdev *cdev,

static int max77650_led_probe(struct platform_device *pdev)
{
- struct fwnode_handle *child;
struct max77650_led *leds, *led;
+ struct fwnode_handle *child;
struct device *dev;
struct regmap *map;
int rv, num_leds;
--
2.26.2

2020-09-17 22:38:15

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 22/50] leds: pm8058: cosmetic change: no need to return in if guard

We can return the last ret value.

Signed-off-by: Marek Behún <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Bjorn Andersson <[email protected]>
---
drivers/leds/leds-pm8058.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-pm8058.c b/drivers/leds/leds-pm8058.c
index 70b4d06488fec..193780a8c0522 100644
--- a/drivers/leds/leds-pm8058.c
+++ b/drivers/leds/leds-pm8058.c
@@ -147,12 +147,10 @@ static int pm8058_led_probe(struct platform_device *pdev)
init_data.fwnode = of_fwnode_handle(np);

ret = devm_led_classdev_register_ext(dev, &led->cdev, &init_data);
- if (ret) {
+ if (ret)
dev_err(dev, "Failed to register LED for %pOF\n", np);
- return ret;
- }

- return 0;
+ return ret;
}

static const struct of_device_id pm8058_leds_id_table[] = {
--
2.26.2

2020-09-17 22:38:19

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 29/50] leds: is31fl319x: cosmetic: use reverse christmas tree

Only a cosmetic change: use reverse christmas tree variables
declaration.

Signed-off-by: Marek Behún <[email protected]>
Cc: H. Nikolaus Schaller <[email protected]>
Cc: Grant Feng <[email protected]>
---
drivers/leds/leds-is31fl319x.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c
index 1dae319b03d60..15bdbc6378d93 100644
--- a/drivers/leds/leds-is31fl319x.c
+++ b/drivers/leds/leds-is31fl319x.c
@@ -111,9 +111,9 @@ static int is31fl319x_brightness_set(struct led_classdev *cdev,
cdev);
struct is31fl319x_chip *is31 = led->chip;
int chan = led - is31->leds;
+ u8 ctrl1 = 0, ctrl2 = 0;
int ret;
int i;
- u8 ctrl1 = 0, ctrl2 = 0;

dev_dbg(&is31->client->dev, "%s %d: %d\n", __func__, chan, brightness);

@@ -340,12 +340,12 @@ static int is31fl319x_parse_and_register(struct device *dev,
static int is31fl319x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- struct is31fl319x_chip *is31;
struct device *dev = &client->dev;
struct gpio_desc *shutdown_gpio;
+ struct is31fl319x_chip *is31;
+ u32 aggregated_led_microamp;
u32 audio_gain_db;
int err;
- u32 aggregated_led_microamp;

if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
return -EIO;
--
2.26.2

2020-09-17 22:38:34

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 10/50] leds: bcm6328, bcm6358: use devres LED registering function

These two drivers do not provide remove method and use devres for
allocation of other resources, yet they use led_classdev_register
instead of the devres variant, devm_led_classdev_register.

Fix this.

Signed-off-by: Marek Behún <[email protected]>
Cc: Álvaro Fernández Rojas <[email protected]>
Cc: Kevin Cernekee <[email protected]>
Cc: Jaedon Shin <[email protected]>
---
drivers/leds/leds-bcm6328.c | 2 +-
drivers/leds/leds-bcm6358.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/leds-bcm6328.c b/drivers/leds/leds-bcm6328.c
index c73097758e353..b3cf84a3eb150 100644
--- a/drivers/leds/leds-bcm6328.c
+++ b/drivers/leds/leds-bcm6328.c
@@ -383,7 +383,7 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg,
led->cdev.brightness_set = bcm6328_led_set;
led->cdev.blink_set = bcm6328_blink_set;

- rc = led_classdev_register(dev, &led->cdev);
+ rc = devm_led_classdev_register(dev, &led->cdev);
if (rc < 0)
return rc;

diff --git a/drivers/leds/leds-bcm6358.c b/drivers/leds/leds-bcm6358.c
index 289dfc412eda4..99dbf62aa6222 100644
--- a/drivers/leds/leds-bcm6358.c
+++ b/drivers/leds/leds-bcm6358.c
@@ -137,7 +137,7 @@ static int bcm6358_led(struct device *dev, struct device_node *nc, u32 reg,

led->cdev.brightness_set = bcm6358_led_set;

- rc = led_classdev_register(dev, &led->cdev);
+ rc = devm_led_classdev_register(dev, &led->cdev);
if (rc < 0)
return rc;

--
2.26.2

2020-09-17 22:38:36

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 49/50] leds: ns2: use struct led_init_data when registering

By using struct led_init_data when registering we do not need to parse
`label` DT property. Moreover `label` is deprecated and if it is not
present but `color` and `function` are, LED core will compose a name
from these properties instead.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 01c54ab0aa00e..b021e94d512c9 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -174,14 +174,11 @@ ATTRIBUTE_GROUPS(ns2_led);
static int ns2_led_register(struct device *dev, struct device_node *np,
struct ns2_led *led)
{
+ struct led_init_data init_data = {};
struct ns2_led_modval *modval;
enum ns2_led_modes mode;
int nmodes, ret, i;

- ret = of_property_read_string(np, "label", &led->cdev.name);
- if (ret)
- led->cdev.name = np->name;
-
led->cmd = devm_gpiod_get_from_of_node(dev, np, "cmd-gpio", 0,
GPIOD_ASIS, np->name);
if (IS_ERR(led->cmd))
@@ -238,7 +235,9 @@ static int ns2_led_register(struct device *dev, struct device_node *np,
led->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
led->cdev.brightness = (mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;

- ret = devm_led_classdev_register(dev, &led->cdev);
+ init_data.fwnode = of_fwnode_handle(np);
+
+ ret = devm_led_classdev_register_ext(dev, &led->cdev, &init_data);
if (ret)
dev_err(dev, "Failed to register LED for node %pOF\n", np);

--
2.26.2

2020-09-17 22:38:36

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 21/50] leds: pm8058: cosmetic change: use helper variable

Use helper variable dev instead of always writing &pdev->dev.

Signed-off-by: Marek Behún <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Bjorn Andersson <[email protected]>
---
drivers/leds/leds-pm8058.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/leds/leds-pm8058.c b/drivers/leds/leds-pm8058.c
index e085bf9ffc1de..70b4d06488fec 100644
--- a/drivers/leds/leds-pm8058.c
+++ b/drivers/leds/leds-pm8058.c
@@ -88,29 +88,32 @@ static enum led_brightness pm8058_led_get(struct led_classdev *cled)
static int pm8058_led_probe(struct platform_device *pdev)
{
struct led_init_data init_data = {};
+ struct device *dev = &pdev->dev;
struct pm8058_led *led;
- struct device_node *np = dev_of_node(&pdev->dev);
+ struct device_node *np;
int ret;
struct regmap *map;
const char *state;
enum led_brightness maxbright;

- led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
+ led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
if (!led)
return -ENOMEM;

- led->ledtype = (u32)(unsigned long)of_device_get_match_data(&pdev->dev);
+ led->ledtype = (u32)(unsigned long)of_device_get_match_data(dev);

- map = dev_get_regmap(pdev->dev.parent, NULL);
+ map = dev_get_regmap(dev->parent, NULL);
if (!map) {
- dev_err(&pdev->dev, "Parent regmap unavailable.\n");
+ dev_err(dev, "Parent regmap unavailable.\n");
return -ENXIO;
}
led->map = map;

+ np = dev_of_node(dev);
+
ret = of_property_read_u32(np, "reg", &led->reg);
if (ret) {
- dev_err(&pdev->dev, "no register offset specified\n");
+ dev_err(dev, "no register offset specified\n");
return -EINVAL;
}

@@ -143,10 +146,9 @@ static int pm8058_led_probe(struct platform_device *pdev)

init_data.fwnode = of_fwnode_handle(np);

- ret = devm_led_classdev_register_ext(&pdev->dev, &led->cdev,
- &init_data);
+ ret = devm_led_classdev_register_ext(dev, &led->cdev, &init_data);
if (ret) {
- dev_err(&pdev->dev, "Failed to register LED for %pOF\n", np);
+ dev_err(dev, "Failed to register LED for %pOF\n", np);
return ret;
}

--
2.26.2

2020-09-17 22:38:38

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 28/50] leds: is31fl319x: refactor to register LEDs while parsing DT

Refactor the code so that LEDs are registered while device tree is being
parsed.

Signed-off-by: Marek Behún <[email protected]>
Cc: H. Nikolaus Schaller <[email protected]>
Cc: Grant Feng <[email protected]>
---
drivers/leds/leds-is31fl319x.c | 174 ++++++++++++++-------------------
1 file changed, 76 insertions(+), 98 deletions(-)

diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c
index 8e3e02d959989..1dae319b03d60 100644
--- a/drivers/leds/leds-is31fl319x.c
+++ b/drivers/leds/leds-is31fl319x.c
@@ -209,86 +209,6 @@ static u32 is31fl319x_parse_audio_gain(struct device *dev)
return result;;
}

-static int is31fl319x_parse_child_dt(const struct device *dev,
- const struct device_node *child,
- struct is31fl319x_led *led)
-{
- struct led_classdev *cdev = &led->cdev;
- int ret;
-
- if (of_property_read_string(child, "label", &cdev->name))
- cdev->name = child->name;
-
- ret = of_property_read_string(child, "linux,default-trigger",
- &cdev->default_trigger);
- if (ret < 0 && ret != -EINVAL) /* is optional */
- return ret;
-
- return 0;
-}
-
-static int is31fl319x_parse_dt(struct device *dev,
- struct is31fl319x_chip *is31)
-{
- struct device_node *np = dev_of_node(dev), *child;
- int count;
- int ret;
-
- if (!np)
- return -ENODEV;
-
- is31->cdef = device_get_match_data(dev);
-
- count = of_get_available_child_count(np);
-
- dev_dbg(dev, "probing with %d leds defined in DT\n", count);
-
- if (!count || count > is31->cdef->num_leds) {
- dev_err(dev, "Number of leds defined must be between 1 and %u\n",
- is31->cdef->num_leds);
- return -ENODEV;
- }
-
- for_each_available_child_of_node(np, child) {
- struct is31fl319x_led *led;
- u32 reg;
-
- ret = of_property_read_u32(child, "reg", &reg);
- if (ret) {
- dev_err(dev, "Failed to read led 'reg' property\n");
- goto put_child_node;
- }
-
- if (reg < 1 || reg > is31->cdef->num_leds) {
- dev_err(dev, "invalid led reg %u\n", reg);
- ret = -EINVAL;
- goto put_child_node;
- }
-
- led = &is31->leds[reg - 1];
-
- if (led->configured) {
- dev_err(dev, "led %u is already configured\n", reg);
- ret = -EINVAL;
- goto put_child_node;
- }
-
- ret = is31fl319x_parse_child_dt(dev, child, led);
- if (ret) {
- dev_err(dev, "led %u DT parsing failed\n", reg);
- goto put_child_node;
- }
-
- led->configured = true;
- }
-
- return 0;
-
-put_child_node:
- of_node_put(child);
- return ret;
-}
-
static bool is31fl319x_readable_reg(struct device *dev, unsigned int reg)
{ /* we have no readable registers */
return false;
@@ -345,6 +265,78 @@ static inline int is31fl319x_db_to_gain(u32 dezibel)
return dezibel / IS31FL319X_AUDIO_GAIN_DB_STEP;
}

+static int is31fl319x_led_register(struct device *dev,
+ struct is31fl319x_chip *is31,
+ struct device_node *np)
+{
+ struct is31fl319x_led *led;
+ u32 reg;
+ int ret;
+
+ ret = of_property_read_u32(np, "reg", &reg);
+ if (ret) {
+ dev_err(dev, "Cannot read reg property of %pOF\n", np);
+ return ret;
+ }
+
+ if (reg < 1 || reg > is31->cdef->num_leds) {
+ dev_err(dev, "Node %pOF has invalid reg property\n", np);
+ return -EINVAL;
+ }
+
+ led = &is31->leds[reg - 1];
+
+ if (led->configured) {
+ dev_err(dev, "Node %pOF 'reg' conflicts with another LED\n",
+ np);
+ return -EEXIST;
+ }
+
+ if (of_property_read_string(np, "label", &led->cdev.name))
+ led->cdev.name = np->name;
+
+ ret = of_property_read_string(np, "linux,default-trigger",
+ &led->cdev.default_trigger);
+ if (ret < 0 && ret != -EINVAL) /* is optional */
+ return ret;
+
+ led->configured = true;
+ led->chip = is31;
+ led->cdev.brightness_set_blocking = is31fl319x_brightness_set;
+
+ ret = devm_led_classdev_register(dev, &led->cdev);
+ if (ret)
+ dev_err(dev, "Failed to register LED for node %pOF\n", np);
+
+ return ret;
+}
+
+static int is31fl319x_parse_and_register(struct device *dev,
+ struct is31fl319x_chip *is31)
+{
+ struct device_node *np = dev_of_node(dev), *child;
+ int ret, count;
+
+ count = of_get_available_child_count(np);
+ if (count < 1 || count > is31->cdef->num_leds) {
+ dev_err(dev, "Between 1 and %u LEDs have to be defined\n",
+ is31->cdef->num_leds);
+ return -ENODEV;
+ }
+
+ dev_dbg(dev, "probing with %d leds defined in DT\n", count);
+
+ for_each_available_child_of_node(np, child) {
+ ret = is31fl319x_led_register(dev, is31, child);
+ if (ret) {
+ of_node_put(child);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
static int is31fl319x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -353,7 +345,6 @@ static int is31fl319x_probe(struct i2c_client *client,
struct gpio_desc *shutdown_gpio;
u32 audio_gain_db;
int err;
- int i = 0;
u32 aggregated_led_microamp;

if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
@@ -388,11 +379,8 @@ static int is31fl319x_probe(struct i2c_client *client,

mutex_init(&is31->lock);

- err = is31fl319x_parse_dt(&client->dev, is31);
- if (err)
- goto free_mutex;
-
is31->client = client;
+ is31->cdef = device_get_match_data(dev);
is31->regmap = devm_regmap_init_i2c(client, &regmap_config);
if (IS_ERR(is31->regmap)) {
dev_err(&client->dev, "failed to allocate register map\n");
@@ -417,19 +405,9 @@ static int is31fl319x_probe(struct i2c_client *client,
is31fl319x_microamp_to_cs(dev, aggregated_led_microamp) |
is31fl319x_db_to_gain(audio_gain_db));

- for (i = 0; i < is31->cdef->num_leds; i++) {
- struct is31fl319x_led *led = &is31->leds[i];
-
- if (!led->configured)
- continue;
-
- led->chip = is31;
- led->cdev.brightness_set_blocking = is31fl319x_brightness_set;
-
- err = devm_led_classdev_register(&client->dev, &led->cdev);
- if (err < 0)
- goto free_mutex;
- }
+ err = is31fl319x_parse_and_register(dev, is31);
+ if (err)
+ goto free_mutex;

return 0;

--
2.26.2

2020-09-17 22:38:40

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 11/50] leds: bcm6328, bcm6358: use struct led_init_data when registering

By using struct led_init_data when registering we do not need to parse
`label` DT property. Moreover `label` is deprecated and if it is not
present but `color` and `function` are, LED core will compose a name
from these properties instead.

Signed-off-by: Marek Behún <[email protected]>
Cc: Álvaro Fernández Rojas <[email protected]>
Cc: Kevin Cernekee <[email protected]>
Cc: Jaedon Shin <[email protected]>
---
drivers/leds/leds-bcm6328.c | 5 +++--
drivers/leds/leds-bcm6358.c | 5 +++--
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-bcm6328.c b/drivers/leds/leds-bcm6328.c
index b3cf84a3eb150..c72b0842e8151 100644
--- a/drivers/leds/leds-bcm6328.c
+++ b/drivers/leds/leds-bcm6328.c
@@ -328,6 +328,7 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg,
void __iomem *mem, spinlock_t *lock,
unsigned long *blink_leds, unsigned long *blink_delay)
{
+ struct led_init_data init_data = {};
struct bcm6328_led *led;
const char *state;
int rc;
@@ -345,7 +346,6 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg,
if (of_property_read_bool(nc, "active-low"))
led->active_low = true;

- led->cdev.name = of_get_property(nc, "label", NULL) ? : nc->name;
led->cdev.default_trigger = of_get_property(nc,
"linux,default-trigger",
NULL);
@@ -382,8 +382,9 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg,

led->cdev.brightness_set = bcm6328_led_set;
led->cdev.blink_set = bcm6328_blink_set;
+ init_data.fwnode = of_fwnode_handle(nc);

- rc = devm_led_classdev_register(dev, &led->cdev);
+ rc = devm_led_classdev_register_ext(dev, &led->cdev, &init_data);
if (rc < 0)
return rc;

diff --git a/drivers/leds/leds-bcm6358.c b/drivers/leds/leds-bcm6358.c
index 99dbf62aa6222..49f703c59ecdc 100644
--- a/drivers/leds/leds-bcm6358.c
+++ b/drivers/leds/leds-bcm6358.c
@@ -94,6 +94,7 @@ static void bcm6358_led_set(struct led_classdev *led_cdev,
static int bcm6358_led(struct device *dev, struct device_node *nc, u32 reg,
void __iomem *mem, spinlock_t *lock)
{
+ struct led_init_data init_data = {};
struct bcm6358_led *led;
const char *state;
int rc;
@@ -109,7 +110,6 @@ static int bcm6358_led(struct device *dev, struct device_node *nc, u32 reg,
if (of_property_read_bool(nc, "active-low"))
led->active_low = true;

- led->cdev.name = of_get_property(nc, "label", NULL) ? : nc->name;
led->cdev.default_trigger = of_get_property(nc,
"linux,default-trigger",
NULL);
@@ -136,8 +136,9 @@ static int bcm6358_led(struct device *dev, struct device_node *nc, u32 reg,
bcm6358_led_set(&led->cdev, led->cdev.brightness);

led->cdev.brightness_set = bcm6358_led_set;
+ init_data.fwnode = of_fwnode_handle(nc);

- rc = devm_led_classdev_register(dev, &led->cdev);
+ rc = devm_led_classdev_register_ext(dev, &led->cdev, &init_data);
if (rc < 0)
return rc;

--
2.26.2

2020-09-17 22:38:49

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 05/50] leds: various: guard of_match_table member value with of_match_ptr

Change
.of_match_table = xxx,
to
.of_match_table = of_match_ptr(xxx),
in various drivers.

This should be standard even for drivers that depend on OF.

Signed-off-by: Marek Behún <[email protected]>
Cc: Sakari Ailus <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Sean Wang <[email protected]>
Cc: Matthias Brugger <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Orson Zhai <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: Chunyan Zhang <[email protected]>
Cc: Thierry Reding <[email protected]>
Cc: "Uwe Kleine-König" <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
---
drivers/leds/leds-aat1290.c | 2 +-
drivers/leds/leds-as3645a.c | 2 +-
drivers/leds/leds-bcm6328.c | 2 +-
drivers/leds/leds-bcm6358.c | 2 +-
drivers/leds/leds-cpcap.c | 2 +-
drivers/leds/leds-cr0014114.c | 2 +-
drivers/leds/leds-el15203000.c | 2 +-
drivers/leds/leds-gpio.c | 2 +-
drivers/leds/leds-is31fl32xx.c | 2 +-
drivers/leds/leds-ktd2692.c | 2 +-
drivers/leds/leds-lm3532.c | 2 +-
drivers/leds/leds-lm3601x.c | 2 +-
drivers/leds/leds-lm3692x.c | 2 +-
drivers/leds/leds-lm3697.c | 2 +-
drivers/leds/leds-lp50xx.c | 2 +-
drivers/leds/leds-lp8860.c | 2 +-
drivers/leds/leds-max77650.c | 2 +-
drivers/leds/leds-max77693.c | 2 +-
drivers/leds/leds-mt6323.c | 2 +-
drivers/leds/leds-netxbig.c | 2 +-
drivers/leds/leds-pca955x.c | 2 +-
drivers/leds/leds-pca963x.c | 2 +-
drivers/leds/leds-pm8058.c | 2 +-
drivers/leds/leds-powernv.c | 2 +-
drivers/leds/leds-pwm.c | 2 +-
drivers/leds/leds-sc27xx-bltc.c | 2 +-
drivers/leds/leds-sgm3140.c | 2 +-
drivers/leds/leds-spi-byte.c | 2 +-
drivers/leds/leds-syscon.c | 2 +-
drivers/leds/leds-turris-omnia.c | 2 +-
30 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/drivers/leds/leds-aat1290.c b/drivers/leds/leds-aat1290.c
index 5a0fe7b7b8bc7..c78a29ab8e9fb 100644
--- a/drivers/leds/leds-aat1290.c
+++ b/drivers/leds/leds-aat1290.c
@@ -545,7 +545,7 @@ static struct platform_driver aat1290_led_driver = {
.remove = aat1290_led_remove,
.driver = {
.name = "aat1290",
- .of_match_table = aat1290_led_dt_match,
+ .of_match_table = of_match_ptr(aat1290_led_dt_match),
},
};

diff --git a/drivers/leds/leds-as3645a.c b/drivers/leds/leds-as3645a.c
index e8922fa033796..50b12e440d88d 100644
--- a/drivers/leds/leds-as3645a.c
+++ b/drivers/leds/leds-as3645a.c
@@ -757,7 +757,7 @@ MODULE_DEVICE_TABLE(of, as3645a_of_table);

static struct i2c_driver as3645a_i2c_driver = {
.driver = {
- .of_match_table = as3645a_of_table,
+ .of_match_table = of_match_ptr(as3645a_of_table),
.name = AS_NAME,
},
.probe_new = as3645a_probe,
diff --git a/drivers/leds/leds-bcm6328.c b/drivers/leds/leds-bcm6328.c
index bad7efb751120..65a3857efa4ed 100644
--- a/drivers/leds/leds-bcm6328.c
+++ b/drivers/leds/leds-bcm6328.c
@@ -477,7 +477,7 @@ static struct platform_driver bcm6328_leds_driver = {
.probe = bcm6328_leds_probe,
.driver = {
.name = "leds-bcm6328",
- .of_match_table = bcm6328_leds_of_match,
+ .of_match_table = of_match_ptr(bcm6328_leds_of_match),
},
};

diff --git a/drivers/leds/leds-bcm6358.c b/drivers/leds/leds-bcm6358.c
index 94fefd456ba07..44fd1ba4be57e 100644
--- a/drivers/leds/leds-bcm6358.c
+++ b/drivers/leds/leds-bcm6358.c
@@ -220,7 +220,7 @@ static struct platform_driver bcm6358_leds_driver = {
.probe = bcm6358_leds_probe,
.driver = {
.name = "leds-bcm6358",
- .of_match_table = bcm6358_leds_of_match,
+ .of_match_table = of_match_ptr(bcm6358_leds_of_match),
},
};

diff --git a/drivers/leds/leds-cpcap.c b/drivers/leds/leds-cpcap.c
index 7d41ce8c9bb1e..263e4bbf3fda5 100644
--- a/drivers/leds/leds-cpcap.c
+++ b/drivers/leds/leds-cpcap.c
@@ -216,7 +216,7 @@ static struct platform_driver cpcap_led_driver = {
.probe = cpcap_led_probe,
.driver = {
.name = "cpcap-led",
- .of_match_table = cpcap_led_of_match,
+ .of_match_table = of_match_ptr(cpcap_led_of_match),
},
};
module_platform_driver(cpcap_led_driver);
diff --git a/drivers/leds/leds-cr0014114.c b/drivers/leds/leds-cr0014114.c
index 2da448ae718e9..a2f5638eda5f7 100644
--- a/drivers/leds/leds-cr0014114.c
+++ b/drivers/leds/leds-cr0014114.c
@@ -291,7 +291,7 @@ static struct spi_driver cr0014114_driver = {
.remove = cr0014114_remove,
.driver = {
.name = KBUILD_MODNAME,
- .of_match_table = cr0014114_dt_ids,
+ .of_match_table = of_match_ptr(cr0014114_dt_ids),
},
};

diff --git a/drivers/leds/leds-el15203000.c b/drivers/leds/leds-el15203000.c
index 298b13e4807a8..bcd13a7fc9d02 100644
--- a/drivers/leds/leds-el15203000.c
+++ b/drivers/leds/leds-el15203000.c
@@ -345,7 +345,7 @@ static struct spi_driver el15203000_driver = {
.remove = el15203000_remove,
.driver = {
.name = KBUILD_MODNAME,
- .of_match_table = el15203000_dt_ids,
+ .of_match_table = of_match_ptr(el15203000_dt_ids),
},
};

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index cf84096d88cec..aa740267eb232 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -311,7 +311,7 @@ static struct platform_driver gpio_led_driver = {
.shutdown = gpio_led_shutdown,
.driver = {
.name = "leds-gpio",
- .of_match_table = of_gpio_leds_match,
+ .of_match_table = of_match_ptr(of_gpio_leds_match),
},
};

diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c
index acf51e17e8df6..408eb5fad4cb0 100644
--- a/drivers/leds/leds-is31fl32xx.c
+++ b/drivers/leds/leds-is31fl32xx.c
@@ -485,7 +485,7 @@ MODULE_DEVICE_TABLE(i2c, is31fl32xx_id);
static struct i2c_driver is31fl32xx_driver = {
.driver = {
.name = "is31fl32xx",
- .of_match_table = of_is31fl32xx_match,
+ .of_match_table = of_match_ptr(of_is31fl32xx_match),
},
.probe = is31fl32xx_probe,
.remove = is31fl32xx_remove,
diff --git a/drivers/leds/leds-ktd2692.c b/drivers/leds/leds-ktd2692.c
index 670efee9b1317..63917db8cac39 100644
--- a/drivers/leds/leds-ktd2692.c
+++ b/drivers/leds/leds-ktd2692.c
@@ -402,7 +402,7 @@ MODULE_DEVICE_TABLE(of, ktd2692_match);
static struct platform_driver ktd2692_driver = {
.driver = {
.name = "ktd2692",
- .of_match_table = ktd2692_match,
+ .of_match_table = of_match_ptr(ktd2692_match),
},
.probe = ktd2692_probe,
.remove = ktd2692_remove,
diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c
index 946ad67eaecb7..3670cc64eee7b 100644
--- a/drivers/leds/leds-lm3532.c
+++ b/drivers/leds/leds-lm3532.c
@@ -752,7 +752,7 @@ static struct i2c_driver lm3532_i2c_driver = {
.id_table = lm3532_id,
.driver = {
.name = LM3532_NAME,
- .of_match_table = of_lm3532_leds_match,
+ .of_match_table = of_match_ptr(of_lm3532_leds_match),
},
};
module_i2c_driver(lm3532_i2c_driver);
diff --git a/drivers/leds/leds-lm3601x.c b/drivers/leds/leds-lm3601x.c
index d0e1d4814042e..e12b9fbac4c1a 100644
--- a/drivers/leds/leds-lm3601x.c
+++ b/drivers/leds/leds-lm3601x.c
@@ -468,7 +468,7 @@ MODULE_DEVICE_TABLE(of, of_lm3601x_leds_match);
static struct i2c_driver lm3601x_i2c_driver = {
.driver = {
.name = "lm3601x",
- .of_match_table = of_lm3601x_leds_match,
+ .of_match_table = of_match_ptr(of_lm3601x_leds_match),
},
.probe_new = lm3601x_probe,
.remove = lm3601x_remove,
diff --git a/drivers/leds/leds-lm3692x.c b/drivers/leds/leds-lm3692x.c
index 1d7ea1b76a125..ba535ee8fd252 100644
--- a/drivers/leds/leds-lm3692x.c
+++ b/drivers/leds/leds-lm3692x.c
@@ -525,7 +525,7 @@ MODULE_DEVICE_TABLE(of, of_lm3692x_leds_match);
static struct i2c_driver lm3692x_driver = {
.driver = {
.name = "lm3692x",
- .of_match_table = of_lm3692x_leds_match,
+ .of_match_table = of_match_ptr(of_lm3692x_leds_match),
},
.probe = lm3692x_probe,
.remove = lm3692x_remove,
diff --git a/drivers/leds/leds-lm3697.c b/drivers/leds/leds-lm3697.c
index 024983088d599..5d14f3d2220af 100644
--- a/drivers/leds/leds-lm3697.c
+++ b/drivers/leds/leds-lm3697.c
@@ -379,7 +379,7 @@ MODULE_DEVICE_TABLE(of, of_lm3697_leds_match);
static struct i2c_driver lm3697_driver = {
.driver = {
.name = "lm3697",
- .of_match_table = of_lm3697_leds_match,
+ .of_match_table = of_match_ptr(of_lm3697_leds_match),
},
.probe = lm3697_probe,
.remove = lm3697_remove,
diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 47144a37cb945..1f8be335084d5 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -621,7 +621,7 @@ MODULE_DEVICE_TABLE(of, of_lp50xx_leds_match);
static struct i2c_driver lp50xx_driver = {
.driver = {
.name = "lp50xx",
- .of_match_table = of_lp50xx_leds_match,
+ .of_match_table = of_match_ptr(of_lp50xx_leds_match),
},
.probe = lp50xx_probe,
.remove = lp50xx_remove,
diff --git a/drivers/leds/leds-lp8860.c b/drivers/leds/leds-lp8860.c
index ac2f5d6272dc0..6eb323212da3c 100644
--- a/drivers/leds/leds-lp8860.c
+++ b/drivers/leds/leds-lp8860.c
@@ -484,7 +484,7 @@ MODULE_DEVICE_TABLE(of, of_lp8860_leds_match);
static struct i2c_driver lp8860_driver = {
.driver = {
.name = "lp8860",
- .of_match_table = of_lp8860_leds_match,
+ .of_match_table = of_match_ptr(of_lp8860_leds_match),
},
.probe = lp8860_probe,
.remove = lp8860_remove,
diff --git a/drivers/leds/leds-max77650.c b/drivers/leds/leds-max77650.c
index a0d4b725c9178..56a37d4b7df63 100644
--- a/drivers/leds/leds-max77650.c
+++ b/drivers/leds/leds-max77650.c
@@ -144,7 +144,7 @@ MODULE_DEVICE_TABLE(of, max77650_led_of_match);
static struct platform_driver max77650_led_driver = {
.driver = {
.name = "max77650-led",
- .of_match_table = max77650_led_of_match,
+ .of_match_table = of_match_ptr(max77650_led_of_match),
},
.probe = max77650_led_probe,
};
diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c
index fec56090c2ba3..1d8e2ffe7ad46 100644
--- a/drivers/leds/leds-max77693.c
+++ b/drivers/leds/leds-max77693.c
@@ -1047,7 +1047,7 @@ static struct platform_driver max77693_led_driver = {
.remove = max77693_led_remove,
.driver = {
.name = "max77693-led",
- .of_match_table = max77693_led_dt_match,
+ .of_match_table = of_match_ptr(max77693_led_dt_match),
},
};

diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c
index 7b240771e45bb..80b57a39445cb 100644
--- a/drivers/leds/leds-mt6323.c
+++ b/drivers/leds/leds-mt6323.c
@@ -482,7 +482,7 @@ static struct platform_driver mt6323_led_driver = {
.remove = mt6323_led_remove,
.driver = {
.name = "mt6323-led",
- .of_match_table = mt6323_led_dt_match,
+ .of_match_table = of_match_ptr(mt6323_led_dt_match),
},
};

diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
index ceceeb6a0e966..7f3313e321fa6 100644
--- a/drivers/leds/leds-netxbig.c
+++ b/drivers/leds/leds-netxbig.c
@@ -617,7 +617,7 @@ static struct platform_driver netxbig_led_driver = {
.probe = netxbig_led_probe,
.driver = {
.name = "leds-netxbig",
- .of_match_table = of_netxbig_leds_match,
+ .of_match_table = of_match_ptr(of_netxbig_leds_match),
},
};

diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
index 7087ca4592fc9..7da2b88a89197 100644
--- a/drivers/leds/leds-pca955x.c
+++ b/drivers/leds/leds-pca955x.c
@@ -579,7 +579,7 @@ static int pca955x_probe(struct i2c_client *client,
static struct i2c_driver pca955x_driver = {
.driver = {
.name = "leds-pca955x",
- .of_match_table = of_pca955x_match,
+ .of_match_table = of_match_ptr(of_pca955x_match),
},
.probe = pca955x_probe,
.id_table = pca955x_id,
diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
index d288acbc99c7c..d3969c7914656 100644
--- a/drivers/leds/leds-pca963x.c
+++ b/drivers/leds/leds-pca963x.c
@@ -473,7 +473,7 @@ static int pca963x_remove(struct i2c_client *client)
static struct i2c_driver pca963x_driver = {
.driver = {
.name = "leds-pca963x",
- .of_match_table = of_pca963x_match,
+ .of_match_table = of_match_ptr(of_pca963x_match),
},
.probe = pca963x_probe,
.remove = pca963x_remove,
diff --git a/drivers/leds/leds-pm8058.c b/drivers/leds/leds-pm8058.c
index 7869ccdf70ce6..d9e8ea80cd167 100644
--- a/drivers/leds/leds-pm8058.c
+++ b/drivers/leds/leds-pm8058.c
@@ -173,7 +173,7 @@ static struct platform_driver pm8058_led_driver = {
.probe = pm8058_led_probe,
.driver = {
.name = "pm8058-leds",
- .of_match_table = pm8058_leds_id_table,
+ .of_match_table = of_match_ptr(pm8058_leds_id_table),
},
};
module_platform_driver(pm8058_led_driver);
diff --git a/drivers/leds/leds-powernv.c b/drivers/leds/leds-powernv.c
index cd43d5dff7f48..d803726300ff4 100644
--- a/drivers/leds/leds-powernv.c
+++ b/drivers/leds/leds-powernv.c
@@ -338,7 +338,7 @@ static struct platform_driver powernv_led_driver = {
.remove = powernv_led_remove,
.driver = {
.name = "powernv-led-driver",
- .of_match_table = powernv_led_match,
+ .of_match_table = of_match_ptr(powernv_led_match),
},
};

diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index e35a97c1d8285..02c9c7a32251e 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -190,7 +190,7 @@ static struct platform_driver led_pwm_driver = {
.probe = led_pwm_probe,
.driver = {
.name = "leds_pwm",
- .of_match_table = of_pwm_leds_match,
+ .of_match_table = of_match_ptr(of_pwm_leds_match),
},
};

diff --git a/drivers/leds/leds-sc27xx-bltc.c b/drivers/leds/leds-sc27xx-bltc.c
index 0ede87420bfc7..3401ad389c8d9 100644
--- a/drivers/leds/leds-sc27xx-bltc.c
+++ b/drivers/leds/leds-sc27xx-bltc.c
@@ -347,7 +347,7 @@ MODULE_DEVICE_TABLE(of, sc27xx_led_of_match);
static struct platform_driver sc27xx_led_driver = {
.driver = {
.name = "sprd-bltc",
- .of_match_table = sc27xx_led_of_match,
+ .of_match_table = of_match_ptr(sc27xx_led_of_match),
},
.probe = sc27xx_led_probe,
.remove = sc27xx_led_remove,
diff --git a/drivers/leds/leds-sgm3140.c b/drivers/leds/leds-sgm3140.c
index f4f831570f11c..92ce22024d91b 100644
--- a/drivers/leds/leds-sgm3140.c
+++ b/drivers/leds/leds-sgm3140.c
@@ -300,7 +300,7 @@ static struct platform_driver sgm3140_driver = {
.remove = sgm3140_remove,
.driver = {
.name = "sgm3140",
- .of_match_table = sgm3140_dt_match,
+ .of_match_table = of_match_ptr(sgm3140_dt_match),
},
};

diff --git a/drivers/leds/leds-spi-byte.c b/drivers/leds/leds-spi-byte.c
index 9632eb84f8de1..21ec02c4f8dac 100644
--- a/drivers/leds/leds-spi-byte.c
+++ b/drivers/leds/leds-spi-byte.c
@@ -144,7 +144,7 @@ static struct spi_driver spi_byte_driver = {
.remove = spi_byte_remove,
.driver = {
.name = KBUILD_MODNAME,
- .of_match_table = spi_byte_dt_ids,
+ .of_match_table = of_match_ptr(spi_byte_dt_ids),
},
};

diff --git a/drivers/leds/leds-syscon.c b/drivers/leds/leds-syscon.c
index b58f3cafe16f4..b56a5c82bf759 100644
--- a/drivers/leds/leds-syscon.c
+++ b/drivers/leds/leds-syscon.c
@@ -134,7 +134,7 @@ static struct platform_driver syscon_led_driver = {
.probe = syscon_led_probe,
.driver = {
.name = "leds-syscon",
- .of_match_table = of_syscon_leds_match,
+ .of_match_table = of_match_ptr(of_syscon_leds_match),
.suppress_bind_attrs = true,
},
};
diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index bb23d8e166144..2a69d2085a225 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -284,7 +284,7 @@ static struct i2c_driver omnia_leds_driver = {
.id_table = omnia_id,
.driver = {
.name = "leds-turris-omnia",
- .of_match_table = of_omnia_leds_match,
+ .of_match_table = of_match_ptr(of_omnia_leds_match),
},
};

--
2.26.2

2020-09-17 22:38:52

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 16/50] leds: max77650: use struct led_init_data when registering

By using struct led_init_data when registering we do not need to parse
`label` DT property. Moreover `label` is deprecated and if it is not
present but `color` and `function` are, LED core will compose a name
from these properties instead.

Previously if the `label` DT property was not present, the code composed
name for the LED in the form
"max77650::"
For backwards compatibility we therefore set
init_data->default_label = ":";
so that the LED will not get a different name if `label` property is not
present.

Signed-off-by: Marek Behún <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
---
drivers/leds/leds-max77650.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/leds/leds-max77650.c b/drivers/leds/leds-max77650.c
index 56a37d4b7df63..f2090d3ebfd53 100644
--- a/drivers/leds/leds-max77650.c
+++ b/drivers/leds/leds-max77650.c
@@ -66,7 +66,6 @@ static int max77650_led_probe(struct platform_device *pdev)
struct max77650_led *leds, *led;
struct device *dev;
struct regmap *map;
- const char *label;
int rv, num_leds;
u32 reg;

@@ -86,6 +85,8 @@ static int max77650_led_probe(struct platform_device *pdev)
return -ENODEV;

device_for_each_child_node(dev, child) {
+ struct led_init_data init_data = {};
+
rv = fwnode_property_read_u32(child, "reg", &reg);
if (rv || reg >= MAX77650_LED_NUM_LEDS) {
rv = -EINVAL;
@@ -99,22 +100,16 @@ static int max77650_led_probe(struct platform_device *pdev)
led->cdev.brightness_set_blocking = max77650_led_brightness_set;
led->cdev.max_brightness = MAX77650_LED_MAX_BRIGHTNESS;

- rv = fwnode_property_read_string(child, "label", &label);
- if (rv) {
- led->cdev.name = "max77650::";
- } else {
- led->cdev.name = devm_kasprintf(dev, GFP_KERNEL,
- "max77650:%s", label);
- if (!led->cdev.name) {
- rv = -ENOMEM;
- goto err_node_put;
- }
- }
-
fwnode_property_read_string(child, "linux,default-trigger",
&led->cdev.default_trigger);

- rv = devm_led_classdev_register(dev, &led->cdev);
+ init_data.fwnode = child;
+ init_data.devicename = "max77650";
+ /* for backwards compatibility if `label` is not present */
+ init_data.default_label = ":";
+
+ rv = devm_led_classdev_register_ext(dev, &led->cdev,
+ &init_data);
if (rv)
goto err_node_put;

--
2.26.2

2020-09-17 22:39:00

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 12/50] leds: bcm6328: cosmetic: use reverse christmas tree

Only a cosmetic change: use reverse christmas tree variables
declaration.

Signed-off-by: Marek Behún <[email protected]>
Cc: Álvaro Fernández Rojas <[email protected]>
Cc: Kevin Cernekee <[email protected]>
Cc: Jaedon Shin <[email protected]>
---
drivers/leds/leds-bcm6328.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/leds/leds-bcm6328.c b/drivers/leds/leds-bcm6328.c
index c72b0842e8151..38bf820372528 100644
--- a/drivers/leds/leds-bcm6328.c
+++ b/drivers/leds/leds-bcm6328.c
@@ -109,8 +109,8 @@ static unsigned long bcm6328_pin2shift(unsigned long pin)

static void bcm6328_led_mode(struct bcm6328_led *led, unsigned long value)
{
- void __iomem *mode;
unsigned long val, shift;
+ void __iomem *mode;

shift = bcm6328_pin2shift(led->pin);
if (shift / 16)
@@ -255,8 +255,8 @@ static int bcm6328_blink_set(struct led_classdev *led_cdev,
static int bcm6328_hwled(struct device *dev, struct device_node *nc, u32 reg,
void __iomem *mem, spinlock_t *lock)
{
- int i, cnt;
unsigned long flags, val;
+ int i, cnt;

spin_lock_irqsave(lock, flags);
val = bcm6328_led_read(mem + BCM6328_REG_HWDIS);
@@ -271,8 +271,8 @@ static int bcm6328_hwled(struct device *dev, struct device_node *nc, u32 reg,
cnt = of_property_count_elems_of_size(nc, "brcm,link-signal-sources",
sizeof(u32));
for (i = 0; i < cnt; i++) {
- u32 sel;
void __iomem *addr;
+ u32 sel;

if (reg < 4)
addr = mem + BCM6328_REG_LNKACTSEL_LO;
@@ -298,8 +298,8 @@ static int bcm6328_hwled(struct device *dev, struct device_node *nc, u32 reg,
"brcm,activity-signal-sources",
sizeof(u32));
for (i = 0; i < cnt; i++) {
- u32 sel;
void __iomem *addr;
+ u32 sel;

if (reg < 4)
addr = mem + BCM6328_REG_LNKACTSEL_LO;
@@ -395,12 +395,11 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg,

static int bcm6328_leds_probe(struct platform_device *pdev)
{
+ unsigned long val, *blink_leds, *blink_delay;
struct device *dev = &pdev->dev;
- struct device_node *np = dev_of_node(&pdev->dev);
- struct device_node *child;
+ struct device_node *np, *child;
void __iomem *mem;
spinlock_t *lock; /* memory lock */
- unsigned long val, *blink_leds, *blink_delay;

mem = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(mem))
@@ -426,6 +425,8 @@ static int bcm6328_leds_probe(struct platform_device *pdev)
bcm6328_led_write(mem + BCM6328_REG_LNKACTSEL_HI, 0);
bcm6328_led_write(mem + BCM6328_REG_LNKACTSEL_LO, 0);

+ np = dev_of_node(dev);
+
val = bcm6328_led_read(mem + BCM6328_REG_INIT);
val &= ~(BCM6328_INIT_MASK);
if (of_property_read_bool(np, "brcm,serial-leds"))
@@ -441,8 +442,8 @@ static int bcm6328_leds_probe(struct platform_device *pdev)
bcm6328_led_write(mem + BCM6328_REG_INIT, val);

for_each_available_child_of_node(np, child) {
- int rc;
u32 reg;
+ int rc;

if (of_property_read_u32(child, "reg", &reg))
continue;
--
2.26.2

2020-09-17 22:39:11

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 07/50] leds: lt3593: do not rewrite .of_node of new LED device to wrong value

The devm_led_classdev_register_ext is given init_data with fwnode set,
so the LED core sets .of_node of the new LED classdev correctly.

Do not rewrite this value to parent of_node.

Signed-off-by: Marek Behún <[email protected]>
Cc: Daniel Mack <[email protected]>
---
drivers/leds/leds-lt3593.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/drivers/leds/leds-lt3593.c b/drivers/leds/leds-lt3593.c
index c2d7ffebacc56..061f02e3995ae 100644
--- a/drivers/leds/leds-lt3593.c
+++ b/drivers/leds/leds-lt3593.c
@@ -107,7 +107,6 @@ static int lt3593_led_probe(struct platform_device *pdev)
return ret;
}

- led_data->cdev.dev->of_node = dev->of_node;
platform_set_drvdata(pdev, led_data);

return 0;
--
2.26.2

2020-09-17 22:39:21

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 37/50] leds: ns2: alloc simple array instead of struct ns2_led_priv

Since .remove method is not needed now that we use devres, there is no
need to remember the number of LEDs in struct ns2_led_priv. Alloc simple
array of ns2_led_data structs.

Signed-off-by: Marek Behún <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Vincent Donnefort <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Linus Walleij <[email protected]>
---
drivers/leds/leds-ns2.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 1a7ef66464b5d..8cd020b340840 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -334,15 +334,10 @@ static const struct of_device_id of_ns2_leds_match[] = {
MODULE_DEVICE_TABLE(of, of_ns2_leds_match);
#endif /* CONFIG_OF_GPIO */

-struct ns2_led_priv {
- int num_leds;
- struct ns2_led_data leds_data[];
-};
-
static int ns2_led_probe(struct platform_device *pdev)
{
struct ns2_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
- struct ns2_led_priv *priv;
+ struct ns2_led_data *leds;
int i;
int ret;

@@ -363,20 +358,18 @@ static int ns2_led_probe(struct platform_device *pdev)
return -EINVAL;
#endif /* CONFIG_OF_GPIO */

- priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds_data, pdata->num_leds), GFP_KERNEL);
- if (!priv)
+ leds = devm_kzalloc(&pdev->dev, array_size(sizeof(*leds),
+ pdata->num_leds),
+ GFP_KERNEL);
+ if (!leds)
return -ENOMEM;
- priv->num_leds = pdata->num_leds;

- for (i = 0; i < priv->num_leds; i++) {
- ret = create_ns2_led(pdev, &priv->leds_data[i],
- &pdata->leds[i]);
+ for (i = 0; i < pdata->num_leds; i++) {
+ ret = create_ns2_led(pdev, &leds[i], &pdata->leds[i]);
if (ret < 0)
return ret;
}

- platform_set_drvdata(pdev, priv);
-
return 0;
}

--
2.26.2

2020-09-17 22:39:31

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 33/50] leds: lm36274: don't iterate through children since there is only one

Do not use device_for_each_child_node. Since this driver works only with
once child node present, use device_get_next_child_node instead.
This also saves one level of indentation.

Signed-off-by: Marek Behún <[email protected]>
Cc: Dan Murphy <[email protected]>
---
drivers/leds/leds-lm36274.c | 50 +++++++++++++++++--------------------
1 file changed, 23 insertions(+), 27 deletions(-)

diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c
index 2569659836e8f..4282b7392f2b5 100644
--- a/drivers/leds/leds-lm36274.c
+++ b/drivers/leds/leds-lm36274.c
@@ -72,40 +72,36 @@ static int lm36274_parse_dt(struct lm36274 *chip)
char label[LED_MAX_NAME_SIZE];
struct device *dev = &chip->pdev->dev;
const char *name;
- int child_cnt;
- int ret = -EINVAL;
+ int ret;

/* There should only be 1 node */
- child_cnt = device_get_child_node_count(dev);
- if (child_cnt != 1)
+ if (device_get_child_node_count(dev) != 1)
return -EINVAL;

- device_for_each_child_node(dev, child) {
- ret = fwnode_property_read_string(child, "label", &name);
- if (ret)
- snprintf(label, sizeof(label), "%s::",
- chip->pdev->name);
- else
- snprintf(label, sizeof(label), "%s:%s", chip->pdev->name,
- name);
-
- chip->num_leds = fwnode_property_count_u32(child, "led-sources");
- if (chip->num_leds <= 0)
- return -ENODEV;
-
- ret = fwnode_property_read_u32_array(child, "led-sources",
- chip->led_sources,
- chip->num_leds);
- if (ret) {
- dev_err(dev, "led-sources property missing\n");
- return ret;
- }
-
- fwnode_property_read_string(child, "linux,default-trigger",
- &chip->led_dev.default_trigger);
+ child = device_get_next_child_node(dev, NULL);
+
+ ret = fwnode_property_read_string(child, "label", &name);
+ if (ret)
+ snprintf(label, sizeof(label), "%s::", chip->pdev->name);
+ else
+ snprintf(label, sizeof(label), "%s:%s", chip->pdev->name, name);

+ chip->num_leds = fwnode_property_count_u32(child, "led-sources");
+ if (chip->num_leds <= 0)
+ return -ENODEV;
+
+ ret = fwnode_property_read_u32_array(child, "led-sources",
+ chip->led_sources, chip->num_leds);
+ if (ret) {
+ dev_err(dev, "led-sources property missing\n");
+ return ret;
}

+ fwnode_property_read_string(child, "linux,default-trigger",
+ &chip->led_dev.default_trigger);
+
+ fwnode_handle_put(child);
+
chip->lmu_data.regmap = chip->regmap;
chip->lmu_data.max_brightness = MAX_BRIGHTNESS_11BIT;
chip->lmu_data.msb_brightness_reg = LM36274_REG_BRT_MSB;
--
2.26.2

2020-09-17 22:39:32

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 09/50] leds: various: fix OF node leaks

Fix OF node leaks by calling of_node_put in
for_each_available_child_of_node when the cycle breaks or returns.

Signed-off-by: Marek Behún <[email protected]>
Cc: Nikita Travkin <[email protected]>
Cc: Milo Kim <[email protected]>
Cc: Dan Murphy <[email protected]>
---
drivers/leds/leds-aw2013.c | 4 +++-
drivers/leds/leds-lp55xx-common.c | 8 ++++++--
drivers/leds/leds-turris-omnia.c | 4 +++-
3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-aw2013.c b/drivers/leds/leds-aw2013.c
index 9df7de042bca2..927c5ba32592f 100644
--- a/drivers/leds/leds-aw2013.c
+++ b/drivers/leds/leds-aw2013.c
@@ -305,8 +305,10 @@ static int aw2013_probe_dt(struct aw2013 *chip)

ret = devm_led_classdev_register_ext(&chip->client->dev,
&led->cdev, &init_data);
- if (ret < 0)
+ if (ret < 0) {
+ of_node_put(child);
return ret;
+ }

i++;
}
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 50f7f5b874636..81de1346bf5d6 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -614,8 +614,10 @@ static int lp55xx_parse_multi_led(struct device_node *np,
for_each_available_child_of_node(np, child) {
ret = lp55xx_parse_multi_led_child(child, cfg, child_number,
num_colors);
- if (ret)
+ if (ret) {
+ of_node_put(child);
return ret;
+ }
num_colors++;
}

@@ -681,8 +683,10 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,

for_each_available_child_of_node(np, child) {
ret = lp55xx_parse_logical_led(child, cfg, i);
- if (ret)
+ if (ret) {
+ of_node_put(child);
return ERR_PTR(-EINVAL);
+ }
i++;
}

diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index b2add494af14d..c276969137d7f 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -236,8 +236,10 @@ static int omnia_leds_probe(struct i2c_client *client,
led = &leds->leds[0];
for_each_available_child_of_node(np, child) {
ret = omnia_led_register(client, led, child);
- if (ret < 0)
+ if (ret < 0) {
+ of_node_put(child);
return ret;
+ }

led += ret;
}
--
2.26.2

2020-09-17 22:39:32

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 31/50] leds: lm36274: use devres LED registering function

By using devres version of LED registering function we can remove the
.remove method from this driver.

Signed-off-by: Marek Behún <[email protected]>
Cc: Dan Murphy <[email protected]>
---
drivers/leds/leds-lm36274.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c
index bfeee03a0053c..1390c71267cc2 100644
--- a/drivers/leds/leds-lm36274.c
+++ b/drivers/leds/leds-lm36274.c
@@ -147,16 +147,8 @@ static int lm36274_probe(struct platform_device *pdev)
return ret;
}

- return led_classdev_register(lm36274_data->dev, &lm36274_data->led_dev);
-}
-
-static int lm36274_remove(struct platform_device *pdev)
-{
- struct lm36274 *lm36274_data = platform_get_drvdata(pdev);
-
- led_classdev_unregister(&lm36274_data->led_dev);
-
- return 0;
+ return devm_led_classdev_register(lm36274_data->dev,
+ &lm36274_data->led_dev);
}

static const struct of_device_id of_lm36274_leds_match[] = {
@@ -167,7 +159,6 @@ MODULE_DEVICE_TABLE(of, of_lm36274_leds_match);

static struct platform_driver lm36274_driver = {
.probe = lm36274_probe,
- .remove = lm36274_remove,
.driver = {
.name = "lm36274-leds",
},
--
2.26.2

2020-09-17 22:39:35

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 01/50] leds: various: compile if COMPILE_TEST=y

These drivers can be compiled without modification when COMPILE_TEST=y:
cobalt-qube, cobalt-raq, netxbig, ns2 and s3c24xx

Signed-off-by: Marek Behún <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: Dan Murphy <[email protected]>
---
drivers/leds/Kconfig | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 4f6464a169d57..96d54e36e3b55 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -274,7 +274,7 @@ config LEDS_MT6323
config LEDS_S3C24XX
tristate "LED Support for Samsung S3C24XX GPIO LEDs"
depends on LEDS_CLASS
- depends on ARCH_S3C24XX
+ depends on ARCH_S3C24XX || COMPILE_TEST
help
This option enables support for LEDs connected to GPIO lines
on Samsung S3C24XX series CPUs, such as the S3C2410 and S3C2440.
@@ -304,13 +304,13 @@ config LEDS_WRAP
config LEDS_COBALT_QUBE
tristate "LED Support for the Cobalt Qube series front LED"
depends on LEDS_CLASS
- depends on MIPS_COBALT
+ depends on MIPS_COBALT || COMPILE_TEST
help
This option enables support for the front LED on Cobalt Qube series

config LEDS_COBALT_RAQ
bool "LED Support for the Cobalt Raq series"
- depends on LEDS_CLASS=y && MIPS_COBALT
+ depends on LEDS_CLASS=y && (MIPS_COBALT || COMPILE_TEST)
select LEDS_TRIGGERS
help
This option enables support for the Cobalt Raq series LEDs.
@@ -644,7 +644,7 @@ config LEDS_MC13783
config LEDS_NS2
tristate "LED support for Network Space v2 GPIO LEDs"
depends on LEDS_CLASS
- depends on MACH_KIRKWOOD || MACH_ARMADA_370
+ depends on MACH_KIRKWOOD || MACH_ARMADA_370 || COMPILE_TEST
default y
help
This option enables support for the dual-GPIO LEDs found on the
@@ -658,7 +658,7 @@ config LEDS_NS2
config LEDS_NETXBIG
tristate "LED support for Big Network series LEDs"
depends on LEDS_CLASS
- depends on MACH_KIRKWOOD
+ depends on MACH_KIRKWOOD || COMPILE_TEST
depends on OF_GPIO
default y
help
--
2.26.2

2020-09-17 22:39:52

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 30/50] leds: is31fl319x: use struct led_init_data when registering

By using struct led_init_data when registering we do not need to parse
`label` DT property. Moreover `label` is deprecated and if it is not
present but `color` and `function` are, LED core will compose a name
from these properties instead.

Signed-off-by: Marek Behún <[email protected]>
Cc: H. Nikolaus Schaller <[email protected]>
Cc: Grant Feng <[email protected]>
---
drivers/leds/leds-is31fl319x.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c
index 15bdbc6378d93..ef5b3e08c7313 100644
--- a/drivers/leds/leds-is31fl319x.c
+++ b/drivers/leds/leds-is31fl319x.c
@@ -269,6 +269,7 @@ static int is31fl319x_led_register(struct device *dev,
struct is31fl319x_chip *is31,
struct device_node *np)
{
+ struct led_init_data init_data = {};
struct is31fl319x_led *led;
u32 reg;
int ret;
@@ -292,9 +293,6 @@ static int is31fl319x_led_register(struct device *dev,
return -EEXIST;
}

- if (of_property_read_string(np, "label", &led->cdev.name))
- led->cdev.name = np->name;
-
ret = of_property_read_string(np, "linux,default-trigger",
&led->cdev.default_trigger);
if (ret < 0 && ret != -EINVAL) /* is optional */
@@ -303,8 +301,9 @@ static int is31fl319x_led_register(struct device *dev,
led->configured = true;
led->chip = is31;
led->cdev.brightness_set_blocking = is31fl319x_brightness_set;
+ init_data.fwnode = of_fwnode_handle(np);

- ret = devm_led_classdev_register(dev, &led->cdev);
+ ret = devm_led_classdev_register_ext(dev, &led->cdev, &init_data);
if (ret)
dev_err(dev, "Failed to register LED for node %pOF\n", np);

--
2.26.2

2020-09-17 22:39:58

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 24/50] leds: is31fl32xx: use struct led_init_data when registering

By using struct led_init_data when registering we do not need to parse
`label` DT property. Moreover `label` is deprecated and if it is not
present but `color` and `function` are, LED core will compose a name
from these properties instead.

Signed-off-by: Marek Behún <[email protected]>
Cc: H. Nikolaus Schaller <[email protected]>
Cc: David Rivshin <[email protected]>
---
drivers/leds/leds-is31fl32xx.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c
index 7bacd01289770..279f52931a177 100644
--- a/drivers/leds/leds-is31fl32xx.c
+++ b/drivers/leds/leds-is31fl32xx.c
@@ -332,9 +332,6 @@ static int is31fl32xx_parse_child_dt(const struct device *dev,
int ret = 0;
u32 reg;

- if (of_property_read_string(child, "label", &cdev->name))
- cdev->name = child->name;
-
ret = of_property_read_u32(child, "reg", &reg);
if (ret || reg < 1 || reg > led_data->priv->cdef->channels) {
dev_err(dev,
@@ -373,6 +370,7 @@ static int is31fl32xx_parse_dt(struct device *dev,
int ret = 0;

for_each_available_child_of_node(dev_of_node(dev), child) {
+ struct led_init_data init_data = {};
struct is31fl32xx_led_data *led_data =
&priv->leds[priv->num_leds];
const struct is31fl32xx_led_data *other_led_data;
@@ -388,17 +386,18 @@ static int is31fl32xx_parse_dt(struct device *dev,
led_data->channel);
if (other_led_data) {
dev_err(dev,
- "%s and %s both attempting to use channel %d\n",
- led_data->cdev.name,
- other_led_data->cdev.name,
- led_data->channel);
+ "Node %pOF 'reg' conflicts with another LED\n",
+ child);
goto err;
}

- ret = devm_led_classdev_register(dev, &led_data->cdev);
+ init_data.fwnode = of_fwnode_handle(child);
+
+ ret = devm_led_classdev_register_ext(dev, &led_data->cdev,
+ &init_data);
if (ret) {
- dev_err(dev, "failed to register PWM led for %s: %d\n",
- led_data->cdev.name, ret);
+ dev_err(dev, "Failed to register LED for %pOF: %d\n",
+ child, ret);
goto err;
}

--
2.26.2

2020-09-17 22:40:12

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 08/50] leds: various: use only available OF children

Various drivers count and iterate over OF children nodes via
of_get_child_count and for_each_child_of_node. Instead they should use
of_get_available_child_count and for_each_available_child_of_node, so
that if a given node has the `status` property set to `disabled`, the
child will be ignored.

Signed-off-by: Marek Behún <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: Andrey Utkin <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Christian Mauderer <[email protected]>
Cc: Chunyan Zhang <[email protected]>
Cc: Dan Murphy <[email protected]>
Cc: David Rivshin <[email protected]>
Cc: Haojian Zhuang <[email protected]>
Cc: H. Nikolaus Schaller <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Milo Kim <[email protected]>
Cc: NeilBrown <[email protected]>
Cc: Nikita Travkin <[email protected]>
Cc: Orson Zhai <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Philippe Retornaz <[email protected]>
Cc: Riku Voipio <[email protected]>
Cc: Simon Guinot <[email protected]>
Cc: Simon Shields <[email protected]>
Cc: Vasant Hegde <[email protected]>
Cc: Xiaotong Lu <[email protected]>
---
drivers/leds/leds-88pm860x.c | 2 +-
drivers/leds/leds-an30259a.c | 2 +-
drivers/leds/leds-aw2013.c | 2 +-
drivers/leds/leds-is31fl319x.c | 4 ++--
drivers/leds/leds-is31fl32xx.c | 4 ++--
drivers/leds/leds-lp55xx-common.c | 6 +++---
drivers/leds/leds-mc13783.c | 4 ++--
drivers/leds/leds-netxbig.c | 4 ++--
drivers/leds/leds-ns2.c | 4 ++--
drivers/leds/leds-pca9532.c | 2 +-
drivers/leds/leds-powernv.c | 2 +-
drivers/leds/leds-sc27xx-bltc.c | 4 ++--
drivers/leds/leds-spi-byte.c | 4 ++--
drivers/leds/leds-tca6507.c | 4 ++--
drivers/leds/leds-tlc591xx.c | 4 ++--
15 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c
index 2d1b3269e0f7f..508d0d859f2e0 100644
--- a/drivers/leds/leds-88pm860x.c
+++ b/drivers/leds/leds-88pm860x.c
@@ -125,7 +125,7 @@ static int pm860x_led_dt_init(struct platform_device *pdev,
dev_err(&pdev->dev, "failed to find leds node\n");
return -ENODEV;
}
- for_each_child_of_node(nproot, np) {
+ for_each_available_child_of_node(nproot, np) {
if (of_node_name_eq(np, data->name)) {
of_property_read_u32(np, "marvell,88pm860x-iset",
&iset);
diff --git a/drivers/leds/leds-an30259a.c b/drivers/leds/leds-an30259a.c
index 8ec23ccd02d69..9749f1cc3e15f 100644
--- a/drivers/leds/leds-an30259a.c
+++ b/drivers/leds/leds-an30259a.c
@@ -208,7 +208,7 @@ static int an30259a_dt_init(struct i2c_client *client,
const char *str;
struct an30259a_led *led;

- count = of_get_child_count(np);
+ count = of_get_available_child_count(np);
if (!count || count > AN30259A_MAX_LEDS)
return -EINVAL;

diff --git a/drivers/leds/leds-aw2013.c b/drivers/leds/leds-aw2013.c
index 3aeed4f68a8a3..9df7de042bca2 100644
--- a/drivers/leds/leds-aw2013.c
+++ b/drivers/leds/leds-aw2013.c
@@ -265,7 +265,7 @@ static int aw2013_probe_dt(struct aw2013 *chip)
int count, ret = 0, i = 0;
struct aw2013_led *led;

- count = of_get_child_count(np);
+ count = of_get_available_child_count(np);
if (!count || count > AW2013_MAX_LEDS)
return -EINVAL;

diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c
index e6d185ad0b7e6..4161b9dd7e488 100644
--- a/drivers/leds/leds-is31fl319x.c
+++ b/drivers/leds/leds-is31fl319x.c
@@ -220,7 +220,7 @@ static int is31fl319x_parse_dt(struct device *dev,

is31->cdef = device_get_match_data(dev);

- count = of_get_child_count(np);
+ count = of_get_available_child_count(np);

dev_dbg(dev, "probing with %d leds defined in DT\n", count);

@@ -230,7 +230,7 @@ static int is31fl319x_parse_dt(struct device *dev,
return -ENODEV;
}

- for_each_child_of_node(np, child) {
+ for_each_available_child_of_node(np, child) {
struct is31fl319x_led *led;
u32 reg;

diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c
index e0af75475e24b..7bacd01289770 100644
--- a/drivers/leds/leds-is31fl32xx.c
+++ b/drivers/leds/leds-is31fl32xx.c
@@ -372,7 +372,7 @@ static int is31fl32xx_parse_dt(struct device *dev,
struct device_node *child;
int ret = 0;

- for_each_child_of_node(dev_of_node(dev), child) {
+ for_each_available_child_of_node(dev_of_node(dev), child) {
struct is31fl32xx_led_data *led_data =
&priv->leds[priv->num_leds];
const struct is31fl32xx_led_data *other_led_data;
@@ -435,7 +435,7 @@ static int is31fl32xx_probe(struct i2c_client *client,

cdef = device_get_match_data(dev);

- count = of_get_child_count(dev_of_node(dev));
+ count = of_get_available_child_count(dev_of_node(dev));
if (!count)
return -EINVAL;

diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 56210f4ad919a..50f7f5b874636 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -611,7 +611,7 @@ static int lp55xx_parse_multi_led(struct device_node *np,
struct device_node *child;
int num_colors = 0, ret;

- for_each_child_of_node(np, child) {
+ for_each_available_child_of_node(np, child) {
ret = lp55xx_parse_multi_led_child(child, cfg, child_number,
num_colors);
if (ret)
@@ -665,7 +665,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
if (!pdata)
return ERR_PTR(-ENOMEM);

- num_channels = of_get_child_count(np);
+ num_channels = of_get_available_child_count(np);
if (num_channels == 0) {
dev_err(dev, "no LED channels\n");
return ERR_PTR(-EINVAL);
@@ -679,7 +679,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
pdata->num_channels = num_channels;
cfg->max_channel = chip->cfg->max_channel;

- for_each_child_of_node(np, child) {
+ for_each_available_child_of_node(np, child) {
ret = lp55xx_parse_logical_led(child, cfg, i);
if (ret)
return ERR_PTR(-EINVAL);
diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
index ee37f4a2d65b4..675502c15c2b4 100644
--- a/drivers/leds/leds-mc13783.c
+++ b/drivers/leds/leds-mc13783.c
@@ -131,7 +131,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
if (ret)
goto out_node_put;

- pdata->num_leds = of_get_child_count(parent);
+ pdata->num_leds = of_get_available_child_count(parent);

pdata->led = devm_kcalloc(dev, pdata->num_leds, sizeof(*pdata->led),
GFP_KERNEL);
@@ -140,7 +140,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
goto out_node_put;
}

- for_each_child_of_node(parent, child) {
+ for_each_available_child_of_node(parent, child) {
const char *str;
u32 tmp;

diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
index 578dd18b21e3b..f41e176cf6c49 100644
--- a/drivers/leds/leds-netxbig.c
+++ b/drivers/leds/leds-netxbig.c
@@ -485,7 +485,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev,
}

/* LEDs */
- num_leds = of_get_child_count(np);
+ num_leds = of_get_available_child_count(np);
if (!num_leds) {
dev_err(dev, "No LED subnodes found in DT\n");
return -ENODEV;
@@ -496,7 +496,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev,
return -ENOMEM;

led = leds;
- for_each_child_of_node(np, child) {
+ for_each_available_child_of_node(np, child) {
const char *string;
int *mode_val;
int num_modes;
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 9cbd2d7251af9..22d38c83b6dca 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -251,7 +251,7 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
struct ns2_led *led, *leds;
int ret, num_leds = 0;

- num_leds = of_get_child_count(np);
+ num_leds = of_get_available_child_count(np);
if (!num_leds)
return -ENODEV;

@@ -261,7 +261,7 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
return -ENOMEM;

led = leds;
- for_each_child_of_node(np, child) {
+ for_each_available_child_of_node(np, child) {
const char *string;
int i, num_modes;
struct ns2_led_modval *modval;
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index b1ae34e509588..f834550999ddb 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -478,7 +478,7 @@ pca9532_of_populate_pdata(struct device *dev, struct device_node *np)
if (!pdata)
return ERR_PTR(-ENOMEM);

- for_each_child_of_node(np, child) {
+ for_each_available_child_of_node(np, child) {
if (of_property_read_string(child, "label",
&pdata->leds[i].name))
pdata->leds[i].name = child->name;
diff --git a/drivers/leds/leds-powernv.c b/drivers/leds/leds-powernv.c
index d803726300ff4..86f288425b2f6 100644
--- a/drivers/leds/leds-powernv.c
+++ b/drivers/leds/leds-powernv.c
@@ -250,7 +250,7 @@ static int powernv_led_classdev(struct platform_device *pdev,
struct powernv_led_data *powernv_led;
struct device *dev = &pdev->dev;

- for_each_child_of_node(led_node, np) {
+ for_each_available_child_of_node(led_node, np) {
p = of_find_property(np, "led-types", NULL);

while ((cur = of_prop_next_string(p, cur)) != NULL) {
diff --git a/drivers/leds/leds-sc27xx-bltc.c b/drivers/leds/leds-sc27xx-bltc.c
index 7ba09e0140739..4947894056305 100644
--- a/drivers/leds/leds-sc27xx-bltc.c
+++ b/drivers/leds/leds-sc27xx-bltc.c
@@ -281,7 +281,7 @@ static int sc27xx_led_probe(struct platform_device *pdev)
u32 base, count, reg;
int err;

- count = of_get_child_count(np);
+ count = of_get_available_child_count(np);
if (!count || count > SC27XX_LEDS_MAX)
return -EINVAL;

@@ -305,7 +305,7 @@ static int sc27xx_led_probe(struct platform_device *pdev)
return err;
}

- for_each_child_of_node(np, child) {
+ for_each_available_child_of_node(np, child) {
err = of_property_read_u32(child, "reg", &reg);
if (err) {
of_node_put(child);
diff --git a/drivers/leds/leds-spi-byte.c b/drivers/leds/leds-spi-byte.c
index 8535c6b1aebec..49909a68e4987 100644
--- a/drivers/leds/leds-spi-byte.c
+++ b/drivers/leds/leds-spi-byte.c
@@ -87,11 +87,11 @@ static int spi_byte_probe(struct spi_device *spi)
const char *state;
int ret;

- if (of_get_child_count(dev_of_node(dev)) != 1) {
+ if (of_get_available_child_count(dev_of_node(dev)) != 1) {
dev_err(dev, "Device must have exactly one LED sub-node.");
return -EINVAL;
}
- child = of_get_next_child(dev_of_node(dev), NULL);
+ child = of_get_next_available_child(dev_of_node(dev), NULL);

led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
if (!led)
diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c
index d44b64af6d6e7..a7e9fd85b6dd5 100644
--- a/drivers/leds/leds-tca6507.c
+++ b/drivers/leds/leds-tca6507.c
@@ -694,7 +694,7 @@ tca6507_led_dt_init(struct i2c_client *client)
struct led_info *tca_leds;
int count;

- count = of_get_child_count(np);
+ count = of_get_available_child_count(np);
if (!count || count > NUM_LEDS)
return ERR_PTR(-ENODEV);

@@ -703,7 +703,7 @@ tca6507_led_dt_init(struct i2c_client *client)
if (!tca_leds)
return ERR_PTR(-ENOMEM);

- for_each_child_of_node(np, child) {
+ for_each_available_child_of_node(np, child) {
struct led_info led;
u32 reg;
int ret;
diff --git a/drivers/leds/leds-tlc591xx.c b/drivers/leds/leds-tlc591xx.c
index f4d5785f0068f..5e84a0c7aacbd 100644
--- a/drivers/leds/leds-tlc591xx.c
+++ b/drivers/leds/leds-tlc591xx.c
@@ -158,7 +158,7 @@ tlc591xx_probe(struct i2c_client *client,
if (!np)
return -ENODEV;

- count = of_get_child_count(np);
+ count = of_get_available_child_count(np);
if (!count || count > tlc591xx->max_leds)
return -EINVAL;

@@ -180,7 +180,7 @@ tlc591xx_probe(struct i2c_client *client,
if (err < 0)
return err;

- for_each_child_of_node(np, child) {
+ for_each_available_child_of_node(np, child) {
struct tlc591xx_led *led;
struct led_init_data init_data = {};

--
2.26.2

2020-09-17 22:40:17

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 19/50] leds: mt6323: cosmetic change: use helper variable

Use helper variable dev instead of always writing &pdev->dev.

Signed-off-by: Marek Behún <[email protected]>
Cc: Sean Wang <[email protected]>
Cc: John Crispin <[email protected]>
Cc: Ryder Lee <[email protected]>
---
drivers/leds/leds-mt6323.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c
index f6c71fd691bb8..5119dcc0aef24 100644
--- a/drivers/leds/leds-mt6323.c
+++ b/drivers/leds/leds-mt6323.c
@@ -368,9 +368,9 @@ static int mt6323_led_set_dt_default(struct led_classdev *cdev,
static int mt6323_led_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *np = dev_of_node(&pdev->dev);
+ struct device_node *np = dev_of_node(dev);
struct device_node *child;
- struct mt6397_chip *hw = dev_get_drvdata(pdev->dev.parent);
+ struct mt6397_chip *hw = dev_get_drvdata(dev->parent);
struct mt6323_leds *leds;
struct mt6323_led *led;
int ret;
@@ -443,8 +443,7 @@ static int mt6323_led_probe(struct platform_device *pdev)
ret = devm_led_classdev_register_ext(dev, &leds->led[reg]->cdev,
&init_data);
if (ret) {
- dev_err(&pdev->dev, "Failed to register LED: %d\n",
- ret);
+ dev_err(dev, "Failed to register LED: %d\n", ret);
goto put_child_node;
}
}
--
2.26.2

2020-09-17 22:40:22

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 13/50] leds: bcm6358: cosmetic: use reverse christmas tree

Only a cosmetic change: use reverse christmas tree variables
declaration.

Signed-off-by: Marek Behún <[email protected]>
Cc: Álvaro Fernández Rojas <[email protected]>
Cc: Kevin Cernekee <[email protected]>
Cc: Jaedon Shin <[email protected]>
---
drivers/leds/leds-bcm6358.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-bcm6358.c b/drivers/leds/leds-bcm6358.c
index 49f703c59ecdc..71c49d5fa811f 100644
--- a/drivers/leds/leds-bcm6358.c
+++ b/drivers/leds/leds-bcm6358.c
@@ -150,11 +150,10 @@ static int bcm6358_led(struct device *dev, struct device_node *nc, u32 reg,
static int bcm6358_leds_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *np = dev_of_node(&pdev->dev);
- struct device_node *child;
+ struct device_node *np, *child;
void __iomem *mem;
- spinlock_t *lock; /* memory lock */
unsigned long val;
+ spinlock_t *lock; /* memory lock */
u32 clk_div;

mem = devm_platform_ioremap_resource(pdev, 0);
@@ -167,6 +166,8 @@ static int bcm6358_leds_probe(struct platform_device *pdev)

spin_lock_init(lock);

+ np = dev_of_node(dev);
+
val = bcm6358_led_busy(mem);
val &= ~(BCM6358_SLED_POLARITY | BCM6358_SLED_CLKDIV_MASK);
if (of_property_read_bool(np, "brcm,clk-dat-low"))
@@ -189,8 +190,8 @@ static int bcm6358_leds_probe(struct platform_device *pdev)
bcm6358_led_write(mem + BCM6358_REG_CTRL, val);

for_each_available_child_of_node(np, child) {
- int rc;
u32 reg;
+ int rc;

if (of_property_read_u32(child, "reg", &reg))
continue;
--
2.26.2

2020-09-17 22:40:25

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 18/50] leds: mt6323: use struct led_init_data when registering

By using struct led_init_data when registering we do not need to parse
`label` DT property. Moreover `label` is deprecated and if it is not
present but `color` and `function` are, LED core will compose a name
from these properties instead.

Since init_data is passed with fwnode handle, we do not need to set
the of_node member of the newly created LED classdev.

Signed-off-by: Marek Behún <[email protected]>
Cc: Sean Wang <[email protected]>
Cc: John Crispin <[email protected]>
Cc: Ryder Lee <[email protected]>
---
drivers/leds/leds-mt6323.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c
index 2c46b75030358..f6c71fd691bb8 100644
--- a/drivers/leds/leds-mt6323.c
+++ b/drivers/leds/leds-mt6323.c
@@ -342,7 +342,6 @@ static int mt6323_led_set_dt_default(struct led_classdev *cdev,
const char *state;
int ret = 0;

- led->cdev.name = of_get_property(np, "label", NULL) ? : np->name;
led->cdev.default_trigger = of_get_property(np,
"linux,default-trigger",
NULL);
@@ -402,6 +401,8 @@ static int mt6323_led_probe(struct platform_device *pdev)
}

for_each_available_child_of_node(np, child) {
+ struct led_init_data init_data = {};
+
ret = of_property_read_u32(child, "reg", &reg);
if (ret) {
dev_err(dev, "Failed to read led 'reg' property\n");
@@ -437,13 +438,15 @@ static int mt6323_led_probe(struct platform_device *pdev)
goto put_child_node;
}

- ret = devm_led_classdev_register(dev, &leds->led[reg]->cdev);
+ init_data.fwnode = of_fwnode_handle(child);
+
+ ret = devm_led_classdev_register_ext(dev, &leds->led[reg]->cdev,
+ &init_data);
if (ret) {
dev_err(&pdev->dev, "Failed to register LED: %d\n",
ret);
goto put_child_node;
}
- leds->led[reg]->cdev.dev->of_node = child;
}

return 0;
--
2.26.2

2020-09-17 22:40:46

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 06/50] leds: various: use dev_of_node(dev) instead of dev->of_node

The dev_of_node function should be preferred.

Signed-off-by: Marek Behún <[email protected]>
Cc: Orson Zhai <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: Chunyan Zhang <[email protected]>
Cc: Sean Wang <[email protected]>
Cc: Matthias Brugger <[email protected]>
Cc: Riku Voipio <[email protected]>
---
drivers/leds/leds-88pm860x.c | 4 ++--
drivers/leds/leds-aat1290.c | 2 +-
drivers/leds/leds-an30259a.c | 2 +-
drivers/leds/leds-aw2013.c | 2 +-
drivers/leds/leds-bcm6328.c | 2 +-
drivers/leds/leds-bcm6358.c | 2 +-
drivers/leds/leds-is31fl319x.c | 2 +-
drivers/leds/leds-is31fl32xx.c | 4 ++--
drivers/leds/leds-ktd2692.c | 4 ++--
drivers/leds/leds-lp5521.c | 2 +-
drivers/leds/leds-lp5523.c | 2 +-
drivers/leds/leds-lp5562.c | 2 +-
drivers/leds/leds-lp8501.c | 2 +-
drivers/leds/leds-lp8860.c | 2 +-
drivers/leds/leds-lt3593.c | 2 +-
drivers/leds/leds-max77693.c | 2 +-
drivers/leds/leds-mc13783.c | 4 ++--
drivers/leds/leds-mt6323.c | 2 +-
drivers/leds/leds-netxbig.c | 2 +-
drivers/leds/leds-ns2.c | 2 +-
drivers/leds/leds-pca9532.c | 2 +-
drivers/leds/leds-pm8058.c | 2 +-
drivers/leds/leds-sc27xx-bltc.c | 2 +-
drivers/leds/leds-spi-byte.c | 4 ++--
drivers/leds/leds-syscon.c | 4 ++--
drivers/leds/leds-tca6507.c | 4 ++--
drivers/leds/leds-tlc591xx.c | 2 +-
drivers/leds/leds-turris-omnia.c | 2 +-
28 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c
index 465c3755cf2e4..2d1b3269e0f7f 100644
--- a/drivers/leds/leds-88pm860x.c
+++ b/drivers/leds/leds-88pm860x.c
@@ -118,9 +118,9 @@ static int pm860x_led_dt_init(struct platform_device *pdev,
struct device_node *nproot, *np;
int iset = 0;

- if (!pdev->dev.parent->of_node)
+ if (!dev_of_node(pdev->dev.parent))
return -ENODEV;
- nproot = of_get_child_by_name(pdev->dev.parent->of_node, "leds");
+ nproot = of_get_child_by_name(dev_of_node(pdev->dev.parent), "leds");
if (!nproot) {
dev_err(&pdev->dev, "failed to find leds node\n");
return -ENODEV;
diff --git a/drivers/leds/leds-aat1290.c b/drivers/leds/leds-aat1290.c
index c78a29ab8e9fb..88cc5edabb581 100644
--- a/drivers/leds/leds-aat1290.c
+++ b/drivers/leds/leds-aat1290.c
@@ -248,7 +248,7 @@ static int aat1290_led_parse_dt(struct aat1290_led *led,
}
#endif

- child_node = of_get_next_available_child(dev->of_node, NULL);
+ child_node = of_get_next_available_child(dev_of_node(dev), NULL);
if (!child_node) {
dev_err(dev, "No DT child node found for connected LED.\n");
return -EINVAL;
diff --git a/drivers/leds/leds-an30259a.c b/drivers/leds/leds-an30259a.c
index 82350a28a5644..8ec23ccd02d69 100644
--- a/drivers/leds/leds-an30259a.c
+++ b/drivers/leds/leds-an30259a.c
@@ -202,7 +202,7 @@ static int an30259a_blink_set(struct led_classdev *cdev,
static int an30259a_dt_init(struct i2c_client *client,
struct an30259a *chip)
{
- struct device_node *np = client->dev.of_node, *child;
+ struct device_node *np = dev_of_node(&client->dev), *child;
int count, ret;
int i = 0;
const char *str;
diff --git a/drivers/leds/leds-aw2013.c b/drivers/leds/leds-aw2013.c
index d709cc1f949e3..3aeed4f68a8a3 100644
--- a/drivers/leds/leds-aw2013.c
+++ b/drivers/leds/leds-aw2013.c
@@ -261,7 +261,7 @@ static int aw2013_blink_set(struct led_classdev *cdev,

static int aw2013_probe_dt(struct aw2013 *chip)
{
- struct device_node *np = chip->client->dev.of_node, *child;
+ struct device_node *np = dev_of_node(&chip->client->dev), *child;
int count, ret = 0, i = 0;
struct aw2013_led *led;

diff --git a/drivers/leds/leds-bcm6328.c b/drivers/leds/leds-bcm6328.c
index 65a3857efa4ed..c73097758e353 100644
--- a/drivers/leds/leds-bcm6328.c
+++ b/drivers/leds/leds-bcm6328.c
@@ -395,7 +395,7 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg,
static int bcm6328_leds_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *np = pdev->dev.of_node;
+ struct device_node *np = dev_of_node(&pdev->dev);
struct device_node *child;
void __iomem *mem;
spinlock_t *lock; /* memory lock */
diff --git a/drivers/leds/leds-bcm6358.c b/drivers/leds/leds-bcm6358.c
index 44fd1ba4be57e..289dfc412eda4 100644
--- a/drivers/leds/leds-bcm6358.c
+++ b/drivers/leds/leds-bcm6358.c
@@ -149,7 +149,7 @@ static int bcm6358_led(struct device *dev, struct device_node *nc, u32 reg,
static int bcm6358_leds_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *np = pdev->dev.of_node;
+ struct device_node *np = dev_of_node(&pdev->dev);
struct device_node *child;
void __iomem *mem;
spinlock_t *lock; /* memory lock */
diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c
index b039ffa33559c..e6d185ad0b7e6 100644
--- a/drivers/leds/leds-is31fl319x.c
+++ b/drivers/leds/leds-is31fl319x.c
@@ -202,7 +202,7 @@ static int is31fl319x_parse_child_dt(const struct device *dev,
static int is31fl319x_parse_dt(struct device *dev,
struct is31fl319x_chip *is31)
{
- struct device_node *np = dev->of_node, *child;
+ struct device_node *np = dev_of_node(dev), *child;
int count;
int ret;

diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c
index 408eb5fad4cb0..e0af75475e24b 100644
--- a/drivers/leds/leds-is31fl32xx.c
+++ b/drivers/leds/leds-is31fl32xx.c
@@ -372,7 +372,7 @@ static int is31fl32xx_parse_dt(struct device *dev,
struct device_node *child;
int ret = 0;

- for_each_child_of_node(dev->of_node, child) {
+ for_each_child_of_node(dev_of_node(dev), child) {
struct is31fl32xx_led_data *led_data =
&priv->leds[priv->num_leds];
const struct is31fl32xx_led_data *other_led_data;
@@ -435,7 +435,7 @@ static int is31fl32xx_probe(struct i2c_client *client,

cdef = device_get_match_data(dev);

- count = of_get_child_count(dev->of_node);
+ count = of_get_child_count(dev_of_node(dev));
if (!count)
return -EINVAL;

diff --git a/drivers/leds/leds-ktd2692.c b/drivers/leds/leds-ktd2692.c
index 63917db8cac39..846c6ecf1a5b0 100644
--- a/drivers/leds/leds-ktd2692.c
+++ b/drivers/leds/leds-ktd2692.c
@@ -259,11 +259,11 @@ static void ktd2692_setup(struct ktd2692_context *led)
static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
struct ktd2692_led_config_data *cfg)
{
- struct device_node *np = dev->of_node;
+ struct device_node *np = dev_of_node(dev);
struct device_node *child_node;
int ret;

- if (!dev->of_node)
+ if (!dev_of_node(dev))
return -ENXIO;

led->ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_ASIS);
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index ef8c3bfa8f3c4..a9e7507c998cd 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -523,7 +523,7 @@ static int lp5521_probe(struct i2c_client *client,
struct lp55xx_chip *chip;
struct lp55xx_led *led;
struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev);
- struct device_node *np = client->dev.of_node;
+ struct device_node *np = dev_of_node(&client->dev);

chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index f55d97258d5e7..fc433e63b1dc0 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -891,7 +891,7 @@ static int lp5523_probe(struct i2c_client *client,
struct lp55xx_chip *chip;
struct lp55xx_led *led;
struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev);
- struct device_node *np = client->dev.of_node;
+ struct device_node *np = dev_of_node(&client->dev);

chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c
index 7ecdd199d7efc..31c14016d2896 100644
--- a/drivers/leds/leds-lp5562.c
+++ b/drivers/leds/leds-lp5562.c
@@ -518,7 +518,7 @@ static int lp5562_probe(struct i2c_client *client,
struct lp55xx_chip *chip;
struct lp55xx_led *led;
struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev);
- struct device_node *np = client->dev.of_node;
+ struct device_node *np = dev_of_node(&client->dev);

chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c
index ac2c31db4a65c..2d2fda2ab1046 100644
--- a/drivers/leds/leds-lp8501.c
+++ b/drivers/leds/leds-lp8501.c
@@ -306,7 +306,7 @@ static int lp8501_probe(struct i2c_client *client,
struct lp55xx_chip *chip;
struct lp55xx_led *led;
struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev);
- struct device_node *np = client->dev.of_node;
+ struct device_node *np = dev_of_node(&client->dev);

chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
diff --git a/drivers/leds/leds-lp8860.c b/drivers/leds/leds-lp8860.c
index 6eb323212da3c..b69ed81d52ab4 100644
--- a/drivers/leds/leds-lp8860.c
+++ b/drivers/leds/leds-lp8860.c
@@ -380,7 +380,7 @@ static int lp8860_probe(struct i2c_client *client,
{
int ret;
struct lp8860_led *led;
- struct device_node *np = client->dev.of_node;
+ struct device_node *np = dev_of_node(&client->dev);
struct device_node *child_node;
struct led_init_data init_data = {};

diff --git a/drivers/leds/leds-lt3593.c b/drivers/leds/leds-lt3593.c
index 9079850e6ea44..c2d7ffebacc56 100644
--- a/drivers/leds/leds-lt3593.c
+++ b/drivers/leds/leds-lt3593.c
@@ -68,7 +68,7 @@ static int lt3593_led_probe(struct platform_device *pdev)
struct led_init_data init_data = {};
const char *tmp;

- if (!dev->of_node)
+ if (!dev_of_node(dev))
return -ENODEV;

led_data = devm_kzalloc(dev, sizeof(*led_data), GFP_KERNEL);
diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c
index 1d8e2ffe7ad46..2baac552a74d4 100644
--- a/drivers/leds/leds-max77693.c
+++ b/drivers/leds/leds-max77693.c
@@ -599,7 +599,7 @@ static int max77693_led_parse_dt(struct max77693_led_device *led,
{
struct device *dev = &led->pdev->dev;
struct max77693_sub_led *sub_leds = led->sub_leds;
- struct device_node *node = dev->of_node, *child_node;
+ struct device_node *node = dev_of_node(dev), *child_node;
struct property *prop;
u32 led_sources[2];
int i, ret, fled_id;
diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
index 5cd810c545f3e..ee37f4a2d65b4 100644
--- a/drivers/leds/leds-mc13783.c
+++ b/drivers/leds/leds-mc13783.c
@@ -121,7 +121,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
if (!pdata)
return ERR_PTR(-ENOMEM);

- parent = of_get_child_by_name(dev->parent->of_node, "leds");
+ parent = of_get_child_by_name(dev_of_node(dev->parent), "leds");
if (!parent)
goto out_node_put;

@@ -192,7 +192,7 @@ static int __init mc13xxx_led_probe(struct platform_device *pdev)
leds->master = mcdev;
platform_set_drvdata(pdev, leds);

- if (dev->parent->of_node) {
+ if (dev_of_node(dev->parent)) {
pdata = mc13xxx_led_probe_dt(pdev);
if (IS_ERR(pdata))
return PTR_ERR(pdata);
diff --git a/drivers/leds/leds-mt6323.c b/drivers/leds/leds-mt6323.c
index 80b57a39445cb..2c46b75030358 100644
--- a/drivers/leds/leds-mt6323.c
+++ b/drivers/leds/leds-mt6323.c
@@ -369,7 +369,7 @@ static int mt6323_led_set_dt_default(struct led_classdev *cdev,
static int mt6323_led_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *np = pdev->dev.of_node;
+ struct device_node *np = dev_of_node(&pdev->dev);
struct device_node *child;
struct mt6397_chip *hw = dev_get_drvdata(pdev->dev.parent);
struct mt6323_leds *leds;
diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
index 7f3313e321fa6..578dd18b21e3b 100644
--- a/drivers/leds/leds-netxbig.c
+++ b/drivers/leds/leds-netxbig.c
@@ -419,7 +419,7 @@ static int netxbig_gpio_ext_get(struct device *dev,
static int netxbig_leds_get_of_pdata(struct device *dev,
struct netxbig_led_platform_data *pdata)
{
- struct device_node *np = dev->of_node;
+ struct device_node *np = dev_of_node(dev);
struct device_node *gpio_ext_np;
struct platform_device *gpio_ext_pdev;
struct device *gpio_ext_dev;
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index bd806e7c8017b..9cbd2d7251af9 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -246,7 +246,7 @@ static void delete_ns2_led(struct ns2_led_data *led_dat)
static int
ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
{
- struct device_node *np = dev->of_node;
+ struct device_node *np = dev_of_node(dev);
struct device_node *child;
struct ns2_led *led, *leds;
int ret, num_leds = 0;
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index 7d515d5e57bd0..b1ae34e509588 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -507,7 +507,7 @@ static int pca9532_probe(struct i2c_client *client,
struct pca9532_data *data = i2c_get_clientdata(client);
struct pca9532_platform_data *pca9532_pdata =
dev_get_platdata(&client->dev);
- struct device_node *np = client->dev.of_node;
+ struct device_node *np = dev_of_node(&client->dev);

if (!pca9532_pdata) {
if (np) {
diff --git a/drivers/leds/leds-pm8058.c b/drivers/leds/leds-pm8058.c
index d9e8ea80cd167..dcd7d8c3d6b44 100644
--- a/drivers/leds/leds-pm8058.c
+++ b/drivers/leds/leds-pm8058.c
@@ -88,7 +88,7 @@ static enum led_brightness pm8058_led_get(struct led_classdev *cled)
static int pm8058_led_probe(struct platform_device *pdev)
{
struct pm8058_led *led;
- struct device_node *np = pdev->dev.of_node;
+ struct device_node *np = dev_of_node(&pdev->dev);
int ret;
struct regmap *map;
const char *state;
diff --git a/drivers/leds/leds-sc27xx-bltc.c b/drivers/leds/leds-sc27xx-bltc.c
index 3401ad389c8d9..7ba09e0140739 100644
--- a/drivers/leds/leds-sc27xx-bltc.c
+++ b/drivers/leds/leds-sc27xx-bltc.c
@@ -276,7 +276,7 @@ static int sc27xx_led_register(struct device *dev, struct sc27xx_led_priv *priv)
static int sc27xx_led_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *np = dev->of_node, *child;
+ struct device_node *np = dev_of_node(dev), *child;
struct sc27xx_led_priv *priv;
u32 base, count, reg;
int err;
diff --git a/drivers/leds/leds-spi-byte.c b/drivers/leds/leds-spi-byte.c
index 21ec02c4f8dac..8535c6b1aebec 100644
--- a/drivers/leds/leds-spi-byte.c
+++ b/drivers/leds/leds-spi-byte.c
@@ -87,11 +87,11 @@ static int spi_byte_probe(struct spi_device *spi)
const char *state;
int ret;

- if (of_get_child_count(dev->of_node) != 1) {
+ if (of_get_child_count(dev_of_node(dev)) != 1) {
dev_err(dev, "Device must have exactly one LED sub-node.");
return -EINVAL;
}
- child = of_get_next_child(dev->of_node, NULL);
+ child = of_get_next_child(dev_of_node(dev), NULL);

led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
if (!led)
diff --git a/drivers/leds/leds-syscon.c b/drivers/leds/leds-syscon.c
index b56a5c82bf759..0c9b2c4fecbf3 100644
--- a/drivers/leds/leds-syscon.c
+++ b/drivers/leds/leds-syscon.c
@@ -56,7 +56,7 @@ static void syscon_led_set(struct led_classdev *led_cdev,
static int syscon_led_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *np = dev->of_node;
+ struct device_node *np = dev_of_node(dev);
struct device *parent;
struct regmap *map;
struct syscon_led *sled;
@@ -68,7 +68,7 @@ static int syscon_led_probe(struct platform_device *pdev)
dev_err(dev, "no parent for syscon LED\n");
return -ENODEV;
}
- map = syscon_node_to_regmap(parent->of_node);
+ map = syscon_node_to_regmap(dev_of_node(parent));
if (IS_ERR(map)) {
dev_err(dev, "no regmap for syscon LED parent\n");
return PTR_ERR(map);
diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c
index 1128ac75443c0..d44b64af6d6e7 100644
--- a/drivers/leds/leds-tca6507.c
+++ b/drivers/leds/leds-tca6507.c
@@ -656,7 +656,7 @@ static int tca6507_probe_gpios(struct i2c_client *client,
tca->gpio.set = tca6507_gpio_set_value;
tca->gpio.parent = &client->dev;
#ifdef CONFIG_OF_GPIO
- tca->gpio.of_node = of_node_get(client->dev.of_node);
+ tca->gpio.of_node = of_node_get(dev_of_node(&client->dev));
#endif
err = gpiochip_add_data(&tca->gpio, tca);
if (err) {
@@ -689,7 +689,7 @@ static void tca6507_remove_gpio(struct tca6507_chip *tca)
static struct tca6507_platform_data *
tca6507_led_dt_init(struct i2c_client *client)
{
- struct device_node *np = client->dev.of_node, *child;
+ struct device_node *np = dev_of_node(&client->dev), *child;
struct tca6507_platform_data *pdata;
struct led_info *tca_leds;
int count;
diff --git a/drivers/leds/leds-tlc591xx.c b/drivers/leds/leds-tlc591xx.c
index aeedf1aa62976..f4d5785f0068f 100644
--- a/drivers/leds/leds-tlc591xx.c
+++ b/drivers/leds/leds-tlc591xx.c
@@ -148,7 +148,7 @@ static int
tlc591xx_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- struct device_node *np = client->dev.of_node, *child;
+ struct device_node *np = dev_of_node(&client->dev), *child;
struct device *dev = &client->dev;
const struct tlc591xx *tlc591xx;
struct tlc591xx_priv *priv;
diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index 2a69d2085a225..b2add494af14d 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -210,7 +210,7 @@ static int omnia_leds_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct device *dev = &client->dev;
- struct device_node *np = dev->of_node, *child;
+ struct device_node *np = dev_of_node(dev), *child;
struct omnia_leds *leds;
struct omnia_led *led;
int ret, count;
--
2.26.2

2020-09-17 22:41:18

by Marek Behún

[permalink] [raw]
Subject: [PATCH leds v2 03/50] leds: fsg: compile if COMPILE_TEST=y

This driver can be compiled on other platforms with small change if
COMPILE_TEST=y.

Signed-off-by: Marek Behún <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: Dan Murphy <[email protected]>
Cc: Rod Whitby <[email protected]>
---
drivers/leds/Kconfig | 2 +-
drivers/leds/leds-fsg.c | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index a008170e73cd8..7f3d16d4f0652 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -290,7 +290,7 @@ config LEDS_NET48XX
config LEDS_FSG
tristate "LED Support for the Freecom FSG-3"
depends on LEDS_CLASS
- depends on MACH_FSG
+ depends on MACH_FSG || COMPILE_TEST
help
This option enables support for the LEDs on the Freecom FSG-3.

diff --git a/drivers/leds/leds-fsg.c b/drivers/leds/leds-fsg.c
index bc6b420637d61..1ffb34baee341 100644
--- a/drivers/leds/leds-fsg.c
+++ b/drivers/leds/leds-fsg.c
@@ -16,7 +16,13 @@
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/io.h>
+
+#if IS_ENABLED(MACH_FSG)
#include <mach/hardware.h>
+#else
+/* for COMPILE_TEST */
+#define IXP4XX_EXP_BUS_BASE(x) (0x12345678 + (x))
+#endif

#define FSG_LED_WLAN_BIT 0
#define FSG_LED_WAN_BIT 1
--
2.26.2

2020-09-18 07:11:44

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH leds v2 05/50] leds: various: guard of_match_table member value with of_match_ptr

Hi Marek,

On Fri, Sep 18, 2020 at 12:32:53AM +0200, Marek Beh?n wrote:
> Change
> .of_match_table = xxx,
> to
> .of_match_table = of_match_ptr(xxx),
> in various drivers.
>
> This should be standard even for drivers that depend on OF.

After this patch, none of these drivers will work on ACPI systems anymore.

How many of them really depend on OF?

--
Regards,

Sakari Ailus

2020-09-18 09:22:17

by Marek Behún

[permalink] [raw]
Subject: Re: [PATCH leds v2 05/50] leds: various: guard of_match_table member value with of_match_ptr

On Fri, 18 Sep 2020 09:15:00 +0300
Sakari Ailus <[email protected]> wrote:

> Hi Marek,
>
> On Fri, Sep 18, 2020 at 12:32:53AM +0200, Marek Behún wrote:
> > Change
> > .of_match_table = xxx,
> > to
> > .of_match_table = of_match_ptr(xxx),
> > in various drivers.
> >
> > This should be standard even for drivers that depend on OF.
>
> After this patch, none of these drivers will work on ACPI systems anymore.

Hi Sakari,

I don't understand. Why not? Does ACPI subsystem parse of_match_table
as well?

2020-09-18 09:59:57

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH leds v2 05/50] leds: various: guard of_match_table member value with of_match_ptr

On Fri, Sep 18, 2020 at 11:20:58AM +0200, Marek Behun wrote:
> On Fri, 18 Sep 2020 09:15:00 +0300
> Sakari Ailus <[email protected]> wrote:
>
> > Hi Marek,
> >
> > On Fri, Sep 18, 2020 at 12:32:53AM +0200, Marek Beh?n wrote:
> > > Change
> > > .of_match_table = xxx,
> > > to
> > > .of_match_table = of_match_ptr(xxx),
> > > in various drivers.
> > >
> > > This should be standard even for drivers that depend on OF.
> >
> > After this patch, none of these drivers will work on ACPI systems anymore.

^

If CONFIG_OF is disabled, that is.

>
> Hi Sakari,
>
> I don't understand. Why not? Does ACPI subsystem parse of_match_table
> as well?

It does. The compatible string is used the same way as in DT for matching
devices with "PRP0001" _HID or _CID.

Please read Documentation/firmware-guide/acpi/enumeration.rst .

IOW, you can safely do the above only for drivers that depend on OF in
Kconfig. Otherwise you'll probably break something.

--
Sakari Ailus

2020-09-18 10:14:14

by Marek Behún

[permalink] [raw]
Subject: Re: [PATCH leds v2 05/50] leds: various: guard of_match_table member value with of_match_ptr

On Fri, 18 Sep 2020 12:57:59 +0300
Sakari Ailus <[email protected]> wrote:

> On Fri, Sep 18, 2020 at 11:20:58AM +0200, Marek Behun wrote:
> > On Fri, 18 Sep 2020 09:15:00 +0300
> > Sakari Ailus <[email protected]> wrote:
> >
> > > Hi Marek,
> > >
> > > On Fri, Sep 18, 2020 at 12:32:53AM +0200, Marek Behún wrote:
> > > > Change
> > > > .of_match_table = xxx,
> > > > to
> > > > .of_match_table = of_match_ptr(xxx),
> > > > in various drivers.
> > > >
> > > > This should be standard even for drivers that depend on OF.
> > >
> > > After this patch, none of these drivers will work on ACPI systems anymore.
>
> ^
>
> If CONFIG_OF is disabled, that is.
>
> >
> > Hi Sakari,
> >
> > I don't understand. Why not? Does ACPI subsystem parse of_match_table
> > as well?
>
> It does. The compatible string is used the same way as in DT for matching
> devices with "PRP0001" _HID or _CID.
>
> Please read Documentation/firmware-guide/acpi/enumeration.rst .
>
> IOW, you can safely do the above only for drivers that depend on OF in
> Kconfig. Otherwise you'll probably break something.
>

Sakari, thank you for the pointer to the docs.
I thought that of_match_table is used only by OF (hence the name).

Marek

2020-09-18 11:49:01

by Dan Murphy

[permalink] [raw]
Subject: Re: [PATCH leds v2 15/50] leds: lm3697: cosmetic change: use helper variable, reverse christmas tree

Marek

On 9/17/20 5:33 PM, Marek Behún wrote:
> Use helper variable dev instead of always writing &client->dev, or
> &priv->client->dev, or even &led->priv->client->dev.
>
> With one more line moved reverse christmas tree is also achieved.

Reviewed-by: Dan Murphy <[email protected]>


2020-09-18 17:24:29

by Marek Behún

[permalink] [raw]
Subject: Re: [PATCH leds v2 15/50] leds: lm3697: cosmetic change: use helper variable, reverse christmas tree

On Fri, 18 Sep 2020 06:47:20 -0500
Dan Murphy <[email protected]> wrote:

>
> Reviewed-by: Dan Murphy <[email protected]>
>
>

Dan,

could you also review patch 14/50? That one is also lm3697 and this one
depends on it.

Marek

2020-09-19 09:20:04

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH leds v2 12/50] leds: bcm6328: cosmetic: use reverse christmas tree

On Fri 2020-09-18 00:33:00, Marek Beh?n wrote:
> Only a cosmetic change: use reverse christmas tree variables
> declaration.

Yeah. Don't do that. Code changes for no reason.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (334.00 B)
signature.asc (188.00 B)
Digital signature
Download all attachments

2020-09-19 09:57:46

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH leds v2 03/50] leds: fsg: compile if COMPILE_TEST=y

On Fri 2020-09-18 00:32:51, Marek Beh?n wrote:
> This driver can be compiled on other platforms with small change if
> COMPILE_TEST=y.
>
> Signed-off-by: Marek Beh?n <[email protected]>

> +++ b/drivers/leds/leds-fsg.c
> @@ -16,7 +16,13 @@
> #include <linux/leds.h>
> #include <linux/module.h>
> #include <linux/io.h>
> +
> +#if IS_ENABLED(MACH_FSG)
> #include <mach/hardware.h>
> +#else
> +/* for COMPILE_TEST */
> +#define IXP4XX_EXP_BUS_BASE(x) (0x12345678 + (x))
> +#endif

This is _way_ too ugly and I'd have to read the driver to understand
what prevents it from using this address and corrupting something, somewhere.

Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (809.00 B)
signature.asc (201.00 B)
Download all attachments

2020-09-19 10:05:57

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH leds v2 31/50] leds: lm36274: use devres LED registering function

Hi!

> By using devres version of LED registering function we can remove the
> .remove method from this driver.

Please see a0972fff09479dd09b731360a3a0b09e4fb4d415.

And yes, Johan should have added a comment instead of placing it in
changelog. Feel free to add the comment. There was more than one such
patch IIRC.

Best regards,
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (508.00 B)
signature.asc (201.00 B)
Download all attachments

2020-09-19 10:20:40

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH leds v2 50/50] leds: parse linux,default-trigger DT property in LED core

Hi!

> Do parsing of `linux,default-trigger` DT property to LED core. Currently
> it is done in many different drivers and the code is repeated.
>
> This patch removes the parsing from 21 drivers:
> an30259a, aw2013, bcm6328, bcm6358, cr0014114, el15203000, gpio,
> is31fl319x, is31fl32xx, lm3532, lm36274, lm3692x, lm3697, lp8860,
> lt3593, max77650, mt6323, ns2, pm8058, tlc591xx and turris-omnia.
>
> There are still 11 drivers that parse this property on their own because
> they do not pass the led_init_data structure to the registering
> function. I will try to refactor those in the future.

I applied selected patches from the series... but it is not clear what
this depends on so I'll avoid it for now.

(Oh and thanks for the great work, BTW!)

Please take a look at my -next tree.... and feel free to send me
patches that still make sense.

Best regards,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (1.03 kB)
signature.asc (201.00 B)
Download all attachments

2020-09-19 10:21:26

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH leds v2 25/50] leds: is31fl319x: compute aggregated max current separately

Hi!

> Parse `led-max-current` property of child nodes and compute aggregated
> value in a separate function. The controller cannot set this value
> separately for every LED, so there is no need to store this value for
> every LED.
>
> Signed-off-by: Marek Beh?n <[email protected]>
> Cc: H. Nikolaus Schaller <[email protected]>

Nikolaus, can we get some reviews/testing/comments/etc here?

Best regards,
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (578.00 B)
signature.asc (201.00 B)
Download all attachments

2020-09-19 15:57:55

by Marek Behún

[permalink] [raw]
Subject: Re: [PATCH leds v2 03/50] leds: fsg: compile if COMPILE_TEST=y

On Sat, 19 Sep 2020 11:56:16 +0200
Pavel Machek <[email protected]> wrote:

> #include <mach/hardware.h>

It can't include this header on other platforms...

2020-09-22 17:34:29

by Simon Guinot

[permalink] [raw]
Subject: Re: [PATCH leds v2 00/50] Start moving parsing of `linux,default-trigger` to LED core (a cleanup of LED drivers)

On Fri, Sep 18, 2020 at 12:32:48AM +0200, Marek Behún wrote:
> Hi,
>
> this series is also available at [1].
>
> This is v2, you can read cover letter of v1 at [2] (togehter with
> explanation of why I did this).

...

> leds: ns2: use devres LED registering function
> leds: ns2: alloc simple array instead of struct ns2_led_priv
> leds: ns2: support OF probing only, forget platdata
> leds: ns2: move parsing of one LED into separate function
> leds: ns2: use devres API for getting GPIO descriptors
> leds: ns2: cosmetic structure rename
> leds: ns2: cosmetic variable rename
> leds: ns2: cosmetic change
> leds: ns2: cosmetic change: use helper variable
> leds: ns2: register LED immediately after parsing DT properties
> leds: ns2: remove unneeded variable
> leds: ns2: cosmetic: use reverse christmas tree
> leds: ns2: reorder headers alphabetically
> leds: ns2: use struct led_init_data when registering

Hi Marek,

If you agree, I'll wait the fwnode support before reviewing and testing
this patches.

Simon


Attachments:
(No filename) (1.05 kB)
signature.asc (849.00 B)
Download all attachments

2020-09-26 13:48:39

by Simon Guinot

[permalink] [raw]
Subject: Re: [PATCH leds v2 00/50] Start moving parsing of `linux,default-trigger` to LED core (a cleanup of LED drivers)

On Fri, Sep 18, 2020 at 12:32:48AM +0200, Marek Behún wrote:
> Hi,
>
> this series is also available at [1].
>
> This is v2, you can read cover letter of v1 at [2] (togehter with
> explanation of why I did this).
>
> Changes since v1:
> - split big changes into several patches of little changes
> - added many cosmetic fixes (helper variables, reversal christmas tree
> variables declaration, ...)
> - fixed some bugs in various drivers (memory leaks, iteration over
> unavailable OF nodes)
> - made some drivers compilable when COMPILE_TEST=y (since allyesconfig
> did not compile them). Not all though, some still don't compile with
> allyesconfig
> - the commit that moves parsing of `linux,default-trigger` property from
> drivers to LED core is now last in the series, instead of first
>
> Marek
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/kabel/linux.git/log/?h=leds-cleanup-for-pavel
> [2] https://lore.kernel.org/linux-leds/[email protected]/T/#m826493318174b0f38a3d4ba107092b5420ce440c

...

> leds: ns2: use devres LED registering function
> leds: ns2: alloc simple array instead of struct ns2_led_priv
> leds: ns2: support OF probing only, forget platdata
> leds: ns2: move parsing of one LED into separate function
> leds: ns2: use devres API for getting GPIO descriptors
> leds: ns2: cosmetic structure rename
> leds: ns2: cosmetic variable rename
> leds: ns2: cosmetic change
> leds: ns2: cosmetic change: use helper variable
> leds: ns2: register LED immediately after parsing DT properties
> leds: ns2: remove unneeded variable
> leds: ns2: cosmetic: use reverse christmas tree
> leds: ns2: reorder headers alphabetically
> leds: ns2: use struct led_init_data when registering
> leds: parse linux,default-trigger DT property in LED core

Hi Marek,

For all the patches applying to the leds-ns2 driver:

Reviewed-by: Simon Guinot <[email protected]>
Tested-by: Simon Guinot <[email protected]>

Thanks for it. The driver is looking way better.

Simon


Attachments:
(No filename) (2.07 kB)
signature.asc (849.00 B)
Download all attachments

2020-09-28 08:07:53

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH leds v2 05/50] leds: various: guard of_match_table member value with of_match_ptr

On Fri, 18 Sep 2020, Sakari Ailus wrote:

> On Fri, Sep 18, 2020 at 11:20:58AM +0200, Marek Behun wrote:
> > On Fri, 18 Sep 2020 09:15:00 +0300
> > Sakari Ailus <[email protected]> wrote:
> >
> > > Hi Marek,
> > >
> > > On Fri, Sep 18, 2020 at 12:32:53AM +0200, Marek Behún wrote:
> > > > Change
> > > > .of_match_table = xxx,
> > > > to
> > > > .of_match_table = of_match_ptr(xxx),
> > > > in various drivers.
> > > >
> > > > This should be standard even for drivers that depend on OF.
> > >
> > > After this patch, none of these drivers will work on ACPI systems anymore.
>
> ^
>
> If CONFIG_OF is disabled, that is.

What? of_match_ptr() is designed to change depending on OF or !OF.

Are you confusing this with acpi_match_table()?

> > Hi Sakari,
> >
> > I don't understand. Why not? Does ACPI subsystem parse of_match_table
> > as well?
>
> It does. The compatible string is used the same way as in DT for matching
> devices with "PRP0001" _HID or _CID.
>
> Please read Documentation/firmware-guide/acpi/enumeration.rst .

Could you allude to the specific line you are referencing please?

> IOW, you can safely do the above only for drivers that depend on OF in
> Kconfig. Otherwise you'll probably break something.

--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

2020-09-28 08:14:38

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH leds v2 05/50] leds: various: guard of_match_table member value with of_match_ptr

On Mon, 28 Sep 2020, Lee Jones wrote:

> On Fri, 18 Sep 2020, Sakari Ailus wrote:
>
> > On Fri, Sep 18, 2020 at 11:20:58AM +0200, Marek Behun wrote:
> > > On Fri, 18 Sep 2020 09:15:00 +0300
> > > Sakari Ailus <[email protected]> wrote:
> > >
> > > > Hi Marek,
> > > >
> > > > On Fri, Sep 18, 2020 at 12:32:53AM +0200, Marek Behún wrote:
> > > > > Change
> > > > > .of_match_table = xxx,
> > > > > to
> > > > > .of_match_table = of_match_ptr(xxx),
> > > > > in various drivers.
> > > > >
> > > > > This should be standard even for drivers that depend on OF.
> > > >
> > > > After this patch, none of these drivers will work on ACPI systems anymore.
> >
> > ^
> >
> > If CONFIG_OF is disabled, that is.
>
> What? of_match_ptr() is designed to change depending on OF or !OF.
>
> Are you confusing this with acpi_match_table()?

Okay, I just grepped the kernel and found some OF matching in the ACPI
bus code. This seems odd to be (at first sight at least). I'm not
entirely sure how this is supposed to work, but when you disable OF,
one could reasonably expect any matching utilising OF based tables to
be disabled too.

Not using of_match_ptr() on ACPI enabled platforms sounds batty to
me. If this is valid, perhaps the of_match_ptr()semantics should be
changed to include ACPI.

> > > Hi Sakari,
> > >
> > > I don't understand. Why not? Does ACPI subsystem parse of_match_table
> > > as well?
> >
> > It does. The compatible string is used the same way as in DT for matching
> > devices with "PRP0001" _HID or _CID.
> >
> > Please read Documentation/firmware-guide/acpi/enumeration.rst .
>
> Could you allude to the specific line you are referencing please?
>
> > IOW, you can safely do the above only for drivers that depend on OF in
> > Kconfig. Otherwise you'll probably break something.
>

--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

2020-09-28 09:39:37

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH leds v2 05/50] leds: various: guard of_match_table member value with of_match_ptr

Hi Lee,

On Mon, Sep 28, 2020 at 09:11:14AM +0100, Lee Jones wrote:
> On Mon, 28 Sep 2020, Lee Jones wrote:
>
> > On Fri, 18 Sep 2020, Sakari Ailus wrote:
> >
> > > On Fri, Sep 18, 2020 at 11:20:58AM +0200, Marek Behun wrote:
> > > > On Fri, 18 Sep 2020 09:15:00 +0300
> > > > Sakari Ailus <[email protected]> wrote:
> > > >
> > > > > Hi Marek,
> > > > >
> > > > > On Fri, Sep 18, 2020 at 12:32:53AM +0200, Marek Beh?n wrote:
> > > > > > Change
> > > > > > .of_match_table = xxx,
> > > > > > to
> > > > > > .of_match_table = of_match_ptr(xxx),
> > > > > > in various drivers.
> > > > > >
> > > > > > This should be standard even for drivers that depend on OF.
> > > > >
> > > > > After this patch, none of these drivers will work on ACPI systems anymore.
> > >
> > > ^
> > >
> > > If CONFIG_OF is disabled, that is.
> >
> > What? of_match_ptr() is designed to change depending on OF or !OF.
> >
> > Are you confusing this with acpi_match_table()?
>
> Okay, I just grepped the kernel and found some OF matching in the ACPI
> bus code. This seems odd to be (at first sight at least). I'm not
> entirely sure how this is supposed to work, but when you disable OF,
> one could reasonably expect any matching utilising OF based tables to
> be disabled too.

There's really no reason having to enable the entire OF framework just to
allow compatible string matching.

>
> Not using of_match_ptr() on ACPI enabled platforms sounds batty to
> me. If this is valid, perhaps the of_match_ptr()semantics should be
> changed to include ACPI.

That'd be one option, yes. But not all drivers that work on both OF and
ACPI rely on the compatible strings on ACPI.

Another option could be adding a new macro, to set that table on both OF
and ACPI when needed? It could be called e.g. of_acpi_match_ptr(), for
instance.

Cc also linux-acpi list and Rafael.

--
Regards,

Sakari Ailus

2020-09-29 13:15:33

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH leds v2 20/50] leds: pm8058: use struct led_init_data when registering

On Fri, Sep 18, 2020 at 12:33 AM Marek Behún <[email protected]> wrote:

> By using struct led_init_data when registering we do not need to parse
> `label` DT property. Moreover `label` is deprecated and if it is not
> present but `color` and `function` are, LED core will compose a name
> from these properties instead.
>
> Signed-off-by: Marek Behún <[email protected]>
> Cc: Linus Walleij <[email protected]>
> Cc: Bjorn Andersson <[email protected]>

For this and the other PM8058 patches:
Acked-by: Linus Walleij <[email protected]>

Yours,
Linus Walleij