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