cpuinfo.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * PXA CPU information display
  3. *
  4. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.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. uint32_t pxa_get_cpu_revision(void)
  41. {
  42. return pxa_get_cpuid() & CPU_MASK_PRODREV;
  43. }
  44. #ifdef CONFIG_DISPLAY_CPUINFO
  45. static const char *pxa25x_get_revision(void)
  46. {
  47. static __maybe_unused const char * const revs_25x[] = { "A0" };
  48. static __maybe_unused const char * const revs_26x[] = {
  49. "A0", "B0", "B1"
  50. };
  51. static const char *unknown = "Unknown";
  52. uint32_t id;
  53. if (!cpu_is_pxa25x())
  54. return unknown;
  55. id = pxa_get_cpuid() & CPU_MASK_PXA_REVID;
  56. /* PXA26x is a sick special case as it can't be told apart from PXA25x :-( */
  57. #ifdef CONFIG_CPU_PXA26X
  58. switch (id) {
  59. case 3: return revs_26x[0];
  60. case 5: return revs_26x[1];
  61. case 6: return revs_26x[2];
  62. }
  63. #else
  64. if (id == 6)
  65. return revs_25x[0];
  66. #endif
  67. return unknown;
  68. }
  69. static const char *pxa27x_get_revision(void)
  70. {
  71. static const char *const rev[] = { "A0", "A1", "B0", "B1", "C0", "C5" };
  72. static const char *unknown = "Unknown";
  73. uint32_t id;
  74. if (!cpu_is_pxa27x())
  75. return unknown;
  76. id = pxa_get_cpuid() & CPU_MASK_PXA_REVID;
  77. if ((id == 5) || (id == 6) || (id > 7))
  78. return unknown;
  79. /* Cap the special PXA270 C5 case. */
  80. if (id == 7)
  81. id = 5;
  82. return rev[id];
  83. }
  84. static int print_cpuinfo_pxa2xx(void)
  85. {
  86. if (cpu_is_pxa25x()) {
  87. puts("Marvell PXA25x rev. ");
  88. puts(pxa25x_get_revision());
  89. } else if (cpu_is_pxa27x()) {
  90. puts("Marvell PXA27x rev. ");
  91. puts(pxa27x_get_revision());
  92. } else
  93. return -EINVAL;
  94. puts("\n");
  95. return 0;
  96. }
  97. int print_cpuinfo(void)
  98. {
  99. int ret;
  100. puts("CPU: ");
  101. ret = print_cpuinfo_pxa2xx();
  102. if (!ret)
  103. return ret;
  104. return ret;
  105. }
  106. #endif