devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Pavel Machek <pavel@ucw.cz>, Lee Jones <lee.jones@linaro.org>,
	Sebastian Reichel <sre@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
	devicetree@vger.kernel.org, linux-input@vger.kernel.org,
	linux-leds@vger.kernel.org, linux-pm@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: Re: [PATCH v3 09/11] leds: max77650: add LEDs support
Date: Fri, 1 Feb 2019 20:45:57 +0100	[thread overview]
Message-ID: <78b99abb-f367-1533-0690-8da26957a664@gmail.com> (raw)
In-Reply-To: <20190201094736.32057-10-brgl@bgdev.pl>

Hi Bartosz,

Thanks for the update.

On 2/1/19 10:47 AM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> This adds basic support for LEDs for the max77650 PMIC. The device has
> three current sinks for driving LEDs.
> 
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>   drivers/leds/Kconfig         |   6 ++
>   drivers/leds/Makefile        |   1 +
>   drivers/leds/leds-max77650.c | 147 +++++++++++++++++++++++++++++++++++
>   3 files changed, 154 insertions(+)
>   create mode 100644 drivers/leds/leds-max77650.c
> 
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index a72f97fca57b..6e7a8f51eccc 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -608,6 +608,12 @@ config LEDS_TLC591XX
>   	  This option enables support for Texas Instruments TLC59108
>   	  and TLC59116 LED controllers.
>   
> +config LEDS_MAX77650
> +	tristate "LED support for Maxim MAX77650 PMIC"
> +	depends on MFD_MAX77650
> +	help
> +	  LEDs driver for MAX77650 family of PMICs from Maxim Integrated."
> +
>   config LEDS_MAX77693
>   	tristate "LED support for MAX77693 Flash"
>   	depends on LEDS_CLASS_FLASH
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 4c1b0054f379..f48b2404dbb7 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -61,6 +61,7 @@ obj-$(CONFIG_LEDS_MC13783)		+= leds-mc13783.o
>   obj-$(CONFIG_LEDS_NS2)			+= leds-ns2.o
>   obj-$(CONFIG_LEDS_NETXBIG)		+= leds-netxbig.o
>   obj-$(CONFIG_LEDS_ASIC3)		+= leds-asic3.o
> +obj-$(CONFIG_LEDS_MAX77650)		+= leds-max77650.o
>   obj-$(CONFIG_LEDS_MAX77693)		+= leds-max77693.o
>   obj-$(CONFIG_LEDS_MAX8997)		+= leds-max8997.o
>   obj-$(CONFIG_LEDS_LM355x)		+= leds-lm355x.o
> diff --git a/drivers/leds/leds-max77650.c b/drivers/leds/leds-max77650.c
> new file mode 100644
> index 000000000000..6b74ce9cac12
> --- /dev/null
> +++ b/drivers/leds/leds-max77650.c
> @@ -0,0 +1,147 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// Copyright (C) 2018 BayLibre SAS
> +// Author: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> +//
> +// LED driver for MAXIM 77650/77651 charger/power-supply.
> +
> +#include <linux/i2c.h>
> +#include <linux/leds.h>
> +#include <linux/mfd/max77650.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +
> +#define MAX77650_LED_NUM_LEDS		3
> +
> +#define MAX77650_LED_A_BASE		0x40
> +#define MAX77650_LED_B_BASE		0x43
> +
> +#define MAX77650_LED_BR_MASK		GENMASK(4, 0)
> +#define MAX77650_LED_EN_MASK		GENMASK(7, 6)
> +
> +#define MAX77650_LED_MAX_BRIGHTNESS	MAX77650_LED_BR_MASK
> +
> +/* Enable EN_LED_MSTR. */
> +#define MAX77650_LED_TOP_DEFAULT	BIT(0)
> +
> +#define MAX77650_LED_ENABLE		GENMASK(7, 6)
> +#define MAX77650_LED_DISABLE		0x00
> +
> +#define MAX77650_LED_A_DEFAULT		MAX77650_LED_DISABLE
> +/* 100% on duty */
> +#define MAX77650_LED_B_DEFAULT		GENMASK(3, 0)
> +
> +struct max77650_led {
> +	struct led_classdev cdev;
> +	struct regmap *map;
> +	unsigned int regA;
> +	unsigned int regB;
> +};
> +
> +static struct max77650_led *max77650_to_led(struct led_classdev *cdev)
> +{
> +	return container_of(cdev, struct max77650_led, cdev);
> +}
> +
> +static int max77650_led_brightness_set(struct led_classdev *cdev,
> +				       enum led_brightness brightness)
> +{
> +	struct max77650_led *led = max77650_to_led(cdev);
> +	int val, mask;
> +
> +	mask = MAX77650_LED_BR_MASK | MAX77650_LED_EN_MASK;
> +
> +	if (brightness == LED_OFF)
> +		val = MAX77650_LED_DISABLE;
> +	else
> +		val = MAX77650_LED_ENABLE | brightness;
> +
> +	return regmap_update_bits(led->map, led->regA, mask, val);
> +}
> +
> +static int max77650_led_probe(struct platform_device *pdev)
> +{
> +	struct device_node *of_node, *child;
> +	struct max77650_led *leds, *led;
> +	struct device *parent;
> +	struct device *dev;
> +	struct regmap *map;
> +	const char *label;
> +	int rv, num_leds;
> +	u32 reg;
> +
> +	dev = &pdev->dev;
> +	parent = dev->parent;
> +	of_node = dev->of_node;
> +
> +	if (!of_node)
> +		return -ENODEV;
> +
> +	leds = devm_kcalloc(dev, sizeof(*leds),
> +			    MAX77650_LED_NUM_LEDS, GFP_KERNEL);
> +	if (!leds)
> +		return -ENOMEM;
> +
> +	map = dev_get_regmap(dev->parent, NULL);
> +	if (!map)
> +		return -ENODEV;
> +
> +	num_leds = of_get_child_count(of_node);
> +	if (!num_leds || num_leds > MAX77650_LED_NUM_LEDS)
> +		return -ENODEV;
> +
> +	for_each_child_of_node(of_node, child) {
> +		rv = of_property_read_u32(child, "reg", &reg);
> +		if (rv || reg >= MAX77650_LED_NUM_LEDS)
> +			return -EINVAL;
> +
> +		led = &leds[reg];
> +		led->map = map;
> +		led->regA = MAX77650_LED_A_BASE + reg;
> +		led->regB = MAX77650_LED_B_BASE + reg;
> +		led->cdev.brightness_set_blocking = max77650_led_brightness_set;
> +		led->cdev.max_brightness = MAX77650_LED_MAX_BRIGHTNESS;
> +
> +		label = of_get_property(child, "label", NULL);
> +		if (!label) {
> +			led->cdev.name = "max77650::";
> +		} else {
> +			led->cdev.name = devm_kasprintf(dev, GFP_KERNEL,
> +							"max77650:%s", label);
> +			if (!led->cdev.name)
> +				return -ENOMEM;
> +		}
> +
> +		of_property_read_string(child, "linux,default-trigger",
> +					&led->cdev.default_trigger);
> +
> +		rv = devm_of_led_classdev_register(dev, child, &led->cdev);
> +		if (rv)
> +			return rv;
> +
> +		rv = regmap_write(map, led->regA, MAX77650_LED_A_DEFAULT);
> +		if (rv)
> +			return rv;
> +
> +		rv = regmap_write(map, led->regB, MAX77650_LED_B_DEFAULT);
> +		if (rv)
> +			return rv;
> +	}
> +
> +	return regmap_write(map,
> +			    MAX77650_REG_CNFG_LED_TOP,
> +			    MAX77650_LED_TOP_DEFAULT);
> +}
> +
> +static struct platform_driver max77650_led_driver = {
> +	.driver = {
> +		.name = "max77650-led",
> +	},
> +	.probe = max77650_led_probe,
> +};
> +module_platform_driver(max77650_led_driver);
> +
> +MODULE_DESCRIPTION("MAXIM 77650/77651 LED driver");
> +MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>");
> +MODULE_LICENSE("GPL v2");
> 

