Amar | bb54b75 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Samsung Electronics |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include <common.h> |
| 24 | #include <fdtdec.h> |
| 25 | #include <asm/io.h> |
| 26 | #include <errno.h> |
| 27 | #include <i2c.h> |
| 28 | #include <netdev.h> |
| 29 | #include <spi.h> |
| 30 | #include <asm/arch/cpu.h> |
| 31 | #include <asm/arch/dwmmc.h> |
| 32 | #include <asm/arch/gpio.h> |
| 33 | #include <asm/arch/mmc.h> |
| 34 | #include <asm/arch/pinmux.h> |
| 35 | #include <asm/arch/power.h> |
| 36 | #include <asm/arch/sromc.h> |
| 37 | #include <power/pmic.h> |
| 38 | #include <power/max77686_pmic.h> |
| 39 | #include <tmu.h> |
| 40 | |
| 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
| 43 | #if defined CONFIG_EXYNOS_TMU |
| 44 | /* |
| 45 | * Boot Time Thermal Analysis for SoC temperature threshold breach |
| 46 | */ |
| 47 | static void boot_temp_check(void) |
| 48 | { |
| 49 | int temp; |
| 50 | |
| 51 | switch (tmu_monitor(&temp)) { |
| 52 | /* Status TRIPPED ans WARNING means corresponding threshold breach */ |
| 53 | case TMU_STATUS_TRIPPED: |
| 54 | puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n"); |
| 55 | set_ps_hold_ctrl(); |
| 56 | hang(); |
| 57 | break; |
| 58 | case TMU_STATUS_WARNING: |
| 59 | puts("EXYNOS_TMU: WARNING! Temperature very high\n"); |
| 60 | break; |
| 61 | /* |
| 62 | * TMU_STATUS_INIT means something is wrong with temperature sensing |
| 63 | * and TMU status was changed back from NORMAL to INIT. |
| 64 | */ |
| 65 | case TMU_STATUS_INIT: |
| 66 | default: |
| 67 | debug("EXYNOS_TMU: Unknown TMU state\n"); |
| 68 | } |
| 69 | } |
| 70 | #endif |
| 71 | |
| 72 | #ifdef CONFIG_USB_EHCI_EXYNOS |
| 73 | int board_usb_vbus_init(void) |
| 74 | { |
| 75 | struct exynos5_gpio_part1 *gpio1 = (struct exynos5_gpio_part1 *) |
| 76 | samsung_get_base_gpio_part1(); |
| 77 | |
| 78 | /* Enable VBUS power switch */ |
| 79 | s5p_gpio_direction_output(&gpio1->x2, 6, 1); |
| 80 | |
| 81 | /* VBUS turn ON time */ |
| 82 | mdelay(3); |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | #ifdef CONFIG_SOUND_MAX98095 |
| 89 | static void board_enable_audio_codec(void) |
| 90 | { |
| 91 | struct exynos5_gpio_part1 *gpio1 = (struct exynos5_gpio_part1 *) |
| 92 | samsung_get_base_gpio_part1(); |
| 93 | |
| 94 | /* Enable MAX98095 Codec */ |
| 95 | s5p_gpio_direction_output(&gpio1->x1, 7, 1); |
| 96 | s5p_gpio_set_pull(&gpio1->x1, 7, GPIO_PULL_NONE); |
| 97 | } |
| 98 | #endif |
| 99 | |
| 100 | int board_init(void) |
| 101 | { |
| 102 | gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL); |
| 103 | |
| 104 | #if defined CONFIG_EXYNOS_TMU |
| 105 | if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) { |
| 106 | debug("%s: Failed to init TMU\n", __func__); |
| 107 | return -1; |
| 108 | } |
| 109 | boot_temp_check(); |
| 110 | #endif |
| 111 | |
| 112 | #ifdef CONFIG_EXYNOS_SPI |
| 113 | spi_init(); |
| 114 | #endif |
| 115 | #ifdef CONFIG_USB_EHCI_EXYNOS |
| 116 | board_usb_vbus_init(); |
| 117 | #endif |
| 118 | #ifdef CONFIG_SOUND_MAX98095 |
| 119 | board_enable_audio_codec(); |
| 120 | #endif |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | int dram_init(void) |
| 125 | { |
| 126 | int i; |
| 127 | u32 addr; |
| 128 | |
| 129 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 130 | addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE); |
| 131 | gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE); |
| 132 | } |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | #if defined(CONFIG_POWER) |
| 137 | static int pmic_reg_update(struct pmic *p, int reg, uint regval) |
| 138 | { |
| 139 | u32 val; |
| 140 | int ret = 0; |
| 141 | |
| 142 | ret = pmic_reg_read(p, reg, &val); |
| 143 | if (ret) { |
| 144 | debug("%s: PMIC %d register read failed\n", __func__, reg); |
| 145 | return -1; |
| 146 | } |
| 147 | val |= regval; |
| 148 | ret = pmic_reg_write(p, reg, val); |
| 149 | if (ret) { |
| 150 | debug("%s: PMIC %d register write failed\n", __func__, reg); |
| 151 | return -1; |
| 152 | } |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | int power_init_board(void) |
| 157 | { |
| 158 | struct pmic *p; |
| 159 | |
| 160 | set_ps_hold_ctrl(); |
| 161 | |
| 162 | i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
| 163 | |
| 164 | if (pmic_init(I2C_PMIC)) |
| 165 | return -1; |
| 166 | |
| 167 | p = pmic_get("MAX77686_PMIC"); |
| 168 | if (!p) |
| 169 | return -ENODEV; |
| 170 | |
| 171 | if (pmic_probe(p)) |
| 172 | return -1; |
| 173 | |
| 174 | if (pmic_reg_update(p, MAX77686_REG_PMIC_32KHZ, MAX77686_32KHCP_EN)) |
| 175 | return -1; |
| 176 | |
| 177 | if (pmic_reg_update(p, MAX77686_REG_PMIC_BBAT, |
| 178 | MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V)) |
| 179 | return -1; |
| 180 | |
| 181 | /* VDD_MIF */ |
| 182 | if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK1OUT, |
| 183 | MAX77686_BUCK1OUT_1V)) { |
| 184 | debug("%s: PMIC %d register write failed\n", __func__, |
| 185 | MAX77686_REG_PMIC_BUCK1OUT); |
| 186 | return -1; |
| 187 | } |
| 188 | |
| 189 | if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK1CRTL, |
| 190 | MAX77686_BUCK1CTRL_EN)) |
| 191 | return -1; |
| 192 | |
| 193 | /* VDD_ARM */ |
| 194 | if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK2DVS1, |
| 195 | MAX77686_BUCK2DVS1_1_3V)) { |
| 196 | debug("%s: PMIC %d register write failed\n", __func__, |
| 197 | MAX77686_REG_PMIC_BUCK2DVS1); |
| 198 | return -1; |
| 199 | } |
| 200 | |
| 201 | if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK2CTRL1, |
| 202 | MAX77686_BUCK2CTRL_ON)) |
| 203 | return -1; |
| 204 | |
| 205 | /* VDD_INT */ |
| 206 | if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK3DVS1, |
| 207 | MAX77686_BUCK3DVS1_1_0125V)) { |
| 208 | debug("%s: PMIC %d register write failed\n", __func__, |
| 209 | MAX77686_REG_PMIC_BUCK3DVS1); |
| 210 | return -1; |
| 211 | } |
| 212 | |
| 213 | if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK3CTRL, |
| 214 | MAX77686_BUCK3CTRL_ON)) |
| 215 | return -1; |
| 216 | |
| 217 | /* VDD_G3D */ |
| 218 | if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK4DVS1, |
| 219 | MAX77686_BUCK4DVS1_1_2V)) { |
| 220 | debug("%s: PMIC %d register write failed\n", __func__, |
| 221 | MAX77686_REG_PMIC_BUCK4DVS1); |
| 222 | return -1; |
| 223 | } |
| 224 | |
| 225 | if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK4CTRL1, |
| 226 | MAX77686_BUCK3CTRL_ON)) |
| 227 | return -1; |
| 228 | |
| 229 | /* VDD_LDO2 */ |
| 230 | if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO2CTRL1, |
| 231 | MAX77686_LD02CTRL1_1_5V | EN_LDO)) |
| 232 | return -1; |
| 233 | |
| 234 | /* VDD_LDO3 */ |
| 235 | if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO3CTRL1, |
| 236 | MAX77686_LD03CTRL1_1_8V | EN_LDO)) |
| 237 | return -1; |
| 238 | |
| 239 | /* VDD_LDO5 */ |
| 240 | if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO5CTRL1, |
| 241 | MAX77686_LD05CTRL1_1_8V | EN_LDO)) |
| 242 | return -1; |
| 243 | |
| 244 | /* VDD_LDO10 */ |
| 245 | if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO10CTRL1, |
| 246 | MAX77686_LD10CTRL1_1_8V | EN_LDO)) |
| 247 | return -1; |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | #endif |
| 252 | |
| 253 | void dram_init_banksize(void) |
| 254 | { |
| 255 | int i; |
| 256 | u32 addr, size; |
| 257 | |
| 258 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 259 | addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE); |
| 260 | size = get_ram_size((long *)addr, SDRAM_BANK_SIZE); |
| 261 | |
| 262 | gd->bd->bi_dram[i].start = addr; |
| 263 | gd->bd->bi_dram[i].size = size; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | static int decode_sromc(const void *blob, struct fdt_sromc *config) |
| 268 | { |
| 269 | int err; |
| 270 | int node; |
| 271 | |
| 272 | node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SROMC); |
| 273 | if (node < 0) { |
| 274 | debug("Could not find SROMC node\n"); |
| 275 | return node; |
| 276 | } |
| 277 | |
| 278 | config->bank = fdtdec_get_int(blob, node, "bank", 0); |
| 279 | config->width = fdtdec_get_int(blob, node, "width", 2); |
| 280 | |
| 281 | err = fdtdec_get_int_array(blob, node, "srom-timing", config->timing, |
| 282 | FDT_SROM_TIMING_COUNT); |
| 283 | if (err < 0) { |
| 284 | debug("Could not decode SROMC configuration Error: %s\n", |
| 285 | fdt_strerror(err)); |
| 286 | return -FDT_ERR_NOTFOUND; |
| 287 | } |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | int board_eth_init(bd_t *bis) |
| 292 | { |
| 293 | #ifdef CONFIG_SMC911X |
| 294 | u32 smc_bw_conf, smc_bc_conf; |
| 295 | struct fdt_sromc config; |
| 296 | fdt_addr_t base_addr; |
| 297 | int node; |
| 298 | |
| 299 | node = decode_sromc(gd->fdt_blob, &config); |
| 300 | if (node < 0) { |
| 301 | debug("%s: Could not find sromc configuration\n", __func__); |
| 302 | return 0; |
| 303 | } |
| 304 | node = fdtdec_next_compatible(gd->fdt_blob, node, COMPAT_SMSC_LAN9215); |
| 305 | if (node < 0) { |
| 306 | debug("%s: Could not find lan9215 configuration\n", __func__); |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | /* We now have a node, so any problems from now on are errors */ |
| 311 | base_addr = fdtdec_get_addr(gd->fdt_blob, node, "reg"); |
| 312 | if (base_addr == FDT_ADDR_T_NONE) { |
| 313 | debug("%s: Could not find lan9215 address\n", __func__); |
| 314 | return -1; |
| 315 | } |
| 316 | |
| 317 | /* Ethernet needs data bus width of 16 bits */ |
| 318 | if (config.width != 2) { |
| 319 | debug("%s: Unsupported bus width %d\n", __func__, |
| 320 | config.width); |
| 321 | return -1; |
| 322 | } |
| 323 | smc_bw_conf = SROMC_DATA16_WIDTH(config.bank) |
| 324 | | SROMC_BYTE_ENABLE(config.bank); |
| 325 | |
| 326 | smc_bc_conf = SROMC_BC_TACS(config.timing[FDT_SROM_TACS]) | |
| 327 | SROMC_BC_TCOS(config.timing[FDT_SROM_TCOS]) | |
| 328 | SROMC_BC_TACC(config.timing[FDT_SROM_TACC]) | |
| 329 | SROMC_BC_TCOH(config.timing[FDT_SROM_TCOH]) | |
| 330 | SROMC_BC_TAH(config.timing[FDT_SROM_TAH]) | |
| 331 | SROMC_BC_TACP(config.timing[FDT_SROM_TACP]) | |
| 332 | SROMC_BC_PMC(config.timing[FDT_SROM_PMC]); |
| 333 | |
| 334 | /* Select and configure the SROMC bank */ |
| 335 | exynos_pinmux_config(PERIPH_ID_SROMC, config.bank); |
| 336 | s5p_config_sromc(config.bank, smc_bw_conf, smc_bc_conf); |
| 337 | return smc911x_initialize(0, base_addr); |
| 338 | #endif |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | #ifdef CONFIG_DISPLAY_BOARDINFO |
| 343 | int checkboard(void) |
| 344 | { |
| 345 | const char *board_name; |
| 346 | |
| 347 | board_name = fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 348 | if (board_name == NULL) |
| 349 | printf("\nUnknown Board\n"); |
| 350 | else |
| 351 | printf("\nBoard: %s\n", board_name); |
| 352 | |
| 353 | return 0; |
| 354 | } |
| 355 | #endif |
| 356 | |
| 357 | #ifdef CONFIG_GENERIC_MMC |
| 358 | int board_mmc_init(bd_t *bis) |
| 359 | { |
| 360 | int ret; |
| 361 | /* dwmmc initializattion for available channels */ |
| 362 | ret = exynos_dwmmc_init(gd->fdt_blob); |
| 363 | if (ret) |
| 364 | debug("dwmmc init failed\n"); |
| 365 | |
| 366 | return ret; |
| 367 | } |
| 368 | #endif |
| 369 | |
| 370 | static int board_uart_init(void) |
| 371 | { |
| 372 | int err, uart_id, ret = 0; |
| 373 | |
| 374 | for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) { |
| 375 | err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE); |
| 376 | if (err) { |
| 377 | debug("UART%d not configured\n", |
| 378 | (uart_id - PERIPH_ID_UART0)); |
| 379 | ret |= err; |
| 380 | } |
| 381 | } |
| 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 386 | int board_early_init_f(void) |
| 387 | { |
| 388 | int err; |
| 389 | err = board_uart_init(); |
| 390 | if (err) { |
| 391 | debug("UART init failed\n"); |
| 392 | return err; |
| 393 | } |
| 394 | #ifdef CONFIG_SYS_I2C_INIT_BOARD |
| 395 | board_i2c_init(gd->fdt_blob); |
| 396 | #endif |
| 397 | return err; |
| 398 | } |
| 399 | #endif |
| 400 | |
| 401 | #ifdef CONFIG_LCD |
| 402 | void exynos_cfg_lcd_gpio(void) |
| 403 | { |
| 404 | struct exynos5_gpio_part1 *gpio1 = |
| 405 | (struct exynos5_gpio_part1 *)samsung_get_base_gpio_part1(); |
| 406 | |
| 407 | /* For Backlight */ |
| 408 | s5p_gpio_cfg_pin(&gpio1->b2, 0, GPIO_OUTPUT); |
| 409 | s5p_gpio_set_value(&gpio1->b2, 0, 1); |
| 410 | |
| 411 | /* LCD power on */ |
| 412 | s5p_gpio_cfg_pin(&gpio1->x1, 5, GPIO_OUTPUT); |
| 413 | s5p_gpio_set_value(&gpio1->x1, 5, 1); |
| 414 | |
| 415 | /* Set Hotplug detect for DP */ |
| 416 | s5p_gpio_cfg_pin(&gpio1->x0, 7, GPIO_FUNC(0x3)); |
| 417 | } |
| 418 | |
| 419 | void exynos_set_dp_phy(unsigned int onoff) |
| 420 | { |
| 421 | set_dp_phy_ctrl(onoff); |
| 422 | } |
| 423 | #endif |