blob: e313dc23e2a8e2491df8cfa934eaced2065a3084 [file] [log] [blame]
Inki Dae1c248b72011-10-04 19:19:01 +09001/*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
3 * Authors:
4 * Inki Dae <inki.dae@samsung.com>
5 * Joonyoung Shim <jy0922.shim@samsung.com>
6 * Seung-Woo Kim <sw0312.kim@samsung.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#include "drmP.h"
29#include "drm.h"
Seung-Woo Kim7db3eba2011-10-18 16:58:05 +090030#include "drm_crtc_helper.h"
Inki Dae1c248b72011-10-04 19:19:01 +090031
32#include <drm/exynos_drm.h>
33
34#include "exynos_drm_drv.h"
35#include "exynos_drm_crtc.h"
Inki Daed081f562012-02-15 11:25:19 +090036#include "exynos_drm_encoder.h"
Inki Dae1c248b72011-10-04 19:19:01 +090037#include "exynos_drm_fbdev.h"
38#include "exynos_drm_fb.h"
39#include "exynos_drm_gem.h"
Joonyoung Shim864ee9e2011-12-08 17:54:07 +090040#include "exynos_drm_plane.h"
Inki Daeb73d1232012-03-21 10:55:26 +090041#include "exynos_drm_vidi.h"
Inki Daeb2df26c2012-04-23 21:01:28 +090042#include "exynos_drm_dmabuf.h"
Joonyoung Shimd7f16422012-05-17 20:06:32 +090043#include "exynos_drm_g2d.h"
Inki Dae1c248b72011-10-04 19:19:01 +090044
Inki Dae0edf9932011-12-15 17:31:24 +090045#define DRIVER_NAME "exynos"
Inki Dae1c248b72011-10-04 19:19:01 +090046#define DRIVER_DESC "Samsung SoC DRM"
47#define DRIVER_DATE "20110530"
48#define DRIVER_MAJOR 1
49#define DRIVER_MINOR 0
50
Inki Dae52c68812011-12-16 21:31:12 +090051#define VBLANK_OFF_DELAY 50000
52
Inki Dae1c248b72011-10-04 19:19:01 +090053static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
54{
55 struct exynos_drm_private *private;
56 int ret;
57 int nr;
58
59 DRM_DEBUG_DRIVER("%s\n", __FILE__);
60
61 private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
62 if (!private) {
63 DRM_ERROR("failed to allocate private\n");
64 return -ENOMEM;
65 }
66
67 INIT_LIST_HEAD(&private->pageflip_event_list);
68 dev->dev_private = (void *)private;
69
70 drm_mode_config_init(dev);
71
Seung-Woo Kim7db3eba2011-10-18 16:58:05 +090072 /* init kms poll for handling hpd */
73 drm_kms_helper_poll_init(dev);
74
Inki Dae1c248b72011-10-04 19:19:01 +090075 exynos_drm_mode_config_init(dev);
76
77 /*
78 * EXYNOS4 is enough to have two CRTCs and each crtc would be used
79 * without dependency of hardware.
80 */
81 for (nr = 0; nr < MAX_CRTC; nr++) {
82 ret = exynos_drm_crtc_create(dev, nr);
83 if (ret)
84 goto err_crtc;
85 }
86
Joonyoung Shim864ee9e2011-12-08 17:54:07 +090087 for (nr = 0; nr < MAX_PLANE; nr++) {
Joonyoung Shimb5d2eb32012-06-27 14:27:04 +090088 struct drm_plane *plane;
89 unsigned int possible_crtcs = (1 << MAX_CRTC) - 1;
90
91 plane = exynos_plane_init(dev, possible_crtcs, false);
92 if (!plane)
Joonyoung Shim864ee9e2011-12-08 17:54:07 +090093 goto err_crtc;
94 }
95
Inki Dae1c248b72011-10-04 19:19:01 +090096 ret = drm_vblank_init(dev, MAX_CRTC);
97 if (ret)
98 goto err_crtc;
99
100 /*
101 * probe sub drivers such as display controller and hdmi driver,
102 * that were registered at probe() of platform driver
103 * to the sub driver and create encoder and connector for them.
104 */
105 ret = exynos_drm_device_register(dev);
106 if (ret)
107 goto err_vblank;
108
Inki Daed081f562012-02-15 11:25:19 +0900109 /* setup possible_clones. */
110 exynos_drm_encoder_setup(dev);
111
Inki Dae1c248b72011-10-04 19:19:01 +0900112 /*
113 * create and configure fb helper and also exynos specific
114 * fbdev object.
115 */
116 ret = exynos_drm_fbdev_init(dev);
117 if (ret) {
118 DRM_ERROR("failed to initialize drm fbdev\n");
119 goto err_drm_device;
120 }
121
Inki Dae52c68812011-12-16 21:31:12 +0900122 drm_vblank_offdelay = VBLANK_OFF_DELAY;
123
Inki Dae1c248b72011-10-04 19:19:01 +0900124 return 0;
125
126err_drm_device:
127 exynos_drm_device_unregister(dev);
128err_vblank:
129 drm_vblank_cleanup(dev);
130err_crtc:
131 drm_mode_config_cleanup(dev);
132 kfree(private);
133
134 return ret;
135}
136
137static int exynos_drm_unload(struct drm_device *dev)
138{
139 DRM_DEBUG_DRIVER("%s\n", __FILE__);
140
141 exynos_drm_fbdev_fini(dev);
142 exynos_drm_device_unregister(dev);
143 drm_vblank_cleanup(dev);
Seung-Woo Kim7db3eba2011-10-18 16:58:05 +0900144 drm_kms_helper_poll_fini(dev);
Inki Dae1c248b72011-10-04 19:19:01 +0900145 drm_mode_config_cleanup(dev);
146 kfree(dev->dev_private);
147
148 dev->dev_private = NULL;
149
150 return 0;
151}
152
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900153static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
Inki Daeccf4d882011-10-14 13:29:51 +0900154{
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900155 struct drm_exynos_file_private *file_priv;
156
Joonyoung Shim6f811502012-02-15 11:25:18 +0900157 DRM_DEBUG_DRIVER("%s\n", __FILE__);
Inki Daeccf4d882011-10-14 13:29:51 +0900158
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900159 file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
160 if (!file_priv)
161 return -ENOMEM;
162
Inki Daeb2df26c2012-04-23 21:01:28 +0900163 drm_prime_init_file_private(&file->prime);
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900164 file->driver_priv = file_priv;
Inki Daeb2df26c2012-04-23 21:01:28 +0900165
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900166 return exynos_drm_subdrv_open(dev, file);
167}
168
Inki Daeccf4d882011-10-14 13:29:51 +0900169static void exynos_drm_preclose(struct drm_device *dev,
170 struct drm_file *file)
171{
Joonyoung Shim3ab094352012-03-16 18:47:07 +0900172 struct exynos_drm_private *private = dev->dev_private;
173 struct drm_pending_vblank_event *e, *t;
174 unsigned long flags;
175
Inki Daeccf4d882011-10-14 13:29:51 +0900176 DRM_DEBUG_DRIVER("%s\n", __FILE__);
177
Joonyoung Shim3ab094352012-03-16 18:47:07 +0900178 /* release events of current file */
179 spin_lock_irqsave(&dev->event_lock, flags);
180 list_for_each_entry_safe(e, t, &private->pageflip_event_list,
181 base.link) {
182 if (e->base.file_priv == file) {
183 list_del(&e->base.link);
184 e->base.destroy(&e->base);
185 }
186 }
Inki Daeb2df26c2012-04-23 21:01:28 +0900187 drm_prime_destroy_file_private(&file->prime);
Joonyoung Shim3ab094352012-03-16 18:47:07 +0900188 spin_unlock_irqrestore(&dev->event_lock, flags);
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900189
190 exynos_drm_subdrv_close(dev, file);
Inki Daeccf4d882011-10-14 13:29:51 +0900191}
192
Inki Dae53ef2992012-02-15 11:25:22 +0900193static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
194{
195 DRM_DEBUG_DRIVER("%s\n", __FILE__);
196
197 if (!file->driver_priv)
198 return;
199
200 kfree(file->driver_priv);
201 file->driver_priv = NULL;
202}
203
Inki Dae1c248b72011-10-04 19:19:01 +0900204static void exynos_drm_lastclose(struct drm_device *dev)
205{
206 DRM_DEBUG_DRIVER("%s\n", __FILE__);
207
208 exynos_drm_fbdev_restore_mode(dev);
209}
210
Laurent Pinchart78b68552012-05-17 13:27:22 +0200211static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
Inki Dae1c248b72011-10-04 19:19:01 +0900212 .fault = exynos_drm_gem_fault,
213 .open = drm_gem_vm_open,
214 .close = drm_gem_vm_close,
215};
216
217static struct drm_ioctl_desc exynos_ioctls[] = {
218 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
219 DRM_UNLOCKED | DRM_AUTH),
220 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
221 exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
222 DRM_AUTH),
223 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
224 exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
Inki Dae40cd7e02012-05-04 15:51:17 +0900225 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET,
226 exynos_drm_gem_get_ioctl, DRM_UNLOCKED),
Joonyoung Shim864ee9e2011-12-08 17:54:07 +0900227 DRM_IOCTL_DEF_DRV(EXYNOS_PLANE_SET_ZPOS, exynos_plane_set_zpos_ioctl,
228 DRM_UNLOCKED | DRM_AUTH),
Inki Daeb73d1232012-03-21 10:55:26 +0900229 DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION,
230 vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH),
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900231 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER,
232 exynos_g2d_get_ver_ioctl, DRM_UNLOCKED | DRM_AUTH),
233 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST,
234 exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED | DRM_AUTH),
235 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC,
236 exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH),
Inki Dae1c248b72011-10-04 19:19:01 +0900237};
238
Joonyoung Shimac2bdf72011-12-08 15:00:20 +0900239static const struct file_operations exynos_drm_driver_fops = {
240 .owner = THIS_MODULE,
241 .open = drm_open,
242 .mmap = exynos_drm_gem_mmap,
243 .poll = drm_poll,
244 .read = drm_read,
245 .unlocked_ioctl = drm_ioctl,
246 .release = drm_release,
247};
248
Inki Dae1c248b72011-10-04 19:19:01 +0900249static struct drm_driver exynos_drm_driver = {
Laurent Pinchart293a1c12012-05-16 17:08:53 +0200250 .driver_features = DRIVER_HAVE_IRQ | DRIVER_MODESET |
251 DRIVER_GEM | DRIVER_PRIME,
Inki Dae1c248b72011-10-04 19:19:01 +0900252 .load = exynos_drm_load,
253 .unload = exynos_drm_unload,
Joonyoung Shim9084f7b2012-03-16 18:47:09 +0900254 .open = exynos_drm_open,
Inki Daeccf4d882011-10-14 13:29:51 +0900255 .preclose = exynos_drm_preclose,
Inki Dae1c248b72011-10-04 19:19:01 +0900256 .lastclose = exynos_drm_lastclose,
Inki Dae53ef2992012-02-15 11:25:22 +0900257 .postclose = exynos_drm_postclose,
Inki Dae1c248b72011-10-04 19:19:01 +0900258 .get_vblank_counter = drm_vblank_count,
259 .enable_vblank = exynos_drm_crtc_enable_vblank,
260 .disable_vblank = exynos_drm_crtc_disable_vblank,
261 .gem_init_object = exynos_drm_gem_init_object,
262 .gem_free_object = exynos_drm_gem_free_object,
263 .gem_vm_ops = &exynos_drm_gem_vm_ops,
264 .dumb_create = exynos_drm_gem_dumb_create,
265 .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
266 .dumb_destroy = exynos_drm_gem_dumb_destroy,
Inki Daeb2df26c2012-04-23 21:01:28 +0900267 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
268 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
269 .gem_prime_export = exynos_dmabuf_prime_export,
270 .gem_prime_import = exynos_dmabuf_prime_import,
Inki Dae1c248b72011-10-04 19:19:01 +0900271 .ioctls = exynos_ioctls,
Joonyoung Shimac2bdf72011-12-08 15:00:20 +0900272 .fops = &exynos_drm_driver_fops,
Inki Dae1c248b72011-10-04 19:19:01 +0900273 .name = DRIVER_NAME,
274 .desc = DRIVER_DESC,
275 .date = DRIVER_DATE,
276 .major = DRIVER_MAJOR,
277 .minor = DRIVER_MINOR,
278};
279
280static int exynos_drm_platform_probe(struct platform_device *pdev)
281{
282 DRM_DEBUG_DRIVER("%s\n", __FILE__);
283
284 exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
285
286 return drm_platform_init(&exynos_drm_driver, pdev);
287}
288
289static int exynos_drm_platform_remove(struct platform_device *pdev)
290{
291 DRM_DEBUG_DRIVER("%s\n", __FILE__);
292
293 drm_platform_exit(&exynos_drm_driver, pdev);
294
295 return 0;
296}
297
298static struct platform_driver exynos_drm_platform_driver = {
299 .probe = exynos_drm_platform_probe,
300 .remove = __devexit_p(exynos_drm_platform_remove),
301 .driver = {
302 .owner = THIS_MODULE,
Marek Szyprowski9866b6c2012-03-05 12:02:30 +0100303 .name = "exynos-drm",
Inki Dae1c248b72011-10-04 19:19:01 +0900304 },
305};
306
307static int __init exynos_drm_init(void)
308{
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900309 int ret;
310
Inki Dae1c248b72011-10-04 19:19:01 +0900311 DRM_DEBUG_DRIVER("%s\n", __FILE__);
312
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900313#ifdef CONFIG_DRM_EXYNOS_FIMD
314 ret = platform_driver_register(&fimd_driver);
315 if (ret < 0)
316 goto out_fimd;
317#endif
318
319#ifdef CONFIG_DRM_EXYNOS_HDMI
320 ret = platform_driver_register(&hdmi_driver);
321 if (ret < 0)
322 goto out_hdmi;
323 ret = platform_driver_register(&mixer_driver);
324 if (ret < 0)
325 goto out_mixer;
326 ret = platform_driver_register(&exynos_drm_common_hdmi_driver);
327 if (ret < 0)
328 goto out_common_hdmi;
329#endif
330
Inki Daeb73d1232012-03-21 10:55:26 +0900331#ifdef CONFIG_DRM_EXYNOS_VIDI
332 ret = platform_driver_register(&vidi_driver);
333 if (ret < 0)
334 goto out_vidi;
335#endif
336
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900337#ifdef CONFIG_DRM_EXYNOS_G2D
338 ret = platform_driver_register(&g2d_driver);
339 if (ret < 0)
340 goto out_g2d;
341#endif
342
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900343 ret = platform_driver_register(&exynos_drm_platform_driver);
344 if (ret < 0)
345 goto out;
346
347 return 0;
348
349out:
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900350#ifdef CONFIG_DRM_EXYNOS_G2D
351 platform_driver_unregister(&g2d_driver);
352out_g2d:
353#endif
354
Inki Daeb73d1232012-03-21 10:55:26 +0900355#ifdef CONFIG_DRM_EXYNOS_VIDI
356out_vidi:
357 platform_driver_unregister(&vidi_driver);
358#endif
359
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900360#ifdef CONFIG_DRM_EXYNOS_HDMI
361 platform_driver_unregister(&exynos_drm_common_hdmi_driver);
362out_common_hdmi:
363 platform_driver_unregister(&mixer_driver);
364out_mixer:
365 platform_driver_unregister(&hdmi_driver);
366out_hdmi:
367#endif
368
369#ifdef CONFIG_DRM_EXYNOS_FIMD
370 platform_driver_unregister(&fimd_driver);
371out_fimd:
372#endif
373 return ret;
Inki Dae1c248b72011-10-04 19:19:01 +0900374}
375
376static void __exit exynos_drm_exit(void)
377{
378 DRM_DEBUG_DRIVER("%s\n", __FILE__);
379
380 platform_driver_unregister(&exynos_drm_platform_driver);
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900381
Joonyoung Shimd7f16422012-05-17 20:06:32 +0900382#ifdef CONFIG_DRM_EXYNOS_G2D
383 platform_driver_unregister(&g2d_driver);
384#endif
385
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900386#ifdef CONFIG_DRM_EXYNOS_HDMI
387 platform_driver_unregister(&exynos_drm_common_hdmi_driver);
388 platform_driver_unregister(&mixer_driver);
389 platform_driver_unregister(&hdmi_driver);
390#endif
391
Inki Daeb73d1232012-03-21 10:55:26 +0900392#ifdef CONFIG_DRM_EXYNOS_VIDI
393 platform_driver_unregister(&vidi_driver);
394#endif
395
Joonyoung Shim132a5b92012-03-16 18:47:08 +0900396#ifdef CONFIG_DRM_EXYNOS_FIMD
397 platform_driver_unregister(&fimd_driver);
398#endif
Inki Dae1c248b72011-10-04 19:19:01 +0900399}
400
401module_init(exynos_drm_init);
402module_exit(exynos_drm_exit);
403
404MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
405MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
406MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
407MODULE_DESCRIPTION("Samsung SoC DRM Driver");
408MODULE_LICENSE("GPL");