blob: 780698139e67cbefa7a279003b6178d048c3a705 [file] [log] [blame]
Inki Dae1c248b72011-10-04 19:19:01 +09001/* 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 *
Inki Daed81aecb2012-12-18 02:30:17 +09009 * 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.
Inki Dae1c248b72011-10-04 19:19:01 +090013 */
14
15#ifndef _EXYNOS_DRM_DRV_H_
16#define _EXYNOS_DRM_DRV_H_
17
Gustavo Padovand2c1bba2014-10-31 14:17:38 +000018#include <drm/drmP.h>
Inki Dae4f9eb942011-11-12 16:57:42 +090019#include <linux/module.h>
Inki Dae1c248b72011-10-04 19:19:01 +090020
Inki Daeb73d1232012-03-21 10:55:26 +090021#define MAX_CRTC 3
Joonyoung Shim864ee9e2011-12-08 17:54:07 +090022#define MAX_PLANE 5
Inki Daeb73d1232012-03-21 10:55:26 +090023#define MAX_FB_BUFFER 4
Joonyoung Shim864ee9e2011-12-08 17:54:07 +090024#define DEFAULT_ZPOS -1
Inki Dae1c248b72011-10-04 19:19:01 +090025
Inki Daeb0119412012-08-20 19:55:14 +090026#define _wait_for(COND, MS) ({ \
27 unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \
28 int ret__ = 0; \
29 while (!(COND)) { \
30 if (time_after(jiffies, timeout__)) { \
31 ret__ = -ETIMEDOUT; \
32 break; \
33 } \
34 } \
35 ret__; \
36})
37
38#define wait_for(COND, MS) _wait_for(COND, MS)
39
Inki Daedf5225b2014-05-29 18:28:02 +090040/* This enumerates device type. */
41enum exynos_drm_device_type {
42 EXYNOS_DEVICE_TYPE_NONE,
43 EXYNOS_DEVICE_TYPE_CRTC,
44 EXYNOS_DEVICE_TYPE_CONNECTOR,
45};
46
Inki Dae1c248b72011-10-04 19:19:01 +090047/* this enumerates display type. */
48enum exynos_drm_output_type {
49 EXYNOS_DISPLAY_TYPE_NONE,
50 /* RGB or CPU Interface. */
51 EXYNOS_DISPLAY_TYPE_LCD,
52 /* HDMI Interface. */
53 EXYNOS_DISPLAY_TYPE_HDMI,
Inki Daeb73d1232012-03-21 10:55:26 +090054 /* Virtual Display Interface. */
55 EXYNOS_DISPLAY_TYPE_VIDI,
Inki Dae1c248b72011-10-04 19:19:01 +090056};
57
58/*
Inki Dae1c248b72011-10-04 19:19:01 +090059 * Exynos drm common overlay structure.
60 *
Inki Dae19c8b832011-10-14 13:29:46 +090061 * @fb_x: offset x on a framebuffer to be displayed.
62 * - the unit is screen coordinates.
63 * @fb_y: offset y on a framebuffer to be displayed.
64 * - the unit is screen coordinates.
65 * @fb_width: width of a framebuffer.
66 * @fb_height: height of a framebuffer.
Seung-Woo Kim0d8071ee2012-04-24 18:43:10 +090067 * @src_width: width of a partial image to be displayed from framebuffer.
68 * @src_height: height of a partial image to be displayed from framebuffer.
Inki Dae19c8b832011-10-14 13:29:46 +090069 * @crtc_x: offset x on hardware screen.
70 * @crtc_y: offset y on hardware screen.
71 * @crtc_width: window width to be displayed (hardware screen).
72 * @crtc_height: window height to be displayed (hardware screen).
73 * @mode_width: width of screen mode.
74 * @mode_height: height of screen mode.
75 * @refresh: refresh rate.
76 * @scan_flag: interlace or progressive way.
77 * (it could be DRM_MODE_FLAG_*)
Inki Dae1c248b72011-10-04 19:19:01 +090078 * @bpp: pixel size.(in bit)
Seung-Woo Kim229d3532011-12-15 14:36:22 +090079 * @pixel_format: fourcc pixel format of this overlay
80 * @dma_addr: array of bus(accessed by dma) address to the memory region
81 * allocated for a overlay.
Joonyoung Shim864ee9e2011-12-08 17:54:07 +090082 * @zpos: order of overlay layer(z position).
Inki Dae1c248b72011-10-04 19:19:01 +090083 * @default_win: a window to be enabled.
84 * @color_key: color key on or off.
85 * @index_color: if using color key feature then this value would be used
86 * as index color.
87 * @local_path: in case of lcd type, local path mode on or off.
88 * @transparency: transparency on or off.
89 * @activated: activated or not.
90 *
91 * this structure is common to exynos SoC and its contents would be copied
92 * to hardware specific overlay info.
93 */
94struct exynos_drm_overlay {
Inki Dae19c8b832011-10-14 13:29:46 +090095 unsigned int fb_x;
96 unsigned int fb_y;
97 unsigned int fb_width;
98 unsigned int fb_height;
Seung-Woo Kim0d8071ee2012-04-24 18:43:10 +090099 unsigned int src_width;
100 unsigned int src_height;
Inki Dae19c8b832011-10-14 13:29:46 +0900101 unsigned int crtc_x;
102 unsigned int crtc_y;
103 unsigned int crtc_width;
104 unsigned int crtc_height;
105 unsigned int mode_width;
106 unsigned int mode_height;
107 unsigned int refresh;
108 unsigned int scan_flag;
Inki Dae1c248b72011-10-04 19:19:01 +0900109 unsigned int bpp;
Inki Dae19c8b832011-10-14 13:29:46 +0900110 unsigned int pitch;
Seung-Woo Kim229d3532011-12-15 14:36:22 +0900111 uint32_t pixel_format;
112 dma_addr_t dma_addr[MAX_FB_BUFFER];
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900113 int zpos;
Inki Dae1c248b72011-10-04 19:19:01 +0900114
115 bool default_win;
116 bool color_key;
117 unsigned int index_color;
118 bool local_path;
119 bool transparency;
120 bool activated;
121};
122
123/*
124 * Exynos DRM Display Structure.
125 * - this structure is common to analog tv, digital tv and lcd panel.
126 *
Sean Paul080be03d2014-02-19 21:02:55 +0900127 * @remove: cleans up the display for removal
Sean Paul080be03d2014-02-19 21:02:55 +0900128 * @mode_fixup: fix mode data comparing to hw specific display mode.
129 * @mode_set: convert drm_display_mode to hw specific display mode and
130 * would be called by encoder->mode_set().
Rahul Sharma16844fb2013-06-10 14:50:00 +0530131 * @check_mode: check if mode is valid or not.
Sean Paul54c40de2014-01-30 16:19:09 -0500132 * @dpms: display device on or off.
Sean Paul080be03d2014-02-19 21:02:55 +0900133 * @commit: apply changes to hw
Inki Dae1c248b72011-10-04 19:19:01 +0900134 */
Sean Paul080be03d2014-02-19 21:02:55 +0900135struct exynos_drm_display;
Inki Dae74ccc532011-10-19 17:23:07 +0900136struct exynos_drm_display_ops {
Sean Paulc37f42c2014-02-24 19:15:38 +0900137 int (*create_connector)(struct exynos_drm_display *display,
138 struct drm_encoder *encoder);
Sean Paul080be03d2014-02-19 21:02:55 +0900139 void (*remove)(struct exynos_drm_display *display);
Sean Paul080be03d2014-02-19 21:02:55 +0900140 void (*mode_fixup)(struct exynos_drm_display *display,
141 struct drm_connector *connector,
142 const struct drm_display_mode *mode,
143 struct drm_display_mode *adjusted_mode);
144 void (*mode_set)(struct exynos_drm_display *display,
145 struct drm_display_mode *mode);
146 int (*check_mode)(struct exynos_drm_display *display,
147 struct drm_display_mode *mode);
148 void (*dpms)(struct exynos_drm_display *display, int mode);
149 void (*commit)(struct exynos_drm_display *display);
150};
151
152/*
153 * Exynos drm display structure, maps 1:1 with an encoder/connector
154 *
155 * @list: the list entry for this manager
156 * @type: one of EXYNOS_DISPLAY_TYPE_LCD and HDMI.
157 * @encoder: encoder object this display maps to
158 * @connector: connector object this display maps to
159 * @ops: pointer to callbacks for exynos drm specific functionality
160 * @ctx: A pointer to the display's implementation specific context
161 */
162struct exynos_drm_display {
163 struct list_head list;
Inki Dae1c248b72011-10-04 19:19:01 +0900164 enum exynos_drm_output_type type;
Sean Paul080be03d2014-02-19 21:02:55 +0900165 struct drm_encoder *encoder;
166 struct drm_connector *connector;
167 struct exynos_drm_display_ops *ops;
168 void *ctx;
Inki Dae1c248b72011-10-04 19:19:01 +0900169};
170
171/*
172 * Exynos drm manager ops
173 *
Inki Daeec05da92011-12-06 11:06:54 +0900174 * @dpms: control device power.
Sean Paul4b405262014-01-30 16:19:19 -0500175 * @mode_fixup: fix mode data before applying it
Sean Paulcd706aa2014-01-30 16:19:18 -0500176 * @mode_set: set the given mode to the manager
Inki Dae1c248b72011-10-04 19:19:01 +0900177 * @commit: set current hw specific display mode to hw.
178 * @enable_vblank: specific driver callback for enabling vblank interrupt.
179 * @disable_vblank: specific driver callback for disabling vblank interrupt.
Prathyush Kf74085a2012-12-06 20:16:00 +0530180 * @wait_for_vblank: wait for vblank interrupt to make sure that
181 * hardware overlay is updated.
Sean Paul1c6244c2014-01-30 16:19:02 -0500182 * @win_mode_set: copy drm overlay info to hw specific overlay info.
183 * @win_commit: apply hardware specific overlay data to registers.
184 * @win_enable: enable hardware specific overlay.
185 * @win_disable: disable hardware specific overlay.
YoungJun Cho5595d4d2014-07-17 18:01:19 +0900186 * @te_handler: trigger to transfer video image at the tearing effect
187 * synchronization signal if there is a page flip request.
Inki Dae1c248b72011-10-04 19:19:01 +0900188 */
Sean Paulbb7704d2014-01-30 16:19:06 -0500189struct exynos_drm_manager;
Inki Dae1c248b72011-10-04 19:19:01 +0900190struct exynos_drm_manager_ops {
Sean Paulbb7704d2014-01-30 16:19:06 -0500191 void (*dpms)(struct exynos_drm_manager *mgr, int mode);
Sean Paul4b405262014-01-30 16:19:19 -0500192 bool (*mode_fixup)(struct exynos_drm_manager *mgr,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200193 const struct drm_display_mode *mode,
Inki Dae1de425b2012-03-16 18:47:04 +0900194 struct drm_display_mode *adjusted_mode);
Sean Paulcd706aa2014-01-30 16:19:18 -0500195 void (*mode_set)(struct exynos_drm_manager *mgr,
196 const struct drm_display_mode *mode);
Sean Paulbb7704d2014-01-30 16:19:06 -0500197 void (*commit)(struct exynos_drm_manager *mgr);
198 int (*enable_vblank)(struct exynos_drm_manager *mgr);
199 void (*disable_vblank)(struct exynos_drm_manager *mgr);
200 void (*wait_for_vblank)(struct exynos_drm_manager *mgr);
201 void (*win_mode_set)(struct exynos_drm_manager *mgr,
Sean Paul1c6244c2014-01-30 16:19:02 -0500202 struct exynos_drm_overlay *overlay);
Sean Paulbb7704d2014-01-30 16:19:06 -0500203 void (*win_commit)(struct exynos_drm_manager *mgr, int zpos);
204 void (*win_enable)(struct exynos_drm_manager *mgr, int zpos);
205 void (*win_disable)(struct exynos_drm_manager *mgr, int zpos);
YoungJun Cho5595d4d2014-07-17 18:01:19 +0900206 void (*te_handler)(struct exynos_drm_manager *mgr);
Inki Dae1c248b72011-10-04 19:19:01 +0900207};
208
209/*
Sean Paul080be03d2014-02-19 21:02:55 +0900210 * Exynos drm common manager structure, maps 1:1 with a crtc
Inki Dae1c248b72011-10-04 19:19:01 +0900211 *
Sean Paul080be03d2014-02-19 21:02:55 +0900212 * @list: the list entry for this manager
213 * @type: one of EXYNOS_DISPLAY_TYPE_LCD and HDMI.
214 * @drm_dev: pointer to the drm device
Inki Daef37cd5e2014-05-09 14:25:20 +0900215 * @crtc: crtc object.
Sean Paul080be03d2014-02-19 21:02:55 +0900216 * @pipe: the pipe number for this crtc/manager
217 * @ops: pointer to callbacks for exynos drm specific functionality
Sean Paulbb7704d2014-01-30 16:19:06 -0500218 * @ctx: A pointer to the manager's implementation specific context
Inki Dae1c248b72011-10-04 19:19:01 +0900219 */
220struct exynos_drm_manager {
Sean Paul080be03d2014-02-19 21:02:55 +0900221 struct list_head list;
222 enum exynos_drm_output_type type;
223 struct drm_device *drm_dev;
Inki Daef37cd5e2014-05-09 14:25:20 +0900224 struct drm_crtc *crtc;
Inki Dae1c248b72011-10-04 19:19:01 +0900225 int pipe;
226 struct exynos_drm_manager_ops *ops;
Sean Paulbb7704d2014-01-30 16:19:06 -0500227 void *ctx;
Inki Dae1c248b72011-10-04 19:19:01 +0900228};
229
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900230struct exynos_drm_g2d_private {
231 struct device *dev;
232 struct list_head inuse_cmdlist;
233 struct list_head event_list;
Inki Dae2a3098f2012-11-04 05:48:52 -0800234 struct list_head userptr_list;
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900235};
236
237struct drm_exynos_file_private {
238 struct exynos_drm_g2d_private *g2d_priv;
Andrzej Hajda5c76c5b2014-07-03 15:10:28 +0200239 struct device *ipp_dev;
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900240};
241
Inki Dae1c248b72011-10-04 19:19:01 +0900242/*
243 * Exynos drm private structure.
Inki Dae0519f9a2012-10-20 07:53:42 -0700244 *
245 * @da_start: start address to device address space.
246 * with iommu, device address space starts from this address
247 * otherwise default one.
248 * @da_space_size: size of device address space.
249 * if 0 then default value is used for it.
Inki Daef37cd5e2014-05-09 14:25:20 +0900250 * @pipe: the pipe number for this crtc/manager.
Inki Dae1c248b72011-10-04 19:19:01 +0900251 */
252struct exynos_drm_private {
253 struct drm_fb_helper *fb_helper;
254
Inki Daeccf4d882011-10-14 13:29:51 +0900255 /* list head for new event to be added. */
Inki Dae1c248b72011-10-04 19:19:01 +0900256 struct list_head pageflip_event_list;
Inki Dae1c248b72011-10-04 19:19:01 +0900257
258 /*
259 * created crtc object would be contained at this array and
260 * this array is used to be aware of which crtc did it request vblank.
261 */
262 struct drm_crtc *crtc[MAX_CRTC];
Joonyoung Shim00ae67c2012-06-27 14:27:06 +0900263 struct drm_property *plane_zpos_property;
Joonyoung Shim3b8d1cf2012-06-27 14:27:11 +0900264 struct drm_property *crtc_mode_property;
Inki Dae0519f9a2012-10-20 07:53:42 -0700265
266 unsigned long da_start;
267 unsigned long da_space_size;
Inki Daef37cd5e2014-05-09 14:25:20 +0900268
269 unsigned int pipe;
Inki Dae1c248b72011-10-04 19:19:01 +0900270};
271
272/*
273 * Exynos drm sub driver structure.
274 *
275 * @list: sub driver has its own list object to register to exynos drm driver.
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900276 * @dev: pointer to device object for subdrv device driver.
Inki Dae1c248b72011-10-04 19:19:01 +0900277 * @drm_dev: pointer to drm_device and this pointer would be set
278 * when sub driver calls exynos_drm_subdrv_register().
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900279 * @manager: subdrv has its own manager to control a hardware appropriately
Inki Daef37cd5e2014-05-09 14:25:20 +0900280 * and we can access a hardware drawing on this manager.
Inki Dae1c248b72011-10-04 19:19:01 +0900281 * @probe: this callback would be called by exynos drm driver after
Inki Daef37cd5e2014-05-09 14:25:20 +0900282 * subdrv is registered to it.
Inki Dae1c248b72011-10-04 19:19:01 +0900283 * @remove: this callback is used to release resources created
Inki Daef37cd5e2014-05-09 14:25:20 +0900284 * by probe callback.
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900285 * @open: this would be called with drm device file open.
286 * @close: this would be called with drm device file close.
Inki Dae1c248b72011-10-04 19:19:01 +0900287 */
288struct exynos_drm_subdrv {
289 struct list_head list;
Joonyoung Shim677e84c2012-04-05 20:49:27 +0900290 struct device *dev;
Inki Dae1c248b72011-10-04 19:19:01 +0900291 struct drm_device *drm_dev;
292
Inki Dae41c24342011-10-14 13:29:48 +0900293 int (*probe)(struct drm_device *drm_dev, struct device *dev);
Inki Dae29cb6022012-09-05 14:12:06 +0900294 void (*remove)(struct drm_device *drm_dev, struct device *dev);
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900295 int (*open)(struct drm_device *drm_dev, struct device *dev,
296 struct drm_file *file);
297 void (*close)(struct drm_device *drm_dev, struct device *dev,
298 struct drm_file *file);
Inki Dae1c248b72011-10-04 19:19:01 +0900299};
300
Inki Daef37cd5e2014-05-09 14:25:20 +0900301 /* This function would be called by non kms drivers such as g2d and ipp. */
Inki Dae1c248b72011-10-04 19:19:01 +0900302int exynos_drm_subdrv_register(struct exynos_drm_subdrv *drm_subdrv);
303
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900304/* this function removes subdrv list from exynos drm driver */
Inki Dae1c248b72011-10-04 19:19:01 +0900305int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *drm_subdrv);
306
Inki Daef37cd5e2014-05-09 14:25:20 +0900307int exynos_drm_device_subdrv_probe(struct drm_device *dev);
308int exynos_drm_device_subdrv_remove(struct drm_device *dev);
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900309int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file);
310void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file);
311
Rahul Sharmaae9dace2012-10-16 05:50:13 +0530312/*
313 * this function registers exynos drm hdmi platform device. It ensures only one
314 * instance of the device is created.
315 */
Seung-Woo Kim0f6f9592013-04-22 18:40:34 +0900316int exynos_platform_device_hdmi_register(void);
Rahul Sharmaae9dace2012-10-16 05:50:13 +0530317
318/*
319 * this function unregisters exynos drm hdmi platform device if it exists.
320 */
321void exynos_platform_device_hdmi_unregister(void);
322
Andrzej Hajda72390672014-11-13 16:37:57 +0900323#ifdef CONFIG_DRM_EXYNOS_IPP
Seung-Woo Kim43f41902013-04-23 14:02:53 +0900324int exynos_platform_device_ipp_register(void);
Seung-Woo Kim43f41902013-04-23 14:02:53 +0900325void exynos_platform_device_ipp_unregister(void);
Andrzej Hajda72390672014-11-13 16:37:57 +0900326#else
327static inline int exynos_platform_device_ipp_register(void) { return 0; }
328static inline void exynos_platform_device_ipp_unregister(void) {}
329#endif
330
Seung-Woo Kim43f41902013-04-23 14:02:53 +0900331
Andrzej Hajda14b68732014-03-17 13:03:56 +0100332#ifdef CONFIG_DRM_EXYNOS_DPI
Andrzej Hajda000cc922014-04-03 16:26:00 +0200333struct exynos_drm_display * exynos_dpi_probe(struct device *dev);
334int exynos_dpi_remove(struct device *dev);
Andrzej Hajda14b68732014-03-17 13:03:56 +0100335#else
Andrzej Hajda000cc922014-04-03 16:26:00 +0200336static inline struct exynos_drm_display *
Dan Carpenterdcdffeda2014-06-11 09:36:23 +0300337exynos_dpi_probe(struct device *dev) { return NULL; }
Andrzej Hajda000cc922014-04-03 16:26:00 +0200338static inline int exynos_dpi_remove(struct device *dev) { return 0; }
Andrzej Hajda14b68732014-03-17 13:03:56 +0100339#endif
340
Andrzej Hajda72390672014-11-13 16:37:57 +0900341#ifdef CONFIG_DRM_EXYNOS_VIDI
Inki Daef37cd5e2014-05-09 14:25:20 +0900342int exynos_drm_probe_vidi(void);
Inki Daef37cd5e2014-05-09 14:25:20 +0900343void exynos_drm_remove_vidi(void);
Andrzej Hajda72390672014-11-13 16:37:57 +0900344#else
345static inline int exynos_drm_probe_vidi(void) { return 0; }
346static inline void exynos_drm_remove_vidi(void) {}
347#endif
Inki Daef37cd5e2014-05-09 14:25:20 +0900348
349/* This function creates a encoder and a connector, and initializes them. */
350int exynos_drm_create_enc_conn(struct drm_device *dev,
351 struct exynos_drm_display *display);
352
Inki Daef37cd5e2014-05-09 14:25:20 +0900353int exynos_drm_component_add(struct device *dev,
Inki Daedf5225b2014-05-29 18:28:02 +0900354 enum exynos_drm_device_type dev_type,
355 enum exynos_drm_output_type out_type);
Inki Daef37cd5e2014-05-09 14:25:20 +0900356
357void exynos_drm_component_del(struct device *dev,
Inki Daedf5225b2014-05-29 18:28:02 +0900358 enum exynos_drm_device_type dev_type);
Inki Daef37cd5e2014-05-09 14:25:20 +0900359
360extern struct platform_driver fimd_driver;
Sean Paul1417f102014-01-30 16:19:23 -0500361extern struct platform_driver dp_driver;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900362extern struct platform_driver dsi_driver;
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900363extern struct platform_driver mixer_driver;
Inki Daef37cd5e2014-05-09 14:25:20 +0900364extern struct platform_driver hdmi_driver;
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900365extern struct platform_driver exynos_drm_common_hdmi_driver;
Inki Daeb73d1232012-03-21 10:55:26 +0900366extern struct platform_driver vidi_driver;
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900367extern struct platform_driver g2d_driver;
Eunchul Kim16102ed2012-12-14 17:58:55 +0900368extern struct platform_driver fimc_driver;
Eunchul Kimbea8a422012-12-14 17:58:56 +0900369extern struct platform_driver rotator_driver;
Eunchul Kimf2646382012-12-14 17:58:57 +0900370extern struct platform_driver gsc_driver;
Eunchul Kimcb471f142012-12-14 18:10:31 +0900371extern struct platform_driver ipp_driver;
Inki Dae1c248b72011-10-04 19:19:01 +0900372#endif