Loading...
Note: File does not exist in v3.1.
1/*
2 * drivers/gpu/drm/omapdrm/omap_connector.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 <drm/drm_atomic_helper.h>
21#include <drm/drm_crtc.h>
22#include <drm/drm_crtc_helper.h>
23
24#include "omap_drv.h"
25
26/*
27 * connector funcs
28 */
29
30#define to_omap_connector(x) container_of(x, struct omap_connector, base)
31
32struct omap_connector {
33 struct drm_connector base;
34 struct omap_dss_device *dssdev;
35 bool hdmi_mode;
36};
37
38bool omap_connector_get_hdmi_mode(struct drm_connector *connector)
39{
40 struct omap_connector *omap_connector = to_omap_connector(connector);
41
42 return omap_connector->hdmi_mode;
43}
44
45static enum drm_connector_status omap_connector_detect(
46 struct drm_connector *connector, bool force)
47{
48 struct omap_connector *omap_connector = to_omap_connector(connector);
49 struct omap_dss_device *dssdev = omap_connector->dssdev;
50 struct omap_dss_driver *dssdrv = dssdev->driver;
51 enum drm_connector_status ret;
52
53 if (dssdrv->detect) {
54 if (dssdrv->detect(dssdev))
55 ret = connector_status_connected;
56 else
57 ret = connector_status_disconnected;
58 } else if (dssdev->type == OMAP_DISPLAY_TYPE_DPI ||
59 dssdev->type == OMAP_DISPLAY_TYPE_DBI ||
60 dssdev->type == OMAP_DISPLAY_TYPE_SDI ||
61 dssdev->type == OMAP_DISPLAY_TYPE_DSI) {
62 ret = connector_status_connected;
63 } else {
64 ret = connector_status_unknown;
65 }
66
67 VERB("%s: %d (force=%d)", omap_connector->dssdev->name, ret, force);
68
69 return ret;
70}
71
72static void omap_connector_destroy(struct drm_connector *connector)
73{
74 struct omap_connector *omap_connector = to_omap_connector(connector);
75 struct omap_dss_device *dssdev = omap_connector->dssdev;
76
77 DBG("%s", omap_connector->dssdev->name);
78 drm_connector_unregister(connector);
79 drm_connector_cleanup(connector);
80 kfree(omap_connector);
81
82 omap_dss_put_device(dssdev);
83}
84
85#define MAX_EDID 512
86
87static int omap_connector_get_modes(struct drm_connector *connector)
88{
89 struct omap_connector *omap_connector = to_omap_connector(connector);
90 struct omap_dss_device *dssdev = omap_connector->dssdev;
91 struct omap_dss_driver *dssdrv = dssdev->driver;
92 struct drm_device *dev = connector->dev;
93 int n = 0;
94
95 DBG("%s", omap_connector->dssdev->name);
96
97 /* if display exposes EDID, then we parse that in the normal way to
98 * build table of supported modes.. otherwise (ie. fixed resolution
99 * LCD panels) we just return a single mode corresponding to the
100 * currently configured timings:
101 */
102 if (dssdrv->read_edid) {
103 void *edid = kzalloc(MAX_EDID, GFP_KERNEL);
104
105 if ((dssdrv->read_edid(dssdev, edid, MAX_EDID) > 0) &&
106 drm_edid_is_valid(edid)) {
107 drm_mode_connector_update_edid_property(
108 connector, edid);
109 n = drm_add_edid_modes(connector, edid);
110
111 omap_connector->hdmi_mode =
112 drm_detect_hdmi_monitor(edid);
113 } else {
114 drm_mode_connector_update_edid_property(
115 connector, NULL);
116 }
117
118 kfree(edid);
119 } else {
120 struct drm_display_mode *mode = drm_mode_create(dev);
121 struct videomode vm = {0};
122
123 dssdrv->get_timings(dssdev, &vm);
124
125 drm_display_mode_from_videomode(&vm, mode);
126
127 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
128 drm_mode_set_name(mode);
129 drm_mode_probed_add(connector, mode);
130
131 n = 1;
132 }
133
134 return n;
135}
136
137static int omap_connector_mode_valid(struct drm_connector *connector,
138 struct drm_display_mode *mode)
139{
140 struct omap_connector *omap_connector = to_omap_connector(connector);
141 struct omap_dss_device *dssdev = omap_connector->dssdev;
142 struct omap_dss_driver *dssdrv = dssdev->driver;
143 struct videomode vm = {0};
144 struct drm_device *dev = connector->dev;
145 struct drm_display_mode *new_mode;
146 int r, ret = MODE_BAD;
147
148 drm_display_mode_to_videomode(mode, &vm);
149 vm.flags |= DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_PIXDATA_POSEDGE |
150 DISPLAY_FLAGS_SYNC_NEGEDGE;
151 mode->vrefresh = drm_mode_vrefresh(mode);
152
153 /*
154 * if the panel driver doesn't have a check_timings, it's most likely
155 * a fixed resolution panel, check if the timings match with the
156 * panel's timings
157 */
158 if (dssdrv->check_timings) {
159 r = dssdrv->check_timings(dssdev, &vm);
160 } else {
161 struct videomode t = {0};
162
163 dssdrv->get_timings(dssdev, &t);
164
165 if (memcmp(&vm, &t, sizeof(struct videomode)))
166 r = -EINVAL;
167 else
168 r = 0;
169 }
170
171 if (!r) {
172 /* check if vrefresh is still valid */
173 new_mode = drm_mode_duplicate(dev, mode);
174 new_mode->clock = vm.pixelclock / 1000;
175 new_mode->vrefresh = 0;
176 if (mode->vrefresh == drm_mode_vrefresh(new_mode))
177 ret = MODE_OK;
178 drm_mode_destroy(dev, new_mode);
179 }
180
181 DBG("connector: mode %s: "
182 "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
183 (ret == MODE_OK) ? "valid" : "invalid",
184 mode->base.id, mode->name, mode->vrefresh, mode->clock,
185 mode->hdisplay, mode->hsync_start,
186 mode->hsync_end, mode->htotal,
187 mode->vdisplay, mode->vsync_start,
188 mode->vsync_end, mode->vtotal, mode->type, mode->flags);
189
190 return ret;
191}
192
193static const struct drm_connector_funcs omap_connector_funcs = {
194 .dpms = drm_atomic_helper_connector_dpms,
195 .reset = drm_atomic_helper_connector_reset,
196 .detect = omap_connector_detect,
197 .fill_modes = drm_helper_probe_single_connector_modes,
198 .destroy = omap_connector_destroy,
199 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
200 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
201};
202
203static const struct drm_connector_helper_funcs omap_connector_helper_funcs = {
204 .get_modes = omap_connector_get_modes,
205 .mode_valid = omap_connector_mode_valid,
206};
207
208/* initialize connector */
209struct drm_connector *omap_connector_init(struct drm_device *dev,
210 int connector_type, struct omap_dss_device *dssdev,
211 struct drm_encoder *encoder)
212{
213 struct drm_connector *connector = NULL;
214 struct omap_connector *omap_connector;
215
216 DBG("%s", dssdev->name);
217
218 omap_dss_get_device(dssdev);
219
220 omap_connector = kzalloc(sizeof(struct omap_connector), GFP_KERNEL);
221 if (!omap_connector)
222 goto fail;
223
224 omap_connector->dssdev = dssdev;
225
226 connector = &omap_connector->base;
227
228 drm_connector_init(dev, connector, &omap_connector_funcs,
229 connector_type);
230 drm_connector_helper_add(connector, &omap_connector_helper_funcs);
231
232#if 0 /* enable when dss2 supports hotplug */
233 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_HPD)
234 connector->polled = 0;
235 else
236#endif
237 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
238 DRM_CONNECTOR_POLL_DISCONNECT;
239
240 connector->interlace_allowed = 1;
241 connector->doublescan_allowed = 0;
242
243 drm_connector_register(connector);
244
245 return connector;
246
247fail:
248 if (connector)
249 omap_connector_destroy(connector);
250
251 return NULL;
252}