cpu_info.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2007-2011
  4. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  5. * Tom Cubie <tangliang@allwinnertech.com>
  6. */
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/cpu.h>
  10. #include <asm/arch/clock.h>
  11. #include <axp_pmic.h>
  12. #include <errno.h>
  13. #ifdef CONFIG_MACH_SUN6I
  14. int sunxi_get_ss_bonding_id(void)
  15. {
  16. struct sunxi_ccm_reg * const ccm =
  17. (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
  18. static int bonding_id = -1;
  19. if (bonding_id != -1)
  20. return bonding_id;
  21. /* Enable Security System */
  22. setbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_SS);
  23. setbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_SS);
  24. bonding_id = readl(SUNXI_SS_BASE);
  25. bonding_id = (bonding_id >> 16) & 0x7;
  26. /* Disable Security System again */
  27. clrbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_SS);
  28. clrbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_SS);
  29. return bonding_id;
  30. }
  31. #endif
  32. #ifdef CONFIG_MACH_SUN8I
  33. uint sunxi_get_sram_id(void)
  34. {
  35. uint id;
  36. /* Unlock sram info reg, read it, relock */
  37. setbits_le32(SUNXI_SRAMC_BASE + 0x24, (1 << 15));
  38. id = readl(SUNXI_SRAMC_BASE + 0x24) >> 16;
  39. clrbits_le32(SUNXI_SRAMC_BASE + 0x24, (1 << 15));
  40. return id;
  41. }
  42. #endif
  43. #ifdef CONFIG_DISPLAY_CPUINFO
  44. int print_cpuinfo(void)
  45. {
  46. #ifdef CONFIG_MACH_SUN4I
  47. puts("CPU: Allwinner A10 (SUN4I)\n");
  48. #elif defined CONFIG_MACH_SUN5I
  49. u32 val = readl(SUNXI_SID_BASE + 0x08);
  50. switch ((val >> 12) & 0xf) {
  51. case 0: puts("CPU: Allwinner A12 (SUN5I)\n"); break;
  52. case 3: puts("CPU: Allwinner A13 (SUN5I)\n"); break;
  53. case 7: puts("CPU: Allwinner A10s (SUN5I)\n"); break;
  54. default: puts("CPU: Allwinner A1X (SUN5I)\n");
  55. }
  56. #elif defined CONFIG_MACH_SUN6I
  57. switch (sunxi_get_ss_bonding_id()) {
  58. case SUNXI_SS_BOND_ID_A31:
  59. puts("CPU: Allwinner A31 (SUN6I)\n");
  60. break;
  61. case SUNXI_SS_BOND_ID_A31S:
  62. puts("CPU: Allwinner A31s (SUN6I)\n");
  63. break;
  64. default:
  65. printf("CPU: Allwinner A31? (SUN6I, id: %d)\n",
  66. sunxi_get_ss_bonding_id());
  67. }
  68. #elif defined CONFIG_MACH_SUN7I
  69. puts("CPU: Allwinner A20 (SUN7I)\n");
  70. #elif defined CONFIG_MACH_SUN8I_A23
  71. printf("CPU: Allwinner A23 (SUN8I %04x)\n", sunxi_get_sram_id());
  72. #elif defined CONFIG_MACH_SUN8I_A33
  73. printf("CPU: Allwinner A33 (SUN8I %04x)\n", sunxi_get_sram_id());
  74. #elif defined CONFIG_MACH_SUN8I_A83T
  75. printf("CPU: Allwinner A83T (SUN8I %04x)\n", sunxi_get_sram_id());
  76. #elif defined CONFIG_MACH_SUN8I_H3
  77. printf("CPU: Allwinner H3 (SUN8I %04x)\n", sunxi_get_sram_id());
  78. #elif defined CONFIG_MACH_SUN8I_R40
  79. printf("CPU: Allwinner R40 (SUN8I %04x)\n", sunxi_get_sram_id());
  80. #elif defined CONFIG_MACH_SUN8I_V3S
  81. printf("CPU: Allwinner V3s (SUN8I %04x)\n", sunxi_get_sram_id());
  82. #elif defined CONFIG_MACH_SUN9I
  83. puts("CPU: Allwinner A80 (SUN9I)\n");
  84. #elif defined CONFIG_MACH_SUN50I
  85. puts("CPU: Allwinner A64 (SUN50I)\n");
  86. #elif defined CONFIG_MACH_SUN50I_H5
  87. puts("CPU: Allwinner H5 (SUN50I)\n");
  88. #elif defined CONFIG_MACH_SUN50I_H6
  89. puts("CPU: Allwinner H6 (SUN50I)\n");
  90. #else
  91. #warning Please update cpu_info.c with correct CPU information
  92. puts("CPU: SUNXI Family\n");
  93. #endif
  94. return 0;
  95. }
  96. #endif
  97. #ifdef CONFIG_MACH_SUN8I_H3
  98. #define SIDC_PRCTL 0x40
  99. #define SIDC_RDKEY 0x60
  100. #define SIDC_OP_LOCK 0xAC
  101. uint32_t sun8i_efuse_read(uint32_t offset)
  102. {
  103. uint32_t reg_val;
  104. reg_val = readl(SUNXI_SIDC_BASE + SIDC_PRCTL);
  105. reg_val &= ~(((0x1ff) << 16) | 0x3);
  106. reg_val |= (offset << 16);
  107. writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL);
  108. reg_val &= ~(((0xff) << 8) | 0x3);
  109. reg_val |= (SIDC_OP_LOCK << 8) | 0x2;
  110. writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL);
  111. while (readl(SUNXI_SIDC_BASE + SIDC_PRCTL) & 0x2);
  112. reg_val &= ~(((0x1ff) << 16) | ((0xff) << 8) | 0x3);
  113. writel(reg_val, SUNXI_SIDC_BASE + SIDC_PRCTL);
  114. reg_val = readl(SUNXI_SIDC_BASE + SIDC_RDKEY);
  115. return reg_val;
  116. }
  117. #endif
  118. int sunxi_get_sid(unsigned int *sid)
  119. {
  120. #ifdef CONFIG_AXP221_POWER
  121. return axp_get_sid(sid);
  122. #elif defined CONFIG_MACH_SUN8I_H3
  123. /*
  124. * H3 SID controller has a bug, which makes the initial value of
  125. * SUNXI_SID_BASE at boot wrong.
  126. * Read the value directly from SID controller, in order to get
  127. * the correct value, and also refresh the wrong value at
  128. * SUNXI_SID_BASE.
  129. */
  130. int i;
  131. for (i = 0; i< 4; i++)
  132. sid[i] = sun8i_efuse_read(i * 4);
  133. return 0;
  134. #elif defined SUNXI_SID_BASE
  135. int i;
  136. for (i = 0; i< 4; i++)
  137. sid[i] = readl((ulong)SUNXI_SID_BASE + 4 * i);
  138. return 0;
  139. #else
  140. return -ENODEV;
  141. #endif
  142. }