blob: 49f5ac7169d3d052a4062af87e9c9d90f71c9a06 [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>
Simon Glass5620cf82018-10-01 12:22:40 -060017#include <power/regulator.h>
Simon Glass75c4d412020-07-19 10:15:37 -060018#include <test/test.h>
19#include <test/ut.h>
Simon Glass5620cf82018-10-01 12:22:40 -060020
21/* Basic test of the panel uclass */
22static int dm_test_panel(struct unit_test_state *uts)
23{
24 struct udevice *dev, *pwm, *gpio, *reg;
25 uint period_ns;
26 uint duty_ns;
27 bool enable;
28 bool polarity;
29
30 ut_assertok(uclass_first_device_err(UCLASS_PANEL, &dev));
31 ut_assertok(uclass_first_device_err(UCLASS_PWM, &pwm));
32 ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
33 ut_assertok(regulator_get_by_platname("VDD_EMMC_1.8V", &reg));
34 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
35 &enable, &polarity));
36 ut_asserteq(false, enable);
37 ut_asserteq(false, regulator_get_enable(reg));
38
39 ut_assertok(panel_enable_backlight(dev));
40 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
41 &enable, &polarity));
42 ut_asserteq(1000, period_ns);
Dario Binacchi753251d2020-10-11 14:28:04 +020043 ut_asserteq(170 * 1000 / 255, duty_ns);
Simon Glass5620cf82018-10-01 12:22:40 -060044 ut_asserteq(true, enable);
45 ut_asserteq(false, polarity);
46 ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
47 ut_asserteq(true, regulator_get_enable(reg));
48
Simon Glassfe68a452018-10-01 12:22:41 -060049 ut_assertok(panel_set_backlight(dev, 40));
50 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
51 &enable, &polarity));
Dario Binacchi753251d2020-10-11 14:28:04 +020052 ut_asserteq(64 * 1000 / 255, duty_ns);
Simon Glassfe68a452018-10-01 12:22:41 -060053
54 ut_assertok(panel_set_backlight(dev, BACKLIGHT_MAX));
55 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
56 &enable, &polarity));
Dario Binacchi753251d2020-10-11 14:28:04 +020057 ut_asserteq(255 * 1000 / 255, duty_ns);
Simon Glassfe68a452018-10-01 12:22:41 -060058
59 ut_assertok(panel_set_backlight(dev, BACKLIGHT_MIN));
60 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
61 &enable, &polarity));
Dario Binacchi753251d2020-10-11 14:28:04 +020062 ut_asserteq(0 * 1000 / 255, duty_ns);
Simon Glassfe68a452018-10-01 12:22:41 -060063 ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
64
65 ut_assertok(panel_set_backlight(dev, BACKLIGHT_DEFAULT));
66 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
67 &enable, &polarity));
68 ut_asserteq(true, enable);
Dario Binacchi753251d2020-10-11 14:28:04 +020069 ut_asserteq(170 * 1000 / 255, duty_ns);
Simon Glassfe68a452018-10-01 12:22:41 -060070
71 ut_assertok(panel_set_backlight(dev, BACKLIGHT_OFF));
72 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
73 &enable, &polarity));
Dario Binacchi753251d2020-10-11 14:28:04 +020074 ut_asserteq(0 * 1000 / 255, duty_ns);
Simon Glassfe68a452018-10-01 12:22:41 -060075 ut_asserteq(0, sandbox_gpio_get_value(gpio, 1));
76 ut_asserteq(false, regulator_get_enable(reg));
77
Simon Glass5620cf82018-10-01 12:22:40 -060078 return 0;
79}
Simon Glass974dccd2020-07-28 19:41:12 -060080DM_TEST(dm_test_panel, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);