exynos5-dt.c 9.6 KB

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