dpu_hw_util.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef _DPU_HW_UTIL_H
  13. #define _DPU_HW_UTIL_H
  14. #include <linux/io.h>
  15. #include <linux/slab.h>
  16. #include "dpu_hw_mdss.h"
  17. #define REG_MASK(n) ((BIT(n)) - 1)
  18. struct dpu_format_extended;
  19. /*
  20. * This is the common struct maintained by each sub block
  21. * for mapping the register offsets in this block to the
  22. * absoulute IO address
  23. * @base_off: mdp register mapped offset
  24. * @blk_off: pipe offset relative to mdss offset
  25. * @length length of register block offset
  26. * @xin_id xin id
  27. * @hwversion mdss hw version number
  28. */
  29. struct dpu_hw_blk_reg_map {
  30. void __iomem *base_off;
  31. u32 blk_off;
  32. u32 length;
  33. u32 xin_id;
  34. u32 hwversion;
  35. u32 log_mask;
  36. };
  37. /**
  38. * struct dpu_hw_scaler3_de_cfg : QSEEDv3 detail enhancer configuration
  39. * @enable: detail enhancer enable/disable
  40. * @sharpen_level1: sharpening strength for noise
  41. * @sharpen_level2: sharpening strength for signal
  42. * @ clip: clip shift
  43. * @ limit: limit value
  44. * @ thr_quiet: quiet threshold
  45. * @ thr_dieout: dieout threshold
  46. * @ thr_high: low threshold
  47. * @ thr_high: high threshold
  48. * @ prec_shift: precision shift
  49. * @ adjust_a: A-coefficients for mapping curve
  50. * @ adjust_b: B-coefficients for mapping curve
  51. * @ adjust_c: C-coefficients for mapping curve
  52. */
  53. struct dpu_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[DPU_MAX_DE_CURVES];
  65. int16_t adjust_b[DPU_MAX_DE_CURVES];
  66. int16_t adjust_c[DPU_MAX_DE_CURVES];
  67. };
  68. /**
  69. * struct dpu_hw_scaler3_cfg : QSEEDv3 configuration
  70. * @enable: scaler enable
  71. * @dir_en: direction detection block enable
  72. * @ init_phase_x: horizontal initial phase
  73. * @ phase_step_x: horizontal phase step
  74. * @ init_phase_y: vertical initial phase
  75. * @ phase_step_y: vertical phase step
  76. * @ preload_x: horizontal preload value
  77. * @ preload_y: vertical preload value
  78. * @ src_width: source width
  79. * @ src_height: source height
  80. * @ dst_width: destination width
  81. * @ dst_height: destination height
  82. * @ y_rgb_filter_cfg: y/rgb plane filter configuration
  83. * @ uv_filter_cfg: uv plane filter configuration
  84. * @ alpha_filter_cfg: alpha filter configuration
  85. * @ blend_cfg: blend coefficients configuration
  86. * @ lut_flag: scaler LUT update flags
  87. * 0x1 swap LUT bank
  88. * 0x2 update 2D filter LUT
  89. * 0x4 update y circular filter LUT
  90. * 0x8 update uv circular filter LUT
  91. * 0x10 update y separable filter LUT
  92. * 0x20 update uv separable filter LUT
  93. * @ dir_lut_idx: 2D filter LUT index
  94. * @ y_rgb_cir_lut_idx: y circular filter LUT index
  95. * @ uv_cir_lut_idx: uv circular filter LUT index
  96. * @ y_rgb_sep_lut_idx: y circular filter LUT index
  97. * @ uv_sep_lut_idx: uv separable filter LUT index
  98. * @ dir_lut: pointer to 2D LUT
  99. * @ cir_lut: pointer to circular filter LUT
  100. * @ sep_lut: pointer to separable filter LUT
  101. * @ de: detail enhancer configuration
  102. */
  103. struct dpu_hw_scaler3_cfg {
  104. u32 enable;
  105. u32 dir_en;
  106. int32_t init_phase_x[DPU_MAX_PLANES];
  107. int32_t phase_step_x[DPU_MAX_PLANES];
  108. int32_t init_phase_y[DPU_MAX_PLANES];
  109. int32_t phase_step_y[DPU_MAX_PLANES];
  110. u32 preload_x[DPU_MAX_PLANES];
  111. u32 preload_y[DPU_MAX_PLANES];
  112. u32 src_width[DPU_MAX_PLANES];
  113. u32 src_height[DPU_MAX_PLANES];
  114. u32 dst_width;
  115. u32 dst_height;
  116. u32 y_rgb_filter_cfg;
  117. u32 uv_filter_cfg;
  118. u32 alpha_filter_cfg;
  119. u32 blend_cfg;
  120. u32 lut_flag;
  121. u32 dir_lut_idx;
  122. u32 y_rgb_cir_lut_idx;
  123. u32 uv_cir_lut_idx;
  124. u32 y_rgb_sep_lut_idx;
  125. u32 uv_sep_lut_idx;
  126. u32 *dir_lut;
  127. size_t dir_len;
  128. u32 *cir_lut;
  129. size_t cir_len;
  130. u32 *sep_lut;
  131. size_t sep_len;
  132. /*
  133. * Detail enhancer settings
  134. */
  135. struct dpu_hw_scaler3_de_cfg de;
  136. };
  137. /**
  138. * struct dpu_drm_pix_ext_v1 - version 1 of pixel ext structure
  139. * @num_ext_pxls_lr: Number of total horizontal pixels
  140. * @num_ext_pxls_tb: Number of total vertical lines
  141. * @left_ftch: Number of extra pixels to overfetch from left
  142. * @right_ftch: Number of extra pixels to overfetch from right
  143. * @top_ftch: Number of extra lines to overfetch from top
  144. * @btm_ftch: Number of extra lines to overfetch from bottom
  145. * @left_rpt: Number of extra pixels to repeat from left
  146. * @right_rpt: Number of extra pixels to repeat from right
  147. * @top_rpt: Number of extra lines to repeat from top
  148. * @btm_rpt: Number of extra lines to repeat from bottom
  149. */
  150. struct dpu_drm_pix_ext_v1 {
  151. /*
  152. * Number of pixels ext in left, right, top and bottom direction
  153. * for all color components.
  154. */
  155. int32_t num_ext_pxls_lr[DPU_MAX_PLANES];
  156. int32_t num_ext_pxls_tb[DPU_MAX_PLANES];
  157. /*
  158. * Number of pixels needs to be overfetched in left, right, top
  159. * and bottom directions from source image for scaling.
  160. */
  161. int32_t left_ftch[DPU_MAX_PLANES];
  162. int32_t right_ftch[DPU_MAX_PLANES];
  163. int32_t top_ftch[DPU_MAX_PLANES];
  164. int32_t btm_ftch[DPU_MAX_PLANES];
  165. /*
  166. * Number of pixels needs to be repeated in left, right, top and
  167. * bottom directions for scaling.
  168. */
  169. int32_t left_rpt[DPU_MAX_PLANES];
  170. int32_t right_rpt[DPU_MAX_PLANES];
  171. int32_t top_rpt[DPU_MAX_PLANES];
  172. int32_t btm_rpt[DPU_MAX_PLANES];
  173. };
  174. /**
  175. * struct dpu_drm_de_v1 - version 1 of detail enhancer structure
  176. * @enable: Enables/disables detail enhancer
  177. * @sharpen_level1: Sharpening strength for noise
  178. * @sharpen_level2: Sharpening strength for context
  179. * @clip: Clip coefficient
  180. * @limit: Detail enhancer limit factor
  181. * @thr_quiet: Quite zone threshold
  182. * @thr_dieout: Die-out zone threshold
  183. * @thr_low: Linear zone left threshold
  184. * @thr_high: Linear zone right threshold
  185. * @prec_shift: Detail enhancer precision
  186. * @adjust_a: Mapping curves A coefficients
  187. * @adjust_b: Mapping curves B coefficients
  188. * @adjust_c: Mapping curves C coefficients
  189. */
  190. struct dpu_drm_de_v1 {
  191. uint32_t enable;
  192. int16_t sharpen_level1;
  193. int16_t sharpen_level2;
  194. uint16_t clip;
  195. uint16_t limit;
  196. uint16_t thr_quiet;
  197. uint16_t thr_dieout;
  198. uint16_t thr_low;
  199. uint16_t thr_high;
  200. uint16_t prec_shift;
  201. int16_t adjust_a[DPU_MAX_DE_CURVES];
  202. int16_t adjust_b[DPU_MAX_DE_CURVES];
  203. int16_t adjust_c[DPU_MAX_DE_CURVES];
  204. };
  205. /**
  206. * struct dpu_drm_scaler_v2 - version 2 of struct dpu_drm_scaler
  207. * @enable: Scaler enable
  208. * @dir_en: Detail enhancer enable
  209. * @pe: Pixel extension settings
  210. * @horz_decimate: Horizontal decimation factor
  211. * @vert_decimate: Vertical decimation factor
  212. * @init_phase_x: Initial scaler phase values for x
  213. * @phase_step_x: Phase step values for x
  214. * @init_phase_y: Initial scaler phase values for y
  215. * @phase_step_y: Phase step values for y
  216. * @preload_x: Horizontal preload value
  217. * @preload_y: Vertical preload value
  218. * @src_width: Source width
  219. * @src_height: Source height
  220. * @dst_width: Destination width
  221. * @dst_height: Destination height
  222. * @y_rgb_filter_cfg: Y/RGB plane filter configuration
  223. * @uv_filter_cfg: UV plane filter configuration
  224. * @alpha_filter_cfg: Alpha filter configuration
  225. * @blend_cfg: Selection of blend coefficients
  226. * @lut_flag: LUT configuration flags
  227. * @dir_lut_idx: 2d 4x4 LUT index
  228. * @y_rgb_cir_lut_idx: Y/RGB circular LUT index
  229. * @uv_cir_lut_idx: UV circular LUT index
  230. * @y_rgb_sep_lut_idx: Y/RGB separable LUT index
  231. * @uv_sep_lut_idx: UV separable LUT index
  232. * @de: Detail enhancer settings
  233. */
  234. struct dpu_drm_scaler_v2 {
  235. /*
  236. * General definitions
  237. */
  238. uint32_t enable;
  239. uint32_t dir_en;
  240. /*
  241. * Pix ext settings
  242. */
  243. struct dpu_drm_pix_ext_v1 pe;
  244. /*
  245. * Decimation settings
  246. */
  247. uint32_t horz_decimate;
  248. uint32_t vert_decimate;
  249. /*
  250. * Phase settings
  251. */
  252. int32_t init_phase_x[DPU_MAX_PLANES];
  253. int32_t phase_step_x[DPU_MAX_PLANES];
  254. int32_t init_phase_y[DPU_MAX_PLANES];
  255. int32_t phase_step_y[DPU_MAX_PLANES];
  256. uint32_t preload_x[DPU_MAX_PLANES];
  257. uint32_t preload_y[DPU_MAX_PLANES];
  258. uint32_t src_width[DPU_MAX_PLANES];
  259. uint32_t src_height[DPU_MAX_PLANES];
  260. uint32_t dst_width;
  261. uint32_t dst_height;
  262. uint32_t y_rgb_filter_cfg;
  263. uint32_t uv_filter_cfg;
  264. uint32_t alpha_filter_cfg;
  265. uint32_t blend_cfg;
  266. uint32_t lut_flag;
  267. uint32_t dir_lut_idx;
  268. /* for Y(RGB) and UV planes*/
  269. uint32_t y_rgb_cir_lut_idx;
  270. uint32_t uv_cir_lut_idx;
  271. uint32_t y_rgb_sep_lut_idx;
  272. uint32_t uv_sep_lut_idx;
  273. /*
  274. * Detail enhancer settings
  275. */
  276. struct dpu_drm_de_v1 de;
  277. };
  278. u32 *dpu_hw_util_get_log_mask_ptr(void);
  279. void dpu_reg_write(struct dpu_hw_blk_reg_map *c,
  280. u32 reg_off,
  281. u32 val,
  282. const char *name);
  283. int dpu_reg_read(struct dpu_hw_blk_reg_map *c, u32 reg_off);
  284. #define DPU_REG_WRITE(c, off, val) dpu_reg_write(c, off, val, #off)
  285. #define DPU_REG_READ(c, off) dpu_reg_read(c, off)
  286. void *dpu_hw_util_get_dir(void);
  287. void dpu_hw_setup_scaler3(struct dpu_hw_blk_reg_map *c,
  288. struct dpu_hw_scaler3_cfg *scaler3_cfg,
  289. u32 scaler_offset, u32 scaler_version,
  290. const struct dpu_format *format);
  291. u32 dpu_hw_get_scaler3_ver(struct dpu_hw_blk_reg_map *c,
  292. u32 scaler_offset);
  293. void dpu_hw_csc_setup(struct dpu_hw_blk_reg_map *c,
  294. u32 csc_reg_off,
  295. struct dpu_csc_cfg *data, bool csc10);
  296. #endif /* _DPU_HW_UTIL_H */