blob: dfacb764bc775a641c70611959c218543b317626 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren6488e642016-06-17 09:43:59 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warren6488e642016-06-17 09:43:59 -06004 */
5
Stephen Warren6488e642016-06-17 09:43:59 -06006#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -07008#include <malloc.h>
Stephen Warren6488e642016-06-17 09:43:59 -06009#include <reset.h>
10#include <asm/io.h>
11#include <asm/reset.h>
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053012#include <linux/err.h>
Stephen Warren6488e642016-06-17 09:43:59 -060013
14struct sandbox_reset_test {
15 struct reset_ctl ctl;
Neil Armstrong20c633d2018-04-03 11:40:51 +020016 struct reset_ctl_bulk bulk;
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053017
18 struct reset_ctl *ctlp;
19 struct reset_ctl_bulk *bulkp;
Stephen Warren6488e642016-06-17 09:43:59 -060020};
21
22int sandbox_reset_test_get(struct udevice *dev)
23{
24 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
25
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053026 sbrt->ctlp = &sbrt->ctl;
Stephen Warren6488e642016-06-17 09:43:59 -060027 return reset_get_by_name(dev, "test", &sbrt->ctl);
28}
29
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053030int 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 Armstrong20c633d2018-04-03 11:40:51 +020050int sandbox_reset_test_get_bulk(struct udevice *dev)
51{
52 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
53
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053054 sbrt->bulkp = &sbrt->bulk;
Neil Armstrong20c633d2018-04-03 11:40:51 +020055 return reset_get_bulk(dev, &sbrt->bulk);
56}
57
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053058int 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 Warren6488e642016-06-17 09:43:59 -060071int sandbox_reset_test_assert(struct udevice *dev)
72{
73 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
74
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053075 return reset_assert(sbrt->ctlp);
Stephen Warren6488e642016-06-17 09:43:59 -060076}
77
Neil Armstrong20c633d2018-04-03 11:40:51 +020078int sandbox_reset_test_assert_bulk(struct udevice *dev)
79{
80 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
81
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053082 return reset_assert_bulk(sbrt->bulkp);
Neil Armstrong20c633d2018-04-03 11:40:51 +020083}
84
Stephen Warren6488e642016-06-17 09:43:59 -060085int sandbox_reset_test_deassert(struct udevice *dev)
86{
87 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
88
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053089 return reset_deassert(sbrt->ctlp);
Stephen Warren6488e642016-06-17 09:43:59 -060090}
91
Neil Armstrong20c633d2018-04-03 11:40:51 +020092int sandbox_reset_test_deassert_bulk(struct udevice *dev)
93{
94 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
95
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053096 return reset_deassert_bulk(sbrt->bulkp);
Neil Armstrong20c633d2018-04-03 11:40:51 +020097}
98
Stephen Warren6488e642016-06-17 09:43:59 -060099int sandbox_reset_test_free(struct udevice *dev)
100{
101 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
102
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +0530103 return reset_free(sbrt->ctlp);
Stephen Warren6488e642016-06-17 09:43:59 -0600104}
105
Neil Armstrong20c633d2018-04-03 11:40:51 +0200106int sandbox_reset_test_release_bulk(struct udevice *dev)
107{
108 struct sandbox_reset_test *sbrt = dev_get_priv(dev);
109
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +0530110 return reset_release_bulk(sbrt->bulkp);
Neil Armstrong20c633d2018-04-03 11:40:51 +0200111}
112
Stephen Warren6488e642016-06-17 09:43:59 -0600113static const struct udevice_id sandbox_reset_test_ids[] = {
114 { .compatible = "sandbox,reset-ctl-test" },
115 { }
116};
117
118U_BOOT_DRIVER(sandbox_reset_test) = {
119 .name = "sandbox_reset_test",
120 .id = UCLASS_MISC,
121 .of_match = sandbox_reset_test_ids,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700122 .priv_auto = sizeof(struct sandbox_reset_test),
Stephen Warren6488e642016-06-17 09:43:59 -0600123};