trats.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics
  3. * Heungjun Kim <riverful.kim@samsung.com>
  4. * Kyungmin Park <kyungmin.park@samsung.com>
  5. * Donghwa Lee <dh09.lee@samsung.com>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <lcd.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/cpu.h>
  29. #include <asm/arch/gpio.h>
  30. #include <asm/arch/mmc.h>
  31. #include <asm/arch/pinmux.h>
  32. #include <asm/arch/clock.h>
  33. #include <asm/arch/clk.h>
  34. #include <asm/arch/mipi_dsim.h>
  35. #include <asm/arch/watchdog.h>
  36. #include <asm/arch/power.h>
  37. #include <power/pmic.h>
  38. #include <usb/s3c_udc.h>
  39. #include <power/max8997_pmic.h>
  40. #include <libtizen.h>
  41. #include <power/max8997_muic.h>
  42. #include <power/battery.h>
  43. #include <power/max17042_fg.h>
  44. #include <usb_mass_storage.h>
  45. #include "setup.h"
  46. DECLARE_GLOBAL_DATA_PTR;
  47. unsigned int board_rev;
  48. #ifdef CONFIG_REVISION_TAG
  49. u32 get_board_rev(void)
  50. {
  51. return board_rev;
  52. }
  53. #endif
  54. static void check_hw_revision(void);
  55. struct s3c_plat_otg_data s5pc210_otg_data;
  56. int board_init(void)
  57. {
  58. gd->bd->bi_boot_params = CONFIG_SYS_SPL_ARGS_ADDR;
  59. check_hw_revision();
  60. printf("HW Revision:\t0x%x\n", board_rev);
  61. return 0;
  62. }
  63. void i2c_init_board(void)
  64. {
  65. struct exynos4_gpio_part1 *gpio1 =
  66. (struct exynos4_gpio_part1 *)samsung_get_base_gpio_part1();
  67. struct exynos4_gpio_part2 *gpio2 =
  68. (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
  69. /* I2C_5 -> PMIC */
  70. s5p_gpio_direction_output(&gpio1->b, 7, 1);
  71. s5p_gpio_direction_output(&gpio1->b, 6, 1);
  72. /* I2C_9 -> FG */
  73. s5p_gpio_direction_output(&gpio2->y4, 0, 1);
  74. s5p_gpio_direction_output(&gpio2->y4, 1, 1);
  75. }
  76. static void trats_low_power_mode(void)
  77. {
  78. struct exynos4_clock *clk =
  79. (struct exynos4_clock *)samsung_get_base_clock();
  80. struct exynos4_power *pwr =
  81. (struct exynos4_power *)samsung_get_base_power();
  82. /* Power down CORE1 */
  83. /* LOCAL_PWR_CFG [1:0] 0x3 EN, 0x0 DIS */
  84. writel(0x0, &pwr->arm_core1_configuration);
  85. /* Change the APLL frequency */
  86. /* ENABLE (1 enable) | LOCKED (1 locked) */
  87. /* [31] | [29] */
  88. /* FSEL | MDIV | PDIV | SDIV */
  89. /* [27] | [25:16] | [13:8] | [2:0] */
  90. writel(0xa0c80604, &clk->apll_con0);
  91. /* Change CPU0 clock divider */
  92. /* CORE2_RATIO | APLL_RATIO | PCLK_DBG_RATIO | ATB_RATIO */
  93. /* [30:28] | [26:24] | [22:20] | [18:16] */
  94. /* PERIPH_RATIO | COREM1_RATIO | COREM0_RATIO | CORE_RATIO */
  95. /* [14:12] | [10:8] | [6:4] | [2:0] */
  96. writel(0x00000100, &clk->div_cpu0);
  97. /* CLK_DIV_STAT_CPU0 - wait until clock gets stable (0 = stable) */
  98. while (readl(&clk->div_stat_cpu0) & 0x1111111)
  99. continue;
  100. /* Change clock divider ratio for DMC */
  101. /* DMCP_RATIO | DMCD_RATIO */
  102. /* [22:20] | [18:16] */
  103. /* DMC_RATIO | DPHY_RATIO | ACP_PCLK_RATIO | ACP_RATIO */
  104. /* [14:12] | [10:8] | [6:4] | [2:0] */
  105. writel(0x13113117, &clk->div_dmc0);
  106. /* CLK_DIV_STAT_DMC0 - wait until clock gets stable (0 = stable) */
  107. while (readl(&clk->div_stat_dmc0) & 0x11111111)
  108. continue;
  109. /* Turn off unnecessary power domains */
  110. writel(0x0, &pwr->xxti_configuration); /* XXTI */
  111. writel(0x0, &pwr->cam_configuration); /* CAM */
  112. writel(0x0, &pwr->tv_configuration); /* TV */
  113. writel(0x0, &pwr->mfc_configuration); /* MFC */
  114. writel(0x0, &pwr->g3d_configuration); /* G3D */
  115. writel(0x0, &pwr->gps_configuration); /* GPS */
  116. writel(0x0, &pwr->gps_alive_configuration); /* GPS_ALIVE */
  117. /* Turn off unnecessary clocks */
  118. writel(0x0, &clk->gate_ip_cam); /* CAM */
  119. writel(0x0, &clk->gate_ip_tv); /* TV */
  120. writel(0x0, &clk->gate_ip_mfc); /* MFC */
  121. writel(0x0, &clk->gate_ip_g3d); /* G3D */
  122. writel(0x0, &clk->gate_ip_image); /* IMAGE */
  123. writel(0x0, &clk->gate_ip_gps); /* GPS */
  124. }
  125. static int pmic_init_max8997(void)
  126. {
  127. struct pmic *p = pmic_get("MAX8997_PMIC");
  128. int i = 0, ret = 0;
  129. u32 val;
  130. if (pmic_probe(p))
  131. return -1;
  132. /* BUCK1 VARM: 1.2V */
  133. val = (1200000 - 650000) / 25000;
  134. ret |= pmic_reg_write(p, MAX8997_REG_BUCK1DVS1, val);
  135. val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */
  136. ret |= pmic_reg_write(p, MAX8997_REG_BUCK1CTRL, val);
  137. /* BUCK2 VINT: 1.1V */
  138. val = (1100000 - 650000) / 25000;
  139. ret |= pmic_reg_write(p, MAX8997_REG_BUCK2DVS1, val);
  140. val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */
  141. ret |= pmic_reg_write(p, MAX8997_REG_BUCK2CTRL, val);
  142. /* BUCK3 G3D: 1.1V - OFF */
  143. ret |= pmic_reg_read(p, MAX8997_REG_BUCK3CTRL, &val);
  144. val &= ~ENBUCK;
  145. ret |= pmic_reg_write(p, MAX8997_REG_BUCK3CTRL, val);
  146. val = (1100000 - 750000) / 50000;
  147. ret |= pmic_reg_write(p, MAX8997_REG_BUCK3DVS, val);
  148. /* BUCK4 CAMISP: 1.2V - OFF */
  149. ret |= pmic_reg_read(p, MAX8997_REG_BUCK4CTRL, &val);
  150. val &= ~ENBUCK;
  151. ret |= pmic_reg_write(p, MAX8997_REG_BUCK4CTRL, val);
  152. val = (1200000 - 650000) / 25000;
  153. ret |= pmic_reg_write(p, MAX8997_REG_BUCK4DVS, val);
  154. /* BUCK5 VMEM: 1.2V */
  155. val = (1200000 - 650000) / 25000;
  156. for (i = 0; i < 8; i++)
  157. ret |= pmic_reg_write(p, MAX8997_REG_BUCK5DVS1 + i, val);
  158. val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */
  159. ret |= pmic_reg_write(p, MAX8997_REG_BUCK5CTRL, val);
  160. /* BUCK6 CAM AF: 2.8V */
  161. /* No Voltage Setting Register */
  162. /* GNSLCT 3.0X */
  163. val = GNSLCT;
  164. ret |= pmic_reg_write(p, MAX8997_REG_BUCK6CTRL, val);
  165. /* BUCK7 VCC_SUB: 2.0V */
  166. val = (2000000 - 750000) / 50000;
  167. ret |= pmic_reg_write(p, MAX8997_REG_BUCK7DVS, val);
  168. /* LDO1 VADC: 3.3V */
  169. val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */
  170. ret |= pmic_reg_write(p, MAX8997_REG_LDO1CTRL, val);
  171. /* LDO1 Disable active discharging */
  172. ret |= pmic_reg_read(p, MAX8997_REG_LDO1CONFIG, &val);
  173. val &= ~LDO_ADE;
  174. ret |= pmic_reg_write(p, MAX8997_REG_LDO1CONFIG, val);
  175. /* LDO2 VALIVE: 1.1V */
  176. val = max8997_reg_ldo(1100000) | EN_LDO;
  177. ret |= pmic_reg_write(p, MAX8997_REG_LDO2CTRL, val);
  178. /* LDO3 VUSB/MIPI: 1.1V */
  179. val = max8997_reg_ldo(1100000) | DIS_LDO; /* OFF */
  180. ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, val);
  181. /* LDO4 VMIPI: 1.8V */
  182. val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
  183. ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, val);
  184. /* LDO5 VHSIC: 1.2V */
  185. val = max8997_reg_ldo(1200000) | DIS_LDO; /* OFF */
  186. ret |= pmic_reg_write(p, MAX8997_REG_LDO5CTRL, val);
  187. /* LDO6 VCC_1.8V_PDA: 1.8V */
  188. val = max8997_reg_ldo(1800000) | EN_LDO;
  189. ret |= pmic_reg_write(p, MAX8997_REG_LDO6CTRL, val);
  190. /* LDO7 CAM_ISP: 1.8V */
  191. val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
  192. ret |= pmic_reg_write(p, MAX8997_REG_LDO7CTRL, val);
  193. /* LDO8 VDAC/VUSB: 3.3V */
  194. val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */
  195. ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, val);
  196. /* LDO9 VCC_2.8V_PDA: 2.8V */
  197. val = max8997_reg_ldo(2800000) | EN_LDO;
  198. ret |= pmic_reg_write(p, MAX8997_REG_LDO9CTRL, val);
  199. /* LDO10 VPLL: 1.1V */
  200. val = max8997_reg_ldo(1100000) | EN_LDO;
  201. ret |= pmic_reg_write(p, MAX8997_REG_LDO10CTRL, val);
  202. /* LDO11 TOUCH: 2.8V */
  203. val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */
  204. ret |= pmic_reg_write(p, MAX8997_REG_LDO11CTRL, val);
  205. /* LDO12 VTCAM: 1.8V */
  206. val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
  207. ret |= pmic_reg_write(p, MAX8997_REG_LDO12CTRL, val);
  208. /* LDO13 VCC_3.0_LCD: 3.0V */
  209. val = max8997_reg_ldo(3000000) | DIS_LDO; /* OFF */
  210. ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, val);
  211. /* LDO14 MOTOR: 3.0V */
  212. val = max8997_reg_ldo(3000000) | DIS_LDO; /* OFF */
  213. ret |= pmic_reg_write(p, MAX8997_REG_LDO14CTRL, val);
  214. /* LDO15 LED_A: 2.8V */
  215. val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */
  216. ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, val);
  217. /* LDO16 CAM_SENSOR: 1.8V */
  218. val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
  219. ret |= pmic_reg_write(p, MAX8997_REG_LDO16CTRL, val);
  220. /* LDO17 VTF: 2.8V */
  221. val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */
  222. ret |= pmic_reg_write(p, MAX8997_REG_LDO17CTRL, val);
  223. /* LDO18 TOUCH_LED 3.3V */
  224. val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */
  225. ret |= pmic_reg_write(p, MAX8997_REG_LDO18CTRL, val);
  226. /* LDO21 VDDQ: 1.2V */
  227. val = max8997_reg_ldo(1200000) | EN_LDO;
  228. ret |= pmic_reg_write(p, MAX8997_REG_LDO21CTRL, val);
  229. /* SAFEOUT for both 1 and 2: 4.9V, Active discharge, Enable */
  230. val = (SAFEOUT_4_90V << 0) | (SAFEOUT_4_90V << 2) |
  231. ACTDISSAFEO1 | ACTDISSAFEO2 | ENSAFEOUT1 | ENSAFEOUT2;
  232. ret |= pmic_reg_write(p, MAX8997_REG_SAFEOUTCTRL, val);
  233. if (ret) {
  234. puts("MAX8997 PMIC setting error!\n");
  235. return -1;
  236. }
  237. return 0;
  238. }
  239. int power_init_board(void)
  240. {
  241. int chrg, ret;
  242. struct power_battery *pb;
  243. struct pmic *p_fg, *p_chrg, *p_muic, *p_bat;
  244. ret = pmic_init(I2C_5);
  245. ret |= pmic_init_max8997();
  246. ret |= power_fg_init(I2C_9);
  247. ret |= power_muic_init(I2C_5);
  248. ret |= power_bat_init(0);
  249. if (ret)
  250. return ret;
  251. p_fg = pmic_get("MAX17042_FG");
  252. if (!p_fg) {
  253. puts("MAX17042_FG: Not found\n");
  254. return -ENODEV;
  255. }
  256. p_chrg = pmic_get("MAX8997_PMIC");
  257. if (!p_chrg) {
  258. puts("MAX8997_PMIC: Not found\n");
  259. return -ENODEV;
  260. }
  261. p_muic = pmic_get("MAX8997_MUIC");
  262. if (!p_muic) {
  263. puts("MAX8997_MUIC: Not found\n");
  264. return -ENODEV;
  265. }
  266. p_bat = pmic_get("BAT_TRATS");
  267. if (!p_bat) {
  268. puts("BAT_TRATS: Not found\n");
  269. return -ENODEV;
  270. }
  271. p_fg->parent = p_bat;
  272. p_chrg->parent = p_bat;
  273. p_muic->parent = p_bat;
  274. p_bat->low_power_mode = trats_low_power_mode;
  275. p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
  276. pb = p_bat->pbat;
  277. chrg = p_muic->chrg->chrg_type(p_muic);
  278. debug("CHARGER TYPE: %d\n", chrg);
  279. if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
  280. puts("No battery detected\n");
  281. return -1;
  282. }
  283. p_fg->fg->fg_battery_check(p_fg, p_bat);
  284. if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
  285. puts("CHARGE Battery !\n");
  286. return 0;
  287. }
  288. int dram_init(void)
  289. {
  290. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE) +
  291. get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE) +
  292. get_ram_size((long *)PHYS_SDRAM_3, PHYS_SDRAM_3_SIZE) +
  293. get_ram_size((long *)PHYS_SDRAM_4, PHYS_SDRAM_4_SIZE);
  294. return 0;
  295. }
  296. void dram_init_banksize(void)
  297. {
  298. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  299. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  300. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  301. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  302. gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
  303. gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
  304. gd->bd->bi_dram[3].start = PHYS_SDRAM_4;
  305. gd->bd->bi_dram[3].size = PHYS_SDRAM_4_SIZE;
  306. }
  307. static unsigned int get_hw_revision(void)
  308. {
  309. struct exynos4_gpio_part1 *gpio =
  310. (struct exynos4_gpio_part1 *)samsung_get_base_gpio_part1();
  311. int hwrev = 0;
  312. int i;
  313. /* hw_rev[3:0] == GPE1[3:0] */
  314. for (i = 0; i < 4; i++) {
  315. s5p_gpio_cfg_pin(&gpio->e1, i, GPIO_INPUT);
  316. s5p_gpio_set_pull(&gpio->e1, i, GPIO_PULL_NONE);
  317. }
  318. udelay(1);
  319. for (i = 0; i < 4; i++)
  320. hwrev |= (s5p_gpio_get_value(&gpio->e1, i) << i);
  321. debug("hwrev 0x%x\n", hwrev);
  322. return hwrev;
  323. }
  324. static void check_hw_revision(void)
  325. {
  326. int hwrev;
  327. hwrev = get_hw_revision();
  328. board_rev |= hwrev;
  329. }
  330. #ifdef CONFIG_DISPLAY_BOARDINFO
  331. int checkboard(void)
  332. {
  333. puts("Board:\tTRATS\n");
  334. return 0;
  335. }
  336. #endif
  337. #ifdef CONFIG_GENERIC_MMC
  338. int board_mmc_init(bd_t *bis)
  339. {
  340. struct exynos4_gpio_part2 *gpio =
  341. (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
  342. int err;
  343. /* eMMC_EN: SD_0_CDn: GPK0[2] Output High */
  344. s5p_gpio_direction_output(&gpio->k0, 2, 1);
  345. s5p_gpio_set_pull(&gpio->k0, 2, GPIO_PULL_NONE);
  346. /*
  347. * MMC device init
  348. * mmc0 : eMMC (8-bit buswidth)
  349. * mmc2 : SD card (4-bit buswidth)
  350. */
  351. err = exynos_pinmux_config(PERIPH_ID_SDMMC0, PINMUX_FLAG_8BIT_MODE);
  352. if (err)
  353. debug("SDMMC0 not configured\n");
  354. else
  355. err = s5p_mmc_init(0, 8);
  356. /* T-flash detect */
  357. s5p_gpio_cfg_pin(&gpio->x3, 4, 0xf);
  358. s5p_gpio_set_pull(&gpio->x3, 4, GPIO_PULL_UP);
  359. /*
  360. * Check the T-flash detect pin
  361. * GPX3[4] T-flash detect pin
  362. */
  363. if (!s5p_gpio_get_value(&gpio->x3, 4)) {
  364. err = exynos_pinmux_config(PERIPH_ID_SDMMC2, PINMUX_FLAG_NONE);
  365. if (err)
  366. debug("SDMMC2 not configured\n");
  367. else
  368. err = s5p_mmc_init(2, 4);
  369. }
  370. return err;
  371. }
  372. #endif
  373. #ifdef CONFIG_USB_GADGET
  374. static int s5pc210_phy_control(int on)
  375. {
  376. int ret = 0;
  377. u32 val = 0;
  378. struct pmic *p = pmic_get("MAX8997_PMIC");
  379. if (!p)
  380. return -ENODEV;
  381. if (pmic_probe(p))
  382. return -1;
  383. if (on) {
  384. ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL,
  385. ENSAFEOUT1, LDO_ON);
  386. ret |= pmic_reg_read(p, MAX8997_REG_LDO3CTRL, &val);
  387. ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, EN_LDO | val);
  388. ret |= pmic_reg_read(p, MAX8997_REG_LDO8CTRL, &val);
  389. ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, EN_LDO | val);
  390. } else {
  391. ret |= pmic_reg_read(p, MAX8997_REG_LDO8CTRL, &val);
  392. ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, DIS_LDO | val);
  393. ret |= pmic_reg_read(p, MAX8997_REG_LDO3CTRL, &val);
  394. ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, DIS_LDO | val);
  395. ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL,
  396. ENSAFEOUT1, LDO_OFF);
  397. }
  398. if (ret) {
  399. puts("MAX8997 LDO setting error!\n");
  400. return -1;
  401. }
  402. return 0;
  403. }
  404. struct s3c_plat_otg_data s5pc210_otg_data = {
  405. .phy_control = s5pc210_phy_control,
  406. .regs_phy = EXYNOS4_USBPHY_BASE,
  407. .regs_otg = EXYNOS4_USBOTG_BASE,
  408. .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
  409. .usb_flags = PHY0_SLEEP,
  410. };
  411. void board_usb_init(void)
  412. {
  413. debug("USB_udc_probe\n");
  414. s3c_udc_probe(&s5pc210_otg_data);
  415. }
  416. #endif
  417. static void pmic_reset(void)
  418. {
  419. struct exynos4_gpio_part2 *gpio =
  420. (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
  421. s5p_gpio_direction_output(&gpio->x0, 7, 1);
  422. s5p_gpio_set_pull(&gpio->x2, 7, GPIO_PULL_NONE);
  423. }
  424. static void board_clock_init(void)
  425. {
  426. struct exynos4_clock *clk =
  427. (struct exynos4_clock *)samsung_get_base_clock();
  428. writel(CLK_SRC_CPU_VAL, (unsigned int)&clk->src_cpu);
  429. writel(CLK_SRC_TOP0_VAL, (unsigned int)&clk->src_top0);
  430. writel(CLK_SRC_FSYS_VAL, (unsigned int)&clk->src_fsys);
  431. writel(CLK_SRC_PERIL0_VAL, (unsigned int)&clk->src_peril0);
  432. writel(CLK_DIV_CPU0_VAL, (unsigned int)&clk->div_cpu0);
  433. writel(CLK_DIV_CPU1_VAL, (unsigned int)&clk->div_cpu1);
  434. writel(CLK_DIV_DMC0_VAL, (unsigned int)&clk->div_dmc0);
  435. writel(CLK_DIV_DMC1_VAL, (unsigned int)&clk->div_dmc1);
  436. writel(CLK_DIV_LEFTBUS_VAL, (unsigned int)&clk->div_leftbus);
  437. writel(CLK_DIV_RIGHTBUS_VAL, (unsigned int)&clk->div_rightbus);
  438. writel(CLK_DIV_TOP_VAL, (unsigned int)&clk->div_top);
  439. writel(CLK_DIV_FSYS1_VAL, (unsigned int)&clk->div_fsys1);
  440. writel(CLK_DIV_FSYS2_VAL, (unsigned int)&clk->div_fsys2);
  441. writel(CLK_DIV_FSYS3_VAL, (unsigned int)&clk->div_fsys3);
  442. writel(CLK_DIV_PERIL0_VAL, (unsigned int)&clk->div_peril0);
  443. writel(CLK_DIV_PERIL3_VAL, (unsigned int)&clk->div_peril3);
  444. writel(PLL_LOCKTIME, (unsigned int)&clk->apll_lock);
  445. writel(PLL_LOCKTIME, (unsigned int)&clk->mpll_lock);
  446. writel(PLL_LOCKTIME, (unsigned int)&clk->epll_lock);
  447. writel(PLL_LOCKTIME, (unsigned int)&clk->vpll_lock);
  448. writel(APLL_CON1_VAL, (unsigned int)&clk->apll_con1);
  449. writel(APLL_CON0_VAL, (unsigned int)&clk->apll_con0);
  450. writel(MPLL_CON1_VAL, (unsigned int)&clk->mpll_con1);
  451. writel(MPLL_CON0_VAL, (unsigned int)&clk->mpll_con0);
  452. writel(EPLL_CON1_VAL, (unsigned int)&clk->epll_con1);
  453. writel(EPLL_CON0_VAL, (unsigned int)&clk->epll_con0);
  454. writel(VPLL_CON1_VAL, (unsigned int)&clk->vpll_con1);
  455. writel(VPLL_CON0_VAL, (unsigned int)&clk->vpll_con0);
  456. writel(CLK_GATE_IP_CAM_VAL, (unsigned int)&clk->gate_ip_cam);
  457. writel(CLK_GATE_IP_VP_VAL, (unsigned int)&clk->gate_ip_tv);
  458. writel(CLK_GATE_IP_MFC_VAL, (unsigned int)&clk->gate_ip_mfc);
  459. writel(CLK_GATE_IP_G3D_VAL, (unsigned int)&clk->gate_ip_g3d);
  460. writel(CLK_GATE_IP_IMAGE_VAL, (unsigned int)&clk->gate_ip_image);
  461. writel(CLK_GATE_IP_LCD0_VAL, (unsigned int)&clk->gate_ip_lcd0);
  462. writel(CLK_GATE_IP_LCD1_VAL, (unsigned int)&clk->gate_ip_lcd1);
  463. writel(CLK_GATE_IP_FSYS_VAL, (unsigned int)&clk->gate_ip_fsys);
  464. writel(CLK_GATE_IP_GPS_VAL, (unsigned int)&clk->gate_ip_gps);
  465. writel(CLK_GATE_IP_PERIL_VAL, (unsigned int)&clk->gate_ip_peril);
  466. writel(CLK_GATE_IP_PERIR_VAL, (unsigned int)&clk->gate_ip_perir);
  467. writel(CLK_GATE_BLOCK_VAL, (unsigned int)&clk->gate_block);
  468. }
  469. static void board_power_init(void)
  470. {
  471. struct exynos4_power *pwr =
  472. (struct exynos4_power *)samsung_get_base_power();
  473. /* PS HOLD */
  474. writel(EXYNOS4_PS_HOLD_CON_VAL, (unsigned int)&pwr->ps_hold_control);
  475. /* Set power down */
  476. writel(0, (unsigned int)&pwr->cam_configuration);
  477. writel(0, (unsigned int)&pwr->tv_configuration);
  478. writel(0, (unsigned int)&pwr->mfc_configuration);
  479. writel(0, (unsigned int)&pwr->g3d_configuration);
  480. writel(0, (unsigned int)&pwr->lcd1_configuration);
  481. writel(0, (unsigned int)&pwr->gps_configuration);
  482. writel(0, (unsigned int)&pwr->gps_alive_configuration);
  483. /* It is necessary to power down core 1 */
  484. /* to successfully boot CPU1 in kernel */
  485. writel(0, (unsigned int)&pwr->arm_core1_configuration);
  486. }
  487. static void board_uart_init(void)
  488. {
  489. struct exynos4_gpio_part1 *gpio1 =
  490. (struct exynos4_gpio_part1 *)samsung_get_base_gpio_part1();
  491. struct exynos4_gpio_part2 *gpio2 =
  492. (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
  493. int i;
  494. /*
  495. * UART2 GPIOs
  496. * GPA1CON[0] = UART_2_RXD(2)
  497. * GPA1CON[1] = UART_2_TXD(2)
  498. * GPA1CON[2] = I2C_3_SDA (3)
  499. * GPA1CON[3] = I2C_3_SCL (3)
  500. */
  501. for (i = 0; i < 4; i++) {
  502. s5p_gpio_set_pull(&gpio1->a1, i, GPIO_PULL_NONE);
  503. s5p_gpio_cfg_pin(&gpio1->a1, i, GPIO_FUNC((i > 1) ? 0x3 : 0x2));
  504. }
  505. /* UART_SEL GPY4[7] (part2) at EXYNOS4 */
  506. s5p_gpio_set_pull(&gpio2->y4, 7, GPIO_PULL_UP);
  507. s5p_gpio_direction_output(&gpio2->y4, 7, 1);
  508. }
  509. int board_early_init_f(void)
  510. {
  511. wdt_stop();
  512. pmic_reset();
  513. board_clock_init();
  514. board_uart_init();
  515. board_power_init();
  516. return 0;
  517. }
  518. void exynos_reset_lcd(void)
  519. {
  520. struct exynos4_gpio_part2 *gpio2 =
  521. (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
  522. s5p_gpio_direction_output(&gpio2->y4, 5, 1);
  523. udelay(10000);
  524. s5p_gpio_direction_output(&gpio2->y4, 5, 0);
  525. udelay(10000);
  526. s5p_gpio_direction_output(&gpio2->y4, 5, 1);
  527. }
  528. static int lcd_power(void)
  529. {
  530. int ret = 0;
  531. struct pmic *p = pmic_get("MAX8997_PMIC");
  532. if (!p)
  533. return -ENODEV;
  534. if (pmic_probe(p))
  535. return 0;
  536. /* LDO15 voltage: 2.2v */
  537. ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, 0x1c | EN_LDO);
  538. /* LDO13 voltage: 3.0v */
  539. ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, 0x2c | EN_LDO);
  540. if (ret) {
  541. puts("MAX8997 LDO setting error!\n");
  542. return -1;
  543. }
  544. return 0;
  545. }
  546. static struct mipi_dsim_config dsim_config = {
  547. .e_interface = DSIM_VIDEO,
  548. .e_virtual_ch = DSIM_VIRTUAL_CH_0,
  549. .e_pixel_format = DSIM_24BPP_888,
  550. .e_burst_mode = DSIM_BURST_SYNC_EVENT,
  551. .e_no_data_lane = DSIM_DATA_LANE_4,
  552. .e_byte_clk = DSIM_PLL_OUT_DIV8,
  553. .hfp = 1,
  554. .p = 3,
  555. .m = 120,
  556. .s = 1,
  557. /* D-PHY PLL stable time spec :min = 200usec ~ max 400usec */
  558. .pll_stable_time = 500,
  559. /* escape clk : 10MHz */
  560. .esc_clk = 20 * 1000000,
  561. /* stop state holding counter after bta change count 0 ~ 0xfff */
  562. .stop_holding_cnt = 0x7ff,
  563. /* bta timeout 0 ~ 0xff */
  564. .bta_timeout = 0xff,
  565. /* lp rx timeout 0 ~ 0xffff */
  566. .rx_timeout = 0xffff,
  567. };
  568. static struct exynos_platform_mipi_dsim s6e8ax0_platform_data = {
  569. .lcd_panel_info = NULL,
  570. .dsim_config = &dsim_config,
  571. };
  572. static struct mipi_dsim_lcd_device mipi_lcd_device = {
  573. .name = "s6e8ax0",
  574. .id = -1,
  575. .bus_id = 0,
  576. .platform_data = (void *)&s6e8ax0_platform_data,
  577. };
  578. static int mipi_power(void)
  579. {
  580. int ret = 0;
  581. struct pmic *p = pmic_get("MAX8997_PMIC");
  582. if (!p)
  583. return -ENODEV;
  584. if (pmic_probe(p))
  585. return 0;
  586. /* LDO3 voltage: 1.1v */
  587. ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, 0x6 | EN_LDO);
  588. /* LDO4 voltage: 1.8v */
  589. ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, 0x14 | EN_LDO);
  590. if (ret) {
  591. puts("MAX8997 LDO setting error!\n");
  592. return -1;
  593. }
  594. return 0;
  595. }
  596. vidinfo_t panel_info = {
  597. .vl_freq = 60,
  598. .vl_col = 720,
  599. .vl_row = 1280,
  600. .vl_width = 720,
  601. .vl_height = 1280,
  602. .vl_clkp = CONFIG_SYS_HIGH,
  603. .vl_hsp = CONFIG_SYS_LOW,
  604. .vl_vsp = CONFIG_SYS_LOW,
  605. .vl_dp = CONFIG_SYS_LOW,
  606. .vl_bpix = 5, /* Bits per pixel, 2^5 = 32 */
  607. /* s6e8ax0 Panel infomation */
  608. .vl_hspw = 5,
  609. .vl_hbpd = 10,
  610. .vl_hfpd = 10,
  611. .vl_vspw = 2,
  612. .vl_vbpd = 1,
  613. .vl_vfpd = 13,
  614. .vl_cmd_allow_len = 0xf,
  615. .win_id = 3,
  616. .dual_lcd_enabled = 0,
  617. .init_delay = 0,
  618. .power_on_delay = 0,
  619. .reset_delay = 0,
  620. .interface_mode = FIMD_RGB_INTERFACE,
  621. .mipi_enabled = 1,
  622. };
  623. void init_panel_info(vidinfo_t *vid)
  624. {
  625. vid->logo_on = 1,
  626. vid->resolution = HD_RESOLUTION,
  627. vid->rgb_mode = MODE_RGB_P,
  628. #ifdef CONFIG_TIZEN
  629. get_tizen_logo_info(vid);
  630. #endif
  631. mipi_lcd_device.reverse_panel = 1;
  632. strcpy(s6e8ax0_platform_data.lcd_panel_name, mipi_lcd_device.name);
  633. s6e8ax0_platform_data.lcd_power = lcd_power;
  634. s6e8ax0_platform_data.mipi_power = mipi_power;
  635. s6e8ax0_platform_data.phy_enable = set_mipi_phy_ctrl;
  636. s6e8ax0_platform_data.lcd_panel_info = (void *)vid;
  637. exynos_mipi_dsi_register_lcd_device(&mipi_lcd_device);
  638. s6e8ax0_init();
  639. exynos_set_dsim_platform_data(&s6e8ax0_platform_data);
  640. setenv("lcdinfo", "lcd=s6e8ax0");
  641. }
  642. #ifdef CONFIG_USB_GADGET_MASS_STORAGE
  643. static int ums_read_sector(struct ums_device *ums_dev,
  644. ulong start, lbaint_t blkcnt, void *buf)
  645. {
  646. if (ums_dev->mmc->block_dev.block_read(ums_dev->dev_num,
  647. start + ums_dev->offset, blkcnt, buf) != blkcnt)
  648. return -1;
  649. return 0;
  650. }
  651. static int ums_write_sector(struct ums_device *ums_dev,
  652. ulong start, lbaint_t blkcnt, const void *buf)
  653. {
  654. if (ums_dev->mmc->block_dev.block_write(ums_dev->dev_num,
  655. start + ums_dev->offset, blkcnt, buf) != blkcnt)
  656. return -1;
  657. return 0;
  658. }
  659. static void ums_get_capacity(struct ums_device *ums_dev,
  660. long long int *capacity)
  661. {
  662. long long int tmp_capacity;
  663. tmp_capacity = (long long int) ((ums_dev->offset + ums_dev->part_size)
  664. * SECTOR_SIZE);
  665. *capacity = ums_dev->mmc->capacity - tmp_capacity;
  666. }
  667. static struct ums_board_info ums_board = {
  668. .read_sector = ums_read_sector,
  669. .write_sector = ums_write_sector,
  670. .get_capacity = ums_get_capacity,
  671. .name = "TRATS UMS disk",
  672. .ums_dev = {
  673. .mmc = NULL,
  674. .dev_num = 0,
  675. .offset = 0,
  676. .part_size = 0.
  677. },
  678. };
  679. struct ums_board_info *board_ums_init(unsigned int dev_num, unsigned int offset,
  680. unsigned int part_size)
  681. {
  682. struct mmc *mmc;
  683. mmc = find_mmc_device(dev_num);
  684. if (!mmc)
  685. return NULL;
  686. ums_board.ums_dev.mmc = mmc;
  687. ums_board.ums_dev.dev_num = dev_num;
  688. ums_board.ums_dev.offset = offset;
  689. ums_board.ums_dev.part_size = part_size;
  690. return &ums_board;
  691. }
  692. #endif