leds: max5970: Add support for max5970
PATCH 1/1 leds: max5970: Add support for max5970
From: Patrick Rudolph <[email protected]>
The MAX5970 is hot swap controller and has 4 indication LED.
--- drivers/leds/Kconfig | 11 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-max5970.c | 129 ++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 drivers/leds/leds-max5970.c
drivers/leds/Kconfig +11 -0
@@ -637,6 +637,17 @@ config LEDS_ADP5520 To compile this driver as a module, choose M here: the module will be called leds-adp5520. +config LEDS_MAX5970 + tristate "LED Support for Maxim 5970" + depends on LEDS_CLASS + depends on MFD_MAX5970 + help + This option enables support for the Maxim MAX5970 & MAX5978 smart + switch indication LEDs via the I2C bus. + + To compile this driver as a module, choose M here: the module will + be called leds-max5970. + config LEDS_MC13783 tristate "LED Support for MC13XXX PMIC" depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o obj-$(CONFIG_LEDS_LP8860) += leds-lp8860.o obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o +obj-$(CONFIG_LEDS_MAX5970) += leds-max5970.o obj-$(CONFIG_LEDS_MAX77650) += leds-max77650.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.o
drivers/leds/leds-max5970.c new file +129 -0
129 lines not on this page · raw message
base-commit: baca986e1f2c31f8e4b2a6d99d47c3bc844033e8
Signature · 1 line
2.41.0
Le 23/08/2023 à 23:23, Naresh Solanki a écrit :
Quoted 137 lines
From: Patrick Rudolph <[email protected]>
The MAX5970 is hot swap controller and has 4 indication LED.
Signed-off-by Patrick Rudolph <[email protected]>Signed-off-by Naresh Solanki <[email protected]>--- drivers/leds/Kconfig | 11 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-max5970.c | 129 ++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+)create mode 100644
drivers/leds/leds-max5970.cdrivers/leds/Kconfig +11
-0@@ -637,6 +637,17 @@ config LEDS_ADP5520 To compile this driver as a module, choose M here: the module will be called leds-adp5520. +config LEDS_MAX5970 + tristate "LED Support for Maxim 5970" + depends on LEDS_CLASS + depends on MFD_MAX5970 + help + This option enables support for the Maxim MAX5970 & MAX5978 smart + switch indication LEDs via the I2C bus. + + To compile this driver as a module, choose M here: the module will + be called leds-max5970. + config LEDS_MC13783 tristate "LED Support for MC13XXX PMIC" depends on LEDS_CLASSdrivers/leds/Makefile +1
-0@@ -56,6 +56,7 @@ obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o obj-$(CONFIG_LEDS_LP8860) += leds-lp8860.o obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o +obj-$(CONFIG_LEDS_MAX5970) += leds-max5970.o obj-$(CONFIG_LEDS_MAX77650) += leds-max77650.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.odrivers/leds/leds-max5970.c new file +84
-0@@ -0,0 +1,129 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Device driver for leds in MAX5970 and MAX5978 IC +* +* Copyright (c) 2022 9elements GmbH +* +* Author: Patrick Rudolph <[email protected]> +*/ + +#include <linux/leds.h> +#include <linux/mfd/max5970.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define ldev_to_maxled (c) container_of(c, struct max5970_led, cdev) + +struct max5970_led { +struct device *dev; +struct regmap *regmap; +struct led_classdev cdev; +unsigned int index; +}; + +static int max5970_led_set_brightness (struct led_classdev *cdev, +enum led_brightness brightness) +{ +struct max5970_led *ddata =ldev_to_maxled (cdev); +int ret, val; + +if (!ddata->regmap) +return -ENODEV ; + +/* Set/clear corresponding bit for given led index */ + val = !brightness ?BIT (ddata->index) :0 ; + + ret =regmap_update_bits (ddata->regmap,MAX5970_REG_LED_FLASH ,BIT (ddata->index), val); +if (ret <0 ) +dev_err (cdev->dev,"failed to set brightness %d" , ret); + +return ret; +} + +static int max5970_setup_led (struct max5970_led *ddata,struct regmap *regmap, +struct device_node *nc,u32 reg) +{ +int ret; + +if (of_property_read_string (nc,"label" , &ddata->cdev.name)) + ddata->cdev.name = nc->name; + + ddata->cdev.max_brightness =1 ; + ddata->cdev.brightness_set_blocking = max5970_led_set_brightness; + ddata->cdev.default_trigger ="none" ; + + ret =devm_led_classdev_register (ddata->dev, &ddata->cdev); +if (ret) +dev_err (ddata->dev,"Error initializing LED %s" , ddata->cdev.name); + +return ret; +} + +static int max5970_led_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np =dev_of_node (dev->parent); +struct regmap *regmap; +struct device_node *led_node; +struct device_node *child; +struct max5970_led *ddata[MAX5970_NUM_LEDS ]; +int ret = -ENODEV , num_leds =0 ; + + regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!regmap) +return -EPROBE_DEFER ; + + led_node =of_get_child_by_name (np,"leds" ); +if (!led_node) +return -ENODEV ; + +for_each_available_child_of_node (led_node, child) { +u32 reg; + +if (of_property_read_u32 (child,"reg" , ®))
drivers/leds/leds-max5970.c line 94
Quoted 10 lines
drivers/leds/leds-max5970.c new file +10
-0+continue ; + +if (reg >=MAX5970_NUM_LEDS ) { +dev_err (dev,"invalid LED (%u >= %d)\n" , reg,MAX5970_NUM_LEDS ); +continue ; + } + + ddata[num_leds] =devm_kzalloc (dev,sizeof (struct max5970_led ),GFP_KERNEL ); +if (!ddata[num_leds]) { + ret = -ENOMEM ;
Hi,
Should we have a "of_node_put(child);" here?
drivers/leds/leds-max5970.c line 104
Quoted 10 lines
drivers/leds/leds-max5970.c new file +10
-0+ goto exit; + } + + ddata[num_leds]->index = reg; + ddata[num_leds]->regmap = regmap; + ddata[num_leds]->dev = dev; + + ret =max5970_setup_led (ddata[num_leds], regmap, child, reg); +if (ret <0 ) { +dev_err (dev,"Failed to initialize LED %u\n" , reg);
Should we have a "of_node_put(child);" here?
drivers/leds/leds-max5970.c line 114
Quoted 10 lines
drivers/leds/leds-max5970.c new file +10
-0+ goto exit; + } + num_leds++; + } + +return ret; + +exit: +for (int j =0 ; j < num_leds; j++) +devm_led_classdev_unregister (dev, &ddata[j]->cdev);
Is it really needed?
There is no equivalent call in a .remove function and devm_led_classdev_register() is used.
Shouldn't the unregister step be done automatically by the framework?
CJ
Quoted 17 lines
drivers/leds/leds-max5970.c new file +15
-0+ +return ret; +} + +static struct platform_driver max5970_led_driver = { + .driver = { + .name ="max5970-led" , + }, + .probe = max5970_led_probe, +}; + +module_platform_driver (max5970_led_driver); +MODULE_AUTHOR ("Patrick Rudolph <[email protected]>" ); +MODULE_DESCRIPTION ("MAX5970_hot-swap controller LED driver" ); +MODULE_LICENSE ("GPL" );base-commit:
baca986e1f2c31f8e4b2a6d99d47c3bc844033e8
Hi,
Quoted 152 lines · Christophe JAILLET
Quoted 137 lines · Naresh Solanki
From: Patrick Rudolph <[email protected]>
The MAX5970 is hot swap controller and has 4 indication LED.
Signed-off-by Patrick Rudolph <[email protected]>Signed-off-by Naresh Solanki <[email protected]>--- drivers/leds/Kconfig | 11 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-max5970.c | 129 ++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+)create mode 100644
drivers/leds/leds-max5970.cdrivers/leds/Kconfig +11
-0@@ -637,6 +637,17 @@ config LEDS_ADP5520 To compile this driver as a module, choose M here: the module will be called leds-adp5520. +config LEDS_MAX5970 + tristate "LED Support for Maxim 5970" + depends on LEDS_CLASS + depends on MFD_MAX5970 + help + This option enables support for the Maxim MAX5970 & MAX5978 smart + switch indication LEDs via the I2C bus. + + To compile this driver as a module, choose M here: the module will + be called leds-max5970. + config LEDS_MC13783 tristate "LED Support for MC13XXX PMIC" depends on LEDS_CLASSdrivers/leds/Makefile +1
-0@@ -56,6 +56,7 @@ obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o obj-$(CONFIG_LEDS_LP8860) += leds-lp8860.o obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o +obj-$(CONFIG_LEDS_MAX5970) += leds-max5970.o obj-$(CONFIG_LEDS_MAX77650) += leds-max77650.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.odrivers/leds/leds-max5970.c new file +84
-0@@ -0,0 +1,129 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Device driver for leds in MAX5970 and MAX5978 IC +* +* Copyright (c) 2022 9elements GmbH +* +* Author: Patrick Rudolph <[email protected]> +*/ + +#include <linux/leds.h> +#include <linux/mfd/max5970.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define ldev_to_maxled (c) container_of(c, struct max5970_led, cdev) + +struct max5970_led { +struct device *dev; +struct regmap *regmap; +struct led_classdev cdev; +unsigned int index; +}; + +static int max5970_led_set_brightness (struct led_classdev *cdev, +enum led_brightness brightness) +{ +struct max5970_led *ddata =ldev_to_maxled (cdev); +int ret, val; + +if (!ddata->regmap) +return -ENODEV ; + +/* Set/clear corresponding bit for given led index */ + val = !brightness ?BIT (ddata->index) :0 ; + + ret =regmap_update_bits (ddata->regmap,MAX5970_REG_LED_FLASH ,BIT (ddata->index), val); +if (ret <0 ) +dev_err (cdev->dev,"failed to set brightness %d" , ret); + +return ret; +} + +static int max5970_setup_led (struct max5970_led *ddata,struct regmap *regmap, +struct device_node *nc,u32 reg) +{ +int ret; + +if (of_property_read_string (nc,"label" , &ddata->cdev.name)) + ddata->cdev.name = nc->name; + + ddata->cdev.max_brightness =1 ; + ddata->cdev.brightness_set_blocking = max5970_led_set_brightness; + ddata->cdev.default_trigger ="none" ; + + ret =devm_led_classdev_register (ddata->dev, &ddata->cdev); +if (ret) +dev_err (ddata->dev,"Error initializing LED %s" , ddata->cdev.name); + +return ret; +} + +static int max5970_led_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np =dev_of_node (dev->parent); +struct regmap *regmap; +struct device_node *led_node; +struct device_node *child; +struct max5970_led *ddata[MAX5970_NUM_LEDS ]; +int ret = -ENODEV , num_leds =0 ; + + regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!regmap) +return -EPROBE_DEFER ; + + led_node =of_get_child_by_name (np,"leds" ); +if (!led_node) +return -ENODEV ; + +for_each_available_child_of_node (led_node, child) { +u32 reg; + +if (of_property_read_u32 (child,"reg" , ®))drivers/leds/leds-max5970.c line 94
Quoted 10 lines
drivers/leds/leds-max5970.c new file +10
-0+continue ; + +if (reg >=MAX5970_NUM_LEDS ) { +dev_err (dev,"invalid LED (%u >= %d)\n" , reg,MAX5970_NUM_LEDS ); +continue ; + } + + ddata[num_leds] =devm_kzalloc (dev,sizeof (struct max5970_led ),GFP_KERNEL ); +if (!ddata[num_leds]) { + ret = -ENOMEM ;Hi,
Quoted 1 line
Should we have a "
of_node_put(child);" here?
Ack. Will add in next revision.
Quoted 13 lines
drivers/leds/leds-max5970.c line 104
Quoted 11 lines
drivers/leds/leds-max5970.c new file +10
-0+ goto exit; + } + + ddata[num_leds]->index = reg; + ddata[num_leds]->regmap = regmap; + ddata[num_leds]->dev = dev; + + ret =max5970_setup_led (ddata[num_leds], regmap, child, reg); +if (ret <0 ) { +dev_err (dev,"Failed to initialize LED %u\n" , reg);Should we have a "
of_node_put(child);" here?
Ack.
Quoted 16 lines
drivers/leds/leds-max5970.c line 114
Quoted 11 lines
drivers/leds/leds-max5970.c new file +10
-0+ goto exit; + } + num_leds++; + } + +return ret; + +exit: +for (int j =0 ; j < num_leds; j++) +devm_led_classdev_unregister (dev, &ddata[j]->cdev);Is it really needed?
There is no equivalent call in a .remove function anddevm_led_classdev_register()is used.
Quoted 1 line
Shouldn't the unregister step be done automatically by the framework?
Ack. Will be removed in the next revision.
Instead of using goto exit, will return with the error code.
Regards,
Naresh
Quoted 21 lines
CJ
Quoted 17 lines
drivers/leds/leds-max5970.c new file +15
-0+ +return ret; +} + +static struct platform_driver max5970_led_driver = { + .driver = { + .name ="max5970-led" , + }, + .probe = max5970_led_probe, +}; + +module_platform_driver (max5970_led_driver); +MODULE_AUTHOR ("Patrick Rudolph <[email protected]>" ); +MODULE_DESCRIPTION ("MAX5970_hot-swap controller LED driver" ); +MODULE_LICENSE ("GPL" );base-commit:
baca986e1f2c31f8e4b2a6d99d47c3bc844033e8
Quoted 76 lines · Naresh Solanki
From: Patrick Rudolph <[email protected]>
The MAX5970 is hot swap controller and has 4 indication LED.
Signed-off-by Patrick Rudolph <[email protected]>Signed-off-by Naresh Solanki <[email protected]>--- drivers/leds/Kconfig | 11 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-max5970.c | 129 ++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 drivers/leds/leds-max5970.cdrivers/leds/Kconfig +11
-0@@ -637,6 +637,17 @@ config LEDS_ADP5520 To compile this driver as a module, choose M here: the module will be called leds-adp5520. +config LEDS_MAX5970 + tristate "LED Support for Maxim 5970" + depends on LEDS_CLASS + depends on MFD_MAX5970 + help + This option enables support for the Maxim MAX5970 & MAX5978 smart + switch indication LEDs via the I2C bus. + + To compile this driver as a module, choose M here: the module will + be called leds-max5970. + config LEDS_MC13783 tristate "LED Support for MC13XXX PMIC" depends on LEDS_CLASSdrivers/leds/Makefile +1
-0@@ -56,6 +56,7 @@ obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o obj-$(CONFIG_LEDS_LP8860) += leds-lp8860.o obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o +obj-$(CONFIG_LEDS_MAX5970) += leds-max5970.o obj-$(CONFIG_LEDS_MAX77650) += leds-max77650.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.odrivers/leds/leds-max5970.c new file +22
-0@@ -0,0 +1,129 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Device driver for leds in MAX5970 and MAX5978 IC +* +* Copyright (c) 2022 9elements GmbH +* +* Author: Patrick Rudolph <[email protected]> +*/ + +#include <linux/leds.h> +#include <linux/mfd/max5970.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define ldev_to_maxled (c) container_of(c, struct max5970_led, cdev) + +struct max5970_led { +struct device *dev; +struct regmap *regmap; +struct led_classdev cdev; +unsigned int index;
drivers/leds/leds-max5970.c line 32
Quoted 10 lines
drivers/leds/leds-max5970.c new file +10
-0+}; + +static int max5970_led_set_brightness (struct led_classdev *cdev, +enum led_brightness brightness) +{ +struct max5970_led *ddata =ldev_to_maxled (cdev); +int ret, val; + +if (!ddata->regmap) +return -ENODEV ;
Can this ever happen? Looks like this conditions is always false.
Quoted 4 lines
drivers/leds/leds-max5970.c new file +4
-0+ +/* Set/clear corresponding bit for given led index */ + val = !brightness ?BIT (ddata->index) :0 ; +
drivers/leds/leds-max5970.c line 46
Quoted 10 lines
drivers/leds/leds-max5970.c new file +10
-0+ ret =regmap_update_bits (ddata->regmap,MAX5970_REG_LED_FLASH ,BIT (ddata->index), val); +if (ret <0 ) +dev_err (cdev->dev,"failed to set brightness %d" , ret); + +return ret; +} + +static int max5970_setup_led (struct max5970_led *ddata,struct regmap *regmap, +struct device_node *nc,u32 reg) +{
regmap and reg is not used within this function.
I don't see the need for this function, just add those 8 lines in the loop below.
Quoted 71 lines
drivers/leds/leds-max5970.c new file +71
-0+int ret; + +if (of_property_read_string (nc,"label" , &ddata->cdev.name)) + ddata->cdev.name = nc->name; + + ddata->cdev.max_brightness =1 ; + ddata->cdev.brightness_set_blocking = max5970_led_set_brightness; + ddata->cdev.default_trigger ="none" ; + + ret =devm_led_classdev_register (ddata->dev, &ddata->cdev); +if (ret) +dev_err (ddata->dev,"Error initializing LED %s" , ddata->cdev.name); + +return ret; +} + +static int max5970_led_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np =dev_of_node (dev->parent); +struct regmap *regmap; +struct device_node *led_node; +struct device_node *child; +struct max5970_led *ddata[MAX5970_NUM_LEDS ]; +int ret = -ENODEV , num_leds =0 ; + + regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!regmap) +return -EPROBE_DEFER ; + + led_node =of_get_child_by_name (np,"leds" ); +if (!led_node) +return -ENODEV ; + +for_each_available_child_of_node (led_node, child) { +u32 reg; + +if (of_property_read_u32 (child,"reg" , ®)) +continue ; + +if (reg >=MAX5970_NUM_LEDS ) { +dev_err (dev,"invalid LED (%u >= %d)\n" , reg,MAX5970_NUM_LEDS ); +continue ; + } + + ddata[num_leds] =devm_kzalloc (dev,sizeof (struct max5970_led ),GFP_KERNEL ); +if (!ddata[num_leds]) { + ret = -ENOMEM ; + goto exit; + } + + ddata[num_leds]->index = reg; + ddata[num_leds]->regmap = regmap; + ddata[num_leds]->dev = dev; + + ret =max5970_setup_led (ddata[num_leds], regmap, child, reg); +if (ret <0 ) { +dev_err (dev,"Failed to initialize LED %u\n" , reg); + goto exit; + } + num_leds++; + } + +return ret; + +exit: +for (int j =0 ; j < num_leds; j++) +devm_led_classdev_unregister (dev, &ddata[j]->cdev); + +return ret; +}
drivers/leds/leds-max5970.c line 127
Quoted 10 lines
drivers/leds/leds-max5970.c new file +10
-0+ +static struct platform_driver max5970_led_driver = { + .driver = { + .name ="max5970-led" , + }, + .probe = max5970_led_probe, +}; + +module_platform_driver (max5970_led_driver); +MODULE_AUTHOR ("Patrick Rudolph <[email protected]>" );
You might want to put your name here, as you've rewritten the complete driver code.
Quoted 7 lines
drivers/leds/leds-max5970.c new file +2
-0+MODULE_DESCRIPTION ("MAX5970_hot-swap controller LED driver" ); +MODULE_LICENSE ("GPL" );base-commit:
baca986e1f2c31f8e4b2a6d99d47c3bc844033e8--
2.41.0
Hi
Quoted 82 lines · Patrick Rudolph
Quoted 79 lines · Naresh Solanki
From: Patrick Rudolph <[email protected]>
The MAX5970 is hot swap controller and has 4 indication LED.
Signed-off-by Patrick Rudolph <[email protected]>Signed-off-by Naresh Solanki <[email protected]>--- drivers/leds/Kconfig | 11 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-max5970.c | 129 ++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 drivers/leds/leds-max5970.cdrivers/leds/Kconfig +11
-0@@ -637,6 +637,17 @@ config LEDS_ADP5520 To compile this driver as a module, choose M here: the module will be called leds-adp5520. +config LEDS_MAX5970 + tristate "LED Support for Maxim 5970" + depends on LEDS_CLASS + depends on MFD_MAX5970 + help + This option enables support for the Maxim MAX5970 & MAX5978 smart + switch indication LEDs via the I2C bus. + + To compile this driver as a module, choose M here: the module will + be called leds-max5970. + config LEDS_MC13783 tristate "LED Support for MC13XXX PMIC" depends on LEDS_CLASSdrivers/leds/Makefile +1
-0@@ -56,6 +56,7 @@ obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o obj-$(CONFIG_LEDS_LP8860) += leds-lp8860.o obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o +obj-$(CONFIG_LEDS_MAX5970) += leds-max5970.o obj-$(CONFIG_LEDS_MAX77650) += leds-max77650.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.odrivers/leds/leds-max5970.c new file +25
-0@@ -0,0 +1,129 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Device driver for leds in MAX5970 and MAX5978 IC +* +* Copyright (c) 2022 9elements GmbH +* +* Author: Patrick Rudolph <[email protected]> +*/ + +#include <linux/leds.h> +#include <linux/mfd/max5970.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define ldev_to_maxled (c) container_of(c, struct max5970_led, cdev) + +struct max5970_led { +struct device *dev; +struct regmap *regmap; +struct led_classdev cdev; +unsigned int index; +}; + +static int max5970_led_set_brightness(struct led_classdev *cdev,
Quoted 8 lines
drivers/leds/leds-max5970.c line 32
Quoted 7 lines
drivers/leds/leds-max5970.c new file +7
-0+ enum led_brightness brightness) +{ +struct max5970_led *ddata =ldev_to_maxled (cdev); +int ret, val; + +if (!ddata->regmap) +return -ENODEV ;Can this ever happen? Looks like this conditions is always false.
Yes. Will be removed in the next revision.
Quoted 10 lines
Quoted 10 lines
drivers/leds/leds-max5970.c new file +9
-0+ +/* Set/clear corresponding bit for given led index */ + val = !brightness ?BIT (ddata->index) :0 ; + + ret =regmap_update_bits (ddata->regmap,MAX5970_REG_LED_FLASH ,BIT (ddata->index), val); +if (ret <0 ) +dev_err (cdev->dev,"failed to set brightness %d" , ret); + +return ret;
Quoted 8 lines
drivers/leds/leds-max5970.c line 46
Quoted 5 lines
drivers/leds/leds-max5970.c new file +5
-0+} + +static int max5970_setup_led (struct max5970_led *ddata,struct regmap *regmap, +struct device_node *nc,u32 reg) +{regmap and reg is not used within this function.
I don't see the need for this function, just add those 8 lines in the loop below.
Ack.
Quoted 77 lines
Quoted 77 lines
drivers/leds/leds-max5970.c new file +76
-0+int ret; + +if (of_property_read_string (nc,"label" , &ddata->cdev.name)) + ddata->cdev.name = nc->name; + + ddata->cdev.max_brightness =1 ; + ddata->cdev.brightness_set_blocking = max5970_led_set_brightness; + ddata->cdev.default_trigger ="none" ; + + ret =devm_led_classdev_register (ddata->dev, &ddata->cdev); +if (ret) +dev_err (ddata->dev,"Error initializing LED %s" , ddata->cdev.name); + +return ret; +} + +static int max5970_led_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np =dev_of_node (dev->parent); +struct regmap *regmap; +struct device_node *led_node; +struct device_node *child; +struct max5970_led *ddata[MAX5970_NUM_LEDS ]; +int ret = -ENODEV , num_leds =0 ; + + regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!regmap) +return -EPROBE_DEFER ; + + led_node =of_get_child_by_name (np,"leds" ); +if (!led_node) +return -ENODEV ; + +for_each_available_child_of_node (led_node, child) { +u32 reg; + +if (of_property_read_u32 (child,"reg" , ®)) +continue ; + +if (reg >=MAX5970_NUM_LEDS ) { +dev_err (dev,"invalid LED (%u >= %d)\n" , reg,MAX5970_NUM_LEDS ); +continue ; + } + + ddata[num_leds] =devm_kzalloc (dev,sizeof (struct max5970_led ),GFP_KERNEL ); +if (!ddata[num_leds]) { + ret = -ENOMEM ; + goto exit; + } + + ddata[num_leds]->index = reg; + ddata[num_leds]->regmap = regmap; + ddata[num_leds]->dev = dev; + + ret =max5970_setup_led (ddata[num_leds], regmap, child, reg); +if (ret <0 ) { +dev_err (dev,"Failed to initialize LED %u\n" , reg); + goto exit; + } + num_leds++; + } + +return ret; + +exit: +for (int j =0 ; j < num_leds; j++) +devm_led_classdev_unregister (dev, &ddata[j]->cdev); + +return ret; +} + +static struct platform_driver max5970_led_driver = { + .driver = { + .name ="max5970-led" , + },
Quoted 8 lines
drivers/leds/leds-max5970.c line 127
Quoted 5 lines
drivers/leds/leds-max5970.c new file +5
-0+ .probe = max5970_led_probe, +}; + +module_platform_driver (max5970_led_driver); +MODULE_AUTHOR ("Patrick Rudolph <[email protected]>" );You might want to put your name here, as you've rewritten the complete driver code.
ok.
Regards,
Naresh
Quoted 8 lines
Quoted 8 lines
drivers/leds/leds-max5970.c new file +2
-0+MODULE_DESCRIPTION ("MAX5970_hot-swap controller LED driver" ); +MODULE_LICENSE ("GPL" );base-commit:
baca986e1f2c31f8e4b2a6d99d47c3bc844033e8--
2.41.0