sys_info.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * sys_info.c
  4. *
  5. * System information functions
  6. *
  7. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  8. *
  9. * Derived from Beagle Board and 3430 SDP code by
  10. * Richard Woodruff <r-woodruff2@ti.com>
  11. * Syed Mohammed Khasim <khasim@ti.com>
  12. */
  13. #include <common.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/sys_proto.h>
  16. #include <asm/arch/cpu.h>
  17. #include <asm/arch/clock.h>
  18. #include <power/tps65910.h>
  19. #include <linux/compiler.h>
  20. struct ctrl_stat *cstat = (struct ctrl_stat *)CTRL_BASE;
  21. /**
  22. * get_cpu_rev(void) - extract rev info
  23. */
  24. u32 get_cpu_rev(void)
  25. {
  26. u32 id;
  27. u32 rev;
  28. id = readl(DEVICE_ID);
  29. rev = (id >> 28) & 0xff;
  30. return rev;
  31. }
  32. /**
  33. * get_cpu_type(void) - extract cpu info
  34. */
  35. u32 get_cpu_type(void)
  36. {
  37. u32 id = 0;
  38. u32 partnum;
  39. id = readl(DEVICE_ID);
  40. partnum = (id >> 12) & 0xffff;
  41. return partnum;
  42. }
  43. /**
  44. * get_sysboot_value(void) - return SYS_BOOT[4:0]
  45. */
  46. u32 get_sysboot_value(void)
  47. {
  48. return readl(&cstat->statusreg) & SYSBOOT_MASK;
  49. }
  50. u32 get_sys_clk_index(void)
  51. {
  52. struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE;
  53. u32 ind = readl(&ctrl->statusreg);
  54. #ifdef CONFIG_AM43XX
  55. u32 src;
  56. src = (ind & CTRL_CRYSTAL_FREQ_SRC_MASK) >> CTRL_CRYSTAL_FREQ_SRC_SHIFT;
  57. if (src == CTRL_CRYSTAL_FREQ_SRC_EFUSE) /* Value read from EFUSE */
  58. return ((ind & CTRL_CRYSTAL_FREQ_SELECTION_MASK) >>
  59. CTRL_CRYSTAL_FREQ_SELECTION_SHIFT);
  60. else /* Value read from SYS BOOT pins */
  61. #endif
  62. return ((ind & CTRL_SYSBOOT_15_14_MASK) >>
  63. CTRL_SYSBOOT_15_14_SHIFT);
  64. }
  65. #ifdef CONFIG_DISPLAY_CPUINFO
  66. static char *cpu_revs[] = {
  67. "1.0",
  68. "2.0",
  69. "2.1"};
  70. static char *cpu_revs_am43xx[] = {
  71. "1.0",
  72. "1.1",
  73. "1.2"};
  74. static char *dev_types[] = {
  75. "TST",
  76. "EMU",
  77. "HS",
  78. "GP"};
  79. /**
  80. * Print CPU information
  81. */
  82. int print_cpuinfo(void)
  83. {
  84. char *cpu_s, *sec_s, *rev_s;
  85. char **cpu_rev_arr = cpu_revs;
  86. switch (get_cpu_type()) {
  87. case AM335X:
  88. cpu_s = "AM335X";
  89. break;
  90. case TI81XX:
  91. cpu_s = "TI81XX";
  92. break;
  93. case AM437X:
  94. cpu_s = "AM437X";
  95. cpu_rev_arr = cpu_revs_am43xx;
  96. break;
  97. default:
  98. cpu_s = "Unknown CPU type";
  99. break;
  100. }
  101. if (get_cpu_rev() < ARRAY_SIZE(cpu_revs))
  102. rev_s = cpu_rev_arr[get_cpu_rev()];
  103. else
  104. rev_s = "?";
  105. if (get_device_type() < ARRAY_SIZE(dev_types))
  106. sec_s = dev_types[get_device_type()];
  107. else
  108. sec_s = "?";
  109. printf("CPU : %s-%s rev %s\n", cpu_s, sec_s, rev_s);
  110. return 0;
  111. }
  112. #endif /* CONFIG_DISPLAY_CPUINFO */
  113. #ifdef CONFIG_AM33XX
  114. int am335x_get_efuse_mpu_max_freq(struct ctrl_dev *cdev)
  115. {
  116. int sil_rev;
  117. sil_rev = readl(&cdev->deviceid) >> 28;
  118. if (sil_rev == 0) {
  119. /* No efuse in PG 1.0. Use max speed */
  120. return MPUPLL_M_720;
  121. } else if (sil_rev >= 1) {
  122. /* Check what the efuse says our max speed is. */
  123. int efuse_arm_mpu_max_freq, package_type;
  124. efuse_arm_mpu_max_freq = readl(&cdev->efuse_sma);
  125. package_type = (efuse_arm_mpu_max_freq & PACKAGE_TYPE_MASK) >>
  126. PACKAGE_TYPE_SHIFT;
  127. /* PG 2.0, efuse may not be set. */
  128. if (package_type == PACKAGE_TYPE_UNDEFINED || package_type ==
  129. PACKAGE_TYPE_RESERVED)
  130. return MPUPLL_M_800;
  131. switch ((efuse_arm_mpu_max_freq & DEVICE_ID_MASK)) {
  132. case AM335X_ZCZ_1000:
  133. return MPUPLL_M_1000;
  134. case AM335X_ZCZ_800:
  135. return MPUPLL_M_800;
  136. case AM335X_ZCZ_720:
  137. return MPUPLL_M_720;
  138. case AM335X_ZCZ_600:
  139. case AM335X_ZCE_600:
  140. return MPUPLL_M_600;
  141. case AM335X_ZCZ_300:
  142. case AM335X_ZCE_300:
  143. return MPUPLL_M_300;
  144. }
  145. }
  146. /* unknown, use the PG1.0 max */
  147. return MPUPLL_M_720;
  148. }
  149. int am335x_get_mpu_vdd(int sil_rev, int frequency)
  150. {
  151. int sel_mask = am335x_get_tps65910_mpu_vdd(sil_rev, frequency);
  152. switch (sel_mask) {
  153. case TPS65910_OP_REG_SEL_1_3_2_5:
  154. return 1325000;
  155. case TPS65910_OP_REG_SEL_1_2_0:
  156. return 1200000;
  157. case TPS65910_OP_REG_SEL_1_1_0:
  158. return 1100000;
  159. default:
  160. return 1262500;
  161. }
  162. }
  163. int am335x_get_tps65910_mpu_vdd(int sil_rev, int frequency)
  164. {
  165. /* For PG2.0 and later, we have one set of values. */
  166. if (sil_rev >= 1) {
  167. switch (frequency) {
  168. case MPUPLL_M_1000:
  169. return TPS65910_OP_REG_SEL_1_3_2_5;
  170. case MPUPLL_M_800:
  171. return TPS65910_OP_REG_SEL_1_2_6;
  172. case MPUPLL_M_720:
  173. return TPS65910_OP_REG_SEL_1_2_0;
  174. case MPUPLL_M_600:
  175. case MPUPLL_M_500:
  176. case MPUPLL_M_300:
  177. return TPS65910_OP_REG_SEL_1_1_0;
  178. }
  179. }
  180. /* Default to PG1.0 values. */
  181. return TPS65910_OP_REG_SEL_1_2_6;
  182. }
  183. #endif