sde_hw_util.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef _SDE_HW_UTIL_H
  7. #define _SDE_HW_UTIL_H
  8. #include <linux/io.h>
  9. #include <linux/slab.h>
  10. #include "sde_hw_mdss.h"
  11. #include "sde_hw_catalog.h"
  12. #define REG_MASK(n) ((BIT(n)) - 1)
  13. #define REG_MASK_SHIFT(n, shift) ((REG_MASK(n)) << (shift))
  14. #define REG_MASK_ULL(n) ((BIT_ULL(n)) - 1)
  15. #define REG_MASK_SHIFT_ULL(n, shift) ((REG_MASK_ULL(n)) << (shift))
  16. #define LP_DDR4_TYPE 0x7
  17. struct sde_format_extended;
  18. /*
  19. * This is the common struct maintained by each sub block
  20. * for mapping the register offsets in this block to the
  21. * absoulute IO address
  22. * @base_off: mdp register mapped offset
  23. * @blk_off: pipe offset relative to mdss offset
  24. * @length length of register block offset
  25. * @xin_id xin id
  26. * @hw_rev mdss hw revision
  27. */
  28. struct sde_hw_blk_reg_map {
  29. void __iomem *base_off;
  30. u32 blk_off;
  31. u32 length;
  32. u32 xin_id;
  33. u32 hw_rev;
  34. u32 log_mask;
  35. };
  36. /**
  37. * struct sde_hw_scaler3_de_cfg : QSEEDv3 detail enhancer configuration
  38. * @enable: detail enhancer enable/disable
  39. * @sharpen_level1: sharpening strength for noise
  40. * @sharpen_level2: sharpening strength for signal
  41. * @ clip: clip shift
  42. * @ limit: limit value
  43. * @ thr_quiet: quiet threshold
  44. * @ thr_dieout: dieout threshold
  45. * @ thr_high: low threshold
  46. * @ thr_high: high threshold
  47. * @ prec_shift: precision shift
  48. * @ adjust_a: A-coefficients for mapping curve
  49. * @ adjust_b: B-coefficients for mapping curve
  50. * @ adjust_c: C-coefficients for mapping curve
  51. * @ blend: Unsharp Blend Filter Ratio
  52. */
  53. struct sde_hw_scaler3_de_cfg {
  54. u32 enable;
  55. int16_t sharpen_level1;
  56. int16_t sharpen_level2;
  57. uint16_t clip;
  58. uint16_t limit;
  59. uint16_t thr_quiet;
  60. uint16_t thr_dieout;
  61. uint16_t thr_low;
  62. uint16_t thr_high;
  63. uint16_t prec_shift;
  64. int16_t adjust_a[SDE_MAX_DE_CURVES];
  65. int16_t adjust_b[SDE_MAX_DE_CURVES];
  66. int16_t adjust_c[SDE_MAX_DE_CURVES];
  67. uint32_t blend;
  68. };
  69. /**
  70. * struct sde_hw_scaler3_cfg : QSEEDv3 configuration
  71. * @enable: scaler enable
  72. * @dir_en: direction detection block enable
  73. * @ init_phase_x: horizontal initial phase
  74. * @ phase_step_x: horizontal phase step
  75. * @ init_phase_y: vertical initial phase
  76. * @ phase_step_y: vertical phase step
  77. * @ preload_x: horizontal preload value
  78. * @ preload_y: vertical preload value
  79. * @ src_width: source width
  80. * @ src_height: source height
  81. * @ dst_width: destination width
  82. * @ dst_height: destination height
  83. * @ y_rgb_filter_cfg: y/rgb plane filter configuration
  84. * @ uv_filter_cfg: uv plane filter configuration
  85. * @ alpha_filter_cfg: alpha filter configuration
  86. * @ blend_cfg: blend coefficients configuration
  87. * @ lut_flag: scaler LUT update flags
  88. * 0x1 swap LUT bank
  89. * 0x2 update 2D filter LUT
  90. * 0x4 update y circular filter LUT
  91. * 0x8 update uv circular filter LUT
  92. * 0x10 update y separable filter LUT
  93. * 0x20 update uv separable filter LUT
  94. * @ dir_lut_idx: 2D filter LUT index
  95. * @ y_rgb_cir_lut_idx: y circular filter LUT index
  96. * @ uv_cir_lut_idx: uv circular filter LUT index
  97. * @ y_rgb_sep_lut_idx: y circular filter LUT index
  98. * @ uv_sep_lut_idx: uv separable filter LUT index
  99. * @ dir_lut: pointer to 2D LUT
  100. * @ cir_lut: pointer to circular filter LUT
  101. * @ sep_lut: pointer to separable filter LUT
  102. * @ de: detail enhancer configuration
  103. * @ dir_weight: Directional Weight
  104. * @dyn_exp_disabled: Dynamic expansion disabled
  105. * @de_lpf_flags: Detail enhancer lpf blned configuration flags
  106. * @de_lpf_h: Detail enhancer lpf blend high
  107. * @de_lpf_l: Detail enhancer lpf blend low
  108. * @de_lpf_m: Detail enhancer lpf blend medium
  109. */
  110. struct sde_hw_scaler3_cfg {
  111. u32 enable;
  112. u32 dir_en;
  113. int32_t init_phase_x[SDE_MAX_PLANES];
  114. int32_t phase_step_x[SDE_MAX_PLANES];
  115. int32_t init_phase_y[SDE_MAX_PLANES];
  116. int32_t phase_step_y[SDE_MAX_PLANES];
  117. u32 preload_x[SDE_MAX_PLANES];
  118. u32 preload_y[SDE_MAX_PLANES];
  119. u32 src_width[SDE_MAX_PLANES];
  120. u32 src_height[SDE_MAX_PLANES];
  121. u32 dst_width;
  122. u32 dst_height;
  123. u32 y_rgb_filter_cfg;
  124. u32 uv_filter_cfg;
  125. u32 alpha_filter_cfg;
  126. u32 blend_cfg;
  127. u32 lut_flag;
  128. u32 dir_lut_idx;
  129. u32 y_rgb_cir_lut_idx;
  130. u32 uv_cir_lut_idx;
  131. u32 y_rgb_sep_lut_idx;
  132. u32 uv_sep_lut_idx;
  133. u32 *dir_lut;
  134. size_t dir_len;
  135. u32 *cir_lut;
  136. size_t cir_len;
  137. u32 *sep_lut;
  138. size_t sep_len;
  139. /*
  140. * Detail enhancer settings
  141. */
  142. struct sde_hw_scaler3_de_cfg de;
  143. uint32_t dir_weight;
  144. uint32_t dyn_exp_disabled;
  145. __u32 de_lpf_flags;
  146. __u32 de_lpf_h;
  147. __u32 de_lpf_l;
  148. __u32 de_lpf_m;
  149. };
  150. struct sde_hw_scaler3_lut_cfg {
  151. bool is_configured;
  152. u32 *dir_lut;
  153. size_t dir_len;
  154. u32 *cir_lut;
  155. size_t cir_len;
  156. u32 *sep_lut;
  157. size_t sep_len;
  158. };
  159. struct sde_hw_inline_pre_downscale_cfg {
  160. u32 pre_downscale_x_0;
  161. u32 pre_downscale_x_1;
  162. u32 pre_downscale_y_0;
  163. u32 pre_downscale_y_1;
  164. };
  165. u32 *sde_hw_util_get_log_mask_ptr(void);
  166. void sde_reg_write(struct sde_hw_blk_reg_map *c,
  167. u32 reg_off,
  168. u32 val,
  169. const char *name);
  170. int sde_reg_read(struct sde_hw_blk_reg_map *c, u32 reg_off);
  171. #define SDE_REG_WRITE(c, off, val) sde_reg_write(c, off, val, #off)
  172. #define SDE_REG_READ(c, off) sde_reg_read(c, off)
  173. #define MISR_FRAME_COUNT_MASK 0xFF
  174. #define MISR_CTRL_ENABLE BIT(8)
  175. #define MISR_CTRL_STATUS BIT(9)
  176. #define MISR_CTRL_STATUS_CLEAR BIT(10)
  177. #define INTF_MISR_CTRL_FREE_RUN_MASK BIT(31)
  178. #define INTF_MISR_CTRL_INPUT_SEL_DATA BIT(24)
  179. void *sde_hw_util_get_dir(void);
  180. void sde_init_scaler_blk(struct sde_scaler_blk *blk, u32 version);
  181. void sde_set_scaler_v2(struct sde_hw_scaler3_cfg *cfg,
  182. const struct sde_drm_scaler_v2 *scale_v2);
  183. void sde_hw_setup_scaler3(struct sde_hw_blk_reg_map *c,
  184. struct sde_hw_scaler3_cfg *scaler3_cfg, u32 scaler_version,
  185. u32 scaler_offset, const struct sde_format *format, bool de_lpf);
  186. void sde_hw_csc_matrix_coeff_setup(struct sde_hw_blk_reg_map *c,
  187. u32 csc_reg_off, struct sde_csc_cfg *data,
  188. u32 shift_bit);
  189. void sde_hw_csc_setup(struct sde_hw_blk_reg_map *c,
  190. u32 csc_reg_off,
  191. struct sde_csc_cfg *data, bool csc10);
  192. uint32_t sde_copy_formats(
  193. struct sde_format_extended *dst_list,
  194. uint32_t dst_list_size,
  195. uint32_t dst_list_pos,
  196. const struct sde_format_extended *src_list,
  197. uint32_t src_list_size);
  198. static inline bool is_qseed3_rev_qseed3lite(struct sde_mdss_cfg *sde_cfg)
  199. {
  200. return ((sde_cfg->qseed_sw_lib_rev == SDE_SSPP_SCALER_QSEED3LITE) ?
  201. true : false);
  202. }
  203. #endif /* _SDE_HW_UTIL_H */