Acked-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>

-- 
Best regards,
Jacek Anaszewski

  reply	other threads:[~2019-02-01 19:45 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-01  9:47 [PATCH v3 00/11] mfd: add support for max77650 PMIC Bartosz Golaszewski
2019-02-01  9:47 ` [PATCH v3 01/11] dt-bindings: mfd: add DT bindings for max77650 Bartosz Golaszewski
2019-02-01  9:47 ` [PATCH v3 02/11] dt-bindings: power: supply: " Bartosz Golaszewski
2019-02-12 11:54   ` Pavel Machek
2019-02-12 13:28     ` Bartosz Golaszewski
2019-02-12 13:47       ` Pavel Machek
2019-02-01  9:47 ` [PATCH v3 03/11] dt-bindings: gpio: " Bartosz Golaszewski
2019-02-01  9:47 ` [PATCH v3 04/11] dt-bindings: leds: " Bartosz Golaszewski
2019-02-01  9:47 ` [PATCH v3 05/11] dt-bindings: input: " Bartosz Golaszewski
2019-02-01  9:47 ` [PATCH v3 06/11] mfd: max77650: new core mfd driver Bartosz Golaszewski
2019-02-12 12:01   ` Pavel Machek
2019-02-01  9:47 ` [PATCH v3 07/11] power: supply: max77650: add support for battery charger Bartosz Golaszewski
2019-02-12 12:07   ` Pavel Machek
2019-02-12 13:31     ` Bartosz Golaszewski
2019-02-12 13:54       ` Pavel Machek
2019-02-12 12:08   ` Pavel Machek
2019-02-01  9:47 ` [PATCH v3 08/11] gpio: max77650: add GPIO support Bartosz Golaszewski
2019-02-04 10:49   ` Bartosz Golaszewski
2019-02-01  9:47 ` [PATCH v3 09/11] leds: max77650: add LEDs support Bartosz Golaszewski
2019-02-01 19:45   ` Jacek Anaszewski [this message]
2019-02-01 20:14     ` Dan Murphy
2019-02-02 14:39       ` Bartosz Golaszewski
2019-02-12 12:10       ` Pavel Machek
2019-02-12 12:12   ` Pavel Machek
2019-02-13 10:58     ` Bartosz Golaszewski
2019-02-13 22:08   ` kbuild test robot
2019-02-01  9:47 ` [PATCH v3 10/11] input: max77650: add onkey support Bartosz Golaszewski
2019-02-12 12:17   ` Pavel Machek
2019-02-12 13:29     ` Bartosz Golaszewski
2019-02-12 13:47       ` Pavel Machek
2019-02-01  9:47 ` [PATCH v3 11/11] MAINTAINERS: add an entry for max77650 mfd driver Bartosz Golaszewski

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=78b99abb-f367-1533-0690-8da26957a664@gmail.com \
    --to=jacek.anaszewski@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=lee.jones@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pavel@ucw.cz \
    --cc=robh+dt@kernel.org \
    --cc=sre@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;
as well as URLs for NNTP newsgroup(s).