Simon Glass | b45c833 | 2019-02-16 20:24:50 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2018 Google LLC |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <pch.h> |
| 9 | #include <asm/test.h> |
| 10 | #include <dm/test.h> |
Simon Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 11 | #include <test/test.h> |
Simon Glass | b45c833 | 2019-02-16 20:24:50 -0700 | [diff] [blame] | 12 | #include <test/ut.h> |
| 13 | |
| 14 | /* Test that sandbox PCH works correctly */ |
| 15 | static int dm_test_pch_base(struct unit_test_state *uts) |
| 16 | { |
| 17 | struct udevice *dev; |
| 18 | u32 gbase, iobase; |
| 19 | ulong sbase; |
| 20 | |
| 21 | ut_assertok(uclass_first_device_err(UCLASS_PCH, &dev)); |
| 22 | ut_assertok(pch_get_spi_base(dev, &sbase)); |
| 23 | ut_asserteq(0x10, sbase); |
| 24 | |
| 25 | ut_asserteq(0, sandbox_get_pch_spi_protect(dev)); |
| 26 | ut_assertok(pch_set_spi_protect(dev, true)); |
| 27 | ut_asserteq(1, sandbox_get_pch_spi_protect(dev)); |
| 28 | |
| 29 | ut_assertok(pch_get_gpio_base(dev, &gbase)); |
| 30 | ut_asserteq(0x20, gbase); |
| 31 | |
| 32 | ut_assertok(pch_get_io_base(dev, &iobase)); |
| 33 | ut_asserteq(0x30, iobase); |
| 34 | |
| 35 | return 0; |
| 36 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 37 | DM_TEST(dm_test_pch_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 1260f8c | 2019-02-16 20:24:51 -0700 | [diff] [blame] | 38 | |
| 39 | /* Test sandbox PCH ioctl */ |
| 40 | static int dm_test_pch_ioctl(struct unit_test_state *uts) |
| 41 | { |
| 42 | struct udevice *dev; |
| 43 | char data; |
| 44 | |
| 45 | ut_assertok(uclass_first_device_err(UCLASS_PCH, &dev)); |
| 46 | |
| 47 | ut_asserteq(-ENOSYS, pch_ioctl(dev, PCH_REQ_TEST1, NULL, 0)); |
| 48 | |
| 49 | ut_asserteq('a', pch_ioctl(dev, PCH_REQ_TEST2, "a", 1)); |
| 50 | |
| 51 | ut_asserteq(1, pch_ioctl(dev, PCH_REQ_TEST3, &data, 1)); |
| 52 | ut_asserteq('x', data); |
| 53 | |
| 54 | return 0; |
| 55 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 56 | DM_TEST(dm_test_pch_ioctl, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |