Skip to contentSkip to conversation

input: force feedback updates

PATCH In review Anssi Hannula 4 participants 23 messages May 15, 2006 – May 26, 2006

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

cover input: force feedback updates

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

--
Anssi Hannula

#1 lore raw

PATCH 1/11 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/11 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/11 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 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 module is named ff-effects. If INPUT_FF_EFFECTS is enabled, the force feedback drivers and interfaces (evdev) will be depending on it.

Userspace interface is left unaltered.

---
 drivers/input/Kconfig      |    9 
 drivers/input/Makefile     |    1 
 drivers/input/evdev.c      |   12 
 drivers/input/ff-effects.c |  751 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/input/input.c      |   17 -
 include/linux/input.h      |   50 ++
 6 files changed, 831 insertions(+), 9 deletions(-)
drivers/input/ff-effects.c new file +751 -0
Index: linux-2.6.17-rc4-git1/drivers/input/ff-effects.c
===================================================================
@@ -0,0 +1,751 @@
+/*
+ *  Force feedback support for Linux input subsystem
+ *
+ *  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
+ */
+
+#include <linux/input.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
+#include <linux/sched.h>
+
+#include "fixp-arith.h"
+
+/* #define DEBUG */
+
+#ifdef DEBUG
+#define debug(format, arg...) printk(KERN_DEBUG "ff-effects: " format "\n" , ## arg)
+#else
+#define debug(format, arg...) do {} while (0)
+#endif
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Anssi Hannula <[email protected]>");
+MODULE_DESCRIPTION("Force feedback support for input subsystem");
+
+/* Number of effects handled with memoryless devices */
+#define FF_MEMLESS_EFFECTS	16
+
+/* Envelope update interval in ms */
+#define FF_ENVELOPE_INTERVAL	50
+
+EXPORT_SYMBOL(input_ff_allocate);
+EXPORT_SYMBOL(input_ff_register);
+EXPORT_SYMBOL(input_ff_upload);
+EXPORT_SYMBOL(input_ff_erase);
+
+#define spin_ff_cond_lock(_ff, _flags)					  \
+	do {								  \
+		if (!_ff->driver->playback)				  \
+			spin_lock_irqsave(&_ff->atomiclock, _flags);	  \
+	} while (0);
+
+#define spin_ff_cond_unlock(_ff, _flags)					  \
+	do {								  \
+		if (!_ff->driver->playback)				  \
+			spin_unlock_irqrestore(&_ff->atomiclock, _flags); \
+	} while (0);
+
+static int input_ff_effect_access(struct input_dev *dev, int id, int override)
+{
+	struct ff_device *ff = dev->ff;
+	if (id < dev->ff_effects_max && id >= 0 && test_bit(FF_EFFECT_USED, ff->effects[id].flags))
+		if (override || ff->effects[id].owner == current->pid)
+			return 0;
+		else
+			return -EACCES;
+	else
+		return -EINVAL;
+}
+
+static int input_ff_envelope_time(struct ff_effect_status *effect, struct ff_envelope *envelope, unsigned long *event_time)
+{
+	unsigned long fade_start;
+	if (!envelope)
+		return 0;
+
+	if (envelope->attack_length && time_after(effect->play_at + msecs_to_jiffies(envelope->attack_length), effect->adj_at)) {
+		*event_time = effect->adj_at + msecs_to_jiffies(FF_ENVELOPE_INTERVAL);
+		return 1;
+	}
+
+	if (!envelope->fade_length || !effect->effect.replay.length)
+		return 0;
+
+	fade_start = effect->stop_at - msecs_to_jiffies(envelope->fade_length);
+
+	if (time_after(fade_start, effect->adj_at)) {
+		*event_time = fade_start;
+		return 1;
+	}
+
+	*event_time = effect->adj_at + msecs_to_jiffies(FF_ENVELOPE_INTERVAL);
+	if (time_after(*event_time, effect->stop_at))
+		*event_time = effect->stop_at;
+
+	return 1;
+}
+
+static void input_ff_calc_timer(struct ff_device *ff)
+{
+	int i;
+	int events = 0;
+	unsigned long next_time = 0;
+	debug("calculating next timer");
+	for (i = 0; i < FF_MEMLESS_EFFECTS; ++i) {
+		unsigned long event_time;
+		struct ff_envelope *envelope = NULL;
+		int event_set = 0;
+
+		if (!test_bit(FF_EFFECT_STARTED, ff->effects[i].flags)) {
+			if (test_bit(FF_EFFECT_PLAYING, ff->effects[i].flags)) {
+				event_time = ff->effects[i].stop_at = jiffies;
+				event_set = 1;
+			} else
+				continue;
+		} else {
+			if (!test_bit(FF_EFFECT_PLAYING, ff->effects[i].flags)) {
+				event_time = ff->effects[i].play_at;
+				event_set = 1;
+			} else {
+				if (ff->effects[i].effect.type == FF_PERIODIC)
+					envelope = &ff->effects[i].effect.u.periodic.envelope;
+				else if (ff->effects[i].effect.type == FF_CONSTANT)
+					envelope = &ff->effects[i].effect.u.constant.envelope;
+
+				event_set = input_ff_envelope_time(&ff->effects[i], envelope, &event_time);
+				if (!event_set && ff->effects[i].effect.replay.length) {
+					event_time = ff->effects[i].stop_at;
+					event_set = 1;
+				}
+			}
+		}
+
+		if (!event_set)
+			continue;
+		events++;
+
+		if (time_after(jiffies, event_time)) {
+			event_time = jiffies;
+			break;
+		}
+		if (events == 1)
+			next_time = event_time;
+		else {
+			if (time_after(next_time, event_time))
+				next_time = event_time;
+		}
+	}
+	if (!events) {
+		debug("no actions");
+		del_timer(&ff->timer);
+	} else {
+		debug("timer set");
+		mod_timer(&ff->timer, next_time);
+	}
+}
+
+static u16 input_ff_unsign(s16 value)
+{
+	if (value == -0x8000)
+		return 0x7fff;
+
+	return (value < 0 ? -value : value);
+}
+
+static int input_ff_envelope(struct ff_effect_status *effect, int value, struct ff_envelope *envelope)
+{
+	unsigned long current_time = jiffies;
+	unsigned int time_from_level;
+	unsigned int time_of_envelope;
+	unsigned int envelope_level;
+	int difference;
+
+	if (envelope->attack_length && time_after(effect->play_at + msecs_to_jiffies(envelope->attack_length),
+						  current_time)) {
+		debug("value = 0x%x, attack_level = 0x%x", value, envelope->attack_level);
+		time_from_level = current_time - effect->play_at;
+		time_of_envelope = msecs_to_jiffies(envelope->attack_length);
+		envelope_level = envelope->attack_level > 0x7fff ? 0x7fff : envelope->attack_level;
+	} else if (envelope->fade_length && effect->effect.replay.length &&
+			  time_after(current_time, effect->stop_at - msecs_to_jiffies(envelope->fade_length)) &&
+			  time_after(effect->stop_at, current_time)) {
+		time_from_level = effect->stop_at - current_time;
+		time_of_envelope = msecs_to_jiffies(envelope->fade_length);
+		envelope_level = envelope->fade_level > 0x7fff ? 0x7fff : envelope->fade_level;
+	} else {
+		return value;
+	}
+
+	difference = abs(value) - envelope_level;
+
+	debug("difference = %d", difference);
+	debug("time_from_level = 0x%x", time_from_level);
+	debug("time_of_envelope = 0x%x", time_of_envelope);
+	if (difference < 0)
+		difference = -((-difference) * time_from_level / time_of_envelope);
+	else
+		difference = difference * time_from_level / time_of_envelope;
+
+	debug("difference = %d", difference);
+
+	if (value < 0)
+		return -(difference + envelope_level);
+
+	return difference + envelope_level;
+}
+
+static int input_ff_emu_effect_type(struct input_dev *dev, int effect_type) {
+
+	if (test_bit(effect_type, dev->ff->flags))
+		return effect_type;
+
+	if (effect_type == FF_PERIODIC && test_bit(FF_RUMBLE, dev->ff->flags))
+		return FF_RUMBLE;
+
+	printk(KERN_ERR "ff-effects: invalid type in input_ff_emu_effect_type()\n");
+	return 0;
+}
+
+static int input_ff_safe_sum(int a, int b, int limit) {
+	int c;
+	if (!a)
+		return b;
+	c = a + b;
+	if (c > limit)
+		return limit;
+	return c;
+}
+
+static s8 input_ff_s8_sum(int a, int b) {
+	int c;
+	c = input_ff_safe_sum(a, b, 0x7f);
+	if (c < -0x80)
+		return -0x80;
+	return c;
+}
+
+static void input_ff_convert_effect(struct input_dev *dev, struct ff_effect *effect)
+{
+	int strong_magnitude, weak_magnitude;
+
+	if (effect->type == FF_RUMBLE && test_bit(FF_PERIODIC, dev->ff->flags)) {
+		/* Strong magnitude as 2/3 full and weak 1/3 full */
+		/* Also divide by 2 */
+		strong_magnitude = effect->u.rumble.strong_magnitude * 2 / 6;
+		weak_magnitude = effect->u.rumble.weak_magnitude / 6;
+
+		effect->type = FF_PERIODIC;
+
+		effect->u.periodic.waveform = FF_SINE;
+		effect->u.periodic.period = 50;
+		effect->u.periodic.magnitude = input_ff_safe_sum(strong_magnitude, weak_magnitude, 0x7fff);
+		effect->u.periodic.offset = 0;
+		effect->u.periodic.phase = 0;
+		effect->u.periodic.envelope.attack_length = 0;
+		effect->u.periodic.envelope.attack_level = 0;
+		effect->u.periodic.envelope.fade_length = 0;
+		effect->u.periodic.envelope.fade_level = 0;
+		return;
+	}
+
+
+	printk(KERN_ERR "ff-effects: invalid effect type in convert_effect()\n");
+}
+
+static void input_ff_sum_effect(struct ff_effect *effect, struct ff_effect_status *new, unsigned int gain)
+{
+	unsigned int strong, weak, i;
+	int x, y;
+	fixp_t level;
+	switch (new->effect.type) {
+		case FF_CONSTANT:
+			if (effect->type != FF_CONSTANT)
+				break;
+			i = new->effect.direction * 360 / 0xffff;
+			level = fixp_new16(input_ff_envelope(new, new->effect.u.constant.level,
+					   &new->effect.u.constant.envelope));
+			x = fixp_mult(fixp_sin(i), level) * gain / 0xffff;
+			y = fixp_mult(-fixp_cos(i), level) * gain / 0xffff;
+			/* here we abuse ff_ramp to hold x and y of constant force */
+			/* If in future any driver wants something else than
+			x and y in s8, this should be changed to something more generic */
+			effect->u.ramp.start_level = input_ff_s8_sum(effect->u.rumble.strong_magnitude, x);
+			effect->u.ramp.end_level = input_ff_s8_sum(effect->u.rumble.weak_magnitude, y);
+			return;
+		case FF_RUMBLE:
+			if (effect->type != FF_RUMBLE)
+				break;
+			strong = new->effect.u.rumble.strong_magnitude * gain / 0xffff;
+			weak = new->effect.u.rumble.weak_magnitude * gain / 0xffff;
+			effect->u.rumble.strong_magnitude =
+					input_ff_safe_sum(effect->u.rumble.strong_magnitude, strong, 0xffff);
+			effect->u.rumble.weak_magnitude =
+					input_ff_safe_sum(effect->u.rumble.weak_magnitude, weak, 0xffff);
+			return;
+		case FF_PERIODIC:
+			if (effect->type != FF_RUMBLE)
+				break;
+			/* very small period values should lessen the magnitude */
+			i = input_ff_unsign(new->effect.u.periodic.magnitude);
+			i = input_ff_envelope(new, i, &new->effect.u.periodic.envelope);
+			/* here we also scale it 0x7fff => 0xffff */
+			i = i * gain / 0x7fff;
+
+			effect->u.rumble.strong_magnitude =
+					input_ff_safe_sum(effect->u.rumble.strong_magnitude, i, 0xffff);
+			effect->u.rumble.weak_magnitude =
+					input_ff_safe_sum(effect->u.rumble.weak_magnitude, i, 0xffff);
+			return;
+	}
+
+	printk(KERN_ERR "ff-effects: invalid type in input_ff_sum_effect()\n");
+}
+
+static void input_ff_timer(unsigned long timer_data)
+{
+	struct input_dev *dev = (struct input_dev *) timer_data;
+	struct ff_device *ff = dev->ff;
+	struct ff_effect effect;
+	int i;
+	unsigned long flags;
+	int effects_pending;
+	unsigned long effect_handled[NBITS(FF_EFFECTS_MAX)];
+	int effect_type;
+	int safety;
+
+	debug("timer: updating effects");
+
+	spin_lock_irqsave(&ff->atomiclock, flags);
+
+	memset(effect_handled, 0, sizeof(effect_handled));
+	safety = 0;
+	effects_pending = 1;
+
+	while (effects_pending) {
+		if (safety++ > 50) {
+			printk(KERN_ERR "ff-effects: update aborted to avoid deadlock\n");
+			break;
+		}
+		effects_pending = 0;
+		memset(&effect, 0, sizeof(effect));
+		for (i = 0; i < dev->ff_effects_max; i++) {
+
+			if (test_bit(i, effect_handled))
+				continue;
+
+			if (!test_bit(FF_EFFECT_STARTED, ff->effects[i].flags)) {
+				if (!test_bit(FF_EFFECT_PLAYING, ff->effects[i].flags))
+					continue;
+				if (!effect.type) {
+					effect.type = input_ff_emu_effect_type(dev, ff->effects[i].effect.type);
+					clear_bit(FF_EFFECT_PLAYING, ff->effects[i].flags);
+					set_bit(i, effect_handled);
+					continue;
+				}
+				if (effect.type == input_ff_emu_effect_type(dev, ff->effects[i].effect.type)) {
+					clear_bit(FF_EFFECT_PLAYING, ff->effects[i].flags);
+					set_bit(i, effect_handled);
+					continue;
+				}
+				debug("effects pending: case 1");
+				effects_pending = 1;
+				continue;
+			}
+
+			if (time_after(ff->effects[i].play_at, jiffies)) {
+				set_bit(i, effect_handled);
+				continue;
+			}
+
+			effect_type = input_ff_emu_effect_type(dev, ff->effects[i].effect.type);
+
+			if (effect.type != effect_type) {
+				if (effect.type) {
+					debug("effects pending: case 2");
+					effects_pending = 1;
+					continue;
+				}
+				effect.type = effect_type;
+			}
+
+			if (ff->effects[i].effect.replay.length && time_after_eq(jiffies, ff->effects[i].stop_at)) {
+
+				clear_bit(FF_EFFECT_PLAYING, ff->effects[i].flags);
+
+				if (--ff->effects[i].count <= 0) {
+					clear_bit(FF_EFFECT_STARTED, ff->effects[i].flags);
+					set_bit(i, effect_handled);
+					continue;
+				} else {
+					ff->effects[i].play_at =
+							jiffies + msecs_to_jiffies(ff->effects[i].effect.replay.delay);
+					ff->effects[i].stop_at =
+							dev->ff->effects[i].play_at +
+							msecs_to_jiffies(ff->effects[i].effect.replay.length);
+					set_bit(i, effect_handled);
+					continue;
+				}
+			}
+
+			set_bit(FF_EFFECT_PLAYING, ff->effects[i].flags);
+
+			input_ff_sum_effect(&effect, &ff->effects[i], ff->gain);
+			ff->effects[i].adj_at = jiffies;
+			set_bit(i, effect_handled);
+		}
+
+		ff->driver->upload(dev, &effect, NULL);
+	}
+
+	input_ff_calc_timer(ff);
+	spin_unlock_irqrestore(&ff->atomiclock, flags);
+
+}
+
+static int _input_ff_erase(struct input_dev *dev, int id, int override)
+{
+	int ret = input_ff_effect_access(dev, id, override);
+	if (ret)
+		return ret;
+	if (dev->ff->driver->playback) {
+		dev->ff->driver->playback(dev, id, 0);
+		ret = dev->ff->driver->erase(dev, id);
+		if (!ret)
+			clear_bit(FF_EFFECT_USED, dev->ff->effects[id].flags);
+	} else {
+		if (test_and_clear_bit(FF_EFFECT_STARTED, dev->ff->effects[id].flags))
+			input_ff_calc_timer(dev->ff);
+		clear_bit(FF_EFFECT_USED, dev->ff->effects[id].flags);
+	}
+	return ret;
+}
+
+int input_ff_erase(struct input_dev *dev, int id)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int ret;
+	if (!test_bit(EV_FF, dev->evbit))
+		return -EINVAL;
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
+	}
+	spin_ff_cond_lock(ff, flags);
+	ret = _input_ff_erase(dev, id, current->pid == 0);
+	spin_ff_cond_unlock(ff, flags);
+
+	mutex_unlock(&dev->ff_lock);
+	return ret;
+}
+
+static int input_ff_flush(struct input_dev *dev, struct file *file)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int i;
+	debug("flushing now");
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
+	}
+	spin_ff_cond_lock(ff, flags);
+	for (i = 0; i < dev->ff_effects_max; i++) {
+		_input_ff_erase(dev, i, 0);
+	}
+	spin_ff_cond_unlock(ff, flags);
+	mutex_unlock(&dev->ff_lock);
+	return 0;
+}
+
+
+static int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
+{
+
+	struct ff_device *ff = dev->ff;
+	int ret = 0;
+	unsigned long flags = 0;
+	if (value < 0)
+		return -EINVAL;
+	/* Mutex is already locked in input.c as input_ff_event address is
+	   stored in ff_device struct */
+	spin_ff_cond_lock(ff, flags);
+
+	if (code == FF_GAIN) {
+		int i;
+		if (!test_bit(FF_GAIN, dev->ffbit) || value > 0xffff || value < 0) {
+			ret = -EINVAL;
+		} else if (ff->driver->set_gain) {
+			ff->driver->set_gain(dev, value);
+		} else if (!ff->driver->playback) {
+			ff->gain = value;
+			for (i = 0; i < dev->ff_effects_max; i++)
+				clear_bit(FF_EFFECT_PLAYING, ff->effects[i].flags);
+			input_ff_calc_timer(ff);
+		} else {
+			ret = -ENOSYS;
+		}
+		spin_ff_cond_unlock(ff, flags);
+		return ret;
+	}
+
+	if (code == FF_AUTOCENTER) {
+		if (!test_bit(FF_AUTOCENTER, dev->ffbit) || value > 0xffff || value < 0) {
+			ret = -EINVAL;
+		} else if (ff->driver->set_autocenter) {
+			ff->driver->set_autocenter(dev, value);
+			ret = 0;
+		} else {
+			ret = -ENOSYS;
+		}
+		spin_ff_cond_unlock(ff, flags);
+		return ret;
+	}
+
+
+	ret = input_ff_effect_access(dev, code, 1);
+	if (ret) {
+		spin_ff_cond_unlock(ff, flags);
+		return ret;
+	}
+
+	if (ff->driver->playback) {
+		ret = ff->driver->playback(dev, code, value);
+		return ret;
+	}
+
+	if (value > 0) {
+		debug("initiated play");
+		set_bit(FF_EFFECT_STARTED, ff->effects[code].flags);
+		clear_bit(FF_EFFECT_PLAYING, ff->effects[code].flags);
+		ff->effects[code].count = value;
+		ff->effects[code].play_at = jiffies +
+				msecs_to_jiffies(ff->effects[code].effect.replay.delay);
+		ff->effects[code].stop_at = ff->effects[code].play_at +
+				msecs_to_jiffies(ff->effects[code].effect.replay.length);
+		ff->effects[code].adj_at = ff->effects[code].play_at;
+	} else {
+		debug("initiated stop");
+		clear_bit(FF_EFFECT_STARTED, ff->effects[code].flags);
+	}
+	input_ff_calc_timer(ff);
+
+	spin_unlock_irqrestore(&ff->atomiclock, flags);
+	return 0;
+}
+
+#define VALID_EFFECT_MIN	FF_RUMBLE
+#define VALID_EFFECT_MAX	FF_RAMP
+#define VALID_WFORM_MIN		FF_SQUARE
+#define VALID_WFORM_MAX		FF_CUSTOM
+static int input_ff_validate_effect(struct ff_effect *effect)
+{
+	if (effect->type < VALID_EFFECT_MIN || effect->type > VALID_EFFECT_MAX)
+		return -EINVAL;
+	if (effect->type == FF_PERIODIC &&
+		   (effect->u.periodic.waveform < VALID_WFORM_MIN ||
+		   effect->u.periodic.waveform > VALID_WFORM_MAX))
+		return -EINVAL;
+	return 0;
+}
+
+int input_ff_upload(struct input_dev *dev, struct ff_effect *effect)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int ret = 0; int id;
+
+	if (!test_bit(EV_FF, dev->evbit) || input_ff_validate_effect(effect) ||
+		    !test_bit(effect->type, dev->ffbit) ||
+		    (effect->type == FF_PERIODIC &&
+				    !test_bit(effect->u.periodic.waveform, dev->ffbit))) {
+		debug("invalid upload");
+		return -EINVAL;
+	}
+
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
+	}
+	spin_ff_cond_lock(ff, flags);
+
+	if (effect->id == -1) {
+		for (id = 0; id < dev->ff_effects_max && test_bit(FF_EFFECT_USED, ff->effects[id].flags); id++);
+
+		if (id >= dev->ff_effects_max) {
+			spin_ff_cond_unlock(ff, flags);
+			mutex_unlock(&dev->ff_lock);
+			return -ENOSPC;
+		}
+
+		effect->id = id;
+		ff->effects[id].owner = current->pid;
+		ff->effects[id].flags[0] = 0;
+		ff->effects[id].effect = *effect;
+
+		if (ff->driver->playback) {
+			if (!test_bit(effect->type, ff->flags))
+				input_ff_convert_effect(dev, effect);
+			ret = ff->driver->upload(dev, effect, NULL);
+			if (!ret)
+				set_bit(FF_EFFECT_USED, ff->effects[id].flags);
+			mutex_unlock(&dev->ff_lock);
+			return ret;
+		}
+		set_bit(FF_EFFECT_USED, ff->effects[id].flags);
+
+	} else {
+		id = effect->id;
+
+		ret = input_ff_effect_access(dev, id, 1);
+		if (ret) {
+			spin_ff_cond_unlock(ff, flags);
+			mutex_unlock(&dev->ff_lock);
+			return ret;
+		}
+
+		if (effect->type != ff->effects[id].effect.type ||
+				  (effect->type == FF_PERIODIC && effect->u.periodic.waveform !=
+				  ff->effects[id].effect.u.periodic.waveform)) {
+			spin_ff_cond_unlock(ff, flags);
+			mutex_unlock(&dev->ff_lock);
+			return -EINVAL;
+		}
+
+		if (ff->driver->playback) {
+			if (!test_bit(effect->type, ff->flags))
+				input_ff_convert_effect(dev, effect);
+			ret = ff->driver->upload(dev, effect, &ff->effects[id].effect);
+			ff->effects[id].effect = *effect;
+			mutex_unlock(&dev->ff_lock);
+			return ret;
+		}
+		ff->effects[id].effect = *effect;
+		clear_bit(FF_EFFECT_PLAYING, ff->effects[id].flags);
+
+	}
+
+	spin_unlock_irqrestore(&ff->atomiclock, flags);
+	mutex_unlock(&dev->ff_lock);
+	return ret;
+}
+
+int input_ff_allocate(struct input_dev *dev)
+{
+	debug("allocating device");
+	mutex_lock(&dev->ff_lock);
+	if (dev->ff)
+		printk(KERN_ERR "ff-effects: allocating to non-NULL pointer\n");
+	dev->ff = kzalloc(sizeof(*dev->ff), GFP_KERNEL);
+	if (!dev->ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENOMEM;
+	}
+	spin_lock_init(&dev->ff->atomiclock);
+	init_timer(&dev->ff->timer);
+	dev->ff->timer.function = input_ff_timer;
+	dev->ff->timer.data = (unsigned long) dev;
+	dev->ff->event = input_ff_event;
+	mutex_unlock(&dev->ff_lock);
+	debug("ff allocated");
+	return 0;
+}
+
+int input_ff_register(struct input_dev *dev, struct ff_driver *driver)
+{
+	debug("registering device");
+	if (!dev->ff) {
+		printk(KERN_ERR "ff-effects: tried to register before allocate\n");
+		return -EPERM;
+	}
+	if (driver->playback && !dev->ff_effects_max) {
+		printk(KERN_ERR "ff-effects: cannot register a device with 0 effects\n");
+		return -EINVAL;
+	}
+	mutex_lock(&dev->ff_lock);
+
+	dev->flush = input_ff_flush;
+	dev->ff->driver = driver;
+
+	if (!dev->ff->driver->playback) {
+		dev->ff_effects_max = FF_MEMLESS_EFFECTS;
+		dev->ff->gain = 0xffff;
+		set_bit(FF_GAIN, dev->ffbit);
+	}
+
+	if (test_bit(FF_RUMBLE, dev->ff->flags)) {
+		debug("device has rumble");
+		set_bit(FF_RUMBLE, dev->ffbit);
+		if (!dev->ff->driver->playback) {
+			set_bit(FF_PERIODIC, dev->ffbit);
+			set_bit(FF_SINE, dev->ffbit);
+			set_bit(FF_TRIANGLE, dev->ffbit);
+			set_bit(FF_SQUARE, dev->ffbit);
+		}
+	}
+
+	if (test_bit(FF_PERIODIC, dev->ff->flags)) {
+		set_bit(FF_PERIODIC, dev->ffbit);
+		if (dev->ff->driver->playback)
+			set_bit(FF_RUMBLE, dev->ffbit);
+	}
+
+	if (test_bit(FF_CONSTANT, dev->ff->flags))
+		set_bit(FF_CONSTANT, dev->ffbit);
+	if (test_bit(FF_SPRING, dev->ff->flags))
+		set_bit(FF_SPRING, dev->ffbit);
+	if (test_bit(FF_FRICTION, dev->ff->flags))
+		set_bit(FF_FRICTION, dev->ffbit);
+	if (test_bit(FF_DAMPER, dev->ff->flags))
+		set_bit(FF_DAMPER, dev->ffbit);
+	if (test_bit(FF_INERTIA, dev->ff->flags))
+		set_bit(FF_INERTIA, dev->ffbit);
+	if (test_bit(FF_RAMP, dev->ff->flags))
+		set_bit(FF_RAMP, dev->ffbit);
+	if (test_bit(FF_SQUARE, dev->ff->flags))
+		set_bit(FF_SQUARE, dev->ffbit);
+	if (test_bit(FF_TRIANGLE, dev->ff->flags))
+		set_bit(FF_TRIANGLE, dev->ffbit);
+	if (test_bit(FF_SINE, dev->ff->flags))
+		set_bit(FF_SINE, dev->ffbit);
+	if (test_bit(FF_SAW_UP, dev->ff->flags))
+		set_bit(FF_SAW_UP, dev->ffbit);
+	if (test_bit(FF_SAW_DOWN, dev->ff->flags))
+		set_bit(FF_SAW_DOWN, dev->ffbit);
+	if (test_bit(FF_CUSTOM, dev->ff->flags))
+		set_bit(FF_CUSTOM, dev->ffbit);
+	if (test_bit(FF_GAIN, dev->ff->flags))
+		set_bit(FF_GAIN, dev->ffbit);
+	if (test_bit(FF_AUTOCENTER, dev->ff->flags))
+		set_bit(FF_AUTOCENTER, dev->ffbit);
+
+ 	set_bit(EV_FF, dev->evbit);
+	mutex_unlock(&dev->ff_lock);
+
+	return 0;
+}
+
drivers/input/Kconfig +9 -0
Index: linux-2.6.17-rc4-git1/drivers/input/Kconfig
===================================================================
@@ -24,6 +24,14 @@ config INPUT
 
 if INPUT
 
