Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2013 SAMSUNG Electronics |
| 3 | * Rajeshwari Shinde <rajeshwari.s@samsung.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <cros_ec.h> |
| 10 | #include <errno.h> |
| 11 | #include <fdtdec.h> |
| 12 | #include <spi.h> |
| 13 | #include <tmu.h> |
| 14 | #include <netdev.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/board.h> |
| 17 | #include <asm/arch/cpu.h> |
| 18 | #include <asm/arch/dwmmc.h> |
| 19 | #include <asm/arch/gpio.h> |
| 20 | #include <asm/arch/mmc.h> |
| 21 | #include <asm/arch/pinmux.h> |
| 22 | #include <asm/arch/power.h> |
| 23 | #include <power/pmic.h> |
| 24 | #include <asm/arch/sromc.h> |
Piotr Wilczek | 431a1c5 | 2014-03-07 14:59:45 +0100 | [diff] [blame] | 25 | #include <lcd.h> |
| 26 | #include <samsung/misc.h> |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Piotr Wilczek | 8e5e1e6 | 2014-03-07 14:59:43 +0100 | [diff] [blame] | 30 | int __exynos_early_init_f(void) |
| 31 | { |
| 32 | return 0; |
| 33 | } |
| 34 | int exynos_early_init_f(void) |
| 35 | __attribute__((weak, alias("__exynos_early_init_f"))); |
| 36 | |
| 37 | int __exynos_power_init(void) |
| 38 | { |
| 39 | return 0; |
| 40 | } |
| 41 | int exynos_power_init(void) |
| 42 | __attribute__((weak, alias("__exynos_power_init"))); |
| 43 | |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 44 | #if defined CONFIG_EXYNOS_TMU |
| 45 | /* Boot Time Thermal Analysis for SoC temperature threshold breach */ |
| 46 | static void boot_temp_check(void) |
| 47 | { |
| 48 | int temp; |
| 49 | |
| 50 | switch (tmu_monitor(&temp)) { |
| 51 | case TMU_STATUS_NORMAL: |
| 52 | break; |
| 53 | case TMU_STATUS_TRIPPED: |
| 54 | /* |
| 55 | * Status TRIPPED ans WARNING means corresponding threshold |
| 56 | * breach |
| 57 | */ |
| 58 | puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n"); |
| 59 | set_ps_hold_ctrl(); |
| 60 | hang(); |
| 61 | break; |
| 62 | case TMU_STATUS_WARNING: |
| 63 | puts("EXYNOS_TMU: WARNING! Temperature very high\n"); |
| 64 | break; |
| 65 | case TMU_STATUS_INIT: |
| 66 | /* |
| 67 | * TMU_STATUS_INIT means something is wrong with temperature |
| 68 | * sensing and TMU status was changed back from NORMAL to INIT. |
| 69 | */ |
| 70 | puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n"); |
| 71 | break; |
| 72 | default: |
| 73 | debug("EXYNOS_TMU: Unknown TMU state\n"); |
| 74 | } |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | int board_init(void) |
| 79 | { |
| 80 | gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL); |
| 81 | #if defined CONFIG_EXYNOS_TMU |
| 82 | if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) { |
| 83 | debug("%s: Failed to init TMU\n", __func__); |
| 84 | return -1; |
| 85 | } |
| 86 | boot_temp_check(); |
| 87 | #endif |
| 88 | |
| 89 | #ifdef CONFIG_EXYNOS_SPI |
| 90 | spi_init(); |
| 91 | #endif |
| 92 | return exynos_init(); |
| 93 | } |
| 94 | |
| 95 | int dram_init(void) |
| 96 | { |
| 97 | int i; |
| 98 | u32 addr; |
| 99 | |
| 100 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 101 | addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE); |
| 102 | gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE); |
| 103 | } |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | void dram_init_banksize(void) |
| 108 | { |
| 109 | int i; |
| 110 | u32 addr, size; |
| 111 | |
| 112 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 113 | addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE); |
| 114 | size = get_ram_size((long *)addr, SDRAM_BANK_SIZE); |
| 115 | |
| 116 | gd->bd->bi_dram[i].start = addr; |
| 117 | gd->bd->bi_dram[i].size = size; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | static int board_uart_init(void) |
| 122 | { |
| 123 | int err, uart_id, ret = 0; |
| 124 | |
| 125 | for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) { |
| 126 | err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE); |
| 127 | if (err) { |
| 128 | debug("UART%d not configured\n", |
| 129 | (uart_id - PERIPH_ID_UART0)); |
| 130 | ret |= err; |
| 131 | } |
| 132 | } |
| 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 137 | int board_early_init_f(void) |
| 138 | { |
| 139 | int err; |
| 140 | |
| 141 | err = board_uart_init(); |
| 142 | if (err) { |
| 143 | debug("UART init failed\n"); |
| 144 | return err; |
| 145 | } |
| 146 | |
| 147 | #ifdef CONFIG_SYS_I2C_INIT_BOARD |
| 148 | board_i2c_init(gd->fdt_blob); |
| 149 | #endif |
| 150 | |
Piotr Wilczek | 8e5e1e6 | 2014-03-07 14:59:43 +0100 | [diff] [blame] | 151 | return exynos_early_init_f(); |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 152 | } |
| 153 | #endif |
| 154 | |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 155 | #if defined(CONFIG_POWER) |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 156 | int power_init_board(void) |
| 157 | { |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 158 | set_ps_hold_ctrl(); |
| 159 | |
Piotr Wilczek | 8e5e1e6 | 2014-03-07 14:59:43 +0100 | [diff] [blame] | 160 | return exynos_power_init(); |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 161 | } |
| 162 | #endif |
| 163 | |
| 164 | #ifdef CONFIG_OF_CONTROL |
Piotr Wilczek | 431a1c5 | 2014-03-07 14:59:45 +0100 | [diff] [blame] | 165 | #ifdef CONFIG_SMC911X |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 166 | static int decode_sromc(const void *blob, struct fdt_sromc *config) |
| 167 | { |
| 168 | int err; |
| 169 | int node; |
| 170 | |
| 171 | node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SROMC); |
| 172 | if (node < 0) { |
| 173 | debug("Could not find SROMC node\n"); |
| 174 | return node; |
| 175 | } |
| 176 | |
| 177 | config->bank = fdtdec_get_int(blob, node, "bank", 0); |
| 178 | config->width = fdtdec_get_int(blob, node, "width", 2); |
| 179 | |
| 180 | err = fdtdec_get_int_array(blob, node, "srom-timing", config->timing, |
| 181 | FDT_SROM_TIMING_COUNT); |
| 182 | if (err < 0) { |
| 183 | debug("Could not decode SROMC configuration Error: %s\n", |
| 184 | fdt_strerror(err)); |
| 185 | return -FDT_ERR_NOTFOUND; |
| 186 | } |
| 187 | return 0; |
| 188 | } |
Piotr Wilczek | 431a1c5 | 2014-03-07 14:59:45 +0100 | [diff] [blame] | 189 | #endif |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 190 | |
| 191 | int board_eth_init(bd_t *bis) |
| 192 | { |
| 193 | #ifdef CONFIG_SMC911X |
| 194 | u32 smc_bw_conf, smc_bc_conf; |
| 195 | struct fdt_sromc config; |
| 196 | fdt_addr_t base_addr; |
| 197 | int node; |
| 198 | |
| 199 | node = decode_sromc(gd->fdt_blob, &config); |
| 200 | if (node < 0) { |
| 201 | debug("%s: Could not find sromc configuration\n", __func__); |
| 202 | return 0; |
| 203 | } |
| 204 | node = fdtdec_next_compatible(gd->fdt_blob, node, COMPAT_SMSC_LAN9215); |
| 205 | if (node < 0) { |
| 206 | debug("%s: Could not find lan9215 configuration\n", __func__); |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | /* We now have a node, so any problems from now on are errors */ |
| 211 | base_addr = fdtdec_get_addr(gd->fdt_blob, node, "reg"); |
| 212 | if (base_addr == FDT_ADDR_T_NONE) { |
| 213 | debug("%s: Could not find lan9215 address\n", __func__); |
| 214 | return -1; |
| 215 | } |
| 216 | |
| 217 | /* Ethernet needs data bus width of 16 bits */ |
| 218 | if (config.width != 2) { |
| 219 | debug("%s: Unsupported bus width %d\n", __func__, |
| 220 | config.width); |
| 221 | return -1; |
| 222 | } |
| 223 | smc_bw_conf = SROMC_DATA16_WIDTH(config.bank) |
| 224 | | SROMC_BYTE_ENABLE(config.bank); |
| 225 | |
| 226 | smc_bc_conf = SROMC_BC_TACS(config.timing[FDT_SROM_TACS]) | |
| 227 | SROMC_BC_TCOS(config.timing[FDT_SROM_TCOS]) | |
| 228 | SROMC_BC_TACC(config.timing[FDT_SROM_TACC]) | |
| 229 | SROMC_BC_TCOH(config.timing[FDT_SROM_TCOH]) | |
| 230 | SROMC_BC_TAH(config.timing[FDT_SROM_TAH]) | |
| 231 | SROMC_BC_TACP(config.timing[FDT_SROM_TACP]) | |
| 232 | SROMC_BC_PMC(config.timing[FDT_SROM_PMC]); |
| 233 | |
| 234 | /* Select and configure the SROMC bank */ |
| 235 | exynos_pinmux_config(PERIPH_ID_SROMC, config.bank); |
| 236 | s5p_config_sromc(config.bank, smc_bw_conf, smc_bc_conf); |
| 237 | return smc911x_initialize(0, base_addr); |
| 238 | #endif |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | #ifdef CONFIG_GENERIC_MMC |
Przemyslaw Marczak | 33a4fcf | 2014-09-01 13:50:45 +0200 | [diff] [blame^] | 243 | static int init_mmc(void) |
| 244 | { |
| 245 | #ifdef CONFIG_SDHCI |
| 246 | return exynos_mmc_init(gd->fdt_blob); |
| 247 | #else |
| 248 | return 0; |
| 249 | #endif |
| 250 | } |
| 251 | |
| 252 | static int init_dwmmc(void) |
| 253 | { |
| 254 | #ifdef CONFIG_DWMMC |
| 255 | return exynos_dwmmc_init(gd->fdt_blob); |
| 256 | #else |
| 257 | return 0; |
| 258 | #endif |
| 259 | } |
| 260 | |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 261 | int board_mmc_init(bd_t *bis) |
| 262 | { |
| 263 | int ret; |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 264 | |
Przemyslaw Marczak | 33a4fcf | 2014-09-01 13:50:45 +0200 | [diff] [blame^] | 265 | if (get_boot_mode() == BOOT_MODE_SD) { |
| 266 | ret = init_mmc(); |
| 267 | ret |= init_dwmmc(); |
| 268 | } else { |
| 269 | ret = init_dwmmc(); |
| 270 | ret |= init_mmc(); |
| 271 | } |
| 272 | |
Jaehoon Chung | 58209df | 2014-05-16 13:59:49 +0900 | [diff] [blame] | 273 | if (ret) |
| 274 | debug("mmc init failed\n"); |
Przemyslaw Marczak | 33a4fcf | 2014-09-01 13:50:45 +0200 | [diff] [blame^] | 275 | |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 276 | return ret; |
| 277 | } |
| 278 | #endif |
Piotr Wilczek | 4c1dd99 | 2014-03-07 14:59:42 +0100 | [diff] [blame] | 279 | |
| 280 | #ifdef CONFIG_DISPLAY_BOARDINFO |
| 281 | int checkboard(void) |
| 282 | { |
| 283 | const char *board_name; |
| 284 | |
| 285 | board_name = fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 286 | printf("Board: %s\n", board_name ? board_name : "unknown"); |
| 287 | |
| 288 | return 0; |
| 289 | } |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 290 | #endif |
Piotr Wilczek | 4c1dd99 | 2014-03-07 14:59:42 +0100 | [diff] [blame] | 291 | #endif /* CONFIG_OF_CONTROL */ |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 292 | |
| 293 | #ifdef CONFIG_BOARD_LATE_INIT |
| 294 | int board_late_init(void) |
| 295 | { |
| 296 | stdio_print_current_devices(); |
| 297 | |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 298 | if (cros_ec_get_error()) { |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 299 | /* Force console on */ |
| 300 | gd->flags &= ~GD_FLG_SILENT; |
| 301 | |
| 302 | printf("cros-ec communications failure %d\n", |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 303 | cros_ec_get_error()); |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 304 | puts("\nPlease reset with Power+Refresh\n\n"); |
| 305 | panic("Cannot init cros-ec device"); |
| 306 | return -1; |
| 307 | } |
| 308 | return 0; |
| 309 | } |
| 310 | #endif |
| 311 | |
| 312 | int arch_early_init_r(void) |
| 313 | { |
| 314 | #ifdef CONFIG_CROS_EC |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 315 | if (cros_ec_board_init()) { |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 316 | printf("%s: Failed to init EC\n", __func__); |
| 317 | return 0; |
| 318 | } |
| 319 | #endif |
| 320 | |
| 321 | return 0; |
| 322 | } |
Piotr Wilczek | 431a1c5 | 2014-03-07 14:59:45 +0100 | [diff] [blame] | 323 | |
| 324 | #ifdef CONFIG_MISC_INIT_R |
| 325 | int misc_init_r(void) |
| 326 | { |
| 327 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 328 | set_board_info(); |
| 329 | #endif |
| 330 | #ifdef CONFIG_LCD_MENU |
| 331 | keys_init(); |
| 332 | check_boot_mode(); |
| 333 | #endif |
| 334 | #ifdef CONFIG_CMD_BMP |
| 335 | if (panel_info.logo_on) |
| 336 | draw_logo(); |
| 337 | #endif |
| 338 | return 0; |
| 339 | } |
| 340 | #endif |