2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-02-26 22:59:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fdtdec.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2014-02-26 22:59:21 +00:00
|
|
|
#include <malloc.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2014-02-26 22:59:21 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <dm/test.h>
|
2023-01-31 10:05:15 +00:00
|
|
|
#include <dm/read.h>
|
2014-02-26 22:59:21 +00:00
|
|
|
#include <dm/root.h>
|
2017-04-24 02:10:44 +00:00
|
|
|
#include <dm/device-internal.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <dm/devres.h>
|
2014-02-26 22:59:21 +00:00
|
|
|
#include <dm/uclass-internal.h>
|
|
|
|
#include <dm/util.h>
|
2018-06-26 06:46:49 +00:00
|
|
|
#include <dm/of_access.h>
|
2021-05-21 10:25:00 +00:00
|
|
|
#include <linux/ioport.h>
|
2020-07-19 16:15:37 +00:00
|
|
|
#include <test/test.h>
|
2015-05-20 19:27:27 +00:00
|
|
|
#include <test/ut.h>
|
2014-02-26 22:59:21 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2017-04-24 02:10:44 +00:00
|
|
|
struct dm_testprobe_pdata {
|
|
|
|
int probe_err;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int testprobe_drv_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct dm_testprobe_pdata *pdata = dev_get_plat(dev);
|
2017-04-24 02:10:44 +00:00
|
|
|
|
|
|
|
return pdata->probe_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id testprobe_ids[] = {
|
|
|
|
{ .compatible = "denx,u-boot-probe-test" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(testprobe_drv) = {
|
|
|
|
.name = "testprobe_drv",
|
|
|
|
.of_match = testprobe_ids,
|
|
|
|
.id = UCLASS_TEST_PROBE,
|
|
|
|
.probe = testprobe_drv_probe,
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct dm_testprobe_pdata),
|
2017-04-24 02:10:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UCLASS_DRIVER(testprobe) = {
|
|
|
|
.name = "testprobe",
|
|
|
|
.id = UCLASS_TEST_PROBE,
|
|
|
|
.flags = DM_UC_FLAG_SEQ_ALIAS,
|
|
|
|
};
|
|
|
|
|
2019-12-30 04:19:25 +00:00
|
|
|
struct dm_testdevres_pdata {
|
|
|
|
void *ptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dm_testdevres_priv {
|
|
|
|
void *ptr;
|
2019-12-30 04:19:28 +00:00
|
|
|
void *ptr_ofdata;
|
2019-12-30 04:19:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int testdevres_drv_bind(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct dm_testdevres_pdata *pdata = dev_get_plat(dev);
|
2019-12-30 04:19:25 +00:00
|
|
|
|
|
|
|
pdata->ptr = devm_kmalloc(dev, TEST_DEVRES_SIZE, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int testdevres_drv_of_to_plat(struct udevice *dev)
|
2019-12-30 04:19:28 +00:00
|
|
|
{
|
|
|
|
struct dm_testdevres_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
priv->ptr_ofdata = devm_kmalloc(dev, TEST_DEVRES_SIZE3, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-30 04:19:25 +00:00
|
|
|
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,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = testdevres_drv_of_to_plat,
|
2019-12-30 04:19:25 +00:00
|
|
|
.probe = testdevres_drv_probe,
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct dm_testdevres_pdata),
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct dm_testdevres_priv),
|
2019-12-30 04:19:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UCLASS_DRIVER(testdevres) = {
|
|
|
|
.name = "testdevres",
|
|
|
|
.id = UCLASS_TEST_DEVRES,
|
|
|
|
.flags = DM_UC_FLAG_SEQ_ALIAS,
|
|
|
|
};
|
|
|
|
|
2015-05-20 19:27:27 +00:00
|
|
|
int dm_check_devices(struct unit_test_state *uts, int num_devices)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
2014-05-22 10:43:05 +00:00
|
|
|
struct udevice *dev;
|
2014-02-26 22:59:21 +00:00
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now check that the ping adds are what we expect. This is using the
|
|
|
|
* ping-add property in each node.
|
|
|
|
*/
|
2014-07-23 12:55:18 +00:00
|
|
|
for (i = 0; i < num_devices; i++) {
|
2014-02-26 22:59:21 +00:00
|
|
|
uint32_t base;
|
|
|
|
|
|
|
|
ret = uclass_get_device(UCLASS_TEST_FDT, i, &dev);
|
|
|
|
ut_assert(!ret);
|
|
|
|
|
|
|
|
/*
|
2014-07-23 12:54:57 +00:00
|
|
|
* Get the 'ping-expect' property, which tells us what the
|
2020-12-03 23:55:18 +00:00
|
|
|
* ping add should be. We don't use the plat because we
|
2014-07-23 12:54:57 +00:00
|
|
|
* want to test the code that sets that up
|
|
|
|
* (testfdt_drv_probe()).
|
2014-02-26 22:59:21 +00:00
|
|
|
*/
|
2017-01-17 23:52:55 +00:00
|
|
|
base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev),
|
2014-07-23 12:54:57 +00:00
|
|
|
"ping-expect");
|
2014-02-26 22:59:21 +00:00
|
|
|
debug("dev=%d, base=%d: %s\n", i, base,
|
2017-01-17 23:52:55 +00:00
|
|
|
fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL));
|
2014-02-26 22:59:21 +00:00
|
|
|
|
2015-05-20 19:27:27 +00:00
|
|
|
ut_assert(!dm_check_operations(uts, dev, base,
|
2014-02-26 22:59:21 +00:00
|
|
|
dev_get_priv(dev)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-23 12:55:18 +00:00
|
|
|
|
|
|
|
/* Test that FDT-based binding works correctly */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_fdt(struct unit_test_state *uts)
|
2014-07-23 12:55:18 +00:00
|
|
|
{
|
2020-09-11 08:13:35 +00:00
|
|
|
const int num_devices = 9;
|
2014-07-23 12:55:18 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
struct uclass *uc;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
2020-11-29 00:50:10 +00:00
|
|
|
ret = dm_extended_scan(false);
|
2014-07-23 12:55:18 +00:00
|
|
|
ut_assert(!ret);
|
|
|
|
|
|
|
|
ret = uclass_get(UCLASS_TEST_FDT, &uc);
|
|
|
|
ut_assert(!ret);
|
|
|
|
|
|
|
|
/* These are num_devices compatible root-level device tree nodes */
|
|
|
|
ut_asserteq(num_devices, list_count_items(&uc->dev_head));
|
|
|
|
|
2015-01-25 15:27:00 +00:00
|
|
|
/* Each should have platform data but no private data */
|
2014-07-23 12:55:18 +00:00
|
|
|
for (i = 0; i < num_devices; i++) {
|
|
|
|
ret = uclass_find_device(UCLASS_TEST_FDT, i, &dev);
|
|
|
|
ut_assert(!ret);
|
|
|
|
ut_assert(!dev_get_priv(dev));
|
2020-12-23 02:30:28 +00:00
|
|
|
ut_assert(dev_get_plat(dev));
|
2014-07-23 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 19:27:27 +00:00
|
|
|
ut_assertok(dm_check_devices(uts, num_devices));
|
2014-07-23 12:55:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-02-26 22:59:21 +00:00
|
|
|
DM_TEST(dm_test_fdt, 0);
|
2014-07-23 12:55:03 +00:00
|
|
|
|
2019-01-31 15:31:00 +00:00
|
|
|
static int dm_test_alias_highest_id(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2021-02-25 15:51:11 +00:00
|
|
|
ret = dev_read_alias_highest_id("ethernet");
|
sandbox: net: Add aliases for ethernet devices
Commit f3dd213e15 ("net: introduce helpers to get PHY ofnode from MAC")
changed the ethernet sequence assignment from
uclass 36: ethernet
0 * eth@10002000 @ 05813460, seq 0
1 * eth@10003000 @ 05813550, seq 5
2 * sbe5 @ 05813640, seq 3
3 * eth@10004000 @ 05813730, seq 6
4 * dsa-test-eth @ 05813820, seq 4
5 * lan0 @ 05813a30, seq 2
6 * lan1 @ 05813b50, seq 7
to
uclass 36: ethernet
0 * eth@10002000 @ 03813630, seq 0
1 * eth@10003000 @ 03813720, seq 5
2 * sbe5 @ 03813810, seq 3
3 * eth@10004000 @ 03813900, seq 6
4 phy-test-eth @ 038139f0, seq 7
5 * dsa-test-eth @ 03813ae0, seq 4
6 * lan0 @ 03813cf0, seq 2
7 * lan1 @ 03813e10, seq 8
This caused the mac address assignment to switch around. Avoid this in
the future by assigning aliases for all ethernet devices. This reverts
the sequence to what it was before the aformentioned commit (with
phy-test-eth as seq 8). There is no ethernet1 for whatever reason.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
2022-05-05 17:11:30 +00:00
|
|
|
ut_asserteq(8, ret);
|
2019-01-31 15:31:00 +00:00
|
|
|
|
|
|
|
ret = dev_read_alias_highest_id("gpio");
|
2020-01-13 10:35:14 +00:00
|
|
|
ut_asserteq(3, ret);
|
2019-01-31 15:31:00 +00:00
|
|
|
|
|
|
|
ret = dev_read_alias_highest_id("pci");
|
|
|
|
ut_asserteq(2, ret);
|
|
|
|
|
|
|
|
ret = dev_read_alias_highest_id("i2c");
|
|
|
|
ut_asserteq(0, ret);
|
|
|
|
|
|
|
|
ret = dev_read_alias_highest_id("deadbeef");
|
|
|
|
ut_asserteq(-1, ret);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_alias_highest_id, 0);
|
|
|
|
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_fdt_pre_reloc(struct unit_test_state *uts)
|
2014-07-23 12:55:03 +00:00
|
|
|
{
|
|
|
|
struct uclass *uc;
|
|
|
|
int ret;
|
|
|
|
|
2020-11-29 00:50:09 +00:00
|
|
|
ret = dm_scan_fdt(true);
|
2014-07-23 12:55:03 +00:00
|
|
|
ut_assert(!ret);
|
|
|
|
|
|
|
|
ret = uclass_get(UCLASS_TEST_FDT, &uc);
|
|
|
|
ut_assert(!ret);
|
|
|
|
|
2018-10-11 05:07:01 +00:00
|
|
|
/*
|
|
|
|
* These are 2 pre-reloc devices:
|
|
|
|
* one with "u-boot,dm-pre-reloc" property (a-test node), and the other
|
|
|
|
* one whose driver marked with DM_FLAG_PRE_RELOC flag (h-test node).
|
|
|
|
*/
|
|
|
|
ut_asserteq(2, list_count_items(&uc->dev_head));
|
2014-07-23 12:55:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_fdt_pre_reloc, 0);
|
2014-07-23 12:55:12 +00:00
|
|
|
|
|
|
|
/* Test that sequence numbers are allocated properly */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
|
2014-07-23 12:55:12 +00:00
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
/* A few basic santiy tests */
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, &dev));
|
2014-07-23 12:55:12 +00:00
|
|
|
ut_asserteq_str("b-test", dev->name);
|
2020-12-17 04:20:26 +00:00
|
|
|
ut_asserteq(3, dev_seq(dev));
|
2014-07-23 12:55:12 +00:00
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, &dev));
|
2014-07-23 12:55:12 +00:00
|
|
|
ut_asserteq_str("a-test", dev->name);
|
2020-12-17 04:20:26 +00:00
|
|
|
ut_asserteq(8, dev_seq(dev));
|
2014-07-23 12:55:12 +00:00
|
|
|
|
2020-12-17 04:20:26 +00:00
|
|
|
/*
|
|
|
|
* This device has no alias so gets the next value after all available
|
|
|
|
* aliases. The last alias is testfdt12
|
|
|
|
*/
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 13, &dev));
|
2020-12-17 04:20:26 +00:00
|
|
|
ut_asserteq_str("d-test", dev->name);
|
|
|
|
ut_asserteq(13, dev_seq(dev));
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9,
|
2020-12-17 04:20:26 +00:00
|
|
|
&dev));
|
2014-07-23 12:55:12 +00:00
|
|
|
ut_asserteq_ptr(NULL, dev);
|
|
|
|
|
|
|
|
/* Test aliases */
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 6, &dev));
|
|
|
|
ut_asserteq_str("e-test", dev->name);
|
2020-12-17 04:20:26 +00:00
|
|
|
ut_asserteq(6, dev_seq(dev));
|
2014-07-23 12:55:12 +00:00
|
|
|
|
2014-07-23 12:55:18 +00:00
|
|
|
/*
|
|
|
|
* Note that c-test nodes are not probed since it is not a top-level
|
|
|
|
* node
|
|
|
|
*/
|
2014-07-23 12:55:12 +00:00
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 3, &dev));
|
|
|
|
ut_asserteq_str("b-test", dev->name);
|
2020-12-17 04:20:26 +00:00
|
|
|
ut_asserteq(3, dev_seq(dev));
|
2014-07-23 12:55:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* d-test wants sequence number 3 also, but it can't have it because
|
|
|
|
* b-test gets it first.
|
|
|
|
*/
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 2, &dev));
|
|
|
|
ut_asserteq_str("d-test", dev->name);
|
2020-12-17 04:20:26 +00:00
|
|
|
ut_asserteq(13, dev_seq(dev));
|
|
|
|
|
|
|
|
/* g-test gets the next value after f-test */
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 15, &dev));
|
|
|
|
ut_asserteq_str("g-test", dev->name);
|
|
|
|
ut_asserteq(15, dev_seq(dev));
|
|
|
|
|
|
|
|
/* And we should still have holes in our sequence numbers */
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 0,
|
2020-12-17 04:20:26 +00:00
|
|
|
&dev));
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 1,
|
2020-12-17 04:20:26 +00:00
|
|
|
&dev));
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 2,
|
2020-12-17 04:20:26 +00:00
|
|
|
&dev));
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 4,
|
2020-12-17 04:20:26 +00:00
|
|
|
&dev));
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 7,
|
2020-12-17 04:20:26 +00:00
|
|
|
&dev));
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9,
|
2020-12-17 04:20:26 +00:00
|
|
|
&dev));
|
|
|
|
ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 10,
|
2020-12-17 04:20:29 +00:00
|
|
|
&dev));
|
2020-12-17 04:20:26 +00:00
|
|
|
ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 11,
|
2020-12-17 04:20:29 +00:00
|
|
|
&dev));
|
2020-06-01 23:47:09 +00:00
|
|
|
|
2014-07-23 12:55:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_fdt_uclass_seq, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-07-23 12:55:14 +00:00
|
|
|
|
2020-12-17 04:20:27 +00:00
|
|
|
/* More tests for sequence numbers */
|
|
|
|
static int dm_test_fdt_uclass_seq_manual(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since DM_UC_FLAG_NO_AUTO_SEQ is set for this uclass, only testfdtm1
|
|
|
|
* should get a sequence number assigned
|
|
|
|
*/
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_FDT_MANUAL, 0, &dev));
|
|
|
|
ut_asserteq_str("testfdtm0", dev->name);
|
|
|
|
ut_asserteq(-1, dev_seq(dev));
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT_MANUAL, 1, &dev));
|
|
|
|
ut_asserteq_str("testfdtm1", dev->name);
|
|
|
|
ut_asserteq(1, dev_seq(dev));
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_FDT_MANUAL, 2, &dev));
|
|
|
|
ut_asserteq_str("testfdtm2", dev->name);
|
|
|
|
ut_asserteq(-1, dev_seq(dev));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_fdt_uclass_seq_manual, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
|
|
|
|
2020-12-17 04:20:32 +00:00
|
|
|
static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
ofnode node;
|
|
|
|
|
|
|
|
/* Check creating a device with an alias */
|
|
|
|
node = ofnode_path("/some-bus/c-test@1");
|
2021-02-03 13:01:09 +00:00
|
|
|
ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test),
|
2020-12-17 04:20:32 +00:00
|
|
|
"c-test@1", NULL, node, &dev));
|
|
|
|
ut_asserteq(12, dev_seq(dev));
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev));
|
|
|
|
ut_asserteq_str("c-test@1", dev->name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now bind a device without an alias. It should not get the next
|
|
|
|
* sequence number after all aliases, and existing bound devices. The
|
|
|
|
* last alias is 12, so we have:
|
|
|
|
*
|
|
|
|
* 13 d-test
|
|
|
|
* 14 f-test
|
|
|
|
* 15 g-test
|
|
|
|
* 16 h-test
|
|
|
|
* 17 another-test
|
|
|
|
* 18 chosen-test
|
|
|
|
*
|
|
|
|
* So next available is 19
|
|
|
|
*/
|
2021-02-03 13:01:09 +00:00
|
|
|
ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test),
|
2020-12-17 04:20:32 +00:00
|
|
|
"fred", NULL, ofnode_null(), &dev));
|
|
|
|
ut_asserteq(19, dev_seq(dev));
|
|
|
|
|
2021-02-03 13:01:09 +00:00
|
|
|
ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test),
|
2020-12-17 04:20:32 +00:00
|
|
|
"fred2", NULL, ofnode_null(), &dev));
|
|
|
|
ut_asserteq(20, dev_seq(dev));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_fdt_uclass_seq_more, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
|
|
|
|
2014-07-23 12:55:14 +00:00
|
|
|
/* Test that we can find a device by device tree offset */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_fdt_offset(struct unit_test_state *uts)
|
2014-07-23 12:55:14 +00:00
|
|
|
{
|
|
|
|
const void *blob = gd->fdt_blob;
|
|
|
|
struct udevice *dev;
|
|
|
|
int node;
|
|
|
|
|
|
|
|
node = fdt_path_offset(blob, "/e-test");
|
|
|
|
ut_assert(node > 0);
|
|
|
|
ut_assertok(uclass_get_device_by_of_offset(UCLASS_TEST_FDT, node,
|
|
|
|
&dev));
|
|
|
|
ut_asserteq_str("e-test", dev->name);
|
|
|
|
|
|
|
|
/* This node should not be bound */
|
|
|
|
node = fdt_path_offset(blob, "/junk");
|
|
|
|
ut_assert(node > 0);
|
|
|
|
ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT,
|
|
|
|
node, &dev));
|
|
|
|
|
|
|
|
/* This is not a top level node so should not be probed */
|
2014-07-23 12:55:18 +00:00
|
|
|
node = fdt_path_offset(blob, "/some-bus/c-test@5");
|
2014-07-23 12:55:14 +00:00
|
|
|
ut_assert(node > 0);
|
|
|
|
ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT,
|
|
|
|
node, &dev));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-19 02:09:44 +00:00
|
|
|
DM_TEST(dm_test_fdt_offset,
|
2020-07-29 01:41:12 +00:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
|
2017-04-24 02:10:44 +00:00
|
|
|
|
|
|
|
/**
|
2022-10-12 19:57:50 +00:00
|
|
|
* Test various error conditions with uclass_first_device(),
|
|
|
|
* uclass_next_device(), and uclass_probe_all()
|
2017-04-24 02:10:44 +00:00
|
|
|
*/
|
2022-10-12 19:57:50 +00:00
|
|
|
static int dm_test_first_next_device_probeall(struct unit_test_state *uts)
|
2017-04-24 02:10:44 +00:00
|
|
|
{
|
|
|
|
struct dm_testprobe_pdata *pdata;
|
|
|
|
struct udevice *dev, *parent = NULL;
|
|
|
|
int count;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* There should be 4 devices */
|
2022-10-12 19:58:09 +00:00
|
|
|
for (uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0;
|
2017-04-24 02:10:44 +00:00
|
|
|
dev;
|
2022-10-12 19:58:09 +00:00
|
|
|
uclass_next_device(&dev)) {
|
2017-04-24 02:10:44 +00:00
|
|
|
count++;
|
|
|
|
parent = dev_get_parent(dev);
|
|
|
|
}
|
|
|
|
ut_asserteq(4, count);
|
|
|
|
|
|
|
|
/* Remove them and try again, with an error on the second one */
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 1, &dev));
|
2020-12-03 23:55:20 +00:00
|
|
|
pdata = dev_get_plat(dev);
|
2017-04-24 02:10:44 +00:00
|
|
|
pdata->probe_err = -ENOMEM;
|
|
|
|
device_remove(parent, DM_REMOVE_NORMAL);
|
2022-10-12 19:58:09 +00:00
|
|
|
for (ret = uclass_first_device_check(UCLASS_TEST_PROBE, &dev),
|
|
|
|
count = 0;
|
|
|
|
dev;
|
|
|
|
ret = uclass_next_device_check(&dev)) {
|
|
|
|
if (!ret)
|
|
|
|
count++;
|
|
|
|
else
|
|
|
|
ut_asserteq(-ENOMEM, ret);
|
|
|
|
parent = dev_get_parent(dev);
|
|
|
|
}
|
|
|
|
ut_asserteq(3, count);
|
2017-04-24 02:10:44 +00:00
|
|
|
|
|
|
|
/* Now an error on the first one */
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 0, &dev));
|
2020-12-03 23:55:20 +00:00
|
|
|
pdata = dev_get_plat(dev);
|
2017-04-24 02:10:44 +00:00
|
|
|
pdata->probe_err = -ENOENT;
|
|
|
|
device_remove(parent, DM_REMOVE_NORMAL);
|
2022-10-12 19:58:09 +00:00
|
|
|
for (uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0;
|
|
|
|
dev;
|
|
|
|
uclass_next_device(&dev)) {
|
|
|
|
count++;
|
|
|
|
parent = dev_get_parent(dev);
|
|
|
|
}
|
|
|
|
ut_asserteq(2, count);
|
2017-04-24 02:10:44 +00:00
|
|
|
|
2022-10-12 19:57:50 +00:00
|
|
|
/* Now that broken devices are set up test probe_all */
|
|
|
|
device_remove(parent, DM_REMOVE_NORMAL);
|
|
|
|
/* There are broken devices so an error should be returned */
|
|
|
|
ut_assert(uclass_probe_all(UCLASS_TEST_PROBE) < 0);
|
|
|
|
/* but non-error device should be probed nonetheless */
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 2, &dev));
|
|
|
|
ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 3, &dev));
|
|
|
|
ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
|
|
|
|
|
2017-04-24 02:10:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2022-10-12 19:57:50 +00:00
|
|
|
DM_TEST(dm_test_first_next_device_probeall,
|
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2017-04-24 02:10:45 +00:00
|
|
|
|
2020-02-06 16:54:49 +00:00
|
|
|
/* Test iteration through devices in a uclass */
|
|
|
|
static int dm_test_uclass_foreach(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
struct uclass *uc;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
uclass_id_foreach_dev(UCLASS_TEST_FDT, dev, uc)
|
|
|
|
count++;
|
2020-09-11 08:13:35 +00:00
|
|
|
ut_asserteq(9, count);
|
2020-02-06 16:54:49 +00:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
uclass_foreach_dev(dev, uc)
|
|
|
|
count++;
|
2020-09-11 08:13:35 +00:00
|
|
|
ut_asserteq(9, count);
|
2020-02-06 16:54:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_uclass_foreach, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-02-06 16:54:49 +00:00
|
|
|
|
2017-04-24 02:10:45 +00:00
|
|
|
/**
|
|
|
|
* check_devices() - Check return values and pointers
|
|
|
|
*
|
|
|
|
* This runs through a full sequence of uclass_first_device_check()...
|
|
|
|
* uclass_next_device_check() checking that the return values and devices
|
|
|
|
* are correct.
|
|
|
|
*
|
|
|
|
* @uts: Test state
|
|
|
|
* @devlist: List of expected devices
|
|
|
|
* @mask: Indicates which devices should return an error. Device n should
|
|
|
|
* return error (-NOENT - n) if bit n is set, or no error (i.e. 0) if
|
|
|
|
* bit n is clear.
|
|
|
|
*/
|
|
|
|
static int check_devices(struct unit_test_state *uts,
|
|
|
|
struct udevice *devlist[], int mask)
|
|
|
|
{
|
|
|
|
int expected_ret;
|
|
|
|
struct udevice *dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
expected_ret = (mask & 1) ? -ENOENT : 0;
|
|
|
|
mask >>= 1;
|
|
|
|
ut_asserteq(expected_ret,
|
|
|
|
uclass_first_device_check(UCLASS_TEST_PROBE, &dev));
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
ut_asserteq_ptr(devlist[i], dev);
|
|
|
|
expected_ret = (mask & 1) ? -ENOENT - (i + 1) : 0;
|
|
|
|
mask >>= 1;
|
|
|
|
ut_asserteq(expected_ret, uclass_next_device_check(&dev));
|
|
|
|
}
|
|
|
|
ut_asserteq_ptr(NULL, dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test uclass_first_device_check() and uclass_next_device_check() */
|
|
|
|
static int dm_test_first_next_ok_device(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct dm_testprobe_pdata *pdata;
|
|
|
|
struct udevice *dev, *parent = NULL, *devlist[4];
|
|
|
|
int count;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* There should be 4 devices */
|
|
|
|
count = 0;
|
|
|
|
for (ret = uclass_first_device_check(UCLASS_TEST_PROBE, &dev);
|
|
|
|
dev;
|
|
|
|
ret = uclass_next_device_check(&dev)) {
|
|
|
|
ut_assertok(ret);
|
|
|
|
devlist[count++] = dev;
|
|
|
|
parent = dev_get_parent(dev);
|
|
|
|
}
|
|
|
|
ut_asserteq(4, count);
|
|
|
|
ut_assertok(uclass_first_device_check(UCLASS_TEST_PROBE, &dev));
|
|
|
|
ut_assertok(check_devices(uts, devlist, 0));
|
|
|
|
|
|
|
|
/* Remove them and try again, with an error on the second one */
|
2020-12-03 23:55:20 +00:00
|
|
|
pdata = dev_get_plat(devlist[1]);
|
2017-04-24 02:10:45 +00:00
|
|
|
pdata->probe_err = -ENOENT - 1;
|
|
|
|
device_remove(parent, DM_REMOVE_NORMAL);
|
|
|
|
ut_assertok(check_devices(uts, devlist, 1 << 1));
|
|
|
|
|
|
|
|
/* Now an error on the first one */
|
2020-12-03 23:55:20 +00:00
|
|
|
pdata = dev_get_plat(devlist[0]);
|
2017-04-24 02:10:45 +00:00
|
|
|
pdata->probe_err = -ENOENT - 0;
|
|
|
|
device_remove(parent, DM_REMOVE_NORMAL);
|
|
|
|
ut_assertok(check_devices(uts, devlist, 3 << 0));
|
|
|
|
|
|
|
|
/* Now errors on all */
|
2020-12-03 23:55:20 +00:00
|
|
|
pdata = dev_get_plat(devlist[2]);
|
2017-04-24 02:10:45 +00:00
|
|
|
pdata->probe_err = -ENOENT - 2;
|
2020-12-03 23:55:20 +00:00
|
|
|
pdata = dev_get_plat(devlist[3]);
|
2017-04-24 02:10:45 +00:00
|
|
|
pdata->probe_err = -ENOENT - 3;
|
|
|
|
device_remove(parent, DM_REMOVE_NORMAL);
|
|
|
|
ut_assertok(check_devices(uts, devlist, 0xf << 0));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_first_next_ok_device, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2018-03-12 13:53:33 +00:00
|
|
|
|
|
|
|
static const struct udevice_id fdt_dummy_ids[] = {
|
|
|
|
{ .compatible = "denx,u-boot-fdt-dummy", },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
UCLASS_DRIVER(fdt_dummy) = {
|
test: dm: Fix wrong aliases property names
After importing v4.17-rc1 Linux commit 9130ba884640 ("scripts/dtc:
Update to upstream version v1.4.6-9-gaadd0b65c987"), sandbox build
reports below warnings:
arch/sandbox/dts/test.dtb: Warning (alias_paths): /aliases: aliases property name must include only lowercase and '-'
arch/sandbox/dts/test.dtb: Warning (alias_paths): /aliases: aliases property name must include only lowercase and '-'
arch/sandbox/dts/test.dtb: Warning (alias_paths): /aliases: aliases property name must include only lowercase and '-'
arch/sandbox/dts/test.dtb: Warning (alias_paths): /aliases: aliases property name must include only lowercase and '-'
Silent them by applying the 's/_/-/' substitution in the names of the
'fdt_dummy0', 'fdt_dummy1', 'fdt_dummy2', 'fdt_dummy3' properties.
Similar DTC warnings have been recently fixed in Linux kernel, e.g. via
v4.17-rc1 commit d366c30d19f4 ("ARM: dts: STi: Fix aliases property name
for STi boards").
If done alone, the DTS update generates a failure of the
`ut dm fdt_translation` unit test in sandbox environment as seen below:
$ ./u-boot -d arch/sandbox/dts/test.dtb
---<-snip->---
=> ut dm fdt_translation
Test: dm_test_fdt_translation: test-fdt.c
test/dm/test-fdt.c:444, dm_test_fdt_translation(): 0 == uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, 1, &dev): Expected 0, got -19
Test: dm_test_fdt_translation: test-fdt.c (flat tree)
test/dm/test-fdt.c:444, dm_test_fdt_translation(): 0 == uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, 1, &dev): Expected 0, got -19
Failures: 2
---<-snip->---
Fix this issue in place, by updating the "name" string in the
UCLASS_DRIVER(fdt_dummy) definition, so that it matches the newly
updated aliases properties. After that, the test passes:
$ ./u-boot -d arch/sandbox/dts/test.dtb
---<-snip->---
=> ut dm fdt_translation
Test: dm_test_fdt_translation: test-fdt.c
Test: dm_test_fdt_translation: test-fdt.c (flat tree)
Failures: 0
---<-snip->---
Fixes: e8d5291824e2 ("core: ofnode: Fix translation for #size-cells == 0")
Reported-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-05-19 12:13:55 +00:00
|
|
|
.name = "fdt-dummy",
|
2018-03-12 13:53:33 +00:00
|
|
|
.id = UCLASS_TEST_DUMMY,
|
|
|
|
.flags = DM_UC_FLAG_SEQ_ALIAS,
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(fdt_dummy_drv) = {
|
|
|
|
.name = "fdt_dummy_drv",
|
|
|
|
.of_match = fdt_dummy_ids,
|
|
|
|
.id = UCLASS_TEST_DUMMY,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int dm_test_fdt_translation(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
2019-05-31 13:11:30 +00:00
|
|
|
fdt32_t dma_addr[2];
|
2018-03-12 13:53:33 +00:00
|
|
|
|
|
|
|
/* Some simple translations */
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
|
2018-03-12 13:53:33 +00:00
|
|
|
ut_asserteq_str("dev@0,0", dev->name);
|
|
|
|
ut_asserteq(0x8000, dev_read_addr(dev));
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, &dev));
|
2018-03-12 13:53:33 +00:00
|
|
|
ut_asserteq_str("dev@1,100", dev->name);
|
|
|
|
ut_asserteq(0x9000, dev_read_addr(dev));
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 2, &dev));
|
2018-03-12 13:53:33 +00:00
|
|
|
ut_asserteq_str("dev@2,200", dev->name);
|
|
|
|
ut_asserteq(0xA000, dev_read_addr(dev));
|
|
|
|
|
2022-12-02 06:23:07 +00:00
|
|
|
/* No translation for buses with #size-cells == 0 */
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 3, &dev));
|
2018-03-12 13:53:33 +00:00
|
|
|
ut_asserteq_str("dev@42", dev->name);
|
|
|
|
ut_asserteq(0x42, dev_read_addr(dev));
|
|
|
|
|
2019-05-31 13:11:30 +00:00
|
|
|
/* dma address translation */
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
|
2019-05-31 13:11:30 +00:00
|
|
|
dma_addr[0] = cpu_to_be32(0);
|
|
|
|
dma_addr[1] = cpu_to_be32(0);
|
|
|
|
ut_asserteq(0x10000000, dev_translate_dma_address(dev, dma_addr));
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, &dev));
|
2019-05-31 13:11:30 +00:00
|
|
|
dma_addr[0] = cpu_to_be32(1);
|
|
|
|
dma_addr[1] = cpu_to_be32(0x100);
|
|
|
|
ut_asserteq(0x20000000, dev_translate_dma_address(dev, dma_addr));
|
|
|
|
|
2018-03-12 13:53:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_fdt_translation, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2018-04-29 19:56:54 +00:00
|
|
|
|
2020-08-03 19:17:36 +00:00
|
|
|
static int dm_test_fdt_get_addr_ptr_flat(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *gpio, *dev;
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
/* Test for missing reg property */
|
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_GPIO, &gpio));
|
|
|
|
ut_assertnull(devfdt_get_addr_ptr(gpio));
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
|
2020-08-03 19:17:36 +00:00
|
|
|
ptr = devfdt_get_addr_ptr(dev);
|
|
|
|
ut_asserteq_ptr((void *)0x8000, ptr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_fdt_get_addr_ptr_flat,
|
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
|
|
|
|
|
2018-04-29 19:56:54 +00:00
|
|
|
static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
fdt_addr_t addr;
|
|
|
|
void *paddr;
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
|
2018-04-29 19:56:54 +00:00
|
|
|
|
|
|
|
addr = devfdt_get_addr(dev);
|
|
|
|
ut_asserteq(0x8000, addr);
|
|
|
|
|
|
|
|
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
|
|
|
ut_assertnonnull(paddr);
|
|
|
|
ut_asserteq_ptr(paddr, devfdt_remap_addr(dev));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_fdt_remap_addr_flat,
|
2020-07-29 01:41:12 +00:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
|
2018-04-29 19:56:54 +00:00
|
|
|
|
2018-12-03 18:37:09 +00:00
|
|
|
static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
fdt_addr_t addr;
|
2019-08-01 13:42:56 +00:00
|
|
|
fdt_size_t size;
|
2018-12-03 18:37:09 +00:00
|
|
|
void *paddr;
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
|
2018-12-03 18:37:09 +00:00
|
|
|
|
2019-08-01 13:42:56 +00:00
|
|
|
addr = devfdt_get_addr_size_index(dev, 0, &size);
|
2018-12-03 18:37:09 +00:00
|
|
|
ut_asserteq(0x8000, addr);
|
2019-08-01 13:42:56 +00:00
|
|
|
ut_asserteq(0x1000, size);
|
2018-12-03 18:37:09 +00:00
|
|
|
|
|
|
|
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
|
|
|
ut_assertnonnull(paddr);
|
|
|
|
ut_asserteq_ptr(paddr, devfdt_remap_addr_index(dev, 0));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_fdt_remap_addr_index_flat,
|
2020-07-29 01:41:12 +00:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
|
2018-12-03 18:37:09 +00:00
|
|
|
|
|
|
|
static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
fdt_addr_t addr;
|
2019-08-01 13:42:56 +00:00
|
|
|
fdt_size_t size;
|
2018-12-03 18:37:09 +00:00
|
|
|
void *paddr;
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
|
2018-12-03 18:37:09 +00:00
|
|
|
|
2019-08-01 13:42:56 +00:00
|
|
|
addr = devfdt_get_addr_size_name(dev, "sandbox-dummy-0", &size);
|
2018-12-03 18:37:09 +00:00
|
|
|
ut_asserteq(0x8000, addr);
|
2019-08-01 13:42:56 +00:00
|
|
|
ut_asserteq(0x1000, size);
|
2018-12-03 18:37:09 +00:00
|
|
|
|
|
|
|
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
|
|
|
ut_assertnonnull(paddr);
|
|
|
|
ut_asserteq_ptr(paddr, devfdt_remap_addr_name(dev, "sandbox-dummy-0"));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_fdt_remap_addr_name_flat,
|
2020-07-29 01:41:12 +00:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
|
2018-12-03 18:37:09 +00:00
|
|
|
|
2018-04-29 19:56:54 +00:00
|
|
|
static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
fdt_addr_t addr;
|
|
|
|
void *paddr;
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
|
2018-04-29 19:56:54 +00:00
|
|
|
|
|
|
|
addr = dev_read_addr(dev);
|
|
|
|
ut_asserteq(0x8000, addr);
|
|
|
|
|
|
|
|
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
|
|
|
ut_assertnonnull(paddr);
|
|
|
|
ut_asserteq_ptr(paddr, dev_remap_addr(dev));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_fdt_remap_addr_live,
|
2020-07-29 01:41:12 +00:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2018-06-26 06:46:49 +00:00
|
|
|
|
2018-12-03 18:37:09 +00:00
|
|
|
static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
fdt_addr_t addr;
|
2019-08-01 13:42:56 +00:00
|
|
|
fdt_size_t size;
|
2018-12-03 18:37:09 +00:00
|
|
|
void *paddr;
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
|
2018-12-03 18:37:09 +00:00
|
|
|
|
2019-08-01 13:42:56 +00:00
|
|
|
addr = dev_read_addr_size_index(dev, 0, &size);
|
2018-12-03 18:37:09 +00:00
|
|
|
ut_asserteq(0x8000, addr);
|
2019-08-01 13:42:56 +00:00
|
|
|
ut_asserteq(0x1000, size);
|
2018-12-03 18:37:09 +00:00
|
|
|
|
|
|
|
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
|
|
|
ut_assertnonnull(paddr);
|
|
|
|
ut_asserteq_ptr(paddr, dev_remap_addr_index(dev, 0));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_fdt_remap_addr_index_live,
|
2020-07-29 01:41:12 +00:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2018-12-03 18:37:09 +00:00
|
|
|
|
|
|
|
static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
fdt_addr_t addr;
|
2019-08-01 13:42:56 +00:00
|
|
|
fdt_size_t size;
|
2018-12-03 18:37:09 +00:00
|
|
|
void *paddr;
|
|
|
|
|
2020-12-17 04:20:29 +00:00
|
|
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
|
2018-12-03 18:37:09 +00:00
|
|
|
|
2019-08-01 13:42:56 +00:00
|
|
|
addr = dev_read_addr_size_name(dev, "sandbox-dummy-0", &size);
|
2018-12-03 18:37:09 +00:00
|
|
|
ut_asserteq(0x8000, addr);
|
2019-08-01 13:42:56 +00:00
|
|
|
ut_asserteq(0x1000, size);
|
2018-12-03 18:37:09 +00:00
|
|
|
|
|
|
|
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
|
|
|
ut_assertnonnull(paddr);
|
|
|
|
ut_asserteq_ptr(paddr, dev_remap_addr_name(dev, "sandbox-dummy-0"));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_fdt_remap_addr_name_live,
|
2020-07-29 01:41:12 +00:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2018-12-03 18:37:09 +00:00
|
|
|
|
2018-06-26 06:46:51 +00:00
|
|
|
static int dm_test_fdt_disable_enable_by_path(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
ofnode node;
|
|
|
|
|
|
|
|
if (!of_live_active()) {
|
|
|
|
printf("Live tree not active; ignore test\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = ofnode_path("/usb@2");
|
|
|
|
|
|
|
|
/* Test enabling devices */
|
|
|
|
|
|
|
|
ut_assert(!of_device_is_available(ofnode_to_np(node)));
|
|
|
|
dev_enable_by_path("/usb@2");
|
|
|
|
ut_assert(of_device_is_available(ofnode_to_np(node)));
|
|
|
|
|
|
|
|
/* Test disabling devices */
|
|
|
|
|
|
|
|
ut_assert(of_device_is_available(ofnode_to_np(node)));
|
|
|
|
dev_disable_by_path("/usb@2");
|
|
|
|
ut_assert(!of_device_is_available(ofnode_to_np(node)));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_fdt_disable_enable_by_path, UT_TESTF_SCAN_PDATA |
|
|
|
|
UT_TESTF_SCAN_FDT);
|
2018-11-18 15:14:30 +00:00
|
|
|
|
|
|
|
/* Test a few uclass phandle functions */
|
|
|
|
static int dm_test_fdt_phandle(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *back, *dev, *dev2;
|
|
|
|
|
|
|
|
ut_assertok(uclass_find_first_device(UCLASS_PANEL_BACKLIGHT, &back));
|
2020-07-16 22:20:14 +00:00
|
|
|
ut_assertnonnull(back);
|
2018-11-18 15:14:30 +00:00
|
|
|
ut_asserteq(-ENOENT, uclass_find_device_by_phandle(UCLASS_REGULATOR,
|
|
|
|
back, "missing", &dev));
|
|
|
|
ut_assertok(uclass_find_device_by_phandle(UCLASS_REGULATOR, back,
|
|
|
|
"power-supply", &dev));
|
2020-07-16 22:20:14 +00:00
|
|
|
ut_assertnonnull(dev);
|
2018-11-18 15:14:30 +00:00
|
|
|
ut_asserteq(0, device_active(dev));
|
|
|
|
ut_asserteq_str("ldo1", dev->name);
|
|
|
|
ut_assertok(uclass_get_device_by_phandle(UCLASS_REGULATOR, back,
|
|
|
|
"power-supply", &dev2));
|
|
|
|
ut_asserteq_ptr(dev, dev2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_fdt_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2018-11-18 15:14:31 +00:00
|
|
|
|
|
|
|
/* Test device_find_first_child_by_uclass() */
|
|
|
|
static int dm_test_first_child(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *i2c, *dev, *dev2;
|
|
|
|
|
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_I2C, &i2c));
|
|
|
|
ut_assertok(device_find_first_child_by_uclass(i2c, UCLASS_RTC, &dev));
|
|
|
|
ut_asserteq_str("rtc@43", dev->name);
|
|
|
|
ut_assertok(device_find_child_by_name(i2c, "rtc@43", &dev2));
|
|
|
|
ut_asserteq_ptr(dev, dev2);
|
|
|
|
ut_assertok(device_find_child_by_name(i2c, "rtc@61", &dev2));
|
|
|
|
ut_asserteq_str("rtc@61", dev2->name);
|
|
|
|
|
|
|
|
ut_assertok(device_find_first_child_by_uclass(i2c, UCLASS_I2C_EEPROM,
|
|
|
|
&dev));
|
|
|
|
ut_asserteq_str("eeprom@2c", dev->name);
|
|
|
|
ut_assertok(device_find_child_by_name(i2c, "eeprom@2c", &dev2));
|
|
|
|
ut_asserteq_ptr(dev, dev2);
|
|
|
|
|
|
|
|
ut_asserteq(-ENODEV, device_find_first_child_by_uclass(i2c,
|
|
|
|
UCLASS_VIDEO, &dev));
|
|
|
|
ut_asserteq(-ENODEV, device_find_child_by_name(i2c, "missing", &dev));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_first_child, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2018-12-10 17:37:37 +00:00
|
|
|
|
|
|
|
/* Test integer functions in dm_read_...() */
|
|
|
|
static int dm_test_read_int(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
2022-06-14 13:21:30 +00:00
|
|
|
u8 val8;
|
|
|
|
u16 val16;
|
2018-12-10 17:37:37 +00:00
|
|
|
u32 val32;
|
|
|
|
s32 sval;
|
|
|
|
uint val;
|
2020-03-29 16:04:40 +00:00
|
|
|
u64 val64;
|
2018-12-10 17:37:37 +00:00
|
|
|
|
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
|
|
|
|
ut_asserteq_str("a-test", dev->name);
|
2022-06-14 13:21:30 +00:00
|
|
|
|
|
|
|
ut_assertok(dev_read_u8(dev, "int8-value", &val8));
|
|
|
|
ut_asserteq(0x12, val8);
|
|
|
|
|
|
|
|
ut_asserteq(-EINVAL, dev_read_u8(dev, "missing", &val8));
|
|
|
|
ut_asserteq(6, dev_read_u8_default(dev, "missing", 6));
|
|
|
|
|
|
|
|
ut_asserteq(0x12, dev_read_u8_default(dev, "int8-value", 6));
|
|
|
|
|
|
|
|
ut_assertok(dev_read_u16(dev, "int16-value", &val16));
|
|
|
|
ut_asserteq(0x1234, val16);
|
|
|
|
|
|
|
|
ut_asserteq(-EINVAL, dev_read_u16(dev, "missing", &val16));
|
|
|
|
ut_asserteq(6, dev_read_u16_default(dev, "missing", 6));
|
|
|
|
|
|
|
|
ut_asserteq(0x1234, dev_read_u16_default(dev, "int16-value", 6));
|
|
|
|
|
2018-12-10 17:37:37 +00:00
|
|
|
ut_assertok(dev_read_u32(dev, "int-value", &val32));
|
|
|
|
ut_asserteq(1234, val32);
|
|
|
|
|
|
|
|
ut_asserteq(-EINVAL, dev_read_u32(dev, "missing", &val32));
|
|
|
|
ut_asserteq(6, dev_read_u32_default(dev, "missing", 6));
|
|
|
|
|
|
|
|
ut_asserteq(1234, dev_read_u32_default(dev, "int-value", 6));
|
|
|
|
ut_asserteq(1234, val32);
|
|
|
|
|
|
|
|
ut_asserteq(-EINVAL, dev_read_s32(dev, "missing", &sval));
|
|
|
|
ut_asserteq(6, dev_read_s32_default(dev, "missing", 6));
|
|
|
|
|
|
|
|
ut_asserteq(-1234, dev_read_s32_default(dev, "uint-value", 6));
|
|
|
|
ut_assertok(dev_read_s32(dev, "uint-value", &sval));
|
|
|
|
ut_asserteq(-1234, sval);
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
ut_asserteq(-EINVAL, dev_read_u32u(dev, "missing", &val));
|
|
|
|
ut_assertok(dev_read_u32u(dev, "uint-value", &val));
|
|
|
|
ut_asserteq(-1234, val);
|
|
|
|
|
2020-03-29 16:04:40 +00:00
|
|
|
ut_assertok(dev_read_u64(dev, "int64-value", &val64));
|
|
|
|
ut_asserteq_64(0x1111222233334444, val64);
|
|
|
|
|
|
|
|
ut_asserteq_64(-EINVAL, dev_read_u64(dev, "missing", &val64));
|
|
|
|
ut_asserteq_64(6, dev_read_u64_default(dev, "missing", 6));
|
|
|
|
|
|
|
|
ut_asserteq_64(0x1111222233334444,
|
|
|
|
dev_read_u64_default(dev, "int64-value", 6));
|
|
|
|
|
2018-12-10 17:37:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_read_int, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-02-06 16:54:50 +00:00
|
|
|
|
2020-03-29 16:04:41 +00:00
|
|
|
static int dm_test_read_int_index(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
u32 val32;
|
|
|
|
|
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
|
|
|
|
ut_asserteq_str("a-test", dev->name);
|
|
|
|
|
|
|
|
ut_asserteq(-EINVAL, dev_read_u32_index(dev, "missing", 0, &val32));
|
|
|
|
ut_asserteq(19, dev_read_u32_index_default(dev, "missing", 0, 19));
|
|
|
|
|
|
|
|
ut_assertok(dev_read_u32_index(dev, "int-array", 0, &val32));
|
|
|
|
ut_asserteq(5678, val32);
|
|
|
|
ut_assertok(dev_read_u32_index(dev, "int-array", 1, &val32));
|
|
|
|
ut_asserteq(9123, val32);
|
|
|
|
ut_assertok(dev_read_u32_index(dev, "int-array", 2, &val32));
|
|
|
|
ut_asserteq(4567, val32);
|
|
|
|
ut_asserteq(-EOVERFLOW, dev_read_u32_index(dev, "int-array", 3,
|
|
|
|
&val32));
|
|
|
|
|
|
|
|
ut_asserteq(5678, dev_read_u32_index_default(dev, "int-array", 0, 2));
|
|
|
|
ut_asserteq(9123, dev_read_u32_index_default(dev, "int-array", 1, 2));
|
|
|
|
ut_asserteq(4567, dev_read_u32_index_default(dev, "int-array", 2, 2));
|
|
|
|
ut_asserteq(2, dev_read_u32_index_default(dev, "int-array", 3, 2));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_read_int_index, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-03-29 16:04:41 +00:00
|
|
|
|
2020-09-25 07:41:16 +00:00
|
|
|
static int dm_test_read_phandle(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
struct ofnode_phandle_args args;
|
|
|
|
int ret;
|
|
|
|
const char prop[] = "test-gpios";
|
|
|
|
const char cell[] = "#gpio-cells";
|
|
|
|
const char prop2[] = "phandle-value";
|
|
|
|
|
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
|
|
|
|
ut_asserteq_str("a-test", dev->name);
|
|
|
|
|
|
|
|
/* Test dev_count_phandle_with_args with cell name */
|
|
|
|
ret = dev_count_phandle_with_args(dev, "missing", cell, 0);
|
|
|
|
ut_asserteq(-ENOENT, ret);
|
|
|
|
ret = dev_count_phandle_with_args(dev, prop, "#invalid", 0);
|
|
|
|
ut_asserteq(-EINVAL, ret);
|
|
|
|
ut_asserteq(5, dev_count_phandle_with_args(dev, prop, cell, 0));
|
|
|
|
|
|
|
|
/* Test dev_read_phandle_with_args with cell name */
|
|
|
|
ret = dev_read_phandle_with_args(dev, "missing", cell, 0, 0, &args);
|
|
|
|
ut_asserteq(-ENOENT, ret);
|
|
|
|
ret = dev_read_phandle_with_args(dev, prop, "#invalid", 0, 0, &args);
|
|
|
|
ut_asserteq(-EINVAL, ret);
|
|
|
|
ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 0, &args));
|
|
|
|
ut_asserteq(1, args.args_count);
|
|
|
|
ut_asserteq(1, args.args[0]);
|
|
|
|
ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 1, &args));
|
|
|
|
ut_asserteq(1, args.args_count);
|
|
|
|
ut_asserteq(4, args.args[0]);
|
|
|
|
ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 2, &args));
|
|
|
|
ut_asserteq(5, args.args_count);
|
|
|
|
ut_asserteq(5, args.args[0]);
|
|
|
|
ut_asserteq(1, args.args[4]);
|
|
|
|
ret = dev_read_phandle_with_args(dev, prop, cell, 0, 3, &args);
|
|
|
|
ut_asserteq(-ENOENT, ret);
|
|
|
|
ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 4, &args));
|
|
|
|
ut_asserteq(1, args.args_count);
|
|
|
|
ut_asserteq(12, args.args[0]);
|
|
|
|
ret = dev_read_phandle_with_args(dev, prop, cell, 0, 5, &args);
|
|
|
|
ut_asserteq(-ENOENT, ret);
|
|
|
|
|
|
|
|
/* Test dev_count_phandle_with_args with cell count */
|
|
|
|
ret = dev_count_phandle_with_args(dev, "missing", NULL, 2);
|
|
|
|
ut_asserteq(-ENOENT, ret);
|
|
|
|
ut_asserteq(3, dev_count_phandle_with_args(dev, prop2, NULL, 1));
|
|
|
|
|
|
|
|
/* Test dev_read_phandle_with_args with cell count */
|
|
|
|
ut_assertok(dev_read_phandle_with_args(dev, prop2, NULL, 1, 0, &args));
|
|
|
|
ut_asserteq(1, ofnode_valid(args.node));
|
|
|
|
ut_asserteq(1, args.args_count);
|
|
|
|
ut_asserteq(10, args.args[0]);
|
|
|
|
ret = dev_read_phandle_with_args(dev, prop2, NULL, 1, 1, &args);
|
|
|
|
ut_asserteq(-EINVAL, ret);
|
|
|
|
ut_assertok(dev_read_phandle_with_args(dev, prop2, NULL, 1, 2, &args));
|
|
|
|
ut_asserteq(1, ofnode_valid(args.node));
|
|
|
|
ut_asserteq(1, args.args_count);
|
|
|
|
ut_asserteq(30, args.args[0]);
|
|
|
|
ret = dev_read_phandle_with_args(dev, prop2, NULL, 1, 3, &args);
|
|
|
|
ut_asserteq(-ENOENT, ret);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_read_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
|
|
|
|
2020-02-06 16:54:50 +00:00
|
|
|
/* Test iteration through devices by drvdata */
|
|
|
|
static int dm_test_uclass_drvdata(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
ut_assertok(uclass_first_device_drvdata(UCLASS_TEST_FDT,
|
|
|
|
DM_TEST_TYPE_FIRST, &dev));
|
|
|
|
ut_asserteq_str("a-test", dev->name);
|
|
|
|
|
|
|
|
ut_assertok(uclass_first_device_drvdata(UCLASS_TEST_FDT,
|
|
|
|
DM_TEST_TYPE_SECOND, &dev));
|
|
|
|
ut_asserteq_str("d-test", dev->name);
|
|
|
|
|
|
|
|
ut_asserteq(-ENODEV, uclass_first_device_drvdata(UCLASS_TEST_FDT,
|
|
|
|
DM_TEST_TYPE_COUNT,
|
|
|
|
&dev));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_uclass_drvdata, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-01-27 15:49:47 +00:00
|
|
|
|
|
|
|
/* 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;
|
2020-12-03 23:55:21 +00:00
|
|
|
device_foreach_child_of_to_plat(dev, bus) {
|
2020-12-19 17:40:10 +00:00
|
|
|
ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID);
|
|
|
|
ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
|
2020-01-27 15:49:47 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
ut_asserteq(3, count);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_child_ofdata, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-01-27 15:49:48 +00:00
|
|
|
|
|
|
|
/* 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) {
|
2020-12-19 17:40:10 +00:00
|
|
|
ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID);
|
|
|
|
ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
|
2020-01-27 15:49:48 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
ut_asserteq(3, count);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_first_child_probe, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-04-05 21:38:19 +00:00
|
|
|
|
|
|
|
/* Test that ofdata is read for parents before children */
|
|
|
|
static int dm_test_ofdata_order(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
|
|
|
|
ut_assertok(uclass_find_first_device(UCLASS_I2C, &bus));
|
|
|
|
ut_assertnonnull(bus);
|
2020-12-19 17:40:10 +00:00
|
|
|
ut_assert(!(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID));
|
2020-04-05 21:38:19 +00:00
|
|
|
|
|
|
|
ut_assertok(device_find_first_child(bus, &dev));
|
|
|
|
ut_assertnonnull(dev);
|
2020-12-19 17:40:10 +00:00
|
|
|
ut_assert(!(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID));
|
2020-04-05 21:38:19 +00:00
|
|
|
|
|
|
|
/* read the child's ofdata which should cause the parent's to be read */
|
2020-12-03 23:55:21 +00:00
|
|
|
ut_assertok(device_of_to_plat(dev));
|
2020-12-19 17:40:10 +00:00
|
|
|
ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID);
|
|
|
|
ut_assert(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID);
|
2020-04-05 21:38:19 +00:00
|
|
|
|
2020-12-19 17:40:10 +00:00
|
|
|
ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
|
|
|
|
ut_assert(!(dev_get_flags(bus) & DM_FLAG_ACTIVATED));
|
2020-04-05 21:38:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_ofdata_order, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-12-29 23:16:26 +00:00
|
|
|
|
|
|
|
/* Test dev_decode_display_timing() */
|
|
|
|
static int dm_test_decode_display_timing(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
struct display_timing timing;
|
|
|
|
|
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
|
|
|
|
ut_asserteq_str("a-test", dev->name);
|
|
|
|
|
|
|
|
ut_assertok(dev_decode_display_timing(dev, 0, &timing));
|
|
|
|
ut_assert(timing.hactive.typ == 240);
|
|
|
|
ut_assert(timing.hback_porch.typ == 7);
|
|
|
|
ut_assert(timing.hfront_porch.typ == 6);
|
|
|
|
ut_assert(timing.hsync_len.typ == 1);
|
|
|
|
ut_assert(timing.vactive.typ == 320);
|
|
|
|
ut_assert(timing.vback_porch.typ == 5);
|
|
|
|
ut_assert(timing.vfront_porch.typ == 8);
|
|
|
|
ut_assert(timing.vsync_len.typ == 2);
|
|
|
|
ut_assert(timing.pixelclock.typ == 6500000);
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_HSYNC_HIGH);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_HSYNC_LOW));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_VSYNC_HIGH));
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_VSYNC_LOW);
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_DE_HIGH);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_DE_LOW));
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE));
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_INTERLACED);
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_DOUBLESCAN);
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_DOUBLECLK);
|
|
|
|
|
|
|
|
ut_assertok(dev_decode_display_timing(dev, 1, &timing));
|
|
|
|
ut_assert(timing.hactive.typ == 480);
|
|
|
|
ut_assert(timing.hback_porch.typ == 59);
|
|
|
|
ut_assert(timing.hfront_porch.typ == 10);
|
|
|
|
ut_assert(timing.hsync_len.typ == 12);
|
|
|
|
ut_assert(timing.vactive.typ == 800);
|
|
|
|
ut_assert(timing.vback_porch.typ == 15);
|
|
|
|
ut_assert(timing.vfront_porch.typ == 17);
|
|
|
|
ut_assert(timing.vsync_len.typ == 16);
|
|
|
|
ut_assert(timing.pixelclock.typ == 9000000);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_HSYNC_HIGH));
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_HSYNC_LOW);
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_VSYNC_HIGH);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_VSYNC_LOW));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_DE_HIGH));
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_DE_LOW);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE));
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_INTERLACED));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_DOUBLESCAN));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_DOUBLECLK));
|
|
|
|
|
|
|
|
ut_assertok(dev_decode_display_timing(dev, 2, &timing));
|
|
|
|
ut_assert(timing.hactive.typ == 800);
|
|
|
|
ut_assert(timing.hback_porch.typ == 89);
|
|
|
|
ut_assert(timing.hfront_porch.typ == 164);
|
|
|
|
ut_assert(timing.hsync_len.typ == 11);
|
|
|
|
ut_assert(timing.vactive.typ == 480);
|
|
|
|
ut_assert(timing.vback_porch.typ == 23);
|
|
|
|
ut_assert(timing.vfront_porch.typ == 10);
|
|
|
|
ut_assert(timing.vsync_len.typ == 13);
|
|
|
|
ut_assert(timing.pixelclock.typ == 33500000);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_HSYNC_HIGH));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_HSYNC_LOW));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_VSYNC_HIGH));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_VSYNC_LOW));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_DE_HIGH));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_DE_LOW));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_INTERLACED));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_DOUBLESCAN));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_DOUBLECLK));
|
|
|
|
|
|
|
|
ut_assert(dev_decode_display_timing(dev, 3, &timing));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_decode_display_timing, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2021-05-21 10:25:00 +00:00
|
|
|
|
2023-01-31 10:05:15 +00:00
|
|
|
/* Test dev_decode_panel_timing() */
|
|
|
|
static int dm_test_decode_panel_timing(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
struct display_timing timing;
|
|
|
|
|
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
|
|
|
|
ut_asserteq_str("a-test", dev->name);
|
|
|
|
|
|
|
|
ut_assertok(dev_decode_panel_timing(dev, &timing));
|
|
|
|
ut_assert(timing.hactive.typ == 240);
|
|
|
|
ut_assert(timing.hback_porch.typ == 7);
|
|
|
|
ut_assert(timing.hfront_porch.typ == 6);
|
|
|
|
ut_assert(timing.hsync_len.typ == 1);
|
|
|
|
ut_assert(timing.vactive.typ == 320);
|
|
|
|
ut_assert(timing.vback_porch.typ == 5);
|
|
|
|
ut_assert(timing.vfront_porch.typ == 8);
|
|
|
|
ut_assert(timing.vsync_len.typ == 2);
|
|
|
|
ut_assert(timing.pixelclock.typ == 6500000);
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_HSYNC_HIGH);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_HSYNC_LOW));
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_VSYNC_HIGH));
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_VSYNC_LOW);
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_DE_HIGH);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_DE_LOW));
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE);
|
|
|
|
ut_assert(!(timing.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE));
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_INTERLACED);
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_DOUBLESCAN);
|
|
|
|
ut_assert(timing.flags & DISPLAY_FLAGS_DOUBLECLK);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_decode_panel_timing, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
|
|
|
|
2021-05-21 10:25:00 +00:00
|
|
|
/* Test read_resourcee() */
|
|
|
|
static int dm_test_read_resource(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
struct resource res;
|
|
|
|
|
|
|
|
/* test resource without translation */
|
|
|
|
ut_assertok(uclass_find_device_by_name(UCLASS_SIMPLE_BUS, "syscon@2", &dev));
|
|
|
|
ut_assertok(dev_read_resource(dev, 0, &res));
|
|
|
|
ut_asserteq(0x40, res.start);
|
|
|
|
ut_asserteq(0x44, res.end);
|
|
|
|
ut_assertok(dev_read_resource(dev, 1, &res));
|
|
|
|
ut_asserteq(0x48, res.start);
|
|
|
|
ut_asserteq(0x4d, res.end);
|
|
|
|
|
|
|
|
/* test resource with translation */
|
|
|
|
ut_assertok(uclass_find_device_by_name(UCLASS_TEST_DUMMY, "dev@1,100", &dev));
|
|
|
|
ut_assertok(dev_read_resource(dev, 0, &res));
|
|
|
|
ut_asserteq(0x9000, res.start);
|
|
|
|
ut_asserteq(0x9fff, res.end);
|
|
|
|
|
|
|
|
/* test named resource */
|
|
|
|
ut_assertok(uclass_find_device_by_name(UCLASS_TEST_DUMMY, "dev@0,0", &dev));
|
|
|
|
ut_assertok(dev_read_resource_byname(dev, "sandbox-dummy-0", &res));
|
|
|
|
ut_asserteq(0x8000, res.start);
|
|
|
|
ut_asserteq(0x8fff, res.end);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DM_TEST(dm_test_read_resource, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|