blob: ca032409f8c911f6bee472a68baa36e9f0407a4e [file] [log] [blame]
Simon Glass5620cf82018-10-01 12:22:40 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Test for panel uclass
4 *
5 * Copyright (c) 2018 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#include <common.h>
10#include <backlight.h>
11#include <dm.h>
12#include <panel.h>
13#include <video.h>
14#include <asm/gpio.h>
15#include <asm/test.h>
16#include <dm/test.h>
17#include <test/ut.h>
18#include <power/regulator.h>
19
20/* Basic test of the panel uclass */
21static int dm_test_panel(struct unit_test_state *uts)
22{
23 struct udevice *dev, *pwm, *gpio, *reg;
24 uint period_ns;
25 uint duty_ns;
26 bool enable;
27 bool polarity;
28
29 ut_assertok(uclass_first_device_err(UCLASS_PANEL, &dev));
30 ut_assertok(uclass_first_device_err(UCLASS_PWM, &pwm));
31 ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
32 ut_assertok(regulator_get_by_platname("VDD_EMMC_1.8V", &reg));
33 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
34 &enable, &polarity));
35 ut_asserteq(false, enable);
36 ut_asserteq(false, regulator_get_enable(reg));
37
38 ut_assertok(panel_enable_backlight(dev));
39 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
40 &enable, &polarity));
41 ut_asserteq(1000, period_ns);
42 ut_asserteq(170 * 1000 / 256, duty_ns);
43 ut_asserteq(true, enable);
44 ut_asserteq(false, polarity);
45 ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
46 ut_asserteq(true, regulator_get_enable(reg));
47
48 return 0;
49}
50DM_TEST(dm_test_panel, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);