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