All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 2/3] leds: Add driver for MAX8907 LED cell
  2026-11-15  9:05 [PATCH v6 0/3] " Svyatoslav Ryhel
@ 2026-11-15  9:05 ` Svyatoslav Ryhel
  0 siblings, 0 replies; 3+ messages in thread
From: Svyatoslav Ryhel @ 2026-11-15  9:05 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
	Svyatoslav Ryhel
  Cc: linux-kernel, devicetree, linux-leds, mfd

Add a small driver to control the LED cell provided by the MAX8907 PMIC.
The LED node is a child of the PMIC node.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
 drivers/leds/Kconfig        | 10 ++++
 drivers/leds/Makefile       |  1 +
 drivers/leds/leds-max8907.c | 99 +++++++++++++++++++++++++++++++++++++
 include/linux/mfd/max8907.h |  2 +-
 4 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100644 drivers/leds/leds-max8907.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 788e689fe875c..d4e0f514bd667 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -813,6 +813,16 @@ config LEDS_MAX77705
 	help
 	  LED driver for MAX77705 PMIC from Maxim Integrated.
 
+config LEDS_MAX8907
+	tristate "LED support for MAX8907 PMIC"
+	depends on LEDS_CLASS && MFD_MAX8907
+	help
+	  This option enables support for on-chip LED drivers on
+	  MAXIM MAX8907 PMIC.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called leds-max8907.
+
 config LEDS_MAX8997
 	tristate "LED support for MAX8997 PMIC"
 	depends on LEDS_CLASS && MFD_MAX8997
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3da746279bb81..24efda3fbaa44 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_LTC3220)		+= leds-ltc3220.o
 obj-$(CONFIG_LEDS_MAX5970)		+= leds-max5970.o
 obj-$(CONFIG_LEDS_MAX77650)		+= leds-max77650.o
 obj-$(CONFIG_LEDS_MAX77705)		+= leds-max77705.o
+obj-$(CONFIG_LEDS_MAX8907)		+= leds-max8907.o
 obj-$(CONFIG_LEDS_MAX8997)		+= leds-max8997.o
 obj-$(CONFIG_LEDS_MC13783)		+= leds-mc13783.o
 obj-$(CONFIG_LEDS_MENF21BMC)		+= leds-menf21bmc.o
diff --git a/drivers/leds/leds-max8907.c b/drivers/leds/leds-max8907.c
new file mode 100644
index 0000000000000..46c60fde4ee39
--- /dev/null
+++ b/drivers/leds/leds-max8907.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/cleanup.h>
+#include <linux/err.h>
+#include <linux/leds.h>
+#include <linux/mfd/max8907.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+
+#define MAX8907_REG_WLED_MODE_ON	BIT(0)
+
+struct max8907_led_data {
+	struct regmap *regmap;
+	struct led_classdev cdev;
+};
+
+static enum led_brightness max8907_led_get_brightness(struct led_classdev *cdev)
+{
+	struct max8907_led_data *ddata = container_of(cdev, struct max8907_led_data, cdev);
+	unsigned int brightness_lvl;
+	int ret;
+
+	ret = regmap_read(ddata->regmap, MAX8907_REG_WLED_MODE_CNTL, &brightness_lvl);
+	if (ret || !(brightness_lvl & MAX8907_REG_WLED_MODE_ON))
+		return LED_OFF;
+
+	ret = regmap_read(ddata->regmap, MAX8907_REG_WLED_CNTL, &brightness_lvl);
+	if (ret)
+		return LED_OFF;
+
+	return brightness_lvl;
+}
+
+static int max8907_led_set_brightness(struct led_classdev *cdev,
+				      enum led_brightness brightness)
+{
+	struct max8907_led_data *ddata = container_of(cdev, struct max8907_led_data, cdev);
+	int brightness_lvl, ret;
+
+	brightness_lvl = clamp(brightness, LED_OFF, LED_FULL);
+
+	if (brightness_lvl) {
+		ret = regmap_write(ddata->regmap, MAX8907_REG_WLED_CNTL, brightness_lvl);
+		if (ret)
+			return ret;
+	}
+
+	return regmap_update_bits(ddata->regmap, MAX8907_REG_WLED_MODE_CNTL,
+				  MAX8907_REG_WLED_MODE_ON,
+				  brightness_lvl ? MAX8907_REG_WLED_MODE_ON : 0);
+}
+
+static int max8907_led_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *led_np __free(device_node) =
+		of_get_available_child_by_name(dev_of_node(dev->parent), "led");
+	struct max8907 *max8907 = dev_get_drvdata(dev->parent);
+	struct led_init_data init_data = { };
+	struct max8907_led_data *ddata;
+
+	if (!led_np)
+		return -ENODEV;
+
+	ddata = devm_kzalloc_obj(dev, struct max8907_led_data);
+	if (!ddata)
+		return -ENOMEM;
+
+	ddata->regmap = max8907->regmap_gen;
+
+	init_data.fwnode = of_fwnode_handle(led_np);
+	init_data.devicename = "max8907";
+	init_data.default_label = ":wled";
+
+	ddata->cdev.brightness = LED_OFF;
+	ddata->cdev.flags = LED_CORE_SUSPENDRESUME;
+	ddata->cdev.max_brightness = LED_FULL;
+
+	ddata->cdev.brightness_get = max8907_led_get_brightness;
+	ddata->cdev.brightness_set_blocking = max8907_led_set_brightness;
+
+	return devm_led_classdev_register_ext(dev, &ddata->cdev, &init_data);
+}
+
+static struct platform_driver max8907_led_driver = {
+	.driver = {
+		.name = "max8907-leds",
+	},
+	.probe = max8907_led_probe,
+};
+module_platform_driver(max8907_led_driver);
+
+MODULE_ALIAS("platform:max8907-leds");
+MODULE_AUTHOR("Svyatoslav Ryhel <clamor95@gmail.com>");
+MODULE_DESCRIPTION("MAX8907 LED driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/max8907.h b/include/linux/mfd/max8907.h
index 025874e5f8808..9865ae52877fd 100644
--- a/include/linux/mfd/max8907.h
+++ b/include/linux/mfd/max8907.h
@@ -112,7 +112,7 @@
 #define MAX8907_REG_CHG_IRQ2_MASK	0x81
 #define MAX8907_REG_CHG_STAT		0x82
 #define MAX8907_REG_WLED_MODE_CNTL	0x84
-#define MAX8907_REG_ILED_CNTL		0x84
+#define MAX8907_REG_WLED_CNTL		0x85
 #define MAX8907_REG_II1RR		0x8E
 #define MAX8907_REG_II2RR		0x8F
 #define MAX8907_REG_LDOCTL20		0x9C
-- 
2.53.0


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

* Re: [PATCH v6 2/3] leds: Add driver for MAX8907 LED cell
@ 2026-11-22 11:18 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-11-22 11:18 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "linux-review patch is more than 7 days old, verify it wasn't already superseded"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20261115090520.102216-3-clamor95@gmail.com>
References: <20261115090520.102216-3-clamor95@gmail.com>
TO: Svyatoslav Ryhel <clamor95@gmail.com>
TO: Liam Girdwood <lgirdwood@gmail.com>
TO: Mark Brown <broonie@kernel.org>
TO: Rob Herring <robh@kernel.org>
TO: Krzysztof Kozlowski <krzk@kernel.org>
TO: Conor Dooley <conor+dt@kernel.org>
TO: Lee Jones <lee@kernel.org>
TO: Pavel Machek <pavel@kernel.org>
TO: "Griffin Kroah-Hartman" <griffin@kroah.com>
TO: Svyatoslav Ryhel <clamor95@gmail.com>
CC: linux-kernel@vger.kernel.org
CC: devicetree@vger.kernel.org
CC: linux-leds@vger.kernel.org
CC: mfd@lists.linux.dev

Hi Svyatoslav,

kernel test robot noticed the following build errors:

[auto build test ERROR on linux-review/Svyatoslav-Ryhel/regulator-dt-bindings-maxim-max8907-Convert-to-DT-schema/20261027-134631]

url:    https://github.com/intel-lab-lkp/linux/commits/Svyatoslav-Ryhel/regulator-dt-bindings-maxim-max8907-Document-LED-support/20261115-110518
base:   https://github.com/intel-lab-lkp/linux Svyatoslav-Ryhel/regulator-dt-bindings-maxim-max8907-Convert-to-DT-schema/20261027-134631
patch link:    https://lore.kernel.org/r/20261115090520.102216-3-clamor95%40gmail.com
patch subject: [PATCH v6 2/3] leds: Add driver for MAX8907 LED cell
:::::: branch date: 7 days ago
:::::: commit date: 7 days ago
config: nios2-allmodconfig (https://download.01.org/0day-ci/archive/20261122/202611221902.rkRrBSnk-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261122/202611221902.rkRrBSnk-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/202611221902.rkRrBSnk-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/leds/leds-max8907.c: In function 'max8907_led_probe':
>> drivers/leds/leds-max8907.c:68:17: error: implicit declaration of function 'devm_kzalloc_obj'; did you mean 'devm_kzalloc'? [-Werror=implicit-function-declaration]
      68 |         ddata = devm_kzalloc_obj(dev, struct max8907_led_data);
         |                 ^~~~~~~~~~~~~~~~
         |                 devm_kzalloc
>> drivers/leds/leds-max8907.c:68:39: error: expected expression before 'struct'
      68 |         ddata = devm_kzalloc_obj(dev, struct max8907_led_data);
         |                                       ^~~~~~
   cc1: some warnings being treated as errors


vim +68 drivers/leds/leds-max8907.c

7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  55  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  56  static int max8907_led_probe(struct platform_device *pdev)
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  57  {
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  58  	struct device *dev = &pdev->dev;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  59  	struct device_node *led_np __free(device_node) =
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  60  		of_get_available_child_by_name(dev_of_node(dev->parent), "led");
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  61  	struct max8907 *max8907 = dev_get_drvdata(dev->parent);
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  62  	struct led_init_data init_data = { };
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  63  	struct max8907_led_data *ddata;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  64  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  65  	if (!led_np)
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  66  		return -ENODEV;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  67  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15 @68  	ddata = devm_kzalloc_obj(dev, struct max8907_led_data);
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  69  	if (!ddata)
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  70  		return -ENOMEM;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  71  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  72  	ddata->regmap = max8907->regmap_gen;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  73  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  74  	init_data.fwnode = of_fwnode_handle(led_np);
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  75  	init_data.devicename = "max8907";
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  76  	init_data.default_label = ":wled";
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  77  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  78  	ddata->cdev.brightness = LED_OFF;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  79  	ddata->cdev.flags = LED_CORE_SUSPENDRESUME;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  80  	ddata->cdev.max_brightness = LED_FULL;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  81  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  82  	ddata->cdev.brightness_get = max8907_led_get_brightness;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  83  	ddata->cdev.brightness_set_blocking = max8907_led_set_brightness;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  84  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  85  	return devm_led_classdev_register_ext(dev, &ddata->cdev, &init_data);
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  86  }
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  87  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH v6 2/3] leds: Add driver for MAX8907 LED cell
@ 2026-11-22 15:08 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-11-22 15:08 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "linux-review patch is more than 7 days old, verify it wasn't already superseded"
:::::: 

BCC: lkp@intel.com
CC: llvm@lists.linux.dev
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20261115090520.102216-3-clamor95@gmail.com>
References: <20261115090520.102216-3-clamor95@gmail.com>
TO: Svyatoslav Ryhel <clamor95@gmail.com>
TO: Liam Girdwood <lgirdwood@gmail.com>
TO: Mark Brown <broonie@kernel.org>
TO: Rob Herring <robh@kernel.org>
TO: Krzysztof Kozlowski <krzk@kernel.org>
TO: Conor Dooley <conor+dt@kernel.org>
TO: Lee Jones <lee@kernel.org>
TO: Pavel Machek <pavel@kernel.org>
TO: "Griffin Kroah-Hartman" <griffin@kroah.com>
TO: Svyatoslav Ryhel <clamor95@gmail.com>
CC: linux-kernel@vger.kernel.org
CC: devicetree@vger.kernel.org
CC: linux-leds@vger.kernel.org
CC: mfd@lists.linux.dev

Hi Svyatoslav,

kernel test robot noticed the following build errors:

[auto build test ERROR on linux-review/Svyatoslav-Ryhel/regulator-dt-bindings-maxim-max8907-Convert-to-DT-schema/20261027-134631]

url:    https://github.com/intel-lab-lkp/linux/commits/Svyatoslav-Ryhel/regulator-dt-bindings-maxim-max8907-Document-LED-support/20261115-110518
base:   https://github.com/intel-lab-lkp/linux Svyatoslav-Ryhel/regulator-dt-bindings-maxim-max8907-Convert-to-DT-schema/20261027-134631
patch link:    https://lore.kernel.org/r/20261115090520.102216-3-clamor95%40gmail.com
patch subject: [PATCH v6 2/3] leds: Add driver for MAX8907 LED cell
:::::: branch date: 7 days ago
:::::: commit date: 7 days ago
config: sparc64-allmodconfig (https://download.01.org/0day-ci/archive/20261122/202611222214.32wErpfA-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261122/202611222214.32wErpfA-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/202611222214.32wErpfA-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/leds/leds-max8907.c:68:10: error: call to undeclared function 'devm_kzalloc_obj'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      68 |         ddata = devm_kzalloc_obj(dev, struct max8907_led_data);
         |                 ^
   drivers/leds/leds-max8907.c:68:10: note: did you mean 'devm_kzalloc'?
   include/linux/device/devres.h:48:21: note: 'devm_kzalloc' declared here
      48 | static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
         |                     ^
>> drivers/leds/leds-max8907.c:68:32: error: expected expression
      68 |         ddata = devm_kzalloc_obj(dev, struct max8907_led_data);
         |                                       ^
   2 errors generated.


vim +/devm_kzalloc_obj +68 drivers/leds/leds-max8907.c

7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  55  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  56  static int max8907_led_probe(struct platform_device *pdev)
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  57  {
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  58  	struct device *dev = &pdev->dev;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  59  	struct device_node *led_np __free(device_node) =
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  60  		of_get_available_child_by_name(dev_of_node(dev->parent), "led");
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  61  	struct max8907 *max8907 = dev_get_drvdata(dev->parent);
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  62  	struct led_init_data init_data = { };
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  63  	struct max8907_led_data *ddata;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  64  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  65  	if (!led_np)
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  66  		return -ENODEV;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  67  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15 @68  	ddata = devm_kzalloc_obj(dev, struct max8907_led_data);
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  69  	if (!ddata)
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  70  		return -ENOMEM;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  71  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  72  	ddata->regmap = max8907->regmap_gen;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  73  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  74  	init_data.fwnode = of_fwnode_handle(led_np);
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  75  	init_data.devicename = "max8907";
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  76  	init_data.default_label = ":wled";
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  77  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  78  	ddata->cdev.brightness = LED_OFF;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  79  	ddata->cdev.flags = LED_CORE_SUSPENDRESUME;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  80  	ddata->cdev.max_brightness = LED_FULL;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  81  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  82  	ddata->cdev.brightness_get = max8907_led_get_brightness;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  83  	ddata->cdev.brightness_set_blocking = max8907_led_set_brightness;
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  84  
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  85  	return devm_led_classdev_register_ext(dev, &ddata->cdev, &init_data);
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  86  }
7b85b7d8f42900 Svyatoslav Ryhel 2026-11-15  87  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2026-11-22 15:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 15:08 [PATCH v6 2/3] leds: Add driver for MAX8907 LED cell kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2026-11-22 11:18 kernel test robot
2026-11-15  9:05 [PATCH v6 0/3] " Svyatoslav Ryhel
2026-11-15  9:05 ` [PATCH v6 2/3] " Svyatoslav Ryhel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.