Skip to contentSkip to conversation

leds: deduplicate led_init_default_state_get()

PATCH Superseded Andy Shevchenko 5 participants 26 messages Sep 6, 2022 – Nov 22, 2022

Subsystems (7)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover leds: deduplicate led_init_default_state_get()

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Changelog v3:
- added tag to patch 11 (Kurt)
- Cc'ed to Lee, who might help with LED subsystem maintenance

Changelog v2:
- added missed patch 2 and hence make it the series
- appended tag to patch 7
- new patch 1

Andy Shevchenko (11):
leds: add missing includes and forward declarations in leds.h
leds: Move led_init_default_state_get() to the global header
leds: an30259a: Get rid of custom led_init_default_state_get()
leds: bcm6328: Get rid of custom led_init_default_state_get()
leds: bcm6358: Get rid of custom led_init_default_state_get()
leds: mt6323: Get rid of custom led_init_default_state_get()
leds: mt6360: Get rid of custom led_init_default_state_get()
leds: pca955x: Get rid of custom led_init_default_state_get()
leds: pm8058: Get rid of custom led_init_default_state_get()
leds: syscon: Get rid of custom led_init_default_state_get()
net: dsa: hellcreek: Get rid of custom led_init_default_state_get()

 drivers/leds/flash/leds-mt6360.c           | 38 +++--------------
 drivers/leds/leds-an30259a.c               | 21 ++--------
 drivers/leds/leds-bcm6328.c                | 49 +++++++++++-----------
 drivers/leds/leds-bcm6358.c                | 32 +++++++-------
 drivers/leds/leds-mt6323.c                 | 30 ++++++-------
 drivers/leds/leds-pca955x.c                | 26 +++---------
 drivers/leds/leds-pm8058.c                 | 29 ++++++-------
 drivers/leds/leds-syscon.c                 | 49 ++++++++++------------
 drivers/leds/leds.h                        |  1 -
 drivers/net/dsa/hirschmann/hellcreek_ptp.c | 45 ++++++++++----------
 include/linux/leds.h                       | 15 ++++---
 11 files changed, 143 insertions(+), 192 deletions(-)
Signature · 7 lines
2.35.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

PATCH v3 1/11 leds: add missing includes and forward declarations in leds.h

Add missing includes and forward declarations to leds.h. While at it, replace headers by forward declarations and vise versa.

---
 include/linux/leds.h | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
include/linux/leds.h +8 -5
index ba4861ec73d3..499aea1e59b9 100644
@@ -10,17 +10,21 @@
 
 #include <dt-bindings/leds/common.h>
 #include <linux/device.h>
-#include <linux/kernfs.h>
-#include <linux/list.h>
 #include <linux/mutex.h>
 #include <linux/rwsem.h>
 #include <linux/spinlock.h>
 #include <linux/timer.h>
+#include <linux/types.h>
 #include <linux/workqueue.h>
 
-struct device;
-struct led_pattern;
+struct attribute_group;
 struct device_node;
+struct fwnode_handle;
+struct gpio_desc;
+struct kernfs_node;
+struct led_pattern;
+struct platform_device;
+
 /*
  * LED Core
  */
@@ -508,7 +512,6 @@ struct led_properties {
 	const char	*label;
 };
 
-struct gpio_desc;
 typedef int (*gpio_blink_set_t)(struct gpio_desc *desc, int state,
 				unsigned long *delay_on,
 				unsigned long *delay_off);
Signature · 1 line
2.35.1
#2 lore raw

PATCH v3 2/11 leds: Move led_init_default_state_get() to the global header

In reply to Andy Shevchenko

There are users inside and outside LED framework that have implemented a local copy of led_init_default_state_get(). In order to deduplicate that, as the first step move the declaration from LED header to the global one.

---
 drivers/leds/leds.h  | 1 -
 include/linux/leds.h | 2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/leds/leds.h +0 -1
index aa64757a4d89..345062ccabda 100644
@@ -27,7 +27,6 @@ ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,
 ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
 			struct bin_attribute *bin_attr, char *buf,
 			loff_t pos, size_t count);
-enum led_default_state led_init_default_state_get(struct fwnode_handle *fwnode);
 
 extern struct rw_semaphore leds_list_lock;
 extern struct list_head leds_list;
include/linux/leds.h +2 -0
index 499aea1e59b9..b96feacc73f8 100644
@@ -67,6 +67,8 @@ struct led_init_data {
 	bool devname_mandatory;
 };
 
+enum led_default_state led_init_default_state_get(struct fwnode_handle *fwnode);
+
 struct led_hw_trigger_type {
 	int dummy;
 };
