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