From patchwork Thu Dec 13 15:14:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10728881 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 8499714DE for ; Thu, 13 Dec 2018 15:15:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 745262C442 for ; Thu, 13 Dec 2018 15:15:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 685002C4BA; Thu, 13 Dec 2018 15:15:08 +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=-7.9 required=2.0 tests=BAYES_00,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 5BE8C2C45E for ; Thu, 13 Dec 2018 15:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729407AbeLMPPG (ORCPT ); Thu, 13 Dec 2018 10:15:06 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:39591 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729401AbeLMPPG (ORCPT ); Thu, 13 Dec 2018 10:15:06 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43Fy0R1FNMz1qxKR; Thu, 13 Dec 2018 16:15:03 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43Fy0R0dfkz1qtfL; Thu, 13 Dec 2018 16:15:03 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id w-7dH96jAt8j; Thu, 13 Dec 2018 16:15:01 +0100 (CET) X-Auth-Info: f/tQhphQtlt7mTiFajj05BN5xvNQlWTaaEMV/iaSCoE= Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz [86.49.110.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 13 Dec 2018 16:15:01 +0100 (CET) From: Marek Vasut To: linux-input@vger.kernel.org Cc: Marek Vasut , Dmitry Torokhov , Henrik Rydberg , Olivier Sobrie Subject: [PATCH 1/8] input: touchscreen: ili210x: Drop platform data support Date: Thu, 13 Dec 2018 16:14:35 +0100 Message-Id: <20181213151442.27854-2-marex@denx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181213151442.27854-1-marex@denx.de> References: <20181213151442.27854-1-marex@denx.de> 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 There is not a single user of the ili210x platform data in the kernel, just drop it. Signed-off-by: Marek Vasut Cc: Dmitry Torokhov Cc: Henrik Rydberg Cc: Olivier Sobrie To: linux-input@vger.kernel.org --- drivers/input/touchscreen/ili210x.c | 12 ++---------- include/linux/input/ili210x.h | 11 ----------- 2 files changed, 2 insertions(+), 21 deletions(-) delete mode 100644 include/linux/input/ili210x.h diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index 6f76eeedf4652..25b0ca6c07d9b 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -6,7 +6,6 @@ #include #include #include -#include #define MAX_TOUCHES 2 #define DEFAULT_POLL_PERIOD 20 @@ -184,7 +183,6 @@ static int ili210x_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; - const struct ili210x_platform_data *pdata = dev_get_platdata(dev); struct ili210x *priv; struct input_dev *input; struct panel_info panel; @@ -194,11 +192,6 @@ static int ili210x_i2c_probe(struct i2c_client *client, dev_dbg(dev, "Probing for ILI210X I2C Touschreen driver"); - if (!pdata) { - dev_err(dev, "No platform data!\n"); - return -EINVAL; - } - if (client->irq <= 0) { dev_err(dev, "No IRQ!\n"); return -EINVAL; @@ -233,8 +226,7 @@ static int ili210x_i2c_probe(struct i2c_client *client, priv->client = client; priv->input = input; - priv->get_pendown_state = pdata->get_pendown_state; - priv->poll_period = pdata->poll_period ? : DEFAULT_POLL_PERIOD; + priv->poll_period = DEFAULT_POLL_PERIOD; INIT_DELAYED_WORK(&priv->dwork, ili210x_work); /* Setup input device */ @@ -258,7 +250,7 @@ static int ili210x_i2c_probe(struct i2c_client *client, i2c_set_clientdata(client, priv); - error = request_irq(client->irq, ili210x_irq, pdata->irq_flags, + error = request_irq(client->irq, ili210x_irq, 0, client->name, priv); if (error) { dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n", diff --git a/include/linux/input/ili210x.h b/include/linux/input/ili210x.h deleted file mode 100644 index b76e7c1404cd1..0000000000000 --- a/include/linux/input/ili210x.h +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ILI210X_H -#define _ILI210X_H - -struct ili210x_platform_data { - unsigned long irq_flags; - unsigned int poll_period; - bool (*get_pendown_state)(void); -}; - -#endif From patchwork Thu Dec 13 15:14:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10728883 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 520FD14DE for ; Thu, 13 Dec 2018 15:15:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41F2128742 for ; Thu, 13 Dec 2018 15:15:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 364A82C45E; Thu, 13 Dec 2018 15:15:09 +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=-7.9 required=2.0 tests=BAYES_00,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 DCF7E28742 for ; Thu, 13 Dec 2018 15:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729401AbeLMPPG (ORCPT ); Thu, 13 Dec 2018 10:15:06 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:58284 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729429AbeLMPPG (ORCPT ); Thu, 13 Dec 2018 10:15:06 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43Fy0S1V8Kz1qxKD; Thu, 13 Dec 2018 16:15:04 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43Fy0S0ymGz1qtfL; Thu, 13 Dec 2018 16:15:04 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 2hINf5uwSPwY; Thu, 13 Dec 2018 16:15:03 +0100 (CET) X-Auth-Info: TgAmnmNZM7KyKZhwYp+KAbJVbNkPYHb41VSWFCxz+Aw= Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz [86.49.110.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 13 Dec 2018 16:15:03 +0100 (CET) From: Marek Vasut To: linux-input@vger.kernel.org Cc: Marek Vasut , Dmitry Torokhov , Henrik Rydberg , Olivier Sobrie Subject: [PATCH 2/8] input: touchscreen: ili210x: Convert to devm_ functions Date: Thu, 13 Dec 2018 16:14:36 +0100 Message-Id: <20181213151442.27854-3-marex@denx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181213151442.27854-1-marex@denx.de> References: <20181213151442.27854-1-marex@denx.de> 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 Convert the driver to dev-managed allocations. Signed-off-by: Marek Vasut Cc: Dmitry Torokhov Cc: Henrik Rydberg Cc: Olivier Sobrie To: linux-input@vger.kernel.org --- drivers/input/touchscreen/ili210x.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index 25b0ca6c07d9b..7ba93de712432 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -217,12 +217,10 @@ static int ili210x_i2c_probe(struct i2c_client *client, xmax = panel.finger_max.x_low | (panel.finger_max.x_high << 8); ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8); - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - input = input_allocate_device(); - if (!priv || !input) { - error = -ENOMEM; - goto err_free_mem; - } + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + input = devm_input_allocate_device(dev); + if (!priv || !input) + return -ENOMEM; priv->client = client; priv->input = input; @@ -284,8 +282,6 @@ static int ili210x_i2c_probe(struct i2c_client *client, err_free_irq: free_irq(client->irq, priv); err_free_mem: - input_free_device(input); - kfree(priv); return error; } @@ -297,7 +293,6 @@ static int ili210x_i2c_remove(struct i2c_client *client) free_irq(priv->client->irq, priv); cancel_delayed_work_sync(&priv->dwork); input_unregister_device(priv->input); - kfree(priv); return 0; } From patchwork Thu Dec 13 15:14:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10728885 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 1586291E for ; Thu, 13 Dec 2018 15:15:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05D9928742 for ; Thu, 13 Dec 2018 15:15:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDE0F2C45E; Thu, 13 Dec 2018 15:15:09 +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=-7.9 required=2.0 tests=BAYES_00,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 8020128742 for ; Thu, 13 Dec 2018 15:15:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728718AbeLMPPJ (ORCPT ); Thu, 13 Dec 2018 10:15:09 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:33092 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729429AbeLMPPI (ORCPT ); Thu, 13 Dec 2018 10:15:08 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43Fy0T2mqyz1qxRw; Thu, 13 Dec 2018 16:15:05 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43Fy0T2MPrz1qtfL; Thu, 13 Dec 2018 16:15:05 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 40sz6SbrpvqR; Thu, 13 Dec 2018 16:15:04 +0100 (CET) X-Auth-Info: IseDMC9JOTl79KxaS1LGKAAFuvsnE/uE9UvnUESXseE= Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz [86.49.110.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 13 Dec 2018 16:15:04 +0100 (CET) From: Marek Vasut To: linux-input@vger.kernel.org Cc: Marek Vasut , Dmitry Torokhov , Henrik Rydberg , Olivier Sobrie Subject: [PATCH 3/8] input: touchscreen: ili210x: Convert to threaded IRQ Date: Thu, 13 Dec 2018 16:14:37 +0100 Message-Id: <20181213151442.27854-4-marex@denx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181213151442.27854-1-marex@denx.de> References: <20181213151442.27854-1-marex@denx.de> 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 Get rid of the workqueue, just spawn a threaded IRQ and handle all the touchscreen readouts in the handler thread. Signed-off-by: Marek Vasut Cc: Dmitry Torokhov Cc: Henrik Rydberg Cc: Olivier Sobrie To: linux-input@vger.kernel.org --- drivers/input/touchscreen/ili210x.c | 51 +++++------------------------ 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index 7ba93de712432..1102ee560bf4d 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -5,7 +5,6 @@ #include #include #include -#include #define MAX_TOUCHES 2 #define DEFAULT_POLL_PERIOD 20 @@ -43,9 +42,6 @@ struct firmware_version { struct ili210x { struct i2c_client *client; struct input_dev *input; - bool (*get_pendown_state)(void); - unsigned int poll_period; - struct delayed_work dwork; }; static int ili210x_read_reg(struct i2c_client *client, u8 reg, void *buf, @@ -102,20 +98,9 @@ static void ili210x_report_events(struct input_dev *input, input_sync(input); } -static bool get_pendown_state(const struct ili210x *priv) -{ - bool state = false; - - if (priv->get_pendown_state) - state = priv->get_pendown_state(); - - return state; -} - -static void ili210x_work(struct work_struct *work) +static irqreturn_t ili210x_irq(int irq, void *irq_data) { - struct ili210x *priv = container_of(work, struct ili210x, - dwork.work); + struct ili210x *priv = irq_data; struct i2c_client *client = priv->client; struct touchdata touchdata; int error; @@ -125,21 +110,10 @@ static void ili210x_work(struct work_struct *work) if (error) { dev_err(&client->dev, "Unable to get touchdata, err = %d\n", error); - return; + return IRQ_HANDLED; } - ili210x_report_events(priv->input, &touchdata); - - if ((touchdata.status & 0xf3) || get_pendown_state(priv)) - schedule_delayed_work(&priv->dwork, - msecs_to_jiffies(priv->poll_period)); -} - -static irqreturn_t ili210x_irq(int irq, void *irq_data) -{ - struct ili210x *priv = irq_data; - - schedule_delayed_work(&priv->dwork, 0); + ili210x_report_events(priv, &touchdata); return IRQ_HANDLED; } @@ -224,8 +198,6 @@ static int ili210x_i2c_probe(struct i2c_client *client, priv->client = client; priv->input = input; - priv->poll_period = DEFAULT_POLL_PERIOD; - INIT_DELAYED_WORK(&priv->dwork, ili210x_work); /* Setup input device */ input->name = "ILI210x Touchscreen"; @@ -248,19 +220,19 @@ static int ili210x_i2c_probe(struct i2c_client *client, i2c_set_clientdata(client, priv); - error = request_irq(client->irq, ili210x_irq, 0, - client->name, priv); + error = devm_request_threaded_irq(dev, client->irq, NULL, ili210x_irq, + IRQF_ONESHOT, client->name, priv); if (error) { dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n", error); - goto err_free_mem; + return error; } error = sysfs_create_group(&dev->kobj, &ili210x_attr_group); if (error) { dev_err(dev, "Unable to create sysfs attributes, err: %d\n", error); - goto err_free_irq; + return error; } error = input_register_device(priv->input); @@ -279,19 +251,12 @@ static int ili210x_i2c_probe(struct i2c_client *client, err_remove_sysfs: sysfs_remove_group(&dev->kobj, &ili210x_attr_group); -err_free_irq: - free_irq(client->irq, priv); -err_free_mem: return error; } static int ili210x_i2c_remove(struct i2c_client *client) { - struct ili210x *priv = i2c_get_clientdata(client); - sysfs_remove_group(&client->dev.kobj, &ili210x_attr_group); - free_irq(priv->client->irq, priv); - cancel_delayed_work_sync(&priv->dwork); input_unregister_device(priv->input); return 0; From patchwork Thu Dec 13 15:14:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10728887 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 40FEB91E for ; Thu, 13 Dec 2018 15:15:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3154528742 for ; Thu, 13 Dec 2018 15:15:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25B912C45E; Thu, 13 Dec 2018 15:15:11 +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=-7.9 required=2.0 tests=BAYES_00,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 BCDA928742 for ; Thu, 13 Dec 2018 15:15:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729429AbeLMPPJ (ORCPT ); Thu, 13 Dec 2018 10:15:09 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:38809 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728591AbeLMPPJ (ORCPT ); Thu, 13 Dec 2018 10:15:09 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43Fy0W3Qyqz1qxfb; Thu, 13 Dec 2018 16:15:07 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43Fy0W31gbz1qtfM; Thu, 13 Dec 2018 16:15:07 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id A5mSOY6dD2S4; Thu, 13 Dec 2018 16:15:05 +0100 (CET) X-Auth-Info: wrRLzLV4Sw/1ttUn4jP5ZP23ikqQrVq+czRwRxxhLh0= Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz [86.49.110.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 13 Dec 2018 16:15:05 +0100 (CET) From: Marek Vasut To: linux-input@vger.kernel.org Cc: Marek Vasut , Dmitry Torokhov , Henrik Rydberg , Olivier Sobrie Subject: [PATCH 4/8] input: touchscreen: ili210x: Add reset GPIO support Date: Thu, 13 Dec 2018 16:14:38 +0100 Message-Id: <20181213151442.27854-5-marex@denx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181213151442.27854-1-marex@denx.de> References: <20181213151442.27854-1-marex@denx.de> 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 The touchscreen can have a reset GPIO connected to it, add support for such an arrangement. Signed-off-by: Marek Vasut Cc: Dmitry Torokhov Cc: Henrik Rydberg Cc: Olivier Sobrie To: linux-input@vger.kernel.org --- drivers/input/touchscreen/ili210x.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index 1102ee560bf4d..7579cf16b3663 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -5,6 +5,7 @@ #include #include #include +#include #define MAX_TOUCHES 2 #define DEFAULT_POLL_PERIOD 20 @@ -42,6 +43,7 @@ struct firmware_version { struct ili210x { struct i2c_client *client; struct input_dev *input; + struct gpio_desc *reset_gpio; }; static int ili210x_read_reg(struct i2c_client *client, u8 reg, void *buf, @@ -158,6 +160,7 @@ static int ili210x_i2c_probe(struct i2c_client *client, { struct device *dev = &client->dev; struct ili210x *priv; + struct gpio_desc *reset_gpio; struct input_dev *input; struct panel_info panel; struct firmware_version firmware; @@ -171,6 +174,17 @@ static int ili210x_i2c_probe(struct i2c_client *client, return -EINVAL; } + reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(reset_gpio)) + return PTR_ERR(reset_gpio); + + if (reset_gpio) { + gpiod_set_value_cansleep(reset_gpio, 1); + usleep_range(50, 100); + gpiod_set_value_cansleep(reset_gpio, 0); + mdelay(100); + } + /* Get firmware version */ error = ili210x_read_reg(client, REG_FIRMWARE_VERSION, &firmware, sizeof(firmware)); @@ -198,6 +212,7 @@ static int ili210x_i2c_probe(struct i2c_client *client, priv->client = client; priv->input = input; + priv->reset_gpio = reset_gpio; /* Setup input device */ input->name = "ILI210x Touchscreen"; @@ -256,8 +271,12 @@ static int ili210x_i2c_probe(struct i2c_client *client, static int ili210x_i2c_remove(struct i2c_client *client) { + struct ili210x *priv = i2c_get_clientdata(client); + sysfs_remove_group(&client->dev.kobj, &ili210x_attr_group); input_unregister_device(priv->input); + if (priv->reset_gpio) + gpiod_set_value_cansleep(priv->reset_gpio, 1); return 0; } From patchwork Thu Dec 13 15:14:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10728889 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 7876114DE for ; Thu, 13 Dec 2018 15:15:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6852528742 for ; Thu, 13 Dec 2018 15:15:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C4EE2C45E; Thu, 13 Dec 2018 15:15:14 +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=-7.9 required=2.0 tests=BAYES_00,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 E700C28742 for ; Thu, 13 Dec 2018 15:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729444AbeLMPPN (ORCPT ); Thu, 13 Dec 2018 10:15:13 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:55432 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728591AbeLMPPN (ORCPT ); Thu, 13 Dec 2018 10:15:13 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43Fy0Z0k8sz1qyB7; Thu, 13 Dec 2018 16:15:10 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43Fy0Z0XlSz1qtfL; Thu, 13 Dec 2018 16:15:10 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id cuXfweM8a0K4; Thu, 13 Dec 2018 16:15:07 +0100 (CET) X-Auth-Info: BKZkhKNQPwSgRDJsLtJEG6E+g7qrtMEvNlpdqX+tjuU= Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz [86.49.110.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 13 Dec 2018 16:15:07 +0100 (CET) From: Marek Vasut To: linux-input@vger.kernel.org Cc: Marek Vasut , Dmitry Torokhov , Henrik Rydberg , Olivier Sobrie Subject: [PATCH 5/8] input: touchscreen: ili210x: Rework the touchscreen sample processing Date: Thu, 13 Dec 2018 16:14:39 +0100 Message-Id: <20181213151442.27854-6-marex@denx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181213151442.27854-1-marex@denx.de> References: <20181213151442.27854-1-marex@denx.de> 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 Get rid of the packed structures for representing data as that does not apply to other similar Ilitek touchscreens. Instead, implement a function which parses the data and reports touch events and coordinates. Signed-off-by: Marek Vasut Cc: Dmitry Torokhov Cc: Henrik Rydberg Cc: Olivier Sobrie To: linux-input@vger.kernel.org --- drivers/input/touchscreen/ili210x.c | 54 ++++++++++++++++------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index 7579cf16b3663..2354e487c796a 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -16,20 +16,11 @@ #define REG_FIRMWARE_VERSION 0x40 #define REG_CALIBRATE 0xcc -struct finger { +struct panel_info { u8 x_low; u8 x_high; u8 y_low; u8 y_high; -} __packed; - -struct touchdata { - u8 status; - struct finger finger[MAX_TOUCHES]; -} __packed; - -struct panel_info { - struct finger finger_max; u8 xchannel_num; u8 ychannel_num; } __packed; @@ -72,25 +63,40 @@ static int ili210x_read_reg(struct i2c_client *client, u8 reg, void *buf, return 0; } -static void ili210x_report_events(struct input_dev *input, - const struct touchdata *touchdata) +static bool ili210x_touchdata_to_coords(struct ili210x *priv, u8 *touchdata, + unsigned int finger, + unsigned int *x, unsigned int *y) +{ + u8 x_low, x_high, y_low, y_high; + + if (finger >= MAX_TOUCHES) + return false; + + if (touchdata[0] & BIT(finger)) + return false; + + x_high = touchdata[1 + (finger * 4) + 0]; + x_low = touchdata[1 + (finger * 4) + 1]; + y_high = touchdata[1 + (finger * 4) + 2]; + y_low = touchdata[1 + (finger * 4) + 3]; + *x = x_low | (x_high << 8); + *y = y_low | (y_high << 8); + + return true; +} + +static void ili210x_report_events(struct ili210x *priv, u8 *touchdata) { int i; bool touch; unsigned int x, y; - const struct finger *finger; for (i = 0; i < MAX_TOUCHES; i++) { input_mt_slot(input, i); - finger = &touchdata->finger[i]; - - touch = touchdata->status & (1 << i); + touch = ili210x_touchdata_to_coords(priv, touchdata, i, &x, &y); input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); if (touch) { - x = finger->x_low | (finger->x_high << 8); - y = finger->y_low | (finger->y_high << 8); - input_report_abs(input, ABS_MT_POSITION_X, x); input_report_abs(input, ABS_MT_POSITION_Y, y); } @@ -104,18 +110,18 @@ static irqreturn_t ili210x_irq(int irq, void *irq_data) { struct ili210x *priv = irq_data; struct i2c_client *client = priv->client; - struct touchdata touchdata; + u8 touchdata[1 + 4 * MAX_TOUCHES]; int error; error = ili210x_read_reg(client, REG_TOUCHDATA, - &touchdata, sizeof(touchdata)); + touchdata, sizeof(touchdata)); if (error) { dev_err(&client->dev, "Unable to get touchdata, err = %d\n", error); return IRQ_HANDLED; } - ili210x_report_events(priv, &touchdata); + ili210x_report_events(priv, touchdata); return IRQ_HANDLED; } @@ -202,8 +208,8 @@ static int ili210x_i2c_probe(struct i2c_client *client, return error; } - xmax = panel.finger_max.x_low | (panel.finger_max.x_high << 8); - ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8); + xmax = panel.x_low | (panel.x_high << 8); + ymax = panel.y_low | (panel.y_high << 8); priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); input = devm_input_allocate_device(dev); From patchwork Thu Dec 13 15:14:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10728891 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 0BB2714DE for ; Thu, 13 Dec 2018 15:15:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF1B328742 for ; Thu, 13 Dec 2018 15:15:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E23DE2C4BA; Thu, 13 Dec 2018 15:15:19 +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=-7.9 required=2.0 tests=BAYES_00,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 61DFB28742 for ; Thu, 13 Dec 2018 15:15:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729453AbeLMPPS (ORCPT ); Thu, 13 Dec 2018 10:15:18 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:55170 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728591AbeLMPPS (ORCPT ); Thu, 13 Dec 2018 10:15:18 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43Fy0h5Sg7z1qyCC; Thu, 13 Dec 2018 16:15:16 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43Fy0h56Wkz1qtfL; Thu, 13 Dec 2018 16:15:16 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id fc1ZRPfUjFE1; Thu, 13 Dec 2018 16:15:10 +0100 (CET) X-Auth-Info: UBfcqNgPZdFawlbO6Cj0cI59+NzG99tlbEImuwQoPNo= Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz [86.49.110.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 13 Dec 2018 16:15:10 +0100 (CET) From: Marek Vasut To: linux-input@vger.kernel.org Cc: Marek Vasut , Dmitry Torokhov , Henrik Rydberg , Olivier Sobrie Subject: [PATCH 6/8] input: touchscreen: ili210x: Reorder probe Date: Thu, 13 Dec 2018 16:14:40 +0100 Message-Id: <20181213151442.27854-7-marex@denx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181213151442.27854-1-marex@denx.de> References: <20181213151442.27854-1-marex@denx.de> 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 Perform the register access only after the I2C client data are set, this is only done in preparation for the subsequent patch which uses the I2C client data in the register IO function. Signed-off-by: Marek Vasut Cc: Dmitry Torokhov Cc: Henrik Rydberg Cc: Olivier Sobrie To: linux-input@vger.kernel.org --- drivers/input/touchscreen/ili210x.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index 2354e487c796a..4d11e6cd9a1b6 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -191,6 +191,17 @@ static int ili210x_i2c_probe(struct i2c_client *client, mdelay(100); } + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + input = devm_input_allocate_device(dev); + if (!priv || !input) + return -ENOMEM; + + priv->client = client; + priv->input = input; + priv->reset_gpio = reset_gpio; + + i2c_set_clientdata(client, priv); + /* Get firmware version */ error = ili210x_read_reg(client, REG_FIRMWARE_VERSION, &firmware, sizeof(firmware)); @@ -211,15 +222,6 @@ static int ili210x_i2c_probe(struct i2c_client *client, xmax = panel.x_low | (panel.x_high << 8); ymax = panel.y_low | (panel.y_high << 8); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - input = devm_input_allocate_device(dev); - if (!priv || !input) - return -ENOMEM; - - priv->client = client; - priv->input = input; - priv->reset_gpio = reset_gpio; - /* Setup input device */ input->name = "ILI210x Touchscreen"; input->id.bustype = BUS_I2C; @@ -239,8 +241,6 @@ static int ili210x_i2c_probe(struct i2c_client *client, input_set_abs_params(input, ABS_MT_POSITION_X, 0, xmax, 0, 0); input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ymax, 0, 0); - i2c_set_clientdata(client, priv); - error = devm_request_threaded_irq(dev, client->irq, NULL, ili210x_irq, IRQF_ONESHOT, client->name, priv); if (error) { From patchwork Thu Dec 13 15:14:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10728893 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 2F42B91E for ; Thu, 13 Dec 2018 15:15:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EACA2C442 for ; Thu, 13 Dec 2018 15:15:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1026228742; Thu, 13 Dec 2018 15:15:20 +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=-7.9 required=2.0 tests=BAYES_00,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 B796F2C442 for ; Thu, 13 Dec 2018 15:15:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728591AbeLMPPT (ORCPT ); Thu, 13 Dec 2018 10:15:19 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:35698 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729445AbeLMPPT (ORCPT ); Thu, 13 Dec 2018 10:15:19 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43Fy0j52fDz1qyCG; Thu, 13 Dec 2018 16:15:17 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43Fy0j4jTzz1qtfS; Thu, 13 Dec 2018 16:15:17 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id WyhdcGhf0Z32; Thu, 13 Dec 2018 16:15:16 +0100 (CET) X-Auth-Info: sIrCFP96/VM9eppmee8NIGGHN9pACbizUy2bMdI8dQs= Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz [86.49.110.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 13 Dec 2018 16:15:16 +0100 (CET) From: Marek Vasut To: linux-input@vger.kernel.org Cc: Marek Vasut , Dmitry Torokhov , Henrik Rydberg , Olivier Sobrie Subject: [PATCH 7/8] input: touchscreen: ili210x: Add OF match table Date: Thu, 13 Dec 2018 16:14:41 +0100 Message-Id: <20181213151442.27854-8-marex@denx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181213151442.27854-1-marex@denx.de> References: <20181213151442.27854-1-marex@denx.de> 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 Add OF match table for the ili210x touchscreen. Signed-off-by: Marek Vasut Cc: Dmitry Torokhov Cc: Henrik Rydberg Cc: Olivier Sobrie To: linux-input@vger.kernel.org --- drivers/input/touchscreen/ili210x.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index 4d11e6cd9a1b6..1a4bf0f717b2b 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -316,10 +316,17 @@ static const struct i2c_device_id ili210x_i2c_id[] = { }; MODULE_DEVICE_TABLE(i2c, ili210x_i2c_id); +static const struct of_device_id ili210x_dt_ids[] = { + { .compatible = "ilitek,ili210x", }, + { }, +}; +MODULE_DEVICE_TABLE(of, ili210x_dt_ids); + static struct i2c_driver ili210x_ts_driver = { .driver = { .name = "ili210x_i2c", .pm = &ili210x_i2c_pm, + .of_match_table = ili210x_dt_ids, }, .id_table = ili210x_i2c_id, .probe = ili210x_i2c_probe, From patchwork Thu Dec 13 15:14:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10728895 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 8394014DE for ; Thu, 13 Dec 2018 15:15:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7301C28742 for ; Thu, 13 Dec 2018 15:15:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 679892C4BA; Thu, 13 Dec 2018 15:15:23 +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=-7.9 required=2.0 tests=BAYES_00,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 C340928742 for ; Thu, 13 Dec 2018 15:15:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729456AbeLMPPW (ORCPT ); Thu, 13 Dec 2018 10:15:22 -0500 Received: from mail-out.m-online.net ([212.18.0.9]:42592 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729445AbeLMPPW (ORCPT ); Thu, 13 Dec 2018 10:15:22 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43Fy0l2Hcmz1qxlF; Thu, 13 Dec 2018 16:15:19 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43Fy0l1PWJz1qtfM; Thu, 13 Dec 2018 16:15:19 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id kcebh2D1DVnq; Thu, 13 Dec 2018 16:15:17 +0100 (CET) X-Auth-Info: uw53tHo6KpjgsdlE+GXyaClFhri57/QgVzl67pjQ/20= Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz [86.49.110.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 13 Dec 2018 16:15:17 +0100 (CET) From: Marek Vasut To: linux-input@vger.kernel.org Cc: Marek Vasut , Dmitry Torokhov , Henrik Rydberg , Olivier Sobrie Subject: [PATCH 8/8] input: touchscreen: ili210x: Add ILI251X support Date: Thu, 13 Dec 2018 16:14:42 +0100 Message-Id: <20181213151442.27854-9-marex@denx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181213151442.27854-1-marex@denx.de> References: <20181213151442.27854-1-marex@denx.de> 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 Add support for ILI251x touch controller. This controller is similar to the ILI210x, except for the following differences: - Does not support I2C R-W transfer, Read must be followed by an obscenely long delay, and then followed by Write - Does support 10 simultaneous touch inputs. - Touch data format is slightly different, pressure reporting does not work although the touch data contain such information. Signed-off-by: Marek Vasut Cc: Dmitry Torokhov Cc: Henrik Rydberg Cc: Olivier Sobrie To: linux-input@vger.kernel.org --- drivers/input/touchscreen/ili210x.c | 121 ++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 14 deletions(-) diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index 1a4bf0f717b2b..b76fa3736d492 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -6,8 +6,10 @@ #include #include #include +#include -#define MAX_TOUCHES 2 +#define ILI210X_TOUCHES 2 +#define ILI251X_TOUCHES 10 #define DEFAULT_POLL_PERIOD 20 /* Touchscreen commands */ @@ -31,15 +33,23 @@ struct firmware_version { u8 minor; } __packed; +enum ili2xxx_model { + MODEL_ILI210X, + MODEL_ILI251X, +}; + struct ili210x { struct i2c_client *client; struct input_dev *input; struct gpio_desc *reset_gpio; + enum ili2xxx_model model; + unsigned int max_touches; }; static int ili210x_read_reg(struct i2c_client *client, u8 reg, void *buf, size_t len) { + struct ili210x *priv = i2c_get_clientdata(client); struct i2c_msg msg[2] = { { .addr = client->addr, @@ -55,7 +65,38 @@ static int ili210x_read_reg(struct i2c_client *client, u8 reg, void *buf, } }; - if (i2c_transfer(client->adapter, msg, 2) != 2) { + if (priv->model == MODEL_ILI251X) { + if (i2c_transfer(client->adapter, msg, 1) != 1) { + dev_err(&client->dev, "i2c transfer failed\n"); + return -EIO; + } + + mdelay(5); + + if (i2c_transfer(client->adapter, msg + 1, 1) != 1) { + dev_err(&client->dev, "i2c transfer failed\n"); + return -EIO; + } + } else { + if (i2c_transfer(client->adapter, msg, 2) != 2) { + dev_err(&client->dev, "i2c transfer failed\n"); + return -EIO; + } + } + + return 0; +} + +static int ili210x_read(struct i2c_client *client, void *buf, size_t len) +{ + struct i2c_msg msg = { + .addr = client->addr, + .flags = I2C_M_RD, + .len = len, + .buf = buf, + }; + + if (i2c_transfer(client->adapter, &msg, 1) != 1) { dev_err(&client->dev, "i2c transfer failed\n"); return -EIO; } @@ -69,7 +110,7 @@ static bool ili210x_touchdata_to_coords(struct ili210x *priv, u8 *touchdata, { u8 x_low, x_high, y_low, y_high; - if (finger >= MAX_TOUCHES) + if (finger >= ILI210X_TOUCHES) return false; if (touchdata[0] & BIT(finger)) @@ -85,16 +126,48 @@ static bool ili210x_touchdata_to_coords(struct ili210x *priv, u8 *touchdata, return true; } +static bool ili251x_touchdata_to_coords(struct ili210x *priv, u8 *touchdata, + unsigned int finger, + unsigned int *x, unsigned int *y) +{ + u8 x_low, x_high, y_low, y_high; + + if (finger >= ILI251X_TOUCHES) + return false; + + x_high = touchdata[1 + (finger * 5) + 0]; + if (!(x_high & BIT(7))) /* Touch indication */ + return false; + + x_high &= 0x3f; + x_low = touchdata[1 + (finger * 5) + 1]; + y_high = touchdata[1 + (finger * 5) + 2]; + y_low = touchdata[1 + (finger * 5) + 3]; + + *x = x_low | (x_high << 8); + *y = y_low | (y_high << 8); + + return true; +} + static void ili210x_report_events(struct ili210x *priv, u8 *touchdata) { + struct input_dev *input = priv->input; int i; - bool touch; - unsigned int x, y; + bool touch = false; + unsigned int x = 0, y = 0; - for (i = 0; i < MAX_TOUCHES; i++) { + for (i = 0; i < priv->max_touches; i++) { input_mt_slot(input, i); - touch = ili210x_touchdata_to_coords(priv, touchdata, i, &x, &y); + if (priv->model == MODEL_ILI210X) { + touch = ili210x_touchdata_to_coords(priv, touchdata, + i, &x, &y); + } else if (priv->model == MODEL_ILI251X) { + touch = ili251x_touchdata_to_coords(priv, touchdata, + i, &x, &y); + } + input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); if (touch) { input_report_abs(input, ABS_MT_POSITION_X, x); @@ -110,11 +183,19 @@ static irqreturn_t ili210x_irq(int irq, void *irq_data) { struct ili210x *priv = irq_data; struct i2c_client *client = priv->client; - u8 touchdata[1 + 4 * MAX_TOUCHES]; - int error; + u8 touchdata[64] = { 0 }; + int error = -EINVAL; + + if (priv->model == MODEL_ILI210X) { + error = ili210x_read_reg(client, REG_TOUCHDATA, + touchdata, sizeof(touchdata)); + } else if (priv->model == MODEL_ILI251X) { + error = ili210x_read_reg(client, REG_TOUCHDATA, + touchdata, 31); + if (!error && touchdata[0] == 2) + error = ili210x_read(client, touchdata, 20); + } - error = ili210x_read_reg(client, REG_TOUCHDATA, - touchdata, sizeof(touchdata)); if (error) { dev_err(&client->dev, "Unable to get touchdata, err = %d\n", error); @@ -161,6 +242,8 @@ static const struct attribute_group ili210x_attr_group = { .attrs = ili210x_attributes, }; +static const struct i2c_device_id ili210x_i2c_id[]; + static int ili210x_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -170,9 +253,12 @@ static int ili210x_i2c_probe(struct i2c_client *client, struct input_dev *input; struct panel_info panel; struct firmware_version firmware; + enum ili2xxx_model model; int xmax, ymax; int error; + model = (enum ili2xxx_model)id->driver_data; + dev_dbg(dev, "Probing for ILI210X I2C Touschreen driver"); if (client->irq <= 0) { @@ -199,6 +285,11 @@ static int ili210x_i2c_probe(struct i2c_client *client, priv->client = client; priv->input = input; priv->reset_gpio = reset_gpio; + priv->model = model; + if (model == MODEL_ILI210X) + priv->max_touches = ILI210X_TOUCHES; + if (model == MODEL_ILI251X) + priv->max_touches = ILI251X_TOUCHES; i2c_set_clientdata(client, priv); @@ -237,7 +328,7 @@ static int ili210x_i2c_probe(struct i2c_client *client, input_set_abs_params(input, ABS_Y, 0, ymax, 0, 0); /* Multi touch */ - input_mt_init_slots(input, MAX_TOUCHES, 0); + input_mt_init_slots(input, priv->max_touches, 0); input_set_abs_params(input, ABS_MT_POSITION_X, 0, xmax, 0, 0); input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ymax, 0, 0); @@ -311,13 +402,15 @@ static SIMPLE_DEV_PM_OPS(ili210x_i2c_pm, ili210x_i2c_suspend, ili210x_i2c_resume); static const struct i2c_device_id ili210x_i2c_id[] = { - { "ili210x", 0 }, + { "ili210x", MODEL_ILI210X }, + { "ili251x", MODEL_ILI251X }, { } }; MODULE_DEVICE_TABLE(i2c, ili210x_i2c_id); static const struct of_device_id ili210x_dt_ids[] = { - { .compatible = "ilitek,ili210x", }, + { .compatible = "ilitek,ili210x", .data = (void *)MODEL_ILI210X }, + { .compatible = "ilitek,ili251x", .data = (void *)MODEL_ILI251X }, { }, }; MODULE_DEVICE_TABLE(of, ili210x_dt_ids);