+config INPUT_FF_EFFECTS
+	tristate "Force feedback effects"
+	help
+	  Say Y here if you want to be able to play force feedback effects.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ff-effects.
+
 comment "Userland interfaces"
 
 config INPUT_MOUSEDEV
@@ -110,6 +118,7 @@ config INPUT_TSDEV_SCREEN_Y
 
 config INPUT_EVDEV
 	tristate "Event interface"
+	depends on INPUT_FF_EFFECTS || INPUT_FF_EFFECTS=n
 	help
 	  Say Y here if you want your input device events be accessible
 	  under char device 13:64+ - /dev/input/eventX in a generic way.
drivers/input/Makefile +1 -0
Index: linux-2.6.17-rc4-git1/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 +50 -0

62 lines not on this page · raw message

drivers/input/input.c +16 -1
Index: linux-2.6.17-rc4-git1/drivers/input/input.c
===================================================================
@@ -172,7 +172,10 @@ void input_event(struct input_dev *dev, 
 			break;
 
 		case EV_FF:
-			if (dev->event) dev->event(dev, type, code, value);
+			mutex_lock(&dev->ff_lock);
+			if (dev->ff)
+				dev->ff->event(dev, type, code, value);
+			mutex_unlock(&dev->ff_lock);
 			break;
 	}
 
