s5p_mfc_opr.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * drivers/media/platform/s5p-mfc/s5p_mfc_opr.c
  3. *
  4. * Samsung MFC (Multi Function Codec - FIMV) driver
  5. * This file contains hw related functions.
  6. *
  7. * Kamil Debski, Copyright (c) 2012 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 "s5p_mfc_debug.h"
  15. #include "s5p_mfc_opr.h"
  16. #include "s5p_mfc_opr_v5.h"
  17. #include "s5p_mfc_opr_v6.h"
  18. static struct s5p_mfc_hw_ops *s5p_mfc_ops;
  19. void s5p_mfc_init_hw_ops(struct s5p_mfc_dev *dev)
  20. {
  21. if (IS_MFCV6_PLUS(dev)) {
  22. s5p_mfc_ops = s5p_mfc_init_hw_ops_v6();
  23. dev->warn_start = S5P_FIMV_ERR_WARNINGS_START_V6;
  24. } else {
  25. s5p_mfc_ops = s5p_mfc_init_hw_ops_v5();
  26. dev->warn_start = S5P_FIMV_ERR_WARNINGS_START;
  27. }
  28. dev->mfc_ops = s5p_mfc_ops;
  29. }
  30. void s5p_mfc_init_regs(struct s5p_mfc_dev *dev)
  31. {
  32. if (IS_MFCV6_PLUS(dev))
  33. dev->mfc_regs = s5p_mfc_init_regs_v6_plus(dev);
  34. }
  35. int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base,
  36. struct s5p_mfc_priv_buf *b)
  37. {
  38. mfc_debug(3, "Allocating priv: %zu\n", b->size);
  39. b->virt = dma_alloc_coherent(dev, b->size, &b->dma, GFP_KERNEL);
  40. if (!b->virt) {
  41. mfc_err("Allocating private buffer failed\n");
  42. return -ENOMEM;
  43. }
  44. if (b->dma < base) {
  45. mfc_err("Invaling memory configuration!\n");
  46. mfc_err("Allocated buffer (%pad) is lower than memory base address (%pad)\n",
  47. &b->dma, &base);
  48. dma_free_coherent(dev, b->size, b->virt, b->dma);
  49. return -ENOMEM;
  50. }
  51. mfc_debug(3, "Allocated addr %p %pad\n", b->virt, &b->dma);
  52. return 0;
  53. }
  54. void s5p_mfc_release_priv_buf(struct device *dev,
  55. struct s5p_mfc_priv_buf *b)
  56. {
  57. if (b->virt) {
  58. dma_free_coherent(dev, b->size, b->virt, b->dma);
  59. b->virt = NULL;
  60. b->dma = 0;
  61. b->size = 0;
  62. }
  63. }