blob: 60c35b4586b814510e0d5a15fe96baf168fde8ff [file] [log] [blame]
Peter Pearse5ca98812007-11-09 15:24:26 +00001/*
2 * (C) Copyright 2005-2007
3 * Samsung Electronics,
4 * Kyungmin Park <kyungmin.park@samsung.com>
5 *
6 * Derived from omap2420
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <asm/arch/omap2420.h>
26#include <asm/io.h>
27#include <asm/arch/bits.h>
28#include <asm/arch/mem.h> /* get mem tables */
29#include <asm/arch/sys_proto.h>
30#include <asm/arch/sys_info.h>
31#include <i2c.h>
32
33/**************************************************************************
34 * get_prod_id() - get id info from chips
35 ***************************************************************************/
36static u32 get_prod_id(void)
37{
38 u32 p;
39 p = __raw_readl(PRODUCTION_ID); /* get production ID */
40 return ((p & CPU_242X_PID_MASK) >> 16);
41}
42/**************************************************************************
43 * get_cpu_type() - low level get cpu type
44 * - no C globals yet.
45 * - just looking to say if this is a 2422 or 2420 or ...
46 * - to start with we will look at switch settings..
47 * - 2422 id's same as 2420 for ES1 will rely on H4 board characteristics
48 * (mux for 2420, non-mux for 2422).
49 ***************************************************************************/
50u32 get_cpu_type(void)
51{
52 u32 v;
53
54 switch (get_prod_id()) {
55 case 1:; /* 2420 */
56 case 2:
57 return (CPU_2420);
58 break; /* 2420 pop */
59 case 4:
60 return (CPU_2422);
61 break;
62 case 8:
63 return (CPU_2423);
64 break;
65 default:
66 break; /* early 2420/2422's unmarked */
67 }
68
69 v = __raw_readl(TAP_IDCODE_REG);
70 v &= CPU_24XX_ID_MASK;
71 if (v == CPU_2420_CHIPID) { /* currently 2420 and 2422 have same id */
72 if (is_gpmc_muxed() == GPMC_MUXED) /* if mux'ed */
73 return (CPU_2420);
74 else
75 return (CPU_2422);
76 } else
77 return (CPU_2420); /* don't know, say 2420 */
78}
79
80/******************************************
81 * get_cpu_rev(void) - extract version info
82 ******************************************/
83u32 get_cpu_rev(void)
84{
85 u32 v;
86 v = __raw_readl(TAP_IDCODE_REG);
87 v = v >> 28;
88 return (v + 1); /* currently 2422 and 2420 match up */
89}
90
91/****************************************************
92 * is_mem_sdr() - return 1 if mem type in use is SDR
93 ****************************************************/
94u32 is_mem_sdr(void)
95{
96 volatile u32 *burst = (volatile u32 *)(SDRC_MR_0 + SDRC_CS0_OSET);
97 if (*burst == H4_2420_SDRC_MR_0_SDR)
98 return (1);
99 return (0);
100}
101
102/***********************************************************
103 * get_mem_type() - identify type of mDDR part used.
104 * 2422 uses stacked DDR, 2 parts CS0/CS1.
105 * 2420 may have 1 or 2, no good way to know...only init 1...
106 * when eeprom data is up we can select 1 more.
107 *************************************************************/
108u32 get_mem_type(void)
109{
110 u32 cpu, sdr = is_mem_sdr();
111
112 cpu = get_cpu_type();
113 if (cpu == CPU_2422 || cpu == CPU_2423)
114 return (DDR_STACKED);
115
116 if (get_prod_id() == 0x2)
117 return (XDR_POP);
118
119 if (get_board_type() == BOARD_H4_MENELAUS)
120 if (sdr)
121 return (SDR_DISCRETE);
122 else
123 return (DDR_COMBO);
124 else if (sdr) /* SDP + SDR kit */
125 return (SDR_DISCRETE);
126 else
127 return (DDR_DISCRETE); /* origional SDP */
128}
129
130/**********************************************************************
131 *
132 * get_cs0_size() - get size of chip select 0/1
133 ************************************************************************/
134u32 get_sdr_cs_size(u32 offset)
135{
136 u32 size;
137 size = __raw_readl(SDRC_MCFG_0 + offset) >> 8; /* get ram size field */
138 size &= 0x2FF; /* remove unwanted bits */
139 size *= SZ_2M; /* find size in MB */
140 return (size);
141}
142
143/**********************************************************************
144 *
145 * get_board_type() - get board type based on current production stats.
146 * --- NOTE: 2 I2C EEPROMs will someday be populated with proper info.
147 * when they are available we can get info from there. This should
148 * be correct of all known boards up until today.
149 ************************************************************************/
150u32 get_board_type(void)
151{
152#if 0
153 if (i2c_probe(I2C_MENELAUS) == 0)
154 return (BOARD_H4_MENELAUS);
155 else
156#endif
157 return (BOARD_H4_SDP);
158}
159
160/******************************************************************
161 * get_sysboot_value() - get init word settings (dip switch on h4)
162******************************************************************/
163inline u32 get_sysboot_value(void)
164{
165 return (0x00000FFF & __raw_readl(CONTROL_STATUS));
166}
167
168/***************************************************************************
169 * get_gpmc0_base() - Return current address hardware will be
170 * fetching from. The below effectively gives what is correct, its a bit
171 * mis-leading compared to the TRM. For the most general case the mask
172 * needs to be also taken into account this does work in practice.
173 * - for u-boot we currently map:
174 * -- 0 to nothing,
175 * -- 4 to flash
176 * -- 8 to enent
177 * -- c to wifi
178 ***************************************************************************/
179u32 get_gpmc0_base(void)
180{
181 u32 b;
182
183 b = __raw_readl(GPMC_CONFIG7_0);
184 b &= 0x1F; /* keep base [5:0] */
185 b = b << 24; /* ret 0x0b000000 */
186 return (b);
187}
188
189/*****************************************************************
190 * is_gpmc_muxed() - tells if address/data lines are multiplexed
191 *****************************************************************/
192u32 is_gpmc_muxed(void)
193{
194 u32 mux;
195 mux = get_sysboot_value();
196 if ((mux & (BIT0 | BIT1 | BIT2 | BIT3)) == (BIT0 | BIT2 | BIT3))
197 return (GPMC_MUXED); /* NAND Boot mode */
198 if (mux & BIT1) /* if mux'ed */
199 return (GPMC_MUXED);
200 else
201 return (GPMC_NONMUXED);
202}
203
204/************************************************************************
205 * get_gpmc0_type() - read sysboot lines to see type of memory attached
206 ************************************************************************/
207u32 get_gpmc0_type(void)
208{
209 u32 type;
210 type = get_sysboot_value();
211 if ((type & (BIT3 | BIT2)) == (BIT3 | BIT2))
212 return (TYPE_NAND);
213 else
214 return (TYPE_NOR);
215}
216
217/*******************************************************************
218 * get_gpmc0_width() - See if bus is in x8 or x16 (mainly for nand)
219 *******************************************************************/
220u32 get_gpmc0_width(void)
221{
222 u32 width;
223 width = get_sysboot_value();
224 if ((width & 0xF) == (BIT3 | BIT2))
225 return (WIDTH_8BIT);
226 else
227 return (WIDTH_16BIT);
228}
229
230/*********************************************************************
231 * wait_on_value() - common routine to allow waiting for changes in
232 * volatile regs.
233 *********************************************************************/
234u32 wait_on_value(u32 read_bit_mask, u32 match_value, u32 read_addr,
235u32 bound) {
236 u32 i = 0, val;
237 do {
238 ++i;
239 val = __raw_readl(read_addr) & read_bit_mask;
240 if (val == match_value)
241 return (1);
242 if (i == bound)
243 return (0);
244 } while (1);
245}
246
247/*********************************************************************
248 * display_board_info() - print banner with board info.
249 *********************************************************************/
250void display_board_info(u32 btype)
251{
252 char cpu_2420[] = "2420"; /* cpu type */
253 char cpu_2422[] = "2422";
254 char cpu_2423[] = "2423";
255 char db_men[] = "Menelaus"; /* board type */
256 char db_ip[] = "IP";
257 char mem_sdr[] = "mSDR"; /* memory type */
258 char mem_ddr[] = "mDDR";
259 char t_tst[] = "TST"; /* security level */
260 char t_emu[] = "EMU";
261 char t_hs[] = "HS";
262 char t_gp[] = "GP";
263 char unk[] = "?";
264
265 char *cpu_s, *db_s, *mem_s, *sec_s;
266 u32 cpu, rev, sec;
267
268 rev = get_cpu_rev();
269 cpu = get_cpu_type();
270 sec = get_device_type();
271
272 if (is_mem_sdr())
273 mem_s = mem_sdr;
274 else
275 mem_s = mem_ddr;
276
277 if (cpu == CPU_2423)
278 cpu_s = cpu_2423;
279 else if (cpu == CPU_2422)
280 cpu_s = cpu_2422;
281 else
282 cpu_s = cpu_2420;
283
284 if (btype == BOARD_H4_MENELAUS)
285 db_s = db_men;
286 else
287 db_s = db_ip;
288
289 switch (sec) {
290 case TST_DEVICE:
291 sec_s = t_tst;
292 break;
293 case EMU_DEVICE:
294 sec_s = t_emu;
295 break;
296 case HS_DEVICE:
297 sec_s = t_hs;
298 break;
299 case GP_DEVICE:
300 sec_s = t_gp;
301 break;
302 default:
303 sec_s = unk;
304 }
305
306 printf("OMAP%s-%s revision %d\n", cpu_s, sec_s, rev - 1);
307 printf("Samsung Apollon SDP Base Board + %s \n", mem_s); }
308
309/*************************************************************************
310 * get_board_rev() - setup to pass kernel board revision information
311 * 0 = 242x IP platform (first 2xx boards)
312 * 1 = 242x Menelaus platfrom.
313 *************************************************************************/
314u32 get_board_rev(void)
315{
316 u32 rev = 0;
317 u32 btype = get_board_type();
318
319 if (btype == BOARD_H4_MENELAUS) {
320 rev = 1;
321 }
322 return (rev);
323}
324
325/********************************************************
326 * get_base(); get upper addr of current execution
327 *******************************************************/
328u32 get_base(void)
329{
330 u32 val;
331 __asm__ __volatile__("mov %0, pc \n":"=r"(val)::"memory");
332 val &= 0xF0000000;
333 val >>= 28;
334 return (val);
335}
336
337/********************************************************
338 * get_base2(); get 2upper addr of current execution
339 *******************************************************/
340u32 get_base2(void)
341{
342 u32 val;
343 __asm__ __volatile__("mov %0, pc \n":"=r"(val)::"memory");
344 val &= 0xFF000000;
345 val >>= 24;
346 return (val);
347}
348
349/********************************************************
350 * running_in_flash() - tell if currently running in
351 * flash.
352 *******************************************************/
353u32 running_in_flash(void)
354{
355 if (get_base() < 4)
356 return (1); /* in flash */
357 return (0); /* running in SRAM or SDRAM */
358}
359
360/********************************************************
361 * running_in_sram() - tell if currently running in
362 * sram.
363 *******************************************************/
364u32 running_in_sram(void)
365{
366 if (get_base() == 4)
367 return (1); /* in SRAM */
368 return (0); /* running in FLASH or SDRAM */
369}
370
371/********************************************************
372 * running_in_sdram() - tell if currently running in
373 * flash.
374 *******************************************************/
375u32 running_in_sdram(void)
376{
377 if (get_base() > 4)
378 return (1); /* in sdram */
379 return (0); /* running in SRAM or FLASH */
380}
381
382/*************************************************************
383 * running_from_internal_boot() - am I a signed NOR image.
384 *************************************************************/
385u32 running_from_internal_boot(void)
386{
387 u32 v, base;
388
389 v = get_sysboot_value() & BIT3;
390 base = get_base2();
391 /* if running at mask rom flash address and
392 * sysboot3 says this was an internal boot
393 */
394 if ((base == 0x08) && v)
395 return (1);
396 else
397 return (0);
398}
399
400/*************************************************************
401 * get_device_type(): tell if GP/HS/EMU/TST
402 *************************************************************/
403u32 get_device_type(void)
404{
405 int mode;
406 mode = __raw_readl(CONTROL_STATUS) & (BIT10 | BIT9 | BIT8);
407 return (mode >>= 8);
408}