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 | |
Lukasz Dalek | 539e9ff | 2012-10-03 00:51:06 +0200 | [diff] [blame] | 14 | #define CPU_MASK_PXA_PRODID 0x000003f0 |
| 15 | #define CPU_MASK_PXA_REVID 0x0000000f |
Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 16 | |
Lukasz Dalek | 539e9ff | 2012-10-03 00:51:06 +0200 | [diff] [blame] | 17 | #define CPU_MASK_PRODREV (CPU_MASK_PXA_PRODID | CPU_MASK_PXA_REVID) |
| 18 | |
Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 19 | #define CPU_VALUE_PXA25X 0x100 |
| 20 | #define CPU_VALUE_PXA27X 0x110 |
| 21 | |
| 22 | static 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 | |
| 29 | int 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 | |
| 36 | int 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 Dalek | 539e9ff | 2012-10-03 00:51:06 +0200 | [diff] [blame] | 43 | uint32_t pxa_get_cpu_revision(void) |
| 44 | { |
| 45 | return pxa_get_cpuid() & CPU_MASK_PRODREV; |
| 46 | } |
| 47 | |
Marek Vasut | e8de0fa | 2011-11-26 08:11:32 +0100 | [diff] [blame] | 48 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 49 | static 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 | |
| 77 | static 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 | |
| 98 | static 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 | |
| 114 | int 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 |