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 device *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 device *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 device *dev) 39 { 40 dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]++; 41 42 return 0; 43 } 44 45 static int test_post_probe(struct device *dev) 46 { 47 struct device *prev = list_entry(dev->uclass_node.prev, struct device, 48 uclass_node); 49 struct dm_test_uclass_perdev_priv *priv = dev->uclass_priv; 50 struct uclass *uc = dev->uclass; 51 52 dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]++; 53 ut_assert(priv); 54 ut_assert(device_active(dev)); 55 priv->base_add = 0; 56 if (dms->skip_post_probe) 57 return 0; 58 if (&prev->uclass_node != &uc->dev_head) { 59 struct dm_test_uclass_perdev_priv *prev_uc_priv 60 = prev->uclass_priv; 61 struct dm_test_pdata *pdata = prev->platdata; 62 63 ut_assert(pdata); 64 ut_assert(prev_uc_priv); 65 priv->base_add = prev_uc_priv->base_add + pdata->ping_add; 66 } 67 68 return 0; 69 } 70 71 static int test_pre_remove(struct device *dev) 72 { 73 dm_testdrv_op_count[DM_TEST_OP_PRE_REMOVE]++; 74 75 return 0; 76 } 77 78 static int test_init(struct uclass *uc) 79 { 80 dm_testdrv_op_count[DM_TEST_OP_INIT]++; 81 ut_assert(uc->priv); 82 83 return 0; 84 } 85 86 static int test_destroy(struct uclass *uc) 87 { 88 dm_testdrv_op_count[DM_TEST_OP_DESTROY]++; 89 90 return 0; 91 } 92 93 UCLASS_DRIVER(test) = { 94 .name = "test", 95 .id = UCLASS_TEST, 96 .post_bind = test_post_bind, 97 .pre_unbind = test_pre_unbind, 98 .post_probe = test_post_probe, 99 .pre_remove = test_pre_remove, 100 .init = test_init, 101 .destroy = test_destroy, 102 .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv), 103 .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv), 104 }; 105