1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Test for pwm command
4  *
5  * Copyright 2020 SiFive, Inc
6  *
7  * Authors:
8  *   Pragnesh Patel <pragnesh.patel@sifive.com>
9  */
10 
11 #include <dm.h>
12 #include <dm/test.h>
13 #include <test/test.h>
14 #include <test/ut.h>
15 
16 /* Basic test of 'pwm' command */
dm_test_pwm_cmd(struct unit_test_state * uts)17 static int dm_test_pwm_cmd(struct unit_test_state *uts)
18 {
19 	struct udevice *dev;
20 
21 	/* cros-ec-pwm */
22 	ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
23 	ut_assertnonnull(dev);
24 
25 	ut_assertok(console_record_reset_enable());
26 
27 	/* pwm <invert> <pwm_dev_num> <channel> <polarity> */
28 	/* cros-ec-pwm doesn't support invert */
29 	ut_asserteq(1, run_command("pwm invert 0 0 1", 0));
30 	ut_assert_nextline("error(-38)")
31 	ut_assert_console_end();
32 
33 	ut_asserteq(1, run_command("pwm invert 0 0 0", 0));
34 	ut_assert_nextline("error(-38)")
35 	ut_assert_console_end();
36 
37 	/* pwm <config> <pwm_dev_num> <channel> <period_ns> <duty_ns> */
38 	ut_assertok(run_command("pwm config 0 0 10 50", 0));
39 	ut_assert_console_end();
40 
41 	/* pwm <enable/disable> <pwm_dev_num> <channel> */
42 	ut_assertok(run_command("pwm enable 0 0", 0));
43 	ut_assert_console_end();
44 
45 	ut_assertok(run_command("pwm disable 0 0", 0));
46 	ut_assert_console_end();
47 
48 	/* sandbox-pwm */
49 	ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
50 	ut_assertnonnull(dev);
51 
52 	ut_assertok(console_record_reset_enable());
53 
54 	/* pwm <invert> <pwm_dev_num> <channel> <polarity> */
55 	ut_assertok(run_command("pwm invert 1 0 1", 0));
56 	ut_assert_console_end();
57 
58 	ut_assertok(run_command("pwm invert 1 0 0", 0));
59 	ut_assert_console_end();
60 
61 	/* pwm <config> <pwm_dev_num> <channel> <period_ns> <duty_ns> */
62 	ut_assertok(run_command("pwm config 1 0 10 50", 0));
63 	ut_assert_console_end();
64 
65 	/* pwm <enable/disable> <pwm_dev_num> <channel> */
66 	ut_assertok(run_command("pwm enable 1 0", 0));
67 	ut_assert_console_end();
68 
69 	ut_assertok(run_command("pwm disable 1 0", 0));
70 	ut_assert_console_end();
71 
72 	return 0;
73 }
74 
75 DM_TEST(dm_test_pwm_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
76