Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
serio.h
Go to the documentation of this file.
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 
28 
30 
31  spinlock_t lock; /* protects critical sections from port's interrupt handler */
32 
33  int (*write)(struct serio *, unsigned char);
34  int (*open)(struct serio *);
35  void (*close)(struct serio *);
36  int (*start)(struct serio *);
37  void (*stop)(struct serio *);
38 
39  struct serio *parent;
40  struct list_head child_node; /* Entry in parent->children list */
42  unsigned int depth; /* level of nesting in serio hierarchy */
43 
44  struct serio_driver *drv; /* accessed from interrupt, must be protected by serio->lock and serio->sem */
45  struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */
46 
47  struct device dev;
48 
49  struct list_head node;
50 };
51 #define to_serio_port(d) container_of(d, struct serio, dev)
52 
53 struct serio_driver {
54  const char *description;
55 
56  const struct serio_device_id *id_table;
58 
59  void (*write_wakeup)(struct serio *);
60  irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int);
61  int (*connect)(struct serio *, struct serio_driver *drv);
62  int (*reconnect)(struct serio *);
63  void (*disconnect)(struct serio *);
64  void (*cleanup)(struct serio *);
65 
67 };
68 #define to_serio_driver(d) container_of(d, struct serio_driver, driver)
69 
70 int serio_open(struct serio *serio, struct serio_driver *drv);
71 void serio_close(struct serio *serio);
72 void serio_rescan(struct serio *serio);
73 void serio_reconnect(struct serio *serio);
74 irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags);
75 
76 void __serio_register_port(struct serio *serio, struct module *owner);
77 
78 /* use a define to avoid include chaining to get THIS_MODULE */
79 #define serio_register_port(serio) \
80  __serio_register_port(serio, THIS_MODULE)
81 
82 void serio_unregister_port(struct serio *serio);
84 
86  struct module *owner, const char *mod_name);
87 
88 /* use a define to avoid include chaining to get THIS_MODULE & friends */
89 #define serio_register_driver(drv) \
90  __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME)
91 
92 void serio_unregister_driver(struct serio_driver *drv);
93 
103 #define module_serio_driver(__serio_driver) \
104  module_driver(__serio_driver, serio_register_driver, \
105  serio_unregister_driver)
106 
107 static inline int serio_write(struct serio *serio, unsigned char data)
108 {
109  if (serio->write)
110  return serio->write(serio, data);
111  else
112  return -1;
113 }
114 
115 static inline void serio_drv_write_wakeup(struct serio *serio)
116 {
117  if (serio->drv && serio->drv->write_wakeup)
118  serio->drv->write_wakeup(serio);
119 }
120 
121 /*
122  * Use the following functions to manipulate serio's per-port
123  * driver-specific data.
124  */
125 static inline void *serio_get_drvdata(struct serio *serio)
126 {
127  return dev_get_drvdata(&serio->dev);
128 }
129 
130 static inline void serio_set_drvdata(struct serio *serio, void *data)
131 {
132  dev_set_drvdata(&serio->dev, data);
133 }
134 
135 /*
136  * Use the following functions to protect critical sections in
137  * driver code from port's interrupt handler
138  */
139 static inline void serio_pause_rx(struct serio *serio)
140 {
141  spin_lock_irq(&serio->lock);
142 }
143 
144 static inline void serio_continue_rx(struct serio *serio)
145 {
146  spin_unlock_irq(&serio->lock);
147 }
148 
149 #endif