Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 1 | /* |
Tom Warren | e5ffffd | 2014-01-24 12:46:16 -0700 | [diff] [blame] | 2 | * (C) Copyright 2010-2014 |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 3 | * NVIDIA Corporation <www.nvidia.com> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <asm/io.h> |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 10 | #include <asm/arch/clock.h> |
| 11 | #include <asm/arch/funcmux.h> |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 12 | #include <asm/arch/tegra.h> |
Lucas Stach | e80f7ca | 2012-09-29 10:02:08 +0000 | [diff] [blame] | 13 | #include <asm/arch-tegra/board.h> |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 14 | #include <asm/arch-tegra/pmc.h> |
| 15 | #include <asm/arch-tegra/sys_proto.h> |
| 16 | #include <asm/arch-tegra/warmboot.h> |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 20 | enum { |
| 21 | /* UARTs which we can enable */ |
| 22 | UARTA = 1 << 0, |
| 23 | UARTB = 1 << 1, |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 24 | UARTC = 1 << 2, |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 25 | UARTD = 1 << 3, |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 26 | UARTE = 1 << 4, |
| 27 | UART_COUNT = 5, |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
Stephen Warren | 1b4af6b | 2014-07-02 14:12:30 -0600 | [diff] [blame^] | 30 | #if defined(CONFIG_TEGRA20) || defined(CONFIG_TEGRA30) || \ |
| 31 | defined(CONFIG_TEGRA114) |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 32 | /* |
| 33 | * Boot ROM initializes the odmdata in APBDEV_PMC_SCRATCH20_0, |
| 34 | * so we are using this value to identify memory size. |
| 35 | */ |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 36 | unsigned int query_sdram_size(void) |
| 37 | { |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 38 | struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE; |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 39 | u32 reg; |
| 40 | |
| 41 | reg = readl(&pmc->pmc_scratch20); |
Marek Vasut | 8148e11 | 2011-10-24 23:41:39 +0000 | [diff] [blame] | 42 | debug("pmc->pmc_scratch20 (ODMData) = 0x%08x\n", reg); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 43 | |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 44 | #if defined(CONFIG_TEGRA20) |
| 45 | /* bits 30:28 in OdmData are used for RAM size on T20 */ |
| 46 | reg &= 0x70000000; |
| 47 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 48 | switch ((reg) >> 28) { |
| 49 | case 1: |
| 50 | return 0x10000000; /* 256 MB */ |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 51 | case 0: |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 52 | case 2: |
Stephen Warren | b60fa39 | 2012-01-06 12:14:41 +0000 | [diff] [blame] | 53 | default: |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 54 | return 0x20000000; /* 512 MB */ |
| 55 | case 3: |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 56 | return 0x40000000; /* 1GB */ |
| 57 | } |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 58 | #else /* Tegra30/Tegra114 */ |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 59 | /* bits 31:28 in OdmData are used for RAM size on T30 */ |
| 60 | switch ((reg) >> 28) { |
| 61 | case 0: |
| 62 | case 1: |
| 63 | default: |
| 64 | return 0x10000000; /* 256 MB */ |
| 65 | case 2: |
| 66 | return 0x20000000; /* 512 MB */ |
| 67 | case 3: |
| 68 | return 0x30000000; /* 768 MB */ |
| 69 | case 4: |
| 70 | return 0x40000000; /* 1GB */ |
| 71 | case 8: |
| 72 | return 0x7ff00000; /* 2GB - 1MB */ |
| 73 | } |
| 74 | #endif |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 75 | } |
Stephen Warren | 1b4af6b | 2014-07-02 14:12:30 -0600 | [diff] [blame^] | 76 | #else |
| 77 | #include <asm/arch/mc.h> |
| 78 | |
| 79 | /* Read the RAM size directly from the memory controller */ |
| 80 | unsigned int query_sdram_size(void) |
| 81 | { |
| 82 | struct mc_ctlr *const mc = (struct mc_ctlr *)NV_PA_MC_BASE; |
| 83 | u32 size_mb; |
| 84 | |
| 85 | size_mb = readl(&mc->mc_emem_cfg); |
| 86 | debug("mc->mc_emem_cfg (MEM_SIZE_MB) = 0x%08x\n", size_mb); |
| 87 | |
| 88 | return size_mb * 1024 * 1024; |
| 89 | } |
| 90 | #endif |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 91 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 92 | int dram_init(void) |
| 93 | { |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 94 | /* We do not initialise DRAM here. We just query the size */ |
Simon Glass | f6fcbbd | 2011-11-05 03:56:57 +0000 | [diff] [blame] | 95 | gd->ram_size = query_sdram_size(); |
Tom Warren | 41b6838 | 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 | 5f3a899 | 2011-11-05 03:56:49 +0000 | [diff] [blame] | 106 | |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 107 | static int uart_configs[] = { |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 108 | #if defined(CONFIG_TEGRA20) |
| 109 | #if defined(CONFIG_TEGRA_UARTA_UAA_UAB) |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 110 | FUNCMUX_UART1_UAA_UAB, |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 111 | #elif defined(CONFIG_TEGRA_UARTA_GPU) |
Stephen Warren | e4c01a8 | 2012-05-16 05:59:59 +0000 | [diff] [blame] | 112 | FUNCMUX_UART1_GPU, |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 113 | #elif defined(CONFIG_TEGRA_UARTA_SDIO1) |
Lucas Stach | 4de6eec | 2012-05-16 08:21:02 +0000 | [diff] [blame] | 114 | FUNCMUX_UART1_SDIO1, |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 115 | #else |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 116 | FUNCMUX_UART1_IRRX_IRTX, |
Stephen Warren | 811af73 | 2013-01-22 06:20:08 +0000 | [diff] [blame] | 117 | #endif |
| 118 | FUNCMUX_UART2_UAD, |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 119 | -1, |
| 120 | FUNCMUX_UART4_GMC, |
| 121 | -1, |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 122 | #elif defined(CONFIG_TEGRA30) |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 123 | FUNCMUX_UART1_ULPI, /* UARTA */ |
| 124 | -1, |
| 125 | -1, |
| 126 | -1, |
| 127 | -1, |
Tom Warren | e5ffffd | 2014-01-24 12:46:16 -0700 | [diff] [blame] | 128 | #elif defined(CONFIG_TEGRA114) |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 129 | -1, |
| 130 | -1, |
| 131 | -1, |
| 132 | FUNCMUX_UART4_GMI, /* UARTD */ |
| 133 | -1, |
Tom Warren | e5ffffd | 2014-01-24 12:46:16 -0700 | [diff] [blame] | 134 | #else /* Tegra124 */ |
| 135 | FUNCMUX_UART1_KBC, /* UARTA */ |
| 136 | -1, |
| 137 | -1, |
| 138 | FUNCMUX_UART4_GPIO, /* UARTD */ |
| 139 | -1, |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 140 | #endif |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 143 | /** |
| 144 | * Set up the specified uarts |
| 145 | * |
| 146 | * @param uarts_ids Mask containing UARTs to init (UARTx) |
| 147 | */ |
| 148 | static void setup_uarts(int uart_ids) |
| 149 | { |
| 150 | static enum periph_id id_for_uart[] = { |
| 151 | PERIPH_ID_UART1, |
| 152 | PERIPH_ID_UART2, |
| 153 | PERIPH_ID_UART3, |
| 154 | PERIPH_ID_UART4, |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 155 | PERIPH_ID_UART5, |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 156 | }; |
| 157 | size_t i; |
| 158 | |
| 159 | for (i = 0; i < UART_COUNT; i++) { |
| 160 | if (uart_ids & (1 << i)) { |
| 161 | enum periph_id id = id_for_uart[i]; |
| 162 | |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 163 | funcmux_select(id, uart_configs[i]); |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 164 | clock_ll_start_uart(id); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | void board_init_uart_f(void) |
| 170 | { |
| 171 | int uart_ids = 0; /* bit mask of which UART ids to enable */ |
| 172 | |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 173 | #ifdef CONFIG_TEGRA_ENABLE_UARTA |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 174 | uart_ids |= UARTA; |
| 175 | #endif |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 176 | #ifdef CONFIG_TEGRA_ENABLE_UARTB |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 177 | uart_ids |= UARTB; |
| 178 | #endif |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 179 | #ifdef CONFIG_TEGRA_ENABLE_UARTC |
| 180 | uart_ids |= UARTC; |
| 181 | #endif |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 182 | #ifdef CONFIG_TEGRA_ENABLE_UARTD |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 183 | uart_ids |= UARTD; |
| 184 | #endif |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 185 | #ifdef CONFIG_TEGRA_ENABLE_UARTE |
| 186 | uart_ids |= UARTE; |
| 187 | #endif |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 188 | setup_uarts(uart_ids); |
| 189 | } |
Simon Glass | 410012f | 2012-01-09 13:22:15 +0000 | [diff] [blame] | 190 | |
| 191 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 192 | void enable_caches(void) |
| 193 | { |
| 194 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 195 | dcache_enable(); |
| 196 | } |
| 197 | #endif |