exynos_drm_drv.c 18 KB

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