leds: max597x: Add support for max597x
PATCH v4 1/1 leds: max597x: Add support for max597x
From: Patrick Rudolph <[email protected]>
max597x is hot swap controller with indicator LED support. This driver uses DT property to configure led during boot time & also provide the LED control in sysfs.
DTS example:
i2c {
#address-cells = <1>;
#size-cells = <0>;
regulator@3a {
compatible = "maxim,max5978";
reg = <0x3a>;
vss1-supply = <&p3v3>;
regulators {
sw0_ref_0: sw0 {
shunt-resistor-micro-ohms = <12000>;
};
};
leds {
#address-cells = <1>;
#size-cells = <0>;
led@0 {
reg = <0>;
label = "led0";
default-state = "on";
};
led@1 {
reg = <1>;
label = "led1";
default-state = "on";
};
};
};
};...
Changes in V4:
- Remove unwanted preinitialise
- Remove unneeded line breaks
- Fix variable name to avoid confusion
- Update module description to mention LED driver. Changes in V3:
- Remove of_node_put as its handled by for loop
- Print error if an LED fails to register.
- Update driver name in Kconfig description
- Remove unneeded variable assignment
- Use devm_led_classdev_register to reget led Changes in V2:
- Fix regmap update
- Remove devm_kfree
- Remove default-state
- Add example dts in commit message
- Fix whitespace in Kconfig
- Fix comment
--- drivers/leds/Kconfig | 11 ++++ drivers/leds/Makefile | 1 + drivers/leds/leds-max597x.c | 112 ++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 drivers/leds/leds-max597x.c
drivers/leds/Kconfig +11 -0
@@ -590,6 +590,17 @@ config LEDS_ADP5520 To compile this driver as a module, choose M here: the module will be called leds-adp5520. +config LEDS_MAX597X + tristate "LED Support for Maxim 597x" + depends on LEDS_CLASS + depends on MFD_MAX597X + 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-max597x. + config LEDS_MC13783 tristate "LED Support for MC13XXX PMIC" depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
@@ -53,6 +53,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_MAX597X) += leds-max597x.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-max597x.c new file +112 -0
112 lines not on this page · raw message
base-commit: 11e572d06c23d61683e20a98bd16f550ef17ac65
prerequisite-patch-id: 456044abe991b2ff3b521d337825432789d71b29
Signature · 1 line
2.39.1
Hi!
Quoted 29 lines
From: Patrick Rudolph <[email protected]>
max597x is hot swap controller with indicator LED support. This driver uses DT property to configure led during boot time & also provide the LED control in sysfs.
DTS example:
i2c { #address-cells = <1>; #size-cells = <0>; regulator@3a { compatible = "maxim,max5978"; reg = <0x3a>; vss1-supply = <&p3v3>; regulators { sw0_ref_0: sw0 { shunt-resistor-micro-ohms = <12000>; }; }; leds { #address-cells = <1>; #size-cells = <0>; led@0 { reg = <0>; label = "led0"; default-state = "on"; };
Quoted 9 lines
led@1 {
reg = <1>;
label = "led1";
default-state = "on";
};
};
};
};Yeah, well, dts bindings need to be properly documented, and example goes to the binding, right?
Plus, we should have better names than led0/led1. Something like hdd0:green:something, based on what the LED does and what are you hot swapping. See/modify Documentation/leds/well-known-leds.txt .
drivers/leds/leds-max597x.c line 33
Quoted 10 lines
drivers/leds/leds-max597x.c new file +10
-0+static int max597x_led_set_brightness (struct led_classdev *cdev, +enum led_brightness brightness) +{ +struct max597x_led *ddata =ldev_to_maxled (cdev); +int ret, val; + +if (!ddata->regmap) +return -ENODEV ; + +/* Set/Clear corresponding bit for given led index */
"/clear".
drivers/leds/leds-max597x.c line 37
Quoted 4 lines
drivers/leds/leds-max597x.c new file +4
-0+ 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);
'\n"'.
drivers/leds/leds-max597x.c line 56
Quoted 2 lines
drivers/leds/leds-max597x.c new file +2
-0+ ddata->cdev.brightness_set_blocking = max597x_led_set_brightness; + ddata->cdev.default_trigger ="none" ;
So what do these leds normally do? Should they be registered with common function to handle default triggers etc?
drivers/leds/leds-max597x.c line 61
Quoted 5 lines
drivers/leds/leds-max597x.c new file +5
-0+ ddata->index = reg; + ddata->regmap = regmap; + ret =devm_led_classdev_register (dev, &ddata->cdev); +if (ret) +dev_err (dev,"Error initializing LED %s" , ddata->cdev.name);
'\n"'.
drivers/leds/leds-max597x.c line 111
Quoted 3 lines
drivers/leds/leds-max597x.c new file +3
-0+module_platform_driver (max597x_led_driver); +MODULE_AUTHOR ("Patrick Rudolph <[email protected]>" ); +MODULE_DESCRIPTION ("MAX5970_hot-swap controller LED driver" );
"MAX5970 hot-swap"?
Quoted 4 lines
+MODULE_LICENSE("GPL");
base-commit:
11e572d06c23d61683e20a98bd16f550ef17ac65
prerequisite-patch-id:456044abe991b2ff3b521d337825432789d71b29
?? Send prerequisites in the series?
BR,
Pavel
Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.
Hi Pavel,
Quoted 41 lines · Pavel Machek
Hi!
Quoted 29 lines
From: Patrick Rudolph <[email protected]>
max597x is hot swap controller with indicator LED support. This driver uses DT property to configure led during boot time & also provide the LED control in sysfs.
DTS example:
i2c { #address-cells = <1>; #size-cells = <0>; regulator@3a { compatible = "maxim,max5978"; reg = <0x3a>; vss1-supply = <&p3v3>; regulators { sw0_ref_0: sw0 { shunt-resistor-micro-ohms = <12000>; }; }; leds { #address-cells = <1>; #size-cells = <0>; led@0 { reg = <0>; label = "led0"; default-state = "on"; };Quoted 9 lines
led@1 { reg = <1>; label = "led1"; default-state = "on"; }; }; }; };
Quoted 2 lines
Yeah, well, dts bindings need to be properly documented, and example goes to the binding, right?
Yes.
Quoted 4 lines
Plus, we should have better names than led0/led1. Something like hdd0:green:something, based on what the LED does and what are you hot swapping. See/modify
Documentation/leds/well-known-leds.txt.
Yeah sure.
Quoted 14 lines
drivers/leds/leds-max597x.c line 33
Quoted 12 lines
drivers/leds/leds-max597x.c new file +10
-0+static int max597x_led_set_brightness (struct led_classdev *cdev, +enum led_brightness brightness) +{ +struct max597x_led *ddata =ldev_to_maxled (cdev); +int ret, val; + +if (!ddata->regmap) +return -ENODEV ; + +/* Set/Clear corresponding bit for given led index */ "/clear".
Ack.
Quoted 7 lines
drivers/leds/leds-max597x.c line 37
Quoted 5 lines
drivers/leds/leds-max597x.c new file +4
-0+ 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);'\n"'.
Ack
Quoted 6 lines
drivers/leds/leds-max597x.c line 56
Quoted 3 lines
drivers/leds/leds-max597x.c new file +2
-0+ ddata->cdev.brightness_set_blocking = max597x_led_set_brightness; + ddata->cdev.default_trigger ="none" ;So what do these leds normally do? Should they be registered with common function to handle default triggers etc?
Not sure if I understand your question right. In my use case in server motherboards, they are use to indicate presence of power for individual PCIe NVME connectors. Turning the LED on/off is handled by another application based on some conditions.
Quoted 8 lines
drivers/leds/leds-max597x.c line 61
Quoted 6 lines
drivers/leds/leds-max597x.c new file +5
-0+ ddata->index = reg; + ddata->regmap = regmap; + ret =devm_led_classdev_register (dev, &ddata->cdev); +if (ret) +dev_err (dev,"Error initializing LED %s" , ddata->cdev.name);'\n"'.
Ack
Quoted 6 lines
drivers/leds/leds-max597x.c line 111
Quoted 4 lines
drivers/leds/leds-max597x.c new file +3
-0+module_platform_driver (max597x_led_driver); +MODULE_AUTHOR ("Patrick Rudolph <[email protected]>" ); +MODULE_DESCRIPTION ("MAX5970_hot-swap controller LED driver" );"MAX5970 hot-swap"?
max5970 is primarily a hotswap controller & it also had indication led support.
Quoted 7 lines
Quoted 5 lines
+MODULE_LICENSE("GPL");
base-commit:
11e572d06c23d61683e20a98bd16f550ef17ac65
prerequisite-patch-id:456044abe991b2ff3b521d337825432789d71b29?? Send prerequisites in the series?
Will fix in v5.
Quoted 3 lines
BR,
Pavel
Regards,
Naresh