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