Import 2.4.0-test2pre7
[davej-history.git] / drivers / char / joystick / serio.c
blob9c98e9e85d3229996bf6234f0f8e5837c8b6b061
1 /*
2 * $Id: serio.c,v 1.5 2000/06/04 17:44:59 vojtech Exp $
4 * Copyright (c) 1999-2000 Vojtech Pavlik
6 * Sponsored by SuSE
7 */
9 /*
10 * The Serio abstraction module
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * Should you need to contact me, the author, you can do so either by
29 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
30 * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
33 #include <linux/stddef.h>
34 #include <linux/module.h>
35 #include <linux/serio.h>
37 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
39 EXPORT_SYMBOL(serio_register_port);
40 EXPORT_SYMBOL(serio_unregister_port);
41 EXPORT_SYMBOL(serio_register_device);
42 EXPORT_SYMBOL(serio_unregister_device);
43 EXPORT_SYMBOL(serio_open);
44 EXPORT_SYMBOL(serio_close);
45 EXPORT_SYMBOL(serio_rescan);
47 static struct serio *serio_list = NULL;
48 static struct serio_dev *serio_dev = NULL;
49 static int serio_number = 0;
51 static void serio_find_dev(struct serio *serio)
53 struct serio_dev *dev = serio_dev;
55 while (dev && !serio->dev) {
56 if (dev->connect)
57 dev->connect(serio, dev);
58 dev = dev->next;
62 void serio_rescan(struct serio *serio)
64 if (serio->dev && serio->dev->disconnect)
65 serio->dev->disconnect(serio);
66 serio_find_dev(serio);
69 void serio_register_port(struct serio *serio)
71 MOD_INC_USE_COUNT;
73 serio->number = serio_number++;
74 serio->next = serio_list;
75 serio_list = serio;
77 serio_find_dev(serio);
80 void serio_unregister_port(struct serio *serio)
82 struct serio **serioptr = &serio_list;
84 while (*serioptr && (*serioptr != serio)) serioptr = &((*serioptr)->next);
85 *serioptr = (*serioptr)->next;
87 if (serio->dev && serio->dev->disconnect)
88 serio->dev->disconnect(serio);
90 serio_number--;
92 MOD_DEC_USE_COUNT;
95 void serio_register_device(struct serio_dev *dev)
97 struct serio *serio = serio_list;
99 MOD_INC_USE_COUNT;
101 dev->next = serio_dev;
102 serio_dev = dev;
104 while (serio) {
105 if (!serio->dev && dev->connect)
106 dev->connect(serio, dev);
107 serio = serio->next;
111 void serio_unregister_device(struct serio_dev *dev)
113 struct serio_dev **devptr = &serio_dev;
114 struct serio *serio = serio_list;
116 while (*devptr && (*devptr != dev)) devptr = &((*devptr)->next);
117 *devptr = (*devptr)->next;
119 while (serio) {
120 if (serio->dev == dev && dev->disconnect)
121 dev->disconnect(serio);
122 serio_find_dev(serio);
123 serio = serio->next;
126 MOD_DEC_USE_COUNT;
129 int serio_open(struct serio *serio, struct serio_dev *dev)
131 MOD_INC_USE_COUNT;
132 if (serio->open(serio)) {
133 MOD_DEC_USE_COUNT;
134 return -1;
136 serio->dev = dev;
138 return 0;
141 void serio_close(struct serio *serio)
143 MOD_DEC_USE_COUNT;
144 serio->close(serio);
145 serio->dev = NULL;