sde_hw_util.h 6.8 KB

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