fdt_powerpc.c revision 330897
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2009-2010 The FreeBSD Foundation
5 * All rights reserved.
6 *
7 * This software was developed by Semihalf under sponsorship from
8 * the FreeBSD Foundation.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: stable/11/sys/dev/fdt/fdt_powerpc.c 330897 2018-03-14 03:19:51Z eadler $");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/module.h>
39#include <sys/bus.h>
40
41#include <machine/intr_machdep.h>
42
43#include <dev/ofw/ofw_bus.h>
44#include <dev/ofw/ofw_bus_subr.h>
45#include <dev/ofw/openfirm.h>
46
47#include "ofw_bus_if.h"
48#include "fdt_common.h"
49
50static void
51fdt_fixup_busfreq(phandle_t root, uint32_t div)
52{
53	phandle_t sb, cpus, child;
54	pcell_t freq;
55
56	/*
57	 * Do a strict check so as to skip non-SOC nodes, which also claim
58	 * simple-bus compatibility such as eLBC etc.
59	 */
60	if ((sb = fdt_find_compatible(root, "simple-bus", 1)) == 0)
61		return;
62
63	/*
64	 * This fixup uses /cpus/ bus-frequency prop value to set simple-bus
65	 * bus-frequency property.
66	 */
67	if ((cpus = OF_finddevice("/cpus")) == -1)
68		return;
69
70	if ((child = OF_child(cpus)) == 0)
71		return;
72
73	if (OF_getprop(child, "bus-frequency", (void *)&freq,
74	    sizeof(freq)) <= 0)
75		return;
76
77	if (div == 0)
78		return;
79
80	freq /= div;
81
82	OF_setprop(sb, "bus-frequency", (void *)&freq, sizeof(freq));
83}
84
85static void
86fdt_fixup_busfreq_mpc85xx(phandle_t root)
87{
88
89	fdt_fixup_busfreq(root, 1);
90}
91
92static void
93fdt_fixup_busfreq_dpaa(phandle_t root)
94{
95
96	fdt_fixup_busfreq(root, 2);
97}
98
99static void
100fdt_fixup_fman(phandle_t root)
101{
102	phandle_t node;
103	pcell_t freq;
104
105	if ((node = fdt_find_compatible(root, "simple-bus", 1)) == 0)
106		return;
107
108	if (OF_getprop(node, "bus-frequency", (void *)&freq,
109	    sizeof(freq)) <= 0)
110		return;
111
112	/*
113	 * Set clock-frequency for FMan nodes (only on QorIQ DPAA targets).
114	 * That frequency is equal to /soc node bus-frequency.
115	 */
116	for (node = OF_child(node); node != 0; node = OF_peer(node)) {
117		if (fdt_is_compatible(node, "fsl,fman") == 0)
118			continue;
119
120		if (OF_setprop(node, "clock-frequency", (void *)&freq,
121		    sizeof(freq)) == -1) {
122			/*
123			 * XXX Shall we take some actions if no clock-frequency
124			 * property was found?
125			 */
126		}
127	}
128}
129
130struct fdt_fixup_entry fdt_fixup_table[] = {
131	{ "fsl,MPC8572DS", &fdt_fixup_busfreq_mpc85xx },
132	{ "MPC8555CDS", &fdt_fixup_busfreq_mpc85xx },
133	{ "fsl,P2020", &fdt_fixup_busfreq_mpc85xx },
134	{ "fsl,P2041RDB", &fdt_fixup_busfreq_dpaa },
135	{ "fsl,P2041RDB", &fdt_fixup_fman },
136	{ "fsl,P3041DS", &fdt_fixup_busfreq_dpaa },
137	{ "fsl,P3041DS", &fdt_fixup_fman },
138	{ "fsl,P5020DS", &fdt_fixup_busfreq_dpaa },
139	{ "fsl,P5020DS", &fdt_fixup_fman },
140	{ "varisys,CYRUS", &fdt_fixup_busfreq_dpaa },
141	{ "varisys,CYRUS", &fdt_fixup_fman },
142	{ NULL, NULL }
143};
144
145