blob: 926cf81a07f0f06a7e8d0a87e30712ceead55fba [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kumar Galac916d7c2011-04-13 08:37:44 -05002/*
3 * Copyright 2009-2011 Freescale Semiconductor, Inc.
4 * Dave Liu <daveliu@freescale.com>
Kumar Galac916d7c2011-04-13 08:37:44 -05005 */
6#include <common.h>
Simon Glassc7694dd2019-08-01 09:46:46 -06007#include <env.h>
Kumar Galac916d7c2011-04-13 08:37:44 -05008#include <malloc.h>
9#include <asm/io.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090010#include <linux/errno.h>
Simon Glass3db71102019-11-14 12:57:16 -070011#include <u-boot/crc.h>
Kumar Galac916d7c2011-04-13 08:37:44 -050012
13#include "fm.h"
Qianyu Gong2459afb2016-02-18 13:01:59 +080014#include <fsl_qe.h> /* For struct qe_firmware */
Kumar Galac916d7c2011-04-13 08:37:44 -050015
Kumar Galac916d7c2011-04-13 08:37:44 -050016#include <nand.h>
Kumar Galac916d7c2011-04-13 08:37:44 -050017#include <spi_flash.h>
Kumar Galac916d7c2011-04-13 08:37:44 -050018#include <mmc.h>
Rajesh Bhagat382c53f2018-11-05 18:02:23 +000019
20#ifdef CONFIG_ARM64
21#include <asm/armv8/mmu.h>
22#include <asm/arch/cpu.h>
Kumar Galac916d7c2011-04-13 08:37:44 -050023#endif
24
25struct fm_muram muram[CONFIG_SYS_NUM_FMAN];
26
Hou Zhiqiang9fc29db2015-10-26 19:47:44 +080027void *fm_muram_base(int fm_idx)
Kumar Galac916d7c2011-04-13 08:37:44 -050028{
29 return muram[fm_idx].base;
30}
31
Hou Zhiqiang9fc29db2015-10-26 19:47:44 +080032void *fm_muram_alloc(int fm_idx, size_t size, ulong align)
Kumar Galac916d7c2011-04-13 08:37:44 -050033{
Hou Zhiqiang9fc29db2015-10-26 19:47:44 +080034 void *ret;
35 ulong align_mask;
36 size_t off;
37 void *save;
Kumar Galac916d7c2011-04-13 08:37:44 -050038
39 align_mask = align - 1;
40 save = muram[fm_idx].alloc;
41
Hou Zhiqiang9fc29db2015-10-26 19:47:44 +080042 off = (ulong)save & align_mask;
Kumar Galac916d7c2011-04-13 08:37:44 -050043 if (off != 0)
44 muram[fm_idx].alloc += (align - off);
45 off = size & align_mask;
46 if (off != 0)
47 size += (align - off);
48 if ((muram[fm_idx].alloc + size) >= muram[fm_idx].top) {
49 muram[fm_idx].alloc = save;
50 printf("%s: run out of ram.\n", __func__);
Hou Zhiqiang9fc29db2015-10-26 19:47:44 +080051 return NULL;
Kumar Galac916d7c2011-04-13 08:37:44 -050052 }
53
54 ret = muram[fm_idx].alloc;
55 muram[fm_idx].alloc += size;
56 memset((void *)ret, 0, size);
57
58 return ret;
59}
60
61static void fm_init_muram(int fm_idx, void *reg)
62{
Hou Zhiqiang9fc29db2015-10-26 19:47:44 +080063 void *base = reg;
Kumar Galac916d7c2011-04-13 08:37:44 -050064
65 muram[fm_idx].base = base;
66 muram[fm_idx].size = CONFIG_SYS_FM_MURAM_SIZE;
67 muram[fm_idx].alloc = base + FM_MURAM_RES_SIZE;
68 muram[fm_idx].top = base + CONFIG_SYS_FM_MURAM_SIZE;
69}
70
71/*
72 * fm_upload_ucode - Fman microcode upload worker function
73 *
74 * This function does the actual uploading of an Fman microcode
75 * to an Fman.
76 */
77static void fm_upload_ucode(int fm_idx, struct fm_imem *imem,
78 u32 *ucode, unsigned int size)
79{
80 unsigned int i;
81 unsigned int timeout = 1000000;
82
83 /* enable address auto increase */
84 out_be32(&imem->iadd, IRAM_IADD_AIE);
85 /* write microcode to IRAM */
86 for (i = 0; i < size / 4; i++)
Hou Zhiqiang648bde62015-10-26 19:47:43 +080087 out_be32(&imem->idata, (be32_to_cpu(ucode[i])));
Kumar Galac916d7c2011-04-13 08:37:44 -050088
89 /* verify if the writing is over */
90 out_be32(&imem->iadd, 0);
Hou Zhiqiang648bde62015-10-26 19:47:43 +080091 while ((in_be32(&imem->idata) != be32_to_cpu(ucode[0])) && --timeout)
Kumar Galac916d7c2011-04-13 08:37:44 -050092 ;
93 if (!timeout)
94 printf("Fman%u: microcode upload timeout\n", fm_idx + 1);
95
96 /* enable microcode from IRAM */
97 out_be32(&imem->iready, IRAM_READY);
98}
99
100/*
101 * Upload an Fman firmware
102 *
103 * This function is similar to qe_upload_firmware(), exception that it uploads
104 * a microcode to the Fman instead of the QE.
105 *
106 * Because the process for uploading a microcode to the Fman is similar for
107 * that of the QE, the QE firmware binary format is used for Fman microcode.
108 * It should be possible to unify these two functions, but for now we keep them
109 * separate.
110 */
111static int fman_upload_firmware(int fm_idx,
112 struct fm_imem *fm_imem,
113 const struct qe_firmware *firmware)
114{
115 unsigned int i;
116 u32 crc;
117 size_t calc_size = sizeof(struct qe_firmware);
118 size_t length;
119 const struct qe_header *hdr;
120
121 if (!firmware) {
122 printf("Fman%u: Invalid address for firmware\n", fm_idx + 1);
123 return -EINVAL;
124 }
125
126 hdr = &firmware->header;
127 length = be32_to_cpu(hdr->length);
128
129 /* Check the magic */
130 if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
131 (hdr->magic[2] != 'F')) {
132 printf("Fman%u: Data at %p is not a firmware\n", fm_idx + 1,
133 firmware);
134 return -EPERM;
135 }
136
137 /* Check the version */
138 if (hdr->version != 1) {
139 printf("Fman%u: Unsupported firmware version %u\n", fm_idx + 1,
140 hdr->version);
141 return -EPERM;
142 }
143
144 /* Validate some of the fields */
145 if ((firmware->count != 1)) {
146 printf("Fman%u: Invalid data in firmware header\n", fm_idx + 1);
147 return -EINVAL;
148 }
149
150 /* Validate the length and check if there's a CRC */
151 calc_size += (firmware->count - 1) * sizeof(struct qe_microcode);
152
153 for (i = 0; i < firmware->count; i++)
154 /*
155 * For situations where the second RISC uses the same microcode
156 * as the first, the 'code_offset' and 'count' fields will be
157 * zero, so it's okay to add those.
158 */
159 calc_size += sizeof(u32) *
160 be32_to_cpu(firmware->microcode[i].count);
161
162 /* Validate the length */
163 if (length != calc_size + sizeof(u32)) {
164 printf("Fman%u: Invalid length in firmware header\n",
165 fm_idx + 1);
166 return -EPERM;
167 }
168
169 /*
170 * Validate the CRC. We would normally call crc32_no_comp(), but that
171 * function isn't available unless you turn on JFFS support.
172 */
173 crc = be32_to_cpu(*(u32 *)((void *)firmware + calc_size));
174 if (crc != (crc32(-1, (const void *)firmware, calc_size) ^ -1)) {
175 printf("Fman%u: Firmware CRC is invalid\n", fm_idx + 1);
176 return -EIO;
177 }
178
179 /* Loop through each microcode. */
180 for (i = 0; i < firmware->count; i++) {
181 const struct qe_microcode *ucode = &firmware->microcode[i];
182
183 /* Upload a microcode if it's present */
Hou Zhiqiang648bde62015-10-26 19:47:43 +0800184 if (be32_to_cpu(ucode->code_offset)) {
Kumar Galac916d7c2011-04-13 08:37:44 -0500185 u32 ucode_size;
186 u32 *code;
187 printf("Fman%u: Uploading microcode version %u.%u.%u\n",
188 fm_idx + 1, ucode->major, ucode->minor,
189 ucode->revision);
Hou Zhiqiang648bde62015-10-26 19:47:43 +0800190 code = (void *)firmware +
191 be32_to_cpu(ucode->code_offset);
192 ucode_size = sizeof(u32) * be32_to_cpu(ucode->count);
Kumar Galac916d7c2011-04-13 08:37:44 -0500193 fm_upload_ucode(fm_idx, fm_imem, code, ucode_size);
194 }
195 }
196
197 return 0;
198}
199
200static u32 fm_assign_risc(int port_id)
201{
202 u32 risc_sel, val;
203 risc_sel = (port_id & 0x1) ? FMFPPRC_RISC2 : FMFPPRC_RISC1;
204 val = (port_id << FMFPPRC_PORTID_SHIFT) & FMFPPRC_PORTID_MASK;
205 val |= ((risc_sel << FMFPPRC_ORA_SHIFT) | risc_sel);
206
207 return val;
208}
209
210static void fm_init_fpm(struct fm_fpm *fpm)
211{
212 int i, port_id;
213 u32 val;
214
215 setbits_be32(&fpm->fmfpee, FMFPEE_EHM | FMFPEE_UEC |
216 FMFPEE_CER | FMFPEE_DER);
217
218 /* IM mode, each even port ID to RISC#1, each odd port ID to RISC#2 */
219
220 /* offline/parser port */
221 for (i = 0; i < MAX_NUM_OH_PORT; i++) {
222 port_id = OH_PORT_ID_BASE + i;
223 val = fm_assign_risc(port_id);
224 out_be32(&fpm->fpmprc, val);
225 }
226 /* Rx 1G port */
227 for (i = 0; i < MAX_NUM_RX_PORT_1G; i++) {
228 port_id = RX_PORT_1G_BASE + i;
229 val = fm_assign_risc(port_id);
230 out_be32(&fpm->fpmprc, val);
231 }
232 /* Tx 1G port */
233 for (i = 0; i < MAX_NUM_TX_PORT_1G; i++) {
234 port_id = TX_PORT_1G_BASE + i;
235 val = fm_assign_risc(port_id);
236 out_be32(&fpm->fpmprc, val);
237 }
238 /* Rx 10G port */
239 port_id = RX_PORT_10G_BASE;
240 val = fm_assign_risc(port_id);
241 out_be32(&fpm->fpmprc, val);
242 /* Tx 10G port */
243 port_id = TX_PORT_10G_BASE;
244 val = fm_assign_risc(port_id);
245 out_be32(&fpm->fpmprc, val);
246
247 /* disable the dispatch limit in IM case */
248 out_be32(&fpm->fpmflc, FMFP_FLC_DISP_LIM_NONE);
249 /* clear events */
250 out_be32(&fpm->fmfpee, FMFPEE_CLEAR_EVENT);
251
252 /* clear risc events */
253 for (i = 0; i < 4; i++)
254 out_be32(&fpm->fpmcev[i], 0xffffffff);
255
256 /* clear error */
257 out_be32(&fpm->fpmrcr, FMFP_RCR_MDEC | FMFP_RCR_IDEC);
258}
259
260static int fm_init_bmi(int fm_idx, struct fm_bmi_common *bmi)
261{
262 int blk, i, port_id;
Hou Zhiqiang9fc29db2015-10-26 19:47:44 +0800263 u32 val;
264 size_t offset;
265 void *base;
Kumar Galac916d7c2011-04-13 08:37:44 -0500266
267 /* alloc free buffer pool in MURAM */
268 base = fm_muram_alloc(fm_idx, FM_FREE_POOL_SIZE, FM_FREE_POOL_ALIGN);
269 if (!base) {
270 printf("%s: no muram for free buffer pool\n", __func__);
271 return -ENOMEM;
272 }
273 offset = base - fm_muram_base(fm_idx);
274
275 /* Need 128KB total free buffer pool size */
276 val = offset / 256;
277 blk = FM_FREE_POOL_SIZE / 256;
278 /* in IM, we must not begin from offset 0 in MURAM */
279 val |= ((blk - 1) << FMBM_CFG1_FBPS_SHIFT);
280 out_be32(&bmi->fmbm_cfg1, val);
281
282 /* disable all BMI interrupt */
283 out_be32(&bmi->fmbm_ier, FMBM_IER_DISABLE_ALL);
284
285 /* clear all events */
286 out_be32(&bmi->fmbm_ievr, FMBM_IEVR_CLEAR_ALL);
287
288 /*
289 * set port parameters - FMBM_PP_x
290 * max tasks 10G Rx/Tx=12, 1G Rx/Tx 4, others is 1
291 * max dma 10G Rx/Tx=3, others is 1
292 * set port FIFO size - FMBM_PFS_x
293 * 4KB for all Rx and Tx ports
294 */
295 /* offline/parser port */
296 for (i = 0; i < MAX_NUM_OH_PORT; i++) {
297 port_id = OH_PORT_ID_BASE + i - 1;
298 /* max tasks=1, max dma=1, no extra */
299 out_be32(&bmi->fmbm_pp[port_id], 0);
300 /* port FIFO size - 256 bytes, no extra */
301 out_be32(&bmi->fmbm_pfs[port_id], 0);
302 }
303 /* Rx 1G port */
304 for (i = 0; i < MAX_NUM_RX_PORT_1G; i++) {
305 port_id = RX_PORT_1G_BASE + i - 1;
306 /* max tasks=4, max dma=1, no extra */
307 out_be32(&bmi->fmbm_pp[port_id], FMBM_PP_MXT(4));
308 /* FIFO size - 4KB, no extra */
309 out_be32(&bmi->fmbm_pfs[port_id], FMBM_PFS_IFSZ(0xf));
310 }
311 /* Tx 1G port FIFO size - 4KB, no extra */
312 for (i = 0; i < MAX_NUM_TX_PORT_1G; i++) {
313 port_id = TX_PORT_1G_BASE + i - 1;
314 /* max tasks=4, max dma=1, no extra */
315 out_be32(&bmi->fmbm_pp[port_id], FMBM_PP_MXT(4));
316 /* FIFO size - 4KB, no extra */
317 out_be32(&bmi->fmbm_pfs[port_id], FMBM_PFS_IFSZ(0xf));
318 }
319 /* Rx 10G port */
320 port_id = RX_PORT_10G_BASE - 1;
321 /* max tasks=12, max dma=3, no extra */
322 out_be32(&bmi->fmbm_pp[port_id], FMBM_PP_MXT(12) | FMBM_PP_MXD(3));
323 /* FIFO size - 4KB, no extra */
324 out_be32(&bmi->fmbm_pfs[port_id], FMBM_PFS_IFSZ(0xf));
325
326 /* Tx 10G port */
327 port_id = TX_PORT_10G_BASE - 1;
328 /* max tasks=12, max dma=3, no extra */
329 out_be32(&bmi->fmbm_pp[port_id], FMBM_PP_MXT(12) | FMBM_PP_MXD(3));
330 /* FIFO size - 4KB, no extra */
331 out_be32(&bmi->fmbm_pfs[port_id], FMBM_PFS_IFSZ(0xf));
332
333 /* initialize internal buffers data base (linked list) */
334 out_be32(&bmi->fmbm_init, FMBM_INIT_START);
335
336 return 0;
337}
338
339static void fm_init_qmi(struct fm_qmi_common *qmi)
340{
Kumar Galac916d7c2011-04-13 08:37:44 -0500341 /* disable all error interrupts */
342 out_be32(&qmi->fmqm_eien, FMQM_EIEN_DISABLE_ALL);
343 /* clear all error events */
344 out_be32(&qmi->fmqm_eie, FMQM_EIE_CLEAR_ALL);
345
346 /* disable all interrupts */
347 out_be32(&qmi->fmqm_ien, FMQM_IEN_DISABLE_ALL);
348 /* clear all interrupts */
349 out_be32(&qmi->fmqm_ie, FMQM_IE_CLEAR_ALL);
350}
351
352/* Init common part of FM, index is fm num# like fm as above */
Rajesh Bhagat382c53f2018-11-05 18:02:23 +0000353#ifdef CONFIG_TFABOOT
354int fm_init_common(int index, struct ccsr_fman *reg)
355{
356 int rc;
357 void *addr = NULL;
358 enum boot_src src = get_boot_src();
359
360 if (src == BOOT_SOURCE_IFC_NOR) {
361 addr = (void *)(CONFIG_SYS_FMAN_FW_ADDR +
362 CONFIG_SYS_FSL_IFC_BASE);
363 } else if (src == BOOT_SOURCE_IFC_NAND) {
364 size_t fw_length = CONFIG_SYS_QE_FMAN_FW_LENGTH;
365
366 addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH);
367
368 rc = nand_read(get_nand_dev_by_index(0),
369 (loff_t)CONFIG_SYS_FMAN_FW_ADDR,
370 &fw_length, (u_char *)addr);
371 if (rc == -EUCLEAN) {
372 printf("NAND read of FMAN firmware at offset 0x%x failed %d\n",
373 CONFIG_SYS_FMAN_FW_ADDR, rc);
374 }
375 } else if (src == BOOT_SOURCE_QSPI_NOR) {
376 struct spi_flash *ucode_flash;
377
378 addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH);
379 int ret = 0;
380
381#ifdef CONFIG_DM_SPI_FLASH
382 struct udevice *new;
383
384 /* speed and mode will be read from DT */
385 ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS,
386 CONFIG_ENV_SPI_CS, 0, 0, &new);
387
388 ucode_flash = dev_get_uclass_priv(new);
389#else
390 ucode_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS,
391 CONFIG_ENV_SPI_CS,
392 CONFIG_ENV_SPI_MAX_HZ,
393 CONFIG_ENV_SPI_MODE);
394#endif
395 if (!ucode_flash) {
396 printf("SF: probe for ucode failed\n");
397 } else {
398 ret = spi_flash_read(ucode_flash,
399 CONFIG_SYS_FMAN_FW_ADDR +
400 CONFIG_SYS_FSL_QSPI_BASE,
401 CONFIG_SYS_QE_FMAN_FW_LENGTH,
402 addr);
403 if (ret)
404 printf("SF: read for ucode failed\n");
405 spi_flash_free(ucode_flash);
406 }
407 } else if (src == BOOT_SOURCE_SD_MMC) {
408 int dev = CONFIG_SYS_MMC_ENV_DEV;
409
410 addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH);
411 u32 cnt = CONFIG_SYS_QE_FMAN_FW_LENGTH / 512;
412 u32 blk = CONFIG_SYS_FMAN_FW_ADDR / 512;
413 struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
414
415 if (!mmc) {
416 printf("\nMMC cannot find device for ucode\n");
417 } else {
418 printf("\nMMC read: dev # %u, block # %u, count %u ...\n",
419 dev, blk, cnt);
420 mmc_init(mmc);
421 (void)blk_dread(mmc_get_blk_desc(mmc), blk, cnt,
422 addr);
423 }
424 } else {
425 addr = NULL;
426 }
427
428 /* Upload the Fman microcode if it's present */
429 rc = fman_upload_firmware(index, &reg->fm_imem, addr);
430 if (rc)
431 return rc;
432 env_set_addr("fman_ucode", addr);
433
434 fm_init_muram(index, &reg->muram);
435 fm_init_qmi(&reg->fm_qmi_common);
436 fm_init_fpm(&reg->fm_fpm);
437
438 /* clear DMA status */
439 setbits_be32(&reg->fm_dma.fmdmsr, FMDMSR_CLEAR_ALL);
440
441 /* set DMA mode */
442 setbits_be32(&reg->fm_dma.fmdmmr, FMDMMR_SBER);
443
444 return fm_init_bmi(index, &reg->fm_bmi_common);
445}
446#else
Kumar Galac916d7c2011-04-13 08:37:44 -0500447int fm_init_common(int index, struct ccsr_fman *reg)
448{
449 int rc;
Timur Tabif2717b42011-11-22 09:21:25 -0600450#if defined(CONFIG_SYS_QE_FMAN_FW_IN_NOR)
Zhao Qiangdcf1d772014-03-21 16:21:44 +0800451 void *addr = (void *)CONFIG_SYS_FMAN_FW_ADDR;
Timur Tabif2717b42011-11-22 09:21:25 -0600452#elif defined(CONFIG_SYS_QE_FMAN_FW_IN_NAND)
453 size_t fw_length = CONFIG_SYS_QE_FMAN_FW_LENGTH;
454 void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH);
Kumar Galac916d7c2011-04-13 08:37:44 -0500455
Grygorii Strashko750b34c2017-06-26 19:13:00 -0500456 rc = nand_read(get_nand_dev_by_index(0),
457 (loff_t)CONFIG_SYS_FMAN_FW_ADDR,
Kumar Galac916d7c2011-04-13 08:37:44 -0500458 &fw_length, (u_char *)addr);
459 if (rc == -EUCLEAN) {
460 printf("NAND read of FMAN firmware at offset 0x%x failed %d\n",
Zhao Qiangdcf1d772014-03-21 16:21:44 +0800461 CONFIG_SYS_FMAN_FW_ADDR, rc);
Kumar Galac916d7c2011-04-13 08:37:44 -0500462 }
Tom Rinicc1e98b2019-05-12 07:59:12 -0400463#elif defined(CONFIG_SYS_QE_FMAN_FW_IN_SPIFLASH)
Kumar Galac916d7c2011-04-13 08:37:44 -0500464 struct spi_flash *ucode_flash;
Timur Tabif2717b42011-11-22 09:21:25 -0600465 void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH);
Kumar Galac916d7c2011-04-13 08:37:44 -0500466 int ret = 0;
467
Qianyu Gong77b571d2016-08-03 11:04:25 +0800468#ifdef CONFIG_DM_SPI_FLASH
469 struct udevice *new;
470
471 /* speed and mode will be read from DT */
472 ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
473 0, 0, &new);
474
475 ucode_flash = dev_get_uclass_priv(new);
476#else
Kumar Galac916d7c2011-04-13 08:37:44 -0500477 ucode_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
478 CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
Qianyu Gong77b571d2016-08-03 11:04:25 +0800479#endif
Kumar Galac916d7c2011-04-13 08:37:44 -0500480 if (!ucode_flash)
481 printf("SF: probe for ucode failed\n");
482 else {
Zhao Qiangdcf1d772014-03-21 16:21:44 +0800483 ret = spi_flash_read(ucode_flash, CONFIG_SYS_FMAN_FW_ADDR,
Timur Tabif2717b42011-11-22 09:21:25 -0600484 CONFIG_SYS_QE_FMAN_FW_LENGTH, addr);
Kumar Galac916d7c2011-04-13 08:37:44 -0500485 if (ret)
486 printf("SF: read for ucode failed\n");
487 spi_flash_free(ucode_flash);
488 }
Timur Tabif2717b42011-11-22 09:21:25 -0600489#elif defined(CONFIG_SYS_QE_FMAN_FW_IN_MMC)
Kumar Galac916d7c2011-04-13 08:37:44 -0500490 int dev = CONFIG_SYS_MMC_ENV_DEV;
Timur Tabif2717b42011-11-22 09:21:25 -0600491 void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH);
492 u32 cnt = CONFIG_SYS_QE_FMAN_FW_LENGTH / 512;
Zhao Qiangdcf1d772014-03-21 16:21:44 +0800493 u32 blk = CONFIG_SYS_FMAN_FW_ADDR / 512;
Kumar Galac916d7c2011-04-13 08:37:44 -0500494 struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
495
496 if (!mmc)
497 printf("\nMMC cannot find device for ucode\n");
498 else {
499 printf("\nMMC read: dev # %u, block # %u, count %u ...\n",
500 dev, blk, cnt);
501 mmc_init(mmc);
Yinbo Zhuc3ced8a2018-09-25 14:47:06 +0800502 (void)blk_dread(mmc_get_blk_desc(mmc), blk, cnt,
Stephen Warren7c4213f2015-12-07 11:38:48 -0700503 addr);
Kumar Galac916d7c2011-04-13 08:37:44 -0500504 }
Liu Gang292dc6c2012-03-08 00:33:18 +0000505#elif defined(CONFIG_SYS_QE_FMAN_FW_IN_REMOTE)
Zhao Qiangdcf1d772014-03-21 16:21:44 +0800506 void *addr = (void *)CONFIG_SYS_FMAN_FW_ADDR;
York Sun7adefb52013-06-25 11:37:40 -0700507#else
508 void *addr = NULL;
Kumar Galac916d7c2011-04-13 08:37:44 -0500509#endif
510
511 /* Upload the Fman microcode if it's present */
512 rc = fman_upload_firmware(index, &reg->fm_imem, addr);
513 if (rc)
514 return rc;
Simon Glass018f5302017-08-03 12:22:10 -0600515 env_set_addr("fman_ucode", addr);
Kumar Galac916d7c2011-04-13 08:37:44 -0500516
517 fm_init_muram(index, &reg->muram);
518 fm_init_qmi(&reg->fm_qmi_common);
519 fm_init_fpm(&reg->fm_fpm);
520
521 /* clear DMA status */
522 setbits_be32(&reg->fm_dma.fmdmsr, FMDMSR_CLEAR_ALL);
523
524 /* set DMA mode */
525 setbits_be32(&reg->fm_dma.fmdmmr, FMDMMR_SBER);
526
527 return fm_init_bmi(index, &reg->fm_bmi_common);
528}
Rajesh Bhagat382c53f2018-11-05 18:02:23 +0000529#endif