blob: de526595c8583eafe7d2d014dfc2f1b00aed4160 [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
15#define pr_fmt(fmt) "sde-wb:[%s] " fmt, __func__
16
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
295 memset(&wb_roi, 0, sizeof(struct sde_rect));
296
297 rc = sde_wb_connector_state_get_output_roi(conn_state, &wb_roi);
298 if (rc) {
299 SDE_ERROR("failed to get roi %d\n", rc);
300 return rc;
301 }
302
303 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi.x, wb_roi.y,
304 wb_roi.w, wb_roi.h);
305
306 fb = sde_wb_connector_state_get_output_fb(conn_state);
307 if (!fb) {
308 SDE_ERROR("no output framebuffer\n");
309 return -EINVAL;
310 }
311
312 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
313 fb->width, fb->height);
314
315 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
316 drm_format_num_planes(fb->pixel_format));
317 if (!fmt) {
318 SDE_ERROR("unsupported output pixel format:%d\n",
319 fb->pixel_format);
320 return -EINVAL;
321 }
322
323 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
324 fb->modifier[0]);
325
326 if (SDE_FORMAT_IS_YUV(fmt) &&
327 !(wb_cfg->features & BIT(SDE_WB_YUV_CONFIG))) {
328 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
329 return -EINVAL;
330 }
331
332 if (SDE_FORMAT_IS_UBWC(fmt) &&
333 !(wb_cfg->features & BIT(SDE_WB_UBWC_1_0))) {
334 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
335 return -EINVAL;
336 }
337
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400338 phys_enc->needs_cdm = SDE_FORMAT_IS_YUV(fmt);
339
Alan Kwongbb27c092016-07-20 16:41:25 -0400340 if (wb_roi.w && wb_roi.h) {
341 if (wb_roi.w != mode->hdisplay) {
342 SDE_ERROR("invalid roi w=%d, mode w=%d\n", wb_roi.w,
343 mode->hdisplay);
344 return -EINVAL;
345 } else if (wb_roi.h != mode->vdisplay) {
346 SDE_ERROR("invalid roi h=%d, mode h=%d\n", wb_roi.h,
347 mode->vdisplay);
348 return -EINVAL;
349 } else if (wb_roi.x + wb_roi.w > fb->width) {
350 SDE_ERROR("invalid roi x=%d, w=%d, fb w=%d\n",
351 wb_roi.x, wb_roi.w, fb->width);
352 return -EINVAL;
353 } else if (wb_roi.y + wb_roi.h > fb->height) {
354 SDE_ERROR("invalid roi y=%d, h=%d, fb h=%d\n",
355 wb_roi.y, wb_roi.h, fb->height);
356 return -EINVAL;
357 } else if (wb_roi.w > wb_cfg->sblk->maxlinewidth) {
358 SDE_ERROR("invalid roi w=%d, maxlinewidth=%u\n",
359 wb_roi.w, wb_cfg->sblk->maxlinewidth);
360 return -EINVAL;
361 }
362 } else {
363 if (wb_roi.x || wb_roi.y) {
364 SDE_ERROR("invalid roi x=%d, y=%d\n",
365 wb_roi.x, wb_roi.y);
366 return -EINVAL;
367 } else if (fb->width != mode->hdisplay) {
368 SDE_ERROR("invalid fb w=%d, mode w=%d\n", fb->width,
369 mode->hdisplay);
370 return -EINVAL;
371 } else if (fb->height != mode->vdisplay) {
372 SDE_ERROR("invalid fb h=%d, mode h=%d\n", fb->height,
373 mode->vdisplay);
374 return -EINVAL;
375 } else if (fb->width > wb_cfg->sblk->maxlinewidth) {
376 SDE_ERROR("invalid fb w=%d, maxlinewidth=%u\n",
377 fb->width, wb_cfg->sblk->maxlinewidth);
378 return -EINVAL;
379 }
380 }
381
382 return 0;
383}
384
385/**
386 * sde_encoder_phys_wb_flush - flush hardware update
387 * @phys_enc: Pointer to physical encoder
388 */
389static void sde_encoder_phys_wb_flush(struct sde_encoder_phys *phys_enc)
390{
391 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
392 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
393 struct sde_hw_ctl *hw_ctl = phys_enc->hw_ctl;
394 struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
395 u32 flush_mask = 0;
396
397 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
398
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400399 if (!hw_ctl) {
400 SDE_DEBUG("[wb:%d] no ctl assigned\n", hw_wb->idx - WB_0);
401 return;
402 }
403
Alan Kwongbb27c092016-07-20 16:41:25 -0400404 if (hw_ctl->ops.get_bitmask_wb)
405 hw_ctl->ops.get_bitmask_wb(hw_ctl, &flush_mask, hw_wb->idx);
406
407 if (hw_ctl->ops.get_bitmask_cdm && hw_cdm)
408 hw_ctl->ops.get_bitmask_cdm(hw_ctl, &flush_mask, hw_cdm->idx);
409
410 if (hw_ctl->ops.update_pending_flush)
411 hw_ctl->ops.update_pending_flush(hw_ctl, flush_mask);
412
413 SDE_DEBUG("Flushing CTL_ID %d, flush_mask %x, WB %d\n",
414 hw_ctl->idx - CTL_0, flush_mask, hw_wb->idx - WB_0);
415}
416
417/**
418 * sde_encoder_phys_wb_setup - setup writeback encoder
419 * @phys_enc: Pointer to physical encoder
420 */
421static void sde_encoder_phys_wb_setup(
422 struct sde_encoder_phys *phys_enc)
423{
424 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
425 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
426 struct drm_display_mode mode = phys_enc->cached_mode;
427 struct drm_framebuffer *fb;
428 struct sde_rect *wb_roi = &wb_enc->wb_roi;
429
430 SDE_DEBUG("[mode_set:%d,%d,\"%s\",%d,%d]\n",
431 hw_wb->idx - WB_0, mode.base.id, mode.name,
432 mode.hdisplay, mode.vdisplay);
433
434 memset(wb_roi, 0, sizeof(struct sde_rect));
435
436 fb = sde_wb_get_output_fb(wb_enc->wb_dev);
437 if (!fb) {
438 SDE_DEBUG("no output framebuffer\n");
439 return;
440 }
441
442 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
443 fb->width, fb->height);
444
445 sde_wb_get_output_roi(wb_enc->wb_dev, wb_roi);
446 if (wb_roi->w == 0 || wb_roi->h == 0) {
447 wb_roi->x = 0;
448 wb_roi->y = 0;
449 wb_roi->w = fb->width;
450 wb_roi->h = fb->height;
451 }
452
453 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi->x, wb_roi->y,
454 wb_roi->w, wb_roi->h);
455
456 wb_enc->wb_fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
457 drm_format_num_planes(fb->pixel_format));
458 if (!wb_enc->wb_fmt) {
459 SDE_ERROR("unsupported output pixel format: %d\n",
460 fb->pixel_format);
461 return;
462 }
463
464 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
465 fb->modifier[0]);
466
Alan Kwong5d324e42016-07-28 22:56:18 -0400467 sde_encoder_phys_wb_set_ot_limit(phys_enc);
468
Alan Kwongbb27c092016-07-20 16:41:25 -0400469 sde_encoder_phys_wb_set_traffic_shaper(phys_enc);
470
471 sde_encoder_phys_setup_cdm(phys_enc, fb, wb_enc->wb_fmt, wb_roi);
472
473 sde_encoder_phys_wb_setup_fb(phys_enc, fb, wb_roi);
474
475 sde_encoder_phys_wb_setup_cdp(phys_enc);
476}
477
478/**
479 * sde_encoder_phys_wb_unregister_irq - unregister writeback interrupt handler
480 * @phys_enc: Pointer to physical encoder
481 */
482static int sde_encoder_phys_wb_unregister_irq(
483 struct sde_encoder_phys *phys_enc)
484{
485 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
486 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
487
488 if (wb_enc->bypass_irqreg)
489 return 0;
490
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400491 sde_core_irq_disable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
492 sde_core_irq_register_callback(phys_enc->sde_kms, wb_enc->irq_idx,
493 NULL);
Alan Kwongbb27c092016-07-20 16:41:25 -0400494
495 SDE_DEBUG("un-register IRQ for wb %d, irq_idx=%d\n",
496 hw_wb->idx - WB_0,
497 wb_enc->irq_idx);
498
499 return 0;
500}
501
502/**
503 * sde_encoder_phys_wb_done_irq - writeback interrupt handler
504 * @arg: Pointer to writeback encoder
505 * @irq_idx: interrupt index
506 */
507static void sde_encoder_phys_wb_done_irq(void *arg, int irq_idx)
508{
509 struct sde_encoder_phys_wb *wb_enc = arg;
510 struct sde_encoder_phys *phys_enc = &wb_enc->base;
511 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
512
513 SDE_DEBUG("[wb:%d,%u]\n", hw_wb->idx - WB_0,
514 wb_enc->frame_count);
515
516 complete_all(&wb_enc->wbdone_complete);
517
518 phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent);
519}
520
521/**
522 * sde_encoder_phys_wb_register_irq - register writeback interrupt handler
523 * @phys_enc: Pointer to physical encoder
524 */
525static int sde_encoder_phys_wb_register_irq(struct sde_encoder_phys *phys_enc)
526{
527 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
528 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
529 struct sde_irq_callback irq_cb;
530 enum sde_intr_type intr_type;
531 int ret = 0;
532
533 if (wb_enc->bypass_irqreg)
534 return 0;
535
536 intr_type = sde_encoder_phys_wb_get_intr_type(hw_wb);
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400537 wb_enc->irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400538 intr_type, hw_wb->idx);
539 if (wb_enc->irq_idx < 0) {
540 SDE_ERROR(
541 "failed to lookup IRQ index for WB_DONE with wb=%d\n",
542 hw_wb->idx - WB_0);
543 return -EINVAL;
544 }
545
546 irq_cb.func = sde_encoder_phys_wb_done_irq;
547 irq_cb.arg = wb_enc;
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400548 ret = sde_core_irq_register_callback(phys_enc->sde_kms,
549 wb_enc->irq_idx, &irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400550 if (ret) {
551 SDE_ERROR("failed to register IRQ callback WB_DONE\n");
552 return ret;
553 }
554
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400555 ret = sde_core_irq_enable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
Alan Kwongbb27c092016-07-20 16:41:25 -0400556 if (ret) {
557 SDE_ERROR(
558 "failed to enable IRQ for WB_DONE, wb %d, irq_idx=%d\n",
559 hw_wb->idx - WB_0,
560 wb_enc->irq_idx);
561 wb_enc->irq_idx = -EINVAL;
562
563 /* Unregister callback on IRQ enable failure */
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400564 sde_core_irq_register_callback(phys_enc->sde_kms,
565 wb_enc->irq_idx, NULL);
Alan Kwongbb27c092016-07-20 16:41:25 -0400566 return ret;
567 }
568
569 SDE_DEBUG("registered IRQ for wb %d, irq_idx=%d\n",
570 hw_wb->idx - WB_0,
571 wb_enc->irq_idx);
572
573 return ret;
574}
575
576/**
577 * sde_encoder_phys_wb_mode_set - set display mode
578 * @phys_enc: Pointer to physical encoder
579 * @mode: Pointer to requested display mode
580 * @adj_mode: Pointer to adjusted display mode
581 */
582static void sde_encoder_phys_wb_mode_set(
583 struct sde_encoder_phys *phys_enc,
584 struct drm_display_mode *mode,
585 struct drm_display_mode *adj_mode)
586{
587 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400588 struct sde_rm *rm = &phys_enc->sde_kms->rm;
Alan Kwongbb27c092016-07-20 16:41:25 -0400589 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400590 struct sde_rm_hw_iter iter;
591 int i, instance;
Alan Kwongbb27c092016-07-20 16:41:25 -0400592
593 phys_enc->cached_mode = *adj_mode;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400594 instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400595
596 SDE_DEBUG("[mode_set_cache:%d,%d,\"%s\",%d,%d]\n",
597 hw_wb->idx - WB_0, mode->base.id,
598 mode->name, mode->hdisplay, mode->vdisplay);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400599
600 /* Retrieve previously allocated HW Resources. CTL shouldn't fail */
601 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
602 for (i = 0; i <= instance; i++) {
603 sde_rm_get_hw(rm, &iter);
604 if (i == instance)
605 phys_enc->hw_ctl = (struct sde_hw_ctl *) iter.hw;
606 }
607
608 if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
609 SDE_ERROR("failed init ctl: %ld\n", PTR_ERR(phys_enc->hw_ctl));
610 phys_enc->hw_ctl = NULL;
611 return;
612 }
613
614 /* CDM is optional */
615 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CDM);
616 for (i = 0; i <= instance; i++) {
617 sde_rm_get_hw(rm, &iter);
618 if (i == instance)
619 phys_enc->hw_cdm = (struct sde_hw_cdm *) iter.hw;
620 }
621
622 if (IS_ERR_OR_NULL(phys_enc->hw_cdm)) {
623 if (phys_enc->needs_cdm) {
624 SDE_ERROR("CDM required but not allocated: %ld\n",
625 PTR_ERR(phys_enc->hw_cdm));
626 phys_enc->hw_ctl = NULL;
627 }
628 phys_enc->hw_cdm = NULL;
629 }
Alan Kwongbb27c092016-07-20 16:41:25 -0400630}
631
632/**
633 * sde_encoder_phys_wb_control_vblank_irq - Control vblank interrupt
634 * @phys_enc: Pointer to physical encoder
635 * @enable: Enable interrupt
636 */
637static int sde_encoder_phys_wb_control_vblank_irq(
638 struct sde_encoder_phys *phys_enc,
639 bool enable)
640{
641 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
642 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
643 int ret = 0;
644
645 SDE_DEBUG("[wb:%d,%d]\n", hw_wb->idx - WB_0, enable);
646
647 if (enable)
648 ret = sde_encoder_phys_wb_register_irq(phys_enc);
649 else
650 ret = sde_encoder_phys_wb_unregister_irq(phys_enc);
651
652 if (ret)
653 SDE_ERROR("control vblank irq error %d, enable %d\n", ret,
654 enable);
655
656 return ret;
657}
658
659/**
660 * sde_encoder_phys_wb_wait_for_commit_done - wait until request is committed
661 * @phys_enc: Pointer to physical encoder
662 */
663static int sde_encoder_phys_wb_wait_for_commit_done(
664 struct sde_encoder_phys *phys_enc)
665{
666 unsigned long ret;
667 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
668 u32 irq_status;
669 u64 wb_time = 0;
670 int rc = 0;
671
672 /* Return EWOULDBLOCK since we know the wait isn't necessary */
673 if (WARN_ON(phys_enc->enable_state != SDE_ENC_ENABLED))
674 return -EWOULDBLOCK;
675
676 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, 0);
677
678 ret = wait_for_completion_timeout(&wb_enc->wbdone_complete,
679 msecs_to_jiffies(wb_enc->wbdone_timeout));
680
681 if (!ret) {
682 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, 0);
683
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400684 irq_status = sde_core_irq_read(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400685 wb_enc->irq_idx, true);
686 if (irq_status) {
687 SDE_DEBUG("wb:%d done but irq not triggered\n",
688 wb_enc->wb_dev->wb_idx - WB_0);
689 sde_encoder_phys_wb_done_irq(wb_enc, wb_enc->irq_idx);
690 } else {
691 SDE_ERROR("wb:%d kickoff timed out\n",
692 wb_enc->wb_dev->wb_idx - WB_0);
693 rc = -ETIMEDOUT;
694 }
695 }
696
697 sde_encoder_phys_wb_unregister_irq(phys_enc);
698
699 if (!rc)
700 wb_enc->end_time = ktime_get();
701
702 /* once operation is done, disable traffic shaper */
703 if (wb_enc->wb_cfg.ts_cfg.en && wb_enc->hw_wb &&
704 wb_enc->hw_wb->ops.setup_trafficshaper) {
705 wb_enc->wb_cfg.ts_cfg.en = false;
706 wb_enc->hw_wb->ops.setup_trafficshaper(
707 wb_enc->hw_wb, &wb_enc->wb_cfg);
708 }
709
710 /* remove vote for iommu/clk/bus */
711 wb_enc->frame_count++;
712
713 if (!rc) {
714 wb_time = (u64)ktime_to_us(wb_enc->end_time) -
715 (u64)ktime_to_us(wb_enc->start_time);
716 SDE_DEBUG("wb:%d took %llu us\n",
717 wb_enc->wb_dev->wb_idx - WB_0, wb_time);
718 }
719
720 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, wb_time);
721
722 return rc;
723}
724
725/**
726 * sde_encoder_phys_wb_prepare_for_kickoff - pre-kickoff processing
727 * @phys_enc: Pointer to physical encoder
728 * @need_to_wait: Wait for next submission
729 */
730static void sde_encoder_phys_wb_prepare_for_kickoff(
731 struct sde_encoder_phys *phys_enc,
732 bool *need_to_wait)
733{
734 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
735 int ret;
736
737 SDE_DEBUG("[wb:%d,%u]\n", wb_enc->hw_wb->idx - WB_0,
738 wb_enc->kickoff_count);
739
740 *need_to_wait = false;
741
742 reinit_completion(&wb_enc->wbdone_complete);
743
744 ret = sde_encoder_phys_wb_register_irq(phys_enc);
745 if (ret) {
746 SDE_ERROR("failed to register irq %d\n", ret);
747 return;
748 }
749
750 wb_enc->kickoff_count++;
751
752 /* set OT limit & enable traffic shaper */
753 sde_encoder_phys_wb_setup(phys_enc);
754
755 sde_encoder_phys_wb_flush(phys_enc);
756
757 /* vote for iommu/clk/bus */
758 wb_enc->start_time = ktime_get();
759
760 MSM_EVT(DEV(phys_enc), *need_to_wait, wb_enc->kickoff_count);
761}
762
763/**
764 * sde_encoder_phys_wb_handle_post_kickoff - post-kickoff processing
765 * @phys_enc: Pointer to physical encoder
766 */
767static void sde_encoder_phys_wb_handle_post_kickoff(
768 struct sde_encoder_phys *phys_enc)
769{
770 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
771
772 SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0);
773
774 MSM_EVT(DEV(phys_enc), 0, 0);
775}
776
777/**
778 * sde_encoder_phys_wb_enable - enable writeback encoder
779 * @phys_enc: Pointer to physical encoder
780 */
781static void sde_encoder_phys_wb_enable(struct sde_encoder_phys *phys_enc)
782{
783 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
784 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
785 struct drm_connector *connector;
786
787 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
788
789 /* find associated writeback connector */
790 drm_for_each_connector(connector, phys_enc->parent->dev) {
791 if (connector->encoder == phys_enc->parent)
792 break;
793 }
794 if (!connector || connector->encoder != phys_enc->parent) {
795 SDE_ERROR("failed to find writeback connector\n");
796 return;
797 }
798 wb_enc->wb_dev = sde_wb_connector_get_wb(connector);
799
800 phys_enc->enable_state = SDE_ENC_ENABLED;
801}
802
803/**
804 * sde_encoder_phys_wb_disable - disable writeback encoder
805 * @phys_enc: Pointer to physical encoder
806 */
807static void sde_encoder_phys_wb_disable(struct sde_encoder_phys *phys_enc)
808{
809 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
810 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
811
812 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
813
814 if (phys_enc->enable_state == SDE_ENC_DISABLED) {
815 SDE_ERROR("encoder is already disabled\n");
816 return;
817 }
818
819 if (wb_enc->frame_count != wb_enc->kickoff_count) {
820 SDE_DEBUG("[wait_for_done: wb:%d, frame:%u, kickoff:%u]\n",
821 hw_wb->idx - WB_0, wb_enc->frame_count,
822 wb_enc->kickoff_count);
823 sde_encoder_phys_wb_wait_for_commit_done(phys_enc);
824 }
825
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400826 if (phys_enc->hw_cdm && phys_enc->hw_cdm->ops.disable) {
827 SDE_DEBUG_DRIVER("[cdm_disable]\n");
828 phys_enc->hw_cdm->ops.disable(phys_enc->hw_cdm);
829 }
830
Alan Kwongbb27c092016-07-20 16:41:25 -0400831 phys_enc->enable_state = SDE_ENC_DISABLED;
832}
833
834/**
835 * sde_encoder_phys_wb_get_hw_resources - get hardware resources
836 * @phys_enc: Pointer to physical encoder
837 * @hw_res: Pointer to encoder resources
838 */
839static void sde_encoder_phys_wb_get_hw_resources(
840 struct sde_encoder_phys *phys_enc,
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400841 struct sde_encoder_hw_resources *hw_res,
842 struct drm_connector_state *conn_state)
Alan Kwongbb27c092016-07-20 16:41:25 -0400843{
844 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400845 struct sde_hw_wb *hw_wb;
Alan Kwongbb27c092016-07-20 16:41:25 -0400846
Clarence Ip03521982016-08-26 10:49:47 -0400847 if (!phys_enc) {
848 SDE_ERROR("invalid encoder\n");
849 return;
850 }
851 hw_wb = wb_enc->hw_wb;
Alan Kwongbb27c092016-07-20 16:41:25 -0400852 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
Clarence Ip03521982016-08-26 10:49:47 -0400853 hw_res->wbs[hw_wb->idx - WB_0] = phys_enc->intf_mode;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400854 hw_res->needs_cdm = phys_enc->needs_cdm;
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400855}
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400856
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400857/**
858 * sde_encoder_phys_wb_needs_ctl_start - Whether encoder needs ctl_start
859 * @phys_enc: Pointer to physical encoder
860 * @Return: Whether encoder needs ctl_start
861 */
862static bool sde_encoder_phys_wb_needs_ctl_start(
863 struct sde_encoder_phys *phys_enc)
864{
865 return true;
Alan Kwongbb27c092016-07-20 16:41:25 -0400866}
867
868#ifdef CONFIG_DEBUG_FS
869/**
870 * sde_encoder_phys_wb_init_debugfs - initialize writeback encoder debugfs
871 * @phys_enc: Pointer to physical encoder
872 * @sde_kms: Pointer to SDE KMS object
873 */
874static int sde_encoder_phys_wb_init_debugfs(
875 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
876{
877 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
878
879 if (!phys_enc || !kms || !wb_enc->hw_wb)
880 return -EINVAL;
881
882 snprintf(wb_enc->wb_name, ARRAY_SIZE(wb_enc->wb_name), "encoder_wb%d",
883 wb_enc->hw_wb->idx - WB_0);
884
885 wb_enc->debugfs_root =
886 debugfs_create_dir(wb_enc->wb_name,
887 sde_debugfs_get_root(kms));
888 if (!wb_enc->debugfs_root) {
889 SDE_ERROR("failed to create debugfs\n");
890 return -ENOMEM;
891 }
892
893 if (!debugfs_create_u32("wbdone_timeout", 0644,
894 wb_enc->debugfs_root, &wb_enc->wbdone_timeout)) {
895 SDE_ERROR("failed to create debugfs/wbdone_timeout\n");
896 return -ENOMEM;
897 }
898
899 if (!debugfs_create_u32("bypass_irqreg", 0644,
900 wb_enc->debugfs_root, &wb_enc->bypass_irqreg)) {
901 SDE_ERROR("failed to create debugfs/bypass_irqreg\n");
902 return -ENOMEM;
903 }
904
905 return 0;
906}
907
908/**
909 * sde_encoder_phys_wb_destroy_debugfs - destroy writeback encoder debugfs
910 * @phys_enc: Pointer to physical encoder
911 */
912static void sde_encoder_phys_wb_destroy_debugfs(
913 struct sde_encoder_phys *phys_enc)
914{
915 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
916
917 if (!phys_enc)
918 return;
919
920 debugfs_remove_recursive(wb_enc->debugfs_root);
921}
922#else
923static void sde_encoder_phys_wb_init_debugfs(
924 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
925{
926}
927static void sde_encoder_phys_wb_destroy_debugfs(
928 struct sde_encoder_phys *phys_enc)
929{
930}
931#endif
932
933/**
934 * sde_encoder_phys_wb_destroy - destroy writeback encoder
935 * @phys_enc: Pointer to physical encoder
936 */
937static void sde_encoder_phys_wb_destroy(struct sde_encoder_phys *phys_enc)
938{
939 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
940 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
941
942 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
943
944 if (!phys_enc)
945 return;
946
947 sde_encoder_phys_wb_destroy_debugfs(phys_enc);
948
Alan Kwongbb27c092016-07-20 16:41:25 -0400949 kfree(wb_enc);
950}
951
952/**
953 * sde_encoder_phys_wb_init_ops - initialize writeback operations
954 * @ops: Pointer to encoder operation table
955 */
956static void sde_encoder_phys_wb_init_ops(struct sde_encoder_phys_ops *ops)
957{
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400958 ops->is_master = sde_encoder_phys_wb_is_master;
Alan Kwongbb27c092016-07-20 16:41:25 -0400959 ops->mode_set = sde_encoder_phys_wb_mode_set;
960 ops->enable = sde_encoder_phys_wb_enable;
961 ops->disable = sde_encoder_phys_wb_disable;
962 ops->destroy = sde_encoder_phys_wb_destroy;
963 ops->atomic_check = sde_encoder_phys_wb_atomic_check;
964 ops->get_hw_resources = sde_encoder_phys_wb_get_hw_resources;
965 ops->control_vblank_irq = sde_encoder_phys_wb_control_vblank_irq;
966 ops->wait_for_commit_done = sde_encoder_phys_wb_wait_for_commit_done;
967 ops->prepare_for_kickoff = sde_encoder_phys_wb_prepare_for_kickoff;
968 ops->handle_post_kickoff = sde_encoder_phys_wb_handle_post_kickoff;
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400969 ops->needs_ctl_start = sde_encoder_phys_wb_needs_ctl_start;
Alan Kwongbb27c092016-07-20 16:41:25 -0400970}
971
972/**
973 * sde_encoder_phys_wb_init - initialize writeback encoder
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400974 * @init: Pointer to init info structure with initialization params
Alan Kwongbb27c092016-07-20 16:41:25 -0400975 */
976struct sde_encoder_phys *sde_encoder_phys_wb_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400977 struct sde_enc_phys_init_params *p)
Alan Kwongbb27c092016-07-20 16:41:25 -0400978{
979 struct sde_encoder_phys *phys_enc;
980 struct sde_encoder_phys_wb *wb_enc;
981 struct sde_hw_mdp *hw_mdp;
982 int ret = 0;
983
984 SDE_DEBUG("\n");
985
986 wb_enc = kzalloc(sizeof(*wb_enc), GFP_KERNEL);
987 if (!wb_enc) {
988 ret = -ENOMEM;
989 goto fail_alloc;
990 }
991 wb_enc->irq_idx = -EINVAL;
992 wb_enc->wbdone_timeout = WAIT_TIMEOUT_MSEC;
993 init_completion(&wb_enc->wbdone_complete);
994
995 phys_enc = &wb_enc->base;
996
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400997 if (p->sde_kms->vbif[VBIF_NRT]) {
Alan Kwongbb27c092016-07-20 16:41:25 -0400998 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400999 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001000 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001001 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001002 } else {
1003 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001004 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001005 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001006 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001007 }
1008
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001009 hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
Alan Kwongbb27c092016-07-20 16:41:25 -04001010 if (IS_ERR_OR_NULL(hw_mdp)) {
1011 ret = PTR_ERR(hw_mdp);
1012 SDE_ERROR("failed to init hw_top: %d\n", ret);
1013 goto fail_mdp_init;
1014 }
1015 phys_enc->hw_mdptop = hw_mdp;
1016
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001017 /**
1018 * hw_wb resource permanently assigned to this encoder
1019 * Other resources allocated at atomic commit time by use case
1020 */
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001021 if (p->wb_idx != SDE_NONE) {
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001022 struct sde_rm_hw_iter iter;
Alan Kwongbb27c092016-07-20 16:41:25 -04001023
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001024 sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_WB);
1025 while (sde_rm_get_hw(&p->sde_kms->rm, &iter)) {
1026 struct sde_hw_wb *hw_wb = (struct sde_hw_wb *)iter.hw;
1027
1028 if (hw_wb->idx == p->wb_idx) {
1029 wb_enc->hw_wb = hw_wb;
1030 break;
1031 }
1032 }
1033
1034 if (!wb_enc->hw_wb) {
1035 ret = -EINVAL;
1036 SDE_ERROR("failed to init hw_wb%d\n", p->wb_idx - WB_0);
Alan Kwongbb27c092016-07-20 16:41:25 -04001037 goto fail_wb_init;
1038 }
Alan Kwongbb27c092016-07-20 16:41:25 -04001039 } else {
1040 ret = -EINVAL;
1041 SDE_ERROR("invalid wb_idx\n");
1042 goto fail_wb_check;
1043 }
1044
Alan Kwongbb27c092016-07-20 16:41:25 -04001045 sde_encoder_phys_wb_init_ops(&phys_enc->ops);
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001046 phys_enc->parent = p->parent;
1047 phys_enc->parent_ops = p->parent_ops;
1048 phys_enc->sde_kms = p->sde_kms;
1049 phys_enc->split_role = p->split_role;
Clarence Ip03521982016-08-26 10:49:47 -04001050 phys_enc->intf_mode = INTF_MODE_WB_LINE;
Alan Kwongbb27c092016-07-20 16:41:25 -04001051 spin_lock_init(&phys_enc->spin_lock);
1052
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001053 ret = sde_encoder_phys_wb_init_debugfs(phys_enc, p->sde_kms);
Alan Kwongbb27c092016-07-20 16:41:25 -04001054 if (ret) {
1055 SDE_ERROR("failed to init debugfs %d\n", ret);
1056 goto fail_debugfs_init;
1057 }
1058
1059 SDE_DEBUG("Created sde_encoder_phys_wb for wb %d\n",
1060 wb_enc->hw_wb->idx - WB_0);
1061
1062 return phys_enc;
1063
1064fail_debugfs_init:
Alan Kwongbb27c092016-07-20 16:41:25 -04001065fail_wb_init:
1066fail_wb_check:
Alan Kwongbb27c092016-07-20 16:41:25 -04001067fail_mdp_init:
1068 kfree(wb_enc);
1069fail_alloc:
1070 return ERR_PTR(ret);
1071}
1072