Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (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
  ...
This commit is contained in:
Linus Torvalds
2006-10-02 08:20:33 -07:00
57 changed files with 4525 additions and 2194 deletions

View File

@@ -60,16 +60,17 @@ 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
feedback for it. The Microsoft Sidewinder Force Feedback 2 is one such
device.
Say Y here if you have a PID-compliant device and wish to enable force
feedback for it. Microsoft Sidewinder Force Feedback 2 is one of such
devices.
config LOGITECH_FF
bool "Logitech WingMan *3D support"
depends on HID_FF
select INPUT_FF_MEMLESS if USB_HID
help
Say Y here if you have one of these devices:
- Logitech WingMan Cordless RumblePad
@@ -81,12 +82,21 @@ config LOGITECH_FF
config THRUSTMASTER_FF
bool "ThrustMaster FireStorm Dual Power 2 support (EXPERIMENTAL)"
depends on HID_FF && EXPERIMENTAL
select INPUT_FF_MEMLESS if USB_HID
help
Say Y here if you have a THRUSTMASTER FireStore Dual Power 2,
and want to enable force feedback support for it.
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
select INPUT_FF_MEMLESS if USB_HID
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

View File

@@ -15,7 +15,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
@@ -23,6 +23,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

View File

@@ -1,87 +0,0 @@
#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 <deneux@ifrance.com>
*/
#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[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, 0x0000
};
/* 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 = 90 - 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

View File

@@ -543,8 +543,6 @@ static void hid_free_device(struct hid_device *device)
{
unsigned i,j;
hid_ff_exit(device);
for (i = 0; i < HID_REPORT_TYPES; i++) {
struct hid_report_enum *report_enum = device->report_enum + i;
@@ -1109,7 +1107,7 @@ int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
/*
* Find a report field with a specified HID usage.
*/
#if 0
struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_usage, int type)
{
struct hid_report *report;
@@ -1121,6 +1119,7 @@ struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_u
return report->field[i];
return NULL;
}
#endif /* 0 */
static int hid_submit_out(struct hid_device *hid)
{

View File

@@ -44,45 +44,38 @@ struct hid_ff_initializer {
int (*init)(struct hid_device*);
};
/*
* 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
*/
static struct hid_ff_initializer inits[] = {
#ifdef CONFIG_LOGITECH_FF
{0x46d, 0xc211, hid_lgff_init}, // Logitech Cordless rumble pad
{0x46d, 0xc283, hid_lgff_init}, // Logitech Wingman Force 3d
{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},
{ 0x46d, 0xc211, hid_lgff_init }, /* Logitech Cordless rumble pad */
{ 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */
{ 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */
{ 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */
#endif
#ifdef CONFIG_THRUSTMASTER_FF
{0x44f, 0xb304, hid_tmff_init},
{ 0x44f, 0xb304, hid_tmff_init },
#endif
{0, 0, NULL} /* Terminating entry */
#ifdef CONFIG_ZEROPLUS_FF
{ 0xc12, 0x0005, hid_zpff_init },
{ 0xc12, 0x0030, hid_zpff_init },
#endif
{ 0, 0, hid_pidff_init} /* Matches anything */
};
static struct hid_ff_initializer *hid_get_ff_init(__u16 idVendor,
__u16 idProduct)
{
struct hid_ff_initializer *init;
for (init = inits;
init->idVendor
&& !(init->idVendor == idVendor
&& init->idProduct == idProduct);
init++);
return init->idVendor? init : NULL;
}
int hid_ff_init(struct hid_device* hid)
{
struct hid_ff_initializer *init;
int vendor = le16_to_cpu(hid->dev->descriptor.idVendor);
int product = le16_to_cpu(hid->dev->descriptor.idProduct);
init = hid_get_ff_init(le16_to_cpu(hid->dev->descriptor.idVendor),
le16_to_cpu(hid->dev->descriptor.idProduct));
for (init = inits; init->idVendor; init++)
if (init->idVendor == vendor && init->idProduct == product)
break;
if (!init) {
dbg("hid_ff_init could not find initializer");
return -ENOSYS;
}
return init->init(hid);
}

View File

@@ -65,11 +65,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
@@ -525,23 +523,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
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;
}
@@ -698,8 +680,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
}
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;
}
@@ -748,7 +729,7 @@ static int hidinput_input_event(struct input_dev *dev, unsigned int type, unsign
int offset;
if (type == EV_FF)
return hid_ff_event(hid, dev, type, code, value);
return input_ff_event(dev, type, code, value);
if (type != EV_LED)
return -1;

View File

@@ -1,12 +1,11 @@
/*
* $$
*
* Force feedback support for hid-compliant for some of the devices from
* Logitech, namely:
* - WingMan Cordless RumblePad
* - WingMan Force 3D
*
* Copyright (c) 2002-2004 Johann Deneux
* Copyright (c) 2006 Anssi Hannula <anssi.hannula@gmail.com>
*/
/*
@@ -29,495 +28,117 @@
*/
#include <linux/input.h>
#include <linux/sched.h>
//#define DEBUG
#include <linux/usb.h>
#include <linux/circ_buf.h>
#include "hid.h"
#include "fixp-arith.h"
/* Periodicity of the update */
#define PERIOD (HZ/10)
#define RUN_AT(t) (jiffies + (t))
/* Effect status */
#define EFFECT_STARTED 0 /* Effect is going to play after some time
(ff_replay.delay) */
#define EFFECT_PLAYING 1 /* Effect is being played */
#define EFFECT_USED 2
// For lgff_device::flags
#define DEVICE_CLOSING 0 /* The driver is being unitialised */
/* Check that the current process can access an effect */
#define CHECK_OWNERSHIP(effect) (current->pid == 0 \
|| effect.owner == current->pid)
#define LGFF_CHECK_OWNERSHIP(i, l) \
(i>=0 && i<LGFF_EFFECTS \
&& test_bit(EFFECT_USED, l->effects[i].flags) \
&& CHECK_OWNERSHIP(l->effects[i]))
#define LGFF_EFFECTS 8
struct device_type {
u16 idVendor;
u16 idProduct;
signed short *ff;
const signed short *ff;
};
struct lgff_effect {
pid_t owner;
struct ff_effect effect;
unsigned long flags[1];
unsigned int count; /* Number of times left to play */
unsigned long started_at; /* When the effect started to play */
};
struct lgff_device {
struct hid_device* hid;
struct hid_report* constant;
struct hid_report* rumble;
struct hid_report* condition;
struct lgff_effect effects[LGFF_EFFECTS];
spinlock_t lock; /* device-level lock. Having locks on
a per-effect basis could be nice, but
isn't really necessary */
unsigned long flags[1]; /* Contains various information about the
state of the driver for this device */
struct timer_list timer;
};
/* Callbacks */
static void hid_lgff_exit(struct hid_device* hid);
static int hid_lgff_event(struct hid_device *hid, struct input_dev *input,
unsigned int type, unsigned int code, int value);
static int hid_lgff_flush(struct input_dev *input, struct file *file);
static int hid_lgff_upload_effect(struct input_dev *input,
struct ff_effect *effect);
static int hid_lgff_erase(struct input_dev *input, int id);
/* Local functions */
static void hid_lgff_input_init(struct hid_device* hid);
static void hid_lgff_timer(unsigned long timer_data);
static struct hid_report* hid_lgff_duplicate_report(struct hid_report*);
static void hid_lgff_delete_report(struct hid_report*);
static signed short ff_rumble[] = {
static const signed short ff_rumble[] = {
FF_RUMBLE,
-1
};
static signed short ff_joystick[] = {
static const signed short ff_joystick[] = {
FF_CONSTANT,
-1
};
static struct device_type devices[] = {
{0x046d, 0xc211, ff_rumble},
{0x046d, 0xc219, ff_rumble},
{0x046d, 0xc283, ff_joystick},
{0x0000, 0x0000, ff_joystick}
static const struct device_type devices[] = {
{ 0x046d, 0xc211, ff_rumble },
{ 0x046d, 0xc219, ff_rumble },
{ 0x046d, 0xc283, ff_joystick },
{ 0x0000, 0x0000, ff_joystick }
};
static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
{
struct hid_device *hid = dev->private;
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
int x, y;
unsigned int left, right;
#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff
switch (effect->type) {
case FF_CONSTANT:
x = effect->u.ramp.start_level + 0x7f; /* 0x7f is center */
y = effect->u.ramp.end_level + 0x7f;
CLAMP(x);
CLAMP(y);
report->field[0]->value[0] = 0x51;
report->field[0]->value[1] = 0x08;
report->field[0]->value[2] = x;
report->field[0]->value[3] = y;
dbg("(x, y)=(%04x, %04x)", x, y);
hid_submit_report(hid, report, USB_DIR_OUT);
break;
case FF_RUMBLE:
right = effect->u.rumble.strong_magnitude;
left = effect->u.rumble.weak_magnitude;
right = right * 0xff / 0xffff;
left = left * 0xff / 0xffff;
CLAMP(left);
CLAMP(right);
report->field[0]->value[0] = 0x42;
report->field[0]->value[1] = 0x00;
report->field[0]->value[2] = left;
report->field[0]->value[3] = right;
dbg("(left, right)=(%04x, %04x)", left, right);
hid_submit_report(hid, report, USB_DIR_OUT);
break;
}
return 0;
}
int hid_lgff_init(struct hid_device* hid)
{
struct lgff_device *private;
struct hid_report* report;
struct hid_field* field;
struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct input_dev *dev = hidinput->input;
struct hid_report *report;
struct hid_field *field;
int error;
int i, j;
/* Find the report to use */
if (list_empty(&hid->report_enum[HID_OUTPUT_REPORT].report_list)) {
if (list_empty(report_list)) {
err("No output report found");
return -1;
}
/* Check that the report looks ok */
report = (struct hid_report*)hid->report_enum[HID_OUTPUT_REPORT].report_list.next;
report = list_entry(report_list->next, struct hid_report, list);
if (!report) {
err("NULL output report");
return -1;
}
field = report->field[0];
if (!field) {
err("NULL field");
return -1;
}
private = kzalloc(sizeof(struct lgff_device), GFP_KERNEL);
if (!private)
return -1;
hid->ff_private = private;
/* Input init */
hid_lgff_input_init(hid);
private->constant = hid_lgff_duplicate_report(report);
if (!private->constant) {
kfree(private);
return -1;
}
private->constant->field[0]->value[0] = 0x51;
private->constant->field[0]->value[1] = 0x08;
private->constant->field[0]->value[2] = 0x7f;
private->constant->field[0]->value[3] = 0x7f;
private->rumble = hid_lgff_duplicate_report(report);
if (!private->rumble) {
hid_lgff_delete_report(private->constant);
kfree(private);
return -1;
}
private->rumble->field[0]->value[0] = 0x42;
private->condition = hid_lgff_duplicate_report(report);
if (!private->condition) {
hid_lgff_delete_report(private->rumble);
hid_lgff_delete_report(private->constant);
kfree(private);
return -1;
for (i = 0; i < ARRAY_SIZE(devices); i++) {
if (dev->id.vendor == devices[i].idVendor &&
dev->id.product == devices[i].idProduct) {
for (j = 0; devices[i].ff[j] >= 0; j++)
set_bit(devices[i].ff[j], dev->ffbit);
break;
}
}
private->hid = hid;
spin_lock_init(&private->lock);
init_timer(&private->timer);
private->timer.data = (unsigned long)private;
private->timer.function = hid_lgff_timer;
/* Event and exit callbacks */
hid->ff_exit = hid_lgff_exit;
hid->ff_event = hid_lgff_event;
/* Start the update task */
private->timer.expires = RUN_AT(PERIOD);
add_timer(&private->timer); /*TODO: only run the timer when at least
one effect is playing */
error = input_ff_create_memless(dev, NULL, hid_lgff_play);
if (error)
return error;
printk(KERN_INFO "Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n");
return 0;
}
static struct hid_report* hid_lgff_duplicate_report(struct hid_report* report)
{
struct hid_report* ret;
ret = kmalloc(sizeof(struct lgff_device), GFP_KERNEL);
if (!ret)
return NULL;
*ret = *report;
ret->field[0] = kmalloc(sizeof(struct hid_field), GFP_KERNEL);
if (!ret->field[0]) {
kfree(ret);
return NULL;
}
*ret->field[0] = *report->field[0];
ret->field[0]->value = kzalloc(sizeof(s32[8]), GFP_KERNEL);
if (!ret->field[0]->value) {
kfree(ret->field[0]);
kfree(ret);
return NULL;
}
return ret;
}
static void hid_lgff_delete_report(struct hid_report* report)
{
if (report) {
kfree(report->field[0]->value);
kfree(report->field[0]);
kfree(report);
}
}
static void hid_lgff_input_init(struct hid_device* hid)
{
struct device_type* dev = devices;
signed short* ff;
u16 idVendor = le16_to_cpu(hid->dev->descriptor.idVendor);
u16 idProduct = le16_to_cpu(hid->dev->descriptor.idProduct);
struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
struct input_dev *input_dev = hidinput->input;
while (dev->idVendor && (idVendor != dev->idVendor || idProduct != dev->idProduct))
dev++;
for (ff = dev->ff; *ff >= 0; ff++)
set_bit(*ff, input_dev->ffbit);
input_dev->upload_effect = hid_lgff_upload_effect;
input_dev->flush = hid_lgff_flush;
set_bit(EV_FF, input_dev->evbit);
input_dev->ff_effects_max = LGFF_EFFECTS;
}
static void hid_lgff_exit(struct hid_device* hid)
{
struct lgff_device *lgff = hid->ff_private;
set_bit(DEVICE_CLOSING, lgff->flags);
del_timer_sync(&lgff->timer);
hid_lgff_delete_report(lgff->condition);
hid_lgff_delete_report(lgff->rumble);
hid_lgff_delete_report(lgff->constant);
kfree(lgff);
}
static int hid_lgff_event(struct hid_device *hid, struct input_dev* input,
unsigned int type, unsigned int code, int value)
{
struct lgff_device *lgff = hid->ff_private;
struct lgff_effect *effect = lgff->effects + code;
unsigned long flags;
if (type != EV_FF) return -EINVAL;
if (!LGFF_CHECK_OWNERSHIP(code, lgff)) return -EACCES;
if (value < 0) return -EINVAL;
spin_lock_irqsave(&lgff->lock, flags);
if (value > 0) {
if (test_bit(EFFECT_STARTED, effect->flags)) {
spin_unlock_irqrestore(&lgff->lock, flags);
return -EBUSY;
}
if (test_bit(EFFECT_PLAYING, effect->flags)) {
spin_unlock_irqrestore(&lgff->lock, flags);
return -EBUSY;
}
effect->count = value;
if (effect->effect.replay.delay) {
set_bit(EFFECT_STARTED, effect->flags);
} else {
set_bit(EFFECT_PLAYING, effect->flags);
}
effect->started_at = jiffies;
}
else { /* value == 0 */
clear_bit(EFFECT_STARTED, effect->flags);
clear_bit(EFFECT_PLAYING, effect->flags);
}
spin_unlock_irqrestore(&lgff->lock, flags);
return 0;
}
/* Erase all effects this process owns */
static int hid_lgff_flush(struct input_dev *dev, struct file *file)
{
struct hid_device *hid = dev->private;
struct lgff_device *lgff = hid->ff_private;
int i;
for (i=0; i<dev->ff_effects_max; ++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 */
if ( current->pid == lgff->effects[i].owner
&& test_bit(EFFECT_USED, lgff->effects[i].flags)) {
if (hid_lgff_erase(dev, i))
warn("erase effect %d failed", i);
}
}
return 0;
}
static int hid_lgff_erase(struct input_dev *dev, int id)
{
struct hid_device *hid = dev->private;
struct lgff_device *lgff = hid->ff_private;
unsigned long flags;
if (!LGFF_CHECK_OWNERSHIP(id, lgff)) return -EACCES;
spin_lock_irqsave(&lgff->lock, flags);
lgff->effects[id].flags[0] = 0;
spin_unlock_irqrestore(&lgff->lock, flags);
return 0;
}
static int hid_lgff_upload_effect(struct input_dev* input,
struct ff_effect* effect)
{
struct hid_device *hid = input->private;
struct lgff_device *lgff = hid->ff_private;
struct lgff_effect new;
int id;
unsigned long flags;
dbg("ioctl rumble");
if (!test_bit(effect->type, input->ffbit)) return -EINVAL;
spin_lock_irqsave(&lgff->lock, flags);
if (effect->id == -1) {
int i;
for (i=0; i<LGFF_EFFECTS && test_bit(EFFECT_USED, lgff->effects[i].flags); ++i);
if (i >= LGFF_EFFECTS) {
spin_unlock_irqrestore(&lgff->lock, flags);
return -ENOSPC;
}
effect->id = i;
lgff->effects[i].owner = current->pid;
lgff->effects[i].flags[0] = 0;
set_bit(EFFECT_USED, lgff->effects[i].flags);
}
else if (!LGFF_CHECK_OWNERSHIP(effect->id, lgff)) {
spin_unlock_irqrestore(&lgff->lock, flags);
return -EACCES;
}
id = effect->id;
new = lgff->effects[id];
new.effect = *effect;
if (test_bit(EFFECT_STARTED, lgff->effects[id].flags)
|| test_bit(EFFECT_STARTED, lgff->effects[id].flags)) {
/* Changing replay parameters is not allowed (for the time
being) */
if (new.effect.replay.delay != lgff->effects[id].effect.replay.delay
|| new.effect.replay.length != lgff->effects[id].effect.replay.length) {
spin_unlock_irqrestore(&lgff->lock, flags);
return -ENOSYS;
}
lgff->effects[id] = new;
} else {
lgff->effects[id] = new;
}
spin_unlock_irqrestore(&lgff->lock, flags);
return 0;
}
static void hid_lgff_timer(unsigned long timer_data)
{
struct lgff_device *lgff = (struct lgff_device*)timer_data;
struct hid_device *hid = lgff->hid;
unsigned long flags;
int x = 0x7f, y = 0x7f; // Coordinates of constant effects
unsigned int left = 0, right = 0; // Rumbling
int i;
spin_lock_irqsave(&lgff->lock, flags);
for (i=0; i<LGFF_EFFECTS; ++i) {
struct lgff_effect* effect = lgff->effects +i;
if (test_bit(EFFECT_PLAYING, effect->flags)) {
switch (effect->effect.type) {
case FF_CONSTANT: {
//TODO: handle envelopes
int degrees = effect->effect.direction * 360 >> 16;
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));
} break;
case FF_RUMBLE:
right += effect->effect.u.rumble.strong_magnitude;
left += effect->effect.u.rumble.weak_magnitude;
break;
};
/* One run of the effect is finished playing */
if (time_after(jiffies,
effect->started_at
+ effect->effect.replay.delay*HZ/1000
+ effect->effect.replay.length*HZ/1000)) {
dbg("Finished playing once %d", i);
if (--effect->count <= 0) {
dbg("Stopped %d", i);
clear_bit(EFFECT_PLAYING, effect->flags);
}
else {
dbg("Start again %d", i);
if (effect->effect.replay.length != 0) {
clear_bit(EFFECT_PLAYING, effect->flags);
set_bit(EFFECT_STARTED, effect->flags);
}
effect->started_at = jiffies;
}
}
} else if (test_bit(EFFECT_STARTED, lgff->effects[i].flags)) {
/* Check if we should start playing the effect */
if (time_after(jiffies,
lgff->effects[i].started_at
+ lgff->effects[i].effect.replay.delay*HZ/1000)) {
dbg("Now playing %d", i);
clear_bit(EFFECT_STARTED, lgff->effects[i].flags);
set_bit(EFFECT_PLAYING, lgff->effects[i].flags);
}
}
}
#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff
// Clamp values
CLAMP(x);
CLAMP(y);
CLAMP(left);
CLAMP(right);
#undef CLAMP
if (x != lgff->constant->field[0]->value[2]
|| y != lgff->constant->field[0]->value[3]) {
lgff->constant->field[0]->value[2] = x;
lgff->constant->field[0]->value[3] = y;
dbg("(x,y)=(%04x, %04x)", x, y);
hid_submit_report(hid, lgff->constant, USB_DIR_OUT);
}
if (left != lgff->rumble->field[0]->value[2]
|| right != lgff->rumble->field[0]->value[3]) {
lgff->rumble->field[0]->value[2] = left;
lgff->rumble->field[0]->value[3] = right;
dbg("(left,right)=(%04x, %04x)", left, right);
hid_submit_report(hid, lgff->rumble, USB_DIR_OUT);
}
if (!test_bit(DEVICE_CLOSING, lgff->flags)) {
lgff->timer.expires = RUN_AT(PERIOD);
add_timer(&lgff->timer);
}
spin_unlock_irqrestore(&lgff->lock, flags);
}

File diff suppressed because it is too large Load Diff

View File

@@ -28,97 +28,65 @@
*/
#include <linux/input.h>
#include <linux/sched.h>
#undef DEBUG
#include <linux/usb.h>
#include <linux/circ_buf.h>
#include "hid.h"
#include "fixp-arith.h"
/* Usages for thrustmaster devices I know about */
#define THRUSTMASTER_USAGE_RUMBLE_LR (HID_UP_GENDESK | 0xbb)
#define DELAY_CALC(t,delay) ((t) + (delay)*HZ/1000)
/* Effect status */
#define EFFECT_STARTED 0 /* Effect is going to play after some time */
#define EFFECT_PLAYING 1 /* Effect is playing */
#define EFFECT_USED 2
/* For tmff_device::flags */
#define DEVICE_CLOSING 0 /* The driver is being unitialised */
/* Check that the current process can access an effect */
#define CHECK_OWNERSHIP(effect) (current->pid == 0 \
|| effect.owner == current->pid)
#define TMFF_CHECK_ID(id) ((id) >= 0 && (id) < TMFF_EFFECTS)
#define TMFF_CHECK_OWNERSHIP(i, l) \
(test_bit(EFFECT_USED, l->effects[i].flags) \
&& CHECK_OWNERSHIP(l->effects[i]))
#define TMFF_EFFECTS 8
struct tmff_effect {
pid_t owner;
struct ff_effect effect;
unsigned long flags[1];
unsigned int count; /* Number of times left to play */
unsigned long play_at; /* When the effect starts to play */
unsigned long stop_at; /* When the effect ends */
};
struct tmff_device {
struct hid_device *hid;
struct hid_report *report;
struct hid_field *rumble;
unsigned int effects_playing;
struct tmff_effect effects[TMFF_EFFECTS];
spinlock_t lock; /* device-level lock. Having locks on
a per-effect basis could be nice, but
isn't really necessary */
unsigned long flags[1]; /* Contains various information about the
state of the driver for this device */
struct timer_list timer;
};
/* Callbacks */
static void hid_tmff_exit(struct hid_device *hid);
static int hid_tmff_event(struct hid_device *hid, struct input_dev *input,
unsigned int type, unsigned int code, int value);
static int hid_tmff_flush(struct input_dev *input, struct file *file);
static int hid_tmff_upload_effect(struct input_dev *input,
struct ff_effect *effect);
static int hid_tmff_erase(struct input_dev *input, int id);
/* Changes values from 0 to 0xffff into values from minimum to maximum */
static inline int hid_tmff_scale(unsigned int in, int minimum, int maximum)
{
int ret;
/* Local functions */
static void hid_tmff_recalculate_timer(struct tmff_device *tmff);
static void hid_tmff_timer(unsigned long timer_data);
ret = (in * (maximum - minimum) / 0xffff) + minimum;
if (ret < minimum)
return minimum;
if (ret > maximum)
return maximum;
return ret;
}
static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
{
struct hid_device *hid = dev->private;
struct tmff_device *tmff = data;
int left, right; /* Rumbling */
left = hid_tmff_scale(effect->u.rumble.weak_magnitude,
tmff->rumble->logical_minimum, tmff->rumble->logical_maximum);
right = hid_tmff_scale(effect->u.rumble.strong_magnitude,
tmff->rumble->logical_minimum, tmff->rumble->logical_maximum);
tmff->rumble->value[0] = left;
tmff->rumble->value[1] = right;
dbg("(left,right)=(%08x, %08x)", left, right);
hid_submit_report(hid, tmff->report, USB_DIR_OUT);
return 0;
}
int hid_tmff_init(struct hid_device *hid)
{
struct tmff_device *private;
struct tmff_device *tmff;
struct list_head *pos;
struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
struct input_dev *input_dev = hidinput->input;
int error;
private = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
if (!private)
tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
if (!tmff)
return -ENOMEM;
hid->ff_private = private;
/* Find the report to use */
__list_for_each(pos, &hid->report_enum[HID_OUTPUT_REPORT].report_list) {
struct hid_report *report = (struct hid_report *)pos;
@@ -142,18 +110,18 @@ int hid_tmff_init(struct hid_device *hid)
continue;
}
if (private->report && private->report != report) {
if (tmff->report && tmff->report != report) {
warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR in other report");
continue;
}
if (private->rumble && private->rumble != field) {
if (tmff->rumble && tmff->rumble != field) {
warn("ignoring duplicate THRUSTMASTER_USAGE_RUMBLE_LR");
continue;
}
private->report = report;
private->rumble = field;
tmff->report = report;
tmff->rumble = field;
set_bit(FF_RUMBLE, input_dev->ffbit);
break;
@@ -162,302 +130,17 @@ int hid_tmff_init(struct hid_device *hid)
warn("ignoring unknown output usage %08x", field->usage[0].hid);
continue;
}
/* Fallthrough to here only when a valid usage is found */
input_dev->upload_effect = hid_tmff_upload_effect;
input_dev->flush = hid_tmff_flush;
set_bit(EV_FF, input_dev->evbit);
input_dev->ff_effects_max = TMFF_EFFECTS;
}
}
private->hid = hid;
spin_lock_init(&private->lock);
init_timer(&private->timer);
private->timer.data = (unsigned long)private;
private->timer.function = hid_tmff_timer;
/* Event and exit callbacks */
hid->ff_exit = hid_tmff_exit;
hid->ff_event = hid_tmff_event;
error = input_ff_create_memless(input_dev, tmff, hid_tmff_play);
if (error) {
kfree(tmff);
return error;
}
info("Force feedback for ThrustMaster rumble pad devices by Zinx Verituse <zinx@epicsol.org>");
return 0;
}
static void hid_tmff_exit(struct hid_device *hid)
{
struct tmff_device *tmff = hid->ff_private;
unsigned long flags;
spin_lock_irqsave(&tmff->lock, flags);
set_bit(DEVICE_CLOSING, tmff->flags);
del_timer_sync(&tmff->timer);
spin_unlock_irqrestore(&tmff->lock, flags);
kfree(tmff);
}
static int hid_tmff_event(struct hid_device *hid, struct input_dev *input,
unsigned int type, unsigned int code, int value)
{
struct tmff_device *tmff = hid->ff_private;
struct tmff_effect *effect = &tmff->effects[code];
unsigned long flags;
if (type != EV_FF)
return -EINVAL;
if (!TMFF_CHECK_ID(code))
return -EINVAL;
if (!TMFF_CHECK_OWNERSHIP(code, tmff))
return -EACCES;
if (value < 0)
return -EINVAL;
spin_lock_irqsave(&tmff->lock, flags);
if (value > 0) {
set_bit(EFFECT_STARTED, effect->flags);
clear_bit(EFFECT_PLAYING, effect->flags);
effect->count = value;
effect->play_at = DELAY_CALC(jiffies, effect->effect.replay.delay);
} else {
clear_bit(EFFECT_STARTED, effect->flags);
clear_bit(EFFECT_PLAYING, effect->flags);
}
hid_tmff_recalculate_timer(tmff);
spin_unlock_irqrestore(&tmff->lock, flags);
return 0;
}
/* Erase all effects this process owns */
static int hid_tmff_flush(struct input_dev *dev, struct file *file)
{
struct hid_device *hid = dev->private;
struct tmff_device *tmff = hid->ff_private;
int i;
for (i=0; i<dev->ff_effects_max; ++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 */
if (current->pid == tmff->effects[i].owner
&& test_bit(EFFECT_USED, tmff->effects[i].flags))
if (hid_tmff_erase(dev, i))
warn("erase effect %d failed", i);
return 0;
}
static int hid_tmff_erase(struct input_dev *dev, int id)
{
struct hid_device *hid = dev->private;
struct tmff_device *tmff = hid->ff_private;
unsigned long flags;
if (!TMFF_CHECK_ID(id))
return -EINVAL;
if (!TMFF_CHECK_OWNERSHIP(id, tmff))
return -EACCES;
spin_lock_irqsave(&tmff->lock, flags);
tmff->effects[id].flags[0] = 0;
hid_tmff_recalculate_timer(tmff);
spin_unlock_irqrestore(&tmff->lock, flags);
return 0;
}
static int hid_tmff_upload_effect(struct input_dev *input,
struct ff_effect *effect)
{
struct hid_device *hid = input->private;
struct tmff_device *tmff = hid->ff_private;
int id;
unsigned long flags;
if (!test_bit(effect->type, input->ffbit))
return -EINVAL;
if (effect->id != -1 && !TMFF_CHECK_ID(effect->id))
return -EINVAL;
spin_lock_irqsave(&tmff->lock, flags);
if (effect->id == -1) {
/* Find a free effect */
for (id = 0; id < TMFF_EFFECTS && test_bit(EFFECT_USED, tmff->effects[id].flags); ++id);
if (id >= TMFF_EFFECTS) {
spin_unlock_irqrestore(&tmff->lock, flags);
return -ENOSPC;
}
effect->id = id;
tmff->effects[id].owner = current->pid;
tmff->effects[id].flags[0] = 0;
set_bit(EFFECT_USED, tmff->effects[id].flags);
} else {
/* Re-uploading an owned effect, to change parameters */
id = effect->id;
clear_bit(EFFECT_PLAYING, tmff->effects[id].flags);
}
tmff->effects[id].effect = *effect;
hid_tmff_recalculate_timer(tmff);
spin_unlock_irqrestore(&tmff->lock, flags);
return 0;
}
/* Start the timer for the next start/stop/delay */
/* Always call this while tmff->lock is locked */
static void hid_tmff_recalculate_timer(struct tmff_device *tmff)
{
int i;
int events = 0;
unsigned long next_time;
next_time = 0; /* Shut up compiler's incorrect warning */
/* Find the next change in an effect's status */
for (i = 0; i < TMFF_EFFECTS; ++i) {
struct tmff_effect *effect = &tmff->effects[i];
unsigned long play_time;
if (!test_bit(EFFECT_STARTED, effect->flags))
continue;
effect->stop_at = DELAY_CALC(effect->play_at, effect->effect.replay.length);
if (!test_bit(EFFECT_PLAYING, effect->flags))
play_time = effect->play_at;
else
play_time = effect->stop_at;
events++;
if (time_after(jiffies, play_time))
play_time = jiffies;
if (events == 1)
next_time = play_time;
else {
if (time_after(next_time, play_time))
next_time = play_time;
}
}
if (!events && tmff->effects_playing) {
/* Treat all effects turning off as an event */
events = 1;
next_time = jiffies;
}
if (!events) {
/* No events, no time, no need for a timer. */
del_timer_sync(&tmff->timer);
return;
}
mod_timer(&tmff->timer, next_time);
}
/* Changes values from 0 to 0xffff into values from minimum to maximum */
static inline int hid_tmff_scale(unsigned int in, int minimum, int maximum)
{
int ret;
ret = (in * (maximum - minimum) / 0xffff) + minimum;
if (ret < minimum)
return minimum;
if (ret > maximum)
return maximum;
return ret;
}
static void hid_tmff_timer(unsigned long timer_data)
{
struct tmff_device *tmff = (struct tmff_device *) timer_data;
struct hid_device *hid = tmff->hid;
unsigned long flags;
int left = 0, right = 0; /* Rumbling */
int i;
spin_lock_irqsave(&tmff->lock, flags);
tmff->effects_playing = 0;
for (i = 0; i < TMFF_EFFECTS; ++i) {
struct tmff_effect *effect = &tmff->effects[i];
if (!test_bit(EFFECT_STARTED, effect->flags))
continue;
if (!time_after(jiffies, effect->play_at))
continue;
if (time_after(jiffies, effect->stop_at)) {
dbg("Finished playing once %d", i);
clear_bit(EFFECT_PLAYING, effect->flags);
if (--effect->count <= 0) {
dbg("Stopped %d", i);
clear_bit(EFFECT_STARTED, effect->flags);
continue;
} else {
dbg("Start again %d", i);
effect->play_at = DELAY_CALC(jiffies, effect->effect.replay.delay);
continue;
}
}
++tmff->effects_playing;
set_bit(EFFECT_PLAYING, effect->flags);
switch (effect->effect.type) {
case FF_RUMBLE:
right += effect->effect.u.rumble.strong_magnitude;
left += effect->effect.u.rumble.weak_magnitude;
break;
default:
BUG();
break;
}
}
left = hid_tmff_scale(left, tmff->rumble->logical_minimum, tmff->rumble->logical_maximum);
right = hid_tmff_scale(right, tmff->rumble->logical_minimum, tmff->rumble->logical_maximum);
if (left != tmff->rumble->value[0] || right != tmff->rumble->value[1]) {
tmff->rumble->value[0] = left;
tmff->rumble->value[1] = right;
dbg("(left,right)=(%08x, %08x)", left, right);
hid_submit_report(hid, tmff->report, USB_DIR_OUT);
}
if (!test_bit(DEVICE_CLOSING, tmff->flags))
hid_tmff_recalculate_timer(tmff);
spin_unlock_irqrestore(&tmff->lock, flags);
}

View File

@@ -0,0 +1,110 @@
/*
* Force feedback support for Zeroplus based devices
*
* Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.com>
*/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* #define DEBUG */
#define debug(format, arg...) pr_debug("hid-zpff: " format "\n" , ## arg)
#include <linux/input.h>
#include <linux/usb.h>
#include "hid.h"
struct zpff_device {
struct hid_report *report;
};
static int hid_zpff_play(struct input_dev *dev, void *data,
struct ff_effect *effect)
{
struct hid_device *hid = dev->private;
struct zpff_device *zpff = data;
int left, right;
/*
* The following is specified the other way around in the Zeroplus
* datasheet but the order below is correct for the XFX Executioner;
* however it is possible that the XFX Executioner is an exception
*/
left = effect->u.rumble.strong_magnitude;
right = effect->u.rumble.weak_magnitude;
debug("called with 0x%04x 0x%04x", left, right);
left = left * 0x7f / 0xffff;
right = right * 0x7f / 0xffff;
zpff->report->field[2]->value[0] = left;
zpff->report->field[3]->value[0] = right;
debug("running with 0x%02x 0x%02x", left, right);
hid_submit_report(hid, zpff->report, USB_DIR_OUT);
return 0;
}
int hid_zpff_init(struct hid_device *hid)
{
struct zpff_device *zpff;
struct hid_report *report;
struct hid_input *hidinput = list_entry(hid->inputs.next,
struct hid_input, list);
struct list_head *report_list =
&hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct input_dev *dev = hidinput->input;
int error;
if (list_empty(report_list)) {
printk(KERN_ERR "hid-zpff: no output report found\n");
return -ENODEV;
}
report = list_entry(report_list->next, struct hid_report, list);
if (report->maxfield < 4) {
printk(KERN_ERR "hid-zpff: not enough fields in report\n");
return -ENODEV;
}
zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL);
if (!zpff)
return -ENOMEM;
set_bit(FF_RUMBLE, dev->ffbit);
error = input_ff_create_memless(dev, zpff, hid_zpff_play);
if (error) {
kfree(zpff);
return error;
}
zpff->report = report;
zpff->report->field[0]->value[0] = 0x00;
zpff->report->field[1]->value[0] = 0x02;
zpff->report->field[2]->value[0] = 0x00;
zpff->report->field[3]->value[0] = 0x00;
hid_submit_report(hid, zpff->report, USB_DIR_OUT);
printk(KERN_INFO "Force feedback for Zeroplus based devices by "
"Anssi Hannula <anssi.hannula@gmail.com>\n");
return 0;
}

View File

@@ -449,11 +449,6 @@ struct hid_device { /* device report descriptor */
char phys[64]; /* Device physical location */
char uniq[64]; /* Device unique identifier (serial #) */
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)];
unsigned long pb_pressed_numlock[NBITS(KEY_MAX)];
@@ -521,29 +516,22 @@ void hid_close(struct hid_device *);
int hid_set_field(struct hid_field *, unsigned, __s32);
void hid_submit_report(struct hid_device *, struct hid_report *, unsigned char dir);
void hid_init_reports(struct hid_device *hid);
struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_usage, int type);
int hid_wait_io(struct hid_device* hid);
#ifdef CONFIG_HID_FF
int hid_ff_init(struct hid_device *hid);
int hid_lgff_init(struct hid_device *hid);
int hid_tmff_init(struct hid_device *hid);
int hid_zpff_init(struct hid_device *hid);
#ifdef CONFIG_HID_PID
int hid_pidff_init(struct hid_device *hid);
#else
static inline int hid_pidff_init(struct hid_device *hid) { return -ENODEV; }
#endif
#else
static inline int hid_ff_init(struct hid_device *hid) { return -1; }
#endif
static inline void hid_ff_exit(struct hid_device *hid)
{
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);
int hid_pid_init(struct hid_device* hid);

