vserver 1.9.5.x5
[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 and serio->sem */
49         struct semaphore drv_sem;       /* protects serio->drv so attributes can pin driver */
50
51         struct device dev;
52
53         struct list_head node;
54 };
55 #define to_serio_port(d)        container_of(d, struct serio, dev)
56
57 struct serio_driver {
58         void *private;
59         char *description;
60
61         unsigned int manual_bind;
62
63         void (*write_wakeup)(struct serio *);
64         irqreturn_t (*interrupt)(struct serio *, unsigned char,
65                         unsigned int, struct pt_regs *);
66         void (*connect)(struct serio *, struct serio_driver *drv);
67         int  (*reconnect)(struct serio *);
68         void (*disconnect)(struct serio *);
69         void (*cleanup)(struct serio *);
70
71         struct device_driver driver;
72
73         struct list_head node;
74 };
75 #define to_serio_driver(d)      container_of(d, struct serio_driver, driver)
76
77 int serio_open(struct serio *serio, struct serio_driver *drv);
78 void serio_close(struct serio *serio);
79 void serio_rescan(struct serio *serio);
80 void serio_reconnect(struct serio *serio);
81 irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags, struct pt_regs *regs);
82
83 void serio_register_port(struct serio *serio);
84 void serio_register_port_delayed(struct serio *serio);
85 void serio_unregister_port(struct serio *serio);
86 void serio_unregister_port_delayed(struct serio *serio);
87
88 void serio_register_driver(struct serio_driver *drv);
89 void serio_unregister_driver(struct serio_driver *drv);
90
91 static __inline__ int serio_write(struct serio *serio, unsigned char data)
92 {
93         if (serio->write)
94                 return serio->write(serio, data);
95         else
96                 return -1;
97 }
98
99 static __inline__ void serio_drv_write_wakeup(struct serio *serio)
100 {
101         if (serio->drv && serio->drv->write_wakeup)
102                 serio->drv->write_wakeup(serio);
103 }
104
105 static __inline__ void serio_cleanup(struct serio *serio)
106 {
107         if (serio->drv && serio->drv->cleanup)
108                 serio->drv->cleanup(serio);
109 }
110
111
112 /*
113  * Use the following fucntions to protect critical sections in
114  * driver code from port's interrupt handler
115  */
116 static __inline__ void serio_pause_rx(struct serio *serio)
117 {
118         spin_lock_irq(&serio->lock);
119 }
120
121 static __inline__ void serio_continue_rx(struct serio *serio)
122 {
123         spin_unlock_irq(&serio->lock);
124 }
125
126 /*
127  * Use the following fucntions to pin serio's driver in process context
128  */
129 static __inline__ int serio_pin_driver(struct serio *serio)
130 {
131         return down_interruptible(&serio->drv_sem);
132 }
133
134 static __inline__ void serio_unpin_driver(struct serio *serio)
135 {
136         up(&serio->drv_sem);
137 }
138
139
140 #endif
141
142 /*
143  * bit masks for use in "interrupt" flags (3rd argument)
144  */
145 #define SERIO_TIMEOUT   1
146 #define SERIO_PARITY    2
147 #define SERIO_FRAME     4
148
149 #define SERIO_TYPE      0xff000000UL
150 #define SERIO_XT        0x00000000UL
151 #define SERIO_8042      0x01000000UL
152 #define SERIO_RS232     0x02000000UL
153 #define SERIO_HIL_MLC   0x03000000UL
154 #define SERIO_PS_PSTHRU 0x05000000UL
155 #define SERIO_8042_XL   0x06000000UL
156
157 #define SERIO_PROTO     0xFFUL
158 #define SERIO_MSC       0x01
159 #define SERIO_SUN       0x02
160 #define SERIO_MS        0x03
161 #define SERIO_MP        0x04
162 #define SERIO_MZ        0x05
163 #define SERIO_MZP       0x06
164 #define SERIO_MZPP      0x07
165 #define SERIO_VSXXXAA   0x08
166 #define SERIO_SUNKBD    0x10
167 #define SERIO_WARRIOR   0x18
168 #define SERIO_SPACEORB  0x19
169 #define SERIO_MAGELLAN  0x1a
170 #define SERIO_SPACEBALL 0x1b
171 #define SERIO_GUNZE     0x1c
172 #define SERIO_IFORCE    0x1d
173 #define SERIO_STINGER   0x1e
174 #define SERIO_NEWTON    0x1f
175 #define SERIO_STOWAWAY  0x20
176 #define SERIO_H3600     0x21
177 #define SERIO_PS2SER    0x22
178 #define SERIO_TWIDKBD   0x23
179 #define SERIO_TWIDJOY   0x24
180 #define SERIO_HIL       0x25
181 #define SERIO_SNES232   0x26
182 #define SERIO_SEMTECH   0x27
183 #define SERIO_LKKBD     0x28
184
185 #define SERIO_ID        0xff00UL
186 #define SERIO_EXTRA     0xff0000UL
187
188 #endif