mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-07-07 15:01:59 +00:00
sandbox: pch: Add a test for the PCH uclass
This uclass currently has no tests. Add a sandbox driver and some simple tests to provide basic coverage. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> [bmeng: Use "sandbox,pch" for the compatible string, for consistency] Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
parent
c882163b09
commit
b45c833c71
6 changed files with 119 additions and 0 deletions
|
@ -407,6 +407,10 @@
|
||||||
compatible = "sandbox,mmc";
|
compatible = "sandbox,mmc";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pch {
|
||||||
|
compatible = "sandbox,pch";
|
||||||
|
};
|
||||||
|
|
||||||
pci0: pci-controller0 {
|
pci0: pci-controller0 {
|
||||||
compatible = "sandbox,pci";
|
compatible = "sandbox,pci";
|
||||||
device_type = "pci";
|
device_type = "pci";
|
||||||
|
|
|
@ -161,4 +161,12 @@ int sandbox_get_setup_called(struct udevice *dev);
|
||||||
*/
|
*/
|
||||||
int sandbox_get_sound_sum(struct udevice *dev);
|
int sandbox_get_sound_sum(struct udevice *dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sandbox_get_pch_spi_protect() - Get the PCI SPI protection status
|
||||||
|
*
|
||||||
|
* @dev: Device to check
|
||||||
|
* @return 0 if not protected, 1 if protected
|
||||||
|
*/
|
||||||
|
int sandbox_get_pch_spi_protect(struct udevice *dev);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,3 +3,4 @@
|
||||||
obj-y += pch-uclass.o
|
obj-y += pch-uclass.o
|
||||||
obj-y += pch7.o
|
obj-y += pch7.o
|
||||||
obj-y += pch9.o
|
obj-y += pch9.o
|
||||||
|
obj-$(CONFIG_SANDBOX) += sandbox_pch.o
|
||||||
|
|
69
drivers/pch/sandbox_pch.c
Normal file
69
drivers/pch/sandbox_pch.c
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
/*
|
||||||
|
* Copyright 2018 Google LLC
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <dm.h>
|
||||||
|
#include <pch.h>
|
||||||
|
|
||||||
|
struct sandbox_pch_priv {
|
||||||
|
bool protect;
|
||||||
|
};
|
||||||
|
|
||||||
|
int sandbox_get_pch_spi_protect(struct udevice *dev)
|
||||||
|
{
|
||||||
|
struct sandbox_pch_priv *priv = dev_get_priv(dev);
|
||||||
|
|
||||||
|
return priv->protect;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sandbox_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
|
||||||
|
{
|
||||||
|
*sbasep = 0x10;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sandbox_pch_set_spi_protect(struct udevice *dev, bool protect)
|
||||||
|
{
|
||||||
|
struct sandbox_pch_priv *priv = dev_get_priv(dev);
|
||||||
|
|
||||||
|
priv->protect = protect;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sandbox_pch_get_gpio_base(struct udevice *dev, u32 *gbasep)
|
||||||
|
{
|
||||||
|
*gbasep = 0x20;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sandbox_pch_get_io_base(struct udevice *dev, u32 *iobasep)
|
||||||
|
{
|
||||||
|
*iobasep = 0x30;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct pch_ops sandbox_pch_ops = {
|
||||||
|
.get_spi_base = sandbox_pch_get_spi_base,
|
||||||
|
.set_spi_protect = sandbox_pch_set_spi_protect,
|
||||||
|
.get_gpio_base = sandbox_pch_get_gpio_base,
|
||||||
|
.get_io_base = sandbox_pch_get_io_base,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct udevice_id sandbox_pch_ids[] = {
|
||||||
|
{ .compatible = "sandbox,pch" },
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
|
U_BOOT_DRIVER(sandbox_pch_drv) = {
|
||||||
|
.name = "sandbox-pch",
|
||||||
|
.id = UCLASS_PCH,
|
||||||
|
.of_match = sandbox_pch_ids,
|
||||||
|
.ops = &sandbox_pch_ops,
|
||||||
|
.priv_auto_alloc_size = sizeof(struct sandbox_pch_priv),
|
||||||
|
};
|
|
@ -30,6 +30,7 @@ obj-y += ofnode.o
|
||||||
obj-$(CONFIG_OSD) += osd.o
|
obj-$(CONFIG_OSD) += osd.o
|
||||||
obj-$(CONFIG_DM_VIDEO) += panel.o
|
obj-$(CONFIG_DM_VIDEO) += panel.o
|
||||||
obj-$(CONFIG_DM_PCI) += pci.o
|
obj-$(CONFIG_DM_PCI) += pci.o
|
||||||
|
obj-$(CONFIG_PCH) += pch.o
|
||||||
obj-$(CONFIG_PHY) += phy.o
|
obj-$(CONFIG_PHY) += phy.o
|
||||||
obj-$(CONFIG_POWER_DOMAIN) += power-domain.o
|
obj-$(CONFIG_POWER_DOMAIN) += power-domain.o
|
||||||
obj-$(CONFIG_DM_PWM) += pwm.o
|
obj-$(CONFIG_DM_PWM) += pwm.o
|
||||||
|
|
36
test/dm/pch.c
Normal file
36
test/dm/pch.c
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
/*
|
||||||
|
* Copyright 2018 Google LLC
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <dm.h>
|
||||||
|
#include <pch.h>
|
||||||
|
#include <asm/test.h>
|
||||||
|
#include <dm/test.h>
|
||||||
|
#include <test/ut.h>
|
||||||
|
|
||||||
|
/* Test that sandbox PCH works correctly */
|
||||||
|
static int dm_test_pch_base(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
u32 gbase, iobase;
|
||||||
|
ulong sbase;
|
||||||
|
|
||||||
|
ut_assertok(uclass_first_device_err(UCLASS_PCH, &dev));
|
||||||
|
ut_assertok(pch_get_spi_base(dev, &sbase));
|
||||||
|
ut_asserteq(0x10, sbase);
|
||||||
|
|
||||||
|
ut_asserteq(0, sandbox_get_pch_spi_protect(dev));
|
||||||
|
ut_assertok(pch_set_spi_protect(dev, true));
|
||||||
|
ut_asserteq(1, sandbox_get_pch_spi_protect(dev));
|
||||||
|
|
||||||
|
ut_assertok(pch_get_gpio_base(dev, &gbase));
|
||||||
|
ut_asserteq(0x20, gbase);
|
||||||
|
|
||||||
|
ut_assertok(pch_get_io_base(dev, &iobase));
|
||||||
|
ut_asserteq(0x30, iobase);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DM_TEST(dm_test_pch_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
Loading…
Add table
Add a link
Reference in a new issue