Skip to contentSkip to conversation

input: force feedback updates, second time

PATCH In review Anssi Hannula 2 participants 27 messages May 26, 2006 – May 27, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover input: force feedback updates, second time

Major update for the force feedback support, including a new force feedback driver interface and two new HID ff drivers.

This is the same patchset that I sent 10 days ago, now with the following changes:

- ugly cond_locking dropped
- 80-column rule now followed
- some function opening braces newlined and unneeded braces removed
- DECLARE_BITMAP used in input_ff_timer()
- effects are fd specific instead of the previous behaviour [1]
- uses setup_timer()
- no new module added, but code is instead compiled into input module (input.c is renamed to input-core.c)
- EXPORT_SYMBOL_GPL() used
- no -ENOSYS return values
- non-atomic bit operations used in most places of input-ff.c
- some comments are added
- new patch for -ENOMEM => -ENOSPC in iforce-ff.c
- UINPUT_VERSION define added in uinput.h
- drop obsolete static function declaration from hid-lgff.c
- pr_debug() used

[1] There are no known ff programs that depend on the old behaviour. Daniel Remenak, who has been coding linux ff support for several programs, agrees to the change. The old behaviour is not documented anywhere, so most likely nobody even knew about it (Daniel didn't).

I described this in another mail already, but here it is again:

old behaviour:
- fd1 opened
- fd1: effects 0, 1 are created
- fd2 opened
- fd2: effects 2, 3 are created
- fd2 closed
=> effects 0, 1, 2, 3 get deleted
- fd1 uses effects
=> failure
- fd1 closed

new behaviour:
- fd1 opened
- fd1: effects 0, 1 are created
- fd2 opened
- fd2: effects 2, 3 are created
- fd2 closed
=> effects 2, 3 get deleted
- fd1 uses effects
- fd1 closed
=> effects 0, 1 get deleted

(fd1 and fd2 are of the same process and the same device)

Signature · 1 line
Anssi Hannula
#1 lore raw

PATCH 1/13 input: move fixp-arith.h to drivers/input

Move fixp-arith.h from drivers/usb/input to drivers/input, as the part of force feedback support that requires trigonometric functions is being moved there.

hid-lgff.c is temporarily modified to avoid breaking git-bisect.

---
 drivers/input/fixp-arith.h     |   90 +++++++++++++++++++++++++++++++++++++++++
 drivers/usb/input/fixp-arith.h |   90 -----------------------------------------
 drivers/usb/input/hid-lgff.c   |    6 +-
 3 files changed, 93 insertions(+), 93 deletions(-)
drivers/input/fixp-arith.h new file +90 -0
Index: linux-2.6.17-rc3-git12/drivers/input/fixp-arith.h
===================================================================
@@ -0,0 +1,90 @@
+#ifndef _FIXP_ARITH_H
+#define _FIXP_ARITH_H
+
+/*
+ * $$
+ *
+ * Simplistic fixed-point arithmetics.
+ * Hmm, I'm probably duplicating some code :(
+ *
+ * Copyright (c) 2002 Johann Deneux
+ */
+
+/*
+ * 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
+ *
+ * Should you need to contact me, the author, you can do so by
+ * e-mail - mail your message to <[email protected]>
+ */
+
+#include <linux/types.h>
+
+// The type representing fixed-point values
+typedef s16 fixp_t;
+
+#define FRAC_N 8
+#define FRAC_MASK ((1<<FRAC_N)-1)
+
+// Not to be used directly. Use fixp_{cos,sin}
+static const fixp_t cos_table[45] = {
+	0x0100,	0x00FF,	0x00FF,	0x00FE,	0x00FD,	0x00FC,	0x00FA,	0x00F8,
+	0x00F6,	0x00F3,	0x00F0,	0x00ED,	0x00E9,	0x00E6,	0x00E2,	0x00DD,
+	0x00D9,	0x00D4,	0x00CF,	0x00C9,	0x00C4,	0x00BE,	0x00B8,	0x00B1,
+	0x00AB,	0x00A4,	0x009D,	0x0096,	0x008F,	0x0087,	0x0080,	0x0078,
+	0x0070,	0x0068,	0x005F,	0x0057,	0x004F,	0x0046,	0x003D,	0x0035,
+	0x002C,	0x0023,	0x001A,	0x0011,	0x0008
+};
+
+
+/* a: 123 -> 123.0 */
+static inline fixp_t fixp_new(s16 a)
+{
+	return a<<FRAC_N;
+}
+
+/* a: 0xFFFF -> -1.0
+      0x8000 -> 1.0
+      0x0000 -> 0.0
+*/
+static inline fixp_t fixp_new16(s16 a)
+{
+	return ((s32)a)>>(16-FRAC_N);
+}
+
+static inline fixp_t fixp_cos(unsigned int degrees)
+{
+	int quadrant = (degrees / 90) & 3;
+	unsigned int i = degrees % 90;
+
+	if (quadrant == 1 || quadrant == 3) {
+		i = 89 - i;
+	}
+
+	i >>= 1;
+
+	return (quadrant == 1 || quadrant == 2)? -cos_table[i] : cos_table[i];
+}
+
+static inline fixp_t fixp_sin(unsigned int degrees)
+{
+	return -fixp_cos(degrees + 90);
+}
+
+static inline fixp_t fixp_mult(fixp_t a, fixp_t b)
+{
+	return ((s32)(a*b))>>FRAC_N;
+}
+
+#endif
drivers/usb/input/fixp-arith.h deleted +0 -90

90 lines not on this page · raw message

drivers/usb/input/hid-lgff.c +3 -3
Index: linux-2.6.17-rc3-git12/drivers/usb/input/hid-lgff.c
===================================================================
@@ -37,7 +37,7 @@
 #include <linux/circ_buf.h>
 
 #include "hid.h"
-#include "fixp-arith.h"
+//#include "fixp-arith.h"
 
 
 /* Periodicity of the update */
@@ -445,10 +445,10 @@ static void hid_lgff_timer(unsigned long
 			case FF_CONSTANT: {
 				//TODO: handle envelopes
 				int degrees = effect->effect.direction * 360 >> 16;
-				x += fixp_mult(fixp_sin(degrees),
+	/*			x += fixp_mult(fixp_sin(degrees),
 					       fixp_new16(effect->effect.u.constant.level));
 				y += fixp_mult(-fixp_cos(degrees),
-					       fixp_new16(effect->effect.u.constant.level));
+					       fixp_new16(effect->effect.u.constant.level));*/
 			}       break;
 			case FF_RUMBLE:
 				right += effect->effect.u.rumble.strong_magnitude;

--
Anssi Hannula

#2 lore raw

PATCH 2/13 input: fix accuracy of fixp-arith.h

In reply to Anssi Hannula

Add the value of cos(90) = 0 to the table. This also moves the results so that sin(x) == sin(180-x) is true as expected.

---
 drivers/input/fixp-arith.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/input/fixp-arith.h +3 -3
Index: linux-2.6.16-git20/drivers/input/fixp-arith.h
===================================================================
@@ -38,13 +38,13 @@ typedef s16 fixp_t;
 #define FRAC_MASK ((1<<FRAC_N)-1)
 
 // Not to be used directly. Use fixp_{cos,sin}
-static const fixp_t cos_table[45] = {
+static const fixp_t cos_table[46] = {
 	0x0100,	0x00FF,	0x00FF,	0x00FE,	0x00FD,	0x00FC,	0x00FA,	0x00F8,
 	0x00F6,	0x00F3,	0x00F0,	0x00ED,	0x00E9,	0x00E6,	0x00E2,	0x00DD,
 	0x00D9,	0x00D4,	0x00CF,	0x00C9,	0x00C4,	0x00BE,	0x00B8,	0x00B1,
 	0x00AB,	0x00A4,	0x009D,	0x0096,	0x008F,	0x0087,	0x0080,	0x0078,
 	0x0070,	0x0068,	0x005F,	0x0057,	0x004F,	0x0046,	0x003D,	0x0035,
-	0x002C,	0x0023,	0x001A,	0x0011,	0x0008
+	0x002C,	0x0023,	0x001A,	0x0011,	0x0008, 0x0000
 };
 
 
@@ -69,7 +69,7 @@ static inline fixp_t fixp_cos(unsigned i
 	unsigned int i = degrees % 90;
 
 	if (quadrant == 1 || quadrant == 3) {
-		i = 89 - i;
+		i = 90 - i;
 	}
 
 	i >>= 1;

--
Anssi Hannula

#3 lore raw

PATCH 3/13 input: make input a multi-object module

In reply to Anssi Hannula

Move the input.c to input-core.c and modify Makefile so that the input module can be built from multiple source files. This is preparing for the input-ff.c.

---
 drivers/input/Makefile     |    2 
 drivers/input/input-core.c | 1099 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/input/input.c      | 1099 ---------------------------------------------
 3 files changed, 1101 insertions(+), 1099 deletions(-)
drivers/input/input.c deleted +0 -1099
Index: linux-2.6.17-rc4-git12/drivers/input/input.c
===================================================================
@@ -1,1099 +0,0 @@
-/*
- * The input core
- *
- * Copyright (c) 1999-2002 Vojtech Pavlik
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published by
- * the Free Software Foundation.
- */
-
-#include <linux/init.h>
-#include <linux/sched.h>
-#include <linux/smp_lock.h>
-#include <linux/input.h>
-#include <linux/module.h>
-#include <linux/random.h>
-#include <linux/major.h>
-#include <linux/proc_fs.h>
-#include <linux/seq_file.h>
-#include <linux/interrupt.h>
-#include <linux/poll.h>
-#include <linux/device.h>
-#include <linux/mutex.h>
-
-MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
-MODULE_DESCRIPTION("Input core");
-MODULE_LICENSE("GPL");
-
-EXPORT_SYMBOL(input_allocate_device);
-EXPORT_SYMBOL(input_register_device);
-EXPORT_SYMBOL(input_unregister_device);
-EXPORT_SYMBOL(input_register_handler);
-EXPORT_SYMBOL(input_unregister_handler);
-EXPORT_SYMBOL(input_grab_device);
-EXPORT_SYMBOL(input_release_device);
-EXPORT_SYMBOL(input_open_device);
-EXPORT_SYMBOL(input_close_device);
-EXPORT_SYMBOL(input_accept_process);
-EXPORT_SYMBOL(input_flush_device);
-EXPORT_SYMBOL(input_event);
-EXPORT_SYMBOL_GPL(input_class);
-
-#define INPUT_DEVICES	256
-
-static LIST_HEAD(input_dev_list);
-static LIST_HEAD(input_handler_list);
-
-static struct input_handler *input_table[8];
-
-void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
-{
-	struct input_handle *handle;
-
-	if (type > EV_MAX || !test_bit(type, dev->evbit))
-		return;
-
-	add_input_randomness(type, code, value);
-
-	switch (type) {
-
-		case EV_SYN:
-			switch (code) {
-				case SYN_CONFIG:
-					if (dev->event) dev->event(dev, type, code, value);
-					break;
-
-				case SYN_REPORT:
-					if (dev->sync) return;
-					dev->sync = 1;
-					break;
-			}
-			break;
-
-		case EV_KEY:
-
-			if (code > KEY_MAX || !test_bit(code, dev->keybit) || !!test_bit(code, dev->key) == value)
-				return;
-
-			if (value == 2)
-				break;
-
-			change_bit(code, dev->key);
-
-			if (test_bit(EV_REP, dev->evbit) && dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] && dev->timer.data && value) {
-				dev->repeat_key = code;
-				mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]));
-			}
-
-			break;
-
-		case EV_SW:
-
-			if (code > SW_MAX || !test_bit(code, dev->swbit) || !!test_bit(code, dev->sw) == value)
-				return;
-
-			change_bit(code, dev->sw);
-
-			break;
-
-		case EV_ABS:
-
-			if (code > ABS_MAX || !test_bit(code, dev->absbit))
-				return;
-
-			if (dev->absfuzz[code]) {
-				if ((value > dev->abs[code] - (dev->absfuzz[code] >> 1)) &&
-				    (value < dev->abs[code] + (dev->absfuzz[code] >> 1)))
-					return;
-
-				if ((value > dev->abs[code] - dev->absfuzz[code]) &&
-				    (value < dev->abs[code] + dev->absfuzz[code]))
-					value = (dev->abs[code] * 3 + value) >> 2;
-
-				if ((value > dev->abs[code] - (dev->absfuzz[code] << 1)) &&
-				    (value < dev->abs[code] + (dev->absfuzz[code] << 1)))
-					value = (dev->abs[code] + value) >> 1;
-			}
-
-			if (dev->abs[code] == value)
-				return;
-
-			dev->abs[code] = value;
-			break;
-
-		case EV_REL:
-
-			if (code > REL_MAX || !test_bit(code, dev->relbit) || (value == 0))
-				return;
-
-			break;
-
-		case EV_MSC:
-
-			if (code > MSC_MAX || !test_bit(code, dev->mscbit))
-				return;
-
-			if (dev->event) dev->event(dev, type, code, value);
-
-			break;
-
-		case EV_LED:
-
-			if (code > LED_MAX || !test_bit(code, dev->ledbit) || !!test_bit(code, dev->led) == value)
-				return;
-
-			change_bit(code, dev->led);
-			if (dev->event) dev->event(dev, type, code, value);
-
-			break;
-
-		case EV_SND:
-
-			if (code > SND_MAX || !test_bit(code, dev->sndbit))
-				return;
-
-			if (!!test_bit(code, dev->snd) != !!value)
-				change_bit(code, dev->snd);
-
-			if (dev->event) dev->event(dev, type, code, value);
-
-			break;
-
-		case EV_REP:
-
-			if (code > REP_MAX || value < 0 || dev->rep[code] == value) return;
-
-			dev->rep[code] = value;
-			if (dev->event) dev->event(dev, type, code, value);
-
-			break;
-
-		case EV_FF:
-			if (dev->event) dev->event(dev, type, code, value);
-			break;
-	}
-
-	if (type != EV_SYN)
-		dev->sync = 0;
-
-	if (dev->grab)
-		dev->grab->handler->event(dev->grab, type, code, value);
-	else
-		list_for_each_entry(handle, &dev->h_list, d_node)
-			if (handle->open)
-				handle->handler->event(handle, type, code, value);
-}
-
-static void input_repeat_key(unsigned long data)
-{
-	struct input_dev *dev = (void *) data;
-
-	if (!test_bit(dev->repeat_key, dev->key))
-		return;
-
-	input_event(dev, EV_KEY, dev->repeat_key, 2);
-	input_sync(dev);
-
-	if (dev->rep[REP_PERIOD])
-		mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_PERIOD]));
-}
-
-int input_accept_process(struct input_handle *handle, struct file *file)
-{
-	if (handle->dev->accept)
-		return handle->dev->accept(handle->dev, file);
-
-	return 0;
-}
-
-int input_grab_device(struct input_handle *handle)
-{
-	if (handle->dev->grab)
-		return -EBUSY;
-
-	handle->dev->grab = handle;
-	return 0;
-}
-
-void input_release_device(struct input_handle *handle)
-{
-	if (handle->dev->grab == handle)
-		handle->dev->grab = NULL;
-}
-
-int input_open_device(struct input_handle *handle)
-{
-	struct input_dev *dev = handle->dev;
-	int err;
-
-	err = mutex_lock_interruptible(&dev->mutex);
-	if (err)
-		return err;
-
-	handle->open++;
-
-	if (!dev->users++ && dev->open)
-		err = dev->open(dev);
-
-	if (err)
-		handle->open--;
-
-	mutex_unlock(&dev->mutex);
-
-	return err;
-}
-
-int input_flush_device(struct input_handle* handle, struct file* file)
-{
-	if (handle->dev->flush)
-		return handle->dev->flush(handle->dev, file);
-
-	return 0;
-}
-
-void input_close_device(struct input_handle *handle)
-{
-	struct input_dev *dev = handle->dev;
-
-	input_release_device(handle);
-
-	mutex_lock(&dev->mutex);
-
-	if (!--dev->users && dev->close)
-		dev->close(dev);
-	handle->open--;
-
-	mutex_unlock(&dev->mutex);
-}
-
-static void input_link_handle(struct input_handle *handle)
-{
-	list_add_tail(&handle->d_node, &handle->dev->h_list);
-	list_add_tail(&handle->h_node, &handle->handler->h_list);
-}
-
-#define MATCH_BIT(bit, max) \
-		for (i = 0; i < NBITS(max); i++) \
-			if ((id->bit[i] & dev->bit[i]) != id->bit[i]) \
-				break; \
-		if (i != NBITS(max)) \
-			continue;
-
-static struct input_device_id *input_match_device(struct input_device_id *id, struct input_dev *dev)
-{
-	int i;
-
-	for (; id->flags || id->driver_info; id++) {
-
-		if (id->flags & INPUT_DEVICE_ID_MATCH_BUS)
-			if (id->bustype != dev->id.bustype)
-				continue;
-
-		if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR)
-			if (id->vendor != dev->id.vendor)
-				continue;
-
-		if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT)
-			if (id->product != dev->id.product)
-				continue;
-
-		if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION)
-			if (id->version != dev->id.version)
-				continue;
-
-		MATCH_BIT(evbit,  EV_MAX);
-		MATCH_BIT(keybit, KEY_MAX);
-		MATCH_BIT(relbit, REL_MAX);
-		MATCH_BIT(absbit, ABS_MAX);
-		MATCH_BIT(mscbit, MSC_MAX);
-		MATCH_BIT(ledbit, LED_MAX);
-		MATCH_BIT(sndbit, SND_MAX);
-		MATCH_BIT(ffbit,  FF_MAX);
-		MATCH_BIT(swbit,  SW_MAX);
-
-		return id;
-	}
-
-	return NULL;
-}
-
-#ifdef CONFIG_PROC_FS
-
-static struct proc_dir_entry *proc_bus_input_dir;
-static DECLARE_WAIT_QUEUE_HEAD(input_devices_poll_wait);
-static int input_devices_state;
-
-static inline void input_wakeup_procfs_readers(void)
-{
-	input_devices_state++;
-	wake_up(&input_devices_poll_wait);
-}
-
-static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait)
-{
-	int state = input_devices_state;
-	poll_wait(file, &input_devices_poll_wait, wait);
-	if (state != input_devices_state)
-		return POLLIN | POLLRDNORM;
-	return 0;
-}
-
-static struct list_head *list_get_nth_element(struct list_head *list, loff_t *pos)
-{
-	struct list_head *node;
-	loff_t i = 0;
-
-	list_for_each(node, list)
-		if (i++ == *pos)
-			return node;
-
-	return NULL;
-}
-
-static struct list_head *list_get_next_element(struct list_head *list, struct list_head *element, loff_t *pos)
-{
-	if (element->next == list)
-		return NULL;
-
-	++(*pos);
-	return element->next;
-}
-
-static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos)
-{
-	/* acquire lock here ... Yes, we do need locking, I knowi, I know... */
-
-	return list_get_nth_element(&input_dev_list, pos);
-}
-
-static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos)
-{
-	return list_get_next_element(&input_dev_list, v, pos);
-}
-
-static void input_devices_seq_stop(struct seq_file *seq, void *v)
-{
-	/* release lock here */
-}
-
-static void input_seq_print_bitmap(struct seq_file *seq, const char *name,
-				   unsigned long *bitmap, int max)
-{
-	int i;
-
-	for (i = NBITS(max) - 1; i > 0; i--)
-		if (bitmap[i])
-			break;
-
-	seq_printf(seq, "B: %s=", name);
-	for (; i >= 0; i--)
-		seq_printf(seq, "%lx%s", bitmap[i], i > 0 ? " " : "");
-	seq_putc(seq, '\n');
-}
-
-static int input_devices_seq_show(struct seq_file *seq, void *v)
-{
-	struct input_dev *dev = container_of(v, struct input_dev, node);
-	const char *path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
-	struct input_handle *handle;
-
-	seq_printf(seq, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
-		   dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
-
-	seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
-	seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : "");
-	seq_printf(seq, "S: Sysfs=%s\n", path ? path : "");
-	seq_printf(seq, "H: Handlers=");
-
-	list_for_each_entry(handle, &dev->h_list, d_node)
-		seq_printf(seq, "%s ", handle->name);
-	seq_putc(seq, '\n');
-
-	input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX);
-	if (test_bit(EV_KEY, dev->evbit))
-		input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX);
-	if (test_bit(EV_REL, dev->evbit))
-		input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX);
-	if (test_bit(EV_ABS, dev->evbit))
-		input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX);
-	if (test_bit(EV_MSC, dev->evbit))
-		input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX);
-	if (test_bit(EV_LED, dev->evbit))
-		input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX);
-	if (test_bit(EV_SND, dev->evbit))
-		input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX);
-	if (test_bit(EV_FF, dev->evbit))
-		input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX);
-	if (test_bit(EV_SW, dev->evbit))
-		input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX);
-
-	seq_putc(seq, '\n');
-
-	kfree(path);
-	return 0;
-}
-
-static struct seq_operations input_devices_seq_ops = {
-	.start	= input_devices_seq_start,
-	.next	= input_devices_seq_next,
-	.stop	= input_devices_seq_stop,
-	.show	= input_devices_seq_show,
-};
-
-static int input_proc_devices_open(struct inode *inode, struct file *file)
-{
-	return seq_open(file, &input_devices_seq_ops);
-}
-
-static struct file_operations input_devices_fileops = {
-	.owner		= THIS_MODULE,
-	.open		= input_proc_devices_open,
-	.poll		= input_proc_devices_poll,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= seq_release,
-};
-
-static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
-{
-	/* acquire lock here ... Yes, we do need locking, I knowi, I know... */
-	seq->private = (void *)(unsigned long)*pos;
-	return list_get_nth_element(&input_handler_list, pos);
-}
-
-static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos)
-{
-	seq->private = (void *)(unsigned long)(*pos + 1);
-	return list_get_next_element(&input_handler_list, v, pos);
-}
-
-static void input_handlers_seq_stop(struct seq_file *seq, void *v)
-{
-	/* release lock here */
-}
-
-static int input_handlers_seq_show(struct seq_file *seq, void *v)
-{
-	struct input_handler *handler = container_of(v, struct input_handler, node);
-
-	seq_printf(seq, "N: Number=%ld Name=%s",
-		   (unsigned long)seq->private, handler->name);
-	if (handler->fops)
-		seq_printf(seq, " Minor=%d", handler->minor);
-	seq_putc(seq, '\n');
-
-	return 0;
-}
-static struct seq_operations input_handlers_seq_ops = {
-	.start	= input_handlers_seq_start,
-	.next	= input_handlers_seq_next,
-	.stop	= input_handlers_seq_stop,
-	.show	= input_handlers_seq_show,
-};
-
-static int input_proc_handlers_open(struct inode *inode, struct file *file)
-{
-	return seq_open(file, &input_handlers_seq_ops);
-}
-
-static struct file_operations input_handlers_fileops = {
-	.owner		= THIS_MODULE,
-	.open		= input_proc_handlers_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= seq_release,
-};
-
-static int __init input_proc_init(void)
-{
-	struct proc_dir_entry *entry;
-
-	proc_bus_input_dir = proc_mkdir("input", proc_bus);
-	if (!proc_bus_input_dir)
-		return -ENOMEM;
-
-	proc_bus_input_dir->owner = THIS_MODULE;
-
-	entry = create_proc_entry("devices", 0, proc_bus_input_dir);
-	if (!entry)
-		goto fail1;
-
-	entry->owner = THIS_MODULE;
-	entry->proc_fops = &input_devices_fileops;
-
-	entry = create_proc_entry("handlers", 0, proc_bus_input_dir);
-	if (!entry)
-		goto fail2;
-
-	entry->owner = THIS_MODULE;
-	entry->proc_fops = &input_handlers_fileops;
-
-	return 0;
-
- fail2:	remove_proc_entry("devices", proc_bus_input_dir);
- fail1: remove_proc_entry("input", proc_bus);
-	return -ENOMEM;
-}
-
-static void input_proc_exit(void)
-{
-	remove_proc_entry("devices", proc_bus_input_dir);
-	remove_proc_entry("handlers", proc_bus_input_dir);
-	remove_proc_entry("input", proc_bus);
-}
-
-#else /* !CONFIG_PROC_FS */
-static inline void input_wakeup_procfs_readers(void) { }
-static inline int input_proc_init(void) { return 0; }
-static inline void input_proc_exit(void) { }
-#endif
-
-#define INPUT_DEV_STRING_ATTR_SHOW(name)					\
-static ssize_t input_dev_show_##name(struct class_device *dev, char *buf)	\
-{										\
-	struct input_dev *input_dev = to_input_dev(dev);			\
-	int retval;								\
-										\
-	retval = mutex_lock_interruptible(&input_dev->mutex);			\
-	if (retval)								\
-		return retval;							\
-										\
-	retval = scnprintf(buf, PAGE_SIZE,					\
-			   "%s\n", input_dev->name ? input_dev->name : "");	\
-										\
-	mutex_unlock(&input_dev->mutex);					\
-										\
-	return retval;								\
-}										\
-static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL);
-
-INPUT_DEV_STRING_ATTR_SHOW(name);
-INPUT_DEV_STRING_ATTR_SHOW(phys);
-INPUT_DEV_STRING_ATTR_SHOW(uniq);
-
-static int input_print_modalias_bits(char *buf, int size,
-				     char name, unsigned long *bm,
-				     unsigned int min_bit, unsigned int max_bit)
-{
-	int len = 0, i;
-
-	len += snprintf(buf, max(size, 0), "%c", name);
-	for (i = min_bit; i < max_bit; i++)
-		if (bm[LONG(i)] & BIT(i))
-			len += snprintf(buf + len, max(size - len, 0), "%X,", i);
-	return len;
-}
-
-static int input_print_modalias(char *buf, int size, struct input_dev *id,
-				int add_cr)
-{
-	int len;
-
-	len = snprintf(buf, max(size, 0),
-		       "input:b%04Xv%04Xp%04Xe%04X-",
-		       id->id.bustype, id->id.vendor,
-		       id->id.product, id->id.version);
-
-	len += input_print_modalias_bits(buf + len, size - len,
-				'e', id->evbit, 0, EV_MAX);
-	len += input_print_modalias_bits(buf + len, size - len,
-				'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX);
-	len += input_print_modalias_bits(buf + len, size - len,
-				'r', id->relbit, 0, REL_MAX);
-	len += input_print_modalias_bits(buf + len, size - len,
-				'a', id->absbit, 0, ABS_MAX);
-	len += input_print_modalias_bits(buf + len, size - len,
-				'm', id->mscbit, 0, MSC_MAX);
-	len += input_print_modalias_bits(buf + len, size - len,
-				'l', id->ledbit, 0, LED_MAX);
-	len += input_print_modalias_bits(buf + len, size - len,
-				's', id->sndbit, 0, SND_MAX);
-	len += input_print_modalias_bits(buf + len, size - len,
-				'f', id->ffbit, 0, FF_MAX);
-	len += input_print_modalias_bits(buf + len, size - len,
-				'w', id->swbit, 0, SW_MAX);
-
-	if (add_cr)
-		len += snprintf(buf + len, max(size - len, 0), "\n");
-
-	return len;
-}
-
-static ssize_t input_dev_show_modalias(struct class_device *dev, char *buf)
-{
-	struct input_dev *id = to_input_dev(dev);
-	ssize_t len;
-
-	len = input_print_modalias(buf, PAGE_SIZE, id, 1);
-
-	return max_t(int, len, PAGE_SIZE);
-}
-static CLASS_DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
-
-static struct attribute *input_dev_attrs[] = {
-	&class_device_attr_name.attr,
-	&class_device_attr_phys.attr,
-	&class_device_attr_uniq.attr,
-	&class_device_attr_modalias.attr,
-	NULL
-};
-
-static struct attribute_group input_dev_attr_group = {
-	.attrs	= input_dev_attrs,
-};
-
-#define INPUT_DEV_ID_ATTR(name)							\
-static ssize_t input_dev_show_id_##name(struct class_device *dev, char *buf)	\
-{										\
-	struct input_dev *input_dev = to_input_dev(dev);			\
-	return scnprintf(buf, PAGE_SIZE, "%04x\n", input_dev->id.name);		\
-}										\
-static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL);
-
-INPUT_DEV_ID_ATTR(bustype);
-INPUT_DEV_ID_ATTR(vendor);
-INPUT_DEV_ID_ATTR(product);
-INPUT_DEV_ID_ATTR(version);
-
-static struct attribute *input_dev_id_attrs[] = {
-	&class_device_attr_bustype.attr,
-	&class_device_attr_vendor.attr,
-	&class_device_attr_product.attr,
-	&class_device_attr_version.attr,
-	NULL
-};
-
-static struct attribute_group input_dev_id_attr_group = {
-	.name	= "id",
-	.attrs	= input_dev_id_attrs,
-};
-
-static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap,
-			      int max, int add_cr)
-{
-	int i;
-	int len = 0;
-
-	for (i = NBITS(max) - 1; i > 0; i--)
-		if (bitmap[i])
-			break;
-
-	for (; i >= 0; i--)
-		len += snprintf(buf + len, max(buf_size - len, 0),
-				"%lx%s", bitmap[i], i > 0 ? " " : "");
-
-	if (add_cr)
-		len += snprintf(buf + len, max(buf_size - len, 0), "\n");
-
-	return len;
-}
-
-#define INPUT_DEV_CAP_ATTR(ev, bm)						\
-static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf)	\
-{										\
-	struct input_dev *input_dev = to_input_dev(dev);			\
-	int len = input_print_bitmap(buf, PAGE_SIZE,				\
-				     input_dev->bm##bit, ev##_MAX, 1);		\
-	return min_t(int, len, PAGE_SIZE);					\
-}										\
-static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL);
-
-INPUT_DEV_CAP_ATTR(EV, ev);
-INPUT_DEV_CAP_ATTR(KEY, key);
-INPUT_DEV_CAP_ATTR(REL, rel);
-INPUT_DEV_CAP_ATTR(ABS, abs);
-INPUT_DEV_CAP_ATTR(MSC, msc);
-INPUT_DEV_CAP_ATTR(LED, led);
-INPUT_DEV_CAP_ATTR(SND, snd);
-INPUT_DEV_CAP_ATTR(FF, ff);
-INPUT_DEV_CAP_ATTR(SW, sw);
-
-static struct attribute *input_dev_caps_attrs[] = {
-	&class_device_attr_ev.attr,
-	&class_device_attr_key.attr,
-	&class_device_attr_rel.attr,
-	&class_device_attr_abs.attr,
-	&class_device_attr_msc.attr,
-	&class_device_attr_led.attr,
-	&class_device_attr_snd.attr,
-	&class_device_attr_ff.attr,
-	&class_device_attr_sw.attr,
-	NULL
-};
-
-static struct attribute_group input_dev_caps_attr_group = {
-	.name	= "capabilities",
-	.attrs	= input_dev_caps_attrs,
-};
-
-static void input_dev_release(struct class_device *class_dev)
-{
-	struct input_dev *dev = to_input_dev(class_dev);
-
-	kfree(dev);
-	module_put(THIS_MODULE);
-}
-
-/*
- * Input uevent interface - loading event handlers based on
- * device bitfields.
- */
-static int input_add_uevent_bm_var(char **envp, int num_envp, int *cur_index,
-				   char *buffer, int buffer_size, int *cur_len,
-				   const char *name, unsigned long *bitmap, int max)
-{
-	if (*cur_index >= num_envp - 1)
-		return -ENOMEM;
-
-	envp[*cur_index] = buffer + *cur_len;
-
-	*cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0), name);
-	if (*cur_len >= buffer_size)
-		return -ENOMEM;
-
-	*cur_len += input_print_bitmap(buffer + *cur_len,
-					max(buffer_size - *cur_len, 0),
-					bitmap, max, 0) + 1;
-	if (*cur_len > buffer_size)
-		return -ENOMEM;
-
-	(*cur_index)++;
-	return 0;
-}
-
-static int input_add_uevent_modalias_var(char **envp, int num_envp, int *cur_index,
-					 char *buffer, int buffer_size, int *cur_len,
-					 struct input_dev *dev)
-{
-	if (*cur_index >= num_envp - 1)
-		return -ENOMEM;
-
-	envp[*cur_index] = buffer + *cur_len;
-
-	*cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0),
-			     "MODALIAS=");
-	if (*cur_len >= buffer_size)
-		return -ENOMEM;
-
-	*cur_len += input_print_modalias(buffer + *cur_len,
-					 max(buffer_size - *cur_len, 0),
-					 dev, 0) + 1;
-	if (*cur_len > buffer_size)
-		return -ENOMEM;
-
-	(*cur_index)++;
-	return 0;
-}
-
-#define INPUT_ADD_HOTPLUG_VAR(fmt, val...)				\
-	do {								\
-		int err = add_uevent_var(envp, num_envp, &i,		\
-					buffer, buffer_size, &len,	\
-					fmt, val);			\
-		if (err)						\
-			return err;					\
-	} while (0)
-
-#define INPUT_ADD_HOTPLUG_BM_VAR(name, bm, max)				\
-	do {								\
-		int err = input_add_uevent_bm_var(envp, num_envp, &i,	\
-					buffer, buffer_size, &len,	\
-					name, bm, max);			\
-		if (err)						\
-			return err;					\
-	} while (0)
-
-#define INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev)				\
-	do {								\
-		int err = input_add_uevent_modalias_var(envp,		\
-					num_envp, &i,			\
-					buffer, buffer_size, &len,	\
-					dev);				\
-		if (err)						\
-			return err;					\
-	} while (0)
-
-static int input_dev_uevent(struct class_device *cdev, char **envp,
-			    int num_envp, char *buffer, int buffer_size)
-{
-	struct input_dev *dev = to_input_dev(cdev);
-	int i = 0;
-	int len = 0;
-
-	INPUT_ADD_HOTPLUG_VAR("PRODUCT=%x/%x/%x/%x",
-				dev->id.bustype, dev->id.vendor,
-				dev->id.product, dev->id.version);
-	if (dev->name)
-		INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name);
-	if (dev->phys)
-		INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys);
-	if (dev->uniq)
-		INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq);
-
-	INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX);
-	if (test_bit(EV_KEY, dev->evbit))
-		INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX);
-	if (test_bit(EV_REL, dev->evbit))
-		INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX);
-	if (test_bit(EV_ABS, dev->evbit))
-		INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX);
-	if (test_bit(EV_MSC, dev->evbit))
-		INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX);
-	if (test_bit(EV_LED, dev->evbit))
-		INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX);
-	if (test_bit(EV_SND, dev->evbit))
-		INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX);
-	if (test_bit(EV_FF, dev->evbit))
-		INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX);
-	if (test_bit(EV_SW, dev->evbit))
-		INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX);
-
-	INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev);
-
-	envp[i] = NULL;
-	return 0;
-}
-
-struct class input_class = {
-	.name			= "input",
-	.release		= input_dev_release,
-	.uevent			= input_dev_uevent,
-};
-
-struct input_dev *input_allocate_device(void)
-{
-	struct input_dev *dev;
-
-	dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
-	if (dev) {
-		dev->dynalloc = 1;
-		dev->cdev.class = &input_class;
-		class_device_initialize(&dev->cdev);
-		INIT_LIST_HEAD(&dev->h_list);
-		INIT_LIST_HEAD(&dev->node);
-	}
-
-	return dev;
-}
-
-int input_register_device(struct input_dev *dev)
-{
-	static atomic_t input_no = ATOMIC_INIT(0);
-	struct input_handle *handle;
-	struct input_handler *handler;
-	struct input_device_id *id;
-	const char *path;
-	int error;
-
-	if (!dev->dynalloc) {
-		printk(KERN_WARNING "input: device %s is statically allocated, will not register\n"
-			"Please convert to input_allocate_device() or contact [email protected]\n",
-			dev->name ? dev->name : "<Unknown>");
-		return -EINVAL;
-	}
-
-	mutex_init(&dev->mutex);
-	set_bit(EV_SYN, dev->evbit);
-
-	/*
-	 * If delay and period are pre-set by the driver, then autorepeating
-	 * is handled by the driver itself and we don't do it in input.c.
-	 */
-
-	init_timer(&dev->timer);
-	if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
-		dev->timer.data = (long) dev;
-		dev->timer.function = input_repeat_key;
-		dev->rep[REP_DELAY] = 250;
-		dev->rep[REP_PERIOD] = 33;
-	}
-
-	INIT_LIST_HEAD(&dev->h_list);
-	list_add_tail(&dev->node, &input_dev_list);
-
-	dev->cdev.class = &input_class;
-	snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
-		 "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1);
-
-	error = class_device_add(&dev->cdev);
-	if (error)
-		return error;
-
-	error = sysfs_create_group(&dev->cdev.kobj, &input_dev_attr_group);
-	if (error)
-		goto fail1;
-
-	error = sysfs_create_group(&dev->cdev.kobj, &input_dev_id_attr_group);
-	if (error)
-		goto fail2;
-
-	error = sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
-	if (error)
-		goto fail3;
-
-	__module_get(THIS_MODULE);
-
-	path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
-	printk(KERN_INFO "input: %s as %s\n",
-		dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
-	kfree(path);
-
-	list_for_each_entry(handler, &input_handler_list, node)
-		if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
-			if ((id = input_match_device(handler->id_table, dev)))
-				if ((handle = handler->connect(handler, dev, id)))
-					input_link_handle(handle);
-
-	input_wakeup_procfs_readers();
-
-	return 0;
-
- fail3:	sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
- fail2:	sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
- fail1:	class_device_del(&dev->cdev);
-	return error;
-}
-
-void input_unregister_device(struct input_dev *dev)
-{
-	struct list_head * node, * next;
-
-	if (!dev) return;
-
-	del_timer_sync(&dev->timer);
-
-	list_for_each_safe(node, next, &dev->h_list) {
-		struct input_handle * handle = to_handle(node);
-		list_del_init(&handle->d_node);
-		list_del_init(&handle->h_node);
-		handle->handler->disconnect(handle);
-	}
-
-	list_del_init(&dev->node);
-
-	sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
-	sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
-	sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
-	class_device_unregister(&dev->cdev);
-
-	input_wakeup_procfs_readers();
-}
-
-void input_register_handler(struct input_handler *handler)
-{
-	struct input_dev *dev;
-	struct input_handle *handle;
-	struct input_device_id *id;
-
-	if (!handler) return;
-
-	INIT_LIST_HEAD(&handler->h_list);
-
-	if (handler->fops != NULL)
-		input_table[handler->minor >> 5] = handler;
-
-	list_add_tail(&handler->node, &input_handler_list);
-
-	list_for_each_entry(dev, &input_dev_list, node)
-		if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
-			if ((id = input_match_device(handler->id_table, dev)))
-				if ((handle = handler->connect(handler, dev, id)))
-					input_link_handle(handle);
-
-	input_wakeup_procfs_readers();
-}
-
-void input_unregister_handler(struct input_handler *handler)
-{
-	struct list_head * node, * next;
-
-	list_for_each_safe(node, next, &handler->h_list) {
-		struct input_handle * handle = to_handle_h(node);
-		list_del_init(&handle->h_node);
-		list_del_init(&handle->d_node);
-		handler->disconnect(handle);
-	}
-
-	list_del_init(&handler->node);
-
-	if (handler->fops != NULL)
-		input_table[handler->minor >> 5] = NULL;
-
-	input_wakeup_procfs_readers();
-}
-
-static int input_open_file(struct inode *inode, struct file *file)
-{
-	struct input_handler *handler = input_table[iminor(inode) >> 5];
-	const struct file_operations *old_fops, *new_fops = NULL;
-	int err;
-
-	/* No load-on-demand here? */
-	if (!handler || !(new_fops = fops_get(handler->fops)))
-		return -ENODEV;
-
-	/*
-	 * That's _really_ odd. Usually NULL ->open means "nothing special",
-	 * not "no device". Oh, well...
-	 */
-	if (!new_fops->open) {
-		fops_put(new_fops);
-		return -ENODEV;
-	}
-	old_fops = file->f_op;
-	file->f_op = new_fops;
-
-	err = new_fops->open(inode, file);
-
-	if (err) {
-		fops_put(file->f_op);
-		file->f_op = fops_get(old_fops);
-	}
-	fops_put(old_fops);
-	return err;
-}
-
-static struct file_operations input_fops = {
-	.owner = THIS_MODULE,
-	.open = input_open_file,
-};
-
-static int __init input_init(void)
-{
-	int err;
-
-	err = class_register(&input_class);
-	if (err) {
-		printk(KERN_ERR "input: unable to register input_dev class\n");
-		return err;
-	}
-
-	err = input_proc_init();
-	if (err)
-		goto fail1;
-
-	err = register_chrdev(INPUT_MAJOR, "input", &input_fops);
-	if (err) {
-		printk(KERN_ERR "input: unable to register char major %d", INPUT_MAJOR);
-		goto fail2;
-	}
-
-	return 0;
-
- fail2:	input_proc_exit();
- fail1:	class_unregister(&input_class);
-	return err;
-}
-
-static void __exit input_exit(void)
-{
-	input_proc_exit();
-	unregister_chrdev(INPUT_MAJOR, "input");
-	class_unregister(&input_class);
-}
-
-subsys_initcall(input_init);
-module_exit(input_exit);
drivers/input/input-core.c new file +1099 -0

