2 * Copyright (c) 2013 Google, Inc
5 * Pavel Herrmann <morpheus.ibis@gmail.com>
7 * SPDX-License-Identifier: GPL-2.0+
16 #include <linux/list.h>
19 static struct unit_test_state
*uts
= &global_dm_test_state
;
21 int test_ping(struct udevice
*dev
, int pingval
, int *pingret
)
23 const struct test_ops
*ops
= device_get_ops(dev
);
28 return ops
->ping(dev
, pingval
, pingret
);
31 static int test_post_bind(struct udevice
*dev
)
33 struct dm_test_perdev_uc_pdata
*uc_pdata
;
35 dm_testdrv_op_count
[DM_TEST_OP_POST_BIND
]++;
36 ut_assert(!device_active(dev
));
38 uc_pdata
= dev_get_uclass_platdata(dev
);
41 uc_pdata
->intval1
= TEST_UC_PDATA_INTVAL1
;
42 uc_pdata
->intval2
= TEST_UC_PDATA_INTVAL2
;
43 uc_pdata
->intval3
= TEST_UC_PDATA_INTVAL3
;
48 static int test_pre_unbind(struct udevice
*dev
)
50 dm_testdrv_op_count
[DM_TEST_OP_PRE_UNBIND
]++;
55 static int test_pre_probe(struct udevice
*dev
)
57 struct dm_test_uclass_perdev_priv
*priv
= dev_get_uclass_priv(dev
);
59 dm_testdrv_op_count
[DM_TEST_OP_PRE_PROBE
]++;
61 ut_assert(device_active(dev
));
66 static int test_post_probe(struct udevice
*dev
)
68 struct udevice
*prev
= list_entry(dev
->uclass_node
.prev
,
69 struct udevice
, uclass_node
);
71 struct dm_test_uclass_perdev_priv
*priv
= dev_get_uclass_priv(dev
);
72 struct uclass
*uc
= dev
->uclass
;
73 struct dm_test_state
*dms
= uts
->priv
;
75 dm_testdrv_op_count
[DM_TEST_OP_POST_PROBE
]++;
77 ut_assert(device_active(dev
));
79 if (dms
->skip_post_probe
)
81 if (&prev
->uclass_node
!= &uc
->dev_head
) {
82 struct dm_test_uclass_perdev_priv
*prev_uc_priv
83 = dev_get_uclass_priv(prev
);
84 struct dm_test_pdata
*pdata
= prev
->platdata
;
87 ut_assert(prev_uc_priv
);
88 priv
->base_add
= prev_uc_priv
->base_add
+ pdata
->ping_add
;
94 static int test_pre_remove(struct udevice
*dev
)
96 dm_testdrv_op_count
[DM_TEST_OP_PRE_REMOVE
]++;
101 static int test_init(struct uclass
*uc
)
103 dm_testdrv_op_count
[DM_TEST_OP_INIT
]++;
109 static int test_destroy(struct uclass
*uc
)
111 dm_testdrv_op_count
[DM_TEST_OP_DESTROY
]++;
116 UCLASS_DRIVER(test
) = {
119 .post_bind
= test_post_bind
,
120 .pre_unbind
= test_pre_unbind
,
121 .pre_probe
= test_pre_probe
,
122 .post_probe
= test_post_probe
,
123 .pre_remove
= test_pre_remove
,
125 .destroy
= test_destroy
,
126 .priv_auto_alloc_size
= sizeof(struct dm_test_uclass_priv
),
127 .per_device_auto_alloc_size
= sizeof(struct dm_test_uclass_perdev_priv
),
128 .per_device_platdata_auto_alloc_size
=
129 sizeof(struct dm_test_perdev_uc_pdata
),