All of lore.kernel.org
 help / color / mirror / Atom feed
From: Piotr Sawuk <piotr5@users.sf.net>
To: linux-input@vger.kernel.org
Cc: Jiri Kosina <jikos@kernel.org>, linux-kernel@vger.kernel.org
Subject: [Patch v2] hid: enhance hid-saitek for use with R.A.T.5 and similar
Date: Thu, 28 Jan 2016 00:18:29 +0100	[thread overview]
Message-ID: <56A95045.3080107@users.sf.net> (raw)

added support for my pid so I can test the changes:
3 events were mapped to one, this allows discerning which is which.
on my mouse there is a button with a 3 colour-led.
I can now determine in user-space which colour is visible.
this patch replaces my previous ones.
if you use an older kernel than Dec 28th 2015, use previous patch!

Signed-off-by: Piotr Sawuk <piotr5@users.sf.net>
---
add support for mad catz r.a.t.5
add a file in sysfs called "mode" exposing the integer of that name.
diff -rup linux-4.2.6-gentoo/drivers/hid/hid-core.c linux-4.2.6-gentoo-rat5/drivers/hid/hid-core.c
--- linux-4.2.6-gentoo/drivers/hid/hid-core.c	2015-08-30 20:34:09.000000000 +0200
+++ linux-4.2.6-gentoo-rat5/drivers/hid/hid-core.c	2016-01-27 22:38:19.133124625 +0100
@@ -1958,6 +1958,7 @@ static const struct hid_device_id hid_ha
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7_OLD) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_MMO7) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT5) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT9) },
 #endif
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
diff -rup linux-4.2.6-gentoo/drivers/hid/hid-ids.h linux-4.2.6-gentoo-rat5/drivers/hid/hid-ids.h
--- linux-4.2.6-gentoo/drivers/hid/hid-ids.h	2015-08-30 20:34:09.000000000 +0200
+++ linux-4.2.6-gentoo-rat5/drivers/hid/hid-ids.h	2015-12-29 18:47:36.756225217 +0100
@@ -634,6 +634,7 @@
 
 #define USB_VENDOR_ID_MADCATZ		0x0738
 #define USB_DEVICE_ID_MADCATZ_BEATPAD	0x4540
+#define USB_DEVICE_ID_MADCATZ_RAT5	0x1705
 #define USB_DEVICE_ID_MADCATZ_RAT9	0x1709
 
 #define USB_VENDOR_ID_MCC		0x09db
diff -rup linux-4.2.6-gentoo/drivers/hid/hid-saitek.c linux-4.2.6-gentoo-rat5/drivers/hid/hid-saitek.c
--- linux-4.2.6-gentoo/drivers/hid/hid-saitek.c	2015-08-30 20:34:09.000000000 +0200
+++ linux-4.2.6-gentoo-rat5/drivers/hid/hid-saitek.c	2016-01-27 22:36:35.475950332 +0100
@@ -7,10 +7,11 @@
  *  (This module is based on "hid-ortek".)
  *  Copyright (c) 2012 Andreas Hübner
  *
- *  R.A.T.7, R.A.T.9, M.M.O.7 (USB gaming mice):
+ *  R.A.T.5, R.A.T.7, R.A.T.9, M.M.O.7 (USB gaming mice):
  *  Fixes the mode button which cycles through three constantly pressed
  *  buttons. All three press events are mapped to one button and the
  *  missing release event is generated immediately.
+ *  Original press event is available in "mode" file on sysfs.
  *
  */
 
@@ -37,6 +38,40 @@ struct saitek_sc {
 	int mode;
 };
 
+static ssize_t show_mode(struct device *dev,
+		struct device_attribute *attr,
+		char *mode_buf);
+
+/* world-readable since errors are caught and no usb-interaction needed. */
+DEVICE_ATTR(mode,0444,show_mode,NULL);
+
+static ssize_t show_mode(struct device *dev,
+		struct device_attribute *attr,
+		char *mode_buf)
+{
+	struct saitek_sc *ssc;
+	struct hid_device *hdev;
+
+	/* error-messages in sysfs file since it's non-critical. */
+	if (dev == NULL) {
+		return snprintf(mode_buf, PAGE_SIZE, "No parent.\n");
+	}
+
+	hdev = to_hid_device(dev);
+	ssc = hid_get_drvdata(hdev);
+	if (ssc == NULL) {
+		return snprintf(mode_buf, PAGE_SIZE, "No data.\n");
+	}
+
+	/* actual output is number >=1. 0 or above text for error: */
+	return snprintf(mode_buf, PAGE_SIZE, "%i\n", ssc->mode + 1);
+}
+
+static void saitek_remove(struct hid_device *hdev)
+{
+	device_remove_file(&hdev->dev, &dev_attr_mode);
+}
+
 static int saitek_probe(struct hid_device *hdev,
 		const struct hid_device_id *id)
 {
@@ -61,9 +96,15 @@ static int saitek_probe(struct hid_devic
 		return ret;
 	}
 
+	ret = device_create_file(&hdev->dev, &dev_attr_mode);
+	if (ret) {
+		hid_warn(hdev, "Couldn't create mode file in sysfs.\n");
+	}
+
 	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
 	if (ret) {
 		hid_err(hdev, "hw start failed\n");
+		saitek_remove(hdev);
 		return ret;
 	}
 
@@ -181,6 +222,8 @@ static const struct hid_device_id saitek
 		.driver_data = SAITEK_RELEASE_MODE_RAT7 },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7),
 		.driver_data = SAITEK_RELEASE_MODE_RAT7 },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT5),