1,099 lines not on this page · raw message

drivers/input/Makefile +2 -0
Index: linux-2.6.17-rc4-git12/drivers/input/Makefile
===================================================================
@@ -4,6 +4,8 @@
 
 # Each configuration option enables a list of files.
 
+input-objs			:= input-core.o
+
 obj-$(CONFIG_INPUT)		+= input.o
 obj-$(CONFIG_INPUT_MOUSEDEV)	+= mousedev.o
 obj-$(CONFIG_INPUT_JOYDEV)	+= joydev.o

--
Anssi Hannula

#4 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 10 lines · Anssi Hannula

Move the input.c to input-core.c and modify Makefile so that the input module can be built from multiple source files. This is preparing for the input-ff.c.

---
 drivers/input/Makefile     |    2 
 drivers/input/input-core.c | 1099 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/input/input.c      | 1099 ---------------------------------------------

urgh. There are other changes pending againt input.c and this renaming makes everything a huge pain.

What does "can be built from multiple source files" mean?

It would be much nicer all round if we could avoid renaming this file.

#5 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 12 lines · Andrew Morton
Quoted 9 lines · Anssi Hannula

Move the input.c to input-core.c and modify Makefile so that the input module can be built from multiple source files. This is preparing for the input-ff.c.

---

drivers/input/Makefile     |    2 
drivers/input/input-core.c | 1099 +++++++++++++++++++++++++++++++++++++++++++++
drivers/input/input.c      | 1099 ---------------------------------------------
Quoted 4 lines

