cpu.c 5.5 KB

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