2 * drivers/gpu/drm/omapdrm/omap_connector.c
4 * Copyright (C) 2011 Texas Instruments
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
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 <drm/drm_atomic_helper.h>
21 #include <drm/drm_crtc.h>
22 #include <drm/drm_crtc_helper.h>
30 #define to_omap_connector(x) container_of(x, struct omap_connector, base)
32 struct omap_connector {
33 struct drm_connector base;
34 struct omap_dss_device *dssdev;
38 bool omap_connector_get_hdmi_mode(struct drm_connector *connector)
40 struct omap_connector *omap_connector = to_omap_connector(connector);
42 return omap_connector->hdmi_mode;
45 static enum drm_connector_status omap_connector_detect(
46 struct drm_connector *connector, bool force)
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;
54 if (dssdrv->detect(dssdev))
55 ret = connector_status_connected;
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;
64 ret = connector_status_unknown;
67 VERB("%s: %d (force=%d)", omap_connector->dssdev->name, ret, force);
72 static void omap_connector_destroy(struct drm_connector *connector)
74 struct omap_connector *omap_connector = to_omap_connector(connector);
75 struct omap_dss_device *dssdev = omap_connector->dssdev;
77 DBG("%s", omap_connector->dssdev->name);
78 drm_connector_unregister(connector);
79 drm_connector_cleanup(connector);
80 kfree(omap_connector);
82 omap_dss_put_device(dssdev);
87 static int omap_connector_get_modes(struct drm_connector *connector)
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;
95 DBG("%s", omap_connector->dssdev->name);
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:
102 if (dssdrv->read_edid) {
103 void *edid = kzalloc(MAX_EDID, GFP_KERNEL);
105 if ((dssdrv->read_edid(dssdev, edid, MAX_EDID) > 0) &&
106 drm_edid_is_valid(edid)) {
107 drm_mode_connector_update_edid_property(
109 n = drm_add_edid_modes(connector, edid);
111 omap_connector->hdmi_mode =
112 drm_detect_hdmi_monitor(edid);
114 drm_mode_connector_update_edid_property(
120 struct drm_display_mode *mode = drm_mode_create(dev);
121 struct videomode vm = {0};
123 dssdrv->get_timings(dssdev, &vm);
125 drm_display_mode_from_videomode(&vm, mode);
127 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
128 drm_mode_set_name(mode);
129 drm_mode_probed_add(connector, mode);
137 static int omap_connector_mode_valid(struct drm_connector *connector,
138 struct drm_display_mode *mode)
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;
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);
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
158 if (dssdrv->check_timings) {
159 r = dssdrv->check_timings(dssdev, &vm);
161 struct videomode t = {0};
163 dssdrv->get_timings(dssdev, &t);
165 if (memcmp(&vm, &t, sizeof(struct videomode)))
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))
178 drm_mode_destroy(dev, new_mode);
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);
193 static 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,
203 static const struct drm_connector_helper_funcs omap_connector_helper_funcs = {
204 .get_modes = omap_connector_get_modes,
205 .mode_valid = omap_connector_mode_valid,
208 /* initialize connector */
209 struct drm_connector *omap_connector_init(struct drm_device *dev,
210 int connector_type, struct omap_dss_device *dssdev,
211 struct drm_encoder *encoder)
213 struct drm_connector *connector = NULL;
214 struct omap_connector *omap_connector;
216 DBG("%s", dssdev->name);
218 omap_dss_get_device(dssdev);
220 omap_connector = kzalloc(sizeof(struct omap_connector), GFP_KERNEL);
224 omap_connector->dssdev = dssdev;
226 connector = &omap_connector->base;
228 drm_connector_init(dev, connector, &omap_connector_funcs,
230 drm_connector_helper_add(connector, &omap_connector_helper_funcs);
232 #if 0 /* enable when dss2 supports hotplug */
233 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_HPD)
234 connector->polled = 0;
237 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
238 DRM_CONNECTOR_POLL_DISCONNECT;
240 connector->interlace_allowed = 1;
241 connector->doublescan_allowed = 0;
243 drm_connector_register(connector);
249 omap_connector_destroy(connector);