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