sde_hw_wb.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include "sde_hw_mdss.h"
  6. #include "sde_hwio.h"
  7. #include "sde_hw_catalog.h"
  8. #include "sde_hw_wb.h"
  9. #include "sde_formats.h"
  10. #include "sde_dbg.h"
  11. #include "sde_kms.h"
  12. #define WB_DST_FORMAT 0x000
  13. #define WB_DST_OP_MODE 0x004
  14. #define WB_DST_PACK_PATTERN 0x008
  15. #define WB_DST0_ADDR 0x00C
  16. #define WB_DST1_ADDR 0x010
  17. #define WB_DST2_ADDR 0x014
  18. #define WB_DST3_ADDR 0x018
  19. #define WB_DST_YSTRIDE0 0x01C
  20. #define WB_DST_YSTRIDE1 0x020
  21. #define WB_DST_YSTRIDE1 0x020
  22. #define WB_DST_DITHER_BITDEPTH 0x024
  23. #define WB_DST_MATRIX_ROW0 0x030
  24. #define WB_DST_MATRIX_ROW1 0x034
  25. #define WB_DST_MATRIX_ROW2 0x038
  26. #define WB_DST_MATRIX_ROW3 0x03C
  27. #define WB_DST_WRITE_CONFIG 0x048
  28. #define WB_ROTATION_DNSCALER 0x050
  29. #define WB_ROTATOR_PIPE_DOWNSCALER 0x054
  30. #define WB_N16_INIT_PHASE_X_C03 0x060
  31. #define WB_N16_INIT_PHASE_X_C12 0x064
  32. #define WB_N16_INIT_PHASE_Y_C03 0x068
  33. #define WB_N16_INIT_PHASE_Y_C12 0x06C
  34. #define WB_OUT_SIZE 0x074
  35. #define WB_ALPHA_X_VALUE 0x078
  36. #define WB_DANGER_LUT 0x084
  37. #define WB_SAFE_LUT 0x088
  38. #define WB_QOS_CTRL 0x090
  39. #define WB_CREQ_LUT_0 0x098
  40. #define WB_CREQ_LUT_1 0x09C
  41. #define WB_UBWC_STATIC_CTRL 0x144
  42. #define WB_MUX 0x150
  43. #define WB_CROP_CTRL 0x154
  44. #define WB_CROP_OFFSET 0x158
  45. #define WB_CSC_BASE 0x260
  46. #define WB_DST_ADDR_SW_STATUS 0x2B0
  47. #define WB_CDP_CNTL 0x2B4
  48. #define WB_OUT_IMAGE_SIZE 0x2C0
  49. #define WB_OUT_XY 0x2C4
  50. #define CWB_CTRL_SRC_SEL 0x0
  51. #define CWB_CTRL_MODE 0x4
  52. /* WB_QOS_CTRL */
  53. #define WB_QOS_CTRL_DANGER_SAFE_EN BIT(0)
  54. static struct sde_wb_cfg *_wb_offset(enum sde_wb wb,
  55. struct sde_mdss_cfg *m,
  56. void __iomem *addr,
  57. struct sde_hw_blk_reg_map *b)
  58. {
  59. int i;
  60. for (i = 0; i < m->wb_count; i++) {
  61. if (wb == m->wb[i].id) {
  62. b->base_off = addr;
  63. b->blk_off = m->wb[i].base;
  64. b->length = m->wb[i].len;
  65. b->hwversion = m->hwversion;
  66. b->log_mask = SDE_DBG_MASK_WB;
  67. return &m->wb[i];
  68. }
  69. }
  70. return ERR_PTR(-EINVAL);
  71. }
  72. static void _sde_hw_cwb_ctrl_init(struct sde_mdss_cfg *m,
  73. void __iomem *addr, struct sde_hw_blk_reg_map *b)
  74. {
  75. int i;
  76. u32 blk_off;
  77. char name[64] = {0};
  78. if (!b)
  79. return;
  80. b->base_off = addr;
  81. b->blk_off = m->cwb_blk_off;
  82. b->length = 0x20;
  83. b->hwversion = m->hwversion;
  84. b->log_mask = SDE_DBG_MASK_WB;
  85. for (i = 0; i < m->pingpong_count; i++) {
  86. snprintf(name, sizeof(name), "cwb%d", i);
  87. blk_off = b->blk_off + (m->cwb_blk_stride * i);
  88. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, name,
  89. blk_off, blk_off + b->length, 0xff);
  90. }
  91. }
  92. static void _sde_hw_dcwb_ctrl_init(struct sde_mdss_cfg *m,
  93. void __iomem *addr, struct sde_hw_blk_reg_map *b)
  94. {
  95. int i;
  96. u32 blk_off;
  97. char name[64] = {0};
  98. if (!b)
  99. return;
  100. b->base_off = addr;
  101. b->blk_off = m->cwb_blk_off;
  102. b->length = 0x20;
  103. b->hwversion = m->hwversion;
  104. b->log_mask = SDE_DBG_MASK_WB;
  105. for (i = 0; i < m->dcwb_count; i++) {
  106. snprintf(name, sizeof(name), "dcwb%d", i);
  107. blk_off = b->blk_off + (m->cwb_blk_stride * i);
  108. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, name,
  109. blk_off, blk_off + b->length, 0xff);
  110. }
  111. }
  112. static void sde_hw_wb_setup_outaddress(struct sde_hw_wb *ctx,
  113. struct sde_hw_wb_cfg *data)
  114. {
  115. struct sde_hw_blk_reg_map *c = &ctx->hw;
  116. SDE_REG_WRITE(c, WB_DST0_ADDR, data->dest.plane_addr[0]);
  117. SDE_REG_WRITE(c, WB_DST1_ADDR, data->dest.plane_addr[1]);
  118. SDE_REG_WRITE(c, WB_DST2_ADDR, data->dest.plane_addr[2]);
  119. SDE_REG_WRITE(c, WB_DST3_ADDR, data->dest.plane_addr[3]);
  120. }
  121. static void sde_hw_wb_setup_format(struct sde_hw_wb *ctx,
  122. struct sde_hw_wb_cfg *data)
  123. {
  124. struct sde_hw_blk_reg_map *c = &ctx->hw;
  125. const struct sde_format *fmt = data->dest.format;
  126. u32 dst_format, pattern, ystride0, ystride1, outsize, chroma_samp;
  127. u32 write_config = 0;
  128. u32 opmode = 0;
  129. u32 dst_addr_sw = 0;
  130. chroma_samp = fmt->chroma_sample;
  131. dst_format = (chroma_samp << 23) |
  132. (fmt->fetch_planes << 19) |
  133. (fmt->bits[C3_ALPHA] << 6) |
  134. (fmt->bits[C2_R_Cr] << 4) |
  135. (fmt->bits[C1_B_Cb] << 2) |
  136. (fmt->bits[C0_G_Y] << 0);
  137. if (fmt->bits[C3_ALPHA] || fmt->alpha_enable) {
  138. dst_format |= BIT(8); /* DSTC3_EN */
  139. if (!fmt->alpha_enable ||
  140. !(ctx->caps->features & BIT(SDE_WB_PIPE_ALPHA)))
  141. dst_format |= BIT(14); /* DST_ALPHA_X */
  142. }
  143. if (SDE_FORMAT_IS_YUV(fmt) &&
  144. (ctx->caps->features & BIT(SDE_WB_YUV_CONFIG)))
  145. dst_format |= BIT(15);
  146. if (SDE_FORMAT_IS_DX(fmt))
  147. dst_format |= BIT(21);
  148. pattern = (fmt->element[3] << 24) |
  149. (fmt->element[2] << 16) |
  150. (fmt->element[1] << 8) |
  151. (fmt->element[0] << 0);
  152. dst_format |= (fmt->unpack_align_msb << 18) |
  153. (fmt->unpack_tight << 17) |
  154. ((fmt->unpack_count - 1) << 12) |
  155. ((fmt->bpp - 1) << 9);
  156. ystride0 = data->dest.plane_pitch[0] |
  157. (data->dest.plane_pitch[1] << 16);
  158. ystride1 = data->dest.plane_pitch[2] |
  159. (data->dest.plane_pitch[3] << 16);
  160. if (data->roi.h && data->roi.w)
  161. outsize = (data->roi.h << 16) | data->roi.w;
  162. else
  163. outsize = (data->dest.height << 16) | data->dest.width;
  164. if (SDE_FORMAT_IS_UBWC(fmt)) {
  165. opmode |= BIT(0);
  166. dst_format |= BIT(31);
  167. write_config |= (ctx->mdp->highest_bank_bit << 8);
  168. if (fmt->base.pixel_format == DRM_FORMAT_RGB565)
  169. write_config |= 0x8;
  170. if (IS_UBWC_20_SUPPORTED(ctx->catalog->ubwc_version))
  171. SDE_REG_WRITE(c, WB_UBWC_STATIC_CTRL,
  172. (ctx->mdp->ubwc_swizzle << 0) |
  173. (ctx->mdp->highest_bank_bit << 4));
  174. if (IS_UBWC_10_SUPPORTED(ctx->catalog->ubwc_version))
  175. SDE_REG_WRITE(c, WB_UBWC_STATIC_CTRL,
  176. (ctx->mdp->ubwc_swizzle << 0) |
  177. BIT(8) |
  178. (ctx->mdp->highest_bank_bit << 4));
  179. }
  180. if (data->is_secure)
  181. dst_addr_sw |= BIT(0);
  182. SDE_REG_WRITE(c, WB_ALPHA_X_VALUE, 0xFF);
  183. SDE_REG_WRITE(c, WB_DST_FORMAT, dst_format);
  184. SDE_REG_WRITE(c, WB_DST_OP_MODE, opmode);
  185. SDE_REG_WRITE(c, WB_DST_PACK_PATTERN, pattern);
  186. SDE_REG_WRITE(c, WB_DST_YSTRIDE0, ystride0);
  187. SDE_REG_WRITE(c, WB_DST_YSTRIDE1, ystride1);
  188. SDE_REG_WRITE(c, WB_OUT_SIZE, outsize);
  189. SDE_REG_WRITE(c, WB_DST_WRITE_CONFIG, write_config);
  190. SDE_REG_WRITE(c, WB_DST_ADDR_SW_STATUS, dst_addr_sw);
  191. }
  192. static void sde_hw_wb_roi(struct sde_hw_wb *ctx, struct sde_hw_wb_cfg *wb)
  193. {
  194. struct sde_hw_blk_reg_map *c = &ctx->hw;
  195. u32 image_size, out_size, out_xy;
  196. image_size = (wb->dest.height << 16) | wb->dest.width;
  197. out_xy = (wb->roi.y << 16) | wb->roi.x;
  198. out_size = (wb->roi.h << 16) | wb->roi.w;
  199. SDE_REG_WRITE(c, WB_OUT_IMAGE_SIZE, image_size);
  200. SDE_REG_WRITE(c, WB_OUT_XY, out_xy);
  201. SDE_REG_WRITE(c, WB_OUT_SIZE, out_size);
  202. }
  203. static void sde_hw_wb_crop(struct sde_hw_wb *ctx, struct sde_hw_wb_cfg *wb, bool crop)
  204. {
  205. struct sde_hw_blk_reg_map *c = &ctx->hw;
  206. u32 crop_xy;
  207. crop_xy = (wb->crop.y << 16) | wb->crop.x;
  208. if (crop) {
  209. SDE_REG_WRITE(c, WB_CROP_CTRL, 0x1);
  210. SDE_REG_WRITE(c, WB_CROP_OFFSET, crop_xy);
  211. } else {
  212. SDE_REG_WRITE(c, WB_CROP_CTRL, 0x0);
  213. }
  214. }
  215. static void sde_hw_wb_setup_qos_lut(struct sde_hw_wb *ctx,
  216. struct sde_hw_wb_qos_cfg *cfg)
  217. {
  218. struct sde_hw_blk_reg_map *c = &ctx->hw;
  219. u32 qos_ctrl = 0;
  220. if (!ctx || !cfg)
  221. return;
  222. SDE_REG_WRITE(c, WB_DANGER_LUT, cfg->danger_lut);
  223. SDE_REG_WRITE(c, WB_SAFE_LUT, cfg->safe_lut);
  224. if (ctx->caps && test_bit(SDE_WB_QOS_8LVL, &ctx->caps->features)) {
  225. SDE_REG_WRITE(c, WB_CREQ_LUT_0, cfg->creq_lut);
  226. SDE_REG_WRITE(c, WB_CREQ_LUT_1, cfg->creq_lut >> 32);
  227. }
  228. if (cfg->danger_safe_en)
  229. qos_ctrl |= WB_QOS_CTRL_DANGER_SAFE_EN;
  230. SDE_REG_WRITE(c, WB_QOS_CTRL, qos_ctrl);
  231. }
  232. static void sde_hw_wb_setup_cdp(struct sde_hw_wb *ctx,
  233. struct sde_hw_wb_cdp_cfg *cfg)
  234. {
  235. struct sde_hw_blk_reg_map *c;
  236. u32 cdp_cntl = 0;
  237. if (!ctx || !cfg)
  238. return;
  239. c = &ctx->hw;
  240. if (cfg->enable)
  241. cdp_cntl |= BIT(0);
  242. if (cfg->ubwc_meta_enable)
  243. cdp_cntl |= BIT(1);
  244. if (cfg->preload_ahead == SDE_WB_CDP_PRELOAD_AHEAD_64)
  245. cdp_cntl |= BIT(3);
  246. SDE_REG_WRITE(c, WB_CDP_CNTL, cdp_cntl);
  247. }
  248. static void sde_hw_wb_bind_pingpong_blk(
  249. struct sde_hw_wb *ctx,
  250. bool enable,
  251. const enum sde_pingpong pp)
  252. {
  253. struct sde_hw_blk_reg_map *c;
  254. int mux_cfg = 0xF;
  255. if (!ctx)
  256. return;
  257. c = &ctx->hw;
  258. if (enable)
  259. mux_cfg = (pp - PINGPONG_0) & 0x7;
  260. SDE_REG_WRITE(c, WB_MUX, mux_cfg);
  261. }
  262. static void sde_hw_wb_bind_dcwb_pp_blk(
  263. struct sde_hw_wb *ctx,
  264. bool enable,
  265. const enum sde_pingpong pp)
  266. {
  267. struct sde_hw_blk_reg_map *c;
  268. int mux_cfg = 0xF;
  269. if (!ctx)
  270. return;
  271. c = &ctx->hw;
  272. if (enable)
  273. mux_cfg = 0xd;
  274. SDE_REG_WRITE(c, WB_MUX, mux_cfg);
  275. }
  276. static void sde_hw_wb_program_dcwb_ctrl(struct sde_hw_wb *ctx,
  277. const enum sde_dcwb cur_idx, const enum sde_cwb data_src,
  278. int tap_location, bool enable)
  279. {
  280. struct sde_hw_blk_reg_map *c;
  281. u32 blk_base;
  282. if (!ctx)
  283. return;
  284. c = &ctx->dcwb_hw;
  285. blk_base = ctx->catalog->cwb_blk_stride * (cur_idx - DCWB_0);
  286. if (enable) {
  287. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, data_src - CWB_0);
  288. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, tap_location);
  289. } else {
  290. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, 0xf);
  291. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, 0x0);
  292. }
  293. }
  294. static void sde_hw_wb_program_cwb_ctrl(struct sde_hw_wb *ctx,
  295. const enum sde_cwb cur_idx, const enum sde_cwb data_src,
  296. bool dspp_out, bool enable)
  297. {
  298. struct sde_hw_blk_reg_map *c;
  299. u32 blk_base;
  300. if (!ctx)
  301. return;
  302. c = &ctx->cwb_hw;
  303. blk_base = ctx->catalog->cwb_blk_stride * (cur_idx - CWB_0);
  304. if (enable) {
  305. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, data_src - CWB_0);
  306. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, dspp_out);
  307. } else {
  308. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, 0xf);
  309. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, 0x0);
  310. }
  311. }
  312. static void _setup_wb_ops(struct sde_hw_wb_ops *ops,
  313. unsigned long features)
  314. {
  315. ops->setup_outaddress = sde_hw_wb_setup_outaddress;
  316. ops->setup_outformat = sde_hw_wb_setup_format;
  317. if (test_bit(SDE_WB_XY_ROI_OFFSET, &features))
  318. ops->setup_roi = sde_hw_wb_roi;
  319. if (test_bit(SDE_WB_CROP, &features))
  320. ops->setup_crop = sde_hw_wb_crop;
  321. if (test_bit(SDE_WB_QOS, &features))
  322. ops->setup_qos_lut = sde_hw_wb_setup_qos_lut;
  323. if (test_bit(SDE_WB_CDP, &features))
  324. ops->setup_cdp = sde_hw_wb_setup_cdp;
  325. if (test_bit(SDE_WB_INPUT_CTRL, &features))
  326. ops->bind_pingpong_blk = sde_hw_wb_bind_pingpong_blk;
  327. if (test_bit(SDE_WB_CWB_CTRL, &features))
  328. ops->program_cwb_ctrl = sde_hw_wb_program_cwb_ctrl;
  329. if (test_bit(SDE_WB_DCWB_CTRL, &features)) {
  330. ops->program_dcwb_ctrl = sde_hw_wb_program_dcwb_ctrl;
  331. ops->bind_dcwb_pp_blk = sde_hw_wb_bind_dcwb_pp_blk;
  332. }
  333. }
  334. static struct sde_hw_blk_ops sde_hw_ops = {
  335. .start = NULL,
  336. .stop = NULL,
  337. };
  338. struct sde_hw_wb *sde_hw_wb_init(enum sde_wb idx,
  339. void __iomem *addr,
  340. struct sde_mdss_cfg *m,
  341. struct sde_hw_mdp *hw_mdp)
  342. {
  343. struct sde_hw_wb *c;
  344. struct sde_wb_cfg *cfg;
  345. int rc;
  346. if (!addr || !m || !hw_mdp)
  347. return ERR_PTR(-EINVAL);
  348. c = kzalloc(sizeof(*c), GFP_KERNEL);
  349. if (!c)
  350. return ERR_PTR(-ENOMEM);
  351. cfg = _wb_offset(idx, m, addr, &c->hw);
  352. if (IS_ERR(cfg)) {
  353. WARN(1, "Unable to find wb idx=%d\n", idx);
  354. kfree(c);
  355. return ERR_PTR(-EINVAL);
  356. }
  357. /* Assign ops */
  358. c->catalog = m;
  359. c->mdp = &m->mdp[0];
  360. c->idx = idx;
  361. c->caps = cfg;
  362. _setup_wb_ops(&c->ops, c->caps->features);
  363. c->hw_mdp = hw_mdp;
  364. rc = sde_hw_blk_init(&c->base, SDE_HW_BLK_WB, idx, &sde_hw_ops);
  365. if (rc) {
  366. SDE_ERROR("failed to init hw blk %d\n", rc);
  367. goto blk_init_error;
  368. }
  369. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  370. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  371. if (test_bit(SDE_WB_CWB_CTRL, &cfg->features))
  372. _sde_hw_cwb_ctrl_init(m, addr, &c->cwb_hw);
  373. if (test_bit(SDE_WB_DCWB_CTRL, &cfg->features))
  374. _sde_hw_dcwb_ctrl_init(m, addr, &c->dcwb_hw);
  375. return c;
  376. blk_init_error:
  377. kfree(c);
  378. return ERR_PTR(rc);
  379. }
  380. void sde_hw_wb_destroy(struct sde_hw_wb *hw_wb)
  381. {
  382. if (hw_wb)
  383. sde_hw_blk_destroy(&hw_wb->base);
  384. kfree(hw_wb);
  385. }