blob: 26ac9a2c8d0e9a5bd626aa1870f078844cdd0ddc [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}
Peter Pearse2db916e2007-11-15 08:45:13 +000042
Peter Pearse5ca98812007-11-09 15:24:26 +000043/**************************************************************************
44 * get_cpu_type() - low level get cpu type
45 * - no C globals yet.
46 * - just looking to say if this is a 2422 or 2420 or ...
47 * - to start with we will look at switch settings..
48 * - 2422 id's same as 2420 for ES1 will rely on H4 board characteristics
49 * (mux for 2420, non-mux for 2422).
50 ***************************************************************************/
51u32 get_cpu_type(void)
52{
53 u32 v;
54
55 switch (get_prod_id()) {
56 case 1:; /* 2420 */
57 case 2:
58 return (CPU_2420);
59 break; /* 2420 pop */
60 case 4:
61 return (CPU_2422);
62 break;
63 case 8:
64 return (CPU_2423);
65 break;
66 default:
67 break; /* early 2420/2422's unmarked */
68 }
69
70 v = __raw_readl(TAP_IDCODE_REG);
71 v &= CPU_24XX_ID_MASK;
Peter Pearse2db916e2007-11-15 08:45:13 +000072 /* currently 2420 and 2422 have same id */
73 if (v == CPU_2420_CHIPID) {
Peter Pearse5ca98812007-11-09 15:24:26 +000074 if (is_gpmc_muxed() == GPMC_MUXED) /* if mux'ed */
75 return (CPU_2420);
76 else
77 return (CPU_2422);
78 } else
79 return (CPU_2420); /* don't know, say 2420 */
80}
81
82/******************************************
83 * get_cpu_rev(void) - extract version info
84 ******************************************/
85u32 get_cpu_rev(void)
86{
87 u32 v;
88 v = __raw_readl(TAP_IDCODE_REG);
89 v = v >> 28;
90 return (v + 1); /* currently 2422 and 2420 match up */
91}
92
93/****************************************************
94 * is_mem_sdr() - return 1 if mem type in use is SDR
95 ****************************************************/
96u32 is_mem_sdr(void)
97{
98 volatile u32 *burst = (volatile u32 *)(SDRC_MR_0 + SDRC_CS0_OSET);
99 if (*burst == H4_2420_SDRC_MR_0_SDR)
100 return (1);
101 return (0);
102}
103
104/***********************************************************
105 * get_mem_type() - identify type of mDDR part used.
106 * 2422 uses stacked DDR, 2 parts CS0/CS1.
107 * 2420 may have 1 or 2, no good way to know...only init 1...
108 * when eeprom data is up we can select 1 more.
109 *************************************************************/
110u32 get_mem_type(void)
111{
112 u32 cpu, sdr = is_mem_sdr();
113
114 cpu = get_cpu_type();
115 if (cpu == CPU_2422 || cpu == CPU_2423)
116 return (DDR_STACKED);
117
118 if (get_prod_id() == 0x2)
119 return (XDR_POP);
120
121 if (get_board_type() == BOARD_H4_MENELAUS)
122 if (sdr)
123 return (SDR_DISCRETE);
124 else
125 return (DDR_COMBO);
126 else if (sdr) /* SDP + SDR kit */
127 return (SDR_DISCRETE);
128 else
129 return (DDR_DISCRETE); /* origional SDP */
130}
131
Peter Pearse2db916e2007-11-15 08:45:13 +0000132/***********************************************************************
Peter Pearse5ca98812007-11-09 15:24:26 +0000133 * get_cs0_size() - get size of chip select 0/1
134 ************************************************************************/
135u32 get_sdr_cs_size(u32 offset)
136{
137 u32 size;
138 size = __raw_readl(SDRC_MCFG_0 + offset) >> 8; /* get ram size field */
139 size &= 0x2FF; /* remove unwanted bits */
140 size *= SZ_2M; /* find size in MB */
141 return (size);
142}
143
Peter Pearse2db916e2007-11-15 08:45:13 +0000144/***********************************************************************
Peter Pearse5ca98812007-11-09 15:24:26 +0000145 * 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{
Peter Pearse2db916e2007-11-15 08:45:13 +0000152 return (BOARD_H4_SDP);
Peter Pearse5ca98812007-11-09 15:24:26 +0000153}
154
155/******************************************************************
156 * get_sysboot_value() - get init word settings (dip switch on h4)
Peter Pearse2db916e2007-11-15 08:45:13 +0000157 ******************************************************************/
Peter Pearse5ca98812007-11-09 15:24:26 +0000158inline u32 get_sysboot_value(void)
159{
160 return (0x00000FFF & __raw_readl(CONTROL_STATUS));
161}
162
163/***************************************************************************
164 * get_gpmc0_base() - Return current address hardware will be
165 * fetching from. The below effectively gives what is correct, its a bit
166 * mis-leading compared to the TRM. For the most general case the mask
167 * needs to be also taken into account this does work in practice.
168 * - for u-boot we currently map:
169 * -- 0 to nothing,
170 * -- 4 to flash
171 * -- 8 to enent
172 * -- c to wifi
Peter Pearse2db916e2007-11-15 08:45:13 +0000173 ****************************************************************************/
Peter Pearse5ca98812007-11-09 15:24:26 +0000174u32 get_gpmc0_base(void)
175{
176 u32 b;
177
178 b = __raw_readl(GPMC_CONFIG7_0);
179 b &= 0x1F; /* keep base [5:0] */
180 b = b << 24; /* ret 0x0b000000 */
181 return (b);
182}
183
184/*****************************************************************
185 * is_gpmc_muxed() - tells if address/data lines are multiplexed
186 *****************************************************************/
187u32 is_gpmc_muxed(void)
188{
189 u32 mux;
190 mux = get_sysboot_value();
191 if ((mux & (BIT0 | BIT1 | BIT2 | BIT3)) == (BIT0 | BIT2 | BIT3))
192 return (GPMC_MUXED); /* NAND Boot mode */
193 if (mux & BIT1) /* if mux'ed */
194 return (GPMC_MUXED);
195 else
196 return (GPMC_NONMUXED);
197}
198
199/************************************************************************
200 * get_gpmc0_type() - read sysboot lines to see type of memory attached
201 ************************************************************************/
202u32 get_gpmc0_type(void)
203{
204 u32 type;
205 type = get_sysboot_value();
206 if ((type & (BIT3 | BIT2)) == (BIT3 | BIT2))
207 return (TYPE_NAND);
208 else
209 return (TYPE_NOR);
210}
211
212/*******************************************************************
213 * get_gpmc0_width() - See if bus is in x8 or x16 (mainly for nand)
214 *******************************************************************/
215u32 get_gpmc0_width(void)
216{
217 u32 width;
218 width = get_sysboot_value();
219 if ((width & 0xF) == (BIT3 | BIT2))
220 return (WIDTH_8BIT);
221 else
222 return (WIDTH_16BIT);
223}
224
225/*********************************************************************
226 * wait_on_value() - common routine to allow waiting for changes in
227 * volatile regs.
228 *********************************************************************/
Peter Pearse2db916e2007-11-15 08:45:13 +0000229u32 wait_on_value(u32 read_bit_mask, u32 match_value, u32 read_addr, u32 bound)
230{
Peter Pearse5ca98812007-11-09 15:24:26 +0000231 u32 i = 0, val;
232 do {
233 ++i;
234 val = __raw_readl(read_addr) & read_bit_mask;
235 if (val == match_value)
236 return (1);
237 if (i == bound)
238 return (0);
239 } while (1);
240}
241
242/*********************************************************************
243 * display_board_info() - print banner with board info.
244 *********************************************************************/
245void display_board_info(u32 btype)
246{
247 char cpu_2420[] = "2420"; /* cpu type */
248 char cpu_2422[] = "2422";
249 char cpu_2423[] = "2423";
250 char db_men[] = "Menelaus"; /* board type */
251 char db_ip[] = "IP";
252 char mem_sdr[] = "mSDR"; /* memory type */
253 char mem_ddr[] = "mDDR";
254 char t_tst[] = "TST"; /* security level */
255 char t_emu[] = "EMU";
256 char t_hs[] = "HS";
257 char t_gp[] = "GP";
258 char unk[] = "?";
259
260 char *cpu_s, *db_s, *mem_s, *sec_s;
261 u32 cpu, rev, sec;
262
263 rev = get_cpu_rev();
264 cpu = get_cpu_type();
265 sec = get_device_type();
266
267 if (is_mem_sdr())
268 mem_s = mem_sdr;
269 else
270 mem_s = mem_ddr;
271
272 if (cpu == CPU_2423)
273 cpu_s = cpu_2423;
274 else if (cpu == CPU_2422)
275 cpu_s = cpu_2422;
276 else
277 cpu_s = cpu_2420;
278
279 if (btype == BOARD_H4_MENELAUS)
280 db_s = db_men;
281 else
282 db_s = db_ip;
283
284 switch (sec) {
285 case TST_DEVICE:
286 sec_s = t_tst;
287 break;
288 case EMU_DEVICE:
289 sec_s = t_emu;
290 break;
291 case HS_DEVICE:
292 sec_s = t_hs;
293 break;
294 case GP_DEVICE:
295 sec_s = t_gp;
296 break;
297 default:
298 sec_s = unk;
299 }
300
301 printf("OMAP%s-%s revision %d\n", cpu_s, sec_s, rev - 1);
Peter Pearse2db916e2007-11-15 08:45:13 +0000302 printf("Samsung Apollon SDP Base Board + %s \n", mem_s);
303}
Peter Pearse5ca98812007-11-09 15:24:26 +0000304
305/*************************************************************************
306 * get_board_rev() - setup to pass kernel board revision information
307 * 0 = 242x IP platform (first 2xx boards)
308 * 1 = 242x Menelaus platfrom.
309 *************************************************************************/
310u32 get_board_rev(void)
311{
312 u32 rev = 0;
313 u32 btype = get_board_type();
314
Peter Pearse2db916e2007-11-15 08:45:13 +0000315 if (btype == BOARD_H4_MENELAUS)
Peter Pearse5ca98812007-11-09 15:24:26 +0000316 rev = 1;
Peter Pearse5ca98812007-11-09 15:24:26 +0000317 return (rev);
318}
319
320/********************************************************
321 * get_base(); get upper addr of current execution
322 *******************************************************/
323u32 get_base(void)
324{
325 u32 val;
326 __asm__ __volatile__("mov %0, pc \n":"=r"(val)::"memory");
327 val &= 0xF0000000;
328 val >>= 28;
329 return (val);
330}
331
332/********************************************************
333 * get_base2(); get 2upper addr of current execution
334 *******************************************************/
335u32 get_base2(void)
336{
337 u32 val;
338 __asm__ __volatile__("mov %0, pc \n":"=r"(val)::"memory");
339 val &= 0xFF000000;
340 val >>= 24;
341 return (val);
342}
343
344/********************************************************
345 * running_in_flash() - tell if currently running in
346 * flash.
347 *******************************************************/
348u32 running_in_flash(void)
349{
350 if (get_base() < 4)
351 return (1); /* in flash */
352 return (0); /* running in SRAM or SDRAM */
353}
354
355/********************************************************
356 * running_in_sram() - tell if currently running in
357 * sram.
358 *******************************************************/
359u32 running_in_sram(void)
360{
361 if (get_base() == 4)
362 return (1); /* in SRAM */
363 return (0); /* running in FLASH or SDRAM */
364}
365
366/********************************************************
367 * running_in_sdram() - tell if currently running in
368 * flash.
369 *******************************************************/
370u32 running_in_sdram(void)
371{
372 if (get_base() > 4)
373 return (1); /* in sdram */
374 return (0); /* running in SRAM or FLASH */
375}
376
377/*************************************************************
378 * running_from_internal_boot() - am I a signed NOR image.
379 *************************************************************/
380u32 running_from_internal_boot(void)
381{
382 u32 v, base;
383
384 v = get_sysboot_value() & BIT3;
385 base = get_base2();
386 /* if running at mask rom flash address and
387 * sysboot3 says this was an internal boot
388 */
389 if ((base == 0x08) && v)
390 return (1);
391 else
392 return (0);
393}
394
395/*************************************************************
396 * get_device_type(): tell if GP/HS/EMU/TST
397 *************************************************************/
398u32 get_device_type(void)
399{
400 int mode;
401 mode = __raw_readl(CONTROL_STATUS) & (BIT10 | BIT9 | BIT8);
402 return (mode >>= 8);
403}