3 * Sascha Hauer, Pengutronix
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/errno.h>
29 #include <asm/arch/imx-regs.h>
30 #include <asm/arch/crm_regs.h>
31 #include <asm/arch/regs-ocotp.h>
32 #include <asm/arch/clock.h>
33 #include <asm/arch/dma.h>
34 #include <asm/arch/sys_proto.h>
35 #include <asm/imx-common/boot_mode.h>
36 #ifdef CONFIG_VIDEO_IPUV3
40 DECLARE_GLOBAL_DATA_PTR;
42 #define TEMPERATURE_MIN -40
43 #define TEMPERATURE_HOT 80
44 #define TEMPERATURE_MAX 125
45 #define REG_VALUE_TO_CEL(ratio, raw) ((raw_n40c - raw) * 100 / ratio - 40)
47 #define __data __attribute__((section(".data")))
57 #ifdef CONFIG_HW_WATCHDOG
58 #define wdog_base ((void *)WDOG1_BASE_ADDR)
60 #define WCR_WDE (1 << 2)
63 void hw_watchdog_reset(void)
65 if (readw(wdog_base + WDOG_WCR) & WCR_WDE) {
66 static u16 toggle = 0xaaaa;
70 printf("Watchdog active\n");
73 writew(toggle, wdog_base + WDOG_WSR);
81 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
82 u32 reg = readl(&anatop->digprog_sololite);
83 u32 type = ((reg >> 16) & 0xff);
85 if (type != MXC_CPU_MX6SL) {
86 reg = readl(&anatop->digprog);
87 type = ((reg >> 16) & 0xff);
88 if (type == MXC_CPU_MX6DL) {
89 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
90 u32 cfg = readl(&scu->config) & 3;
93 type = MXC_CPU_MX6SOLO;
96 reg &= 0xff; /* mx6 silicon revision */
97 return (type << 12) | (reg + 0x10);
102 struct aipstz_regs *aips1, *aips2;
104 aips1 = (struct aipstz_regs *)AIPS1_BASE_ADDR;
105 aips2 = (struct aipstz_regs *)AIPS2_BASE_ADDR;
108 * Set all MPROTx to be non-bufferable, trusted for R/W,
109 * not forced to user-mode.
111 writel(0x77777777, &aips1->mprot0);
112 writel(0x77777777, &aips1->mprot1);
113 writel(0x77777777, &aips2->mprot0);
114 writel(0x77777777, &aips2->mprot1);
117 * Set all OPACRx to be non-bufferable, not require
118 * supervisor privilege level for access,allow for
119 * write access and untrusted master access.
121 writel(0x00000000, &aips1->opacr0);
122 writel(0x00000000, &aips1->opacr1);
123 writel(0x00000000, &aips1->opacr2);
124 writel(0x00000000, &aips1->opacr3);
125 writel(0x00000000, &aips1->opacr4);
126 writel(0x00000000, &aips2->opacr0);
127 writel(0x00000000, &aips2->opacr1);
128 writel(0x00000000, &aips2->opacr2);
129 writel(0x00000000, &aips2->opacr3);
130 writel(0x00000000, &aips2->opacr4);
136 * Mask out the REG_CORE[22:18] bits (REG2_TRIG) and set
137 * them to the specified millivolt level.
138 * Possible values are from 0.725V to 1.450V in steps of
141 static void set_vddsoc(u32 mv)
143 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
144 u32 val, reg = readl(&anatop->reg_core);
147 val = 0x00; /* Power gated off */
149 val = 0x1F; /* Power FET switched full on. No regulation */
151 val = (mv - 700) / 25;
154 * Mask out the REG_CORE[22:18] bits (REG2_TRIG)
155 * and set them to the calculated value (0.7V + val * 0.25V)
157 reg = (reg & ~(0x1F << 18)) | (val << 18);
158 writel(reg, &anatop->reg_core);
161 static u32 __data thermal_calib;
163 int read_cpu_temperature(void)
165 unsigned int reg, tmp, i;
166 unsigned int raw_25c, raw_hot, hot_temp, raw_n40c, ratio;
168 struct anatop_regs *const anatop = (void *)ANATOP_BASE_ADDR;
169 struct mx6_ocotp_regs *const ocotp_regs = (void *)OCOTP_BASE_ADDR;
171 if (!thermal_calib) {
173 writel(1, &ocotp_regs->hw_ocotp_read_ctrl);
174 thermal_calib = readl(&ocotp_regs->hw_ocotp_ana1);
175 writel(0, &ocotp_regs->hw_ocotp_read_ctrl);
179 if (thermal_calib == 0 || thermal_calib == 0xffffffff)
180 return TEMPERATURE_MIN;
183 * [31:20] sensor value @ 25C
184 * [19:8] sensor value of hot
185 * [7:0] hot temperature value */
186 raw_25c = thermal_calib >> 20;
187 raw_hot = (thermal_calib & 0xfff00) >> 8;
188 hot_temp = thermal_calib & 0xff;
190 ratio = ((raw_25c - raw_hot) * 100) / (hot_temp - 25);
191 raw_n40c = raw_25c + (13 * ratio) / 20;
193 /* now we only using single measure, every time we measure
194 the temperature, we will power on/down the anadig module*/
195 writel(BM_ANADIG_TEMPSENSE0_POWER_DOWN, &anatop->tempsense0_clr);
196 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
198 /* write measure freq */
199 reg = readl(&anatop->tempsense1);
200 reg &= ~BM_ANADIG_TEMPSENSE1_MEASURE_FREQ;
202 writel(reg, &anatop->tempsense1);
204 writel(BM_ANADIG_TEMPSENSE0_MEASURE_TEMP, &anatop->tempsense0_clr);
205 writel(BM_ANADIG_TEMPSENSE0_FINISHED, &anatop->tempsense0_clr);
206 writel(BM_ANADIG_TEMPSENSE0_MEASURE_TEMP, &anatop->tempsense0_set);
209 /* read five times of temperature values to get average*/
210 for (i = 0; i < 5; i++) {
211 while ((readl(&anatop->tempsense0) &
212 BM_ANADIG_TEMPSENSE0_FINISHED) == 0)
214 reg = readl(&anatop->tempsense0);
215 tmp += (reg & BM_ANADIG_TEMPSENSE0_TEMP_VALUE) >>
216 BP_ANADIG_TEMPSENSE0_TEMP_VALUE;
217 writel(BM_ANADIG_TEMPSENSE0_FINISHED,
218 &anatop->tempsense0_clr);
223 temperature = REG_VALUE_TO_CEL(ratio, tmp);
225 temperature = TEMPERATURE_MIN;
227 /* power down anatop thermal sensor */
228 writel(BM_ANADIG_TEMPSENSE0_POWER_DOWN, &anatop->tempsense0_set);
229 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_clr);
234 int check_cpu_temperature(int boot)
236 static int __data max_temp;
237 int boot_limit = TEMPERATURE_HOT;
238 int tmp = read_cpu_temperature();
240 debug("max_temp[%p]=%d diff=%d\n", &max_temp, max_temp, tmp - max_temp);
242 if (tmp < TEMPERATURE_MIN || tmp > TEMPERATURE_MAX) {
243 printf("Temperature: can't get valid data!\n");
247 while (tmp >= boot_limit) {
249 printf("CPU is %d C, too hot to boot, waiting...\n",
252 tmp = read_cpu_temperature();
253 boot_limit = TEMPERATURE_HOT - 1;
255 printf("CPU is %d C, too hot, resetting...\n",
263 printf("Temperature: %d C, calibration data 0x%x\n",
265 } else if (tmp > max_temp) {
266 if (tmp > TEMPERATURE_HOT - 5)
267 printf("WARNING: CPU temperature %d C\n", tmp);
273 int arch_cpu_init(void)
277 set_vddsoc(1200); /* Set VDDSOC to 1.2V */
279 #ifdef CONFIG_VIDEO_IPUV3
280 gd->arch.ipu_hw_rev = IPUV3_HW_REV_IPUV3H;
282 #ifdef CONFIG_APBH_DMA
283 /* Timer is required for Initializing APBH DMA */
290 #ifndef CONFIG_SYS_DCACHE_OFF
291 void enable_caches(void)
293 /* Enable D-cache. I-cache is already enabled in start.S */
298 #if defined(CONFIG_FEC_MXC)
299 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
301 struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
302 struct fuse_bank *bank = &iim->bank[4];
303 struct fuse_bank4_regs *fuse =
304 (struct fuse_bank4_regs *)bank->fuse_regs;
306 u32 value = readl(&fuse->mac_addr_high);
307 mac[0] = (value >> 8);
310 value = readl(&fuse->mac_addr_low);
311 mac[2] = value >> 24;
312 mac[3] = value >> 16;
318 void boot_mode_apply(unsigned cfg_val)
321 struct src *psrc = (struct src *)SRC_BASE_ADDR;
322 writel(cfg_val, &psrc->gpr9);
323 reg = readl(&psrc->gpr10);
328 writel(reg, &psrc->gpr10);
331 * cfg_val will be used for
332 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
333 * After reset, if GPR10[28] is 1, ROM will copy GPR9[25:0]
334 * to SBMR1, which will determine the boot device.
336 const struct boot_mode soc_boot_modes[] = {
337 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
338 /* reserved value should start rom usb */
339 {"usb", MAKE_CFGVAL(0x01, 0x00, 0x00, 0x00)},
340 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
341 {"escpi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
342 {"escpi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
343 {"escpi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
344 {"escpi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
345 /* 4 bit bus width */
346 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
347 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
348 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
349 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
352 #define RESET_MAX_TIMEOUT 1000000
353 #define MXS_BLOCK_SFTRST (1 << 31)
354 #define MXS_BLOCK_CLKGATE (1 << 30)
357 static const int scale = 1;
359 int mxs_wait_mask_set(struct mx6_register_32 *mx6_reg, uint32_t mask, unsigned long timeout)
361 unsigned long loops = 0;
367 /* Wait for at least one microsecond for the bit mask to be set */
368 while ((readl(&mx6_reg->reg) & mask) != mask) {
369 if ((loops += scale) >= timeout) {
370 printf("MASK %08x in %p not set after %lu ticks\n",
371 mask, &mx6_reg->reg, loops * scale);
382 int mxs_wait_mask_clr(struct mx6_register_32 *mx6_reg, uint32_t mask, unsigned long timeout)
384 unsigned long loops = 0;
390 /* Wait for at least one microsecond for the bit mask to be cleared */
391 while ((readl(&mx6_reg->reg) & mask) != 0) {
392 if ((loops += scale) >= timeout) {
393 printf("MASK %08x in %p not cleared after %lu ticks\n",
394 mask, &mx6_reg->reg, loops * scale);
405 int mxs_reset_block(struct mx6_register_32 *mx6_reg)
408 writel(MXS_BLOCK_SFTRST, &mx6_reg->reg_clr);
410 if (mxs_wait_mask_clr(mx6_reg, MXS_BLOCK_SFTRST, RESET_MAX_TIMEOUT)) {
411 printf("TIMEOUT waiting for SFTRST[%p] to clear: %08x\n",
412 &mx6_reg->reg, readl(&mx6_reg->reg));
417 writel(MXS_BLOCK_CLKGATE, &mx6_reg->reg_clr);
420 writel(MXS_BLOCK_SFTRST, &mx6_reg->reg_set);
422 /* Wait for CLKGATE being set */
423 if (mxs_wait_mask_set(mx6_reg, MXS_BLOCK_CLKGATE, RESET_MAX_TIMEOUT)) {
424 printf("TIMEOUT waiting for CLKGATE[%p] to set: %08x\n",
425 &mx6_reg->reg, readl(&mx6_reg->reg));
430 writel(MXS_BLOCK_SFTRST, &mx6_reg->reg_clr);
432 if (mxs_wait_mask_clr(mx6_reg, MXS_BLOCK_SFTRST, RESET_MAX_TIMEOUT)) {
433 printf("TIMEOUT waiting for SFTRST[%p] to clear: %08x\n",
434 &mx6_reg->reg, readl(&mx6_reg->reg));
439 writel(MXS_BLOCK_CLKGATE, &mx6_reg->reg_clr);
441 if (mxs_wait_mask_clr(mx6_reg, MXS_BLOCK_CLKGATE, RESET_MAX_TIMEOUT)) {
442 printf("TIMEOUT waiting for CLKGATE[%p] to clear: %08x\n",
443 &mx6_reg->reg, readl(&mx6_reg->reg));