From patchwork Wed Sep 11 07:27:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13799809 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5B1F8EDE998 for ; Wed, 11 Sep 2024 07:31:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9XBl4KvAxY2W5qf9J8VaXaQIQeHry8eBV5yNyqGAqXM=; b=F40tojmFv+0Zq7FnCMmUcWTK35 mnXKZ/SI7zbk37hJ+Rrp2/JFDdHkQKf8bxw6yOImSLsyOCU/uDWwUN+00uX0KiSB/a2VlUpm33a7b hw13tOgBVZrRnYWKmMzkz+A4MBh4rwmAdaTwjNoCiaZCOykFN1vwTtieYd9etfWdtSHMlu6nlbdLt gZ9ZLZPhuuaEbw1pLkLliP0uKiZXOMcFprz20hl5EWUsWZVs1UX3OYMxC761v16LdVfUL9pQ3wrhK 0FG4Q2qLSAFA7ZpPbOfkkEHxiSrOrYSJ6nlW1VJSPU283c3bnGRM53v/iYLIart5qKQ++OJ7A9RFs wWTKeeCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHoe-00000008RYB-3UV5; Wed, 11 Sep 2024 07:31:04 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHm3-00000008Qih-0lsb for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:28:25 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-718816be6cbso4562097b3a.1 for ; Wed, 11 Sep 2024 00:28:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726039702; x=1726644502; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9XBl4KvAxY2W5qf9J8VaXaQIQeHry8eBV5yNyqGAqXM=; b=iVEQVYqOKMaDuQTrEHnP1tM3dkXmqYZAYsuiogNscTw0OKTJM68A9+PN2pkNLqRhzp D6hjSJAhizaTjo0khjPZxypYFzCN0A0Mdxsfo2DZVp+xe+HnpRY/u7YesfkTjPpFcD91 jkfqBmLQcPTC9J4LnsR2tS/NAfNBjWlOARQGs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726039702; x=1726644502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9XBl4KvAxY2W5qf9J8VaXaQIQeHry8eBV5yNyqGAqXM=; b=SCC1eEcS7t4AqVB5vuM9HDQdlpfq7BrRzvVYB8PlVv2k9ZCpO5acbiKiruszjVowVj WMW8TSzq5g0DCkT5GSi5SrO9u+hFDycvksJNwlS06u5OitYj8x43AuxS5aGAOcPuiEND zcGUgs09bJMOLZ8n8QRXVB+ci8qX0R2YfjbuKPcnIjVW475YiDqHwYAA67/y9FHo0m5L mQPmmyiGE2zViTT92imqueIs2pAViWJ6svGLp4GQbkhTbDzU5R9x4+FfrEMgQ2IGEMKQ FB931cj8FfdTgBwMj82OGZ3XGdzaISVnVo+by8u3Na1P1XRP8JTTJND6oGbkFVZR8F29 LF+Q== X-Forwarded-Encrypted: i=1; AJvYcCXu9Rrfcrq+MpIjG2svQ1g2RWD1veGioAaGPUKNezfp+IwfhlO8eHyrUrW/gA2XvbHrBMF+TluuYbbbQufEFOhv@lists.infradead.org X-Gm-Message-State: AOJu0Ywes9hdgCW6BQfa8J1iw/AdQUx/jRW76G6VyY+D1N5zPaZPr6yb xW05kaJ7UMNnJ2z9sW8zLGhYJ8ROuE66tl35t9Ti53pH9eC/8cmJiEdTFdkiwQ== X-Google-Smtp-Source: AGHT+IFjUTc14exhMNLPWpC6tKqxzxp/QnxrLH5ALh3HkEgdTdW2uDtj4xbh/J245j8YHjY14LvqFA== X-Received: by 2002:aa7:8887:0:b0:718:d96d:34d7 with SMTP id d2e1a72fcca58-718e3f9caacmr18512422b3a.3.1726039701972; Wed, 11 Sep 2024 00:28:21 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8398:fe34:eba2:f301]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm2399415b3a.80.2024.09.11.00.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:28:21 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v7 01/10] of: dynamic: Add of_changeset_update_prop_string Date: Wed, 11 Sep 2024 15:27:39 +0800 Message-ID: <20240911072751.365361-2-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240911072751.365361-1-wenst@chromium.org> References: <20240911072751.365361-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_002823_266078_84AC600F X-CRM114-Status: GOOD ( 17.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a helper function to add string property updates to an OF changeset. This is similar to of_changeset_add_prop_string(), but instead of adding the property (and failing if it exists), it will update the property. This shall be used later in the DT hardware prober. Signed-off-by: Chen-Yu Tsai Reviewed-by: Rob Herring (Arm) --- Changes since v6: None. Changes since v5: - Collected Rob's tag Changes since v4: - Use modern designated initializer for |prop| Changes since v3: - Use new __of_prop_free() helper - Add new line before header declaration Changes since v2: - New patch added in v3 --- drivers/of/dynamic.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 4 ++++ 2 files changed, 48 insertions(+) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 110104a936d9..daa69d160a78 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -1072,3 +1072,47 @@ int of_changeset_add_prop_bool(struct of_changeset *ocs, struct device_node *np, return of_changeset_add_prop_helper(ocs, np, &prop); } EXPORT_SYMBOL_GPL(of_changeset_add_prop_bool); + +static int of_changeset_update_prop_helper(struct of_changeset *ocs, + struct device_node *np, + const struct property *pp) +{ + struct property *new_pp; + int ret; + + new_pp = __of_prop_dup(pp, GFP_KERNEL); + if (!new_pp) + return -ENOMEM; + + ret = of_changeset_update_property(ocs, np, new_pp); + if (ret) + __of_prop_free(new_pp); + + return ret; +} + +/** + * of_changeset_update_prop_string - Add a string property update to a changeset + * + * @ocs: changeset pointer + * @np: device node pointer + * @prop_name: name of the property to be updated + * @str: pointer to null terminated string + * + * Create a string property to be updated and add it to a changeset. + * + * Return: 0 on success, a negative error value in case of an error. + */ +int of_changeset_update_prop_string(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, const char *str) +{ + struct property prop = { + .name = (char *)prop_name, + .length = strlen(str) + 1, + .value = (void *)str, + }; + + return of_changeset_update_prop_helper(ocs, np, &prop); +} +EXPORT_SYMBOL_GPL(of_changeset_update_prop_string); diff --git a/include/linux/of.h b/include/linux/of.h index 85b60ac9eec5..046283be1cd3 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1651,6 +1651,10 @@ static inline int of_changeset_add_prop_u32(struct of_changeset *ocs, return of_changeset_add_prop_u32_array(ocs, np, prop_name, &val, 1); } +int of_changeset_update_prop_string(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, const char *str); + int of_changeset_add_prop_bool(struct of_changeset *ocs, struct device_node *np, const char *prop_name); From patchwork Wed Sep 11 07:27:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13799819 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E3F8EE0211 for ; Wed, 11 Sep 2024 07:32:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VHYuF087WkDWw6t01rd+JoBLqqCohsT20qRvxciVpzs=; b=H/0rdayvIn80raiYngYSQTOMGz KFiZB6Nh4fYITG9CqAkTAZr6AeMfqzmAp93yeQ66ZFUxK67U0u2zowZaJVhrxIPinrrm5x8Ecm9Yf acve9K1lD/wH+6QvW2Q3AyiFhCdtggsE4+37ALfrjYkPuXZLZzCaelf4HcHWR/yctPHOJH18jApXq 1tFmigXWZyi3PF51otrvmgTu57/KZkFv/PbVGrPHdqQU6jB/E3qONws5dEjucZWObuem5V4LBiftS lGZAxz2b73lMGr7sPh/b4P31CBpw4uxm2f3sGlzC5Do8k0RTU9/BE/p5MFay7wc2rafwOE/zFIN2z US7mzdoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHpf-00000008Rnu-15WM; Wed, 11 Sep 2024 07:32:07 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHm6-00000008Qje-0FcR for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:28:27 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-717849c0dcaso5990715b3a.3 for ; Wed, 11 Sep 2024 00:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726039705; x=1726644505; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VHYuF087WkDWw6t01rd+JoBLqqCohsT20qRvxciVpzs=; b=QXpDww/L8ffSgM7dwDf/3sMG6AXZ6hiZjukATZcfbUZ/UhuNh1xSvK2geJoJyG9l04 EwARuQ2LdRcPXPygMHvndxMBMajjddWXa7O0ba1kRFlMZMv6Vy4Q54AL7CBM8youOsZU p6FaXGa2wczqMJkfyv01grsORdfXKgwcnESZ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726039705; x=1726644505; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VHYuF087WkDWw6t01rd+JoBLqqCohsT20qRvxciVpzs=; b=suUV6Uzh2cCU6jtHqWhsoiy5CFYkc3XRM5qTu58ZImXRfRX9Mvfo0cqKVqb9NRGueu 9OtjceJ+pog7spV6tm8CCynkkfsG9ql72MqXCba5dUQzR+eqhMnmI0HoN8yOaKGWSk/1 m/CPLRjA6uHY2RnBNksgSqP5GBOHBMBmgIGH+AVJbCLD2N2jPHZH7MahnW/XXlIsgDXD YfZMOoZMZrR6BQ0wqMG9RXs/mo72+zpZQkHaihTWhJJwOQm79FvYrS1nhtLXnGJWzS+J tU9NtSMUMPBosIVUtJYQD5+zJsytI8riQAOAc0xIC/ULmh97LHoE1szfY74JLoYzh6YQ yvPw== X-Forwarded-Encrypted: i=1; AJvYcCVLYJRHr4tF44O0XeUso6lS8HsQd+OrC9hL1yv7m+RgJTUbaNbTbG7ogFa20i5BtuvrIdibgzHlfjiQ5ZEVcxSL@lists.infradead.org X-Gm-Message-State: AOJu0Ywglzv1PxhdbZcTqpML/nTVVwTpqMPDXLp3nIDjakdvKc+hjU5v 3W8RgEHahccb8J4A1TDW1cow7xWXFyU5cZxlui4nM4Gy7PLfaBN6CADz9w4y3w== X-Google-Smtp-Source: AGHT+IF7NCaFQn5NI21IL8mvEhnYcnrMWrYJBC5MrY8umX2zBuXqZDWtQyZtz6v7uD5SvjxSxtithQ== X-Received: by 2002:a05:6a20:2d0b:b0:1cf:6dd7:fa50 with SMTP id adf61e73a8af0-1cf6dd7fa7cmr114263637.11.1726039705459; Wed, 11 Sep 2024 00:28:25 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8398:fe34:eba2:f301]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm2399415b3a.80.2024.09.11.00.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:28:25 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v7 02/10] of: base: Add for_each_child_of_node_with_prefix() Date: Wed, 11 Sep 2024 15:27:40 +0800 Message-ID: <20240911072751.365361-3-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240911072751.365361-1-wenst@chromium.org> References: <20240911072751.365361-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_002826_122452_12326743 X-CRM114-Status: GOOD ( 16.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There are cases where drivers would go through child device nodes and operate on only the ones whose node name starts with a given prefix. Provide a helper for these users. This will mainly be used in a subsequent patch that implements a hardware component prober for I2C busses. Signed-off-by: Chen-Yu Tsai Reviewed-by: Rob Herring (Arm) --- Changes since v6: - Changed helper name to "for_each_child_of_node_with_prefix()" Changes since v5: - New patch --- drivers/of/base.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/of.h | 9 +++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 20603d3c9931..d3c123b3261a 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -628,6 +628,41 @@ struct device_node *of_get_next_child(const struct device_node *node, } EXPORT_SYMBOL(of_get_next_child); +/** + * of_get_next_child_with_prefix - Find the next child node with prefix + * @node: parent node + * @prev: previous child of the parent node, or NULL to get first + * + * This function is like of_get_next_child(), except that it automatically + * skips any nodes whose name doesn't have the given prefix. + * + * Return: A node pointer with refcount incremented, use + * of_node_put() on it when done. + */ +struct device_node *of_get_next_child_with_prefix(const struct device_node *node, + struct device_node *prev, + const char *prefix) +{ + struct device_node *next; + unsigned long flags; + + if (!node) + return NULL; + + raw_spin_lock_irqsave(&devtree_lock, flags); + next = prev ? prev->sibling : node->child; + for (; next; next = next->sibling) { + if (!of_node_name_prefix(next, prefix)) + continue; + if (of_node_get(next)) + break; + } + of_node_put(prev); + raw_spin_unlock_irqrestore(&devtree_lock, flags); + return next; +} +EXPORT_SYMBOL(of_get_next_child_with_prefix); + static struct device_node *of_get_next_status_child(const struct device_node *node, struct device_node *prev, bool (*checker)(const struct device_node *)) diff --git a/include/linux/of.h b/include/linux/of.h index 046283be1cd3..48cfb39197d6 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -289,6 +289,9 @@ extern struct device_node *of_get_parent(const struct device_node *node); extern struct device_node *of_get_next_parent(struct device_node *node); extern struct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev); +extern struct device_node *of_get_next_child_with_prefix(const struct device_node *node, + struct device_node *prev, + const char *prefix); extern struct device_node *of_get_next_available_child( const struct device_node *node, struct device_node *prev); extern struct device_node *of_get_next_reserved_child( @@ -1468,6 +1471,12 @@ static inline int of_property_read_s32(const struct device_node *np, child != NULL; \ child = of_get_next_child(parent, child)) +#define for_each_child_of_node_with_prefix(parent, child, prefix) \ + for (struct device_node *child __free(device_node) = \ + of_get_next_child_with_prefix(parent, NULL, prefix); \ + child != NULL; \ + child = of_get_next_child_with_prefix(parent, child, prefix)) + #define for_each_available_child_of_node(parent, child) \ for (child = of_get_next_available_child(parent, NULL); child != NULL; \ child = of_get_next_available_child(parent, child)) From patchwork Wed Sep 11 07:27:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13799820 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0031BEDE998 for ; Wed, 11 Sep 2024 07:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Uo9H3mi08AzEIcyFPjnP71nK8rUWm/O6uNXtiPTxfPw=; b=z3jdvGlpd8AADPqOxxjy4vQGH+ W5e6lgQwAIEPjuYoFaFWuec/GgjR9gf955M7wTt2mcW1ILSFt53l/LRTY8Rmg5mo2h1a6xK5ZbJTM TyYFGohRgqVP85AZuKiH0MCNuS1YeCvx11LNZpCv8JMnFPtvyLg920ITAb1AJ8qkqfsj3tFq9ScGY 5lhWELvrV9AfOrsLxHq5Yr4ZvmdCAxVnAvImLRntcDkG60SDcvCChGvI7hNQQQI1WwgPJMvFCAq62 HYy6+qVSM1WeGGuk5ihAfajzxKBBZl3lcbxeJs0F2SJPbo9o1vbqZM3E4U/7OYcwFM4iPeialIdmY NW1ZOw+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHqh-00000008S5d-3uUB; Wed, 11 Sep 2024 07:33:12 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHmA-00000008QlD-0GWX for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:28:31 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-71798661a52so466123b3a.0 for ; Wed, 11 Sep 2024 00:28:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726039709; x=1726644509; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Uo9H3mi08AzEIcyFPjnP71nK8rUWm/O6uNXtiPTxfPw=; b=Y2ZvjfWd2VIRTb8u90v+CqZQEBfUPt0z6Hi+7F8dgDpFj4m/8G/1D11JUJ4L9iggof IzI3A0HQRe8eKdb1trpWH90QuLAsq+hsR/55UW09/4sWyl0FLi8YeMFKAgc04lQ5D2NG QkXRXcuE+F0x9RhIn1D2UTJYQJzz7ecW0zf0s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726039709; x=1726644509; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Uo9H3mi08AzEIcyFPjnP71nK8rUWm/O6uNXtiPTxfPw=; b=Qn/CUKBebnrTECooL1I+abJconzN4fYMxAidtF7tXDl26J+MreKxltKVn1+NsHd2iK 5yJca0PV9tyZrHoTabCqR7zRBQRxDVG398xRZj76yQFSvkcXwkLFFTSk1cJfb9B1FVCl jsYnp84RQEKzKuPHkiV4zS2b4K1RdM6iVpbq6o4bERD2SRN8l4tOdZhMvWS2z1bJHK92 Vn5ycWSYpz3Gh9O+Y+mk5O1W5aGqPpWUGIA9n0R1UvG0xIRRxQSq0yT+s9BCVFlzlNwl BhRleu4cz/DY1ebsWKX9TSJHZVajrcuuHeeLtrH3wqQzZlrLL05dhzGuWn0SgkYSublc PNsw== X-Forwarded-Encrypted: i=1; AJvYcCWYFBv50wVEq7tTfX+lDjsVc+sTuVHj3Ab9PZr+VzARIYHuac+n0dmqwkD4DzXs7VOeWkJSfWCbS1+ux1I0x8xP@lists.infradead.org X-Gm-Message-State: AOJu0YyCxIld5JXbZy/7AOHUsdkd9WN6wrnc8ORTMvwOqgVjiNszQkq4 2/SF09SXV9BhQ+wMwYoNQE3/o7H2jP4YImGfm7CH3qUBWQKGWYtQJcD3U83kmA== X-Google-Smtp-Source: AGHT+IH8y/5qgaRg14jmmESJlTP33GJD1mpI9XyvqpkYm264oWkGo2r0XR7RzXDvrRycmczgHdwVfQ== X-Received: by 2002:a05:6a00:6f0c:b0:70d:26cd:9741 with SMTP id d2e1a72fcca58-71907f29d40mr7749073b3a.12.1726039709427; Wed, 11 Sep 2024 00:28:29 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8398:fe34:eba2:f301]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm2399415b3a.80.2024.09.11.00.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:28:29 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v7 03/10] regulator: Split up _regulator_get() Date: Wed, 11 Sep 2024 15:27:41 +0800 Message-ID: <20240911072751.365361-4-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240911072751.365361-1-wenst@chromium.org> References: <20240911072751.365361-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_002830_129564_4A9B7811 X-CRM114-Status: GOOD ( 19.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org _regulator_get() contains a lot of common code doing checks prior to the regulator lookup and housekeeping work after the lookup. Almost all the code could be shared with a OF-specific variant of _regulator_get(). Split out the common parts so that they can be reused. The OF-specific version of _regulator_get() will be added in a subsequent patch. No functional changes were made. Signed-off-by: Chen-Yu Tsai Reviewed-by: Andy Shevchenko --- Changes since v6: None. Changes since v5: - Fixed kerneldoc "Return" section format for _regulator_get_common() - Slightly reworded return value description Changes since v4: - New patch --- drivers/regulator/core.c | 54 ++++++++++++++++++++++++++++-------- drivers/regulator/internal.h | 4 +++ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 835a5531d045..d60c86477ac2 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2103,26 +2103,43 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) return ret; } -/* Internal regulator request function */ -struct regulator *_regulator_get(struct device *dev, const char *id, - enum regulator_get_type get_type) +/* common pre-checks for regulator requests */ +int _regulator_get_common_check(struct device *dev, const char *id, + enum regulator_get_type get_type) { - struct regulator_dev *rdev; - struct regulator *regulator; - struct device_link *link; - int ret; - if (get_type >= MAX_GET_TYPE) { dev_err(dev, "invalid type %d in %s\n", get_type, __func__); - return ERR_PTR(-EINVAL); + return -EINVAL; } if (id == NULL) { dev_err(dev, "regulator request with no identifier\n"); - return ERR_PTR(-EINVAL); + return -EINVAL; } - rdev = regulator_dev_lookup(dev, id); + return 0; +} + +/** + * _regulator_get_common - Common code for regulator requests + * @rdev: regulator device pointer as returned by *regulator_dev_lookup() + * Its reference count is expected to have been incremented. + * @dev: device used for dev_printk messages + * @id: Supply name or regulator ID + * @get_type: enum regulator_get_type value corresponding to type of request + * + * Returns: pointer to struct regulator corresponding to @rdev, or ERR_PTR() + * encoded error. + * + * This function should be chained with *regulator_dev_lookup() functions. + */ +struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct device *dev, + const char *id, enum regulator_get_type get_type) +{ + struct regulator *regulator; + struct device_link *link; + int ret; + if (IS_ERR(rdev)) { ret = PTR_ERR(rdev); @@ -2238,6 +2255,21 @@ struct regulator *_regulator_get(struct device *dev, const char *id, return regulator; } +/* Internal regulator request function */ +struct regulator *_regulator_get(struct device *dev, const char *id, + enum regulator_get_type get_type) +{ + struct regulator_dev *rdev; + int ret; + + ret = _regulator_get_common_check(dev, id, get_type); + if (ret) + return ERR_PTR(ret); + + rdev = regulator_dev_lookup(dev, id); + return _regulator_get_common(rdev, dev, id, get_type); +} + /** * regulator_get - lookup and obtain a reference to a regulator. * @dev: device for regulator "consumer" diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h index 8e5506c5ee94..5b43f802468d 100644 --- a/drivers/regulator/internal.h +++ b/drivers/regulator/internal.h @@ -121,6 +121,10 @@ enum regulator_get_type { MAX_GET_TYPE }; +int _regulator_get_common_check(struct device *dev, const char *id, + enum regulator_get_type get_type); +struct regulator *_regulator_get_common(struct regulator_dev *rdev, struct device *dev, + const char *id, enum regulator_get_type get_type); struct regulator *_regulator_get(struct device *dev, const char *id, enum regulator_get_type get_type); int _regulator_bulk_get(struct device *dev, int num_consumers, From patchwork Wed Sep 11 07:27:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13799821 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 58551EDE998 for ; Wed, 11 Sep 2024 07:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=usCLS2gw9idy/3IwRZ6LuORHWtJja/i6x5Lk0clI0uw=; b=Dqwx9Crbckg/Pxc1Q1QMYpue98 Itx/Z+4mPIk+KHUyXB7Q7k1VNtZwMnA1qYQGbbvfg1cffbcWXA88j5WMGNTqs7qieEAtCb8S1XOTF TdLBW0hIMFv0nRT7zjq2+ZxDq6sE9D+UWs1gHuFIR8T/2klMTXrUHPHSd+qn8COn7XJKPsJL9F7wT qWOWSVDQlM/ccHzM2MCeQbV14/O1zmEZGvWqMyzA/U19kBbVljcB1ZrK4NE8OHzoeycFBnBm0Qto7 vSKUpzREkrtnQFhbcRhjzvN56+NV77OCAlWtJzdTHbcPZEEleDhMtOEl4jRwtZWcduLlOLTzMJmm1 DdhmAfLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHrj-00000008SFM-0fIz; Wed, 11 Sep 2024 07:34:15 +0000 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHmE-00000008QmO-1XRu for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:28:35 +0000 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5e1ba05bf73so2199458eaf.3 for ; Wed, 11 Sep 2024 00:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726039713; x=1726644513; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=usCLS2gw9idy/3IwRZ6LuORHWtJja/i6x5Lk0clI0uw=; b=DlGHd3ZOkysthJ0GgfTMqIZGr3CBNUoPFJpcmwxV3Bl0Jn21BqENOMwlamjuQFOvFg mcCEsVmqDQVc7y9oUz4ftA7OnPAihLUUWFJejpYetexvVQBrP/N4Jazxmfq8TNOm6UZU 4WFmr35i+GAu+f3al/Q1EAE/zXqYC9UuvUQZw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726039713; x=1726644513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=usCLS2gw9idy/3IwRZ6LuORHWtJja/i6x5Lk0clI0uw=; b=Rg9WUSfxxSHyybWVCDjEIFkh61TKFtjcA8xhvKj3nTqQmRFL8pT+x1gNQcg/pgUsQW KwHVNG4RFFROv4SlsebYM0bX5wIIXPpjs32VjFfQ8R0DnR51ZLMks6xWPYuptlVNGKmx sx4AlZ5KpHJOTg9c3CKW9ZdJaWC6EBHrzgpt7HisvIjk7sf+BBmJ2YKHigP6e3fiz+59 ZWBRqThzTjx+egmgvH4Fy+Aibx+04KsO/+Hzse2KQKv9+0NGjHhNanze86bA+kYFai9l geUnW6wjLXOByS4kcMpim/tGwOG3a865fTReR7L46uKFav/GVNcahntcWNW6O6WRBKPY 63iQ== X-Forwarded-Encrypted: i=1; AJvYcCXObB65PuNs9Brus6lEpZZCgmPI3hPP/3fpFNZJGFAeSqyFHdZOFgqrBN+oQNKL5a1aJmY61xPjLEIGhWR7Gt6+@lists.infradead.org X-Gm-Message-State: AOJu0YwXZw3gE74EKxXQF0bkYK8dlCgw6YhwNOVmaaI5T1G7WOeZZRrm QHP6X4YPywUQDWHHILRWayBdlkMhxADnrPRv/d2GZowIa/UEMvnbHQIEj/ei5A== X-Google-Smtp-Source: AGHT+IFNM7b4JkSSxOxl6LIFw91t1hLIJvdgyEh6OE43L+BvV2ny7clTTpH+bkJj2RTSowhSQE6gdw== X-Received: by 2002:a05:6870:1702:b0:24f:dd11:4486 with SMTP id 586e51a60fabf-27b9dd8110fmr8247849fac.36.1726039712931; Wed, 11 Sep 2024 00:28:32 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8398:fe34:eba2:f301]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm2399415b3a.80.2024.09.11.00.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:28:32 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v7 04/10] regulator: Add of_regulator_get_optional() for pure DT regulator lookup Date: Wed, 11 Sep 2024 15:27:42 +0800 Message-ID: <20240911072751.365361-5-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240911072751.365361-1-wenst@chromium.org> References: <20240911072751.365361-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_002834_421258_E725C72F X-CRM114-Status: GOOD ( 28.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The to-be-introduced I2C component prober needs to enable regulator supplies (and toggle GPIO pins) for the various components it intends to probe. To support this, a new "pure DT lookup" method for getting regulator supplies is needed, since the device normally requesting the supply won't get created until after the component is probed to be available. Add a new of_regulator_get_optional() function for this. This mirrors the existing regulator_get_optional() function, but is OF-specific. The underlying code that supports the existing regulator_get*() functions has been reworked in previous patches to support this specific case. Also convert an existing usage of "dev && dev->of_node" to "dev_of_node(dev)". Link: https://lore.kernel.org/all/20231220203537.83479-2-jernej.skrabec@gmail.com/ [1] Signed-off-by: Chen-Yu Tsai --- Changes since v6: - Changed reference [1] to Link: tag - Rebased on top of commit 401d078eaf2e ("regulator: of: Refactor of_get_*regulator() to decrease indentation") - Exported of_regulator_get_optional() - Changed commit message to focus on "of_regulator_get_optional()" - Dropped change to of_regulator_bulk_get_all() Changes since v5: - Used "dev_of_node(dev)" instead of "dev->of_node" - Replaced "dev_printk" with "dev_printk()" in kerneldoc mentions - Fixed kerneldoc "Return" section format for of_regulator_get_optional() - Fix @np parameter name in of_regulator_dev_lookup() kerneldoc Changes since v4: - Restore platform-agnostic regulator consumer code to original state - Move OF-specific regulator code to of_regulator.c (separate patch) - Split _regulator_get() into three parts for reuse (separate patch) - Add OF-specific _of_regulator_get() function - Rename regulator_of_get_optional() to of_regulator_get_optional() for consistency - Make of_regulator_get_optional static, as it is only used internally - Convert of_regulator_bulk_get_all() Changes since v3: - New patch --- drivers/regulator/core.c | 4 +-- drivers/regulator/internal.h | 2 ++ drivers/regulator/of_regulator.c | 51 ++++++++++++++++++++++++++---- include/linux/regulator/consumer.h | 4 +++ 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index d60c86477ac2..f94a06ac2109 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1959,8 +1959,8 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev, regulator_supply_alias(&dev, &supply); /* first do a dt based lookup */ - if (dev && dev->of_node) { - r = of_regulator_dev_lookup(dev, supply); + if (dev_of_node(dev)) { + r = of_regulator_dev_lookup(dev, dev_of_node(dev), supply); if (!IS_ERR(r)) return r; if (PTR_ERR(r) == -EPROBE_DEFER) diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h index 5b43f802468d..f62cacbbc729 100644 --- a/drivers/regulator/internal.h +++ b/drivers/regulator/internal.h @@ -67,6 +67,7 @@ static inline struct regulator_dev *dev_to_rdev(struct device *dev) #ifdef CONFIG_OF struct regulator_dev *of_regulator_dev_lookup(struct device *dev, + struct device_node *np, const char *supply); struct regulator_init_data *regulator_of_get_init_data(struct device *dev, const struct regulator_desc *desc, @@ -82,6 +83,7 @@ bool of_check_coupling_data(struct regulator_dev *rdev); #else static inline struct regulator_dev *of_regulator_dev_lookup(struct device *dev, + struct device_node *np, const char *supply) { return ERR_PTR(-ENODEV); diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 3f490d81abc2..358c3ed791db 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -588,7 +588,8 @@ static struct device_node *of_get_child_regulator(struct device_node *parent, /** * of_get_regulator - get a regulator device node based on supply name - * @dev: Device pointer for the consumer (of regulator) device + * @dev: Device pointer for dev_printk() messages + * @node: Device node pointer for supply property lookup * @supply: regulator supply name * * Extract the regulator device node corresponding to the supply name. @@ -596,15 +597,16 @@ static struct device_node *of_get_child_regulator(struct device_node *parent, * Return: Pointer to the &struct device_node corresponding to the regulator * if found, or %NULL if not found. */ -static struct device_node *of_get_regulator(struct device *dev, const char *supply) +static struct device_node *of_get_regulator(struct device *dev, struct device_node *node, + const char *supply) { struct device_node *regnode = NULL; char prop_name[64]; /* 64 is max size of property name */ - dev_dbg(dev, "Looking up %s-supply from device tree\n", supply); + dev_dbg(dev, "Looking up %s-supply from device node %pOF\n", supply, node); snprintf(prop_name, 64, "%s-supply", supply); - regnode = of_parse_phandle(dev->of_node, prop_name, 0); + regnode = of_parse_phandle(node, prop_name, 0); if (regnode) return regnode; @@ -628,6 +630,7 @@ static struct regulator_dev *of_find_regulator_by_node(struct device_node *np) /** * of_regulator_dev_lookup - lookup a regulator device with device tree only * @dev: Device pointer for regulator supply lookup. + * @np: Device node pointer for regulator supply lookup. * @supply: Supply name or regulator ID. * * Return: Pointer to the &struct regulator_dev on success, or ERR_PTR() @@ -642,13 +645,13 @@ static struct regulator_dev *of_find_regulator_by_node(struct device_node *np) * * -%ENODEV if lookup fails permanently. * * -%EPROBE_DEFER if lookup could succeed in the future. */ -struct regulator_dev *of_regulator_dev_lookup(struct device *dev, +struct regulator_dev *of_regulator_dev_lookup(struct device *dev, struct device_node *np, const char *supply) { struct regulator_dev *r; struct device_node *node; - node = of_get_regulator(dev, supply); + node = of_get_regulator(dev, np, supply); if (node) { r = of_find_regulator_by_node(node); of_node_put(node); @@ -665,6 +668,42 @@ struct regulator_dev *of_regulator_dev_lookup(struct device *dev, return ERR_PTR(-ENODEV); } +static struct regulator *_of_regulator_get(struct device *dev, struct device_node *node, + const char *id, enum regulator_get_type get_type) +{ + struct regulator_dev *r; + int ret; + + ret = _regulator_get_common_check(dev, id, get_type); + if (ret) + return ERR_PTR(ret); + + r = of_regulator_dev_lookup(dev, node, id); + return _regulator_get_common(r, dev, id, get_type); +} + +/** + * of_regulator_get_optional - get optional regulator via device tree lookup + * @dev: device used for dev_printk() messages + * @node: device node for regulator "consumer" + * @id: Supply name + * + * Return: pointer to struct regulator corresponding to the regulator producer, + * or PTR_ERR() encoded error number. + * + * This is intended for use by consumers that want to get a regulator + * supply directly from a device node, and can and want to deal with + * absence of such supplies. This will _not_ consider supply aliases. + * See regulator_dev_lookup(). + */ +struct regulator *of_regulator_get_optional(struct device *dev, + struct device_node *node, + const char *id) +{ + return _of_regulator_get(dev, node, id, OPTIONAL_GET); +} +EXPORT_SYMBOL_GPL(of_regulator_get_optional); + /* * Returns number of regulators coupled with rdev. */ diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index b9ce521910a0..d7325e27a1ce 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -168,6 +168,10 @@ int devm_regulator_get_enable_read_voltage(struct device *dev, const char *id); void regulator_put(struct regulator *regulator); void devm_regulator_put(struct regulator *regulator); +struct regulator *__must_check of_regulator_get_optional(struct device *dev, + struct device_node *node, + const char *id); + int regulator_register_supply_alias(struct device *dev, const char *id, struct device *alias_dev, const char *alias_id); From patchwork Wed Sep 11 07:27:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13799822 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75A71EE0211 for ; Wed, 11 Sep 2024 07:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TZj+Rwt2K/givoXdUXg/sARHG7LMQ+JDTIquBzN2oCY=; b=00U8lmtg8qXS0Skbu4p7PNqH97 wGsN9Fj0zzZQ6IFr8waARBGz2+WVF7WZfvOShJWvZca5iNJnNf6XPz3GC/CLjDZgpyRL5/z6z5kxs nDMzt71mT57zznslf/Qrfr1AGgBpZX7Px0vfRgiPjpm2oU4MTqlDQ+WdnYxZY3SlEqbn4bjsC35jN mqlsSnLP7hjwz6vOa9Sycz8tncsP3VrRENMphHNNNdokKhzcdBE1WjlPzLnpFBBUW2W21wzid3PRO wxUN3HxIlvHpe4qnPk+8ETokzrFZn/Iz1AAOTrXzNzfWOvs1oH+jQNdd1yJo88NanZZDGzzc8rAIr ufybbmFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHsi-00000008SRt-2vnU; Wed, 11 Sep 2024 07:35:17 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHmH-00000008QoI-0FnP for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:28:39 +0000 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-656d8b346d2so4118509a12.2 for ; Wed, 11 Sep 2024 00:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726039716; x=1726644516; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TZj+Rwt2K/givoXdUXg/sARHG7LMQ+JDTIquBzN2oCY=; b=LQsF5FW4egImV8Z9QLfA0yXFoILANe7YbhO9HV5X8bV7QJvgIgj0z3KPV1QHxSo+V2 s8q1+7+CKg2C1LUa1zBSj7Yta+2R4E1hHkbL/6Xc6Vn29xhu7R+xza9B4XFoGkJh5t0U I71r+riucLT/5g29hX3agrEdhpNtw3woAFx0A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726039716; x=1726644516; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TZj+Rwt2K/givoXdUXg/sARHG7LMQ+JDTIquBzN2oCY=; b=YrG4rpo3n74YUcS3w2jnNAe825ZYS9a/C4k98I5ITWXp+EjXZwIilnFuxSGHCuVRbb F8J+tX7eVobwW8V50O2OV6NU5vUrdfG8Gn8OeQ15VsUm4v90tLLSq8cIbb0Xdmmd/LPB CMmm3jLqutLfZBSqV4iJdnYZ2N1eR4R8Ue7JDoyypQkTV82fDgliwWHSVThdRMy7eUdx AdBWyohYZ2teMwpLZmV/gNIjIYFgXrqorPZ9S5V8xFYk8el3cfEJIka3xw/pW34WM8xQ zVOzyY4J5vQRhVsQo8OdFku8iHwePfxk0o+7EOHH531kSBTwRt8CQ0mVMRKaWvFeuaM8 SK6g== X-Forwarded-Encrypted: i=1; AJvYcCVEwczo9FK8RISgRUzTLLPRnjRNsx9I6oBI9ZijBIZMGJN47G7g6+pmU6DH0yliWCQUMCLhXr3QACfPvfz+FbSB@lists.infradead.org X-Gm-Message-State: AOJu0Yw2m3EPiZ9egRDygu8pF/mp4iL8nq9hPfWn7rBUfRO23BHvixHE znkXr+mEMclGhHclbGkXOScmUk8ZgxXG0Svu5kGjkaVTdEjIIMAJH2virWqxFw== X-Google-Smtp-Source: AGHT+IHedUO15STr+MI+20JywnkGwOWN1412qS2q6DZSwhZSeZ7SKRwPtcyUrKy5SFYgpsHfqp5wRg== X-Received: by 2002:a05:6a20:cd0e:b0:1c0:eba5:e192 with SMTP id adf61e73a8af0-1cf5e0f52bcmr4279897637.27.1726039716399; Wed, 11 Sep 2024 00:28:36 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8398:fe34:eba2:f301]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm2399415b3a.80.2024.09.11.00.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:28:36 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v7 05/10] i2c: core: Remove extra space in Makefile Date: Wed, 11 Sep 2024 15:27:43 +0800 Message-ID: <20240911072751.365361-6-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240911072751.365361-1-wenst@chromium.org> References: <20240911072751.365361-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_002837_226311_EB8424C6 X-CRM114-Status: GOOD ( 12.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some lines in the Makefile have a space before tabs. Remove those. Reported-by: Andy Shevchenko Closes: https://lore.kernel.org/all/ZsdE0PxKnGRjzChl@smile.fi.intel.com/ Signed-off-by: Chen-Yu Tsai Reviewed-by: Andy Shevchenko Reviewed-by: Andi Shyti --- Changes since v6: - Collected Andy's Reviewed-by Changes since v5: - new patch --- drivers/i2c/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index 3f71ce4711e3..f12d6b10a85e 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -5,10 +5,10 @@ obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o obj-$(CONFIG_I2C) += i2c-core.o -i2c-core-objs := i2c-core-base.o i2c-core-smbus.o +i2c-core-objs := i2c-core-base.o i2c-core-smbus.o i2c-core-$(CONFIG_ACPI) += i2c-core-acpi.o -i2c-core-$(CONFIG_I2C_SLAVE) += i2c-core-slave.o -i2c-core-$(CONFIG_OF) += i2c-core-of.o +i2c-core-$(CONFIG_I2C_SLAVE) += i2c-core-slave.o +i2c-core-$(CONFIG_OF) += i2c-core-of.o obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o From patchwork Wed Sep 11 07:27:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13799827 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4D6A5EDE998 for ; Wed, 11 Sep 2024 07:36:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YuuJ4IMp8f8RUPgIJJofk3lgpK2gw9f2hR5QsihKIF0=; b=yyeUAWhUi+nOQBPOrcIujt9Wtf 9Qb7tYv3Pl//EipL55z8p+5ttjyg8v8q79NAt1afwhHViftVZzxyTtT6VoBH7ogpUDk1HFZGaUjXw +qnK6dXwfc6o8/f/h6g6uo3n4Wk9/jgKV5oUk81rMzQtY6L22zZP/IgbVz6e3WlpNpTc1gbCp+Yj0 2e6FSkn3hz+M/HOFRqLOkwijRDzS1slztJsQn6EU6zXQXwU7n82d9D9a1kULqSGYBjNgvsH/Kj4+O gWAehI+d/MbJza4ysG7RUEKigRhEMYehvdq86/GD2ajKXZVKz3UGEyhKfP9qmgk65OurRJoT7NXSZ rLGnhbTw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHtl-00000008ShQ-1gsC; Wed, 11 Sep 2024 07:36:21 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHmL-00000008QqB-0eqC for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:28:43 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-718816be6cbso4562314b3a.1 for ; Wed, 11 Sep 2024 00:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726039720; x=1726644520; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YuuJ4IMp8f8RUPgIJJofk3lgpK2gw9f2hR5QsihKIF0=; b=m1eI1yo/8z5a39kwjZjGIE9BO1r874hVRbIABVmmliWsOlTysFxchOc0nGVvUu/qzd RiuFQQFZMsKRs5/df0nGnbMzokksS+IW0jAJQPPRTV30eU2cixXOUVo8IaP/WDibAOar 9U2h9rY7EkZutFvFv0wDWSKNiWgkjmmSKFtV0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726039720; x=1726644520; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YuuJ4IMp8f8RUPgIJJofk3lgpK2gw9f2hR5QsihKIF0=; b=Nh+V5bVaw7AdZLrAVWmxBY5xpmYFG6gWNs8letmQR7+7G0pmY3fVdcNOK0O/07Xxdl b591f77LYTKCHN3/PjzC1F32WWH2eBXY1yUy2oMgMgQioEd250wWchygjeGSHkjtumzy Ak2yLOM0vCnRb4CIvi6CXYTWS0afp+opSGzONSBxYALeKxiINAeH8y9vzOBaawzWODvs aPxQ8S75n4zwq6XihGSgfBSGhicSKbLsL/Pvjyo4gTkNrUx/hKJyKHx/MRdhUSEaTQBK TkgQDA20CcBdsJ7zMd7U9p/fgrxa2ClnQixQxNUvQ+pUWxT0jeSn+X7yjPj5gTuM1srR oe1A== X-Forwarded-Encrypted: i=1; AJvYcCUZ34yxFZSwAYWxV2hXeYPpj3gn5i4PV8hsNajOHSccmiTHOytPkrqWCNuowMGavDoI03YYBFQkR49ayocW1OrI@lists.infradead.org X-Gm-Message-State: AOJu0YznprpCz+GCui7mC7KSqrEFuSzhfq1fwsUqwVoyiTKxLQwp0Ony mSPiWidyIdIPYBIZBu+Be4aIrqrPqPJ0CZZ19TsVJkdmIjc95UeLOt0XuR7lcA== X-Google-Smtp-Source: AGHT+IGnls1/wySnShGxcSfF4z8WnLnKNAl5aI9lwWWNHkRT83lWy5txFhO7utXp/CZOwDQ3OoJEgw== X-Received: by 2002:a05:6a00:1a87:b0:717:945e:effd with SMTP id d2e1a72fcca58-718e3f9dd53mr18901401b3a.1.1726039719906; Wed, 11 Sep 2024 00:28:39 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8398:fe34:eba2:f301]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm2399415b3a.80.2024.09.11.00.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:28:39 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v7 06/10] i2c: Introduce OF component probe function Date: Wed, 11 Sep 2024 15:27:44 +0800 Message-ID: <20240911072751.365361-7-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240911072751.365361-1-wenst@chromium.org> References: <20240911072751.365361-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_002841_216136_C2B0988E X-CRM114-Status: GOOD ( 44.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some devices are designed and manufactured with some components having multiple drop-in replacement options. These components are often connected to the mainboard via ribbon cables, having the same signals and pin assignments across all options. These may include the display panel and touchscreen on laptops and tablets, and the trackpad on laptops. Sometimes which component option is used in a particular device can be detected by some firmware provided identifier, other times that information is not available, and the kernel has to try to probe each device. This change attempts to make the "probe each device" case cleaner. The current approach is to have all options added and enabled in the device tree. The kernel would then bind each device and run each driver's probe function. This works, but has been broken before due to the introduction of asynchronous probing, causing multiple instances requesting "shared" resources, such as pinmuxes, GPIO pins, interrupt lines, at the same time, with only one instance succeeding. Work arounds for these include moving the pinmux to the parent I2C controller, using GPIO hogs or pinmux settings to keep the GPIO pins in some fixed configuration, and requesting the interrupt line very late. Such configurations can be seen on the MT8183 Krane Chromebook tablets, and the Qualcomm sc8280xp-based Lenovo Thinkpad 13S. Instead of this delicate dance between drivers and device tree quirks, this change introduces a simple I2C component probe. function For a given class of devices on the same I2C bus, it will go through all of them, doing a simple I2C read transfer and see which one of them responds. It will then enable the device that responds. This requires some minor modifications in the existing device tree. The status for all the device nodes for the component options must be set to "failed-needs-probe". This makes it clear that some mechanism is needed to enable one of them, and also prevents the prober and device drivers running at the same time. Signed-off-by: Chen-Yu Tsai --- Changes since v6: - Correctly replaced for_each_child_of_node_scoped() with for_each_child_of_node_with_prefix() - Added namespace for exported symbol - Made the probe function a framework with hooks - Split out a new header file - Added MAINTAINERS entry - Reworded kernel-doc - Dropped usage of __free from i2c_of_probe_component() since error path cleanup is needed anyway Changes since v5: - Fixed indent in Makefile - Split regulator and GPIO TODO items - Reversed final conditional in i2c_of_probe_enable_node() Changes since v4: - Split code into helper functions - Use scoped helpers and __free() to reduce error path Changes since v3: - Complete kernel-doc - Return different error if I2C controller is disabled - Expand comment to explain assumptions and constraints - Split for-loop finding target node and operations on target node - Add missing i2c_put_adapter() - Move prober code to separate file Rob also asked why there was a limitation of "exactly one touchscreen will be enabled across the whole tree". The use case this prober currently targets is a component on consumer electronics (tablet or laptop) being swapped out due to cost or supply reasons. Designs with multiple components of the same type are pretty rare. The way the next patch is written also assumes this for efficiency reasons. Changes since v2: - New patch split out from "of: Introduce hardware prober driver" - Addressed Rob's comments - Move i2c prober to i2c subsystem - Use of_node_is_available() to check if node is enabled. - Use OF changeset API to update status property - Addressed Andy's comments - Probe function now accepts "struct device *dev" instead to reduce line length and dereferences - Move "ret = 0" to just before for_each_child_of_node(i2c_node, node) --- MAINTAINERS | 8 ++ drivers/i2c/Makefile | 1 + drivers/i2c/i2c-core-of-prober.c | 195 +++++++++++++++++++++++++++++++ include/linux/i2c-of-prober.h | 73 ++++++++++++ 4 files changed, 277 insertions(+) create mode 100644 drivers/i2c/i2c-core-of-prober.c create mode 100644 include/linux/i2c-of-prober.h diff --git a/MAINTAINERS b/MAINTAINERS index 927f81c12543..d88646380786 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10645,6 +10645,14 @@ S: Maintained F: Documentation/devicetree/bindings/i2c/marvell,mv64xxx-i2c.yaml F: drivers/i2c/busses/i2c-mv64xxx.c +I2C OF COMPONENT PROBER +M: Chen-Yu Tsai +L: linux-i2c@vger.kernel.org +L: devicetree@vger.kernel.org +S: Maintained +F: drivers/i2c/i2c-core-of-prober.c +F: include/linux-i2c-of-prober.h + I2C OVER PARALLEL PORT M: Jean Delvare L: linux-i2c@vger.kernel.org diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index f12d6b10a85e..c539cdc1e305 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -9,6 +9,7 @@ i2c-core-objs := i2c-core-base.o i2c-core-smbus.o i2c-core-$(CONFIG_ACPI) += i2c-core-acpi.o i2c-core-$(CONFIG_I2C_SLAVE) += i2c-core-slave.o i2c-core-$(CONFIG_OF) += i2c-core-of.o +i2c-core-$(CONFIG_OF_DYNAMIC) += i2c-core-of-prober.o obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o diff --git a/drivers/i2c/i2c-core-of-prober.c b/drivers/i2c/i2c-core-of-prober.c new file mode 100644 index 000000000000..62ff2f4b6177 --- /dev/null +++ b/drivers/i2c/i2c-core-of-prober.c @@ -0,0 +1,195 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Linux I2C core OF component prober code + * + * Copyright (C) 2024 Google LLC + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Some devices, such as Google Hana Chromebooks, are produced by multiple + * vendors each using their preferred components. Such components are all + * in the device tree. Instead of having all of them enabled and having each + * driver separately try and probe its device while fighting over shared + * resources, they can be marked as "fail-needs-probe" and have a prober + * figure out which one is actually used beforehand. + * + * This prober assumes such drop-in parts are on the same I2C bus, have + * non-conflicting addresses, and can be directly probed by seeing which + * address responds. + * + * TODO: + * - Support handling common regulators. + * - Support handling common GPIOs. + * - Support I2C muxes + */ + +static struct device_node *i2c_of_probe_get_i2c_node(struct device *dev, const char *type) +{ + struct device_node *node __free(device_node) = of_find_node_by_name(NULL, type); + if (!node) + return dev_err_ptr_probe(dev, -ENODEV, "Could not find %s device node\n", type); + + struct device_node *i2c_node __free(device_node) = of_get_parent(node); + if (!of_node_name_eq(i2c_node, "i2c")) + return dev_err_ptr_probe(dev, -EINVAL, "%s device isn't on I2C bus\n", type); + + if (!of_device_is_available(i2c_node)) + return dev_err_ptr_probe(dev, -ENODEV, "I2C controller not available\n"); + + return no_free_ptr(i2c_node); +} + +static int i2c_of_probe_enable_node(struct device *dev, struct device_node *node) +{ + int ret; + + dev_info(dev, "Enabling %pOF\n", node); + + struct of_changeset *ocs __free(kfree) = kzalloc(sizeof(*ocs), GFP_KERNEL); + if (!ocs) + return -ENOMEM; + + of_changeset_init(ocs); + ret = of_changeset_update_prop_string(ocs, node, "status", "okay"); + if (ret) + return ret; + + ret = of_changeset_apply(ocs); + if (ret) { + /* ocs needs to be explicitly cleaned up before being freed. */ + of_changeset_destroy(ocs); + } else { + /* + * ocs is intentionally kept around as it needs to + * exist as long as the change is applied. + */ + void *ptr __always_unused = no_free_ptr(ocs); + } + + return ret; +} + +static const struct i2c_of_probe_ops i2c_of_probe_dummy_ops; + +/** + * i2c_of_probe_component() - probe for devices of "type" on the same i2c bus + * @dev: Pointer to the &struct device of the caller, only used for dev_printk() messages. + * @cfg: Pointer to the &struct i2c_of_probe_cfg containing callbacks and other options + * for the prober. + * @ctx: Context data for callbacks. + * + * Probe for possible I2C components of the same "type" (&i2c_of_probe_cfg->type) + * on the same I2C bus that have their status marked as "fail". + * + * Assumes that across the entire device tree the only instances of nodes + * prefixed with "type" are the ones that need handling for second source + * components. In other words, if "type" is "touchscreen", then all device + * nodes named "touchscreen*" are the ones that need probing. There cannot + * be another "touchscreen" node that is already enabled. + * + * Assumes that for each "type" of component, only one actually exists. In + * other words, only one matching and existing device will be enabled. + * + * Context: Process context only. Does non-atomic I2C transfers. + * Should only be used from a driver probe function, as the function + * can return -EPROBE_DEFER if the I2C adapter or other resources + * are unavailable. + * Return: 0 on success or no-op, error code otherwise. + * A no-op can happen when it seems like the device tree already + * has components of the type to be probed already enabled. This + * can happen when the device tree had not been updated to mark + * the status of the to-be-probed components as "fail". Or this + * function was already run with the same parameters and succeeded + * in enabling a component. The latter could happen if the user + * had multiple types of components to probe, and one of them down + * the list caused a deferred probe. This is expected behavior. + */ +int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_cfg *cfg, void *ctx) +{ + const struct i2c_of_probe_ops *ops; + const char *type; + struct device_node *i2c_node; + struct i2c_adapter *i2c; + int ret; + + if (!cfg) + return -EINVAL; + + ops = cfg->ops ?: &i2c_of_probe_dummy_ops; + type = cfg->type; + + i2c_node = i2c_of_probe_get_i2c_node(dev, type); + if (IS_ERR(i2c_node)) + return PTR_ERR(i2c_node); + + for_each_child_of_node_with_prefix(i2c_node, node, type) { + if (!of_device_is_available(node)) + continue; + + /* + * Device tree has component already enabled. Either the + * device tree isn't supported or we already probed once. + */ + ret = 0; + goto out_put_i2c_node; + } + + i2c = of_get_i2c_adapter_by_node(i2c_node); + if (!i2c) { + ret = dev_err_probe(dev, -EPROBE_DEFER, "Couldn't get I2C adapter\n"); + goto out_put_i2c_node; + } + + /* Grab resources */ + ret = 0; + if (ops->get_resources) + ret = ops->get_resources(dev, i2c_node, ctx); + if (ret) + goto out_put_i2c_adapter; + + /* Enable resources */ + if (ops->enable) + ret = ops->enable(dev, ctx); + if (ret) + goto out_release_resources; + + ret = 0; + for_each_child_of_node_with_prefix(i2c_node, node, type) { + union i2c_smbus_data data; + u32 addr; + + if (of_property_read_u32(node, "reg", &addr)) + continue; + if (i2c_smbus_xfer(i2c, addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data) < 0) + continue; + + /* Found a device that is responding */ + if (ops->free_resources_early) + ops->free_resources_early(ctx); + ret = i2c_of_probe_enable_node(dev, node); + break; + } + + if (ops->cleanup) + ops->cleanup(dev, ctx); +out_release_resources: + if (ops->free_resources_late) + ops->free_resources_late(ctx); +out_put_i2c_adapter: + i2c_put_adapter(i2c); +out_put_i2c_node: + of_node_put(i2c_node); + + return ret; +} +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_component, I2C_OF_PROBER); diff --git a/include/linux/i2c-of-prober.h b/include/linux/i2c-of-prober.h new file mode 100644 index 000000000000..0f94e7c94310 --- /dev/null +++ b/include/linux/i2c-of-prober.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * i2c-of-prober.h - definitions for the Linux I2C OF component prober + * + * Copyright (C) 2024 Google LLC + */ + +#ifndef _LINUX_I2C_OF_PROBER_H +#define _LINUX_I2C_OF_PROBER_H + +#if IS_ENABLED(CONFIG_OF_DYNAMIC) + +struct device; +struct device_node; + +/** + * struct i2c_of_probe_ops - I2C OF component prober callbacks + * + * A set of callbacks to be used by i2c_of_probe_component(). + * + * All callbacks are optional. Callbacks are called only once per run, and are + * used in the order they are defined in this structure. + * + * All callbacks that have return values shall return %0 on success, + * or a negative error number on failure. + * + * The @dev parameter passed to the callbacks is the same as @dev passed to + * i2c_of_probe_component(). It should only be used for dev_printk() calls + * and nothing else, especially not managed device resource (devres) APIs. + */ +struct i2c_of_probe_ops { + /** @get_resources: Retrieve resources for components. */ + int (*get_resources)(struct device *dev, struct device_node *bus_node, void *data); + + /** @free_resources_early: Release exclusive resources prior to enabling component. */ + void (*free_resources_early)(void *data); + + /** + * @enable: Enable resources so that the components respond to probes. + * + * Resources should be reverted to their initial state before returning if this fails. + */ + int (*enable)(struct device *dev, void *data); + + /** + * @cleanup: Opposite of @enable to balance refcounts after probing. + * + * Can not operate on resources already freed in @free_resources_early. + */ + int (*cleanup)(struct device *dev, void *data); + + /** + * @free_resources_late: Release all resources, including those that would have + * been released by @free_resources_early. + */ + void (*free_resources_late)(void *data); +}; + +/** + * struct i2c_of_probe_cfg - I2C OF component prober configuration + * @ops: Callbacks for the prober to use. + * @type: A string to match the device node name prefix to probe for. + */ +struct i2c_of_probe_cfg { + const struct i2c_of_probe_ops *ops; + const char *type; +}; + +int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_cfg *cfg, void *ctx); + +#endif /* IS_ENABLED(CONFIG_OF_DYNAMIC) */ + +#endif /* _LINUX_I2C_OF_PROBER_H */ From patchwork Wed Sep 11 07:27:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13799828 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F184AEDE998 for ; Wed, 11 Sep 2024 07:37:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fVhbTxLURsXagkjV6T5t8snpx3JbKq5qtkesVJ+9OU0=; b=fIwoWwhINsxFJ3s/9uDPELY83K U77Q9UkpN2bw7gPN5dDpviZEsg42nTqQebs5hSkUSaBXhuTTCz3towaq5MJPxniAHG3SU9MAY1qEF wb0cJwUqocWvaPU99ewphEqx7kZ0a6CdhuqWbFkMmlD+5bESW6KVSfjX1d2KkQiWRL1d5/ncQDVJl okePY45UbnGG33IGanr3i6ma7FcX3XOp6/P8mwdag5irHTMQ7z795MP6GQVfEJJqESyXbbjhPB9p7 o/yblYc5GAKm/Wpgj5VFb4vc3TnuhWFkQt/ShVaF1bDfmq+p+mFTBCii94aegXA9EGUYEKB1fkp8V 18JyCK6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHul-00000008T3c-3qLV; Wed, 11 Sep 2024 07:37:23 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHmO-00000008Qr6-1016 for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:28:45 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-718d985b6bbso4612421b3a.2 for ; Wed, 11 Sep 2024 00:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726039723; x=1726644523; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fVhbTxLURsXagkjV6T5t8snpx3JbKq5qtkesVJ+9OU0=; b=LjznuO7vyOhEcli+8Hwxr6lad89cdWBH4ULELuZOsbiLm8D4ueR9hXPzoEuHL9syoG uyf7K7t+nYPbPi9J6evEItfVGAMwzdCTLi17A2/LCy0jqAqyz2SMQR6kdKHlUBHogSJR wP8n16usToQQFW35PpKMeAVDcBn2H6VCnxw/4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726039723; x=1726644523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fVhbTxLURsXagkjV6T5t8snpx3JbKq5qtkesVJ+9OU0=; b=ASUlM4SFNUyBWIY9PR8YeprGBO8+LeBx+K1ERH+DjMWZFLpsrPyQStuXbrN/iRHSof 63C5xkLpGhyxylC426B/FQyab8RtORC4s95KvUn1hLfgaC3EE5VbzMvKLFpMkfvDwu9/ 9RV5Zq/5VxgPt85b8jYReuevtQSjjb/iwGS3iMOZw33lrfKYA5cGed16GoYZVFQMceYR wCLSNAV3bzinyvv36CfEFkCVuy1wcCfPZXIawpxjIE+dyM0E0micAQ3ORnBTNm8FBnYf IRNC8PJMOsnnIzbsuy7rJTXg+syUA16ncEFDS6SucqaX+goiAAq7LJPgypXkTzBjALyq 3DbQ== X-Forwarded-Encrypted: i=1; AJvYcCWBaKo0tIU6ZiU2Wa8l6zwnO8HR3q4XLxesUK8AWE+i1s1VMHttI6FX0aDB+V6FXMveTqMqQ+WGgL+9liwFchUs@lists.infradead.org X-Gm-Message-State: AOJu0YxhAVYQCYwGHqM8vkmT7k8ttrK5sub4inF7QCBQ9ZpVPFGePD0v XL9Yn6FQuArNUob3R7f3sArJeZWeb3e3fti/+jgaSp7mLMMB0C3BWIo5qAfZMlMMnhf9xidM9XI = X-Google-Smtp-Source: AGHT+IHJHP/sS0c8oI4sQVmWMgfIt7DzJlolRs9q3i3C6TrZ9TAHcWiYmt8L4UpiwKLjhWZ/rnLTPA== X-Received: by 2002:a05:6a20:cf90:b0:1cf:5437:e76f with SMTP id adf61e73a8af0-1cf5e098306mr4519928637.4.1726039723417; Wed, 11 Sep 2024 00:28:43 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8398:fe34:eba2:f301]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm2399415b3a.80.2024.09.11.00.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:28:43 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v7 07/10] i2c: of-prober: Add simple helpers for regulator support Date: Wed, 11 Sep 2024 15:27:45 +0800 Message-ID: <20240911072751.365361-8-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240911072751.365361-1-wenst@chromium.org> References: <20240911072751.365361-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_002844_366669_0DA43BDF X-CRM114-Status: GOOD ( 30.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add helpers to do regulator management for the I2C OF component prober. Components that the prober intends to probe likely require their regulator supplies be enabled, and GPIOs be toggled to enable them or bring them out of reset before they will respond to probe attempts. GPIOs will be handled in the next patch. The assumption is that the same class of components to be probed are always connected in the same fashion with the same regulator supply and GPIO. The names may vary due to binding differences, but the physical layout does not change. This set of helpers supports at most one regulator supply. The user must specify the node from which the supply is retrieved. The supply name and the amount of time to wait after the supply is enabled are also given by the user. Signed-off-by: Chen-Yu Tsai --- Changes since v6: - Moved change of of_get_next_child_scoped() to of_get_next_child_with_prefix() to previous patch - Restructured into helpers for the I2C OF component prober - Reduced to only handle one regulator - Commit message updated Changes since v5: - Split of_regulator_bulk_get_all() return value check and explain "ret == 0" case - Switched to of_get_next_child_with_prefix_scoped() where applicable - Used krealloc_array() instead of directly calculating size - copy whole regulator array in one memcpy() call - Drop "0" from struct zeroing initializer - Split out regulator helper from i2c_of_probe_enable_res() to keep code cleaner when combined with the next patch - Added options for customizing power sequencing delay - Rename i2c_of_probe_get_regulator() to i2c_of_probe_get_regulators() - Add i2c_of_probe_free_regulator() helper Changes since v4: - Split out GPIO handling to separate patch - Rewrote using of_regulator_bulk_get_all() - Replaced "regulators" with "regulator supplies" in debug messages Changes since v3: - New patch This change is kept as a separate patch for now since the changes are quite numerous. --- drivers/i2c/i2c-core-of-prober.c | 169 ++++++++++++++++++++++++++++++- include/linux/i2c-of-prober.h | 48 +++++++++ 2 files changed, 216 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core-of-prober.c b/drivers/i2c/i2c-core-of-prober.c index 62ff2f4b6177..1371ea565556 100644 --- a/drivers/i2c/i2c-core-of-prober.c +++ b/drivers/i2c/i2c-core-of-prober.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -13,6 +14,7 @@ #include #include #include +#include #include /* @@ -28,7 +30,6 @@ * address responds. * * TODO: - * - Support handling common regulators. * - Support handling common GPIOs. * - Support I2C muxes */ @@ -193,3 +194,169 @@ int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_cfg *cf return ret; } EXPORT_SYMBOL_NS_GPL(i2c_of_probe_component, I2C_OF_PROBER); + +static int i2c_of_probe_simple_get_supply(struct device *dev, struct device_node *node, + struct i2c_of_probe_simple_ctx *ctx) +{ + const char *supply_name; + struct regulator *supply; + + /* + * It's entirely possible for the component's device node to not have regulator + * supplies. While it does not make sense from a hardware perspective, the + * supplies could be always on or otherwise not modeled in the device tree, but + * the device would still work. + */ + supply_name = ctx->opts->supply_name; + if (!supply_name) + return 0; + + supply = of_regulator_get_optional(dev, node, supply_name); + if (IS_ERR(supply)) { + return dev_err_probe(dev, PTR_ERR(supply), + "Failed to get regulator supply \"%s\" from %pOF\n", + supply_name, node); + } + + ctx->supply = supply; + + return 0; +} + +static void i2c_of_probe_simple_put_supply(struct i2c_of_probe_simple_ctx *ctx) +{ + regulator_put(ctx->supply); + ctx->supply = NULL; +} + +static int i2c_of_probe_simple_enable_regulator(struct device *dev, struct i2c_of_probe_simple_ctx *ctx) +{ + int ret; + + if (!ctx->supply) + return 0; + + dev_dbg(dev, "Enabling regulator supply \"%s\"\n", ctx->opts->supply_name); + + ret = regulator_enable(ctx->supply); + if (ret) + return ret; + + msleep(ctx->opts->post_power_on_delay_ms); + + return 0; +} + +static void i2c_of_probe_simple_disable_regulator(struct device *dev, struct i2c_of_probe_simple_ctx *ctx) +{ + if (!ctx->supply) + return; + + dev_dbg(dev, "Disabling regulator supply \"%s\"\n", ctx->opts->supply_name); + + regulator_disable(ctx->supply); +} + +/** + * i2c_of_probe_simple_get_res - Simple helper for I2C OF prober to get resources + * @dev: Pointer to the &struct device of the caller, only used for dev_printk() messages + * @bus_node: Pointer to the &struct device_node of the I2C adapter. + * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. + * + * If &i2c_of_probe_simple_opts->supply_name is given, request the named regulator supply. + * + * Return: %0 on success or no-op, or a negative error number on failure. + */ +int i2c_of_probe_simple_get_res(struct device *dev, struct device_node *bus_node, void *data) +{ + struct i2c_of_probe_simple_ctx *ctx = data; + struct device_node *node; + const char *compat; + int ret; + + dev_dbg(dev, "Requesting resources for components under I2C bus %pOF\n", bus_node); + + if (!ctx || !ctx->opts) + return -EINVAL; + + compat = ctx->opts->res_node_compatible; + if (!compat) + return -EINVAL; + + node = of_get_compatible_child(bus_node, compat); + if (!node) + return dev_err_probe(dev, -ENODEV, "No device compatible with \"%s\" found\n", + compat); + + ret = i2c_of_probe_simple_get_supply(dev, node, ctx); + if (ret) + goto out_put_node; + + return 0; + +out_put_node: + of_node_put(node); + return ret; +} +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_get_res, I2C_OF_PROBER); + +/** + * i2c_of_probe_simple_free_res_late - Simple helper for I2C OF prober to release all resources. + * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. + */ +void i2c_of_probe_simple_free_res_late(void *data) +{ + struct i2c_of_probe_simple_ctx *ctx = data; + + i2c_of_probe_simple_put_supply(ctx); +} +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_free_res_late, I2C_OF_PROBER); + +/** + * i2c_of_probe_simple_enable - Enable resources for I2C OF prober simple helpers + * @dev: Pointer to the &struct device of the caller, only used for dev_printk() messages + * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. + * + * If a regulator supply was found, enable that regulator. + * + * Return: %0 on success or no-op, or a negative error number on failure. + */ +int i2c_of_probe_simple_enable(struct device *dev, void *data) +{ + struct i2c_of_probe_simple_ctx *ctx = data; + int ret; + + ret = i2c_of_probe_simple_enable_regulator(dev, ctx); + if (ret) + return ret; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_enable, I2C_OF_PROBER); + +/** + * i2c_of_probe_simple_cleanup - Clean up resources for I2C OF prober simple helpers + * @dev: Pointer to the &struct device of the caller, only used for dev_printk() messages + * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. + * + * If a regulator supply was found, disable that regulator. + * + * Return: %0 on success or no-op, or a negative error number on failure. + */ +int i2c_of_probe_simple_cleanup(struct device *dev, void *data) +{ + struct i2c_of_probe_simple_ctx *ctx = data; + + i2c_of_probe_simple_disable_regulator(dev, ctx); + + return 0; +} +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_cleanup, I2C_OF_PROBER); + +struct i2c_of_probe_ops i2c_of_probe_simple_ops = { + .get_resources = i2c_of_probe_simple_get_res, + .enable = i2c_of_probe_simple_enable, + .cleanup = i2c_of_probe_simple_cleanup, + .free_resources_late = i2c_of_probe_simple_free_res_late, +}; +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_ops, I2C_OF_PROBER); diff --git a/include/linux/i2c-of-prober.h b/include/linux/i2c-of-prober.h index 0f94e7c94310..541451fbf58d 100644 --- a/include/linux/i2c-of-prober.h +++ b/include/linux/i2c-of-prober.h @@ -68,6 +68,54 @@ struct i2c_of_probe_cfg { int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_cfg *cfg, void *ctx); +/** + * DOC: I2C OF component prober simple helpers + * + * Components such as trackpads are commonly connected to a devices baseboard + * with a 6-pin ribbon cable. That gives at most one voltage supply and one + * GPIO besides the I2C bus, interrupt pin, and common ground. Touchscreens, + * while integrated into the display panel's connection, typically have the + * same set of connections. + * + * A simple set of helpers are provided here for use with the I2C OF component + * prober. This implementation targets such components, allowing for at most + * one regulator supply. + * + * The following helpers are provided: + * * i2c_of_probe_simple_get_res() + * * i2c_of_probe_simple_free_res_late() + * * i2c_of_probe_simple_enable() + * * i2c_of_probe_simple_cleanup() + */ + +/** + * struct i2c_of_probe_simple_opts - Options for simple I2C component prober callbacks + * @res_node_compatible: Compatible string of device node to retrieve resources from. + * @supply_name: Name of regulator supply. + * @post_power_on_delay_ms: Delay in ms after regulators are powered on. Passed to msleep(). + */ +struct i2c_of_probe_simple_opts { + const char *res_node_compatible; + const char *supply_name; + unsigned int post_power_on_delay_ms; +}; + +struct regulator; + +struct i2c_of_probe_simple_ctx { + /* public: provided by user before helpers are used. */ + const struct i2c_of_probe_simple_opts *opts; + /* private: internal fields for helpers. */ + struct regulator *supply; +}; + +int i2c_of_probe_simple_get_res(struct device *dev, struct device_node *bus_node, void *data); +void i2c_of_probe_simple_free_res_late(void *data); +int i2c_of_probe_simple_enable(struct device *dev, void *data); +int i2c_of_probe_simple_cleanup(struct device *dev, void *data); + +extern struct i2c_of_probe_ops i2c_of_probe_simple_ops; + #endif /* IS_ENABLED(CONFIG_OF_DYNAMIC) */ #endif /* _LINUX_I2C_OF_PROBER_H */ From patchwork Wed Sep 11 07:27:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13799829 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 163F8EDE998 for ; Wed, 11 Sep 2024 07:38:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RNFQ0+k6gl1kkh3o3uKf0ZEr04CBiZ9w1gp6dXSYFKk=; b=YATATJnYoHFlfm8b6UdhUTYdKR Xz4obLenMwEAYREm9EH1+glrkRsiNUuBU9BYW7HZzWv/fEx6nlfg5Dmdv+ighfNorH0xhOifT4txg Q6mbSAhTxVvNF0zguzJYpjsB8ddJrAtVpup8AnEvej7HLXmBrLHBkWHHCy8fVI4+nv1DBhLE1xBSh oT1qXUy0y8Zzr0XsLDQptEAx+nQfkza/R+AisuqB1WLhIht4EXgUDMcf/RqR/OL+od4yVqzwiQqui OMLtygyyKXbdmrTRakZezmZ6KDSViteu/7rD8PZcwKD3XiWWcUodbQpqK1A+73APP8BiTsdAw/ZL2 htmdxA4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHvl-00000008TSS-3D5R; Wed, 11 Sep 2024 07:38:25 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHmR-00000008QsV-2VN8 for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:28:49 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-718e285544fso2991581b3a.1 for ; Wed, 11 Sep 2024 00:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726039727; x=1726644527; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RNFQ0+k6gl1kkh3o3uKf0ZEr04CBiZ9w1gp6dXSYFKk=; b=ONngVfoVhAiiMMnUMKdFmGZ9YLaFygUyXT8wj9CzLto5VKwyNQcLSHNw2TwVdPr6Rk SQBOxxmaRAJ8OeJ5dOov4F1W2NATku+I8s5tEPJ3XV3QhuW/Wcs6KTuGBEq8dZFCySuX A42wZT+O1xaqBcr0cP+Vw2jKWBo/U4D30kSks= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726039727; x=1726644527; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RNFQ0+k6gl1kkh3o3uKf0ZEr04CBiZ9w1gp6dXSYFKk=; b=evd3byvvLKaG31DFfwnfZ5JWJ84HhVzZrF3pvqlYQxro9W+g9rDTflrHkDFXhLGhVH q0DKYTkchwN8CxD2SgOxPqQwgFnRjJ1xaWnUI3rlhDFutIvH8I0J733xaxf5z/xScF4e 4mB7qtN9axsBGzZ7o611l6BqGjwcKT2zrqPXW0u/8oHXeVu5M0n5MX4IT7azyPSR+QUE 16zMhnWoFaQYUZcX8sGz79/myPBBuOG8ZgnKkB65JB9EBA1HBUddK3CoWJT1xakrDI9q 3NZojUnE3jjkNL7cFXJn8A/RSmZ7J+kkv1GAajMyG7KE0QQakieFO8BVQp/cRhgANxWx AAgw== X-Forwarded-Encrypted: i=1; AJvYcCU1YrPJrZYi/+tw2u6Vp7satudzKjW8eDI1FSrjKPhca7XzlZB8M/E9+wM5qzTTInDzfVWb2iaEkwK8d2+GxXy5@lists.infradead.org X-Gm-Message-State: AOJu0YzZxLMxBXZI4DmZAVeBQgCwEUxAV5W6VGQng+zLSabMUOz5q8RM CPRXE+t5WsrxNFiRU0po2419Zwczq70ECWG0GHNCfxOGY15djxTAKT8fQch/DA== X-Google-Smtp-Source: AGHT+IFFL6/Rj4Gwyc1YxeZ/hABvvBsCQgvzC/UjAY926OKBN27PE9HKTGhU9CwzQureNFH/FVgdIQ== X-Received: by 2002:a05:6a00:1254:b0:70e:8070:f9d0 with SMTP id d2e1a72fcca58-718d5e16641mr18401634b3a.9.1726039726903; Wed, 11 Sep 2024 00:28:46 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8398:fe34:eba2:f301]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm2399415b3a.80.2024.09.11.00.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:28:46 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v7 08/10] i2c: of-prober: Add GPIO support to simple helpers Date: Wed, 11 Sep 2024 15:27:46 +0800 Message-ID: <20240911072751.365361-9-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240911072751.365361-1-wenst@chromium.org> References: <20240911072751.365361-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_002847_702373_12A3CB80 X-CRM114-Status: GOOD ( 29.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add GPIO support to the simple helpers for the I2C OF component prober. Components that the prober intends to probe likely require their regulator supplies be enabled, and GPIOs be toggled to enable them or bring them out of reset before they will respond to probe attempts. Regulator supplies were handled in the previous patch. The assumption is that the same class of components to be probed are always connected in the same fashion with the same regulator supply and GPIO. The names may vary due to binding differences, but the physical layout does not change. This supports at most one GPIO pin. The user must specify the GPIO name, the polarity, and the amount of time to wait after the GPIO is toggled. Devices with more than one GPIO pin likely require specific power sequencing beyond what generic code can easily support. Signed-off-by: Chen-Yu Tsai --- Changes since v6: - Restructured into helpers for the I2C OF component prober - Reduced to only handle one GPIO - Set GPIO to input on (failure) cleanup - Updated commit message Changes since v5: - Renamed "con" to "propname" in i2c_of_probe_get_gpiod() - Copy string first and check return value of strscpy() for overflow in i2c_of_probe_get_gpiod() - Add parenthesis around "enable" and "reset" GPIO names in comments - Split resource count debug message into two separate lines - Split out GPIO helper from i2c_of_probe_enable_res() to keep code cleaner following the previous patch - Adopted options for customizing power sequencing delay following previous patch Changes since v4: - Split out from previous patch - Moved GPIO property name check to common function in gpiolib.c in new patch - Moved i2c_of_probe_free_gpios() into for_each_child_of_node_scoped() - Rewrote in gpiod_*_array-esque fashion --- drivers/i2c/i2c-core-of-prober.c | 95 +++++++++++++++++++++++++++++++- include/linux/i2c-of-prober.h | 10 ++++ 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core-of-prober.c b/drivers/i2c/i2c-core-of-prober.c index 1371ea565556..6794ec749882 100644 --- a/drivers/i2c/i2c-core-of-prober.c +++ b/drivers/i2c/i2c-core-of-prober.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,6 @@ * address responds. * * TODO: - * - Support handling common GPIOs. * - Support I2C muxes */ @@ -257,6 +257,64 @@ static void i2c_of_probe_simple_disable_regulator(struct device *dev, struct i2c regulator_disable(ctx->supply); } +static int i2c_of_probe_simple_get_gpiod(struct device *dev, struct device_node *node, + struct i2c_of_probe_simple_ctx *ctx) +{ + struct fwnode_handle *fwnode = of_fwnode_handle(node); + struct gpio_desc *gpiod; + const char *con_id = NULL; + + /* NULL signals no GPIO needed */ + if (!ctx->opts->gpio_name) + return 0; + + /* An empty string signals an unnamed GPIO */ + if (strlen(ctx->opts->gpio_name)) + con_id = ctx->opts->gpio_name; + + gpiod = fwnode_gpiod_get_index(fwnode, con_id, 0, GPIOD_ASIS, "i2c-of-prober"); + if (IS_ERR(gpiod)) + return PTR_ERR(gpiod); + + ctx->gpiod = gpiod; + + return 0; +} + +static void i2c_of_probe_simple_put_gpiod(struct i2c_of_probe_simple_ctx *ctx) +{ + gpiod_put(ctx->gpiod); + ctx->gpiod = NULL; +} + +static int i2c_of_probe_simple_set_gpio(struct device *dev, struct i2c_of_probe_simple_ctx *ctx) +{ + int ret; + + if (!ctx->gpiod) + return 0; + + dev_dbg(dev, "Setting GPIO\n"); + + ret = gpiod_direction_output_raw(ctx->gpiod, ctx->opts->gpio_high_to_enable ? 1 : 0); + if (ret) + return ret; + + msleep(ctx->opts->post_reset_deassert_delay_ms); + + return 0; +} + +static void i2c_of_probe_simple_disable_gpio(struct device *dev, struct i2c_of_probe_simple_ctx *ctx) +{ + if (!ctx->gpiod) + return; + + dev_dbg(dev, "Setting GPIO to input\n"); + + gpiod_direction_input(ctx->gpiod); +} + /** * i2c_of_probe_simple_get_res - Simple helper for I2C OF prober to get resources * @dev: Pointer to the &struct device of the caller, only used for dev_printk() messages @@ -264,6 +322,8 @@ static void i2c_of_probe_simple_disable_regulator(struct device *dev, struct i2c * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. * * If &i2c_of_probe_simple_opts->supply_name is given, request the named regulator supply. + * If &i2c_of_probe_simple_opts->gpio_name is given, request the named GPIO. Or if it is + * the empty string, request the unnamed GPIO. * * Return: %0 on success or no-op, or a negative error number on failure. */ @@ -292,14 +352,36 @@ int i2c_of_probe_simple_get_res(struct device *dev, struct device_node *bus_node if (ret) goto out_put_node; + ret = i2c_of_probe_simple_get_gpiod(dev, node, ctx); + if (ret) + goto out_put_supply; + return 0; +out_put_supply: + i2c_of_probe_simple_put_supply(ctx); out_put_node: of_node_put(node); return ret; } EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_get_res, I2C_OF_PROBER); +/** + * i2c_of_probe_simple_free_res_early - \ + * Simple helper for I2C OF prober to release GPIOs before component is enabled + * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. + * + * GPIO descriptors are exclusive and have to be released before the + * actual driver probes so that the latter can acquire them. + */ +void i2c_of_probe_simple_free_res_early(void *data) +{ + struct i2c_of_probe_simple_ctx *ctx = data; + + i2c_of_probe_simple_put_gpiod(ctx); +} +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_free_res_early, I2C_OF_PROBER); + /** * i2c_of_probe_simple_free_res_late - Simple helper for I2C OF prober to release all resources. * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. @@ -308,6 +390,7 @@ void i2c_of_probe_simple_free_res_late(void *data) { struct i2c_of_probe_simple_ctx *ctx = data; + i2c_of_probe_simple_put_gpiod(ctx); i2c_of_probe_simple_put_supply(ctx); } EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_free_res_late, I2C_OF_PROBER); @@ -330,7 +413,15 @@ int i2c_of_probe_simple_enable(struct device *dev, void *data) if (ret) return ret; + ret = i2c_of_probe_simple_set_gpio(dev, ctx); + if (ret) + goto err; + return 0; + +err: + i2c_of_probe_simple_disable_regulator(dev, ctx); + return ret; } EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_enable, I2C_OF_PROBER); @@ -347,6 +438,7 @@ int i2c_of_probe_simple_cleanup(struct device *dev, void *data) { struct i2c_of_probe_simple_ctx *ctx = data; + i2c_of_probe_simple_disable_gpio(dev, ctx); i2c_of_probe_simple_disable_regulator(dev, ctx); return 0; @@ -355,6 +447,7 @@ EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_cleanup, I2C_OF_PROBER); struct i2c_of_probe_ops i2c_of_probe_simple_ops = { .get_resources = i2c_of_probe_simple_get_res, + .free_resources_early = i2c_of_probe_simple_free_res_early, .enable = i2c_of_probe_simple_enable, .cleanup = i2c_of_probe_simple_cleanup, .free_resources_late = i2c_of_probe_simple_free_res_late, diff --git a/include/linux/i2c-of-prober.h b/include/linux/i2c-of-prober.h index 541451fbf58d..c5e241163c94 100644 --- a/include/linux/i2c-of-prober.h +++ b/include/linux/i2c-of-prober.h @@ -83,6 +83,7 @@ int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_cfg *cf * * The following helpers are provided: * * i2c_of_probe_simple_get_res() + * * i2c_of_probe_simple_free_res_early() * * i2c_of_probe_simple_free_res_late() * * i2c_of_probe_simple_enable() * * i2c_of_probe_simple_cleanup() @@ -92,24 +93,33 @@ int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_cfg *cf * struct i2c_of_probe_simple_opts - Options for simple I2C component prober callbacks * @res_node_compatible: Compatible string of device node to retrieve resources from. * @supply_name: Name of regulator supply. + * @gpio_name: Name of GPIO. * @post_power_on_delay_ms: Delay in ms after regulators are powered on. Passed to msleep(). + * @post_reset_deassert_delay_ms: Delay in ms after GPIOs are set. Passed to msleep(). + * @gpio_high_to_enable: %true if GPIO should be set to electrical high to enable component. */ struct i2c_of_probe_simple_opts { const char *res_node_compatible; const char *supply_name; + const char *gpio_name; unsigned int post_power_on_delay_ms; + unsigned int post_reset_deassert_delay_ms; + bool gpio_high_to_enable; }; struct regulator; +struct gpio_desc; struct i2c_of_probe_simple_ctx { /* public: provided by user before helpers are used. */ const struct i2c_of_probe_simple_opts *opts; /* private: internal fields for helpers. */ struct regulator *supply; + struct gpio_desc *gpiod; }; int i2c_of_probe_simple_get_res(struct device *dev, struct device_node *bus_node, void *data); +void i2c_of_probe_simple_free_res_early(void *data); void i2c_of_probe_simple_free_res_late(void *data); int i2c_of_probe_simple_enable(struct device *dev, void *data); int i2c_of_probe_simple_cleanup(struct device *dev, void *data); From patchwork Wed Sep 11 07:27:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13799830 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7AFE3EE0211 for ; Wed, 11 Sep 2024 07:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fr9yV4HGWVMIrGkx9ydigLiwJCnrmGer3in2e1w4xKk=; b=YCRRAgk7iH1uJMqJ2e/wsnLsxI yhnaZvwmBFiQ3SDW+5vUw+TDA24NLm6iIPzBn08/V4UT+vp496b0hyv68vwEi5mEKQA72iP8l1X3p UjdS+7WCq6yr1vh0Esi3xLGdO+3lculTjsCU3ZSnIUrnaVX9wWi214RYqbKO1HrHYFX/rjHitmI4O THZogvIvI/CrhlN1eBkDl0eGfdO/uqa1w4HMjR4T4Bm0UpY98rdL7cbAeLSYXj9ymMCW+IoZWVX0y hwdJ3rMTqXDKe23nsDMp+/o+BUOYtCXI2OLXo23ZI8b3b9tAlwW6OlgRR6S5l5eFaJDPUn8sOScJB 9F/cmObw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHwl-00000008TpY-0pWT; Wed, 11 Sep 2024 07:39:27 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHmV-00000008QuK-0PHQ for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:28:53 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-718e3c98b5aso3071265b3a.0 for ; Wed, 11 Sep 2024 00:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726039730; x=1726644530; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fr9yV4HGWVMIrGkx9ydigLiwJCnrmGer3in2e1w4xKk=; b=T9Gt47YX90RJMgoln2rdfvTDBCP6JJUu/P28hLQR/3ERnB5BOU43t5KobKyHbMOIy6 q84BEve6NrYyvgEGc4txUva+O85O6lcfGVMhHO3GGckcalMKAjlHBvIRKrFqnzGRnwDp DcCrfpxRL3y3LD1nQpJchmgy9aVyClSlxpCcY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726039730; x=1726644530; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fr9yV4HGWVMIrGkx9ydigLiwJCnrmGer3in2e1w4xKk=; b=F2DI39D8IlYkKz8CiFgoL6Tm8pTY/nikoiGWs2HwdfjKZbMrEDrzjzm7T7GETcBbGS 23iVG6g/VuXDzEpzaQb2lTD3PaQNZY1DlCUmjAvE6dvwZdJMn8eESoQNS1K/RthIEsE1 B98XT9ePalsBo0uLG9UvIo8fFeYhnihfNLg8sAv+lP5BDtHXlTZYVp/ktKqD+GZeAcr9 qou0HEpnbiYGPWV1y2vNUAU2Ii8p7f//qDlneAoWY/29ldDqbZsDXH/TQ0S0XiU2lA0m KGQ/wdbvivgN5XSsODkhBmJcKnrmCrH1k9V3xEJLGX6QLQzRQ45gikYPo3RRPHpkm5+p /hlw== X-Forwarded-Encrypted: i=1; AJvYcCU6IhihFvyFEan8WBGTBkFr6mGfT8w0qxLbSwDFQ3TuHR99MsIz3Qz+SqWsxTFPBGhbrL1He2yKcvHtEAGhXZiT@lists.infradead.org X-Gm-Message-State: AOJu0YxVTwfsQlu+qAdj5OyX8HpJGyegWKERz573kWIFq+1GlBn06ufj F+YpZspthv6IXNtPg6XnTkEU5YIzGPdtZR7WDnRKVOjkQXEEutOeGesWJJQI4g== X-Google-Smtp-Source: AGHT+IEzZ5LA89X7I7aF3pUCsQe4p61WBrpC4obNNheNiGy0SPXWE2Q7sI4QYrZczPaRm66JSqQ2zw== X-Received: by 2002:a05:6a21:4a4b:b0:1cf:2df6:453f with SMTP id adf61e73a8af0-1cf5de0ef4cmr5867206637.0.1726039730361; Wed, 11 Sep 2024 00:28:50 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8398:fe34:eba2:f301]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm2399415b3a.80.2024.09.11.00.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:28:50 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v7 09/10] platform/chrome: Introduce device tree hardware prober Date: Wed, 11 Sep 2024 15:27:47 +0800 Message-ID: <20240911072751.365361-10-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240911072751.365361-1-wenst@chromium.org> References: <20240911072751.365361-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_002851_185317_6843BA6D X-CRM114-Status: GOOD ( 40.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some devices are designed and manufactured with some components having multiple drop-in replacement options. These components are often connected to the mainboard via ribbon cables, having the same signals and pin assignments across all options. These may include the display panel and touchscreen on laptops and tablets, and the trackpad on laptops. Sometimes which component option is used in a particular device can be detected by some firmware provided identifier, other times that information is not available, and the kernel has to try to probe each device. This change attempts to make the "probe each device" case cleaner. The current approach is to have all options added and enabled in the device tree. The kernel would then bind each device and run each driver's probe function. This works, but has been broken before due to the introduction of asynchronous probing, causing multiple instances requesting "shared" resources, such as pinmuxes, GPIO pins, interrupt lines, at the same time, with only one instance succeeding. Work arounds for these include moving the pinmux to the parent I2C controller, using GPIO hogs or pinmux settings to keep the GPIO pins in some fixed configuration, and requesting the interrupt line very late. Such configurations can be seen on the MT8183 Krane Chromebook tablets, and the Qualcomm sc8280xp-based Lenovo Thinkpad 13S. Instead of this delicate dance between drivers and device tree quirks, this change introduces a simple I2C component prober. For any given class of devices on the same I2C bus, it will go through all of them, doing a simple I2C read transfer and see which one of them responds. It will then enable the device that responds. This requires some minor modifications in the existing device tree. The status for all the device nodes for the component options must be set to "failed-needs-probe". This makes it clear that some mechanism is needed to enable one of them, and also prevents the prober and device drivers running at the same time. Signed-off-by: Chen-Yu Tsai Acked-by: Tzung-Bi Shih --- Changes since v6: - Adapted to new I2C OF prober interface - Collected Acked-by Changes since v5: - Adapt to new i2c_of_probe_component() parameters Changes since v4: - Fix Kconfig dependency - Update copyright year - Drop "linux/of.h" header - Include "linux/errno.h" - Move |int ret| declaration to top of block - Return -ENODEV on no match instead of 0 - Unregister platform driver and device unconditionally after previous change Changes since v3: - Include linux/init.h - Rewrite for loop in driver probe function as suggested by Andy - Make prober driver buildable as module - Ignore prober errors other than probe deferral Changes since v2: - Addressed Rob's comments - Move remaining driver code to drivers/platform/chrome/ - Depend on rather than select CONFIG_I2C - Copy machine check to driver init function - Addressed Andy's comments - Explicitly mention "device tree" or OF in driver name, description and Kconfig symbol - Drop filename from inside the file - Switch to passing "struct device *" to shorten lines - Move "ret = 0" to just before for_each_child_of_node(i2c_node, node) - Make loop variable size_t (instead of unsigned int as Andy asked) - Use PLATFORM_DEVID_NONE instead of raw -1 - Use standard goto error path pattern in hw_prober_driver_init() - Changes since v1: - New patch --- drivers/platform/chrome/Kconfig | 11 ++ drivers/platform/chrome/Makefile | 1 + .../platform/chrome/chromeos_of_hw_prober.c | 125 ++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 drivers/platform/chrome/chromeos_of_hw_prober.c diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index 7dbeb786352a..b7dbaf77b6db 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -61,6 +61,17 @@ config CHROMEOS_TBMC To compile this driver as a module, choose M here: the module will be called chromeos_tbmc. +config CHROMEOS_OF_HW_PROBER + tristate "ChromeOS Device Tree Hardware Prober" + depends on OF + depends on I2C + select OF_DYNAMIC + default OF + help + This option enables the device tree hardware prober for ChromeOS + devices. The driver will probe the correct component variant in + devices that have multiple drop-in options for one component. + config CROS_EC tristate "ChromeOS Embedded Controller" select CROS_EC_PROTO diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index 2dcc6ccc2302..21a9d5047053 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_CHROMEOS_ACPI) += chromeos_acpi.o obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o obj-$(CONFIG_CHROMEOS_PRIVACY_SCREEN) += chromeos_privacy_screen.o obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o +obj-$(CONFIG_CHROMEOS_OF_HW_PROBER) += chromeos_of_hw_prober.o obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o obj-$(CONFIG_CROS_EC) += cros_ec.o obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o diff --git a/drivers/platform/chrome/chromeos_of_hw_prober.c b/drivers/platform/chrome/chromeos_of_hw_prober.c new file mode 100644 index 000000000000..6d9667c40cc7 --- /dev/null +++ b/drivers/platform/chrome/chromeos_of_hw_prober.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ChromeOS Device Tree Hardware Prober + * + * Copyright (c) 2024 Google LLC + */ + +#include +#include +#include +#include +#include + +#define DRV_NAME "chromeos_of_hw_prober" + +/** + * struct hw_prober_entry - Holds an entry for the hardware prober + * + * @compatible: compatible string to match against the machine + * @prober: prober function to call when machine matches + * @data: extra data for the prober function + */ +struct hw_prober_entry { + const char *compatible; + int (*prober)(struct device *dev, const void *data); + const void *data; +}; + +struct chromeos_i2c_probe_data { + const struct i2c_of_probe_cfg *cfg; + const struct i2c_of_probe_simple_opts *opts; +}; + +static int chromeos_i2c_component_prober(struct device *dev, const void *_data) +{ + const struct chromeos_i2c_probe_data *data = _data; + struct i2c_of_probe_simple_ctx ctx = { + .opts = data->opts + }; + + return i2c_of_probe_component(dev, data->cfg, &ctx); +} + +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_dumb_touchscreen = { + .cfg = &(const struct i2c_of_probe_cfg) { + .type = "touchscreen" + } +}; + +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_dumb_trackpad = { + .cfg = &(const struct i2c_of_probe_cfg) { + .type = "trackpad" + } +}; + +static const struct hw_prober_entry hw_prober_platforms[] = { + { .compatible = "google,hana", .prober = chromeos_i2c_component_prober, .data = &chromeos_i2c_probe_dumb_touchscreen }, + { .compatible = "google,hana", .prober = chromeos_i2c_component_prober, .data = &chromeos_i2c_probe_dumb_trackpad }, +}; + +static int chromeos_of_hw_prober_probe(struct platform_device *pdev) +{ + for (size_t i = 0; i < ARRAY_SIZE(hw_prober_platforms); i++) { + int ret; + + if (!of_machine_is_compatible(hw_prober_platforms[i].compatible)) + continue; + + ret = hw_prober_platforms[i].prober(&pdev->dev, hw_prober_platforms[i].data); + /* Ignore unrecoverable errors and keep going through other probers */ + if (ret == -EPROBE_DEFER) + return ret; + } + + return 0; +} + +static struct platform_driver chromeos_of_hw_prober_driver = { + .probe = chromeos_of_hw_prober_probe, + .driver = { + .name = DRV_NAME, + }, +}; + +static struct platform_device *chromeos_of_hw_prober_pdev; + +static int chromeos_of_hw_prober_driver_init(void) +{ + size_t i; + int ret; + + for (i = 0; i < ARRAY_SIZE(hw_prober_platforms); i++) + if (of_machine_is_compatible(hw_prober_platforms[i].compatible)) + break; + if (i == ARRAY_SIZE(hw_prober_platforms)) + return -ENODEV; + + ret = platform_driver_register(&chromeos_of_hw_prober_driver); + if (ret) + return ret; + + chromeos_of_hw_prober_pdev = + platform_device_register_simple(DRV_NAME, PLATFORM_DEVID_NONE, NULL, 0); + if (IS_ERR(chromeos_of_hw_prober_pdev)) + goto err; + + return 0; + +err: + platform_driver_unregister(&chromeos_of_hw_prober_driver); + + return PTR_ERR(chromeos_of_hw_prober_pdev); +} +module_init(chromeos_of_hw_prober_driver_init); + +static void chromeos_of_hw_prober_driver_exit(void) +{ + platform_device_unregister(chromeos_of_hw_prober_pdev); + platform_driver_unregister(&chromeos_of_hw_prober_driver); +} +module_exit(chromeos_of_hw_prober_driver_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("ChromeOS device tree hardware prober"); +MODULE_IMPORT_NS(I2C_OF_PROBER); From patchwork Wed Sep 11 07:27:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13799831 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05D2BEE0211 for ; Wed, 11 Sep 2024 07:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nwH4RxuOgmEV/VtpOzbgUmR2GAZBgupxo+TGOE0kG2U=; b=BMvJnpp8jW2DI8pLJ/nMZa/owd rIJltZv6JGUkXivkaQo7Vc4Jtr+ZLfDFBD0N0EHw7sRkXgmE0KoFyoUftA4Nx5S690lmUqUugcQUW GySPQhKIZswl3Ov5PvsXTSFjDapyv6tpbkj66n1C4gd+aKHu3zQDvfwY+cZG63FW09qpciA49ooc9 2qJtvPMpG9WlcRaMTZ7wExtG366uH645AxkMqVuTxT8zL5Xi0846iX7j43zdRz2l3CVwEGuSEvLgx DNEKUNYuC46sO2YB5BQSHgPURxm94Z+wLXPzxvOzHi7xATG0do6bq/iBdGSL68C+wETnYWho3i4pt rmOMuaaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHxn-00000008U86-0f28; Wed, 11 Sep 2024 07:40:31 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHmY-00000008QwJ-3sx9 for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:28:56 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-718d985b6bbso4612585b3a.2 for ; Wed, 11 Sep 2024 00:28:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726039734; x=1726644534; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nwH4RxuOgmEV/VtpOzbgUmR2GAZBgupxo+TGOE0kG2U=; b=cMyuSXy33b4RzrULMmZDSEfKhfc0OXp4erQcXRkAQLp4xwbtWKxFs2FDVXKeW1q0Tg mqn+CBkND3hMpto80HKk59JtzGx6EIbt5ZbzyScRxl8kIh43cwjfrX7e4GV48izmdBom OwC2RUtVjz6UbCqh30x/Fjl2vjzbg2z9B7YBQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726039734; x=1726644534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nwH4RxuOgmEV/VtpOzbgUmR2GAZBgupxo+TGOE0kG2U=; b=odDLtbqlelPH+X6ACpQBzcYZTDr5uLFExVasi9EbVbSYGF+m/cYHxdydO1tanGe/DO WbOhtfgyATdNRZt2PimUkFCJv+Q6aqYv84Y2o4bv6HSGwqwuvtRHMRioW8AqCMyqXnFF uupmDETDxa0z2fwoiFjvnwO0OBIBQuTGNUVLwpfAHn1AepVHBrKAjS+M3dmZS+KJHuZc WG9BGY9LggXd0RJnLmkH8TVggm7V61E9DzyK8IcGCeNLPwgPouICG/vvQnYzLxbYECm5 VFx+5xo7+v9k5vxgAnTha2w9ZrJS+zRsgGN2HJFCH9GQieLxYQ/7M3N0XF+/gBWwKVrK /BUA== X-Forwarded-Encrypted: i=1; AJvYcCU+rjzFOdPHE8X5KCwe8O6B/1SwKlf7goucgUBgcUm2ptO48mZJvsdawTCyoHllLBV7qtVnS4lLtHjZ+Hq/Ry6x@lists.infradead.org X-Gm-Message-State: AOJu0YzbXUexBVM+lsmlDDJntNqx2ykY0MvcyR86p9YQwzG4jo2ydPau W36ouEj/p33hgP4y0lSgxVX6byPB4qnZi0Opi3GkeEYYnVQGLTY1KcwLH5eodg== X-Google-Smtp-Source: AGHT+IE516O5LzHPomwlShsfozQVhv9kW9/2NJZ52HjZuQpukTdS9x9UaAx49lZ9H3HGK77PP1P1/Q== X-Received: by 2002:a05:6a00:4b4c:b0:717:bce8:f8a9 with SMTP id d2e1a72fcca58-718d5dee47amr21431629b3a.1.1726039733865; Wed, 11 Sep 2024 00:28:53 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8398:fe34:eba2:f301]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm2399415b3a.80.2024.09.11.00.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:28:53 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v7 10/10] arm64: dts: mediatek: mt8173-elm-hana: Mark touchscreens and trackpads as fail Date: Wed, 11 Sep 2024 15:27:48 +0800 Message-ID: <20240911072751.365361-11-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240911072751.365361-1-wenst@chromium.org> References: <20240911072751.365361-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_002855_021394_35395A18 X-CRM114-Status: GOOD ( 15.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Instead of having them all available, mark them all as "fail-needs-probe" and have the implementation try to probe which one is present. Also remove the shared resource workaround by moving the pinctrl entry for the trackpad interrupt line back into the individual trackpad nodes. Signed-off-by: Chen-Yu Tsai --- Changes since v6: None. Changes since v5: None. Changes since v4: - Rebased Changes since v3: - Also remove second source workaround, i.e. move the interrupt line pinctrl entry from the i2c node back to the components. Changes since v2: - Drop class from status --- arch/arm64/boot/dts/mediatek/mt8173-elm-hana.dtsi | 13 +++++++++++++ arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/mediatek/mt8173-elm-hana.dtsi b/arch/arm64/boot/dts/mediatek/mt8173-elm-hana.dtsi index 8d1cbc92bce3..251e084bf7de 100644 --- a/arch/arm64/boot/dts/mediatek/mt8173-elm-hana.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8173-elm-hana.dtsi @@ -14,6 +14,7 @@ touchscreen2: touchscreen@34 { compatible = "melfas,mip4_ts"; reg = <0x34>; interrupts-extended = <&pio 88 IRQ_TYPE_LEVEL_LOW>; + status = "fail-needs-probe"; }; /* @@ -26,6 +27,7 @@ touchscreen3: touchscreen@20 { reg = <0x20>; hid-descr-addr = <0x0020>; interrupts-extended = <&pio 88 IRQ_TYPE_LEVEL_LOW>; + status = "fail-needs-probe"; }; /* Lenovo Ideapad C330 uses G2Touch touchscreen as a 2nd source touchscreen */ @@ -47,9 +49,12 @@ &i2c4 { trackpad2: trackpad@2c { compatible = "hid-over-i2c"; interrupts-extended = <&pio 117 IRQ_TYPE_LEVEL_LOW>; + pinctrl-names = "default"; + pinctrl-0 = <&trackpad_irq>; reg = <0x2c>; hid-descr-addr = <0x0020>; wakeup-source; + status = "fail-needs-probe"; }; }; @@ -74,3 +79,11 @@ pins_wp { }; }; }; + +&touchscreen { + status = "fail-needs-probe"; +}; + +&trackpad { + status = "fail-needs-probe"; +}; diff --git a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi index b4d85147b77b..eee64461421f 100644 --- a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi @@ -358,12 +358,12 @@ touchscreen: touchscreen@10 { &i2c4 { clock-frequency = <400000>; status = "okay"; - pinctrl-names = "default"; - pinctrl-0 = <&trackpad_irq>; trackpad: trackpad@15 { compatible = "elan,ekth3000"; interrupts-extended = <&pio 117 IRQ_TYPE_LEVEL_LOW>; + pinctrl-names = "default"; + pinctrl-0 = <&trackpad_irq>; reg = <0x15>; vcc-supply = <&mt6397_vgp6_reg>; wakeup-source;