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_fbdev.h"
37 #include "exynos_drm_fb.h"
38 #include "exynos_drm_gem.h"
39 #include "exynos_drm_plane.h"
41 #define DRIVER_NAME "exynos-drm"
42 #define DRIVER_DESC "Samsung SoC DRM"
43 #define DRIVER_DATE "20110530"
44 #define DRIVER_MAJOR 1
45 #define DRIVER_MINOR 0
47 static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
49 struct exynos_drm_private *private;
53 DRM_DEBUG_DRIVER("%s\n", __FILE__);
55 private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
57 DRM_ERROR("failed to allocate private\n");
61 INIT_LIST_HEAD(&private->pageflip_event_list);
62 dev->dev_private = (void *)private;
64 drm_mode_config_init(dev);
66 /* init kms poll for handling hpd */
67 drm_kms_helper_poll_init(dev);
69 exynos_drm_mode_config_init(dev);
72 * EXYNOS4 is enough to have two CRTCs and each crtc would be used
73 * without dependency of hardware.
75 for (nr = 0; nr < MAX_CRTC; nr++) {
76 ret = exynos_drm_crtc_create(dev, nr);
81 for (nr = 0; nr < MAX_PLANE; nr++) {
82 ret = exynos_plane_init(dev, nr);
87 ret = drm_vblank_init(dev, MAX_CRTC);
92 * probe sub drivers such as display controller and hdmi driver,
93 * that were registered at probe() of platform driver
94 * to the sub driver and create encoder and connector for them.
96 ret = exynos_drm_device_register(dev);
101 * create and configure fb helper and also exynos specific
104 ret = exynos_drm_fbdev_init(dev);
106 DRM_ERROR("failed to initialize drm fbdev\n");
113 exynos_drm_device_unregister(dev);
115 drm_vblank_cleanup(dev);
117 drm_mode_config_cleanup(dev);
123 static int exynos_drm_unload(struct drm_device *dev)
125 DRM_DEBUG_DRIVER("%s\n", __FILE__);
127 exynos_drm_fbdev_fini(dev);
128 exynos_drm_device_unregister(dev);
129 drm_vblank_cleanup(dev);
130 drm_kms_helper_poll_fini(dev);
131 drm_mode_config_cleanup(dev);
132 kfree(dev->dev_private);
134 dev->dev_private = NULL;
139 static void exynos_drm_preclose(struct drm_device *dev,
140 struct drm_file *file_priv)
142 struct exynos_drm_private *dev_priv = dev->dev_private;
145 * drm framework frees all events at release time,
146 * so private event list should be cleared.
148 if (!list_empty(&dev_priv->pageflip_event_list))
149 INIT_LIST_HEAD(&dev_priv->pageflip_event_list);
152 static void exynos_drm_lastclose(struct drm_device *dev)
154 DRM_DEBUG_DRIVER("%s\n", __FILE__);
156 exynos_drm_fbdev_restore_mode(dev);
159 static struct vm_operations_struct exynos_drm_gem_vm_ops = {
160 .fault = exynos_drm_gem_fault,
161 .open = drm_gem_vm_open,
162 .close = drm_gem_vm_close,
165 static struct drm_ioctl_desc exynos_ioctls[] = {
166 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
167 DRM_UNLOCKED | DRM_AUTH),
168 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
169 exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
171 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
172 exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
173 DRM_IOCTL_DEF_DRV(EXYNOS_PLANE_SET_ZPOS, exynos_plane_set_zpos_ioctl,
174 DRM_UNLOCKED | DRM_AUTH),
177 static const struct file_operations exynos_drm_driver_fops = {
178 .owner = THIS_MODULE,
180 .mmap = exynos_drm_gem_mmap,
183 .unlocked_ioctl = drm_ioctl,
184 .release = drm_release,
187 static struct drm_driver exynos_drm_driver = {
188 .driver_features = DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
189 DRIVER_MODESET | DRIVER_GEM,
190 .load = exynos_drm_load,
191 .unload = exynos_drm_unload,
192 .preclose = exynos_drm_preclose,
193 .lastclose = exynos_drm_lastclose,
194 .get_vblank_counter = drm_vblank_count,
195 .enable_vblank = exynos_drm_crtc_enable_vblank,
196 .disable_vblank = exynos_drm_crtc_disable_vblank,
197 .gem_init_object = exynos_drm_gem_init_object,
198 .gem_free_object = exynos_drm_gem_free_object,
199 .gem_vm_ops = &exynos_drm_gem_vm_ops,
200 .dumb_create = exynos_drm_gem_dumb_create,
201 .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
202 .dumb_destroy = exynos_drm_gem_dumb_destroy,
203 .ioctls = exynos_ioctls,
204 .fops = &exynos_drm_driver_fops,
208 .major = DRIVER_MAJOR,
209 .minor = DRIVER_MINOR,
212 static int exynos_drm_platform_probe(struct platform_device *pdev)
214 DRM_DEBUG_DRIVER("%s\n", __FILE__);
216 exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
218 return drm_platform_init(&exynos_drm_driver, pdev);
221 static int exynos_drm_platform_remove(struct platform_device *pdev)
223 DRM_DEBUG_DRIVER("%s\n", __FILE__);
225 drm_platform_exit(&exynos_drm_driver, pdev);
230 static struct platform_driver exynos_drm_platform_driver = {
231 .probe = exynos_drm_platform_probe,
232 .remove = __devexit_p(exynos_drm_platform_remove),
234 .owner = THIS_MODULE,
239 static int __init exynos_drm_init(void)
241 DRM_DEBUG_DRIVER("%s\n", __FILE__);
243 return platform_driver_register(&exynos_drm_platform_driver);
246 static void __exit exynos_drm_exit(void)
248 DRM_DEBUG_DRIVER("%s\n", __FILE__);
250 platform_driver_unregister(&exynos_drm_platform_driver);
253 module_init(exynos_drm_init);
254 module_exit(exynos_drm_exit);
256 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
257 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
258 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
259 MODULE_DESCRIPTION("Samsung SoC DRM Driver");
260 MODULE_LICENSE("GPL");