cpu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. /*
  23. * CPU specific code for the MPC83xx family.
  24. *
  25. * Derived from the MPC8260 and MPC85xx.
  26. */
  27. #include <common.h>
  28. #include <watchdog.h>
  29. #include <command.h>
  30. #include <mpc83xx.h>
  31. #include <asm/processor.h>
  32. #if defined(CONFIG_OF_FLAT_TREE)
  33. #include <ft_build.h>
  34. #elif defined(CONFIG_OF_LIBFDT)
  35. #include <libfdt.h>
  36. #include <fdt_support.h>
  37. #endif
  38. DECLARE_GLOBAL_DATA_PTR;
  39. int checkcpu(void)
  40. {
  41. volatile immap_t *immr;
  42. ulong clock = gd->cpu_clk;
  43. u32 pvr = get_pvr();
  44. u32 spridr;
  45. char buf[32];
  46. immr = (immap_t *)CFG_IMMR;
  47. puts("CPU: ");
  48. switch (pvr & 0xffff0000) {
  49. case PVR_E300C1:
  50. printf("e300c1, ");
  51. break;
  52. case PVR_E300C2:
  53. printf("e300c2, ");
  54. break;
  55. case PVR_E300C3:
  56. printf("e300c3, ");
  57. break;
  58. case PVR_E300C4:
  59. printf("e300c4, ");
  60. break;
  61. default:
  62. printf("Unknown core, ");
  63. }
  64. spridr = immr->sysconf.spridr;
  65. switch(spridr) {
  66. case SPR_8349E_REV10:
  67. case SPR_8349E_REV11:
  68. case SPR_8349E_REV31:
  69. puts("MPC8349E, ");
  70. break;
  71. case SPR_8349_REV10:
  72. case SPR_8349_REV11:
  73. case SPR_8349_REV31:
  74. puts("MPC8349, ");
  75. break;
  76. case SPR_8347E_REV10_TBGA:
  77. case SPR_8347E_REV11_TBGA:
  78. case SPR_8347E_REV31_TBGA:
  79. case SPR_8347E_REV10_PBGA:
  80. case SPR_8347E_REV11_PBGA:
  81. case SPR_8347E_REV31_PBGA:
  82. puts("MPC8347E, ");
  83. break;
  84. case SPR_8347_REV10_TBGA:
  85. case SPR_8347_REV11_TBGA:
  86. case SPR_8347_REV31_TBGA:
  87. case SPR_8347_REV10_PBGA:
  88. case SPR_8347_REV11_PBGA:
  89. case SPR_8347_REV31_PBGA:
  90. puts("MPC8347, ");
  91. break;
  92. case SPR_8343E_REV10:
  93. case SPR_8343E_REV11:
  94. case SPR_8343E_REV31:
  95. puts("MPC8343E, ");
  96. break;
  97. case SPR_8343_REV10:
  98. case SPR_8343_REV11:
  99. case SPR_8343_REV31:
  100. puts("MPC8343, ");
  101. break;
  102. case SPR_8360E_REV10:
  103. case SPR_8360E_REV11:
  104. case SPR_8360E_REV12:
  105. case SPR_8360E_REV20:
  106. case SPR_8360E_REV21:
  107. puts("MPC8360E, ");
  108. break;
  109. case SPR_8360_REV10:
  110. case SPR_8360_REV11:
  111. case SPR_8360_REV12:
  112. case SPR_8360_REV20:
  113. case SPR_8360_REV21:
  114. puts("MPC8360, ");
  115. break;
  116. case SPR_8323E_REV10:
  117. case SPR_8323E_REV11:
  118. puts("MPC8323E, ");
  119. break;
  120. case SPR_8323_REV10:
  121. case SPR_8323_REV11:
  122. puts("MPC8323, ");
  123. break;
  124. case SPR_8321E_REV10:
  125. case SPR_8321E_REV11:
  126. puts("MPC8321E, ");
  127. break;
  128. case SPR_8321_REV10:
  129. case SPR_8321_REV11:
  130. puts("MPC8321, ");
  131. break;
  132. case SPR_8311_REV10:
  133. puts("MPC8311, ");
  134. break;
  135. case SPR_8311E_REV10:
  136. puts("MPC8311E, ");
  137. break;
  138. case SPR_8313_REV10:
  139. puts("MPC8313, ");
  140. break;
  141. case SPR_8313E_REV10:
  142. puts("MPC8313E, ");
  143. break;
  144. case SPR_8379E_REV10:
  145. puts("MPC8379E, ");
  146. break;
  147. case SPR_8379_REV10:
  148. puts("MPC8379, ");
  149. break;
  150. case SPR_8378E_REV10:
  151. puts("MPC8378E, ");
  152. break;
  153. case SPR_8378_REV10:
  154. puts("MPC8378, ");
  155. break;
  156. case SPR_8377E_REV10:
  157. puts("MPC8377E, ");
  158. break;
  159. case SPR_8377_REV10:
  160. puts("MPC8377, ");
  161. break;
  162. default:
  163. printf("Rev: Unknown revision number:%08x\n"
  164. "Warning: Unsupported cpu revision!\n",spridr);
  165. return 0;
  166. }
  167. #if defined(CONFIG_MPC834X)
  168. /* Multiple revisons of 834x processors may have the same SPRIDR value.
  169. * So use PVR to identify the revision number.
  170. */
  171. printf("Rev: %02x at %s MHz", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock));
  172. #else
  173. printf("Rev: %02x at %s MHz", spridr & 0x0000FFFF, strmhz(buf, clock));
  174. #endif
  175. printf(", CSB: %4d MHz\n", gd->csb_clk / 1000000);
  176. return 0;
  177. }
  178. /*
  179. * Program a UPM with the code supplied in the table.
  180. *
  181. * The 'dummy' variable is used to increment the MAD. 'dummy' is
  182. * supposed to be a pointer to the memory of the device being
  183. * programmed by the UPM. The data in the MDR is written into
  184. * memory and the MAD is incremented every time there's a read
  185. * from 'dummy'. Unfortunately, the current prototype for this
  186. * function doesn't allow for passing the address of this
  187. * device, and changing the prototype will break a number lots
  188. * of other code, so we need to use a round-about way of finding
  189. * the value for 'dummy'.
  190. *
  191. * The value can be extracted from the base address bits of the
  192. * Base Register (BR) associated with the specific UPM. To find
  193. * that BR, we need to scan all 8 BRs until we find the one that
  194. * has its MSEL bits matching the UPM we want. Once we know the
  195. * right BR, we can extract the base address bits from it.
  196. *
  197. * The MxMR and the BR and OR of the chosen bank should all be
  198. * configured before calling this function.
  199. *
  200. * Parameters:
  201. * upm: 0=UPMA, 1=UPMB, 2=UPMC
  202. * table: Pointer to an array of values to program
  203. * size: Number of elements in the array. Must be 64 or less.
  204. */
  205. void upmconfig (uint upm, uint *table, uint size)
  206. {
  207. #if defined(CONFIG_MPC834X)
  208. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  209. volatile lbus83xx_t *lbus = &immap->lbus;
  210. volatile uchar *dummy = NULL;
  211. const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
  212. volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
  213. uint i;
  214. /* Scan all the banks to determine the base address of the device */
  215. for (i = 0; i < 8; i++) {
  216. if ((lbus->bank[i].br & BR_MSEL) == msel) {
  217. dummy = (uchar *) (lbus->bank[i].br & BR_BA);
  218. break;
  219. }
  220. }
  221. if (!dummy) {
  222. printf("Error: %s() could not find matching BR\n", __FUNCTION__);
  223. hang();
  224. }
  225. /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
  226. *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
  227. for (i = 0; i < size; i++) {
  228. lbus->mdr = table[i];
  229. __asm__ __volatile__ ("sync");
  230. *dummy; /* Write the value to memory and increment MAD */
  231. __asm__ __volatile__ ("sync");
  232. }
  233. /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
  234. *mxmr &= 0xCFFFFFC0;
  235. #else
  236. printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
  237. hang();
  238. #endif
  239. }
  240. int
  241. do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  242. {
  243. ulong msr;
  244. #ifndef MPC83xx_RESET
  245. ulong addr;
  246. #endif
  247. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  248. #ifdef MPC83xx_RESET
  249. /* Interrupts and MMU off */
  250. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  251. msr &= ~( MSR_EE | MSR_IR | MSR_DR);
  252. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  253. /* enable Reset Control Reg */
  254. immap->reset.rpr = 0x52535445;
  255. __asm__ __volatile__ ("sync");
  256. __asm__ __volatile__ ("isync");
  257. /* confirm Reset Control Reg is enabled */
  258. while(!((immap->reset.rcer) & RCER_CRE));
  259. printf("Resetting the board.");
  260. printf("\n");
  261. udelay(200);
  262. /* perform reset, only one bit */
  263. immap->reset.rcr = RCR_SWHR;
  264. #else /* ! MPC83xx_RESET */
  265. immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
  266. /* Interrupts and MMU off */
  267. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  268. msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
  269. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  270. /*
  271. * Trying to execute the next instruction at a non-existing address
  272. * should cause a machine check, resulting in reset
  273. */
  274. addr = CFG_RESET_ADDRESS;
  275. printf("resetting the board.");
  276. printf("\n");
  277. ((void (*)(void)) addr) ();
  278. #endif /* MPC83xx_RESET */
  279. return 1;
  280. }
  281. /*
  282. * Get timebase clock frequency (like cpu_clk in Hz)
  283. */
  284. unsigned long get_tbclk(void)
  285. {
  286. ulong tbclk;
  287. tbclk = (gd->bus_clk + 3L) / 4L;
  288. return tbclk;
  289. }
  290. #if defined(CONFIG_WATCHDOG)
  291. void watchdog_reset (void)
  292. {
  293. int re_enable = disable_interrupts();
  294. /* Reset the 83xx watchdog */
  295. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  296. immr->wdt.swsrr = 0x556c;
  297. immr->wdt.swsrr = 0xaa39;
  298. if (re_enable)
  299. enable_interrupts ();
  300. }
  301. #endif
  302. #if defined(CONFIG_OF_LIBFDT)
  303. /*
  304. * "Setter" functions used to add/modify FDT entries.
  305. */
  306. static int fdt_set_eth0(void *blob, int nodeoffset, const char *name, bd_t *bd)
  307. {
  308. /* Fix it up if it exists, don't create it if it doesn't exist */
  309. if (fdt_get_property(blob, nodeoffset, name, 0)) {
  310. return fdt_setprop(blob, nodeoffset, name, bd->bi_enetaddr, 6);
  311. }
  312. return 0;
  313. }
  314. #ifdef CONFIG_HAS_ETH1
  315. /* second onboard ethernet port */
  316. static int fdt_set_eth1(void *blob, int nodeoffset, const char *name, bd_t *bd)
  317. {
  318. /* Fix it up if it exists, don't create it if it doesn't exist */
  319. if (fdt_get_property(blob, nodeoffset, name, 0)) {
  320. return fdt_setprop(blob, nodeoffset, name, bd->bi_enet1addr, 6);
  321. }
  322. return 0;
  323. }
  324. #endif
  325. #ifdef CONFIG_HAS_ETH2
  326. /* third onboard ethernet port */
  327. static int fdt_set_eth2(void *blob, int nodeoffset, const char *name, bd_t *bd)
  328. {
  329. /* Fix it up if it exists, don't create it if it doesn't exist */
  330. if (fdt_get_property(blob, nodeoffset, name, 0)) {
  331. return fdt_setprop(blob, nodeoffset, name, bd->bi_enet2addr, 6);
  332. }
  333. return 0;
  334. }
  335. #endif
  336. #ifdef CONFIG_HAS_ETH3
  337. /* fourth onboard ethernet port */
  338. static int fdt_set_eth3(void *blob, int nodeoffset, const char *name, bd_t *bd)
  339. {
  340. /* Fix it up if it exists, don't create it if it doesn't exist */
  341. if (fdt_get_property(blob, nodeoffset, name, 0)) {
  342. return fdt_setprop(blob, nodeoffset, name, bd->bi_enet3addr, 6);
  343. }
  344. return 0;
  345. }
  346. #endif
  347. static int fdt_set_busfreq(void *blob, int nodeoffset, const char *name, bd_t *bd)
  348. {
  349. u32 tmp;
  350. /* Create or update the property */
  351. tmp = cpu_to_be32(bd->bi_busfreq);
  352. return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));
  353. }
  354. static int fdt_set_tbfreq(void *blob, int nodeoffset, const char *name, bd_t *bd)
  355. {
  356. u32 tmp;
  357. /* Create or update the property */
  358. tmp = cpu_to_be32(OF_TBCLK);
  359. return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));
  360. }
  361. static int fdt_set_clockfreq(void *blob, int nodeoffset, const char *name, bd_t *bd)
  362. {
  363. u32 tmp;
  364. /* Create or update the property */
  365. tmp = cpu_to_be32(gd->core_clk);
  366. return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));
  367. }
  368. #ifdef CONFIG_QE
  369. static int fdt_set_qe_busfreq(void *blob, int nodeoffset, const char *name, bd_t *bd)
  370. {
  371. u32 tmp;
  372. /* Create or update the property */
  373. tmp = cpu_to_be32(gd->qe_clk);
  374. return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));
  375. }
  376. static int fdt_set_qe_brgfreq(void *blob, int nodeoffset, const char *name, bd_t *bd)
  377. {
  378. u32 tmp;
  379. /* Create or update the property */
  380. tmp = cpu_to_be32(gd->brg_clk);
  381. return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));
  382. }
  383. #endif
  384. /*
  385. * Fixups to the fdt.
  386. */
  387. static const struct {
  388. char *node;
  389. char *prop;
  390. int (*set_fn)(void *blob, int nodeoffset, const char *name, bd_t *bd);
  391. } fixup_props[] = {
  392. { "/cpus/" OF_CPU,
  393. "timebase-frequency",
  394. fdt_set_tbfreq
  395. },
  396. { "/cpus/" OF_CPU,
  397. "bus-frequency",
  398. fdt_set_busfreq
  399. },
  400. { "/cpus/" OF_CPU,
  401. "clock-frequency",
  402. fdt_set_clockfreq
  403. },
  404. { "/" OF_SOC,
  405. "bus-frequency",
  406. fdt_set_busfreq
  407. },
  408. { "/" OF_SOC "/serial@4500",
  409. "clock-frequency",
  410. fdt_set_busfreq
  411. },
  412. { "/" OF_SOC "/serial@4600",
  413. "clock-frequency",
  414. fdt_set_busfreq
  415. },
  416. #ifdef CONFIG_TSEC1
  417. { "/" OF_SOC "/ethernet@24000",
  418. "mac-address",
  419. fdt_set_eth0
  420. },
  421. { "/" OF_SOC "/ethernet@24000",
  422. "local-mac-address",
  423. fdt_set_eth0
  424. },
  425. #endif
  426. #ifdef CONFIG_TSEC2
  427. { "/" OF_SOC "/ethernet@25000",
  428. "mac-address",
  429. fdt_set_eth1
  430. },
  431. { "/" OF_SOC "/ethernet@25000",
  432. "local-mac-address",
  433. fdt_set_eth1
  434. },
  435. #endif
  436. #ifdef CONFIG_QE
  437. { "/" OF_QE,
  438. "brg-frequency",
  439. fdt_set_qe_brgfreq
  440. },
  441. { "/" OF_QE,
  442. "bus-frequency",
  443. fdt_set_qe_busfreq
  444. },
  445. #ifdef CONFIG_UEC_ETH1
  446. #if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
  447. { "/" OF_QE "/ucc@2000",
  448. "mac-address",
  449. fdt_set_eth0
  450. },
  451. { "/" OF_QE "/ucc@2000",
  452. "local-mac-address",
  453. fdt_set_eth0
  454. },
  455. #elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
  456. { "/" OF_QE "/ucc@2200",
  457. "mac-address",
  458. fdt_set_eth0
  459. },
  460. { "/" OF_QE "/ucc@2200",
  461. "local-mac-address",
  462. fdt_set_eth0
  463. },
  464. #endif
  465. #endif /* CONFIG_UEC_ETH1 */
  466. #ifdef CONFIG_UEC_ETH2
  467. #if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
  468. { "/" OF_QE "/ucc@3000",
  469. "mac-address",
  470. fdt_set_eth1
  471. },
  472. { "/" OF_QE "/ucc@3000",
  473. "local-mac-address",
  474. fdt_set_eth1
  475. },
  476. #elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
  477. { "/" OF_QE "/ucc@3200",
  478. "mac-address",
  479. fdt_set_eth1
  480. },
  481. { "/" OF_QE "/ucc@3200",
  482. "local-mac-address",
  483. fdt_set_eth1
  484. },
  485. #endif
  486. #endif /* CONFIG_UEC_ETH2 */
  487. #endif /* CONFIG_QE */
  488. };
  489. void
  490. ft_cpu_setup(void *blob, bd_t *bd)
  491. {
  492. int nodeoffset;
  493. int err;
  494. int j;
  495. for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) {
  496. nodeoffset = fdt_path_offset(blob, fixup_props[j].node);
  497. if (nodeoffset >= 0) {
  498. err = fixup_props[j].set_fn(blob, nodeoffset,
  499. fixup_props[j].prop, bd);
  500. if (err < 0)
  501. debug("Problem setting %s = %s: %s\n",
  502. fixup_props[j].node, fixup_props[j].prop,
  503. fdt_strerror(err));
  504. } else {
  505. debug("Couldn't find %s: %s\n",
  506. fixup_props[j].node, fdt_strerror(nodeoffset));
  507. }
  508. }
  509. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  510. }
  511. #elif defined(CONFIG_OF_FLAT_TREE)
  512. void
  513. ft_cpu_setup(void *blob, bd_t *bd)
  514. {
  515. u32 *p;
  516. int len;
  517. ulong clock;
  518. clock = bd->bi_busfreq;
  519. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  520. if (p != NULL)
  521. *p = cpu_to_be32(clock);
  522. p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len);
  523. if (p != NULL)
  524. *p = cpu_to_be32(clock);
  525. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  526. if (p != NULL)
  527. *p = cpu_to_be32(clock);
  528. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  529. if (p != NULL)
  530. *p = cpu_to_be32(clock);
  531. #ifdef CONFIG_TSEC1
  532. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
  533. if (p != NULL)
  534. memcpy(p, bd->bi_enetaddr, 6);
  535. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
  536. if (p != NULL)
  537. memcpy(p, bd->bi_enetaddr, 6);
  538. #endif
  539. #ifdef CONFIG_TSEC2
  540. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
  541. if (p != NULL)
  542. memcpy(p, bd->bi_enet1addr, 6);
  543. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
  544. if (p != NULL)
  545. memcpy(p, bd->bi_enet1addr, 6);
  546. #endif
  547. #ifdef CONFIG_UEC_ETH1
  548. #if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
  549. p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len);
  550. if (p != NULL)
  551. memcpy(p, bd->bi_enetaddr, 6);
  552. p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len);
  553. if (p != NULL)
  554. memcpy(p, bd->bi_enetaddr, 6);
  555. #elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
  556. p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/mac-address", &len);
  557. if (p != NULL)
  558. memcpy(p, bd->bi_enetaddr, 6);
  559. p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/local-mac-address", &len);
  560. if (p != NULL)
  561. memcpy(p, bd->bi_enetaddr, 6);
  562. #endif
  563. #endif
  564. #ifdef CONFIG_UEC_ETH2
  565. #if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
  566. p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len);
  567. if (p != NULL)
  568. memcpy(p, bd->bi_enet1addr, 6);
  569. p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len);
  570. if (p != NULL)
  571. memcpy(p, bd->bi_enet1addr, 6);
  572. #elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
  573. p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/mac-address", &len);
  574. if (p != NULL)
  575. memcpy(p, bd->bi_enet1addr, 6);
  576. p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/local-mac-address", &len);
  577. if (p != NULL)
  578. memcpy(p, bd->bi_enet1addr, 6);
  579. #endif
  580. #endif
  581. }
  582. #endif
  583. #if defined(CONFIG_DDR_ECC)
  584. void dma_init(void)
  585. {
  586. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  587. volatile dma83xx_t *dma = &immap->dma;
  588. volatile u32 status = swab32(dma->dmasr0);
  589. volatile u32 dmamr0 = swab32(dma->dmamr0);
  590. debug("DMA-init\n");
  591. /* initialize DMASARn, DMADAR and DMAABCRn */
  592. dma->dmadar0 = (u32)0;
  593. dma->dmasar0 = (u32)0;
  594. dma->dmabcr0 = 0;
  595. __asm__ __volatile__ ("sync");
  596. __asm__ __volatile__ ("isync");
  597. /* clear CS bit */
  598. dmamr0 &= ~DMA_CHANNEL_START;
  599. dma->dmamr0 = swab32(dmamr0);
  600. __asm__ __volatile__ ("sync");
  601. __asm__ __volatile__ ("isync");
  602. /* while the channel is busy, spin */
  603. while(status & DMA_CHANNEL_BUSY) {
  604. status = swab32(dma->dmasr0);
  605. }
  606. debug("DMA-init end\n");
  607. }
  608. uint dma_check(void)
  609. {
  610. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  611. volatile dma83xx_t *dma = &immap->dma;
  612. volatile u32 status = swab32(dma->dmasr0);
  613. volatile u32 byte_count = swab32(dma->dmabcr0);
  614. /* while the channel is busy, spin */
  615. while (status & DMA_CHANNEL_BUSY) {
  616. status = swab32(dma->dmasr0);
  617. }
  618. if (status & DMA_CHANNEL_TRANSFER_ERROR) {
  619. printf ("DMA Error: status = %x @ %d\n", status, byte_count);
  620. }
  621. return status;
  622. }
  623. int dma_xfer(void *dest, u32 count, void *src)
  624. {
  625. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  626. volatile dma83xx_t *dma = &immap->dma;
  627. volatile u32 dmamr0;
  628. /* initialize DMASARn, DMADAR and DMAABCRn */
  629. dma->dmadar0 = swab32((u32)dest);
  630. dma->dmasar0 = swab32((u32)src);
  631. dma->dmabcr0 = swab32(count);
  632. __asm__ __volatile__ ("sync");
  633. __asm__ __volatile__ ("isync");
  634. /* init direct transfer, clear CS bit */
  635. dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
  636. DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
  637. DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
  638. dma->dmamr0 = swab32(dmamr0);
  639. __asm__ __volatile__ ("sync");
  640. __asm__ __volatile__ ("isync");
  641. /* set CS to start DMA transfer */
  642. dmamr0 |= DMA_CHANNEL_START;
  643. dma->dmamr0 = swab32(dmamr0);
  644. __asm__ __volatile__ ("sync");
  645. __asm__ __volatile__ ("isync");
  646. return ((int)dma_check());
  647. }
  648. #endif /*CONFIG_DDR_ECC*/