a4m072.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2004
  6. * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
  7. *
  8. * (C) Copyright 2010
  9. * Sergei Poselenov, Emcraft Systems, sposelenov@emcraft.com.
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <mpc5xxx.h>
  31. #include <pci.h>
  32. #include <asm/processor.h>
  33. #include <asm/io.h>
  34. #include <libfdt.h>
  35. #include <netdev.h>
  36. #include <led-display.h>
  37. #include <linux/err.h>
  38. #include "mt46v32m16.h"
  39. #ifndef CONFIG_SYS_RAMBOOT
  40. static void sdram_start (int hi_addr)
  41. {
  42. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  43. long control = SDRAM_CONTROL | hi_addr_bit;
  44. /* unlock mode register */
  45. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
  46. __asm__ volatile ("sync");
  47. /* precharge all banks */
  48. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
  49. __asm__ volatile ("sync");
  50. #if SDRAM_DDR
  51. /* set mode register: extended mode */
  52. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_EMODE);
  53. __asm__ volatile ("sync");
  54. /* set mode register: reset DLL */
  55. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE | 0x04000000);
  56. __asm__ volatile ("sync");
  57. #endif
  58. /* precharge all banks */
  59. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
  60. __asm__ volatile ("sync");
  61. /* auto refresh */
  62. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
  63. __asm__ volatile ("sync");
  64. /* set mode register */
  65. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
  66. __asm__ volatile ("sync");
  67. /* normal operation */
  68. out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
  69. __asm__ volatile ("sync");
  70. }
  71. #endif
  72. /*
  73. * ATTENTION: Although partially referenced initdram does NOT make real use
  74. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  75. * is something else than 0x00000000.
  76. */
  77. phys_size_t initdram (int board_type)
  78. {
  79. ulong dramsize = 0;
  80. uint svr, pvr;
  81. #ifndef CONFIG_SYS_RAMBOOT
  82. ulong test1, test2;
  83. /* setup SDRAM chip selects */
  84. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001e); /* 2GB at 0x0 */
  85. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000); /* disabled */
  86. __asm__ volatile ("sync");
  87. /* setup config registers */
  88. out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
  89. out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
  90. __asm__ volatile ("sync");
  91. #if SDRAM_DDR
  92. /* set tap delay */
  93. out_be32((void *)MPC5XXX_CDM_PORCFG, SDRAM_TAPDELAY);
  94. __asm__ volatile ("sync");
  95. #endif
  96. /* find RAM size using SDRAM CS0 only */
  97. sdram_start(0);
  98. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  99. sdram_start(1);
  100. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  101. if (test1 > test2) {
  102. sdram_start(0);
  103. dramsize = test1;
  104. } else {
  105. dramsize = test2;
  106. }
  107. /* memory smaller than 1MB is impossible */
  108. if (dramsize < (1 << 20)) {
  109. dramsize = 0;
  110. }
  111. /* set SDRAM CS0 size according to the amount of RAM found */
  112. if (dramsize > 0) {
  113. out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
  114. 0x13 + __builtin_ffs(dramsize >> 20) - 1);
  115. } else {
  116. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0); /* disabled */
  117. }
  118. #else /* CONFIG_SYS_RAMBOOT */
  119. /* retrieve size of memory connected to SDRAM CS0 */
  120. dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
  121. if (dramsize >= 0x13) {
  122. dramsize = (1 << (dramsize - 0x13)) << 20;
  123. } else {
  124. dramsize = 0;
  125. }
  126. #endif /* CONFIG_SYS_RAMBOOT */
  127. /*
  128. * On MPC5200B we need to set the special configuration delay in the
  129. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  130. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  131. *
  132. * "The SDelay should be written to a value of 0x00000004. It is
  133. * required to account for changes caused by normal wafer processing
  134. * parameters."
  135. */
  136. svr = get_svr();
  137. pvr = get_pvr();
  138. if ((SVR_MJREV(svr) >= 2) &&
  139. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  140. out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
  141. __asm__ volatile ("sync");
  142. }
  143. return dramsize;
  144. }
  145. int checkboard (void)
  146. {
  147. puts ("Board: A4M072\n");
  148. return 0;
  149. }
  150. #ifdef CONFIG_PCI
  151. static struct pci_controller hose;
  152. extern void pci_mpc5xxx_init(struct pci_controller *);
  153. void pci_init_board(void)
  154. {
  155. pci_mpc5xxx_init(&hose);
  156. }
  157. #endif
  158. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  159. void
  160. ft_board_setup(void *blob, bd_t *bd)
  161. {
  162. ft_cpu_setup(blob, bd);
  163. }
  164. #endif
  165. int board_eth_init(bd_t *bis)
  166. {
  167. int rv, num_if = 0;
  168. /* Initialize TSECs first */
  169. if ((rv = cpu_eth_init(bis)) >= 0)
  170. num_if += rv;
  171. else
  172. printf("ERROR: failed to initialize FEC.\n");
  173. if ((rv = pci_eth_init(bis)) >= 0)
  174. num_if += rv;
  175. else
  176. printf("ERROR: failed to initialize PCI Ethernet.\n");
  177. return num_if;
  178. }
  179. /*
  180. * Miscellaneous late-boot configurations
  181. *
  182. * Initialize EEPROM write-protect GPIO pin.
  183. */
  184. int misc_init_r(void)
  185. {
  186. #if defined(CONFIG_SYS_EEPROM_WREN)
  187. /* Enable GPIO pin */
  188. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, CONFIG_SYS_EEPROM_WP);
  189. /* Set direction, output */
  190. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, CONFIG_SYS_EEPROM_WP);
  191. /* De-assert write enable */
  192. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP);
  193. #endif
  194. return 0;
  195. }
  196. #if defined(CONFIG_SYS_EEPROM_WREN)
  197. /* Input: <dev_addr> I2C address of EEPROM device to enable.
  198. * <state> -1: deliver current state
  199. * 0: disable write
  200. * 1: enable write
  201. * Returns: -1: wrong device address
  202. * 0: dis-/en- able done
  203. * 0/1: current state if <state> was -1.
  204. */
  205. int eeprom_write_enable (unsigned dev_addr, int state)
  206. {
  207. if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) {
  208. return -1;
  209. } else {
  210. switch (state) {
  211. case 1:
  212. /* Enable write access */
  213. clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP);
  214. state = 0;
  215. break;
  216. case 0:
  217. /* Disable write access */
  218. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP);
  219. state = 0;
  220. break;
  221. default:
  222. /* Read current status back. */
  223. state = (0 == (in_be32((void *)MPC5XXX_WU_GPIO_DATA_O) &
  224. CONFIG_SYS_EEPROM_WP));
  225. break;
  226. }
  227. }
  228. return state;
  229. }
  230. #endif
  231. #ifdef CONFIG_CMD_DISPLAY
  232. #define DISPLAY_BUF_SIZE 2
  233. static u8 display_buf[DISPLAY_BUF_SIZE];
  234. static u8 display_putc_pos;
  235. static u8 display_out_pos;
  236. void display_set(int cmd) {
  237. if (cmd & DISPLAY_CLEAR) {
  238. display_buf[0] = display_buf[1] = 0;
  239. }
  240. if (cmd & DISPLAY_HOME) {
  241. display_putc_pos = 0;
  242. }
  243. }
  244. #define SEG_A (1<<0)
  245. #define SEG_B (1<<1)
  246. #define SEG_C (1<<2)
  247. #define SEG_D (1<<3)
  248. #define SEG_E (1<<4)
  249. #define SEG_F (1<<5)
  250. #define SEG_G (1<<6)
  251. #define SEG_P (1<<7)
  252. #define SEG__ 0
  253. /*
  254. * +- A -+
  255. * | |
  256. * F B
  257. * | |
  258. * +- G -+
  259. * | |
  260. * E C
  261. * | |
  262. * +- D -+ P
  263. *
  264. * 0..9 index 0..9
  265. * A..Z index 10..35
  266. * - index 36
  267. * _ index 37
  268. * . index 38
  269. */
  270. #define SYMBOL_DASH (36)
  271. #define SYMBOL_UNDERLINE (37)
  272. #define SYMBOL_DOT (38)
  273. static u8 display_char2seg7_tbl[]=
  274. {
  275. SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, /* 0 */
  276. SEG_B | SEG_C, /* 1 */
  277. SEG_A | SEG_B | SEG_D | SEG_E | SEG_G, /* 2 */
  278. SEG_A | SEG_B | SEG_C | SEG_D | SEG_G, /* 3 */
  279. SEG_B | SEG_C | SEG_F | SEG_G, /* 4 */
  280. SEG_A | SEG_C | SEG_D | SEG_F | SEG_G, /* 5 */
  281. SEG_A | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, /* 6 */
  282. SEG_A | SEG_B | SEG_C, /* 7 */
  283. SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, /* 8 */
  284. SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, /* 9 */
  285. SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, /* A */
  286. SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, /* b */
  287. SEG_A | SEG_D | SEG_E | SEG_F, /* C */
  288. SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, /* d */
  289. SEG_A | SEG_D | SEG_E | SEG_F | SEG_G, /* E */
  290. SEG_A | SEG_E | SEG_F | SEG_G, /* F */
  291. 0, /* g - not displayed */
  292. SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, /* H */
  293. SEG_B | SEG_C, /* I */
  294. 0, /* J - not displayed */
  295. 0, /* K - not displayed */
  296. SEG_D | SEG_E | SEG_F, /* L */
  297. 0, /* m - not displayed */
  298. 0, /* n - not displayed */
  299. SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, /* O */
  300. SEG_A | SEG_B | SEG_E | SEG_F | SEG_G, /* P */
  301. 0, /* q - not displayed */
  302. 0, /* r - not displayed */
  303. SEG_A | SEG_C | SEG_D | SEG_F | SEG_G, /* S */
  304. SEG_D | SEG_E | SEG_F | SEG_G, /* t */
  305. SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, /* U */
  306. 0, /* V - not displayed */
  307. 0, /* w - not displayed */
  308. 0, /* X - not displayed */
  309. SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, /* Y */
  310. 0, /* Z - not displayed */
  311. SEG_G, /* - */
  312. SEG_D, /* _ */
  313. SEG_P /* . */
  314. };
  315. /* Convert char to the LED segments representation */
  316. static u8 display_char2seg7(char c)
  317. {
  318. u8 val = 0;
  319. if (c >= '0' && c <= '9')
  320. c -= '0';
  321. else if (c >= 'a' && c <= 'z')
  322. c -= 'a' - 10;
  323. else if (c >= 'A' && c <= 'Z')
  324. c -= 'A' - 10;
  325. else if (c == '-')
  326. c = SYMBOL_DASH;
  327. else if (c == '_')
  328. c = SYMBOL_UNDERLINE;
  329. else if (c == '.')
  330. c = SYMBOL_DOT;
  331. else
  332. c = ' '; /* display unsupported symbols as space */
  333. if (c != ' ')
  334. val = display_char2seg7_tbl[(int)c];
  335. return val;
  336. }
  337. int display_putc(char c)
  338. {
  339. if (display_putc_pos >= DISPLAY_BUF_SIZE)
  340. return -1;
  341. display_buf[display_putc_pos++] = display_char2seg7(c);
  342. /* one-symbol message should be steady */
  343. if (display_putc_pos == 1)
  344. display_buf[display_putc_pos] = display_char2seg7(c);
  345. return c;
  346. }
  347. /*
  348. * Flush current symbol to the LED display hardware
  349. */
  350. static inline void display_flush(void)
  351. {
  352. u32 val = display_buf[display_out_pos];
  353. val |= (val << 8) | (val << 16) | (val << 24);
  354. out_be32((void *)CONFIG_SYS_DISP_CHR_RAM, val);
  355. }
  356. /*
  357. * Output contents of the software display buffer to the LED display every 0.5s
  358. */
  359. void board_show_activity(ulong timestamp)
  360. {
  361. static ulong last;
  362. static u8 once;
  363. if (!once || (timestamp - last >= (CONFIG_SYS_HZ / 2))) {
  364. display_flush();
  365. display_out_pos ^= 1;
  366. last = timestamp;
  367. once = 1;
  368. }
  369. }
  370. /*
  371. * Empty fake function
  372. */
  373. void show_activity(int arg)
  374. {
  375. }
  376. #endif
  377. #if defined (CONFIG_SHOW_BOOT_PROGRESS)
  378. static int a4m072_status2code(int status, char *buf)
  379. {
  380. char c = 0;
  381. if (((status > 0) && (status <= 8)) ||
  382. ((status >= 100) && (status <= 108)) ||
  383. ((status < 0) && (status >= -9)) ||
  384. (status == -100) || (status == -101) ||
  385. ((status <= -103) && (status >= -113))) {
  386. c = '5';
  387. } else if (((status >= 9) && (status <= 14)) ||
  388. ((status >= 120) && (status <= 123)) ||
  389. ((status >= 125) && (status <= 129)) ||
  390. ((status >= -13) && (status <= -10)) ||
  391. (status == -120) || (status == -122) ||
  392. ((status <= -124) && (status >= -127)) ||
  393. (status == -129)) {
  394. c = '8';
  395. } else if (status == 15) {
  396. c = '9';
  397. } else if ((status <= -30) && (status >= -32)) {
  398. c = 'A';
  399. } else if (((status <= -35) && (status >= -40)) ||
  400. ((status <= -42) && (status >= -51)) ||
  401. ((status <= -53) && (status >= -58)) ||
  402. (status == -64) ||
  403. ((status <= -80) && (status >= -83)) ||
  404. (status == -130) || (status == -140) ||
  405. (status == -150)) {
  406. c = 'B';
  407. }
  408. if (c == 0)
  409. return -EINVAL;
  410. buf[0] = (status < 0) ? '-' : c;
  411. buf[1] = c;
  412. return 0;
  413. }
  414. void show_boot_progress(int status)
  415. {
  416. char buf[2];
  417. if (a4m072_status2code(status, buf) < 0)
  418. return;
  419. display_putc(buf[0]);
  420. display_putc(buf[1]);
  421. display_set(DISPLAY_HOME);
  422. display_out_pos = 0; /* reset output position */
  423. /* we want to flush status 15 now */
  424. if (status == 15)
  425. display_flush();
  426. }
  427. #endif