cpu.c 4.1 KB

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