Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2062225lqz; Tue, 2 Apr 2024 06:21:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3gkLBN3gWSvvjbBgHO7ZE2bjtCp/uKeoCAcbjKdgnUp4qptMP/KBi++9uVUgiKyypVvzQmkIQnuLf8n80IHoPznNnT8nTjKznzhJ1hA== X-Google-Smtp-Source: AGHT+IEP0FSnxdgDCiG+dEg3+xXk/GIBkIVtsCB45JMP79uXNiLRmciYySd9OB9Jy88GcZXy5KxM X-Received: by 2002:a05:6402:5253:b0:56d:eed0:4dc6 with SMTP id t19-20020a056402525300b0056deed04dc6mr1136987edd.23.1712064119022; Tue, 02 Apr 2024 06:21:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712064119; cv=pass; d=google.com; s=arc-20160816; b=wf5WmIl8XfnEiowVFKr6iOZtiKFM3MHFZ9wgZbsXUbl7rWZuj9cbSfT023qj2E6TZe taoAyQgqFIExxDTZ0kR0j1Ot6a/1cB35RbcuiJDkMGCrl5CQal0FFAs8YEkUTYgy+N8I ULg4wPfH8rc198RgcY+qXK1paFcKpsFw3rU4CIQcdOSbg3Baehgk0cNBOJjsbHGVc9dd W8Miux3ikrzYflqYh5FHZY5oRs2BpowSOpYG28zBUvVTtPPhkUyPkCHutO3gEnHmjD/U aSkAZ8TnNdnPsmohMPKC4xwYO7T+LT+AckulAowisVnSyPyI+DBUXAedqgxAEN8ykNu/ 0MBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=nMi5MWdWdsrgYsZFU1DfXDunA9NbnOFV3R0OEjbIxjc=; fh=4Y9LYk1mNJRKxiyde1JZtHOPLk3eMIW0j1YXurIIPt0=; b=BmAiCZEk9G+JzeBO+yeSeYpHgEH2RswF0PuXJJmAiN8Kx1t27g6vz6WxyYZ97WQ9ul 5RLCZhZFqHPdDcoelyFRpx29evce2sXxIZBCIxgmboZOuR8xsJavEkvt3ajTJKOOSTS8 iSnn0I05xUOyXtRwzhFKpVGaYedAWipsK3gXyf8ZFXjXJwrV4xdlVrc+jMQldACU1rn4 sAr5goRNn+WQ+Fftc6LsFvxZ5uJYViOuF6KxbbdT7p8f/Hg51PYQzvElUrwqgnzqB/d5 Au3nEU9l+ZJiKJazr4bMWckmwdZowHgsqD9bVRGk8X7VixUM9zO8UYJacOghVZ8RSufR bPCw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=irl.hu dmarc=pass fromdomain=irl.hu); spf=pass (google.com: domain of linux-kernel+bounces-128032-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128032-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=irl.hu Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e26-20020a50d4da000000b0056c0d158f7fsi5626833edj.81.2024.04.02.06.21.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 06:21:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128032-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=irl.hu dmarc=pass fromdomain=irl.hu); spf=pass (google.com: domain of linux-kernel+bounces-128032-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128032-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=irl.hu Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8B9EC1F21171 for ; Tue, 2 Apr 2024 13:21:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2FB48564C; Tue, 2 Apr 2024 13:21:24 +0000 (UTC) Received: from irl.hu (irl.hu [95.85.9.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DF4480631; Tue, 2 Apr 2024 13:21:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.85.9.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712064084; cv=none; b=G1izORQr+QoV/D6/tGMy63JQn52w8c3xxDVwqeLw1/9Rl06ALjFrQ/O/rbpMmwn8rLqTgrt0xVF9PQf5Ld0Wl6a/yIBrUtmZ9vGhgBY1KIbajnFOhskglxKTvQFuPP0BsY6SfAeUU9vWD6c3fJp/D8bRB8o4JitosSiQH0+t7wQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712064084; c=relaxed/simple; bh=soN8FkpcgRBwdzzFH5CZlu5Cs9CmIZZdqx8WdcS451g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Mime-Version:Content-Type; b=iT0tCtPNDNEe+L5ptvgaCt0tq1EV9pPVJZsEH0aRlfx5+Iy1Xb7sYtCP0nP+eASLMwFNbvWeXf1W+O6ynbTgXZsgvgzhOJGc39t7oqXyW//BbgjvcJ2dhAG9BScEcsR3oOm/mRPkB3DZHGX/XyfV2Wj5zkgMWxpEDdmDuqk2W9M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=irl.hu; spf=pass smtp.mailfrom=irl.hu; arc=none smtp.client-ip=95.85.9.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=irl.hu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=irl.hu Received: from fedori.lan (51b69867.dsl.pool.telekom.hu [::ffff:81.182.152.103]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 00000000000644A9.00000000660C064A.002529D9; Tue, 02 Apr 2024 15:21:14 +0200 From: Gergo Koteles To: Ike Panhc , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, devicetree@vger.kernel.org, Gergo Koteles Subject: [PATCH 3/3] platform/x86: ideapad-laptop: add FnLock LED class device Date: Tue, 2 Apr 2024 15:21:02 +0200 Message-ID: <2db08c948568a8d5352780864956c3271b4e42ce.1712063200.git.soyer@irl.hu> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 Some Ideapad/Yoga Laptops have an FnLock LED in the Esc key. Expose Fnlock as an LED class device for easier OSD support. Signed-off-by: Gergo Koteles --- drivers/platform/x86/ideapad-laptop.c | 97 ++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index 529df08af548..8a5bef4eedfe 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -152,6 +152,11 @@ struct ideapad_private { struct led_classdev led; unsigned int last_brightness; } kbd_bl; + struct { + bool initialized; + struct led_classdev led; + unsigned int last_brightness; + } fn_lock; }; static bool no_bt_rfkill; @@ -531,6 +536,19 @@ static int ideapad_fn_lock_set(struct ideapad_private *priv, bool state) state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF); } +static void ideapad_fn_lock_led_notify(struct ideapad_private *priv, int brightness) +{ + if (!priv->fn_lock.initialized) + return; + + if (brightness == priv->fn_lock.last_brightness) + return; + + priv->fn_lock.last_brightness = brightness; + + led_classdev_notify_brightness_hw_changed(&priv->fn_lock.led, brightness); +} + static ssize_t fn_lock_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -561,6 +579,8 @@ static ssize_t fn_lock_store(struct device *dev, if (err) return err; + ideapad_fn_lock_led_notify(priv, state); + return count; } @@ -1479,6 +1499,65 @@ static void ideapad_kbd_bl_exit(struct ideapad_private *priv) led_classdev_unregister(&priv->kbd_bl.led); } +/* + * FnLock LED + */ +static enum led_brightness ideapad_fn_lock_led_cdev_get(struct led_classdev *led_cdev) +{ + struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, fn_lock.led); + + return ideapad_fn_lock_get(priv); +} + +static int ideapad_fn_lock_led_cdev_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, fn_lock.led); + + return ideapad_fn_lock_set(priv, brightness); +} + +static int ideapad_fn_lock_led_init(struct ideapad_private *priv) +{ + int brightness, err; + + if (!priv->features.fn_lock) + return -ENODEV; + + if (WARN_ON(priv->fn_lock.initialized)) + return -EEXIST; + + priv->fn_lock.led.max_brightness = 1; + + brightness = ideapad_fn_lock_get(priv); + if (brightness < 0) + return brightness; + + priv->fn_lock.last_brightness = brightness; + priv->fn_lock.led.name = "platform::" LED_FUNCTION_FNLOCK; + priv->fn_lock.led.brightness_get = ideapad_fn_lock_led_cdev_get; + priv->fn_lock.led.brightness_set_blocking = ideapad_fn_lock_led_cdev_set; + priv->fn_lock.led.flags = LED_BRIGHT_HW_CHANGED; + + err = led_classdev_register(&priv->platform_device->dev, &priv->fn_lock.led); + if (err) + return err; + + priv->fn_lock.initialized = true; + + return 0; +} + +static void ideapad_fn_lock_led_exit(struct ideapad_private *priv) +{ + if (!priv->fn_lock.initialized) + return; + + priv->fn_lock.initialized = false; + + led_classdev_unregister(&priv->fn_lock.led); +} + /* * module init/exit */ @@ -1741,8 +1820,10 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data) if (priv->features.set_fn_lock_led) { int brightness = ideapad_fn_lock_get(priv); - if (brightness >= 0) + if (brightness >= 0) { ideapad_fn_lock_set(priv, brightness); + ideapad_fn_lock_led_notify(priv, brightness); + } } if (data->type != ACPI_TYPE_INTEGER) { @@ -1754,6 +1835,10 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data) dev_dbg(&wdev->dev, "WMI fn-key event: 0x%llx\n", data->integer.value); + /* 0x02 FnLock, 0x03 Esc */ + if (data->integer.value == 0x02 || data->integer.value == 0x03) + ideapad_fn_lock_led_notify(priv, data->integer.value == 0x02); + ideapad_input_report(priv, data->integer.value | IDEAPAD_WMI_KEY); @@ -1847,6 +1932,14 @@ static int ideapad_acpi_add(struct platform_device *pdev) dev_info(&pdev->dev, "Keyboard backlight control not available\n"); } + err = ideapad_fn_lock_led_init(priv); + if (err) { + if (err != -ENODEV) + dev_warn(&pdev->dev, "Could not set up FnLock LED: %d\n", err); + else + dev_info(&pdev->dev, "FnLock control not available\n"); + } + /* * 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. @@ -1903,6 +1996,7 @@ static int ideapad_acpi_add(struct platform_device *pdev) for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(priv, i); + ideapad_fn_lock_led_exit(priv); ideapad_kbd_bl_exit(priv); ideapad_input_exit(priv); @@ -1930,6 +2024,7 @@ static void ideapad_acpi_remove(struct platform_device *pdev) for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(priv, i); + ideapad_fn_lock_led_exit(priv); ideapad_kbd_bl_exit(priv); ideapad_input_exit(priv); ideapad_debugfs_exit(priv); -- 2.44.0