blob: 75eddc0cc7db898b3a96df5ee880ccd25e2de8d1 [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
Alan Kwongd6a38602017-03-11 22:26:25 -080031#define TO_S15D16(_x_) ((_x_) << 7)
32
33/**
34 * sde_rgb2yuv_601l - rgb to yuv color space conversion matrix
35 *
36 */
37static struct sde_csc_cfg sde_encoder_phys_wb_rgb2yuv_601l = {
38 {
39 TO_S15D16(0x0083), TO_S15D16(0x0102), TO_S15D16(0x0032),
40 TO_S15D16(0x1fb5), TO_S15D16(0x1f6c), TO_S15D16(0x00e1),
41 TO_S15D16(0x00e1), TO_S15D16(0x1f45), TO_S15D16(0x1fdc)
42 },
43 { 0x00, 0x00, 0x00 },
44 { 0x0040, 0x0200, 0x0200 },
45 { 0x000, 0x3ff, 0x000, 0x3ff, 0x000, 0x3ff },
46 { 0x040, 0x3ac, 0x040, 0x3c0, 0x040, 0x3c0 },
47};
48
Alan Kwongbb27c092016-07-20 16:41:25 -040049/**
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -040050 * sde_encoder_phys_wb_is_master - report wb always as master encoder
51 */
52static bool sde_encoder_phys_wb_is_master(struct sde_encoder_phys *phys_enc)
53{
54 return true;
55}
56
57/**
Alan Kwongbb27c092016-07-20 16:41:25 -040058 * sde_encoder_phys_wb_get_intr_type - get interrupt type based on block mode
59 * @hw_wb: Pointer to h/w writeback driver
60 */
61static enum sde_intr_type sde_encoder_phys_wb_get_intr_type(
62 struct sde_hw_wb *hw_wb)
63{
64 return (hw_wb->caps->features & BIT(SDE_WB_BLOCK_MODE)) ?
65 SDE_IRQ_TYPE_WB_ROT_COMP : SDE_IRQ_TYPE_WB_WFD_COMP;
66}
67
68/**
Alan Kwong5d324e42016-07-28 22:56:18 -040069 * sde_encoder_phys_wb_set_ot_limit - set OT limit for writeback interface
70 * @phys_enc: Pointer to physical encoder
71 */
72static void sde_encoder_phys_wb_set_ot_limit(
73 struct sde_encoder_phys *phys_enc)
74{
75 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
76 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
77 struct sde_vbif_set_ot_params ot_params;
78
79 memset(&ot_params, 0, sizeof(ot_params));
80 ot_params.xin_id = hw_wb->caps->xin_id;
81 ot_params.num = hw_wb->idx - WB_0;
82 ot_params.width = wb_enc->wb_roi.w;
83 ot_params.height = wb_enc->wb_roi.h;
84 ot_params.is_wfd = true;
85 ot_params.frame_rate = phys_enc->cached_mode.vrefresh;
86 ot_params.vbif_idx = hw_wb->caps->vbif_idx;
87 ot_params.clk_ctrl = hw_wb->caps->clk_ctrl;
88 ot_params.rd = false;
89
90 sde_vbif_set_ot_limit(phys_enc->sde_kms, &ot_params);
91}
92
93/**
Alan Kwongbb27c092016-07-20 16:41:25 -040094 * sde_encoder_phys_wb_set_traffic_shaper - set traffic shaper for writeback
95 * @phys_enc: Pointer to physical encoder
96 */
97static void sde_encoder_phys_wb_set_traffic_shaper(
98 struct sde_encoder_phys *phys_enc)
99{
100 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
101 struct sde_hw_wb_cfg *wb_cfg = &wb_enc->wb_cfg;
102
103 /* traffic shaper is only enabled for rotator */
104 wb_cfg->ts_cfg.en = false;
105}
106
107/**
108 * sde_encoder_phys_setup_cdm - setup chroma down block
109 * @phys_enc: Pointer to physical encoder
110 * @fb: Pointer to output framebuffer
111 * @format: Output format
112 */
113void sde_encoder_phys_setup_cdm(struct sde_encoder_phys *phys_enc,
114 struct drm_framebuffer *fb, const struct sde_format *format,
115 struct sde_rect *wb_roi)
116{
117 struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
118 struct sde_hw_cdm_cfg *cdm_cfg = &phys_enc->cdm_cfg;
119 int ret;
120
121 if (!SDE_FORMAT_IS_YUV(format)) {
122 SDE_DEBUG("[cdm_disable fmt:%x]\n",
123 format->base.pixel_format);
124
125 if (hw_cdm && hw_cdm->ops.disable)
126 hw_cdm->ops.disable(hw_cdm);
127
128 return;
129 }
130
131 memset(cdm_cfg, 0, sizeof(struct sde_hw_cdm_cfg));
132
133 cdm_cfg->output_width = wb_roi->w;
134 cdm_cfg->output_height = wb_roi->h;
135 cdm_cfg->output_fmt = format;
136 cdm_cfg->output_type = CDM_CDWN_OUTPUT_WB;
abeykun5ed42e12016-08-24 17:09:26 -0400137 cdm_cfg->output_bit_depth = SDE_FORMAT_IS_DX(format) ?
138 CDM_CDWN_OUTPUT_10BIT : CDM_CDWN_OUTPUT_8BIT;
Alan Kwongbb27c092016-07-20 16:41:25 -0400139
140 /* enable 10 bit logic */
141 switch (cdm_cfg->output_fmt->chroma_sample) {
142 case SDE_CHROMA_RGB:
143 cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
144 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
145 break;
146 case SDE_CHROMA_H2V1:
147 cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
148 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
149 break;
150 case SDE_CHROMA_420:
151 cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
152 cdm_cfg->v_cdwn_type = CDM_CDWN_OFFSITE;
153 break;
154 case SDE_CHROMA_H1V2:
155 default:
156 SDE_ERROR("unsupported chroma sampling type\n");
157 cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
158 cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
159 break;
160 }
161
162 SDE_DEBUG("[cdm_enable:%d,%d,%X,%d,%d,%d,%d]\n",
163 cdm_cfg->output_width,
164 cdm_cfg->output_height,
165 cdm_cfg->output_fmt->base.pixel_format,
166 cdm_cfg->output_type,
167 cdm_cfg->output_bit_depth,
168 cdm_cfg->h_cdwn_type,
169 cdm_cfg->v_cdwn_type);
170
Alan Kwongd6a38602017-03-11 22:26:25 -0800171 if (hw_cdm && hw_cdm->ops.setup_csc_data) {
172 ret = hw_cdm->ops.setup_csc_data(hw_cdm,
173 &sde_encoder_phys_wb_rgb2yuv_601l);
174 if (ret < 0) {
175 SDE_ERROR("failed to setup CSC %d\n", ret);
176 return;
177 }
178 }
179
Alan Kwongbb27c092016-07-20 16:41:25 -0400180 if (hw_cdm && hw_cdm->ops.setup_cdwn) {
181 ret = hw_cdm->ops.setup_cdwn(hw_cdm, cdm_cfg);
182 if (ret < 0) {
183 SDE_ERROR("failed to setup CDM %d\n", ret);
184 return;
185 }
186 }
187
188 if (hw_cdm && hw_cdm->ops.enable) {
189 ret = hw_cdm->ops.enable(hw_cdm, cdm_cfg);
190 if (ret < 0) {
191 SDE_ERROR("failed to enable CDM %d\n", ret);
192 return;
193 }
194 }
195}
196
197/**
198 * sde_encoder_phys_wb_setup_fb - setup output framebuffer
199 * @phys_enc: Pointer to physical encoder
200 * @fb: Pointer to output framebuffer
201 * @wb_roi: Pointer to output region of interest
202 */
203static void sde_encoder_phys_wb_setup_fb(struct sde_encoder_phys *phys_enc,
204 struct drm_framebuffer *fb, struct sde_rect *wb_roi)
205{
206 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400207 struct sde_hw_wb *hw_wb;
208 struct sde_hw_wb_cfg *wb_cfg;
Alan Kwongbb27c092016-07-20 16:41:25 -0400209 const struct msm_format *format;
210 int ret, mmu_id;
211
Clarence Ip03521982016-08-26 10:49:47 -0400212 if (!phys_enc) {
213 SDE_ERROR("invalid encoder\n");
214 return;
215 }
216
217 hw_wb = wb_enc->hw_wb;
218 wb_cfg = &wb_enc->wb_cfg;
Alan Kwongbb27c092016-07-20 16:41:25 -0400219 memset(wb_cfg, 0, sizeof(struct sde_hw_wb_cfg));
220
Clarence Ip03521982016-08-26 10:49:47 -0400221 wb_cfg->intf_mode = phys_enc->intf_mode;
Alan Kwongbb27c092016-07-20 16:41:25 -0400222 wb_cfg->is_secure = (fb->flags & DRM_MODE_FB_SECURE) ? true : false;
223 mmu_id = (wb_cfg->is_secure) ?
224 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] :
225 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE];
226
227 SDE_DEBUG("[fb_secure:%d]\n", wb_cfg->is_secure);
228
229 format = msm_framebuffer_format(fb);
Dhaval Patelccbcb3d2016-08-22 11:58:14 -0700230 if (!format) {
231 SDE_DEBUG("invalid format for fb\n");
232 return;
233 }
234
Alan Kwongbb27c092016-07-20 16:41:25 -0400235 wb_cfg->dest.format = sde_get_sde_format_ext(
236 format->pixel_format,
237 fb->modifier,
238 drm_format_num_planes(fb->pixel_format));
239 if (!wb_cfg->dest.format) {
240 /* this error should be detected during atomic_check */
241 SDE_ERROR("failed to get format %x\n", format->pixel_format);
242 return;
243 }
abeykunf1539f72016-08-24 16:08:03 -0400244 wb_cfg->roi = *wb_roi;
Alan Kwongbb27c092016-07-20 16:41:25 -0400245
abeykunf1539f72016-08-24 16:08:03 -0400246 if (hw_wb->caps->features & BIT(SDE_WB_XY_ROI_OFFSET)) {
247 ret = sde_format_populate_layout(mmu_id, fb, &wb_cfg->dest);
248 if (ret) {
249 SDE_DEBUG("failed to populate layout %d\n", ret);
250 return;
251 }
252 wb_cfg->dest.width = fb->width;
253 wb_cfg->dest.height = fb->height;
254 wb_cfg->dest.num_planes = wb_cfg->dest.format->num_planes;
255 } else {
256 ret = sde_format_populate_layout_with_roi(mmu_id, fb, wb_roi,
Alan Kwongbb27c092016-07-20 16:41:25 -0400257 &wb_cfg->dest);
abeykunf1539f72016-08-24 16:08:03 -0400258 if (ret) {
259 /* this error should be detected during atomic_check */
260 SDE_DEBUG("failed to populate layout %d\n", ret);
261 return;
262 }
Alan Kwongbb27c092016-07-20 16:41:25 -0400263 }
264
265 if ((wb_cfg->dest.format->fetch_planes == SDE_PLANE_PLANAR) &&
266 (wb_cfg->dest.format->element[0] == C1_B_Cb))
267 swap(wb_cfg->dest.plane_addr[1], wb_cfg->dest.plane_addr[2]);
268
269 SDE_DEBUG("[fb_offset:%8.8x,%8.8x,%8.8x,%8.8x]\n",
270 wb_cfg->dest.plane_addr[0],
271 wb_cfg->dest.plane_addr[1],
272 wb_cfg->dest.plane_addr[2],
273 wb_cfg->dest.plane_addr[3]);
274 SDE_DEBUG("[fb_stride:%8.8x,%8.8x,%8.8x,%8.8x]\n",
275 wb_cfg->dest.plane_pitch[0],
276 wb_cfg->dest.plane_pitch[1],
277 wb_cfg->dest.plane_pitch[2],
278 wb_cfg->dest.plane_pitch[3]);
279
abeykunf1539f72016-08-24 16:08:03 -0400280 if (hw_wb->ops.setup_roi)
281 hw_wb->ops.setup_roi(hw_wb, wb_cfg);
282
Alan Kwongbb27c092016-07-20 16:41:25 -0400283 if (hw_wb->ops.setup_outformat)
284 hw_wb->ops.setup_outformat(hw_wb, wb_cfg);
285
286 if (hw_wb->ops.setup_outaddress)
287 hw_wb->ops.setup_outaddress(hw_wb, wb_cfg);
288}
289
290/**
291 * sde_encoder_phys_wb_setup_cdp - setup chroma down prefetch block
292 * @phys_enc: Pointer to physical encoder
293 */
294static void sde_encoder_phys_wb_setup_cdp(struct sde_encoder_phys *phys_enc)
295{
296 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
297 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
298 struct sde_hw_intf_cfg *intf_cfg = &wb_enc->intf_cfg;
299
300 memset(intf_cfg, 0, sizeof(struct sde_hw_intf_cfg));
301
302 intf_cfg->intf = SDE_NONE;
303 intf_cfg->wb = hw_wb->idx;
Lloyd Atkinson55987b02016-08-16 16:57:46 -0400304 intf_cfg->mode_3d = sde_encoder_helper_get_3d_blend_mode(phys_enc);
Alan Kwongbb27c092016-07-20 16:41:25 -0400305
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400306 if (phys_enc->hw_ctl && phys_enc->hw_ctl->ops.setup_intf_cfg)
Alan Kwongbb27c092016-07-20 16:41:25 -0400307 phys_enc->hw_ctl->ops.setup_intf_cfg(phys_enc->hw_ctl,
308 intf_cfg);
309}
310
311/**
312 * sde_encoder_phys_wb_atomic_check - verify and fixup given atomic states
313 * @phys_enc: Pointer to physical encoder
314 * @crtc_state: Pointer to CRTC atomic state
315 * @conn_state: Pointer to connector atomic state
316 */
317static int sde_encoder_phys_wb_atomic_check(
318 struct sde_encoder_phys *phys_enc,
319 struct drm_crtc_state *crtc_state,
320 struct drm_connector_state *conn_state)
321{
322 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
323 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
324 const struct sde_wb_cfg *wb_cfg = hw_wb->caps;
325 struct drm_framebuffer *fb;
326 const struct sde_format *fmt;
327 struct sde_rect wb_roi;
328 const struct drm_display_mode *mode = &crtc_state->mode;
329 int rc;
330
331 SDE_DEBUG("[atomic_check:%d,%d,\"%s\",%d,%d]\n",
332 hw_wb->idx - WB_0, mode->base.id, mode->name,
333 mode->hdisplay, mode->vdisplay);
334
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400335 if (!conn_state || !conn_state->connector) {
336 SDE_ERROR("invalid connector state\n");
337 return -EINVAL;
338 } else if (conn_state->connector->status !=
339 connector_status_connected) {
340 SDE_ERROR("connector not connected %d\n",
341 conn_state->connector->status);
342 return -EINVAL;
343 }
344
Alan Kwongbb27c092016-07-20 16:41:25 -0400345 memset(&wb_roi, 0, sizeof(struct sde_rect));
346
347 rc = sde_wb_connector_state_get_output_roi(conn_state, &wb_roi);
348 if (rc) {
349 SDE_ERROR("failed to get roi %d\n", rc);
350 return rc;
351 }
352
353 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi.x, wb_roi.y,
354 wb_roi.w, wb_roi.h);
355
356 fb = sde_wb_connector_state_get_output_fb(conn_state);
357 if (!fb) {
358 SDE_ERROR("no output framebuffer\n");
359 return -EINVAL;
360 }
361
362 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
363 fb->width, fb->height);
364
365 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
366 drm_format_num_planes(fb->pixel_format));
367 if (!fmt) {
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400368 SDE_ERROR("unsupported output pixel format:%x\n",
Alan Kwongbb27c092016-07-20 16:41:25 -0400369 fb->pixel_format);
370 return -EINVAL;
371 }
372
373 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
374 fb->modifier[0]);
375
376 if (SDE_FORMAT_IS_YUV(fmt) &&
377 !(wb_cfg->features & BIT(SDE_WB_YUV_CONFIG))) {
378 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
379 return -EINVAL;
380 }
381
382 if (SDE_FORMAT_IS_UBWC(fmt) &&
383 !(wb_cfg->features & BIT(SDE_WB_UBWC_1_0))) {
384 SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
385 return -EINVAL;
386 }
387
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400388 if (SDE_FORMAT_IS_YUV(fmt) != !!phys_enc->hw_cdm)
389 crtc_state->mode_changed = true;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400390
Alan Kwongbb27c092016-07-20 16:41:25 -0400391 if (wb_roi.w && wb_roi.h) {
392 if (wb_roi.w != mode->hdisplay) {
393 SDE_ERROR("invalid roi w=%d, mode w=%d\n", wb_roi.w,
394 mode->hdisplay);
395 return -EINVAL;
396 } else if (wb_roi.h != mode->vdisplay) {
397 SDE_ERROR("invalid roi h=%d, mode h=%d\n", wb_roi.h,
398 mode->vdisplay);
399 return -EINVAL;
400 } else if (wb_roi.x + wb_roi.w > fb->width) {
401 SDE_ERROR("invalid roi x=%d, w=%d, fb w=%d\n",
402 wb_roi.x, wb_roi.w, fb->width);
403 return -EINVAL;
404 } else if (wb_roi.y + wb_roi.h > fb->height) {
405 SDE_ERROR("invalid roi y=%d, h=%d, fb h=%d\n",
406 wb_roi.y, wb_roi.h, fb->height);
407 return -EINVAL;
408 } else if (wb_roi.w > wb_cfg->sblk->maxlinewidth) {
409 SDE_ERROR("invalid roi w=%d, maxlinewidth=%u\n",
410 wb_roi.w, wb_cfg->sblk->maxlinewidth);
411 return -EINVAL;
412 }
413 } else {
414 if (wb_roi.x || wb_roi.y) {
415 SDE_ERROR("invalid roi x=%d, y=%d\n",
416 wb_roi.x, wb_roi.y);
417 return -EINVAL;
418 } else if (fb->width != mode->hdisplay) {
419 SDE_ERROR("invalid fb w=%d, mode w=%d\n", fb->width,
420 mode->hdisplay);
421 return -EINVAL;
422 } else if (fb->height != mode->vdisplay) {
423 SDE_ERROR("invalid fb h=%d, mode h=%d\n", fb->height,
424 mode->vdisplay);
425 return -EINVAL;
426 } else if (fb->width > wb_cfg->sblk->maxlinewidth) {
427 SDE_ERROR("invalid fb w=%d, maxlinewidth=%u\n",
428 fb->width, wb_cfg->sblk->maxlinewidth);
429 return -EINVAL;
430 }
431 }
432
433 return 0;
434}
435
436/**
437 * sde_encoder_phys_wb_flush - flush hardware update
438 * @phys_enc: Pointer to physical encoder
439 */
440static void sde_encoder_phys_wb_flush(struct sde_encoder_phys *phys_enc)
441{
442 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
443 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
444 struct sde_hw_ctl *hw_ctl = phys_enc->hw_ctl;
445 struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
446 u32 flush_mask = 0;
447
448 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
449
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400450 if (!hw_ctl) {
451 SDE_DEBUG("[wb:%d] no ctl assigned\n", hw_wb->idx - WB_0);
452 return;
453 }
454
Alan Kwongbb27c092016-07-20 16:41:25 -0400455 if (hw_ctl->ops.get_bitmask_wb)
456 hw_ctl->ops.get_bitmask_wb(hw_ctl, &flush_mask, hw_wb->idx);
457
458 if (hw_ctl->ops.get_bitmask_cdm && hw_cdm)
459 hw_ctl->ops.get_bitmask_cdm(hw_ctl, &flush_mask, hw_cdm->idx);
460
461 if (hw_ctl->ops.update_pending_flush)
462 hw_ctl->ops.update_pending_flush(hw_ctl, flush_mask);
463
464 SDE_DEBUG("Flushing CTL_ID %d, flush_mask %x, WB %d\n",
465 hw_ctl->idx - CTL_0, flush_mask, hw_wb->idx - WB_0);
466}
467
468/**
469 * sde_encoder_phys_wb_setup - setup writeback encoder
470 * @phys_enc: Pointer to physical encoder
471 */
472static void sde_encoder_phys_wb_setup(
473 struct sde_encoder_phys *phys_enc)
474{
475 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
476 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
477 struct drm_display_mode mode = phys_enc->cached_mode;
478 struct drm_framebuffer *fb;
479 struct sde_rect *wb_roi = &wb_enc->wb_roi;
480
481 SDE_DEBUG("[mode_set:%d,%d,\"%s\",%d,%d]\n",
482 hw_wb->idx - WB_0, mode.base.id, mode.name,
483 mode.hdisplay, mode.vdisplay);
484
485 memset(wb_roi, 0, sizeof(struct sde_rect));
486
487 fb = sde_wb_get_output_fb(wb_enc->wb_dev);
488 if (!fb) {
489 SDE_DEBUG("no output framebuffer\n");
490 return;
491 }
492
493 SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
494 fb->width, fb->height);
495
496 sde_wb_get_output_roi(wb_enc->wb_dev, wb_roi);
497 if (wb_roi->w == 0 || wb_roi->h == 0) {
498 wb_roi->x = 0;
499 wb_roi->y = 0;
500 wb_roi->w = fb->width;
501 wb_roi->h = fb->height;
502 }
503
504 SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi->x, wb_roi->y,
505 wb_roi->w, wb_roi->h);
506
507 wb_enc->wb_fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
508 drm_format_num_planes(fb->pixel_format));
509 if (!wb_enc->wb_fmt) {
510 SDE_ERROR("unsupported output pixel format: %d\n",
511 fb->pixel_format);
512 return;
513 }
514
515 SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
516 fb->modifier[0]);
517
Alan Kwong5d324e42016-07-28 22:56:18 -0400518 sde_encoder_phys_wb_set_ot_limit(phys_enc);
519
Alan Kwongbb27c092016-07-20 16:41:25 -0400520 sde_encoder_phys_wb_set_traffic_shaper(phys_enc);
521
522 sde_encoder_phys_setup_cdm(phys_enc, fb, wb_enc->wb_fmt, wb_roi);
523
524 sde_encoder_phys_wb_setup_fb(phys_enc, fb, wb_roi);
525
526 sde_encoder_phys_wb_setup_cdp(phys_enc);
527}
528
529/**
530 * sde_encoder_phys_wb_unregister_irq - unregister writeback interrupt handler
531 * @phys_enc: Pointer to physical encoder
532 */
533static int sde_encoder_phys_wb_unregister_irq(
534 struct sde_encoder_phys *phys_enc)
535{
536 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
537 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
538
539 if (wb_enc->bypass_irqreg)
540 return 0;
541
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400542 sde_core_irq_disable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
Alan Kwonga172ef52016-09-27 00:29:10 -0400543 sde_core_irq_unregister_callback(phys_enc->sde_kms, wb_enc->irq_idx,
544 &wb_enc->irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400545
546 SDE_DEBUG("un-register IRQ for wb %d, irq_idx=%d\n",
547 hw_wb->idx - WB_0,
548 wb_enc->irq_idx);
549
550 return 0;
551}
552
553/**
554 * sde_encoder_phys_wb_done_irq - writeback interrupt handler
555 * @arg: Pointer to writeback encoder
556 * @irq_idx: interrupt index
557 */
558static void sde_encoder_phys_wb_done_irq(void *arg, int irq_idx)
559{
560 struct sde_encoder_phys_wb *wb_enc = arg;
561 struct sde_encoder_phys *phys_enc = &wb_enc->base;
562 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
563
564 SDE_DEBUG("[wb:%d,%u]\n", hw_wb->idx - WB_0,
565 wb_enc->frame_count);
566
Alan Kwong628d19e2016-10-31 13:50:13 -0400567 if (phys_enc->parent_ops.handle_frame_done)
568 phys_enc->parent_ops.handle_frame_done(phys_enc->parent,
569 phys_enc, SDE_ENCODER_FRAME_EVENT_DONE);
Alan Kwongbb27c092016-07-20 16:41:25 -0400570
Dhaval Patel81e87882016-10-19 21:41:56 -0700571 phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent,
572 phys_enc);
Alan Kwong628d19e2016-10-31 13:50:13 -0400573
574 complete_all(&wb_enc->wbdone_complete);
Alan Kwongbb27c092016-07-20 16:41:25 -0400575}
576
577/**
578 * sde_encoder_phys_wb_register_irq - register writeback interrupt handler
579 * @phys_enc: Pointer to physical encoder
580 */
581static int sde_encoder_phys_wb_register_irq(struct sde_encoder_phys *phys_enc)
582{
583 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
584 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Alan Kwonga172ef52016-09-27 00:29:10 -0400585 struct sde_irq_callback *irq_cb = &wb_enc->irq_cb;
Alan Kwongbb27c092016-07-20 16:41:25 -0400586 enum sde_intr_type intr_type;
587 int ret = 0;
588
589 if (wb_enc->bypass_irqreg)
590 return 0;
591
592 intr_type = sde_encoder_phys_wb_get_intr_type(hw_wb);
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400593 wb_enc->irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400594 intr_type, hw_wb->idx);
595 if (wb_enc->irq_idx < 0) {
596 SDE_ERROR(
597 "failed to lookup IRQ index for WB_DONE with wb=%d\n",
598 hw_wb->idx - WB_0);
599 return -EINVAL;
600 }
601
Alan Kwonga172ef52016-09-27 00:29:10 -0400602 irq_cb->func = sde_encoder_phys_wb_done_irq;
603 irq_cb->arg = wb_enc;
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400604 ret = sde_core_irq_register_callback(phys_enc->sde_kms,
Alan Kwonga172ef52016-09-27 00:29:10 -0400605 wb_enc->irq_idx, irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400606 if (ret) {
607 SDE_ERROR("failed to register IRQ callback WB_DONE\n");
608 return ret;
609 }
610
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400611 ret = sde_core_irq_enable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
Alan Kwongbb27c092016-07-20 16:41:25 -0400612 if (ret) {
613 SDE_ERROR(
614 "failed to enable IRQ for WB_DONE, wb %d, irq_idx=%d\n",
615 hw_wb->idx - WB_0,
616 wb_enc->irq_idx);
617 wb_enc->irq_idx = -EINVAL;
618
619 /* Unregister callback on IRQ enable failure */
Alan Kwonga172ef52016-09-27 00:29:10 -0400620 sde_core_irq_unregister_callback(phys_enc->sde_kms,
621 wb_enc->irq_idx, irq_cb);
Alan Kwongbb27c092016-07-20 16:41:25 -0400622 return ret;
623 }
624
625 SDE_DEBUG("registered IRQ for wb %d, irq_idx=%d\n",
626 hw_wb->idx - WB_0,
627 wb_enc->irq_idx);
628
629 return ret;
630}
631
632/**
633 * sde_encoder_phys_wb_mode_set - set display mode
634 * @phys_enc: Pointer to physical encoder
635 * @mode: Pointer to requested display mode
636 * @adj_mode: Pointer to adjusted display mode
637 */
638static void sde_encoder_phys_wb_mode_set(
639 struct sde_encoder_phys *phys_enc,
640 struct drm_display_mode *mode,
641 struct drm_display_mode *adj_mode)
642{
643 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400644 struct sde_rm *rm = &phys_enc->sde_kms->rm;
Alan Kwongbb27c092016-07-20 16:41:25 -0400645 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400646 struct sde_rm_hw_iter iter;
647 int i, instance;
Alan Kwongbb27c092016-07-20 16:41:25 -0400648
649 phys_enc->cached_mode = *adj_mode;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400650 instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400651
652 SDE_DEBUG("[mode_set_cache:%d,%d,\"%s\",%d,%d]\n",
653 hw_wb->idx - WB_0, mode->base.id,
654 mode->name, mode->hdisplay, mode->vdisplay);
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400655
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400656 phys_enc->hw_ctl = NULL;
657 phys_enc->hw_cdm = NULL;
658
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400659 /* Retrieve previously allocated HW Resources. CTL shouldn't fail */
660 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
661 for (i = 0; i <= instance; i++) {
662 sde_rm_get_hw(rm, &iter);
663 if (i == instance)
664 phys_enc->hw_ctl = (struct sde_hw_ctl *) iter.hw;
665 }
666
667 if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
668 SDE_ERROR("failed init ctl: %ld\n", PTR_ERR(phys_enc->hw_ctl));
669 phys_enc->hw_ctl = NULL;
670 return;
671 }
672
673 /* CDM is optional */
674 sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CDM);
675 for (i = 0; i <= instance; i++) {
676 sde_rm_get_hw(rm, &iter);
677 if (i == instance)
678 phys_enc->hw_cdm = (struct sde_hw_cdm *) iter.hw;
679 }
680
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400681 if (IS_ERR(phys_enc->hw_cdm)) {
682 SDE_ERROR("CDM required but not allocated: %ld\n",
683 PTR_ERR(phys_enc->hw_cdm));
684 phys_enc->hw_ctl = NULL;
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400685 }
Alan Kwongbb27c092016-07-20 16:41:25 -0400686}
687
688/**
Alan Kwongbb27c092016-07-20 16:41:25 -0400689 * sde_encoder_phys_wb_wait_for_commit_done - wait until request is committed
690 * @phys_enc: Pointer to physical encoder
691 */
692static int sde_encoder_phys_wb_wait_for_commit_done(
693 struct sde_encoder_phys *phys_enc)
694{
695 unsigned long ret;
696 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
697 u32 irq_status;
698 u64 wb_time = 0;
699 int rc = 0;
Alan Kwong5a50a4a2017-01-24 19:12:51 -0800700 u32 timeout = max_t(u32, wb_enc->wbdone_timeout, KICKOFF_TIMEOUT_MS);
Alan Kwongbb27c092016-07-20 16:41:25 -0400701
702 /* Return EWOULDBLOCK since we know the wait isn't necessary */
703 if (WARN_ON(phys_enc->enable_state != SDE_ENC_ENABLED))
704 return -EWOULDBLOCK;
705
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400706 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count);
Alan Kwongbb27c092016-07-20 16:41:25 -0400707
708 ret = wait_for_completion_timeout(&wb_enc->wbdone_complete,
Alan Kwong5a50a4a2017-01-24 19:12:51 -0800709 msecs_to_jiffies(timeout));
Alan Kwongbb27c092016-07-20 16:41:25 -0400710
711 if (!ret) {
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400712 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc),
713 wb_enc->frame_count);
Alan Kwongbb27c092016-07-20 16:41:25 -0400714
Alan Kwongf5dd86c2016-08-09 18:08:17 -0400715 irq_status = sde_core_irq_read(phys_enc->sde_kms,
Alan Kwongbb27c092016-07-20 16:41:25 -0400716 wb_enc->irq_idx, true);
717 if (irq_status) {
718 SDE_DEBUG("wb:%d done but irq not triggered\n",
719 wb_enc->wb_dev->wb_idx - WB_0);
720 sde_encoder_phys_wb_done_irq(wb_enc, wb_enc->irq_idx);
721 } else {
722 SDE_ERROR("wb:%d kickoff timed out\n",
723 wb_enc->wb_dev->wb_idx - WB_0);
Alan Kwong628d19e2016-10-31 13:50:13 -0400724 if (phys_enc->parent_ops.handle_frame_done)
725 phys_enc->parent_ops.handle_frame_done(
726 phys_enc->parent, phys_enc,
727 SDE_ENCODER_FRAME_EVENT_ERROR);
Alan Kwongbb27c092016-07-20 16:41:25 -0400728 rc = -ETIMEDOUT;
729 }
730 }
731
732 sde_encoder_phys_wb_unregister_irq(phys_enc);
733
734 if (!rc)
735 wb_enc->end_time = ktime_get();
736
737 /* once operation is done, disable traffic shaper */
738 if (wb_enc->wb_cfg.ts_cfg.en && wb_enc->hw_wb &&
739 wb_enc->hw_wb->ops.setup_trafficshaper) {
740 wb_enc->wb_cfg.ts_cfg.en = false;
741 wb_enc->hw_wb->ops.setup_trafficshaper(
742 wb_enc->hw_wb, &wb_enc->wb_cfg);
743 }
744
745 /* remove vote for iommu/clk/bus */
746 wb_enc->frame_count++;
747
748 if (!rc) {
749 wb_time = (u64)ktime_to_us(wb_enc->end_time) -
750 (u64)ktime_to_us(wb_enc->start_time);
751 SDE_DEBUG("wb:%d took %llu us\n",
752 wb_enc->wb_dev->wb_idx - WB_0, wb_time);
753 }
754
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400755 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count,
756 wb_time);
Alan Kwongbb27c092016-07-20 16:41:25 -0400757
758 return rc;
759}
760
761/**
762 * sde_encoder_phys_wb_prepare_for_kickoff - pre-kickoff processing
763 * @phys_enc: Pointer to physical encoder
Alan Kwongbb27c092016-07-20 16:41:25 -0400764 */
765static void sde_encoder_phys_wb_prepare_for_kickoff(
Lloyd Atkinsonaa0dce92016-11-23 20:16:47 -0500766 struct sde_encoder_phys *phys_enc)
Alan Kwongbb27c092016-07-20 16:41:25 -0400767{
768 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
769 int ret;
770
771 SDE_DEBUG("[wb:%d,%u]\n", wb_enc->hw_wb->idx - WB_0,
772 wb_enc->kickoff_count);
773
Alan Kwongbb27c092016-07-20 16:41:25 -0400774 reinit_completion(&wb_enc->wbdone_complete);
775
776 ret = sde_encoder_phys_wb_register_irq(phys_enc);
777 if (ret) {
778 SDE_ERROR("failed to register irq %d\n", ret);
779 return;
780 }
781
782 wb_enc->kickoff_count++;
783
784 /* set OT limit & enable traffic shaper */
785 sde_encoder_phys_wb_setup(phys_enc);
786
787 sde_encoder_phys_wb_flush(phys_enc);
788
789 /* vote for iommu/clk/bus */
790 wb_enc->start_time = ktime_get();
791
Lloyd Atkinsonaa0dce92016-11-23 20:16:47 -0500792 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->kickoff_count);
Alan Kwongbb27c092016-07-20 16:41:25 -0400793}
794
795/**
796 * sde_encoder_phys_wb_handle_post_kickoff - post-kickoff processing
797 * @phys_enc: Pointer to physical encoder
798 */
799static void sde_encoder_phys_wb_handle_post_kickoff(
800 struct sde_encoder_phys *phys_enc)
801{
802 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
803
804 SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0);
805
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400806 SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc));
Alan Kwongbb27c092016-07-20 16:41:25 -0400807}
808
809/**
810 * sde_encoder_phys_wb_enable - enable writeback encoder
811 * @phys_enc: Pointer to physical encoder
812 */
813static void sde_encoder_phys_wb_enable(struct sde_encoder_phys *phys_enc)
814{
815 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
816 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
Alan Kwong74e8ba32016-09-30 14:25:16 -0400817 struct drm_device *dev;
Alan Kwongbb27c092016-07-20 16:41:25 -0400818 struct drm_connector *connector;
819
820 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
821
Alan Kwong74e8ba32016-09-30 14:25:16 -0400822 if (!wb_enc->base.parent || !wb_enc->base.parent->dev) {
823 SDE_ERROR("invalid drm device\n");
824 return;
825 }
826 dev = wb_enc->base.parent->dev;
827
Alan Kwongbb27c092016-07-20 16:41:25 -0400828 /* find associated writeback connector */
Alan Kwong74e8ba32016-09-30 14:25:16 -0400829 mutex_lock(&dev->mode_config.mutex);
Alan Kwongbb27c092016-07-20 16:41:25 -0400830 drm_for_each_connector(connector, phys_enc->parent->dev) {
831 if (connector->encoder == phys_enc->parent)
832 break;
833 }
Alan Kwong74e8ba32016-09-30 14:25:16 -0400834 mutex_unlock(&dev->mode_config.mutex);
835
Alan Kwongbb27c092016-07-20 16:41:25 -0400836 if (!connector || connector->encoder != phys_enc->parent) {
837 SDE_ERROR("failed to find writeback connector\n");
838 return;
839 }
840 wb_enc->wb_dev = sde_wb_connector_get_wb(connector);
841
842 phys_enc->enable_state = SDE_ENC_ENABLED;
843}
844
845/**
846 * sde_encoder_phys_wb_disable - disable writeback encoder
847 * @phys_enc: Pointer to physical encoder
848 */
849static void sde_encoder_phys_wb_disable(struct sde_encoder_phys *phys_enc)
850{
851 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
852 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
853
854 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
855
856 if (phys_enc->enable_state == SDE_ENC_DISABLED) {
857 SDE_ERROR("encoder is already disabled\n");
858 return;
859 }
860
861 if (wb_enc->frame_count != wb_enc->kickoff_count) {
862 SDE_DEBUG("[wait_for_done: wb:%d, frame:%u, kickoff:%u]\n",
863 hw_wb->idx - WB_0, wb_enc->frame_count,
864 wb_enc->kickoff_count);
865 sde_encoder_phys_wb_wait_for_commit_done(phys_enc);
866 }
867
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400868 if (phys_enc->hw_cdm && phys_enc->hw_cdm->ops.disable) {
869 SDE_DEBUG_DRIVER("[cdm_disable]\n");
870 phys_enc->hw_cdm->ops.disable(phys_enc->hw_cdm);
871 }
872
Alan Kwongbb27c092016-07-20 16:41:25 -0400873 phys_enc->enable_state = SDE_ENC_DISABLED;
874}
875
876/**
877 * sde_encoder_phys_wb_get_hw_resources - get hardware resources
878 * @phys_enc: Pointer to physical encoder
879 * @hw_res: Pointer to encoder resources
880 */
881static void sde_encoder_phys_wb_get_hw_resources(
882 struct sde_encoder_phys *phys_enc,
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400883 struct sde_encoder_hw_resources *hw_res,
884 struct drm_connector_state *conn_state)
Alan Kwongbb27c092016-07-20 16:41:25 -0400885{
886 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
Clarence Ip03521982016-08-26 10:49:47 -0400887 struct sde_hw_wb *hw_wb;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400888 struct drm_framebuffer *fb;
889 const struct sde_format *fmt;
Alan Kwongbb27c092016-07-20 16:41:25 -0400890
Clarence Ip03521982016-08-26 10:49:47 -0400891 if (!phys_enc) {
892 SDE_ERROR("invalid encoder\n");
893 return;
894 }
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400895
896 fb = sde_wb_connector_state_get_output_fb(conn_state);
897 if (!fb) {
898 SDE_ERROR("no output framebuffer\n");
899 return;
900 }
901
902 fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
903 drm_format_num_planes(fb->pixel_format));
904 if (!fmt) {
905 SDE_ERROR("unsupported output pixel format:%d\n",
906 fb->pixel_format);
907 return;
908 }
909
Clarence Ip03521982016-08-26 10:49:47 -0400910 hw_wb = wb_enc->hw_wb;
Clarence Ip03521982016-08-26 10:49:47 -0400911 hw_res->wbs[hw_wb->idx - WB_0] = phys_enc->intf_mode;
Alan Kwong4c3cf4c2016-09-25 20:08:09 -0400912 hw_res->needs_cdm = SDE_FORMAT_IS_YUV(fmt);
913 SDE_DEBUG("[wb:%d] intf_mode=%d needs_cdm=%d\n", hw_wb->idx - WB_0,
914 hw_res->wbs[hw_wb->idx - WB_0],
915 hw_res->needs_cdm);
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400916}
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400917
Alan Kwongbb27c092016-07-20 16:41:25 -0400918#ifdef CONFIG_DEBUG_FS
919/**
920 * sde_encoder_phys_wb_init_debugfs - initialize writeback encoder debugfs
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700921 * @phys_enc: Pointer to physical encoder
922 * @debugfs_root: Pointer to virtual encoder's debugfs_root dir
Alan Kwongbb27c092016-07-20 16:41:25 -0400923 */
924static int sde_encoder_phys_wb_init_debugfs(
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700925 struct sde_encoder_phys *phys_enc, struct dentry *debugfs_root)
Alan Kwongbb27c092016-07-20 16:41:25 -0400926{
927 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
928
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700929 if (!phys_enc || !wb_enc->hw_wb || !debugfs_root)
Alan Kwongbb27c092016-07-20 16:41:25 -0400930 return -EINVAL;
931
Alan Kwongbb27c092016-07-20 16:41:25 -0400932 if (!debugfs_create_u32("wbdone_timeout", 0644,
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700933 debugfs_root, &wb_enc->wbdone_timeout)) {
Alan Kwongbb27c092016-07-20 16:41:25 -0400934 SDE_ERROR("failed to create debugfs/wbdone_timeout\n");
935 return -ENOMEM;
936 }
937
938 if (!debugfs_create_u32("bypass_irqreg", 0644,
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700939 debugfs_root, &wb_enc->bypass_irqreg)) {
Alan Kwongbb27c092016-07-20 16:41:25 -0400940 SDE_ERROR("failed to create debugfs/bypass_irqreg\n");
941 return -ENOMEM;
942 }
943
944 return 0;
945}
Alan Kwongbb27c092016-07-20 16:41:25 -0400946#else
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700947static int sde_encoder_phys_wb_init_debugfs(
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700948 struct sde_encoder_phys *phys_enc, struct dentry *debugfs_root)
Alan Kwongbb27c092016-07-20 16:41:25 -0400949{
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700950 return 0;
Alan Kwongbb27c092016-07-20 16:41:25 -0400951}
Alan Kwongbb27c092016-07-20 16:41:25 -0400952#endif
953
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700954static int sde_encoder_phys_wb_late_register(struct sde_encoder_phys *phys_enc,
955 struct dentry *debugfs_root)
956{
957 return sde_encoder_phys_wb_init_debugfs(phys_enc, debugfs_root);
958}
959
Alan Kwongbb27c092016-07-20 16:41:25 -0400960/**
961 * sde_encoder_phys_wb_destroy - destroy writeback encoder
962 * @phys_enc: Pointer to physical encoder
963 */
964static void sde_encoder_phys_wb_destroy(struct sde_encoder_phys *phys_enc)
965{
966 struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
967 struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
968
969 SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
970
971 if (!phys_enc)
972 return;
973
Alan Kwongbb27c092016-07-20 16:41:25 -0400974 kfree(wb_enc);
975}
976
977/**
978 * sde_encoder_phys_wb_init_ops - initialize writeback operations
979 * @ops: Pointer to encoder operation table
980 */
981static void sde_encoder_phys_wb_init_ops(struct sde_encoder_phys_ops *ops)
982{
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700983 ops->late_register = sde_encoder_phys_wb_late_register;
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400984 ops->is_master = sde_encoder_phys_wb_is_master;
Alan Kwongbb27c092016-07-20 16:41:25 -0400985 ops->mode_set = sde_encoder_phys_wb_mode_set;
986 ops->enable = sde_encoder_phys_wb_enable;
987 ops->disable = sde_encoder_phys_wb_disable;
988 ops->destroy = sde_encoder_phys_wb_destroy;
989 ops->atomic_check = sde_encoder_phys_wb_atomic_check;
990 ops->get_hw_resources = sde_encoder_phys_wb_get_hw_resources;
Alan Kwongbb27c092016-07-20 16:41:25 -0400991 ops->wait_for_commit_done = sde_encoder_phys_wb_wait_for_commit_done;
992 ops->prepare_for_kickoff = sde_encoder_phys_wb_prepare_for_kickoff;
993 ops->handle_post_kickoff = sde_encoder_phys_wb_handle_post_kickoff;
Clarence Ip110d15c2016-08-16 14:44:41 -0400994 ops->trigger_start = sde_encoder_helper_trigger_start;
Lloyd Atkinson8c49c582016-11-18 14:23:54 -0500995 ops->hw_reset = sde_encoder_helper_hw_reset;
Alan Kwongbb27c092016-07-20 16:41:25 -0400996}
997
998/**
999 * sde_encoder_phys_wb_init - initialize writeback encoder
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001000 * @init: Pointer to init info structure with initialization params
Alan Kwongbb27c092016-07-20 16:41:25 -04001001 */
1002struct sde_encoder_phys *sde_encoder_phys_wb_init(
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001003 struct sde_enc_phys_init_params *p)
Alan Kwongbb27c092016-07-20 16:41:25 -04001004{
1005 struct sde_encoder_phys *phys_enc;
1006 struct sde_encoder_phys_wb *wb_enc;
1007 struct sde_hw_mdp *hw_mdp;
1008 int ret = 0;
1009
1010 SDE_DEBUG("\n");
1011
1012 wb_enc = kzalloc(sizeof(*wb_enc), GFP_KERNEL);
1013 if (!wb_enc) {
1014 ret = -ENOMEM;
1015 goto fail_alloc;
1016 }
1017 wb_enc->irq_idx = -EINVAL;
Lloyd Atkinsonaa0dce92016-11-23 20:16:47 -05001018 wb_enc->wbdone_timeout = KICKOFF_TIMEOUT_MS;
Alan Kwongbb27c092016-07-20 16:41:25 -04001019 init_completion(&wb_enc->wbdone_complete);
1020
1021 phys_enc = &wb_enc->base;
1022
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001023 if (p->sde_kms->vbif[VBIF_NRT]) {
Alan Kwongbb27c092016-07-20 16:41:25 -04001024 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001025 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001026 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001027 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_NRT_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001028 } else {
1029 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_UNSECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001030 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_UNSECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001031 wb_enc->mmu_id[SDE_IOMMU_DOMAIN_SECURE] =
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001032 p->sde_kms->mmu_id[MSM_SMMU_DOMAIN_SECURE];
Alan Kwongbb27c092016-07-20 16:41:25 -04001033 }
1034
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001035 hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
Alan Kwongbb27c092016-07-20 16:41:25 -04001036 if (IS_ERR_OR_NULL(hw_mdp)) {
1037 ret = PTR_ERR(hw_mdp);
1038 SDE_ERROR("failed to init hw_top: %d\n", ret);
1039 goto fail_mdp_init;
1040 }
1041 phys_enc->hw_mdptop = hw_mdp;
1042
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001043 /**
1044 * hw_wb resource permanently assigned to this encoder
1045 * Other resources allocated at atomic commit time by use case
1046 */
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001047 if (p->wb_idx != SDE_NONE) {
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001048 struct sde_rm_hw_iter iter;
Alan Kwongbb27c092016-07-20 16:41:25 -04001049
Lloyd Atkinson11f34442016-08-11 11:19:52 -04001050 sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_WB);
1051 while (sde_rm_get_hw(&p->sde_kms->rm, &iter)) {
1052 struct sde_hw_wb *hw_wb = (struct sde_hw_wb *)iter.hw;
1053
1054 if (hw_wb->idx == p->wb_idx) {
1055 wb_enc->hw_wb = hw_wb;
1056 break;
1057 }
1058 }
1059
1060 if (!wb_enc->hw_wb) {
1061 ret = -EINVAL;
1062 SDE_ERROR("failed to init hw_wb%d\n", p->wb_idx - WB_0);
Alan Kwongbb27c092016-07-20 16:41:25 -04001063 goto fail_wb_init;
1064 }
Alan Kwongbb27c092016-07-20 16:41:25 -04001065 } else {
1066 ret = -EINVAL;
1067 SDE_ERROR("invalid wb_idx\n");
1068 goto fail_wb_check;
1069 }
1070
Alan Kwongbb27c092016-07-20 16:41:25 -04001071 sde_encoder_phys_wb_init_ops(&phys_enc->ops);
Lloyd Atkinson6ef6cb52016-07-06 11:49:18 -04001072 phys_enc->parent = p->parent;
1073 phys_enc->parent_ops = p->parent_ops;
1074 phys_enc->sde_kms = p->sde_kms;
1075 phys_enc->split_role = p->split_role;
Clarence Ip03521982016-08-26 10:49:47 -04001076 phys_enc->intf_mode = INTF_MODE_WB_LINE;
Dhaval Patel81e87882016-10-19 21:41:56 -07001077 phys_enc->intf_idx = p->intf_idx;
Lloyd Atkinson7d070942016-07-26 18:35:12 -04001078 phys_enc->enc_spinlock = p->enc_spinlock;
Alan Kwonga172ef52016-09-27 00:29:10 -04001079 INIT_LIST_HEAD(&wb_enc->irq_cb.list);
Alan Kwongbb27c092016-07-20 16:41:25 -04001080
Alan Kwongbb27c092016-07-20 16:41:25 -04001081 SDE_DEBUG("Created sde_encoder_phys_wb for wb %d\n",
1082 wb_enc->hw_wb->idx - WB_0);
1083
1084 return phys_enc;
1085
Alan Kwongbb27c092016-07-20 16:41:25 -04001086fail_wb_init:
1087fail_wb_check:
Alan Kwongbb27c092016-07-20 16:41:25 -04001088fail_mdp_init:
1089 kfree(wb_enc);
1090fail_alloc:
1091 return ERR_PTR(ret);
1092}
1093