dm: core: Require users of devres to include the header
[oweals/u-boot.git] / test / dm / test-fdt.c
index 1fb8b5c248d346f9903663b7727b5e375dae0638..f54db759b65c74872bc417b5b43bde9d0724fe9f 100644 (file)
@@ -12,6 +12,7 @@
 #include <dm/test.h>
 #include <dm/root.h>
 #include <dm/device-internal.h>
+#include <dm/devres.h>
 #include <dm/uclass-internal.h>
 #include <dm/util.h>
 #include <dm/lists.h>
@@ -153,6 +154,64 @@ UCLASS_DRIVER(testprobe) = {
        .flags          = DM_UC_FLAG_SEQ_ALIAS,
 };
 
+struct dm_testdevres_pdata {
+       void *ptr;
+};
+
+struct dm_testdevres_priv {
+       void *ptr;
+       void *ptr_ofdata;
+};
+
+static int testdevres_drv_bind(struct udevice *dev)
+{
+       struct dm_testdevres_pdata *pdata = dev_get_platdata(dev);
+
+       pdata->ptr = devm_kmalloc(dev, TEST_DEVRES_SIZE, 0);
+
+       return 0;
+}
+
+static int testdevres_drv_ofdata_to_platdata(struct udevice *dev)
+{
+       struct dm_testdevres_priv *priv = dev_get_priv(dev);
+
+       priv->ptr_ofdata = devm_kmalloc(dev, TEST_DEVRES_SIZE3, 0);
+
+       return 0;
+}
+
+static int testdevres_drv_probe(struct udevice *dev)
+{
+       struct dm_testdevres_priv *priv = dev_get_priv(dev);
+
+       priv->ptr = devm_kmalloc(dev, TEST_DEVRES_SIZE2, 0);
+
+       return 0;
+}
+
+static const struct udevice_id testdevres_ids[] = {
+       { .compatible = "denx,u-boot-devres-test" },
+       { }
+};
+
+U_BOOT_DRIVER(testdevres_drv) = {
+       .name   = "testdevres_drv",
+       .of_match       = testdevres_ids,
+       .id     = UCLASS_TEST_DEVRES,
+       .bind   = testdevres_drv_bind,
+       .ofdata_to_platdata     = testdevres_drv_ofdata_to_platdata,
+       .probe  = testdevres_drv_probe,
+       .platdata_auto_alloc_size       = sizeof(struct dm_testdevres_pdata),
+       .priv_auto_alloc_size   = sizeof(struct dm_testdevres_priv),
+};
+
+UCLASS_DRIVER(testdevres) = {
+       .name           = "testdevres",
+       .id             = UCLASS_TEST_DEVRES,
+       .flags          = DM_UC_FLAG_SEQ_ALIAS,
+};
+
 int dm_check_devices(struct unit_test_state *uts, int num_devices)
 {
        struct udevice *dev;
@@ -814,3 +873,41 @@ static int dm_test_read_int(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test device_first_child_ofdata_err(), etc. */
+static int dm_test_child_ofdata(struct unit_test_state *uts)
+{
+       struct udevice *bus, *dev;
+       int count;
+
+       ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus));
+       count = 0;
+       device_foreach_child_ofdata_to_platdata(dev, bus) {
+               ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID);
+               ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
+               count++;
+       }
+       ut_asserteq(3, count);
+
+       return 0;
+}
+DM_TEST(dm_test_child_ofdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test device_first_child_err(), etc. */
+static int dm_test_first_child_probe(struct unit_test_state *uts)
+{
+       struct udevice *bus, *dev;
+       int count;
+
+       ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus));
+       count = 0;
+       device_foreach_child_probe(dev, bus) {
+               ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID);
+               ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+               count++;
+       }
+       ut_asserteq(3, count);
+
+       return 0;
+}
+DM_TEST(dm_test_first_child_probe, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);