meson_vpp.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (C) 2016 BayLibre, SAS
  3. * Author: Neil Armstrong <narmstrong@baylibre.com>
  4. * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
  5. * Copyright (C) 2014 Endless Mobile
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <drm/drmP.h>
  23. #include "meson_drv.h"
  24. #include "meson_vpp.h"
  25. #include "meson_registers.h"
  26. /**
  27. * DOC: Video Post Processing
  28. *
  29. * VPP Handles all the Post Processing after the Scanout from the VIU
  30. * We handle the following post processings :
  31. *
  32. * - Postblend, Blends the OSD1 only
  33. * We exclude OSD2, VS1, VS1 and Preblend output
  34. * - Vertical OSD Scaler for OSD1 only, we disable vertical scaler and
  35. * use it only for interlace scanout
  36. * - Intermediate FIFO with default Amlogic values
  37. *
  38. * What is missing :
  39. *
  40. * - Preblend for video overlay pre-scaling
  41. * - OSD2 support for cursor framebuffer
  42. * - Video pre-scaling before postblend
  43. * - Full Vertical/Horizontal OSD scaling to support TV overscan
  44. * - HDR conversion
  45. */
  46. void meson_vpp_setup_mux(struct meson_drm *priv, unsigned int mux)
  47. {
  48. writel(mux, priv->io_base + _REG(VPU_VIU_VENC_MUX_CTRL));
  49. }
  50. /*
  51. * When the output is interlaced, the OSD must switch between
  52. * each field using the INTERLACE_SEL_ODD (0) of VIU_OSD1_BLK0_CFG_W0
  53. * at each vsync.
  54. * But the vertical scaler can provide such funtionnality if
  55. * is configured for 2:1 scaling with interlace options enabled.
  56. */
  57. void meson_vpp_setup_interlace_vscaler_osd1(struct meson_drm *priv,
  58. struct drm_rect *input)
  59. {
  60. writel_relaxed(BIT(3) /* Enable scaler */ |
  61. BIT(2), /* Select OSD1 */
  62. priv->io_base + _REG(VPP_OSD_SC_CTRL0));
  63. writel_relaxed(((drm_rect_width(input) - 1) << 16) |
  64. (drm_rect_height(input) - 1),
  65. priv->io_base + _REG(VPP_OSD_SCI_WH_M1));
  66. /* 2:1 scaling */
  67. writel_relaxed(((input->x1) << 16) | (input->x2),
  68. priv->io_base + _REG(VPP_OSD_SCO_H_START_END));
  69. writel_relaxed(((input->y1 >> 1) << 16) | (input->y2 >> 1),
  70. priv->io_base + _REG(VPP_OSD_SCO_V_START_END));
  71. /* 2:1 scaling values */
  72. writel_relaxed(BIT(16), priv->io_base + _REG(VPP_OSD_VSC_INI_PHASE));
  73. writel_relaxed(BIT(25), priv->io_base + _REG(VPP_OSD_VSC_PHASE_STEP));
  74. writel_relaxed(0, priv->io_base + _REG(VPP_OSD_HSC_CTRL0));
  75. writel_relaxed((4 << 0) /* osd_vsc_bank_length */ |
  76. (4 << 3) /* osd_vsc_top_ini_rcv_num0 */ |
  77. (1 << 8) /* osd_vsc_top_rpt_p0_num0 */ |
  78. (6 << 11) /* osd_vsc_bot_ini_rcv_num0 */ |
  79. (2 << 16) /* osd_vsc_bot_rpt_p0_num0 */ |
  80. BIT(23) /* osd_prog_interlace */ |
  81. BIT(24), /* Enable vertical scaler */
  82. priv->io_base + _REG(VPP_OSD_VSC_CTRL0));
  83. }
  84. void meson_vpp_disable_interlace_vscaler_osd1(struct meson_drm *priv)
  85. {
  86. writel_relaxed(0, priv->io_base + _REG(VPP_OSD_SC_CTRL0));
  87. writel_relaxed(0, priv->io_base + _REG(VPP_OSD_VSC_CTRL0));
  88. writel_relaxed(0, priv->io_base + _REG(VPP_OSD_HSC_CTRL0));
  89. }
  90. static unsigned int vpp_filter_coefs_4point_bspline[] = {
  91. 0x15561500, 0x14561600, 0x13561700, 0x12561800,
  92. 0x11551a00, 0x11541b00, 0x10541c00, 0x0f541d00,
  93. 0x0f531e00, 0x0e531f00, 0x0d522100, 0x0c522200,
  94. 0x0b522300, 0x0b512400, 0x0a502600, 0x0a4f2700,
  95. 0x094e2900, 0x084e2a00, 0x084d2b00, 0x074c2c01,
  96. 0x074b2d01, 0x064a2f01, 0x06493001, 0x05483201,
  97. 0x05473301, 0x05463401, 0x04453601, 0x04433702,
  98. 0x04423802, 0x03413a02, 0x03403b02, 0x033f3c02,
  99. 0x033d3d03
  100. };
  101. static void meson_vpp_write_scaling_filter_coefs(struct meson_drm *priv,
  102. const unsigned int *coefs,
  103. bool is_horizontal)
  104. {
  105. int i;
  106. writel_relaxed(is_horizontal ? BIT(8) : 0,
  107. priv->io_base + _REG(VPP_OSD_SCALE_COEF_IDX));
  108. for (i = 0; i < 33; i++)
  109. writel_relaxed(coefs[i],
  110. priv->io_base + _REG(VPP_OSD_SCALE_COEF));
  111. }
  112. void meson_vpp_init(struct meson_drm *priv)
  113. {
  114. /* set dummy data default YUV black */
  115. if (meson_vpu_is_compatible(priv, "amlogic,meson-gxl-vpu"))
  116. writel_relaxed(0x108080, priv->io_base + _REG(VPP_DUMMY_DATA1));
  117. else if (meson_vpu_is_compatible(priv, "amlogic,meson-gxm-vpu")) {
  118. writel_bits_relaxed(0xff << 16, 0xff << 16,
  119. priv->io_base + _REG(VIU_MISC_CTRL1));
  120. writel_relaxed(0x20000, priv->io_base + _REG(VPP_DOLBY_CTRL));
  121. writel_relaxed(0x1020080,
  122. priv->io_base + _REG(VPP_DUMMY_DATA1));
  123. }
  124. /* Initialize vpu fifo control registers */
  125. writel_relaxed(readl_relaxed(priv->io_base + _REG(VPP_OFIFO_SIZE)) |
  126. 0x77f, priv->io_base + _REG(VPP_OFIFO_SIZE));
  127. writel_relaxed(0x08080808, priv->io_base + _REG(VPP_HOLD_LINES));
  128. /* Turn off preblend */
  129. writel_bits_relaxed(VPP_PREBLEND_ENABLE, 0,
  130. priv->io_base + _REG(VPP_MISC));
  131. /* Turn off POSTBLEND */
  132. writel_bits_relaxed(VPP_POSTBLEND_ENABLE, 0,
  133. priv->io_base + _REG(VPP_MISC));
  134. /* Force all planes off */
  135. writel_bits_relaxed(VPP_OSD1_POSTBLEND | VPP_OSD2_POSTBLEND |
  136. VPP_VD1_POSTBLEND | VPP_VD2_POSTBLEND, 0,
  137. priv->io_base + _REG(VPP_MISC));
  138. /* Disable Scalers */
  139. writel_relaxed(0, priv->io_base + _REG(VPP_OSD_SC_CTRL0));
  140. writel_relaxed(0, priv->io_base + _REG(VPP_OSD_VSC_CTRL0));
  141. writel_relaxed(0, priv->io_base + _REG(VPP_OSD_HSC_CTRL0));
  142. /* Write in the proper filter coefficients. */
  143. meson_vpp_write_scaling_filter_coefs(priv,
  144. vpp_filter_coefs_4point_bspline, false);
  145. meson_vpp_write_scaling_filter_coefs(priv,
  146. vpp_filter_coefs_4point_bspline, true);
  147. }