2 * Freescale Layerscape MC I/O wrapper
4 * Copyright (C) 2013-2015 Freescale Semiconductor, Inc.
5 * Author: German Rivera <German.Rivera@freescale.com>
7 * SPDX-License-Identifier: GPL-2.0+
10 #include <fsl-mc/fsl_mc_sys.h>
11 #include <fsl-mc/fsl_mc_cmd.h>
16 #define MC_CMD_HDR_READ_CMDID(_hdr) \
17 ((uint16_t)mc_dec((_hdr), MC_CMD_HDR_CMDID_O, MC_CMD_HDR_CMDID_S))
20 * mc_send_command - Send MC command and wait for response
22 * @mc_io: Pointer to MC I/O object to be used
23 * @cmd: MC command buffer. On input, it contains the command to send to the MC.
24 * On output, it contains the response from the MC if any.
26 * Depending on the sharing option specified when creating the MC portal
27 * wrapper, this function will use a spinlock or mutex to ensure exclusive
28 * access to the MC portal from the point when the command is sent until a
29 * response is received from the MC.
31 int mc_send_command(struct fsl_mc_io *mc_io,
32 struct mc_command *cmd)
34 enum mc_cmd_status status;
37 mc_write_command(mc_io->mmio_regs, cmd);
40 status = mc_read_response(mc_io->mmio_regs, cmd);
41 if (status != MC_CMD_STATUS_READY)
45 printf("Error: Timeout waiting for MC response\n");
52 if (status != MC_CMD_STATUS_OK) {
53 printf("Error: MC command failed (portal: %p, obj handle: %#x, command: %#x, status: %#x)\n",
55 (unsigned int)MC_CMD_HDR_READ_TOKEN(cmd->header),
56 (unsigned int)MC_CMD_HDR_READ_CMDID(cmd->header),
57 (unsigned int)status);