s5p_mfc_cmd.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * linux/drivers/media/video/s5p-mfc/s5p_mfc_cmd.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. static int s5p_mfc_cmd_host2risc(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(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(dev, S5P_FIMV_H2R_CMD_SYS_INIT, &h2r_args);
  46. }
  47. /* Suspend the MFC hardware */
  48. int s5p_mfc_sleep_cmd(struct s5p_mfc_dev *dev)
  49. {
  50. struct s5p_mfc_cmd_args h2r_args;
  51. memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
  52. return s5p_mfc_cmd_host2risc(dev, S5P_FIMV_H2R_CMD_SLEEP, &h2r_args);
  53. }
  54. /* Wake up the MFC hardware */
  55. int s5p_mfc_wakeup_cmd(struct s5p_mfc_dev *dev)
  56. {
  57. struct s5p_mfc_cmd_args h2r_args;
  58. memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
  59. return s5p_mfc_cmd_host2risc(dev, S5P_FIMV_H2R_CMD_WAKEUP, &h2r_args);
  60. }
  61. int s5p_mfc_open_inst_cmd(struct s5p_mfc_ctx *ctx)
  62. {
  63. struct s5p_mfc_dev *dev = ctx->dev;
  64. struct s5p_mfc_cmd_args h2r_args;
  65. int ret;
  66. /* Preparing decoding - getting instance number */
  67. mfc_debug(2, "Getting instance number (codec: %d)\n", ctx->codec_mode);
  68. dev->curr_ctx = ctx->num;
  69. memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
  70. h2r_args.arg[0] = ctx->codec_mode;
  71. h2r_args.arg[1] = 0; /* no crc & no pixelcache */
  72. h2r_args.arg[2] = ctx->ctx_ofs;
  73. h2r_args.arg[3] = ctx->ctx_size;
  74. ret = s5p_mfc_cmd_host2risc(dev, S5P_FIMV_H2R_CMD_OPEN_INSTANCE,
  75. &h2r_args);
  76. if (ret) {
  77. mfc_err("Failed to create a new instance\n");
  78. ctx->state = MFCINST_ERROR;
  79. }
  80. return ret;
  81. }
  82. int s5p_mfc_close_inst_cmd(struct s5p_mfc_ctx *ctx)
  83. {
  84. struct s5p_mfc_dev *dev = ctx->dev;
  85. struct s5p_mfc_cmd_args h2r_args;
  86. int ret;
  87. if (ctx->state == MFCINST_FREE) {
  88. mfc_err("Instance already returned\n");
  89. ctx->state = MFCINST_ERROR;
  90. return -EINVAL;
  91. }
  92. /* Closing decoding instance */
  93. mfc_debug(2, "Returning instance number %d\n", ctx->inst_no);
  94. dev->curr_ctx = ctx->num;
  95. memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
  96. h2r_args.arg[0] = ctx->inst_no;
  97. ret = s5p_mfc_cmd_host2risc(dev, S5P_FIMV_H2R_CMD_CLOSE_INSTANCE,
  98. &h2r_args);
  99. if (ret) {
  100. mfc_err("Failed to return an instance\n");
  101. ctx->state = MFCINST_ERROR;
  102. return -EINVAL;
  103. }
  104. return 0;
  105. }