sde_hw_wb.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include "sde_hw_mdss.h"
  6. #include "sde_hwio.h"
  7. #include "sde_hw_catalog.h"
  8. #include "sde_hw_wb.h"
  9. #include "sde_formats.h"
  10. #include "sde_dbg.h"
  11. #include "sde_kms.h"
  12. #define WB_DST_FORMAT 0x000
  13. #define WB_DST_OP_MODE 0x004
  14. #define WB_DST_PACK_PATTERN 0x008
  15. #define WB_DST0_ADDR 0x00C
  16. #define WB_DST1_ADDR 0x010
  17. #define WB_DST2_ADDR 0x014
  18. #define WB_DST3_ADDR 0x018
  19. #define WB_DST_YSTRIDE0 0x01C
  20. #define WB_DST_YSTRIDE1 0x020
  21. #define WB_DST_YSTRIDE1 0x020
  22. #define WB_DST_DITHER_BITDEPTH 0x024
  23. #define WB_DST_MATRIX_ROW0 0x030
  24. #define WB_DST_MATRIX_ROW1 0x034
  25. #define WB_DST_MATRIX_ROW2 0x038
  26. #define WB_DST_MATRIX_ROW3 0x03C
  27. #define WB_DST_WRITE_CONFIG 0x048
  28. #define WB_ROTATION_DNSCALER 0x050
  29. #define WB_ROTATOR_PIPE_DOWNSCALER 0x054
  30. #define WB_N16_INIT_PHASE_X_C03 0x060
  31. #define WB_N16_INIT_PHASE_X_C12 0x064
  32. #define WB_N16_INIT_PHASE_Y_C03 0x068
  33. #define WB_N16_INIT_PHASE_Y_C12 0x06C
  34. #define WB_OUT_SIZE 0x074
  35. #define WB_ALPHA_X_VALUE 0x078
  36. #define WB_DANGER_LUT 0x084
  37. #define WB_SAFE_LUT 0x088
  38. #define WB_QOS_CTRL 0x090
  39. #define WB_CREQ_LUT_0 0x098
  40. #define WB_CREQ_LUT_1 0x09C
  41. #define WB_UBWC_STATIC_CTRL 0x144
  42. #define WB_MUX 0x150
  43. #define WB_CROP_CTRL 0x154
  44. #define WB_CROP_OFFSET 0x158
  45. #define WB_CSC_BASE 0x260
  46. #define WB_DST_ADDR_SW_STATUS 0x2B0
  47. #define WB_CDP_CNTL 0x2B4
  48. #define WB_OUT_IMAGE_SIZE 0x2C0
  49. #define WB_OUT_XY 0x2C4
  50. #define CWB_CTRL_SRC_SEL 0x0
  51. #define CWB_CTRL_MODE 0x4
  52. /* WB_QOS_CTRL */
  53. #define WB_QOS_CTRL_DANGER_SAFE_EN BIT(0)
  54. static struct sde_wb_cfg *_wb_offset(enum sde_wb wb,
  55. struct sde_mdss_cfg *m,
  56. void __iomem *addr,
  57. struct sde_hw_blk_reg_map *b)
  58. {
  59. int i;
  60. for (i = 0; i < m->wb_count; i++) {
  61. if (wb == m->wb[i].id) {
  62. b->base_off = addr;
  63. b->blk_off = m->wb[i].base;
  64. b->length = m->wb[i].len;
  65. b->hwversion = m->hwversion;
  66. b->log_mask = SDE_DBG_MASK_WB;
  67. return &m->wb[i];
  68. }
  69. }
  70. return ERR_PTR(-EINVAL);
  71. }
  72. static void _sde_hw_cwb_ctrl_init(struct sde_mdss_cfg *m,
  73. void __iomem *addr, struct sde_hw_blk_reg_map *b)
  74. {
  75. int i;
  76. u32 blk_off;
  77. char name[64] = {0};
  78. if (!b)
  79. return;
  80. b->base_off = addr;
  81. b->blk_off = m->cwb_blk_off;
  82. b->length = 0x20;
  83. b->hwversion = m->hwversion;
  84. b->log_mask = SDE_DBG_MASK_WB;
  85. for (i = 0; i < m->pingpong_count; i++) {
  86. snprintf(name, sizeof(name), "cwb%d", i);
  87. blk_off = b->blk_off + (m->cwb_blk_stride * i);
  88. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, name,
  89. blk_off, blk_off + b->length, 0xff);
  90. }
  91. }
  92. static void _sde_hw_dcwb_ctrl_init(struct sde_mdss_cfg *m,
  93. void __iomem *addr, struct sde_hw_blk_reg_map *b)
  94. {
  95. int i;
  96. u32 blk_off;
  97. char name[64] = {0};
  98. if (!b)
  99. return;
  100. b->base_off = addr;
  101. b->blk_off = m->cwb_blk_off;
  102. b->length = 0x20;
  103. b->hwversion = m->hwversion;
  104. b->log_mask = SDE_DBG_MASK_WB;
  105. for (i = 0; i < m->dcwb_count; i++) {
  106. snprintf(name, sizeof(name), "dcwb%d", i);
  107. blk_off = b->blk_off + (m->cwb_blk_stride * i);
  108. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, name,
  109. blk_off, blk_off + b->length, 0xff);
  110. }
  111. }
  112. static void _sde_hw_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.hwversion = m->hwversion;
  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. (ctx->caps->features & BIT(SDE_WB_YUV_CONFIG)))
  174. dst_format |= BIT(15);
  175. if (SDE_FORMAT_IS_DX(fmt))
  176. dst_format |= BIT(21);
  177. pattern = (fmt->element[3] << 24) |
  178. (fmt->element[2] << 16) |
  179. (fmt->element[1] << 8) |
  180. (fmt->element[0] << 0);
  181. dst_format |= (fmt->unpack_align_msb << 18) |
  182. (fmt->unpack_tight << 17) |
  183. ((fmt->unpack_count - 1) << 12) |
  184. ((fmt->bpp - 1) << 9);
  185. ystride0 = data->dest.plane_pitch[0] |
  186. (data->dest.plane_pitch[1] << 16);
  187. ystride1 = data->dest.plane_pitch[2] |
  188. (data->dest.plane_pitch[3] << 16);
  189. if (data->roi.h && data->roi.w)
  190. outsize = (data->roi.h << 16) | data->roi.w;
  191. else
  192. outsize = (data->dest.height << 16) | data->dest.width;
  193. if (SDE_FORMAT_IS_UBWC(fmt)) {
  194. opmode |= BIT(0);
  195. dst_format |= BIT(31);
  196. write_config |= (ctx->mdp->highest_bank_bit << 8);
  197. if (fmt->base.pixel_format == DRM_FORMAT_RGB565)
  198. write_config |= 0x8;
  199. if (IS_UBWC_20_SUPPORTED(ctx->catalog->ubwc_version))
  200. SDE_REG_WRITE(c, WB_UBWC_STATIC_CTRL,
  201. (ctx->mdp->ubwc_swizzle << 0) |
  202. (ctx->mdp->highest_bank_bit << 4));
  203. if (IS_UBWC_10_SUPPORTED(ctx->catalog->ubwc_version))
  204. SDE_REG_WRITE(c, WB_UBWC_STATIC_CTRL,
  205. (ctx->mdp->ubwc_swizzle << 0) |
  206. BIT(8) |
  207. (ctx->mdp->highest_bank_bit << 4));
  208. }
  209. if (data->is_secure)
  210. dst_addr_sw |= BIT(0);
  211. SDE_REG_WRITE(c, WB_ALPHA_X_VALUE, 0xFF);
  212. SDE_REG_WRITE(c, WB_DST_FORMAT, dst_format);
  213. SDE_REG_WRITE(c, WB_DST_OP_MODE, opmode);
  214. SDE_REG_WRITE(c, WB_DST_PACK_PATTERN, pattern);
  215. SDE_REG_WRITE(c, WB_DST_YSTRIDE0, ystride0);
  216. SDE_REG_WRITE(c, WB_DST_YSTRIDE1, ystride1);
  217. SDE_REG_WRITE(c, WB_OUT_SIZE, outsize);
  218. SDE_REG_WRITE(c, WB_DST_WRITE_CONFIG, write_config);
  219. SDE_REG_WRITE(c, WB_DST_ADDR_SW_STATUS, dst_addr_sw);
  220. }
  221. static void sde_hw_wb_roi(struct sde_hw_wb *ctx, struct sde_hw_wb_cfg *wb)
  222. {
  223. struct sde_hw_blk_reg_map *c = &ctx->hw;
  224. u32 image_size, out_size, out_xy;
  225. image_size = (wb->dest.height << 16) | wb->dest.width;
  226. out_xy = (wb->roi.y << 16) | wb->roi.x;
  227. out_size = (wb->roi.h << 16) | wb->roi.w;
  228. SDE_REG_WRITE(c, WB_OUT_IMAGE_SIZE, image_size);
  229. SDE_REG_WRITE(c, WB_OUT_XY, out_xy);
  230. SDE_REG_WRITE(c, WB_OUT_SIZE, out_size);
  231. }
  232. static void sde_hw_wb_crop(struct sde_hw_wb *ctx, struct sde_hw_wb_cfg *wb, bool crop)
  233. {
  234. struct sde_hw_blk_reg_map *c = &ctx->hw;
  235. u32 crop_xy;
  236. crop_xy = (wb->crop.y << 16) | wb->crop.x;
  237. if (crop) {
  238. SDE_REG_WRITE(c, WB_CROP_CTRL, 0x1);
  239. SDE_REG_WRITE(c, WB_CROP_OFFSET, crop_xy);
  240. } else {
  241. SDE_REG_WRITE(c, WB_CROP_CTRL, 0x0);
  242. }
  243. }
  244. static void sde_hw_wb_setup_qos_lut(struct sde_hw_wb *ctx,
  245. struct sde_hw_wb_qos_cfg *cfg)
  246. {
  247. struct sde_hw_blk_reg_map *c = &ctx->hw;
  248. u32 qos_ctrl = 0;
  249. if (!ctx || !cfg)
  250. return;
  251. SDE_REG_WRITE(c, WB_DANGER_LUT, cfg->danger_lut);
  252. SDE_REG_WRITE(c, WB_SAFE_LUT, cfg->safe_lut);
  253. if (ctx->caps && test_bit(SDE_WB_QOS_8LVL, &ctx->caps->features)) {
  254. SDE_REG_WRITE(c, WB_CREQ_LUT_0, cfg->creq_lut);
  255. SDE_REG_WRITE(c, WB_CREQ_LUT_1, cfg->creq_lut >> 32);
  256. }
  257. if (cfg->danger_safe_en)
  258. qos_ctrl |= WB_QOS_CTRL_DANGER_SAFE_EN;
  259. SDE_REG_WRITE(c, WB_QOS_CTRL, qos_ctrl);
  260. }
  261. static void sde_hw_wb_setup_cdp(struct sde_hw_wb *ctx,
  262. struct sde_hw_wb_cdp_cfg *cfg)
  263. {
  264. struct sde_hw_blk_reg_map *c;
  265. u32 cdp_cntl = 0;
  266. if (!ctx || !cfg)
  267. return;
  268. c = &ctx->hw;
  269. if (cfg->enable)
  270. cdp_cntl |= BIT(0);
  271. if (cfg->ubwc_meta_enable)
  272. cdp_cntl |= BIT(1);
  273. if (cfg->preload_ahead == SDE_WB_CDP_PRELOAD_AHEAD_64)
  274. cdp_cntl |= BIT(3);
  275. SDE_REG_WRITE(c, WB_CDP_CNTL, cdp_cntl);
  276. }
  277. static void sde_hw_wb_bind_pingpong_blk(
  278. struct sde_hw_wb *ctx,
  279. bool enable,
  280. const enum sde_pingpong pp)
  281. {
  282. struct sde_hw_blk_reg_map *c;
  283. int mux_cfg = 0xF;
  284. if (!ctx)
  285. return;
  286. c = &ctx->hw;
  287. if (enable)
  288. mux_cfg = (pp - PINGPONG_0) & 0x7;
  289. SDE_REG_WRITE(c, WB_MUX, mux_cfg);
  290. }
  291. static void sde_hw_wb_bind_dcwb_pp_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 = 0xd;
  303. SDE_REG_WRITE(c, WB_MUX, mux_cfg);
  304. }
  305. static void sde_hw_wb_program_dcwb_ctrl(struct sde_hw_wb *ctx,
  306. const enum sde_dcwb cur_idx, const enum sde_cwb data_src,
  307. int tap_location, bool enable)
  308. {
  309. struct sde_hw_blk_reg_map *c;
  310. u32 blk_base;
  311. if (!ctx)
  312. return;
  313. c = &ctx->dcwb_hw;
  314. blk_base = ctx->catalog->cwb_blk_stride * (cur_idx - DCWB_0);
  315. if (enable) {
  316. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, data_src - CWB_0);
  317. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, tap_location);
  318. } else {
  319. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, 0xf);
  320. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, 0x0);
  321. }
  322. }
  323. static void sde_hw_wb_program_cwb_ctrl(struct sde_hw_wb *ctx,
  324. const enum sde_cwb cur_idx, const enum sde_cwb data_src,
  325. bool dspp_out, bool enable)
  326. {
  327. struct sde_hw_blk_reg_map *c;
  328. u32 blk_base;
  329. if (!ctx)
  330. return;
  331. c = &ctx->cwb_hw;
  332. blk_base = ctx->catalog->cwb_blk_stride * (cur_idx - CWB_0);
  333. if (enable) {
  334. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, data_src - CWB_0);
  335. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, dspp_out);
  336. } else {
  337. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, 0xf);
  338. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, 0x0);
  339. }
  340. }
  341. static void sde_hw_wb_program_cwb_dither_ctrl(struct sde_hw_wb *ctx,
  342. const enum sde_dcwb dcwb_idx, void *cfg, size_t len, bool enable)
  343. {
  344. struct sde_hw_pingpong *pp = NULL;
  345. struct sde_hw_blk_reg_map *c = NULL;
  346. struct drm_msm_dither *dither_data = NULL;
  347. enum sde_pingpong pp_id = PINGPONG_MAX;
  348. u32 dither_base = 0, offset = 0, data = 0, idx = 0;
  349. bool found = false;
  350. if (!ctx) {
  351. DRM_ERROR("Invalid pointer ctx is null\n");
  352. return;
  353. }
  354. /* map to pp_id from dcwb id */
  355. if (dcwb_idx == DCWB_0) {
  356. pp_id = PINGPONG_CWB_0;
  357. } else if (dcwb_idx == DCWB_1) {
  358. pp_id = PINGPONG_CWB_1;
  359. } else {
  360. DRM_ERROR("Invalid dcwb_idx %d\n", dcwb_idx);
  361. return;
  362. }
  363. /* find pp blk with pp_id */
  364. for (idx = 0; idx < DCWB_MAX - DCWB_0; ++idx) {
  365. pp = &ctx->dcwb_pp_hw[idx];
  366. if (pp && pp->idx == pp_id) {
  367. found = true;
  368. break;
  369. }
  370. }
  371. if (!found) {
  372. DRM_ERROR("Not found pp id %d\n", pp_id);
  373. return;
  374. }
  375. if (!test_bit(SDE_PINGPONG_CWB_DITHER, &pp->caps->features)) {
  376. DRM_ERROR("Invalid ping-pong cwb config dcwb idx %d pp id %d\n",
  377. dcwb_idx, pp_id);
  378. return;
  379. }
  380. c = &pp->hw;
  381. dither_base = pp->caps->sblk->dither.base;
  382. dither_data = (struct drm_msm_dither *)cfg;
  383. if (!dither_data || !enable) {
  384. SDE_REG_WRITE(c, dither_base, 0);
  385. SDE_DEBUG("cwb dither disabled, dcwb_idx %u pp_id %u\n", dcwb_idx, pp_id);
  386. return;
  387. }
  388. if (len != sizeof(struct drm_msm_dither)) {
  389. SDE_ERROR("input len %zu, expected len %zu\n", len,
  390. sizeof(struct drm_msm_dither));
  391. return;
  392. }
  393. if (dither_data->c0_bitdepth >= DITHER_DEPTH_MAP_INDEX ||
  394. dither_data->c1_bitdepth >= DITHER_DEPTH_MAP_INDEX ||
  395. dither_data->c2_bitdepth >= DITHER_DEPTH_MAP_INDEX ||
  396. dither_data->c3_bitdepth >= DITHER_DEPTH_MAP_INDEX) {
  397. SDE_ERROR("Invalid bitdepth [c0, c1, c2, c3] = [%u, %u, %u, %u]\n",
  398. dither_data->c0_bitdepth, dither_data->c1_bitdepth,
  399. dither_data->c2_bitdepth, dither_data->c3_bitdepth);
  400. return;
  401. }
  402. offset += 4;
  403. data = dither_depth_map[dither_data->c0_bitdepth] & REG_MASK(2);
  404. data |= (dither_depth_map[dither_data->c1_bitdepth] & REG_MASK(2)) << 2;
  405. data |= (dither_depth_map[dither_data->c2_bitdepth] & REG_MASK(2)) << 4;
  406. data |= (dither_depth_map[dither_data->c3_bitdepth] & REG_MASK(2)) << 6;
  407. data |= (dither_data->temporal_en) ? (1 << 8) : 0;
  408. SDE_REG_WRITE(c, dither_base + offset, data);
  409. for (idx = 0; idx < DITHER_MATRIX_SZ - 3; idx += 4) {
  410. offset += 4;
  411. data = (dither_data->matrix[idx] & REG_MASK(4)) |
  412. ((dither_data->matrix[idx + 1] & REG_MASK(4)) << 4) |
  413. ((dither_data->matrix[idx + 2] & REG_MASK(4)) << 8) |
  414. ((dither_data->matrix[idx + 3] & REG_MASK(4)) << 12);
  415. SDE_REG_WRITE(c, dither_base + offset, data);
  416. }
  417. /* Enable dither */
  418. if (test_bit(SDE_PINGPONG_DITHER_LUMA, &pp->caps->features)
  419. && (dither_data->flags & DITHER_LUMA_MODE))
  420. SDE_REG_WRITE(c, dither_base, 0x11);
  421. else
  422. SDE_REG_WRITE(c, dither_base, 1);
  423. SDE_DEBUG("cwb dither enabled, dcwb_idx %u pp_id %u\n", dcwb_idx, pp_id);
  424. }
  425. static void _setup_wb_ops(struct sde_hw_wb_ops *ops,
  426. unsigned long features)
  427. {
  428. ops->setup_outaddress = sde_hw_wb_setup_outaddress;
  429. ops->setup_outformat = sde_hw_wb_setup_format;
  430. if (test_bit(SDE_WB_XY_ROI_OFFSET, &features))
  431. ops->setup_roi = sde_hw_wb_roi;
  432. if (test_bit(SDE_WB_CROP, &features))
  433. ops->setup_crop = sde_hw_wb_crop;
  434. if (test_bit(SDE_WB_QOS, &features))
  435. ops->setup_qos_lut = sde_hw_wb_setup_qos_lut;
  436. if (test_bit(SDE_WB_CDP, &features))
  437. ops->setup_cdp = sde_hw_wb_setup_cdp;
  438. if (test_bit(SDE_WB_INPUT_CTRL, &features))
  439. ops->bind_pingpong_blk = sde_hw_wb_bind_pingpong_blk;
  440. if (test_bit(SDE_WB_CWB_CTRL, &features))
  441. ops->program_cwb_ctrl = sde_hw_wb_program_cwb_ctrl;
  442. if (test_bit(SDE_WB_DCWB_CTRL, &features)) {
  443. ops->program_dcwb_ctrl = sde_hw_wb_program_dcwb_ctrl;
  444. ops->bind_dcwb_pp_blk = sde_hw_wb_bind_dcwb_pp_blk;
  445. }
  446. if (test_bit(SDE_WB_CWB_DITHER_CTRL, &features))
  447. ops->program_cwb_dither_ctrl = sde_hw_wb_program_cwb_dither_ctrl;
  448. }
  449. static struct sde_hw_blk_ops sde_hw_ops = {
  450. .start = NULL,
  451. .stop = NULL,
  452. };
  453. struct sde_hw_wb *sde_hw_wb_init(enum sde_wb idx,
  454. void __iomem *addr,
  455. struct sde_mdss_cfg *m,
  456. struct sde_hw_mdp *hw_mdp)
  457. {
  458. struct sde_hw_wb *c;
  459. struct sde_wb_cfg *cfg;
  460. int rc;
  461. if (!addr || !m || !hw_mdp)
  462. return ERR_PTR(-EINVAL);
  463. c = kzalloc(sizeof(*c), GFP_KERNEL);
  464. if (!c)
  465. return ERR_PTR(-ENOMEM);
  466. cfg = _wb_offset(idx, m, addr, &c->hw);
  467. if (IS_ERR(cfg)) {
  468. WARN(1, "Unable to find wb idx=%d\n", idx);
  469. kfree(c);
  470. return ERR_PTR(-EINVAL);
  471. }
  472. /* Assign ops */
  473. c->catalog = m;
  474. c->mdp = &m->mdp[0];
  475. c->idx = idx;
  476. c->caps = cfg;
  477. _setup_wb_ops(&c->ops, c->caps->features);
  478. c->hw_mdp = hw_mdp;
  479. rc = sde_hw_blk_init(&c->base, SDE_HW_BLK_WB, idx, &sde_hw_ops);
  480. if (rc) {
  481. SDE_ERROR("failed to init hw blk %d\n", rc);
  482. goto blk_init_error;
  483. }
  484. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  485. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  486. if (test_bit(SDE_WB_CWB_CTRL, &cfg->features))
  487. _sde_hw_cwb_ctrl_init(m, addr, &c->cwb_hw);
  488. if (test_bit(SDE_WB_DCWB_CTRL, &cfg->features)) {
  489. _sde_hw_dcwb_ctrl_init(m, addr, &c->dcwb_hw);
  490. _sde_hw_dcwb_pp_ctrl_init(m, addr, c);
  491. }
  492. return c;
  493. blk_init_error:
  494. kfree(c);
  495. return ERR_PTR(rc);
  496. }
  497. void sde_hw_wb_destroy(struct sde_hw_wb *hw_wb)
  498. {
  499. if (hw_wb)
  500. sde_hw_blk_destroy(&hw_wb->base);
  501. kfree(hw_wb);
  502. }