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