exynos_drm_drv.c 9.5 KB

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