cpu.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. #include <thermal.h>
  20. #include <sata.h>
  21. #ifdef CONFIG_FSL_ESDHC
  22. #include <fsl_esdhc.h>
  23. #endif
  24. #if defined(CONFIG_DISPLAY_CPUINFO)
  25. static u32 reset_cause = -1;
  26. static char *get_reset_cause(void)
  27. {
  28. u32 cause;
  29. struct src *src_regs = (struct src *)SRC_BASE_ADDR;
  30. cause = readl(&src_regs->srsr);
  31. writel(cause, &src_regs->srsr);
  32. reset_cause = cause;
  33. switch (cause) {
  34. case 0x00001:
  35. case 0x00011:
  36. return "POR";
  37. case 0x00004:
  38. return "CSU";
  39. case 0x00008:
  40. return "IPP USER";
  41. case 0x00010:
  42. return "WDOG";
  43. case 0x00020:
  44. return "JTAG HIGH-Z";
  45. case 0x00040:
  46. return "JTAG SW";
  47. case 0x10000:
  48. return "WARM BOOT";
  49. default:
  50. return "unknown reset";
  51. }
  52. }
  53. u32 get_imx_reset_cause(void)
  54. {
  55. return reset_cause;
  56. }
  57. #endif
  58. #if defined(CONFIG_MX53) || defined(CONFIG_MX6)
  59. #if defined(CONFIG_MX53)
  60. #define MEMCTL_BASE ESDCTL_BASE_ADDR
  61. #else
  62. #define MEMCTL_BASE MMDC_P0_BASE_ADDR
  63. #endif
  64. static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
  65. static const unsigned char bank_lookup[] = {3, 2};
  66. /* these MMDC registers are common to the IMX53 and IMX6 */
  67. struct esd_mmdc_regs {
  68. uint32_t ctl;
  69. uint32_t pdc;
  70. uint32_t otc;
  71. uint32_t cfg0;
  72. uint32_t cfg1;
  73. uint32_t cfg2;
  74. uint32_t misc;
  75. };
  76. #define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7)
  77. #define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7)
  78. #define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3)
  79. #define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1)
  80. #define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1)
  81. /*
  82. * imx_ddr_size - return size in bytes of DRAM according MMDC config
  83. * The MMDC MDCTL register holds the number of bits for row, col, and data
  84. * width and the MMDC MDMISC register holds the number of banks. Combine
  85. * all these bits to determine the meme size the MMDC has been configured for
  86. */
  87. unsigned imx_ddr_size(void)
  88. {
  89. struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
  90. unsigned ctl = readl(&mem->ctl);
  91. unsigned misc = readl(&mem->misc);
  92. int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */
  93. bits += ESD_MMDC_CTL_GET_ROW(ctl);
  94. bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
  95. bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
  96. bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
  97. bits += ESD_MMDC_CTL_GET_CS1(ctl);
  98. /* The MX6 can do only 3840 MiB of DRAM */
  99. if (bits == 32)
  100. return 0xf0000000;
  101. return 1 << bits;
  102. }
  103. #endif
  104. #if defined(CONFIG_DISPLAY_CPUINFO)
  105. const char *get_imx_type(u32 imxtype)
  106. {
  107. switch (imxtype) {
  108. case MXC_CPU_MX6Q:
  109. return "6Q"; /* Quad-core version of the mx6 */
  110. case MXC_CPU_MX6D:
  111. return "6D"; /* Dual-core version of the mx6 */
  112. case MXC_CPU_MX6DL:
  113. return "6DL"; /* Dual Lite version of the mx6 */
  114. case MXC_CPU_MX6SOLO:
  115. return "6SOLO"; /* Solo version of the mx6 */
  116. case MXC_CPU_MX6SL:
  117. return "6SL"; /* Solo-Lite version of the mx6 */
  118. case MXC_CPU_MX6SX:
  119. return "6SX"; /* SoloX version of the mx6 */
  120. case MXC_CPU_MX51:
  121. return "51";
  122. case MXC_CPU_MX53:
  123. return "53";
  124. default:
  125. return "??";
  126. }
  127. }
  128. int print_cpuinfo(void)
  129. {
  130. u32 cpurev, max_freq;
  131. #if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL)
  132. struct udevice *thermal_dev;
  133. int cpu_tmp, ret;
  134. #endif
  135. cpurev = get_cpu_rev();
  136. #if defined(CONFIG_MX6)
  137. printf("CPU: Freescale i.MX%s rev%d.%d",
  138. get_imx_type((cpurev & 0xFF000) >> 12),
  139. (cpurev & 0x000F0) >> 4,
  140. (cpurev & 0x0000F) >> 0);
  141. max_freq = get_cpu_speed_grade_hz();
  142. if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
  143. printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
  144. } else {
  145. printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
  146. mxc_get_clock(MXC_ARM_CLK) / 1000000);
  147. }
  148. #else
  149. printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
  150. get_imx_type((cpurev & 0xFF000) >> 12),
  151. (cpurev & 0x000F0) >> 4,
  152. (cpurev & 0x0000F) >> 0,
  153. mxc_get_clock(MXC_ARM_CLK) / 1000000);
  154. #endif
  155. #if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL)
  156. ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
  157. if (!ret) {
  158. ret = thermal_get_temp(thermal_dev, &cpu_tmp);
  159. if (!ret)
  160. printf("CPU: Temperature %d C\n", cpu_tmp);
  161. else
  162. printf("CPU: Temperature: invalid sensor data\n");
  163. } else {
  164. printf("CPU: Temperature: Can't find sensor device\n");
  165. }
  166. #endif
  167. printf("Reset cause: %s\n", get_reset_cause());
  168. return 0;
  169. }
  170. #endif
  171. int cpu_eth_init(bd_t *bis)
  172. {
  173. int rc = -ENODEV;
  174. #if defined(CONFIG_FEC_MXC)
  175. rc = fecmxc_initialize(bis);
  176. #endif
  177. return rc;
  178. }
  179. #ifdef CONFIG_FSL_ESDHC
  180. /*
  181. * Initializes on-chip MMC controllers.
  182. * to override, implement board_mmc_init()
  183. */
  184. int cpu_mmc_init(bd_t *bis)
  185. {
  186. return fsl_esdhc_mmc_init(bis);
  187. }
  188. #endif
  189. u32 get_ahb_clk(void)
  190. {
  191. struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  192. u32 reg, ahb_podf;
  193. reg = __raw_readl(&imx_ccm->cbcdr);
  194. reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
  195. ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
  196. return get_periph_clk() / (ahb_podf + 1);
  197. }
  198. void arch_preboot_os(void)
  199. {
  200. #if defined(CONFIG_CMD_SATA)
  201. sata_stop();
  202. #if defined(CONFIG_MX6)
  203. disable_sata_clock();
  204. #endif
  205. #endif
  206. #if defined(CONFIG_VIDEO_IPUV3)
  207. /* disable video before launching O/S */
  208. ipuv3_fb_shutdown();
  209. #endif
  210. }
  211. void set_chipselect_size(int const cs_size)
  212. {
  213. unsigned int reg;
  214. struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
  215. reg = readl(&iomuxc_regs->gpr[1]);
  216. switch (cs_size) {
  217. case CS0_128:
  218. reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
  219. reg |= 0x5;
  220. break;
  221. case CS0_64M_CS1_64M:
  222. reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
  223. reg |= 0x1B;
  224. break;
  225. case CS0_64M_CS1_32M_CS2_32M:
  226. reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
  227. reg |= 0x4B;
  228. break;
  229. case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
  230. reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
  231. reg |= 0x249;
  232. break;
  233. default:
  234. printf("Unknown chip select size: %d\n", cs_size);
  235. break;
  236. }
  237. writel(reg, &iomuxc_regs->gpr[1]);
  238. }