From patchwork Thu Apr 13 09:36:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13210015 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 098DBC77B6C for ; Thu, 13 Apr 2023 09:37:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230204AbjDMJhQ (ORCPT ); Thu, 13 Apr 2023 05:37:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbjDMJhO (ORCPT ); Thu, 13 Apr 2023 05:37:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC64E10FC for ; Thu, 13 Apr 2023 02:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681378589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UFLbyQ/siPdTt/ksUTe6CUAuQDKxUj93BikknIIghx8=; b=UbaS8TanozLmVXpz2gkTGhYT8WSFXoh5pnoNdT/A3Ugo2txQSH6to9Ottj9hfF7bn9XJEI Dcnf0uwgks6lrpOLwgQy+6Tmr8HgX/et6wAjEwN1JYCLc23LcamQiJT2Igs1VlZuwFOQZ+ ZsOV07X48fdZ6Yrt34JfS+2/rC7naYA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-106-zklUxsNpO8KTDd4x4kZ1aQ-1; Thu, 13 Apr 2023 05:36:28 -0400 X-MC-Unique: zklUxsNpO8KTDd4x4kZ1aQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3E0B81C0879F; Thu, 13 Apr 2023 09:36:28 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.195.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B0B7C16028; Thu, 13 Apr 2023 09:36:27 +0000 (UTC) From: Hans de Goede To: Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , Douglas Anderson , linux-input@vger.kernel.org Subject: [PATCH v2 1/3] HID: i2c-hid-of: Consistenly use dev local variable in probe() Date: Thu, 13 Apr 2023 11:36:23 +0200 Message-Id: <20230413093625.71146-2-hdegoede@redhat.com> In-Reply-To: <20230413093625.71146-1-hdegoede@redhat.com> References: <20230413093625.71146-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org i2c_hid_of_probe() has a dev local variable pointing to &i2c_client->dev, consistently use this everywhere in i2c_hid_of_probe(). Signed-off-by: Hans de Goede --- drivers/hid/i2c-hid/i2c-hid-of.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-of.c b/drivers/hid/i2c-hid/i2c-hid-of.c index 10176568133a..c82a5a54c3e6 100644 --- a/drivers/hid/i2c-hid/i2c-hid-of.c +++ b/drivers/hid/i2c-hid/i2c-hid-of.c @@ -75,7 +75,7 @@ static int i2c_hid_of_probe(struct i2c_client *client) int ret; u32 val; - ihid_of = devm_kzalloc(&client->dev, sizeof(*ihid_of), GFP_KERNEL); + ihid_of = devm_kzalloc(dev, sizeof(*ihid_of), GFP_KERNEL); if (!ihid_of) return -ENOMEM; @@ -84,24 +84,21 @@ static int i2c_hid_of_probe(struct i2c_client *client) ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val); if (ret) { - dev_err(&client->dev, "HID register address not provided\n"); + dev_err(dev, "HID register address not provided\n"); return -ENODEV; } if (val >> 16) { - dev_err(&client->dev, "Bad HID register address: 0x%08x\n", - val); + dev_err(dev, "Bad HID register address: 0x%08x\n", val); return -EINVAL; } hid_descriptor_address = val; - if (!device_property_read_u32(&client->dev, "post-power-on-delay-ms", - &val)) + if (!device_property_read_u32(dev, "post-power-on-delay-ms", &val)) ihid_of->post_power_delay_ms = val; ihid_of->supplies[0].supply = "vdd"; ihid_of->supplies[1].supply = "vddl"; - ret = devm_regulator_bulk_get(&client->dev, - ARRAY_SIZE(ihid_of->supplies), + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ihid_of->supplies), ihid_of->supplies); if (ret) return ret; From patchwork Thu Apr 13 09:36:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13210018 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 120FFC77B6E for ; Thu, 13 Apr 2023 09:37:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230272AbjDMJhW (ORCPT ); Thu, 13 Apr 2023 05:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbjDMJhU (ORCPT ); Thu, 13 Apr 2023 05:37:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC7894EF2 for ; Thu, 13 Apr 2023 02:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681378593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZqvPZJAfawDAQ9NHo9T3b1Jmr1jDjUSR0TnjxNywKX0=; b=BGZb7/BSULk5PnEsdUpeeo/i51pCVGJTeJ+GdDbwgRrRUEIcz30j8+9wjKYVA6ndC06rcZ sAdrJQxSTy8U6AO/ifYKJ1AJXc0airYDfW4n/3ijgQAVnTSAOm57I25jviknNr7UPkDYSa po/KGceKGsfFeZV9VdPk7MoyJw6z5vk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-5UvQoKvWOYKTNMttNPfCEg-1; Thu, 13 Apr 2023 05:36:29 -0400 X-MC-Unique: 5UvQoKvWOYKTNMttNPfCEg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 504FD101A54F; Thu, 13 Apr 2023 09:36:29 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.195.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DC69C1602A; Thu, 13 Apr 2023 09:36:28 +0000 (UTC) From: Hans de Goede To: Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , Douglas Anderson , linux-input@vger.kernel.org Subject: [PATCH v2 2/3] HID: i2c-hid-of: Allow using i2c-hid-of on non OF platforms Date: Thu, 13 Apr 2023 11:36:24 +0200 Message-Id: <20230413093625.71146-3-hdegoede@redhat.com> In-Reply-To: <20230413093625.71146-1-hdegoede@redhat.com> References: <20230413093625.71146-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org There are some x86 tablets / 2-in-1s which ship with Android as their factory OS image. These have pretty broken ACPI tables, relying on everything being hardcoded in the factory kernel image. platform/x86/x86-android-tablets.c manually instantiates i2c-clients for i2c devices on these tablets to make them work with the mainline kernel. The Lenovo Yoga Book 1 (yb1-x90f/l) is such a 2-in-1. It has 2 I2C-HID devices its main touchscreen and a Wacom digitizer. Its main touchscreen can alternatively also be used in HiDeep's native protocol mode but for the Wacom digitizer we really need I2C-HID. This patch allows using i2c-hid-of on non OF platforms so that it can bind to a non ACPI instantiated i2c_client on x86 for the Wacom digitizer. Note the driver already has an "i2c-over-hid" i2c_device_id (rather then an of_device_id). Besides enabling building on non-OF platforms this also replaces the only of_property_read_u32() call with device_property_read_u32() note that other properties where already read using device_property_read_...(). Signed-off-by: Hans de Goede --- drivers/hid/i2c-hid/Kconfig | 6 ++++-- drivers/hid/i2c-hid/i2c-hid-of.c | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/hid/i2c-hid/Kconfig b/drivers/hid/i2c-hid/Kconfig index 4439be7fa74d..3be17109301a 100644 --- a/drivers/hid/i2c-hid/Kconfig +++ b/drivers/hid/i2c-hid/Kconfig @@ -23,12 +23,14 @@ config I2C_HID_ACPI config I2C_HID_OF tristate "HID over I2C transport layer Open Firmware driver" - depends on OF + # No "depends on OF" because this can also be used for manually + # (board-file) instantiated "hid-over-i2c" type i2c-clients. select I2C_HID_CORE help Say Y here if you use a keyboard, a touchpad, a touchscreen, or any other HID based devices which is connected to your computer via I2C. - This driver supports Open Firmware (Device Tree)-based systems. + This driver supports Open Firmware (Device Tree)-based systems as + well as binding to manually (board-file) instantiated i2c-hid-clients. If unsure, say N. diff --git a/drivers/hid/i2c-hid/i2c-hid-of.c b/drivers/hid/i2c-hid/i2c-hid-of.c index c82a5a54c3e6..385f7460e03c 100644 --- a/drivers/hid/i2c-hid/i2c-hid-of.c +++ b/drivers/hid/i2c-hid/i2c-hid-of.c @@ -82,7 +82,7 @@ static int i2c_hid_of_probe(struct i2c_client *client) ihid_of->ops.power_up = i2c_hid_of_power_up; ihid_of->ops.power_down = i2c_hid_of_power_down; - ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val); + ret = device_property_read_u32(dev, "hid-descr-addr", &val); if (ret) { dev_err(dev, "HID register address not provided\n"); return -ENODEV; @@ -113,11 +113,13 @@ static int i2c_hid_of_probe(struct i2c_client *client) hid_descriptor_address, quirks); } +#ifdef CONFIG_OF static const struct of_device_id i2c_hid_of_match[] = { { .compatible = "hid-over-i2c" }, {}, }; MODULE_DEVICE_TABLE(of, i2c_hid_of_match); +#endif static const struct i2c_device_id i2c_hid_of_id_table[] = { { "hid", 0 }, From patchwork Thu Apr 13 09:36:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13210017 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75D4FC77B61 for ; Thu, 13 Apr 2023 09:37:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbjDMJhW (ORCPT ); Thu, 13 Apr 2023 05:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbjDMJhU (ORCPT ); Thu, 13 Apr 2023 05:37:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18D8E4C3C for ; Thu, 13 Apr 2023 02:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681378594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2470Jn1xT8SqVojwsdSC8po6r74iycG8WPpiDgzZJ2o=; b=cDut8nar4fBHEnjdmDQnG4Ca+6pjE4W+TrpPMjcE9exTl3hW6hqzM4E27wNVXT05/qNwkw lO21BjHTcp5iq2+vU1taW+QFEhXv4/8O6BcLNDIuaaUngcD3OJFt01ji/wSFGjEpfPJ2SE /YMejq26z33PEm5nfK2L+FYWA2e1G6Q= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-435-36X916g1PfOKGAkFyQ34tw-1; Thu, 13 Apr 2023 05:36:30 -0400 X-MC-Unique: 36X916g1PfOKGAkFyQ34tw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43AC18996E2; Thu, 13 Apr 2023 09:36:30 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.195.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80FCFC15E7F; Thu, 13 Apr 2023 09:36:29 +0000 (UTC) From: Hans de Goede To: Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , Douglas Anderson , linux-input@vger.kernel.org Subject: [PATCH v2 3/3] HID: i2c-hid-of: Add reset GPIO support to i2c-hid-of Date: Thu, 13 Apr 2023 11:36:25 +0200 Message-Id: <20230413093625.71146-4-hdegoede@redhat.com> In-Reply-To: <20230413093625.71146-1-hdegoede@redhat.com> References: <20230413093625.71146-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add reset GPIO support to the generic i2c-hid-of driver This is necessary to make the Wacom digitizer on the Lenovo Yoga Book 1 (yb1-x90f/l) work and this will also allow consolidating the 2 specialized i2c-hid-of-elan.c and i2c-hid-of-goodix.c drivers into the generic i2c-hid-of driver. For now the new "post-reset-deassert-delay-ms" property is only used on x86/ACPI (non devicetree) devs. IOW it is not used in actual devicetree files and the same goes for the reset GPIO. The devicetree-bindings maintainers have requested properties like these to not be added to the devicetree-bindings, so the new property + GPIO are deliberately not added to the existing devicetree-bindings. Signed-off-by: Hans de Goede --- Chanhes in v2: - Add a comment to the "post-reset-deassert-delay-ms" property reading, that it is a kernel internal (non public) property used between x86 platform code and the i2c-hid driver. --- drivers/hid/i2c-hid/i2c-hid-of.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/hid/i2c-hid/i2c-hid-of.c b/drivers/hid/i2c-hid/i2c-hid-of.c index 385f7460e03c..855f53092f4e 100644 --- a/drivers/hid/i2c-hid/i2c-hid-of.c +++ b/drivers/hid/i2c-hid/i2c-hid-of.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -35,8 +36,10 @@ struct i2c_hid_of { struct i2chid_ops ops; struct i2c_client *client; + struct gpio_desc *reset_gpio; struct regulator_bulk_data supplies[2]; int post_power_delay_ms; + int post_reset_delay_ms; }; static int i2c_hid_of_power_up(struct i2chid_ops *ops) @@ -55,6 +58,10 @@ static int i2c_hid_of_power_up(struct i2chid_ops *ops) if (ihid_of->post_power_delay_ms) msleep(ihid_of->post_power_delay_ms); + gpiod_set_value_cansleep(ihid_of->reset_gpio, 0); + if (ihid_of->post_reset_delay_ms) + msleep(ihid_of->post_reset_delay_ms); + return 0; } @@ -62,6 +69,7 @@ static void i2c_hid_of_power_down(struct i2chid_ops *ops) { struct i2c_hid_of *ihid_of = container_of(ops, struct i2c_hid_of, ops); + gpiod_set_value_cansleep(ihid_of->reset_gpio, 1); regulator_bulk_disable(ARRAY_SIZE(ihid_of->supplies), ihid_of->supplies); } @@ -96,6 +104,19 @@ static int i2c_hid_of_probe(struct i2c_client *client) if (!device_property_read_u32(dev, "post-power-on-delay-ms", &val)) ihid_of->post_power_delay_ms = val; + /* + * Note this is a kernel internal device-property set by x86 platform code, + * this MUST not be used in devicetree files without first adding it to + * the DT bindings. + */ + if (!device_property_read_u32(dev, "post-reset-deassert-delay-ms", &val)) + ihid_of->post_reset_delay_ms = val; + + /* Start out with reset asserted */ + ihid_of->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(ihid_of->reset_gpio)) + return PTR_ERR(ihid_of->reset_gpio); + ihid_of->supplies[0].supply = "vdd"; ihid_of->supplies[1].supply = "vddl"; ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ihid_of->supplies),