2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* $Id: iforce-serio.c,v 1.4 2002/01/28 22:45:00 jdeneux Exp $
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000-2001 Vojtech Pavlik <vojtech@ucw.cz>
|
2007-04-12 09:30:24 +04:00
|
|
|
* Copyright (c) 2001, 2007 Johann Deneux <johann.deneux@gmail.com>
|
2005-04-17 02:20:36 +04: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"
|
|
|
|
|
|
|
|
void iforce_serial_xmit(struct iforce *iforce)
|
|
|
|
{
|
|
|
|
unsigned char cs;
|
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (test_and_set_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags)) {
|
|
|
|
set_bit(IFORCE_XMIT_AGAIN, iforce->xmit_flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&iforce->xmit_lock, flags);
|
|
|
|
|
|
|
|
again:
|
|
|
|
if (iforce->xmit.head == iforce->xmit.tail) {
|
|
|
|
clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
|
|
|
|
spin_unlock_irqrestore(&iforce->xmit_lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cs = 0x2b;
|
|
|
|
|
|
|
|
serio_write(iforce->serio, 0x2b);
|
|
|
|
|
|
|
|
serio_write(iforce->serio, iforce->xmit.buf[iforce->xmit.tail]);
|
|
|
|
cs ^= iforce->xmit.buf[iforce->xmit.tail];
|
|
|
|
XMIT_INC(iforce->xmit.tail, 1);
|
|
|
|
|
|
|
|
for (i=iforce->xmit.buf[iforce->xmit.tail]; i >= 0; --i) {
|
|
|
|
serio_write(iforce->serio, iforce->xmit.buf[iforce->xmit.tail]);
|
|
|
|
cs ^= iforce->xmit.buf[iforce->xmit.tail];
|
|
|
|
XMIT_INC(iforce->xmit.tail, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
serio_write(iforce->serio, cs);
|
|
|
|
|
|
|
|
if (test_and_clear_bit(IFORCE_XMIT_AGAIN, iforce->xmit_flags))
|
|
|
|
goto again;
|
|
|
|
|
|
|
|
clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&iforce->xmit_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void iforce_serio_write_wakeup(struct serio *serio)
|
|
|
|
{
|
|
|
|
struct iforce *iforce = serio_get_drvdata(serio);
|
|
|
|
|
|
|
|
iforce_serial_xmit(iforce);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t iforce_serio_irq(struct serio *serio,
|
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 17:55:46 +04:00
|
|
|
unsigned char data, unsigned int flags)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct iforce *iforce = serio_get_drvdata(serio);
|
|
|
|
|
|
|
|
if (!iforce->pkt) {
|
|
|
|
if (data == 0x2b)
|
|
|
|
iforce->pkt = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!iforce->id) {
|
|
|
|
if (data > 3 && data != 0xff)
|
|
|
|
iforce->pkt = 0;
|
|
|
|
else
|
|
|
|
iforce->id = data;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!iforce->len) {
|
|
|
|
if (data > IFORCE_MAX_LENGTH) {
|
|
|
|
iforce->pkt = 0;
|
|
|
|
iforce->id = 0;
|
|
|
|
} else {
|
|
|
|
iforce->len = data;
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iforce->idx < iforce->len) {
|
|
|
|
iforce->csum += iforce->data[iforce->idx++] = data;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iforce->idx == iforce->len) {
|
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 17:55:46 +04:00
|
|
|
iforce_process_packet(iforce, (iforce->id << 8) | iforce->idx, iforce->data);
|
2005-04-17 02:20:36 +04:00
|
|
|
iforce->pkt = 0;
|
|
|
|
iforce->id = 0;
|
|
|
|
iforce->len = 0;
|
|
|
|
iforce->idx = 0;
|
|
|
|
iforce->csum = 0;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
|
|
|
|
{
|
|
|
|
struct iforce *iforce;
|
|
|
|
int err;
|
|
|
|
|
2005-09-15 11:01:52 +04:00
|
|
|
iforce = kzalloc(sizeof(struct iforce), GFP_KERNEL);
|
|
|
|
if (!iforce)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
iforce->bus = IFORCE_232;
|
|
|
|
iforce->serio = serio;
|
|
|
|
|
|
|
|
serio_set_drvdata(serio, iforce);
|
|
|
|
|
|
|
|
err = serio_open(serio, drv);
|
2006-11-06 06:40:09 +03:00
|
|
|
if (err)
|
|
|
|
goto fail1;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-09-15 11:01:52 +04:00
|
|
|
err = iforce_init_device(iforce);
|
2006-11-06 06:40:09 +03:00
|
|
|
if (err)
|
|
|
|
goto fail2;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return 0;
|
2006-11-06 06:40:09 +03:00
|
|
|
|
|
|
|
fail2: serio_close(serio);
|
|
|
|
fail1: serio_set_drvdata(serio, NULL);
|
|
|
|
kfree(iforce);
|
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void iforce_serio_disconnect(struct serio *serio)
|
|
|
|
{
|
|
|
|
struct iforce *iforce = serio_get_drvdata(serio);
|
|
|
|
|
2005-09-15 11:01:52 +04:00
|
|
|
input_unregister_device(iforce->dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
serio_close(serio);
|
|
|
|
serio_set_drvdata(serio, NULL);
|
|
|
|
kfree(iforce);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct serio_device_id iforce_serio_ids[] = {
|
|
|
|
{
|
|
|
|
.type = SERIO_RS232,
|
|
|
|
.proto = SERIO_IFORCE,
|
|
|
|
.id = SERIO_ANY,
|
|
|
|
.extra = SERIO_ANY,
|
|
|
|
},
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(serio, iforce_serio_ids);
|
|
|
|
|
|
|
|
struct serio_driver iforce_serio_drv = {
|
|
|
|
.driver = {
|
|
|
|
.name = "iforce",
|
|
|
|
},
|
|
|
|
.description = "RS232 I-Force joysticks and wheels driver",
|
|
|
|
.id_table = iforce_serio_ids,
|
|
|
|
.write_wakeup = iforce_serio_write_wakeup,
|
|
|
|
.interrupt = iforce_serio_irq,
|
|
|
|
.connect = iforce_serio_connect,
|
|
|
|
.disconnect = iforce_serio_disconnect,
|
|
|
|
};
|