cpuinfo.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * PXA CPU information display
  4. *
  5. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  6. */
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <errno.h>
  10. #include <linux/compiler.h>
  11. #ifdef CONFIG_CPU_PXA25X
  12. #if ((CONFIG_SYS_INIT_SP_ADDR) != 0xfffff800)
  13. #error "Init SP address must be set to 0xfffff800 for PXA250"
  14. #endif
  15. #endif
  16. #define CPU_MASK_PXA_PRODID 0x000003f0
  17. #define CPU_MASK_PXA_REVID 0x0000000f
  18. #define CPU_MASK_PRODREV (CPU_MASK_PXA_PRODID | CPU_MASK_PXA_REVID)
  19. #define CPU_VALUE_PXA25X 0x100
  20. #define CPU_VALUE_PXA27X 0x110
  21. static uint32_t pxa_get_cpuid(void)
  22. {
  23. uint32_t cpuid;
  24. asm volatile("mrc p15, 0, %0, c0, c0, 0" : "=r"(cpuid));
  25. return cpuid;
  26. }
  27. int cpu_is_pxa25x(void)
  28. {
  29. uint32_t id = pxa_get_cpuid();
  30. id &= CPU_MASK_PXA_PRODID;
  31. return id == CPU_VALUE_PXA25X;
  32. }
  33. int cpu_is_pxa27x(void)
  34. {
  35. uint32_t id = pxa_get_cpuid();
  36. id &= CPU_MASK_PXA_PRODID;
  37. return id == CPU_VALUE_PXA27X;
  38. }
  39. int cpu_is_pxa27xm(void)
  40. {
  41. uint32_t id = pxa_get_cpuid();
  42. return ((id & CPU_MASK_PXA_PRODID) == CPU_VALUE_PXA27X) &&
  43. ((id & CPU_MASK_PXA_REVID) == 8);
  44. }
  45. uint32_t pxa_get_cpu_revision(void)
  46. {
  47. return pxa_get_cpuid() & CPU_MASK_PRODREV;
  48. }
  49. #ifdef CONFIG_DISPLAY_CPUINFO
  50. static const char *pxa25x_get_revision(void)
  51. {
  52. static __maybe_unused const char * const revs_25x[] = { "A0" };
  53. static __maybe_unused const char * const revs_26x[] = {
  54. "A0", "B0", "B1"
  55. };
  56. static const char *unknown = "Unknown";
  57. uint32_t id;
  58. if (!cpu_is_pxa25x())
  59. return unknown;
  60. id = pxa_get_cpuid() & CPU_MASK_PXA_REVID;
  61. /* PXA26x is a sick special case as it can't be told apart from PXA25x :-( */
  62. #ifdef CONFIG_CPU_PXA26X
  63. switch (id) {
  64. case 3: return revs_26x[0];
  65. case 5: return revs_26x[1];
  66. case 6: return revs_26x[2];
  67. }
  68. #else
  69. if (id == 6)
  70. return revs_25x[0];
  71. #endif
  72. return unknown;
  73. }
  74. static const char *pxa27x_get_revision(void)
  75. {
  76. static const char *const rev[] = { "A0", "A1", "B0", "B1", "C0", "C5" };
  77. static const char *unknown = "Unknown";
  78. uint32_t id;
  79. if (!cpu_is_pxa27x())
  80. return unknown;
  81. id = pxa_get_cpuid() & CPU_MASK_PXA_REVID;
  82. if ((id == 5) || (id == 6) || (id > 8))
  83. return unknown;
  84. /* Cap the special PXA270 C5 case. */
  85. if (id == 7)
  86. id = 5;
  87. /* Cap the special PXA270M A1 case. */
  88. if (id == 8)
  89. id = 1;
  90. return rev[id];
  91. }
  92. static int print_cpuinfo_pxa2xx(void)
  93. {
  94. if (cpu_is_pxa25x()) {
  95. puts("Marvell PXA25x rev. ");
  96. puts(pxa25x_get_revision());
  97. } else if (cpu_is_pxa27x()) {
  98. puts("Marvell PXA27x");
  99. if (cpu_is_pxa27xm()) puts("M");
  100. puts(" rev. ");
  101. puts(pxa27x_get_revision());
  102. } else
  103. return -EINVAL;
  104. puts("\n");
  105. return 0;
  106. }
  107. int print_cpuinfo(void)
  108. {
  109. int ret;
  110. puts("CPU: ");
  111. ret = print_cpuinfo_pxa2xx();
  112. if (!ret)
  113. return ret;
  114. return ret;
  115. }
  116. #endif