[U-Boot,v2,5/5] test: clk: test clock self assignment
diff mbox series

Message ID 20191022120007.23288-6-jjhiblot@ti.com
State Accepted
Delegated to: Lukasz Majewski
Headers show
Series
  • clk: Add a managed API and fix clock self-assignment
Related show

Commit Message

Jean-Jacques Hiblot Oct. 22, 2019, noon UTC
Make sure that the clock self-assignment works by having a clock of
clk-sbox be configured automatically when clk-sbox is probed.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

---

Changes in v2: None

 arch/sandbox/dts/test.dts |  2 ++
 drivers/clk/clk_sandbox.c | 22 ++++++++++++++++++++++
 test/dm/clk.c             |  4 ++--
 3 files changed, 26 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 0ee86a74ed..c118125169 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -226,6 +226,8 @@ 
 	clk_sandbox: clk-sbox {
 		compatible = "sandbox,clk";
 		#clock-cells = <1>;
+		assigned-clocks = <&clk_sandbox 3>;
+		assigned-clock-rates = <321>;
 	};
 
 	clk-test {
diff --git a/drivers/clk/clk_sandbox.c b/drivers/clk/clk_sandbox.c
index d152fd7e5b..de6b2f7c82 100644
--- a/drivers/clk/clk_sandbox.c
+++ b/drivers/clk/clk_sandbox.c
@@ -10,6 +10,7 @@ 
 #include <asm/clk.h>
 
 struct sandbox_clk_priv {
+	bool probed;
 	ulong rate[SANDBOX_CLK_ID_COUNT];
 	bool enabled[SANDBOX_CLK_ID_COUNT];
 	bool requested[SANDBOX_CLK_ID_COUNT];
@@ -19,6 +20,9 @@  static ulong sandbox_clk_get_rate(struct clk *clk)
 {
 	struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
 
+	if (!priv->probed)
+		return -ENODEV;
+
 	if (clk->id >= SANDBOX_CLK_ID_COUNT)
 		return -EINVAL;
 
@@ -30,6 +34,9 @@  static ulong sandbox_clk_set_rate(struct clk *clk, ulong rate)
 	struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
 	ulong old_rate;
 
+	if (!priv->probed)
+		return -ENODEV;
+
 	if (clk->id >= SANDBOX_CLK_ID_COUNT)
 		return -EINVAL;
 
@@ -46,6 +53,9 @@  static int sandbox_clk_enable(struct clk *clk)
 {
 	struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
 
+	if (!priv->probed)
+		return -ENODEV;
+
 	if (clk->id >= SANDBOX_CLK_ID_COUNT)
 		return -EINVAL;
 
@@ -58,6 +68,9 @@  static int sandbox_clk_disable(struct clk *clk)
 {
 	struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
 
+	if (!priv->probed)
+		return -ENODEV;
+
 	if (clk->id >= SANDBOX_CLK_ID_COUNT)
 		return -EINVAL;
 
@@ -97,6 +110,14 @@  static struct clk_ops sandbox_clk_ops = {
 	.free		= sandbox_clk_free,
 };
 
+static int sandbox_clk_probe(struct udevice *dev)
+{
+	struct sandbox_clk_priv *priv = dev_get_priv(dev);
+
+	priv->probed = true;
+	return 0;
+}
+
 static const struct udevice_id sandbox_clk_ids[] = {
 	{ .compatible = "sandbox,clk" },
 	{ }
@@ -107,6 +128,7 @@  U_BOOT_DRIVER(clk_sandbox) = {
 	.id		= UCLASS_CLK,
 	.of_match	= sandbox_clk_ids,
 	.ops		= &sandbox_clk_ops,
+	.probe		= sandbox_clk_probe,
 	.priv_auto_alloc_size = sizeof(struct sandbox_clk_priv),
 };
 
diff --git a/test/dm/clk.c b/test/dm/clk.c
index 3ad0ad8ca3..31335a543f 100644
--- a/test/dm/clk.c
+++ b/test/dm/clk.c
@@ -74,8 +74,8 @@  static int dm_test_clk(struct unit_test_state *uts)
 						 SANDBOX_CLK_TEST_ID_SPI));
 	ut_asserteq(0, sandbox_clk_test_get_rate(dev_test,
 						 SANDBOX_CLK_TEST_ID_I2C));
-	ut_asserteq(0, sandbox_clk_test_get_rate(dev_test,
-						 SANDBOX_CLK_TEST_ID_DEVM1));
+	ut_asserteq(321, sandbox_clk_test_get_rate(dev_test,
+						   SANDBOX_CLK_TEST_ID_DEVM1));
 	ut_asserteq(0, sandbox_clk_test_get_rate(dev_test,
 						 SANDBOX_CLK_TEST_ID_DEVM2));