tqm8xx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. /*
  2. * (C) Copyright 2000-2008
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <hwconfig.h>
  25. #include <mpc8xx.h>
  26. #ifdef CONFIG_PS2MULT
  27. #include <ps2mult.h>
  28. #endif
  29. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  30. #include <libfdt.h>
  31. #endif
  32. extern flash_info_t flash_info[]; /* FLASH chips info */
  33. DECLARE_GLOBAL_DATA_PTR;
  34. static long int dram_size (long int, long int *, long int);
  35. #define _NOT_USED_ 0xFFFFFFFF
  36. /* UPM initialization table for SDRAM: 40, 50, 66 MHz CLKOUT @ CAS latency 2, tWR=2 */
  37. const uint sdram_table[] =
  38. {
  39. /*
  40. * Single Read. (Offset 0 in UPMA RAM)
  41. */
  42. 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
  43. 0x1FF5FC47, /* last */
  44. /*
  45. * SDRAM Initialization (offset 5 in UPMA RAM)
  46. *
  47. * This is no UPM entry point. The following definition uses
  48. * the remaining space to establish an initialization
  49. * sequence, which is executed by a RUN command.
  50. *
  51. */
  52. 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
  53. /*
  54. * Burst Read. (Offset 8 in UPMA RAM)
  55. */
  56. 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
  57. 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
  58. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  59. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  60. /*
  61. * Single Write. (Offset 18 in UPMA RAM)
  62. */
  63. 0x1F0DFC04, 0xEEABBC00, 0x11B77C04, 0xEFFAFC44,
  64. 0x1FF5FC47, /* last */
  65. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  66. /*
  67. * Burst Write. (Offset 20 in UPMA RAM)
  68. */
  69. 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
  70. 0xF0AFFC00, 0xF0AFFC04, 0xE1BAFC44, 0x1FF5FC47, /* last */
  71. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  72. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  73. /*
  74. * Refresh (Offset 30 in UPMA RAM)
  75. */
  76. 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
  77. 0xFFFFFC84, 0xFFFFFC07, /* last */
  78. _NOT_USED_, _NOT_USED_,
  79. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  80. /*
  81. * Exception. (Offset 3c in UPMA RAM)
  82. */
  83. 0xFFFFFC07, /* last */
  84. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  85. };
  86. /* ------------------------------------------------------------------------- */
  87. /*
  88. * Check Board Identity:
  89. *
  90. * Test TQ ID string (TQM8xx...)
  91. * If present, check for "L" type (no second DRAM bank),
  92. * otherwise "L" type is assumed as default.
  93. *
  94. * Set board_type to 'L' for "L" type, 'M' for "M" type, 0 else.
  95. */
  96. int checkboard (void)
  97. {
  98. char *s = getenv ("serial#");
  99. puts ("Board: ");
  100. if (!s || strncmp (s, "TQM8", 4)) {
  101. puts ("### No HW ID - assuming TQM8xxL\n");
  102. return (0);
  103. }
  104. if ((*(s + 6) == 'L')) { /* a TQM8xxL type */
  105. gd->board_type = 'L';
  106. }
  107. if ((*(s + 6) == 'M')) { /* a TQM8xxM type */
  108. gd->board_type = 'M';
  109. }
  110. if ((*(s + 6) == 'D')) { /* a TQM885D type */
  111. gd->board_type = 'D';
  112. }
  113. for (; *s; ++s) {
  114. if (*s == ' ')
  115. break;
  116. putc (*s);
  117. }
  118. #ifdef CONFIG_VIRTLAB2
  119. puts (" (Virtlab2)");
  120. #endif
  121. putc ('\n');
  122. return (0);
  123. }
  124. /* ------------------------------------------------------------------------- */
  125. phys_size_t initdram (int board_type)
  126. {
  127. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  128. volatile memctl8xx_t *memctl = &immap->im_memctl;
  129. long int size8, size9, size10;
  130. long int size_b0 = 0;
  131. long int size_b1 = 0;
  132. upmconfig (UPMA, (uint *) sdram_table,
  133. sizeof (sdram_table) / sizeof (uint));
  134. /*
  135. * Preliminary prescaler for refresh (depends on number of
  136. * banks): This value is selected for four cycles every 62.4 us
  137. * with two SDRAM banks or four cycles every 31.2 us with one
  138. * bank. It will be adjusted after memory sizing.
  139. */
  140. memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_8K;
  141. /*
  142. * The following value is used as an address (i.e. opcode) for
  143. * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If
  144. * the port size is 32bit the SDRAM does NOT "see" the lower two
  145. * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for
  146. * MICRON SDRAMs:
  147. * -> 0 00 010 0 010
  148. * | | | | +- Burst Length = 4
  149. * | | | +----- Burst Type = Sequential
  150. * | | +------- CAS Latency = 2
  151. * | +----------- Operating Mode = Standard
  152. * +-------------- Write Burst Mode = Programmed Burst Length
  153. */
  154. memctl->memc_mar = 0x00000088;
  155. /*
  156. * Map controller banks 2 and 3 to the SDRAM banks 2 and 3 at
  157. * preliminary addresses - these have to be modified after the
  158. * SDRAM size has been determined.
  159. */
  160. memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
  161. memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
  162. #ifndef CONFIG_CAN_DRIVER
  163. if ((board_type != 'L') &&
  164. (board_type != 'M') &&
  165. (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
  166. memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
  167. memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
  168. }
  169. #endif /* CONFIG_CAN_DRIVER */
  170. memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
  171. udelay (200);
  172. /* perform SDRAM initializsation sequence */
  173. memctl->memc_mcr = 0x80004105; /* SDRAM bank 0 */
  174. udelay (1);
  175. memctl->memc_mcr = 0x80004230; /* SDRAM bank 0 - execute twice */
  176. udelay (1);
  177. #ifndef CONFIG_CAN_DRIVER
  178. if ((board_type != 'L') &&
  179. (board_type != 'M') &&
  180. (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
  181. memctl->memc_mcr = 0x80006105; /* SDRAM bank 1 */
  182. udelay (1);
  183. memctl->memc_mcr = 0x80006230; /* SDRAM bank 1 - execute twice */
  184. udelay (1);
  185. }
  186. #endif /* CONFIG_CAN_DRIVER */
  187. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  188. udelay (1000);
  189. /*
  190. * Check Bank 0 Memory Size for re-configuration
  191. *
  192. * try 8 column mode
  193. */
  194. size8 = dram_size (CONFIG_SYS_MAMR_8COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
  195. debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size8 >> 20);
  196. udelay (1000);
  197. /*
  198. * try 9 column mode
  199. */
  200. size9 = dram_size (CONFIG_SYS_MAMR_9COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
  201. debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size9 >> 20);
  202. udelay(1000);
  203. #if defined(CONFIG_SYS_MAMR_10COL)
  204. /*
  205. * try 10 column mode
  206. */
  207. size10 = dram_size (CONFIG_SYS_MAMR_10COL, SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
  208. debug ("SDRAM Bank 0 in 10 column mode: %ld MB\n", size10 >> 20);
  209. #else
  210. size10 = 0;
  211. #endif /* CONFIG_SYS_MAMR_10COL */
  212. if ((size8 < size10) && (size9 < size10)) {
  213. size_b0 = size10;
  214. } else if ((size8 < size9) && (size10 < size9)) {
  215. size_b0 = size9;
  216. memctl->memc_mamr = CONFIG_SYS_MAMR_9COL;
  217. udelay (500);
  218. } else {
  219. size_b0 = size8;
  220. memctl->memc_mamr = CONFIG_SYS_MAMR_8COL;
  221. udelay (500);
  222. }
  223. debug ("SDRAM Bank 0: %ld MB\n", size_b0 >> 20);
  224. #ifndef CONFIG_CAN_DRIVER
  225. if ((board_type != 'L') &&
  226. (board_type != 'M') &&
  227. (board_type != 'D') ) { /* only one SDRAM bank on L, M and D modules */
  228. /*
  229. * Check Bank 1 Memory Size
  230. * use current column settings
  231. * [9 column SDRAM may also be used in 8 column mode,
  232. * but then only half the real size will be used.]
  233. */
  234. size_b1 = dram_size (memctl->memc_mamr, (long int *)SDRAM_BASE3_PRELIM,
  235. SDRAM_MAX_SIZE);
  236. debug ("SDRAM Bank 1: %ld MB\n", size_b1 >> 20);
  237. } else {
  238. size_b1 = 0;
  239. }
  240. #endif /* CONFIG_CAN_DRIVER */
  241. udelay (1000);
  242. /*
  243. * Adjust refresh rate depending on SDRAM type, both banks
  244. * For types > 128 MBit leave it at the current (fast) rate
  245. */
  246. if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) {
  247. /* reduce to 15.6 us (62.4 us / quad) */
  248. memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K;
  249. udelay (1000);
  250. }
  251. /*
  252. * Final mapping: map bigger bank first
  253. */
  254. if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */
  255. memctl->memc_or3 = ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
  256. memctl->memc_br3 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  257. if (size_b0 > 0) {
  258. /*
  259. * Position Bank 0 immediately above Bank 1
  260. */
  261. memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
  262. memctl->memc_br2 = ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
  263. + size_b1;
  264. } else {
  265. unsigned long reg;
  266. /*
  267. * No bank 0
  268. *
  269. * invalidate bank
  270. */
  271. memctl->memc_br2 = 0;
  272. /* adjust refresh rate depending on SDRAM type, one bank */
  273. reg = memctl->memc_mptpr;
  274. reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */
  275. memctl->memc_mptpr = reg;
  276. }
  277. } else { /* SDRAM Bank 0 is bigger - map first */
  278. memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
  279. memctl->memc_br2 =
  280. (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  281. if (size_b1 > 0) {
  282. /*
  283. * Position Bank 1 immediately above Bank 0
  284. */
  285. memctl->memc_or3 =
  286. ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
  287. memctl->memc_br3 =
  288. ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
  289. + size_b0;
  290. } else {
  291. unsigned long reg;
  292. #ifndef CONFIG_CAN_DRIVER
  293. /*
  294. * No bank 1
  295. *
  296. * invalidate bank
  297. */
  298. memctl->memc_br3 = 0;
  299. #endif /* CONFIG_CAN_DRIVER */
  300. /* adjust refresh rate depending on SDRAM type, one bank */
  301. reg = memctl->memc_mptpr;
  302. reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */
  303. memctl->memc_mptpr = reg;
  304. }
  305. }
  306. udelay (10000);
  307. #ifdef CONFIG_CAN_DRIVER
  308. /* UPM initialization for CAN @ CLKOUT <= 66 MHz */
  309. /* Initialize OR3 / BR3 */
  310. memctl->memc_or3 = CONFIG_SYS_OR3_CAN;
  311. memctl->memc_br3 = CONFIG_SYS_BR3_CAN;
  312. /* Initialize MBMR */
  313. memctl->memc_mbmr = MBMR_GPL_B4DIS; /* GPL_B4 ouput line Disable */
  314. /* Initialize UPMB for CAN: single read */
  315. memctl->memc_mdr = 0xFFFFCC04;
  316. memctl->memc_mcr = 0x0100 | UPMB;
  317. memctl->memc_mdr = 0x0FFFD004;
  318. memctl->memc_mcr = 0x0101 | UPMB;
  319. memctl->memc_mdr = 0x0FFFC000;
  320. memctl->memc_mcr = 0x0102 | UPMB;
  321. memctl->memc_mdr = 0x3FFFC004;
  322. memctl->memc_mcr = 0x0103 | UPMB;
  323. memctl->memc_mdr = 0xFFFFDC07;
  324. memctl->memc_mcr = 0x0104 | UPMB;
  325. /* Initialize UPMB for CAN: single write */
  326. memctl->memc_mdr = 0xFFFCCC04;
  327. memctl->memc_mcr = 0x0118 | UPMB;
  328. memctl->memc_mdr = 0xCFFCDC04;
  329. memctl->memc_mcr = 0x0119 | UPMB;
  330. memctl->memc_mdr = 0x3FFCC000;
  331. memctl->memc_mcr = 0x011A | UPMB;
  332. memctl->memc_mdr = 0xFFFCC004;
  333. memctl->memc_mcr = 0x011B | UPMB;
  334. memctl->memc_mdr = 0xFFFDC405;
  335. memctl->memc_mcr = 0x011C | UPMB;
  336. #endif /* CONFIG_CAN_DRIVER */
  337. #ifdef CONFIG_ISP1362_USB
  338. /* Initialize OR5 / BR5 */
  339. memctl->memc_or5 = CONFIG_SYS_OR5_ISP1362;
  340. memctl->memc_br5 = CONFIG_SYS_BR5_ISP1362;
  341. #endif /* CONFIG_ISP1362_USB */
  342. return (size_b0 + size_b1);
  343. }
  344. /* ------------------------------------------------------------------------- */
  345. /*
  346. * Check memory range for valid RAM. A simple memory test determines
  347. * the actually available RAM size between addresses `base' and
  348. * `base + maxsize'. Some (not all) hardware errors are detected:
  349. * - short between address lines
  350. * - short between data lines
  351. */
  352. static long int dram_size (long int mamr_value, long int *base, long int maxsize)
  353. {
  354. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  355. volatile memctl8xx_t *memctl = &immap->im_memctl;
  356. memctl->memc_mamr = mamr_value;
  357. return (get_ram_size(base, maxsize));
  358. }
  359. /* ------------------------------------------------------------------------- */
  360. #ifdef CONFIG_PS2MULT
  361. #ifdef CONFIG_HMI10
  362. #define BASE_BAUD ( 1843200 / 16 )
  363. struct serial_state rs_table[] = {
  364. { BASE_BAUD, 4, (void*)0xec140000 },
  365. { BASE_BAUD, 2, (void*)0xec150000 },
  366. { BASE_BAUD, 6, (void*)0xec160000 },
  367. { BASE_BAUD, 10, (void*)0xec170000 },
  368. };
  369. #ifdef CONFIG_BOARD_EARLY_INIT_R
  370. int board_early_init_r (void)
  371. {
  372. ps2mult_early_init();
  373. return (0);
  374. }
  375. #endif
  376. #endif /* CONFIG_HMI10 */
  377. #endif /* CONFIG_PS2MULT */
  378. #ifdef CONFIG_MISC_INIT_R
  379. extern void load_sernum_ethaddr(void);
  380. int misc_init_r (void)
  381. {
  382. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  383. volatile memctl8xx_t *memctl = &immap->im_memctl;
  384. load_sernum_ethaddr();
  385. #ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ
  386. int scy, trlx, flash_or_timing, clk_diff;
  387. scy = (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & OR_SCY_MSK) >> 4;
  388. if (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & OR_TRLX) {
  389. trlx = OR_TRLX;
  390. scy *= 2;
  391. } else {
  392. trlx = 0;
  393. }
  394. /*
  395. * We assume that each 10MHz of bus clock require 1-clk SCY
  396. * adjustment.
  397. */
  398. clk_diff = (gd->bus_clk / 1000000) - 50;
  399. /*
  400. * We need proper rounding here. This is what the "+5" and "-5"
  401. * are here for.
  402. */
  403. if (clk_diff >= 0)
  404. scy += (clk_diff + 5) / 10;
  405. else
  406. scy += (clk_diff - 5) / 10;
  407. /*
  408. * For bus frequencies above 50MHz, we want to use relaxed timing
  409. * (OR_TRLX).
  410. */
  411. if (gd->bus_clk >= 50000000)
  412. trlx = OR_TRLX;
  413. else
  414. trlx = 0;
  415. if (trlx)
  416. scy /= 2;
  417. if (scy > 0xf)
  418. scy = 0xf;
  419. if (scy < 1)
  420. scy = 1;
  421. flash_or_timing = (scy << 4) | trlx |
  422. (CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ & ~(OR_TRLX | OR_SCY_MSK));
  423. memctl->memc_or0 =
  424. flash_or_timing | (-flash_info[0].size & OR_AM_MSK);
  425. #else
  426. memctl->memc_or0 =
  427. CONFIG_SYS_OR_TIMING_FLASH | (-flash_info[0].size & OR_AM_MSK);
  428. #endif
  429. memctl->memc_br0 = (CONFIG_SYS_FLASH_BASE & BR_BA_MSK) | BR_MS_GPCM | BR_V;
  430. debug ("## BR0: 0x%08x OR0: 0x%08x\n",
  431. memctl->memc_br0, memctl->memc_or0);
  432. if (flash_info[1].size) {
  433. #ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ
  434. memctl->memc_or1 = flash_or_timing |
  435. (-flash_info[1].size & 0xFFFF8000);
  436. #else
  437. memctl->memc_or1 = CONFIG_SYS_OR_TIMING_FLASH |
  438. (-flash_info[1].size & 0xFFFF8000);
  439. #endif
  440. memctl->memc_br1 =
  441. ((CONFIG_SYS_FLASH_BASE +
  442. flash_info[0].
  443. size) & BR_BA_MSK) | BR_MS_GPCM | BR_V;
  444. debug ("## BR1: 0x%08x OR1: 0x%08x\n",
  445. memctl->memc_br1, memctl->memc_or1);
  446. } else {
  447. memctl->memc_br1 = 0; /* invalidate bank */
  448. debug ("## DISABLE BR1: 0x%08x OR1: 0x%08x\n",
  449. memctl->memc_br1, memctl->memc_or1);
  450. }
  451. # ifdef CONFIG_IDE_LED
  452. /* Configure PA15 as output port */
  453. immap->im_ioport.iop_padir |= 0x0001;
  454. immap->im_ioport.iop_paodr |= 0x0001;
  455. immap->im_ioport.iop_papar &= ~0x0001;
  456. immap->im_ioport.iop_padat &= ~0x0001; /* turn it off */
  457. # endif
  458. #ifdef CONFIG_NSCU
  459. /* wake up ethernet module */
  460. immap->im_ioport.iop_pcpar &= ~0x0004; /* GPIO pin */
  461. immap->im_ioport.iop_pcdir |= 0x0004; /* output */
  462. immap->im_ioport.iop_pcso &= ~0x0004; /* for clarity */
  463. immap->im_ioport.iop_pcdat |= 0x0004; /* enable */
  464. #endif /* CONFIG_NSCU */
  465. return (0);
  466. }
  467. #endif /* CONFIG_MISC_INIT_R */
  468. # ifdef CONFIG_IDE_LED
  469. void ide_led (uchar led, uchar status)
  470. {
  471. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  472. /* We have one led for both pcmcia slots */
  473. if (status) { /* led on */
  474. immap->im_ioport.iop_padat |= 0x0001;
  475. } else {
  476. immap->im_ioport.iop_padat &= ~0x0001;
  477. }
  478. }
  479. # endif
  480. #ifdef CONFIG_LCD_INFO
  481. #include <lcd.h>
  482. #include <version.h>
  483. #include <timestamp.h>
  484. void lcd_show_board_info(void)
  485. {
  486. char temp[32];
  487. lcd_printf ("%s (%s - %s)\n", U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME);
  488. lcd_printf ("(C) 2008 DENX Software Engineering GmbH\n");
  489. lcd_printf (" Wolfgang DENK, wd@denx.de\n");
  490. #ifdef CONFIG_LCD_INFO_BELOW_LOGO
  491. lcd_printf ("MPC823 CPU at %s MHz\n",
  492. strmhz(temp, gd->cpu_clk));
  493. lcd_printf (" %ld MB RAM, %ld MB Flash\n",
  494. gd->ram_size >> 20,
  495. gd->bd->bi_flashsize >> 20 );
  496. #else
  497. /* leave one blank line */
  498. lcd_printf ("\nMPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash\n",
  499. strmhz(temp, gd->cpu_clk),
  500. gd->ram_size >> 20,
  501. gd->bd->bi_flashsize >> 20 );
  502. #endif /* CONFIG_LCD_INFO_BELOW_LOGO */
  503. }
  504. #endif /* CONFIG_LCD_INFO */
  505. /*
  506. * Device Tree Support
  507. */
  508. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  509. int fdt_set_node_and_value (void *blob,
  510. char *nodename,
  511. char *regname,
  512. void *var,
  513. int size)
  514. {
  515. int ret = 0;
  516. int nodeoffset = 0;
  517. nodeoffset = fdt_path_offset (blob, nodename);
  518. if (nodeoffset >= 0) {
  519. ret = fdt_setprop (blob, nodeoffset, regname, var,
  520. size);
  521. if (ret < 0) {
  522. printf("ft_blob_update(): "
  523. "cannot set %s/%s property; err: %s\n",
  524. nodename, regname, fdt_strerror (ret));
  525. }
  526. } else {
  527. printf("ft_blob_update(): "
  528. "cannot find %s node err:%s\n",
  529. nodename, fdt_strerror (nodeoffset));
  530. }
  531. return ret;
  532. }
  533. int fdt_del_node_name (void *blob, char *nodename)
  534. {
  535. int ret = 0;
  536. int nodeoffset = 0;
  537. nodeoffset = fdt_path_offset (blob, nodename);
  538. if (nodeoffset >= 0) {
  539. ret = fdt_del_node (blob, nodeoffset);
  540. if (ret < 0) {
  541. printf("%s: cannot delete %s; err: %s\n",
  542. __func__, nodename, fdt_strerror (ret));
  543. }
  544. } else {
  545. printf("%s: cannot find %s node err:%s\n",
  546. __func__, nodename, fdt_strerror (nodeoffset));
  547. }
  548. return ret;
  549. }
  550. int fdt_del_prop_name (void *blob, char *nodename, char *propname)
  551. {
  552. int ret = 0;
  553. int nodeoffset = 0;
  554. nodeoffset = fdt_path_offset (blob, nodename);
  555. if (nodeoffset >= 0) {
  556. ret = fdt_delprop (blob, nodeoffset, propname);
  557. if (ret < 0) {
  558. printf("%s: cannot delete %s %s; err: %s\n",
  559. __func__, nodename, propname,
  560. fdt_strerror (ret));
  561. }
  562. } else {
  563. printf("%s: cannot find %s node err:%s\n",
  564. __func__, nodename, fdt_strerror (nodeoffset));
  565. }
  566. return ret;
  567. }
  568. /*
  569. * update "brg" property in the blob
  570. */
  571. void ft_blob_update (void *blob, bd_t *bd)
  572. {
  573. uchar enetaddr[6];
  574. ulong brg_data = 0;
  575. /* BRG */
  576. brg_data = cpu_to_be32(bd->bi_busfreq);
  577. fdt_set_node_and_value(blob,
  578. "/soc/cpm", "brg-frequency",
  579. &brg_data, sizeof(brg_data));
  580. /* MAC addr */
  581. if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
  582. fdt_set_node_and_value(blob,
  583. "ethernet0", "local-mac-address",
  584. enetaddr, sizeof(u8) * 6);
  585. }
  586. if (hwconfig_arg_cmp("fec", "off")) {
  587. /* no FEC on this plattform, delete DTS nodes */
  588. fdt_del_node_name (blob, "ethernet1");
  589. fdt_del_node_name (blob, "mdio1");
  590. /* also the aliases entries */
  591. fdt_del_prop_name (blob, "/aliases", "ethernet1");
  592. fdt_del_prop_name (blob, "/aliases", "mdio1");
  593. } else {
  594. /* adjust local-mac-address for FEC ethernet */
  595. if (eth_getenv_enetaddr("eth1addr", enetaddr)) {
  596. fdt_set_node_and_value(blob,
  597. "ethernet1", "local-mac-address",
  598. enetaddr, sizeof(u8) * 6);
  599. }
  600. }
  601. }
  602. void ft_board_setup(void *blob, bd_t *bd)
  603. {
  604. ft_cpu_setup(blob, bd);
  605. ft_blob_update(blob, bd);
  606. }
  607. #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */
  608. /* ---------------------------------------------------------------------------- */
  609. /* TK885D specific initializaion */
  610. /* ---------------------------------------------------------------------------- */
  611. #ifdef CONFIG_TK885D
  612. #include <miiphy.h>
  613. int last_stage_init(void)
  614. {
  615. const unsigned char phy[] = {CONFIG_FEC1_PHY, CONFIG_FEC2_PHY};
  616. unsigned short reg;
  617. int ret, i = 100;
  618. char *s;
  619. mii_init();
  620. /* Without this delay 0xff is read from the UART buffer later in
  621. * abortboot() and autoboot is aborted */
  622. udelay(10000);
  623. while (tstc() && i--)
  624. (void)getc();
  625. /* Check if auto-negotiation is prohibited */
  626. s = getenv("phy_auto_nego");
  627. if (!s || !strcmp(s, "on"))
  628. /* Nothing to do - autonegotiation by default */
  629. return 0;
  630. for (i = 0; i < 2; i++) {
  631. ret = miiphy_read("FEC", phy[i], PHY_BMCR, &reg);
  632. if (ret) {
  633. printf("Cannot read BMCR on PHY %d\n", phy[i]);
  634. return 0;
  635. }
  636. /* Auto-negotiation off, hard set full duplex, 100Mbps */
  637. ret = miiphy_write("FEC", phy[i],
  638. PHY_BMCR, (reg | PHY_BMCR_100MB |
  639. PHY_BMCR_DPLX) & ~PHY_BMCR_AUTON);
  640. if (ret) {
  641. printf("Cannot write BMCR on PHY %d\n", phy[i]);
  642. return 0;
  643. }
  644. }
  645. return 0;
  646. }
  647. #endif