All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anssi Hannula <anssi.hannula@gmail.com>
To: Dmitry Torokhov <dtor_core@ameritech.net>
Cc: linux-joystick@atrey.karlin.mff.cuni.cz, linux-kernel@vger.kernel.org
Subject: [patch 08/12] input: force feedback driver for Zeroplus devices
Date: Tue, 30 May 2006 13:57:13 +0300	[thread overview]
Message-ID: <20060530110134.874949000@gmail.com> (raw)
In-Reply-To: 20060530105705.157014000@gmail.com

[-- Attachment #1: ff-refactoring-new-driver-zpff.diff --]
[-- Type: text/plain, Size: 6624 bytes --]

Add force feedback driver for some PSX-style Zeroplus devices.

Signed-off-by: Anssi Hannula <anssi.hannula@gmail.com>

---
 drivers/usb/input/Kconfig    |    7 ++
 drivers/usb/input/Makefile   |    3 +
 drivers/usb/input/hid-ff.c   |    4 +
 drivers/usb/input/hid-zpff.c |  124 +++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/input/hid.h      |    1 
 5 files changed, 139 insertions(+)

Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid-ff.c
===================================================================
--- linux-2.6.17-rc4-git12.orig/drivers/usb/input/hid-ff.c	2006-05-24 21:14:35.000000000 +0300
+++ linux-2.6.17-rc4-git12/drivers/usb/input/hid-ff.c	2006-05-24 21:15:25.000000000 +0300
@@ -54,6 +54,10 @@ static struct hid_ff_initializer inits[]
 #ifdef CONFIG_THRUSTMASTER_FF
 	{0x44f, 0xb304, hid_tmff_init},
 #endif
+#ifdef CONFIG_ZEROPLUS_FF
+	{0xc12, 0x0005, zpff_init},
+	{0xc12, 0x0030, zpff_init},
+#endif
 	{0, 0, NULL} /* Terminating entry */
 };
 
Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid-zpff.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.17-rc4-git12/drivers/usb/input/hid-zpff.c	2006-05-24 21:15:52.000000000 +0300
@@ -0,0 +1,124 @@
+/*
+ *  Force feedback support for Zeroplus based devices
+ *
+ *  Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.com>
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/* #define DEBUG */
+
+#define debug(format, arg...) pr_debug("hid-zpff: " format "\n" , ## arg)
+
+#include <linux/input.h>
+#include <linux/usb.h>
+#include "hid.h"
+struct zpff_device {
+	struct hid_report *report;
+};
+
+static int zpff_play(struct input_dev *dev, struct ff_effect *effect,
+		     struct ff_effect *old)
+{
+	struct hid_device *hid = dev->private;
+	struct zpff_device *zpff = hid->ff_private;
+	int left, right;
+
+	/* The following is specified the other way around in the Zeroplus
+	   datasheet, but the order below is correct for the XFX Executioner */
+	/* However it is possible that the XFX Executioner is an exception */
+
+	left = effect->u.rumble.strong_magnitude;
+	right = effect->u.rumble.weak_magnitude;
+	debug("called with 0x%04x 0x%04x", left, right);
+
+	left = left * 0x7f / 0xffff;
+	right = right * 0x7f / 0xffff;
+
+	zpff->report->field[2]->value[0] = left;
+	zpff->report->field[3]->value[0] = right;
+	debug("running with 0x%02x 0x%02x", left, right);
+	hid_submit_report(hid, zpff->report, USB_DIR_OUT);
+	return 0;
+}
+
+static void zpff_exit(struct hid_device *hid)
+{
+	struct zpff_device *zpff = hid->ff_private;
+	hid->ff_private = NULL;
+	kfree(zpff);
+}
+
+static struct ff_driver zpff_driver = {
+	.upload = zpff_play,
+};
+
+int zpff_init(struct hid_device *hid)
+{
+	struct zpff_device *zpff;
+	struct hid_report *report;
+	struct hid_input *hidinput =
+	    list_entry(hid->inputs.next, struct hid_input, list);
+	struct input_dev *dev = hidinput->input;
+	int ret;
+
+	if (list_empty(&hid->report_enum[HID_OUTPUT_REPORT].report_list)) {
+		printk(KERN_ERR "hid-zpff: no output report found\n");
+		return -1;
+	}
+	report =
+	    list_entry(hid->report_enum[HID_OUTPUT_REPORT].report_list.next,
+		       struct hid_report, list);
+
+	if (report->maxfield < 4) {
+		printk(KERN_ERR "hid-zpff: not enough fields in report\n");
+		return -1;
+	}
+
+	ret = input_ff_allocate(dev);
+	if (ret)
+		return ret;
+
+	zpff = kzalloc(sizeof(*zpff), GFP_KERNEL);
+	if (!zpff) {
+		return -ENOMEM;
+	}
+
+	hid->ff_private = zpff;
+	hid->ff_exit = zpff_exit;
+
+	set_bit(FF_RUMBLE, dev->ff->flags);
+
+	zpff->report = report;
+	zpff->report->field[0]->value[0] = 0x00;
+	zpff->report->field[1]->value[0] = 0x02;
+	zpff->report->field[2]->value[0] = 0x00;
+	zpff->report->field[3]->value[0] = 0x00;
+	hid_submit_report(hid, zpff->report, USB_DIR_OUT);
+
+	ret = input_ff_register(dev, &zpff_driver);
+	if (ret) {
+		kfree(zpff);
+		return ret;
+	}
+
+	printk(KERN_INFO "Force feedback for Zeroplus based devices by "
+	       "Anssi Hannula <anssi.hannula@gmail.com>\n");
+
+	return 0;
+}
Index: linux-2.6.17-rc4-git12/drivers/usb/input/Kconfig
===================================================================
--- linux-2.6.17-rc4-git12.orig/drivers/usb/input/Kconfig	2006-05-24 21:14:35.000000000 +0300
+++ linux-2.6.17-rc4-git12/drivers/usb/input/Kconfig	2006-05-24 21:15:25.000000000 +0300
@@ -87,6 +87,13 @@ config THRUSTMASTER_FF
 	  Note: if you say N here, this device will still be supported, but without
 	  force feedback.
 
