1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /* exynos_drm_drv.h
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5*4882a593Smuzhiyun * Authors:
6*4882a593Smuzhiyun * Inki Dae <inki.dae@samsung.com>
7*4882a593Smuzhiyun * Joonyoung Shim <jy0922.shim@samsung.com>
8*4882a593Smuzhiyun * Seung-Woo Kim <sw0312.kim@samsung.com>
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #ifndef _EXYNOS_DRM_DRV_H_
12*4882a593Smuzhiyun #define _EXYNOS_DRM_DRV_H_
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #include <linux/module.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #include <drm/drm_crtc.h>
17*4882a593Smuzhiyun #include <drm/drm_device.h>
18*4882a593Smuzhiyun #include <drm/drm_plane.h>
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #define MAX_CRTC 3
21*4882a593Smuzhiyun #define MAX_PLANE 5
22*4882a593Smuzhiyun #define MAX_FB_BUFFER 4
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #define DEFAULT_WIN 0
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun struct drm_crtc_state;
27*4882a593Smuzhiyun struct drm_display_mode;
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #define to_exynos_crtc(x) container_of(x, struct exynos_drm_crtc, base)
30*4882a593Smuzhiyun #define to_exynos_plane(x) container_of(x, struct exynos_drm_plane, base)
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun /* this enumerates display type. */
33*4882a593Smuzhiyun enum exynos_drm_output_type {
34*4882a593Smuzhiyun EXYNOS_DISPLAY_TYPE_NONE,
35*4882a593Smuzhiyun /* RGB or CPU Interface. */
36*4882a593Smuzhiyun EXYNOS_DISPLAY_TYPE_LCD,
37*4882a593Smuzhiyun /* HDMI Interface. */
38*4882a593Smuzhiyun EXYNOS_DISPLAY_TYPE_HDMI,
39*4882a593Smuzhiyun /* Virtual Display Interface. */
40*4882a593Smuzhiyun EXYNOS_DISPLAY_TYPE_VIDI,
41*4882a593Smuzhiyun };
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun struct exynos_drm_rect {
44*4882a593Smuzhiyun unsigned int x, y;
45*4882a593Smuzhiyun unsigned int w, h;
46*4882a593Smuzhiyun };
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun /*
49*4882a593Smuzhiyun * Exynos drm plane state structure.
50*4882a593Smuzhiyun *
51*4882a593Smuzhiyun * @base: plane_state object (contains drm_framebuffer pointer)
52*4882a593Smuzhiyun * @src: rectangle of the source image data to be displayed (clipped to
53*4882a593Smuzhiyun * visible part).
54*4882a593Smuzhiyun * @crtc: rectangle of the target image position on hardware screen
55*4882a593Smuzhiyun * (clipped to visible part).
56*4882a593Smuzhiyun * @h_ratio: horizontal scaling ratio, 16.16 fixed point
57*4882a593Smuzhiyun * @v_ratio: vertical scaling ratio, 16.16 fixed point
58*4882a593Smuzhiyun *
59*4882a593Smuzhiyun * this structure consists plane state data that will be applied to hardware
60*4882a593Smuzhiyun * specific overlay info.
61*4882a593Smuzhiyun */
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun struct exynos_drm_plane_state {
64*4882a593Smuzhiyun struct drm_plane_state base;
65*4882a593Smuzhiyun struct exynos_drm_rect crtc;
66*4882a593Smuzhiyun struct exynos_drm_rect src;
67*4882a593Smuzhiyun unsigned int h_ratio;
68*4882a593Smuzhiyun unsigned int v_ratio;
69*4882a593Smuzhiyun };
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun static inline struct exynos_drm_plane_state *
to_exynos_plane_state(struct drm_plane_state * state)72*4882a593Smuzhiyun to_exynos_plane_state(struct drm_plane_state *state)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun return container_of(state, struct exynos_drm_plane_state, base);
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun /*
78*4882a593Smuzhiyun * Exynos drm common overlay structure.
79*4882a593Smuzhiyun *
80*4882a593Smuzhiyun * @base: plane object
81*4882a593Smuzhiyun * @index: hardware index of the overlay layer
82*4882a593Smuzhiyun *
83*4882a593Smuzhiyun * this structure is common to exynos SoC and its contents would be copied
84*4882a593Smuzhiyun * to hardware specific overlay info.
85*4882a593Smuzhiyun */
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun struct exynos_drm_plane {
88*4882a593Smuzhiyun struct drm_plane base;
89*4882a593Smuzhiyun const struct exynos_drm_plane_config *config;
90*4882a593Smuzhiyun unsigned int index;
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun #define EXYNOS_DRM_PLANE_CAP_DOUBLE (1 << 0)
94*4882a593Smuzhiyun #define EXYNOS_DRM_PLANE_CAP_SCALE (1 << 1)
95*4882a593Smuzhiyun #define EXYNOS_DRM_PLANE_CAP_ZPOS (1 << 2)
96*4882a593Smuzhiyun #define EXYNOS_DRM_PLANE_CAP_TILE (1 << 3)
97*4882a593Smuzhiyun #define EXYNOS_DRM_PLANE_CAP_PIX_BLEND (1 << 4)
98*4882a593Smuzhiyun #define EXYNOS_DRM_PLANE_CAP_WIN_BLEND (1 << 5)
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun /*
101*4882a593Smuzhiyun * Exynos DRM plane configuration structure.
102*4882a593Smuzhiyun *
103*4882a593Smuzhiyun * @zpos: initial z-position of the plane.
104*4882a593Smuzhiyun * @type: type of the plane (primary, cursor or overlay).
105*4882a593Smuzhiyun * @pixel_formats: supported pixel formats.
106*4882a593Smuzhiyun * @num_pixel_formats: number of elements in 'pixel_formats'.
107*4882a593Smuzhiyun * @capabilities: supported features (see EXYNOS_DRM_PLANE_CAP_*)
108*4882a593Smuzhiyun */
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun struct exynos_drm_plane_config {
111*4882a593Smuzhiyun unsigned int zpos;
112*4882a593Smuzhiyun enum drm_plane_type type;
113*4882a593Smuzhiyun const uint32_t *pixel_formats;
114*4882a593Smuzhiyun unsigned int num_pixel_formats;
115*4882a593Smuzhiyun unsigned int capabilities;
116*4882a593Smuzhiyun };
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun /*
119*4882a593Smuzhiyun * Exynos drm crtc ops
120*4882a593Smuzhiyun *
121*4882a593Smuzhiyun * @atomic_enable: enable the device
122*4882a593Smuzhiyun * @atomic_disable: disable the device
123*4882a593Smuzhiyun * @enable_vblank: specific driver callback for enabling vblank interrupt.
124*4882a593Smuzhiyun * @disable_vblank: specific driver callback for disabling vblank interrupt.
125*4882a593Smuzhiyun * @mode_valid: specific driver callback for mode validation
126*4882a593Smuzhiyun * @atomic_check: validate state
127*4882a593Smuzhiyun * @atomic_begin: prepare device to receive an update
128*4882a593Smuzhiyun * @atomic_flush: mark the end of device update
129*4882a593Smuzhiyun * @update_plane: apply hardware specific overlay data to registers.
130*4882a593Smuzhiyun * @disable_plane: disable hardware specific overlay.
131*4882a593Smuzhiyun * @te_handler: trigger to transfer video image at the tearing effect
132*4882a593Smuzhiyun * synchronization signal if there is a page flip request.
133*4882a593Smuzhiyun */
134*4882a593Smuzhiyun struct exynos_drm_crtc;
135*4882a593Smuzhiyun struct exynos_drm_crtc_ops {
136*4882a593Smuzhiyun void (*atomic_enable)(struct exynos_drm_crtc *crtc);
137*4882a593Smuzhiyun void (*atomic_disable)(struct exynos_drm_crtc *crtc);
138*4882a593Smuzhiyun int (*enable_vblank)(struct exynos_drm_crtc *crtc);
139*4882a593Smuzhiyun void (*disable_vblank)(struct exynos_drm_crtc *crtc);
140*4882a593Smuzhiyun enum drm_mode_status (*mode_valid)(struct exynos_drm_crtc *crtc,
141*4882a593Smuzhiyun const struct drm_display_mode *mode);
142*4882a593Smuzhiyun bool (*mode_fixup)(struct exynos_drm_crtc *crtc,
143*4882a593Smuzhiyun const struct drm_display_mode *mode,
144*4882a593Smuzhiyun struct drm_display_mode *adjusted_mode);
145*4882a593Smuzhiyun int (*atomic_check)(struct exynos_drm_crtc *crtc,
146*4882a593Smuzhiyun struct drm_crtc_state *state);
147*4882a593Smuzhiyun void (*atomic_begin)(struct exynos_drm_crtc *crtc);
148*4882a593Smuzhiyun void (*update_plane)(struct exynos_drm_crtc *crtc,
149*4882a593Smuzhiyun struct exynos_drm_plane *plane);
150*4882a593Smuzhiyun void (*disable_plane)(struct exynos_drm_crtc *crtc,
151*4882a593Smuzhiyun struct exynos_drm_plane *plane);
152*4882a593Smuzhiyun void (*atomic_flush)(struct exynos_drm_crtc *crtc);
153*4882a593Smuzhiyun void (*te_handler)(struct exynos_drm_crtc *crtc);
154*4882a593Smuzhiyun };
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun struct exynos_drm_clk {
157*4882a593Smuzhiyun void (*enable)(struct exynos_drm_clk *clk, bool enable);
158*4882a593Smuzhiyun };
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun /*
161*4882a593Smuzhiyun * Exynos specific crtc structure.
162*4882a593Smuzhiyun *
163*4882a593Smuzhiyun * @base: crtc object.
164*4882a593Smuzhiyun * @type: one of EXYNOS_DISPLAY_TYPE_LCD and HDMI.
165*4882a593Smuzhiyun * @ops: pointer to callbacks for exynos drm specific functionality
166*4882a593Smuzhiyun * @ctx: A pointer to the crtc's implementation specific context
167*4882a593Smuzhiyun * @pipe_clk: A pointer to the crtc's pipeline clock.
168*4882a593Smuzhiyun */
169*4882a593Smuzhiyun struct exynos_drm_crtc {
170*4882a593Smuzhiyun struct drm_crtc base;
171*4882a593Smuzhiyun enum exynos_drm_output_type type;
172*4882a593Smuzhiyun const struct exynos_drm_crtc_ops *ops;
173*4882a593Smuzhiyun void *ctx;
174*4882a593Smuzhiyun struct exynos_drm_clk *pipe_clk;
175*4882a593Smuzhiyun bool i80_mode : 1;
176*4882a593Smuzhiyun };
177*4882a593Smuzhiyun
exynos_drm_pipe_clk_enable(struct exynos_drm_crtc * crtc,bool enable)178*4882a593Smuzhiyun static inline void exynos_drm_pipe_clk_enable(struct exynos_drm_crtc *crtc,
179*4882a593Smuzhiyun bool enable)
180*4882a593Smuzhiyun {
181*4882a593Smuzhiyun if (crtc->pipe_clk)
182*4882a593Smuzhiyun crtc->pipe_clk->enable(crtc->pipe_clk, enable);
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun struct drm_exynos_file_private {
186*4882a593Smuzhiyun /* for g2d api */
187*4882a593Smuzhiyun struct list_head inuse_cmdlist;
188*4882a593Smuzhiyun struct list_head event_list;
189*4882a593Smuzhiyun struct list_head userptr_list;
190*4882a593Smuzhiyun };
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun /*
193*4882a593Smuzhiyun * Exynos drm private structure.
194*4882a593Smuzhiyun *
195*4882a593Smuzhiyun * @pending: the crtcs that have pending updates to finish
196*4882a593Smuzhiyun * @lock: protect access to @pending
197*4882a593Smuzhiyun * @wait: wait an atomic commit to finish
198*4882a593Smuzhiyun */
199*4882a593Smuzhiyun struct exynos_drm_private {
200*4882a593Smuzhiyun struct drm_fb_helper *fb_helper;
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun struct device *g2d_dev;
203*4882a593Smuzhiyun struct device *dma_dev;
204*4882a593Smuzhiyun void *mapping;
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun /* for atomic commit */
207*4882a593Smuzhiyun u32 pending;
208*4882a593Smuzhiyun spinlock_t lock;
209*4882a593Smuzhiyun wait_queue_head_t wait;
210*4882a593Smuzhiyun };
211*4882a593Smuzhiyun
to_dma_dev(struct drm_device * dev)212*4882a593Smuzhiyun static inline struct device *to_dma_dev(struct drm_device *dev)
213*4882a593Smuzhiyun {
214*4882a593Smuzhiyun struct exynos_drm_private *priv = dev->dev_private;
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun return priv->dma_dev;
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun
is_drm_iommu_supported(struct drm_device * drm_dev)219*4882a593Smuzhiyun static inline bool is_drm_iommu_supported(struct drm_device *drm_dev)
220*4882a593Smuzhiyun {
221*4882a593Smuzhiyun struct exynos_drm_private *priv = drm_dev->dev_private;
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun return priv->mapping ? true : false;
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun int exynos_drm_register_dma(struct drm_device *drm, struct device *dev,
227*4882a593Smuzhiyun void **dma_priv);
228*4882a593Smuzhiyun void exynos_drm_unregister_dma(struct drm_device *drm, struct device *dev,
229*4882a593Smuzhiyun void **dma_priv);
230*4882a593Smuzhiyun void exynos_drm_cleanup_dma(struct drm_device *drm);
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun #ifdef CONFIG_DRM_EXYNOS_DPI
233*4882a593Smuzhiyun struct drm_encoder *exynos_dpi_probe(struct device *dev);
234*4882a593Smuzhiyun int exynos_dpi_remove(struct drm_encoder *encoder);
235*4882a593Smuzhiyun int exynos_dpi_bind(struct drm_device *dev, struct drm_encoder *encoder);
236*4882a593Smuzhiyun #else
237*4882a593Smuzhiyun static inline struct drm_encoder *
exynos_dpi_probe(struct device * dev)238*4882a593Smuzhiyun exynos_dpi_probe(struct device *dev) { return NULL; }
exynos_dpi_remove(struct drm_encoder * encoder)239*4882a593Smuzhiyun static inline int exynos_dpi_remove(struct drm_encoder *encoder)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun return 0;
242*4882a593Smuzhiyun }
exynos_dpi_bind(struct drm_device * dev,struct drm_encoder * encoder)243*4882a593Smuzhiyun static inline int exynos_dpi_bind(struct drm_device *dev,
244*4882a593Smuzhiyun struct drm_encoder *encoder)
245*4882a593Smuzhiyun {
246*4882a593Smuzhiyun return 0;
247*4882a593Smuzhiyun }
248*4882a593Smuzhiyun #endif
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun #ifdef CONFIG_DRM_EXYNOS_FIMC
251*4882a593Smuzhiyun int exynos_drm_check_fimc_device(struct device *dev);
252*4882a593Smuzhiyun #else
exynos_drm_check_fimc_device(struct device * dev)253*4882a593Smuzhiyun static inline int exynos_drm_check_fimc_device(struct device *dev)
254*4882a593Smuzhiyun {
255*4882a593Smuzhiyun return 0;
256*4882a593Smuzhiyun }
257*4882a593Smuzhiyun #endif
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun int exynos_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state,
260*4882a593Smuzhiyun bool nonblock);
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun extern struct platform_driver fimd_driver;
264*4882a593Smuzhiyun extern struct platform_driver exynos5433_decon_driver;
265*4882a593Smuzhiyun extern struct platform_driver decon_driver;
266*4882a593Smuzhiyun extern struct platform_driver dp_driver;
267*4882a593Smuzhiyun extern struct platform_driver dsi_driver;
268*4882a593Smuzhiyun extern struct platform_driver mixer_driver;
269*4882a593Smuzhiyun extern struct platform_driver hdmi_driver;
270*4882a593Smuzhiyun extern struct platform_driver vidi_driver;
271*4882a593Smuzhiyun extern struct platform_driver g2d_driver;
272*4882a593Smuzhiyun extern struct platform_driver fimc_driver;
273*4882a593Smuzhiyun extern struct platform_driver rotator_driver;
274*4882a593Smuzhiyun extern struct platform_driver scaler_driver;
275*4882a593Smuzhiyun extern struct platform_driver gsc_driver;
276*4882a593Smuzhiyun extern struct platform_driver mic_driver;
277*4882a593Smuzhiyun #endif
278