leds: Add driver for MAX8907 LED cell
Subsystems (2)
PATCH v3 1/1 leds: Add driver for MAX8907 LED cell
Add a small driver to control the LED cell provided by the MAX8907 PMIC. The LED does not require any specific configuration and is folded into the PMIC's node.
---
Changes in v2:
- rebased so patch is now applicable to linux/next
Changes in v3:
- added check if led is off for get callback
- added dedicated MAX8907_REG_WLED_MODE_ON mask
- switched to devm_led_classdev_register_ext
--- drivers/leds/Kconfig | 7 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-max8907.c | 92 +++++++++++++++++++++++++++++++++++++ drivers/mfd/max8907.c | 1 + include/linux/mfd/max8907.h | 2 +- 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 drivers/leds/leds-max8907.c
drivers/leds/Kconfig +7 -0
@@ -813,6 +813,13 @@ 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. + config LEDS_MAX8997 tristate "LED support for MAX8997 PMIC" depends on LEDS_CLASS && MFD_MAX8997
drivers/leds/Makefile +1 -0
@@ -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
drivers/leds/leds-max8907.c new file +92 -0
92 lines not on this page · raw message
drivers/mfd/max8907.c +1 -0
@@ -20,6 +20,7 @@#include <linux/slab.h> static const struct mfd_cell max8907_cells[] = { + { .name ="max8907-leds" , }, { .name ="max8907-regulator" , }, { .name ="max8907-rtc" , }, };
include/linux/mfd/max8907.h +1 -1
@@ -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
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] leds: max8907: missing MODULE_ALIAS() prevents module autoloading - [Medium] leds: max8907…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] leds: max8907: missing MODULE_ALIAS() prevents module autoloading
- [Medium] leds: max8907: invalid fwnode and missing default_label in max8907_led_probe()
- [Low] leds: max8907: unused max8907 field and platform_set_drvdata() in probe --
commit 585d0f44a3d2f49e9a4916f8fc771037b7486e53
Author: Svyatoslav Ryhel <[email protected]>
leds: Add driver for MAX8907 LED cell
This commit adds a platform driver for the LED cell on the MAX8907 PMIC and registers the max8907-leds cell in the parent MFD driver.
Quoted 6 lines
drivers/leds/leds-max8907.c new file +0
-0@@ -0,0 +1,92 @@
[ ... ]
Quoted 5 lines
drivers/leds/leds-max8907.c new file +5
-0+struct max8907_led_data { +struct max8907 *max8907; +struct regmap *regmap; +struct led_classdev cdev; +};
[ ... ]
Quoted 5 lines
drivers/leds/leds-max8907.c new file +5
-0+static int max8907_led_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct max8907 *max8907 =dev_get_drvdata (dev->parent); +struct led_init_data init_data = { };
drivers/leds/leds-max8907.c line 69
Quoted 10 lines
drivers/leds/leds-max8907.c new file +10
-0+struct max8907_led_data *ddata; + + ddata =devm_kzalloc (dev,sizeof (*ddata),GFP_KERNEL ); +if (!ddata) +return -ENOMEM ; + + ddata->max8907 = max8907; + ddata->regmap = max8907->regmap_gen; + +platform_set_drvdata (pdev, ddata);
[Severity: Low]
Are ddata->max8907 and the platform_set_drvdata(pdev, ddata) call needed here?
Neither ddata->max8907 nor the platform device driver data appears to be read anywhere after max8907_led_probe(), since register accesses go through ddata->regmap and the LED callbacks retrieve ddata via container_of() on ddata->cdev.
drivers/leds/leds-max8907.c line 82
Quoted 13 lines
drivers/leds/leds-max8907.c new file +13
-0+ + init_data.fwnode =dev_fwnode (dev->parent); + init_data.devicename =dev_name (dev); + + 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); +}
[Severity: Medium]
What happens in max8907_led_probe() -> devm_led_classdev_register_ext() -> led_classdev_register_ext() -> led_compose_name() when init_data.fwnode is set to dev_fwnode(dev->parent) and init_data.default_label is left NULL?
In drivers/leds/led-core.c:led_compose_name(), when no LED properties are present on the fwnode:
} else if (init_data->default_label) {
if (!devicename) {
dev_err(dev, "Legacy LED naming requires devicename segment");
return -EINVAL;
}
n = snprintf(led_classdev_name, LED_MAX_NAME_SIZE, "%s:%s",
devicename, init_data->default_label);
} else if (is_of_node(fwnode)) {
n = snprintf(led_classdev_name, LED_MAX_NAME_SIZE, "%s",
to_of_node(fwnode)->name);
} else if (is_software_node(fwnode)) {
n = snprintf(led_classdev_name, LED_MAX_NAME_SIZE, "%s",
fwnode_get_name(fwnode));
} else {
return -EINVAL;
}On non-DT platforms using struct max8907_platform_data, dev_fwnode(dev->parent) is NULL, and because init_data.default_label is also NULL, led_compose_name() reaches the final else branch and fails with -EINVAL.
On Device Tree platforms where the parent maxim,max8907 PMIC node does not define LED properties (such as color, function, or label), led_compose_name() falls through to the is_of_node(fwnode) branch and names the LED after to_of_node(fwnode)->name (the parent MFD node name, such as pmic) while ignoring init_data.devicename and binding the LED class device directly to the parent MFD fwnode.
Should max8907_led_probe() set init_data.default_label (or ddata->cdev.name) instead of passing the parent MFD fwnode without a default_label?
drivers/leds/leds-max8907.c line 92
Quoted 10 lines
drivers/leds/leds-max8907.c new file +10
-0+ +static struct platform_driver max8907_led_driver = { + .driver.name ="max8907-leds" , + .probe = max8907_led_probe, +}; +module_platform_driver (max8907_led_driver); + +MODULE_AUTHOR ("Svyatolsav Ryhel <[email protected]>" ); +MODULE_DESCRIPTION ("MAX8907 LED driver" ); +MODULE_LICENSE ("GPL" );
[Severity: Medium]
When CONFIG_LEDS_MAX8907=m, will this module autoload when mfd_add_devices() registers the max8907-leds cell from max8907_cells[] in drivers/mfd/max8907.c?
Because max8907_cells[] instantiates the device by name without an of_compatible string, the platform bus emits MODALIAS=platform:max8907-leds. Without MODULE_ALIAS("platform:max8907-leds") or a platform_device_id table with MODULE_DEVICE_TABLE(platform, ...), leds-max8907.ko will have no modalias entry for udev/kmod to match.
Also, there is a typo in MODULE_AUTHOR ("Svyatolsav").
[ ... ]
Quoted 12 lines
drivers/mfd/max8907.c +1
-0@@ -19,6 +19,7 @@#include <linux/slab.h> static const struct mfd_cell max8907_cells[] = { + { .name ="max8907-leds" , }, { .name ="max8907-regulator" , }, { .name ="max8907-rtc" , }, };
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1