cpuinfo.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_REVID 0x00f
  26. #define CPU_MASK_PXA_PRODID 0x3f0
  27. #define CPU_VALUE_PXA25X 0x100
  28. #define CPU_VALUE_PXA27X 0x110
  29. static uint32_t pxa_get_cpuid(void)
  30. {
  31. uint32_t cpuid;
  32. asm volatile("mrc p15, 0, %0, c0, c0, 0" : "=r"(cpuid));
  33. return cpuid;
  34. }
  35. int cpu_is_pxa25x(void)
  36. {
  37. uint32_t id = pxa_get_cpuid();
  38. id &= CPU_MASK_PXA_PRODID;
  39. return id == CPU_VALUE_PXA25X;
  40. }
  41. int cpu_is_pxa27x(void)
  42. {
  43. uint32_t id = pxa_get_cpuid();
  44. id &= CPU_MASK_PXA_PRODID;
  45. return id == CPU_VALUE_PXA27X;
  46. }
  47. #ifdef CONFIG_DISPLAY_CPUINFO
  48. static const char *pxa25x_get_revision(void)
  49. {
  50. static __maybe_unused const char * const revs_25x[] = { "A0" };
  51. static __maybe_unused const char * const revs_26x[] = {
  52. "A0", "B0", "B1"
  53. };
  54. static const char *unknown = "Unknown";
  55. uint32_t id;
  56. if (!cpu_is_pxa25x())
  57. return unknown;
  58. id = pxa_get_cpuid() & CPU_MASK_PXA_REVID;
  59. /* PXA26x is a sick special case as it can't be told apart from PXA25x :-( */
  60. #ifdef CONFIG_CPU_PXA26X
  61. switch (id) {
  62. case 3: return revs_26x[0];
  63. case 5: return revs_26x[1];
  64. case 6: return revs_26x[2];
  65. }
  66. #else
  67. if (id == 6)
  68. return revs_25x[0];
  69. #endif
  70. return unknown;
  71. }
  72. static const char *pxa27x_get_revision(void)
  73. {
  74. static const char *const rev[] = { "A0", "A1", "B0", "B1", "C0", "C5" };
  75. static const char *unknown = "Unknown";
  76. uint32_t id;
  77. if (!cpu_is_pxa27x())
  78. return unknown;
  79. id = pxa_get_cpuid() & CPU_MASK_PXA_REVID;
  80. if ((id == 5) || (id == 6) || (id > 7))
  81. return unknown;
  82. /* Cap the special PXA270 C5 case. */
  83. if (id == 7)
  84. id = 5;
  85. return rev[id];
  86. }
  87. static int print_cpuinfo_pxa2xx(void)
  88. {
  89. if (cpu_is_pxa25x()) {
  90. puts("Marvell PXA25x rev. ");
  91. puts(pxa25x_get_revision());
  92. } else if (cpu_is_pxa27x()) {
  93. puts("Marvell PXA27x rev. ");
  94. puts(pxa27x_get_revision());
  95. } else
  96. return -EINVAL;
  97. puts("\n");
  98. return 0;
  99. }
  100. int print_cpuinfo(void)
  101. {
  102. int ret;
  103. puts("CPU: ");
  104. ret = print_cpuinfo_pxa2xx();
  105. if (!ret)
  106. return ret;
  107. return ret;
  108. }
  109. #endif