Alper Nebi Yasak | 8a8cd4f | 2021-05-19 19:33:31 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
Alper Nebi Yasak | 8a8cd4f | 2021-05-19 19:33:31 +0300 | [diff] [blame] | 3 | #include <cros_ec.h> |
| 4 | #include <dm.h> |
| 5 | #include <pwm.h> |
| 6 | #include <asm/test.h> |
| 7 | #include <dm/test.h> |
| 8 | #include <test/test.h> |
| 9 | #include <test/ut.h> |
| 10 | |
| 11 | static int dm_test_cros_ec_pwm(struct unit_test_state *uts) |
| 12 | { |
| 13 | struct udevice *pwm; |
| 14 | struct udevice *ec; |
| 15 | uint duty; |
| 16 | |
| 17 | ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "cros-ec-pwm", &pwm)); |
| 18 | ut_assertnonnull(pwm); |
| 19 | ec = dev_get_parent(pwm); |
| 20 | ut_assertnonnull(ec); |
| 21 | |
| 22 | ut_assertok(pwm_set_config(pwm, 0, 100, 50)); |
| 23 | ut_assertok(pwm_set_enable(pwm, 0, true)); |
| 24 | ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 0, &duty)); |
| 25 | ut_asserteq(50 * EC_PWM_MAX_DUTY / 100, duty); |
| 26 | |
| 27 | ut_assertok(pwm_set_config(pwm, 0, 15721, 2719)); |
| 28 | ut_assertok(pwm_set_enable(pwm, 0, true)); |
| 29 | ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 0, &duty)); |
| 30 | ut_asserteq(2719 * EC_PWM_MAX_DUTY / 15721, duty); |
| 31 | |
| 32 | ut_assertok(pwm_set_enable(pwm, 0, false)); |
| 33 | ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 0, &duty)); |
| 34 | ut_asserteq(0, duty); |
| 35 | |
| 36 | ut_assertok(pwm_set_enable(pwm, 0, true)); |
| 37 | ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 0, &duty)); |
| 38 | ut_asserteq(2719 * EC_PWM_MAX_DUTY / 15721, duty); |
| 39 | |
| 40 | ut_assertok(pwm_set_config(pwm, 1, 1000, 0)); |
| 41 | ut_assertok(pwm_set_enable(pwm, 1, true)); |
| 42 | ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 1, &duty)); |
| 43 | ut_asserteq(0, duty); |
| 44 | |
| 45 | ut_assertok(pwm_set_config(pwm, 2, 1000, 1024)); |
| 46 | ut_assertok(pwm_set_enable(pwm, 2, true)); |
| 47 | ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 2, &duty)); |
| 48 | ut_asserteq(EC_PWM_MAX_DUTY, duty); |
| 49 | |
| 50 | ut_assertok(pwm_set_config(pwm, 3, EC_PWM_MAX_DUTY, 0xABCD)); |
| 51 | ut_assertok(pwm_set_enable(pwm, 3, true)); |
| 52 | ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 3, &duty)); |
| 53 | ut_asserteq(0xABCD, duty); |
| 54 | |
| 55 | ut_asserteq(-EINVAL, pwm_set_enable(pwm, 4, true)); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | DM_TEST(dm_test_cros_ec_pwm, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |