sys_info.c 11 KB

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