universal.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. * Copyright (C) 2010 Samsung Electronics
  3. * Minkyu Kang <mk7.kang@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/adc.h>
  27. #include <asm/arch/gpio.h>
  28. #include <asm/arch/mmc.h>
  29. #include <power/pmic.h>
  30. #include <usb/s3c_udc.h>
  31. #include <asm/arch/cpu.h>
  32. #include <power/max8998_pmic.h>
  33. DECLARE_GLOBAL_DATA_PTR;
  34. struct exynos4_gpio_part1 *gpio1;
  35. struct exynos4_gpio_part2 *gpio2;
  36. unsigned int board_rev;
  37. u32 get_board_rev(void)
  38. {
  39. return board_rev;
  40. }
  41. static int get_hwrev(void)
  42. {
  43. return board_rev & 0xFF;
  44. }
  45. static void check_hw_revision(void);
  46. int board_init(void)
  47. {
  48. gpio1 = (struct exynos4_gpio_part1 *) EXYNOS4_GPIO_PART1_BASE;
  49. gpio2 = (struct exynos4_gpio_part2 *) EXYNOS4_GPIO_PART2_BASE;
  50. gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
  51. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  52. check_hw_revision();
  53. printf("HW Revision:\t0x%x\n", board_rev);
  54. return 0;
  55. }
  56. int power_init_board(void)
  57. {
  58. int ret;
  59. ret = pmic_init(I2C_5);
  60. if (ret)
  61. return ret;
  62. return 0;
  63. }
  64. int dram_init(void)
  65. {
  66. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE) +
  67. get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
  68. return 0;
  69. }
  70. void dram_init_banksize(void)
  71. {
  72. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  73. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  74. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  75. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  76. }
  77. static unsigned short get_adc_value(int channel)
  78. {
  79. struct s5p_adc *adc = (struct s5p_adc *)samsung_get_base_adc();
  80. unsigned short ret = 0;
  81. unsigned int reg;
  82. unsigned int loop = 0;
  83. writel(channel & 0xF, &adc->adcmux);
  84. writel((1 << 14) | (49 << 6), &adc->adccon);
  85. writel(1000 & 0xffff, &adc->adcdly);
  86. writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
  87. udelay(10);
  88. writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
  89. udelay(10);
  90. do {
  91. udelay(1);
  92. reg = readl(&adc->adccon);
  93. } while (!(reg & (1 << 15)) && (loop++ < 1000));
  94. ret = readl(&adc->adcdat0) & 0xFFF;
  95. return ret;
  96. }
  97. static int adc_power_control(int on)
  98. {
  99. int ret;
  100. struct pmic *p = pmic_get("MAX8998_PMIC");
  101. if (!p)
  102. return -ENODEV;
  103. if (pmic_probe(p))
  104. return -1;
  105. ret = pmic_set_output(p,
  106. MAX8998_REG_ONOFF1,
  107. MAX8998_LDO4, !!on);
  108. return ret;
  109. }
  110. static unsigned int get_hw_revision(void)
  111. {
  112. int hwrev, mode0, mode1;
  113. adc_power_control(1);
  114. mode0 = get_adc_value(1); /* HWREV_MODE0 */
  115. mode1 = get_adc_value(2); /* HWREV_MODE1 */
  116. /*
  117. * XXX Always set the default hwrev as the latest board
  118. * ADC = (voltage) / 3.3 * 4096
  119. */
  120. hwrev = 3;
  121. #define IS_RANGE(x, min, max) ((x) > (min) && (x) < (max))
  122. if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
  123. hwrev = 0x0; /* 0.01V 0.01V */
  124. if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
  125. hwrev = 0x1; /* 610mV 0.01V */
  126. if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
  127. hwrev = 0x2; /* 1.16V 0.01V */
  128. if (IS_RANGE(mode0, 2000, 2400) && IS_RANGE(mode1, 80, 200))
  129. hwrev = 0x3; /* 1.79V 0.01V */
  130. #undef IS_RANGE
  131. debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
  132. adc_power_control(0);
  133. return hwrev;
  134. }
  135. static void check_hw_revision(void)
  136. {
  137. int hwrev;
  138. hwrev = get_hw_revision();
  139. board_rev |= hwrev;
  140. }
  141. #ifdef CONFIG_DISPLAY_BOARDINFO
  142. int checkboard(void)
  143. {
  144. puts("Board:\tUniversal C210\n");
  145. return 0;
  146. }
  147. #endif
  148. #ifdef CONFIG_GENERIC_MMC
  149. int board_mmc_init(bd_t *bis)
  150. {
  151. int i, err;
  152. switch (get_hwrev()) {
  153. case 0:
  154. /*
  155. * Set the low to enable LDO_EN
  156. * But when you use the test board for eMMC booting
  157. * you should set it HIGH since it removes the inverter
  158. */
  159. /* MASSMEMORY_EN: XMDMDATA_6: GPE3[6] */
  160. s5p_gpio_direction_output(&gpio1->e3, 6, 0);
  161. break;
  162. default:
  163. /*
  164. * Default reset state is High and there's no inverter
  165. * But set it as HIGH to ensure
  166. */
  167. /* MASSMEMORY_EN: XMDMADDR_3: GPE1[3] */
  168. s5p_gpio_direction_output(&gpio1->e1, 3, 1);
  169. break;
  170. }
  171. /*
  172. * eMMC GPIO:
  173. * SDR 8-bit@48MHz at MMC0
  174. * GPK0[0] SD_0_CLK(2)
  175. * GPK0[1] SD_0_CMD(2)
  176. * GPK0[2] SD_0_CDn -> Not used
  177. * GPK0[3:6] SD_0_DATA[0:3](2)
  178. * GPK1[3:6] SD_0_DATA[0:3](3)
  179. *
  180. * DDR 4-bit@26MHz at MMC4
  181. * GPK0[0] SD_4_CLK(3)
  182. * GPK0[1] SD_4_CMD(3)
  183. * GPK0[2] SD_4_CDn -> Not used
  184. * GPK0[3:6] SD_4_DATA[0:3](3)
  185. * GPK1[3:6] SD_4_DATA[4:7](4)
  186. */
  187. for (i = 0; i < 7; i++) {
  188. if (i == 2)
  189. continue;
  190. /* GPK0[0:6] special function 2 */
  191. s5p_gpio_cfg_pin(&gpio2->k0, i, 0x2);
  192. /* GPK0[0:6] pull disable */
  193. s5p_gpio_set_pull(&gpio2->k0, i, GPIO_PULL_NONE);
  194. /* GPK0[0:6] drv 4x */
  195. s5p_gpio_set_drv(&gpio2->k0, i, GPIO_DRV_4X);
  196. }
  197. for (i = 3; i < 7; i++) {
  198. /* GPK1[3:6] special function 3 */
  199. s5p_gpio_cfg_pin(&gpio2->k1, i, 0x3);
  200. /* GPK1[3:6] pull disable */
  201. s5p_gpio_set_pull(&gpio2->k1, i, GPIO_PULL_NONE);
  202. /* GPK1[3:6] drv 4x */
  203. s5p_gpio_set_drv(&gpio2->k1, i, GPIO_DRV_4X);
  204. }
  205. /* T-flash detect */
  206. s5p_gpio_cfg_pin(&gpio2->x3, 4, 0xf);
  207. s5p_gpio_set_pull(&gpio2->x3, 4, GPIO_PULL_UP);
  208. /*
  209. * MMC device init
  210. * mmc0 : eMMC (8-bit buswidth)
  211. * mmc2 : SD card (4-bit buswidth)
  212. */
  213. err = s5p_mmc_init(0, 8);
  214. /*
  215. * Check the T-flash detect pin
  216. * GPX3[4] T-flash detect pin
  217. */
  218. if (!s5p_gpio_get_value(&gpio2->x3, 4)) {
  219. /*
  220. * SD card GPIO:
  221. * GPK2[0] SD_2_CLK(2)
  222. * GPK2[1] SD_2_CMD(2)
  223. * GPK2[2] SD_2_CDn -> Not used
  224. * GPK2[3:6] SD_2_DATA[0:3](2)
  225. */
  226. for (i = 0; i < 7; i++) {
  227. if (i == 2)
  228. continue;
  229. /* GPK2[0:6] special function 2 */
  230. s5p_gpio_cfg_pin(&gpio2->k2, i, 0x2);
  231. /* GPK2[0:6] pull disable */
  232. s5p_gpio_set_pull(&gpio2->k2, i, GPIO_PULL_NONE);
  233. /* GPK2[0:6] drv 4x */
  234. s5p_gpio_set_drv(&gpio2->k2, i, GPIO_DRV_4X);
  235. }
  236. err = s5p_mmc_init(2, 4);
  237. }
  238. return err;
  239. }
  240. #endif
  241. #ifdef CONFIG_USB_GADGET
  242. static int s5pc210_phy_control(int on)
  243. {
  244. int ret = 0;
  245. struct pmic *p = pmic_get("MAX8998_PMIC");
  246. if (!p)
  247. return -ENODEV;
  248. if (pmic_probe(p))
  249. return -1;
  250. if (on) {
  251. ret |= pmic_set_output(p,
  252. MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
  253. MAX8998_SAFEOUT1, LDO_ON);
  254. ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
  255. MAX8998_LDO3, LDO_ON);
  256. ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
  257. MAX8998_LDO8, LDO_ON);
  258. } else {
  259. ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
  260. MAX8998_LDO8, LDO_OFF);
  261. ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
  262. MAX8998_LDO3, LDO_OFF);
  263. ret |= pmic_set_output(p,
  264. MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
  265. MAX8998_SAFEOUT1, LDO_OFF);
  266. }
  267. if (ret) {
  268. puts("MAX8998 LDO setting error!\n");
  269. return -1;
  270. }
  271. return 0;
  272. }
  273. struct s3c_plat_otg_data s5pc210_otg_data = {
  274. .phy_control = s5pc210_phy_control,
  275. .regs_phy = EXYNOS4_USBPHY_BASE,
  276. .regs_otg = EXYNOS4_USBOTG_BASE,
  277. .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
  278. .usb_flags = PHY0_SLEEP,
  279. };
  280. #endif