vserver 1.9.3
[linux-2.6.git] / include / linux / serio.h
1 #ifndef _SERIO_H
2 #define _SERIO_H
3
4 /*
5  * Copyright (C) 1999-2002 Vojtech Pavlik
6 *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License version 2 as published by
9  * the Free Software Foundation.
10  */
11
12 #include <linux/ioctl.h>
13 #include <linux/interrupt.h>
14
15 #define SPIOCSTYPE      _IOW('q', 0x01, unsigned long)
16
17 #ifdef __KERNEL__
18
19 #include <linux/list.h>
20 #include <linux/spinlock.h>
21 #include <linux/device.h>
22
23 struct serio {
24         void *private;
25         void *port_data;
26
27         char name[32];
28         char phys[32];
29
30         unsigned int manual_bind;
31
32         unsigned short idbus;
33         unsigned short idvendor;
34         unsigned short idproduct;
35         unsigned short idversion;
36
37         unsigned long type;
38         unsigned long event;
39
40         spinlock_t lock;                /* protects critical sections from port's interrupt handler */
41
42         int (*write)(struct serio *, unsigned char);
43         int (*open)(struct serio *);
44         void (*close)(struct serio *);
45
46         struct serio *parent, *child;
47
48         struct serio_driver *drv;       /* accessed from interrupt, must be protected by serio->lock */
49
50         struct device dev;
51
52         struct list_head node;
53 };
54 #define to_serio_port(d)        container_of(d, struct serio, dev)
55
56 struct serio_driver {
57         void *private;
58         char *description;
59
60         unsigned int manual_bind;
61
62         void (*write_wakeup)(struct serio *);
63         irqreturn_t (*interrupt)(struct serio *, unsigned char,
64                         unsigned int, struct pt_regs *);
65         void (*connect)(struct serio *, struct serio_driver *drv);
66         int  (*reconnect)(struct serio *);
67         void (*disconnect)(struct serio *);
68         void (*cleanup)(struct serio *);
69
70         struct device_driver driver;
71
72         struct list_head node;
73 };
74 #define to_serio_driver(d)      container_of(d, struct serio_driver, driver)
75
76 int serio_open(struct serio *serio, struct serio_driver *drv);
77 void serio_close(struct serio *serio);
78 void serio_rescan(struct serio *serio);
79 void serio_reconnect(struct serio *serio);
80 irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags, struct pt_regs *regs);
81
82 void serio_register_port(struct serio *serio);
83 void serio_register_port_delayed(struct serio *serio);
84 void serio_unregister_port(struct serio *serio);
85 void serio_unregister_port_delayed(struct serio *serio);
86
87 void serio_register_driver(struct serio_driver *drv);
88 void serio_unregister_driver(struct serio_driver *drv);
89
90 static __inline__ int serio_write(struct serio *serio, unsigned char data)
91 {
92         if (serio->write)
93                 return serio->write(serio, data);
94         else
95                 return -1;
96 }
97
98 static __inline__ void serio_drv_write_wakeup(struct serio *serio)
99 {
100         if (serio->drv && serio->drv->write_wakeup)
101                 serio->drv->write_wakeup(serio);
102 }
103
104 static __inline__ void serio_cleanup(struct serio *serio)
105 {
106         if (serio->drv && serio->drv->cleanup)
107                 serio->drv->cleanup(serio);
108 }
109
110
111 /*
112  * Use the following fucntions to protect critical sections in
113  * driver code from port's interrupt handler
114  */
115 static __inline__ void serio_pause_rx(struct serio *serio)
116 {
117         spin_lock_irq(&serio->lock);
118 }
119
120 static __inline__ void serio_continue_rx(struct serio *serio)
121 {
122         spin_unlock_irq(&serio->lock);
123 }
124
125
126 #endif
127
128 /*
129  * bit masks for use in "interrupt" flags (3rd argument)
130  */
131 #define SERIO_TIMEOUT   1
132 #define SERIO_PARITY    2
133 #define SERIO_FRAME     4
134
135 #define SERIO_TYPE      0xff000000UL
136 #define SERIO_XT        0x00000000UL
137 #define SERIO_8042      0x01000000UL
138 #define SERIO_RS232     0x02000000UL
139 #define SERIO_HIL_MLC   0x03000000UL
140 #define SERIO_PS_PSTHRU 0x05000000UL
141 #define SERIO_8042_XL   0x06000000UL
142
143 #define SERIO_PROTO     0xFFUL
144 #define SERIO_MSC       0x01
145 #define SERIO_SUN       0x02
146 #define SERIO_MS        0x03
147 #define SERIO_MP        0x04
148 #define SERIO_MZ        0x05
149 #define SERIO_MZP       0x06
150 #define SERIO_MZPP      0x07
151 #define SERIO_VSXXXAA   0x08
152 #define SERIO_SUNKBD    0x10
153 #define SERIO_WARRIOR   0x18
154 #define SERIO_SPACEORB  0x19
155 #define SERIO_MAGELLAN  0x1a
156 #define SERIO_SPACEBALL 0x1b
157 #define SERIO_GUNZE     0x1c
158 #define SERIO_IFORCE    0x1d
159 #define SERIO_STINGER   0x1e
160 #define SERIO_NEWTON    0x1f
161 #define SERIO_STOWAWAY  0x20
162 #define SERIO_H3600     0x21
163 #define SERIO_PS2SER    0x22
164 #define SERIO_TWIDKBD   0x23
165 #define SERIO_TWIDJOY   0x24
166 #define SERIO_HIL       0x25
167 #define SERIO_SNES232   0x26
168 #define SERIO_SEMTECH   0x27
169 #define SERIO_LKKBD     0x28
170
171 #define SERIO_ID        0xff00UL
172 #define SERIO_EXTRA     0xff0000UL
173
174 #endif