3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5 * Inki Dae <inki.dae@samsung.com>
6 * Joonyoung Shim <jy0922.shim@samsung.com>
7 * Seung-Woo Kim <sw0312.kim@samsung.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
29 #ifndef _EXYNOS_DRM_DRV_H_
30 #define _EXYNOS_DRM_DRV_H_
32 #include <linux/kref.h>
33 #include <linux/module.h>
38 #ifdef CONFIG_EXYNOS_IOMMU
39 #include <mach/sysmmu.h>
40 #include <linux/of_platform.h>
43 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
44 #include "linux/kds.h"
45 #include <linux/dma-buf.h>
50 #define MAX_FB_BUFFER 4
51 #define DEFAULT_ZPOS -1
54 struct exynos_drm_overlay;
56 struct exynos_drm_gem_object;
57 struct exynos_drm_display;
59 extern unsigned int drm_vblank_offdelay;
62 * Exynos drm common overlay structure.
64 * @fb_x: offset x on a framebuffer to be displayed.
65 * - the unit is screen coordinates.
66 * @fb_y: offset y on a framebuffer to be displayed.
67 * - the unit is screen coordinates.
68 * @fb_width: width of a framebuffer.
69 * @fb_height: height of a framebuffer.
70 * @fb_pitch: pitch of a framebuffer.
71 * @crtc_x: offset x on hardware screen.
72 * @crtc_y: offset y on hardware screen.
73 * @crtc_width: window width to be displayed (hardware screen).
74 * @crtc_height: window height to be displayed (hardware screen).
75 * @mode_width: width of screen mode.
76 * @mode_height: height of screen mode.
77 * @refresh: refresh rate.
78 * @scan_flag: interlace or progressive way.
79 * (it could be DRM_MODE_FLAG_*)
80 * @bpp: pixel size.(in bit)
81 * @pixel_format: fourcc pixel format of this overlay
82 * @dma_addr: array of bus(accessed by dma) address to the memory region
83 * allocated for a overlay.
84 * @vaddr: array of virtual memory addresss to this overlay.
85 * @zpos: order of overlay layer(z position).
86 * @default_win: a window to be enabled.
87 * @color_key: color key on or off.
88 * @index_color: if using color key feature then this value would be used
90 * @local_path: in case of lcd type, local path mode on or off.
91 * @transparency: transparency on or off.
92 * @activated: activated or not.
94 * this structure is common to exynos SoC and its contents would be copied
95 * to hardware specific overlay info.
97 struct exynos_drm_overlay {
100 unsigned int fb_width;
101 unsigned int fb_height;
102 unsigned int fb_pitch;
105 unsigned int crtc_width;
106 unsigned int crtc_height;
107 unsigned int crtc_htotal;
108 unsigned int crtc_hsync_len;
109 unsigned int crtc_vtotal;
110 unsigned int crtc_vsync_len;
111 unsigned int mode_width;
112 unsigned int mode_height;
113 unsigned int refresh;
114 unsigned int scan_flag;
116 uint32_t pixel_format;
117 dma_addr_t dma_addr[MAX_FB_BUFFER];
118 void __iomem *vaddr[MAX_FB_BUFFER];
123 unsigned int index_color;
130 * Exynos drm private structure.
132 struct exynos_drm_private {
133 struct drm_fb_helper *fb_helper;
135 wait_queue_head_t wait_vsync_queue;
138 * created crtc object would be contained at this array and
139 * this array is used to be aware of which crtc did it request vblank.
141 struct drm_crtc *crtc[MAX_CRTC];
143 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
144 struct kds_callback kds_cb;
146 #ifdef CONFIG_DRM_EXYNOS_DEBUG
148 atomic_t object_memory;
149 atomic_t object_count;
155 * Exynos drm sub driver structure.
157 * @list: sub driver has its own list object to register to exynos drm driver.
158 * @dev: pointer to device object for subdrv device driver.
159 * @drm_dev: pointer to drm_device and this pointer would be set
160 * when sub driver calls exynos_drm_subdrv_register().
161 * @display: A pointer to the display structure for this sub driver
162 * @probe: this callback would be called by exynos drm driver after
163 * subdrv is registered to it.
164 * @remove: this callback is used to release resources created
166 * @open: this would be called with drm device file open.
167 * @close: this would be called with drm device file close.
168 * @encoder: encoder object owned by this sub driver.
169 * @connector: connector object owned by this sub driver.
171 struct exynos_drm_subdrv {
172 struct list_head list;
174 struct drm_device *drm_dev;
175 struct exynos_drm_display *display;
177 int (*probe)(struct drm_device *drm_dev,
178 struct exynos_drm_subdrv *subdrv);
179 void (*remove)(struct drm_device *dev);
180 int (*open)(struct drm_device *drm_dev, struct device *dev,
181 struct drm_file *file);
182 void (*close)(struct drm_device *drm_dev, struct device *dev,
183 struct drm_file *file);
185 struct drm_encoder *encoder;
186 struct drm_connector *connector;
190 * this function calls a probe callback registered to sub driver list and
191 * create its own encoder and connector and then set drm_device object
194 int exynos_drm_device_register(struct drm_device *dev);
196 * this function calls a remove callback registered to sub driver list and
197 * destroy its own encoder and connetor.
199 int exynos_drm_device_unregister(struct drm_device *dev);
202 * this function would be called by sub drivers such as display controller
203 * or hdmi driver to register this sub driver object to exynos drm driver
204 * and when a sub driver is registered to exynos drm driver a probe callback
205 * of the sub driver is called and creates its own encoder and connector.
207 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *drm_subdrv);
209 /* this function removes subdrv list from exynos drm driver */
210 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *drm_subdrv);
212 void exynos_fimd_dp_attach(struct device *dev);
214 int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file);
215 void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file);
217 void exynos_drm_encoder_dpms(struct drm_encoder *encoder, int mode);
218 int exynos_drm_encoder_get_dpms(struct drm_encoder *encoder);
221 * exynos specific framebuffer structure.
223 * @release_work: for the worker destroying the fb after it's done being used
224 * @fb: drm framebuffer obejct.
225 * @exynos_gem_obj: array of exynos specific gem object containing a gem object.
227 struct exynos_drm_fb {
228 struct kref refcount;
229 struct work_struct release_work;
230 struct drm_framebuffer fb;
231 struct exynos_drm_gem_obj *exynos_gem_obj[MAX_FB_BUFFER];
232 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
233 struct drm_crtc *crtc;
234 struct kds_resource_set *kds_res_set;
235 struct dma_buf *dma_buf;
239 void exynos_drm_fb_release(struct kref *kref);
241 static inline void exynos_drm_fb_get(struct exynos_drm_fb *exynos_fb)
243 kref_get(&exynos_fb->refcount);
246 static inline void exynos_drm_fb_put(struct exynos_drm_fb *exynos_fb)
248 kref_put(&exynos_fb->refcount, exynos_drm_fb_release);
252 * Exynos specific crtc structure.
254 * @drm_crtc: crtc object.
255 * @overlay: contain information common to display controller and hdmi and
256 * contents of this overlay object would be copied to sub driver size.
257 * @current_fb: current fb that is being scanned out
258 * @pending_fb: fb that will start scanout on next flip
259 * @event: vblank event that is currently queued for flip
260 * @pipe: a crtc index created at load() with a new crtc object creation
261 * and the crtc object would be set to private->crtc array
262 * to get a crtc object corresponding to this pipe from private->crtc
263 * array when irq interrupt occured. the reason of using this pipe is that
264 * drm framework doesn't support multiple irq yet.
265 * we can refer to the crtc to current hardware interrupt occured through
267 * @dpms: store the crtc dpms value
268 * @flip_pending: there is a flip pending that we need to process next vblank
270 struct exynos_drm_crtc {
271 struct drm_crtc drm_crtc;
272 struct exynos_drm_overlay overlay;
273 struct drm_framebuffer *current_fb;
274 struct drm_framebuffer *pending_fb;
275 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
276 struct drm_pending_vblank_event *event;
277 struct kds_resource_set *current_kds;
278 struct kds_resource_set *pending_kds;
279 struct kds_resource_set *future_kds;
280 struct kds_resource_set *future_kds_extra;
284 unsigned int flip_in_flight;
285 atomic_t flip_pending;
288 #define to_exynos_fb(x) container_of(x, struct exynos_drm_fb, fb)
289 #define to_exynos_crtc(x) container_of(x, struct exynos_drm_crtc,\
292 extern struct platform_driver fimd_driver;
293 extern struct platform_driver hdmi_driver;
294 extern struct platform_driver dp_driver;
295 extern struct platform_driver mixer_driver;
296 extern struct platform_driver exynos_drm_common_hdmi_driver;
297 extern struct platform_driver vidi_driver;
298 #ifdef CONFIG_EXYNOS_IOMMU
299 extern struct dma_iommu_mapping *exynos_drm_common_mapping;
302 /* exynos_drm_debugfs.c */
303 int exynos_drm_debugfs_init(struct drm_minor *minor);
304 void exynos_drm_debugfs_cleanup(struct drm_minor *minor);