Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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