Merge tag 'v3.10.105' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / serio.h
1 /*
2 * Copyright (C) 1999-2002 Vojtech Pavlik
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 */
8 #ifndef _SERIO_H
9 #define _SERIO_H
10
11
12 #include <linux/types.h>
13 #include <linux/interrupt.h>
14 #include <linux/list.h>
15 #include <linux/spinlock.h>
16 #include <linux/mutex.h>
17 #include <linux/device.h>
18 #include <linux/mod_devicetable.h>
19 #include <uapi/linux/serio.h>
20
21 struct serio {
22 void *port_data;
23
24 char name[32];
25 char phys[32];
26
27 bool manual_bind;
28
29 struct serio_device_id id;
30
31 /* Protects critical sections from port's interrupt handler */
32 spinlock_t lock;
33
34 int (*write)(struct serio *, unsigned char);
35 int (*open)(struct serio *);
36 void (*close)(struct serio *);
37 int (*start)(struct serio *);
38 void (*stop)(struct serio *);
39
40 struct serio *parent;
41 /* Entry in parent->children list */
42 struct list_head child_node;
43 struct list_head children;
44 /* Level of nesting in serio hierarchy */
45 unsigned int depth;
46
47 /*
48 * serio->drv is accessed from interrupt handlers; when modifying
49 * caller should acquire serio->drv_mutex and serio->lock.
50 */
51 struct serio_driver *drv;
52 /* Protects serio->drv so attributes can pin current driver */
53 struct mutex drv_mutex;
54
55 struct device dev;
56
57 struct list_head node;
58
59 /*
60 * For use by PS/2 layer when several ports share hardware and
61 * may get indigestion when exposed to concurrent access (i8042).
62 */
63 struct mutex *ps2_cmd_mutex;
64 };
65 #define to_serio_port(d) container_of(d, struct serio, dev)
66
67 struct serio_driver {
68 const char *description;
69
70 const struct serio_device_id *id_table;
71 bool manual_bind;
72
73 void (*write_wakeup)(struct serio *);
74 irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int);
75 int (*connect)(struct serio *, struct serio_driver *drv);
76 int (*reconnect)(struct serio *);
77 void (*disconnect)(struct serio *);
78 void (*cleanup)(struct serio *);
79
80 struct device_driver driver;
81 };
82 #define to_serio_driver(d) container_of(d, struct serio_driver, driver)
83
84 int serio_open(struct serio *serio, struct serio_driver *drv);
85 void serio_close(struct serio *serio);
86 void serio_rescan(struct serio *serio);
87 void serio_reconnect(struct serio *serio);
88 irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags);
89
90 void __serio_register_port(struct serio *serio, struct module *owner);
91
92 /* use a define to avoid include chaining to get THIS_MODULE */
93 #define serio_register_port(serio) \
94 __serio_register_port(serio, THIS_MODULE)
95
96 void serio_unregister_port(struct serio *serio);
97 void serio_unregister_child_port(struct serio *serio);
98
99 int __must_check __serio_register_driver(struct serio_driver *drv,
100 struct module *owner, const char *mod_name);
101
102 /* use a define to avoid include chaining to get THIS_MODULE & friends */
103 #define serio_register_driver(drv) \
104 __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME)
105
106 void serio_unregister_driver(struct serio_driver *drv);
107
108 /**
109 * module_serio_driver() - Helper macro for registering a serio driver
110 * @__serio_driver: serio_driver struct
111 *
112 * Helper macro for serio drivers which do not do anything special in
113 * module init/exit. This eliminates a lot of boilerplate. Each module
114 * may only use this macro once, and calling it replaces module_init()
115 * and module_exit().
116 */
117 #define module_serio_driver(__serio_driver) \
118 module_driver(__serio_driver, serio_register_driver, \
119 serio_unregister_driver)
120
121 static inline int serio_write(struct serio *serio, unsigned char data)
122 {
123 if (serio->write)
124 return serio->write(serio, data);
125 else
126 return -1;
127 }
128
129 static inline void serio_drv_write_wakeup(struct serio *serio)
130 {
131 if (serio->drv && serio->drv->write_wakeup)
132 serio->drv->write_wakeup(serio);
133 }
134
135 /*
136 * Use the following functions to manipulate serio's per-port
137 * driver-specific data.
138 */
139 static inline void *serio_get_drvdata(struct serio *serio)
140 {
141 return dev_get_drvdata(&serio->dev);
142 }
143
144 static inline void serio_set_drvdata(struct serio *serio, void *data)
145 {
146 dev_set_drvdata(&serio->dev, data);
147 }
148
149 /*
150 * Use the following functions to protect critical sections in
151 * driver code from port's interrupt handler
152 */
153 static inline void serio_pause_rx(struct serio *serio)
154 {
155 spin_lock_irq(&serio->lock);
156 }
157
158 static inline void serio_continue_rx(struct serio *serio)
159 {
160 spin_unlock_irq(&serio->lock);
161 }
162
163 #endif