2019-06-24 13:50:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019
|
|
|
|
* Lukasz Majewski, DENX Software Engineering, lukma@denx.de
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <clk.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <asm/clk.h>
|
|
|
|
#include <dm/test.h>
|
|
|
|
#include <dm/uclass.h>
|
|
|
|
#include <linux/err.h>
|
2020-07-19 16:15:37 +00:00
|
|
|
#include <test/test.h>
|
2019-06-24 13:50:50 +00:00
|
|
|
#include <test/ut.h>
|
|
|
|
#include <sandbox-clk.h>
|
|
|
|
|
|
|
|
/* Tests for Common Clock Framework driver */
|
|
|
|
static int dm_test_clk_ccf(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct clk *clk, *pclk;
|
|
|
|
struct udevice *dev;
|
|
|
|
long long rate;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Get the device using the clk device */
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-ccf", &dev));
|
|
|
|
|
|
|
|
/* Test for clk_get_by_id() */
|
|
|
|
ret = clk_get_by_id(SANDBOX_CLK_ECSPI_ROOT, &clk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str("ecspi_root", clk->dev->name);
|
2020-04-13 12:36:27 +00:00
|
|
|
ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
|
2019-06-24 13:50:50 +00:00
|
|
|
|
|
|
|
/* Test for clk_get_parent_rate() */
|
|
|
|
ret = clk_get_by_id(SANDBOX_CLK_ECSPI1, &clk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str("ecspi1", clk->dev->name);
|
2020-04-13 12:36:27 +00:00
|
|
|
ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
|
2019-06-24 13:50:50 +00:00
|
|
|
|
|
|
|
rate = clk_get_parent_rate(clk);
|
|
|
|
ut_asserteq(rate, 20000000);
|
|
|
|
|
2020-04-13 12:36:26 +00:00
|
|
|
/* test the gate of CCF */
|
|
|
|
ret = clk_get_by_id(SANDBOX_CLK_ECSPI0, &clk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str("ecspi0", clk->dev->name);
|
2020-04-13 12:36:27 +00:00
|
|
|
ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
|
2020-04-13 12:36:26 +00:00
|
|
|
|
|
|
|
rate = clk_get_parent_rate(clk);
|
|
|
|
ut_asserteq(rate, 20000000);
|
|
|
|
|
2019-06-24 13:50:50 +00:00
|
|
|
/* Test the mux of CCF */
|
|
|
|
ret = clk_get_by_id(SANDBOX_CLK_USDHC1_SEL, &clk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str("usdhc1_sel", clk->dev->name);
|
2020-04-13 12:36:27 +00:00
|
|
|
ut_asserteq(CLK_SET_RATE_NO_REPARENT, clk->flags);
|
2019-06-24 13:50:50 +00:00
|
|
|
|
|
|
|
rate = clk_get_parent_rate(clk);
|
|
|
|
ut_asserteq(rate, 60000000);
|
|
|
|
|
2020-06-03 13:36:25 +00:00
|
|
|
rate = clk_get_rate(clk);
|
|
|
|
ut_asserteq(rate, 60000000);
|
|
|
|
|
|
|
|
ret = clk_get_by_id(SANDBOX_CLK_PLL3_80M, &pclk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
|
|
|
|
ret = clk_set_parent(clk, pclk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
|
|
|
|
rate = clk_get_rate(clk);
|
|
|
|
ut_asserteq(rate, 80000000);
|
|
|
|
|
2019-06-24 13:50:50 +00:00
|
|
|
ret = clk_get_by_id(SANDBOX_CLK_USDHC2_SEL, &clk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str("usdhc2_sel", clk->dev->name);
|
2020-04-13 12:36:27 +00:00
|
|
|
ut_asserteq(CLK_SET_RATE_NO_REPARENT, clk->flags);
|
2019-06-24 13:50:50 +00:00
|
|
|
|
|
|
|
rate = clk_get_parent_rate(clk);
|
|
|
|
ut_asserteq(rate, 80000000);
|
|
|
|
|
|
|
|
pclk = clk_get_parent(clk);
|
|
|
|
ut_asserteq_str("pll3_80m", pclk->dev->name);
|
2020-04-13 12:36:27 +00:00
|
|
|
ut_asserteq(CLK_SET_RATE_PARENT, pclk->flags);
|
2019-06-24 13:50:50 +00:00
|
|
|
|
2020-06-03 13:36:25 +00:00
|
|
|
rate = clk_get_rate(clk);
|
|
|
|
ut_asserteq(rate, 80000000);
|
|
|
|
|
|
|
|
ret = clk_get_by_id(SANDBOX_CLK_PLL3_60M, &pclk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
|
|
|
|
ret = clk_set_parent(clk, pclk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
|
|
|
|
rate = clk_get_rate(clk);
|
|
|
|
ut_asserteq(rate, 60000000);
|
|
|
|
|
2019-07-31 07:02:05 +00:00
|
|
|
/* Test the composite of CCF */
|
|
|
|
ret = clk_get_by_id(SANDBOX_CLK_I2C, &clk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str("i2c", clk->dev->name);
|
2020-04-13 12:36:27 +00:00
|
|
|
ut_asserteq(CLK_SET_RATE_UNGATE, clk->flags);
|
2019-07-31 07:02:05 +00:00
|
|
|
|
|
|
|
rate = clk_get_rate(clk);
|
|
|
|
ut_asserteq(rate, 60000000);
|
|
|
|
|
2019-08-21 13:35:19 +00:00
|
|
|
#if CONFIG_IS_ENABLED(CLK_CCF)
|
|
|
|
/* Test clk tree enable/disable */
|
|
|
|
ret = clk_get_by_id(SANDBOX_CLK_I2C_ROOT, &clk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str("i2c_root", clk->dev->name);
|
|
|
|
|
|
|
|
ret = clk_enable(clk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
|
|
|
|
ret = sandbox_clk_enable_count(clk);
|
|
|
|
ut_asserteq(ret, 1);
|
|
|
|
|
|
|
|
ret = clk_get_by_id(SANDBOX_CLK_I2C, &pclk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
|
|
|
|
ret = sandbox_clk_enable_count(pclk);
|
|
|
|
ut_asserteq(ret, 1);
|
|
|
|
|
|
|
|
ret = clk_disable(clk);
|
|
|
|
ut_assertok(ret);
|
|
|
|
|
|
|
|
ret = sandbox_clk_enable_count(clk);
|
|
|
|
ut_asserteq(ret, 0);
|
|
|
|
|
|
|
|
ret = sandbox_clk_enable_count(pclk);
|
|
|
|
ut_asserteq(ret, 0);
|
|
|
|
#endif
|
|
|
|
|
2019-06-24 13:50:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_clk_ccf, UT_TESTF_SCAN_FDT);
|