urgh. There are other changes pending againt input.c and this renaming makes everything a huge pain.

What does "can be built from multiple source files" mean?

Well, I want to embed the input-ff.c into the input module too.

Quoted 1 line

It would be much nicer all round if we could avoid renaming this file.

Indeed... There are these 4 options as far as I see:

1. Do this rename
2. Put all the code in input-ff.c to input.c
3. Make the input-ff a separate bool "module" and add EXPORT_SYMBOL_GPL() for input_ff_event() which is currently the only function in input-ff.c that is called from input.c
4. Rename the input "module" to something else, it doesn't matter so much as almost everybody builds it as built-in anyway.

WDYT is the best one?

Signature · 1 line
Anssi Hannula
#6 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 14 lines · Anssi Hannula
Quoted 12 lines · Andrew Morton
Quoted 9 lines · Anssi Hannula

Move the input.c to input-core.c and modify Makefile so that the input module can be built from multiple source files. This is preparing for the input-ff.c.

---

drivers/input/Makefile     |    2 
drivers/input/input-core.c | 1099 +++++++++++++++++++++++++++++++++++++++++++++
drivers/input/input.c      | 1099 ---------------------------------------------
Quoted 6 lines
Quoted 4 lines

urgh. There are other changes pending againt input.c and this renaming makes everything a huge pain.

What does "can be built from multiple source files" mean?

Well, I want to embed the input-ff.c into the input module too.

What does "embed" mean? #include a .c file, or what? (If "yes" then "no", there's enough of that happening and it's an awful thing to do).

Quoted 12 lines
Quoted 1 line

It would be much nicer all round if we could avoid renaming this file.

Indeed... There are these 4 options as far as I see:

1. Do this rename
2. Put all the code in input-ff.c to input.c
3. Make the input-ff a separate bool "module" and add EXPORT_SYMBOL_GPL() for input_ff_event() which is currently the only function in input-ff.c that is called from input.c
4. Rename the input "module" to something else, it doesn't matter so much as almost everybody builds it as built-in anyway.

Quoted 1 line

WDYT is the best one?

I still don't know what problem you're trying to solve so I cannot say.

#7 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 20 lines · Andrew Morton
Quoted 18 lines · Anssi Hannula
Quoted 16 lines · Andrew Morton
Quoted 9 lines · Anssi Hannula

Move the input.c to input-core.c and modify Makefile so that the input module can be built from multiple source files. This is preparing for the input-ff.c.

---

