mc_sys.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Freescale Layerscape MC I/O wrapper
  4. *
  5. * Copyright (C) 2013-2015 Freescale Semiconductor, Inc.
  6. * Author: German Rivera <German.Rivera@freescale.com>
  7. */
  8. #include <fsl-mc/fsl_mc_sys.h>
  9. #include <fsl-mc/fsl_mc_cmd.h>
  10. #include <common.h>
  11. #include <errno.h>
  12. #include <asm/io.h>
  13. #define MC_CMD_HDR_READ_CMDID(_hdr) \
  14. ((uint16_t)mc_dec((_hdr), MC_CMD_HDR_CMDID_O, MC_CMD_HDR_CMDID_S))
  15. /**
  16. * mc_send_command - Send MC command and wait for response
  17. *
  18. * @mc_io: Pointer to MC I/O object to be used
  19. * @cmd: MC command buffer. On input, it contains the command to send to the MC.
  20. * On output, it contains the response from the MC if any.
  21. *
  22. * Depending on the sharing option specified when creating the MC portal
  23. * wrapper, this function will use a spinlock or mutex to ensure exclusive
  24. * access to the MC portal from the point when the command is sent until a
  25. * response is received from the MC.
  26. */
  27. int mc_send_command(struct fsl_mc_io *mc_io,
  28. struct mc_command *cmd)
  29. {
  30. enum mc_cmd_status status;
  31. int timeout = 12000;
  32. mc_write_command(mc_io->mmio_regs, cmd);
  33. for ( ; ; ) {
  34. status = mc_read_response(mc_io->mmio_regs, cmd);
  35. if (status != MC_CMD_STATUS_READY)
  36. break;
  37. if (--timeout == 0) {
  38. printf("Error: Timeout waiting for MC response\n");
  39. return -ETIMEDOUT;
  40. }
  41. udelay(500);
  42. }
  43. if (status != MC_CMD_STATUS_OK) {
  44. printf("Error: MC command failed (portal: %p, obj handle: %#x, command: %#x, status: %#x)\n",
  45. mc_io->mmio_regs,
  46. (unsigned int)MC_CMD_HDR_READ_TOKEN(cmd->header),
  47. (unsigned int)MC_CMD_HDR_READ_CMDID(cmd->header),
  48. (unsigned int)status);
  49. return -EIO;
  50. }
  51. return 0;
  52. }