cpu.c 16 KB

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