Prepare v2023.10
[platform/kernel/u-boot.git] / drivers / reset / sandbox-reset.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2016, NVIDIA CORPORATION.
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <log.h>
9 #include <malloc.h>
10 #include <reset-uclass.h>
11 #include <asm/io.h>
12 #include <asm/reset.h>
13
14 #define SANDBOX_RESET_SIGNALS 101
15
16 struct sandbox_reset_signal {
17         bool asserted;
18         bool requested;
19 };
20
21 struct sandbox_reset {
22         struct sandbox_reset_signal signals[SANDBOX_RESET_SIGNALS];
23 };
24
25 static int sandbox_reset_request(struct reset_ctl *reset_ctl)
26 {
27         struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
28
29         debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
30
31         if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
32                 return -EINVAL;
33
34         sbr->signals[reset_ctl->id].requested = true;
35         return 0;
36 }
37
38 static int sandbox_reset_free(struct reset_ctl *reset_ctl)
39 {
40         struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
41
42         debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
43
44         sbr->signals[reset_ctl->id].requested = false;
45         return 0;
46 }
47
48 static 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
59 static 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
70 static int sandbox_reset_bind(struct udevice *dev)
71 {
72         debug("%s(dev=%p)\n", __func__, dev);
73
74         return 0;
75 }
76
77 static int sandbox_reset_probe(struct udevice *dev)
78 {
79         debug("%s(dev=%p)\n", __func__, dev);
80
81         return 0;
82 }
83
84 static const struct udevice_id sandbox_reset_ids[] = {
85         { .compatible = "sandbox,reset-ctl" },
86         { }
87 };
88
89 struct reset_ops sandbox_reset_reset_ops = {
90         .request = sandbox_reset_request,
91         .rfree = sandbox_reset_free,
92         .rst_assert = sandbox_reset_assert,
93         .rst_deassert = sandbox_reset_deassert,
94 };
95
96 U_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      = sizeof(struct sandbox_reset),
103         .ops = &sandbox_reset_reset_ops,
104 };
105
106 int 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 }
117
118 int 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 }