[PATCH v5 06/13] HID: haptic: Convert to a loadable plugin module
From: Rong Zhang
Date: Sun Nov 29 2026 - 12:56:46 EST
Commit 083a4f3f3cc7 ("HID: Kconfig: Fix build error from
CONFIG_HID_HAPTIC") built hid-haptic into vmlinux or hid.ko. This is not
optimal for generic kernel images, as a platform with no multitouch
device doesn't need it anyway. It's also a bit harsh for enabling it in
distribution kernels.
With the new hid-plugin framework, convert hid-haptic into a loadable
plugin module, which is only requested on demand.
The plugin provides complicated methods as callbacks, which can be
called by using the associated static inline wrappers. Simple methods
are moved to the header file as static inline ones, too.
The plugin now connects to hid-input instead of hid-multitouch, only
leaving several hooks in the latter. Despite that, it still only works
on hid-multitouch devices. The limitation will be lifted in the future.
If the HID driver provides EV_FF itself or ask the HID core not to
register FF devices, no haptic FF device is registered. Otherwise,
prefer hid-haptic over hid-pidff.
When hid-haptic is disabled, the hid-plugin framework's helper functions
will ensure that all calls to its methods are subject to dead code
elimination during compilation.
The redaundent `default n' statement in Kconfig is also removed for
tidiness since we are anyway touching its context.
Suggested-by: Benjamin Tissoires <bentiss@xxxxxxxxxx>
Link: https://lore.kernel.org/linux-input/auypydfkhx2eg7vp764way4batdilzc35inqda3exwzs3tk3ff@oagat6g46zto/
Signed-off-by: Rong Zhang <i@xxxxxxxx>
---
Changes in v5:
- Adopt the new hid-plugin design
- Connect to hid-input
- Alloc hid_haptic_device in hid_haptic_feature_mapping()
- Don't move complicated methods to the header file
---
MAINTAINERS | 1 +
drivers/hid/Kconfig | 8 +-
drivers/hid/Makefile | 2 +-
drivers/hid/hid-haptic.c | 82 +++++++++++----------
drivers/hid/hid-haptic.h | 172 ++++++++++++++++++++++++++-----------------
drivers/hid/hid-input.c | 50 ++++++++++++-
drivers/hid/hid-multitouch.c | 35 ++-------
drivers/hid/hid-plugin.c | 3 +
include/linux/hid.h | 8 +-
9 files changed, 221 insertions(+), 140 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 6b2a4a96a333..b09007428c43 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11906,6 +11906,7 @@ HID PLUGINS
M: Rong Zhang <i@xxxxxxxx>
L: linux-input@xxxxxxxxxxxxxxx
S: Maintained
+F: drivers/hid/hid-haptic.*
F: drivers/hid/hid-plugin.*
HID PULSAR DRIVER
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index f9f4fb4de986..80b950eb54d9 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -105,12 +105,14 @@ menuconfig HID_PLUGIN
If unsure, say Y.
+if HID_PLUGIN
+
config HID_PLUGIN_CORE
bool
config HID_HAPTIC
- bool "Haptic touchpad support"
- default n
+ tristate "Haptic touchpad support"
+ select HID_PLUGIN_CORE
help
Support for touchpads with force sensors and haptic actuators instead of a
traditional button.
@@ -119,6 +121,8 @@ config HID_HAPTIC
If unsure, say N.
+endif # HID_PLUGIN
+
menu "Special HID drivers"
config HID_A4TECH
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index b39ccc9a360b..29b983517ac0 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -6,7 +6,7 @@ hid-y := hid-core.o hid-input.o hid-quirks.o
hid-$(CONFIG_DEBUG_FS) += hid-debug.o
hid-$(CONFIG_HID_PLUGIN_CORE) += hid-plugin.o
-hid-$(CONFIG_HID_HAPTIC) += hid-haptic.o
+obj-$(CONFIG_HID_HAPTIC) += hid-haptic.o
obj-$(CONFIG_HID_BPF) += bpf/
diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c
index 2e9631fa2f69..c8c1c7fddaa6 100644
--- a/drivers/hid/hid-haptic.c
+++ b/drivers/hid/hid-haptic.c
@@ -5,14 +5,14 @@
* Copyright (c) 2021 Angela Czubak <acz@xxxxxxxxxxxx>
*/
+#include <linux/err.h>
#include <linux/input/mt.h>
#include <linux/module.h>
#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)
+static void __hid_haptic_feature_mapping(struct hid_device *hdev, struct hid_haptic_device *haptic,
+ struct hid_field *field, struct hid_usage *usage)
{
u16 usage_hid;
@@ -39,10 +39,9 @@ void hid_haptic_feature_mapping(struct hid_device *hdev,
}
}
}
-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)
+static bool __hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
+ struct hid_input *hi, struct hid_field *field)
{
if (IS_ERR(haptic->input_dev))
return false;
@@ -78,23 +77,6 @@ bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
haptic->input_dev = ERR_PTR(-EPROTO);
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 == HID_HP_MANUALTRIGGER) {
- haptic->manual_trigger_report = field->report;
- /* we don't really want to map these fields */
- return -1;
- }
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(hid_haptic_input_mapping);
static void parse_auto_trigger_field(struct hid_haptic_device *haptic,
struct hid_field *field)
@@ -396,6 +378,9 @@ static void hid_haptic_destroy(struct ff_device *ff)
kfree(haptic->hid_usage_map);
haptic->hid_usage_map = NULL;
+
+ /* Our private data is managed by hid-plugin. */
+ ff->private = NULL;
}
static void hid_haptic_get_reports(struct hid_device *hdev, struct hid_haptic_device *haptic)
@@ -408,9 +393,8 @@ static void hid_haptic_get_reports(struct hid_device *hdev, struct hid_haptic_de
hid_device_io_stop(hdev);
}
-int hid_haptic_init(struct hid_device *hdev,
- struct hid_haptic_device *haptic,
- struct input_dev *dev)
+static int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic,
+ struct input_dev *dev)
{
struct ff_device *ff;
int ret = 0, r;
@@ -531,7 +515,6 @@ int hid_haptic_init(struct hid_device *hdev,
hid_warn(hdev, "Cannot allocate haptic for %s: %d\n", hdev->name, ret);
return ret;
}
-EXPORT_SYMBOL_GPL(hid_haptic_init);
static int hid_haptic_check_prerequisites(struct hid_device *hdev,
struct hid_haptic_device *haptic, struct hid_input *hi)
@@ -542,14 +525,18 @@ static int hid_haptic_check_prerequisites(struct hid_device *hdev,
if (IS_ERR_OR_NULL(haptic->input_dev))
return PTR_ERR(haptic->input_dev) ?: -EXDEV;
+ /* Check the prerequisites only. */
+ if (!hi)
+ return 1;
+
if (haptic->input_dev == hi->input)
return 0;
return 1; /* Waiting for the relevant input device. */
}
-int hid_haptic_input_configured(struct hid_device *hdev,
- struct hid_haptic_device *haptic, struct hid_input *hi)
+static int __hid_haptic_input_configured(struct hid_device *hdev,
+ struct hid_haptic_device *haptic, struct hid_input *hi)
{
int ret;
@@ -566,17 +553,34 @@ int hid_haptic_input_configured(struct hid_device *hdev,
return 0;
}
-EXPORT_SYMBOL_GPL(hid_haptic_input_configured);
-void hid_haptic_pressure_reset(struct hid_haptic_device *haptic)
-{
- haptic->pressure_sum = 0;
-}
-EXPORT_SYMBOL_GPL(hid_haptic_pressure_reset);
+static struct hid_plugin_haptic hid_plugin_haptic;
-void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
- __s32 pressure)
+static void *hid_haptic_plugin_connect(struct hid_device *hdev)
{
- haptic->pressure_sum += pressure;
+ struct hid_haptic_device *haptic = kzalloc_obj(*haptic);
+
+ if (!haptic)
+ return ERR_PTR(-ENOMEM);
+
+ haptic->hdev = hdev;
+ haptic->plugin = &hid_plugin_haptic;
+ return haptic;
}
-EXPORT_SYMBOL_GPL(hid_haptic_pressure_increase);
+
+static struct hid_plugin_haptic hid_plugin_haptic = {
+ .hp = {
+ .owner = THIS_MODULE,
+ .connect = hid_haptic_plugin_connect,
+ },
+ .feature_mapping = __hid_haptic_feature_mapping,
+ .check_pressure_unit = __hid_haptic_check_pressure_unit,
+ .input_configured = __hid_haptic_input_configured,
+};
+module_hid_plugin(haptic, HID_PLUGIN_HAPTIC, &hid_plugin_haptic.hp);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Angela Czubak <aczubak@xxxxxxxxxx>");
+MODULE_AUTHOR("Jonathan Denose <jdenose@xxxxxxxxxx>");
+MODULE_AUTHOR("Rong Zhang <i@xxxxxxxx>");
+MODULE_DESCRIPTION("HID helpers for Haptics Page");
diff --git a/drivers/hid/hid-haptic.h b/drivers/hid/hid-haptic.h
index e39104f75229..836520bf8dc7 100644
--- a/drivers/hid/hid-haptic.h
+++ b/drivers/hid/hid-haptic.h
@@ -5,8 +5,13 @@
* Copyright (c) 2021 Angela Czubak <acz@xxxxxxxxxxxx>
*/
+#include <linux/compiler.h>
+#include <linux/container_of.h>
+#include <linux/err.h>
#include <linux/hid.h>
+#include "hid-plugin.h"
+
#define HID_HAPTIC_ORDINAL_WAVEFORMNONE 1
#define HID_HAPTIC_ORDINAL_WAVEFORMSTOP 2
@@ -51,90 +56,123 @@ struct hid_haptic_device {
u16 release_ordinal;
struct hid_haptic_effect *effect;
struct hid_haptic_effect stop_effect;
+
+ struct hid_plugin_haptic *plugin;
+};
+
+struct hid_plugin_haptic {
+ struct hid_plugin hp;
+ void (*feature_mapping)(struct hid_device *hdev, struct hid_haptic_device *haptic,
+ struct hid_field *field, struct hid_usage *usage);
+ bool (*check_pressure_unit)(struct hid_haptic_device *haptic,
+ struct hid_input *hi, struct hid_field *field);
+ int (*input_configured)(struct hid_device *hdev, struct hid_haptic_device *haptic,
+ struct hid_input *hi);
};
-#if IS_ENABLED(CONFIG_HID_HAPTIC)
-static inline bool hid_haptic_connected_to_input(struct hid_haptic_device *haptic,
- struct input_dev *input)
+static inline struct hid_haptic_device *hid_plugin_to_haptic(struct hid_device *hdev)
{
+ return hid_plugin_to_priv(hdev, HID_PLUGIN_HAPTIC);
+}
+
+static inline bool hid_haptic_connected_to_input(struct hid_device *hdev, struct input_dev *input)
+{
+ struct hid_haptic_device *haptic = hid_plugin_to_haptic(hdev);
+
+ if (IS_ERR_OR_NULL(haptic))
+ return false;
+
return haptic->input_dev == input;
}
-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);
-int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic,
- struct input_dev *dev);
-void hid_haptic_handle_press_release(struct hid_haptic_device *haptic);
-void hid_haptic_pressure_reset(struct hid_haptic_device *haptic);
-void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
- __s32 pressure);
-#else
-static inline bool hid_haptic_connected_to_input(struct hid_haptic_device *haptic,
- struct input_dev *input)
+static inline struct hid_haptic_device *hid_haptic_connect(struct hid_device *hdev)
{
- return false;
+ return hid_plugin_connect(hdev, HID_PLUGIN_HAPTIC);
}
-static inline
-void hid_haptic_feature_mapping(struct hid_device *hdev,
- struct hid_haptic_device *haptic,
- struct hid_field *field, struct hid_usage
- *usage)
-{}
-static inline
-bool hid_haptic_check_pressure_unit(struct hid_haptic_device *haptic,
- struct hid_input *hi, struct hid_field *field)
+static inline void hid_haptic_disconnect(struct hid_device *hdev)
{
- return false;
+ hid_plugin_disconnect(hdev, HID_PLUGIN_HAPTIC);
}
-static inline
-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)
+
+static inline void hid_haptic_feature_mapping(struct hid_device *hdev, struct hid_field *field,
+ struct hid_usage *usage)
{
- return 0;
+ struct hid_haptic_device *haptic;
+
+ if ((field->logical & HID_USAGE_PAGE) != HID_UP_HAPTIC &&
+ (usage->hid & HID_USAGE_PAGE) != HID_UP_HAPTIC)
+ return;
+
+ haptic = hid_plugin_to_haptic(hdev);
+ if (unlikely(!haptic))
+ haptic = hid_haptic_connect(hdev);
+ if (IS_ERR(haptic))
+ return;
+
+ haptic->plugin->feature_mapping(hdev, haptic, field, usage);
}
-static inline
-int hid_haptic_input_configured(struct hid_device *hdev,
- struct hid_haptic_device *haptic,
- struct hid_input *hi)
+
+static inline bool hid_haptic_check_pressure_unit(struct hid_device *hdev, struct hid_input *hi,
+ struct hid_field *field)
{
- return -EOPNOTSUPP;
+ struct hid_haptic_device *haptic = hid_plugin_to_haptic(hdev);
+
+ if (IS_ERR_OR_NULL(haptic))
+ return false;
+
+ return haptic->plugin->check_pressure_unit(haptic, hi, field);
}
-static inline
-void hid_haptic_reset(struct hid_device *hdev, struct hid_haptic_device *haptic)
-{}
-static inline
-int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic,
- struct input_dev *dev)
+
+static inline int hid_haptic_input_mapping(struct hid_device *hdev, struct hid_input *hi,
+ struct hid_field *field, struct hid_usage *usage,
+ unsigned long **bit, int *max)
{
+ struct hid_haptic_device *haptic = hid_plugin_to_haptic(hdev);
+
+ if (IS_ERR_OR_NULL(haptic))
+ return 0;
+
+ if (usage->hid == HID_HP_MANUALTRIGGER) {
+ haptic->manual_trigger_report = field->report;
+ /* we don't really want to map these fields */
+ return -1;
+ }
+
return 0;
}
-static inline
-void hid_haptic_handle_press_release(struct hid_haptic_device *haptic) {}
-static inline
-bool hid_haptic_handle_input(struct hid_haptic_device *haptic)
+
+static inline int hid_haptic_input_configured(struct hid_device *hdev, struct hid_input *hi)
{
- return false;
+ struct hid_haptic_device *haptic = hid_plugin_to_haptic(hdev);
+ int ret;
+
+ if (IS_ERR_OR_NULL(haptic))
+ return -EOPNOTSUPP;
+
+ ret = haptic->plugin->input_configured(hdev, haptic, hi);
+ if (ret < 0)
+ hid_haptic_disconnect(hdev);
+
+ return ret;
+}
+
+static inline void hid_haptic_pressure_reset(struct hid_device *hdev)
+{
+ struct hid_haptic_device *haptic = hid_plugin_to_haptic(hdev);
+
+ if (IS_ERR_OR_NULL(haptic))
+ return;
+
+ haptic->pressure_sum = 0;
+}
+
+static inline void hid_haptic_pressure_increase(struct hid_device *hdev, __s32 pressure)
+{
+ struct hid_haptic_device *haptic = hid_plugin_to_haptic(hdev);
+
+ if (IS_ERR_OR_NULL(haptic))
+ return;
+
+ haptic->pressure_sum += pressure;
}
-static inline
-void hid_haptic_pressure_reset(struct hid_haptic_device *haptic) {}
-static inline
-void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
- __s32 pressure)
-{}
-#endif
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index a4d3536c7af2..e9a25a3bfa1b 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -20,6 +20,7 @@
#include <linux/hid.h>
#include <linux/hid-debug.h>
+#include "hid-haptic.h"
#include "hid-ids.h"
#define unk KEY_UNKNOWN
@@ -1353,6 +1354,17 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
}
break;
+ case HID_UP_HAPTIC: {
+ int ret = hid_haptic_input_mapping(device, hidinput, field, usage, &bit, &max);
+
+ if (ret > 0)
+ goto mapped;
+ if (ret < 0)
+ goto ignore;
+
+ break;
+ }
+
case HID_UP_HPVENDOR: /* Reported on a Dutch layout HP5308 */
set_bit(EV_REP, input->evbit);
switch (usage->hid & HID_USAGE) {
@@ -2054,6 +2066,8 @@ static void report_features(struct hid_device *hid)
hidinput_setup_battery(hid, HID_FEATURE_REPORT,
rep->field[i], false);
+ hid_haptic_feature_mapping(hid, rep->field[i], usage);
+
if (drv->feature_mapping)
drv->feature_mapping(hid, rep->field[i], usage);
}
@@ -2346,6 +2360,7 @@ int hidinput_connect(struct hid_device *hid, unsigned int connect_mask)
struct hid_driver *drv = hid->driver;
struct hid_report *report;
struct hid_input *next, *hidinput = NULL;
+ bool haptic_ff, driver_ff = false;
unsigned int application;
int i, k;
@@ -2409,20 +2424,42 @@ int hidinput_connect(struct hid_device *hid, unsigned int connect_mask)
hidinput_change_resolution_multipliers(hid);
+ haptic_ff = hid_haptic_input_configured(hid, NULL) >= 0;
+
list_for_each_entry_safe(hidinput, next, &hid->inputs, list) {
+ bool first = list_is_first(&hidinput->list, &hid->inputs);
+
if (drv->input_configured &&
drv->input_configured(hid, hidinput))
goto out_unwind;
+ if (first) {
+ driver_ff = hid_has_ff_input(hid) || !(connect_mask & HID_CONNECT_FF);
+ if (haptic_ff && driver_ff) {
+ hid_info(hid, "prefer driver's FF over haptic\n");
+ hid_haptic_disconnect(hid);
+ haptic_ff = false;
+ } else if (haptic_ff) {
+ /*
+ * Prefer hid-haptic over hid-pidff.
+ *
+ * Skip hid-pidff even if hid-haptic somehow fails
+ * to initialize, so that the choice is constant.
+ */
+ driver_ff = true;
+ }
+ }
+
+ if (haptic_ff)
+ haptic_ff = hid_haptic_input_configured(hid, hidinput) >= 0;
+
if (!hidinput_has_been_populated(hidinput)) {
/* no need to register an input device not populated */
hidinput_cleanup_hidinput(hid, hidinput);
continue;
}
- if (list_is_first(&hidinput->list, &hid->inputs) &&
- (connect_mask & HID_CONNECT_FF) && hid->ff_init &&
- !hid_has_ff_input(hid))
+ if (first && !driver_ff && hid->ff_init)
hid->ff_init(hid);
if (input_register_device(hidinput->input))
@@ -2445,6 +2482,13 @@ int hidinput_connect(struct hid_device *hid, unsigned int connect_mask)
/* unwind the ones we already registered */
hidinput_disconnect(hid);
+ /*
+ * On failure, the HID device may still keep connected to the HID
+ * driver. To prevent holding useless resources during runtime, don't
+ * wait until driver removal and disconnect hid-haptic early.
+ */
+ hid_haptic_disconnect(hid);
+
return -1;
}
EXPORT_SYMBOL_GPL(hidinput_connect);
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index e017eff9b784..b8299a1a2bb9 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -173,7 +173,6 @@ struct mt_report_data {
struct mt_device {
struct mt_class mtclass; /* our mt device class */
struct timer_list release_timer; /* to release sticky fingers */
- struct hid_haptic_device *haptic; /* haptic related configuration */
struct hid_device *hdev; /* hid_device we're attached to */
unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_RUNNING) */
unsigned long *active_slots; /* bitmap of slots with an active
@@ -604,8 +603,6 @@ static void mt_feature_mapping(struct hid_device *hdev,
mt_get_feature(hdev, field->report);
break;
}
-
- hid_haptic_feature_mapping(hdev, td->haptic, field, usage);
}
static void set_abs(struct input_dev *input, unsigned int code,
@@ -961,9 +958,7 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
case HID_DG_TIPPRESSURE:
set_abs(hi->input, ABS_MT_PRESSURE, field,
cls->sn_pressure);
- td->is_haptic_touchpad =
- hid_haptic_check_pressure_unit(td->haptic,
- hi, field);
+ td->is_haptic_touchpad = hid_haptic_check_pressure_unit(hdev, hi, field);
MT_STORE_FIELD(p);
return 1;
case HID_DG_SCANTIME:
@@ -1074,6 +1069,8 @@ static void mt_release_pending_palms(struct mt_device *td,
static void mt_sync_frame(struct mt_device *td, struct mt_application *app,
struct input_dev *input)
{
+ struct hid_device *hdev = td->hdev;
+
if (app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS)
input_event(input, EV_KEY, BTN_LEFT, app->left_button_state);
@@ -1085,8 +1082,8 @@ static void mt_sync_frame(struct mt_device *td, struct mt_application *app,
app->num_received = 0;
app->left_button_state = 0;
- if (td->is_haptic_touchpad && hid_haptic_connected_to_input(td->haptic, input))
- hid_haptic_pressure_reset(td->haptic);
+ if (td->is_haptic_touchpad && hid_haptic_connected_to_input(hdev, input))
+ hid_haptic_pressure_reset(hdev);
}
static int mt_compute_timestamp(struct mt_application *app, __s32 value)
@@ -1238,8 +1235,8 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input,
minor = minor >> 1;
}
- if (td->is_haptic_touchpad && hid_haptic_connected_to_input(td->haptic, input))
- hid_haptic_pressure_increase(td->haptic, *slot->p);
+ if (td->is_haptic_touchpad && hid_haptic_connected_to_input(hdev, input))
+ hid_haptic_pressure_increase(hdev, *slot->p);
x = hdev->quirks & HID_QUIRK_X_INVERT ?
input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->x :
@@ -1441,7 +1438,7 @@ static int mt_touch_input_configured(struct hid_device *hdev,
if (cls->is_indirect)
app->mt_flags |= INPUT_MT_POINTER;
- if (td->is_haptic_touchpad && hid_haptic_connected_to_input(td->haptic, input))
+ if (td->is_haptic_touchpad && hid_haptic_connected_to_input(hdev, input))
app->mt_flags |= INPUT_MT_TOTAL_FORCE;
if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
@@ -1490,7 +1487,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
struct mt_device *td = hid_get_drvdata(hdev);
struct mt_application *application;
struct mt_report_data *rdata;
- int ret;
rdata = mt_find_report_data(td, field->report);
if (!rdata) {
@@ -1553,11 +1549,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
if (field->physical == HID_DG_STYLUS)
hi->application = HID_DG_STYLUS;
- ret = hid_haptic_input_mapping(hdev, td->haptic, hi, field, usage, bit,
- max);
- if (ret != 0)
- return ret;
-
/* let hid-core decide for the others */
return 0;
}
@@ -1954,9 +1945,6 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
struct hid_report *report;
int ret;
- if (!td->is_haptic_touchpad)
- td->is_haptic_touchpad = !hid_haptic_input_configured(hdev, td->haptic, hi);
-
list_for_each_entry(report, &hi->reports, hidinput_list) {
rdata = mt_find_report_data(td, report);
if (!rdata) {
@@ -2125,11 +2113,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
dev_err(&hdev->dev, "cannot allocate multitouch data\n");
return -ENOMEM;
}
- td->haptic = devm_kzalloc_obj(&hdev->dev, *(td->haptic));
- if (!td->haptic)
- return -ENOMEM;
- td->haptic->hdev = hdev;
td->hdev = hdev;
td->mtclass = *mtclass;
td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
@@ -2198,9 +2182,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
- if (!td->is_haptic_touchpad)
- devm_kfree(&hdev->dev, td->haptic);
-
return 0;
}
diff --git a/drivers/hid/hid-plugin.c b/drivers/hid/hid-plugin.c
index f93753d3ee12..b4de74e70021 100644
--- a/drivers/hid/hid-plugin.c
+++ b/drivers/hid/hid-plugin.c
@@ -22,6 +22,9 @@
#include "hid-plugin.h"
static const char * const hid_plugin_mod_names[NR_HID_PLUGINS] = {
+#if IS_MODULE(CONFIG_HID_HAPTIC)
+ [HID_PLUGIN_HAPTIC] = "hid-haptic",
+#endif
};
static struct hid_plugin __rcu *hid_plugins[NR_HID_PLUGINS];
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 2444aabcb604..585b3336f4a7 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -676,6 +676,12 @@ struct hid_ll_driver;
enum hid_plugin_id {
HID_PLUGIN_DISABLED = -1,
+#if IS_ENABLED(CONFIG_HID_HAPTIC)
+ HID_PLUGIN_HAPTIC,
+#else
+#define HID_PLUGIN_HAPTIC HID_PLUGIN_DISABLED
+#endif
+
NR_HID_PLUGINS,
};
@@ -765,7 +771,7 @@ struct hid_device {
struct hid_bpf bpf; /* hid-bpf data */
#endif /* CONFIG_HID_BPF */
- struct hid_plugin_private *plugins[NR_HID_PLUGINS];
+ void *plugins[NR_HID_PLUGINS];
};
void hiddev_free(struct kref *ref);
--
2.55.0