common: Drop log.h from common header
[oweals/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 };
19
20 struct sandbox_reset {
21         struct sandbox_reset_signal signals[SANDBOX_RESET_SIGNALS];
22 };
23
24 static 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
34 static 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
41 static 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
52 static 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
63 static int sandbox_reset_bind(struct udevice *dev)
64 {
65         debug("%s(dev=%p)\n", __func__, dev);
66
67         return 0;
68 }
69
70 static int sandbox_reset_probe(struct udevice *dev)
71 {
72         debug("%s(dev=%p)\n", __func__, dev);
73
74         return 0;
75 }
76
77 static const struct udevice_id sandbox_reset_ids[] = {
78         { .compatible = "sandbox,reset-ctl" },
79         { }
80 };
81
82 struct reset_ops sandbox_reset_reset_ops = {
83         .request = sandbox_reset_request,
84         .rfree = sandbox_reset_free,
85         .rst_assert = sandbox_reset_assert,
86         .rst_deassert = sandbox_reset_deassert,
87 };
88
89 U_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
99 int 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 }