From nobody Sun Oct 5 14:09:57 2025 Received: from mail-il1-f201.google.com (mail-il1-f201.google.com [209.85.166.201]) (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 1F95E270EA3 for ; Mon, 4 Aug 2025 14:11:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754316686; cv=none; b=PuI767h3Z3PUFiVjc0+cIQd1PxxcwKY5U/e1KPPzU2eTYAdMk4yoTuOOTueBWffnldEh/1oQS9gUB3yI9dkZXtYVYwTbMlOv4n83xoygHEWLVAAK9ckwvgglDBeH6YRmmi9UNXjdz2lsVtDikg3/7VZNCkaJ0VbaHYU9ss3ghmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754316686; c=relaxed/simple; bh=7C9KnOWBMiDynkpD0XgPEOAXG+leUvk1gAVzZExBgzY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HriyWo0bJeQQbJq9vwMBPgPSzxG0RpA5Db5cp2ngK3ZmbCErqPyZ6WSuBYOLpzgM32hKJ9I/DN5pXMhMX8pLmGokxHb4T1HGxG6X6RxLYVhuKlnFD4XG2ZWadpBaQIKXEOEZ+xwqdWJfAERDGzQL95qXhk5pJgDkioHdREftKa4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jdenose.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=o5i2Z4vS; arc=none smtp.client-ip=209.85.166.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jdenose.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="o5i2Z4vS" Received: by mail-il1-f201.google.com with SMTP id e9e14a558f8ab-3e3fe1d77ccso29618235ab.2 for ; Mon, 04 Aug 2025 07:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1754316683; x=1754921483; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tI2UwnRHp67jtdQcIIHTxEfXbkGwaWKBWOArqM8/7sQ=; b=o5i2Z4vSeAN/Iu/EQIsXG7n38WVM/aStZ1z3h0Lj3s/jsEJvpKKQzt9qzUu14f61mz URsIFxc5J/MD+QTpL6jLuMXv/ZoJ4cbAiDLiF1cemTMw+v9m8fdAzIvt/Tyl/xQYhPy6 GUTvvixD4QwPAq1BqpyNuhqmjasEW9DjMlvqP0iTgZW5NPH6Bqy7EJ9WEb8Nci3ZV2GA RoNblnsq9hHkijMJuvrj7guvCusJhRr2GLePh4fVJEFk5NfuKK7H0v8KLnF946x+y1A1 okvdAxkxTQBFjwFre9XYdgRpb3XlbDvfoh76ybGkFCg4vqT7Jt4hEDKsOEA2WXEvSHEl phtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754316683; x=1754921483; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tI2UwnRHp67jtdQcIIHTxEfXbkGwaWKBWOArqM8/7sQ=; b=AyWvrvFujfQfV3jGfGe/x0HDfY1jemD8WlKvAYLKLttuCxUg/rg/tzEGzv6bYCiSec GRMs98uenKw+TKhZnfjmNczvaWpY1jEuLw0uY6d/OOF5hL6CGkrstZ6AaIjzxvLHg6fE YG8m+kWTZiNudk9IMIvSBfZjzQuCeqrsB9gGWQQa9L5G4X+nTEMOrBNp2EJ1xgXZ1Urk Q8d/WPGYxZgL8zIjMoZ8u+2MGqzzQyPCFYh+PLRdHQ5AxyDIDwIbMe2HcBLmG2mtsilc AhvoLu8vGYPVtlsL0WfWKYA2ppMKkfMpnJH9ULAB0o95yqsd+JPB1UoBfdmfKm4jM9an N5lw== X-Forwarded-Encrypted: i=1; AJvYcCXI1mHc9xeJ7XBjNDn4XoDCeThJ43iuuqcEqC9j95tdx/EY1CNp3J7XH4q0/MW2DYN8t60cWn5jQKhsc84=@vger.kernel.org X-Gm-Message-State: AOJu0YyXkUrvvsYzPF3uYD9Q7jqMpu83txT4mjfOPYkz3adnnDz/ONIM 2cys3WWN/uHHkhc5K3TDC0t2oBNhBwTX5E3zgXZv+ok2U4T5i4On8QeQty92zG6GM0vNAujf7OX C6s7vMiaMHA== X-Google-Smtp-Source: AGHT+IG94Ytkdp9v6tw5ED83Vd429b23qGOtJraJWnGWhrOUSoc7Hxd+FrrKYeEDdZs/k3iY2iFFO7Zy8pgh X-Received: from ilbbt17.prod.google.com ([2002:a05:6e02:2491:b0:3e4:1196:9e17]) (user=jdenose job=prod-delivery.src-stubby-dispatcher) by 2002:a92:cda6:0:b0:3e2:a8d7:cbc0 with SMTP id e9e14a558f8ab-3e41610d612mr178872045ab.2.1754316683290; Mon, 04 Aug 2025 07:11:23 -0700 (PDT) Date: Mon, 04 Aug 2025 14:11:19 +0000 In-Reply-To: <20250804-support-forcepads-v2-0-138ca980261d@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250804-support-forcepads-v2-0-138ca980261d@google.com> X-Mailer: b4 0.14.2 Message-ID: <20250804-support-forcepads-v2-4-138ca980261d@google.com> Subject: [PATCH v2 04/11] HID: haptic: introduce hid_haptic_device From: Jonathan Denose To: Jiri Kosina , Benjamin Tissoires , Dmitry Torokhov , Jonathan Corbet , Henrik Rydberg Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Angela Czubak , "Sean O'Brien" , Jonathan Denose Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Angela Czubak Define a new structure that contains simple haptic device configuration as well as current state. Add functions that recognize auto trigger and manual trigger reports as well as save their addresses. Verify that the pressure unit is either grams or newtons. Mark the input device as a haptic touchpad if the unit is correct and the reports are found. Signed-off-by: Angela Czubak Co-developed-by: Jonathan Denose Signed-off-by: Jonathan Denose --- drivers/hid/Kconfig | 9 ++++++ drivers/hid/Makefile | 1 + drivers/hid/hid-haptic.c | 72 ++++++++++++++++++++++++++++++++++++++++++++= ++ drivers/hid/hid-haptic.h | 74 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 156 insertions(+) diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 43859fc757470caf6ad43bd5f72f119e9c36aea7..ad6bcc4248cc111705d7cfde2b1= 481b46353e2d7 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -92,6 +92,15 @@ config HID_GENERIC =20 If unsure, say Y. =20 +config HID_HAPTIC + bool "Haptic touchpad support" + default n + help + Support for touchpads with force sensors and haptic actuators instead of a + traditional button. + + If unsure, say N. + menu "Special HID drivers" =20 config HID_A4TECH diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 10ae5dedbd84708d988ea1f594d409ccebd85ebb..361a7daedeb85454114def8afb5= f58caeab58a00 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -4,6 +4,7 @@ # hid-y :=3D hid-core.o hid-input.o hid-quirks.o hid-$(CONFIG_DEBUG_FS) +=3D hid-debug.o +hid-$(CONFIG_HID_HAPTIC) +=3D hid-haptic.o =20 obj-$(CONFIG_HID_BPF) +=3D bpf/ =20 diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c new file mode 100644 index 0000000000000000000000000000000000000000..d659a430c1a6b06ded31d49efe4= bded909671cb6 --- /dev/null +++ b/drivers/hid/hid-haptic.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * HID Haptic support for Linux + * + * Copyright (c) 2021 Angela Czubak + */ + +#include "hid-haptic.h" + +void hid_haptic_feature_mapping(struct hid_device *hdev, + struct hid_haptic_device *haptic, + struct hid_field *field, struct hid_usage *usage) +{ + if (usage->hid =3D=3D HID_HP_AUTOTRIGGER) { + if (usage->usage_index >=3D field->report_count) { + dev_err(&hdev->dev, + "HID_HP_AUTOTRIGGER out of range\n"); + return; + } + + hid_device_io_start(hdev); + hid_hw_request(hdev, field->report, HID_REQ_GET_REPORT); + hid_hw_wait(hdev); + hid_device_io_stop(hdev); + haptic->default_auto_trigger =3D + field->value[usage->usage_index]; + haptic->auto_trigger_report =3D field->report; + } +} +EXPORT_SYMBOL_GPL(hid_haptic_feature_mapping); + +bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic, + struct hid_input *hi, struct hid_field *field) +{ + if (field->unit =3D=3D HID_UNIT_GRAM || field->unit =3D=3D HID_UNIT_NEWTO= N) + return true; + return false; +} +EXPORT_SYMBOL_GPL(hid_haptic_check_pressure_unit); + +int hid_haptic_input_mapping(struct hid_device *hdev, + struct hid_haptic_device *haptic, + struct hid_input *hi, + struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max) +{ + if (usage->hid =3D=3D HID_HP_MANUALTRIGGER) { + haptic->manual_trigger_report =3D field->report; + /* we don't really want to map these fields */ + return -1; + } + + return 0; +} +EXPORT_SYMBOL_GPL(hid_haptic_input_mapping); + +int hid_haptic_input_configured(struct hid_device *hdev, + struct hid_haptic_device *haptic, + struct hid_input *hi) +{ + + if (hi->application =3D=3D HID_DG_TOUCHPAD) { + if (haptic->auto_trigger_report && + haptic->manual_trigger_report) { + __set_bit(INPUT_PROP_HAPTIC_TOUCHPAD, hi->input->propbit); + return 1; + } + return 0; + } + return -1; +} +EXPORT_SYMBOL_GPL(hid_haptic_input_configured); diff --git a/drivers/hid/hid-haptic.h b/drivers/hid/hid-haptic.h new file mode 100644 index 0000000000000000000000000000000000000000..fc8979772d00e8b3238b26060c5= 541065a61811d --- /dev/null +++ b/drivers/hid/hid-haptic.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * HID Haptic support for Linux + * + * Copyright (c) 2021 Angela Czubak + */ + +/* + */ + + +#include + +#define HID_HAPTIC_ORDINAL_WAVEFORMNONE 1 +#define HID_HAPTIC_ORDINAL_WAVEFORMSTOP 2 + +#define HID_HAPTIC_MODE_DEVICE 0 +#define HID_HAPTIC_MODE_HOST 1 + +struct hid_haptic_effect { + u8 *report_buf; + struct input_dev *input_dev; + struct work_struct work; + struct list_head control; + struct mutex control_mutex; +}; + +struct hid_haptic_effect_node { + struct list_head node; + struct file *file; +}; + +struct hid_haptic_device { + struct input_dev *input_dev; + struct hid_device *hdev; + struct hid_report *auto_trigger_report; + struct mutex auto_trigger_mutex; + struct workqueue_struct *wq; + struct hid_report *manual_trigger_report; + struct mutex manual_trigger_mutex; + size_t manual_trigger_report_len; + int pressed_state; + s32 pressure_sum; + s32 force_logical_minimum; + s32 force_physical_minimum; + s32 force_resolution; + u32 mode; + u32 default_auto_trigger; + u32 vendor_page; + u32 vendor_id; + u32 max_waveform_id; + u32 max_duration_id; + u16 *hid_usage_map; + u32 *duration_map; + u16 press_ordinal; + u16 release_ordinal; + struct hid_haptic_effect *effect; + struct hid_haptic_effect stop_effect; +}; + +void hid_haptic_feature_mapping(struct hid_device *hdev, + struct hid_haptic_device *haptic, + struct hid_field *field, struct hid_usage + *usage); +bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic, + struct hid_input *hi, struct hid_field *field); +int hid_haptic_input_mapping(struct hid_device *hdev, + struct hid_haptic_device *haptic, + struct hid_input *hi, + struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max); +int hid_haptic_input_configured(struct hid_device *hdev, + struct hid_haptic_device *haptic, + struct hid_input *hi); --=20 2.50.1.565.gc32cd1483b-goog