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