sys_info.c 11 KB

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