sys_info.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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_cpu_type() - low level get cpu type
  31. * - no C globals yet.
  32. * - just looking to say if this is a 2422 or 2420 or ...
  33. * - to start with we will look at switch settings..
  34. * - 2422 id's same as 2420 for ES1 will rely on H4 board characteristics
  35. * (mux for 2420, non-mux for 2422).
  36. ***************************************************************************/
  37. u32 get_cpu_type(void)
  38. {
  39. u32 v;
  40. v = __raw_readl(TAP_IDCODE_REG);
  41. v &= CPU_24XX_ID_MASK;
  42. if (v == CPU_2420_CHIPID) { /* currently 2420 and 2422 have same id */
  43. if (is_gpmc_muxed() == GPMC_MUXED) /* if mux'ed */
  44. return(CPU_2420);
  45. else
  46. return(CPU_2422);
  47. } else
  48. return(CPU_2420); /* don't know, say 2420 */
  49. }
  50. /******************************************
  51. * get_cpu_rev(void) - extract version info
  52. ******************************************/
  53. u32 get_cpu_rev(void)
  54. {
  55. u32 v;
  56. v = __raw_readl(TAP_IDCODE_REG);
  57. v = v >> 28;
  58. return(v+1); /* currently 2422 and 2420 match up */
  59. }
  60. /***********************************************************
  61. * get_mem_type() - identify type of mDDR part used.
  62. * 2422 uses stacked DDR, 2 parts CS0/CS1.
  63. * 2420 may have 1 or 2, no good way to know...only init 1...
  64. * when eeprom data is up we can select 1 more.
  65. *************************************************************/
  66. u32 get_mem_type(void)
  67. {
  68. volatile u32 *burst = (volatile u32 *)(SDRC_MR_0+SDRC_CS0_OSET);
  69. if (get_cpu_type() == CPU_2422)
  70. return(DDR_STACKED);
  71. if (get_board_type() == BOARD_H4_MENELAUS)
  72. if(*burst == H4_2420_SDRC_MR_0_SDR)
  73. return(SDR_DISCRETE);
  74. else
  75. return(DDR_COMBO);
  76. else
  77. if(*burst == H4_2420_SDRC_MR_0_SDR) /* SDP + SDR kit */
  78. return(SDR_DISCRETE);
  79. else
  80. return(DDR_DISCRETE); /* origional SDP */
  81. }
  82. /***********************************************************************
  83. * get_board_type() - get board type based on current production stats.
  84. * --- NOTE: 2 I2C EEPROMs will someday be populated with proper info.
  85. * when they are available we can get info from there. This should
  86. * be correct of all known boards up until today.
  87. ************************************************************************/
  88. u32 get_board_type(void)
  89. {
  90. if (i2c_probe(I2C_MENELAUS) == 0)
  91. return(BOARD_H4_MENELAUS);
  92. else
  93. return(BOARD_H4_SDP);
  94. }
  95. /******************************************************************
  96. * get_sysboot_value() - get init word settings (dip switch on h4)
  97. ******************************************************************/
  98. u32 get_sysboot_value(void)
  99. {
  100. return(0x00000FFF & __raw_readl(CONTROL_STATUS));
  101. }
  102. /***************************************************************************
  103. * get_gpmc0_base() - Return current address hardware will be
  104. * fetching from. The below effectively gives what is correct, its a bit
  105. * mis-leading compared to the TRM. For the most general case the mask
  106. * needs to be also taken into account this does work in practice.
  107. * - for u-boot we currently map:
  108. * -- 0 to nothing,
  109. * -- 4 to flash
  110. * -- 8 to enent
  111. * -- c to wifi
  112. ****************************************************************************/
  113. u32 get_gpmc0_base(void)
  114. {
  115. u32 b;
  116. b = __raw_readl(GPMC_CONFIG7_0);
  117. b &= 0x1F; /* keep base [5:0] */
  118. b = b << 24; /* ret 0x0b000000 */
  119. return(b);
  120. }
  121. /*****************************************************************
  122. * is_gpmc_muxed() - tells if address/data lines are multiplexed
  123. *****************************************************************/
  124. u32 is_gpmc_muxed(void)
  125. {
  126. u32 mux;
  127. mux = get_sysboot_value();
  128. if ((mux & (BIT0 | BIT1 | BIT2 | BIT3)) == (BIT0 | BIT2 | BIT3))
  129. return(GPMC_MUXED); /* NAND Boot mode */
  130. if (mux & BIT1) /* if mux'ed */
  131. return(GPMC_MUXED);
  132. else
  133. return(GPMC_NONMUXED);
  134. }
  135. /************************************************************************
  136. * get_gpmc0_type() - read sysboot lines to see type of memory attached
  137. ************************************************************************/
  138. u32 get_gpmc0_type(void)
  139. {
  140. u32 type;
  141. type = get_sysboot_value();
  142. if ((type & (BIT3|BIT2)) == (BIT3|BIT2))
  143. return(TYPE_NAND);
  144. else
  145. return(TYPE_NOR);
  146. }
  147. /*******************************************************************
  148. * get_gpmc0_width() - See if bus is in x8 or x16 (mainly for nand)
  149. *******************************************************************/
  150. u32 get_gpmc0_width(void)
  151. {
  152. u32 width;
  153. width = get_sysboot_value();
  154. if ((width & 0xF) == (BIT3|BIT2))
  155. return(WIDTH_8BIT);
  156. else
  157. return(WIDTH_16BIT);
  158. }
  159. /*********************************************************************
  160. * wait_on_value() - common routine to allow waiting for changes in
  161. * volatile regs.
  162. *********************************************************************/
  163. u32 wait_on_value(u32 read_bit_mask, u32 match_value, u32 read_addr, u32 bound)
  164. {
  165. u32 i = 0, val;
  166. do {
  167. ++i;
  168. val = __raw_readl(read_addr) & read_bit_mask;
  169. if (val == match_value)
  170. return(1);
  171. if (i==bound)
  172. return(0);
  173. } while (1);
  174. }
  175. /*********************************************************************
  176. * display_board_info() - print banner with board info.
  177. *********************************************************************/
  178. void display_board_info(u32 btype)
  179. {
  180. char cpu_2420[] = "2420";
  181. char cpu_2422[] = "2422";
  182. char db_men[] = "Menelaus";
  183. char db_ip[]= "IP";
  184. char *cpu_s, *db_s;
  185. u32 cpu = get_cpu_type();
  186. if(cpu == CPU_2420)
  187. cpu_s = cpu_2420;
  188. else
  189. cpu_s = cpu_2422;
  190. if(btype == BOARD_H4_MENELAUS)
  191. db_s = db_men;
  192. else
  193. db_s = db_ip;
  194. printf("TI H4 SDP Base Board with OMAP%s %s Daughter Board\n",cpu_s, db_s);
  195. }
  196. /*************************************************************************
  197. * get_board_rev() - setup to pass kernel board revision information
  198. * 0 = 242x IP platform (first 2xx boards)
  199. * 1 = 242x Menelaus platfrom.
  200. *************************************************************************/
  201. u32 get_board_rev(void)
  202. {
  203. u32 rev = 0;
  204. u32 btype = get_board_type();
  205. if (btype == BOARD_H4_MENELAUS){
  206. rev = 1;
  207. }
  208. return(rev);
  209. }
  210. /********************************************************
  211. * get_base(); get upper addr of current execution
  212. *******************************************************/
  213. static u32 get_base(void)
  214. {
  215. u32 val;
  216. __asm__ __volatile__("mov %0, pc \n" : "=r" (val) : : "memory");
  217. val &= 0xF0000000;
  218. val >>= 28;
  219. return(val);
  220. }
  221. /********************************************************
  222. * get_base2(); get 2upper addr of current execution
  223. *******************************************************/
  224. static u32 get_base2(void)
  225. {
  226. u32 val;
  227. __asm__ __volatile__("mov %0, pc \n" : "=r" (val) : : "memory");
  228. val &= 0xFF000000;
  229. val >>= 24;
  230. return(val);
  231. }
  232. /********************************************************
  233. * running_in_flash() - tell if currently running in
  234. * flash.
  235. *******************************************************/
  236. u32 running_in_flash(void)
  237. {
  238. if (get_base() < 4)
  239. return(1); /* in flash */
  240. return(0); /* running in SRAM or SDRAM */
  241. }
  242. /********************************************************
  243. * running_in_sram() - tell if currently running in
  244. * sram.
  245. *******************************************************/
  246. u32 running_in_sram(void)
  247. {
  248. if (get_base() == 4)
  249. return(1); /* in SRAM */
  250. return(0); /* running in FLASH or SDRAM */
  251. }
  252. /********************************************************
  253. * running_in_sdram() - tell if currently running in
  254. * flash.
  255. *******************************************************/
  256. u32 running_in_sdram(void)
  257. {
  258. if (get_base() > 4)
  259. return(1); /* in sdram */
  260. return(0); /* running in SRAM or FLASH */
  261. }
  262. /*************************************************************
  263. * running_from_internal_boot() - am I a signed NOR image.
  264. *************************************************************/
  265. u32 running_from_internal_boot(void)
  266. {
  267. u32 v, base;
  268. v = get_sysboot_value() & BIT3;
  269. base = get_base2();
  270. /* if running at mask rom flash address and
  271. * sysboot3 says this was an internal boot
  272. */
  273. if ((base == 0x08) && v)
  274. return(1);
  275. else
  276. return(0);
  277. }