.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * i.MX IPUv3 DP Overlay Planes |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2013 Philipp Zabel, Pengutronix |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or |
---|
7 | | - * modify it under the terms of the GNU General Public License |
---|
8 | | - * as published by the Free Software Foundation; either version 2 |
---|
9 | | - * of the License, or (at your option) any later version. |
---|
10 | | - * This program is distributed in the hope that it will be useful, |
---|
11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | | - * GNU General Public License for more details. |
---|
14 | 6 | */ |
---|
15 | 7 | |
---|
16 | | -#include <drm/drmP.h> |
---|
17 | 8 | #include <drm/drm_atomic.h> |
---|
18 | 9 | #include <drm/drm_atomic_helper.h> |
---|
19 | 10 | #include <drm/drm_fb_cma_helper.h> |
---|
| 11 | +#include <drm/drm_fourcc.h> |
---|
20 | 12 | #include <drm/drm_gem_cma_helper.h> |
---|
21 | 13 | #include <drm/drm_gem_framebuffer_helper.h> |
---|
22 | 14 | #include <drm/drm_plane_helper.h> |
---|
23 | 15 | |
---|
24 | | -#include "video/imx-ipu-v3.h" |
---|
| 16 | +#include <video/imx-ipu-v3.h> |
---|
| 17 | + |
---|
25 | 18 | #include "imx-drm.h" |
---|
26 | 19 | #include "ipuv3-plane.h" |
---|
27 | 20 | |
---|
.. | .. |
---|
123 | 116 | cma_obj = drm_fb_cma_get_gem_obj(fb, 1); |
---|
124 | 117 | BUG_ON(!cma_obj); |
---|
125 | 118 | |
---|
126 | | - x /= drm_format_horz_chroma_subsampling(fb->format->format); |
---|
127 | | - y /= drm_format_vert_chroma_subsampling(fb->format->format); |
---|
| 119 | + x /= fb->format->hsub; |
---|
| 120 | + y /= fb->format->vsub; |
---|
128 | 121 | |
---|
129 | 122 | return cma_obj->paddr + fb->offsets[1] + fb->pitches[1] * y + |
---|
130 | 123 | fb->format->cpp[1] * x - eba; |
---|
.. | .. |
---|
142 | 135 | cma_obj = drm_fb_cma_get_gem_obj(fb, 2); |
---|
143 | 136 | BUG_ON(!cma_obj); |
---|
144 | 137 | |
---|
145 | | - x /= drm_format_horz_chroma_subsampling(fb->format->format); |
---|
146 | | - y /= drm_format_vert_chroma_subsampling(fb->format->format); |
---|
| 138 | + x /= fb->format->hsub; |
---|
| 139 | + y /= fb->format->vsub; |
---|
147 | 140 | |
---|
148 | 141 | return cma_obj->paddr + fb->offsets[2] + fb->pitches[2] * y + |
---|
149 | 142 | fb->format->cpp[2] * x - eba; |
---|
.. | .. |
---|
236 | 229 | |
---|
237 | 230 | void ipu_plane_disable(struct ipu_plane *ipu_plane, bool disable_dp_channel) |
---|
238 | 231 | { |
---|
| 232 | + int ret; |
---|
| 233 | + |
---|
239 | 234 | DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__); |
---|
240 | 235 | |
---|
241 | | - ipu_idmac_wait_busy(ipu_plane->ipu_ch, 50); |
---|
| 236 | + ret = ipu_idmac_wait_busy(ipu_plane->ipu_ch, 50); |
---|
| 237 | + if (ret == -ETIMEDOUT) { |
---|
| 238 | + DRM_ERROR("[PLANE:%d] IDMAC timeout\n", |
---|
| 239 | + ipu_plane->base.base.id); |
---|
| 240 | + } |
---|
242 | 241 | |
---|
243 | 242 | if (ipu_plane->dp && disable_dp_channel) |
---|
244 | 243 | ipu_dp_disable_channel(ipu_plane->dp, false); |
---|
.. | .. |
---|
275 | 274 | |
---|
276 | 275 | static void ipu_plane_state_reset(struct drm_plane *plane) |
---|
277 | 276 | { |
---|
| 277 | + unsigned int zpos = (plane->type == DRM_PLANE_TYPE_PRIMARY) ? 0 : 1; |
---|
278 | 278 | struct ipu_plane_state *ipu_state; |
---|
279 | 279 | |
---|
280 | 280 | if (plane->state) { |
---|
281 | 281 | ipu_state = to_ipu_plane_state(plane->state); |
---|
282 | 282 | __drm_atomic_helper_plane_destroy_state(plane->state); |
---|
283 | 283 | kfree(ipu_state); |
---|
| 284 | + plane->state = NULL; |
---|
284 | 285 | } |
---|
285 | 286 | |
---|
286 | 287 | ipu_state = kzalloc(sizeof(*ipu_state), GFP_KERNEL); |
---|
287 | 288 | |
---|
288 | 289 | if (ipu_state) { |
---|
289 | | - ipu_state->base.plane = plane; |
---|
290 | | - ipu_state->base.rotation = DRM_MODE_ROTATE_0; |
---|
| 290 | + __drm_atomic_helper_plane_reset(plane, &ipu_state->base); |
---|
| 291 | + ipu_state->base.zpos = zpos; |
---|
| 292 | + ipu_state->base.normalized_zpos = zpos; |
---|
291 | 293 | } |
---|
292 | | - |
---|
293 | | - plane->state = &ipu_state->base; |
---|
294 | 294 | } |
---|
295 | 295 | |
---|
296 | 296 | static struct drm_plane_state * |
---|
.. | .. |
---|
353 | 353 | struct drm_framebuffer *old_fb = old_state->fb; |
---|
354 | 354 | unsigned long eba, ubo, vbo, old_ubo, old_vbo, alpha_eba; |
---|
355 | 355 | bool can_position = (plane->type == DRM_PLANE_TYPE_OVERLAY); |
---|
356 | | - int hsub, vsub; |
---|
357 | 356 | int ret; |
---|
358 | 357 | |
---|
359 | 358 | /* Ok to disable */ |
---|
360 | 359 | if (!fb) |
---|
361 | 360 | return 0; |
---|
362 | 361 | |
---|
363 | | - if (!state->crtc) |
---|
| 362 | + if (WARN_ON(!state->crtc)) |
---|
364 | 363 | return -EINVAL; |
---|
365 | 364 | |
---|
366 | 365 | crtc_state = |
---|
.. | .. |
---|
448 | 447 | if (fb->pitches[1] != fb->pitches[2]) |
---|
449 | 448 | return -EINVAL; |
---|
450 | 449 | |
---|
451 | | - /* fall-through */ |
---|
| 450 | + fallthrough; |
---|
452 | 451 | case DRM_FORMAT_NV12: |
---|
453 | 452 | case DRM_FORMAT_NV16: |
---|
454 | 453 | ubo = drm_plane_state_to_ubo(state); |
---|
.. | .. |
---|
472 | 471 | * The x/y offsets must be even in case of horizontal/vertical |
---|
473 | 472 | * chroma subsampling. |
---|
474 | 473 | */ |
---|
475 | | - hsub = drm_format_horz_chroma_subsampling(fb->format->format); |
---|
476 | | - vsub = drm_format_vert_chroma_subsampling(fb->format->format); |
---|
477 | | - if (((state->src.x1 >> 16) & (hsub - 1)) || |
---|
478 | | - ((state->src.y1 >> 16) & (vsub - 1))) |
---|
| 474 | + if (((state->src.x1 >> 16) & (fb->format->hsub - 1)) || |
---|
| 475 | + ((state->src.y1 >> 16) & (fb->format->vsub - 1))) |
---|
479 | 476 | return -EINVAL; |
---|
480 | 477 | break; |
---|
481 | 478 | case DRM_FORMAT_RGB565_A8: |
---|
.. | .. |
---|
565 | 562 | if (ipu_plane->dp_flow == IPU_DP_FLOW_SYNC_FG) |
---|
566 | 563 | ipu_dp_set_window_pos(ipu_plane->dp, dst->x1, dst->y1); |
---|
567 | 564 | |
---|
| 565 | + switch (ipu_plane->dp_flow) { |
---|
| 566 | + case IPU_DP_FLOW_SYNC_BG: |
---|
| 567 | + if (state->normalized_zpos == 1) { |
---|
| 568 | + ipu_dp_set_global_alpha(ipu_plane->dp, |
---|
| 569 | + !fb->format->has_alpha, 0xff, |
---|
| 570 | + true); |
---|
| 571 | + } else { |
---|
| 572 | + ipu_dp_set_global_alpha(ipu_plane->dp, true, 0, true); |
---|
| 573 | + } |
---|
| 574 | + break; |
---|
| 575 | + case IPU_DP_FLOW_SYNC_FG: |
---|
| 576 | + if (state->normalized_zpos == 1) { |
---|
| 577 | + ipu_dp_set_global_alpha(ipu_plane->dp, |
---|
| 578 | + !fb->format->has_alpha, 0xff, |
---|
| 579 | + false); |
---|
| 580 | + } |
---|
| 581 | + break; |
---|
| 582 | + } |
---|
| 583 | + |
---|
568 | 584 | eba = drm_plane_state_to_eba(state, 0); |
---|
569 | 585 | |
---|
570 | 586 | /* |
---|
.. | .. |
---|
600 | 616 | switch (ipu_plane->dp_flow) { |
---|
601 | 617 | case IPU_DP_FLOW_SYNC_BG: |
---|
602 | 618 | ipu_dp_setup_channel(ipu_plane->dp, ics, IPUV3_COLORSPACE_RGB); |
---|
603 | | - ipu_dp_set_global_alpha(ipu_plane->dp, true, 0, true); |
---|
604 | 619 | break; |
---|
605 | 620 | case IPU_DP_FLOW_SYNC_FG: |
---|
606 | 621 | ipu_dp_setup_channel(ipu_plane->dp, ics, |
---|
607 | 622 | IPUV3_COLORSPACE_UNKNOWN); |
---|
608 | | - /* Enable local alpha on partial plane */ |
---|
609 | | - switch (fb->format->format) { |
---|
610 | | - case DRM_FORMAT_ARGB1555: |
---|
611 | | - case DRM_FORMAT_ABGR1555: |
---|
612 | | - case DRM_FORMAT_RGBA5551: |
---|
613 | | - case DRM_FORMAT_BGRA5551: |
---|
614 | | - case DRM_FORMAT_ARGB4444: |
---|
615 | | - case DRM_FORMAT_ARGB8888: |
---|
616 | | - case DRM_FORMAT_ABGR8888: |
---|
617 | | - case DRM_FORMAT_RGBA8888: |
---|
618 | | - case DRM_FORMAT_BGRA8888: |
---|
619 | | - case DRM_FORMAT_RGB565_A8: |
---|
620 | | - case DRM_FORMAT_BGR565_A8: |
---|
621 | | - case DRM_FORMAT_RGB888_A8: |
---|
622 | | - case DRM_FORMAT_BGR888_A8: |
---|
623 | | - case DRM_FORMAT_RGBX8888_A8: |
---|
624 | | - case DRM_FORMAT_BGRX8888_A8: |
---|
625 | | - ipu_dp_set_global_alpha(ipu_plane->dp, false, 0, false); |
---|
626 | | - break; |
---|
627 | | - default: |
---|
628 | | - ipu_dp_set_global_alpha(ipu_plane->dp, true, 0, true); |
---|
629 | | - break; |
---|
630 | | - } |
---|
| 623 | + break; |
---|
631 | 624 | } |
---|
632 | 625 | |
---|
633 | 626 | ipu_dmfc_config_wait4eot(ipu_plane->dmfc, drm_rect_width(dst)); |
---|
.. | .. |
---|
643 | 636 | ipu_cpmem_set_fmt(ipu_plane->ipu_ch, fb->format->format); |
---|
644 | 637 | ipu_cpmem_set_burstsize(ipu_plane->ipu_ch, burstsize); |
---|
645 | 638 | ipu_cpmem_set_high_priority(ipu_plane->ipu_ch); |
---|
| 639 | + ipu_idmac_enable_watermark(ipu_plane->ipu_ch, true); |
---|
646 | 640 | ipu_idmac_set_double_buffer(ipu_plane->ipu_ch, 1); |
---|
647 | 641 | ipu_cpmem_set_stride(ipu_plane->ipu_ch, fb->pitches[0]); |
---|
648 | 642 | ipu_cpmem_set_axi_id(ipu_plane->ipu_ch, axi_id); |
---|
.. | .. |
---|
723 | 717 | .atomic_update = ipu_plane_atomic_update, |
---|
724 | 718 | }; |
---|
725 | 719 | |
---|
| 720 | +bool ipu_plane_atomic_update_pending(struct drm_plane *plane) |
---|
| 721 | +{ |
---|
| 722 | + struct ipu_plane *ipu_plane = to_ipu_plane(plane); |
---|
| 723 | + struct drm_plane_state *state = plane->state; |
---|
| 724 | + struct ipu_plane_state *ipu_state = to_ipu_plane_state(state); |
---|
| 725 | + |
---|
| 726 | + /* disabled crtcs must not block the update */ |
---|
| 727 | + if (!state->crtc) |
---|
| 728 | + return false; |
---|
| 729 | + |
---|
| 730 | + if (ipu_state->use_pre) |
---|
| 731 | + return ipu_prg_channel_configure_pending(ipu_plane->ipu_ch); |
---|
| 732 | + |
---|
| 733 | + /* |
---|
| 734 | + * Pretend no update is pending in the non-PRE/PRG case. For this to |
---|
| 735 | + * happen, an atomic update would have to be deferred until after the |
---|
| 736 | + * start of the next frame and simultaneously interrupt latency would |
---|
| 737 | + * have to be high enough to let the atomic update finish and issue an |
---|
| 738 | + * event before the previous end of frame interrupt handler can be |
---|
| 739 | + * executed. |
---|
| 740 | + */ |
---|
| 741 | + return false; |
---|
| 742 | +} |
---|
726 | 743 | int ipu_planes_assign_pre(struct drm_device *dev, |
---|
727 | 744 | struct drm_atomic_state *state) |
---|
728 | 745 | { |
---|
.. | .. |
---|
811 | 828 | { |
---|
812 | 829 | struct ipu_plane *ipu_plane; |
---|
813 | 830 | const uint64_t *modifiers = ipu_format_modifiers; |
---|
| 831 | + unsigned int zpos = (type == DRM_PLANE_TYPE_PRIMARY) ? 0 : 1; |
---|
814 | 832 | int ret; |
---|
815 | 833 | |
---|
816 | 834 | DRM_DEBUG_KMS("channel %d, dp flow %d, possible_crtcs=0x%x\n", |
---|
.. | .. |
---|
841 | 859 | |
---|
842 | 860 | drm_plane_helper_add(&ipu_plane->base, &ipu_plane_helper_funcs); |
---|
843 | 861 | |
---|
| 862 | + if (dp == IPU_DP_FLOW_SYNC_BG || dp == IPU_DP_FLOW_SYNC_FG) |
---|
| 863 | + drm_plane_create_zpos_property(&ipu_plane->base, zpos, 0, 1); |
---|
| 864 | + else |
---|
| 865 | + drm_plane_create_zpos_immutable_property(&ipu_plane->base, 0); |
---|
| 866 | + |
---|
844 | 867 | return ipu_plane; |
---|
845 | 868 | } |
---|