Loading...
1/*
2 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
3 * Author: Rob Clark <rob@ti.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <linux/list.h>
19
20#include <drm/drm_crtc.h>
21#include <drm/drm_crtc_helper.h>
22#include <drm/drm_edid.h>
23
24#include "omap_drv.h"
25
26/*
27 * encoder funcs
28 */
29
30#define to_omap_encoder(x) container_of(x, struct omap_encoder, base)
31
32/* The encoder and connector both map to same dssdev.. the encoder
33 * handles the 'active' parts, ie. anything the modifies the state
34 * of the hw, and the connector handles the 'read-only' parts, like
35 * detecting connection and reading edid.
36 */
37struct omap_encoder {
38 struct drm_encoder base;
39 struct omap_dss_device *dssdev;
40};
41
42struct omap_dss_device *omap_encoder_get_dssdev(struct drm_encoder *encoder)
43{
44 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
45
46 return omap_encoder->dssdev;
47}
48
49static void omap_encoder_destroy(struct drm_encoder *encoder)
50{
51 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
52
53 drm_encoder_cleanup(encoder);
54 kfree(omap_encoder);
55}
56
57static const struct drm_encoder_funcs omap_encoder_funcs = {
58 .destroy = omap_encoder_destroy,
59};
60
61static void omap_encoder_mode_set(struct drm_encoder *encoder,
62 struct drm_display_mode *mode,
63 struct drm_display_mode *adjusted_mode)
64{
65 struct drm_device *dev = encoder->dev;
66 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
67 struct omap_dss_device *dssdev = omap_encoder->dssdev;
68 struct drm_connector *connector;
69 bool hdmi_mode;
70 int r;
71
72 hdmi_mode = false;
73 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
74 if (connector->encoder == encoder) {
75 hdmi_mode = omap_connector_get_hdmi_mode(connector);
76 break;
77 }
78 }
79
80 if (dssdev->driver->set_hdmi_mode)
81 dssdev->driver->set_hdmi_mode(dssdev, hdmi_mode);
82
83 if (hdmi_mode && dssdev->driver->set_hdmi_infoframe) {
84 struct hdmi_avi_infoframe avi;
85
86 r = drm_hdmi_avi_infoframe_from_display_mode(&avi, adjusted_mode,
87 false);
88 if (r == 0)
89 dssdev->driver->set_hdmi_infoframe(dssdev, &avi);
90 }
91}
92
93static void omap_encoder_disable(struct drm_encoder *encoder)
94{
95 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
96 struct omap_dss_device *dssdev = omap_encoder->dssdev;
97 struct omap_dss_driver *dssdrv = dssdev->driver;
98
99 dssdrv->disable(dssdev);
100}
101
102static int omap_encoder_update(struct drm_encoder *encoder,
103 enum omap_channel channel,
104 struct videomode *vm)
105{
106 struct drm_device *dev = encoder->dev;
107 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
108 struct omap_dss_device *dssdev = omap_encoder->dssdev;
109 struct omap_dss_driver *dssdrv = dssdev->driver;
110 int ret;
111
112 if (dssdrv->check_timings) {
113 ret = dssdrv->check_timings(dssdev, vm);
114 } else {
115 struct videomode t = {0};
116
117 dssdrv->get_timings(dssdev, &t);
118
119 if (memcmp(vm, &t, sizeof(*vm)))
120 ret = -EINVAL;
121 else
122 ret = 0;
123 }
124
125 if (ret) {
126 dev_err(dev->dev, "could not set timings: %d\n", ret);
127 return ret;
128 }
129
130 if (dssdrv->set_timings)
131 dssdrv->set_timings(dssdev, vm);
132
133 return 0;
134}
135
136static void omap_encoder_enable(struct drm_encoder *encoder)
137{
138 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
139 struct omap_dss_device *dssdev = omap_encoder->dssdev;
140 struct omap_dss_driver *dssdrv = dssdev->driver;
141 int r;
142
143 omap_encoder_update(encoder, omap_crtc_channel(encoder->crtc),
144 omap_crtc_timings(encoder->crtc));
145
146 r = dssdrv->enable(dssdev);
147 if (r)
148 dev_err(encoder->dev->dev,
149 "Failed to enable display '%s': %d\n",
150 dssdev->name, r);
151}
152
153static int omap_encoder_atomic_check(struct drm_encoder *encoder,
154 struct drm_crtc_state *crtc_state,
155 struct drm_connector_state *conn_state)
156{
157 return 0;
158}
159
160static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = {
161 .mode_set = omap_encoder_mode_set,
162 .disable = omap_encoder_disable,
163 .enable = omap_encoder_enable,
164 .atomic_check = omap_encoder_atomic_check,
165};
166
167/* initialize encoder */
168struct drm_encoder *omap_encoder_init(struct drm_device *dev,
169 struct omap_dss_device *dssdev)
170{
171 struct drm_encoder *encoder = NULL;
172 struct omap_encoder *omap_encoder;
173
174 omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL);
175 if (!omap_encoder)
176 goto fail;
177
178 omap_encoder->dssdev = dssdev;
179
180 encoder = &omap_encoder->base;
181
182 drm_encoder_init(dev, encoder, &omap_encoder_funcs,
183 DRM_MODE_ENCODER_TMDS, NULL);
184 drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs);
185
186 return encoder;
187
188fail:
189 if (encoder)
190 omap_encoder_destroy(encoder);
191
192 return NULL;
193}
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 "omap_drv.h"
21
22#include "drm_crtc.h"
23#include "drm_crtc_helper.h"
24
25#include <linux/list.h>
26
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 */
39struct omap_encoder {
40 struct drm_encoder base;
41 struct omap_dss_device *dssdev;
42};
43
44struct 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
51static 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
61static const struct drm_encoder_funcs omap_encoder_funcs = {
62 .destroy = omap_encoder_destroy,
63};
64
65/*
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.
70 *
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.
75 */
76
77static void omap_encoder_dpms(struct drm_encoder *encoder, int mode)
78{
79}
80
81static bool omap_encoder_mode_fixup(struct drm_encoder *encoder,
82 const struct drm_display_mode *mode,
83 struct drm_display_mode *adjusted_mode)
84{
85 return true;
86}
87
88static void omap_encoder_mode_set(struct drm_encoder *encoder,
89 struct drm_display_mode *mode,
90 struct drm_display_mode *adjusted_mode)
91{
92}
93
94static void omap_encoder_prepare(struct drm_encoder *encoder)
95{
96}
97
98static void omap_encoder_commit(struct drm_encoder *encoder)
99{
100}
101
102static 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,
108};
109
110/*
111 * Instead of relying on the helpers for modeset, the omap_crtc code
112 * calls these functions in the proper sequence.
113 */
114
115int omap_encoder_set_enabled(struct drm_encoder *encoder, bool enabled)
116{
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;
120
121 if (enabled) {
122 return dssdrv->enable(dssdev);
123 } else {
124 dssdrv->disable(dssdev);
125 return 0;
126 }
127}
128
129int omap_encoder_update(struct drm_encoder *encoder,
130 struct omap_overlay_manager *mgr,
131 struct omap_video_timings *timings)
132{
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;
138
139 dssdev->src->manager = mgr;
140
141 if (dssdrv->check_timings) {
142 ret = dssdrv->check_timings(dssdev, timings);
143 } else {
144 struct omap_video_timings t = {0};
145
146 dssdrv->get_timings(dssdev, &t);
147
148 if (memcmp(timings, &t, sizeof(struct omap_video_timings)))
149 ret = -EINVAL;
150 else
151 ret = 0;
152 }
153
154 if (ret) {
155 dev_err(dev->dev, "could not set timings: %d\n", ret);
156 return ret;
157 }
158
159 if (dssdrv->set_timings)
160 dssdrv->set_timings(dssdev, timings);
161
162 return 0;
163}
164
165/* initialize encoder */
166struct drm_encoder *omap_encoder_init(struct drm_device *dev,
167 struct omap_dss_device *dssdev)
168{
169 struct drm_encoder *encoder = NULL;
170 struct omap_encoder *omap_encoder;
171
172 omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL);
173 if (!omap_encoder)
174 goto fail;
175
176 omap_encoder->dssdev = dssdev;
177
178 encoder = &omap_encoder->base;
179
180 drm_encoder_init(dev, encoder, &omap_encoder_funcs,
181 DRM_MODE_ENCODER_TMDS);
182 drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs);
183
184 return encoder;
185
186fail:
187 if (encoder)
188 omap_encoder_destroy(encoder);
189
190 return NULL;
191}