a4m072.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. static u8 display_dot_enable;
  237. void display_set(int cmd) {
  238. if (cmd & DISPLAY_CLEAR) {
  239. display_buf[0] = display_buf[1] = 0;
  240. }
  241. if (cmd & DISPLAY_HOME) {
  242. display_putc_pos = 0;
  243. }
  244. if (cmd & DISPLAY_MARK) {
  245. display_dot_enable = 1;
  246. } else {
  247. display_dot_enable = 0;
  248. }
  249. }
  250. #define SEG_A (1<<0)
  251. #define SEG_B (1<<1)
  252. #define SEG_C (1<<2)
  253. #define SEG_D (1<<3)
  254. #define SEG_E (1<<4)
  255. #define SEG_F (1<<5)
  256. #define SEG_G (1<<6)
  257. #define SEG_P (1<<7)
  258. #define SEG__ 0
  259. /*
  260. * +- A -+
  261. * | |
  262. * F B
  263. * | |
  264. * +- G -+
  265. * | |
  266. * E C
  267. * | |
  268. * +- D -+ P
  269. *
  270. * 0..9 index 0..9
  271. * A..Z index 10..35
  272. * - index 36
  273. * _ index 37
  274. */
  275. #define SYMBOL_DASH (36)
  276. #define SYMBOL_UNDERLINE (37)
  277. static u8 display_char2seg7_tbl[]=
  278. {
  279. SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, /* 0 */
  280. SEG_B | SEG_C, /* 1 */
  281. SEG_A | SEG_B | SEG_D | SEG_E | SEG_G, /* 2 */
  282. SEG_A | SEG_B | SEG_C | SEG_D | SEG_G, /* 3 */
  283. SEG_B | SEG_C | SEG_F | SEG_G, /* 4 */
  284. SEG_A | SEG_C | SEG_D | SEG_F | SEG_G, /* 5 */
  285. SEG_A | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, /* 6 */
  286. SEG_A | SEG_B | SEG_C, /* 7 */
  287. SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, /* 8 */
  288. SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, /* 9 */
  289. SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, /* A */
  290. SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, /* b */
  291. SEG_A | SEG_D | SEG_E | SEG_F, /* C */
  292. SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, /* d */
  293. SEG_A | SEG_D | SEG_E | SEG_F | SEG_G, /* E */
  294. SEG_A | SEG_E | SEG_F | SEG_G, /* F */
  295. SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, /* g */
  296. SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, /* H */
  297. SEG_E | SEG_F, /* I */
  298. SEG_B | SEG_C | SEG_D | SEG_E, /* J */
  299. SEG_A, /* K - special 1 */
  300. SEG_D | SEG_E | SEG_F, /* L */
  301. SEG_B, /* m - special 2 */
  302. SEG_C | SEG_E | SEG_G, /* n */
  303. SEG_C | SEG_D | SEG_E | SEG_G, /* o */
  304. SEG_A | SEG_B | SEG_E | SEG_F | SEG_G, /* P */
  305. SEG_A | SEG_B | SEG_C | SEG_F | SEG_G, /* q */
  306. SEG_E | SEG_G, /* r */
  307. SEG_A | SEG_C | SEG_D | SEG_F | SEG_G, /* S */
  308. SEG_D | SEG_E | SEG_F | SEG_G, /* t */
  309. SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, /* U */
  310. SEG_C | SEG_D | SEG_E | SEG_F, /* V */
  311. SEG_C, /* w - special 3 */
  312. SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, /* X */
  313. SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, /* Y */
  314. SEG_A | SEG_B | SEG_D | SEG_E | SEG_G, /* Z */
  315. SEG_G, /* - */
  316. SEG_D /* _ */
  317. };
  318. /* Convert char to the LED segments representation */
  319. static u8 display_char2seg7(char c)
  320. {
  321. u8 val = 0;
  322. if (c >= '0' && c <= '9')
  323. c -= '0';
  324. else if (c >= 'a' && c <= 'z')
  325. c -= 'a' - 10;
  326. else if (c >= 'A' && c <= 'Z')
  327. c -= 'A' - 10;
  328. else if (c == '-')
  329. c = SYMBOL_DASH;
  330. else if ((c == '_') || (c == '.'))
  331. c = SYMBOL_UNDERLINE;
  332. else
  333. c = ' '; /* display unsupported symbols as space */
  334. if (c != ' ')
  335. val = display_char2seg7_tbl[(int)c];
  336. /* Handle DP LED here */
  337. if (display_dot_enable) {
  338. val |= SEG_P;
  339. }
  340. return val;
  341. }
  342. static inline int display_putc_nomark(char c)
  343. {
  344. if (display_putc_pos >= DISPLAY_BUF_SIZE)
  345. return -1;
  346. display_buf[display_putc_pos++] = display_char2seg7(c);
  347. /* one-symbol message should be steady */
  348. if (display_putc_pos == 1)
  349. display_buf[display_putc_pos] = display_char2seg7(c);
  350. return c;
  351. }
  352. int display_putc(char c)
  353. {
  354. /* Mark the codes from the "display" command with the DP LED */
  355. display_set(DISPLAY_MARK);
  356. return display_putc_nomark(c);
  357. }
  358. /*
  359. * Flush current symbol to the LED display hardware
  360. */
  361. static inline void display_flush(void)
  362. {
  363. u32 val = display_buf[display_out_pos];
  364. val |= (val << 8) | (val << 16) | (val << 24);
  365. out_be32((void *)CONFIG_SYS_DISP_CHR_RAM, val);
  366. }
  367. /*
  368. * Output contents of the software display buffer to the LED display every 0.5s
  369. */
  370. void board_show_activity(ulong timestamp)
  371. {
  372. static ulong last;
  373. static u8 once;
  374. if (!once || (timestamp - last >= (CONFIG_SYS_HZ / 2))) {
  375. display_flush();
  376. display_out_pos ^= 1;
  377. last = timestamp;
  378. once = 1;
  379. }
  380. }
  381. /*
  382. * Empty fake function
  383. */
  384. void show_activity(int arg)
  385. {
  386. }
  387. #endif
  388. #if defined (CONFIG_SHOW_BOOT_PROGRESS)
  389. static int a4m072_status2code(int status, char *buf)
  390. {
  391. char c = 0;
  392. if (((status > 0) && (status <= 8)) ||
  393. ((status >= 100) && (status <= 108)) ||
  394. ((status < 0) && (status >= -9)) ||
  395. (status == -100) || (status == -101) ||
  396. ((status <= -103) && (status >= -113))) {
  397. c = '5';
  398. } else if (((status >= 9) && (status <= 14)) ||
  399. ((status >= 120) && (status <= 123)) ||
  400. ((status >= 125) && (status <= 129)) ||
  401. ((status >= -13) && (status <= -10)) ||
  402. (status == -120) || (status == -122) ||
  403. ((status <= -124) && (status >= -127)) ||
  404. (status == -129)) {
  405. c = '8';
  406. } else if (status == 15) {
  407. c = '9';
  408. } else if ((status <= -30) && (status >= -32)) {
  409. c = 'A';
  410. } else if (((status <= -35) && (status >= -40)) ||
  411. ((status <= -42) && (status >= -51)) ||
  412. ((status <= -53) && (status >= -58)) ||
  413. (status == -64) ||
  414. ((status <= -80) && (status >= -83)) ||
  415. (status == -130) || (status == -140) ||
  416. (status == -150)) {
  417. c = 'B';
  418. }
  419. if (c == 0)
  420. return -EINVAL;
  421. buf[0] = (status < 0) ? '-' : c;
  422. buf[1] = c;
  423. return 0;
  424. }
  425. void show_boot_progress(int status)
  426. {
  427. char buf[2];
  428. if (a4m072_status2code(status, buf) < 0)
  429. return;
  430. display_set(0); /* Clear DP Led */
  431. display_putc_nomark(buf[0]);
  432. display_putc_nomark(buf[1]);
  433. display_set(DISPLAY_HOME);
  434. display_out_pos = 0; /* reset output position */
  435. /* we want to flush status 15 now */
  436. if (status == 15)
  437. display_flush();
  438. }
  439. #endif