sde_hw_wb.c 17 KB

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