Pragnesh Patel | 1d5955f | 2020-12-22 11:30:05 +0530 | [diff] [blame] | 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 */ |
| 17 | static int dm_test_pwm_cmd(struct unit_test_state *uts) |
| 18 | { |
| 19 | struct udevice *dev; |
| 20 | |
Alper Nebi Yasak | 8a8cd4f | 2021-05-19 19:33:31 +0300 | [diff] [blame] | 21 | /* cros-ec-pwm */ |
Pragnesh Patel | 1d5955f | 2020-12-22 11:30:05 +0530 | [diff] [blame] | 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> */ |
Alper Nebi Yasak | 8a8cd4f | 2021-05-19 19:33:31 +0300 | [diff] [blame] | 28 | /* cros-ec-pwm doesn't support invert */ |
| 29 | ut_asserteq(1, run_command("pwm invert 0 0 1", 0)); |
Marek Vasut | 1531c4e | 2023-03-10 04:33:13 +0100 | [diff] [blame] | 30 | ut_assert_nextline("error(-38)"); |
Pragnesh Patel | 1d5955f | 2020-12-22 11:30:05 +0530 | [diff] [blame] | 31 | ut_assert_console_end(); |
| 32 | |
Alper Nebi Yasak | 8a8cd4f | 2021-05-19 19:33:31 +0300 | [diff] [blame] | 33 | ut_asserteq(1, run_command("pwm invert 0 0 0", 0)); |
Marek Vasut | 1531c4e | 2023-03-10 04:33:13 +0100 | [diff] [blame] | 34 | ut_assert_nextline("error(-38)"); |
Pragnesh Patel | 1d5955f | 2020-12-22 11:30:05 +0530 | [diff] [blame] | 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 | |
Alper Nebi Yasak | 8a8cd4f | 2021-05-19 19:33:31 +0300 | [diff] [blame] | 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 | |
Pragnesh Patel | 1d5955f | 2020-12-22 11:30:05 +0530 | [diff] [blame] | 72 | return 0; |
| 73 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 74 | DM_TEST(dm_test_pwm_cmd, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE_REC); |