s5p_mfc_cmd_v5.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * linux/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c
  3. *
  4. * Copyright (C) 2011 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include "regs-mfc.h"
  13. #include "s5p_mfc_cmd.h"
  14. #include "s5p_mfc_common.h"
  15. #include "s5p_mfc_debug.h"
  16. /* This function is used to send a command to the MFC */
  17. int s5p_mfc_cmd_host2risc_v5(struct s5p_mfc_dev *dev, int cmd,
  18. struct s5p_mfc_cmd_args *args)
  19. {
  20. int cur_cmd;
  21. unsigned long timeout;
  22. timeout = jiffies + msecs_to_jiffies(MFC_BW_TIMEOUT);
  23. /* wait until host to risc command register becomes 'H2R_CMD_EMPTY' */
  24. do {
  25. if (time_after(jiffies, timeout)) {
  26. mfc_err("Timeout while waiting for hardware\n");
  27. return -EIO;
  28. }
  29. cur_cmd = mfc_read(dev, S5P_FIMV_HOST2RISC_CMD);
  30. } while (cur_cmd != S5P_FIMV_H2R_CMD_EMPTY);
  31. mfc_write(dev, args->arg[0], S5P_FIMV_HOST2RISC_ARG1);
  32. mfc_write(dev, args->arg[1], S5P_FIMV_HOST2RISC_ARG2);
  33. mfc_write(dev, args->arg[2], S5P_FIMV_HOST2RISC_ARG3);
  34. mfc_write(dev, args->arg[3], S5P_FIMV_HOST2RISC_ARG4);
  35. /* Issue the command */
  36. mfc_write(dev, cmd, S5P_FIMV_HOST2RISC_CMD);
  37. return 0;
  38. }
  39. /* Initialize the MFC */
  40. int s5p_mfc_sys_init_cmd_v5(struct s5p_mfc_dev *dev)
  41. {
  42. struct s5p_mfc_cmd_args h2r_args;
  43. memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
  44. h2r_args.arg[0] = dev->fw_size;
  45. return s5p_mfc_cmd_host2risc_v5(dev, S5P_FIMV_H2R_CMD_SYS_INIT,
  46. &h2r_args);
  47. }
  48. /* Suspend the MFC hardware */
  49. int s5p_mfc_sleep_cmd_v5(struct s5p_mfc_dev *dev)
  50. {
  51. struct s5p_mfc_cmd_args h2r_args;
  52. memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
  53. return s5p_mfc_cmd_host2risc_v5(dev, S5P_FIMV_H2R_CMD_SLEEP, &h2r_args);
  54. }
  55. /* Wake up the MFC hardware */
  56. int s5p_mfc_wakeup_cmd_v5(struct s5p_mfc_dev *dev)
  57. {
  58. struct s5p_mfc_cmd_args h2r_args;
  59. memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
  60. return s5p_mfc_cmd_host2risc_v5(dev, S5P_FIMV_H2R_CMD_WAKEUP,
  61. &h2r_args);
  62. }
  63. int s5p_mfc_open_inst_cmd_v5(struct s5p_mfc_ctx *ctx)
  64. {
  65. struct s5p_mfc_dev *dev = ctx->dev;
  66. struct s5p_mfc_cmd_args h2r_args;
  67. int ret;
  68. /* Preparing decoding - getting instance number */
  69. mfc_debug(2, "Getting instance number (codec: %d)\n", ctx->codec_mode);
  70. dev->curr_ctx = ctx->num;
  71. memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
  72. switch (ctx->codec_mode) {
  73. case S5P_MFC_CODEC_H264_DEC:
  74. h2r_args.arg[0] = S5P_FIMV_CODEC_H264_DEC;
  75. break;
  76. case S5P_MFC_CODEC_VC1_DEC:
  77. h2r_args.arg[0] = S5P_FIMV_CODEC_VC1_DEC;
  78. break;
  79. case S5P_MFC_CODEC_MPEG4_DEC:
  80. h2r_args.arg[0] = S5P_FIMV_CODEC_MPEG4_DEC;
  81. break;
  82. case S5P_MFC_CODEC_MPEG2_DEC:
  83. h2r_args.arg[0] = S5P_FIMV_CODEC_MPEG2_DEC;
  84. break;
  85. case S5P_MFC_CODEC_H263_DEC:
  86. h2r_args.arg[0] = S5P_FIMV_CODEC_H263_DEC;
  87. break;
  88. case S5P_MFC_CODEC_VC1RCV_DEC:
  89. h2r_args.arg[0] = S5P_FIMV_CODEC_VC1RCV_DEC;
  90. break;
  91. case S5P_MFC_CODEC_H264_ENC:
  92. h2r_args.arg[0] = S5P_FIMV_CODEC_H264_ENC;
  93. break;
  94. case S5P_MFC_CODEC_MPEG4_ENC:
  95. h2r_args.arg[0] = S5P_FIMV_CODEC_MPEG4_ENC;
  96. break;
  97. case S5P_MFC_CODEC_H263_ENC:
  98. h2r_args.arg[0] = S5P_FIMV_CODEC_H263_ENC;
  99. break;
  100. default:
  101. h2r_args.arg[0] = S5P_FIMV_CODEC_NONE;
  102. };
  103. h2r_args.arg[1] = 0; /* no crc & no pixelcache */
  104. h2r_args.arg[2] = ctx->ctx.ofs;
  105. h2r_args.arg[3] = ctx->ctx.size;
  106. ret = s5p_mfc_cmd_host2risc_v5(dev, S5P_FIMV_H2R_CMD_OPEN_INSTANCE,
  107. &h2r_args);
  108. if (ret) {
  109. mfc_err("Failed to create a new instance\n");
  110. ctx->state = MFCINST_ERROR;
  111. }
  112. return ret;
  113. }
  114. int s5p_mfc_close_inst_cmd_v5(struct s5p_mfc_ctx *ctx)
  115. {
  116. struct s5p_mfc_dev *dev = ctx->dev;
  117. struct s5p_mfc_cmd_args h2r_args;
  118. int ret;
  119. if (ctx->state == MFCINST_FREE) {
  120. mfc_err("Instance already returned\n");
  121. ctx->state = MFCINST_ERROR;
  122. return -EINVAL;
  123. }
  124. /* Closing decoding instance */
  125. mfc_debug(2, "Returning instance number %d\n", ctx->inst_no);
  126. dev->curr_ctx = ctx->num;
  127. memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
  128. h2r_args.arg[0] = ctx->inst_no;
  129. ret = s5p_mfc_cmd_host2risc_v5(dev, S5P_FIMV_H2R_CMD_CLOSE_INSTANCE,
  130. &h2r_args);
  131. if (ret) {
  132. mfc_err("Failed to return an instance\n");
  133. ctx->state = MFCINST_ERROR;
  134. return -EINVAL;
  135. }
  136. return 0;
  137. }
  138. /* Initialize cmd function pointers for MFC v5 */
  139. static struct s5p_mfc_hw_cmds s5p_mfc_cmds_v5 = {
  140. .cmd_host2risc = s5p_mfc_cmd_host2risc_v5,
  141. .sys_init_cmd = s5p_mfc_sys_init_cmd_v5,
  142. .sleep_cmd = s5p_mfc_sleep_cmd_v5,
  143. .wakeup_cmd = s5p_mfc_wakeup_cmd_v5,
  144. .open_inst_cmd = s5p_mfc_open_inst_cmd_v5,
  145. .close_inst_cmd = s5p_mfc_close_inst_cmd_v5,
  146. };
  147. struct s5p_mfc_hw_cmds *s5p_mfc_init_hw_cmds_v5(void)
  148. {
  149. return &s5p_mfc_cmds_v5;
  150. }