^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) * iNexio 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) 2008 Richard Lemon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Based on the mtouch driver (c) Vojtech Pavlik and Dan Streetman
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * 2008/06/19 Richard Lemon <richard@codelemon.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copied mtouch.c and edited for iNexio 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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define DRIVER_DESC "iNexio serial touchscreen driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) MODULE_AUTHOR("Richard Lemon <richard@codelemon.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Definitions & global arrays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define INEXIO_FORMAT_TOUCH_BIT 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define INEXIO_FORMAT_LENGTH 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define INEXIO_RESPONSE_BEGIN_BYTE 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* todo: check specs for max length of all responses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define INEXIO_MAX_LENGTH 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define INEXIO_MIN_XC 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define INEXIO_MAX_XC 0x3fff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define INEXIO_MIN_YC 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define INEXIO_MAX_YC 0x3fff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define INEXIO_GET_XC(data) (((data[1])<<7) | data[2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define INEXIO_GET_YC(data) (((data[3])<<7) | data[4])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define INEXIO_GET_TOUCHED(data) (INEXIO_FORMAT_TOUCH_BIT & data[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * Per-touchscreen data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct inexio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct serio *serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) unsigned char data[INEXIO_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static void inexio_process_data(struct inexio *pinexio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct input_dev *dev = pinexio->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (INEXIO_FORMAT_LENGTH == ++pinexio->idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) input_report_abs(dev, ABS_X, INEXIO_GET_XC(pinexio->data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) input_report_abs(dev, ABS_Y, INEXIO_GET_YC(pinexio->data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) input_report_key(dev, BTN_TOUCH, INEXIO_GET_TOUCHED(pinexio->data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) pinexio->idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static irqreturn_t inexio_interrupt(struct serio *serio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned char data, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct inexio *pinexio = serio_get_drvdata(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) pinexio->data[pinexio->idx] = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (INEXIO_RESPONSE_BEGIN_BYTE&pinexio->data[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) inexio_process_data(pinexio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) printk(KERN_DEBUG "inexio.c: unknown/unsynchronized data from device, byte %x\n",pinexio->data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * inexio_disconnect() is the opposite of inexio_connect()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static void inexio_disconnect(struct serio *serio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct inexio *pinexio = serio_get_drvdata(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) input_get_device(pinexio->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) input_unregister_device(pinexio->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) serio_close(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) serio_set_drvdata(serio, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) input_put_device(pinexio->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) kfree(pinexio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * inexio_connect() is the routine that is called when someone adds a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * new serio device that supports iNexio protocol and registers it as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * an input device. This is usually accomplished using inputattach.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int inexio_connect(struct serio *serio, struct serio_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct inexio *pinexio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) pinexio = kzalloc(sizeof(struct inexio), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (!pinexio || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) pinexio->serio = serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) pinexio->dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) snprintf(pinexio->phys, sizeof(pinexio->phys), "%s/input0", serio->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) input_dev->name = "iNexio Serial TouchScreen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) input_dev->phys = pinexio->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) input_dev->id.bustype = BUS_RS232;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) input_dev->id.vendor = SERIO_INEXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) input_dev->id.product = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) input_dev->id.version = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) input_dev->dev.parent = &serio->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) input_set_abs_params(pinexio->dev, ABS_X, INEXIO_MIN_XC, INEXIO_MAX_XC, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) input_set_abs_params(pinexio->dev, ABS_Y, INEXIO_MIN_YC, INEXIO_MAX_YC, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) serio_set_drvdata(serio, pinexio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) err = serio_open(serio, drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) err = input_register_device(pinexio->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) fail3: serio_close(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) fail2: serio_set_drvdata(serio, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) fail1: input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) kfree(pinexio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * The serio driver structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static const struct serio_device_id inexio_serio_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .type = SERIO_RS232,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .proto = SERIO_INEXIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .id = SERIO_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .extra = SERIO_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) { 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) MODULE_DEVICE_TABLE(serio, inexio_serio_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static struct serio_driver inexio_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .name = "inexio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) .description = DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .id_table = inexio_serio_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .interrupt = inexio_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .connect = inexio_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .disconnect = inexio_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) module_serio_driver(inexio_drv);