mxs.c 8.0 KB

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