sys_info.c 11 KB

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