1
2
3
4
5
6
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
21extern struct bus_type serio_bus;
22
23struct serio {
24 void *port_data;
25
26 char name[32];
27 char phys[32];
28 char firmware_id[128];
29
30 bool manual_bind;
31
32 struct serio_device_id id;
33
34
35 spinlock_t lock;
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;
44
45 struct list_head child_node;
46 struct list_head children;
47
48 unsigned int depth;
49
50
51
52
53
54 struct serio_driver *drv;
55
56 struct mutex drv_mutex;
57
58 struct device dev;
59
60 struct list_head node;
61
62
63
64
65
66 struct mutex *ps2_cmd_mutex;
67};
68#define to_serio_port(d) container_of(d, struct serio, dev)
69
70struct serio_driver {
71 const char *description;
72
73 const struct serio_device_id *id_table;
74 bool manual_bind;
75
76 void (*write_wakeup)(struct serio *);
77 irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int);
78 int (*connect)(struct serio *, struct serio_driver *drv);
79 int (*reconnect)(struct serio *);
80 int (*fast_reconnect)(struct serio *);
81 void (*disconnect)(struct serio *);
82 void (*cleanup)(struct serio *);
83
84 struct device_driver driver;
85};
86#define to_serio_driver(d) container_of(d, struct serio_driver, driver)
87
88int serio_open(struct serio *serio, struct serio_driver *drv);
89void serio_close(struct serio *serio);
90void serio_rescan(struct serio *serio);
91void serio_reconnect(struct serio *serio);
92irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags);
93
94void __serio_register_port(struct serio *serio, struct module *owner);
95
96
97#define serio_register_port(serio) \
98 __serio_register_port(serio, THIS_MODULE)
99
100void serio_unregister_port(struct serio *serio);
101void serio_unregister_child_port(struct serio *serio);
102
103int __must_check __serio_register_driver(struct serio_driver *drv,
104 struct module *owner, const char *mod_name);
105
106
107#define serio_register_driver(drv) \
108 __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME)
109
110void serio_unregister_driver(struct serio_driver *drv);
111
112
113
114
115
116
117
118
119
120
121#define module_serio_driver(__serio_driver) \
122 module_driver(__serio_driver, serio_register_driver, \
123 serio_unregister_driver)
124
125static inline int serio_write(struct serio *serio, unsigned char data)
126{
127 if (serio->write)
128 return serio->write(serio, data);
129 else
130 return -1;
131}
132
133static inline void serio_drv_write_wakeup(struct serio *serio)
134{
135 if (serio->drv && serio->drv->write_wakeup)
136 serio->drv->write_wakeup(serio);
137}
138
139
140
141
142
143static inline void *serio_get_drvdata(struct serio *serio)
144{
145 return dev_get_drvdata(&serio->dev);
146}
147
148static inline void serio_set_drvdata(struct serio *serio, void *data)
149{
150 dev_set_drvdata(&serio->dev, data);
151}
152
153
154
155
156
157static inline void serio_pause_rx(struct serio *serio)
158{
159 spin_lock_irq(&serio->lock);
160}
161
162static inline void serio_continue_rx(struct serio *serio)
163{
164 spin_unlock_irq(&serio->lock);
165}
166
167#endif
168