@@ -733,6 +736,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;
+		kfree(ff);
+		mutex_unlock(&dev->ff_lock);
+	}
+
 	kfree(dev);
 	module_put(THIS_MODULE);
 }
@@ -874,6 +888,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 +4 -8
Index: linux-2.6.17-rc4-git1/drivers/input/evdev.c
===================================================================
@@ -458,24 +458,20 @@ 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);
+				err = input_ff_upload(dev, &effect);
 				if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
 					return -EFAULT;
 				return err;
-			} else
-				return -ENOSYS;
+			}
 
 		case EVIOCRMFF:
-			if (!dev->erase_effect)
-				return -ENOSYS;
-
-			return dev->erase_effect(dev, (int)(unsigned long) p);
+			return input_ff_erase(dev, (int)(unsigned long) p);
 
 		case EVIOCGEFFECTS:
 			if (put_user(dev->ff_effects_max, ip))

--
Anssi Hannula

#4 lore raw

Re: [patch 03/11] input: new force feedback interface

Quoted 12 lines · Anssi Hannula

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.

Quoted 5 lines

The module is named ff-effects. If INPUT_FF_EFFECTS is enabled, the force feedback drivers and interfaces (evdev) will be depending on it.

Userspace interface is left unaltered.

Nice-looking patches.

drivers/input/ff-effects.c line 64

Quoted 12 lines
drivers/input/ff-effects.c new file +11 -0
+#define spin_ff_cond_lock(_ff, _flags)					  \
+	do {								  \
+		if (!_ff->driver->playback)				  \
+			spin_lock_irqsave(&_ff->atomiclock, _flags);	  \
+	} while (0);
+
+#define spin_ff_cond_unlock(_ff, _flags)					  \
+	do {								  \
+		if (!_ff->driver->playback)				  \
+			spin_unlock_irqrestore(&_ff->atomiclock, _flags); \
+	} while (0);

Making these static inline functions would deuglify them a bit.

drivers/input/ff-effects.c line 69

