sde_hw_ds.c 3.6 KB

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