Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 1 | /* |
Rob Clark | 8bb0daf | 2013-02-11 12:43:09 -0500 | [diff] [blame] | 2 | * drivers/gpu/drm/omapdrm/omap_drv.c |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 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 | |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 20 | #include <drm/drm_atomic.h> |
Laurent Pinchart | cef77d4 | 2015-03-05 21:50:00 +0200 | [diff] [blame] | 21 | #include <drm/drm_atomic_helper.h> |
Laurent Pinchart | 2d278f5 | 2015-03-05 21:31:37 +0200 | [diff] [blame] | 22 | #include <drm/drm_crtc_helper.h> |
| 23 | #include <drm/drm_fb_helper.h> |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 24 | |
Andy Gross | 5c13779 | 2012-03-05 10:48:39 -0600 | [diff] [blame] | 25 | #include "omap_dmm_tiler.h" |
Laurent Pinchart | 2d278f5 | 2015-03-05 21:31:37 +0200 | [diff] [blame] | 26 | #include "omap_drv.h" |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 27 | |
| 28 | #define DRIVER_NAME MODULE_NAME |
| 29 | #define DRIVER_DESC "OMAP DRM" |
| 30 | #define DRIVER_DATE "20110917" |
| 31 | #define DRIVER_MAJOR 1 |
| 32 | #define DRIVER_MINOR 0 |
| 33 | #define DRIVER_PATCHLEVEL 0 |
| 34 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 35 | /* |
| 36 | * mode config funcs |
| 37 | */ |
| 38 | |
| 39 | /* Notes about mapping DSS and DRM entities: |
| 40 | * CRTC: overlay |
| 41 | * encoder: manager.. with some extension to allow one primary CRTC |
| 42 | * and zero or more video CRTC's to be mapped to one encoder? |
| 43 | * connector: dssdev.. manager can be attached/detached from different |
| 44 | * devices |
| 45 | */ |
| 46 | |
| 47 | static void omap_fb_output_poll_changed(struct drm_device *dev) |
| 48 | { |
| 49 | struct omap_drm_private *priv = dev->dev_private; |
| 50 | DBG("dev=%p", dev); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 51 | if (priv->fbdev) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 52 | drm_fb_helper_hotplug_event(priv->fbdev); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 53 | } |
| 54 | |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 55 | static void omap_atomic_wait_for_completion(struct drm_device *dev, |
| 56 | struct drm_atomic_state *old_state) |
| 57 | { |
| 58 | struct drm_crtc_state *old_crtc_state; |
| 59 | struct drm_crtc *crtc; |
| 60 | unsigned int i; |
| 61 | int ret; |
| 62 | |
| 63 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 64 | if (!crtc->state->enable) |
| 65 | continue; |
| 66 | |
| 67 | ret = omap_crtc_wait_pending(crtc); |
| 68 | |
| 69 | if (!ret) |
| 70 | dev_warn(dev->dev, |
| 71 | "atomic complete timeout (pipe %u)!\n", i); |
| 72 | } |
| 73 | } |
| 74 | |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 75 | static void omap_atomic_commit_tail(struct drm_atomic_state *old_state) |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 76 | { |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 77 | struct drm_device *dev = old_state->dev; |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 78 | struct omap_drm_private *priv = dev->dev_private; |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 79 | |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 80 | priv->dispc_ops->runtime_get(); |
Laurent Pinchart | 69fb7c8 | 2015-05-28 02:09:56 +0300 | [diff] [blame] | 81 | |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 82 | /* Apply the atomic update. */ |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 83 | drm_atomic_helper_commit_modeset_disables(dev, old_state); |
Jyri Sarha | 897145d | 2017-01-27 12:04:55 +0200 | [diff] [blame] | 84 | |
| 85 | /* With the current dss dispc implementation we have to enable |
| 86 | * the new modeset before we can commit planes. The dispc ovl |
| 87 | * configuration relies on the video mode configuration been |
| 88 | * written into the HW when the ovl configuration is |
| 89 | * calculated. |
| 90 | * |
| 91 | * This approach is not ideal because after a mode change the |
| 92 | * plane update is executed only after the first vblank |
| 93 | * interrupt. The dispc implementation should be fixed so that |
| 94 | * it is able use uncommitted drm state information. |
| 95 | */ |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 96 | drm_atomic_helper_commit_modeset_enables(dev, old_state); |
Jyri Sarha | 897145d | 2017-01-27 12:04:55 +0200 | [diff] [blame] | 97 | omap_atomic_wait_for_completion(dev, old_state); |
| 98 | |
| 99 | drm_atomic_helper_commit_planes(dev, old_state, 0); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 100 | |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 101 | drm_atomic_helper_commit_hw_done(old_state); |
| 102 | |
| 103 | /* |
| 104 | * Wait for completion of the page flips to ensure that old buffers |
| 105 | * can't be touched by the hardware anymore before cleaning up planes. |
| 106 | */ |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 107 | omap_atomic_wait_for_completion(dev, old_state); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 108 | |
| 109 | drm_atomic_helper_cleanup_planes(dev, old_state); |
| 110 | |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 111 | priv->dispc_ops->runtime_put(); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 112 | } |
| 113 | |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 114 | static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = { |
| 115 | .atomic_commit_tail = omap_atomic_commit_tail, |
| 116 | }; |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 117 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 118 | static const struct drm_mode_config_funcs omap_mode_config_funcs = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 119 | .fb_create = omap_framebuffer_create, |
| 120 | .output_poll_changed = omap_fb_output_poll_changed, |
Laurent Pinchart | cef77d4 | 2015-03-05 21:50:00 +0200 | [diff] [blame] | 121 | .atomic_check = drm_atomic_helper_check, |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 122 | .atomic_commit = drm_atomic_helper_commit, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | static int get_connector_type(struct omap_dss_device *dssdev) |
| 126 | { |
| 127 | switch (dssdev->type) { |
| 128 | case OMAP_DISPLAY_TYPE_HDMI: |
| 129 | return DRM_MODE_CONNECTOR_HDMIA; |
Tomi Valkeinen | 4635c17 | 2013-05-14 14:14:15 +0300 | [diff] [blame] | 130 | case OMAP_DISPLAY_TYPE_DVI: |
| 131 | return DRM_MODE_CONNECTOR_DVID; |
Sebastian Reichel | 4a64b90 | 2016-03-08 17:39:36 +0100 | [diff] [blame] | 132 | case OMAP_DISPLAY_TYPE_DSI: |
| 133 | return DRM_MODE_CONNECTOR_DSI; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 134 | default: |
| 135 | return DRM_MODE_CONNECTOR_Unknown; |
| 136 | } |
| 137 | } |
| 138 | |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 139 | static void omap_disconnect_dssdevs(void) |
| 140 | { |
| 141 | struct omap_dss_device *dssdev = NULL; |
| 142 | |
| 143 | for_each_dss_dev(dssdev) |
| 144 | dssdev->driver->disconnect(dssdev); |
| 145 | } |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 146 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 147 | static int omap_connect_dssdevs(void) |
| 148 | { |
| 149 | int r; |
| 150 | struct omap_dss_device *dssdev = NULL; |
Peter Ujfalusi | a09d2bc | 2016-05-03 22:08:01 +0300 | [diff] [blame] | 151 | |
| 152 | if (!omapdss_stack_is_ready()) |
| 153 | return -EPROBE_DEFER; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 154 | |
| 155 | for_each_dss_dev(dssdev) { |
| 156 | r = dssdev->driver->connect(dssdev); |
| 157 | if (r == -EPROBE_DEFER) { |
| 158 | omap_dss_put_device(dssdev); |
| 159 | goto cleanup; |
| 160 | } else if (r) { |
| 161 | dev_warn(dssdev->dev, "could not connect display: %s\n", |
| 162 | dssdev->name); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 166 | return 0; |
| 167 | |
| 168 | cleanup: |
| 169 | /* |
| 170 | * if we are deferring probe, we disconnect the devices we previously |
| 171 | * connected |
| 172 | */ |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 173 | omap_disconnect_dssdevs(); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 174 | |
| 175 | return r; |
| 176 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 177 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 178 | static int omap_modeset_init_properties(struct drm_device *dev) |
| 179 | { |
| 180 | struct omap_drm_private *priv = dev->dev_private; |
| 181 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 182 | priv->zorder_prop = drm_property_create_range(dev, 0, "zorder", 0, 3); |
| 183 | if (!priv->zorder_prop) |
| 184 | return -ENOMEM; |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 189 | static int omap_modeset_init(struct drm_device *dev) |
| 190 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 191 | struct omap_drm_private *priv = dev->dev_private; |
| 192 | struct omap_dss_device *dssdev = NULL; |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 193 | int num_ovls = priv->dispc_ops->get_num_ovls(); |
| 194 | int num_mgrs = priv->dispc_ops->get_num_mgrs(); |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 195 | int num_crtcs, crtc_idx, plane_idx; |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 196 | int ret; |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 197 | u32 plane_crtc_mask; |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 198 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 199 | drm_mode_config_init(dev); |
| 200 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 201 | ret = omap_modeset_init_properties(dev); |
| 202 | if (ret < 0) |
| 203 | return ret; |
| 204 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 205 | /* |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 206 | * This function creates exactly one connector, encoder, crtc, |
| 207 | * and primary plane per each connected dss-device. Each |
| 208 | * connector->encoder->crtc chain is expected to be separate |
| 209 | * and each crtc is connect to a single dss-channel. If the |
| 210 | * configuration does not match the expectations or exceeds |
| 211 | * the available resources, the configuration is rejected. |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 212 | */ |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 213 | num_crtcs = 0; |
Jyri Sarha | f1118b8 | 2017-03-24 16:47:51 +0200 | [diff] [blame] | 214 | for_each_dss_dev(dssdev) |
| 215 | if (omapdss_device_is_connected(dssdev)) |
| 216 | num_crtcs++; |
| 217 | |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 218 | if (num_crtcs > num_mgrs || num_crtcs > num_ovls || |
| 219 | num_crtcs > ARRAY_SIZE(priv->crtcs) || |
| 220 | num_crtcs > ARRAY_SIZE(priv->planes) || |
| 221 | num_crtcs > ARRAY_SIZE(priv->encoders) || |
| 222 | num_crtcs > ARRAY_SIZE(priv->connectors)) { |
| 223 | dev_err(dev->dev, "%s(): Too many connected displays\n", |
| 224 | __func__); |
| 225 | return -EINVAL; |
| 226 | } |
| 227 | |
| 228 | /* All planes can be put to any CRTC */ |
| 229 | plane_crtc_mask = (1 << num_crtcs) - 1; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 230 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 231 | dssdev = NULL; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 232 | |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 233 | crtc_idx = 0; |
| 234 | plane_idx = 0; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 235 | for_each_dss_dev(dssdev) { |
| 236 | struct drm_connector *connector; |
| 237 | struct drm_encoder *encoder; |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 238 | struct drm_plane *plane; |
| 239 | struct drm_crtc *crtc; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 240 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 241 | if (!omapdss_device_is_connected(dssdev)) |
Archit Taneja | 581382e | 2013-03-26 19:15:18 +0530 | [diff] [blame] | 242 | continue; |
Tomi Valkeinen | a7e71e7 | 2013-05-08 16:23:32 +0300 | [diff] [blame] | 243 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 244 | encoder = omap_encoder_init(dev, dssdev); |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 245 | if (!encoder) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 246 | return -ENOMEM; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 247 | |
| 248 | connector = omap_connector_init(dev, |
| 249 | get_connector_type(dssdev), dssdev, encoder); |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 250 | if (!connector) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 251 | return -ENOMEM; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 252 | |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 253 | plane = omap_plane_init(dev, plane_idx, DRM_PLANE_TYPE_PRIMARY, |
| 254 | plane_crtc_mask); |
| 255 | if (IS_ERR(plane)) |
| 256 | return PTR_ERR(plane); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 257 | |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 258 | crtc = omap_crtc_init(dev, plane, dssdev); |
| 259 | if (IS_ERR(crtc)) |
| 260 | return PTR_ERR(crtc); |
| 261 | |
| 262 | drm_mode_connector_attach_encoder(connector, encoder); |
| 263 | encoder->possible_crtcs = (1 << crtc_idx); |
| 264 | |
| 265 | priv->crtcs[priv->num_crtcs++] = crtc; |
| 266 | priv->planes[priv->num_planes++] = plane; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 267 | priv->encoders[priv->num_encoders++] = encoder; |
| 268 | priv->connectors[priv->num_connectors++] = connector; |
| 269 | |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 270 | plane_idx++; |
| 271 | crtc_idx++; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 275 | * Create normal planes for the remaining overlays: |
| 276 | */ |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 277 | for (; plane_idx < num_ovls; plane_idx++) { |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 278 | struct drm_plane *plane; |
| 279 | |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 280 | if (WARN_ON(priv->num_planes >= ARRAY_SIZE(priv->planes))) |
| 281 | return -EINVAL; |
| 282 | |
| 283 | plane = omap_plane_init(dev, plane_idx, DRM_PLANE_TYPE_OVERLAY, |
| 284 | plane_crtc_mask); |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 285 | if (IS_ERR(plane)) |
| 286 | return PTR_ERR(plane); |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 287 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 288 | priv->planes[priv->num_planes++] = plane; |
| 289 | } |
| 290 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 291 | DBG("registered %d planes, %d crtcs, %d encoders and %d connectors\n", |
| 292 | priv->num_planes, priv->num_crtcs, priv->num_encoders, |
| 293 | priv->num_connectors); |
| 294 | |
Tomi Valkeinen | 1e90711 | 2016-08-23 12:35:39 +0300 | [diff] [blame] | 295 | dev->mode_config.min_width = 8; |
| 296 | dev->mode_config.min_height = 2; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 297 | |
| 298 | /* note: eventually will need some cpu_is_omapXYZ() type stuff here |
| 299 | * to fill in these limits properly on different OMAP generations.. |
| 300 | */ |
| 301 | dev->mode_config.max_width = 2048; |
| 302 | dev->mode_config.max_height = 2048; |
| 303 | |
| 304 | dev->mode_config.funcs = &omap_mode_config_funcs; |
Laurent Pinchart | a9e6f9f | 2017-05-09 01:27:10 +0300 | [diff] [blame] | 305 | dev->mode_config.helper_private = &omap_mode_config_helper_funcs; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 306 | |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 307 | drm_mode_config_reset(dev); |
| 308 | |
Laurent Pinchart | 728ae8d | 2015-05-28 00:21:29 +0300 | [diff] [blame] | 309 | omap_drm_irq_install(dev); |
| 310 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 311 | return 0; |
| 312 | } |
| 313 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 314 | /* |
| 315 | * drm ioctl funcs |
| 316 | */ |
| 317 | |
| 318 | |
| 319 | static int ioctl_get_param(struct drm_device *dev, void *data, |
| 320 | struct drm_file *file_priv) |
| 321 | { |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 322 | struct omap_drm_private *priv = dev->dev_private; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 323 | struct drm_omap_param *args = data; |
| 324 | |
| 325 | DBG("%p: param=%llu", dev, args->param); |
| 326 | |
| 327 | switch (args->param) { |
| 328 | case OMAP_PARAM_CHIPSET_ID: |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 329 | args->value = priv->omaprev; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 330 | break; |
| 331 | default: |
| 332 | DBG("unknown parameter %lld", args->param); |
| 333 | return -EINVAL; |
| 334 | } |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static int ioctl_set_param(struct drm_device *dev, void *data, |
| 340 | struct drm_file *file_priv) |
| 341 | { |
| 342 | struct drm_omap_param *args = data; |
| 343 | |
| 344 | switch (args->param) { |
| 345 | default: |
| 346 | DBG("unknown parameter %lld", args->param); |
| 347 | return -EINVAL; |
| 348 | } |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 353 | #define OMAP_BO_USER_MASK 0x00ffffff /* flags settable by userspace */ |
| 354 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 355 | static int ioctl_gem_new(struct drm_device *dev, void *data, |
| 356 | struct drm_file *file_priv) |
| 357 | { |
| 358 | struct drm_omap_gem_new *args = data; |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 359 | u32 flags = args->flags & OMAP_BO_USER_MASK; |
| 360 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 361 | VERB("%p:%p: size=0x%08x, flags=%08x", dev, file_priv, |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 362 | args->size.bytes, flags); |
| 363 | |
| 364 | return omap_gem_new_handle(dev, file_priv, args->size, flags, |
| 365 | &args->handle); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 366 | } |
| 367 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 368 | static int ioctl_gem_info(struct drm_device *dev, void *data, |
| 369 | struct drm_file *file_priv) |
| 370 | { |
| 371 | struct drm_omap_gem_info *args = data; |
| 372 | struct drm_gem_object *obj; |
| 373 | int ret = 0; |
| 374 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 375 | VERB("%p:%p: handle=%d", dev, file_priv, args->handle); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 376 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 377 | obj = drm_gem_object_lookup(file_priv, args->handle); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 378 | if (!obj) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 379 | return -ENOENT; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 380 | |
Rob Clark | f7f9f45 | 2011-12-05 19:19:22 -0600 | [diff] [blame] | 381 | args->size = omap_gem_mmap_size(obj); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 382 | args->offset = omap_gem_mmap_offset(obj); |
| 383 | |
| 384 | drm_gem_object_unreference_unlocked(obj); |
| 385 | |
| 386 | return ret; |
| 387 | } |
| 388 | |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 389 | static const struct drm_ioctl_desc ioctls[DRM_COMMAND_END - DRM_COMMAND_BASE] = { |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 390 | DRM_IOCTL_DEF_DRV(OMAP_GET_PARAM, ioctl_get_param, |
| 391 | DRM_AUTH | DRM_RENDER_ALLOW), |
| 392 | DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, ioctl_set_param, |
| 393 | DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY), |
| 394 | DRM_IOCTL_DEF_DRV(OMAP_GEM_NEW, ioctl_gem_new, |
| 395 | DRM_AUTH | DRM_RENDER_ALLOW), |
Laurent Pinchart | d6f544f | 2017-05-09 01:27:11 +0300 | [diff] [blame^] | 396 | /* Deprecated, to be removed. */ |
| 397 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_PREP, drm_noop, |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 398 | DRM_AUTH | DRM_RENDER_ALLOW), |
Laurent Pinchart | d6f544f | 2017-05-09 01:27:11 +0300 | [diff] [blame^] | 399 | /* Deprecated, to be removed. */ |
| 400 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_FINI, drm_noop, |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 401 | DRM_AUTH | DRM_RENDER_ALLOW), |
| 402 | DRM_IOCTL_DEF_DRV(OMAP_GEM_INFO, ioctl_gem_info, |
| 403 | DRM_AUTH | DRM_RENDER_ALLOW), |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 404 | }; |
| 405 | |
| 406 | /* |
| 407 | * drm driver funcs |
| 408 | */ |
| 409 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 410 | static int dev_open(struct drm_device *dev, struct drm_file *file) |
| 411 | { |
| 412 | file->driver_priv = NULL; |
| 413 | |
| 414 | DBG("open: dev=%p, file=%p", dev, file); |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 419 | /** |
| 420 | * lastclose - clean up after all DRM clients have exited |
| 421 | * @dev: DRM device |
| 422 | * |
| 423 | * Take care of cleaning up after all DRM clients have exited. In the |
| 424 | * mode setting case, we want to restore the kernel's initial mode (just |
| 425 | * in case the last client left us in a bad state). |
| 426 | */ |
| 427 | static void dev_lastclose(struct drm_device *dev) |
| 428 | { |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 429 | int i; |
| 430 | |
Lukas Wunner | f15a66e | 2015-09-05 11:22:39 +0200 | [diff] [blame] | 431 | /* we don't support vga_switcheroo.. so just make sure the fbdev |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 432 | * mode is active |
| 433 | */ |
| 434 | struct omap_drm_private *priv = dev->dev_private; |
| 435 | int ret; |
| 436 | |
| 437 | DBG("lastclose: dev=%p", dev); |
| 438 | |
Ville Syrjälä | 0da88db | 2016-09-26 19:30:52 +0300 | [diff] [blame] | 439 | /* need to restore default rotation state.. not sure |
| 440 | * if there is a cleaner way to restore properties to |
| 441 | * default state? Maybe a flag that properties should |
| 442 | * automatically be restored to default state on |
| 443 | * lastclose? |
| 444 | */ |
| 445 | for (i = 0; i < priv->num_crtcs; i++) { |
| 446 | struct drm_crtc *crtc = priv->crtcs[i]; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 447 | |
Ville Syrjälä | 0da88db | 2016-09-26 19:30:52 +0300 | [diff] [blame] | 448 | if (!crtc->primary->rotation_property) |
| 449 | continue; |
| 450 | |
| 451 | drm_object_property_set_value(&crtc->base, |
| 452 | crtc->primary->rotation_property, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 453 | DRM_MODE_ROTATE_0); |
Ville Syrjälä | 0da88db | 2016-09-26 19:30:52 +0300 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | for (i = 0; i < priv->num_planes; i++) { |
| 457 | struct drm_plane *plane = priv->planes[i]; |
| 458 | |
| 459 | if (!plane->rotation_property) |
| 460 | continue; |
| 461 | |
| 462 | drm_object_property_set_value(&plane->base, |
| 463 | plane->rotation_property, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 464 | DRM_MODE_ROTATE_0); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 465 | } |
| 466 | |
Tomi Valkeinen | c7c1aec | 2014-09-25 19:24:26 +0000 | [diff] [blame] | 467 | if (priv->fbdev) { |
| 468 | ret = drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev); |
| 469 | if (ret) |
| 470 | DBG("failed to restore crtc mode"); |
| 471 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 472 | } |
| 473 | |
Laurent Pinchart | 78b6855 | 2012-05-17 13:27:22 +0200 | [diff] [blame] | 474 | static const struct vm_operations_struct omap_gem_vm_ops = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 475 | .fault = omap_gem_fault, |
| 476 | .open = drm_gem_vm_open, |
| 477 | .close = drm_gem_vm_close, |
| 478 | }; |
| 479 | |
Rob Clark | ff4f387 | 2012-01-16 12:51:14 -0600 | [diff] [blame] | 480 | static const struct file_operations omapdriver_fops = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 481 | .owner = THIS_MODULE, |
| 482 | .open = drm_open, |
| 483 | .unlocked_ioctl = drm_ioctl, |
| 484 | .release = drm_release, |
| 485 | .mmap = omap_gem_mmap, |
| 486 | .poll = drm_poll, |
| 487 | .read = drm_read, |
| 488 | .llseek = noop_llseek, |
Rob Clark | ff4f387 | 2012-01-16 12:51:14 -0600 | [diff] [blame] | 489 | }; |
| 490 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 491 | static struct drm_driver omap_drm_driver = { |
Tomi Valkeinen | 728fea7 | 2015-10-02 11:10:41 +0300 | [diff] [blame] | 492 | .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME | |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 493 | DRIVER_ATOMIC | DRIVER_RENDER, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 494 | .open = dev_open, |
| 495 | .lastclose = dev_lastclose, |
Andy Gross | 6169a148 | 2011-12-15 21:05:17 -0600 | [diff] [blame] | 496 | #ifdef CONFIG_DEBUG_FS |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 497 | .debugfs_init = omap_debugfs_init, |
Andy Gross | 6169a148 | 2011-12-15 21:05:17 -0600 | [diff] [blame] | 498 | #endif |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 499 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 500 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 501 | .gem_prime_export = omap_gem_prime_export, |
| 502 | .gem_prime_import = omap_gem_prime_import, |
| 503 | .gem_free_object = omap_gem_free_object, |
| 504 | .gem_vm_ops = &omap_gem_vm_ops, |
| 505 | .dumb_create = omap_gem_dumb_create, |
| 506 | .dumb_map_offset = omap_gem_dumb_map_offset, |
| 507 | .dumb_destroy = drm_gem_dumb_destroy, |
| 508 | .ioctls = ioctls, |
| 509 | .num_ioctls = DRM_OMAP_NUM_IOCTLS, |
| 510 | .fops = &omapdriver_fops, |
| 511 | .name = DRIVER_NAME, |
| 512 | .desc = DRIVER_DESC, |
| 513 | .date = DRIVER_DATE, |
| 514 | .major = DRIVER_MAJOR, |
| 515 | .minor = DRIVER_MINOR, |
| 516 | .patchlevel = DRIVER_PATCHLEVEL, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 517 | }; |
| 518 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 519 | static int pdev_probe(struct platform_device *pdev) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 520 | { |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 521 | struct omap_drm_platform_data *pdata = pdev->dev.platform_data; |
| 522 | struct omap_drm_private *priv; |
| 523 | struct drm_device *ddev; |
| 524 | unsigned int i; |
| 525 | int ret; |
| 526 | |
| 527 | DBG("%s", pdev->name); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 528 | |
Tomi Valkeinen | 591a0ac | 2013-05-23 12:07:50 +0300 | [diff] [blame] | 529 | if (omapdss_is_initialized() == false) |
| 530 | return -EPROBE_DEFER; |
| 531 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 532 | omap_crtc_pre_init(); |
| 533 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 534 | ret = omap_connect_dssdevs(); |
| 535 | if (ret) |
| 536 | goto err_crtc_uninit; |
| 537 | |
| 538 | /* Allocate and initialize the driver private structure. */ |
| 539 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 540 | if (!priv) { |
| 541 | ret = -ENOMEM; |
| 542 | goto err_disconnect_dssdevs; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 543 | } |
| 544 | |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 545 | priv->dispc_ops = dispc_get_ops(); |
| 546 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 547 | priv->omaprev = pdata->omaprev; |
| 548 | priv->wq = alloc_ordered_workqueue("omapdrm", 0); |
| 549 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 550 | spin_lock_init(&priv->list_lock); |
| 551 | INIT_LIST_HEAD(&priv->obj_list); |
| 552 | |
| 553 | /* Allocate and initialize the DRM device. */ |
| 554 | ddev = drm_dev_alloc(&omap_drm_driver, &pdev->dev); |
| 555 | if (IS_ERR(ddev)) { |
| 556 | ret = PTR_ERR(ddev); |
| 557 | goto err_free_priv; |
| 558 | } |
| 559 | |
| 560 | ddev->dev_private = priv; |
| 561 | platform_set_drvdata(pdev, ddev); |
| 562 | |
| 563 | omap_gem_init(ddev); |
| 564 | |
| 565 | ret = omap_modeset_init(ddev); |
| 566 | if (ret) { |
| 567 | dev_err(&pdev->dev, "omap_modeset_init failed: ret=%d\n", ret); |
| 568 | goto err_free_drm_dev; |
| 569 | } |
| 570 | |
| 571 | /* Initialize vblank handling, start with all CRTCs disabled. */ |
| 572 | ret = drm_vblank_init(ddev, priv->num_crtcs); |
| 573 | if (ret) { |
| 574 | dev_err(&pdev->dev, "could not init vblank\n"); |
| 575 | goto err_cleanup_modeset; |
| 576 | } |
| 577 | |
| 578 | for (i = 0; i < priv->num_crtcs; i++) |
| 579 | drm_crtc_vblank_off(priv->crtcs[i]); |
| 580 | |
| 581 | priv->fbdev = omap_fbdev_init(ddev); |
| 582 | |
| 583 | drm_kms_helper_poll_init(ddev); |
| 584 | |
| 585 | /* |
| 586 | * Register the DRM device with the core and the connectors with |
| 587 | * sysfs. |
| 588 | */ |
| 589 | ret = drm_dev_register(ddev, 0); |
| 590 | if (ret) |
| 591 | goto err_cleanup_helpers; |
| 592 | |
| 593 | return 0; |
| 594 | |
| 595 | err_cleanup_helpers: |
| 596 | drm_kms_helper_poll_fini(ddev); |
| 597 | if (priv->fbdev) |
| 598 | omap_fbdev_free(ddev); |
| 599 | err_cleanup_modeset: |
| 600 | drm_mode_config_cleanup(ddev); |
| 601 | omap_drm_irq_uninstall(ddev); |
| 602 | err_free_drm_dev: |
| 603 | omap_gem_deinit(ddev); |
| 604 | drm_dev_unref(ddev); |
| 605 | err_free_priv: |
| 606 | destroy_workqueue(priv->wq); |
| 607 | kfree(priv); |
| 608 | err_disconnect_dssdevs: |
| 609 | omap_disconnect_dssdevs(); |
| 610 | err_crtc_uninit: |
| 611 | omap_crtc_pre_uninit(); |
| 612 | return ret; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 613 | } |
| 614 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 615 | static int pdev_remove(struct platform_device *pdev) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 616 | { |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 617 | struct drm_device *ddev = platform_get_drvdata(pdev); |
| 618 | struct omap_drm_private *priv = ddev->dev_private; |
| 619 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 620 | DBG(""); |
Andy Gross | 5c13779 | 2012-03-05 10:48:39 -0600 | [diff] [blame] | 621 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 622 | drm_dev_unregister(ddev); |
| 623 | |
| 624 | drm_kms_helper_poll_fini(ddev); |
| 625 | |
| 626 | if (priv->fbdev) |
| 627 | omap_fbdev_free(ddev); |
| 628 | |
Tomi Valkeinen | 8a54aa9 | 2017-03-27 10:02:22 +0300 | [diff] [blame] | 629 | drm_atomic_helper_shutdown(ddev); |
| 630 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 631 | drm_mode_config_cleanup(ddev); |
| 632 | |
| 633 | omap_drm_irq_uninstall(ddev); |
| 634 | omap_gem_deinit(ddev); |
| 635 | |
| 636 | drm_dev_unref(ddev); |
| 637 | |
| 638 | destroy_workqueue(priv->wq); |
| 639 | kfree(priv); |
Tomi Valkeinen | 707cf58 | 2014-04-02 13:47:43 +0300 | [diff] [blame] | 640 | |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 641 | omap_disconnect_dssdevs(); |
| 642 | omap_crtc_pre_uninit(); |
Daniel Vetter | fd3c025 | 2013-12-11 11:34:26 +0100 | [diff] [blame] | 643 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 644 | return 0; |
| 645 | } |
| 646 | |
Grygorii Strashko | 8450c8d | 2015-02-26 15:57:17 +0200 | [diff] [blame] | 647 | #ifdef CONFIG_PM_SLEEP |
Tomi Valkeinen | 92bf0f9 | 2015-10-02 11:10:42 +0300 | [diff] [blame] | 648 | static int omap_drm_suspend_all_displays(void) |
| 649 | { |
| 650 | struct omap_dss_device *dssdev = NULL; |
| 651 | |
| 652 | for_each_dss_dev(dssdev) { |
| 653 | if (!dssdev->driver) |
| 654 | continue; |
| 655 | |
| 656 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { |
| 657 | dssdev->driver->disable(dssdev); |
| 658 | dssdev->activate_after_resume = true; |
| 659 | } else { |
| 660 | dssdev->activate_after_resume = false; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int omap_drm_resume_all_displays(void) |
| 668 | { |
| 669 | struct omap_dss_device *dssdev = NULL; |
| 670 | |
| 671 | for_each_dss_dev(dssdev) { |
| 672 | if (!dssdev->driver) |
| 673 | continue; |
| 674 | |
| 675 | if (dssdev->activate_after_resume) { |
| 676 | dssdev->driver->enable(dssdev); |
| 677 | dssdev->activate_after_resume = false; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 684 | static int omap_drm_suspend(struct device *dev) |
| 685 | { |
| 686 | struct drm_device *drm_dev = dev_get_drvdata(dev); |
| 687 | |
| 688 | drm_kms_helper_poll_disable(drm_dev); |
| 689 | |
Tomi Valkeinen | 92bf0f9 | 2015-10-02 11:10:42 +0300 | [diff] [blame] | 690 | drm_modeset_lock_all(drm_dev); |
| 691 | omap_drm_suspend_all_displays(); |
| 692 | drm_modeset_unlock_all(drm_dev); |
| 693 | |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | static int omap_drm_resume(struct device *dev) |
| 698 | { |
| 699 | struct drm_device *drm_dev = dev_get_drvdata(dev); |
| 700 | |
Tomi Valkeinen | 92bf0f9 | 2015-10-02 11:10:42 +0300 | [diff] [blame] | 701 | drm_modeset_lock_all(drm_dev); |
| 702 | omap_drm_resume_all_displays(); |
| 703 | drm_modeset_unlock_all(drm_dev); |
| 704 | |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 705 | drm_kms_helper_poll_enable(drm_dev); |
| 706 | |
| 707 | return omap_gem_resume(dev); |
| 708 | } |
Andy Gross | e78edba | 2012-12-19 14:53:37 -0600 | [diff] [blame] | 709 | #endif |
| 710 | |
Grygorii Strashko | 8450c8d | 2015-02-26 15:57:17 +0200 | [diff] [blame] | 711 | static SIMPLE_DEV_PM_OPS(omapdrm_pm_ops, omap_drm_suspend, omap_drm_resume); |
| 712 | |
Tomi Valkeinen | 6717cd2 | 2013-04-10 10:44:00 +0300 | [diff] [blame] | 713 | static struct platform_driver pdev = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 714 | .driver = { |
| 715 | .name = DRIVER_NAME, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 716 | .pm = &omapdrm_pm_ops, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 717 | }, |
| 718 | .probe = pdev_probe, |
| 719 | .remove = pdev_remove, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 720 | }; |
| 721 | |
Thierry Reding | e1c49bd | 2015-12-02 17:23:31 +0100 | [diff] [blame] | 722 | static struct platform_driver * const drivers[] = { |
| 723 | &omap_dmm_driver, |
| 724 | &pdev, |
| 725 | }; |
| 726 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 727 | static int __init omap_drm_init(void) |
| 728 | { |
| 729 | DBG("init"); |
Tomi Valkeinen | ea7e3a6 | 2014-04-02 14:31:50 +0300 | [diff] [blame] | 730 | |
Thierry Reding | e1c49bd | 2015-12-02 17:23:31 +0100 | [diff] [blame] | 731 | return platform_register_drivers(drivers, ARRAY_SIZE(drivers)); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | static void __exit omap_drm_fini(void) |
| 735 | { |
| 736 | DBG("fini"); |
Tomi Valkeinen | ea7e3a6 | 2014-04-02 14:31:50 +0300 | [diff] [blame] | 737 | |
Thierry Reding | e1c49bd | 2015-12-02 17:23:31 +0100 | [diff] [blame] | 738 | platform_unregister_drivers(drivers, ARRAY_SIZE(drivers)); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /* need late_initcall() so we load after dss_driver's are loaded */ |
| 742 | late_initcall(omap_drm_init); |
| 743 | module_exit(omap_drm_fini); |
| 744 | |
| 745 | MODULE_AUTHOR("Rob Clark <rob@ti.com>"); |
| 746 | MODULE_DESCRIPTION("OMAP DRM Display Driver"); |
| 747 | MODULE_ALIAS("platform:" DRIVER_NAME); |
| 748 | MODULE_LICENSE("GPL v2"); |