From patchwork Fri Dec 9 01:33:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 632572 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4254AC001B2 for ; Fri, 9 Dec 2022 01:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229843AbiLIBdc (ORCPT ); Thu, 8 Dec 2022 20:33:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbiLIBd3 (ORCPT ); Thu, 8 Dec 2022 20:33:29 -0500 Received: from codeconstruct.com.au (pi.codeconstruct.com.au [203.29.241.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8D2A86F66; Thu, 8 Dec 2022 17:33:27 -0800 (PST) Received: by codeconstruct.com.au (Postfix, from userid 10000) id DAF5B21689; Fri, 9 Dec 2022 09:33:22 +0800 (AWST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1670549602; bh=arOEJsM/yx+o1Y+f81ge85whdOVlDOd7/7bivSC46z8=; h=From:To:Subject:Date:In-Reply-To:References; b=YLyrgmMag9QrLadwsXZCXpKtNZ9cAdK3Miagysxb39wkRrREMV6fQC6Nj5PBcngt+ WPTa1D9q3HdJN4pDzJKHi7VyRwqLN5PekDCvTPaywzl4rjshJBp78QjE7o0wzXSbBo k4rL58FSDnFa0fwQCOfY1gB3w78ZkSLEzLalcYX2c8Mlc6ZrlD+QxE4oWFN4mAUrf1 K4sri46vNwpb842p5h4ulUTE0fwqJPCYXzCb+bAgSzenusjDIhdFVezab8pV08hZxf ikWS3a13GGLepRIt6c65EJAniQwK65uLuq5Cmel+wTqpm7U91ITBduSJuFrqHP4kVV 65efjLWTFHVfw== From: Jeremy Kerr To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Lee Jones , Rob Herring , Krzysztof Kozlowski , Arnd Bergmann , Philipp Zabel , Mark Brown Subject: [RFC PATCH v2 3/3] mfd: syscon: allow reset control for syscon devices Date: Fri, 9 Dec 2022 09:33:09 +0800 Message-Id: <20221209013309.407879-4-jk@codeconstruct.com.au> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221209013309.407879-1-jk@codeconstruct.com.au> References: <20221209013309.407879-1-jk@codeconstruct.com.au> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Simple syscon devices may require deassertion of a reset signal in order to access their register set. Rather than requiring a custom driver to implement this, we can use the generic "resets" specifiers to link a reset line to the syscon. This change adds an optional reset line to the syscon device description, and code to perform the deassertion/assertion on probe/remove. Signed-off-by: Jeremy Kerr --- v2: * do reset control in the early of_syscon_register() path, rather than the platform device init, which isn't used. --- drivers/mfd/syscon.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index bdb2ce7ff03b..6b99488d05a6 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,7 @@ static LIST_HEAD(syscon_list); struct syscon { struct device_node *np; struct regmap *regmap; + struct reset_control *reset; struct list_head list; }; @@ -40,7 +42,7 @@ static const struct regmap_config syscon_regmap_config = { .reg_stride = 4, }; -static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) +static struct syscon *of_syscon_register(struct device_node *np, bool check_res) { struct clk *clk; struct syscon *syscon; @@ -50,6 +52,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) int ret; struct regmap_config syscon_config = syscon_regmap_config; struct resource res; + struct reset_control *reset; syscon = kzalloc(sizeof(*syscon), GFP_KERNEL); if (!syscon) @@ -114,7 +117,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) goto err_regmap; } - if (check_clk) { + if (check_res) { clk = of_clk_get(np, 0); if (IS_ERR(clk)) { ret = PTR_ERR(clk); @@ -124,7 +127,17 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) } else { ret = regmap_mmio_attach_clk(regmap, clk); if (ret) - goto err_attach; + goto err_attach_clk; + } + + reset = of_reset_control_get_optional_exclusive(np, NULL); + if (IS_ERR(reset)) { + ret = PTR_ERR(reset); + goto err_attach_clk; + } else if (reset) { + ret = regmap_mmio_attach_reset(regmap, reset); + if (ret) + goto err_attach_reset; } } @@ -137,7 +150,9 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) return syscon; -err_attach: +err_attach_reset: + reset_control_put(reset); +err_attach_clk: if (!IS_ERR(clk)) clk_put(clk); err_clk: @@ -150,7 +165,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) } static struct regmap *device_node_get_regmap(struct device_node *np, - bool check_clk) + bool check_res) { struct syscon *entry, *syscon = NULL; @@ -165,7 +180,7 @@ static struct regmap *device_node_get_regmap(struct device_node *np, spin_unlock(&syscon_list_slock); if (!syscon) - syscon = of_syscon_register(np, check_clk); + syscon = of_syscon_register(np, check_res); if (IS_ERR(syscon)) return ERR_CAST(syscon);