aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/joystick/cobra.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/joystick/cobra.c')
-rw-r--r--drivers/input/joystick/cobra.c66
1 files changed, 37 insertions, 29 deletions
diff --git a/drivers/input/joystick/cobra.c b/drivers/input/joystick/cobra.c
index 0b2e9fa26579..9a3dfc724a41 100644
--- a/drivers/input/joystick/cobra.c
+++ b/drivers/input/joystick/cobra.c
@@ -44,13 +44,11 @@ MODULE_LICENSE("GPL");
44#define COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */ 44#define COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */
45#define COBRA_LENGTH 36 45#define COBRA_LENGTH 36
46 46
47static char* cobra_name = "Creative Labs Blaster GamePad Cobra";
48
49static int cobra_btn[] = { BTN_START, BTN_SELECT, BTN_TL, BTN_TR, BTN_X, BTN_Y, BTN_Z, BTN_A, BTN_B, BTN_C, BTN_TL2, BTN_TR2, 0 }; 47static int cobra_btn[] = { BTN_START, BTN_SELECT, BTN_TL, BTN_TR, BTN_X, BTN_Y, BTN_Z, BTN_A, BTN_B, BTN_C, BTN_TL2, BTN_TR2, 0 };
50 48
51struct cobra { 49struct cobra {
52 struct gameport *gameport; 50 struct gameport *gameport;
53 struct input_dev dev[2]; 51 struct input_dev *dev[2];
54 int reads; 52 int reads;
55 int bads; 53 int bads;
56 unsigned char exists; 54 unsigned char exists;
@@ -128,7 +126,7 @@ static void cobra_poll(struct gameport *gameport)
128 for (i = 0; i < 2; i++) 126 for (i = 0; i < 2; i++)
129 if (cobra->exists & r & (1 << i)) { 127 if (cobra->exists & r & (1 << i)) {
130 128
131 dev = cobra->dev + i; 129 dev = cobra->dev[i];
132 130
133 input_report_abs(dev, ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1)); 131 input_report_abs(dev, ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1));
134 input_report_abs(dev, ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1)); 132 input_report_abs(dev, ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1));
@@ -159,11 +157,13 @@ static void cobra_close(struct input_dev *dev)
159static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv) 157static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
160{ 158{
161 struct cobra *cobra; 159 struct cobra *cobra;
160 struct input_dev *input_dev;
162 unsigned int data[2]; 161 unsigned int data[2];
163 int i, j; 162 int i, j;
164 int err; 163 int err;
165 164
166 if (!(cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL))) 165 cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL);
166 if (!cobra)
167 return -ENOMEM; 167 return -ENOMEM;
168 168
169 cobra->gameport = gameport; 169 cobra->gameport = gameport;
@@ -191,38 +191,46 @@ static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
191 gameport_set_poll_handler(gameport, cobra_poll); 191 gameport_set_poll_handler(gameport, cobra_poll);
192 gameport_set_poll_interval(gameport, 20); 192 gameport_set_poll_interval(gameport, 20);
193 193
194 for (i = 0; i < 2; i++) 194 for (i = 0; i < 2; i++) {
195 if ((cobra->exists >> i) & 1) { 195 if (~(cobra->exists >> i) & 1)
196 196 continue;
197 sprintf(cobra->phys[i], "%s/input%d", gameport->phys, i);
198 197
199 cobra->dev[i].private = cobra; 198 cobra->dev[i] = input_dev = input_allocate_device();
200 cobra->dev[i].open = cobra_open; 199 if (!input_dev) {
201 cobra->dev[i].close = cobra_close; 200 err = -ENOMEM;
201 goto fail3;
202 }
202 203
203 cobra->dev[i].name = cobra_name; 204 sprintf(cobra->phys[i], "%s/input%d", gameport->phys, i);
204 cobra->dev[i].phys = cobra->phys[i];
205 cobra->dev[i].id.bustype = BUS_GAMEPORT;
206 cobra->dev[i].id.vendor = GAMEPORT_ID_VENDOR_CREATIVE;
207 cobra->dev[i].id.product = 0x0008;
208 cobra->dev[i].id.version = 0x0100;
209 205
210 cobra->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 206 input_dev->name = "Creative Labs Blaster GamePad Cobra";
207 input_dev->phys = cobra->phys[i];
208 input_dev->id.bustype = BUS_GAMEPORT;
209 input_dev->id.vendor = GAMEPORT_ID_VENDOR_CREATIVE;
210 input_dev->id.product = 0x0008;
211 input_dev->id.version = 0x0100;
212 input_dev->cdev.dev = &gameport->dev;
213 input_dev->private = cobra;
211 214
212 input_set_abs_params(&cobra->dev[i], ABS_X, -1, 1, 0, 0); 215 input_dev->open = cobra_open;
213 input_set_abs_params(&cobra->dev[i], ABS_Y, -1, 1, 0, 0); 216 input_dev->close = cobra_close;
214 217
215 for (j = 0; cobra_btn[j]; j++) 218 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
216 set_bit(cobra_btn[j], cobra->dev[i].keybit); 219 input_set_abs_params(input_dev, ABS_X, -1, 1, 0, 0);
220 input_set_abs_params(input_dev, ABS_Y, -1, 1, 0, 0);
221 for (j = 0; cobra_btn[j]; j++)
222 set_bit(cobra_btn[j], input_dev->keybit);
217 223
218 input_register_device(&cobra->dev[i]); 224 input_register_device(cobra->dev[i]);
219 printk(KERN_INFO "input: %s on %s\n", cobra_name, gameport->phys); 225 }
220 }
221 226
222 return 0; 227 return 0;
223 228
224fail2: gameport_close(gameport); 229 fail3: for (i = 0; i < 2; i++)
225fail1: gameport_set_drvdata(gameport, NULL); 230 if (cobra->dev[i])
231 input_unregister_device(cobra->dev[i]);
232 fail2: gameport_close(gameport);
233 fail1: gameport_set_drvdata(gameport, NULL);
226 kfree(cobra); 234 kfree(cobra);
227 return err; 235 return err;
228} 236}
@@ -234,7 +242,7 @@ static void cobra_disconnect(struct gameport *gameport)
234 242
235 for (i = 0; i < 2; i++) 243 for (i = 0; i < 2; i++)
236 if ((cobra->exists >> i) & 1) 244 if ((cobra->exists >> i) & 1)
237 input_unregister_device(cobra->dev + i); 245 input_unregister_device(cobra->dev[i]);
238 gameport_close(gameport); 246 gameport_close(gameport);
239 gameport_set_drvdata(gameport, NULL); 247 gameport_set_drvdata(gameport, NULL);
240 kfree(cobra); 248 kfree(cobra);