From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.8 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796299859; b=SmYpJ/2nyufTK38VrZuJpgNFyd49OPT3UiTXtw2y62XeAVjurYTr1Nfxysg7t483UZLb GMzmTyCeVYHYX67JdqCCkfwgdCEu8CdGF+Cm+rcuV3/47L3jKnWGqsYLVe8FCvNByRA1a hk32zXhKBVwrbrzvB6I2D5UAdhhs3kuGy0ZS9TZus1NQ1hBux6ZC9yLHvtbL0ybqrMkDC pZ4K43ZDJAVzs3C/Sigz6StJ2TGcjfgl/QYTV7vGuvDS1l7FNzwq9PMK3lrtksXQaA1Jf YFYus3EBjPPci/F67hnzJBZ6JqYcwNf1N6ZoaHdc+DCqx9C0fJx/KLEXwve/2lCTHmw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796299859; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=WjZwV3tRBuKKJYpDfpBM/jjxmBDFzflFQE+E+NZ8pkY=; b=XL0Yq47rYfs9DnGl15ZDv85P9zMXd0DIwAy76B1sgOAfTlSvudddgUUz118jZX5E0vaJ 53QyyB4Aup9BmabFzcThQWo4lZ3VIJxCuY2L6AxPa93jC+nLW/kVvqKk2Bh+FU1fcooCb AaQ+g62E9sYkJhgvrOlzM89YepY5YHFbYYC38S9HxmSRnpbMPvxsBwa28hFUOu9qWU2yj rt+XhGq+VoBBsWQrZadfCGUKsIqonVf/YgFIwjVOFimjNPTdVSqDFO8+zj+BQ/ILftTbo iBoCOcpKcJEzzWGENWordJbohuCd6pL2DNXMgmnb++KR/NWo6o4BnAbEh5wxtW0v6aA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UwINBkYk; arc=none smtp.remote-ip=74.125.229.8 Received: from mail-dy2-f8.google.com (mail-dy2-f8.google.com [74.125.229.8]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E312606BCEF for ; Thu, 3 Dec 2026 12:10:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0E312606BCEF Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UwINBkYk Received: by mail-dy2-f8.google.com with SMTP id 5a478bee46e88-3831d564bcfso4762685eec.1 for ; Thu, 03 Dec 2026 04:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796299858; x=1796904658; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WjZwV3tRBuKKJYpDfpBM/jjxmBDFzflFQE+E+NZ8pkY=; b=UwINBkYkOEuGL3THIXuK7KHWhs6r5aJycEExVL1TWmSkPgfqof/Xfvmh2lx8iwWCUS 4X/Y56/RbpXCdilU8ayHs8vSL8k01i62l2762sjBnz730jt82J/4CBHPd/i/724Z5HFl wpFP4YmIX1DwTWBCOHj+4B4NDndi4zqS7zXYSWgwvN6j0jNxoAaGdhjHElu+9baiGAGl xah61GLwppllMbMCPhToxx19SaZ/yNRrpUu3vRJ8tiJ1ovLZk9adWQD084ibd6rSDeQ6 Y4jOylT0mxrMZ++fqMZvIhwSj6n6Sjd+HgxKLqE3cqLH/1Lkbjjn11yXOzW/9n2cDz1h rN8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796299858; x=1796904658; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=WjZwV3tRBuKKJYpDfpBM/jjxmBDFzflFQE+E+NZ8pkY=; b=MceP/tZi/Mh42Ww6NThiljNGH85nc2YfIqbbc3TvxR0ojIqMTHHkDvWZyPNV/C9sLW 4fXPJbGFI7x+qpdX/HzIj4n6EnWqLXhaPvbLm7ihyevzIx6Ldj8PpRz38rxo2loNFXrz fPegVq4zOx2Un/SS+JyQK4sArqUmrMxhQJ+dayFc0OoZbR57QSiWcldpIgXebD1o27NF xzyg76/Q4ylRLOuuBj713XsUI14h00JfTEgR6f/v3z77UTVdcxl3kkRDai4y55XnZT9S xvvGpX3+pMOCkNI14lCkCa2PoUyjpEn/N78dpOMwC1uOBDSbLLj3z7kf79F/eFDbXMoU hZlQ== X-Forwarded-Encrypted: i=1; AL+hErHSTf4yYuSVWgJJwmn6Ux4bvIggxA3diO2JBhFEcEBvWxb+phFB1wCzjExpWhnaKtod7fmlZ6wBz60bAMc=@vger.kernel.org X-Gm-Message-State: APuU4Z90hPOtOfwnUsLspoH24wJP+qwLXluw6rgAAUroSn7xh5T7E1bY JaT91shgL3r1FYB6YrJwmDYRIgyD0KgQOit1sSnW6CvySG1dW6zkL8pK X-Gm-Gg: AZFdTZdSUXNvvFmSkx/UXOOrCOM1WNdeBTjkUSgupYg9DaRfEZ3R6FfUAszWESc4Stl tT0VTIQSu5bsWVKLu/9Tr1srIKFWFL+iIBrIJPejGOMp1hFqGxg6529zPV17xkkMgS4pP6Y6+Vd Y15VW2sKBKCRArCnSo1Ed5QWawEupME2BrXBIuHu9cL3Oyt5jquzhi+lheF4YWHJ7v1D0Wqfnvc pdDzKtaInyBAenriaPeqgJ8aalk2OeUkhiamasVbKUuvpnf5BsIbJ01CMGi+SnslFyb/I4jRyjJ QNsquyruxOiqb6kyF5DMVegoY2neaLWWd9Q5wE0xgxUb5UMk42xjymHSMGug97XJV/dEXg/VOQF fdQwNvxlaNGU7D33+IvL+xP0nc1RQl8bUcLbo2ILtOg28Ewjxf3gQ7kmIRGJaQ6BigdiYldMSE6 mZQ6GwE6v+jluqRmkPYXw/jpstAJQYPtw4lHAgKRdcCKPvvwjd50gky2Bc3B+5Fs5f7tgb8HS7P JVPqWQvW/TRKXPQmaGwSBPtsT4smOjL2AsIsZ4ij9uihl6RhXlU5IMgEfoPJK2v4kXumL2mZCSn uXySpYRW+gQoUO3+toatphpNHK5X X-Received: by 2002:a05:7022:130d:b0:136:c443:80e5 with SMTP id a92af1059eb24-1b5568a15b7mr37331762c88.6.1796299858124; Thu, 03 Dec 2026 04:10:58 -0800 (PST) Received: from ThinkPad ([192.220.23.71]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b556840494sm101600588c88.12.2026.12.03.04.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 04:10:57 -0800 (PST) From: Qiling Zhu To: Mark Pearson , "Derek J. Clark" , Rong Zhang , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Henrique de Moraes Holschuh Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, ibm-acpi-devel@lists.sourceforge.net, Lee Jones , Pavel Machek , Griffin Kroah-Hartman , linux-leds@vger.kernel.org, vishnuocv@gmail.com, vsankar@lenovo.com, Andrea Rabbaglietti Subject: [PATCH v6 2/6] platform/x86: thinkpad_acpi: Extract kbdlight notify helpers Date: Thu, 3 Dec 2026 20:07:00 +0800 Message-ID: <20261203120704.41431-3-kmatzkaczor244@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203120704.41431-1-kmatzkaczor244@gmail.com> References: <20261203120704.41431-1-kmatzkaczor244@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit TP_HKEY_EV_KBD_LIGHT handling in tpacpi_driver_event() reads back the brightness, compares it with the cached value and notifies the LED core inline. Extract this block into two helpers: kbdlight_notify_level() takes an EC level, compares it with the cached value, updates the cache and notifies the LED core, translating the level to a brightness on the way, as kbdlight_sysfs_get() does; kbdlight_notify_change() reads the level back and calls the former under kbdlight_mutex. kbdlight_notify_level() expects the caller to hold kbdlight_mutex, so that the proc write path can reuse it with the level it has just written in a subsequent change. The helpers work in EC levels rather than brightness values, as the rest of the series builds on that. This differs from the original code in two situations: a change from off to the auto mode or back, which reads back as the same brightness, now produces a notification reporting 0 when the cached value holds the EC level, where the original code sent none; and a failed read of the level now sends no notification and leaves the cached value alone, where the original code went on with a brightness of 0. kbdlight_brightness is still an enum led_brightness at this point, and kbdlight_init() still fills it in from the reported brightness; a later change in this series makes it an int that tracks the EC level from init on. Signed-off-by: Qiling Zhu Reviewed-by: Rong Zhang Reviewed-by: Mark Pearson --- drivers/platform/x86/lenovo/thinkpad_acpi.c | 48 ++++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c index 31d3721bb..3ef857542 100644 --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c @@ -5267,6 +5267,36 @@ static int kbdlight_set_level_and_update(int level) return ret; } +static void kbdlight_notify_level(int level) +{ + struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev; + + lockdep_assert_held(&kbdlight_mutex); + + /* + * Check the level actually changed, setting the level + * through kbdlight_set_level() also triggers this event. + */ + if (level == kbdlight_brightness) + return; + + kbdlight_brightness = level; + led_classdev_notify_brightness_hw_changed(led_cdev, kbdlight_level_to_brightness(level)); +} + +static void kbdlight_notify_change(void) +{ + int level; + + guard(mutex)(&kbdlight_mutex); + + level = kbdlight_get_level(); + if (level < 0) + return; + + kbdlight_notify_level(level); +} + static int kbdlight_read(struct seq_file *m) { int level; @@ -11593,22 +11623,8 @@ static bool tpacpi_driver_event(const unsigned int hkey_event) /* Key events are suppressed by default hotkey_user_mask */ return false; case TP_HKEY_EV_KBD_LIGHT: - if (tp_features.kbdlight) { - enum led_brightness brightness; - - guard(mutex)(&kbdlight_mutex); - - /* - * Check the brightness actually changed, setting the brightness - * through kbdlight_set_level() also triggers this event. - */ - brightness = kbdlight_sysfs_get(NULL); - if (kbdlight_brightness != brightness) { - kbdlight_brightness = brightness; - led_classdev_notify_brightness_hw_changed( - &tpacpi_led_kbdlight.led_classdev, brightness); - } - } + if (tp_features.kbdlight) + kbdlight_notify_change(); /* Key events are suppressed by default hotkey_user_mask */ return false; case TP_HKEY_EV_DFR_CHANGE_ROW: -- 2.56.1