aboutsummaryrefslogtreecommitdiff
path: root/hid-tmt248.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-02-09 11:46:32 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2023-02-09 11:46:32 +0200
commit3953b2e7a24e2cf3926a0038a91acf8d9f9ee887 (patch)
tree3c60298711629fd1e3a6857537b705574baa9576 /hid-tmt248.c
parentae9c87774836124e6303b5a7321d9ea0ddf5ab85 (diff)
downloadhid-tmff2-3953b2e7a24e2cf3926a0038a91acf8d9f9ee887.tar.gz
hid-tmff2-3953b2e7a24e2cf3926a0038a91acf8d9f9ee887.zip
add open_mode module parameter
+ open_mode = 1 (default) sends out mode switch commands on open/close, open_mode = 0 sets the wheel into 'open' mode once at init
Diffstat (limited to 'hid-tmt248.c')
-rw-r--r--hid-tmt248.c149
1 files changed, 87 insertions, 62 deletions
diff --git a/hid-tmt248.c b/hid-tmt248.c
index e241301..606cff5 100644
--- a/hid-tmt248.c
+++ b/hid-tmt248.c
@@ -163,56 +163,6 @@ err:
return ret;
}
-int t248_wheel_init(struct tmff2_device_entry *tmff2)
-{
- struct t300rs_device_entry *t248 = kzalloc(sizeof(struct t300rs_device_entry), GFP_KERNEL);
- struct list_head *report_list;
- int ret;
-
-
- if (!t248) {
- ret = -ENOMEM;
- goto t248_err;
- }
-
- t248->hdev = tmff2->hdev;
- t248->input_dev = tmff2->input_dev;
- t248->usbdev = to_usb_device(tmff2->hdev->dev.parent->parent);
- t248->buffer_length = T248_BUFFER_LENGTH;
-
- t248->send_buffer = kzalloc(t248->buffer_length, GFP_KERNEL);
- if (!t248->send_buffer) {
- ret = -ENOMEM;
- goto send_err;
- }
-
- report_list = &t248->hdev->report_enum[HID_OUTPUT_REPORT].report_list;
- 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;
-
- /* everything went OK */
- tmff2->data = t248;
- tmff2->params = t248_params;
- tmff2->max_effects = T248_MAX_EFFECTS;
- memcpy(tmff2->supported_effects, t248_effects, sizeof(t248_effects));
-
- hid_info(t248->hdev, "force feedback for T248\n");
- return 0;
-
-interrupt_err:
-send_err:
- kfree(t248);
-t248_err:
- hid_err(tmff2->hdev, "failed initializing T248\n");
- return ret;
-}
-
int t248_wheel_destroy(void *data)
{
struct t300rs_device_entry *t300rs = data;
@@ -242,43 +192,118 @@ int t248_set_range(void *data, uint16_t value)
return t300rs_set_range(data, value);
}
-static int t248_open(void *data)
+static int t248_send_open(struct t300rs_device_entry *t248)
{
- struct t300rs_device_entry *t248 = data;
-
- if (!t248)
- return -ENODEV;
-
+ int r1, r2;
t248->send_buffer[0] = 0x01;
t248->send_buffer[1] = 0x04;
- t300rs_send_int(t248);
+ if ((r1 = t300rs_send_int(t248)))
+ return r1;
t248->send_buffer[0] = 0x01;
t248->send_buffer[1] = 0x05;
- t300rs_send_int(t248);
+ if ((r2 = t300rs_send_int(t248)))
+ return r2;
- return t248->open(t248->input_dev);
+ return 0;
}
-static int t248_close(void *data)
+static int t248_open(void *data, int open_mode)
{
struct t300rs_device_entry *t248 = data;
if (!t248)
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)
+{
+ int r1, r2;
t248->send_buffer[0] = 0x01;
t248->send_buffer[1] = 0x05;
- t300rs_send_int(t248);
+ if ((r1 = t300rs_send_int(t248)))
+ return r1;
t248->send_buffer[0] = 0x01;
t248->send_buffer[1] = 0x00;
- t300rs_send_int(t248);
+ if ((r2 = t300rs_send_int(t248)))
+ return r2;
+
+ return 0;
+}
+
+static int t248_close(void *data, int open_mode)
+{
+ struct t300rs_device_entry *t248 = data;
+
+ if (!t248)
+ return -ENODEV;
+
+ if (open_mode)
+ t248_send_close(t248);
t248->close(t248->input_dev);
return 0;
}
+int t248_wheel_init(struct tmff2_device_entry *tmff2, int open_mode)
+{
+ struct t300rs_device_entry *t248 = kzalloc(sizeof(struct t300rs_device_entry), GFP_KERNEL);
+ struct list_head *report_list;
+ int ret;
+
+
+ if (!t248) {
+ ret = -ENOMEM;
+ goto t248_err;
+ }
+
+ t248->hdev = tmff2->hdev;
+ t248->input_dev = tmff2->input_dev;
+ t248->usbdev = to_usb_device(tmff2->hdev->dev.parent->parent);
+ t248->buffer_length = T248_BUFFER_LENGTH;
+
+ t248->send_buffer = kzalloc(t248->buffer_length, GFP_KERNEL);
+ if (!t248->send_buffer) {
+ ret = -ENOMEM;
+ goto send_err;
+ }
+
+ report_list = &t248->hdev->report_enum[HID_OUTPUT_REPORT].report_list;
+ 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;
+
+ /* everything went OK */
+ tmff2->data = t248;
+ tmff2->params = t248_params;
+ tmff2->max_effects = T248_MAX_EFFECTS;
+ memcpy(tmff2->supported_effects, t248_effects, sizeof(t248_effects));
+
+ if (!open_mode)
+ t248_send_open(t248);
+
+ hid_info(t248->hdev, "force feedback for T248\n");
+ return 0;
+
+interrupt_err:
+send_err:
+ kfree(t248);
+t248_err:
+ hid_err(tmff2->hdev, "failed initializing T248\n");
+ return ret;
+}
+
static __u8 *t248_wheel_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{