From 04035fd36c9c793ab7b6e7c4513fe6a053daf5dd Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 6 Jul 2015 12:54:35 -0600 Subject: [PATCH] dm: test: Add a test for the system controller uclass Add a test to confirm that we can access system controllers and find their driver data. Signed-off-by: Simon Glass --- arch/sandbox/dts/test.dts | 10 ++++++++++ arch/sandbox/include/asm/test.h | 8 ++++++++ configs/sandbox_defconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/syscon_sandbox.c | 27 +++++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/syscon.c | 31 +++++++++++++++++++++++++++++++ 7 files changed, 79 insertions(+) create mode 100644 drivers/misc/syscon_sandbox.c create mode 100644 test/dm/syscon.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 4b9861835e..51611009ae 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -240,6 +240,16 @@ }; }; + syscon@0 { + compatible = "sandbox,syscon0"; + reg = <0x10>; + }; + + syscon@1 { + compatible = "sandbox,syscon1"; + reg = <0x20>; + }; + uart0: serial { compatible = "sandbox,serial"; u-boot,dm-pre-reloc; diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 28e9c09c06..d3c7851bb5 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -28,6 +28,14 @@ enum { PERIPH_ID_COUNT, }; +/* System controller driver data */ +enum { + SYSCON0 = 32, + SYSCON1, + + SYSCON_COUNT +}; + /** * sandbox_i2c_set_test_mode() - set test mode for running unit tests * diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 56d55ac5b8..553574682d 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -51,3 +51,4 @@ CONFIG_RAM=y CONFIG_DM_MMC=y CONFIG_LED=y CONFIG_LED_GPIO=y +CONFIG_SYSCON=y diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 629de25a42..5218b91c0b 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -29,6 +29,7 @@ endif obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o obj-$(CONFIG_STATUS_LED) += status_led.o obj-$(CONFIG_SANDBOX) += swap_case.o +obj-$(CONFIG_SANDBOX) += syscon_sandbox.o obj-$(CONFIG_TWL4030_LED) += twl4030_led.o obj-$(CONFIG_FSL_IFC) += fsl_ifc.o obj-$(CONFIG_FSL_SEC_MON) += fsl_sec_mon.o diff --git a/drivers/misc/syscon_sandbox.c b/drivers/misc/syscon_sandbox.c new file mode 100644 index 0000000000..ccfab3ef98 --- /dev/null +++ b/drivers/misc/syscon_sandbox.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2015 Google, Inc + * Written by Simon Glass + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +static const struct udevice_id sandbox_syscon_ids[] = { + { .compatible = "sandbox,syscon0", .data = SYSCON0 }, + { .compatible = "sandbox,syscon1", .data = SYSCON1 }, + { } +}; + +U_BOOT_DRIVER(sandbox_syscon) = { + .name = "sandbox_syscon", + .id = UCLASS_SYSCON, + .of_match = sandbox_syscon_ids, +}; diff --git a/test/dm/Makefile b/test/dm/Makefile index 6242a0265a..99cd21fd06 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_RESET) += reset.o obj-$(CONFIG_DM_RTC) += rtc.o obj-$(CONFIG_DM_SPI_FLASH) += sf.o obj-$(CONFIG_DM_SPI) += spi.o +obj-y += syscon.o obj-$(CONFIG_DM_USB) += usb.o obj-$(CONFIG_DM_PMIC) += pmic.o obj-$(CONFIG_DM_REGULATOR) += regulator.o diff --git a/test/dm/syscon.c b/test/dm/syscon.c new file mode 100644 index 0000000000..36424816b8 --- /dev/null +++ b/test/dm/syscon.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* Base test of system controllers */ +static int dm_test_syscon_base(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev)); + ut_asserteq(SYSCON0, dev->driver_data); + + ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev)); + ut_asserteq(SYSCON1, dev->driver_data); + + ut_asserteq(-ENODEV, uclass_get_device(UCLASS_SYSCON, 2, &dev)); + + return 0; +} +DM_TEST(dm_test_syscon_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -- 2.39.5