2 * $Id: serio.c,v 1.5 2000/06/04 17:44:59 vojtech Exp $
4 * Copyright (c) 1999-2000 Vojtech Pavlik
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
) {
57 dev
->connect(serio
, dev
);
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
)
73 serio
->number
= serio_number
++;
74 serio
->next
= serio_list
;
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
);
95 void serio_register_device(struct serio_dev
*dev
)
97 struct serio
*serio
= serio_list
;
101 dev
->next
= serio_dev
;
105 if (!serio
->dev
&& dev
->connect
)
106 dev
->connect(serio
, dev
);
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
;
120 if (serio
->dev
== dev
&& dev
->disconnect
)
121 dev
->disconnect(serio
);
122 serio_find_dev(serio
);
129 int serio_open(struct serio
*serio
, struct serio_dev
*dev
)
132 if (serio
->open(serio
)) {
141 void serio_close(struct serio
*serio
)