1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2017 Google, Inc
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <pwm.h>
9 #include <asm/test.h>
10 #include <dm/test.h>
11 #include <test/test.h>
12 #include <test/ut.h>
13 
14 /* Basic test of the pwm uclass */
dm_test_pwm_base(struct unit_test_state * uts)15 static int dm_test_pwm_base(struct unit_test_state *uts)
16 {
17 	struct udevice *dev;
18 	uint period_ns;
19 	uint duty_ns;
20 	bool enable;
21 	bool polarity;
22 
23 	ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
24 	ut_assertnonnull(dev);
25 	ut_assertok(pwm_set_config(dev, 0, 100, 50));
26 	ut_assertok(pwm_set_enable(dev, 0, true));
27 	ut_assertok(pwm_set_enable(dev, 1, true));
28 	ut_assertok(pwm_set_enable(dev, 2, true));
29 	ut_asserteq(-ENOSPC, pwm_set_enable(dev, 3, true));
30 	ut_assertok(pwm_set_invert(dev, 0, true));
31 
32 	ut_assertok(pwm_set_config(dev, 2, 100, 50));
33 	ut_assertok(sandbox_pwm_get_config(dev, 2, &period_ns, &duty_ns,
34 					   &enable, &polarity));
35 	ut_asserteq(period_ns, 4096);
36 	ut_asserteq(duty_ns, 50 * 4096 / 100);
37 
38 	ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
39 	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 2, &dev));
40 
41 	return 0;
42 }
43 DM_TEST(dm_test_pwm_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
44