2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
|
2007-04-12 13:30:24 +08:00
|
|
|
* Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
|
2005-04-17 06:20:36 +08: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 <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/serio.h>
|
|
|
|
#include <linux/circ_buf.h>
|
2006-02-19 13:22:30 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* This module provides arbitrary resource management routines.
|
|
|
|
* I use it to manage the device's memory.
|
|
|
|
* Despite the name of this module, I am *not* going to access the ioports.
|
|
|
|
*/
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
|
2006-02-19 13:22:30 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define IFORCE_MAX_LENGTH 16
|
|
|
|
|
|
|
|
/* iforce::bus */
|
|
|
|
#define IFORCE_232 1
|
|
|
|
#define IFORCE_USB 2
|
|
|
|
|
2006-07-19 13:40:39 +08:00
|
|
|
#define IFORCE_EFFECTS_MAX 32
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Each force feedback effect is made of one core effect, which can be
|
|
|
|
* associated to at most to effect modifiers
|
|
|
|
*/
|
|
|
|
#define FF_MOD1_IS_USED 0
|
|
|
|
#define FF_MOD2_IS_USED 1
|
|
|
|
#define FF_CORE_IS_USED 2
|
|
|
|
#define FF_CORE_IS_PLAYED 3 /* Effect is currently being played */
|
|
|
|
#define FF_CORE_SHOULD_PLAY 4 /* User wants the effect to be played */
|
|
|
|
#define FF_CORE_UPDATE 5 /* Effect is being updated */
|
2007-10-19 14:40:32 +08:00
|
|
|
#define FF_MODCORE_CNT 6
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct iforce_core_effect {
|
|
|
|
/* Information about where modifiers are stored in the device's memory */
|
|
|
|
struct resource mod1_chunk;
|
|
|
|
struct resource mod2_chunk;
|
2007-10-19 14:40:32 +08:00
|
|
|
unsigned long flags[BITS_TO_LONGS(FF_MODCORE_CNT)];
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define FF_CMD_EFFECT 0x010e
|
|
|
|
#define FF_CMD_ENVELOPE 0x0208
|
|
|
|
#define FF_CMD_MAGNITUDE 0x0303
|
|
|
|
#define FF_CMD_PERIOD 0x0407
|
|
|
|
#define FF_CMD_CONDITION 0x050a
|
|
|
|
|
|
|
|
#define FF_CMD_AUTOCENTER 0x4002
|
|
|
|
#define FF_CMD_PLAY 0x4103
|
|
|
|
#define FF_CMD_ENABLE 0x4201
|
|
|
|
#define FF_CMD_GAIN 0x4301
|
|
|
|
|
|
|
|
#define FF_CMD_QUERY 0xff01
|
|
|
|
|
|
|
|
/* Buffer for async write */
|
|
|
|
#define XMIT_SIZE 256
|
|
|
|
#define XMIT_INC(var, n) (var)+=n; (var)&= XMIT_SIZE -1
|
|
|
|
/* iforce::xmit_flags */
|
|
|
|
#define IFORCE_XMIT_RUNNING 0
|
|
|
|
#define IFORCE_XMIT_AGAIN 1
|
|
|
|
|
|
|
|
struct iforce_device {
|
|
|
|
u16 idvendor;
|
|
|
|
u16 idproduct;
|
|
|
|
char *name;
|
|
|
|
signed short *btn;
|
|
|
|
signed short *abs;
|
|
|
|
signed short *ff;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct iforce {
|
2005-09-15 15:01:52 +08:00
|
|
|
struct input_dev *dev; /* Input device interface */
|
2005-04-17 06:20:36 +08:00
|
|
|
struct iforce_device *type;
|
|
|
|
int bus;
|
|
|
|
|
|
|
|
unsigned char data[IFORCE_MAX_LENGTH];
|
|
|
|
unsigned char edata[IFORCE_MAX_LENGTH];
|
|
|
|
u16 ecmd;
|
|
|
|
u16 expect_packet;
|
|
|
|
|
|
|
|
#ifdef CONFIG_JOYSTICK_IFORCE_232
|
|
|
|
struct serio *serio; /* RS232 transfer */
|
|
|
|
int idx, pkt, len, id;
|
|
|
|
unsigned char csum;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_JOYSTICK_IFORCE_USB
|
|
|
|
struct usb_device *usbdev; /* USB transfer */
|
2012-05-05 06:23:04 +08:00
|
|
|
struct usb_interface *intf;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct urb *irq, *out, *ctrl;
|
|
|
|
struct usb_ctrlrequest cr;
|
|
|
|
#endif
|
|
|
|
spinlock_t xmit_lock;
|
|
|
|
/* Buffer used for asynchronous sending of bytes to the device */
|
|
|
|
struct circ_buf xmit;
|
|
|
|
unsigned char xmit_data[XMIT_SIZE];
|
2007-05-03 12:52:51 +08:00
|
|
|
unsigned long xmit_flags[1];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Force Feedback */
|
|
|
|
wait_queue_head_t wait;
|
|
|
|
struct resource device_memory;
|
2006-07-19 13:40:39 +08:00
|
|
|
struct iforce_core_effect core_effects[IFORCE_EFFECTS_MAX];
|
2006-02-19 13:22:30 +08:00
|
|
|
struct mutex mem_mutex;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Get hi and low bytes of a 16-bits int */
|
|
|
|
#define HI(a) ((unsigned char)((a) >> 8))
|
|
|
|
#define LO(a) ((unsigned char)((a) & 0xff))
|
|
|
|
|
|
|
|
/* For many parameters, it seems that 0x80 is a special value that should
|
|
|
|
* be avoided. Instead, we replace this value by 0x7f
|
|
|
|
*/
|
|
|
|
#define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
|
|
|
|
|
|
|
|
/* Encode a time value */
|
|
|
|
#define TIME_SCALE(a) (a)
|
|
|
|
|
|
|
|
|
|
|
|
/* Public functions */
|
|
|
|
/* iforce-serio.c */
|
|
|
|
void iforce_serial_xmit(struct iforce *iforce);
|
|
|
|
|
|
|
|
/* iforce-usb.c */
|
|
|
|
void iforce_usb_xmit(struct iforce *iforce);
|
|
|
|
|
|
|
|
/* iforce-main.c */
|
|
|
|
int iforce_init_device(struct iforce *iforce);
|
|
|
|
|
|
|
|
/* iforce-packets.c */
|
|
|
|
int iforce_control_playback(struct iforce*, u16 id, unsigned int);
|
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 21:55:46 +08:00
|
|
|
void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data);
|
2005-04-17 06:20:36 +08:00
|
|
|
int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
|
|
|
|
void iforce_dump_packet(char *msg, u16 cmd, unsigned char *data) ;
|
|
|
|
int iforce_get_id_packet(struct iforce *iforce, char *packet);
|
|
|
|
|
|
|
|
/* iforce-ff.c */
|
2006-07-19 13:40:39 +08:00
|
|
|
int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *);
|
|
|
|
int iforce_upload_constant(struct iforce *, struct ff_effect *, struct ff_effect *);
|
|
|
|
int iforce_upload_condition(struct iforce *, struct ff_effect *, struct ff_effect *);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Public variables */
|
|
|
|
extern struct serio_driver iforce_serio_drv;
|
|
|
|
extern struct usb_driver iforce_usb_driver;
|