blob: 5f4f5ad93345b8260902219ae0c5542af1e57104 [file] [log] [blame]
Rob Clarkcd5351f2011-11-12 12:09:40 -06001/*
Rob Clark8bb0daf2013-02-11 12:43:09 -05002 * drivers/gpu/drm/omapdrm/omap_crtc.c
Rob Clarkcd5351f2011-11-12 12:09:40 -06003 *
4 * Copyright (C) 2011 Texas Instruments
5 * Author: Rob Clark <rob@ti.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
Laurent Pincharta42133a2015-01-17 19:09:26 +020020#include <linux/completion.h>
21
Laurent Pinchart69a12262015-03-05 21:38:16 +020022#include <drm/drm_atomic.h>
23#include <drm/drm_atomic_helper.h>
Laurent Pinchart2d278f52015-03-05 21:31:37 +020024#include <drm/drm_crtc.h>
25#include <drm/drm_crtc_helper.h>
Andy Grossb9ed9f02012-10-16 00:17:40 -050026#include <drm/drm_mode.h>
Daniel Vetter3cb9ae42014-10-29 10:03:57 +010027#include <drm/drm_plane_helper.h>
Laurent Pinchart2d278f52015-03-05 21:31:37 +020028
29#include "omap_drv.h"
Rob Clarkcd5351f2011-11-12 12:09:40 -060030
31#define to_omap_crtc(x) container_of(x, struct omap_crtc, base)
32
Laurent Pinchart15d02e92015-01-25 22:42:30 +020033enum omap_page_flip_state {
34 OMAP_PAGE_FLIP_IDLE,
35 OMAP_PAGE_FLIP_WAIT,
36 OMAP_PAGE_FLIP_QUEUED,
37 OMAP_PAGE_FLIP_CANCELLED,
38};
39
Rob Clarkcd5351f2011-11-12 12:09:40 -060040struct omap_crtc {
41 struct drm_crtc base;
Rob Clarkf5f94542012-12-04 13:59:12 -060042
Rob Clarkbb5c2d92012-01-16 12:51:16 -060043 const char *name;
Rob Clarkf5f94542012-12-04 13:59:12 -060044 int pipe;
45 enum omap_channel channel;
46 struct omap_overlay_manager_info info;
Tomi Valkeinenc7aef122014-04-03 16:30:03 +030047 struct drm_encoder *current_encoder;
Rob Clarkf5f94542012-12-04 13:59:12 -060048
49 /*
50 * Temporary: eventually this will go away, but it is needed
51 * for now to keep the output's happy. (They only need
52 * mgr->id.) Eventually this will be replaced w/ something
53 * more common-panel-framework-y
54 */
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +030055 struct omap_overlay_manager *mgr;
Rob Clarkf5f94542012-12-04 13:59:12 -060056
57 struct omap_video_timings timings;
58 bool enabled;
Rob Clarkf5f94542012-12-04 13:59:12 -060059
Laurent Pincharta42133a2015-01-17 19:09:26 +020060 struct omap_drm_irq vblank_irq;
Rob Clarkf5f94542012-12-04 13:59:12 -060061 struct omap_drm_irq error_irq;
62
Laurent Pincharta42133a2015-01-17 19:09:26 +020063 /* list of framebuffers to unpin */
64 struct list_head pending_unpins;
Rob Clarkcd5351f2011-11-12 12:09:40 -060065
Laurent Pinchart42fb61c2015-01-26 02:58:51 +020066 /*
Laurent Pinchart15d02e92015-01-25 22:42:30 +020067 * flip_state flag indicates the current page flap state: IDLE if no
68 * page queue has been submitted, WAIT when waiting for GEM async
69 * completion, QUEUED when the page flip has been queued to the hardware
70 * or CANCELLED when the CRTC is turned off before the flip gets queued
Laurent Pinchart0c19ac92015-03-04 18:24:18 +020071 * to the hardware. The flip event, if any, is stored in flip_event, and
72 * the framebuffer queued for page flip is stored in flip_fb. The
Laurent Pinchart15d02e92015-01-25 22:42:30 +020073 * flip_wait wait queue is used to wait for page flip completion.
Laurent Pinchart42fb61c2015-01-26 02:58:51 +020074 *
75 * The flip_work work queue handles page flip requests without caring
76 * about what context the GEM async callback is called from. Possibly we
77 * should just make omap_gem always call the cb from the worker so we
78 * don't have to care about this.
79 */
Laurent Pinchart15d02e92015-01-25 22:42:30 +020080 enum omap_page_flip_state flip_state;
Laurent Pinchart42fb61c2015-01-26 02:58:51 +020081 struct drm_pending_vblank_event *flip_event;
Laurent Pinchart0c19ac92015-03-04 18:24:18 +020082 struct drm_framebuffer *flip_fb;
Laurent Pinchartc397cfd2015-01-25 22:42:30 +020083 wait_queue_head_t flip_wait;
Laurent Pinchart42fb61c2015-01-26 02:58:51 +020084 struct work_struct flip_work;
Rob Clarkf5f94542012-12-04 13:59:12 -060085
Laurent Pincharta42133a2015-01-17 19:09:26 +020086 struct completion completion;
87
Tomi Valkeinena36af732015-02-26 15:20:24 +020088 bool ignore_digit_sync_lost;
Rob Clarkcd5351f2011-11-12 12:09:40 -060089};
90
Laurent Pincharta42133a2015-01-17 19:09:26 +020091struct omap_framebuffer_unpin {
92 struct list_head list;
93 struct drm_framebuffer *fb;
94};
95
Laurent Pinchart971fb3e2015-01-18 01:12:59 +020096/* -----------------------------------------------------------------------------
97 * Helper Functions
98 */
99
Archit Taneja0d8f3712013-03-26 19:15:19 +0530100uint32_t pipe2vbl(struct drm_crtc *crtc)
101{
102 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
103
104 return dispc_mgr_get_vsync_irq(omap_crtc->channel);
105}
106
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200107const struct omap_video_timings *omap_crtc_timings(struct drm_crtc *crtc)
108{
109 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
110 return &omap_crtc->timings;
111}
112
113enum omap_channel omap_crtc_channel(struct drm_crtc *crtc)
114{
115 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
116 return omap_crtc->channel;
117}
118
119/* -----------------------------------------------------------------------------
120 * DSS Manager Functions
121 */
122
Rob Clarkf5f94542012-12-04 13:59:12 -0600123/*
124 * Manager-ops, callbacks from output when they need to configure
125 * the upstream part of the video pipe.
126 *
127 * Most of these we can ignore until we add support for command-mode
128 * panels.. for video-mode the crtc-helpers already do an adequate
129 * job of sequencing the setup of the video pipe in the proper order
130 */
131
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +0300132/* ovl-mgr-id -> crtc */
133static struct omap_crtc *omap_crtcs[8];
134
Rob Clarkf5f94542012-12-04 13:59:12 -0600135/* we can probably ignore these until we support command-mode panels: */
Laurent Pinchart4343f0f2015-03-05 22:01:02 +0200136static int omap_crtc_dss_connect(struct omap_overlay_manager *mgr,
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300137 struct omap_dss_device *dst)
Tomi Valkeinena7e71e72013-05-08 16:23:32 +0300138{
139 if (mgr->output)
140 return -EINVAL;
141
142 if ((mgr->supported_outputs & dst->id) == 0)
143 return -EINVAL;
144
145 dst->manager = mgr;
146 mgr->output = dst;
147
148 return 0;
149}
150
Laurent Pinchart4343f0f2015-03-05 22:01:02 +0200151static void omap_crtc_dss_disconnect(struct omap_overlay_manager *mgr,
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300152 struct omap_dss_device *dst)
Tomi Valkeinena7e71e72013-05-08 16:23:32 +0300153{
154 mgr->output->manager = NULL;
155 mgr->output = NULL;
156}
157
Laurent Pinchart4343f0f2015-03-05 22:01:02 +0200158static void omap_crtc_dss_start_update(struct omap_overlay_manager *mgr)
Rob Clarkf5f94542012-12-04 13:59:12 -0600159{
160}
161
Laurent Pincharta42133a2015-01-17 19:09:26 +0200162/* Called only from omap_crtc_setup and suspend/resume handlers. */
Laurent Pinchart8472b572015-01-15 00:45:17 +0200163static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable)
164{
165 struct drm_device *dev = crtc->dev;
166 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
167 enum omap_channel channel = omap_crtc->channel;
168 struct omap_irq_wait *wait;
169 u32 framedone_irq, vsync_irq;
170 int ret;
171
172 if (dispc_mgr_is_enabled(channel) == enable)
173 return;
174
Tomi Valkeinenef422282015-02-26 15:20:25 +0200175 if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
176 /*
177 * Digit output produces some sync lost interrupts during the
178 * first frame when enabling, so we need to ignore those.
179 */
180 omap_crtc->ignore_digit_sync_lost = true;
181 }
Laurent Pinchart8472b572015-01-15 00:45:17 +0200182
183 framedone_irq = dispc_mgr_get_framedone_irq(channel);
184 vsync_irq = dispc_mgr_get_vsync_irq(channel);
185
186 if (enable) {
187 wait = omap_irq_wait_init(dev, vsync_irq, 1);
188 } else {
189 /*
190 * When we disable the digit output, we need to wait for
191 * FRAMEDONE to know that DISPC has finished with the output.
192 *
193 * OMAP2/3 does not have FRAMEDONE irq for digit output, and in
194 * that case we need to use vsync interrupt, and wait for both
195 * even and odd frames.
196 */
197
198 if (framedone_irq)
199 wait = omap_irq_wait_init(dev, framedone_irq, 1);
200 else
201 wait = omap_irq_wait_init(dev, vsync_irq, 2);
202 }
203
204 dispc_mgr_enable(channel, enable);
205
206 ret = omap_irq_wait(dev, wait, msecs_to_jiffies(100));
207 if (ret) {
208 dev_err(dev->dev, "%s: timeout waiting for %s\n",
209 omap_crtc->name, enable ? "enable" : "disable");
210 }
211
Tomi Valkeinenef422282015-02-26 15:20:25 +0200212 if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
213 omap_crtc->ignore_digit_sync_lost = false;
214 /* make sure the irq handler sees the value above */
215 mb();
216 }
Laurent Pinchart8472b572015-01-15 00:45:17 +0200217}
218
Tomi Valkeinen506096a2014-04-03 13:11:54 +0300219
Laurent Pinchart4343f0f2015-03-05 22:01:02 +0200220static int omap_crtc_dss_enable(struct omap_overlay_manager *mgr)
Rob Clarkf5f94542012-12-04 13:59:12 -0600221{
Tomi Valkeinen506096a2014-04-03 13:11:54 +0300222 struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
223
224 dispc_mgr_setup(omap_crtc->channel, &omap_crtc->info);
225 dispc_mgr_set_timings(omap_crtc->channel,
226 &omap_crtc->timings);
Laurent Pinchart8472b572015-01-15 00:45:17 +0200227 omap_crtc_set_enabled(&omap_crtc->base, true);
Tomi Valkeinen506096a2014-04-03 13:11:54 +0300228
Rob Clarkf5f94542012-12-04 13:59:12 -0600229 return 0;
230}
231
Laurent Pinchart4343f0f2015-03-05 22:01:02 +0200232static void omap_crtc_dss_disable(struct omap_overlay_manager *mgr)
Rob Clarkf5f94542012-12-04 13:59:12 -0600233{
Tomi Valkeinen506096a2014-04-03 13:11:54 +0300234 struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
235
Laurent Pinchart8472b572015-01-15 00:45:17 +0200236 omap_crtc_set_enabled(&omap_crtc->base, false);
Rob Clarkf5f94542012-12-04 13:59:12 -0600237}
238
Laurent Pinchart4343f0f2015-03-05 22:01:02 +0200239static void omap_crtc_dss_set_timings(struct omap_overlay_manager *mgr,
Rob Clarkf5f94542012-12-04 13:59:12 -0600240 const struct omap_video_timings *timings)
241{
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +0300242 struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
Rob Clarkf5f94542012-12-04 13:59:12 -0600243 DBG("%s", omap_crtc->name);
244 omap_crtc->timings = *timings;
Rob Clarkf5f94542012-12-04 13:59:12 -0600245}
246
Laurent Pinchart4343f0f2015-03-05 22:01:02 +0200247static void omap_crtc_dss_set_lcd_config(struct omap_overlay_manager *mgr,
Rob Clarkf5f94542012-12-04 13:59:12 -0600248 const struct dss_lcd_mgr_config *config)
249{
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +0300250 struct omap_crtc *omap_crtc = omap_crtcs[mgr->id];
Rob Clarkf5f94542012-12-04 13:59:12 -0600251 DBG("%s", omap_crtc->name);
252 dispc_mgr_set_lcd_config(omap_crtc->channel, config);
253}
254
Laurent Pinchart4343f0f2015-03-05 22:01:02 +0200255static int omap_crtc_dss_register_framedone(
Rob Clarkf5f94542012-12-04 13:59:12 -0600256 struct omap_overlay_manager *mgr,
257 void (*handler)(void *), void *data)
258{
259 return 0;
260}
261
Laurent Pinchart4343f0f2015-03-05 22:01:02 +0200262static void omap_crtc_dss_unregister_framedone(
Rob Clarkf5f94542012-12-04 13:59:12 -0600263 struct omap_overlay_manager *mgr,
264 void (*handler)(void *), void *data)
265{
266}
267
268static const struct dss_mgr_ops mgr_ops = {
Laurent Pinchart4343f0f2015-03-05 22:01:02 +0200269 .connect = omap_crtc_dss_connect,
270 .disconnect = omap_crtc_dss_disconnect,
271 .start_update = omap_crtc_dss_start_update,
272 .enable = omap_crtc_dss_enable,
273 .disable = omap_crtc_dss_disable,
274 .set_timings = omap_crtc_dss_set_timings,
275 .set_lcd_config = omap_crtc_dss_set_lcd_config,
276 .register_framedone_handler = omap_crtc_dss_register_framedone,
277 .unregister_framedone_handler = omap_crtc_dss_unregister_framedone,
Rob Clarkf5f94542012-12-04 13:59:12 -0600278};
279
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200280/* -----------------------------------------------------------------------------
Laurent Pinchart1d5e5ea2015-01-18 16:57:36 +0200281 * Setup, Flush and Page Flip
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200282 */
283
Laurent Pinchart1d5e5ea2015-01-18 16:57:36 +0200284void omap_crtc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file)
285{
286 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
287 struct drm_device *dev = crtc->dev;
288 unsigned long flags;
289
290 spin_lock_irqsave(&dev->event_lock, flags);
291
292 /* Only complete events queued for our file handle. */
293 if (omap_crtc->flip_event &&
294 file == omap_crtc->flip_event->base.file_priv) {
295 drm_send_vblank_event(dev, omap_crtc->pipe,
296 omap_crtc->flip_event);
297 omap_crtc->flip_event = NULL;
298 }
299
300 spin_unlock_irqrestore(&dev->event_lock, flags);
301}
302
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200303/* Must be called with dev->event_lock locked. */
304static void omap_crtc_complete_page_flip(struct drm_crtc *crtc,
305 enum omap_page_flip_state state)
306{
307 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
308 struct drm_device *dev = crtc->dev;
309
310 if (omap_crtc->flip_event) {
311 drm_send_vblank_event(dev, omap_crtc->pipe,
312 omap_crtc->flip_event);
313 omap_crtc->flip_event = NULL;
314 }
315
316 omap_crtc->flip_state = state;
Laurent Pinchartc397cfd2015-01-25 22:42:30 +0200317
318 if (state == OMAP_PAGE_FLIP_IDLE)
319 wake_up(&omap_crtc->flip_wait);
320}
321
322static bool omap_crtc_page_flip_pending(struct drm_crtc *crtc)
323{
324 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
325 struct drm_device *dev = crtc->dev;
326 unsigned long flags;
327 bool pending;
328
329 spin_lock_irqsave(&dev->event_lock, flags);
330 pending = omap_crtc->flip_state != OMAP_PAGE_FLIP_IDLE;
331 spin_unlock_irqrestore(&dev->event_lock, flags);
332
333 return pending;
334}
335
336static void omap_crtc_wait_page_flip(struct drm_crtc *crtc)
337{
338 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
339 struct drm_device *dev = crtc->dev;
340 bool cancelled = false;
341 unsigned long flags;
342
343 /*
344 * If we're still waiting for the GEM async operation to complete just
345 * cancel the page flip, as we're holding the CRTC mutex preventing the
346 * page flip work handler from queueing the page flip.
347 *
348 * We can't release the reference to the frame buffer here as the async
349 * operation doesn't keep its own reference to the buffer. We'll just
350 * let the page flip work queue handle that.
351 */
352 spin_lock_irqsave(&dev->event_lock, flags);
353 if (omap_crtc->flip_state == OMAP_PAGE_FLIP_WAIT) {
354 omap_crtc_complete_page_flip(crtc, OMAP_PAGE_FLIP_CANCELLED);
355 cancelled = true;
356 }
357 spin_unlock_irqrestore(&dev->event_lock, flags);
358
359 if (cancelled)
360 return;
361
362 if (wait_event_timeout(omap_crtc->flip_wait,
363 !omap_crtc_page_flip_pending(crtc),
364 msecs_to_jiffies(50)))
365 return;
366
367 dev_warn(crtc->dev->dev, "page flip timeout!\n");
368
369 spin_lock_irqsave(&dev->event_lock, flags);
370 omap_crtc_complete_page_flip(crtc, OMAP_PAGE_FLIP_IDLE);
371 spin_unlock_irqrestore(&dev->event_lock, flags);
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200372}
373
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200374static void omap_crtc_error_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
375{
376 struct omap_crtc *omap_crtc =
377 container_of(irq, struct omap_crtc, error_irq);
Tomi Valkeinena36af732015-02-26 15:20:24 +0200378
379 if (omap_crtc->ignore_digit_sync_lost) {
380 irqstatus &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
381 if (!irqstatus)
382 return;
383 }
384
Tomi Valkeinen3b143fc2014-11-19 12:50:13 +0200385 DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_crtc->name, irqstatus);
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200386}
387
Laurent Pincharta42133a2015-01-17 19:09:26 +0200388static void omap_crtc_vblank_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200389{
390 struct omap_crtc *omap_crtc =
Laurent Pincharta42133a2015-01-17 19:09:26 +0200391 container_of(irq, struct omap_crtc, vblank_irq);
392 struct drm_device *dev = omap_crtc->base.dev;
393 unsigned long flags;
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200394
Laurent Pincharta42133a2015-01-17 19:09:26 +0200395 if (dispc_mgr_go_busy(omap_crtc->channel))
396 return;
397
398 DBG("%s: apply done", omap_crtc->name);
399 __omap_irq_unregister(dev, &omap_crtc->vblank_irq);
400
Laurent Pincharta42133a2015-01-17 19:09:26 +0200401 /* wakeup userspace */
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200402 spin_lock_irqsave(&dev->event_lock, flags);
403 omap_crtc_complete_page_flip(&omap_crtc->base, OMAP_PAGE_FLIP_IDLE);
Laurent Pincharta42133a2015-01-17 19:09:26 +0200404 spin_unlock_irqrestore(&dev->event_lock, flags);
405
406 complete(&omap_crtc->completion);
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200407}
408
Laurent Pincharta42133a2015-01-17 19:09:26 +0200409int omap_crtc_flush(struct drm_crtc *crtc)
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200410{
411 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
Laurent Pincharta42133a2015-01-17 19:09:26 +0200412 struct omap_framebuffer_unpin *fb, *next;
413
414 DBG("%s: GO", omap_crtc->name);
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200415
416 WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
Laurent Pincharta42133a2015-01-17 19:09:26 +0200417 WARN_ON(omap_crtc->vblank_irq.registered);
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200418
Laurent Pincharta42133a2015-01-17 19:09:26 +0200419 dispc_runtime_get();
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200420
Laurent Pincharta42133a2015-01-17 19:09:26 +0200421 if (dispc_mgr_is_enabled(omap_crtc->channel)) {
422 dispc_mgr_go(omap_crtc->channel);
423 omap_irq_register(crtc->dev, &omap_crtc->vblank_irq);
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200424
Laurent Pincharta42133a2015-01-17 19:09:26 +0200425 WARN_ON(!wait_for_completion_timeout(&omap_crtc->completion,
426 msecs_to_jiffies(100)));
427 reinit_completion(&omap_crtc->completion);
428 }
429
430 dispc_runtime_put();
431
432 /* Unpin and unreference pending framebuffers. */
433 list_for_each_entry_safe(fb, next, &omap_crtc->pending_unpins, list) {
434 omap_framebuffer_unpin(fb->fb);
435 drm_framebuffer_unreference(fb->fb);
436 list_del(&fb->list);
437 kfree(fb);
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200438 }
439
440 return 0;
441}
442
Laurent Pincharta42133a2015-01-17 19:09:26 +0200443int omap_crtc_queue_unpin(struct drm_crtc *crtc, struct drm_framebuffer *fb)
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200444{
Laurent Pincharta42133a2015-01-17 19:09:26 +0200445 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
446 struct omap_framebuffer_unpin *unpin;
447
448 unpin = kzalloc(sizeof(*unpin), GFP_KERNEL);
449 if (!unpin)
450 return -ENOMEM;
451
452 unpin->fb = fb;
453 list_add_tail(&unpin->list, &omap_crtc->pending_unpins);
454
455 return 0;
456}
457
458static void omap_crtc_setup(struct drm_crtc *crtc)
459{
460 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200461 struct omap_drm_private *priv = crtc->dev->dev_private;
462 struct drm_encoder *encoder = NULL;
463 unsigned int i;
464
465 DBG("%s: enabled=%d", omap_crtc->name, omap_crtc->enabled);
466
Laurent Pincharta42133a2015-01-17 19:09:26 +0200467 dispc_runtime_get();
468
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200469 for (i = 0; i < priv->num_encoders; i++) {
470 if (priv->encoders[i]->crtc == crtc) {
471 encoder = priv->encoders[i];
472 break;
473 }
474 }
475
476 if (omap_crtc->current_encoder && encoder != omap_crtc->current_encoder)
477 omap_encoder_set_enabled(omap_crtc->current_encoder, false);
478
479 omap_crtc->current_encoder = encoder;
480
481 if (!omap_crtc->enabled) {
482 if (encoder)
483 omap_encoder_set_enabled(encoder, false);
484 } else {
485 if (encoder) {
486 omap_encoder_set_enabled(encoder, false);
487 omap_encoder_update(encoder, omap_crtc->mgr,
488 &omap_crtc->timings);
489 omap_encoder_set_enabled(encoder, true);
490 }
491 }
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200492
Laurent Pincharta42133a2015-01-17 19:09:26 +0200493 dispc_runtime_put();
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200494}
495
496/* -----------------------------------------------------------------------------
497 * CRTC Functions
Rob Clarkf5f94542012-12-04 13:59:12 -0600498 */
499
Rob Clarkcd5351f2011-11-12 12:09:40 -0600500static void omap_crtc_destroy(struct drm_crtc *crtc)
501{
502 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
Rob Clarkf5f94542012-12-04 13:59:12 -0600503
504 DBG("%s", omap_crtc->name);
505
Laurent Pincharta42133a2015-01-17 19:09:26 +0200506 WARN_ON(omap_crtc->vblank_irq.registered);
Rob Clarkf5f94542012-12-04 13:59:12 -0600507 omap_irq_unregister(crtc->dev, &omap_crtc->error_irq);
508
Rob Clarkcd5351f2011-11-12 12:09:40 -0600509 drm_crtc_cleanup(crtc);
Rob Clarkf5f94542012-12-04 13:59:12 -0600510
Rob Clarkcd5351f2011-11-12 12:09:40 -0600511 kfree(omap_crtc);
512}
513
Rob Clarkcd5351f2011-11-12 12:09:40 -0600514static bool omap_crtc_mode_fixup(struct drm_crtc *crtc,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200515 const struct drm_display_mode *mode,
Rob Clarkbb5c2d92012-01-16 12:51:16 -0600516 struct drm_display_mode *adjusted_mode)
Rob Clarkcd5351f2011-11-12 12:09:40 -0600517{
Rob Clarkcd5351f2011-11-12 12:09:40 -0600518 return true;
519}
520
Laurent Pinchartf1d57fb2015-03-05 22:13:22 +0200521static void omap_crtc_enable(struct drm_crtc *crtc)
522{
523 struct omap_drm_private *priv = crtc->dev->dev_private;
524 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
525 unsigned int i;
526
527 DBG("%s", omap_crtc->name);
528
529 if (omap_crtc->enabled)
530 return;
531
532 /* Enable all planes associated with the CRTC. */
533 for (i = 0; i < priv->num_planes; i++) {
534 struct drm_plane *plane = priv->planes[i];
535
536 if (plane->crtc == crtc)
537 WARN_ON(omap_plane_set_enable(plane, true));
538 }
539
540 omap_crtc->enabled = true;
541
542 omap_crtc_setup(crtc);
543 omap_crtc_flush(crtc);
544
545 dispc_runtime_get();
546 drm_crtc_vblank_on(crtc);
547 dispc_runtime_put();
548}
549
550static void omap_crtc_disable(struct drm_crtc *crtc)
551{
552 struct omap_drm_private *priv = crtc->dev->dev_private;
553 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
554 unsigned int i;
555
556 DBG("%s", omap_crtc->name);
557
558 if (!omap_crtc->enabled)
559 return;
560
561 omap_crtc_wait_page_flip(crtc);
562 dispc_runtime_get();
563 drm_crtc_vblank_off(crtc);
564 dispc_runtime_put();
565
566 /* Disable all planes associated with the CRTC. */
567 for (i = 0; i < priv->num_planes; i++) {
568 struct drm_plane *plane = priv->planes[i];
569
570 if (plane->crtc == crtc)
571 WARN_ON(omap_plane_set_enable(plane, false));
572 }
573
574 omap_crtc->enabled = false;
575
576 omap_crtc_setup(crtc);
577 omap_crtc_flush(crtc);
578}
579
Rob Clarkcd5351f2011-11-12 12:09:40 -0600580static int omap_crtc_mode_set(struct drm_crtc *crtc,
Rob Clarkbb5c2d92012-01-16 12:51:16 -0600581 struct drm_display_mode *mode,
582 struct drm_display_mode *adjusted_mode,
583 int x, int y,
584 struct drm_framebuffer *old_fb)
Rob Clarkcd5351f2011-11-12 12:09:40 -0600585{
586 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
587
Rob Clarkf5f94542012-12-04 13:59:12 -0600588 mode = adjusted_mode;
589
590 DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
591 omap_crtc->name, mode->base.id, mode->name,
592 mode->vrefresh, mode->clock,
593 mode->hdisplay, mode->hsync_start,
594 mode->hsync_end, mode->htotal,
595 mode->vdisplay, mode->vsync_start,
596 mode->vsync_end, mode->vtotal,
597 mode->type, mode->flags);
598
599 copy_timings_drm_to_omap(&omap_crtc->timings, mode);
Rob Clarkf5f94542012-12-04 13:59:12 -0600600
Laurent Pinchartef6b0e02015-01-11 00:11:18 +0200601 /*
602 * The primary plane CRTC can be reset if the plane is disabled directly
603 * through the universal plane API. Set it again here.
604 */
605 crtc->primary->crtc = crtc;
606
607 return omap_plane_mode_set(crtc->primary, crtc, crtc->primary->fb,
Laurent Pincharta350da82015-01-17 22:31:42 +0200608 0, 0, mode->hdisplay, mode->vdisplay,
Laurent Pincharta42133a2015-01-17 19:09:26 +0200609 x, y, mode->hdisplay, mode->vdisplay);
Rob Clarkcd5351f2011-11-12 12:09:40 -0600610}
611
Laurent Pinchartf1d57fb2015-03-05 22:13:22 +0200612static void omap_crtc_dpms(struct drm_crtc *crtc, int mode)
613{
614 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
615 bool enable = (mode == DRM_MODE_DPMS_ON);
616
617 DBG("%s: %d", omap_crtc->name, mode);
618
619 if (enable)
620 omap_crtc_enable(crtc);
621 else
622 omap_crtc_disable(crtc);
623}
624
Rob Clarkcd5351f2011-11-12 12:09:40 -0600625static void omap_crtc_prepare(struct drm_crtc *crtc)
626{
627 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
Rob Clarkbb5c2d92012-01-16 12:51:16 -0600628 DBG("%s", omap_crtc->name);
Rob Clarkcd5351f2011-11-12 12:09:40 -0600629 omap_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
630}
631
632static void omap_crtc_commit(struct drm_crtc *crtc)
633{
634 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
Rob Clarkbb5c2d92012-01-16 12:51:16 -0600635 DBG("%s", omap_crtc->name);
Rob Clarkcd5351f2011-11-12 12:09:40 -0600636 omap_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
637}
638
639static int omap_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
Rob Clarkbb5c2d92012-01-16 12:51:16 -0600640 struct drm_framebuffer *old_fb)
Rob Clarkcd5351f2011-11-12 12:09:40 -0600641{
Laurent Pinchartef6b0e02015-01-11 00:11:18 +0200642 struct drm_plane *plane = crtc->primary;
Rob Clarkbb5c2d92012-01-16 12:51:16 -0600643 struct drm_display_mode *mode = &crtc->mode;
Laurent Pincharta42133a2015-01-17 19:09:26 +0200644 int ret;
Rob Clarkcd5351f2011-11-12 12:09:40 -0600645
Laurent Pincharta42133a2015-01-17 19:09:26 +0200646 ret = omap_plane_mode_set(plane, crtc, crtc->primary->fb,
647 0, 0, mode->hdisplay, mode->vdisplay,
648 x, y, mode->hdisplay, mode->vdisplay);
649 if (ret < 0)
650 return ret;
Rob Clarkcd5351f2011-11-12 12:09:40 -0600651
Laurent Pincharta42133a2015-01-17 19:09:26 +0200652 return omap_crtc_flush(crtc);
Rob Clarkf5f94542012-12-04 13:59:12 -0600653}
654
655static void page_flip_worker(struct work_struct *work)
656{
657 struct omap_crtc *omap_crtc =
Laurent Pinchart42fb61c2015-01-26 02:58:51 +0200658 container_of(work, struct omap_crtc, flip_work);
Rob Clarkf5f94542012-12-04 13:59:12 -0600659 struct drm_crtc *crtc = &omap_crtc->base;
Rob Clarkf5f94542012-12-04 13:59:12 -0600660 struct drm_display_mode *mode = &crtc->mode;
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200661 struct drm_device *dev = crtc->dev;
662 struct drm_framebuffer *fb;
Rob Clarkf5f94542012-12-04 13:59:12 -0600663 struct drm_gem_object *bo;
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200664 unsigned long flags;
665 bool queue_flip;
Rob Clarkf5f94542012-12-04 13:59:12 -0600666
Rob Clark51fd3712013-11-19 12:10:12 -0500667 drm_modeset_lock(&crtc->mutex, NULL);
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200668
669 spin_lock_irqsave(&dev->event_lock, flags);
Laurent Pinchart0c19ac92015-03-04 18:24:18 +0200670
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200671 /*
672 * The page flip could have been cancelled while waiting for the GEM
673 * async operation to complete. Don't queue the flip in that case.
674 */
675 if (omap_crtc->flip_state == OMAP_PAGE_FLIP_WAIT) {
676 omap_crtc->flip_state = OMAP_PAGE_FLIP_QUEUED;
677 queue_flip = true;
678 } else {
679 omap_crtc->flip_state = OMAP_PAGE_FLIP_IDLE;
680 queue_flip = false;
681 }
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200682
Laurent Pinchart0c19ac92015-03-04 18:24:18 +0200683 fb = omap_crtc->flip_fb;
684 omap_crtc->flip_fb = NULL;
685
686 spin_unlock_irqrestore(&dev->event_lock, flags);
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200687
688 if (queue_flip) {
689 omap_plane_mode_set(crtc->primary, crtc, fb,
690 0, 0, mode->hdisplay, mode->vdisplay,
691 crtc->x, crtc->y, mode->hdisplay,
692 mode->vdisplay);
693 omap_crtc_flush(crtc);
694 }
695
Rob Clark51fd3712013-11-19 12:10:12 -0500696 drm_modeset_unlock(&crtc->mutex);
Rob Clarkf5f94542012-12-04 13:59:12 -0600697
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200698 bo = omap_framebuffer_bo(fb, 0);
Rob Clarkf5f94542012-12-04 13:59:12 -0600699 drm_gem_object_unreference_unlocked(bo);
Laurent Pinchart0c19ac92015-03-04 18:24:18 +0200700 drm_framebuffer_unreference(fb);
Rob Clarkcd5351f2011-11-12 12:09:40 -0600701}
702
Rob Clark72d0c332012-03-11 21:11:21 -0500703static void page_flip_cb(void *arg)
704{
705 struct drm_crtc *crtc = arg;
706 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
Rob Clarkf5f94542012-12-04 13:59:12 -0600707 struct omap_drm_private *priv = crtc->dev->dev_private;
Rob Clark72d0c332012-03-11 21:11:21 -0500708
Rob Clarkf5f94542012-12-04 13:59:12 -0600709 /* avoid assumptions about what ctxt we are called from: */
Laurent Pinchart42fb61c2015-01-26 02:58:51 +0200710 queue_work(priv->wq, &omap_crtc->flip_work);
Rob Clark72d0c332012-03-11 21:11:21 -0500711}
712
Laurent Pinchart077db4d2015-01-18 16:36:19 +0200713static int omap_crtc_page_flip(struct drm_crtc *crtc,
714 struct drm_framebuffer *fb,
715 struct drm_pending_vblank_event *event,
716 uint32_t page_flip_flags)
Rob Clarkcd5351f2011-11-12 12:09:40 -0600717{
718 struct drm_device *dev = crtc->dev;
719 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -0700720 struct drm_plane *primary = crtc->primary;
Rob Clark119c0812012-09-04 17:46:22 -0500721 struct drm_gem_object *bo;
Archit Taneja38e55972014-04-11 12:53:35 +0530722 unsigned long flags;
Rob Clarkcd5351f2011-11-12 12:09:40 -0600723
Matt Roperf4510a22014-04-01 15:22:40 -0700724 DBG("%d -> %d (event=%p)", primary->fb ? primary->fb->base.id : -1,
Rob Clarkf5f94542012-12-04 13:59:12 -0600725 fb->base.id, event);
Rob Clarkcd5351f2011-11-12 12:09:40 -0600726
Archit Taneja38e55972014-04-11 12:53:35 +0530727 spin_lock_irqsave(&dev->event_lock, flags);
728
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200729 if (omap_crtc->flip_state != OMAP_PAGE_FLIP_IDLE) {
Archit Taneja38e55972014-04-11 12:53:35 +0530730 spin_unlock_irqrestore(&dev->event_lock, flags);
Rob Clarkcd5351f2011-11-12 12:09:40 -0600731 dev_err(dev->dev, "already a pending flip\n");
Tomi Valkeinen549a7542014-09-03 19:25:50 +0000732 return -EBUSY;
Rob Clarkcd5351f2011-11-12 12:09:40 -0600733 }
734
Laurent Pinchart0c19ac92015-03-04 18:24:18 +0200735 /*
736 * Store a reference to the framebuffer queued for page flip in the CRTC
737 * private structure. We can't rely on crtc->primary->fb in the page
738 * flip worker, as a racing CRTC disable (due for instance to an
739 * explicit framebuffer deletion from userspace) would set that field to
740 * NULL before the worker gets a change to run.
741 */
742 drm_framebuffer_reference(fb);
743 omap_crtc->flip_fb = fb;
Laurent Pinchart42fb61c2015-01-26 02:58:51 +0200744 omap_crtc->flip_event = event;
Laurent Pinchart15d02e92015-01-25 22:42:30 +0200745 omap_crtc->flip_state = OMAP_PAGE_FLIP_WAIT;
Laurent Pinchart0c19ac92015-03-04 18:24:18 +0200746
Laurent Pinchart69a12262015-03-05 21:38:16 +0200747 drm_atomic_set_fb_for_plane(primary->state, fb);
Laurent Pinchart42fb61c2015-01-26 02:58:51 +0200748 primary->fb = fb;
Rob Clarkcd5351f2011-11-12 12:09:40 -0600749
Archit Taneja38e55972014-04-11 12:53:35 +0530750 spin_unlock_irqrestore(&dev->event_lock, flags);
751
Rob Clark119c0812012-09-04 17:46:22 -0500752 /*
753 * Hold a reference temporarily until the crtc is updated
754 * and takes the reference to the bo. This avoids it
755 * getting freed from under us:
756 */
757 bo = omap_framebuffer_bo(fb, 0);
758 drm_gem_object_reference(bo);
759
760 omap_gem_op_async(bo, OMAP_GEM_READ, page_flip_cb, crtc);
Rob Clarkcd5351f2011-11-12 12:09:40 -0600761
762 return 0;
763}
764
Rob Clark3c810c62012-08-15 15:18:01 -0500765static int omap_crtc_set_property(struct drm_crtc *crtc,
766 struct drm_property *property, uint64_t val)
767{
Laurent Pincharte2cd09b2015-03-06 17:16:43 +0200768 if (property == crtc->dev->mode_config.rotation_property) {
Rob Clark1e0fdfc2012-09-04 11:36:20 -0500769 crtc->invert_dimensions =
770 !!(val & ((1LL << DRM_ROTATE_90) | (1LL << DRM_ROTATE_270)));
771 }
772
Laurent Pinchartef6b0e02015-01-11 00:11:18 +0200773 return omap_plane_set_property(crtc->primary, property, val);
Rob Clark3c810c62012-08-15 15:18:01 -0500774}
775
Rob Clarkcd5351f2011-11-12 12:09:40 -0600776static const struct drm_crtc_funcs omap_crtc_funcs = {
Laurent Pinchart69a12262015-03-05 21:38:16 +0200777 .reset = drm_atomic_helper_crtc_reset,
Rob Clarkcd5351f2011-11-12 12:09:40 -0600778 .set_config = drm_crtc_helper_set_config,
779 .destroy = omap_crtc_destroy,
Laurent Pinchart077db4d2015-01-18 16:36:19 +0200780 .page_flip = omap_crtc_page_flip,
Rob Clark3c810c62012-08-15 15:18:01 -0500781 .set_property = omap_crtc_set_property,
Laurent Pinchart69a12262015-03-05 21:38:16 +0200782 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
783 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
Rob Clarkcd5351f2011-11-12 12:09:40 -0600784};
785
786static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = {
787 .dpms = omap_crtc_dpms,
788 .mode_fixup = omap_crtc_mode_fixup,
789 .mode_set = omap_crtc_mode_set,
790 .prepare = omap_crtc_prepare,
791 .commit = omap_crtc_commit,
792 .mode_set_base = omap_crtc_mode_set_base,
Laurent Pinchartf1d57fb2015-03-05 22:13:22 +0200793 .disable = omap_crtc_disable,
794 .enable = omap_crtc_enable,
Rob Clarkcd5351f2011-11-12 12:09:40 -0600795};
796
Laurent Pinchart971fb3e2015-01-18 01:12:59 +0200797/* -----------------------------------------------------------------------------
798 * Init and Cleanup
799 */
Tomi Valkeinene2f8fd72014-04-02 14:31:57 +0300800
Rob Clarkf5f94542012-12-04 13:59:12 -0600801static const char *channel_names[] = {
Laurent Pinchart222025e2015-01-11 00:02:07 +0200802 [OMAP_DSS_CHANNEL_LCD] = "lcd",
803 [OMAP_DSS_CHANNEL_DIGIT] = "tv",
804 [OMAP_DSS_CHANNEL_LCD2] = "lcd2",
805 [OMAP_DSS_CHANNEL_LCD3] = "lcd3",
Rob Clarkf5f94542012-12-04 13:59:12 -0600806};
807
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +0300808void omap_crtc_pre_init(void)
809{
810 dss_install_mgr_ops(&mgr_ops);
811}
812
Archit Taneja3a01ab22014-01-02 14:49:51 +0530813void omap_crtc_pre_uninit(void)
814{
815 dss_uninstall_mgr_ops();
816}
817
Rob Clarkcd5351f2011-11-12 12:09:40 -0600818/* initialize crtc */
819struct drm_crtc *omap_crtc_init(struct drm_device *dev,
Rob Clarkf5f94542012-12-04 13:59:12 -0600820 struct drm_plane *plane, enum omap_channel channel, int id)
Rob Clarkcd5351f2011-11-12 12:09:40 -0600821{
822 struct drm_crtc *crtc = NULL;
Rob Clarkf5f94542012-12-04 13:59:12 -0600823 struct omap_crtc *omap_crtc;
824 struct omap_overlay_manager_info *info;
Laurent Pinchartef6b0e02015-01-11 00:11:18 +0200825 int ret;
Rob Clarkcd5351f2011-11-12 12:09:40 -0600826
Rob Clarkf5f94542012-12-04 13:59:12 -0600827 DBG("%s", channel_names[channel]);
828
829 omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL);
Joe Perches78110bb2013-02-11 09:41:29 -0800830 if (!omap_crtc)
Laurent Pinchartef6b0e02015-01-11 00:11:18 +0200831 return NULL;
Rob Clarkcd5351f2011-11-12 12:09:40 -0600832
Rob Clarkcd5351f2011-11-12 12:09:40 -0600833 crtc = &omap_crtc->base;
Rob Clarkbb5c2d92012-01-16 12:51:16 -0600834
Laurent Pinchart42fb61c2015-01-26 02:58:51 +0200835 INIT_WORK(&omap_crtc->flip_work, page_flip_worker);
Laurent Pinchartc397cfd2015-01-25 22:42:30 +0200836 init_waitqueue_head(&omap_crtc->flip_wait);
Rob Clarkf5f94542012-12-04 13:59:12 -0600837
Laurent Pincharta42133a2015-01-17 19:09:26 +0200838 INIT_LIST_HEAD(&omap_crtc->pending_unpins);
Rob Clarkf5f94542012-12-04 13:59:12 -0600839
Laurent Pincharta42133a2015-01-17 19:09:26 +0200840 init_completion(&omap_crtc->completion);
Rob Clarkf5f94542012-12-04 13:59:12 -0600841
Archit Taneja0d8f3712013-03-26 19:15:19 +0530842 omap_crtc->channel = channel;
Archit Taneja0d8f3712013-03-26 19:15:19 +0530843 omap_crtc->name = channel_names[channel];
844 omap_crtc->pipe = id;
845
Laurent Pincharta42133a2015-01-17 19:09:26 +0200846 omap_crtc->vblank_irq.irqmask = pipe2vbl(crtc);
847 omap_crtc->vblank_irq.irq = omap_crtc_vblank_irq;
Rob Clarkf5f94542012-12-04 13:59:12 -0600848
849 omap_crtc->error_irq.irqmask =
850 dispc_mgr_get_sync_lost_irq(channel);
851 omap_crtc->error_irq.irq = omap_crtc_error_irq;
852 omap_irq_register(dev, &omap_crtc->error_irq);
853
Rob Clarkf5f94542012-12-04 13:59:12 -0600854 /* temporary: */
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +0300855 omap_crtc->mgr = omap_dss_get_overlay_manager(channel);
Rob Clarkf5f94542012-12-04 13:59:12 -0600856
857 /* TODO: fix hard-coded setup.. add properties! */
858 info = &omap_crtc->info;
859 info->default_color = 0x00000000;
860 info->trans_key = 0x00000000;
861 info->trans_key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
862 info->trans_enabled = false;
Rob Clarkbb5c2d92012-01-16 12:51:16 -0600863
Laurent Pinchartef6b0e02015-01-11 00:11:18 +0200864 ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
865 &omap_crtc_funcs);
866 if (ret < 0) {
867 kfree(omap_crtc);
868 return NULL;
869 }
870
Rob Clarkcd5351f2011-11-12 12:09:40 -0600871 drm_crtc_helper_add(crtc, &omap_crtc_helper_funcs);
872
Laurent Pinchartef6b0e02015-01-11 00:11:18 +0200873 omap_plane_install_properties(crtc->primary, &crtc->base);
Rob Clark3c810c62012-08-15 15:18:01 -0500874
Tomi Valkeinen04b1fc02013-05-14 10:55:19 +0300875 omap_crtcs[channel] = omap_crtc;
876
Rob Clarkcd5351f2011-11-12 12:09:40 -0600877 return crtc;
Rob Clarkcd5351f2011-11-12 12:09:40 -0600878}