omap_drv.c 19 KB

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