sde_hw_wb.c 18 KB

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