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=1796044549; b=dV2Erqyj/Z3EY8/wRy3vYLrAYtBM8zytjzyYAsl9sLJmUJAhphziuioSaTxdWB9gSrMz C7dtSV3+QktP4AoOlhcfu2j6NsVzitqxjP8TQc3sGPQ4PdKEpLNtelXpw+lCb8CjLLCgf lcb19YME92yldk8SjTtozxlSyjguUgw4dh64ZJ1mNdJNtdmImHPZUubWdOO1VgnYcj76G qR+mgyTxq3XRsc81jHZm048GheXVxUQxKKvLtES165La7VlIeNZYH6AafXciCRJ18K0C2 ADSQkzTs8gQn5q4O007Orj8s0nS/8PiVy/cDRJ/ez3VsXG+i5aIxCPoedzkTg3GiZjQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796044549; 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=FFThK9kzp3MEBVvQNjJ3FlPJOaDz7g8FBcdtZrcFmquTw1nJ5NyC9TDDZfsSsbc6qOXL MOacBkdAw614W0TKrnVpR/iil5vIp7WjmJ3seYCud7sdtvsxMb35vOybwGjmbTJlYgcts yvoHdMjpBONWsaV2ay3ahA0tzIrufdhpSNXeilBc0QvbNhhCaSrZ3gIbYd0ZWSlHpdPKR pe09zqkDsQvIGgtBK1YiiEAsfU1o68qG+SYZb1ajIUv7HEx/s4idbCH8Qc1A9O0omG9kJ apsAUG2bDCmNLZO+/b3jAdN4Ln5oSvzbPRrP3t4W+mLaO5zDSmgSn8u/JPkOoAgm37Q== 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=GcSQ0Dh8; 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 78E57606A325 for ; Mon, 30 Nov 2026 13:15:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 78E57606A325 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=GcSQ0Dh8 Received: by mail-dy2-f8.google.com with SMTP id 5a478bee46e88-36a6ce64b95so3783412eec.1 for ; Mon, 30 Nov 2026 05:15:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796044548; x=1796649348; 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=GcSQ0Dh8YRyUCxdggD6w5bq/ERDoGjGiUTA43f3ElQjFELBer7ptuOlmU+laCkbkR/ Lz+6fTn7pql06WlN/G4xJPmKDofU0Izh7Chbqi4VkuGmsuZCiN5cVSqlGXy6/S8aF1Vq kCKbGRhAGK46Ut7etetfR4pYE9BKHOqeooZyvWOX674RnetdbgzGbBIwlagoD5BTp5fv 70TDQhySvN54EZfjtxY3uQjs60teCel3MTh3jCrY3Q0tjzJ7cnVOROzQs5AkFA2gTgHs kxn7ACoAdSoGRkqox7/hvogS5RzOjqvXl9ySzDm3fi5906RYYPnQyQnqcWrHhdB99Rke gilg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796044548; x=1796649348; 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=cCkbaw2RxJaG7x3IvLNVGxRW+TMYhojZKVx1i/yG4g68SsAX9ZhpseoKCyZGVIesvH Hder+XkN+hLoDikyn3XravvTPLvF4d7IM07MG7KJogUj6Ymf93uALvRlBxJFSeIIwDAD LBOxScEjo4NdUop7aj+9xe7IUDUW4n8juVssGJk80cm9R6CDsjXbfCCLtXvwHFnH3xjF 0bvZkDr3Z00rYdjcJmq7CmGKOHDmLwB4l9mkS1p8Ojent/mfWlRWwIKp+KRXo+DLVKQn Xrqw3dUpEVaHfWBb90SmnFsF0Z1adKb4+Ux9emBV+OwD9WN7h/2O1hbY4i8UV3euN+bI dVjg== X-Forwarded-Encrypted: i=1; AL+hErGGN5rDtvIixOFBtIaBVIAwNBCxm2Vd6UpnAK5yBV8MhyIkrSaHSmPI12kC2LpV4nVhLSDZsczvH/9rqaE=@vger.kernel.org X-Gm-Message-State: APuU4Z80WKEbwfPQYOmIkqi/1dRPFl6uYbUyzleP3fpiDXJPESP+4kwX /uic6TdEA+KiiZJMBVtS1ozIePXj8WT3CuEVoNUbDDouwMlAH0he9RuY X-Gm-Gg: AZFdTZdVZgVcH53x9+0obEktkt4+FcqQv8ib0h5QKpH5E7mDxAbAopAdpTb+jqsyKEm VCdGL160ekydtMlNIhtmKC7f9E+CBlPZwvKoRd9beRYWXFLef03yFx6yxTzmW91bpriMDT89l6N 0W8Ly0Yhdf5omqcSiiKQeRBmIIFZQIG6Xb/PyWEBmBH50wOYYaSMfO1nDDwEpTbsghd0XQGn2WV 404OgRYPEsqX8lUDXq/NRQh6BrES1zVqP4PeqIG7BuR231+IO8YJ8gnJQc6vAFG2EzV8fHSxDCi zX2Uf6z/3veTUKBETBWf2P8udYSdh4npUpuCNko39Fwo9r0LuEHwh/xsoA9it53advTo8L7SCCA WHTSS2tt5Pbq/PEwLnWuRAg5vOr8IBxhQu4+L+MQ2QivZbfTqN3HUZqB1XL6c0hDwj5noEUqzJO e9kpPGDjF5WGhBRQ31P6HzJOJTuXXp+Kp3RerRtygsa6wtBvC5OryFrQiil/OMlrAQaXJFOGrbO FL6vDVsaIp3bgK9rldhubvwwwovF8n6GdJA4DcZCL7S/OdJc53phd6PJM+jAgo54k7BZsf3YS7P rt4sVkMls5rrQsUCUzR9OnfOIMVR X-Received: by 2002:a05:7301:5f84:b0:385:f410:fe74 with SMTP id 5a478bee46e88-385f4110110mr44467464eec.26.1796044548496; Mon, 30 Nov 2026 05:15:48 -0800 (PST) Received: from ThinkPad ([192.220.23.71]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386992b404bsm84150401eec.1.2026.11.30.05.15.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 05:15:48 -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 v5 2/6] platform/x86: thinkpad_acpi: Extract kbdlight notify helpers Date: Mon, 30 Nov 2026 21:12:48 +0800 Message-ID: <20261130131252.80436-3-kmatzkaczor244@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261130131252.80436-1-kmatzkaczor244@gmail.com> References: <20261130131252.80436-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