m68k: rename CONFIG_MCFTMR to CFG_MCFTMR
[platform/kernel/u-boot.git] / arch / m68k / cpu / mcf532x / cpu_init.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *
4  * (C) Copyright 2000-2003
5  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6  *
7  * (C) Copyright 2004-2008, 2012 Freescale Semiconductor, Inc.
8  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
9  */
10
11 #include <common.h>
12 #include <cpu_func.h>
13 #include <init.h>
14 #include <watchdog.h>
15 #include <asm/immap.h>
16 #include <asm/io.h>
17
18 #if defined(CONFIG_MCFFEC)
19 #include <config.h>
20 #include <net.h>
21 #include <asm/fec.h>
22 #endif
23
24 #ifdef CONFIG_MCF5301x
25 void cpu_init_f(void)
26 {
27         scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
28         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
29         fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
30
31         out_be32(&scm1->mpr, 0x77777777);
32         out_be32(&scm1->pacra, 0);
33         out_be32(&scm1->pacrb, 0);
34         out_be32(&scm1->pacrc, 0);
35         out_be32(&scm1->pacrd, 0);
36         out_be32(&scm1->pacre, 0);
37         out_be32(&scm1->pacrf, 0);
38         out_be32(&scm1->pacrg, 0);
39
40 #if (defined(CFG_SYS_CS0_BASE) && defined(CFG_SYS_CS0_MASK) \
41      && defined(CFG_SYS_CS0_CTRL))
42         setbits_8(&gpio->par_cs, GPIO_PAR_CS0_CS0);
43         out_be32(&fbcs->csar0, CFG_SYS_CS0_BASE);
44         out_be32(&fbcs->cscr0, CFG_SYS_CS0_CTRL);
45         out_be32(&fbcs->csmr0, CFG_SYS_CS0_MASK);
46 #endif
47
48 #if (defined(CFG_SYS_CS1_BASE) && defined(CFG_SYS_CS1_MASK) \
49      && defined(CFG_SYS_CS1_CTRL))
50         setbits_8(&gpio->par_cs, GPIO_PAR_CS1_CS1);
51         out_be32(&fbcs->csar1, CFG_SYS_CS1_BASE);
52         out_be32(&fbcs->cscr1, CFG_SYS_CS1_CTRL);
53         out_be32(&fbcs->csmr1, CFG_SYS_CS1_MASK);
54 #endif
55
56 #if (defined(CFG_SYS_CS2_BASE) && defined(CFG_SYS_CS2_MASK) \
57      && defined(CFG_SYS_CS2_CTRL))
58         out_be32(&fbcs->csar2, CFG_SYS_CS2_BASE);
59         out_be32(&fbcs->cscr2, CFG_SYS_CS2_CTRL);
60         out_be32(&fbcs->csmr2, CFG_SYS_CS2_MASK);
61 #endif
62
63 #if (defined(CFG_SYS_CS3_BASE) && defined(CFG_SYS_CS3_MASK) \
64      && defined(CFG_SYS_CS3_CTRL))
65         out_be32(&fbcs->csar3, CFG_SYS_CS3_BASE);
66         out_be32(&fbcs->cscr3, CFG_SYS_CS3_CTRL);
67         out_be32(&fbcs->csmr3, CFG_SYS_CS3_MASK);
68 #endif
69
70 #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
71      && defined(CONFIG_SYS_CS4_CTRL))
72         setbits_8(&gpio->par_cs, GPIO_PAR_CS4);
73         out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
74         out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
75         out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
76 #endif
77
78 #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
79      && defined(CONFIG_SYS_CS5_CTRL))
80         setbits_8(&gpio->par_cs, GPIO_PAR_CS5);
81         out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
82         out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
83         out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
84 #endif
85
86 #ifdef CONFIG_SYS_I2C_FSL
87         out_8(&gpio->par_feci2c,
88                 GPIO_PAR_FECI2C_SDA_SDA | GPIO_PAR_FECI2C_SCL_SCL);
89 #endif
90
91         icache_enable();
92 }
93
94 /* initialize higher level parts of CPU like timers */
95 int cpu_init_r(void)
96 {
97 #ifdef CONFIG_MCFFEC
98         u32 fec_mii_base0, fec_mii_base1;
99         ccm_t *ccm = (ccm_t *) MMAP_CCM;
100 #endif
101 #ifdef CONFIG_MCFRTC
102         rtc_t *rtc = (rtc_t *) (CONFIG_SYS_MCFRTC_BASE);
103         rtcex_t *rtcex = (rtcex_t *) &rtc->extended;
104
105         out_be32(&rtcex->gocu, CFG_SYS_RTC_CNT);
106         out_be32(&rtcex->gocl, CFG_SYS_RTC_SETUP);
107
108 #endif
109 #ifdef CONFIG_MCFFEC
110         fec_get_mii_base(0, &fec_mii_base0);
111         fec_get_mii_base(1, &fec_mii_base1);
112
113         if (fec_mii_base0 != fec_mii_base1)
114                 setbits_be16(&ccm->misccr, CCM_MISCCR_FECM);
115         else
116                 clrbits_be16(&ccm->misccr, CCM_MISCCR_FECM);
117 #endif
118
119         return (0);
120 }
121
122 void uart_port_conf(int port)
123 {
124         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
125
126         /* Setup Ports: */
127         switch (port) {
128         case 0:
129                 clrbits_8(&gpio->par_uart,
130                         GPIO_PAR_UART_U0TXD | GPIO_PAR_UART_U0RXD);
131                 setbits_8(&gpio->par_uart,
132                         GPIO_PAR_UART_U0TXD | GPIO_PAR_UART_U0RXD);
133                 break;
134         case 1:
135 #ifdef CONFIG_SYS_UART1_ALT1_GPIO
136                 clrbits_8(&gpio->par_simp1h,
137                         GPIO_PAR_SIMP1H_DATA1_UNMASK |
138                         GPIO_PAR_SIMP1H_VEN1_UNMASK);
139                 setbits_8(&gpio->par_simp1h,
140                         GPIO_PAR_SIMP1H_DATA1_U1TXD |
141                         GPIO_PAR_SIMP1H_VEN1_U1RXD);
142 #elif defined(CONFIG_SYS_UART1_ALT2_GPIO)
143                 clrbits_8(&gpio->par_ssih,
144                         GPIO_PAR_SSIH_RXD_UNMASK |
145                         GPIO_PAR_SSIH_TXD_UNMASK);
146                 setbits_8(&gpio->par_ssih,
147                         GPIO_PAR_SSIH_RXD_U1RXD |
148                         GPIO_PAR_SSIH_TXD_U1TXD);
149 #endif
150                 break;
151         case 2:
152 #ifdef CONFIG_SYS_UART2_PRI_GPIO
153                 setbits_8(&gpio->par_uart,
154                         GPIO_PAR_UART_U2TXD |
155                         GPIO_PAR_UART_U2RXD);
156 #elif defined(CONFIG_SYS_UART2_ALT1_GPIO)
157                 clrbits_8(&gpio->par_dspih,
158                         GPIO_PAR_DSPIH_SIN_UNMASK |
159                         GPIO_PAR_DSPIH_SOUT_UNMASK);
160                 setbits_8(&gpio->par_dspih,
161                         GPIO_PAR_DSPIH_SIN_U2RXD |
162                         GPIO_PAR_DSPIH_SOUT_U2TXD);
163 #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
164                 clrbits_8(&gpio->par_feci2c,
165                         GPIO_PAR_FECI2C_SDA_UNMASK |
166                         GPIO_PAR_FECI2C_SCL_UNMASK);
167                 setbits_8(&gpio->par_feci2c,
168                         GPIO_PAR_FECI2C_SDA_U2TXD |
169                         GPIO_PAR_FECI2C_SCL_U2RXD);
170 #endif
171                 break;
172         }
173 }
174
175 #if defined(CONFIG_CMD_NET)
176 int fecpin_setclear(fec_info_t *info, int setclear)
177 {
178         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
179         u32 fec0_base;
180
181         if (fec_get_base_addr(0, &fec0_base))
182                 return -1;
183
184         if (setclear) {
185                 if (info->iobase == fec0_base) {
186                         setbits_8(&gpio->par_fec,
187                                 GPIO_PAR_FEC0_7W_FEC | GPIO_PAR_FEC0_RMII_FEC);
188                         setbits_8(&gpio->par_feci2c,
189                                 GPIO_PAR_FECI2C_MDC0 | GPIO_PAR_FECI2C_MDIO0);
190                 } else {
191                         setbits_8(&gpio->par_fec,
192                                 GPIO_PAR_FEC1_7W_FEC | GPIO_PAR_FEC1_RMII_FEC);
193                         setbits_8(&gpio->par_feci2c,
194                                 GPIO_PAR_FECI2C_MDC1 | GPIO_PAR_FECI2C_MDIO1);
195                 }
196         } else {
197                 if (info->iobase == fec0_base) {
198                         clrbits_8(&gpio->par_fec,
199                                 GPIO_PAR_FEC0_7W_FEC | GPIO_PAR_FEC0_RMII_FEC);
200                         clrbits_8(&gpio->par_feci2c, ~GPIO_PAR_FECI2C_RMII0_UNMASK);
201                 } else {
202                         clrbits_8(&gpio->par_fec,
203                                 GPIO_PAR_FEC1_7W_FEC | GPIO_PAR_FEC1_RMII_FEC);
204                         clrbits_8(&gpio->par_feci2c, ~GPIO_PAR_FECI2C_RMII1_UNMASK);
205                 }
206         }
207         return 0;
208 }
209 #endif                          /* CONFIG_CMD_NET */
210 #endif                          /* CONFIG_MCF5301x */
211
212 #ifdef CONFIG_MCF532x
213 void cpu_init_f(void)
214 {
215         scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
216         scm2_t *scm2 = (scm2_t *) MMAP_SCM2;
217         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
218         fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
219 #ifndef CONFIG_WATCHDOG
220         wdog_t *wdog = (wdog_t *) MMAP_WDOG;
221
222         /* watchdog is enabled by default - disable the watchdog */
223         out_be16(&wdog->cr, 0);
224 #endif
225
226         out_be32(&scm1->mpr0, 0x77777777);
227         out_be32(&scm2->pacra, 0);
228         out_be32(&scm2->pacrb, 0);
229         out_be32(&scm2->pacrc, 0);
230         out_be32(&scm2->pacrd, 0);
231         out_be32(&scm2->pacre, 0);
232         out_be32(&scm2->pacrf, 0);
233         out_be32(&scm2->pacrg, 0);
234         out_be32(&scm1->pacrh, 0);
235
236         /* Port configuration */
237         out_8(&gpio->par_cs, 0);
238
239 #if (defined(CFG_SYS_CS0_BASE) && defined(CFG_SYS_CS0_MASK) \
240      && defined(CFG_SYS_CS0_CTRL))
241         out_be32(&fbcs->csar0, CFG_SYS_CS0_BASE);
242         out_be32(&fbcs->cscr0, CFG_SYS_CS0_CTRL);
243         out_be32(&fbcs->csmr0, CFG_SYS_CS0_MASK);
244 #endif
245
246 #if (defined(CFG_SYS_CS1_BASE) && defined(CFG_SYS_CS1_MASK) \
247      && defined(CFG_SYS_CS1_CTRL))
248         /* Latch chipselect */
249         setbits_8(&gpio->par_cs, GPIO_PAR_CS1);
250         out_be32(&fbcs->csar1, CFG_SYS_CS1_BASE);
251         out_be32(&fbcs->cscr1, CFG_SYS_CS1_CTRL);
252         out_be32(&fbcs->csmr1, CFG_SYS_CS1_MASK);
253 #endif
254
255 #if (defined(CFG_SYS_CS2_BASE) && defined(CFG_SYS_CS2_MASK) \
256      && defined(CFG_SYS_CS2_CTRL))
257         setbits_8(&gpio->par_cs, GPIO_PAR_CS2);
258         out_be32(&fbcs->csar2, CFG_SYS_CS2_BASE);
259         out_be32(&fbcs->cscr2, CFG_SYS_CS2_CTRL);
260         out_be32(&fbcs->csmr2, CFG_SYS_CS2_MASK);
261 #endif
262
263 #if (defined(CFG_SYS_CS3_BASE) && defined(CFG_SYS_CS3_MASK) \
264      && defined(CFG_SYS_CS3_CTRL))
265         setbits_8(&gpio->par_cs, GPIO_PAR_CS3);
266         out_be32(&fbcs->csar3, CFG_SYS_CS3_BASE);
267         out_be32(&fbcs->cscr3, CFG_SYS_CS3_CTRL);
268         out_be32(&fbcs->csmr3, CFG_SYS_CS3_MASK);
269 #endif
270
271 #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
272      && defined(CONFIG_SYS_CS4_CTRL))
273         setbits_8(&gpio->par_cs, GPIO_PAR_CS4);
274         out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
275         out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
276         out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
277 #endif
278
279 #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
280      && defined(CONFIG_SYS_CS5_CTRL))
281         setbits_8(&gpio->par_cs, GPIO_PAR_CS5);
282         out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
283         out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
284         out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
285 #endif
286
287 #ifdef CONFIG_SYS_I2C_FSL
288         out_8(&gpio->par_feci2c,
289                 GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
290 #endif
291
292         icache_enable();
293 }
294
295 /*
296  * initialize higher level parts of CPU like timers
297  */
298 int cpu_init_r(void)
299 {
300         return (0);
301 }
302
303 void uart_port_conf(int port)
304 {
305         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
306
307         /* Setup Ports: */
308         switch (port) {
309         case 0:
310                 clrbits_be16(&gpio->par_uart,
311                         GPIO_PAR_UART_TXD0 | GPIO_PAR_UART_RXD0);
312                 setbits_be16(&gpio->par_uart,
313                         GPIO_PAR_UART_TXD0 | GPIO_PAR_UART_RXD0);
314                 break;
315         case 1:
316                 clrbits_be16(&gpio->par_uart,
317                         GPIO_PAR_UART_TXD1(3) | GPIO_PAR_UART_RXD1(3));
318                 setbits_be16(&gpio->par_uart,
319                         GPIO_PAR_UART_TXD1(3) | GPIO_PAR_UART_RXD1(3));
320                 break;
321         case 2:
322 #ifdef CONFIG_SYS_UART2_ALT1_GPIO
323                 clrbits_8(&gpio->par_timer, 0xf0);
324                 setbits_8(&gpio->par_timer,
325                         GPIO_PAR_TIN3_URXD2 | GPIO_PAR_TIN2_UTXD2);
326 #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
327                 clrbits_8(&gpio->par_feci2c, 0x00ff);
328                 setbits_8(&gpio->par_feci2c,
329                         GPIO_PAR_FECI2C_SCL_UTXD2 | GPIO_PAR_FECI2C_SDA_URXD2);
330 #elif defined(CFG_SYS_UART2_ALT3_GPIO)
331                 clrbits_be16(&gpio->par_ssi, 0x0f00);
332                 setbits_be16(&gpio->par_ssi,
333                         GPIO_PAR_SSI_RXD(2) | GPIO_PAR_SSI_TXD(2));
334 #endif
335                 break;
336         }
337 }
338
339 #if defined(CONFIG_CMD_NET)
340 int fecpin_setclear(fec_info_t *info, int setclear)
341 {
342         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
343
344         if (setclear) {
345                 setbits_8(&gpio->par_fec,
346                         GPIO_PAR_FEC_7W_FEC | GPIO_PAR_FEC_MII_FEC);
347                 setbits_8(&gpio->par_feci2c,
348                         GPIO_PAR_FECI2C_MDC_EMDC | GPIO_PAR_FECI2C_MDIO_EMDIO);
349         } else {
350                 clrbits_8(&gpio->par_fec,
351                         GPIO_PAR_FEC_7W_FEC | GPIO_PAR_FEC_MII_FEC);
352                 clrbits_8(&gpio->par_feci2c,
353                         GPIO_PAR_FECI2C_MDC_EMDC | GPIO_PAR_FECI2C_MDIO_EMDIO);
354         }
355         return 0;
356 }
357 #endif
358 #endif                          /* CONFIG_MCF532x */