Quoted 4 lines
drivers/input/ff-effects.c new file +4 -0
+static int input_ff_effect_access(struct input_dev *dev, int id, int override)
+{
+	struct ff_device *ff = dev->ff;
+	if (id < dev->ff_effects_max && id >= 0 && test_bit(FF_EFFECT_USED, ff->effects[id].flags))

Kernel does have an 80-columns rule, but input seems to have always spurned it.

drivers/input/ff-effects.c line 84

Quoted 7 lines
drivers/input/ff-effects.c new file +7 -0
+static int input_ff_envelope_time(struct ff_effect_status *effect, struct ff_envelope *envelope, unsigned long *event_time)
+{
+	unsigned long fade_start;
+	if (!envelope)
+		return 0;
+
+	if (envelope->attack_length && time_after(effect->play_at + msecs_to_jiffies(envelope->attack_length), effect->adj_at)) {

Try using an 80-column wondow for a while ;)

drivers/input/ff-effects.c line 205

Quoted 12 lines
drivers/input/ff-effects.c new file +12 -0
+		return value;
+	}
+
+	difference = abs(value) - envelope_level;
+
+	debug("difference = %d", difference);
+	debug("time_from_level = 0x%x", time_from_level);
+	debug("time_of_envelope = 0x%x", time_of_envelope);
+	if (difference < 0)
+		difference = -((-difference) * time_from_level / time_of_envelope);
+	else
+		difference = difference * time_from_level / time_of_envelope;

You've checked there's no possibility of divide-by-zero here?

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static int input_ff_safe_sum(int a, int b, int limit) {

The opening brace goes in column zero, please.

drivers/input/ff-effects.c line 237

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+	int c;
+	if (!a)
+		return b;
+	c = a + b;
+	if (c > limit)
+		return limit;
+	return c;
+}
+
+static s8 input_ff_s8_sum(int a, int b) {

dittoes.

Quoted 8 lines
drivers/input/ff-effects.c new file +6 -0
+	int c;
+	c = input_ff_safe_sum(a, b, 0x7f);
+	if (c < -0x80)
+		return -0x80;
+	return c;
+}
 
...

drivers/input/ff-effects.c line 330

Quoted 10 lines
drivers/input/ff-effects.c new file +9 -0
 
+static void input_ff_timer(unsigned long timer_data)
+{
+	struct input_dev *dev = (struct input_dev *) timer_data;
+	struct ff_device *ff = dev->ff;
+	struct ff_effect effect;
+	int i;
+	unsigned long flags;
+	int effects_pending;
+	unsigned long effect_handled[NBITS(FF_EFFECTS_MAX)];

DECLARE_BITMAP would be more usual. (Yes, it should have been called DEFINE_BITMAP).

drivers/input/ff-effects.c line 338

Quoted 8 lines
drivers/input/ff-effects.c new file +8 -0
+	int effect_type;
+	int safety;
+
+	debug("timer: updating effects");
+
+	spin_lock_irqsave(&ff->atomiclock, flags);
+
+	memset(effect_handled, 0, sizeof(effect_handled));

You could take the lock after the memset.

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+int input_ff_erase(struct input_dev *dev, int id)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int ret;
+	if (!test_bit(EV_FF, dev->evbit))
+		return -EINVAL;
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {

drivers/input/ff-effects.c line 460

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
+	}
+	spin_ff_cond_lock(ff, flags);
+	ret = _input_ff_erase(dev, id, current->pid == 0);
+	spin_ff_cond_unlock(ff, flags);
+
+	mutex_unlock(&dev->ff_lock);
+	return ret;
+}

Perhaps you meant `current->uid == 0' here. There's no way in which pid 0 will call this code.

What's happening here anyway? Why does this code need to know about pids?

Checking for uid==0 woud be a fishy thing to do as well.

Quoted 6 lines
drivers/input/ff-effects.c new file +6 -0
+static int input_ff_flush(struct input_dev *dev, struct file *file)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int i;
+	debug("flushing now");

drivers/input/ff-effects.c line 477

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
+	}
+	spin_ff_cond_lock(ff, flags);
+	for (i = 0; i < dev->ff_effects_max; i++) {
+		_input_ff_erase(dev, i, 0);
+	}

Unneeded braces.

Quoted 35 lines
drivers/input/ff-effects.c new file +35 -0
+	spin_ff_cond_unlock(ff, flags);
+	mutex_unlock(&dev->ff_lock);
+	return 0;
+}
+
+
+		ff->effects[id].flags[0] = 0;
+		ff->effects[id].effect = *effect;
+
+		if (ff->driver->playback) {
+			if (!test_bit(effect->type, ff->flags))
+				input_ff_convert_effect(dev, effect);
+			ret = ff->driver->upload(dev, effect, NULL);
+			if (!ret)
+				set_bit(FF_EFFECT_USED, ff->effects[id].flags);
+			mutex_unlock(&dev->ff_lock);
+			return ret;
+		}
+		set_bit(FF_EFFECT_USED, ff->effects[id].flags);
+
+	} else {
+		id = effect->id;
+
+		ret = input_ff_effect_access(dev, id, 1);
+		if (ret) {
+			spin_ff_cond_unlock(ff, flags);
+			mutex_unlock(&dev->ff_lock);
+			return ret;
+		}
+
+		if (effect->type != ff->effects[id].effect.type ||
+				  (effect->type == FF_PERIODIC && effect->u.periodic.waveform !=
+				  ff->effects[id].effect.u.periodic.waveform)) {
+			spin_ff_cond_unlock(ff, flags);
+			mutex_unlock(&dev->ff_lock);

drivers/input/ff-effects.c line 645

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+			return -EINVAL;
+		}
+
+		if (ff->driver->playback) {
+			if (!test_bit(effect->type, ff->flags))
+				input_ff_convert_effect(dev, effect);
+			ret = ff->driver->upload(dev, effect, &ff->effects[id].effect);
+			ff->effects[id].effect = *effect;
+			mutex_unlock(&dev->ff_lock);
+			return ret;

I think we're missing a spin_ff_cond_unlock() here?

drivers/input/ff-effects.c line 655

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+		}
+		ff->effects[id].effect = *effect;
+		clear_bit(FF_EFFECT_PLAYING, ff->effects[id].flags);
+
+	}
+
+	spin_unlock_irqrestore(&ff->atomiclock, flags);
+	mutex_unlock(&dev->ff_lock);
+	return ret;
+}

And here we have spin_unlock_irqrestore() instead of spin_ff_cond_unlock().

It would be best to convert this function to have a single return point. That tends to prevent problems like this from happening, and from creeping in later on.

Quoted 6 lines
drivers/input/ff-effects.c new file +6 -0
+int input_ff_allocate(struct input_dev *dev)
+{
+	debug("allocating device");
+	mutex_lock(&dev->ff_lock);
+	if (dev->ff)
+		printk(KERN_ERR "ff-effects: allocating to non-NULL pointer\n");

drivers/input/ff-effects.c line 672

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+	dev->ff = kzalloc(sizeof(*dev->ff), GFP_KERNEL);
+	if (!dev->ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENOMEM;
+	}
+	spin_lock_init(&dev->ff->atomiclock);
+	init_timer(&dev->ff->timer);
+	dev->ff->timer.function = input_ff_timer;
+	dev->ff->timer.data = (unsigned long) dev;
+	dev->ff->event = input_ff_event;

setup_timer()

Quoted 13 lines
drivers/input/ff-effects.c new file +5 -0
+	mutex_unlock(&dev->ff_lock);
+	debug("ff allocated");
+	return 0;
+}
+
 
...

Index: linux-2.6.17-rc4-git1/drivers/input/Kconfig
===================================================================

drivers/input/Kconfig config INPUT · line 33

Quoted 10 lines
drivers/input/Kconfig +7 -0
@@ -24,6 +24,14 @@ config INPUT
 
 if INPUT
 
+config INPUT_FF_EFFECTS
+	tristate "Force feedback effects"
+	help
+	  Say Y here if you want to be able to play force feedback effects.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ff-effects.

hm. I'd have expected more dependencies than this.

drivers/input/Kconfig config INPUT_TSDEV_SCREEN_Y · line 121

Quoted 8 lines
drivers/input/Kconfig +1 -0
 comment "Userland interfaces"
 
 config INPUT_MOUSEDEV
@@ -110,6 +118,7 @@ config INPUT_TSDEV_SCREEN_Y
 
 config INPUT_EVDEV
 	tristate "Event interface"
+	depends on INPUT_FF_EFFECTS || INPUT_FF_EFFECTS=n

Isn't that always true?

drivers/input/Kconfig config INPUT_TSDEV_SCREEN_Y · line 124

Quoted 3 lines
drivers/input/Kconfig +3 -0
+
+struct ff_effect_status {
+	pid_t owner;

This code is almost devoid of comments. Those which it does have tend to cover little low-level implementation details. But it's the *big* things which a reader is not able to learn from the implementation, and which should be commented. Like: why on earth does this code need to know about pids?

Quoted 1 line

+#if defined(CONFIG_INPUT_FF_EFFECTS_MODULE) || defined(CONFIG_INPUT_FF_EFFECTS)

No, we shouldn't use CONFIG_FOO_MODULE. We just don't know at compile-time whether the user will later compile and insert a particular module.

drivers/input/Kconfig

Quoted 6 lines
drivers/input/Kconfig +6 -0
+		mutex_lock(&dev->ff_lock);
+		del_timer_sync(&ff->timer);
+		dev->flush = NULL;
+		dev->ff = NULL;
+		kfree(ff);
+		mutex_unlock(&dev->ff_lock);

The kfree can be moved outside the lock.

#5 lore raw

Re: [patch 03/11] input: new force feedback interface

Quoted 13 lines · Andrew Morton
Quoted 11 lines · Anssi Hannula

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.

Quoted 9 lines
Quoted 5 lines

The module is named ff-effects. If INPUT_FF_EFFECTS is enabled, the force feedback drivers and interfaces (evdev) will be depending on it.

Userspace interface is left unaltered.

Nice-looking patches.

Thanks for looking and providing helpful comments :)

Quoted 6 lines
Quoted 6 lines
drivers/input/ff-effects.c new file +6 -0
+#define spin_ff_cond_lock(_ff, _flags)					  \
+	do {								  \
+		if (!_ff->driver->playback)				  \
+			spin_lock_irqsave(&_ff->atomiclock, _flags);	  \
+	} while (0);
+
Quoted 9 lines

drivers/input/ff-effects.c line 64

Quoted 5 lines
drivers/input/ff-effects.c new file +5 -0
+#define spin_ff_cond_unlock(_ff, _flags)					  \
+	do {								  \
+		if (!_ff->driver->playback)				  \
+			spin_unlock_irqrestore(&_ff->atomiclock, _flags); \
+	} while (0);

Making these static inline functions would deuglify them a bit.

I put them like that because spin_lock_irqsave is a macro that uses the local variable "flags".
But yes, I can probably pass that parameter to an inline function as a pointer. I'll change that.

Quoted 9 lines

drivers/input/ff-effects.c line 69

Quoted 4 lines
drivers/input/ff-effects.c new file +4 -0
+static int input_ff_effect_access(struct input_dev *dev, int id, int override)
+{
+	struct ff_device *ff = dev->ff;
+	if (id < dev->ff_effects_max && id >= 0 && test_bit(FF_EFFECT_USED, ff->effects[id].flags))

Kernel does have an 80-columns rule, but input seems to have always spurned it.

Quoted 10 lines

drivers/input/ff-effects.c line 84

Quoted 7 lines
drivers/input/ff-effects.c new file +7 -0
+static int input_ff_envelope_time(struct ff_effect_status *effect, struct ff_envelope *envelope, unsigned long *event_time)
+{
+	unsigned long fade_start;
+	if (!envelope)
+		return 0;
+
+	if (envelope->attack_length && time_after(effect->play_at + msecs_to_jiffies(envelope->attack_length), effect->adj_at)) {

Try using an 80-column wondow for a while ;)

Okay, I'll make the lines shorter.

Quoted 18 lines
Quoted 4 lines
drivers/input/ff-effects.c new file +2 -0
+		return value;
+	}

drivers/input/ff-effects.c line 205

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+
+	difference = abs(value) - envelope_level;
+
+	debug("difference = %d", difference);
+	debug("time_from_level = 0x%x", time_from_level);
+	debug("time_of_envelope = 0x%x", time_of_envelope);
+	if (difference < 0)
+		difference = -((-difference) * time_from_level / time_of_envelope);
+	else
+		difference = difference * time_from_level / time_of_envelope;

You've checked there's no possibility of divide-by-zero here?

Yes, the "time_of_envelope" is set a few lines above from "envelope->attack_length" or "envelope->fade_length", and there is an if block that checks they're non-zero.

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static int input_ff_safe_sum(int a, int b, int limit) {

The opening brace goes in column zero, please.

Quoted 13 lines

drivers/input/ff-effects.c line 237

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+	int c;
+	if (!a)
+		return b;
+	c = a + b;
+	if (c > limit)
+		return limit;
+	return c;
+}
+
+static s8 input_ff_s8_sum(int a, int b) {

dittoes.

Okay, will fix.

Quoted 10 lines
Quoted 10 lines
drivers/input/ff-effects.c new file +6 -0
+	int c;
+	c = input_ff_safe_sum(a, b, 0x7f);
+	if (c < -0x80)
+		return -0x80;
+	return c;
+}
 
...
Quoted 14 lines

drivers/input/ff-effects.c line 330

Quoted 9 lines
drivers/input/ff-effects.c new file +9 -0
+static void input_ff_timer(unsigned long timer_data)
+{
+	struct input_dev *dev = (struct input_dev *) timer_data;
+	struct ff_device *ff = dev->ff;
+	struct ff_effect effect;
+	int i;
+	unsigned long flags;
+	int effects_pending;
+	unsigned long effect_handled[NBITS(FF_EFFECTS_MAX)];

DECLARE_BITMAP would be more usual. (Yes, it should have been called DEFINE_BITMAP).

Ok.

Quoted 12 lines

drivers/input/ff-effects.c line 338

Quoted 8 lines
drivers/input/ff-effects.c new file +8 -0
+	int effect_type;
+	int safety;
+
+	debug("timer: updating effects");
+
+	spin_lock_irqsave(&ff->atomiclock, flags);
+
+	memset(effect_handled, 0, sizeof(effect_handled));

You could take the lock after the memset.

Ok.

Quoted 16 lines
Quoted 16 lines
drivers/input/ff-effects.c new file +16 -0
+int input_ff_erase(struct input_dev *dev, int id)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int ret;
+	if (!test_bit(EV_FF, dev->evbit))
+		return -EINVAL;
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
+	}
+	spin_ff_cond_lock(ff, flags);
+	ret = _input_ff_erase(dev, id, current->pid == 0);
+	spin_ff_cond_unlock(ff, flags);
Quoted 8 lines

drivers/input/ff-effects.c line 460

Quoted 4 lines
drivers/input/ff-effects.c new file +4 -0
+
+	mutex_unlock(&dev->ff_lock);
+	return ret;
+}

Perhaps you meant `current->uid == 0' here. There's no way in which pid 0 will call this code.

Right, a silly mistake.

Quoted 3 lines

What's happening here anyway? Why does this code need to know about pids?

Checking for uid==0 woud be a fishy thing to do as well.

User ID 0 is allowed to delete effects of other users. Pids are used to keep a track of what process owns what effects. This is the same behaviour as before.

There is a problem with this, though:
When a process closes any fd to this device, all pid-matching effects are deleted whether the process has another fd using the device or not.

One solution would probably be to add some handle parameter to input_ff_upload() and input_ff_erase(), and then in evdev_ioctl_handler() pass an id unique to this fd. Then effects would be fd-specific, not pid-specific. I think the uid == 0 thing can also be dropped... I don't think the root user needs ability to override user effects (it can delete them anyway, just kill the user process owning the effects).

WDYT?

Quoted 12 lines
Quoted 12 lines
drivers/input/ff-effects.c new file +11 -0
+static int input_ff_flush(struct input_dev *dev, struct file *file)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int i;
+	debug("flushing now");
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
Quoted 9 lines

drivers/input/ff-effects.c line 477

Quoted 5 lines
drivers/input/ff-effects.c new file +5 -0
+	}
+	spin_ff_cond_lock(ff, flags);
+	for (i = 0; i < dev->ff_effects_max; i++) {
+		_input_ff_erase(dev, i, 0);
+	}

