]> Git Repo - J-u-boot.git/blob - test/dm/test-uclass.c
Merge tag 'u-boot-imx-20221024' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx
[J-u-boot.git] / test / dm / test-uclass.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2013 Google, Inc
4  *
5  * (C) Copyright 2012
6  * Pavel Herrmann <[email protected]>
7  */
8
9 #include <common.h>
10 #include <log.h>
11 #include <malloc.h>
12 #include <dm.h>
13 #include <errno.h>
14 #include <asm/io.h>
15 #include <dm/test.h>
16 #include <linux/list.h>
17 #include <test/test.h>
18 #include <test/ut.h>
19
20 int test_ping(struct udevice *dev, int pingval, int *pingret)
21 {
22         const struct test_ops *ops = device_get_ops(dev);
23
24         if (!ops->ping)
25                 return -ENOSYS;
26
27         return ops->ping(dev, pingval, pingret);
28 }
29
30 static int test_post_bind(struct udevice *dev)
31 {
32         struct unit_test_state *uts = test_get_state();
33         struct dm_test_perdev_uc_pdata *uc_pdata;
34
35         dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++;
36         ut_assert(!device_active(dev));
37
38         uc_pdata = dev_get_uclass_plat(dev);
39         ut_assert(uc_pdata);
40
41         uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1;
42         uc_pdata->intval2 = TEST_UC_PDATA_INTVAL2;
43         uc_pdata->intval3 = TEST_UC_PDATA_INTVAL3;
44
45         return 0;
46 }
47
48 static int test_pre_unbind(struct udevice *dev)
49 {
50         dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]++;
51
52         return 0;
53 }
54
55 static int test_pre_probe(struct udevice *dev)
56 {
57         struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
58         struct unit_test_state *uts = test_get_state();
59
60         dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]++;
61         ut_assert(priv);
62         ut_assert(device_active(dev));
63
64         return 0;
65 }
66
67 static int test_post_probe(struct udevice *dev)
68 {
69         struct unit_test_state *uts = test_get_state();
70         struct udevice *prev = list_entry(dev->uclass_node.prev,
71                                             struct udevice, uclass_node);
72
73         struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
74         struct uclass *uc = dev->uclass;
75
76         dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]++;
77         ut_assert(priv);
78         ut_assert(device_active(dev));
79         priv->base_add = 0;
80         if (uts->skip_post_probe)
81                 return 0;
82         if (&prev->uclass_node != &uc->dev_head) {
83                 struct dm_test_uclass_perdev_priv *prev_uc_priv
84                                 = dev_get_uclass_priv(prev);
85                 struct dm_test_pdata *pdata = dev_get_plat(prev);
86
87                 ut_assert(pdata);
88                 ut_assert(prev_uc_priv);
89                 priv->base_add = prev_uc_priv->base_add + pdata->ping_add;
90         }
91
92         return 0;
93 }
94
95 static int test_pre_remove(struct udevice *dev)
96 {
97         dm_testdrv_op_count[DM_TEST_OP_PRE_REMOVE]++;
98
99         return 0;
100 }
101
102 static int test_init(struct uclass *uc)
103 {
104         struct unit_test_state *uts = test_get_state();
105
106         dm_testdrv_op_count[DM_TEST_OP_INIT]++;
107         ut_assert(uclass_get_priv(uc));
108
109         return 0;
110 }
111
112 static int test_destroy(struct uclass *uc)
113 {
114         dm_testdrv_op_count[DM_TEST_OP_DESTROY]++;
115
116         return 0;
117 }
118
119 UCLASS_DRIVER(test) = {
120         .name           = "test",
121         .id             = UCLASS_TEST,
122         .post_bind      = test_post_bind,
123         .pre_unbind     = test_pre_unbind,
124         .pre_probe      = test_pre_probe,
125         .post_probe     = test_post_probe,
126         .pre_remove     = test_pre_remove,
127         .init           = test_init,
128         .destroy        = test_destroy,
129         .priv_auto      = sizeof(struct dm_test_uclass_priv),
130         .per_device_auto        = sizeof(struct dm_test_uclass_perdev_priv),
131         .per_device_plat_auto   = sizeof(struct dm_test_perdev_uc_pdata),
132 };
This page took 0.033306 seconds and 4 git commands to generate.