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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <asm/io.h> |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 10 | #include <asm/arch/clock.h> |
| 11 | #include <asm/arch/funcmux.h> |
Tom Warren | 150c249 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 12 | #include <asm/arch/tegra.h> |
Lucas Stach | 516f00b | 2012-09-29 10:02:08 +0000 | [diff] [blame] | 13 | #include <asm/arch-tegra/board.h> |
Tom Warren | 150c249 | 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 | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Simon Glass | bb6997f | 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 | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 24 | UARTC = 1 << 2, |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 25 | UARTD = 1 << 3, |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 26 | UARTE = 1 << 4, |
| 27 | UART_COUNT = 5, |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 30 | /* |
| 31 | * Boot ROM initializes the odmdata in APBDEV_PMC_SCRATCH20_0, |
| 32 | * so we are using this value to identify memory size. |
| 33 | */ |
| 34 | |
| 35 | unsigned int query_sdram_size(void) |
| 36 | { |
Tom Warren | 29f3e3f | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 37 | struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE; |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 38 | u32 reg; |
| 39 | |
| 40 | reg = readl(&pmc->pmc_scratch20); |
Marek Vasut | 4a34af7 | 2011-10-24 23:41:39 +0000 | [diff] [blame] | 41 | debug("pmc->pmc_scratch20 (ODMData) = 0x%08x\n", reg); |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 42 | |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 43 | #if defined(CONFIG_TEGRA20) |
| 44 | /* bits 30:28 in OdmData are used for RAM size on T20 */ |
| 45 | reg &= 0x70000000; |
| 46 | |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 47 | switch ((reg) >> 28) { |
| 48 | case 1: |
| 49 | return 0x10000000; /* 256 MB */ |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 50 | case 0: |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 51 | case 2: |
Stephen Warren | 9057e65 | 2012-01-06 12:14:41 +0000 | [diff] [blame] | 52 | default: |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 53 | return 0x20000000; /* 512 MB */ |
| 54 | case 3: |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 55 | return 0x40000000; /* 1GB */ |
| 56 | } |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 57 | #else /* Tegra30/Tegra114 */ |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 58 | /* bits 31:28 in OdmData are used for RAM size on T30 */ |
| 59 | switch ((reg) >> 28) { |
| 60 | case 0: |
| 61 | case 1: |
| 62 | default: |
| 63 | return 0x10000000; /* 256 MB */ |
| 64 | case 2: |
| 65 | return 0x20000000; /* 512 MB */ |
| 66 | case 3: |
| 67 | return 0x30000000; /* 768 MB */ |
| 68 | case 4: |
| 69 | return 0x40000000; /* 1GB */ |
| 70 | case 8: |
| 71 | return 0x7ff00000; /* 2GB - 1MB */ |
| 72 | } |
| 73 | #endif |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 76 | int dram_init(void) |
| 77 | { |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 78 | /* We do not initialise DRAM here. We just query the size */ |
Simon Glass | 7f8c070 | 2011-11-05 03:56:57 +0000 | [diff] [blame] | 79 | gd->ram_size = query_sdram_size(); |
Tom Warren | 3f82b1d | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | #ifdef CONFIG_DISPLAY_BOARDINFO |
| 84 | int checkboard(void) |
| 85 | { |
| 86 | printf("Board: %s\n", sysinfo.board_string); |
| 87 | return 0; |
| 88 | } |
| 89 | #endif /* CONFIG_DISPLAY_BOARDINFO */ |
Simon Glass | e43d6ed | 2011-11-05 03:56:49 +0000 | [diff] [blame] | 90 | |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 91 | static int uart_configs[] = { |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 92 | #if defined(CONFIG_TEGRA20) |
| 93 | #if defined(CONFIG_TEGRA_UARTA_UAA_UAB) |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 94 | FUNCMUX_UART1_UAA_UAB, |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 95 | #elif defined(CONFIG_TEGRA_UARTA_GPU) |
Stephen Warren | e21649b | 2012-05-16 05:59:59 +0000 | [diff] [blame] | 96 | FUNCMUX_UART1_GPU, |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 97 | #elif defined(CONFIG_TEGRA_UARTA_SDIO1) |
Lucas Stach | a2cfe63 | 2012-05-16 08:21:02 +0000 | [diff] [blame] | 98 | FUNCMUX_UART1_SDIO1, |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 99 | #else |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 100 | FUNCMUX_UART1_IRRX_IRTX, |
Stephen Warren | 4727a13 | 2013-01-22 06:20:08 +0000 | [diff] [blame] | 101 | #endif |
| 102 | FUNCMUX_UART2_UAD, |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 103 | -1, |
| 104 | FUNCMUX_UART4_GMC, |
| 105 | -1, |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 106 | #elif defined(CONFIG_TEGRA30) |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 107 | FUNCMUX_UART1_ULPI, /* UARTA */ |
| 108 | -1, |
| 109 | -1, |
| 110 | -1, |
| 111 | -1, |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 112 | #else /* Tegra114 */ |
| 113 | -1, |
| 114 | -1, |
| 115 | -1, |
| 116 | FUNCMUX_UART4_GMI, /* UARTD */ |
| 117 | -1, |
Tom Warren | b287103 | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 118 | #endif |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 121 | /** |
| 122 | * Set up the specified uarts |
| 123 | * |
| 124 | * @param uarts_ids Mask containing UARTs to init (UARTx) |
| 125 | */ |
| 126 | static void setup_uarts(int uart_ids) |
| 127 | { |
| 128 | static enum periph_id id_for_uart[] = { |
| 129 | PERIPH_ID_UART1, |
| 130 | PERIPH_ID_UART2, |
| 131 | PERIPH_ID_UART3, |
| 132 | PERIPH_ID_UART4, |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 133 | PERIPH_ID_UART5, |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 134 | }; |
| 135 | size_t i; |
| 136 | |
| 137 | for (i = 0; i < UART_COUNT; i++) { |
| 138 | if (uart_ids & (1 << i)) { |
| 139 | enum periph_id id = id_for_uart[i]; |
| 140 | |
Stephen Warren | b9607e7 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 141 | funcmux_select(id, uart_configs[i]); |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 142 | clock_ll_start_uart(id); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void board_init_uart_f(void) |
| 148 | { |
| 149 | int uart_ids = 0; /* bit mask of which UART ids to enable */ |
| 150 | |
Tom Warren | 29f3e3f | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 151 | #ifdef CONFIG_TEGRA_ENABLE_UARTA |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 152 | uart_ids |= UARTA; |
| 153 | #endif |
Tom Warren | 29f3e3f | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 154 | #ifdef CONFIG_TEGRA_ENABLE_UARTB |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 155 | uart_ids |= UARTB; |
| 156 | #endif |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 157 | #ifdef CONFIG_TEGRA_ENABLE_UARTC |
| 158 | uart_ids |= UARTC; |
| 159 | #endif |
Tom Warren | 29f3e3f | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 160 | #ifdef CONFIG_TEGRA_ENABLE_UARTD |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 161 | uart_ids |= UARTD; |
| 162 | #endif |
Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 163 | #ifdef CONFIG_TEGRA_ENABLE_UARTE |
| 164 | uart_ids |= UARTE; |
| 165 | #endif |
Simon Glass | bb6997f | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 166 | setup_uarts(uart_ids); |
| 167 | } |
Simon Glass | bd29cb0 | 2012-01-09 13:22:15 +0000 | [diff] [blame] | 168 | |
| 169 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 170 | void enable_caches(void) |
| 171 | { |
| 172 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 173 | dcache_enable(); |
| 174 | } |
| 175 | #endif |