blob: 242d2d756fd75fd9a3127b9fec294d2d560531a1 [file] [log] [blame]
Lukasz Majewski8c0709b2019-06-24 15:50:50 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
5 */
6
7#include <common.h>
8#include <clk.h>
9#include <dm.h>
10#include <asm/clk.h>
11#include <dm/test.h>
12#include <dm/uclass.h>
13#include <linux/err.h>
Simon Glass75c4d412020-07-19 10:15:37 -060014#include <test/test.h>
Lukasz Majewski8c0709b2019-06-24 15:50:50 +020015#include <test/ut.h>
16#include <sandbox-clk.h>
17
18/* Tests for Common Clock Framework driver */
19static int dm_test_clk_ccf(struct unit_test_state *uts)
20{
21 struct clk *clk, *pclk;
22 struct udevice *dev;
23 long long rate;
24 int ret;
25
26 /* Get the device using the clk device */
27 ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-ccf", &dev));
28
29 /* Test for clk_get_by_id() */
30 ret = clk_get_by_id(SANDBOX_CLK_ECSPI_ROOT, &clk);
31 ut_assertok(ret);
32 ut_asserteq_str("ecspi_root", clk->dev->name);
Dario Binacchi1a62dc12020-04-13 14:36:27 +020033 ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
Lukasz Majewski8c0709b2019-06-24 15:50:50 +020034
35 /* Test for clk_get_parent_rate() */
36 ret = clk_get_by_id(SANDBOX_CLK_ECSPI1, &clk);
37 ut_assertok(ret);
38 ut_asserteq_str("ecspi1", clk->dev->name);
Dario Binacchi1a62dc12020-04-13 14:36:27 +020039 ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
Lukasz Majewski8c0709b2019-06-24 15:50:50 +020040
41 rate = clk_get_parent_rate(clk);
42 ut_asserteq(rate, 20000000);
43
Dario Binacchic98b8022020-04-13 14:36:26 +020044 /* test the gate of CCF */
45 ret = clk_get_by_id(SANDBOX_CLK_ECSPI0, &clk);
46 ut_assertok(ret);
47 ut_asserteq_str("ecspi0", clk->dev->name);
Dario Binacchi1a62dc12020-04-13 14:36:27 +020048 ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
Dario Binacchic98b8022020-04-13 14:36:26 +020049
50 rate = clk_get_parent_rate(clk);
51 ut_asserteq(rate, 20000000);
52
Lukasz Majewski8c0709b2019-06-24 15:50:50 +020053 /* Test the mux of CCF */
54 ret = clk_get_by_id(SANDBOX_CLK_USDHC1_SEL, &clk);
55 ut_assertok(ret);
56 ut_asserteq_str("usdhc1_sel", clk->dev->name);
Dario Binacchi1a62dc12020-04-13 14:36:27 +020057 ut_asserteq(CLK_SET_RATE_NO_REPARENT, clk->flags);
Lukasz Majewski8c0709b2019-06-24 15:50:50 +020058
59 rate = clk_get_parent_rate(clk);
60 ut_asserteq(rate, 60000000);
61
62 ret = clk_get_by_id(SANDBOX_CLK_USDHC2_SEL, &clk);
63 ut_assertok(ret);
64 ut_asserteq_str("usdhc2_sel", clk->dev->name);
Dario Binacchi1a62dc12020-04-13 14:36:27 +020065 ut_asserteq(CLK_SET_RATE_NO_REPARENT, clk->flags);
Lukasz Majewski8c0709b2019-06-24 15:50:50 +020066
67 rate = clk_get_parent_rate(clk);
68 ut_asserteq(rate, 80000000);
69
70 pclk = clk_get_parent(clk);
71 ut_asserteq_str("pll3_80m", pclk->dev->name);
Dario Binacchi1a62dc12020-04-13 14:36:27 +020072 ut_asserteq(CLK_SET_RATE_PARENT, pclk->flags);
Lukasz Majewski8c0709b2019-06-24 15:50:50 +020073
Peng Fan91f053f2019-07-31 07:02:05 +000074 /* Test the composite of CCF */
75 ret = clk_get_by_id(SANDBOX_CLK_I2C, &clk);
76 ut_assertok(ret);
77 ut_asserteq_str("i2c", clk->dev->name);
Dario Binacchi1a62dc12020-04-13 14:36:27 +020078 ut_asserteq(CLK_SET_RATE_UNGATE, clk->flags);
Peng Fan91f053f2019-07-31 07:02:05 +000079
80 rate = clk_get_rate(clk);
81 ut_asserteq(rate, 60000000);
82
Peng Fan8eec5102019-08-21 13:35:19 +000083#if CONFIG_IS_ENABLED(CLK_CCF)
84 /* Test clk tree enable/disable */
85 ret = clk_get_by_id(SANDBOX_CLK_I2C_ROOT, &clk);
86 ut_assertok(ret);
87 ut_asserteq_str("i2c_root", clk->dev->name);
88
89 ret = clk_enable(clk);
90 ut_assertok(ret);
91
92 ret = sandbox_clk_enable_count(clk);
93 ut_asserteq(ret, 1);
94
95 ret = clk_get_by_id(SANDBOX_CLK_I2C, &pclk);
96 ut_assertok(ret);
97
98 ret = sandbox_clk_enable_count(pclk);
99 ut_asserteq(ret, 1);
100
101 ret = clk_disable(clk);
102 ut_assertok(ret);
103
104 ret = sandbox_clk_enable_count(clk);
105 ut_asserteq(ret, 0);
106
107 ret = sandbox_clk_enable_count(pclk);
108 ut_asserteq(ret, 0);
109#endif
110
Lukasz Majewski8c0709b2019-06-24 15:50:50 +0200111 return 1;
112}
113
Simon Glass974dccd2020-07-28 19:41:12 -0600114DM_TEST(dm_test_clk_ccf, UT_TESTF_SCAN_FDT);