1 /*
2  * rcar_du_crtc.h  --  R-Car Display Unit CRTCs
3  *
4  * Copyright (C) 2013-2015 Renesas Electronics Corporation
5  *
6  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  */
13 
14 #ifndef __RCAR_DU_CRTC_H__
15 #define __RCAR_DU_CRTC_H__
16 
17 #include <linux/mutex.h>
18 #include <linux/spinlock.h>
19 #include <linux/wait.h>
20 
21 #include <drm/drmP.h>
22 #include <drm/drm_crtc.h>
23 
24 #include <media/vsp1.h>
25 
26 struct rcar_du_group;
27 struct rcar_du_vsp;
28 
29 /**
30  * struct rcar_du_crtc - the CRTC, representing a DU superposition processor
31  * @crtc: base DRM CRTC
32  * @clock: the CRTC functional clock
33  * @extclock: external pixel dot clock (optional)
34  * @mmio_offset: offset of the CRTC registers in the DU MMIO block
35  * @index: CRTC software and hardware index
36  * @initialized: whether the CRTC has been initialized and clocks enabled
37  * @vblank_enable: whether vblank events are enabled on this CRTC
38  * @event: event to post when the pending page flip completes
39  * @flip_wait: wait queue used to signal page flip completion
40  * @vblank_lock: protects vblank_wait and vblank_count
41  * @vblank_wait: wait queue used to signal vertical blanking
42  * @vblank_count: number of vertical blanking interrupts to wait for
43  * @outputs: bitmask of the outputs (enum rcar_du_output) driven by this CRTC
44  * @group: CRTC group this CRTC belongs to
45  * @vsp: VSP feeding video to this CRTC
46  * @vsp_pipe: index of the VSP pipeline feeding video to this CRTC
47  */
48 struct rcar_du_crtc {
49 	struct drm_crtc crtc;
50 
51 	struct clk *clock;
52 	struct clk *extclock;
53 	unsigned int mmio_offset;
54 	unsigned int index;
55 	bool initialized;
56 
57 	bool vblank_enable;
58 	struct drm_pending_vblank_event *event;
59 	wait_queue_head_t flip_wait;
60 
61 	spinlock_t vblank_lock;
62 	wait_queue_head_t vblank_wait;
63 	unsigned int vblank_count;
64 
65 	unsigned int outputs;
66 
67 	struct rcar_du_group *group;
68 	struct rcar_du_vsp *vsp;
69 	unsigned int vsp_pipe;
70 };
71 
72 #define to_rcar_crtc(c)	container_of(c, struct rcar_du_crtc, crtc)
73 
74 /**
75  * struct rcar_du_crtc_state - Driver-specific CRTC state
76  * @state: base DRM CRTC state
77  * @crc: CRC computation configuration
78  */
79 struct rcar_du_crtc_state {
80 	struct drm_crtc_state state;
81 
82 	struct vsp1_du_crc_config crc;
83 };
84 
85 #define to_rcar_crtc_state(s) container_of(s, struct rcar_du_crtc_state, state)
86 
87 enum rcar_du_output {
88 	RCAR_DU_OUTPUT_DPAD0,
89 	RCAR_DU_OUTPUT_DPAD1,
90 	RCAR_DU_OUTPUT_LVDS0,
91 	RCAR_DU_OUTPUT_LVDS1,
92 	RCAR_DU_OUTPUT_HDMI0,
93 	RCAR_DU_OUTPUT_HDMI1,
94 	RCAR_DU_OUTPUT_TCON,
95 	RCAR_DU_OUTPUT_MAX,
96 };
97 
98 int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int swindex,
99 			unsigned int hwindex);
100 void rcar_du_crtc_suspend(struct rcar_du_crtc *rcrtc);
101 void rcar_du_crtc_resume(struct rcar_du_crtc *rcrtc);
102 
103 void rcar_du_crtc_route_output(struct drm_crtc *crtc,
104 			       enum rcar_du_output output);
105 void rcar_du_crtc_finish_page_flip(struct rcar_du_crtc *rcrtc);
106 
107 #endif /* __RCAR_DU_CRTC_H__ */
108