xref: /linux/drivers/clk/clk-fixed-rate_test.c (revision 5776526beb9513a6593250f742cbc634b17711eb)
1*5776526bSStephen Boyd // SPDX-License-Identifier: GPL-2.0
2*5776526bSStephen Boyd /*
3*5776526bSStephen Boyd  * KUnit test for clk fixed rate basic type
4*5776526bSStephen Boyd  */
5*5776526bSStephen Boyd #include <linux/clk.h>
6*5776526bSStephen Boyd #include <linux/clk-provider.h>
7*5776526bSStephen Boyd #include <linux/completion.h>
8*5776526bSStephen Boyd #include <linux/of.h>
9*5776526bSStephen Boyd #include <linux/platform_device.h>
10*5776526bSStephen Boyd 
11*5776526bSStephen Boyd #include <kunit/clk.h>
12*5776526bSStephen Boyd #include <kunit/of.h>
13*5776526bSStephen Boyd #include <kunit/platform_device.h>
14*5776526bSStephen Boyd #include <kunit/resource.h>
15*5776526bSStephen Boyd #include <kunit/test.h>
16*5776526bSStephen Boyd 
17*5776526bSStephen Boyd #include "clk-fixed-rate_test.h"
18*5776526bSStephen Boyd 
19*5776526bSStephen Boyd /**
20*5776526bSStephen Boyd  * struct clk_hw_fixed_rate_kunit_params - Parameters to pass to __clk_hw_register_fixed_rate()
21*5776526bSStephen Boyd  * @dev: device registering clk
22*5776526bSStephen Boyd  * @np: device_node of device registering clk
23*5776526bSStephen Boyd  * @name: name of clk
24*5776526bSStephen Boyd  * @parent_name: parent name of clk
25*5776526bSStephen Boyd  * @parent_hw: clk_hw pointer to parent of clk
26*5776526bSStephen Boyd  * @parent_data: parent_data describing parent of clk
27*5776526bSStephen Boyd  * @flags: clk framework flags
28*5776526bSStephen Boyd  * @fixed_rate: frequency of clk
29*5776526bSStephen Boyd  * @fixed_accuracy: accuracy of clk
30*5776526bSStephen Boyd  * @clk_fixed_flags: fixed rate specific clk flags
31*5776526bSStephen Boyd  */
32*5776526bSStephen Boyd struct clk_hw_fixed_rate_kunit_params {
33*5776526bSStephen Boyd 	struct device *dev;
34*5776526bSStephen Boyd 	struct device_node *np;
35*5776526bSStephen Boyd 	const char *name;
36*5776526bSStephen Boyd 	const char *parent_name;
37*5776526bSStephen Boyd 	const struct clk_hw *parent_hw;
38*5776526bSStephen Boyd 	const struct clk_parent_data *parent_data;
39*5776526bSStephen Boyd 	unsigned long flags;
40*5776526bSStephen Boyd 	unsigned long fixed_rate;
41*5776526bSStephen Boyd 	unsigned long fixed_accuracy;
42*5776526bSStephen Boyd 	unsigned long clk_fixed_flags;
43*5776526bSStephen Boyd };
44*5776526bSStephen Boyd 
45*5776526bSStephen Boyd static int
46*5776526bSStephen Boyd clk_hw_register_fixed_rate_kunit_init(struct kunit_resource *res, void *context)
47*5776526bSStephen Boyd {
48*5776526bSStephen Boyd 	struct clk_hw_fixed_rate_kunit_params *params = context;
49*5776526bSStephen Boyd 	struct clk_hw *hw;
50*5776526bSStephen Boyd 
51*5776526bSStephen Boyd 	hw = __clk_hw_register_fixed_rate(params->dev, params->np,
52*5776526bSStephen Boyd 					  params->name,
53*5776526bSStephen Boyd 					  params->parent_name,
54*5776526bSStephen Boyd 					  params->parent_hw,
55*5776526bSStephen Boyd 					  params->parent_data,
56*5776526bSStephen Boyd 					  params->flags,
57*5776526bSStephen Boyd 					  params->fixed_rate,
58*5776526bSStephen Boyd 					  params->fixed_accuracy,
59*5776526bSStephen Boyd 					  params->clk_fixed_flags,
60*5776526bSStephen Boyd 					  false);
61*5776526bSStephen Boyd 	if (IS_ERR(hw))
62*5776526bSStephen Boyd 		return PTR_ERR(hw);
63*5776526bSStephen Boyd 
64*5776526bSStephen Boyd 	res->data = hw;
65*5776526bSStephen Boyd 
66*5776526bSStephen Boyd 	return 0;
67*5776526bSStephen Boyd }
68*5776526bSStephen Boyd 
69*5776526bSStephen Boyd static void clk_hw_register_fixed_rate_kunit_exit(struct kunit_resource *res)
70*5776526bSStephen Boyd {
71*5776526bSStephen Boyd 	struct clk_hw *hw = res->data;
72*5776526bSStephen Boyd 
73*5776526bSStephen Boyd 	clk_hw_unregister_fixed_rate(hw);
74*5776526bSStephen Boyd }
75*5776526bSStephen Boyd 
76*5776526bSStephen Boyd /**
77*5776526bSStephen Boyd  * clk_hw_register_fixed_rate_kunit() - Test managed __clk_hw_register_fixed_rate()
78*5776526bSStephen Boyd  * @test: The test context
79*5776526bSStephen Boyd  * @params: Arguments to __clk_hw_register_fixed_rate()
80*5776526bSStephen Boyd  *
81*5776526bSStephen Boyd  * Return: Registered fixed rate clk_hw or ERR_PTR on failure
82*5776526bSStephen Boyd  */
83*5776526bSStephen Boyd static struct clk_hw *
84*5776526bSStephen Boyd clk_hw_register_fixed_rate_kunit(struct kunit *test,
85*5776526bSStephen Boyd 				 struct clk_hw_fixed_rate_kunit_params *params)
86*5776526bSStephen Boyd {
87*5776526bSStephen Boyd 	struct clk_hw *hw;
88*5776526bSStephen Boyd 
89*5776526bSStephen Boyd 	hw = kunit_alloc_resource(test,
90*5776526bSStephen Boyd 				  clk_hw_register_fixed_rate_kunit_init,
91*5776526bSStephen Boyd 				  clk_hw_register_fixed_rate_kunit_exit,
92*5776526bSStephen Boyd 				  GFP_KERNEL, params);
93*5776526bSStephen Boyd 	if (!hw)
94*5776526bSStephen Boyd 		return ERR_PTR(-EINVAL);
95*5776526bSStephen Boyd 
96*5776526bSStephen Boyd 	return hw;
97*5776526bSStephen Boyd }
98*5776526bSStephen Boyd 
99*5776526bSStephen Boyd /**
100*5776526bSStephen Boyd  * clk_hw_unregister_fixed_rate_kunit() - Test managed clk_hw_unregister_fixed_rate()
101*5776526bSStephen Boyd  * @test: The test context
102*5776526bSStephen Boyd  * @hw: fixed rate clk to unregister upon test completion
103*5776526bSStephen Boyd  *
104*5776526bSStephen Boyd  * Automatically unregister @hw when @test is complete via
105*5776526bSStephen Boyd  * clk_hw_unregister_fixed_rate().
106*5776526bSStephen Boyd  *
107*5776526bSStephen Boyd  * Return: 0 on success or negative errno on failure
108*5776526bSStephen Boyd  */
109*5776526bSStephen Boyd static int clk_hw_unregister_fixed_rate_kunit(struct kunit *test, struct clk_hw *hw)
110*5776526bSStephen Boyd {
111*5776526bSStephen Boyd 	if (!kunit_alloc_resource(test, NULL,
112*5776526bSStephen Boyd 				  clk_hw_register_fixed_rate_kunit_exit,
113*5776526bSStephen Boyd 				  GFP_KERNEL, hw))
114*5776526bSStephen Boyd 		return -ENOMEM;
115*5776526bSStephen Boyd 
116*5776526bSStephen Boyd 	return 0;
117*5776526bSStephen Boyd }
118*5776526bSStephen Boyd 
119*5776526bSStephen Boyd /*
120*5776526bSStephen Boyd  * Test that clk_get_rate() on a fixed rate clk registered with
121*5776526bSStephen Boyd  * clk_hw_register_fixed_rate() gets the proper frequency.
122*5776526bSStephen Boyd  */
123*5776526bSStephen Boyd static void clk_fixed_rate_rate_test(struct kunit *test)
124*5776526bSStephen Boyd {
125*5776526bSStephen Boyd 	struct clk_hw *hw;
126*5776526bSStephen Boyd 	struct clk *clk;
127*5776526bSStephen Boyd 	const unsigned long fixed_rate = 230000;
128*5776526bSStephen Boyd 
129*5776526bSStephen Boyd 	hw = clk_hw_register_fixed_rate(NULL, "test-fixed-rate", NULL, 0, fixed_rate);
130*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
131*5776526bSStephen Boyd 	KUNIT_ASSERT_EQ(test, 0, clk_hw_unregister_fixed_rate_kunit(test, hw));
132*5776526bSStephen Boyd 
133*5776526bSStephen Boyd 	clk = clk_hw_get_clk_prepared_enabled_kunit(test, hw, __func__);
134*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, clk);
135*5776526bSStephen Boyd 
136*5776526bSStephen Boyd 	KUNIT_EXPECT_EQ(test, fixed_rate, clk_get_rate(clk));
137*5776526bSStephen Boyd }
138*5776526bSStephen Boyd 
139*5776526bSStephen Boyd /*
140*5776526bSStephen Boyd  * Test that clk_get_accuracy() on a fixed rate clk registered via
141*5776526bSStephen Boyd  * clk_hw_register_fixed_rate_with_accuracy() gets the proper accuracy.
142*5776526bSStephen Boyd  */
143*5776526bSStephen Boyd static void clk_fixed_rate_accuracy_test(struct kunit *test)
144*5776526bSStephen Boyd {
145*5776526bSStephen Boyd 	struct clk_hw *hw;
146*5776526bSStephen Boyd 	struct clk *clk;
147*5776526bSStephen Boyd 	const unsigned long fixed_accuracy = 5000;
148*5776526bSStephen Boyd 
149*5776526bSStephen Boyd 	hw = clk_hw_register_fixed_rate_with_accuracy(NULL, "test-fixed-rate",
150*5776526bSStephen Boyd 						      NULL, 0, 0,
151*5776526bSStephen Boyd 						      fixed_accuracy);
152*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
153*5776526bSStephen Boyd 	KUNIT_ASSERT_EQ(test, 0, clk_hw_unregister_fixed_rate_kunit(test, hw));
154*5776526bSStephen Boyd 
155*5776526bSStephen Boyd 	clk = clk_hw_get_clk_kunit(test, hw, __func__);
156*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, clk);
157*5776526bSStephen Boyd 
158*5776526bSStephen Boyd 	KUNIT_EXPECT_EQ(test, fixed_accuracy, clk_get_accuracy(clk));
159*5776526bSStephen Boyd }
160*5776526bSStephen Boyd 
161*5776526bSStephen Boyd /* Test suite for a fixed rate clk without any parent */
162*5776526bSStephen Boyd static struct kunit_case clk_fixed_rate_test_cases[] = {
163*5776526bSStephen Boyd 	KUNIT_CASE(clk_fixed_rate_rate_test),
164*5776526bSStephen Boyd 	KUNIT_CASE(clk_fixed_rate_accuracy_test),
165*5776526bSStephen Boyd 	{}
166*5776526bSStephen Boyd };
167*5776526bSStephen Boyd 
168*5776526bSStephen Boyd static struct kunit_suite clk_fixed_rate_suite = {
169*5776526bSStephen Boyd 	.name = "clk_fixed_rate",
170*5776526bSStephen Boyd 	.test_cases = clk_fixed_rate_test_cases,
171*5776526bSStephen Boyd };
172*5776526bSStephen Boyd 
173*5776526bSStephen Boyd /*
174*5776526bSStephen Boyd  * Test that clk_get_parent() on a fixed rate clk gets the proper parent.
175*5776526bSStephen Boyd  */
176*5776526bSStephen Boyd static void clk_fixed_rate_parent_test(struct kunit *test)
177*5776526bSStephen Boyd {
178*5776526bSStephen Boyd 	struct clk_hw *hw, *parent_hw;
179*5776526bSStephen Boyd 	struct clk *expected_parent, *actual_parent;
180*5776526bSStephen Boyd 	struct clk *clk;
181*5776526bSStephen Boyd 	const char *parent_name = "test-fixed-rate-parent";
182*5776526bSStephen Boyd 	struct clk_hw_fixed_rate_kunit_params parent_params = {
183*5776526bSStephen Boyd 		.name = parent_name,
184*5776526bSStephen Boyd 	};
185*5776526bSStephen Boyd 
186*5776526bSStephen Boyd 	parent_hw = clk_hw_register_fixed_rate_kunit(test, &parent_params);
187*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent_hw);
188*5776526bSStephen Boyd 	KUNIT_ASSERT_STREQ(test, parent_name, clk_hw_get_name(parent_hw));
189*5776526bSStephen Boyd 
190*5776526bSStephen Boyd 	expected_parent = clk_hw_get_clk_kunit(test, parent_hw, __func__);
191*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected_parent);
192*5776526bSStephen Boyd 
193*5776526bSStephen Boyd 	hw = clk_hw_register_fixed_rate(NULL, "test-fixed-rate", parent_name, 0, 0);
194*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
195*5776526bSStephen Boyd 	KUNIT_ASSERT_EQ(test, 0, clk_hw_unregister_fixed_rate_kunit(test, hw));
196*5776526bSStephen Boyd 
197*5776526bSStephen Boyd 	clk = clk_hw_get_clk_kunit(test, hw, __func__);
198*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, clk);
199*5776526bSStephen Boyd 
200*5776526bSStephen Boyd 	actual_parent = clk_get_parent(clk);
201*5776526bSStephen Boyd 	KUNIT_EXPECT_TRUE(test, clk_is_match(expected_parent, actual_parent));
202*5776526bSStephen Boyd }
203*5776526bSStephen Boyd 
204*5776526bSStephen Boyd /*
205*5776526bSStephen Boyd  * Test that clk_get_rate() on a fixed rate clk ignores the parent rate.
206*5776526bSStephen Boyd  */
207*5776526bSStephen Boyd static void clk_fixed_rate_parent_rate_test(struct kunit *test)
208*5776526bSStephen Boyd {
209*5776526bSStephen Boyd 	struct clk_hw *hw, *parent_hw;
210*5776526bSStephen Boyd 	struct clk *clk;
211*5776526bSStephen Boyd 	const unsigned long expected_rate = 1405;
212*5776526bSStephen Boyd 	const unsigned long parent_rate = 90402;
213*5776526bSStephen Boyd 	const char *parent_name = "test-fixed-rate-parent";
214*5776526bSStephen Boyd 	struct clk_hw_fixed_rate_kunit_params parent_params = {
215*5776526bSStephen Boyd 		.name = parent_name,
216*5776526bSStephen Boyd 		.fixed_rate = parent_rate,
217*5776526bSStephen Boyd 	};
218*5776526bSStephen Boyd 
219*5776526bSStephen Boyd 	parent_hw = clk_hw_register_fixed_rate_kunit(test, &parent_params);
220*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent_hw);
221*5776526bSStephen Boyd 	KUNIT_ASSERT_STREQ(test, parent_name, clk_hw_get_name(parent_hw));
222*5776526bSStephen Boyd 
223*5776526bSStephen Boyd 	hw = clk_hw_register_fixed_rate(NULL, "test-fixed-rate", parent_name, 0,
224*5776526bSStephen Boyd 					expected_rate);
225*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
226*5776526bSStephen Boyd 	KUNIT_ASSERT_EQ(test, 0, clk_hw_unregister_fixed_rate_kunit(test, hw));
227*5776526bSStephen Boyd 
228*5776526bSStephen Boyd 	clk = clk_hw_get_clk_prepared_enabled_kunit(test, hw, __func__);
229*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, clk);
230*5776526bSStephen Boyd 
231*5776526bSStephen Boyd 	KUNIT_EXPECT_EQ(test, expected_rate, clk_get_rate(clk));
232*5776526bSStephen Boyd }
233*5776526bSStephen Boyd 
234*5776526bSStephen Boyd /*
235*5776526bSStephen Boyd  * Test that clk_get_accuracy() on a fixed rate clk ignores the parent accuracy.
236*5776526bSStephen Boyd  */
237*5776526bSStephen Boyd static void clk_fixed_rate_parent_accuracy_test(struct kunit *test)
238*5776526bSStephen Boyd {
239*5776526bSStephen Boyd 	struct clk_hw *hw, *parent_hw;
240*5776526bSStephen Boyd 	struct clk *clk;
241*5776526bSStephen Boyd 	const unsigned long expected_accuracy = 900;
242*5776526bSStephen Boyd 	const unsigned long parent_accuracy = 24000;
243*5776526bSStephen Boyd 	const char *parent_name = "test-fixed-rate-parent";
244*5776526bSStephen Boyd 	struct clk_hw_fixed_rate_kunit_params parent_params = {
245*5776526bSStephen Boyd 		.name = parent_name,
246*5776526bSStephen Boyd 		.fixed_accuracy = parent_accuracy,
247*5776526bSStephen Boyd 	};
248*5776526bSStephen Boyd 
249*5776526bSStephen Boyd 	parent_hw = clk_hw_register_fixed_rate_kunit(test, &parent_params);
250*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent_hw);
251*5776526bSStephen Boyd 	KUNIT_ASSERT_STREQ(test, parent_name, clk_hw_get_name(parent_hw));
252*5776526bSStephen Boyd 
253*5776526bSStephen Boyd 	hw = clk_hw_register_fixed_rate_with_accuracy(NULL, "test-fixed-rate",
254*5776526bSStephen Boyd 						      parent_name, 0, 0,
255*5776526bSStephen Boyd 						      expected_accuracy);
256*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
257*5776526bSStephen Boyd 	KUNIT_ASSERT_EQ(test, 0, clk_hw_unregister_fixed_rate_kunit(test, hw));
258*5776526bSStephen Boyd 
259*5776526bSStephen Boyd 	clk = clk_hw_get_clk_kunit(test, hw, __func__);
260*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, clk);
261*5776526bSStephen Boyd 
262*5776526bSStephen Boyd 	KUNIT_EXPECT_EQ(test, expected_accuracy, clk_get_accuracy(clk));
263*5776526bSStephen Boyd }
264*5776526bSStephen Boyd 
265*5776526bSStephen Boyd /* Test suite for a fixed rate clk with a parent */
266*5776526bSStephen Boyd static struct kunit_case clk_fixed_rate_parent_test_cases[] = {
267*5776526bSStephen Boyd 	KUNIT_CASE(clk_fixed_rate_parent_test),
268*5776526bSStephen Boyd 	KUNIT_CASE(clk_fixed_rate_parent_rate_test),
269*5776526bSStephen Boyd 	KUNIT_CASE(clk_fixed_rate_parent_accuracy_test),
270*5776526bSStephen Boyd 	{}
271*5776526bSStephen Boyd };
272*5776526bSStephen Boyd 
273*5776526bSStephen Boyd static struct kunit_suite clk_fixed_rate_parent_suite = {
274*5776526bSStephen Boyd 	.name = "clk_fixed_rate_parent",
275*5776526bSStephen Boyd 	.test_cases = clk_fixed_rate_parent_test_cases,
276*5776526bSStephen Boyd };
277*5776526bSStephen Boyd 
278*5776526bSStephen Boyd struct clk_fixed_rate_of_test_context {
279*5776526bSStephen Boyd 	struct device *dev;
280*5776526bSStephen Boyd 	struct platform_driver pdrv;
281*5776526bSStephen Boyd 	struct completion probed;
282*5776526bSStephen Boyd };
283*5776526bSStephen Boyd 
284*5776526bSStephen Boyd static inline struct clk_fixed_rate_of_test_context *
285*5776526bSStephen Boyd pdev_to_clk_fixed_rate_of_test_context(struct platform_device *pdev)
286*5776526bSStephen Boyd {
287*5776526bSStephen Boyd 	return container_of(to_platform_driver(pdev->dev.driver),
288*5776526bSStephen Boyd 			    struct clk_fixed_rate_of_test_context,
289*5776526bSStephen Boyd 			    pdrv);
290*5776526bSStephen Boyd }
291*5776526bSStephen Boyd 
292*5776526bSStephen Boyd /*
293*5776526bSStephen Boyd  * Test that of_fixed_clk_setup() registers a fixed rate clk with the proper
294*5776526bSStephen Boyd  * rate.
295*5776526bSStephen Boyd  */
296*5776526bSStephen Boyd static void clk_fixed_rate_of_probe_test(struct kunit *test)
297*5776526bSStephen Boyd {
298*5776526bSStephen Boyd 	struct clk_fixed_rate_of_test_context *ctx = test->priv;
299*5776526bSStephen Boyd 	struct device *dev = ctx->dev;
300*5776526bSStephen Boyd 	struct clk *clk;
301*5776526bSStephen Boyd 
302*5776526bSStephen Boyd 	clk = clk_get_kunit(test, dev, NULL);
303*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, clk);
304*5776526bSStephen Boyd 
305*5776526bSStephen Boyd 	KUNIT_ASSERT_EQ(test, 0, clk_prepare_enable_kunit(test, clk));
306*5776526bSStephen Boyd 	KUNIT_EXPECT_EQ(test, TEST_FIXED_FREQUENCY, clk_get_rate(clk));
307*5776526bSStephen Boyd }
308*5776526bSStephen Boyd 
309*5776526bSStephen Boyd /*
310*5776526bSStephen Boyd  * Test that of_fixed_clk_setup() registers a fixed rate clk with the proper
311*5776526bSStephen Boyd  * accuracy.
312*5776526bSStephen Boyd  */
313*5776526bSStephen Boyd static void clk_fixed_rate_of_accuracy_test(struct kunit *test)
314*5776526bSStephen Boyd {
315*5776526bSStephen Boyd 	struct clk_fixed_rate_of_test_context *ctx = test->priv;
316*5776526bSStephen Boyd 	struct device *dev = ctx->dev;
317*5776526bSStephen Boyd 	struct clk *clk;
318*5776526bSStephen Boyd 
319*5776526bSStephen Boyd 	clk = clk_get_kunit(test, dev, NULL);
320*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, clk);
321*5776526bSStephen Boyd 
322*5776526bSStephen Boyd 	KUNIT_EXPECT_EQ(test, TEST_FIXED_ACCURACY, clk_get_accuracy(clk));
323*5776526bSStephen Boyd }
324*5776526bSStephen Boyd 
325*5776526bSStephen Boyd static struct kunit_case clk_fixed_rate_of_cases[] = {
326*5776526bSStephen Boyd 	KUNIT_CASE(clk_fixed_rate_of_probe_test),
327*5776526bSStephen Boyd 	KUNIT_CASE(clk_fixed_rate_of_accuracy_test),
328*5776526bSStephen Boyd 	{}
329*5776526bSStephen Boyd };
330*5776526bSStephen Boyd 
331*5776526bSStephen Boyd static int clk_fixed_rate_of_test_probe(struct platform_device *pdev)
332*5776526bSStephen Boyd {
333*5776526bSStephen Boyd 	struct clk_fixed_rate_of_test_context *ctx;
334*5776526bSStephen Boyd 
335*5776526bSStephen Boyd 	ctx = pdev_to_clk_fixed_rate_of_test_context(pdev);
336*5776526bSStephen Boyd 	ctx->dev = &pdev->dev;
337*5776526bSStephen Boyd 	complete(&ctx->probed);
338*5776526bSStephen Boyd 
339*5776526bSStephen Boyd 	return 0;
340*5776526bSStephen Boyd }
341*5776526bSStephen Boyd 
342*5776526bSStephen Boyd static int clk_fixed_rate_of_init(struct kunit *test)
343*5776526bSStephen Boyd {
344*5776526bSStephen Boyd 	struct clk_fixed_rate_of_test_context *ctx;
345*5776526bSStephen Boyd 	static const struct of_device_id match_table[] = {
346*5776526bSStephen Boyd 		{ .compatible = "test,single-clk-consumer" },
347*5776526bSStephen Boyd 		{ }
348*5776526bSStephen Boyd 	};
349*5776526bSStephen Boyd 
350*5776526bSStephen Boyd 	KUNIT_ASSERT_EQ(test, 0, of_overlay_apply_kunit(test, kunit_clk_fixed_rate_test));
351*5776526bSStephen Boyd 
352*5776526bSStephen Boyd 	ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
353*5776526bSStephen Boyd 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
354*5776526bSStephen Boyd 	test->priv = ctx;
355*5776526bSStephen Boyd 
356*5776526bSStephen Boyd 	ctx->pdrv.probe = clk_fixed_rate_of_test_probe;
357*5776526bSStephen Boyd 	ctx->pdrv.driver.of_match_table = match_table;
358*5776526bSStephen Boyd 	ctx->pdrv.driver.name = __func__;
359*5776526bSStephen Boyd 	ctx->pdrv.driver.owner = THIS_MODULE;
360*5776526bSStephen Boyd 	init_completion(&ctx->probed);
361*5776526bSStephen Boyd 
362*5776526bSStephen Boyd 	KUNIT_ASSERT_EQ(test, 0, kunit_platform_driver_register(test, &ctx->pdrv));
363*5776526bSStephen Boyd 	KUNIT_ASSERT_NE(test, 0, wait_for_completion_timeout(&ctx->probed, HZ));
364*5776526bSStephen Boyd 
365*5776526bSStephen Boyd 	return 0;
366*5776526bSStephen Boyd }
367*5776526bSStephen Boyd 
368*5776526bSStephen Boyd static struct kunit_suite clk_fixed_rate_of_suite = {
369*5776526bSStephen Boyd 	.name = "clk_fixed_rate_of",
370*5776526bSStephen Boyd 	.init = clk_fixed_rate_of_init,
371*5776526bSStephen Boyd 	.test_cases = clk_fixed_rate_of_cases,
372*5776526bSStephen Boyd };
373*5776526bSStephen Boyd 
374*5776526bSStephen Boyd kunit_test_suites(
375*5776526bSStephen Boyd 	&clk_fixed_rate_suite,
376*5776526bSStephen Boyd 	&clk_fixed_rate_of_suite,
377*5776526bSStephen Boyd 	&clk_fixed_rate_parent_suite,
378*5776526bSStephen Boyd );
379*5776526bSStephen Boyd MODULE_LICENSE("GPL");
380*5776526bSStephen Boyd MODULE_DESCRIPTION("KUnit test for clk fixed rate basic type");
381