1 1.1 matt /* $Id: bootimx23.c,v 1.1 2013/10/07 17:36:40 matt Exp $ */ 2 1.1 matt 3 1.1 matt /* 4 1.1 matt * Copyright (c) 2013 The NetBSD Foundation, Inc. 5 1.1 matt * All rights reserved. 6 1.1 matt * 7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation 8 1.1 matt * by Petri Laakso. 9 1.1 matt * 10 1.1 matt * Redistribution and use in source and binary forms, with or without 11 1.1 matt * modification, are permitted provided that the following conditions 12 1.1 matt * are met: 13 1.1 matt * 1. Redistributions of source code must retain the above copyright 14 1.1 matt * notice, this list of conditions and the following disclaimer. 15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 matt * notice, this list of conditions and the following disclaimer in the 17 1.1 matt * documentation and/or other materials provided with the distribution. 18 1.1 matt * 19 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 matt * POSSIBILITY OF SUCH DAMAGE. 30 1.1 matt */ 31 1.1 matt 32 1.1 matt #include <sys/param.h> 33 1.1 matt #include <sys/cdefs.h> 34 1.1 matt 35 1.1 matt #include <arm/imx/imx23_digctlreg.h> 36 1.1 matt #include <arm/imx/imx23_powerreg.h> 37 1.1 matt #include <arm/imx/imx23_clkctrlreg.h> 38 1.1 matt 39 1.1 matt #include <lib/libsa/stand.h> 40 1.1 matt 41 1.1 matt #include "common.h" 42 1.1 matt 43 1.1 matt #define DRAM_REGS 41 44 1.1 matt #define HBUS_DIV 2 45 1.1 matt #define CPU_FRAC 22 46 1.1 matt #define EMI_DIV 2 47 1.1 matt #define EMI_FRAC 33 48 1.1 matt #define SSP_DIV 2 49 1.1 matt #define IO_FRAC 27 50 1.1 matt 51 1.1 matt /* 52 1.1 matt * Initialize i.MX233 53 1.1 matt */ 54 1.1 matt int 55 1.1 matt _start(void) 56 1.1 matt { 57 1.1 matt 58 1.1 matt volatile uint32_t *digctl_ctrl_rs; 59 1.1 matt volatile uint32_t *digctl_ctrl_rc; 60 1.1 matt volatile uint32_t *digctl_id_r; 61 1.1 matt volatile uint32_t *pwr_status_r; 62 1.1 matt uint8_t boot_reason; 63 1.1 matt int on_batt; 64 1.1 matt 65 1.1 matt digctl_ctrl_rs = (uint32_t *)(HW_DIGCTL_BASE + HW_DIGCTL_CTRL_SET); 66 1.1 matt digctl_ctrl_rc = (uint32_t *)(HW_DIGCTL_BASE + HW_DIGCTL_CTRL_CLR); 67 1.1 matt pwr_status_r = (uint32_t *)(HW_POWER_BASE + HW_POWER_STS); 68 1.1 matt digctl_id_r = (uint32_t *)(HW_DIGCTL_BASE + HW_DIGCTL_CHIPID); 69 1.1 matt 70 1.1 matt /* Enable SJTAG. */ 71 1.1 matt *digctl_ctrl_rs = HW_DIGCTL_CTRL_USE_SERIAL_JTAG; 72 1.1 matt 73 1.1 matt /* Enable microseconds timer. */ 74 1.1 matt *digctl_ctrl_rc = HW_DIGCTL_CTRL_XTAL24M_GATE; 75 1.1 matt 76 1.1 matt if (*pwr_status_r & HW_POWER_STS_VDD5V_GT_VDDIO) 77 1.1 matt on_batt = 0; 78 1.1 matt else 79 1.1 matt on_batt = 1; 80 1.1 matt 81 1.1 matt printf("\r\nbootimx23: "); 82 1.1 matt printf("HW revision TA%d, ", 83 1.1 matt (uint8_t)__SHIFTOUT(*digctl_id_r, HW_DIGCTL_CHIPID_REVISION) + 1); 84 1.1 matt printf("boot reason "); 85 1.1 matt boot_reason = 86 1.1 matt (uint8_t) __SHIFTOUT(*pwr_status_r, HW_POWER_STS_PWRUP_SOURCE); 87 1.1 matt 88 1.1 matt switch (boot_reason) 89 1.1 matt { 90 1.1 matt case 0x20: 91 1.1 matt printf("5V, "); 92 1.1 matt break; 93 1.1 matt case 0x10: 94 1.1 matt printf("RTC, "); 95 1.1 matt break; 96 1.1 matt case 0x02: 97 1.1 matt printf("high pswitch, "); 98 1.1 matt break; 99 1.1 matt case 0x01: 100 1.1 matt printf("mid pswitch, "); 101 1.1 matt break; 102 1.1 matt default: 103 1.1 matt printf("UNKNOWN, "); 104 1.1 matt } 105 1.1 matt 106 1.1 matt printf("power source "); 107 1.1 matt if (on_batt) 108 1.1 matt printf("battery"); 109 1.1 matt else 110 1.1 matt printf("5V"); 111 1.1 matt printf("\r\n"); 112 1.1 matt 113 1.1 matt /* Power. */ 114 1.1 matt en_vbusvalid(); 115 1.1 matt if (!vbusvalid()) 116 1.1 matt printf("WARNING: !VBUSVALID\r\n"); 117 1.1 matt 118 1.1 matt printf("Enabling 4P2 regulator..."); 119 1.1 matt en_4p2_reg(); 120 1.1 matt printf("done\r\n"); 121 1.1 matt 122 1.1 matt power_tune(); 123 1.1 matt 124 1.1 matt printf("Enabling 4P2 regulator output to DCDC..."); 125 1.1 matt en_4p2_to_dcdc(); 126 1.1 matt printf("done\r\n"); 127 1.1 matt 128 1.1 matt printf("Enabling VDDMEM..."); 129 1.1 matt power_vddmem(2500); 130 1.1 matt printf("done\r\n"); 131 1.1 matt 132 1.1 matt printf("Powering VDDD from DCDC..."); 133 1.1 matt /* Boot fails if I set here TRG to +1500mV, do it later. */ 134 1.1 matt power_vddd_from_dcdc(1400, 1075); 135 1.1 matt printf("done\r\n"); 136 1.1 matt 137 1.1 matt printf("Powering VDDA from DCDC..."); 138 1.1 matt power_vdda_from_dcdc(1800, 1625); 139 1.1 matt printf("done\r\n"); 140 1.1 matt 141 1.1 matt /* 142 1.1 matt * VDDIO and thus SSP_CLK setup is postponed to 143 1.1 matt * imx23_olinuxino_machdep.c because SB is not able to load kernel if 144 1.1 matt * clocks are changed now. 145 1.1 matt */ 146 1.1 matt printf("Powering VDDIO from DCDC..."); 147 1.1 matt power_vddio_from_dcdc(3100, 2925); 148 1.1 matt printf("done\r\n"); 149 1.1 matt 150 1.1 matt /* Clocks */ 151 1.1 matt printf("Enabling clocks..."); 152 1.1 matt en_pll(); 153 1.1 matt bypass_saif(); /* Always set to zero bit. */ 154 1.1 matt set_cpu_frac(CPU_FRAC); 155 1.1 matt set_hbus_div(HBUS_DIV); 156 1.1 matt bypass_cpu(); 157 1.1 matt power_vddd_from_dcdc(1475, 1375); 158 1.1 matt set_emi_div(EMI_DIV); 159 1.1 matt set_emi_frac(EMI_FRAC); 160 1.1 matt bypass_emi(); 161 1.1 matt printf("done\r\n"); 162 1.1 matt 163 1.1 matt printf("Configuring pins..."); 164 1.1 matt pinctrl_prep(); 165 1.1 matt printf("done\r\n"); 166 1.1 matt printf("Configuring EMI..."); 167 1.1 matt emi_prep(); 168 1.1 matt printf("done\r\n"); 169 1.1 matt args_prep(); 170 1.1 matt 171 1.1 matt return 0; 172 1.1 matt } 173