blob: b5552568178d9c459412bac9f10671b822ca2af4 [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34 struct serio_device_id id;
35
36 spinlock_t lock; /* protects critical sections from port's interrupt handler */
37
38 int (*write)(struct serio *, unsigned char);
39 int (*open)(struct serio *);
40 void (*close)(struct serio *);
41 int (*start)(struct serio *);
42 void (*stop)(struct serio *);
43
44 struct serio *parent, *child;
Jiri Kosina88aa0102006-10-11 01:45:31 -040045 unsigned int depth; /* level of nesting in serio hierarchy */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47 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 -050048 struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 struct device dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 struct list_head node;
53};
54#define to_serio_port(d) container_of(d, struct serio, dev)
55
56struct serio_driver {
57 void *private;
58 char *description;
59
60 struct serio_device_id *id_table;
Dmitry Torokhov7e044e02009-05-09 16:08:05 -070061 bool manual_bind;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63 void (*write_wakeup)(struct serio *);
David Howells7d12e782006-10-05 14:55:46 +010064 irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 int (*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#define to_serio_driver(d) container_of(d, struct serio_driver, driver)
73
74int serio_open(struct serio *serio, struct serio_driver *drv);
75void serio_close(struct serio *serio);
76void serio_rescan(struct serio *serio);
77void serio_reconnect(struct serio *serio);
David Howells7d12e782006-10-05 14:55:46 +010078irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80void __serio_register_port(struct serio *serio, struct module *owner);
81static inline void serio_register_port(struct serio *serio)
82{
83 __serio_register_port(serio, THIS_MODULE);
84}
85
86void serio_unregister_port(struct serio *serio);
Dmitry Torokhovdbf4ccd2005-06-01 02:40:01 -050087void serio_unregister_child_port(struct serio *serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Greg Kroah-Hartman4b315622007-01-15 11:50:02 -080089int __serio_register_driver(struct serio_driver *drv, struct module *owner, const char *mod_name);
Dmitry Torokhova822bea2008-06-06 01:34:00 -040090static inline int __must_check serio_register_driver(struct serio_driver *drv)
Greg Kroah-Hartman4b315622007-01-15 11:50:02 -080091{
92 return __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME);
93}
Linus Torvalds1da177e2005-04-16 15:20:36 -070094void serio_unregister_driver(struct serio_driver *drv);
95
96static inline int serio_write(struct serio *serio, unsigned char data)
97{
98 if (serio->write)
99 return serio->write(serio, data);
100 else
101 return -1;
102}
103
104static inline void serio_drv_write_wakeup(struct serio *serio)
105{
106 if (serio->drv && serio->drv->write_wakeup)
107 serio->drv->write_wakeup(serio);
108}
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/*
Akinobu Mita0b280022006-03-26 01:38:58 -0800111 * Use the following functions to manipulate serio's per-port
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 * driver-specific data.
113 */
114static inline void *serio_get_drvdata(struct serio *serio)
115{
116 return dev_get_drvdata(&serio->dev);
117}
118
119static inline void serio_set_drvdata(struct serio *serio, void *data)
120{
121 dev_set_drvdata(&serio->dev, data);
122}
123
124/*
Akinobu Mita0b280022006-03-26 01:38:58 -0800125 * Use the following functions to protect critical sections in
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 * driver code from port's interrupt handler
127 */
128static inline void serio_pause_rx(struct serio *serio)
129{
130 spin_lock_irq(&serio->lock);
131}
132
133static inline void serio_continue_rx(struct serio *serio)
134{
135 spin_unlock_irq(&serio->lock);
136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#endif
139
140/*
141 * bit masks for use in "interrupt" flags (3rd argument)
142 */
143#define SERIO_TIMEOUT 1
144#define SERIO_PARITY 2
145#define SERIO_FRAME 4
146
147/*
148 * Serio types
149 */
150#define SERIO_XT 0x00
151#define SERIO_8042 0x01
152#define SERIO_RS232 0x02
153#define SERIO_HIL_MLC 0x03
154#define SERIO_PS_PSTHRU 0x05
155#define SERIO_8042_XL 0x06
156
157/*
Niels de Vosf3d1eb12008-07-08 10:30:27 -0400158 * Serio protocols
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 */
160#define SERIO_UNKNOWN 0x00
161#define SERIO_MSC 0x01
162#define SERIO_SUN 0x02
163#define SERIO_MS 0x03
164#define SERIO_MP 0x04
165#define SERIO_MZ 0x05
166#define SERIO_MZP 0x06
167#define SERIO_MZPP 0x07
168#define SERIO_VSXXXAA 0x08
169#define SERIO_SUNKBD 0x10
170#define SERIO_WARRIOR 0x18
171#define SERIO_SPACEORB 0x19
172#define SERIO_MAGELLAN 0x1a
173#define SERIO_SPACEBALL 0x1b
174#define SERIO_GUNZE 0x1c
175#define SERIO_IFORCE 0x1d
176#define SERIO_STINGER 0x1e
177#define SERIO_NEWTON 0x1f
178#define SERIO_STOWAWAY 0x20
179#define SERIO_H3600 0x21
180#define SERIO_PS2SER 0x22
181#define SERIO_TWIDKBD 0x23
182#define SERIO_TWIDJOY 0x24
183#define SERIO_HIL 0x25
184#define SERIO_SNES232 0x26
185#define SERIO_SEMTECH 0x27
186#define SERIO_LKKBD 0x28
187#define SERIO_ELO 0x29
188#define SERIO_MICROTOUCH 0x30
Rick Kochee479992006-08-05 00:32:18 -0400189#define SERIO_PENMOUNT 0x31
Rick Koch4003dff2006-08-05 00:32:24 -0400190#define SERIO_TOUCHRIGHT 0x32
Rick Koch11ea3172006-08-05 00:32:30 -0400191#define SERIO_TOUCHWIN 0x33
Jean Delvareb9cdad72007-07-12 14:12:31 +0200192#define SERIO_TAOSEVM 0x34
Dmitry Torokhov85f202d2007-07-18 00:37:01 -0400193#define SERIO_FUJITSU 0x35
Martin Kebert3e24e2b2008-03-10 13:40:36 +0100194#define SERIO_ZHENHUA 0x36
Richard Lemon3cadd2d2008-06-26 10:10:41 -0400195#define SERIO_INEXIO 0x37
Dmitry Torokhovab96dde2009-03-07 13:39:22 -0800196#define SERIO_TOUCHIT213 0x38
Jaya Kumar3eb1aa42008-11-19 16:58:50 -0500197#define SERIO_W8001 0x39
Tias Gunsa5f523b2009-10-25 12:13:58 -0700198#define SERIO_DYNAPRO 0x3a
Adam Bennett422dee52010-04-12 19:54:38 -0700199#define SERIO_HAMPSHIRE 0x3b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201#endif