leds: max5970: Add support for max5970
PATCH v4 1/1 leds: max5970: Add support for max5970
From: Patrick Rudolph <[email protected]>
The MAX5970 is hot swap controller and has 4 indication LED.
---
Changes in V4:
- Compact declaration of variable to single line
- Use sizeof(*ddata) instead of sizeof(struct max5970_led).
- Use the shorter 'dev' version whilst it's available Changes in V3:
- Drop array for ddata variable.
Changes in V2:
- Add of_node_put before return.
- Code cleanup
- Refactor code & remove max5970_setup_led function.
--- drivers/leds/Kconfig | 11 ++++ drivers/leds/Makefile | 1 + drivers/leds/leds-max5970.c | 109 ++++++++++++++++++++++++++++++++++++ 3 files changed, 121 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 +109 -0
109 lines not on this page · raw message
base-commit: baca986e1f2c31f8e4b2a6d99d47c3bc844033e8
Signature · 1 line
2.41.0
Lee Jones
maintainerQuoted 107 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]>Reviewed-by Lee Jones <[email protected]>---
Changes in V4:
- Compact declaration of variable to single line
- Usesizeof(*ddata)instead ofsizeof(struct max5970_led).
- Use the shorter 'dev' version whilst it's available Changes in V3:
- Drop array for ddata variable.
Changes in V2:
- Addof_node_putbefore return.
- Code cleanup
- Refactor code & removemax5970_setup_ledfunction.--- drivers/leds/Kconfig | 11 ++++ drivers/leds/Makefile | 1 + drivers/leds/leds-max5970.c | 109 ++++++++++++++++++++++++++++++++++++ 3 files changed, 121 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 +42
-0@@ -0,0 +1,109 @@ +// 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; + +/* 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_led_probe (struct platform_device *pdev) +{
drivers/leds/leds-max5970.c line 52
Quoted 10 lines
drivers/leds/leds-max5970.c new file +10
-0+struct device *dev = &pdev->dev; +struct device_node *np =dev_of_node (dev->parent); +struct regmap *regmap; +struct device_node *led_node, *child; +struct max5970_led *ddata; +int ret = -ENODEV , num_leds =0 ; + + regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!regmap) +return -EPROBE_DEFER ;
You're too quick off the mark.
Let's finish the discussion about this first.
Signature · 1 line
Lee Jones [李琼斯]