exynos_drm_drv.c 19 KB

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