View | Details | Raw Unified | Return to bug 206228
Collapse All | Expand All

(-)b/sys/conf/files (+2 lines)
Lines 1423-1428 dev/fdt/fdt_pinctrl_if.m optional fdt fdt_pinctrl Link Here
1423
dev/fdt/fdt_regulator.c		optional fdt fdt_regulator
1423
dev/fdt/fdt_regulator.c		optional fdt fdt_regulator
1424
dev/fdt/fdt_regulator_if.m	optional fdt fdt_regulator
1424
dev/fdt/fdt_regulator_if.m	optional fdt fdt_regulator
1425
dev/fdt/fdt_regulator_fixed.c	optional fdt fdt_regulator_fixed
1425
dev/fdt/fdt_regulator_fixed.c	optional fdt fdt_regulator_fixed
1426
dev/fdt/fdt_reset.c		optional fdt fdt_reset
1427
dev/fdt/fdt_reset_if.m		optional fdt fdt_reset
1426
dev/fdt/fdt_slicer.c		optional fdt cfi | fdt nand
1428
dev/fdt/fdt_slicer.c		optional fdt cfi | fdt nand
1427
dev/fdt/fdt_static_dtb.S	optional fdt fdt_dtb_static \
1429
dev/fdt/fdt_static_dtb.S	optional fdt fdt_dtb_static \
1428
	dependency	"$S/boot/fdt/dts/${MACHINE}/${FDT_DTS_FILE}"
1430
	dependency	"$S/boot/fdt/dts/${MACHINE}/${FDT_DTS_FILE}"
(-)b/sys/dev/fdt/fdt_reset.c (+125 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2016 Stanislav Galabov
3
 * Copyright (c) 2014 Ian Lepore <ian@freebsd.org>
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
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.
14
 *
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
25
 * SUCH DAMAGE.
26
 *
27
 * $FreeBSD$
28
 */
29
30
#include <sys/cdefs.h>
31
#include <sys/param.h>
32
#include <sys/kernel.h>
33
#include <sys/lock.h>
34
#include <sys/mutex.h>
35
#include <sys/queue.h>
36
#include <sys/systm.h>
37
38
#include <dev/ofw/ofw_bus.h>
39
#include <dev/ofw/ofw_bus_subr.h>
40
41
#include "fdt_reset_if.h"
42
#include <dev/fdt/fdt_reset.h>
43
44
/*
45
 * Loop through all the tuples in the resets= property for a device, asserting
46
 * or deasserting each reset.
47
 *
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.
51
 */
52
static int
53
assert_deassert_all(device_t consumer, boolean_t assert)
54
{
55
	phandle_t rnode;
56
	device_t resetdev;
57
	int resetnum, err, i, ncells;
58
	uint32_t *resets;
59
	boolean_t anyerrors;
60
61
	rnode = ofw_bus_get_node(consumer);
62
	ncells = OF_getencprop_alloc(rnode, "resets", sizeof(*resets),
63
	    (void **)&resets);
64
	if (!assert && ncells < 2) {
65
		device_printf(consumer, "Warning: No resets specified in fdt "
66
		    "data; device may not function.");
67
		return (ENXIO);
68
	}
69
	anyerrors = false;
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) {
74
			if (!assert)
75
				device_printf(consumer, "Warning: can not find "
76
				    "driver for reset number %u; device may "
77
				    "not function\n", resetnum);
78
			anyerrors = true;
79
			continue;
80
		}
81
		if (assert)
82
			err = FDT_RESET_ASSERT(resetdev, resetnum);
83
		else
84
			err = FDT_RESET_DEASSERT(resetdev, resetnum);
85
		if (err != 0) {
86
			if (!assert)
87
				device_printf(consumer, "Warning: failed to "
88
				    "deassert reset number %u; device may not "
89
				    "function\n", resetnum);
90
			anyerrors = true;
91
		}
92
	}
93
	free(resets, M_OFWPROP);
94
	return (anyerrors ? ENXIO : 0);
95
}
96
97
int
98
fdt_reset_assert_all(device_t consumer)
99
{
100
101
	return (assert_deassert_all(consumer, true));
102
}
103
104
int
105
fdt_reset_deassert_all(device_t consumer)
106
{
107
108
	return (assert_deassert_all(consumer, false));
109
}
110
111
void
112
fdt_reset_register_provider(device_t provider)
113
{
114
115
	OF_device_register_xref(
116
	    OF_xref_from_node(ofw_bus_get_node(provider)), provider);
117
}
118
119
void
120
fdt_reset_unregister_provider(device_t provider)
121
{
122
123
	OF_device_register_xref(OF_xref_from_device(provider), NULL);
124
}
125
(-)b/sys/dev/fdt/fdt_reset.h (+49 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2016 Stanislav Galabov
3
 * Copyright (c) 2014 Ian Lepore <ian@freebsd.org>
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
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.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 *
26
 * $FreeBSD$
27
 */
28
29
#ifndef DEV_FDT_RESET_H
30
#define DEV_FDT_RESET_H
31
32
#include "fdt_reset_if.h"
33
34
/*
35
 * Look up "resets" property in consumer's fdt data and assert or deassert all
36
 * configured resets.
37
 */
38
int fdt_reset_assert_all(device_t consumer);
39
int fdt_reset_deassert_all(device_t consumer);
40
41
/*
42
 * [Un]register the given device instance as a driver that implements the
43
 * fdt_clock interface.
44
 */
45
void fdt_reset_register_provider(device_t provider);
46
void fdt_reset_unregister_provider(device_t provider);
47
48
#endif /* DEV_FDT_RESET_H */
49
(-)b/sys/dev/fdt/fdt_reset_if.m (+58 lines)
Added Link Here
1
#-
2
# Copyright (c) 2016 Stanislav Galabov
3
# Copyright (c) 2014 Ian Lepore
4
# All rights reserved.
5
#
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions
8
# are met:
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.
14
#
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
25
# SUCH DAMAGE.
26
#
27
# $FreeBSD$
28
#
29
30
#include <sys/types.h>
31
32
#
33
# This is the interface that fdt_reset drivers provide to other drivers.
34
# In this context, reset refers to a reset signal provided to some other
35
# hardware component within the system.  They are most often found within
36
# embedded processors that have on-chip IO controllers.
37
#
38
39
INTERFACE fdt_reset;
40
41
#
42
# Enable/assert/apply the specified reset.
43
# Returns 0 on success or a standard errno value.
44
#
45
METHOD int assert {
46
	device_t	provider;
47
	int		index;
48
};
49
50
#
51
# Disable/de-assert/remove the specified reset.
52
# Returns 0 on success or a standard errno value.
53
#
54
METHOD int deassert {
55
	device_t	provider;
56
	int		index;
57
};
58

Return to bug 206228