pwm.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include <dm.h>
  11. #include <dm/test.h>
  12. #include <test/test.h>
  13. #include <test/ut.h>
  14. /* Basic test of 'pwm' command */
  15. static int dm_test_pwm_cmd(struct unit_test_state *uts)
  16. {
  17. struct udevice *dev;
  18. /* cros-ec-pwm */
  19. ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
  20. ut_assertnonnull(dev);
  21. ut_assertok(console_record_reset_enable());
  22. /* pwm <invert> <pwm_dev_num> <channel> <polarity> */
  23. /* cros-ec-pwm doesn't support invert */
  24. ut_asserteq(1, run_command("pwm invert 0 0 1", 0));
  25. ut_assert_nextline("error(-38)")
  26. ut_assert_console_end();
  27. ut_asserteq(1, run_command("pwm invert 0 0 0", 0));
  28. ut_assert_nextline("error(-38)")
  29. ut_assert_console_end();
  30. /* pwm <config> <pwm_dev_num> <channel> <period_ns> <duty_ns> */
  31. ut_assertok(run_command("pwm config 0 0 10 50", 0));
  32. ut_assert_console_end();
  33. /* pwm <enable/disable> <pwm_dev_num> <channel> */
  34. ut_assertok(run_command("pwm enable 0 0", 0));
  35. ut_assert_console_end();
  36. ut_assertok(run_command("pwm disable 0 0", 0));
  37. ut_assert_console_end();
  38. /* sandbox-pwm */
  39. ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
  40. ut_assertnonnull(dev);
  41. ut_assertok(console_record_reset_enable());
  42. /* pwm <invert> <pwm_dev_num> <channel> <polarity> */
  43. ut_assertok(run_command("pwm invert 1 0 1", 0));
  44. ut_assert_console_end();
  45. ut_assertok(run_command("pwm invert 1 0 0", 0));
  46. ut_assert_console_end();
  47. /* pwm <config> <pwm_dev_num> <channel> <period_ns> <duty_ns> */
  48. ut_assertok(run_command("pwm config 1 0 10 50", 0));
  49. ut_assert_console_end();
  50. /* pwm <enable/disable> <pwm_dev_num> <channel> */
  51. ut_assertok(run_command("pwm enable 1 0", 0));
  52. ut_assert_console_end();
  53. ut_assertok(run_command("pwm disable 1 0", 0));
  54. ut_assert_console_end();
  55. return 0;
  56. }
  57. DM_TEST(dm_test_pwm_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);