PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / gpu / drm / omapdrm / omap_encoder.c
blob5290a88c681db3e6cd2d4a9e4fa32c0e50230153
1 /*
2 * drivers/gpu/drm/omapdrm/omap_encoder.c
4 * Copyright (C) 2011 Texas Instruments
5 * Author: Rob Clark <rob@ti.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "omap_drv.h"
22 #include "drm_crtc.h"
23 #include "drm_crtc_helper.h"
25 #include <linux/list.h>
29 * encoder funcs
32 #define to_omap_encoder(x) container_of(x, struct omap_encoder, base)
34 /* The encoder and connector both map to same dssdev.. the encoder
35 * handles the 'active' parts, ie. anything the modifies the state
36 * of the hw, and the connector handles the 'read-only' parts, like
37 * detecting connection and reading edid.
39 struct omap_encoder {
40 struct drm_encoder base;
41 struct omap_dss_device *dssdev;
44 struct omap_dss_device *omap_encoder_get_dssdev(struct drm_encoder *encoder)
46 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
48 return omap_encoder->dssdev;
51 static void omap_encoder_destroy(struct drm_encoder *encoder)
53 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
55 omap_encoder_set_enabled(encoder, false);
57 drm_encoder_cleanup(encoder);
58 kfree(omap_encoder);
61 static const struct drm_encoder_funcs omap_encoder_funcs = {
62 .destroy = omap_encoder_destroy,
66 * The CRTC drm_crtc_helper_set_mode() doesn't really give us the right
67 * order.. the easiest way to work around this for now is to make all
68 * the encoder-helper's no-op's and have the omap_crtc code take care
69 * of the sequencing and call us in the right points.
71 * Eventually to handle connecting CRTCs to different encoders properly,
72 * either the CRTC helpers need to change or we need to replace
73 * drm_crtc_helper_set_mode(), but lets wait until atomic-modeset for
74 * that.
77 static void omap_encoder_dpms(struct drm_encoder *encoder, int mode)
81 static bool omap_encoder_mode_fixup(struct drm_encoder *encoder,
82 const struct drm_display_mode *mode,
83 struct drm_display_mode *adjusted_mode)
85 return true;
88 static void omap_encoder_mode_set(struct drm_encoder *encoder,
89 struct drm_display_mode *mode,
90 struct drm_display_mode *adjusted_mode)
94 static void omap_encoder_prepare(struct drm_encoder *encoder)
98 static void omap_encoder_commit(struct drm_encoder *encoder)
102 static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = {
103 .dpms = omap_encoder_dpms,
104 .mode_fixup = omap_encoder_mode_fixup,
105 .mode_set = omap_encoder_mode_set,
106 .prepare = omap_encoder_prepare,
107 .commit = omap_encoder_commit,
111 * Instead of relying on the helpers for modeset, the omap_crtc code
112 * calls these functions in the proper sequence.
115 int omap_encoder_set_enabled(struct drm_encoder *encoder, bool enabled)
117 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
118 struct omap_dss_device *dssdev = omap_encoder->dssdev;
119 struct omap_dss_driver *dssdrv = dssdev->driver;
121 if (enabled) {
122 return dssdrv->enable(dssdev);
123 } else {
124 dssdrv->disable(dssdev);
125 return 0;
129 int omap_encoder_update(struct drm_encoder *encoder,
130 struct omap_overlay_manager *mgr,
131 struct omap_video_timings *timings)
133 struct drm_device *dev = encoder->dev;
134 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
135 struct omap_dss_device *dssdev = omap_encoder->dssdev;
136 struct omap_dss_driver *dssdrv = dssdev->driver;
137 int ret;
139 dssdev->src->manager = mgr;
141 if (dssdrv->check_timings) {
142 ret = dssdrv->check_timings(dssdev, timings);
143 } else {
144 struct omap_video_timings t = {0};
146 dssdrv->get_timings(dssdev, &t);
148 if (memcmp(timings, &t, sizeof(struct omap_video_timings)))
149 ret = -EINVAL;
150 else
151 ret = 0;
154 if (ret) {
155 dev_err(dev->dev, "could not set timings: %d\n", ret);
156 return ret;
159 if (dssdrv->set_timings)
160 dssdrv->set_timings(dssdev, timings);
162 return 0;
165 /* initialize encoder */
166 struct drm_encoder *omap_encoder_init(struct drm_device *dev,
167 struct omap_dss_device *dssdev)
169 struct drm_encoder *encoder = NULL;
170 struct omap_encoder *omap_encoder;
172 omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL);
173 if (!omap_encoder)
174 goto fail;
176 omap_encoder->dssdev = dssdev;
178 encoder = &omap_encoder->base;
180 drm_encoder_init(dev, encoder, &omap_encoder_funcs,
181 DRM_MODE_ENCODER_TMDS);
182 drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs);
184 return encoder;
186 fail:
187 if (encoder)
188 omap_encoder_destroy(encoder);
190 return NULL;