a4m072.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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 "mt46v32m16.h"
  38. #ifndef CONFIG_SYS_RAMBOOT
  39. static void sdram_start (int hi_addr)
  40. {
  41. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  42. long control = SDRAM_CONTROL | hi_addr_bit;
  43. /* unlock mode register */
  44. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
  45. __asm__ volatile ("sync");
  46. /* precharge all banks */
  47. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
  48. __asm__ volatile ("sync");
  49. #if SDRAM_DDR
  50. /* set mode register: extended mode */
  51. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_EMODE);
  52. __asm__ volatile ("sync");
  53. /* set mode register: reset DLL */
  54. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE | 0x04000000);
  55. __asm__ volatile ("sync");
  56. #endif
  57. /* precharge all banks */
  58. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
  59. __asm__ volatile ("sync");
  60. /* auto refresh */
  61. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
  62. __asm__ volatile ("sync");
  63. /* set mode register */
  64. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
  65. __asm__ volatile ("sync");
  66. /* normal operation */
  67. out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
  68. __asm__ volatile ("sync");
  69. }
  70. #endif
  71. /*
  72. * ATTENTION: Although partially referenced initdram does NOT make real use
  73. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  74. * is something else than 0x00000000.
  75. */
  76. phys_size_t initdram (int board_type)
  77. {
  78. ulong dramsize = 0;
  79. uint svr, pvr;
  80. #ifndef CONFIG_SYS_RAMBOOT
  81. ulong test1, test2;
  82. /* setup SDRAM chip selects */
  83. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001e); /* 2GB at 0x0 */
  84. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000); /* disabled */
  85. __asm__ volatile ("sync");
  86. /* setup config registers */
  87. out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
  88. out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
  89. __asm__ volatile ("sync");
  90. #if SDRAM_DDR
  91. /* set tap delay */
  92. out_be32((void *)MPC5XXX_CDM_PORCFG, SDRAM_TAPDELAY);
  93. __asm__ volatile ("sync");
  94. #endif
  95. /* find RAM size using SDRAM CS0 only */
  96. sdram_start(0);
  97. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  98. sdram_start(1);
  99. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  100. if (test1 > test2) {
  101. sdram_start(0);
  102. dramsize = test1;
  103. } else {
  104. dramsize = test2;
  105. }
  106. /* memory smaller than 1MB is impossible */
  107. if (dramsize < (1 << 20)) {
  108. dramsize = 0;
  109. }
  110. /* set SDRAM CS0 size according to the amount of RAM found */
  111. if (dramsize > 0) {
  112. out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
  113. 0x13 + __builtin_ffs(dramsize >> 20) - 1);
  114. } else {
  115. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0); /* disabled */
  116. }
  117. #else /* CONFIG_SYS_RAMBOOT */
  118. /* retrieve size of memory connected to SDRAM CS0 */
  119. dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
  120. if (dramsize >= 0x13) {
  121. dramsize = (1 << (dramsize - 0x13)) << 20;
  122. } else {
  123. dramsize = 0;
  124. }
  125. #endif /* CONFIG_SYS_RAMBOOT */
  126. /*
  127. * On MPC5200B we need to set the special configuration delay in the
  128. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  129. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  130. *
  131. * "The SDelay should be written to a value of 0x00000004. It is
  132. * required to account for changes caused by normal wafer processing
  133. * parameters."
  134. */
  135. svr = get_svr();
  136. pvr = get_pvr();
  137. if ((SVR_MJREV(svr) >= 2) &&
  138. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  139. out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
  140. __asm__ volatile ("sync");
  141. }
  142. return dramsize;
  143. }
  144. int checkboard (void)
  145. {
  146. puts ("Board: A4M072\n");
  147. return 0;
  148. }
  149. #ifdef CONFIG_PCI
  150. static struct pci_controller hose;
  151. extern void pci_mpc5xxx_init(struct pci_controller *);
  152. void pci_init_board(void)
  153. {
  154. pci_mpc5xxx_init(&hose);
  155. }
  156. #endif
  157. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  158. void
  159. ft_board_setup(void *blob, bd_t *bd)
  160. {
  161. ft_cpu_setup(blob, bd);
  162. }
  163. #endif
  164. int board_eth_init(bd_t *bis)
  165. {
  166. int rv, num_if = 0;
  167. /* Initialize TSECs first */
  168. if ((rv = cpu_eth_init(bis)) >= 0)
  169. num_if += rv;
  170. else
  171. printf("ERROR: failed to initialize FEC.\n");
  172. if ((rv = pci_eth_init(bis)) >= 0)
  173. num_if += rv;
  174. else
  175. printf("ERROR: failed to initialize PCI Ethernet.\n");
  176. return num_if;
  177. }
  178. /*
  179. * Miscellaneous late-boot configurations
  180. *
  181. * Initialize EEPROM write-protect GPIO pin.
  182. */
  183. int misc_init_r(void)
  184. {
  185. #if defined(CONFIG_SYS_EEPROM_WREN)
  186. /* Enable GPIO pin */
  187. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, CONFIG_SYS_EEPROM_WP);
  188. /* Set direction, output */
  189. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, CONFIG_SYS_EEPROM_WP);
  190. /* De-assert write enable */
  191. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP);
  192. #endif
  193. return 0;
  194. }
  195. #if defined(CONFIG_SYS_EEPROM_WREN)
  196. /* Input: <dev_addr> I2C address of EEPROM device to enable.
  197. * <state> -1: deliver current state
  198. * 0: disable write
  199. * 1: enable write
  200. * Returns: -1: wrong device address
  201. * 0: dis-/en- able done
  202. * 0/1: current state if <state> was -1.
  203. */
  204. int eeprom_write_enable (unsigned dev_addr, int state)
  205. {
  206. if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) {
  207. return -1;
  208. } else {
  209. switch (state) {
  210. case 1:
  211. /* Enable write access */
  212. clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP);
  213. state = 0;
  214. break;
  215. case 0:
  216. /* Disable write access */
  217. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP);
  218. state = 0;
  219. break;
  220. default:
  221. /* Read current status back. */
  222. state = (0 == (in_be32((void *)MPC5XXX_WU_GPIO_DATA_O) &
  223. CONFIG_SYS_EEPROM_WP));
  224. break;
  225. }
  226. }
  227. return state;
  228. }
  229. #endif
  230. #ifdef CONFIG_CMD_DISPLAY
  231. #define DISPLAY_BUF_SIZE 2
  232. static u8 display_buf[DISPLAY_BUF_SIZE];
  233. static u8 display_putc_pos;
  234. static u8 display_out_pos;
  235. static u8 display_dot_enable;
  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. if (cmd & DISPLAY_MARK) {
  244. display_dot_enable = 1;
  245. } else {
  246. display_dot_enable = 0;
  247. }
  248. }
  249. #define SEG_A (1<<0)
  250. #define SEG_B (1<<1)
  251. #define SEG_C (1<<2)
  252. #define SEG_D (1<<3)
  253. #define SEG_E (1<<4)
  254. #define SEG_F (1<<5)
  255. #define SEG_G (1<<6)
  256. #define SEG_P (1<<7)
  257. #define SEG__ 0
  258. /*
  259. * +- A -+
  260. * | |
  261. * F B
  262. * | |
  263. * +- G -+
  264. * | |
  265. * E C
  266. * | |
  267. * +- D -+ P
  268. *
  269. * 0..9 index 0..9
  270. * A..Z index 10..35
  271. * - index 36
  272. * _ index 37
  273. */
  274. #define SYMBOL_DASH (36)
  275. #define SYMBOL_UNDERLINE (37)
  276. static u8 display_char2seg7_tbl[]=
  277. {
  278. SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, /* 0 */
  279. SEG_B | SEG_C, /* 1 */
  280. SEG_A | SEG_B | SEG_D | SEG_E | SEG_G, /* 2 */
  281. SEG_A | SEG_B | SEG_C | SEG_D | SEG_G, /* 3 */
  282. SEG_B | SEG_C | SEG_F | SEG_G, /* 4 */
  283. SEG_A | SEG_C | SEG_D | SEG_F | SEG_G, /* 5 */
  284. SEG_A | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, /* 6 */
  285. SEG_A | SEG_B | SEG_C, /* 7 */
  286. SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, /* 8 */
  287. SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, /* 9 */
  288. SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, /* A */
  289. SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, /* b */
  290. SEG_A | SEG_D | SEG_E | SEG_F, /* C */
  291. SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, /* d */
  292. SEG_A | SEG_D | SEG_E | SEG_F | SEG_G, /* E */
  293. SEG_A | SEG_E | SEG_F | SEG_G, /* F */
  294. SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, /* g */
  295. SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, /* H */
  296. SEG_E | SEG_F, /* I */
  297. SEG_B | SEG_C | SEG_D | SEG_E, /* J */
  298. SEG_A, /* K - special 1 */
  299. SEG_D | SEG_E | SEG_F, /* L */
  300. SEG_B, /* m - special 2 */
  301. SEG_C | SEG_E | SEG_G, /* n */
  302. SEG_C | SEG_D | SEG_E | SEG_G, /* o */
  303. SEG_A | SEG_B | SEG_E | SEG_F | SEG_G, /* P */
  304. SEG_A | SEG_B | SEG_C | SEG_F | SEG_G, /* q */
  305. SEG_E | SEG_G, /* r */
  306. SEG_A | SEG_C | SEG_D | SEG_F | SEG_G, /* S */
  307. SEG_D | SEG_E | SEG_F | SEG_G, /* t */
  308. SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, /* U */
  309. SEG_C | SEG_D | SEG_E | SEG_F, /* V */
  310. SEG_C, /* w - special 3 */
  311. SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, /* X */
  312. SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, /* Y */
  313. SEG_A | SEG_B | SEG_D | SEG_E | SEG_G, /* Z */
  314. SEG_G, /* - */
  315. SEG_D /* _ */
  316. };
  317. /* Convert char to the LED segments representation */
  318. static u8 display_char2seg7(char c)
  319. {
  320. u8 val = 0;
  321. if (c >= '0' && c <= '9')
  322. c -= '0';
  323. else if (c >= 'a' && c <= 'z')
  324. c -= 'a' - 10;
  325. else if (c >= 'A' && c <= 'Z')
  326. c -= 'A' - 10;
  327. else if (c == '-')
  328. c = SYMBOL_DASH;
  329. else if ((c == '_') || (c == '.'))
  330. c = SYMBOL_UNDERLINE;
  331. else
  332. c = ' '; /* display unsupported symbols as space */
  333. if (c != ' ')
  334. val = display_char2seg7_tbl[(int)c];
  335. /* Handle DP LED here */
  336. if (display_dot_enable) {
  337. val |= SEG_P;
  338. }
  339. return val;
  340. }
  341. static inline int display_putc_nomark(char c)
  342. {
  343. if (display_putc_pos >= DISPLAY_BUF_SIZE)
  344. return -1;
  345. display_buf[display_putc_pos++] = display_char2seg7(c);
  346. /* one-symbol message should be steady */
  347. if (display_putc_pos == 1)
  348. display_buf[display_putc_pos] = display_char2seg7(c);
  349. return c;
  350. }
  351. int display_putc(char c)
  352. {
  353. /* Mark the codes from the "display" command with the DP LED */
  354. display_set(DISPLAY_MARK);
  355. return display_putc_nomark(c);
  356. }
  357. /*
  358. * Output content of the software display buffer to the LED display every 0.5s
  359. */
  360. void board_show_activity(ulong timestamp)
  361. {
  362. static ulong last;
  363. static u8 once;
  364. u32 val;
  365. if (!once || (timestamp - last >= (CONFIG_SYS_HZ / 2))) {
  366. val = display_buf[display_out_pos];
  367. val |= (val << 8) | (val << 16) | (val << 24);
  368. out_be32((void *)CONFIG_SYS_DISP_CHR_RAM, val);
  369. display_out_pos ^= 1;
  370. last = timestamp;
  371. once = 1;
  372. }
  373. }
  374. /*
  375. * Empty fake function
  376. */
  377. void show_activity(int arg)
  378. {
  379. }
  380. #endif