Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1480428

[PATCH 1/5] HID:hid-logitech: Introduce dev_attr for combined pedals feature

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Simon Wood <gitsend@mungewell.org>
Newsgroups linux.kernel
Subject [PATCH 1/5] HID:hid-logitech: Introduce dev_attr for combined pedals feature
Date Sat, 10 Sep 2016 01:00:01 +0200
Message-ID <sfCW5-tE-7@gated-at.bofh.it> (permalink)
X-Original-To linux-input@vger.kernel.org
Dkim-Signature v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mungewell.org; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=3xi8sj4HJyCtWymdmKbo1O7ln5SMhh+n8dfPLNjeoVI=; b=ghzSxYohLW3ZUMIldigFnlji6w rQpajNljgPgnDr6larEUyFn+C0hkI3ptBvs6P2aA79ftzWqfKad5Vqfz8284OIneX6VfvtX3BNnG9 dJrvklPFEafVhKeXh9azJod/bC9jOeUu1T+op7zMSsELVw9+7R/IzlSkF8Jfv/s7sjb/lxxYAVhnc Xai+q5ZjKes4fGxx4sOxsVD0vQlLctb/2DSMP6B4zj3OTRBVdGI/piY3QaTfK9sTJmdGOejTiyH0d nf0h1P1Dt4vGF45d1c5I7f3XVY+z1RFGA3SbKYL/PDEzj00B1jUjbTHZkNuHPKlEtHFNPx2i9wepk 10nWQYlA==;
X-Mailer git-send-email 2.7.4
X-Outgoing-Spam-Status No, score=-1.0
X-Antiabuse This header was added to track abuse, please include it with any abuse report
X-Antiabuse Primary Hostname - host18.canaca.com
X-Antiabuse Original Domain - vger.kernel.org
X-Antiabuse Originator/Caller UID/GID - [47 12] / [47 12]
X-Antiabuse Sender Address Domain - mungewell.org
X-Get-Message-Sender-Via host18.canaca.com: authenticated_id: gitsend@mungewell.org
X-Authenticated-Sender host18.canaca.com: gitsend@mungewell.org
X-From-Rewrite rewritten was: [simon@mungewell.org], actual sender does not match
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 126
Organization linux.* mail to news gateway
X-Original-Cc linux-kernel@vger.kernel.org, Jiri Kosina <jkosina@suse.cz>, Edwin Velds <edwin@velds.nl>, Elias Vanderstuyft <elias.vds@gmail.com>, Michal Maly <madcatxster@gmail.com>, Simon Wood <simon@mungewell.org>
X-Original-Date Fri, 9 Sep 2016 16:50:45 -0600
X-Original-Message-ID <1473461449-8060-1-git-send-email-simon@mungewell.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1480428

Show key headers only | View raw


Introduce a dev_attr which can be used to combine the accelerator
and brake pedals into a single axis. This is useful for older games
which can not handle separate accelerator and brake.

Signed-off-by: Simon Wood <simon@mungewell.org>
---
 .../ABI/testing/sysfs-driver-hid-logitech-lg4ff    |  9 ++++
 drivers/hid/hid-lg4ff.c                            | 58 ++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-driver-hid-logitech-lg4ff b/Documentation/ABI/testing/sysfs-driver-hid-logitech-lg4ff
index db197a8..69fb890 100644
--- a/Documentation/ABI/testing/sysfs-driver-hid-logitech-lg4ff
+++ b/Documentation/ABI/testing/sysfs-driver-hid-logitech-lg4ff
@@ -50,3 +50,12 @@ Description:	Displays the real model of the wheel regardless of any
 		alternate mode the wheel might be switched to.
 		It is a read-only value.
 		This entry is not created for devices that have only one mode.
