test: clk: test clock self assignment

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>
This commit is contained in:
Jean-Jacques Hiblot 2019-10-22 14:00:07 +02:00 committed by Lukasz Majewski
parent fd1ba29652
commit 9a52be129c
3 changed files with 26 additions and 2 deletions

View File

@ -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 {

View File

@ -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),
};

View File

@ -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));