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