1 // SPDX-License-Identifier: GPL-2.0+
3 * Test for panel uclass
5 * Copyright (c) 2018 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
10 #include <backlight.h>
18 #include <power/regulator.h>
20 /* Basic test of the panel uclass */
21 static int dm_test_panel(struct unit_test_state *uts)
23 struct udevice *dev, *pwm, *gpio, *reg;
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", ®));
33 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
35 ut_asserteq(false, enable);
36 ut_asserteq(false, regulator_get_enable(reg));
38 ut_assertok(panel_enable_backlight(dev));
39 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
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));
48 ut_assertok(panel_set_backlight(dev, 40));
49 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
51 ut_asserteq(64 * 1000 / 256, duty_ns);
53 ut_assertok(panel_set_backlight(dev, BACKLIGHT_MAX));
54 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
56 ut_asserteq(255 * 1000 / 256, duty_ns);
58 ut_assertok(panel_set_backlight(dev, BACKLIGHT_MIN));
59 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
61 ut_asserteq(0 * 1000 / 256, duty_ns);
62 ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
64 ut_assertok(panel_set_backlight(dev, BACKLIGHT_DEFAULT));
65 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
67 ut_asserteq(true, enable);
68 ut_asserteq(170 * 1000 / 256, duty_ns);
70 ut_assertok(panel_set_backlight(dev, BACKLIGHT_OFF));
71 ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
73 ut_asserteq(0 * 1000 / 256, duty_ns);
74 ut_asserteq(0, sandbox_gpio_get_value(gpio, 1));
75 ut_asserteq(false, regulator_get_enable(reg));
79 DM_TEST(dm_test_panel, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);