Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Texas Instruments |
| 3 | * Author: Rob Clark <robdclark@gmail.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 18 | #include "drm_flip_work.h" |
Daniel Vetter | 3cb9ae4 | 2014-10-29 10:03:57 +0100 | [diff] [blame] | 19 | #include <drm/drm_plane_helper.h> |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 20 | |
| 21 | #include "tilcdc_drv.h" |
| 22 | #include "tilcdc_regs.h" |
| 23 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 24 | #define TILCDC_VBLANK_SAFETY_THRESHOLD_US 1000 |
| 25 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 26 | struct tilcdc_crtc { |
| 27 | struct drm_crtc base; |
| 28 | |
| 29 | const struct tilcdc_panel_info *info; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 30 | struct drm_pending_vblank_event *event; |
| 31 | int dpms; |
| 32 | wait_queue_head_t frame_done_wq; |
| 33 | bool frame_done; |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 34 | spinlock_t irq_lock; |
| 35 | |
| 36 | ktime_t last_vblank; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 37 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 38 | struct drm_framebuffer *curr_fb; |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 39 | struct drm_framebuffer *next_fb; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 40 | |
| 41 | /* for deferred fb unref's: */ |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 42 | struct drm_flip_work unref_work; |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 43 | |
| 44 | /* Only set if an external encoder is connected */ |
| 45 | bool simulate_vesa_sync; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 46 | }; |
| 47 | #define to_tilcdc_crtc(x) container_of(x, struct tilcdc_crtc, base) |
| 48 | |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 49 | static void unref_worker(struct drm_flip_work *work, void *val) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 50 | { |
Darren Etheridge | f7b4575 | 2013-06-21 13:52:26 -0500 | [diff] [blame] | 51 | struct tilcdc_crtc *tilcdc_crtc = |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 52 | container_of(work, struct tilcdc_crtc, unref_work); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 53 | struct drm_device *dev = tilcdc_crtc->base.dev; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 54 | |
| 55 | mutex_lock(&dev->mode_config.mutex); |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 56 | drm_framebuffer_unreference(val); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 57 | mutex_unlock(&dev->mode_config.mutex); |
| 58 | } |
| 59 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 60 | static void set_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 61 | { |
| 62 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 63 | struct drm_device *dev = crtc->dev; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 64 | struct drm_gem_cma_object *gem; |
| 65 | unsigned int depth, bpp; |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 66 | dma_addr_t start, end; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 67 | |
| 68 | drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp); |
| 69 | gem = drm_fb_cma_get_gem_obj(fb, 0); |
| 70 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 71 | start = gem->paddr + fb->offsets[0] + |
| 72 | crtc->y * fb->pitches[0] + |
| 73 | crtc->x * bpp / 8; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 74 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 75 | end = start + (crtc->mode.vdisplay * fb->pitches[0]); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 76 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 77 | tilcdc_write(dev, LCDC_DMA_FB_BASE_ADDR_0_REG, start); |
| 78 | tilcdc_write(dev, LCDC_DMA_FB_CEILING_ADDR_0_REG, end); |
| 79 | |
| 80 | if (tilcdc_crtc->curr_fb) |
| 81 | drm_flip_work_queue(&tilcdc_crtc->unref_work, |
| 82 | tilcdc_crtc->curr_fb); |
| 83 | |
| 84 | tilcdc_crtc->curr_fb = fb; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 85 | } |
| 86 | |
Tomi Valkeinen | 2efec4f | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 87 | static void reset(struct drm_crtc *crtc) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 88 | { |
| 89 | struct drm_device *dev = crtc->dev; |
| 90 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 91 | |
Tomi Valkeinen | 2efec4f | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 92 | if (priv->rev != 2) |
| 93 | return; |
| 94 | |
| 95 | tilcdc_set(dev, LCDC_CLK_RESET_REG, LCDC_CLK_MAIN_RESET); |
| 96 | usleep_range(250, 1000); |
| 97 | tilcdc_clear(dev, LCDC_CLK_RESET_REG, LCDC_CLK_MAIN_RESET); |
| 98 | } |
| 99 | |
| 100 | static void start(struct drm_crtc *crtc) |
| 101 | { |
| 102 | struct drm_device *dev = crtc->dev; |
| 103 | |
| 104 | reset(crtc); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 105 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 106 | tilcdc_clear(dev, LCDC_DMA_CTRL_REG, LCDC_DUAL_FRAME_BUFFER_ENABLE); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 107 | tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_PALETTE_LOAD_MODE(DATA_ONLY)); |
| 108 | tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE); |
| 109 | } |
| 110 | |
| 111 | static void stop(struct drm_crtc *crtc) |
| 112 | { |
| 113 | struct drm_device *dev = crtc->dev; |
| 114 | |
| 115 | tilcdc_clear(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE); |
| 116 | } |
| 117 | |
| 118 | static void tilcdc_crtc_destroy(struct drm_crtc *crtc) |
| 119 | { |
| 120 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 121 | |
Jyri Sarha | de9cb5f | 2015-02-26 10:12:41 +0200 | [diff] [blame] | 122 | tilcdc_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 123 | |
| 124 | drm_crtc_cleanup(crtc); |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 125 | drm_flip_work_cleanup(&tilcdc_crtc->unref_work); |
| 126 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 127 | kfree(tilcdc_crtc); |
| 128 | } |
| 129 | |
Tomi Valkeinen | 6f206e9 | 2014-02-07 17:37:07 +0000 | [diff] [blame] | 130 | static int tilcdc_verify_fb(struct drm_crtc *crtc, struct drm_framebuffer *fb) |
| 131 | { |
| 132 | struct drm_device *dev = crtc->dev; |
| 133 | unsigned int depth, bpp; |
| 134 | |
| 135 | drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp); |
| 136 | |
| 137 | if (fb->pitches[0] != crtc->mode.hdisplay * bpp / 8) { |
| 138 | dev_err(dev->dev, |
| 139 | "Invalid pitch: fb and crtc widths must be the same"); |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 146 | static int tilcdc_crtc_page_flip(struct drm_crtc *crtc, |
| 147 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 148 | struct drm_pending_vblank_event *event, |
| 149 | uint32_t page_flip_flags) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 150 | { |
| 151 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 152 | struct drm_device *dev = crtc->dev; |
Tomi Valkeinen | 6f206e9 | 2014-02-07 17:37:07 +0000 | [diff] [blame] | 153 | int r; |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 154 | unsigned long flags; |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 155 | s64 tdiff; |
| 156 | ktime_t next_vblank; |
Tomi Valkeinen | 6f206e9 | 2014-02-07 17:37:07 +0000 | [diff] [blame] | 157 | |
| 158 | r = tilcdc_verify_fb(crtc, fb); |
| 159 | if (r) |
| 160 | return r; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 161 | |
| 162 | if (tilcdc_crtc->event) { |
| 163 | dev_err(dev->dev, "already pending page flip!\n"); |
| 164 | return -EBUSY; |
| 165 | } |
| 166 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 167 | drm_framebuffer_reference(fb); |
| 168 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 169 | crtc->primary->fb = fb; |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 170 | |
| 171 | pm_runtime_get_sync(dev->dev); |
| 172 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 173 | spin_lock_irqsave(&tilcdc_crtc->irq_lock, flags); |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 174 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 175 | next_vblank = ktime_add_us(tilcdc_crtc->last_vblank, |
| 176 | 1000000 / crtc->hwmode.vrefresh); |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 177 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 178 | tdiff = ktime_to_us(ktime_sub(next_vblank, ktime_get())); |
| 179 | |
| 180 | if (tdiff >= TILCDC_VBLANK_SAFETY_THRESHOLD_US) |
| 181 | set_scanout(crtc, fb); |
| 182 | else |
| 183 | tilcdc_crtc->next_fb = fb; |
| 184 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 185 | tilcdc_crtc->event = event; |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 186 | |
| 187 | spin_unlock_irqrestore(&tilcdc_crtc->irq_lock, flags); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 188 | |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 189 | pm_runtime_put_sync(dev->dev); |
| 190 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 191 | return 0; |
| 192 | } |
| 193 | |
Darren Etheridge | 614b3cfe | 2014-09-25 00:59:32 +0000 | [diff] [blame] | 194 | void tilcdc_crtc_dpms(struct drm_crtc *crtc, int mode) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 195 | { |
| 196 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 197 | struct drm_device *dev = crtc->dev; |
| 198 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 199 | |
| 200 | /* we really only care about on or off: */ |
| 201 | if (mode != DRM_MODE_DPMS_ON) |
| 202 | mode = DRM_MODE_DPMS_OFF; |
| 203 | |
| 204 | if (tilcdc_crtc->dpms == mode) |
| 205 | return; |
| 206 | |
| 207 | tilcdc_crtc->dpms = mode; |
| 208 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 209 | if (mode == DRM_MODE_DPMS_ON) { |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 210 | pm_runtime_get_sync(dev->dev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 211 | start(crtc); |
| 212 | } else { |
| 213 | tilcdc_crtc->frame_done = false; |
| 214 | stop(crtc); |
| 215 | |
Darren Etheridge | f7b4575 | 2013-06-21 13:52:26 -0500 | [diff] [blame] | 216 | /* |
| 217 | * if necessary wait for framedone irq which will still come |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 218 | * before putting things to sleep.. |
| 219 | */ |
| 220 | if (priv->rev == 2) { |
| 221 | int ret = wait_event_timeout( |
| 222 | tilcdc_crtc->frame_done_wq, |
| 223 | tilcdc_crtc->frame_done, |
| 224 | msecs_to_jiffies(50)); |
| 225 | if (ret == 0) |
| 226 | dev_err(dev->dev, "timeout waiting for framedone\n"); |
| 227 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 228 | |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 229 | pm_runtime_put_sync(dev->dev); |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 230 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 231 | if (tilcdc_crtc->next_fb) { |
| 232 | drm_flip_work_queue(&tilcdc_crtc->unref_work, |
| 233 | tilcdc_crtc->next_fb); |
| 234 | tilcdc_crtc->next_fb = NULL; |
| 235 | } |
| 236 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 237 | if (tilcdc_crtc->curr_fb) { |
| 238 | drm_flip_work_queue(&tilcdc_crtc->unref_work, |
| 239 | tilcdc_crtc->curr_fb); |
| 240 | tilcdc_crtc->curr_fb = NULL; |
| 241 | } |
| 242 | |
| 243 | drm_flip_work_commit(&tilcdc_crtc->unref_work, priv->wq); |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 244 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static bool tilcdc_crtc_mode_fixup(struct drm_crtc *crtc, |
| 248 | const struct drm_display_mode *mode, |
| 249 | struct drm_display_mode *adjusted_mode) |
| 250 | { |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 251 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 252 | |
| 253 | if (!tilcdc_crtc->simulate_vesa_sync) |
| 254 | return true; |
| 255 | |
| 256 | /* |
| 257 | * tilcdc does not generate VESA-compliant sync but aligns |
| 258 | * VS on the second edge of HS instead of first edge. |
| 259 | * We use adjusted_mode, to fixup sync by aligning both rising |
| 260 | * edges and add HSKEW offset to fix the sync. |
| 261 | */ |
| 262 | adjusted_mode->hskew = mode->hsync_end - mode->hsync_start; |
| 263 | adjusted_mode->flags |= DRM_MODE_FLAG_HSKEW; |
| 264 | |
| 265 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) { |
| 266 | adjusted_mode->flags |= DRM_MODE_FLAG_PHSYNC; |
| 267 | adjusted_mode->flags &= ~DRM_MODE_FLAG_NHSYNC; |
| 268 | } else { |
| 269 | adjusted_mode->flags |= DRM_MODE_FLAG_NHSYNC; |
| 270 | adjusted_mode->flags &= ~DRM_MODE_FLAG_PHSYNC; |
| 271 | } |
| 272 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 273 | return true; |
| 274 | } |
| 275 | |
| 276 | static void tilcdc_crtc_prepare(struct drm_crtc *crtc) |
| 277 | { |
| 278 | tilcdc_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
| 279 | } |
| 280 | |
| 281 | static void tilcdc_crtc_commit(struct drm_crtc *crtc) |
| 282 | { |
| 283 | tilcdc_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
| 284 | } |
| 285 | |
| 286 | static int tilcdc_crtc_mode_set(struct drm_crtc *crtc, |
| 287 | struct drm_display_mode *mode, |
| 288 | struct drm_display_mode *adjusted_mode, |
| 289 | int x, int y, |
| 290 | struct drm_framebuffer *old_fb) |
| 291 | { |
| 292 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 293 | struct drm_device *dev = crtc->dev; |
| 294 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 295 | const struct tilcdc_panel_info *info = tilcdc_crtc->info; |
| 296 | uint32_t reg, hbp, hfp, hsw, vbp, vfp, vsw; |
| 297 | int ret; |
| 298 | |
| 299 | ret = tilcdc_crtc_mode_valid(crtc, mode); |
| 300 | if (WARN_ON(ret)) |
| 301 | return ret; |
| 302 | |
| 303 | if (WARN_ON(!info)) |
| 304 | return -EINVAL; |
| 305 | |
Tomi Valkeinen | 6f206e9 | 2014-02-07 17:37:07 +0000 | [diff] [blame] | 306 | ret = tilcdc_verify_fb(crtc, crtc->primary->fb); |
| 307 | if (ret) |
| 308 | return ret; |
| 309 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 310 | pm_runtime_get_sync(dev->dev); |
| 311 | |
| 312 | /* Configure the Burst Size and fifo threshold of DMA: */ |
| 313 | reg = tilcdc_read(dev, LCDC_DMA_CTRL_REG) & ~0x00000770; |
| 314 | switch (info->dma_burst_sz) { |
| 315 | case 1: |
| 316 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_1); |
| 317 | break; |
| 318 | case 2: |
| 319 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_2); |
| 320 | break; |
| 321 | case 4: |
| 322 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_4); |
| 323 | break; |
| 324 | case 8: |
| 325 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_8); |
| 326 | break; |
| 327 | case 16: |
| 328 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_16); |
| 329 | break; |
| 330 | default: |
| 331 | return -EINVAL; |
| 332 | } |
| 333 | reg |= (info->fifo_th << 8); |
| 334 | tilcdc_write(dev, LCDC_DMA_CTRL_REG, reg); |
| 335 | |
| 336 | /* Configure timings: */ |
| 337 | hbp = mode->htotal - mode->hsync_end; |
| 338 | hfp = mode->hsync_start - mode->hdisplay; |
| 339 | hsw = mode->hsync_end - mode->hsync_start; |
| 340 | vbp = mode->vtotal - mode->vsync_end; |
| 341 | vfp = mode->vsync_start - mode->vdisplay; |
| 342 | vsw = mode->vsync_end - mode->vsync_start; |
| 343 | |
| 344 | DBG("%dx%d, hbp=%u, hfp=%u, hsw=%u, vbp=%u, vfp=%u, vsw=%u", |
| 345 | mode->hdisplay, mode->vdisplay, hbp, hfp, hsw, vbp, vfp, vsw); |
| 346 | |
| 347 | /* Configure the AC Bias Period and Number of Transitions per Interrupt: */ |
| 348 | reg = tilcdc_read(dev, LCDC_RASTER_TIMING_2_REG) & ~0x000fff00; |
| 349 | reg |= LCDC_AC_BIAS_FREQUENCY(info->ac_bias) | |
| 350 | LCDC_AC_BIAS_TRANSITIONS_PER_INT(info->ac_bias_intrpt); |
Darren Etheridge | db2b4bd | 2013-06-21 13:52:24 -0500 | [diff] [blame] | 351 | |
| 352 | /* |
| 353 | * subtract one from hfp, hbp, hsw because the hardware uses |
| 354 | * a value of 0 as 1 |
| 355 | */ |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 356 | if (priv->rev == 2) { |
Pantelis Antoniou | c19b3e2 | 2013-06-21 13:52:28 -0500 | [diff] [blame] | 357 | /* clear bits we're going to set */ |
| 358 | reg &= ~0x78000033; |
Darren Etheridge | db2b4bd | 2013-06-21 13:52:24 -0500 | [diff] [blame] | 359 | reg |= ((hfp-1) & 0x300) >> 8; |
| 360 | reg |= ((hbp-1) & 0x300) >> 4; |
| 361 | reg |= ((hsw-1) & 0x3c0) << 21; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 362 | } |
| 363 | tilcdc_write(dev, LCDC_RASTER_TIMING_2_REG, reg); |
| 364 | |
| 365 | reg = (((mode->hdisplay >> 4) - 1) << 4) | |
Darren Etheridge | db2b4bd | 2013-06-21 13:52:24 -0500 | [diff] [blame] | 366 | (((hbp-1) & 0xff) << 24) | |
| 367 | (((hfp-1) & 0xff) << 16) | |
| 368 | (((hsw-1) & 0x3f) << 10); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 369 | if (priv->rev == 2) |
| 370 | reg |= (((mode->hdisplay >> 4) - 1) & 0x40) >> 3; |
| 371 | tilcdc_write(dev, LCDC_RASTER_TIMING_0_REG, reg); |
| 372 | |
| 373 | reg = ((mode->vdisplay - 1) & 0x3ff) | |
| 374 | ((vbp & 0xff) << 24) | |
| 375 | ((vfp & 0xff) << 16) | |
Darren Etheridge | db2b4bd | 2013-06-21 13:52:24 -0500 | [diff] [blame] | 376 | (((vsw-1) & 0x3f) << 10); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 377 | tilcdc_write(dev, LCDC_RASTER_TIMING_1_REG, reg); |
| 378 | |
Darren Etheridge | 6bf02c6 | 2013-06-21 13:52:22 -0500 | [diff] [blame] | 379 | /* |
| 380 | * be sure to set Bit 10 for the V2 LCDC controller, |
| 381 | * otherwise limited to 1024 pixels width, stopping |
| 382 | * 1920x1080 being suppoted. |
| 383 | */ |
| 384 | if (priv->rev == 2) { |
| 385 | if ((mode->vdisplay - 1) & 0x400) { |
| 386 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, |
| 387 | LCDC_LPP_B10); |
| 388 | } else { |
| 389 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, |
| 390 | LCDC_LPP_B10); |
| 391 | } |
| 392 | } |
| 393 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 394 | /* Configure display type: */ |
| 395 | reg = tilcdc_read(dev, LCDC_RASTER_CTRL_REG) & |
| 396 | ~(LCDC_TFT_MODE | LCDC_MONO_8BIT_MODE | LCDC_MONOCHROME_MODE | |
| 397 | LCDC_V2_TFT_24BPP_MODE | LCDC_V2_TFT_24BPP_UNPACK | 0x000ff000); |
| 398 | reg |= LCDC_TFT_MODE; /* no monochrome/passive support */ |
| 399 | if (info->tft_alt_mode) |
| 400 | reg |= LCDC_TFT_ALT_ENABLE; |
| 401 | if (priv->rev == 2) { |
| 402 | unsigned int depth, bpp; |
| 403 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 404 | drm_fb_get_bpp_depth(crtc->primary->fb->pixel_format, &depth, &bpp); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 405 | switch (bpp) { |
| 406 | case 16: |
| 407 | break; |
| 408 | case 32: |
| 409 | reg |= LCDC_V2_TFT_24BPP_UNPACK; |
| 410 | /* fallthrough */ |
| 411 | case 24: |
| 412 | reg |= LCDC_V2_TFT_24BPP_MODE; |
| 413 | break; |
| 414 | default: |
| 415 | dev_err(dev->dev, "invalid pixel format\n"); |
| 416 | return -EINVAL; |
| 417 | } |
| 418 | } |
| 419 | reg |= info->fdd < 12; |
| 420 | tilcdc_write(dev, LCDC_RASTER_CTRL_REG, reg); |
| 421 | |
| 422 | if (info->invert_pxl_clk) |
| 423 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_PIXEL_CLOCK); |
| 424 | else |
| 425 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_PIXEL_CLOCK); |
| 426 | |
| 427 | if (info->sync_ctrl) |
| 428 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_CTRL); |
| 429 | else |
| 430 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_CTRL); |
| 431 | |
| 432 | if (info->sync_edge) |
| 433 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_EDGE); |
| 434 | else |
| 435 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_EDGE); |
| 436 | |
Darren Etheridge | a976718 | 2013-08-14 21:43:33 +0200 | [diff] [blame] | 437 | /* |
| 438 | * use value from adjusted_mode here as this might have been |
| 439 | * changed as part of the fixup for slave encoders to solve the |
| 440 | * issue where tilcdc timings are not VESA compliant |
| 441 | */ |
| 442 | if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 443 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_HSYNC); |
| 444 | else |
| 445 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_HSYNC); |
| 446 | |
| 447 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 448 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_VSYNC); |
| 449 | else |
| 450 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_VSYNC); |
| 451 | |
| 452 | if (info->raster_order) |
| 453 | tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ORDER); |
| 454 | else |
| 455 | tilcdc_clear(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ORDER); |
| 456 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 457 | drm_framebuffer_reference(crtc->primary->fb); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 458 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 459 | set_scanout(crtc, crtc->primary->fb); |
| 460 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 461 | tilcdc_crtc_update_clk(crtc); |
| 462 | |
| 463 | pm_runtime_put_sync(dev->dev); |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | static int tilcdc_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
| 469 | struct drm_framebuffer *old_fb) |
| 470 | { |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 471 | struct drm_device *dev = crtc->dev; |
Tomi Valkeinen | 6f206e9 | 2014-02-07 17:37:07 +0000 | [diff] [blame] | 472 | int r; |
| 473 | |
| 474 | r = tilcdc_verify_fb(crtc, crtc->primary->fb); |
| 475 | if (r) |
| 476 | return r; |
| 477 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 478 | drm_framebuffer_reference(crtc->primary->fb); |
| 479 | |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 480 | pm_runtime_get_sync(dev->dev); |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 481 | |
| 482 | set_scanout(crtc, crtc->primary->fb); |
| 483 | |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 484 | pm_runtime_put_sync(dev->dev); |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 485 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 486 | return 0; |
| 487 | } |
| 488 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 489 | static const struct drm_crtc_funcs tilcdc_crtc_funcs = { |
| 490 | .destroy = tilcdc_crtc_destroy, |
| 491 | .set_config = drm_crtc_helper_set_config, |
| 492 | .page_flip = tilcdc_crtc_page_flip, |
| 493 | }; |
| 494 | |
| 495 | static const struct drm_crtc_helper_funcs tilcdc_crtc_helper_funcs = { |
| 496 | .dpms = tilcdc_crtc_dpms, |
| 497 | .mode_fixup = tilcdc_crtc_mode_fixup, |
| 498 | .prepare = tilcdc_crtc_prepare, |
| 499 | .commit = tilcdc_crtc_commit, |
| 500 | .mode_set = tilcdc_crtc_mode_set, |
| 501 | .mode_set_base = tilcdc_crtc_mode_set_base, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 502 | }; |
| 503 | |
| 504 | int tilcdc_crtc_max_width(struct drm_crtc *crtc) |
| 505 | { |
| 506 | struct drm_device *dev = crtc->dev; |
| 507 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 508 | int max_width = 0; |
| 509 | |
| 510 | if (priv->rev == 1) |
| 511 | max_width = 1024; |
| 512 | else if (priv->rev == 2) |
| 513 | max_width = 2048; |
| 514 | |
| 515 | return max_width; |
| 516 | } |
| 517 | |
| 518 | int tilcdc_crtc_mode_valid(struct drm_crtc *crtc, struct drm_display_mode *mode) |
| 519 | { |
| 520 | struct tilcdc_drm_private *priv = crtc->dev->dev_private; |
| 521 | unsigned int bandwidth; |
Darren Etheridge | e1c5d0a | 2013-06-21 13:52:25 -0500 | [diff] [blame] | 522 | uint32_t hbp, hfp, hsw, vbp, vfp, vsw; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 523 | |
Darren Etheridge | e1c5d0a | 2013-06-21 13:52:25 -0500 | [diff] [blame] | 524 | /* |
| 525 | * check to see if the width is within the range that |
| 526 | * the LCD Controller physically supports |
| 527 | */ |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 528 | if (mode->hdisplay > tilcdc_crtc_max_width(crtc)) |
| 529 | return MODE_VIRTUAL_X; |
| 530 | |
| 531 | /* width must be multiple of 16 */ |
| 532 | if (mode->hdisplay & 0xf) |
| 533 | return MODE_VIRTUAL_X; |
| 534 | |
| 535 | if (mode->vdisplay > 2048) |
| 536 | return MODE_VIRTUAL_Y; |
| 537 | |
Darren Etheridge | e1c5d0a | 2013-06-21 13:52:25 -0500 | [diff] [blame] | 538 | DBG("Processing mode %dx%d@%d with pixel clock %d", |
| 539 | mode->hdisplay, mode->vdisplay, |
| 540 | drm_mode_vrefresh(mode), mode->clock); |
| 541 | |
| 542 | hbp = mode->htotal - mode->hsync_end; |
| 543 | hfp = mode->hsync_start - mode->hdisplay; |
| 544 | hsw = mode->hsync_end - mode->hsync_start; |
| 545 | vbp = mode->vtotal - mode->vsync_end; |
| 546 | vfp = mode->vsync_start - mode->vdisplay; |
| 547 | vsw = mode->vsync_end - mode->vsync_start; |
| 548 | |
| 549 | if ((hbp-1) & ~0x3ff) { |
| 550 | DBG("Pruning mode: Horizontal Back Porch out of range"); |
| 551 | return MODE_HBLANK_WIDE; |
| 552 | } |
| 553 | |
| 554 | if ((hfp-1) & ~0x3ff) { |
| 555 | DBG("Pruning mode: Horizontal Front Porch out of range"); |
| 556 | return MODE_HBLANK_WIDE; |
| 557 | } |
| 558 | |
| 559 | if ((hsw-1) & ~0x3ff) { |
| 560 | DBG("Pruning mode: Horizontal Sync Width out of range"); |
| 561 | return MODE_HSYNC_WIDE; |
| 562 | } |
| 563 | |
| 564 | if (vbp & ~0xff) { |
| 565 | DBG("Pruning mode: Vertical Back Porch out of range"); |
| 566 | return MODE_VBLANK_WIDE; |
| 567 | } |
| 568 | |
| 569 | if (vfp & ~0xff) { |
| 570 | DBG("Pruning mode: Vertical Front Porch out of range"); |
| 571 | return MODE_VBLANK_WIDE; |
| 572 | } |
| 573 | |
| 574 | if ((vsw-1) & ~0x3f) { |
| 575 | DBG("Pruning mode: Vertical Sync Width out of range"); |
| 576 | return MODE_VSYNC_WIDE; |
| 577 | } |
| 578 | |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 579 | /* |
| 580 | * some devices have a maximum allowed pixel clock |
| 581 | * configured from the DT |
| 582 | */ |
| 583 | if (mode->clock > priv->max_pixelclock) { |
Darren Etheridge | f7b4575 | 2013-06-21 13:52:26 -0500 | [diff] [blame] | 584 | DBG("Pruning mode: pixel clock too high"); |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 585 | return MODE_CLOCK_HIGH; |
| 586 | } |
| 587 | |
| 588 | /* |
| 589 | * some devices further limit the max horizontal resolution |
| 590 | * configured from the DT |
| 591 | */ |
| 592 | if (mode->hdisplay > priv->max_width) |
| 593 | return MODE_BAD_WIDTH; |
| 594 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 595 | /* filter out modes that would require too much memory bandwidth: */ |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 596 | bandwidth = mode->hdisplay * mode->vdisplay * |
| 597 | drm_mode_vrefresh(mode); |
| 598 | if (bandwidth > priv->max_bandwidth) { |
Darren Etheridge | f7b4575 | 2013-06-21 13:52:26 -0500 | [diff] [blame] | 599 | DBG("Pruning mode: exceeds defined bandwidth limit"); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 600 | return MODE_BAD; |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 601 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 602 | |
| 603 | return MODE_OK; |
| 604 | } |
| 605 | |
| 606 | void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc, |
| 607 | const struct tilcdc_panel_info *info) |
| 608 | { |
| 609 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 610 | tilcdc_crtc->info = info; |
| 611 | } |
| 612 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 613 | void tilcdc_crtc_set_simulate_vesa_sync(struct drm_crtc *crtc, |
| 614 | bool simulate_vesa_sync) |
| 615 | { |
| 616 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 617 | |
| 618 | tilcdc_crtc->simulate_vesa_sync = simulate_vesa_sync; |
| 619 | } |
| 620 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 621 | void tilcdc_crtc_update_clk(struct drm_crtc *crtc) |
| 622 | { |
| 623 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 624 | struct drm_device *dev = crtc->dev; |
| 625 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 626 | int dpms = tilcdc_crtc->dpms; |
Darren Etheridge | 3d19306 | 2014-01-15 15:52:36 -0600 | [diff] [blame] | 627 | unsigned long lcd_clk; |
| 628 | const unsigned clkdiv = 2; /* using a fixed divider of 2 */ |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 629 | int ret; |
| 630 | |
| 631 | pm_runtime_get_sync(dev->dev); |
| 632 | |
| 633 | if (dpms == DRM_MODE_DPMS_ON) |
| 634 | tilcdc_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
| 635 | |
Darren Etheridge | 3d19306 | 2014-01-15 15:52:36 -0600 | [diff] [blame] | 636 | /* mode.clock is in KHz, set_rate wants parameter in Hz */ |
| 637 | ret = clk_set_rate(priv->clk, crtc->mode.clock * 1000 * clkdiv); |
| 638 | if (ret < 0) { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 639 | dev_err(dev->dev, "failed to set display clock rate to: %d\n", |
| 640 | crtc->mode.clock); |
| 641 | goto out; |
| 642 | } |
| 643 | |
| 644 | lcd_clk = clk_get_rate(priv->clk); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 645 | |
Darren Etheridge | 3d19306 | 2014-01-15 15:52:36 -0600 | [diff] [blame] | 646 | DBG("lcd_clk=%lu, mode clock=%d, div=%u", |
| 647 | lcd_clk, crtc->mode.clock, clkdiv); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 648 | |
| 649 | /* Configure the LCD clock divisor. */ |
Darren Etheridge | 3d19306 | 2014-01-15 15:52:36 -0600 | [diff] [blame] | 650 | tilcdc_write(dev, LCDC_CTRL_REG, LCDC_CLK_DIVISOR(clkdiv) | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 651 | LCDC_RASTER_MODE); |
| 652 | |
| 653 | if (priv->rev == 2) |
| 654 | tilcdc_set(dev, LCDC_CLK_ENABLE_REG, |
| 655 | LCDC_V2_DMA_CLK_EN | LCDC_V2_LIDD_CLK_EN | |
| 656 | LCDC_V2_CORE_CLK_EN); |
| 657 | |
| 658 | if (dpms == DRM_MODE_DPMS_ON) |
| 659 | tilcdc_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
| 660 | |
| 661 | out: |
| 662 | pm_runtime_put_sync(dev->dev); |
| 663 | } |
| 664 | |
| 665 | irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) |
| 666 | { |
| 667 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 668 | struct drm_device *dev = crtc->dev; |
| 669 | struct tilcdc_drm_private *priv = dev->dev_private; |
Tomi Valkeinen | 317aae7 | 2015-10-20 12:08:03 +0300 | [diff] [blame] | 670 | uint32_t stat; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 671 | |
Tomi Valkeinen | 317aae7 | 2015-10-20 12:08:03 +0300 | [diff] [blame] | 672 | stat = tilcdc_read_irqstatus(dev); |
| 673 | tilcdc_clear_irqstatus(dev, stat); |
| 674 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 675 | if (stat & LCDC_END_OF_FRAME0) { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 676 | unsigned long flags; |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 677 | bool skip_event = false; |
| 678 | ktime_t now; |
| 679 | |
| 680 | now = ktime_get(); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 681 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 682 | drm_flip_work_commit(&tilcdc_crtc->unref_work, priv->wq); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 683 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 684 | spin_lock_irqsave(&tilcdc_crtc->irq_lock, flags); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 685 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 686 | tilcdc_crtc->last_vblank = now; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 687 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 688 | if (tilcdc_crtc->next_fb) { |
| 689 | set_scanout(crtc, tilcdc_crtc->next_fb); |
| 690 | tilcdc_crtc->next_fb = NULL; |
| 691 | skip_event = true; |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 692 | } |
| 693 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 694 | spin_unlock_irqrestore(&tilcdc_crtc->irq_lock, flags); |
| 695 | |
| 696 | drm_handle_vblank(dev, 0); |
| 697 | |
| 698 | if (!skip_event) { |
| 699 | struct drm_pending_vblank_event *event; |
| 700 | |
| 701 | spin_lock_irqsave(&dev->event_lock, flags); |
| 702 | |
| 703 | event = tilcdc_crtc->event; |
| 704 | tilcdc_crtc->event = NULL; |
| 705 | if (event) |
| 706 | drm_send_vblank_event(dev, 0, event); |
| 707 | |
| 708 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 709 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | if (priv->rev == 2) { |
| 713 | if (stat & LCDC_FRAME_DONE) { |
| 714 | tilcdc_crtc->frame_done = true; |
| 715 | wake_up(&tilcdc_crtc->frame_done_wq); |
| 716 | } |
| 717 | tilcdc_write(dev, LCDC_END_OF_INT_IND_REG, 0); |
| 718 | } |
| 719 | |
Jyri Sarha | c0c2baa | 2015-12-18 13:07:52 +0200 | [diff] [blame^] | 720 | if (stat & LCDC_SYNC_LOST) |
| 721 | dev_err_ratelimited(dev->dev, "%s(0x%08x): Sync lost", |
| 722 | __func__, stat); |
| 723 | |
| 724 | if (stat & LCDC_FIFO_UNDERFLOW) |
| 725 | dev_err_ratelimited(dev->dev, "%s(0x%08x): FIFO underfow", |
| 726 | __func__, stat); |
| 727 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 728 | return IRQ_HANDLED; |
| 729 | } |
| 730 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 731 | struct drm_crtc *tilcdc_crtc_create(struct drm_device *dev) |
| 732 | { |
| 733 | struct tilcdc_crtc *tilcdc_crtc; |
| 734 | struct drm_crtc *crtc; |
| 735 | int ret; |
| 736 | |
| 737 | tilcdc_crtc = kzalloc(sizeof(*tilcdc_crtc), GFP_KERNEL); |
| 738 | if (!tilcdc_crtc) { |
| 739 | dev_err(dev->dev, "allocation failed\n"); |
| 740 | return NULL; |
| 741 | } |
| 742 | |
| 743 | crtc = &tilcdc_crtc->base; |
| 744 | |
| 745 | tilcdc_crtc->dpms = DRM_MODE_DPMS_OFF; |
| 746 | init_waitqueue_head(&tilcdc_crtc->frame_done_wq); |
| 747 | |
Boris BREZILLON | d7f8db5 | 2014-11-14 19:30:30 +0100 | [diff] [blame] | 748 | drm_flip_work_init(&tilcdc_crtc->unref_work, |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 749 | "unref", unref_worker); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 750 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 751 | spin_lock_init(&tilcdc_crtc->irq_lock); |
| 752 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 753 | ret = drm_crtc_init(dev, crtc, &tilcdc_crtc_funcs); |
| 754 | if (ret < 0) |
| 755 | goto fail; |
| 756 | |
| 757 | drm_crtc_helper_add(crtc, &tilcdc_crtc_helper_funcs); |
| 758 | |
| 759 | return crtc; |
| 760 | |
| 761 | fail: |
| 762 | tilcdc_crtc_destroy(crtc); |
| 763 | return NULL; |
| 764 | } |