Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 10 | #include <reset.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/reset.h> |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 13 | #include <linux/err.h> |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 14 | |
| 15 | struct sandbox_reset_test { |
| 16 | struct reset_ctl ctl; |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 17 | struct reset_ctl_bulk bulk; |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 18 | |
| 19 | struct reset_ctl *ctlp; |
| 20 | struct reset_ctl_bulk *bulkp; |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 21 | }; |
| 22 | |
| 23 | int sandbox_reset_test_get(struct udevice *dev) |
| 24 | { |
| 25 | struct sandbox_reset_test *sbrt = dev_get_priv(dev); |
| 26 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 27 | sbrt->ctlp = &sbrt->ctl; |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 28 | return reset_get_by_name(dev, "test", &sbrt->ctl); |
| 29 | } |
| 30 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 31 | int sandbox_reset_test_get_devm(struct udevice *dev) |
| 32 | { |
| 33 | struct sandbox_reset_test *sbrt = dev_get_priv(dev); |
| 34 | struct reset_ctl *r; |
| 35 | |
| 36 | r = devm_reset_control_get(dev, "not-a-valid-reset-ctl"); |
| 37 | if (!IS_ERR(r)) |
| 38 | return -EINVAL; |
| 39 | |
| 40 | r = devm_reset_control_get_optional(dev, "not-a-valid-reset-ctl"); |
| 41 | if (r) |
| 42 | return -EINVAL; |
| 43 | |
| 44 | sbrt->ctlp = devm_reset_control_get(dev, "test"); |
| 45 | if (IS_ERR(sbrt->ctlp)) |
| 46 | return PTR_ERR(sbrt->ctlp); |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 51 | int sandbox_reset_test_get_bulk(struct udevice *dev) |
| 52 | { |
| 53 | struct sandbox_reset_test *sbrt = dev_get_priv(dev); |
| 54 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 55 | sbrt->bulkp = &sbrt->bulk; |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 56 | return reset_get_bulk(dev, &sbrt->bulk); |
| 57 | } |
| 58 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 59 | int sandbox_reset_test_get_bulk_devm(struct udevice *dev) |
| 60 | { |
| 61 | struct sandbox_reset_test *sbrt = dev_get_priv(dev); |
| 62 | struct reset_ctl_bulk *r; |
| 63 | |
| 64 | r = devm_reset_bulk_get_optional(dev); |
| 65 | if (IS_ERR(r)) |
| 66 | return PTR_ERR(r); |
| 67 | |
| 68 | sbrt->bulkp = r; |
| 69 | return 0; |
| 70 | } |
| 71 | |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 72 | int sandbox_reset_test_assert(struct udevice *dev) |
| 73 | { |
| 74 | struct sandbox_reset_test *sbrt = dev_get_priv(dev); |
| 75 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 76 | return reset_assert(sbrt->ctlp); |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 77 | } |
| 78 | |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 79 | int sandbox_reset_test_assert_bulk(struct udevice *dev) |
| 80 | { |
| 81 | struct sandbox_reset_test *sbrt = dev_get_priv(dev); |
| 82 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 83 | return reset_assert_bulk(sbrt->bulkp); |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 86 | int sandbox_reset_test_deassert(struct udevice *dev) |
| 87 | { |
| 88 | struct sandbox_reset_test *sbrt = dev_get_priv(dev); |
| 89 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 90 | return reset_deassert(sbrt->ctlp); |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 91 | } |
| 92 | |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 93 | int sandbox_reset_test_deassert_bulk(struct udevice *dev) |
| 94 | { |
| 95 | struct sandbox_reset_test *sbrt = dev_get_priv(dev); |
| 96 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 97 | return reset_deassert_bulk(sbrt->bulkp); |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 100 | int sandbox_reset_test_free(struct udevice *dev) |
| 101 | { |
| 102 | struct sandbox_reset_test *sbrt = dev_get_priv(dev); |
| 103 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 104 | return reset_free(sbrt->ctlp); |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 105 | } |
| 106 | |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 107 | int sandbox_reset_test_release_bulk(struct udevice *dev) |
| 108 | { |
| 109 | struct sandbox_reset_test *sbrt = dev_get_priv(dev); |
| 110 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 111 | return reset_release_bulk(sbrt->bulkp); |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 112 | } |
| 113 | |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 114 | static const struct udevice_id sandbox_reset_test_ids[] = { |
| 115 | { .compatible = "sandbox,reset-ctl-test" }, |
| 116 | { } |
| 117 | }; |
| 118 | |
| 119 | U_BOOT_DRIVER(sandbox_reset_test) = { |
| 120 | .name = "sandbox_reset_test", |
| 121 | .id = UCLASS_MISC, |
| 122 | .of_match = sandbox_reset_test_ids, |
| 123 | .priv_auto_alloc_size = sizeof(struct sandbox_reset_test), |
| 124 | }; |