blob: 08008d875ab73e6796c1b4d4e23e8aa02394d1f3 [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
6#include <common.h>
7#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <malloc.h>
Stephen Warren6488e642016-06-17 09:43:59 -060010#include <reset-uclass.h>
11#include <asm/io.h>
12#include <asm/reset.h>
13
Neil Armstrong20c633d2018-04-03 11:40:51 +020014#define SANDBOX_RESET_SIGNALS 101
Stephen Warren6488e642016-06-17 09:43:59 -060015
16struct sandbox_reset_signal {
17 bool asserted;
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053018 bool requested;
Stephen Warren6488e642016-06-17 09:43:59 -060019};
20
21struct sandbox_reset {
22 struct sandbox_reset_signal signals[SANDBOX_RESET_SIGNALS];
23};
24
25static int sandbox_reset_request(struct reset_ctl *reset_ctl)
26{
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053027 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
28
Stephen Warren6488e642016-06-17 09:43:59 -060029 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
30
31 if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
32 return -EINVAL;
33
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053034 sbr->signals[reset_ctl->id].requested = true;
Stephen Warren6488e642016-06-17 09:43:59 -060035 return 0;
36}
37
38static int sandbox_reset_free(struct reset_ctl *reset_ctl)
39{
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053040 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
41
Stephen Warren6488e642016-06-17 09:43:59 -060042 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
43
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +053044 sbr->signals[reset_ctl->id].requested = false;
Stephen Warren6488e642016-06-17 09:43:59 -060045 return 0;
46}
47
48static int sandbox_reset_assert(struct reset_ctl *reset_ctl)
49{
50 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
51
52 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
53
54 sbr->signals[reset_ctl->id].asserted = true;
55
56 return 0;
57}
58
59static int sandbox_reset_deassert(struct reset_ctl *reset_ctl)
60{
61 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
62
63 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
64
65 sbr->signals[reset_ctl->id].asserted = false;
66
67 return 0;
68}
69
70static int sandbox_reset_bind(struct udevice *dev)
71{
72 debug("%s(dev=%p)\n", __func__, dev);
73
74 return 0;
75}
76
77static int sandbox_reset_probe(struct udevice *dev)
78{
79 debug("%s(dev=%p)\n", __func__, dev);
80
81 return 0;
82}
83
84static const struct udevice_id sandbox_reset_ids[] = {
85 { .compatible = "sandbox,reset-ctl" },
86 { }
87};
88
89struct reset_ops sandbox_reset_reset_ops = {
90 .request = sandbox_reset_request,
Simon Glass1928cd42020-02-03 07:35:52 -070091 .rfree = sandbox_reset_free,
Stephen Warren6488e642016-06-17 09:43:59 -060092 .rst_assert = sandbox_reset_assert,
93 .rst_deassert = sandbox_reset_deassert,
94};
95
96U_BOOT_DRIVER(sandbox_reset) = {
97 .name = "sandbox_reset",
98 .id = UCLASS_RESET,
99 .of_match = sandbox_reset_ids,
100 .bind = sandbox_reset_bind,
101 .probe = sandbox_reset_probe,
102 .priv_auto_alloc_size = sizeof(struct sandbox_reset),
103 .ops = &sandbox_reset_reset_ops,
104};
105
106int sandbox_reset_query(struct udevice *dev, unsigned long id)
107{
108 struct sandbox_reset *sbr = dev_get_priv(dev);
109
110 debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
111
112 if (id >= SANDBOX_RESET_SIGNALS)
113 return -EINVAL;
114
115 return sbr->signals[id].asserted;
116}
Jean-Jacques Hiblot880c5c72020-09-09 15:37:04 +0530117
118int sandbox_reset_is_requested(struct udevice *dev, unsigned long id)
119{
120 struct sandbox_reset *sbr = dev_get_priv(dev);
121
122 debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
123
124 if (id >= SANDBOX_RESET_SIGNALS)
125 return -EINVAL;
126
127 return sbr->signals[id].requested;
128}