tqm8xx.c 17 KB

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