Commit a12f66fc authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge branch 'for-linus' of git://

* 'for-linus' of git:// (35 commits)
  Input: wistron - add support for Acer TravelMate 2424NWXCi
  Input: wistron - fix setting up special buttons
  Input: add KEY_BLUETOOTH and KEY_WLAN definitions
  Input: add new BUS_VIRTUAL bus type
  Input: add driver for stowaway serial keyboards
  Input: make input_register_handler() return error codes
  Input: remove cruft that was needed for transition to sysfs
  Input: fix input module refcounting
  Input: constify input core
  Input: libps2 - rearrange exports
  Input: atkbd - support Microsoft Natural Elite Pro keyboards
  Input: i8042 - disable MUX mode on Toshiba Equium A110
  Input: i8042 - get rid of polling timer
  Input: send key up events at disconnect
  Input: constify psmouse driver
  Input: i8042 - add Amoi to the MUX blacklist
  Input: logips2pp - add sugnature 56 (Cordless MouseMan Wheel), cleanup
  Input: add driver for Touchwin serial touchscreens
  Input: add driver for Touchright serial touchscreens
  Input: add driver for Penmount serial touchscreens
parents 12dce626 bb088590
Force feedback for Linux.
By Johann Deneux <> on 2001/04/22.
Updated by Anssi Hannula <> 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
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
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 a driver that supports your
2. make sure evdev module is loaded and /dev/input/event* device files are
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".
To stop this annoying behaviour, move you joystick to its limits. Anyway, you
should keep a hand on your device, in order to avoid it to brake down if
should keep a hand on your device, in order to avoid it to break 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 ?
......@@ -70,9 +40,9 @@ There is an utility called fftest that will allow you to test the driver.
3. Instructions to the developper
All interactions are done using the event API. That is, you can use ioctl()
All interactions are done using the event API. That is, you can use ioctl()
and write() on /dev/input/eventXX.
This information is subject to change.
This information is subject to change.
3.1 Querying device capabilities
......@@ -86,18 +56,29 @@ int ioctl(int file_descriptor, int request, unsigned long *features);
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_FRICTION can simulate friction
- FF_DAMPER can simulate damper effects
- FF_RUMBLE rumble effects (normally the only effect supported by rumble
- 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);
......@@ -108,7 +89,7 @@ Returns the number of effects the device can keep in its memory.
#include <linux/input.h>
#include <sys/ioctl.h>
int ioctl(int file_descriptor, int request, struct ff_effect *effect);
"request" must be EVIOCSFF.
......@@ -120,6 +101,9 @@ to the unique id assigned by the driver. This data is required for performing
some operations (removing an effect, controlling the playback).
This if field must be set to -1 by the user in order to tell the driver to
allocate a new effect.
Effects are file descriptor specific.
See <linux/input.h> for a description of the ff_effect struct. You should also
find help in a few sketches, contained in files shape.fig and interactive.fig.
You need xfig to visualize these files.
......@@ -128,8 +112,8 @@ You need xfig to visualize these files.
int ioctl(int fd, EVIOCRMFF,;
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
......@@ -149,22 +133,21 @@ Control of playing is done with write(). Below is an example:
play.type = EV_FF;
play.code =;
play.value = 3;
write(fd, (const void*) &play, sizeof(play));
/* Stop an effect */
stop.type = EV_FF;
stop.code =;
stop.value = 0;
write(fd, (const void*) &play, sizeof(stop));
3.5 Setting the gain
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,11 +187,14 @@ type of device, not all parameters can be dynamically updated. For example,
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
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 {
/* When the status of the effect changed */
struct timeval time;
......@@ -225,3 +211,9 @@ struct input_event {
FF_STATUS_STOPPED The effect stopped playing
FF_STATUS_PLAYING The effect started to play
NOTE: Status feedback is only supported by iforce driver. If you have
a really good reason to use this, please contact or
so that support for it can be added to the rest of the drivers.
......@@ -1293,7 +1293,7 @@ static void kbd_event(struct input_handle *handle, unsigned int event_type,
static struct input_handle *kbd_connect(struct input_handler *handler,
struct input_dev *dev,
struct input_device_id *id)
const struct input_device_id *id)
struct input_handle *handle;
int i;
......@@ -1342,7 +1342,7 @@ static void kbd_start(struct input_handle *handle)
static struct input_device_id kbd_ids[] = {
static const struct input_device_id kbd_ids[] = {
.evbit = { BIT(EV_KEY) },
......@@ -1370,6 +1370,7 @@ static struct input_handler kbd_handler = {
int __init kbd_init(void)
int i;
int error;
for (i = 0; i < MAX_NR_CONSOLES; i++) {
kbd_table[i].ledflagstate = KBD_DEFLEDS;
......@@ -1381,7 +1382,9 @@ int __init kbd_init(void)
kbd_table[i].kbdmode = VC_XLATE;
error = input_register_handler(&kbd_handler);
if (error)
return error;
......@@ -24,6 +24,20 @@ config INPUT
tristate "Support for memoryless force-feedback devices"
default n
Say Y here if you have memoryless force-feedback input device
such as Logitech WingMan Force 3D, ThrustMaster FireStorm Dual
Power 2, or similar. You will also need to enable hardware-specific
If unsure, say N.
To compile this driver as a module, choose M here: the
module will be called ff-memless.
comment "Userland interfaces"
......@@ -4,7 +4,11 @@
# Each configuration option enables a list of files.
obj-$(CONFIG_INPUT) += input.o
obj-$(CONFIG_INPUT) += input-core.o
input-core-objs := input.o ff-core.o
obj-$(CONFIG_INPUT_FF_MEMLESS) += ff-memless.o
obj-$(CONFIG_INPUT_MOUSEDEV) += mousedev.o
obj-$(CONFIG_INPUT_JOYDEV) += joydev.o
obj-$(CONFIG_INPUT_EVDEV) += evdev.o
......@@ -42,10 +42,12 @@ static char evbug_name[] = "evbug";
static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
printk(KERN_DEBUG "evbug.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n", handle->dev->phys, type, code, value);
printk(KERN_DEBUG "evbug.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n",
handle->dev->phys, type, code, value);
static struct input_handle *evbug_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
static struct input_handle *evbug_connect(struct input_handler *handler, struct input_dev *dev,
const struct input_device_id *id)
struct input_handle *handle;
......@@ -72,7 +74,7 @@ static void evbug_disconnect(struct input_handle *handle)
static struct input_device_id evbug_ids[] = {
static const struct input_device_id evbug_ids[] = {
{ .driver_info = 1 }, /* Matches all devices */
{ }, /* Terminating zero entry */
......@@ -89,8 +91,7 @@ static struct input_handler evbug_handler = {
static int __init evbug_init(void)
return 0;
return input_register_handler(&evbug_handler);
static void __exit evbug_exit(void)
......@@ -391,8 +391,10 @@ static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
struct evdev *evdev = list->evdev;
struct input_dev *dev = evdev->;
struct input_absinfo abs;
struct ff_effect effect;
int __user *ip = (int __user *)p;
int i, t, u, v;
int error;
if (!evdev->exist)
return -ENODEV;
......@@ -460,27 +462,22 @@ static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
return 0;
if (dev->upload_effect) {
struct ff_effect effect;
int err;
if (copy_from_user(&effect, p, sizeof(effect)))
return -EFAULT;
err = dev->upload_effect(dev, &effect);
if (put_user(, &(((struct ff_effect __user *)p)->id)))
return -EFAULT;
return err;
} else
return -ENOSYS;
if (copy_from_user(&effect, p, sizeof(effect)))
return -EFAULT;
if (!dev->erase_effect)
return -ENOSYS;
error = input_ff_upload(dev, &effect, file);
return dev->erase_effect(dev, (int)(unsigned long) p);
if (put_user(, &(((struct ff_effect __user *)p)->id)))
return -EFAULT;
return error;
return input_ff_erase(dev, (int)(unsigned long) p, file);
if (put_user(dev->ff_effects_max, ip))
i = test_bit(EV_FF, dev->evbit) ? dev->ff->max_effects : 0;
if (put_user(i, ip))
return -EFAULT;
return 0;
......@@ -604,7 +601,7 @@ static long evdev_ioctl_compat(struct file *file, unsigned int cmd, unsigned lon
static struct file_operations evdev_fops = {
static const struct file_operations evdev_fops = {
.owner = THIS_MODULE,
.read = evdev_read,
.write = evdev_write,
......@@ -619,7 +616,8 @@ static struct file_operations evdev_fops = {
.flush = evdev_flush
static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev,
const struct input_device_id *id)
struct evdev *evdev;
struct class_device *cdev;
......@@ -669,6 +667,7 @@ static void evdev_disconnect(struct input_handle *handle)
evdev->exist = 0;
if (evdev->open) {
input_flush_device(handle, NULL);
list_for_each_entry(list, &evdev->list, node)
......@@ -677,7 +676,7 @@ static void evdev_disconnect(struct input_handle *handle)
static struct input_device_id evdev_ids[] = {
static const struct input_device_id evdev_ids[] = {
{ .driver_info = 1 }, /* Matches all devices */
{ }, /* Terminating zero entry */
......@@ -696,8 +695,7 @@ static struct input_handler evdev_handler = {
static int __init evdev_init(void)
return 0;
return input_register_handler(&evdev_handler);
static void __exit evdev_exit(void)
* Force feedback support for Linux input subsystem
* Copyright (c) 2006 Anssi Hannula <>
* Copyright (c) 2006 Dmitry Torokhov <>
* 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
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/* #define DEBUG */
#define debug(format, arg...) pr_debug("ff-core: " format "\n", ## arg)
#include <linux/input.h>
#include <linux/module.h>
#include <linux/mutex.h>
* Check that the effect_id is a valid effect and whether the user
* is the owner
static int check_effect_access(struct ff_device *ff, int effect_id,
struct file *file)
if (effect_id < 0 || effect_id >= ff->max_effects ||
return -EINVAL;
if (file && ff->effect_owners[effect_id] != file)
return -EACCES;
return 0;
* Checks whether 2 effects can be combined together
static inline int check_effects_compatible(struct ff_effect *e1,
struct ff_effect *e2)
return e1->type == e2->type &&
(e1->type != FF_PERIODIC ||
e1->u.periodic.waveform == e2->u.periodic.waveform);
* Convert an effect into compatible one
static int compat_effect(struct ff_device *ff, struct ff_effect *effect)
int magnitude;
switch (effect->type) {
if (!test_bit(FF_PERIODIC, ff->ffbit))
return -EINVAL;
* calculate manginude of sine wave as average of rumble's
* 2/3 of strong magnitude and 1/3 of weak magnitude
magnitude = effect->u.rumble.strong_magnitude / 3 +
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 = max(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 0;
/* Let driver handle conversion */
return 0;
* input_ff_upload() - upload effect into force-feedback device
* @dev: input device
* @effect: effect to be uploaded
* @file: owner of the effect
int input_ff_upload(struct input_dev *dev, struct ff_effect *effect,
struct file *file)
struct ff_device *ff = dev->ff;
struct ff_effect *old;
int ret = 0;
int id;
if (!test_bit(EV_FF, dev->evbit))
return -ENOSYS;
if (effect->type < FF_EFFECT_MIN || effect->type > FF_EFFECT_MAX ||
!test_bit(effect->type, dev->ffbit)) {
debug("invalid or not supported effect type in upload");
return -EINVAL;
if (effect->type == FF_PERIODIC &&
(effect->u.periodic.waveform < FF_WAVEFORM_MIN ||
effect->u.periodic.waveform > FF_WAVEFORM_MAX ||
!test_bit(effect->u.periodic.waveform, dev->ffbit))) {
debug("invalid or not supported wave form in upload");
return -EINVAL;
if (!test_bit(effect->type, ff->ffbit)) {
ret = compat_effect(ff, effect);
if (ret)
return ret;
if (effect->id == -1) {
for (id = 0; id < ff->max_effects; id++)
if (!ff->effect_owners[id])
if (id >= ff->max_effects) {
ret = -ENOSPC;
goto out;
effect->id = id;
old = NULL;
} else {
id = effect->id;
ret = check_effect_access(ff, id, file);
if (ret)
goto out;
old = &ff->effects[id];
if (!check_effects_compatible(effect, old)) {
ret = -EINVAL;
goto out;
ret = ff->upload(dev, effect, old);
if (ret)
goto out;
ff->effects[id] = *effect;
ff->effect_owners[id] = file;
return ret;
* Erases the effect if the requester is also the effect owner. The mutex
* should already be locked before calling this function.
static int erase_effect(struct input_dev *dev, int effect_id,
struct file *file)
struct ff_device *ff = dev->ff;
int error;
error = check_effect_access(ff, effect_id, file);
if (error)
return error;
ff->playback(dev, effect_id, 0);
if (ff->erase) {
error = ff->erase(dev, effect_id);
if (error)
return error;
ff->effect_owners[effect_id] = NULL;
return 0;
* input_ff_erase - erase an effect from device
* @dev: input device to erase effect from
* @effect_id: id of the ffect to be erased
* @file: purported owner of the request
* This function erases a force-feedback effect from specified device.
* The effect will only be erased if it was uploaded through the same
* file handle that is requesting erase.
int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file)
struct ff_device *ff = dev->ff;
int ret;
if (!test_bit(EV_FF, dev->evbit))
return -ENOSYS;
ret = erase_effect(dev, effect_id, file);