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