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