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
|
|
|
|
*
|
|
|
|
* (C) Copyright 2012
|
|
|
|
* Pavel Herrmann <morpheus.ibis@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2014-02-26 22:59:21 +00:00
|
|
|
#include <malloc.h>
|
2020-07-19 16:15:37 +00:00
|
|
|
#include <asm/io.h>
|
2020-12-23 02:30:28 +00:00
|
|
|
#include <dm/device-internal.h>
|
2014-02-26 22:59:21 +00:00
|
|
|
#include <dm/test.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
|
|
|
|
|
|
|
int dm_testdrv_op_count[DM_TEST_OP_COUNT];
|
2015-05-20 19:27:27 +00:00
|
|
|
static struct unit_test_state *uts = &global_dm_test_state;
|
2014-02-26 22:59:21 +00:00
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int testdrv_ping(struct udevice *dev, int pingval, int *pingret)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
const struct dm_test_pdata *pdata = dev_get_plat(dev);
|
2014-02-26 22:59:21 +00:00
|
|
|
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 = testdrv_ping,
|
|
|
|
};
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_bind(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
/* Private data should not be allocated */
|
|
|
|
ut_assert(!dev_get_priv(dev));
|
|
|
|
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_BIND]++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_probe(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
struct dm_test_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
/* Private data should be allocated */
|
|
|
|
ut_assert(priv);
|
|
|
|
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
|
|
|
|
priv->ping_total += DM_TEST_START_TOTAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_remove(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
/* Private data should still be allocated */
|
|
|
|
ut_assert(dev_get_priv(dev));
|
|
|
|
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_unbind(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
/* Private data should not be allocated */
|
2020-12-23 02:30:28 +00:00
|
|
|
ut_assert(!dev_get_priv(dev));
|
2014-02-26 22:59:21 +00:00
|
|
|
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(test_drv) = {
|
|
|
|
.name = "test_drv",
|
|
|
|
.id = UCLASS_TEST,
|
|
|
|
.ops = &test_ops,
|
|
|
|
.bind = test_bind,
|
|
|
|
.probe = test_probe,
|
|
|
|
.remove = test_remove,
|
|
|
|
.unbind = test_unbind,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct dm_test_priv),
|
2014-02-26 22:59:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(test2_drv) = {
|
|
|
|
.name = "test2_drv",
|
|
|
|
.id = UCLASS_TEST,
|
|
|
|
.ops = &test_ops,
|
|
|
|
.bind = test_bind,
|
|
|
|
.probe = test_probe,
|
|
|
|
.remove = test_remove,
|
|
|
|
.unbind = test_unbind,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct dm_test_priv),
|
2014-02-26 22:59:21 +00:00
|
|
|
};
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_manual_drv_ping(struct udevice *dev, int pingval, int *pingret)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
*pingret = pingval + 2;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct test_ops test_manual_ops = {
|
|
|
|
.ping = test_manual_drv_ping,
|
|
|
|
};
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_manual_bind(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_BIND]++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_manual_probe(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
2015-05-20 19:27:27 +00:00
|
|
|
struct dm_test_state *dms = uts->priv;
|
|
|
|
|
2014-02-26 22:59:21 +00:00
|
|
|
dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
|
|
|
|
if (!dms->force_fail_alloc)
|
2020-12-23 02:30:28 +00:00
|
|
|
dev_set_priv(dev, calloc(1, sizeof(struct dm_test_priv)));
|
|
|
|
if (!dev_get_priv(dev))
|
2014-02-26 22:59:21 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_manual_remove(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_manual_unbind(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(test_manual_drv) = {
|
|
|
|
.name = "test_manual_drv",
|
|
|
|
.id = UCLASS_TEST,
|
|
|
|
.ops = &test_manual_ops,
|
|
|
|
.bind = test_manual_bind,
|
|
|
|
.probe = test_manual_probe,
|
|
|
|
.remove = test_manual_remove,
|
|
|
|
.unbind = test_manual_unbind,
|
|
|
|
};
|
2014-07-23 12:55:03 +00:00
|
|
|
|
|
|
|
U_BOOT_DRIVER(test_pre_reloc_drv) = {
|
|
|
|
.name = "test_pre_reloc_drv",
|
|
|
|
.id = UCLASS_TEST,
|
|
|
|
.ops = &test_manual_ops,
|
|
|
|
.bind = test_manual_bind,
|
|
|
|
.probe = test_manual_probe,
|
|
|
|
.remove = test_manual_remove,
|
|
|
|
.unbind = test_manual_unbind,
|
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|
2017-03-27 09:02:43 +00:00
|
|
|
|
|
|
|
U_BOOT_DRIVER(test_act_dma_drv) = {
|
|
|
|
.name = "test_act_dma_drv",
|
|
|
|
.id = UCLASS_TEST,
|
|
|
|
.ops = &test_manual_ops,
|
|
|
|
.bind = test_manual_bind,
|
|
|
|
.probe = test_manual_probe,
|
|
|
|
.remove = test_manual_remove,
|
|
|
|
.unbind = test_manual_unbind,
|
|
|
|
.flags = DM_FLAG_ACTIVE_DMA,
|
|
|
|
};
|
2021-01-24 21:32:46 +00:00
|
|
|
|
|
|
|
U_BOOT_DRIVER(test_vital_clk_drv) = {
|
|
|
|
.name = "test_vital_clk_drv",
|
|
|
|
.id = UCLASS_TEST,
|
|
|
|
.ops = &test_manual_ops,
|
|
|
|
.bind = test_manual_bind,
|
|
|
|
.probe = test_manual_probe,
|
|
|
|
.remove = test_manual_remove,
|
|
|
|
.unbind = test_manual_unbind,
|
|
|
|
.flags = DM_FLAG_VITAL,
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(test_act_dma_vital_clk_drv) = {
|
|
|
|
.name = "test_act_dma_vital_clk_drv",
|
|
|
|
.id = UCLASS_TEST,
|
|
|
|
.ops = &test_manual_ops,
|
|
|
|
.bind = test_manual_bind,
|
|
|
|
.probe = test_manual_probe,
|
|
|
|
.remove = test_manual_remove,
|
|
|
|
.unbind = test_manual_unbind,
|
|
|
|
.flags = DM_FLAG_VITAL | DM_FLAG_ACTIVE_DMA,
|
|
|
|
};
|