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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Wacom W8001 penabled serial touchscreen driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2008 Jaya Kumar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2010 Red Hat, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (c) 2010 - 2011 Ping Cheng, Wacom. <pingc@wacom.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * License. See the file COPYING in the main directory of this archive for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Layout based on Elo serial touchscreen driver by Vojtech Pavlik
^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/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/serio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define DRIVER_DESC	"Wacom W8001 serial touchscreen driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_AUTHOR("Jaya Kumar <jayakumar.lkml@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define W8001_MAX_PHYS		42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define W8001_MAX_LENGTH	13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define W8001_LEAD_MASK		0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define W8001_LEAD_BYTE		0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define W8001_TAB_MASK		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define W8001_TAB_BYTE		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /* set in first byte of touch data packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define W8001_TOUCH_MASK	(0x10 | W8001_LEAD_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define W8001_TOUCH_BYTE	(0x10 | W8001_LEAD_BYTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define W8001_QUERY_PACKET	0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define W8001_CMD_STOP		'0'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define W8001_CMD_START		'1'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define W8001_CMD_QUERY		'*'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define W8001_CMD_TOUCHQUERY	'%'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* length of data packets in bytes, depends on device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define W8001_PKTLEN_TOUCH93	5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define W8001_PKTLEN_TOUCH9A	7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define W8001_PKTLEN_TPCPEN	9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define W8001_PKTLEN_TPCCTL	11	/* control packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define W8001_PKTLEN_TOUCH2FG	13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /* resolution in points/mm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define W8001_PEN_RESOLUTION    100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define W8001_TOUCH_RESOLUTION  10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) struct w8001_coord {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	u8 rdy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	u8 tsw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	u8 f1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u8 f2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	u16 x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	u16 y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	u16 pen_pressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	u8 tilt_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	u8 tilt_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) /* touch query reply packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) struct w8001_touch_query {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	u16 x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	u16 y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	u8 panel_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	u8 capacity_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	u8 sensor_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * Per-touchscreen data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) struct w8001 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct input_dev *pen_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct input_dev *touch_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct serio *serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct completion cmd_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	unsigned char response_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	unsigned char response[W8001_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	unsigned char data[W8001_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	char phys[W8001_MAX_PHYS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	unsigned int pktlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	u16 max_touch_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	u16 max_touch_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	u16 max_pen_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	u16 max_pen_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	char pen_name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	char touch_name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int open_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void parse_pen_data(u8 *data, struct w8001_coord *coord)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	memset(coord, 0, sizeof(*coord));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	coord->rdy = data[0] & 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	coord->tsw = data[0] & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	coord->f1 = data[0] & 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	coord->f2 = data[0] & 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	coord->x = (data[1] & 0x7F) << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	coord->x |= (data[2] & 0x7F) << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	coord->x |= (data[6] & 0x60) >> 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	coord->y = (data[3] & 0x7F) << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	coord->y |= (data[4] & 0x7F) << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	coord->y |= (data[6] & 0x18) >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	coord->pen_pressure = data[5] & 0x7F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	coord->pen_pressure |= (data[6] & 0x07) << 7 ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	coord->tilt_x = data[7] & 0x7F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	coord->tilt_y = data[8] & 0x7F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static void parse_single_touch(u8 *data, struct w8001_coord *coord)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	coord->x = (data[1] << 7) | data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	coord->y = (data[3] << 7) | data[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	coord->tsw = data[0] & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static void scale_touch_coordinates(struct w8001 *w8001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				    unsigned int *x, unsigned int *y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (w8001->max_pen_x && w8001->max_touch_x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		*x = *x * w8001->max_pen_x / w8001->max_touch_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (w8001->max_pen_y && w8001->max_touch_y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		*y = *y * w8001->max_pen_y / w8001->max_touch_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static void parse_multi_touch(struct w8001 *w8001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct input_dev *dev = w8001->touch_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	unsigned char *data = w8001->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	unsigned int x, y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		bool touch = data[0] & (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		input_mt_slot(dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		input_mt_report_slot_state(dev, MT_TOOL_FINGER, touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (touch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			x = (data[6 * i + 1] << 7) | data[6 * i + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			y = (data[6 * i + 3] << 7) | data[6 * i + 4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			/* data[5,6] and [11,12] is finger capacity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			/* scale to pen maximum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			scale_touch_coordinates(w8001, &x, &y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			input_report_abs(dev, ABS_MT_POSITION_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			input_report_abs(dev, ABS_MT_POSITION_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* emulate single touch events when stylus is out of proximity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 * This is to make single touch backward support consistent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	 * across all Wacom single touch devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (w8001->type != BTN_TOOL_PEN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			    w8001->type != BTN_TOOL_RUBBER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		w8001->type = count == 1 ? BTN_TOOL_FINGER : KEY_RESERVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		input_mt_report_pointer_emulation(dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static void parse_touchquery(u8 *data, struct w8001_touch_query *query)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	memset(query, 0, sizeof(*query));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	query->panel_res = data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	query->sensor_id = data[2] & 0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	query->capacity_res = data[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	query->x = data[3] << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	query->x |= data[4] << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	query->x |= (data[2] >> 5) & 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	query->y = data[5] << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	query->y |= data[6] << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	query->y |= (data[2] >> 3) & 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	/* Early days' single-finger touch models need the following defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (!query->x && !query->y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		query->x = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		query->y = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		if (query->panel_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			query->x = query->y = (1 << query->panel_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		query->panel_res = W8001_TOUCH_RESOLUTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static void report_pen_events(struct w8001 *w8001, struct w8001_coord *coord)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct input_dev *dev = w8001->pen_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	 * We have 1 bit for proximity (rdy) and 3 bits for tip, side,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	 * side2/eraser. If rdy && f2 are set, this can be either pen + side2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 * or eraser. Assume:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 * - if dev is already in proximity and f2 is toggled → pen + side2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	 * - if dev comes into proximity with f2 set → eraser
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	 * If f2 disappears after assuming eraser, fake proximity out for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	 * eraser and in for pen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	switch (w8001->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	case BTN_TOOL_RUBBER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		if (!coord->f2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			input_report_abs(dev, ABS_PRESSURE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			input_report_key(dev, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			input_report_key(dev, BTN_STYLUS, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			input_report_key(dev, BTN_STYLUS2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			input_report_key(dev, BTN_TOOL_RUBBER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			w8001->type = BTN_TOOL_PEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	case BTN_TOOL_FINGER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	case KEY_RESERVED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		w8001->type = coord->f2 ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		input_report_key(dev, BTN_STYLUS2, coord->f2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	input_report_abs(dev, ABS_X, coord->x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	input_report_abs(dev, ABS_Y, coord->y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	input_report_abs(dev, ABS_PRESSURE, coord->pen_pressure);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	input_report_key(dev, BTN_TOUCH, coord->tsw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	input_report_key(dev, BTN_STYLUS, coord->f1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	input_report_key(dev, w8001->type, coord->rdy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (!coord->rdy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		w8001->type = KEY_RESERVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static void report_single_touch(struct w8001 *w8001, struct w8001_coord *coord)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	struct input_dev *dev = w8001->touch_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	unsigned int x = coord->x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	unsigned int y = coord->y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	/* scale to pen maximum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	scale_touch_coordinates(w8001, &x, &y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	input_report_abs(dev, ABS_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	input_report_abs(dev, ABS_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	input_report_key(dev, BTN_TOUCH, coord->tsw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	w8001->type = coord->tsw ? BTN_TOOL_FINGER : KEY_RESERVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static irqreturn_t w8001_interrupt(struct serio *serio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 				   unsigned char data, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	struct w8001 *w8001 = serio_get_drvdata(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct w8001_coord coord;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	unsigned char tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	w8001->data[w8001->idx] = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	switch (w8001->idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		if ((data & W8001_LEAD_MASK) != W8001_LEAD_BYTE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			pr_debug("w8001: unsynchronized data: 0x%02x\n", data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			w8001->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	case W8001_PKTLEN_TOUCH93 - 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	case W8001_PKTLEN_TOUCH9A - 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		tmp = w8001->data[0] & W8001_TOUCH_BYTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		if (tmp != W8001_TOUCH_BYTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		if (w8001->pktlen == w8001->idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			w8001->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			if (w8001->type != BTN_TOOL_PEN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			    w8001->type != BTN_TOOL_RUBBER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 				parse_single_touch(w8001->data, &coord);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 				report_single_touch(w8001, &coord);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	/* Pen coordinates packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	case W8001_PKTLEN_TPCPEN - 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		tmp = w8001->data[0] & W8001_TAB_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		if (unlikely(tmp == W8001_TAB_BYTE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		tmp = w8001->data[0] & W8001_TOUCH_BYTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		if (tmp == W8001_TOUCH_BYTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		w8001->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		parse_pen_data(w8001->data, &coord);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		report_pen_events(w8001, &coord);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	/* control packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	case W8001_PKTLEN_TPCCTL - 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		tmp = w8001->data[0] & W8001_TOUCH_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		if (tmp == W8001_TOUCH_BYTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		w8001->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		memcpy(w8001->response, w8001->data, W8001_MAX_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		w8001->response_type = W8001_QUERY_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		complete(&w8001->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	/* 2 finger touch packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	case W8001_PKTLEN_TOUCH2FG - 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		w8001->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		parse_multi_touch(w8001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		 * ThinkPad X60 Tablet PC (pen only device) sometimes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		 * sends invalid data packets that are larger than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		 * W8001_PKTLEN_TPCPEN. Let's start over again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		if (!w8001->touch_dev && w8001->idx > W8001_PKTLEN_TPCPEN - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			w8001->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static int w8001_command(struct w8001 *w8001, unsigned char command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			 bool wait_response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	w8001->response_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	init_completion(&w8001->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	rc = serio_write(w8001->serio, command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (rc == 0 && wait_response) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		wait_for_completion_timeout(&w8001->cmd_done, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		if (w8001->response_type != W8001_QUERY_PACKET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static int w8001_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	struct w8001 *w8001 = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	err = mutex_lock_interruptible(&w8001->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (w8001->open_count++ == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		err = w8001_command(w8001, W8001_CMD_START, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			w8001->open_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	mutex_unlock(&w8001->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static void w8001_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct w8001 *w8001 = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	mutex_lock(&w8001->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	if (--w8001->open_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		w8001_command(w8001, W8001_CMD_STOP, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	mutex_unlock(&w8001->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static int w8001_detect(struct w8001 *w8001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	error = w8001_command(w8001, W8001_CMD_STOP, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	msleep(250);	/* wait 250ms before querying the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static int w8001_setup_pen(struct w8001 *w8001, char *basename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			   size_t basename_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	struct input_dev *dev = w8001->pen_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	struct w8001_coord coord;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	/* penabled? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	error = w8001_command(w8001, W8001_CMD_QUERY, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	__set_bit(EV_KEY, dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	__set_bit(EV_ABS, dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	__set_bit(BTN_TOUCH, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	__set_bit(BTN_TOOL_PEN, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	__set_bit(BTN_TOOL_RUBBER, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	__set_bit(BTN_STYLUS, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	__set_bit(BTN_STYLUS2, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	__set_bit(INPUT_PROP_DIRECT, dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	parse_pen_data(w8001->response, &coord);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	w8001->max_pen_x = coord.x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	w8001->max_pen_y = coord.y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	input_abs_set_res(dev, ABS_X, W8001_PEN_RESOLUTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	input_abs_set_res(dev, ABS_Y, W8001_PEN_RESOLUTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (coord.tilt_x && coord.tilt_y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	w8001->id = 0x90;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	strlcat(basename, " Penabled", basename_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static int w8001_setup_touch(struct w8001 *w8001, char *basename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			     size_t basename_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	struct input_dev *dev = w8001->touch_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	struct w8001_touch_query touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	/* Touch enabled? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	error = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	 * Some non-touch devices may reply to the touch query. But their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	 * second byte is empty, which indicates touch is not supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	if (!w8001->response[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	__set_bit(EV_KEY, dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	__set_bit(EV_ABS, dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	__set_bit(BTN_TOUCH, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	__set_bit(INPUT_PROP_DIRECT, dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	parse_touchquery(w8001->response, &touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	w8001->max_touch_x = touch.x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	w8001->max_touch_y = touch.y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	if (w8001->max_pen_x && w8001->max_pen_y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		/* if pen is supported scale to pen maximum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		touch.x = w8001->max_pen_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		touch.y = w8001->max_pen_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		touch.panel_res = W8001_PEN_RESOLUTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	input_set_abs_params(dev, ABS_X, 0, touch.x, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	input_set_abs_params(dev, ABS_Y, 0, touch.y, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	input_abs_set_res(dev, ABS_X, touch.panel_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	input_abs_set_res(dev, ABS_Y, touch.panel_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	switch (touch.sensor_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		w8001->pktlen = W8001_PKTLEN_TOUCH93;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		w8001->id = 0x93;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		strlcat(basename, " 1FG", basename_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		w8001->pktlen = W8001_PKTLEN_TOUCH9A;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		strlcat(basename, " 1FG", basename_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		w8001->id = 0x9a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		w8001->pktlen = W8001_PKTLEN_TOUCH2FG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		__set_bit(BTN_TOOL_DOUBLETAP, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		error = input_mt_init_slots(dev, 2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			dev_err(&w8001->serio->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 				"failed to initialize MT slots: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		input_set_abs_params(dev, ABS_MT_POSITION_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 					0, touch.x, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		input_set_abs_params(dev, ABS_MT_POSITION_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 					0, touch.y, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		input_set_abs_params(dev, ABS_MT_TOOL_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 					0, MT_TOOL_MAX, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		input_abs_set_res(dev, ABS_MT_POSITION_X, touch.panel_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		input_abs_set_res(dev, ABS_MT_POSITION_Y, touch.panel_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		strlcat(basename, " 2FG", basename_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		if (w8001->max_pen_x && w8001->max_pen_y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 			w8001->id = 0xE3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 			w8001->id = 0xE2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	strlcat(basename, " Touchscreen", basename_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static void w8001_set_devdata(struct input_dev *dev, struct w8001 *w8001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 			      struct serio *serio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	dev->phys = w8001->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	dev->id.bustype = BUS_RS232;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	dev->id.product = w8001->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	dev->id.vendor = 0x056a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	dev->open = w8001_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	dev->close = w8001_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	dev->dev.parent = &serio->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	input_set_drvdata(dev, w8001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)  * w8001_disconnect() is the opposite of w8001_connect()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static void w8001_disconnect(struct serio *serio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	struct w8001 *w8001 = serio_get_drvdata(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	serio_close(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	if (w8001->pen_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		input_unregister_device(w8001->pen_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	if (w8001->touch_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		input_unregister_device(w8001->touch_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	kfree(w8001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	serio_set_drvdata(serio, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)  * w8001_connect() is the routine that is called when someone adds a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)  * new serio device that supports the w8001 protocol and registers it as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)  * an input device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static int w8001_connect(struct serio *serio, struct serio_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	struct w8001 *w8001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	struct input_dev *input_dev_pen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	struct input_dev *input_dev_touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	char basename[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	int err, err_pen, err_touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	w8001 = kzalloc(sizeof(struct w8001), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	input_dev_pen = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	input_dev_touch = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	if (!w8001 || !input_dev_pen || !input_dev_touch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	w8001->serio = serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	w8001->pen_dev = input_dev_pen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	w8001->touch_dev = input_dev_touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	mutex_init(&w8001->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	init_completion(&w8001->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	snprintf(w8001->phys, sizeof(w8001->phys), "%s/input0", serio->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	serio_set_drvdata(serio, w8001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	err = serio_open(serio, drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	err = w8001_detect(w8001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	/* For backwards-compatibility we compose the basename based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	 * capabilities and then just append the tool type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	strlcpy(basename, "Wacom Serial", sizeof(basename));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	err_pen = w8001_setup_pen(w8001, basename, sizeof(basename));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	err_touch = w8001_setup_touch(w8001, basename, sizeof(basename));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	if (err_pen && err_touch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		err = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	if (!err_pen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		strlcpy(w8001->pen_name, basename, sizeof(w8001->pen_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 		strlcat(w8001->pen_name, " Pen", sizeof(w8001->pen_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 		input_dev_pen->name = w8001->pen_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		w8001_set_devdata(input_dev_pen, w8001, serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 		err = input_register_device(w8001->pen_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 			goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		input_free_device(input_dev_pen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		input_dev_pen = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 		w8001->pen_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	if (!err_touch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		strlcpy(w8001->touch_name, basename, sizeof(w8001->touch_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 		strlcat(w8001->touch_name, " Finger",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 			sizeof(w8001->touch_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		input_dev_touch->name = w8001->touch_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		w8001_set_devdata(input_dev_touch, w8001, serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		err = input_register_device(w8001->touch_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 			goto fail4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		input_free_device(input_dev_touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		input_dev_touch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		w8001->touch_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) fail4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	if (w8001->pen_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 		input_unregister_device(w8001->pen_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) fail3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	serio_close(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	serio_set_drvdata(serio, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	input_free_device(input_dev_pen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	input_free_device(input_dev_touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	kfree(w8001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) static const struct serio_device_id w8001_serio_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 		.type	= SERIO_RS232,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 		.proto	= SERIO_W8001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		.id	= SERIO_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		.extra	= SERIO_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	{ 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) MODULE_DEVICE_TABLE(serio, w8001_serio_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) static struct serio_driver w8001_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 		.name	= "w8001",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	.description	= DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	.id_table	= w8001_serio_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	.interrupt	= w8001_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	.connect	= w8001_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	.disconnect	= w8001_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) module_serio_driver(w8001_drv);