Simon Glass | 5620cf8 | 2018-10-01 12:22:40 -0600 | [diff] [blame] | 1 | // 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 | |
Simon Glass | 5620cf8 | 2018-10-01 12:22:40 -0600 | [diff] [blame] | 9 | #include <backlight.h> |
| 10 | #include <dm.h> |
| 11 | #include <panel.h> |
| 12 | #include <video.h> |
| 13 | #include <asm/gpio.h> |
| 14 | #include <asm/test.h> |
| 15 | #include <dm/test.h> |
Simon Glass | 5620cf8 | 2018-10-01 12:22:40 -0600 | [diff] [blame] | 16 | #include <power/regulator.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 17 | #include <test/test.h> |
| 18 | #include <test/ut.h> |
Simon Glass | 5620cf8 | 2018-10-01 12:22:40 -0600 | [diff] [blame] | 19 | |
| 20 | /* Basic test of the panel uclass */ |
| 21 | static 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)); |
Alper Nebi Yasak | 8a8cd4f | 2021-05-19 19:33:31 +0300 | [diff] [blame] | 30 | ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &pwm)); |
Simon Glass | 5620cf8 | 2018-10-01 12:22:40 -0600 | [diff] [blame] | 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, |
| 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); |
Dario Binacchi | 753251d | 2020-10-11 14:28:04 +0200 | [diff] [blame] | 42 | ut_asserteq(170 * 1000 / 255, duty_ns); |
Simon Glass | 5620cf8 | 2018-10-01 12:22:40 -0600 | [diff] [blame] | 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 | |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 48 | ut_assertok(panel_set_backlight(dev, 40)); |
| 49 | ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, |
| 50 | &enable, &polarity)); |
Dario Binacchi | 753251d | 2020-10-11 14:28:04 +0200 | [diff] [blame] | 51 | ut_asserteq(64 * 1000 / 255, duty_ns); |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 52 | |
| 53 | ut_assertok(panel_set_backlight(dev, BACKLIGHT_MAX)); |
| 54 | ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, |
| 55 | &enable, &polarity)); |
Dario Binacchi | 753251d | 2020-10-11 14:28:04 +0200 | [diff] [blame] | 56 | ut_asserteq(255 * 1000 / 255, duty_ns); |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 57 | |
| 58 | ut_assertok(panel_set_backlight(dev, BACKLIGHT_MIN)); |
| 59 | ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, |
| 60 | &enable, &polarity)); |
Dario Binacchi | 753251d | 2020-10-11 14:28:04 +0200 | [diff] [blame] | 61 | ut_asserteq(0 * 1000 / 255, duty_ns); |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 62 | ut_asserteq(1, sandbox_gpio_get_value(gpio, 1)); |
| 63 | |
| 64 | ut_assertok(panel_set_backlight(dev, BACKLIGHT_DEFAULT)); |
| 65 | ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, |
| 66 | &enable, &polarity)); |
| 67 | ut_asserteq(true, enable); |
Dario Binacchi | 753251d | 2020-10-11 14:28:04 +0200 | [diff] [blame] | 68 | ut_asserteq(170 * 1000 / 255, duty_ns); |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 69 | |
| 70 | ut_assertok(panel_set_backlight(dev, BACKLIGHT_OFF)); |
| 71 | ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, |
| 72 | &enable, &polarity)); |
Dario Binacchi | 753251d | 2020-10-11 14:28:04 +0200 | [diff] [blame] | 73 | ut_asserteq(0 * 1000 / 255, duty_ns); |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 74 | ut_asserteq(0, sandbox_gpio_get_value(gpio, 1)); |
| 75 | ut_asserteq(false, regulator_get_enable(reg)); |
| 76 | |
Simon Glass | 5620cf8 | 2018-10-01 12:22:40 -0600 | [diff] [blame] | 77 | return 0; |
| 78 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 79 | DM_TEST(dm_test_panel, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |