From patchwork Fri Jul 31 22:36:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11695549 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 060BA138A for ; Fri, 31 Jul 2020 22:45:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC61922B3F for ; Fri, 31 Jul 2020 22:44:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="UzABnuFV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726281AbgGaWo7 (ORCPT ); Fri, 31 Jul 2020 18:44:59 -0400 Received: from mail-40140.protonmail.ch ([185.70.40.140]:17401 "EHLO mail-40140.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726099AbgGaWo7 (ORCPT ); Fri, 31 Jul 2020 18:44:59 -0400 X-Greylist: delayed 492 seconds by postgrey-1.27 at vger.kernel.org; Fri, 31 Jul 2020 18:44:58 EDT Date: Fri, 31 Jul 2020 22:36:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1596235004; bh=DZK+C9tspeddpYuevasHBR3qJVFo7MjtUx2qpZxkoXs=; h=Date:To:From:Reply-To:Subject:From; b=UzABnuFVzPs/tzGpTfOU346tWyURsjmOvegLLzDf8JkswwxJBW1lgQqZ9o3MzMCqn A8WZRXf87+0KG7f4CLFtHCxZCE5mHOeD12qcHj16Yh8BXiZZvVZ894dmDPOLEIpiyy yAOfrwC2UmF8WrmQt7id67DQjoJgouxNNjCyiHKU= To: Jiri Kosina , Benjamin Tissoires , "linux-input@vger.kernel.org" From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 1/2] HID: multitouch: export {surface,button}_switch to sysfs Message-ID: <46x0ZulX2qWADzBaU_UWUW7qQX-azKvbS40ooWaLKhIZ-NkUZDy51EfE6f1ViuUAEGPmBLYVTONaipsGosR0WczAt_OIFbW-8CkK42hXdfo=@protonmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mail.protonmail.ch Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Some touchpads have an LED that tells the user whether the touchpad is disabled/enabled. Sometimes this LED may only be controlled by the touchpad hardware. In such cases disabling the touchpad simply via X.Org (or other similar means) cannot take advantage of the available LED to signal the state of the touchpad to the user. Thus users may choose to disable their touchpad via these two attributes (instead of xinput, etc.) so that they can take advantage of the visual cue provided by the LED. This commit also changes all exported attributes to use the DEVICE_ATTR_RW() macro (hence mt_{show,set}_quirks() functions have been renamed). Signed-off-by: Barnabás Pőcze --- drivers/hid/hid-multitouch.c | 96 ++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 10 deletions(-) -- 2.27.0 diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 3f94b4954225..051c78c37603 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -164,6 +164,8 @@ struct mt_device { __u8 maxcontacts; bool is_buttonpad; /* is this device a button pad? */ bool serial_maybe; /* need to check for serial protocol */ + enum latency_mode latency; + bool surface_switch, button_switch; struct list_head applications; struct list_head reports; @@ -370,7 +372,7 @@ static const struct mt_class mt_classes[] = { { } }; -static ssize_t mt_show_quirks(struct device *dev, +static ssize_t quirks_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -380,7 +382,7 @@ static ssize_t mt_show_quirks(struct device *dev, return sprintf(buf, "%u\n", td->mtclass.quirks); } -static ssize_t mt_set_quirks(struct device *dev, +static ssize_t quirks_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -404,10 +406,72 @@ static ssize_t mt_set_quirks(struct device *dev, return count; } -static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks); +static void mt_set_modes(struct mt_device *td); + +static ssize_t surface_switch_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct hid_device *hdev = to_hid_device(dev); + struct mt_device *td = hid_get_drvdata(hdev); + + return sprintf(buf, "%d\n", (int) td->surface_switch); +} + +static ssize_t surface_switch_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hdev = to_hid_device(dev); + struct mt_device *td = hid_get_drvdata(hdev); + + bool val; + + if (kstrtobool(buf, &val)) + return -EINVAL; + + td->surface_switch = val; + mt_set_modes(td); + + return count; +} + +static ssize_t button_switch_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct hid_device *hdev = to_hid_device(dev); + struct mt_device *td = hid_get_drvdata(hdev); + + return sprintf(buf, "%d\n", (int) td->button_switch); +} + +static ssize_t button_switch_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hdev = to_hid_device(dev); + struct mt_device *td = hid_get_drvdata(hdev); + + bool val; + + if (kstrtobool(buf, &val)) + return -EINVAL; + + td->button_switch = val; + mt_set_modes(td); + + return count; +} + +static DEVICE_ATTR_RW(quirks); +static DEVICE_ATTR_RW(surface_switch); +static DEVICE_ATTR_RW(button_switch); static struct attribute *sysfs_attrs[] = { &dev_attr_quirks.attr, + &dev_attr_surface_switch.attr, + &dev_attr_button_switch.attr, NULL }; @@ -1470,9 +1534,9 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev, return false; /* no need to update the report */ } -static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency, - bool surface_switch, bool button_switch) +static void mt_set_modes(struct mt_device *td) { + struct hid_device *hdev = td->hdev; struct hid_report_enum *rep_enum; struct hid_report *rep; struct hid_usage *usage; @@ -1495,9 +1559,9 @@ static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency, if (mt_need_to_apply_feature(hdev, rep->field[i], usage, - latency, - surface_switch, - button_switch, + td->latency, + td->surface_switch, + td->button_switch, &inputmode_found)) update_report = true; } @@ -1738,7 +1802,11 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n", hdev->name); - mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true); + td->latency = HID_LATENCY_NORMAL; + td->surface_switch = true; + td->button_switch = true; + + mt_set_modes(td); return 0; } @@ -1746,8 +1814,16 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) #ifdef CONFIG_PM static int mt_reset_resume(struct hid_device *hdev) { + struct mt_device *td = hid_get_drvdata(hdev); + mt_release_contacts(hdev); - mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true); + + td->latency = HID_LATENCY_NORMAL; + td->surface_switch = true; + td->button_switch = true; + + mt_set_modes(td); + return 0; } From patchwork Fri Jul 31 22:36:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 11695551 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2D60138A for ; Fri, 31 Jul 2020 22:46:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9922B208E4 for ; Fri, 31 Jul 2020 22:46:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="J8gGLVro" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726932AbgGaWqj (ORCPT ); Fri, 31 Jul 2020 18:46:39 -0400 Received: from mail4.protonmail.ch ([185.70.40.27]:48271 "EHLO mail4.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726099AbgGaWqi (ORCPT ); Fri, 31 Jul 2020 18:46:38 -0400 Date: Fri, 31 Jul 2020 22:36:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1596235010; bh=jOpCThSd4zWFLr8rUsalKKueJOq+gXIB/lUGVFH8X7E=; h=Date:To:From:Reply-To:Subject:From; b=J8gGLVroyMELyjskaOqt0mP3TbXAhWwdb1W2q2Qng3XROXR+YyebrRW+TFoXd6pHT r+ioKrRotSatCkr8QEKBGVKHyqudcuLn8r6WVqWxFlmE1MGJQwaEnygkCm/Jh2RJmC SgEdX+FgzrQ06eyUr9HiHTnOSX/eXN37h0W7/cCk= To: Jiri Kosina , Benjamin Tissoires , "linux-input@vger.kernel.org" From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH 2/2] Documentation/ABI/hid-multitouch: add description for {surface,button}_switch sysfs attributes Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mail.protonmail.ch Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This commit adds description for the {surface,button}_switch sysfs attributes that are exported by the hid-multitouch driver, and that may be used to enable/disable certain parts of a touch device. Signed-off-by: Barnabás Pőcze --- .../ABI/testing/sysfs-driver-hid-multitouch | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) -- 2.27.0 diff --git a/Documentation/ABI/testing/sysfs-driver-hid-multitouch b/Documentation/ABI/testing/sysfs-driver-hid-multitouch index f79839d1af37..10c8d427232d 100644 --- a/Documentation/ABI/testing/sysfs-driver-hid-multitouch +++ b/Documentation/ABI/testing/sysfs-driver-hid-multitouch @@ -7,3 +7,20 @@ Description: The integer value of this attribute corresponds to the MT_QUIRKS_* in hid-multitouch.c). When written this attribute change on the fly the quirks, then the protocol to handle the device. + +What: /sys/bus/usb/devices/-:./::./surface_switch +Date: July 2020 +Contact: linux-input@vger.kernel.org +Description: The integer value of this attribute corresponds to the state of + the device's surface switch. It is 0 if the the surface switch + is off, meaning no surface events are reported; otherwise it + is 1. Writing to this attribute changes the state of the switch. + + +What: /sys/bus/usb/devices/-:./::./button_switch +Date: July 2020 +Contact: linux-input@vger.kernel.org +Description: The integer value of this attribute corresponds to the state of + the device's button switch. It is 0 if the the button switch + is off, meaning no button events are reported; otherwise it + is 1. Writing to this attribute changes the state of the switch.