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