]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - test/dm/test-uclass.c
dm: core: Add a uclass pre_probe() method for devices
[karo-tx-uboot.git] / test / dm / test-uclass.c
1 /*
2  * Copyright (c) 2013 Google, Inc
3  *
4  * (C) Copyright 2012
5  * Pavel Herrmann <morpheus.ibis@gmail.com>
6  *
7  * SPDX-License-Identifier:     GPL-2.0+
8  */
9
10 #include <common.h>
11 #include <malloc.h>
12 #include <dm.h>
13 #include <errno.h>
14 #include <dm/test.h>
15 #include <dm/ut.h>
16 #include <asm/io.h>
17 #include <linux/list.h>
18
19 static struct dm_test_state *dms = &global_test_state;
20
21 int test_ping(struct udevice *dev, int pingval, int *pingret)
22 {
23         const struct test_ops *ops = device_get_ops(dev);
24
25         if (!ops->ping)
26                 return -ENOSYS;
27
28         return ops->ping(dev, pingval, pingret);
29 }
30
31 static int test_post_bind(struct udevice *dev)
32 {
33         dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++;
34
35         return 0;
36 }
37
38 static int test_pre_unbind(struct udevice *dev)
39 {
40         dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]++;
41
42         return 0;
43 }
44
45 static int test_pre_probe(struct udevice *dev)
46 {
47         struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
48
49         dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]++;
50         ut_assert(priv);
51         ut_assert(!device_active(dev));
52
53         return 0;
54 }
55
56 static int test_post_probe(struct udevice *dev)
57 {
58         struct udevice *prev = list_entry(dev->uclass_node.prev,
59                                             struct udevice, uclass_node);
60
61         struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
62         struct uclass *uc = dev->uclass;
63
64         dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]++;
65         ut_assert(priv);
66         ut_assert(device_active(dev));
67         priv->base_add = 0;
68         if (dms->skip_post_probe)
69                 return 0;
70         if (&prev->uclass_node != &uc->dev_head) {
71                 struct dm_test_uclass_perdev_priv *prev_uc_priv
72                                 = dev_get_uclass_priv(prev);
73                 struct dm_test_pdata *pdata = prev->platdata;
74
75                 ut_assert(pdata);
76                 ut_assert(prev_uc_priv);
77                 priv->base_add = prev_uc_priv->base_add + pdata->ping_add;
78         }
79
80         return 0;
81 }
82
83 static int test_pre_remove(struct udevice *dev)
84 {
85         dm_testdrv_op_count[DM_TEST_OP_PRE_REMOVE]++;
86
87         return 0;
88 }
89
90 static int test_init(struct uclass *uc)
91 {
92         dm_testdrv_op_count[DM_TEST_OP_INIT]++;
93         ut_assert(uc->priv);
94
95         return 0;
96 }
97
98 static int test_destroy(struct uclass *uc)
99 {
100         dm_testdrv_op_count[DM_TEST_OP_DESTROY]++;
101
102         return 0;
103 }
104
105 UCLASS_DRIVER(test) = {
106         .name           = "test",
107         .id             = UCLASS_TEST,
108         .post_bind      = test_post_bind,
109         .pre_unbind     = test_pre_unbind,
110         .pre_probe      = test_pre_probe,
111         .post_probe     = test_post_probe,
112         .pre_remove     = test_pre_remove,
113         .init           = test_init,
114         .destroy        = test_destroy,
115         .priv_auto_alloc_size   = sizeof(struct dm_test_uclass_priv),
116         .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv),
117 };