blob: a5ea7af6ede2ed48a540372a4751d2111696ae8c [file] [log] [blame]
Alan Kwongbb27c092016-07-20 16:41:25 -04001/*
Lloyd Atkinson8772e202016-09-26 17:52:16 -04002 * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved.
Alan Kwongbb27c092016-07-20 16:41:25 -04003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
Alan Kwong4c3cf4c2016-09-25 20:08:09 -040015#define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
Alan Kwongbb27c092016-07-20 16:41:25 -040016
17#include <linux/jiffies.h>
18#include <linux/debugfs.h>
19
20#include "sde_encoder_phys.h"
21#include "sde_formats.h"
22#include "sde_hw_top.h"
23#include "sde_hw_interrupts.h"
Alan Kwongf5dd86c2016-08-09 18:08:17 -040024#include "sde_core_irq.h"
Alan Kwongbb27c092016-07-20 16:41:25 -040025#include "sde_wb.h"
Lloyd Atkinson8772e202016-09-26 17:52:16 -040026#include "sde_vbif.h"
Alan Kwongbb27c092016-07-20 16:41:25 -040027
28/* wait for at most 2 vsync for lowest refresh rate (24hz) */
29#define WAIT_TIMEOUT_MSEC 84
30
31#define to_sde_encoder_phys_wb(x) \
32 container_of(x, struct sde_encoder_phys_wb, base)
33
34#define DEV(phy_enc) (phy_enc->parent->dev)
35
36/**
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -040037 * sde_encoder_phys_wb_is_master - report wb always as master encoder
38 */
39static bool sde_encoder_phys_wb_is_master(struct sde_encoder_phys *phys_enc)
40{
41 return true;
42}
43
44/**
Alan Kwongbb27c092016-07-20 16:41:25 -040045 * sde_encoder_phys_wb_get_intr_type - get interrupt type based on block mode
46 * @hw_wb: Pointer to h/w writeback driver
47 */
48static enum sde_intr_type sde_encoder_phys_wb_get_intr_type(
49 struct sde_hw_wb *hw_wb)
50{
51 return (hw_wb->caps->features & BIT(SDE_WB_BLOCK_MODE)) ?
52 SDE_IRQ_TYPE_WB_ROT_COMP : SDE_IRQ_TYPE_WB_WFD_COMP;
53}
54
55/**
Alan Kwong5d324e42016-07-28 22:56:18 -040056 * sde_encoder_phys_wb_set_ot_limit - set OT limit for writeback interface
57 * @phys_enc: Pointer to physical encoder
58 */
59static void sde_encoder_phys_wb_set_ot_limit(
60 struct sde_encoder_phys *phys_enc)
61{
62 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
63 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
64 struct sde_vbif_set_ot_params ot_params;
65
66 memset(&ot_params, 0, sizeof(ot_params));
67 ot_params.xin_id = hw_wb->caps->xin_id;
68 ot_params.num = hw_wb->idx - WB_0;
69 ot_params.width = wb_enc->wb_roi.w;
70 ot_params.height = wb_enc->wb_roi.h;
71 ot_params.is_wfd = true;
72 ot_params.frame_rate = phys_enc->cached_mode.vrefresh;
73 ot_params.vbif_idx = hw_wb->caps->vbif_idx;
74 ot_params.clk_ctrl = hw_wb->caps->clk_ctrl;
75 ot_params.rd = false;
76
77 sde_vbif_set_ot_limit(phys_enc->sde_kms, &ot_params);
78}
79
80/**
Alan Kwongbb27c092016-07-20 16:41:25 -040081 * sde_encoder_phys_wb_set_traffic_shaper - set traffic shaper for writeback
82 * @phys_enc: Pointer to physical encoder
83 */
84static void sde_encoder_phys_wb_set_traffic_shaper(
85 struct sde_encoder_phys *phys_enc)
86{
87 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
88 struct sde_hw_wb_cfg *wb_cfg = &wb_enc->wb_cfg;
89
90 /* traffic shaper is only enabled for rotator */
91 wb_cfg->ts_cfg.en = false;
92}
93
94/**
95 * sde_encoder_phys_setup_cdm - setup chroma down block
96 * @phys_enc: Pointer to physical encoder
97 * @fb: Pointer to output framebuffer
98 * @format: Output format
99 */
100void sde_encoder_phys_setup_cdm(struct sde_encoder_phys *phys_enc,
101 struct drm_framebuffer *fb, const struct sde_format *format,
102 struct sde_rect *wb_roi)
103{
104 struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
105 struct sde_hw_cdm_cfg *cdm_cfg = &phys_enc->cdm_cfg;
106 int ret;
107
108 if (!SDE_FORMAT_IS_YUV(format)) {
109 SDE_DEBUG("[cdm_disable fmt:%x]\n",
110 format->base.pixel_format);
111
112 if (hw_cdm && hw_cdm->ops.disable)
113 hw_cdm->ops.disable(hw_cdm);
114
115 return;
116 }
117
118 memset(cdm_cfg, 0, sizeof(struct sde_hw_cdm_cfg));
119
120 cdm_cfg->output_width = wb_roi->w;
121 cdm_cfg->output_height = wb_roi->h;
122 cdm_cfg->output_fmt = format;
123 cdm_cfg->output_type = CDM_CDWN_OUTPUT_WB;
124 cdm_cfg->output_bit_depth = CDM_CDWN_OUTPUT_8BIT;
125
126 /* enable 10 bit logic */
127 switch (cdm_cfg->output_fmt->chroma_sample) {
128 case SDE_CHROMA_RGB:
129 cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
130 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
131 break;
132 case SDE_CHROMA_H2V1:
133 cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
134 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
135 break;
136 case SDE_CHROMA_420:
137 cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
138 cdm_cfg->v_cdwn_type = CDM_CDWN_OFFSITE;
139 break;
140 case SDE_CHROMA_H1V2:
141 default:
142 SDE_ERROR("unsupported chroma sampling type\n");
143 cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
144 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
145 break;
146 }
147
148 SDE_DEBUG("[cdm_enable:%d,%d,%X,%d,%d,%d,%d]\n",
149 cdm_cfg->output_width,
150 cdm_cfg->output_height,
151 cdm_cfg->output_fmt->base.pixel_format,
152 cdm_cfg->output_type,
153 cdm_cfg->output_bit_depth,
154 cdm_cfg->h_cdwn_type,
155 cdm_cfg->v_cdwn_type);
156
157 if (hw_cdm && hw_cdm->ops.setup_cdwn) {
158 ret = hw_cdm->ops.setup_cdwn(hw_cdm, cdm_cfg);
159 if (ret < 0) {
160 SDE_ERROR("failed to setup CDM %d\n", ret);
161 return;
162 }
163 }
164
165 if (hw_cdm && hw_cdm->ops.enable) {
166 ret = hw_cdm->ops.enable(hw_cdm, cdm_cfg);
167 if (ret < 0) {
168 SDE_ERROR("failed to enable CDM %d\n", ret);
169 return;
170 }
171 }
172}
173
174/**
175 * sde_encoder_phys_wb_setup_fb - setup output framebuffer
176 * @phys_enc: Pointer to physical encoder
177 * @fb: Pointer to output framebuffer
178 * @wb_roi: Pointer to output region of interest
179 */
180static void sde_encoder_phys_wb_setup_fb(struct sde_encoder_phys *phys_enc,
181 struct drm_framebuffer *fb, struct sde_rect *wb_roi)
182{
183 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400184 struct sde_hw_wb *hw_wb;
185 struct sde_hw_wb_cfg *wb_cfg;
Alan Kwongbb27c092016-07-20 16:41:25 -0400186 const struct msm_format *format;
187 int ret, mmu_id;
188
Clarence Ip03521982016-08-26 10:49:47 -0400189 if (!phys_enc) {
190 SDE_ERROR("invalid encoder\n");
191 return;
192 }
193
194 hw_wb = wb_enc->hw_wb;
195 wb_cfg = &wb_enc->wb_cfg;
Alan Kwongbb27c092016-07-20 16:41:25 -0400196 memset(wb_cfg, 0, sizeof(struct sde_hw_wb_cfg));
197
Clarence Ip03521982016-08-26 10:49:47 -0400198 wb_cfg->intf_mode = phys_enc->intf_mode;
Alan Kwongbb27c092016-07-20 16:41:25 -0400199 wb_cfg->is_secure = (fb->flags & DRM_MODE_FB_SECURE) ? true : false;
200 mmu_id = (wb_cfg->is_secure) ?
201 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] :
202 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE];
203
204 SDE_DEBUG("[fb_secure:%d]\n", wb_cfg->is_secure);
205
206 format = msm_framebuffer_format(fb);
Dhaval Patelccbcb3d2016-08-22 11:58:14 -0700207 if (!format) {
208 SDE_DEBUG("invalid format for fb\n");
209 return;
210 }
211
Alan Kwongbb27c092016-07-20 16:41:25 -0400212 wb_cfg->dest.format = sde_get_sde_format_ext(
213 format->pixel_format,
214 fb->modifier,
215 drm_format_num_planes(fb->pixel_format));
216 if (!wb_cfg->dest.format) {
217 /* this error should be detected during atomic_check */
218 SDE_ERROR("failed to get format %x\n", format->pixel_format);
219 return;
220 }
abeykunf1539f72016-08-24 16:08:03 -0400221 wb_cfg->roi = *wb_roi;
Alan Kwongbb27c092016-07-20 16:41:25 -0400222
abeykunf1539f72016-08-24 16:08:03 -0400223 if (hw_wb->caps->features & BIT(SDE_WB_XY_ROI_OFFSET)) {
224 ret = sde_format_populate_layout(mmu_id, fb, &wb_cfg->dest);
225 if (ret) {
226 SDE_DEBUG("failed to populate layout %d\n", ret);
227 return;
228 }
229 wb_cfg->dest.width = fb->width;
230 wb_cfg->dest.height = fb->height;
231 wb_cfg->dest.num_planes = wb_cfg->dest.format->num_planes;
232 } else {
233 ret = sde_format_populate_layout_with_roi(mmu_id, fb, wb_roi,
Alan Kwongbb27c092016-07-20 16:41:25 -0400234 &wb_cfg->dest);
abeykunf1539f72016-08-24 16:08:03 -0400235 if (ret) {
236 /* this error should be detected during atomic_check */
237 SDE_DEBUG("failed to populate layout %d\n", ret);
238 return;
239 }
Alan Kwongbb27c092016-07-20 16:41:25 -0400240 }
241
242 if ((wb_cfg->dest.format->fetch_planes == SDE_PLANE_PLANAR) &&
243 (wb_cfg->dest.format->element[0] == C1_B_Cb))
244 swap(wb_cfg->dest.plane_addr[1], wb_cfg->dest.plane_addr[2]);
245
246 SDE_DEBUG("[fb_offset:%8.8x,%8.8x,%8.8x,%8.8x]\n",
247 wb_cfg->dest.plane_addr[0],
248 wb_cfg->dest.plane_addr[1],
249 wb_cfg->dest.plane_addr[2],
250 wb_cfg->dest.plane_addr[3]);
251 SDE_DEBUG("[fb_stride:%8.8x,%8.8x,%8.8x,%8.8x]\n",
252 wb_cfg->dest.plane_pitch[0],
253 wb_cfg->dest.plane_pitch[1],
254 wb_cfg->dest.plane_pitch[2],
255 wb_cfg->dest.plane_pitch[3]);
256
abeykunf1539f72016-08-24 16:08:03 -0400257 if (hw_wb->ops.setup_roi)
258 hw_wb->ops.setup_roi(hw_wb, wb_cfg);
259
Alan Kwongbb27c092016-07-20 16:41:25 -0400260 if (hw_wb->ops.setup_outformat)
261 hw_wb->ops.setup_outformat(hw_wb, wb_cfg);
262
263 if (hw_wb->ops.setup_outaddress)
264 hw_wb->ops.setup_outaddress(hw_wb, wb_cfg);
265}
266
267/**
268 * sde_encoder_phys_wb_setup_cdp - setup chroma down prefetch block
269 * @phys_enc: Pointer to physical encoder
270 */
271static void sde_encoder_phys_wb_setup_cdp(struct sde_encoder_phys *phys_enc)
272{
273 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
274 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
275 struct sde_hw_intf_cfg *intf_cfg = &wb_enc->intf_cfg;
276
277 memset(intf_cfg, 0, sizeof(struct sde_hw_intf_cfg));
278
279 intf_cfg->intf = SDE_NONE;
280 intf_cfg->wb = hw_wb->idx;
Lloyd Atkinson55987b02016-08-16 16:57:46 -0400281 intf_cfg->mode_3d = sde_encoder_helper_get_3d_blend_mode(phys_enc);
Alan Kwongbb27c092016-07-20 16:41:25 -0400282
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400283 if (phys_enc->hw_ctl && phys_enc->hw_ctl->ops.setup_intf_cfg)
Alan Kwongbb27c092016-07-20 16:41:25 -0400284 phys_enc->hw_ctl->ops.setup_intf_cfg(phys_enc->hw_ctl,
285 intf_cfg);
286}
287
288/**
289 * sde_encoder_phys_wb_atomic_check - verify and fixup given atomic states
290 * @phys_enc: Pointer to physical encoder
291 * @crtc_state: Pointer to CRTC atomic state
292 * @conn_state: Pointer to connector atomic state
293 */
294static int sde_encoder_phys_wb_atomic_check(
295 struct sde_encoder_phys *phys_enc,
296 struct drm_crtc_state *crtc_state,
297 struct drm_connector_state *conn_state)
298{
299 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
300 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
301 const struct sde_wb_cfg *wb_cfg = hw_wb->caps;
302 struct drm_framebuffer *fb;
303 const struct sde_format *fmt;
304 struct sde_rect wb_roi;
305 const struct drm_display_mode *mode = &crtc_state->mode;
306 int rc;
307
308 SDE_DEBUG("[atomic_check:%d,%d,\"%s\",%d,%d]\n",
309 hw_wb->idx - WB_0, mode->base.id, mode->name,
310 mode->hdisplay, mode->vdisplay);
311
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400312 if (!conn_state || !conn_state->connector) {
313 SDE_ERROR("invalid connector state\n");
314 return -EINVAL;
315 } else if (conn_state->connector->status !=
316 connector_status_connected) {
317 SDE_ERROR("connector not connected %d\n",
318 conn_state->connector->status);
319 return -EINVAL;
320 }
321
Alan Kwongbb27c092016-07-20 16:41:25 -0400322 memset(&wb_roi, 0, sizeof(struct sde_rect));
323
324 rc = sde_wb_connector_state_get_output_roi(conn_state, &wb_roi);
325 if (rc) {
326 SDE_ERROR("failed to get roi %d\n", rc);
327 return rc;
328 }
329
330 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi.x, wb_roi.y,
331 wb_roi.w, wb_roi.h);
332
333 fb = sde_wb_connector_state_get_output_fb(conn_state);
334 if (!fb) {
335 SDE_ERROR("no output framebuffer\n");
336 return -EINVAL;
337 }
338
339 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
340 fb->width, fb->height);
341
342 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
343 drm_format_num_planes(fb->pixel_format));
344 if (!fmt) {
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400345 SDE_ERROR("unsupported output pixel format:%x\n",
Alan Kwongbb27c092016-07-20 16:41:25 -0400346 fb->pixel_format);
347 return -EINVAL;
348 }
349
350 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
351 fb->modifier[0]);
352
353 if (SDE_FORMAT_IS_YUV(fmt) &&
354 !(wb_cfg->features & BIT(SDE_WB_YUV_CONFIG))) {
355 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
356 return -EINVAL;
357 }
358
359 if (SDE_FORMAT_IS_UBWC(fmt) &&
360 !(wb_cfg->features & BIT(SDE_WB_UBWC_1_0))) {
361 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
362 return -EINVAL;
363 }
364
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400365 if (SDE_FORMAT_IS_YUV(fmt) != !!phys_enc->hw_cdm)
366 crtc_state->mode_changed = true;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400367
Alan Kwongbb27c092016-07-20 16:41:25 -0400368 if (wb_roi.w && wb_roi.h) {
369 if (wb_roi.w != mode->hdisplay) {
370 SDE_ERROR("invalid roi w=%d, mode w=%d\n", wb_roi.w,
371 mode->hdisplay);
372 return -EINVAL;
373 } else if (wb_roi.h != mode->vdisplay) {
374 SDE_ERROR("invalid roi h=%d, mode h=%d\n", wb_roi.h,
375 mode->vdisplay);
376 return -EINVAL;
377 } else if (wb_roi.x + wb_roi.w > fb->width) {
378 SDE_ERROR("invalid roi x=%d, w=%d, fb w=%d\n",
379 wb_roi.x, wb_roi.w, fb->width);
380 return -EINVAL;
381 } else if (wb_roi.y + wb_roi.h > fb->height) {
382 SDE_ERROR("invalid roi y=%d, h=%d, fb h=%d\n",
383 wb_roi.y, wb_roi.h, fb->height);
384 return -EINVAL;
385 } else if (wb_roi.w > wb_cfg->sblk->maxlinewidth) {
386 SDE_ERROR("invalid roi w=%d, maxlinewidth=%u\n",
387 wb_roi.w, wb_cfg->sblk->maxlinewidth);
388 return -EINVAL;
389 }
390 } else {
391 if (wb_roi.x || wb_roi.y) {
392 SDE_ERROR("invalid roi x=%d, y=%d\n",
393 wb_roi.x, wb_roi.y);
394 return -EINVAL;
395 } else if (fb->width != mode->hdisplay) {
396 SDE_ERROR("invalid fb w=%d, mode w=%d\n", fb->width,
397 mode->hdisplay);
398 return -EINVAL;
399 } else if (fb->height != mode->vdisplay) {
400 SDE_ERROR("invalid fb h=%d, mode h=%d\n", fb->height,
401 mode->vdisplay);
402 return -EINVAL;
403 } else if (fb->width > wb_cfg->sblk->maxlinewidth) {
404 SDE_ERROR("invalid fb w=%d, maxlinewidth=%u\n",
405 fb->width, wb_cfg->sblk->maxlinewidth);
406 return -EINVAL;
407 }
408 }
409
410 return 0;
411}
412
413/**
414 * sde_encoder_phys_wb_flush - flush hardware update
415 * @phys_enc: Pointer to physical encoder
416 */
417static void sde_encoder_phys_wb_flush(struct sde_encoder_phys *phys_enc)
418{
419 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
420 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
421 struct sde_hw_ctl *hw_ctl = phys_enc->hw_ctl;
422 struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
423 u32 flush_mask = 0;
424
425 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
426
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400427 if (!hw_ctl) {
428 SDE_DEBUG("[wb:%d] no ctl assigned\n", hw_wb->idx - WB_0);
429 return;
430 }
431
Alan Kwongbb27c092016-07-20 16:41:25 -0400432 if (hw_ctl->ops.get_bitmask_wb)
433 hw_ctl->ops.get_bitmask_wb(hw_ctl, &flush_mask, hw_wb->idx);
434
435 if (hw_ctl->ops.get_bitmask_cdm && hw_cdm)
436 hw_ctl->ops.get_bitmask_cdm(hw_ctl, &flush_mask, hw_cdm->idx);
437
438 if (hw_ctl->ops.update_pending_flush)
439 hw_ctl->ops.update_pending_flush(hw_ctl, flush_mask);
440
441 SDE_DEBUG("Flushing CTL_ID %d, flush_mask %x, WB %d\n",
442 hw_ctl->idx - CTL_0, flush_mask, hw_wb->idx - WB_0);
443}
444
445/**
446 * sde_encoder_phys_wb_setup - setup writeback encoder
447 * @phys_enc: Pointer to physical encoder
448 */
449static void sde_encoder_phys_wb_setup(
450 struct sde_encoder_phys *phys_enc)
451{
452 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
453 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
454 struct drm_display_mode mode = phys_enc->cached_mode;
455 struct drm_framebuffer *fb;
456 struct sde_rect *wb_roi = &wb_enc->wb_roi;
457
458 SDE_DEBUG("[mode_set:%d,%d,\"%s\",%d,%d]\n",
459 hw_wb->idx - WB_0, mode.base.id, mode.name,
460 mode.hdisplay, mode.vdisplay);
461
462 memset(wb_roi, 0, sizeof(struct sde_rect));
463
464 fb = sde_wb_get_output_fb(wb_enc->wb_dev);
465 if (!fb) {
466 SDE_DEBUG("no output framebuffer\n");
467 return;
468 }
469
470 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
471 fb->width, fb->height);
472
473 sde_wb_get_output_roi(wb_enc->wb_dev, wb_roi);
474 if (wb_roi->w == 0 || wb_roi->h == 0) {
475 wb_roi->x = 0;
476 wb_roi->y = 0;
477 wb_roi->w = fb->width;
478 wb_roi->h = fb->height;
479 }
480
481 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi->x, wb_roi->y,
482 wb_roi->w, wb_roi->h);
483
484 wb_enc->wb_fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
485 drm_format_num_planes(fb->pixel_format));
486 if (!wb_enc->wb_fmt) {
487 SDE_ERROR("unsupported output pixel format: %d\n",
488 fb->pixel_format);
489 return;
490 }
491
492 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
493 fb->modifier[0]);
494
Alan Kwong5d324e42016-07-28 22:56:18 -0400495 sde_encoder_phys_wb_set_ot_limit(phys_enc);
496
Alan Kwongbb27c092016-07-20 16:41:25 -0400497 sde_encoder_phys_wb_set_traffic_shaper(phys_enc);
498
499 sde_encoder_phys_setup_cdm(phys_enc, fb, wb_enc->wb_fmt, wb_roi);
500
501 sde_encoder_phys_wb_setup_fb(phys_enc, fb, wb_roi);
502
503 sde_encoder_phys_wb_setup_cdp(phys_enc);
504}
505
506/**
507 * sde_encoder_phys_wb_unregister_irq - unregister writeback interrupt handler
508 * @phys_enc: Pointer to physical encoder
509 */
510static int sde_encoder_phys_wb_unregister_irq(
511 struct sde_encoder_phys *phys_enc)
512{
513 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
514 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
515
516 if (wb_enc->bypass_irqreg)
517 return 0;
518
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400519 sde_core_irq_disable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
Alan Kwonga172ef52016-09-27 00:29:10 -0400520 sde_core_irq_unregister_callback(phys_enc->sde_kms, wb_enc->irq_idx,
521 &wb_enc->irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400522
523 SDE_DEBUG("un-register IRQ for wb %d, irq_idx=%d\n",
524 hw_wb->idx - WB_0,
525 wb_enc->irq_idx);
526
527 return 0;
528}
529
530/**
531 * sde_encoder_phys_wb_done_irq - writeback interrupt handler
532 * @arg: Pointer to writeback encoder
533 * @irq_idx: interrupt index
534 */
535static void sde_encoder_phys_wb_done_irq(void *arg, int irq_idx)
536{
537 struct sde_encoder_phys_wb *wb_enc = arg;
538 struct sde_encoder_phys *phys_enc = &wb_enc->base;
539 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
540
541 SDE_DEBUG("[wb:%d,%u]\n", hw_wb->idx - WB_0,
542 wb_enc->frame_count);
543
544 complete_all(&wb_enc->wbdone_complete);
545
Dhaval Patel81e87882016-10-19 21:41:56 -0700546 phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent,
547 phys_enc);
Alan Kwongbb27c092016-07-20 16:41:25 -0400548}
549
550/**
551 * sde_encoder_phys_wb_register_irq - register writeback interrupt handler
552 * @phys_enc: Pointer to physical encoder
553 */
554static int sde_encoder_phys_wb_register_irq(struct sde_encoder_phys *phys_enc)
555{
556 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
557 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Alan Kwonga172ef52016-09-27 00:29:10 -0400558 struct sde_irq_callback *irq_cb = &wb_enc->irq_cb;
Alan Kwongbb27c092016-07-20 16:41:25 -0400559 enum sde_intr_type intr_type;
560 int ret = 0;
561
562 if (wb_enc->bypass_irqreg)
563 return 0;
564
565 intr_type = sde_encoder_phys_wb_get_intr_type(hw_wb);
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400566 wb_enc->irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400567 intr_type, hw_wb->idx);
568 if (wb_enc->irq_idx < 0) {
569 SDE_ERROR(
570 "failed to lookup IRQ index for WB_DONE with wb=%d\n",
571 hw_wb->idx - WB_0);
572 return -EINVAL;
573 }
574
Alan Kwonga172ef52016-09-27 00:29:10 -0400575 irq_cb->func = sde_encoder_phys_wb_done_irq;
576 irq_cb->arg = wb_enc;
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400577 ret = sde_core_irq_register_callback(phys_enc->sde_kms,
Alan Kwonga172ef52016-09-27 00:29:10 -0400578 wb_enc->irq_idx, irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400579 if (ret) {
580 SDE_ERROR("failed to register IRQ callback WB_DONE\n");
581 return ret;
582 }
583
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400584 ret = sde_core_irq_enable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
Alan Kwongbb27c092016-07-20 16:41:25 -0400585 if (ret) {
586 SDE_ERROR(
587 "failed to enable IRQ for WB_DONE, wb %d, irq_idx=%d\n",
588 hw_wb->idx - WB_0,
589 wb_enc->irq_idx);
590 wb_enc->irq_idx = -EINVAL;
591
592 /* Unregister callback on IRQ enable failure */
Alan Kwonga172ef52016-09-27 00:29:10 -0400593 sde_core_irq_unregister_callback(phys_enc->sde_kms,
594 wb_enc->irq_idx, irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400595 return ret;
596 }
597
598 SDE_DEBUG("registered IRQ for wb %d, irq_idx=%d\n",
599 hw_wb->idx - WB_0,
600 wb_enc->irq_idx);
601
602 return ret;
603}
604
605/**
606 * sde_encoder_phys_wb_mode_set - set display mode
607 * @phys_enc: Pointer to physical encoder
608 * @mode: Pointer to requested display mode
609 * @adj_mode: Pointer to adjusted display mode
610 */
611static void sde_encoder_phys_wb_mode_set(
612 struct sde_encoder_phys *phys_enc,
613 struct drm_display_mode *mode,
614 struct drm_display_mode *adj_mode)
615{
616 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400617 struct sde_rm *rm = &phys_enc->sde_kms->rm;
Alan Kwongbb27c092016-07-20 16:41:25 -0400618 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400619 struct sde_rm_hw_iter iter;
620 int i, instance;
Alan Kwongbb27c092016-07-20 16:41:25 -0400621
622 phys_enc->cached_mode = *adj_mode;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400623 instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400624
625 SDE_DEBUG("[mode_set_cache:%d,%d,\"%s\",%d,%d]\n",
626 hw_wb->idx - WB_0, mode->base.id,
627 mode->name, mode->hdisplay, mode->vdisplay);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400628
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400629 phys_enc->hw_ctl = NULL;
630 phys_enc->hw_cdm = NULL;
631
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400632 /* Retrieve previously allocated HW Resources. CTL shouldn't fail */
633 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
634 for (i = 0; i <= instance; i++) {
635 sde_rm_get_hw(rm, &iter);
636 if (i == instance)
637 phys_enc->hw_ctl = (struct sde_hw_ctl *) iter.hw;
638 }
639
640 if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
641 SDE_ERROR("failed init ctl: %ld\n", PTR_ERR(phys_enc->hw_ctl));
642 phys_enc->hw_ctl = NULL;
643 return;
644 }
645
646 /* CDM is optional */
647 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CDM);
648 for (i = 0; i <= instance; i++) {
649 sde_rm_get_hw(rm, &iter);
650 if (i == instance)
651 phys_enc->hw_cdm = (struct sde_hw_cdm *) iter.hw;
652 }
653
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400654 if (IS_ERR(phys_enc->hw_cdm)) {
655 SDE_ERROR("CDM required but not allocated: %ld\n",
656 PTR_ERR(phys_enc->hw_cdm));
657 phys_enc->hw_ctl = NULL;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400658 }
Alan Kwongbb27c092016-07-20 16:41:25 -0400659}
660
661/**
Alan Kwongbb27c092016-07-20 16:41:25 -0400662 * sde_encoder_phys_wb_wait_for_commit_done - wait until request is committed
663 * @phys_enc: Pointer to physical encoder
664 */
665static int sde_encoder_phys_wb_wait_for_commit_done(
666 struct sde_encoder_phys *phys_enc)
667{
668 unsigned long ret;
669 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
670 u32 irq_status;
671 u64 wb_time = 0;
672 int rc = 0;
673
674 /* Return EWOULDBLOCK since we know the wait isn't necessary */
675 if (WARN_ON(phys_enc->enable_state != SDE_ENC_ENABLED))
676 return -EWOULDBLOCK;
677
678 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, 0);
679
680 ret = wait_for_completion_timeout(&wb_enc->wbdone_complete,
681 msecs_to_jiffies(wb_enc->wbdone_timeout));
682
683 if (!ret) {
684 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, 0);
685
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400686 irq_status = sde_core_irq_read(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400687 wb_enc->irq_idx, true);
688 if (irq_status) {
689 SDE_DEBUG("wb:%d done but irq not triggered\n",
690 wb_enc->wb_dev->wb_idx - WB_0);
691 sde_encoder_phys_wb_done_irq(wb_enc, wb_enc->irq_idx);
692 } else {
693 SDE_ERROR("wb:%d kickoff timed out\n",
694 wb_enc->wb_dev->wb_idx - WB_0);
695 rc = -ETIMEDOUT;
696 }
697 }
698
699 sde_encoder_phys_wb_unregister_irq(phys_enc);
700
701 if (!rc)
702 wb_enc->end_time = ktime_get();
703
704 /* once operation is done, disable traffic shaper */
705 if (wb_enc->wb_cfg.ts_cfg.en && wb_enc->hw_wb &&
706 wb_enc->hw_wb->ops.setup_trafficshaper) {
707 wb_enc->wb_cfg.ts_cfg.en = false;
708 wb_enc->hw_wb->ops.setup_trafficshaper(
709 wb_enc->hw_wb, &wb_enc->wb_cfg);
710 }
711
712 /* remove vote for iommu/clk/bus */
713 wb_enc->frame_count++;
714
715 if (!rc) {
716 wb_time = (u64)ktime_to_us(wb_enc->end_time) -
717 (u64)ktime_to_us(wb_enc->start_time);
718 SDE_DEBUG("wb:%d took %llu us\n",
719 wb_enc->wb_dev->wb_idx - WB_0, wb_time);
720 }
721
722 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, wb_time);
723
724 return rc;
725}
726
727/**
728 * sde_encoder_phys_wb_prepare_for_kickoff - pre-kickoff processing
729 * @phys_enc: Pointer to physical encoder
730 * @need_to_wait: Wait for next submission
731 */
732static void sde_encoder_phys_wb_prepare_for_kickoff(
733 struct sde_encoder_phys *phys_enc,
734 bool *need_to_wait)
735{
736 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
737 int ret;
738
739 SDE_DEBUG("[wb:%d,%u]\n", wb_enc->hw_wb->idx - WB_0,
740 wb_enc->kickoff_count);
741
742 *need_to_wait = false;
743
744 reinit_completion(&wb_enc->wbdone_complete);
745
746 ret = sde_encoder_phys_wb_register_irq(phys_enc);
747 if (ret) {
748 SDE_ERROR("failed to register irq %d\n", ret);
749 return;
750 }
751
752 wb_enc->kickoff_count++;
753
754 /* set OT limit & enable traffic shaper */
755 sde_encoder_phys_wb_setup(phys_enc);
756
757 sde_encoder_phys_wb_flush(phys_enc);
758
759 /* vote for iommu/clk/bus */
760 wb_enc->start_time = ktime_get();
761
762 MSM_EVT(DEV(phys_enc), *need_to_wait, wb_enc->kickoff_count);
763}
764
765/**
766 * sde_encoder_phys_wb_handle_post_kickoff - post-kickoff processing
767 * @phys_enc: Pointer to physical encoder
768 */
769static void sde_encoder_phys_wb_handle_post_kickoff(
770 struct sde_encoder_phys *phys_enc)
771{
772 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
773
774 SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0);
775
776 MSM_EVT(DEV(phys_enc), 0, 0);
777}
778
779/**
780 * sde_encoder_phys_wb_enable - enable writeback encoder
781 * @phys_enc: Pointer to physical encoder
782 */
783static void sde_encoder_phys_wb_enable(struct sde_encoder_phys *phys_enc)
784{
785 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
786 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Alan Kwong74e8ba32016-09-30 14:25:16 -0400787 struct drm_device *dev;
Alan Kwongbb27c092016-07-20 16:41:25 -0400788 struct drm_connector *connector;
789
790 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
791
Alan Kwong74e8ba32016-09-30 14:25:16 -0400792 if (!wb_enc->base.parent || !wb_enc->base.parent->dev) {
793 SDE_ERROR("invalid drm device\n");
794 return;
795 }
796 dev = wb_enc->base.parent->dev;
797
Alan Kwongbb27c092016-07-20 16:41:25 -0400798 /* find associated writeback connector */
Alan Kwong74e8ba32016-09-30 14:25:16 -0400799 mutex_lock(&dev->mode_config.mutex);
Alan Kwongbb27c092016-07-20 16:41:25 -0400800 drm_for_each_connector(connector, phys_enc->parent->dev) {
801 if (connector->encoder == phys_enc->parent)
802 break;
803 }
Alan Kwong74e8ba32016-09-30 14:25:16 -0400804 mutex_unlock(&dev->mode_config.mutex);
805
Alan Kwongbb27c092016-07-20 16:41:25 -0400806 if (!connector || connector->encoder != phys_enc->parent) {
807 SDE_ERROR("failed to find writeback connector\n");
808 return;
809 }
810 wb_enc->wb_dev = sde_wb_connector_get_wb(connector);
811
812 phys_enc->enable_state = SDE_ENC_ENABLED;
813}
814
815/**
816 * sde_encoder_phys_wb_disable - disable writeback encoder
817 * @phys_enc: Pointer to physical encoder
818 */
819static void sde_encoder_phys_wb_disable(struct sde_encoder_phys *phys_enc)
820{
821 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
822 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
823
824 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
825
826 if (phys_enc->enable_state == SDE_ENC_DISABLED) {
827 SDE_ERROR("encoder is already disabled\n");
828 return;
829 }
830
831 if (wb_enc->frame_count != wb_enc->kickoff_count) {
832 SDE_DEBUG("[wait_for_done: wb:%d, frame:%u, kickoff:%u]\n",
833 hw_wb->idx - WB_0, wb_enc->frame_count,
834 wb_enc->kickoff_count);
835 sde_encoder_phys_wb_wait_for_commit_done(phys_enc);
836 }
837
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400838 if (phys_enc->hw_cdm && phys_enc->hw_cdm->ops.disable) {
839 SDE_DEBUG_DRIVER("[cdm_disable]\n");
840 phys_enc->hw_cdm->ops.disable(phys_enc->hw_cdm);
841 }
842
Alan Kwongbb27c092016-07-20 16:41:25 -0400843 phys_enc->enable_state = SDE_ENC_DISABLED;
844}
845
846/**
847 * sde_encoder_phys_wb_get_hw_resources - get hardware resources
848 * @phys_enc: Pointer to physical encoder
849 * @hw_res: Pointer to encoder resources
850 */
851static void sde_encoder_phys_wb_get_hw_resources(
852 struct sde_encoder_phys *phys_enc,
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400853 struct sde_encoder_hw_resources *hw_res,
854 struct drm_connector_state *conn_state)
Alan Kwongbb27c092016-07-20 16:41:25 -0400855{
856 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400857 struct sde_hw_wb *hw_wb;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400858 struct drm_framebuffer *fb;
859 const struct sde_format *fmt;
Alan Kwongbb27c092016-07-20 16:41:25 -0400860
Clarence Ip03521982016-08-26 10:49:47 -0400861 if (!phys_enc) {
862 SDE_ERROR("invalid encoder\n");
863 return;
864 }
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400865
866 fb = sde_wb_connector_state_get_output_fb(conn_state);
867 if (!fb) {
868 SDE_ERROR("no output framebuffer\n");
869 return;
870 }
871
872 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
873 drm_format_num_planes(fb->pixel_format));
874 if (!fmt) {
875 SDE_ERROR("unsupported output pixel format:%d\n",
876 fb->pixel_format);
877 return;
878 }
879
Clarence Ip03521982016-08-26 10:49:47 -0400880 hw_wb = wb_enc->hw_wb;
Clarence Ip03521982016-08-26 10:49:47 -0400881 hw_res->wbs[hw_wb->idx - WB_0] = phys_enc->intf_mode;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400882 hw_res->needs_cdm = SDE_FORMAT_IS_YUV(fmt);
883 SDE_DEBUG("[wb:%d] intf_mode=%d needs_cdm=%d\n", hw_wb->idx - WB_0,
884 hw_res->wbs[hw_wb->idx - WB_0],
885 hw_res->needs_cdm);
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400886}
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400887
Alan Kwongbb27c092016-07-20 16:41:25 -0400888#ifdef CONFIG_DEBUG_FS
889/**
890 * sde_encoder_phys_wb_init_debugfs - initialize writeback encoder debugfs
891 * @phys_enc: Pointer to physical encoder
892 * @sde_kms: Pointer to SDE KMS object
893 */
894static int sde_encoder_phys_wb_init_debugfs(
895 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
896{
897 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
898
899 if (!phys_enc || !kms || !wb_enc->hw_wb)
900 return -EINVAL;
901
902 snprintf(wb_enc->wb_name, ARRAY_SIZE(wb_enc->wb_name), "encoder_wb%d",
903 wb_enc->hw_wb->idx - WB_0);
904
905 wb_enc->debugfs_root =
906 debugfs_create_dir(wb_enc->wb_name,
907 sde_debugfs_get_root(kms));
908 if (!wb_enc->debugfs_root) {
909 SDE_ERROR("failed to create debugfs\n");
910 return -ENOMEM;
911 }
912
913 if (!debugfs_create_u32("wbdone_timeout", 0644,
914 wb_enc->debugfs_root, &wb_enc->wbdone_timeout)) {
915 SDE_ERROR("failed to create debugfs/wbdone_timeout\n");
916 return -ENOMEM;
917 }
918
919 if (!debugfs_create_u32("bypass_irqreg", 0644,
920 wb_enc->debugfs_root, &wb_enc->bypass_irqreg)) {
921 SDE_ERROR("failed to create debugfs/bypass_irqreg\n");
922 return -ENOMEM;
923 }
924
925 return 0;
926}
927
928/**
929 * sde_encoder_phys_wb_destroy_debugfs - destroy writeback encoder debugfs
930 * @phys_enc: Pointer to physical encoder
931 */
932static void sde_encoder_phys_wb_destroy_debugfs(
933 struct sde_encoder_phys *phys_enc)
934{
935 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
936
937 if (!phys_enc)
938 return;
939
940 debugfs_remove_recursive(wb_enc->debugfs_root);
941}
942#else
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700943static int sde_encoder_phys_wb_init_debugfs(
Alan Kwongbb27c092016-07-20 16:41:25 -0400944 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
945{
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700946 return 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400947}
948static void sde_encoder_phys_wb_destroy_debugfs(
949 struct sde_encoder_phys *phys_enc)
950{
951}
952#endif
953
954/**
955 * sde_encoder_phys_wb_destroy - destroy writeback encoder
956 * @phys_enc: Pointer to physical encoder
957 */
958static void sde_encoder_phys_wb_destroy(struct sde_encoder_phys *phys_enc)
959{
960 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
961 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
962
963 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
964
965 if (!phys_enc)
966 return;
967
968 sde_encoder_phys_wb_destroy_debugfs(phys_enc);
969
Alan Kwongbb27c092016-07-20 16:41:25 -0400970 kfree(wb_enc);
971}
972
973/**
974 * sde_encoder_phys_wb_init_ops - initialize writeback operations
975 * @ops: Pointer to encoder operation table
976 */
977static void sde_encoder_phys_wb_init_ops(struct sde_encoder_phys_ops *ops)
978{
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400979 ops->is_master = sde_encoder_phys_wb_is_master;
Alan Kwongbb27c092016-07-20 16:41:25 -0400980 ops->mode_set = sde_encoder_phys_wb_mode_set;
981 ops->enable = sde_encoder_phys_wb_enable;
982 ops->disable = sde_encoder_phys_wb_disable;
983 ops->destroy = sde_encoder_phys_wb_destroy;
984 ops->atomic_check = sde_encoder_phys_wb_atomic_check;
985 ops->get_hw_resources = sde_encoder_phys_wb_get_hw_resources;
Alan Kwongbb27c092016-07-20 16:41:25 -0400986 ops->wait_for_commit_done = sde_encoder_phys_wb_wait_for_commit_done;
987 ops->prepare_for_kickoff = sde_encoder_phys_wb_prepare_for_kickoff;
988 ops->handle_post_kickoff = sde_encoder_phys_wb_handle_post_kickoff;
Clarence Ip110d15c2016-08-16 14:44:41 -0400989 ops->trigger_start = sde_encoder_helper_trigger_start;
Alan Kwongbb27c092016-07-20 16:41:25 -0400990}
991
992/**
993 * sde_encoder_phys_wb_init - initialize writeback encoder
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400994 * @init: Pointer to init info structure with initialization params
Alan Kwongbb27c092016-07-20 16:41:25 -0400995 */
996struct sde_encoder_phys *sde_encoder_phys_wb_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400997 struct sde_enc_phys_init_params *p)
Alan Kwongbb27c092016-07-20 16:41:25 -0400998{
999 struct sde_encoder_phys *phys_enc;
1000 struct sde_encoder_phys_wb *wb_enc;
1001 struct sde_hw_mdp *hw_mdp;
1002 int ret = 0;
1003
1004 SDE_DEBUG("\n");
1005
1006 wb_enc = kzalloc(sizeof(*wb_enc), GFP_KERNEL);
1007 if (!wb_enc) {
1008 ret = -ENOMEM;
1009 goto fail_alloc;
1010 }
1011 wb_enc->irq_idx = -EINVAL;
1012 wb_enc->wbdone_timeout = WAIT_TIMEOUT_MSEC;
1013 init_completion(&wb_enc->wbdone_complete);
1014
1015 phys_enc = &wb_enc->base;
1016
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001017 if (p->sde_kms->vbif[VBIF_NRT]) {
Alan Kwongbb27c092016-07-20 16:41:25 -04001018 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001019 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001020 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001021 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001022 } else {
1023 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001024 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001025 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001026 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001027 }
1028
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001029 hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
Alan Kwongbb27c092016-07-20 16:41:25 -04001030 if (IS_ERR_OR_NULL(hw_mdp)) {
1031 ret = PTR_ERR(hw_mdp);
1032 SDE_ERROR("failed to init hw_top: %d\n", ret);
1033 goto fail_mdp_init;
1034 }
1035 phys_enc->hw_mdptop = hw_mdp;
1036
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001037 /**
1038 * hw_wb resource permanently assigned to this encoder
1039 * Other resources allocated at atomic commit time by use case
1040 */
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001041 if (p->wb_idx != SDE_NONE) {
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001042 struct sde_rm_hw_iter iter;
Alan Kwongbb27c092016-07-20 16:41:25 -04001043
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001044 sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_WB);
1045 while (sde_rm_get_hw(&p->sde_kms->rm, &iter)) {
1046 struct sde_hw_wb *hw_wb = (struct sde_hw_wb *)iter.hw;
1047
1048 if (hw_wb->idx == p->wb_idx) {
1049 wb_enc->hw_wb = hw_wb;
1050 break;
1051 }
1052 }
1053
1054 if (!wb_enc->hw_wb) {
1055 ret = -EINVAL;
1056 SDE_ERROR("failed to init hw_wb%d\n", p->wb_idx - WB_0);
Alan Kwongbb27c092016-07-20 16:41:25 -04001057 goto fail_wb_init;
1058 }
Alan Kwongbb27c092016-07-20 16:41:25 -04001059 } else {
1060 ret = -EINVAL;
1061 SDE_ERROR("invalid wb_idx\n");
1062 goto fail_wb_check;
1063 }
1064
Alan Kwongbb27c092016-07-20 16:41:25 -04001065 sde_encoder_phys_wb_init_ops(&phys_enc->ops);
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001066 phys_enc->parent = p->parent;
1067 phys_enc->parent_ops = p->parent_ops;
1068 phys_enc->sde_kms = p->sde_kms;
1069 phys_enc->split_role = p->split_role;
Clarence Ip03521982016-08-26 10:49:47 -04001070 phys_enc->intf_mode = INTF_MODE_WB_LINE;
Dhaval Patel81e87882016-10-19 21:41:56 -07001071 phys_enc->intf_idx = p->intf_idx;
Alan Kwongbb27c092016-07-20 16:41:25 -04001072 spin_lock_init(&phys_enc->spin_lock);
Alan Kwonga172ef52016-09-27 00:29:10 -04001073 INIT_LIST_HEAD(&wb_enc->irq_cb.list);
Alan Kwongbb27c092016-07-20 16:41:25 -04001074
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001075 ret = sde_encoder_phys_wb_init_debugfs(phys_enc, p->sde_kms);
Alan Kwongbb27c092016-07-20 16:41:25 -04001076 if (ret) {
1077 SDE_ERROR("failed to init debugfs %d\n", ret);
1078 goto fail_debugfs_init;
1079 }
1080
1081 SDE_DEBUG("Created sde_encoder_phys_wb for wb %d\n",
1082 wb_enc->hw_wb->idx - WB_0);
1083
1084 return phys_enc;
1085
1086fail_debugfs_init:
Alan Kwongbb27c092016-07-20 16:41:25 -04001087fail_wb_init:
1088fail_wb_check:
Alan Kwongbb27c092016-07-20 16:41:25 -04001089fail_mdp_init:
1090 kfree(wb_enc);
1091fail_alloc:
1092 return ERR_PTR(ret);
1093}
1094