* add p cc
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / char / joystick / joy-amiga.c
blob520f262a4f064d5251aaa5d2c6055562c670297e
1 /*
2 * joy-amiga.c Version 1.2
4 * Copyright (c) 1998 Vojtech Pavlik
5 */
7 /*
8 * This is a module for the Linux joystick driver, supporting
9 * microswitch based joystick connected to Amiga joystick port.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * Should you need to contact me, the author, you can do so either by
28 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
29 * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
32 #include <asm/system.h>
33 #include <linux/types.h>
34 #include <linux/errno.h>
35 #include <linux/joystick.h>
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <asm/amigahw.h>
40 static struct js_port* js_am_port __initdata = NULL;
42 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
43 MODULE_PARM(js_am, "1-2i");
45 static int js_am[]={0,0};
48 * js_am_read() reads and Amiga joystick data.
51 static int js_am_read(void *info, int **axes, int **buttons)
53 int data = 0;
55 switch (*(int*)info) {
56 case 0:
57 data = ~custom.joy0dat;
58 buttons[0][0] = (~ciaa.pra >> 6) & 1;
59 break;
61 case 1:
62 data = ~custom.joy1dat;
63 buttons[0][0] = (~ciaa.pra >> 7) & 1;
64 break;
66 default:
67 return -1;
70 axes[0][0] = ((data >> 1) & 1) - ((data >> 9) & 1);
71 data = ~(data ^ (data << 1));
72 axes[0][0] = ((data >> 1) & 1) - ((data >> 9) & 1);
74 return 0;
78 * js_am_open() is a callback from the file open routine.
81 static int js_am_open(struct js_dev *jd)
83 MOD_INC_USE_COUNT;
84 return 0;
88 * js_am_close() is a callback from the file release routine.
91 static int js_am_close(struct js_dev *jd)
93 MOD_DEC_USE_COUNT;
94 return 0;
98 * js_am_init_corr() initializes correction values of
99 * Amiga joysticks.
102 static void __init js_am_init_corr(struct js_corr **corr)
104 int i;
106 for (i = 0; i < 2; i++) {
107 corr[0][i].type = JS_CORR_BROKEN;
108 corr[0][i].prec = 0;
109 corr[0][i].coef[0] = 0;
110 corr[0][i].coef[1] = 0;
111 corr[0][i].coef[2] = (1 << 29);
112 corr[0][i].coef[3] = (1 << 29);
116 #ifndef MODULE
117 void __init js_am_setup(char *str, int *ints)
119 int i;
120 for (i = 0; i <= ints[0] && i < 2; i++) js_am[i] = ints[i+1];
122 #endif
124 #ifdef MODULE
125 int init_module(void)
126 #else
127 int __init js_am_init(void)
128 #endif
130 int i;
132 for (i = 0; i < 2; i++)
133 if (js_am[i]) {
134 js_am_port = js_register_port(js_am_port, &i, 1, sizeof(int), js_am_read);
135 printk(KERN_INFO "js%d: Amiga joystick at joy%ddat\n",
136 js_register_device(js_am_port, 0, 2, 1, "Amiga joystick", js_am_open, js_am_close), i);
137 js_am_init_corr(js_am_port->corr);
139 if (js_am_port) return 0;
141 #ifdef MODULE
142 printk(KERN_WARNING "joy-amiga: no joysticks specified\n");
143 #endif
145 return -ENODEV;
148 #ifdef MODULE
149 void cleanup_module(void)
151 while (js_am_port != NULL) {
152 if (js_am_port->devs[0] != NULL)
153 js_unregister_device(js_am_port->devs[0]);
154 js_am_port = js_unregister_port(js_am_port);
157 #endif