Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 2 | /* |
Andrew F. Davis | bb5cdf8 | 2017-12-05 14:29:31 -0600 | [diff] [blame] | 3 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 4 | * Author: Rob Clark <rob@ti.com> |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 7 | #include <drm/drm_atomic.h> |
| 8 | #include <drm/drm_atomic_helper.h> |
Laurent Pinchart | 2d278f5 | 2015-03-05 21:31:37 +0200 | [diff] [blame] | 9 | #include <drm/drm_crtc.h> |
Andy Gross | b9ed9f0 | 2012-10-16 00:17:40 -0500 | [diff] [blame] | 10 | #include <drm/drm_mode.h> |
Daniel Vetter | 3cb9ae4 | 2014-10-29 10:03:57 +0100 | [diff] [blame] | 11 | #include <drm/drm_plane_helper.h> |
Peter Ujfalusi | a7631c4 | 2017-11-30 14:12:37 +0200 | [diff] [blame] | 12 | #include <linux/math64.h> |
Laurent Pinchart | 2d278f5 | 2015-03-05 21:31:37 +0200 | [diff] [blame] | 13 | |
| 14 | #include "omap_drv.h" |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 15 | |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 16 | #define to_omap_crtc_state(x) container_of(x, struct omap_crtc_state, base) |
| 17 | |
| 18 | struct omap_crtc_state { |
| 19 | /* Must be first. */ |
| 20 | struct drm_crtc_state base; |
| 21 | /* Shadow values for legacy userspace support. */ |
| 22 | unsigned int rotation; |
| 23 | unsigned int zpos; |
| 24 | }; |
| 25 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 26 | #define to_omap_crtc(x) container_of(x, struct omap_crtc, base) |
| 27 | |
| 28 | struct omap_crtc { |
| 29 | struct drm_crtc base; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 30 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 31 | const char *name; |
Laurent Pinchart | 67dfd2d | 2018-03-06 23:38:21 +0200 | [diff] [blame] | 32 | struct omap_drm_pipeline *pipe; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 33 | enum omap_channel channel; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 34 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 35 | struct videomode vm; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 36 | |
Tomi Valkeinen | a36af73 | 2015-02-26 15:20:24 +0200 | [diff] [blame] | 37 | bool ignore_digit_sync_lost; |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 38 | |
Laurent Pinchart | f933a3a | 2016-04-18 02:54:31 +0300 | [diff] [blame] | 39 | bool enabled; |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 40 | bool pending; |
| 41 | wait_queue_head_t pending_wait; |
Laurent Pinchart | 577d398 | 2016-04-19 01:15:11 +0300 | [diff] [blame] | 42 | struct drm_pending_vblank_event *event; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 43 | }; |
| 44 | |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 45 | /* ----------------------------------------------------------------------------- |
| 46 | * Helper Functions |
| 47 | */ |
| 48 | |
Peter Ujfalusi | 4520ff2 | 2016-09-22 14:07:03 +0300 | [diff] [blame] | 49 | struct videomode *omap_crtc_timings(struct drm_crtc *crtc) |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 50 | { |
| 51 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 52 | return &omap_crtc->vm; |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | enum omap_channel omap_crtc_channel(struct drm_crtc *crtc) |
| 56 | { |
| 57 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 58 | return omap_crtc->channel; |
| 59 | } |
| 60 | |
Laurent Pinchart | d173d3d | 2016-04-19 01:31:21 +0300 | [diff] [blame] | 61 | static bool omap_crtc_is_pending(struct drm_crtc *crtc) |
| 62 | { |
| 63 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 64 | unsigned long flags; |
| 65 | bool pending; |
| 66 | |
| 67 | spin_lock_irqsave(&crtc->dev->event_lock, flags); |
| 68 | pending = omap_crtc->pending; |
| 69 | spin_unlock_irqrestore(&crtc->dev->event_lock, flags); |
| 70 | |
| 71 | return pending; |
| 72 | } |
| 73 | |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 74 | int omap_crtc_wait_pending(struct drm_crtc *crtc) |
| 75 | { |
| 76 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 77 | |
Tomi Valkeinen | 61f3c40 | 2015-11-19 17:31:25 +0200 | [diff] [blame] | 78 | /* |
| 79 | * Timeout is set to a "sufficiently" high value, which should cover |
| 80 | * a single frame refresh even on slower displays. |
| 81 | */ |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 82 | return wait_event_timeout(omap_crtc->pending_wait, |
Laurent Pinchart | d173d3d | 2016-04-19 01:31:21 +0300 | [diff] [blame] | 83 | !omap_crtc_is_pending(crtc), |
Tomi Valkeinen | 61f3c40 | 2015-11-19 17:31:25 +0200 | [diff] [blame] | 84 | msecs_to_jiffies(250)); |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 85 | } |
| 86 | |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 87 | /* ----------------------------------------------------------------------------- |
| 88 | * DSS Manager Functions |
| 89 | */ |
| 90 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 91 | /* |
| 92 | * Manager-ops, callbacks from output when they need to configure |
| 93 | * the upstream part of the video pipe. |
| 94 | * |
| 95 | * Most of these we can ignore until we add support for command-mode |
| 96 | * panels.. for video-mode the crtc-helpers already do an adequate |
| 97 | * job of sequencing the setup of the video pipe in the proper order |
| 98 | */ |
| 99 | |
| 100 | /* we can probably ignore these until we support command-mode panels: */ |
Laurent Pinchart | 64cb817 | 2018-02-13 14:00:39 +0200 | [diff] [blame] | 101 | static void omap_crtc_dss_start_update(struct omap_drm_private *priv, |
| 102 | enum omap_channel channel) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 103 | { |
| 104 | } |
| 105 | |
Laurent Pinchart | 4029755e | 2015-05-28 02:34:05 +0300 | [diff] [blame] | 106 | /* Called only from the encoder enable/disable and suspend/resume handlers. */ |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 107 | static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable) |
| 108 | { |
| 109 | struct drm_device *dev = crtc->dev; |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 110 | struct omap_drm_private *priv = dev->dev_private; |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 111 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 112 | enum omap_channel channel = omap_crtc->channel; |
| 113 | struct omap_irq_wait *wait; |
| 114 | u32 framedone_irq, vsync_irq; |
| 115 | int ret; |
| 116 | |
Laurent Pinchart | 03af815 | 2016-04-18 03:09:48 +0300 | [diff] [blame] | 117 | if (WARN_ON(omap_crtc->enabled == enable)) |
| 118 | return; |
| 119 | |
Laurent Pinchart | 0dbfc39 | 2018-12-10 14:00:38 +0200 | [diff] [blame] | 120 | if (omap_crtc->pipe->output->type == OMAP_DISPLAY_TYPE_HDMI) { |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 121 | priv->dispc_ops->mgr_enable(priv->dispc, channel, enable); |
Laurent Pinchart | f933a3a | 2016-04-18 02:54:31 +0300 | [diff] [blame] | 122 | omap_crtc->enabled = enable; |
Tomi Valkeinen | 4e4b53c | 2015-03-24 15:46:35 +0200 | [diff] [blame] | 123 | return; |
| 124 | } |
| 125 | |
Tomi Valkeinen | ef42228 | 2015-02-26 15:20:25 +0200 | [diff] [blame] | 126 | if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) { |
| 127 | /* |
| 128 | * Digit output produces some sync lost interrupts during the |
| 129 | * first frame when enabling, so we need to ignore those. |
| 130 | */ |
| 131 | omap_crtc->ignore_digit_sync_lost = true; |
| 132 | } |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 133 | |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 134 | framedone_irq = priv->dispc_ops->mgr_get_framedone_irq(priv->dispc, |
| 135 | channel); |
| 136 | vsync_irq = priv->dispc_ops->mgr_get_vsync_irq(priv->dispc, channel); |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 137 | |
| 138 | if (enable) { |
| 139 | wait = omap_irq_wait_init(dev, vsync_irq, 1); |
| 140 | } else { |
| 141 | /* |
| 142 | * When we disable the digit output, we need to wait for |
| 143 | * FRAMEDONE to know that DISPC has finished with the output. |
| 144 | * |
| 145 | * OMAP2/3 does not have FRAMEDONE irq for digit output, and in |
| 146 | * that case we need to use vsync interrupt, and wait for both |
| 147 | * even and odd frames. |
| 148 | */ |
| 149 | |
| 150 | if (framedone_irq) |
| 151 | wait = omap_irq_wait_init(dev, framedone_irq, 1); |
| 152 | else |
| 153 | wait = omap_irq_wait_init(dev, vsync_irq, 2); |
| 154 | } |
| 155 | |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 156 | priv->dispc_ops->mgr_enable(priv->dispc, channel, enable); |
Laurent Pinchart | f933a3a | 2016-04-18 02:54:31 +0300 | [diff] [blame] | 157 | omap_crtc->enabled = enable; |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 158 | |
| 159 | ret = omap_irq_wait(dev, wait, msecs_to_jiffies(100)); |
| 160 | if (ret) { |
| 161 | dev_err(dev->dev, "%s: timeout waiting for %s\n", |
| 162 | omap_crtc->name, enable ? "enable" : "disable"); |
| 163 | } |
| 164 | |
Tomi Valkeinen | ef42228 | 2015-02-26 15:20:25 +0200 | [diff] [blame] | 165 | if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) { |
| 166 | omap_crtc->ignore_digit_sync_lost = false; |
| 167 | /* make sure the irq handler sees the value above */ |
| 168 | mb(); |
| 169 | } |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 170 | } |
| 171 | |
Tomi Valkeinen | 506096a | 2014-04-03 13:11:54 +0300 | [diff] [blame] | 172 | |
Laurent Pinchart | 64cb817 | 2018-02-13 14:00:39 +0200 | [diff] [blame] | 173 | static int omap_crtc_dss_enable(struct omap_drm_private *priv, |
| 174 | enum omap_channel channel) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 175 | { |
Laurent Pinchart | e48f9f1 | 2018-03-07 00:01:33 +0200 | [diff] [blame] | 176 | struct drm_crtc *crtc = priv->channels[channel]->crtc; |
| 177 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Tomi Valkeinen | 506096a | 2014-04-03 13:11:54 +0300 | [diff] [blame] | 178 | |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 179 | priv->dispc_ops->mgr_set_timings(priv->dispc, omap_crtc->channel, |
| 180 | &omap_crtc->vm); |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 181 | omap_crtc_set_enabled(&omap_crtc->base, true); |
Tomi Valkeinen | 506096a | 2014-04-03 13:11:54 +0300 | [diff] [blame] | 182 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 183 | return 0; |
| 184 | } |
| 185 | |
Laurent Pinchart | 64cb817 | 2018-02-13 14:00:39 +0200 | [diff] [blame] | 186 | static void omap_crtc_dss_disable(struct omap_drm_private *priv, |
| 187 | enum omap_channel channel) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 188 | { |
Laurent Pinchart | e48f9f1 | 2018-03-07 00:01:33 +0200 | [diff] [blame] | 189 | struct drm_crtc *crtc = priv->channels[channel]->crtc; |
| 190 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Tomi Valkeinen | 506096a | 2014-04-03 13:11:54 +0300 | [diff] [blame] | 191 | |
Laurent Pinchart | 8472b57 | 2015-01-15 00:45:17 +0200 | [diff] [blame] | 192 | omap_crtc_set_enabled(&omap_crtc->base, false); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 193 | } |
| 194 | |
Laurent Pinchart | 64cb817 | 2018-02-13 14:00:39 +0200 | [diff] [blame] | 195 | static void omap_crtc_dss_set_timings(struct omap_drm_private *priv, |
| 196 | enum omap_channel channel, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 197 | const struct videomode *vm) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 198 | { |
Laurent Pinchart | e48f9f1 | 2018-03-07 00:01:33 +0200 | [diff] [blame] | 199 | struct drm_crtc *crtc = priv->channels[channel]->crtc; |
| 200 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 201 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 202 | DBG("%s", omap_crtc->name); |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 203 | omap_crtc->vm = *vm; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 204 | } |
| 205 | |
Laurent Pinchart | 64cb817 | 2018-02-13 14:00:39 +0200 | [diff] [blame] | 206 | static void omap_crtc_dss_set_lcd_config(struct omap_drm_private *priv, |
| 207 | enum omap_channel channel, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 208 | const struct dss_lcd_mgr_config *config) |
| 209 | { |
Laurent Pinchart | e48f9f1 | 2018-03-07 00:01:33 +0200 | [diff] [blame] | 210 | struct drm_crtc *crtc = priv->channels[channel]->crtc; |
| 211 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 212 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 213 | DBG("%s", omap_crtc->name); |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 214 | priv->dispc_ops->mgr_set_lcd_config(priv->dispc, omap_crtc->channel, |
| 215 | config); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 216 | } |
| 217 | |
Laurent Pinchart | 4343f0f | 2015-03-05 22:01:02 +0200 | [diff] [blame] | 218 | static int omap_crtc_dss_register_framedone( |
Laurent Pinchart | 64cb817 | 2018-02-13 14:00:39 +0200 | [diff] [blame] | 219 | struct omap_drm_private *priv, enum omap_channel channel, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 220 | void (*handler)(void *), void *data) |
| 221 | { |
| 222 | return 0; |
| 223 | } |
| 224 | |
Laurent Pinchart | 4343f0f | 2015-03-05 22:01:02 +0200 | [diff] [blame] | 225 | static void omap_crtc_dss_unregister_framedone( |
Laurent Pinchart | 64cb817 | 2018-02-13 14:00:39 +0200 | [diff] [blame] | 226 | struct omap_drm_private *priv, enum omap_channel channel, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 227 | void (*handler)(void *), void *data) |
| 228 | { |
| 229 | } |
| 230 | |
| 231 | static const struct dss_mgr_ops mgr_ops = { |
Laurent Pinchart | 4343f0f | 2015-03-05 22:01:02 +0200 | [diff] [blame] | 232 | .start_update = omap_crtc_dss_start_update, |
| 233 | .enable = omap_crtc_dss_enable, |
| 234 | .disable = omap_crtc_dss_disable, |
| 235 | .set_timings = omap_crtc_dss_set_timings, |
| 236 | .set_lcd_config = omap_crtc_dss_set_lcd_config, |
| 237 | .register_framedone_handler = omap_crtc_dss_register_framedone, |
| 238 | .unregister_framedone_handler = omap_crtc_dss_unregister_framedone, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 239 | }; |
| 240 | |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 241 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 1d5e5ea | 2015-01-18 16:57:36 +0200 | [diff] [blame] | 242 | * Setup, Flush and Page Flip |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 243 | */ |
| 244 | |
Laurent Pinchart | dfe9cfc | 2018-02-11 15:07:33 +0200 | [diff] [blame] | 245 | void omap_crtc_error_irq(struct drm_crtc *crtc, u32 irqstatus) |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 246 | { |
Laurent Pinchart | e0519af | 2015-05-28 00:21:29 +0300 | [diff] [blame] | 247 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Tomi Valkeinen | a36af73 | 2015-02-26 15:20:24 +0200 | [diff] [blame] | 248 | |
| 249 | if (omap_crtc->ignore_digit_sync_lost) { |
| 250 | irqstatus &= ~DISPC_IRQ_SYNC_LOST_DIGIT; |
| 251 | if (!irqstatus) |
| 252 | return; |
| 253 | } |
| 254 | |
Tomi Valkeinen | 3b143fc | 2014-11-19 12:50:13 +0200 | [diff] [blame] | 255 | DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_crtc->name, irqstatus); |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 256 | } |
| 257 | |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 258 | void omap_crtc_vblank_irq(struct drm_crtc *crtc) |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 259 | { |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 260 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 261 | struct drm_device *dev = omap_crtc->base.dev; |
| 262 | struct omap_drm_private *priv = dev->dev_private; |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 263 | bool pending; |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 264 | |
Laurent Pinchart | d173d3d | 2016-04-19 01:31:21 +0300 | [diff] [blame] | 265 | spin_lock(&crtc->dev->event_lock); |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 266 | /* |
| 267 | * If the dispc is busy we're racing the flush operation. Try again on |
| 268 | * the next vblank interrupt. |
| 269 | */ |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 270 | if (priv->dispc_ops->mgr_go_busy(priv->dispc, omap_crtc->channel)) { |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 271 | spin_unlock(&crtc->dev->event_lock); |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | /* Send the vblank event if one has been requested. */ |
| 276 | if (omap_crtc->event) { |
| 277 | drm_crtc_send_vblank_event(crtc, omap_crtc->event); |
| 278 | omap_crtc->event = NULL; |
| 279 | } |
| 280 | |
| 281 | pending = omap_crtc->pending; |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 282 | omap_crtc->pending = false; |
Laurent Pinchart | d173d3d | 2016-04-19 01:31:21 +0300 | [diff] [blame] | 283 | spin_unlock(&crtc->dev->event_lock); |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 284 | |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 285 | if (pending) |
| 286 | drm_crtc_vblank_put(crtc); |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 287 | |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 288 | /* Wake up omap_atomic_complete. */ |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 289 | wake_up(&omap_crtc->pending_wait); |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 290 | |
| 291 | DBG("%s: apply done", omap_crtc->name); |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Tomi Valkeinen | 7e3d927 | 2015-08-10 12:08:50 +0300 | [diff] [blame] | 294 | static void omap_crtc_write_crtc_properties(struct drm_crtc *crtc) |
| 295 | { |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 296 | struct omap_drm_private *priv = crtc->dev->dev_private; |
Tomi Valkeinen | 7e3d927 | 2015-08-10 12:08:50 +0300 | [diff] [blame] | 297 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 298 | struct omap_overlay_manager_info info; |
| 299 | |
| 300 | memset(&info, 0, sizeof(info)); |
| 301 | |
| 302 | info.default_color = 0x000000; |
| 303 | info.trans_enabled = false; |
| 304 | info.partial_alpha_enabled = false; |
| 305 | info.cpr_enable = false; |
| 306 | |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 307 | priv->dispc_ops->mgr_setup(priv->dispc, omap_crtc->channel, &info); |
Tomi Valkeinen | 7e3d927 | 2015-08-10 12:08:50 +0300 | [diff] [blame] | 308 | } |
| 309 | |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 310 | /* ----------------------------------------------------------------------------- |
| 311 | * CRTC Functions |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 312 | */ |
| 313 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 314 | static void omap_crtc_destroy(struct drm_crtc *crtc) |
| 315 | { |
| 316 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 317 | |
| 318 | DBG("%s", omap_crtc->name); |
| 319 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 320 | drm_crtc_cleanup(crtc); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 321 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 322 | kfree(omap_crtc); |
| 323 | } |
| 324 | |
Laurent Pinchart | ce9a8f1 | 2017-05-09 01:27:09 +0300 | [diff] [blame] | 325 | static void omap_crtc_arm_event(struct drm_crtc *crtc) |
| 326 | { |
| 327 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 328 | |
| 329 | WARN_ON(omap_crtc->pending); |
| 330 | omap_crtc->pending = true; |
| 331 | |
| 332 | if (crtc->state->event) { |
| 333 | omap_crtc->event = crtc->state->event; |
| 334 | crtc->state->event = NULL; |
| 335 | } |
| 336 | } |
| 337 | |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 338 | static void omap_crtc_atomic_enable(struct drm_crtc *crtc, |
| 339 | struct drm_crtc_state *old_state) |
Laurent Pinchart | f1d57fb | 2015-03-05 22:13:22 +0200 | [diff] [blame] | 340 | { |
Laurent Pinchart | 24ec84e | 2018-11-10 13:16:54 +0200 | [diff] [blame] | 341 | struct omap_drm_private *priv = crtc->dev->dev_private; |
Laurent Pinchart | f1d57fb | 2015-03-05 22:13:22 +0200 | [diff] [blame] | 342 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 343 | int ret; |
Laurent Pinchart | f1d57fb | 2015-03-05 22:13:22 +0200 | [diff] [blame] | 344 | |
| 345 | DBG("%s", omap_crtc->name); |
| 346 | |
Laurent Pinchart | 24ec84e | 2018-11-10 13:16:54 +0200 | [diff] [blame] | 347 | priv->dispc_ops->runtime_get(priv->dispc); |
| 348 | |
Laurent Pinchart | d173d3d | 2016-04-19 01:31:21 +0300 | [diff] [blame] | 349 | spin_lock_irq(&crtc->dev->event_lock); |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 350 | drm_crtc_vblank_on(crtc); |
| 351 | ret = drm_crtc_vblank_get(crtc); |
| 352 | WARN_ON(ret != 0); |
| 353 | |
Laurent Pinchart | ce9a8f1 | 2017-05-09 01:27:09 +0300 | [diff] [blame] | 354 | omap_crtc_arm_event(crtc); |
Laurent Pinchart | d173d3d | 2016-04-19 01:31:21 +0300 | [diff] [blame] | 355 | spin_unlock_irq(&crtc->dev->event_lock); |
Laurent Pinchart | f1d57fb | 2015-03-05 22:13:22 +0200 | [diff] [blame] | 356 | } |
| 357 | |
Laurent Pinchart | 6458171 | 2017-06-30 12:36:45 +0300 | [diff] [blame] | 358 | static void omap_crtc_atomic_disable(struct drm_crtc *crtc, |
| 359 | struct drm_crtc_state *old_state) |
Laurent Pinchart | f1d57fb | 2015-03-05 22:13:22 +0200 | [diff] [blame] | 360 | { |
Laurent Pinchart | 24ec84e | 2018-11-10 13:16:54 +0200 | [diff] [blame] | 361 | struct omap_drm_private *priv = crtc->dev->dev_private; |
Laurent Pinchart | f1d57fb | 2015-03-05 22:13:22 +0200 | [diff] [blame] | 362 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Laurent Pinchart | f1d57fb | 2015-03-05 22:13:22 +0200 | [diff] [blame] | 363 | |
| 364 | DBG("%s", omap_crtc->name); |
| 365 | |
Laurent Pinchart | ce9a8f1 | 2017-05-09 01:27:09 +0300 | [diff] [blame] | 366 | spin_lock_irq(&crtc->dev->event_lock); |
| 367 | if (crtc->state->event) { |
| 368 | drm_crtc_send_vblank_event(crtc, crtc->state->event); |
| 369 | crtc->state->event = NULL; |
| 370 | } |
| 371 | spin_unlock_irq(&crtc->dev->event_lock); |
| 372 | |
Laurent Pinchart | f1d57fb | 2015-03-05 22:13:22 +0200 | [diff] [blame] | 373 | drm_crtc_vblank_off(crtc); |
Laurent Pinchart | 24ec84e | 2018-11-10 13:16:54 +0200 | [diff] [blame] | 374 | |
| 375 | priv->dispc_ops->runtime_put(priv->dispc); |
Laurent Pinchart | f1d57fb | 2015-03-05 22:13:22 +0200 | [diff] [blame] | 376 | } |
| 377 | |
Peter Ujfalusi | a7631c4 | 2017-11-30 14:12:37 +0200 | [diff] [blame] | 378 | static enum drm_mode_status omap_crtc_mode_valid(struct drm_crtc *crtc, |
| 379 | const struct drm_display_mode *mode) |
| 380 | { |
| 381 | struct omap_drm_private *priv = crtc->dev->dev_private; |
Laurent Pinchart | 116c772 | 2018-09-20 00:17:42 +0300 | [diff] [blame] | 382 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
| 383 | struct videomode vm = {0}; |
| 384 | int r; |
| 385 | |
| 386 | drm_display_mode_to_videomode(mode, &vm); |
| 387 | r = priv->dispc_ops->mgr_check_timings(priv->dispc, omap_crtc->channel, |
| 388 | &vm); |
| 389 | if (r) |
| 390 | return r; |
Peter Ujfalusi | a7631c4 | 2017-11-30 14:12:37 +0200 | [diff] [blame] | 391 | |
| 392 | /* Check for bandwidth limit */ |
| 393 | if (priv->max_bandwidth) { |
| 394 | /* |
| 395 | * Estimation for the bandwidth need of a given mode with one |
| 396 | * full screen plane: |
| 397 | * bandwidth = resolution * 32bpp * (pclk / (vtotal * htotal)) |
| 398 | * ^^ Refresh rate ^^ |
| 399 | * |
| 400 | * The interlaced mode is taken into account by using the |
| 401 | * pixelclock in the calculation. |
| 402 | * |
| 403 | * The equation is rearranged for 64bit arithmetic. |
| 404 | */ |
| 405 | uint64_t bandwidth = mode->clock * 1000; |
| 406 | unsigned int bpp = 4; |
| 407 | |
| 408 | bandwidth = bandwidth * mode->hdisplay * mode->vdisplay * bpp; |
| 409 | bandwidth = div_u64(bandwidth, mode->htotal * mode->vtotal); |
| 410 | |
| 411 | /* |
| 412 | * Reject modes which would need more bandwidth if used with one |
| 413 | * full resolution plane (most common use case). |
| 414 | */ |
| 415 | if (priv->max_bandwidth < bandwidth) |
| 416 | return MODE_BAD; |
| 417 | } |
| 418 | |
| 419 | return MODE_OK; |
| 420 | } |
| 421 | |
Laurent Pinchart | f7a73b6 | 2015-03-05 13:45:14 +0200 | [diff] [blame] | 422 | static void omap_crtc_mode_set_nofb(struct drm_crtc *crtc) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 423 | { |
| 424 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Laurent Pinchart | f7a73b6 | 2015-03-05 13:45:14 +0200 | [diff] [blame] | 425 | struct drm_display_mode *mode = &crtc->state->adjusted_mode; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 426 | |
Shayenne Moura | c39ff7e | 2018-12-20 10:26:10 -0200 | [diff] [blame] | 427 | DBG("%s: set mode: " DRM_MODE_FMT, |
| 428 | omap_crtc->name, DRM_MODE_ARG(mode)); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 429 | |
Laurent Pinchart | 8e9c1c6 | 2018-06-07 18:32:16 +0300 | [diff] [blame] | 430 | drm_display_mode_to_videomode(mode, &omap_crtc->vm); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 431 | } |
| 432 | |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 433 | static int omap_crtc_atomic_check(struct drm_crtc *crtc, |
| 434 | struct drm_crtc_state *state) |
| 435 | { |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 436 | struct drm_plane_state *pri_state; |
| 437 | |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 438 | if (state->color_mgmt_changed && state->gamma_lut) { |
Laurent Pinchart | dfe9cfc | 2018-02-11 15:07:33 +0200 | [diff] [blame] | 439 | unsigned int length = state->gamma_lut->length / |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 440 | sizeof(struct drm_color_lut); |
| 441 | |
| 442 | if (length < 2) |
| 443 | return -EINVAL; |
| 444 | } |
| 445 | |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 446 | pri_state = drm_atomic_get_new_plane_state(state->state, crtc->primary); |
| 447 | if (pri_state) { |
| 448 | struct omap_crtc_state *omap_crtc_state = |
| 449 | to_omap_crtc_state(state); |
| 450 | |
| 451 | /* Mirror new values for zpos and rotation in omap_crtc_state */ |
| 452 | omap_crtc_state->zpos = pri_state->zpos; |
| 453 | omap_crtc_state->rotation = pri_state->rotation; |
| 454 | } |
| 455 | |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 456 | return 0; |
| 457 | } |
| 458 | |
Daniel Vetter | c201d00 | 2015-08-06 14:09:35 +0200 | [diff] [blame] | 459 | static void omap_crtc_atomic_begin(struct drm_crtc *crtc, |
Laurent Pinchart | 577d398 | 2016-04-19 01:15:11 +0300 | [diff] [blame] | 460 | struct drm_crtc_state *old_crtc_state) |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 461 | { |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 462 | } |
| 463 | |
Daniel Vetter | c201d00 | 2015-08-06 14:09:35 +0200 | [diff] [blame] | 464 | static void omap_crtc_atomic_flush(struct drm_crtc *crtc, |
Laurent Pinchart | 577d398 | 2016-04-19 01:15:11 +0300 | [diff] [blame] | 465 | struct drm_crtc_state *old_crtc_state) |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 466 | { |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 467 | struct omap_drm_private *priv = crtc->dev->dev_private; |
Tomi Valkeinen | 6646dfd | 2015-06-08 13:08:25 +0300 | [diff] [blame] | 468 | struct omap_crtc *omap_crtc = to_omap_crtc(crtc); |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 469 | int ret; |
Tomi Valkeinen | 6646dfd | 2015-06-08 13:08:25 +0300 | [diff] [blame] | 470 | |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 471 | if (crtc->state->color_mgmt_changed) { |
| 472 | struct drm_color_lut *lut = NULL; |
Laurent Pinchart | dfe9cfc | 2018-02-11 15:07:33 +0200 | [diff] [blame] | 473 | unsigned int length = 0; |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 474 | |
| 475 | if (crtc->state->gamma_lut) { |
| 476 | lut = (struct drm_color_lut *) |
| 477 | crtc->state->gamma_lut->data; |
| 478 | length = crtc->state->gamma_lut->length / |
| 479 | sizeof(*lut); |
| 480 | } |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 481 | priv->dispc_ops->mgr_set_gamma(priv->dispc, omap_crtc->channel, |
| 482 | lut, length); |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 483 | } |
| 484 | |
Tomi Valkeinen | 7e3d927 | 2015-08-10 12:08:50 +0300 | [diff] [blame] | 485 | omap_crtc_write_crtc_properties(crtc); |
| 486 | |
Jyri Sarha | e025d38 | 2017-01-27 12:04:54 +0200 | [diff] [blame] | 487 | /* Only flush the CRTC if it is currently enabled. */ |
Laurent Pinchart | f933a3a | 2016-04-18 02:54:31 +0300 | [diff] [blame] | 488 | if (!omap_crtc->enabled) |
| 489 | return; |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 490 | |
Laurent Pinchart | f933a3a | 2016-04-18 02:54:31 +0300 | [diff] [blame] | 491 | DBG("%s: GO", omap_crtc->name); |
Tomi Valkeinen | 6646dfd | 2015-06-08 13:08:25 +0300 | [diff] [blame] | 492 | |
Laurent Pinchart | 14389a3 | 2016-04-19 01:43:03 +0300 | [diff] [blame] | 493 | ret = drm_crtc_vblank_get(crtc); |
| 494 | WARN_ON(ret != 0); |
| 495 | |
Laurent Pinchart | d173d3d | 2016-04-19 01:31:21 +0300 | [diff] [blame] | 496 | spin_lock_irq(&crtc->dev->event_lock); |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 497 | priv->dispc_ops->mgr_go(priv->dispc, omap_crtc->channel); |
Laurent Pinchart | ce9a8f1 | 2017-05-09 01:27:09 +0300 | [diff] [blame] | 498 | omap_crtc_arm_event(crtc); |
Laurent Pinchart | d173d3d | 2016-04-19 01:31:21 +0300 | [diff] [blame] | 499 | spin_unlock_irq(&crtc->dev->event_lock); |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 500 | } |
| 501 | |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 502 | static int omap_crtc_atomic_set_property(struct drm_crtc *crtc, |
| 503 | struct drm_crtc_state *state, |
| 504 | struct drm_property *property, |
Laurent Pinchart | dfe9cfc | 2018-02-11 15:07:33 +0200 | [diff] [blame] | 505 | u64 val) |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 506 | { |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 507 | struct omap_drm_private *priv = crtc->dev->dev_private; |
| 508 | struct drm_plane_state *plane_state; |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 509 | |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 510 | /* |
| 511 | * Delegate property set to the primary plane. Get the plane state and |
| 512 | * set the property directly, the shadow copy will be assigned in the |
| 513 | * omap_crtc_atomic_check callback. This way updates to plane state will |
| 514 | * always be mirrored in the crtc state correctly. |
| 515 | */ |
| 516 | plane_state = drm_atomic_get_plane_state(state->state, crtc->primary); |
| 517 | if (IS_ERR(plane_state)) |
| 518 | return PTR_ERR(plane_state); |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 519 | |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 520 | if (property == crtc->primary->rotation_property) |
| 521 | plane_state->rotation = val; |
| 522 | else if (property == priv->zorder_prop) |
| 523 | plane_state->zpos = val; |
| 524 | else |
| 525 | return -EINVAL; |
Tomi Valkeinen | 6bdad6c | 2016-02-18 18:47:14 +0200 | [diff] [blame] | 526 | |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 527 | return 0; |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static int omap_crtc_atomic_get_property(struct drm_crtc *crtc, |
| 531 | const struct drm_crtc_state *state, |
| 532 | struct drm_property *property, |
Laurent Pinchart | dfe9cfc | 2018-02-11 15:07:33 +0200 | [diff] [blame] | 533 | u64 *val) |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 534 | { |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 535 | struct omap_drm_private *priv = crtc->dev->dev_private; |
| 536 | struct omap_crtc_state *omap_state = to_omap_crtc_state(state); |
Tomi Valkeinen | 6bdad6c | 2016-02-18 18:47:14 +0200 | [diff] [blame] | 537 | |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 538 | if (property == crtc->primary->rotation_property) |
| 539 | *val = omap_state->rotation; |
| 540 | else if (property == priv->zorder_prop) |
| 541 | *val = omap_state->zpos; |
| 542 | else |
| 543 | return -EINVAL; |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static void omap_crtc_reset(struct drm_crtc *crtc) |
| 549 | { |
| 550 | if (crtc->state) |
| 551 | __drm_atomic_helper_crtc_destroy_state(crtc->state); |
| 552 | |
| 553 | kfree(crtc->state); |
| 554 | crtc->state = kzalloc(sizeof(struct omap_crtc_state), GFP_KERNEL); |
| 555 | |
| 556 | if (crtc->state) |
| 557 | crtc->state->crtc = crtc; |
| 558 | } |
| 559 | |
| 560 | static struct drm_crtc_state * |
| 561 | omap_crtc_duplicate_state(struct drm_crtc *crtc) |
| 562 | { |
| 563 | struct omap_crtc_state *state, *current_state; |
| 564 | |
| 565 | if (WARN_ON(!crtc->state)) |
| 566 | return NULL; |
| 567 | |
| 568 | current_state = to_omap_crtc_state(crtc->state); |
| 569 | |
| 570 | state = kmalloc(sizeof(*state), GFP_KERNEL); |
Dan Carpenter | 2419672 | 2017-08-11 23:16:06 +0300 | [diff] [blame] | 571 | if (!state) |
| 572 | return NULL; |
| 573 | |
| 574 | __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base); |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 575 | |
| 576 | state->zpos = current_state->zpos; |
| 577 | state->rotation = current_state->rotation; |
| 578 | |
| 579 | return &state->base; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 580 | } |
| 581 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 582 | static const struct drm_crtc_funcs omap_crtc_funcs = { |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 583 | .reset = omap_crtc_reset, |
Laurent Pinchart | 9416c9d | 2015-03-05 21:54:54 +0200 | [diff] [blame] | 584 | .set_config = drm_atomic_helper_set_config, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 585 | .destroy = omap_crtc_destroy, |
Laurent Pinchart | fa16d26 | 2015-03-06 16:01:53 +0200 | [diff] [blame] | 586 | .page_flip = drm_atomic_helper_page_flip, |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 587 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 3dfeb63 | 2017-08-07 12:20:06 +0200 | [diff] [blame] | 588 | .atomic_duplicate_state = omap_crtc_duplicate_state, |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 589 | .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 590 | .atomic_set_property = omap_crtc_atomic_set_property, |
| 591 | .atomic_get_property = omap_crtc_atomic_get_property, |
Tomi Valkeinen | 0396162 | 2017-02-08 13:26:00 +0200 | [diff] [blame] | 592 | .enable_vblank = omap_irq_enable_vblank, |
| 593 | .disable_vblank = omap_irq_disable_vblank, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 594 | }; |
| 595 | |
| 596 | static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = { |
Laurent Pinchart | f7a73b6 | 2015-03-05 13:45:14 +0200 | [diff] [blame] | 597 | .mode_set_nofb = omap_crtc_mode_set_nofb, |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 598 | .atomic_check = omap_crtc_atomic_check, |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 599 | .atomic_begin = omap_crtc_atomic_begin, |
| 600 | .atomic_flush = omap_crtc_atomic_flush, |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 601 | .atomic_enable = omap_crtc_atomic_enable, |
Laurent Pinchart | 6458171 | 2017-06-30 12:36:45 +0300 | [diff] [blame] | 602 | .atomic_disable = omap_crtc_atomic_disable, |
Peter Ujfalusi | a7631c4 | 2017-11-30 14:12:37 +0200 | [diff] [blame] | 603 | .mode_valid = omap_crtc_mode_valid, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 604 | }; |
| 605 | |
Laurent Pinchart | 971fb3e | 2015-01-18 01:12:59 +0200 | [diff] [blame] | 606 | /* ----------------------------------------------------------------------------- |
| 607 | * Init and Cleanup |
| 608 | */ |
Tomi Valkeinen | e2f8fd7 | 2014-04-02 14:31:57 +0300 | [diff] [blame] | 609 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 610 | static const char *channel_names[] = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 611 | [OMAP_DSS_CHANNEL_LCD] = "lcd", |
| 612 | [OMAP_DSS_CHANNEL_DIGIT] = "tv", |
| 613 | [OMAP_DSS_CHANNEL_LCD2] = "lcd2", |
| 614 | [OMAP_DSS_CHANNEL_LCD3] = "lcd3", |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 615 | }; |
| 616 | |
Laurent Pinchart | 64cb817 | 2018-02-13 14:00:39 +0200 | [diff] [blame] | 617 | void omap_crtc_pre_init(struct omap_drm_private *priv) |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 618 | { |
Laurent Pinchart | 845417b | 2018-03-02 03:05:10 +0200 | [diff] [blame] | 619 | dss_install_mgr_ops(priv->dss, &mgr_ops, priv); |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 620 | } |
| 621 | |
Laurent Pinchart | 845417b | 2018-03-02 03:05:10 +0200 | [diff] [blame] | 622 | void omap_crtc_pre_uninit(struct omap_drm_private *priv) |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 623 | { |
Laurent Pinchart | 845417b | 2018-03-02 03:05:10 +0200 | [diff] [blame] | 624 | dss_uninstall_mgr_ops(priv->dss); |
Archit Taneja | 3a01ab2 | 2014-01-02 14:49:51 +0530 | [diff] [blame] | 625 | } |
| 626 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 627 | /* initialize crtc */ |
| 628 | struct drm_crtc *omap_crtc_init(struct drm_device *dev, |
Laurent Pinchart | 00b30e7 | 2018-03-06 23:37:25 +0200 | [diff] [blame] | 629 | struct omap_drm_pipeline *pipe, |
| 630 | struct drm_plane *plane) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 631 | { |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 632 | struct omap_drm_private *priv = dev->dev_private; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 633 | struct drm_crtc *crtc = NULL; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 634 | struct omap_crtc *omap_crtc; |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 635 | enum omap_channel channel; |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 636 | int ret; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 637 | |
Laurent Pinchart | 00b30e7 | 2018-03-06 23:37:25 +0200 | [diff] [blame] | 638 | channel = pipe->output->dispc_channel; |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 639 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 640 | DBG("%s", channel_names[channel]); |
| 641 | |
| 642 | omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL); |
Joe Perches | 78110bb | 2013-02-11 09:41:29 -0800 | [diff] [blame] | 643 | if (!omap_crtc) |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 644 | return ERR_PTR(-ENOMEM); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 645 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 646 | crtc = &omap_crtc->base; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 647 | |
Tomi Valkeinen | 5f741b3 | 2015-05-29 16:01:18 +0300 | [diff] [blame] | 648 | init_waitqueue_head(&omap_crtc->pending_wait); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 649 | |
Laurent Pinchart | 67dfd2d | 2018-03-06 23:38:21 +0200 | [diff] [blame] | 650 | omap_crtc->pipe = pipe; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 651 | omap_crtc->channel = channel; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 652 | omap_crtc->name = channel_names[channel]; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 653 | |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 654 | ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 655 | &omap_crtc_funcs, NULL); |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 656 | if (ret < 0) { |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 657 | dev_err(dev->dev, "%s(): could not init crtc for: %s\n", |
Laurent Pinchart | 79107f2 | 2018-09-23 12:58:15 +0300 | [diff] [blame] | 658 | __func__, pipe->output->name); |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 659 | kfree(omap_crtc); |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 660 | return ERR_PTR(ret); |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 661 | } |
| 662 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 663 | drm_crtc_helper_add(crtc, &omap_crtc_helper_funcs); |
| 664 | |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 665 | /* The dispc API adapts to what ever size, but the HW supports |
| 666 | * 256 element gamma table for LCDs and 1024 element table for |
| 667 | * OMAP_DSS_CHANNEL_DIGIT. X server assumes 256 element gamma |
| 668 | * tables so lets use that. Size of HW gamma table can be |
| 669 | * extracted with dispc_mgr_gamma_size(). If it returns 0 |
| 670 | * gamma table is not supprted. |
| 671 | */ |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 672 | if (priv->dispc_ops->mgr_gamma_size(priv->dispc, channel)) { |
Laurent Pinchart | dfe9cfc | 2018-02-11 15:07:33 +0200 | [diff] [blame] | 673 | unsigned int gamma_lut_size = 256; |
Jyri Sarha | 492a426 | 2016-06-07 15:09:17 +0300 | [diff] [blame] | 674 | |
| 675 | drm_crtc_enable_color_mgmt(crtc, 0, false, gamma_lut_size); |
| 676 | drm_mode_crtc_set_gamma_size(crtc, gamma_lut_size); |
| 677 | } |
| 678 | |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 679 | omap_plane_install_properties(crtc->primary, &crtc->base); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 680 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 681 | return crtc; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 682 | } |