aml8726_machdep.c revision 314506
1/*-
2 * Copyright 2013-2015 John Wehle <john@feith.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include "opt_global.h"
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: stable/11/sys/arm/amlogic/aml8726/aml8726_machdep.c 314506 2017-03-01 19:55:04Z ian $");
31
32#include "opt_platform.h"
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/bus.h>
37#include <sys/devmap.h>
38
39#include <vm/vm.h>
40#include <vm/pmap.h>
41
42#include <machine/bus.h>
43#include <machine/intr.h>
44#include <machine/machdep.h>
45#include <machine/platform.h>
46
47#include <dev/fdt/fdt_common.h>
48
49#include <arm/amlogic/aml8726/aml8726_soc.h>
50#include <arm/amlogic/aml8726/aml8726_clkmsr.h>
51
52#if defined(SOCDEV_PA) && defined(SOCDEV_VA)
53vm_offset_t aml8726_aobus_kva_base = SOCDEV_VA;
54#else
55vm_offset_t aml8726_aobus_kva_base;
56#endif
57
58static void
59aml8726_fixup_busfreq(void)
60{
61	phandle_t node;
62	pcell_t freq, prop;
63	ssize_t len;
64
65	/*
66	 * Set the bus-frequency for the SoC simple-bus if it
67	 * needs updating (meaning the current frequency is zero).
68	 */
69
70	if ((freq = aml8726_clkmsr_bus_frequency()) == 0 ||
71	    (node = OF_finddevice("/soc")) == 0 ||
72	    fdt_is_compatible_strict(node, "simple-bus") == 0)
73		while (1);
74
75	freq = cpu_to_fdt32(freq);
76
77	len = OF_getencprop(node, "bus-frequency", &prop, sizeof(prop));
78	if ((len / sizeof(prop)) == 1 && prop == 0)
79		OF_setprop(node, "bus-frequency", (void *)&freq, sizeof(freq));
80}
81
82vm_offset_t
83platform_lastaddr(void)
84{
85
86	return (devmap_lastaddr());
87}
88
89void
90platform_probe_and_attach(void)
91{
92}
93
94void
95platform_gpio_init(void)
96{
97
98	/*
99	 * The UART console driver used for debugging early boot code
100	 * needs to know the virtual base address of the aobus.  It's
101	 * expected to equal SOCDEV_VA prior to initarm calling setttb
102	 * ... afterwards it needs to be updated due to the new page
103	 * tables.
104	 *
105	 * This means there's a deadzone in initarm between setttb
106	 * and platform_gpio_init during which printf can't be used.
107	 */
108	aml8726_aobus_kva_base =
109	    (vm_offset_t)devmap_ptov(0xc8100000, 0x100000);
110
111	/*
112	 * The hardware mux used by clkmsr is unique to the SoC (though
113	 * currently clk81 is at a fixed location, however that might
114	 * change in the future).
115	 */
116	aml8726_identify_soc();
117
118	/*
119	 * My aml8726-m3 development box which identifies the CPU as
120	 * a Cortex A9-r2 rev 4 randomly locks up during boot when WFI
121	 * is used.
122	 */
123	switch (aml8726_soc_hw_rev) {
124	case AML_SOC_HW_REV_M3:
125		cpufuncs.cf_sleep = (void *)cpufunc_nullop;
126		break;
127	default:
128		break;
129	}
130
131	/*
132	 * This FDT fixup should arguably be called through fdt_fixup_table,
133	 * however currently there's no mechanism to specify a fixup which
134	 * should always be invoked.
135	 *
136	 * It needs to be called prior to the console being initialized which
137	 * is why it's called here, rather than from platform_late_init.
138	 */
139	aml8726_fixup_busfreq();
140}
141
142void
143platform_late_init(void)
144{
145}
146
147/*
148 * Construct static devmap entries to map out the core
149 * peripherals using 1mb section mappings.
150 */
151int
152platform_devmap_init(void)
153{
154
155	devmap_add_entry(0xc1100000, 0x200000); /* cbus */
156	devmap_add_entry(0xc4200000, 0x100000); /* pl310 */
157	devmap_add_entry(0xc4300000, 0x100000); /* periph */
158	devmap_add_entry(0xc8000000, 0x100000); /* apbbus */
159	devmap_add_entry(0xc8100000, 0x100000); /* aobus */
160	devmap_add_entry(0xc9000000, 0x800000); /* ahbbus */
161	devmap_add_entry(0xd9000000, 0x100000); /* ahb */
162	devmap_add_entry(0xda000000, 0x100000); /* secbus */
163
164	return (0);
165}
166
167#ifndef INTRNG
168#ifndef DEV_GIC
169static int
170fdt_pic_decode_ic(phandle_t node, pcell_t *intr, int *interrupt, int *trig,
171    int *pol)
172{
173
174	/*
175	 * The single core chips have just an Amlogic PIC.
176	 */
177	if (!fdt_is_compatible_strict(node, "amlogic,aml8726-pic"))
178		return (ENXIO);
179
180	*interrupt = fdt32_to_cpu(intr[1]);
181	*trig = INTR_TRIGGER_EDGE;
182	*pol = INTR_POLARITY_HIGH;
183
184	return (0);
185}
186#endif
187
188fdt_pic_decode_t fdt_pic_table[] = {
189#ifdef DEV_GIC
190	&gic_decode_fdt,
191#else
192	&fdt_pic_decode_ic,
193#endif
194	NULL
195};
196#endif /* INTRNG */
197