]> Git Repo - J-u-boot.git/blob - test/dm/pwm.c
sandbox: cros-ec: Add tests for the Chromium OS EC PWM driver
[J-u-boot.git] / test / dm / pwm.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2017 Google, Inc
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <pwm.h>
9 #include <asm/test.h>
10 #include <dm/test.h>
11 #include <test/test.h>
12 #include <test/ut.h>
13
14 /* Basic test of the pwm uclass */
15 static int dm_test_pwm_base(struct unit_test_state *uts)
16 {
17         struct udevice *dev;
18         uint period_ns;
19         uint duty_ns;
20         bool enable;
21         bool polarity;
22
23         ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev));
24         ut_assertnonnull(dev);
25         ut_assertok(pwm_set_config(dev, 0, 100, 50));
26         ut_assertok(pwm_set_enable(dev, 0, true));
27         ut_assertok(pwm_set_enable(dev, 1, true));
28         ut_assertok(pwm_set_enable(dev, 2, true));
29         ut_asserteq(-ENOSPC, pwm_set_enable(dev, 3, true));
30         ut_assertok(pwm_set_invert(dev, 0, true));
31
32         ut_assertok(pwm_set_config(dev, 2, 100, 50));
33         ut_assertok(sandbox_pwm_get_config(dev, 2, &period_ns, &duty_ns,
34                                            &enable, &polarity));
35         ut_asserteq(period_ns, 4096);
36         ut_asserteq(duty_ns, 50 * 4096 / 100);
37
38         ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
39         ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
40         ut_assertok(uclass_get_device(UCLASS_PWM, 2, &dev));
41         ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 3, &dev));
42
43         return 0;
44 }
45 DM_TEST(dm_test_pwm_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
This page took 0.026896 seconds and 4 git commands to generate.