mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Rodnei Cilto <rodnei.cilto@gmail.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	 Ike Panhc <ikepanhc@gmail.com>,
	Mark Pearson <mpearson-lenovo@squebb.ca>,
	 "Derek J. Clark" <derekjohn.clark@gmail.com>,
	 Hans de Goede <hansg@kernel.org>,
	linux-input@vger.kernel.org,  LKML <linux-kernel@vger.kernel.org>,
	platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH 2/2] platform/x86: ideapad-laptop: add CapsLock/NumLock LED via EC
Date: Mon, 9 Nov 2026 18:49:37 +0200 (EET)	[thread overview]
Message-ID: <82a8e236-d219-3ce5-f6fa-c5ff23d910c3@linux.intel.com> (raw)
In-Reply-To: <20260628-ideapad-kbd-leds-v1-2-50b421d94927@gmail.com>

On Sun, 28 Jun 2026, Rodnei Cilto wrote:

> Some Lenovo IdeaPad laptops (e.g. 83RR/83SR, Wildcat Lake) have
> physical CapsLock and NumLock LEDs controlled via the EC.
> 
> The EC exposes CAPL (bit 5) and NUML (bit 4) at offset 0xA1.
> Writing these bits via ec_write() and evaluating _QDF via
> acpi_evaluate_object() causes the firmware to sync EC state to the
> GPIO lines that drive the physical LEDs.
> 
> Discovery via DSDT analysis on Lenovo IdeaPad 83RR (Wildcat Lake):
>   - CAPL/NUML at EC offset 0xA1 (bits 5 and 4)
>   - _QDF (_SB.PC00.LPCB.EC0._QDF) reads CAPL/NUML -> SGOV()
>   - GPIO 0x001A1087 -> CapsLock LED physical pin
>   - GPIO 0x001A0485 -> NumLock LED physical pin
>   - ec_read/ec_write exported via EXPORT_SYMBOL in drivers/acpi/ec.c
>     and declared in <linux/acpi.h>
> 
> Add two led_classdev entries (input::capslock, input::numlock)
> guarded by DMI match (features.kbd_leds) for 83RR and its Brazil
> regional variant 83SR.
> 
> Signed-off-by: Rodnei Cilto <rodnei.cilto@gmail.com>
> ---
>  drivers/platform/x86/lenovo/ideapad-laptop.c | 143 +++++++++++++++++++++++++++
>  1 file changed, 143 insertions(+)
> 
> diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
> index 4fbc904f1fc3..03e3f234067c 100644
> --- a/drivers/platform/x86/lenovo/ideapad-laptop.c
> +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
> @@ -42,6 +42,17 @@
>  
>  #include <dt-bindings/leds/common.h>
>  
> +/* EC keyboard LED control (IdeaPad EC PS/2 emulation).
> + * Validated on Lenovo IdeaPad 83RR (Wildcat Lake):
> + *   EC offset 0xA1 bit4=NUML, bit5=CAPL
> + *   _QDF syncs EC state to GPIO -> physical LED
> + * ec_read/ec_write declared in <linux/acpi.h>
> + */
> +#define IDEAPAD_EC_KBD_LED_OFFSET	0xA1
> +#define IDEAPAD_EC_KBD_LED_NUML_BIT	BIT(4)
> +#define IDEAPAD_EC_KBD_LED_CAPL_BIT	BIT(5)
> +#define IDEAPAD_ACPI_EC0_QDF_PATH	"\\_SB.PC00.LPCB.EC0._QDF"
> +
>  #define IDEAPAD_RFKILL_DEV_NUM	3
>  
>  enum {
> @@ -198,6 +209,7 @@ struct ideapad_private {
>  		bool ctrl_ps2_aux_port    : 1;
>  		bool usb_charging         : 1;
>  		bool ymc_ec_trigger       : 1;
> +		bool kbd_leds             : 1;
>  	} features;
>  	struct {
>  		bool initialized;
> @@ -210,6 +222,11 @@ struct ideapad_private {
>  		struct led_classdev led;
>  		unsigned int last_brightness;
>  	} fn_lock;
> +	struct {
> +		bool initialized;
> +		struct led_classdev capslock;
> +		struct led_classdev numlock;
> +	} kbd_leds;
>  };
>  
>  static bool no_bt_rfkill;
> @@ -1587,6 +1604,99 @@ static void ideapad_backlight_notify_brightness(struct ideapad_private *priv)
>  /*
>   * keyboard backlight
>   */
> +static int ideapad_kbd_led_ec_set(u8 bit, bool on)
> +{
> +	u8 val;
> +	int err;
> +
> +	err = ec_read(IDEAPAD_EC_KBD_LED_OFFSET, &val);
> +	if (err)
> +		return err;
> +	if (on)
> +		val |= bit;
> +	else
> +		val &= ~bit;
> +	err = ec_write(IDEAPAD_EC_KBD_LED_OFFSET, val);
> +	if (err)
> +		return err;

Hi,

Don't you need to protect this RMW sequence with a lock?

> +	acpi_evaluate_object(NULL, IDEAPAD_ACPI_EC0_QDF_PATH, NULL, NULL);
> +	return 0;
> +}
> +
> +static void ideapad_capslock_led_set(struct led_classdev *led_cdev,
> +				     enum led_brightness brightness)
> +{
> +	ideapad_kbd_led_ec_set(IDEAPAD_EC_KBD_LED_CAPL_BIT, brightness != LED_OFF);
> +}
> +
> +static enum led_brightness ideapad_capslock_led_get(struct led_classdev *led_cdev)
> +{
> +	u8 val;
> +
> +	if (ec_read(IDEAPAD_EC_KBD_LED_OFFSET, &val))
> +		return LED_OFF;
> +	return (val & IDEAPAD_EC_KBD_LED_CAPL_BIT) ? LED_ON : LED_OFF;
> +}
> +
> +static void ideapad_numlock_led_set(struct led_classdev *led_cdev,
> +				    enum led_brightness brightness)
> +{
> +	ideapad_kbd_led_ec_set(IDEAPAD_EC_KBD_LED_NUML_BIT, brightness != LED_OFF);
> +}
> +
> +static enum led_brightness ideapad_numlock_led_get(struct led_classdev *led_cdev)
> +{
> +	u8 val;
> +
> +	if (ec_read(IDEAPAD_EC_KBD_LED_OFFSET, &val))
> +		return LED_OFF;
> +	return (val & IDEAPAD_EC_KBD_LED_NUML_BIT) ? LED_ON : LED_OFF;
> +}
> +
> +static int ideapad_kbd_leds_init(struct ideapad_private *priv)
> +{
> +	int err;
> +
> +	if (WARN_ON(priv->kbd_leds.initialized))
> +		return -EEXIST;
> +
> +	priv->kbd_leds.capslock.name           = "input::capslock";

Documentation/leds/ example seems to have input<number>::capslock ?

You should also cc leds people when sending v2.

> +	priv->kbd_leds.capslock.max_brightness = 1;
> +	priv->kbd_leds.capslock.brightness_set = ideapad_capslock_led_set;
> +	priv->kbd_leds.capslock.brightness_get = ideapad_capslock_led_get;
> +	priv->kbd_leds.capslock.flags          = LED_RETAIN_AT_SHUTDOWN;
> +
> +	err = led_classdev_register(&priv->platform_device->dev,
> +				    &priv->kbd_leds.capslock);
> +	if (err)
> +		return err;
> +
> +	priv->kbd_leds.numlock.name            = "input::numlock";
> +	priv->kbd_leds.numlock.max_brightness  = 1;
> +	priv->kbd_leds.numlock.brightness_set  = ideapad_numlock_led_set;
> +	priv->kbd_leds.numlock.brightness_get  = ideapad_numlock_led_get;
> +	priv->kbd_leds.numlock.flags           = LED_RETAIN_AT_SHUTDOWN;
> +
> +	err = led_classdev_register(&priv->platform_device->dev,
> +				    &priv->kbd_leds.numlock);
> +	if (err) {
> +		led_classdev_unregister(&priv->kbd_leds.capslock);
> +		return err;
> +	}
> +
> +	priv->kbd_leds.initialized = true;
> +	return 0;
> +}
> +
> +static void ideapad_kbd_leds_exit(struct ideapad_private *priv)
> +{
> +	if (!priv->kbd_leds.initialized)
> +		return;
> +	priv->kbd_leds.initialized = false;
> +	led_classdev_unregister(&priv->kbd_leds.numlock);
> +	led_classdev_unregister(&priv->kbd_leds.capslock);
> +}
> +
>  static int ideapad_kbd_bl_check_tristate(int type)
>  {
>  	return (type == KBD_BL_TRISTATE) || (type == KBD_BL_TRISTATE_AUTO);
> @@ -1832,6 +1942,29 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
>  	priv->r_touchpad_val = value;
>  }
>  
> +static const struct dmi_system_id ideapad_kbd_leds_dmi_table[] = {
> +	{
> +		/*
> +		 * Lenovo IdeaPad 83RR (Wildcat Lake) - EC PS/2 emulation
> +		 * controls CapsLock/NumLock LEDs via EC offset 0xA1 + _QDF.
> +		 * CAPL=bit5 (0x20), NUML=bit4 (0x10).
> +		 * _QDF drives GPIO via SGOV() to physical LED pins.
> +		 */

Put this comment before the table and generalize it such that it doesn't 
start with the model but only given that as an example.

> +		.matches = {
> +			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
> +			DMI_MATCH(DMI_PRODUCT_NAME, "83RR"),
> +		},
> +	},
> +	{
> +		/* Lenovo IdeaPad 83SR (83RR Brazil regional variant) */
> +		.matches = {
> +			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
> +			DMI_MATCH(DMI_PRODUCT_NAME, "83SR"),
> +		},
> +	},
> +	{ }
> +};
> +
>  static const struct dmi_system_id ymc_ec_trigger_quirk_dmi_table[] = {
>  	{
>  		/* Lenovo Yoga 7 14ARB7 */
> @@ -2178,6 +2311,8 @@ static int ideapad_check_features(struct ideapad_private *priv)
>  	priv->features.touchpad_ctrl_via_ec = touchpad_ctrl_via_ec;
>  	priv->features.ymc_ec_trigger =
>  		ymc_ec_trigger || dmi_check_system(ymc_ec_trigger_quirk_dmi_table);
> +	priv->features.kbd_leds =
> +		dmi_check_system(ideapad_kbd_leds_dmi_table);

Fits to one line.

>  
>  	if (!read_ec_data(handle, VPCCMD_R_FAN, &val))
>  		priv->features.fan_mode = true;
> @@ -2418,6 +2553,12 @@ static int ideapad_acpi_add(struct platform_device *pdev)
>  			dev_info(&pdev->dev, "FnLock control not available\n");
>  	}
>  
> +	if (priv->features.kbd_leds) {
> +		err = ideapad_kbd_leds_init(priv);
> +		if (err)
> +			dev_warn(&pdev->dev, "Could not set up kbd LEDs: %d\n", err);
> +	}
> +
>  	/*
>  	 * On some models without a hw-switch (the yoga 2 13 at least)
>  	 * VPCCMD_W_RF must be explicitly set to 1 for the wifi to work.
> @@ -2477,6 +2618,7 @@ static int ideapad_acpi_add(struct platform_device *pdev)
>  		ideapad_unregister_rfkill(priv, i);
>  
>  	ideapad_fn_lock_led_exit(priv);
> +	ideapad_kbd_leds_exit(priv);
>  	ideapad_kbd_bl_exit(priv);
>  	ideapad_input_exit(priv);
>  
> @@ -2506,6 +2648,7 @@ static void ideapad_acpi_remove(struct platform_device *pdev)
>  		ideapad_unregister_rfkill(priv, i);
>  
>  	ideapad_fn_lock_led_exit(priv);
> +	ideapad_kbd_leds_exit(priv);
>  	ideapad_kbd_bl_exit(priv);
>  	ideapad_input_exit(priv);
>  	ideapad_debugfs_exit(priv);
> 
> 

-- 
 i.


      reply	other threads:[~2026-11-09 16:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29  1:57 [PATCH 0/2] Add keyboard LED support for Lenovo IdeaPad 83RR/83SR Rodnei Cilto
2026-06-29  1:57 ` [PATCH 1/2] input: atkbd: add softleds quirk for broken EC PS/2 emulation Rodnei Cilto
2026-06-28  5:20   ` Dmitry Torokhov
2026-06-29  1:57 ` [PATCH 2/2] platform/x86: ideapad-laptop: add CapsLock/NumLock LED via EC Rodnei Cilto
2026-11-09 16:49   ` Ilpo Järvinen [this message]

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=82a8e236-d219-3ce5-f6fa-c5ff23d910c3@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=derekjohn.clark@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hansg@kernel.org \
    --cc=ikepanhc@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpearson-lenovo@squebb.ca \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rodnei.cilto@gmail.com \
    /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®