Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PXA CPU information display |
| 3 | * |
| 4 | * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com> |
| 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <errno.h> |
| 12 | #include <linux/compiler.h> |
| 13 | |
Albert ARIBAUD | 23ff29b | 2014-04-15 16:13:49 +0200 | [diff] [blame] | 14 | #ifdef CONFIG_CPU_PXA25X |
| 15 | #if ((CONFIG_SYS_INIT_SP_ADDR) != 0xfffff800) |
| 16 | #error "Init SP address must be set to 0xfffff800 for PXA250" |
| 17 | #endif |
| 18 | #endif |
| 19 | |
Lukasz Dalek | 539e9ff | 2012-10-03 00:51:06 +0200 | [diff] [blame] | 20 | #define CPU_MASK_PXA_PRODID 0x000003f0 |
| 21 | #define CPU_MASK_PXA_REVID 0x0000000f |
Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 22 | |
Lukasz Dalek | 539e9ff | 2012-10-03 00:51:06 +0200 | [diff] [blame] | 23 | #define CPU_MASK_PRODREV (CPU_MASK_PXA_PRODID | CPU_MASK_PXA_REVID) |
| 24 | |
Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 25 | #define CPU_VALUE_PXA25X 0x100 |
| 26 | #define CPU_VALUE_PXA27X 0x110 |
| 27 | |
| 28 | static uint32_t pxa_get_cpuid(void) |
| 29 | { |
| 30 | uint32_t cpuid; |
| 31 | asm volatile("mrc p15, 0, %0, c0, c0, 0" : "=r"(cpuid)); |
| 32 | return cpuid; |
| 33 | } |
| 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 | |
| 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 | |
Marcel Ziswiler | 901f79e | 2015-03-04 14:57:31 +0100 | [diff] [blame] | 49 | int cpu_is_pxa27xm(void) |
| 50 | { |
| 51 | uint32_t id = pxa_get_cpuid(); |
| 52 | return ((id & CPU_MASK_PXA_PRODID) == CPU_VALUE_PXA27X) && |
| 53 | ((id & CPU_MASK_PXA_REVID) == 8); |
| 54 | } |
| 55 | |
Lukasz Dalek | 539e9ff | 2012-10-03 00:51:06 +0200 | [diff] [blame] | 56 | uint32_t pxa_get_cpu_revision(void) |
| 57 | { |
| 58 | return pxa_get_cpuid() & CPU_MASK_PRODREV; |
| 59 | } |
| 60 | |
Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 61 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 62 | static 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 | |
| 90 | static 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 | |
Marcel Ziswiler | 901f79e | 2015-03-04 14:57:31 +0100 | [diff] [blame] | 101 | if ((id == 5) || (id == 6) || (id > 8)) |
Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 102 | return unknown; |
| 103 | |
| 104 | /* Cap the special PXA270 C5 case. */ |
| 105 | if (id == 7) |
| 106 | id = 5; |
| 107 | |
Marcel Ziswiler | 901f79e | 2015-03-04 14:57:31 +0100 | [diff] [blame] | 108 | /* Cap the special PXA270M A1 case. */ |
| 109 | if (id == 8) |
| 110 | id = 1; |
| 111 | |
Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 112 | return rev[id]; |
| 113 | } |
| 114 | |
| 115 | static int print_cpuinfo_pxa2xx(void) |
| 116 | { |
| 117 | if (cpu_is_pxa25x()) { |
| 118 | puts("Marvell PXA25x rev. "); |
| 119 | puts(pxa25x_get_revision()); |
| 120 | } else if (cpu_is_pxa27x()) { |
Marcel Ziswiler | 901f79e | 2015-03-04 14:57:31 +0100 | [diff] [blame] | 121 | puts("Marvell PXA27x"); |
| 122 | if (cpu_is_pxa27xm()) puts("M"); |
| 123 | puts(" rev. "); |
Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 124 | puts(pxa27x_get_revision()); |
| 125 | } else |
| 126 | return -EINVAL; |
| 127 | |
| 128 | puts("\n"); |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | int print_cpuinfo(void) |
| 134 | { |
| 135 | int ret; |
| 136 | |
| 137 | puts("CPU: "); |
| 138 | |
| 139 | ret = print_cpuinfo_pxa2xx(); |
| 140 | if (!ret) |
| 141 | return ret; |
| 142 | |
| 143 | return ret; |
| 144 | } |
| 145 | #endif |