sti_vid.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (C) STMicroelectronics SA 2014
  3. * Author: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
  4. * License terms: GNU General Public License (GPL), version 2
  5. */
  6. #include <drm/drmP.h>
  7. #include "sti_layer.h"
  8. #include "sti_vid.h"
  9. #include "sti_vtg.h"
  10. /* Registers */
  11. #define VID_CTL 0x00
  12. #define VID_ALP 0x04
  13. #define VID_CLF 0x08
  14. #define VID_VPO 0x0C
  15. #define VID_VPS 0x10
  16. #define VID_KEY1 0x28
  17. #define VID_KEY2 0x2C
  18. #define VID_MPR0 0x30
  19. #define VID_MPR1 0x34
  20. #define VID_MPR2 0x38
  21. #define VID_MPR3 0x3C
  22. #define VID_MST 0x68
  23. #define VID_BC 0x70
  24. #define VID_TINT 0x74
  25. #define VID_CSAT 0x78
  26. /* Registers values */
  27. #define VID_CTL_IGNORE (BIT(31) | BIT(30))
  28. #define VID_CTL_PSI_ENABLE (BIT(2) | BIT(1) | BIT(0))
  29. #define VID_ALP_OPAQUE 0x00000080
  30. #define VID_BC_DFLT 0x00008000
  31. #define VID_TINT_DFLT 0x00000000
  32. #define VID_CSAT_DFLT 0x00000080
  33. /* YCbCr to RGB BT709:
  34. * R = Y+1.5391Cr
  35. * G = Y-0.4590Cr-0.1826Cb
  36. * B = Y+1.8125Cb */
  37. #define VID_MPR0_BT709 0x0A800000
  38. #define VID_MPR1_BT709 0x0AC50000
  39. #define VID_MPR2_BT709 0x07150545
  40. #define VID_MPR3_BT709 0x00000AE8
  41. static int sti_vid_prepare_layer(struct sti_layer *vid, bool first_prepare)
  42. {
  43. u32 val;
  44. /* Unmask */
  45. val = readl(vid->regs + VID_CTL);
  46. val &= ~VID_CTL_IGNORE;
  47. writel(val, vid->regs + VID_CTL);
  48. return 0;
  49. }
  50. static int sti_vid_commit_layer(struct sti_layer *vid)
  51. {
  52. struct drm_display_mode *mode = vid->mode;
  53. u32 ydo, xdo, yds, xds;
  54. ydo = sti_vtg_get_line_number(*mode, vid->dst_y);
  55. yds = sti_vtg_get_line_number(*mode, vid->dst_y + vid->dst_h - 1);
  56. xdo = sti_vtg_get_pixel_number(*mode, vid->dst_x);
  57. xds = sti_vtg_get_pixel_number(*mode, vid->dst_x + vid->dst_w - 1);
  58. writel((ydo << 16) | xdo, vid->regs + VID_VPO);
  59. writel((yds << 16) | xds, vid->regs + VID_VPS);
  60. return 0;
  61. }
  62. static int sti_vid_disable_layer(struct sti_layer *vid)
  63. {
  64. u32 val;
  65. /* Mask */
  66. val = readl(vid->regs + VID_CTL);
  67. val |= VID_CTL_IGNORE;
  68. writel(val, vid->regs + VID_CTL);
  69. return 0;
  70. }
  71. static const uint32_t *sti_vid_get_formats(struct sti_layer *layer)
  72. {
  73. return NULL;
  74. }
  75. static unsigned int sti_vid_get_nb_formats(struct sti_layer *layer)
  76. {
  77. return 0;
  78. }
  79. static void sti_vid_init(struct sti_layer *vid)
  80. {
  81. /* Enable PSI, Mask layer */
  82. writel(VID_CTL_PSI_ENABLE | VID_CTL_IGNORE, vid->regs + VID_CTL);
  83. /* Opaque */
  84. writel(VID_ALP_OPAQUE, vid->regs + VID_ALP);
  85. /* Color conversion parameters */
  86. writel(VID_MPR0_BT709, vid->regs + VID_MPR0);
  87. writel(VID_MPR1_BT709, vid->regs + VID_MPR1);
  88. writel(VID_MPR2_BT709, vid->regs + VID_MPR2);
  89. writel(VID_MPR3_BT709, vid->regs + VID_MPR3);
  90. /* Brightness, contrast, tint, saturation */
  91. writel(VID_BC_DFLT, vid->regs + VID_BC);
  92. writel(VID_TINT_DFLT, vid->regs + VID_TINT);
  93. writel(VID_CSAT_DFLT, vid->regs + VID_CSAT);
  94. }
  95. static const struct sti_layer_funcs vid_ops = {
  96. .get_formats = sti_vid_get_formats,
  97. .get_nb_formats = sti_vid_get_nb_formats,
  98. .init = sti_vid_init,
  99. .prepare = sti_vid_prepare_layer,
  100. .commit = sti_vid_commit_layer,
  101. .disable = sti_vid_disable_layer,
  102. };
  103. struct sti_layer *sti_vid_create(struct device *dev)
  104. {
  105. struct sti_layer *vid;
  106. vid = devm_kzalloc(dev, sizeof(*vid), GFP_KERNEL);
  107. if (!vid) {
  108. DRM_ERROR("Failed to allocate memory for VID\n");
  109. return NULL;
  110. }
  111. vid->ops = &vid_ops;
  112. return vid;
  113. }