Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 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 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 21 | int test_ping(struct udevice *dev, int pingval, int *pingret) |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 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 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 31 | static int test_post_bind(struct udevice *dev) |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 32 | { |
| 33 | dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++; |
Simon Glass | 8b04e73 | 2015-03-25 12:21:56 -0600 | [diff] [blame] | 34 | ut_assert(!device_active(dev)); |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 39 | static int test_pre_unbind(struct udevice *dev) |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 40 | { |
| 41 | dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]++; |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
Simon Glass | 9c1f382 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 46 | static int test_pre_probe(struct udevice *dev) |
| 47 | { |
| 48 | struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev); |
| 49 | |
| 50 | dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]++; |
| 51 | ut_assert(priv); |
Simon Glass | 8b04e73 | 2015-03-25 12:21:56 -0600 | [diff] [blame] | 52 | ut_assert(device_active(dev)); |
Simon Glass | 9c1f382 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 57 | static int test_post_probe(struct udevice *dev) |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 58 | { |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 59 | struct udevice *prev = list_entry(dev->uclass_node.prev, |
| 60 | struct udevice, uclass_node); |
| 61 | |
Simon Glass | de0977b | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 62 | struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev); |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 63 | struct uclass *uc = dev->uclass; |
| 64 | |
| 65 | dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]++; |
| 66 | ut_assert(priv); |
| 67 | ut_assert(device_active(dev)); |
| 68 | priv->base_add = 0; |
| 69 | if (dms->skip_post_probe) |
| 70 | return 0; |
| 71 | if (&prev->uclass_node != &uc->dev_head) { |
| 72 | struct dm_test_uclass_perdev_priv *prev_uc_priv |
Simon Glass | de0977b | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 73 | = dev_get_uclass_priv(prev); |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 74 | struct dm_test_pdata *pdata = prev->platdata; |
| 75 | |
| 76 | ut_assert(pdata); |
| 77 | ut_assert(prev_uc_priv); |
| 78 | priv->base_add = prev_uc_priv->base_add + pdata->ping_add; |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 84 | static int test_pre_remove(struct udevice *dev) |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 85 | { |
| 86 | dm_testdrv_op_count[DM_TEST_OP_PRE_REMOVE]++; |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static int test_init(struct uclass *uc) |
| 92 | { |
| 93 | dm_testdrv_op_count[DM_TEST_OP_INIT]++; |
| 94 | ut_assert(uc->priv); |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static int test_destroy(struct uclass *uc) |
| 100 | { |
| 101 | dm_testdrv_op_count[DM_TEST_OP_DESTROY]++; |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | UCLASS_DRIVER(test) = { |
| 107 | .name = "test", |
| 108 | .id = UCLASS_TEST, |
| 109 | .post_bind = test_post_bind, |
| 110 | .pre_unbind = test_pre_unbind, |
Simon Glass | 9c1f382 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 111 | .pre_probe = test_pre_probe, |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 112 | .post_probe = test_post_probe, |
| 113 | .pre_remove = test_pre_remove, |
| 114 | .init = test_init, |
| 115 | .destroy = test_destroy, |
| 116 | .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv), |
| 117 | .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv), |
| 118 | }; |