blob: 9d16079956235d156f0d1c57727487813eb7a924 [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Marek Vasute8de0fa2011-11-26 08:11:32 +01007 */
8
9#include <common.h>
10#include <asm/io.h>
11#include <errno.h>
12#include <linux/compiler.h>
13
Lukasz Dalek539e9ff2012-10-03 00:51:06 +020014#define CPU_MASK_PXA_PRODID 0x000003f0
15#define CPU_MASK_PXA_REVID 0x0000000f
Marek Vasute8de0fa2011-11-26 08:11:32 +010016
Lukasz Dalek539e9ff2012-10-03 00:51:06 +020017#define CPU_MASK_PRODREV (CPU_MASK_PXA_PRODID | CPU_MASK_PXA_REVID)
18
Marek Vasute8de0fa2011-11-26 08:11:32 +010019#define CPU_VALUE_PXA25X 0x100
20#define CPU_VALUE_PXA27X 0x110
21
22static 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
29int cpu_is_pxa25x(void)
30{
31 uint32_t id = pxa_get_cpuid();
32 id &= CPU_MASK_PXA_PRODID;
33 return id == CPU_VALUE_PXA25X;
34}
35
36int cpu_is_pxa27x(void)
37{
38 uint32_t id = pxa_get_cpuid();
39 id &= CPU_MASK_PXA_PRODID;
40 return id == CPU_VALUE_PXA27X;
41}
42
Lukasz Dalek539e9ff2012-10-03 00:51:06 +020043uint32_t pxa_get_cpu_revision(void)
44{
45 return pxa_get_cpuid() & CPU_MASK_PRODREV;
46}
47
Marek Vasute8de0fa2011-11-26 08:11:32 +010048#ifdef CONFIG_DISPLAY_CPUINFO
49static const char *pxa25x_get_revision(void)
50{
51 static __maybe_unused const char * const revs_25x[] = { "A0" };
52 static __maybe_unused const char * const revs_26x[] = {
53 "A0", "B0", "B1"
54 };
55 static const char *unknown = "Unknown";
56 uint32_t id;
57
58 if (!cpu_is_pxa25x())
59 return unknown;
60
61 id = pxa_get_cpuid() & CPU_MASK_PXA_REVID;
62
63/* PXA26x is a sick special case as it can't be told apart from PXA25x :-( */
64#ifdef CONFIG_CPU_PXA26X
65 switch (id) {
66 case 3: return revs_26x[0];
67 case 5: return revs_26x[1];
68 case 6: return revs_26x[2];
69 }
70#else
71 if (id == 6)
72 return revs_25x[0];
73#endif
74 return unknown;
75}
76
77static 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
83 if (!cpu_is_pxa27x())
84 return unknown;
85
86 id = pxa_get_cpuid() & CPU_MASK_PXA_REVID;
87
88 if ((id == 5) || (id == 6) || (id > 7))
89 return unknown;
90
91 /* Cap the special PXA270 C5 case. */
92 if (id == 7)
93 id = 5;
94
95 return rev[id];
96}
97
98static int print_cpuinfo_pxa2xx(void)
99{
100 if (cpu_is_pxa25x()) {
101 puts("Marvell PXA25x rev. ");
102 puts(pxa25x_get_revision());
103 } else if (cpu_is_pxa27x()) {
104 puts("Marvell PXA27x rev. ");
105 puts(pxa27x_get_revision());
106 } else
107 return -EINVAL;
108
109 puts("\n");
110
111 return 0;
112}
113
114int print_cpuinfo(void)
115{
116 int ret;
117
118 puts("CPU: ");
119
120 ret = print_cpuinfo_pxa2xx();
121 if (!ret)
122 return ret;
123
124 return ret;
125}
126#endif