cpu.c 5.6 KB

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