Unneeded braces.

Will remove.

Quoted 40 lines
Quoted 40 lines
drivers/input/ff-effects.c new file +40 -0
+	spin_ff_cond_unlock(ff, flags);
+	mutex_unlock(&dev->ff_lock);
+	return 0;
+}
+
+
+		ff->effects[id].flags[0] = 0;
+		ff->effects[id].effect = *effect;
+
+		if (ff->driver->playback) {
+			if (!test_bit(effect->type, ff->flags))
+				input_ff_convert_effect(dev, effect);
+			ret = ff->driver->upload(dev, effect, NULL);
+			if (!ret)
+				set_bit(FF_EFFECT_USED, ff->effects[id].flags);
+			mutex_unlock(&dev->ff_lock);
+			return ret;
+		}
+		set_bit(FF_EFFECT_USED, ff->effects[id].flags);
+
+	} else {
+		id = effect->id;
+
+		ret = input_ff_effect_access(dev, id, 1);
+		if (ret) {
+			spin_ff_cond_unlock(ff, flags);
+			mutex_unlock(&dev->ff_lock);
+			return ret;
+		}
+
+		if (effect->type != ff->effects[id].effect.type ||
+				  (effect->type == FF_PERIODIC && effect->u.periodic.waveform !=
+				  ff->effects[id].effect.u.periodic.waveform)) {
+			spin_ff_cond_unlock(ff, flags);
+			mutex_unlock(&dev->ff_lock);
+			return -EINVAL;
+		}
+
+		if (ff->driver->playback) {
+			if (!test_bit(effect->type, ff->flags))
Quoted 8 lines

drivers/input/ff-effects.c line 645

Quoted 5 lines
drivers/input/ff-effects.c new file +5 -0
+				input_ff_convert_effect(dev, effect);
+			ret = ff->driver->upload(dev, effect, &ff->effects[id].effect);
+			ff->effects[id].effect = *effect;
+			mutex_unlock(&dev->ff_lock);
+			return ret;

I think we're missing a spin_ff_cond_unlock() here?

Well, spin_ff_cond_unlock() checks for ff->driver->playback and it is already tested in the if block above.

Quoted 14 lines

drivers/input/ff-effects.c line 655

Quoted 11 lines
drivers/input/ff-effects.c new file +10 -0
+		}
+		ff->effects[id].effect = *effect;
+		clear_bit(FF_EFFECT_PLAYING, ff->effects[id].flags);
+
+	}
+
+	spin_unlock_irqrestore(&ff->atomiclock, flags);
+	mutex_unlock(&dev->ff_lock);
+	return ret;
+}

And here we have spin_unlock_irqrestore() instead of spin_ff_cond_unlock().

If there is no need to unlock, one of the above "if (ff->driver->playback)" would be true and the function would've already returned before this point.

Quoted 3 lines

It would be best to convert this function to have a single return point. That tends to prevent problems like this from happening, and from creeping in later on.

I agree that the locking is too confusing in input_ff_event() and input_ff_upload(), even if it is correct.

I'll modify the function to have a single return point, or maybe split the function for the two different locking paths, which then call common functions without the need to cond_lock. I guess that could be done for all cond_locking functions.

Quoted 12 lines
Quoted 12 lines
drivers/input/ff-effects.c new file +11 -0
+int input_ff_allocate(struct input_dev *dev)
+{
+	debug("allocating device");
+	mutex_lock(&dev->ff_lock);
+	if (dev->ff)
+		printk(KERN_ERR "ff-effects: allocating to non-NULL pointer\n");
+	dev->ff = kzalloc(sizeof(*dev->ff), GFP_KERNEL);
+	if (!dev->ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENOMEM;
+	}
Quoted 9 lines

drivers/input/ff-effects.c line 672

Quoted 5 lines
drivers/input/ff-effects.c new file +5 -0
+	spin_lock_init(&dev->ff->atomiclock);
+	init_timer(&dev->ff->timer);
+	dev->ff->timer.function = input_ff_timer;
+	dev->ff->timer.data = (unsigned long) dev;
+	dev->ff->event = input_ff_event;

setup_timer()

Will change.

Quoted 16 lines
Quoted 16 lines
drivers/input/ff-effects.c new file +5 -0
+	mutex_unlock(&dev->ff_lock);
+	debug("ff allocated");
+	return 0;
+}
+
 
...

Index: linux-2.6.17-rc4-git1/drivers/input/Kconfig
===================================================================

drivers/input/Kconfig +0 -0
@@ -24,6 +24,14 @@ config INPUT
 

if INPUT

Quoted 11 lines

drivers/input/Kconfig config INPUT · line 33

Quoted 7 lines
drivers/input/Kconfig +7 -0
+config INPUT_FF_EFFECTS
+	tristate "Force feedback effects"
+	help
+	  Say Y here if you want to be able to play force feedback effects.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ff-effects.

hm. I'd have expected more dependencies than this.

Only INPUT.

Quoted 5 lines
Quoted 5 lines

comment "Userland interfaces"

config INPUT_MOUSEDEV

