cpu.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * (C) Copyright 2007
  3. * Sascha Hauer, Pengutronix
  4. *
  5. * (C) Copyright 2009 Freescale Semiconductor, Inc.
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <bootm.h>
  10. #include <common.h>
  11. #include <netdev.h>
  12. #include <asm/errno.h>
  13. #include <asm/io.h>
  14. #include <asm/arch/imx-regs.h>
  15. #include <asm/arch/clock.h>
  16. #include <asm/arch/sys_proto.h>
  17. #include <asm/arch/crm_regs.h>
  18. #include <ipu_pixfmt.h>
  19. #ifdef CONFIG_FSL_ESDHC
  20. #include <fsl_esdhc.h>
  21. #endif
  22. char *get_reset_cause(void)
  23. {
  24. u32 cause;
  25. struct src *src_regs = (struct src *)SRC_BASE_ADDR;
  26. cause = readl(&src_regs->srsr);
  27. writel(cause, &src_regs->srsr);
  28. switch (cause) {
  29. case 0x00001:
  30. case 0x00011:
  31. return "POR";
  32. case 0x00004:
  33. return "CSU";
  34. case 0x00008:
  35. return "IPP USER";
  36. case 0x00010:
  37. return "WDOG";
  38. case 0x00020:
  39. return "JTAG HIGH-Z";
  40. case 0x00040:
  41. return "JTAG SW";
  42. case 0x10000:
  43. return "WARM BOOT";
  44. default:
  45. return "unknown reset";
  46. }
  47. }
  48. #if defined(CONFIG_MX53) || defined(CONFIG_MX6)
  49. #if defined(CONFIG_MX53)
  50. #define MEMCTL_BASE ESDCTL_BASE_ADDR
  51. #else
  52. #define MEMCTL_BASE MMDC_P0_BASE_ADDR
  53. #endif
  54. static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
  55. static const unsigned char bank_lookup[] = {3, 2};
  56. /* these MMDC registers are common to the IMX53 and IMX6 */
  57. struct esd_mmdc_regs {
  58. uint32_t ctl;
  59. uint32_t pdc;
  60. uint32_t otc;
  61. uint32_t cfg0;
  62. uint32_t cfg1;
  63. uint32_t cfg2;
  64. uint32_t misc;
  65. };
  66. #define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7)
  67. #define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7)
  68. #define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3)
  69. #define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1)
  70. #define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1)
  71. /*
  72. * imx_ddr_size - return size in bytes of DRAM according MMDC config
  73. * The MMDC MDCTL register holds the number of bits for row, col, and data
  74. * width and the MMDC MDMISC register holds the number of banks. Combine
  75. * all these bits to determine the meme size the MMDC has been configured for
  76. */
  77. unsigned imx_ddr_size(void)
  78. {
  79. struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
  80. unsigned ctl = readl(&mem->ctl);
  81. unsigned misc = readl(&mem->misc);
  82. int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */
  83. bits += ESD_MMDC_CTL_GET_ROW(ctl);
  84. bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
  85. bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
  86. bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
  87. bits += ESD_MMDC_CTL_GET_CS1(ctl);
  88. /* The MX6 can do only 3840 MiB of DRAM */
  89. if (bits == 32)
  90. return 0xf0000000;
  91. return 1 << bits;
  92. }
  93. #endif
  94. #if defined(CONFIG_DISPLAY_CPUINFO)
  95. const char *get_imx_type(u32 imxtype)
  96. {
  97. switch (imxtype) {
  98. case MXC_CPU_MX6Q:
  99. return "6Q"; /* Quad-core version of the mx6 */
  100. case MXC_CPU_MX6D:
  101. return "6D"; /* Dual-core version of the mx6 */
  102. case MXC_CPU_MX6DL:
  103. return "6DL"; /* Dual Lite version of the mx6 */
  104. case MXC_CPU_MX6SOLO:
  105. return "6SOLO"; /* Solo version of the mx6 */
  106. case MXC_CPU_MX6SL:
  107. return "6SL"; /* Solo-Lite version of the mx6 */
  108. case MXC_CPU_MX6SX:
  109. return "6SX"; /* SoloX version of the mx6 */
  110. case MXC_CPU_MX51:
  111. return "51";
  112. case MXC_CPU_MX53:
  113. return "53";
  114. default:
  115. return "??";
  116. }
  117. }
  118. int print_cpuinfo(void)
  119. {
  120. u32 cpurev;
  121. cpurev = get_cpu_rev();
  122. printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
  123. get_imx_type((cpurev & 0xFF000) >> 12),
  124. (cpurev & 0x000F0) >> 4,
  125. (cpurev & 0x0000F) >> 0,
  126. mxc_get_clock(MXC_ARM_CLK) / 1000000);
  127. printf("Reset cause: %s\n", get_reset_cause());
  128. return 0;
  129. }
  130. #endif
  131. int cpu_eth_init(bd_t *bis)
  132. {
  133. int rc = -ENODEV;
  134. #if defined(CONFIG_FEC_MXC)
  135. rc = fecmxc_initialize(bis);
  136. #endif
  137. return rc;
  138. }
  139. #ifdef CONFIG_FSL_ESDHC
  140. /*
  141. * Initializes on-chip MMC controllers.
  142. * to override, implement board_mmc_init()
  143. */
  144. int cpu_mmc_init(bd_t *bis)
  145. {
  146. return fsl_esdhc_mmc_init(bis);
  147. }
  148. #endif
  149. u32 get_ahb_clk(void)
  150. {
  151. struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  152. u32 reg, ahb_podf;
  153. reg = __raw_readl(&imx_ccm->cbcdr);
  154. reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
  155. ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
  156. return get_periph_clk() / (ahb_podf + 1);
  157. }
  158. #if defined(CONFIG_VIDEO_IPUV3)
  159. void arch_preboot_os(void)
  160. {
  161. /* disable video before launching O/S */
  162. ipuv3_fb_shutdown();
  163. }
  164. #endif