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_crtc.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 | |
| 20 | #include "omap_drv.h" |
| 21 | |
Andy Gross | b9ed9f0 | 2012-10-16 00:17:40 -0500 | [diff] [blame] | 22 | #include <drm/drm_mode.h> |
Daniel Vetter | 3cb9ae4 | 2014-10-29 10:03:57 +0100 | [diff] [blame] | 23 | #include <drm/drm_plane_helper.h> |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 24 | #include "drm_crtc.h" |
| 25 | #include "drm_crtc_helper.h" |
| 26 | |
| 27 | #define to_omap_crtc(x) container_of(x, struct omap_crtc, base) |
| 28 | |
| 29 | struct omap_crtc { |
| 30 | struct drm_crtc base; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 31 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 32 | const char *name; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 33 | int pipe; |
| 34 | enum omap_channel channel; |
| 35 | struct omap_overlay_manager_info info; |
Tomi Valkeinen | c7aef12 | 2014-04-03 16:30:03 +0300 | [diff] [blame] | 36 | struct drm_encoder *current_encoder; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Temporary: eventually this will go away, but it is needed |
| 40 | * for now to keep the output's happy. (They only need |
| 41 | * mgr->id.) Eventually this will be replaced w/ something |
| 42 | * more common-panel-framework-y |
| 43 | */ |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 44 | struct omap_overlay_manager *mgr; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 45 | |
| 46 | struct omap_video_timings timings; |
| 47 | bool enabled; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 48 | |
| 49 | struct omap_drm_apply apply; |
| 50 | |
| 51 | struct omap_drm_irq apply_irq; |
| 52 | struct omap_drm_irq error_irq; |
| 53 | |
| 54 | /* list of in-progress apply's: */ |
| 55 | struct list_head pending_applies; |
| 56 | |
| 57 | /* list of queued apply's: */ |
| 58 | struct list_head queued_applies; |
| 59 | |
| 60 | /* for handling queued and in-progress applies: */ |
| 61 | struct work_struct apply_work; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 62 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 63 | /* if there is a pending flip, these will be non-null: */ |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 64 | struct drm_pending_vblank_event *event; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 65 | struct drm_framebuffer *old_fb; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 66 | |
| 67 | /* for handling page flips without caring about what |
| 68 | * the callback is called from. Possibly we should just |
| 69 | * make omap_gem always call the cb from the worker so |
| 70 | * we don't have to care about this.. |
| 71 | * |
| 72 | * XXX maybe fold into apply_work?? |
| 73 | */ |
| 74 | struct work_struct page_flip_work; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 75 | }; |
| 76 | |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame^] | 77 | /* ----------------------------------------------------------------------------- |
| 78 | * Helper Functions |
| 79 | */ |
| 80 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 81 | uint32_t pipe2vbl(struct drm_crtc *crtc) |
| 82 | { |
| 83 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 84 | |
| 85 | return dispc_mgr_get_vsync_irq(omap_crtc->channel); |
| 86 | } |
| 87 | |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame^] | 88 | const struct omap_video_timings *omap_crtc_timings(struct drm_crtc *crtc) |
| 89 | { |
| 90 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 91 | return &omap_crtc->timings; |
| 92 | } |
| 93 | |
| 94 | enum omap_channel omap_crtc_channel(struct drm_crtc *crtc) |
| 95 | { |
| 96 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 97 | return omap_crtc->channel; |
| 98 | } |
| 99 | |
| 100 | /* ----------------------------------------------------------------------------- |
| 101 | * DSS Manager Functions |
| 102 | */ |
| 103 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 104 | /* |
| 105 | * Manager-ops, callbacks from output when they need to configure |
| 106 | * the upstream part of the video pipe. |
| 107 | * |
| 108 | * Most of these we can ignore until we add support for command-mode |
| 109 | * panels.. for video-mode the crtc-helpers already do an adequate |
| 110 | * job of sequencing the setup of the video pipe in the proper order |
| 111 | */ |
| 112 | |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 113 | /* ovl-mgr-id -> crtc */ |
| 114 | static struct omap_crtc *omap_crtcs[8]; |
| 115 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 116 | /* we can probably ignore these until we support command-mode panels: */ |
Tomi Valkeinen | a7e71e7 | 2013-05-08 16:23:32 +0300 | [diff] [blame] | 117 | static int omap_crtc_connect(struct omap_overlay_manager *mgr, |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 118 | struct omap_dss_device *dst) |
Tomi Valkeinen | a7e71e7 | 2013-05-08 16:23:32 +0300 | [diff] [blame] | 119 | { |
| 120 | if (mgr->output) |
| 121 | return -EINVAL; |
| 122 | |
| 123 | if ((mgr->supported_outputs & dst->id) == 0) |
| 124 | return -EINVAL; |
| 125 | |
| 126 | dst->manager = mgr; |
| 127 | mgr->output = dst; |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | static void omap_crtc_disconnect(struct omap_overlay_manager *mgr, |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 133 | struct omap_dss_device *dst) |
Tomi Valkeinen | a7e71e7 | 2013-05-08 16:23:32 +0300 | [diff] [blame] | 134 | { |
| 135 | mgr->output->manager = NULL; |
| 136 | mgr->output = NULL; |
| 137 | } |
| 138 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 139 | static void omap_crtc_start_update(struct omap_overlay_manager *mgr) |
| 140 | { |
| 141 | } |
| 142 | |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 143 | /* Called only from CRTC pre_apply and suspend/resume handlers. */ |
| 144 | static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable) |
| 145 | { |
| 146 | struct drm_device *dev = crtc->dev; |
| 147 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 148 | enum omap_channel channel = omap_crtc->channel; |
| 149 | struct omap_irq_wait *wait; |
| 150 | u32 framedone_irq, vsync_irq; |
| 151 | int ret; |
| 152 | |
| 153 | if (dispc_mgr_is_enabled(channel) == enable) |
| 154 | return; |
| 155 | |
| 156 | /* |
| 157 | * Digit output produces some sync lost interrupts during the first |
| 158 | * frame when enabling, so we need to ignore those. |
| 159 | */ |
| 160 | omap_irq_unregister(crtc->dev, &omap_crtc->error_irq); |
| 161 | |
| 162 | framedone_irq = dispc_mgr_get_framedone_irq(channel); |
| 163 | vsync_irq = dispc_mgr_get_vsync_irq(channel); |
| 164 | |
| 165 | if (enable) { |
| 166 | wait = omap_irq_wait_init(dev, vsync_irq, 1); |
| 167 | } else { |
| 168 | /* |
| 169 | * When we disable the digit output, we need to wait for |
| 170 | * FRAMEDONE to know that DISPC has finished with the output. |
| 171 | * |
| 172 | * OMAP2/3 does not have FRAMEDONE irq for digit output, and in |
| 173 | * that case we need to use vsync interrupt, and wait for both |
| 174 | * even and odd frames. |
| 175 | */ |
| 176 | |
| 177 | if (framedone_irq) |
| 178 | wait = omap_irq_wait_init(dev, framedone_irq, 1); |
| 179 | else |
| 180 | wait = omap_irq_wait_init(dev, vsync_irq, 2); |
| 181 | } |
| 182 | |
| 183 | dispc_mgr_enable(channel, enable); |
| 184 | |
| 185 | ret = omap_irq_wait(dev, wait, msecs_to_jiffies(100)); |
| 186 | if (ret) { |
| 187 | dev_err(dev->dev, "%s: timeout waiting for %s\n", |
| 188 | omap_crtc->name, enable ? "enable" : "disable"); |
| 189 | } |
| 190 | |
| 191 | omap_irq_register(crtc->dev, &omap_crtc->error_irq); |
| 192 | } |
| 193 | |
Tomi Valkeinen | 506096a | 2014-04-03 13:11:54 +0300 | [diff] [blame] | 194 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 195 | static int omap_crtc_enable(struct omap_overlay_manager *mgr) |
| 196 | { |
Tomi Valkeinen | 506096a | 2014-04-03 13:11:54 +0300 | [diff] [blame] | 197 | struct omap_crtc *omap_crtc = omap_crtcs[mgr->id]; |
| 198 | |
| 199 | dispc_mgr_setup(omap_crtc->channel, &omap_crtc->info); |
| 200 | dispc_mgr_set_timings(omap_crtc->channel, |
| 201 | &omap_crtc->timings); |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 202 | omap_crtc_set_enabled(&omap_crtc->base, true); |
Tomi Valkeinen | 506096a | 2014-04-03 13:11:54 +0300 | [diff] [blame] | 203 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | static void omap_crtc_disable(struct omap_overlay_manager *mgr) |
| 208 | { |
Tomi Valkeinen | 506096a | 2014-04-03 13:11:54 +0300 | [diff] [blame] | 209 | struct omap_crtc *omap_crtc = omap_crtcs[mgr->id]; |
| 210 | |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 211 | omap_crtc_set_enabled(&omap_crtc->base, false); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static void omap_crtc_set_timings(struct omap_overlay_manager *mgr, |
| 215 | const struct omap_video_timings *timings) |
| 216 | { |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 217 | struct omap_crtc *omap_crtc = omap_crtcs[mgr->id]; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 218 | DBG("%s", omap_crtc->name); |
| 219 | omap_crtc->timings = *timings; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static void omap_crtc_set_lcd_config(struct omap_overlay_manager *mgr, |
| 223 | const struct dss_lcd_mgr_config *config) |
| 224 | { |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 225 | struct omap_crtc *omap_crtc = omap_crtcs[mgr->id]; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 226 | DBG("%s", omap_crtc->name); |
| 227 | dispc_mgr_set_lcd_config(omap_crtc->channel, config); |
| 228 | } |
| 229 | |
| 230 | static int omap_crtc_register_framedone_handler( |
| 231 | struct omap_overlay_manager *mgr, |
| 232 | void (*handler)(void *), void *data) |
| 233 | { |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static void omap_crtc_unregister_framedone_handler( |
| 238 | struct omap_overlay_manager *mgr, |
| 239 | void (*handler)(void *), void *data) |
| 240 | { |
| 241 | } |
| 242 | |
| 243 | static const struct dss_mgr_ops mgr_ops = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 244 | .connect = omap_crtc_connect, |
| 245 | .disconnect = omap_crtc_disconnect, |
| 246 | .start_update = omap_crtc_start_update, |
| 247 | .enable = omap_crtc_enable, |
| 248 | .disable = omap_crtc_disable, |
| 249 | .set_timings = omap_crtc_set_timings, |
| 250 | .set_lcd_config = omap_crtc_set_lcd_config, |
| 251 | .register_framedone_handler = omap_crtc_register_framedone_handler, |
| 252 | .unregister_framedone_handler = omap_crtc_unregister_framedone_handler, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 253 | }; |
| 254 | |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame^] | 255 | /* ----------------------------------------------------------------------------- |
| 256 | * Apply Logic |
| 257 | */ |
| 258 | |
| 259 | static void omap_crtc_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus) |
| 260 | { |
| 261 | struct omap_crtc *omap_crtc = |
| 262 | container_of(irq, struct omap_crtc, error_irq); |
| 263 | struct drm_crtc *crtc = &omap_crtc->base; |
| 264 | DRM_ERROR("%s: errors: %08x\n", omap_crtc->name, irqstatus); |
| 265 | /* avoid getting in a flood, unregister the irq until next vblank */ |
| 266 | __omap_irq_unregister(crtc->dev, &omap_crtc->error_irq); |
| 267 | } |
| 268 | |
| 269 | static void omap_crtc_apply_irq(struct omap_drm_irq *irq, uint32_t irqstatus) |
| 270 | { |
| 271 | struct omap_crtc *omap_crtc = |
| 272 | container_of(irq, struct omap_crtc, apply_irq); |
| 273 | struct drm_crtc *crtc = &omap_crtc->base; |
| 274 | |
| 275 | if (!omap_crtc->error_irq.registered) |
| 276 | __omap_irq_register(crtc->dev, &omap_crtc->error_irq); |
| 277 | |
| 278 | if (!dispc_mgr_go_busy(omap_crtc->channel)) { |
| 279 | struct omap_drm_private *priv = |
| 280 | crtc->dev->dev_private; |
| 281 | DBG("%s: apply done", omap_crtc->name); |
| 282 | __omap_irq_unregister(crtc->dev, &omap_crtc->apply_irq); |
| 283 | queue_work(priv->wq, &omap_crtc->apply_work); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | static void apply_worker(struct work_struct *work) |
| 288 | { |
| 289 | struct omap_crtc *omap_crtc = |
| 290 | container_of(work, struct omap_crtc, apply_work); |
| 291 | struct drm_crtc *crtc = &omap_crtc->base; |
| 292 | struct drm_device *dev = crtc->dev; |
| 293 | struct omap_drm_apply *apply, *n; |
| 294 | bool need_apply; |
| 295 | |
| 296 | /* |
| 297 | * Synchronize everything on mode_config.mutex, to keep |
| 298 | * the callbacks and list modification all serialized |
| 299 | * with respect to modesetting ioctls from userspace. |
| 300 | */ |
| 301 | drm_modeset_lock(&crtc->mutex, NULL); |
| 302 | dispc_runtime_get(); |
| 303 | |
| 304 | /* |
| 305 | * If we are still pending a previous update, wait.. when the |
| 306 | * pending update completes, we get kicked again. |
| 307 | */ |
| 308 | if (omap_crtc->apply_irq.registered) |
| 309 | goto out; |
| 310 | |
| 311 | /* finish up previous apply's: */ |
| 312 | list_for_each_entry_safe(apply, n, |
| 313 | &omap_crtc->pending_applies, pending_node) { |
| 314 | apply->post_apply(apply); |
| 315 | list_del(&apply->pending_node); |
| 316 | } |
| 317 | |
| 318 | need_apply = !list_empty(&omap_crtc->queued_applies); |
| 319 | |
| 320 | /* then handle the next round of of queued apply's: */ |
| 321 | list_for_each_entry_safe(apply, n, |
| 322 | &omap_crtc->queued_applies, queued_node) { |
| 323 | apply->pre_apply(apply); |
| 324 | list_del(&apply->queued_node); |
| 325 | apply->queued = false; |
| 326 | list_add_tail(&apply->pending_node, |
| 327 | &omap_crtc->pending_applies); |
| 328 | } |
| 329 | |
| 330 | if (need_apply) { |
| 331 | enum omap_channel channel = omap_crtc->channel; |
| 332 | |
| 333 | DBG("%s: GO", omap_crtc->name); |
| 334 | |
| 335 | if (dispc_mgr_is_enabled(channel)) { |
| 336 | dispc_mgr_go(channel); |
| 337 | omap_irq_register(dev, &omap_crtc->apply_irq); |
| 338 | } else { |
| 339 | struct omap_drm_private *priv = dev->dev_private; |
| 340 | queue_work(priv->wq, &omap_crtc->apply_work); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | out: |
| 345 | dispc_runtime_put(); |
| 346 | drm_modeset_unlock(&crtc->mutex); |
| 347 | } |
| 348 | |
| 349 | int omap_crtc_apply(struct drm_crtc *crtc, |
| 350 | struct omap_drm_apply *apply) |
| 351 | { |
| 352 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 353 | |
| 354 | WARN_ON(!drm_modeset_is_locked(&crtc->mutex)); |
| 355 | |
| 356 | /* no need to queue it again if it is already queued: */ |
| 357 | if (apply->queued) |
| 358 | return 0; |
| 359 | |
| 360 | apply->queued = true; |
| 361 | list_add_tail(&apply->queued_node, &omap_crtc->queued_applies); |
| 362 | |
| 363 | /* |
| 364 | * If there are no currently pending updates, then go ahead and |
| 365 | * kick the worker immediately, otherwise it will run again when |
| 366 | * the current update finishes. |
| 367 | */ |
| 368 | if (list_empty(&omap_crtc->pending_applies)) { |
| 369 | struct omap_drm_private *priv = crtc->dev->dev_private; |
| 370 | queue_work(priv->wq, &omap_crtc->apply_work); |
| 371 | } |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | static void omap_crtc_pre_apply(struct omap_drm_apply *apply) |
| 377 | { |
| 378 | struct omap_crtc *omap_crtc = |
| 379 | container_of(apply, struct omap_crtc, apply); |
| 380 | struct drm_crtc *crtc = &omap_crtc->base; |
| 381 | struct omap_drm_private *priv = crtc->dev->dev_private; |
| 382 | struct drm_encoder *encoder = NULL; |
| 383 | unsigned int i; |
| 384 | |
| 385 | DBG("%s: enabled=%d", omap_crtc->name, omap_crtc->enabled); |
| 386 | |
| 387 | for (i = 0; i < priv->num_encoders; i++) { |
| 388 | if (priv->encoders[i]->crtc == crtc) { |
| 389 | encoder = priv->encoders[i]; |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | if (omap_crtc->current_encoder && encoder != omap_crtc->current_encoder) |
| 395 | omap_encoder_set_enabled(omap_crtc->current_encoder, false); |
| 396 | |
| 397 | omap_crtc->current_encoder = encoder; |
| 398 | |
| 399 | if (!omap_crtc->enabled) { |
| 400 | if (encoder) |
| 401 | omap_encoder_set_enabled(encoder, false); |
| 402 | } else { |
| 403 | if (encoder) { |
| 404 | omap_encoder_set_enabled(encoder, false); |
| 405 | omap_encoder_update(encoder, omap_crtc->mgr, |
| 406 | &omap_crtc->timings); |
| 407 | omap_encoder_set_enabled(encoder, true); |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | static void omap_crtc_post_apply(struct omap_drm_apply *apply) |
| 413 | { |
| 414 | /* nothing needed for post-apply */ |
| 415 | } |
| 416 | |
| 417 | void omap_crtc_flush(struct drm_crtc *crtc) |
| 418 | { |
| 419 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 420 | int loops = 0; |
| 421 | |
| 422 | while (!list_empty(&omap_crtc->pending_applies) || |
| 423 | !list_empty(&omap_crtc->queued_applies) || |
| 424 | omap_crtc->event || omap_crtc->old_fb) { |
| 425 | |
| 426 | if (++loops > 10) { |
| 427 | dev_err(crtc->dev->dev, |
| 428 | "omap_crtc_flush() timeout\n"); |
| 429 | break; |
| 430 | } |
| 431 | |
| 432 | schedule_timeout_uninterruptible(msecs_to_jiffies(20)); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /* ----------------------------------------------------------------------------- |
| 437 | * CRTC Functions |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 438 | */ |
| 439 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 440 | static void omap_crtc_destroy(struct drm_crtc *crtc) |
| 441 | { |
| 442 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 443 | |
| 444 | DBG("%s", omap_crtc->name); |
| 445 | |
| 446 | WARN_ON(omap_crtc->apply_irq.registered); |
| 447 | omap_irq_unregister(crtc->dev, &omap_crtc->error_irq); |
| 448 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 449 | drm_crtc_cleanup(crtc); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 450 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 451 | kfree(omap_crtc); |
| 452 | } |
| 453 | |
| 454 | static void omap_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 455 | { |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 456 | struct omap_drm_private *priv = crtc->dev->dev_private; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 457 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 458 | bool enabled = (mode == DRM_MODE_DPMS_ON); |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 459 | int i; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 460 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 461 | DBG("%s: %d", omap_crtc->name, mode); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 462 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 463 | if (enabled != omap_crtc->enabled) { |
| 464 | omap_crtc->enabled = enabled; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 465 | omap_crtc_apply(crtc, &omap_crtc->apply); |
| 466 | |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 467 | /* Enable/disable all planes associated with the CRTC. */ |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 468 | for (i = 0; i < priv->num_planes; i++) { |
| 469 | struct drm_plane *plane = priv->planes[i]; |
| 470 | if (plane->crtc == crtc) |
Laurent Pinchart | 2debab9 | 2015-01-12 22:38:16 +0200 | [diff] [blame] | 471 | WARN_ON(omap_plane_set_enable(plane, enabled)); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 472 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 473 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static bool omap_crtc_mode_fixup(struct drm_crtc *crtc, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 477 | const struct drm_display_mode *mode, |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 478 | struct drm_display_mode *adjusted_mode) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 479 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 480 | return true; |
| 481 | } |
| 482 | |
| 483 | static int omap_crtc_mode_set(struct drm_crtc *crtc, |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 484 | struct drm_display_mode *mode, |
| 485 | struct drm_display_mode *adjusted_mode, |
| 486 | int x, int y, |
| 487 | struct drm_framebuffer *old_fb) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 488 | { |
| 489 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 490 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 491 | mode = adjusted_mode; |
| 492 | |
| 493 | DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x", |
| 494 | omap_crtc->name, mode->base.id, mode->name, |
| 495 | mode->vrefresh, mode->clock, |
| 496 | mode->hdisplay, mode->hsync_start, |
| 497 | mode->hsync_end, mode->htotal, |
| 498 | mode->vdisplay, mode->vsync_start, |
| 499 | mode->vsync_end, mode->vtotal, |
| 500 | mode->type, mode->flags); |
| 501 | |
| 502 | copy_timings_drm_to_omap(&omap_crtc->timings, mode); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 503 | |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 504 | /* |
| 505 | * The primary plane CRTC can be reset if the plane is disabled directly |
| 506 | * through the universal plane API. Set it again here. |
| 507 | */ |
| 508 | crtc->primary->crtc = crtc; |
| 509 | |
| 510 | return omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb, |
Laurent Pinchart | a350da8 | 2015-01-17 22:31:42 +0200 | [diff] [blame] | 511 | 0, 0, mode->hdisplay, mode->vdisplay, |
| 512 | x, y, mode->hdisplay, mode->vdisplay, |
| 513 | NULL, NULL); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static void omap_crtc_prepare(struct drm_crtc *crtc) |
| 517 | { |
| 518 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 519 | DBG("%s", omap_crtc->name); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 520 | omap_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
| 521 | } |
| 522 | |
| 523 | static void omap_crtc_commit(struct drm_crtc *crtc) |
| 524 | { |
| 525 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 526 | DBG("%s", omap_crtc->name); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 527 | omap_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
| 528 | } |
| 529 | |
| 530 | static int omap_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 531 | struct drm_framebuffer *old_fb) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 532 | { |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 533 | struct drm_plane *plane = crtc->primary; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 534 | struct drm_display_mode *mode = &crtc->mode; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 535 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 536 | return omap_plane_mode_set(plane, crtc, crtc->primary->fb, |
Laurent Pinchart | a350da8 | 2015-01-17 22:31:42 +0200 | [diff] [blame] | 537 | 0, 0, mode->hdisplay, mode->vdisplay, |
| 538 | x, y, mode->hdisplay, mode->vdisplay, |
| 539 | NULL, NULL); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 540 | } |
| 541 | |
Rob Clark | 72d0c33 | 2012-03-11 21:11:21 -0500 | [diff] [blame] | 542 | static void vblank_cb(void *arg) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 543 | { |
| 544 | struct drm_crtc *crtc = arg; |
| 545 | struct drm_device *dev = crtc->dev; |
| 546 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 547 | unsigned long flags; |
| 548 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 549 | spin_lock_irqsave(&dev->event_lock, flags); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 550 | |
| 551 | /* wakeup userspace */ |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 552 | if (omap_crtc->event) |
| 553 | drm_send_vblank_event(dev, omap_crtc->pipe, omap_crtc->event); |
Rob Clark | 7411f9c | 2012-03-11 21:11:22 -0500 | [diff] [blame] | 554 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 555 | omap_crtc->event = NULL; |
| 556 | omap_crtc->old_fb = NULL; |
| 557 | |
| 558 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 559 | } |
| 560 | |
| 561 | static void page_flip_worker(struct work_struct *work) |
| 562 | { |
| 563 | struct omap_crtc *omap_crtc = |
| 564 | container_of(work, struct omap_crtc, page_flip_work); |
| 565 | struct drm_crtc *crtc = &omap_crtc->base; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 566 | struct drm_display_mode *mode = &crtc->mode; |
| 567 | struct drm_gem_object *bo; |
| 568 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 569 | drm_modeset_lock(&crtc->mutex, NULL); |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 570 | omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb, |
Laurent Pinchart | a350da8 | 2015-01-17 22:31:42 +0200 | [diff] [blame] | 571 | 0, 0, mode->hdisplay, mode->vdisplay, |
| 572 | crtc->x, crtc->y, mode->hdisplay, mode->vdisplay, |
| 573 | vblank_cb, crtc); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 574 | drm_modeset_unlock(&crtc->mutex); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 575 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 576 | bo = omap_framebuffer_bo(crtc->primary->fb, 0); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 577 | drm_gem_object_unreference_unlocked(bo); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 578 | } |
| 579 | |
Rob Clark | 72d0c33 | 2012-03-11 21:11:21 -0500 | [diff] [blame] | 580 | static void page_flip_cb(void *arg) |
| 581 | { |
| 582 | struct drm_crtc *crtc = arg; |
| 583 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 584 | struct omap_drm_private *priv = crtc->dev->dev_private; |
Rob Clark | 72d0c33 | 2012-03-11 21:11:21 -0500 | [diff] [blame] | 585 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 586 | /* avoid assumptions about what ctxt we are called from: */ |
| 587 | queue_work(priv->wq, &omap_crtc->page_flip_work); |
Rob Clark | 72d0c33 | 2012-03-11 21:11:21 -0500 | [diff] [blame] | 588 | } |
| 589 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 590 | static int omap_crtc_page_flip_locked(struct drm_crtc *crtc, |
| 591 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 592 | struct drm_pending_vblank_event *event, |
| 593 | uint32_t page_flip_flags) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 594 | { |
| 595 | struct drm_device *dev = crtc->dev; |
| 596 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 597 | struct drm_plane *primary = crtc->primary; |
Rob Clark | 119c081 | 2012-09-04 17:46:22 -0500 | [diff] [blame] | 598 | struct drm_gem_object *bo; |
Archit Taneja | 38e5597 | 2014-04-11 12:53:35 +0530 | [diff] [blame] | 599 | unsigned long flags; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 600 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 601 | DBG("%d -> %d (event=%p)", primary->fb ? primary->fb->base.id : -1, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 602 | fb->base.id, event); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 603 | |
Archit Taneja | 38e5597 | 2014-04-11 12:53:35 +0530 | [diff] [blame] | 604 | spin_lock_irqsave(&dev->event_lock, flags); |
| 605 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 606 | if (omap_crtc->old_fb) { |
Archit Taneja | 38e5597 | 2014-04-11 12:53:35 +0530 | [diff] [blame] | 607 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 608 | dev_err(dev->dev, "already a pending flip\n"); |
| 609 | return -EINVAL; |
| 610 | } |
| 611 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 612 | omap_crtc->event = event; |
Archit Taneja | bc905ace | 2014-04-11 12:53:34 +0530 | [diff] [blame] | 613 | omap_crtc->old_fb = primary->fb = fb; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 614 | |
Archit Taneja | 38e5597 | 2014-04-11 12:53:35 +0530 | [diff] [blame] | 615 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 616 | |
Rob Clark | 119c081 | 2012-09-04 17:46:22 -0500 | [diff] [blame] | 617 | /* |
| 618 | * Hold a reference temporarily until the crtc is updated |
| 619 | * and takes the reference to the bo. This avoids it |
| 620 | * getting freed from under us: |
| 621 | */ |
| 622 | bo = omap_framebuffer_bo(fb, 0); |
| 623 | drm_gem_object_reference(bo); |
| 624 | |
| 625 | omap_gem_op_async(bo, OMAP_GEM_READ, page_flip_cb, crtc); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 630 | static int omap_crtc_set_property(struct drm_crtc *crtc, |
| 631 | struct drm_property *property, uint64_t val) |
| 632 | { |
Rob Clark | 1e0fdfc | 2012-09-04 11:36:20 -0500 | [diff] [blame] | 633 | struct omap_drm_private *priv = crtc->dev->dev_private; |
| 634 | |
| 635 | if (property == priv->rotation_prop) { |
| 636 | crtc->invert_dimensions = |
| 637 | !!(val & ((1LL << DRM_ROTATE_90) | (1LL << DRM_ROTATE_270))); |
| 638 | } |
| 639 | |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 640 | return omap_plane_set_property(crtc->primary, property, val); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 641 | } |
| 642 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 643 | static const struct drm_crtc_funcs omap_crtc_funcs = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 644 | .set_config = drm_crtc_helper_set_config, |
| 645 | .destroy = omap_crtc_destroy, |
| 646 | .page_flip = omap_crtc_page_flip_locked, |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 647 | .set_property = omap_crtc_set_property, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 648 | }; |
| 649 | |
| 650 | static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = { |
| 651 | .dpms = omap_crtc_dpms, |
| 652 | .mode_fixup = omap_crtc_mode_fixup, |
| 653 | .mode_set = omap_crtc_mode_set, |
| 654 | .prepare = omap_crtc_prepare, |
| 655 | .commit = omap_crtc_commit, |
| 656 | .mode_set_base = omap_crtc_mode_set_base, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 657 | }; |
| 658 | |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame^] | 659 | /* ----------------------------------------------------------------------------- |
| 660 | * Init and Cleanup |
| 661 | */ |
Tomi Valkeinen | e2f8fd7 | 2014-04-02 14:31:57 +0300 | [diff] [blame] | 662 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 663 | static const char *channel_names[] = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 664 | [OMAP_DSS_CHANNEL_LCD] = "lcd", |
| 665 | [OMAP_DSS_CHANNEL_DIGIT] = "tv", |
| 666 | [OMAP_DSS_CHANNEL_LCD2] = "lcd2", |
| 667 | [OMAP_DSS_CHANNEL_LCD3] = "lcd3", |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 668 | }; |
| 669 | |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 670 | void omap_crtc_pre_init(void) |
| 671 | { |
| 672 | dss_install_mgr_ops(&mgr_ops); |
| 673 | } |
| 674 | |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 675 | void omap_crtc_pre_uninit(void) |
| 676 | { |
| 677 | dss_uninstall_mgr_ops(); |
| 678 | } |
| 679 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 680 | /* initialize crtc */ |
| 681 | struct drm_crtc *omap_crtc_init(struct drm_device *dev, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 682 | struct drm_plane *plane, enum omap_channel channel, int id) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 683 | { |
| 684 | struct drm_crtc *crtc = NULL; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 685 | struct omap_crtc *omap_crtc; |
| 686 | struct omap_overlay_manager_info *info; |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 687 | int ret; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 688 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 689 | DBG("%s", channel_names[channel]); |
| 690 | |
| 691 | omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL); |
Joe Perches | 78110bb | 2013-02-11 09:41:29 -0800 | [diff] [blame] | 692 | if (!omap_crtc) |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 693 | return NULL; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 694 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 695 | crtc = &omap_crtc->base; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 696 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 697 | INIT_WORK(&omap_crtc->page_flip_work, page_flip_worker); |
| 698 | INIT_WORK(&omap_crtc->apply_work, apply_worker); |
| 699 | |
| 700 | INIT_LIST_HEAD(&omap_crtc->pending_applies); |
| 701 | INIT_LIST_HEAD(&omap_crtc->queued_applies); |
| 702 | |
| 703 | omap_crtc->apply.pre_apply = omap_crtc_pre_apply; |
| 704 | omap_crtc->apply.post_apply = omap_crtc_post_apply; |
| 705 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 706 | omap_crtc->channel = channel; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 707 | omap_crtc->name = channel_names[channel]; |
| 708 | omap_crtc->pipe = id; |
| 709 | |
| 710 | omap_crtc->apply_irq.irqmask = pipe2vbl(crtc); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 711 | omap_crtc->apply_irq.irq = omap_crtc_apply_irq; |
| 712 | |
| 713 | omap_crtc->error_irq.irqmask = |
| 714 | dispc_mgr_get_sync_lost_irq(channel); |
| 715 | omap_crtc->error_irq.irq = omap_crtc_error_irq; |
| 716 | omap_irq_register(dev, &omap_crtc->error_irq); |
| 717 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 718 | /* temporary: */ |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 719 | omap_crtc->mgr = omap_dss_get_overlay_manager(channel); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 720 | |
| 721 | /* TODO: fix hard-coded setup.. add properties! */ |
| 722 | info = &omap_crtc->info; |
| 723 | info->default_color = 0x00000000; |
| 724 | info->trans_key = 0x00000000; |
| 725 | info->trans_key_type = OMAP_DSS_COLOR_KEY_GFX_DST; |
| 726 | info->trans_enabled = false; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 727 | |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 728 | ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL, |
| 729 | &omap_crtc_funcs); |
| 730 | if (ret < 0) { |
| 731 | kfree(omap_crtc); |
| 732 | return NULL; |
| 733 | } |
| 734 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 735 | drm_crtc_helper_add(crtc, &omap_crtc_helper_funcs); |
| 736 | |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 737 | omap_plane_install_properties(crtc->primary, &crtc->base); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 738 | |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 739 | omap_crtcs[channel] = omap_crtc; |
| 740 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 741 | return crtc; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 742 | } |