Re: [PATCH v2 06/21] test: Move some test drivers into their own file

2020-12-28 Thread Simon Glass
At present several test drivers are part of the test file itself. Some of
these are useful for of-platdata tests. Separate them out so we can use
them for other things also.

A few adjustments are needed so this driver can build for sandbox_spl as
well.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/misc/Kconfig|   9 ++
 drivers/misc/Makefile   |   1 +
 drivers/misc/test_drv.c | 230 
 include/dm/test.h   |  18 
 include/test/test.h |   9 ++
 test/dm/bus.c   | 105 +-
 test/dm/test-fdt.c  | 120 -
 7 files changed, 271 insertions(+), 221 deletions(-)
 create mode 100644 drivers/misc/test_drv.c

Applied to u-boot-dm/next, thanks!


[PATCH v2 06/21] test: Move some test drivers into their own file

2020-12-23 Thread Simon Glass
At present several test drivers are part of the test file itself. Some of
these are useful for of-platdata tests. Separate them out so we can use
them for other things also.

A few adjustments are needed so this driver can build for sandbox_spl as
well.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/misc/Kconfig|   9 ++
 drivers/misc/Makefile   |   1 +
 drivers/misc/test_drv.c | 230 
 include/dm/test.h   |  18 
 include/test/test.h |   9 ++
 test/dm/bus.c   | 105 +-
 test/dm/test-fdt.c  | 120 -
 7 files changed, 271 insertions(+), 221 deletions(-)
 create mode 100644 drivers/misc/test_drv.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 29432ae7eb4..7d2a2997797 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -343,6 +343,15 @@ config TEGRA186_BPMP
  can make requests to the BPMP. This driver is similar to an MFD
  driver in the Linux kernel.
 
+config TEST_DRV
+   bool "Enable support for test drivers"
+   default y if SANDBOX
+   help
+ This enables drivers and uclasses that provides a way of testing the
+ operations of memory allocation and driver/uclass methods in driver
+ model. This should only be enabled for testing as it is not useful for
+ anything else.
+
 config TWL4030_LED
bool "Enable TWL4030 LED controller"
help
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 947bd3a647f..d7372037045 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_STM32_RCC) += stm32_rcc.o
 obj-$(CONFIG_SYS_DPAA_QBMAN) += fsl_portals.o
 obj-$(CONFIG_TEGRA186_BPMP) += tegra186_bpmp.o
 obj-$(CONFIG_TEGRA_CAR) += tegra_car.o
+obj-$(CONFIG_TEST_DRV) += test_drv.o
 obj-$(CONFIG_TWL4030_LED) += twl4030_led.o
 obj-$(CONFIG_VEXPRESS_CONFIG) += vexpress_config.o
 obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
diff --git a/drivers/misc/test_drv.c b/drivers/misc/test_drv.c
new file mode 100644
index 000..a163312b108
--- /dev/null
+++ b/drivers/misc/test_drv.c
@@ -0,0 +1,230 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2014 Google, Inc
+ */
+
+#include 
+#include 
+#include 
+
+/* Records the last testbus device that was removed */
+static struct udevice *testbus_removed;
+
+struct udevice *testbus_get_clear_removed(void)
+{
+   struct udevice *removed = testbus_removed;
+
+   testbus_removed = NULL;
+
+   return removed;
+}
+
+static int testbus_drv_probe(struct udevice *dev)
+{
+   if (!CONFIG_IS_ENABLED(OF_PLATDATA)) {
+   int ret;
+
+   ret = dm_scan_fdt_dev(dev);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
+static int testbus_child_post_bind(struct udevice *dev)
+{
+   struct dm_test_parent_plat *plat;
+
+   plat = dev_get_parent_plat(dev);
+   plat->bind_flag = 1;
+   plat->uclass_bind_flag = 2;
+
+   return 0;
+}
+
+static int testbus_child_pre_probe(struct udevice *dev)
+{
+   struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
+
+   parent_data->flag += TEST_FLAG_CHILD_PROBED;
+
+   return 0;
+}
+
+static int testbus_child_pre_probe_uclass(struct udevice *dev)
+{
+   struct dm_test_priv *priv = dev_get_priv(dev);
+
+   priv->uclass_flag++;
+
+   return 0;
+}
+
+static int testbus_child_post_probe_uclass(struct udevice *dev)
+{
+   struct dm_test_priv *priv = dev_get_priv(dev);
+
+   priv->uclass_postp++;
+
+   return 0;
+}
+
+static int testbus_child_post_remove(struct udevice *dev)
+{
+   struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
+
+   parent_data->flag += TEST_FLAG_CHILD_REMOVED;
+   testbus_removed = dev;
+
+   return 0;
+}
+
+static const struct udevice_id testbus_ids[] = {
+   {
+   .compatible = "denx,u-boot-test-bus",
+   .data = DM_TEST_TYPE_FIRST },
+   { }
+};
+
+U_BOOT_DRIVER(testbus_drv) = {
+   .name   = "testbus_drv",
+   .of_match   = testbus_ids,
+   .id = UCLASS_TEST_BUS,
+   .probe  = testbus_drv_probe,
+   .child_post_bind = testbus_child_post_bind,
+   .priv_auto  = sizeof(struct dm_test_priv),
+   .plat_auto  = sizeof(struct dm_test_pdata),
+   .per_child_auto = sizeof(struct dm_test_parent_data),
+   .per_child_plat_auto= sizeof(struct dm_test_parent_plat),
+   .child_pre_probe = testbus_child_pre_probe,
+   .child_post_remove = testbus_child_post_remove,
+};
+
+UCLASS_DRIVER(testbus) = {
+   .name   = "testbus",
+   .id = UCLASS_TEST_BUS,
+   .flags  = DM_UC_FLAG_SEQ_ALIAS,
+   .child_pre_probe = testbus_child_pre_probe_uclass,
+   .child_post_probe = testbus_child_post_probe_uclass,
+};
+
+static int testfdt_drv_ping(struct udevice *dev, int