aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-03-20 17:48:19 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2022-03-20 17:48:19 +0200
commit28d0a3f76748a2555fc1417216ed51112dba945c (patch)
treefbf2b5618259a8404284bf14d3a290cfea03f9ec
parent0dcf31ff3fe8eb9bc079d94242253290a30eb97e (diff)
downloadhid-tmff2-28d0a3f76748a2555fc1417216ed51112dba945c.tar.gz
hid-tmff2-28d0a3f76748a2555fc1417216ed51112dba945c.zip
merge headers into one
-rw-r--r--hid-tmff2.c35
-rw-r--r--hid-tmff2.h21
-rw-r--r--hid-tmt300rs.c35
3 files changed, 49 insertions, 42 deletions
diff --git a/hid-tmff2.c b/hid-tmff2.c
index 811d75b..2e7221f 100644
--- a/hid-tmff2.c
+++ b/hid-tmff2.c
@@ -1,9 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
#include <linux/workqueue.h>
#include <linux/module.h>
#include <linux/hid.h>
-#define TMFF2_MAIN
#include "hid-tmff2.h"
-#include "hid-tmt300rs.h"
+
int timer_msecs = DEFAULT_TIMER_PERIOD;
module_param(timer_msecs, int, 0660);
@@ -421,35 +421,35 @@ static int tmff2_create_files(struct tmff2_device_entry *tmff2)
int ret;
/* could use short circuiting but this is more explicit */
- if (tmff2->params & HAS_ALT_MODE) {
+ if (tmff2->params & PARAM_ALT_MODE) {
if ((ret = device_create_file(dev, &dev_attr_alt_mode))) {
hid_err(tmff2->hdev, "unable to create sysfs for alt_mode\n");
goto alt_err;
}
}
- if (tmff2->params & HAS_RANGE) {
+ if (tmff2->params & PARAM_RANGE) {
if ((ret = device_create_file(dev, &dev_attr_range))) {
hid_warn(tmff2->hdev, "unable to create sysfs for range\n");
goto range_err;
}
}
- if (tmff2->params & HAS_SPRING_LEVEL) {
+ if (tmff2->params & PARAM_SPRING_LEVEL) {
if ((ret = device_create_file(dev, &dev_attr_spring_level))) {
hid_warn(tmff2->hdev, "unable to create sysfs for spring_level\n");
goto spring_err;
}
}
- if (tmff2->params & HAS_DAMPER_LEVEL) {
+ if (tmff2->params & PARAM_DAMPER_LEVEL) {
if ((ret = device_create_file(dev, &dev_attr_damper_level))) {
hid_warn(tmff2->hdev, "unable to create sysfs for damper_level\n");
goto damper_err;
}
}
- if (tmff2->params & HAS_FRICTION_LEVEL) {
+ if (tmff2->params & PARAM_FRICTION_LEVEL) {
if ((ret = device_create_file(dev, &dev_attr_friction_level))) {
hid_warn(tmff2->hdev, "unable to create sysfs for friction_level\n");
goto friction_err;
@@ -545,12 +545,13 @@ static int tmff2_probe(struct hid_device *hdev, const struct hid_device_id *id)
switch (tmff2->hdev->product) {
/* t300rs */
- case 0xb66e:
- case 0xb66f:
- case 0xb66d:
+ case TMT300RS_PS3_NORM_ID:
+ case TMT300RS_PS3_ADV_ID:
+ case TMT300RS_PS4_NORM_ID:
if ((ret = t300rs_populate_api(tmff2)))
goto wheel_err;
break;
+
default:
ret = -ENODEV;
goto wheel_err;
@@ -609,16 +610,16 @@ static void tmff2_remove(struct hid_device *hdev)
cancel_delayed_work_sync(&tmff2->work);
dev = &tmff2->hdev->dev;
- if (tmff2->params & HAS_DAMPER_LEVEL)
+ if (tmff2->params & PARAM_DAMPER_LEVEL)
device_remove_file(dev, &dev_attr_damper_level);
- if (tmff2->params & HAS_SPRING_LEVEL)
+ if (tmff2->params & PARAM_SPRING_LEVEL)
device_remove_file(dev, &dev_attr_spring_level);
- if (tmff2->params & HAS_RANGE)
+ if (tmff2->params & PARAM_RANGE)
device_remove_file(dev, &dev_attr_range);
- if (tmff2->params & HAS_ALT_MODE)
+ if (tmff2->params & PARAM_ALT_MODE)
device_remove_file(dev, &dev_attr_alt_mode);
tmff2->wheel_destroy(tmff2->data);
@@ -630,9 +631,9 @@ static void tmff2_remove(struct hid_device *hdev)
static const struct hid_device_id tmff2_devices[] = {
/* t300rs and variations */
- {HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb66e)},
- {HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb66f)},
- {HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb66d)},
+ {HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, TMT300RS_PS3_NORM_ID)},
+ {HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, TMT300RS_PS3_ADV_ID)},
+ {HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, TMT300RS_PS4_NORM_ID)},
{}
};
MODULE_DEVICE_TABLE(hid, tmff2_devices);
diff --git a/hid-tmff2.h b/hid-tmff2.h
index 1585649..d59104a 100644
--- a/hid-tmff2.h
+++ b/hid-tmff2.h
@@ -6,14 +6,12 @@
#include <linux/ktime.h>
#include <linux/input.h>
-#ifndef TMFF2_MAIN
extern int timer_msecs;
extern int spring_level;
extern int damper_level;
extern int friction_level;
extern int range;
extern int alt_mode;
-#endif
#define USB_VENDOR_ID_THRUSTMASTER 0x044f
@@ -23,7 +21,7 @@ extern int alt_mode;
* space out the interrupts so that they all leave at regular intervals, but
* for now this is good enough, go slow enough that everything works.
*/
-#define DEFAULT_TIMER_PERIOD 8
+#define DEFAULT_TIMER_PERIOD 8
#define FF_EFFECT_QUEUE_UPLOAD 0
#define FF_EFFECT_QUEUE_START 1
@@ -31,11 +29,11 @@ extern int alt_mode;
#define FF_EFFECT_QUEUE_UPDATE 3
#define FF_EFFECT_PLAYING 4
-#define HAS_SPRING_LEVEL (1 << 0)
-#define HAS_DAMPER_LEVEL (1 << 1)
-#define HAS_FRICTION_LEVEL (1 << 2)
-#define HAS_RANGE (1 << 3)
-#define HAS_ALT_MODE (1 << 4)
+#define PARAM_SPRING_LEVEL (1 << 0)
+#define PARAM_DAMPER_LEVEL (1 << 1)
+#define PARAM_FRICTION_LEVEL (1 << 2)
+#define PARAM_RANGE (1 << 3)
+#define PARAM_ALT_MODE (1 << 4)
#undef fixp_sin16
#define fixp_sin16(v) (((v % 360) > 180) ?\
@@ -91,4 +89,11 @@ struct tmff2_device_entry {
/* void pointers are dangerous, I know, but in this case likely the best option... */
};
+/* external */
+int t300rs_populate_api(struct tmff2_device_entry *tmff2);
+
+#define TMT300RS_PS3_NORM_ID 0xb66e
+#define TMT300RS_PS3_ADV_ID 0xb66f
+#define TMT300RS_PS4_NORM_ID 0xb66d
+
#endif /* __HID_TMFF2_H */
diff --git a/hid-tmt300rs.c b/hid-tmt300rs.c
index b253562..8c4655b 100644
--- a/hid-tmt300rs.c
+++ b/hid-tmt300rs.c
@@ -2,18 +2,18 @@
#include <linux/usb.h>
#include <linux/hid.h>
#include "hid-tmff2.h"
-#include "hid-tmt300rs.h"
#define T300RS_MAX_EFFECTS 16
#define T300RS_NORM_BUFFER_LENGTH 63
#define T300RS_PS4_BUFFER_LENGTH 31
static const unsigned long t300rs_params =
- HAS_SPRING_LEVEL
- | HAS_DAMPER_LEVEL
- | HAS_FRICTION_LEVEL
- | HAS_RANGE
- | HAS_ALT_MODE;
+ PARAM_SPRING_LEVEL
+ | PARAM_DAMPER_LEVEL
+ | PARAM_FRICTION_LEVEL
+ | PARAM_RANGE
+ | PARAM_ALT_MODE
+ ;
static const signed short t300rs_effects[] = {
FF_CONSTANT,
@@ -356,7 +356,7 @@ static u8 damper_values[] = {
0x7f, 0x07
};
-static int t300rs_send_buf(struct t300rs_device_entry *t300rs, size_t len, u8 *send_buffer)
+static int t300rs_send_buf(struct t300rs_device_entry *t300rs, u8 *send_buffer, size_t len)
{
int i;
/* check that send_buffer fits into our report */
@@ -377,7 +377,7 @@ static int t300rs_send_buf(struct t300rs_device_entry *t300rs, size_t len, u8 *s
static int t300rs_send_int(struct t300rs_device_entry *t300rs)
{
- t300rs_send_buf(t300rs, t300rs->buffer_length, t300rs->send_buffer);
+ t300rs_send_buf(t300rs, t300rs->send_buffer, t300rs->buffer_length);
memset(t300rs->send_buffer, 0, t300rs->buffer_length);
return 0;
@@ -1213,6 +1213,7 @@ static int t300rs_set_autocenter(void *data, uint16_t value)
if (!t300rs)
return -ENODEV;
+ /* TODO: this should probably also use a separately allocated buffer? */
autocenter_packet = (struct t300rs_packet_autocenter *)t300rs->send_buffer;
autocenter_packet->header.cmd = 0x08;
@@ -1288,7 +1289,7 @@ static int t300rs_set_range(void *data, uint16_t value)
send_buffer[2] = scaled_value & 0xff;
send_buffer[3] = scaled_value >> 8;
- if ((ret = t300rs_send_buf(t300rs, t300rs->buffer_length, send_buffer)))
+ if ((ret = t300rs_send_buf(t300rs, send_buffer, t300rs->buffer_length)))
hid_warn(t300rs->hdev, "failed setting range\n");
/* since everythin went OK, update the current range */
@@ -1403,7 +1404,7 @@ static int t300rs_wheel_init(struct tmff2_device_entry *tmff2)
t300rs->input_dev = tmff2->input_dev;
t300rs->usbdev = to_usb_device(tmff2->hdev->dev.parent->parent);
- if(t300rs->hdev->product == 0xb66d)
+ if(t300rs->hdev->product == TMT300RS_PS4_NORM_ID)
t300rs->buffer_length = T300RS_PS4_BUFFER_LENGTH;
else
t300rs->buffer_length = T300RS_NORM_BUFFER_LENGTH;
@@ -1427,7 +1428,7 @@ static int t300rs_wheel_init(struct tmff2_device_entry *tmff2)
t300rs->close = t300rs->input_dev->close;
/* TODO: PS4 advanced mode? */
- alt_mode = (t300rs->hdev->product == 0xb66f);
+ alt_mode = (t300rs->hdev->product == TMT300RS_PS3_ADV_ID);
/* everythin went OK */
tmff2->data = t300rs;
@@ -1440,10 +1441,10 @@ static int t300rs_wheel_init(struct tmff2_device_entry *tmff2)
firmware_err:
kfree(t300rs->send_buffer);
-t300rs_err:
- kfree(t300rs);
send_err:
- hid_err(tmff2->hdev, "failed creating force feedback device\n");
+ kfree(t300rs);
+t300rs_err:
+ hid_err(tmff2->hdev, "failed initializing T300RS\n");
return ret;
}
@@ -1462,19 +1463,19 @@ static __u8 *t300rs_wheel_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
switch (hdev->product) {
- case 0xb66e:
+ case TMT300RS_PS3_NORM_ID:
/* normal PS3 mode */
rdesc = t300rs_rdesc_nrm_fixed;
*rsize = sizeof(t300rs_rdesc_nrm_fixed);
break;
- case 0xb66d:
+ case TMT300RS_PS4_NORM_ID:
/* PS4 normal mode */
rdesc = t300rs_rdesc_ps4_fixed;
*rsize = sizeof(t300rs_rdesc_ps4_fixed);
break;
- case 0xb66f:
+ case TMT300RS_PS3_ADV_ID:
/* PS3 advanced mode */
rdesc = t300rs_rdesc_adv_fixed;
*rsize = sizeof(t300rs_rdesc_adv_fixed);