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>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2014-02-26 22:59:21 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <asm/io.h>
|
2015-05-20 19:27:27 +00:00
|
|
|
#include <dm/test.h>
|
2014-02-26 22:59:21 +00:00
|
|
|
#include <linux/list.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
|
|
|
|
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
|
|
|
int test_ping(struct udevice *dev, int pingval, int *pingret)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
const struct test_ops *ops = device_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->ping)
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
return ops->ping(dev, pingval, pingret);
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_post_bind(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
2015-04-15 11:07:19 +00:00
|
|
|
struct dm_test_perdev_uc_pdata *uc_pdata;
|
|
|
|
|
2014-02-26 22:59:21 +00:00
|
|
|
dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++;
|
2015-03-25 18:21:56 +00:00
|
|
|
ut_assert(!device_active(dev));
|
2014-02-26 22:59:21 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2015-04-15 11:07:19 +00:00
|
|
|
ut_assert(uc_pdata);
|
|
|
|
|
|
|
|
uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1;
|
|
|
|
uc_pdata->intval2 = TEST_UC_PDATA_INTVAL2;
|
|
|
|
uc_pdata->intval3 = TEST_UC_PDATA_INTVAL3;
|
|
|
|
|
2014-02-26 22:59:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_pre_unbind(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-05 19:25:22 +00:00
|
|
|
static int test_pre_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]++;
|
|
|
|
ut_assert(priv);
|
2015-03-25 18:21:56 +00:00
|
|
|
ut_assert(device_active(dev));
|
2015-03-05 19:25:22 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_post_probe(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
2014-05-22 10:43:05 +00:00
|
|
|
struct udevice *prev = list_entry(dev->uclass_node.prev,
|
|
|
|
struct udevice, uclass_node);
|
|
|
|
|
2015-03-05 19:25:20 +00:00
|
|
|
struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
|
2014-02-26 22:59:21 +00:00
|
|
|
struct uclass *uc = dev->uclass;
|
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_POST_PROBE]++;
|
|
|
|
ut_assert(priv);
|
|
|
|
ut_assert(device_active(dev));
|
|
|
|
priv->base_add = 0;
|
|
|
|
if (dms->skip_post_probe)
|
|
|
|
return 0;
|
|
|
|
if (&prev->uclass_node != &uc->dev_head) {
|
|
|
|
struct dm_test_uclass_perdev_priv *prev_uc_priv
|
2015-03-05 19:25:20 +00:00
|
|
|
= dev_get_uclass_priv(prev);
|
2020-12-23 02:30:28 +00:00
|
|
|
struct dm_test_pdata *pdata = dev_get_plat(prev);
|
2014-02-26 22:59:21 +00:00
|
|
|
|
|
|
|
ut_assert(pdata);
|
|
|
|
ut_assert(prev_uc_priv);
|
|
|
|
priv->base_add = prev_uc_priv->base_add + pdata->ping_add;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
static int test_pre_remove(struct udevice *dev)
|
2014-02-26 22:59:21 +00:00
|
|
|
{
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_PRE_REMOVE]++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_init(struct uclass *uc)
|
|
|
|
{
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_INIT]++;
|
2020-12-23 02:30:28 +00:00
|
|
|
ut_assert(uclass_get_priv(uc));
|
2014-02-26 22:59:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_destroy(struct uclass *uc)
|
|
|
|
{
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_DESTROY]++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UCLASS_DRIVER(test) = {
|
|
|
|
.name = "test",
|
|
|
|
.id = UCLASS_TEST,
|
|
|
|
.post_bind = test_post_bind,
|
|
|
|
.pre_unbind = test_pre_unbind,
|
2015-03-05 19:25:22 +00:00
|
|
|
.pre_probe = test_pre_probe,
|
2014-02-26 22:59:21 +00:00
|
|
|
.post_probe = test_post_probe,
|
|
|
|
.pre_remove = test_pre_remove,
|
|
|
|
.init = test_init,
|
|
|
|
.destroy = test_destroy,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct dm_test_uclass_priv),
|
|
|
|
.per_device_auto = sizeof(struct dm_test_uclass_perdev_priv),
|
2020-12-03 23:55:22 +00:00
|
|
|
.per_device_plat_auto = sizeof(struct dm_test_perdev_uc_pdata),
|
2014-02-26 22:59:21 +00:00
|
|
|
};
|