]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/omapdrm/omap_encoder.c
drm: omapdrm: Make the omap_crtc_flush function static
[karo-tx-linux.git] / drivers / gpu / drm / omapdrm / omap_encoder.c
1 /*
2  * drivers/gpu/drm/omapdrm/omap_encoder.c
3  *
4  * Copyright (C) 2011 Texas Instruments
5  * Author: Rob Clark <rob@ti.com>
6  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #include <linux/list.h>
21
22 #include <drm/drm_crtc.h>
23 #include <drm/drm_crtc_helper.h>
24 #include <drm/drm_edid.h>
25
26 #include "omap_drv.h"
27
28 /*
29  * encoder funcs
30  */
31
32 #define to_omap_encoder(x) container_of(x, struct omap_encoder, base)
33
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.
38  */
39 struct omap_encoder {
40         struct drm_encoder base;
41         struct omap_dss_device *dssdev;
42 };
43
44 struct omap_dss_device *omap_encoder_get_dssdev(struct drm_encoder *encoder)
45 {
46         struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
47
48         return omap_encoder->dssdev;
49 }
50
51 static void omap_encoder_destroy(struct drm_encoder *encoder)
52 {
53         struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
54
55         omap_encoder_set_enabled(encoder, false);
56
57         drm_encoder_cleanup(encoder);
58         kfree(omap_encoder);
59 }
60
61 static const struct drm_encoder_funcs omap_encoder_funcs = {
62         .destroy = omap_encoder_destroy,
63 };
64
65 static void omap_encoder_mode_set(struct drm_encoder *encoder,
66                                 struct drm_display_mode *mode,
67                                 struct drm_display_mode *adjusted_mode)
68 {
69         struct drm_device *dev = encoder->dev;
70         struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
71         struct omap_dss_device *dssdev = omap_encoder->dssdev;
72         struct drm_connector *connector;
73         bool hdmi_mode;
74         int r;
75
76         hdmi_mode = false;
77         list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
78                 if (connector->encoder == encoder) {
79                         hdmi_mode = omap_connector_get_hdmi_mode(connector);
80                         break;
81                 }
82         }
83
84         if (dssdev->driver->set_hdmi_mode)
85                 dssdev->driver->set_hdmi_mode(dssdev, hdmi_mode);
86
87         if (hdmi_mode && dssdev->driver->set_hdmi_infoframe) {
88                 struct hdmi_avi_infoframe avi;
89
90                 r = drm_hdmi_avi_infoframe_from_display_mode(&avi, adjusted_mode);
91                 if (r == 0)
92                         dssdev->driver->set_hdmi_infoframe(dssdev, &avi);
93         }
94 }
95
96 /*
97  * The CRTC drm_crtc_helper_set_mode() didn't really give us the right order.
98  * The easiest way to work around this was to make all the encoder-helper's
99  * no-op's and have the omap_crtc code take care of the sequencing and call
100  * us in the right points.
101  *
102  * FIXME: Revisit this after switching to atomic updates completely.
103  */
104
105 static void omap_encoder_disable(struct drm_encoder *encoder)
106 {
107 }
108
109 static void omap_encoder_enable(struct drm_encoder *encoder)
110 {
111 }
112
113 static int omap_encoder_atomic_check(struct drm_encoder *encoder,
114                                      struct drm_crtc_state *crtc_state,
115                                      struct drm_connector_state *conn_state)
116 {
117         return 0;
118 }
119
120 static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = {
121         .mode_set = omap_encoder_mode_set,
122         .disable = omap_encoder_disable,
123         .enable = omap_encoder_enable,
124         .atomic_check = omap_encoder_atomic_check,
125 };
126
127 /*
128  * Instead of relying on the helpers for modeset, the omap_crtc code
129  * calls these functions in the proper sequence.
130  */
131
132 int omap_encoder_set_enabled(struct drm_encoder *encoder, bool enabled)
133 {
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
138         if (enabled) {
139                 return dssdrv->enable(dssdev);
140         } else {
141                 dssdrv->disable(dssdev);
142                 return 0;
143         }
144 }
145
146 int omap_encoder_update(struct drm_encoder *encoder,
147                 struct omap_overlay_manager *mgr,
148                 struct omap_video_timings *timings)
149 {
150         struct drm_device *dev = encoder->dev;
151         struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
152         struct omap_dss_device *dssdev = omap_encoder->dssdev;
153         struct omap_dss_driver *dssdrv = dssdev->driver;
154         int ret;
155
156         dssdev->src->manager = mgr;
157
158         if (dssdrv->check_timings) {
159                 ret = dssdrv->check_timings(dssdev, timings);
160         } else {
161                 struct omap_video_timings t = {0};
162
163                 dssdrv->get_timings(dssdev, &t);
164
165                 if (memcmp(timings, &t, sizeof(struct omap_video_timings)))
166                         ret = -EINVAL;
167                 else
168                         ret = 0;
169         }
170
171         if (ret) {
172                 dev_err(dev->dev, "could not set timings: %d\n", ret);
173                 return ret;
174         }
175
176         if (dssdrv->set_timings)
177                 dssdrv->set_timings(dssdev, timings);
178
179         return 0;
180 }
181
182 /* initialize encoder */
183 struct drm_encoder *omap_encoder_init(struct drm_device *dev,
184                 struct omap_dss_device *dssdev)
185 {
186         struct drm_encoder *encoder = NULL;
187         struct omap_encoder *omap_encoder;
188
189         omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL);
190         if (!omap_encoder)
191                 goto fail;
192
193         omap_encoder->dssdev = dssdev;
194
195         encoder = &omap_encoder->base;
196
197         drm_encoder_init(dev, encoder, &omap_encoder_funcs,
198                          DRM_MODE_ENCODER_TMDS);
199         drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs);
200
201         return encoder;
202
203 fail:
204         if (encoder)
205                 omap_encoder_destroy(encoder);
206
207         return NULL;
208 }