dpu_hw_sspp.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. #include "dpu_hwio.h"
  13. #include "dpu_hw_catalog.h"
  14. #include "dpu_hw_lm.h"
  15. #include "dpu_hw_sspp.h"
  16. #include "dpu_dbg.h"
  17. #include "dpu_kms.h"
  18. #define DPU_FETCH_CONFIG_RESET_VALUE 0x00000087
  19. /* DPU_SSPP_SRC */
  20. #define SSPP_SRC_SIZE 0x00
  21. #define SSPP_SRC_XY 0x08
  22. #define SSPP_OUT_SIZE 0x0c
  23. #define SSPP_OUT_XY 0x10
  24. #define SSPP_SRC0_ADDR 0x14
  25. #define SSPP_SRC1_ADDR 0x18
  26. #define SSPP_SRC2_ADDR 0x1C
  27. #define SSPP_SRC3_ADDR 0x20
  28. #define SSPP_SRC_YSTRIDE0 0x24
  29. #define SSPP_SRC_YSTRIDE1 0x28
  30. #define SSPP_SRC_FORMAT 0x30
  31. #define SSPP_SRC_UNPACK_PATTERN 0x34
  32. #define SSPP_SRC_OP_MODE 0x38
  33. /* SSPP_MULTIRECT*/
  34. #define SSPP_SRC_SIZE_REC1 0x16C
  35. #define SSPP_SRC_XY_REC1 0x168
  36. #define SSPP_OUT_SIZE_REC1 0x160
  37. #define SSPP_OUT_XY_REC1 0x164
  38. #define SSPP_SRC_FORMAT_REC1 0x174
  39. #define SSPP_SRC_UNPACK_PATTERN_REC1 0x178
  40. #define SSPP_SRC_OP_MODE_REC1 0x17C
  41. #define SSPP_MULTIRECT_OPMODE 0x170
  42. #define SSPP_SRC_CONSTANT_COLOR_REC1 0x180
  43. #define SSPP_EXCL_REC_SIZE_REC1 0x184
  44. #define SSPP_EXCL_REC_XY_REC1 0x188
  45. #define MDSS_MDP_OP_DEINTERLACE BIT(22)
  46. #define MDSS_MDP_OP_DEINTERLACE_ODD BIT(23)
  47. #define MDSS_MDP_OP_IGC_ROM_1 BIT(18)
  48. #define MDSS_MDP_OP_IGC_ROM_0 BIT(17)
  49. #define MDSS_MDP_OP_IGC_EN BIT(16)
  50. #define MDSS_MDP_OP_FLIP_UD BIT(14)
  51. #define MDSS_MDP_OP_FLIP_LR BIT(13)
  52. #define MDSS_MDP_OP_BWC_EN BIT(0)
  53. #define MDSS_MDP_OP_PE_OVERRIDE BIT(31)
  54. #define MDSS_MDP_OP_BWC_LOSSLESS (0 << 1)
  55. #define MDSS_MDP_OP_BWC_Q_HIGH (1 << 1)
  56. #define MDSS_MDP_OP_BWC_Q_MED (2 << 1)
  57. #define SSPP_SRC_CONSTANT_COLOR 0x3c
  58. #define SSPP_EXCL_REC_CTL 0x40
  59. #define SSPP_UBWC_STATIC_CTRL 0x44
  60. #define SSPP_FETCH_CONFIG 0x048
  61. #define SSPP_DANGER_LUT 0x60
  62. #define SSPP_SAFE_LUT 0x64
  63. #define SSPP_CREQ_LUT 0x68
  64. #define SSPP_QOS_CTRL 0x6C
  65. #define SSPP_DECIMATION_CONFIG 0xB4
  66. #define SSPP_SRC_ADDR_SW_STATUS 0x70
  67. #define SSPP_CREQ_LUT_0 0x74
  68. #define SSPP_CREQ_LUT_1 0x78
  69. #define SSPP_SW_PIX_EXT_C0_LR 0x100
  70. #define SSPP_SW_PIX_EXT_C0_TB 0x104
  71. #define SSPP_SW_PIX_EXT_C0_REQ_PIXELS 0x108
  72. #define SSPP_SW_PIX_EXT_C1C2_LR 0x110
  73. #define SSPP_SW_PIX_EXT_C1C2_TB 0x114
  74. #define SSPP_SW_PIX_EXT_C1C2_REQ_PIXELS 0x118
  75. #define SSPP_SW_PIX_EXT_C3_LR 0x120
  76. #define SSPP_SW_PIX_EXT_C3_TB 0x124
  77. #define SSPP_SW_PIX_EXT_C3_REQ_PIXELS 0x128
  78. #define SSPP_TRAFFIC_SHAPER 0x130
  79. #define SSPP_CDP_CNTL 0x134
  80. #define SSPP_UBWC_ERROR_STATUS 0x138
  81. #define SSPP_TRAFFIC_SHAPER_PREFILL 0x150
  82. #define SSPP_TRAFFIC_SHAPER_REC1_PREFILL 0x154
  83. #define SSPP_TRAFFIC_SHAPER_REC1 0x158
  84. #define SSPP_EXCL_REC_SIZE 0x1B4
  85. #define SSPP_EXCL_REC_XY 0x1B8
  86. #define SSPP_VIG_OP_MODE 0x0
  87. #define SSPP_VIG_CSC_10_OP_MODE 0x0
  88. #define SSPP_TRAFFIC_SHAPER_BPC_MAX 0xFF
  89. /* SSPP_QOS_CTRL */
  90. #define SSPP_QOS_CTRL_VBLANK_EN BIT(16)
  91. #define SSPP_QOS_CTRL_DANGER_SAFE_EN BIT(0)
  92. #define SSPP_QOS_CTRL_DANGER_VBLANK_MASK 0x3
  93. #define SSPP_QOS_CTRL_DANGER_VBLANK_OFF 4
  94. #define SSPP_QOS_CTRL_CREQ_VBLANK_MASK 0x3
  95. #define SSPP_QOS_CTRL_CREQ_VBLANK_OFF 20
  96. /* DPU_SSPP_SCALER_QSEED2 */
  97. #define SCALE_CONFIG 0x04
  98. #define COMP0_3_PHASE_STEP_X 0x10
  99. #define COMP0_3_PHASE_STEP_Y 0x14
  100. #define COMP1_2_PHASE_STEP_X 0x18
  101. #define COMP1_2_PHASE_STEP_Y 0x1c
  102. #define COMP0_3_INIT_PHASE_X 0x20
  103. #define COMP0_3_INIT_PHASE_Y 0x24
  104. #define COMP1_2_INIT_PHASE_X 0x28
  105. #define COMP1_2_INIT_PHASE_Y 0x2C
  106. #define VIG_0_QSEED2_SHARP 0x30
  107. /*
  108. * Definitions for ViG op modes
  109. */
  110. #define VIG_OP_CSC_DST_DATAFMT BIT(19)
  111. #define VIG_OP_CSC_SRC_DATAFMT BIT(18)
  112. #define VIG_OP_CSC_EN BIT(17)
  113. #define VIG_OP_MEM_PROT_CONT BIT(15)
  114. #define VIG_OP_MEM_PROT_VAL BIT(14)
  115. #define VIG_OP_MEM_PROT_SAT BIT(13)
  116. #define VIG_OP_MEM_PROT_HUE BIT(12)
  117. #define VIG_OP_HIST BIT(8)
  118. #define VIG_OP_SKY_COL BIT(7)
  119. #define VIG_OP_FOIL BIT(6)
  120. #define VIG_OP_SKIN_COL BIT(5)
  121. #define VIG_OP_PA_EN BIT(4)
  122. #define VIG_OP_PA_SAT_ZERO_EXP BIT(2)
  123. #define VIG_OP_MEM_PROT_BLEND BIT(1)
  124. /*
  125. * Definitions for CSC 10 op modes
  126. */
  127. #define VIG_CSC_10_SRC_DATAFMT BIT(1)
  128. #define VIG_CSC_10_EN BIT(0)
  129. #define CSC_10BIT_OFFSET 4
  130. /* traffic shaper clock in Hz */
  131. #define TS_CLK 19200000
  132. static inline int _sspp_subblk_offset(struct dpu_hw_pipe *ctx,
  133. int s_id,
  134. u32 *idx)
  135. {
  136. int rc = 0;
  137. const struct dpu_sspp_sub_blks *sblk = ctx->cap->sblk;
  138. if (!ctx)
  139. return -EINVAL;
  140. switch (s_id) {
  141. case DPU_SSPP_SRC:
  142. *idx = sblk->src_blk.base;
  143. break;
  144. case DPU_SSPP_SCALER_QSEED2:
  145. case DPU_SSPP_SCALER_QSEED3:
  146. case DPU_SSPP_SCALER_RGB:
  147. *idx = sblk->scaler_blk.base;
  148. break;
  149. case DPU_SSPP_CSC:
  150. case DPU_SSPP_CSC_10BIT:
  151. *idx = sblk->csc_blk.base;
  152. break;
  153. default:
  154. rc = -EINVAL;
  155. }
  156. return rc;
  157. }
  158. static void dpu_hw_sspp_setup_multirect(struct dpu_hw_pipe *ctx,
  159. enum dpu_sspp_multirect_index index,
  160. enum dpu_sspp_multirect_mode mode)
  161. {
  162. u32 mode_mask;
  163. u32 idx;
  164. if (_sspp_subblk_offset(ctx, DPU_SSPP_SRC, &idx))
  165. return;
  166. if (index == DPU_SSPP_RECT_SOLO) {
  167. /**
  168. * if rect index is RECT_SOLO, we cannot expect a
  169. * virtual plane sharing the same SSPP id. So we go
  170. * and disable multirect
  171. */
  172. mode_mask = 0;
  173. } else {
  174. mode_mask = DPU_REG_READ(&ctx->hw, SSPP_MULTIRECT_OPMODE + idx);
  175. mode_mask |= index;
  176. if (mode == DPU_SSPP_MULTIRECT_TIME_MX)
  177. mode_mask |= BIT(2);
  178. else
  179. mode_mask &= ~BIT(2);
  180. }
  181. DPU_REG_WRITE(&ctx->hw, SSPP_MULTIRECT_OPMODE + idx, mode_mask);
  182. }
  183. static void _sspp_setup_opmode(struct dpu_hw_pipe *ctx,
  184. u32 mask, u8 en)
  185. {
  186. u32 idx;
  187. u32 opmode;
  188. if (!test_bit(DPU_SSPP_SCALER_QSEED2, &ctx->cap->features) ||
  189. _sspp_subblk_offset(ctx, DPU_SSPP_SCALER_QSEED2, &idx) ||
  190. !test_bit(DPU_SSPP_CSC, &ctx->cap->features))
  191. return;
  192. opmode = DPU_REG_READ(&ctx->hw, SSPP_VIG_OP_MODE + idx);
  193. if (en)
  194. opmode |= mask;
  195. else
  196. opmode &= ~mask;
  197. DPU_REG_WRITE(&ctx->hw, SSPP_VIG_OP_MODE + idx, opmode);
  198. }
  199. static void _sspp_setup_csc10_opmode(struct dpu_hw_pipe *ctx,
  200. u32 mask, u8 en)
  201. {
  202. u32 idx;
  203. u32 opmode;
  204. if (_sspp_subblk_offset(ctx, DPU_SSPP_CSC_10BIT, &idx))
  205. return;
  206. opmode = DPU_REG_READ(&ctx->hw, SSPP_VIG_CSC_10_OP_MODE + idx);
  207. if (en)
  208. opmode |= mask;
  209. else
  210. opmode &= ~mask;
  211. DPU_REG_WRITE(&ctx->hw, SSPP_VIG_CSC_10_OP_MODE + idx, opmode);
  212. }
  213. /**
  214. * Setup source pixel format, flip,
  215. */
  216. static void dpu_hw_sspp_setup_format(struct dpu_hw_pipe *ctx,
  217. const struct dpu_format *fmt, u32 flags,
  218. enum dpu_sspp_multirect_index rect_mode)
  219. {
  220. struct dpu_hw_blk_reg_map *c;
  221. u32 chroma_samp, unpack, src_format;
  222. u32 opmode = 0;
  223. u32 fast_clear = 0;
  224. u32 op_mode_off, unpack_pat_off, format_off;
  225. u32 idx;
  226. if (_sspp_subblk_offset(ctx, DPU_SSPP_SRC, &idx) || !fmt)
  227. return;
  228. if (rect_mode == DPU_SSPP_RECT_SOLO || rect_mode == DPU_SSPP_RECT_0) {
  229. op_mode_off = SSPP_SRC_OP_MODE;
  230. unpack_pat_off = SSPP_SRC_UNPACK_PATTERN;
  231. format_off = SSPP_SRC_FORMAT;
  232. } else {
  233. op_mode_off = SSPP_SRC_OP_MODE_REC1;
  234. unpack_pat_off = SSPP_SRC_UNPACK_PATTERN_REC1;
  235. format_off = SSPP_SRC_FORMAT_REC1;
  236. }
  237. c = &ctx->hw;
  238. opmode = DPU_REG_READ(c, op_mode_off + idx);
  239. opmode &= ~(MDSS_MDP_OP_FLIP_LR | MDSS_MDP_OP_FLIP_UD |
  240. MDSS_MDP_OP_BWC_EN | MDSS_MDP_OP_PE_OVERRIDE);
  241. if (flags & DPU_SSPP_FLIP_LR)
  242. opmode |= MDSS_MDP_OP_FLIP_LR;
  243. if (flags & DPU_SSPP_FLIP_UD)
  244. opmode |= MDSS_MDP_OP_FLIP_UD;
  245. chroma_samp = fmt->chroma_sample;
  246. if (flags & DPU_SSPP_SOURCE_ROTATED_90) {
  247. if (chroma_samp == DPU_CHROMA_H2V1)
  248. chroma_samp = DPU_CHROMA_H1V2;
  249. else if (chroma_samp == DPU_CHROMA_H1V2)
  250. chroma_samp = DPU_CHROMA_H2V1;
  251. }
  252. src_format = (chroma_samp << 23) | (fmt->fetch_planes << 19) |
  253. (fmt->bits[C3_ALPHA] << 6) | (fmt->bits[C2_R_Cr] << 4) |
  254. (fmt->bits[C1_B_Cb] << 2) | (fmt->bits[C0_G_Y] << 0);
  255. if (flags & DPU_SSPP_ROT_90)
  256. src_format |= BIT(11); /* ROT90 */
  257. if (fmt->alpha_enable && fmt->fetch_planes == DPU_PLANE_INTERLEAVED)
  258. src_format |= BIT(8); /* SRCC3_EN */
  259. if (flags & DPU_SSPP_SOLID_FILL)
  260. src_format |= BIT(22);
  261. unpack = (fmt->element[3] << 24) | (fmt->element[2] << 16) |
  262. (fmt->element[1] << 8) | (fmt->element[0] << 0);
  263. src_format |= ((fmt->unpack_count - 1) << 12) |
  264. (fmt->unpack_tight << 17) |
  265. (fmt->unpack_align_msb << 18) |
  266. ((fmt->bpp - 1) << 9);
  267. if (fmt->fetch_mode != DPU_FETCH_LINEAR) {
  268. if (DPU_FORMAT_IS_UBWC(fmt))
  269. opmode |= MDSS_MDP_OP_BWC_EN;
  270. src_format |= (fmt->fetch_mode & 3) << 30; /*FRAME_FORMAT */
  271. DPU_REG_WRITE(c, SSPP_FETCH_CONFIG,
  272. DPU_FETCH_CONFIG_RESET_VALUE |
  273. ctx->mdp->highest_bank_bit << 18);
  274. if (IS_UBWC_20_SUPPORTED(ctx->catalog->caps->ubwc_version)) {
  275. fast_clear = fmt->alpha_enable ? BIT(31) : 0;
  276. DPU_REG_WRITE(c, SSPP_UBWC_STATIC_CTRL,
  277. fast_clear | (ctx->mdp->ubwc_swizzle) |
  278. (ctx->mdp->highest_bank_bit << 4));
  279. }
  280. }
  281. opmode |= MDSS_MDP_OP_PE_OVERRIDE;
  282. /* if this is YUV pixel format, enable CSC */
  283. if (DPU_FORMAT_IS_YUV(fmt))
  284. src_format |= BIT(15);
  285. if (DPU_FORMAT_IS_DX(fmt))
  286. src_format |= BIT(14);
  287. /* update scaler opmode, if appropriate */
  288. if (test_bit(DPU_SSPP_CSC, &ctx->cap->features))
  289. _sspp_setup_opmode(ctx, VIG_OP_CSC_EN | VIG_OP_CSC_SRC_DATAFMT,
  290. DPU_FORMAT_IS_YUV(fmt));
  291. else if (test_bit(DPU_SSPP_CSC_10BIT, &ctx->cap->features))
  292. _sspp_setup_csc10_opmode(ctx,
  293. VIG_CSC_10_EN | VIG_CSC_10_SRC_DATAFMT,
  294. DPU_FORMAT_IS_YUV(fmt));
  295. DPU_REG_WRITE(c, format_off + idx, src_format);
  296. DPU_REG_WRITE(c, unpack_pat_off + idx, unpack);
  297. DPU_REG_WRITE(c, op_mode_off + idx, opmode);
  298. /* clear previous UBWC error */
  299. DPU_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS + idx, BIT(31));
  300. }
  301. static void dpu_hw_sspp_setup_pe_config(struct dpu_hw_pipe *ctx,
  302. struct dpu_hw_pixel_ext *pe_ext)
  303. {
  304. struct dpu_hw_blk_reg_map *c;
  305. u8 color;
  306. u32 lr_pe[4], tb_pe[4], tot_req_pixels[4];
  307. const u32 bytemask = 0xff;
  308. const u32 shortmask = 0xffff;
  309. u32 idx;
  310. if (_sspp_subblk_offset(ctx, DPU_SSPP_SRC, &idx) || !pe_ext)
  311. return;
  312. c = &ctx->hw;
  313. /* program SW pixel extension override for all pipes*/
  314. for (color = 0; color < DPU_MAX_PLANES; color++) {
  315. /* color 2 has the same set of registers as color 1 */
  316. if (color == 2)
  317. continue;
  318. lr_pe[color] = ((pe_ext->right_ftch[color] & bytemask) << 24)|
  319. ((pe_ext->right_rpt[color] & bytemask) << 16)|
  320. ((pe_ext->left_ftch[color] & bytemask) << 8)|
  321. (pe_ext->left_rpt[color] & bytemask);
  322. tb_pe[color] = ((pe_ext->btm_ftch[color] & bytemask) << 24)|
  323. ((pe_ext->btm_rpt[color] & bytemask) << 16)|
  324. ((pe_ext->top_ftch[color] & bytemask) << 8)|
  325. (pe_ext->top_rpt[color] & bytemask);
  326. tot_req_pixels[color] = (((pe_ext->roi_h[color] +
  327. pe_ext->num_ext_pxls_top[color] +
  328. pe_ext->num_ext_pxls_btm[color]) & shortmask) << 16) |
  329. ((pe_ext->roi_w[color] +
  330. pe_ext->num_ext_pxls_left[color] +
  331. pe_ext->num_ext_pxls_right[color]) & shortmask);
  332. }
  333. /* color 0 */
  334. DPU_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_LR + idx, lr_pe[0]);
  335. DPU_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_TB + idx, tb_pe[0]);
  336. DPU_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_REQ_PIXELS + idx,
  337. tot_req_pixels[0]);
  338. /* color 1 and color 2 */
  339. DPU_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_LR + idx, lr_pe[1]);
  340. DPU_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_TB + idx, tb_pe[1]);
  341. DPU_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_REQ_PIXELS + idx,
  342. tot_req_pixels[1]);
  343. /* color 3 */
  344. DPU_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_LR + idx, lr_pe[3]);
  345. DPU_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_TB + idx, lr_pe[3]);
  346. DPU_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_REQ_PIXELS + idx,
  347. tot_req_pixels[3]);
  348. }
  349. static void _dpu_hw_sspp_setup_scaler3(struct dpu_hw_pipe *ctx,
  350. struct dpu_hw_pipe_cfg *sspp,
  351. struct dpu_hw_pixel_ext *pe,
  352. void *scaler_cfg)
  353. {
  354. u32 idx;
  355. struct dpu_hw_scaler3_cfg *scaler3_cfg = scaler_cfg;
  356. (void)pe;
  357. if (_sspp_subblk_offset(ctx, DPU_SSPP_SCALER_QSEED3, &idx) || !sspp
  358. || !scaler3_cfg || !ctx || !ctx->cap || !ctx->cap->sblk)
  359. return;
  360. dpu_hw_setup_scaler3(&ctx->hw, scaler3_cfg, idx,
  361. ctx->cap->sblk->scaler_blk.version,
  362. sspp->layout.format);
  363. }
  364. static u32 _dpu_hw_sspp_get_scaler3_ver(struct dpu_hw_pipe *ctx)
  365. {
  366. u32 idx;
  367. if (!ctx || _sspp_subblk_offset(ctx, DPU_SSPP_SCALER_QSEED3, &idx))
  368. return 0;
  369. return dpu_hw_get_scaler3_ver(&ctx->hw, idx);
  370. }
  371. /**
  372. * dpu_hw_sspp_setup_rects()
  373. */
  374. static void dpu_hw_sspp_setup_rects(struct dpu_hw_pipe *ctx,
  375. struct dpu_hw_pipe_cfg *cfg,
  376. enum dpu_sspp_multirect_index rect_index)
  377. {
  378. struct dpu_hw_blk_reg_map *c;
  379. u32 src_size, src_xy, dst_size, dst_xy, ystride0, ystride1;
  380. u32 src_size_off, src_xy_off, out_size_off, out_xy_off;
  381. u32 idx;
  382. if (_sspp_subblk_offset(ctx, DPU_SSPP_SRC, &idx) || !cfg)
  383. return;
  384. c = &ctx->hw;
  385. if (rect_index == DPU_SSPP_RECT_SOLO || rect_index == DPU_SSPP_RECT_0) {
  386. src_size_off = SSPP_SRC_SIZE;
  387. src_xy_off = SSPP_SRC_XY;
  388. out_size_off = SSPP_OUT_SIZE;
  389. out_xy_off = SSPP_OUT_XY;
  390. } else {
  391. src_size_off = SSPP_SRC_SIZE_REC1;
  392. src_xy_off = SSPP_SRC_XY_REC1;
  393. out_size_off = SSPP_OUT_SIZE_REC1;
  394. out_xy_off = SSPP_OUT_XY_REC1;
  395. }
  396. /* src and dest rect programming */
  397. src_xy = (cfg->src_rect.y1 << 16) | cfg->src_rect.x1;
  398. src_size = (drm_rect_height(&cfg->src_rect) << 16) |
  399. drm_rect_width(&cfg->src_rect);
  400. dst_xy = (cfg->dst_rect.y1 << 16) | cfg->dst_rect.x1;
  401. dst_size = (drm_rect_height(&cfg->dst_rect) << 16) |
  402. drm_rect_width(&cfg->dst_rect);
  403. if (rect_index == DPU_SSPP_RECT_SOLO) {
  404. ystride0 = (cfg->layout.plane_pitch[0]) |
  405. (cfg->layout.plane_pitch[1] << 16);
  406. ystride1 = (cfg->layout.plane_pitch[2]) |
  407. (cfg->layout.plane_pitch[3] << 16);
  408. } else {
  409. ystride0 = DPU_REG_READ(c, SSPP_SRC_YSTRIDE0 + idx);
  410. ystride1 = DPU_REG_READ(c, SSPP_SRC_YSTRIDE1 + idx);
  411. if (rect_index == DPU_SSPP_RECT_0) {
  412. ystride0 = (ystride0 & 0xFFFF0000) |
  413. (cfg->layout.plane_pitch[0] & 0x0000FFFF);
  414. ystride1 = (ystride1 & 0xFFFF0000)|
  415. (cfg->layout.plane_pitch[2] & 0x0000FFFF);
  416. } else {
  417. ystride0 = (ystride0 & 0x0000FFFF) |
  418. ((cfg->layout.plane_pitch[0] << 16) &
  419. 0xFFFF0000);
  420. ystride1 = (ystride1 & 0x0000FFFF) |
  421. ((cfg->layout.plane_pitch[2] << 16) &
  422. 0xFFFF0000);
  423. }
  424. }
  425. /* rectangle register programming */
  426. DPU_REG_WRITE(c, src_size_off + idx, src_size);
  427. DPU_REG_WRITE(c, src_xy_off + idx, src_xy);
  428. DPU_REG_WRITE(c, out_size_off + idx, dst_size);
  429. DPU_REG_WRITE(c, out_xy_off + idx, dst_xy);
  430. DPU_REG_WRITE(c, SSPP_SRC_YSTRIDE0 + idx, ystride0);
  431. DPU_REG_WRITE(c, SSPP_SRC_YSTRIDE1 + idx, ystride1);
  432. }
  433. static void dpu_hw_sspp_setup_sourceaddress(struct dpu_hw_pipe *ctx,
  434. struct dpu_hw_pipe_cfg *cfg,
  435. enum dpu_sspp_multirect_index rect_mode)
  436. {
  437. int i;
  438. u32 idx;
  439. if (_sspp_subblk_offset(ctx, DPU_SSPP_SRC, &idx))
  440. return;
  441. if (rect_mode == DPU_SSPP_RECT_SOLO) {
  442. for (i = 0; i < ARRAY_SIZE(cfg->layout.plane_addr); i++)
  443. DPU_REG_WRITE(&ctx->hw, SSPP_SRC0_ADDR + idx + i * 0x4,
  444. cfg->layout.plane_addr[i]);
  445. } else if (rect_mode == DPU_SSPP_RECT_0) {
  446. DPU_REG_WRITE(&ctx->hw, SSPP_SRC0_ADDR + idx,
  447. cfg->layout.plane_addr[0]);
  448. DPU_REG_WRITE(&ctx->hw, SSPP_SRC2_ADDR + idx,
  449. cfg->layout.plane_addr[2]);
  450. } else {
  451. DPU_REG_WRITE(&ctx->hw, SSPP_SRC1_ADDR + idx,
  452. cfg->layout.plane_addr[0]);
  453. DPU_REG_WRITE(&ctx->hw, SSPP_SRC3_ADDR + idx,
  454. cfg->layout.plane_addr[2]);
  455. }
  456. }
  457. static void dpu_hw_sspp_setup_csc(struct dpu_hw_pipe *ctx,
  458. struct dpu_csc_cfg *data)
  459. {
  460. u32 idx;
  461. bool csc10 = false;
  462. if (_sspp_subblk_offset(ctx, DPU_SSPP_CSC, &idx) || !data)
  463. return;
  464. if (test_bit(DPU_SSPP_CSC_10BIT, &ctx->cap->features)) {
  465. idx += CSC_10BIT_OFFSET;
  466. csc10 = true;
  467. }
  468. dpu_hw_csc_setup(&ctx->hw, idx, data, csc10);
  469. }
  470. static void dpu_hw_sspp_setup_solidfill(struct dpu_hw_pipe *ctx, u32 color, enum
  471. dpu_sspp_multirect_index rect_index)
  472. {
  473. u32 idx;
  474. if (_sspp_subblk_offset(ctx, DPU_SSPP_SRC, &idx))
  475. return;
  476. if (rect_index == DPU_SSPP_RECT_SOLO || rect_index == DPU_SSPP_RECT_0)
  477. DPU_REG_WRITE(&ctx->hw, SSPP_SRC_CONSTANT_COLOR + idx, color);
  478. else
  479. DPU_REG_WRITE(&ctx->hw, SSPP_SRC_CONSTANT_COLOR_REC1 + idx,
  480. color);
  481. }
  482. static void dpu_hw_sspp_setup_danger_safe_lut(struct dpu_hw_pipe *ctx,
  483. struct dpu_hw_pipe_qos_cfg *cfg)
  484. {
  485. u32 idx;
  486. if (_sspp_subblk_offset(ctx, DPU_SSPP_SRC, &idx))
  487. return;
  488. DPU_REG_WRITE(&ctx->hw, SSPP_DANGER_LUT + idx, cfg->danger_lut);
  489. DPU_REG_WRITE(&ctx->hw, SSPP_SAFE_LUT + idx, cfg->safe_lut);
  490. }
  491. static void dpu_hw_sspp_setup_creq_lut(struct dpu_hw_pipe *ctx,
  492. struct dpu_hw_pipe_qos_cfg *cfg)
  493. {
  494. u32 idx;
  495. if (_sspp_subblk_offset(ctx, DPU_SSPP_SRC, &idx))
  496. return;
  497. if (ctx->cap && test_bit(DPU_SSPP_QOS_8LVL, &ctx->cap->features)) {
  498. DPU_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT_0 + idx, cfg->creq_lut);
  499. DPU_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT_1 + idx,
  500. cfg->creq_lut >> 32);
  501. } else {
  502. DPU_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT + idx, cfg->creq_lut);
  503. }
  504. }
  505. static void dpu_hw_sspp_setup_qos_ctrl(struct dpu_hw_pipe *ctx,
  506. struct dpu_hw_pipe_qos_cfg *cfg)
  507. {
  508. u32 idx;
  509. u32 qos_ctrl = 0;
  510. if (_sspp_subblk_offset(ctx, DPU_SSPP_SRC, &idx))
  511. return;
  512. if (cfg->vblank_en) {
  513. qos_ctrl |= ((cfg->creq_vblank &
  514. SSPP_QOS_CTRL_CREQ_VBLANK_MASK) <<
  515. SSPP_QOS_CTRL_CREQ_VBLANK_OFF);
  516. qos_ctrl |= ((cfg->danger_vblank &
  517. SSPP_QOS_CTRL_DANGER_VBLANK_MASK) <<
  518. SSPP_QOS_CTRL_DANGER_VBLANK_OFF);
  519. qos_ctrl |= SSPP_QOS_CTRL_VBLANK_EN;
  520. }
  521. if (cfg->danger_safe_en)
  522. qos_ctrl |= SSPP_QOS_CTRL_DANGER_SAFE_EN;
  523. DPU_REG_WRITE(&ctx->hw, SSPP_QOS_CTRL + idx, qos_ctrl);
  524. }
  525. static void dpu_hw_sspp_setup_cdp(struct dpu_hw_pipe *ctx,
  526. struct dpu_hw_pipe_cdp_cfg *cfg)
  527. {
  528. u32 idx;
  529. u32 cdp_cntl = 0;
  530. if (!ctx || !cfg)
  531. return;
  532. if (_sspp_subblk_offset(ctx, DPU_SSPP_SRC, &idx))
  533. return;
  534. if (cfg->enable)
  535. cdp_cntl |= BIT(0);
  536. if (cfg->ubwc_meta_enable)
  537. cdp_cntl |= BIT(1);
  538. if (cfg->tile_amortize_enable)
  539. cdp_cntl |= BIT(2);
  540. if (cfg->preload_ahead == DPU_SSPP_CDP_PRELOAD_AHEAD_64)
  541. cdp_cntl |= BIT(3);
  542. DPU_REG_WRITE(&ctx->hw, SSPP_CDP_CNTL, cdp_cntl);
  543. }
  544. static void _setup_layer_ops(struct dpu_hw_pipe *c,
  545. unsigned long features)
  546. {
  547. if (test_bit(DPU_SSPP_SRC, &features)) {
  548. c->ops.setup_format = dpu_hw_sspp_setup_format;
  549. c->ops.setup_rects = dpu_hw_sspp_setup_rects;
  550. c->ops.setup_sourceaddress = dpu_hw_sspp_setup_sourceaddress;
  551. c->ops.setup_solidfill = dpu_hw_sspp_setup_solidfill;
  552. c->ops.setup_pe = dpu_hw_sspp_setup_pe_config;
  553. }
  554. if (test_bit(DPU_SSPP_QOS, &features)) {
  555. c->ops.setup_danger_safe_lut =
  556. dpu_hw_sspp_setup_danger_safe_lut;
  557. c->ops.setup_creq_lut = dpu_hw_sspp_setup_creq_lut;
  558. c->ops.setup_qos_ctrl = dpu_hw_sspp_setup_qos_ctrl;
  559. }
  560. if (test_bit(DPU_SSPP_CSC, &features) ||
  561. test_bit(DPU_SSPP_CSC_10BIT, &features))
  562. c->ops.setup_csc = dpu_hw_sspp_setup_csc;
  563. if (dpu_hw_sspp_multirect_enabled(c->cap))
  564. c->ops.setup_multirect = dpu_hw_sspp_setup_multirect;
  565. if (test_bit(DPU_SSPP_SCALER_QSEED3, &features)) {
  566. c->ops.setup_scaler = _dpu_hw_sspp_setup_scaler3;
  567. c->ops.get_scaler_ver = _dpu_hw_sspp_get_scaler3_ver;
  568. }
  569. if (test_bit(DPU_SSPP_CDP, &features))
  570. c->ops.setup_cdp = dpu_hw_sspp_setup_cdp;
  571. }
  572. static struct dpu_sspp_cfg *_sspp_offset(enum dpu_sspp sspp,
  573. void __iomem *addr,
  574. struct dpu_mdss_cfg *catalog,
  575. struct dpu_hw_blk_reg_map *b)
  576. {
  577. int i;
  578. if ((sspp < SSPP_MAX) && catalog && addr && b) {
  579. for (i = 0; i < catalog->sspp_count; i++) {
  580. if (sspp == catalog->sspp[i].id) {
  581. b->base_off = addr;
  582. b->blk_off = catalog->sspp[i].base;
  583. b->length = catalog->sspp[i].len;
  584. b->hwversion = catalog->hwversion;
  585. b->log_mask = DPU_DBG_MASK_SSPP;
  586. return &catalog->sspp[i];
  587. }
  588. }
  589. }
  590. return ERR_PTR(-ENOMEM);
  591. }
  592. static struct dpu_hw_blk_ops dpu_hw_ops = {
  593. .start = NULL,
  594. .stop = NULL,
  595. };
  596. struct dpu_hw_pipe *dpu_hw_sspp_init(enum dpu_sspp idx,
  597. void __iomem *addr, struct dpu_mdss_cfg *catalog,
  598. bool is_virtual_pipe)
  599. {
  600. struct dpu_hw_pipe *hw_pipe;
  601. struct dpu_sspp_cfg *cfg;
  602. int rc;
  603. if (!addr || !catalog)
  604. return ERR_PTR(-EINVAL);
  605. hw_pipe = kzalloc(sizeof(*hw_pipe), GFP_KERNEL);
  606. if (!hw_pipe)
  607. return ERR_PTR(-ENOMEM);
  608. cfg = _sspp_offset(idx, addr, catalog, &hw_pipe->hw);
  609. if (IS_ERR_OR_NULL(cfg)) {
  610. kfree(hw_pipe);
  611. return ERR_PTR(-EINVAL);
  612. }
  613. /* Assign ops */
  614. hw_pipe->catalog = catalog;
  615. hw_pipe->mdp = &catalog->mdp[0];
  616. hw_pipe->idx = idx;
  617. hw_pipe->cap = cfg;
  618. _setup_layer_ops(hw_pipe, hw_pipe->cap->features);
  619. rc = dpu_hw_blk_init(&hw_pipe->base, DPU_HW_BLK_SSPP, idx, &dpu_hw_ops);
  620. if (rc) {
  621. DPU_ERROR("failed to init hw blk %d\n", rc);
  622. goto blk_init_error;
  623. }
  624. return hw_pipe;
  625. blk_init_error:
  626. kzfree(hw_pipe);
  627. return ERR_PTR(rc);
  628. }
  629. void dpu_hw_sspp_destroy(struct dpu_hw_pipe *ctx)
  630. {
  631. if (ctx)
  632. dpu_hw_blk_destroy(&ctx->base);
  633. kfree(ctx);
  634. }