exynos_drm_drv.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  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. #include "drmP.h"
  28. #include "drm.h"
  29. #include <drm/exynos_drm.h>
  30. #include "exynos_drm_drv.h"
  31. #include "exynos_drm_crtc.h"
  32. #include "exynos_drm_fbdev.h"
  33. #include "exynos_drm_fb.h"
  34. #include "exynos_drm_gem.h"
  35. #define DRIVER_NAME "exynos-drm"
  36. #define DRIVER_DESC "Samsung SoC DRM"
  37. #define DRIVER_DATE "20110530"
  38. #define DRIVER_MAJOR 1
  39. #define DRIVER_MINOR 0
  40. static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
  41. {
  42. struct exynos_drm_private *private;
  43. int ret;
  44. int nr;
  45. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  46. private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
  47. if (!private) {
  48. DRM_ERROR("failed to allocate private\n");
  49. return -ENOMEM;
  50. }
  51. INIT_LIST_HEAD(&private->pageflip_event_list);
  52. dev->dev_private = (void *)private;
  53. drm_mode_config_init(dev);
  54. exynos_drm_mode_config_init(dev);
  55. /*
  56. * EXYNOS4 is enough to have two CRTCs and each crtc would be used
  57. * without dependency of hardware.
  58. */
  59. for (nr = 0; nr < MAX_CRTC; nr++) {
  60. ret = exynos_drm_crtc_create(dev, nr);
  61. if (ret)
  62. goto err_crtc;
  63. }
  64. ret = drm_vblank_init(dev, MAX_CRTC);
  65. if (ret)
  66. goto err_crtc;
  67. /*
  68. * probe sub drivers such as display controller and hdmi driver,
  69. * that were registered at probe() of platform driver
  70. * to the sub driver and create encoder and connector for them.
  71. */
  72. ret = exynos_drm_device_register(dev);
  73. if (ret)
  74. goto err_vblank;
  75. /*
  76. * create and configure fb helper and also exynos specific
  77. * fbdev object.
  78. */
  79. ret = exynos_drm_fbdev_init(dev);
  80. if (ret) {
  81. DRM_ERROR("failed to initialize drm fbdev\n");
  82. goto err_drm_device;
  83. }
  84. return 0;
  85. err_drm_device:
  86. exynos_drm_device_unregister(dev);
  87. err_vblank:
  88. drm_vblank_cleanup(dev);
  89. err_crtc:
  90. drm_mode_config_cleanup(dev);
  91. kfree(private);
  92. return ret;
  93. }
  94. static int exynos_drm_unload(struct drm_device *dev)
  95. {
  96. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  97. exynos_drm_fbdev_fini(dev);
  98. exynos_drm_device_unregister(dev);
  99. drm_vblank_cleanup(dev);
  100. drm_mode_config_cleanup(dev);
  101. kfree(dev->dev_private);
  102. dev->dev_private = NULL;
  103. return 0;
  104. }
  105. static void exynos_drm_preclose(struct drm_device *dev,
  106. struct drm_file *file_priv)
  107. {
  108. struct exynos_drm_private *dev_priv = dev->dev_private;
  109. /*
  110. * drm framework frees all events at release time,
  111. * so private event list should be cleared.
  112. */
  113. if (!list_empty(&dev_priv->pageflip_event_list))
  114. INIT_LIST_HEAD(&dev_priv->pageflip_event_list);
  115. }
  116. static void exynos_drm_lastclose(struct drm_device *dev)
  117. {
  118. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  119. exynos_drm_fbdev_restore_mode(dev);
  120. }
  121. static struct vm_operations_struct exynos_drm_gem_vm_ops = {
  122. .fault = exynos_drm_gem_fault,
  123. .open = drm_gem_vm_open,
  124. .close = drm_gem_vm_close,
  125. };
  126. static struct drm_ioctl_desc exynos_ioctls[] = {
  127. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
  128. DRM_UNLOCKED | DRM_AUTH),
  129. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
  130. exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
  131. DRM_AUTH),
  132. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
  133. exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
  134. };
  135. static struct drm_driver exynos_drm_driver = {
  136. .driver_features = DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
  137. DRIVER_MODESET | DRIVER_GEM,
  138. .load = exynos_drm_load,
  139. .unload = exynos_drm_unload,
  140. .preclose = exynos_drm_preclose,
  141. .lastclose = exynos_drm_lastclose,
  142. .get_vblank_counter = drm_vblank_count,
  143. .enable_vblank = exynos_drm_crtc_enable_vblank,
  144. .disable_vblank = exynos_drm_crtc_disable_vblank,
  145. .gem_init_object = exynos_drm_gem_init_object,
  146. .gem_free_object = exynos_drm_gem_free_object,
  147. .gem_vm_ops = &exynos_drm_gem_vm_ops,
  148. .dumb_create = exynos_drm_gem_dumb_create,
  149. .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
  150. .dumb_destroy = exynos_drm_gem_dumb_destroy,
  151. .ioctls = exynos_ioctls,
  152. .fops = {
  153. .owner = THIS_MODULE,
  154. .open = drm_open,
  155. .mmap = exynos_drm_gem_mmap,
  156. .poll = drm_poll,
  157. .read = drm_read,
  158. .unlocked_ioctl = drm_ioctl,
  159. .release = drm_release,
  160. },
  161. .name = DRIVER_NAME,
  162. .desc = DRIVER_DESC,
  163. .date = DRIVER_DATE,
  164. .major = DRIVER_MAJOR,
  165. .minor = DRIVER_MINOR,
  166. };
  167. static int exynos_drm_platform_probe(struct platform_device *pdev)
  168. {
  169. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  170. exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
  171. return drm_platform_init(&exynos_drm_driver, pdev);
  172. }
  173. static int exynos_drm_platform_remove(struct platform_device *pdev)
  174. {
  175. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  176. drm_platform_exit(&exynos_drm_driver, pdev);
  177. return 0;
  178. }
  179. static struct platform_driver exynos_drm_platform_driver = {
  180. .probe = exynos_drm_platform_probe,
  181. .remove = __devexit_p(exynos_drm_platform_remove),
  182. .driver = {
  183. .owner = THIS_MODULE,
  184. .name = DRIVER_NAME,
  185. },
  186. };
  187. static int __init exynos_drm_init(void)
  188. {
  189. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  190. return platform_driver_register(&exynos_drm_platform_driver);
  191. }
  192. static void __exit exynos_drm_exit(void)
  193. {
  194. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  195. platform_driver_unregister(&exynos_drm_platform_driver);
  196. }
  197. module_init(exynos_drm_init);
  198. module_exit(exynos_drm_exit);
  199. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  200. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  201. MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
  202. MODULE_DESCRIPTION("Samsung SoC DRM Driver");
  203. MODULE_LICENSE("GPL");