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.
29 #include <drm/drm_crtc_helper.h>
31 #include <drm/exynos_drm.h>
33 #include "exynos_drm_drv.h"
34 #include "exynos_drm_crtc.h"
35 #include "exynos_drm_encoder.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"
40 #include "exynos_drm_vidi.h"
41 #include "exynos_drm_dmabuf.h"
42 #include "exynos_drm_g2d.h"
43 #include "exynos_drm_iommu.h"
45 #define DRIVER_NAME "exynos"
46 #define DRIVER_DESC "Samsung SoC DRM"
47 #define DRIVER_DATE "20110530"
48 #define DRIVER_MAJOR 1
49 #define DRIVER_MINOR 0
51 #define VBLANK_OFF_DELAY 50000
53 /* platform device pointer for eynos drm device. */
54 static struct platform_device *exynos_drm_pdev;
56 static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
58 struct exynos_drm_private *private;
62 DRM_DEBUG_DRIVER("%s\n", __FILE__);
64 private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
66 DRM_ERROR("failed to allocate private\n");
70 INIT_LIST_HEAD(&private->pageflip_event_list);
71 dev->dev_private = (void *)private;
74 * create mapping to manage iommu table and set a pointer to iommu
75 * mapping structure to iommu_mapping of private data.
76 * also this iommu_mapping can be used to check if iommu is supported
79 ret = drm_create_iommu_mapping(dev);
81 DRM_ERROR("failed to create iommu mapping.\n");
85 drm_mode_config_init(dev);
87 /* init kms poll for handling hpd */
88 drm_kms_helper_poll_init(dev);
90 exynos_drm_mode_config_init(dev);
93 * EXYNOS4 is enough to have two CRTCs and each crtc would be used
94 * without dependency of hardware.
96 for (nr = 0; nr < MAX_CRTC; nr++) {
97 ret = exynos_drm_crtc_create(dev, nr);
99 goto err_release_iommu_mapping;
102 for (nr = 0; nr < MAX_PLANE; nr++) {
103 struct drm_plane *plane;
104 unsigned int possible_crtcs = (1 << MAX_CRTC) - 1;
106 plane = exynos_plane_init(dev, possible_crtcs, false);
108 goto err_release_iommu_mapping;
111 ret = drm_vblank_init(dev, MAX_CRTC);
113 goto err_release_iommu_mapping;
116 * probe sub drivers such as display controller and hdmi driver,
117 * that were registered at probe() of platform driver
118 * to the sub driver and create encoder and connector for them.
120 ret = exynos_drm_device_register(dev);
124 /* setup possible_clones. */
125 exynos_drm_encoder_setup(dev);
128 * create and configure fb helper and also exynos specific
131 ret = exynos_drm_fbdev_init(dev);
133 DRM_ERROR("failed to initialize drm fbdev\n");
137 drm_vblank_offdelay = VBLANK_OFF_DELAY;
142 exynos_drm_device_unregister(dev);
144 drm_vblank_cleanup(dev);
145 err_release_iommu_mapping:
146 drm_release_iommu_mapping(dev);
148 drm_mode_config_cleanup(dev);
154 static int exynos_drm_unload(struct drm_device *dev)
156 DRM_DEBUG_DRIVER("%s\n", __FILE__);
158 exynos_drm_fbdev_fini(dev);
159 exynos_drm_device_unregister(dev);
160 drm_vblank_cleanup(dev);
161 drm_kms_helper_poll_fini(dev);
162 drm_mode_config_cleanup(dev);
164 drm_release_iommu_mapping(dev);
165 kfree(dev->dev_private);
167 dev->dev_private = NULL;
172 static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
174 struct drm_exynos_file_private *file_priv;
176 DRM_DEBUG_DRIVER("%s\n", __FILE__);
178 file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
182 file->driver_priv = file_priv;
184 return exynos_drm_subdrv_open(dev, file);
187 static void exynos_drm_preclose(struct drm_device *dev,
188 struct drm_file *file)
190 struct exynos_drm_private *private = dev->dev_private;
191 struct drm_pending_vblank_event *e, *t;
194 DRM_DEBUG_DRIVER("%s\n", __FILE__);
196 /* release events of current file */
197 spin_lock_irqsave(&dev->event_lock, flags);
198 list_for_each_entry_safe(e, t, &private->pageflip_event_list,
200 if (e->base.file_priv == file) {
201 list_del(&e->base.link);
202 e->base.destroy(&e->base);
205 spin_unlock_irqrestore(&dev->event_lock, flags);
207 exynos_drm_subdrv_close(dev, file);
210 static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
212 DRM_DEBUG_DRIVER("%s\n", __FILE__);
214 if (!file->driver_priv)
217 kfree(file->driver_priv);
218 file->driver_priv = NULL;
221 static void exynos_drm_lastclose(struct drm_device *dev)
223 DRM_DEBUG_DRIVER("%s\n", __FILE__);
225 exynos_drm_fbdev_restore_mode(dev);
228 static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
229 .fault = exynos_drm_gem_fault,
230 .open = drm_gem_vm_open,
231 .close = drm_gem_vm_close,
234 static struct drm_ioctl_desc exynos_ioctls[] = {
235 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
236 DRM_UNLOCKED | DRM_AUTH),
237 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
238 exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
240 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
241 exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
242 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET,
243 exynos_drm_gem_get_ioctl, DRM_UNLOCKED),
244 DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION,
245 vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH),
246 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER,
247 exynos_g2d_get_ver_ioctl, DRM_UNLOCKED | DRM_AUTH),
248 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST,
249 exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED | DRM_AUTH),
250 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC,
251 exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH),
254 static const struct file_operations exynos_drm_driver_fops = {
255 .owner = THIS_MODULE,
257 .mmap = exynos_drm_gem_mmap,
260 .unlocked_ioctl = drm_ioctl,
262 .compat_ioctl = drm_compat_ioctl,
264 .release = drm_release,
267 static struct drm_driver exynos_drm_driver = {
268 .driver_features = DRIVER_HAVE_IRQ | DRIVER_MODESET |
269 DRIVER_GEM | DRIVER_PRIME,
270 .load = exynos_drm_load,
271 .unload = exynos_drm_unload,
272 .open = exynos_drm_open,
273 .preclose = exynos_drm_preclose,
274 .lastclose = exynos_drm_lastclose,
275 .postclose = exynos_drm_postclose,
276 .get_vblank_counter = drm_vblank_count,
277 .enable_vblank = exynos_drm_crtc_enable_vblank,
278 .disable_vblank = exynos_drm_crtc_disable_vblank,
279 .gem_init_object = exynos_drm_gem_init_object,
280 .gem_free_object = exynos_drm_gem_free_object,
281 .gem_vm_ops = &exynos_drm_gem_vm_ops,
282 .dumb_create = exynos_drm_gem_dumb_create,
283 .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
284 .dumb_destroy = exynos_drm_gem_dumb_destroy,
285 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
286 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
287 .gem_prime_export = exynos_dmabuf_prime_export,
288 .gem_prime_import = exynos_dmabuf_prime_import,
289 .ioctls = exynos_ioctls,
290 .fops = &exynos_drm_driver_fops,
294 .major = DRIVER_MAJOR,
295 .minor = DRIVER_MINOR,
298 static int exynos_drm_platform_probe(struct platform_device *pdev)
300 DRM_DEBUG_DRIVER("%s\n", __FILE__);
302 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
303 exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
305 return drm_platform_init(&exynos_drm_driver, pdev);
308 static int exynos_drm_platform_remove(struct platform_device *pdev)
310 DRM_DEBUG_DRIVER("%s\n", __FILE__);
312 drm_platform_exit(&exynos_drm_driver, pdev);
317 static struct platform_driver exynos_drm_platform_driver = {
318 .probe = exynos_drm_platform_probe,
319 .remove = __devexit_p(exynos_drm_platform_remove),
321 .owner = THIS_MODULE,
322 .name = "exynos-drm",
326 static int __init exynos_drm_init(void)
330 DRM_DEBUG_DRIVER("%s\n", __FILE__);
332 #ifdef CONFIG_DRM_EXYNOS_FIMD
333 ret = platform_driver_register(&fimd_driver);
338 #ifdef CONFIG_DRM_EXYNOS_HDMI
339 ret = platform_driver_register(&hdmi_driver);
342 ret = platform_driver_register(&mixer_driver);
345 ret = platform_driver_register(&exynos_drm_common_hdmi_driver);
347 goto out_common_hdmi;
350 #ifdef CONFIG_DRM_EXYNOS_VIDI
351 ret = platform_driver_register(&vidi_driver);
356 #ifdef CONFIG_DRM_EXYNOS_G2D
357 ret = platform_driver_register(&g2d_driver);
362 ret = platform_driver_register(&exynos_drm_platform_driver);
366 exynos_drm_pdev = platform_device_register_simple("exynos-drm", -1,
368 if (IS_ERR_OR_NULL(exynos_drm_pdev)) {
369 ret = PTR_ERR(exynos_drm_pdev);
376 platform_driver_unregister(&exynos_drm_platform_driver);
379 #ifdef CONFIG_DRM_EXYNOS_G2D
380 platform_driver_unregister(&g2d_driver);
384 #ifdef CONFIG_DRM_EXYNOS_VIDI
386 platform_driver_unregister(&vidi_driver);
389 #ifdef CONFIG_DRM_EXYNOS_HDMI
390 platform_driver_unregister(&exynos_drm_common_hdmi_driver);
392 platform_driver_unregister(&mixer_driver);
394 platform_driver_unregister(&hdmi_driver);
398 #ifdef CONFIG_DRM_EXYNOS_FIMD
399 platform_driver_unregister(&fimd_driver);
405 static void __exit exynos_drm_exit(void)
407 DRM_DEBUG_DRIVER("%s\n", __FILE__);
409 platform_device_unregister(exynos_drm_pdev);
411 platform_driver_unregister(&exynos_drm_platform_driver);
413 #ifdef CONFIG_DRM_EXYNOS_G2D
414 platform_driver_unregister(&g2d_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 #ifdef CONFIG_DRM_EXYNOS_FIMD
428 platform_driver_unregister(&fimd_driver);
432 module_init(exynos_drm_init);
433 module_exit(exynos_drm_exit);
435 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
436 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
437 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
438 MODULE_DESCRIPTION("Samsung SoC DRM Driver");
439 MODULE_LICENSE("GPL");