18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Driver for I2C connected EETI EXC3000 multiple touch controller 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2017 Ahmet Inan <inan@distec.de> 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * minimal implementation based on egalax_ts.c and egalax_i2c.c 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/bitops.h> 118c2ecf20Sopenharmony_ci#include <linux/delay.h> 128c2ecf20Sopenharmony_ci#include <linux/device.h> 138c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h> 148c2ecf20Sopenharmony_ci#include <linux/i2c.h> 158c2ecf20Sopenharmony_ci#include <linux/input.h> 168c2ecf20Sopenharmony_ci#include <linux/input/mt.h> 178c2ecf20Sopenharmony_ci#include <linux/input/touchscreen.h> 188c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 198c2ecf20Sopenharmony_ci#include <linux/module.h> 208c2ecf20Sopenharmony_ci#include <linux/of.h> 218c2ecf20Sopenharmony_ci#include <linux/sizes.h> 228c2ecf20Sopenharmony_ci#include <linux/timer.h> 238c2ecf20Sopenharmony_ci#include <asm/unaligned.h> 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define EXC3000_NUM_SLOTS 10 268c2ecf20Sopenharmony_ci#define EXC3000_SLOTS_PER_FRAME 5 278c2ecf20Sopenharmony_ci#define EXC3000_LEN_FRAME 66 288c2ecf20Sopenharmony_ci#define EXC3000_LEN_POINT 10 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define EXC3000_LEN_MODEL_NAME 16 318c2ecf20Sopenharmony_ci#define EXC3000_LEN_FW_VERSION 16 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define EXC3000_MT1_EVENT 0x06 348c2ecf20Sopenharmony_ci#define EXC3000_MT2_EVENT 0x18 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define EXC3000_TIMEOUT_MS 100 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define EXC3000_RESET_MS 10 398c2ecf20Sopenharmony_ci#define EXC3000_READY_MS 100 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic const struct i2c_device_id exc3000_id[]; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistruct eeti_dev_info { 448c2ecf20Sopenharmony_ci const char *name; 458c2ecf20Sopenharmony_ci int max_xy; 468c2ecf20Sopenharmony_ci}; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cienum eeti_dev_id { 498c2ecf20Sopenharmony_ci EETI_EXC3000, 508c2ecf20Sopenharmony_ci EETI_EXC80H60, 518c2ecf20Sopenharmony_ci EETI_EXC80H84, 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic struct eeti_dev_info exc3000_info[] = { 558c2ecf20Sopenharmony_ci [EETI_EXC3000] = { 568c2ecf20Sopenharmony_ci .name = "EETI EXC3000 Touch Screen", 578c2ecf20Sopenharmony_ci .max_xy = SZ_4K - 1, 588c2ecf20Sopenharmony_ci }, 598c2ecf20Sopenharmony_ci [EETI_EXC80H60] = { 608c2ecf20Sopenharmony_ci .name = "EETI EXC80H60 Touch Screen", 618c2ecf20Sopenharmony_ci .max_xy = SZ_16K - 1, 628c2ecf20Sopenharmony_ci }, 638c2ecf20Sopenharmony_ci [EETI_EXC80H84] = { 648c2ecf20Sopenharmony_ci .name = "EETI EXC80H84 Touch Screen", 658c2ecf20Sopenharmony_ci .max_xy = SZ_16K - 1, 668c2ecf20Sopenharmony_ci }, 678c2ecf20Sopenharmony_ci}; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistruct exc3000_data { 708c2ecf20Sopenharmony_ci struct i2c_client *client; 718c2ecf20Sopenharmony_ci const struct eeti_dev_info *info; 728c2ecf20Sopenharmony_ci struct input_dev *input; 738c2ecf20Sopenharmony_ci struct touchscreen_properties prop; 748c2ecf20Sopenharmony_ci struct gpio_desc *reset; 758c2ecf20Sopenharmony_ci struct timer_list timer; 768c2ecf20Sopenharmony_ci u8 buf[2 * EXC3000_LEN_FRAME]; 778c2ecf20Sopenharmony_ci struct completion wait_event; 788c2ecf20Sopenharmony_ci struct mutex query_lock; 798c2ecf20Sopenharmony_ci int query_result; 808c2ecf20Sopenharmony_ci char model[EXC3000_LEN_MODEL_NAME]; 818c2ecf20Sopenharmony_ci char fw_version[EXC3000_LEN_FW_VERSION]; 828c2ecf20Sopenharmony_ci}; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistatic void exc3000_report_slots(struct input_dev *input, 858c2ecf20Sopenharmony_ci struct touchscreen_properties *prop, 868c2ecf20Sopenharmony_ci const u8 *buf, int num) 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci for (; num--; buf += EXC3000_LEN_POINT) { 898c2ecf20Sopenharmony_ci if (buf[0] & BIT(0)) { 908c2ecf20Sopenharmony_ci input_mt_slot(input, buf[1]); 918c2ecf20Sopenharmony_ci input_mt_report_slot_state(input, MT_TOOL_FINGER, true); 928c2ecf20Sopenharmony_ci touchscreen_report_pos(input, prop, 938c2ecf20Sopenharmony_ci get_unaligned_le16(buf + 2), 948c2ecf20Sopenharmony_ci get_unaligned_le16(buf + 4), 958c2ecf20Sopenharmony_ci true); 968c2ecf20Sopenharmony_ci } 978c2ecf20Sopenharmony_ci } 988c2ecf20Sopenharmony_ci} 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistatic void exc3000_timer(struct timer_list *t) 1018c2ecf20Sopenharmony_ci{ 1028c2ecf20Sopenharmony_ci struct exc3000_data *data = from_timer(data, t, timer); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci input_mt_sync_frame(data->input); 1058c2ecf20Sopenharmony_ci input_sync(data->input); 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic int exc3000_read_frame(struct exc3000_data *data, u8 *buf) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 1118c2ecf20Sopenharmony_ci u8 expected_event = EXC3000_MT1_EVENT; 1128c2ecf20Sopenharmony_ci int ret; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci if (data->info->max_xy == SZ_16K - 1) 1158c2ecf20Sopenharmony_ci expected_event = EXC3000_MT2_EVENT; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci ret = i2c_master_send(client, "'", 2); 1188c2ecf20Sopenharmony_ci if (ret < 0) 1198c2ecf20Sopenharmony_ci return ret; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci if (ret != 2) 1228c2ecf20Sopenharmony_ci return -EIO; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci ret = i2c_master_recv(client, buf, EXC3000_LEN_FRAME); 1258c2ecf20Sopenharmony_ci if (ret < 0) 1268c2ecf20Sopenharmony_ci return ret; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci if (ret != EXC3000_LEN_FRAME) 1298c2ecf20Sopenharmony_ci return -EIO; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci if (get_unaligned_le16(buf) != EXC3000_LEN_FRAME) 1328c2ecf20Sopenharmony_ci return -EINVAL; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci if (buf[2] != expected_event) 1358c2ecf20Sopenharmony_ci return -EINVAL; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci return 0; 1388c2ecf20Sopenharmony_ci} 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_cistatic int exc3000_read_data(struct exc3000_data *data, 1418c2ecf20Sopenharmony_ci u8 *buf, int *n_slots) 1428c2ecf20Sopenharmony_ci{ 1438c2ecf20Sopenharmony_ci int error; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci error = exc3000_read_frame(data, buf); 1468c2ecf20Sopenharmony_ci if (error) 1478c2ecf20Sopenharmony_ci return error; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci *n_slots = buf[3]; 1508c2ecf20Sopenharmony_ci if (!*n_slots || *n_slots > EXC3000_NUM_SLOTS) 1518c2ecf20Sopenharmony_ci return -EINVAL; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci if (*n_slots > EXC3000_SLOTS_PER_FRAME) { 1548c2ecf20Sopenharmony_ci /* Read 2nd frame to get the rest of the contacts. */ 1558c2ecf20Sopenharmony_ci error = exc3000_read_frame(data, buf + EXC3000_LEN_FRAME); 1568c2ecf20Sopenharmony_ci if (error) 1578c2ecf20Sopenharmony_ci return error; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci /* 2nd chunk must have number of contacts set to 0. */ 1608c2ecf20Sopenharmony_ci if (buf[EXC3000_LEN_FRAME + 3] != 0) 1618c2ecf20Sopenharmony_ci return -EINVAL; 1628c2ecf20Sopenharmony_ci } 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci return 0; 1658c2ecf20Sopenharmony_ci} 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistatic int exc3000_query_interrupt(struct exc3000_data *data) 1688c2ecf20Sopenharmony_ci{ 1698c2ecf20Sopenharmony_ci u8 *buf = data->buf; 1708c2ecf20Sopenharmony_ci int error; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci error = i2c_master_recv(data->client, buf, EXC3000_LEN_FRAME); 1738c2ecf20Sopenharmony_ci if (error < 0) 1748c2ecf20Sopenharmony_ci return error; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci if (buf[0] != 'B') 1778c2ecf20Sopenharmony_ci return -EPROTO; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci if (buf[4] == 'E') 1808c2ecf20Sopenharmony_ci strlcpy(data->model, buf + 5, sizeof(data->model)); 1818c2ecf20Sopenharmony_ci else if (buf[4] == 'D') 1828c2ecf20Sopenharmony_ci strlcpy(data->fw_version, buf + 5, sizeof(data->fw_version)); 1838c2ecf20Sopenharmony_ci else 1848c2ecf20Sopenharmony_ci return -EPROTO; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci return 0; 1878c2ecf20Sopenharmony_ci} 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_cistatic irqreturn_t exc3000_interrupt(int irq, void *dev_id) 1908c2ecf20Sopenharmony_ci{ 1918c2ecf20Sopenharmony_ci struct exc3000_data *data = dev_id; 1928c2ecf20Sopenharmony_ci struct input_dev *input = data->input; 1938c2ecf20Sopenharmony_ci u8 *buf = data->buf; 1948c2ecf20Sopenharmony_ci int slots, total_slots; 1958c2ecf20Sopenharmony_ci int error; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci if (mutex_is_locked(&data->query_lock)) { 1988c2ecf20Sopenharmony_ci data->query_result = exc3000_query_interrupt(data); 1998c2ecf20Sopenharmony_ci complete(&data->wait_event); 2008c2ecf20Sopenharmony_ci goto out; 2018c2ecf20Sopenharmony_ci } 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci error = exc3000_read_data(data, buf, &total_slots); 2048c2ecf20Sopenharmony_ci if (error) { 2058c2ecf20Sopenharmony_ci /* Schedule a timer to release "stuck" contacts */ 2068c2ecf20Sopenharmony_ci mod_timer(&data->timer, 2078c2ecf20Sopenharmony_ci jiffies + msecs_to_jiffies(EXC3000_TIMEOUT_MS)); 2088c2ecf20Sopenharmony_ci goto out; 2098c2ecf20Sopenharmony_ci } 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci /* 2128c2ecf20Sopenharmony_ci * We read full state successfully, no contacts will be "stuck". 2138c2ecf20Sopenharmony_ci */ 2148c2ecf20Sopenharmony_ci del_timer_sync(&data->timer); 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci while (total_slots > 0) { 2178c2ecf20Sopenharmony_ci slots = min(total_slots, EXC3000_SLOTS_PER_FRAME); 2188c2ecf20Sopenharmony_ci exc3000_report_slots(input, &data->prop, buf + 4, slots); 2198c2ecf20Sopenharmony_ci total_slots -= slots; 2208c2ecf20Sopenharmony_ci buf += EXC3000_LEN_FRAME; 2218c2ecf20Sopenharmony_ci } 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci input_mt_sync_frame(input); 2248c2ecf20Sopenharmony_ci input_sync(input); 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ciout: 2278c2ecf20Sopenharmony_ci return IRQ_HANDLED; 2288c2ecf20Sopenharmony_ci} 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_cistatic ssize_t fw_version_show(struct device *dev, 2318c2ecf20Sopenharmony_ci struct device_attribute *attr, char *buf) 2328c2ecf20Sopenharmony_ci{ 2338c2ecf20Sopenharmony_ci struct i2c_client *client = to_i2c_client(dev); 2348c2ecf20Sopenharmony_ci struct exc3000_data *data = i2c_get_clientdata(client); 2358c2ecf20Sopenharmony_ci static const u8 request[68] = { 2368c2ecf20Sopenharmony_ci 0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'D', 0x00 2378c2ecf20Sopenharmony_ci }; 2388c2ecf20Sopenharmony_ci int error; 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci mutex_lock(&data->query_lock); 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci data->query_result = -ETIMEDOUT; 2438c2ecf20Sopenharmony_ci reinit_completion(&data->wait_event); 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci error = i2c_master_send(client, request, sizeof(request)); 2468c2ecf20Sopenharmony_ci if (error < 0) { 2478c2ecf20Sopenharmony_ci mutex_unlock(&data->query_lock); 2488c2ecf20Sopenharmony_ci return error; 2498c2ecf20Sopenharmony_ci } 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci wait_for_completion_interruptible_timeout(&data->wait_event, 1 * HZ); 2528c2ecf20Sopenharmony_ci mutex_unlock(&data->query_lock); 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci if (data->query_result < 0) 2558c2ecf20Sopenharmony_ci return data->query_result; 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci return sprintf(buf, "%s\n", data->fw_version); 2588c2ecf20Sopenharmony_ci} 2598c2ecf20Sopenharmony_cistatic DEVICE_ATTR_RO(fw_version); 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_cistatic ssize_t exc3000_get_model(struct exc3000_data *data) 2628c2ecf20Sopenharmony_ci{ 2638c2ecf20Sopenharmony_ci static const u8 request[68] = { 2648c2ecf20Sopenharmony_ci 0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'E', 0x00 2658c2ecf20Sopenharmony_ci }; 2668c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 2678c2ecf20Sopenharmony_ci int error; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci mutex_lock(&data->query_lock); 2708c2ecf20Sopenharmony_ci data->query_result = -ETIMEDOUT; 2718c2ecf20Sopenharmony_ci reinit_completion(&data->wait_event); 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci error = i2c_master_send(client, request, sizeof(request)); 2748c2ecf20Sopenharmony_ci if (error < 0) { 2758c2ecf20Sopenharmony_ci mutex_unlock(&data->query_lock); 2768c2ecf20Sopenharmony_ci return error; 2778c2ecf20Sopenharmony_ci } 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci wait_for_completion_interruptible_timeout(&data->wait_event, 1 * HZ); 2808c2ecf20Sopenharmony_ci mutex_unlock(&data->query_lock); 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci return data->query_result; 2838c2ecf20Sopenharmony_ci} 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_cistatic ssize_t model_show(struct device *dev, 2868c2ecf20Sopenharmony_ci struct device_attribute *attr, char *buf) 2878c2ecf20Sopenharmony_ci{ 2888c2ecf20Sopenharmony_ci struct i2c_client *client = to_i2c_client(dev); 2898c2ecf20Sopenharmony_ci struct exc3000_data *data = i2c_get_clientdata(client); 2908c2ecf20Sopenharmony_ci int error; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci error = exc3000_get_model(data); 2938c2ecf20Sopenharmony_ci if (error < 0) 2948c2ecf20Sopenharmony_ci return error; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci return sprintf(buf, "%s\n", data->model); 2978c2ecf20Sopenharmony_ci} 2988c2ecf20Sopenharmony_cistatic DEVICE_ATTR_RO(model); 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_cistatic struct attribute *sysfs_attrs[] = { 3018c2ecf20Sopenharmony_ci &dev_attr_fw_version.attr, 3028c2ecf20Sopenharmony_ci &dev_attr_model.attr, 3038c2ecf20Sopenharmony_ci NULL 3048c2ecf20Sopenharmony_ci}; 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_cistatic struct attribute_group exc3000_attribute_group = { 3078c2ecf20Sopenharmony_ci .attrs = sysfs_attrs 3088c2ecf20Sopenharmony_ci}; 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_cistatic int exc3000_probe(struct i2c_client *client) 3118c2ecf20Sopenharmony_ci{ 3128c2ecf20Sopenharmony_ci struct exc3000_data *data; 3138c2ecf20Sopenharmony_ci struct input_dev *input; 3148c2ecf20Sopenharmony_ci int error, max_xy, retry; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); 3178c2ecf20Sopenharmony_ci if (!data) 3188c2ecf20Sopenharmony_ci return -ENOMEM; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci data->client = client; 3218c2ecf20Sopenharmony_ci data->info = device_get_match_data(&client->dev); 3228c2ecf20Sopenharmony_ci if (!data->info) { 3238c2ecf20Sopenharmony_ci enum eeti_dev_id eeti_dev_id = 3248c2ecf20Sopenharmony_ci i2c_match_id(exc3000_id, client)->driver_data; 3258c2ecf20Sopenharmony_ci data->info = &exc3000_info[eeti_dev_id]; 3268c2ecf20Sopenharmony_ci } 3278c2ecf20Sopenharmony_ci timer_setup(&data->timer, exc3000_timer, 0); 3288c2ecf20Sopenharmony_ci init_completion(&data->wait_event); 3298c2ecf20Sopenharmony_ci mutex_init(&data->query_lock); 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci data->reset = devm_gpiod_get_optional(&client->dev, "reset", 3328c2ecf20Sopenharmony_ci GPIOD_OUT_HIGH); 3338c2ecf20Sopenharmony_ci if (IS_ERR(data->reset)) 3348c2ecf20Sopenharmony_ci return PTR_ERR(data->reset); 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci if (data->reset) { 3378c2ecf20Sopenharmony_ci msleep(EXC3000_RESET_MS); 3388c2ecf20Sopenharmony_ci gpiod_set_value_cansleep(data->reset, 0); 3398c2ecf20Sopenharmony_ci msleep(EXC3000_READY_MS); 3408c2ecf20Sopenharmony_ci } 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci input = devm_input_allocate_device(&client->dev); 3438c2ecf20Sopenharmony_ci if (!input) 3448c2ecf20Sopenharmony_ci return -ENOMEM; 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci data->input = input; 3478c2ecf20Sopenharmony_ci input_set_drvdata(input, data); 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci input->name = data->info->name; 3508c2ecf20Sopenharmony_ci input->id.bustype = BUS_I2C; 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci max_xy = data->info->max_xy; 3538c2ecf20Sopenharmony_ci input_set_abs_params(input, ABS_MT_POSITION_X, 0, max_xy, 0, 0); 3548c2ecf20Sopenharmony_ci input_set_abs_params(input, ABS_MT_POSITION_Y, 0, max_xy, 0, 0); 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci touchscreen_parse_properties(input, true, &data->prop); 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci error = input_mt_init_slots(input, EXC3000_NUM_SLOTS, 3598c2ecf20Sopenharmony_ci INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); 3608c2ecf20Sopenharmony_ci if (error) 3618c2ecf20Sopenharmony_ci return error; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci error = input_register_device(input); 3648c2ecf20Sopenharmony_ci if (error) 3658c2ecf20Sopenharmony_ci return error; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci error = devm_request_threaded_irq(&client->dev, client->irq, 3688c2ecf20Sopenharmony_ci NULL, exc3000_interrupt, IRQF_ONESHOT, 3698c2ecf20Sopenharmony_ci client->name, data); 3708c2ecf20Sopenharmony_ci if (error) 3718c2ecf20Sopenharmony_ci return error; 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci /* 3748c2ecf20Sopenharmony_ci * I²C does not have built-in recovery, so retry on failure. This 3758c2ecf20Sopenharmony_ci * ensures, that the device probe will not fail for temporary issues 3768c2ecf20Sopenharmony_ci * on the bus. This is not needed for the sysfs calls (userspace 3778c2ecf20Sopenharmony_ci * will receive the error code and can start another query) and 3788c2ecf20Sopenharmony_ci * cannot be done for touch events (but that only means loosing one 3798c2ecf20Sopenharmony_ci * or two touch events anyways). 3808c2ecf20Sopenharmony_ci */ 3818c2ecf20Sopenharmony_ci for (retry = 0; retry < 3; retry++) { 3828c2ecf20Sopenharmony_ci error = exc3000_get_model(data); 3838c2ecf20Sopenharmony_ci if (!error) 3848c2ecf20Sopenharmony_ci break; 3858c2ecf20Sopenharmony_ci dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n", 3868c2ecf20Sopenharmony_ci retry + 1, error); 3878c2ecf20Sopenharmony_ci } 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci if (error) 3908c2ecf20Sopenharmony_ci return error; 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci dev_dbg(&client->dev, "TS Model: %s", data->model); 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci i2c_set_clientdata(client, data); 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci error = devm_device_add_group(&client->dev, &exc3000_attribute_group); 3978c2ecf20Sopenharmony_ci if (error) 3988c2ecf20Sopenharmony_ci return error; 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci return 0; 4018c2ecf20Sopenharmony_ci} 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_cistatic const struct i2c_device_id exc3000_id[] = { 4048c2ecf20Sopenharmony_ci { "exc3000", EETI_EXC3000 }, 4058c2ecf20Sopenharmony_ci { "exc80h60", EETI_EXC80H60 }, 4068c2ecf20Sopenharmony_ci { "exc80h84", EETI_EXC80H84 }, 4078c2ecf20Sopenharmony_ci { } 4088c2ecf20Sopenharmony_ci}; 4098c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, exc3000_id); 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci#ifdef CONFIG_OF 4128c2ecf20Sopenharmony_cistatic const struct of_device_id exc3000_of_match[] = { 4138c2ecf20Sopenharmony_ci { .compatible = "eeti,exc3000", .data = &exc3000_info[EETI_EXC3000] }, 4148c2ecf20Sopenharmony_ci { .compatible = "eeti,exc80h60", .data = &exc3000_info[EETI_EXC80H60] }, 4158c2ecf20Sopenharmony_ci { .compatible = "eeti,exc80h84", .data = &exc3000_info[EETI_EXC80H84] }, 4168c2ecf20Sopenharmony_ci { } 4178c2ecf20Sopenharmony_ci}; 4188c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, exc3000_of_match); 4198c2ecf20Sopenharmony_ci#endif 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_cistatic struct i2c_driver exc3000_driver = { 4228c2ecf20Sopenharmony_ci .driver = { 4238c2ecf20Sopenharmony_ci .name = "exc3000", 4248c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(exc3000_of_match), 4258c2ecf20Sopenharmony_ci }, 4268c2ecf20Sopenharmony_ci .id_table = exc3000_id, 4278c2ecf20Sopenharmony_ci .probe_new = exc3000_probe, 4288c2ecf20Sopenharmony_ci}; 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_cimodule_i2c_driver(exc3000_driver); 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ciMODULE_AUTHOR("Ahmet Inan <inan@distec.de>"); 4338c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("I2C connected EETI EXC3000 multiple touch controller driver"); 4348c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 435