From patchwork Tue Dec 10 21:00:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 848969 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62BD41BD9E9 for ; Tue, 10 Dec 2024 21:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733864468; cv=none; b=t2xq2GCmMkTXEnxceSO7XUpofNF8wGgRL59Hh+JVqpMd68P5PIiIfExW+Z+WwqFLamua9d7Iw9Z6aZEGDzpt0SPtePKlvVtCBsW5LW/ybgyvVOJjAGVx0HnSG7ir8b95fPIpOt1yNXyS6VtImeGCPuggL8Q8ApiRgCrs+Zjssj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733864468; c=relaxed/simple; bh=kn2zLn6+c4GewCdeZl3qVtflE53ih10wTlFJk59NyNI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KeiIjpMkXFcNTCKi3Hfk0bMyCdqukuxrA3Edz41w8CnDLK3gh3bUO+tfD32l/VYE/FQ/Vs8bk9aVMIO5UnbggRDgsGGDytB43j87FHRyNobuNiOJkovVoetiIl7haTdufDaobiiamCMy/ED1koNv/gmuocXMWJoN0QOx69wg0ho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=f6ZQaCti; arc=none smtp.client-ip=209.85.214.181 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.b="f6ZQaCti" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-216426b0865so26097265ad.0 for ; Tue, 10 Dec 2024 13:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733864466; x=1734469266; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jRpN9f+Qwyf6/7hWUZysB3z1EtHm0ttDZm4S3DjEg7k=; b=f6ZQaCtiQ91pIpxbG7G1firiYgY3/9PJFfmcoLeiSEppywFOzacEY3ThemTDdhEQ34 0Smj6EaRWyOQ7Bgz1r6GBFaxwP03hkYgtwOc8wizkPBl6K8VWqjqhINzEeRutJotPYlS 0bXWybcomeEPD0r1+9anbn8RZFUBVP8XQN4iF1/SMCR5T+r/INSkLqc1QbRIlfd6PQDF vpBkNoVJkd0RqVQi2XyB0t6aY/iCJcuJ1qXK4+/VN6THqsUaas5/84reX3RUPsqowO9s 46RK425MW5ek37NOX7prCE6w68byjqh2NKtsXR5gE2GSWiggkbmiddnmJQK7ppPFmsar /xaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733864466; x=1734469266; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jRpN9f+Qwyf6/7hWUZysB3z1EtHm0ttDZm4S3DjEg7k=; b=HecM1FNTVoCe1+9DW2WUdl4yaxaAi84bSB0LSmAqqw6flC98Gm6yk43+8RMXZHwEvs 6Oj5KwXDt+c0wP6AXUm5Mm/UMya+klSR4TSeGrNvEn34b8maL0MXeY68HfhaMdwTS/3l ZFQRDhMnWJBUr59kTsmu5hU00af6Q3Y4yHhJD8E8K3HK0YSCHHbwKvbxhy3KdHIes/Fa tRM91gMBh26yxkzhZwfTVV/nbfygGHQXQMp74VlHcS1G2LnOzcWNI2xMONBjXdhOotFW GV3BNsoiy857j5yeI4RuSBwLS4wFZNnatW7t/+Ob8FcQByAWg2duFzS7sgdEItb2xb+U t+cA== X-Gm-Message-State: AOJu0YyP81CGVvo/+qQik9LqIBbwsAFjJUHNJs04amelGJ3+egvLvjDy SGGEaQOpnlJU2SgKhPE8y8C3kvYkF+mcKzTN13OTmvm0xgDSufEyuXHOeQ== X-Gm-Gg: ASbGnctlx2P8BWE7DqarAPx0+olJXy7v6d1rzgzL0KNOXYKKwd7fLfZlDhwF4eMfGkf GfaoPxLecwzT7E25N/aIMsbBmHN3VcfslCNuGAT/GffzrgDdPIh6SnP6chmguwnWkELYlGS1+C0 7r565ZcDsCvwjQ0C0zLE4anwTJNa9pLYerCCt4jq/wilxhUygY/rMBL/Ex8T4OtEZI6v1urjbga ZDynQE1wf7YHadC2WfbbsI2zpXffbaucACruEFubJ2sBVCfte5LqJy97f+9P+lQyjfOs1Y+SAV3 F8L8OuK1mZSIC0jX8WKdHo99 X-Google-Smtp-Source: AGHT+IH1qspQ1G8ufNdeBSxAMd1atHQcdGJC8h/Vw1FNVMgQXnn53x20gbDlPlI4tx/FNvBJwN4Hzw== X-Received: by 2002:a17:902:e848:b0:212:6011:594a with SMTP id d9443c01a7336-21778393aa4mr8269675ad.3.1733864465413; Tue, 10 Dec 2024 13:01:05 -0800 (PST) Received: from localhost.localdomain (75-164-192-68.ptld.qwest.net. [75.164.192.68]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2164419d02dsm45530625ad.268.2024.12.10.13.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 13:01:04 -0800 (PST) From: "Gerecke, Jason" X-Google-Original-From: "Gerecke, Jason" To: linux-input@vger.kernel.org, Jiri Kosina , Benjamin Tissoires Cc: Ping Cheng , Joshua Dickens , Erin Skomra , Peter Hutterer , Jason Gerecke Subject: [PATCH 1/2] HID: wacom: Improve behavior of non-standard LED brightness values Date: Tue, 10 Dec 2024 13:00:58 -0800 Message-ID: <20241210210059.87780-1-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jason Gerecke Assigning a non-standard brightness value to an LED can cause the value to slowly drift downward over time as the effects of integer division accumulate. Each time that an LED is triggered, a series of set and get calls occur. For example, if we assume a tablet with max_hlv = 100, then when brightness is set to "200" through sysfs, the hlv value written to hardware will be `200*100/255 = 78`. If the LED trigger is later activated, the hlv value will be used to determine the brightness: `78*255/100 = 198`. This lower brightness then used to set the brightness of the next LED. However, `198*100/255 = 77`, so the next LED ends up slightly dimmer. Each subsequent trigger activation will cause the brightness to continue drifting down until we reach a point where the result of integer divsion does not introduce any new error. This commit corrects the issue by being more careful about how we handle scaling between the two ranges (0..max_{h,l}lv) and (0..LED_FULL). Signed-off-by: Jason Gerecke --- drivers/hid/wacom.h | 8 ++++++++ drivers/hid/wacom_sys.c | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/hid/wacom.h b/drivers/hid/wacom.h index 6f1443999d1d9..1deacb4568cb9 100644 --- a/drivers/hid/wacom.h +++ b/drivers/hid/wacom.h @@ -218,6 +218,14 @@ static inline __u32 wacom_s32tou(s32 value, __u8 n) return value & (1 << (n - 1)) ? value & (~(~0U << n)) : value; } +static inline u32 wacom_rescale(u32 value, u32 in_max, u32 out_max) +{ + if (in_max == 0 || out_max == 0) + return 0; + value = clamp(value, 0, in_max); + return DIV_ROUND_CLOSEST(value * out_max, in_max); +} + extern const struct hid_device_id wacom_ids[]; void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len); diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 34428349fa311..5689bb6fcb264 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -1302,10 +1302,10 @@ enum led_brightness wacom_leds_brightness_get(struct wacom_led *led) struct wacom *wacom = led->wacom; if (wacom->led.max_hlv) - return led->hlv * LED_FULL / wacom->led.max_hlv; + return wacom_rescale(led->hlv, wacom->led.max_hlv, LED_FULL); if (wacom->led.max_llv) - return led->llv * LED_FULL / wacom->led.max_llv; + return wacom_rescale(led->llv, wacom->led.max_llv, LED_FULL); /* device doesn't support brightness tuning */ return LED_FULL; @@ -1337,8 +1337,8 @@ static int wacom_led_brightness_set(struct led_classdev *cdev, goto out; } - led->llv = wacom->led.llv = wacom->led.max_llv * brightness / LED_FULL; - led->hlv = wacom->led.hlv = wacom->led.max_hlv * brightness / LED_FULL; + led->llv = wacom->led.llv = wacom_rescale(brightness, LED_FULL, wacom->led.max_llv); + led->hlv = wacom->led.hlv = wacom_rescale(brightness, LED_FULL, wacom->led.max_hlv); wacom->led.groups[led->group].select = led->id; From patchwork Tue Dec 10 21:00:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 849474 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43DEF22CBF2 for ; Tue, 10 Dec 2024 21:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733864469; cv=none; b=As0M1y73bIZ+jKw5/RZDeRAHgngwgzjCn1MlHsE5rEIAyCKET8Pcdh/F2sqa+P3LF39AgN7/wL09JxtCPRDEz2nmMAma2QzIiFxfEDZcDAH82yuP01mx5gc+LBCxrQMgps55ITM86LcyatHsA81KeN7K1sZAENDNeDbm6+oym/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733864469; c=relaxed/simple; bh=ItcyMlCLd+5cE0NmL8lYd39KFYD+l+56nRJiRSqL1eE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i+IoC8OdCYeDEtj3ZAhTw+YLcLKj9gBW5Ngte2wegXzHcpgQiu4NfPkI3od0TzeLaxzCzw+24/d5UQ4SUR6y63y5EgVNPEzICnEl/12X1NB8plVi0WvQZdNKfdzxbm0CbbuEtH8X1ahACvr324CRKxwi29avTFq8jzHN5/0nFH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T1drlFJP; arc=none smtp.client-ip=209.85.214.174 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.b="T1drlFJP" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2163dc5155fso26132855ad.0 for ; Tue, 10 Dec 2024 13:01:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733864467; x=1734469267; 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; bh=ZkphP3HDfEfJV6jv71F7QkJUTS+/ikjohv4a3WH/Meo=; b=T1drlFJPAEdKB8cb6J9Drio/FDNE0rrlGCNl/1lLvWYXIW3+D7OS+1Lf6i8c9SR3xP uGr7hSWO5LPvRf6hTTiZHczVVtcaWOf2gg8s6HxKPz5ZwiNrzKWgSmgOE7VJvhCVzGWT /xSC/zVJJdrmvdhIM5m5pCwnrWMERbVrEKOtXvxlruWFifM1/C6yf6+ImhpWzBj/uHen vr2zCPq4QgXw+xSqw+9aDmM/JZ/p11G4bCxrFJZZKf2MDyToMqt2m07EWxLXC9vhhqF2 G6CmR+7LG9bJEk4ug6L+PPp3HClpTVv/XHbFcCKzEB1t/w3k3kgUAfCcddeeEgteaUu6 hpgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733864467; x=1734469267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZkphP3HDfEfJV6jv71F7QkJUTS+/ikjohv4a3WH/Meo=; b=ghY372xWE/47UuOSmEPAQlu99ZlehmGk724abNaTx/W/zwkdjnPH0SlNwR1MkgXrX6 RfTfn+jw27txcMo/Rz8QMS/sA9GFH5/J4nzLPbKT9kRBMG0XJn1qgHfLS8b8kTHt0/v1 Xcot4X7M9mL8u2v8S5DHC/g+wsuUhnOWzE0dZU6PxAkd9103u2RXGgV40k06MuOInMpq zHts/WPDhu5XDYtOQ6sF8fd8HuxEk46lVpDWCzurA79VAjrCkrn803+Af1mbp8XnfzEL bzfFPZVKrkuY9ZJe7f16E/gkD9ExW6NRkvDZLnBsnJRmDyQZI961Vi5JA6ZTphLASOCD aTJA== X-Gm-Message-State: AOJu0YxYcCGqcKZWGUO14GFPEyQD7GBzeKVqVgqKBxBhuWKxUXyfScTS 7pI3ixRvmq0TGHX+iiTejdg7r+fU6XD6a+ribeGg5Y/RyRDNNaL+UmabaA== X-Gm-Gg: ASbGncuik4Xf7tgyN2xYBv1pEc3syWxqG7ezE+cugpZKfVS+Gxaf5m35qMWG8nQ1ZWw Z6G9ZhChibXUQ32mBpipUFFuzIaSJsu++w95rDDmIaRjXeQMGt5H1m/NlMzpW52pLXH523MlvCk NtFHIhRlPv488a7YBXHM6+jQPytJeVqFrTZXaVCw7Een830SgOnQU84AAO94T/9yT75vr3hZhT8 0DyocppDqnLk0yLx61AACuug/go5zaSPqGTEefU1VhL3z/Klov6N4XUP/DQmQj9IvRWzqL0WBsS Zk6CyJYkQJ9cikVawl06wdo0 X-Google-Smtp-Source: AGHT+IG/krV/UNRRjn/ZbjQ9g9pfameASGJ/Wg7Evzw/ATEB1o8MRgDF0QXgfjMuCy4DbS6Z5mh9FQ== X-Received: by 2002:a17:902:d54a:b0:216:4c88:d939 with SMTP id d9443c01a7336-21778505a47mr9573445ad.38.1733864466621; Tue, 10 Dec 2024 13:01:06 -0800 (PST) Received: from localhost.localdomain (75-164-192-68.ptld.qwest.net. [75.164.192.68]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2164419d02dsm45530625ad.268.2024.12.10.13.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 13:01:06 -0800 (PST) From: "Gerecke, Jason" X-Google-Original-From: "Gerecke, Jason" To: linux-input@vger.kernel.org, Jiri Kosina , Benjamin Tissoires Cc: Ping Cheng , Joshua Dickens , Erin Skomra , Peter Hutterer , Jason Gerecke Subject: [PATCH 2/2] HID: wacom: Status luminance properties should set brightness of all LEDs Date: Tue, 10 Dec 2024 13:00:59 -0800 Message-ID: <20241210210059.87780-2-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241210210059.87780-1-jason.gerecke@wacom.com> References: <20241210210059.87780-1-jason.gerecke@wacom.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jason Gerecke The wacom driver has (deprecated) sysfs properties `status0_luminance` and `status1_luminance` that are used to control the low- and high- level brightness values (llv and hlv) of the status LEDs. These two properties had an effect on /all/ of the status LEDs. After our driver switched to exposing each status LED individually through the LED class, this behavior changed. These controls started having only a temporary effect on the currently-lit LED. If a trigger changed the current LED, the driver would switch the brightness back to the llv/hlv values stored per-LED. (The code's current behavior of updating the "global" e.g. `wacom->led.llv` values has essentially no effect because those values are only used at initialization time). This commit restores the original behavior by ensuring these properties update the per-LED brightness for all LEDs. Signed-off-by: Jason Gerecke --- drivers/hid/wacom_sys.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 5689bb6fcb264..8125383932ec7 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -1084,6 +1084,17 @@ static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest, mutex_lock(&wacom->lock); *dest = value & 0x7f; + for (unsigned int i = 0; i < wacom->led.count; i++) { + struct wacom_group_leds *group = &wacom->led.groups[i]; + + for (unsigned int j = 0; j < group->count; j++) { + if (dest == &wacom->led.llv) + group->leds[j].llv = *dest; + else if (dest == &wacom->led.hlv) + group->leds[j].hlv = *dest; + } + } + err = wacom_led_control(wacom); mutex_unlock(&wacom->lock);