panda.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. * (C) Copyright 2010
  3. * Texas Instruments Incorporated, <www.ti.com>
  4. * Steve Sakoman <steve@sakoman.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <asm/arch/sys_proto.h>
  10. #include <asm/arch/mmc_host_def.h>
  11. #include <asm/arch/clock.h>
  12. #include <asm/arch/gpio.h>
  13. #include <asm/gpio.h>
  14. #include <twl6030.h>
  15. #include "panda_mux_data.h"
  16. #ifdef CONFIG_USB_EHCI
  17. #include <usb.h>
  18. #include <asm/arch/ehci.h>
  19. #include <asm/ehci-omap.h>
  20. #endif
  21. #define PANDA_ULPI_PHY_TYPE_GPIO 182
  22. #define PANDA_BOARD_ID_1_GPIO 101
  23. #define PANDA_ES_BOARD_ID_1_GPIO 48
  24. #define PANDA_BOARD_ID_2_GPIO 171
  25. #define PANDA_ES_BOARD_ID_3_GPIO 3
  26. #define PANDA_ES_BOARD_ID_4_GPIO 2
  27. DECLARE_GLOBAL_DATA_PTR;
  28. const struct omap_sysinfo sysinfo = {
  29. "Board: OMAP4 Panda\n"
  30. };
  31. struct omap4_scrm_regs *const scrm = (struct omap4_scrm_regs *)0x4a30a000;
  32. /**
  33. * @brief board_init
  34. *
  35. * @return 0
  36. */
  37. int board_init(void)
  38. {
  39. gpmc_init();
  40. gd->bd->bi_arch_number = MACH_TYPE_OMAP4_PANDA;
  41. gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
  42. return 0;
  43. }
  44. int board_eth_init(bd_t *bis)
  45. {
  46. return 0;
  47. }
  48. /*
  49. * Routine: get_board_revision
  50. * Description: Detect if we are running on a panda revision A1-A6,
  51. * or an ES panda board. This can be done by reading
  52. * the level of GPIOs and checking the processor revisions.
  53. * This should result in:
  54. * Panda 4430:
  55. * GPIO171, GPIO101, GPIO182: 0 1 1 => A1-A5
  56. * GPIO171, GPIO101, GPIO182: 1 0 1 => A6
  57. * Panda ES:
  58. * GPIO2, GPIO3, GPIO171, GPIO48, GPIO182: 0 0 0 1 1 => B1/B2
  59. * GPIO2, GPIO3, GPIO171, GPIO48, GPIO182: 0 0 1 1 1 => B3
  60. */
  61. int get_board_revision(void)
  62. {
  63. int board_id0, board_id1, board_id2;
  64. int board_id3, board_id4;
  65. int board_id;
  66. int processor_rev = omap_revision();
  67. /* Setup the mux for the common board ID pins (gpio 171 and 182) */
  68. writew((IEN | M3), (*ctrl)->control_padconf_core_base + UNIPRO_TX0);
  69. writew((IEN | M3), (*ctrl)->control_padconf_core_base + FREF_CLK2_OUT);
  70. board_id0 = gpio_get_value(PANDA_ULPI_PHY_TYPE_GPIO);
  71. board_id2 = gpio_get_value(PANDA_BOARD_ID_2_GPIO);
  72. if ((processor_rev >= OMAP4460_ES1_0 &&
  73. processor_rev <= OMAP4460_ES1_1)) {
  74. /*
  75. * Setup the mux for the ES specific board ID pins (gpio 101,
  76. * 2 and 3.
  77. */
  78. writew((IEN | M3), (*ctrl)->control_padconf_core_base +
  79. GPMC_A24);
  80. writew((IEN | M3), (*ctrl)->control_padconf_core_base +
  81. UNIPRO_RY0);
  82. writew((IEN | M3), (*ctrl)->control_padconf_core_base +
  83. UNIPRO_RX1);
  84. board_id1 = gpio_get_value(PANDA_ES_BOARD_ID_1_GPIO);
  85. board_id3 = gpio_get_value(PANDA_ES_BOARD_ID_3_GPIO);
  86. board_id4 = gpio_get_value(PANDA_ES_BOARD_ID_4_GPIO);
  87. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  88. setenv("board_name", "panda-es");
  89. #endif
  90. board_id = ((board_id4 << 4) | (board_id3 << 3) |
  91. (board_id2 << 2) | (board_id1 << 1) | (board_id0));
  92. } else {
  93. /* Setup the mux for the Ax specific board ID pins (gpio 101) */
  94. writew((IEN | M3), (*ctrl)->control_padconf_core_base +
  95. FREF_CLK2_OUT);
  96. board_id1 = gpio_get_value(PANDA_BOARD_ID_1_GPIO);
  97. board_id = ((board_id2 << 2) | (board_id1 << 1) | (board_id0));
  98. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  99. if ((board_id >= 0x3) && (processor_rev == OMAP4430_ES2_3))
  100. setenv("board_name", "panda-a4");
  101. #endif
  102. }
  103. return board_id;
  104. }
  105. /**
  106. * is_panda_es_rev_b3() - Detect if we are running on rev B3 of panda board ES
  107. *
  108. *
  109. * Detect if we are running on B3 version of ES panda board,
  110. * This can be done by reading the level of GPIO 171 and checking the
  111. * processor revisions.
  112. * GPIO171: 1 => Panda ES Rev B3
  113. *
  114. * Return : return 1 if Panda ES Rev B3 , else return 0
  115. */
  116. u8 is_panda_es_rev_b3(void)
  117. {
  118. int processor_rev = omap_revision();
  119. int ret = 0;
  120. if ((processor_rev >= OMAP4460_ES1_0 &&
  121. processor_rev <= OMAP4460_ES1_1)) {
  122. /* Setup the mux for the common board ID pins (gpio 171) */
  123. writew((IEN | M3),
  124. (*ctrl)->control_padconf_core_base + UNIPRO_TX0);
  125. /* if processor_rev is panda ES and GPIO171 is 1,it is rev b3 */
  126. ret = gpio_get_value(PANDA_BOARD_ID_2_GPIO);
  127. }
  128. return ret;
  129. }
  130. #ifdef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
  131. /*
  132. * emif_get_reg_dump() - emif_get_reg_dump strong function
  133. *
  134. * @emif_nr - emif base
  135. * @regs - reg dump of timing values
  136. *
  137. * Strong function to override emif_get_reg_dump weak function in sdram_elpida.c
  138. */
  139. void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs)
  140. {
  141. u32 omap4_rev = omap_revision();
  142. /* Same devices and geometry on both EMIFs */
  143. if (omap4_rev == OMAP4430_ES1_0)
  144. *regs = &emif_regs_elpida_380_mhz_1cs;
  145. else if (omap4_rev == OMAP4430_ES2_0)
  146. *regs = &emif_regs_elpida_200_mhz_2cs;
  147. else if (omap4_rev == OMAP4430_ES2_3)
  148. *regs = &emif_regs_elpida_400_mhz_1cs;
  149. else if (omap4_rev < OMAP4470_ES1_0) {
  150. if(is_panda_es_rev_b3())
  151. *regs = &emif_regs_elpida_400_mhz_1cs;
  152. else
  153. *regs = &emif_regs_elpida_400_mhz_2cs;
  154. }
  155. else
  156. *regs = &emif_regs_elpida_400_mhz_1cs;
  157. }
  158. void emif_get_dmm_regs(const struct dmm_lisa_map_regs
  159. **dmm_lisa_regs)
  160. {
  161. u32 omap_rev = omap_revision();
  162. if (omap_rev == OMAP4430_ES1_0)
  163. *dmm_lisa_regs = &lisa_map_2G_x_1_x_2;
  164. else if (omap_rev == OMAP4430_ES2_3)
  165. *dmm_lisa_regs = &lisa_map_2G_x_2_x_2;
  166. else if (omap_rev < OMAP4460_ES1_0)
  167. *dmm_lisa_regs = &lisa_map_2G_x_2_x_2;
  168. else
  169. *dmm_lisa_regs = &ma_lisa_map_2G_x_2_x_2;
  170. }
  171. #endif
  172. /**
  173. * @brief misc_init_r - Configure Panda board specific configurations
  174. * such as power configurations, ethernet initialization as phase2 of
  175. * boot sequence
  176. *
  177. * @return 0
  178. */
  179. int misc_init_r(void)
  180. {
  181. int phy_type;
  182. u32 auxclk, altclksrc;
  183. /* EHCI is not supported on ES1.0 */
  184. if (omap_revision() == OMAP4430_ES1_0)
  185. return 0;
  186. get_board_revision();
  187. gpio_direction_input(PANDA_ULPI_PHY_TYPE_GPIO);
  188. phy_type = gpio_get_value(PANDA_ULPI_PHY_TYPE_GPIO);
  189. if (phy_type == 1) {
  190. /* ULPI PHY supplied by auxclk3 derived from sys_clk */
  191. debug("ULPI PHY supplied by auxclk3\n");
  192. auxclk = readl(&scrm->auxclk3);
  193. /* Select sys_clk */
  194. auxclk &= ~AUXCLK_SRCSELECT_MASK;
  195. auxclk |= AUXCLK_SRCSELECT_SYS_CLK << AUXCLK_SRCSELECT_SHIFT;
  196. /* Set the divisor to 2 */
  197. auxclk &= ~AUXCLK_CLKDIV_MASK;
  198. auxclk |= AUXCLK_CLKDIV_2 << AUXCLK_CLKDIV_SHIFT;
  199. /* Request auxilary clock #3 */
  200. auxclk |= AUXCLK_ENABLE_MASK;
  201. writel(auxclk, &scrm->auxclk3);
  202. } else {
  203. /* ULPI PHY supplied by auxclk1 derived from PER dpll */
  204. debug("ULPI PHY supplied by auxclk1\n");
  205. auxclk = readl(&scrm->auxclk1);
  206. /* Select per DPLL */
  207. auxclk &= ~AUXCLK_SRCSELECT_MASK;
  208. auxclk |= AUXCLK_SRCSELECT_PER_DPLL << AUXCLK_SRCSELECT_SHIFT;
  209. /* Set the divisor to 16 */
  210. auxclk &= ~AUXCLK_CLKDIV_MASK;
  211. auxclk |= AUXCLK_CLKDIV_16 << AUXCLK_CLKDIV_SHIFT;
  212. /* Request auxilary clock #3 */
  213. auxclk |= AUXCLK_ENABLE_MASK;
  214. writel(auxclk, &scrm->auxclk1);
  215. }
  216. altclksrc = readl(&scrm->altclksrc);
  217. /* Activate alternate system clock supplier */
  218. altclksrc &= ~ALTCLKSRC_MODE_MASK;
  219. altclksrc |= ALTCLKSRC_MODE_ACTIVE;
  220. /* enable clocks */
  221. altclksrc |= ALTCLKSRC_ENABLE_INT_MASK | ALTCLKSRC_ENABLE_EXT_MASK;
  222. writel(altclksrc, &scrm->altclksrc);
  223. omap_die_id_usbethaddr();
  224. return 0;
  225. }
  226. void set_muxconf_regs(void)
  227. {
  228. do_set_mux((*ctrl)->control_padconf_core_base,
  229. core_padconf_array_essential,
  230. sizeof(core_padconf_array_essential) /
  231. sizeof(struct pad_conf_entry));
  232. do_set_mux((*ctrl)->control_padconf_wkup_base,
  233. wkup_padconf_array_essential,
  234. sizeof(wkup_padconf_array_essential) /
  235. sizeof(struct pad_conf_entry));
  236. if (omap_revision() >= OMAP4460_ES1_0)
  237. do_set_mux((*ctrl)->control_padconf_wkup_base,
  238. wkup_padconf_array_essential_4460,
  239. sizeof(wkup_padconf_array_essential_4460) /
  240. sizeof(struct pad_conf_entry));
  241. }
  242. #if defined(CONFIG_GENERIC_MMC)
  243. int board_mmc_init(bd_t *bis)
  244. {
  245. return omap_mmc_init(0, 0, 0, -1, -1);
  246. }
  247. #if !defined(CONFIG_SPL_BUILD)
  248. void board_mmc_power_init(void)
  249. {
  250. twl6030_power_mmc_init(0);
  251. }
  252. #endif
  253. #endif
  254. #ifdef CONFIG_USB_EHCI
  255. static struct omap_usbhs_board_data usbhs_bdata = {
  256. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  257. .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED,
  258. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
  259. };
  260. int ehci_hcd_init(int index, enum usb_init_type init,
  261. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  262. {
  263. int ret;
  264. unsigned int utmi_clk;
  265. /* Now we can enable our port clocks */
  266. utmi_clk = readl((void *)CM_L3INIT_HSUSBHOST_CLKCTRL);
  267. utmi_clk |= HSUSBHOST_CLKCTRL_CLKSEL_UTMI_P1_MASK;
  268. setbits_le32((void *)CM_L3INIT_HSUSBHOST_CLKCTRL, utmi_clk);
  269. ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
  270. if (ret < 0)
  271. return ret;
  272. return 0;
  273. }
  274. int ehci_hcd_stop(int index)
  275. {
  276. return omap_ehci_hcd_stop();
  277. }
  278. #endif
  279. /*
  280. * get_board_rev() - get board revision
  281. */
  282. u32 get_board_rev(void)
  283. {
  284. return 0x20;
  285. }