OMAP3: Move get_sysboot_value() function to not duplicate code
[pandora-x-loader.git] / cpu / omap3 / sys_info.c
1 /*
2  * See file CREDITS for list of people who contributed to this
3  * project.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA
19  */
20
21 #include <common.h>
22 #include <asm/io.h>
23 #include <asm/arch/bits.h>
24 #include <asm/arch/sys_proto.h>
25 #include <asm/arch/sys_info.h>
26
27 static char *rev_s[CPU_3XX_MAX_REV] = {
28                                 "1.0",
29                                 "2.0",
30                                 "2.1",
31                                 "3.0",
32                                 "3.1",
33                                 "UNKNOWN",
34                                 "UNKNOWN",
35                                 "3.1.2"};
36
37 /*
38  *  get_device_type(): tell if GP/HS/EMU/TST
39  */
40 u32 get_device_type(void)
41 {
42         int mode;
43         mode = __raw_readl(CONTROL_STATUS) & (DEVICE_MASK);
44         return mode >>= 8;
45 }
46
47 /*
48  *  get_cpu_type(): extract cpu info
49  */
50 u32 get_cpu_type(void)
51 {
52         return __raw_readl(CONTROL_OMAP_STATUS);
53 }
54
55 /*
56  * get_cpu_id(): extract cpu id
57  * returns 0 for ES1.0, cpuid otherwise
58  */
59 u32 get_cpu_id(void)
60 {
61         u32 cpuid = 0;
62
63         /*
64          * On ES1.0 the IDCODE register is not exposed on L4
65          * so using CPU ID to differentiate between ES1.0 and > ES1.0.
66          */
67         __asm__ __volatile__("mrc p15, 0, %0, c0, c0, 0":"=r"(cpuid));
68         if ((cpuid & 0xf) == 0x0) {
69                 return 0;
70         } else {
71                 /* Decode the IDs on > ES1.0 */
72                 cpuid = __raw_readl(CONTROL_IDCODE);
73         }
74
75         return cpuid;
76 }
77
78 /*
79  * get_cpu_family(void): extract cpu info
80  */
81 u32 get_cpu_family(void)
82 {
83         u16 hawkeye;
84         u32 cpu_family;
85         u32 cpuid = get_cpu_id();
86
87         if (cpuid == 0)
88                 return CPU_OMAP34XX;
89
90         hawkeye = (cpuid >> HAWKEYE_SHIFT) & 0xffff;
91         switch (hawkeye) {
92         case HAWKEYE_OMAP34XX:
93                 cpu_family = CPU_OMAP34XX;
94                 break;
95         case HAWKEYE_AM35XX:
96                 cpu_family = CPU_AM35XX;
97                 break;
98         case HAWKEYE_OMAP36XX:
99                 cpu_family = CPU_OMAP36XX;
100                 break;
101         default:
102                 cpu_family = CPU_OMAP34XX;
103         }
104
105         return cpu_family;
106 }
107
108 /*
109  * get_cpu_rev(void): extract version info
110  */
111 u32 get_cpu_rev(void)
112 {
113         u32 cpuid = get_cpu_id();
114
115         if (cpuid == 0)
116                 return CPU_3XX_ES10;
117         else
118                 return (cpuid >> CPU_3XX_ID_SHIFT) & 0xf;
119 }
120
121 /*
122  * print_cpuinfo(void): print CPU information
123  */
124 int print_cpuinfo(void)
125 {
126         char *cpu_family_s, *cpu_s, *sec_s;
127
128         switch (get_cpu_family()) {
129         case CPU_OMAP34XX:
130                 cpu_family_s = "OMAP";
131                 switch (get_cpu_type()) {
132                 case OMAP3503:
133                         cpu_s = "3503";
134                         break;
135                 case OMAP3515:
136                         cpu_s = "3515";
137                         break;
138                 case OMAP3525:
139                         cpu_s = "3525";
140                         break;
141                 case OMAP3530:
142                         cpu_s = "3530";
143                         break;
144                 default:
145                         cpu_s = "35XX";
146                         break;
147                 }
148                 break;
149         case CPU_AM35XX:
150                 cpu_family_s = "AM";
151                 switch (get_cpu_type()) {
152                 case AM3505:
153                         cpu_s = "3505";
154                         break;
155                 case AM3517:
156                         cpu_s = "3517";
157                         break;
158                 default:
159                         cpu_s = "35XX";
160                         break;
161                 }
162                 break;
163         case CPU_OMAP36XX:
164                 cpu_family_s = "OMAP";
165                 switch (get_cpu_type()) {
166                 case OMAP3730:
167                         cpu_s = "3630/3730";
168                         break;
169                 default:
170                         cpu_s = "36XX/37XX";
171                         break;
172                 }
173                 break;
174         default:
175                 cpu_family_s = "OMAP";
176                 cpu_s = "35XX";
177         }
178
179         switch (get_device_type()) {
180         case TST_DEVICE:
181                 sec_s = "TST";
182                 break;
183         case EMU_DEVICE:
184                 sec_s = "EMU";
185                 break;
186         case HS_DEVICE:
187                 sec_s = "HS";
188                 break;
189         case GP_DEVICE:
190                 sec_s = "GP";
191                 break;
192         default:
193                 sec_s = "?";
194         }
195
196         printf("%s%s-%s ES%s\n",
197                         cpu_family_s, cpu_s, sec_s, rev_s[get_cpu_rev()]);
198
199         return 0;
200 }
201
202 /*
203  * get_sysboot_value(void): return SYS_BOOT[4:0]
204  */
205 u32 get_sysboot_value(void)
206 {
207         int mode;
208         mode = __raw_readl(CONTROL_STATUS) & (SYSBOOT_MASK);
209         return mode;
210 }