Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
422 | giacomo | 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 | |||
12 | #include <asm/io.h> |
||
13 | #include <linux/input.h> |
||
14 | #include <linux/list.h> |
||
15 | |||
16 | struct gameport; |
||
17 | |||
18 | struct gameport { |
||
19 | |||
20 | void *private; /* Private pointer for joystick drivers */ |
||
21 | void *driver; /* Private pointer for gameport drivers */ |
||
22 | char *name; |
||
23 | char *phys; |
||
24 | |||
25 | struct input_id id; |
||
26 | |||
27 | int io; |
||
28 | int speed; |
||
29 | int fuzz; |
||
30 | |||
31 | void (*trigger)(struct gameport *); |
||
32 | unsigned char (*read)(struct gameport *); |
||
33 | int (*cooked_read)(struct gameport *, int *, int *); |
||
34 | int (*calibrate)(struct gameport *, int *, int *); |
||
35 | int (*open)(struct gameport *, int); |
||
36 | void (*close)(struct gameport *); |
||
37 | |||
38 | struct gameport_dev *dev; |
||
39 | |||
40 | struct list_head node; |
||
41 | }; |
||
42 | |||
43 | struct gameport_dev { |
||
44 | |||
45 | void *private; |
||
46 | char *name; |
||
47 | |||
48 | void (*connect)(struct gameport *, struct gameport_dev *dev); |
||
49 | void (*disconnect)(struct gameport *); |
||
50 | |||
51 | struct list_head node; |
||
52 | }; |
||
53 | |||
54 | int gameport_open(struct gameport *gameport, struct gameport_dev *dev, int mode); |
||
55 | void gameport_close(struct gameport *gameport); |
||
56 | void gameport_rescan(struct gameport *gameport); |
||
57 | |||
58 | #if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE) |
||
59 | void gameport_register_port(struct gameport *gameport); |
||
60 | void gameport_unregister_port(struct gameport *gameport); |
||
61 | #else |
||
62 | static inline void gameport_register_port(struct gameport *gameport) { return; } |
||
63 | static inline void gameport_unregister_port(struct gameport *gameport) { return; } |
||
64 | #endif |
||
65 | |||
66 | void gameport_register_device(struct gameport_dev *dev); |
||
67 | void gameport_unregister_device(struct gameport_dev *dev); |
||
68 | |||
69 | #define GAMEPORT_MODE_DISABLED 0 |
||
70 | #define GAMEPORT_MODE_RAW 1 |
||
71 | #define GAMEPORT_MODE_COOKED 2 |
||
72 | |||
73 | #define GAMEPORT_ID_VENDOR_ANALOG 0x0001 |
||
74 | #define GAMEPORT_ID_VENDOR_MADCATZ 0x0002 |
||
75 | #define GAMEPORT_ID_VENDOR_LOGITECH 0x0003 |
||
76 | #define GAMEPORT_ID_VENDOR_CREATIVE 0x0004 |
||
77 | #define GAMEPORT_ID_VENDOR_GENIUS 0x0005 |
||
78 | #define GAMEPORT_ID_VENDOR_INTERACT 0x0006 |
||
79 | #define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007 |
||
80 | #define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008 |
||
81 | #define GAMEPORT_ID_VENDOR_GRAVIS 0x0009 |
||
82 | #define GAMEPORT_ID_VENDOR_GUILLEMOT 0x000a |
||
83 | |||
84 | static __inline__ void gameport_trigger(struct gameport *gameport) |
||
85 | { |
||
86 | if (gameport->trigger) |
||
87 | gameport->trigger(gameport); |
||
88 | else |
||
89 | outb(0xff, gameport->io); |
||
90 | } |
||
91 | |||
92 | static __inline__ unsigned char gameport_read(struct gameport *gameport) |
||
93 | { |
||
94 | if (gameport->read) |
||
95 | return gameport->read(gameport); |
||
96 | else |
||
97 | return inb(gameport->io); |
||
98 | } |
||
99 | |||
100 | static __inline__ int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons) |
||
101 | { |
||
102 | if (gameport->cooked_read) |
||
103 | return gameport->cooked_read(gameport, axes, buttons); |
||
104 | else |
||
105 | return -1; |
||
106 | } |
||
107 | |||
108 | static __inline__ int gameport_calibrate(struct gameport *gameport, int *axes, int *max) |
||
109 | { |
||
110 | if (gameport->calibrate) |
||
111 | return gameport->calibrate(gameport, axes, max); |
||
112 | else |
||
113 | return -1; |
||
114 | } |
||
115 | |||
116 | static __inline__ int gameport_time(struct gameport *gameport, int time) |
||
117 | { |
||
118 | return (time * gameport->speed) / 1000; |
||
119 | } |
||
120 | |||
121 | static __inline__ void wait_ms(unsigned int ms) |
||
122 | { |
||
123 | set_current_state(TASK_UNINTERRUPTIBLE); |
||
124 | schedule_timeout(1 + ms * HZ / 1000); |
||
125 | } |
||
126 | |||
127 | #endif |