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