2 * Copyright (c) 2016 Stanislav Galabov
3 * Copyright (c) 2014 Ian Lepore <ian@freebsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 #include <sys/param.h>
32 #include <sys/kernel.h>
34 #include <sys/mutex.h>
35 #include <sys/queue.h>
36 #include <sys/systm.h>
38 #include <dev/ofw/ofw_bus.h>
39 #include <dev/ofw/ofw_bus_subr.h>
41 #include "fdt_reset_if.h"
42 #include <mips/mediatek/fdt_reset.h>
45 * Loop through all the tuples in the resets= property for a device, asserting
46 * or deasserting each reset.
48 * Be liberal about errors for now: warn about a failure to (de)assert but keep
49 * trying with any other resets in the list. Return ENXIO if any errors were
50 * found, and let the caller decide whether the problem is fatal.
53 assert_deassert_all(device_t consumer, boolean_t assert)
57 int resetnum, err, i, ncells;
61 rnode = ofw_bus_get_node(consumer);
62 ncells = OF_getencprop_alloc_multi(rnode, "resets", sizeof(*resets),
64 if (!assert && ncells < 2) {
65 device_printf(consumer, "Warning: No resets specified in fdt "
66 "data; device may not function.");
70 for (i = 0; i < ncells; i += 2) {
71 resetdev = OF_device_from_xref(resets[i]);
72 resetnum = resets[i + 1];
73 if (resetdev == NULL) {
75 device_printf(consumer, "Warning: can not find "
76 "driver for reset number %u; device may "
77 "not function\n", resetnum);
82 err = FDT_RESET_ASSERT(resetdev, resetnum);
84 err = FDT_RESET_DEASSERT(resetdev, resetnum);
87 device_printf(consumer, "Warning: failed to "
88 "deassert reset number %u; device may not "
89 "function\n", resetnum);
94 return (anyerrors ? ENXIO : 0);
98 fdt_reset_assert_all(device_t consumer)
101 return (assert_deassert_all(consumer, true));
105 fdt_reset_deassert_all(device_t consumer)
108 return (assert_deassert_all(consumer, false));
112 fdt_reset_register_provider(device_t provider)
115 OF_device_register_xref(
116 OF_xref_from_node(ofw_bus_get_node(provider)), provider);
120 fdt_reset_unregister_provider(device_t provider)
123 OF_device_register_xref(OF_xref_from_device(provider), NULL);