drivers/input/Makefile     |    2 
drivers/input/input-core.c | 1099 +++++++++++++++++++++++++++++++++++++++++++++
drivers/input/input.c      | 1099 ---------------------------------------------

urgh. There are other changes pending againt input.c and this renaming makes everything a huge pain.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

What does "can be built from multiple source files" mean?

Well, I want to embed the input-ff.c into the input module too.

What does "embed" mean? #include a .c file, or what? (If "yes" then "no", there's enough of that happening and it's an awful thing to do).

No, but this (from Documentation/kbuild/makefiles.txt):
<clip>
If a kernel module is built from several source files, you specify that you want to build a module in the same way as above.

Kbuild needs to know which the parts that you want to build your module from, so you have to tell it by setting an $(<module_name>-objs) variable.

Example:
#drivers/isdn/i4l/Makefile obj-$(CONFIG_ISDN) += isdn.o
isdn-objs := isdn_net_lib.o isdn_v110.o isdn_common.o

In this example, the module name will be isdn.o. Kbuild will compile the objects listed in $(isdn-objs) and then run "$(LD) -r" on the list of these files to generate isdn.o.
</clip>

input.o would be the "module" name, and it would be by default build from input-core.o, and if INPUT_FF_EFFECTS is enabled, then also input-ff.o.

Then any functions in input-ff.c that are called from input-core.c would not need to be EXPORT_SYMBOLed to the rest of the kernel.

Note especially that the module name of such module can't be the same as one of the source files that the module is built from (I tried). That's the reason for the rename.

Quoted 12 lines
Quoted 12 lines
Quoted 1 line

It would be much nicer all round if we could avoid renaming this file.

Indeed... There are these 4 options as far as I see:

1. Do this rename
2. Put all the code in input-ff.c to input.c
3. Make the input-ff a separate bool "module" and add EXPORT_SYMBOL_GPL() for input_ff_event() which is currently the only function in input-ff.c that is called from input.c
4. Rename the input "module" to something else, it doesn't matter so much as almost everybody builds it as built-in anyway.

Quoted 4 lines
Quoted 1 line

WDYT is the best one?

I still don't know what problem you're trying to solve so I cannot say.

Maybe you know now.

Signature · 1 line
Anssi Hannula
#8 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 14 lines · Anssi Hannula
Quoted 14 lines
Quoted 14 lines
Quoted 3 lines

It would be much nicer all round if we could avoid renaming this file.

Indeed... There are these 4 options as far as I see:

1. Do this rename
2. Put all the code in input-ff.c to input.c
3. Make the input-ff a separate bool "module" and add EXPORT_SYMBOL_GPL() for input_ff_event() which is currently the only function in input-ff.c that is called from input.c
4. Rename the input "module" to something else, it doesn't matter so much as almost everybody builds it as built-in anyway.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

WDYT is the best one?

I still don't know what problem you're trying to solve so I cannot say.

Maybe you know now.

yup, thanks.

I'd have thought that 3) is the path of least resistance.

But it does require that input.c "knows" that input-ff.c was included in the build, which is not a thing we like to do.

Why should things in input.c call into input-ff.c, btw? The way we normally would handle that is to add a register_something() API to input.c and input-ff.c would insert its callback via that interface.

#9 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 23 lines · Andrew Morton
Quoted 13 lines · Anssi Hannula
Quoted 13 lines
Quoted 13 lines
Quoted 2 lines

It would be much nicer all round if we could avoid renaming this file.

Indeed... There are these 4 options as far as I see:

1. Do this rename
2. Put all the code in input-ff.c to input.c
3. Make the input-ff a separate bool "module" and add EXPORT_SYMBOL_GPL() for input_ff_event() which is currently the only function in input-ff.c that is called from input.c
4. Rename the input "module" to something else, it doesn't matter so much as almost everybody builds it as built-in anyway.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

WDYT is the best one?

I still don't know what problem you're trying to solve so I cannot say.

Maybe you know now.

Quoted 6 lines

yup, thanks.

I'd have thought that 3) is the path of least resistance.

But it does require that input.c "knows" that input-ff.c was included in the build, which is not a thing we like to do.

Well, it's going to be included as built-in and can't be built as a module at all, so I think it's okay for us to do so?

Quoted 3 lines

Why should things in input.c call into input-ff.c, btw? The way we normally would handle that is to add a register_something() API to input.c and input-ff.c would insert its callback via that interface.

Yes, we could easily add a callback to e.g. struct input_dev, but is that really preferred if the input-ff.c is built-in?

And it's built-in only because: If I were to implement register_something() stuff for this, no module would require input-ff and it would not be loaded, even if there are ff-capable device drivers present.

Signature · 1 line
Anssi Hannula
#10 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 27 lines · Anssi Hannula
Quoted 25 lines · Andrew Morton
Quoted 13 lines · Anssi Hannula
Quoted 13 lines
Quoted 13 lines
Quoted 2 lines

It would be much nicer all round if we could avoid renaming this file.

Indeed... There are these 4 options as far as I see:

1. Do this rename
2. Put all the code in input-ff.c to input.c
3. Make the input-ff a separate bool "module" and add EXPORT_SYMBOL_GPL() for input_ff_event() which is currently the only function in input-ff.c that is called from input.c
4. Rename the input "module" to something else, it doesn't matter so much as almost everybody builds it as built-in anyway.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

WDYT is the best one?

I still don't know what problem you're trying to solve so I cannot say.

Maybe you know now.

yup, thanks.

Quoted 7 lines
Quoted 4 lines

I'd have thought that 3) is the path of least resistance.

But it does require that input.c "knows" that input-ff.c was included in the build, which is not a thing we like to do.

Well, it's going to be included as built-in and can't be built as a module at all, so I think it's okay for us to do so?

If that's the case then no EXPORT_SYMBOL_GPL() is needed - we just link the the two .o files together, link the result into vmlinux?

Quoted 6 lines
Quoted 3 lines

Why should things in input.c call into input-ff.c, btw? The way we normally would handle that is to add a register_something() API to input.c and input-ff.c would insert its callback via that interface.

Yes, we could easily add a callback to e.g. struct input_dev, but is that really preferred if the input-ff.c is built-in?

Nope, not if they're as tightly-coupled as that.

However it still might not be _appropriate_ for the input core code to call into the force-feedback code in this manner. It certainly sounds unusual.

#11 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 34 lines · Andrew Morton
Quoted 32 lines · Anssi Hannula
Quoted 29 lines · Andrew Morton
Quoted 12 lines · Anssi Hannula
Quoted 12 lines
Quoted 12 lines
Quoted 1 line

It would be much nicer all round if we could avoid renaming this file.

Indeed... There are these 4 options as far as I see:

1. Do this rename
2. Put all the code in input-ff.c to input.c
3. Make the input-ff a separate bool "module" and add EXPORT_SYMBOL_GPL() for input_ff_event() which is currently the only function in input-ff.c that is called from input.c
4. Rename the input "module" to something else, it doesn't matter so much as almost everybody builds it as built-in anyway.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

WDYT is the best one?

I still don't know what problem you're trying to solve so I cannot say.

Maybe you know now.

yup, thanks.

I'd have thought that 3) is the path of least resistance.

But it does require that input.c "knows" that input-ff.c was included in the build, which is not a thing we like to do.

Quoted 7 lines
Quoted 2 lines

Well, it's going to be included as built-in and can't be built as a module at all, so I think it's okay for us to do so?

If that's the case then no EXPORT_SYMBOL_GPL() is needed - we just link the the two .o files together, link the result into vmlinux?

Probably so, I was under the false assumption that even built-in modules should use EXPORT_SYMBOL.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Why should things in input.c call into input-ff.c, btw? The way we normally would handle that is to add a register_something() API to input.c and input-ff.c would insert its callback via that interface.

Yes, we could easily add a callback to e.g. struct input_dev, but is that really preferred if the input-ff.c is built-in?

Nope, not if they're as tightly-coupled as that.

Actually, they don't call each others functions at all (except for the one we discuss below)... But if input-ff.o would be allowed as a module, device drivers would either need to know at the build time if input-ff.o is enabled (not an option, as it could be built as a module afterwards), _or_ query input.o if the input-ff.o is registered in. However the latter causes again the situation that nothing depends on input-ff.o and it is never loaded...

Quoted 3 lines

However it still might not be _appropriate_ for the input core code to call into the force-feedback code in this manner. It certainly sounds unusual.

I guess I could just use the normal event() handler in input_dev:
FF-capable input-drivers should assign input_ff_event() as the event() or call input_ff_event() in their own event() handler.

Hmm, just came to me mind that input.o can be built as module if EMBEDDED is set. But input-ff.o doesn't actually require input.o (it's just not useful without it), so input-ff.o as a built-in wouldn't be a problem. That's why I wanted them to be in a single module (so that if input.o is a module, input-ff.o would also be part of that module instead of being built-in). But I don't think there is someone who runs with EMBEDDED enabled, INPUT as a module, INPUT_FF_EFFECTS enabled, and doesn't like that input-ff.o cannot be built as a module.

So, I guess we go for a separate input-ff.o as a bool.

Unless you have any more thoughts, I'll make patches for (1) separate input-ff.o from input.o so that input.c renaming is not required, and to
(2) use the input_dev->event() handler instead of input.o calling input-ff.o.

Signature · 1 line
Anssi Hannula
#12 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 5 lines · Anssi Hannula

Unless you have any more thoughts, I'll make patches for (1) separate input-ff.o from input.o so that input.c renaming is not required, and to
(2) use the input_dev->event() handler instead of input.o calling input-ff.o.

Sounds good, thanks.

#13 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 9 lines · Andrew Morton
Quoted 4 lines · Anssi Hannula

Unless you have any more thoughts, I'll make patches for (1) separate input-ff.o from input.o so that input.c renaming is not required, and to
(2) use the input_dev->event() handler instead of input.o calling input-ff.o.

Sounds good, thanks.

Hmh, I guess I need to send the modified "input: new force feedback interface" patch fully again, as the previous patch patches input-core.c that doesn't exist if we drop the rename.

A final minor question: In your opinion is input-ff.c or ff-effects.c a better name? ;)

Signature · 1 line
Anssi Hannula
#14 lore raw

Re: [patch 03/13] input: make input a multi-object module

Quoted 10 lines · Anssi Hannula
Quoted 8 lines · Andrew Morton
Quoted 4 lines · Anssi Hannula

Unless you have any more thoughts, I'll make patches for (1) separate input-ff.o from input.o so that input.c renaming is not required, and to
(2) use the input_dev->event() handler instead of input.o calling input-ff.o.

Quoted 5 lines
Quoted 1 line

Sounds good, thanks.

Hmh, I guess I need to send the modified "input: new force feedback interface" patch fully again, as the previous patch patches input-core.c that doesn't exist if we drop the rename.

yup.

Quoted 2 lines

A final minor question: In your opinion is input-ff.c or ff-effects.c a better name? ;)

ff-effects.

#15 lore raw

PATCH 1/1 input: new force feedback interface

Implement a new force feedback interface, in which all non-driver-specific operations are separated to a common module. This module handles effect type validations, effect timers, locking, etc.

As a result, support is added for gain and envelope for memoryless devices, periodic => rumble conversion for memoryless devices and rumble => periodic conversion for devices with periodic support instead of rumble support. Also the effect memory of devices is not emptied if the root user opens and closes the device while another user is using effects. This module also obsoletes some flawed locking and timer code in few ff drivers.

The effects are now file descriptor specific instead of the previous strange half-process half-fd specific behaviour. This is a minor change and most likely no force feedback aware programs are affected by this negatively.

Otherwise the userspace interface is left unaltered.

The module is named ff-effects and can only be built as builtin. The code should really be a part of input module, but we want to avoid having to rename input.c.

---

This patch replaces the patches 3 and 4 of my last patchset.

 drivers/input/Kconfig      |    5
 drivers/input/Makefile     |    1
 drivers/input/evdev.c      |   30 -
 drivers/input/ff-effects.c |  894 +++++++++++++++++++++++++++++++++++
 drivers/input/input.c      |   12
 include/linux/input.h      |   81 +++
 6 files changed, 1006 insertions(+), 17 deletions(-)
drivers/input/Kconfig +5 -0
Index: linux-2.6.17-rc4-git12/drivers/input/Kconfig
===================================================================
@@ -24,6 +24,11 @@ config INPUT
 
 if INPUT
 
+config INPUT_FF_EFFECTS
+	bool "Force feedback effects"
+	help
+	  Say Y here if you want to be able to play force feedback effects.
+
 comment "Userland interfaces"
 
 config INPUT_MOUSEDEV
drivers/input/Makefile +1 -0
Index: linux-2.6.17-rc4-git12/drivers/input/Makefile
===================================================================
@@ -5,6 +5,7 @@
 # Each configuration option enables a list of files.
 
 obj-$(CONFIG_INPUT)		+= input.o
+obj-$(CONFIG_INPUT_FF_EFFECTS)	+= ff-effects.o
 obj-$(CONFIG_INPUT_MOUSEDEV)	+= mousedev.o
 obj-$(CONFIG_INPUT_JOYDEV)	+= joydev.o
 obj-$(CONFIG_INPUT_EVDEV)	+= evdev.o
include/linux/input.h +81 -0

93 lines not on this page · raw message

