2 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
3 * Author: Rob Clark <rob@ti.com>
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.
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
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/>.
18 #include <drm/drm_atomic.h>
19 #include <drm/drm_atomic_helper.h>
20 #include <drm/drm_crtc.h>
21 #include <drm/drm_mode.h>
22 #include <drm/drm_plane_helper.h>
23 #include <linux/math64.h>
27 #define to_omap_crtc_state(x) container_of(x, struct omap_crtc_state, base)
29 struct omap_crtc_state {
31 struct drm_crtc_state base;
32 /* Shadow values for legacy userspace support. */
33 unsigned int rotation;
35 bool manually_updated;
38 #define to_omap_crtc(x) container_of(x, struct omap_crtc, base)
44 struct omap_drm_pipeline *pipe;
45 enum omap_channel channel;
49 bool ignore_digit_sync_lost;
53 wait_queue_head_t pending_wait;
54 struct drm_pending_vblank_event *event;
55 struct delayed_work update_work;
57 void (*framedone_handler)(void *);
58 void *framedone_handler_data;
61 /* -----------------------------------------------------------------------------
65 struct videomode *omap_crtc_timings(struct drm_crtc *crtc)
67 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
68 return &omap_crtc->vm;
71 enum omap_channel omap_crtc_channel(struct drm_crtc *crtc)
73 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
74 return omap_crtc->channel;
77 static bool omap_crtc_is_pending(struct drm_crtc *crtc)
79 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
83 spin_lock_irqsave(&crtc->dev->event_lock, flags);
84 pending = omap_crtc->pending;
85 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
90 int omap_crtc_wait_pending(struct drm_crtc *crtc)
92 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
95 * Timeout is set to a "sufficiently" high value, which should cover
96 * a single frame refresh even on slower displays.
98 return wait_event_timeout(omap_crtc->pending_wait,
99 !omap_crtc_is_pending(crtc),
100 msecs_to_jiffies(250));
103 /* -----------------------------------------------------------------------------
104 * DSS Manager Functions
108 * Manager-ops, callbacks from output when they need to configure
109 * the upstream part of the video pipe.
112 static void omap_crtc_dss_start_update(struct omap_drm_private *priv,
113 enum omap_channel channel)
115 priv->dispc_ops->mgr_enable(priv->dispc, channel, true);
118 /* Called only from the encoder enable/disable and suspend/resume handlers. */
119 static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable)
121 struct omap_crtc_state *omap_state = to_omap_crtc_state(crtc->state);
122 struct drm_device *dev = crtc->dev;
123 struct omap_drm_private *priv = dev->dev_private;
124 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
125 enum omap_channel channel = omap_crtc->channel;
126 struct omap_irq_wait *wait;
127 u32 framedone_irq, vsync_irq;
130 if (WARN_ON(omap_crtc->enabled == enable))
133 if (omap_state->manually_updated) {
134 omap_irq_enable_framedone(crtc, enable);
135 omap_crtc->enabled = enable;
139 if (omap_crtc->pipe->output->type == OMAP_DISPLAY_TYPE_HDMI) {
140 priv->dispc_ops->mgr_enable(priv->dispc, channel, enable);
141 omap_crtc->enabled = enable;
145 if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
147 * Digit output produces some sync lost interrupts during the
148 * first frame when enabling, so we need to ignore those.
150 omap_crtc->ignore_digit_sync_lost = true;
153 framedone_irq = priv->dispc_ops->mgr_get_framedone_irq(priv->dispc,
155 vsync_irq = priv->dispc_ops->mgr_get_vsync_irq(priv->dispc, channel);
158 wait = omap_irq_wait_init(dev, vsync_irq, 1);
161 * When we disable the digit output, we need to wait for
162 * FRAMEDONE to know that DISPC has finished with the output.
164 * OMAP2/3 does not have FRAMEDONE irq for digit output, and in
165 * that case we need to use vsync interrupt, and wait for both
166 * even and odd frames.
170 wait = omap_irq_wait_init(dev, framedone_irq, 1);
172 wait = omap_irq_wait_init(dev, vsync_irq, 2);
175 priv->dispc_ops->mgr_enable(priv->dispc, channel, enable);
176 omap_crtc->enabled = enable;
178 ret = omap_irq_wait(dev, wait, msecs_to_jiffies(100));
180 dev_err(dev->dev, "%s: timeout waiting for %s\n",
181 omap_crtc->name, enable ? "enable" : "disable");
184 if (omap_crtc->channel == OMAP_DSS_CHANNEL_DIGIT) {
185 omap_crtc->ignore_digit_sync_lost = false;
186 /* make sure the irq handler sees the value above */
192 static int omap_crtc_dss_enable(struct omap_drm_private *priv,
193 enum omap_channel channel)
195 struct drm_crtc *crtc = priv->channels[channel]->crtc;
196 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
198 priv->dispc_ops->mgr_set_timings(priv->dispc, omap_crtc->channel,
200 omap_crtc_set_enabled(&omap_crtc->base, true);
205 static void omap_crtc_dss_disable(struct omap_drm_private *priv,
206 enum omap_channel channel)
208 struct drm_crtc *crtc = priv->channels[channel]->crtc;
209 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
211 omap_crtc_set_enabled(&omap_crtc->base, false);
214 static void omap_crtc_dss_set_timings(struct omap_drm_private *priv,
215 enum omap_channel channel,
216 const struct videomode *vm)
218 struct drm_crtc *crtc = priv->channels[channel]->crtc;
219 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
221 DBG("%s", omap_crtc->name);
225 static void omap_crtc_dss_set_lcd_config(struct omap_drm_private *priv,
226 enum omap_channel channel,
227 const struct dss_lcd_mgr_config *config)
229 struct drm_crtc *crtc = priv->channels[channel]->crtc;
230 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
232 DBG("%s", omap_crtc->name);
233 priv->dispc_ops->mgr_set_lcd_config(priv->dispc, omap_crtc->channel,
237 static int omap_crtc_dss_register_framedone(
238 struct omap_drm_private *priv, enum omap_channel channel,
239 void (*handler)(void *), void *data)
241 struct drm_crtc *crtc = priv->channels[channel]->crtc;
242 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
243 struct drm_device *dev = omap_crtc->base.dev;
245 if (omap_crtc->framedone_handler)
248 dev_dbg(dev->dev, "register framedone %s", omap_crtc->name);
250 omap_crtc->framedone_handler = handler;
251 omap_crtc->framedone_handler_data = data;
256 static void omap_crtc_dss_unregister_framedone(
257 struct omap_drm_private *priv, enum omap_channel channel,
258 void (*handler)(void *), void *data)
260 struct drm_crtc *crtc = priv->channels[channel]->crtc;
261 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
262 struct drm_device *dev = omap_crtc->base.dev;
264 dev_dbg(dev->dev, "unregister framedone %s", omap_crtc->name);
266 WARN_ON(omap_crtc->framedone_handler != handler);
267 WARN_ON(omap_crtc->framedone_handler_data != data);
269 omap_crtc->framedone_handler = NULL;
270 omap_crtc->framedone_handler_data = NULL;
273 static const struct dss_mgr_ops mgr_ops = {
274 .start_update = omap_crtc_dss_start_update,
275 .enable = omap_crtc_dss_enable,
276 .disable = omap_crtc_dss_disable,
277 .set_timings = omap_crtc_dss_set_timings,
278 .set_lcd_config = omap_crtc_dss_set_lcd_config,
279 .register_framedone_handler = omap_crtc_dss_register_framedone,
280 .unregister_framedone_handler = omap_crtc_dss_unregister_framedone,
283 /* -----------------------------------------------------------------------------
284 * Setup, Flush and Page Flip
287 void omap_crtc_error_irq(struct drm_crtc *crtc, u32 irqstatus)
289 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
291 if (omap_crtc->ignore_digit_sync_lost) {
292 irqstatus &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
297 DRM_ERROR_RATELIMITED("%s: errors: %08x\n", omap_crtc->name, irqstatus);
300 void omap_crtc_vblank_irq(struct drm_crtc *crtc)
302 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
303 struct drm_device *dev = omap_crtc->base.dev;
304 struct omap_drm_private *priv = dev->dev_private;
307 spin_lock(&crtc->dev->event_lock);
309 * If the dispc is busy we're racing the flush operation. Try again on
310 * the next vblank interrupt.
312 if (priv->dispc_ops->mgr_go_busy(priv->dispc, omap_crtc->channel)) {
313 spin_unlock(&crtc->dev->event_lock);
317 /* Send the vblank event if one has been requested. */
318 if (omap_crtc->event) {
319 drm_crtc_send_vblank_event(crtc, omap_crtc->event);
320 omap_crtc->event = NULL;
323 pending = omap_crtc->pending;
324 omap_crtc->pending = false;
325 spin_unlock(&crtc->dev->event_lock);
328 drm_crtc_vblank_put(crtc);
330 /* Wake up omap_atomic_complete. */
331 wake_up(&omap_crtc->pending_wait);
333 DBG("%s: apply done", omap_crtc->name);
336 void omap_crtc_framedone_irq(struct drm_crtc *crtc, uint32_t irqstatus)
338 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
340 if (!omap_crtc->framedone_handler)
343 omap_crtc->framedone_handler(omap_crtc->framedone_handler_data);
345 spin_lock(&crtc->dev->event_lock);
346 /* Send the vblank event if one has been requested. */
347 if (omap_crtc->event) {
348 drm_crtc_send_vblank_event(crtc, omap_crtc->event);
349 omap_crtc->event = NULL;
351 omap_crtc->pending = false;
352 spin_unlock(&crtc->dev->event_lock);
354 /* Wake up omap_atomic_complete. */
355 wake_up(&omap_crtc->pending_wait);
358 void omap_crtc_flush(struct drm_crtc *crtc)
360 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
361 struct omap_crtc_state *omap_state = to_omap_crtc_state(crtc->state);
363 if (!omap_state->manually_updated)
366 if (!delayed_work_pending(&omap_crtc->update_work))
367 schedule_delayed_work(&omap_crtc->update_work, 0);
370 static void omap_crtc_manual_display_update(struct work_struct *data)
372 struct omap_crtc *omap_crtc =
373 container_of(data, struct omap_crtc, update_work.work);
374 struct drm_display_mode *mode = &omap_crtc->pipe->crtc->mode;
375 struct omap_dss_device *dssdev = omap_crtc->pipe->output->next;
376 struct drm_device *dev = omap_crtc->base.dev;
377 const struct omap_dss_driver *dssdrv;
381 dev_err_once(dev->dev, "missing display dssdev!");
385 dssdrv = dssdev->driver;
386 if (!dssdrv || !dssdrv->update) {
387 dev_err_once(dev->dev, "missing or incorrect dssdrv!");
392 dssdrv->sync(dssdev);
394 ret = dssdrv->update(dssdev, 0, 0, mode->hdisplay, mode->vdisplay);
396 spin_lock_irq(&dev->event_lock);
397 omap_crtc->pending = false;
398 spin_unlock_irq(&dev->event_lock);
399 wake_up(&omap_crtc->pending_wait);
403 static void omap_crtc_write_crtc_properties(struct drm_crtc *crtc)
405 struct omap_drm_private *priv = crtc->dev->dev_private;
406 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
407 struct omap_overlay_manager_info info;
409 memset(&info, 0, sizeof(info));
411 info.default_color = 0x000000;
412 info.trans_enabled = false;
413 info.partial_alpha_enabled = false;
414 info.cpr_enable = false;
416 priv->dispc_ops->mgr_setup(priv->dispc, omap_crtc->channel, &info);
419 /* -----------------------------------------------------------------------------
423 static void omap_crtc_destroy(struct drm_crtc *crtc)
425 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
427 DBG("%s", omap_crtc->name);
429 drm_crtc_cleanup(crtc);
434 static void omap_crtc_arm_event(struct drm_crtc *crtc)
436 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
438 WARN_ON(omap_crtc->pending);
439 omap_crtc->pending = true;
441 if (crtc->state->event) {
442 omap_crtc->event = crtc->state->event;
443 crtc->state->event = NULL;
447 static void omap_crtc_atomic_enable(struct drm_crtc *crtc,
448 struct drm_crtc_state *old_state)
450 struct omap_drm_private *priv = crtc->dev->dev_private;
451 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
452 struct omap_crtc_state *omap_state = to_omap_crtc_state(crtc->state);
455 DBG("%s", omap_crtc->name);
457 priv->dispc_ops->runtime_get(priv->dispc);
459 /* manual updated display will not trigger vsync irq */
460 if (omap_state->manually_updated)
463 spin_lock_irq(&crtc->dev->event_lock);
464 drm_crtc_vblank_on(crtc);
465 ret = drm_crtc_vblank_get(crtc);
468 omap_crtc_arm_event(crtc);
469 spin_unlock_irq(&crtc->dev->event_lock);
472 static void omap_crtc_atomic_disable(struct drm_crtc *crtc,
473 struct drm_crtc_state *old_state)
475 struct omap_drm_private *priv = crtc->dev->dev_private;
476 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
477 struct drm_device *dev = crtc->dev;
479 DBG("%s", omap_crtc->name);
481 spin_lock_irq(&crtc->dev->event_lock);
482 if (crtc->state->event) {
483 drm_crtc_send_vblank_event(crtc, crtc->state->event);
484 crtc->state->event = NULL;
486 spin_unlock_irq(&crtc->dev->event_lock);
488 cancel_delayed_work(&omap_crtc->update_work);
490 if (!omap_crtc_wait_pending(crtc))
491 dev_warn(dev->dev, "manual display update did not finish!");
493 drm_crtc_vblank_off(crtc);
495 priv->dispc_ops->runtime_put(priv->dispc);
498 static enum drm_mode_status omap_crtc_mode_valid(struct drm_crtc *crtc,
499 const struct drm_display_mode *mode)
501 struct omap_drm_private *priv = crtc->dev->dev_private;
502 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
503 struct videomode vm = {0};
506 drm_display_mode_to_videomode(mode, &vm);
509 * DSI might not call this, since the supplied mode is not a
510 * valid DISPC mode. DSI will calculate and configure the
511 * proper DISPC mode later.
513 if (omap_crtc->pipe->output->next == NULL ||
514 omap_crtc->pipe->output->next->type != OMAP_DISPLAY_TYPE_DSI) {
515 r = priv->dispc_ops->mgr_check_timings(priv->dispc,
522 /* Check for bandwidth limit */
523 if (priv->max_bandwidth) {
525 * Estimation for the bandwidth need of a given mode with one
527 * bandwidth = resolution * 32bpp * (pclk / (vtotal * htotal))
530 * The interlaced mode is taken into account by using the
531 * pixelclock in the calculation.
533 * The equation is rearranged for 64bit arithmetic.
535 uint64_t bandwidth = mode->clock * 1000;
536 unsigned int bpp = 4;
538 bandwidth = bandwidth * mode->hdisplay * mode->vdisplay * bpp;
539 bandwidth = div_u64(bandwidth, mode->htotal * mode->vtotal);
542 * Reject modes which would need more bandwidth if used with one
543 * full resolution plane (most common use case).
545 if (priv->max_bandwidth < bandwidth)
552 static void omap_crtc_mode_set_nofb(struct drm_crtc *crtc)
554 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
555 struct drm_display_mode *mode = &crtc->state->adjusted_mode;
557 DBG("%s: set mode: " DRM_MODE_FMT,
558 omap_crtc->name, DRM_MODE_ARG(mode));
560 drm_display_mode_to_videomode(mode, &omap_crtc->vm);
563 static bool omap_crtc_is_manually_updated(struct drm_crtc *crtc)
565 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
566 struct omap_dss_device *display = omap_crtc->pipe->output->next;
571 if (display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
572 DBG("detected manually updated display!");
579 static int omap_crtc_atomic_check(struct drm_crtc *crtc,
580 struct drm_crtc_state *state)
582 struct drm_plane_state *pri_state;
584 if (state->color_mgmt_changed && state->gamma_lut) {
585 unsigned int length = state->gamma_lut->length /
586 sizeof(struct drm_color_lut);
592 pri_state = drm_atomic_get_new_plane_state(state->state, crtc->primary);
594 struct omap_crtc_state *omap_crtc_state =
595 to_omap_crtc_state(state);
597 /* Mirror new values for zpos and rotation in omap_crtc_state */
598 omap_crtc_state->zpos = pri_state->zpos;
599 omap_crtc_state->rotation = pri_state->rotation;
601 /* Check if this CRTC is for a manually updated display */
602 omap_crtc_state->manually_updated = omap_crtc_is_manually_updated(crtc);
608 static void omap_crtc_atomic_begin(struct drm_crtc *crtc,
609 struct drm_crtc_state *old_crtc_state)
613 static void omap_crtc_atomic_flush(struct drm_crtc *crtc,
614 struct drm_crtc_state *old_crtc_state)
616 struct omap_drm_private *priv = crtc->dev->dev_private;
617 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
618 struct omap_crtc_state *omap_crtc_state = to_omap_crtc_state(crtc->state);
621 if (crtc->state->color_mgmt_changed) {
622 struct drm_color_lut *lut = NULL;
623 unsigned int length = 0;
625 if (crtc->state->gamma_lut) {
626 lut = (struct drm_color_lut *)
627 crtc->state->gamma_lut->data;
628 length = crtc->state->gamma_lut->length /
631 priv->dispc_ops->mgr_set_gamma(priv->dispc, omap_crtc->channel,
635 omap_crtc_write_crtc_properties(crtc);
637 /* Only flush the CRTC if it is currently enabled. */
638 if (!omap_crtc->enabled)
641 DBG("%s: GO", omap_crtc->name);
643 if (omap_crtc_state->manually_updated) {
644 /* send new image for page flips and modeset changes */
645 spin_lock_irq(&crtc->dev->event_lock);
646 omap_crtc_flush(crtc);
647 omap_crtc_arm_event(crtc);
648 spin_unlock_irq(&crtc->dev->event_lock);
652 ret = drm_crtc_vblank_get(crtc);
655 spin_lock_irq(&crtc->dev->event_lock);
656 priv->dispc_ops->mgr_go(priv->dispc, omap_crtc->channel);
657 omap_crtc_arm_event(crtc);
658 spin_unlock_irq(&crtc->dev->event_lock);
661 static int omap_crtc_atomic_set_property(struct drm_crtc *crtc,
662 struct drm_crtc_state *state,
663 struct drm_property *property,
666 struct omap_drm_private *priv = crtc->dev->dev_private;
667 struct drm_plane_state *plane_state;
670 * Delegate property set to the primary plane. Get the plane state and
671 * set the property directly, the shadow copy will be assigned in the
672 * omap_crtc_atomic_check callback. This way updates to plane state will
673 * always be mirrored in the crtc state correctly.
675 plane_state = drm_atomic_get_plane_state(state->state, crtc->primary);
676 if (IS_ERR(plane_state))
677 return PTR_ERR(plane_state);
679 if (property == crtc->primary->rotation_property)
680 plane_state->rotation = val;
681 else if (property == priv->zorder_prop)
682 plane_state->zpos = val;
689 static int omap_crtc_atomic_get_property(struct drm_crtc *crtc,
690 const struct drm_crtc_state *state,
691 struct drm_property *property,
694 struct omap_drm_private *priv = crtc->dev->dev_private;
695 struct omap_crtc_state *omap_state = to_omap_crtc_state(state);
697 if (property == crtc->primary->rotation_property)
698 *val = omap_state->rotation;
699 else if (property == priv->zorder_prop)
700 *val = omap_state->zpos;
707 static void omap_crtc_reset(struct drm_crtc *crtc)
710 __drm_atomic_helper_crtc_destroy_state(crtc->state);
713 crtc->state = kzalloc(sizeof(struct omap_crtc_state), GFP_KERNEL);
716 crtc->state->crtc = crtc;
719 static struct drm_crtc_state *
720 omap_crtc_duplicate_state(struct drm_crtc *crtc)
722 struct omap_crtc_state *state, *current_state;
724 if (WARN_ON(!crtc->state))
727 current_state = to_omap_crtc_state(crtc->state);
729 state = kmalloc(sizeof(*state), GFP_KERNEL);
733 __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
735 state->zpos = current_state->zpos;
736 state->rotation = current_state->rotation;
737 state->manually_updated = current_state->manually_updated;
742 static const struct drm_crtc_funcs omap_crtc_funcs = {
743 .reset = omap_crtc_reset,
744 .set_config = drm_atomic_helper_set_config,
745 .destroy = omap_crtc_destroy,
746 .page_flip = drm_atomic_helper_page_flip,
747 .gamma_set = drm_atomic_helper_legacy_gamma_set,
748 .atomic_duplicate_state = omap_crtc_duplicate_state,
749 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
750 .atomic_set_property = omap_crtc_atomic_set_property,
751 .atomic_get_property = omap_crtc_atomic_get_property,
752 .enable_vblank = omap_irq_enable_vblank,
753 .disable_vblank = omap_irq_disable_vblank,
756 static const struct drm_crtc_helper_funcs omap_crtc_helper_funcs = {
757 .mode_set_nofb = omap_crtc_mode_set_nofb,
758 .atomic_check = omap_crtc_atomic_check,
759 .atomic_begin = omap_crtc_atomic_begin,
760 .atomic_flush = omap_crtc_atomic_flush,
761 .atomic_enable = omap_crtc_atomic_enable,
762 .atomic_disable = omap_crtc_atomic_disable,
763 .mode_valid = omap_crtc_mode_valid,
766 /* -----------------------------------------------------------------------------
770 static const char *channel_names[] = {
771 [OMAP_DSS_CHANNEL_LCD] = "lcd",
772 [OMAP_DSS_CHANNEL_DIGIT] = "tv",
773 [OMAP_DSS_CHANNEL_LCD2] = "lcd2",
774 [OMAP_DSS_CHANNEL_LCD3] = "lcd3",
777 void omap_crtc_pre_init(struct omap_drm_private *priv)
779 dss_install_mgr_ops(priv->dss, &mgr_ops, priv);
782 void omap_crtc_pre_uninit(struct omap_drm_private *priv)
784 dss_uninstall_mgr_ops(priv->dss);
787 /* initialize crtc */
788 struct drm_crtc *omap_crtc_init(struct drm_device *dev,
789 struct omap_drm_pipeline *pipe,
790 struct drm_plane *plane)
792 struct omap_drm_private *priv = dev->dev_private;
793 struct drm_crtc *crtc = NULL;
794 struct omap_crtc *omap_crtc;
795 enum omap_channel channel;
798 channel = pipe->output->dispc_channel;
800 DBG("%s", channel_names[channel]);
802 omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL);
804 return ERR_PTR(-ENOMEM);
806 crtc = &omap_crtc->base;
808 init_waitqueue_head(&omap_crtc->pending_wait);
810 omap_crtc->pipe = pipe;
811 omap_crtc->channel = channel;
812 omap_crtc->name = channel_names[channel];
815 * We want to refresh manually updated displays from dirty callback,
816 * which is called quite often (e.g. for each drawn line). This will
817 * be used to do the display update asynchronously to avoid blocking
818 * the rendering process and merges multiple dirty calls into one
819 * update if they arrive very fast. We also call this function for
820 * atomic display updates (e.g. for page flips), which means we do
821 * not need extra locking. Atomic updates should be synchronous, but
822 * need to wait for the framedone interrupt anyways.
824 INIT_DELAYED_WORK(&omap_crtc->update_work,
825 omap_crtc_manual_display_update);
827 ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
828 &omap_crtc_funcs, NULL);
830 dev_err(dev->dev, "%s(): could not init crtc for: %s\n",
831 __func__, pipe->output->name);
836 drm_crtc_helper_add(crtc, &omap_crtc_helper_funcs);
838 /* The dispc API adapts to what ever size, but the HW supports
839 * 256 element gamma table for LCDs and 1024 element table for
840 * OMAP_DSS_CHANNEL_DIGIT. X server assumes 256 element gamma
841 * tables so lets use that. Size of HW gamma table can be
842 * extracted with dispc_mgr_gamma_size(). If it returns 0
843 * gamma table is not supprted.
845 if (priv->dispc_ops->mgr_gamma_size(priv->dispc, channel)) {
846 unsigned int gamma_lut_size = 256;
848 drm_crtc_enable_color_mgmt(crtc, 0, false, gamma_lut_size);
849 drm_mode_crtc_set_gamma_size(crtc, gamma_lut_size);
852 omap_plane_install_properties(crtc->primary, &crtc->base);