universal.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 <asm/arch/pinmux.h>
  30. #include <pmic.h>
  31. #include <usb/s3c_udc.h>
  32. #include <asm/arch/cpu.h>
  33. #include <max8998_pmic.h>
  34. #include <asm/arch/watchdog.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. struct exynos4_gpio_part1 *gpio1;
  37. struct exynos4_gpio_part2 *gpio2;
  38. unsigned int board_rev;
  39. u32 get_board_rev(void)
  40. {
  41. return board_rev;
  42. }
  43. static int get_hwrev(void)
  44. {
  45. return board_rev & 0xFF;
  46. }
  47. static void check_hw_revision(void);
  48. int board_init(void)
  49. {
  50. gpio1 = (struct exynos4_gpio_part1 *) EXYNOS4_GPIO_PART1_BASE;
  51. gpio2 = (struct exynos4_gpio_part2 *) EXYNOS4_GPIO_PART2_BASE;
  52. gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
  53. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  54. #if defined(CONFIG_PMIC)
  55. pmic_init();
  56. #endif
  57. check_hw_revision();
  58. printf("HW Revision:\t0x%x\n", board_rev);
  59. return 0;
  60. }
  61. int dram_init(void)
  62. {
  63. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE) +
  64. get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
  65. return 0;
  66. }
  67. void dram_init_banksize(void)
  68. {
  69. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  70. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  71. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  72. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  73. }
  74. static unsigned short get_adc_value(int channel)
  75. {
  76. struct s5p_adc *adc = (struct s5p_adc *)samsung_get_base_adc();
  77. unsigned short ret = 0;
  78. unsigned int reg;
  79. unsigned int loop = 0;
  80. writel(channel & 0xF, &adc->adcmux);
  81. writel((1 << 14) | (49 << 6), &adc->adccon);
  82. writel(1000 & 0xffff, &adc->adcdly);
  83. writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
  84. udelay(10);
  85. writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
  86. udelay(10);
  87. do {
  88. udelay(1);
  89. reg = readl(&adc->adccon);
  90. } while (!(reg & (1 << 15)) && (loop++ < 1000));
  91. ret = readl(&adc->adcdat0) & 0xFFF;
  92. return ret;
  93. }
  94. static int adc_power_control(int on)
  95. {
  96. int ret;
  97. struct pmic *p = get_pmic();
  98. if (pmic_probe(p))
  99. return -1;
  100. ret = pmic_set_output(p,
  101. MAX8998_REG_ONOFF1,
  102. MAX8998_LDO4, !!on);
  103. return ret;
  104. }
  105. static unsigned int get_hw_revision(void)
  106. {
  107. int hwrev, mode0, mode1;
  108. adc_power_control(1);
  109. mode0 = get_adc_value(1); /* HWREV_MODE0 */
  110. mode1 = get_adc_value(2); /* HWREV_MODE1 */
  111. /*
  112. * XXX Always set the default hwrev as the latest board
  113. * ADC = (voltage) / 3.3 * 4096
  114. */
  115. hwrev = 3;
  116. #define IS_RANGE(x, min, max) ((x) > (min) && (x) < (max))
  117. if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
  118. hwrev = 0x0; /* 0.01V 0.01V */
  119. if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
  120. hwrev = 0x1; /* 610mV 0.01V */
  121. if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
  122. hwrev = 0x2; /* 1.16V 0.01V */
  123. if (IS_RANGE(mode0, 2000, 2400) && IS_RANGE(mode1, 80, 200))
  124. hwrev = 0x3; /* 1.79V 0.01V */
  125. #undef IS_RANGE
  126. debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
  127. adc_power_control(0);
  128. return hwrev;
  129. }
  130. static void check_hw_revision(void)
  131. {
  132. int hwrev;
  133. hwrev = get_hw_revision();
  134. board_rev |= hwrev;
  135. }
  136. #ifdef CONFIG_DISPLAY_BOARDINFO
  137. int checkboard(void)
  138. {
  139. puts("Board:\tUniversal C210\n");
  140. return 0;
  141. }
  142. #endif
  143. #ifdef CONFIG_GENERIC_MMC
  144. int board_mmc_init(bd_t *bis)
  145. {
  146. int err;
  147. switch (get_hwrev()) {
  148. case 0:
  149. /*
  150. * Set the low to enable LDO_EN
  151. * But when you use the test board for eMMC booting
  152. * you should set it HIGH since it removes the inverter
  153. */
  154. /* MASSMEMORY_EN: XMDMDATA_6: GPE3[6] */
  155. s5p_gpio_direction_output(&gpio1->e3, 6, 0);
  156. break;
  157. default:
  158. /*
  159. * Default reset state is High and there's no inverter
  160. * But set it as HIGH to ensure
  161. */
  162. /* MASSMEMORY_EN: XMDMADDR_3: GPE1[3] */
  163. s5p_gpio_direction_output(&gpio1->e1, 3, 1);
  164. break;
  165. }
  166. /*
  167. * MMC device init
  168. * mmc0 : eMMC (8-bit buswidth)
  169. * mmc2 : SD card (4-bit buswidth)
  170. */
  171. err = exynos_pinmux_config(PERIPH_ID_SDMMC0, PINMUX_FLAG_8BIT_MODE);
  172. if (err)
  173. debug("SDMMC0 not configured\n");
  174. else
  175. err = s5p_mmc_init(0, 8);
  176. /* T-flash detect */
  177. s5p_gpio_cfg_pin(&gpio2->x3, 4, 0xf);
  178. s5p_gpio_set_pull(&gpio2->x3, 4, GPIO_PULL_UP);
  179. /*
  180. * Check the T-flash detect pin
  181. * GPX3[4] T-flash detect pin
  182. */
  183. if (!s5p_gpio_get_value(&gpio2->x3, 4)) {
  184. err = exynos_pinmux_config(PERIPH_ID_SDMMC2, PINMUX_FLAG_NONE);
  185. if (err)
  186. debug("SDMMC2 not configured\n");
  187. else
  188. err = s5p_mmc_init(2, 4);
  189. }
  190. return err;
  191. }
  192. #endif
  193. #ifdef CONFIG_USB_GADGET
  194. static int s5pc210_phy_control(int on)
  195. {
  196. int ret = 0;
  197. struct pmic *p = get_pmic();
  198. if (pmic_probe(p))
  199. return -1;
  200. if (on) {
  201. ret |= pmic_set_output(p,
  202. MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
  203. MAX8998_SAFEOUT1, LDO_ON);
  204. ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
  205. MAX8998_LDO3, LDO_ON);
  206. ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
  207. MAX8998_LDO8, LDO_ON);
  208. } else {
  209. ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
  210. MAX8998_LDO8, LDO_OFF);
  211. ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
  212. MAX8998_LDO3, LDO_OFF);
  213. ret |= pmic_set_output(p,
  214. MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
  215. MAX8998_SAFEOUT1, LDO_OFF);
  216. }
  217. if (ret) {
  218. puts("MAX8998 LDO setting error!\n");
  219. return -1;
  220. }
  221. return 0;
  222. }
  223. struct s3c_plat_otg_data s5pc210_otg_data = {
  224. .phy_control = s5pc210_phy_control,
  225. .regs_phy = EXYNOS4_USBPHY_BASE,
  226. .regs_otg = EXYNOS4_USBOTG_BASE,
  227. .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
  228. .usb_flags = PHY0_SLEEP,
  229. };
  230. #endif
  231. int board_early_init_f(void)
  232. {
  233. wdt_stop();
  234. return 0;
  235. }