Path: blob/main/sys/arm/freescale/imx/imx6_machdep.c
39537 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2013 Ian Lepore <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include "opt_platform.h"2930#include <sys/param.h>31#include <sys/systm.h>32#include <sys/bus.h>33#include <sys/reboot.h>34#include <sys/devmap.h>3536#include <vm/vm.h>37#include <vm/pmap.h>3839#include <machine/bus.h>40#include <machine/intr.h>41#include <machine/machdep.h>42#include <machine/platformvar.h>4344#include <arm/arm/mpcore_timervar.h>45#include <arm/freescale/imx/imx6_anatopreg.h>46#include <arm/freescale/imx/imx6_anatopvar.h>47#include <arm/freescale/imx/imx_machdep.h>4849#include <dev/fdt/fdt_common.h>50#include <dev/ofw/openfirm.h>5152#include <arm/freescale/imx/imx6_machdep.h>5354#include "platform_if.h"55#include "platform_pl310_if.h"5657static platform_attach_t imx6_attach;58static platform_devmap_init_t imx6_devmap_init;59static platform_late_init_t imx6_late_init;60static platform_cpu_reset_t imx6_cpu_reset;6162/*63* Fix FDT data related to interrupts.64*65* Driven by the needs of linux and its drivers (as always), the published FDT66* data for imx6 now sets the interrupt parent for most devices to the GPC67* interrupt controller, which is for use when the chip is in deep-sleep mode.68* We don't support deep sleep or have a GPC-PIC driver; we need all interrupts69* to be handled by the GIC.70*71* Luckily, the change to the FDT data was to assign the GPC as the interrupt72* parent for the soc node and letting that get inherited by all other devices73* (except a few that directly name GIC as their interrupt parent). So we can74* set the world right by just changing the interrupt-parent property of the soc75* node to refer to GIC instead of GPC. This will get us by until we write our76* own GPC driver (or until linux changes its mind and the FDT data again).77*78* 2020/11/25: The tempmon and pmu nodes are siblings (not children) of the soc79* node, so for them to use interrupts we need to apply the same fix as we do80* for the soc node.81*82* We validate that we have data that looks like we expect before changing it:83* - SOC node exists and has GPC as its interrupt parent.84* - GPC node exists and has GIC as its interrupt parent.85* - GIC node exists and is its own interrupt parent or has no parent.86*87* This applies to all models of imx6. Luckily all of them have the devices88* involved at the same addresses on the same buses, so we don't need any89* per-soc logic. We handle this at platform attach time rather than via the90* fdt_fixup_table, because the latter requires matching on the FDT "model"91* property, and this applies to all boards including those not yet invented.92*93* This just in: as of the import of dts files from linux 4.15 on 2018-02-10,94* they appear to have applied a new style rule to the dts which forbids leading95* zeroes in the @address qualifiers on node names. Since we have to find those96* nodes by string matching we now have to search for both flavors of each node97* name involved.98*/99100static void101fix_node_iparent(const char* nodepath, phandle_t gpcxref, phandle_t gicxref)102{103static const char *propname = "interrupt-parent";104phandle_t node, iparent;105106if ((node = OF_finddevice(nodepath)) == -1)107return;108if (OF_getencprop(node, propname, &iparent, sizeof(iparent)) <= 0)109return;110if (iparent != gpcxref)111return;112113OF_setprop(node, propname, &gicxref, sizeof(gicxref));114}115116static void117fix_fdt_interrupt_data(void)118{119phandle_t gicipar, gicnode, gicxref;120phandle_t gpcipar, gpcnode, gpcxref;121int result;122123/* GIC node may be child of soc node, or appear directly at root. */124gicnode = OF_finddevice("/soc/interrupt-controller@00a01000");125if (gicnode == -1)126gicnode = OF_finddevice("/soc/interrupt-controller@a01000");127if (gicnode == -1) {128gicnode = OF_finddevice("/interrupt-controller@00a01000");129if (gicnode == -1)130gicnode = OF_finddevice("/interrupt-controller@a01000");131if (gicnode == -1)132return;133}134gicxref = OF_xref_from_node(gicnode);135136/* If gic node has no parent, pretend it is its own parent. */137result = OF_getencprop(gicnode, "interrupt-parent", &gicipar,138sizeof(gicipar));139if (result <= 0)140gicipar = gicxref;141142gpcnode = OF_finddevice("/soc/aips-bus@02000000/gpc@020dc000");143if (gpcnode == -1)144gpcnode = OF_finddevice("/soc/aips-bus@2000000/gpc@20dc000");145if (gpcnode == -1)146gpcnode = OF_finddevice("/soc/bus@2000000/gpc@20dc000");147if (gpcnode == -1)148return;149result = OF_getencprop(gpcnode, "interrupt-parent", &gpcipar,150sizeof(gpcipar));151if (result <= 0)152return;153gpcxref = OF_xref_from_node(gpcnode);154155if (gpcipar != gicxref || gicipar != gicxref)156return;157158gicxref = cpu_to_fdt32(gicxref);159fix_node_iparent("/soc", gpcxref, gicxref);160fix_node_iparent("/pmu", gpcxref, gicxref);161fix_node_iparent("/tempmon", gpcxref, gicxref);162}163164static void165fix_fdt_iomuxc_data(void)166{167phandle_t node;168169/*170* The linux dts defines two nodes with the same mmio address range,171* iomuxc-gpr and the regular iomuxc. The -grp node is a simple_mfd and172* a syscon, but it only has access to a small subset of the iomuxc173* registers, so it can't serve as the accessor for the iomuxc driver's174* register IO. But right now, the simple_mfd driver attaches first,175* preventing the real iomuxc driver from allocating its mmio register176* range because it partially overlaps with the -gpr range.177*178* For now, by far the easiest thing to do to keep imx6 working is to179* just disable the iomuxc-gpr node because we don't have a driver for180* it anyway, we just need to prevent attachment of simple_mfd.181*182* If we ever write a -gpr driver, this code should probably switch to183* modifying the reg property so that the range covers all the iomuxc184* regs, then the -gpr driver can be a regular syscon driver that iomuxc185* uses for register access.186*/187node = OF_finddevice("/soc/aips-bus@2000000/iomuxc-gpr@20e0000");188if (node == -1)189node = OF_finddevice("/soc/bus@2000000/iomuxc-gpr@20e0000");190if (node != -1)191OF_setprop(node, "status", "disabled", sizeof("disabled"));192}193194static int195imx6_attach(platform_t plat)196{197198/* Fix soc interrupt-parent property. */199fix_fdt_interrupt_data();200201/* Fix iomuxc-gpr and iomuxc nodes both using the same mmio range. */202fix_fdt_iomuxc_data();203204/* Inform the MPCore timer driver that its clock is variable. */205arm_tmr_change_frequency(ARM_TMR_FREQUENCY_VARIES);206207return (0);208}209210static void211imx6_late_init(platform_t plat)212{213const uint32_t IMX6_WDOG_SR_PHYS = 0x020bc004;214215imx_wdog_init_last_reset(IMX6_WDOG_SR_PHYS);216}217218/*219* Set up static device mappings.220*221* This attempts to cover the most-used devices with 1MB section mappings, which222* is good for performance (uses fewer TLB entries for device access).223*224* ARMMP covers the interrupt controller, MPCore timers, global timer, and the225* L2 cache controller. Most of the 1MB range is unused reserved space.226*227* AIPS1/AIPS2 cover most of the on-chip devices such as uart, spi, i2c, etc.228*229* Notably not mapped right now are HDMI, GPU, and other devices below ARMMP in230* the memory map. When we get support for graphics it might make sense to231* static map some of that area. Be careful with other things in that area such232* as OCRAM that probably shouldn't be mapped as VM_MEMATTR_DEVICE memory.233*/234static int235imx6_devmap_init(platform_t plat)236{237const uint32_t IMX6_ARMMP_PHYS = 0x00a00000;238const uint32_t IMX6_ARMMP_SIZE = 0x00100000;239const uint32_t IMX6_AIPS1_PHYS = 0x02000000;240const uint32_t IMX6_AIPS1_SIZE = 0x00100000;241const uint32_t IMX6_AIPS2_PHYS = 0x02100000;242const uint32_t IMX6_AIPS2_SIZE = 0x00100000;243244devmap_add_entry(IMX6_ARMMP_PHYS, IMX6_ARMMP_SIZE);245devmap_add_entry(IMX6_AIPS1_PHYS, IMX6_AIPS1_SIZE);246devmap_add_entry(IMX6_AIPS2_PHYS, IMX6_AIPS2_SIZE);247248return (0);249}250251static void252imx6_cpu_reset(platform_t plat)253{254const uint32_t IMX6_WDOG_CR_PHYS = 0x020bc000;255256imx_wdog_cpu_reset(IMX6_WDOG_CR_PHYS);257}258259/*260* Determine what flavor of imx6 we're running on.261*262* This code is based on the way u-boot does it. Information found on the web263* indicates that Freescale themselves were the original source of this logic,264* including the strange check for number of CPUs in the SCU configuration265* register, which is apparently needed on some revisions of the SOLO.266*267* According to the documentation, there is such a thing as an i.MX6 Dual268* (non-lite flavor). However, Freescale doesn't seem to have assigned it a269* number or provided any logic to handle it in their detection code.270*271* Note that the ANALOG_DIGPROG and SCU configuration registers are not272* documented in the chip reference manual. (SCU configuration is mentioned,273* but not mapped out in detail.) I think the bottom two bits of the scu config274* register may be ncpu-1.275*276* This hasn't been tested yet on a dual[-lite].277*278* On a solo:279* digprog = 0x00610001280* hwsoc = 0x00000062281* scu config = 0x00000500282* On a quad:283* digprog = 0x00630002284* hwsoc = 0x00000063285* scu config = 0x00005503286*/287u_int288imx_soc_type(void)289{290uint32_t digprog, hwsoc;291uint32_t *pcr;292static u_int soctype;293const vm_offset_t SCU_CONFIG_PHYSADDR = 0x00a00004;294#define HWSOC_MX6SL 0x60295#define HWSOC_MX6DL 0x61296#define HWSOC_MX6SOLO 0x62297#define HWSOC_MX6Q 0x63298#define HWSOC_MX6UL 0x64299300if (soctype != 0)301return (soctype);302303digprog = imx6_anatop_read_4(IMX6_ANALOG_DIGPROG_SL);304hwsoc = (digprog >> IMX6_ANALOG_DIGPROG_SOCTYPE_SHIFT) &305IMX6_ANALOG_DIGPROG_SOCTYPE_MASK;306307if (hwsoc != HWSOC_MX6SL) {308digprog = imx6_anatop_read_4(IMX6_ANALOG_DIGPROG);309hwsoc = (digprog & IMX6_ANALOG_DIGPROG_SOCTYPE_MASK) >>310IMX6_ANALOG_DIGPROG_SOCTYPE_SHIFT;311/*printf("digprog = 0x%08x\n", digprog);*/312if (hwsoc == HWSOC_MX6DL) {313pcr = pmap_mapdev(SCU_CONFIG_PHYSADDR, 4);314if (pcr != NULL) {315/*printf("scu config = 0x%08x\n", *pcr);*/316if ((*pcr & 0x03) == 0) {317hwsoc = HWSOC_MX6SOLO;318}319pmap_unmapdev(pcr, 4);320}321}322}323/* printf("hwsoc 0x%08x\n", hwsoc); */324325switch (hwsoc) {326case HWSOC_MX6SL:327soctype = IMXSOC_6SL;328break;329case HWSOC_MX6SOLO:330soctype = IMXSOC_6S;331break;332case HWSOC_MX6DL:333soctype = IMXSOC_6DL;334break;335case HWSOC_MX6Q :336soctype = IMXSOC_6Q;337break;338case HWSOC_MX6UL:339soctype = IMXSOC_6UL;340break;341default:342printf("imx_soc_type: Don't understand hwsoc 0x%02x, "343"digprog 0x%08x; assuming IMXSOC_6Q\n", hwsoc, digprog);344soctype = IMXSOC_6Q;345break;346}347348return (soctype);349}350351/*352* Early putc routine for EARLY_PRINTF support. To use, add to kernel config:353* option SOCDEV_PA=0x02000000354* option SOCDEV_VA=0x02000000355* option EARLY_PRINTF356* Resist the temptation to change the #if 0 to #ifdef EARLY_PRINTF here. It357* makes sense now, but if multiple SOCs do that it will make early_putc another358* duplicate symbol to be eliminated on the path to a generic kernel.359*/360#if 0361static void362imx6_early_putc(int c)363{364volatile uint32_t * UART_STAT_REG = (uint32_t *)0x02020098;365volatile uint32_t * UART_TX_REG = (uint32_t *)0x02020040;366const uint32_t UART_TXRDY = (1 << 3);367368while ((*UART_STAT_REG & UART_TXRDY) == 0)369continue;370*UART_TX_REG = c;371}372early_putc_t *early_putc = imx6_early_putc;373#endif374375static platform_method_t imx6_methods[] = {376PLATFORMMETHOD(platform_attach, imx6_attach),377PLATFORMMETHOD(platform_devmap_init, imx6_devmap_init),378PLATFORMMETHOD(platform_late_init, imx6_late_init),379PLATFORMMETHOD(platform_cpu_reset, imx6_cpu_reset),380381#ifdef SMP382PLATFORMMETHOD(platform_mp_start_ap, imx6_mp_start_ap),383PLATFORMMETHOD(platform_mp_setmaxid, imx6_mp_setmaxid),384#endif385386PLATFORMMETHOD(platform_pl310_init, imx6_pl310_init),387388PLATFORMMETHOD_END,389};390391FDT_PLATFORM_DEF2(imx6, imx6s, "i.MX6 Solo", 0, "fsl,imx6s", 80);392FDT_PLATFORM_DEF2(imx6, imx6d, "i.MX6 Dual", 0, "fsl,imx6dl", 80);393FDT_PLATFORM_DEF2(imx6, imx6q, "i.MX6 Quad", 0, "fsl,imx6q", 80);394FDT_PLATFORM_DEF2(imx6, imx6ul, "i.MX6 UltraLite", 0, "fsl,imx6ul", 67);395396397