blob: 10e02f1036241757ded86a0ff75558ee931252e1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren4581b712016-06-17 09:43:59 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warren4581b712016-06-17 09:43:59 -06004 */
5
6#include <common.h>
7#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -07009#include <malloc.h>
Stephen Warren4581b712016-06-17 09:43:59 -060010#include <reset.h>
11#include <asm/io.h>
12#include <asm/reset.h>
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053013#include <linux/err.h>
Stephen Warren4581b712016-06-17 09:43:59 -060014
15struct sandbox_reset_test {
16 struct reset_ctl ctl;
Neil Armstrong91f5f8b2018-04-03 11:40:51 +020017 struct reset_ctl_bulk bulk;
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053018
19 struct reset_ctl *ctlp;
20 struct reset_ctl_bulk *bulkp;
Stephen Warren4581b712016-06-17 09:43:59 -060021};
22
23int sandbox_reset_test_get(struct udevice *dev)
24{
25 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
26
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053027 sbrt->ctlp = &sbrt->ctl;
Stephen Warren4581b712016-06-17 09:43:59 -060028 return reset_get_by_name(dev, "test", &sbrt->ctl);
29}
30
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053031int 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 Armstrong91f5f8b2018-04-03 11:40:51 +020051int sandbox_reset_test_get_bulk(struct udevice *dev)
52{
53 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
54
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053055 sbrt->bulkp = &sbrt->bulk;
Neil Armstrong91f5f8b2018-04-03 11:40:51 +020056 return reset_get_bulk(dev, &sbrt->bulk);
57}
58
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053059int 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 Warren4581b712016-06-17 09:43:59 -060072int sandbox_reset_test_assert(struct udevice *dev)
73{
74 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
75
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053076 return reset_assert(sbrt->ctlp);
Stephen Warren4581b712016-06-17 09:43:59 -060077}
78
Neil Armstrong91f5f8b2018-04-03 11:40:51 +020079int sandbox_reset_test_assert_bulk(struct udevice *dev)
80{
81 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
82
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053083 return reset_assert_bulk(sbrt->bulkp);
Neil Armstrong91f5f8b2018-04-03 11:40:51 +020084}
85
Stephen Warren4581b712016-06-17 09:43:59 -060086int sandbox_reset_test_deassert(struct udevice *dev)
87{
88 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
89
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053090 return reset_deassert(sbrt->ctlp);
Stephen Warren4581b712016-06-17 09:43:59 -060091}
92
Neil Armstrong91f5f8b2018-04-03 11:40:51 +020093int sandbox_reset_test_deassert_bulk(struct udevice *dev)
94{
95 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
96
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053097 return reset_deassert_bulk(sbrt->bulkp);
Neil Armstrong91f5f8b2018-04-03 11:40:51 +020098}
99
Stephen Warren4581b712016-06-17 09:43:59 -0600100int sandbox_reset_test_free(struct udevice *dev)
101{
102 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
103
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +0530104 return reset_free(sbrt->ctlp);
Stephen Warren4581b712016-06-17 09:43:59 -0600105}
106
Neil Armstrong91f5f8b2018-04-03 11:40:51 +0200107int sandbox_reset_test_release_bulk(struct udevice *dev)
108{
109 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
110
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +0530111 return reset_release_bulk(sbrt->bulkp);
Neil Armstrong91f5f8b2018-04-03 11:40:51 +0200112}
113
Stephen Warren4581b712016-06-17 09:43:59 -0600114static const struct udevice_id sandbox_reset_test_ids[] = {
115 { .compatible = "sandbox,reset-ctl-test" },
116 { }
117};
118
119U_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};