universal.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. DECLARE_GLOBAL_DATA_PTR;
  30. struct s5pc210_gpio_part1 *gpio1;
  31. struct s5pc210_gpio_part2 *gpio2;
  32. unsigned int board_rev;
  33. u32 get_board_rev(void)
  34. {
  35. return board_rev;
  36. }
  37. static int get_hwrev(void)
  38. {
  39. return board_rev & 0xFF;
  40. }
  41. static void check_hw_revision(void);
  42. int board_init(void)
  43. {
  44. gpio1 = (struct s5pc210_gpio_part1 *) S5PC210_GPIO_PART1_BASE;
  45. gpio2 = (struct s5pc210_gpio_part2 *) S5PC210_GPIO_PART2_BASE;
  46. gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
  47. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  48. check_hw_revision();
  49. printf("HW Revision:\t0x%x\n", board_rev);
  50. return 0;
  51. }
  52. int dram_init(void)
  53. {
  54. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE) +
  55. get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
  56. return 0;
  57. }
  58. void dram_init_banksize(void)
  59. {
  60. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  61. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  62. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  63. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  64. }
  65. static unsigned short get_adc_value(int channel)
  66. {
  67. struct s5p_adc *adc = (struct s5p_adc *)samsung_get_base_adc();
  68. unsigned short ret = 0;
  69. unsigned int reg;
  70. unsigned int loop = 0;
  71. writel(channel & 0xF, &adc->adcmux);
  72. writel((1 << 14) | (49 << 6), &adc->adccon);
  73. writel(1000 & 0xffff, &adc->adcdly);
  74. writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
  75. udelay(10);
  76. writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
  77. udelay(10);
  78. do {
  79. udelay(1);
  80. reg = readl(&adc->adccon);
  81. } while (!(reg & (1 << 15)) && (loop++ < 1000));
  82. ret = readl(&adc->adcdat0) & 0xFFF;
  83. return ret;
  84. }
  85. static unsigned int get_hw_revision(void)
  86. {
  87. int hwrev, mode0, mode1;
  88. mode0 = get_adc_value(1); /* HWREV_MODE0 */
  89. mode1 = get_adc_value(2); /* HWREV_MODE1 */
  90. /*
  91. * XXX Always set the default hwrev as the latest board
  92. * ADC = (voltage) / 3.3 * 4096
  93. */
  94. hwrev = 3;
  95. #define IS_RANGE(x, min, max) ((x) > (min) && (x) < (max))
  96. if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
  97. hwrev = 0x0; /* 0.01V 0.01V */
  98. if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
  99. hwrev = 0x1; /* 610mV 0.01V */
  100. if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
  101. hwrev = 0x2; /* 1.16V 0.01V */
  102. if (IS_RANGE(mode0, 2000, 2400) && IS_RANGE(mode1, 80, 200))
  103. hwrev = 0x3; /* 1.79V 0.01V */
  104. #undef IS_RANGE
  105. debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
  106. return hwrev;
  107. }
  108. static void check_hw_revision(void)
  109. {
  110. int hwrev;
  111. hwrev = get_hw_revision();
  112. board_rev |= hwrev;
  113. }
  114. #ifdef CONFIG_DISPLAY_BOARDINFO
  115. int checkboard(void)
  116. {
  117. puts("Board:\tUniversal C210\n");
  118. return 0;
  119. }
  120. #endif
  121. #ifdef CONFIG_GENERIC_MMC
  122. int board_mmc_init(bd_t *bis)
  123. {
  124. int i, err;
  125. switch (get_hwrev()) {
  126. case 0:
  127. /*
  128. * Set the low to enable LDO_EN
  129. * But when you use the test board for eMMC booting
  130. * you should set it HIGH since it removes the inverter
  131. */
  132. /* MASSMEMORY_EN: XMDMDATA_6: GPE3[6] */
  133. gpio_direction_output(&gpio1->e3, 6, 0);
  134. break;
  135. default:
  136. /*
  137. * Default reset state is High and there's no inverter
  138. * But set it as HIGH to ensure
  139. */
  140. /* MASSMEMORY_EN: XMDMADDR_3: GPE1[3] */
  141. gpio_direction_output(&gpio1->e1, 3, 1);
  142. break;
  143. }
  144. /*
  145. * eMMC GPIO:
  146. * SDR 8-bit@48MHz at MMC0
  147. * GPK0[0] SD_0_CLK(2)
  148. * GPK0[1] SD_0_CMD(2)
  149. * GPK0[2] SD_0_CDn -> Not used
  150. * GPK0[3:6] SD_0_DATA[0:3](2)
  151. * GPK1[3:6] SD_0_DATA[0:3](3)
  152. *
  153. * DDR 4-bit@26MHz at MMC4
  154. * GPK0[0] SD_4_CLK(3)
  155. * GPK0[1] SD_4_CMD(3)
  156. * GPK0[2] SD_4_CDn -> Not used
  157. * GPK0[3:6] SD_4_DATA[0:3](3)
  158. * GPK1[3:6] SD_4_DATA[4:7](4)
  159. */
  160. for (i = 0; i < 7; i++) {
  161. if (i == 2)
  162. continue;
  163. /* GPK0[0:6] special function 2 */
  164. gpio_cfg_pin(&gpio2->k0, i, 0x2);
  165. /* GPK0[0:6] pull disable */
  166. gpio_set_pull(&gpio2->k0, i, GPIO_PULL_NONE);
  167. /* GPK0[0:6] drv 4x */
  168. gpio_set_drv(&gpio2->k0, i, GPIO_DRV_4X);
  169. }
  170. for (i = 3; i < 7; i++) {
  171. /* GPK1[3:6] special function 3 */
  172. gpio_cfg_pin(&gpio2->k1, i, 0x3);
  173. /* GPK1[3:6] pull disable */
  174. gpio_set_pull(&gpio2->k1, i, GPIO_PULL_NONE);
  175. /* GPK1[3:6] drv 4x */
  176. gpio_set_drv(&gpio2->k1, i, GPIO_DRV_4X);
  177. }
  178. /* T-flash detect */
  179. gpio_cfg_pin(&gpio2->x3, 4, 0xf);
  180. gpio_set_pull(&gpio2->x3, 4, GPIO_PULL_UP);
  181. /*
  182. * MMC device init
  183. * mmc0 : eMMC (8-bit buswidth)
  184. * mmc2 : SD card (4-bit buswidth)
  185. */
  186. err = s5p_mmc_init(0, 8);
  187. /*
  188. * Check the T-flash detect pin
  189. * GPX3[4] T-flash detect pin
  190. */
  191. if (!gpio_get_value(&gpio2->x3, 4)) {
  192. /*
  193. * SD card GPIO:
  194. * GPK2[0] SD_2_CLK(2)
  195. * GPK2[1] SD_2_CMD(2)
  196. * GPK2[2] SD_2_CDn -> Not used
  197. * GPK2[3:6] SD_2_DATA[0:3](2)
  198. */
  199. for (i = 0; i < 7; i++) {
  200. if (i == 2)
  201. continue;
  202. /* GPK2[0:6] special function 2 */
  203. gpio_cfg_pin(&gpio2->k2, i, 0x2);
  204. /* GPK2[0:6] pull disable */
  205. gpio_set_pull(&gpio2->k2, i, GPIO_PULL_NONE);
  206. /* GPK2[0:6] drv 4x */
  207. gpio_set_drv(&gpio2->k2, i, GPIO_DRV_4X);
  208. }
  209. err = s5p_mmc_init(2, 4);
  210. }
  211. return err;
  212. }
  213. #endif