From: Tony Lindgren <tony@atomide.com>
To: linux-omap@vger.kernel.org
Cc: Dhruva Gole <d-gole@ti.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Philipp Zabel <p.zabel@pengutronix.de>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: [RFC PATCH 3/4] bus: ti-sysc: Implement reset control framework for soft reset
Date: Thu, 11 Apr 2024 08:22:56 +0300 [thread overview]
Message-ID: <20240411052257.2113-4-tony@atomide.com> (raw)
In-Reply-To: <20240411052257.2113-1-tony@atomide.com>
We can implement reset control framework for ti-sysc for the connected
devices to use for the interconnect target reset.
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
drivers/bus/ti-sysc.c | 109 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 109 insertions(+)
diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c
--- a/drivers/bus/ti-sysc.c
+++ b/drivers/bus/ti-sysc.c
@@ -25,6 +25,7 @@
#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>
#include <linux/reset.h>
+#include <linux/reset-controller.h>
#include <linux/of_address.h>
#include <linux/of_platform.h>
#include <linux/slab.h>
@@ -42,6 +43,7 @@
#define SOC_FLAG(match, flag) { .machine = match, .data = (void *)(flag), }
+#define TI_SYSC_SOFTRESET_ID 0
#define MAX_MODULE_SOFTRESET_WAIT 10000
enum sysc_soc {
@@ -79,6 +81,11 @@ struct sysc_soc_info {
struct notifier_block nb;
};
+struct sysc_reset_lookup {
+ struct list_head node;
+ struct reset_control_lookup lookup;
+};
+
enum sysc_clocks {
SYSC_FCK,
SYSC_ICK,
@@ -147,6 +154,9 @@ struct sysc {
const char **clock_roles;
int nr_clocks;
struct reset_control *rsts;
+ struct reset_controller_dev rcdev;
+ struct list_head child_resets;
+ struct mutex child_lock; /* child device data list lock */
const char *legacy_mode;
const struct sysc_capabilities *cap;
struct sysc_config cfg;
@@ -2194,6 +2204,46 @@ static int sysc_reset(struct sysc *ddata)
return error;
}
+/*
+ * Only handles the softreset for the interconnect target, does not consider
+ * the device specific external resets. We must ensure the interconnect target
+ * is runtime PM active for the reset. And we must restore the sysconfig
+ * register after reset. Locking is currently not needed as we only touch the
+ * sysconfig register on PM runtime state changes, and no other sysconfig
+ * register access happens when the interconnect target is runtime PM active.
+ * Interconnect targets with multiple children must coordinate the reset
+ * usage with reset_control_get_shared().
+ */
+static int ti_sysc_reset_control_reset(struct reset_controller_dev *rcdev,
+ unsigned long id)
+{
+ struct sysc *ddata;
+ int error;
+
+ if (id != TI_SYSC_SOFTRESET_ID)
+ return -EINVAL;
+
+ ddata = container_of(rcdev, struct sysc, rcdev);
+
+ error = pm_runtime_resume_and_get(ddata->dev);
+ if (error < 0)
+ return error;
+
+ error = sysc_reset(ddata);
+ if (error)
+ dev_warn(ddata->dev, "reset failed: %i\n", error);
+
+ sysc_write_sysconfig(ddata, ddata->sysconfig);
+
+ pm_runtime_put_sync(ddata->dev);
+
+ return error;
+}
+
+static const struct reset_control_ops ti_sysc_reset_ops = {
+ .reset = ti_sysc_reset_control_reset,
+};
+
/*
* At this point the module is configured enough to read the revision but
* module may not be completely configured yet to use PM runtime. Enable
@@ -2408,6 +2458,45 @@ static int sysc_child_add_clocks(struct sysc *ddata,
return 0;
}
+static int sysc_child_add_reset(struct sysc *ddata,
+ struct device *child)
+{
+ struct sysc_reset_lookup *srl;
+
+ srl = kzalloc(sizeof(*srl), GFP_KERNEL);
+ if (!srl)
+ return -ENOMEM;
+
+ srl->lookup.provider = dev_name(ddata->dev);
+ srl->lookup.index = TI_SYSC_SOFTRESET_ID;
+ srl->lookup.dev_id = dev_name(child);
+ srl->lookup.con_id = "softreset";
+ reset_controller_add_lookup(&srl->lookup, 1);
+ mutex_lock(&ddata->child_lock);
+ list_add(&srl->node, &ddata->child_resets);
+ mutex_unlock(&ddata->child_lock);
+
+ return 0;
+}
+
+static void sysc_child_remove_reset(struct sysc *ddata,
+ struct device *child)
+{
+ struct sysc_reset_lookup *srl;
+
+ mutex_lock(&ddata->child_lock);
+ list_for_each_entry(srl, &ddata->child_resets, node) {
+ if (srl->lookup.index == TI_SYSC_SOFTRESET_ID &&
+ !strcmp(dev_name(child), srl->lookup.dev_id)) {
+ reset_controller_remove_lookup(&srl->lookup, 1);
+ list_del(&srl->node);
+ kfree(srl);
+ break;
+ }
+ }
+ mutex_unlock(&ddata->child_lock);
+}
+
static const struct device_type sysc_device_type = {
};
@@ -2541,6 +2630,14 @@ static int sysc_notifier_call(struct notifier_block *nb,
error = sysc_child_add_clocks(ddata, dev);
if (error)
return error;
+
+ error = sysc_child_add_reset(ddata, dev);
+ if (error)
+ return error;
+
+ break;
+ case BUS_NOTIFY_REMOVED_DEVICE:
+ sysc_child_remove_reset(ddata, dev);
break;
default:
break;
@@ -3186,6 +3283,8 @@ static int sysc_probe(struct platform_device *pdev)
ddata->offsets[SYSC_SYSCONFIG] = -ENODEV;
ddata->offsets[SYSC_SYSSTATUS] = -ENODEV;
ddata->dev = &pdev->dev;
+ mutex_init(&ddata->child_lock);
+ INIT_LIST_HEAD(&ddata->child_resets);
platform_set_drvdata(pdev, ddata);
error = sysc_init_static_data(ddata);
@@ -3266,6 +3365,16 @@ static int sysc_probe(struct platform_device *pdev)
ddata->dev->type = &sysc_device_type;
+ ddata->rcdev.owner = THIS_MODULE;
+ ddata->rcdev.nr_resets = 1;
+ ddata->rcdev.ops = &ti_sysc_reset_ops;
+ ddata->rcdev.dev = &pdev->dev;
+ ddata->rcdev.of_node = ddata->dev->of_node;
+
+ error = devm_reset_controller_register(ddata->dev, &ddata->rcdev);
+ if (error)
+ goto err;
+
if (!ddata->reserved) {
error = of_platform_populate(ddata->dev->of_node,
sysc_match_table,
--
2.44.0
next prev parent reply other threads:[~2024-04-11 5:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-11 5:22 [RFC PATCH 0/4] Provide interconnect resets for ti-sysc users Tony Lindgren
2024-04-11 5:22 ` [RFC PATCH 1/4] reset: Fall back to lookup if no reset node is found Tony Lindgren
2024-04-11 5:22 ` [RFC PATCH 2/4] reset: Allow removing a lookup Tony Lindgren
2024-04-11 5:22 ` Tony Lindgren [this message]
2024-04-11 5:22 ` [RFC PATCH 4/4] serial: 8250: omap: Use reset control for resets Tony Lindgren
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=20240411052257.2113-4-tony@atomide.com \
--to=tony@atomide.com \
--cc=d-gole@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.