Merge remote-tracking branches 'asoc/topic/rl6231', 'asoc/topic/rockchip', 'asoc...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / exynos / exynos_drm_drv.h
1 /* exynos_drm_drv.h
2  *
3  * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4  * Authors:
5  *      Inki Dae <inki.dae@samsung.com>
6  *      Joonyoung Shim <jy0922.shim@samsung.com>
7  *      Seung-Woo Kim <sw0312.kim@samsung.com>
8  *
9  * This program is free software; you can redistribute  it and/or modify it
10  * under  the terms of  the GNU General  Public License as published by the
11  * Free Software Foundation;  either version 2 of the  License, or (at your
12  * option) any later version.
13  */
14
15 #ifndef _EXYNOS_DRM_DRV_H_
16 #define _EXYNOS_DRM_DRV_H_
17
18 #include <linux/module.h>
19
20 #define MAX_CRTC        3
21 #define MAX_PLANE       5
22 #define MAX_FB_BUFFER   4
23 #define DEFAULT_ZPOS    -1
24
25 #define _wait_for(COND, MS) ({ \
26         unsigned long timeout__ = jiffies + msecs_to_jiffies(MS);       \
27         int ret__ = 0;                                                  \
28         while (!(COND)) {                                               \
29                 if (time_after(jiffies, timeout__)) {                   \
30                         ret__ = -ETIMEDOUT;                             \
31                         break;                                          \
32                 }                                                       \
33         }                                                               \
34         ret__;                                                          \
35 })
36
37 #define wait_for(COND, MS) _wait_for(COND, MS)
38
39 struct drm_device;
40 struct exynos_drm_overlay;
41 struct drm_connector;
42
43 extern unsigned int drm_vblank_offdelay;
44
45 /* This enumerates device type. */
46 enum exynos_drm_device_type {
47         EXYNOS_DEVICE_TYPE_NONE,
48         EXYNOS_DEVICE_TYPE_CRTC,
49         EXYNOS_DEVICE_TYPE_CONNECTOR,
50 };
51
52 /* this enumerates display type. */
53 enum exynos_drm_output_type {
54         EXYNOS_DISPLAY_TYPE_NONE,
55         /* RGB or CPU Interface. */
56         EXYNOS_DISPLAY_TYPE_LCD,
57         /* HDMI Interface. */
58         EXYNOS_DISPLAY_TYPE_HDMI,
59         /* Virtual Display Interface. */
60         EXYNOS_DISPLAY_TYPE_VIDI,
61 };
62
63 /*
64  * Exynos drm common overlay structure.
65  *
66  * @fb_x: offset x on a framebuffer to be displayed.
67  *      - the unit is screen coordinates.
68  * @fb_y: offset y on a framebuffer to be displayed.
69  *      - the unit is screen coordinates.
70  * @fb_width: width of a framebuffer.
71  * @fb_height: height of a framebuffer.
72  * @src_width: width of a partial image to be displayed from framebuffer.
73  * @src_height: height of a partial image to be displayed from framebuffer.
74  * @crtc_x: offset x on hardware screen.
75  * @crtc_y: offset y on hardware screen.
76  * @crtc_width: window width to be displayed (hardware screen).
77  * @crtc_height: window height to be displayed (hardware screen).
78  * @mode_width: width of screen mode.
79  * @mode_height: height of screen mode.
80  * @refresh: refresh rate.
81  * @scan_flag: interlace or progressive way.
82  *      (it could be DRM_MODE_FLAG_*)
83  * @bpp: pixel size.(in bit)
84  * @pixel_format: fourcc pixel format of this overlay
85  * @dma_addr: array of bus(accessed by dma) address to the memory region
86  *            allocated for a overlay.
87  * @zpos: order of overlay layer(z position).
88  * @default_win: a window to be enabled.
89  * @color_key: color key on or off.
90  * @index_color: if using color key feature then this value would be used
91  *                      as index color.
92  * @local_path: in case of lcd type, local path mode on or off.
93  * @transparency: transparency on or off.
94  * @activated: activated or not.
95  *
96  * this structure is common to exynos SoC and its contents would be copied
97  * to hardware specific overlay info.
98  */
99 struct exynos_drm_overlay {
100         unsigned int fb_x;
101         unsigned int fb_y;
102         unsigned int fb_width;
103         unsigned int fb_height;
104         unsigned int src_width;
105         unsigned int src_height;
106         unsigned int crtc_x;
107         unsigned int crtc_y;
108         unsigned int crtc_width;
109         unsigned int crtc_height;
110         unsigned int mode_width;
111         unsigned int mode_height;
112         unsigned int refresh;
113         unsigned int scan_flag;
114         unsigned int bpp;
115         unsigned int pitch;
116         uint32_t pixel_format;
117         dma_addr_t dma_addr[MAX_FB_BUFFER];
118         int zpos;
119
120         bool default_win;
121         bool color_key;
122         unsigned int index_color;
123         bool local_path;
124         bool transparency;
125         bool activated;
126 };
127
128 /*
129  * Exynos DRM Display Structure.
130  *      - this structure is common to analog tv, digital tv and lcd panel.
131  *
132  * @remove: cleans up the display for removal
133  * @mode_fixup: fix mode data comparing to hw specific display mode.
134  * @mode_set: convert drm_display_mode to hw specific display mode and
135  *            would be called by encoder->mode_set().
136  * @check_mode: check if mode is valid or not.
137  * @dpms: display device on or off.
138  * @commit: apply changes to hw
139  */
140 struct exynos_drm_display;
141 struct exynos_drm_display_ops {
142         int (*create_connector)(struct exynos_drm_display *display,
143                                 struct drm_encoder *encoder);
144         void (*remove)(struct exynos_drm_display *display);
145         void (*mode_fixup)(struct exynos_drm_display *display,
146                                 struct drm_connector *connector,
147                                 const struct drm_display_mode *mode,
148                                 struct drm_display_mode *adjusted_mode);
149         void (*mode_set)(struct exynos_drm_display *display,
150                                 struct drm_display_mode *mode);
151         int (*check_mode)(struct exynos_drm_display *display,
152                                 struct drm_display_mode *mode);
153         void (*dpms)(struct exynos_drm_display *display, int mode);
154         void (*commit)(struct exynos_drm_display *display);
155 };
156
157 /*
158  * Exynos drm display structure, maps 1:1 with an encoder/connector
159  *
160  * @list: the list entry for this manager
161  * @type: one of EXYNOS_DISPLAY_TYPE_LCD and HDMI.
162  * @encoder: encoder object this display maps to
163  * @connector: connector object this display maps to
164  * @ops: pointer to callbacks for exynos drm specific functionality
165  * @ctx: A pointer to the display's implementation specific context
166  */
167 struct exynos_drm_display {
168         struct list_head list;
169         enum exynos_drm_output_type type;
170         struct drm_encoder *encoder;
171         struct drm_connector *connector;
172         struct exynos_drm_display_ops *ops;
173         void *ctx;
174 };
175
176 /*
177  * Exynos drm manager ops
178  *
179  * @dpms: control device power.
180  * @mode_fixup: fix mode data before applying it
181  * @mode_set: set the given mode to the manager
182  * @commit: set current hw specific display mode to hw.
183  * @enable_vblank: specific driver callback for enabling vblank interrupt.
184  * @disable_vblank: specific driver callback for disabling vblank interrupt.
185  * @wait_for_vblank: wait for vblank interrupt to make sure that
186  *      hardware overlay is updated.
187  * @win_mode_set: copy drm overlay info to hw specific overlay info.
188  * @win_commit: apply hardware specific overlay data to registers.
189  * @win_enable: enable hardware specific overlay.
190  * @win_disable: disable hardware specific overlay.
191  */
192 struct exynos_drm_manager;
193 struct exynos_drm_manager_ops {
194         void (*dpms)(struct exynos_drm_manager *mgr, int mode);
195         bool (*mode_fixup)(struct exynos_drm_manager *mgr,
196                                 const struct drm_display_mode *mode,
197                                 struct drm_display_mode *adjusted_mode);
198         void (*mode_set)(struct exynos_drm_manager *mgr,
199                                 const struct drm_display_mode *mode);
200         void (*commit)(struct exynos_drm_manager *mgr);
201         int (*enable_vblank)(struct exynos_drm_manager *mgr);
202         void (*disable_vblank)(struct exynos_drm_manager *mgr);
203         void (*wait_for_vblank)(struct exynos_drm_manager *mgr);
204         void (*win_mode_set)(struct exynos_drm_manager *mgr,
205                                 struct exynos_drm_overlay *overlay);
206         void (*win_commit)(struct exynos_drm_manager *mgr, int zpos);
207         void (*win_enable)(struct exynos_drm_manager *mgr, int zpos);
208         void (*win_disable)(struct exynos_drm_manager *mgr, int zpos);
209 };
210
211 /*
212  * Exynos drm common manager structure, maps 1:1 with a crtc
213  *
214  * @list: the list entry for this manager
215  * @type: one of EXYNOS_DISPLAY_TYPE_LCD and HDMI.
216  * @drm_dev: pointer to the drm device
217  * @crtc: crtc object.
218  * @pipe: the pipe number for this crtc/manager
219  * @ops: pointer to callbacks for exynos drm specific functionality
220  * @ctx: A pointer to the manager's implementation specific context
221  */
222 struct exynos_drm_manager {
223         struct list_head list;
224         enum exynos_drm_output_type type;
225         struct drm_device *drm_dev;
226         struct drm_crtc *crtc;
227         int pipe;
228         struct exynos_drm_manager_ops *ops;
229         void *ctx;
230 };
231
232 struct exynos_drm_g2d_private {
233         struct device           *dev;
234         struct list_head        inuse_cmdlist;
235         struct list_head        event_list;
236         struct list_head        userptr_list;
237 };
238
239 struct exynos_drm_ipp_private {
240         struct device   *dev;
241         struct list_head        event_list;
242 };
243
244 struct drm_exynos_file_private {
245         struct exynos_drm_g2d_private   *g2d_priv;
246         struct exynos_drm_ipp_private   *ipp_priv;
247         struct file                     *anon_filp;
248 };
249
250 /*
251  * Exynos drm private structure.
252  *
253  * @da_start: start address to device address space.
254  *      with iommu, device address space starts from this address
255  *      otherwise default one.
256  * @da_space_size: size of device address space.
257  *      if 0 then default value is used for it.
258  * @pipe: the pipe number for this crtc/manager.
259  */
260 struct exynos_drm_private {
261         struct drm_fb_helper *fb_helper;
262
263         /* list head for new event to be added. */
264         struct list_head pageflip_event_list;
265
266         /*
267          * created crtc object would be contained at this array and
268          * this array is used to be aware of which crtc did it request vblank.
269          */
270         struct drm_crtc *crtc[MAX_CRTC];
271         struct drm_property *plane_zpos_property;
272         struct drm_property *crtc_mode_property;
273
274         unsigned long da_start;
275         unsigned long da_space_size;
276
277         unsigned int pipe;
278 };
279
280 /*
281  * Exynos drm sub driver structure.
282  *
283  * @list: sub driver has its own list object to register to exynos drm driver.
284  * @dev: pointer to device object for subdrv device driver.
285  * @drm_dev: pointer to drm_device and this pointer would be set
286  *      when sub driver calls exynos_drm_subdrv_register().
287  * @manager: subdrv has its own manager to control a hardware appropriately
288  *     and we can access a hardware drawing on this manager.
289  * @probe: this callback would be called by exynos drm driver after
290  *     subdrv is registered to it.
291  * @remove: this callback is used to release resources created
292  *     by probe callback.
293  * @open: this would be called with drm device file open.
294  * @close: this would be called with drm device file close.
295  */
296 struct exynos_drm_subdrv {
297         struct list_head list;
298         struct device *dev;
299         struct drm_device *drm_dev;
300
301         int (*probe)(struct drm_device *drm_dev, struct device *dev);
302         void (*remove)(struct drm_device *drm_dev, struct device *dev);
303         int (*open)(struct drm_device *drm_dev, struct device *dev,
304                         struct drm_file *file);
305         void (*close)(struct drm_device *drm_dev, struct device *dev,
306                         struct drm_file *file);
307 };
308
309  /* This function would be called by non kms drivers such as g2d and ipp. */
310 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *drm_subdrv);
311
312 /* this function removes subdrv list from exynos drm driver */
313 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *drm_subdrv);
314
315 int exynos_drm_device_subdrv_probe(struct drm_device *dev);
316 int exynos_drm_device_subdrv_remove(struct drm_device *dev);
317 int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file);
318 void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file);
319
320 /*
321  * this function registers exynos drm hdmi platform device. It ensures only one
322  * instance of the device is created.
323  */
324 int exynos_platform_device_hdmi_register(void);
325
326 /*
327  * this function unregisters exynos drm hdmi platform device if it exists.
328  */
329 void exynos_platform_device_hdmi_unregister(void);
330
331 /*
332  * this function registers exynos drm ipp platform device.
333  */
334 int exynos_platform_device_ipp_register(void);
335
336 /*
337  * this function unregisters exynos drm ipp platform device if it exists.
338  */
339 void exynos_platform_device_ipp_unregister(void);
340
341 #ifdef CONFIG_DRM_EXYNOS_DPI
342 struct exynos_drm_display * exynos_dpi_probe(struct device *dev);
343 int exynos_dpi_remove(struct device *dev);
344 #else
345 static inline struct exynos_drm_display *
346 exynos_dpi_probe(struct device *dev) { return NULL; }
347 static inline int exynos_dpi_remove(struct device *dev) { return 0; }
348 #endif
349
350 /*
351  * this function registers exynos drm vidi platform device/driver.
352  */
353 int exynos_drm_probe_vidi(void);
354
355 /*
356  * this function unregister exynos drm vidi platform device/driver.
357  */
358 void exynos_drm_remove_vidi(void);
359
360 /* This function creates a encoder and a connector, and initializes them. */
361 int exynos_drm_create_enc_conn(struct drm_device *dev,
362                                 struct exynos_drm_display *display);
363
364 int exynos_drm_component_add(struct device *dev,
365                                 enum exynos_drm_device_type dev_type,
366                                 enum exynos_drm_output_type out_type);
367
368 void exynos_drm_component_del(struct device *dev,
369                                 enum exynos_drm_device_type dev_type);
370
371 extern struct platform_driver fimd_driver;
372 extern struct platform_driver dp_driver;
373 extern struct platform_driver dsi_driver;
374 extern struct platform_driver mixer_driver;
375 extern struct platform_driver hdmi_driver;
376 extern struct platform_driver exynos_drm_common_hdmi_driver;
377 extern struct platform_driver vidi_driver;
378 extern struct platform_driver g2d_driver;
379 extern struct platform_driver fimc_driver;
380 extern struct platform_driver rotator_driver;
381 extern struct platform_driver gsc_driver;
382 extern struct platform_driver ipp_driver;
383 #endif