From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6BACC4742C for ; Tue, 3 Nov 2020 00:13:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A266D22275 for ; Tue, 3 Nov 2020 00:13:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aDVU2nzb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727227AbgKCANM (ORCPT ); Mon, 2 Nov 2020 19:13:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727193AbgKCANK (ORCPT ); Mon, 2 Nov 2020 19:13:10 -0500 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 351CDC0617A6 for ; Mon, 2 Nov 2020 16:13:10 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id w11so7680793pll.8 for ; Mon, 02 Nov 2020 16:13:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=97UEiB822+bqf5cp9dtnLiwnHYdHrQTsb2r4ia6eYtA=; b=aDVU2nzb2iKQxsov5JiAryU6VsMoZwDbY3EnI6IjFtjZEIEJjKAkEkssfGbDo3tXNi 33bfUPC0/YjtRi5EuPAZZUH7ooyT0pXvS2gtymCaZ1b2/HDZEUscDmt2idjXF5rhkRBj x1AAezfDTresNl0hzFvsrrwlsxysOyySx+IsQ= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=97UEiB822+bqf5cp9dtnLiwnHYdHrQTsb2r4ia6eYtA=; b=SoRsNJzCHrMkyMNY83C4Ik1BgqgNoBWIcPopIMonzfwuCR0xwrlKrOYy0gKhRadTHj pUHUfflgddfO4HvruBRC6BWNSjNy3K0a14wPJWnsSkEa82/ILOwPjP3BVJQ7NfjxHJro +ds3MH/CXABeLT0nmjK8uVYXKMXQTPaG/DNG1/hbQpRdbEdS3Fu6SkKBrwAx0KL9c+Oe 1nVuMsHxJDw20l+AoeaxCZMwcJYjChErc9knPibFOl2+rb919DQy3dMxoTdYQLqgb5n8 376LOooiAiIJzqFhD7quVka89aTeXui3tItlyplBtlZOg6C1Fy0B05KJ4+Kx/gn3NiTv ejrA== X-Gm-Message-State: AOAM533sOKnrFzIxNeCEKNsL8UHkMS5mjl6M16eS0Csj8zI7Ie7rndGP jZpkM1PVyMh+7jd/Lfkg6E4SmQ== X-Google-Smtp-Source: ABdhPJyQMaFVKP/JVrDd7qFFIFAJNqE7LOR3R6jgdcD/jZC/RstC2B1bNRiN5YSLqjnkisQ1/NKapA== X-Received: by 2002:a17:902:c383:b029:d6:991c:671b with SMTP id g3-20020a170902c383b02900d6991c671bmr18366735plg.51.1604362389743; Mon, 02 Nov 2020 16:13:09 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:42b0:34ff:fe3d:58e6]) by smtp.gmail.com with ESMTPSA id v16sm13244295pgk.26.2020.11.02.16.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 16:13:09 -0800 (PST) From: Douglas Anderson To: jkosina@suse.cz, benjamin.tissoires@redhat.com, gregkh@linuxfoundation.org, Dmitry Torokhov Cc: linux-input@vger.kernel.org, hdegoede@redhat.com, swboyd@chromium.org, kai.heng.feng@canonical.com, robh+dt@kernel.org, andrea@borgia.bo.it, Douglas Anderson , Krzysztof Kozlowski , Linus Walleij , Michael Srba , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] Input: Introduce goodix-i2c-hid as a subclass of i2c-hid Date: Mon, 2 Nov 2020 16:12:41 -0800 Message-Id: <20201102161210.v3.3.If41b7d621633b94d56653c6d53f5f89c5274de7b@changeid> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201102161210.v3.1.Ibb28033c81d87fcc13a6ba28c6ea7ac154d65f93@changeid> References: <20201102161210.v3.1.Ibb28033c81d87fcc13a6ba28c6ea7ac154d65f93@changeid> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Goodix i2c-hid touchscreens are mostly i2c-hid compliant but have some special power sequencing requirements, including the need to drive a reset line during the sequencing. Let's use the new ability of i2c-hid to have subclasses for power sequencing to support the first Goodix i2c-hid touchscreen: GT7375P Signed-off-by: Douglas Anderson --- Changes in v3: - Rework to use subclassing. drivers/input/touchscreen/Kconfig | 12 +++ drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/goodix-i2c-hid.c | 115 +++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 drivers/input/touchscreen/goodix-i2c-hid.c diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index f012fe746df0..64d481101917 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -403,6 +403,18 @@ config TOUCHSCREEN_GOODIX To compile this driver as a module, choose M here: the module will be called goodix. +config TOUCHSCREEN_GOODIX_I2C_HID + tristate "Goodix I2C-HID touchscreen" + depends on I2C_HID + help + Say Y here if you have a Goodix touchscreen that uses i2c-hid + to communicate. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called goodix-i2c-hid. + config TOUCHSCREEN_HIDEEP tristate "HiDeep Touch IC" depends on I2C diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 6233541e9173..32b1a768aa06 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -45,6 +45,7 @@ obj-$(CONFIG_TOUCHSCREEN_EGALAX_SERIAL) += egalax_ts_serial.o obj-$(CONFIG_TOUCHSCREEN_EXC3000) += exc3000.o obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix.o +obj-$(CONFIG_TOUCHSCREEN_GOODIX_I2C_HID) += goodix-i2c-hid.o obj-$(CONFIG_TOUCHSCREEN_HIDEEP) += hideep.o obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o obj-$(CONFIG_TOUCHSCREEN_IMX6UL_TSC) += imx6ul_tsc.o diff --git a/drivers/input/touchscreen/goodix-i2c-hid.c b/drivers/input/touchscreen/goodix-i2c-hid.c new file mode 100644 index 000000000000..a2cc4f923d8a --- /dev/null +++ b/drivers/input/touchscreen/goodix-i2c-hid.c @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for Goodix touchscreens that use the i2c-hid protocol. + * + * Copyright 2020 Google LLC + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct goodix_i2c_hid_timing_data { + unsigned int post_gpio_reset_delay_ms; + unsigned int post_power_delay_ms; +}; + +static const struct goodix_i2c_hid_timing_data goodix_gt7375p_timing_data = { + .post_power_delay_ms = 10, + .post_gpio_reset_delay_ms = 120, +}; + +struct goodix_i2c_hid_plat_data { + struct gpio_desc *reset_gpio; + const struct goodix_i2c_hid_timing_data *timings; + + struct i2c_hid_platform_data ihid_pdata; +}; + +static int goodix_i2c_hid_power_up_device(struct i2c_hid_platform_data *ihid_pdata) +{ + struct goodix_i2c_hid_plat_data *pdata = ihid_pdata->power_data; + int ret; + + ret = regulator_bulk_enable(ARRAY_SIZE(ihid_pdata->supplies), + ihid_pdata->supplies); + if (ret) + return ret; + + if (pdata->timings->post_power_delay_ms) + msleep(pdata->timings->post_power_delay_ms); + + gpiod_set_value_cansleep(pdata->reset_gpio, 0); + if (pdata->timings->post_gpio_reset_delay_ms) + msleep(pdata->timings->post_gpio_reset_delay_ms); + + return 0; +} + +static void goodix_i2c_hid_power_down_device(struct i2c_hid_platform_data *ihid_pdata) +{ + struct goodix_i2c_hid_plat_data *pdata = ihid_pdata->power_data; + + gpiod_set_value_cansleep(pdata->reset_gpio, 1); + regulator_bulk_disable(ARRAY_SIZE(ihid_pdata->supplies), + ihid_pdata->supplies); +} + +static int goodix_i2c_hid_ts_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct goodix_i2c_hid_plat_data *pdata; + + pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); + + /* Start out with reset asserted */ + pdata->reset_gpio = + devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(pdata->reset_gpio)) + return PTR_ERR(pdata->reset_gpio); + + pdata->timings = device_get_match_data(&client->dev); + + pdata->ihid_pdata.hid_descriptor_address = 0x0001; + pdata->ihid_pdata.power_data = pdata; + pdata->ihid_pdata.power_up_device = goodix_i2c_hid_power_up_device; + pdata->ihid_pdata.power_down_device = goodix_i2c_hid_power_down_device; + + client->dev.platform_data = &pdata->ihid_pdata; + + return i2c_hid_probe(client, id); +} + +static const struct of_device_id goodix_i2c_hid_of_match[] = { + { .compatible = "goodix,gt7375p", .data = &goodix_gt7375p_timing_data }, + { } +}; +MODULE_DEVICE_TABLE(of, goodix_i2c_hid_of_match); + +static const struct dev_pm_ops goodix_i2c_hid_pm = { + SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume) +}; + +static struct i2c_driver goodix_i2c_hid_ts_driver = { + .driver = { + .name = "goodix-i2c-hid", + .pm = &goodix_i2c_hid_pm, + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + .of_match_table = of_match_ptr(goodix_i2c_hid_of_match), + }, + .probe = goodix_i2c_hid_ts_probe, + .remove = i2c_hid_remove, + .shutdown = i2c_hid_shutdown, +}; +module_i2c_driver(goodix_i2c_hid_ts_driver); + +MODULE_AUTHOR("Douglas Anderson "); +MODULE_DESCRIPTION("Goodix i2c-hid touchscreen driver"); +MODULE_LICENSE("GPL v2"); -- 2.29.1.341.ge80a0c044ae-goog