exynos_drm_drv.c 18 KB

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