drivers/input/Kconfig +0 -0
@@ -110,6 +118,7 @@ config INPUT_TSDEV_SCREEN_Y
 
Quoted 7 lines

drivers/input/Kconfig config INPUT_TSDEV_SCREEN_Y · line 121

Quoted 3 lines

config INPUT_EVDEV
tristate "Event interface"

drivers/input/Kconfig +1 -0
+	depends on INPUT_FF_EFFECTS || INPUT_FF_EFFECTS=n

Isn't that always true?

This disallows building evdev as builtin and ff-effects as module.

Quoted 10 lines

drivers/input/Kconfig

Quoted 3 lines
drivers/input/Kconfig +3 -0
+
+struct ff_effect_status {
+	pid_t owner;

This code is almost devoid of comments. Those which it does have tend to cover little low-level implementation details. But it's the *big* things which a reader is not able to learn from the implementation, and which should be commented. Like: why on earth does this code need to know about pids?

Okay, I'll try to add some.

Quoted 7 lines
Quoted 2 lines

+#if defined(CONFIG_INPUT_FF_EFFECTS_MODULE) || defined(CONFIG_INPUT_FF_EFFECTS)

No, we shouldn't use CONFIG_FOO_MODULE. We just don't know at compile-time whether the user will later compile and insert a particular module.

Right... so maybe we should just make ff-effects a bool instead of tristate or put it in the input module?

Quoted 10 lines

drivers/input/Kconfig

Quoted 6 lines
drivers/input/Kconfig +6 -0
+		mutex_lock(&dev->ff_lock);
+		del_timer_sync(&ff->timer);
+		dev->flush = NULL;
+		dev->ff = NULL;
+		kfree(ff);
+		mutex_unlock(&dev->ff_lock);

The kfree can be moved outside the lock.

Indeed.

BTW, what is the best way to send corrected patches for this patchset? Probably as a reply to the individual patches?

Signature · 1 line
Anssi Hannula
#6 lore raw

Re: [patch 03/11] input: new force feedback interface

Quoted 23 lines · Anssi Hannula
Quoted 21 lines · Andrew Morton
Quoted 16 lines · Anssi Hannula

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 module is named ff-effects. If INPUT_FF_EFFECTS is enabled, the force feedback drivers and interfaces (evdev) will be depending on it.

Userspace interface is left unaltered.

Quoted 6 lines
Quoted 2 lines

Nice-looking patches.

Thanks for looking and providing helpful comments :)

Andrew, did you get my response? I received Delivery Status Notification for your address:
<copy>
- These recipients of your message have been processed by the mail server:
[email protected]; Failed; 5.3.0 (other or undefined mail system status)

Remote MTA smtp.osdl.org: network error

- SMTP protocol diagnostic: 554 5.7.1 gmail.com suggested we reject
your email: 81.228.11.120 is neither permitted nor denied by domain of [email protected]
</paste>

Quoted 4 lines

BTW, what is the best way to send corrected patches for this patchset? Probably as a reply to the individual patches?

Hmm, I think it is easier to just send the whole updated set...

I'm going to do all the changes discussed and then send the set probably tomorrow or in the weekend.

Signature · 1 line
Anssi Hannula
#7 lore raw

Re: [patch 03/11] input: new force feedback interface

Quoted 3 lines · Anssi Hannula

Andrew, did you get my response?

Nope.

Quoted 6 lines

I received Delivery Status Notification
for your address:
<copy>
- These recipients of your message have been processed by the mail server:
[email protected]; Failed; 5.3.0 (other or undefined mail system status)

Quoted 8 lines

Remote MTA smtp.osdl.org: network error

- SMTP protocol diagnostic: 554 5.7.1 gmail.com suggested we reject
your email: 81.228.11.120 is neither permitted nor denied by domain of [email protected]
</paste>

Appropriate people have been informed ;)

Quoted 11 lines
Quoted 5 lines

BTW, what is the best way to send corrected patches for this patchset? Probably as a reply to the individual patches?

Hmm, I think it is easier to just send the whole updated set...

I'm going to do all the changes discussed and then send the set probably tomorrow or in the weekend.

Yes, that's fine. Once patches have matured a bit, incremental (and fine-grained) updates are preferred. And I'll often turn wholesale-replacement-attempts into incremental updates, so we can see what changed.

But at this stage, rip-it-out-and-redo is fine. Although it does help if you can tell us which of the review comments were and were not implemented, so we don't have to re-read the whole thing with the same level of attention.

#8 lore raw

Re: [patch 03/11] input: new force feedback interface

Quoted 17 lines · Andrew Morton
Quoted 9 lines · Anssi Hannula
Quoted 3 lines

BTW, what is the best way to send corrected patches for this patchset? Probably as a reply to the individual patches?

Hmm, I think it is easier to just send the whole updated set...

I'm going to do all the changes discussed and then send the set probably tomorrow or in the weekend.

Yes, that's fine. Once patches have matured a bit, incremental (and fine-grained) updates are preferred. And I'll often turn wholesale-replacement-attempts into incremental updates, so we can see what changed.

Quoted 4 lines

But at this stage, rip-it-out-and-redo is fine. Although it does help if you can tell us which of the review comments were and were not implemented, so we don't have to re-read the whole thing with the same level of attention.

Okay, I sent the whole set again.
I hope you have time to take a look :)

(didn't CC the patches for you because quilt sends them through my ISP with @gmail.com => smpt.osdl.org would've not accepted them)

Signature · 1 line
Anssi Hannula
#9 lore raw

Re: [patch 03/11] input: new force feedback interface

In reply to Andrew Morton

Here's this reply again with different From email address, so that Andrew Morton gets it too:

Quoted 13 lines · Andrew Morton
Quoted 11 lines · Anssi Hannula

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.

Quoted 9 lines
Quoted 5 lines

The module is named ff-effects. If INPUT_FF_EFFECTS is enabled, the force feedback drivers and interfaces (evdev) will be depending on it.

Userspace interface is left unaltered.

Nice-looking patches.

Thanks for looking and providing helpful comments :)

Quoted 6 lines
Quoted 6 lines
drivers/input/ff-effects.c new file +6 -0
+#define spin_ff_cond_lock(_ff, _flags)					  \
+	do {								  \
+		if (!_ff->driver->playback)				  \
+			spin_lock_irqsave(&_ff->atomiclock, _flags);	  \
+	} while (0);
+
Quoted 9 lines

drivers/input/ff-effects.c line 64

Quoted 5 lines
drivers/input/ff-effects.c new file +5 -0
+#define spin_ff_cond_unlock(_ff, _flags)					  \
+	do {								  \
+		if (!_ff->driver->playback)				  \
+			spin_unlock_irqrestore(&_ff->atomiclock, _flags); \
+	} while (0);

Making these static inline functions would deuglify them a bit.

I put them like that because spin_lock_irqsave is a macro that uses the local variable "flags".
But yes, I can probably pass that parameter to an inline function as a pointer. I'll change that.

Quoted 9 lines

drivers/input/ff-effects.c line 69

Quoted 4 lines
drivers/input/ff-effects.c new file +4 -0
+static int input_ff_effect_access(struct input_dev *dev, int id, int override)
+{
+	struct ff_device *ff = dev->ff;
+	if (id < dev->ff_effects_max && id >= 0 && test_bit(FF_EFFECT_USED, ff->effects[id].flags))

Kernel does have an 80-columns rule, but input seems to have always spurned it.

Quoted 10 lines

drivers/input/ff-effects.c line 84

Quoted 7 lines
drivers/input/ff-effects.c new file +7 -0
+static int input_ff_envelope_time(struct ff_effect_status *effect, struct ff_envelope *envelope, unsigned long *event_time)
+{
+	unsigned long fade_start;
+	if (!envelope)
+		return 0;
+
+	if (envelope->attack_length && time_after(effect->play_at + msecs_to_jiffies(envelope->attack_length), effect->adj_at)) {

Try using an 80-column wondow for a while ;)

Okay, I'll make the lines shorter.

Quoted 18 lines
Quoted 4 lines
drivers/input/ff-effects.c new file +2 -0
+		return value;
+	}

drivers/input/ff-effects.c line 205

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+
+	difference = abs(value) - envelope_level;
+
+	debug("difference = %d", difference);
+	debug("time_from_level = 0x%x", time_from_level);
+	debug("time_of_envelope = 0x%x", time_of_envelope);
+	if (difference < 0)
+		difference = -((-difference) * time_from_level / time_of_envelope);
+	else
+		difference = difference * time_from_level / time_of_envelope;

You've checked there's no possibility of divide-by-zero here?

Yes, the "time_of_envelope" is set a few lines above from "envelope->attack_length" or "envelope->fade_length", and there is an if block that checks they're non-zero.

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static int input_ff_safe_sum(int a, int b, int limit) {

The opening brace goes in column zero, please.

Quoted 13 lines

drivers/input/ff-effects.c line 237

Quoted 10 lines
drivers/input/ff-effects.c new file +10 -0
+	int c;
+	if (!a)
+		return b;
+	c = a + b;
+	if (c > limit)
+		return limit;
+	return c;
+}
+
+static s8 input_ff_s8_sum(int a, int b) {

dittoes.

Okay, will fix.

Quoted 10 lines
Quoted 10 lines
drivers/input/ff-effects.c new file +6 -0
+	int c;
+	c = input_ff_safe_sum(a, b, 0x7f);
+	if (c < -0x80)
+		return -0x80;
+	return c;
+}
 
...
Quoted 14 lines

drivers/input/ff-effects.c line 330

Quoted 9 lines
drivers/input/ff-effects.c new file +9 -0
+static void input_ff_timer(unsigned long timer_data)
+{
+	struct input_dev *dev = (struct input_dev *) timer_data;
+	struct ff_device *ff = dev->ff;
+	struct ff_effect effect;
+	int i;
+	unsigned long flags;
+	int effects_pending;
+	unsigned long effect_handled[NBITS(FF_EFFECTS_MAX)];

DECLARE_BITMAP would be more usual. (Yes, it should have been called DEFINE_BITMAP).

Ok.

Quoted 12 lines

drivers/input/ff-effects.c line 338

Quoted 8 lines
drivers/input/ff-effects.c new file +8 -0
+	int effect_type;
+	int safety;
+
+	debug("timer: updating effects");
+
+	spin_lock_irqsave(&ff->atomiclock, flags);
+
+	memset(effect_handled, 0, sizeof(effect_handled));

You could take the lock after the memset.

Ok.

Quoted 16 lines
Quoted 16 lines
drivers/input/ff-effects.c new file +16 -0
+int input_ff_erase(struct input_dev *dev, int id)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int ret;
+	if (!test_bit(EV_FF, dev->evbit))
+		return -EINVAL;
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
+	}
+	spin_ff_cond_lock(ff, flags);
+	ret = _input_ff_erase(dev, id, current->pid == 0);
+	spin_ff_cond_unlock(ff, flags);
Quoted 8 lines

drivers/input/ff-effects.c line 460

Quoted 4 lines
drivers/input/ff-effects.c new file +4 -0
+
+	mutex_unlock(&dev->ff_lock);
+	return ret;
+}

