diff mbox series

[v1,1/1] leds: syscon: Get rid of custom led_init_default_state_get()

Message ID 20220802212507.6995-1-andriy.shevchenko@linux.intel.com
State Superseded
Headers show
Series [v1,1/1] leds: syscon: Get rid of custom led_init_default_state_get() | expand

Commit Message

Andy Shevchenko Aug. 2, 2022, 9:25 p.m. UTC
LED core provides a helper to parse default state from firmware node.
Use it instead of custom implementation.

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

Comments

kernel test robot Aug. 3, 2022, 12:55 a.m. UTC | #1
Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on pavel-leds/for-next]
[also build test ERROR on linus/master v5.19 next-20220728]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/leds-syscon-Get-rid-of-custom-led_init_default_state_get/20220803-052528
base:   git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next
config: hexagon-randconfig-r041-20220801 (https://download.01.org/0day-ci/archive/20220803/202208030858.VhHvPCPM-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 52cd00cabf479aa7eb6dbb063b7ba41ea57bce9e)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/485abd71bd954b7a2d1ea89818ca5c925714b1e1
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Andy-Shevchenko/leds-syscon-Get-rid-of-custom-led_init_default_state_get/20220803-052528
        git checkout 485abd71bd954b7a2d1ea89818ca5c925714b1e1
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/leds/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/leds/leds-syscon.c:92:10: error: call to undeclared function 'led_init_default_state_get'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
           state = led_init_default_state_get(init_data.fwnode);
                   ^
   1 error generated.


vim +/led_init_default_state_get +92 drivers/leds/leds-syscon.c

    55	
    56	static int syscon_led_probe(struct platform_device *pdev)
    57	{
    58		struct led_init_data init_data = {};
    59		struct device *dev = &pdev->dev;
    60		struct device_node *np = dev_of_node(dev);
    61		struct device *parent;
    62		struct regmap *map;
    63		struct syscon_led *sled;
    64		enum led_default_state state;
    65		u32 value;
    66		int ret;
    67	
    68		parent = dev->parent;
    69		if (!parent) {
    70			dev_err(dev, "no parent for syscon LED\n");
    71			return -ENODEV;
    72		}
    73		map = syscon_node_to_regmap(dev_of_node(parent));
    74		if (IS_ERR(map)) {
    75			dev_err(dev, "no regmap for syscon LED parent\n");
    76			return PTR_ERR(map);
    77		}
    78	
    79		sled = devm_kzalloc(dev, sizeof(*sled), GFP_KERNEL);
    80		if (!sled)
    81			return -ENOMEM;
    82	
    83		sled->map = map;
    84	
    85		if (of_property_read_u32(np, "offset", &sled->offset))
    86			return -EINVAL;
    87		if (of_property_read_u32(np, "mask", &sled->mask))
    88			return -EINVAL;
    89	
    90		init_data.fwnode = of_fwnode_handle(np);
    91	
  > 92		state = led_init_default_state_get(init_data.fwnode);
    93		switch (state) {
    94		case LEDS_DEFSTATE_ON:
    95			ret = regmap_update_bits(map, sled->offset, sled->mask, sled->mask);
    96			if (ret < 0)
    97				return ret;
    98			sled->state = true;
    99			break;
   100		case LEDS_DEFSTATE_KEEP:
   101			ret = regmap_read(map, sled->offset, &value);
   102			if (ret < 0)
   103				return ret;
   104			sled->state = !!(value & sled->mask);
   105			break;
   106		default:
   107			ret = regmap_update_bits(map, sled->offset, sled->mask, 0);
   108			if (ret < 0)
   109				return ret;
   110			sled->state = false;
   111		}
   112		sled->cdev.brightness_set = syscon_led_set;
   113	
   114		ret = devm_led_classdev_register_ext(dev, &sled->cdev, &init_data);
   115		if (ret < 0)
   116			return ret;
   117	
   118		platform_set_drvdata(pdev, sled);
   119		dev_info(dev, "registered LED %s\n", sled->cdev.name);
   120	
   121		return 0;
   122	}
   123
diff mbox series

Patch

diff --git a/drivers/leds/leds-syscon.c b/drivers/leds/leds-syscon.c
index 7eddb8ecb44e..e38abb5e60c1 100644
--- a/drivers/leds/leds-syscon.c
+++ b/drivers/leds/leds-syscon.c
@@ -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;