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

TOMOYO Linux Cross Reference
Linux/Documentation/input/gameport-programming.rst

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 ] ~

Diff markup

Differences between /Documentation/input/gameport-programming.rst (Version linux-6.11.5) and /Documentation/input/gameport-programming.rst (Version linux-5.18.19)


  1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~                        1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2 Programming gameport drivers                        2 Programming gameport drivers
  3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~                        3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4                                                     4 
  5 A basic classic gameport                            5 A basic classic gameport
  6 ~~~~~~~~~~~~~~~~~~~~~~~~                            6 ~~~~~~~~~~~~~~~~~~~~~~~~
  7                                                     7 
  8 If the gameport doesn't provide more than the       8 If the gameport doesn't provide more than the inb()/outb() functionality,
  9 the code needed to register it with the joysti      9 the code needed to register it with the joystick drivers is simple::
 10                                                    10 
 11         struct gameport gameport;                  11         struct gameport gameport;
 12                                                    12 
 13         gameport.io = MY_IO_ADDRESS;               13         gameport.io = MY_IO_ADDRESS;
 14         gameport_register_port(&gameport);         14         gameport_register_port(&gameport);
 15                                                    15 
 16 Make sure struct gameport is initialized to 0      16 Make sure struct gameport is initialized to 0 in all other fields. The
 17 gameport generic code will take care of the re     17 gameport generic code will take care of the rest.
 18                                                    18 
 19 If your hardware supports more than one io add     19 If your hardware supports more than one io address, and your driver can
 20 choose which one to program the hardware to, s     20 choose which one to program the hardware to, starting from the more exotic
 21 addresses is preferred, because the likelihood     21 addresses is preferred, because the likelihood of clashing with the standard
 22 0x201 address is smaller.                          22 0x201 address is smaller.
 23                                                    23 
 24 E.g. if your driver supports addresses 0x200,      24 E.g. if your driver supports addresses 0x200, 0x208, 0x210 and 0x218, then
 25 0x218 would be the address of first choice.        25 0x218 would be the address of first choice.
 26                                                    26 
 27 If your hardware supports a gameport address t     27 If your hardware supports a gameport address that is not mapped to ISA io
 28 space (is above 0x1000), use that one, and don     28 space (is above 0x1000), use that one, and don't map the ISA mirror.
 29                                                    29 
 30 Also, always request_region() on the whole io      30 Also, always request_region() on the whole io space occupied by the
 31 gameport. Although only one ioport is really u     31 gameport. Although only one ioport is really used, the gameport usually
 32 occupies from one to sixteen addresses in the      32 occupies from one to sixteen addresses in the io space.
 33                                                    33 
 34 Please also consider enabling the gameport on      34 Please also consider enabling the gameport on the card in the ->open()
 35 callback if the io is mapped to ISA space - th     35 callback if the io is mapped to ISA space - this way it'll occupy the io
 36 space only when something really is using it.      36 space only when something really is using it. Disable it again in the
 37 ->close() callback. You also can select the io     37 ->close() callback. You also can select the io address in the ->open()
 38 callback, so that it doesn't fail if some of t     38 callback, so that it doesn't fail if some of the possible addresses are
 39 already occupied by other gameports.               39 already occupied by other gameports.
 40                                                    40 
 41 Memory mapped gameport                             41 Memory mapped gameport
 42 ~~~~~~~~~~~~~~~~~~~~~~                             42 ~~~~~~~~~~~~~~~~~~~~~~
 43                                                    43 
 44 When a gameport can be accessed through MMIO,      44 When a gameport can be accessed through MMIO, this way is preferred, because
 45 it is faster, allowing more reads per second.      45 it is faster, allowing more reads per second. Registering such a gameport
 46 isn't as easy as a basic IO one, but not so mu     46 isn't as easy as a basic IO one, but not so much complex::
 47                                                    47 
 48         struct gameport gameport;                  48         struct gameport gameport;
 49                                                    49 
 50         void my_trigger(struct gameport *gamep     50         void my_trigger(struct gameport *gameport)
 51         {                                          51         {
 52                 my_mmio = 0xff;                    52                 my_mmio = 0xff;
 53         }                                          53         }
 54                                                    54 
 55         unsigned char my_read(struct gameport      55         unsigned char my_read(struct gameport *gameport)
 56         {                                          56         {
 57                 return my_mmio;                    57                 return my_mmio;
 58         }                                          58         }
 59                                                    59 
 60         gameport.read = my_read;                   60         gameport.read = my_read;
 61         gameport.trigger = my_trigger;             61         gameport.trigger = my_trigger;
 62         gameport_register_port(&gameport);         62         gameport_register_port(&gameport);
 63                                                    63 
 64 .. _gameport_pgm_cooked_mode:                      64 .. _gameport_pgm_cooked_mode:
 65                                                    65 
 66 Cooked mode gameport                               66 Cooked mode gameport
 67 ~~~~~~~~~~~~~~~~~~~~                               67 ~~~~~~~~~~~~~~~~~~~~
 68                                                    68 
 69 There are gameports that can report the axis v     69 There are gameports that can report the axis values as numbers, that means
 70 the driver doesn't have to measure them the ol     70 the driver doesn't have to measure them the old way - an ADC is built into
 71 the gameport. To register a cooked gameport::      71 the gameport. To register a cooked gameport::
 72                                                    72 
 73         struct gameport gameport;                  73         struct gameport gameport;
 74                                                    74 
 75         int my_cooked_read(struct gameport *ga     75         int my_cooked_read(struct gameport *gameport, int *axes, int *buttons)
 76         {                                          76         {
 77                 int i;                             77                 int i;
 78                                                    78 
 79                 for (i = 0; i < 4; i++)            79                 for (i = 0; i < 4; i++)
 80                         axes[i] = my_mmio[i];      80                         axes[i] = my_mmio[i];
 81                 buttons[0] = my_mmio[4];           81                 buttons[0] = my_mmio[4];
 82         }                                          82         }
 83                                                    83 
 84         int my_open(struct gameport *gameport,     84         int my_open(struct gameport *gameport, int mode)
 85         {                                          85         {
 86                 return -(mode != GAMEPORT_MODE     86                 return -(mode != GAMEPORT_MODE_COOKED);
 87         }                                          87         }
 88                                                    88 
 89         gameport.cooked_read = my_cooked_read;     89         gameport.cooked_read = my_cooked_read;
 90         gameport.open = my_open;                   90         gameport.open = my_open;
 91         gameport.fuzz = 8;                         91         gameport.fuzz = 8;
 92         gameport_register_port(&gameport);         92         gameport_register_port(&gameport);
 93                                                    93 
 94 The only confusing thing here is the fuzz valu     94 The only confusing thing here is the fuzz value. Best determined by
 95 experimentation, it is the amount of noise in      95 experimentation, it is the amount of noise in the ADC data. Perfect
 96 gameports can set this to zero, most common ha     96 gameports can set this to zero, most common have fuzz between 8 and 32.
 97 See analog.c and input.c for handling of fuzz      97 See analog.c and input.c for handling of fuzz - the fuzz value determines
 98 the size of a gaussian filter window that is u     98 the size of a gaussian filter window that is used to eliminate the noise
 99 in the data.                                       99 in the data.
100                                                   100 
101 More complex gameports                            101 More complex gameports
102 ~~~~~~~~~~~~~~~~~~~~~~                            102 ~~~~~~~~~~~~~~~~~~~~~~
103                                                   103 
104 Gameports can support both raw and cooked mode    104 Gameports can support both raw and cooked modes. In that case combine either
105 examples 1+2 or 1+3. Gameports can support int    105 examples 1+2 or 1+3. Gameports can support internal calibration - see below,
106 and also lightning.c and analog.c on how that     106 and also lightning.c and analog.c on how that works. If your driver supports
107 more than one gameport instance simultaneously    107 more than one gameport instance simultaneously, use the ->private member of
108 the gameport struct to point to your data.        108 the gameport struct to point to your data.
109                                                   109 
110 Unregistering a gameport                          110 Unregistering a gameport
111 ~~~~~~~~~~~~~~~~~~~~~~~~                          111 ~~~~~~~~~~~~~~~~~~~~~~~~
112                                                   112 
113 Simple::                                          113 Simple::
114                                                   114 
115     gameport_unregister_port(&gameport);          115     gameport_unregister_port(&gameport);
116                                                   116 
117 The gameport structure                            117 The gameport structure
118 ~~~~~~~~~~~~~~~~~~~~~~                            118 ~~~~~~~~~~~~~~~~~~~~~~
119                                                   119 
120 ::                                                120 ::
121                                                   121 
122     struct gameport {                             122     struct gameport {
123                                                   123 
124         void *port_data;                          124         void *port_data;
125                                                   125 
126 A private pointer for free use in the gameport    126 A private pointer for free use in the gameport driver. (Not the joystick
127 driver!)                                          127 driver!)
128                                                   128 
129 ::                                                129 ::
130                                                   130 
131         char name[32];                            131         char name[32];
132                                                   132 
133 Driver's name as set by driver calling gamepor    133 Driver's name as set by driver calling gameport_set_name(). Informational
134 purpose only.                                     134 purpose only.
135                                                   135 
136 ::                                                136 ::
137                                                   137 
138         char phys[32];                            138         char phys[32];
139                                                   139 
140 gameport's physical name/description as set by    140 gameport's physical name/description as set by driver calling gameport_set_phys().
141 Informational purpose only.                       141 Informational purpose only.
142                                                   142 
143 ::                                                143 ::
144                                                   144 
145         int io;                                   145         int io;
146                                                   146 
147 I/O address for use with raw mode. You have to    147 I/O address for use with raw mode. You have to either set this, or ->read()
148 to some value if your gameport supports raw mo    148 to some value if your gameport supports raw mode.
149                                                   149 
150 ::                                                150 ::
151                                                   151 
152         int speed;                                152         int speed;
153                                                   153 
154 Raw mode speed of the gameport reads in thousa    154 Raw mode speed of the gameport reads in thousands of reads per second.
155                                                   155 
156 ::                                                156 ::
157                                                   157 
158         int fuzz;                                 158         int fuzz;
159                                                   159 
160 If the gameport supports cooked mode, this sho    160 If the gameport supports cooked mode, this should be set to a value that
161 represents the amount of noise in the data. Se    161 represents the amount of noise in the data. See
162 :ref:`gameport_pgm_cooked_mode`.                  162 :ref:`gameport_pgm_cooked_mode`.
163                                                   163 
164 ::                                                164 ::
165                                                   165 
166         void (*trigger)(struct gameport *);       166         void (*trigger)(struct gameport *);
167                                                   167 
168 Trigger. This function should trigger the ns55    168 Trigger. This function should trigger the ns558 oneshots. If set to NULL,
169 outb(0xff, io) will be used.                      169 outb(0xff, io) will be used.
170                                                   170 
171 ::                                                171 ::
172                                                   172 
173         unsigned char (*read)(struct gameport     173         unsigned char (*read)(struct gameport *);
174                                                   174 
175 Read the buttons and ns558 oneshot bits. If se    175 Read the buttons and ns558 oneshot bits. If set to NULL, inb(io) will be
176 used instead.                                     176 used instead.
177                                                   177 
178 ::                                                178 ::
179                                                   179 
180         int (*cooked_read)(struct gameport *,     180         int (*cooked_read)(struct gameport *, int *axes, int *buttons);
181                                                   181 
182 If the gameport supports cooked mode, it shoul    182 If the gameport supports cooked mode, it should point this to its cooked
183 read function. It should fill axes[0..3] with     183 read function. It should fill axes[0..3] with four values of the joystick axes
184 and buttons[0] with four bits representing the    184 and buttons[0] with four bits representing the buttons.
185                                                   185 
186 ::                                                186 ::
187                                                   187 
188         int (*calibrate)(struct gameport *, in    188         int (*calibrate)(struct gameport *, int *axes, int *max);
189                                                   189 
190 Function for calibrating the ADC hardware. Whe    190 Function for calibrating the ADC hardware. When called, axes[0..3] should be
191 pre-filled by cooked data by the caller, max[0    191 pre-filled by cooked data by the caller, max[0..3] should be pre-filled with
192 expected maximums for each axis. The calibrate    192 expected maximums for each axis. The calibrate() function should set the
193 sensitivity of the ADC hardware so that the ma    193 sensitivity of the ADC hardware so that the maximums fit in its range and
194 recompute the axes[] values to match the new s    194 recompute the axes[] values to match the new sensitivity or re-read them from
195 the hardware so that they give valid values.      195 the hardware so that they give valid values.
196                                                   196 
197 ::                                                197 ::
198                                                   198 
199         int (*open)(struct gameport *, int mod    199         int (*open)(struct gameport *, int mode);
200                                                   200 
201 Open() serves two purposes. First a driver eit    201 Open() serves two purposes. First a driver either opens the port in raw or
202 in cooked mode, the open() callback can decide    202 in cooked mode, the open() callback can decide which modes are supported.
203 Second, resource allocation can happen here. T    203 Second, resource allocation can happen here. The port can also be enabled
204 here. Prior to this call, other fields of the     204 here. Prior to this call, other fields of the gameport struct (namely the io
205 member) need not to be valid.                     205 member) need not to be valid.
206                                                   206 
207 ::                                                207 ::
208                                                   208 
209         void (*close)(struct gameport *);         209         void (*close)(struct gameport *);
210                                                   210 
211 Close() should free the resources allocated by    211 Close() should free the resources allocated by open, possibly disabling the
212 gameport.                                         212 gameport.
213                                                   213 
214 ::                                                214 ::
215                                                   215 
216         struct timer_list poll_timer;             216         struct timer_list poll_timer;
217         unsigned int poll_interval;     /* in     217         unsigned int poll_interval;     /* in msecs */
218         spinlock_t timer_lock;                    218         spinlock_t timer_lock;
219         unsigned int poll_cnt;                    219         unsigned int poll_cnt;
220         void (*poll_handler)(struct gameport *    220         void (*poll_handler)(struct gameport *);
221         struct gameport *parent, *child;          221         struct gameport *parent, *child;
222         struct gameport_driver *drv;              222         struct gameport_driver *drv;
223         struct mutex drv_mutex;         /* pro    223         struct mutex drv_mutex;         /* protects serio->drv so attributes can pin driver */
224         struct device dev;                        224         struct device dev;
225         struct list_head node;                    225         struct list_head node;
226                                                   226 
227 For internal use by the gameport layer.           227 For internal use by the gameport layer.
228                                                   228 
229 ::                                                229 ::
230                                                   230 
231     };                                            231     };
232                                                   232 
233 Enjoy!                                            233 Enjoy!
                                                      

~ [ 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