2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
|
2007-04-11 23:30:24 -06:00
|
|
|
* Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
|
|
|
* USB/RS232 I-Force joysticks and wheels.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 either by
|
|
|
|
* e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
|
|
|
|
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "iforce.h"
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
__s32 x;
|
|
|
|
__s32 y;
|
|
|
|
} iforce_hat_to_axis[16] = {{ 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}};
|
|
|
|
|
|
|
|
|
|
|
|
void iforce_dump_packet(char *msg, u16 cmd, unsigned char *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2007-04-11 23:30:24 -06:00
|
|
|
printk(KERN_DEBUG __FILE__ ": %s cmd = %04x, data = ", msg, cmd);
|
2005-04-16 16:20:36 -06:00
|
|
|
for (i = 0; i < LO(cmd); i++)
|
|
|
|
printk("%02x ", data[i]);
|
2007-04-11 23:30:24 -06:00
|
|
|
printk("\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a packet of bytes to the device
|
|
|
|
*/
|
|
|
|
int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data)
|
|
|
|
{
|
|
|
|
/* Copy data to buffer */
|
|
|
|
int n = LO(cmd);
|
|
|
|
int c;
|
|
|
|
int empty;
|
|
|
|
int head, tail;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update head and tail of xmit buffer
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(&iforce->xmit_lock, flags);
|
|
|
|
|
|
|
|
head = iforce->xmit.head;
|
|
|
|
tail = iforce->xmit.tail;
|
|
|
|
|
2007-04-11 23:30:24 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (CIRC_SPACE(head, tail, XMIT_SIZE) < n+2) {
|
2008-08-14 10:37:34 -06:00
|
|
|
dev_warn(&iforce->dev->dev,
|
|
|
|
"not enough space in xmit buffer to send new packet\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
spin_unlock_irqrestore(&iforce->xmit_lock, flags);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
empty = head == tail;
|
|
|
|
XMIT_INC(iforce->xmit.head, n+2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store packet in xmit buffer
|
|
|
|
*/
|
|
|
|
iforce->xmit.buf[head] = HI(cmd);
|
|
|
|
XMIT_INC(head, 1);
|
|
|
|
iforce->xmit.buf[head] = LO(cmd);
|
|
|
|
XMIT_INC(head, 1);
|
|
|
|
|
|
|
|
c = CIRC_SPACE_TO_END(head, tail, XMIT_SIZE);
|
|
|
|
if (n < c) c=n;
|
|
|
|
|
|
|
|
memcpy(&iforce->xmit.buf[head],
|
|
|
|
data,
|
|
|
|
c);
|
|
|
|
if (n != c) {
|
|
|
|
memcpy(&iforce->xmit.buf[0],
|
|
|
|
data + c,
|
|
|
|
n - c);
|
|
|
|
}
|
|
|
|
XMIT_INC(head, n);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&iforce->xmit_lock, flags);
|
|
|
|
/*
|
|
|
|
* If necessary, start the transmission
|
|
|
|
*/
|
|
|
|
switch (iforce->bus) {
|
|
|
|
|
|
|
|
#ifdef CONFIG_JOYSTICK_IFORCE_232
|
|
|
|
case IFORCE_232:
|
|
|
|
if (empty)
|
|
|
|
iforce_serial_xmit(iforce);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_JOYSTICK_IFORCE_USB
|
|
|
|
case IFORCE_USB:
|
|
|
|
|
|
|
|
if (iforce->usbdev && empty &&
|
|
|
|
!test_and_set_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags)) {
|
|
|
|
|
|
|
|
iforce_usb_xmit(iforce);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start or stop an effect */
|
|
|
|
int iforce_control_playback(struct iforce* iforce, u16 id, unsigned int value)
|
|
|
|
{
|
|
|
|
unsigned char data[3];
|
|
|
|
|
|
|
|
data[0] = LO(id);
|
|
|
|
data[1] = (value > 0) ? ((value > 1) ? 0x41 : 0x01) : 0;
|
|
|
|
data[2] = LO(value);
|
|
|
|
return iforce_send_packet(iforce, FF_CMD_PLAY, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark an effect that was being updated as ready. That means it can be updated
|
|
|
|
* again */
|
|
|
|
static int mark_core_as_ready(struct iforce *iforce, unsigned short addr)
|
|
|
|
{
|
|
|
|
int i;
|
2005-09-15 01:01:52 -06:00
|
|
|
|
2006-07-18 23:40:39 -06:00
|
|
|
if (!iforce->dev->ff)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < iforce->dev->ff->max_effects; ++i) {
|
2005-04-16 16:20:36 -06:00
|
|
|
if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) &&
|
|
|
|
(iforce->core_effects[i].mod1_chunk.start == addr ||
|
|
|
|
iforce->core_effects[i].mod2_chunk.start == addr)) {
|
|
|
|
clear_bit(FF_CORE_UPDATE, iforce->core_effects[i].flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2008-08-14 10:37:34 -06:00
|
|
|
dev_warn(&iforce->dev->dev, "unused effect %04x updated !!!\n", addr);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-09-15 01:01:52 -06:00
|
|
|
struct input_dev *dev = iforce->dev;
|
2005-04-16 16:20:36 -06:00
|
|
|
int i;
|
|
|
|
static int being_used = 0;
|
|
|
|
|
|
|
|
if (being_used)
|
2008-08-14 10:37:34 -06:00
|
|
|
dev_warn(&iforce->dev->dev,
|
|
|
|
"re-entrant call to iforce_process %d\n", being_used);
|
2005-04-16 16:20:36 -06:00
|
|
|
being_used++;
|
|
|
|
|
|
|
|
#ifdef CONFIG_JOYSTICK_IFORCE_232
|
|
|
|
if (HI(iforce->expect_packet) == HI(cmd)) {
|
|
|
|
iforce->expect_packet = 0;
|
|
|
|
iforce->ecmd = cmd;
|
|
|
|
memcpy(iforce->edata, data, IFORCE_MAX_LENGTH);
|
|
|
|
}
|
|
|
|
#endif
|
2006-01-30 23:31:07 -07:00
|
|
|
wake_up(&iforce->wait);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (!iforce->type) {
|
|
|
|
being_used--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (HI(cmd)) {
|
|
|
|
|
|
|
|
case 0x01: /* joystick position data */
|
|
|
|
case 0x03: /* wheel position data */
|
|
|
|
if (HI(cmd) == 1) {
|
|
|
|
input_report_abs(dev, ABS_X, (__s16) (((__s16)data[1] << 8) | data[0]));
|
|
|
|
input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[3] << 8) | data[2]));
|
|
|
|
input_report_abs(dev, ABS_THROTTLE, 255 - data[4]);
|
|
|
|
if (LO(cmd) >= 8 && test_bit(ABS_RUDDER ,dev->absbit))
|
|
|
|
input_report_abs(dev, ABS_RUDDER, (__s8)data[7]);
|
|
|
|
} else {
|
|
|
|
input_report_abs(dev, ABS_WHEEL, (__s16) (((__s16)data[1] << 8) | data[0]));
|
|
|
|
input_report_abs(dev, ABS_GAS, 255 - data[2]);
|
|
|
|
input_report_abs(dev, ABS_BRAKE, 255 - data[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
input_report_abs(dev, ABS_HAT0X, iforce_hat_to_axis[data[6] >> 4].x);
|
|
|
|
input_report_abs(dev, ABS_HAT0Y, iforce_hat_to_axis[data[6] >> 4].y);
|
|
|
|
|
|
|
|
for (i = 0; iforce->type->btn[i] >= 0; i++)
|
|
|
|
input_report_key(dev, iforce->type->btn[i], data[(i >> 3) + 5] & (1 << (i & 7)));
|
|
|
|
|
|
|
|
/* If there are untouched bits left, interpret them as the second hat */
|
|
|
|
if (i <= 8) {
|
|
|
|
int btns = data[6];
|
|
|
|
if (test_bit(ABS_HAT1X, dev->absbit)) {
|
|
|
|
if (btns & 8) input_report_abs(dev, ABS_HAT1X, -1);
|
|
|
|
else if (btns & 2) input_report_abs(dev, ABS_HAT1X, 1);
|
|
|
|
else input_report_abs(dev, ABS_HAT1X, 0);
|
|
|
|
}
|
|
|
|
if (test_bit(ABS_HAT1Y, dev->absbit)) {
|
|
|
|
if (btns & 1) input_report_abs(dev, ABS_HAT1Y, -1);
|
|
|
|
else if (btns & 4) input_report_abs(dev, ABS_HAT1Y, 1);
|
|
|
|
else input_report_abs(dev, ABS_HAT1Y, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
input_sync(dev);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02: /* status report */
|
|
|
|
input_report_key(dev, BTN_DEAD, data[0] & 0x02);
|
|
|
|
input_sync(dev);
|
|
|
|
|
|
|
|
/* Check if an effect was just started or stopped */
|
|
|
|
i = data[1] & 0x7f;
|
|
|
|
if (data[1] & 0x80) {
|
|
|
|
if (!test_and_set_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) {
|
2006-07-18 23:40:39 -06:00
|
|
|
/* Report play event */
|
|
|
|
input_report_ff_status(dev, i, FF_STATUS_PLAYING);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2006-07-18 23:40:39 -06:00
|
|
|
} else if (test_and_clear_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Report stop event */
|
|
|
|
input_report_ff_status(dev, i, FF_STATUS_STOPPED);
|
|
|
|
}
|
|
|
|
if (LO(cmd) > 3) {
|
|
|
|
int j;
|
2006-07-18 23:40:39 -06:00
|
|
|
for (j = 3; j < LO(cmd); j += 2)
|
2005-04-16 16:20:36 -06:00
|
|
|
mark_core_as_ready(iforce, data[j] | (data[j+1]<<8));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
being_used--;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iforce_get_id_packet(struct iforce *iforce, char *packet)
|
|
|
|
{
|
|
|
|
switch (iforce->bus) {
|
|
|
|
|
2007-08-29 22:04:33 -06:00
|
|
|
case IFORCE_USB: {
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifdef CONFIG_JOYSTICK_IFORCE_USB
|
2007-08-29 22:04:33 -06:00
|
|
|
int status;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
iforce->cr.bRequest = packet[0];
|
|
|
|
iforce->ctrl->dev = iforce->usbdev;
|
|
|
|
|
2007-05-13 22:09:33 -06:00
|
|
|
status = usb_submit_urb(iforce->ctrl, GFP_ATOMIC);
|
|
|
|
if (status) {
|
|
|
|
err("usb_submit_urb failed %d", status);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -1;
|
2007-05-13 22:09:33 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-09-04 23:12:39 -06:00
|
|
|
wait_event_interruptible_timeout(iforce->wait,
|
|
|
|
iforce->ctrl->status != -EINPROGRESS, HZ);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-30 23:31:07 -07:00
|
|
|
if (iforce->ctrl->status) {
|
2007-05-13 22:09:33 -06:00
|
|
|
dbg("iforce->ctrl->status = %d", iforce->ctrl->status);
|
2005-04-16 16:20:36 -06:00
|
|
|
usb_unlink_urb(iforce->ctrl);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#else
|
2007-05-13 22:09:33 -06:00
|
|
|
dbg("iforce_get_id_packet: iforce->bus = USB!");
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
2007-08-29 22:04:33 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IFORCE_232:
|
|
|
|
|
|
|
|
#ifdef CONFIG_JOYSTICK_IFORCE_232
|
|
|
|
iforce->expect_packet = FF_CMD_QUERY;
|
|
|
|
iforce_send_packet(iforce, FF_CMD_QUERY, packet);
|
|
|
|
|
2005-09-04 23:12:39 -06:00
|
|
|
wait_event_interruptible_timeout(iforce->wait,
|
|
|
|
!iforce->expect_packet, HZ);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-09-04 23:12:39 -06:00
|
|
|
if (iforce->expect_packet) {
|
2005-04-16 16:20:36 -06:00
|
|
|
iforce->expect_packet = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#else
|
2007-04-11 23:30:24 -06:00
|
|
|
err("iforce_get_id_packet: iforce->bus = SERIO!");
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-04-11 23:30:24 -06:00
|
|
|
err("iforce_get_id_packet: iforce->bus = %d", iforce->bus);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -(iforce->edata[0] != packet[0]);
|
|
|
|
}
|
|
|
|
|