View File

@@ -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 <rdamazio@lsi.usp.br>
*/
#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 <rdamazio@lsi.usp.br>.\n");
return 0;
}

View File

@@ -1,62 +0,0 @@
/*
* PID Force feedback support for hid devices.
*
* Copyright (c) 2002 Rodrigo Damazio.
*/
/*
* 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 <rdamazio@lsi.usp.br>
*/
#define FF_EFFECTS_MAX 64
#define FF_PID_FLAGS_USED 1 /* If the effect exists */
#define FF_PID_FLAGS_UPDATING 2 /* If the effect is being updated */
#define FF_PID_FLAGS_PLAYING 3 /* If the effect is currently being played */
#define FF_PID_FALSE 0
#define FF_PID_TRUE 1
struct hid_pid_effect {
unsigned long flags;
pid_t owner;
unsigned int device_id; /* The device-assigned ID */
struct ff_effect effect;
};
struct hid_ff_pid {
struct hid_device *hid;
unsigned long gain;
struct urb *urbffout;
struct usb_ctrlrequest ffcr;
spinlock_t lock;
unsigned char ctrl_buffer[8];
struct hid_pid_effect effects[FF_EFFECTS_MAX];
};
/*
* Constants from the PID usage table (still far from complete)
*/
#define FF_PID_USAGE_BLOCK_LOAD 0x89UL
#define FF_PID_USAGE_BLOCK_FREE 0x90UL
#define FF_PID_USAGE_NEW_EFFECT 0xABUL
#define FF_PID_USAGE_POOL_REPORT 0x7FUL