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