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