blob: 80133347ec73a9004b61ee501f6d7a9c7843bf8a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glasse62f4be2017-04-16 21:01:11 -06002/*
3 * Copyright (C) 2017 Google, Inc
Simon Glasse62f4be2017-04-16 21:01:11 -06004 */
5
Simon Glasse62f4be2017-04-16 21:01:11 -06006#include <dm.h>
7#include <pwm.h>
Alper Nebi Yasak46927462020-10-22 23:49:26 +03008#include <asm/test.h>
Simon Glasse62f4be2017-04-16 21:01:11 -06009#include <dm/test.h>
Simon Glass75c4d412020-07-19 10:15:37 -060010#include <test/test.h>
Simon Glasse62f4be2017-04-16 21:01:11 -060011#include <test/ut.h>
12
Simon Glasse62f4be2017-04-16 21:01:11 -060013/* Basic test of the pwm uclass */
14static int dm_test_pwm_base(struct unit_test_state *uts)
15{
16 struct udevice *dev;
Alper Nebi Yasak46927462020-10-22 23:49:26 +030017 uint period_ns;
18 uint duty_ns;
19 bool enable;
20 bool polarity;
Simon Glasse62f4be2017-04-16 21:01:11 -060021
Alper Nebi Yasak8a8cd4f2021-05-19 19:33:31 +030022 ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev));
Simon Glass680e9322017-06-07 10:28:38 -060023 ut_assertnonnull(dev);
Simon Glasse62f4be2017-04-16 21:01:11 -060024 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 Yang809c3e62017-04-24 10:27:52 +080029 ut_assertok(pwm_set_invert(dev, 0, true));
Simon Glasse62f4be2017-04-16 21:01:11 -060030
Alper Nebi Yasak46927462020-10-22 23:49:26 +030031 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 Yasak8a8cd4f2021-05-19 19:33:31 +030037 ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
Simon Glasse62f4be2017-04-16 21:01:11 -060038 ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
Alper Nebi Yasak8a8cd4f2021-05-19 19:33:31 +030039 ut_assertok(uclass_get_device(UCLASS_PWM, 2, &dev));
40 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 3, &dev));
Simon Glasse62f4be2017-04-16 21:01:11 -060041
42 return 0;
43}
Simon Glass974dccd2020-07-28 19:41:12 -060044DM_TEST(dm_test_pwm_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);