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