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 | |
Jyri Sarha | 47f571c | 2016-04-07 15:04:18 +0300 | [diff] [blame] | 29 | struct drm_plane primary; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 30 | const struct tilcdc_panel_info *info; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 31 | struct drm_pending_vblank_event *event; |
| 32 | int dpms; |
| 33 | wait_queue_head_t frame_done_wq; |
| 34 | bool frame_done; |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 35 | spinlock_t irq_lock; |
| 36 | |
| 37 | ktime_t last_vblank; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 38 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 39 | struct drm_framebuffer *curr_fb; |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 40 | struct drm_framebuffer *next_fb; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 41 | |
| 42 | /* for deferred fb unref's: */ |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 43 | struct drm_flip_work unref_work; |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 44 | |
| 45 | /* Only set if an external encoder is connected */ |
| 46 | bool simulate_vesa_sync; |
Jyri Sarha | 5895d08 | 2016-01-08 14:33:09 +0200 | [diff] [blame] | 47 | |
| 48 | int sync_lost_count; |
| 49 | bool frame_intact; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 50 | }; |
| 51 | #define to_tilcdc_crtc(x) container_of(x, struct tilcdc_crtc, base) |
| 52 | |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 53 | static void unref_worker(struct drm_flip_work *work, void *val) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 54 | { |
Darren Etheridge | f7b4575 | 2013-06-21 13:52:26 -0500 | [diff] [blame] | 55 | struct tilcdc_crtc *tilcdc_crtc = |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 56 | container_of(work, struct tilcdc_crtc, unref_work); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 57 | struct drm_device *dev = tilcdc_crtc->base.dev; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 58 | |
| 59 | mutex_lock(&dev->mode_config.mutex); |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 60 | drm_framebuffer_unreference(val); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 61 | mutex_unlock(&dev->mode_config.mutex); |
| 62 | } |
| 63 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 64 | static void set_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 65 | { |
| 66 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 67 | struct drm_device *dev = crtc->dev; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 68 | struct drm_gem_cma_object *gem; |
| 69 | unsigned int depth, bpp; |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 70 | dma_addr_t start, end; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 71 | |
| 72 | drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp); |
| 73 | gem = drm_fb_cma_get_gem_obj(fb, 0); |
| 74 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 75 | start = gem->paddr + fb->offsets[0] + |
| 76 | crtc->y * fb->pitches[0] + |
| 77 | crtc->x * bpp / 8; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 78 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 79 | end = start + (crtc->mode.vdisplay * fb->pitches[0]); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 80 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 81 | tilcdc_write(dev, LCDC_DMA_FB_BASE_ADDR_0_REG, start); |
| 82 | tilcdc_write(dev, LCDC_DMA_FB_CEILING_ADDR_0_REG, end); |
| 83 | |
| 84 | if (tilcdc_crtc->curr_fb) |
| 85 | drm_flip_work_queue(&tilcdc_crtc->unref_work, |
| 86 | tilcdc_crtc->curr_fb); |
| 87 | |
| 88 | tilcdc_crtc->curr_fb = fb; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 89 | } |
| 90 | |
Tomi Valkeinen | 2efec4f | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 91 | static void reset(struct drm_crtc *crtc) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 92 | { |
| 93 | struct drm_device *dev = crtc->dev; |
| 94 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 95 | |
Tomi Valkeinen | 2efec4f | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 96 | if (priv->rev != 2) |
| 97 | return; |
| 98 | |
| 99 | tilcdc_set(dev, LCDC_CLK_RESET_REG, LCDC_CLK_MAIN_RESET); |
| 100 | usleep_range(250, 1000); |
| 101 | tilcdc_clear(dev, LCDC_CLK_RESET_REG, LCDC_CLK_MAIN_RESET); |
| 102 | } |
| 103 | |
| 104 | static void start(struct drm_crtc *crtc) |
| 105 | { |
| 106 | struct drm_device *dev = crtc->dev; |
| 107 | |
| 108 | reset(crtc); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 109 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 110 | tilcdc_clear(dev, LCDC_DMA_CTRL_REG, LCDC_DUAL_FRAME_BUFFER_ENABLE); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 111 | tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_PALETTE_LOAD_MODE(DATA_ONLY)); |
| 112 | tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE); |
Jyri Sarha | d85f850e | 2016-06-15 11:16:23 +0300 | [diff] [blame] | 113 | |
| 114 | drm_crtc_vblank_on(crtc); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static void stop(struct drm_crtc *crtc) |
| 118 | { |
Jyri Sarha | 2d5be88 | 2016-04-07 20:20:23 +0300 | [diff] [blame] | 119 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 120 | struct drm_device *dev = crtc->dev; |
Jyri Sarha | 2d5be88 | 2016-04-07 20:20:23 +0300 | [diff] [blame] | 121 | struct tilcdc_drm_private *priv = dev->dev_private; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 122 | |
Jyri Sarha | 2d5be88 | 2016-04-07 20:20:23 +0300 | [diff] [blame] | 123 | tilcdc_crtc->frame_done = false; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 124 | tilcdc_clear(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE); |
Jyri Sarha | 2d5be88 | 2016-04-07 20:20:23 +0300 | [diff] [blame] | 125 | |
| 126 | /* |
| 127 | * if necessary wait for framedone irq which will still come |
| 128 | * before putting things to sleep.. |
| 129 | */ |
| 130 | if (priv->rev == 2) { |
| 131 | int ret = wait_event_timeout(tilcdc_crtc->frame_done_wq, |
| 132 | tilcdc_crtc->frame_done, |
Jyri Sarha | 437c7d9 | 2016-06-16 16:19:17 +0300 | [diff] [blame] | 133 | msecs_to_jiffies(500)); |
Jyri Sarha | 2d5be88 | 2016-04-07 20:20:23 +0300 | [diff] [blame] | 134 | if (ret == 0) |
| 135 | dev_err(dev->dev, "%s: timeout waiting for framedone\n", |
| 136 | __func__); |
| 137 | } |
Jyri Sarha | d85f850e | 2016-06-15 11:16:23 +0300 | [diff] [blame] | 138 | |
| 139 | drm_crtc_vblank_off(crtc); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void tilcdc_crtc_destroy(struct drm_crtc *crtc) |
| 143 | { |
| 144 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 145 | |
Jyri Sarha | de9cb5f | 2015-02-26 10:12:41 +0200 | [diff] [blame] | 146 | tilcdc_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 147 | |
Jyri Sarha | d66284fb | 2015-05-27 11:58:37 +0300 | [diff] [blame] | 148 | of_node_put(crtc->port); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 149 | drm_crtc_cleanup(crtc); |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 150 | drm_flip_work_cleanup(&tilcdc_crtc->unref_work); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 151 | } |
| 152 | |
Tomi Valkeinen | 6f206e9 | 2014-02-07 17:37:07 +0000 | [diff] [blame] | 153 | static int tilcdc_verify_fb(struct drm_crtc *crtc, struct drm_framebuffer *fb) |
| 154 | { |
| 155 | struct drm_device *dev = crtc->dev; |
| 156 | unsigned int depth, bpp; |
| 157 | |
| 158 | drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp); |
| 159 | |
| 160 | if (fb->pitches[0] != crtc->mode.hdisplay * bpp / 8) { |
| 161 | dev_err(dev->dev, |
| 162 | "Invalid pitch: fb and crtc widths must be the same"); |
| 163 | return -EINVAL; |
| 164 | } |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
Jyri Sarha | 8c65abb | 2016-04-07 14:56:32 +0300 | [diff] [blame] | 169 | int tilcdc_crtc_page_flip(struct drm_crtc *crtc, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 170 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 171 | struct drm_pending_vblank_event *event, |
| 172 | uint32_t page_flip_flags) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 173 | { |
| 174 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 175 | struct drm_device *dev = crtc->dev; |
Tomi Valkeinen | 6f206e9 | 2014-02-07 17:37:07 +0000 | [diff] [blame] | 176 | int r; |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 177 | unsigned long flags; |
Tomi Valkeinen | 6f206e9 | 2014-02-07 17:37:07 +0000 | [diff] [blame] | 178 | |
| 179 | r = tilcdc_verify_fb(crtc, fb); |
| 180 | if (r) |
| 181 | return r; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 182 | |
| 183 | if (tilcdc_crtc->event) { |
| 184 | dev_err(dev->dev, "already pending page flip!\n"); |
| 185 | return -EBUSY; |
| 186 | } |
| 187 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 188 | drm_framebuffer_reference(fb); |
| 189 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 190 | crtc->primary->fb = fb; |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 191 | |
| 192 | pm_runtime_get_sync(dev->dev); |
| 193 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 194 | spin_lock_irqsave(&tilcdc_crtc->irq_lock, flags); |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 195 | |
Jyri Sarha | 0a1fe1b | 2016-06-13 09:53:36 +0300 | [diff] [blame] | 196 | if (crtc->hwmode.vrefresh && ktime_to_ns(tilcdc_crtc->last_vblank)) { |
| 197 | ktime_t next_vblank; |
| 198 | s64 tdiff; |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 199 | |
Jyri Sarha | 0a1fe1b | 2016-06-13 09:53:36 +0300 | [diff] [blame] | 200 | next_vblank = ktime_add_us(tilcdc_crtc->last_vblank, |
| 201 | 1000000 / crtc->hwmode.vrefresh); |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 202 | |
Jyri Sarha | 0a1fe1b | 2016-06-13 09:53:36 +0300 | [diff] [blame] | 203 | tdiff = ktime_to_us(ktime_sub(next_vblank, ktime_get())); |
| 204 | |
| 205 | if (tdiff < TILCDC_VBLANK_SAFETY_THRESHOLD_US) |
| 206 | tilcdc_crtc->next_fb = fb; |
| 207 | } |
| 208 | |
| 209 | if (tilcdc_crtc->next_fb != fb) |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 210 | set_scanout(crtc, fb); |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 211 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 212 | tilcdc_crtc->event = event; |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 213 | |
| 214 | spin_unlock_irqrestore(&tilcdc_crtc->irq_lock, flags); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 215 | |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 216 | pm_runtime_put_sync(dev->dev); |
| 217 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 218 | return 0; |
| 219 | } |
| 220 | |
Darren Etheridge | 614b3cfe | 2014-09-25 00:59:32 +0000 | [diff] [blame] | 221 | void tilcdc_crtc_dpms(struct drm_crtc *crtc, int mode) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 222 | { |
| 223 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 224 | struct drm_device *dev = crtc->dev; |
| 225 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 226 | |
| 227 | /* we really only care about on or off: */ |
| 228 | if (mode != DRM_MODE_DPMS_ON) |
| 229 | mode = DRM_MODE_DPMS_OFF; |
| 230 | |
| 231 | if (tilcdc_crtc->dpms == mode) |
| 232 | return; |
| 233 | |
| 234 | tilcdc_crtc->dpms = mode; |
| 235 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 236 | if (mode == DRM_MODE_DPMS_ON) { |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 237 | pm_runtime_get_sync(dev->dev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 238 | start(crtc); |
| 239 | } else { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 240 | stop(crtc); |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 241 | pm_runtime_put_sync(dev->dev); |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 242 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 243 | if (tilcdc_crtc->next_fb) { |
| 244 | drm_flip_work_queue(&tilcdc_crtc->unref_work, |
| 245 | tilcdc_crtc->next_fb); |
| 246 | tilcdc_crtc->next_fb = NULL; |
| 247 | } |
| 248 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 249 | if (tilcdc_crtc->curr_fb) { |
| 250 | drm_flip_work_queue(&tilcdc_crtc->unref_work, |
| 251 | tilcdc_crtc->curr_fb); |
| 252 | tilcdc_crtc->curr_fb = NULL; |
| 253 | } |
| 254 | |
| 255 | drm_flip_work_commit(&tilcdc_crtc->unref_work, priv->wq); |
Jyri Sarha | 0a1fe1b | 2016-06-13 09:53:36 +0300 | [diff] [blame] | 256 | tilcdc_crtc->last_vblank = ktime_set(0, 0); |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 257 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 258 | } |
| 259 | |
Jyri Sarha | 8fe5616 | 2016-06-14 11:43:30 +0300 | [diff] [blame] | 260 | int tilcdc_crtc_current_dpms_state(struct drm_crtc *crtc) |
| 261 | { |
| 262 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 263 | |
| 264 | return tilcdc_crtc->dpms; |
| 265 | } |
| 266 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 267 | static bool tilcdc_crtc_mode_fixup(struct drm_crtc *crtc, |
| 268 | const struct drm_display_mode *mode, |
| 269 | struct drm_display_mode *adjusted_mode) |
| 270 | { |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 271 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 272 | |
| 273 | if (!tilcdc_crtc->simulate_vesa_sync) |
| 274 | return true; |
| 275 | |
| 276 | /* |
| 277 | * tilcdc does not generate VESA-compliant sync but aligns |
| 278 | * VS on the second edge of HS instead of first edge. |
| 279 | * We use adjusted_mode, to fixup sync by aligning both rising |
| 280 | * edges and add HSKEW offset to fix the sync. |
| 281 | */ |
| 282 | adjusted_mode->hskew = mode->hsync_end - mode->hsync_start; |
| 283 | adjusted_mode->flags |= DRM_MODE_FLAG_HSKEW; |
| 284 | |
| 285 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) { |
| 286 | adjusted_mode->flags |= DRM_MODE_FLAG_PHSYNC; |
| 287 | adjusted_mode->flags &= ~DRM_MODE_FLAG_NHSYNC; |
| 288 | } else { |
| 289 | adjusted_mode->flags |= DRM_MODE_FLAG_NHSYNC; |
| 290 | adjusted_mode->flags &= ~DRM_MODE_FLAG_PHSYNC; |
| 291 | } |
| 292 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 293 | return true; |
| 294 | } |
| 295 | |
| 296 | static void tilcdc_crtc_prepare(struct drm_crtc *crtc) |
| 297 | { |
| 298 | tilcdc_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
| 299 | } |
| 300 | |
| 301 | static void tilcdc_crtc_commit(struct drm_crtc *crtc) |
| 302 | { |
| 303 | tilcdc_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
| 304 | } |
| 305 | |
Jyri Sarha | f6382f1 | 2016-04-07 15:09:50 +0300 | [diff] [blame] | 306 | static void tilcdc_crtc_mode_set_nofb(struct drm_crtc *crtc) |
| 307 | { |
| 308 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 309 | struct drm_device *dev = crtc->dev; |
| 310 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 311 | const struct tilcdc_panel_info *info = tilcdc_crtc->info; |
| 312 | uint32_t reg, hbp, hfp, hsw, vbp, vfp, vsw; |
| 313 | struct drm_display_mode *mode = &crtc->state->adjusted_mode; |
| 314 | struct drm_framebuffer *fb = crtc->primary->state->fb; |
| 315 | |
| 316 | if (WARN_ON(!info)) |
| 317 | return; |
| 318 | |
| 319 | if (WARN_ON(!fb)) |
| 320 | return; |
| 321 | |
| 322 | pm_runtime_get_sync(dev->dev); |
| 323 | |
| 324 | /* Configure the Burst Size and fifo threshold of DMA: */ |
| 325 | reg = tilcdc_read(dev, LCDC_DMA_CTRL_REG) & ~0x00000770; |
| 326 | switch (info->dma_burst_sz) { |
| 327 | case 1: |
| 328 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_1); |
| 329 | break; |
| 330 | case 2: |
| 331 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_2); |
| 332 | break; |
| 333 | case 4: |
| 334 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_4); |
| 335 | break; |
| 336 | case 8: |
| 337 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_8); |
| 338 | break; |
| 339 | case 16: |
| 340 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_16); |
| 341 | break; |
| 342 | default: |
| 343 | dev_err(dev->dev, "invalid burst size\n"); |
| 344 | return; |
| 345 | } |
| 346 | reg |= (info->fifo_th << 8); |
| 347 | tilcdc_write(dev, LCDC_DMA_CTRL_REG, reg); |
| 348 | |
| 349 | /* Configure timings: */ |
| 350 | hbp = mode->htotal - mode->hsync_end; |
| 351 | hfp = mode->hsync_start - mode->hdisplay; |
| 352 | hsw = mode->hsync_end - mode->hsync_start; |
| 353 | vbp = mode->vtotal - mode->vsync_end; |
| 354 | vfp = mode->vsync_start - mode->vdisplay; |
| 355 | vsw = mode->vsync_end - mode->vsync_start; |
| 356 | |
| 357 | DBG("%dx%d, hbp=%u, hfp=%u, hsw=%u, vbp=%u, vfp=%u, vsw=%u", |
| 358 | mode->hdisplay, mode->vdisplay, hbp, hfp, hsw, vbp, vfp, vsw); |
| 359 | |
| 360 | /* Set AC Bias Period and Number of Transitions per Interrupt: */ |
| 361 | reg = tilcdc_read(dev, LCDC_RASTER_TIMING_2_REG) & ~0x000fff00; |
| 362 | reg |= LCDC_AC_BIAS_FREQUENCY(info->ac_bias) | |
| 363 | LCDC_AC_BIAS_TRANSITIONS_PER_INT(info->ac_bias_intrpt); |
| 364 | |
| 365 | /* |
| 366 | * subtract one from hfp, hbp, hsw because the hardware uses |
| 367 | * a value of 0 as 1 |
| 368 | */ |
| 369 | if (priv->rev == 2) { |
| 370 | /* clear bits we're going to set */ |
| 371 | reg &= ~0x78000033; |
| 372 | reg |= ((hfp-1) & 0x300) >> 8; |
| 373 | reg |= ((hbp-1) & 0x300) >> 4; |
| 374 | reg |= ((hsw-1) & 0x3c0) << 21; |
| 375 | } |
| 376 | tilcdc_write(dev, LCDC_RASTER_TIMING_2_REG, reg); |
| 377 | |
| 378 | reg = (((mode->hdisplay >> 4) - 1) << 4) | |
| 379 | (((hbp-1) & 0xff) << 24) | |
| 380 | (((hfp-1) & 0xff) << 16) | |
| 381 | (((hsw-1) & 0x3f) << 10); |
| 382 | if (priv->rev == 2) |
| 383 | reg |= (((mode->hdisplay >> 4) - 1) & 0x40) >> 3; |
| 384 | tilcdc_write(dev, LCDC_RASTER_TIMING_0_REG, reg); |
| 385 | |
| 386 | reg = ((mode->vdisplay - 1) & 0x3ff) | |
| 387 | ((vbp & 0xff) << 24) | |
| 388 | ((vfp & 0xff) << 16) | |
| 389 | (((vsw-1) & 0x3f) << 10); |
| 390 | tilcdc_write(dev, LCDC_RASTER_TIMING_1_REG, reg); |
| 391 | |
| 392 | /* |
| 393 | * be sure to set Bit 10 for the V2 LCDC controller, |
| 394 | * otherwise limited to 1024 pixels width, stopping |
| 395 | * 1920x1080 being supported. |
| 396 | */ |
| 397 | if (priv->rev == 2) { |
| 398 | if ((mode->vdisplay - 1) & 0x400) { |
| 399 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, |
| 400 | LCDC_LPP_B10); |
| 401 | } else { |
| 402 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, |
| 403 | LCDC_LPP_B10); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /* Configure display type: */ |
| 408 | reg = tilcdc_read(dev, LCDC_RASTER_CTRL_REG) & |
| 409 | ~(LCDC_TFT_MODE | LCDC_MONO_8BIT_MODE | LCDC_MONOCHROME_MODE | |
| 410 | LCDC_V2_TFT_24BPP_MODE | LCDC_V2_TFT_24BPP_UNPACK | |
| 411 | 0x000ff000 /* Palette Loading Delay bits */); |
| 412 | reg |= LCDC_TFT_MODE; /* no monochrome/passive support */ |
| 413 | if (info->tft_alt_mode) |
| 414 | reg |= LCDC_TFT_ALT_ENABLE; |
| 415 | if (priv->rev == 2) { |
| 416 | unsigned int depth, bpp; |
| 417 | |
| 418 | drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp); |
| 419 | switch (bpp) { |
| 420 | case 16: |
| 421 | break; |
| 422 | case 32: |
| 423 | reg |= LCDC_V2_TFT_24BPP_UNPACK; |
| 424 | /* fallthrough */ |
| 425 | case 24: |
| 426 | reg |= LCDC_V2_TFT_24BPP_MODE; |
| 427 | break; |
| 428 | default: |
| 429 | dev_err(dev->dev, "invalid pixel format\n"); |
| 430 | return; |
| 431 | } |
| 432 | } |
| 433 | reg |= info->fdd < 12; |
| 434 | tilcdc_write(dev, LCDC_RASTER_CTRL_REG, reg); |
| 435 | |
| 436 | if (info->invert_pxl_clk) |
| 437 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_PIXEL_CLOCK); |
| 438 | else |
| 439 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_PIXEL_CLOCK); |
| 440 | |
| 441 | if (info->sync_ctrl) |
| 442 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_CTRL); |
| 443 | else |
| 444 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_CTRL); |
| 445 | |
| 446 | if (info->sync_edge) |
| 447 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_EDGE); |
| 448 | else |
| 449 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_EDGE); |
| 450 | |
| 451 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 452 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_HSYNC); |
| 453 | else |
| 454 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_HSYNC); |
| 455 | |
| 456 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 457 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_VSYNC); |
| 458 | else |
| 459 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_VSYNC); |
| 460 | |
| 461 | if (info->raster_order) |
| 462 | tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ORDER); |
| 463 | else |
| 464 | tilcdc_clear(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ORDER); |
| 465 | |
| 466 | drm_framebuffer_reference(fb); |
| 467 | |
| 468 | set_scanout(crtc, fb); |
| 469 | |
| 470 | tilcdc_crtc_update_clk(crtc); |
| 471 | |
| 472 | pm_runtime_put_sync(dev->dev); |
| 473 | |
| 474 | crtc->hwmode = crtc->state->adjusted_mode; |
| 475 | } |
| 476 | |
Jyri Sarha | db380c5 | 2016-04-07 15:10:23 +0300 | [diff] [blame^] | 477 | static int tilcdc_crtc_atomic_check(struct drm_crtc *crtc, |
| 478 | struct drm_crtc_state *state) |
| 479 | { |
| 480 | struct drm_display_mode *mode = &state->mode; |
| 481 | int ret; |
| 482 | |
| 483 | /* If we are not active we don't care */ |
| 484 | if (!state->active) |
| 485 | return 0; |
| 486 | |
| 487 | if (state->state->planes[0].ptr != crtc->primary || |
| 488 | state->state->planes[0].state == NULL || |
| 489 | state->state->planes[0].state->crtc != crtc) { |
| 490 | dev_dbg(crtc->dev->dev, "CRTC primary plane must be present"); |
| 491 | return -EINVAL; |
| 492 | } |
| 493 | |
| 494 | ret = tilcdc_crtc_mode_valid(crtc, mode); |
| 495 | if (ret) { |
| 496 | dev_dbg(crtc->dev->dev, "Mode \"%s\" not valid", mode->name); |
| 497 | return -EINVAL; |
| 498 | } |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 503 | static int tilcdc_crtc_mode_set(struct drm_crtc *crtc, |
| 504 | struct drm_display_mode *mode, |
| 505 | struct drm_display_mode *adjusted_mode, |
| 506 | int x, int y, |
| 507 | struct drm_framebuffer *old_fb) |
| 508 | { |
| 509 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 510 | struct drm_device *dev = crtc->dev; |
| 511 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 512 | const struct tilcdc_panel_info *info = tilcdc_crtc->info; |
| 513 | uint32_t reg, hbp, hfp, hsw, vbp, vfp, vsw; |
| 514 | int ret; |
| 515 | |
| 516 | ret = tilcdc_crtc_mode_valid(crtc, mode); |
| 517 | if (WARN_ON(ret)) |
| 518 | return ret; |
| 519 | |
| 520 | if (WARN_ON(!info)) |
| 521 | return -EINVAL; |
| 522 | |
Tomi Valkeinen | 6f206e9 | 2014-02-07 17:37:07 +0000 | [diff] [blame] | 523 | ret = tilcdc_verify_fb(crtc, crtc->primary->fb); |
| 524 | if (ret) |
| 525 | return ret; |
| 526 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 527 | pm_runtime_get_sync(dev->dev); |
| 528 | |
| 529 | /* Configure the Burst Size and fifo threshold of DMA: */ |
| 530 | reg = tilcdc_read(dev, LCDC_DMA_CTRL_REG) & ~0x00000770; |
| 531 | switch (info->dma_burst_sz) { |
| 532 | case 1: |
| 533 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_1); |
| 534 | break; |
| 535 | case 2: |
| 536 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_2); |
| 537 | break; |
| 538 | case 4: |
| 539 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_4); |
| 540 | break; |
| 541 | case 8: |
| 542 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_8); |
| 543 | break; |
| 544 | case 16: |
| 545 | reg |= LCDC_DMA_BURST_SIZE(LCDC_DMA_BURST_16); |
| 546 | break; |
| 547 | default: |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | reg |= (info->fifo_th << 8); |
| 551 | tilcdc_write(dev, LCDC_DMA_CTRL_REG, reg); |
| 552 | |
| 553 | /* Configure timings: */ |
| 554 | hbp = mode->htotal - mode->hsync_end; |
| 555 | hfp = mode->hsync_start - mode->hdisplay; |
| 556 | hsw = mode->hsync_end - mode->hsync_start; |
| 557 | vbp = mode->vtotal - mode->vsync_end; |
| 558 | vfp = mode->vsync_start - mode->vdisplay; |
| 559 | vsw = mode->vsync_end - mode->vsync_start; |
| 560 | |
| 561 | DBG("%dx%d, hbp=%u, hfp=%u, hsw=%u, vbp=%u, vfp=%u, vsw=%u", |
| 562 | mode->hdisplay, mode->vdisplay, hbp, hfp, hsw, vbp, vfp, vsw); |
| 563 | |
| 564 | /* Configure the AC Bias Period and Number of Transitions per Interrupt: */ |
| 565 | reg = tilcdc_read(dev, LCDC_RASTER_TIMING_2_REG) & ~0x000fff00; |
| 566 | reg |= LCDC_AC_BIAS_FREQUENCY(info->ac_bias) | |
| 567 | LCDC_AC_BIAS_TRANSITIONS_PER_INT(info->ac_bias_intrpt); |
Darren Etheridge | db2b4bd | 2013-06-21 13:52:24 -0500 | [diff] [blame] | 568 | |
| 569 | /* |
| 570 | * subtract one from hfp, hbp, hsw because the hardware uses |
| 571 | * a value of 0 as 1 |
| 572 | */ |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 573 | if (priv->rev == 2) { |
Pantelis Antoniou | c19b3e2 | 2013-06-21 13:52:28 -0500 | [diff] [blame] | 574 | /* clear bits we're going to set */ |
| 575 | reg &= ~0x78000033; |
Darren Etheridge | db2b4bd | 2013-06-21 13:52:24 -0500 | [diff] [blame] | 576 | reg |= ((hfp-1) & 0x300) >> 8; |
| 577 | reg |= ((hbp-1) & 0x300) >> 4; |
| 578 | reg |= ((hsw-1) & 0x3c0) << 21; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 579 | } |
| 580 | tilcdc_write(dev, LCDC_RASTER_TIMING_2_REG, reg); |
| 581 | |
| 582 | reg = (((mode->hdisplay >> 4) - 1) << 4) | |
Darren Etheridge | db2b4bd | 2013-06-21 13:52:24 -0500 | [diff] [blame] | 583 | (((hbp-1) & 0xff) << 24) | |
| 584 | (((hfp-1) & 0xff) << 16) | |
| 585 | (((hsw-1) & 0x3f) << 10); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 586 | if (priv->rev == 2) |
| 587 | reg |= (((mode->hdisplay >> 4) - 1) & 0x40) >> 3; |
| 588 | tilcdc_write(dev, LCDC_RASTER_TIMING_0_REG, reg); |
| 589 | |
| 590 | reg = ((mode->vdisplay - 1) & 0x3ff) | |
| 591 | ((vbp & 0xff) << 24) | |
| 592 | ((vfp & 0xff) << 16) | |
Darren Etheridge | db2b4bd | 2013-06-21 13:52:24 -0500 | [diff] [blame] | 593 | (((vsw-1) & 0x3f) << 10); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 594 | tilcdc_write(dev, LCDC_RASTER_TIMING_1_REG, reg); |
| 595 | |
Darren Etheridge | 6bf02c6 | 2013-06-21 13:52:22 -0500 | [diff] [blame] | 596 | /* |
| 597 | * be sure to set Bit 10 for the V2 LCDC controller, |
| 598 | * otherwise limited to 1024 pixels width, stopping |
| 599 | * 1920x1080 being suppoted. |
| 600 | */ |
| 601 | if (priv->rev == 2) { |
| 602 | if ((mode->vdisplay - 1) & 0x400) { |
| 603 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, |
| 604 | LCDC_LPP_B10); |
| 605 | } else { |
| 606 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, |
| 607 | LCDC_LPP_B10); |
| 608 | } |
| 609 | } |
| 610 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 611 | /* Configure display type: */ |
| 612 | reg = tilcdc_read(dev, LCDC_RASTER_CTRL_REG) & |
| 613 | ~(LCDC_TFT_MODE | LCDC_MONO_8BIT_MODE | LCDC_MONOCHROME_MODE | |
| 614 | LCDC_V2_TFT_24BPP_MODE | LCDC_V2_TFT_24BPP_UNPACK | 0x000ff000); |
| 615 | reg |= LCDC_TFT_MODE; /* no monochrome/passive support */ |
| 616 | if (info->tft_alt_mode) |
| 617 | reg |= LCDC_TFT_ALT_ENABLE; |
| 618 | if (priv->rev == 2) { |
| 619 | unsigned int depth, bpp; |
| 620 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 621 | drm_fb_get_bpp_depth(crtc->primary->fb->pixel_format, &depth, &bpp); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 622 | switch (bpp) { |
| 623 | case 16: |
| 624 | break; |
| 625 | case 32: |
| 626 | reg |= LCDC_V2_TFT_24BPP_UNPACK; |
| 627 | /* fallthrough */ |
| 628 | case 24: |
| 629 | reg |= LCDC_V2_TFT_24BPP_MODE; |
| 630 | break; |
| 631 | default: |
| 632 | dev_err(dev->dev, "invalid pixel format\n"); |
| 633 | return -EINVAL; |
| 634 | } |
| 635 | } |
| 636 | reg |= info->fdd < 12; |
| 637 | tilcdc_write(dev, LCDC_RASTER_CTRL_REG, reg); |
| 638 | |
| 639 | if (info->invert_pxl_clk) |
| 640 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_PIXEL_CLOCK); |
| 641 | else |
| 642 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_PIXEL_CLOCK); |
| 643 | |
| 644 | if (info->sync_ctrl) |
| 645 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_CTRL); |
| 646 | else |
| 647 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_CTRL); |
| 648 | |
| 649 | if (info->sync_edge) |
| 650 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_EDGE); |
| 651 | else |
| 652 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_SYNC_EDGE); |
| 653 | |
Darren Etheridge | a976718 | 2013-08-14 21:43:33 +0200 | [diff] [blame] | 654 | /* |
| 655 | * use value from adjusted_mode here as this might have been |
| 656 | * changed as part of the fixup for slave encoders to solve the |
| 657 | * issue where tilcdc timings are not VESA compliant |
| 658 | */ |
| 659 | if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 660 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_HSYNC); |
| 661 | else |
| 662 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_HSYNC); |
| 663 | |
| 664 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 665 | tilcdc_set(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_VSYNC); |
| 666 | else |
| 667 | tilcdc_clear(dev, LCDC_RASTER_TIMING_2_REG, LCDC_INVERT_VSYNC); |
| 668 | |
| 669 | if (info->raster_order) |
| 670 | tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ORDER); |
| 671 | else |
| 672 | tilcdc_clear(dev, LCDC_RASTER_CTRL_REG, LCDC_RASTER_ORDER); |
| 673 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 674 | drm_framebuffer_reference(crtc->primary->fb); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 675 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 676 | set_scanout(crtc, crtc->primary->fb); |
| 677 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 678 | tilcdc_crtc_update_clk(crtc); |
| 679 | |
| 680 | pm_runtime_put_sync(dev->dev); |
| 681 | |
| 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | static int tilcdc_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
| 686 | struct drm_framebuffer *old_fb) |
| 687 | { |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 688 | struct drm_device *dev = crtc->dev; |
Tomi Valkeinen | 6f206e9 | 2014-02-07 17:37:07 +0000 | [diff] [blame] | 689 | int r; |
| 690 | |
| 691 | r = tilcdc_verify_fb(crtc, crtc->primary->fb); |
| 692 | if (r) |
| 693 | return r; |
| 694 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 695 | drm_framebuffer_reference(crtc->primary->fb); |
| 696 | |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 697 | pm_runtime_get_sync(dev->dev); |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 698 | |
| 699 | set_scanout(crtc, crtc->primary->fb); |
| 700 | |
Tomi Valkeinen | 65734a2 | 2015-10-19 12:30:03 +0300 | [diff] [blame] | 701 | pm_runtime_put_sync(dev->dev); |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 702 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 706 | static const struct drm_crtc_funcs tilcdc_crtc_funcs = { |
| 707 | .destroy = tilcdc_crtc_destroy, |
| 708 | .set_config = drm_crtc_helper_set_config, |
| 709 | .page_flip = tilcdc_crtc_page_flip, |
| 710 | }; |
| 711 | |
| 712 | static const struct drm_crtc_helper_funcs tilcdc_crtc_helper_funcs = { |
| 713 | .dpms = tilcdc_crtc_dpms, |
| 714 | .mode_fixup = tilcdc_crtc_mode_fixup, |
| 715 | .prepare = tilcdc_crtc_prepare, |
| 716 | .commit = tilcdc_crtc_commit, |
| 717 | .mode_set = tilcdc_crtc_mode_set, |
| 718 | .mode_set_base = tilcdc_crtc_mode_set_base, |
Jyri Sarha | db380c5 | 2016-04-07 15:10:23 +0300 | [diff] [blame^] | 719 | .atomic_check = tilcdc_crtc_atomic_check, |
Jyri Sarha | f6382f1 | 2016-04-07 15:09:50 +0300 | [diff] [blame] | 720 | .mode_set_nofb = tilcdc_crtc_mode_set_nofb, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 721 | }; |
| 722 | |
| 723 | int tilcdc_crtc_max_width(struct drm_crtc *crtc) |
| 724 | { |
| 725 | struct drm_device *dev = crtc->dev; |
| 726 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 727 | int max_width = 0; |
| 728 | |
| 729 | if (priv->rev == 1) |
| 730 | max_width = 1024; |
| 731 | else if (priv->rev == 2) |
| 732 | max_width = 2048; |
| 733 | |
| 734 | return max_width; |
| 735 | } |
| 736 | |
| 737 | int tilcdc_crtc_mode_valid(struct drm_crtc *crtc, struct drm_display_mode *mode) |
| 738 | { |
| 739 | struct tilcdc_drm_private *priv = crtc->dev->dev_private; |
| 740 | unsigned int bandwidth; |
Darren Etheridge | e1c5d0a | 2013-06-21 13:52:25 -0500 | [diff] [blame] | 741 | uint32_t hbp, hfp, hsw, vbp, vfp, vsw; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 742 | |
Darren Etheridge | e1c5d0a | 2013-06-21 13:52:25 -0500 | [diff] [blame] | 743 | /* |
| 744 | * check to see if the width is within the range that |
| 745 | * the LCD Controller physically supports |
| 746 | */ |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 747 | if (mode->hdisplay > tilcdc_crtc_max_width(crtc)) |
| 748 | return MODE_VIRTUAL_X; |
| 749 | |
| 750 | /* width must be multiple of 16 */ |
| 751 | if (mode->hdisplay & 0xf) |
| 752 | return MODE_VIRTUAL_X; |
| 753 | |
| 754 | if (mode->vdisplay > 2048) |
| 755 | return MODE_VIRTUAL_Y; |
| 756 | |
Darren Etheridge | e1c5d0a | 2013-06-21 13:52:25 -0500 | [diff] [blame] | 757 | DBG("Processing mode %dx%d@%d with pixel clock %d", |
| 758 | mode->hdisplay, mode->vdisplay, |
| 759 | drm_mode_vrefresh(mode), mode->clock); |
| 760 | |
| 761 | hbp = mode->htotal - mode->hsync_end; |
| 762 | hfp = mode->hsync_start - mode->hdisplay; |
| 763 | hsw = mode->hsync_end - mode->hsync_start; |
| 764 | vbp = mode->vtotal - mode->vsync_end; |
| 765 | vfp = mode->vsync_start - mode->vdisplay; |
| 766 | vsw = mode->vsync_end - mode->vsync_start; |
| 767 | |
| 768 | if ((hbp-1) & ~0x3ff) { |
| 769 | DBG("Pruning mode: Horizontal Back Porch out of range"); |
| 770 | return MODE_HBLANK_WIDE; |
| 771 | } |
| 772 | |
| 773 | if ((hfp-1) & ~0x3ff) { |
| 774 | DBG("Pruning mode: Horizontal Front Porch out of range"); |
| 775 | return MODE_HBLANK_WIDE; |
| 776 | } |
| 777 | |
| 778 | if ((hsw-1) & ~0x3ff) { |
| 779 | DBG("Pruning mode: Horizontal Sync Width out of range"); |
| 780 | return MODE_HSYNC_WIDE; |
| 781 | } |
| 782 | |
| 783 | if (vbp & ~0xff) { |
| 784 | DBG("Pruning mode: Vertical Back Porch out of range"); |
| 785 | return MODE_VBLANK_WIDE; |
| 786 | } |
| 787 | |
| 788 | if (vfp & ~0xff) { |
| 789 | DBG("Pruning mode: Vertical Front Porch out of range"); |
| 790 | return MODE_VBLANK_WIDE; |
| 791 | } |
| 792 | |
| 793 | if ((vsw-1) & ~0x3f) { |
| 794 | DBG("Pruning mode: Vertical Sync Width out of range"); |
| 795 | return MODE_VSYNC_WIDE; |
| 796 | } |
| 797 | |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 798 | /* |
| 799 | * some devices have a maximum allowed pixel clock |
| 800 | * configured from the DT |
| 801 | */ |
| 802 | if (mode->clock > priv->max_pixelclock) { |
Darren Etheridge | f7b4575 | 2013-06-21 13:52:26 -0500 | [diff] [blame] | 803 | DBG("Pruning mode: pixel clock too high"); |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 804 | return MODE_CLOCK_HIGH; |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * some devices further limit the max horizontal resolution |
| 809 | * configured from the DT |
| 810 | */ |
| 811 | if (mode->hdisplay > priv->max_width) |
| 812 | return MODE_BAD_WIDTH; |
| 813 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 814 | /* filter out modes that would require too much memory bandwidth: */ |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 815 | bandwidth = mode->hdisplay * mode->vdisplay * |
| 816 | drm_mode_vrefresh(mode); |
| 817 | if (bandwidth > priv->max_bandwidth) { |
Darren Etheridge | f7b4575 | 2013-06-21 13:52:26 -0500 | [diff] [blame] | 818 | DBG("Pruning mode: exceeds defined bandwidth limit"); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 819 | return MODE_BAD; |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 820 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 821 | |
| 822 | return MODE_OK; |
| 823 | } |
| 824 | |
| 825 | void tilcdc_crtc_set_panel_info(struct drm_crtc *crtc, |
| 826 | const struct tilcdc_panel_info *info) |
| 827 | { |
| 828 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 829 | tilcdc_crtc->info = info; |
| 830 | } |
| 831 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 832 | void tilcdc_crtc_set_simulate_vesa_sync(struct drm_crtc *crtc, |
| 833 | bool simulate_vesa_sync) |
| 834 | { |
| 835 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 836 | |
| 837 | tilcdc_crtc->simulate_vesa_sync = simulate_vesa_sync; |
| 838 | } |
| 839 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 840 | void tilcdc_crtc_update_clk(struct drm_crtc *crtc) |
| 841 | { |
| 842 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 843 | struct drm_device *dev = crtc->dev; |
| 844 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 845 | int dpms = tilcdc_crtc->dpms; |
Darren Etheridge | 3d19306 | 2014-01-15 15:52:36 -0600 | [diff] [blame] | 846 | unsigned long lcd_clk; |
| 847 | const unsigned clkdiv = 2; /* using a fixed divider of 2 */ |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 848 | int ret; |
| 849 | |
| 850 | pm_runtime_get_sync(dev->dev); |
| 851 | |
| 852 | if (dpms == DRM_MODE_DPMS_ON) |
| 853 | tilcdc_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
| 854 | |
Darren Etheridge | 3d19306 | 2014-01-15 15:52:36 -0600 | [diff] [blame] | 855 | /* mode.clock is in KHz, set_rate wants parameter in Hz */ |
| 856 | ret = clk_set_rate(priv->clk, crtc->mode.clock * 1000 * clkdiv); |
| 857 | if (ret < 0) { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 858 | dev_err(dev->dev, "failed to set display clock rate to: %d\n", |
| 859 | crtc->mode.clock); |
| 860 | goto out; |
| 861 | } |
| 862 | |
| 863 | lcd_clk = clk_get_rate(priv->clk); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 864 | |
Darren Etheridge | 3d19306 | 2014-01-15 15:52:36 -0600 | [diff] [blame] | 865 | DBG("lcd_clk=%lu, mode clock=%d, div=%u", |
| 866 | lcd_clk, crtc->mode.clock, clkdiv); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 867 | |
| 868 | /* Configure the LCD clock divisor. */ |
Darren Etheridge | 3d19306 | 2014-01-15 15:52:36 -0600 | [diff] [blame] | 869 | tilcdc_write(dev, LCDC_CTRL_REG, LCDC_CLK_DIVISOR(clkdiv) | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 870 | LCDC_RASTER_MODE); |
| 871 | |
| 872 | if (priv->rev == 2) |
| 873 | tilcdc_set(dev, LCDC_CLK_ENABLE_REG, |
| 874 | LCDC_V2_DMA_CLK_EN | LCDC_V2_LIDD_CLK_EN | |
| 875 | LCDC_V2_CORE_CLK_EN); |
| 876 | |
| 877 | if (dpms == DRM_MODE_DPMS_ON) |
| 878 | tilcdc_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
| 879 | |
| 880 | out: |
| 881 | pm_runtime_put_sync(dev->dev); |
| 882 | } |
| 883 | |
Jyri Sarha | 5895d08 | 2016-01-08 14:33:09 +0200 | [diff] [blame] | 884 | #define SYNC_LOST_COUNT_LIMIT 50 |
| 885 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 886 | irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) |
| 887 | { |
| 888 | struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); |
| 889 | struct drm_device *dev = crtc->dev; |
| 890 | struct tilcdc_drm_private *priv = dev->dev_private; |
Tomi Valkeinen | 317aae7 | 2015-10-20 12:08:03 +0300 | [diff] [blame] | 891 | uint32_t stat; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 892 | |
Tomi Valkeinen | 317aae7 | 2015-10-20 12:08:03 +0300 | [diff] [blame] | 893 | stat = tilcdc_read_irqstatus(dev); |
| 894 | tilcdc_clear_irqstatus(dev, stat); |
| 895 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 896 | if (stat & LCDC_END_OF_FRAME0) { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 897 | unsigned long flags; |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 898 | bool skip_event = false; |
| 899 | ktime_t now; |
| 900 | |
| 901 | now = ktime_get(); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 902 | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 903 | drm_flip_work_commit(&tilcdc_crtc->unref_work, priv->wq); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 904 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 905 | spin_lock_irqsave(&tilcdc_crtc->irq_lock, flags); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 906 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 907 | tilcdc_crtc->last_vblank = now; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 908 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 909 | if (tilcdc_crtc->next_fb) { |
| 910 | set_scanout(crtc, tilcdc_crtc->next_fb); |
| 911 | tilcdc_crtc->next_fb = NULL; |
| 912 | skip_event = true; |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 913 | } |
| 914 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 915 | spin_unlock_irqrestore(&tilcdc_crtc->irq_lock, flags); |
| 916 | |
Gustavo Padovan | 099ede8 | 2016-07-04 21:04:52 -0300 | [diff] [blame] | 917 | drm_crtc_handle_vblank(crtc); |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 918 | |
| 919 | if (!skip_event) { |
| 920 | struct drm_pending_vblank_event *event; |
| 921 | |
| 922 | spin_lock_irqsave(&dev->event_lock, flags); |
| 923 | |
| 924 | event = tilcdc_crtc->event; |
| 925 | tilcdc_crtc->event = NULL; |
| 926 | if (event) |
Gustavo Padovan | dfebc15 | 2016-04-14 10:48:22 -0700 | [diff] [blame] | 927 | drm_crtc_send_vblank_event(crtc, event); |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 928 | |
| 929 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 930 | } |
Jyri Sarha | 5895d08 | 2016-01-08 14:33:09 +0200 | [diff] [blame] | 931 | |
| 932 | if (tilcdc_crtc->frame_intact) |
| 933 | tilcdc_crtc->sync_lost_count = 0; |
| 934 | else |
| 935 | tilcdc_crtc->frame_intact = true; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 936 | } |
| 937 | |
Jyri Sarha | 1494411 | 2016-04-07 20:36:48 +0300 | [diff] [blame] | 938 | if (stat & LCDC_FIFO_UNDERFLOW) |
| 939 | dev_err_ratelimited(dev->dev, "%s(0x%08x): FIFO underfow", |
| 940 | __func__, stat); |
| 941 | |
| 942 | /* For revision 2 only */ |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 943 | if (priv->rev == 2) { |
| 944 | if (stat & LCDC_FRAME_DONE) { |
| 945 | tilcdc_crtc->frame_done = true; |
| 946 | wake_up(&tilcdc_crtc->frame_done_wq); |
| 947 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 948 | |
Jyri Sarha | 1abcdac | 2016-06-17 11:54:06 +0300 | [diff] [blame] | 949 | if (stat & LCDC_SYNC_LOST) { |
| 950 | dev_err_ratelimited(dev->dev, "%s(0x%08x): Sync lost", |
| 951 | __func__, stat); |
| 952 | tilcdc_crtc->frame_intact = false; |
| 953 | if (tilcdc_crtc->sync_lost_count++ > |
| 954 | SYNC_LOST_COUNT_LIMIT) { |
| 955 | dev_err(dev->dev, "%s(0x%08x): Sync lost flood detected, disabling the interrupt", __func__, stat); |
| 956 | tilcdc_write(dev, LCDC_INT_ENABLE_CLR_REG, |
| 957 | LCDC_SYNC_LOST); |
| 958 | } |
Jyri Sarha | 5895d08 | 2016-01-08 14:33:09 +0200 | [diff] [blame] | 959 | } |
Jyri Sarha | c0c2baa | 2015-12-18 13:07:52 +0200 | [diff] [blame] | 960 | |
Jyri Sarha | 1494411 | 2016-04-07 20:36:48 +0300 | [diff] [blame] | 961 | /* Indicate to LCDC that the interrupt service routine has |
| 962 | * completed, see 13.3.6.1.6 in AM335x TRM. |
| 963 | */ |
| 964 | tilcdc_write(dev, LCDC_END_OF_INT_IND_REG, 0); |
| 965 | } |
Jyri Sarha | c0c2baa | 2015-12-18 13:07:52 +0200 | [diff] [blame] | 966 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 967 | return IRQ_HANDLED; |
| 968 | } |
| 969 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 970 | struct drm_crtc *tilcdc_crtc_create(struct drm_device *dev) |
| 971 | { |
Jyri Sarha | d66284fb | 2015-05-27 11:58:37 +0300 | [diff] [blame] | 972 | struct tilcdc_drm_private *priv = dev->dev_private; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 973 | struct tilcdc_crtc *tilcdc_crtc; |
| 974 | struct drm_crtc *crtc; |
| 975 | int ret; |
| 976 | |
Jyri Sarha | d0ec32c | 2016-02-23 12:44:27 +0200 | [diff] [blame] | 977 | tilcdc_crtc = devm_kzalloc(dev->dev, sizeof(*tilcdc_crtc), GFP_KERNEL); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 978 | if (!tilcdc_crtc) { |
| 979 | dev_err(dev->dev, "allocation failed\n"); |
| 980 | return NULL; |
| 981 | } |
| 982 | |
| 983 | crtc = &tilcdc_crtc->base; |
| 984 | |
Jyri Sarha | 47f571c | 2016-04-07 15:04:18 +0300 | [diff] [blame] | 985 | ret = tilcdc_plane_init(dev, &tilcdc_crtc->primary); |
| 986 | if (ret < 0) |
| 987 | goto fail; |
| 988 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 989 | tilcdc_crtc->dpms = DRM_MODE_DPMS_OFF; |
| 990 | init_waitqueue_head(&tilcdc_crtc->frame_done_wq); |
| 991 | |
Boris BREZILLON | d7f8db5 | 2014-11-14 19:30:30 +0100 | [diff] [blame] | 992 | drm_flip_work_init(&tilcdc_crtc->unref_work, |
Rob Clark | a464d61 | 2013-08-07 13:41:20 -0400 | [diff] [blame] | 993 | "unref", unref_worker); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 994 | |
Tomi Valkeinen | 2b3a8cd | 2015-11-03 12:00:51 +0200 | [diff] [blame] | 995 | spin_lock_init(&tilcdc_crtc->irq_lock); |
| 996 | |
Jyri Sarha | 47f571c | 2016-04-07 15:04:18 +0300 | [diff] [blame] | 997 | ret = drm_crtc_init_with_planes(dev, crtc, |
| 998 | &tilcdc_crtc->primary, |
| 999 | NULL, |
| 1000 | &tilcdc_crtc_funcs, |
| 1001 | "tilcdc crtc"); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 1002 | if (ret < 0) |
| 1003 | goto fail; |
| 1004 | |
| 1005 | drm_crtc_helper_add(crtc, &tilcdc_crtc_helper_funcs); |
| 1006 | |
Jyri Sarha | d66284fb | 2015-05-27 11:58:37 +0300 | [diff] [blame] | 1007 | if (priv->is_componentized) { |
| 1008 | struct device_node *ports = |
| 1009 | of_get_child_by_name(dev->dev->of_node, "ports"); |
| 1010 | |
| 1011 | if (ports) { |
| 1012 | crtc->port = of_get_child_by_name(ports, "port"); |
| 1013 | of_node_put(ports); |
| 1014 | } else { |
| 1015 | crtc->port = |
| 1016 | of_get_child_by_name(dev->dev->of_node, "port"); |
| 1017 | } |
| 1018 | if (!crtc->port) { /* This should never happen */ |
| 1019 | dev_err(dev->dev, "Port node not found in %s\n", |
| 1020 | dev->dev->of_node->full_name); |
| 1021 | goto fail; |
| 1022 | } |
| 1023 | } |
| 1024 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 1025 | return crtc; |
| 1026 | |
| 1027 | fail: |
| 1028 | tilcdc_crtc_destroy(crtc); |
| 1029 | return NULL; |
| 1030 | } |