Perhaps you meant `current->uid == 0' here. There's no way in which pid 0 will call this code.

Right, a silly mistake.

Quoted 3 lines

What's happening here anyway? Why does this code need to know about pids?

Checking for uid==0 woud be a fishy thing to do as well.

User ID 0 is allowed to delete effects of other users. Pids are used to keep a track of what process owns what effects. This is the same behaviour as before.

There is a problem with this, though:
When a process closes any fd to this device, all pid-matching effects are deleted whether the process has another fd using the device or not.

One solution would probably be to add some handle parameter to input_ff_upload() and input_ff_erase(), and then in evdev_ioctl_handler() pass an id unique to this fd. Then effects would be fd-specific, not pid-specific. I think the uid == 0 thing can also be dropped... I don't think the root user needs ability to override user effects (it can delete them anyway, just kill the user process owning the effects).

WDYT?

Quoted 12 lines
Quoted 12 lines
drivers/input/ff-effects.c new file +11 -0
+static int input_ff_flush(struct input_dev *dev, struct file *file)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int i;
+	debug("flushing now");
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
Quoted 9 lines

drivers/input/ff-effects.c line 477

Quoted 5 lines
drivers/input/ff-effects.c new file +5 -0
+	}
+	spin_ff_cond_lock(ff, flags);
+	for (i = 0; i < dev->ff_effects_max; i++) {
+		_input_ff_erase(dev, i, 0);
+	}

Unneeded braces.

Will remove.

Quoted 40 lines
Quoted 40 lines
drivers/input/ff-effects.c new file +40 -0
+	spin_ff_cond_unlock(ff, flags);
+	mutex_unlock(&dev->ff_lock);
+	return 0;
+}
+
+
+		ff->effects[id].flags[0] = 0;
+		ff->effects[id].effect = *effect;
+
+		if (ff->driver->playback) {
+			if (!test_bit(effect->type, ff->flags))
+				input_ff_convert_effect(dev, effect);
+			ret = ff->driver->upload(dev, effect, NULL);
+			if (!ret)
+				set_bit(FF_EFFECT_USED, ff->effects[id].flags);
+			mutex_unlock(&dev->ff_lock);
+			return ret;
+		}
+		set_bit(FF_EFFECT_USED, ff->effects[id].flags);
+
+	} else {
+		id = effect->id;
+
+		ret = input_ff_effect_access(dev, id, 1);
+		if (ret) {
+			spin_ff_cond_unlock(ff, flags);
+			mutex_unlock(&dev->ff_lock);
+			return ret;
+		}
+
+		if (effect->type != ff->effects[id].effect.type ||
+				  (effect->type == FF_PERIODIC && effect->u.periodic.waveform !=
+				  ff->effects[id].effect.u.periodic.waveform)) {
+			spin_ff_cond_unlock(ff, flags);
+			mutex_unlock(&dev->ff_lock);
+			return -EINVAL;
+		}
+
+		if (ff->driver->playback) {
+			if (!test_bit(effect->type, ff->flags))
Quoted 8 lines

drivers/input/ff-effects.c line 645

Quoted 5 lines
drivers/input/ff-effects.c new file +5 -0
+				input_ff_convert_effect(dev, effect);
+			ret = ff->driver->upload(dev, effect, &ff->effects[id].effect);
+			ff->effects[id].effect = *effect;
+			mutex_unlock(&dev->ff_lock);
+			return ret;

I think we're missing a spin_ff_cond_unlock() here?

Well, spin_ff_cond_unlock() checks for ff->driver->playback and it is already tested in the if block above.

Quoted 14 lines

drivers/input/ff-effects.c line 655

Quoted 11 lines
drivers/input/ff-effects.c new file +10 -0
+		}
+		ff->effects[id].effect = *effect;
+		clear_bit(FF_EFFECT_PLAYING, ff->effects[id].flags);
+
+	}
+
+	spin_unlock_irqrestore(&ff->atomiclock, flags);
+	mutex_unlock(&dev->ff_lock);
+	return ret;
+}

And here we have spin_unlock_irqrestore() instead of spin_ff_cond_unlock().

If there is no need to unlock, one of the above "if (ff->driver->playback)" would be true and the function would've already returned before this point.

Quoted 3 lines

It would be best to convert this function to have a single return point. That tends to prevent problems like this from happening, and from creeping in later on.

I agree that the locking is too confusing in input_ff_event() and input_ff_upload(), even if it is correct.

I'll modify the function to have a single return point, or maybe split the function for the two different locking paths, which then call common functions without the need to cond_lock. I guess that could be done for all cond_locking functions.

Quoted 12 lines
Quoted 12 lines
drivers/input/ff-effects.c new file +11 -0
+int input_ff_allocate(struct input_dev *dev)
+{
+	debug("allocating device");
+	mutex_lock(&dev->ff_lock);
+	if (dev->ff)
+		printk(KERN_ERR "ff-effects: allocating to non-NULL pointer\n");
+	dev->ff = kzalloc(sizeof(*dev->ff), GFP_KERNEL);
+	if (!dev->ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENOMEM;
+	}
Quoted 9 lines

drivers/input/ff-effects.c line 672

Quoted 5 lines
drivers/input/ff-effects.c new file +5 -0
+	spin_lock_init(&dev->ff->atomiclock);
+	init_timer(&dev->ff->timer);
+	dev->ff->timer.function = input_ff_timer;
+	dev->ff->timer.data = (unsigned long) dev;
+	dev->ff->event = input_ff_event;

setup_timer()

Will change.

Quoted 16 lines
Quoted 16 lines
drivers/input/ff-effects.c new file +5 -0
+	mutex_unlock(&dev->ff_lock);
+	debug("ff allocated");
+	return 0;
+}
+
 
...

Index: linux-2.6.17-rc4-git1/drivers/input/Kconfig
===================================================================

drivers/input/Kconfig +0 -0
@@ -24,6 +24,14 @@ config INPUT
 

if INPUT

Quoted 11 lines

drivers/input/Kconfig config INPUT · line 33

Quoted 7 lines
drivers/input/Kconfig +7 -0
+config INPUT_FF_EFFECTS
+	tristate "Force feedback effects"
+	help
+	  Say Y here if you want to be able to play force feedback effects.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ff-effects.

hm. I'd have expected more dependencies than this.

Only INPUT.

Quoted 5 lines
Quoted 5 lines

comment "Userland interfaces"

config INPUT_MOUSEDEV

drivers/input/Kconfig +0 -0
@@ -110,6 +118,7 @@ config INPUT_TSDEV_SCREEN_Y
 
Quoted 7 lines

drivers/input/Kconfig config INPUT_TSDEV_SCREEN_Y · line 121

Quoted 3 lines

config INPUT_EVDEV
tristate "Event interface"

drivers/input/Kconfig +1 -0
+	depends on INPUT_FF_EFFECTS || INPUT_FF_EFFECTS=n

Isn't that always true?

This disallows building evdev as builtin and ff-effects as module.

Quoted 10 lines

drivers/input/Kconfig

Quoted 3 lines
drivers/input/Kconfig +3 -0
+
+struct ff_effect_status {
+	pid_t owner;

This code is almost devoid of comments. Those which it does have tend to cover little low-level implementation details. But it's the *big* things which a reader is not able to learn from the implementation, and which should be commented. Like: why on earth does this code need to know about pids?

Okay, I'll try to add some.

Quoted 7 lines
Quoted 2 lines

+#if defined(CONFIG_INPUT_FF_EFFECTS_MODULE) || defined(CONFIG_INPUT_FF_EFFECTS)

No, we shouldn't use CONFIG_FOO_MODULE. We just don't know at compile-time whether the user will later compile and insert a particular module.

Right... so maybe we should just make ff-effects a bool instead of tristate or put it in the input module?

Quoted 10 lines

drivers/input/Kconfig

Quoted 6 lines
drivers/input/Kconfig +6 -0
+		mutex_lock(&dev->ff_lock);
+		del_timer_sync(&ff->timer);
+		dev->flush = NULL;
+		dev->ff = NULL;
+		kfree(ff);
+		mutex_unlock(&dev->ff_lock);

The kfree can be moved outside the lock.

Indeed.

BTW, what is the best way to send corrected patches for this patchset? Probably as a reply to the individual patches?

Signature · 1 line
Anssi Hannula
#10 lore raw

Re: [patch 03/11] input: new force feedback interface

Quoted 28 lines · Anssi Hannula
Quoted 17 lines
Quoted 17 lines
drivers/input/ff-effects.c new file +16 -0
+int input_ff_erase(struct input_dev *dev, int id)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int ret;
+	if (!test_bit(EV_FF, dev->evbit))
+		return -EINVAL;
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
+	}
+	spin_ff_cond_lock(ff, flags);
+	ret = _input_ff_erase(dev, id, current->pid == 0);
+	spin_ff_cond_unlock(ff, flags);
Quoted 8 lines

drivers/input/ff-effects.c line 460

Quoted 4 lines
drivers/input/ff-effects.c new file +4 -0
+
+	mutex_unlock(&dev->ff_lock);
+	return ret;
+}

Perhaps you meant `current->uid == 0' here. There's no way in which pid 0 will call this code.

Right, a silly mistake.

Quoted 7 lines
Quoted 3 lines

What's happening here anyway? Why does this code need to know about pids?

Checking for uid==0 woud be a fishy thing to do as well.

User ID 0 is allowed to delete effects of other users. Pids are used to keep a track of what process owns what effects. This is the same behaviour as before.

Oh dear.

Whatever we do here should remain 100%-compatible with "before". Which rather limits our options.

Quoted 4 lines

There is a problem with this, though:
When a process closes any fd to this device, all pid-matching effects are deleted whether the process has another fd using the device or not.

Quoted 8 lines

One solution would probably be to add some handle parameter to input_ff_upload() and input_ff_erase(), and then in evdev_ioctl_handler() pass an id unique to this fd. Then effects would be fd-specific, not pid-specific. I think the uid == 0 thing can also be dropped... I don't think the root user needs ability to override user effects (it can delete them anyway, just kill the user process owning the effects).

