1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2552a848eSStefano Babic /*
3552a848eSStefano Babic * Copyright 2015 Freescale Semiconductor, Inc.
4552a848eSStefano Babic */
5552a848eSStefano Babic
6552a848eSStefano Babic #include <asm/io.h>
7552a848eSStefano Babic #include <asm/arch/imx-regs.h>
8552a848eSStefano Babic #include <asm/arch/clock.h>
9552a848eSStefano Babic #include <asm/arch/sys_proto.h>
10552a848eSStefano Babic #include <asm/mach-imx/boot_mode.h>
11552a848eSStefano Babic #include <asm/arch/crm_regs.h>
12552a848eSStefano Babic
init_aips(void)13552a848eSStefano Babic void init_aips(void)
14552a848eSStefano Babic {
15552a848eSStefano Babic struct aipstz_regs *aips1, *aips2, *aips3;
16552a848eSStefano Babic
17552a848eSStefano Babic aips1 = (struct aipstz_regs *)AIPS1_BASE_ADDR;
18552a848eSStefano Babic aips2 = (struct aipstz_regs *)AIPS2_BASE_ADDR;
19552a848eSStefano Babic aips3 = (struct aipstz_regs *)AIPS3_BASE_ADDR;
20552a848eSStefano Babic
21552a848eSStefano Babic /*
22552a848eSStefano Babic * Set all MPROTx to be non-bufferable, trusted for R/W,
23552a848eSStefano Babic * not forced to user-mode.
24552a848eSStefano Babic */
25552a848eSStefano Babic writel(0x77777777, &aips1->mprot0);
26552a848eSStefano Babic writel(0x77777777, &aips1->mprot1);
27552a848eSStefano Babic writel(0x77777777, &aips2->mprot0);
28552a848eSStefano Babic writel(0x77777777, &aips2->mprot1);
29552a848eSStefano Babic
30552a848eSStefano Babic /*
31552a848eSStefano Babic * Set all OPACRx to be non-bufferable, not require
32552a848eSStefano Babic * supervisor privilege level for access,allow for
33552a848eSStefano Babic * write access and untrusted master access.
34552a848eSStefano Babic */
35552a848eSStefano Babic writel(0x00000000, &aips1->opacr0);
36552a848eSStefano Babic writel(0x00000000, &aips1->opacr1);
37552a848eSStefano Babic writel(0x00000000, &aips1->opacr2);
38552a848eSStefano Babic writel(0x00000000, &aips1->opacr3);
39552a848eSStefano Babic writel(0x00000000, &aips1->opacr4);
40552a848eSStefano Babic writel(0x00000000, &aips2->opacr0);
41552a848eSStefano Babic writel(0x00000000, &aips2->opacr1);
42552a848eSStefano Babic writel(0x00000000, &aips2->opacr2);
43552a848eSStefano Babic writel(0x00000000, &aips2->opacr3);
44552a848eSStefano Babic writel(0x00000000, &aips2->opacr4);
45552a848eSStefano Babic
46552a848eSStefano Babic if (is_mx6ull() || is_mx6sx() || is_mx7()) {
47552a848eSStefano Babic /*
48552a848eSStefano Babic * Set all MPROTx to be non-bufferable, trusted for R/W,
49552a848eSStefano Babic * not forced to user-mode.
50552a848eSStefano Babic */
51552a848eSStefano Babic writel(0x77777777, &aips3->mprot0);
52552a848eSStefano Babic writel(0x77777777, &aips3->mprot1);
53552a848eSStefano Babic
54552a848eSStefano Babic /*
55552a848eSStefano Babic * Set all OPACRx to be non-bufferable, not require
56552a848eSStefano Babic * supervisor privilege level for access,allow for
57552a848eSStefano Babic * write access and untrusted master access.
58552a848eSStefano Babic */
59552a848eSStefano Babic writel(0x00000000, &aips3->opacr0);
60552a848eSStefano Babic writel(0x00000000, &aips3->opacr1);
61552a848eSStefano Babic writel(0x00000000, &aips3->opacr2);
62552a848eSStefano Babic writel(0x00000000, &aips3->opacr3);
63552a848eSStefano Babic writel(0x00000000, &aips3->opacr4);
64552a848eSStefano Babic }
65552a848eSStefano Babic }
66552a848eSStefano Babic
imx_wdog_disable_powerdown(void)67e2162d70SFabio Estevam void imx_wdog_disable_powerdown(void)
68552a848eSStefano Babic {
69552a848eSStefano Babic struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
70552a848eSStefano Babic struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
71552a848eSStefano Babic struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
72552a848eSStefano Babic #ifdef CONFIG_MX7D
73552a848eSStefano Babic struct wdog_regs *wdog4 = (struct wdog_regs *)WDOG4_BASE_ADDR;
74552a848eSStefano Babic #endif
75552a848eSStefano Babic
76552a848eSStefano Babic /* Write to the PDE (Power Down Enable) bit */
77e2162d70SFabio Estevam writew(0, &wdog1->wmcr);
78e2162d70SFabio Estevam writew(0, &wdog2->wmcr);
79552a848eSStefano Babic
80b42287f4SFabio Estevam if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx7())
81e2162d70SFabio Estevam writew(0, &wdog3->wmcr);
82552a848eSStefano Babic #ifdef CONFIG_MX7D
83e2162d70SFabio Estevam writew(0, &wdog4->wmcr);
84552a848eSStefano Babic #endif
85552a848eSStefano Babic }
86552a848eSStefano Babic
87552a848eSStefano Babic #define SRC_SCR_WARM_RESET_ENABLE 0
88552a848eSStefano Babic
init_src(void)89552a848eSStefano Babic void init_src(void)
90552a848eSStefano Babic {
91552a848eSStefano Babic struct src *src_regs = (struct src *)SRC_BASE_ADDR;
92552a848eSStefano Babic u32 val;
93552a848eSStefano Babic
94552a848eSStefano Babic /*
95552a848eSStefano Babic * force warm reset sources to generate cold reset
96552a848eSStefano Babic * for a more reliable restart
97552a848eSStefano Babic */
98552a848eSStefano Babic val = readl(&src_regs->scr);
99552a848eSStefano Babic val &= ~(1 << SRC_SCR_WARM_RESET_ENABLE);
100552a848eSStefano Babic writel(val, &src_regs->scr);
101552a848eSStefano Babic }
102552a848eSStefano Babic
103552a848eSStefano Babic #ifdef CONFIG_CMD_BMODE
boot_mode_apply(unsigned cfg_val)104552a848eSStefano Babic void boot_mode_apply(unsigned cfg_val)
105552a848eSStefano Babic {
106552a848eSStefano Babic unsigned reg;
107552a848eSStefano Babic struct src *psrc = (struct src *)SRC_BASE_ADDR;
108552a848eSStefano Babic writel(cfg_val, &psrc->gpr9);
109552a848eSStefano Babic reg = readl(&psrc->gpr10);
110552a848eSStefano Babic if (cfg_val)
111552a848eSStefano Babic reg |= 1 << 28;
112552a848eSStefano Babic else
113552a848eSStefano Babic reg &= ~(1 << 28);
114552a848eSStefano Babic writel(reg, &psrc->gpr10);
115552a848eSStefano Babic }
116552a848eSStefano Babic #endif
117552a848eSStefano Babic
118552a848eSStefano Babic #if defined(CONFIG_MX6)
imx6_src_get_boot_mode(void)119552a848eSStefano Babic u32 imx6_src_get_boot_mode(void)
120552a848eSStefano Babic {
121552a848eSStefano Babic if (imx6_is_bmode_from_gpr9())
122552a848eSStefano Babic return readl(&src_base->gpr9);
123552a848eSStefano Babic else
124552a848eSStefano Babic return readl(&src_base->sbmr1);
125552a848eSStefano Babic }
126552a848eSStefano Babic #endif
127