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