blob: dff626c771ac468ac6e7771aa61cb0a18b9abc93 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass43b41562017-04-16 21:01:11 -06002/*
3 * Copyright (C) 2017 Google, Inc
Simon Glass43b41562017-04-16 21:01:11 -06004 */
5
6#include <common.h>
7#include <dm.h>
8#include <pwm.h>
Alper Nebi Yasakfefa7132020-10-22 23:49:26 +03009#include <asm/test.h>
Simon Glass43b41562017-04-16 21:01:11 -060010#include <dm/test.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060011#include <test/test.h>
Simon Glass43b41562017-04-16 21:01:11 -060012#include <test/ut.h>
13
Simon Glass43b41562017-04-16 21:01:11 -060014/* Basic test of the pwm uclass */
15static int dm_test_pwm_base(struct unit_test_state *uts)
16{
17 struct udevice *dev;
Alper Nebi Yasakfefa7132020-10-22 23:49:26 +030018 uint period_ns;
19 uint duty_ns;
20 bool enable;
21 bool polarity;
Simon Glass43b41562017-04-16 21:01:11 -060022
Alper Nebi Yasake7122452021-05-19 19:33:31 +030023 ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev));
Simon Glass1a596c42017-06-07 10:28:38 -060024 ut_assertnonnull(dev);
Simon Glass43b41562017-04-16 21:01:11 -060025 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));
Kever Yang5540e252017-04-24 10:27:52 +080030 ut_assertok(pwm_set_invert(dev, 0, true));
Simon Glass43b41562017-04-16 21:01:11 -060031
Alper Nebi Yasakfefa7132020-10-22 23:49:26 +030032 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
Alper Nebi Yasake7122452021-05-19 19:33:31 +030038 ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
Simon Glass43b41562017-04-16 21:01:11 -060039 ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
Alper Nebi Yasake7122452021-05-19 19:33:31 +030040 ut_assertok(uclass_get_device(UCLASS_PWM, 2, &dev));
41 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 3, &dev));
Simon Glass43b41562017-04-16 21:01:11 -060042
43 return 0;
44}
Simon Glasse180c2b2020-07-28 19:41:12 -060045DM_TEST(dm_test_pwm_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);