exynos_drm_drv.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/pm_runtime.h>
  14. #include <drm/drmP.h>
  15. #include <drm/drm_crtc_helper.h>
  16. #include <linux/anon_inodes.h>
  17. #include <linux/component.h>
  18. #include <drm/exynos_drm.h>
  19. #include "exynos_drm_drv.h"
  20. #include "exynos_drm_crtc.h"
  21. #include "exynos_drm_encoder.h"
  22. #include "exynos_drm_fbdev.h"
  23. #include "exynos_drm_fb.h"
  24. #include "exynos_drm_gem.h"
  25. #include "exynos_drm_plane.h"
  26. #include "exynos_drm_vidi.h"
  27. #include "exynos_drm_dmabuf.h"
  28. #include "exynos_drm_g2d.h"
  29. #include "exynos_drm_ipp.h"
  30. #include "exynos_drm_iommu.h"
  31. #define DRIVER_NAME "exynos"
  32. #define DRIVER_DESC "Samsung SoC DRM"
  33. #define DRIVER_DATE "20110530"
  34. #define DRIVER_MAJOR 1
  35. #define DRIVER_MINOR 0
  36. #define VBLANK_OFF_DELAY 50000
  37. static struct platform_device *exynos_drm_pdev;
  38. static DEFINE_MUTEX(drm_component_lock);
  39. static LIST_HEAD(drm_component_list);
  40. struct component_dev {
  41. struct list_head list;
  42. struct device *crtc_dev;
  43. struct device *conn_dev;
  44. enum exynos_drm_output_type out_type;
  45. unsigned int dev_type_flag;
  46. };
  47. static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
  48. {
  49. struct exynos_drm_private *private;
  50. int ret;
  51. int nr;
  52. private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
  53. if (!private)
  54. return -ENOMEM;
  55. INIT_LIST_HEAD(&private->pageflip_event_list);
  56. dev_set_drvdata(dev->dev, dev);
  57. dev->dev_private = (void *)private;
  58. /*
  59. * create mapping to manage iommu table and set a pointer to iommu
  60. * mapping structure to iommu_mapping of private data.
  61. * also this iommu_mapping can be used to check if iommu is supported
  62. * or not.
  63. */
  64. ret = drm_create_iommu_mapping(dev);
  65. if (ret < 0) {
  66. DRM_ERROR("failed to create iommu mapping.\n");
  67. goto err_free_private;
  68. }
  69. drm_mode_config_init(dev);
  70. exynos_drm_mode_config_init(dev);
  71. for (nr = 0; nr < MAX_PLANE; nr++) {
  72. struct drm_plane *plane;
  73. unsigned long possible_crtcs = (1 << MAX_CRTC) - 1;
  74. plane = exynos_plane_init(dev, possible_crtcs, false);
  75. if (!plane)
  76. goto err_mode_config_cleanup;
  77. }
  78. /* init kms poll for handling hpd */
  79. drm_kms_helper_poll_init(dev);
  80. ret = drm_vblank_init(dev, MAX_CRTC);
  81. if (ret)
  82. goto err_mode_config_cleanup;
  83. /* setup possible_clones. */
  84. exynos_drm_encoder_setup(dev);
  85. drm_vblank_offdelay = VBLANK_OFF_DELAY;
  86. platform_set_drvdata(dev->platformdev, dev);
  87. /* Try to bind all sub drivers. */
  88. ret = component_bind_all(dev->dev, dev);
  89. if (ret)
  90. goto err_cleanup_vblank;
  91. /* Probe non kms sub drivers and virtual display driver. */
  92. ret = exynos_drm_device_subdrv_probe(dev);
  93. if (ret)
  94. goto err_unbind_all;
  95. /* force connectors detection */
  96. drm_helper_hpd_irq_event(dev);
  97. return 0;
  98. err_unbind_all:
  99. component_unbind_all(dev->dev, dev);
  100. err_cleanup_vblank:
  101. drm_vblank_cleanup(dev);
  102. err_mode_config_cleanup:
  103. drm_mode_config_cleanup(dev);
  104. drm_release_iommu_mapping(dev);
  105. err_free_private:
  106. kfree(private);
  107. return ret;
  108. }
  109. static int exynos_drm_unload(struct drm_device *dev)
  110. {
  111. exynos_drm_device_subdrv_remove(dev);
  112. exynos_drm_fbdev_fini(dev);
  113. drm_vblank_cleanup(dev);
  114. drm_kms_helper_poll_fini(dev);
  115. drm_mode_config_cleanup(dev);
  116. drm_release_iommu_mapping(dev);
  117. kfree(dev->dev_private);
  118. component_unbind_all(dev->dev, dev);
  119. dev->dev_private = NULL;
  120. return 0;
  121. }
  122. static const struct file_operations exynos_drm_gem_fops = {
  123. .mmap = exynos_drm_gem_mmap_buffer,
  124. };
  125. static int exynos_drm_suspend(struct drm_device *dev, pm_message_t state)
  126. {
  127. struct drm_connector *connector;
  128. drm_modeset_lock_all(dev);
  129. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  130. int old_dpms = connector->dpms;
  131. if (connector->funcs->dpms)
  132. connector->funcs->dpms(connector, DRM_MODE_DPMS_OFF);
  133. /* Set the old mode back to the connector for resume */
  134. connector->dpms = old_dpms;
  135. }
  136. drm_modeset_unlock_all(dev);
  137. return 0;
  138. }
  139. static int exynos_drm_resume(struct drm_device *dev)
  140. {
  141. struct drm_connector *connector;
  142. drm_modeset_lock_all(dev);
  143. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  144. if (connector->funcs->dpms)
  145. connector->funcs->dpms(connector, connector->dpms);
  146. }
  147. drm_modeset_unlock_all(dev);
  148. drm_helper_resume_force_mode(dev);
  149. return 0;
  150. }
  151. static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
  152. {
  153. struct drm_exynos_file_private *file_priv;
  154. struct file *anon_filp;
  155. int ret;
  156. file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
  157. if (!file_priv)
  158. return -ENOMEM;
  159. file->driver_priv = file_priv;
  160. ret = exynos_drm_subdrv_open(dev, file);
  161. if (ret)
  162. goto err_file_priv_free;
  163. anon_filp = anon_inode_getfile("exynos_gem", &exynos_drm_gem_fops,
  164. NULL, 0);
  165. if (IS_ERR(anon_filp)) {
  166. ret = PTR_ERR(anon_filp);
  167. goto err_subdrv_close;
  168. }
  169. anon_filp->f_mode = FMODE_READ | FMODE_WRITE;
  170. file_priv->anon_filp = anon_filp;
  171. return ret;
  172. err_subdrv_close:
  173. exynos_drm_subdrv_close(dev, file);
  174. err_file_priv_free:
  175. kfree(file_priv);
  176. file->driver_priv = NULL;
  177. return ret;
  178. }
  179. static void exynos_drm_preclose(struct drm_device *dev,
  180. struct drm_file *file)
  181. {
  182. exynos_drm_subdrv_close(dev, file);
  183. }
  184. static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
  185. {
  186. struct exynos_drm_private *private = dev->dev_private;
  187. struct drm_exynos_file_private *file_priv;
  188. struct drm_pending_vblank_event *v, *vt;
  189. struct drm_pending_event *e, *et;
  190. unsigned long flags;
  191. if (!file->driver_priv)
  192. return;
  193. /* Release all events not unhandled by page flip handler. */
  194. spin_lock_irqsave(&dev->event_lock, flags);
  195. list_for_each_entry_safe(v, vt, &private->pageflip_event_list,
  196. base.link) {
  197. if (v->base.file_priv == file) {
  198. list_del(&v->base.link);
  199. drm_vblank_put(dev, v->pipe);
  200. v->base.destroy(&v->base);
  201. }
  202. }
  203. /* Release all events handled by page flip handler but not freed. */
  204. list_for_each_entry_safe(e, et, &file->event_list, link) {
  205. list_del(&e->link);
  206. e->destroy(e);
  207. }
  208. spin_unlock_irqrestore(&dev->event_lock, flags);
  209. file_priv = file->driver_priv;
  210. if (file_priv->anon_filp)
  211. fput(file_priv->anon_filp);
  212. kfree(file->driver_priv);
  213. file->driver_priv = NULL;
  214. }
  215. static void exynos_drm_lastclose(struct drm_device *dev)
  216. {
  217. exynos_drm_fbdev_restore_mode(dev);
  218. }
  219. static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
  220. .fault = exynos_drm_gem_fault,
  221. .open = drm_gem_vm_open,
  222. .close = drm_gem_vm_close,
  223. };
  224. static const struct drm_ioctl_desc exynos_ioctls[] = {
  225. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
  226. DRM_UNLOCKED | DRM_AUTH),
  227. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
  228. exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
  229. DRM_AUTH),
  230. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
  231. exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
  232. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET,
  233. exynos_drm_gem_get_ioctl, DRM_UNLOCKED),
  234. DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION,
  235. vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH),
  236. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER,
  237. exynos_g2d_get_ver_ioctl, DRM_UNLOCKED | DRM_AUTH),
  238. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST,
  239. exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED | DRM_AUTH),
  240. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC,
  241. exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH),
  242. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY,
  243. exynos_drm_ipp_get_property, DRM_UNLOCKED | DRM_AUTH),
  244. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY,
  245. exynos_drm_ipp_set_property, DRM_UNLOCKED | DRM_AUTH),
  246. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF,
  247. exynos_drm_ipp_queue_buf, DRM_UNLOCKED | DRM_AUTH),
  248. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL,
  249. exynos_drm_ipp_cmd_ctrl, DRM_UNLOCKED | DRM_AUTH),
  250. };
  251. static const struct file_operations exynos_drm_driver_fops = {
  252. .owner = THIS_MODULE,
  253. .open = drm_open,
  254. .mmap = exynos_drm_gem_mmap,
  255. .poll = drm_poll,
  256. .read = drm_read,
  257. .unlocked_ioctl = drm_ioctl,
  258. #ifdef CONFIG_COMPAT
  259. .compat_ioctl = drm_compat_ioctl,
  260. #endif
  261. .release = drm_release,
  262. };
  263. static struct drm_driver exynos_drm_driver = {
  264. .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
  265. .load = exynos_drm_load,
  266. .unload = exynos_drm_unload,
  267. .suspend = exynos_drm_suspend,
  268. .resume = exynos_drm_resume,
  269. .open = exynos_drm_open,
  270. .preclose = exynos_drm_preclose,
  271. .lastclose = exynos_drm_lastclose,
  272. .postclose = exynos_drm_postclose,
  273. .get_vblank_counter = drm_vblank_count,
  274. .enable_vblank = exynos_drm_crtc_enable_vblank,
  275. .disable_vblank = exynos_drm_crtc_disable_vblank,
  276. .gem_free_object = exynos_drm_gem_free_object,
  277. .gem_vm_ops = &exynos_drm_gem_vm_ops,
  278. .dumb_create = exynos_drm_gem_dumb_create,
  279. .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
  280. .dumb_destroy = drm_gem_dumb_destroy,
  281. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  282. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  283. .gem_prime_export = exynos_dmabuf_prime_export,
  284. .gem_prime_import = exynos_dmabuf_prime_import,
  285. .ioctls = exynos_ioctls,
  286. .num_ioctls = ARRAY_SIZE(exynos_ioctls),
  287. .fops = &exynos_drm_driver_fops,
  288. .name = DRIVER_NAME,
  289. .desc = DRIVER_DESC,
  290. .date = DRIVER_DATE,
  291. .major = DRIVER_MAJOR,
  292. .minor = DRIVER_MINOR,
  293. };
  294. #ifdef CONFIG_PM_SLEEP
  295. static int exynos_drm_sys_suspend(struct device *dev)
  296. {
  297. struct drm_device *drm_dev = dev_get_drvdata(dev);
  298. pm_message_t message;
  299. if (pm_runtime_suspended(dev))
  300. return 0;
  301. message.event = PM_EVENT_SUSPEND;
  302. return exynos_drm_suspend(drm_dev, message);
  303. }
  304. static int exynos_drm_sys_resume(struct device *dev)
  305. {
  306. struct drm_device *drm_dev = dev_get_drvdata(dev);
  307. if (pm_runtime_suspended(dev))
  308. return 0;
  309. return exynos_drm_resume(drm_dev);
  310. }
  311. #endif
  312. static const struct dev_pm_ops exynos_drm_pm_ops = {
  313. SET_SYSTEM_SLEEP_PM_OPS(exynos_drm_sys_suspend, exynos_drm_sys_resume)
  314. };
  315. int exynos_drm_component_add(struct device *dev,
  316. enum exynos_drm_device_type dev_type,
  317. enum exynos_drm_output_type out_type)
  318. {
  319. struct component_dev *cdev;
  320. if (dev_type != EXYNOS_DEVICE_TYPE_CRTC &&
  321. dev_type != EXYNOS_DEVICE_TYPE_CONNECTOR) {
  322. DRM_ERROR("invalid device type.\n");
  323. return -EINVAL;
  324. }
  325. mutex_lock(&drm_component_lock);
  326. /*
  327. * Make sure to check if there is a component which has two device
  328. * objects, for connector and for encoder/connector.
  329. * It should make sure that crtc and encoder/connector drivers are
  330. * ready before exynos drm core binds them.
  331. */
  332. list_for_each_entry(cdev, &drm_component_list, list) {
  333. if (cdev->out_type == out_type) {
  334. /*
  335. * If crtc and encoder/connector device objects are
  336. * added already just return.
  337. */
  338. if (cdev->dev_type_flag == (EXYNOS_DEVICE_TYPE_CRTC |
  339. EXYNOS_DEVICE_TYPE_CONNECTOR)) {
  340. mutex_unlock(&drm_component_lock);
  341. return 0;
  342. }
  343. if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) {
  344. cdev->crtc_dev = dev;
  345. cdev->dev_type_flag |= dev_type;
  346. }
  347. if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR) {
  348. cdev->conn_dev = dev;
  349. cdev->dev_type_flag |= dev_type;
  350. }
  351. mutex_unlock(&drm_component_lock);
  352. return 0;
  353. }
  354. }
  355. mutex_unlock(&drm_component_lock);
  356. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  357. if (!cdev)
  358. return -ENOMEM;
  359. if (dev_type == EXYNOS_DEVICE_TYPE_CRTC)
  360. cdev->crtc_dev = dev;
  361. if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR)
  362. cdev->conn_dev = dev;
  363. cdev->out_type = out_type;
  364. cdev->dev_type_flag = dev_type;
  365. mutex_lock(&drm_component_lock);
  366. list_add_tail(&cdev->list, &drm_component_list);
  367. mutex_unlock(&drm_component_lock);
  368. return 0;
  369. }
  370. void exynos_drm_component_del(struct device *dev,
  371. enum exynos_drm_device_type dev_type)
  372. {
  373. struct component_dev *cdev, *next;
  374. mutex_lock(&drm_component_lock);
  375. list_for_each_entry_safe(cdev, next, &drm_component_list, list) {
  376. if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) {
  377. if (cdev->crtc_dev == dev) {
  378. cdev->crtc_dev = NULL;
  379. cdev->dev_type_flag &= ~dev_type;
  380. }
  381. }
  382. if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR) {
  383. if (cdev->conn_dev == dev) {
  384. cdev->conn_dev = NULL;
  385. cdev->dev_type_flag &= ~dev_type;
  386. }
  387. }
  388. /*
  389. * Release cdev object only in case that both of crtc and
  390. * encoder/connector device objects are NULL.
  391. */
  392. if (!cdev->crtc_dev && !cdev->conn_dev) {
  393. list_del(&cdev->list);
  394. kfree(cdev);
  395. }
  396. break;
  397. }
  398. mutex_unlock(&drm_component_lock);
  399. }
  400. static int compare_of(struct device *dev, void *data)
  401. {
  402. return dev == (struct device *)data;
  403. }
  404. static int exynos_drm_add_components(struct device *dev, struct master *m)
  405. {
  406. struct component_dev *cdev;
  407. unsigned int attach_cnt = 0;
  408. mutex_lock(&drm_component_lock);
  409. list_for_each_entry(cdev, &drm_component_list, list) {
  410. int ret;
  411. /*
  412. * Add components to master only in case that crtc and
  413. * encoder/connector device objects exist.
  414. */
  415. if (!cdev->crtc_dev || !cdev->conn_dev)
  416. continue;
  417. attach_cnt++;
  418. mutex_unlock(&drm_component_lock);
  419. /*
  420. * fimd and dpi modules have same device object so add
  421. * only crtc device object in this case.
  422. *
  423. * TODO. if dpi module follows driver-model driver then
  424. * below codes can be removed.
  425. */
  426. if (cdev->crtc_dev == cdev->conn_dev) {
  427. ret = component_master_add_child(m, compare_of,
  428. cdev->crtc_dev);
  429. if (ret < 0)
  430. return ret;
  431. goto out_lock;
  432. }
  433. /*
  434. * Do not chage below call order.
  435. * crtc device first should be added to master because
  436. * connector/encoder need pipe number of crtc when they
  437. * are created.
  438. */
  439. ret = component_master_add_child(m, compare_of, cdev->crtc_dev);
  440. ret |= component_master_add_child(m, compare_of,
  441. cdev->conn_dev);
  442. if (ret < 0)
  443. return ret;
  444. out_lock:
  445. mutex_lock(&drm_component_lock);
  446. }
  447. mutex_unlock(&drm_component_lock);
  448. return attach_cnt ? 0 : -ENODEV;
  449. }
  450. static int exynos_drm_bind(struct device *dev)
  451. {
  452. return drm_platform_init(&exynos_drm_driver, to_platform_device(dev));
  453. }
  454. static void exynos_drm_unbind(struct device *dev)
  455. {
  456. drm_put_dev(dev_get_drvdata(dev));
  457. }
  458. static const struct component_master_ops exynos_drm_ops = {
  459. .add_components = exynos_drm_add_components,
  460. .bind = exynos_drm_bind,
  461. .unbind = exynos_drm_unbind,
  462. };
  463. static int exynos_drm_platform_probe(struct platform_device *pdev)
  464. {
  465. int ret;
  466. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  467. exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls);
  468. #ifdef CONFIG_DRM_EXYNOS_FIMD
  469. ret = platform_driver_register(&fimd_driver);
  470. if (ret < 0)
  471. return ret;
  472. #endif
  473. #ifdef CONFIG_DRM_EXYNOS_DP
  474. ret = platform_driver_register(&dp_driver);
  475. if (ret < 0)
  476. goto err_unregister_fimd_drv;
  477. #endif
  478. #ifdef CONFIG_DRM_EXYNOS_DSI
  479. ret = platform_driver_register(&dsi_driver);
  480. if (ret < 0)
  481. goto err_unregister_dp_drv;
  482. #endif
  483. #ifdef CONFIG_DRM_EXYNOS_HDMI
  484. ret = platform_driver_register(&mixer_driver);
  485. if (ret < 0)
  486. goto err_unregister_dsi_drv;
  487. ret = platform_driver_register(&hdmi_driver);
  488. if (ret < 0)
  489. goto err_unregister_mixer_drv;
  490. #endif
  491. #ifdef CONFIG_DRM_EXYNOS_G2D
  492. ret = platform_driver_register(&g2d_driver);
  493. if (ret < 0)
  494. goto err_unregister_hdmi_drv;
  495. #endif
  496. #ifdef CONFIG_DRM_EXYNOS_FIMC
  497. ret = platform_driver_register(&fimc_driver);
  498. if (ret < 0)
  499. goto err_unregister_g2d_drv;
  500. #endif
  501. #ifdef CONFIG_DRM_EXYNOS_ROTATOR
  502. ret = platform_driver_register(&rotator_driver);
  503. if (ret < 0)
  504. goto err_unregister_fimc_drv;
  505. #endif
  506. #ifdef CONFIG_DRM_EXYNOS_GSC
  507. ret = platform_driver_register(&gsc_driver);
  508. if (ret < 0)
  509. goto err_unregister_rotator_drv;
  510. #endif
  511. #ifdef CONFIG_DRM_EXYNOS_IPP
  512. ret = platform_driver_register(&ipp_driver);
  513. if (ret < 0)
  514. goto err_unregister_gsc_drv;
  515. ret = exynos_platform_device_ipp_register();
  516. if (ret < 0)
  517. goto err_unregister_ipp_drv;
  518. #endif
  519. ret = component_master_add(&pdev->dev, &exynos_drm_ops);
  520. if (ret < 0)
  521. DRM_DEBUG_KMS("re-tried by last sub driver probed later.\n");
  522. return 0;
  523. #ifdef CONFIG_DRM_EXYNOS_IPP
  524. err_unregister_ipp_drv:
  525. platform_driver_unregister(&ipp_driver);
  526. err_unregister_gsc_drv:
  527. #endif
  528. #ifdef CONFIG_DRM_EXYNOS_GSC
  529. platform_driver_unregister(&gsc_driver);
  530. err_unregister_rotator_drv:
  531. #endif
  532. #ifdef CONFIG_DRM_EXYNOS_ROTATOR
  533. platform_driver_unregister(&rotator_driver);
  534. err_unregister_fimc_drv:
  535. #endif
  536. #ifdef CONFIG_DRM_EXYNOS_FIMC
  537. platform_driver_unregister(&fimc_driver);
  538. err_unregister_g2d_drv:
  539. #endif
  540. #ifdef CONFIG_DRM_EXYNOS_G2D
  541. platform_driver_unregister(&g2d_driver);
  542. err_unregister_hdmi_drv:
  543. #endif
  544. #ifdef CONFIG_DRM_EXYNOS_HDMI
  545. platform_driver_unregister(&hdmi_driver);
  546. err_unregister_mixer_drv:
  547. platform_driver_unregister(&mixer_driver);
  548. err_unregister_dsi_drv:
  549. #endif
  550. #ifdef CONFIG_DRM_EXYNOS_DSI
  551. platform_driver_unregister(&dsi_driver);
  552. err_unregister_dp_drv:
  553. #endif
  554. #ifdef CONFIG_DRM_EXYNOS_DP
  555. platform_driver_unregister(&dp_driver);
  556. err_unregister_fimd_drv:
  557. #endif
  558. #ifdef CONFIG_DRM_EXYNOS_FIMD
  559. platform_driver_unregister(&fimd_driver);
  560. #endif
  561. return ret;
  562. }
  563. static int exynos_drm_platform_remove(struct platform_device *pdev)
  564. {
  565. #ifdef CONFIG_DRM_EXYNOS_IPP
  566. exynos_platform_device_ipp_unregister();
  567. platform_driver_unregister(&ipp_driver);
  568. #endif
  569. #ifdef CONFIG_DRM_EXYNOS_GSC
  570. platform_driver_unregister(&gsc_driver);
  571. #endif
  572. #ifdef CONFIG_DRM_EXYNOS_ROTATOR
  573. platform_driver_unregister(&rotator_driver);
  574. #endif
  575. #ifdef CONFIG_DRM_EXYNOS_FIMC
  576. platform_driver_unregister(&fimc_driver);
  577. #endif
  578. #ifdef CONFIG_DRM_EXYNOS_G2D
  579. platform_driver_unregister(&g2d_driver);
  580. #endif
  581. #ifdef CONFIG_DRM_EXYNOS_HDMI
  582. platform_driver_unregister(&mixer_driver);
  583. platform_driver_unregister(&hdmi_driver);
  584. #endif
  585. #ifdef CONFIG_DRM_EXYNOS_FIMD
  586. platform_driver_unregister(&fimd_driver);
  587. #endif
  588. #ifdef CONFIG_DRM_EXYNOS_DSI
  589. platform_driver_unregister(&dsi_driver);
  590. #endif
  591. #ifdef CONFIG_DRM_EXYNOS_DP
  592. platform_driver_unregister(&dp_driver);
  593. #endif
  594. component_master_del(&pdev->dev, &exynos_drm_ops);
  595. return 0;
  596. }
  597. static struct platform_driver exynos_drm_platform_driver = {
  598. .probe = exynos_drm_platform_probe,
  599. .remove = exynos_drm_platform_remove,
  600. .driver = {
  601. .owner = THIS_MODULE,
  602. .name = "exynos-drm",
  603. .pm = &exynos_drm_pm_ops,
  604. },
  605. };
  606. static int exynos_drm_init(void)
  607. {
  608. int ret;
  609. exynos_drm_pdev = platform_device_register_simple("exynos-drm", -1,
  610. NULL, 0);
  611. if (IS_ERR(exynos_drm_pdev))
  612. return PTR_ERR(exynos_drm_pdev);
  613. #ifdef CONFIG_DRM_EXYNOS_VIDI
  614. ret = exynos_drm_probe_vidi();
  615. if (ret < 0)
  616. goto err_unregister_pd;
  617. #endif
  618. ret = platform_driver_register(&exynos_drm_platform_driver);
  619. if (ret)
  620. goto err_remove_vidi;
  621. return 0;
  622. err_remove_vidi:
  623. #ifdef CONFIG_DRM_EXYNOS_VIDI
  624. exynos_drm_remove_vidi();
  625. err_unregister_pd:
  626. #endif
  627. platform_device_unregister(exynos_drm_pdev);
  628. return ret;
  629. }
  630. static void exynos_drm_exit(void)
  631. {
  632. platform_driver_unregister(&exynos_drm_platform_driver);
  633. #ifdef CONFIG_DRM_EXYNOS_VIDI
  634. exynos_drm_remove_vidi();
  635. #endif
  636. platform_device_unregister(exynos_drm_pdev);
  637. }
  638. module_init(exynos_drm_init);
  639. module_exit(exynos_drm_exit);
  640. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  641. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  642. MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
  643. MODULE_DESCRIPTION("Samsung SoC DRM Driver");
  644. MODULE_LICENSE("GPL");