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