blob: 40f2654d8e437cbbc1e60b8adcb55ce060a3ad5a [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>
8#include <reset-uclass.h>
9#include <asm/io.h>
10#include <asm/reset.h>
11
Neil Armstrong20c633d2018-04-03 11:40:51 +020012#define SANDBOX_RESET_SIGNALS 101
Stephen Warren6488e642016-06-17 09:43:59 -060013
14struct sandbox_reset_signal {
15 bool asserted;
16};
17
18struct sandbox_reset {
19 struct sandbox_reset_signal signals[SANDBOX_RESET_SIGNALS];
20};
21
22static int sandbox_reset_request(struct reset_ctl *reset_ctl)
23{
24 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
25
26 if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
27 return -EINVAL;
28
29 return 0;
30}
31
32static int sandbox_reset_free(struct reset_ctl *reset_ctl)
33{
34 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
35
36 return 0;
37}
38
39static int sandbox_reset_assert(struct reset_ctl *reset_ctl)
40{
41 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
42
43 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
44
45 sbr->signals[reset_ctl->id].asserted = true;
46
47 return 0;
48}
49
50static int sandbox_reset_deassert(struct reset_ctl *reset_ctl)
51{
52 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
53
54 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
55
56 sbr->signals[reset_ctl->id].asserted = false;
57
58 return 0;
59}
60
61static int sandbox_reset_bind(struct udevice *dev)
62{
63 debug("%s(dev=%p)\n", __func__, dev);
64
65 return 0;
66}
67
68static int sandbox_reset_probe(struct udevice *dev)
69{
70 debug("%s(dev=%p)\n", __func__, dev);
71
72 return 0;
73}
74
75static const struct udevice_id sandbox_reset_ids[] = {
76 { .compatible = "sandbox,reset-ctl" },
77 { }
78};
79
80struct reset_ops sandbox_reset_reset_ops = {
81 .request = sandbox_reset_request,
82 .free = sandbox_reset_free,
83 .rst_assert = sandbox_reset_assert,
84 .rst_deassert = sandbox_reset_deassert,
85};
86
87U_BOOT_DRIVER(sandbox_reset) = {
88 .name = "sandbox_reset",
89 .id = UCLASS_RESET,
90 .of_match = sandbox_reset_ids,
91 .bind = sandbox_reset_bind,
92 .probe = sandbox_reset_probe,
93 .priv_auto_alloc_size = sizeof(struct sandbox_reset),
94 .ops = &sandbox_reset_reset_ops,
95};
96
97int sandbox_reset_query(struct udevice *dev, unsigned long id)
98{
99 struct sandbox_reset *sbr = dev_get_priv(dev);
100
101 debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
102
103 if (id >= SANDBOX_RESET_SIGNALS)
104 return -EINVAL;
105
106 return sbr->signals[id].asserted;
107}