blob: adf9eedcba6dcd6cc8fae388756e0a909e343e99 [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-uclass.h>
10#include <asm/io.h>
11#include <asm/reset.h>
12
Neil Armstrong20c633d2018-04-03 11:40:51 +020013#define SANDBOX_RESET_SIGNALS 101
Stephen Warren6488e642016-06-17 09:43:59 -060014
15struct sandbox_reset_signal {
16 bool asserted;
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053017 bool requested;
Stephen Warren6488e642016-06-17 09:43:59 -060018};
19
20struct sandbox_reset {
21 struct sandbox_reset_signal signals[SANDBOX_RESET_SIGNALS];
22};
23
24static int sandbox_reset_request(struct reset_ctl *reset_ctl)
25{
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053026 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
27
Stephen Warren6488e642016-06-17 09:43:59 -060028 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
29
30 if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
31 return -EINVAL;
32
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053033 sbr->signals[reset_ctl->id].requested = true;
Stephen Warren6488e642016-06-17 09:43:59 -060034 return 0;
35}
36
37static int sandbox_reset_free(struct reset_ctl *reset_ctl)
38{
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053039 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
40
Stephen Warren6488e642016-06-17 09:43:59 -060041 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
42
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053043 sbr->signals[reset_ctl->id].requested = false;
Stephen Warren6488e642016-06-17 09:43:59 -060044 return 0;
45}
46
47static int sandbox_reset_assert(struct reset_ctl *reset_ctl)
48{
49 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
50
51 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
52
53 sbr->signals[reset_ctl->id].asserted = true;
54
55 return 0;
56}
57
58static int sandbox_reset_deassert(struct reset_ctl *reset_ctl)
59{
60 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
61
62 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
63
64 sbr->signals[reset_ctl->id].asserted = false;
65
66 return 0;
67}
68
69static int sandbox_reset_bind(struct udevice *dev)
70{
71 debug("%s(dev=%p)\n", __func__, dev);
72
73 return 0;
74}
75
76static int sandbox_reset_probe(struct udevice *dev)
77{
78 debug("%s(dev=%p)\n", __func__, dev);
79
80 return 0;
81}
82
83static const struct udevice_id sandbox_reset_ids[] = {
84 { .compatible = "sandbox,reset-ctl" },
85 { }
86};
87
88struct reset_ops sandbox_reset_reset_ops = {
89 .request = sandbox_reset_request,
Simon Glass1928cd42020-02-03 07:35:52 -070090 .rfree = sandbox_reset_free,
Stephen Warren6488e642016-06-17 09:43:59 -060091 .rst_assert = sandbox_reset_assert,
92 .rst_deassert = sandbox_reset_deassert,
93};
94
95U_BOOT_DRIVER(sandbox_reset) = {
96 .name = "sandbox_reset",
97 .id = UCLASS_RESET,
98 .of_match = sandbox_reset_ids,
99 .bind = sandbox_reset_bind,
100 .probe = sandbox_reset_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700101 .priv_auto = sizeof(struct sandbox_reset),
Stephen Warren6488e642016-06-17 09:43:59 -0600102 .ops = &sandbox_reset_reset_ops,
103};
104
105int sandbox_reset_query(struct udevice *dev, unsigned long id)
106{
107 struct sandbox_reset *sbr = dev_get_priv(dev);
108
109 debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
110
111 if (id >= SANDBOX_RESET_SIGNALS)
112 return -EINVAL;
113
114 return sbr->signals[id].asserted;
115}
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +0530116
117int sandbox_reset_is_requested(struct udevice *dev, unsigned long id)
118{
119 struct sandbox_reset *sbr = dev_get_priv(dev);
120
121 debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
122
123 if (id >= SANDBOX_RESET_SIGNALS)
124 return -EINVAL;
125
126 return sbr->signals[id].requested;
127}