+config ZEROPLUS_FF
+	bool "Zeroplus based game controller support"
+	depends on HID_FF
+	help
+	  Say Y here if you have a Zeroplus based game controller and want to
+	  enable force feedback for it.
+
 config USB_HIDDEV
 	bool "/dev/hiddev raw HID device support"
 	depends on USB_HID
Index: linux-2.6.17-rc4-git12/drivers/usb/input/Makefile
===================================================================
--- linux-2.6.17-rc4-git12.orig/drivers/usb/input/Makefile	2006-05-24 21:14:35.000000000 +0300
+++ linux-2.6.17-rc4-git12/drivers/usb/input/Makefile	2006-05-24 21:15:25.000000000 +0300
@@ -22,6 +22,9 @@ endif
 ifeq ($(CONFIG_THRUSTMASTER_FF),y)
 	usbhid-objs	+= hid-tmff.o
 endif
+ifeq ($(CONFIG_ZEROPLUS_FF),y)
+	usbhid-objs	+= hid-zpff.o
+endif
 ifeq ($(CONFIG_HID_FF),y)
 	usbhid-objs	+= hid-ff.o
 endif
Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid.h
===================================================================
--- linux-2.6.17-rc4-git12.orig/drivers/usb/input/hid.h	2006-05-24 21:14:35.000000000 +0300
+++ linux-2.6.17-rc4-git12/drivers/usb/input/hid.h	2006-05-24 21:15:25.000000000 +0300
@@ -527,6 +527,7 @@ static inline void hid_ff_exit(struct hi
 
 int hid_lgff_init(struct hid_device* hid);
 int hid_tmff_init(struct hid_device* hid);
+int zpff_init(struct hid_device* hid);
 
 #ifdef CONFIG_HID_PID
 int pidff_init(struct hid_device *hid);

--
Anssi Hannula

  parent reply	other threads:[~2006-05-30 11:05 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-30 10:57 [patch 00/12] input: force feedback updates, third time Anssi Hannula
2006-05-30 10:57 ` [patch 01/12] input: move fixp-arith.h to drivers/input Anssi Hannula
2006-05-30 10:57 ` [patch 02/12] input: fix accuracy of fixp-arith.h Anssi Hannula
2006-05-30 10:57 ` [patch 03/12] input: new force feedback interface Anssi Hannula
2006-05-31  5:21   ` Randy.Dunlap
2006-05-31 10:13     ` Anssi Hannula
2006-06-01 19:02     ` input: return -ENOSYS for registering functions when ff is disabled Anssi Hannula
2006-06-01 19:07     ` input: fix comments and blank lines in new ff code Anssi Hannula
2006-06-01 19:52       ` Randy.Dunlap
2006-06-01 20:03         ` Anssi Hannula
2006-06-01 20:09           ` Randy.Dunlap
2006-06-01 20:47             ` Anssi Hannula
2006-06-01 21:33               ` Randy.Dunlap
2006-06-01 22:16                 ` Anssi Hannula
2006-06-01 22:31                   ` Randy.Dunlap
2006-06-02 17:44                 ` [patch] input: fix function name in a comment Anssi Hannula
2006-06-05 18:52   ` [patch 03/12] input: new force feedback interface Dmitry Torokhov
2006-06-05 21:11     ` Anssi Hannula
2006-06-06  2:02       ` Dmitry Torokhov
2006-06-06 11:23         ` Anssi Hannula
2006-06-06 12:45           ` Dmitry Torokhov
2006-06-06 13:11             ` Anssi Hannula
2006-06-19 20:09               ` Anssi Hannula
2006-05-30 10:57 ` [patch 04/12] input: adapt hid force feedback drivers for the new interface Anssi Hannula
2006-05-30 10:57 ` [patch 05/12] input: adapt uinput for the new force feedback interface Anssi Hannula
2006-05-30 10:57 ` [patch 06/12] input: adapt iforce driver " Anssi Hannula
2006-05-30 10:57 ` [patch 07/12] input: force feedback driver for PID devices Anssi Hannula
2006-05-30 10:57 ` Anssi Hannula [this message]
2006-05-30 10:57 ` [patch 09/12] input: update documentation of force feedback Anssi Hannula
2006-05-30 10:57 ` [patch 10/12] input: drop the remains of the old ff interface Anssi Hannula
2006-05-30 10:57 ` [patch 11/12] input: drop the old PID driver Anssi Hannula
2006-05-30 10:57 ` [patch 12/12] input: use -ENOSPC instead of -ENOMEM in iforce when device full Anssi Hannula
2006-05-31  5:02   ` Randy.Dunlap
2006-05-31 10:04     ` Anssi Hannula
2006-05-31 15:15       ` Randy.Dunlap

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=20060530110134.874949000@gmail.com \
    --to=anssi.hannula@gmail.com \
    --cc=dtor_core@ameritech.net \
    --cc=linux-joystick@atrey.karlin.mff.cuni.cz \
    --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.