From 66e522e26549afab26d032e900ae9f6576c83b9d Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 26 Jan 2026 18:21:43 +0200 Subject: Revert "use on_hid_hw_open instead of input_dev->open" This reverts commit c26573d77369c042dc2b9a881a7f2ff88ddc0dd9. + `on_hid_hw_open` is apparently new enough that common distros don't have it yet, so let's wait a few years and try again. The old method works well enough and if not, just set `open_mode=0`. --- src/hid-tmff2.c | 36 +++++++++++++++++++++--------------- src/hid-tmff2.h | 11 +++++++---- src/tmt248/hid-tmt248.c | 17 +++++++++++++---- src/tmt300rs/hid-tmt300rs.c | 16 ++++++++++++---- src/tmtspc/hid-tmtspc.c | 16 ++++++++++++---- src/tmtsxw/hid-tmtsxw.c | 16 ++++++++++++---- src/tmtx/hid-tmtx.c | 16 ++++++++++++---- 7 files changed, 89 insertions(+), 39 deletions(-) diff --git a/src/hid-tmff2.c b/src/hid-tmff2.c index 3b3c0cc..162a30a 100644 --- a/src/hid-tmff2.c +++ b/src/hid-tmff2.c @@ -486,26 +486,24 @@ static int tmff2_play(struct input_dev *dev, int effect_id, int value) return 0; } -static void tmff2_open(struct hid_device *hdev) +static int tmff2_open(struct input_dev *dev) { - struct tmff2_device_entry *tmff2 = hid_get_drvdata(hdev); - - pr_err("entering tmff2_open\n"); + struct tmff2_device_entry *tmff2 = tmff2_from_input(dev); - if (!tmff2) { - pr_err("no device entry\n"); - return; - } + if (!tmff2) + return -ENODEV; if (tmff2->open) return tmff2->open(tmff2->data, open_mode); + + hid_err(tmff2->hdev, "no open callback set\n"); + return -EINVAL; } -static void tmff2_close(struct hid_device *hdev) +static void tmff2_close(struct input_dev *dev) { - struct tmff2_device_entry *tmff2 = hid_get_drvdata(hdev); + struct tmff2_device_entry *tmff2 = tmff2_from_input(dev); - pr_err("entering tmff2_close\n"); if (!tmff2) return; @@ -514,8 +512,12 @@ static void tmff2_close(struct hid_device *hdev) * time */ cancel_delayed_work_sync(&tmff2->work); - if (tmff2->close) - return tmff2->close(tmff2->data, open_mode); + if (tmff2->close) { + tmff2->close(tmff2->data, open_mode); + return; + } + + hid_err(tmff2->hdev, "no close callback set\n"); } static int tmff2_create_files(struct tmff2_device_entry *tmff2) @@ -632,6 +634,12 @@ static int tmff2_wheel_init(struct tmff2_device_entry *tmff2) ff->upload = tmff2_upload; ff->playback = tmff2_play; + if (tmff2->open) + tmff2->input_dev->open = tmff2_open; + + if (tmff2->close) + tmff2->input_dev->close = tmff2_close; + /* set defaults wherever possible */ if (tmff2->set_gain) { ff->set_gain = tmff2_set_gain; @@ -817,8 +825,6 @@ static struct hid_driver tmff2_driver = { .probe = tmff2_probe, .remove = tmff2_remove, .report_fixup = tmff2_report_fixup, - .on_hid_hw_open = tmff2_open, - .on_hid_hw_close = tmff2_close }; module_hid_driver(tmff2_driver); diff --git a/src/hid-tmff2.h b/src/hid-tmff2.h index 213bebe..6ad1d82 100644 --- a/src/hid-tmff2.h +++ b/src/hid-tmff2.h @@ -82,8 +82,8 @@ struct tmff2_device_entry { int (*wheel_destroy)(void *data); /* optional callbacks */ - void (*open)(void *data, int); - void (*close)(void *data, int); + int (*open)(void *data, int); + int (*close)(void *data, int); int (*set_gain)(void *data, uint16_t gain); int (*set_range)(void *data, uint16_t range); /* switch_mode is required to not do anything if we're alredy in the @@ -128,6 +128,9 @@ struct t300rs_device_entry { struct hid_field *ff_field; struct usb_device *usbdev; + int (*open)(struct input_dev *dev); + void (*close)(struct input_dev *dev); + int mode; int attachment; u8 buffer_length; @@ -139,8 +142,8 @@ int t300rs_upload_effect(void *, const struct tmff2_effect_state *); int t300rs_update_effect(void *, const struct tmff2_effect_state *); int t300rs_stop_effect(void *, const struct tmff2_effect_state *); -void t300rs_open(void *, int); -void t300rs_close(void *, int); +int t300rs_open(void *, int); +int t300rs_close(void *, int); int t300rs_set_gain(void *, uint16_t); int t300rs_set_range(void *, uint16_t); int t300rs_set_autocenter(void *, uint16_t); diff --git a/src/tmt248/hid-tmt248.c b/src/tmt248/hid-tmt248.c index 4c42264..9ac43d9 100644 --- a/src/tmt248/hid-tmt248.c +++ b/src/tmt248/hid-tmt248.c @@ -208,15 +208,17 @@ static int t248_send_open(struct t300rs_device_entry *t248) return 0; } -static void t248_open(void *data, int open_mode) +static int t248_open(void *data, int open_mode) { struct t300rs_device_entry *t248 = data; if (!t248) - return; + return -ENODEV; if (open_mode) t248_send_open(t248); + + return t248->open(t248->input_dev); } static int t248_send_close(struct t300rs_device_entry *t248) @@ -235,14 +237,18 @@ static int t248_send_close(struct t300rs_device_entry *t248) return 0; } -static void t248_close(void *data, int open_mode) +static int t248_close(void *data, int open_mode) { struct t300rs_device_entry *t248 = data; + if (!t248) - return; + return -ENODEV; if (open_mode) t248_send_close(t248); + + t248->close(t248->input_dev); + return 0; } static int t248_wheel_init(struct tmff2_device_entry *tmff2, int open_mode) @@ -273,6 +279,9 @@ static int t248_wheel_init(struct tmff2_device_entry *tmff2, int open_mode) t248->report = list_entry(report_list->next, struct hid_report, list); t248->ff_field = t248->report->field[0]; + t248->open = t248->input_dev->open; + t248->close = t248->input_dev->close; + if ((ret = t248_interrupts(t248))) goto interrupt_err; diff --git a/src/tmt300rs/hid-tmt300rs.c b/src/tmt300rs/hid-tmt300rs.c index 689466f..00eecee 100644 --- a/src/tmt300rs/hid-tmt300rs.c +++ b/src/tmt300rs/hid-tmt300rs.c @@ -1287,26 +1287,31 @@ static int t300rs_send_close(struct t300rs_device_entry *t300rs) return t300rs_send_int(t300rs); } -void t300rs_open(void *data, int open_mode) +int t300rs_open(void *data, int open_mode) { struct t300rs_device_entry *t300rs = data; if (!t300rs) - return; + return -ENODEV; if (open_mode && t300rs_send_open(t300rs)) hid_warn(t300rs->hdev, "failed sending open command\n"); + + return t300rs->open(t300rs->input_dev); } -void t300rs_close(void *data, int open_mode) +int t300rs_close(void *data, int open_mode) { struct t300rs_device_entry *t300rs = data; int ret = 0; if (!t300rs) - return; + return -ENODEV; if (open_mode && (ret = t300rs_send_close(t300rs))) hid_warn(t300rs->hdev, "failed sending close command\n"); + + t300rs->close(t300rs->input_dev); + return ret; } static int t300rs_check_firmware(struct t300rs_device_entry *t300rs) @@ -1464,6 +1469,9 @@ static int t300rs_wheel_init(struct tmff2_device_entry *tmff2, int open_mode) t300rs->report = list_entry(report_list->next, struct hid_report, list); t300rs->ff_field = t300rs->report->field[0]; + t300rs->open = t300rs->input_dev->open; + t300rs->close = t300rs->input_dev->close; + /* TODO: PS4 advanced mode? */ alt_mode = (t300rs->mode = (t300rs->hdev->product == TMT300RS_PS3_ADV_ID)); if ((t300rs->attachment = t300rs_get_attachment(t300rs)) < 0) diff --git a/src/tmtspc/hid-tmtspc.c b/src/tmtspc/hid-tmtspc.c index 031358a..a51ec01 100644 --- a/src/tmtspc/hid-tmtspc.c +++ b/src/tmtspc/hid-tmtspc.c @@ -197,15 +197,17 @@ static int tspc_send_open(struct t300rs_device_entry *tspc) return 0; } -static void tspc_open(void *data, int open_mode) +static int tspc_open(void *data, int open_mode) { struct t300rs_device_entry *tspc = data; if (!tspc) - return; + return -ENODEV; if (open_mode) tspc_send_open(tspc); + + return tspc->open(tspc->input_dev); } static int tspc_send_close(struct t300rs_device_entry *tspc) @@ -224,15 +226,18 @@ static int tspc_send_close(struct t300rs_device_entry *tspc) return 0; } -static void tspc_close(void *data, int open_mode) +static int tspc_close(void *data, int open_mode) { struct t300rs_device_entry *tspc = data; if (!tspc) - return; + return -ENODEV; if (open_mode) tspc_send_close(tspc); + + tspc->close(tspc->input_dev); + return 0; } static int tspc_wheel_init(struct tmff2_device_entry *tmff2, int open_mode) @@ -263,6 +268,9 @@ static int tspc_wheel_init(struct tmff2_device_entry *tmff2, int open_mode) tspc->report = list_entry(report_list->next, struct hid_report, list); tspc->ff_field = tspc->report->field[0]; + tspc->open = tspc->input_dev->open; + tspc->close = tspc->input_dev->close; + if ((ret = tspc_interrupts(tspc))) goto interrupt_err; diff --git a/src/tmtsxw/hid-tmtsxw.c b/src/tmtsxw/hid-tmtsxw.c index ac44bdb..b8ee1fd 100644 --- a/src/tmtsxw/hid-tmtsxw.c +++ b/src/tmtsxw/hid-tmtsxw.c @@ -196,15 +196,17 @@ static int tsxw_send_open(struct t300rs_device_entry *tsxw) return 0; } -static void tsxw_open(void *data, int open_mode) +static int tsxw_open(void *data, int open_mode) { struct t300rs_device_entry *tsxw = data; if (!tsxw) - return; + return -ENODEV; if (open_mode) tsxw_send_open(tsxw); + + return tsxw->open(tsxw->input_dev); } static int tsxw_send_close(struct t300rs_device_entry *tsxw) @@ -223,15 +225,18 @@ static int tsxw_send_close(struct t300rs_device_entry *tsxw) return 0; } -static void tsxw_close(void *data, int open_mode) +static int tsxw_close(void *data, int open_mode) { struct t300rs_device_entry *tsxw = data; if (!tsxw) - return; + return -ENODEV; if (open_mode) tsxw_send_close(tsxw); + + tsxw->close(tsxw->input_dev); + return 0; } static int tsxw_wheel_init(struct tmff2_device_entry *tmff2, int open_mode) @@ -262,6 +267,9 @@ static int tsxw_wheel_init(struct tmff2_device_entry *tmff2, int open_mode) tsxw->report = list_entry(report_list->next, struct hid_report, list); tsxw->ff_field = tsxw->report->field[0]; + tsxw->open = tsxw->input_dev->open; + tsxw->close = tsxw->input_dev->close; + if ((ret = tsxw_interrupts(tsxw))) goto interrupt_err; diff --git a/src/tmtx/hid-tmtx.c b/src/tmtx/hid-tmtx.c index f1f1b32..857886c 100644 --- a/src/tmtx/hid-tmtx.c +++ b/src/tmtx/hid-tmtx.c @@ -196,15 +196,17 @@ static int tx_send_open(struct t300rs_device_entry *tx) return 0; } -static void tx_open(void *data, int open_mode) +static int tx_open(void *data, int open_mode) { struct t300rs_device_entry *tx = data; if (!tx) - return; + return -ENODEV; if (open_mode) tx_send_open(tx); + + return tx->open(tx->input_dev); } static int tx_send_close(struct t300rs_device_entry *tx) @@ -223,15 +225,18 @@ static int tx_send_close(struct t300rs_device_entry *tx) return 0; } -static void tx_close(void *data, int open_mode) +static int tx_close(void *data, int open_mode) { struct t300rs_device_entry *tx = data; if (!tx) - return; + return -ENODEV; if (open_mode) tx_send_close(tx); + + tx->close(tx->input_dev); + return 0; } static int tx_wheel_init(struct tmff2_device_entry *tmff2, int open_mode) @@ -262,6 +267,9 @@ static int tx_wheel_init(struct tmff2_device_entry *tmff2, int open_mode) tx->report = list_entry(report_list->next, struct hid_report, list); tx->ff_field = tx->report->field[0]; + tx->open = tx->input_dev->open; + tx->close = tx->input_dev->close; + if ((ret = tx_interrupts(tx))) goto interrupt_err; -- cgit v1.3