treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / input / mouse / touchkit_ps2.c
blob760e45158d5f59d6c8f6ac0379d6158631d839dd
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* ----------------------------------------------------------------------------
3 * touchkit_ps2.c -- Driver for eGalax TouchKit PS/2 Touchscreens
5 * Copyright (C) 2005 by Stefan Lucke
6 * Copyright (C) 2004 by Daniel Ritz
7 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
9 * Based upon touchkitusb.c
11 * Vendor documentation is available at:
12 * http://home.eeti.com.tw/web20/drivers/Software%20Programming%20Guide_v2.0.pdf
15 #include <linux/kernel.h>
17 #include <linux/input.h>
18 #include <linux/serio.h>
19 #include <linux/libps2.h>
21 #include "psmouse.h"
22 #include "touchkit_ps2.h"
24 #define TOUCHKIT_MAX_XC 0x07ff
25 #define TOUCHKIT_MAX_YC 0x07ff
27 #define TOUCHKIT_CMD 0x0a
28 #define TOUCHKIT_CMD_LENGTH 1
30 #define TOUCHKIT_CMD_ACTIVE 'A'
31 #define TOUCHKIT_CMD_FIRMWARE_VERSION 'D'
32 #define TOUCHKIT_CMD_CONTROLLER_TYPE 'E'
34 #define TOUCHKIT_SEND_PARMS(s, r, c) ((s) << 12 | (r) << 8 | (c))
36 #define TOUCHKIT_GET_TOUCHED(packet) (((packet)[0]) & 0x01)
37 #define TOUCHKIT_GET_X(packet) (((packet)[1] << 7) | (packet)[2])
38 #define TOUCHKIT_GET_Y(packet) (((packet)[3] << 7) | (packet)[4])
40 static psmouse_ret_t touchkit_ps2_process_byte(struct psmouse *psmouse)
42 unsigned char *packet = psmouse->packet;
43 struct input_dev *dev = psmouse->dev;
45 if (psmouse->pktcnt != 5)
46 return PSMOUSE_GOOD_DATA;
48 input_report_abs(dev, ABS_X, TOUCHKIT_GET_X(packet));
49 input_report_abs(dev, ABS_Y, TOUCHKIT_GET_Y(packet));
50 input_report_key(dev, BTN_TOUCH, TOUCHKIT_GET_TOUCHED(packet));
51 input_sync(dev);
53 return PSMOUSE_FULL_PACKET;
56 int touchkit_ps2_detect(struct psmouse *psmouse, bool set_properties)
58 struct input_dev *dev = psmouse->dev;
59 unsigned char param[3];
60 int command;
62 param[0] = TOUCHKIT_CMD_LENGTH;
63 param[1] = TOUCHKIT_CMD_ACTIVE;
64 command = TOUCHKIT_SEND_PARMS(2, 3, TOUCHKIT_CMD);
66 if (ps2_command(&psmouse->ps2dev, param, command))
67 return -ENODEV;
69 if (param[0] != TOUCHKIT_CMD || param[1] != 0x01 ||
70 param[2] != TOUCHKIT_CMD_ACTIVE)
71 return -ENODEV;
73 if (set_properties) {
74 dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
75 dev->keybit[BIT_WORD(BTN_MOUSE)] = 0;
76 dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
77 input_set_abs_params(dev, ABS_X, 0, TOUCHKIT_MAX_XC, 0, 0);
78 input_set_abs_params(dev, ABS_Y, 0, TOUCHKIT_MAX_YC, 0, 0);
80 psmouse->vendor = "eGalax";
81 psmouse->name = "Touchscreen";
82 psmouse->protocol_handler = touchkit_ps2_process_byte;
83 psmouse->pktsize = 5;
86 return 0;