From: Kishon Vijay Abraham I <kishon@ti.com>
To: Lokesh Vutla <lokeshvutla@ti.com>, Simon Glass <sjg@chromium.org>
Cc: Kishon Vijay Abraham I <kishon@ti.com>,
Aswath Govindraju <a-govindraju@ti.com>,
Pratyush Yadav <p.yadav@ti.com>, <u-boot@lists.denx.de>
Subject: [PATCH v4 01/21] drivers: reset: Add devm_to_reset() to return dummy "struct reset_ctl"
Date: Mon, 12 Jul 2021 11:50:05 +0530 [thread overview]
Message-ID: <20210712062025.14518-2-kishon@ti.com> (raw)
In-Reply-To: <20210712062025.14518-1-kishon@ti.com>
Add devm_to_reset() to return dummy "struct reset_ctl", useful for
invoking reset APIs which doesn't have a valid "struct reset_ctl".
Suggested-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
drivers/reset/reset-uclass.c | 16 ++++++++++++++++
drivers/reset/sandbox-reset-test.c | 4 +++-
include/reset.h | 17 +++++++++++++++++
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
index 8caa616ed9..9f2eeb4fe4 100644
--- a/drivers/reset/reset-uclass.c
+++ b/drivers/reset/reset-uclass.c
@@ -15,6 +15,8 @@
#include <dm/devres.h>
#include <dm/lists.h>
+static struct reset_ctl devm_no_reset;
+
static inline struct reset_ops *reset_dev_ops(struct udevice *dev)
{
return (struct reset_ops *)dev->driver->ops;
@@ -256,6 +258,20 @@ int reset_release_all(struct reset_ctl *reset_ctl, int count)
return 0;
}
+int devm_to_reset(struct reset_ctl *in, struct reset_ctl **outp)
+{
+ if (IS_ERR_OR_NULL(in)) {
+ *outp = &devm_no_reset;
+ if (!in)
+ return -ENOENT;
+ else
+ return PTR_ERR(in);
+ }
+ *outp = in;
+
+ return 0;
+}
+
static void devm_reset_release(struct udevice *dev, void *res)
{
reset_free(res);
diff --git a/drivers/reset/sandbox-reset-test.c b/drivers/reset/sandbox-reset-test.c
index 51b79810c8..4389bde5e7 100644
--- a/drivers/reset/sandbox-reset-test.c
+++ b/drivers/reset/sandbox-reset-test.c
@@ -32,13 +32,15 @@ int sandbox_reset_test_get_devm(struct udevice *dev)
{
struct sandbox_reset_test *sbrt = dev_get_priv(dev);
struct reset_ctl *r;
+ int ret;
r = devm_reset_control_get(dev, "not-a-valid-reset-ctl");
if (!IS_ERR(r))
return -EINVAL;
r = devm_reset_control_get_optional(dev, "not-a-valid-reset-ctl");
- if (r)
+ ret = devm_to_reset(r, &r);
+ if (reset_valid(r))
return -EINVAL;
sbrt->ctlp = devm_reset_control_get(dev, "test");
diff --git a/include/reset.h b/include/reset.h
index cde2c4b4a8..21affc1455 100644
--- a/include/reset.h
+++ b/include/reset.h
@@ -341,6 +341,18 @@ int reset_status(struct reset_ctl *reset_ctl);
*/
int reset_release_all(struct reset_ctl *reset_ctl, int count);
+/**
+ * devm_to_reset - Provide a dummy reset_ctl for invalid reset_ctl
+ *
+ * Provide a dummy reset_ctl for invalid reset_ctl or give the same
+ * input reset_ctl
+ *
+ * @in: Input reset_ctl returned by devm_reset_control_get()
+ * @outp: Dummy reset_ctl for invalid reset_ctl or Input reset_ctl
+ * @return 0 if OK, or a negative error code.
+ */
+int devm_to_reset(struct reset_ctl *in, struct reset_ctl **outp);
+
/**
* reset_release_bulk - Assert/Free an array of previously requested reset
* signals in a reset control bulk struct.
@@ -456,6 +468,11 @@ static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
{
return 0;
}
+
+static inline int devm_to_reset(struct reset_ctl *in, struct reset_ctl **outp)
+{
+ return 0;
+}
#endif
/**
--
2.17.1
next prev parent reply other threads:[~2021-07-12 6:20 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-12 6:20 [PATCH v4 00/21] TI/Cadence: Add Sierra/Torrent SERDES driver Kishon Vijay Abraham I
2021-07-12 6:20 ` Kishon Vijay Abraham I [this message]
2021-07-20 18:32 ` [PATCH v4 01/21] drivers: reset: Add devm_to_reset() to return dummy "struct reset_ctl" Simon Glass
2021-07-21 12:16 ` Kishon Vijay Abraham I
2021-07-24 17:22 ` Simon Glass
2021-07-12 6:20 ` [PATCH v4 02/21] dm: core: Add helper to compare node names Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 03/21] dm: test: Add test case to check node name ignoring unit address Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 04/21] dt-bindings: phy: Add definitions for additional phy types Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 05/21] dt-bindings: phy: Add defines for AM64 SERDES Wrapper Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 06/21] dt-bindings: phy: cadence-torrent: Add defines for refclk driver Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 07/21] dt-bindings: ti-serdes-mux: Add defines for AM64 SoC Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 08/21] phy: cadence: Add driver for Sierra PHY Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 09/21] phy: cadence: Add driver for Torrent SERDES Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 10/21] phy: ti: j721e-wiz: Add support for WIZ module present in TI J721E SoC Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 11/21] board: ti: j721e: Add support for probing and configuring Torrent serdes on J7200 Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 12/21] ARM: dts: k3-j721e: Add support for USB3 in USB0 instance Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 13/21] arm: dts: k3-j7200-main: Add DT node for torrent serdes Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 14/21] arm: dts: k3-j7200-common-proc-board: Enable SERDES DT Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 15/21] arm: dts: k3-j7200-common-proc-board-u-boot: Add u-boot tags for torrent serdes Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 16/21] configs: j721e_evm_a72: Enable the drivers required for the USB3 support Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 17/21] configs: j7200_evm_a72_defconfig: Add config for torrent serdes and common clock framework Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 18/21] env: ti: j721e-evm: Add env variable to power on & reset QSGMII PHY in J7200 EVM Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 19/21] configs: j7200_evm_a72: Add CONFIG_PREBOOT to configure ethernet PHY Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 20/21] doc: board: Move j721e document to doc/board/ti/ directory Kishon Vijay Abraham I
2021-07-13 19:18 ` Tom Rini
2021-07-14 6:40 ` Kishon Vijay Abraham I
2021-07-12 6:20 ` [PATCH v4 21/21] doc: board: j721e_evm: Add documentation for firmware loading Kishon Vijay Abraham I
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=20210712062025.14518-2-kishon@ti.com \
--to=kishon@ti.com \
--cc=a-govindraju@ti.com \
--cc=lokeshvutla@ti.com \
--cc=p.yadav@ti.com \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox