exynos_drm_drv.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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_crtc_helper.h"
  30. #include <drm/exynos_drm.h>
  31. #include "exynos_drm_drv.h"
  32. #include "exynos_drm_crtc.h"
  33. #include "exynos_drm_encoder.h"
  34. #include "exynos_drm_fbdev.h"
  35. #include "exynos_drm_fb.h"
  36. #include "exynos_drm_gem.h"
  37. #include "exynos_drm_plane.h"
  38. #define DRIVER_NAME "exynos"
  39. #define DRIVER_DESC "Samsung SoC DRM"
  40. #define DRIVER_DATE "20110530"
  41. #define DRIVER_MAJOR 1
  42. #define DRIVER_MINOR 0
  43. #define VBLANK_OFF_DELAY 50000
  44. static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
  45. {
  46. struct exynos_drm_private *private;
  47. int ret;
  48. int nr;
  49. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  50. private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
  51. if (!private) {
  52. DRM_ERROR("failed to allocate private\n");
  53. return -ENOMEM;
  54. }
  55. INIT_LIST_HEAD(&private->pageflip_event_list);
  56. dev->dev_private = (void *)private;
  57. drm_mode_config_init(dev);
  58. /* init kms poll for handling hpd */
  59. drm_kms_helper_poll_init(dev);
  60. exynos_drm_mode_config_init(dev);
  61. /*
  62. * EXYNOS4 is enough to have two CRTCs and each crtc would be used
  63. * without dependency of hardware.
  64. */
  65. for (nr = 0; nr < MAX_CRTC; nr++) {
  66. ret = exynos_drm_crtc_create(dev, nr);
  67. if (ret)
  68. goto err_crtc;
  69. }
  70. for (nr = 0; nr < MAX_PLANE; nr++) {
  71. ret = exynos_plane_init(dev, nr);
  72. if (ret)
  73. goto err_crtc;
  74. }
  75. ret = drm_vblank_init(dev, MAX_CRTC);
  76. if (ret)
  77. goto err_crtc;
  78. /*
  79. * probe sub drivers such as display controller and hdmi driver,
  80. * that were registered at probe() of platform driver
  81. * to the sub driver and create encoder and connector for them.
  82. */
  83. ret = exynos_drm_device_register(dev);
  84. if (ret)
  85. goto err_vblank;
  86. /* setup possible_clones. */
  87. exynos_drm_encoder_setup(dev);
  88. /*
  89. * create and configure fb helper and also exynos specific
  90. * fbdev object.
  91. */
  92. ret = exynos_drm_fbdev_init(dev);
  93. if (ret) {
  94. DRM_ERROR("failed to initialize drm fbdev\n");
  95. goto err_drm_device;
  96. }
  97. drm_vblank_offdelay = VBLANK_OFF_DELAY;
  98. return 0;
  99. err_drm_device:
  100. exynos_drm_device_unregister(dev);
  101. err_vblank:
  102. drm_vblank_cleanup(dev);
  103. err_crtc:
  104. drm_mode_config_cleanup(dev);
  105. kfree(private);
  106. return ret;
  107. }
  108. static int exynos_drm_unload(struct drm_device *dev)
  109. {
  110. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  111. exynos_drm_fbdev_fini(dev);
  112. exynos_drm_device_unregister(dev);
  113. drm_vblank_cleanup(dev);
  114. drm_kms_helper_poll_fini(dev);
  115. drm_mode_config_cleanup(dev);
  116. kfree(dev->dev_private);
  117. dev->dev_private = NULL;
  118. return 0;
  119. }
  120. static void exynos_drm_preclose(struct drm_device *dev,
  121. struct drm_file *file)
  122. {
  123. struct exynos_drm_private *private = dev->dev_private;
  124. struct drm_pending_vblank_event *e, *t;
  125. unsigned long flags;
  126. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  127. /* release events of current file */
  128. spin_lock_irqsave(&dev->event_lock, flags);
  129. list_for_each_entry_safe(e, t, &private->pageflip_event_list,
  130. base.link) {
  131. if (e->base.file_priv == file) {
  132. list_del(&e->base.link);
  133. e->base.destroy(&e->base);
  134. }
  135. }
  136. spin_unlock_irqrestore(&dev->event_lock, flags);
  137. }
  138. static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
  139. {
  140. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  141. if (!file->driver_priv)
  142. return;
  143. kfree(file->driver_priv);
  144. file->driver_priv = NULL;
  145. }
  146. static void exynos_drm_lastclose(struct drm_device *dev)
  147. {
  148. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  149. exynos_drm_fbdev_restore_mode(dev);
  150. }
  151. static struct vm_operations_struct exynos_drm_gem_vm_ops = {
  152. .fault = exynos_drm_gem_fault,
  153. .open = drm_gem_vm_open,
  154. .close = drm_gem_vm_close,
  155. };
  156. static struct drm_ioctl_desc exynos_ioctls[] = {
  157. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
  158. DRM_UNLOCKED | DRM_AUTH),
  159. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
  160. exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
  161. DRM_AUTH),
  162. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
  163. exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
  164. DRM_IOCTL_DEF_DRV(EXYNOS_PLANE_SET_ZPOS, exynos_plane_set_zpos_ioctl,
  165. DRM_UNLOCKED | DRM_AUTH),
  166. };
  167. static const struct file_operations exynos_drm_driver_fops = {
  168. .owner = THIS_MODULE,
  169. .open = drm_open,
  170. .mmap = exynos_drm_gem_mmap,
  171. .poll = drm_poll,
  172. .read = drm_read,
  173. .unlocked_ioctl = drm_ioctl,
  174. .release = drm_release,
  175. };
  176. static struct drm_driver exynos_drm_driver = {
  177. .driver_features = DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
  178. DRIVER_MODESET | DRIVER_GEM,
  179. .load = exynos_drm_load,
  180. .unload = exynos_drm_unload,
  181. .preclose = exynos_drm_preclose,
  182. .lastclose = exynos_drm_lastclose,
  183. .postclose = exynos_drm_postclose,
  184. .get_vblank_counter = drm_vblank_count,
  185. .enable_vblank = exynos_drm_crtc_enable_vblank,
  186. .disable_vblank = exynos_drm_crtc_disable_vblank,
  187. .gem_init_object = exynos_drm_gem_init_object,
  188. .gem_free_object = exynos_drm_gem_free_object,
  189. .gem_vm_ops = &exynos_drm_gem_vm_ops,
  190. .dumb_create = exynos_drm_gem_dumb_create,
  191. .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
  192. .dumb_destroy = exynos_drm_gem_dumb_destroy,
  193. .ioctls = exynos_ioctls,
  194. .fops = &exynos_drm_driver_fops,
  195. .name = DRIVER_NAME,
  196. .desc = DRIVER_DESC,
  197. .date = DRIVER_DATE,
  198. .major = DRIVER_MAJOR,
  199. .minor = DRIVER_MINOR,
  200. };
  201. static int exynos_drm_platform_probe(struct platform_device *pdev)
  202. {
  203. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  204. exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
  205. return drm_platform_init(&exynos_drm_driver, pdev);
  206. }
  207. static int exynos_drm_platform_remove(struct platform_device *pdev)
  208. {
  209. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  210. drm_platform_exit(&exynos_drm_driver, pdev);
  211. return 0;
  212. }
  213. static struct platform_driver exynos_drm_platform_driver = {
  214. .probe = exynos_drm_platform_probe,
  215. .remove = __devexit_p(exynos_drm_platform_remove),
  216. .driver = {
  217. .owner = THIS_MODULE,
  218. .name = DRIVER_NAME,
  219. },
  220. };
  221. static int __init exynos_drm_init(void)
  222. {
  223. int ret;
  224. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  225. #ifdef CONFIG_DRM_EXYNOS_FIMD
  226. ret = platform_driver_register(&fimd_driver);
  227. if (ret < 0)
  228. goto out_fimd;
  229. #endif
  230. #ifdef CONFIG_DRM_EXYNOS_HDMI
  231. ret = platform_driver_register(&hdmi_driver);
  232. if (ret < 0)
  233. goto out_hdmi;
  234. ret = platform_driver_register(&mixer_driver);
  235. if (ret < 0)
  236. goto out_mixer;
  237. ret = platform_driver_register(&exynos_drm_common_hdmi_driver);
  238. if (ret < 0)
  239. goto out_common_hdmi;
  240. #endif
  241. ret = platform_driver_register(&exynos_drm_platform_driver);
  242. if (ret < 0)
  243. goto out;
  244. return 0;
  245. out:
  246. #ifdef CONFIG_DRM_EXYNOS_HDMI
  247. platform_driver_unregister(&exynos_drm_common_hdmi_driver);
  248. out_common_hdmi:
  249. platform_driver_unregister(&mixer_driver);
  250. out_mixer:
  251. platform_driver_unregister(&hdmi_driver);
  252. out_hdmi:
  253. #endif
  254. #ifdef CONFIG_DRM_EXYNOS_FIMD
  255. platform_driver_unregister(&fimd_driver);
  256. out_fimd:
  257. #endif
  258. return ret;
  259. }
  260. static void __exit exynos_drm_exit(void)
  261. {
  262. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  263. platform_driver_unregister(&exynos_drm_platform_driver);
  264. #ifdef CONFIG_DRM_EXYNOS_HDMI
  265. platform_driver_unregister(&exynos_drm_common_hdmi_driver);
  266. platform_driver_unregister(&mixer_driver);
  267. platform_driver_unregister(&hdmi_driver);
  268. #endif
  269. #ifdef CONFIG_DRM_EXYNOS_FIMD
  270. platform_driver_unregister(&fimd_driver);
  271. #endif
  272. }
  273. module_init(exynos_drm_init);
  274. module_exit(exynos_drm_exit);
  275. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  276. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  277. MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
  278. MODULE_DESCRIPTION("Samsung SoC DRM Driver");
  279. MODULE_LICENSE("GPL");