blob: 3cb711d13e7ac6c74b0291bc77ee793e0a3a5077 [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;
Alan Kwong5a50a4a2017-01-24 19:12:51 -0800673 u32 timeout = max_t(u32, wb_enc->wbdone_timeout, KICKOFF_TIMEOUT_MS);
Alan Kwongbb27c092016-07-20 16:41:25 -0400674
675 /* Return EWOULDBLOCK since we know the wait isn't necessary */
676 if (WARN_ON(phys_enc->enable_state != SDE_ENC_ENABLED))
677 return -EWOULDBLOCK;
678
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400679 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count);
Alan Kwongbb27c092016-07-20 16:41:25 -0400680
681 ret = wait_for_completion_timeout(&wb_enc->wbdone_complete,
Alan Kwong5a50a4a2017-01-24 19:12:51 -0800682 msecs_to_jiffies(timeout));
Alan Kwongbb27c092016-07-20 16:41:25 -0400683
684 if (!ret) {
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400685 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc),
686 wb_enc->frame_count);
Alan Kwongbb27c092016-07-20 16:41:25 -0400687
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400688 irq_status = sde_core_irq_read(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400689 wb_enc->irq_idx, true);
690 if (irq_status) {
691 SDE_DEBUG("wb:%d done but irq not triggered\n",
692 wb_enc->wb_dev->wb_idx - WB_0);
693 sde_encoder_phys_wb_done_irq(wb_enc, wb_enc->irq_idx);
694 } else {
695 SDE_ERROR("wb:%d kickoff timed out\n",
696 wb_enc->wb_dev->wb_idx - WB_0);
Alan Kwong628d19e2016-10-31 13:50:13 -0400697 if (phys_enc->parent_ops.handle_frame_done)
698 phys_enc->parent_ops.handle_frame_done(
699 phys_enc->parent, phys_enc,
700 SDE_ENCODER_FRAME_EVENT_ERROR);
Alan Kwongbb27c092016-07-20 16:41:25 -0400701 rc = -ETIMEDOUT;
702 }
703 }
704
705 sde_encoder_phys_wb_unregister_irq(phys_enc);
706
707 if (!rc)
708 wb_enc->end_time = ktime_get();
709
710 /* once operation is done, disable traffic shaper */
711 if (wb_enc->wb_cfg.ts_cfg.en && wb_enc->hw_wb &&
712 wb_enc->hw_wb->ops.setup_trafficshaper) {
713 wb_enc->wb_cfg.ts_cfg.en = false;
714 wb_enc->hw_wb->ops.setup_trafficshaper(
715 wb_enc->hw_wb, &wb_enc->wb_cfg);
716 }
717
718 /* remove vote for iommu/clk/bus */
719 wb_enc->frame_count++;
720
721 if (!rc) {
722 wb_time = (u64)ktime_to_us(wb_enc->end_time) -
723 (u64)ktime_to_us(wb_enc->start_time);
724 SDE_DEBUG("wb:%d took %llu us\n",
725 wb_enc->wb_dev->wb_idx - WB_0, wb_time);
726 }
727
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400728 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count,
729 wb_time);
Alan Kwongbb27c092016-07-20 16:41:25 -0400730
731 return rc;
732}
733
734/**
735 * sde_encoder_phys_wb_prepare_for_kickoff - pre-kickoff processing
736 * @phys_enc: Pointer to physical encoder
Alan Kwongbb27c092016-07-20 16:41:25 -0400737 */
738static void sde_encoder_phys_wb_prepare_for_kickoff(
Lloyd Atkinsonaa0dce92016-11-23 20:16:47 -0500739 struct sde_encoder_phys *phys_enc)
Alan Kwongbb27c092016-07-20 16:41:25 -0400740{
741 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
742 int ret;
743
744 SDE_DEBUG("[wb:%d,%u]\n", wb_enc->hw_wb->idx - WB_0,
745 wb_enc->kickoff_count);
746
Alan Kwongbb27c092016-07-20 16:41:25 -0400747 reinit_completion(&wb_enc->wbdone_complete);
748
749 ret = sde_encoder_phys_wb_register_irq(phys_enc);
750 if (ret) {
751 SDE_ERROR("failed to register irq %d\n", ret);
752 return;
753 }
754
755 wb_enc->kickoff_count++;
756
757 /* set OT limit & enable traffic shaper */
758 sde_encoder_phys_wb_setup(phys_enc);
759
760 sde_encoder_phys_wb_flush(phys_enc);
761
762 /* vote for iommu/clk/bus */
763 wb_enc->start_time = ktime_get();
764
Lloyd Atkinsonaa0dce92016-11-23 20:16:47 -0500765 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->kickoff_count);
Alan Kwongbb27c092016-07-20 16:41:25 -0400766}
767
768/**
769 * sde_encoder_phys_wb_handle_post_kickoff - post-kickoff processing
770 * @phys_enc: Pointer to physical encoder
771 */
772static void sde_encoder_phys_wb_handle_post_kickoff(
773 struct sde_encoder_phys *phys_enc)
774{
775 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
776
777 SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0);
778
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400779 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc));
Alan Kwongbb27c092016-07-20 16:41:25 -0400780}
781
782/**
783 * sde_encoder_phys_wb_enable - enable writeback encoder
784 * @phys_enc: Pointer to physical encoder
785 */
786static void sde_encoder_phys_wb_enable(struct sde_encoder_phys *phys_enc)
787{
788 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
789 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Alan Kwong74e8ba32016-09-30 14:25:16 -0400790 struct drm_device *dev;
Alan Kwongbb27c092016-07-20 16:41:25 -0400791 struct drm_connector *connector;
792
793 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
794
Alan Kwong74e8ba32016-09-30 14:25:16 -0400795 if (!wb_enc->base.parent || !wb_enc->base.parent->dev) {
796 SDE_ERROR("invalid drm device\n");
797 return;
798 }
799 dev = wb_enc->base.parent->dev;
800
Alan Kwongbb27c092016-07-20 16:41:25 -0400801 /* find associated writeback connector */
Alan Kwong74e8ba32016-09-30 14:25:16 -0400802 mutex_lock(&dev->mode_config.mutex);
Alan Kwongbb27c092016-07-20 16:41:25 -0400803 drm_for_each_connector(connector, phys_enc->parent->dev) {
804 if (connector->encoder == phys_enc->parent)
805 break;
806 }
Alan Kwong74e8ba32016-09-30 14:25:16 -0400807 mutex_unlock(&dev->mode_config.mutex);
808
Alan Kwongbb27c092016-07-20 16:41:25 -0400809 if (!connector || connector->encoder != phys_enc->parent) {
810 SDE_ERROR("failed to find writeback connector\n");
811 return;
812 }
813 wb_enc->wb_dev = sde_wb_connector_get_wb(connector);
814
815 phys_enc->enable_state = SDE_ENC_ENABLED;
816}
817
818/**
819 * sde_encoder_phys_wb_disable - disable writeback encoder
820 * @phys_enc: Pointer to physical encoder
821 */
822static void sde_encoder_phys_wb_disable(struct sde_encoder_phys *phys_enc)
823{
824 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
825 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
826
827 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
828
829 if (phys_enc->enable_state == SDE_ENC_DISABLED) {
830 SDE_ERROR("encoder is already disabled\n");
831 return;
832 }
833
834 if (wb_enc->frame_count != wb_enc->kickoff_count) {
835 SDE_DEBUG("[wait_for_done: wb:%d, frame:%u, kickoff:%u]\n",
836 hw_wb->idx - WB_0, wb_enc->frame_count,
837 wb_enc->kickoff_count);
838 sde_encoder_phys_wb_wait_for_commit_done(phys_enc);
839 }
840
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400841 if (phys_enc->hw_cdm && phys_enc->hw_cdm->ops.disable) {
842 SDE_DEBUG_DRIVER("[cdm_disable]\n");
843 phys_enc->hw_cdm->ops.disable(phys_enc->hw_cdm);
844 }
845
Alan Kwongbb27c092016-07-20 16:41:25 -0400846 phys_enc->enable_state = SDE_ENC_DISABLED;
847}
848
849/**
850 * sde_encoder_phys_wb_get_hw_resources - get hardware resources
851 * @phys_enc: Pointer to physical encoder
852 * @hw_res: Pointer to encoder resources
853 */
854static void sde_encoder_phys_wb_get_hw_resources(
855 struct sde_encoder_phys *phys_enc,
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400856 struct sde_encoder_hw_resources *hw_res,
857 struct drm_connector_state *conn_state)
Alan Kwongbb27c092016-07-20 16:41:25 -0400858{
859 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400860 struct sde_hw_wb *hw_wb;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400861 struct drm_framebuffer *fb;
862 const struct sde_format *fmt;
Alan Kwongbb27c092016-07-20 16:41:25 -0400863
Clarence Ip03521982016-08-26 10:49:47 -0400864 if (!phys_enc) {
865 SDE_ERROR("invalid encoder\n");
866 return;
867 }
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400868
869 fb = sde_wb_connector_state_get_output_fb(conn_state);
870 if (!fb) {
871 SDE_ERROR("no output framebuffer\n");
872 return;
873 }
874
875 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
876 drm_format_num_planes(fb->pixel_format));
877 if (!fmt) {
878 SDE_ERROR("unsupported output pixel format:%d\n",
879 fb->pixel_format);
880 return;
881 }
882
Clarence Ip03521982016-08-26 10:49:47 -0400883 hw_wb = wb_enc->hw_wb;
Clarence Ip03521982016-08-26 10:49:47 -0400884 hw_res->wbs[hw_wb->idx - WB_0] = phys_enc->intf_mode;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400885 hw_res->needs_cdm = SDE_FORMAT_IS_YUV(fmt);
886 SDE_DEBUG("[wb:%d] intf_mode=%d needs_cdm=%d\n", hw_wb->idx - WB_0,
887 hw_res->wbs[hw_wb->idx - WB_0],
888 hw_res->needs_cdm);
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400889}
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400890
Alan Kwongbb27c092016-07-20 16:41:25 -0400891#ifdef CONFIG_DEBUG_FS
892/**
893 * sde_encoder_phys_wb_init_debugfs - initialize writeback encoder debugfs
894 * @phys_enc: Pointer to physical encoder
895 * @sde_kms: Pointer to SDE KMS object
896 */
897static int sde_encoder_phys_wb_init_debugfs(
898 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
899{
900 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
901
902 if (!phys_enc || !kms || !wb_enc->hw_wb)
903 return -EINVAL;
904
905 snprintf(wb_enc->wb_name, ARRAY_SIZE(wb_enc->wb_name), "encoder_wb%d",
906 wb_enc->hw_wb->idx - WB_0);
907
908 wb_enc->debugfs_root =
909 debugfs_create_dir(wb_enc->wb_name,
910 sde_debugfs_get_root(kms));
911 if (!wb_enc->debugfs_root) {
912 SDE_ERROR("failed to create debugfs\n");
913 return -ENOMEM;
914 }
915
916 if (!debugfs_create_u32("wbdone_timeout", 0644,
917 wb_enc->debugfs_root, &wb_enc->wbdone_timeout)) {
918 SDE_ERROR("failed to create debugfs/wbdone_timeout\n");
919 return -ENOMEM;
920 }
921
922 if (!debugfs_create_u32("bypass_irqreg", 0644,
923 wb_enc->debugfs_root, &wb_enc->bypass_irqreg)) {
924 SDE_ERROR("failed to create debugfs/bypass_irqreg\n");
925 return -ENOMEM;
926 }
927
928 return 0;
929}
930
931/**
932 * sde_encoder_phys_wb_destroy_debugfs - destroy writeback encoder debugfs
933 * @phys_enc: Pointer to physical encoder
934 */
935static void sde_encoder_phys_wb_destroy_debugfs(
936 struct sde_encoder_phys *phys_enc)
937{
938 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
939
940 if (!phys_enc)
941 return;
942
943 debugfs_remove_recursive(wb_enc->debugfs_root);
944}
945#else
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700946static int sde_encoder_phys_wb_init_debugfs(
Alan Kwongbb27c092016-07-20 16:41:25 -0400947 struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
948{
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700949 return 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400950}
951static void sde_encoder_phys_wb_destroy_debugfs(
952 struct sde_encoder_phys *phys_enc)
953{
954}
955#endif
956
957/**
958 * sde_encoder_phys_wb_destroy - destroy writeback encoder
959 * @phys_enc: Pointer to physical encoder
960 */
961static void sde_encoder_phys_wb_destroy(struct sde_encoder_phys *phys_enc)
962{
963 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
964 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
965
966 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
967
968 if (!phys_enc)
969 return;
970
971 sde_encoder_phys_wb_destroy_debugfs(phys_enc);
972
Alan Kwongbb27c092016-07-20 16:41:25 -0400973 kfree(wb_enc);
974}
975
976/**
977 * sde_encoder_phys_wb_init_ops - initialize writeback operations
978 * @ops: Pointer to encoder operation table
979 */
980static void sde_encoder_phys_wb_init_ops(struct sde_encoder_phys_ops *ops)
981{
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400982 ops->is_master = sde_encoder_phys_wb_is_master;
Alan Kwongbb27c092016-07-20 16:41:25 -0400983 ops->mode_set = sde_encoder_phys_wb_mode_set;
984 ops->enable = sde_encoder_phys_wb_enable;
985 ops->disable = sde_encoder_phys_wb_disable;
986 ops->destroy = sde_encoder_phys_wb_destroy;
987 ops->atomic_check = sde_encoder_phys_wb_atomic_check;
988 ops->get_hw_resources = sde_encoder_phys_wb_get_hw_resources;
Alan Kwongbb27c092016-07-20 16:41:25 -0400989 ops->wait_for_commit_done = sde_encoder_phys_wb_wait_for_commit_done;
990 ops->prepare_for_kickoff = sde_encoder_phys_wb_prepare_for_kickoff;
991 ops->handle_post_kickoff = sde_encoder_phys_wb_handle_post_kickoff;
Clarence Ip110d15c2016-08-16 14:44:41 -0400992 ops->trigger_start = sde_encoder_helper_trigger_start;
Lloyd Atkinson8c49c582016-11-18 14:23:54 -0500993 ops->hw_reset = sde_encoder_helper_hw_reset;
Alan Kwongbb27c092016-07-20 16:41:25 -0400994}
995
996/**
997 * sde_encoder_phys_wb_init - initialize writeback encoder
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -0400998 * @init: Pointer to init info structure with initialization params
Alan Kwongbb27c092016-07-20 16:41:25 -0400999 */
1000struct sde_encoder_phys *sde_encoder_phys_wb_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001001 struct sde_enc_phys_init_params *p)
Alan Kwongbb27c092016-07-20 16:41:25 -04001002{
1003 struct sde_encoder_phys *phys_enc;
1004 struct sde_encoder_phys_wb *wb_enc;
1005 struct sde_hw_mdp *hw_mdp;
1006 int ret = 0;
1007
1008 SDE_DEBUG("\n");
1009
1010 wb_enc = kzalloc(sizeof(*wb_enc), GFP_KERNEL);
1011 if (!wb_enc) {
1012 ret = -ENOMEM;
1013 goto fail_alloc;
1014 }
1015 wb_enc->irq_idx = -EINVAL;
Lloyd Atkinsonaa0dce92016-11-23 20:16:47 -05001016 wb_enc->wbdone_timeout = KICKOFF_TIMEOUT_MS;
Alan Kwongbb27c092016-07-20 16:41:25 -04001017 init_completion(&wb_enc->wbdone_complete);
1018
1019 phys_enc = &wb_enc->base;
1020
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001021 if (p->sde_kms->vbif[VBIF_NRT]) {
Alan Kwongbb27c092016-07-20 16:41:25 -04001022 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001023 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001024 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001025 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001026 } else {
1027 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001028 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001029 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001030 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001031 }
1032
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001033 hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
Alan Kwongbb27c092016-07-20 16:41:25 -04001034 if (IS_ERR_OR_NULL(hw_mdp)) {
1035 ret = PTR_ERR(hw_mdp);
1036 SDE_ERROR("failed to init hw_top: %d\n", ret);
1037 goto fail_mdp_init;
1038 }
1039 phys_enc->hw_mdptop = hw_mdp;
1040
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001041 /**
1042 * hw_wb resource permanently assigned to this encoder
1043 * Other resources allocated at atomic commit time by use case
1044 */
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001045 if (p->wb_idx != SDE_NONE) {
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001046 struct sde_rm_hw_iter iter;
Alan Kwongbb27c092016-07-20 16:41:25 -04001047
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001048 sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_WB);
1049 while (sde_rm_get_hw(&p->sde_kms->rm, &iter)) {
1050 struct sde_hw_wb *hw_wb = (struct sde_hw_wb *)iter.hw;
1051
1052 if (hw_wb->idx == p->wb_idx) {
1053 wb_enc->hw_wb = hw_wb;
1054 break;
1055 }
1056 }
1057
1058 if (!wb_enc->hw_wb) {
1059 ret = -EINVAL;
1060 SDE_ERROR("failed to init hw_wb%d\n", p->wb_idx - WB_0);
Alan Kwongbb27c092016-07-20 16:41:25 -04001061 goto fail_wb_init;
1062 }
Alan Kwongbb27c092016-07-20 16:41:25 -04001063 } else {
1064 ret = -EINVAL;
1065 SDE_ERROR("invalid wb_idx\n");
1066 goto fail_wb_check;
1067 }
1068
Alan Kwongbb27c092016-07-20 16:41:25 -04001069 sde_encoder_phys_wb_init_ops(&phys_enc->ops);
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001070 phys_enc->parent = p->parent;
1071 phys_enc->parent_ops = p->parent_ops;
1072 phys_enc->sde_kms = p->sde_kms;
1073 phys_enc->split_role = p->split_role;
Clarence Ip03521982016-08-26 10:49:47 -04001074 phys_enc->intf_mode = INTF_MODE_WB_LINE;
Dhaval Patel81e87882016-10-19 21:41:56 -07001075 phys_enc->intf_idx = p->intf_idx;
Lloyd Atkinson7d070942016-07-26 18:35:12 -04001076 phys_enc->enc_spinlock = p->enc_spinlock;
Alan Kwonga172ef52016-09-27 00:29:10 -04001077 INIT_LIST_HEAD(&wb_enc->irq_cb.list);
Alan Kwongbb27c092016-07-20 16:41:25 -04001078
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001079 ret = sde_encoder_phys_wb_init_debugfs(phys_enc, p->sde_kms);
Alan Kwongbb27c092016-07-20 16:41:25 -04001080 if (ret) {
1081 SDE_ERROR("failed to init debugfs %d\n", ret);
1082 goto fail_debugfs_init;
1083 }
1084
1085 SDE_DEBUG("Created sde_encoder_phys_wb for wb %d\n",
1086 wb_enc->hw_wb->idx - WB_0);
1087
1088 return phys_enc;
1089
1090fail_debugfs_init:
Alan Kwongbb27c092016-07-20 16:41:25 -04001091fail_wb_init:
1092fail_wb_check:
Alan Kwongbb27c092016-07-20 16:41:25 -04001093fail_mdp_init:
1094 kfree(wb_enc);
1095fail_alloc:
1096 return ERR_PTR(ret);
1097}
1098