+		.driver_data = SAITEK_RELEASE_MODE_RAT7 },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT9),
 		.driver_data = SAITEK_RELEASE_MODE_RAT7 },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_MMO7),
@@ -197,6 +240,7 @@ static struct hid_driver saitek_driver =
 	.report_fixup = saitek_report_fixup,
 	.raw_event = saitek_raw_event,
 	.event = saitek_event,
+	.remove = saitek_remove,
 };
 module_hid_driver(saitek_driver);
 
diff -rup linux-4.2.6-gentoo/drivers/hid/Kconfig linux-4.2.6-gentoo-rat5/drivers/hid/Kconfig
--- linux-4.2.6-gentoo/drivers/hid/Kconfig	2015-08-30 20:34:09.000000000 +0200
+++ linux-4.2.6-gentoo-rat5/drivers/hid/Kconfig	2015-12-30 12:14:49.228404039 +0100
@@ -665,6 +665,7 @@ config HID_SAITEK
 
 	Supported devices:
 	- PS1000 Dual Analog Pad
+	- R.A.T.5 Gaming Mouse
 	- R.A.T.9 Gaming Mouse
 	- R.A.T.7 Gaming Mouse
 	- M.M.O.7 Gaming Mouse
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: Piotr Sawuk <piotr5@users.sf.net>
To: linux-input@vger.kernel.org
Cc: Jiri Kosina <jikos@kernel.org>, linux-kernel@vger.kernel.org
Subject: [Patch v2] hid: enhance hid-saitek for use with R.A.T.5 and similar
Date: Thu, 28 Jan 2016 00:18:29 +0100	[thread overview]
Message-ID: <56A95045.3080107@users.sf.net> (raw)

added support for my pid so I can test the changes:
3 events were mapped to one, this allows discerning which is which.
on my mouse there is a button with a 3 colour-led.
I can now determine in user-space which colour is visible.
this patch replaces my previous ones.
if you use an older kernel than Dec 28th 2015, use previous patch!

Signed-off-by: Piotr Sawuk <piotr5@users.sf.net>
---
add support for mad catz r.a.t.5
add a file in sysfs called "mode" exposing the integer of that name.
diff -rup linux-4.2.6-gentoo/drivers/hid/hid-core.c linux-4.2.6-gentoo-rat5/drivers/hid/hid-core.c
--- linux-4.2.6-gentoo/drivers/hid/hid-core.c	2015-08-30 20:34:09.000000000 +0200
+++ linux-4.2.6-gentoo-rat5/drivers/hid/hid-core.c	2016-01-27 22:38:19.133124625 +0100
@@ -1958,6 +1958,7 @@ static const struct hid_device_id hid_ha
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7_OLD) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_MMO7) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT5) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT9) },
 #endif
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
diff -rup linux-4.2.6-gentoo/drivers/hid/hid-ids.h linux-4.2.6-gentoo-rat5/drivers/hid/hid-ids.h
--- linux-4.2.6-gentoo/drivers/hid/hid-ids.h	2015-08-30 20:34:09.000000000 +0200
+++ linux-4.2.6-gentoo-rat5/drivers/hid/hid-ids.h	2015-12-29 18:47:36.756225217 +0100
@@ -634,6 +634,7 @@
 
 #define USB_VENDOR_ID_MADCATZ		0x0738
 #define USB_DEVICE_ID_MADCATZ_BEATPAD	0x4540
+#define USB_DEVICE_ID_MADCATZ_RAT5	0x1705
 #define USB_DEVICE_ID_MADCATZ_RAT9	0x1709
 
 #define USB_VENDOR_ID_MCC		0x09db
