Commit | Line | Data |
---|---|---|
1c248b7d ID |
1 | /* exynos_drm_crtc.c |
2 | * | |
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> | |
8 | * | |
d81aecb5 ID |
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. | |
1c248b7d ID |
13 | */ |
14 | ||
760285e7 DH |
15 | #include <drm/drmP.h> |
16 | #include <drm/drm_crtc_helper.h> | |
4ea9526b GP |
17 | #include <drm/drm_atomic.h> |
18 | #include <drm/drm_atomic_helper.h> | |
1c248b7d | 19 | |
e30655d0 | 20 | #include "exynos_drm_crtc.h" |
1c248b7d | 21 | #include "exynos_drm_drv.h" |
b5d2eb3b | 22 | #include "exynos_drm_plane.h" |
1c248b7d | 23 | |
63498e30 | 24 | static void exynos_drm_crtc_enable(struct drm_crtc *crtc) |
1c248b7d | 25 | { |
d2716c89 | 26 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
1c248b7d | 27 | |
3cecda03 GP |
28 | if (exynos_crtc->ops->enable) |
29 | exynos_crtc->ops->enable(exynos_crtc); | |
080be03d | 30 | |
63498e30 | 31 | drm_crtc_vblank_on(crtc); |
1c248b7d ID |
32 | } |
33 | ||
3fc4867c GP |
34 | static void exynos_drm_crtc_disable(struct drm_crtc *crtc) |
35 | { | |
63498e30 | 36 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
3fc4867c | 37 | |
63498e30 GP |
38 | drm_crtc_vblank_off(crtc); |
39 | ||
3cecda03 GP |
40 | if (exynos_crtc->ops->disable) |
41 | exynos_crtc->ops->disable(exynos_crtc); | |
41cbf0fd ID |
42 | |
43 | if (crtc->state->event && !crtc->state->active) { | |
44 | spin_lock_irq(&crtc->dev->event_lock); | |
45 | drm_crtc_send_vblank_event(crtc, crtc->state->event); | |
46 | spin_unlock_irq(&crtc->dev->event_lock); | |
47 | ||
48 | crtc->state->event = NULL; | |
49 | } | |
3fc4867c GP |
50 | } |
51 | ||
199329cb GP |
52 | static void |
53 | exynos_drm_crtc_mode_set_nofb(struct drm_crtc *crtc) | |
1c248b7d | 54 | { |
4070d212 | 55 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
32aeab17 | 56 | |
199329cb GP |
57 | if (exynos_crtc->ops->commit) |
58 | exynos_crtc->ops->commit(exynos_crtc); | |
1c248b7d ID |
59 | } |
60 | ||
5625b341 AH |
61 | static int exynos_crtc_atomic_check(struct drm_crtc *crtc, |
62 | struct drm_crtc_state *state) | |
63 | { | |
64 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); | |
65 | ||
c4e07407 AH |
66 | if (!state->enable) |
67 | return 0; | |
68 | ||
5625b341 AH |
69 | if (exynos_crtc->ops->atomic_check) |
70 | return exynos_crtc->ops->atomic_check(exynos_crtc, state); | |
71 | ||
72 | return 0; | |
73 | } | |
74 | ||
613d2b27 ML |
75 | static void exynos_crtc_atomic_begin(struct drm_crtc *crtc, |
76 | struct drm_crtc_state *old_crtc_state) | |
9d5ab6a0 GP |
77 | { |
78 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); | |
79 | ||
d29c2c14 MS |
80 | if (exynos_crtc->ops->atomic_begin) |
81 | exynos_crtc->ops->atomic_begin(exynos_crtc); | |
9d5ab6a0 GP |
82 | } |
83 | ||
613d2b27 ML |
84 | static void exynos_crtc_atomic_flush(struct drm_crtc *crtc, |
85 | struct drm_crtc_state *old_crtc_state) | |
9d5ab6a0 | 86 | { |
d9220d47 | 87 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
9276dff7 AH |
88 | struct drm_pending_vblank_event *event; |
89 | unsigned long flags; | |
d9220d47 | 90 | |
d29c2c14 MS |
91 | if (exynos_crtc->ops->atomic_flush) |
92 | exynos_crtc->ops->atomic_flush(exynos_crtc); | |
9276dff7 AH |
93 | |
94 | event = crtc->state->event; | |
95 | if (event) { | |
96 | crtc->state->event = NULL; | |
97 | ||
98 | spin_lock_irqsave(&crtc->dev->event_lock, flags); | |
99 | if (drm_crtc_vblank_get(crtc) == 0) | |
100 | drm_crtc_arm_vblank_event(crtc, event); | |
101 | else | |
102 | drm_crtc_send_vblank_event(crtc, event); | |
103 | spin_unlock_irqrestore(&crtc->dev->event_lock, flags); | |
104 | } | |
105 | ||
9d5ab6a0 GP |
106 | } |
107 | ||
800ba2b5 | 108 | static const struct drm_crtc_helper_funcs exynos_crtc_helper_funcs = { |
63498e30 | 109 | .enable = exynos_drm_crtc_enable, |
3fc4867c | 110 | .disable = exynos_drm_crtc_disable, |
199329cb | 111 | .mode_set_nofb = exynos_drm_crtc_mode_set_nofb, |
5625b341 | 112 | .atomic_check = exynos_crtc_atomic_check, |
9d5ab6a0 GP |
113 | .atomic_begin = exynos_crtc_atomic_begin, |
114 | .atomic_flush = exynos_crtc_atomic_flush, | |
1c248b7d ID |
115 | }; |
116 | ||
1c248b7d ID |
117 | static void exynos_drm_crtc_destroy(struct drm_crtc *crtc) |
118 | { | |
119 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); | |
1c248b7d ID |
120 | |
121 | drm_crtc_cleanup(crtc); | |
122 | kfree(exynos_crtc); | |
123 | } | |
124 | ||
800ba2b5 | 125 | static const struct drm_crtc_funcs exynos_crtc_funcs = { |
47a7deff | 126 | .set_config = drm_atomic_helper_set_config, |
9d5ab6a0 | 127 | .page_flip = drm_atomic_helper_page_flip, |
1c248b7d | 128 | .destroy = exynos_drm_crtc_destroy, |
4ea9526b GP |
129 | .reset = drm_atomic_helper_crtc_reset, |
130 | .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, | |
131 | .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, | |
1c248b7d ID |
132 | }; |
133 | ||
93bca243 | 134 | struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev, |
f3aaf762 KK |
135 | struct drm_plane *plane, |
136 | int pipe, | |
137 | enum exynos_drm_output_type type, | |
138 | const struct exynos_drm_crtc_ops *ops, | |
139 | void *ctx) | |
1c248b7d ID |
140 | { |
141 | struct exynos_drm_crtc *exynos_crtc; | |
1c248b7d | 142 | struct drm_crtc *crtc; |
72ed6ccd | 143 | int ret; |
1c248b7d | 144 | |
1c248b7d | 145 | exynos_crtc = kzalloc(sizeof(*exynos_crtc), GFP_KERNEL); |
38bb5253 | 146 | if (!exynos_crtc) |
93bca243 | 147 | return ERR_PTR(-ENOMEM); |
1c248b7d | 148 | |
e09f2b0d | 149 | exynos_crtc->pipe = pipe; |
5d1741ad | 150 | exynos_crtc->type = type; |
93bca243 GP |
151 | exynos_crtc->ops = ops; |
152 | exynos_crtc->ctx = ctx; | |
b5d2eb3b | 153 | |
357193cd | 154 | crtc = &exynos_crtc->base; |
1c248b7d | 155 | |
eb88e422 | 156 | ret = drm_crtc_init_with_planes(drm_dev, crtc, plane, NULL, |
f9882876 | 157 | &exynos_crtc_funcs, NULL); |
72ed6ccd AH |
158 | if (ret < 0) |
159 | goto err_crtc; | |
160 | ||
1c248b7d ID |
161 | drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs); |
162 | ||
93bca243 | 163 | return exynos_crtc; |
72ed6ccd AH |
164 | |
165 | err_crtc: | |
166 | plane->funcs->destroy(plane); | |
72ed6ccd | 167 | kfree(exynos_crtc); |
93bca243 | 168 | return ERR_PTR(ret); |
1c248b7d ID |
169 | } |
170 | ||
88e72717 | 171 | int exynos_drm_crtc_enable_vblank(struct drm_device *dev, unsigned int pipe) |
1c248b7d | 172 | { |
27019328 AH |
173 | struct exynos_drm_crtc *exynos_crtc = exynos_drm_crtc_from_pipe(dev, |
174 | pipe); | |
1c248b7d | 175 | |
93bca243 | 176 | if (exynos_crtc->ops->enable_vblank) |
08dd2009 | 177 | return exynos_crtc->ops->enable_vblank(exynos_crtc); |
1c248b7d ID |
178 | |
179 | return 0; | |
180 | } | |
181 | ||
88e72717 | 182 | void exynos_drm_crtc_disable_vblank(struct drm_device *dev, unsigned int pipe) |
1c248b7d | 183 | { |
27019328 AH |
184 | struct exynos_drm_crtc *exynos_crtc = exynos_drm_crtc_from_pipe(dev, |
185 | pipe); | |
1c248b7d | 186 | |
93bca243 GP |
187 | if (exynos_crtc->ops->disable_vblank) |
188 | exynos_crtc->ops->disable_vblank(exynos_crtc); | |
1c248b7d | 189 | } |
663d8766 | 190 | |
f37cd5e8 | 191 | int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev, |
cf67cc9a | 192 | enum exynos_drm_output_type out_type) |
f37cd5e8 ID |
193 | { |
194 | struct drm_crtc *crtc; | |
195 | ||
196 | list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) { | |
197 | struct exynos_drm_crtc *exynos_crtc; | |
198 | ||
199 | exynos_crtc = to_exynos_crtc(crtc); | |
5d1741ad | 200 | if (exynos_crtc->type == out_type) |
8a326edd | 201 | return exynos_crtc->pipe; |
f37cd5e8 ID |
202 | } |
203 | ||
204 | return -EPERM; | |
205 | } | |
5595d4d8 YC |
206 | |
207 | void exynos_drm_crtc_te_handler(struct drm_crtc *crtc) | |
208 | { | |
93bca243 | 209 | struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); |
5595d4d8 | 210 | |
93bca243 GP |
211 | if (exynos_crtc->ops->te_handler) |
212 | exynos_crtc->ops->te_handler(exynos_crtc); | |
5595d4d8 | 213 | } |