sys_info.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 mem_sdr[] = "mSDR"; /* memory type */
  230. char mem_ddr[] = "mDDR";
  231. char t_tst[] = "TST"; /* security level */
  232. char t_emu[] = "EMU";
  233. char t_hs[] = "HS";
  234. char t_gp[] = "GP";
  235. char unk[] = "?";
  236. char *cpu_s, *mem_s, *sec_s;
  237. u32 cpu, rev, sec;
  238. rev = get_cpu_rev();
  239. cpu = get_cpu_type();
  240. sec = get_device_type();
  241. if (is_mem_sdr())
  242. mem_s = mem_sdr;
  243. else
  244. mem_s = mem_ddr;
  245. if (cpu == CPU_2423)
  246. cpu_s = cpu_2423;
  247. else if (cpu == CPU_2422)
  248. cpu_s = cpu_2422;
  249. else
  250. cpu_s = cpu_2420;
  251. switch (sec) {
  252. case TST_DEVICE:
  253. sec_s = t_tst;
  254. break;
  255. case EMU_DEVICE:
  256. sec_s = t_emu;
  257. break;
  258. case HS_DEVICE:
  259. sec_s = t_hs;
  260. break;
  261. case GP_DEVICE:
  262. sec_s = t_gp;
  263. break;
  264. default:
  265. sec_s = unk;
  266. }
  267. printf("OMAP%s-%s revision %d\n", cpu_s, sec_s, rev - 1);
  268. printf("Samsung Apollon SDP Base Board + %s \n", mem_s);
  269. }
  270. /*************************************************************************
  271. * get_board_rev() - setup to pass kernel board revision information
  272. * 0 = 242x IP platform (first 2xx boards)
  273. * 1 = 242x Menelaus platfrom.
  274. *************************************************************************/
  275. u32 get_board_rev(void)
  276. {
  277. u32 rev = 0;
  278. u32 btype = get_board_type();
  279. if (btype == BOARD_H4_MENELAUS)
  280. rev = 1;
  281. return (rev);
  282. }
  283. /********************************************************
  284. * get_base(); get upper addr of current execution
  285. *******************************************************/
  286. u32 get_base(void)
  287. {
  288. u32 val;
  289. __asm__ __volatile__("mov %0, pc \n":"=r"(val)::"memory");
  290. val &= 0xF0000000;
  291. val >>= 28;
  292. return (val);
  293. }
  294. /********************************************************
  295. * get_base2(); get 2upper addr of current execution
  296. *******************************************************/
  297. u32 get_base2(void)
  298. {
  299. u32 val;
  300. __asm__ __volatile__("mov %0, pc \n":"=r"(val)::"memory");
  301. val &= 0xFF000000;
  302. val >>= 24;
  303. return (val);
  304. }
  305. /********************************************************
  306. * running_in_flash() - tell if currently running in
  307. * flash.
  308. *******************************************************/
  309. u32 running_in_flash(void)
  310. {
  311. if (get_base() < 4)
  312. return (1); /* in flash */
  313. return (0); /* running in SRAM or SDRAM */
  314. }
  315. /********************************************************
  316. * running_in_sram() - tell if currently running in
  317. * sram.
  318. *******************************************************/
  319. u32 running_in_sram(void)
  320. {
  321. if (get_base() == 4)
  322. return (1); /* in SRAM */
  323. return (0); /* running in FLASH or SDRAM */
  324. }
  325. /********************************************************
  326. * running_in_sdram() - tell if currently running in
  327. * flash.
  328. *******************************************************/
  329. u32 running_in_sdram(void)
  330. {
  331. if (get_base() > 4)
  332. return (1); /* in sdram */
  333. return (0); /* running in SRAM or FLASH */
  334. }
  335. /*************************************************************
  336. * running_from_internal_boot() - am I a signed NOR image.
  337. *************************************************************/
  338. u32 running_from_internal_boot(void)
  339. {
  340. u32 v, base;
  341. v = get_sysboot_value() & BIT3;
  342. base = get_base2();
  343. /* if running at mask rom flash address and
  344. * sysboot3 says this was an internal boot
  345. */
  346. if ((base == 0x08) && v)
  347. return (1);
  348. else
  349. return (0);
  350. }
  351. /*************************************************************
  352. * get_device_type(): tell if GP/HS/EMU/TST
  353. *************************************************************/
  354. u32 get_device_type(void)
  355. {
  356. int mode;
  357. mode = __raw_readl(CONTROL_STATUS) & (BIT10 | BIT9 | BIT8);
  358. return (mode >>= 8);
  359. }