drm/exynos: Add disable of manager
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / gpu / drm / exynos / exynos_drm_encoder.c
blob153061415bafba2d3c83d155a7e86a4901db0b52
1 /* exynos_drm_encoder.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 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
29 #include "drmP.h"
30 #include "drm_crtc_helper.h"
32 #include "exynos_drm_drv.h"
33 #include "exynos_drm_crtc.h"
34 #include "exynos_drm_encoder.h"
36 #define to_exynos_encoder(x) container_of(x, struct exynos_drm_encoder,\
37 drm_encoder)
40 * exynos specific encoder structure.
42 * @drm_encoder: encoder object.
43 * @manager: specific encoder has its own manager to control a hardware
44 * appropriately and we can access a hardware drawing on this manager.
46 struct exynos_drm_encoder {
47 struct drm_encoder drm_encoder;
48 struct exynos_drm_manager *manager;
51 static void exynos_drm_encoder_dpms(struct drm_encoder *encoder, int mode)
53 struct drm_device *dev = encoder->dev;
54 struct drm_connector *connector;
55 struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder);
56 struct exynos_drm_manager_ops *manager_ops = manager->ops;
58 DRM_DEBUG_KMS("%s, encoder dpms: %d\n", __FILE__, mode);
60 switch (mode) {
61 case DRM_MODE_DPMS_ON:
62 if (manager_ops && manager_ops->commit)
63 manager_ops->commit(manager->dev);
64 break;
65 case DRM_MODE_DPMS_STANDBY:
66 case DRM_MODE_DPMS_SUSPEND:
67 case DRM_MODE_DPMS_OFF:
68 /* TODO */
69 if (manager_ops && manager_ops->disable)
70 manager_ops->disable(manager->dev);
71 break;
72 default:
73 DRM_ERROR("unspecified mode %d\n", mode);
74 break;
77 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
78 if (connector->encoder == encoder) {
79 struct exynos_drm_display_ops *display_ops =
80 manager->display_ops;
82 DRM_DEBUG_KMS("connector[%d] dpms[%d]\n",
83 connector->base.id, mode);
84 if (display_ops && display_ops->power_on)
85 display_ops->power_on(manager->dev, mode);
90 static bool
91 exynos_drm_encoder_mode_fixup(struct drm_encoder *encoder,
92 struct drm_display_mode *mode,
93 struct drm_display_mode *adjusted_mode)
95 DRM_DEBUG_KMS("%s\n", __FILE__);
97 /* drm framework doesn't check NULL. */
99 return true;
102 static void exynos_drm_encoder_mode_set(struct drm_encoder *encoder,
103 struct drm_display_mode *mode,
104 struct drm_display_mode *adjusted_mode)
106 struct drm_device *dev = encoder->dev;
107 struct drm_connector *connector;
108 struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder);
109 struct exynos_drm_manager_ops *manager_ops = manager->ops;
110 struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops;
111 struct exynos_drm_overlay *overlay = get_exynos_drm_overlay(dev,
112 encoder->crtc);
114 DRM_DEBUG_KMS("%s\n", __FILE__);
116 mode = adjusted_mode;
118 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
119 if (connector->encoder == encoder) {
120 if (manager_ops && manager_ops->mode_set)
121 manager_ops->mode_set(manager->dev, mode);
123 if (overlay_ops && overlay_ops->mode_set)
124 overlay_ops->mode_set(manager->dev, overlay);
129 static void exynos_drm_encoder_prepare(struct drm_encoder *encoder)
131 DRM_DEBUG_KMS("%s\n", __FILE__);
133 /* drm framework doesn't check NULL. */
136 static void exynos_drm_encoder_commit(struct drm_encoder *encoder)
138 struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder);
139 struct exynos_drm_manager_ops *manager_ops = manager->ops;
141 DRM_DEBUG_KMS("%s\n", __FILE__);
143 if (manager_ops && manager_ops->commit)
144 manager_ops->commit(manager->dev);
147 static struct drm_crtc *
148 exynos_drm_encoder_get_crtc(struct drm_encoder *encoder)
150 return encoder->crtc;
153 static struct drm_encoder_helper_funcs exynos_encoder_helper_funcs = {
154 .dpms = exynos_drm_encoder_dpms,
155 .mode_fixup = exynos_drm_encoder_mode_fixup,
156 .mode_set = exynos_drm_encoder_mode_set,
157 .prepare = exynos_drm_encoder_prepare,
158 .commit = exynos_drm_encoder_commit,
159 .get_crtc = exynos_drm_encoder_get_crtc,
162 static void exynos_drm_encoder_destroy(struct drm_encoder *encoder)
164 struct exynos_drm_encoder *exynos_encoder =
165 to_exynos_encoder(encoder);
167 DRM_DEBUG_KMS("%s\n", __FILE__);
169 exynos_encoder->manager->pipe = -1;
171 drm_encoder_cleanup(encoder);
172 encoder->dev->mode_config.num_encoder--;
173 kfree(exynos_encoder);
176 static struct drm_encoder_funcs exynos_encoder_funcs = {
177 .destroy = exynos_drm_encoder_destroy,
180 struct drm_encoder *
181 exynos_drm_encoder_create(struct drm_device *dev,
182 struct exynos_drm_manager *manager,
183 unsigned int possible_crtcs)
185 struct drm_encoder *encoder;
186 struct exynos_drm_encoder *exynos_encoder;
188 DRM_DEBUG_KMS("%s\n", __FILE__);
190 if (!manager || !possible_crtcs)
191 return NULL;
193 if (!manager->dev)
194 return NULL;
196 exynos_encoder = kzalloc(sizeof(*exynos_encoder), GFP_KERNEL);
197 if (!exynos_encoder) {
198 DRM_ERROR("failed to allocate encoder\n");
199 return NULL;
202 exynos_encoder->manager = manager;
203 encoder = &exynos_encoder->drm_encoder;
204 encoder->possible_crtcs = possible_crtcs;
206 DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
208 drm_encoder_init(dev, encoder, &exynos_encoder_funcs,
209 DRM_MODE_ENCODER_TMDS);
211 drm_encoder_helper_add(encoder, &exynos_encoder_helper_funcs);
213 DRM_DEBUG_KMS("encoder has been created\n");
215 return encoder;
218 struct exynos_drm_manager *exynos_drm_get_manager(struct drm_encoder *encoder)
220 return to_exynos_encoder(encoder)->manager;
223 void exynos_drm_fn_encoder(struct drm_crtc *crtc, void *data,
224 void (*fn)(struct drm_encoder *, void *))
226 struct drm_device *dev = crtc->dev;
227 struct drm_encoder *encoder;
228 struct exynos_drm_private *private = dev->dev_private;
229 struct exynos_drm_manager *manager;
231 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
233 * if crtc is detached from encoder, check pipe,
234 * otherwise check crtc attached to encoder
236 if (!encoder->crtc) {
237 manager = to_exynos_encoder(encoder)->manager;
238 if (manager->pipe < 0 ||
239 private->crtc[manager->pipe] != crtc)
240 continue;
241 } else {
242 if (encoder->crtc != crtc)
243 continue;
246 fn(encoder, data);
250 void exynos_drm_enable_vblank(struct drm_encoder *encoder, void *data)
252 struct exynos_drm_manager *manager =
253 to_exynos_encoder(encoder)->manager;
254 struct exynos_drm_manager_ops *manager_ops = manager->ops;
255 int crtc = *(int *)data;
257 if (manager->pipe == -1)
258 manager->pipe = crtc;
260 if (manager_ops->enable_vblank)
261 manager_ops->enable_vblank(manager->dev);
264 void exynos_drm_disable_vblank(struct drm_encoder *encoder, void *data)
266 struct exynos_drm_manager *manager =
267 to_exynos_encoder(encoder)->manager;
268 struct exynos_drm_manager_ops *manager_ops = manager->ops;
269 int crtc = *(int *)data;
271 if (manager->pipe == -1)
272 manager->pipe = crtc;
274 if (manager_ops->disable_vblank)
275 manager_ops->disable_vblank(manager->dev);
278 void exynos_drm_encoder_crtc_commit(struct drm_encoder *encoder, void *data)
280 struct exynos_drm_manager *manager =
281 to_exynos_encoder(encoder)->manager;
282 struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops;
283 int crtc = *(int *)data;
285 DRM_DEBUG_KMS("%s\n", __FILE__);
288 * when crtc is detached from encoder, this pipe is used
289 * to select manager operation
291 manager->pipe = crtc;
293 if (overlay_ops && overlay_ops->commit)
294 overlay_ops->commit(manager->dev);
297 void exynos_drm_encoder_crtc_mode_set(struct drm_encoder *encoder, void *data)
299 struct exynos_drm_manager *manager =
300 to_exynos_encoder(encoder)->manager;
301 struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops;
302 struct exynos_drm_overlay *overlay = data;
304 if (overlay_ops && overlay_ops->mode_set)
305 overlay_ops->mode_set(manager->dev, overlay);
308 void exynos_drm_encoder_crtc_disable(struct drm_encoder *encoder, void *data)
310 struct exynos_drm_manager *manager =
311 to_exynos_encoder(encoder)->manager;
312 struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops;
314 DRM_DEBUG_KMS("\n");
316 if (overlay_ops && overlay_ops->disable)
317 overlay_ops->disable(manager->dev);
320 * crtc is already detached from encoder and last
321 * function for detaching is properly done, so
322 * clear pipe from manager to prevent repeated call
324 if (!encoder->crtc)
325 manager->pipe = -1;
328 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
329 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
330 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
331 MODULE_DESCRIPTION("Samsung SoC DRM Encoder Driver");
332 MODULE_LICENSE("GPL");