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