smdk5250.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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 <lcd.h>
  28. #include <netdev.h>
  29. #include <spi.h>
  30. #include <asm/arch/cpu.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 <asm/arch/dp_info.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. #ifdef CONFIG_USB_EHCI_EXYNOS
  69. int board_usb_vbus_init(void)
  70. {
  71. struct exynos5_gpio_part1 *gpio1 = (struct exynos5_gpio_part1 *)
  72. samsung_get_base_gpio_part1();
  73. /* Enable VBUS power switch */
  74. s5p_gpio_direction_output(&gpio1->x2, 6, 1);
  75. /* VBUS turn ON time */
  76. mdelay(3);
  77. return 0;
  78. }
  79. #endif
  80. #ifdef CONFIG_SOUND_MAX98095
  81. static void board_enable_audio_codec(void)
  82. {
  83. struct exynos5_gpio_part1 *gpio1 = (struct exynos5_gpio_part1 *)
  84. samsung_get_base_gpio_part1();
  85. /* Enable MAX98095 Codec */
  86. s5p_gpio_direction_output(&gpio1->x1, 7, 1);
  87. s5p_gpio_set_pull(&gpio1->x1, 7, GPIO_PULL_NONE);
  88. }
  89. #endif
  90. int board_init(void)
  91. {
  92. gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
  93. #if defined CONFIG_EXYNOS_TMU
  94. if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
  95. debug("%s: Failed to init TMU\n", __func__);
  96. return -1;
  97. }
  98. boot_temp_check();
  99. #endif
  100. #ifdef CONFIG_EXYNOS_SPI
  101. spi_init();
  102. #endif
  103. #ifdef CONFIG_USB_EHCI_EXYNOS
  104. board_usb_vbus_init();
  105. #endif
  106. #ifdef CONFIG_SOUND_MAX98095
  107. board_enable_audio_codec();
  108. #endif
  109. return 0;
  110. }
  111. int dram_init(void)
  112. {
  113. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE)
  114. + get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE)
  115. + get_ram_size((long *)PHYS_SDRAM_3, PHYS_SDRAM_3_SIZE)
  116. + get_ram_size((long *)PHYS_SDRAM_4, PHYS_SDRAM_4_SIZE)
  117. + get_ram_size((long *)PHYS_SDRAM_5, PHYS_SDRAM_7_SIZE)
  118. + get_ram_size((long *)PHYS_SDRAM_6, PHYS_SDRAM_7_SIZE)
  119. + get_ram_size((long *)PHYS_SDRAM_7, PHYS_SDRAM_7_SIZE)
  120. + get_ram_size((long *)PHYS_SDRAM_8, PHYS_SDRAM_8_SIZE);
  121. return 0;
  122. }
  123. #if defined(CONFIG_POWER)
  124. static int pmic_reg_update(struct pmic *p, int reg, uint regval)
  125. {
  126. u32 val;
  127. int ret = 0;
  128. ret = pmic_reg_read(p, reg, &val);
  129. if (ret) {
  130. debug("%s: PMIC %d register read failed\n", __func__, reg);
  131. return -1;
  132. }
  133. val |= regval;
  134. ret = pmic_reg_write(p, reg, val);
  135. if (ret) {
  136. debug("%s: PMIC %d register write failed\n", __func__, reg);
  137. return -1;
  138. }
  139. return 0;
  140. }
  141. int power_init_board(void)
  142. {
  143. struct pmic *p;
  144. set_ps_hold_ctrl();
  145. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  146. if (pmic_init(I2C_PMIC))
  147. return -1;
  148. p = pmic_get("MAX77686_PMIC");
  149. if (!p)
  150. return -ENODEV;
  151. if (pmic_probe(p))
  152. return -1;
  153. if (pmic_reg_update(p, MAX77686_REG_PMIC_32KHZ, MAX77686_32KHCP_EN))
  154. return -1;
  155. if (pmic_reg_update(p, MAX77686_REG_PMIC_BBAT,
  156. MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V))
  157. return -1;
  158. /* VDD_MIF */
  159. if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK1OUT,
  160. MAX77686_BUCK1OUT_1V)) {
  161. debug("%s: PMIC %d register write failed\n", __func__,
  162. MAX77686_REG_PMIC_BUCK1OUT);
  163. return -1;
  164. }
  165. if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK1CRTL,
  166. MAX77686_BUCK1CTRL_EN))
  167. return -1;
  168. /* VDD_ARM */
  169. if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK2DVS1,
  170. MAX77686_BUCK2DVS1_1_3V)) {
  171. debug("%s: PMIC %d register write failed\n", __func__,
  172. MAX77686_REG_PMIC_BUCK2DVS1);
  173. return -1;
  174. }
  175. if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK2CTRL1,
  176. MAX77686_BUCK2CTRL_ON))
  177. return -1;
  178. /* VDD_INT */
  179. if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK3DVS1,
  180. MAX77686_BUCK3DVS1_1_0125V)) {
  181. debug("%s: PMIC %d register write failed\n", __func__,
  182. MAX77686_REG_PMIC_BUCK3DVS1);
  183. return -1;
  184. }
  185. if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK3CTRL,
  186. MAX77686_BUCK3CTRL_ON))
  187. return -1;
  188. /* VDD_G3D */
  189. if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK4DVS1,
  190. MAX77686_BUCK4DVS1_1_2V)) {
  191. debug("%s: PMIC %d register write failed\n", __func__,
  192. MAX77686_REG_PMIC_BUCK4DVS1);
  193. return -1;
  194. }
  195. if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK4CTRL1,
  196. MAX77686_BUCK3CTRL_ON))
  197. return -1;
  198. /* VDD_LDO2 */
  199. if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO2CTRL1,
  200. MAX77686_LD02CTRL1_1_5V | EN_LDO))
  201. return -1;
  202. /* VDD_LDO3 */
  203. if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO3CTRL1,
  204. MAX77686_LD03CTRL1_1_8V | EN_LDO))
  205. return -1;
  206. /* VDD_LDO5 */
  207. if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO5CTRL1,
  208. MAX77686_LD05CTRL1_1_8V | EN_LDO))
  209. return -1;
  210. /* VDD_LDO10 */
  211. if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO10CTRL1,
  212. MAX77686_LD10CTRL1_1_8V | EN_LDO))
  213. return -1;
  214. return 0;
  215. }
  216. #endif
  217. void dram_init_banksize(void)
  218. {
  219. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  220. gd->bd->bi_dram[0].size = get_ram_size((long *)PHYS_SDRAM_1,
  221. PHYS_SDRAM_1_SIZE);
  222. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  223. gd->bd->bi_dram[1].size = get_ram_size((long *)PHYS_SDRAM_2,
  224. PHYS_SDRAM_2_SIZE);
  225. gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
  226. gd->bd->bi_dram[2].size = get_ram_size((long *)PHYS_SDRAM_3,
  227. PHYS_SDRAM_3_SIZE);
  228. gd->bd->bi_dram[3].start = PHYS_SDRAM_4;
  229. gd->bd->bi_dram[3].size = get_ram_size((long *)PHYS_SDRAM_4,
  230. PHYS_SDRAM_4_SIZE);
  231. gd->bd->bi_dram[4].start = PHYS_SDRAM_5;
  232. gd->bd->bi_dram[4].size = get_ram_size((long *)PHYS_SDRAM_5,
  233. PHYS_SDRAM_5_SIZE);
  234. gd->bd->bi_dram[5].start = PHYS_SDRAM_6;
  235. gd->bd->bi_dram[5].size = get_ram_size((long *)PHYS_SDRAM_6,
  236. PHYS_SDRAM_6_SIZE);
  237. gd->bd->bi_dram[6].start = PHYS_SDRAM_7;
  238. gd->bd->bi_dram[6].size = get_ram_size((long *)PHYS_SDRAM_7,
  239. PHYS_SDRAM_7_SIZE);
  240. gd->bd->bi_dram[7].start = PHYS_SDRAM_8;
  241. gd->bd->bi_dram[7].size = get_ram_size((long *)PHYS_SDRAM_8,
  242. PHYS_SDRAM_8_SIZE);
  243. }
  244. #ifdef CONFIG_OF_CONTROL
  245. static int decode_sromc(const void *blob, struct fdt_sromc *config)
  246. {
  247. int err;
  248. int node;
  249. node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SROMC);
  250. if (node < 0) {
  251. debug("Could not find SROMC node\n");
  252. return node;
  253. }
  254. config->bank = fdtdec_get_int(blob, node, "bank", 0);
  255. config->width = fdtdec_get_int(blob, node, "width", 2);
  256. err = fdtdec_get_int_array(blob, node, "srom-timing", config->timing,
  257. FDT_SROM_TIMING_COUNT);
  258. if (err < 0) {
  259. debug("Could not decode SROMC configuration\n");
  260. return -FDT_ERR_NOTFOUND;
  261. }
  262. return 0;
  263. }
  264. #endif
  265. int board_eth_init(bd_t *bis)
  266. {
  267. #ifdef CONFIG_SMC911X
  268. u32 smc_bw_conf, smc_bc_conf;
  269. struct fdt_sromc config;
  270. fdt_addr_t base_addr;
  271. int node;
  272. #ifdef CONFIG_OF_CONTROL
  273. node = decode_sromc(gd->fdt_blob, &config);
  274. if (node < 0) {
  275. debug("%s: Could not find sromc configuration\n", __func__);
  276. return 0;
  277. }
  278. node = fdtdec_next_compatible(gd->fdt_blob, node, COMPAT_SMSC_LAN9215);
  279. if (node < 0) {
  280. debug("%s: Could not find lan9215 configuration\n", __func__);
  281. return 0;
  282. }
  283. /* We now have a node, so any problems from now on are errors */
  284. base_addr = fdtdec_get_addr(gd->fdt_blob, node, "reg");
  285. if (base_addr == FDT_ADDR_T_NONE) {
  286. debug("%s: Could not find lan9215 address\n", __func__);
  287. return -1;
  288. }
  289. #else
  290. /* Non-FDT configuration - bank number and timing parameters*/
  291. config.bank = CONFIG_ENV_SROM_BANK;
  292. config.width = 2;
  293. config.timing[FDT_SROM_TACS] = 0x01;
  294. config.timing[FDT_SROM_TCOS] = 0x01;
  295. config.timing[FDT_SROM_TACC] = 0x06;
  296. config.timing[FDT_SROM_TCOH] = 0x01;
  297. config.timing[FDT_SROM_TAH] = 0x0C;
  298. config.timing[FDT_SROM_TACP] = 0x09;
  299. config.timing[FDT_SROM_PMC] = 0x01;
  300. base_addr = CONFIG_SMC911X_BASE;
  301. #endif
  302. /* Ethernet needs data bus width of 16 bits */
  303. if (config.width != 2) {
  304. debug("%s: Unsupported bus width %d\n", __func__,
  305. config.width);
  306. return -1;
  307. }
  308. smc_bw_conf = SROMC_DATA16_WIDTH(config.bank)
  309. | SROMC_BYTE_ENABLE(config.bank);
  310. smc_bc_conf = SROMC_BC_TACS(config.timing[FDT_SROM_TACS]) |\
  311. SROMC_BC_TCOS(config.timing[FDT_SROM_TCOS]) |\
  312. SROMC_BC_TACC(config.timing[FDT_SROM_TACC]) |\
  313. SROMC_BC_TCOH(config.timing[FDT_SROM_TCOH]) |\
  314. SROMC_BC_TAH(config.timing[FDT_SROM_TAH]) |\
  315. SROMC_BC_TACP(config.timing[FDT_SROM_TACP]) |\
  316. SROMC_BC_PMC(config.timing[FDT_SROM_PMC]);
  317. /* Select and configure the SROMC bank */
  318. exynos_pinmux_config(PERIPH_ID_SROMC, config.bank);
  319. s5p_config_sromc(config.bank, smc_bw_conf, smc_bc_conf);
  320. return smc911x_initialize(0, base_addr);
  321. #endif
  322. return 0;
  323. }
  324. #ifdef CONFIG_DISPLAY_BOARDINFO
  325. int checkboard(void)
  326. {
  327. #ifdef CONFIG_OF_CONTROL
  328. const char *board_name;
  329. board_name = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
  330. if (board_name == NULL)
  331. printf("\nUnknown Board\n");
  332. else
  333. printf("\nBoard: %s\n", board_name);
  334. #else
  335. printf("\nBoard: SMDK5250\n");
  336. #endif
  337. return 0;
  338. }
  339. #endif
  340. #ifdef CONFIG_GENERIC_MMC
  341. int board_mmc_init(bd_t *bis)
  342. {
  343. int err;
  344. err = exynos_pinmux_config(PERIPH_ID_SDMMC0, PINMUX_FLAG_8BIT_MODE);
  345. if (err) {
  346. debug("SDMMC0 not configured\n");
  347. return err;
  348. }
  349. err = s5p_mmc_init(0, 8);
  350. return err;
  351. }
  352. #endif
  353. static int board_uart_init(void)
  354. {
  355. int err;
  356. err = exynos_pinmux_config(PERIPH_ID_UART0, PINMUX_FLAG_NONE);
  357. if (err) {
  358. debug("UART0 not configured\n");
  359. return err;
  360. }
  361. err = exynos_pinmux_config(PERIPH_ID_UART1, PINMUX_FLAG_NONE);
  362. if (err) {
  363. debug("UART1 not configured\n");
  364. return err;
  365. }
  366. err = exynos_pinmux_config(PERIPH_ID_UART2, PINMUX_FLAG_NONE);
  367. if (err) {
  368. debug("UART2 not configured\n");
  369. return err;
  370. }
  371. err = exynos_pinmux_config(PERIPH_ID_UART3, PINMUX_FLAG_NONE);
  372. if (err) {
  373. debug("UART3 not configured\n");
  374. return err;
  375. }
  376. return 0;
  377. }
  378. #ifdef CONFIG_BOARD_EARLY_INIT_F
  379. int board_early_init_f(void)
  380. {
  381. int err;
  382. err = board_uart_init();
  383. if (err) {
  384. debug("UART init failed\n");
  385. return err;
  386. }
  387. #ifdef CONFIG_SYS_I2C_INIT_BOARD
  388. board_i2c_init(gd->fdt_blob);
  389. #endif
  390. return err;
  391. }
  392. #endif
  393. #ifdef CONFIG_LCD
  394. void cfg_lcd_gpio(void)
  395. {
  396. struct exynos5_gpio_part1 *gpio1 =
  397. (struct exynos5_gpio_part1 *) samsung_get_base_gpio_part1();
  398. /* For Backlight */
  399. s5p_gpio_cfg_pin(&gpio1->b2, 0, GPIO_OUTPUT);
  400. s5p_gpio_set_value(&gpio1->b2, 0, 1);
  401. /* LCD power on */
  402. s5p_gpio_cfg_pin(&gpio1->x1, 5, GPIO_OUTPUT);
  403. s5p_gpio_set_value(&gpio1->x1, 5, 1);
  404. /* Set Hotplug detect for DP */
  405. s5p_gpio_cfg_pin(&gpio1->x0, 7, GPIO_FUNC(0x3));
  406. }
  407. vidinfo_t panel_info = {
  408. .vl_freq = 60,
  409. .vl_col = 2560,
  410. .vl_row = 1600,
  411. .vl_width = 2560,
  412. .vl_height = 1600,
  413. .vl_clkp = CONFIG_SYS_LOW,
  414. .vl_hsp = CONFIG_SYS_LOW,
  415. .vl_vsp = CONFIG_SYS_LOW,
  416. .vl_dp = CONFIG_SYS_LOW,
  417. .vl_bpix = 4, /* LCD_BPP = 2^4, for output conosle on LCD */
  418. /* wDP panel timing infomation */
  419. .vl_hspw = 32,
  420. .vl_hbpd = 80,
  421. .vl_hfpd = 48,
  422. .vl_vspw = 6,
  423. .vl_vbpd = 37,
  424. .vl_vfpd = 3,
  425. .vl_cmd_allow_len = 0xf,
  426. .win_id = 3,
  427. .cfg_gpio = cfg_lcd_gpio,
  428. .backlight_on = NULL,
  429. .lcd_power_on = NULL,
  430. .reset_lcd = NULL,
  431. .dual_lcd_enabled = 0,
  432. .init_delay = 0,
  433. .power_on_delay = 0,
  434. .reset_delay = 0,
  435. .interface_mode = FIMD_RGB_INTERFACE,
  436. .dp_enabled = 1,
  437. };
  438. static struct edp_device_info edp_info = {
  439. .disp_info = {
  440. .h_res = 2560,
  441. .h_sync_width = 32,
  442. .h_back_porch = 80,
  443. .h_front_porch = 48,
  444. .v_res = 1600,
  445. .v_sync_width = 6,
  446. .v_back_porch = 37,
  447. .v_front_porch = 3,
  448. .v_sync_rate = 60,
  449. },
  450. .lt_info = {
  451. .lt_status = DP_LT_NONE,
  452. },
  453. .video_info = {
  454. .master_mode = 0,
  455. .bist_mode = DP_DISABLE,
  456. .bist_pattern = NO_PATTERN,
  457. .h_sync_polarity = 0,
  458. .v_sync_polarity = 0,
  459. .interlaced = 0,
  460. .color_space = COLOR_RGB,
  461. .dynamic_range = VESA,
  462. .ycbcr_coeff = COLOR_YCBCR601,
  463. .color_depth = COLOR_8,
  464. },
  465. };
  466. static struct exynos_dp_platform_data dp_platform_data = {
  467. .phy_enable = set_dp_phy_ctrl,
  468. .edp_dev_info = &edp_info,
  469. };
  470. void init_panel_info(vidinfo_t *vid)
  471. {
  472. vid->rgb_mode = MODE_RGB_P,
  473. exynos_set_dp_platform_data(&dp_platform_data);
  474. }
  475. #endif