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 <linux/wait.h> |
| 21 | |
| 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 | |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 57 | struct omap_atomic_state_commit { |
| 58 | struct work_struct work; |
| 59 | struct drm_device *dev; |
| 60 | struct drm_atomic_state *state; |
| 61 | u32 crtcs; |
| 62 | }; |
| 63 | |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 64 | static void omap_atomic_wait_for_completion(struct drm_device *dev, |
| 65 | struct drm_atomic_state *old_state) |
| 66 | { |
| 67 | struct drm_crtc_state *old_crtc_state; |
| 68 | struct drm_crtc *crtc; |
| 69 | unsigned int i; |
| 70 | int ret; |
| 71 | |
| 72 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 73 | if (!crtc->state->enable) |
| 74 | continue; |
| 75 | |
| 76 | ret = omap_crtc_wait_pending(crtc); |
| 77 | |
| 78 | if (!ret) |
| 79 | dev_warn(dev->dev, |
| 80 | "atomic complete timeout (pipe %u)!\n", i); |
| 81 | } |
| 82 | } |
| 83 | |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 84 | static void omap_atomic_complete(struct omap_atomic_state_commit *commit) |
| 85 | { |
| 86 | struct drm_device *dev = commit->dev; |
| 87 | struct omap_drm_private *priv = dev->dev_private; |
| 88 | struct drm_atomic_state *old_state = commit->state; |
| 89 | |
| 90 | /* Apply the atomic update. */ |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 91 | priv->dispc_ops->runtime_get(); |
Laurent Pinchart | 69fb7c8 | 2015-05-28 02:09:56 +0300 | [diff] [blame] | 92 | |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 93 | drm_atomic_helper_commit_modeset_disables(dev, old_state); |
Jyri Sarha | 897145d | 2017-01-27 12:04:55 +0200 | [diff] [blame] | 94 | |
| 95 | /* With the current dss dispc implementation we have to enable |
| 96 | * the new modeset before we can commit planes. The dispc ovl |
| 97 | * configuration relies on the video mode configuration been |
| 98 | * written into the HW when the ovl configuration is |
| 99 | * calculated. |
| 100 | * |
| 101 | * This approach is not ideal because after a mode change the |
| 102 | * plane update is executed only after the first vblank |
| 103 | * interrupt. The dispc implementation should be fixed so that |
| 104 | * it is able use uncommitted drm state information. |
| 105 | */ |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 106 | drm_atomic_helper_commit_modeset_enables(dev, old_state); |
Jyri Sarha | 897145d | 2017-01-27 12:04:55 +0200 | [diff] [blame] | 107 | omap_atomic_wait_for_completion(dev, old_state); |
| 108 | |
| 109 | drm_atomic_helper_commit_planes(dev, old_state, 0); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 110 | |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 111 | omap_atomic_wait_for_completion(dev, old_state); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 112 | |
| 113 | drm_atomic_helper_cleanup_planes(dev, old_state); |
| 114 | |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 115 | priv->dispc_ops->runtime_put(); |
Laurent Pinchart | 69fb7c8 | 2015-05-28 02:09:56 +0300 | [diff] [blame] | 116 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 117 | drm_atomic_state_put(old_state); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 118 | |
| 119 | /* Complete the commit, wake up any waiter. */ |
| 120 | spin_lock(&priv->commit.lock); |
| 121 | priv->commit.pending &= ~commit->crtcs; |
| 122 | spin_unlock(&priv->commit.lock); |
| 123 | |
| 124 | wake_up_all(&priv->commit.wait); |
| 125 | |
| 126 | kfree(commit); |
| 127 | } |
| 128 | |
| 129 | static void omap_atomic_work(struct work_struct *work) |
| 130 | { |
| 131 | struct omap_atomic_state_commit *commit = |
| 132 | container_of(work, struct omap_atomic_state_commit, work); |
| 133 | |
| 134 | omap_atomic_complete(commit); |
| 135 | } |
| 136 | |
| 137 | static bool omap_atomic_is_pending(struct omap_drm_private *priv, |
| 138 | struct omap_atomic_state_commit *commit) |
| 139 | { |
| 140 | bool pending; |
| 141 | |
| 142 | spin_lock(&priv->commit.lock); |
| 143 | pending = priv->commit.pending & commit->crtcs; |
| 144 | spin_unlock(&priv->commit.lock); |
| 145 | |
| 146 | return pending; |
| 147 | } |
| 148 | |
| 149 | static int omap_atomic_commit(struct drm_device *dev, |
Maarten Lankhorst | 6fc17fb | 2016-04-26 16:11:39 +0200 | [diff] [blame] | 150 | struct drm_atomic_state *state, bool nonblock) |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 151 | { |
| 152 | struct omap_drm_private *priv = dev->dev_private; |
| 153 | struct omap_atomic_state_commit *commit; |
Daniel Vetter | 8207257 | 2016-06-02 00:06:29 +0200 | [diff] [blame] | 154 | struct drm_crtc *crtc; |
| 155 | struct drm_crtc_state *crtc_state; |
| 156 | int i, ret; |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 157 | |
| 158 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 159 | if (ret) |
| 160 | return ret; |
| 161 | |
| 162 | /* Allocate the commit object. */ |
| 163 | commit = kzalloc(sizeof(*commit), GFP_KERNEL); |
| 164 | if (commit == NULL) { |
| 165 | ret = -ENOMEM; |
| 166 | goto error; |
| 167 | } |
| 168 | |
| 169 | INIT_WORK(&commit->work, omap_atomic_work); |
| 170 | commit->dev = dev; |
| 171 | commit->state = state; |
| 172 | |
| 173 | /* Wait until all affected CRTCs have completed previous commits and |
| 174 | * mark them as pending. |
| 175 | */ |
Daniel Vetter | 8207257 | 2016-06-02 00:06:29 +0200 | [diff] [blame] | 176 | for_each_crtc_in_state(state, crtc, crtc_state, i) |
| 177 | commit->crtcs |= drm_crtc_mask(crtc); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 178 | |
| 179 | wait_event(priv->commit.wait, !omap_atomic_is_pending(priv, commit)); |
| 180 | |
| 181 | spin_lock(&priv->commit.lock); |
| 182 | priv->commit.pending |= commit->crtcs; |
| 183 | spin_unlock(&priv->commit.lock); |
| 184 | |
| 185 | /* Swap the state, this is the point of no return. */ |
Daniel Vetter | 5e84c26 | 2016-06-10 00:06:32 +0200 | [diff] [blame] | 186 | drm_atomic_helper_swap_state(state, true); |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 187 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 188 | drm_atomic_state_get(state); |
Maarten Lankhorst | 6fc17fb | 2016-04-26 16:11:39 +0200 | [diff] [blame] | 189 | if (nonblock) |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 190 | schedule_work(&commit->work); |
| 191 | else |
| 192 | omap_atomic_complete(commit); |
| 193 | |
| 194 | return 0; |
| 195 | |
| 196 | error: |
| 197 | drm_atomic_helper_cleanup_planes(dev, state); |
| 198 | return ret; |
| 199 | } |
| 200 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 201 | static const struct drm_mode_config_funcs omap_mode_config_funcs = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 202 | .fb_create = omap_framebuffer_create, |
| 203 | .output_poll_changed = omap_fb_output_poll_changed, |
Laurent Pinchart | cef77d4 | 2015-03-05 21:50:00 +0200 | [diff] [blame] | 204 | .atomic_check = drm_atomic_helper_check, |
Laurent Pinchart | 748471a5 | 2015-03-05 23:42:39 +0200 | [diff] [blame] | 205 | .atomic_commit = omap_atomic_commit, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | static int get_connector_type(struct omap_dss_device *dssdev) |
| 209 | { |
| 210 | switch (dssdev->type) { |
| 211 | case OMAP_DISPLAY_TYPE_HDMI: |
| 212 | return DRM_MODE_CONNECTOR_HDMIA; |
Tomi Valkeinen | 4635c17 | 2013-05-14 14:14:15 +0300 | [diff] [blame] | 213 | case OMAP_DISPLAY_TYPE_DVI: |
| 214 | return DRM_MODE_CONNECTOR_DVID; |
Sebastian Reichel | 4a64b90 | 2016-03-08 17:39:36 +0100 | [diff] [blame] | 215 | case OMAP_DISPLAY_TYPE_DSI: |
| 216 | return DRM_MODE_CONNECTOR_DSI; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 217 | default: |
| 218 | return DRM_MODE_CONNECTOR_Unknown; |
| 219 | } |
| 220 | } |
| 221 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 222 | static bool channel_used(struct drm_device *dev, enum omap_channel channel) |
| 223 | { |
| 224 | struct omap_drm_private *priv = dev->dev_private; |
| 225 | int i; |
| 226 | |
| 227 | for (i = 0; i < priv->num_crtcs; i++) { |
| 228 | struct drm_crtc *crtc = priv->crtcs[i]; |
| 229 | |
| 230 | if (omap_crtc_channel(crtc) == channel) |
| 231 | return true; |
| 232 | } |
| 233 | |
| 234 | return false; |
| 235 | } |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 236 | static void omap_disconnect_dssdevs(void) |
| 237 | { |
| 238 | struct omap_dss_device *dssdev = NULL; |
| 239 | |
| 240 | for_each_dss_dev(dssdev) |
| 241 | dssdev->driver->disconnect(dssdev); |
| 242 | } |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 243 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 244 | static int omap_connect_dssdevs(void) |
| 245 | { |
| 246 | int r; |
| 247 | struct omap_dss_device *dssdev = NULL; |
Peter Ujfalusi | a09d2bc | 2016-05-03 22:08:01 +0300 | [diff] [blame] | 248 | |
| 249 | if (!omapdss_stack_is_ready()) |
| 250 | return -EPROBE_DEFER; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 251 | |
| 252 | for_each_dss_dev(dssdev) { |
| 253 | r = dssdev->driver->connect(dssdev); |
| 254 | if (r == -EPROBE_DEFER) { |
| 255 | omap_dss_put_device(dssdev); |
| 256 | goto cleanup; |
| 257 | } else if (r) { |
| 258 | dev_warn(dssdev->dev, "could not connect display: %s\n", |
| 259 | dssdev->name); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 263 | return 0; |
| 264 | |
| 265 | cleanup: |
| 266 | /* |
| 267 | * if we are deferring probe, we disconnect the devices we previously |
| 268 | * connected |
| 269 | */ |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 270 | omap_disconnect_dssdevs(); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 271 | |
| 272 | return r; |
| 273 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 274 | |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 275 | static int omap_modeset_create_crtc(struct drm_device *dev, int id, |
Tomi Valkeinen | e43f2c3 | 2016-12-02 16:07:11 +0200 | [diff] [blame] | 276 | enum omap_channel channel, |
| 277 | u32 possible_crtcs) |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 278 | { |
| 279 | struct omap_drm_private *priv = dev->dev_private; |
| 280 | struct drm_plane *plane; |
| 281 | struct drm_crtc *crtc; |
| 282 | |
Tomi Valkeinen | e43f2c3 | 2016-12-02 16:07:11 +0200 | [diff] [blame] | 283 | plane = omap_plane_init(dev, id, DRM_PLANE_TYPE_PRIMARY, |
| 284 | possible_crtcs); |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 285 | if (IS_ERR(plane)) |
| 286 | return PTR_ERR(plane); |
| 287 | |
| 288 | crtc = omap_crtc_init(dev, plane, channel, id); |
| 289 | |
| 290 | BUG_ON(priv->num_crtcs >= ARRAY_SIZE(priv->crtcs)); |
| 291 | priv->crtcs[id] = crtc; |
| 292 | priv->num_crtcs++; |
| 293 | |
| 294 | priv->planes[id] = plane; |
| 295 | priv->num_planes++; |
| 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 300 | static int omap_modeset_init_properties(struct drm_device *dev) |
| 301 | { |
| 302 | struct omap_drm_private *priv = dev->dev_private; |
| 303 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 304 | priv->zorder_prop = drm_property_create_range(dev, 0, "zorder", 0, 3); |
| 305 | if (!priv->zorder_prop) |
| 306 | return -ENOMEM; |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 311 | static int omap_modeset_init(struct drm_device *dev) |
| 312 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 313 | struct omap_drm_private *priv = dev->dev_private; |
| 314 | struct omap_dss_device *dssdev = NULL; |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 315 | int num_ovls = priv->dispc_ops->get_num_ovls(); |
| 316 | int num_mgrs = priv->dispc_ops->get_num_mgrs(); |
Jyri Sarha | f1118b8 | 2017-03-24 16:47:51 +0200 | [diff] [blame^] | 317 | int num_crtcs = 0; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 318 | int i, id = 0; |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 319 | int ret; |
Tomi Valkeinen | e43f2c3 | 2016-12-02 16:07:11 +0200 | [diff] [blame] | 320 | u32 possible_crtcs; |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 321 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 322 | drm_mode_config_init(dev); |
| 323 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 324 | ret = omap_modeset_init_properties(dev); |
| 325 | if (ret < 0) |
| 326 | return ret; |
| 327 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 328 | /* |
Jyri Sarha | f1118b8 | 2017-03-24 16:47:51 +0200 | [diff] [blame^] | 329 | * Let's create one CRTC for each connected DSS device if we |
| 330 | * have display managers and overlays (for primary planes) for |
| 331 | * them. |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 332 | */ |
Jyri Sarha | f1118b8 | 2017-03-24 16:47:51 +0200 | [diff] [blame^] | 333 | for_each_dss_dev(dssdev) |
| 334 | if (omapdss_device_is_connected(dssdev)) |
| 335 | num_crtcs++; |
| 336 | |
| 337 | num_crtcs = min3(num_crtcs, num_mgrs, num_ovls); |
Tomi Valkeinen | e43f2c3 | 2016-12-02 16:07:11 +0200 | [diff] [blame] | 338 | possible_crtcs = (1 << num_crtcs) - 1; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 339 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 340 | dssdev = NULL; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 341 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 342 | for_each_dss_dev(dssdev) { |
| 343 | struct drm_connector *connector; |
| 344 | struct drm_encoder *encoder; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 345 | enum omap_channel channel; |
Tomi Valkeinen | 179df15 | 2015-10-21 16:17:23 +0300 | [diff] [blame] | 346 | struct omap_dss_device *out; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 347 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 348 | if (!omapdss_device_is_connected(dssdev)) |
Archit Taneja | 581382e | 2013-03-26 19:15:18 +0530 | [diff] [blame] | 349 | continue; |
Tomi Valkeinen | a7e71e7 | 2013-05-08 16:23:32 +0300 | [diff] [blame] | 350 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 351 | encoder = omap_encoder_init(dev, dssdev); |
| 352 | |
| 353 | if (!encoder) { |
| 354 | dev_err(dev->dev, "could not create encoder: %s\n", |
| 355 | dssdev->name); |
| 356 | return -ENOMEM; |
| 357 | } |
| 358 | |
| 359 | connector = omap_connector_init(dev, |
| 360 | get_connector_type(dssdev), dssdev, encoder); |
| 361 | |
| 362 | if (!connector) { |
| 363 | dev_err(dev->dev, "could not create connector: %s\n", |
| 364 | dssdev->name); |
| 365 | return -ENOMEM; |
| 366 | } |
| 367 | |
| 368 | BUG_ON(priv->num_encoders >= ARRAY_SIZE(priv->encoders)); |
| 369 | BUG_ON(priv->num_connectors >= ARRAY_SIZE(priv->connectors)); |
| 370 | |
| 371 | priv->encoders[priv->num_encoders++] = encoder; |
| 372 | priv->connectors[priv->num_connectors++] = connector; |
| 373 | |
| 374 | drm_mode_connector_attach_encoder(connector, encoder); |
| 375 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 376 | /* |
Jyri Sarha | f1118b8 | 2017-03-24 16:47:51 +0200 | [diff] [blame^] | 377 | * if we have reached the limit of the crtcs we can |
| 378 | * create, let's not try to create a crtc for this |
| 379 | * panel/encoder and onwards. |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 380 | */ |
| 381 | if (id == num_crtcs) |
| 382 | continue; |
| 383 | |
| 384 | /* |
| 385 | * get the recommended DISPC channel for this encoder. For now, |
| 386 | * we only try to get create a crtc out of the recommended, the |
| 387 | * other possible channels to which the encoder can connect are |
| 388 | * not considered. |
| 389 | */ |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 390 | |
Tomi Valkeinen | 179df15 | 2015-10-21 16:17:23 +0300 | [diff] [blame] | 391 | out = omapdss_find_output_from_display(dssdev); |
| 392 | channel = out->dispc_channel; |
| 393 | omap_dss_put_device(out); |
| 394 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 395 | /* |
| 396 | * if this channel hasn't already been taken by a previously |
| 397 | * allocated crtc, we create a new crtc for it |
| 398 | */ |
| 399 | if (!channel_used(dev, channel)) { |
Tomi Valkeinen | e43f2c3 | 2016-12-02 16:07:11 +0200 | [diff] [blame] | 400 | ret = omap_modeset_create_crtc(dev, id, channel, |
| 401 | possible_crtcs); |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 402 | if (ret < 0) { |
| 403 | dev_err(dev->dev, |
| 404 | "could not create CRTC (channel %u)\n", |
| 405 | channel); |
| 406 | return ret; |
| 407 | } |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 408 | |
| 409 | id++; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /* |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 414 | * Create normal planes for the remaining overlays: |
| 415 | */ |
| 416 | for (; id < num_ovls; id++) { |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 417 | struct drm_plane *plane; |
| 418 | |
Tomi Valkeinen | e43f2c3 | 2016-12-02 16:07:11 +0200 | [diff] [blame] | 419 | plane = omap_plane_init(dev, id, DRM_PLANE_TYPE_OVERLAY, |
| 420 | possible_crtcs); |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 421 | if (IS_ERR(plane)) |
| 422 | return PTR_ERR(plane); |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 423 | |
| 424 | BUG_ON(priv->num_planes >= ARRAY_SIZE(priv->planes)); |
| 425 | priv->planes[priv->num_planes++] = plane; |
| 426 | } |
| 427 | |
Jyri Sarha | f1118b8 | 2017-03-24 16:47:51 +0200 | [diff] [blame^] | 428 | /* |
| 429 | * populate the the possible_crtcs field for all the encoders |
| 430 | * we created. |
| 431 | */ |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 432 | for (i = 0; i < priv->num_encoders; i++) { |
| 433 | struct drm_encoder *encoder = priv->encoders[i]; |
| 434 | struct omap_dss_device *dssdev = |
| 435 | omap_encoder_get_dssdev(encoder); |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 436 | struct omap_dss_device *output; |
Tomi Valkeinen | be8e8e1 | 2013-04-23 15:35:35 +0300 | [diff] [blame] | 437 | |
| 438 | output = omapdss_find_output_from_display(dssdev); |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 439 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 440 | /* figure out which crtc's we can connect the encoder to: */ |
| 441 | encoder->possible_crtcs = 0; |
| 442 | for (id = 0; id < priv->num_crtcs; id++) { |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 443 | struct drm_crtc *crtc = priv->crtcs[id]; |
| 444 | enum omap_channel crtc_channel; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 445 | |
| 446 | crtc_channel = omap_crtc_channel(crtc); |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 447 | |
Tomi Valkeinen | 1733729 | 2014-09-03 19:25:49 +0000 | [diff] [blame] | 448 | if (output->dispc_channel == crtc_channel) { |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 449 | encoder->possible_crtcs |= (1 << id); |
Tomi Valkeinen | 1733729 | 2014-09-03 19:25:49 +0000 | [diff] [blame] | 450 | break; |
| 451 | } |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 452 | } |
Tomi Valkeinen | 820caab | 2013-04-25 14:53:18 +0300 | [diff] [blame] | 453 | |
| 454 | omap_dss_put_device(output); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 455 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 456 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 457 | DBG("registered %d planes, %d crtcs, %d encoders and %d connectors\n", |
| 458 | priv->num_planes, priv->num_crtcs, priv->num_encoders, |
| 459 | priv->num_connectors); |
| 460 | |
Tomi Valkeinen | 1e90711 | 2016-08-23 12:35:39 +0300 | [diff] [blame] | 461 | dev->mode_config.min_width = 8; |
| 462 | dev->mode_config.min_height = 2; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 463 | |
| 464 | /* note: eventually will need some cpu_is_omapXYZ() type stuff here |
| 465 | * to fill in these limits properly on different OMAP generations.. |
| 466 | */ |
| 467 | dev->mode_config.max_width = 2048; |
| 468 | dev->mode_config.max_height = 2048; |
| 469 | |
| 470 | dev->mode_config.funcs = &omap_mode_config_funcs; |
| 471 | |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 472 | drm_mode_config_reset(dev); |
| 473 | |
Laurent Pinchart | 728ae8d | 2015-05-28 00:21:29 +0300 | [diff] [blame] | 474 | omap_drm_irq_install(dev); |
| 475 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 476 | return 0; |
| 477 | } |
| 478 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 479 | /* |
| 480 | * drm ioctl funcs |
| 481 | */ |
| 482 | |
| 483 | |
| 484 | static int ioctl_get_param(struct drm_device *dev, void *data, |
| 485 | struct drm_file *file_priv) |
| 486 | { |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 487 | struct omap_drm_private *priv = dev->dev_private; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 488 | struct drm_omap_param *args = data; |
| 489 | |
| 490 | DBG("%p: param=%llu", dev, args->param); |
| 491 | |
| 492 | switch (args->param) { |
| 493 | case OMAP_PARAM_CHIPSET_ID: |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 494 | args->value = priv->omaprev; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 495 | break; |
| 496 | default: |
| 497 | DBG("unknown parameter %lld", args->param); |
| 498 | return -EINVAL; |
| 499 | } |
| 500 | |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | static int ioctl_set_param(struct drm_device *dev, void *data, |
| 505 | struct drm_file *file_priv) |
| 506 | { |
| 507 | struct drm_omap_param *args = data; |
| 508 | |
| 509 | switch (args->param) { |
| 510 | default: |
| 511 | DBG("unknown parameter %lld", args->param); |
| 512 | return -EINVAL; |
| 513 | } |
| 514 | |
| 515 | return 0; |
| 516 | } |
| 517 | |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 518 | #define OMAP_BO_USER_MASK 0x00ffffff /* flags settable by userspace */ |
| 519 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 520 | static int ioctl_gem_new(struct drm_device *dev, void *data, |
| 521 | struct drm_file *file_priv) |
| 522 | { |
| 523 | struct drm_omap_gem_new *args = data; |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 524 | u32 flags = args->flags & OMAP_BO_USER_MASK; |
| 525 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 526 | VERB("%p:%p: size=0x%08x, flags=%08x", dev, file_priv, |
Laurent Pinchart | ef3f4e9 | 2015-12-14 22:39:36 +0200 | [diff] [blame] | 527 | args->size.bytes, flags); |
| 528 | |
| 529 | return omap_gem_new_handle(dev, file_priv, args->size, flags, |
| 530 | &args->handle); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | static int ioctl_gem_cpu_prep(struct drm_device *dev, void *data, |
| 534 | struct drm_file *file_priv) |
| 535 | { |
| 536 | struct drm_omap_gem_cpu_prep *args = data; |
| 537 | struct drm_gem_object *obj; |
| 538 | int ret; |
| 539 | |
| 540 | VERB("%p:%p: handle=%d, op=%x", dev, file_priv, args->handle, args->op); |
| 541 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 542 | obj = drm_gem_object_lookup(file_priv, args->handle); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 543 | if (!obj) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 544 | return -ENOENT; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 545 | |
| 546 | ret = omap_gem_op_sync(obj, args->op); |
| 547 | |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 548 | if (!ret) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 549 | ret = omap_gem_op_start(obj, args->op); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 550 | |
| 551 | drm_gem_object_unreference_unlocked(obj); |
| 552 | |
| 553 | return ret; |
| 554 | } |
| 555 | |
| 556 | static int ioctl_gem_cpu_fini(struct drm_device *dev, void *data, |
| 557 | struct drm_file *file_priv) |
| 558 | { |
| 559 | struct drm_omap_gem_cpu_fini *args = data; |
| 560 | struct drm_gem_object *obj; |
| 561 | int ret; |
| 562 | |
| 563 | VERB("%p:%p: handle=%d", dev, file_priv, args->handle); |
| 564 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 565 | obj = drm_gem_object_lookup(file_priv, args->handle); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 566 | if (!obj) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 567 | return -ENOENT; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 568 | |
| 569 | /* XXX flushy, flushy */ |
| 570 | ret = 0; |
| 571 | |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 572 | if (!ret) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 573 | ret = omap_gem_op_finish(obj, args->op); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 574 | |
| 575 | drm_gem_object_unreference_unlocked(obj); |
| 576 | |
| 577 | return ret; |
| 578 | } |
| 579 | |
| 580 | static int ioctl_gem_info(struct drm_device *dev, void *data, |
| 581 | struct drm_file *file_priv) |
| 582 | { |
| 583 | struct drm_omap_gem_info *args = data; |
| 584 | struct drm_gem_object *obj; |
| 585 | int ret = 0; |
| 586 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 587 | VERB("%p:%p: handle=%d", dev, file_priv, args->handle); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 588 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 589 | obj = drm_gem_object_lookup(file_priv, args->handle); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 590 | if (!obj) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 591 | return -ENOENT; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 592 | |
Rob Clark | f7f9f45 | 2011-12-05 19:19:22 -0600 | [diff] [blame] | 593 | args->size = omap_gem_mmap_size(obj); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 594 | args->offset = omap_gem_mmap_offset(obj); |
| 595 | |
| 596 | drm_gem_object_unreference_unlocked(obj); |
| 597 | |
| 598 | return ret; |
| 599 | } |
| 600 | |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 601 | 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] | 602 | DRM_IOCTL_DEF_DRV(OMAP_GET_PARAM, ioctl_get_param, |
| 603 | DRM_AUTH | DRM_RENDER_ALLOW), |
| 604 | DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, ioctl_set_param, |
| 605 | DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY), |
| 606 | DRM_IOCTL_DEF_DRV(OMAP_GEM_NEW, ioctl_gem_new, |
| 607 | DRM_AUTH | DRM_RENDER_ALLOW), |
| 608 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_PREP, ioctl_gem_cpu_prep, |
| 609 | DRM_AUTH | DRM_RENDER_ALLOW), |
| 610 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_FINI, ioctl_gem_cpu_fini, |
| 611 | DRM_AUTH | DRM_RENDER_ALLOW), |
| 612 | DRM_IOCTL_DEF_DRV(OMAP_GEM_INFO, ioctl_gem_info, |
| 613 | DRM_AUTH | DRM_RENDER_ALLOW), |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 614 | }; |
| 615 | |
| 616 | /* |
| 617 | * drm driver funcs |
| 618 | */ |
| 619 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 620 | static int dev_open(struct drm_device *dev, struct drm_file *file) |
| 621 | { |
| 622 | file->driver_priv = NULL; |
| 623 | |
| 624 | DBG("open: dev=%p, file=%p", dev, file); |
| 625 | |
| 626 | return 0; |
| 627 | } |
| 628 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 629 | /** |
| 630 | * lastclose - clean up after all DRM clients have exited |
| 631 | * @dev: DRM device |
| 632 | * |
| 633 | * Take care of cleaning up after all DRM clients have exited. In the |
| 634 | * mode setting case, we want to restore the kernel's initial mode (just |
| 635 | * in case the last client left us in a bad state). |
| 636 | */ |
| 637 | static void dev_lastclose(struct drm_device *dev) |
| 638 | { |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 639 | int i; |
| 640 | |
Lukas Wunner | f15a66e | 2015-09-05 11:22:39 +0200 | [diff] [blame] | 641 | /* we don't support vga_switcheroo.. so just make sure the fbdev |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 642 | * mode is active |
| 643 | */ |
| 644 | struct omap_drm_private *priv = dev->dev_private; |
| 645 | int ret; |
| 646 | |
| 647 | DBG("lastclose: dev=%p", dev); |
| 648 | |
Ville Syrjälä | 0da88db | 2016-09-26 19:30:52 +0300 | [diff] [blame] | 649 | /* need to restore default rotation state.. not sure |
| 650 | * if there is a cleaner way to restore properties to |
| 651 | * default state? Maybe a flag that properties should |
| 652 | * automatically be restored to default state on |
| 653 | * lastclose? |
| 654 | */ |
| 655 | for (i = 0; i < priv->num_crtcs; i++) { |
| 656 | struct drm_crtc *crtc = priv->crtcs[i]; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 657 | |
Ville Syrjälä | 0da88db | 2016-09-26 19:30:52 +0300 | [diff] [blame] | 658 | if (!crtc->primary->rotation_property) |
| 659 | continue; |
| 660 | |
| 661 | drm_object_property_set_value(&crtc->base, |
| 662 | crtc->primary->rotation_property, |
| 663 | DRM_ROTATE_0); |
| 664 | } |
| 665 | |
| 666 | for (i = 0; i < priv->num_planes; i++) { |
| 667 | struct drm_plane *plane = priv->planes[i]; |
| 668 | |
| 669 | if (!plane->rotation_property) |
| 670 | continue; |
| 671 | |
| 672 | drm_object_property_set_value(&plane->base, |
| 673 | plane->rotation_property, |
| 674 | DRM_ROTATE_0); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 675 | } |
| 676 | |
Tomi Valkeinen | c7c1aec | 2014-09-25 19:24:26 +0000 | [diff] [blame] | 677 | if (priv->fbdev) { |
| 678 | ret = drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev); |
| 679 | if (ret) |
| 680 | DBG("failed to restore crtc mode"); |
| 681 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 682 | } |
| 683 | |
Laurent Pinchart | 78b6855 | 2012-05-17 13:27:22 +0200 | [diff] [blame] | 684 | static const struct vm_operations_struct omap_gem_vm_ops = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 685 | .fault = omap_gem_fault, |
| 686 | .open = drm_gem_vm_open, |
| 687 | .close = drm_gem_vm_close, |
| 688 | }; |
| 689 | |
Rob Clark | ff4f387 | 2012-01-16 12:51:14 -0600 | [diff] [blame] | 690 | static const struct file_operations omapdriver_fops = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 691 | .owner = THIS_MODULE, |
| 692 | .open = drm_open, |
| 693 | .unlocked_ioctl = drm_ioctl, |
| 694 | .release = drm_release, |
| 695 | .mmap = omap_gem_mmap, |
| 696 | .poll = drm_poll, |
| 697 | .read = drm_read, |
| 698 | .llseek = noop_llseek, |
Rob Clark | ff4f387 | 2012-01-16 12:51:14 -0600 | [diff] [blame] | 699 | }; |
| 700 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 701 | static struct drm_driver omap_drm_driver = { |
Tomi Valkeinen | 728fea7 | 2015-10-02 11:10:41 +0300 | [diff] [blame] | 702 | .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME | |
Hemant Hariyani | 5f6ab8c | 2016-06-07 13:23:19 -0500 | [diff] [blame] | 703 | DRIVER_ATOMIC | DRIVER_RENDER, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 704 | .open = dev_open, |
| 705 | .lastclose = dev_lastclose, |
Andy Gross | 6169a148 | 2011-12-15 21:05:17 -0600 | [diff] [blame] | 706 | #ifdef CONFIG_DEBUG_FS |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 707 | .debugfs_init = omap_debugfs_init, |
Andy Gross | 6169a148 | 2011-12-15 21:05:17 -0600 | [diff] [blame] | 708 | #endif |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 709 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 710 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 711 | .gem_prime_export = omap_gem_prime_export, |
| 712 | .gem_prime_import = omap_gem_prime_import, |
| 713 | .gem_free_object = omap_gem_free_object, |
| 714 | .gem_vm_ops = &omap_gem_vm_ops, |
| 715 | .dumb_create = omap_gem_dumb_create, |
| 716 | .dumb_map_offset = omap_gem_dumb_map_offset, |
| 717 | .dumb_destroy = drm_gem_dumb_destroy, |
| 718 | .ioctls = ioctls, |
| 719 | .num_ioctls = DRM_OMAP_NUM_IOCTLS, |
| 720 | .fops = &omapdriver_fops, |
| 721 | .name = DRIVER_NAME, |
| 722 | .desc = DRIVER_DESC, |
| 723 | .date = DRIVER_DATE, |
| 724 | .major = DRIVER_MAJOR, |
| 725 | .minor = DRIVER_MINOR, |
| 726 | .patchlevel = DRIVER_PATCHLEVEL, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 727 | }; |
| 728 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 729 | static int pdev_probe(struct platform_device *pdev) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 730 | { |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 731 | struct omap_drm_platform_data *pdata = pdev->dev.platform_data; |
| 732 | struct omap_drm_private *priv; |
| 733 | struct drm_device *ddev; |
| 734 | unsigned int i; |
| 735 | int ret; |
| 736 | |
| 737 | DBG("%s", pdev->name); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 738 | |
Tomi Valkeinen | 591a0ac | 2013-05-23 12:07:50 +0300 | [diff] [blame] | 739 | if (omapdss_is_initialized() == false) |
| 740 | return -EPROBE_DEFER; |
| 741 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 742 | omap_crtc_pre_init(); |
| 743 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 744 | ret = omap_connect_dssdevs(); |
| 745 | if (ret) |
| 746 | goto err_crtc_uninit; |
| 747 | |
| 748 | /* Allocate and initialize the driver private structure. */ |
| 749 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 750 | if (!priv) { |
| 751 | ret = -ENOMEM; |
| 752 | goto err_disconnect_dssdevs; |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 753 | } |
| 754 | |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 755 | priv->dispc_ops = dispc_get_ops(); |
| 756 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 757 | priv->omaprev = pdata->omaprev; |
| 758 | priv->wq = alloc_ordered_workqueue("omapdrm", 0); |
| 759 | |
| 760 | init_waitqueue_head(&priv->commit.wait); |
| 761 | spin_lock_init(&priv->commit.lock); |
| 762 | spin_lock_init(&priv->list_lock); |
| 763 | INIT_LIST_HEAD(&priv->obj_list); |
| 764 | |
| 765 | /* Allocate and initialize the DRM device. */ |
| 766 | ddev = drm_dev_alloc(&omap_drm_driver, &pdev->dev); |
| 767 | if (IS_ERR(ddev)) { |
| 768 | ret = PTR_ERR(ddev); |
| 769 | goto err_free_priv; |
| 770 | } |
| 771 | |
| 772 | ddev->dev_private = priv; |
| 773 | platform_set_drvdata(pdev, ddev); |
| 774 | |
| 775 | omap_gem_init(ddev); |
| 776 | |
| 777 | ret = omap_modeset_init(ddev); |
| 778 | if (ret) { |
| 779 | dev_err(&pdev->dev, "omap_modeset_init failed: ret=%d\n", ret); |
| 780 | goto err_free_drm_dev; |
| 781 | } |
| 782 | |
| 783 | /* Initialize vblank handling, start with all CRTCs disabled. */ |
| 784 | ret = drm_vblank_init(ddev, priv->num_crtcs); |
| 785 | if (ret) { |
| 786 | dev_err(&pdev->dev, "could not init vblank\n"); |
| 787 | goto err_cleanup_modeset; |
| 788 | } |
| 789 | |
| 790 | for (i = 0; i < priv->num_crtcs; i++) |
| 791 | drm_crtc_vblank_off(priv->crtcs[i]); |
| 792 | |
| 793 | priv->fbdev = omap_fbdev_init(ddev); |
| 794 | |
| 795 | drm_kms_helper_poll_init(ddev); |
| 796 | |
| 797 | /* |
| 798 | * Register the DRM device with the core and the connectors with |
| 799 | * sysfs. |
| 800 | */ |
| 801 | ret = drm_dev_register(ddev, 0); |
| 802 | if (ret) |
| 803 | goto err_cleanup_helpers; |
| 804 | |
| 805 | return 0; |
| 806 | |
| 807 | err_cleanup_helpers: |
| 808 | drm_kms_helper_poll_fini(ddev); |
| 809 | if (priv->fbdev) |
| 810 | omap_fbdev_free(ddev); |
| 811 | err_cleanup_modeset: |
| 812 | drm_mode_config_cleanup(ddev); |
| 813 | omap_drm_irq_uninstall(ddev); |
| 814 | err_free_drm_dev: |
| 815 | omap_gem_deinit(ddev); |
| 816 | drm_dev_unref(ddev); |
| 817 | err_free_priv: |
| 818 | destroy_workqueue(priv->wq); |
| 819 | kfree(priv); |
| 820 | err_disconnect_dssdevs: |
| 821 | omap_disconnect_dssdevs(); |
| 822 | err_crtc_uninit: |
| 823 | omap_crtc_pre_uninit(); |
| 824 | return ret; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 825 | } |
| 826 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 827 | static int pdev_remove(struct platform_device *pdev) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 828 | { |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 829 | struct drm_device *ddev = platform_get_drvdata(pdev); |
| 830 | struct omap_drm_private *priv = ddev->dev_private; |
| 831 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 832 | DBG(""); |
Andy Gross | 5c13779 | 2012-03-05 10:48:39 -0600 | [diff] [blame] | 833 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 834 | drm_dev_unregister(ddev); |
| 835 | |
| 836 | drm_kms_helper_poll_fini(ddev); |
| 837 | |
| 838 | if (priv->fbdev) |
| 839 | omap_fbdev_free(ddev); |
| 840 | |
Tomi Valkeinen | 8a54aa9 | 2017-03-27 10:02:22 +0300 | [diff] [blame] | 841 | drm_atomic_helper_shutdown(ddev); |
| 842 | |
Laurent Pinchart | 2f95bc6 | 2016-12-12 11:28:47 +0200 | [diff] [blame] | 843 | drm_mode_config_cleanup(ddev); |
| 844 | |
| 845 | omap_drm_irq_uninstall(ddev); |
| 846 | omap_gem_deinit(ddev); |
| 847 | |
| 848 | drm_dev_unref(ddev); |
| 849 | |
| 850 | destroy_workqueue(priv->wq); |
| 851 | kfree(priv); |
Tomi Valkeinen | 707cf58 | 2014-04-02 13:47:43 +0300 | [diff] [blame] | 852 | |
Archit Taneja | cc823bd | 2014-01-02 14:49:52 +0530 | [diff] [blame] | 853 | omap_disconnect_dssdevs(); |
| 854 | omap_crtc_pre_uninit(); |
Daniel Vetter | fd3c025 | 2013-12-11 11:34:26 +0100 | [diff] [blame] | 855 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 856 | return 0; |
| 857 | } |
| 858 | |
Grygorii Strashko | 8450c8d | 2015-02-26 15:57:17 +0200 | [diff] [blame] | 859 | #ifdef CONFIG_PM_SLEEP |
Tomi Valkeinen | 92bf0f9 | 2015-10-02 11:10:42 +0300 | [diff] [blame] | 860 | static int omap_drm_suspend_all_displays(void) |
| 861 | { |
| 862 | struct omap_dss_device *dssdev = NULL; |
| 863 | |
| 864 | for_each_dss_dev(dssdev) { |
| 865 | if (!dssdev->driver) |
| 866 | continue; |
| 867 | |
| 868 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { |
| 869 | dssdev->driver->disable(dssdev); |
| 870 | dssdev->activate_after_resume = true; |
| 871 | } else { |
| 872 | dssdev->activate_after_resume = false; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | static int omap_drm_resume_all_displays(void) |
| 880 | { |
| 881 | struct omap_dss_device *dssdev = NULL; |
| 882 | |
| 883 | for_each_dss_dev(dssdev) { |
| 884 | if (!dssdev->driver) |
| 885 | continue; |
| 886 | |
| 887 | if (dssdev->activate_after_resume) { |
| 888 | dssdev->driver->enable(dssdev); |
| 889 | dssdev->activate_after_resume = false; |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | return 0; |
| 894 | } |
| 895 | |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 896 | static int omap_drm_suspend(struct device *dev) |
| 897 | { |
| 898 | struct drm_device *drm_dev = dev_get_drvdata(dev); |
| 899 | |
| 900 | drm_kms_helper_poll_disable(drm_dev); |
| 901 | |
Tomi Valkeinen | 92bf0f9 | 2015-10-02 11:10:42 +0300 | [diff] [blame] | 902 | drm_modeset_lock_all(drm_dev); |
| 903 | omap_drm_suspend_all_displays(); |
| 904 | drm_modeset_unlock_all(drm_dev); |
| 905 | |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 906 | return 0; |
| 907 | } |
| 908 | |
| 909 | static int omap_drm_resume(struct device *dev) |
| 910 | { |
| 911 | struct drm_device *drm_dev = dev_get_drvdata(dev); |
| 912 | |
Tomi Valkeinen | 92bf0f9 | 2015-10-02 11:10:42 +0300 | [diff] [blame] | 913 | drm_modeset_lock_all(drm_dev); |
| 914 | omap_drm_resume_all_displays(); |
| 915 | drm_modeset_unlock_all(drm_dev); |
| 916 | |
Tomi Valkeinen | ccd7b5e | 2014-11-14 15:18:28 +0200 | [diff] [blame] | 917 | drm_kms_helper_poll_enable(drm_dev); |
| 918 | |
| 919 | return omap_gem_resume(dev); |
| 920 | } |
Andy Gross | e78edba | 2012-12-19 14:53:37 -0600 | [diff] [blame] | 921 | #endif |
| 922 | |
Grygorii Strashko | 8450c8d | 2015-02-26 15:57:17 +0200 | [diff] [blame] | 923 | static SIMPLE_DEV_PM_OPS(omapdrm_pm_ops, omap_drm_suspend, omap_drm_resume); |
| 924 | |
Tomi Valkeinen | 6717cd2 | 2013-04-10 10:44:00 +0300 | [diff] [blame] | 925 | static struct platform_driver pdev = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 926 | .driver = { |
| 927 | .name = DRIVER_NAME, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 928 | .pm = &omapdrm_pm_ops, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 929 | }, |
| 930 | .probe = pdev_probe, |
| 931 | .remove = pdev_remove, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 932 | }; |
| 933 | |
Thierry Reding | e1c49bd | 2015-12-02 17:23:31 +0100 | [diff] [blame] | 934 | static struct platform_driver * const drivers[] = { |
| 935 | &omap_dmm_driver, |
| 936 | &pdev, |
| 937 | }; |
| 938 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 939 | static int __init omap_drm_init(void) |
| 940 | { |
| 941 | DBG("init"); |
Tomi Valkeinen | ea7e3a6 | 2014-04-02 14:31:50 +0300 | [diff] [blame] | 942 | |
Thierry Reding | e1c49bd | 2015-12-02 17:23:31 +0100 | [diff] [blame] | 943 | return platform_register_drivers(drivers, ARRAY_SIZE(drivers)); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | static void __exit omap_drm_fini(void) |
| 947 | { |
| 948 | DBG("fini"); |
Tomi Valkeinen | ea7e3a6 | 2014-04-02 14:31:50 +0300 | [diff] [blame] | 949 | |
Thierry Reding | e1c49bd | 2015-12-02 17:23:31 +0100 | [diff] [blame] | 950 | platform_unregister_drivers(drivers, ARRAY_SIZE(drivers)); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | /* need late_initcall() so we load after dss_driver's are loaded */ |
| 954 | late_initcall(omap_drm_init); |
| 955 | module_exit(omap_drm_fini); |
| 956 | |
| 957 | MODULE_AUTHOR("Rob Clark <rob@ti.com>"); |
| 958 | MODULE_DESCRIPTION("OMAP DRM Display Driver"); |
| 959 | MODULE_ALIAS("platform:" DRIVER_NAME); |
| 960 | MODULE_LICENSE("GPL v2"); |