blob: 126d24c9eaa86a8fa374f9a28285e51e0ef7a4a5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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
Dmitry Torokhov7e044e02009-05-09 16:08:05 -070018#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/interrupt.h>
20#include <linux/list.h>
21#include <linux/spinlock.h>
Arjan van de Venc4e32e92006-02-19 00:21:55 -050022#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/device.h>
24#include <linux/mod_devicetable.h>
25
26struct serio {
27 void *port_data;
28
29 char name[32];
30 char phys[32];
31
Dmitry Torokhov7e044e02009-05-09 16:08:05 -070032 bool manual_bind;
33 bool registered; /* port has been fully registered with driver core */
34 bool suspended; /* port is suspended */
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 struct serio_device_id id;
38
39 spinlock_t lock; /* protects critical sections from port's interrupt handler */
40
41 int (*write)(struct serio *, unsigned char);
42 int (*open)(struct serio *);
43 void (*close)(struct serio *);
44 int (*start)(struct serio *);
45 void (*stop)(struct serio *);
46
47 struct serio *parent, *child;
Jiri Kosina88aa0102006-10-11 01:45:31 -040048 unsigned int depth; /* level of nesting in serio hierarchy */
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 struct serio_driver *drv; /* accessed from interrupt, must be protected by serio->lock and serio->sem */
Arjan van de Venc4e32e92006-02-19 00:21:55 -050051 struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 struct device dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 struct list_head node;
56};
57#define to_serio_port(d) container_of(d, struct serio, dev)
58
59struct serio_driver {
60 void *private;
61 char *description;
62
63 struct serio_device_id *id_table;
Dmitry Torokhov7e044e02009-05-09 16:08:05 -070064 bool manual_bind;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 void (*write_wakeup)(struct serio *);
David Howells7d12e782006-10-05 14:55:46 +010067 irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 int (*connect)(struct serio *, struct serio_driver *drv);
69 int (*reconnect)(struct serio *);
70 void (*disconnect)(struct serio *);
71 void (*cleanup)(struct serio *);
72
73 struct device_driver driver;
74};
75#define to_serio_driver(d) container_of(d, struct serio_driver, driver)
76
77int serio_open(struct serio *serio, struct serio_driver *drv);
78void serio_close(struct serio *serio);
79void serio_rescan(struct serio *serio);
80void serio_reconnect(struct serio *serio);
David Howells7d12e782006-10-05 14:55:46 +010081irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83void __serio_register_port(struct serio *serio, struct module *owner);
84static inline void serio_register_port(struct serio *serio)
85{
86 __serio_register_port(serio, THIS_MODULE);
87}
88
89void serio_unregister_port(struct serio *serio);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -050090void serio_unregister_child_port(struct serio *serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Greg Kroah-Hartman4b315622007-01-15 11:50:02 -080092int __serio_register_driver(struct serio_driver *drv, struct module *owner, const char *mod_name);
Dmitry Torokhova822bea2008-06-06 01:34:00 -040093static inline int __must_check serio_register_driver(struct serio_driver *drv)
Greg Kroah-Hartman4b315622007-01-15 11:50:02 -080094{
95 return __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME);
96}
Linus Torvalds1da177e2005-04-16 15:20:36 -070097void serio_unregister_driver(struct serio_driver *drv);
98
99static inline int serio_write(struct serio *serio, unsigned char data)
100{
101 if (serio->write)
102 return serio->write(serio, data);
103 else
104 return -1;
105}
106
107static inline void serio_drv_write_wakeup(struct serio *serio)
108{
109 if (serio->drv && serio->drv->write_wakeup)
110 serio->drv->write_wakeup(serio);
111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/*
Akinobu Mita0b280022006-03-26 01:38:58 -0800114 * Use the following functions to manipulate serio's per-port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 * driver-specific data.
116 */
117static inline void *serio_get_drvdata(struct serio *serio)
118{
119 return dev_get_drvdata(&serio->dev);
120}
121
122static inline void serio_set_drvdata(struct serio *serio, void *data)
123{
124 dev_set_drvdata(&serio->dev, data);
125}
126
127/*
Akinobu Mita0b280022006-03-26 01:38:58 -0800128 * Use the following functions to protect critical sections in
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 * driver code from port's interrupt handler
130 */
131static inline void serio_pause_rx(struct serio *serio)
132{
133 spin_lock_irq(&serio->lock);
134}
135
136static inline void serio_continue_rx(struct serio *serio)
137{
138 spin_unlock_irq(&serio->lock);
139}
140
141/*
Akinobu Mita0b280022006-03-26 01:38:58 -0800142 * Use the following functions to pin serio's driver in process context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 */
144static inline int serio_pin_driver(struct serio *serio)
145{
Arjan van de Venc4e32e92006-02-19 00:21:55 -0500146 return mutex_lock_interruptible(&serio->drv_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500149static inline void serio_pin_driver_uninterruptible(struct serio *serio)
150{
Arjan van de Venc4e32e92006-02-19 00:21:55 -0500151 mutex_lock(&serio->drv_mutex);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -0500152}
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154static inline void serio_unpin_driver(struct serio *serio)
155{
Arjan van de Venc4e32e92006-02-19 00:21:55 -0500156 mutex_unlock(&serio->drv_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
159
160#endif
161
162/*
163 * bit masks for use in "interrupt" flags (3rd argument)
164 */
165#define SERIO_TIMEOUT 1
166#define SERIO_PARITY 2
167#define SERIO_FRAME 4
168
169/*
170 * Serio types
171 */
172#define SERIO_XT 0x00
173#define SERIO_8042 0x01
174#define SERIO_RS232 0x02
175#define SERIO_HIL_MLC 0x03
176#define SERIO_PS_PSTHRU 0x05
177#define SERIO_8042_XL 0x06
178
179/*
Niels de Vosf3d1eb12008-07-08 10:30:27 -0400180 * Serio protocols
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 */
182#define SERIO_UNKNOWN 0x00
183#define SERIO_MSC 0x01
184#define SERIO_SUN 0x02
185#define SERIO_MS 0x03
186#define SERIO_MP 0x04
187#define SERIO_MZ 0x05
188#define SERIO_MZP 0x06
189#define SERIO_MZPP 0x07
190#define SERIO_VSXXXAA 0x08
191#define SERIO_SUNKBD 0x10
192#define SERIO_WARRIOR 0x18
193#define SERIO_SPACEORB 0x19
194#define SERIO_MAGELLAN 0x1a
195#define SERIO_SPACEBALL 0x1b
196#define SERIO_GUNZE 0x1c
197#define SERIO_IFORCE 0x1d
198#define SERIO_STINGER 0x1e
199#define SERIO_NEWTON 0x1f
200#define SERIO_STOWAWAY 0x20
201#define SERIO_H3600 0x21
202#define SERIO_PS2SER 0x22
203#define SERIO_TWIDKBD 0x23
204#define SERIO_TWIDJOY 0x24
205#define SERIO_HIL 0x25
206#define SERIO_SNES232 0x26
207#define SERIO_SEMTECH 0x27
208#define SERIO_LKKBD 0x28
209#define SERIO_ELO 0x29
210#define SERIO_MICROTOUCH 0x30
Rick Kochee479992006-08-05 00:32:18 -0400211#define SERIO_PENMOUNT 0x31
Rick Koch4003dff2006-08-05 00:32:24 -0400212#define SERIO_TOUCHRIGHT 0x32
Rick Koch11ea3172006-08-05 00:32:30 -0400213#define SERIO_TOUCHWIN 0x33
Jean Delvareb9cdad72007-07-12 14:12:31 +0200214#define SERIO_TAOSEVM 0x34
Dmitry Torokhov85f202d2007-07-18 00:37:01 -0400215#define SERIO_FUJITSU 0x35
Martin Kebert3e24e2b2008-03-10 13:40:36 +0100216#define SERIO_ZHENHUA 0x36
Richard Lemon3cadd2d2008-06-26 10:10:41 -0400217#define SERIO_INEXIO 0x37
Dmitry Torokhovab96dde2009-03-07 13:39:22 -0800218#define SERIO_TOUCHIT213 0x38
Jaya Kumar3eb1aa42008-11-19 16:58:50 -0500219#define SERIO_W8001 0x39
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221#endif