Signature · 7 lines
2.35.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#3 lore raw

PATCH v3 3/11 leds: an30259a: Get rid of custom led_init_default_state_get()

In reply to Andy Shevchenko

LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.

---
 drivers/leds/leds-an30259a.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)
drivers/leds/leds-an30259a.c +4 -17
index e072ee5409f7..89df267853a9 100644
@@ -55,10 +55,6 @@
 
 #define AN30259A_NAME "an30259a"
 
-#define STATE_OFF 0
-#define STATE_KEEP 1
-#define STATE_ON 2
-
 struct an30259a;
 
 struct an30259a_led {
@@ -66,7 +62,7 @@ struct an30259a_led {
 	struct fwnode_handle *fwnode;
 	struct led_classdev cdev;
 	u32 num;
-	u32 default_state;
+	enum led_default_state default_state;
 	bool sloping;
 };
 
@@ -205,7 +201,6 @@ static int an30259a_dt_init(struct i2c_client *client,
 	struct device_node *np = dev_of_node(&client->dev), *child;
 	int count, ret;
 	int i = 0;
-	const char *str;
 	struct an30259a_led *led;
 
 	count = of_get_available_child_count(np);
@@ -228,15 +223,7 @@ static int an30259a_dt_init(struct i2c_client *client,
 		led->num = source;
 		led->chip = chip;
 		led->fwnode = of_fwnode_handle(child);
-
-		if (!of_property_read_string(child, "default-state", &str)) {
-			if (!strcmp(str, "on"))
-				led->default_state = STATE_ON;
-			else if (!strcmp(str, "keep"))
-				led->default_state = STATE_KEEP;
-			else
-				led->default_state = STATE_OFF;
-		}
+		led->default_state = led_init_default_state_get(led->fwnode);
 
 		i++;
 	}
@@ -261,10 +248,10 @@ static void an30259a_init_default_state(struct an30259a_led *led)
 	int led_on, err;
 
 	switch (led->default_state) {
-	case STATE_ON:
+	case LEDS_DEFSTATE_ON:
 		led->cdev.brightness = LED_FULL;
 		break;
-	case STATE_KEEP:
+	case LEDS_DEFSTATE_KEEP:
 		err = regmap_read(chip->regmap, AN30259A_REG_LED_ON, &led_on);
 		if (err)
 			break;
Signature · 7 lines
2.35.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#4 lore raw

PATCH v3 4/11 leds: bcm6328: Get rid of custom led_init_default_state_get()

In reply to Andy Shevchenko

LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.

---
 drivers/leds/leds-bcm6328.c | 49 ++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 25 deletions(-)
drivers/leds/leds-bcm6328.c +24 -25
index 2d4d87957a30..246f1296ab09 100644
@@ -330,7 +330,9 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg,
 {
 	struct led_init_data init_data = {};
 	struct bcm6328_led *led;
-	const char *state;
+	enum led_default_state state;
+	unsigned long val, shift;
+	void __iomem *mode;
 	int rc;
 
 	led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
@@ -346,31 +348,29 @@ 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;
 
-	if (!of_property_read_string(nc, "default-state", &state)) {
-		if (!strcmp(state, "on")) {
+	init_data.fwnode = of_fwnode_handle(nc);
+
+	state = led_init_default_state_get(init_data.fwnode);
+	switch (state) {
+	case LEDS_DEFSTATE_ON:
+		led->cdev.brightness = LED_FULL;
+		break;
+	case LEDS_DEFSTATE_KEEP:
+		shift = bcm6328_pin2shift(led->pin);
+		if (shift / 16)
+			mode = mem + BCM6328_REG_MODE_HI;
+		else
+			mode = mem + BCM6328_REG_MODE_LO;
+
+		val = bcm6328_led_read(mode) >> BCM6328_LED_SHIFT(shift % 16);
+		val &= BCM6328_LED_MODE_MASK;
+		if ((led->active_low && val == BCM6328_LED_MODE_OFF) ||
+		    (!led->active_low && val == BCM6328_LED_MODE_ON))
 			led->cdev.brightness = LED_FULL;
-		} else if (!strcmp(state, "keep")) {
-			void __iomem *mode;
-			unsigned long val, shift;
-
-			shift = bcm6328_pin2shift(led->pin);
-			if (shift / 16)
-				mode = mem + BCM6328_REG_MODE_HI;
-			else
-				mode = mem + BCM6328_REG_MODE_LO;
-
-			val = bcm6328_led_read(mode) >>
-			      BCM6328_LED_SHIFT(shift % 16);
-			val &= BCM6328_LED_MODE_MASK;
-			if ((led->active_low && val == BCM6328_LED_MODE_OFF) ||
-			    (!led->active_low && val == BCM6328_LED_MODE_ON))
-				led->cdev.brightness = LED_FULL;
-			else
-				led->cdev.brightness = LED_OFF;
-		} else {
+		else
 			led->cdev.brightness = LED_OFF;
-		}
-	} else {
+		break;
+	default:
 		led->cdev.brightness = LED_OFF;
 	}
 
@@ -378,7 +378,6 @@ 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_ext(dev, &led->cdev, &init_data);
 	if (rc < 0)
Signature · 7 lines
2.35.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#6 lore raw

PATCH v3 5/11 leds: bcm6358: Get rid of custom led_init_default_state_get()

In reply to Andy Shevchenko

LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.

---
 drivers/leds/leds-bcm6358.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/leds/leds-bcm6358.c +16 -16
index 9d2e487fa08a..86e51d44a5a7 100644
@@ -96,7 +96,8 @@ static int bcm6358_led(struct device *dev, struct device_node *nc, u32 reg,
 {
 	struct led_init_data init_data = {};
 	struct bcm6358_led *led;
-	const char *state;
+	enum led_default_state state;
+	unsigned long val;
 	int rc;
 
 	led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
@@ -110,29 +111,28 @@ 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;
 
-	if (!of_property_read_string(nc, "default-state", &state)) {
-		if (!strcmp(state, "on")) {
+	init_data.fwnode = of_fwnode_handle(nc);
+
+	state = led_init_default_state_get(init_data.fwnode);
+	switch (state) {
+	case LEDS_DEFSTATE_ON:
+		led->cdev.brightness = LED_FULL;
+		break;
+	case LEDS_DEFSTATE_KEEP:
+		val = bcm6358_led_read(led->mem + BCM6358_REG_MODE);
+		val &= BIT(led->pin);
+		if ((led->active_low && !val) || (!led->active_low && val))
 			led->cdev.brightness = LED_FULL;
-		} else if (!strcmp(state, "keep")) {
-			unsigned long val;
-			val = bcm6358_led_read(led->mem + BCM6358_REG_MODE);
-			val &= BIT(led->pin);
-			if ((led->active_low && !val) ||
-			    (!led->active_low && val))
-				led->cdev.brightness = LED_FULL;
-			else
-				led->cdev.brightness = LED_OFF;
-		} else {
+		else
 			led->cdev.brightness = LED_OFF;
-		}
-	} else {
+		break;
+	default:
 		led->cdev.brightness = LED_OFF;
 	}
 
 	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_ext(dev, &led->cdev, &init_data);
 	if (rc < 0)
Signature · 7 lines
2.35.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#8 lore raw

PATCH v3 6/11 leds: mt6323: Get rid of custom led_init_default_state_get()

In reply to Andy Shevchenko

LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.

---
 drivers/leds/leds-mt6323.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/leds/leds-mt6323.c +15 -15
index f59e0e8bda8b..17ee88043f52 100644
@@ -339,23 +339,23 @@ static int mt6323_led_set_dt_default(struct led_classdev *cdev,
 				     struct device_node *np)
 {
 	struct mt6323_led *led = container_of(cdev, struct mt6323_led, cdev);
-	const char *state;
+	enum led_default_state state;
 	int ret = 0;
 
-	state = of_get_property(np, "default-state", NULL);
-	if (state) {
-		if (!strcmp(state, "keep")) {
-			ret = mt6323_get_led_hw_brightness(cdev);
-			if (ret < 0)
-				return ret;
-			led->current_brightness = ret;
-			ret = 0;
-		} else if (!strcmp(state, "on")) {
-			ret =
-			mt6323_led_set_brightness(cdev, cdev->max_brightness);
-		} else  {
-			ret = mt6323_led_set_brightness(cdev, LED_OFF);
-		}
+	state = led_init_default_state_get(of_fwnode_handle(np));
+	switch (state) {
+	case LEDS_DEFSTATE_ON:
+		ret = mt6323_led_set_brightness(cdev, cdev->max_brightness);
+		break;
+	case LEDS_DEFSTATE_KEEP:
+		ret = mt6323_get_led_hw_brightness(cdev);
+		if (ret < 0)
+			return ret;
+		led->current_brightness = ret;
+		ret = 0;
+		break;
+	default:
+		ret = mt6323_led_set_brightness(cdev, LED_OFF);
 	}
 
 	return ret;
Signature · 1 line
2.35.1
#10 lore raw

PATCH v3 7/11 leds: mt6360: Get rid of custom led_init_default_state_get()

In reply to Andy Shevchenko

LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.

---
 drivers/leds/flash/leds-mt6360.c | 38 +++++---------------------------
 1 file changed, 6 insertions(+), 32 deletions(-)
drivers/leds/flash/leds-mt6360.c +6 -32
index e1066a52d2d2..1af6c5898343 100644
@@ -71,10 +71,6 @@ enum {
 #define MT6360_STRBTO_STEPUS		32000
 #define MT6360_STRBTO_MAXUS		2432000
 
-#define STATE_OFF			0
-#define STATE_KEEP			1
-#define STATE_ON			2
-
 struct mt6360_led {
 	union {
 		struct led_classdev isnk;
@@ -84,7 +80,7 @@ struct mt6360_led {
 	struct v4l2_flash *v4l2_flash;
 	struct mt6360_priv *priv;
 	u32 led_no;
-	u32 default_state;
+	enum led_default_state default_state;
 };
 
 struct mt6360_priv {
@@ -405,10 +401,10 @@ static int mt6360_isnk_init_default_state(struct mt6360_led *led)
 		level = LED_OFF;
 
 	switch (led->default_state) {
-	case STATE_ON:
+	case LEDS_DEFSTATE_ON:
 		led->isnk.brightness = led->isnk.max_brightness;
 		break;
-	case STATE_KEEP:
+	case LEDS_DEFSTATE_KEEP:
 		led->isnk.brightness = min(level, led->isnk.max_brightness);
 		break;
 	default:
@@ -443,10 +439,10 @@ static int mt6360_flash_init_default_state(struct mt6360_led *led)
 		level = LED_OFF;
 
 	switch (led->default_state) {
-	case STATE_ON:
+	case LEDS_DEFSTATE_ON:
 		flash->led_cdev.brightness = flash->led_cdev.max_brightness;
 		break;
-	case STATE_KEEP:
+	case LEDS_DEFSTATE_KEEP:
 		flash->led_cdev.brightness =
 			min(level, flash->led_cdev.max_brightness);
 		break;
@@ -760,25 +756,6 @@ static int mt6360_init_flash_properties(struct mt6360_led *led,
 	return 0;
 }
 
-static int mt6360_init_common_properties(struct mt6360_led *led,
-					 struct led_init_data *init_data)
-{
-	const char *const states[] = { "off", "keep", "on" };
-	const char *str;
-	int ret;
-
-	if (!fwnode_property_read_string(init_data->fwnode,
-					 "default-state", &str)) {
-		ret = match_string(states, ARRAY_SIZE(states), str);
-		if (ret < 0)
-			ret = STATE_OFF;
-
-		led->default_state = ret;
-	}
-
-	return 0;
-}
-
 static void mt6360_v4l2_flash_release(struct mt6360_priv *priv)
 {
 	int i;
@@ -852,10 +829,7 @@ static int mt6360_led_probe(struct platform_device *pdev)
 
 		led->led_no = reg;
 		led->priv = priv;
-
-		ret = mt6360_init_common_properties(led, &init_data);
-		if (ret)
-			goto out_flash_release;
+		led->default_state = led_init_default_state_get(child);
 
 		if (reg == MT6360_VIRTUAL_MULTICOLOR ||
 		    reg <= MT6360_LED_ISNKML)
Signature · 1 line
2.35.1
maintainer Reviewed-by on v3 7/11
#11 lore raw

Re: [PATCH v3 07/11] leds: mt6360: Get rid of custom led_init_default_state_get()

Il 06/09/22 15:50, Andy Shevchenko ha scritto:

Quoted 5 lines

LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.

#12 lore raw

PATCH v3 8/11 leds: pca955x: Get rid of custom led_init_default_state_get()

In reply to Andy Shevchenko

LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.

---
 drivers/leds/leds-pca955x.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)
drivers/leds/leds-pca955x.c +6 -20
index 81aaf21212d7..8dca6f99e699 100644
@@ -130,7 +130,7 @@ struct pca955x_led {
 	struct led_classdev	led_cdev;
 	int			led_num;	/* 0 .. 15 potentially */
 	u32			type;
-	int			default_state;
+	enum led_default_state	default_state;
 	struct fwnode_handle	*fwnode;
 };
 
@@ -443,7 +443,6 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
 		return ERR_PTR(-ENOMEM);
 
 	device_for_each_child_node(&client->dev, child) {
-		const char *state;
 		u32 reg;
 		int res;
 
@@ -454,19 +453,9 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
 		led = &pdata->leds[reg];
 		led->type = PCA955X_TYPE_LED;
 		led->fwnode = child;
-		fwnode_property_read_u32(child, "type", &led->type);
+		led->default_state = led_init_default_state_get(child);
 
-		if (!fwnode_property_read_string(child, "default-state",
-						 &state)) {
-			if (!strcmp(state, "keep"))
-				led->default_state = LEDS_GPIO_DEFSTATE_KEEP;
-			else if (!strcmp(state, "on"))
-				led->default_state = LEDS_GPIO_DEFSTATE_ON;
-			else
-				led->default_state = LEDS_GPIO_DEFSTATE_OFF;
-		} else {
-			led->default_state = LEDS_GPIO_DEFSTATE_OFF;
-		}
+		fwnode_property_read_u32(child, "type", &led->type);
 	}
 
 	pdata->num_leds = chip->bits;
@@ -578,13 +567,11 @@ static int pca955x_probe(struct i2c_client *client)
 			led->brightness_set_blocking = pca955x_led_set;
 			led->brightness_get = pca955x_led_get;
 
-			if (pdata->leds[i].default_state ==
-			    LEDS_GPIO_DEFSTATE_OFF) {
+			if (pdata->leds[i].default_state == LEDS_DEFSTATE_OFF) {
 				err = pca955x_led_set(led, LED_OFF);
 				if (err)
 					return err;
-			} else if (pdata->leds[i].default_state ==
-				   LEDS_GPIO_DEFSTATE_ON) {
+			} else if (pdata->leds[i].default_state == LEDS_DEFSTATE_ON) {
 				err = pca955x_led_set(led, LED_FULL);
 				if (err)
 					return err;
@@ -623,8 +610,7 @@ static int pca955x_probe(struct i2c_client *client)
 			 * brightness to see if it's using PWM1. If so, PWM1
 			 * should not be written below.
 			 */
-			if (pdata->leds[i].default_state ==
-			    LEDS_GPIO_DEFSTATE_KEEP) {
+			if (pdata->leds[i].default_state == LEDS_DEFSTATE_KEEP) {
 				if (led->brightness != LED_FULL &&
 				    led->brightness != LED_OFF &&
 				    led->brightness != LED_HALF)
Signature · 7 lines
2.35.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#13 lore raw

PATCH v3 9/11 leds: pm8058: Get rid of custom led_init_default_state_get()

In reply to Andy Shevchenko

LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.

---
 drivers/leds/leds-pm8058.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/leds/leds-pm8058.c +15 -14
index fb2ab72c0c40..b9233f14b646 100644
@@ -93,8 +93,8 @@ static int pm8058_led_probe(struct platform_device *pdev)
 	struct device_node *np;
 	int ret;
 	struct regmap *map;
-	const char *state;
 	enum led_brightness maxbright;
+	enum led_default_state state;
 
 	led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
 	if (!led)
@@ -125,25 +125,26 @@ static int pm8058_led_probe(struct platform_device *pdev)
 		maxbright = 15; /* 4 bits */
 	led->cdev.max_brightness = maxbright;
 
-	state = of_get_property(np, "default-state", NULL);
-	if (state) {
-		if (!strcmp(state, "keep")) {
-			led->cdev.brightness = pm8058_led_get(&led->cdev);
-		} else if (!strcmp(state, "on")) {
-			led->cdev.brightness = maxbright;
-			pm8058_led_set(&led->cdev, maxbright);
-		} else {
-			led->cdev.brightness = LED_OFF;
-			pm8058_led_set(&led->cdev, LED_OFF);
-		}
+	init_data.fwnode = of_fwnode_handle(np);
+
+	state = led_init_default_state_get(init_data.fwnode);
+	switch (state) {
+	case LEDS_DEFSTATE_ON:
+		led->cdev.brightness = maxbright;
+		pm8058_led_set(&led->cdev, maxbright);
+		break;
+	case LEDS_DEFSTATE_KEEP:
+		led->cdev.brightness = pm8058_led_get(&led->cdev);
+		break;
+	default:
+		led->cdev.brightness = LED_OFF;
+		pm8058_led_set(&led->cdev, LED_OFF);
 	}
 
 	if (led->ledtype == PM8058_LED_TYPE_KEYPAD ||
 	    led->ledtype == PM8058_LED_TYPE_FLASH)
 		led->cdev.flags	= LED_CORE_SUSPENDRESUME;
 
-	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 %pOF\n", np);
Signature · 1 line
2.35.1
#14 lore raw

PATCH v3 10/11 leds: syscon: Get rid of custom led_init_default_state_get()

In reply to Andy Shevchenko

LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.

---
 drivers/leds/leds-syscon.c | 49 ++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 26 deletions(-)
drivers/leds/leds-syscon.c +23 -26
index 7eddb8ecb44e..e38abb5e60c1 100644
@@ -61,7 +61,8 @@ static int syscon_led_probe(struct platform_device *pdev)
 	struct device *parent;
 	struct regmap *map;
 	struct syscon_led *sled;
-	const char *state;
+	enum led_default_state state;
+	u32 value;
 	int ret;
 
 	parent = dev->parent;
@@ -86,34 +87,30 @@ static int syscon_led_probe(struct platform_device *pdev)
 	if (of_property_read_u32(np, "mask", &sled->mask))
 		return -EINVAL;
 
-	state = of_get_property(np, "default-state", NULL);
-	if (state) {
-		if (!strcmp(state, "keep")) {
-			u32 val;
-
-			ret = regmap_read(map, sled->offset, &val);
-			if (ret < 0)
-				return ret;
-			sled->state = !!(val & sled->mask);
-		} else if (!strcmp(state, "on")) {
-			sled->state = true;
-			ret = regmap_update_bits(map, sled->offset,
-						 sled->mask,
-						 sled->mask);
-			if (ret < 0)
-				return ret;
-		} else {
-			sled->state = false;
-			ret = regmap_update_bits(map, sled->offset,
-						 sled->mask, 0);
-			if (ret < 0)
-				return ret;
-		}
+	init_data.fwnode = of_fwnode_handle(np);
+
+	state = led_init_default_state_get(init_data.fwnode);
+	switch (state) {
+	case LEDS_DEFSTATE_ON:
+		ret = regmap_update_bits(map, sled->offset, sled->mask, sled->mask);
+		if (ret < 0)
+			return ret;
+		sled->state = true;
+		break;
+	case LEDS_DEFSTATE_KEEP:
+		ret = regmap_read(map, sled->offset, &value);
+		if (ret < 0)
+			return ret;
+		sled->state = !!(value & sled->mask);
+		break;
+	default:
+		ret = regmap_update_bits(map, sled->offset, sled->mask, 0);
+		if (ret < 0)
+			return ret;
+		sled->state = false;
 	}
 	sled->cdev.brightness_set = syscon_led_set;
 
-	init_data.fwnode = of_fwnode_handle(np);
-
 	ret = devm_led_classdev_register_ext(dev, &sled->cdev, &init_data);
 	if (ret < 0)
 		return ret;
Signature · 1 line
2.35.1
#15 lore raw

PATCH v3 11/11 net: dsa: hellcreek: Get rid of custom led_init_default_state_get()

In reply to Andy Shevchenko

LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation.

---
 drivers/net/dsa/hirschmann/hellcreek_ptp.c | 45 ++++++++++++----------
 1 file changed, 24 insertions(+), 21 deletions(-)
drivers/net/dsa/hirschmann/hellcreek_ptp.c +24 -21
index b28baab6d56a..793b2c296314 100644
@@ -297,7 +297,8 @@ static enum led_brightness hellcreek_led_is_gm_get(struct led_classdev *ldev)
 static int hellcreek_led_setup(struct hellcreek *hellcreek)
 {
 	struct device_node *leds, *led = NULL;
-	const char *label, *state;
+	enum led_default_state state;
+	const char *label;
 	int ret = -EINVAL;
 
 	of_node_get(hellcreek->dev->of_node);
@@ -318,16 +319,17 @@ static int hellcreek_led_setup(struct hellcreek *hellcreek)
 	ret = of_property_read_string(led, "label", &label);
 	hellcreek->led_sync_good.name = ret ? "sync_good" : label;
 
-	ret = of_property_read_string(led, "default-state", &state);
-	if (!ret) {
-		if (!strcmp(state, "on"))
-			hellcreek->led_sync_good.brightness = 1;
-		else if (!strcmp(state, "off"))
-			hellcreek->led_sync_good.brightness = 0;
-		else if (!strcmp(state, "keep"))
-			hellcreek->led_sync_good.brightness =
-				hellcreek_get_brightness(hellcreek,
-							 STATUS_OUT_SYNC_GOOD);
+	state = led_init_default_state_get(of_fwnode_handle(led));
+	switch (state) {
+	case LEDS_DEFSTATE_ON:
+		hellcreek->led_sync_good.brightness = 1;
+		break;
+	case LEDS_DEFSTATE_KEEP:
+		hellcreek->led_sync_good.brightness =
+				hellcreek_get_brightness(hellcreek, STATUS_OUT_SYNC_GOOD);
+		break;
+	default:
+		hellcreek->led_sync_good.brightness = 0;
 	}
 
 	hellcreek->led_sync_good.max_brightness = 1;
@@ -344,16 +346,17 @@ static int hellcreek_led_setup(struct hellcreek *hellcreek)
 	ret = of_property_read_string(led, "label", &label);
 	hellcreek->led_is_gm.name = ret ? "is_gm" : label;
 
-	ret = of_property_read_string(led, "default-state", &state);
-	if (!ret) {
-		if (!strcmp(state, "on"))
-			hellcreek->led_is_gm.brightness = 1;
-		else if (!strcmp(state, "off"))
-			hellcreek->led_is_gm.brightness = 0;
-		else if (!strcmp(state, "keep"))
-			hellcreek->led_is_gm.brightness =
-				hellcreek_get_brightness(hellcreek,
-							 STATUS_OUT_IS_GM);
+	state = led_init_default_state_get(of_fwnode_handle(led));
+	switch (state) {
+	case LEDS_DEFSTATE_ON:
+		hellcreek->led_is_gm.brightness = 1;
+		break;
+	case LEDS_DEFSTATE_KEEP:
+		hellcreek->led_is_gm.brightness =
+				hellcreek_get_brightness(hellcreek, STATUS_OUT_IS_GM);
+		break;
+	default:
+		hellcreek->led_is_gm.brightness = 0;
 	}
 
 	hellcreek->led_is_gm.max_brightness = 1;
Signature · 7 lines
2.35.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#16 lore raw
In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Can this be applied now?

Lee, Pavel, what do you think?

Quoted 8 lines

Changelog v3:
- added tag to patch 11 (Kurt)
- Cc'ed to Lee, who might help with LED subsystem maintenance

Changelog v2:
- added missed patch 2 and hence make it the series
- appended tag to patch 7
- new patch 1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#17 lore raw
In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Dear LED maintainers, is there any news on this series? It's hanging around for almost 2 months now...

Quoted 38 lines

Changelog v3:
- added tag to patch 11 (Kurt)
- Cc'ed to Lee, who might help with LED subsystem maintenance

Changelog v2:
- added missed patch 2 and hence make it the series
- appended tag to patch 7
- new patch 1

Andy Shevchenko (11):
leds: add missing includes and forward declarations in leds.h
leds: Move led_init_default_state_get() to the global header
leds: an30259a: Get rid of custom led_init_default_state_get()
leds: bcm6328: Get rid of custom led_init_default_state_get()
leds: bcm6358: Get rid of custom led_init_default_state_get()
leds: mt6323: Get rid of custom led_init_default_state_get()
leds: mt6360: Get rid of custom led_init_default_state_get()
leds: pca955x: Get rid of custom led_init_default_state_get()
leds: pm8058: Get rid of custom led_init_default_state_get()
leds: syscon: Get rid of custom led_init_default_state_get()
net: dsa: hellcreek: Get rid of custom led_init_default_state_get()

 drivers/leds/flash/leds-mt6360.c           | 38 +++--------------
 drivers/leds/leds-an30259a.c               | 21 ++--------
 drivers/leds/leds-bcm6328.c                | 49 +++++++++++-----------
 drivers/leds/leds-bcm6358.c                | 32 +++++++-------
 drivers/leds/leds-mt6323.c                 | 30 ++++++-------
 drivers/leds/leds-pca955x.c                | 26 +++---------
 drivers/leds/leds-pm8058.c                 | 29 ++++++-------
 drivers/leds/leds-syscon.c                 | 49 ++++++++++------------
 drivers/leds/leds.h                        |  1 -
 drivers/net/dsa/hirschmann/hellcreek_ptp.c | 45 ++++++++++----------
 include/linux/leds.h                       | 15 ++++---
 11 files changed, 143 insertions(+), 192 deletions(-)
Signature · 1 line
2.35.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#18 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Dear LED maintainers, is there any news on this series? It's hanging around for almost 2 months now...

My offer still stands if help is required.

Signature · 1 line
Lee Jones [李琼斯]
#19 lore raw
Quoted 8 lines · Lee Jones
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Quoted 4 lines
Quoted 2 lines

Dear LED maintainers, is there any news on this series? It's hanging around for almost 2 months now...

My offer still stands if help is required.

From my point of view the LED subsystem is quite laggish lately (as shown by this patch series, for instance), which means that _in practice_ the help is needed, but I haven't got if we have any administrative agreement on that.

Pavel?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#20 lore raw
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Lee Jones
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Dear LED maintainers, is there any news on this series? It's hanging around for almost 2 months now...

Quoted 7 lines
Quoted 1 line

My offer still stands if help is required.

From my point of view the LED subsystem is quite laggish lately (as shown by this patch series, for instance), which means that _in practice_ the help is needed, but I haven't got if we have any administrative agreement on that.

Pavel?

So, Pavel seems quite unresponsive lately... Shall we just move on and take maintainership?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#21 lore raw
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Andy Shevchenko
Quoted 12 lines · Lee Jones
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Dear LED maintainers, is there any news on this series? It's hanging around for almost 2 months now...

My offer still stands if help is required.

Quoted 8 lines
Quoted 5 lines

From my point of view the LED subsystem is quite laggish lately (as shown by this patch series, for instance), which means that _in practice_ the help is needed, but I haven't got if we have any administrative agreement on that.

Pavel?

So, Pavel seems quite unresponsive lately... Shall we just move on and take maintainership?

I had an off-line conversation with Greg who advised me against that.

Signature · 1 line
Lee Jones [李琼斯]
#22 lore raw
Quoted 20 lines · Lee Jones
Quoted 19 lines · Andy Shevchenko
Quoted 18 lines · Andy Shevchenko
Quoted 8 lines · Lee Jones
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Quoted 4 lines
Quoted 2 lines

Dear LED maintainers, is there any news on this series? It's hanging around for almost 2 months now...

My offer still stands if help is required.

From my point of view the LED subsystem is quite laggish lately (as shown by this patch series, for instance), which means that _in practice_ the help is needed, but I haven't got if we have any administrative agreement on that.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Pavel?

So, Pavel seems quite unresponsive lately... Shall we just move on and take maintainership?

I had an off-line conversation with Greg who advised me against that.

OK. What the reasonable option we have then?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#23 lore raw
Quoted 21 lines · Andy Shevchenko
Quoted 20 lines · Lee Jones
Quoted 19 lines · Andy Shevchenko
Quoted 18 lines · Andy Shevchenko
Quoted 8 lines · Lee Jones
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Quoted 4 lines
Quoted 2 lines

Dear LED maintainers, is there any news on this series? It's hanging around for almost 2 months now...

My offer still stands if help is required.

From my point of view the LED subsystem is quite laggish lately (as shown by this patch series, for instance), which means that _in practice_ the help is needed, but I haven't got if we have any administrative agreement on that.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Pavel?

So, Pavel seems quite unresponsive lately... Shall we just move on and take maintainership?

I had an off-line conversation with Greg who advised me against that.

OK. What the reasonable option we have then?

I thought there is now a new LED maintainer, is that not working out?

#24 lore raw
Quoted 24 lines · Greg Kroah-Hartman
Quoted 23 lines · Andy Shevchenko
Quoted 22 lines · Lee Jones
Quoted 21 lines · Andy Shevchenko
Quoted 19 lines · Andy Shevchenko
Quoted 8 lines · Lee Jones
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Quoted 4 lines
Quoted 2 lines

Dear LED maintainers, is there any news on this series? It's hanging around for almost 2 months now...

My offer still stands if help is required.

From my point of view the LED subsystem is quite laggish lately (as shown by this patch series, for instance), which means that _in practice_ the help is needed, but I haven't got if we have any administrative agreement on that.

Pavel?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

So, Pavel seems quite unresponsive lately... Shall we just move on and take maintainership?

I had an off-line conversation with Greg who advised me against that.

OK. What the reasonable option we have then?

I thought there is now a new LED maintainer, is that not working out?

No new (co-)maintainer due to stale mate situation as far as I can read it right now.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#25 lore raw
Quoted 27 lines · Andy Shevchenko
Quoted 26 lines · Greg Kroah-Hartman
Quoted 25 lines · Andy Shevchenko
Quoted 24 lines · Lee Jones
Quoted 22 lines · Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Lee Jones
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are several users of LED framework that reimplement the functionality of led_init_default_state_get(). In order to deduplicate them move the declaration to the global header (patch 2) and convert users (patche 3-11).

Dear LED maintainers, is there any news on this series? It's hanging around for almost 2 months now...

Quoted 7 lines
Quoted 1 line

My offer still stands if help is required.

From my point of view the LED subsystem is quite laggish lately (as shown by this patch series, for instance), which means that _in practice_ the help is needed, but I haven't got if we have any administrative agreement on that.

Pavel?

So, Pavel seems quite unresponsive lately... Shall we just move on and take maintainership?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I had an off-line conversation with Greg who advised me against that.

OK. What the reasonable option we have then?

I thought there is now a new LED maintainer, is that not working out?

No new (co-)maintainer due to stale mate situation as far as I can read it right now.

So, any suggestion on how to proceed here?

De facto we have no patch flow in LED subsystem and the queue is growing...

Signature · 2 lines
With Best Regards,
Andy Shevchenko