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