mx28.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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/gpio.h>
  33. #include <asm/arch/iomux.h>
  34. #include <asm/arch/imx-regs.h>
  35. #include <asm/arch/sys_proto.h>
  36. DECLARE_GLOBAL_DATA_PTR;
  37. /* 1 second delay should be plenty of time for block reset. */
  38. #define RESET_MAX_TIMEOUT 1000000
  39. #define MX28_BLOCK_SFTRST (1 << 31)
  40. #define MX28_BLOCK_CLKGATE (1 << 30)
  41. /* Lowlevel init isn't used on i.MX28, so just have a dummy here */
  42. inline void lowlevel_init(void) {}
  43. void reset_cpu(ulong ignored) __attribute__((noreturn));
  44. void reset_cpu(ulong ignored)
  45. {
  46. struct mx28_rtc_regs *rtc_regs =
  47. (struct mx28_rtc_regs *)MXS_RTC_BASE;
  48. /* Wait 1 uS before doing the actual watchdog reset */
  49. writel(1, &rtc_regs->hw_rtc_watchdog);
  50. writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
  51. /* Endless loop, reset will exit from here */
  52. for (;;)
  53. ;
  54. }
  55. int mx28_wait_mask_set(struct mx28_register_32 *reg, uint32_t mask, int timeout)
  56. {
  57. while (--timeout) {
  58. if ((readl(&reg->reg) & mask) == mask)
  59. break;
  60. udelay(1);
  61. }
  62. return !timeout;
  63. }
  64. int mx28_wait_mask_clr(struct mx28_register_32 *reg, uint32_t mask, int timeout)
  65. {
  66. while (--timeout) {
  67. if ((readl(&reg->reg) & mask) == 0)
  68. break;
  69. udelay(1);
  70. }
  71. return !timeout;
  72. }
  73. int mx28_reset_block(struct mx28_register_32 *reg)
  74. {
  75. /* Clear SFTRST */
  76. writel(MX28_BLOCK_SFTRST, &reg->reg_clr);
  77. if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
  78. return 1;
  79. /* Clear CLKGATE */
  80. writel(MX28_BLOCK_CLKGATE, &reg->reg_clr);
  81. /* Set SFTRST */
  82. writel(MX28_BLOCK_SFTRST, &reg->reg_set);
  83. /* Wait for CLKGATE being set */
  84. if (mx28_wait_mask_set(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
  85. return 1;
  86. /* Clear SFTRST */
  87. writel(MX28_BLOCK_SFTRST, &reg->reg_clr);
  88. if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
  89. return 1;
  90. /* Clear CLKGATE */
  91. writel(MX28_BLOCK_CLKGATE, &reg->reg_clr);
  92. if (mx28_wait_mask_clr(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
  93. return 1;
  94. return 0;
  95. }
  96. void mx28_fixup_vt(uint32_t start_addr)
  97. {
  98. uint32_t *vt = (uint32_t *)0x20;
  99. int i;
  100. for (i = 0; i < 8; i++)
  101. vt[i] = start_addr + (4 * i);
  102. }
  103. #ifdef CONFIG_ARCH_MISC_INIT
  104. int arch_misc_init(void)
  105. {
  106. mx28_fixup_vt(gd->relocaddr);
  107. return 0;
  108. }
  109. #endif
  110. #ifdef CONFIG_ARCH_CPU_INIT
  111. int arch_cpu_init(void)
  112. {
  113. struct mx28_clkctrl_regs *clkctrl_regs =
  114. (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
  115. extern uint32_t _start;
  116. mx28_fixup_vt((uint32_t)&_start);
  117. /*
  118. * Enable NAND clock
  119. */
  120. /* Clear bypass bit */
  121. writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
  122. &clkctrl_regs->hw_clkctrl_clkseq_set);
  123. /* Set GPMI clock to ref_gpmi / 12 */
  124. clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
  125. CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1);
  126. udelay(1000);
  127. /*
  128. * Configure GPIO unit
  129. */
  130. mxs_gpio_init();
  131. return 0;
  132. }
  133. #endif
  134. #if defined(CONFIG_DISPLAY_CPUINFO)
  135. int print_cpuinfo(void)
  136. {
  137. printf("Freescale i.MX28 family at %d MHz\n",
  138. mxc_get_clock(MXC_ARM_CLK) / 1000000);
  139. return 0;
  140. }
  141. #endif
  142. int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  143. {
  144. printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
  145. printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
  146. printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
  147. printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
  148. return 0;
  149. }
  150. /*
  151. * Initializes on-chip ethernet controllers.
  152. */
  153. #ifdef CONFIG_CMD_NET
  154. int cpu_eth_init(bd_t *bis)
  155. {
  156. struct mx28_clkctrl_regs *clkctrl_regs =
  157. (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
  158. /* Turn on ENET clocks */
  159. clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
  160. CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
  161. /* Set up ENET PLL for 50 MHz */
  162. /* Power on ENET PLL */
  163. writel(CLKCTRL_PLL2CTRL0_POWER,
  164. &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
  165. udelay(10);
  166. /* Gate on ENET PLL */
  167. writel(CLKCTRL_PLL2CTRL0_CLKGATE,
  168. &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
  169. /* Enable pad output */
  170. setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
  171. return 0;
  172. }
  173. #endif
  174. static void __mx28_adjust_mac(int dev_id, unsigned char *mac)
  175. {
  176. mac[0] = 0x00;
  177. mac[1] = 0x04; /* Use FSL vendor MAC address by default */
  178. if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
  179. mac[5] += 1;
  180. }
  181. void mx28_adjust_mac(int dev_id, unsigned char *mac)
  182. __attribute__((weak, alias("__mx28_adjust_mac")));
  183. #ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
  184. #define MXS_OCOTP_MAX_TIMEOUT 1000000
  185. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  186. {
  187. struct mx28_ocotp_regs *ocotp_regs =
  188. (struct mx28_ocotp_regs *)MXS_OCOTP_BASE;
  189. uint32_t data;
  190. memset(mac, 0, 6);
  191. writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
  192. if (mx28_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
  193. MXS_OCOTP_MAX_TIMEOUT)) {
  194. printf("MXS FEC: Can't get MAC from OCOTP\n");
  195. return;
  196. }
  197. data = readl(&ocotp_regs->hw_ocotp_cust0);
  198. mac[2] = (data >> 24) & 0xff;
  199. mac[3] = (data >> 16) & 0xff;
  200. mac[4] = (data >> 8) & 0xff;
  201. mac[5] = data & 0xff;
  202. mx28_adjust_mac(dev_id, mac);
  203. }
  204. #else
  205. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  206. {
  207. memset(mac, 0, 6);
  208. }
  209. #endif
  210. int mx28_dram_init(void)
  211. {
  212. struct mx28_digctl_regs *digctl_regs =
  213. (struct mx28_digctl_regs *)MXS_DIGCTL_BASE;
  214. uint32_t sz[2];
  215. sz[0] = readl(&digctl_regs->hw_digctl_scratch0);
  216. sz[1] = readl(&digctl_regs->hw_digctl_scratch1);
  217. if (sz[0] != sz[1]) {
  218. printf("MX28:\n"
  219. "Error, the RAM size in HW_DIGCTRL_SCRATCH0 and\n"
  220. "HW_DIGCTRL_SCRATCH1 is not the same. Please\n"
  221. "verify these two registers contain valid RAM size!\n");
  222. hang();
  223. }
  224. gd->ram_size = sz[0];
  225. return 0;
  226. }
  227. U_BOOT_CMD(
  228. clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
  229. "display clocks",
  230. ""
  231. );