trats.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics
  3. * Heungjun Kim <riverful.kim@samsung.com>
  4. * Kyungmin Park <kyungmin.park@samsung.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/cpu.h>
  27. #include <asm/arch/gpio.h>
  28. #include <asm/arch/mmc.h>
  29. #include <asm/arch/clock.h>
  30. #include <asm/arch/watchdog.h>
  31. #include <asm/arch/power.h>
  32. #include <pmic.h>
  33. #include <usb/s3c_udc.h>
  34. #include <max8998_pmic.h>
  35. #include "setup.h"
  36. DECLARE_GLOBAL_DATA_PTR;
  37. unsigned int board_rev;
  38. #ifdef CONFIG_REVISION_TAG
  39. u32 get_board_rev(void)
  40. {
  41. return board_rev;
  42. }
  43. #endif
  44. static void check_hw_revision(void);
  45. int board_init(void)
  46. {
  47. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  48. check_hw_revision();
  49. printf("HW Revision:\t0x%x\n", board_rev);
  50. #if defined(CONFIG_PMIC)
  51. pmic_init();
  52. #endif
  53. return 0;
  54. }
  55. int dram_init(void)
  56. {
  57. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE) +
  58. get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
  59. return 0;
  60. }
  61. void dram_init_banksize(void)
  62. {
  63. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  64. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  65. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  66. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  67. }
  68. static unsigned int get_hw_revision(void)
  69. {
  70. struct exynos4_gpio_part1 *gpio =
  71. (struct exynos4_gpio_part1 *)samsung_get_base_gpio_part1();
  72. int hwrev = 0;
  73. int i;
  74. /* hw_rev[3:0] == GPE1[3:0] */
  75. for (i = 0; i < 4; i++) {
  76. s5p_gpio_cfg_pin(&gpio->e1, i, GPIO_INPUT);
  77. s5p_gpio_set_pull(&gpio->e1, i, GPIO_PULL_NONE);
  78. }
  79. udelay(1);
  80. for (i = 0; i < 4; i++)
  81. hwrev |= (s5p_gpio_get_value(&gpio->e1, i) << i);
  82. debug("hwrev 0x%x\n", hwrev);
  83. return hwrev;
  84. }
  85. static void check_hw_revision(void)
  86. {
  87. int hwrev;
  88. hwrev = get_hw_revision();
  89. board_rev |= hwrev;
  90. }
  91. #ifdef CONFIG_DISPLAY_BOARDINFO
  92. int checkboard(void)
  93. {
  94. puts("Board:\tTRATS\n");
  95. return 0;
  96. }
  97. #endif
  98. #ifdef CONFIG_GENERIC_MMC
  99. int board_mmc_init(bd_t *bis)
  100. {
  101. struct exynos4_gpio_part2 *gpio =
  102. (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
  103. int i, err;
  104. /* eMMC_EN: SD_0_CDn: GPK0[2] Output High */
  105. s5p_gpio_direction_output(&gpio->k0, 2, 1);
  106. s5p_gpio_set_pull(&gpio->k0, 2, GPIO_PULL_NONE);
  107. /*
  108. * eMMC GPIO:
  109. * SDR 8-bit@48MHz at MMC0
  110. * GPK0[0] SD_0_CLK(2)
  111. * GPK0[1] SD_0_CMD(2)
  112. * GPK0[2] SD_0_CDn -> Not used
  113. * GPK0[3:6] SD_0_DATA[0:3](2)
  114. * GPK1[3:6] SD_0_DATA[0:3](3)
  115. *
  116. * DDR 4-bit@26MHz at MMC4
  117. * GPK0[0] SD_4_CLK(3)
  118. * GPK0[1] SD_4_CMD(3)
  119. * GPK0[2] SD_4_CDn -> Not used
  120. * GPK0[3:6] SD_4_DATA[0:3](3)
  121. * GPK1[3:6] SD_4_DATA[4:7](4)
  122. */
  123. for (i = 0; i < 7; i++) {
  124. if (i == 2)
  125. continue;
  126. /* GPK0[0:6] special function 2 */
  127. s5p_gpio_cfg_pin(&gpio->k0, i, 0x2);
  128. /* GPK0[0:6] pull disable */
  129. s5p_gpio_set_pull(&gpio->k0, i, GPIO_PULL_NONE);
  130. /* GPK0[0:6] drv 4x */
  131. s5p_gpio_set_drv(&gpio->k0, i, GPIO_DRV_4X);
  132. }
  133. for (i = 3; i < 7; i++) {
  134. /* GPK1[3:6] special function 3 */
  135. s5p_gpio_cfg_pin(&gpio->k1, i, 0x3);
  136. /* GPK1[3:6] pull disable */
  137. s5p_gpio_set_pull(&gpio->k1, i, GPIO_PULL_NONE);
  138. /* GPK1[3:6] drv 4x */
  139. s5p_gpio_set_drv(&gpio->k1, i, GPIO_DRV_4X);
  140. }
  141. /*
  142. * MMC device init
  143. * mmc0 : eMMC (8-bit buswidth)
  144. * mmc2 : SD card (4-bit buswidth)
  145. */
  146. err = s5p_mmc_init(0, 8);
  147. /* T-flash detect */
  148. s5p_gpio_cfg_pin(&gpio->x3, 4, 0xf);
  149. s5p_gpio_set_pull(&gpio->x3, 4, GPIO_PULL_UP);
  150. /*
  151. * Check the T-flash detect pin
  152. * GPX3[4] T-flash detect pin
  153. */
  154. if (!s5p_gpio_get_value(&gpio->x3, 4)) {
  155. /*
  156. * SD card GPIO:
  157. * GPK2[0] SD_2_CLK(2)
  158. * GPK2[1] SD_2_CMD(2)
  159. * GPK2[2] SD_2_CDn -> Not used
  160. * GPK2[3:6] SD_2_DATA[0:3](2)
  161. */
  162. for (i = 0; i < 7; i++) {
  163. if (i == 2)
  164. continue;
  165. /* GPK2[0:6] special function 2 */
  166. s5p_gpio_cfg_pin(&gpio->k2, i, 0x2);
  167. /* GPK2[0:6] pull disable */
  168. s5p_gpio_set_pull(&gpio->k2, i, GPIO_PULL_NONE);
  169. /* GPK2[0:6] drv 4x */
  170. s5p_gpio_set_drv(&gpio->k2, i, GPIO_DRV_4X);
  171. }
  172. err = s5p_mmc_init(2, 4);
  173. }
  174. return err;
  175. }
  176. #endif
  177. #ifdef CONFIG_USB_GADGET
  178. static int s5pc210_phy_control(int on)
  179. {
  180. int ret = 0;
  181. struct pmic *p = get_pmic();
  182. if (pmic_probe(p))
  183. return -1;
  184. if (on) {
  185. ret |= pmic_set_output(p,
  186. MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
  187. MAX8998_SAFEOUT1, LDO_ON);
  188. ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
  189. MAX8998_LDO3, LDO_ON);
  190. ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
  191. MAX8998_LDO8, LDO_ON);
  192. } else {
  193. ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
  194. MAX8998_LDO8, LDO_OFF);
  195. ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
  196. MAX8998_LDO3, LDO_OFF);
  197. ret |= pmic_set_output(p,
  198. MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
  199. MAX8998_SAFEOUT1, LDO_OFF);
  200. }
  201. if (ret) {
  202. puts("MAX8998 LDO setting error!\n");
  203. return -1;
  204. }
  205. return 0;
  206. }
  207. struct s3c_plat_otg_data s5pc210_otg_data = {
  208. .phy_control = s5pc210_phy_control,
  209. .regs_phy = EXYNOS4_USBPHY_BASE,
  210. .regs_otg = EXYNOS4_USBOTG_BASE,
  211. .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
  212. .usb_flags = PHY0_SLEEP,
  213. };
  214. #endif
  215. static void pmic_reset(void)
  216. {
  217. struct exynos4_gpio_part2 *gpio =
  218. (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
  219. s5p_gpio_direction_output(&gpio->x0, 7, 1);
  220. s5p_gpio_set_pull(&gpio->x2, 7, GPIO_PULL_NONE);
  221. }
  222. static void board_clock_init(void)
  223. {
  224. struct exynos4_clock *clk =
  225. (struct exynos4_clock *)samsung_get_base_clock();
  226. writel(CLK_SRC_CPU_VAL, (unsigned int)&clk->src_cpu);
  227. writel(CLK_SRC_TOP0_VAL, (unsigned int)&clk->src_top0);
  228. writel(CLK_SRC_FSYS_VAL, (unsigned int)&clk->src_fsys);
  229. writel(CLK_SRC_PERIL0_VAL, (unsigned int)&clk->src_peril0);
  230. writel(CLK_DIV_CPU0_VAL, (unsigned int)&clk->div_cpu0);
  231. writel(CLK_DIV_CPU1_VAL, (unsigned int)&clk->div_cpu1);
  232. writel(CLK_DIV_DMC0_VAL, (unsigned int)&clk->div_dmc0);
  233. writel(CLK_DIV_DMC1_VAL, (unsigned int)&clk->div_dmc1);
  234. writel(CLK_DIV_LEFTBUS_VAL, (unsigned int)&clk->div_leftbus);
  235. writel(CLK_DIV_RIGHTBUS_VAL, (unsigned int)&clk->div_rightbus);
  236. writel(CLK_DIV_TOP_VAL, (unsigned int)&clk->div_top);
  237. writel(CLK_DIV_FSYS1_VAL, (unsigned int)&clk->div_fsys1);
  238. writel(CLK_DIV_FSYS2_VAL, (unsigned int)&clk->div_fsys2);
  239. writel(CLK_DIV_FSYS3_VAL, (unsigned int)&clk->div_fsys3);
  240. writel(CLK_DIV_PERIL0_VAL, (unsigned int)&clk->div_peril0);
  241. writel(CLK_DIV_PERIL3_VAL, (unsigned int)&clk->div_peril3);
  242. writel(PLL_LOCKTIME, (unsigned int)&clk->apll_lock);
  243. writel(PLL_LOCKTIME, (unsigned int)&clk->mpll_lock);
  244. writel(PLL_LOCKTIME, (unsigned int)&clk->epll_lock);
  245. writel(PLL_LOCKTIME, (unsigned int)&clk->vpll_lock);
  246. writel(APLL_CON1_VAL, (unsigned int)&clk->apll_con1);
  247. writel(APLL_CON0_VAL, (unsigned int)&clk->apll_con0);
  248. writel(MPLL_CON1_VAL, (unsigned int)&clk->mpll_con1);
  249. writel(MPLL_CON0_VAL, (unsigned int)&clk->mpll_con0);
  250. writel(EPLL_CON1_VAL, (unsigned int)&clk->epll_con1);
  251. writel(EPLL_CON0_VAL, (unsigned int)&clk->epll_con0);
  252. writel(VPLL_CON1_VAL, (unsigned int)&clk->vpll_con1);
  253. writel(VPLL_CON0_VAL, (unsigned int)&clk->vpll_con0);
  254. writel(CLK_GATE_IP_CAM_VAL, (unsigned int)&clk->gate_ip_cam);
  255. writel(CLK_GATE_IP_VP_VAL, (unsigned int)&clk->gate_ip_tv);
  256. writel(CLK_GATE_IP_MFC_VAL, (unsigned int)&clk->gate_ip_mfc);
  257. writel(CLK_GATE_IP_G3D_VAL, (unsigned int)&clk->gate_ip_g3d);
  258. writel(CLK_GATE_IP_IMAGE_VAL, (unsigned int)&clk->gate_ip_image);
  259. writel(CLK_GATE_IP_LCD0_VAL, (unsigned int)&clk->gate_ip_lcd0);
  260. writel(CLK_GATE_IP_LCD1_VAL, (unsigned int)&clk->gate_ip_lcd1);
  261. writel(CLK_GATE_IP_FSYS_VAL, (unsigned int)&clk->gate_ip_fsys);
  262. writel(CLK_GATE_IP_GPS_VAL, (unsigned int)&clk->gate_ip_gps);
  263. writel(CLK_GATE_IP_PERIL_VAL, (unsigned int)&clk->gate_ip_peril);
  264. writel(CLK_GATE_IP_PERIR_VAL, (unsigned int)&clk->gate_ip_perir);
  265. writel(CLK_GATE_BLOCK_VAL, (unsigned int)&clk->gate_block);
  266. }
  267. static void board_power_init(void)
  268. {
  269. struct exynos4_power *pwr =
  270. (struct exynos4_power *)samsung_get_base_power();
  271. /* PS HOLD */
  272. writel(EXYNOS4_PS_HOLD_CON_VAL, (unsigned int)&pwr->ps_hold_control);
  273. /* Set power down */
  274. writel(0, (unsigned int)&pwr->cam_configuration);
  275. writel(0, (unsigned int)&pwr->tv_configuration);
  276. writel(0, (unsigned int)&pwr->mfc_configuration);
  277. writel(0, (unsigned int)&pwr->g3d_configuration);
  278. writel(0, (unsigned int)&pwr->lcd1_configuration);
  279. writel(0, (unsigned int)&pwr->gps_configuration);
  280. writel(0, (unsigned int)&pwr->gps_alive_configuration);
  281. }
  282. static void board_uart_init(void)
  283. {
  284. struct exynos4_gpio_part1 *gpio1 =
  285. (struct exynos4_gpio_part1 *)samsung_get_base_gpio_part1();
  286. struct exynos4_gpio_part2 *gpio2 =
  287. (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
  288. int i;
  289. /*
  290. * UART2 GPIOs
  291. * GPA1CON[0] = UART_2_RXD(2)
  292. * GPA1CON[1] = UART_2_TXD(2)
  293. * GPA1CON[2] = I2C_3_SDA (3)
  294. * GPA1CON[3] = I2C_3_SCL (3)
  295. */
  296. for (i = 0; i < 4; i++) {
  297. s5p_gpio_set_pull(&gpio1->a1, i, GPIO_PULL_NONE);
  298. s5p_gpio_cfg_pin(&gpio1->a1, i, GPIO_FUNC((i > 1) ? 0x3 : 0x2));
  299. }
  300. /* UART_SEL GPY4[7] (part2) at EXYNOS4 */
  301. s5p_gpio_set_pull(&gpio2->y4, 7, GPIO_PULL_UP);
  302. s5p_gpio_direction_output(&gpio2->y4, 7, 1);
  303. }
  304. int board_early_init_f(void)
  305. {
  306. wdt_stop();
  307. pmic_reset();
  308. board_clock_init();
  309. board_uart_init();
  310. board_power_init();
  311. return 0;
  312. }