sde_hw_ds.c 3.5 KB

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