blob: cf7ee0e0e6504bbfc225f81a075bdfcef86105f0 [file] [log] [blame]
Pragnesh Patel1d5955f2020-12-22 11:30:05 +05301// 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 */
17static int dm_test_pwm_cmd(struct unit_test_state *uts)
18{
19 struct udevice *dev;
20
Alper Nebi Yasak8a8cd4f2021-05-19 19:33:31 +030021 /* cros-ec-pwm */
Pragnesh Patel1d5955f2020-12-22 11:30:05 +053022 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> */
Alper Nebi Yasak8a8cd4f2021-05-19 19:33:31 +030028 /* cros-ec-pwm doesn't support invert */
29 ut_asserteq(1, run_command("pwm invert 0 0 1", 0));
Marek Vasut1531c4e2023-03-10 04:33:13 +010030 ut_assert_nextline("error(-38)");
Pragnesh Patel1d5955f2020-12-22 11:30:05 +053031 ut_assert_console_end();
32
Alper Nebi Yasak8a8cd4f2021-05-19 19:33:31 +030033 ut_asserteq(1, run_command("pwm invert 0 0 0", 0));
Marek Vasut1531c4e2023-03-10 04:33:13 +010034 ut_assert_nextline("error(-38)");
Pragnesh Patel1d5955f2020-12-22 11:30:05 +053035 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
Alper Nebi Yasak8a8cd4f2021-05-19 19:33:31 +030048 /* 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
Pragnesh Patel1d5955f2020-12-22 11:30:05 +053072 return 0;
73}
74
75DM_TEST(dm_test_pwm_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);