cpuinfo.c 2.7 KB

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