From patchwork Wed Nov 4 01:29:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Anderson X-Patchwork-Id: 11879467 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8BD506A2 for ; Wed, 4 Nov 2020 01:30:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5DF4A223C7 for ; Wed, 4 Nov 2020 01:30:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="kFPDQu9g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730225AbgKDBaC (ORCPT ); Tue, 3 Nov 2020 20:30:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730234AbgKDBaC (ORCPT ); Tue, 3 Nov 2020 20:30:02 -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 2CE5BC0401C1 for ; Tue, 3 Nov 2020 17:30:01 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id z1so9462657plo.12 for ; Tue, 03 Nov 2020 17:30:01 -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=E+cZah/q0g9jl4Q/67CpDAAwhQR4OuHdsGIQ7vS19NA=; b=kFPDQu9gdkWPECvdYqq05fIxB4KoU25ijItILqJNxvTc/5B1vpXMv0ufWftrniVQiW QY+zz1y4ZC6VTrvavj0TaD7PCVNjGoshymnQyND6A0ZdEBm6aBbrOavkfnHcZ7TzwtnN MmOdLE6DDmy3n4aIoV85zscu7TPHXfa1xMVo8= 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=E+cZah/q0g9jl4Q/67CpDAAwhQR4OuHdsGIQ7vS19NA=; b=LCiItBccvWD8bAZhMG4eyAMRa3zdk0xh7SOPZaaIzZMBstOKrah6dZ3+rvp3lawVTv wbNEtmQ8RoHLKfDqxPxmeNi8bQW6+Pm7G176AYZYGslZih90n7J0/CgURJz4w/3Z+hjW IU3Wz20qErdfrkHeFQW8luaC0p9D/+yNydfMgpnPggDY4SilKIZ9hBUQ3QmxE6HWtrLl bf79P0q9gYvAop/ROUQkGBnoYKnm1jnuMsQN3e+FJkb06aZAcHLCF9KGko1TuDHJ/S0e HShWqlnlqX7hU62nfvAqEbVGK5aavI+cDDkL8+pZ80C0l9a8DAoPolmMP2stzNLUbdwg d68Q== X-Gm-Message-State: AOAM532L/5JuQEKlloub+wqZyzZezUa8scKtc3CccwrchUqunD8e0a36 jKKuxpOAj3NuIp/cRj7UkH+ayg== X-Google-Smtp-Source: ABdhPJz2madxkcDZ2Gv0YgLbwiZcpePYjx4aVUVimBHhyxlJt5LLztUconxKvoalnaC28UlIJdReLQ== X-Received: by 2002:a17:902:8e8b:b029:d2:4276:1df0 with SMTP id bg11-20020a1709028e8bb02900d242761df0mr27268491plb.62.1604453400693; Tue, 03 Nov 2020 17:30:00 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:42b0:34ff:fe3d:58e6]) by smtp.gmail.com with ESMTPSA id m3sm347424pjv.52.2020.11.03.17.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 17:30:00 -0800 (PST) From: Douglas Anderson To: jkosina@suse.cz, benjamin.tissoires@redhat.com, gregkh@linuxfoundation.org, Dmitry Torokhov Cc: linux-input@vger.kernel.org, swboyd@chromium.org, andrea@borgia.bo.it, kai.heng.feng@canonical.com, hdegoede@redhat.com, robh+dt@kernel.org, Douglas Anderson , Jiri Kosina , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v4 4/4] HID: i2c-hid: Introduce goodix-i2c-hid as a subclass of i2c-hid Date: Tue, 3 Nov 2020 17:29:29 -0800 Message-Id: <20201103172824.v4.4.If41b7d621633b94d56653c6d53f5f89c5274de7b@changeid> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201104012929.3850691-1-dianders@chromium.org> References: <20201104012929.3850691-1-dianders@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@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 v4: - Totally redid based on the new subclass system. Changes in v3: - Rework to use subclassing. drivers/hid/i2c-hid/Kconfig | 19 +++- drivers/hid/i2c-hid/Makefile | 1 + drivers/hid/i2c-hid/i2c-hid-of-goodix.c | 120 ++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 drivers/hid/i2c-hid/i2c-hid-of-goodix.c diff --git a/drivers/hid/i2c-hid/Kconfig b/drivers/hid/i2c-hid/Kconfig index 819b7521c182..a16c6a69680b 100644 --- a/drivers/hid/i2c-hid/Kconfig +++ b/drivers/hid/i2c-hid/Kconfig @@ -32,10 +32,25 @@ config I2C_HID_OF will be called i2c-hid-of. It will also build/depend on the module i2c-hid. +config I2C_HID_OF_GOODIX + tristate "Driver for Goodix hid-i2c based devices on OF systems" + default n + depends on I2C && INPUT && OF + help + Say Y here if you want support for Goodix i2c devices that use + the i2c-hid protocol on Open Firmware (Device Tree)-based + systems. + + If unsure, say N. + + This support is also available as a module. If so, the module + will be called i2c-hid-of-goodix. It will also build/depend on + the module i2c-hid. + endmenu config I2C_HID_CORE tristate - default y if I2C_HID_ACPI=y || I2C_HID_OF=y - default m if I2C_HID_ACPI=m || I2C_HID_OF=m + default y if I2C_HID_ACPI=y || I2C_HID_OF=y || I2C_HID_OF_GOODIX=y + default m if I2C_HID_ACPI=m || I2C_HID_OF=m || I2C_HID_OF_GOODIX=m select HID diff --git a/drivers/hid/i2c-hid/Makefile b/drivers/hid/i2c-hid/Makefile index 9b4a73446841..302545a771f3 100644 --- a/drivers/hid/i2c-hid/Makefile +++ b/drivers/hid/i2c-hid/Makefile @@ -10,3 +10,4 @@ i2c-hid-$(CONFIG_DMI) += i2c-hid-dmi-quirks.o obj-$(CONFIG_I2C_HID_ACPI) += i2c-hid-acpi.o obj-$(CONFIG_I2C_HID_OF) += i2c-hid-of.o +obj-$(CONFIG_I2C_HID_OF_GOODIX) += i2c-hid-of-goodix.o diff --git a/drivers/hid/i2c-hid/i2c-hid-of-goodix.c b/drivers/hid/i2c-hid/i2c-hid-of-goodix.c new file mode 100644 index 000000000000..7b27fd8b7401 --- /dev/null +++ b/drivers/hid/i2c-hid/i2c-hid-of-goodix.c @@ -0,0 +1,120 @@ +// 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 "i2c-hid.h" + +struct goodix_i2c_hid_timing_data { + unsigned int post_gpio_reset_delay_ms; + unsigned int post_power_delay_ms; +}; + +struct i2c_hid_of_goodix { + struct i2chid_subclass_data subclass; + + struct regulator *vdd; + struct gpio_desc *reset_gpio; + const struct goodix_i2c_hid_timing_data *timings; +}; + +static int goodix_i2c_hid_power_up_device(struct i2chid_subclass_data *subclass) +{ + struct i2c_hid_of_goodix *ihid_goodix = + container_of(subclass, struct i2c_hid_of_goodix, subclass); + int ret; + + ret = regulator_enable(ihid_goodix->vdd); + if (ret) + return ret; + + if (ihid_goodix->timings->post_power_delay_ms) + msleep(ihid_goodix->timings->post_power_delay_ms); + + gpiod_set_value_cansleep(ihid_goodix->reset_gpio, 0); + if (ihid_goodix->timings->post_gpio_reset_delay_ms) + msleep(ihid_goodix->timings->post_gpio_reset_delay_ms); + + return 0; +} + +static void goodix_i2c_hid_power_down_device(struct i2chid_subclass_data *subclass) +{ + struct i2c_hid_of_goodix *ihid_goodix = + container_of(subclass, struct i2c_hid_of_goodix, subclass); + + gpiod_set_value_cansleep(ihid_goodix->reset_gpio, 1); + regulator_disable(ihid_goodix->vdd); +} + +static int i2c_hid_of_goodix_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_hid_of_goodix *ihid_goodix; + + ihid_goodix = devm_kzalloc(&client->dev, sizeof(*ihid_goodix), + GFP_KERNEL); + if (!ihid_goodix) + return -ENOMEM; + + ihid_goodix->subclass.power_up_device = goodix_i2c_hid_power_up_device; + ihid_goodix->subclass.power_down_device = goodix_i2c_hid_power_down_device; + + /* Start out with reset asserted */ + ihid_goodix->reset_gpio = + devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(ihid_goodix->reset_gpio)) + return PTR_ERR(ihid_goodix->reset_gpio); + + ihid_goodix->vdd = devm_regulator_get(&client->dev, "vdd"); + if (IS_ERR(ihid_goodix->vdd)) + return PTR_ERR(ihid_goodix->vdd); + + ihid_goodix->timings = device_get_match_data(&client->dev); + + return i2c_hid_core_probe(client, &ihid_goodix->subclass, 0x0001); +} + +static const struct goodix_i2c_hid_timing_data goodix_gt7375p_timing_data = { + .post_power_delay_ms = 10, + .post_gpio_reset_delay_ms = 120, +}; + +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_core_suspend, i2c_hid_core_resume) +}; + +static struct i2c_driver goodix_i2c_hid_ts_driver = { + .driver = { + .name = "i2c_hid_of_goodix", + .pm = &goodix_i2c_hid_pm, + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + .of_match_table = of_match_ptr(goodix_i2c_hid_of_match), + }, + .probe = i2c_hid_of_goodix_probe, + .remove = i2c_hid_core_remove, + .shutdown = i2c_hid_core_shutdown, +}; +module_i2c_driver(goodix_i2c_hid_ts_driver); + +MODULE_AUTHOR("Douglas Anderson "); +MODULE_DESCRIPTION("Goodix i2c-hid touchscreen driver"); +MODULE_LICENSE("GPL v2");