diff -rup linux-4.2.6-gentoo/drivers/hid/hid-saitek.c linux-4.2.6-gentoo-rat5/drivers/hid/hid-saitek.c
--- linux-4.2.6-gentoo/drivers/hid/hid-saitek.c	2015-08-30 20:34:09.000000000 +0200
+++ linux-4.2.6-gentoo-rat5/drivers/hid/hid-saitek.c	2016-01-27 22:36:35.475950332 +0100
@@ -7,10 +7,11 @@
  *  (This module is based on "hid-ortek".)
  *  Copyright (c) 2012 Andreas Hübner
  *
- *  R.A.T.7, R.A.T.9, M.M.O.7 (USB gaming mice):
+ *  R.A.T.5, R.A.T.7, R.A.T.9, M.M.O.7 (USB gaming mice):
  *  Fixes the mode button which cycles through three constantly pressed
  *  buttons. All three press events are mapped to one button and the
  *  missing release event is generated immediately.
+ *  Original press event is available in "mode" file on sysfs.
  *
  */
 
@@ -37,6 +38,40 @@ struct saitek_sc {
 	int mode;
 };
 
+static ssize_t show_mode(struct device *dev,
+		struct device_attribute *attr,
+		char *mode_buf);
+
+/* world-readable since errors are caught and no usb-interaction needed. */
+DEVICE_ATTR(mode,0444,show_mode,NULL);
+
+static ssize_t show_mode(struct device *dev,
+		struct device_attribute *attr,
+		char *mode_buf)
+{
+	struct saitek_sc *ssc;
+	struct hid_device *hdev;
+
+	/* error-messages in sysfs file since it's non-critical. */
+	if (dev == NULL) {
+		return snprintf(mode_buf, PAGE_SIZE, "No parent.\n");
+	}
+
+	hdev = to_hid_device(dev);
+	ssc = hid_get_drvdata(hdev);
+	if (ssc == NULL) {
+		return snprintf(mode_buf, PAGE_SIZE, "No data.\n");
+	}
+
+	/* actual output is number >=1. 0 or above text for error: */
+	return snprintf(mode_buf, PAGE_SIZE, "%i\n", ssc->mode + 1);
+}
+
+static void saitek_remove(struct hid_device *hdev)
+{
+	device_remove_file(&hdev->dev, &dev_attr_mode);
+}
+
 static int saitek_probe(struct hid_device *hdev,
 		const struct hid_device_id *id)
 {
@@ -61,9 +96,15 @@ static int saitek_probe(struct hid_devic
 		return ret;
 	}
 
+	ret = device_create_file(&hdev->dev, &dev_attr_mode);
+	if (ret) {
+		hid_warn(hdev, "Couldn't create mode file in sysfs.\n");
+	}
+
 	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
 	if (ret) {
 		hid_err(hdev, "hw start failed\n");
+		saitek_remove(hdev);
 		return ret;
 	}
 
@@ -181,6 +222,8 @@ static const struct hid_device_id saitek
 		.driver_data = SAITEK_RELEASE_MODE_RAT7 },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7),
 		.driver_data = SAITEK_RELEASE_MODE_RAT7 },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT5),
+		.driver_data = SAITEK_RELEASE_MODE_RAT7 },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT9),
 		.driver_data = SAITEK_RELEASE_MODE_RAT7 },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_MMO7),
@@ -197,6 +240,7 @@ static struct hid_driver saitek_driver =
 	.report_fixup = saitek_report_fixup,
 	.raw_event = saitek_raw_event,
 	.event = saitek_event,
+	.remove = saitek_remove,
 };
 module_hid_driver(saitek_driver);
 
diff -rup linux-4.2.6-gentoo/drivers/hid/Kconfig linux-4.2.6-gentoo-rat5/drivers/hid/Kconfig
--- linux-4.2.6-gentoo/drivers/hid/Kconfig	2015-08-30 20:34:09.000000000 +0200
+++ linux-4.2.6-gentoo-rat5/drivers/hid/Kconfig	2015-12-30 12:14:49.228404039 +0100
@@ -665,6 +665,7 @@ config HID_SAITEK
 
 	Supported devices:
 	- PS1000 Dual Analog Pad
+	- R.A.T.5 Gaming Mouse
 	- R.A.T.9 Gaming Mouse
 	- R.A.T.7 Gaming Mouse
 	- M.M.O.7 Gaming Mouse

             reply	other threads:[~2016-01-27 23:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-27 23:18 Piotr Sawuk [this message]
2016-01-27 23:18 ` [Patch v2] hid: enhance hid-saitek for use with R.A.T.5 and similar Piotr Sawuk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56A95045.3080107@users.sf.net \
    --to=piotr5@users.sf.net \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.