aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hid-tmff2.c11
-rw-r--r--hid-tmff2.h10
-rw-r--r--hid-tmt248.c149
-rw-r--r--hid-tmt300rs.c44
4 files changed, 129 insertions, 85 deletions
diff --git a/hid-tmff2.c b/hid-tmff2.c
index e726123..f53a34a 100644
--- a/hid-tmff2.c
+++ b/hid-tmff2.c
@@ -5,6 +5,11 @@
#include "hid-tmff2.h"
+int open_mode = 1;
+module_param(open_mode, int, 0660);
+MODULE_PARM_DESC(open_mode,
+ "Whether to send mode change commands on open/close");
+
int timer_msecs = DEFAULT_TIMER_PERIOD;
module_param(timer_msecs, int, 0660);
MODULE_PARM_DESC(timer_msecs,
@@ -439,7 +444,7 @@ static int tmff2_open(struct input_dev *dev)
return -ENODEV;
if (tmff2->open)
- return tmff2->open(tmff2->data);
+ return tmff2->open(tmff2->data, open_mode);
hid_err(tmff2->hdev, "no open callback set\n");
return -EINVAL;
@@ -456,7 +461,7 @@ static void tmff2_close(struct input_dev *dev)
cancel_delayed_work_sync(&tmff2->work);
if (tmff2->close) {
- tmff2->close(tmff2->data);
+ tmff2->close(tmff2->data, open_mode);
return;
}
@@ -538,7 +543,7 @@ static int tmff2_wheel_init(struct tmff2_device_entry *tmff2)
INIT_DELAYED_WORK(&tmff2->work, tmff2_work_handler);
/* get parameters etc from backend */
- if ((ret = tmff2->wheel_init(tmff2)))
+ if ((ret = tmff2->wheel_init(tmff2, open_mode)))
goto err;
diff --git a/hid-tmff2.h b/hid-tmff2.h
index d5de938..8b7842e 100644
--- a/hid-tmff2.h
+++ b/hid-tmff2.h
@@ -78,12 +78,12 @@ struct tmff2_device_entry {
int (*update_effect)(void *data, struct tmff2_effect_state *state);
int (*stop_effect)(void *data, struct tmff2_effect_state *state);
- int (*wheel_init)(struct tmff2_device_entry *tmff2);
+ int (*wheel_init)(struct tmff2_device_entry *tmff2, int open_mode);
int (*wheel_destroy)(void *data);
/* optional callbacks */
- int (*open)(void *data);
- int (*close)(void *data);
+ 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 has to not do anything if we're alredy in the specified
@@ -132,8 +132,8 @@ int t300rs_upload_effect(void *, struct tmff2_effect_state *);
int t300rs_update_effect(void *, struct tmff2_effect_state *);
int t300rs_stop_effect(void *, struct tmff2_effect_state *);
-int t300rs_open(void *);
-int t300rs_close(void *);
+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/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)
{
diff --git a/hid-tmt300rs.c b/hid-tmt300rs.c
index ad9bf4b..48d029d 100644
--- a/hid-tmt300rs.c
+++ b/hid-tmt300rs.c
@@ -1414,41 +1414,52 @@ err:
return ret;
}
-int t300rs_open(void *data)
+static int t300rs_send_open(struct t300rs_device_entry *t300rs)
{
- struct t300rs_device_entry *t300rs = data;
struct __packed t300rs_packet_open {
struct t300rs_setup_header header;
} *open_packet;
- if (!t300rs)
- return -ENODEV;
-
open_packet = (struct t300rs_packet_open *)t300rs->send_buffer;
open_packet->header.cmd = 0x01;
open_packet->header.code = 0x05;
- if (t300rs_send_int(t300rs))
+ return t300rs_send_int(t300rs);
+}
+
+static int t300rs_send_close(struct t300rs_device_entry *t300rs)
+{
+ struct __packed t300rs_packet_open {
+ struct t300rs_setup_header header;
+ } *open_packet;
+
+ open_packet = (struct t300rs_packet_open *)t300rs->send_buffer;
+ open_packet->header.cmd = 0x01;
+
+ return t300rs_send_int(t300rs);
+}
+
+int t300rs_open(void *data, int open_mode)
+{
+ struct t300rs_device_entry *t300rs = data;
+ if (!t300rs)
+ return -ENODEV;
+
+ if (open_mode && t300rs_send_open(t300rs))
hid_warn(t300rs->hdev, "failed sending open command\n");
return t300rs->open(t300rs->input_dev);
}
-int t300rs_close(void *data)
+int t300rs_close(void *data, int open_mode)
{
struct t300rs_device_entry *t300rs = data;
- struct __packed t300rs_packet_close {
- struct t300rs_setup_header header;
- } *close_packet;
int ret;
if (!t300rs)
return -ENODEV;
- close_packet = (struct t300rs_packet_close *)t300rs->send_buffer;
- close_packet->header.cmd = 0x01;
-
- if ((ret = t300rs_send_int(t300rs)))
+ if (open_mode && (ret = t300rs_send_close(t300rs)))
hid_warn(t300rs->hdev, "failed sending close command\n");
t300rs->close(t300rs->input_dev);
@@ -1577,7 +1588,7 @@ out:
return ret;
}
-static int t300rs_wheel_init(struct tmff2_device_entry *tmff2)
+static int t300rs_wheel_init(struct tmff2_device_entry *tmff2, int open_mode)
{
struct t300rs_device_entry *t300rs = kzalloc(sizeof(struct t300rs_device_entry), GFP_KERNEL);
struct list_head *report_list;
@@ -1626,6 +1637,9 @@ static int t300rs_wheel_init(struct tmff2_device_entry *tmff2)
tmff2->max_effects = T300RS_MAX_EFFECTS;
memcpy(tmff2->supported_effects, t300rs_effects, sizeof(t300rs_effects));
+ if (!open_mode)
+ t300rs_send_open(t300rs);
+
hid_info(t300rs->hdev, "force feedback for T300RS\n");
return 0;