exynos_drm_drv.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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_atomic.h>
  16. #include <drm/drm_atomic_helper.h>
  17. #include <drm/drm_crtc_helper.h>
  18. #include <linux/component.h>
  19. #include <drm/exynos_drm.h>
  20. #include "exynos_drm_drv.h"
  21. #include "exynos_drm_crtc.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_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. struct exynos_atomic_commit {
  36. struct work_struct work;
  37. struct drm_device *dev;
  38. struct drm_atomic_state *state;
  39. u32 crtcs;
  40. };
  41. static void exynos_atomic_wait_for_commit(struct drm_atomic_state *state)
  42. {
  43. struct drm_crtc_state *crtc_state;
  44. struct drm_crtc *crtc;
  45. int i, ret;
  46. for_each_crtc_in_state(state, crtc, crtc_state, i) {
  47. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  48. if (!crtc->state->enable)
  49. continue;
  50. ret = drm_crtc_vblank_get(crtc);
  51. if (ret)
  52. continue;
  53. exynos_drm_crtc_wait_pending_update(exynos_crtc);
  54. drm_crtc_vblank_put(crtc);
  55. }
  56. }
  57. static void exynos_atomic_commit_complete(struct exynos_atomic_commit *commit)
  58. {
  59. struct drm_device *dev = commit->dev;
  60. struct exynos_drm_private *priv = dev->dev_private;
  61. struct drm_atomic_state *state = commit->state;
  62. struct drm_plane *plane;
  63. struct drm_crtc *crtc;
  64. struct drm_plane_state *plane_state;
  65. struct drm_crtc_state *crtc_state;
  66. int i;
  67. drm_atomic_helper_commit_modeset_disables(dev, state);
  68. drm_atomic_helper_commit_modeset_enables(dev, state);
  69. /*
  70. * Exynos can't update planes with CRTCs and encoders disabled,
  71. * its updates routines, specially for FIMD, requires the clocks
  72. * to be enabled. So it is necessary to handle the modeset operations
  73. * *before* the commit_planes() step, this way it will always
  74. * have the relevant clocks enabled to perform the update.
  75. */
  76. for_each_crtc_in_state(state, crtc, crtc_state, i) {
  77. struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
  78. atomic_set(&exynos_crtc->pending_update, 0);
  79. }
  80. for_each_plane_in_state(state, plane, plane_state, i) {
  81. struct exynos_drm_crtc *exynos_crtc =
  82. to_exynos_crtc(plane->crtc);
  83. if (!plane->crtc)
  84. continue;
  85. atomic_inc(&exynos_crtc->pending_update);
  86. }
  87. drm_atomic_helper_commit_planes(dev, state, false);
  88. exynos_atomic_wait_for_commit(state);
  89. drm_atomic_helper_cleanup_planes(dev, state);
  90. drm_atomic_state_free(state);
  91. spin_lock(&priv->lock);
  92. priv->pending &= ~commit->crtcs;
  93. spin_unlock(&priv->lock);
  94. wake_up_all(&priv->wait);
  95. kfree(commit);
  96. }
  97. static void exynos_drm_atomic_work(struct work_struct *work)
  98. {
  99. struct exynos_atomic_commit *commit = container_of(work,
  100. struct exynos_atomic_commit, work);
  101. exynos_atomic_commit_complete(commit);
  102. }
  103. static struct device *exynos_drm_get_dma_device(void);
  104. static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
  105. {
  106. struct exynos_drm_private *private;
  107. struct drm_encoder *encoder;
  108. unsigned int clone_mask;
  109. int cnt, ret;
  110. private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
  111. if (!private)
  112. return -ENOMEM;
  113. init_waitqueue_head(&private->wait);
  114. spin_lock_init(&private->lock);
  115. dev_set_drvdata(dev->dev, dev);
  116. dev->dev_private = (void *)private;
  117. /* the first real CRTC device is used for all dma mapping operations */
  118. private->dma_dev = exynos_drm_get_dma_device();
  119. if (!private->dma_dev) {
  120. DRM_ERROR("no device found for DMA mapping operations.\n");
  121. ret = -ENODEV;
  122. goto err_free_private;
  123. }
  124. DRM_INFO("Exynos DRM: using %s device for DMA mapping operations\n",
  125. dev_name(private->dma_dev));
  126. /* create common IOMMU mapping for all devices attached to Exynos DRM */
  127. ret = drm_create_iommu_mapping(dev);
  128. if (ret < 0) {
  129. DRM_ERROR("failed to create iommu mapping.\n");
  130. goto err_free_private;
  131. }
  132. drm_mode_config_init(dev);
  133. exynos_drm_mode_config_init(dev);
  134. /* setup possible_clones. */
  135. cnt = 0;
  136. clone_mask = 0;
  137. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  138. clone_mask |= (1 << (cnt++));
  139. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  140. encoder->possible_clones = clone_mask;
  141. platform_set_drvdata(dev->platformdev, dev);
  142. /* Try to bind all sub drivers. */
  143. ret = component_bind_all(dev->dev, dev);
  144. if (ret)
  145. goto err_mode_config_cleanup;
  146. ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
  147. if (ret)
  148. goto err_unbind_all;
  149. /* Probe non kms sub drivers and virtual display driver. */
  150. ret = exynos_drm_device_subdrv_probe(dev);
  151. if (ret)
  152. goto err_cleanup_vblank;
  153. drm_mode_config_reset(dev);
  154. /*
  155. * enable drm irq mode.
  156. * - with irq_enabled = true, we can use the vblank feature.
  157. *
  158. * P.S. note that we wouldn't use drm irq handler but
  159. * just specific driver own one instead because
  160. * drm framework supports only one irq handler.
  161. */
  162. dev->irq_enabled = true;
  163. /* init kms poll for handling hpd */
  164. drm_kms_helper_poll_init(dev);
  165. /* force connectors detection */
  166. drm_helper_hpd_irq_event(dev);
  167. return 0;
  168. err_cleanup_vblank:
  169. drm_vblank_cleanup(dev);
  170. err_unbind_all:
  171. component_unbind_all(dev->dev, dev);
  172. err_mode_config_cleanup:
  173. drm_mode_config_cleanup(dev);
  174. drm_release_iommu_mapping(dev);
  175. err_free_private:
  176. kfree(private);
  177. return ret;
  178. }
  179. static int exynos_drm_unload(struct drm_device *dev)
  180. {
  181. exynos_drm_device_subdrv_remove(dev);
  182. exynos_drm_fbdev_fini(dev);
  183. drm_kms_helper_poll_fini(dev);
  184. drm_vblank_cleanup(dev);
  185. component_unbind_all(dev->dev, dev);
  186. drm_mode_config_cleanup(dev);
  187. drm_release_iommu_mapping(dev);
  188. kfree(dev->dev_private);
  189. dev->dev_private = NULL;
  190. return 0;
  191. }
  192. static int commit_is_pending(struct exynos_drm_private *priv, u32 crtcs)
  193. {
  194. bool pending;
  195. spin_lock(&priv->lock);
  196. pending = priv->pending & crtcs;
  197. spin_unlock(&priv->lock);
  198. return pending;
  199. }
  200. int exynos_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state,
  201. bool nonblock)
  202. {
  203. struct exynos_drm_private *priv = dev->dev_private;
  204. struct exynos_atomic_commit *commit;
  205. struct drm_crtc *crtc;
  206. struct drm_crtc_state *crtc_state;
  207. int i, ret;
  208. commit = kzalloc(sizeof(*commit), GFP_KERNEL);
  209. if (!commit)
  210. return -ENOMEM;
  211. ret = drm_atomic_helper_prepare_planes(dev, state);
  212. if (ret) {
  213. kfree(commit);
  214. return ret;
  215. }
  216. /* This is the point of no return */
  217. INIT_WORK(&commit->work, exynos_drm_atomic_work);
  218. commit->dev = dev;
  219. commit->state = state;
  220. /* Wait until all affected CRTCs have completed previous commits and
  221. * mark them as pending.
  222. */
  223. for_each_crtc_in_state(state, crtc, crtc_state, i)
  224. commit->crtcs |= drm_crtc_mask(crtc);
  225. wait_event(priv->wait, !commit_is_pending(priv, commit->crtcs));
  226. spin_lock(&priv->lock);
  227. priv->pending |= commit->crtcs;
  228. spin_unlock(&priv->lock);
  229. drm_atomic_helper_swap_state(state, true);
  230. if (nonblock)
  231. schedule_work(&commit->work);
  232. else
  233. exynos_atomic_commit_complete(commit);
  234. return 0;
  235. }
  236. static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
  237. {
  238. struct drm_exynos_file_private *file_priv;
  239. int ret;
  240. file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
  241. if (!file_priv)
  242. return -ENOMEM;
  243. file->driver_priv = file_priv;
  244. ret = exynos_drm_subdrv_open(dev, file);
  245. if (ret)
  246. goto err_file_priv_free;
  247. return ret;
  248. err_file_priv_free:
  249. kfree(file_priv);
  250. file->driver_priv = NULL;
  251. return ret;
  252. }
  253. static void exynos_drm_preclose(struct drm_device *dev,
  254. struct drm_file *file)
  255. {
  256. struct drm_crtc *crtc;
  257. exynos_drm_subdrv_close(dev, file);
  258. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  259. exynos_drm_crtc_cancel_page_flip(crtc, file);
  260. }
  261. static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
  262. {
  263. kfree(file->driver_priv);
  264. file->driver_priv = NULL;
  265. }
  266. static void exynos_drm_lastclose(struct drm_device *dev)
  267. {
  268. exynos_drm_fbdev_restore_mode(dev);
  269. }
  270. static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
  271. .fault = exynos_drm_gem_fault,
  272. .open = drm_gem_vm_open,
  273. .close = drm_gem_vm_close,
  274. };
  275. static const struct drm_ioctl_desc exynos_ioctls[] = {
  276. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
  277. DRM_AUTH | DRM_RENDER_ALLOW),
  278. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP, exynos_drm_gem_map_ioctl,
  279. DRM_AUTH | DRM_RENDER_ALLOW),
  280. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET, exynos_drm_gem_get_ioctl,
  281. DRM_RENDER_ALLOW),
  282. DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION, vidi_connection_ioctl,
  283. DRM_AUTH),
  284. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER, exynos_g2d_get_ver_ioctl,
  285. DRM_AUTH | DRM_RENDER_ALLOW),
  286. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST, exynos_g2d_set_cmdlist_ioctl,
  287. DRM_AUTH | DRM_RENDER_ALLOW),
  288. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC, exynos_g2d_exec_ioctl,
  289. DRM_AUTH | DRM_RENDER_ALLOW),
  290. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY, exynos_drm_ipp_get_property,
  291. DRM_AUTH | DRM_RENDER_ALLOW),
  292. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY, exynos_drm_ipp_set_property,
  293. DRM_AUTH | DRM_RENDER_ALLOW),
  294. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF, exynos_drm_ipp_queue_buf,
  295. DRM_AUTH | DRM_RENDER_ALLOW),
  296. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL, exynos_drm_ipp_cmd_ctrl,
  297. DRM_AUTH | DRM_RENDER_ALLOW),
  298. };
  299. static const struct file_operations exynos_drm_driver_fops = {
  300. .owner = THIS_MODULE,
  301. .open = drm_open,
  302. .mmap = exynos_drm_gem_mmap,
  303. .poll = drm_poll,
  304. .read = drm_read,
  305. .unlocked_ioctl = drm_ioctl,
  306. #ifdef CONFIG_COMPAT
  307. .compat_ioctl = drm_compat_ioctl,
  308. #endif
  309. .release = drm_release,
  310. };
  311. static struct drm_driver exynos_drm_driver = {
  312. .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME
  313. | DRIVER_ATOMIC | DRIVER_RENDER,
  314. .load = exynos_drm_load,
  315. .unload = exynos_drm_unload,
  316. .open = exynos_drm_open,
  317. .preclose = exynos_drm_preclose,
  318. .lastclose = exynos_drm_lastclose,
  319. .postclose = exynos_drm_postclose,
  320. .get_vblank_counter = drm_vblank_no_hw_counter,
  321. .enable_vblank = exynos_drm_crtc_enable_vblank,
  322. .disable_vblank = exynos_drm_crtc_disable_vblank,
  323. .gem_free_object_unlocked = exynos_drm_gem_free_object,
  324. .gem_vm_ops = &exynos_drm_gem_vm_ops,
  325. .dumb_create = exynos_drm_gem_dumb_create,
  326. .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
  327. .dumb_destroy = drm_gem_dumb_destroy,
  328. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  329. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  330. .gem_prime_export = drm_gem_prime_export,
  331. .gem_prime_import = drm_gem_prime_import,
  332. .gem_prime_get_sg_table = exynos_drm_gem_prime_get_sg_table,
  333. .gem_prime_import_sg_table = exynos_drm_gem_prime_import_sg_table,
  334. .gem_prime_vmap = exynos_drm_gem_prime_vmap,
  335. .gem_prime_vunmap = exynos_drm_gem_prime_vunmap,
  336. .gem_prime_mmap = exynos_drm_gem_prime_mmap,
  337. .ioctls = exynos_ioctls,
  338. .num_ioctls = ARRAY_SIZE(exynos_ioctls),
  339. .fops = &exynos_drm_driver_fops,
  340. .name = DRIVER_NAME,
  341. .desc = DRIVER_DESC,
  342. .date = DRIVER_DATE,
  343. .major = DRIVER_MAJOR,
  344. .minor = DRIVER_MINOR,
  345. };
  346. #ifdef CONFIG_PM_SLEEP
  347. static int exynos_drm_suspend(struct device *dev)
  348. {
  349. struct drm_device *drm_dev = dev_get_drvdata(dev);
  350. struct drm_connector *connector;
  351. if (pm_runtime_suspended(dev) || !drm_dev)
  352. return 0;
  353. drm_modeset_lock_all(drm_dev);
  354. drm_for_each_connector(connector, drm_dev) {
  355. int old_dpms = connector->dpms;
  356. if (connector->funcs->dpms)
  357. connector->funcs->dpms(connector, DRM_MODE_DPMS_OFF);
  358. /* Set the old mode back to the connector for resume */
  359. connector->dpms = old_dpms;
  360. }
  361. drm_modeset_unlock_all(drm_dev);
  362. return 0;
  363. }
  364. static int exynos_drm_resume(struct device *dev)
  365. {
  366. struct drm_device *drm_dev = dev_get_drvdata(dev);
  367. struct drm_connector *connector;
  368. if (pm_runtime_suspended(dev) || !drm_dev)
  369. return 0;
  370. drm_modeset_lock_all(drm_dev);
  371. drm_for_each_connector(connector, drm_dev) {
  372. if (connector->funcs->dpms) {
  373. int dpms = connector->dpms;
  374. connector->dpms = DRM_MODE_DPMS_OFF;
  375. connector->funcs->dpms(connector, dpms);
  376. }
  377. }
  378. drm_modeset_unlock_all(drm_dev);
  379. return 0;
  380. }
  381. #endif
  382. static const struct dev_pm_ops exynos_drm_pm_ops = {
  383. SET_SYSTEM_SLEEP_PM_OPS(exynos_drm_suspend, exynos_drm_resume)
  384. };
  385. /* forward declaration */
  386. static struct platform_driver exynos_drm_platform_driver;
  387. struct exynos_drm_driver_info {
  388. struct platform_driver *driver;
  389. unsigned int flags;
  390. };
  391. #define DRM_COMPONENT_DRIVER BIT(0) /* supports component framework */
  392. #define DRM_VIRTUAL_DEVICE BIT(1) /* create virtual platform device */
  393. #define DRM_DMA_DEVICE BIT(2) /* can be used for dma allocations */
  394. #define DRV_PTR(drv, cond) (IS_ENABLED(cond) ? &drv : NULL)
  395. /*
  396. * Connector drivers should not be placed before associated crtc drivers,
  397. * because connector requires pipe number of its crtc during initialization.
  398. */
  399. static struct exynos_drm_driver_info exynos_drm_drivers[] = {
  400. {
  401. DRV_PTR(fimd_driver, CONFIG_DRM_EXYNOS_FIMD),
  402. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  403. }, {
  404. DRV_PTR(exynos5433_decon_driver, CONFIG_DRM_EXYNOS5433_DECON),
  405. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  406. }, {
  407. DRV_PTR(decon_driver, CONFIG_DRM_EXYNOS7_DECON),
  408. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  409. }, {
  410. DRV_PTR(mixer_driver, CONFIG_DRM_EXYNOS_MIXER),
  411. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  412. }, {
  413. DRV_PTR(mic_driver, CONFIG_DRM_EXYNOS_MIC),
  414. DRM_COMPONENT_DRIVER
  415. }, {
  416. DRV_PTR(dp_driver, CONFIG_DRM_EXYNOS_DP),
  417. DRM_COMPONENT_DRIVER
  418. }, {
  419. DRV_PTR(dsi_driver, CONFIG_DRM_EXYNOS_DSI),
  420. DRM_COMPONENT_DRIVER
  421. }, {
  422. DRV_PTR(hdmi_driver, CONFIG_DRM_EXYNOS_HDMI),
  423. DRM_COMPONENT_DRIVER
  424. }, {
  425. DRV_PTR(vidi_driver, CONFIG_DRM_EXYNOS_VIDI),
  426. DRM_COMPONENT_DRIVER | DRM_VIRTUAL_DEVICE
  427. }, {
  428. DRV_PTR(g2d_driver, CONFIG_DRM_EXYNOS_G2D),
  429. }, {
  430. DRV_PTR(fimc_driver, CONFIG_DRM_EXYNOS_FIMC),
  431. }, {
  432. DRV_PTR(rotator_driver, CONFIG_DRM_EXYNOS_ROTATOR),
  433. }, {
  434. DRV_PTR(gsc_driver, CONFIG_DRM_EXYNOS_GSC),
  435. }, {
  436. DRV_PTR(ipp_driver, CONFIG_DRM_EXYNOS_IPP),
  437. DRM_VIRTUAL_DEVICE
  438. }, {
  439. &exynos_drm_platform_driver,
  440. DRM_VIRTUAL_DEVICE
  441. }
  442. };
  443. static int compare_dev(struct device *dev, void *data)
  444. {
  445. return dev == (struct device *)data;
  446. }
  447. static struct component_match *exynos_drm_match_add(struct device *dev)
  448. {
  449. struct component_match *match = NULL;
  450. int i;
  451. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  452. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  453. struct device *p = NULL, *d;
  454. if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
  455. continue;
  456. while ((d = bus_find_device(&platform_bus_type, p,
  457. &info->driver->driver,
  458. (void *)platform_bus_type.match))) {
  459. put_device(p);
  460. component_match_add(dev, &match, compare_dev, d);
  461. p = d;
  462. }
  463. put_device(p);
  464. }
  465. return match ?: ERR_PTR(-ENODEV);
  466. }
  467. static int exynos_drm_bind(struct device *dev)
  468. {
  469. return drm_platform_init(&exynos_drm_driver, to_platform_device(dev));
  470. }
  471. static void exynos_drm_unbind(struct device *dev)
  472. {
  473. drm_put_dev(dev_get_drvdata(dev));
  474. }
  475. static const struct component_master_ops exynos_drm_ops = {
  476. .bind = exynos_drm_bind,
  477. .unbind = exynos_drm_unbind,
  478. };
  479. static int exynos_drm_platform_probe(struct platform_device *pdev)
  480. {
  481. struct component_match *match;
  482. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  483. exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls);
  484. match = exynos_drm_match_add(&pdev->dev);
  485. if (IS_ERR(match))
  486. return PTR_ERR(match);
  487. return component_master_add_with_match(&pdev->dev, &exynos_drm_ops,
  488. match);
  489. }
  490. static int exynos_drm_platform_remove(struct platform_device *pdev)
  491. {
  492. component_master_del(&pdev->dev, &exynos_drm_ops);
  493. return 0;
  494. }
  495. static struct platform_driver exynos_drm_platform_driver = {
  496. .probe = exynos_drm_platform_probe,
  497. .remove = exynos_drm_platform_remove,
  498. .driver = {
  499. .name = "exynos-drm",
  500. .pm = &exynos_drm_pm_ops,
  501. },
  502. };
  503. static struct device *exynos_drm_get_dma_device(void)
  504. {
  505. int i;
  506. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  507. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  508. struct device *dev;
  509. if (!info->driver || !(info->flags & DRM_DMA_DEVICE))
  510. continue;
  511. while ((dev = bus_find_device(&platform_bus_type, NULL,
  512. &info->driver->driver,
  513. (void *)platform_bus_type.match))) {
  514. put_device(dev);
  515. return dev;
  516. }
  517. }
  518. return NULL;
  519. }
  520. static void exynos_drm_unregister_devices(void)
  521. {
  522. int i;
  523. for (i = ARRAY_SIZE(exynos_drm_drivers) - 1; i >= 0; --i) {
  524. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  525. struct device *dev;
  526. if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
  527. continue;
  528. while ((dev = bus_find_device(&platform_bus_type, NULL,
  529. &info->driver->driver,
  530. (void *)platform_bus_type.match))) {
  531. put_device(dev);
  532. platform_device_unregister(to_platform_device(dev));
  533. }
  534. }
  535. }
  536. static int exynos_drm_register_devices(void)
  537. {
  538. struct platform_device *pdev;
  539. int i;
  540. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  541. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  542. if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
  543. continue;
  544. pdev = platform_device_register_simple(
  545. info->driver->driver.name, -1, NULL, 0);
  546. if (IS_ERR(pdev))
  547. goto fail;
  548. }
  549. return 0;
  550. fail:
  551. exynos_drm_unregister_devices();
  552. return PTR_ERR(pdev);
  553. }
  554. static void exynos_drm_unregister_drivers(void)
  555. {
  556. int i;
  557. for (i = ARRAY_SIZE(exynos_drm_drivers) - 1; i >= 0; --i) {
  558. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  559. if (!info->driver)
  560. continue;
  561. platform_driver_unregister(info->driver);
  562. }
  563. }
  564. static int exynos_drm_register_drivers(void)
  565. {
  566. int i, ret;
  567. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  568. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  569. if (!info->driver)
  570. continue;
  571. ret = platform_driver_register(info->driver);
  572. if (ret)
  573. goto fail;
  574. }
  575. return 0;
  576. fail:
  577. exynos_drm_unregister_drivers();
  578. return ret;
  579. }
  580. static int exynos_drm_init(void)
  581. {
  582. int ret;
  583. ret = exynos_drm_register_devices();
  584. if (ret)
  585. return ret;
  586. ret = exynos_drm_register_drivers();
  587. if (ret)
  588. goto err_unregister_pdevs;
  589. return 0;
  590. err_unregister_pdevs:
  591. exynos_drm_unregister_devices();
  592. return ret;
  593. }
  594. static void exynos_drm_exit(void)
  595. {
  596. exynos_drm_unregister_drivers();
  597. exynos_drm_unregister_devices();
  598. }
  599. module_init(exynos_drm_init);
  600. module_exit(exynos_drm_exit);
  601. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  602. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  603. MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
  604. MODULE_DESCRIPTION("Samsung SoC DRM Driver");
  605. MODULE_LICENSE("GPL");