Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / input / joystick / iforce / iforce-serio.c
blob64a78c5154847bfaf574ba8d510a24d9441d190f
1 /*
2 * $Id: iforce-serio.c,v 1.4 2002/01/28 22:45:00 jdeneux Exp $
4 * Copyright (c) 2000-2001 Vojtech Pavlik <vojtech@ucw.cz>
5 * Copyright (c) 2001 Johann Deneux <deneux@ifrance.com>
7 * USB/RS232 I-Force joysticks and wheels.
8 */
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Should you need to contact me, the author, you can do so either by
26 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
27 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
30 #include "iforce.h"
32 void iforce_serial_xmit(struct iforce *iforce)
34 unsigned char cs;
35 int i;
36 unsigned long flags;
38 if (test_and_set_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags)) {
39 set_bit(IFORCE_XMIT_AGAIN, iforce->xmit_flags);
40 return;
43 spin_lock_irqsave(&iforce->xmit_lock, flags);
45 again:
46 if (iforce->xmit.head == iforce->xmit.tail) {
47 clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
48 spin_unlock_irqrestore(&iforce->xmit_lock, flags);
49 return;
52 cs = 0x2b;
54 serio_write(iforce->serio, 0x2b);
56 serio_write(iforce->serio, iforce->xmit.buf[iforce->xmit.tail]);
57 cs ^= iforce->xmit.buf[iforce->xmit.tail];
58 XMIT_INC(iforce->xmit.tail, 1);
60 for (i=iforce->xmit.buf[iforce->xmit.tail]; i >= 0; --i) {
61 serio_write(iforce->serio, iforce->xmit.buf[iforce->xmit.tail]);
62 cs ^= iforce->xmit.buf[iforce->xmit.tail];
63 XMIT_INC(iforce->xmit.tail, 1);
66 serio_write(iforce->serio, cs);
68 if (test_and_clear_bit(IFORCE_XMIT_AGAIN, iforce->xmit_flags))
69 goto again;
71 clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
73 spin_unlock_irqrestore(&iforce->xmit_lock, flags);
76 static void iforce_serio_write_wakeup(struct serio *serio)
78 struct iforce *iforce = serio_get_drvdata(serio);
80 iforce_serial_xmit(iforce);
83 static irqreturn_t iforce_serio_irq(struct serio *serio,
84 unsigned char data, unsigned int flags, struct pt_regs *regs)
86 struct iforce *iforce = serio_get_drvdata(serio);
88 if (!iforce->pkt) {
89 if (data == 0x2b)
90 iforce->pkt = 1;
91 goto out;
94 if (!iforce->id) {
95 if (data > 3 && data != 0xff)
96 iforce->pkt = 0;
97 else
98 iforce->id = data;
99 goto out;
102 if (!iforce->len) {
103 if (data > IFORCE_MAX_LENGTH) {
104 iforce->pkt = 0;
105 iforce->id = 0;
106 } else {
107 iforce->len = data;
109 goto out;
112 if (iforce->idx < iforce->len) {
113 iforce->csum += iforce->data[iforce->idx++] = data;
114 goto out;
117 if (iforce->idx == iforce->len) {
118 iforce_process_packet(iforce, (iforce->id << 8) | iforce->idx, iforce->data, regs);
119 iforce->pkt = 0;
120 iforce->id = 0;
121 iforce->len = 0;
122 iforce->idx = 0;
123 iforce->csum = 0;
125 out:
126 return IRQ_HANDLED;
129 static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
131 struct iforce *iforce;
132 int err;
134 iforce = kzalloc(sizeof(struct iforce), GFP_KERNEL);
135 if (!iforce)
136 return -ENOMEM;
138 iforce->bus = IFORCE_232;
139 iforce->serio = serio;
141 serio_set_drvdata(serio, iforce);
143 err = serio_open(serio, drv);
144 if (err) {
145 serio_set_drvdata(serio, NULL);
146 kfree(iforce);
147 return err;
150 err = iforce_init_device(iforce);
151 if (err) {
152 serio_close(serio);
153 serio_set_drvdata(serio, NULL);
154 kfree(iforce);
155 return -ENODEV;
158 return 0;
161 static void iforce_serio_disconnect(struct serio *serio)
163 struct iforce *iforce = serio_get_drvdata(serio);
165 input_unregister_device(iforce->dev);
166 serio_close(serio);
167 serio_set_drvdata(serio, NULL);
168 kfree(iforce);
171 static struct serio_device_id iforce_serio_ids[] = {
173 .type = SERIO_RS232,
174 .proto = SERIO_IFORCE,
175 .id = SERIO_ANY,
176 .extra = SERIO_ANY,
178 { 0 }
181 MODULE_DEVICE_TABLE(serio, iforce_serio_ids);
183 struct serio_driver iforce_serio_drv = {
184 .driver = {
185 .name = "iforce",
187 .description = "RS232 I-Force joysticks and wheels driver",
188 .id_table = iforce_serio_ids,
189 .write_wakeup = iforce_serio_write_wakeup,
190 .interrupt = iforce_serio_irq,
191 .connect = iforce_serio_connect,
192 .disconnect = iforce_serio_disconnect,