OMAP3: Move sr32() function to not duplicate code
[x-loader-sniper.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  * sr32: clear & set a value in a bit range for a 32 bit address
39  */
40 void sr32(u32 addr, u32 start_bit, u32 num_bits, u32 value)
41 {
42         u32 tmp, msk = 0;
43         msk = 1 << num_bits;
44         --msk;
45         tmp = __raw_readl(addr) & ~(msk << start_bit);
46         tmp |= value << start_bit;
47         __raw_writel(tmp, addr);
48 }
49
50 /*
51  *  get_device_type(): tell if GP/HS/EMU/TST
52  */
53 u32 get_device_type(void)
54 {
55         int mode;
56         mode = __raw_readl(CONTROL_STATUS) & (DEVICE_MASK);
57         return mode >>= 8;
58 }
59
60 /*
61  *  get_cpu_type(): extract cpu info
62  */
63 u32 get_cpu_type(void)
64 {
65         return __raw_readl(CONTROL_OMAP_STATUS);
66 }
67
68 /*
69  * get_cpu_id(): extract cpu id
70  * returns 0 for ES1.0, cpuid otherwise
71  */
72 u32 get_cpu_id(void)
73 {
74         u32 cpuid = 0;
75
76         /*
77          * On ES1.0 the IDCODE register is not exposed on L4
78          * so using CPU ID to differentiate between ES1.0 and > ES1.0.
79          */
80         __asm__ __volatile__("mrc p15, 0, %0, c0, c0, 0":"=r"(cpuid));
81         if ((cpuid & 0xf) == 0x0) {
82                 return 0;
83         } else {
84                 /* Decode the IDs on > ES1.0 */
85                 cpuid = __raw_readl(CONTROL_IDCODE);
86         }
87
88         return cpuid;
89 }
90
91 /*
92  * get_cpu_family(void): extract cpu info
93  */
94 u32 get_cpu_family(void)
95 {
96         u16 hawkeye;
97         u32 cpu_family;
98         u32 cpuid = get_cpu_id();
99
100         if (cpuid == 0)
101                 return CPU_OMAP34XX;
102
103         hawkeye = (cpuid >> HAWKEYE_SHIFT) & 0xffff;
104         switch (hawkeye) {
105         case HAWKEYE_OMAP34XX:
106                 cpu_family = CPU_OMAP34XX;
107                 break;
108         case HAWKEYE_AM35XX:
109                 cpu_family = CPU_AM35XX;
110                 break;
111         case HAWKEYE_OMAP36XX:
112                 cpu_family = CPU_OMAP36XX;
113                 break;
114         default:
115                 cpu_family = CPU_OMAP34XX;
116         }
117
118         return cpu_family;
119 }
120
121 /*
122  * get_cpu_rev(void): extract version info
123  */
124 u32 get_cpu_rev(void)
125 {
126         u32 cpuid = get_cpu_id();
127
128         if (cpuid == 0)
129                 return CPU_3XX_ES10;
130         else
131                 return (cpuid >> CPU_3XX_ID_SHIFT) & 0xf;
132 }
133
134 /*
135  * print_cpuinfo(void): print CPU information
136  */
137 int print_cpuinfo(void)
138 {
139         char *cpu_family_s, *cpu_s, *sec_s;
140
141         switch (get_cpu_family()) {
142         case CPU_OMAP34XX:
143                 cpu_family_s = "OMAP";
144                 switch (get_cpu_type()) {
145                 case OMAP3503:
146                         cpu_s = "3503";
147                         break;
148                 case OMAP3515:
149                         cpu_s = "3515";
150                         break;
151                 case OMAP3525:
152                         cpu_s = "3525";
153                         break;
154                 case OMAP3530:
155                         cpu_s = "3530";
156                         break;
157                 default:
158                         cpu_s = "35XX";
159                         break;
160                 }
161                 break;
162         case CPU_AM35XX:
163                 cpu_family_s = "AM";
164                 switch (get_cpu_type()) {
165                 case AM3505:
166                         cpu_s = "3505";
167                         break;
168                 case AM3517:
169                         cpu_s = "3517";
170                         break;
171                 default:
172                         cpu_s = "35XX";
173                         break;
174                 }
175                 break;
176         case CPU_OMAP36XX:
177                 cpu_family_s = "OMAP";
178                 switch (get_cpu_type()) {
179                 case OMAP3730:
180                         cpu_s = "3630/3730";
181                         break;
182                 default:
183                         cpu_s = "36XX/37XX";
184                         break;
185                 }
186                 break;
187         default:
188                 cpu_family_s = "OMAP";
189                 cpu_s = "35XX";
190         }
191
192         switch (get_device_type()) {
193         case TST_DEVICE:
194                 sec_s = "TST";
195                 break;
196         case EMU_DEVICE:
197                 sec_s = "EMU";
198                 break;
199         case HS_DEVICE:
200                 sec_s = "HS";
201                 break;
202         case GP_DEVICE:
203                 sec_s = "GP";
204                 break;
205         default:
206                 sec_s = "?";
207         }
208
209         printf("%s%s-%s ES%s\n",
210                         cpu_family_s, cpu_s, sec_s, rev_s[get_cpu_rev()]);
211
212         return 0;
213 }
214
215 /*
216  * get_sysboot_value(void): return SYS_BOOT[4:0]
217  */
218 u32 get_sysboot_value(void)
219 {
220         int mode;
221         mode = __raw_readl(CONTROL_STATUS) & (SYSBOOT_MASK);
222         return mode;
223 }