From: Dan Murphy <dmurphy@ti.com>
To: Ondrej Jirman <megous@megous.com>, <linux-sunxi@googlegroups.com>,
Jacek Anaszewski <jacek.anaszewski@gmail.com>,
Pavel Machek <pavel@ucw.cz>, Rob Herring <robh+dt@kernel.org>,
Chen-Yu Tsai <wens@csie.org>, Maxime Ripard <mripard@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
Lee Jones <lee.jones@linaro.org>, <linux-leds@vger.kernel.org>,
<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 2/4] leds: axp20x: Support charger LED on AXP20x like PMICs
Date: Tue, 25 Feb 2020 06:53:58 -0600 [thread overview]
Message-ID: <7f8a74e1-28ad-1b27-b491-9bd70f0c4e61@ti.com> (raw)
In-Reply-To: <20200223131435.681620-3-megous@megous.com>
Ondrej
On 2/23/20 7:14 AM, Ondrej Jirman wrote:
> There is single LED that can be turned on and off by the user, or set to
> be controlled by the charger in 2 different modes.
>
> The driver initializes the LED to be controlled by the charger, but
> allows to switch it to user control, and change the mode of charging
> indication via a sysfs.
>
> The driver was developed on AXP813, but should work on other PMICs like
> that without changes.
>
> Signed-off-by: Ondrej Jirman <megous@megous.com>
> ---
> drivers/leds/Kconfig | 7 ++
> drivers/leds/Makefile | 1 +
> drivers/leds/leds-axp20x.c | 240 +++++++++++++++++++++++++++++++++++++
> drivers/mfd/axp20x.c | 3 +
> 4 files changed, 251 insertions(+)
> create mode 100644 drivers/leds/leds-axp20x.c
>
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index d82f1dea37111..80a3f31f6f4c3 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -846,6 +846,13 @@ config LEDS_TPS6105X
> It is a single boost converter primarily for white LEDs and
> audio amplifiers.
>
> +config LEDS_AXP20X
> + tristate "Charger LED support for AXP20X-like PMICs (AXP813, ...)"
> + depends on LEDS_CLASS && MFD_AXP20X
> + help
> + This option enables support for on-chip LED driver on
> + AXP20X-like PMICs.
> +
> comment "LED Triggers"
> source "drivers/leds/trigger/Kconfig"
>
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index d7e1107753fb1..80ea1bc4744b0 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -86,6 +86,7 @@ obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o
> obj-$(CONFIG_LEDS_LM3697) += leds-lm3697.o
> obj-$(CONFIG_LEDS_LM36274) += leds-lm36274.o
> obj-$(CONFIG_LEDS_TPS6105X) += leds-tps6105x.o
> +obj-$(CONFIG_LEDS_AXP20X) += leds-axp20x.o
>
> # LED SPI Drivers
> obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.o
> diff --git a/drivers/leds/leds-axp20x.c b/drivers/leds/leds-axp20x.c
> new file mode 100644
> index 0000000000000..e6c9853b84d52
> --- /dev/null
> +++ b/drivers/leds/leds-axp20x.c
> @@ -0,0 +1,240 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * LED Driver for X-Powers AXP813 PMIC and similar.
> + *
> + * Copyright(c) 2020 Ondrej Jirman <megous@megous.com>
> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/platform_device.h>
> +#include <linux/leds.h>
> +#include <linux/slab.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/mfd/axp20x.h>
> +
> +#define AXP20X_CHGLED_CTRL_MASK BIT(3)
> +#define AXP20X_CHGLED_CTRL_CHARGER BIT(3)
> +#define AXP20X_CHGLED_CTRL_USER 0
> +
> +#define AXP20X_CHRG_CTRL2_MODE BIT(4)
> +
> +#define AXP20X_CHGLED_USER_STATE_MASK GENMASK(5, 4)
> +#define AXP20X_CHGLED_USER_STATE_OFF (0 << 4)
> +#define AXP20X_CHGLED_USER_STATE_BLINK_SLOW (1 << 4)
> +#define AXP20X_CHGLED_USER_STATE_BLINK_FAST (2 << 4)
> +#define AXP20X_CHGLED_USER_STATE_ON (3 << 4)
> +
> +struct axp20x_led {
> + struct led_classdev cdev;
> + struct regmap *regmap;
> +};
> +
> +static int axp20x_led_set(struct led_classdev *led_cdev,
> + enum led_brightness value)
> +{
> + struct axp20x_led *led =
> + container_of(led_cdev, struct axp20x_led, cdev);
> + unsigned int val;
> +
> + val = value == LED_OFF ? AXP20X_CHGLED_USER_STATE_OFF :
> + AXP20X_CHGLED_USER_STATE_ON;
> +
> + return regmap_update_bits(led->regmap, AXP20X_OFF_CTRL,
> + AXP20X_CHGLED_USER_STATE_MASK, val);
> +
> +}
> +
> +static ssize_t charger_control_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct led_classdev *led_cdev = dev_get_drvdata(dev);
> + struct axp20x_led *led =
> + container_of(led_cdev, struct axp20x_led, cdev);
> + unsigned int val;
> + int ret;
> +
> + ret = regmap_read(led->regmap, AXP20X_OFF_CTRL, &val);
> + if (ret)
> + return ret;
> +
> + return scnprintf(buf, PAGE_SIZE, "%u\n",
> + val & AXP20X_CHGLED_CTRL_MASK ? 1 : 0);
> +}
> +
> +static ssize_t charger_control_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct led_classdev *led_cdev = dev_get_drvdata(dev);
> + struct axp20x_led *led =
> + container_of(led_cdev, struct axp20x_led, cdev);
> + bool status;
> + int ret;
> +
> + ret = kstrtobool(buf, &status);
> + if (ret)
> + return ret;
> +
> + ret = regmap_update_bits(led->regmap, AXP20X_OFF_CTRL,
> + AXP20X_CHGLED_CTRL_MASK,
> + status ? AXP20X_CHGLED_CTRL_CHARGER :
> + AXP20X_CHGLED_CTRL_USER);
> + if (ret)
> + return ret;
> +
> + return len;
> +}
> +
> +static ssize_t charger_mode_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct led_classdev *led_cdev = dev_get_drvdata(dev);
> + struct axp20x_led *led =
> + container_of(led_cdev, struct axp20x_led, cdev);
> + unsigned int val;
> + int ret;
> +
> + ret = regmap_read(led->regmap, AXP20X_CHRG_CTRL2, &val);
> + if (ret)
> + return ret;
> +
> + return scnprintf(buf, PAGE_SIZE, "%u\n",
> + val & AXP20X_CHRG_CTRL2_MODE ? 1 : 0);
> +}
> +
> +static ssize_t charger_mode_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct led_classdev *led_cdev = dev_get_drvdata(dev);
> + struct axp20x_led *led =
> + container_of(led_cdev, struct axp20x_led, cdev);
> + unsigned int mode;
> + int ret;
> +
> + ret = kstrtouint(buf, 0, &mode);
> + if (ret)
> + return ret;
> +
> + if (mode > 1)
> + return -ERANGE;
> +
> + ret = regmap_update_bits(led->regmap, AXP20X_CHRG_CTRL2,
> + AXP20X_CHRG_CTRL2_MODE,
> + mode ? AXP20X_CHRG_CTRL2_MODE : 0);
> + if (ret)
> + return ret;
> +
> + return len;
> +}
> +
> +static DEVICE_ATTR_RW(charger_control);
> +static DEVICE_ATTR_RW(charger_mode);
> +
> +static struct attribute *axp20x_led_attrs[] = {
> + &dev_attr_charger_control.attr,
> + &dev_attr_charger_mode.attr,
> + NULL,
> +};
> +
> +ATTRIBUTE_GROUPS(axp20x_led);
> +
> +static int axp20x_led_probe(struct platform_device *pdev)
> +{
> + struct axp20x_dev *axp20x;
> + struct axp20x_led *led;
> + int ret;
> +
> + if (!of_device_is_available(pdev->dev.of_node))
> + return -ENODEV;
> +
> + axp20x = dev_get_drvdata(pdev->dev.parent);
> + if (!axp20x)
> + return -EINVAL;
> +
> + led = devm_kzalloc(&pdev->dev,
> + sizeof(struct axp20x_led),
> + GFP_KERNEL);
> + if (!led)
> + return -ENOMEM;
> +
> + platform_set_drvdata(pdev, led);
> +
> + led->regmap = axp20x->regmap;
> +
> + led->cdev.name = "axp20x-chgarger-led";
This does not follow the LED device naming convention please refer to
the leds-class.rst document
https://elixir.bootlin.com/linux/latest/source/Documentation/leds/leds-class.rst
Dan
next prev parent reply other threads:[~2020-02-25 12:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-23 13:14 [PATCH 0/4] Add support for charger LED for AXP813 and TBS A711 Tablet Ondrej Jirman
2020-02-23 13:14 ` [PATCH 1/4] dt-bindings: leds: Add a binding for AXP813 charger led Ondrej Jirman
2020-02-25 12:55 ` Dan Murphy
2020-02-26 22:30 ` Rob Herring
2020-02-23 13:14 ` [PATCH 2/4] leds: axp20x: Support charger LED on AXP20x like PMICs Ondrej Jirman
2020-02-25 12:53 ` Dan Murphy [this message]
2020-02-26 14:08 ` Pavel Machek
2020-02-23 13:14 ` [PATCH 3/4] ARM: dts: axp813: Add charger LED Ondrej Jirman
2020-02-25 12:56 ` Dan Murphy
2020-02-23 13:14 ` [PATCH 4/4] ARM: dts: sun8i-a83t-tbs-a711: Enable charging LED Ondrej Jirman
2020-02-23 13:27 ` [PATCH 0/4] Add support for charger LED for AXP813 and TBS A711 Tablet Ondřej Jirman
2020-02-23 13:35 ` Ondřej Jirman
2020-02-24 6:31 ` [linux-sunxi] " Stefan Mavrodiev
2020-02-24 16:28 ` Ondřej Jirman
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=7f8a74e1-28ad-1b27-b491-9bd70f0c4e61@ti.com \
--to=dmurphy@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=jacek.anaszewski@gmail.com \
--cc=lee.jones@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-sunxi@googlegroups.com \
--cc=mark.rutland@arm.com \
--cc=megous@megous.com \
--cc=mripard@kernel.org \
--cc=pavel@ucw.cz \
--cc=robh+dt@kernel.org \
--cc=wens@csie.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®