drivers/input/input.c +12 -0
Index: linux-2.6.17-rc4-git12/drivers/input/input.c
===================================================================
@@ -733,6 +733,17 @@ static void input_dev_release(struct cla
 {
 	struct input_dev *dev = to_input_dev(class_dev);
 
+	if (dev->ff) {
+		struct ff_device *ff = dev->ff;
+		clear_bit(EV_FF, dev->evbit);
+		mutex_lock(&dev->ff_lock);
+		del_timer_sync(&ff->timer);
+		dev->flush = NULL;
+		dev->ff = NULL;
+		mutex_unlock(&dev->ff_lock);
+		kfree(ff);
+	}
+
 	kfree(dev);
 	module_put(THIS_MODULE);
 }
@@ -874,6 +885,7 @@ struct input_dev *input_allocate_device(
 		class_device_initialize(&dev->cdev);
 		INIT_LIST_HEAD(&dev->h_list);
 		INIT_LIST_HEAD(&dev->node);
+		mutex_init(&dev->ff_lock);
 	}
 
 	return dev;
drivers/input/evdev.c +13 -17
Index: linux-2.6.17-rc4-git12/drivers/input/evdev.c
===================================================================
@@ -457,25 +457,21 @@ static long evdev_ioctl_handler(struct f
 
 			return 0;
 
-		case EVIOCSFF:
-			if (dev->upload_effect) {
-				struct ff_effect effect;
-				int err;
-
-				if (copy_from_user(&effect, p, sizeof(effect)))
-					return -EFAULT;
-				err = dev->upload_effect(dev, &effect);
-				if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
-					return -EFAULT;
-				return err;
-			} else
-				return -ENOSYS;
+		case EVIOCSFF: {
+			struct ff_effect effect;
+			int err;
 
-		case EVIOCRMFF:
-			if (!dev->erase_effect)
-				return -ENOSYS;
+			if (copy_from_user(&effect, p, sizeof(effect)))
+				return -EFAULT;
+			err = input_ff_upload(dev, &effect, file);
+			if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
+				return -EFAULT;
+			return err;
+		}
 
-			return dev->erase_effect(dev, (int)(unsigned long) p);
+		case EVIOCRMFF:
+			return input_ff_erase(dev, (int)(unsigned long) p,
+					      file);
 
 		case EVIOCGEFFECTS:
 			if (put_user(dev->ff_effects_max, ip))
drivers/input/ff-effects.c new file +894 -0

894 lines not on this page · raw message

#16 lore raw

PATCH 1/1 input: use event handler in ff drivers

In reply to Andrew Morton

Call input_ff_event() from drivers when they receive EV_FF event through event() of struct input_dev.

---

This is to be applied after other patches in my last patchset.

 input/joystick/iforce/iforce-main.c |    1 +
 input/misc/uinput.c                 |    3 +++
 usb/input/hid-input.c               |    3 +++
 3 files changed, 7 insertions(+)
drivers/usb/input/hid-input.c +3 -0
Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid-input.c
===================================================================
@@ -717,6 +717,9 @@ static int hidinput_input_event(struct i
 	struct hid_field *field;
 	int offset;
 
+	if (type == EV_FF)
+		return input_ff_event(dev, type, code, value);
+
 	if (type != EV_LED)
 		return -1;
 
drivers/input/joystick/iforce/iforce-main.c +1 -0
Index: linux-2.6.17-rc4-git12/drivers/input/joystick/iforce/iforce-main.c
===================================================================
@@ -306,6 +306,7 @@ int iforce_init_device(struct iforce *if
 	input_dev->name = "Unknown I-Force device";
 	input_dev->open = iforce_open;
 	input_dev->close = iforce_release;
+	input_dev->event = input_ff_event;
 	if (!ff_err)
 		input_dev->ff_effects_max = 10;
 
drivers/input/misc/uinput.c +3 -0
Index: linux-2.6.17-rc4-git12/drivers/input/misc/uinput.c
===================================================================
@@ -43,6 +43,9 @@ static int uinput_dev_event(struct input
 {
 	struct uinput_device	*udev;
 
+	if (type == EV_FF)
+		return input_ff_event(dev, type, code, value);
+
 	udev = dev->private;
 
 	udev->buff[udev->head].type = type;
#17 lore raw

PATCH 4/13 input: new force feedback interface

In reply to Anssi Hannula

Implement a new force feedback interface, in which all non-driver-specific operations are separated to to the input module. This includes handling effect type validations, effect timers, locking, etc.

As a result, support is added for gain and envelope for memoryless devices, periodic => rumble conversion for memoryless devices and rumble => periodic conversion for devices with periodic support instead of rumble support. Also the effect memory of devices is not emptied if the root user opens and closes the device while another user is using effects. This module also obsoletes some flawed locking and timer code in few ff drivers.

The effects are now file descriptor specific instead of the previous strange half-process half-fd specific behaviour. This is a minor change and most likely no force feedback aware programs are affected by this negatively.

Otherwise the userspace interface is left unaltered.

The code will be built into the input module.

---
 drivers/input/Kconfig      |    5 
 drivers/input/Makefile     |    3 
 drivers/input/evdev.c      |   30 -
 drivers/input/input-core.c |   15 
 drivers/input/input-ff.c   |  889 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/input/input-ff.h   |   34 +
 include/linux/input.h      |   61 +++
 7 files changed, 1019 insertions(+), 18 deletions(-)
drivers/input/Kconfig +5 -0
Index: linux-2.6.17-rc4-git12/drivers/input/Kconfig
===================================================================
@@ -24,6 +24,11 @@ config INPUT
 
 if INPUT
 
+config INPUT_FF_EFFECTS
+	bool "Force feedback effects"
+	help
+	  Say Y here if you want to be able to play force feedback effects.
+
 comment "Userland interfaces"
 
 config INPUT_MOUSEDEV
drivers/input/Makefile +3 -0
Index: linux-2.6.17-rc4-git12/drivers/input/Makefile
===================================================================
@@ -5,6 +5,9 @@
 # Each configuration option enables a list of files.
 
 input-objs			:= input-core.o
+ifeq ($(CONFIG_INPUT_FF_EFFECTS),y)
+	input-objs		+= input-ff.o
+endif
 
 obj-$(CONFIG_INPUT)		+= input.o
 obj-$(CONFIG_INPUT_MOUSEDEV)	+= mousedev.o
include/linux/input.h +61 -0

73 lines not on this page · raw message

drivers/input/input-core.c +14 -1
Index: linux-2.6.17-rc4-git12/drivers/input/input-core.c
===================================================================
@@ -23,6 +23,7 @@
 #include <linux/poll.h>
 #include <linux/device.h>
 #include <linux/mutex.h>
+#include "input-ff.h"
 
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
 MODULE_DESCRIPTION("Input core");
@@ -172,7 +173,7 @@ void input_event(struct input_dev *dev, 
 			break;
 
 		case EV_FF:
-			if (dev->event) dev->event(dev, type, code, value);
+			input_ff_event(dev, type, code, value);
 			break;
 	}
 
@@ -733,6 +734,17 @@ static void input_dev_release(struct cla
 {
 	struct input_dev *dev = to_input_dev(class_dev);
 
+	if (dev->ff) {
+		struct ff_device *ff = dev->ff;
+		clear_bit(EV_FF, dev->evbit);
+		mutex_lock(&dev->ff_lock);
+		del_timer_sync(&ff->timer);
+		dev->flush = NULL;
+		dev->ff = NULL;
+		mutex_unlock(&dev->ff_lock);
+		kfree(ff);
+	}
+
 	kfree(dev);
 	module_put(THIS_MODULE);
 }
@@ -874,6 +886,7 @@ struct input_dev *input_allocate_device(
 		class_device_initialize(&dev->cdev);
 		INIT_LIST_HEAD(&dev->h_list);
 		INIT_LIST_HEAD(&dev->node);
+		mutex_init(&dev->ff_lock);
 	}
 
 	return dev;
drivers/input/evdev.c +13 -17
Index: linux-2.6.17-rc4-git12/drivers/input/evdev.c
===================================================================
@@ -457,25 +457,21 @@ static long evdev_ioctl_handler(struct f
 
 			return 0;
 
-		case EVIOCSFF:
-			if (dev->upload_effect) {
-				struct ff_effect effect;
-				int err;
-
-				if (copy_from_user(&effect, p, sizeof(effect)))
-					return -EFAULT;
-				err = dev->upload_effect(dev, &effect);
-				if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
-					return -EFAULT;
-				return err;
-			} else
-				return -ENOSYS;
+		case EVIOCSFF: {
+			struct ff_effect effect;
+			int err;
 
-		case EVIOCRMFF:
-			if (!dev->erase_effect)
-				return -ENOSYS;
+			if (copy_from_user(&effect, p, sizeof(effect)))
+				return -EFAULT;
+			err = input_ff_upload(dev, &effect, file);
+			if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
+				return -EFAULT;
+			return err;
+		}
 
-			return dev->erase_effect(dev, (int)(unsigned long) p);
+		case EVIOCRMFF:
+			return input_ff_erase(dev, (int)(unsigned long) p,
+					      file);
 
 		case EVIOCGEFFECTS:
 			if (put_user(dev->ff_effects_max, ip))
drivers/input/input-ff.c new file +889 -0

889 lines not on this page · raw message

drivers/input/input-ff.h new file +34 -0
Index: linux-2.6.17-rc4-git12/drivers/input/input-ff.h
===================================================================
@@ -0,0 +1,34 @@
+
+#ifndef _INPUT_FF_H
+#define _INPUT_FF_H
+
+/*
+ *  Copyright (c) 2006 Anssi Hannula <[email protected]>
+ */
+
+/*
+ * 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
+ */
+
+
+#ifdef CONFIG_INPUT_FF_EFFECTS
+void input_ff_event(struct input_dev *dev, unsigned int type,
+		    unsigned int code, int value);
+#else
+static inline void input_ff_event(struct input_dev *dev, unsigned int type,
+				  unsigned int code, int value) { return; }
+#endif
+
+#endif

--
Anssi Hannula

#18 lore raw

PATCH 5/13 input: adapt hid force feedback drivers for the new interface

In reply to Anssi Hannula

Modify the HID force feedback drivers for the new interface. This removes a lot of code duplication.

---
 drivers/usb/input/Kconfig     |    2 
 drivers/usb/input/hid-input.c |    3 
 drivers/usb/input/hid-lgff.c  |  458 ++++--------------------------------------
 drivers/usb/input/hid-tmff.c  |  353 ++------------------------------
 drivers/usb/input/hid.h       |    9 
 5 files changed, 81 insertions(+), 744 deletions(-)
drivers/usb/input/hid.h +0 -9
Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid.h
===================================================================
@@ -442,8 +442,6 @@ struct hid_device {							/* device repo
 
 	void *ff_private;                                               /* Private data for the force-feedback driver */
 	void (*ff_exit)(struct hid_device*);                            /* Called by hid_exit_ff(hid) */
-	int (*ff_event)(struct hid_device *hid, struct input_dev *input,
-			unsigned int type, unsigned int code, int value);
 
 #ifdef CONFIG_USB_HIDINPUT_POWERBOOK
 	unsigned long pb_pressed_fn[NBITS(KEY_MAX)];
@@ -526,13 +524,6 @@ static inline void hid_ff_exit(struct hi
 	if (hid->ff_exit)
 		hid->ff_exit(hid);
 }
-static inline int hid_ff_event(struct hid_device *hid, struct input_dev *input,
-			unsigned int type, unsigned int code, int value)
-{
-	if (hid->ff_event)
-		return hid->ff_event(hid, input, type, code, value);
-	return -ENOSYS;
-}
 
 int hid_lgff_init(struct hid_device* hid);
 int hid_tmff_init(struct hid_device* hid);
drivers/usb/input/hid-input.c +0 -3
Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid-input.c
===================================================================
@@ -736,9 +736,6 @@ static int hidinput_input_event(struct i
 	struct hid_field *field;
 	int offset;
 
-	if (type == EV_FF)
-		return hid_ff_event(hid, dev, type, code, value);
-
 	if (type != EV_LED)
 		return -1;
 
drivers/usb/input/hid-lgff.c +50 -408

526 lines not on this page · raw message

drivers/usb/input/hid-tmff.c +30 -323

423 lines not on this page · raw message

drivers/usb/input/Kconfig +1 -1
Index: linux-2.6.17-rc4-git12/drivers/usb/input/Kconfig
===================================================================
@@ -49,7 +49,7 @@ config USB_HIDINPUT_POWERBOOK
 
 config HID_FF
 	bool "Force feedback support (EXPERIMENTAL)"
-	depends on USB_HIDINPUT && EXPERIMENTAL
+	depends on USB_HIDINPUT && EXPERIMENTAL && INPUT_FF_EFFECTS
 	help
 	  Say Y here is you want force feedback support for a few HID devices.
 	  See below for a list of supported devices.

--
Anssi Hannula

#19 lore raw

PATCH 6/13 input: adapt uinput for the new force feedback interface

In reply to Anssi Hannula

Modify the uinput driver for the new force feedback interface. The userspace interface of the force feedback part is changed and documentation in uinput.h is updated accordingly. MODULE_VERSION is also added to reflect the revision.

---
 drivers/input/misc/uinput.c |   76 +++++++++++++++++++++++++++++++++++---------
 include/linux/uinput.h      |   21 ++++++++----
 2 files changed, 77 insertions(+), 20 deletions(-)
drivers/input/misc/uinput.c +62 -14
Index: linux-2.6.17-rc4-git12/drivers/input/misc/uinput.c
===================================================================
@@ -20,6 +20,9 @@
  * Author: Aristeu Sergio Rozanski Filho <[email protected]>
  *
  * Changes/Revisions:
+ *	0.3	09/04/2006 (Anssi Hannula <[email protected]>)
+ *		- updated ff support for the changes in kernel interface
+ *		- added MODULE_VERSION
  *	0.2	16/10/2004 (Micah Dowty <[email protected]>)
  *		- added force feedback support
  *              - added UI_SET_PHYS
@@ -107,18 +110,31 @@ static int uinput_request_submit(struct 
 	return request->retval;
 }
 
-static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect)
+static void uinput_dev_set_gain(struct input_dev *dev, u16 gain)
+{
+	uinput_dev_event(dev, EV_FF, FF_GAIN, gain);
+}
+
+static void uinput_dev_set_autocenter(struct input_dev *dev, u16 magnitude)
+{
+	uinput_dev_event(dev, EV_FF, FF_AUTOCENTER, magnitude);
+}
+
+static int uinput_dev_playback(struct input_dev *dev, int effect_id, int value)
+{
+	return uinput_dev_event(dev, EV_FF, effect_id, value);
+}
+
+static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old)
 {
 	struct uinput_request request;
 	int retval;
 
-	if (!test_bit(EV_FF, dev->evbit))
-		return -ENOSYS;
-
 	request.id = -1;
 	init_completion(&request.done);
 	request.code = UI_FF_UPLOAD;
-	request.u.effect = effect;
+	request.u.upload.effect = effect;
+	request.u.upload.old = old;
 
 	retval = uinput_request_reserve_slot(dev->private, &request);
 	if (!retval)
@@ -166,6 +182,14 @@ static void uinput_destroy_device(struct
 	udev->state = UIST_NEW_DEVICE;
 }
 
+static struct ff_driver uinput_ff_driver = {
+	.upload = uinput_dev_upload_effect,
+	.erase = uinput_dev_erase_effect,
+	.playback = uinput_dev_playback,
+	.set_gain = uinput_dev_set_gain,
+	.set_autocenter = uinput_dev_set_autocenter
+};
+
 static int uinput_create_device(struct uinput_device *udev)
 {
 	int error;
@@ -181,6 +205,14 @@ static int uinput_create_device(struct u
 		return error;
 	}
 
+	if (udev->dev->ff) {
+		error = input_ff_register(udev->dev, &uinput_ff_driver);
+		if (error) {
+			uinput_destroy_device(udev);
+			return error;
+		}
+	}
+
 	udev->state = UIST_CREATED;
 
 	return 0;
@@ -243,8 +275,6 @@ static int uinput_allocate_device(struct
 		return -ENOMEM;
 
 	udev->dev->event = uinput_dev_event;
-	udev->dev->upload_effect = uinput_dev_upload_effect;
-	udev->dev->erase_effect = uinput_dev_erase_effect;
 	udev->dev->private = udev;
 
 	return 0;
@@ -296,7 +326,12 @@ static int uinput_setup_device(struct ui
 	dev->id.vendor	= user_dev->id.vendor;
 	dev->id.product	= user_dev->id.product;
 	dev->id.version	= user_dev->id.version;
-	dev->ff_effects_max = user_dev->ff_effects_max;
+	if (user_dev->ff_effects_max) {
+		retval = input_ff_allocate(dev);
+		if (retval)
+			goto exit;
+		dev->ff_effects_max = user_dev->ff_effects_max;
+	}
 
 	size = sizeof(int) * (ABS_MAX + 1);
 	memcpy(dev->absmax, user_dev->absmax, size);
@@ -459,7 +494,12 @@ static long uinput_ioctl(struct file *fi
 			break;
 
 		case UI_SET_EVBIT:
-			retval = uinput_set_bit(arg, evbit, EV_MAX);
+			if (arg == EV_FF)
+				/* EV_FF shall not be touched by the driver
+				   it is set by force feedback subsystem */
+				retval = -EINVAL;
+			else
+				retval = uinput_set_bit(arg, evbit, EV_MAX);
 			break;
 
 		case UI_SET_KEYBIT:
@@ -487,7 +527,10 @@ static long uinput_ioctl(struct file *fi
 			break;
 
 		case UI_SET_FFBIT:
-			retval = uinput_set_bit(arg, ffbit, FF_MAX);
+			if (!udev->dev->ff)
+				retval = -EINVAL;
+			else
+				retval = uinput_set_bit(arg, ff->flags, FF_MAX);
 			break;
 
 		case UI_SET_SWBIT:
@@ -525,12 +568,17 @@ static long uinput_ioctl(struct file *fi
 				break;
 			}
 			req = uinput_request_find(udev, ff_up.request_id);
-			if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) {
+			if (!(req && req->code == UI_FF_UPLOAD && req->u.upload.effect)) {
 				retval = -EINVAL;
 				break;
 			}
 			ff_up.retval = 0;
-			memcpy(&ff_up.effect, req->u.effect, sizeof(struct ff_effect));
+			memcpy(&ff_up.effect, req->u.upload.effect, sizeof(struct ff_effect));
+			if (req->u.upload.old)
+				memcpy(&ff_up.old, req->u.upload.old, sizeof(struct ff_effect));
+			else
+				memset(&ff_up.old, 0, sizeof(struct ff_effect));
+
 			if (copy_to_user(p, &ff_up, sizeof(ff_up))) {
 				retval = -EFAULT;
 				break;
@@ -561,12 +609,11 @@ static long uinput_ioctl(struct file *fi
 				break;
 			}
 			req = uinput_request_find(udev, ff_up.request_id);
-			if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) {
+			if (!(req && req->code == UI_FF_UPLOAD && req->u.upload.effect)) {
 				retval = -EINVAL;
 				break;
 			}
 			req->retval = ff_up.retval;
-			memcpy(req->u.effect, &ff_up.effect, sizeof(struct ff_effect));
 			uinput_request_done(udev, req);
 			break;
 
@@ -622,6 +669,7 @@ static void __exit uinput_exit(void)
 MODULE_AUTHOR("Aristeu Sergio Rozanski Filho");
 MODULE_DESCRIPTION("User level driver support for input subsystem");
 MODULE_LICENSE("GPL");
+MODULE_VERSION("0.3");
 
 module_init(uinput_init);
 module_exit(uinput_exit);
include/linux/uinput.h +15 -6
Index: linux-2.6.17-rc4-git12/include/linux/uinput.h
===================================================================
@@ -22,12 +22,18 @@
  * Author: Aristeu Sergio Rozanski Filho <[email protected]>
  *
  * Changes/Revisions:
+ *	0.3	24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>)
+ *		- update ff support for the changes in kernel interface
+ *		- add UINPUT_VERSION
  *	0.2	16/10/2004 (Micah Dowty <[email protected]>)
  *		- added force feedback support
  *             - added UI_SET_PHYS
  *	0.1	20/06/2002
  *		- first public version
  */
+
+#define UINPUT_VERSION		3
+
 #ifdef __KERNEL__
 #define UINPUT_MINOR		223
 #define UINPUT_NAME		"uinput"
@@ -45,7 +51,10 @@ struct uinput_request {
 
 	union {
 		int		effect_id;
-		struct ff_effect* effect;
+		struct {
+			struct ff_effect* effect;
+			struct ff_effect* old;
+		} upload;
 	} u;
 };
 
@@ -69,6 +78,7 @@ struct uinput_ff_upload {
 	int			request_id;
 	int			retval;
 	struct ff_effect	effect;
+	struct ff_effect	old;
 };
 
 struct uinput_ff_erase {
@@ -105,7 +115,7 @@ struct uinput_ff_erase {
  * ioctls to retrieve additional parameters and send the return code.
  * The callback blocks until this return code is sent.
  *
- * The described callback mechanism is only used if EV_FF is set.
+ * The described callback mechanism is only used if ff_effects_max is set.
  * Otherwise, default implementations of upload_effect and erase_effect
  * are used.
  *
@@ -116,9 +126,9 @@ struct uinput_ff_erase {
  *      the 'value' from the EV_UINPUT event.
  *   3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the
  *      uinput_ff_upload struct. It will be filled in with the
- *      ff_effect passed to upload_effect().
- *   4. Perform the effect upload, and place the modified ff_effect
- *      and a return code back into the uinput_ff_upload struct.
+ *      ff_effects passed to upload_effect().
+ *   4. Perform the effect upload, and place a return code back into
+        the uinput_ff_upload struct.
  *   5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the
  *      uinput_ff_upload_effect struct. This will complete execution
  *      of our upload_effect() handler.
@@ -133,7 +143,6 @@ struct uinput_ff_erase {
  *      effect ID passed to erase_effect().
  *   4. Perform the effect erasure, and place a return code back
  *      into the uinput_ff_erase struct.
- *      and a return code back into the uinput_ff_erase struct.
  *   5. Issue a UI_END_FF_ERASE ioctl, also giving it the
  *      uinput_ff_erase_effect struct. This will complete execution
  *      of our erase_effect() handler.

--
Anssi Hannula

#20 lore raw

PATCH 7/13 input: adapt iforce driver for the new force feedback interface

In reply to Anssi Hannula

Modify the iforce driver for the new force feedback interface.

---
 drivers/input/joystick/iforce/iforce-ff.c   |   61 +++------
 drivers/input/joystick/iforce/iforce-main.c |  188 ++++++++--------------------
 drivers/input/joystick/iforce/iforce.h      |   15 --
 3 files changed, 86 insertions(+), 178 deletions(-)
drivers/input/joystick/iforce/iforce-ff.c +23 -38
Index: linux-2.6.17-rc4-git12/drivers/input/joystick/iforce/iforce-ff.c
===================================================================
@@ -198,10 +198,8 @@ static unsigned char find_button(struct 
  * Analyse the changes in an effect, and tell if we need to send an condition
  * parameter packet
  */
-static int need_condition_modifier(struct iforce* iforce, struct ff_effect* new)
+static int need_condition_modifier(struct ff_effect* old, struct ff_effect* new)
 {
-	int id = new->id;
-	struct ff_effect* old = &iforce->core_effects[id].effect;
 	int ret=0;
 	int i;
 
@@ -225,11 +223,8 @@ static int need_condition_modifier(struc
  * Analyse the changes in an effect, and tell if we need to send a magnitude
  * parameter packet
  */
-static int need_magnitude_modifier(struct iforce* iforce, struct ff_effect* effect)
+static int need_magnitude_modifier(struct ff_effect* old, struct ff_effect* effect)
 {
-	int id = effect->id;
-	struct ff_effect* old = &iforce->core_effects[id].effect;
-
 	if (effect->type != FF_CONSTANT) {
 		printk(KERN_WARNING "iforce.c: bad effect type in need_envelope_modifier\n");
 		return FALSE;
@@ -242,11 +237,8 @@ static int need_magnitude_modifier(struc
  * Analyse the changes in an effect, and tell if we need to send an envelope
  * parameter packet
  */
-static int need_envelope_modifier(struct iforce* iforce, struct ff_effect* effect)
+static int need_envelope_modifier(struct ff_effect* old, struct ff_effect* effect)
 {
-	int id = effect->id;
-	struct ff_effect* old = &iforce->core_effects[id].effect;
-
 	switch (effect->type) {
 	case FF_CONSTANT:
 		if (old->u.constant.envelope.attack_length != effect->u.constant.envelope.attack_length
@@ -275,16 +267,12 @@ static int need_envelope_modifier(struct
  * Analyse the changes in an effect, and tell if we need to send a periodic
  * parameter effect
  */
-static int need_period_modifier(struct iforce* iforce, struct ff_effect* new)
+static int need_period_modifier(struct ff_effect* old, struct ff_effect* new)
 {
-	int id = new->id;
-	struct ff_effect* old = &iforce->core_effects[id].effect;
-
 	if (new->type != FF_PERIODIC) {
-		printk(KERN_WARNING "iforce.c: bad effect type in need_periodic_modifier\n");
+		printk(KERN_WARNING "iforce.c: bad effect type in need_period_modifier\n");
 		return FALSE;
 	}
-
 	return (old->u.periodic.period != new->u.periodic.period
 		|| old->u.periodic.magnitude != new->u.periodic.magnitude
 		|| old->u.periodic.offset != new->u.periodic.offset
@@ -295,11 +283,8 @@ static int need_period_modifier(struct i
  * Analyse the changes in an effect, and tell if we need to send an effect
  * packet
  */
-static int need_core(struct iforce* iforce, struct ff_effect* new)
+static int need_core(struct ff_effect* old, struct ff_effect* new)
 {
-	int id = new->id;
-	struct ff_effect* old = &iforce->core_effects[id].effect;
-
 	if (old->direction != new->direction
 		|| old->trigger.button != new->trigger.button
 		|| old->trigger.interval != new->trigger.interval
@@ -360,7 +345,7 @@ static int make_core(struct iforce* ifor
  * Upload a periodic effect to the device
  * See also iforce_upload_constant.
  */
-int iforce_upload_periodic(struct iforce* iforce, struct ff_effect* effect, int is_update)
+int iforce_upload_periodic(struct iforce* iforce, struct ff_effect* effect, struct ff_effect *old)
 {
 	u8 wave_code;
 	int core_id = effect->id;
@@ -371,18 +356,18 @@ int iforce_upload_periodic(struct iforce
 	int param2_err = 1;
 	int core_err = 0;
 
-	if (!is_update || need_period_modifier(iforce, effect)) {
+	if (!old || need_period_modifier(old, effect)) {
 		param1_err = make_period_modifier(iforce, mod1_chunk,
-			is_update,
+			old ? 1 : 0,
 			effect->u.periodic.magnitude, effect->u.periodic.offset,
 			effect->u.periodic.period, effect->u.periodic.phase);
 		if (param1_err) return param1_err;
 		set_bit(FF_MOD1_IS_USED, core_effect->flags);
 	}
 
-	if (!is_update || need_envelope_modifier(iforce, effect)) {
+	if (!old || need_envelope_modifier(old, effect)) {
 		param2_err = make_envelope_modifier(iforce, mod2_chunk,
-			is_update,
+			old ? 1 : 0,
 			effect->u.periodic.envelope.attack_length,
 			effect->u.periodic.envelope.attack_level,
 			effect->u.periodic.envelope.fade_length,
@@ -400,7 +385,7 @@ int iforce_upload_periodic(struct iforce
 		default:		wave_code = 0x20; break;
 	}
 
-	if (!is_update || need_core(iforce, effect)) {
+	if (!old || need_core(old, effect)) {
 		core_err = make_core(iforce, effect->id,
 			mod1_chunk->start,
 			mod2_chunk->start,
@@ -429,7 +414,7 @@ int iforce_upload_periodic(struct iforce
  *  0 Ok, effect created or updated
  *  1 effect did not change since last upload, and no packet was therefore sent
  */
-int iforce_upload_constant(struct iforce* iforce, struct ff_effect* effect, int is_update)
+int iforce_upload_constant(struct iforce* iforce, struct ff_effect* effect, struct ff_effect* old)
 {
 	int core_id = effect->id;
 	struct iforce_core_effect* core_effect = iforce->core_effects + core_id;
@@ -439,17 +424,17 @@ int iforce_upload_constant(struct iforce
 	int param2_err = 1;
 	int core_err = 0;
 
-	if (!is_update || need_magnitude_modifier(iforce, effect)) {
+	if (!old || need_magnitude_modifier(old, effect)) {
 		param1_err = make_magnitude_modifier(iforce, mod1_chunk,
-			is_update,
+			old ? 1 : 0,
 			effect->u.constant.level);
 		if (param1_err) return param1_err;
 		set_bit(FF_MOD1_IS_USED, core_effect->flags);
 	}
 
-	if (!is_update || need_envelope_modifier(iforce, effect)) {
+	if (!old || need_envelope_modifier(old, effect)) {
 		param2_err = make_envelope_modifier(iforce, mod2_chunk,
-			is_update,
+			old ? 1 : 0,
 			effect->u.constant.envelope.attack_length,
 			effect->u.constant.envelope.attack_level,
 			effect->u.constant.envelope.fade_length,
@@ -458,7 +443,7 @@ int iforce_upload_constant(struct iforce
 		set_bit(FF_MOD2_IS_USED, core_effect->flags);
 	}
 
-	if (!is_update || need_core(iforce, effect)) {
+	if (!old || need_core(old, effect)) {
 		core_err = make_core(iforce, effect->id,
 			mod1_chunk->start,
 			mod2_chunk->start,
@@ -483,7 +468,7 @@ int iforce_upload_constant(struct iforce
 /*
  * Upload an condition effect. Those are for example friction, inertia, springs...
  */
-int iforce_upload_condition(struct iforce* iforce, struct ff_effect* effect, int is_update)
+int iforce_upload_condition(struct iforce* iforce, struct ff_effect* effect, struct ff_effect* old)
 {
 	int core_id = effect->id;
 	struct iforce_core_effect* core_effect = iforce->core_effects + core_id;
@@ -499,9 +484,9 @@ int iforce_upload_condition(struct iforc
 		default: return -1;
 	}
 
-	if (!is_update || need_condition_modifier(iforce, effect)) {
+	if (!old || need_condition_modifier(old, effect)) {
 		param_err = make_condition_modifier(iforce, mod1_chunk,
-			is_update,
+			old ? 1 : 0,
 			effect->u.condition[0].right_saturation,
 			effect->u.condition[0].left_saturation,
 			effect->u.condition[0].right_coeff,
@@ -512,7 +497,7 @@ int iforce_upload_condition(struct iforc
 		set_bit(FF_MOD1_IS_USED, core_effect->flags);
 
 		param_err = make_condition_modifier(iforce, mod2_chunk,
-			is_update,
+			old ? 1 : 0,
 			effect->u.condition[1].right_saturation,
 			effect->u.condition[1].left_saturation,
 			effect->u.condition[1].right_coeff,
@@ -524,7 +509,7 @@ int iforce_upload_condition(struct iforc
 
 	}
 
-	if (!is_update || need_core(iforce, effect)) {
+	if (!old || need_core(old, effect)) {
 		core_err = make_core(iforce, effect->id,
 			mod1_chunk->start, mod2_chunk->start,
 			type, 0xc0,
drivers/input/joystick/iforce/iforce.h +4 -11
Index: linux-2.6.17-rc4-git12/drivers/input/joystick/iforce/iforce.h
===================================================================
@@ -55,7 +55,7 @@
 #define FALSE 0
 #define TRUE 1
 
-#define FF_EFFECTS_MAX	32
+#define IFORCE_EFFECTS_MAX	32
 
 /* Each force feedback effect is made of one core effect, which can be
  * associated to at most to effect modifiers
@@ -79,13 +79,6 @@ struct iforce_core_effect {
 	struct resource mod1_chunk;
 	struct resource mod2_chunk;
 	unsigned long flags[NBITS(FF_MODCORE_MAX)];
-	pid_t owner;
-	/* Used to keep track of parameters of an effect. They are needed
-	 * to know what parts of an effect changed in an update operation.
-	 * We try to send only parameter packets if possible, as sending
-	 * effect parameter requires the effect to be stoped and restarted
-	 */
-	struct ff_effect effect;
 };
 
 #define FF_CMD_EFFECT		0x010e
@@ -183,9 +176,9 @@ void iforce_dump_packet(char *msg, u16 c
 int iforce_get_id_packet(struct iforce *iforce, char *packet);
 
 /* iforce-ff.c */
-int iforce_upload_periodic(struct iforce*, struct ff_effect*, int is_update);
-int iforce_upload_constant(struct iforce*, struct ff_effect*, int is_update);
-int iforce_upload_condition(struct iforce*, struct ff_effect*, int is_update);
+int iforce_upload_periodic(struct iforce*, struct ff_effect*, struct ff_effect* old);
+int iforce_upload_constant(struct iforce*, struct ff_effect*, struct ff_effect* old);
+int iforce_upload_condition(struct iforce*, struct ff_effect*, struct ff_effect* old);
 
 /* Public variables */
 extern struct serio_driver iforce_serio_drv;
drivers/input/joystick/iforce/iforce-main.c +59 -129

296 lines not on this page · raw message

--
Anssi Hannula

#21 lore raw

PATCH 8/13 input: force feedback driver for PID devices

In reply to Anssi Hannula

Add force feedback driver for PID devices. This replaces the older PID driver which was never completed.

---
 drivers/usb/input/Kconfig     |    4 
 drivers/usb/input/Makefile    |    2 
 drivers/usb/input/hid-ff.c    |   14 
 drivers/usb/input/hid-input.c |   21 
 drivers/usb/input/hid-pidff.c | 1400 ++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/input/hid.h       |    6 
 6 files changed, 1416 insertions(+), 31 deletions(-)
drivers/usb/input/hid-ff.c +7 -7
Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid-ff.c
===================================================================
@@ -51,9 +51,6 @@ static struct hid_ff_initializer inits[]
 	{0x46d, 0xc295, hid_lgff_init},	// Logitech MOMO force wheel
 	{0x46d, 0xc219, hid_lgff_init}, // Logitech Cordless rumble pad 2
 #endif
-#ifdef CONFIG_HID_PID
-	{0x45e, 0x001b, hid_pid_init},
-#endif
 #ifdef CONFIG_THRUSTMASTER_FF
 	{0x44f, 0xb304, hid_tmff_init},
 #endif
@@ -80,9 +77,12 @@ int hid_ff_init(struct hid_device* hid)
 	init = hid_get_ff_init(le16_to_cpu(hid->dev->descriptor.idVendor),
 			       le16_to_cpu(hid->dev->descriptor.idProduct));
 
-	if (!init) {
-		dbg("hid_ff_init could not find initializer");
-		return -ENOSYS;
-	}
+	/* We try pidff when no other driver is found because PID is the
+	standards compliant way of implementing force feedback in HID.
+	pidff_init() will quickly abort if the device doesn't appear to
+	be a PID device */
+	if (!init)
+		return pidff_init(hid);
+
 	return init->init(hid);
 }
drivers/usb/input/hid.h +5 -1
Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid.h
===================================================================
@@ -527,5 +527,9 @@ 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 hid_pid_init(struct hid_device* hid);
 
+#ifdef CONFIG_HID_PID
+int pidff_init(struct hid_device *hid);
+#else
+static inline int pidff_init(struct hid_device *hid) { return -1; }
+#endif
drivers/usb/input/hid-input.c +1 -20
Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid-input.c
===================================================================
@@ -67,11 +67,9 @@ static const struct {
 #define map_rel(c)	do { usage->code = c; usage->type = EV_REL; bit = input->relbit; max = REL_MAX; } while (0)
 #define map_key(c)	do { usage->code = c; usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX; } while (0)
 #define map_led(c)	do { usage->code = c; usage->type = EV_LED; bit = input->ledbit; max = LED_MAX; } while (0)
-#define map_ff(c)	do { usage->code = c; usage->type = EV_FF;  bit = input->ffbit;  max =  FF_MAX; } while (0)
 
 #define map_abs_clear(c)	do { map_abs(c); clear_bit(c, bit); } while (0)
 #define map_key_clear(c)	do { map_key(c); clear_bit(c, bit); } while (0)
-#define map_ff_effect(c)	do { set_bit(c, input->ffbit); } while (0)
 
 #ifdef CONFIG_USB_HIDINPUT_POWERBOOK
 
@@ -527,23 +525,7 @@ static void hidinput_configure_usage(str
 
 		case HID_UP_PID:
 
-			set_bit(EV_FF, input->evbit);
 			switch(usage->hid & HID_USAGE) {
-				case 0x26: map_ff_effect(FF_CONSTANT);	goto ignore;
-				case 0x27: map_ff_effect(FF_RAMP);	goto ignore;
-				case 0x28: map_ff_effect(FF_CUSTOM);	goto ignore;
-				case 0x30: map_ff_effect(FF_SQUARE);	map_ff_effect(FF_PERIODIC); goto ignore;
-				case 0x31: map_ff_effect(FF_SINE);	map_ff_effect(FF_PERIODIC); goto ignore;
-				case 0x32: map_ff_effect(FF_TRIANGLE);	map_ff_effect(FF_PERIODIC); goto ignore;
-				case 0x33: map_ff_effect(FF_SAW_UP);	map_ff_effect(FF_PERIODIC); goto ignore;
-				case 0x34: map_ff_effect(FF_SAW_DOWN);	map_ff_effect(FF_PERIODIC); goto ignore;
-				case 0x40: map_ff_effect(FF_SPRING);	goto ignore;
-				case 0x41: map_ff_effect(FF_DAMPER);	goto ignore;
-				case 0x42: map_ff_effect(FF_INERTIA);	goto ignore;
-				case 0x43: map_ff_effect(FF_FRICTION);	goto ignore;
-				case 0x7e: map_ff(FF_GAIN);		break;
-				case 0x83: input->ff_effects_max = field->value[0]; goto ignore;
-				case 0x98: map_ff(FF_AUTOCENTER);	break;
 				case 0xa4: map_key_clear(BTN_DEAD);	break;
 				default: goto ignore;
 			}
@@ -687,8 +669,7 @@ void hidinput_hid_event(struct hid_devic
 	}
 
 	if (usage->hid == (HID_UP_PID | 0x83UL)) { /* Simultaneous Effects Max */
-		input->ff_effects_max = value;
-		dbg("Maximum Effects - %d",input->ff_effects_max);
+		dbg("Maximum Effects - %d",value);
 		return;
 	}
 
drivers/usb/input/hid-pidff.c new file +1400 -0

1,400 lines not on this page · raw message

drivers/usb/input/Kconfig +2 -2
Index: linux-2.6.17-rc4-git12/drivers/usb/input/Kconfig
===================================================================
@@ -60,10 +60,10 @@ config HID_FF
 	  If unsure, say N.
 
 config HID_PID
-	bool "PID Devices (Microsoft Sidewinder Force Feedback 2)"
+	bool "PID device support"
 	depends on HID_FF
 	help
-	  Say Y here if you have a PID-compliant joystick and wish to enable force
+	  Say Y here if you have a PID-compliant device and wish to enable force
 	  feedback for it. The Microsoft Sidewinder Force Feedback 2 is one such
 	  device.
 
drivers/usb/input/Makefile +1 -1
Index: linux-2.6.17-rc4-git12/drivers/usb/input/Makefile
===================================================================
@@ -14,7 +14,7 @@ ifeq ($(CONFIG_USB_HIDINPUT),y)
 	usbhid-objs	+= hid-input.o
 endif
 ifeq ($(CONFIG_HID_PID),y)
-	usbhid-objs	+= pid.o
+	usbhid-objs	+= hid-pidff.o
 endif
 ifeq ($(CONFIG_LOGITECH_FF),y)
 	usbhid-objs	+= hid-lgff.o

--
Anssi Hannula

#22 lore raw

PATCH 9/13 input: force feedback driver for Zeroplus devices

In reply to Anssi Hannula

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

---
 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(+)
drivers/usb/input/hid-ff.c +4 -0
Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid-ff.c
===================================================================
@@ -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 */
 };
 
drivers/usb/input/hid-zpff.c new file +124 -0

124 lines not on this page · raw message

drivers/usb/input/Kconfig +7 -0
Index: linux-2.6.17-rc4-git12/drivers/usb/input/Kconfig
===================================================================
@@ -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
drivers/usb/input/Makefile +3 -0
Index: linux-2.6.17-rc4-git12/drivers/usb/input/Makefile
===================================================================
@@ -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
drivers/usb/input/hid.h +1 -0
Index: linux-2.6.17-rc4-git12/drivers/usb/input/hid.h
===================================================================
@@ -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

#23 lore raw

PATCH 10/13 input: update documentation of force feedback

In reply to Anssi Hannula

Update the force feedback documentation in ff.txt and input.h.

---
 Documentation/input/ff.txt |   96 ++++++++++++++++++++-------------------------
 include/linux/input.h      |   12 +++++
 2 files changed, 54 insertions(+), 54 deletions(-)
Documentation/input/ff.txt +43 -53
Index: linux-2.6.17-rc4-git12/Documentation/input/ff.txt
===================================================================
@@ -1,27 +1,27 @@
 Force feedback for Linux.
 By Johann Deneux <[email protected]> on 2001/04/22.
+Updated by Anssi Hannula <[email protected]> on 2006/04/09.
 You may redistribute this file. Please remember to include shape.fig and
 interactive.fig as well.
 ----------------------------------------------------------------------------
 
-0. Introduction
+1. Introduction
 ~~~~~~~~~~~~~~~
 This document describes how to use force feedback devices under Linux. The
 goal is not to support these devices as if they were simple input-only devices
 (as it is already the case), but to really enable the rendering of force
 effects.
-At the moment, only I-Force devices are supported, and not officially. That
-means I had to find out how the protocol works on my own. Of course, the
-information I managed to grasp is far from being complete, and I can not
-guarranty that this driver will work for you.
-This document only describes the force feedback part of the driver for I-Force
-devices. Please read joystick.txt before reading further this document.
+This document only describes the force feedback part of the Linux input
+interface. Please read joystick.txt and input.txt before reading further this
+document.
 
 2. Instructions to the user
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Here are instructions on how to compile and use the driver. In fact, this
-driver is the normal iforce, input and evdev drivers written by Vojtech
-Pavlik, plus additions to support force feedback.
+To enable force feedback, you have to
+1. have your kernel configured with evdev and force feedback effects enabled
+   with a driver that supports your device.
+2. make sure evdev module is loaded and /dev/input/event* device files are
+   created.
 
 Before you start, let me WARN you that some devices shake violently during the
 initialisation phase. This happens for example with my "AVB Top Shot Pegasus".
@@ -29,39 +29,8 @@ To stop this annoying behaviour, move yo
 should keep a hand on your device, in order to avoid it to brake down if
 something goes wrong.
 
-At the kernel's compilation:
-	- Enable IForce/Serial
-	- Enable Event interface
-
-Compile the modules, install them.
-
-You also need inputattach.
-
-You then need to insert the modules into the following order:
-% modprobe joydev
-% modprobe serport		# Only for serial
-% modprobe iforce
-% modprobe evdev
-% ./inputattach -ifor $2 &	# Only for serial
-If you are using USB, you don't need the inputattach step.
-
-Please check that you have all the /dev/input entries needed:
-cd /dev
-rm js*
-mkdir input
-mknod input/js0 c 13 0
-mknod input/js1 c 13 1
-mknod input/js2 c 13 2
-mknod input/js3 c 13 3
-ln -s input/js0 js0
-ln -s input/js1 js1
-ln -s input/js2 js2
-ln -s input/js3 js3
-
-mknod input/event0 c 13 64
-mknod input/event1 c 13 65
-mknod input/event2 c 13 66
-mknod input/event3 c 13 67
+If you have a serial iforce device, you need to start inputattach. See
+joystick.txt for details.
 
 2.1 Does it work ?
 ~~~~~~~~~~~~~~~~~~
@@ -86,18 +55,29 @@ int ioctl(int file_descriptor, int reque
 
 Returns the features supported by the device. features is a bitfield with the
 following bits:
-- FF_X		has an X axis (usually joysticks)
-- FF_Y		has an Y axis (usually joysticks)
-- FF_WHEEL	has a wheel (usually sterring wheels)
 - FF_CONSTANT	can render constant force effects
-- FF_PERIODIC	can render periodic effects (sine, triangle, square...)
+- FF_PERIODIC	can render periodic effects with the following waveforms:
+  - FF_SQUARE	  square waveform
+  - FF_TRIANGLE	  triangle waveform
+  - FF_SINE	  sine waveform
+  - FF_SAW_UP	  sawtooth up waveform
+  - FF_SAW_DOWN	  sawtooth down waveform
+  - FF_CUSTOM	  custom waveform
 - FF_RAMP       can render ramp effects
 - FF_SPRING	can simulate the presence of a spring
 - FF_FRICTION	can simulate friction 
 - FF_DAMPER	can simulate damper effects
-- FF_RUMBLE	rumble effects (normally the only effect supported by rumble
-		pads)
+- FF_RUMBLE	rumble effects
 - FF_INERTIA    can simulate inertia
+- FF_GAIN	gain is adjustable
+- FF_AUTOCENTER	autocenter is adjustable
+
+Note: In most cases you should use FF_PERIODIC instead of FF_RUMBLE. All
+      devices that support FF_RUMBLE support FF_PERIODIC (square, triangle,
+      sine) and the other way around.
+
+Note: The exact syntax FF_CUSTOM is undefined for the time being as no driver
+      supports it yet.
 
 
 int ioctl(int fd, EVIOCGEFFECTS, int *n);
@@ -120,6 +100,9 @@ to the unique id assigned by the driver.
 some operations (removing an effect, controlling the playback).
 This if field must be set to -1 by the user in order to tell the driver to
 allocate a new effect.
+
+Effects are file descriptor specific.
+
 See <linux/input.h> for a description of the ff_effect struct. You should also
 find help in a few sketches, contained in files shape.fig and interactive.fig.
 You need xfig to visualize these files.
@@ -128,8 +111,8 @@ You need xfig to visualize these files.
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 int ioctl(int fd, EVIOCRMFF, effect.id);
 
-This makes room for new effects in the device's memory. Please note this won't
-stop the effect if it was playing.
+This makes room for new effects in the device's memory. Note that this also
+stops the effect if it was playing.
 
 3.4 Controlling the playback of effects
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -163,8 +146,7 @@ Control of playing is done with write().
 ~~~~~~~~~~~~~~~~~~~~
 Not all devices have the same strength. Therefore, users should set a gain
 factor depending on how strong they want effects to be. This setting is
-persistent across access to the driver, so you should not care about it if
-you are writing games, as another utility probably already set this for you.
+persistent across access to the driver.
 
 /* Set the gain of the device
 int gain;		/* between 0 and 100 */
@@ -204,9 +186,17 @@ type of device, not all parameters can b
 the direction of an effect cannot be updated with iforce devices. In this
 case, the driver stops the effect, up-load it, and restart it.
 
+Therefore it is recommended to dynamically change direction while the effect
+is playing only when it is ok to restart the effect with a replay count of 1.
 
 3.8 Information about the status of effects
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+NOTE: This is deprecated and should not be used. It applies only to iforce
+      devices and is provided for backward-compatibility only. If you have a
+      really good reason to use this, please contact
+      [email protected] or [email protected]
+      so that support for it can be added to all drivers.
+
 Every time the status of an effect is changed, an event is sent. The values
 and meanings of the fields of the event are as follows:
 struct input_event {
include/linux/input.h +11 -1
Index: linux-2.6.17-rc4-git12/include/linux/input.h
===================================================================
@@ -672,8 +672,14 @@ struct input_absinfo {
  * They are sub-structures of the actually sent structure (called ff_effect)
  */
 
+/*
+ * All time duration values are expressed in ms.
+ * Time values above 32767ms (0x7fff) should not be used and have unspecified
+ * results depending on device.
+ */
+
 struct ff_replay {
-	__u16 length; /* Duration of an effect in ms. All other times are also expressed in ms */
+	__u16 length; /* Duration of an effect in ms */
 	__u16 delay;  /* Time to wait before to start playing an effect */
 };
 
@@ -683,6 +689,10 @@ struct ff_trigger {
 };
 
 struct ff_envelope {
+	/* The attack_level and fade_level are absolute values of the level,
+	i.e. if the default magnitude is negative the envelope level is
+	also seen as an absolute value of a below-zero value */
+	/* Therefore the valid level range is from 0x0000 to 0x7fff */
 	__u16 attack_length;	/* Duration of attack (ms) */
 	__u16 attack_level;	/* Level at beginning of attack */
 	__u16 fade_length;	/* Duration of fade (ms) */

--
Anssi Hannula

#24 lore raw

PATCH 11/13 input: drop the remains of the old ff interface

In reply to Anssi Hannula

Drop the now unused handlers and input_report_ff().

---
 include/linux/input.h |    7 -------
 1 files changed, 7 deletions(-)
include/linux/input.h +0 -7
Index: linux-2.6.16-git20/include/linux/input.h
===================================================================
@@ -938,8 +938,6 @@ struct input_dev {
 	int (*accept)(struct input_dev *dev, struct file *file);
 	int (*flush)(struct input_dev *dev, struct file *file);
 	int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
-	int (*upload_effect)(struct input_dev *dev, struct ff_effect *effect);
-	int (*erase_effect)(struct input_dev *dev, int effect_id);
 
 	struct input_handle *grab;
 
@@ -1118,11 +1116,6 @@ static inline void input_report_abs(stru
 	input_event(dev, EV_ABS, code, value);
 }
 
-static inline void input_report_ff(struct input_dev *dev, unsigned int code, int value)
-{
-	input_event(dev, EV_FF, code, value);
-}
-
 static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
 {
 	input_event(dev, EV_FF_STATUS, code, value);

--
Anssi Hannula

#25 lore raw

PATCH 12/13 input: drop the old PID driver

In reply to Anssi Hannula

Drop the old PID driver that is now obsoleted by a new implementation in hid-pidff.c. This older driver was never completed and is not able to upload effects.

---
 drivers/usb/input/pid.c |  295 ------------------------------------------------
 drivers/usb/input/pid.h |   62 ----------
 2 files changed, 357 deletions(-)
drivers/usb/input/pid.c deleted +0 -295
Index: linux-2.6.16-git20/drivers/usb/input/pid.c
===================================================================
@@ -1,295 +0,0 @@
-/*
- *  PID Force feedback support for hid devices.
- *
- *  Copyright (c) 2002 Rodrigo Damazio.
- *  Portions by Johann Deneux and Bjorn Augustson
- */
-
-/*
- * 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
- *
- * Should you need to contact me, the author, you can do so by
- * e-mail - mail your message to <[email protected]>
- */
-
-#include <linux/config.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/mm.h>
-#include <linux/smp_lock.h>
-#include <linux/spinlock.h>
-#include <linux/input.h>
-#include <linux/usb.h>
-#include "hid.h"
-#include "pid.h"
-
-#define CHECK_OWNERSHIP(i, hid_pid)	\
-	((i) < FF_EFFECTS_MAX && i >= 0 && \
-	test_bit(FF_PID_FLAGS_USED, &hid_pid->effects[(i)].flags) && \
-	(current->pid == 0 || \
-	(hid_pid)->effects[(i)].owner == current->pid))
-
-/* Called when a transfer is completed */
-static void hid_pid_ctrl_out(struct urb *u, struct pt_regs *regs)
-{
-	dev_dbg(&u->dev->dev, "hid_pid_ctrl_out - Transfer Completed\n");
-}
-
-static void hid_pid_exit(struct hid_device *hid)
-{
-	struct hid_ff_pid *private = hid->ff_private;
-
-	if (private->urbffout) {
-		usb_kill_urb(private->urbffout);
-		usb_free_urb(private->urbffout);
-	}
-}
-
-static int pid_upload_periodic(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
-{
-	dev_info(&pid->hid->dev->dev, "requested periodic force upload\n");
-	return 0;
-}
-
-static int pid_upload_constant(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
-{
-	dev_info(&pid->hid->dev->dev, "requested constant force upload\n");
-	return 0;
-}
-
-static int pid_upload_condition(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
-{
-	dev_info(&pid->hid->dev->dev, "requested Condition force upload\n");
-	return 0;
-}
-
-static int pid_upload_ramp(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
-{
-	dev_info(&pid->hid->dev->dev, "request ramp force upload\n");
-	return 0;
-}
-
-static int hid_pid_event(struct hid_device *hid, struct input_dev *input,
-			 unsigned int type, unsigned int code, int value)
-{
-	dev_dbg(&hid->dev->dev, "PID event received: type=%d,code=%d,value=%d.\n", type, code, value);
-
-	if (type != EV_FF)
-		return -1;
-
-	return 0;
-}
-
-/* Lock must be held by caller */
-static void hid_pid_ctrl_playback(struct hid_device *hid, struct hid_pid_effect *effect, int play)
-{
-	if (play)
-		set_bit(FF_PID_FLAGS_PLAYING, &effect->flags);
-	else
-		clear_bit(FF_PID_FLAGS_PLAYING, &effect->flags);
-}
-
-static int hid_pid_erase(struct input_dev *dev, int id)
-{
-	struct hid_device *hid = dev->private;
-	struct hid_ff_pid *pid = hid->ff_private;
-	struct hid_field *field;
-	unsigned long flags;
-	int ret;
-
-	if (!CHECK_OWNERSHIP(id, pid))
-		return -EACCES;
-
-	/* Find report */
-	field = hid_find_field_by_usage(hid, HID_UP_PID | FF_PID_USAGE_BLOCK_FREE,
-					HID_OUTPUT_REPORT);
-	if (!field) {
-		dev_err(&hid->dev->dev, "couldn't find report\n");
-		return -EIO;
-	}
-
-	ret = hid_set_field(field, 0, pid->effects[id].device_id);
-	if (ret) {
-		dev_err(&hid->dev->dev, "couldn't set field\n");
-		return ret;
-	}
-
-	hid_submit_report(hid, field->report, USB_DIR_OUT);
-
-	spin_lock_irqsave(&pid->lock, flags);
-	hid_pid_ctrl_playback(hid, pid->effects + id, 0);
-	pid->effects[id].flags = 0;
-	spin_unlock_irqrestore(&pid->lock, flags);
-
-	return 0;
-}
-
-/* Erase all effects this process owns */
-static int hid_pid_flush(struct input_dev *dev, struct file *file)
-{
-	struct hid_device *hid = dev->private;
-	struct hid_ff_pid *pid = hid->ff_private;
-	int i;
-
-	/*NOTE: no need to lock here. The only times EFFECT_USED is
-	   modified is when effects are uploaded or when an effect is
-	   erased. But a process cannot close its dev/input/eventX fd
-	   and perform ioctls on the same fd all at the same time */
-	/*FIXME: multiple threads, anyone? */
-	for (i = 0; i < dev->ff_effects_max; ++i)
-		if (current->pid == pid->effects[i].owner
-		    && test_bit(FF_PID_FLAGS_USED, &pid->effects[i].flags))
-			if (hid_pid_erase(dev, i))
-				dev_warn(&hid->dev->dev, "erase effect %d failed", i);
-
-	return 0;
-}
-
-static int hid_pid_upload_effect(struct input_dev *dev,
-				 struct ff_effect *effect)
-{
-	struct hid_ff_pid *pid_private = (struct hid_ff_pid *)(dev->private);
-	int ret;
-	int is_update;
-	unsigned long flags;
-
-	dev_dbg(&pid_private->hid->dev->dev, "upload effect called: effect_type=%x\n", effect->type);
-	/* Check this effect type is supported by this device */
-	if (!test_bit(effect->type, dev->ffbit)) {
-		dev_dbg(&pid_private->hid->dev->dev,
-			"invalid kind of effect requested.\n");
-		return -EINVAL;
-	}
-
-	/*
-	 * If we want to create a new effect, get a free id
-	 */
-	if (effect->id == -1) {
-		int id = 0;
-
-		// Spinlock so we don`t get a race condition when choosing IDs
-		spin_lock_irqsave(&pid_private->lock, flags);
-
-		while (id < FF_EFFECTS_MAX)
-			if (!test_and_set_bit(FF_PID_FLAGS_USED, &pid_private->effects[id++].flags))
-				break;
-
-		if (id == FF_EFFECTS_MAX) {
-			spin_unlock_irqrestore(&pid_private->lock, flags);
-// TEMP - We need to get ff_effects_max correctly first:  || id >= dev->ff_effects_max) {
-			dev_dbg(&pid_private->hid->dev->dev, "Not enough device memory\n");
-			return -ENOMEM;
-		}
-
-		effect->id = id;
-		dev_dbg(&pid_private->hid->dev->dev, "effect ID is %d.\n", id);
-		pid_private->effects[id].owner = current->pid;
-		pid_private->effects[id].flags = (1 << FF_PID_FLAGS_USED);
-		spin_unlock_irqrestore(&pid_private->lock, flags);
-
-		is_update = FF_PID_FALSE;
-	} else {
-		/* We want to update an effect */
-		if (!CHECK_OWNERSHIP(effect->id, pid_private))
-			return -EACCES;
-
-		/* Parameter type cannot be updated */
-		if (effect->type != pid_private->effects[effect->id].effect.type)
-			return -EINVAL;
-
-		/* Check the effect is not already being updated */
-		if (test_bit(FF_PID_FLAGS_UPDATING, &pid_private->effects[effect->id].flags))
-			return -EAGAIN;
-
-		is_update = FF_PID_TRUE;
-	}
-
-	/*
-	 * Upload the effect
-	 */
-	switch (effect->type) {
-	case FF_PERIODIC:
-		ret = pid_upload_periodic(pid_private, effect, is_update);
-		break;
-
-	case FF_CONSTANT:
-		ret = pid_upload_constant(pid_private, effect, is_update);
-		break;
-
-	case FF_SPRING:
-	case FF_FRICTION:
-	case FF_DAMPER:
-	case FF_INERTIA:
-		ret = pid_upload_condition(pid_private, effect, is_update);
-		break;
-
-	case FF_RAMP:
-		ret = pid_upload_ramp(pid_private, effect, is_update);
-		break;
-
-	default:
-		dev_dbg(&pid_private->hid->dev->dev,
-			"invalid type of effect requested - %x.\n",
-			effect->type);
-		return -EINVAL;
-	}
-	/* If a packet was sent, forbid new updates until we are notified
-	 * that the packet was updated
-	 */
-	if (ret == 0)
-		set_bit(FF_PID_FLAGS_UPDATING, &pid_private->effects[effect->id].flags);
-	pid_private->effects[effect->id].effect = *effect;
-	return ret;
-}
-
-int hid_pid_init(struct hid_device *hid)
-{
-	struct hid_ff_pid *private;
-	struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
-	struct input_dev *input_dev = hidinput->input;
-
-	private = hid->ff_private = kzalloc(sizeof(struct hid_ff_pid), GFP_KERNEL);
-	if (!private)
-		return -ENOMEM;
-
-	private->hid = hid;
-
-	hid->ff_exit = hid_pid_exit;
-	hid->ff_event = hid_pid_event;
-
-	/* Open output URB */
-	if (!(private->urbffout = usb_alloc_urb(0, GFP_KERNEL))) {
-		kfree(private);
-		return -1;
-	}
-
-	usb_fill_control_urb(private->urbffout, hid->dev, 0,
-			     (void *)&private->ffcr, private->ctrl_buffer, 8,
-			     hid_pid_ctrl_out, hid);
-
-	input_dev->upload_effect = hid_pid_upload_effect;
-	input_dev->flush = hid_pid_flush;
-	input_dev->ff_effects_max = 8;	// A random default
-	set_bit(EV_FF, input_dev->evbit);
-	set_bit(EV_FF_STATUS, input_dev->evbit);
-
-	spin_lock_init(&private->lock);
-
-	printk(KERN_INFO "Force feedback driver for PID devices by Rodrigo Damazio <[email protected]>.\n");
-
-	return 0;
-}
drivers/usb/input/pid.h deleted +0 -62

62 lines not on this page · raw message

--
Anssi Hannula

#26 lore raw

PATCH 13/13 input: use -ENOSPC instead of -ENOMEM in iforce when device full

In reply to Anssi Hannula

Use -ENOSPC instead of -ENOMEM when the iforce device doesn't have enough free memory for the new effect. All other drivers are already been using -ENOSPC, so this makes the behaviour coherent.

---
 drivers/input/joystick/iforce/iforce-ff.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/input/joystick/iforce/iforce-ff.c +4 -4
Index: linux-2.6.17-rc4-git12/drivers/input/joystick/iforce/iforce-ff.c
===================================================================
@@ -47,7 +47,7 @@ static int make_magnitude_modifier(struc
 			iforce->device_memory.start, iforce->device_memory.end, 2L,
 			NULL, NULL)) {
 			mutex_unlock(&iforce->mem_mutex);
-			return -ENOMEM;
+			return -ENOSPC;
 		}
 		mutex_unlock(&iforce->mem_mutex);
 	}
@@ -80,7 +80,7 @@ static int make_period_modifier(struct i
 			iforce->device_memory.start, iforce->device_memory.end, 2L,
 			NULL, NULL)) {
 			mutex_unlock(&iforce->mem_mutex);
-			return -ENOMEM;
+			return -ENOSPC;
 		}
 		mutex_unlock(&iforce->mem_mutex);
 	}
@@ -120,7 +120,7 @@ static int make_envelope_modifier(struct
 			iforce->device_memory.start, iforce->device_memory.end, 2L,
 			NULL, NULL)) {
 			mutex_unlock(&iforce->mem_mutex);
-			return -ENOMEM;
+			return -ENOSPC;
 		}
 		mutex_unlock(&iforce->mem_mutex);
 	}
@@ -157,7 +157,7 @@ static int make_condition_modifier(struc
 			iforce->device_memory.start, iforce->device_memory.end, 2L,
 			NULL, NULL)) {
 			mutex_unlock(&iforce->mem_mutex);
-			return -ENOMEM;
+			return -ENOSPC;
 		}
 		mutex_unlock(&iforce->mem_mutex);
 	}

--
Anssi Hannula