sde_hw_wb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  7. #include "sde_hw_mdss.h"
  8. #include "sde_hwio.h"
  9. #include "sde_hw_catalog.h"
  10. #include "sde_hw_wb.h"
  11. #include "sde_formats.h"
  12. #include "sde_dbg.h"
  13. #include "sde_kms.h"
  14. #include "sde_vbif.h"
  15. #define WB_DST_FORMAT 0x000
  16. #define WB_DST_OP_MODE 0x004
  17. #define WB_DST_PACK_PATTERN 0x008
  18. #define WB_DST0_ADDR 0x00C
  19. #define WB_DST1_ADDR 0x010
  20. #define WB_DST2_ADDR 0x014
  21. #define WB_DST3_ADDR 0x018
  22. #define WB_DST_YSTRIDE0 0x01C
  23. #define WB_DST_YSTRIDE1 0x020
  24. #define WB_TS_WR_CLIENT 0x040
  25. #define WB_DST_WRITE_CONFIG 0x048
  26. #define WB_OUT_SIZE 0x074
  27. #define WB_ALPHA_X_VALUE 0x078
  28. #define WB_DANGER_LUT 0x084
  29. #define WB_SAFE_LUT 0x088
  30. #define WB_QOS_CTRL 0x090
  31. #define WB_CREQ_LUT_0 0x098
  32. #define WB_CREQ_LUT_1 0x09C
  33. #define WB_UBWC_STATIC_CTRL 0x144
  34. #define WB_MUX 0x150
  35. #define WB_CROP_CTRL 0x154
  36. #define WB_CROP_OFFSET 0x158
  37. #define WB_CLK_CTRL 0x178
  38. #define WB_CLK_STATUS 0x17C
  39. #define WB_LINE_COUNT 0x184
  40. #define WB_PROG_LINE_COUNT 0x188
  41. #define WB_CSC_BASE 0x260
  42. #define WB_DST_ADDR_SW_STATUS 0x2B0
  43. #define WB_CDP_CNTL 0x2B4
  44. #define WB_UBWC_ERROR_STATUS 0x2BC
  45. #define WB_OUT_IMAGE_SIZE 0x2C0
  46. #define WB_OUT_XY 0x2C4
  47. #define WB_SYS_CACHE_MODE 0x094
  48. #define CWB_CTRL_SRC_SEL 0x0
  49. #define CWB_CTRL_MODE 0x4
  50. /* WB_QOS_CTRL */
  51. #define WB_QOS_CTRL_DANGER_SAFE_EN BIT(0)
  52. static struct sde_wb_cfg *_wb_offset(enum sde_wb wb,
  53. struct sde_mdss_cfg *m,
  54. void __iomem *addr,
  55. struct sde_hw_blk_reg_map *b)
  56. {
  57. int i;
  58. for (i = 0; i < m->wb_count; i++) {
  59. if (wb == m->wb[i].id) {
  60. b->base_off = addr;
  61. b->blk_off = m->wb[i].base;
  62. b->length = m->wb[i].len;
  63. b->hw_rev = m->hw_rev;
  64. b->log_mask = SDE_DBG_MASK_WB;
  65. return &m->wb[i];
  66. }
  67. }
  68. return ERR_PTR(-EINVAL);
  69. }
  70. static void _sde_hw_cwb_ctrl_init(struct sde_mdss_cfg *m,
  71. void __iomem *addr, struct sde_hw_blk_reg_map *b)
  72. {
  73. int i;
  74. u32 blk_off;
  75. char name[64] = {0};
  76. if (!b)
  77. return;
  78. b->base_off = addr;
  79. b->blk_off = m->cwb_blk_off[0];
  80. b->length = 0x20;
  81. b->hw_rev = m->hw_rev;
  82. b->log_mask = SDE_DBG_MASK_WB;
  83. for (i = 0; i < m->pingpong_count; i++) {
  84. snprintf(name, sizeof(name), "cwb%d", i);
  85. blk_off = b->blk_off + (m->cwb_blk_stride * i);
  86. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, name,
  87. blk_off, blk_off + b->length, 0xff);
  88. }
  89. }
  90. static void _sde_hw_dcwb_ctrl_init(struct sde_mdss_cfg *m,
  91. void __iomem *addr, struct sde_hw_wb *hw_wb)
  92. {
  93. int i, j, dcwb_count, blk_count;
  94. u32 blk_off;
  95. char name[64] = {0};
  96. if (!hw_wb || !m->dcwb_count)
  97. return;
  98. dcwb_count = (m->dcwb_count < MAX_CWB_BLOCKSIZE) ? m->dcwb_count :
  99. (m->dcwb_count / MAX_CWB_BLOCKSIZE);
  100. if (dcwb_count == m->dcwb_count)
  101. blk_count = m->dcwb_count;
  102. else
  103. blk_count = MAX_CWB_BLOCKSIZE;
  104. for (j = 0; j < dcwb_count; j++) {
  105. hw_wb->dcwb_hw[j].base_off = addr;
  106. hw_wb->dcwb_hw[j].blk_off = m->cwb_blk_off[j];
  107. hw_wb->dcwb_hw[j].length = 0x20;
  108. hw_wb->dcwb_hw[j].hw_rev = m->hw_rev;
  109. hw_wb->dcwb_hw[j].log_mask = SDE_DBG_MASK_WB;
  110. for (i = 0; i < blk_count; i++) {
  111. snprintf(name, sizeof(name), "dcwb%d", i);
  112. blk_off = hw_wb->dcwb_hw[j].blk_off + (m->cwb_blk_stride * i);
  113. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, name,
  114. blk_off, blk_off + hw_wb->dcwb_hw[j].length, 0xff);
  115. }
  116. }
  117. }
  118. static void _sde_hw_dcwb_pp_ctrl_init(struct sde_mdss_cfg *m,
  119. void __iomem *addr, struct sde_hw_wb *hw_wb)
  120. {
  121. int i = 0, dcwb_pp_count = 0;
  122. struct sde_pingpong_cfg *pp_blk = NULL;
  123. if (!hw_wb) {
  124. DRM_ERROR("hw_wb is null\n");
  125. return;
  126. }
  127. for (i = 0; i < m->pingpong_count; i++) {
  128. pp_blk = &m->pingpong[i];
  129. if (test_bit(SDE_PINGPONG_CWB_DITHER, &pp_blk->features)) {
  130. if (dcwb_pp_count < DCWB_MAX - DCWB_0) {
  131. hw_wb->dcwb_pp_hw[dcwb_pp_count].caps = pp_blk;
  132. hw_wb->dcwb_pp_hw[dcwb_pp_count].idx = pp_blk->id;
  133. hw_wb->dcwb_pp_hw[dcwb_pp_count].hw.base_off = addr;
  134. hw_wb->dcwb_pp_hw[dcwb_pp_count].hw.blk_off = pp_blk->base;
  135. hw_wb->dcwb_pp_hw[dcwb_pp_count].hw.length = pp_blk->len;
  136. hw_wb->dcwb_pp_hw[dcwb_pp_count].hw.hw_rev = m->hw_rev;
  137. hw_wb->dcwb_pp_hw[dcwb_pp_count].hw.log_mask = SDE_DBG_MASK_WB;
  138. } else {
  139. DRM_ERROR("Invalid dcwb pp count %d more than %d",
  140. dcwb_pp_count, DCWB_MAX - DCWB_0);
  141. return;
  142. }
  143. ++dcwb_pp_count;
  144. }
  145. }
  146. }
  147. static void sde_hw_wb_setup_outaddress(struct sde_hw_wb *ctx,
  148. struct sde_hw_wb_cfg *data)
  149. {
  150. struct sde_hw_blk_reg_map *c = &ctx->hw;
  151. SDE_REG_WRITE(c, WB_DST0_ADDR, data->dest.plane_addr[0]);
  152. SDE_REG_WRITE(c, WB_DST1_ADDR, data->dest.plane_addr[1]);
  153. SDE_REG_WRITE(c, WB_DST2_ADDR, data->dest.plane_addr[2]);
  154. SDE_REG_WRITE(c, WB_DST3_ADDR, data->dest.plane_addr[3]);
  155. }
  156. static void sde_hw_wb_setup_format(struct sde_hw_wb *ctx,
  157. struct sde_hw_wb_cfg *data)
  158. {
  159. struct sde_hw_blk_reg_map *c = &ctx->hw;
  160. const struct sde_format *fmt = data->dest.format;
  161. u32 dst_format, pattern, ystride0, ystride1, outsize, chroma_samp;
  162. u32 write_config = 0;
  163. u32 opmode = 0;
  164. u32 dst_addr_sw = 0;
  165. chroma_samp = fmt->chroma_sample;
  166. dst_format = (chroma_samp << 23) |
  167. (fmt->fetch_planes << 19) |
  168. (fmt->bits[C3_ALPHA] << 6) |
  169. (fmt->bits[C2_R_Cr] << 4) |
  170. (fmt->bits[C1_B_Cb] << 2) |
  171. (fmt->bits[C0_G_Y] << 0);
  172. if (fmt->bits[C3_ALPHA] || fmt->alpha_enable) {
  173. dst_format |= BIT(8); /* DSTC3_EN */
  174. if (!fmt->alpha_enable ||
  175. !(ctx->caps->features & BIT(SDE_WB_PIPE_ALPHA)))
  176. dst_format |= BIT(14); /* DST_ALPHA_X */
  177. }
  178. if (SDE_FORMAT_IS_YUV(fmt))
  179. dst_format |= BIT(15);
  180. if (SDE_FORMAT_IS_DX(fmt))
  181. dst_format |= BIT(21);
  182. /* Set A5x tile bit for uncompressed tile formats also */
  183. if (SDE_FORMAT_IS_TILE(fmt))
  184. dst_format |= BIT(31);
  185. if (data->rotate_90)
  186. dst_format |= BIT(11);
  187. pattern = (fmt->element[3] << 24) |
  188. (fmt->element[2] << 16) |
  189. (fmt->element[1] << 8) |
  190. (fmt->element[0] << 0);
  191. dst_format |= (fmt->unpack_align_msb << 18) |
  192. (fmt->unpack_tight << 17) |
  193. ((fmt->unpack_count - 1) << 12) |
  194. ((fmt->bpp - 1) << 9);
  195. ystride0 = data->dest.plane_pitch[0] |
  196. (data->dest.plane_pitch[1] << 16);
  197. ystride1 = data->dest.plane_pitch[2] |
  198. (data->dest.plane_pitch[3] << 16);
  199. if (data->roi.h && data->roi.w)
  200. outsize = (data->roi.h << 16) | data->roi.w;
  201. else
  202. outsize = (data->dest.height << 16) | data->dest.width;
  203. if (SDE_FORMAT_IS_UBWC(fmt)) {
  204. opmode |= BIT(0);
  205. dst_format |= BIT(31);
  206. write_config |= (ctx->mdp->highest_bank_bit << 8);
  207. if (fmt->base.pixel_format == DRM_FORMAT_RGB565)
  208. write_config |= 0x8;
  209. if (IS_UBWC_20_SUPPORTED(ctx->catalog->ubwc_rev))
  210. SDE_REG_WRITE(c, WB_UBWC_STATIC_CTRL,
  211. (ctx->mdp->ubwc_swizzle << 0) |
  212. (ctx->mdp->highest_bank_bit << 4));
  213. if (IS_UBWC_10_SUPPORTED(ctx->catalog->ubwc_rev))
  214. SDE_REG_WRITE(c, WB_UBWC_STATIC_CTRL,
  215. (ctx->mdp->ubwc_swizzle << 0) |
  216. BIT(8) |
  217. (ctx->mdp->highest_bank_bit << 4));
  218. }
  219. if (data->is_secure)
  220. dst_addr_sw |= BIT(0);
  221. SDE_REG_WRITE(c, WB_ALPHA_X_VALUE, 0xFF);
  222. SDE_REG_WRITE(c, WB_DST_FORMAT, dst_format);
  223. SDE_REG_WRITE(c, WB_DST_OP_MODE, opmode);
  224. SDE_REG_WRITE(c, WB_DST_PACK_PATTERN, pattern);
  225. SDE_REG_WRITE(c, WB_DST_YSTRIDE0, ystride0);
  226. SDE_REG_WRITE(c, WB_DST_YSTRIDE1, ystride1);
  227. SDE_REG_WRITE(c, WB_OUT_SIZE, outsize);
  228. SDE_REG_WRITE(c, WB_DST_WRITE_CONFIG, write_config);
  229. SDE_REG_WRITE(c, WB_DST_ADDR_SW_STATUS, dst_addr_sw);
  230. }
  231. static void sde_hw_wb_roi(struct sde_hw_wb *ctx, struct sde_hw_wb_cfg *wb)
  232. {
  233. struct sde_hw_blk_reg_map *c = &ctx->hw;
  234. u32 image_size, out_size, out_xy;
  235. image_size = (wb->dest.height << 16) | wb->dest.width;
  236. out_xy = (wb->roi.y << 16) | wb->roi.x;
  237. out_size = (wb->roi.h << 16) | wb->roi.w;
  238. SDE_REG_WRITE(c, WB_OUT_IMAGE_SIZE, image_size);
  239. SDE_REG_WRITE(c, WB_OUT_XY, out_xy);
  240. SDE_REG_WRITE(c, WB_OUT_SIZE, out_size);
  241. }
  242. static void sde_hw_wb_crop(struct sde_hw_wb *ctx, struct sde_hw_wb_cfg *wb, bool crop)
  243. {
  244. struct sde_hw_blk_reg_map *c = &ctx->hw;
  245. u32 crop_xy;
  246. crop_xy = (wb->crop.y << 16) | wb->crop.x;
  247. if (crop) {
  248. SDE_REG_WRITE(c, WB_CROP_CTRL, 0x1);
  249. SDE_REG_WRITE(c, WB_CROP_OFFSET, crop_xy);
  250. } else {
  251. SDE_REG_WRITE(c, WB_CROP_CTRL, 0x0);
  252. }
  253. }
  254. static void sde_hw_wb_setup_qos_lut(struct sde_hw_wb *ctx,
  255. struct sde_hw_wb_qos_cfg *cfg)
  256. {
  257. struct sde_hw_blk_reg_map *c = &ctx->hw;
  258. u32 qos_ctrl = 0;
  259. if (!ctx || !cfg)
  260. return;
  261. SDE_REG_WRITE(c, WB_DANGER_LUT, cfg->danger_lut);
  262. SDE_REG_WRITE(c, WB_SAFE_LUT, cfg->safe_lut);
  263. if (ctx->caps && test_bit(SDE_WB_QOS_8LVL, &ctx->caps->features)) {
  264. SDE_REG_WRITE(c, WB_CREQ_LUT_0, cfg->creq_lut);
  265. SDE_REG_WRITE(c, WB_CREQ_LUT_1, cfg->creq_lut >> 32);
  266. }
  267. if (cfg->danger_safe_en)
  268. qos_ctrl |= WB_QOS_CTRL_DANGER_SAFE_EN;
  269. if (test_bit(SDE_WB_LINEAR_ROTATION, &ctx->caps->features)) {
  270. SDE_REG_WRITE(c, WB_TS_WR_CLIENT, cfg->bytes_per_clk & 0xFF);
  271. qos_ctrl |= (cfg->qos_mode << 1);
  272. }
  273. SDE_REG_WRITE(c, WB_QOS_CTRL, qos_ctrl);
  274. }
  275. static void sde_hw_wb_setup_cdp(struct sde_hw_wb *ctx,
  276. struct sde_hw_wb_cdp_cfg *cfg)
  277. {
  278. struct sde_hw_blk_reg_map *c;
  279. u32 cdp_cntl = 0;
  280. if (!ctx || !cfg)
  281. return;
  282. c = &ctx->hw;
  283. if (cfg->enable)
  284. cdp_cntl |= BIT(0);
  285. if (cfg->ubwc_meta_enable)
  286. cdp_cntl |= BIT(1);
  287. if (cfg->preload_ahead == SDE_WB_CDP_PRELOAD_AHEAD_64)
  288. cdp_cntl |= BIT(3);
  289. SDE_REG_WRITE(c, WB_CDP_CNTL, cdp_cntl);
  290. }
  291. static void sde_hw_wb_bind_pingpong_blk(
  292. struct sde_hw_wb *ctx,
  293. bool enable,
  294. const enum sde_pingpong pp)
  295. {
  296. struct sde_hw_blk_reg_map *c;
  297. int mux_cfg = 0xF;
  298. if (!ctx)
  299. return;
  300. c = &ctx->hw;
  301. if (enable)
  302. mux_cfg = (pp - PINGPONG_0) & 0x7;
  303. SDE_REG_WRITE(c, WB_MUX, mux_cfg);
  304. }
  305. static void sde_hw_wb_bind_dcwb_pp_blk(
  306. struct sde_hw_wb *ctx,
  307. bool enable,
  308. const enum sde_pingpong pp)
  309. {
  310. struct sde_hw_blk_reg_map *c;
  311. int mux_cfg = 0xF;
  312. if (!ctx)
  313. return;
  314. c = &ctx->hw;
  315. if (enable)
  316. mux_cfg = (pp < PINGPONG_CWB_2) ? 0xd : 0xb;
  317. SDE_REG_WRITE(c, WB_MUX, mux_cfg);
  318. }
  319. static void sde_hw_wb_program_dcwb_ctrl(struct sde_hw_wb *ctx,
  320. const enum sde_dcwb cur_idx, const enum sde_cwb data_src,
  321. int tap_location, bool enable)
  322. {
  323. struct sde_hw_blk_reg_map *c;
  324. u32 blk_base;
  325. int idx;
  326. if (!ctx)
  327. return;
  328. idx = (cur_idx < DCWB_2) ? 0 : 1;
  329. c = &ctx->dcwb_hw[idx];
  330. blk_base = ctx->catalog->cwb_blk_stride * ((cur_idx - DCWB_0) % MAX_CWB_BLOCKSIZE);
  331. if (enable) {
  332. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, data_src - CWB_0);
  333. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, tap_location);
  334. } else {
  335. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, 0xf);
  336. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, 0x0);
  337. }
  338. }
  339. static void sde_hw_wb_program_cwb_ctrl(struct sde_hw_wb *ctx,
  340. const enum sde_cwb cur_idx, const enum sde_cwb data_src,
  341. bool dspp_out, bool enable)
  342. {
  343. struct sde_hw_blk_reg_map *c;
  344. u32 blk_base;
  345. if (!ctx)
  346. return;
  347. c = &ctx->cwb_hw;
  348. blk_base = ctx->catalog->cwb_blk_stride * (cur_idx - CWB_0);
  349. if (enable) {
  350. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, data_src - CWB_0);
  351. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, dspp_out);
  352. } else {
  353. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, 0xf);
  354. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, 0x0);
  355. }
  356. }
  357. static void sde_hw_wb_setup_sys_cache(struct sde_hw_wb *ctx, struct sde_hw_wb_sc_cfg *cfg)
  358. {
  359. u32 val = 0;
  360. if (!ctx || !cfg)
  361. return;
  362. if (cfg->flags & SYS_CACHE_EN_FLAG)
  363. val |= (cfg->wr_en ? BIT(15) : 0);
  364. if (cfg->flags & SYS_CACHE_SCID)
  365. val |= ((cfg->wr_scid & 0x1f) << 8);
  366. if (cfg->flags & SYS_CACHE_OP_TYPE)
  367. val |= ((cfg->wr_op_type & 0xf) << 0);
  368. if (cfg->flags & SYS_CACHE_NO_ALLOC)
  369. val |= ((cfg->wr_noallocate & 0x1) << 4);
  370. SDE_REG_WRITE(&ctx->hw, WB_SYS_CACHE_MODE, val);
  371. }
  372. static void sde_hw_wb_program_cwb_dither_ctrl(struct sde_hw_wb *ctx,
  373. const enum sde_dcwb dcwb_idx, void *cfg, size_t len, bool enable)
  374. {
  375. struct sde_hw_pingpong *pp = NULL;
  376. struct sde_hw_blk_reg_map *c = NULL;
  377. struct drm_msm_dither *dither_data = NULL;
  378. enum sde_pingpong pp_id = PINGPONG_MAX;
  379. u32 dither_base = 0, offset = 0, data = 0, idx = 0;
  380. bool found = false;
  381. if (!ctx) {
  382. DRM_ERROR("Invalid pointer ctx is null\n");
  383. return;
  384. }
  385. if (dcwb_idx >= DCWB_MAX) {
  386. DRM_ERROR("Invalid dcwb_idx %d\n", dcwb_idx);
  387. return;
  388. }
  389. /* find pp blk with pp_id */
  390. for (idx = 0; idx < DCWB_MAX - DCWB_0; ++idx) {
  391. pp = &ctx->dcwb_pp_hw[idx];
  392. if (pp && dcwb_idx == idx + 1) {
  393. pp_id = pp->idx;
  394. found = true;
  395. break;
  396. }
  397. }
  398. if (!found) {
  399. DRM_ERROR("Not found pp id %d\n", pp_id);
  400. return;
  401. }
  402. if (!test_bit(SDE_PINGPONG_CWB_DITHER, &pp->caps->features)) {
  403. DRM_ERROR("Invalid ping-pong cwb config dcwb idx %d pp id %d\n",
  404. dcwb_idx, pp_id);
  405. return;
  406. }
  407. c = &pp->hw;
  408. dither_base = pp->caps->sblk->dither.base;
  409. dither_data = (struct drm_msm_dither *)cfg;
  410. if (!dither_data || !enable) {
  411. SDE_REG_WRITE(c, dither_base, 0);
  412. SDE_DEBUG("cwb dither disabled, dcwb_idx %u pp_id %u\n", dcwb_idx, pp_id);
  413. return;
  414. }
  415. if (len != sizeof(struct drm_msm_dither)) {
  416. SDE_ERROR("input len %zu, expected len %zu\n", len,
  417. sizeof(struct drm_msm_dither));
  418. return;
  419. }
  420. if (dither_data->c0_bitdepth >= DITHER_DEPTH_MAP_INDEX ||
  421. dither_data->c1_bitdepth >= DITHER_DEPTH_MAP_INDEX ||
  422. dither_data->c2_bitdepth >= DITHER_DEPTH_MAP_INDEX ||
  423. dither_data->c3_bitdepth >= DITHER_DEPTH_MAP_INDEX) {
  424. SDE_ERROR("Invalid bitdepth [c0, c1, c2, c3] = [%u, %u, %u, %u]\n",
  425. dither_data->c0_bitdepth, dither_data->c1_bitdepth,
  426. dither_data->c2_bitdepth, dither_data->c3_bitdepth);
  427. return;
  428. }
  429. offset += 4;
  430. data = dither_depth_map[dither_data->c0_bitdepth] & REG_MASK(2);
  431. data |= (dither_depth_map[dither_data->c1_bitdepth] & REG_MASK(2)) << 2;
  432. data |= (dither_depth_map[dither_data->c2_bitdepth] & REG_MASK(2)) << 4;
  433. data |= (dither_depth_map[dither_data->c3_bitdepth] & REG_MASK(2)) << 6;
  434. data |= (dither_data->temporal_en) ? (1 << 8) : 0;
  435. SDE_REG_WRITE(c, dither_base + offset, data);
  436. for (idx = 0; idx < DITHER_MATRIX_SZ - 3; idx += 4) {
  437. offset += 4;
  438. data = (dither_data->matrix[idx] & REG_MASK(4)) |
  439. ((dither_data->matrix[idx + 1] & REG_MASK(4)) << 4) |
  440. ((dither_data->matrix[idx + 2] & REG_MASK(4)) << 8) |
  441. ((dither_data->matrix[idx + 3] & REG_MASK(4)) << 12);
  442. SDE_REG_WRITE(c, dither_base + offset, data);
  443. }
  444. /* Enable dither */
  445. if (test_bit(SDE_PINGPONG_DITHER_LUMA, &pp->caps->features)
  446. && (dither_data->flags & DITHER_LUMA_MODE))
  447. SDE_REG_WRITE(c, dither_base, 0x11);
  448. else
  449. SDE_REG_WRITE(c, dither_base, 1);
  450. SDE_DEBUG("cwb dither enabled, dcwb_idx %u pp_id %u\n", dcwb_idx, pp_id);
  451. }
  452. static bool sde_hw_wb_setup_clk_force_ctrl(struct sde_hw_blk_reg_map *hw,
  453. enum sde_clk_ctrl_type clk_ctrl, bool enable)
  454. {
  455. u32 reg_val, new_val;
  456. if (!hw)
  457. return false;
  458. if (!SDE_CLK_CTRL_WB_VALID(clk_ctrl))
  459. return false;
  460. reg_val = SDE_REG_READ(hw, WB_CLK_CTRL);
  461. if (enable)
  462. new_val = reg_val | BIT(0);
  463. else
  464. new_val = reg_val & ~BIT(0);
  465. SDE_REG_WRITE(hw, WB_CLK_CTRL, new_val);
  466. wmb(); /* ensure write finished before progressing */
  467. return !(reg_val & BIT(0));
  468. }
  469. static int sde_hw_wb_get_clk_ctrl_status(struct sde_hw_blk_reg_map *hw,
  470. enum sde_clk_ctrl_type clk_ctrl, bool *status)
  471. {
  472. if (!hw)
  473. return -EINVAL;
  474. if (!SDE_CLK_CTRL_WB_VALID(clk_ctrl))
  475. return -EINVAL;
  476. *status = SDE_REG_READ(hw, WB_CLK_STATUS) & BIT(0);
  477. return 0;
  478. }
  479. static u32 sde_hw_wb_get_line_count(struct sde_hw_wb *ctx)
  480. {
  481. struct sde_hw_blk_reg_map *c;
  482. c = &ctx->hw;
  483. return SDE_REG_READ(c, WB_LINE_COUNT) & 0xFFFF;
  484. }
  485. static void sde_hw_wb_set_prog_line_count(struct sde_hw_wb *ctx, u32 val)
  486. {
  487. struct sde_hw_blk_reg_map *c;
  488. c = &ctx->hw;
  489. SDE_REG_WRITE(c, WB_PROG_LINE_COUNT, val);
  490. }
  491. static u32 sde_hw_wb_get_ubwc_error(struct sde_hw_wb *ctx)
  492. {
  493. struct sde_hw_blk_reg_map *c;
  494. c = &ctx->hw;
  495. return SDE_REG_READ(c, WB_UBWC_ERROR_STATUS) & 0xFF;
  496. }
  497. static void sde_hw_wb_clear_ubwc_error(struct sde_hw_wb *ctx)
  498. {
  499. struct sde_hw_blk_reg_map *c;
  500. c = &ctx->hw;
  501. return SDE_REG_WRITE(c, WB_UBWC_ERROR_STATUS, BIT(31));
  502. }
  503. static void _setup_wb_ops(struct sde_hw_wb_ops *ops,
  504. unsigned long features)
  505. {
  506. ops->setup_outaddress = sde_hw_wb_setup_outaddress;
  507. ops->setup_outformat = sde_hw_wb_setup_format;
  508. ops->setup_qos_lut = sde_hw_wb_setup_qos_lut;
  509. ops->setup_roi = sde_hw_wb_roi;
  510. ops->get_ubwc_error = sde_hw_wb_get_ubwc_error;
  511. ops->clear_ubwc_error = sde_hw_wb_clear_ubwc_error;
  512. if (test_bit(SDE_WB_CROP, &features))
  513. ops->setup_crop = sde_hw_wb_crop;
  514. if (test_bit(SDE_WB_CDP, &features))
  515. ops->setup_cdp = sde_hw_wb_setup_cdp;
  516. if (test_bit(SDE_WB_INPUT_CTRL, &features))
  517. ops->bind_pingpong_blk = sde_hw_wb_bind_pingpong_blk;
  518. if (test_bit(SDE_WB_CWB_CTRL, &features))
  519. ops->program_cwb_ctrl = sde_hw_wb_program_cwb_ctrl;
  520. if (test_bit(SDE_WB_DCWB_CTRL, &features)) {
  521. ops->program_dcwb_ctrl = sde_hw_wb_program_dcwb_ctrl;
  522. ops->bind_dcwb_pp_blk = sde_hw_wb_bind_dcwb_pp_blk;
  523. }
  524. if (test_bit(SDE_WB_SYS_CACHE, &features))
  525. ops->setup_sys_cache = sde_hw_wb_setup_sys_cache;
  526. if (test_bit(SDE_WB_CWB_DITHER_CTRL, &features))
  527. ops->program_cwb_dither_ctrl = sde_hw_wb_program_cwb_dither_ctrl;
  528. if (test_bit(SDE_WB_PROG_LINE, &features)) {
  529. ops->get_line_count = sde_hw_wb_get_line_count;
  530. ops->set_prog_line_count = sde_hw_wb_set_prog_line_count;
  531. }
  532. }
  533. struct sde_hw_blk_reg_map *sde_hw_wb_init(enum sde_wb idx,
  534. void __iomem *addr,
  535. struct sde_mdss_cfg *m,
  536. struct sde_hw_mdp *hw_mdp,
  537. struct sde_vbif_clk_client *clk_client)
  538. {
  539. struct sde_hw_wb *c;
  540. struct sde_wb_cfg *cfg;
  541. if (!addr || !m || !hw_mdp)
  542. return ERR_PTR(-EINVAL);
  543. c = kzalloc(sizeof(*c), GFP_KERNEL);
  544. if (!c)
  545. return ERR_PTR(-ENOMEM);
  546. cfg = _wb_offset(idx, m, addr, &c->hw);
  547. if (IS_ERR(cfg)) {
  548. WARN(1, "Unable to find wb idx=%d\n", idx);
  549. kfree(c);
  550. return ERR_PTR(-EINVAL);
  551. }
  552. /* Assign ops */
  553. c->catalog = m;
  554. c->mdp = &m->mdp[0];
  555. c->idx = idx;
  556. c->caps = cfg;
  557. _setup_wb_ops(&c->ops, c->caps->features);
  558. c->hw_mdp = hw_mdp;
  559. if (test_bit(SDE_FEATURE_VBIF_CLK_SPLIT, m->features)) {
  560. if (SDE_CLK_CTRL_WB_VALID(cfg->clk_ctrl)) {
  561. clk_client->hw = &c->hw;
  562. clk_client->clk_ctrl = cfg->clk_ctrl;
  563. clk_client->ops.get_clk_ctrl_status = sde_hw_wb_get_clk_ctrl_status;
  564. clk_client->ops.setup_clk_force_ctrl = sde_hw_wb_setup_clk_force_ctrl;
  565. } else {
  566. SDE_ERROR("invalid wb clk ctrl type %d\n", cfg->clk_ctrl);
  567. }
  568. }
  569. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  570. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  571. if (test_bit(SDE_WB_CWB_CTRL, &cfg->features))
  572. _sde_hw_cwb_ctrl_init(m, addr, &c->cwb_hw);
  573. if (test_bit(SDE_WB_DCWB_CTRL, &cfg->features)) {
  574. _sde_hw_dcwb_ctrl_init(m, addr, c);
  575. _sde_hw_dcwb_pp_ctrl_init(m, addr, c);
  576. }
  577. return &c->hw;
  578. }
  579. void sde_hw_wb_destroy(struct sde_hw_blk_reg_map *hw)
  580. {
  581. if (hw)
  582. kfree(to_sde_hw_wb(hw));
  583. }