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