Generally we use file descriptors (and driver-specific state at file.f_private) to manage things like that. But I'd imagine that we couldn't retain the existing semantics with any such scheme.

A pragmatic approach would be to put a big fat comment in there explaining how it all works and leave it at that.

#11 lore raw

Re: [patch 03/11] input: new force feedback interface

Quoted 38 lines · Andrew Morton
Quoted 27 lines · Anssi Hannula
Quoted 16 lines
Quoted 16 lines
drivers/input/ff-effects.c new file +16 -0
+int input_ff_erase(struct input_dev *dev, int id)
+{
+	struct ff_device *ff;
+	unsigned long flags = 0;
+	int ret;
+	if (!test_bit(EV_FF, dev->evbit))
+		return -EINVAL;
+	mutex_lock(&dev->ff_lock);
+	ff = dev->ff;
+	if (!ff) {
+		mutex_unlock(&dev->ff_lock);
+		return -ENODEV;
+	}
+	spin_ff_cond_lock(ff, flags);
+	ret = _input_ff_erase(dev, id, current->pid == 0);
+	spin_ff_cond_unlock(ff, flags);
Quoted 8 lines

drivers/input/ff-effects.c line 460

Quoted 4 lines
drivers/input/ff-effects.c new file +4 -0
+
+	mutex_unlock(&dev->ff_lock);
+	return ret;
+}

Perhaps you meant `current->uid == 0' here. There's no way in which pid 0 will call this code.

Right, a silly mistake.

Quoted 7 lines
Quoted 3 lines

What's happening here anyway? Why does this code need to know about pids?

Checking for uid==0 woud be a fishy thing to do as well.

User ID 0 is allowed to delete effects of other users. Pids are used to keep a track of what process owns what effects. This is the same behaviour as before.

Quoted 4 lines

Oh dear.

Whatever we do here should remain 100%-compatible with "before". Which rather limits our options.

There are only _very_ few programs using FF on Linux ATM, and I don't think any of them opens multiple fd:s to the same device and expects to be able to delete effects created on the other fd. And that is the only con of changing the behaviour.

Should the behaviour be changed so that the effect owners are file descriptors, the effects of one fd would not be lost if the process opens and closes another fd on the same device (currently all effects of a process are deleted if the process closes any fd to the device).

Quoted 14 lines
Quoted 4 lines

There is a problem with this, though:
When a process closes any fd to this device, all pid-matching effects are deleted whether the process has another fd using the device or not.

Quoted 8 lines

One solution would probably be to add some handle parameter to input_ff_upload() and input_ff_erase(), and then in evdev_ioctl_handler() pass an id unique to this fd. Then effects would be fd-specific, not pid-specific. I think the uid == 0 thing can also be dropped... I don't think the root user needs ability to override user effects (it can delete them anyway, just kill the user process owning the effects).

Quoted 6 lines

Generally we use file descriptors (and driver-specific state at file.f_private) to manage things like that. But I'd imagine that we couldn't retain the existing semantics with any such scheme.

A pragmatic approach would be to put a big fat comment in there explaining how it all works and leave it at that.

As I don't see this could break any existing applications, I would very much like to change the behaviour so that the effects are file descriptor specific. What should I use to differentiate the descriptors? Can I just compare the "struct file*"? (it seems to work well, I just modified the code so)

Signature · 1 line
Anssi Hannula
#12 lore raw

Re: [patch 03/11] input: new force feedback interface

Quoted 11 lines · Anssi Hannula
Quoted 7 lines

Generally we use file descriptors (and driver-specific state at file.f_private) to manage things like that. But I'd imagine that we couldn't retain the existing semantics with any such scheme.

A pragmatic approach would be to put a big fat comment in there explaining how it all works and leave it at that.

As I don't see this could break any existing applications, I would very much like to change the behaviour so that the effects are file descriptor specific.

ooh, that's always risky - we just don't know what people are doing out there. They do the damnedest things.

Is it possible to implement the new behaviour while retaining the old behaviour as well? And to detect when an app is using the old behaviour and to drop a printk("stop doing this")? So we can kill the old behaviour in a year or so?

Quoted 3 lines

What should I use to differentiate the descriptors?
Can I just compare the "struct file*"? (it seems to work well, I just modified the code so)

Depends what you're trying to do. Different threads in the same process can share the same file*'s.

#13 lore raw

Re: [patch 03/11] input: new force feedback interface

Quoted 15 lines · Andrew Morton
Quoted 11 lines · Anssi Hannula
Quoted 7 lines

Generally we use file descriptors (and driver-specific state at

file.f_private) to manage things like that. But I'd imagine that we couldn't retain the existing semantics with any such scheme.

A pragmatic approach would be to put a big fat comment in there explaining how it all works and leave it at that.

As I don't see this could break any existing applications, I would very much like to change the behaviour so that the effects are file descriptor specific.

Quoted 7 lines

ooh, that's always risky - we just don't know what people are doing out there. They do the damnedest things.

Is it possible to implement the new behaviour while retaining the old behaviour as well? And to detect when an app is using the old behaviour and to drop a printk("stop doing this")? So we can kill the old behaviour in a year or so?

I *really* don't think any app is trying to do one of the following:
- open another fd to the same device and delete effect created in the first fd
- open and close another fd to the same device to delete all effects

The latter one doesn't make any sense (the process could just open and close the first fd), but the former one is possible, though very unlikely.

I count only 6 programs using linux ff, of which 3 are test programs. None of those messes up with fd's so that they would depend on the old behaviour. I would change the behaviour, while we still can.

What we could do is allow deleting effects, whether they're owned by the fd or not. If they aren't, printk() would be issued.

Quoted 7 lines
Quoted 4 lines

What should I use to differentiate the descriptors?
Can I just compare the "struct file*"? (it seems to work well, I just modified the code so)

Depends what you're trying to do. Different threads in the same process can share the same file*'s.

I try to have a coherent 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

I will once again give an example how things would go with the 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

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

Signature · 1 line
Anssi Hannula
#14 lore raw

PATCH 4/11 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  |  457 ++++--------------------------------------
 drivers/usb/input/hid-tmff.c  |  353 ++------------------------------
 drivers/usb/input/hid.h       |    9 
 5 files changed, 81 insertions(+), 743 deletions(-)
drivers/usb/input/hid.h +0 -9
Index: linux-2.6.17-rc4-git1/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-git1/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 -407

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-git1/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

#15 lore raw

PATCH 5/11 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 |   74 +++++++++++++++++++++++++++++++++++---------
 include/linux/uinput.h      |   17 ++++++----
 2 files changed, 71 insertions(+), 20 deletions(-)
drivers/input/misc/uinput.c +60 -14
Index: linux-2.6.16-git20/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,10 @@ static long uinput_ioctl(struct file *fi
 			break;
 
 		case UI_SET_EVBIT:
-			retval = uinput_set_bit(arg, evbit, EV_MAX);
+			if (arg == EV_FF)
+				retval = -EINVAL;
+			else
+				retval = uinput_set_bit(arg, evbit, EV_MAX);
 			break;
 
 		case UI_SET_KEYBIT:
@@ -487,7 +525,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 +566,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 +607,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 +667,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 +11 -6
Index: linux-2.6.16-git20/include/linux/uinput.h
===================================================================
@@ -22,6 +22,8 @@
  * Author: Aristeu Sergio Rozanski Filho <[email protected]>
  * 
  * Changes/Revisions:
+ *	0.3	09/04/2006 (Anssi Hannula <anssi.hannulagmail.com>)
+ *		- update ff support for the changes in kernel interface
  *	0.2	16/10/2004 (Micah Dowty <[email protected]>)
  *		- added force feedback support
  *             - added UI_SET_PHYS
@@ -45,7 +47,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 +74,7 @@ struct uinput_ff_upload {
 	int			request_id;
 	int			retval;
 	struct ff_effect	effect;
+	struct ff_effect	old;
 };
 
 struct uinput_ff_erase {
@@ -105,7 +111,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 +122,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 +139,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

#16 lore raw

PATCH 6/11 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/Kconfig       |    2 
 drivers/input/joystick/iforce/iforce-ff.c   |   61 +++------
 drivers/input/joystick/iforce/iforce-main.c |  188 ++++++++--------------------
 drivers/input/joystick/iforce/iforce.h      |   15 --
 4 files changed, 87 insertions(+), 179 deletions(-)
drivers/input/joystick/iforce/iforce-ff.c +23 -38
Index: linux-2.6.17-rc4-git1/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-git1/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

drivers/input/joystick/iforce/Kconfig +1 -1
Index: linux-2.6.17-rc4-git1/drivers/input/joystick/iforce/Kconfig
===================================================================
@@ -3,7 +3,7 @@
 #
 config JOYSTICK_IFORCE
 	tristate "I-Force devices"
-	depends on INPUT && INPUT_JOYSTICK
+	depends on INPUT && INPUT_JOYSTICK && (INPUT_FF_EFFECTS || INPUT_FF_EFFECTS=n)
 	help
 	  Say Y here if you have an I-Force joystick or steering wheel
 

--
Anssi Hannula

#17 lore raw

PATCH 7/11 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 | 1105 ++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/input/hid.h       |    6 
 6 files changed, 1121 insertions(+), 31 deletions(-)
drivers/usb/input/hid-ff.c +7 -7
Index: linux-2.6.17-rc3-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-rc3-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-rc3-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 +1105 -0

1,105 lines not on this page · raw message

drivers/usb/input/Kconfig +2 -2
Index: linux-2.6.17-rc3-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-rc3-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

#18 lore raw

PATCH 8/11 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 |  128 +++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/input/hid.h      |    1 
 5 files changed, 143 insertions(+)
drivers/usb/input/hid-ff.c +4 -0
Index: linux-2.6.16-rc1-git11/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 +128 -0

128 lines not on this page · raw message

drivers/usb/input/Kconfig +7 -0
Index: linux-2.6.16-rc1-git11/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.16-rc1-git11/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.16-rc1-git11/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

#19 lore raw

PATCH 9/11 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 |   93 +++++++++++++++++++--------------------------
 include/linux/input.h      |   12 +++++
 2 files changed, 51 insertions(+), 54 deletions(-)
Documentation/input/ff.txt +40 -53
Index: linux-2.6.16-rc1-git11/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);
@@ -128,8 +108,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 +143,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 +183,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.16-rc1-git11/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

#20 lore raw

PATCH 10/11 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

#21 lore raw

PATCH 11/11 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

#22 lore raw
In reply to Anssi Hannula
Quoted 3 lines · --- Anssi Hannula

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

Hi Anssi,

Thank you for the patches. I should finish settling down and setting up my connection by the end of this week and then I should be able to review the patches.

--
Dmitry