devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeremy Kerr <jk@codeconstruct.com.au>
To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Lee Jones <lee@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Philipp Zabel <p.zabel@pengutronix.de>
Subject: [RFC PATCH 2/2] mfd: syscon: allow reset control for syscon devices
Date: Tue,  6 Dec 2022 15:39:16 +0800	[thread overview]
Message-ID: <20221206073916.1606125-3-jk@codeconstruct.com.au> (raw)
In-Reply-To: <20221206073916.1606125-1-jk@codeconstruct.com.au>

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 <jk@codeconstruct.com.au>
---
 drivers/mfd/syscon.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index bdb2ce7ff03b..a0483dbfe17a 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -20,6 +20,7 @@
 #include <linux/platform_data/syscon.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
+#include <linux/reset.h>
 #include <linux/mfd/syscon.h>
 #include <linux/slab.h>
 
@@ -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;
 };
 
@@ -280,6 +282,7 @@ static int syscon_probe(struct platform_device *pdev)
 	struct regmap_config syscon_config = syscon_regmap_config;
 	struct resource *res;
 	void __iomem *base;
+	int rc;
 
 	syscon = devm_kzalloc(dev, sizeof(*syscon), GFP_KERNEL);
 	if (!syscon)
@@ -302,13 +305,32 @@ static int syscon_probe(struct platform_device *pdev)
 		return PTR_ERR(syscon->regmap);
 	}
 
+	syscon->reset = devm_reset_control_get_optional_exclusive(&pdev->dev,
+								  "reset");
+	if (IS_ERR(syscon->reset))
+		return PTR_ERR(syscon->reset);
+
 	platform_set_drvdata(pdev, syscon);
 
+	rc = reset_control_deassert(syscon->reset);
+	if (rc) {
+		dev_err(dev, "failed to deassert reset line! rc: %d\n", rc);
+		return rc;
+	}
+
 	dev_dbg(dev, "regmap %pR registered\n", res);
 
 	return 0;
 }
 
+static int syscon_remove(struct platform_device *pdev)
+{
+	struct syscon *syscon = platform_get_drvdata(pdev);
+
+	reset_control_assert(syscon->reset);
+	return 0;
+}
+
 static const struct platform_device_id syscon_ids[] = {
 	{ "syscon", },
 	{ }
@@ -319,6 +341,7 @@ static struct platform_driver syscon_driver = {
 		.name = "syscon",
 	},
 	.probe		= syscon_probe,
+	.remove		= syscon_remove,
 	.id_table	= syscon_ids,
 };
 
-- 
2.35.1


  parent reply	other threads:[~2022-12-06  7:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-06  7:39 [RFC PATCH 0/2] Add reset control for mfd syscon devices Jeremy Kerr
2022-12-06  7:39 ` [RFC PATCH 1/2] dt-bindings: mfd/syscon: Add resets property Jeremy Kerr
2022-12-06 13:09   ` Rob Herring
2022-12-06  7:39 ` Jeremy Kerr [this message]
2022-12-06  8:41   ` [RFC PATCH 2/2] mfd: syscon: allow reset control for syscon devices Arnd Bergmann
2022-12-06  9:25     ` Philipp Zabel
2022-12-06 14:18       ` Arnd Bergmann
2022-12-07  7:56         ` Jeremy Kerr
2022-12-07  8:59           ` Arnd Bergmann
2022-12-07  9:28             ` Jeremy Kerr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221206073916.1606125-3-jk@codeconstruct.com.au \
    --to=jk@codeconstruct.com.au \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).