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 /* pwm <invert> <pwm_dev_num> <channel> <polarity> */
26 /* cros-ec-pwm doesn't support invert */
27 ut_asserteq(1, run_command("pwm invert 0 0 1", 0));
28 ut_assert_nextline("error(-38)");
29 ut_assert_console_end();
30
31 ut_asserteq(1, run_command("pwm invert 0 0 0", 0));
32 ut_assert_nextline("error(-38)");
33 ut_assert_console_end();
34
35 /* pwm <config> <pwm_dev_num> <channel> <period_ns> <duty_ns> */
36 ut_assertok(run_command("pwm config 0 0 10 50", 0));
37 ut_assert_console_end();
38
39 /* pwm <enable/disable> <pwm_dev_num> <channel> */
40 ut_assertok(run_command("pwm enable 0 0", 0));
41 ut_assert_console_end();
42
43 ut_assertok(run_command("pwm disable 0 0", 0));
44 ut_assert_console_end();
45
46 /* sandbox-pwm */
47 ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
48 ut_assertnonnull(dev);
49
50 /* pwm <invert> <pwm_dev_num> <channel> <polarity> */
51 ut_assertok(run_command("pwm invert 1 0 1", 0));
52 ut_assert_console_end();
53
54 ut_assertok(run_command("pwm invert 1 0 0", 0));
55 ut_assert_console_end();
56
57 /* pwm <config> <pwm_dev_num> <channel> <period_ns> <duty_ns> */
58 ut_assertok(run_command("pwm config 1 0 10 50", 0));
59 ut_assert_console_end();
60
61 /* pwm <enable/disable> <pwm_dev_num> <channel> */
62 ut_assertok(run_command("pwm enable 1 0", 0));
63 ut_assert_console_end();
64
65 ut_assertok(run_command("pwm disable 1 0", 0));
66 ut_assert_console_end();
67
68 return 0;
69 }
70 DM_TEST(dm_test_pwm_cmd, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
71