sde_hw_util.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. * @dir45_en: 45/-45 degree direction filtering block enable
  74. * @cor_en: corner detection block enable
  75. * @ init_phase_x: horizontal initial phase
  76. * @ phase_step_x: horizontal phase step
  77. * @ init_phase_y: vertical initial phase
  78. * @ phase_step_y: vertical phase step
  79. * @ preload_x: horizontal preload value
  80. * @ preload_y: vertical preload value
  81. * @ src_width: source width
  82. * @ src_height: source height
  83. * @ dst_width: destination width
  84. * @ dst_height: destination height
  85. * @ y_rgb_filter_cfg: y/rgb plane filter configuration
  86. * @ uv_filter_cfg: uv plane filter configuration
  87. * @ alpha_filter_cfg: alpha filter configuration
  88. * @ blend_cfg: blend coefficients configuration
  89. * @ lut_flag: scaler LUT update flags
  90. * 0x1 swap LUT bank
  91. * 0x2 update 2D filter LUT
  92. * 0x4 update y circular filter LUT
  93. * 0x8 update uv circular filter LUT
  94. * 0x10 update y separable filter LUT
  95. * 0x20 update uv separable filter LUT
  96. * @ dir_lut_idx: 2D filter LUT index
  97. * @ y_rgb_cir_lut_idx: y circular filter LUT index
  98. * @ uv_cir_lut_idx: uv circular filter LUT index
  99. * @ y_rgb_sep_lut_idx: y circular filter LUT index
  100. * @ uv_sep_lut_idx: uv separable filter LUT index
  101. * @ dir_lut: pointer to 2D LUT
  102. * @ cir_lut: pointer to circular filter LUT
  103. * @ sep_lut: pointer to separable filter LUT
  104. * @ de: detail enhancer configuration
  105. * @ dir_weight: Directional Weight
  106. * @dyn_exp_disabled: Dynamic expansion disabled
  107. * @de_lpf_flags: Detail enhancer lpf blned configuration flags
  108. * @de_lpf_h: Detail enhancer lpf blend high
  109. * @de_lpf_l: Detail enhancer lpf blend low
  110. * @de_lpf_m: Detail enhancer lpf blend medium
  111. */
  112. struct sde_hw_scaler3_cfg {
  113. u32 enable;
  114. u32 dir_en;
  115. u32 dir45_en;
  116. u32 cor_en;
  117. int32_t init_phase_x[SDE_MAX_PLANES];
  118. int32_t phase_step_x[SDE_MAX_PLANES];
  119. int32_t init_phase_y[SDE_MAX_PLANES];
  120. int32_t phase_step_y[SDE_MAX_PLANES];
  121. u32 preload_x[SDE_MAX_PLANES];
  122. u32 preload_y[SDE_MAX_PLANES];
  123. u32 src_width[SDE_MAX_PLANES];
  124. u32 src_height[SDE_MAX_PLANES];
  125. u32 dst_width;
  126. u32 dst_height;
  127. u32 y_rgb_filter_cfg;
  128. u32 uv_filter_cfg;
  129. u32 alpha_filter_cfg;
  130. u32 blend_cfg;
  131. u32 lut_flag;
  132. u32 dir_lut_idx;
  133. u32 y_rgb_cir_lut_idx;
  134. u32 uv_cir_lut_idx;
  135. u32 y_rgb_sep_lut_idx;
  136. u32 uv_sep_lut_idx;
  137. u32 *dir_lut;
  138. size_t dir_len;
  139. u32 *cir_lut;
  140. size_t cir_len;
  141. u32 *sep_lut;
  142. size_t sep_len;
  143. /*
  144. * Detail enhancer settings
  145. */
  146. struct sde_hw_scaler3_de_cfg de;
  147. uint32_t dir_weight;
  148. uint32_t dyn_exp_disabled;
  149. __u32 de_lpf_flags;
  150. __u32 de_lpf_h;
  151. __u32 de_lpf_l;
  152. __u32 de_lpf_m;
  153. };
  154. struct sde_hw_scaler3_lut_cfg {
  155. bool is_configured;
  156. u32 *dir_lut;
  157. size_t dir_len;
  158. u32 *cir_lut;
  159. size_t cir_len;
  160. u32 *sep_lut;
  161. size_t sep_len;
  162. };
  163. struct sde_hw_inline_pre_downscale_cfg {
  164. u32 pre_downscale_x_0;
  165. u32 pre_downscale_x_1;
  166. u32 pre_downscale_y_0;
  167. u32 pre_downscale_y_1;
  168. };
  169. u32 *sde_hw_util_get_log_mask_ptr(void);
  170. void sde_reg_write(struct sde_hw_blk_reg_map *c,
  171. u32 reg_off,
  172. u32 val,
  173. const char *name);
  174. int sde_reg_read(struct sde_hw_blk_reg_map *c, u32 reg_off);
  175. #define SDE_REG_WRITE(c, off, val) sde_reg_write(c, off, val, #off)
  176. #define SDE_REG_READ(c, off) sde_reg_read(c, off)
  177. #define MISR_FRAME_COUNT_MASK 0xFF
  178. #define MISR_CTRL_ENABLE BIT(8)
  179. #define MISR_CTRL_STATUS BIT(9)
  180. #define MISR_CTRL_STATUS_CLEAR BIT(10)
  181. #define INTF_MISR_CTRL_FREE_RUN_MASK BIT(31)
  182. #define INTF_MISR_CTRL_INPUT_SEL_DATA BIT(24)
  183. void *sde_hw_util_get_dir(void);
  184. void sde_init_scaler_blk(struct sde_scaler_blk *blk, u32 version);
  185. void sde_set_scaler_v2(struct sde_hw_scaler3_cfg *cfg,
  186. const struct sde_drm_scaler_v2 *scale_v2);
  187. void sde_hw_setup_scaler3(struct sde_hw_blk_reg_map *c,
  188. struct sde_hw_scaler3_cfg *scaler3_cfg, u32 scaler_version,
  189. u32 scaler_offset, const struct sde_format *format, bool de_lpf);
  190. void sde_hw_csc_matrix_coeff_setup(struct sde_hw_blk_reg_map *c,
  191. u32 csc_reg_off, struct sde_csc_cfg *data,
  192. u32 shift_bit);
  193. void sde_hw_csc_setup(struct sde_hw_blk_reg_map *c,
  194. u32 csc_reg_off,
  195. struct sde_csc_cfg *data, bool csc10);
  196. uint32_t sde_copy_formats(
  197. struct sde_format_extended *dst_list,
  198. uint32_t dst_list_size,
  199. uint32_t dst_list_pos,
  200. const struct sde_format_extended *src_list,
  201. uint32_t src_list_size);
  202. static inline bool is_qseed3_rev_qseed3lite(struct sde_mdss_cfg *sde_cfg)
  203. {
  204. return ((sde_cfg->qseed_sw_lib_rev == SDE_SSPP_SCALER_QSEED3LITE) ?
  205. true : false);
  206. }
  207. #endif /* _SDE_HW_UTIL_H */