From: Lee Jones <lee@kernel.org>
To: Svyatoslav Ryhel <clamor95@gmail.com>
Cc: "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Pavel Machek" <pavel@kernel.org>,
"Arnd Bergmann" <arnd@arndb.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Sebastian Reichel" <sre@kernel.org>,
"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"Ion Agorria" <ion@agorria.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-input@vger.kernel.org, linux-leds@vger.kernel.org,
linux-pm@vger.kernel.org
Subject: Re: [PATCH v2 7/9] leds: Add driver for Asus Transformer LEDs
Date: Fri, 6 Mar 2026 10:04:06 +0000 [thread overview]
Message-ID: <20260306100406.GE183676@google.com> (raw)
In-Reply-To: <20260209104407.116426-8-clamor95@gmail.com>
On Mon, 09 Feb 2026, Svyatoslav Ryhel wrote:
> From: Michał Mirosław <mirq-linux@rere.qmqm.pl>
>
> Asus Transformer tablets have a green and an amber LED on both the Pad
> and the Dock. If both LEDs are enabled simultaneously, the emitted light
> will be yellow.
>
> Co-developed-by: Svyatoslav Ryhel <clamor95@gmail.com>
> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
> drivers/leds/Kconfig | 11 ++++
> drivers/leds/Makefile | 1 +
> drivers/leds/leds-asus-ec.c | 104 ++++++++++++++++++++++++++++++++++++
> 3 files changed, 116 insertions(+)
> create mode 100644 drivers/leds/leds-asus-ec.c
>
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index 597d7a79c988..96dab210f6ca 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -120,6 +120,17 @@ config LEDS_OSRAM_AMS_AS3668
> To compile this driver as a module, choose M here: the module
> will be called leds-as3668.
>
> +config LEDS_ASUSEC
> + tristate "LED Support for Asus Transformer charging LED"
> + depends on LEDS_CLASS
> + depends on MFD_ASUSEC
> + help
> + This option enables support for charging indicator on
> + Asus Transformer's Pad and it's Dock.
> +
> + To compile this driver as a module, choose M here: the module
> + will be called leds-asus-ec.
> +
> config LEDS_AW200XX
> tristate "LED support for Awinic AW20036/AW20054/AW20072/AW20108"
> depends on LEDS_CLASS
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 8fdb45d5b439..1117304dfdf4 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -16,6 +16,7 @@ obj-$(CONFIG_LEDS_AN30259A) += leds-an30259a.o
> obj-$(CONFIG_LEDS_APU) += leds-apu.o
> obj-$(CONFIG_LEDS_ARIEL) += leds-ariel.o
> obj-$(CONFIG_LEDS_AS3668) += leds-as3668.o
> +obj-$(CONFIG_LEDS_ASUSEC) += leds-asus-ec.o
> obj-$(CONFIG_LEDS_AW200XX) += leds-aw200xx.o
> obj-$(CONFIG_LEDS_AW2013) += leds-aw2013.o
> obj-$(CONFIG_LEDS_BCM6328) += leds-bcm6328.o
> diff --git a/drivers/leds/leds-asus-ec.c b/drivers/leds/leds-asus-ec.c
> new file mode 100644
> index 000000000000..5dd76c9247ee
> --- /dev/null
> +++ b/drivers/leds/leds-asus-ec.c
> @@ -0,0 +1,104 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * ASUS EC driver - battery LED
> + */
> +
> +#include <linux/err.h>
> +#include <linux/leds.h>
> +#include <linux/mfd/asus-ec.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +
> +/*
> + * F[5] & 0x07
> + * auto: brightness == 0
> + * bit 0: blink / charger on
> + * bit 1: amber on
> + * bit 2: green on
> + */
> +
> +#define ASUSEC_CTL_LED_BLINK BIT_ULL(40)
> +#define ASUSEC_CTL_LED_AMBER BIT_ULL(41)
> +#define ASUSEC_CTL_LED_GREEN BIT_ULL(42)
> +
> +static void asus_ec_led_set_brightness_amber(struct led_classdev *led,
> + enum led_brightness brightness)
> +{
> + const struct asusec_info *ec = dev_get_drvdata(led->dev->parent);
> +
> + if (brightness)
> + asus_ec_set_ctl_bits(ec, ASUSEC_CTL_LED_AMBER);
> + else
> + asus_ec_clear_ctl_bits(ec, ASUSEC_CTL_LED_AMBER);
> +}
> +
> +static void asus_ec_led_set_brightness_green(struct led_classdev *led,
> + enum led_brightness brightness)
> +{
> + const struct asusec_info *ec = dev_get_drvdata(led->dev->parent);
> +
> + if (brightness)
> + asus_ec_set_ctl_bits(ec, ASUSEC_CTL_LED_GREEN);
> + else
> + asus_ec_clear_ctl_bits(ec, ASUSEC_CTL_LED_GREEN);
> +}
> +
> +static int asus_ec_led_probe(struct platform_device *pdev)
> +{
> + struct asusec_info *ec = cell_to_ec(pdev);
Please remove all of your abstraction layers. They serve little purpose
other than to complicate things. Just use dev_get_drvdata() here.
Remove the "_info" part and change "ec" to "ddata".
> + struct device *dev = &pdev->dev;
> + struct led_classdev *amber_led, *green_led;
> + int ret;
> +
> + platform_set_drvdata(pdev, ec);
Wait, what?
Why are you doing that?
> + amber_led = devm_kzalloc(dev, sizeof(*amber_led), GFP_KERNEL);
> + if (!amber_led)
> + return -ENOMEM;
> +
> + amber_led->name = devm_kasprintf(dev, GFP_KERNEL, "%s::amber", ec->name);
> + amber_led->max_brightness = 1;
> + amber_led->flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN;
> + amber_led->brightness_set = asus_ec_led_set_brightness_amber;
> +
> + ret = devm_led_classdev_register(dev, amber_led);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to register amber LED\n");
> +
> + green_led = devm_kzalloc(dev, sizeof(*green_led), GFP_KERNEL);
> + if (!green_led)
> + return -ENOMEM;
> +
> + green_led->name = devm_kasprintf(dev, GFP_KERNEL, "%s::green", ec->name);
> + green_led->max_brightness = 1;
> + green_led->flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN;
> + green_led->brightness_set = asus_ec_led_set_brightness_green;
> +
> + ret = devm_led_classdev_register(dev, green_led);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to register green LED\n");
Lots of repetition here.
I'd make a sub-function that takes the differences.
Same with the set brightness functions.
Think to yourself - what if I had to support 16 different LEDs?
> +
> + return 0;
> +}
> +
> +static const struct of_device_id asus_ec_led_match[] = {
> + { .compatible = "asus,ec-led" },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, asus_ec_led_match);
> +
> +static struct platform_driver asus_ec_led_driver = {
> + .driver = {
> + .name = "asus-ec-led",
> + .of_match_table = asus_ec_led_match,
> + },
> + .probe = asus_ec_led_probe,
> +};
> +module_platform_driver(asus_ec_led_driver);
> +
> +MODULE_AUTHOR("Michał Mirosław <mirq-linux@rere.qmqm.pl>");
> +MODULE_AUTHOR("Svyatoslav Ryhel <clamor95@gmail.com>");
> +MODULE_DESCRIPTION("ASUS Transformer's charging LED driver");
> +MODULE_LICENSE("GPL");
> --
> 2.51.0
>
>
--
Lee Jones [李琼斯]
next prev parent reply other threads:[~2026-03-06 10:04 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-09 10:43 [PATCH v2 0/9] mfd: Add support for Asus Transformer embedded controller Svyatoslav Ryhel
2026-02-09 10:43 ` [PATCH v2 1/9] dt-bindings: misc: document ASUS Transformers EC DockRAM Svyatoslav Ryhel
2026-02-10 9:25 ` Krzysztof Kozlowski
2026-02-10 9:42 ` Svyatoslav Ryhel
2026-02-10 10:50 ` Krzysztof Kozlowski
2026-02-10 11:08 ` Svyatoslav Ryhel
2026-02-09 10:44 ` [PATCH v2 2/9] misc: Support Asus Transformer's EC access device Svyatoslav Ryhel
2026-02-09 10:44 ` [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC Svyatoslav Ryhel
2026-02-10 9:22 ` Krzysztof Kozlowski
2026-02-10 9:37 ` Svyatoslav Ryhel
2026-02-10 10:48 ` Krzysztof Kozlowski
2026-02-10 10:59 ` Svyatoslav Ryhel
2026-02-10 11:04 ` Krzysztof Kozlowski
2026-02-10 11:14 ` Svyatoslav Ryhel
2026-02-10 11:24 ` Krzysztof Kozlowski
2026-02-10 11:40 ` Svyatoslav Ryhel
2026-02-10 11:54 ` Krzysztof Kozlowski
2026-02-10 12:48 ` Krzysztof Kozlowski
2026-02-11 10:48 ` Svyatoslav Ryhel
2026-02-09 10:44 ` [PATCH v2 4/9] mfd: Add driver for Asus Transformer embedded controller Svyatoslav Ryhel
2026-03-06 9:18 ` Lee Jones
2026-03-06 12:36 ` Svyatoslav Ryhel
2026-02-09 10:44 ` [PATCH v2 5/9] input: serio: Add driver for Asus Transformer dock keyboard and touchpad Svyatoslav Ryhel
2026-02-09 10:44 ` [PATCH v2 6/9] input: keyboard: Add driver for Asus Transformer dock multimedia keys Svyatoslav Ryhel
2026-02-09 10:44 ` [PATCH v2 7/9] leds: Add driver for Asus Transformer LEDs Svyatoslav Ryhel
2026-03-06 10:04 ` Lee Jones [this message]
2026-03-06 12:45 ` Svyatoslav Ryhel
2026-03-09 19:04 ` Lee Jones
2026-02-09 10:44 ` [PATCH v2 8/9] power: supply: Add driver for Asus Transformer battery Svyatoslav Ryhel
2026-02-09 10:44 ` [PATCH v2 9/9] power: supply: Add charger driver for Asus Transformers Svyatoslav Ryhel
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=20260306100406.GE183676@google.com \
--to=lee@kernel.org \
--cc=arnd@arndb.de \
--cc=clamor95@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=ion@agorria.com \
--cc=krzk+dt@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=mirq-linux@rere.qmqm.pl \
--cc=pavel@kernel.org \
--cc=robh@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