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