sde_hw_ds.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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-2020, 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. static void sde_hw_ds_setup_opmode(struct sde_hw_ds *hw_ds,
  14. u32 op_mode)
  15. {
  16. struct sde_hw_blk_reg_map *hw = &hw_ds->hw;
  17. u32 op_mode_val;
  18. op_mode_val = SDE_REG_READ(hw, DEST_SCALER_OP_MODE);
  19. if (op_mode)
  20. op_mode_val |= op_mode;
  21. else if (!op_mode && (op_mode_val & SDE_DS_OP_MODE_DUAL))
  22. op_mode_val = 0;
  23. else
  24. op_mode_val &= ~BIT(hw_ds->idx - DS_0);
  25. SDE_REG_WRITE(hw, DEST_SCALER_OP_MODE, op_mode_val);
  26. }
  27. static void sde_hw_ds_setup_scaler3(struct sde_hw_ds *hw_ds,
  28. void *scaler_cfg, void *scaler_lut_cfg)
  29. {
  30. struct sde_hw_scaler3_cfg *scl3_cfg = scaler_cfg;
  31. struct sde_hw_scaler3_lut_cfg *scl3_lut_cfg = scaler_lut_cfg;
  32. if (!hw_ds || !hw_ds->scl || !scl3_cfg || !scl3_lut_cfg)
  33. return;
  34. /*
  35. * copy LUT values to scaler structure
  36. */
  37. if (scl3_lut_cfg->is_configured) {
  38. scl3_cfg->dir_lut = scl3_lut_cfg->dir_lut;
  39. scl3_cfg->dir_len = scl3_lut_cfg->dir_len;
  40. scl3_cfg->cir_lut = scl3_lut_cfg->cir_lut;
  41. scl3_cfg->cir_len = scl3_lut_cfg->cir_len;
  42. scl3_cfg->sep_lut = scl3_lut_cfg->sep_lut;
  43. scl3_cfg->sep_len = scl3_lut_cfg->sep_len;
  44. }
  45. sde_hw_setup_scaler3(&hw_ds->hw, scl3_cfg, hw_ds->scl->version,
  46. hw_ds->scl->base,
  47. sde_get_sde_format(DRM_FORMAT_XBGR2101010));
  48. }
  49. static void _setup_ds_ops(struct sde_hw_ds_ops *ops, unsigned long features)
  50. {
  51. ops->setup_opmode = sde_hw_ds_setup_opmode;
  52. if (test_bit(SDE_SSPP_SCALER_QSEED3, &features) ||
  53. test_bit(SDE_SSPP_SCALER_QSEED3LITE, &features))
  54. ops->setup_scaler = sde_hw_ds_setup_scaler3;
  55. }
  56. static struct sde_ds_cfg *_ds_offset(enum sde_ds ds,
  57. struct sde_mdss_cfg *m,
  58. void __iomem *addr,
  59. struct sde_hw_blk_reg_map *b)
  60. {
  61. int i;
  62. if (!m || !addr || !b)
  63. return ERR_PTR(-EINVAL);
  64. for (i = 0; i < m->ds_count; i++) {
  65. if ((ds == m->ds[i].id) &&
  66. (m->ds[i].top)) {
  67. b->base_off = addr;
  68. b->blk_off = m->ds[i].top->base;
  69. b->length = m->ds[i].top->len;
  70. b->hwversion = m->hwversion;
  71. b->log_mask = SDE_DBG_MASK_DS;
  72. return &m->ds[i];
  73. }
  74. }
  75. return ERR_PTR(-EINVAL);
  76. }
  77. static struct sde_hw_blk_ops sde_hw_ops = {
  78. .start = NULL,
  79. .stop = NULL,
  80. };
  81. struct sde_hw_ds *sde_hw_ds_init(enum sde_ds idx,
  82. void __iomem *addr,
  83. struct sde_mdss_cfg *m)
  84. {
  85. struct sde_hw_ds *hw_ds;
  86. struct sde_ds_cfg *cfg;
  87. int rc;
  88. if (!addr || !m)
  89. return ERR_PTR(-EINVAL);
  90. hw_ds = kzalloc(sizeof(*hw_ds), GFP_KERNEL);
  91. if (!hw_ds)
  92. return ERR_PTR(-ENOMEM);
  93. cfg = _ds_offset(idx, m, addr, &hw_ds->hw);
  94. if (IS_ERR_OR_NULL(cfg)) {
  95. SDE_ERROR("failed to get ds cfg\n");
  96. kfree(hw_ds);
  97. return ERR_PTR(-EINVAL);
  98. }
  99. /* Assign ops */
  100. hw_ds->idx = idx;
  101. hw_ds->scl = cfg;
  102. _setup_ds_ops(&hw_ds->ops, hw_ds->scl->features);
  103. if (m->qseed_hw_version)
  104. hw_ds->scl->version = m->qseed_hw_version;
  105. rc = sde_hw_blk_init(&hw_ds->base, SDE_HW_BLK_DS, idx, &sde_hw_ops);
  106. if (rc) {
  107. SDE_ERROR("failed to init hw blk %d\n", rc);
  108. goto blk_init_error;
  109. }
  110. if (cfg->len) {
  111. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name,
  112. hw_ds->hw.blk_off + cfg->base,
  113. hw_ds->hw.blk_off + cfg->base + cfg->len,
  114. hw_ds->hw.xin_id);
  115. }
  116. return hw_ds;
  117. blk_init_error:
  118. kfree(hw_ds);
  119. return ERR_PTR(rc);
  120. }
  121. void sde_hw_ds_destroy(struct sde_hw_ds *hw_ds)
  122. {
  123. if (hw_ds)
  124. sde_hw_blk_destroy(&hw_ds->base);
  125. kfree(hw_ds);
  126. }