~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/gameport.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-only */
  2 /*
  3  *  Copyright (c) 1999-2002 Vojtech Pavlik
  4  */
  5 #ifndef _GAMEPORT_H
  6 #define _GAMEPORT_H
  7 
  8 #include <linux/types.h>
  9 #include <linux/list.h>
 10 #include <linux/mutex.h>
 11 #include <linux/device.h>
 12 #include <linux/timer.h>
 13 #include <linux/slab.h>
 14 #include <uapi/linux/gameport.h>
 15 
 16 struct gameport {
 17 
 18         void *port_data;        /* Private pointer for gameport drivers */
 19         char name[32];
 20         char phys[32];
 21 
 22         int io;
 23         int speed;
 24         int fuzz;
 25 
 26         void (*trigger)(struct gameport *);
 27         unsigned char (*read)(struct gameport *);
 28         int (*cooked_read)(struct gameport *, int *, int *);
 29         int (*calibrate)(struct gameport *, int *, int *);
 30         int (*open)(struct gameport *, int);
 31         void (*close)(struct gameport *);
 32 
 33         struct timer_list poll_timer;
 34         unsigned int poll_interval;     /* in msecs */
 35         spinlock_t timer_lock;
 36         unsigned int poll_cnt;
 37         void (*poll_handler)(struct gameport *);
 38 
 39         struct gameport *parent, *child;
 40 
 41         struct gameport_driver *drv;
 42         struct mutex drv_mutex;         /* protects serio->drv so attributes can pin driver */
 43 
 44         struct device dev;
 45 
 46         struct list_head node;
 47 };
 48 #define to_gameport_port(d)     container_of(d, struct gameport, dev)
 49 
 50 struct gameport_driver {
 51         const char *description;
 52 
 53         int (*connect)(struct gameport *, struct gameport_driver *drv);
 54         int (*reconnect)(struct gameport *);
 55         void (*disconnect)(struct gameport *);
 56 
 57         struct device_driver driver;
 58 
 59         bool ignore;
 60 };
 61 #define to_gameport_driver(d)   container_of_const(d, struct gameport_driver, driver)
 62 
 63 int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode);
 64 void gameport_close(struct gameport *gameport);
 65 
 66 #if IS_REACHABLE(CONFIG_GAMEPORT)
 67 
 68 void __gameport_register_port(struct gameport *gameport, struct module *owner);
 69 /* use a define to avoid include chaining to get THIS_MODULE */
 70 #define gameport_register_port(gameport) \
 71         __gameport_register_port(gameport, THIS_MODULE)
 72 
 73 void gameport_unregister_port(struct gameport *gameport);
 74 
 75 __printf(2, 3)
 76 void gameport_set_phys(struct gameport *gameport, const char *fmt, ...);
 77 
 78 #else
 79 
 80 static inline void gameport_register_port(struct gameport *gameport)
 81 {
 82         return;
 83 }
 84 
 85 static inline void gameport_unregister_port(struct gameport *gameport)
 86 {
 87         return;
 88 }
 89 
 90 static inline __printf(2, 3)
 91 void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
 92 {
 93         return;
 94 }
 95 
 96 #endif
 97 
 98 static inline struct gameport *gameport_allocate_port(void)
 99 {
100         struct gameport *gameport = kzalloc(sizeof(struct gameport), GFP_KERNEL);
101 
102         return gameport;
103 }
104 
105 static inline void gameport_free_port(struct gameport *gameport)
106 {
107         kfree(gameport);
108 }
109 
110 static inline void gameport_set_name(struct gameport *gameport, const char *name)
111 {
112         strscpy(gameport->name, name, sizeof(gameport->name));
113 }
114 
115 /*
116  * Use the following functions to manipulate gameport's per-port
117  * driver-specific data.
118  */
119 static inline void *gameport_get_drvdata(struct gameport *gameport)
120 {
121         return dev_get_drvdata(&gameport->dev);
122 }
123 
124 static inline void gameport_set_drvdata(struct gameport *gameport, void *data)
125 {
126         dev_set_drvdata(&gameport->dev, data);
127 }
128 
129 /*
130  * Use the following functions to pin gameport's driver in process context
131  */
132 static inline int gameport_pin_driver(struct gameport *gameport)
133 {
134         return mutex_lock_interruptible(&gameport->drv_mutex);
135 }
136 
137 static inline void gameport_unpin_driver(struct gameport *gameport)
138 {
139         mutex_unlock(&gameport->drv_mutex);
140 }
141 
142 int __must_check __gameport_register_driver(struct gameport_driver *drv,
143                                 struct module *owner, const char *mod_name);
144 
145 /* use a define to avoid include chaining to get THIS_MODULE & friends */
146 #define gameport_register_driver(drv) \
147         __gameport_register_driver(drv, THIS_MODULE, KBUILD_MODNAME)
148 
149 void gameport_unregister_driver(struct gameport_driver *drv);
150 
151 /**
152  * module_gameport_driver() - Helper macro for registering a gameport driver
153  * @__gameport_driver: gameport_driver struct
154  *
155  * Helper macro for gameport drivers which do not do anything special in
156  * module init/exit. This eliminates a lot of boilerplate. Each module may
157  * only use this macro once, and calling it replaces module_init() and
158  * module_exit().
159  */
160 #define module_gameport_driver(__gameport_driver) \
161         module_driver(__gameport_driver, gameport_register_driver, \
162                        gameport_unregister_driver)
163 
164 
165 static inline void gameport_trigger(struct gameport *gameport)
166 {
167         gameport->trigger(gameport);
168 }
169 
170 static inline unsigned char gameport_read(struct gameport *gameport)
171 {
172         return gameport->read(gameport);
173 }
174 
175 static inline int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
176 {
177         if (gameport->cooked_read)
178                 return gameport->cooked_read(gameport, axes, buttons);
179         else
180                 return -1;
181 }
182 
183 static inline int gameport_calibrate(struct gameport *gameport, int *axes, int *max)
184 {
185         if (gameport->calibrate)
186                 return gameport->calibrate(gameport, axes, max);
187         else
188                 return -1;
189 }
190 
191 static inline int gameport_time(struct gameport *gameport, int time)
192 {
193         return (time * gameport->speed) / 1000;
194 }
195 
196 static inline void gameport_set_poll_handler(struct gameport *gameport, void (*handler)(struct gameport *))
197 {
198         gameport->poll_handler = handler;
199 }
200 
201 static inline void gameport_set_poll_interval(struct gameport *gameport, unsigned int msecs)
202 {
203         gameport->poll_interval = msecs;
204 }
205 
206 void gameport_start_polling(struct gameport *gameport);
207 void gameport_stop_polling(struct gameport *gameport);
208 
209 #endif
210 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php