cpuinfo.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * PXA CPU information display
  3. *
  4. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. */
  21. #include <common.h>
  22. #include <asm/io.h>
  23. #include <errno.h>
  24. #include <linux/compiler.h>
  25. #define CPU_MASK_PXA_PRODID 0x000003f0
  26. #define CPU_MASK_PXA_REVID 0x0000000f
  27. #define CPU_MASK_PRODREV (CPU_MASK_PXA_PRODID | CPU_MASK_PXA_REVID)
  28. #define CPU_VALUE_PXA25X 0x100
  29. #define CPU_VALUE_PXA27X 0x110
  30. static uint32_t pxa_get_cpuid(void)
  31. {
  32. uint32_t cpuid;
  33. asm volatile("mrc p15, 0, %0, c0, c0, 0" : "=r"(cpuid));
  34. return cpuid;
  35. }
  36. int cpu_is_pxa25x(void)
  37. {
  38. uint32_t id = pxa_get_cpuid();
  39. id &= CPU_MASK_PXA_PRODID;
  40. return id == CPU_VALUE_PXA25X;
  41. }
  42. int cpu_is_pxa27x(void)
  43. {
  44. uint32_t id = pxa_get_cpuid();
  45. id &= CPU_MASK_PXA_PRODID;
  46. return id == CPU_VALUE_PXA27X;
  47. }
  48. uint32_t pxa_get_cpu_revision(void)
  49. {
  50. return pxa_get_cpuid() & CPU_MASK_PRODREV;
  51. }
  52. #ifdef CONFIG_DISPLAY_CPUINFO
  53. static const char *pxa25x_get_revision(void)
  54. {
  55. static __maybe_unused const char * const revs_25x[] = { "A0" };
  56. static __maybe_unused const char * const revs_26x[] = {
  57. "A0", "B0", "B1"
  58. };
  59. static const char *unknown = "Unknown";
  60. uint32_t id;
  61. if (!cpu_is_pxa25x())
  62. return unknown;
  63. id = pxa_get_cpuid() & CPU_MASK_PXA_REVID;
  64. /* PXA26x is a sick special case as it can't be told apart from PXA25x :-( */
  65. #ifdef CONFIG_CPU_PXA26X
  66. switch (id) {
  67. case 3: return revs_26x[0];
  68. case 5: return revs_26x[1];
  69. case 6: return revs_26x[2];
  70. }
  71. #else
  72. if (id == 6)
  73. return revs_25x[0];
  74. #endif
  75. return unknown;
  76. }
  77. static const char *pxa27x_get_revision(void)
  78. {
  79. static const char *const rev[] = { "A0", "A1", "B0", "B1", "C0", "C5" };
  80. static const char *unknown = "Unknown";
  81. uint32_t id;
  82. if (!cpu_is_pxa27x())
  83. return unknown;
  84. id = pxa_get_cpuid() & CPU_MASK_PXA_REVID;
  85. if ((id == 5) || (id == 6) || (id > 7))
  86. return unknown;
  87. /* Cap the special PXA270 C5 case. */
  88. if (id == 7)
  89. id = 5;
  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 rev. ");
  99. puts(pxa27x_get_revision());
  100. } else
  101. return -EINVAL;
  102. puts("\n");
  103. return 0;
  104. }
  105. int print_cpuinfo(void)
  106. {
  107. int ret;
  108. puts("CPU: ");
  109. ret = print_cpuinfo_pxa2xx();
  110. if (!ret)
  111. return ret;
  112. return ret;
  113. }
  114. #endif