blob: 0d47e2d8abbaac4869f7e6559ec7fc599dce8e83 [file] [log] [blame]
Pragnesh Patel9e9a5302020-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 Yasake7122452021-05-19 19:33:31 +030021 /* cros-ec-pwm */
Pragnesh Patel9e9a5302020-12-22 11:30:05 +053022 ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
23 ut_assertnonnull(dev);
24
Pragnesh Patel9e9a5302020-12-22 11:30:05 +053025 /* pwm <invert> <pwm_dev_num> <channel> <polarity> */
Alper Nebi Yasake7122452021-05-19 19:33:31 +030026 /* cros-ec-pwm doesn't support invert */
27 ut_asserteq(1, run_command("pwm invert 0 0 1", 0));
Marek Vasutfa847bb2023-03-10 04:33:13 +010028 ut_assert_nextline("error(-38)");
Pragnesh Patel9e9a5302020-12-22 11:30:05 +053029 ut_assert_console_end();
30
Alper Nebi Yasake7122452021-05-19 19:33:31 +030031 ut_asserteq(1, run_command("pwm invert 0 0 0", 0));
Marek Vasutfa847bb2023-03-10 04:33:13 +010032 ut_assert_nextline("error(-38)");
Pragnesh Patel9e9a5302020-12-22 11:30:05 +053033 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
Alper Nebi Yasake7122452021-05-19 19:33:31 +030046 /* sandbox-pwm */
47 ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
48 ut_assertnonnull(dev);
49
Alper Nebi Yasake7122452021-05-19 19:33:31 +030050 /* 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
Pragnesh Patel9e9a5302020-12-22 11:30:05 +053068 return 0;
69}
Simon Glass9b997622024-08-22 07:57:50 -060070DM_TEST(dm_test_pwm_cmd, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);