Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 2 | /* |
| 3 | * |
| 4 | * (C) Copyright 2000-2003 |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 6 | * |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 7 | * (C) Copyright 2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 8 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 12 | #include <cpu_func.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 13 | #include <init.h> |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 14 | #include <watchdog.h> |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 15 | #include <asm/immap.h> |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 16 | #include <asm/io.h> |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 17 | |
TsiChung Liew | 69b1757 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 18 | #if defined(CONFIG_CMD_NET) |
| 19 | #include <config.h> |
| 20 | #include <net.h> |
| 21 | #include <asm/fec.h> |
| 22 | #endif |
| 23 | |
Vasili Galka | 4834c64 | 2014-06-30 12:59:41 +0300 | [diff] [blame] | 24 | /* The registers in fbcs_t struct can be 16-bit for CONFIG_M5235 or 32-bit wide otherwise. */ |
| 25 | #ifdef CONFIG_M5235 |
| 26 | #define out_be_fbcs_reg out_be16 |
| 27 | #else |
| 28 | #define out_be_fbcs_reg out_be32 |
| 29 | #endif |
| 30 | |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 31 | /* |
| 32 | * Breath some life into the CPU... |
| 33 | * |
| 34 | * Set up the memory map, |
| 35 | * initialize a bunch of registers, |
| 36 | * initialize the UPM's |
| 37 | */ |
| 38 | void cpu_init_f(void) |
| 39 | { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 40 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
| 41 | fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS; |
| 42 | wdog_t *wdog = (wdog_t *) MMAP_WDOG; |
| 43 | scm_t *scm = (scm_t *) MMAP_SCM; |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 44 | |
| 45 | /* watchdog is enabled by default - disable the watchdog */ |
| 46 | #ifndef CONFIG_WATCHDOG |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 47 | out_be16(&wdog->cr, 0); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 48 | #endif |
| 49 | |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 50 | out_be32(&scm->rambar, CONFIG_SYS_INIT_RAM_ADDR | SCM_RAMBAR_BDE); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 51 | |
| 52 | /* Port configuration */ |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 53 | out_8(&gpio->par_cs, 0); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 54 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 55 | #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL)) |
Vasili Galka | 4834c64 | 2014-06-30 12:59:41 +0300 | [diff] [blame] | 56 | out_be_fbcs_reg(&fbcs->csar0, CONFIG_SYS_CS0_BASE); |
| 57 | out_be_fbcs_reg(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 58 | out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 59 | #endif |
| 60 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 61 | #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL)) |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 62 | setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS1); |
Vasili Galka | 4834c64 | 2014-06-30 12:59:41 +0300 | [diff] [blame] | 63 | out_be_fbcs_reg(&fbcs->csar1, CONFIG_SYS_CS1_BASE); |
| 64 | out_be_fbcs_reg(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 65 | out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 66 | #endif |
| 67 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 68 | #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL)) |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 69 | setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS2); |
Vasili Galka | 4834c64 | 2014-06-30 12:59:41 +0300 | [diff] [blame] | 70 | out_be_fbcs_reg(&fbcs->csar2, CONFIG_SYS_CS2_BASE); |
| 71 | out_be_fbcs_reg(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 72 | out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 73 | #endif |
| 74 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 75 | #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL)) |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 76 | setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS3); |
Vasili Galka | 4834c64 | 2014-06-30 12:59:41 +0300 | [diff] [blame] | 77 | out_be_fbcs_reg(&fbcs->csar3, CONFIG_SYS_CS3_BASE); |
| 78 | out_be_fbcs_reg(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 79 | out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 80 | #endif |
| 81 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 82 | #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL)) |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 83 | setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS4); |
Vasili Galka | 4834c64 | 2014-06-30 12:59:41 +0300 | [diff] [blame] | 84 | out_be_fbcs_reg(&fbcs->csar4, CONFIG_SYS_CS4_BASE); |
| 85 | out_be_fbcs_reg(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 86 | out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 87 | #endif |
| 88 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 89 | #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL)) |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 90 | setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS5); |
Vasili Galka | 4834c64 | 2014-06-30 12:59:41 +0300 | [diff] [blame] | 91 | out_be_fbcs_reg(&fbcs->csar5, CONFIG_SYS_CS5_BASE); |
| 92 | out_be_fbcs_reg(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 93 | out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 94 | #endif |
| 95 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 96 | #if (defined(CONFIG_SYS_CS6_BASE) && defined(CONFIG_SYS_CS6_MASK) && defined(CONFIG_SYS_CS6_CTRL)) |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 97 | setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS6); |
Vasili Galka | 4834c64 | 2014-06-30 12:59:41 +0300 | [diff] [blame] | 98 | out_be_fbcs_reg(&fbcs->csar6, CONFIG_SYS_CS6_BASE); |
| 99 | out_be_fbcs_reg(&fbcs->cscr6, CONFIG_SYS_CS6_CTRL); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 100 | out_be32(&fbcs->csmr6, CONFIG_SYS_CS6_MASK); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 101 | #endif |
| 102 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 103 | #if (defined(CONFIG_SYS_CS7_BASE) && defined(CONFIG_SYS_CS7_MASK) && defined(CONFIG_SYS_CS7_CTRL)) |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 104 | setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS7); |
Vasili Galka | 4834c64 | 2014-06-30 12:59:41 +0300 | [diff] [blame] | 105 | out_be_fbcs_reg(&fbcs->csar7, CONFIG_SYS_CS7_BASE); |
| 106 | out_be_fbcs_reg(&fbcs->cscr7, CONFIG_SYS_CS7_CTRL); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 107 | out_be32(&fbcs->csmr7, CONFIG_SYS_CS7_MASK); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 108 | #endif |
| 109 | |
Heiko Schocher | f285074 | 2012-10-24 13:48:22 +0200 | [diff] [blame] | 110 | #ifdef CONFIG_SYS_I2C_FSL |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 111 | CONFIG_SYS_I2C_PINMUX_REG &= CONFIG_SYS_I2C_PINMUX_CLR; |
| 112 | CONFIG_SYS_I2C_PINMUX_REG |= CONFIG_SYS_I2C_PINMUX_SET; |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | icache_enable(); |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * initialize higher level parts of CPU like timers |
| 120 | */ |
| 121 | int cpu_init_r(void) |
| 122 | { |
| 123 | return (0); |
| 124 | } |
| 125 | |
TsiChung Liew | f9556a7 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 126 | void uart_port_conf(int port) |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 127 | { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 128 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 129 | |
Stefan Roese | fe9dae6 | 2007-08-18 14:33:02 +0200 | [diff] [blame] | 130 | /* Setup Ports: */ |
TsiChung Liew | f9556a7 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 131 | switch (port) { |
Stefan Roese | fe9dae6 | 2007-08-18 14:33:02 +0200 | [diff] [blame] | 132 | case 0: |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 133 | clrbits_be16(&gpio->par_uart, |
| 134 | GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD); |
| 135 | setbits_be16(&gpio->par_uart, |
| 136 | GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD); |
Stefan Roese | fe9dae6 | 2007-08-18 14:33:02 +0200 | [diff] [blame] | 137 | break; |
| 138 | case 1: |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 139 | clrbits_be16(&gpio->par_uart, |
| 140 | GPIO_PAR_UART_U1RXD_MASK | GPIO_PAR_UART_U1TXD_MASK); |
| 141 | setbits_be16(&gpio->par_uart, |
| 142 | GPIO_PAR_UART_U1RXD_U1RXD | GPIO_PAR_UART_U1TXD_U1TXD); |
Stefan Roese | fe9dae6 | 2007-08-18 14:33:02 +0200 | [diff] [blame] | 143 | break; |
| 144 | case 2: |
TsiChung Liew | f9556a7 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 145 | #ifdef CONFIG_SYS_UART2_PRI_GPIO |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 146 | clrbits_be16(&gpio->par_uart, |
| 147 | GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD); |
| 148 | setbits_be16(&gpio->par_uart, |
| 149 | GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD); |
TsiChung Liew | f9556a7 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 150 | #elif defined(CONFIG_SYS_UART2_ALT1_GPIO) |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 151 | clrbits_8(&gpio->par_feci2c, |
| 152 | GPIO_PAR_FECI2C_EMDC_MASK | GPIO_PAR_FECI2C_EMDIO_MASK); |
| 153 | setbits_8(&gpio->par_feci2c, |
| 154 | GPIO_PAR_FECI2C_EMDC_U2TXD | GPIO_PAR_FECI2C_EMDIO_U2RXD); |
TsiChung Liew | f9556a7 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 155 | #endif |
Stefan Roese | fe9dae6 | 2007-08-18 14:33:02 +0200 | [diff] [blame] | 156 | break; |
| 157 | } |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 158 | } |
TsiChung Liew | 69b1757 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 159 | |
| 160 | #if defined(CONFIG_CMD_NET) |
Angelo Durgehello | 8ff47f7 | 2019-11-15 23:54:16 +0100 | [diff] [blame] | 161 | int fecpin_setclear(fec_info_t *info, int setclear) |
TsiChung Liew | 69b1757 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 162 | { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 163 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChung Liew | 69b1757 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 164 | |
| 165 | if (setclear) { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 166 | setbits_8(&gpio->par_feci2c, |
| 167 | GPIO_PAR_FECI2C_EMDC_FECEMDC | |
| 168 | GPIO_PAR_FECI2C_EMDIO_FECEMDIO); |
TsiChung Liew | 69b1757 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 169 | } else { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 170 | clrbits_8(&gpio->par_feci2c, |
| 171 | GPIO_PAR_FECI2C_EMDC_MASK | |
| 172 | GPIO_PAR_FECI2C_EMDIO_MASK); |
TsiChung Liew | 69b1757 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | #endif |