mx28.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * Freescale i.MX28 common code
  3. *
  4. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  5. * on behalf of DENX Software Engineering GmbH
  6. *
  7. * Based on code from LTIB:
  8. * Copyright (C) 2010 Freescale Semiconductor, Inc.
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <asm/errno.h>
  30. #include <asm/io.h>
  31. #include <asm/arch/clock.h>
  32. #include <asm/arch/dma.h>
  33. #include <asm/arch/gpio.h>
  34. #include <asm/arch/iomux.h>
  35. #include <asm/arch/imx-regs.h>
  36. #include <asm/arch/sys_proto.h>
  37. DECLARE_GLOBAL_DATA_PTR;
  38. /* 1 second delay should be plenty of time for block reset. */
  39. #define RESET_MAX_TIMEOUT 1000000
  40. #define MX28_BLOCK_SFTRST (1 << 31)
  41. #define MX28_BLOCK_CLKGATE (1 << 30)
  42. /* Lowlevel init isn't used on i.MX28, so just have a dummy here */
  43. inline void lowlevel_init(void) {}
  44. void reset_cpu(ulong ignored) __attribute__((noreturn));
  45. void reset_cpu(ulong ignored)
  46. {
  47. struct mx28_rtc_regs *rtc_regs =
  48. (struct mx28_rtc_regs *)MXS_RTC_BASE;
  49. /* Wait 1 uS before doing the actual watchdog reset */
  50. writel(1, &rtc_regs->hw_rtc_watchdog);
  51. writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
  52. /* Endless loop, reset will exit from here */
  53. for (;;)
  54. ;
  55. }
  56. void enable_caches(void)
  57. {
  58. #ifndef CONFIG_SYS_ICACHE_OFF
  59. icache_enable();
  60. #endif
  61. #ifndef CONFIG_SYS_DCACHE_OFF
  62. dcache_enable();
  63. #endif
  64. }
  65. int mx28_wait_mask_set(struct mx28_register_32 *reg, uint32_t mask, int timeout)
  66. {
  67. while (--timeout) {
  68. if ((readl(&reg->reg) & mask) == mask)
  69. break;
  70. udelay(1);
  71. }
  72. return !timeout;
  73. }
  74. int mx28_wait_mask_clr(struct mx28_register_32 *reg, uint32_t mask, int timeout)
  75. {
  76. while (--timeout) {
  77. if ((readl(&reg->reg) & mask) == 0)
  78. break;
  79. udelay(1);
  80. }
  81. return !timeout;
  82. }
  83. int mx28_reset_block(struct mx28_register_32 *reg)
  84. {
  85. /* Clear SFTRST */
  86. writel(MX28_BLOCK_SFTRST, &reg->reg_clr);
  87. if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
  88. return 1;
  89. /* Clear CLKGATE */
  90. writel(MX28_BLOCK_CLKGATE, &reg->reg_clr);
  91. /* Set SFTRST */
  92. writel(MX28_BLOCK_SFTRST, &reg->reg_set);
  93. /* Wait for CLKGATE being set */
  94. if (mx28_wait_mask_set(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
  95. return 1;
  96. /* Clear SFTRST */
  97. writel(MX28_BLOCK_SFTRST, &reg->reg_clr);
  98. if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
  99. return 1;
  100. /* Clear CLKGATE */
  101. writel(MX28_BLOCK_CLKGATE, &reg->reg_clr);
  102. if (mx28_wait_mask_clr(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
  103. return 1;
  104. return 0;
  105. }
  106. void mx28_fixup_vt(uint32_t start_addr)
  107. {
  108. uint32_t *vt = (uint32_t *)0x20;
  109. int i;
  110. for (i = 0; i < 8; i++)
  111. vt[i] = start_addr + (4 * i);
  112. }
  113. #ifdef CONFIG_ARCH_MISC_INIT
  114. int arch_misc_init(void)
  115. {
  116. mx28_fixup_vt(gd->relocaddr);
  117. return 0;
  118. }
  119. #endif
  120. #ifdef CONFIG_ARCH_CPU_INIT
  121. int arch_cpu_init(void)
  122. {
  123. struct mx28_clkctrl_regs *clkctrl_regs =
  124. (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
  125. extern uint32_t _start;
  126. mx28_fixup_vt((uint32_t)&_start);
  127. /*
  128. * Enable NAND clock
  129. */
  130. /* Clear bypass bit */
  131. writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
  132. &clkctrl_regs->hw_clkctrl_clkseq_set);
  133. /* Set GPMI clock to ref_gpmi / 12 */
  134. clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
  135. CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1);
  136. udelay(1000);
  137. /*
  138. * Configure GPIO unit
  139. */
  140. mxs_gpio_init();
  141. #ifdef CONFIG_APBH_DMA
  142. /* Start APBH DMA */
  143. mxs_dma_init();
  144. #endif
  145. return 0;
  146. }
  147. #endif
  148. #if defined(CONFIG_DISPLAY_CPUINFO)
  149. int print_cpuinfo(void)
  150. {
  151. struct mx28_spl_data *data = (struct mx28_spl_data *)
  152. ((CONFIG_SYS_TEXT_BASE - sizeof(struct mx28_spl_data)) & ~0xf);
  153. printf("Freescale i.MX28 family at %d MHz\n",
  154. mxc_get_clock(MXC_ARM_CLK) / 1000000);
  155. printf("BOOT: %s\n", mx28_boot_modes[data->boot_mode_idx].mode);
  156. return 0;
  157. }
  158. #endif
  159. int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  160. {
  161. printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
  162. printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
  163. printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
  164. printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
  165. return 0;
  166. }
  167. /*
  168. * Initializes on-chip ethernet controllers.
  169. */
  170. #ifdef CONFIG_CMD_NET
  171. int cpu_eth_init(bd_t *bis)
  172. {
  173. struct mx28_clkctrl_regs *clkctrl_regs =
  174. (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
  175. /* Turn on ENET clocks */
  176. clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
  177. CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
  178. /* Set up ENET PLL for 50 MHz */
  179. /* Power on ENET PLL */
  180. writel(CLKCTRL_PLL2CTRL0_POWER,
  181. &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
  182. udelay(10);
  183. /* Gate on ENET PLL */
  184. writel(CLKCTRL_PLL2CTRL0_CLKGATE,
  185. &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
  186. /* Enable pad output */
  187. setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
  188. return 0;
  189. }
  190. #endif
  191. static void __mx28_adjust_mac(int dev_id, unsigned char *mac)
  192. {
  193. mac[0] = 0x00;
  194. mac[1] = 0x04; /* Use FSL vendor MAC address by default */
  195. if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
  196. mac[5] += 1;
  197. }
  198. void mx28_adjust_mac(int dev_id, unsigned char *mac)
  199. __attribute__((weak, alias("__mx28_adjust_mac")));
  200. #ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
  201. #define MXS_OCOTP_MAX_TIMEOUT 1000000
  202. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  203. {
  204. struct mx28_ocotp_regs *ocotp_regs =
  205. (struct mx28_ocotp_regs *)MXS_OCOTP_BASE;
  206. uint32_t data;
  207. memset(mac, 0, 6);
  208. writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
  209. if (mx28_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
  210. MXS_OCOTP_MAX_TIMEOUT)) {
  211. printf("MXS FEC: Can't get MAC from OCOTP\n");
  212. return;
  213. }
  214. data = readl(&ocotp_regs->hw_ocotp_cust0);
  215. mac[2] = (data >> 24) & 0xff;
  216. mac[3] = (data >> 16) & 0xff;
  217. mac[4] = (data >> 8) & 0xff;
  218. mac[5] = data & 0xff;
  219. mx28_adjust_mac(dev_id, mac);
  220. }
  221. #else
  222. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  223. {
  224. memset(mac, 0, 6);
  225. }
  226. #endif
  227. int mx28_dram_init(void)
  228. {
  229. struct mx28_spl_data *data = (struct mx28_spl_data *)
  230. ((CONFIG_SYS_TEXT_BASE - sizeof(struct mx28_spl_data)) & ~0xf);
  231. if (data->mem_dram_size == 0) {
  232. printf("MX28:\n"
  233. "Error, the RAM size passed up from SPL is 0!\n");
  234. hang();
  235. }
  236. gd->ram_size = data->mem_dram_size;
  237. return 0;
  238. }
  239. U_BOOT_CMD(
  240. clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
  241. "display clocks",
  242. ""
  243. );