2 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
3 * Author: Rob Clark <rob@ti.com>
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.
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
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/>.
18 #include <drm/drm_atomic_helper.h>
19 #include <drm/drm_crtc.h>
20 #include <drm/drm_crtc_helper.h>
28 #define to_omap_connector(x) container_of(x, struct omap_connector, base)
30 struct omap_connector
{
31 struct drm_connector base
;
32 struct omap_dss_device
*dssdev
;
36 static void omap_connector_hpd_cb(void *cb_data
,
37 enum drm_connector_status status
)
39 struct omap_connector
*omap_connector
= cb_data
;
40 struct drm_connector
*connector
= &omap_connector
->base
;
41 struct drm_device
*dev
= connector
->dev
;
42 enum drm_connector_status old_status
;
44 mutex_lock(&dev
->mode_config
.mutex
);
45 old_status
= connector
->status
;
46 connector
->status
= status
;
47 mutex_unlock(&dev
->mode_config
.mutex
);
49 if (old_status
!= status
)
50 drm_kms_helper_hotplug_event(dev
);
53 bool omap_connector_get_hdmi_mode(struct drm_connector
*connector
)
55 struct omap_connector
*omap_connector
= to_omap_connector(connector
);
57 return omap_connector
->hdmi_mode
;
60 static enum drm_connector_status
omap_connector_detect(
61 struct drm_connector
*connector
, bool force
)
63 struct omap_connector
*omap_connector
= to_omap_connector(connector
);
64 struct omap_dss_device
*dssdev
= omap_connector
->dssdev
;
65 struct omap_dss_driver
*dssdrv
= dssdev
->driver
;
66 enum drm_connector_status ret
;
69 if (dssdrv
->detect(dssdev
))
70 ret
= connector_status_connected
;
72 ret
= connector_status_disconnected
;
73 } else if (dssdev
->type
== OMAP_DISPLAY_TYPE_DPI
||
74 dssdev
->type
== OMAP_DISPLAY_TYPE_DBI
||
75 dssdev
->type
== OMAP_DISPLAY_TYPE_SDI
||
76 dssdev
->type
== OMAP_DISPLAY_TYPE_DSI
) {
77 ret
= connector_status_connected
;
79 ret
= connector_status_unknown
;
82 VERB("%s: %d (force=%d)", omap_connector
->dssdev
->name
, ret
, force
);
87 static void omap_connector_destroy(struct drm_connector
*connector
)
89 struct omap_connector
*omap_connector
= to_omap_connector(connector
);
90 struct omap_dss_device
*dssdev
= omap_connector
->dssdev
;
92 DBG("%s", omap_connector
->dssdev
->name
);
93 if (connector
->polled
== DRM_CONNECTOR_POLL_HPD
&&
94 dssdev
->driver
->unregister_hpd_cb
) {
95 dssdev
->driver
->unregister_hpd_cb(dssdev
);
97 drm_connector_unregister(connector
);
98 drm_connector_cleanup(connector
);
99 kfree(omap_connector
);
101 omap_dss_put_device(dssdev
);
106 static int omap_connector_get_modes(struct drm_connector
*connector
)
108 struct omap_connector
*omap_connector
= to_omap_connector(connector
);
109 struct omap_dss_device
*dssdev
= omap_connector
->dssdev
;
110 struct omap_dss_driver
*dssdrv
= dssdev
->driver
;
111 struct drm_device
*dev
= connector
->dev
;
114 DBG("%s", omap_connector
->dssdev
->name
);
116 /* if display exposes EDID, then we parse that in the normal way to
117 * build table of supported modes.. otherwise (ie. fixed resolution
118 * LCD panels) we just return a single mode corresponding to the
119 * currently configured timings:
121 if (dssdrv
->read_edid
) {
122 void *edid
= kzalloc(MAX_EDID
, GFP_KERNEL
);
124 if ((dssdrv
->read_edid(dssdev
, edid
, MAX_EDID
) > 0) &&
125 drm_edid_is_valid(edid
)) {
126 drm_mode_connector_update_edid_property(
128 n
= drm_add_edid_modes(connector
, edid
);
130 omap_connector
->hdmi_mode
=
131 drm_detect_hdmi_monitor(edid
);
133 drm_mode_connector_update_edid_property(
139 struct drm_display_mode
*mode
= drm_mode_create(dev
);
140 struct videomode vm
= {0};
142 dssdrv
->get_timings(dssdev
, &vm
);
144 drm_display_mode_from_videomode(&vm
, mode
);
146 mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
147 drm_mode_set_name(mode
);
148 drm_mode_probed_add(connector
, mode
);
150 if (dssdrv
->get_size
) {
151 dssdrv
->get_size(dssdev
,
152 &connector
->display_info
.width_mm
,
153 &connector
->display_info
.height_mm
);
162 static int omap_connector_mode_valid(struct drm_connector
*connector
,
163 struct drm_display_mode
*mode
)
165 struct omap_connector
*omap_connector
= to_omap_connector(connector
);
166 struct omap_dss_device
*dssdev
= omap_connector
->dssdev
;
167 struct omap_dss_driver
*dssdrv
= dssdev
->driver
;
168 struct videomode vm
= {0};
169 struct drm_device
*dev
= connector
->dev
;
170 struct drm_display_mode
*new_mode
;
171 int r
, ret
= MODE_BAD
;
173 drm_display_mode_to_videomode(mode
, &vm
);
174 mode
->vrefresh
= drm_mode_vrefresh(mode
);
177 * if the panel driver doesn't have a check_timings, it's most likely
178 * a fixed resolution panel, check if the timings match with the
181 if (dssdrv
->check_timings
) {
182 r
= dssdrv
->check_timings(dssdev
, &vm
);
184 struct videomode t
= {0};
186 dssdrv
->get_timings(dssdev
, &t
);
189 * Ignore the flags, as we don't get them from
190 * drm_display_mode_to_videomode.
194 if (memcmp(&vm
, &t
, sizeof(vm
)))
201 /* check if vrefresh is still valid */
202 new_mode
= drm_mode_duplicate(dev
, mode
);
203 new_mode
->clock
= vm
.pixelclock
/ 1000;
204 new_mode
->vrefresh
= 0;
205 if (mode
->vrefresh
== drm_mode_vrefresh(new_mode
))
207 drm_mode_destroy(dev
, new_mode
);
210 DBG("connector: mode %s: "
211 "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
212 (ret
== MODE_OK
) ? "valid" : "invalid",
213 mode
->base
.id
, mode
->name
, mode
->vrefresh
, mode
->clock
,
214 mode
->hdisplay
, mode
->hsync_start
,
215 mode
->hsync_end
, mode
->htotal
,
216 mode
->vdisplay
, mode
->vsync_start
,
217 mode
->vsync_end
, mode
->vtotal
, mode
->type
, mode
->flags
);
222 static const struct drm_connector_funcs omap_connector_funcs
= {
223 .reset
= drm_atomic_helper_connector_reset
,
224 .detect
= omap_connector_detect
,
225 .fill_modes
= drm_helper_probe_single_connector_modes
,
226 .destroy
= omap_connector_destroy
,
227 .atomic_duplicate_state
= drm_atomic_helper_connector_duplicate_state
,
228 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
231 static const struct drm_connector_helper_funcs omap_connector_helper_funcs
= {
232 .get_modes
= omap_connector_get_modes
,
233 .mode_valid
= omap_connector_mode_valid
,
236 /* initialize connector */
237 struct drm_connector
*omap_connector_init(struct drm_device
*dev
,
238 int connector_type
, struct omap_dss_device
*dssdev
,
239 struct drm_encoder
*encoder
)
241 struct drm_connector
*connector
= NULL
;
242 struct omap_connector
*omap_connector
;
243 bool hpd_supported
= false;
245 DBG("%s", dssdev
->name
);
247 omap_dss_get_device(dssdev
);
249 omap_connector
= kzalloc(sizeof(*omap_connector
), GFP_KERNEL
);
253 omap_connector
->dssdev
= dssdev
;
255 connector
= &omap_connector
->base
;
257 drm_connector_init(dev
, connector
, &omap_connector_funcs
,
259 drm_connector_helper_add(connector
, &omap_connector_helper_funcs
);
261 if (dssdev
->driver
->register_hpd_cb
) {
262 int ret
= dssdev
->driver
->register_hpd_cb(dssdev
,
263 omap_connector_hpd_cb
,
266 hpd_supported
= true;
267 else if (ret
!= -ENOTSUPP
)
268 DBG("%s: Failed to register HPD callback (%d).",
273 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
274 else if (dssdev
->driver
->detect
)
275 connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
|
276 DRM_CONNECTOR_POLL_DISCONNECT
;
278 connector
->polled
= 0;
280 connector
->interlace_allowed
= 1;
281 connector
->doublescan_allowed
= 0;
287 omap_connector_destroy(connector
);