s5p_mfc_intr.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * drivers/media/platform/samsung/mfc5/s5p_mfc_intr.c
  3. *
  4. * C file for Samsung MFC (Multi Function Codec - FIMV) driver
  5. * This file contains functions used to wait for command completion.
  6. *
  7. * Kamil Debski, Copyright (C) 2011 Samsung Electronics Co., Ltd.
  8. * http://www.samsung.com/
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/errno.h>
  16. #include <linux/io.h>
  17. #include <linux/sched.h>
  18. #include <linux/wait.h>
  19. #include "s5p_mfc_common.h"
  20. #include "s5p_mfc_debug.h"
  21. #include "s5p_mfc_intr.h"
  22. int s5p_mfc_wait_for_done_dev(struct s5p_mfc_dev *dev, int command)
  23. {
  24. int ret;
  25. ret = wait_event_interruptible_timeout(dev->queue,
  26. (dev->int_cond && (dev->int_type == command
  27. || dev->int_type == S5P_MFC_R2H_CMD_ERR_RET)),
  28. msecs_to_jiffies(MFC_INT_TIMEOUT));
  29. if (ret == 0) {
  30. mfc_err("Interrupt (dev->int_type:%d, command:%d) timed out\n",
  31. dev->int_type, command);
  32. return 1;
  33. } else if (ret == -ERESTARTSYS) {
  34. mfc_err("Interrupted by a signal\n");
  35. return 1;
  36. }
  37. mfc_debug(1, "Finished waiting (dev->int_type:%d, command: %d)\n",
  38. dev->int_type, command);
  39. if (dev->int_type == S5P_MFC_R2H_CMD_ERR_RET)
  40. return 1;
  41. return 0;
  42. }
  43. void s5p_mfc_clean_dev_int_flags(struct s5p_mfc_dev *dev)
  44. {
  45. dev->int_cond = 0;
  46. dev->int_type = 0;
  47. dev->int_err = 0;
  48. }
  49. int s5p_mfc_wait_for_done_ctx(struct s5p_mfc_ctx *ctx,
  50. int command, int interrupt)
  51. {
  52. int ret;
  53. if (interrupt) {
  54. ret = wait_event_interruptible_timeout(ctx->queue,
  55. (ctx->int_cond && (ctx->int_type == command
  56. || ctx->int_type == S5P_MFC_R2H_CMD_ERR_RET)),
  57. msecs_to_jiffies(MFC_INT_TIMEOUT));
  58. } else {
  59. ret = wait_event_timeout(ctx->queue,
  60. (ctx->int_cond && (ctx->int_type == command
  61. || ctx->int_type == S5P_MFC_R2H_CMD_ERR_RET)),
  62. msecs_to_jiffies(MFC_INT_TIMEOUT));
  63. }
  64. if (ret == 0) {
  65. mfc_err("Interrupt (ctx->int_type:%d, command:%d) timed out\n",
  66. ctx->int_type, command);
  67. return 1;
  68. } else if (ret == -ERESTARTSYS) {
  69. mfc_err("Interrupted by a signal\n");
  70. return 1;
  71. }
  72. mfc_debug(1, "Finished waiting (ctx->int_type:%d, command: %d)\n",
  73. ctx->int_type, command);
  74. if (ctx->int_type == S5P_MFC_R2H_CMD_ERR_RET)
  75. return 1;
  76. return 0;
  77. }
  78. void s5p_mfc_clean_ctx_int_flags(struct s5p_mfc_ctx *ctx)
  79. {
  80. ctx->int_cond = 0;
  81. ctx->int_type = 0;
  82. ctx->int_err = 0;
  83. }