sys_info.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*
  2. * (C) Copyright 2008
  3. * Texas Instruments, <www.ti.com>
  4. *
  5. * Author :
  6. * Manikandan Pillai <mani.pillai@ti.com>
  7. *
  8. * Derived from Beagle Board and 3430 SDP code by
  9. * Richard Woodruff <r-woodruff2@ti.com>
  10. * Syed Mohammed Khasim <khasim@ti.com>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <asm/io.h>
  29. #include <asm/arch/mem.h> /* get mem tables */
  30. #include <asm/arch/sys_proto.h>
  31. #include <i2c.h>
  32. #include <linux/compiler.h>
  33. extern omap3_sysinfo sysinfo;
  34. static struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
  35. #ifdef CONFIG_DISPLAY_CPUINFO
  36. static char *rev_s[CPU_3XX_MAX_REV] = {
  37. "1.0",
  38. "2.0",
  39. "2.1",
  40. "3.0",
  41. "3.1",
  42. "UNKNOWN",
  43. "UNKNOWN",
  44. "3.1.2"};
  45. /* this is the revision table for 37xx CPUs */
  46. static char *rev_s_37xx[CPU_37XX_MAX_REV] = {
  47. "1.0",
  48. "1.1",
  49. "1.2"};
  50. #endif /* CONFIG_DISPLAY_CPUINFO */
  51. /*****************************************************************
  52. * dieid_num_r(void) - read and set die ID
  53. *****************************************************************/
  54. void dieid_num_r(void)
  55. {
  56. struct ctrl_id *id_base = (struct ctrl_id *)OMAP34XX_ID_L4_IO_BASE;
  57. char *uid_s, die_id[34];
  58. u32 id[4];
  59. memset(die_id, 0, sizeof(die_id));
  60. uid_s = getenv("dieid#");
  61. if (uid_s == NULL) {
  62. id[3] = readl(&id_base->die_id_0);
  63. id[2] = readl(&id_base->die_id_1);
  64. id[1] = readl(&id_base->die_id_2);
  65. id[0] = readl(&id_base->die_id_3);
  66. sprintf(die_id, "%08x%08x%08x%08x", id[0], id[1], id[2], id[3]);
  67. setenv("dieid#", die_id);
  68. uid_s = die_id;
  69. }
  70. printf("Die ID #%s\n", uid_s);
  71. }
  72. /******************************************
  73. * get_cpu_type(void) - extract cpu info
  74. ******************************************/
  75. u32 get_cpu_type(void)
  76. {
  77. return readl(&ctrl_base->ctrl_omap_stat);
  78. }
  79. /******************************************
  80. * get_cpu_id(void) - extract cpu id
  81. * returns 0 for ES1.0, cpuid otherwise
  82. ******************************************/
  83. u32 get_cpu_id(void)
  84. {
  85. struct ctrl_id *id_base;
  86. u32 cpuid = 0;
  87. /*
  88. * On ES1.0 the IDCODE register is not exposed on L4
  89. * so using CPU ID to differentiate between ES1.0 and > ES1.0.
  90. */
  91. __asm__ __volatile__("mrc p15, 0, %0, c0, c0, 0":"=r"(cpuid));
  92. if ((cpuid & 0xf) == 0x0) {
  93. return 0;
  94. } else {
  95. /* Decode the IDs on > ES1.0 */
  96. id_base = (struct ctrl_id *) OMAP34XX_ID_L4_IO_BASE;
  97. cpuid = readl(&id_base->idcode);
  98. }
  99. return cpuid;
  100. }
  101. /******************************************
  102. * get_cpu_family(void) - extract cpu info
  103. ******************************************/
  104. u32 get_cpu_family(void)
  105. {
  106. u16 hawkeye;
  107. u32 cpu_family;
  108. u32 cpuid = get_cpu_id();
  109. if (cpuid == 0)
  110. return CPU_OMAP34XX;
  111. hawkeye = (cpuid >> HAWKEYE_SHIFT) & 0xffff;
  112. switch (hawkeye) {
  113. case HAWKEYE_OMAP34XX:
  114. cpu_family = CPU_OMAP34XX;
  115. break;
  116. case HAWKEYE_AM35XX:
  117. cpu_family = CPU_AM35XX;
  118. break;
  119. case HAWKEYE_OMAP36XX:
  120. cpu_family = CPU_OMAP36XX;
  121. break;
  122. default:
  123. cpu_family = CPU_OMAP34XX;
  124. }
  125. return cpu_family;
  126. }
  127. /******************************************
  128. * get_cpu_rev(void) - extract version info
  129. ******************************************/
  130. u32 get_cpu_rev(void)
  131. {
  132. u32 cpuid = get_cpu_id();
  133. if (cpuid == 0)
  134. return CPU_3XX_ES10;
  135. else
  136. return (cpuid >> CPU_3XX_ID_SHIFT) & 0xf;
  137. }
  138. /*****************************************************************
  139. * get_sku_id(void) - read sku_id to get info on max clock rate
  140. *****************************************************************/
  141. u32 get_sku_id(void)
  142. {
  143. struct ctrl_id *id_base = (struct ctrl_id *)OMAP34XX_ID_L4_IO_BASE;
  144. return readl(&id_base->sku_id) & SKUID_CLK_MASK;
  145. }
  146. /***************************************************************************
  147. * get_gpmc0_base() - Return current address hardware will be
  148. * fetching from. The below effectively gives what is correct, its a bit
  149. * mis-leading compared to the TRM. For the most general case the mask
  150. * needs to be also taken into account this does work in practice.
  151. * - for u-boot we currently map:
  152. * -- 0 to nothing,
  153. * -- 4 to flash
  154. * -- 8 to enent
  155. * -- c to wifi
  156. ****************************************************************************/
  157. u32 get_gpmc0_base(void)
  158. {
  159. u32 b;
  160. b = readl(&gpmc_cfg->cs[0].config7);
  161. b &= 0x1F; /* keep base [5:0] */
  162. b = b << 24; /* ret 0x0b000000 */
  163. return b;
  164. }
  165. /*******************************************************************
  166. * get_gpmc0_width() - See if bus is in x8 or x16 (mainly for nand)
  167. *******************************************************************/
  168. u32 get_gpmc0_width(void)
  169. {
  170. return WIDTH_16BIT;
  171. }
  172. /*************************************************************************
  173. * get_board_rev() - setup to pass kernel board revision information
  174. * returns:(bit[0-3] sub version, higher bit[7-4] is higher version)
  175. *************************************************************************/
  176. u32 __weak get_board_rev(void)
  177. {
  178. return 0x20;
  179. }
  180. /********************************************************
  181. * get_base(); get upper addr of current execution
  182. *******************************************************/
  183. u32 get_base(void)
  184. {
  185. u32 val;
  186. __asm__ __volatile__("mov %0, pc \n":"=r"(val)::"memory");
  187. val &= 0xF0000000;
  188. val >>= 28;
  189. return val;
  190. }
  191. /********************************************************
  192. * is_running_in_flash() - tell if currently running in
  193. * FLASH.
  194. *******************************************************/
  195. u32 is_running_in_flash(void)
  196. {
  197. if (get_base() < 4)
  198. return 1; /* in FLASH */
  199. return 0; /* running in SRAM or SDRAM */
  200. }
  201. /********************************************************
  202. * is_running_in_sram() - tell if currently running in
  203. * SRAM.
  204. *******************************************************/
  205. u32 is_running_in_sram(void)
  206. {
  207. if (get_base() == 4)
  208. return 1; /* in SRAM */
  209. return 0; /* running in FLASH or SDRAM */
  210. }
  211. /********************************************************
  212. * is_running_in_sdram() - tell if currently running in
  213. * SDRAM.
  214. *******************************************************/
  215. u32 is_running_in_sdram(void)
  216. {
  217. if (get_base() > 4)
  218. return 1; /* in SDRAM */
  219. return 0; /* running in SRAM or FLASH */
  220. }
  221. /***************************************************************
  222. * get_boot_type() - Is this an XIP type device or a stream one
  223. * bits 4-0 specify type. Bit 5 says mem/perif
  224. ***************************************************************/
  225. u32 get_boot_type(void)
  226. {
  227. return (readl(&ctrl_base->status) & SYSBOOT_MASK);
  228. }
  229. /*************************************************************
  230. * get_device_type(): tell if GP/HS/EMU/TST
  231. *************************************************************/
  232. u32 get_device_type(void)
  233. {
  234. return ((readl(&ctrl_base->status) & (DEVICE_MASK)) >> 8);
  235. }
  236. #ifdef CONFIG_DISPLAY_CPUINFO
  237. /**
  238. * Print CPU information
  239. */
  240. int print_cpuinfo (void)
  241. {
  242. char *cpu_family_s, *cpu_s, *sec_s, *max_clk;
  243. switch (get_cpu_family()) {
  244. case CPU_OMAP34XX:
  245. cpu_family_s = "OMAP";
  246. switch (get_cpu_type()) {
  247. case OMAP3503:
  248. cpu_s = "3503";
  249. break;
  250. case OMAP3515:
  251. cpu_s = "3515";
  252. break;
  253. case OMAP3525:
  254. cpu_s = "3525";
  255. break;
  256. case OMAP3530:
  257. cpu_s = "3530";
  258. break;
  259. default:
  260. cpu_s = "35XX";
  261. break;
  262. }
  263. if ((get_cpu_rev() >= CPU_3XX_ES31) &&
  264. (get_sku_id() == SKUID_CLK_720MHZ))
  265. max_clk = "720 mHz";
  266. else
  267. max_clk = "600 mHz";
  268. break;
  269. case CPU_AM35XX:
  270. cpu_family_s = "AM";
  271. switch (get_cpu_type()) {
  272. case AM3505:
  273. cpu_s = "3505";
  274. break;
  275. case AM3517:
  276. cpu_s = "3517";
  277. break;
  278. default:
  279. cpu_s = "35XX";
  280. break;
  281. }
  282. max_clk = "600 Mhz";
  283. break;
  284. case CPU_OMAP36XX:
  285. cpu_family_s = "OMAP";
  286. switch (get_cpu_type()) {
  287. case OMAP3730:
  288. cpu_s = "3630/3730";
  289. break;
  290. default:
  291. cpu_s = "36XX/37XX";
  292. break;
  293. }
  294. max_clk = "1 Ghz";
  295. break;
  296. default:
  297. cpu_family_s = "OMAP";
  298. cpu_s = "35XX";
  299. max_clk = "600 Mhz";
  300. }
  301. switch (get_device_type()) {
  302. case TST_DEVICE:
  303. sec_s = "TST";
  304. break;
  305. case EMU_DEVICE:
  306. sec_s = "EMU";
  307. break;
  308. case HS_DEVICE:
  309. sec_s = "HS";
  310. break;
  311. case GP_DEVICE:
  312. sec_s = "GP";
  313. break;
  314. default:
  315. sec_s = "?";
  316. }
  317. if (CPU_OMAP36XX == get_cpu_family())
  318. printf("%s%s-%s ES%s, CPU-OPP2, L3-165MHz, Max CPU Clock %s\n",
  319. cpu_family_s, cpu_s, sec_s,
  320. rev_s_37xx[get_cpu_rev()], max_clk);
  321. else
  322. printf("%s%s-%s ES%s, CPU-OPP2, L3-165MHz, Max CPU Clock %s\n",
  323. cpu_family_s, cpu_s, sec_s,
  324. rev_s[get_cpu_rev()], max_clk);
  325. return 0;
  326. }
  327. #endif /* CONFIG_DISPLAY_CPUINFO */