Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[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
14 #define SPIOCSTYPE      _IOW('q', 0x01, unsigned long)
15
16 #ifdef __KERNEL__
17
18 #include <linux/interrupt.h>
19 #include <linux/list.h>
20 #include <linux/spinlock.h>
21 #include <linux/mutex.h>
22 #include <linux/device.h>
23 #include <linux/mod_devicetable.h>
24
25 struct serio {
26         void *port_data;
27
28         char name[32];
29         char phys[32];
30
31         unsigned int manual_bind;
32
33         struct serio_device_id id;
34
35         spinlock_t lock;                /* protects critical sections from port's interrupt handler */
36
37         int (*write)(struct serio *, unsigned char);
38         int (*open)(struct serio *);
39         void (*close)(struct serio *);
40         int (*start)(struct serio *);
41         void (*stop)(struct serio *);
42
43         struct serio *parent, *child;
44         unsigned int depth;             /* level of nesting in serio hierarchy */
45
46         struct serio_driver *drv;       /* accessed from interrupt, must be protected by serio->lock and serio->sem */
47         struct mutex drv_mutex;         /* protects serio->drv so attributes can pin driver */
48
49         struct device dev;
50         unsigned int registered;        /* port has been fully registered with driver core */
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         struct serio_device_id *id_table;
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         int  (*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 #define to_serio_driver(d)      container_of(d, struct serio_driver, driver)
74
75 int serio_open(struct serio *serio, struct serio_driver *drv);
76 void serio_close(struct serio *serio);
77 void serio_rescan(struct serio *serio);
78 void serio_reconnect(struct serio *serio);
79 irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags, struct pt_regs *regs);
80
81 void __serio_register_port(struct serio *serio, struct module *owner);
82 static inline void serio_register_port(struct serio *serio)
83 {
84         __serio_register_port(serio, THIS_MODULE);
85 }
86
87 void serio_unregister_port(struct serio *serio);
88 void serio_unregister_child_port(struct serio *serio);
89 void __serio_unregister_port_delayed(struct serio *serio, struct module *owner);
90 static inline void serio_unregister_port_delayed(struct serio *serio)
91 {
92         __serio_unregister_port_delayed(serio, THIS_MODULE);
93 }
94
95 void __serio_register_driver(struct serio_driver *drv, struct module *owner);
96 static inline void serio_register_driver(struct serio_driver *drv)
97 {
98         __serio_register_driver(drv, THIS_MODULE);
99 }
100
101 void serio_unregister_driver(struct serio_driver *drv);
102
103 static inline int serio_write(struct serio *serio, unsigned char data)
104 {
105         if (serio->write)
106                 return serio->write(serio, data);
107         else
108                 return -1;
109 }
110
111 static inline void serio_drv_write_wakeup(struct serio *serio)
112 {
113         if (serio->drv && serio->drv->write_wakeup)
114                 serio->drv->write_wakeup(serio);
115 }
116
117 static inline void serio_cleanup(struct serio *serio)
118 {
119         if (serio->drv && serio->drv->cleanup)
120                 serio->drv->cleanup(serio);
121 }
122
123 /*
124  * Use the following functions to manipulate serio's per-port
125  * driver-specific data.
126  */
127 static inline void *serio_get_drvdata(struct serio *serio)
128 {
129         return dev_get_drvdata(&serio->dev);
130 }
131
132 static inline void serio_set_drvdata(struct serio *serio, void *data)
133 {
134         dev_set_drvdata(&serio->dev, data);
135 }
136
137 /*
138  * Use the following functions to protect critical sections in
139  * driver code from port's interrupt handler
140  */
141 static inline void serio_pause_rx(struct serio *serio)
142 {
143         spin_lock_irq(&serio->lock);
144 }
145
146 static inline void serio_continue_rx(struct serio *serio)
147 {
148         spin_unlock_irq(&serio->lock);
149 }
150
151 /*
152  * Use the following functions to pin serio's driver in process context
153  */
154 static inline int serio_pin_driver(struct serio *serio)
155 {
156         return mutex_lock_interruptible(&serio->drv_mutex);
157 }
158
159 static inline void serio_pin_driver_uninterruptible(struct serio *serio)
160 {
161         mutex_lock(&serio->drv_mutex);
162 }
163
164 static inline void serio_unpin_driver(struct serio *serio)
165 {
166         mutex_unlock(&serio->drv_mutex);
167 }
168
169
170 #endif
171
172 /*
173  * bit masks for use in "interrupt" flags (3rd argument)
174  */
175 #define SERIO_TIMEOUT   1
176 #define SERIO_PARITY    2
177 #define SERIO_FRAME     4
178
179 /*
180  * Serio types
181  */
182 #define SERIO_XT        0x00
183 #define SERIO_8042      0x01
184 #define SERIO_RS232     0x02
185 #define SERIO_HIL_MLC   0x03
186 #define SERIO_PS_PSTHRU 0x05
187 #define SERIO_8042_XL   0x06
188
189 /*
190  * Serio types
191  */
192 #define SERIO_UNKNOWN   0x00
193 #define SERIO_MSC       0x01
194 #define SERIO_SUN       0x02
195 #define SERIO_MS        0x03
196 #define SERIO_MP        0x04
197 #define SERIO_MZ        0x05
198 #define SERIO_MZP       0x06
199 #define SERIO_MZPP      0x07
200 #define SERIO_VSXXXAA   0x08
201 #define SERIO_SUNKBD    0x10
202 #define SERIO_WARRIOR   0x18
203 #define SERIO_SPACEORB  0x19
204 #define SERIO_MAGELLAN  0x1a
205 #define SERIO_SPACEBALL 0x1b
206 #define SERIO_GUNZE     0x1c
207 #define SERIO_IFORCE    0x1d
208 #define SERIO_STINGER   0x1e
209 #define SERIO_NEWTON    0x1f
210 #define SERIO_STOWAWAY  0x20
211 #define SERIO_H3600     0x21
212 #define SERIO_PS2SER    0x22
213 #define SERIO_TWIDKBD   0x23
214 #define SERIO_TWIDJOY   0x24
215 #define SERIO_HIL       0x25
216 #define SERIO_SNES232   0x26
217 #define SERIO_SEMTECH   0x27
218 #define SERIO_LKKBD     0x28
219 #define SERIO_ELO       0x29
220 #define SERIO_MICROTOUCH        0x30
221
222 #endif