2 * Copyright 2013-2015 John Wehle <john@feith.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include "opt_global.h"
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include "opt_platform.h"
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <sys/devmap.h>
42 #include <machine/bus.h>
43 #include <machine/intr.h>
44 #include <machine/machdep.h>
45 #include <machine/platform.h>
47 #include <dev/fdt/fdt_common.h>
49 #include <arm/amlogic/aml8726/aml8726_soc.h>
50 #include <arm/amlogic/aml8726/aml8726_clkmsr.h>
52 #if defined(SOCDEV_PA) && defined(SOCDEV_VA)
53 vm_offset_t aml8726_aobus_kva_base = SOCDEV_VA;
55 vm_offset_t aml8726_aobus_kva_base;
59 aml8726_fixup_busfreq(void)
66 * Set the bus-frequency for the SoC simple-bus if it
67 * needs updating (meaning the current frequency is zero).
70 if ((freq = aml8726_clkmsr_bus_frequency()) == 0 ||
71 (node = OF_finddevice("/soc")) == 0 ||
72 fdt_is_compatible_strict(node, "simple-bus") == 0)
75 freq = cpu_to_fdt32(freq);
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));
83 platform_lastaddr(void)
86 return (devmap_lastaddr());
90 platform_probe_and_attach(void)
95 platform_gpio_init(void)
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
105 * This means there's a deadzone in initarm between setttb
106 * and platform_gpio_init during which printf can't be used.
108 aml8726_aobus_kva_base =
109 (vm_offset_t)devmap_ptov(0xc8100000, 0x100000);
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).
116 aml8726_identify_soc();
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
123 switch (aml8726_soc_hw_rev) {
124 case AML_SOC_HW_REV_M3:
125 cpufuncs.cf_sleep = (void *)cpufunc_nullop;
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.
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.
139 aml8726_fixup_busfreq();
143 platform_late_init(void)
148 * Construct static devmap entries to map out the core
149 * peripherals using 1mb section mappings.
152 platform_devmap_init(void)
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 */
170 fdt_pic_decode_ic(phandle_t node, pcell_t *intr, int *interrupt, int *trig,
175 * The single core chips have just an Amlogic PIC.
177 if (!fdt_is_compatible_strict(node, "amlogic,aml8726-pic"))
180 *interrupt = fdt32_to_cpu(intr[1]);
181 *trig = INTR_TRIGGER_EDGE;
182 *pol = INTR_POLARITY_HIGH;
188 fdt_pic_decode_t fdt_pic_table[] = {