cpu.c 17 KB

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