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