drm/nouveau/fb: add gm20b device
[linux/fpc-iii.git] / drivers / gpu / drm / exynos / exynos_drm_crtc.c
blob2530bf57716a93a800fca4b1a1608052cfe7db39
1 /* exynos_drm_crtc.c
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Authors:
5 * Inki Dae <inki.dae@samsung.com>
6 * Joonyoung Shim <jy0922.shim@samsung.com>
7 * Seung-Woo Kim <sw0312.kim@samsung.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
15 #include <drm/drmP.h>
16 #include <drm/drm_crtc_helper.h>
17 #include <drm/drm_atomic.h>
18 #include <drm/drm_atomic_helper.h>
20 #include "exynos_drm_crtc.h"
21 #include "exynos_drm_drv.h"
22 #include "exynos_drm_plane.h"
24 static void exynos_drm_crtc_enable(struct drm_crtc *crtc)
26 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
28 if (exynos_crtc->ops->enable)
29 exynos_crtc->ops->enable(exynos_crtc);
31 drm_crtc_vblank_on(crtc);
34 static void exynos_drm_crtc_disable(struct drm_crtc *crtc)
36 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
38 drm_crtc_vblank_off(crtc);
40 if (exynos_crtc->ops->disable)
41 exynos_crtc->ops->disable(exynos_crtc);
44 static void
45 exynos_drm_crtc_mode_set_nofb(struct drm_crtc *crtc)
47 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
49 if (exynos_crtc->ops->commit)
50 exynos_crtc->ops->commit(exynos_crtc);
53 static int exynos_crtc_atomic_check(struct drm_crtc *crtc,
54 struct drm_crtc_state *state)
56 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
58 if (!state->enable)
59 return 0;
61 if (exynos_crtc->ops->atomic_check)
62 return exynos_crtc->ops->atomic_check(exynos_crtc, state);
64 return 0;
67 static void exynos_crtc_atomic_begin(struct drm_crtc *crtc,
68 struct drm_crtc_state *old_crtc_state)
70 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
72 if (exynos_crtc->ops->atomic_begin)
73 exynos_crtc->ops->atomic_begin(exynos_crtc);
76 static void exynos_crtc_atomic_flush(struct drm_crtc *crtc,
77 struct drm_crtc_state *old_crtc_state)
79 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
80 struct drm_pending_vblank_event *event;
81 unsigned long flags;
83 if (exynos_crtc->ops->atomic_flush)
84 exynos_crtc->ops->atomic_flush(exynos_crtc);
86 event = crtc->state->event;
87 if (event) {
88 crtc->state->event = NULL;
90 spin_lock_irqsave(&crtc->dev->event_lock, flags);
91 if (drm_crtc_vblank_get(crtc) == 0)
92 drm_crtc_arm_vblank_event(crtc, event);
93 else
94 drm_crtc_send_vblank_event(crtc, event);
95 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
100 static const struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = {
101 .enable = exynos_drm_crtc_enable,
102 .disable = exynos_drm_crtc_disable,
103 .mode_set_nofb = exynos_drm_crtc_mode_set_nofb,
104 .atomic_check = exynos_crtc_atomic_check,
105 .atomic_begin = exynos_crtc_atomic_begin,
106 .atomic_flush = exynos_crtc_atomic_flush,
109 static void exynos_drm_crtc_destroy(struct drm_crtc *crtc)
111 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
112 struct exynos_drm_private *private = crtc->dev->dev_private;
114 private->crtc[exynos_crtc->pipe] = NULL;
116 drm_crtc_cleanup(crtc);
117 kfree(exynos_crtc);
120 static const struct drm_crtc_funcs exynos_crtc_funcs = {
121 .set_config = drm_atomic_helper_set_config,
122 .page_flip = drm_atomic_helper_page_flip,
123 .destroy = exynos_drm_crtc_destroy,
124 .reset = drm_atomic_helper_crtc_reset,
125 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
126 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
129 struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
130 struct drm_plane *plane,
131 int pipe,
132 enum exynos_drm_output_type type,
133 const struct exynos_drm_crtc_ops *ops,
134 void *ctx)
136 struct exynos_drm_crtc *exynos_crtc;
137 struct exynos_drm_private *private = drm_dev->dev_private;
138 struct drm_crtc *crtc;
139 int ret;
141 exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL);
142 if (!exynos_crtc)
143 return ERR_PTR(-ENOMEM);
145 exynos_crtc->pipe = pipe;
146 exynos_crtc->type = type;
147 exynos_crtc->ops = ops;
148 exynos_crtc->ctx = ctx;
150 crtc = &exynos_crtc->base;
152 private->crtc[pipe] = crtc;
154 ret = drm_crtc_init_with_planes(drm_dev, crtc, plane, NULL,
155 &exynos_crtc_funcs, NULL);
156 if (ret < 0)
157 goto err_crtc;
159 drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
161 return exynos_crtc;
163 err_crtc:
164 plane->funcs->destroy(plane);
165 kfree(exynos_crtc);
166 return ERR_PTR(ret);
169 int exynos_drm_crtc_enable_vblank(struct drm_device *dev, unsigned int pipe)
171 struct exynos_drm_crtc *exynos_crtc = exynos_drm_crtc_from_pipe(dev,
172 pipe);
174 if (exynos_crtc->ops->enable_vblank)
175 return exynos_crtc->ops->enable_vblank(exynos_crtc);
177 return 0;
180 void exynos_drm_crtc_disable_vblank(struct drm_device *dev, unsigned int pipe)
182 struct exynos_drm_crtc *exynos_crtc = exynos_drm_crtc_from_pipe(dev,
183 pipe);
185 if (exynos_crtc->ops->disable_vblank)
186 exynos_crtc->ops->disable_vblank(exynos_crtc);
189 int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev,
190 enum exynos_drm_output_type out_type)
192 struct drm_crtc *crtc;
194 list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) {
195 struct exynos_drm_crtc *exynos_crtc;
197 exynos_crtc = to_exynos_crtc(crtc);
198 if (exynos_crtc->type == out_type)
199 return exynos_crtc->pipe;
202 return -EPERM;
205 void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
207 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
209 if (exynos_crtc->ops->te_handler)
210 exynos_crtc->ops->te_handler(exynos_crtc);
213 void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc,
214 struct drm_file *file)
216 struct drm_pending_vblank_event *e;
217 unsigned long flags;
219 spin_lock_irqsave(&crtc->dev->event_lock, flags);
221 e = crtc->state->event;
222 if (e && e->base.file_priv == file)
223 crtc->state->event = NULL;
224 else
225 e = NULL;
227 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
229 if (e)
230 drm_event_cancel_free(crtc->dev, &e->base);