blob: 7a6f7f676cc48e3459aab4548adcfe34434b329a [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;
18};
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{
26 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
27
28 if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
29 return -EINVAL;
30
31 return 0;
32}
33
34static int sandbox_reset_free(struct reset_ctl *reset_ctl)
35{
36 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
37
38 return 0;
39}
40
41static int sandbox_reset_assert(struct reset_ctl *reset_ctl)
42{
43 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
44
45 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
46
47 sbr->signals[reset_ctl->id].asserted = true;
48
49 return 0;
50}
51
52static int sandbox_reset_deassert(struct reset_ctl *reset_ctl)
53{
54 struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
55
56 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
57
58 sbr->signals[reset_ctl->id].asserted = false;
59
60 return 0;
61}
62
63static int sandbox_reset_bind(struct udevice *dev)
64{
65 debug("%s(dev=%p)\n", __func__, dev);
66
67 return 0;
68}
69
70static int sandbox_reset_probe(struct udevice *dev)
71{
72 debug("%s(dev=%p)\n", __func__, dev);
73
74 return 0;
75}
76
77static const struct udevice_id sandbox_reset_ids[] = {
78 { .compatible = "sandbox,reset-ctl" },
79 { }
80};
81
82struct reset_ops sandbox_reset_reset_ops = {
83 .request = sandbox_reset_request,
Simon Glass1928cd42020-02-03 07:35:52 -070084 .rfree = sandbox_reset_free,
Stephen Warren6488e642016-06-17 09:43:59 -060085 .rst_assert = sandbox_reset_assert,
86 .rst_deassert = sandbox_reset_deassert,
87};
88
89U_BOOT_DRIVER(sandbox_reset) = {
90 .name = "sandbox_reset",
91 .id = UCLASS_RESET,
92 .of_match = sandbox_reset_ids,
93 .bind = sandbox_reset_bind,
94 .probe = sandbox_reset_probe,
95 .priv_auto_alloc_size = sizeof(struct sandbox_reset),
96 .ops = &sandbox_reset_reset_ops,
97};
98
99int sandbox_reset_query(struct udevice *dev, unsigned long id)
100{
101 struct sandbox_reset *sbr = dev_get_priv(dev);
102
103 debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
104
105 if (id >= SANDBOX_RESET_SIGNALS)
106 return -EINVAL;
107
108 return sbr->signals[id].asserted;
109}