[U-Boot] [PATCH v2 1/6] clk: add clk_valid()
Fabrice Gasnier
fabrice.gasnier at st.com
Tue Jul 24 14:31:28 UTC 2018
Add clk_valid() to check for optional clocks are valid.
Call clk_valid() in test/dm/clk.c and add relevant test routine to
sandbox clk tests.
Signed-off-by: Fabrice Gasnier <fabrice.gasnier at st.com>
---
Changes in v2:
- add test case for 'clk_valid()', e.g. in test/dm/clk.c and sandbox.
- Update TRUE/FALSE comments to lower case: true/false
---
arch/sandbox/include/asm/clk.h | 8 ++++++++
drivers/clk/clk_sandbox_test.c | 13 +++++++++++++
include/clk.h | 10 ++++++++++
test/dm/clk.c | 1 +
4 files changed, 32 insertions(+)
diff --git a/arch/sandbox/include/asm/clk.h b/arch/sandbox/include/asm/clk.h
index d85cbad..2b1c49f 100644
--- a/arch/sandbox/include/asm/clk.h
+++ b/arch/sandbox/include/asm/clk.h
@@ -138,5 +138,13 @@ int sandbox_clk_test_free(struct udevice *dev);
* @return: 0 if OK, or a negative error code.
*/
int sandbox_clk_test_release_bulk(struct udevice *dev);
+/**
+ * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
+ * clocks are valid.
+ *
+ * @dev: The sandbox clock test (client) devivce.
+ * @return: 0 if OK, or a negative error code.
+ */
+int sandbox_clk_test_valid(struct udevice *dev);
#endif
diff --git a/drivers/clk/clk_sandbox_test.c b/drivers/clk/clk_sandbox_test.c
index 8cd4abb..e8465db 100644
--- a/drivers/clk/clk_sandbox_test.c
+++ b/drivers/clk/clk_sandbox_test.c
@@ -116,6 +116,19 @@ int sandbox_clk_test_release_bulk(struct udevice *dev)
return clk_release_bulk(&sbct->bulk);
}
+int sandbox_clk_test_valid(struct udevice *dev)
+{
+ struct sandbox_clk_test *sbct = dev_get_priv(dev);
+ int i;
+
+ for (i = 0; i < SANDBOX_CLK_TEST_ID_COUNT; i++) {
+ if (!clk_valid(&sbct->clks[i]))
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static const struct udevice_id sandbox_clk_test_ids[] = {
{ .compatible = "sandbox,clk-test" },
{ }
diff --git a/include/clk.h b/include/clk.h
index 9a35764..f6d1cc5 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -294,4 +294,14 @@ int clk_disable_bulk(struct clk_bulk *bulk);
int soc_clk_dump(void);
+/**
+ * clk_valid() - check if clk is valid
+ *
+ * @clk: the clock to check
+ * @return true if valid, or false
+ */
+static inline bool clk_valid(struct clk *clk)
+{
+ return !!clk->dev;
+}
#endif
diff --git a/test/dm/clk.c b/test/dm/clk.c
index b06906a..898c034 100644
--- a/test/dm/clk.c
+++ b/test/dm/clk.c
@@ -28,6 +28,7 @@ static int dm_test_clk(struct unit_test_state *uts)
ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test",
&dev_test));
ut_assertok(sandbox_clk_test_get(dev_test));
+ ut_assertok(sandbox_clk_test_valid(dev_test));
ut_asserteq(1234,
sandbox_clk_test_get_rate(dev_test,
--
1.9.1
More information about the U-Boot
mailing list