sde_hw_ds.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  7. #include "sde_hw_ds.h"
  8. #include "sde_formats.h"
  9. #include "sde_dbg.h"
  10. #include "sde_kms.h"
  11. /* Destination scaler TOP registers */
  12. #define DEST_SCALER_OP_MODE 0x00
  13. #define DEST_SCALER_HW_VERSION 0x10
  14. #define DEST_SCALER_MERGE_CTRL 0x0C
  15. #define DEST_SCALER_DUAL_PIPE 1
  16. #define DEST_SCALER_QUAD_PIPE 3
  17. static void sde_hw_ds_setup_opmode(struct sde_hw_ds *hw_ds, u32 op_mode)
  18. {
  19. struct sde_hw_blk_reg_map *hw = &hw_ds->hw;
  20. u32 op_mode_val;
  21. op_mode_val = SDE_REG_READ(hw, DEST_SCALER_OP_MODE);
  22. if (op_mode)
  23. op_mode_val |= op_mode;
  24. else if (!op_mode && (op_mode_val & SDE_DS_OP_MODE_DUAL))
  25. op_mode_val = 0;
  26. else
  27. op_mode_val &= ~BIT(hw_ds->idx - DS_0);
  28. SDE_REG_WRITE(hw, DEST_SCALER_OP_MODE, op_mode_val);
  29. }
  30. static void sde_hw_ds_setup_opmode_v1(struct sde_hw_ds *hw_ds, u32 op_mode)
  31. {
  32. struct sde_hw_blk_reg_map *hw = &hw_ds->hw;
  33. if (op_mode & SDE_DS_OP_MODE_DUAL) {
  34. op_mode = DEST_SCALER_DUAL_PIPE;
  35. SDE_REG_WRITE(hw, DEST_SCALER_MERGE_CTRL + hw_ds->scl->base, op_mode);
  36. }
  37. }
  38. static void sde_hw_ds_setup_scaler3(struct sde_hw_ds *hw_ds,
  39. void *scaler_cfg, void *scaler_lut_cfg)
  40. {
  41. struct sde_hw_scaler3_cfg *scl3_cfg = scaler_cfg;
  42. struct sde_hw_scaler3_lut_cfg *scl3_lut_cfg = scaler_lut_cfg;
  43. bool de_lpf_en = false;
  44. if (!hw_ds || !hw_ds->scl || !scl3_cfg || !scl3_lut_cfg)
  45. return;
  46. /*
  47. * copy LUT values to scaler structure
  48. */
  49. if (scl3_lut_cfg->is_configured) {
  50. scl3_cfg->dir_lut = scl3_lut_cfg->dir_lut;
  51. scl3_cfg->dir_len = scl3_lut_cfg->dir_len;
  52. scl3_cfg->cir_lut = scl3_lut_cfg->cir_lut;
  53. scl3_cfg->cir_len = scl3_lut_cfg->cir_len;
  54. scl3_cfg->sep_lut = scl3_lut_cfg->sep_lut;
  55. scl3_cfg->sep_len = scl3_lut_cfg->sep_len;
  56. }
  57. if (test_bit(SDE_DS_DE_LPF_BLEND, &hw_ds->scl->features))
  58. de_lpf_en = true;
  59. sde_hw_setup_scaler3(&hw_ds->hw, scl3_cfg, hw_ds->scl->version,
  60. hw_ds->scl->base,
  61. sde_get_sde_format(DRM_FORMAT_XBGR2101010), de_lpf_en);
  62. }
  63. static void _setup_ds_ops(struct sde_hw_ds_ops *ops, unsigned long features)
  64. {
  65. if (test_bit(SDE_DS_MERGE_CTRL, &features))
  66. ops->setup_opmode = sde_hw_ds_setup_opmode_v1;
  67. else
  68. ops->setup_opmode = sde_hw_ds_setup_opmode;
  69. if (test_bit(SDE_SSPP_SCALER_QSEED3, &features) ||
  70. test_bit(SDE_SSPP_SCALER_QSEED3LITE, &features))
  71. ops->setup_scaler = sde_hw_ds_setup_scaler3;
  72. }
  73. static struct sde_ds_cfg *_ds_offset(enum sde_ds ds,
  74. struct sde_mdss_cfg *m,
  75. void __iomem *addr,
  76. struct sde_hw_blk_reg_map *b)
  77. {
  78. int i;
  79. if (!m || !addr || !b)
  80. return ERR_PTR(-EINVAL);
  81. for (i = 0; i < m->ds_count; i++) {
  82. if ((ds == m->ds[i].id) &&
  83. (m->ds[i].top)) {
  84. b->base_off = addr;
  85. b->blk_off = m->ds[i].top->base;
  86. b->length = m->ds[i].top->len;
  87. b->hw_rev = m->hw_rev;
  88. b->log_mask = SDE_DBG_MASK_DS;
  89. return &m->ds[i];
  90. }
  91. }
  92. return ERR_PTR(-EINVAL);
  93. }
  94. struct sde_hw_blk_reg_map *sde_hw_ds_init(enum sde_ds idx,
  95. void __iomem *addr,
  96. struct sde_mdss_cfg *m)
  97. {
  98. struct sde_hw_ds *hw_ds;
  99. struct sde_ds_cfg *cfg;
  100. if (!addr || !m)
  101. return ERR_PTR(-EINVAL);
  102. hw_ds = kzalloc(sizeof(*hw_ds), GFP_KERNEL);
  103. if (!hw_ds)
  104. return ERR_PTR(-ENOMEM);
  105. cfg = _ds_offset(idx, m, addr, &hw_ds->hw);
  106. if (IS_ERR_OR_NULL(cfg)) {
  107. SDE_ERROR("failed to get ds cfg\n");
  108. kfree(hw_ds);
  109. return ERR_PTR(-EINVAL);
  110. }
  111. /* Assign ops */
  112. hw_ds->idx = idx;
  113. hw_ds->scl = cfg;
  114. _setup_ds_ops(&hw_ds->ops, hw_ds->scl->features);
  115. if (m->qseed_hw_rev)
  116. hw_ds->scl->version = m->qseed_hw_rev;
  117. if (cfg->len) {
  118. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name,
  119. hw_ds->hw.blk_off + cfg->base,
  120. hw_ds->hw.blk_off + cfg->base + cfg->len,
  121. hw_ds->hw.xin_id);
  122. }
  123. return &hw_ds->hw;
  124. }
  125. void sde_hw_ds_destroy(struct sde_hw_blk_reg_map *hw)
  126. {
  127. if (hw)
  128. kfree(to_sde_hw_ds(hw));
  129. }