qe.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. /*
  2. * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
  3. *
  4. * Dave Liu <daveliu@freescale.com>
  5. * based on source code of Shlomi Gridish
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <malloc.h>
  11. #include <command.h>
  12. #include <linux/errno.h>
  13. #include <asm/io.h>
  14. #include <linux/immap_qe.h>
  15. #include <fsl_qe.h>
  16. #ifdef CONFIG_ARCH_LS1021A
  17. #include <asm/arch/immap_ls102xa.h>
  18. #endif
  19. #ifdef CONFIG_SYS_QE_FMAN_FW_IN_MMC
  20. #include <mmc.h>
  21. #endif
  22. #define MPC85xx_DEVDISR_QE_DISABLE 0x1
  23. qe_map_t *qe_immr = NULL;
  24. #ifdef CONFIG_QE
  25. static qe_snum_t snums[QE_NUM_OF_SNUM];
  26. #endif
  27. DECLARE_GLOBAL_DATA_PTR;
  28. void qe_issue_cmd(uint cmd, uint sbc, u8 mcn, u32 cmd_data)
  29. {
  30. u32 cecr;
  31. if (cmd == QE_RESET) {
  32. out_be32(&qe_immr->cp.cecr,(u32) (cmd | QE_CR_FLG));
  33. } else {
  34. out_be32(&qe_immr->cp.cecdr, cmd_data);
  35. out_be32(&qe_immr->cp.cecr, (sbc | QE_CR_FLG |
  36. ((u32) mcn<<QE_CR_PROTOCOL_SHIFT) | cmd));
  37. }
  38. /* Wait for the QE_CR_FLG to clear */
  39. do {
  40. cecr = in_be32(&qe_immr->cp.cecr);
  41. } while (cecr & QE_CR_FLG);
  42. return;
  43. }
  44. #ifdef CONFIG_QE
  45. uint qe_muram_alloc(uint size, uint align)
  46. {
  47. uint retloc;
  48. uint align_mask, off;
  49. uint savebase;
  50. align_mask = align - 1;
  51. savebase = gd->arch.mp_alloc_base;
  52. off = gd->arch.mp_alloc_base & align_mask;
  53. if (off != 0)
  54. gd->arch.mp_alloc_base += (align - off);
  55. if ((off = size & align_mask) != 0)
  56. size += (align - off);
  57. if ((gd->arch.mp_alloc_base + size) >= gd->arch.mp_alloc_top) {
  58. gd->arch.mp_alloc_base = savebase;
  59. printf("%s: ran out of ram.\n", __FUNCTION__);
  60. }
  61. retloc = gd->arch.mp_alloc_base;
  62. gd->arch.mp_alloc_base += size;
  63. memset((void *)&qe_immr->muram[retloc], 0, size);
  64. __asm__ __volatile__("sync");
  65. return retloc;
  66. }
  67. #endif
  68. void *qe_muram_addr(uint offset)
  69. {
  70. return (void *)&qe_immr->muram[offset];
  71. }
  72. #ifdef CONFIG_QE
  73. static void qe_sdma_init(void)
  74. {
  75. volatile sdma_t *p;
  76. uint sdma_buffer_base;
  77. p = (volatile sdma_t *)&qe_immr->sdma;
  78. /* All of DMA transaction in bus 1 */
  79. out_be32(&p->sdaqr, 0);
  80. out_be32(&p->sdaqmr, 0);
  81. /* Allocate 2KB temporary buffer for sdma */
  82. sdma_buffer_base = qe_muram_alloc(2048, 4096);
  83. out_be32(&p->sdwbcr, sdma_buffer_base & QE_SDEBCR_BA_MASK);
  84. /* Clear sdma status */
  85. out_be32(&p->sdsr, 0x03000000);
  86. /* Enable global mode on bus 1, and 2KB buffer size */
  87. out_be32(&p->sdmr, QE_SDMR_GLB_1_MSK | (0x3 << QE_SDMR_CEN_SHIFT));
  88. }
  89. /* This table is a list of the serial numbers of the Threads, taken from the
  90. * "SNUM Table" chart in the QE Reference Manual. The order is not important,
  91. * we just need to know what the SNUMs are for the threads.
  92. */
  93. static u8 thread_snum[] = {
  94. /* Evthreads 16-29 are not supported in MPC8309 */
  95. #if !defined(CONFIG_MPC8309)
  96. 0x04, 0x05, 0x0c, 0x0d,
  97. 0x14, 0x15, 0x1c, 0x1d,
  98. 0x24, 0x25, 0x2c, 0x2d,
  99. 0x34, 0x35,
  100. #endif
  101. 0x88, 0x89, 0x98, 0x99,
  102. 0xa8, 0xa9, 0xb8, 0xb9,
  103. 0xc8, 0xc9, 0xd8, 0xd9,
  104. 0xe8, 0xe9, 0x08, 0x09,
  105. 0x18, 0x19, 0x28, 0x29,
  106. 0x38, 0x39, 0x48, 0x49,
  107. 0x58, 0x59, 0x68, 0x69,
  108. 0x78, 0x79, 0x80, 0x81
  109. };
  110. static void qe_snums_init(void)
  111. {
  112. int i;
  113. for (i = 0; i < QE_NUM_OF_SNUM; i++) {
  114. snums[i].state = QE_SNUM_STATE_FREE;
  115. snums[i].num = thread_snum[i];
  116. }
  117. }
  118. int qe_get_snum(void)
  119. {
  120. int snum = -EBUSY;
  121. int i;
  122. for (i = 0; i < QE_NUM_OF_SNUM; i++) {
  123. if (snums[i].state == QE_SNUM_STATE_FREE) {
  124. snums[i].state = QE_SNUM_STATE_USED;
  125. snum = snums[i].num;
  126. break;
  127. }
  128. }
  129. return snum;
  130. }
  131. void qe_put_snum(u8 snum)
  132. {
  133. int i;
  134. for (i = 0; i < QE_NUM_OF_SNUM; i++) {
  135. if (snums[i].num == snum) {
  136. snums[i].state = QE_SNUM_STATE_FREE;
  137. break;
  138. }
  139. }
  140. }
  141. void qe_init(uint qe_base)
  142. {
  143. /* Init the QE IMMR base */
  144. qe_immr = (qe_map_t *)qe_base;
  145. #ifdef CONFIG_SYS_QE_FMAN_FW_IN_NOR
  146. /*
  147. * Upload microcode to IRAM for those SOCs which do not have ROM in QE.
  148. */
  149. qe_upload_firmware((const void *)CONFIG_SYS_QE_FW_ADDR);
  150. /* enable the microcode in IRAM */
  151. out_be32(&qe_immr->iram.iready,QE_IRAM_READY);
  152. #endif
  153. gd->arch.mp_alloc_base = QE_DATAONLY_BASE;
  154. gd->arch.mp_alloc_top = gd->arch.mp_alloc_base + QE_DATAONLY_SIZE;
  155. qe_sdma_init();
  156. qe_snums_init();
  157. }
  158. #endif
  159. #ifdef CONFIG_U_QE
  160. void u_qe_init(void)
  161. {
  162. qe_immr = (qe_map_t *)(CONFIG_SYS_IMMR + QE_IMMR_OFFSET);
  163. void *addr = (void *)CONFIG_SYS_QE_FW_ADDR;
  164. #ifdef CONFIG_SYS_QE_FMAN_FW_IN_MMC
  165. int dev = CONFIG_SYS_MMC_ENV_DEV;
  166. u32 cnt = CONFIG_SYS_QE_FMAN_FW_LENGTH / 512;
  167. u32 blk = CONFIG_SYS_QE_FW_ADDR / 512;
  168. if (mmc_initialize(gd->bd)) {
  169. printf("%s: mmc_initialize() failed\n", __func__);
  170. return;
  171. }
  172. addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH);
  173. struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
  174. if (!mmc) {
  175. free(addr);
  176. printf("\nMMC cannot find device for ucode\n");
  177. } else {
  178. printf("\nMMC read: dev # %u, block # %u, count %u ...\n",
  179. dev, blk, cnt);
  180. mmc_init(mmc);
  181. (void)mmc->block_dev.block_read(&mmc->block_dev, blk, cnt,
  182. addr);
  183. /* flush cache after read */
  184. flush_cache((ulong)addr, cnt * 512);
  185. }
  186. #endif
  187. u_qe_upload_firmware(addr);
  188. out_be32(&qe_immr->iram.iready, QE_IRAM_READY);
  189. #ifdef CONFIG_SYS_QE_FMAN_FW_IN_MMC
  190. free(addr);
  191. #endif
  192. }
  193. #endif
  194. #ifdef CONFIG_U_QE
  195. void u_qe_resume(void)
  196. {
  197. qe_map_t *qe_immrr;
  198. qe_immrr = (qe_map_t *)(CONFIG_SYS_IMMR + QE_IMMR_OFFSET);
  199. u_qe_firmware_resume((const void *)CONFIG_SYS_QE_FW_ADDR, qe_immrr);
  200. out_be32(&qe_immrr->iram.iready, QE_IRAM_READY);
  201. }
  202. #endif
  203. void qe_reset(void)
  204. {
  205. qe_issue_cmd(QE_RESET, QE_CR_SUBBLOCK_INVALID,
  206. (u8) QE_CR_PROTOCOL_UNSPECIFIED, 0);
  207. }
  208. #ifdef CONFIG_QE
  209. void qe_assign_page(uint snum, uint para_ram_base)
  210. {
  211. u32 cecr;
  212. out_be32(&qe_immr->cp.cecdr, para_ram_base);
  213. out_be32(&qe_immr->cp.cecr, ((u32) snum<<QE_CR_ASSIGN_PAGE_SNUM_SHIFT)
  214. | QE_CR_FLG | QE_ASSIGN_PAGE);
  215. /* Wait for the QE_CR_FLG to clear */
  216. do {
  217. cecr = in_be32(&qe_immr->cp.cecr);
  218. } while (cecr & QE_CR_FLG );
  219. return;
  220. }
  221. #endif
  222. /*
  223. * brg: 0~15 as BRG1~BRG16
  224. rate: baud rate
  225. * BRG input clock comes from the BRGCLK (internal clock generated from
  226. the QE clock, it is one-half of the QE clock), If need the clock source
  227. from CLKn pin, we have te change the function.
  228. */
  229. #define BRG_CLK (gd->arch.brg_clk)
  230. #ifdef CONFIG_QE
  231. int qe_set_brg(uint brg, uint rate)
  232. {
  233. volatile uint *bp;
  234. u32 divisor;
  235. int div16 = 0;
  236. if (brg >= QE_NUM_OF_BRGS)
  237. return -EINVAL;
  238. bp = (uint *)&qe_immr->brg.brgc1;
  239. bp += brg;
  240. divisor = (BRG_CLK / rate);
  241. if (divisor > QE_BRGC_DIVISOR_MAX + 1) {
  242. div16 = 1;
  243. divisor /= 16;
  244. }
  245. *bp = ((divisor - 1) << QE_BRGC_DIVISOR_SHIFT) | QE_BRGC_ENABLE;
  246. __asm__ __volatile__("sync");
  247. if (div16) {
  248. *bp |= QE_BRGC_DIV16;
  249. __asm__ __volatile__("sync");
  250. }
  251. return 0;
  252. }
  253. #endif
  254. /* Set ethernet MII clock master
  255. */
  256. int qe_set_mii_clk_src(int ucc_num)
  257. {
  258. u32 cmxgcr;
  259. /* check if the UCC number is in range. */
  260. if ((ucc_num > UCC_MAX_NUM - 1) || (ucc_num < 0)) {
  261. printf("%s: ucc num not in ranges\n", __FUNCTION__);
  262. return -EINVAL;
  263. }
  264. cmxgcr = in_be32(&qe_immr->qmx.cmxgcr);
  265. cmxgcr &= ~QE_CMXGCR_MII_ENET_MNG_MASK;
  266. cmxgcr |= (ucc_num <<QE_CMXGCR_MII_ENET_MNG_SHIFT);
  267. out_be32(&qe_immr->qmx.cmxgcr, cmxgcr);
  268. return 0;
  269. }
  270. /* Firmware information stored here for qe_get_firmware_info() */
  271. static struct qe_firmware_info qe_firmware_info;
  272. /*
  273. * Set to 1 if QE firmware has been uploaded, and therefore
  274. * qe_firmware_info contains valid data.
  275. */
  276. static int qe_firmware_uploaded;
  277. /*
  278. * Upload a QE microcode
  279. *
  280. * This function is a worker function for qe_upload_firmware(). It does
  281. * the actual uploading of the microcode.
  282. */
  283. static void qe_upload_microcode(const void *base,
  284. const struct qe_microcode *ucode)
  285. {
  286. const u32 *code = base + be32_to_cpu(ucode->code_offset);
  287. unsigned int i;
  288. if (ucode->major || ucode->minor || ucode->revision)
  289. printf("QE: uploading microcode '%s' version %u.%u.%u\n",
  290. (char *)ucode->id, (u16)ucode->major, (u16)ucode->minor,
  291. (u16)ucode->revision);
  292. else
  293. printf("QE: uploading microcode '%s'\n", (char *)ucode->id);
  294. /* Use auto-increment */
  295. out_be32(&qe_immr->iram.iadd, be32_to_cpu(ucode->iram_offset) |
  296. QE_IRAM_IADD_AIE | QE_IRAM_IADD_BADDR);
  297. for (i = 0; i < be32_to_cpu(ucode->count); i++)
  298. out_be32(&qe_immr->iram.idata, be32_to_cpu(code[i]));
  299. }
  300. /*
  301. * Upload a microcode to the I-RAM at a specific address.
  302. *
  303. * See docs/README.qe_firmware for information on QE microcode uploading.
  304. *
  305. * Currently, only version 1 is supported, so the 'version' field must be
  306. * set to 1.
  307. *
  308. * The SOC model and revision are not validated, they are only displayed for
  309. * informational purposes.
  310. *
  311. * 'calc_size' is the calculated size, in bytes, of the firmware structure and
  312. * all of the microcode structures, minus the CRC.
  313. *
  314. * 'length' is the size that the structure says it is, including the CRC.
  315. */
  316. int qe_upload_firmware(const struct qe_firmware *firmware)
  317. {
  318. unsigned int i;
  319. unsigned int j;
  320. u32 crc;
  321. size_t calc_size = sizeof(struct qe_firmware);
  322. size_t length;
  323. const struct qe_header *hdr;
  324. #ifdef CONFIG_DEEP_SLEEP
  325. #ifdef CONFIG_ARCH_LS1021A
  326. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  327. #else
  328. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  329. #endif
  330. #endif
  331. if (!firmware) {
  332. printf("Invalid address\n");
  333. return -EINVAL;
  334. }
  335. hdr = &firmware->header;
  336. length = be32_to_cpu(hdr->length);
  337. /* Check the magic */
  338. if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
  339. (hdr->magic[2] != 'F')) {
  340. printf("QE microcode not found\n");
  341. #ifdef CONFIG_DEEP_SLEEP
  342. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_QE_DISABLE);
  343. #endif
  344. return -EPERM;
  345. }
  346. /* Check the version */
  347. if (hdr->version != 1) {
  348. printf("Unsupported version\n");
  349. return -EPERM;
  350. }
  351. /* Validate some of the fields */
  352. if ((firmware->count < 1) || (firmware->count > MAX_QE_RISC)) {
  353. printf("Invalid data\n");
  354. return -EINVAL;
  355. }
  356. /* Validate the length and check if there's a CRC */
  357. calc_size += (firmware->count - 1) * sizeof(struct qe_microcode);
  358. for (i = 0; i < firmware->count; i++)
  359. /*
  360. * For situations where the second RISC uses the same microcode
  361. * as the first, the 'code_offset' and 'count' fields will be
  362. * zero, so it's okay to add those.
  363. */
  364. calc_size += sizeof(u32) *
  365. be32_to_cpu(firmware->microcode[i].count);
  366. /* Validate the length */
  367. if (length != calc_size + sizeof(u32)) {
  368. printf("Invalid length\n");
  369. return -EPERM;
  370. }
  371. /*
  372. * Validate the CRC. We would normally call crc32_no_comp(), but that
  373. * function isn't available unless you turn on JFFS support.
  374. */
  375. crc = be32_to_cpu(*(u32 *)((void *)firmware + calc_size));
  376. if (crc != (crc32(-1, (const void *) firmware, calc_size) ^ -1)) {
  377. printf("Firmware CRC is invalid\n");
  378. return -EIO;
  379. }
  380. /*
  381. * If the microcode calls for it, split the I-RAM.
  382. */
  383. if (!firmware->split) {
  384. out_be16(&qe_immr->cp.cercr,
  385. in_be16(&qe_immr->cp.cercr) | QE_CP_CERCR_CIR);
  386. }
  387. if (firmware->soc.model)
  388. printf("Firmware '%s' for %u V%u.%u\n",
  389. firmware->id, be16_to_cpu(firmware->soc.model),
  390. firmware->soc.major, firmware->soc.minor);
  391. else
  392. printf("Firmware '%s'\n", firmware->id);
  393. /*
  394. * The QE only supports one microcode per RISC, so clear out all the
  395. * saved microcode information and put in the new.
  396. */
  397. memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
  398. strncpy(qe_firmware_info.id, (char *)firmware->id, 62);
  399. qe_firmware_info.extended_modes = firmware->extended_modes;
  400. memcpy(qe_firmware_info.vtraps, firmware->vtraps,
  401. sizeof(firmware->vtraps));
  402. qe_firmware_uploaded = 1;
  403. /* Loop through each microcode. */
  404. for (i = 0; i < firmware->count; i++) {
  405. const struct qe_microcode *ucode = &firmware->microcode[i];
  406. /* Upload a microcode if it's present */
  407. if (ucode->code_offset)
  408. qe_upload_microcode(firmware, ucode);
  409. /* Program the traps for this processor */
  410. for (j = 0; j < 16; j++) {
  411. u32 trap = be32_to_cpu(ucode->traps[j]);
  412. if (trap)
  413. out_be32(&qe_immr->rsp[i].tibcr[j], trap);
  414. }
  415. /* Enable traps */
  416. out_be32(&qe_immr->rsp[i].eccr, be32_to_cpu(ucode->eccr));
  417. }
  418. return 0;
  419. }
  420. #ifdef CONFIG_U_QE
  421. /*
  422. * Upload a microcode to the I-RAM at a specific address.
  423. *
  424. * See docs/README.qe_firmware for information on QE microcode uploading.
  425. *
  426. * Currently, only version 1 is supported, so the 'version' field must be
  427. * set to 1.
  428. *
  429. * The SOC model and revision are not validated, they are only displayed for
  430. * informational purposes.
  431. *
  432. * 'calc_size' is the calculated size, in bytes, of the firmware structure and
  433. * all of the microcode structures, minus the CRC.
  434. *
  435. * 'length' is the size that the structure says it is, including the CRC.
  436. */
  437. int u_qe_upload_firmware(const struct qe_firmware *firmware)
  438. {
  439. unsigned int i;
  440. unsigned int j;
  441. u32 crc;
  442. size_t calc_size = sizeof(struct qe_firmware);
  443. size_t length;
  444. const struct qe_header *hdr;
  445. #ifdef CONFIG_DEEP_SLEEP
  446. #ifdef CONFIG_ARCH_LS1021A
  447. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  448. #else
  449. ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  450. #endif
  451. #endif
  452. if (!firmware) {
  453. printf("Invalid address\n");
  454. return -EINVAL;
  455. }
  456. hdr = &firmware->header;
  457. length = be32_to_cpu(hdr->length);
  458. /* Check the magic */
  459. if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
  460. (hdr->magic[2] != 'F')) {
  461. printf("Not a microcode\n");
  462. #ifdef CONFIG_DEEP_SLEEP
  463. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_QE_DISABLE);
  464. #endif
  465. return -EPERM;
  466. }
  467. /* Check the version */
  468. if (hdr->version != 1) {
  469. printf("Unsupported version\n");
  470. return -EPERM;
  471. }
  472. /* Validate some of the fields */
  473. if ((firmware->count < 1) || (firmware->count > MAX_QE_RISC)) {
  474. printf("Invalid data\n");
  475. return -EINVAL;
  476. }
  477. /* Validate the length and check if there's a CRC */
  478. calc_size += (firmware->count - 1) * sizeof(struct qe_microcode);
  479. for (i = 0; i < firmware->count; i++)
  480. /*
  481. * For situations where the second RISC uses the same microcode
  482. * as the first, the 'code_offset' and 'count' fields will be
  483. * zero, so it's okay to add those.
  484. */
  485. calc_size += sizeof(u32) *
  486. be32_to_cpu(firmware->microcode[i].count);
  487. /* Validate the length */
  488. if (length != calc_size + sizeof(u32)) {
  489. printf("Invalid length\n");
  490. return -EPERM;
  491. }
  492. /*
  493. * Validate the CRC. We would normally call crc32_no_comp(), but that
  494. * function isn't available unless you turn on JFFS support.
  495. */
  496. crc = be32_to_cpu(*(u32 *)((void *)firmware + calc_size));
  497. if (crc != (crc32(-1, (const void *)firmware, calc_size) ^ -1)) {
  498. printf("Firmware CRC is invalid\n");
  499. return -EIO;
  500. }
  501. /*
  502. * If the microcode calls for it, split the I-RAM.
  503. */
  504. if (!firmware->split) {
  505. out_be16(&qe_immr->cp.cercr,
  506. in_be16(&qe_immr->cp.cercr) | QE_CP_CERCR_CIR);
  507. }
  508. if (firmware->soc.model)
  509. printf("Firmware '%s' for %u V%u.%u\n",
  510. firmware->id, be16_to_cpu(firmware->soc.model),
  511. firmware->soc.major, firmware->soc.minor);
  512. else
  513. printf("Firmware '%s'\n", firmware->id);
  514. /* Loop through each microcode. */
  515. for (i = 0; i < firmware->count; i++) {
  516. const struct qe_microcode *ucode = &firmware->microcode[i];
  517. /* Upload a microcode if it's present */
  518. if (ucode->code_offset)
  519. qe_upload_microcode(firmware, ucode);
  520. /* Program the traps for this processor */
  521. for (j = 0; j < 16; j++) {
  522. u32 trap = be32_to_cpu(ucode->traps[j]);
  523. if (trap)
  524. out_be32(&qe_immr->rsp[i].tibcr[j], trap);
  525. }
  526. /* Enable traps */
  527. out_be32(&qe_immr->rsp[i].eccr, be32_to_cpu(ucode->eccr));
  528. }
  529. return 0;
  530. }
  531. #endif
  532. #ifdef CONFIG_U_QE
  533. int u_qe_firmware_resume(const struct qe_firmware *firmware, qe_map_t *qe_immrr)
  534. {
  535. unsigned int i;
  536. unsigned int j;
  537. const struct qe_header *hdr;
  538. const u32 *code;
  539. #ifdef CONFIG_DEEP_SLEEP
  540. #ifdef CONFIG_PPC
  541. ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  542. #else
  543. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  544. #endif
  545. #endif
  546. if (!firmware)
  547. return -EINVAL;
  548. hdr = &firmware->header;
  549. /* Check the magic */
  550. if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
  551. (hdr->magic[2] != 'F')) {
  552. #ifdef CONFIG_DEEP_SLEEP
  553. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_QE_DISABLE);
  554. #endif
  555. return -EPERM;
  556. }
  557. /*
  558. * If the microcode calls for it, split the I-RAM.
  559. */
  560. if (!firmware->split) {
  561. out_be16(&qe_immrr->cp.cercr,
  562. in_be16(&qe_immrr->cp.cercr) | QE_CP_CERCR_CIR);
  563. }
  564. /* Loop through each microcode. */
  565. for (i = 0; i < firmware->count; i++) {
  566. const struct qe_microcode *ucode = &firmware->microcode[i];
  567. /* Upload a microcode if it's present */
  568. if (!ucode->code_offset)
  569. return 0;
  570. code = (const void *)firmware + be32_to_cpu(ucode->code_offset);
  571. /* Use auto-increment */
  572. out_be32(&qe_immrr->iram.iadd, be32_to_cpu(ucode->iram_offset) |
  573. QE_IRAM_IADD_AIE | QE_IRAM_IADD_BADDR);
  574. for (i = 0; i < be32_to_cpu(ucode->count); i++)
  575. out_be32(&qe_immrr->iram.idata, be32_to_cpu(code[i]));
  576. /* Program the traps for this processor */
  577. for (j = 0; j < 16; j++) {
  578. u32 trap = be32_to_cpu(ucode->traps[j]);
  579. if (trap)
  580. out_be32(&qe_immrr->rsp[i].tibcr[j], trap);
  581. }
  582. /* Enable traps */
  583. out_be32(&qe_immrr->rsp[i].eccr, be32_to_cpu(ucode->eccr));
  584. }
  585. return 0;
  586. }
  587. #endif
  588. struct qe_firmware_info *qe_get_firmware_info(void)
  589. {
  590. return qe_firmware_uploaded ? &qe_firmware_info : NULL;
  591. }
  592. static int qe_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  593. {
  594. ulong addr;
  595. if (argc < 3)
  596. return cmd_usage(cmdtp);
  597. if (strcmp(argv[1], "fw") == 0) {
  598. addr = simple_strtoul(argv[2], NULL, 16);
  599. if (!addr) {
  600. printf("Invalid address\n");
  601. return -EINVAL;
  602. }
  603. /*
  604. * If a length was supplied, compare that with the 'length'
  605. * field.
  606. */
  607. if (argc > 3) {
  608. ulong length = simple_strtoul(argv[3], NULL, 16);
  609. struct qe_firmware *firmware = (void *) addr;
  610. if (length != be32_to_cpu(firmware->header.length)) {
  611. printf("Length mismatch\n");
  612. return -EINVAL;
  613. }
  614. }
  615. return qe_upload_firmware((const struct qe_firmware *) addr);
  616. }
  617. return cmd_usage(cmdtp);
  618. }
  619. U_BOOT_CMD(
  620. qe, 4, 0, qe_cmd,
  621. "QUICC Engine commands",
  622. "fw <addr> [<length>] - Upload firmware binary at address <addr> to "
  623. "the QE,\n"
  624. "\twith optional length <length> verification."
  625. );