mx28.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. /* 1 second delay should be plenty of time for block reset. */
  37. #define RESET_MAX_TIMEOUT 1000000
  38. #define MX28_BLOCK_SFTRST (1 << 31)
  39. #define MX28_BLOCK_CLKGATE (1 << 30)
  40. /* Lowlevel init isn't used on i.MX28, so just have a dummy here */
  41. inline void lowlevel_init(void) {}
  42. void reset_cpu(ulong ignored) __attribute__((noreturn));
  43. void reset_cpu(ulong ignored)
  44. {
  45. struct mx28_rtc_regs *rtc_regs =
  46. (struct mx28_rtc_regs *)MXS_RTC_BASE;
  47. /* Wait 1 uS before doing the actual watchdog reset */
  48. writel(1, &rtc_regs->hw_rtc_watchdog);
  49. writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
  50. /* Endless loop, reset will exit from here */
  51. for (;;)
  52. ;
  53. }
  54. int mx28_wait_mask_set(struct mx28_register *reg, uint32_t mask, int timeout)
  55. {
  56. while (--timeout) {
  57. if ((readl(&reg->reg) & mask) == mask)
  58. break;
  59. udelay(1);
  60. }
  61. return !timeout;
  62. }
  63. int mx28_wait_mask_clr(struct mx28_register *reg, uint32_t mask, int timeout)
  64. {
  65. while (--timeout) {
  66. if ((readl(&reg->reg) & mask) == 0)
  67. break;
  68. udelay(1);
  69. }
  70. return !timeout;
  71. }
  72. int mx28_reset_block(struct mx28_register *reg)
  73. {
  74. /* Clear SFTRST */
  75. writel(MX28_BLOCK_SFTRST, &reg->reg_clr);
  76. if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
  77. return 1;
  78. /* Clear CLKGATE */
  79. writel(MX28_BLOCK_CLKGATE, &reg->reg_clr);
  80. /* Set SFTRST */
  81. writel(MX28_BLOCK_SFTRST, &reg->reg_set);
  82. /* Wait for CLKGATE being set */
  83. if (mx28_wait_mask_set(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
  84. return 1;
  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. if (mx28_wait_mask_clr(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
  92. return 1;
  93. return 0;
  94. }
  95. #ifdef CONFIG_ARCH_CPU_INIT
  96. int arch_cpu_init(void)
  97. {
  98. struct mx28_clkctrl_regs *clkctrl_regs =
  99. (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
  100. /*
  101. * Enable NAND clock
  102. */
  103. /* Clear bypass bit */
  104. writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
  105. &clkctrl_regs->hw_clkctrl_clkseq_set);
  106. /* Set GPMI clock to ref_gpmi / 12 */
  107. clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
  108. CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1);
  109. udelay(1000);
  110. /*
  111. * Configure GPIO unit
  112. */
  113. mxs_gpio_init();
  114. return 0;
  115. }
  116. #endif
  117. #if defined(CONFIG_DISPLAY_CPUINFO)
  118. int print_cpuinfo(void)
  119. {
  120. printf("Freescale i.MX28 family\n");
  121. return 0;
  122. }
  123. #endif
  124. int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  125. {
  126. printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
  127. printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
  128. printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
  129. printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
  130. return 0;
  131. }
  132. /*
  133. * Initializes on-chip ethernet controllers.
  134. */
  135. #ifdef CONFIG_CMD_NET
  136. int cpu_eth_init(bd_t *bis)
  137. {
  138. struct mx28_clkctrl_regs *clkctrl_regs =
  139. (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
  140. /* Turn on ENET clocks */
  141. clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
  142. CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
  143. /* Set up ENET PLL for 50 MHz */
  144. /* Power on ENET PLL */
  145. writel(CLKCTRL_PLL2CTRL0_POWER,
  146. &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
  147. udelay(10);
  148. /* Gate on ENET PLL */
  149. writel(CLKCTRL_PLL2CTRL0_CLKGATE,
  150. &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
  151. /* Enable pad output */
  152. setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
  153. return 0;
  154. }
  155. #endif
  156. U_BOOT_CMD(
  157. clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
  158. "display clocks",
  159. ""
  160. );