Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010,2011 |
| 3 | * NVIDIA Corporation <www.nvidia.com> |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <asm/io.h> |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 26 | #include <asm/arch/clock.h> |
| 27 | #include <asm/arch/funcmux.h> |
Tom Warren | 150c249 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 28 | #include <asm/arch/tegra.h> |
Lucas Stach | 516f00b | 2012-09-29 10:02:08 +0000 | [diff] [blame] | 29 | #include <asm/arch-tegra/board.h> |
Tom Warren | 150c249 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 30 | #include <asm/arch-tegra/pmc.h> |
| 31 | #include <asm/arch-tegra/sys_proto.h> |
| 32 | #include <asm/arch-tegra/warmboot.h> |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 36 | enum { |
| 37 | /* UARTs which we can enable */ |
| 38 | UARTA = 1 << 0, |
| 39 | UARTB = 1 << 1, |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 40 | UARTC = 1 << 2, |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 41 | UARTD = 1 << 3, |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 42 | UARTE = 1 << 4, |
| 43 | UART_COUNT = 5, |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 46 | /* |
| 47 | * Boot ROM initializes the odmdata in APBDEV_PMC_SCRATCH20_0, |
| 48 | * so we are using this value to identify memory size. |
| 49 | */ |
| 50 | |
| 51 | unsigned int query_sdram_size(void) |
| 52 | { |
Tom Warren | 29f3e3f | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 53 | struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE; |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 54 | u32 reg; |
| 55 | |
| 56 | reg = readl(&pmc->pmc_scratch20); |
Marek Vasut | 4a34af7 | 2011-10-24 23:41:39 +0000 | [diff] [blame] | 57 | debug("pmc->pmc_scratch20 (ODMData) = 0x%08x\n", reg); |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 58 | |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 59 | #if defined(CONFIG_TEGRA20) |
| 60 | /* bits 30:28 in OdmData are used for RAM size on T20 */ |
| 61 | reg &= 0x70000000; |
| 62 | |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 63 | switch ((reg) >> 28) { |
| 64 | case 1: |
| 65 | return 0x10000000; /* 256 MB */ |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 66 | case 0: |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 67 | case 2: |
Stephen Warren | 9057e65 | 2012-01-06 12:14:41 +0000 | [diff] [blame] | 68 | default: |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 69 | return 0x20000000; /* 512 MB */ |
| 70 | case 3: |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 71 | return 0x40000000; /* 1GB */ |
| 72 | } |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 73 | #else /* Tegra30/Tegra114 */ |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 74 | /* bits 31:28 in OdmData are used for RAM size on T30 */ |
| 75 | switch ((reg) >> 28) { |
| 76 | case 0: |
| 77 | case 1: |
| 78 | default: |
| 79 | return 0x10000000; /* 256 MB */ |
| 80 | case 2: |
| 81 | return 0x20000000; /* 512 MB */ |
| 82 | case 3: |
| 83 | return 0x30000000; /* 768 MB */ |
| 84 | case 4: |
| 85 | return 0x40000000; /* 1GB */ |
| 86 | case 8: |
| 87 | return 0x7ff00000; /* 2GB - 1MB */ |
| 88 | } |
| 89 | #endif |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 92 | int dram_init(void) |
| 93 | { |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 94 | /* We do not initialise DRAM here. We just query the size */ |
Simon Glass | 7f8c070 | 2011-11-05 03:56:57 +0000 | [diff] [blame] | 95 | gd->ram_size = query_sdram_size(); |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | #ifdef CONFIG_DISPLAY_BOARDINFO |
| 100 | int checkboard(void) |
| 101 | { |
| 102 | printf("Board: %s\n", sysinfo.board_string); |
| 103 | return 0; |
| 104 | } |
| 105 | #endif /* CONFIG_DISPLAY_BOARDINFO */ |
Simon Glass | e43d6ed | 2011-11-05 03:56:49 +0000 | [diff] [blame] | 106 | |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 107 | static int uart_configs[] = { |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 108 | #if defined(CONFIG_TEGRA20) |
| 109 | #if defined(CONFIG_TEGRA_UARTA_UAA_UAB) |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 110 | FUNCMUX_UART1_UAA_UAB, |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 111 | #elif defined(CONFIG_TEGRA_UARTA_GPU) |
Stephen Warren | e21649b | 2012-05-16 05:59:59 +0000 | [diff] [blame] | 112 | FUNCMUX_UART1_GPU, |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 113 | #elif defined(CONFIG_TEGRA_UARTA_SDIO1) |
Lucas Stach | a2cfe63 | 2012-05-16 08:21:02 +0000 | [diff] [blame] | 114 | FUNCMUX_UART1_SDIO1, |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 115 | #else |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 116 | FUNCMUX_UART1_IRRX_IRTX, |
Stephen Warren | 4727a13 | 2013-01-22 06:20:08 +0000 | [diff] [blame] | 117 | #endif |
| 118 | FUNCMUX_UART2_UAD, |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 119 | -1, |
| 120 | FUNCMUX_UART4_GMC, |
| 121 | -1, |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 122 | #elif defined(CONFIG_TEGRA30) |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 123 | FUNCMUX_UART1_ULPI, /* UARTA */ |
| 124 | -1, |
| 125 | -1, |
| 126 | -1, |
| 127 | -1, |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 128 | #else /* Tegra114 */ |
| 129 | -1, |
| 130 | -1, |
| 131 | -1, |
| 132 | FUNCMUX_UART4_GMI, /* UARTD */ |
| 133 | -1, |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 134 | #endif |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 137 | /** |
| 138 | * Set up the specified uarts |
| 139 | * |
| 140 | * @param uarts_ids Mask containing UARTs to init (UARTx) |
| 141 | */ |
| 142 | static void setup_uarts(int uart_ids) |
| 143 | { |
| 144 | static enum periph_id id_for_uart[] = { |
| 145 | PERIPH_ID_UART1, |
| 146 | PERIPH_ID_UART2, |
| 147 | PERIPH_ID_UART3, |
| 148 | PERIPH_ID_UART4, |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 149 | PERIPH_ID_UART5, |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 150 | }; |
| 151 | size_t i; |
| 152 | |
| 153 | for (i = 0; i < UART_COUNT; i++) { |
| 154 | if (uart_ids & (1 << i)) { |
| 155 | enum periph_id id = id_for_uart[i]; |
| 156 | |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 157 | funcmux_select(id, uart_configs[i]); |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 158 | clock_ll_start_uart(id); |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void board_init_uart_f(void) |
| 164 | { |
| 165 | int uart_ids = 0; /* bit mask of which UART ids to enable */ |
| 166 | |
Tom Warren | 29f3e3f | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 167 | #ifdef CONFIG_TEGRA_ENABLE_UARTA |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 168 | uart_ids |= UARTA; |
| 169 | #endif |
Tom Warren | 29f3e3f | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 170 | #ifdef CONFIG_TEGRA_ENABLE_UARTB |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 171 | uart_ids |= UARTB; |
| 172 | #endif |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 173 | #ifdef CONFIG_TEGRA_ENABLE_UARTC |
| 174 | uart_ids |= UARTC; |
| 175 | #endif |
Tom Warren | 29f3e3f | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 176 | #ifdef CONFIG_TEGRA_ENABLE_UARTD |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 177 | uart_ids |= UARTD; |
| 178 | #endif |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 179 | #ifdef CONFIG_TEGRA_ENABLE_UARTE |
| 180 | uart_ids |= UARTE; |
| 181 | #endif |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 182 | setup_uarts(uart_ids); |
| 183 | } |
Simon Glass | bd29cb0 | 2012-01-09 13:22:15 +0000 | [diff] [blame] | 184 | |
| 185 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 186 | void enable_caches(void) |
| 187 | { |
| 188 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 189 | dcache_enable(); |
| 190 | } |
| 191 | #endif |