omap_drv.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. * drivers/gpu/drm/omapdrm/omap_drv.c
  3. *
  4. * Copyright (C) 2011 Texas Instruments
  5. * Author: Rob Clark <rob@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/sys_soc.h>
  20. #include <drm/drm_atomic.h>
  21. #include <drm/drm_atomic_helper.h>
  22. #include <drm/drm_crtc_helper.h>
  23. #include <drm/drm_fb_helper.h>
  24. #include "omap_dmm_tiler.h"
  25. #include "omap_drv.h"
  26. #define DRIVER_NAME MODULE_NAME
  27. #define DRIVER_DESC "OMAP DRM"
  28. #define DRIVER_DATE "20110917"
  29. #define DRIVER_MAJOR 1
  30. #define DRIVER_MINOR 0
  31. #define DRIVER_PATCHLEVEL 0
  32. /*
  33. * mode config funcs
  34. */
  35. /* Notes about mapping DSS and DRM entities:
  36. * CRTC: overlay
  37. * encoder: manager.. with some extension to allow one primary CRTC
  38. * and zero or more video CRTC's to be mapped to one encoder?
  39. * connector: dssdev.. manager can be attached/detached from different
  40. * devices
  41. */
  42. static void omap_fb_output_poll_changed(struct drm_device *dev)
  43. {
  44. struct omap_drm_private *priv = dev->dev_private;
  45. DBG("dev=%p", dev);
  46. if (priv->fbdev)
  47. drm_fb_helper_hotplug_event(priv->fbdev);
  48. }
  49. static void omap_atomic_wait_for_completion(struct drm_device *dev,
  50. struct drm_atomic_state *old_state)
  51. {
  52. struct drm_crtc_state *new_crtc_state;
  53. struct drm_crtc *crtc;
  54. unsigned int i;
  55. int ret;
  56. for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) {
  57. if (!new_crtc_state->active)
  58. continue;
  59. ret = omap_crtc_wait_pending(crtc);
  60. if (!ret)
  61. dev_warn(dev->dev,
  62. "atomic complete timeout (pipe %u)!\n", i);
  63. }
  64. }
  65. static void omap_atomic_commit_tail(struct drm_atomic_state *old_state)
  66. {
  67. struct drm_device *dev = old_state->dev;
  68. struct omap_drm_private *priv = dev->dev_private;
  69. priv->dispc_ops->runtime_get();
  70. /* Apply the atomic update. */
  71. drm_atomic_helper_commit_modeset_disables(dev, old_state);
  72. if (priv->omaprev != 0x3430) {
  73. /* With the current dss dispc implementation we have to enable
  74. * the new modeset before we can commit planes. The dispc ovl
  75. * configuration relies on the video mode configuration been
  76. * written into the HW when the ovl configuration is
  77. * calculated.
  78. *
  79. * This approach is not ideal because after a mode change the
  80. * plane update is executed only after the first vblank
  81. * interrupt. The dispc implementation should be fixed so that
  82. * it is able use uncommitted drm state information.
  83. */
  84. drm_atomic_helper_commit_modeset_enables(dev, old_state);
  85. omap_atomic_wait_for_completion(dev, old_state);
  86. drm_atomic_helper_commit_planes(dev, old_state, 0);
  87. drm_atomic_helper_commit_hw_done(old_state);
  88. } else {
  89. /*
  90. * OMAP3 DSS seems to have issues with the work-around above,
  91. * resulting in endless sync losts if a crtc is enabled without
  92. * a plane. For now, skip the WA for OMAP3.
  93. */
  94. drm_atomic_helper_commit_planes(dev, old_state, 0);
  95. drm_atomic_helper_commit_modeset_enables(dev, old_state);
  96. drm_atomic_helper_commit_hw_done(old_state);
  97. }
  98. /*
  99. * Wait for completion of the page flips to ensure that old buffers
  100. * can't be touched by the hardware anymore before cleaning up planes.
  101. */
  102. omap_atomic_wait_for_completion(dev, old_state);
  103. drm_atomic_helper_cleanup_planes(dev, old_state);
  104. priv->dispc_ops->runtime_put();
  105. }
  106. static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = {
  107. .atomic_commit_tail = omap_atomic_commit_tail,
  108. };
  109. static const struct drm_mode_config_funcs omap_mode_config_funcs = {
  110. .fb_create = omap_framebuffer_create,
  111. .output_poll_changed = omap_fb_output_poll_changed,
  112. .atomic_check = drm_atomic_helper_check,
  113. .atomic_commit = drm_atomic_helper_commit,
  114. };
  115. static int get_connector_type(struct omap_dss_device *dssdev)
  116. {
  117. switch (dssdev->type) {
  118. case OMAP_DISPLAY_TYPE_HDMI:
  119. return DRM_MODE_CONNECTOR_HDMIA;
  120. case OMAP_DISPLAY_TYPE_DVI:
  121. return DRM_MODE_CONNECTOR_DVID;
  122. case OMAP_DISPLAY_TYPE_DSI:
  123. return DRM_MODE_CONNECTOR_DSI;
  124. case OMAP_DISPLAY_TYPE_DPI:
  125. case OMAP_DISPLAY_TYPE_DBI:
  126. return DRM_MODE_CONNECTOR_DPI;
  127. case OMAP_DISPLAY_TYPE_VENC:
  128. /* TODO: This could also be composite */
  129. return DRM_MODE_CONNECTOR_SVIDEO;
  130. case OMAP_DISPLAY_TYPE_SDI:
  131. return DRM_MODE_CONNECTOR_LVDS;
  132. default:
  133. return DRM_MODE_CONNECTOR_Unknown;
  134. }
  135. }
  136. static void omap_disconnect_dssdevs(void)
  137. {
  138. struct omap_dss_device *dssdev = NULL;
  139. for_each_dss_dev(dssdev)
  140. dssdev->driver->disconnect(dssdev);
  141. }
  142. static int omap_connect_dssdevs(void)
  143. {
  144. int r;
  145. struct omap_dss_device *dssdev = NULL;
  146. if (!omapdss_stack_is_ready())
  147. return -EPROBE_DEFER;
  148. for_each_dss_dev(dssdev) {
  149. r = dssdev->driver->connect(dssdev);
  150. if (r == -EPROBE_DEFER) {
  151. omap_dss_put_device(dssdev);
  152. goto cleanup;
  153. } else if (r) {
  154. dev_warn(dssdev->dev, "could not connect display: %s\n",
  155. dssdev->name);
  156. }
  157. }
  158. return 0;
  159. cleanup:
  160. /*
  161. * if we are deferring probe, we disconnect the devices we previously
  162. * connected
  163. */
  164. omap_disconnect_dssdevs();
  165. return r;
  166. }
  167. static int omap_modeset_init_properties(struct drm_device *dev)
  168. {
  169. struct omap_drm_private *priv = dev->dev_private;
  170. unsigned int num_planes = priv->dispc_ops->get_num_ovls();
  171. priv->zorder_prop = drm_property_create_range(dev, 0, "zorder", 0,
  172. num_planes - 1);
  173. if (!priv->zorder_prop)
  174. return -ENOMEM;
  175. return 0;
  176. }
  177. static int omap_modeset_init(struct drm_device *dev)
  178. {
  179. struct omap_drm_private *priv = dev->dev_private;
  180. struct omap_dss_device *dssdev = NULL;
  181. int num_ovls = priv->dispc_ops->get_num_ovls();
  182. int num_mgrs = priv->dispc_ops->get_num_mgrs();
  183. int num_crtcs, crtc_idx, plane_idx;
  184. int ret;
  185. u32 plane_crtc_mask;
  186. drm_mode_config_init(dev);
  187. ret = omap_modeset_init_properties(dev);
  188. if (ret < 0)
  189. return ret;
  190. /*
  191. * This function creates exactly one connector, encoder, crtc,
  192. * and primary plane per each connected dss-device. Each
  193. * connector->encoder->crtc chain is expected to be separate
  194. * and each crtc is connect to a single dss-channel. If the
  195. * configuration does not match the expectations or exceeds
  196. * the available resources, the configuration is rejected.
  197. */
  198. num_crtcs = 0;
  199. for_each_dss_dev(dssdev)
  200. if (omapdss_device_is_connected(dssdev))
  201. num_crtcs++;
  202. if (num_crtcs > num_mgrs || num_crtcs > num_ovls ||
  203. num_crtcs > ARRAY_SIZE(priv->crtcs) ||
  204. num_crtcs > ARRAY_SIZE(priv->planes) ||
  205. num_crtcs > ARRAY_SIZE(priv->encoders) ||
  206. num_crtcs > ARRAY_SIZE(priv->connectors)) {
  207. dev_err(dev->dev, "%s(): Too many connected displays\n",
  208. __func__);
  209. return -EINVAL;
  210. }
  211. /* All planes can be put to any CRTC */
  212. plane_crtc_mask = (1 << num_crtcs) - 1;
  213. dssdev = NULL;
  214. crtc_idx = 0;
  215. plane_idx = 0;
  216. for_each_dss_dev(dssdev) {
  217. struct drm_connector *connector;
  218. struct drm_encoder *encoder;
  219. struct drm_plane *plane;
  220. struct drm_crtc *crtc;
  221. if (!omapdss_device_is_connected(dssdev))
  222. continue;
  223. encoder = omap_encoder_init(dev, dssdev);
  224. if (!encoder)
  225. return -ENOMEM;
  226. connector = omap_connector_init(dev,
  227. get_connector_type(dssdev), dssdev, encoder);
  228. if (!connector)
  229. return -ENOMEM;
  230. plane = omap_plane_init(dev, plane_idx, DRM_PLANE_TYPE_PRIMARY,
  231. plane_crtc_mask);
  232. if (IS_ERR(plane))
  233. return PTR_ERR(plane);
  234. crtc = omap_crtc_init(dev, plane, dssdev);
  235. if (IS_ERR(crtc))
  236. return PTR_ERR(crtc);
  237. drm_mode_connector_attach_encoder(connector, encoder);
  238. encoder->possible_crtcs = (1 << crtc_idx);
  239. priv->crtcs[priv->num_crtcs++] = crtc;
  240. priv->planes[priv->num_planes++] = plane;
  241. priv->encoders[priv->num_encoders++] = encoder;
  242. priv->connectors[priv->num_connectors++] = connector;
  243. plane_idx++;
  244. crtc_idx++;
  245. }
  246. /*
  247. * Create normal planes for the remaining overlays:
  248. */
  249. for (; plane_idx < num_ovls; plane_idx++) {
  250. struct drm_plane *plane;
  251. if (WARN_ON(priv->num_planes >= ARRAY_SIZE(priv->planes)))
  252. return -EINVAL;
  253. plane = omap_plane_init(dev, plane_idx, DRM_PLANE_TYPE_OVERLAY,
  254. plane_crtc_mask);
  255. if (IS_ERR(plane))
  256. return PTR_ERR(plane);
  257. priv->planes[priv->num_planes++] = plane;
  258. }
  259. DBG("registered %d planes, %d crtcs, %d encoders and %d connectors\n",
  260. priv->num_planes, priv->num_crtcs, priv->num_encoders,
  261. priv->num_connectors);
  262. dev->mode_config.min_width = 8;
  263. dev->mode_config.min_height = 2;
  264. /* note: eventually will need some cpu_is_omapXYZ() type stuff here
  265. * to fill in these limits properly on different OMAP generations..
  266. */
  267. dev->mode_config.max_width = 2048;
  268. dev->mode_config.max_height = 2048;
  269. dev->mode_config.funcs = &omap_mode_config_funcs;
  270. dev->mode_config.helper_private = &omap_mode_config_helper_funcs;
  271. drm_mode_config_reset(dev);
  272. omap_drm_irq_install(dev);
  273. return 0;
  274. }
  275. /*
  276. * Enable the HPD in external components if supported
  277. */
  278. static void omap_modeset_enable_external_hpd(void)
  279. {
  280. struct omap_dss_device *dssdev = NULL;
  281. for_each_dss_dev(dssdev) {
  282. if (dssdev->driver->enable_hpd)
  283. dssdev->driver->enable_hpd(dssdev);
  284. }
  285. }
  286. /*
  287. * Disable the HPD in external components if supported
  288. */
  289. static void omap_modeset_disable_external_hpd(void)
  290. {
  291. struct omap_dss_device *dssdev = NULL;
  292. for_each_dss_dev(dssdev) {
  293. if (dssdev->driver->disable_hpd)
  294. dssdev->driver->disable_hpd(dssdev);
  295. }
  296. }
  297. /*
  298. * drm ioctl funcs
  299. */
  300. static int ioctl_get_param(struct drm_device *dev, void *data,
  301. struct drm_file *file_priv)
  302. {
  303. struct omap_drm_private *priv = dev->dev_private;
  304. struct drm_omap_param *args = data;
  305. DBG("%p: param=%llu", dev, args->param);
  306. switch (args->param) {
  307. case OMAP_PARAM_CHIPSET_ID:
  308. args->value = priv->omaprev;
  309. break;
  310. default:
  311. DBG("unknown parameter %lld", args->param);
  312. return -EINVAL;
  313. }
  314. return 0;
  315. }
  316. static int ioctl_set_param(struct drm_device *dev, void *data,
  317. struct drm_file *file_priv)
  318. {
  319. struct drm_omap_param *args = data;
  320. switch (args->param) {
  321. default:
  322. DBG("unknown parameter %lld", args->param);
  323. return -EINVAL;
  324. }
  325. return 0;
  326. }
  327. #define OMAP_BO_USER_MASK 0x00ffffff /* flags settable by userspace */
  328. static int ioctl_gem_new(struct drm_device *dev, void *data,
  329. struct drm_file *file_priv)
  330. {
  331. struct drm_omap_gem_new *args = data;
  332. u32 flags = args->flags & OMAP_BO_USER_MASK;
  333. VERB("%p:%p: size=0x%08x, flags=%08x", dev, file_priv,
  334. args->size.bytes, flags);
  335. return omap_gem_new_handle(dev, file_priv, args->size, flags,
  336. &args->handle);
  337. }
  338. static int ioctl_gem_info(struct drm_device *dev, void *data,
  339. struct drm_file *file_priv)
  340. {
  341. struct drm_omap_gem_info *args = data;
  342. struct drm_gem_object *obj;
  343. int ret = 0;
  344. VERB("%p:%p: handle=%d", dev, file_priv, args->handle);
  345. obj = drm_gem_object_lookup(file_priv, args->handle);
  346. if (!obj)
  347. return -ENOENT;
  348. args->size = omap_gem_mmap_size(obj);
  349. args->offset = omap_gem_mmap_offset(obj);
  350. drm_gem_object_unreference_unlocked(obj);
  351. return ret;
  352. }
  353. static const struct drm_ioctl_desc ioctls[DRM_COMMAND_END - DRM_COMMAND_BASE] = {
  354. DRM_IOCTL_DEF_DRV(OMAP_GET_PARAM, ioctl_get_param,
  355. DRM_AUTH | DRM_RENDER_ALLOW),
  356. DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, ioctl_set_param,
  357. DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
  358. DRM_IOCTL_DEF_DRV(OMAP_GEM_NEW, ioctl_gem_new,
  359. DRM_AUTH | DRM_RENDER_ALLOW),
  360. /* Deprecated, to be removed. */
  361. DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_PREP, drm_noop,
  362. DRM_AUTH | DRM_RENDER_ALLOW),
  363. /* Deprecated, to be removed. */
  364. DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_FINI, drm_noop,
  365. DRM_AUTH | DRM_RENDER_ALLOW),
  366. DRM_IOCTL_DEF_DRV(OMAP_GEM_INFO, ioctl_gem_info,
  367. DRM_AUTH | DRM_RENDER_ALLOW),
  368. };
  369. /*
  370. * drm driver funcs
  371. */
  372. static int dev_open(struct drm_device *dev, struct drm_file *file)
  373. {
  374. file->driver_priv = NULL;
  375. DBG("open: dev=%p, file=%p", dev, file);
  376. return 0;
  377. }
  378. /**
  379. * lastclose - clean up after all DRM clients have exited
  380. * @dev: DRM device
  381. *
  382. * Take care of cleaning up after all DRM clients have exited. In the
  383. * mode setting case, we want to restore the kernel's initial mode (just
  384. * in case the last client left us in a bad state).
  385. */
  386. static void dev_lastclose(struct drm_device *dev)
  387. {
  388. struct omap_drm_private *priv = dev->dev_private;
  389. int ret;
  390. DBG("lastclose: dev=%p", dev);
  391. if (priv->fbdev) {
  392. ret = drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev);
  393. if (ret)
  394. DBG("failed to restore crtc mode");
  395. }
  396. }
  397. static const struct vm_operations_struct omap_gem_vm_ops = {
  398. .fault = omap_gem_fault,
  399. .open = drm_gem_vm_open,
  400. .close = drm_gem_vm_close,
  401. };
  402. static const struct file_operations omapdriver_fops = {
  403. .owner = THIS_MODULE,
  404. .open = drm_open,
  405. .unlocked_ioctl = drm_ioctl,
  406. .compat_ioctl = drm_compat_ioctl,
  407. .release = drm_release,
  408. .mmap = omap_gem_mmap,
  409. .poll = drm_poll,
  410. .read = drm_read,
  411. .llseek = noop_llseek,
  412. };
  413. static struct drm_driver omap_drm_driver = {
  414. .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME |
  415. DRIVER_ATOMIC | DRIVER_RENDER,
  416. .open = dev_open,
  417. .lastclose = dev_lastclose,
  418. #ifdef CONFIG_DEBUG_FS
  419. .debugfs_init = omap_debugfs_init,
  420. #endif
  421. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  422. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  423. .gem_prime_export = omap_gem_prime_export,
  424. .gem_prime_import = omap_gem_prime_import,
  425. .gem_free_object = omap_gem_free_object,
  426. .gem_vm_ops = &omap_gem_vm_ops,
  427. .dumb_create = omap_gem_dumb_create,
  428. .dumb_map_offset = omap_gem_dumb_map_offset,
  429. .ioctls = ioctls,
  430. .num_ioctls = DRM_OMAP_NUM_IOCTLS,
  431. .fops = &omapdriver_fops,
  432. .name = DRIVER_NAME,
  433. .desc = DRIVER_DESC,
  434. .date = DRIVER_DATE,
  435. .major = DRIVER_MAJOR,
  436. .minor = DRIVER_MINOR,
  437. .patchlevel = DRIVER_PATCHLEVEL,
  438. };
  439. static const struct soc_device_attribute omapdrm_soc_devices[] = {
  440. { .family = "OMAP3", .data = (void *)0x3430 },
  441. { .family = "OMAP4", .data = (void *)0x4430 },
  442. { .family = "OMAP5", .data = (void *)0x5430 },
  443. { .family = "DRA7", .data = (void *)0x0752 },
  444. { /* sentinel */ }
  445. };
  446. static int pdev_probe(struct platform_device *pdev)
  447. {
  448. const struct soc_device_attribute *soc;
  449. struct omap_drm_private *priv;
  450. struct drm_device *ddev;
  451. unsigned int i;
  452. int ret;
  453. DBG("%s", pdev->name);
  454. if (omapdss_is_initialized() == false)
  455. return -EPROBE_DEFER;
  456. ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  457. if (ret) {
  458. dev_err(&pdev->dev, "Failed to set the DMA mask\n");
  459. return ret;
  460. }
  461. omap_crtc_pre_init();
  462. ret = omap_connect_dssdevs();
  463. if (ret)
  464. goto err_crtc_uninit;
  465. /* Allocate and initialize the driver private structure. */
  466. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  467. if (!priv) {
  468. ret = -ENOMEM;
  469. goto err_disconnect_dssdevs;
  470. }
  471. priv->dispc_ops = dispc_get_ops();
  472. soc = soc_device_match(omapdrm_soc_devices);
  473. priv->omaprev = soc ? (unsigned int)soc->data : 0;
  474. priv->wq = alloc_ordered_workqueue("omapdrm", 0);
  475. spin_lock_init(&priv->list_lock);
  476. INIT_LIST_HEAD(&priv->obj_list);
  477. /* Allocate and initialize the DRM device. */
  478. ddev = drm_dev_alloc(&omap_drm_driver, &pdev->dev);
  479. if (IS_ERR(ddev)) {
  480. ret = PTR_ERR(ddev);
  481. goto err_free_priv;
  482. }
  483. ddev->dev_private = priv;
  484. platform_set_drvdata(pdev, ddev);
  485. omap_gem_init(ddev);
  486. ret = omap_modeset_init(ddev);
  487. if (ret) {
  488. dev_err(&pdev->dev, "omap_modeset_init failed: ret=%d\n", ret);
  489. goto err_free_drm_dev;
  490. }
  491. /* Initialize vblank handling, start with all CRTCs disabled. */
  492. ret = drm_vblank_init(ddev, priv->num_crtcs);
  493. if (ret) {
  494. dev_err(&pdev->dev, "could not init vblank\n");
  495. goto err_cleanup_modeset;
  496. }
  497. for (i = 0; i < priv->num_crtcs; i++)
  498. drm_crtc_vblank_off(priv->crtcs[i]);
  499. priv->fbdev = omap_fbdev_init(ddev);
  500. drm_kms_helper_poll_init(ddev);
  501. omap_modeset_enable_external_hpd();
  502. /*
  503. * Register the DRM device with the core and the connectors with
  504. * sysfs.
  505. */
  506. ret = drm_dev_register(ddev, 0);
  507. if (ret)
  508. goto err_cleanup_helpers;
  509. return 0;
  510. err_cleanup_helpers:
  511. omap_modeset_disable_external_hpd();
  512. drm_kms_helper_poll_fini(ddev);
  513. if (priv->fbdev)
  514. omap_fbdev_free(ddev);
  515. err_cleanup_modeset:
  516. drm_mode_config_cleanup(ddev);
  517. omap_drm_irq_uninstall(ddev);
  518. err_free_drm_dev:
  519. omap_gem_deinit(ddev);
  520. drm_dev_unref(ddev);
  521. err_free_priv:
  522. destroy_workqueue(priv->wq);
  523. kfree(priv);
  524. err_disconnect_dssdevs:
  525. omap_disconnect_dssdevs();
  526. err_crtc_uninit:
  527. omap_crtc_pre_uninit();
  528. return ret;
  529. }
  530. static int pdev_remove(struct platform_device *pdev)
  531. {
  532. struct drm_device *ddev = platform_get_drvdata(pdev);
  533. struct omap_drm_private *priv = ddev->dev_private;
  534. DBG("");
  535. drm_dev_unregister(ddev);
  536. omap_modeset_disable_external_hpd();
  537. drm_kms_helper_poll_fini(ddev);
  538. if (priv->fbdev)
  539. omap_fbdev_free(ddev);
  540. drm_atomic_helper_shutdown(ddev);
  541. drm_mode_config_cleanup(ddev);
  542. omap_drm_irq_uninstall(ddev);
  543. omap_gem_deinit(ddev);
  544. drm_dev_unref(ddev);
  545. destroy_workqueue(priv->wq);
  546. kfree(priv);
  547. omap_disconnect_dssdevs();
  548. omap_crtc_pre_uninit();
  549. return 0;
  550. }
  551. #ifdef CONFIG_PM_SLEEP
  552. static int omap_drm_suspend_all_displays(void)
  553. {
  554. struct omap_dss_device *dssdev = NULL;
  555. for_each_dss_dev(dssdev) {
  556. if (!dssdev->driver)
  557. continue;
  558. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  559. dssdev->driver->disable(dssdev);
  560. dssdev->activate_after_resume = true;
  561. } else {
  562. dssdev->activate_after_resume = false;
  563. }
  564. }
  565. return 0;
  566. }
  567. static int omap_drm_resume_all_displays(void)
  568. {
  569. struct omap_dss_device *dssdev = NULL;
  570. for_each_dss_dev(dssdev) {
  571. if (!dssdev->driver)
  572. continue;
  573. if (dssdev->activate_after_resume) {
  574. dssdev->driver->enable(dssdev);
  575. dssdev->activate_after_resume = false;
  576. }
  577. }
  578. return 0;
  579. }
  580. static int omap_drm_suspend(struct device *dev)
  581. {
  582. struct drm_device *drm_dev = dev_get_drvdata(dev);
  583. drm_kms_helper_poll_disable(drm_dev);
  584. drm_modeset_lock_all(drm_dev);
  585. omap_drm_suspend_all_displays();
  586. drm_modeset_unlock_all(drm_dev);
  587. return 0;
  588. }
  589. static int omap_drm_resume(struct device *dev)
  590. {
  591. struct drm_device *drm_dev = dev_get_drvdata(dev);
  592. drm_modeset_lock_all(drm_dev);
  593. omap_drm_resume_all_displays();
  594. drm_modeset_unlock_all(drm_dev);
  595. drm_kms_helper_poll_enable(drm_dev);
  596. return omap_gem_resume(dev);
  597. }
  598. #endif
  599. static SIMPLE_DEV_PM_OPS(omapdrm_pm_ops, omap_drm_suspend, omap_drm_resume);
  600. static struct platform_driver pdev = {
  601. .driver = {
  602. .name = "omapdrm",
  603. .pm = &omapdrm_pm_ops,
  604. },
  605. .probe = pdev_probe,
  606. .remove = pdev_remove,
  607. };
  608. static struct platform_driver * const drivers[] = {
  609. &omap_dmm_driver,
  610. &pdev,
  611. };
  612. static int __init omap_drm_init(void)
  613. {
  614. DBG("init");
  615. return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
  616. }
  617. static void __exit omap_drm_fini(void)
  618. {
  619. DBG("fini");
  620. platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
  621. }
  622. /* need late_initcall() so we load after dss_driver's are loaded */
  623. late_initcall(omap_drm_init);
  624. module_exit(omap_drm_fini);
  625. MODULE_AUTHOR("Rob Clark <rob@ti.com>");
  626. MODULE_DESCRIPTION("OMAP DRM Display Driver");
  627. MODULE_ALIAS("platform:" DRIVER_NAME);
  628. MODULE_LICENSE("GPL v2");