core:
 - uapi: error out EBUSY when existing master
 - uapi: rework SET/DROP MASTER permission handling
 - remove drm_pci.h
 - drm_pci* are now legacy
 - introduced managed DRM resources
 - subclassing support for drm_framebuffer
 - simple encoder helper
 - edid improvements
 - vblank + writeback documentation improved
 - drm/mm - optimise tree searches
 - port drivers to use devm_drm_dev_alloc
 
 dma-buf:
 - add flag for p2p buffer support
 
 mst:
 - ACT timeout improvements
 - remove drm_dp_mst_has_audio
 - don't use 2nd TX slot - spec recommends against it
 
 bridge:
 - dw-hdmi various improvements
 - chrontel ch7033 support
 - fix stack issues with old gcc
 
 hdmi:
 - add unpack function for drm infoframe
 
 fbdev:
 - misc fbdev driver fixes
 
 i915:
 - uapi: global sseu pinning
 - uapi: OA buffer polling
 - uapi: remove generated perf code
 - uapi: per-engine default property values in sysfs
 - Tigerlake GEN12 enabled.
 - Lots of gem refactoring
 - Tigerlake enablement patches
 - move to drm_device logging
 - Icelake gamma HW readout
 - push MST link retrain to hotplug work
 - bandwidth atomic helpers
 - ICL fixes
 - RPS/GT refactoring
 - Cherryview full-ppgtt support
 - i915 locking guidelines documented
 - require linear fb stride to be 512 multiple on gen9
 - Tigerlake SAGV support
 
 amdgpu:
 - uapi: encrypted GPU memory handling
 - uapi: add MEM_SYNC IB flag
 - p2p dma-buf support
 - export VRAM dma-bufs
 - FRU chip access support
 - RAS/SR-IOV updates
 - Powerplay locking fixes
 - VCN DPG (powergating) enablement
 - GFX10 clockgating fixes
 - DC fixes
 - GPU reset fixes
 - navi SDMA fix
 - expose FP16 for modesetting
 - DP 1.4 compliance fixes
 - gfx10 soft recovery
 - Improved Critical Thermal Faults handling
 - resizable BAR on gmc10
 
 amdkfd:
 - uapi: GWS resource management
 - track GPU memory per process
 - report PCI domain in topology
 
 radeon:
 - safe reg list generator fixes
 
 nouveau:
 - HD audio fixes on recent systems
 - vGPU detection (fail probe if we're on one, for now)
 - Interlaced mode fixes (mostly avoidance on Turing, which doesn't support it)
 - SVM improvements/fixes
 - NVIDIA format modifier support
 - Misc other fixes.
 
 adv7511:
 - HDMI SPDIF support
 
 ast:
 - allocate crtc state size
 - fix double assignment
 - fix suspend
 
 bochs:
 - drop connector register
 
 cirrus:
 - move to tiny drivers.
 
 exynos:
 - fix imported dma-buf mapping
 - enable runtime PM
 - fixes and cleanups
 
 mediatek:
 - DPI pin mode swap
 - config mipi_tx current/impedance
 
 lima:
 - devfreq + cooling device support
 - task handling improvements
 - runtime PM support
 
 pl111:
 - vexpress init improvements
 - fix module auto-load
 
 rcar-du:
 - DT bindings conversion to YAML
 - Planes zpos sanity check and fix
 - MAINTAINERS entry for LVDS panel driver
 
 mcde:
 - fix return value
 
 mgag200:
 - use managed config init
 
 stm:
 - read endpoints from DT
 
 vboxvideo:
 - use PCI managed functions
 - drop WC mtrr
 
 vkms:
 - enable cursor by default
 
 rockchip:
 - afbc support
 
 virtio:
 - various cleanups
 
 qxl:
 - fix cursor notify port
 
 hisilicon:
 - 128-byte stride alignment fix
 
 sun4i:
 - improved format handling
 -----BEGIN PGP SIGNATURE-----
 
 iQIcBAABAgAGBQJe1edsAAoJEAx081l5xIa+bKEQAJAZv/8OMM2rx+p+GyKgrNpl
 ihTX/oyToy8dw97s1kWF7V5kKU+qjF8aWlKoPS0xovzaMAzYSFz9FRNEUgqtTXMI
 zIAzSXioqP21oL9/ZTHcXDULtz8Gk3uiPomgXMWLlNBdt3X5qvCwsmPRIYSwG0GJ
 00VCvxDbVxGSM3wzcvbfyRwHCq3SrFvIusXv5jHnnxEFGH0C7Mj2/FLYMKLNjvli
 Q8VEI2wQPZj1QdA8fLFVneIQsR6YUSko9OfFMANP8VJGpPMnUkvVxTJ5ACGJspvn
 U/h6NYqJeUU2Y3BSKqtjIC3a1LY51tp5tL9q4H9TD1hqMckt6F2V7T2IeFU8i6+V
 YzUsSiT4q1xB+uiFVcgopx2hyIp8INOEyWrVdYgw2JviROeRD+pDHvJd13ZNMnTe
 GvLWQ/PfBFrcz8eligjiYjOf66ZTU+j/rivaOBFyrs9gdlsaEW2QRurFrcNX+0lZ
 kDbLsIFjhYnPXsvHP87x4BuQCKQIEh8wWuxXuJjunBPdqVrJyltZWbBiKO571b5/
 BtX6xj6ztUOffR2RdiVanzY546I2hEi7SHMUuWnMqXsOV46GBN0QvlpZad/47n9x
 ZUy8HDDD0/qWuGwvPOJGIeAnUteWge9AhWXTeN5+1h5m+QEOzYkPKqC3Hp8TW1pM
 gToTWgAhnu731fhzLWyt
 =H7IS
 -----END PGP SIGNATURE-----
Merge tag 'drm-next-2020-06-02' of git://anongit.freedesktop.org/drm/drm
Pull drm updates from Dave Airlie:
 "Highlights:
   - Core DRM had a lot of refactoring around managed drm resources to
     make drivers simpler.
   - Intel Tigerlake support is on by default
   - amdgpu now support p2p PCI buffer sharing and encrypted GPU memory
  Details:
  core:
   - uapi: error out EBUSY when existing master
   - uapi: rework SET/DROP MASTER permission handling
   - remove drm_pci.h
   - drm_pci* are now legacy
   - introduced managed DRM resources
   - subclassing support for drm_framebuffer
   - simple encoder helper
   - edid improvements
   - vblank + writeback documentation improved
   - drm/mm - optimise tree searches
   - port drivers to use devm_drm_dev_alloc
  dma-buf:
   - add flag for p2p buffer support
  mst:
   - ACT timeout improvements
   - remove drm_dp_mst_has_audio
   - don't use 2nd TX slot - spec recommends against it
  bridge:
   - dw-hdmi various improvements
   - chrontel ch7033 support
   - fix stack issues with old gcc
  hdmi:
   - add unpack function for drm infoframe
  fbdev:
   - misc fbdev driver fixes
  i915:
   - uapi: global sseu pinning
   - uapi: OA buffer polling
   - uapi: remove generated perf code
   - uapi: per-engine default property values in sysfs
   - Tigerlake GEN12 enabled.
   - Lots of gem refactoring
   - Tigerlake enablement patches
   - move to drm_device logging
   - Icelake gamma HW readout
   - push MST link retrain to hotplug work
   - bandwidth atomic helpers
   - ICL fixes
   - RPS/GT refactoring
   - Cherryview full-ppgtt support
   - i915 locking guidelines documented
   - require linear fb stride to be 512 multiple on gen9
   - Tigerlake SAGV support
  amdgpu:
   - uapi: encrypted GPU memory handling
   - uapi: add MEM_SYNC IB flag
   - p2p dma-buf support
   - export VRAM dma-bufs
   - FRU chip access support
   - RAS/SR-IOV updates
   - Powerplay locking fixes
   - VCN DPG (powergating) enablement
   - GFX10 clockgating fixes
   - DC fixes
   - GPU reset fixes
   - navi SDMA fix
   - expose FP16 for modesetting
   - DP 1.4 compliance fixes
   - gfx10 soft recovery
   - Improved Critical Thermal Faults handling
   - resizable BAR on gmc10
  amdkfd:
   - uapi: GWS resource management
   - track GPU memory per process
   - report PCI domain in topology
  radeon:
   - safe reg list generator fixes
  nouveau:
   - HD audio fixes on recent systems
   - vGPU detection (fail probe if we're on one, for now)
   - Interlaced mode fixes (mostly avoidance on Turing, which doesn't support it)
   - SVM improvements/fixes
   - NVIDIA format modifier support
   - Misc other fixes.
  adv7511:
   - HDMI SPDIF support
  ast:
   - allocate crtc state size
   - fix double assignment
   - fix suspend
  bochs:
   - drop connector register
  cirrus:
   - move to tiny drivers.
  exynos:
   - fix imported dma-buf mapping
   - enable runtime PM
   - fixes and cleanups
  mediatek:
   - DPI pin mode swap
   - config mipi_tx current/impedance
  lima:
   - devfreq + cooling device support
   - task handling improvements
   - runtime PM support
  pl111:
   - vexpress init improvements
   - fix module auto-load
  rcar-du:
   - DT bindings conversion to YAML
   - Planes zpos sanity check and fix
   - MAINTAINERS entry for LVDS panel driver
  mcde:
   - fix return value
  mgag200:
   - use managed config init
  stm:
   - read endpoints from DT
  vboxvideo:
   - use PCI managed functions
   - drop WC mtrr
  vkms:
   - enable cursor by default
  rockchip:
   - afbc support
  virtio:
   - various cleanups
  qxl:
   - fix cursor notify port
  hisilicon:
   - 128-byte stride alignment fix
  sun4i:
   - improved format handling"
* tag 'drm-next-2020-06-02' of git://anongit.freedesktop.org/drm/drm: (1401 commits)
  drm/amd/display: Fix potential integer wraparound resulting in a hang
  drm/amd/display: drop cursor position check in atomic test
  drm/amdgpu: fix device attribute node create failed with multi gpu
  drm/nouveau: use correct conflicting framebuffer API
  drm/vblank: Fix -Wformat compile warnings on some arches
  drm/amdgpu: Sync with VM root BO when switching VM to CPU update mode
  drm/amd/display: Handle GPU reset for DC block
  drm/amdgpu: add apu flags (v2)
  drm/amd/powerpay: Disable gfxoff when setting manual mode on picasso and raven
  drm/amdgpu: fix pm sysfs node handling (v2)
  drm/amdgpu: move gpu_info parsing after common early init
  drm/amdgpu: move discovery gfx config fetching
  drm/nouveau/dispnv50: fix runtime pm imbalance on error
  drm/nouveau: fix runtime pm imbalance on error
  drm/nouveau: fix runtime pm imbalance on error
  drm/nouveau/debugfs: fix runtime pm imbalance on error
  drm/nouveau/nouveau/hmm: fix migrate zero page to GPU
  drm/nouveau/nouveau/hmm: fix nouveau_dmem_chunk allocations
  drm/nouveau/kms/nv50-: Share DP SST mode_valid() handling with MST
  drm/nouveau/kms/nv50-: Move 8BPC limit for MST into nv50_mstc_get_modes()
  ...
		
	
			
		
			
				
	
	
		
			443 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			443 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| // SPDX-License-Identifier: GPL-2.0
 | |
| /*
 | |
|  * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
 | |
|  * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
 | |
|  */
 | |
| 
 | |
| #include <drm/drm_atomic.h>
 | |
| #include <drm/drm_atomic_helper.h>
 | |
| #include <drm/drm_crtc.h>
 | |
| #include <drm/drm_crtc_helper.h>
 | |
| #include <drm/drm_fb_cma_helper.h>
 | |
| #include <drm/drm_gem_cma_helper.h>
 | |
| #include <drm/drm_plane_helper.h>
 | |
| #include <drm/drm_vblank.h>
 | |
| 
 | |
| #include "tidss_crtc.h"
 | |
| #include "tidss_dispc.h"
 | |
| #include "tidss_drv.h"
 | |
| #include "tidss_irq.h"
 | |
| #include "tidss_plane.h"
 | |
| 
 | |
| /* Page flip and frame done IRQs */
 | |
| 
 | |
| static void tidss_crtc_finish_page_flip(struct tidss_crtc *tcrtc)
 | |
| {
 | |
| 	struct drm_device *ddev = tcrtc->crtc.dev;
 | |
| 	struct tidss_device *tidss = to_tidss(ddev);
 | |
| 	struct drm_pending_vblank_event *event;
 | |
| 	unsigned long flags;
 | |
| 	bool busy;
 | |
| 
 | |
| 	spin_lock_irqsave(&ddev->event_lock, flags);
 | |
| 
 | |
| 	/*
 | |
| 	 * New settings are taken into use at VFP, and GO bit is cleared at
 | |
| 	 * the same time. This happens before the vertical blank interrupt.
 | |
| 	 * So there is a small change that the driver sets GO bit after VFP, but
 | |
| 	 * before vblank, and we have to check for that case here.
 | |
| 	 */
 | |
| 	busy = dispc_vp_go_busy(tidss->dispc, tcrtc->hw_videoport);
 | |
| 	if (busy) {
 | |
| 		spin_unlock_irqrestore(&ddev->event_lock, flags);
 | |
| 		return;
 | |
| 	}
 | |
| 
 | |
| 	event = tcrtc->event;
 | |
| 	tcrtc->event = NULL;
 | |
| 
 | |
| 	if (!event) {
 | |
| 		spin_unlock_irqrestore(&ddev->event_lock, flags);
 | |
| 		return;
 | |
| 	}
 | |
| 
 | |
| 	drm_crtc_send_vblank_event(&tcrtc->crtc, event);
 | |
| 
 | |
| 	spin_unlock_irqrestore(&ddev->event_lock, flags);
 | |
| 
 | |
| 	drm_crtc_vblank_put(&tcrtc->crtc);
 | |
| }
 | |
| 
 | |
| void tidss_crtc_vblank_irq(struct drm_crtc *crtc)
 | |
| {
 | |
| 	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
 | |
| 
 | |
| 	drm_crtc_handle_vblank(crtc);
 | |
| 
 | |
| 	tidss_crtc_finish_page_flip(tcrtc);
 | |
| }
 | |
| 
 | |
| void tidss_crtc_framedone_irq(struct drm_crtc *crtc)
 | |
| {
 | |
| 	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
 | |
| 
 | |
| 	complete(&tcrtc->framedone_completion);
 | |
| }
 | |
| 
 | |
| void tidss_crtc_error_irq(struct drm_crtc *crtc, u64 irqstatus)
 | |
| {
 | |
| 	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
 | |
| 
 | |
| 	dev_err_ratelimited(crtc->dev->dev, "CRTC%u SYNC LOST: (irq %llx)\n",
 | |
| 			    tcrtc->hw_videoport, irqstatus);
 | |
| }
 | |
| 
 | |
| /* drm_crtc_helper_funcs */
 | |
| 
 | |
| static int tidss_crtc_atomic_check(struct drm_crtc *crtc,
 | |
| 				   struct drm_crtc_state *state)
 | |
| {
 | |
| 	struct drm_device *ddev = crtc->dev;
 | |
| 	struct tidss_device *tidss = to_tidss(ddev);
 | |
| 	struct dispc_device *dispc = tidss->dispc;
 | |
| 	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
 | |
| 	u32 hw_videoport = tcrtc->hw_videoport;
 | |
| 	const struct drm_display_mode *mode;
 | |
| 	enum drm_mode_status ok;
 | |
| 
 | |
| 	dev_dbg(ddev->dev, "%s\n", __func__);
 | |
| 
 | |
| 	if (!state->enable)
 | |
| 		return 0;
 | |
| 
 | |
| 	mode = &state->adjusted_mode;
 | |
| 
 | |
| 	ok = dispc_vp_mode_valid(dispc, hw_videoport, mode);
 | |
| 	if (ok != MODE_OK) {
 | |
| 		dev_dbg(ddev->dev, "%s: bad mode: %ux%u pclk %u kHz\n",
 | |
| 			__func__, mode->hdisplay, mode->vdisplay, mode->clock);
 | |
| 		return -EINVAL;
 | |
| 	}
 | |
| 
 | |
| 	return dispc_vp_bus_check(dispc, hw_videoport, state);
 | |
| }
 | |
| 
 | |
| /*
 | |
|  * This needs all affected planes to be present in the atomic
 | |
|  * state. The untouched planes are added to the state in
 | |
|  * tidss_atomic_check().
 | |
|  */
 | |
| static void tidss_crtc_position_planes(struct tidss_device *tidss,
 | |
| 				       struct drm_crtc *crtc,
 | |
| 				       struct drm_crtc_state *old_state,
 | |
| 				       bool newmodeset)
 | |
| {
 | |
| 	struct drm_atomic_state *ostate = old_state->state;
 | |
| 	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
 | |
| 	struct drm_crtc_state *cstate = crtc->state;
 | |
| 	int layer;
 | |
| 
 | |
| 	if (!newmodeset && !cstate->zpos_changed &&
 | |
| 	    !to_tidss_crtc_state(cstate)->plane_pos_changed)
 | |
| 		return;
 | |
| 
 | |
| 	for (layer = 0; layer < tidss->feat->num_planes; layer++) {
 | |
| 		struct drm_plane_state *pstate;
 | |
| 		struct drm_plane *plane;
 | |
| 		bool layer_active = false;
 | |
| 		int i;
 | |
| 
 | |
| 		for_each_new_plane_in_state(ostate, plane, pstate, i) {
 | |
| 			if (pstate->crtc != crtc || !pstate->visible)
 | |
| 				continue;
 | |
| 
 | |
| 			if (pstate->normalized_zpos == layer) {
 | |
| 				layer_active = true;
 | |
| 				break;
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		if (layer_active) {
 | |
| 			struct tidss_plane *tplane = to_tidss_plane(plane);
 | |
| 
 | |
| 			dispc_ovr_set_plane(tidss->dispc, tplane->hw_plane_id,
 | |
| 					    tcrtc->hw_videoport,
 | |
| 					    pstate->crtc_x, pstate->crtc_y,
 | |
| 					    layer);
 | |
| 		}
 | |
| 		dispc_ovr_enable_layer(tidss->dispc, tcrtc->hw_videoport, layer,
 | |
| 				       layer_active);
 | |
| 	}
 | |
| }
 | |
| 
 | |
| static void tidss_crtc_atomic_flush(struct drm_crtc *crtc,
 | |
| 				    struct drm_crtc_state *old_crtc_state)
 | |
| {
 | |
| 	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
 | |
| 	struct drm_device *ddev = crtc->dev;
 | |
| 	struct tidss_device *tidss = to_tidss(ddev);
 | |
| 	unsigned long flags;
 | |
| 
 | |
| 	dev_dbg(ddev->dev,
 | |
| 		"%s: %s enabled %d, needs modeset %d, event %p\n", __func__,
 | |
| 		crtc->name, drm_atomic_crtc_needs_modeset(crtc->state),
 | |
| 		crtc->state->enable, crtc->state->event);
 | |
| 
 | |
| 	/* There is nothing to do if CRTC is not going to be enabled. */
 | |
| 	if (!crtc->state->enable)
 | |
| 		return;
 | |
| 
 | |
| 	/*
 | |
| 	 * Flush CRTC changes with go bit only if new modeset is not
 | |
| 	 * coming, so CRTC is enabled trough out the commit.
 | |
| 	 */
 | |
| 	if (drm_atomic_crtc_needs_modeset(crtc->state))
 | |
| 		return;
 | |
| 
 | |
| 	/* If the GO bit is stuck we better quit here. */
 | |
| 	if (WARN_ON(dispc_vp_go_busy(tidss->dispc, tcrtc->hw_videoport)))
 | |
| 		return;
 | |
| 
 | |
| 	/* We should have event if CRTC is enabled through out this commit. */
 | |
| 	if (WARN_ON(!crtc->state->event))
 | |
| 		return;
 | |
| 
 | |
| 	/* Write vp properties to HW if needed. */
 | |
| 	dispc_vp_setup(tidss->dispc, tcrtc->hw_videoport, crtc->state, false);
 | |
| 
 | |
| 	/* Update plane positions if needed. */
 | |
| 	tidss_crtc_position_planes(tidss, crtc, old_crtc_state, false);
 | |
| 
 | |
| 	WARN_ON(drm_crtc_vblank_get(crtc) != 0);
 | |
| 
 | |
| 	spin_lock_irqsave(&ddev->event_lock, flags);
 | |
| 	dispc_vp_go(tidss->dispc, tcrtc->hw_videoport);
 | |
| 
 | |
| 	WARN_ON(tcrtc->event);
 | |
| 
 | |
| 	tcrtc->event = crtc->state->event;
 | |
| 	crtc->state->event = NULL;
 | |
| 
 | |
| 	spin_unlock_irqrestore(&ddev->event_lock, flags);
 | |
| }
 | |
| 
 | |
| static void tidss_crtc_atomic_enable(struct drm_crtc *crtc,
 | |
| 				     struct drm_crtc_state *old_state)
 | |
| {
 | |
| 	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
 | |
| 	struct drm_device *ddev = crtc->dev;
 | |
| 	struct tidss_device *tidss = to_tidss(ddev);
 | |
| 	const struct drm_display_mode *mode = &crtc->state->adjusted_mode;
 | |
| 	unsigned long flags;
 | |
| 	int r;
 | |
| 
 | |
| 	dev_dbg(ddev->dev, "%s, event %p\n", __func__, crtc->state->event);
 | |
| 
 | |
| 	tidss_runtime_get(tidss);
 | |
| 
 | |
| 	r = dispc_vp_set_clk_rate(tidss->dispc, tcrtc->hw_videoport,
 | |
| 				  mode->clock * 1000);
 | |
| 	if (r != 0)
 | |
| 		return;
 | |
| 
 | |
| 	r = dispc_vp_enable_clk(tidss->dispc, tcrtc->hw_videoport);
 | |
| 	if (r != 0)
 | |
| 		return;
 | |
| 
 | |
| 	dispc_vp_setup(tidss->dispc, tcrtc->hw_videoport, crtc->state, true);
 | |
| 	tidss_crtc_position_planes(tidss, crtc, old_state, true);
 | |
| 
 | |
| 	/* Turn vertical blanking interrupt reporting on. */
 | |
| 	drm_crtc_vblank_on(crtc);
 | |
| 
 | |
| 	dispc_vp_prepare(tidss->dispc, tcrtc->hw_videoport, crtc->state);
 | |
| 
 | |
| 	dispc_vp_enable(tidss->dispc, tcrtc->hw_videoport, crtc->state);
 | |
| 
 | |
| 	spin_lock_irqsave(&ddev->event_lock, flags);
 | |
| 
 | |
| 	if (crtc->state->event) {
 | |
| 		drm_crtc_send_vblank_event(crtc, crtc->state->event);
 | |
| 		crtc->state->event = NULL;
 | |
| 	}
 | |
| 
 | |
| 	spin_unlock_irqrestore(&ddev->event_lock, flags);
 | |
| }
 | |
| 
 | |
| static void tidss_crtc_atomic_disable(struct drm_crtc *crtc,
 | |
| 				      struct drm_crtc_state *old_state)
 | |
| {
 | |
| 	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
 | |
| 	struct drm_device *ddev = crtc->dev;
 | |
| 	struct tidss_device *tidss = to_tidss(ddev);
 | |
| 	unsigned long flags;
 | |
| 
 | |
| 	dev_dbg(ddev->dev, "%s, event %p\n", __func__, crtc->state->event);
 | |
| 
 | |
| 	reinit_completion(&tcrtc->framedone_completion);
 | |
| 
 | |
| 	dispc_vp_disable(tidss->dispc, tcrtc->hw_videoport);
 | |
| 
 | |
| 	if (!wait_for_completion_timeout(&tcrtc->framedone_completion,
 | |
| 					 msecs_to_jiffies(500)))
 | |
| 		dev_err(tidss->dev, "Timeout waiting for framedone on crtc %d",
 | |
| 			tcrtc->hw_videoport);
 | |
| 
 | |
| 	dispc_vp_unprepare(tidss->dispc, tcrtc->hw_videoport);
 | |
| 
 | |
| 	spin_lock_irqsave(&ddev->event_lock, flags);
 | |
| 	if (crtc->state->event) {
 | |
| 		drm_crtc_send_vblank_event(crtc, crtc->state->event);
 | |
| 		crtc->state->event = NULL;
 | |
| 	}
 | |
| 	spin_unlock_irqrestore(&ddev->event_lock, flags);
 | |
| 
 | |
| 	drm_crtc_vblank_off(crtc);
 | |
| 
 | |
| 	dispc_vp_disable_clk(tidss->dispc, tcrtc->hw_videoport);
 | |
| 
 | |
| 	tidss_runtime_put(tidss);
 | |
| }
 | |
| 
 | |
| static
 | |
| enum drm_mode_status tidss_crtc_mode_valid(struct drm_crtc *crtc,
 | |
| 					   const struct drm_display_mode *mode)
 | |
| {
 | |
| 	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
 | |
| 	struct drm_device *ddev = crtc->dev;
 | |
| 	struct tidss_device *tidss = to_tidss(ddev);
 | |
| 
 | |
| 	return dispc_vp_mode_valid(tidss->dispc, tcrtc->hw_videoport, mode);
 | |
| }
 | |
| 
 | |
| static const struct drm_crtc_helper_funcs tidss_crtc_helper_funcs = {
 | |
| 	.atomic_check = tidss_crtc_atomic_check,
 | |
| 	.atomic_flush = tidss_crtc_atomic_flush,
 | |
| 	.atomic_enable = tidss_crtc_atomic_enable,
 | |
| 	.atomic_disable = tidss_crtc_atomic_disable,
 | |
| 
 | |
| 	.mode_valid = tidss_crtc_mode_valid,
 | |
| };
 | |
| 
 | |
| /* drm_crtc_funcs */
 | |
| 
 | |
| static int tidss_crtc_enable_vblank(struct drm_crtc *crtc)
 | |
| {
 | |
| 	struct drm_device *ddev = crtc->dev;
 | |
| 	struct tidss_device *tidss = to_tidss(ddev);
 | |
| 
 | |
| 	dev_dbg(ddev->dev, "%s\n", __func__);
 | |
| 
 | |
| 	tidss_runtime_get(tidss);
 | |
| 
 | |
| 	tidss_irq_enable_vblank(crtc);
 | |
| 
 | |
| 	return 0;
 | |
| }
 | |
| 
 | |
| static void tidss_crtc_disable_vblank(struct drm_crtc *crtc)
 | |
| {
 | |
| 	struct drm_device *ddev = crtc->dev;
 | |
| 	struct tidss_device *tidss = to_tidss(ddev);
 | |
| 
 | |
| 	dev_dbg(ddev->dev, "%s\n", __func__);
 | |
| 
 | |
| 	tidss_irq_disable_vblank(crtc);
 | |
| 
 | |
| 	tidss_runtime_put(tidss);
 | |
| }
 | |
| 
 | |
| static void tidss_crtc_reset(struct drm_crtc *crtc)
 | |
| {
 | |
| 	struct tidss_crtc_state *tcrtc;
 | |
| 
 | |
| 	if (crtc->state)
 | |
| 		__drm_atomic_helper_crtc_destroy_state(crtc->state);
 | |
| 
 | |
| 	kfree(crtc->state);
 | |
| 
 | |
| 	tcrtc = kzalloc(sizeof(*tcrtc), GFP_KERNEL);
 | |
| 	if (!tcrtc) {
 | |
| 		crtc->state = NULL;
 | |
| 		return;
 | |
| 	}
 | |
| 
 | |
| 	crtc->state = &tcrtc->base;
 | |
| 	crtc->state->crtc = crtc;
 | |
| }
 | |
| 
 | |
| static struct drm_crtc_state *tidss_crtc_duplicate_state(struct drm_crtc *crtc)
 | |
| {
 | |
| 	struct tidss_crtc_state *state, *current_state;
 | |
| 
 | |
| 	if (WARN_ON(!crtc->state))
 | |
| 		return NULL;
 | |
| 
 | |
| 	current_state = to_tidss_crtc_state(crtc->state);
 | |
| 
 | |
| 	state = kmalloc(sizeof(*state), GFP_KERNEL);
 | |
| 	if (!state)
 | |
| 		return NULL;
 | |
| 
 | |
| 	__drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
 | |
| 
 | |
| 	state->plane_pos_changed = false;
 | |
| 
 | |
| 	state->bus_format = current_state->bus_format;
 | |
| 	state->bus_flags = current_state->bus_flags;
 | |
| 
 | |
| 	return &state->base;
 | |
| }
 | |
| 
 | |
| static void tidss_crtc_destroy(struct drm_crtc *crtc)
 | |
| {
 | |
| 	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
 | |
| 
 | |
| 	drm_crtc_cleanup(crtc);
 | |
| 	kfree(tcrtc);
 | |
| }
 | |
| 
 | |
| static const struct drm_crtc_funcs tidss_crtc_funcs = {
 | |
| 	.reset = tidss_crtc_reset,
 | |
| 	.destroy = tidss_crtc_destroy,
 | |
| 	.set_config = drm_atomic_helper_set_config,
 | |
| 	.page_flip = drm_atomic_helper_page_flip,
 | |
| 	.atomic_duplicate_state = tidss_crtc_duplicate_state,
 | |
| 	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
 | |
| 	.enable_vblank = tidss_crtc_enable_vblank,
 | |
| 	.disable_vblank = tidss_crtc_disable_vblank,
 | |
| };
 | |
| 
 | |
| struct tidss_crtc *tidss_crtc_create(struct tidss_device *tidss,
 | |
| 				     u32 hw_videoport,
 | |
| 				     struct drm_plane *primary)
 | |
| {
 | |
| 	struct tidss_crtc *tcrtc;
 | |
| 	struct drm_crtc *crtc;
 | |
| 	unsigned int gamma_lut_size = 0;
 | |
| 	bool has_ctm = tidss->feat->vp_feat.color.has_ctm;
 | |
| 	int ret;
 | |
| 
 | |
| 	tcrtc = kzalloc(sizeof(*tcrtc), GFP_KERNEL);
 | |
| 	if (!tcrtc)
 | |
| 		return ERR_PTR(-ENOMEM);
 | |
| 
 | |
| 	tcrtc->hw_videoport = hw_videoport;
 | |
| 	init_completion(&tcrtc->framedone_completion);
 | |
| 
 | |
| 	crtc =  &tcrtc->crtc;
 | |
| 
 | |
| 	ret = drm_crtc_init_with_planes(&tidss->ddev, crtc, primary,
 | |
| 					NULL, &tidss_crtc_funcs, NULL);
 | |
| 	if (ret < 0) {
 | |
| 		kfree(tcrtc);
 | |
| 		return ERR_PTR(ret);
 | |
| 	}
 | |
| 
 | |
| 	drm_crtc_helper_add(crtc, &tidss_crtc_helper_funcs);
 | |
| 
 | |
| 	/*
 | |
| 	 * The dispc gamma functions adapt to what ever size we ask
 | |
| 	 * from it no matter what HW supports. X-server assumes 256
 | |
| 	 * element gamma tables so lets use that.
 | |
| 	 */
 | |
| 	if (tidss->feat->vp_feat.color.gamma_size)
 | |
| 		gamma_lut_size = 256;
 | |
| 
 | |
| 	drm_crtc_enable_color_mgmt(crtc, 0, has_ctm, gamma_lut_size);
 | |
| 	if (gamma_lut_size)
 | |
| 		drm_mode_crtc_set_gamma_size(crtc, gamma_lut_size);
 | |
| 
 | |
| 	return tcrtc;
 | |
| }
 |