blob: 2bfd9b10784c65824709d4cbb70550ea19c83116 [file] [log] [blame]
Alan Kwongbb27c092016-07-20 16:41:25 -04001/*
2 * Copyright (c) 2015-2016 The Linux Foundation. All rights reserved.
3 *
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"
26
27/* wait for at most 2 vsync for lowest refresh rate (24hz) */
28#define WAIT_TIMEOUT_MSEC 84
29
30#define to_sde_encoder_phys_wb(x) \
31 container_of(x, struct sde_encoder_phys_wb, base)
32
33#define DEV(phy_enc) (phy_enc->parent->dev)
34
35/**
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -040036 * sde_encoder_phys_wb_is_master - report wb always as master encoder
37 */
38static bool sde_encoder_phys_wb_is_master(struct sde_encoder_phys *phys_enc)
39{
40 return true;
41}
42
43/**
Alan Kwongbb27c092016-07-20 16:41:25 -040044 * sde_encoder_phys_wb_get_intr_type - get interrupt type based on block mode
45 * @hw_wb: Pointer to h/w writeback driver
46 */
47static enum sde_intr_type sde_encoder_phys_wb_get_intr_type(
48 struct sde_hw_wb *hw_wb)
49{
50 return (hw_wb->caps->features & BIT(SDE_WB_BLOCK_MODE)) ?
51 SDE_IRQ_TYPE_WB_ROT_COMP : SDE_IRQ_TYPE_WB_WFD_COMP;
52}
53
54/**
Alan Kwong5d324e42016-07-28 22:56:18 -040055 * sde_encoder_phys_wb_set_ot_limit - set OT limit for writeback interface
56 * @phys_enc: Pointer to physical encoder
57 */
58static void sde_encoder_phys_wb_set_ot_limit(
59 struct sde_encoder_phys *phys_enc)
60{
61 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
62 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
63 struct sde_vbif_set_ot_params ot_params;
64
65 memset(&ot_params, 0, sizeof(ot_params));
66 ot_params.xin_id = hw_wb->caps->xin_id;
67 ot_params.num = hw_wb->idx - WB_0;
68 ot_params.width = wb_enc->wb_roi.w;
69 ot_params.height = wb_enc->wb_roi.h;
70 ot_params.is_wfd = true;
71 ot_params.frame_rate = phys_enc->cached_mode.vrefresh;
72 ot_params.vbif_idx = hw_wb->caps->vbif_idx;
73 ot_params.clk_ctrl = hw_wb->caps->clk_ctrl;
74 ot_params.rd = false;
75
76 sde_vbif_set_ot_limit(phys_enc->sde_kms, &ot_params);
77}
78
79/**
Alan Kwongbb27c092016-07-20 16:41:25 -040080 * sde_encoder_phys_wb_set_traffic_shaper - set traffic shaper for writeback
81 * @phys_enc: Pointer to physical encoder
82 */
83static void sde_encoder_phys_wb_set_traffic_shaper(
84 struct sde_encoder_phys *phys_enc)
85{
86 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
87 struct sde_hw_wb_cfg *wb_cfg = &wb_enc->wb_cfg;
88
89 /* traffic shaper is only enabled for rotator */
90 wb_cfg->ts_cfg.en = false;
91}
92
93/**
94 * sde_encoder_phys_setup_cdm - setup chroma down block
95 * @phys_enc: Pointer to physical encoder
96 * @fb: Pointer to output framebuffer
97 * @format: Output format
98 */
99void sde_encoder_phys_setup_cdm(struct sde_encoder_phys *phys_enc,
100 struct drm_framebuffer *fb, const struct sde_format *format,
101 struct sde_rect *wb_roi)
102{
103 struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
104 struct sde_hw_cdm_cfg *cdm_cfg = &phys_enc->cdm_cfg;
105 int ret;
106
107 if (!SDE_FORMAT_IS_YUV(format)) {
108 SDE_DEBUG("[cdm_disable fmt:%x]\n",
109 format->base.pixel_format);
110
111 if (hw_cdm && hw_cdm->ops.disable)
112 hw_cdm->ops.disable(hw_cdm);
113
114 return;
115 }
116
117 memset(cdm_cfg, 0, sizeof(struct sde_hw_cdm_cfg));
118
119 cdm_cfg->output_width = wb_roi->w;
120 cdm_cfg->output_height = wb_roi->h;
121 cdm_cfg->output_fmt = format;
122 cdm_cfg->output_type = CDM_CDWN_OUTPUT_WB;
123 cdm_cfg->output_bit_depth = CDM_CDWN_OUTPUT_8BIT;
124
125 /* enable 10 bit logic */
126 switch (cdm_cfg->output_fmt->chroma_sample) {
127 case SDE_CHROMA_RGB:
128 cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
129 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
130 break;
131 case SDE_CHROMA_H2V1:
132 cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
133 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
134 break;
135 case SDE_CHROMA_420:
136 cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
137 cdm_cfg->v_cdwn_type = CDM_CDWN_OFFSITE;
138 break;
139 case SDE_CHROMA_H1V2:
140 default:
141 SDE_ERROR("unsupported chroma sampling type\n");
142 cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
143 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
144 break;
145 }
146
147 SDE_DEBUG("[cdm_enable:%d,%d,%X,%d,%d,%d,%d]\n",
148 cdm_cfg->output_width,
149 cdm_cfg->output_height,
150 cdm_cfg->output_fmt->base.pixel_format,
151 cdm_cfg->output_type,
152 cdm_cfg->output_bit_depth,
153 cdm_cfg->h_cdwn_type,
154 cdm_cfg->v_cdwn_type);
155
156 if (hw_cdm && hw_cdm->ops.setup_cdwn) {
157 ret = hw_cdm->ops.setup_cdwn(hw_cdm, cdm_cfg);
158 if (ret < 0) {
159 SDE_ERROR("failed to setup CDM %d\n", ret);
160 return;
161 }
162 }
163
164 if (hw_cdm && hw_cdm->ops.enable) {
165 ret = hw_cdm->ops.enable(hw_cdm, cdm_cfg);
166 if (ret < 0) {
167 SDE_ERROR("failed to enable CDM %d\n", ret);
168 return;
169 }
170 }
171}
172
173/**
174 * sde_encoder_phys_wb_setup_fb - setup output framebuffer
175 * @phys_enc: Pointer to physical encoder
176 * @fb: Pointer to output framebuffer
177 * @wb_roi: Pointer to output region of interest
178 */
179static void sde_encoder_phys_wb_setup_fb(struct sde_encoder_phys *phys_enc,
180 struct drm_framebuffer *fb, struct sde_rect *wb_roi)
181{
182 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400183 struct sde_hw_wb *hw_wb;
184 struct sde_hw_wb_cfg *wb_cfg;
Alan Kwongbb27c092016-07-20 16:41:25 -0400185 const struct msm_format *format;
186 int ret, mmu_id;
187
Clarence Ip03521982016-08-26 10:49:47 -0400188 if (!phys_enc) {
189 SDE_ERROR("invalid encoder\n");
190 return;
191 }
192
193 hw_wb = wb_enc->hw_wb;
194 wb_cfg = &wb_enc->wb_cfg;
Alan Kwongbb27c092016-07-20 16:41:25 -0400195 memset(wb_cfg, 0, sizeof(struct sde_hw_wb_cfg));
196
Clarence Ip03521982016-08-26 10:49:47 -0400197 wb_cfg->intf_mode = phys_enc->intf_mode;
Alan Kwongbb27c092016-07-20 16:41:25 -0400198 wb_cfg->is_secure = (fb->flags & DRM_MODE_FB_SECURE) ? true : false;
199 mmu_id = (wb_cfg->is_secure) ?
200 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] :
201 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE];
202
203 SDE_DEBUG("[fb_secure:%d]\n", wb_cfg->is_secure);
204
205 format = msm_framebuffer_format(fb);
Dhaval Patelccbcb3d2016-08-22 11:58:14 -0700206 if (!format) {
207 SDE_DEBUG("invalid format for fb\n");
208 return;
209 }
210
Alan Kwongbb27c092016-07-20 16:41:25 -0400211 wb_cfg->dest.format = sde_get_sde_format_ext(
212 format->pixel_format,
213 fb->modifier,
214 drm_format_num_planes(fb->pixel_format));
215 if (!wb_cfg->dest.format) {
216 /* this error should be detected during atomic_check */
217 SDE_ERROR("failed to get format %x\n", format->pixel_format);
218 return;
219 }
220
221 ret = sde_format_populate_layout_with_roi(mmu_id, fb, wb_roi,
222 &wb_cfg->dest);
223 if (ret) {
224 /* this error should be detected during atomic_check */
225 SDE_DEBUG("failed to populate layout %d\n", ret);
226 return;
227 }
228
229 if ((wb_cfg->dest.format->fetch_planes == SDE_PLANE_PLANAR) &&
230 (wb_cfg->dest.format->element[0] == C1_B_Cb))
231 swap(wb_cfg->dest.plane_addr[1], wb_cfg->dest.plane_addr[2]);
232
233 SDE_DEBUG("[fb_offset:%8.8x,%8.8x,%8.8x,%8.8x]\n",
234 wb_cfg->dest.plane_addr[0],
235 wb_cfg->dest.plane_addr[1],
236 wb_cfg->dest.plane_addr[2],
237 wb_cfg->dest.plane_addr[3]);
238 SDE_DEBUG("[fb_stride:%8.8x,%8.8x,%8.8x,%8.8x]\n",
239 wb_cfg->dest.plane_pitch[0],
240 wb_cfg->dest.plane_pitch[1],
241 wb_cfg->dest.plane_pitch[2],
242 wb_cfg->dest.plane_pitch[3]);
243
244 if (hw_wb->ops.setup_outformat)
245 hw_wb->ops.setup_outformat(hw_wb, wb_cfg);
246
247 if (hw_wb->ops.setup_outaddress)
248 hw_wb->ops.setup_outaddress(hw_wb, wb_cfg);
249}
250
251/**
252 * sde_encoder_phys_wb_setup_cdp - setup chroma down prefetch block
253 * @phys_enc: Pointer to physical encoder
254 */
255static void sde_encoder_phys_wb_setup_cdp(struct sde_encoder_phys *phys_enc)
256{
257 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
258 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
259 struct sde_hw_intf_cfg *intf_cfg = &wb_enc->intf_cfg;
260
261 memset(intf_cfg, 0, sizeof(struct sde_hw_intf_cfg));
262
263 intf_cfg->intf = SDE_NONE;
264 intf_cfg->wb = hw_wb->idx;
265
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400266 if (phys_enc->hw_ctl && phys_enc->hw_ctl->ops.setup_intf_cfg)
Alan Kwongbb27c092016-07-20 16:41:25 -0400267 phys_enc->hw_ctl->ops.setup_intf_cfg(phys_enc->hw_ctl,
268 intf_cfg);
269}
270
271/**
272 * sde_encoder_phys_wb_atomic_check - verify and fixup given atomic states
273 * @phys_enc: Pointer to physical encoder
274 * @crtc_state: Pointer to CRTC atomic state
275 * @conn_state: Pointer to connector atomic state
276 */
277static int sde_encoder_phys_wb_atomic_check(
278 struct sde_encoder_phys *phys_enc,
279 struct drm_crtc_state *crtc_state,
280 struct drm_connector_state *conn_state)
281{
282 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
283 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
284 const struct sde_wb_cfg *wb_cfg = hw_wb->caps;
285 struct drm_framebuffer *fb;
286 const struct sde_format *fmt;
287 struct sde_rect wb_roi;
288 const struct drm_display_mode *mode = &crtc_state->mode;
289 int rc;
290
291 SDE_DEBUG("[atomic_check:%d,%d,\"%s\",%d,%d]\n",
292 hw_wb->idx - WB_0, mode->base.id, mode->name,
293 mode->hdisplay, mode->vdisplay);
294
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400295 if (!conn_state || !conn_state->connector) {
296 SDE_ERROR("invalid connector state\n");
297 return -EINVAL;
298 } else if (conn_state->connector->status !=
299 connector_status_connected) {
300 SDE_ERROR("connector not connected %d\n",
301 conn_state->connector->status);
302 return -EINVAL;
303 }
304
Alan Kwongbb27c092016-07-20 16:41:25 -0400305 memset(&wb_roi, 0, sizeof(struct sde_rect));
306
307 rc = sde_wb_connector_state_get_output_roi(conn_state, &wb_roi);
308 if (rc) {
309 SDE_ERROR("failed to get roi %d\n", rc);
310 return rc;
311 }
312
313 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi.x, wb_roi.y,
314 wb_roi.w, wb_roi.h);
315
316 fb = sde_wb_connector_state_get_output_fb(conn_state);
317 if (!fb) {
318 SDE_ERROR("no output framebuffer\n");
319 return -EINVAL;
320 }
321
322 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
323 fb->width, fb->height);
324
325 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
326 drm_format_num_planes(fb->pixel_format));
327 if (!fmt) {
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400328 SDE_ERROR("unsupported output pixel format:%x\n",
Alan Kwongbb27c092016-07-20 16:41:25 -0400329 fb->pixel_format);
330 return -EINVAL;
331 }
332
333 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
334 fb->modifier[0]);
335
336 if (SDE_FORMAT_IS_YUV(fmt) &&
337 !(wb_cfg->features & BIT(SDE_WB_YUV_CONFIG))) {
338 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
339 return -EINVAL;
340 }
341
342 if (SDE_FORMAT_IS_UBWC(fmt) &&
343 !(wb_cfg->features & BIT(SDE_WB_UBWC_1_0))) {
344 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
345 return -EINVAL;
346 }
347
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400348 if (SDE_FORMAT_IS_YUV(fmt) != !!phys_enc->hw_cdm)
349 crtc_state->mode_changed = true;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400350
Alan Kwongbb27c092016-07-20 16:41:25 -0400351 if (wb_roi.w && wb_roi.h) {
352 if (wb_roi.w != mode->hdisplay) {
353 SDE_ERROR("invalid roi w=%d, mode w=%d\n", wb_roi.w,
354 mode->hdisplay);
355 return -EINVAL;
356 } else if (wb_roi.h != mode->vdisplay) {
357 SDE_ERROR("invalid roi h=%d, mode h=%d\n", wb_roi.h,
358 mode->vdisplay);
359 return -EINVAL;
360 } else if (wb_roi.x + wb_roi.w > fb->width) {
361 SDE_ERROR("invalid roi x=%d, w=%d, fb w=%d\n",
362 wb_roi.x, wb_roi.w, fb->width);
363 return -EINVAL;
364 } else if (wb_roi.y + wb_roi.h > fb->height) {
365 SDE_ERROR("invalid roi y=%d, h=%d, fb h=%d\n",
366 wb_roi.y, wb_roi.h, fb->height);
367 return -EINVAL;
368 } else if (wb_roi.w > wb_cfg->sblk->maxlinewidth) {
369 SDE_ERROR("invalid roi w=%d, maxlinewidth=%u\n",
370 wb_roi.w, wb_cfg->sblk->maxlinewidth);
371 return -EINVAL;
372 }
373 } else {
374 if (wb_roi.x || wb_roi.y) {
375 SDE_ERROR("invalid roi x=%d, y=%d\n",
376 wb_roi.x, wb_roi.y);
377 return -EINVAL;
378 } else if (fb->width != mode->hdisplay) {
379 SDE_ERROR("invalid fb w=%d, mode w=%d\n", fb->width,
380 mode->hdisplay);
381 return -EINVAL;
382 } else if (fb->height != mode->vdisplay) {
383 SDE_ERROR("invalid fb h=%d, mode h=%d\n", fb->height,
384 mode->vdisplay);
385 return -EINVAL;
386 } else if (fb->width > wb_cfg->sblk->maxlinewidth) {
387 SDE_ERROR("invalid fb w=%d, maxlinewidth=%u\n",
388 fb->width, wb_cfg->sblk->maxlinewidth);
389 return -EINVAL;
390 }
391 }
392
393 return 0;
394}
395
396/**
397 * sde_encoder_phys_wb_flush - flush hardware update
398 * @phys_enc: Pointer to physical encoder
399 */
400static void sde_encoder_phys_wb_flush(struct sde_encoder_phys *phys_enc)
401{
402 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
403 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
404 struct sde_hw_ctl *hw_ctl = phys_enc->hw_ctl;
405 struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
406 u32 flush_mask = 0;
407
408 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
409
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400410 if (!hw_ctl) {
411 SDE_DEBUG("[wb:%d] no ctl assigned\n", hw_wb->idx - WB_0);
412 return;
413 }
414
Alan Kwongbb27c092016-07-20 16:41:25 -0400415 if (hw_ctl->ops.get_bitmask_wb)
416 hw_ctl->ops.get_bitmask_wb(hw_ctl, &flush_mask, hw_wb->idx);
417
418 if (hw_ctl->ops.get_bitmask_cdm && hw_cdm)
419 hw_ctl->ops.get_bitmask_cdm(hw_ctl, &flush_mask, hw_cdm->idx);
420
421 if (hw_ctl->ops.update_pending_flush)
422 hw_ctl->ops.update_pending_flush(hw_ctl, flush_mask);
423
424 SDE_DEBUG("Flushing CTL_ID %d, flush_mask %x, WB %d\n",
425 hw_ctl->idx - CTL_0, flush_mask, hw_wb->idx - WB_0);
426}
427
428/**
429 * sde_encoder_phys_wb_setup - setup writeback encoder
430 * @phys_enc: Pointer to physical encoder
431 */
432static void sde_encoder_phys_wb_setup(
433 struct sde_encoder_phys *phys_enc)
434{
435 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
436 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
437 struct drm_display_mode mode = phys_enc->cached_mode;
438 struct drm_framebuffer *fb;
439 struct sde_rect *wb_roi = &wb_enc->wb_roi;
440
441 SDE_DEBUG("[mode_set:%d,%d,\"%s\",%d,%d]\n",
442 hw_wb->idx - WB_0, mode.base.id, mode.name,
443 mode.hdisplay, mode.vdisplay);
444
445 memset(wb_roi, 0, sizeof(struct sde_rect));
446
447 fb = sde_wb_get_output_fb(wb_enc->wb_dev);
448 if (!fb) {
449 SDE_DEBUG("no output framebuffer\n");
450 return;
451 }
452
453 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
454 fb->width, fb->height);
455
456 sde_wb_get_output_roi(wb_enc->wb_dev, wb_roi);
457 if (wb_roi->w == 0 || wb_roi->h == 0) {
458 wb_roi->x = 0;
459 wb_roi->y = 0;
460 wb_roi->w = fb->width;
461 wb_roi->h = fb->height;
462 }
463
464 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi->x, wb_roi->y,
465 wb_roi->w, wb_roi->h);
466
467 wb_enc->wb_fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
468 drm_format_num_planes(fb->pixel_format));
469 if (!wb_enc->wb_fmt) {
470 SDE_ERROR("unsupported output pixel format: %d\n",
471 fb->pixel_format);
472 return;
473 }
474
475 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
476 fb->modifier[0]);
477
Alan Kwong5d324e42016-07-28 22:56:18 -0400478 sde_encoder_phys_wb_set_ot_limit(phys_enc);
479
Alan Kwongbb27c092016-07-20 16:41:25 -0400480 sde_encoder_phys_wb_set_traffic_shaper(phys_enc);
481
482 sde_encoder_phys_setup_cdm(phys_enc, fb, wb_enc->wb_fmt, wb_roi);
483
484 sde_encoder_phys_wb_setup_fb(phys_enc, fb, wb_roi);
485
486 sde_encoder_phys_wb_setup_cdp(phys_enc);
487}
488
489/**
490 * sde_encoder_phys_wb_unregister_irq - unregister writeback interrupt handler
491 * @phys_enc: Pointer to physical encoder
492 */
493static int sde_encoder_phys_wb_unregister_irq(
494 struct sde_encoder_phys *phys_enc)
495{
496 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
497 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
498
499 if (wb_enc->bypass_irqreg)
500 return 0;
501
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400502 sde_core_irq_disable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
503 sde_core_irq_register_callback(phys_enc->sde_kms, wb_enc->irq_idx,
504 NULL);
Alan Kwongbb27c092016-07-20 16:41:25 -0400505
506 SDE_DEBUG("un-register IRQ for wb %d, irq_idx=%d\n",
507 hw_wb->idx - WB_0,
508 wb_enc->irq_idx);
509
510 return 0;
511}
512
513/**
514 * sde_encoder_phys_wb_done_irq - writeback interrupt handler
515 * @arg: Pointer to writeback encoder
516 * @irq_idx: interrupt index
517 */
518static void sde_encoder_phys_wb_done_irq(void *arg, int irq_idx)
519{
520 struct sde_encoder_phys_wb *wb_enc = arg;
521 struct sde_encoder_phys *phys_enc = &wb_enc->base;
522 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
523
524 SDE_DEBUG("[wb:%d,%u]\n", hw_wb->idx - WB_0,
525 wb_enc->frame_count);
526
527 complete_all(&wb_enc->wbdone_complete);
528
529 phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent);
530}
531
532/**
533 * sde_encoder_phys_wb_register_irq - register writeback interrupt handler
534 * @phys_enc: Pointer to physical encoder
535 */
536static int sde_encoder_phys_wb_register_irq(struct sde_encoder_phys *phys_enc)
537{
538 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
539 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
540 struct sde_irq_callback irq_cb;
541 enum sde_intr_type intr_type;
542 int ret = 0;
543
544 if (wb_enc->bypass_irqreg)
545 return 0;
546
547 intr_type = sde_encoder_phys_wb_get_intr_type(hw_wb);
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400548 wb_enc->irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400549 intr_type, hw_wb->idx);
550 if (wb_enc->irq_idx < 0) {
551 SDE_ERROR(
552 "failed to lookup IRQ index for WB_DONE with wb=%d\n",
553 hw_wb->idx - WB_0);
554 return -EINVAL;
555 }
556
557 irq_cb.func = sde_encoder_phys_wb_done_irq;
558 irq_cb.arg = wb_enc;
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400559 ret = sde_core_irq_register_callback(phys_enc->sde_kms,
560 wb_enc->irq_idx, &irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400561 if (ret) {
562 SDE_ERROR("failed to register IRQ callback WB_DONE\n");
563 return ret;
564 }
565
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400566 ret = sde_core_irq_enable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
Alan Kwongbb27c092016-07-20 16:41:25 -0400567 if (ret) {
568 SDE_ERROR(
569 "failed to enable IRQ for WB_DONE, wb %d, irq_idx=%d\n",
570 hw_wb->idx - WB_0,
571 wb_enc->irq_idx);
572 wb_enc->irq_idx = -EINVAL;
573
574 /* Unregister callback on IRQ enable failure */
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400575 sde_core_irq_register_callback(phys_enc->sde_kms,
576 wb_enc->irq_idx, NULL);
Alan Kwongbb27c092016-07-20 16:41:25 -0400577 return ret;
578 }
579
580 SDE_DEBUG("registered IRQ for wb %d, irq_idx=%d\n",
581 hw_wb->idx - WB_0,
582 wb_enc->irq_idx);
583
584 return ret;
585}
586
587/**
588 * sde_encoder_phys_wb_mode_set - set display mode
589 * @phys_enc: Pointer to physical encoder
590 * @mode: Pointer to requested display mode
591 * @adj_mode: Pointer to adjusted display mode
592 */
593static void sde_encoder_phys_wb_mode_set(
594 struct sde_encoder_phys *phys_enc,
595 struct drm_display_mode *mode,
596 struct drm_display_mode *adj_mode)
597{
598 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400599 struct sde_rm *rm = &phys_enc->sde_kms->rm;
Alan Kwongbb27c092016-07-20 16:41:25 -0400600 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400601 struct sde_rm_hw_iter iter;
602 int i, instance;
Alan Kwongbb27c092016-07-20 16:41:25 -0400603
604 phys_enc->cached_mode = *adj_mode;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400605 instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400606
607 SDE_DEBUG("[mode_set_cache:%d,%d,\"%s\",%d,%d]\n",
608 hw_wb->idx - WB_0, mode->base.id,
609 mode->name, mode->hdisplay, mode->vdisplay);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400610
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400611 phys_enc->hw_ctl = NULL;
612 phys_enc->hw_cdm = NULL;
613
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400614 /* Retrieve previously allocated HW Resources. CTL shouldn't fail */
615 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
616 for (i = 0; i <= instance; i++) {
617 sde_rm_get_hw(rm, &iter);
618 if (i == instance)
619 phys_enc->hw_ctl = (struct sde_hw_ctl *) iter.hw;
620 }
621
622 if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
623 SDE_ERROR("failed init ctl: %ld\n", PTR_ERR(phys_enc->hw_ctl));
624 phys_enc->hw_ctl = NULL;
625 return;
626 }
627
628 /* CDM is optional */
629 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CDM);
630 for (i = 0; i <= instance; i++) {
631 sde_rm_get_hw(rm, &iter);
632 if (i == instance)
633 phys_enc->hw_cdm = (struct sde_hw_cdm *) iter.hw;
634 }
635
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400636 if (IS_ERR(phys_enc->hw_cdm)) {
637 SDE_ERROR("CDM required but not allocated: %ld\n",
638 PTR_ERR(phys_enc->hw_cdm));
639 phys_enc->hw_ctl = NULL;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400640 }
Alan Kwongbb27c092016-07-20 16:41:25 -0400641}
642
643/**
Alan Kwongbb27c092016-07-20 16:41:25 -0400644 * sde_encoder_phys_wb_wait_for_commit_done - wait until request is committed
645 * @phys_enc: Pointer to physical encoder
646 */
647static int sde_encoder_phys_wb_wait_for_commit_done(
648 struct sde_encoder_phys *phys_enc)
649{
650 unsigned long ret;
651 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
652 u32 irq_status;
653 u64 wb_time = 0;
654 int rc = 0;
655
656 /* Return EWOULDBLOCK since we know the wait isn't necessary */
657 if (WARN_ON(phys_enc->enable_state != SDE_ENC_ENABLED))
658 return -EWOULDBLOCK;
659
660 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, 0);
661
662 ret = wait_for_completion_timeout(&wb_enc->wbdone_complete,
663 msecs_to_jiffies(wb_enc->wbdone_timeout));
664
665 if (!ret) {
666 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, 0);
667
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400668 irq_status = sde_core_irq_read(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400669 wb_enc->irq_idx, true);
670 if (irq_status) {
671 SDE_DEBUG("wb:%d done but irq not triggered\n",
672 wb_enc->wb_dev->wb_idx - WB_0);
673 sde_encoder_phys_wb_done_irq(wb_enc, wb_enc->irq_idx);
674 } else {
675 SDE_ERROR("wb:%d kickoff timed out\n",
676 wb_enc->wb_dev->wb_idx - WB_0);
677 rc = -ETIMEDOUT;
678 }
679 }
680
681 sde_encoder_phys_wb_unregister_irq(phys_enc);
682
683 if (!rc)
684 wb_enc->end_time = ktime_get();
685
686 /* once operation is done, disable traffic shaper */
687 if (wb_enc->wb_cfg.ts_cfg.en && wb_enc->hw_wb &&
688 wb_enc->hw_wb->ops.setup_trafficshaper) {
689 wb_enc->wb_cfg.ts_cfg.en = false;
690 wb_enc->hw_wb->ops.setup_trafficshaper(
691 wb_enc->hw_wb, &wb_enc->wb_cfg);
692 }
693
694 /* remove vote for iommu/clk/bus */
695 wb_enc->frame_count++;
696
697 if (!rc) {
698 wb_time = (u64)ktime_to_us(wb_enc->end_time) -
699 (u64)ktime_to_us(wb_enc->start_time);
700 SDE_DEBUG("wb:%d took %llu us\n",
701 wb_enc->wb_dev->wb_idx - WB_0, wb_time);
702 }
703
704 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, wb_time);
705
706 return rc;
707}
708
709/**
710 * sde_encoder_phys_wb_prepare_for_kickoff - pre-kickoff processing
711 * @phys_enc: Pointer to physical encoder
712 * @need_to_wait: Wait for next submission
713 */
714static void sde_encoder_phys_wb_prepare_for_kickoff(
715 struct sde_encoder_phys *phys_enc,
716 bool *need_to_wait)
717{
718 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
719 int ret;
720
721 SDE_DEBUG("[wb:%d,%u]\n", wb_enc->hw_wb->idx - WB_0,
722 wb_enc->kickoff_count);
723
724 *need_to_wait = false;
725
726 reinit_completion(&wb_enc->wbdone_complete);
727
728 ret = sde_encoder_phys_wb_register_irq(phys_enc);
729 if (ret) {
730 SDE_ERROR("failed to register irq %d\n", ret);
731 return;
732 }
733
734 wb_enc->kickoff_count++;
735
736 /* set OT limit & enable traffic shaper */
737 sde_encoder_phys_wb_setup(phys_enc);
738
739 sde_encoder_phys_wb_flush(phys_enc);
740
741 /* vote for iommu/clk/bus */
742 wb_enc->start_time = ktime_get();
743
744 MSM_EVT(DEV(phys_enc), *need_to_wait, wb_enc->kickoff_count);
745}
746
747/**
748 * sde_encoder_phys_wb_handle_post_kickoff - post-kickoff processing
749 * @phys_enc: Pointer to physical encoder
750 */
751static void sde_encoder_phys_wb_handle_post_kickoff(
752 struct sde_encoder_phys *phys_enc)
753{
754 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
755
756 SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0);
757
758 MSM_EVT(DEV(phys_enc), 0, 0);
759}
760
761/**
762 * sde_encoder_phys_wb_enable - enable writeback encoder
763 * @phys_enc: Pointer to physical encoder
764 */
765static void sde_encoder_phys_wb_enable(struct sde_encoder_phys *phys_enc)
766{
767 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
768 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
769 struct drm_connector *connector;
770
771 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
772
773 /* find associated writeback connector */
774 drm_for_each_connector(connector, phys_enc->parent->dev) {
775 if (connector->encoder == phys_enc->parent)
776 break;
777 }
778 if (!connector || connector->encoder != phys_enc->parent) {
779 SDE_ERROR("failed to find writeback connector\n");
780 return;
781 }
782 wb_enc->wb_dev = sde_wb_connector_get_wb(connector);
783
784 phys_enc->enable_state = SDE_ENC_ENABLED;
785}
786
787/**
788 * sde_encoder_phys_wb_disable - disable writeback encoder
789 * @phys_enc: Pointer to physical encoder
790 */
791static void sde_encoder_phys_wb_disable(struct sde_encoder_phys *phys_enc)
792{
793 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
794 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
795
796 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
797
798 if (phys_enc->enable_state == SDE_ENC_DISABLED) {
799 SDE_ERROR("encoder is already disabled\n");
800 return;
801 }
802
803 if (wb_enc->frame_count != wb_enc->kickoff_count) {
804 SDE_DEBUG("[wait_for_done: wb:%d, frame:%u, kickoff:%u]\n",
805 hw_wb->idx - WB_0, wb_enc->frame_count,
806 wb_enc->kickoff_count);
807 sde_encoder_phys_wb_wait_for_commit_done(phys_enc);
808 }
809
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400810 if (phys_enc->hw_cdm && phys_enc->hw_cdm->ops.disable) {
811 SDE_DEBUG_DRIVER("[cdm_disable]\n");
812 phys_enc->hw_cdm->ops.disable(phys_enc->hw_cdm);
813 }
814
Alan Kwongbb27c092016-07-20 16:41:25 -0400815 phys_enc->enable_state = SDE_ENC_DISABLED;
816}
817
818/**
819 * sde_encoder_phys_wb_get_hw_resources - get hardware resources
820 * @phys_enc: Pointer to physical encoder
821 * @hw_res: Pointer to encoder resources
822 */
823static void sde_encoder_phys_wb_get_hw_resources(
824 struct sde_encoder_phys *phys_enc,
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400825 struct sde_encoder_hw_resources *hw_res,
826 struct drm_connector_state *conn_state)
Alan Kwongbb27c092016-07-20 16:41:25 -0400827{
828 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400829 struct sde_hw_wb *hw_wb;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400830 struct drm_framebuffer *fb;
831 const struct sde_format *fmt;
Alan Kwongbb27c092016-07-20 16:41:25 -0400832
Clarence Ip03521982016-08-26 10:49:47 -0400833 if (!phys_enc) {
834 SDE_ERROR("invalid encoder\n");
835 return;
836 }
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400837
838 fb = sde_wb_connector_state_get_output_fb(conn_state);
839 if (!fb) {
840 SDE_ERROR("no output framebuffer\n");
841 return;
842 }
843
844 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
845 drm_format_num_planes(fb->pixel_format));
846 if (!fmt) {
847 SDE_ERROR("unsupported output pixel format:%d\n",
848 fb->pixel_format);
849 return;
850 }
851
Clarence Ip03521982016-08-26 10:49:47 -0400852 hw_wb = wb_enc->hw_wb;
Clarence Ip03521982016-08-26 10:49:47 -0400853 hw_res->wbs[hw_wb->idx - WB_0] = phys_enc->intf_mode;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400854 hw_res->needs_cdm = SDE_FORMAT_IS_YUV(fmt);
855 SDE_DEBUG("[wb:%d] intf_mode=%d needs_cdm=%d\n", hw_wb->idx - WB_0,
856 hw_res->wbs[hw_wb->idx - WB_0],
857 hw_res->needs_cdm);
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400858}
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400859
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400860/**
861 * sde_encoder_phys_wb_needs_ctl_start - Whether encoder needs ctl_start
862 * @phys_enc: Pointer to physical encoder
863 * @Return: Whether encoder needs ctl_start
864 */
865static bool sde_encoder_phys_wb_needs_ctl_start(
866 struct sde_encoder_phys *phys_enc)
867{
868 return true;
Alan Kwongbb27c092016-07-20 16:41:25 -0400869}
870
871#ifdef CONFIG_DEBUG_FS
872/**
873 * sde_encoder_phys_wb_init_debugfs - initialize writeback encoder debugfs
874 * @phys_enc: Pointer to physical encoder
875 * @sde_kms: Pointer to SDE KMS object
876 */
877static int sde_encoder_phys_wb_init_debugfs(
878 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
879{
880 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
881
882 if (!phys_enc || !kms || !wb_enc->hw_wb)
883 return -EINVAL;
884
885 snprintf(wb_enc->wb_name, ARRAY_SIZE(wb_enc->wb_name), "encoder_wb%d",
886 wb_enc->hw_wb->idx - WB_0);
887
888 wb_enc->debugfs_root =
889 debugfs_create_dir(wb_enc->wb_name,
890 sde_debugfs_get_root(kms));
891 if (!wb_enc->debugfs_root) {
892 SDE_ERROR("failed to create debugfs\n");
893 return -ENOMEM;
894 }
895
896 if (!debugfs_create_u32("wbdone_timeout", 0644,
897 wb_enc->debugfs_root, &wb_enc->wbdone_timeout)) {
898 SDE_ERROR("failed to create debugfs/wbdone_timeout\n");
899 return -ENOMEM;
900 }
901
902 if (!debugfs_create_u32("bypass_irqreg", 0644,
903 wb_enc->debugfs_root, &wb_enc->bypass_irqreg)) {
904 SDE_ERROR("failed to create debugfs/bypass_irqreg\n");
905 return -ENOMEM;
906 }
907
908 return 0;
909}
910
911/**
912 * sde_encoder_phys_wb_destroy_debugfs - destroy writeback encoder debugfs
913 * @phys_enc: Pointer to physical encoder
914 */
915static void sde_encoder_phys_wb_destroy_debugfs(
916 struct sde_encoder_phys *phys_enc)
917{
918 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
919
920 if (!phys_enc)
921 return;
922
923 debugfs_remove_recursive(wb_enc->debugfs_root);
924}
925#else
926static void sde_encoder_phys_wb_init_debugfs(
927 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
928{
929}
930static void sde_encoder_phys_wb_destroy_debugfs(
931 struct sde_encoder_phys *phys_enc)
932{
933}
934#endif
935
936/**
937 * sde_encoder_phys_wb_destroy - destroy writeback encoder
938 * @phys_enc: Pointer to physical encoder
939 */
940static void sde_encoder_phys_wb_destroy(struct sde_encoder_phys *phys_enc)
941{
942 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
943 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
944
945 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
946
947 if (!phys_enc)
948 return;
949
950 sde_encoder_phys_wb_destroy_debugfs(phys_enc);
951
Alan Kwongbb27c092016-07-20 16:41:25 -0400952 kfree(wb_enc);
953}
954
955/**
956 * sde_encoder_phys_wb_init_ops - initialize writeback operations
957 * @ops: Pointer to encoder operation table
958 */
959static void sde_encoder_phys_wb_init_ops(struct sde_encoder_phys_ops *ops)
960{
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400961 ops->is_master = sde_encoder_phys_wb_is_master;
Alan Kwongbb27c092016-07-20 16:41:25 -0400962 ops->mode_set = sde_encoder_phys_wb_mode_set;
963 ops->enable = sde_encoder_phys_wb_enable;
964 ops->disable = sde_encoder_phys_wb_disable;
965 ops->destroy = sde_encoder_phys_wb_destroy;
966 ops->atomic_check = sde_encoder_phys_wb_atomic_check;
967 ops->get_hw_resources = sde_encoder_phys_wb_get_hw_resources;
Alan Kwongbb27c092016-07-20 16:41:25 -0400968 ops->wait_for_commit_done = sde_encoder_phys_wb_wait_for_commit_done;
969 ops->prepare_for_kickoff = sde_encoder_phys_wb_prepare_for_kickoff;
970 ops->handle_post_kickoff = sde_encoder_phys_wb_handle_post_kickoff;
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400971 ops->needs_ctl_start = sde_encoder_phys_wb_needs_ctl_start;
Alan Kwongbb27c092016-07-20 16:41:25 -0400972}
973
974/**
975 * sde_encoder_phys_wb_init - initialize writeback encoder
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400976 * @init: Pointer to init info structure with initialization params
Alan Kwongbb27c092016-07-20 16:41:25 -0400977 */
978struct sde_encoder_phys *sde_encoder_phys_wb_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400979 struct sde_enc_phys_init_params *p)
Alan Kwongbb27c092016-07-20 16:41:25 -0400980{
981 struct sde_encoder_phys *phys_enc;
982 struct sde_encoder_phys_wb *wb_enc;
983 struct sde_hw_mdp *hw_mdp;
984 int ret = 0;
985
986 SDE_DEBUG("\n");
987
988 wb_enc = kzalloc(sizeof(*wb_enc), GFP_KERNEL);
989 if (!wb_enc) {
990 ret = -ENOMEM;
991 goto fail_alloc;
992 }
993 wb_enc->irq_idx = -EINVAL;
994 wb_enc->wbdone_timeout = WAIT_TIMEOUT_MSEC;
995 init_completion(&wb_enc->wbdone_complete);
996
997 phys_enc = &wb_enc->base;
998
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400999 if (p->sde_kms->vbif[VBIF_NRT]) {
Alan Kwongbb27c092016-07-20 16:41:25 -04001000 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001001 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001002 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001003 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001004 } else {
1005 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001006 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001007 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001008 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001009 }
1010
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001011 hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
Alan Kwongbb27c092016-07-20 16:41:25 -04001012 if (IS_ERR_OR_NULL(hw_mdp)) {
1013 ret = PTR_ERR(hw_mdp);
1014 SDE_ERROR("failed to init hw_top: %d\n", ret);
1015 goto fail_mdp_init;
1016 }
1017 phys_enc->hw_mdptop = hw_mdp;
1018
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001019 /**
1020 * hw_wb resource permanently assigned to this encoder
1021 * Other resources allocated at atomic commit time by use case
1022 */
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001023 if (p->wb_idx != SDE_NONE) {
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001024 struct sde_rm_hw_iter iter;
Alan Kwongbb27c092016-07-20 16:41:25 -04001025
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001026 sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_WB);
1027 while (sde_rm_get_hw(&p->sde_kms->rm, &iter)) {
1028 struct sde_hw_wb *hw_wb = (struct sde_hw_wb *)iter.hw;
1029
1030 if (hw_wb->idx == p->wb_idx) {
1031 wb_enc->hw_wb = hw_wb;
1032 break;
1033 }
1034 }
1035
1036 if (!wb_enc->hw_wb) {
1037 ret = -EINVAL;
1038 SDE_ERROR("failed to init hw_wb%d\n", p->wb_idx - WB_0);
Alan Kwongbb27c092016-07-20 16:41:25 -04001039 goto fail_wb_init;
1040 }
Alan Kwongbb27c092016-07-20 16:41:25 -04001041 } else {
1042 ret = -EINVAL;
1043 SDE_ERROR("invalid wb_idx\n");
1044 goto fail_wb_check;
1045 }
1046
Alan Kwongbb27c092016-07-20 16:41:25 -04001047 sde_encoder_phys_wb_init_ops(&phys_enc->ops);
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001048 phys_enc->parent = p->parent;
1049 phys_enc->parent_ops = p->parent_ops;
1050 phys_enc->sde_kms = p->sde_kms;
1051 phys_enc->split_role = p->split_role;
Clarence Ip03521982016-08-26 10:49:47 -04001052 phys_enc->intf_mode = INTF_MODE_WB_LINE;
Alan Kwongbb27c092016-07-20 16:41:25 -04001053 spin_lock_init(&phys_enc->spin_lock);
1054
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001055 ret = sde_encoder_phys_wb_init_debugfs(phys_enc, p->sde_kms);
Alan Kwongbb27c092016-07-20 16:41:25 -04001056 if (ret) {
1057 SDE_ERROR("failed to init debugfs %d\n", ret);
1058 goto fail_debugfs_init;
1059 }
1060
1061 SDE_DEBUG("Created sde_encoder_phys_wb for wb %d\n",
1062 wb_enc->hw_wb->idx - WB_0);
1063
1064 return phys_enc;
1065
1066fail_debugfs_init:
Alan Kwongbb27c092016-07-20 16:41:25 -04001067fail_wb_init:
1068fail_wb_check:
Alan Kwongbb27c092016-07-20 16:41:25 -04001069fail_mdp_init:
1070 kfree(wb_enc);
1071fail_alloc:
1072 return ERR_PTR(ret);
1073}
1074