+
+What:		/sys/bus/hid/drivers/logitech/<dev>/combine_pedals
+Date:		Sep 2016
+KernelVersion:	4.9
+Contact:	Simon Wood <simon@mungewell.org>
+Description:	Controls whether a combined value of accelerator and brake is
+		reported on the Y axis of the controller. Useful for older games
+		which can do not work with separate accelerator/brake axis.
+		Off ('0') by default, enabled by setting '1'.
diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
index af3a8ec..ca31ce4 100644
--- a/drivers/hid/hid-lg4ff.c
+++ b/drivers/hid/hid-lg4ff.c
@@ -75,6 +75,7 @@ static void lg4ff_set_range_g25(struct hid_device *hid, u16 range);
 
 struct lg4ff_wheel_data {
 	const u32 product_id;
+	u16 combine;
 	u16 range;
 	const u16 min_range;
 	const u16 max_range;
@@ -345,6 +346,7 @@ static void lg4ff_init_wheel_data(struct lg4ff_wheel_data * const wdata, const s
 	{
 		struct lg4ff_wheel_data t_wdata =  { .product_id = wheel->product_id,
 						     .real_product_id = real_product_id,
+						     .combine = 0,
 						     .min_range = wheel->min_range,
 						     .max_range = wheel->max_range,
 						     .set_range = wheel->set_range,
@@ -885,6 +887,58 @@ static ssize_t lg4ff_alternate_modes_store(struct device *dev, struct device_att
 }
 static DEVICE_ATTR(alternate_modes, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, lg4ff_alternate_modes_show, lg4ff_alternate_modes_store);
 
+static ssize_t lg4ff_combine_show(struct device *dev, struct device_attribute *attr,
+				char *buf)
+{
+	struct hid_device *hid = to_hid_device(dev);
+	struct lg4ff_device_entry *entry;
+	struct lg_drv_data *drv_data;
+	size_t count;
+
+	drv_data = hid_get_drvdata(hid);
+	if (!drv_data) {
+		hid_err(hid, "Private driver data not found!\n");
+		return 0;
+	}
+
+	entry = drv_data->device_props;
+	if (!entry) {
+		hid_err(hid, "Device properties not found!\n");
+		return 0;
+	}
+
+	count = scnprintf(buf, PAGE_SIZE, "%u\n", entry->wdata.combine);
+	return count;
+}
+
+static ssize_t lg4ff_combine_store(struct device *dev, struct device_attribute *attr,
+				 const char *buf, size_t count)
+{
+	struct hid_device *hid = to_hid_device(dev);
+	struct lg4ff_device_entry *entry;
+	struct lg_drv_data *drv_data;
+	u16 combine = simple_strtoul(buf, NULL, 10);
+
+	drv_data = hid_get_drvdata(hid);
+	if (!drv_data) {
+		hid_err(hid, "Private driver data not found!\n");
+		return -EINVAL;
+	}
+
+	entry = drv_data->device_props;
+	if (!entry) {
+		hid_err(hid, "Device properties not found!\n");
+		return -EINVAL;
+	}
+
+	if (combine > 1)
+		combine = 1;
+
+	entry->wdata.combine = combine;
+	return count;
+}
+static DEVICE_ATTR(combine_pedals, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, lg4ff_combine_show, lg4ff_combine_store);
+
 /* Export the currently set range of the wheel */
 static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *attr,
 				char *buf)
@@ -1259,6 +1313,9 @@ int lg4ff_init(struct hid_device *hid)
 	}
 
 	/* Create sysfs interface */
+	error = device_create_file(&hid->dev, &dev_attr_combine_pedals);
+	if (error)
+		hid_warn(hid, "Unable to create sysfs interface for \"combine\", errno %d\n", error);
 	error = device_create_file(&hid->dev, &dev_attr_range);
 	if (error)
 		hid_warn(hid, "Unable to create sysfs interface for \"range\", errno %d\n", error);
@@ -1358,6 +1415,7 @@ int lg4ff_deinit(struct hid_device *hid)
 		device_remove_file(&hid->dev, &dev_attr_alternate_modes);
 	}
 
+	device_remove_file(&hid->dev, &dev_attr_combine_pedals);
 	device_remove_file(&hid->dev, &dev_attr_range);
 #ifdef CONFIG_LEDS_CLASS
 	{
-- 
2.7.4

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/5] HID:hid-logitech: Introduce dev_attr for combined pedals feature Simon Wood <gitsend@mungewell.org> - 2016-09-10 01:00 +0200
  [PATCH 5/5] HID:hid-logitech: Documentation updates/corrections Simon Wood <gitsend@mungewell.org> - 2016-09-10 01:00 +0200
  [PATCH 3/5] HID:hid-logitech: Compute combined pedals if not supplied Simon Wood <gitsend@mungewell.org> - 2016-09-10 01:00 +0200
  [Patch-V2 2/6] HID:hid-logitech: Add combined pedal support Logitech wheels Simon Wood <gitsend@mungewell.org> - 2016-09-18 19:00 +0200
  [Patch-V2 4/6] HID:hid-logitech: Rewrite of descriptor for all DF wheels Simon Wood <gitsend@mungewell.org> - 2016-09-18 19:00 +0200
  [Patch-V2 6/6] HID:hid-logitech: Documentation updates/corrections Simon Wood <gitsend@mungewell.org> - 2016-09-18 19:00 +0200
  [Patch-V2 1/6] HID:hid-logitech: Introduce control for combined pedals feature Simon Wood <gitsend@mungewell.org> - 2016-09-18 19:00 +0200
    [Patch-V2 3/6] HID:hid-logitech: Compute combined pedals value Simon Wood <gitsend@mungewell.org> - 2016-09-18 19:00 +0200
    [Patch-V2 5/6] HID:hid-logitech: Improve Wingman Formula Force GP support Simon Wood <gitsend@mungewell.org> - 2016-09-18 19:00 +0200

csiph-web