1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <linux/kernel.h>
29
30#include <linux/input.h>
31#include <linux/serio.h>
32#include <linux/libps2.h>
33
34#include "psmouse.h"
35#include "touchkit_ps2.h"
36
37#define TOUCHKIT_MAX_XC 0x07ff
38#define TOUCHKIT_MAX_YC 0x07ff
39
40#define TOUCHKIT_CMD 0x0a
41#define TOUCHKIT_CMD_LENGTH 1
42
43#define TOUCHKIT_CMD_ACTIVE 'A'
44#define TOUCHKIT_CMD_FIRMWARE_VERSION 'D'
45#define TOUCHKIT_CMD_CONTROLLER_TYPE 'E'
46
47#define TOUCHKIT_SEND_PARMS(s, r, c) ((s) << 12 | (r) << 8 | (c))
48
49#define TOUCHKIT_GET_TOUCHED(packet) (((packet)[0]) & 0x01)
50#define TOUCHKIT_GET_X(packet) (((packet)[1] << 7) | (packet)[2])
51#define TOUCHKIT_GET_Y(packet) (((packet)[3] << 7) | (packet)[4])
52
53static psmouse_ret_t touchkit_ps2_process_byte(struct psmouse *psmouse)
54{
55 unsigned char *packet = psmouse->packet;
56 struct input_dev *dev = psmouse->dev;
57
58 if (psmouse->pktcnt != 5)
59 return PSMOUSE_GOOD_DATA;
60
61 input_report_abs(dev, ABS_X, TOUCHKIT_GET_X(packet));
62 input_report_abs(dev, ABS_Y, TOUCHKIT_GET_Y(packet));
63 input_report_key(dev, BTN_TOUCH, TOUCHKIT_GET_TOUCHED(packet));
64 input_sync(dev);
65
66 return PSMOUSE_FULL_PACKET;
67}
68
69int touchkit_ps2_detect(struct psmouse *psmouse, bool set_properties)
70{
71 struct input_dev *dev = psmouse->dev;
72 unsigned char param[3];
73 int command;
74
75 param[0] = TOUCHKIT_CMD_LENGTH;
76 param[1] = TOUCHKIT_CMD_ACTIVE;
77 command = TOUCHKIT_SEND_PARMS(2, 3, TOUCHKIT_CMD);
78
79 if (ps2_command(&psmouse->ps2dev, param, command))
80 return -ENODEV;
81
82 if (param[0] != TOUCHKIT_CMD || param[1] != 0x01 ||
83 param[2] != TOUCHKIT_CMD_ACTIVE)
84 return -ENODEV;
85
86 if (set_properties) {
87 dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
88 dev->keybit[BIT_WORD(BTN_MOUSE)] = 0;
89 dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
90 input_set_abs_params(dev, ABS_X, 0, TOUCHKIT_MAX_XC, 0, 0);
91 input_set_abs_params(dev, ABS_Y, 0, TOUCHKIT_MAX_YC, 0, 0);
92
93 psmouse->vendor = "eGalax";
94 psmouse->name = "Touchscreen";
95 psmouse->protocol_handler = touchkit_ps2_process_byte;
96 psmouse->pktsize = 5;
97 }
98
99 return 0;
100}
101