From patchwork Thu Jul 20 09:55:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 1810491 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=V2Wly0yc; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6F5g6gsrz1yYm for ; Fri, 21 Jul 2023 00:13:11 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 69885867DA; Thu, 20 Jul 2023 16:13:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="V2Wly0yc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 173F886719; Thu, 20 Jul 2023 11:56:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_FILL_THIS_FORM_SHORT,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 65D758615A for ; Thu, 20 Jul 2023 11:56:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mripard@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 20DDA619F2; Thu, 20 Jul 2023 09:56:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDDABC433C9; Thu, 20 Jul 2023 09:56:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689846964; bh=u77FFabAHTqZC6U6+o4mCn8aRfkra8jOP+lpC3dRgo4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=V2Wly0ycikBMwuN989B2OQix6doh5gScUgo6KSBSETRCqTcsEl9hQmBTJyQi02i0s Ho0/5OHDVHbNBThIF0EI3ZPlgLOT6tf7CGrPmz+0WFG94DklQ5B8s5muOXkqzPqpaj dkKBnLKpFWgOC5sVKdELKe6CeSogizWR1/ubZtShX87IpXsugSbm0sh7OguTjY1Evq MbeOKp3Nswuiv4P6kn05E4Uyy4nyzIKPYbGy3nGwk3EWt1zae5El0lCQMJGJFrb/bS bLnPtU2NjL1rDNOaPM1E7kmm4nPNi1XME1wzGHMaCuWndL9MlaHO6rUeIi7FftCAIe n3ZhKSFWIwZkg== From: Maxime Ripard Date: Thu, 20 Jul 2023 11:55:56 +0200 Subject: [PATCH 1/4] pinctrl: Create a select_state variant with the ofnode MIME-Version: 1.0 Message-Id: <20230720-ti-mdio-pinmux-v1-1-0bd3bd1cf759@kernel.org> References: <20230720-ti-mdio-pinmux-v1-0-0bd3bd1cf759@kernel.org> In-Reply-To: <20230720-ti-mdio-pinmux-v1-0-0bd3bd1cf759@kernel.org> To: Simon Glass , Joe Hershberger , Ramon Fried , Nishanth Menon , Ravi Gunasekaran Cc: Javier Martinez Canillas , Peter Robinson , u-boot@lists.denx.de, Maxime Ripard X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4466; i=mripard@kernel.org; h=from:subject:message-id; bh=u77FFabAHTqZC6U6+o4mCn8aRfkra8jOP+lpC3dRgo4=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDCk7WdZ96ipRqvRQnXlXa1lvV8ZyzVn/52ocvz+DTcf6Y Z/ii4QPHaUsDGJcDLJiiiwxwuZL4k7Net3JxjcPZg4rE8gQBi5OAZjIUitGhr3TvWvfTzGTFKuw 7T68Q3zz4jktSx82VUnG6d5fOEl86VNGhvWtn54wHG7YtrJ2t57z35azkvG1t68vmBcV61jpUx+ ygAcA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Mailman-Approved-At: Thu, 20 Jul 2023 16:12:58 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Some drivers might not follow entirely the driver/device association, and thus might support what should be multiple devices in a single driver. Such a driver is am65-cpsw-nuss, where the MAC and MDIO controllers are different device tree nodes, with their own resources (including pinctrl pins) but supported by a single driver tied to the MAC device in U-Boot. In order to get the proper pinctrl state, we would need to get the state from the MDIO device tree node, but tie it to the MAC device since it's the only thing we have access to. Signed-off-by: Maxime Ripard --- drivers/pinctrl/pinctrl-uclass.c | 15 +++++++++------ include/dm/pinctrl.h | 26 ++++++++++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index 73dd7b1038bb..9e28f1858cbd 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -53,7 +53,8 @@ static int pinctrl_config_one(struct udevice *config) * @statename: state name, like "default" * @return: 0 on success, or negative error code on failure */ -static int pinctrl_select_state_full(struct udevice *dev, const char *statename) +static int pinctrl_select_state_full(struct udevice *dev, ofnode node, + const char *statename) { char propname[32]; /* long enough */ const fdt32_t *list; @@ -61,7 +62,7 @@ static int pinctrl_select_state_full(struct udevice *dev, const char *statename) struct udevice *config; int state, size, i, ret; - state = dev_read_stringlist_search(dev, "pinctrl-names", statename); + state = ofnode_stringlist_search(node, "pinctrl-names", statename); if (state < 0) { char *end; /* @@ -74,7 +75,7 @@ static int pinctrl_select_state_full(struct udevice *dev, const char *statename) } snprintf(propname, sizeof(propname), "pinctrl-%d", state); - list = dev_read_prop(dev, propname, &size); + list = ofnode_get_property(node, propname, &size); if (!list) return -ENOSYS; @@ -293,20 +294,22 @@ static int pinctrl_select_state_simple(struct udevice *dev) return ops->set_state_simple(pctldev, dev); } -int pinctrl_select_state(struct udevice *dev, const char *statename) +int pinctrl_select_state_by_ofnode(struct udevice *dev, ofnode node, + const char *statename) { /* * Some device which is logical like mmc.blk, do not have * a valid ofnode. */ - if (!dev_has_ofnode(dev)) + if (!ofnode_valid(node)) return 0; + /* * Try full-implemented pinctrl first. * If it fails or is not implemented, try simple one. */ if (CONFIG_IS_ENABLED(PINCTRL_FULL)) - return pinctrl_select_state_full(dev, statename); + return pinctrl_select_state_full(dev, node, statename); return pinctrl_select_state_simple(dev); } diff --git a/include/dm/pinctrl.h b/include/dm/pinctrl.h index e3e50afeaff0..be4679b7f20d 100644 --- a/include/dm/pinctrl.h +++ b/include/dm/pinctrl.h @@ -502,6 +502,24 @@ static inline int pinctrl_generic_set_state(struct udevice *pctldev, #endif #if CONFIG_IS_ENABLED(PINCTRL) +/** + * pinctrl_select_state_by_ofnode() - Set a device to a given state using the given ofnode + * @dev: Peripheral device + * @ofnode: Device Tree node to get the state from + * @statename: State name, like "default" + * + * Return: 0 on success, or negative error code on failure + */ +int pinctrl_select_state_by_ofnode(struct udevice *dev, ofnode node, const char *statename); +#else +static inline int pinctrl_select_state_by_ofnode(struct udevice *dev, + ofnode node, + const char *statename) +{ + return -ENOSYS; +} +#endif + /** * pinctrl_select_state() - Set a device to a given state * @dev: Peripheral device @@ -509,14 +527,10 @@ static inline int pinctrl_generic_set_state(struct udevice *pctldev, * * Return: 0 on success, or negative error code on failure */ -int pinctrl_select_state(struct udevice *dev, const char *statename); -#else -static inline int pinctrl_select_state(struct udevice *dev, - const char *statename) +static inline int pinctrl_select_state(struct udevice *dev, const char *statename) { - return -ENOSYS; + return pinctrl_select_state_by_ofnode(dev, dev_ofnode(dev), statename); } -#endif /** * pinctrl_request() - Request a particular pinctrl function