1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2014 Google, Inc
*/
#include <dm.h>
#include <dm/test.h>
#include <asm/global_data.h>
/* 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(denx_u_boot_test_bus) = {
.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,
DM_HEADER(<test.h>)
};
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,
.per_device_auto = sizeof(struct dm_test_uclass_priv),
/* Note: this is for dtoc testing as well as tags*/
.per_device_plat_auto = sizeof(struct dm_test_uclass_plat),
};
static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret)
{
const struct dm_test_pdata *pdata = dev_get_plat(dev);
struct dm_test_priv *priv = dev_get_priv(dev);
*pingret = pingval + pdata->ping_add;
priv->ping_total += *pingret;
return 0;
}
static const struct test_ops test_ops = {
.ping = testfdt_drv_ping,
};
static int testfdt_of_to_plat(struct udevice *dev)
{
struct dm_test_pdata *pdata = dev_get_plat(dev);
pdata->ping_add = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"ping-add", -1);
pdata->base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev),
"ping-expect");
return 0;
}
static int testfdt_drv_probe(struct udevice *dev)
{
struct dm_test_priv *priv = dev_get_priv(dev);
priv->ping_total += DM_TEST_START_TOTAL;
/*
* If this device is on a bus, the uclass_flag will be set before
* calling this function. In the meantime the uclass_postp is
* initlized to a value -1. These are used respectively by
* dm_test_bus_child_pre_probe_uclass() and
* dm_test_bus_child_post_probe_uclass().
*/
priv->uclass_total += priv->uclass_flag;
priv->uclass_postp = -1;
return 0;
}
static const struct udevice_id testfdt_ids[] = {
{ .compatible = "denx,u-boot-fdt-test", .data = DM_TEST_TYPE_FIRST },
{ .compatible = "google,another-fdt-test", .data = DM_TEST_TYPE_SECOND },
{ }
};
DM_DRIVER_ALIAS(denx_u_boot_fdt_test, google_another_fdt_test)
U_BOOT_DRIVER(denx_u_boot_fdt_test) = {
.name = "testfdt_drv",
.of_match = testfdt_ids,
.id = UCLASS_TEST_FDT,
.of_to_plat = testfdt_of_to_plat,
.probe = testfdt_drv_probe,
.ops = &test_ops,
.priv_auto = sizeof(struct dm_test_priv),
.plat_auto = sizeof(struct dm_test_pdata),
};
static const struct udevice_id testfdt1_ids[] = {
{ .compatible = "denx,u-boot-fdt-test1", .data = DM_TEST_TYPE_FIRST },
{ }
};
U_BOOT_DRIVER(testfdt1_drv) = {
.name = "testfdt1_drv",
.of_match = testfdt1_ids,
.id = UCLASS_TEST_FDT,
.of_to_plat = testfdt_of_to_plat,
.probe = testfdt_drv_probe,
.ops = &test_ops,
.priv_auto = sizeof(struct dm_test_priv),
.plat_auto = sizeof(struct dm_test_pdata),
.flags = DM_FLAG_PRE_RELOC,
};
/* From here is the testfdt uclass code */
int testfdt_ping(struct udevice *dev, int pingval, int *pingret)
{
const struct test_ops *ops = device_get_ops(dev);
if (!ops->ping)
return -ENOSYS;
return ops->ping(dev, pingval, pingret);
}
UCLASS_DRIVER(testfdt) = {
.name = "testfdt",
.id = UCLASS_TEST_FDT,
.flags = DM_UC_FLAG_SEQ_ALIAS,
.priv_auto = sizeof(struct dm_test_uc_priv),
};
static const struct udevice_id testfdtm_ids[] = {
{ .compatible = "denx,u-boot-fdtm-test" },
{ }
};
U_BOOT_DRIVER(testfdtm_drv) = {
.name = "testfdtm_drv",
.of_match = testfdtm_ids,
.id = UCLASS_TEST_FDT_MANUAL,
};
UCLASS_DRIVER(testfdtm) = {
.name = "testfdtm",
.id = UCLASS_TEST_FDT_MANUAL,
.flags = DM_UC_FLAG_SEQ_ALIAS | DM_UC_FLAG_NO_AUTO_SEQ,
};
|