blob: 987f376260c6fcae821a8cbcaebcfaa416cb519e [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 }
abeykunf1539f72016-08-24 16:08:03 -0400220 wb_cfg->roi = *wb_roi;
Alan Kwongbb27c092016-07-20 16:41:25 -0400221
abeykunf1539f72016-08-24 16:08:03 -0400222 if (hw_wb->caps->features & BIT(SDE_WB_XY_ROI_OFFSET)) {
223 ret = sde_format_populate_layout(mmu_id, fb, &wb_cfg->dest);
224 if (ret) {
225 SDE_DEBUG("failed to populate layout %d\n", ret);
226 return;
227 }
228 wb_cfg->dest.width = fb->width;
229 wb_cfg->dest.height = fb->height;
230 wb_cfg->dest.num_planes = wb_cfg->dest.format->num_planes;
231 } else {
232 ret = sde_format_populate_layout_with_roi(mmu_id, fb, wb_roi,
Alan Kwongbb27c092016-07-20 16:41:25 -0400233 &wb_cfg->dest);
abeykunf1539f72016-08-24 16:08:03 -0400234 if (ret) {
235 /* this error should be detected during atomic_check */
236 SDE_DEBUG("failed to populate layout %d\n", ret);
237 return;
238 }
Alan Kwongbb27c092016-07-20 16:41:25 -0400239 }
240
241 if ((wb_cfg->dest.format->fetch_planes == SDE_PLANE_PLANAR) &&
242 (wb_cfg->dest.format->element[0] == C1_B_Cb))
243 swap(wb_cfg->dest.plane_addr[1], wb_cfg->dest.plane_addr[2]);
244
245 SDE_DEBUG("[fb_offset:%8.8x,%8.8x,%8.8x,%8.8x]\n",
246 wb_cfg->dest.plane_addr[0],
247 wb_cfg->dest.plane_addr[1],
248 wb_cfg->dest.plane_addr[2],
249 wb_cfg->dest.plane_addr[3]);
250 SDE_DEBUG("[fb_stride:%8.8x,%8.8x,%8.8x,%8.8x]\n",
251 wb_cfg->dest.plane_pitch[0],
252 wb_cfg->dest.plane_pitch[1],
253 wb_cfg->dest.plane_pitch[2],
254 wb_cfg->dest.plane_pitch[3]);
255
abeykunf1539f72016-08-24 16:08:03 -0400256 if (hw_wb->ops.setup_roi)
257 hw_wb->ops.setup_roi(hw_wb, wb_cfg);
258
Alan Kwongbb27c092016-07-20 16:41:25 -0400259 if (hw_wb->ops.setup_outformat)
260 hw_wb->ops.setup_outformat(hw_wb, wb_cfg);
261
262 if (hw_wb->ops.setup_outaddress)
263 hw_wb->ops.setup_outaddress(hw_wb, wb_cfg);
264}
265
266/**
267 * sde_encoder_phys_wb_setup_cdp - setup chroma down prefetch block
268 * @phys_enc: Pointer to physical encoder
269 */
270static void sde_encoder_phys_wb_setup_cdp(struct sde_encoder_phys *phys_enc)
271{
272 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
273 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
274 struct sde_hw_intf_cfg *intf_cfg = &wb_enc->intf_cfg;
275
276 memset(intf_cfg, 0, sizeof(struct sde_hw_intf_cfg));
277
278 intf_cfg->intf = SDE_NONE;
279 intf_cfg->wb = hw_wb->idx;
280
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400281 if (phys_enc->hw_ctl && phys_enc->hw_ctl->ops.setup_intf_cfg)
Alan Kwongbb27c092016-07-20 16:41:25 -0400282 phys_enc->hw_ctl->ops.setup_intf_cfg(phys_enc->hw_ctl,
283 intf_cfg);
284}
285
286/**
287 * sde_encoder_phys_wb_atomic_check - verify and fixup given atomic states
288 * @phys_enc: Pointer to physical encoder
289 * @crtc_state: Pointer to CRTC atomic state
290 * @conn_state: Pointer to connector atomic state
291 */
292static int sde_encoder_phys_wb_atomic_check(
293 struct sde_encoder_phys *phys_enc,
294 struct drm_crtc_state *crtc_state,
295 struct drm_connector_state *conn_state)
296{
297 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
298 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
299 const struct sde_wb_cfg *wb_cfg = hw_wb->caps;
300 struct drm_framebuffer *fb;
301 const struct sde_format *fmt;
302 struct sde_rect wb_roi;
303 const struct drm_display_mode *mode = &crtc_state->mode;
304 int rc;
305
306 SDE_DEBUG("[atomic_check:%d,%d,\"%s\",%d,%d]\n",
307 hw_wb->idx - WB_0, mode->base.id, mode->name,
308 mode->hdisplay, mode->vdisplay);
309
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400310 if (!conn_state || !conn_state->connector) {
311 SDE_ERROR("invalid connector state\n");
312 return -EINVAL;
313 } else if (conn_state->connector->status !=
314 connector_status_connected) {
315 SDE_ERROR("connector not connected %d\n",
316 conn_state->connector->status);
317 return -EINVAL;
318 }
319
Alan Kwongbb27c092016-07-20 16:41:25 -0400320 memset(&wb_roi, 0, sizeof(struct sde_rect));
321
322 rc = sde_wb_connector_state_get_output_roi(conn_state, &wb_roi);
323 if (rc) {
324 SDE_ERROR("failed to get roi %d\n", rc);
325 return rc;
326 }
327
328 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi.x, wb_roi.y,
329 wb_roi.w, wb_roi.h);
330
331 fb = sde_wb_connector_state_get_output_fb(conn_state);
332 if (!fb) {
333 SDE_ERROR("no output framebuffer\n");
334 return -EINVAL;
335 }
336
337 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
338 fb->width, fb->height);
339
340 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
341 drm_format_num_planes(fb->pixel_format));
342 if (!fmt) {
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400343 SDE_ERROR("unsupported output pixel format:%x\n",
Alan Kwongbb27c092016-07-20 16:41:25 -0400344 fb->pixel_format);
345 return -EINVAL;
346 }
347
348 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
349 fb->modifier[0]);
350
351 if (SDE_FORMAT_IS_YUV(fmt) &&
352 !(wb_cfg->features & BIT(SDE_WB_YUV_CONFIG))) {
353 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
354 return -EINVAL;
355 }
356
357 if (SDE_FORMAT_IS_UBWC(fmt) &&
358 !(wb_cfg->features & BIT(SDE_WB_UBWC_1_0))) {
359 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
360 return -EINVAL;
361 }
362
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400363 if (SDE_FORMAT_IS_YUV(fmt) != !!phys_enc->hw_cdm)
364 crtc_state->mode_changed = true;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400365
Alan Kwongbb27c092016-07-20 16:41:25 -0400366 if (wb_roi.w && wb_roi.h) {
367 if (wb_roi.w != mode->hdisplay) {
368 SDE_ERROR("invalid roi w=%d, mode w=%d\n", wb_roi.w,
369 mode->hdisplay);
370 return -EINVAL;
371 } else if (wb_roi.h != mode->vdisplay) {
372 SDE_ERROR("invalid roi h=%d, mode h=%d\n", wb_roi.h,
373 mode->vdisplay);
374 return -EINVAL;
375 } else if (wb_roi.x + wb_roi.w > fb->width) {
376 SDE_ERROR("invalid roi x=%d, w=%d, fb w=%d\n",
377 wb_roi.x, wb_roi.w, fb->width);
378 return -EINVAL;
379 } else if (wb_roi.y + wb_roi.h > fb->height) {
380 SDE_ERROR("invalid roi y=%d, h=%d, fb h=%d\n",
381 wb_roi.y, wb_roi.h, fb->height);
382 return -EINVAL;
383 } else if (wb_roi.w > wb_cfg->sblk->maxlinewidth) {
384 SDE_ERROR("invalid roi w=%d, maxlinewidth=%u\n",
385 wb_roi.w, wb_cfg->sblk->maxlinewidth);
386 return -EINVAL;
387 }
388 } else {
389 if (wb_roi.x || wb_roi.y) {
390 SDE_ERROR("invalid roi x=%d, y=%d\n",
391 wb_roi.x, wb_roi.y);
392 return -EINVAL;
393 } else if (fb->width != mode->hdisplay) {
394 SDE_ERROR("invalid fb w=%d, mode w=%d\n", fb->width,
395 mode->hdisplay);
396 return -EINVAL;
397 } else if (fb->height != mode->vdisplay) {
398 SDE_ERROR("invalid fb h=%d, mode h=%d\n", fb->height,
399 mode->vdisplay);
400 return -EINVAL;
401 } else if (fb->width > wb_cfg->sblk->maxlinewidth) {
402 SDE_ERROR("invalid fb w=%d, maxlinewidth=%u\n",
403 fb->width, wb_cfg->sblk->maxlinewidth);
404 return -EINVAL;
405 }
406 }
407
408 return 0;
409}
410
411/**
412 * sde_encoder_phys_wb_flush - flush hardware update
413 * @phys_enc: Pointer to physical encoder
414 */
415static void sde_encoder_phys_wb_flush(struct sde_encoder_phys *phys_enc)
416{
417 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
418 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
419 struct sde_hw_ctl *hw_ctl = phys_enc->hw_ctl;
420 struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
421 u32 flush_mask = 0;
422
423 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
424
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400425 if (!hw_ctl) {
426 SDE_DEBUG("[wb:%d] no ctl assigned\n", hw_wb->idx - WB_0);
427 return;
428 }
429
Alan Kwongbb27c092016-07-20 16:41:25 -0400430 if (hw_ctl->ops.get_bitmask_wb)
431 hw_ctl->ops.get_bitmask_wb(hw_ctl, &flush_mask, hw_wb->idx);
432
433 if (hw_ctl->ops.get_bitmask_cdm && hw_cdm)
434 hw_ctl->ops.get_bitmask_cdm(hw_ctl, &flush_mask, hw_cdm->idx);
435
436 if (hw_ctl->ops.update_pending_flush)
437 hw_ctl->ops.update_pending_flush(hw_ctl, flush_mask);
438
439 SDE_DEBUG("Flushing CTL_ID %d, flush_mask %x, WB %d\n",
440 hw_ctl->idx - CTL_0, flush_mask, hw_wb->idx - WB_0);
441}
442
443/**
444 * sde_encoder_phys_wb_setup - setup writeback encoder
445 * @phys_enc: Pointer to physical encoder
446 */
447static void sde_encoder_phys_wb_setup(
448 struct sde_encoder_phys *phys_enc)
449{
450 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
451 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
452 struct drm_display_mode mode = phys_enc->cached_mode;
453 struct drm_framebuffer *fb;
454 struct sde_rect *wb_roi = &wb_enc->wb_roi;
455
456 SDE_DEBUG("[mode_set:%d,%d,\"%s\",%d,%d]\n",
457 hw_wb->idx - WB_0, mode.base.id, mode.name,
458 mode.hdisplay, mode.vdisplay);
459
460 memset(wb_roi, 0, sizeof(struct sde_rect));
461
462 fb = sde_wb_get_output_fb(wb_enc->wb_dev);
463 if (!fb) {
464 SDE_DEBUG("no output framebuffer\n");
465 return;
466 }
467
468 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
469 fb->width, fb->height);
470
471 sde_wb_get_output_roi(wb_enc->wb_dev, wb_roi);
472 if (wb_roi->w == 0 || wb_roi->h == 0) {
473 wb_roi->x = 0;
474 wb_roi->y = 0;
475 wb_roi->w = fb->width;
476 wb_roi->h = fb->height;
477 }
478
479 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi->x, wb_roi->y,
480 wb_roi->w, wb_roi->h);
481
482 wb_enc->wb_fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
483 drm_format_num_planes(fb->pixel_format));
484 if (!wb_enc->wb_fmt) {
485 SDE_ERROR("unsupported output pixel format: %d\n",
486 fb->pixel_format);
487 return;
488 }
489
490 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
491 fb->modifier[0]);
492
Alan Kwong5d324e42016-07-28 22:56:18 -0400493 sde_encoder_phys_wb_set_ot_limit(phys_enc);
494
Alan Kwongbb27c092016-07-20 16:41:25 -0400495 sde_encoder_phys_wb_set_traffic_shaper(phys_enc);
496
497 sde_encoder_phys_setup_cdm(phys_enc, fb, wb_enc->wb_fmt, wb_roi);
498
499 sde_encoder_phys_wb_setup_fb(phys_enc, fb, wb_roi);
500
501 sde_encoder_phys_wb_setup_cdp(phys_enc);
502}
503
504/**
505 * sde_encoder_phys_wb_unregister_irq - unregister writeback interrupt handler
506 * @phys_enc: Pointer to physical encoder
507 */
508static int sde_encoder_phys_wb_unregister_irq(
509 struct sde_encoder_phys *phys_enc)
510{
511 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
512 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
513
514 if (wb_enc->bypass_irqreg)
515 return 0;
516
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400517 sde_core_irq_disable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
518 sde_core_irq_register_callback(phys_enc->sde_kms, wb_enc->irq_idx,
519 NULL);
Alan Kwongbb27c092016-07-20 16:41:25 -0400520
521 SDE_DEBUG("un-register IRQ for wb %d, irq_idx=%d\n",
522 hw_wb->idx - WB_0,
523 wb_enc->irq_idx);
524
525 return 0;
526}
527
528/**
529 * sde_encoder_phys_wb_done_irq - writeback interrupt handler
530 * @arg: Pointer to writeback encoder
531 * @irq_idx: interrupt index
532 */
533static void sde_encoder_phys_wb_done_irq(void *arg, int irq_idx)
534{
535 struct sde_encoder_phys_wb *wb_enc = arg;
536 struct sde_encoder_phys *phys_enc = &wb_enc->base;
537 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
538
539 SDE_DEBUG("[wb:%d,%u]\n", hw_wb->idx - WB_0,
540 wb_enc->frame_count);
541
542 complete_all(&wb_enc->wbdone_complete);
543
544 phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent);
545}
546
547/**
548 * sde_encoder_phys_wb_register_irq - register writeback interrupt handler
549 * @phys_enc: Pointer to physical encoder
550 */
551static int sde_encoder_phys_wb_register_irq(struct sde_encoder_phys *phys_enc)
552{
553 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
554 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
555 struct sde_irq_callback irq_cb;
556 enum sde_intr_type intr_type;
557 int ret = 0;
558
559 if (wb_enc->bypass_irqreg)
560 return 0;
561
562 intr_type = sde_encoder_phys_wb_get_intr_type(hw_wb);
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400563 wb_enc->irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400564 intr_type, hw_wb->idx);
565 if (wb_enc->irq_idx < 0) {
566 SDE_ERROR(
567 "failed to lookup IRQ index for WB_DONE with wb=%d\n",
568 hw_wb->idx - WB_0);
569 return -EINVAL;
570 }
571
572 irq_cb.func = sde_encoder_phys_wb_done_irq;
573 irq_cb.arg = wb_enc;
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400574 ret = sde_core_irq_register_callback(phys_enc->sde_kms,
575 wb_enc->irq_idx, &irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400576 if (ret) {
577 SDE_ERROR("failed to register IRQ callback WB_DONE\n");
578 return ret;
579 }
580
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400581 ret = sde_core_irq_enable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
Alan Kwongbb27c092016-07-20 16:41:25 -0400582 if (ret) {
583 SDE_ERROR(
584 "failed to enable IRQ for WB_DONE, wb %d, irq_idx=%d\n",
585 hw_wb->idx - WB_0,
586 wb_enc->irq_idx);
587 wb_enc->irq_idx = -EINVAL;
588
589 /* Unregister callback on IRQ enable failure */
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400590 sde_core_irq_register_callback(phys_enc->sde_kms,
591 wb_enc->irq_idx, NULL);
Alan Kwongbb27c092016-07-20 16:41:25 -0400592 return ret;
593 }
594
595 SDE_DEBUG("registered IRQ for wb %d, irq_idx=%d\n",
596 hw_wb->idx - WB_0,
597 wb_enc->irq_idx);
598
599 return ret;
600}
601
602/**
603 * sde_encoder_phys_wb_mode_set - set display mode
604 * @phys_enc: Pointer to physical encoder
605 * @mode: Pointer to requested display mode
606 * @adj_mode: Pointer to adjusted display mode
607 */
608static void sde_encoder_phys_wb_mode_set(
609 struct sde_encoder_phys *phys_enc,
610 struct drm_display_mode *mode,
611 struct drm_display_mode *adj_mode)
612{
613 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400614 struct sde_rm *rm = &phys_enc->sde_kms->rm;
Alan Kwongbb27c092016-07-20 16:41:25 -0400615 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400616 struct sde_rm_hw_iter iter;
617 int i, instance;
Alan Kwongbb27c092016-07-20 16:41:25 -0400618
619 phys_enc->cached_mode = *adj_mode;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400620 instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400621
622 SDE_DEBUG("[mode_set_cache:%d,%d,\"%s\",%d,%d]\n",
623 hw_wb->idx - WB_0, mode->base.id,
624 mode->name, mode->hdisplay, mode->vdisplay);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400625
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400626 phys_enc->hw_ctl = NULL;
627 phys_enc->hw_cdm = NULL;
628
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400629 /* Retrieve previously allocated HW Resources. CTL shouldn't fail */
630 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
631 for (i = 0; i <= instance; i++) {
632 sde_rm_get_hw(rm, &iter);
633 if (i == instance)
634 phys_enc->hw_ctl = (struct sde_hw_ctl *) iter.hw;
635 }
636
637 if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
638 SDE_ERROR("failed init ctl: %ld\n", PTR_ERR(phys_enc->hw_ctl));
639 phys_enc->hw_ctl = NULL;
640 return;
641 }
642
643 /* CDM is optional */
644 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CDM);
645 for (i = 0; i <= instance; i++) {
646 sde_rm_get_hw(rm, &iter);
647 if (i == instance)
648 phys_enc->hw_cdm = (struct sde_hw_cdm *) iter.hw;
649 }
650
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400651 if (IS_ERR(phys_enc->hw_cdm)) {
652 SDE_ERROR("CDM required but not allocated: %ld\n",
653 PTR_ERR(phys_enc->hw_cdm));
654 phys_enc->hw_ctl = NULL;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400655 }
Alan Kwongbb27c092016-07-20 16:41:25 -0400656}
657
658/**
Alan Kwongbb27c092016-07-20 16:41:25 -0400659 * sde_encoder_phys_wb_wait_for_commit_done - wait until request is committed
660 * @phys_enc: Pointer to physical encoder
661 */
662static int sde_encoder_phys_wb_wait_for_commit_done(
663 struct sde_encoder_phys *phys_enc)
664{
665 unsigned long ret;
666 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
667 u32 irq_status;
668 u64 wb_time = 0;
669 int rc = 0;
670
671 /* Return EWOULDBLOCK since we know the wait isn't necessary */
672 if (WARN_ON(phys_enc->enable_state != SDE_ENC_ENABLED))
673 return -EWOULDBLOCK;
674
675 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, 0);
676
677 ret = wait_for_completion_timeout(&wb_enc->wbdone_complete,
678 msecs_to_jiffies(wb_enc->wbdone_timeout));
679
680 if (!ret) {
681 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, 0);
682
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400683 irq_status = sde_core_irq_read(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400684 wb_enc->irq_idx, true);
685 if (irq_status) {
686 SDE_DEBUG("wb:%d done but irq not triggered\n",
687 wb_enc->wb_dev->wb_idx - WB_0);
688 sde_encoder_phys_wb_done_irq(wb_enc, wb_enc->irq_idx);
689 } else {
690 SDE_ERROR("wb:%d kickoff timed out\n",
691 wb_enc->wb_dev->wb_idx - WB_0);
692 rc = -ETIMEDOUT;
693 }
694 }
695
696 sde_encoder_phys_wb_unregister_irq(phys_enc);
697
698 if (!rc)
699 wb_enc->end_time = ktime_get();
700
701 /* once operation is done, disable traffic shaper */
702 if (wb_enc->wb_cfg.ts_cfg.en && wb_enc->hw_wb &&
703 wb_enc->hw_wb->ops.setup_trafficshaper) {
704 wb_enc->wb_cfg.ts_cfg.en = false;
705 wb_enc->hw_wb->ops.setup_trafficshaper(
706 wb_enc->hw_wb, &wb_enc->wb_cfg);
707 }
708
709 /* remove vote for iommu/clk/bus */
710 wb_enc->frame_count++;
711
712 if (!rc) {
713 wb_time = (u64)ktime_to_us(wb_enc->end_time) -
714 (u64)ktime_to_us(wb_enc->start_time);
715 SDE_DEBUG("wb:%d took %llu us\n",
716 wb_enc->wb_dev->wb_idx - WB_0, wb_time);
717 }
718
719 MSM_EVT(DEV(phys_enc), wb_enc->frame_count, wb_time);
720
721 return rc;
722}
723
724/**
725 * sde_encoder_phys_wb_prepare_for_kickoff - pre-kickoff processing
726 * @phys_enc: Pointer to physical encoder
727 * @need_to_wait: Wait for next submission
728 */
729static void sde_encoder_phys_wb_prepare_for_kickoff(
730 struct sde_encoder_phys *phys_enc,
731 bool *need_to_wait)
732{
733 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
734 int ret;
735
736 SDE_DEBUG("[wb:%d,%u]\n", wb_enc->hw_wb->idx - WB_0,
737 wb_enc->kickoff_count);
738
739 *need_to_wait = false;
740
741 reinit_completion(&wb_enc->wbdone_complete);
742
743 ret = sde_encoder_phys_wb_register_irq(phys_enc);
744 if (ret) {
745 SDE_ERROR("failed to register irq %d\n", ret);
746 return;
747 }
748
749 wb_enc->kickoff_count++;
750
751 /* set OT limit & enable traffic shaper */
752 sde_encoder_phys_wb_setup(phys_enc);
753
754 sde_encoder_phys_wb_flush(phys_enc);
755
756 /* vote for iommu/clk/bus */
757 wb_enc->start_time = ktime_get();
758
759 MSM_EVT(DEV(phys_enc), *need_to_wait, wb_enc->kickoff_count);
760}
761
762/**
763 * sde_encoder_phys_wb_handle_post_kickoff - post-kickoff processing
764 * @phys_enc: Pointer to physical encoder
765 */
766static void sde_encoder_phys_wb_handle_post_kickoff(
767 struct sde_encoder_phys *phys_enc)
768{
769 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
770
771 SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0);
772
773 MSM_EVT(DEV(phys_enc), 0, 0);
774}
775
776/**
777 * sde_encoder_phys_wb_enable - enable writeback encoder
778 * @phys_enc: Pointer to physical encoder
779 */
780static void sde_encoder_phys_wb_enable(struct sde_encoder_phys *phys_enc)
781{
782 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
783 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Alan Kwong74e8ba32016-09-30 14:25:16 -0400784 struct drm_device *dev;
Alan Kwongbb27c092016-07-20 16:41:25 -0400785 struct drm_connector *connector;
786
787 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
788
Alan Kwong74e8ba32016-09-30 14:25:16 -0400789 if (!wb_enc->base.parent || !wb_enc->base.parent->dev) {
790 SDE_ERROR("invalid drm device\n");
791 return;
792 }
793 dev = wb_enc->base.parent->dev;
794
Alan Kwongbb27c092016-07-20 16:41:25 -0400795 /* find associated writeback connector */
Alan Kwong74e8ba32016-09-30 14:25:16 -0400796 mutex_lock(&dev->mode_config.mutex);
Alan Kwongbb27c092016-07-20 16:41:25 -0400797 drm_for_each_connector(connector, phys_enc->parent->dev) {
798 if (connector->encoder == phys_enc->parent)
799 break;
800 }
Alan Kwong74e8ba32016-09-30 14:25:16 -0400801 mutex_unlock(&dev->mode_config.mutex);
802
Alan Kwongbb27c092016-07-20 16:41:25 -0400803 if (!connector || connector->encoder != phys_enc->parent) {
804 SDE_ERROR("failed to find writeback connector\n");
805 return;
806 }
807 wb_enc->wb_dev = sde_wb_connector_get_wb(connector);
808
809 phys_enc->enable_state = SDE_ENC_ENABLED;
810}
811
812/**
813 * sde_encoder_phys_wb_disable - disable writeback encoder
814 * @phys_enc: Pointer to physical encoder
815 */
816static void sde_encoder_phys_wb_disable(struct sde_encoder_phys *phys_enc)
817{
818 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
819 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
820
821 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
822
823 if (phys_enc->enable_state == SDE_ENC_DISABLED) {
824 SDE_ERROR("encoder is already disabled\n");
825 return;
826 }
827
828 if (wb_enc->frame_count != wb_enc->kickoff_count) {
829 SDE_DEBUG("[wait_for_done: wb:%d, frame:%u, kickoff:%u]\n",
830 hw_wb->idx - WB_0, wb_enc->frame_count,
831 wb_enc->kickoff_count);
832 sde_encoder_phys_wb_wait_for_commit_done(phys_enc);
833 }
834
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400835 if (phys_enc->hw_cdm && phys_enc->hw_cdm->ops.disable) {
836 SDE_DEBUG_DRIVER("[cdm_disable]\n");
837 phys_enc->hw_cdm->ops.disable(phys_enc->hw_cdm);
838 }
839
Alan Kwongbb27c092016-07-20 16:41:25 -0400840 phys_enc->enable_state = SDE_ENC_DISABLED;
841}
842
843/**
844 * sde_encoder_phys_wb_get_hw_resources - get hardware resources
845 * @phys_enc: Pointer to physical encoder
846 * @hw_res: Pointer to encoder resources
847 */
848static void sde_encoder_phys_wb_get_hw_resources(
849 struct sde_encoder_phys *phys_enc,
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400850 struct sde_encoder_hw_resources *hw_res,
851 struct drm_connector_state *conn_state)
Alan Kwongbb27c092016-07-20 16:41:25 -0400852{
853 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400854 struct sde_hw_wb *hw_wb;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400855 struct drm_framebuffer *fb;
856 const struct sde_format *fmt;
Alan Kwongbb27c092016-07-20 16:41:25 -0400857
Clarence Ip03521982016-08-26 10:49:47 -0400858 if (!phys_enc) {
859 SDE_ERROR("invalid encoder\n");
860 return;
861 }
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400862
863 fb = sde_wb_connector_state_get_output_fb(conn_state);
864 if (!fb) {
865 SDE_ERROR("no output framebuffer\n");
866 return;
867 }
868
869 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
870 drm_format_num_planes(fb->pixel_format));
871 if (!fmt) {
872 SDE_ERROR("unsupported output pixel format:%d\n",
873 fb->pixel_format);
874 return;
875 }
876
Clarence Ip03521982016-08-26 10:49:47 -0400877 hw_wb = wb_enc->hw_wb;
Clarence Ip03521982016-08-26 10:49:47 -0400878 hw_res->wbs[hw_wb->idx - WB_0] = phys_enc->intf_mode;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400879 hw_res->needs_cdm = SDE_FORMAT_IS_YUV(fmt);
880 SDE_DEBUG("[wb:%d] intf_mode=%d needs_cdm=%d\n", hw_wb->idx - WB_0,
881 hw_res->wbs[hw_wb->idx - WB_0],
882 hw_res->needs_cdm);
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400883}
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400884
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400885/**
886 * sde_encoder_phys_wb_needs_ctl_start - Whether encoder needs ctl_start
887 * @phys_enc: Pointer to physical encoder
888 * @Return: Whether encoder needs ctl_start
889 */
890static bool sde_encoder_phys_wb_needs_ctl_start(
891 struct sde_encoder_phys *phys_enc)
892{
893 return true;
Alan Kwongbb27c092016-07-20 16:41:25 -0400894}
895
896#ifdef CONFIG_DEBUG_FS
897/**
898 * sde_encoder_phys_wb_init_debugfs - initialize writeback encoder debugfs
899 * @phys_enc: Pointer to physical encoder
900 * @sde_kms: Pointer to SDE KMS object
901 */
902static int sde_encoder_phys_wb_init_debugfs(
903 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
904{
905 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
906
907 if (!phys_enc || !kms || !wb_enc->hw_wb)
908 return -EINVAL;
909
910 snprintf(wb_enc->wb_name, ARRAY_SIZE(wb_enc->wb_name), "encoder_wb%d",
911 wb_enc->hw_wb->idx - WB_0);
912
913 wb_enc->debugfs_root =
914 debugfs_create_dir(wb_enc->wb_name,
915 sde_debugfs_get_root(kms));
916 if (!wb_enc->debugfs_root) {
917 SDE_ERROR("failed to create debugfs\n");
918 return -ENOMEM;
919 }
920
921 if (!debugfs_create_u32("wbdone_timeout", 0644,
922 wb_enc->debugfs_root, &wb_enc->wbdone_timeout)) {
923 SDE_ERROR("failed to create debugfs/wbdone_timeout\n");
924 return -ENOMEM;
925 }
926
927 if (!debugfs_create_u32("bypass_irqreg", 0644,
928 wb_enc->debugfs_root, &wb_enc->bypass_irqreg)) {
929 SDE_ERROR("failed to create debugfs/bypass_irqreg\n");
930 return -ENOMEM;
931 }
932
933 return 0;
934}
935
936/**
937 * sde_encoder_phys_wb_destroy_debugfs - destroy writeback encoder debugfs
938 * @phys_enc: Pointer to physical encoder
939 */
940static void sde_encoder_phys_wb_destroy_debugfs(
941 struct sde_encoder_phys *phys_enc)
942{
943 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
944
945 if (!phys_enc)
946 return;
947
948 debugfs_remove_recursive(wb_enc->debugfs_root);
949}
950#else
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700951static int sde_encoder_phys_wb_init_debugfs(
Alan Kwongbb27c092016-07-20 16:41:25 -0400952 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
953{
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700954 return 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400955}
956static void sde_encoder_phys_wb_destroy_debugfs(
957 struct sde_encoder_phys *phys_enc)
958{
959}
960#endif
961
962/**
963 * sde_encoder_phys_wb_destroy - destroy writeback encoder
964 * @phys_enc: Pointer to physical encoder
965 */
966static void sde_encoder_phys_wb_destroy(struct sde_encoder_phys *phys_enc)
967{
968 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
969 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
970
971 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
972
973 if (!phys_enc)
974 return;
975
976 sde_encoder_phys_wb_destroy_debugfs(phys_enc);
977
Alan Kwongbb27c092016-07-20 16:41:25 -0400978 kfree(wb_enc);
979}
980
981/**
982 * sde_encoder_phys_wb_init_ops - initialize writeback operations
983 * @ops: Pointer to encoder operation table
984 */
985static void sde_encoder_phys_wb_init_ops(struct sde_encoder_phys_ops *ops)
986{
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400987 ops->is_master = sde_encoder_phys_wb_is_master;
Alan Kwongbb27c092016-07-20 16:41:25 -0400988 ops->mode_set = sde_encoder_phys_wb_mode_set;
989 ops->enable = sde_encoder_phys_wb_enable;
990 ops->disable = sde_encoder_phys_wb_disable;
991 ops->destroy = sde_encoder_phys_wb_destroy;
992 ops->atomic_check = sde_encoder_phys_wb_atomic_check;
993 ops->get_hw_resources = sde_encoder_phys_wb_get_hw_resources;
Alan Kwongbb27c092016-07-20 16:41:25 -0400994 ops->wait_for_commit_done = sde_encoder_phys_wb_wait_for_commit_done;
995 ops->prepare_for_kickoff = sde_encoder_phys_wb_prepare_for_kickoff;
996 ops->handle_post_kickoff = sde_encoder_phys_wb_handle_post_kickoff;
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400997 ops->needs_ctl_start = sde_encoder_phys_wb_needs_ctl_start;
Alan Kwongbb27c092016-07-20 16:41:25 -0400998}
999
1000/**
1001 * sde_encoder_phys_wb_init - initialize writeback encoder
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001002 * @init: Pointer to init info structure with initialization params
Alan Kwongbb27c092016-07-20 16:41:25 -04001003 */
1004struct sde_encoder_phys *sde_encoder_phys_wb_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001005 struct sde_enc_phys_init_params *p)
Alan Kwongbb27c092016-07-20 16:41:25 -04001006{
1007 struct sde_encoder_phys *phys_enc;
1008 struct sde_encoder_phys_wb *wb_enc;
1009 struct sde_hw_mdp *hw_mdp;
1010 int ret = 0;
1011
1012 SDE_DEBUG("\n");
1013
1014 wb_enc = kzalloc(sizeof(*wb_enc), GFP_KERNEL);
1015 if (!wb_enc) {
1016 ret = -ENOMEM;
1017 goto fail_alloc;
1018 }
1019 wb_enc->irq_idx = -EINVAL;
1020 wb_enc->wbdone_timeout = WAIT_TIMEOUT_MSEC;
1021 init_completion(&wb_enc->wbdone_complete);
1022
1023 phys_enc = &wb_enc->base;
1024
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001025 if (p->sde_kms->vbif[VBIF_NRT]) {
Alan Kwongbb27c092016-07-20 16:41:25 -04001026 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001027 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001028 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001029 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001030 } else {
1031 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001032 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001033 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001034 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001035 }
1036
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001037 hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
Alan Kwongbb27c092016-07-20 16:41:25 -04001038 if (IS_ERR_OR_NULL(hw_mdp)) {
1039 ret = PTR_ERR(hw_mdp);
1040 SDE_ERROR("failed to init hw_top: %d\n", ret);
1041 goto fail_mdp_init;
1042 }
1043 phys_enc->hw_mdptop = hw_mdp;
1044
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001045 /**
1046 * hw_wb resource permanently assigned to this encoder
1047 * Other resources allocated at atomic commit time by use case
1048 */
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001049 if (p->wb_idx != SDE_NONE) {
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001050 struct sde_rm_hw_iter iter;
Alan Kwongbb27c092016-07-20 16:41:25 -04001051
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001052 sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_WB);
1053 while (sde_rm_get_hw(&p->sde_kms->rm, &iter)) {
1054 struct sde_hw_wb *hw_wb = (struct sde_hw_wb *)iter.hw;
1055
1056 if (hw_wb->idx == p->wb_idx) {
1057 wb_enc->hw_wb = hw_wb;
1058 break;
1059 }
1060 }
1061
1062 if (!wb_enc->hw_wb) {
1063 ret = -EINVAL;
1064 SDE_ERROR("failed to init hw_wb%d\n", p->wb_idx - WB_0);
Alan Kwongbb27c092016-07-20 16:41:25 -04001065 goto fail_wb_init;
1066 }
Alan Kwongbb27c092016-07-20 16:41:25 -04001067 } else {
1068 ret = -EINVAL;
1069 SDE_ERROR("invalid wb_idx\n");
1070 goto fail_wb_check;
1071 }
1072
Alan Kwongbb27c092016-07-20 16:41:25 -04001073 sde_encoder_phys_wb_init_ops(&phys_enc->ops);
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001074 phys_enc->parent = p->parent;
1075 phys_enc->parent_ops = p->parent_ops;
1076 phys_enc->sde_kms = p->sde_kms;
1077 phys_enc->split_role = p->split_role;
Clarence Ip03521982016-08-26 10:49:47 -04001078 phys_enc->intf_mode = INTF_MODE_WB_LINE;
Alan Kwongbb27c092016-07-20 16:41:25 -04001079 spin_lock_init(&phys_enc->spin_lock);
1080
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001081 ret = sde_encoder_phys_wb_init_debugfs(phys_enc, p->sde_kms);
Alan Kwongbb27c092016-07-20 16:41:25 -04001082 if (ret) {
1083 SDE_ERROR("failed to init debugfs %d\n", ret);
1084 goto fail_debugfs_init;
1085 }
1086
1087 SDE_DEBUG("Created sde_encoder_phys_wb for wb %d\n",
1088 wb_enc->hw_wb->idx - WB_0);
1089
1090 return phys_enc;
1091
1092fail_debugfs_init:
Alan Kwongbb27c092016-07-20 16:41:25 -04001093fail_wb_init:
1094fail_wb_check:
Alan Kwongbb27c092016-07-20 16:41:25 -04001095fail_mdp_init:
1096 kfree(wb_enc);
1097fail_alloc:
1098 return ERR_PTR(ret);
1099}
1100