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