1
2
3
4
5
6
7
8
9
10#include <fsl-mc/fsl_mc_sys.h>
11#include <fsl-mc/fsl_mc_cmd.h>
12#include <common.h>
13#include <errno.h>
14#include <asm/io.h>
15
16#define MC_CMD_HDR_READ_CMDID(_hdr) \
17 ((uint16_t)mc_dec((_hdr), MC_CMD_HDR_CMDID_O, MC_CMD_HDR_CMDID_S))
18
19
20
21
22
23
24
25
26
27
28
29
30
31int mc_send_command(struct fsl_mc_io *mc_io,
32 struct mc_command *cmd)
33{
34 enum mc_cmd_status status;
35 int timeout = 12000;
36
37 mc_write_command(mc_io->mmio_regs, cmd);
38
39 for ( ; ; ) {
40 status = mc_read_response(mc_io->mmio_regs, cmd);
41 if (status != MC_CMD_STATUS_READY)
42 break;
43
44 if (--timeout == 0) {
45 printf("Error: Timeout waiting for MC response\n");
46 return -ETIMEDOUT;
47 }
48
49 udelay(500);
50 }
51
52 if (status != MC_CMD_STATUS_OK) {
53 printf("Error: MC command failed (portal: %p, obj handle: %#x, command: %#x, status: %#x)\n",
54 mc_io->mmio_regs,
55 (unsigned int)MC_CMD_HDR_READ_TOKEN(cmd->header),
56 (unsigned int)MC_CMD_HDR_READ_CMDID(cmd->header),
57 (unsigned int)status);
58
59 return -EIO;
60 }
61
62 return 0;
63}
64