e990f3c09e619c97a0e5a93570ed007c32dcb9d2
[platform/kernel/u-boot.git] / arch / arm / cpu / arm926ejs / mx28 / mx28.c
1 /*
2  * Freescale i.MX28 common code
3  *
4  * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5  * on behalf of DENX Software Engineering GmbH
6  *
7  * Based on code from LTIB:
8  * Copyright (C) 2010 Freescale Semiconductor, Inc.
9  *
10  * See file CREDITS for list of people who contributed to this
11  * project.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License as
15  * published by the Free Software Foundation; either version 2 of
16  * the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26  * MA 02111-1307 USA
27  */
28
29 #include <common.h>
30 #include <asm/errno.h>
31 #include <asm/io.h>
32 #include <asm/arch/clock.h>
33 #include <asm/arch/gpio.h>
34 #include <asm/arch/iomux.h>
35 #include <asm/arch/imx-regs.h>
36 #include <asm/arch/sys_proto.h>
37
38 /* 1 second delay should be plenty of time for block reset. */
39 #define RESET_MAX_TIMEOUT       1000000
40
41 #define MX28_BLOCK_SFTRST       (1 << 31)
42 #define MX28_BLOCK_CLKGATE      (1 << 30)
43
44 /* Lowlevel init isn't used on i.MX28, so just have a dummy here */
45 inline void lowlevel_init(void) {}
46
47 void reset_cpu(ulong ignored) __attribute__((noreturn));
48
49 void reset_cpu(ulong ignored)
50 {
51
52         struct mx28_rtc_regs *rtc_regs =
53                 (struct mx28_rtc_regs *)MXS_RTC_BASE;
54
55         /* Wait 1 uS before doing the actual watchdog reset */
56         writel(1, &rtc_regs->hw_rtc_watchdog);
57         writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
58
59         /* Endless loop, reset will exit from here */
60         for (;;)
61                 ;
62 }
63
64 int mx28_wait_mask_set(struct mx28_register *reg, uint32_t mask, int timeout)
65 {
66         while (--timeout) {
67                 if ((readl(&reg->reg) & mask) == mask)
68                         break;
69                 udelay(1);
70         }
71
72         return !timeout;
73 }
74
75 int mx28_wait_mask_clr(struct mx28_register *reg, uint32_t mask, int timeout)
76 {
77         while (--timeout) {
78                 if ((readl(&reg->reg) & mask) == 0)
79                         break;
80                 udelay(1);
81         }
82
83         return !timeout;
84 }
85
86 int mx28_reset_block(struct mx28_register *reg)
87 {
88         /* Clear SFTRST */
89         writel(MX28_BLOCK_SFTRST, &reg->reg_clr);
90
91         if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
92                 return 1;
93
94         /* Clear CLKGATE */
95         writel(MX28_BLOCK_CLKGATE, &reg->reg_clr);
96
97         /* Set SFTRST */
98         writel(MX28_BLOCK_SFTRST, &reg->reg_set);
99
100         /* Wait for CLKGATE being set */
101         if (mx28_wait_mask_set(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
102                 return 1;
103
104         /* Clear SFTRST */
105         writel(MX28_BLOCK_SFTRST, &reg->reg_clr);
106
107         if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
108                 return 1;
109
110         /* Clear CLKGATE */
111         writel(MX28_BLOCK_CLKGATE, &reg->reg_clr);
112
113         if (mx28_wait_mask_clr(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
114                 return 1;
115
116         return 0;
117 }
118
119 #ifdef  CONFIG_ARCH_CPU_INIT
120 int arch_cpu_init(void)
121 {
122         struct mx28_clkctrl_regs *clkctrl_regs =
123                 (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
124
125         /*
126          * Enable NAND clock
127          */
128         /* Clear bypass bit */
129         writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
130                 &clkctrl_regs->hw_clkctrl_clkseq_set);
131
132         /* Set GPMI clock to ref_gpmi / 12 */
133         clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
134                 CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1);
135
136         udelay(1000);
137
138         /*
139          * Configure GPIO unit
140          */
141         mxs_gpio_init();
142
143         return 0;
144 }
145 #endif
146
147 #if defined(CONFIG_DISPLAY_CPUINFO)
148 int print_cpuinfo(void)
149 {
150         printf("Freescale i.MX28 family\n");
151         return 0;
152 }
153 #endif
154
155 int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
156 {
157         printf("CPU:   %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
158         printf("BUS:   %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
159         printf("EMI:   %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
160         printf("GPMI:  %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
161         return 0;
162 }
163
164 /*
165  * Initializes on-chip ethernet controllers.
166  */
167 #ifdef  CONFIG_CMD_NET
168 int cpu_eth_init(bd_t *bis)
169 {
170         struct mx28_clkctrl_regs *clkctrl_regs =
171                 (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
172
173         /* Turn on ENET clocks */
174         clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
175                 CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
176
177         /* Set up ENET PLL for 50 MHz */
178         /* Power on ENET PLL */
179         writel(CLKCTRL_PLL2CTRL0_POWER,
180                 &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
181
182         udelay(10);
183
184         /* Gate on ENET PLL */
185         writel(CLKCTRL_PLL2CTRL0_CLKGATE,
186                 &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
187
188         /* Enable pad output */
189         setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
190
191         return 0;
192 }
193 #endif
194
195 U_BOOT_CMD(
196         clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
197         "display clocks",
198         ""
199 );