Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Google, Inc |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <pwm.h> |
Alper Nebi Yasak | 4692746 | 2020-10-22 23:49:26 +0300 | [diff] [blame] | 8 | #include <asm/test.h> |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 9 | #include <dm/test.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 10 | #include <test/test.h> |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 11 | #include <test/ut.h> |
| 12 | |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 13 | /* Basic test of the pwm uclass */ |
| 14 | static int dm_test_pwm_base(struct unit_test_state *uts) |
| 15 | { |
| 16 | struct udevice *dev; |
Alper Nebi Yasak | 4692746 | 2020-10-22 23:49:26 +0300 | [diff] [blame] | 17 | uint period_ns; |
| 18 | uint duty_ns; |
| 19 | bool enable; |
| 20 | bool polarity; |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 21 | |
Alper Nebi Yasak | 8a8cd4f | 2021-05-19 19:33:31 +0300 | [diff] [blame] | 22 | ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev)); |
Simon Glass | 680e932 | 2017-06-07 10:28:38 -0600 | [diff] [blame] | 23 | ut_assertnonnull(dev); |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 24 | ut_assertok(pwm_set_config(dev, 0, 100, 50)); |
| 25 | ut_assertok(pwm_set_enable(dev, 0, true)); |
| 26 | ut_assertok(pwm_set_enable(dev, 1, true)); |
| 27 | ut_assertok(pwm_set_enable(dev, 2, true)); |
| 28 | ut_asserteq(-ENOSPC, pwm_set_enable(dev, 3, true)); |
Kever Yang | 809c3e6 | 2017-04-24 10:27:52 +0800 | [diff] [blame] | 29 | ut_assertok(pwm_set_invert(dev, 0, true)); |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 30 | |
Alper Nebi Yasak | 4692746 | 2020-10-22 23:49:26 +0300 | [diff] [blame] | 31 | ut_assertok(pwm_set_config(dev, 2, 100, 50)); |
| 32 | ut_assertok(sandbox_pwm_get_config(dev, 2, &period_ns, &duty_ns, |
| 33 | &enable, &polarity)); |
| 34 | ut_asserteq(period_ns, 4096); |
| 35 | ut_asserteq(duty_ns, 50 * 4096 / 100); |
| 36 | |
Alper Nebi Yasak | 8a8cd4f | 2021-05-19 19:33:31 +0300 | [diff] [blame] | 37 | ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev)); |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 38 | ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev)); |
Alper Nebi Yasak | 8a8cd4f | 2021-05-19 19:33:31 +0300 | [diff] [blame] | 39 | ut_assertok(uclass_get_device(UCLASS_PWM, 2, &dev)); |
| 40 | ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 3, &dev)); |
Simon Glass | e62f4be | 2017-04-16 21:01:11 -0600 | [diff] [blame] | 41 | |
| 42 | return 0; |
| 43 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 44 | DM_TEST(dm_test_pwm_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |