UPSTREAM: clk: add clk_valid()

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@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Wu <david.wu@rock-chips.com>
Change-Id: I78b1edea1f8ef54d3aa3f7610d39d79dd994d1bf
This commit is contained in:
Fabrice Gasnier 2018-07-24 16:31:28 +02:00 committed by Jianhong Chen
parent ee601a06f7
commit 827e2ae92e
4 changed files with 32 additions and 0 deletions

View File

@ -139,5 +139,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

View File

@ -117,6 +117,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" },
{ }

View File

@ -317,4 +317,14 @@ int soc_clk_dump(void);
int clks_probe(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

View File

@ -29,6 +29,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,