2 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Inki Dae <inki.dae@samsung.com>
5 * Joonyoung Shim <jy0922.shim@samsung.com>
6 * Seung-Woo Kim <sw0312.kim@samsung.com>
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:
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
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.
30 #include "drm_crtc_helper.h"
32 #include <drm/exynos_drm.h>
34 #include "exynos_drm_drv.h"
35 #include "exynos_drm_crtc.h"
36 #include "exynos_drm_encoder.h"
37 #include "exynos_drm_fbdev.h"
38 #include "exynos_drm_fb.h"
39 #include "exynos_drm_gem.h"
40 #include "exynos_drm_plane.h"
41 #include "exynos_drm_vidi.h"
42 #include "exynos_drm_dmabuf.h"
44 #define DRIVER_NAME "exynos"
45 #define DRIVER_DESC "Samsung SoC DRM"
46 #define DRIVER_DATE "20110530"
47 #define DRIVER_MAJOR 1
48 #define DRIVER_MINOR 0
50 #define VBLANK_OFF_DELAY 50000
52 static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
54 struct exynos_drm_private *private;
58 DRM_DEBUG_DRIVER("%s\n", __FILE__);
60 private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
62 DRM_ERROR("failed to allocate private\n");
66 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
67 if (kds_callback_init(&private->kds_cb, 1,
68 exynos_drm_kds_callback) < 0) {
69 DRM_ERROR("kds alloc queue failed.\n");
73 if (kds_callback_init(&private->kds_cb_rm_fb, 0,
74 exynos_drm_kds_callback_rm_fb) < 0) {
75 DRM_ERROR("kds alloc queue failed.\n");
81 DRM_INIT_WAITQUEUE(&private->wait_vsync_queue);
82 atomic_set(&private->wait_vsync_event, 0);
84 dev->dev_private = (void *)private;
86 drm_mode_config_init(dev);
88 /* init kms poll for handling hpd */
89 drm_kms_helper_poll_init(dev);
91 exynos_drm_mode_config_init(dev);
94 * EXYNOS4 is enough to have two CRTCs and each crtc would be used
95 * without dependency of hardware.
97 for (nr = 0; nr < MAX_CRTC; nr++) {
98 ret = exynos_drm_crtc_create(dev, nr);
103 for (nr = 0; nr < MAX_PLANE; nr++) {
104 ret = exynos_plane_init(dev, nr);
109 ret = drm_vblank_init(dev, MAX_CRTC);
114 * probe sub drivers such as display controller and hdmi driver,
115 * that were registered at probe() of platform driver
116 * to the sub driver and create encoder and connector for them.
118 ret = exynos_drm_device_register(dev);
122 /* setup possible_clones. */
123 exynos_drm_encoder_setup(dev);
126 * create and configure fb helper and also exynos specific
129 ret = exynos_drm_fbdev_init(dev);
131 DRM_ERROR("failed to initialize drm fbdev\n");
135 drm_vblank_offdelay = VBLANK_OFF_DELAY;
140 exynos_drm_device_unregister(dev);
142 drm_vblank_cleanup(dev);
144 drm_mode_config_cleanup(dev);
145 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
146 kds_callback_term(&private->kds_cb_rm_fb);
148 kds_callback_term(&private->kds_cb);
156 static int exynos_drm_unload(struct drm_device *dev)
158 struct exynos_drm_private *private = dev->dev_private;
160 DRM_DEBUG_DRIVER("%s\n", __FILE__);
162 exynos_drm_fbdev_fini(dev);
163 exynos_drm_device_unregister(dev);
164 drm_vblank_cleanup(dev);
165 drm_kms_helper_poll_fini(dev);
166 drm_mode_config_cleanup(dev);
167 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
168 kds_callback_term(&private->kds_cb);
172 dev->dev_private = NULL;
177 static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
179 DRM_DEBUG_DRIVER("%s\n", __FILE__);
181 return exynos_drm_subdrv_open(dev, file);
184 static void exynos_drm_preclose(struct drm_device *dev,
185 struct drm_file *file)
187 DRM_DEBUG_DRIVER("%s\n", __FILE__);
189 exynos_drm_subdrv_close(dev, file);
192 static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
194 DRM_DEBUG_DRIVER("%s\n", __FILE__);
196 if (!file->driver_priv)
199 kfree(file->driver_priv);
200 file->driver_priv = NULL;
203 static void exynos_drm_lastclose(struct drm_device *dev)
205 DRM_DEBUG_DRIVER("%s\n", __FILE__);
207 exynos_drm_fbdev_restore_mode(dev);
210 static struct vm_operations_struct exynos_drm_gem_vm_ops = {
211 .fault = exynos_drm_gem_fault,
212 .open = drm_gem_vm_open,
213 .close = drm_gem_vm_close,
216 static struct drm_ioctl_desc exynos_ioctls[] = {
217 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
218 DRM_UNLOCKED | DRM_AUTH),
219 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
220 exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
222 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
223 exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
224 DRM_IOCTL_DEF_DRV(EXYNOS_PLANE_SET_ZPOS, exynos_plane_set_zpos_ioctl,
225 DRM_UNLOCKED | DRM_AUTH),
226 DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION,
227 vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH),
230 static const struct file_operations exynos_drm_driver_fops = {
231 .owner = THIS_MODULE,
233 .mmap = exynos_drm_gem_mmap,
236 .unlocked_ioctl = drm_ioctl,
237 .release = drm_release,
240 static struct drm_driver exynos_drm_driver = {
241 .driver_features = DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
242 DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
243 .load = exynos_drm_load,
244 .unload = exynos_drm_unload,
245 .open = exynos_drm_open,
246 .preclose = exynos_drm_preclose,
247 .lastclose = exynos_drm_lastclose,
248 .postclose = exynos_drm_postclose,
249 .get_vblank_counter = drm_vblank_count,
250 .enable_vblank = exynos_drm_crtc_enable_vblank,
251 .disable_vblank = exynos_drm_crtc_disable_vblank,
252 .gem_init_object = exynos_drm_gem_init_object,
253 .gem_free_object = exynos_drm_gem_free_object,
254 .gem_vm_ops = &exynos_drm_gem_vm_ops,
255 .dumb_create = exynos_drm_gem_dumb_create,
256 .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
257 .dumb_destroy = exynos_drm_gem_dumb_destroy,
258 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
259 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
260 .gem_prime_export = exynos_dmabuf_prime_export,
261 .gem_prime_import = exynos_dmabuf_prime_import,
262 .ioctls = exynos_ioctls,
263 .fops = &exynos_drm_driver_fops,
267 .major = DRIVER_MAJOR,
268 .minor = DRIVER_MINOR,
271 #ifdef CONFIG_EXYNOS_IOMMU
272 static int iommu_init(struct platform_device *pdev)
274 /* DRM device expects a IOMMU mapping to be already
275 * created in FIMD. Else this function should
278 if (exynos_drm_common_mapping==NULL) {
279 printk(KERN_ERR "exynos drm common mapping is invalid\n");
284 * The ordering in Makefile warrants that this is initialized after
285 * FIMD, so only just ensure that it works as expected and we are
286 * reusing the mapping originally created in exynos_drm_fimd.c.
288 WARN_ON(!exynos_drm_common_mapping);
289 if (!s5p_create_iommu_mapping(&pdev->dev, 0,
290 0, 0, exynos_drm_common_mapping)) {
291 printk(KERN_ERR "failed to create IOMMU mapping\n");
298 static void iommu_deinit(struct platform_device *pdev)
300 /* detach the device and mapping */
301 s5p_destroy_iommu_mapping(&pdev->dev);
302 DRM_DEBUG("released the IOMMU mapping\n");
308 static int exynos_drm_platform_probe(struct platform_device *pdev)
310 DRM_DEBUG_DRIVER("%s\n", __FILE__);
312 #ifdef CONFIG_EXYNOS_IOMMU
313 if (iommu_init(pdev)) {
314 DRM_ERROR("failed to initialize IOMMU\n");
319 exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
321 return drm_platform_init(&exynos_drm_driver, pdev);
324 static int __devexit exynos_drm_platform_remove(struct platform_device *pdev)
326 DRM_DEBUG_DRIVER("%s\n", __FILE__);
328 drm_platform_exit(&exynos_drm_driver, pdev);
330 #ifdef CONFIG_EXYNOS_IOMMU
336 static struct platform_driver exynos_drm_platform_driver = {
337 .probe = exynos_drm_platform_probe,
338 .remove = __devexit_p(exynos_drm_platform_remove),
340 .owner = THIS_MODULE,
341 .name = "exynos-drm",
345 static int __init exynos_drm_init(void)
349 DRM_DEBUG_DRIVER("%s\n", __FILE__);
351 #ifdef CONFIG_DRM_EXYNOS_FIMD
352 ret = platform_driver_register(&fimd_driver);
357 #ifdef CONFIG_DRM_EXYNOS_DP
358 ret = platform_driver_register(&dp_driver);
363 #ifdef CONFIG_DRM_EXYNOS_HDMI
364 ret = platform_driver_register(&hdmi_driver);
367 ret = platform_driver_register(&mixer_driver);
370 ret = platform_driver_register(&exynos_drm_common_hdmi_driver);
372 goto out_common_hdmi;
375 #ifdef CONFIG_DRM_EXYNOS_VIDI
376 ret = platform_driver_register(&vidi_driver);
381 ret = platform_driver_register(&exynos_drm_platform_driver);
388 #ifdef CONFIG_DRM_EXYNOS_VIDI
390 platform_driver_unregister(&vidi_driver);
393 #ifdef CONFIG_DRM_EXYNOS_HDMI
394 platform_driver_unregister(&exynos_drm_common_hdmi_driver);
396 platform_driver_unregister(&mixer_driver);
398 platform_driver_unregister(&hdmi_driver);
402 platform_driver_unregister(&dp_driver);
404 #ifdef CONFIG_DRM_EXYNOS_FIMD
405 platform_driver_unregister(&fimd_driver);
411 static void __exit exynos_drm_exit(void)
413 DRM_DEBUG_DRIVER("%s\n", __FILE__);
415 platform_driver_unregister(&exynos_drm_platform_driver);
417 #ifdef CONFIG_DRM_EXYNOS_HDMI
418 platform_driver_unregister(&exynos_drm_common_hdmi_driver);
419 platform_driver_unregister(&mixer_driver);
420 platform_driver_unregister(&hdmi_driver);
423 #ifdef CONFIG_DRM_EXYNOS_VIDI
424 platform_driver_unregister(&vidi_driver);
427 platform_driver_unregister(&dp_driver);
428 #ifdef CONFIG_DRM_EXYNOS_FIMD
429 platform_driver_unregister(&fimd_driver);
433 module_init(exynos_drm_init);
434 module_exit(exynos_drm_exit);
436 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
437 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
438 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
439 MODULE_DESCRIPTION("Samsung SoC DRM Driver");
440 MODULE_LICENSE("GPL");