1034e9ed6SIan Lepore /*- 2034e9ed6SIan Lepore * Copyright (c) 2013 Ian Lepore <ian@freebsd.org> 3034e9ed6SIan Lepore * All rights reserved. 4034e9ed6SIan Lepore * 5034e9ed6SIan Lepore * Redistribution and use in source and binary forms, with or without 6034e9ed6SIan Lepore * modification, are permitted provided that the following conditions 7034e9ed6SIan Lepore * are met: 8034e9ed6SIan Lepore * 1. Redistributions of source code must retain the above copyright 9034e9ed6SIan Lepore * notice, this list of conditions and the following disclaimer. 10034e9ed6SIan Lepore * 2. Redistributions in binary form must reproduce the above copyright 11034e9ed6SIan Lepore * notice, this list of conditions and the following disclaimer in the 12034e9ed6SIan Lepore * documentation and/or other materials provided with the distribution. 13034e9ed6SIan Lepore * 14034e9ed6SIan Lepore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15034e9ed6SIan Lepore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16034e9ed6SIan Lepore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17034e9ed6SIan Lepore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18034e9ed6SIan Lepore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19034e9ed6SIan Lepore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20034e9ed6SIan Lepore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21034e9ed6SIan Lepore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22034e9ed6SIan Lepore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23034e9ed6SIan Lepore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24034e9ed6SIan Lepore * SUCH DAMAGE. 25034e9ed6SIan Lepore */ 26034e9ed6SIan Lepore 27034e9ed6SIan Lepore #include "opt_platform.h" 28034e9ed6SIan Lepore 29034e9ed6SIan Lepore #include <sys/cdefs.h> 30034e9ed6SIan Lepore __FBSDID("$FreeBSD$"); 31034e9ed6SIan Lepore 32034e9ed6SIan Lepore #include <sys/param.h> 33034e9ed6SIan Lepore #include <sys/systm.h> 34034e9ed6SIan Lepore #include <sys/bus.h> 35034e9ed6SIan Lepore #include <sys/reboot.h> 36034e9ed6SIan Lepore 37034e9ed6SIan Lepore #include <vm/vm.h> 3813a98c85SIan Lepore 3913a98c85SIan Lepore #include <machine/bus.h> 4013a98c85SIan Lepore #include <machine/devmap.h> 41952ded80SIan Lepore #include <machine/intr.h> 4281acdf3fSIan Lepore #include <machine/machdep.h> 43*ef7eac43SAndrew Turner #include <machine/platformvar.h> 4413a98c85SIan Lepore 45a3ff7ef6SIan Lepore #include <arm/arm/mpcore_timervar.h> 46034e9ed6SIan Lepore #include <arm/freescale/imx/imx6_anatopreg.h> 47034e9ed6SIan Lepore #include <arm/freescale/imx/imx6_anatopvar.h> 48034e9ed6SIan Lepore #include <arm/freescale/imx/imx_machdep.h> 49034e9ed6SIan Lepore 50952ded80SIan Lepore #include <dev/fdt/fdt_common.h> 51952ded80SIan Lepore #include <dev/ofw/openfirm.h> 52952ded80SIan Lepore 53*ef7eac43SAndrew Turner #include "platform_if.h" 54*ef7eac43SAndrew Turner 55952ded80SIan Lepore struct fdt_fixup_entry fdt_fixup_table[] = { 56952ded80SIan Lepore { NULL, NULL } 57952ded80SIan Lepore }; 58952ded80SIan Lepore 592c746c6aSIan Lepore static uint32_t gpio1_node; 602c746c6aSIan Lepore 612c746c6aSIan Lepore /* 622c746c6aSIan Lepore * Work around the linux workaround for imx6 erratum 006687, in which some 632c746c6aSIan Lepore * ethernet interrupts don't go to the GPC and thus won't wake the system from 642c746c6aSIan Lepore * Wait mode. We don't use Wait mode (which halts the GIC, leaving only GPC 652c746c6aSIan Lepore * interrupts able to wake the system), so we don't experience the bug at all. 662c746c6aSIan Lepore * The linux workaround is to reconfigure GPIO1_6 as the ENET interrupt by 672c746c6aSIan Lepore * writing magic values to an undocumented IOMUX register, then letting the gpio 682c746c6aSIan Lepore * interrupt driver notify the ethernet driver. We'll be able to do all that 692c746c6aSIan Lepore * (even though we don't need to) once the INTRNG project is committed and the 702c746c6aSIan Lepore * imx_gpio driver becomes an interrupt driver. Until then, this crazy little 712c746c6aSIan Lepore * workaround watches for requests to map an interrupt 6 with the interrupt 722c746c6aSIan Lepore * controller node referring to gpio1, and it substitutes the proper ffec 732c746c6aSIan Lepore * interrupt number. 742c746c6aSIan Lepore */ 752c746c6aSIan Lepore static int 762c746c6aSIan Lepore imx6_decode_fdt(uint32_t iparent, uint32_t *intr, int *interrupt, 772c746c6aSIan Lepore int *trig, int *pol) 782c746c6aSIan Lepore { 792c746c6aSIan Lepore 802c746c6aSIan Lepore if (fdt32_to_cpu(intr[0]) == 6 && 812c746c6aSIan Lepore OF_node_from_xref(iparent) == gpio1_node) { 822c746c6aSIan Lepore *interrupt = 150; 832c746c6aSIan Lepore *trig = INTR_TRIGGER_CONFORM; 842c746c6aSIan Lepore *pol = INTR_POLARITY_CONFORM; 852c746c6aSIan Lepore return (0); 862c746c6aSIan Lepore } 872c746c6aSIan Lepore return (gic_decode_fdt(iparent, intr, interrupt, trig, pol)); 882c746c6aSIan Lepore } 892c746c6aSIan Lepore 90952ded80SIan Lepore fdt_pic_decode_t fdt_pic_table[] = { 912c746c6aSIan Lepore &imx6_decode_fdt, 92952ded80SIan Lepore NULL 93952ded80SIan Lepore }; 94952ded80SIan Lepore 95*ef7eac43SAndrew Turner static vm_offset_t 96*ef7eac43SAndrew Turner imx6_lastaddr(platform_t plat) 9781acdf3fSIan Lepore { 9881acdf3fSIan Lepore 9981acdf3fSIan Lepore return (arm_devmap_lastaddr()); 10081acdf3fSIan Lepore } 10181acdf3fSIan Lepore 102*ef7eac43SAndrew Turner static int 103*ef7eac43SAndrew Turner imx6_attach(platform_t plat) 10481acdf3fSIan Lepore { 10581acdf3fSIan Lepore 106a3ff7ef6SIan Lepore /* Inform the MPCore timer driver that its clock is variable. */ 107a3ff7ef6SIan Lepore arm_tmr_change_frequency(ARM_TMR_FREQUENCY_VARIES); 108*ef7eac43SAndrew Turner 109*ef7eac43SAndrew Turner return (0); 11081acdf3fSIan Lepore } 11181acdf3fSIan Lepore 112*ef7eac43SAndrew Turner static void 113*ef7eac43SAndrew Turner imx6_late_init(platform_t plat) 11481acdf3fSIan Lepore { 11581acdf3fSIan Lepore 1162c746c6aSIan Lepore /* Cache the gpio1 node handle for imx6_decode_fdt() workaround code. */ 1172c746c6aSIan Lepore gpio1_node = OF_node_from_xref( 1182c746c6aSIan Lepore OF_finddevice("/soc/aips-bus@02000000/gpio@0209c000")); 11981acdf3fSIan Lepore } 12081acdf3fSIan Lepore 121034e9ed6SIan Lepore /* 12281acdf3fSIan Lepore * Set up static device mappings. 123034e9ed6SIan Lepore * 124034e9ed6SIan Lepore * This attempts to cover the most-used devices with 1MB section mappings, which 125034e9ed6SIan Lepore * is good for performance (uses fewer TLB entries for device access). 126034e9ed6SIan Lepore * 127034e9ed6SIan Lepore * ARMMP covers the interrupt controller, MPCore timers, global timer, and the 128034e9ed6SIan Lepore * L2 cache controller. Most of the 1MB range is unused reserved space. 129034e9ed6SIan Lepore * 130034e9ed6SIan Lepore * AIPS1/AIPS2 cover most of the on-chip devices such as uart, spi, i2c, etc. 131034e9ed6SIan Lepore * 132034e9ed6SIan Lepore * Notably not mapped right now are HDMI, GPU, and other devices below ARMMP in 133034e9ed6SIan Lepore * the memory map. When we get support for graphics it might make sense to 134034e9ed6SIan Lepore * static map some of that area. Be careful with other things in that area such 135034e9ed6SIan Lepore * as OCRAM that probably shouldn't be mapped as PTE_DEVICE memory. 136034e9ed6SIan Lepore */ 137*ef7eac43SAndrew Turner static int 138*ef7eac43SAndrew Turner imx6_devmap_init(platform_t plat) 139034e9ed6SIan Lepore { 140034e9ed6SIan Lepore const uint32_t IMX6_ARMMP_PHYS = 0x00a00000; 141034e9ed6SIan Lepore const uint32_t IMX6_ARMMP_SIZE = 0x00100000; 142034e9ed6SIan Lepore const uint32_t IMX6_AIPS1_PHYS = 0x02000000; 143034e9ed6SIan Lepore const uint32_t IMX6_AIPS1_SIZE = 0x00100000; 144034e9ed6SIan Lepore const uint32_t IMX6_AIPS2_PHYS = 0x02100000; 145034e9ed6SIan Lepore const uint32_t IMX6_AIPS2_SIZE = 0x00100000; 146034e9ed6SIan Lepore 14781acdf3fSIan Lepore arm_devmap_add_entry(IMX6_ARMMP_PHYS, IMX6_ARMMP_SIZE); 14881acdf3fSIan Lepore arm_devmap_add_entry(IMX6_AIPS1_PHYS, IMX6_AIPS1_SIZE); 14981acdf3fSIan Lepore arm_devmap_add_entry(IMX6_AIPS2_PHYS, IMX6_AIPS2_SIZE); 15081acdf3fSIan Lepore 15181acdf3fSIan Lepore return (0); 152034e9ed6SIan Lepore } 153034e9ed6SIan Lepore 154034e9ed6SIan Lepore void 155034e9ed6SIan Lepore cpu_reset(void) 156034e9ed6SIan Lepore { 157034e9ed6SIan Lepore const uint32_t IMX6_WDOG_CR_PHYS = 0x020bc000; 158034e9ed6SIan Lepore 159034e9ed6SIan Lepore imx_wdog_cpu_reset(IMX6_WDOG_CR_PHYS); 160034e9ed6SIan Lepore } 161034e9ed6SIan Lepore 162034e9ed6SIan Lepore /* 163034e9ed6SIan Lepore * Determine what flavor of imx6 we're running on. 164034e9ed6SIan Lepore * 165034e9ed6SIan Lepore * This code is based on the way u-boot does it. Information found on the web 166034e9ed6SIan Lepore * indicates that Freescale themselves were the original source of this logic, 167034e9ed6SIan Lepore * including the strange check for number of CPUs in the SCU configuration 168034e9ed6SIan Lepore * register, which is apparently needed on some revisions of the SOLO. 169034e9ed6SIan Lepore * 170034e9ed6SIan Lepore * According to the documentation, there is such a thing as an i.MX6 Dual 171034e9ed6SIan Lepore * (non-lite flavor). However, Freescale doesn't seem to have assigned it a 172034e9ed6SIan Lepore * number or provided any logic to handle it in their detection code. 173034e9ed6SIan Lepore * 174034e9ed6SIan Lepore * Note that the ANALOG_DIGPROG and SCU configuration registers are not 175034e9ed6SIan Lepore * documented in the chip reference manual. (SCU configuration is mentioned, 176034e9ed6SIan Lepore * but not mapped out in detail.) I think the bottom two bits of the scu config 177034e9ed6SIan Lepore * register may be ncpu-1. 178034e9ed6SIan Lepore * 179034e9ed6SIan Lepore * This hasn't been tested yet on a dual[-lite]. 180034e9ed6SIan Lepore * 181034e9ed6SIan Lepore * On a solo: 182034e9ed6SIan Lepore * digprog = 0x00610001 183034e9ed6SIan Lepore * hwsoc = 0x00000062 184034e9ed6SIan Lepore * scu config = 0x00000500 185034e9ed6SIan Lepore * On a quad: 186034e9ed6SIan Lepore * digprog = 0x00630002 187034e9ed6SIan Lepore * hwsoc = 0x00000063 188034e9ed6SIan Lepore * scu config = 0x00005503 189034e9ed6SIan Lepore */ 190034e9ed6SIan Lepore u_int imx_soc_type() 191034e9ed6SIan Lepore { 192034e9ed6SIan Lepore uint32_t digprog, hwsoc; 193034e9ed6SIan Lepore uint32_t *pcr; 1945fdc7f7eSIan Lepore static u_int soctype; 195034e9ed6SIan Lepore const vm_offset_t SCU_CONFIG_PHYSADDR = 0x00a00004; 196272faa5fSIan Lepore #define HWSOC_MX6SL 0x60 197272faa5fSIan Lepore #define HWSOC_MX6DL 0x61 198272faa5fSIan Lepore #define HWSOC_MX6SOLO 0x62 199272faa5fSIan Lepore #define HWSOC_MX6Q 0x63 200034e9ed6SIan Lepore 2015fdc7f7eSIan Lepore if (soctype != 0) 2025fdc7f7eSIan Lepore return (soctype); 2035fdc7f7eSIan Lepore 204034e9ed6SIan Lepore digprog = imx6_anatop_read_4(IMX6_ANALOG_DIGPROG_SL); 205034e9ed6SIan Lepore hwsoc = (digprog >> IMX6_ANALOG_DIGPROG_SOCTYPE_SHIFT) & 206034e9ed6SIan Lepore IMX6_ANALOG_DIGPROG_SOCTYPE_MASK; 207034e9ed6SIan Lepore 208034e9ed6SIan Lepore if (hwsoc != HWSOC_MX6SL) { 209034e9ed6SIan Lepore digprog = imx6_anatop_read_4(IMX6_ANALOG_DIGPROG); 210034e9ed6SIan Lepore hwsoc = (digprog & IMX6_ANALOG_DIGPROG_SOCTYPE_MASK) >> 211034e9ed6SIan Lepore IMX6_ANALOG_DIGPROG_SOCTYPE_SHIFT; 212034e9ed6SIan Lepore /*printf("digprog = 0x%08x\n", digprog);*/ 213034e9ed6SIan Lepore if (hwsoc == HWSOC_MX6DL) { 21413a98c85SIan Lepore pcr = arm_devmap_ptov(SCU_CONFIG_PHYSADDR, 4); 21513a98c85SIan Lepore if (pcr != NULL) { 216034e9ed6SIan Lepore /*printf("scu config = 0x%08x\n", *pcr);*/ 217034e9ed6SIan Lepore if ((*pcr & 0x03) == 0) { 218034e9ed6SIan Lepore hwsoc = HWSOC_MX6SOLO; 219034e9ed6SIan Lepore } 220034e9ed6SIan Lepore } 221034e9ed6SIan Lepore } 222034e9ed6SIan Lepore } 223034e9ed6SIan Lepore /* printf("hwsoc 0x%08x\n", hwsoc); */ 224034e9ed6SIan Lepore 225034e9ed6SIan Lepore switch (hwsoc) { 226034e9ed6SIan Lepore case HWSOC_MX6SL: 2275fdc7f7eSIan Lepore soctype = IMXSOC_6SL; 2285fdc7f7eSIan Lepore break; 229034e9ed6SIan Lepore case HWSOC_MX6SOLO: 2305fdc7f7eSIan Lepore soctype = IMXSOC_6S; 2315fdc7f7eSIan Lepore break; 232034e9ed6SIan Lepore case HWSOC_MX6DL: 2335fdc7f7eSIan Lepore soctype = IMXSOC_6DL; 2345fdc7f7eSIan Lepore break; 235034e9ed6SIan Lepore case HWSOC_MX6Q : 2365fdc7f7eSIan Lepore soctype = IMXSOC_6Q; 2375fdc7f7eSIan Lepore break; 238034e9ed6SIan Lepore default: 239034e9ed6SIan Lepore printf("imx_soc_type: Don't understand hwsoc 0x%02x, " 240034e9ed6SIan Lepore "digprog 0x%08x; assuming IMXSOC_6Q\n", hwsoc, digprog); 2415fdc7f7eSIan Lepore soctype = IMXSOC_6Q; 242034e9ed6SIan Lepore break; 243034e9ed6SIan Lepore } 244034e9ed6SIan Lepore 2455fdc7f7eSIan Lepore return (soctype); 246034e9ed6SIan Lepore } 247034e9ed6SIan Lepore 2488df34dd2SIan Lepore /* 2498df34dd2SIan Lepore * Early putc routine for EARLY_PRINTF support. To use, add to kernel config: 2508df34dd2SIan Lepore * option SOCDEV_PA=0x02000000 2518df34dd2SIan Lepore * option SOCDEV_VA=0x02000000 2528df34dd2SIan Lepore * option EARLY_PRINTF 2538df34dd2SIan Lepore * Resist the temptation to change the #if 0 to #ifdef EARLY_PRINTF here. It 2548df34dd2SIan Lepore * makes sense now, but if multiple SOCs do that it will make early_putc another 2558df34dd2SIan Lepore * duplicate symbol to be eliminated on the path to a generic kernel. 2568df34dd2SIan Lepore */ 2578df34dd2SIan Lepore #if 0 2588df34dd2SIan Lepore static void 2598df34dd2SIan Lepore imx6_early_putc(int c) 2608df34dd2SIan Lepore { 2618df34dd2SIan Lepore volatile uint32_t * UART_STAT_REG = (uint32_t *)0x02020098; 2628df34dd2SIan Lepore volatile uint32_t * UART_TX_REG = (uint32_t *)0x02020040; 2638df34dd2SIan Lepore const uint32_t UART_TXRDY = (1 << 3); 2648df34dd2SIan Lepore 2658df34dd2SIan Lepore while ((*UART_STAT_REG & UART_TXRDY) == 0) 2668df34dd2SIan Lepore continue; 2678df34dd2SIan Lepore *UART_TX_REG = c; 2688df34dd2SIan Lepore } 2698df34dd2SIan Lepore early_putc_t *early_putc = imx6_early_putc; 2708df34dd2SIan Lepore #endif 2718df34dd2SIan Lepore 272*ef7eac43SAndrew Turner static platform_method_t imx6_methods[] = { 273*ef7eac43SAndrew Turner PLATFORMMETHOD(platform_attach, imx6_attach), 274*ef7eac43SAndrew Turner PLATFORMMETHOD(platform_lastaddr, imx6_lastaddr), 275*ef7eac43SAndrew Turner PLATFORMMETHOD(platform_devmap_init, imx6_devmap_init), 276*ef7eac43SAndrew Turner PLATFORMMETHOD(platform_late_init, imx6_late_init), 277*ef7eac43SAndrew Turner 278*ef7eac43SAndrew Turner PLATFORMMETHOD_END, 279*ef7eac43SAndrew Turner }; 280*ef7eac43SAndrew Turner 281*ef7eac43SAndrew Turner FDT_PLATFORM_DEF2(imx6, imx6s, "i.MX6 Solo", 0, "fsl,imx6s"); 282*ef7eac43SAndrew Turner FDT_PLATFORM_DEF2(imx6, imx6d, "i.MX6 Dual", 0, "fsl,imx6d"); 283*ef7eac43SAndrew Turner FDT_PLATFORM_DEF2(imx6, imx6q, "i.MX6 Quad", 0, "fsl,imx6q"); 284