summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPragnesh Patel <pragnesh.patel@sifive.com>2020-12-22 11:30:05 +0530
committerTom Rini <trini@konsulko.com>2021-01-18 15:23:06 -0500
commit9e9a530a61c01e412a239d8c211d5b1e26b578fa (patch)
treecc2c5f125fba8721f5546c21594bb1c637a0c1b2 /test
parent2767d881f031124b2193ab33b32e48b29c6e18e1 (diff)
downloadu-boot-9e9a530a61c01e412a239d8c211d5b1e26b578fa.tar.gz
u-boot-9e9a530a61c01e412a239d8c211d5b1e26b578fa.tar.xz
u-boot-9e9a530a61c01e412a239d8c211d5b1e26b578fa.zip
cmd: Add a pwm command
Add the command "pwm" for controlling the pwm channels. This command provides pwm invert/config/enable/disable functionalities via PWM uclass drivers Signed-off-by: Pragnesh Patel <pragnesh.patel@sifive.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/cmd/Makefile1
-rw-r--r--test/cmd/pwm.c47
2 files changed, 48 insertions, 0 deletions
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index b2f71af847..758bc14273 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -4,4 +4,5 @@
obj-y += mem.o
obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
+obj-$(CONFIG_CMD_PWM) += pwm.o
obj-y += setexpr.o
diff --git a/test/cmd/pwm.c b/test/cmd/pwm.c
new file mode 100644
index 0000000000..5343af83fa
--- /dev/null
+++ b/test/cmd/pwm.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for pwm command
+ *
+ * Copyright 2020 SiFive, Inc
+ *
+ * Authors:
+ * Pragnesh Patel <pragnesh.patel@sifive.com>
+ */
+
+#include <dm.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+/* Basic test of 'pwm' command */
+static int dm_test_pwm_cmd(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+
+ ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
+ ut_assertnonnull(dev);
+
+ ut_assertok(console_record_reset_enable());
+
+ /* pwm <invert> <pwm_dev_num> <channel> <polarity> */
+ ut_assertok(run_command("pwm invert 0 0 1", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("pwm invert 0 0 0", 0));
+ ut_assert_console_end();
+
+ /* pwm <config> <pwm_dev_num> <channel> <period_ns> <duty_ns> */
+ ut_assertok(run_command("pwm config 0 0 10 50", 0));
+ ut_assert_console_end();
+
+ /* pwm <enable/disable> <pwm_dev_num> <channel> */
+ ut_assertok(run_command("pwm enable 0 0", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("pwm disable 0 0", 0));
+ ut_assert_console_end();
+
+ return 0;
+}
+
+DM_TEST(dm_test_pwm_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);