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