sde_hw_wb.c 17 KB

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