From patchwork Tue Mar 12 19:01:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Ford X-Patchwork-Id: 10849877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 356B7139A for ; Tue, 12 Mar 2019 19:01:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23B9E298A5 for ; Tue, 12 Mar 2019 19:01:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1853F29893; Tue, 12 Mar 2019 19:01:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16AF72989A for ; Tue, 12 Mar 2019 19:01:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727134AbfCLTBr (ORCPT ); Tue, 12 Mar 2019 15:01:47 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:51581 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726815AbfCLTBr (ORCPT ); Tue, 12 Mar 2019 15:01:47 -0400 Received: by mail-it1-f193.google.com with SMTP id e24so6255445itl.1; Tue, 12 Mar 2019 12:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=/WY186pZEkhv66KsoaOMTZw4RCYDW0Ke8bRloUi7n8Q=; b=fGLEa43Wcyodxpkp1Zx8QutVk1gPq/QAzb3iiABr1AWmB3gW2OReWu3S/Rk3YpLFAv bk9E2Z8u3bcGaB84B2/BumJpccXbnHmAYRCMRlDQPRhgTY+IvPn8u1+HaoED3apoVkwf DrPbOFm0MIuQNj3sKwJPN2X2GOwEh3p8lOfn4ZmQgy95FdP6GYR5TZEb7bKzxqzFMOs7 zj+ZJwxyx9fXgXIU2o03hN2jbnKP2rR7tnBMdWl9VHPWdL5a+NJ0Us38sTtxO66MA0GM bMmBTizJoj2zwsJW7aYvOty3oRYF5PXYK/N/+jZ0ZfvVp8E2xgKcL9UlcbqhBq4Rtl3A W21g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/WY186pZEkhv66KsoaOMTZw4RCYDW0Ke8bRloUi7n8Q=; b=V1HmQSmQulU4527ANoLtOKYU1rpm5vnHKZb2N/AuEPRDcQ7HmNab6wQuQ8YAkydj4N J6ddZJfoCyOWR+QaP6LXWla8UOfpF9KhHl8B69MqcgJhHSkSAWdhk7BMIwJ8ZdUysiIN /7SCOyGcIROhrpxvR5kMDYrI1xdTT3nMfNyy18QU5ydi7z2YzjsQ9jHWAZyzDkietWfs nIuKxdSEWsWnrnuVcKtdcSYvXO1K/5W71Oh4m04VphEtVkSaCXr1y6+yqB4CgTOBJDRK zbCKx1wS7ySg4OxRvhjdCJ8LR94aTZb9bQldsf3SJT4jzUd+AyIbWSKU2E3sGUEkVtfz 6zsQ== X-Gm-Message-State: APjAAAU2w29/JfwvHv8Gn5hGL3ZjOLn3gube0En7p+ypI4WVOiYjce4L x/Vg3chjsUAoxg+BJ/z5piJTCyA1 X-Google-Smtp-Source: APXvYqyFxF7vW/8gef8ID7fSkD+dkrxAFN+1HMlwArPbxS+b4FJZfvA5+CVcvyPfw0mpapEkEdfLng== X-Received: by 2002:a05:6638:348:: with SMTP id x8mr11705866jap.79.1552417305586; Tue, 12 Mar 2019 12:01:45 -0700 (PDT) Received: from aford-OptiPlex-7050.logicpd.com ([174.46.170.158]) by smtp.gmail.com with ESMTPSA id m26sm705201iti.6.2019.03.12.12.01.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 12:01:44 -0700 (PDT) From: Adam Ford To: linux-input@vger.kernel.org Cc: adam.ford@logicpd.com, Adam Ford , Dmitry Torokhov , Henrik Rydberg , linux-kernel@vger.kernel.org Subject: [PATCH] Input: ili2117a - Add support for Ilitek ILI2117A based touchscreens Date: Tue, 12 Mar 2019 14:01:37 -0500 Message-Id: <20190312190137.8138-1-aford173@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This driver supports the ILI2117A touch controller. This is different than the ILI210x and it uses different register and algorithm so it's a separate driver rather than integrating with the other. Signed-off-by: Adam Ford diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 6c16aaeb4191..ff7cd369514e 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -416,6 +416,18 @@ config TOUCHSCREEN_ILI210X To compile this driver as a module, choose M here: the module will be called ili210x. +config TOUCHSCREEN_ILI2117A + tristate "Ilitek ILI2117A Multi-Touch Controller" + depends on I2C + help + Say Y here if you have a ILI2117A based touchscreen + controller. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called ili2117a. + config TOUCHSCREEN_IPROC tristate "IPROC touch panel driver support" depends on ARCH_BCM_IPROC || COMPILE_TEST diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index fcc7605fba8d..0290d503bed1 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -46,6 +46,7 @@ obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix.o obj-$(CONFIG_TOUCHSCREEN_HIDEEP) += hideep.o obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o +obj-$(CONFIG_TOUCHSCREEN_ILI2117A) += ili2117a.o obj-$(CONFIG_TOUCHSCREEN_IMX6UL_TSC) += imx6ul_tsc.o obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o obj-$(CONFIG_TOUCHSCREEN_IPROC) += bcm_iproc_tsc.o diff --git a/drivers/input/touchscreen/ili2117a.c b/drivers/input/touchscreen/ili2117a.c new file mode 100644 index 000000000000..c47874ee89f4 --- /dev/null +++ b/drivers/input/touchscreen/ili2117a.c @@ -0,0 +1,308 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_TOUCHES 10 +#define DEFAULT_POLL_PERIOD 20 +#define MAX_X ((1 << 12) - 1) +#define MAX_Y ((1 << 12) - 1) + +/* Touchscreen commands */ +#define TOUCH_INFO 0x00 + +struct finger { + u8 xy; + u8 x; + u8 y; + u8 c_sum; +} __packed; + +struct touchdata { + u8 packet_id; + struct finger finger[MAX_TOUCHES]; + u8 key; + u8 checksum; +} __packed; + + +struct ili2117a { + struct i2c_client *client; + struct input_dev *input; + bool (*get_pendown_state)(void); + unsigned int poll_period; + struct delayed_work dwork; + int max_touch; +}; + +static int ili2117a_read_reg(struct i2c_client *client, u8 reg, void *buf, + size_t len) +{ + struct i2c_msg msg[2] = { + { + .addr = client->addr, + .flags = 0, + .len = 1, + .buf = ®, + }, + { + .addr = client->addr, + .flags = I2C_M_RD, + .len = len, + .buf = buf, + } + }; + + if (i2c_transfer(client->adapter, msg, 2) != 2) { + dev_err(&client->dev, "i2c transfer failed\n"); + return -EIO; + } + + return 0; +} + +static bool ili2117a_report_events(struct input_dev *input, + const struct touchdata *touchdata, + int max_touch) +{ + int i; + bool touch; + bool pen_down = 0; + u16 x = 0xfff; + u16 y = 0xfff; + const struct finger *finger; + + for (i = 0; i < max_touch; i++) { + touch = 0; + input_mt_slot(input, i); + finger = &touchdata->finger[i]; + + x = finger->x | (((finger->xy & 0xf0) >> 4) << 8); + y = finger->y | ((finger->xy & 0x0f) << 8); + + /* This driver returns 0xfff if there is no touch */ + if (x != 0xfff && y != 0xfff) { + touch = 1; + pen_down = 1; + } + + input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); + + if (touch) { + input_report_abs(input, ABS_MT_POSITION_X, x); + input_report_abs(input, ABS_MT_POSITION_Y, y); + } + } + + input_mt_report_pointer_emulation(input, false); + input_sync(input); + return pen_down; +} + +static void ili2117a_work(struct work_struct *work) +{ + struct ili2117a *priv = container_of(work, struct ili2117a, + dwork.work); + struct i2c_client *client = priv->client; + struct touchdata touchdata; + int error; + bool status; + + error = ili2117a_read_reg(client, TOUCH_INFO, + (uint8_t *) &touchdata, sizeof(touchdata)); + + if (error) { + dev_err(&client->dev, + "Unable to get touchdata, err = %d\n", error); + return; + } + + status = ili2117a_report_events(priv->input, &touchdata, + priv->max_touch); + + if (status) { + schedule_delayed_work(&priv->dwork, + msecs_to_jiffies(priv->poll_period)); + } +} + +static irqreturn_t ili2117a_irq(int irq, void *irq_data) +{ + struct ili2117a *priv = irq_data; + + schedule_delayed_work(&priv->dwork, 0); + + return IRQ_HANDLED; +} + +static struct attribute *ili2117a_attributes[] = { + NULL, +}; + +static const struct attribute_group ili2117a_attr_group = { + .attrs = ili2117a_attributes, +}; + +static int ili2117a_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; + struct ili2117a *priv; + struct input_dev *input; + int error; + int poll_period; + int max_touch; + + if (client->irq <= 0) { + dev_err(dev, "No IRQ!\n"); + return -EINVAL; + } + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + input = input_allocate_device(); + if (!priv || !input) { + error = -ENOMEM; + goto err_free_mem; + } + + priv->client = client; + priv->input = input; + + error = device_property_read_u32(dev, "ili2117a,poll-period", + &poll_period); + priv->poll_period = error ? DEFAULT_POLL_PERIOD : poll_period; + + error = device_property_read_u32(dev, "ili2117a,max-touch", + &max_touch); + if (max_touch > MAX_TOUCHES) + max_touch = MAX_TOUCHES; + priv->max_touch = error ? MAX_TOUCHES : max_touch; + + INIT_DELAYED_WORK(&priv->dwork, ili2117a_work); + + /* Setup input device */ + input->name = "ili2117a Touchscreen"; + input->id.bustype = BUS_I2C; + input->dev.parent = dev; + + __set_bit(EV_SYN, input->evbit); + __set_bit(EV_KEY, input->evbit); + __set_bit(EV_ABS, input->evbit); + __set_bit(BTN_TOUCH, input->keybit); + + /* Single touch */ + input_set_abs_params(input, ABS_X, 0, MAX_X, 0, 0); + input_set_abs_params(input, ABS_Y, 0, MAX_Y, 0, 0); + + /* Multi touch */ + input_mt_init_slots(input, priv->max_touch, 0); + input_set_abs_params(input, ABS_MT_POSITION_X, 0, MAX_X, 0, 0); + input_set_abs_params(input, ABS_MT_POSITION_Y, 0, MAX_Y, 0, 0); + + i2c_set_clientdata(client, priv); + + error = devm_request_threaded_irq(dev, client->irq, NULL, + ili2117a_irq, + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + client->name, priv); + + if (error) { + dev_err(dev, "Failed to request irq, err: %d\n", error); + goto err_free_mem; + } + + error = sysfs_create_group(&dev->kobj, &ili2117a_attr_group); + if (error) { + dev_err(dev, "Unable to create sysfs attributes, err: %d\n", + error); + goto err_free_irq; + } + + error = input_register_device(priv->input); + if (error) { + dev_err(dev, "Cannot register input device, err: %d\n", error); + goto err_remove_sysfs; + } + + device_init_wakeup(dev, 1); + return 0; + +err_remove_sysfs: + sysfs_remove_group(&dev->kobj, &ili2117a_attr_group); +err_free_irq: + free_irq(client->irq, priv); +err_free_mem: + input_free_device(input); + kfree(priv); + return error; +} + +static int ili2117a_i2c_remove(struct i2c_client *client) +{ + struct ili2117a *priv = i2c_get_clientdata(client); + + sysfs_remove_group(&client->dev.kobj, &ili2117a_attr_group); + free_irq(priv->client->irq, priv); + cancel_delayed_work_sync(&priv->dwork); + input_unregister_device(priv->input); + kfree(priv); + + return 0; +} + +static int __maybe_unused ili2117a_i2c_suspend(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + + if (device_may_wakeup(&client->dev)) + enable_irq_wake(client->irq); + + return 0; +} + +static int __maybe_unused ili2117a_i2c_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + + if (device_may_wakeup(&client->dev)) + disable_irq_wake(client->irq); + + return 0; +} + +static SIMPLE_DEV_PM_OPS(ili2117a_i2c_pm, + ili2117a_i2c_suspend, ili2117a_i2c_resume); + +static const struct of_device_id ili_match_table[] = { + { .compatible = "ilitek,ili2117a" }, + { }, +}; + +static const struct i2c_device_id ili2117a_i2c_id[] = { + { "ili2117a", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ili2117a_i2c_id); + +static struct i2c_driver ili2117a_ts_driver = { + .driver = { + .name = "ili2117a_i2c", + .pm = &ili2117a_i2c_pm, + .of_match_table = of_match_ptr(ili_match_table), + }, + .id_table = ili2117a_i2c_id, + .probe = ili2117a_i2c_probe, + .remove = ili2117a_i2c_remove, +}; + +module_i2c_driver(ili2117a_ts_driver); + +MODULE_AUTHOR("Adam Ford "); +MODULE_DESCRIPTION("ili2117a I2C Touchscreen Driver"); +MODULE_LICENSE("GPL");