blob: 3aa4e16e53d82ce449840c6986d0f43d842236cc [file] [log] [blame]
Alan Kwongbb27c092016-07-20 16:41:25 -04001/*
Lloyd Atkinson8772e202016-09-26 17:52:16 -04002 * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved.
Alan Kwongbb27c092016-07-20 16:41:25 -04003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
Alan Kwong4c3cf4c2016-09-25 20:08:09 -040015#define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
Alan Kwongbb27c092016-07-20 16:41:25 -040016#include <linux/debugfs.h>
17
18#include "sde_encoder_phys.h"
19#include "sde_formats.h"
20#include "sde_hw_top.h"
21#include "sde_hw_interrupts.h"
Alan Kwongf5dd86c2016-08-09 18:08:17 -040022#include "sde_core_irq.h"
Alan Kwongbb27c092016-07-20 16:41:25 -040023#include "sde_wb.h"
Lloyd Atkinson8772e202016-09-26 17:52:16 -040024#include "sde_vbif.h"
Alan Kwongbb27c092016-07-20 16:41:25 -040025
Alan Kwongbb27c092016-07-20 16:41:25 -040026#define to_sde_encoder_phys_wb(x) \
27 container_of(x, struct sde_encoder_phys_wb, base)
28
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040029#define WBID(wb_enc) ((wb_enc) ? wb_enc->wb_dev->wb_idx : -1)
Alan Kwongbb27c092016-07-20 16:41:25 -040030
31/**
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -040032 * sde_encoder_phys_wb_is_master - report wb always as master encoder
33 */
34static bool sde_encoder_phys_wb_is_master(struct sde_encoder_phys *phys_enc)
35{
36 return true;
37}
38
39/**
Alan Kwongbb27c092016-07-20 16:41:25 -040040 * sde_encoder_phys_wb_get_intr_type - get interrupt type based on block mode
41 * @hw_wb: Pointer to h/w writeback driver
42 */
43static enum sde_intr_type sde_encoder_phys_wb_get_intr_type(
44 struct sde_hw_wb *hw_wb)
45{
46 return (hw_wb->caps->features & BIT(SDE_WB_BLOCK_MODE)) ?
47 SDE_IRQ_TYPE_WB_ROT_COMP : SDE_IRQ_TYPE_WB_WFD_COMP;
48}
49
50/**
Alan Kwong5d324e42016-07-28 22:56:18 -040051 * sde_encoder_phys_wb_set_ot_limit - set OT limit for writeback interface
52 * @phys_enc: Pointer to physical encoder
53 */
54static void sde_encoder_phys_wb_set_ot_limit(
55 struct sde_encoder_phys *phys_enc)
56{
57 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
58 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
59 struct sde_vbif_set_ot_params ot_params;
60
61 memset(&ot_params, 0, sizeof(ot_params));
62 ot_params.xin_id = hw_wb->caps->xin_id;
63 ot_params.num = hw_wb->idx - WB_0;
64 ot_params.width = wb_enc->wb_roi.w;
65 ot_params.height = wb_enc->wb_roi.h;
66 ot_params.is_wfd = true;
67 ot_params.frame_rate = phys_enc->cached_mode.vrefresh;
68 ot_params.vbif_idx = hw_wb->caps->vbif_idx;
69 ot_params.clk_ctrl = hw_wb->caps->clk_ctrl;
70 ot_params.rd = false;
71
72 sde_vbif_set_ot_limit(phys_enc->sde_kms, &ot_params);
73}
74
75/**
Alan Kwongbb27c092016-07-20 16:41:25 -040076 * sde_encoder_phys_wb_set_traffic_shaper - set traffic shaper for writeback
77 * @phys_enc: Pointer to physical encoder
78 */
79static void sde_encoder_phys_wb_set_traffic_shaper(
80 struct sde_encoder_phys *phys_enc)
81{
82 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
83 struct sde_hw_wb_cfg *wb_cfg = &wb_enc->wb_cfg;
84
85 /* traffic shaper is only enabled for rotator */
86 wb_cfg->ts_cfg.en = false;
87}
88
89/**
90 * sde_encoder_phys_setup_cdm - setup chroma down block
91 * @phys_enc: Pointer to physical encoder
92 * @fb: Pointer to output framebuffer
93 * @format: Output format
94 */
95void sde_encoder_phys_setup_cdm(struct sde_encoder_phys *phys_enc,
96 struct drm_framebuffer *fb, const struct sde_format *format,
97 struct sde_rect *wb_roi)
98{
99 struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
100 struct sde_hw_cdm_cfg *cdm_cfg = &phys_enc->cdm_cfg;
101 int ret;
102
103 if (!SDE_FORMAT_IS_YUV(format)) {
104 SDE_DEBUG("[cdm_disable fmt:%x]\n",
105 format->base.pixel_format);
106
107 if (hw_cdm && hw_cdm->ops.disable)
108 hw_cdm->ops.disable(hw_cdm);
109
110 return;
111 }
112
113 memset(cdm_cfg, 0, sizeof(struct sde_hw_cdm_cfg));
114
115 cdm_cfg->output_width = wb_roi->w;
116 cdm_cfg->output_height = wb_roi->h;
117 cdm_cfg->output_fmt = format;
118 cdm_cfg->output_type = CDM_CDWN_OUTPUT_WB;
abeykun5ed42e12016-08-24 17:09:26 -0400119 cdm_cfg->output_bit_depth = SDE_FORMAT_IS_DX(format) ?
120 CDM_CDWN_OUTPUT_10BIT : CDM_CDWN_OUTPUT_8BIT;
Alan Kwongbb27c092016-07-20 16:41:25 -0400121
122 /* enable 10 bit logic */
123 switch (cdm_cfg->output_fmt->chroma_sample) {
124 case SDE_CHROMA_RGB:
125 cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
126 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
127 break;
128 case SDE_CHROMA_H2V1:
129 cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
130 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
131 break;
132 case SDE_CHROMA_420:
133 cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
134 cdm_cfg->v_cdwn_type = CDM_CDWN_OFFSITE;
135 break;
136 case SDE_CHROMA_H1V2:
137 default:
138 SDE_ERROR("unsupported chroma sampling type\n");
139 cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
140 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
141 break;
142 }
143
144 SDE_DEBUG("[cdm_enable:%d,%d,%X,%d,%d,%d,%d]\n",
145 cdm_cfg->output_width,
146 cdm_cfg->output_height,
147 cdm_cfg->output_fmt->base.pixel_format,
148 cdm_cfg->output_type,
149 cdm_cfg->output_bit_depth,
150 cdm_cfg->h_cdwn_type,
151 cdm_cfg->v_cdwn_type);
152
153 if (hw_cdm && hw_cdm->ops.setup_cdwn) {
154 ret = hw_cdm->ops.setup_cdwn(hw_cdm, cdm_cfg);
155 if (ret < 0) {
156 SDE_ERROR("failed to setup CDM %d\n", ret);
157 return;
158 }
159 }
160
161 if (hw_cdm && hw_cdm->ops.enable) {
162 ret = hw_cdm->ops.enable(hw_cdm, cdm_cfg);
163 if (ret < 0) {
164 SDE_ERROR("failed to enable CDM %d\n", ret);
165 return;
166 }
167 }
168}
169
170/**
171 * sde_encoder_phys_wb_setup_fb - setup output framebuffer
172 * @phys_enc: Pointer to physical encoder
173 * @fb: Pointer to output framebuffer
174 * @wb_roi: Pointer to output region of interest
175 */
176static void sde_encoder_phys_wb_setup_fb(struct sde_encoder_phys *phys_enc,
177 struct drm_framebuffer *fb, struct sde_rect *wb_roi)
178{
179 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400180 struct sde_hw_wb *hw_wb;
181 struct sde_hw_wb_cfg *wb_cfg;
Alan Kwongbb27c092016-07-20 16:41:25 -0400182 const struct msm_format *format;
183 int ret, mmu_id;
184
Clarence Ip03521982016-08-26 10:49:47 -0400185 if (!phys_enc) {
186 SDE_ERROR("invalid encoder\n");
187 return;
188 }
189
190 hw_wb = wb_enc->hw_wb;
191 wb_cfg = &wb_enc->wb_cfg;
Alan Kwongbb27c092016-07-20 16:41:25 -0400192 memset(wb_cfg, 0, sizeof(struct sde_hw_wb_cfg));
193
Clarence Ip03521982016-08-26 10:49:47 -0400194 wb_cfg->intf_mode = phys_enc->intf_mode;
Alan Kwongbb27c092016-07-20 16:41:25 -0400195 wb_cfg->is_secure = (fb->flags & DRM_MODE_FB_SECURE) ? true : false;
196 mmu_id = (wb_cfg->is_secure) ?
197 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] :
198 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE];
199
200 SDE_DEBUG("[fb_secure:%d]\n", wb_cfg->is_secure);
201
202 format = msm_framebuffer_format(fb);
Dhaval Patelccbcb3d2016-08-22 11:58:14 -0700203 if (!format) {
204 SDE_DEBUG("invalid format for fb\n");
205 return;
206 }
207
Alan Kwongbb27c092016-07-20 16:41:25 -0400208 wb_cfg->dest.format = sde_get_sde_format_ext(
209 format->pixel_format,
210 fb->modifier,
211 drm_format_num_planes(fb->pixel_format));
212 if (!wb_cfg->dest.format) {
213 /* this error should be detected during atomic_check */
214 SDE_ERROR("failed to get format %x\n", format->pixel_format);
215 return;
216 }
abeykunf1539f72016-08-24 16:08:03 -0400217 wb_cfg->roi = *wb_roi;
Alan Kwongbb27c092016-07-20 16:41:25 -0400218
abeykunf1539f72016-08-24 16:08:03 -0400219 if (hw_wb->caps->features & BIT(SDE_WB_XY_ROI_OFFSET)) {
220 ret = sde_format_populate_layout(mmu_id, fb, &wb_cfg->dest);
221 if (ret) {
222 SDE_DEBUG("failed to populate layout %d\n", ret);
223 return;
224 }
225 wb_cfg->dest.width = fb->width;
226 wb_cfg->dest.height = fb->height;
227 wb_cfg->dest.num_planes = wb_cfg->dest.format->num_planes;
228 } else {
229 ret = sde_format_populate_layout_with_roi(mmu_id, fb, wb_roi,
Alan Kwongbb27c092016-07-20 16:41:25 -0400230 &wb_cfg->dest);
abeykunf1539f72016-08-24 16:08:03 -0400231 if (ret) {
232 /* this error should be detected during atomic_check */
233 SDE_DEBUG("failed to populate layout %d\n", ret);
234 return;
235 }
Alan Kwongbb27c092016-07-20 16:41:25 -0400236 }
237
238 if ((wb_cfg->dest.format->fetch_planes == SDE_PLANE_PLANAR) &&
239 (wb_cfg->dest.format->element[0] == C1_B_Cb))
240 swap(wb_cfg->dest.plane_addr[1], wb_cfg->dest.plane_addr[2]);
241
242 SDE_DEBUG("[fb_offset:%8.8x,%8.8x,%8.8x,%8.8x]\n",
243 wb_cfg->dest.plane_addr[0],
244 wb_cfg->dest.plane_addr[1],
245 wb_cfg->dest.plane_addr[2],
246 wb_cfg->dest.plane_addr[3]);
247 SDE_DEBUG("[fb_stride:%8.8x,%8.8x,%8.8x,%8.8x]\n",
248 wb_cfg->dest.plane_pitch[0],
249 wb_cfg->dest.plane_pitch[1],
250 wb_cfg->dest.plane_pitch[2],
251 wb_cfg->dest.plane_pitch[3]);
252
abeykunf1539f72016-08-24 16:08:03 -0400253 if (hw_wb->ops.setup_roi)
254 hw_wb->ops.setup_roi(hw_wb, wb_cfg);
255
Alan Kwongbb27c092016-07-20 16:41:25 -0400256 if (hw_wb->ops.setup_outformat)
257 hw_wb->ops.setup_outformat(hw_wb, wb_cfg);
258
259 if (hw_wb->ops.setup_outaddress)
260 hw_wb->ops.setup_outaddress(hw_wb, wb_cfg);
261}
262
263/**
264 * sde_encoder_phys_wb_setup_cdp - setup chroma down prefetch block
265 * @phys_enc: Pointer to physical encoder
266 */
267static void sde_encoder_phys_wb_setup_cdp(struct sde_encoder_phys *phys_enc)
268{
269 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
270 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
271 struct sde_hw_intf_cfg *intf_cfg = &wb_enc->intf_cfg;
272
273 memset(intf_cfg, 0, sizeof(struct sde_hw_intf_cfg));
274
275 intf_cfg->intf = SDE_NONE;
276 intf_cfg->wb = hw_wb->idx;
Lloyd Atkinson55987b02016-08-16 16:57:46 -0400277 intf_cfg->mode_3d = sde_encoder_helper_get_3d_blend_mode(phys_enc);
Alan Kwongbb27c092016-07-20 16:41:25 -0400278
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400279 if (phys_enc->hw_ctl && phys_enc->hw_ctl->ops.setup_intf_cfg)
Alan Kwongbb27c092016-07-20 16:41:25 -0400280 phys_enc->hw_ctl->ops.setup_intf_cfg(phys_enc->hw_ctl,
281 intf_cfg);
282}
283
284/**
285 * sde_encoder_phys_wb_atomic_check - verify and fixup given atomic states
286 * @phys_enc: Pointer to physical encoder
287 * @crtc_state: Pointer to CRTC atomic state
288 * @conn_state: Pointer to connector atomic state
289 */
290static int sde_encoder_phys_wb_atomic_check(
291 struct sde_encoder_phys *phys_enc,
292 struct drm_crtc_state *crtc_state,
293 struct drm_connector_state *conn_state)
294{
295 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
296 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
297 const struct sde_wb_cfg *wb_cfg = hw_wb->caps;
298 struct drm_framebuffer *fb;
299 const struct sde_format *fmt;
300 struct sde_rect wb_roi;
301 const struct drm_display_mode *mode = &crtc_state->mode;
302 int rc;
303
304 SDE_DEBUG("[atomic_check:%d,%d,\"%s\",%d,%d]\n",
305 hw_wb->idx - WB_0, mode->base.id, mode->name,
306 mode->hdisplay, mode->vdisplay);
307
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400308 if (!conn_state || !conn_state->connector) {
309 SDE_ERROR("invalid connector state\n");
310 return -EINVAL;
311 } else if (conn_state->connector->status !=
312 connector_status_connected) {
313 SDE_ERROR("connector not connected %d\n",
314 conn_state->connector->status);
315 return -EINVAL;
316 }
317
Alan Kwongbb27c092016-07-20 16:41:25 -0400318 memset(&wb_roi, 0, sizeof(struct sde_rect));
319
320 rc = sde_wb_connector_state_get_output_roi(conn_state, &wb_roi);
321 if (rc) {
322 SDE_ERROR("failed to get roi %d\n", rc);
323 return rc;
324 }
325
326 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi.x, wb_roi.y,
327 wb_roi.w, wb_roi.h);
328
329 fb = sde_wb_connector_state_get_output_fb(conn_state);
330 if (!fb) {
331 SDE_ERROR("no output framebuffer\n");
332 return -EINVAL;
333 }
334
335 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
336 fb->width, fb->height);
337
338 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
339 drm_format_num_planes(fb->pixel_format));
340 if (!fmt) {
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400341 SDE_ERROR("unsupported output pixel format:%x\n",
Alan Kwongbb27c092016-07-20 16:41:25 -0400342 fb->pixel_format);
343 return -EINVAL;
344 }
345
346 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
347 fb->modifier[0]);
348
349 if (SDE_FORMAT_IS_YUV(fmt) &&
350 !(wb_cfg->features & BIT(SDE_WB_YUV_CONFIG))) {
351 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
352 return -EINVAL;
353 }
354
355 if (SDE_FORMAT_IS_UBWC(fmt) &&
356 !(wb_cfg->features & BIT(SDE_WB_UBWC_1_0))) {
357 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
358 return -EINVAL;
359 }
360
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400361 if (SDE_FORMAT_IS_YUV(fmt) != !!phys_enc->hw_cdm)
362 crtc_state->mode_changed = true;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400363
Alan Kwongbb27c092016-07-20 16:41:25 -0400364 if (wb_roi.w && wb_roi.h) {
365 if (wb_roi.w != mode->hdisplay) {
366 SDE_ERROR("invalid roi w=%d, mode w=%d\n", wb_roi.w,
367 mode->hdisplay);
368 return -EINVAL;
369 } else if (wb_roi.h != mode->vdisplay) {
370 SDE_ERROR("invalid roi h=%d, mode h=%d\n", wb_roi.h,
371 mode->vdisplay);
372 return -EINVAL;
373 } else if (wb_roi.x + wb_roi.w > fb->width) {
374 SDE_ERROR("invalid roi x=%d, w=%d, fb w=%d\n",
375 wb_roi.x, wb_roi.w, fb->width);
376 return -EINVAL;
377 } else if (wb_roi.y + wb_roi.h > fb->height) {
378 SDE_ERROR("invalid roi y=%d, h=%d, fb h=%d\n",
379 wb_roi.y, wb_roi.h, fb->height);
380 return -EINVAL;
381 } else if (wb_roi.w > wb_cfg->sblk->maxlinewidth) {
382 SDE_ERROR("invalid roi w=%d, maxlinewidth=%u\n",
383 wb_roi.w, wb_cfg->sblk->maxlinewidth);
384 return -EINVAL;
385 }
386 } else {
387 if (wb_roi.x || wb_roi.y) {
388 SDE_ERROR("invalid roi x=%d, y=%d\n",
389 wb_roi.x, wb_roi.y);
390 return -EINVAL;
391 } else if (fb->width != mode->hdisplay) {
392 SDE_ERROR("invalid fb w=%d, mode w=%d\n", fb->width,
393 mode->hdisplay);
394 return -EINVAL;
395 } else if (fb->height != mode->vdisplay) {
396 SDE_ERROR("invalid fb h=%d, mode h=%d\n", fb->height,
397 mode->vdisplay);
398 return -EINVAL;
399 } else if (fb->width > wb_cfg->sblk->maxlinewidth) {
400 SDE_ERROR("invalid fb w=%d, maxlinewidth=%u\n",
401 fb->width, wb_cfg->sblk->maxlinewidth);
402 return -EINVAL;
403 }
404 }
405
406 return 0;
407}
408
409/**
410 * sde_encoder_phys_wb_flush - flush hardware update
411 * @phys_enc: Pointer to physical encoder
412 */
413static void sde_encoder_phys_wb_flush(struct sde_encoder_phys *phys_enc)
414{
415 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
416 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
417 struct sde_hw_ctl *hw_ctl = phys_enc->hw_ctl;
418 struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
419 u32 flush_mask = 0;
420
421 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
422
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400423 if (!hw_ctl) {
424 SDE_DEBUG("[wb:%d] no ctl assigned\n", hw_wb->idx - WB_0);
425 return;
426 }
427
Alan Kwongbb27c092016-07-20 16:41:25 -0400428 if (hw_ctl->ops.get_bitmask_wb)
429 hw_ctl->ops.get_bitmask_wb(hw_ctl, &flush_mask, hw_wb->idx);
430
431 if (hw_ctl->ops.get_bitmask_cdm && hw_cdm)
432 hw_ctl->ops.get_bitmask_cdm(hw_ctl, &flush_mask, hw_cdm->idx);
433
434 if (hw_ctl->ops.update_pending_flush)
435 hw_ctl->ops.update_pending_flush(hw_ctl, flush_mask);
436
437 SDE_DEBUG("Flushing CTL_ID %d, flush_mask %x, WB %d\n",
438 hw_ctl->idx - CTL_0, flush_mask, hw_wb->idx - WB_0);
439}
440
441/**
442 * sde_encoder_phys_wb_setup - setup writeback encoder
443 * @phys_enc: Pointer to physical encoder
444 */
445static void sde_encoder_phys_wb_setup(
446 struct sde_encoder_phys *phys_enc)
447{
448 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
449 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
450 struct drm_display_mode mode = phys_enc->cached_mode;
451 struct drm_framebuffer *fb;
452 struct sde_rect *wb_roi = &wb_enc->wb_roi;
453
454 SDE_DEBUG("[mode_set:%d,%d,\"%s\",%d,%d]\n",
455 hw_wb->idx - WB_0, mode.base.id, mode.name,
456 mode.hdisplay, mode.vdisplay);
457
458 memset(wb_roi, 0, sizeof(struct sde_rect));
459
460 fb = sde_wb_get_output_fb(wb_enc->wb_dev);
461 if (!fb) {
462 SDE_DEBUG("no output framebuffer\n");
463 return;
464 }
465
466 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
467 fb->width, fb->height);
468
469 sde_wb_get_output_roi(wb_enc->wb_dev, wb_roi);
470 if (wb_roi->w == 0 || wb_roi->h == 0) {
471 wb_roi->x = 0;
472 wb_roi->y = 0;
473 wb_roi->w = fb->width;
474 wb_roi->h = fb->height;
475 }
476
477 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi->x, wb_roi->y,
478 wb_roi->w, wb_roi->h);
479
480 wb_enc->wb_fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
481 drm_format_num_planes(fb->pixel_format));
482 if (!wb_enc->wb_fmt) {
483 SDE_ERROR("unsupported output pixel format: %d\n",
484 fb->pixel_format);
485 return;
486 }
487
488 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
489 fb->modifier[0]);
490
Alan Kwong5d324e42016-07-28 22:56:18 -0400491 sde_encoder_phys_wb_set_ot_limit(phys_enc);
492
Alan Kwongbb27c092016-07-20 16:41:25 -0400493 sde_encoder_phys_wb_set_traffic_shaper(phys_enc);
494
495 sde_encoder_phys_setup_cdm(phys_enc, fb, wb_enc->wb_fmt, wb_roi);
496
497 sde_encoder_phys_wb_setup_fb(phys_enc, fb, wb_roi);
498
499 sde_encoder_phys_wb_setup_cdp(phys_enc);
500}
501
502/**
503 * sde_encoder_phys_wb_unregister_irq - unregister writeback interrupt handler
504 * @phys_enc: Pointer to physical encoder
505 */
506static int sde_encoder_phys_wb_unregister_irq(
507 struct sde_encoder_phys *phys_enc)
508{
509 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
510 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
511
512 if (wb_enc->bypass_irqreg)
513 return 0;
514
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400515 sde_core_irq_disable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
Alan Kwonga172ef52016-09-27 00:29:10 -0400516 sde_core_irq_unregister_callback(phys_enc->sde_kms, wb_enc->irq_idx,
517 &wb_enc->irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400518
519 SDE_DEBUG("un-register IRQ for wb %d, irq_idx=%d\n",
520 hw_wb->idx - WB_0,
521 wb_enc->irq_idx);
522
523 return 0;
524}
525
526/**
527 * sde_encoder_phys_wb_done_irq - writeback interrupt handler
528 * @arg: Pointer to writeback encoder
529 * @irq_idx: interrupt index
530 */
531static void sde_encoder_phys_wb_done_irq(void *arg, int irq_idx)
532{
533 struct sde_encoder_phys_wb *wb_enc = arg;
534 struct sde_encoder_phys *phys_enc = &wb_enc->base;
535 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
536
537 SDE_DEBUG("[wb:%d,%u]\n", hw_wb->idx - WB_0,
538 wb_enc->frame_count);
539
Alan Kwong628d19e2016-10-31 13:50:13 -0400540 if (phys_enc->parent_ops.handle_frame_done)
541 phys_enc->parent_ops.handle_frame_done(phys_enc->parent,
542 phys_enc, SDE_ENCODER_FRAME_EVENT_DONE);
Alan Kwongbb27c092016-07-20 16:41:25 -0400543
Dhaval Patel81e87882016-10-19 21:41:56 -0700544 phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent,
545 phys_enc);
Alan Kwong628d19e2016-10-31 13:50:13 -0400546
547 complete_all(&wb_enc->wbdone_complete);
Alan Kwongbb27c092016-07-20 16:41:25 -0400548}
549
550/**
551 * sde_encoder_phys_wb_register_irq - register writeback interrupt handler
552 * @phys_enc: Pointer to physical encoder
553 */
554static int sde_encoder_phys_wb_register_irq(struct sde_encoder_phys *phys_enc)
555{
556 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
557 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Alan Kwonga172ef52016-09-27 00:29:10 -0400558 struct sde_irq_callback *irq_cb = &wb_enc->irq_cb;
Alan Kwongbb27c092016-07-20 16:41:25 -0400559 enum sde_intr_type intr_type;
560 int ret = 0;
561
562 if (wb_enc->bypass_irqreg)
563 return 0;
564
565 intr_type = sde_encoder_phys_wb_get_intr_type(hw_wb);
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400566 wb_enc->irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400567 intr_type, hw_wb->idx);
568 if (wb_enc->irq_idx < 0) {
569 SDE_ERROR(
570 "failed to lookup IRQ index for WB_DONE with wb=%d\n",
571 hw_wb->idx - WB_0);
572 return -EINVAL;
573 }
574
Alan Kwonga172ef52016-09-27 00:29:10 -0400575 irq_cb->func = sde_encoder_phys_wb_done_irq;
576 irq_cb->arg = wb_enc;
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400577 ret = sde_core_irq_register_callback(phys_enc->sde_kms,
Alan Kwonga172ef52016-09-27 00:29:10 -0400578 wb_enc->irq_idx, irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400579 if (ret) {
580 SDE_ERROR("failed to register IRQ callback WB_DONE\n");
581 return ret;
582 }
583
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400584 ret = sde_core_irq_enable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
Alan Kwongbb27c092016-07-20 16:41:25 -0400585 if (ret) {
586 SDE_ERROR(
587 "failed to enable IRQ for WB_DONE, wb %d, irq_idx=%d\n",
588 hw_wb->idx - WB_0,
589 wb_enc->irq_idx);
590 wb_enc->irq_idx = -EINVAL;
591
592 /* Unregister callback on IRQ enable failure */
Alan Kwonga172ef52016-09-27 00:29:10 -0400593 sde_core_irq_unregister_callback(phys_enc->sde_kms,
594 wb_enc->irq_idx, irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400595 return ret;
596 }
597
598 SDE_DEBUG("registered IRQ for wb %d, irq_idx=%d\n",
599 hw_wb->idx - WB_0,
600 wb_enc->irq_idx);
601
602 return ret;
603}
604
605/**
606 * sde_encoder_phys_wb_mode_set - set display mode
607 * @phys_enc: Pointer to physical encoder
608 * @mode: Pointer to requested display mode
609 * @adj_mode: Pointer to adjusted display mode
610 */
611static void sde_encoder_phys_wb_mode_set(
612 struct sde_encoder_phys *phys_enc,
613 struct drm_display_mode *mode,
614 struct drm_display_mode *adj_mode)
615{
616 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400617 struct sde_rm *rm = &phys_enc->sde_kms->rm;
Alan Kwongbb27c092016-07-20 16:41:25 -0400618 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400619 struct sde_rm_hw_iter iter;
620 int i, instance;
Alan Kwongbb27c092016-07-20 16:41:25 -0400621
622 phys_enc->cached_mode = *adj_mode;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400623 instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400624
625 SDE_DEBUG("[mode_set_cache:%d,%d,\"%s\",%d,%d]\n",
626 hw_wb->idx - WB_0, mode->base.id,
627 mode->name, mode->hdisplay, mode->vdisplay);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400628
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400629 phys_enc->hw_ctl = NULL;
630 phys_enc->hw_cdm = NULL;
631
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400632 /* Retrieve previously allocated HW Resources. CTL shouldn't fail */
633 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
634 for (i = 0; i <= instance; i++) {
635 sde_rm_get_hw(rm, &iter);
636 if (i == instance)
637 phys_enc->hw_ctl = (struct sde_hw_ctl *) iter.hw;
638 }
639
640 if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
641 SDE_ERROR("failed init ctl: %ld\n", PTR_ERR(phys_enc->hw_ctl));
642 phys_enc->hw_ctl = NULL;
643 return;
644 }
645
646 /* CDM is optional */
647 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CDM);
648 for (i = 0; i <= instance; i++) {
649 sde_rm_get_hw(rm, &iter);
650 if (i == instance)
651 phys_enc->hw_cdm = (struct sde_hw_cdm *) iter.hw;
652 }
653
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400654 if (IS_ERR(phys_enc->hw_cdm)) {
655 SDE_ERROR("CDM required but not allocated: %ld\n",
656 PTR_ERR(phys_enc->hw_cdm));
657 phys_enc->hw_ctl = NULL;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400658 }
Alan Kwongbb27c092016-07-20 16:41:25 -0400659}
660
661/**
Alan Kwongbb27c092016-07-20 16:41:25 -0400662 * sde_encoder_phys_wb_wait_for_commit_done - wait until request is committed
663 * @phys_enc: Pointer to physical encoder
664 */
665static int sde_encoder_phys_wb_wait_for_commit_done(
666 struct sde_encoder_phys *phys_enc)
667{
668 unsigned long ret;
669 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
670 u32 irq_status;
671 u64 wb_time = 0;
672 int rc = 0;
673
674 /* Return EWOULDBLOCK since we know the wait isn't necessary */
675 if (WARN_ON(phys_enc->enable_state != SDE_ENC_ENABLED))
676 return -EWOULDBLOCK;
677
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400678 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count);
Alan Kwongbb27c092016-07-20 16:41:25 -0400679
680 ret = wait_for_completion_timeout(&wb_enc->wbdone_complete,
Lloyd Atkinsonaa0dce92016-11-23 20:16:47 -0500681 KICKOFF_TIMEOUT_JIFFIES);
Alan Kwongbb27c092016-07-20 16:41:25 -0400682
683 if (!ret) {
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400684 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc),
685 wb_enc->frame_count);
Alan Kwongbb27c092016-07-20 16:41:25 -0400686
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400687 irq_status = sde_core_irq_read(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400688 wb_enc->irq_idx, true);
689 if (irq_status) {
690 SDE_DEBUG("wb:%d done but irq not triggered\n",
691 wb_enc->wb_dev->wb_idx - WB_0);
692 sde_encoder_phys_wb_done_irq(wb_enc, wb_enc->irq_idx);
693 } else {
694 SDE_ERROR("wb:%d kickoff timed out\n",
695 wb_enc->wb_dev->wb_idx - WB_0);
Alan Kwong628d19e2016-10-31 13:50:13 -0400696 if (phys_enc->parent_ops.handle_frame_done)
697 phys_enc->parent_ops.handle_frame_done(
698 phys_enc->parent, phys_enc,
699 SDE_ENCODER_FRAME_EVENT_ERROR);
Alan Kwongbb27c092016-07-20 16:41:25 -0400700 rc = -ETIMEDOUT;
701 }
702 }
703
704 sde_encoder_phys_wb_unregister_irq(phys_enc);
705
706 if (!rc)
707 wb_enc->end_time = ktime_get();
708
709 /* once operation is done, disable traffic shaper */
710 if (wb_enc->wb_cfg.ts_cfg.en && wb_enc->hw_wb &&
711 wb_enc->hw_wb->ops.setup_trafficshaper) {
712 wb_enc->wb_cfg.ts_cfg.en = false;
713 wb_enc->hw_wb->ops.setup_trafficshaper(
714 wb_enc->hw_wb, &wb_enc->wb_cfg);
715 }
716
717 /* remove vote for iommu/clk/bus */
718 wb_enc->frame_count++;
719
720 if (!rc) {
721 wb_time = (u64)ktime_to_us(wb_enc->end_time) -
722 (u64)ktime_to_us(wb_enc->start_time);
723 SDE_DEBUG("wb:%d took %llu us\n",
724 wb_enc->wb_dev->wb_idx - WB_0, wb_time);
725 }
726
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400727 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count,
728 wb_time);
Alan Kwongbb27c092016-07-20 16:41:25 -0400729
730 return rc;
731}
732
733/**
734 * sde_encoder_phys_wb_prepare_for_kickoff - pre-kickoff processing
735 * @phys_enc: Pointer to physical encoder
Alan Kwongbb27c092016-07-20 16:41:25 -0400736 */
737static void sde_encoder_phys_wb_prepare_for_kickoff(
Lloyd Atkinsonaa0dce92016-11-23 20:16:47 -0500738 struct sde_encoder_phys *phys_enc)
Alan Kwongbb27c092016-07-20 16:41:25 -0400739{
740 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
741 int ret;
742
743 SDE_DEBUG("[wb:%d,%u]\n", wb_enc->hw_wb->idx - WB_0,
744 wb_enc->kickoff_count);
745
Alan Kwongbb27c092016-07-20 16:41:25 -0400746 reinit_completion(&wb_enc->wbdone_complete);
747
748 ret = sde_encoder_phys_wb_register_irq(phys_enc);
749 if (ret) {
750 SDE_ERROR("failed to register irq %d\n", ret);
751 return;
752 }
753
754 wb_enc->kickoff_count++;
755
756 /* set OT limit & enable traffic shaper */
757 sde_encoder_phys_wb_setup(phys_enc);
758
759 sde_encoder_phys_wb_flush(phys_enc);
760
761 /* vote for iommu/clk/bus */
762 wb_enc->start_time = ktime_get();
763
Lloyd Atkinsonaa0dce92016-11-23 20:16:47 -0500764 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->kickoff_count);
Alan Kwongbb27c092016-07-20 16:41:25 -0400765}
766
767/**
768 * sde_encoder_phys_wb_handle_post_kickoff - post-kickoff processing
769 * @phys_enc: Pointer to physical encoder
770 */
771static void sde_encoder_phys_wb_handle_post_kickoff(
772 struct sde_encoder_phys *phys_enc)
773{
774 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
775
776 SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0);
777
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400778 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc));
Alan Kwongbb27c092016-07-20 16:41:25 -0400779}
780
781/**
782 * sde_encoder_phys_wb_enable - enable writeback encoder
783 * @phys_enc: Pointer to physical encoder
784 */
785static void sde_encoder_phys_wb_enable(struct sde_encoder_phys *phys_enc)
786{
787 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
788 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Alan Kwong74e8ba32016-09-30 14:25:16 -0400789 struct drm_device *dev;
Alan Kwongbb27c092016-07-20 16:41:25 -0400790 struct drm_connector *connector;
791
792 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
793
Alan Kwong74e8ba32016-09-30 14:25:16 -0400794 if (!wb_enc->base.parent || !wb_enc->base.parent->dev) {
795 SDE_ERROR("invalid drm device\n");
796 return;
797 }
798 dev = wb_enc->base.parent->dev;
799
Alan Kwongbb27c092016-07-20 16:41:25 -0400800 /* find associated writeback connector */
Alan Kwong74e8ba32016-09-30 14:25:16 -0400801 mutex_lock(&dev->mode_config.mutex);
Alan Kwongbb27c092016-07-20 16:41:25 -0400802 drm_for_each_connector(connector, phys_enc->parent->dev) {
803 if (connector->encoder == phys_enc->parent)
804 break;
805 }
Alan Kwong74e8ba32016-09-30 14:25:16 -0400806 mutex_unlock(&dev->mode_config.mutex);
807
Alan Kwongbb27c092016-07-20 16:41:25 -0400808 if (!connector || connector->encoder != phys_enc->parent) {
809 SDE_ERROR("failed to find writeback connector\n");
810 return;
811 }
812 wb_enc->wb_dev = sde_wb_connector_get_wb(connector);
813
814 phys_enc->enable_state = SDE_ENC_ENABLED;
815}
816
817/**
818 * sde_encoder_phys_wb_disable - disable writeback encoder
819 * @phys_enc: Pointer to physical encoder
820 */
821static void sde_encoder_phys_wb_disable(struct sde_encoder_phys *phys_enc)
822{
823 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
824 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
825
826 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
827
828 if (phys_enc->enable_state == SDE_ENC_DISABLED) {
829 SDE_ERROR("encoder is already disabled\n");
830 return;
831 }
832
833 if (wb_enc->frame_count != wb_enc->kickoff_count) {
834 SDE_DEBUG("[wait_for_done: wb:%d, frame:%u, kickoff:%u]\n",
835 hw_wb->idx - WB_0, wb_enc->frame_count,
836 wb_enc->kickoff_count);
837 sde_encoder_phys_wb_wait_for_commit_done(phys_enc);
838 }
839
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400840 if (phys_enc->hw_cdm && phys_enc->hw_cdm->ops.disable) {
841 SDE_DEBUG_DRIVER("[cdm_disable]\n");
842 phys_enc->hw_cdm->ops.disable(phys_enc->hw_cdm);
843 }
844
Alan Kwongbb27c092016-07-20 16:41:25 -0400845 phys_enc->enable_state = SDE_ENC_DISABLED;
846}
847
848/**
849 * sde_encoder_phys_wb_get_hw_resources - get hardware resources
850 * @phys_enc: Pointer to physical encoder
851 * @hw_res: Pointer to encoder resources
852 */
853static void sde_encoder_phys_wb_get_hw_resources(
854 struct sde_encoder_phys *phys_enc,
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400855 struct sde_encoder_hw_resources *hw_res,
856 struct drm_connector_state *conn_state)
Alan Kwongbb27c092016-07-20 16:41:25 -0400857{
858 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400859 struct sde_hw_wb *hw_wb;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400860 struct drm_framebuffer *fb;
861 const struct sde_format *fmt;
Alan Kwongbb27c092016-07-20 16:41:25 -0400862
Clarence Ip03521982016-08-26 10:49:47 -0400863 if (!phys_enc) {
864 SDE_ERROR("invalid encoder\n");
865 return;
866 }
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400867
868 fb = sde_wb_connector_state_get_output_fb(conn_state);
869 if (!fb) {
870 SDE_ERROR("no output framebuffer\n");
871 return;
872 }
873
874 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
875 drm_format_num_planes(fb->pixel_format));
876 if (!fmt) {
877 SDE_ERROR("unsupported output pixel format:%d\n",
878 fb->pixel_format);
879 return;
880 }
881
Clarence Ip03521982016-08-26 10:49:47 -0400882 hw_wb = wb_enc->hw_wb;
Clarence Ip03521982016-08-26 10:49:47 -0400883 hw_res->wbs[hw_wb->idx - WB_0] = phys_enc->intf_mode;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400884 hw_res->needs_cdm = SDE_FORMAT_IS_YUV(fmt);
885 SDE_DEBUG("[wb:%d] intf_mode=%d needs_cdm=%d\n", hw_wb->idx - WB_0,
886 hw_res->wbs[hw_wb->idx - WB_0],
887 hw_res->needs_cdm);
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400888}
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400889
Alan Kwongbb27c092016-07-20 16:41:25 -0400890#ifdef CONFIG_DEBUG_FS
891/**
892 * sde_encoder_phys_wb_init_debugfs - initialize writeback encoder debugfs
893 * @phys_enc: Pointer to physical encoder
894 * @sde_kms: Pointer to SDE KMS object
895 */
896static int sde_encoder_phys_wb_init_debugfs(
897 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
898{
899 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
900
901 if (!phys_enc || !kms || !wb_enc->hw_wb)
902 return -EINVAL;
903
904 snprintf(wb_enc->wb_name, ARRAY_SIZE(wb_enc->wb_name), "encoder_wb%d",
905 wb_enc->hw_wb->idx - WB_0);
906
907 wb_enc->debugfs_root =
908 debugfs_create_dir(wb_enc->wb_name,
909 sde_debugfs_get_root(kms));
910 if (!wb_enc->debugfs_root) {
911 SDE_ERROR("failed to create debugfs\n");
912 return -ENOMEM;
913 }
914
915 if (!debugfs_create_u32("wbdone_timeout", 0644,
916 wb_enc->debugfs_root, &wb_enc->wbdone_timeout)) {
917 SDE_ERROR("failed to create debugfs/wbdone_timeout\n");
918 return -ENOMEM;
919 }
920
921 if (!debugfs_create_u32("bypass_irqreg", 0644,
922 wb_enc->debugfs_root, &wb_enc->bypass_irqreg)) {
923 SDE_ERROR("failed to create debugfs/bypass_irqreg\n");
924 return -ENOMEM;
925 }
926
927 return 0;
928}
929
930/**
931 * sde_encoder_phys_wb_destroy_debugfs - destroy writeback encoder debugfs
932 * @phys_enc: Pointer to physical encoder
933 */
934static void sde_encoder_phys_wb_destroy_debugfs(
935 struct sde_encoder_phys *phys_enc)
936{
937 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
938
939 if (!phys_enc)
940 return;
941
942 debugfs_remove_recursive(wb_enc->debugfs_root);
943}
944#else
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700945static int sde_encoder_phys_wb_init_debugfs(
Alan Kwongbb27c092016-07-20 16:41:25 -0400946 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
947{
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700948 return 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400949}
950static void sde_encoder_phys_wb_destroy_debugfs(
951 struct sde_encoder_phys *phys_enc)
952{
953}
954#endif
955
956/**
957 * sde_encoder_phys_wb_destroy - destroy writeback encoder
958 * @phys_enc: Pointer to physical encoder
959 */
960static void sde_encoder_phys_wb_destroy(struct sde_encoder_phys *phys_enc)
961{
962 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
963 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
964
965 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
966
967 if (!phys_enc)
968 return;
969
970 sde_encoder_phys_wb_destroy_debugfs(phys_enc);
971
Alan Kwongbb27c092016-07-20 16:41:25 -0400972 kfree(wb_enc);
973}
974
975/**
976 * sde_encoder_phys_wb_init_ops - initialize writeback operations
977 * @ops: Pointer to encoder operation table
978 */
979static void sde_encoder_phys_wb_init_ops(struct sde_encoder_phys_ops *ops)
980{
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400981 ops->is_master = sde_encoder_phys_wb_is_master;
Alan Kwongbb27c092016-07-20 16:41:25 -0400982 ops->mode_set = sde_encoder_phys_wb_mode_set;
983 ops->enable = sde_encoder_phys_wb_enable;
984 ops->disable = sde_encoder_phys_wb_disable;
985 ops->destroy = sde_encoder_phys_wb_destroy;
986 ops->atomic_check = sde_encoder_phys_wb_atomic_check;
987 ops->get_hw_resources = sde_encoder_phys_wb_get_hw_resources;
Alan Kwongbb27c092016-07-20 16:41:25 -0400988 ops->wait_for_commit_done = sde_encoder_phys_wb_wait_for_commit_done;
989 ops->prepare_for_kickoff = sde_encoder_phys_wb_prepare_for_kickoff;
990 ops->handle_post_kickoff = sde_encoder_phys_wb_handle_post_kickoff;
Clarence Ip110d15c2016-08-16 14:44:41 -0400991 ops->trigger_start = sde_encoder_helper_trigger_start;
Alan Kwongbb27c092016-07-20 16:41:25 -0400992}
993
994/**
995 * sde_encoder_phys_wb_init - initialize writeback encoder
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400996 * @init: Pointer to init info structure with initialization params
Alan Kwongbb27c092016-07-20 16:41:25 -0400997 */
998struct sde_encoder_phys *sde_encoder_phys_wb_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400999 struct sde_enc_phys_init_params *p)
Alan Kwongbb27c092016-07-20 16:41:25 -04001000{
1001 struct sde_encoder_phys *phys_enc;
1002 struct sde_encoder_phys_wb *wb_enc;
1003 struct sde_hw_mdp *hw_mdp;
1004 int ret = 0;
1005
1006 SDE_DEBUG("\n");
1007
1008 wb_enc = kzalloc(sizeof(*wb_enc), GFP_KERNEL);
1009 if (!wb_enc) {
1010 ret = -ENOMEM;
1011 goto fail_alloc;
1012 }
1013 wb_enc->irq_idx = -EINVAL;
Lloyd Atkinsonaa0dce92016-11-23 20:16:47 -05001014 wb_enc->wbdone_timeout = KICKOFF_TIMEOUT_MS;
Alan Kwongbb27c092016-07-20 16:41:25 -04001015 init_completion(&wb_enc->wbdone_complete);
1016
1017 phys_enc = &wb_enc->base;
1018
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001019 if (p->sde_kms->vbif[VBIF_NRT]) {
Alan Kwongbb27c092016-07-20 16:41:25 -04001020 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001021 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001022 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001023 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001024 } else {
1025 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001026 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001027 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001028 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001029 }
1030
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001031 hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
Alan Kwongbb27c092016-07-20 16:41:25 -04001032 if (IS_ERR_OR_NULL(hw_mdp)) {
1033 ret = PTR_ERR(hw_mdp);
1034 SDE_ERROR("failed to init hw_top: %d\n", ret);
1035 goto fail_mdp_init;
1036 }
1037 phys_enc->hw_mdptop = hw_mdp;
1038
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001039 /**
1040 * hw_wb resource permanently assigned to this encoder
1041 * Other resources allocated at atomic commit time by use case
1042 */
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001043 if (p->wb_idx != SDE_NONE) {
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001044 struct sde_rm_hw_iter iter;
Alan Kwongbb27c092016-07-20 16:41:25 -04001045
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001046 sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_WB);
1047 while (sde_rm_get_hw(&p->sde_kms->rm, &iter)) {
1048 struct sde_hw_wb *hw_wb = (struct sde_hw_wb *)iter.hw;
1049
1050 if (hw_wb->idx == p->wb_idx) {
1051 wb_enc->hw_wb = hw_wb;
1052 break;
1053 }
1054 }
1055
1056 if (!wb_enc->hw_wb) {
1057 ret = -EINVAL;
1058 SDE_ERROR("failed to init hw_wb%d\n", p->wb_idx - WB_0);
Alan Kwongbb27c092016-07-20 16:41:25 -04001059 goto fail_wb_init;
1060 }
Alan Kwongbb27c092016-07-20 16:41:25 -04001061 } else {
1062 ret = -EINVAL;
1063 SDE_ERROR("invalid wb_idx\n");
1064 goto fail_wb_check;
1065 }
1066
Alan Kwongbb27c092016-07-20 16:41:25 -04001067 sde_encoder_phys_wb_init_ops(&phys_enc->ops);
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001068 phys_enc->parent = p->parent;
1069 phys_enc->parent_ops = p->parent_ops;
1070 phys_enc->sde_kms = p->sde_kms;
1071 phys_enc->split_role = p->split_role;
Clarence Ip03521982016-08-26 10:49:47 -04001072 phys_enc->intf_mode = INTF_MODE_WB_LINE;
Dhaval Patel81e87882016-10-19 21:41:56 -07001073 phys_enc->intf_idx = p->intf_idx;
Lloyd Atkinson7d070942016-07-26 18:35:12 -04001074 phys_enc->enc_spinlock = p->enc_spinlock;
Alan Kwonga172ef52016-09-27 00:29:10 -04001075 INIT_LIST_HEAD(&wb_enc->irq_cb.list);
Alan Kwongbb27c092016-07-20 16:41:25 -04001076
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001077 ret = sde_encoder_phys_wb_init_debugfs(phys_enc, p->sde_kms);
Alan Kwongbb27c092016-07-20 16:41:25 -04001078 if (ret) {
1079 SDE_ERROR("failed to init debugfs %d\n", ret);
1080 goto fail_debugfs_init;
1081 }
1082
1083 SDE_DEBUG("Created sde_encoder_phys_wb for wb %d\n",
1084 wb_enc->hw_wb->idx - WB_0);
1085
1086 return phys_enc;
1087
1088fail_debugfs_init:
Alan Kwongbb27c092016-07-20 16:41:25 -04001089fail_wb_init:
1090fail_wb_check:
Alan Kwongbb27c092016-07-20 16:41:25 -04001091fail_mdp_init:
1092 kfree(wb_enc);
1093fail_alloc:
1094 return ERR_PTR(ret);
1095}
1096