^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Elo serial touchscreen driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2004 Vojtech Pavlik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This driver can handle serial Elo touchscreens using either the Elo standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * 'E271-2210' 10-byte protocol, Elo legacy 'E281A-4002' 6-byte protocol, Elo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * legacy 'E271-140' 4-byte protocol and Elo legacy 'E261-280' 3-byte protocol.
^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.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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define DRIVER_DESC "Elo serial touchscreen driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Definitions & global arrays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define ELO_MAX_LENGTH 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define ELO10_PACKET_LEN 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define ELO10_TOUCH 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define ELO10_PRESSURE 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define ELO10_LEAD_BYTE 'U'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define ELO10_ID_CMD 'i'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define ELO10_TOUCH_PACKET 'T'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define ELO10_ACK_PACKET 'A'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define ELI10_ID_PACKET 'I'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * Per-touchscreen data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct elo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct serio *serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct mutex cmd_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct completion cmd_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) unsigned char expected_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) unsigned char csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) unsigned char data[ELO_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) unsigned char response[ELO10_PACKET_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static void elo_process_data_10(struct elo *elo, unsigned char data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct input_dev *dev = elo->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) elo->data[elo->idx] = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) switch (elo->idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) elo->csum = 0xaa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (data != ELO10_LEAD_BYTE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) dev_dbg(&elo->serio->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) "unsynchronized data: 0x%02x\n", data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) case 9:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (data != elo->csum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) dev_dbg(&elo->serio->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) "bad checksum: 0x%02x, expected 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) data, elo->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (elo->data[1] != elo->expected_packet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (elo->data[1] != ELO10_TOUCH_PACKET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) dev_dbg(&elo->serio->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) "unexpected packet: 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) elo->data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (likely(elo->data[1] == ELO10_TOUCH_PACKET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (elo->data[2] & ELO10_PRESSURE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) input_report_abs(dev, ABS_PRESSURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) (elo->data[8] << 8) | elo->data[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) input_report_key(dev, BTN_TOUCH, elo->data[2] & ELO10_TOUCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) } else if (elo->data[1] == ELO10_ACK_PACKET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (elo->data[2] == '0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) elo->expected_packet = ELO10_TOUCH_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) complete(&elo->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) memcpy(elo->response, &elo->data[1], ELO10_PACKET_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) elo->expected_packet = ELO10_ACK_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) elo->csum += data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static void elo_process_data_6(struct elo *elo, unsigned char data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct input_dev *dev = elo->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) elo->data[elo->idx] = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) switch (elo->idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if ((data & 0xc0) != 0xc0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if ((data & 0xc0) != 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if ((data & 0xc0) != 0x40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (data & 0xc0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) input_report_abs(dev, ABS_X, ((elo->data[0] & 0x3f) << 6) | (elo->data[1] & 0x3f));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) input_report_abs(dev, ABS_Y, ((elo->data[2] & 0x3f) << 6) | (elo->data[3] & 0x3f));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (elo->id == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) input_report_key(dev, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if ((data & 0xf0) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) input_report_abs(dev, ABS_PRESSURE, elo->data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) input_report_key(dev, BTN_TOUCH, !!elo->data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) break;
^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) static void elo_process_data_3(struct elo *elo, unsigned char data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct input_dev *dev = elo->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) elo->data[elo->idx] = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) switch (elo->idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if ((data & 0x7f) != 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) input_report_key(dev, BTN_TOUCH, !(elo->data[1] & 0x80));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) input_report_abs(dev, ABS_X, elo->data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) input_report_abs(dev, ABS_Y, elo->data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) elo->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static irqreturn_t elo_interrupt(struct serio *serio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) unsigned char data, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct elo *elo = serio_get_drvdata(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) switch (elo->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) elo_process_data_10(elo, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) elo_process_data_6(elo, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) elo_process_data_3(elo, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static int elo_command_10(struct elo *elo, unsigned char *packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int rc = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) unsigned char csum = 0xaa + ELO10_LEAD_BYTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) mutex_lock(&elo->cmd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) serio_pause_rx(elo->serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) elo->expected_packet = toupper(packet[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) init_completion(&elo->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) serio_continue_rx(elo->serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (serio_write(elo->serio, ELO10_LEAD_BYTE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) for (i = 0; i < ELO10_PACKET_LEN; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) csum += packet[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (serio_write(elo->serio, packet[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (serio_write(elo->serio, csum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) wait_for_completion_timeout(&elo->cmd_done, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (elo->expected_packet == ELO10_TOUCH_PACKET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* We are back in reporting mode, the command was ACKed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) memcpy(packet, elo->response, ELO10_PACKET_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) mutex_unlock(&elo->cmd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static int elo_setup_10(struct elo *elo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static const char *elo_types[] = { "Accu", "Dura", "Intelli", "Carroll" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct input_dev *dev = elo->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) unsigned char packet[ELO10_PACKET_LEN] = { ELO10_ID_CMD };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (elo_command_10(elo, packet))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) dev->id.version = (packet[5] << 8) | packet[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) input_set_abs_params(dev, ABS_X, 96, 4000, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) input_set_abs_params(dev, ABS_Y, 96, 4000, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (packet[3] & ELO10_PRESSURE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) dev_info(&elo->serio->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) "%sTouch touchscreen, fw: %02x.%02x, features: 0x%02x, controller: 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) elo_types[(packet[1] -'0') & 0x03],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) packet[5], packet[4], packet[3], packet[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * elo_disconnect() is the opposite of elo_connect()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static void elo_disconnect(struct serio *serio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct elo *elo = serio_get_drvdata(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) input_get_device(elo->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) input_unregister_device(elo->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) serio_close(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) serio_set_drvdata(serio, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) input_put_device(elo->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) kfree(elo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * elo_connect() is the routine that is called when someone adds a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * new serio device that supports Gunze protocol and registers it as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * an input device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static int elo_connect(struct serio *serio, struct serio_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct elo *elo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) elo = kzalloc(sizeof(struct elo), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (!elo || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) elo->serio = serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) elo->id = serio->id.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) elo->dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) elo->expected_packet = ELO10_TOUCH_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) mutex_init(&elo->cmd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) init_completion(&elo->cmd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) snprintf(elo->phys, sizeof(elo->phys), "%s/input0", serio->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) input_dev->name = "Elo Serial TouchScreen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) input_dev->phys = elo->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) input_dev->id.bustype = BUS_RS232;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) input_dev->id.vendor = SERIO_ELO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) input_dev->id.product = elo->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) input_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) input_dev->dev.parent = &serio->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) serio_set_drvdata(serio, elo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) err = serio_open(serio, drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) switch (elo->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) case 0: /* 10-byte protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (elo_setup_10(elo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) case 1: /* 6-byte protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) input_set_abs_params(input_dev, ABS_PRESSURE, 0, 15, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) case 2: /* 4-byte protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) case 3: /* 3-byte protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) input_set_abs_params(input_dev, ABS_X, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) input_set_abs_params(input_dev, ABS_Y, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) err = input_register_device(elo->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) fail3: serio_close(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) fail2: serio_set_drvdata(serio, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) fail1: input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) kfree(elo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * The serio driver structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static const struct serio_device_id elo_serio_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .type = SERIO_RS232,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) .proto = SERIO_ELO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .id = SERIO_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .extra = SERIO_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) { 0 }
^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) MODULE_DEVICE_TABLE(serio, elo_serio_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static struct serio_driver elo_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) .name = "elo",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) .description = DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .id_table = elo_serio_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .interrupt = elo_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) .connect = elo_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) .disconnect = elo_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) module_serio_driver(elo_drv);