aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2009-08-08 02:17:47 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2009-08-09 16:27:27 -0400
commitfa71c605c2bb4d816514c2611ad53f48007f1fd3 (patch)
tree9f57765287a2c2a7623ba6b5031e2897c01e5216 /drivers/input
parent1437dc3089911d42180be11c50a0b960250a1d87 (diff)
Input: combine hil_kbd and hil_ptr drivers
hil_kbd and hil_ptr look like twins so it makes sense to combine them into a single driver. [deller@gmx.de: add MODULE_ALIAS() entry for mouse] Tested-by: Helge Deller <deller@gmx.de> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/keyboard/Kconfig5
-rw-r--r--drivers/input/keyboard/hil_kbd.c251
-rw-r--r--drivers/input/mouse/Kconfig8
-rw-r--r--drivers/input/mouse/Makefile1
-rw-r--r--drivers/input/mouse/hil_ptr.c447
5 files changed, 219 insertions, 493 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index a6b989a9dc07..5239e25e88ac 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -187,7 +187,7 @@ config KEYBOARD_HIL_OLD
187 submenu. 187 submenu.
188 188
189config KEYBOARD_HIL 189config KEYBOARD_HIL
190 tristate "HP HIL keyboard support" 190 tristate "HP HIL keyboard/pointer support"
191 depends on GSC || HP300 191 depends on GSC || HP300
192 default y 192 default y
193 select HP_SDC 193 select HP_SDC
@@ -196,7 +196,8 @@ config KEYBOARD_HIL
196 help 196 help
197 The "Human Interface Loop" is a older, 8-channel USB-like 197 The "Human Interface Loop" is a older, 8-channel USB-like
198 controller used in several Hewlett Packard models. 198 controller used in several Hewlett Packard models.
199 This driver implements support for HIL-keyboards attached 199 This driver implements support for HIL-keyboards and pointing
200 devices (mice, tablets, touchscreens) attached
200 to your machine, so normally you should say Y here. 201 to your machine, so normally you should say Y here.
201 202
202config KEYBOARD_HP6XX 203config KEYBOARD_HP6XX
diff --git a/drivers/input/keyboard/hil_kbd.c b/drivers/input/keyboard/hil_kbd.c
index 235a669a0ac3..c83f4b2ec7d3 100644
--- a/drivers/input/keyboard/hil_kbd.c
+++ b/drivers/input/keyboard/hil_kbd.c
@@ -41,13 +41,13 @@
41#include <linux/slab.h> 41#include <linux/slab.h>
42#include <linux/pci_ids.h> 42#include <linux/pci_ids.h>
43 43
44#define PREFIX "HIL KEYB: " 44#define PREFIX "HIL: "
45#define HIL_GENERIC_NAME "HIL keyboard"
46 45
47MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>"); 46MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
48MODULE_DESCRIPTION(HIL_GENERIC_NAME " driver"); 47MODULE_DESCRIPTION("HIL keyboard/mouse driver");
49MODULE_LICENSE("Dual BSD/GPL"); 48MODULE_LICENSE("Dual BSD/GPL");
50MODULE_ALIAS("serio:ty03pr25id00ex*"); 49MODULE_ALIAS("serio:ty03pr25id00ex*"); /* HIL keyboard */
50MODULE_ALIAS("serio:ty03pr25id0Fex*"); /* HIL mouse */
51 51
52#define HIL_PACKET_MAX_LENGTH 16 52#define HIL_PACKET_MAX_LENGTH 16
53 53
@@ -82,6 +82,11 @@ struct hil_dev {
82 char rnm[HIL_PACKET_MAX_LENGTH + 1]; /* RNM record + NULL term. */ 82 char rnm[HIL_PACKET_MAX_LENGTH + 1]; /* RNM record + NULL term. */
83 83
84 struct completion cmd_done; 84 struct completion cmd_done;
85
86 bool is_pointer;
87 /* Extra device details needed for pointing devices. */
88 unsigned int nbtn, naxes;
89 unsigned int btnmap[7];
85}; 90};
86 91
87static bool hil_dev_is_command_response(hil_packet p) 92static bool hil_dev_is_command_response(hil_packet p)
@@ -139,7 +144,7 @@ static void hil_dev_handle_command_response(struct hil_dev *dev)
139 complete(&dev->cmd_done); 144 complete(&dev->cmd_done);
140} 145}
141 146
142static void hil_dev_handle_key_events(struct hil_dev *kbd) 147static void hil_dev_handle_kbd_events(struct hil_dev *kbd)
143{ 148{
144 struct input_dev *dev = kbd->dev; 149 struct input_dev *dev = kbd->dev;
145 int idx = kbd->idx4 / 4; 150 int idx = kbd->idx4 / 4;
@@ -198,6 +203,67 @@ static void hil_dev_handle_key_events(struct hil_dev *kbd)
198 input_sync(dev); 203 input_sync(dev);
199} 204}
200 205
206static void hil_dev_handle_ptr_events(struct hil_dev *ptr)
207{
208 struct input_dev *dev = ptr->dev;
209 int idx = ptr->idx4 / 4;
210 hil_packet p = ptr->data[idx - 1];
211 int i, cnt, laxis;
212 bool absdev, ax16;
213
214 if ((p & HIL_CMDCT_POL) != idx - 1) {
215 printk(KERN_WARNING PREFIX
216 "Malformed poll packet %x (idx = %i)\n", p, idx);
217 return;
218 }
219
220 i = (p & HIL_POL_AXIS_ALT) ? 3 : 0;
221 laxis = (p & HIL_POL_NUM_AXES_MASK) + i;
222
223 ax16 = ptr->idd[1] & HIL_IDD_HEADER_16BIT; /* 8 or 16bit resolution */
224 absdev = ptr->idd[1] & HIL_IDD_HEADER_ABS;
225
226 for (cnt = 1; i < laxis; i++) {
227 unsigned int lo, hi, val;
228
229 lo = ptr->data[cnt++] & HIL_PKT_DATA_MASK;
230 hi = ax16 ? (ptr->data[cnt++] & HIL_PKT_DATA_MASK) : 0;
231
232 if (absdev) {
233 val = lo + (hi << 8);
234#ifdef TABLET_AUTOADJUST
235 if (val < dev->absmin[ABS_X + i])
236 dev->absmin[ABS_X + i] = val;
237 if (val > dev->absmax[ABS_X + i])
238 dev->absmax[ABS_X + i] = val;
239#endif
240 if (i%3) val = dev->absmax[ABS_X + i] - val;
241 input_report_abs(dev, ABS_X + i, val);
242 } else {
243 val = (int) (((int8_t)lo) | ((int8_t)hi << 8));
244 if (i % 3)
245 val *= -1;
246 input_report_rel(dev, REL_X + i, val);
247 }
248 }
249
250 while (cnt < idx - 1) {
251 unsigned int btn = ptr->data[cnt++];
252 int up = btn & 1;
253
254 btn &= 0xfe;
255 if (btn == 0x8e)
256 continue; /* TODO: proximity == touch? */
257 if (btn > 0x8c || btn < 0x80)
258 continue;
259 btn = (btn - 0x80) >> 1;
260 btn = ptr->btnmap[btn];
261 input_report_key(dev, btn, !up);
262 }
263
264 input_sync(dev);
265}
266
201static void hil_dev_process_err(struct hil_dev *dev) 267static void hil_dev_process_err(struct hil_dev *dev)
202{ 268{
203 printk(KERN_WARNING PREFIX "errored HIL packet\n"); 269 printk(KERN_WARNING PREFIX "errored HIL packet\n");
@@ -234,8 +300,10 @@ static irqreturn_t hil_dev_interrupt(struct serio *serio,
234 } else if (packet & HIL_PKT_CMD) { 300 } else if (packet & HIL_PKT_CMD) {
235 if (hil_dev_is_command_response(packet)) 301 if (hil_dev_is_command_response(packet))
236 hil_dev_handle_command_response(dev); 302 hil_dev_handle_command_response(dev);
303 else if (dev->is_pointer)
304 hil_dev_handle_ptr_events(dev);
237 else 305 else
238 hil_dev_handle_key_events(dev); 306 hil_dev_handle_kbd_events(dev);
239 dev->idx4 = 0; 307 dev->idx4 = 0;
240 } 308 }
241 } 309 }
@@ -251,15 +319,130 @@ static void hil_dev_disconnect(struct serio *serio)
251 319
252 serio_close(serio); 320 serio_close(serio);
253 input_unregister_device(dev->dev); 321 input_unregister_device(dev->dev);
322 serio_set_drvdata(serio, NULL);
254 kfree(dev); 323 kfree(dev);
255} 324}
256 325
326static void hil_dev_keyboard_setup(struct hil_dev *kbd)
327{
328 struct input_dev *input_dev = kbd->dev;
329 uint8_t did = kbd->idd[0];
330 int i;
331
332 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
333 input_dev->ledbit[0] = BIT_MASK(LED_NUML) | BIT_MASK(LED_CAPSL) |
334 BIT_MASK(LED_SCROLLL);
335
336 for (i = 0; i < 128; i++) {
337 __set_bit(hil_kbd_set1[i], input_dev->keybit);
338 __set_bit(hil_kbd_set3[i], input_dev->keybit);
339 }
340 __clear_bit(KEY_RESERVED, input_dev->keybit);
341
342 input_dev->keycodemax = HIL_KEYCODES_SET1_TBLSIZE;
343 input_dev->keycodesize = sizeof(hil_kbd_set1[0]);
344 input_dev->keycode = hil_kbd_set1;
345
346 input_dev->name = strlen(kbd->rnm) ? kbd->rnm : "HIL keyboard";
347 input_dev->phys = "hpkbd/input0";
348
349 printk(KERN_INFO PREFIX "HIL keyboard found (did = 0x%02x, lang = %s)\n",
350 did, hil_language[did & HIL_IDD_DID_TYPE_KB_LANG_MASK]);
351}
352
353static void hil_dev_pointer_setup(struct hil_dev *ptr)
354{
355 struct input_dev *input_dev = ptr->dev;
356 uint8_t did = ptr->idd[0];
357 uint8_t *idd = ptr->idd + 1;
358 unsigned int naxsets = HIL_IDD_NUM_AXSETS(*idd);
359 unsigned int i, btntype;
360 const char *txt;
361
362 ptr->naxes = HIL_IDD_NUM_AXES_PER_SET(*idd);
363
364 switch (did & HIL_IDD_DID_TYPE_MASK) {
365 case HIL_IDD_DID_TYPE_REL:
366 input_dev->evbit[0] = BIT_MASK(EV_REL);
367
368 for (i = 0; i < ptr->naxes; i++)
369 __set_bit(REL_X + i, input_dev->relbit);
370
371 for (i = 3; naxsets > 1 && i < ptr->naxes + 3; i++)
372 __set_bit(REL_X + i, input_dev->relbit);
373
374 txt = "relative";
375 break;
376
377 case HIL_IDD_DID_TYPE_ABS:
378 input_dev->evbit[0] = BIT_MASK(EV_ABS);
379
380 for (i = 0; i < ptr->naxes; i++)
381 input_set_abs_params(input_dev, ABS_X + i,
382 0, HIL_IDD_AXIS_MAX(idd, i), 0, 0);
383
384 for (i = 3; naxsets > 1 && i < ptr->naxes + 3; i++)
385 input_set_abs_params(input_dev, ABS_X + i,
386 0, HIL_IDD_AXIS_MAX(idd, i - 3), 0, 0);
387
388#ifdef TABLET_AUTOADJUST
389 for (i = 0; i < ABS_MAX; i++) {
390 int diff = input_dev->absmax[ABS_X + i] / 10;
391 input_dev->absmin[ABS_X + i] += diff;
392 input_dev->absmax[ABS_X + i] -= diff;
393 }
394#endif
395
396 txt = "absolute";
397 break;
398
399 default:
400 BUG();
401 }
402
403 ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd);
404 if (ptr->nbtn)
405 input_dev->evbit[0] |= BIT_MASK(EV_KEY);
406
407 btntype = BTN_MISC;
408 if ((did & HIL_IDD_DID_ABS_TABLET_MASK) == HIL_IDD_DID_ABS_TABLET)
409#ifdef TABLET_SIMULATES_MOUSE
410 btntype = BTN_TOUCH;
411#else
412 btntype = BTN_DIGI;
413#endif
414 if ((did & HIL_IDD_DID_ABS_TSCREEN_MASK) == HIL_IDD_DID_ABS_TSCREEN)
415 btntype = BTN_TOUCH;
416
417 if ((did & HIL_IDD_DID_REL_MOUSE_MASK) == HIL_IDD_DID_REL_MOUSE)
418 btntype = BTN_MOUSE;
419
420 for (i = 0; i < ptr->nbtn; i++) {
421 __set_bit(btntype | i, input_dev->keybit);
422 ptr->btnmap[i] = btntype | i;
423 }
424
425 if (btntype == BTN_MOUSE) {
426 /* Swap buttons 2 and 3 */
427 ptr->btnmap[1] = BTN_MIDDLE;
428 ptr->btnmap[2] = BTN_RIGHT;
429 }
430
431 input_dev->name = strlen(ptr->rnm) ? ptr->rnm : "HIL pointer device";
432
433 printk(KERN_INFO PREFIX
434 "HIL pointer device found (did: 0x%02x, axis: %s)\n",
435 did, txt);
436 printk(KERN_INFO PREFIX
437 "HIL pointer has %i buttons and %i sets of %i axes\n",
438 ptr->nbtn, naxsets, ptr->naxes);
439}
440
257static int hil_dev_connect(struct serio *serio, struct serio_driver *drv) 441static int hil_dev_connect(struct serio *serio, struct serio_driver *drv)
258{ 442{
259 struct hil_dev *dev; 443 struct hil_dev *dev;
260 struct input_dev *input_dev; 444 struct input_dev *input_dev;
261 uint8_t did, *idd; 445 uint8_t did, *idd;
262 int i;
263 int error; 446 int error;
264 447
265 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 448 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
@@ -317,49 +500,47 @@ static int hil_dev_connect(struct serio *serio, struct serio_driver *drv)
317 500
318 did = dev->idd[0]; 501 did = dev->idd[0];
319 idd = dev->idd + 1; 502 idd = dev->idd + 1;
503
320 switch (did & HIL_IDD_DID_TYPE_MASK) { 504 switch (did & HIL_IDD_DID_TYPE_MASK) {
321 case HIL_IDD_DID_TYPE_KB_INTEGRAL: 505 case HIL_IDD_DID_TYPE_KB_INTEGRAL:
322 case HIL_IDD_DID_TYPE_KB_ITF: 506 case HIL_IDD_DID_TYPE_KB_ITF:
323 case HIL_IDD_DID_TYPE_KB_RSVD: 507 case HIL_IDD_DID_TYPE_KB_RSVD:
324 case HIL_IDD_DID_TYPE_CHAR: 508 case HIL_IDD_DID_TYPE_CHAR:
325 printk(KERN_INFO PREFIX "HIL keyboard found (did = 0x%02x, lang = %s)\n", 509 if (HIL_IDD_NUM_BUTTONS(idd) ||
326 did, hil_language[did & HIL_IDD_DID_TYPE_KB_LANG_MASK]); 510 HIL_IDD_NUM_AXES_PER_SET(*idd)) {
511 printk(KERN_INFO PREFIX
512 "combo devices are not supported.\n");
513 goto bail1;
514 }
515
516 dev->is_pointer = false;
517 hil_dev_keyboard_setup(dev);
327 break; 518 break;
328 default:
329 goto bail1;
330 }
331 519
332 if (HIL_IDD_NUM_BUTTONS(idd) || HIL_IDD_NUM_AXES_PER_SET(*idd)) { 520 case HIL_IDD_DID_TYPE_REL:
333 printk(KERN_INFO PREFIX "keyboards only, no combo devices supported.\n"); 521 case HIL_IDD_DID_TYPE_ABS:
522 dev->is_pointer = true;
523 hil_dev_pointer_setup(dev);
524 break;
525
526 default:
334 goto bail1; 527 goto bail1;
335 } 528 }
336 529
337 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
338 input_dev->ledbit[0] = BIT_MASK(LED_NUML) | BIT_MASK(LED_CAPSL) |
339 BIT_MASK(LED_SCROLLL);
340 input_dev->keycodemax = HIL_KEYCODES_SET1_TBLSIZE;
341 input_dev->keycodesize = sizeof(hil_kbd_set1[0]);
342 input_dev->keycode = hil_kbd_set1;
343 input_dev->name = strlen(dev->rnm) ? dev->rnm : HIL_GENERIC_NAME;
344 input_dev->phys = "hpkbd/input0"; /* XXX */
345
346 input_dev->id.bustype = BUS_HIL; 530 input_dev->id.bustype = BUS_HIL;
347 input_dev->id.vendor = PCI_VENDOR_ID_HP; 531 input_dev->id.vendor = PCI_VENDOR_ID_HP;
348 input_dev->id.product = 0x0001; /* TODO: get from kbd->rsc */ 532 input_dev->id.product = 0x0001; /* TODO: get from kbd->rsc */
349 input_dev->id.version = 0x0100; /* TODO: get from kbd->rsc */ 533 input_dev->id.version = 0x0100; /* TODO: get from kbd->rsc */
350 input_dev->dev.parent = &serio->dev; 534 input_dev->dev.parent = &serio->dev;
351 535
352 for (i = 0; i < 128; i++) { 536 if (!dev->is_pointer) {
353 __set_bit(hil_kbd_set1[i], input_dev->keybit); 537 serio_write(serio, 0);
354 __set_bit(hil_kbd_set3[i], input_dev->keybit); 538 serio_write(serio, 0);
539 serio_write(serio, HIL_PKT_CMD >> 8);
540 /* Enable Keyswitch Autorepeat 1 */
541 serio_write(serio, HIL_CMD_EK1);
542 /* No need to wait for completion */
355 } 543 }
356 __clear_bit(KEY_RESERVED, input_dev->keybit);
357
358 serio_write(serio, 0);
359 serio_write(serio, 0);
360 serio_write(serio, HIL_PKT_CMD >> 8);
361 serio_write(serio, HIL_CMD_EK1); /* Enable Keyswitch Autorepeat 1 */
362 /* No need to wait for completion */
363 544
364 error = input_register_device(input_dev); 545 error = input_register_device(input_dev);
365 if (error) 546 if (error)
@@ -388,9 +569,9 @@ static struct serio_device_id hil_dev_ids[] = {
388 569
389static struct serio_driver hil_serio_drv = { 570static struct serio_driver hil_serio_drv = {
390 .driver = { 571 .driver = {
391 .name = "hil_kbd", 572 .name = "hil_dev",
392 }, 573 },
393 .description = "HP HIL keyboard driver", 574 .description = "HP HIL keyboard/mouse/tablet driver",
394 .id_table = hil_dev_ids, 575 .id_table = hil_dev_ids,
395 .connect = hil_dev_connect, 576 .connect = hil_dev_connect,
396 .disconnect = hil_dev_disconnect, 577 .disconnect = hil_dev_disconnect,
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index 8a2c5b14c8d8..90bef5d498f0 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -262,14 +262,6 @@ config MOUSE_VSXXXAA
262 described in the source file). This driver also works with the 262 described in the source file). This driver also works with the
263 digitizer (VSXXX-AB) DEC produced. 263 digitizer (VSXXX-AB) DEC produced.
264 264
265config MOUSE_HIL
266 tristate "HIL pointers (mice etc)."
267 depends on GSC || HP300
268 select HP_SDC
269 select HIL_MLC
270 help
271 Say Y here to support HIL pointers.
272
273config MOUSE_GPIO 265config MOUSE_GPIO
274 tristate "GPIO mouse" 266 tristate "GPIO mouse"
275 depends on GENERIC_GPIO 267 depends on GENERIC_GPIO
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index 010f265ec152..ea58c9a372b6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,7 +9,6 @@ obj-$(CONFIG_MOUSE_APPLETOUCH) += appletouch.o
9obj-$(CONFIG_MOUSE_ATARI) += atarimouse.o 9obj-$(CONFIG_MOUSE_ATARI) += atarimouse.o
10obj-$(CONFIG_MOUSE_BCM5974) += bcm5974.o 10obj-$(CONFIG_MOUSE_BCM5974) += bcm5974.o
11obj-$(CONFIG_MOUSE_GPIO) += gpio_mouse.o 11obj-$(CONFIG_MOUSE_GPIO) += gpio_mouse.o
12obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o
13obj-$(CONFIG_MOUSE_INPORT) += inport.o 12obj-$(CONFIG_MOUSE_INPORT) += inport.o
14obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o 13obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
15obj-$(CONFIG_MOUSE_MAPLE) += maplemouse.o 14obj-$(CONFIG_MOUSE_MAPLE) += maplemouse.o
diff --git a/drivers/input/mouse/hil_ptr.c b/drivers/input/mouse/hil_ptr.c
deleted file mode 100644
index cd12c2d8fa0b..000000000000
--- a/drivers/input/mouse/hil_ptr.c
+++ /dev/null
@@ -1,447 +0,0 @@
1/*
2 * Generic linux-input device driver for axis-bearing devices
3 *
4 * Copyright (c) 2001 Brian S. Julin
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * Alternatively, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL").
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 *
29 * References:
30 * HP-HIL Technical Reference Manual. Hewlett Packard Product No. 45918A
31 *
32 */
33
34#include <linux/hil.h>
35#include <linux/input.h>
36#include <linux/serio.h>
37#include <linux/kernel.h>
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/slab.h>
41#include <linux/pci_ids.h>
42
43#define PREFIX "HIL PTR: "
44#define HIL_GENERIC_NAME "HIL pointer device"
45
46MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
47MODULE_DESCRIPTION(HIL_GENERIC_NAME " driver");
48MODULE_LICENSE("Dual BSD/GPL");
49MODULE_ALIAS("serio:ty03pr25id0Fex*");
50
51#define TABLET_SIMULATES_MOUSE /* allow tablet to be used as mouse */
52#undef TABLET_AUTOADJUST /* auto-adjust valid tablet ranges */
53
54
55#define HIL_PTR_MAX_LENGTH 16
56
57struct hil_ptr {
58 struct input_dev *dev;
59 struct serio *serio;
60
61 /* Input buffer and index for packets from HIL bus. */
62 hil_packet data[HIL_PTR_MAX_LENGTH];
63 int idx4; /* four counts per packet */
64
65 /* Raw device info records from HIL bus, see hil.h for fields. */
66 char idd[HIL_PTR_MAX_LENGTH]; /* DID byte and IDD record */
67 char rsc[HIL_PTR_MAX_LENGTH]; /* RSC record */
68 char exd[HIL_PTR_MAX_LENGTH]; /* EXD record */
69 char rnm[HIL_PTR_MAX_LENGTH + 1]; /* RNM record + NULL term. */
70
71 /* Extra device details not contained in struct input_dev. */
72 unsigned int nbtn, naxes;
73 unsigned int btnmap[7];
74
75 /* Something to sleep around with. */
76 struct semaphore sem;
77};
78
79/* Process a complete packet after transfer from the HIL */
80static void hil_ptr_process_record(struct hil_ptr *ptr)
81{
82 struct input_dev *dev = ptr->dev;
83 hil_packet *data = ptr->data;
84 hil_packet p;
85 int idx, i, cnt, laxis;
86 int ax16, absdev;
87
88 idx = ptr->idx4/4;
89 p = data[idx - 1];
90
91 if ((p & ~HIL_CMDCT_POL) ==
92 (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL))
93 goto report;
94 if ((p & ~HIL_CMDCT_RPL) ==
95 (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_RPL))
96 goto report;
97
98 /* Not a poll response. See if we are loading config records. */
99 switch (p & HIL_PKT_DATA_MASK) {
100 case HIL_CMD_IDD:
101 for (i = 0; i < idx; i++)
102 ptr->idd[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
103 for (; i < HIL_PTR_MAX_LENGTH; i++)
104 ptr->idd[i] = 0;
105 break;
106
107 case HIL_CMD_RSC:
108 for (i = 0; i < idx; i++)
109 ptr->rsc[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
110 for (; i < HIL_PTR_MAX_LENGTH; i++)
111 ptr->rsc[i] = 0;
112 break;
113
114 case HIL_CMD_EXD:
115 for (i = 0; i < idx; i++)
116 ptr->exd[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
117 for (; i < HIL_PTR_MAX_LENGTH; i++)
118 ptr->exd[i] = 0;
119 break;
120
121 case HIL_CMD_RNM:
122 for (i = 0; i < idx; i++)
123 ptr->rnm[i] = ptr->data[i] & HIL_PKT_DATA_MASK;
124 for (; i < HIL_PTR_MAX_LENGTH + 1; i++)
125 ptr->rnm[i] = 0;
126 break;
127
128 default:
129 /* These occur when device isn't present */
130 if (p == (HIL_ERR_INT | HIL_PKT_CMD))
131 break;
132 /* Anything else we'd like to know about. */
133 printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p);
134 break;
135 }
136 goto out;
137
138 report:
139 if ((p & HIL_CMDCT_POL) != idx - 1) {
140 printk(KERN_WARNING PREFIX
141 "Malformed poll packet %x (idx = %i)\n", p, idx);
142 goto out;
143 }
144
145 i = (ptr->data[0] & HIL_POL_AXIS_ALT) ? 3 : 0;
146 laxis = ptr->data[0] & HIL_POL_NUM_AXES_MASK;
147 laxis += i;
148
149 ax16 = ptr->idd[1] & HIL_IDD_HEADER_16BIT; /* 8 or 16bit resolution */
150 absdev = ptr->idd[1] & HIL_IDD_HEADER_ABS;
151
152 for (cnt = 1; i < laxis; i++) {
153 unsigned int lo,hi,val;
154 lo = ptr->data[cnt++] & HIL_PKT_DATA_MASK;
155 hi = ax16 ? (ptr->data[cnt++] & HIL_PKT_DATA_MASK) : 0;
156 if (absdev) {
157 val = lo + (hi<<8);
158#ifdef TABLET_AUTOADJUST
159 if (val < dev->absmin[ABS_X + i])
160 dev->absmin[ABS_X + i] = val;
161 if (val > dev->absmax[ABS_X + i])
162 dev->absmax[ABS_X + i] = val;
163#endif
164 if (i%3) val = dev->absmax[ABS_X + i] - val;
165 input_report_abs(dev, ABS_X + i, val);
166 } else {
167 val = (int) (((int8_t)lo) | ((int8_t)hi<<8));
168 if (i%3)
169 val *= -1;
170 input_report_rel(dev, REL_X + i, val);
171 }
172 }
173
174 while (cnt < idx - 1) {
175 unsigned int btn;
176 int up;
177 btn = ptr->data[cnt++];
178 up = btn & 1;
179 btn &= 0xfe;
180 if (btn == 0x8e)
181 continue; /* TODO: proximity == touch? */
182 else
183 if ((btn > 0x8c) || (btn < 0x80))
184 continue;
185 btn = (btn - 0x80) >> 1;
186 btn = ptr->btnmap[btn];
187 input_report_key(dev, btn, !up);
188 }
189 input_sync(dev);
190 out:
191 ptr->idx4 = 0;
192 up(&ptr->sem);
193}
194
195static void hil_ptr_process_err(struct hil_ptr *ptr)
196{
197 printk(KERN_WARNING PREFIX "errored HIL packet\n");
198 ptr->idx4 = 0;
199 up(&ptr->sem);
200}
201
202static irqreturn_t hil_ptr_interrupt(struct serio *serio,
203 unsigned char data, unsigned int flags)
204{
205 struct hil_ptr *ptr;
206 hil_packet packet;
207 int idx;
208
209 ptr = serio_get_drvdata(serio);
210 BUG_ON(ptr == NULL);
211
212 if (ptr->idx4 >= (HIL_PTR_MAX_LENGTH * sizeof(hil_packet))) {
213 hil_ptr_process_err(ptr);
214 return IRQ_HANDLED;
215 }
216 idx = ptr->idx4/4;
217 if (!(ptr->idx4 % 4))
218 ptr->data[idx] = 0;
219 packet = ptr->data[idx];
220 packet |= ((hil_packet)data) << ((3 - (ptr->idx4 % 4)) * 8);
221 ptr->data[idx] = packet;
222
223 /* Records of N 4-byte hil_packets must terminate with a command. */
224 if ((++(ptr->idx4)) % 4)
225 return IRQ_HANDLED;
226 if ((packet & 0xffff0000) != HIL_ERR_INT) {
227 hil_ptr_process_err(ptr);
228 return IRQ_HANDLED;
229 }
230 if (packet & HIL_PKT_CMD)
231 hil_ptr_process_record(ptr);
232
233 return IRQ_HANDLED;
234}
235
236static void hil_ptr_disconnect(struct serio *serio)
237{
238 struct hil_ptr *ptr;
239
240 ptr = serio_get_drvdata(serio);
241 BUG_ON(ptr == NULL);
242
243 serio_close(serio);
244 input_unregister_device(ptr->dev);
245 kfree(ptr);
246}
247
248static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
249{
250 struct hil_ptr *ptr;
251 const char *txt;
252 unsigned int i, naxsets, btntype;
253 uint8_t did, *idd;
254 int error;
255
256 ptr = kzalloc(sizeof(struct hil_ptr), GFP_KERNEL);
257 if (!ptr)
258 return -ENOMEM;
259
260 ptr->dev = input_allocate_device();
261 if (!ptr->dev) {
262 error = -ENOMEM;
263 goto bail0;
264 }
265
266 error = serio_open(serio, driver);
267 if (error)
268 goto bail1;
269
270 serio_set_drvdata(serio, ptr);
271 ptr->serio = serio;
272
273 init_MUTEX_LOCKED(&ptr->sem);
274
275 /* Get device info. MLC driver supplies devid/status/etc. */
276 serio_write(serio, 0);
277 serio_write(serio, 0);
278 serio_write(serio, HIL_PKT_CMD >> 8);
279 serio_write(serio, HIL_CMD_IDD);
280 down(&ptr->sem);
281
282 serio_write(serio, 0);
283 serio_write(serio, 0);
284 serio_write(serio, HIL_PKT_CMD >> 8);
285 serio_write(serio, HIL_CMD_RSC);
286 down(&ptr->sem);
287
288 serio_write(serio, 0);
289 serio_write(serio, 0);
290 serio_write(serio, HIL_PKT_CMD >> 8);
291 serio_write(serio, HIL_CMD_RNM);
292 down(&ptr->sem);
293
294 serio_write(serio, 0);
295 serio_write(serio, 0);
296 serio_write(serio, HIL_PKT_CMD >> 8);
297 serio_write(serio, HIL_CMD_EXD);
298 down(&ptr->sem);
299
300 up(&ptr->sem);
301
302 did = ptr->idd[0];
303 idd = ptr->idd + 1;
304 txt = "unknown";
305
306 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
307 ptr->dev->evbit[0] = BIT_MASK(EV_REL);
308 txt = "relative";
309 }
310
311 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_ABS) {
312 ptr->dev->evbit[0] = BIT_MASK(EV_ABS);
313 txt = "absolute";
314 }
315
316 if (!ptr->dev->evbit[0]) {
317 error = -ENODEV;
318 goto bail2;
319 }
320
321 ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd);
322 if (ptr->nbtn)
323 ptr->dev->evbit[0] |= BIT_MASK(EV_KEY);
324
325 naxsets = HIL_IDD_NUM_AXSETS(*idd);
326 ptr->naxes = HIL_IDD_NUM_AXES_PER_SET(*idd);
327
328 printk(KERN_INFO PREFIX "HIL pointer device found (did: 0x%02x, axis: %s)\n",
329 did, txt);
330 printk(KERN_INFO PREFIX "HIL pointer has %i buttons and %i sets of %i axes\n",
331 ptr->nbtn, naxsets, ptr->naxes);
332
333 btntype = BTN_MISC;
334 if ((did & HIL_IDD_DID_ABS_TABLET_MASK) == HIL_IDD_DID_ABS_TABLET)
335#ifdef TABLET_SIMULATES_MOUSE
336 btntype = BTN_TOUCH;
337#else
338 btntype = BTN_DIGI;
339#endif
340 if ((did & HIL_IDD_DID_ABS_TSCREEN_MASK) == HIL_IDD_DID_ABS_TSCREEN)
341 btntype = BTN_TOUCH;
342
343 if ((did & HIL_IDD_DID_REL_MOUSE_MASK) == HIL_IDD_DID_REL_MOUSE)
344 btntype = BTN_MOUSE;
345
346 for (i = 0; i < ptr->nbtn; i++) {
347 set_bit(btntype | i, ptr->dev->keybit);
348 ptr->btnmap[i] = btntype | i;
349 }
350
351 if (btntype == BTN_MOUSE) {
352 /* Swap buttons 2 and 3 */
353 ptr->btnmap[1] = BTN_MIDDLE;
354 ptr->btnmap[2] = BTN_RIGHT;
355 }
356
357 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
358 for (i = 0; i < ptr->naxes; i++)
359 set_bit(REL_X + i, ptr->dev->relbit);
360 for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++)
361 set_bit(REL_X + i, ptr->dev->relbit);
362 } else {
363 for (i = 0; i < ptr->naxes; i++) {
364 set_bit(ABS_X + i, ptr->dev->absbit);
365 ptr->dev->absmin[ABS_X + i] = 0;
366 ptr->dev->absmax[ABS_X + i] =
367 HIL_IDD_AXIS_MAX((ptr->idd + 1), i);
368 }
369 for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) {
370 set_bit(ABS_X + i, ptr->dev->absbit);
371 ptr->dev->absmin[ABS_X + i] = 0;
372 ptr->dev->absmax[ABS_X + i] =
373 HIL_IDD_AXIS_MAX((ptr->idd + 1), (i - 3));
374 }
375#ifdef TABLET_AUTOADJUST
376 for (i = 0; i < ABS_MAX; i++) {
377 int diff = ptr->dev->absmax[ABS_X + i] / 10;
378 ptr->dev->absmin[ABS_X + i] += diff;
379 ptr->dev->absmax[ABS_X + i] -= diff;
380 }
381#endif
382 }
383
384 ptr->dev->name = strlen(ptr->rnm) ? ptr->rnm : HIL_GENERIC_NAME;
385
386 ptr->dev->id.bustype = BUS_HIL;
387 ptr->dev->id.vendor = PCI_VENDOR_ID_HP;
388 ptr->dev->id.product = 0x0001; /* TODO: get from ptr->rsc */
389 ptr->dev->id.version = 0x0100; /* TODO: get from ptr->rsc */
390 ptr->dev->dev.parent = &serio->dev;
391
392 error = input_register_device(ptr->dev);
393 if (error) {
394 printk(KERN_INFO PREFIX "Unable to register input device\n");
395 goto bail2;
396 }
397
398 printk(KERN_INFO "input: %s (%s), ID: %d\n",
399 ptr->dev->name,
400 (btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad",
401 did);
402
403 return 0;
404
405 bail2:
406 serio_close(serio);
407 bail1:
408 input_free_device(ptr->dev);
409 bail0:
410 kfree(ptr);
411 serio_set_drvdata(serio, NULL);
412 return error;
413}
414
415static struct serio_device_id hil_ptr_ids[] = {
416 {
417 .type = SERIO_HIL_MLC,
418 .proto = SERIO_HIL,
419 .id = SERIO_ANY,
420 .extra = SERIO_ANY,
421 },
422 { 0 }
423};
424
425static struct serio_driver hil_ptr_serio_driver = {
426 .driver = {
427 .name = "hil_ptr",
428 },
429 .description = "HP HIL mouse/tablet driver",
430 .id_table = hil_ptr_ids,
431 .connect = hil_ptr_connect,
432 .disconnect = hil_ptr_disconnect,
433 .interrupt = hil_ptr_interrupt
434};
435
436static int __init hil_ptr_init(void)
437{
438 return serio_register_driver(&hil_ptr_serio_driver);
439}
440
441static void __exit hil_ptr_exit(void)
442{
443 serio_unregister_driver(&hil_ptr_serio_driver);
444}
445
446module_init(hil_ptr_init);
447module_exit(hil_ptr_exit);