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