1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
27e577a17SAhmet Inan /*
37e577a17SAhmet Inan * Driver for I2C connected EETI EXC3000 multiple touch controller
47e577a17SAhmet Inan *
57e577a17SAhmet Inan * Copyright (C) 2017 Ahmet Inan <inan@distec.de>
67e577a17SAhmet Inan *
77e577a17SAhmet Inan * minimal implementation based on egalax_ts.c and egalax_i2c.c
87e577a17SAhmet Inan */
97e577a17SAhmet Inan
10bac6eb72SAndreas Helbech Kleist #include <linux/acpi.h>
117e577a17SAhmet Inan #include <linux/bitops.h>
1227aced19SSebastian Reichel #include <linux/delay.h>
137e577a17SAhmet Inan #include <linux/device.h>
1427aced19SSebastian Reichel #include <linux/gpio/consumer.h>
157e577a17SAhmet Inan #include <linux/i2c.h>
167e577a17SAhmet Inan #include <linux/input.h>
177e577a17SAhmet Inan #include <linux/input/mt.h>
187e577a17SAhmet Inan #include <linux/input/touchscreen.h>
197e577a17SAhmet Inan #include <linux/interrupt.h>
207e577a17SAhmet Inan #include <linux/module.h>
217e577a17SAhmet Inan #include <linux/of.h>
22*0d384e59SMike Looijmans #include <linux/regulator/consumer.h>
233bdd21c6SSebastian Reichel #include <linux/sizes.h>
247e577a17SAhmet Inan #include <linux/timer.h>
257e577a17SAhmet Inan #include <asm/unaligned.h>
267e577a17SAhmet Inan
277e577a17SAhmet Inan #define EXC3000_NUM_SLOTS 10
287e577a17SAhmet Inan #define EXC3000_SLOTS_PER_FRAME 5
297e577a17SAhmet Inan #define EXC3000_LEN_FRAME 66
30102feb1dSLucas Stach #define EXC3000_LEN_VENDOR_REQUEST 68
317e577a17SAhmet Inan #define EXC3000_LEN_POINT 10
323bdd21c6SSebastian Reichel
33d862a306SSebastian Reichel #define EXC3000_LEN_MODEL_NAME 16
34d862a306SSebastian Reichel #define EXC3000_LEN_FW_VERSION 16
35d862a306SSebastian Reichel
36a63d0120SLucas Stach #define EXC3000_VENDOR_EVENT 0x03
373bdd21c6SSebastian Reichel #define EXC3000_MT1_EVENT 0x06
383bdd21c6SSebastian Reichel #define EXC3000_MT2_EVENT 0x18
393bdd21c6SSebastian Reichel
407e577a17SAhmet Inan #define EXC3000_TIMEOUT_MS 100
417e577a17SAhmet Inan
4227aced19SSebastian Reichel #define EXC3000_RESET_MS 10
4327aced19SSebastian Reichel #define EXC3000_READY_MS 100
4427aced19SSebastian Reichel
453bdd21c6SSebastian Reichel static const struct i2c_device_id exc3000_id[];
463bdd21c6SSebastian Reichel
473bdd21c6SSebastian Reichel struct eeti_dev_info {
483bdd21c6SSebastian Reichel const char *name;
493bdd21c6SSebastian Reichel int max_xy;
503bdd21c6SSebastian Reichel };
513bdd21c6SSebastian Reichel
523bdd21c6SSebastian Reichel enum eeti_dev_id {
533bdd21c6SSebastian Reichel EETI_EXC3000,
543bdd21c6SSebastian Reichel EETI_EXC80H60,
553bdd21c6SSebastian Reichel EETI_EXC80H84,
563bdd21c6SSebastian Reichel };
573bdd21c6SSebastian Reichel
583bdd21c6SSebastian Reichel static struct eeti_dev_info exc3000_info[] = {
593bdd21c6SSebastian Reichel [EETI_EXC3000] = {
603bdd21c6SSebastian Reichel .name = "EETI EXC3000 Touch Screen",
613bdd21c6SSebastian Reichel .max_xy = SZ_4K - 1,
623bdd21c6SSebastian Reichel },
633bdd21c6SSebastian Reichel [EETI_EXC80H60] = {
643bdd21c6SSebastian Reichel .name = "EETI EXC80H60 Touch Screen",
653bdd21c6SSebastian Reichel .max_xy = SZ_16K - 1,
663bdd21c6SSebastian Reichel },
673bdd21c6SSebastian Reichel [EETI_EXC80H84] = {
683bdd21c6SSebastian Reichel .name = "EETI EXC80H84 Touch Screen",
693bdd21c6SSebastian Reichel .max_xy = SZ_16K - 1,
703bdd21c6SSebastian Reichel },
713bdd21c6SSebastian Reichel };
723bdd21c6SSebastian Reichel
737e577a17SAhmet Inan struct exc3000_data {
747e577a17SAhmet Inan struct i2c_client *client;
753bdd21c6SSebastian Reichel const struct eeti_dev_info *info;
767e577a17SAhmet Inan struct input_dev *input;
777e577a17SAhmet Inan struct touchscreen_properties prop;
7827aced19SSebastian Reichel struct gpio_desc *reset;
797e577a17SAhmet Inan struct timer_list timer;
807e577a17SAhmet Inan u8 buf[2 * EXC3000_LEN_FRAME];
81d862a306SSebastian Reichel struct completion wait_event;
82d862a306SSebastian Reichel struct mutex query_lock;
837e577a17SAhmet Inan };
847e577a17SAhmet Inan
exc3000_report_slots(struct input_dev * input,struct touchscreen_properties * prop,const u8 * buf,int num)857e577a17SAhmet Inan static void exc3000_report_slots(struct input_dev *input,
867e577a17SAhmet Inan struct touchscreen_properties *prop,
877e577a17SAhmet Inan const u8 *buf, int num)
887e577a17SAhmet Inan {
897e577a17SAhmet Inan for (; num--; buf += EXC3000_LEN_POINT) {
907e577a17SAhmet Inan if (buf[0] & BIT(0)) {
917e577a17SAhmet Inan input_mt_slot(input, buf[1]);
927e577a17SAhmet Inan input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
937e577a17SAhmet Inan touchscreen_report_pos(input, prop,
947e577a17SAhmet Inan get_unaligned_le16(buf + 2),
957e577a17SAhmet Inan get_unaligned_le16(buf + 4),
967e577a17SAhmet Inan true);
977e577a17SAhmet Inan }
987e577a17SAhmet Inan }
997e577a17SAhmet Inan }
1007e577a17SAhmet Inan
exc3000_timer(struct timer_list * t)1017e577a17SAhmet Inan static void exc3000_timer(struct timer_list *t)
1027e577a17SAhmet Inan {
1037e577a17SAhmet Inan struct exc3000_data *data = from_timer(data, t, timer);
1047e577a17SAhmet Inan
1057e577a17SAhmet Inan input_mt_sync_frame(data->input);
1067e577a17SAhmet Inan input_sync(data->input);
1077e577a17SAhmet Inan }
1087e577a17SAhmet Inan
exc3000_schedule_timer(struct exc3000_data * data)109a63d0120SLucas Stach static inline void exc3000_schedule_timer(struct exc3000_data *data)
110a63d0120SLucas Stach {
111a63d0120SLucas Stach mod_timer(&data->timer, jiffies + msecs_to_jiffies(EXC3000_TIMEOUT_MS));
112a63d0120SLucas Stach }
113a63d0120SLucas Stach
exc3000_shutdown_timer(void * timer)11479c81d13SDmitry Torokhov static void exc3000_shutdown_timer(void *timer)
11579c81d13SDmitry Torokhov {
11679c81d13SDmitry Torokhov timer_shutdown_sync(timer);
11779c81d13SDmitry Torokhov }
11879c81d13SDmitry Torokhov
exc3000_read_frame(struct exc3000_data * data,u8 * buf)1193bdd21c6SSebastian Reichel static int exc3000_read_frame(struct exc3000_data *data, u8 *buf)
1207e577a17SAhmet Inan {
1213bdd21c6SSebastian Reichel struct i2c_client *client = data->client;
1227e577a17SAhmet Inan int ret;
1237e577a17SAhmet Inan
1247e577a17SAhmet Inan ret = i2c_master_send(client, "'", 2);
1257e577a17SAhmet Inan if (ret < 0)
1267e577a17SAhmet Inan return ret;
1277e577a17SAhmet Inan
1287e577a17SAhmet Inan if (ret != 2)
1297e577a17SAhmet Inan return -EIO;
1307e577a17SAhmet Inan
1317e577a17SAhmet Inan ret = i2c_master_recv(client, buf, EXC3000_LEN_FRAME);
1327e577a17SAhmet Inan if (ret < 0)
1337e577a17SAhmet Inan return ret;
1347e577a17SAhmet Inan
1357e577a17SAhmet Inan if (ret != EXC3000_LEN_FRAME)
1367e577a17SAhmet Inan return -EIO;
1377e577a17SAhmet Inan
1383bdd21c6SSebastian Reichel if (get_unaligned_le16(buf) != EXC3000_LEN_FRAME)
1393bdd21c6SSebastian Reichel return -EINVAL;
1403bdd21c6SSebastian Reichel
1417e577a17SAhmet Inan return 0;
1427e577a17SAhmet Inan }
1437e577a17SAhmet Inan
exc3000_handle_mt_event(struct exc3000_data * data)144a63d0120SLucas Stach static int exc3000_handle_mt_event(struct exc3000_data *data)
1457e577a17SAhmet Inan {
146a63d0120SLucas Stach struct input_dev *input = data->input;
147a63d0120SLucas Stach int ret, total_slots;
148a63d0120SLucas Stach u8 *buf = data->buf;
1497e577a17SAhmet Inan
150a63d0120SLucas Stach total_slots = buf[3];
151a63d0120SLucas Stach if (!total_slots || total_slots > EXC3000_NUM_SLOTS) {
152a63d0120SLucas Stach ret = -EINVAL;
153a63d0120SLucas Stach goto out_fail;
154a63d0120SLucas Stach }
1557e577a17SAhmet Inan
156a63d0120SLucas Stach if (total_slots > EXC3000_SLOTS_PER_FRAME) {
1577e577a17SAhmet Inan /* Read 2nd frame to get the rest of the contacts. */
158a63d0120SLucas Stach ret = exc3000_read_frame(data, buf + EXC3000_LEN_FRAME);
159a63d0120SLucas Stach if (ret)
160a63d0120SLucas Stach goto out_fail;
1617e577a17SAhmet Inan
1627e577a17SAhmet Inan /* 2nd chunk must have number of contacts set to 0. */
163a63d0120SLucas Stach if (buf[EXC3000_LEN_FRAME + 3] != 0) {
164a63d0120SLucas Stach ret = -EINVAL;
165a63d0120SLucas Stach goto out_fail;
166a63d0120SLucas Stach }
1677e577a17SAhmet Inan }
1687e577a17SAhmet Inan
169a63d0120SLucas Stach /*
170a63d0120SLucas Stach * We read full state successfully, no contacts will be "stuck".
171a63d0120SLucas Stach */
172a63d0120SLucas Stach del_timer_sync(&data->timer);
173a63d0120SLucas Stach
174a63d0120SLucas Stach while (total_slots > 0) {
175a63d0120SLucas Stach int slots = min(total_slots, EXC3000_SLOTS_PER_FRAME);
176a63d0120SLucas Stach
177a63d0120SLucas Stach exc3000_report_slots(input, &data->prop, buf + 4, slots);
178a63d0120SLucas Stach total_slots -= slots;
179a63d0120SLucas Stach buf += EXC3000_LEN_FRAME;
180a63d0120SLucas Stach }
181a63d0120SLucas Stach
182a63d0120SLucas Stach input_mt_sync_frame(input);
183a63d0120SLucas Stach input_sync(input);
184a63d0120SLucas Stach
1857e577a17SAhmet Inan return 0;
186a63d0120SLucas Stach
187a63d0120SLucas Stach out_fail:
188a63d0120SLucas Stach /* Schedule a timer to release "stuck" contacts */
189a63d0120SLucas Stach exc3000_schedule_timer(data);
190a63d0120SLucas Stach
191a63d0120SLucas Stach return ret;
1927e577a17SAhmet Inan }
1937e577a17SAhmet Inan
exc3000_interrupt(int irq,void * dev_id)1947e577a17SAhmet Inan static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
1957e577a17SAhmet Inan {
1967e577a17SAhmet Inan struct exc3000_data *data = dev_id;
1977e577a17SAhmet Inan u8 *buf = data->buf;
198a63d0120SLucas Stach int ret;
1997e577a17SAhmet Inan
200a63d0120SLucas Stach ret = exc3000_read_frame(data, buf);
201a63d0120SLucas Stach if (ret) {
202a63d0120SLucas Stach /* Schedule a timer to release "stuck" contacts */
203a63d0120SLucas Stach exc3000_schedule_timer(data);
204a63d0120SLucas Stach goto out;
205a63d0120SLucas Stach }
206a63d0120SLucas Stach
207a63d0120SLucas Stach switch (buf[2]) {
208a63d0120SLucas Stach case EXC3000_VENDOR_EVENT:
209d862a306SSebastian Reichel complete(&data->wait_event);
210a63d0120SLucas Stach break;
211a63d0120SLucas Stach
212a63d0120SLucas Stach case EXC3000_MT1_EVENT:
213a63d0120SLucas Stach case EXC3000_MT2_EVENT:
214a63d0120SLucas Stach exc3000_handle_mt_event(data);
215a63d0120SLucas Stach break;
216a63d0120SLucas Stach
217a63d0120SLucas Stach default:
218a63d0120SLucas Stach break;
219d862a306SSebastian Reichel }
220d862a306SSebastian Reichel
2217e577a17SAhmet Inan out:
2227e577a17SAhmet Inan return IRQ_HANDLED;
2237e577a17SAhmet Inan }
2247e577a17SAhmet Inan
exc3000_vendor_data_request(struct exc3000_data * data,u8 * request,u8 request_len,u8 * response,int timeout)225102feb1dSLucas Stach static int exc3000_vendor_data_request(struct exc3000_data *data, u8 *request,
226102feb1dSLucas Stach u8 request_len, u8 *response, int timeout)
227102feb1dSLucas Stach {
228102feb1dSLucas Stach u8 buf[EXC3000_LEN_VENDOR_REQUEST] = { 0x67, 0x00, 0x42, 0x00, 0x03 };
229102feb1dSLucas Stach int ret;
2306bb7144cSMiaoqian Lin unsigned long time_left;
231102feb1dSLucas Stach
232102feb1dSLucas Stach mutex_lock(&data->query_lock);
233102feb1dSLucas Stach
234102feb1dSLucas Stach reinit_completion(&data->wait_event);
235102feb1dSLucas Stach
236102feb1dSLucas Stach buf[5] = request_len;
237102feb1dSLucas Stach memcpy(&buf[6], request, request_len);
238102feb1dSLucas Stach
239102feb1dSLucas Stach ret = i2c_master_send(data->client, buf, EXC3000_LEN_VENDOR_REQUEST);
240102feb1dSLucas Stach if (ret < 0)
241102feb1dSLucas Stach goto out_unlock;
242102feb1dSLucas Stach
243102feb1dSLucas Stach if (response) {
2446bb7144cSMiaoqian Lin time_left = wait_for_completion_timeout(&data->wait_event,
245102feb1dSLucas Stach timeout * HZ);
2466bb7144cSMiaoqian Lin if (time_left == 0) {
247102feb1dSLucas Stach ret = -ETIMEDOUT;
248102feb1dSLucas Stach goto out_unlock;
249102feb1dSLucas Stach }
250102feb1dSLucas Stach
251102feb1dSLucas Stach if (data->buf[3] >= EXC3000_LEN_FRAME) {
252102feb1dSLucas Stach ret = -ENOSPC;
253102feb1dSLucas Stach goto out_unlock;
254102feb1dSLucas Stach }
255102feb1dSLucas Stach
256102feb1dSLucas Stach memcpy(response, &data->buf[4], data->buf[3]);
257102feb1dSLucas Stach ret = data->buf[3];
258102feb1dSLucas Stach }
259102feb1dSLucas Stach
260102feb1dSLucas Stach out_unlock:
261102feb1dSLucas Stach mutex_unlock(&data->query_lock);
262102feb1dSLucas Stach
263102feb1dSLucas Stach return ret;
264102feb1dSLucas Stach }
265102feb1dSLucas Stach
fw_version_show(struct device * dev,struct device_attribute * attr,char * buf)266d862a306SSebastian Reichel static ssize_t fw_version_show(struct device *dev,
267d862a306SSebastian Reichel struct device_attribute *attr, char *buf)
268d862a306SSebastian Reichel {
269d862a306SSebastian Reichel struct i2c_client *client = to_i2c_client(dev);
270d862a306SSebastian Reichel struct exc3000_data *data = i2c_get_clientdata(client);
271102feb1dSLucas Stach u8 response[EXC3000_LEN_FRAME];
272102feb1dSLucas Stach int ret;
273d862a306SSebastian Reichel
274c929ac9eSLucas Stach /* query bootloader info */
275c929ac9eSLucas Stach ret = exc3000_vendor_data_request(data,
276c929ac9eSLucas Stach (u8[]){0x39, 0x02}, 2, response, 1);
277c929ac9eSLucas Stach if (ret < 0)
278c929ac9eSLucas Stach return ret;
279c929ac9eSLucas Stach
280c929ac9eSLucas Stach /*
281c929ac9eSLucas Stach * If the bootloader version is non-zero then the device is in
282c929ac9eSLucas Stach * bootloader mode and won't answer a query for the application FW
283c929ac9eSLucas Stach * version, so we just use the bootloader version info.
284c929ac9eSLucas Stach */
285c929ac9eSLucas Stach if (response[2] || response[3])
286c929ac9eSLucas Stach return sprintf(buf, "%d.%d\n", response[2], response[3]);
287c929ac9eSLucas Stach
288102feb1dSLucas Stach ret = exc3000_vendor_data_request(data, (u8[]){'D'}, 1, response, 1);
289102feb1dSLucas Stach if (ret < 0)
290102feb1dSLucas Stach return ret;
291d862a306SSebastian Reichel
292102feb1dSLucas Stach return sprintf(buf, "%s\n", &response[1]);
293d862a306SSebastian Reichel }
294d862a306SSebastian Reichel static DEVICE_ATTR_RO(fw_version);
295d862a306SSebastian Reichel
model_show(struct device * dev,struct device_attribute * attr,char * buf)296d862a306SSebastian Reichel static ssize_t model_show(struct device *dev,
297d862a306SSebastian Reichel struct device_attribute *attr, char *buf)
298d862a306SSebastian Reichel {
299d862a306SSebastian Reichel struct i2c_client *client = to_i2c_client(dev);
300d862a306SSebastian Reichel struct exc3000_data *data = i2c_get_clientdata(client);
301102feb1dSLucas Stach u8 response[EXC3000_LEN_FRAME];
302102feb1dSLucas Stach int ret;
303d862a306SSebastian Reichel
304102feb1dSLucas Stach ret = exc3000_vendor_data_request(data, (u8[]){'E'}, 1, response, 1);
305102feb1dSLucas Stach if (ret < 0)
306102feb1dSLucas Stach return ret;
307d862a306SSebastian Reichel
308102feb1dSLucas Stach return sprintf(buf, "%s\n", &response[1]);
309d862a306SSebastian Reichel }
310d862a306SSebastian Reichel static DEVICE_ATTR_RO(model);
311d862a306SSebastian Reichel
type_show(struct device * dev,struct device_attribute * attr,char * buf)312ad117c55SLucas Stach static ssize_t type_show(struct device *dev,
313ad117c55SLucas Stach struct device_attribute *attr, char *buf)
314ad117c55SLucas Stach {
315ad117c55SLucas Stach struct i2c_client *client = to_i2c_client(dev);
316ad117c55SLucas Stach struct exc3000_data *data = i2c_get_clientdata(client);
317ad117c55SLucas Stach u8 response[EXC3000_LEN_FRAME];
318ad117c55SLucas Stach int ret;
319ad117c55SLucas Stach
320ad117c55SLucas Stach ret = exc3000_vendor_data_request(data, (u8[]){'F'}, 1, response, 1);
321ad117c55SLucas Stach if (ret < 0)
322ad117c55SLucas Stach return ret;
323ad117c55SLucas Stach
324ad117c55SLucas Stach return sprintf(buf, "%s\n", &response[1]);
325ad117c55SLucas Stach }
326ad117c55SLucas Stach static DEVICE_ATTR_RO(type);
327ad117c55SLucas Stach
328d862a306SSebastian Reichel static struct attribute *sysfs_attrs[] = {
329d862a306SSebastian Reichel &dev_attr_fw_version.attr,
330d862a306SSebastian Reichel &dev_attr_model.attr,
331ad117c55SLucas Stach &dev_attr_type.attr,
332d862a306SSebastian Reichel NULL
333d862a306SSebastian Reichel };
334d862a306SSebastian Reichel
335d862a306SSebastian Reichel static struct attribute_group exc3000_attribute_group = {
336d862a306SSebastian Reichel .attrs = sysfs_attrs
337d862a306SSebastian Reichel };
338d862a306SSebastian Reichel
exc3000_probe(struct i2c_client * client)339deae5764SSebastian Reichel static int exc3000_probe(struct i2c_client *client)
3407e577a17SAhmet Inan {
3417e577a17SAhmet Inan struct exc3000_data *data;
3427e577a17SAhmet Inan struct input_dev *input;
343d862a306SSebastian Reichel int error, max_xy, retry;
3447e577a17SAhmet Inan
3457e577a17SAhmet Inan data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
3467e577a17SAhmet Inan if (!data)
3477e577a17SAhmet Inan return -ENOMEM;
3487e577a17SAhmet Inan
3497e577a17SAhmet Inan data->client = client;
3503bdd21c6SSebastian Reichel data->info = device_get_match_data(&client->dev);
3513bdd21c6SSebastian Reichel if (!data->info) {
3523bdd21c6SSebastian Reichel enum eeti_dev_id eeti_dev_id =
3533bdd21c6SSebastian Reichel i2c_match_id(exc3000_id, client)->driver_data;
3543bdd21c6SSebastian Reichel data->info = &exc3000_info[eeti_dev_id];
3553bdd21c6SSebastian Reichel }
3567e577a17SAhmet Inan timer_setup(&data->timer, exc3000_timer, 0);
357d862a306SSebastian Reichel init_completion(&data->wait_event);
358d862a306SSebastian Reichel mutex_init(&data->query_lock);
3597e577a17SAhmet Inan
36027aced19SSebastian Reichel data->reset = devm_gpiod_get_optional(&client->dev, "reset",
36127aced19SSebastian Reichel GPIOD_OUT_HIGH);
36227aced19SSebastian Reichel if (IS_ERR(data->reset))
36327aced19SSebastian Reichel return PTR_ERR(data->reset);
36427aced19SSebastian Reichel
365*0d384e59SMike Looijmans /* For proper reset sequence, enable power while reset asserted */
366*0d384e59SMike Looijmans error = devm_regulator_get_enable(&client->dev, "vdd");
367*0d384e59SMike Looijmans if (error && error != -ENODEV)
368*0d384e59SMike Looijmans return dev_err_probe(&client->dev, error,
369*0d384e59SMike Looijmans "failed to request vdd regulator\n");
370*0d384e59SMike Looijmans
37127aced19SSebastian Reichel if (data->reset) {
37227aced19SSebastian Reichel msleep(EXC3000_RESET_MS);
37327aced19SSebastian Reichel gpiod_set_value_cansleep(data->reset, 0);
37427aced19SSebastian Reichel msleep(EXC3000_READY_MS);
37527aced19SSebastian Reichel }
37627aced19SSebastian Reichel
3777e577a17SAhmet Inan input = devm_input_allocate_device(&client->dev);
3787e577a17SAhmet Inan if (!input)
3797e577a17SAhmet Inan return -ENOMEM;
3807e577a17SAhmet Inan
3817e577a17SAhmet Inan data->input = input;
382d862a306SSebastian Reichel input_set_drvdata(input, data);
3837e577a17SAhmet Inan
3843bdd21c6SSebastian Reichel input->name = data->info->name;
3857e577a17SAhmet Inan input->id.bustype = BUS_I2C;
3867e577a17SAhmet Inan
3873bdd21c6SSebastian Reichel max_xy = data->info->max_xy;
3883bdd21c6SSebastian Reichel input_set_abs_params(input, ABS_MT_POSITION_X, 0, max_xy, 0, 0);
3893bdd21c6SSebastian Reichel input_set_abs_params(input, ABS_MT_POSITION_Y, 0, max_xy, 0, 0);
3903bdd21c6SSebastian Reichel
3917e577a17SAhmet Inan touchscreen_parse_properties(input, true, &data->prop);
3927e577a17SAhmet Inan
3937e577a17SAhmet Inan error = input_mt_init_slots(input, EXC3000_NUM_SLOTS,
3947e577a17SAhmet Inan INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
3957e577a17SAhmet Inan if (error)
3967e577a17SAhmet Inan return error;
3977e577a17SAhmet Inan
3987e577a17SAhmet Inan error = input_register_device(input);
3997e577a17SAhmet Inan if (error)
4007e577a17SAhmet Inan return error;
4017e577a17SAhmet Inan
40279c81d13SDmitry Torokhov error = devm_add_action_or_reset(&client->dev, exc3000_shutdown_timer,
40379c81d13SDmitry Torokhov &data->timer);
40479c81d13SDmitry Torokhov if (error)
40579c81d13SDmitry Torokhov return error;
40679c81d13SDmitry Torokhov
4077e577a17SAhmet Inan error = devm_request_threaded_irq(&client->dev, client->irq,
4087e577a17SAhmet Inan NULL, exc3000_interrupt, IRQF_ONESHOT,
4097e577a17SAhmet Inan client->name, data);
4107e577a17SAhmet Inan if (error)
4117e577a17SAhmet Inan return error;
4127e577a17SAhmet Inan
413d862a306SSebastian Reichel /*
414d862a306SSebastian Reichel * I²C does not have built-in recovery, so retry on failure. This
415d862a306SSebastian Reichel * ensures, that the device probe will not fail for temporary issues
416d862a306SSebastian Reichel * on the bus. This is not needed for the sysfs calls (userspace
417d862a306SSebastian Reichel * will receive the error code and can start another query) and
418d862a306SSebastian Reichel * cannot be done for touch events (but that only means loosing one
419d862a306SSebastian Reichel * or two touch events anyways).
420d862a306SSebastian Reichel */
421d862a306SSebastian Reichel for (retry = 0; retry < 3; retry++) {
422102feb1dSLucas Stach u8 response[EXC3000_LEN_FRAME];
423102feb1dSLucas Stach
424102feb1dSLucas Stach error = exc3000_vendor_data_request(data, (u8[]){'E'}, 1,
425102feb1dSLucas Stach response, 1);
426102feb1dSLucas Stach if (error > 0) {
427102feb1dSLucas Stach dev_dbg(&client->dev, "TS Model: %s", &response[1]);
428102feb1dSLucas Stach error = 0;
429d862a306SSebastian Reichel break;
430102feb1dSLucas Stach }
431d862a306SSebastian Reichel dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n",
432d862a306SSebastian Reichel retry + 1, error);
433d862a306SSebastian Reichel }
434d862a306SSebastian Reichel
435d862a306SSebastian Reichel if (error)
436d862a306SSebastian Reichel return error;
437d862a306SSebastian Reichel
438d862a306SSebastian Reichel i2c_set_clientdata(client, data);
439d862a306SSebastian Reichel
440d862a306SSebastian Reichel error = devm_device_add_group(&client->dev, &exc3000_attribute_group);
441d862a306SSebastian Reichel if (error)
442d862a306SSebastian Reichel return error;
443d862a306SSebastian Reichel
4447e577a17SAhmet Inan return 0;
4457e577a17SAhmet Inan }
4467e577a17SAhmet Inan
4477e577a17SAhmet Inan static const struct i2c_device_id exc3000_id[] = {
4483bdd21c6SSebastian Reichel { "exc3000", EETI_EXC3000 },
4493bdd21c6SSebastian Reichel { "exc80h60", EETI_EXC80H60 },
4503bdd21c6SSebastian Reichel { "exc80h84", EETI_EXC80H84 },
4517e577a17SAhmet Inan { }
4527e577a17SAhmet Inan };
4537e577a17SAhmet Inan MODULE_DEVICE_TABLE(i2c, exc3000_id);
4547e577a17SAhmet Inan
4557e577a17SAhmet Inan #ifdef CONFIG_OF
4567e577a17SAhmet Inan static const struct of_device_id exc3000_of_match[] = {
4573bdd21c6SSebastian Reichel { .compatible = "eeti,exc3000", .data = &exc3000_info[EETI_EXC3000] },
4583bdd21c6SSebastian Reichel { .compatible = "eeti,exc80h60", .data = &exc3000_info[EETI_EXC80H60] },
4593bdd21c6SSebastian Reichel { .compatible = "eeti,exc80h84", .data = &exc3000_info[EETI_EXC80H84] },
4607e577a17SAhmet Inan { }
4617e577a17SAhmet Inan };
4627e577a17SAhmet Inan MODULE_DEVICE_TABLE(of, exc3000_of_match);
4637e577a17SAhmet Inan #endif
4647e577a17SAhmet Inan
465bac6eb72SAndreas Helbech Kleist #ifdef CONFIG_ACPI
466bac6eb72SAndreas Helbech Kleist static const struct acpi_device_id exc3000_acpi_match[] = {
467bac6eb72SAndreas Helbech Kleist { "EGA00001", .driver_data = (kernel_ulong_t)&exc3000_info[EETI_EXC80H60] },
468bac6eb72SAndreas Helbech Kleist { }
469bac6eb72SAndreas Helbech Kleist };
470bac6eb72SAndreas Helbech Kleist MODULE_DEVICE_TABLE(acpi, exc3000_acpi_match);
471bac6eb72SAndreas Helbech Kleist #endif
472bac6eb72SAndreas Helbech Kleist
4737e577a17SAhmet Inan static struct i2c_driver exc3000_driver = {
4747e577a17SAhmet Inan .driver = {
4757e577a17SAhmet Inan .name = "exc3000",
4767e577a17SAhmet Inan .of_match_table = of_match_ptr(exc3000_of_match),
477bac6eb72SAndreas Helbech Kleist .acpi_match_table = ACPI_PTR(exc3000_acpi_match),
4787e577a17SAhmet Inan },
4797e577a17SAhmet Inan .id_table = exc3000_id,
480d8bde56dSUwe Kleine-König .probe = exc3000_probe,
4817e577a17SAhmet Inan };
4827e577a17SAhmet Inan
4837e577a17SAhmet Inan module_i2c_driver(exc3000_driver);
4847e577a17SAhmet Inan
4857e577a17SAhmet Inan MODULE_AUTHOR("Ahmet Inan <inan@distec.de>");
4867e577a17SAhmet Inan MODULE_DESCRIPTION("I2C connected EETI EXC3000 multiple touch controller driver");
4877e577a17SAhmet Inan MODULE_LICENSE("GPL v2");
488