]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/linux/gameport.h
mm: clean up mm_counter
[mirror_ubuntu-zesty-kernel.git] / include / linux / gameport.h
CommitLineData
1da177e4
LT
1#ifndef _GAMEPORT_H
2#define _GAMEPORT_H
3
4/*
5 * Copyright (c) 1999-2002 Vojtech Pavlik
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 */
11
25478bb2 12#ifdef __KERNEL__
1da177e4 13#include <asm/io.h>
7e044e05 14#include <linux/types.h>
1da177e4 15#include <linux/list.h>
286295eb 16#include <linux/mutex.h>
1da177e4 17#include <linux/device.h>
4e57b681 18#include <linux/timer.h>
1da177e4
LT
19
20struct gameport {
21
22 void *port_data; /* Private pointer for gameport drivers */
23 char name[32];
24 char phys[32];
25
26 int io;
27 int speed;
28 int fuzz;
29
30 void (*trigger)(struct gameport *);
31 unsigned char (*read)(struct gameport *);
32 int (*cooked_read)(struct gameport *, int *, int *);
33 int (*calibrate)(struct gameport *, int *, int *);
34 int (*open)(struct gameport *, int);
35 void (*close)(struct gameport *);
36
37 struct timer_list poll_timer;
38 unsigned int poll_interval; /* in msecs */
39 spinlock_t timer_lock;
40 unsigned int poll_cnt;
41 void (*poll_handler)(struct gameport *);
42
43 struct gameport *parent, *child;
44
45 struct gameport_driver *drv;
286295eb 46 struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */
1da177e4
LT
47
48 struct device dev;
1da177e4
LT
49
50 struct list_head node;
51};
52#define to_gameport_port(d) container_of(d, struct gameport, dev)
53
54struct gameport_driver {
55
56 void *private;
57 char *description;
58
59 int (*connect)(struct gameport *, struct gameport_driver *drv);
60 int (*reconnect)(struct gameport *);
61 void (*disconnect)(struct gameport *);
62
63 struct device_driver driver;
64
7e044e05 65 bool ignore;
1da177e4
LT
66};
67#define to_gameport_driver(d) container_of(d, struct gameport_driver, driver)
68
69int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode);
70void gameport_close(struct gameport *gameport);
1da177e4 71
668d1e60
AB
72#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
73
1da177e4
LT
74void __gameport_register_port(struct gameport *gameport, struct module *owner);
75static inline void gameport_register_port(struct gameport *gameport)
76{
77 __gameport_register_port(gameport, THIS_MODULE);
78}
79
80void gameport_unregister_port(struct gameport *gameport);
81
668d1e60
AB
82void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
83 __attribute__ ((format (printf, 2, 3)));
84
85#else
86
87static inline void gameport_register_port(struct gameport *gameport)
88{
89 return;
90}
91
92static inline void gameport_unregister_port(struct gameport *gameport)
93{
94 return;
95}
96
97static inline void gameport_set_phys(struct gameport *gameport,
98 const char *fmt, ...)
99{
100 return;
101}
102
103#endif
104
1da177e4
LT
105static inline struct gameport *gameport_allocate_port(void)
106{
cd861280 107 struct gameport *gameport = kzalloc(sizeof(struct gameport), GFP_KERNEL);
1da177e4
LT
108
109 return gameport;
110}
111
112static inline void gameport_free_port(struct gameport *gameport)
113{
114 kfree(gameport);
115}
116
117static inline void gameport_set_name(struct gameport *gameport, const char *name)
118{
119 strlcpy(gameport->name, name, sizeof(gameport->name));
120}
121
1da177e4 122/*
0b28002f 123 * Use the following functions to manipulate gameport's per-port
1da177e4
LT
124 * driver-specific data.
125 */
126static inline void *gameport_get_drvdata(struct gameport *gameport)
127{
128 return dev_get_drvdata(&gameport->dev);
129}
130
131static inline void gameport_set_drvdata(struct gameport *gameport, void *data)
132{
133 dev_set_drvdata(&gameport->dev, data);
134}
135
136/*
0b28002f 137 * Use the following functions to pin gameport's driver in process context
1da177e4
LT
138 */
139static inline int gameport_pin_driver(struct gameport *gameport)
140{
286295eb 141 return mutex_lock_interruptible(&gameport->drv_mutex);
1da177e4
LT
142}
143
144static inline void gameport_unpin_driver(struct gameport *gameport)
145{
286295eb 146 mutex_unlock(&gameport->drv_mutex);
1da177e4
LT
147}
148
6902c0be
DT
149int __gameport_register_driver(struct gameport_driver *drv,
150 struct module *owner, const char *mod_name);
8c4b3c29 151static inline int __must_check gameport_register_driver(struct gameport_driver *drv)
1da177e4 152{
6902c0be 153 return __gameport_register_driver(drv, THIS_MODULE, KBUILD_MODNAME);
1da177e4
LT
154}
155
156void gameport_unregister_driver(struct gameport_driver *drv);
157
25478bb2
DW
158#endif /* __KERNEL__ */
159
1da177e4
LT
160#define GAMEPORT_MODE_DISABLED 0
161#define GAMEPORT_MODE_RAW 1
162#define GAMEPORT_MODE_COOKED 2
163
164#define GAMEPORT_ID_VENDOR_ANALOG 0x0001
165#define GAMEPORT_ID_VENDOR_MADCATZ 0x0002
166#define GAMEPORT_ID_VENDOR_LOGITECH 0x0003
167#define GAMEPORT_ID_VENDOR_CREATIVE 0x0004
168#define GAMEPORT_ID_VENDOR_GENIUS 0x0005
169#define GAMEPORT_ID_VENDOR_INTERACT 0x0006
170#define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007
171#define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
172#define GAMEPORT_ID_VENDOR_GRAVIS 0x0009
173#define GAMEPORT_ID_VENDOR_GUILLEMOT 0x000a
174
25478bb2
DW
175#ifdef __KERNEL__
176
1da177e4
LT
177static inline void gameport_trigger(struct gameport *gameport)
178{
179 if (gameport->trigger)
180 gameport->trigger(gameport);
181 else
182 outb(0xff, gameport->io);
183}
184
185static inline unsigned char gameport_read(struct gameport *gameport)
186{
187 if (gameport->read)
188 return gameport->read(gameport);
189 else
190 return inb(gameport->io);
191}
192
193static inline int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
194{
195 if (gameport->cooked_read)
196 return gameport->cooked_read(gameport, axes, buttons);
197 else
198 return -1;
199}
200
201static inline int gameport_calibrate(struct gameport *gameport, int *axes, int *max)
202{
203 if (gameport->calibrate)
204 return gameport->calibrate(gameport, axes, max);
205 else
206 return -1;
207}
208
209static inline int gameport_time(struct gameport *gameport, int time)
210{
211 return (time * gameport->speed) / 1000;
212}
213
214static inline void gameport_set_poll_handler(struct gameport *gameport, void (*handler)(struct gameport *))
215{
216 gameport->poll_handler = handler;
217}
218
219static inline void gameport_set_poll_interval(struct gameport *gameport, unsigned int msecs)
220{
221 gameport->poll_interval = msecs;
222}
223
224void gameport_start_polling(struct gameport *gameport);
225void gameport_stop_polling(struct gameport *gameport);
226
25478bb2 227#endif /* __KERNEL__ */
1da177e4 228#endif