Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / m68k / cpu / mcf5445x / 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-2007, 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/processor.h>
17 #include <asm/rtc.h>
18 #include <asm/io.h>
19 #include <linux/compiler.h>
20
21 #if defined(CONFIG_CMD_NET)
22 #include <config.h>
23 #include <net.h>
24 #include <asm/fec.h>
25 #endif
26
27 void init_fbcs(void)
28 {
29         fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
30
31 #if !defined(CONFIG_SERIAL_BOOT)
32 #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
33         out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
34         out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
35         out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
36 #endif
37 #endif
38
39 #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
40         /* Latch chipselect */
41         out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
42         out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
43         out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
44 #endif
45
46 #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
47         out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
48         out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
49         out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
50 #endif
51
52 #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
53         out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
54         out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
55         out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
56 #endif
57
58 #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
59         out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
60         out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
61         out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
62 #endif
63
64 #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
65         out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
66         out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
67         out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
68 #endif
69 }
70
71 #ifdef CONFIG_CF_DSPI
72 void cfspi_port_conf(void)
73 {
74         gpio_t *gpio = (gpio_t *)MMAP_GPIO;
75
76 #ifdef CONFIG_MCF5445x
77         out_8(&gpio->par_dspi,
78               GPIO_PAR_DSPI_SIN_SIN |
79               GPIO_PAR_DSPI_SOUT_SOUT |
80               GPIO_PAR_DSPI_SCK_SCK);
81 #endif
82
83 #ifdef CONFIG_MCF5441x
84         pm_t *pm = (pm_t *)MMAP_PM;
85
86         out_8(&gpio->par_dspi0,
87               GPIO_PAR_DSPI0_SIN_DSPI0SIN | GPIO_PAR_DSPI0_SOUT_DSPI0SOUT |
88               GPIO_PAR_DSPI0_SCK_DSPI0SCK);
89         out_8(&gpio->srcr_dspiow, 3);
90
91         /* DSPI0 */
92         out_8(&pm->pmcr0, 23);
93 #endif
94 }
95 #endif
96
97 /*
98  * Breath some life into the CPU...
99  *
100  * Set up the memory map,
101  * initialize a bunch of registers,
102  * initialize the UPM's
103  */
104 void cpu_init_f(void)
105 {
106         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
107
108 #ifdef CONFIG_MCF5441x
109         scm_t *scm = (scm_t *) MMAP_SCM;
110         pm_t *pm = (pm_t *) MMAP_PM;
111
112         /* Disable Switch */
113         *(unsigned long *)(MMAP_L2_SW0 + 0x00000024) = 0;
114
115         /* Disable core watchdog */
116         out_be16(&scm->cwcr, 0);
117         out_8(&gpio->par_fbctl,
118                 GPIO_PAR_FBCTL_ALE_FB_ALE | GPIO_PAR_FBCTL_OE_FB_OE |
119                 GPIO_PAR_FBCTL_FBCLK | GPIO_PAR_FBCTL_RW |
120                 GPIO_PAR_FBCTL_TA_TA);
121         out_8(&gpio->par_be,
122                 GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
123                 GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
124
125         /* eDMA */
126         out_8(&pm->pmcr0, 17);
127
128         /* INTR0 - INTR2 */
129         out_8(&pm->pmcr0, 18);
130         out_8(&pm->pmcr0, 19);
131         out_8(&pm->pmcr0, 20);
132
133         /* I2C */
134         out_8(&pm->pmcr0, 22);
135         out_8(&pm->pmcr1, 4);
136         out_8(&pm->pmcr1, 7);
137
138         /* DTMR0 - DTMR3*/
139         out_8(&pm->pmcr0, 28);
140         out_8(&pm->pmcr0, 29);
141         out_8(&pm->pmcr0, 30);
142         out_8(&pm->pmcr0, 31);
143
144         /* PIT0 - PIT3 */
145         out_8(&pm->pmcr0, 32);
146         out_8(&pm->pmcr0, 33);
147         out_8(&pm->pmcr0, 34);
148         out_8(&pm->pmcr0, 35);
149
150         /* Edge Port */
151         out_8(&pm->pmcr0, 36);
152         out_8(&pm->pmcr0, 37);
153
154         /* USB OTG */
155         out_8(&pm->pmcr0, 44);
156         /* USB Host */
157         out_8(&pm->pmcr0, 45);
158
159         /* ESDHC */
160         out_8(&pm->pmcr0, 51);
161
162         /* ENET0 - ENET1 */
163         out_8(&pm->pmcr0, 53);
164         out_8(&pm->pmcr0, 54);
165
166         /* NAND */
167         out_8(&pm->pmcr0, 63);
168
169 #ifdef CONFIG_SYS_I2C_0
170         out_8(&gpio->par_cani2c, 0xF0);
171         /* I2C0 pull up */
172         out_be16(&gpio->pcr_b, 0x003C);
173         /* I2C0 max speed */
174         out_8(&gpio->srcr_cani2c, 0x03);
175 #endif
176 #ifdef CONFIG_SYS_I2C_2
177         /* I2C2 */
178         out_8(&gpio->par_ssi0h, 0xA0);
179         /* I2C2, UART7 */
180         out_8(&gpio->par_ssi0h, 0xA8);
181         /* UART7 */
182         out_8(&gpio->par_ssi0l, 0x2);
183         /* UART8, UART9 */
184         out_8(&gpio->par_cani2c, 0xAA);
185         /* UART4, UART0 */
186         out_8(&gpio->par_uart0, 0xAF);
187         /* UART5, UART1 */
188         out_8(&gpio->par_uart1, 0xAF);
189         /* UART6, UART2 */
190         out_8(&gpio->par_uart2, 0xAF);
191         /* I2C2 pull up */
192         out_be16(&gpio->pcr_h, 0xF000);
193 #endif
194 #ifdef CONFIG_SYS_I2C_5
195         /* I2C5 */
196         out_8(&gpio->par_uart1, 0x0A);
197         /* I2C5 pull up */
198         out_be16(&gpio->pcr_e, 0x0003);
199         out_be16(&gpio->pcr_f, 0xC000);
200 #endif
201
202         /* Lowest slew rate for UART0,1,2 */
203         out_8(&gpio->srcr_uart, 0x00);
204
205 #ifdef CONFIG_FSL_ESDHC_IMX
206         /* eSDHC pin as faster speed */
207         out_8(&gpio->srcr_sdhc, 0x03);
208
209         /* All esdhc pins as SD */
210         out_8(&gpio->par_sdhch, 0xff);
211         out_8(&gpio->par_sdhcl, 0xff);
212 #endif
213 #endif          /* CONFIG_MCF5441x */
214
215 #ifdef CONFIG_MCF5445x
216         scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
217
218         out_be32(&scm1->mpr, 0x77777777);
219         out_be32(&scm1->pacra, 0);
220         out_be32(&scm1->pacrb, 0);
221         out_be32(&scm1->pacrc, 0);
222         out_be32(&scm1->pacrd, 0);
223         out_be32(&scm1->pacre, 0);
224         out_be32(&scm1->pacrf, 0);
225         out_be32(&scm1->pacrg, 0);
226
227         /* FlexBus */
228         out_8(&gpio->par_be,
229                 GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
230                 GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
231         out_8(&gpio->par_fbctl,
232                 GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA |
233                 GPIO_PAR_FBCTL_RW_RW | GPIO_PAR_FBCTL_TS_TS);
234
235 #ifdef CONFIG_CF_SPI
236         cfspi_port_conf();
237 #endif
238
239 #ifdef CONFIG_SYS_FSL_I2C
240         out_be16(&gpio->par_feci2c,
241                 GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
242 #endif
243 #endif          /* CONFIG_MCF5445x */
244
245         /* FlexBus Chipselect */
246         init_fbcs();
247
248 #ifdef CONFIG_SYS_CS0_BASE
249         /*
250          * now the flash base address is no longer at 0 (Newer ColdFire family
251          * boot at address 0 instead of 0xFFnn_nnnn). The vector table must
252          * also move to the new location.
253          */
254         if (CONFIG_SYS_CS0_BASE != 0)
255                 setvbr(CONFIG_SYS_CS0_BASE);
256 #endif
257
258         icache_enable();
259 }
260
261 /*
262  * initialize higher level parts of CPU like timers
263  */
264 int cpu_init_r(void)
265 {
266 #ifdef CONFIG_MCFRTC
267         rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
268         rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
269
270         out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
271         out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
272 #endif
273
274         return (0);
275 }
276
277 void uart_port_conf(int port)
278 {
279         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
280 #ifdef CONFIG_MCF5441x
281         pm_t *pm = (pm_t *) MMAP_PM;
282 #endif
283
284         /* Setup Ports: */
285         switch (port) {
286 #ifdef CONFIG_MCF5441x
287         case 0:
288                 /* UART0 */
289                 out_8(&pm->pmcr0, 24);
290                 clrbits_8(&gpio->par_uart0,
291                         ~(GPIO_PAR_UART0_U0RXD_MASK | GPIO_PAR_UART0_U0TXD_MASK));
292                 setbits_8(&gpio->par_uart0,
293                         GPIO_PAR_UART0_U0RXD_U0RXD | GPIO_PAR_UART0_U0TXD_U0TXD);
294                 break;
295         case 1:
296                 /* UART1 */
297                 out_8(&pm->pmcr0, 25);
298                 clrbits_8(&gpio->par_uart1,
299                         ~(GPIO_PAR_UART1_U1RXD_MASK | GPIO_PAR_UART1_U1TXD_MASK));
300                 setbits_8(&gpio->par_uart1,
301                         GPIO_PAR_UART1_U1RXD_U1RXD | GPIO_PAR_UART1_U1TXD_U1TXD);
302                 break;
303         case 2:
304                 /* UART2 */
305                 out_8(&pm->pmcr0, 26);
306                 clrbits_8(&gpio->par_uart2,
307                         ~(GPIO_PAR_UART2_U2RXD_MASK | GPIO_PAR_UART2_U2TXD_MASK));
308                 setbits_8(&gpio->par_uart2,
309                         GPIO_PAR_UART2_U2RXD_U2RXD | GPIO_PAR_UART2_U2TXD_U2TXD);
310                 break;
311         case 3:
312                 /* UART3 */
313                 out_8(&pm->pmcr0, 27);
314                 clrbits_8(&gpio->par_dspi0,
315                         ~(GPIO_PAR_DSPI0_SIN_MASK | GPIO_PAR_DSPI0_SOUT_MASK));
316                 setbits_8(&gpio->par_dspi0,
317                         GPIO_PAR_DSPI0_SIN_U3RXD | GPIO_PAR_DSPI0_SOUT_U3TXD);
318                 break;
319         case 4:
320                 /* UART4 */
321                 out_8(&pm->pmcr1, 24);
322                 clrbits_8(&gpio->par_uart0,
323                         ~(GPIO_PAR_UART0_U0CTS_MASK | GPIO_PAR_UART0_U0RTS_MASK));
324                 setbits_8(&gpio->par_uart0,
325                         GPIO_PAR_UART0_U0CTS_U4TXD | GPIO_PAR_UART0_U0RTS_U4RXD);
326                 break;
327         case 5:
328                 /* UART5 */
329                 out_8(&pm->pmcr1, 25);
330                 clrbits_8(&gpio->par_uart1,
331                         ~(GPIO_PAR_UART1_U1CTS_MASK | GPIO_PAR_UART1_U1RTS_MASK));
332                 setbits_8(&gpio->par_uart1,
333                         GPIO_PAR_UART1_U1CTS_U5TXD | GPIO_PAR_UART1_U1RTS_U5RXD);
334                 break;
335         case 6:
336                 /* UART6 */
337                 out_8(&pm->pmcr1, 26);
338                 clrbits_8(&gpio->par_uart2,
339                         ~(GPIO_PAR_UART2_U2CTS_MASK | GPIO_PAR_UART2_U2RTS_MASK));
340                 setbits_8(&gpio->par_uart2,
341                         GPIO_PAR_UART2_U2CTS_U6TXD | GPIO_PAR_UART2_U2RTS_U6RXD);
342                 break;
343         case 7:
344                 /* UART7 */
345                 out_8(&pm->pmcr1, 27);
346                 clrbits_8(&gpio->par_ssi0h, ~GPIO_PAR_SSI0H_RXD_MASK);
347                 clrbits_8(&gpio->par_ssi0l, ~GPIO_PAR_SSI0L_BCLK_MASK);
348                 setbits_8(&gpio->par_ssi0h, GPIO_PAR_SSI0H_FS_U7TXD);
349                 setbits_8(&gpio->par_ssi0l, GPIO_PAR_SSI0L_BCLK_U7RXD);
350                 break;
351         case 8:
352                 /* UART8 */
353                 out_8(&pm->pmcr0, 28);
354                 clrbits_8(&gpio->par_cani2c,
355                         ~(GPIO_PAR_CANI2C_I2C0SCL_MASK | GPIO_PAR_CANI2C_I2C0SDA_MASK));
356                 setbits_8(&gpio->par_cani2c,
357                         GPIO_PAR_CANI2C_I2C0SCL_U8TXD | GPIO_PAR_CANI2C_I2C0SDA_U8RXD);
358                 break;
359         case 9:
360                 /* UART9 */
361                 out_8(&pm->pmcr1, 29);
362                 clrbits_8(&gpio->par_cani2c,
363                         ~(GPIO_PAR_CANI2C_CAN1TX_MASK | GPIO_PAR_CANI2C_CAN1RX_MASK));
364                 setbits_8(&gpio->par_cani2c,
365                         GPIO_PAR_CANI2C_CAN1TX_U9TXD | GPIO_PAR_CANI2C_CAN1RX_U9RXD);
366                 break;
367 #endif
368 #ifdef CONFIG_MCF5445x
369         case 0:
370                 clrbits_8(&gpio->par_uart,
371                         GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
372                 setbits_8(&gpio->par_uart,
373                         GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
374                 break;
375         case 1:
376 #ifdef CONFIG_SYS_UART1_PRI_GPIO
377                 clrbits_8(&gpio->par_uart,
378                         GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
379                 setbits_8(&gpio->par_uart,
380                         GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
381 #elif defined(CONFIG_SYS_UART1_ALT1_GPIO)
382                 clrbits_be16(&gpio->par_ssi,
383                         ~(GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK));
384                 setbits_be16(&gpio->par_ssi,
385                         GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD);
386 #endif
387                 break;
388         case 2:
389 #if defined(CONFIG_SYS_UART2_ALT1_GPIO)
390                 clrbits_8(&gpio->par_timer,
391                         ~(GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK));
392                 setbits_8(&gpio->par_timer,
393                         GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD);
394 #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
395                 clrbits_8(&gpio->par_timer,
396                         ~(GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK));
397                 setbits_8(&gpio->par_timer,
398                         GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD);
399 #endif
400                 break;
401 #endif  /* CONFIG_MCF5445x */
402         }
403 }
404
405 #if defined(CONFIG_CMD_NET)
406 int fecpin_setclear(fec_info_t *info, int setclear)
407 {
408         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
409         u32 fec0_base;
410
411         if (fec_get_base_addr(0, &fec0_base))
412                 return -1;
413
414 #ifdef CONFIG_MCF5445x
415         if (setclear) {
416 #ifdef CONFIG_SYS_FEC_NO_SHARED_PHY
417                 if (info->iobase == fec0_base)
418                         setbits_be16(&gpio->par_feci2c,
419                                 GPIO_PAR_FECI2C_MDC0_MDC0 |
420                                 GPIO_PAR_FECI2C_MDIO0_MDIO0);
421                 else
422                         setbits_be16(&gpio->par_feci2c,
423                                 GPIO_PAR_FECI2C_MDC1_MDC1 |
424                                 GPIO_PAR_FECI2C_MDIO1_MDIO1);
425 #else
426                 setbits_be16(&gpio->par_feci2c,
427                         GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
428 #endif
429
430                 if (info->iobase == fec0_base)
431                         setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO);
432                 else
433                         setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA);
434         } else {
435                 clrbits_be16(&gpio->par_feci2c,
436                         GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
437
438                 if (info->iobase == fec0_base) {
439 #ifdef CONFIG_SYS_FEC_FULL_MII
440                         setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII);
441 #else
442                         clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC0_UNMASK);
443 #endif
444                 } else {
445 #ifdef CONFIG_SYS_FEC_FULL_MII
446                         setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_MII);
447 #else
448                         clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC1_UNMASK);
449 #endif
450                 }
451         }
452 #endif  /* CONFIG_MCF5445x */
453
454 #ifdef CONFIG_MCF5441x
455         if (setclear) {
456                 out_8(&gpio->par_fec, 0x03);
457                 out_8(&gpio->srcr_fec, 0x0F);
458                 clrsetbits_8(&gpio->par_simp0h, ~GPIO_PAR_SIMP0H_DAT_MASK,
459                         GPIO_PAR_SIMP0H_DAT_GPIO);
460                 clrsetbits_8(&gpio->pddr_g, ~GPIO_PDDR_G4_MASK,
461                         GPIO_PDDR_G4_OUTPUT);
462                 clrbits_8(&gpio->podr_g, ~GPIO_PODR_G4_MASK);
463
464         } else
465                 clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC_MASK);
466 #endif
467         return 0;
468 }
469 #endif