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> |
Marcel Ziswiler | c5ecf27 | 2014-10-10 23:32:32 +0200 | [diff] [blame] | 12 | #include <asm/arch/mc.h> |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 13 | #include <asm/arch/tegra.h> |
Lucas Stach | e80f7ca | 2012-09-29 10:02:08 +0000 | [diff] [blame] | 14 | #include <asm/arch-tegra/board.h> |
Tom Warren | ab37196 | 2012-09-19 15:50:56 -0700 | [diff] [blame] | 15 | #include <asm/arch-tegra/pmc.h> |
| 16 | #include <asm/arch-tegra/sys_proto.h> |
| 17 | #include <asm/arch-tegra/warmboot.h> |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 21 | enum { |
| 22 | /* UARTs which we can enable */ |
| 23 | UARTA = 1 << 0, |
| 24 | UARTB = 1 << 1, |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 25 | UARTC = 1 << 2, |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 26 | UARTD = 1 << 3, |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 27 | UARTE = 1 << 4, |
| 28 | UART_COUNT = 5, |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
Stephen Warren | 1b4af6b | 2014-07-02 14:12:30 -0600 | [diff] [blame] | 31 | /* Read the RAM size directly from the memory controller */ |
| 32 | unsigned int query_sdram_size(void) |
| 33 | { |
| 34 | struct mc_ctlr *const mc = (struct mc_ctlr *)NV_PA_MC_BASE; |
Stephen Warren | 210bdb2 | 2014-12-23 10:34:50 -0700 | [diff] [blame^] | 35 | u32 emem_cfg, size_bytes; |
Stephen Warren | 1b4af6b | 2014-07-02 14:12:30 -0600 | [diff] [blame] | 36 | |
Stephen Warren | 210bdb2 | 2014-12-23 10:34:50 -0700 | [diff] [blame^] | 37 | emem_cfg = readl(&mc->mc_emem_cfg); |
Marcel Ziswiler | c5ecf27 | 2014-10-10 23:32:32 +0200 | [diff] [blame] | 38 | #if defined(CONFIG_TEGRA20) |
Stephen Warren | 210bdb2 | 2014-12-23 10:34:50 -0700 | [diff] [blame^] | 39 | debug("mc->mc_emem_cfg (MEM_SIZE_KB) = 0x%08x\n", emem_cfg); |
| 40 | size_bytes = get_ram_size((void *)PHYS_SDRAM_1, emem_cfg * 1024); |
Marcel Ziswiler | c5ecf27 | 2014-10-10 23:32:32 +0200 | [diff] [blame] | 41 | #else |
Stephen Warren | 210bdb2 | 2014-12-23 10:34:50 -0700 | [diff] [blame^] | 42 | debug("mc->mc_emem_cfg (MEM_SIZE_MB) = 0x%08x\n", emem_cfg); |
| 43 | size_bytes = get_ram_size((void *)PHYS_SDRAM_1, emem_cfg * 1024 * 1024); |
Marcel Ziswiler | c5ecf27 | 2014-10-10 23:32:32 +0200 | [diff] [blame] | 44 | #endif |
Stephen Warren | 1b4af6b | 2014-07-02 14:12:30 -0600 | [diff] [blame] | 45 | |
Marcel Ziswiler | c5ecf27 | 2014-10-10 23:32:32 +0200 | [diff] [blame] | 46 | #if defined(CONFIG_TEGRA30) || defined(CONFIG_TEGRA114) |
| 47 | /* External memory limited to 2047 MB due to IROM/HI-VEC */ |
Stephen Warren | 210bdb2 | 2014-12-23 10:34:50 -0700 | [diff] [blame^] | 48 | if (size_bytes == SZ_2G) |
| 49 | size_bytes -= SZ_1M; |
Stephen Warren | 1b4af6b | 2014-07-02 14:12:30 -0600 | [diff] [blame] | 50 | #endif |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 51 | |
Stephen Warren | 210bdb2 | 2014-12-23 10:34:50 -0700 | [diff] [blame^] | 52 | return size_bytes; |
Marcel Ziswiler | c5ecf27 | 2014-10-10 23:32:32 +0200 | [diff] [blame] | 53 | } |
| 54 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 55 | int dram_init(void) |
| 56 | { |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 57 | /* We do not initialise DRAM here. We just query the size */ |
Simon Glass | f6fcbbd | 2011-11-05 03:56:57 +0000 | [diff] [blame] | 58 | gd->ram_size = query_sdram_size(); |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | #ifdef CONFIG_DISPLAY_BOARDINFO |
| 63 | int checkboard(void) |
| 64 | { |
| 65 | printf("Board: %s\n", sysinfo.board_string); |
| 66 | return 0; |
| 67 | } |
| 68 | #endif /* CONFIG_DISPLAY_BOARDINFO */ |
Simon Glass | 5f3a899 | 2011-11-05 03:56:49 +0000 | [diff] [blame] | 69 | |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 70 | static int uart_configs[] = { |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 71 | #if defined(CONFIG_TEGRA20) |
| 72 | #if defined(CONFIG_TEGRA_UARTA_UAA_UAB) |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 73 | FUNCMUX_UART1_UAA_UAB, |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 74 | #elif defined(CONFIG_TEGRA_UARTA_GPU) |
Stephen Warren | e4c01a8 | 2012-05-16 05:59:59 +0000 | [diff] [blame] | 75 | FUNCMUX_UART1_GPU, |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 76 | #elif defined(CONFIG_TEGRA_UARTA_SDIO1) |
Lucas Stach | 4de6eec | 2012-05-16 08:21:02 +0000 | [diff] [blame] | 77 | FUNCMUX_UART1_SDIO1, |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 78 | #else |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 79 | FUNCMUX_UART1_IRRX_IRTX, |
Stephen Warren | 811af73 | 2013-01-22 06:20:08 +0000 | [diff] [blame] | 80 | #endif |
| 81 | FUNCMUX_UART2_UAD, |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 82 | -1, |
| 83 | FUNCMUX_UART4_GMC, |
| 84 | -1, |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 85 | #elif defined(CONFIG_TEGRA30) |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 86 | FUNCMUX_UART1_ULPI, /* UARTA */ |
| 87 | -1, |
| 88 | -1, |
| 89 | -1, |
| 90 | -1, |
Tom Warren | e5ffffd | 2014-01-24 12:46:16 -0700 | [diff] [blame] | 91 | #elif defined(CONFIG_TEGRA114) |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 92 | -1, |
| 93 | -1, |
| 94 | -1, |
| 95 | FUNCMUX_UART4_GMI, /* UARTD */ |
| 96 | -1, |
Tom Warren | e5ffffd | 2014-01-24 12:46:16 -0700 | [diff] [blame] | 97 | #else /* Tegra124 */ |
| 98 | FUNCMUX_UART1_KBC, /* UARTA */ |
| 99 | -1, |
| 100 | -1, |
| 101 | FUNCMUX_UART4_GPIO, /* UARTD */ |
| 102 | -1, |
Tom Warren | 61c6d0e | 2012-12-11 13:34:15 +0000 | [diff] [blame] | 103 | #endif |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 106 | /** |
| 107 | * Set up the specified uarts |
| 108 | * |
| 109 | * @param uarts_ids Mask containing UARTs to init (UARTx) |
| 110 | */ |
| 111 | static void setup_uarts(int uart_ids) |
| 112 | { |
| 113 | static enum periph_id id_for_uart[] = { |
| 114 | PERIPH_ID_UART1, |
| 115 | PERIPH_ID_UART2, |
| 116 | PERIPH_ID_UART3, |
| 117 | PERIPH_ID_UART4, |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 118 | PERIPH_ID_UART5, |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 119 | }; |
| 120 | size_t i; |
| 121 | |
| 122 | for (i = 0; i < UART_COUNT; i++) { |
| 123 | if (uart_ids & (1 << i)) { |
| 124 | enum periph_id id = id_for_uart[i]; |
| 125 | |
Stephen Warren | 59f9010 | 2012-05-14 13:13:45 +0000 | [diff] [blame] | 126 | funcmux_select(id, uart_configs[i]); |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 127 | clock_ll_start_uart(id); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | void board_init_uart_f(void) |
| 133 | { |
| 134 | int uart_ids = 0; /* bit mask of which UART ids to enable */ |
| 135 | |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 136 | #ifdef CONFIG_TEGRA_ENABLE_UARTA |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 137 | uart_ids |= UARTA; |
| 138 | #endif |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 139 | #ifdef CONFIG_TEGRA_ENABLE_UARTB |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 140 | uart_ids |= UARTB; |
| 141 | #endif |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 142 | #ifdef CONFIG_TEGRA_ENABLE_UARTC |
| 143 | uart_ids |= UARTC; |
| 144 | #endif |
Tom Warren | 22562a4 | 2012-09-04 17:00:24 -0700 | [diff] [blame] | 145 | #ifdef CONFIG_TEGRA_ENABLE_UARTD |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 146 | uart_ids |= UARTD; |
| 147 | #endif |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 148 | #ifdef CONFIG_TEGRA_ENABLE_UARTE |
| 149 | uart_ids |= UARTE; |
| 150 | #endif |
Simon Glass | 96b7c43 | 2011-11-28 15:04:39 +0000 | [diff] [blame] | 151 | setup_uarts(uart_ids); |
| 152 | } |
Simon Glass | 410012f | 2012-01-09 13:22:15 +0000 | [diff] [blame] | 153 | |
| 154 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 155 | void enable_caches(void) |
| 156 | { |
| 157 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 158 | dcache_enable(); |
| 159 | } |
| 160 | #endif |