@@ -0,0 +1,154 @@
+/*
+ * Driver for I2C connected EETI EXC3000 multiple touch controller
+ *
+ * Copyright (C) 2017 Ahmet Inan <inan@distec.de>
+ *
+ * minimal implementation based on egalax_ts.c and egalax_i2c.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/i2c.h>
+#include <linux/input.h>
+#include <linux/irq.h>
+#include <linux/input/mt.h>
+
+#define NUM_SLOTS 10
+#define PER_FRAME 5
+#define LEN_FRAME 66
+#define LEN_POINT 10
+
+struct exc3000_data {
+ struct i2c_client *client;
+ struct input_dev *input;
+ unsigned char buf[2 * LEN_FRAME];
+};
+
+static void exc3000_process(struct input_dev *input,
+ unsigned char *buf, int num)
+{
+ while (num--) {
+ int dn, id, x, y;
+
+ dn = buf[0] & 1;
+ id = buf[1];
+ x = (buf[3] << 8) | buf[2];
+ y = (buf[5] << 8) | buf[4];
+ buf += LEN_POINT;
+ if (id >= NUM_SLOTS)
+ continue;
+ input_mt_slot(input, id);
+ input_mt_report_slot_state(input, MT_TOOL_FINGER, dn);
+ if (dn) {
+ input_report_abs(input, ABS_MT_POSITION_X, x);
+ input_report_abs(input, ABS_MT_POSITION_Y, y);
+ }
+ }
+}
+
+static int exc3000_read(struct i2c_client *client, unsigned char *buf)
+{
+ if (i2c_master_send(client, "'", 2) != 2)
+ return 1;
+ memset(buf, 0, LEN_FRAME);
+ i2c_master_recv(client, buf, LEN_FRAME);
+ return buf[0] != 0x42 || buf[1] != 0x00 || buf[2] != 0x06;
+}
+
+static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
+{
+ struct exc3000_data *data = (struct exc3000_data *)dev_id;
+ struct i2c_client *client = data->client;
+ struct input_dev *input = data->input;
+ unsigned char *buf = data->buf;
+
+ if (exc3000_read(client, buf) || !buf[3] || buf[3] > NUM_SLOTS)
+ return IRQ_HANDLED;
+ if (buf[3] <= PER_FRAME) {
+ exc3000_process(input, buf + 4, buf[3]);
+ } else {
+ if (exc3000_read(client, buf + LEN_FRAME) || buf[LEN_FRAME + 3])
+ return IRQ_HANDLED;
+ exc3000_process(input, buf + 4, PER_FRAME);
+ exc3000_process(input, buf + LEN_FRAME + 4, buf[3] - PER_FRAME);
+ }
+ input_mt_report_pointer_emulation(input, true);
+ input_sync(input);
+ return IRQ_HANDLED;
+}
+
+static int exc3000_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct exc3000_data *data;
+ struct input_dev *input;
+ int error;
+
+ data = (struct exc3000_data *)devm_kzalloc(&client->dev,
+ sizeof(struct exc3000_data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ input = devm_input_allocate_device(&client->dev);
+ if (!input)
+ return -ENOMEM;
+
+ input->name = "EETI EXC3000 Touch Screen";
+ input->id.bustype = BUS_I2C;
+
+ __set_bit(EV_ABS, input->evbit);
+ __set_bit(EV_KEY, input->evbit);
+ __set_bit(BTN_TOUCH, input->keybit);
+ input_set_abs_params(input, ABS_X, 0, 4096, 0, 0);
+ input_set_abs_params(input, ABS_Y, 0, 4096, 0, 0);
+ input_set_abs_params(input, ABS_MT_POSITION_X, 0, 4096, 0, 0);
+ input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 4096, 0, 0);
+ input_mt_init_slots(input, NUM_SLOTS, 0);
+
+ error = input_register_device(input);
+ if (error)
+ return error;
+
+ data->input = input;
+ data->client = client;
+ i2c_set_clientdata(client, data);
+
+ error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+ exc3000_interrupt, IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+ client->name, data);
+ if (error)
+ return error;
+
+ return 0;
+}
+
+static const struct i2c_device_id exc3000_id[] = {
+ { "exc3000", 0 },
+ { }
+};
+
+static const struct of_device_id exc3000_dt_ids[] = {
+ { .compatible = "eeti,exc3000" },
+ { }
+};
+
+MODULE_DEVICE_TABLE(i2c, exc3000_id);
+
+static struct i2c_driver exc3000_driver = {
+ .driver = {
+ .name = "exc3000",
+ .of_match_table = exc3000_dt_ids,
+ },
+ .id_table = exc3000_id,
+ .probe = exc3000_probe,
+};
+
+module_i2c_driver(exc3000_driver);
+
+MODULE_AUTHOR("Ahmet Inan <inan@distec.de>");
+MODULE_DESCRIPTION("I2C connected EETI EXC3000 multiple touch controller driver");
+MODULE_LICENSE("GPL");