From: Svyatoslav Ryhel <clamor95@gmail.com>
To: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Lee Jones <lee@kernel.org>,
Pavel Machek <pavel@kernel.org>,
Griffin Kroah-Hartman <griffin@kroah.com>,
Svyatoslav Ryhel <clamor95@gmail.com>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-leds@vger.kernel.org, mfd@lists.linux.dev
Subject: [PATCH v5 2/3] leds: Add driver for MAX8907 LED cell
Date: Sun, 8 Nov 2026 17:13:47 +0200 [thread overview]
Message-ID: <20261108151348.204182-3-clamor95@gmail.com> (raw)
In-Reply-To: <20261108151348.204182-1-clamor95@gmail.com>
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..795b35390b039
--- /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(dev, sizeof(*ddata), GFP_KERNEL);
+ 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 e222250f0cc1e..35b2ede54f856 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
next prev parent reply other threads:[~2026-11-08 15:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 15:13 [PATCH v5 0/3] " Svyatoslav Ryhel
2026-11-08 15:13 ` [PATCH v5 1/3] regulator: dt-bindings: maxim,max8907: Document LED support Svyatoslav Ryhel
2026-11-08 15:13 ` Svyatoslav Ryhel [this message]
2026-11-08 15:13 ` [PATCH v5 3/3] mfd: max8907: Add LED cell Svyatoslav Ryhel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261108151348.204182-3-clamor95@gmail.com \
--to=clamor95@gmail.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=griffin@kroah.com \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--cc=pavel@kernel.org \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®