mxs.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * Freescale i.MX23/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/imx-common/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. #include <linux/compiler.h>
  38. DECLARE_GLOBAL_DATA_PTR;
  39. /* Lowlevel init isn't used on i.MX28, so just have a dummy here */
  40. inline void lowlevel_init(void) {}
  41. void reset_cpu(ulong ignored) __attribute__((noreturn));
  42. void reset_cpu(ulong ignored)
  43. {
  44. struct mxs_rtc_regs *rtc_regs =
  45. (struct mxs_rtc_regs *)MXS_RTC_BASE;
  46. struct mxs_lcdif_regs *lcdif_regs =
  47. (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
  48. /*
  49. * Shut down the LCD controller as it interferes with BootROM boot mode
  50. * pads sampling.
  51. */
  52. writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr);
  53. /* Wait 1 uS before doing the actual watchdog reset */
  54. writel(1, &rtc_regs->hw_rtc_watchdog);
  55. writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
  56. /* Endless loop, reset will exit from here */
  57. for (;;)
  58. ;
  59. }
  60. void enable_caches(void)
  61. {
  62. #ifndef CONFIG_SYS_ICACHE_OFF
  63. icache_enable();
  64. #endif
  65. #ifndef CONFIG_SYS_DCACHE_OFF
  66. dcache_enable();
  67. #endif
  68. }
  69. /*
  70. * This function will craft a jumptable at 0x0 which will redirect interrupt
  71. * vectoring to proper location of U-Boot in RAM.
  72. *
  73. * The structure of the jumptable will be as follows:
  74. * ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times
  75. * <destination address> ... for each previous ldr, thus also repeated 8 times
  76. *
  77. * The "ldr pc, [pc, #0x18]" instruction above loads address from memory at
  78. * offset 0x18 from current value of PC register. Note that PC is already
  79. * incremented by 4 when computing the offset, so the effective offset is
  80. * actually 0x20, this the associated <destination address>. Loading the PC
  81. * register with an address performs a jump to that address.
  82. */
  83. void mx28_fixup_vt(uint32_t start_addr)
  84. {
  85. /* ldr pc, [pc, #0x18] */
  86. const uint32_t ldr_pc = 0xe59ff018;
  87. /* Jumptable location is 0x0 */
  88. uint32_t *vt = (uint32_t *)0x0;
  89. int i;
  90. for (i = 0; i < 8; i++) {
  91. vt[i] = ldr_pc;
  92. vt[i + 8] = start_addr + (4 * i);
  93. }
  94. }
  95. #ifdef CONFIG_ARCH_MISC_INIT
  96. int arch_misc_init(void)
  97. {
  98. mx28_fixup_vt(gd->relocaddr);
  99. return 0;
  100. }
  101. #endif
  102. int arch_cpu_init(void)
  103. {
  104. struct mxs_clkctrl_regs *clkctrl_regs =
  105. (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
  106. extern uint32_t _start;
  107. mx28_fixup_vt((uint32_t)&_start);
  108. /*
  109. * Enable NAND clock
  110. */
  111. /* Clear bypass bit */
  112. writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
  113. &clkctrl_regs->hw_clkctrl_clkseq_set);
  114. /* Set GPMI clock to ref_gpmi / 12 */
  115. clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
  116. CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1);
  117. udelay(1000);
  118. /*
  119. * Configure GPIO unit
  120. */
  121. mxs_gpio_init();
  122. #ifdef CONFIG_APBH_DMA
  123. /* Start APBH DMA */
  124. mxs_dma_init();
  125. #endif
  126. return 0;
  127. }
  128. #if defined(CONFIG_DISPLAY_CPUINFO)
  129. static const char *get_cpu_type(void)
  130. {
  131. struct mxs_digctl_regs *digctl_regs =
  132. (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
  133. switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
  134. case HW_DIGCTL_CHIPID_MX23:
  135. return "23";
  136. case HW_DIGCTL_CHIPID_MX28:
  137. return "28";
  138. default:
  139. return "??";
  140. }
  141. }
  142. static const char *get_cpu_rev(void)
  143. {
  144. struct mxs_digctl_regs *digctl_regs =
  145. (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
  146. uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;
  147. switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
  148. case HW_DIGCTL_CHIPID_MX23:
  149. switch (rev) {
  150. case 0x0:
  151. return "1.0";
  152. case 0x1:
  153. return "1.1";
  154. case 0x2:
  155. return "1.2";
  156. case 0x3:
  157. return "1.3";
  158. case 0x4:
  159. return "1.4";
  160. default:
  161. return "??";
  162. }
  163. case HW_DIGCTL_CHIPID_MX28:
  164. switch (rev) {
  165. case 0x1:
  166. return "1.2";
  167. default:
  168. return "??";
  169. }
  170. default:
  171. return "??";
  172. }
  173. }
  174. int print_cpuinfo(void)
  175. {
  176. struct mxs_spl_data *data = (struct mxs_spl_data *)
  177. ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
  178. printf("CPU: Freescale i.MX%s rev%s at %d MHz\n",
  179. get_cpu_type(),
  180. get_cpu_rev(),
  181. mxc_get_clock(MXC_ARM_CLK) / 1000000);
  182. printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
  183. return 0;
  184. }
  185. #endif
  186. int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  187. {
  188. printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
  189. printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
  190. printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
  191. printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
  192. return 0;
  193. }
  194. /*
  195. * Initializes on-chip ethernet controllers.
  196. */
  197. #if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
  198. int cpu_eth_init(bd_t *bis)
  199. {
  200. struct mxs_clkctrl_regs *clkctrl_regs =
  201. (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
  202. /* Turn on ENET clocks */
  203. clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
  204. CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
  205. /* Set up ENET PLL for 50 MHz */
  206. /* Power on ENET PLL */
  207. writel(CLKCTRL_PLL2CTRL0_POWER,
  208. &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
  209. udelay(10);
  210. /* Gate on ENET PLL */
  211. writel(CLKCTRL_PLL2CTRL0_CLKGATE,
  212. &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
  213. /* Enable pad output */
  214. setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
  215. return 0;
  216. }
  217. #endif
  218. __weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
  219. {
  220. mac[0] = 0x00;
  221. mac[1] = 0x04; /* Use FSL vendor MAC address by default */
  222. if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
  223. mac[5] += 1;
  224. }
  225. #ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
  226. #define MXS_OCOTP_MAX_TIMEOUT 1000000
  227. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  228. {
  229. struct mxs_ocotp_regs *ocotp_regs =
  230. (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
  231. uint32_t data;
  232. memset(mac, 0, 6);
  233. writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
  234. if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
  235. MXS_OCOTP_MAX_TIMEOUT)) {
  236. printf("MXS FEC: Can't get MAC from OCOTP\n");
  237. return;
  238. }
  239. data = readl(&ocotp_regs->hw_ocotp_cust0);
  240. mac[2] = (data >> 24) & 0xff;
  241. mac[3] = (data >> 16) & 0xff;
  242. mac[4] = (data >> 8) & 0xff;
  243. mac[5] = data & 0xff;
  244. mx28_adjust_mac(dev_id, mac);
  245. }
  246. #else
  247. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  248. {
  249. memset(mac, 0, 6);
  250. }
  251. #endif
  252. int mxs_dram_init(void)
  253. {
  254. struct mxs_spl_data *data = (struct mxs_spl_data *)
  255. ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
  256. if (data->mem_dram_size == 0) {
  257. printf("MXS:\n"
  258. "Error, the RAM size passed up from SPL is 0!\n");
  259. hang();
  260. }
  261. gd->ram_size = data->mem_dram_size;
  262. return 0;
  263. }
  264. U_BOOT_CMD(
  265. clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
  266. "display clocks",
  267. ""
  268. );