exynos5-dt.c 11 KB

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