xref: /openbmc/linux/drivers/gpu/drm/gma500/cdv_intel_hdmi.c (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
16a227d5fSAlan Cox /*
26a227d5fSAlan Cox  * Copyright © 2006-2011 Intel Corporation
36a227d5fSAlan Cox  *
46a227d5fSAlan Cox  * Permission is hereby granted, free of charge, to any person obtaining a
56a227d5fSAlan Cox  * copy of this software and associated documentation files (the "Software"),
66a227d5fSAlan Cox  * to deal in the Software without restriction, including without limitation
76a227d5fSAlan Cox  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
86a227d5fSAlan Cox  * and/or sell copies of the Software, and to permit persons to whom the
96a227d5fSAlan Cox  * Software is furnished to do so, subject to the following conditions:
106a227d5fSAlan Cox  *
116a227d5fSAlan Cox  * The above copyright notice and this permission notice (including the next
126a227d5fSAlan Cox  * paragraph) shall be included in all copies or substantial portions of the
136a227d5fSAlan Cox  * Software.
146a227d5fSAlan Cox  *
156a227d5fSAlan Cox  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
166a227d5fSAlan Cox  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
176a227d5fSAlan Cox  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
186a227d5fSAlan Cox  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
196a227d5fSAlan Cox  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
206a227d5fSAlan Cox  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
216a227d5fSAlan Cox  * DEALINGS IN THE SOFTWARE.
226a227d5fSAlan Cox  *
236a227d5fSAlan Cox  * Authors:
246a227d5fSAlan Cox  *	jim liu <jim.liu@intel.com>
256a227d5fSAlan Cox  */
266a227d5fSAlan Cox 
270c7b178aSSam Ravnborg #include <linux/pm_runtime.h>
280c7b178aSSam Ravnborg 
296a227d5fSAlan Cox #include <drm/drm.h>
306a227d5fSAlan Cox #include <drm/drm_crtc.h>
31*3599dfa1SThomas Zimmermann #include <drm/drm_crtc_helper.h>
326a227d5fSAlan Cox #include <drm/drm_edid.h>
33*3599dfa1SThomas Zimmermann #include <drm/drm_modeset_helper_vtables.h>
34d088b69fSThomas Zimmermann #include <drm/drm_simple_kms_helper.h>
350c7b178aSSam Ravnborg 
36455b9e91SKirill A. Shutemov #include "cdv_device.h"
370c7b178aSSam Ravnborg #include "psb_drv.h"
380c7b178aSSam Ravnborg #include "psb_intel_drv.h"
390c7b178aSSam Ravnborg #include "psb_intel_reg.h"
406a227d5fSAlan Cox 
416a227d5fSAlan Cox /* hdmi control bits */
426a227d5fSAlan Cox #define HDMI_NULL_PACKETS_DURING_VSYNC	(1 << 9)
436a227d5fSAlan Cox #define HDMI_BORDER_ENABLE		(1 << 7)
446a227d5fSAlan Cox #define HDMI_AUDIO_ENABLE		(1 << 6)
456a227d5fSAlan Cox #define HDMI_VSYNC_ACTIVE_HIGH		(1 << 4)
466a227d5fSAlan Cox #define HDMI_HSYNC_ACTIVE_HIGH		(1 << 3)
476a227d5fSAlan Cox /* hdmi-b control bits */
486a227d5fSAlan Cox #define	HDMIB_PIPE_B_SELECT		(1 << 30)
496a227d5fSAlan Cox 
506a227d5fSAlan Cox 
516a227d5fSAlan Cox struct mid_intel_hdmi_priv {
526a227d5fSAlan Cox 	u32 hdmi_reg;
536a227d5fSAlan Cox 	u32 save_HDMIB;
546a227d5fSAlan Cox 	bool has_hdmi_sink;
556a227d5fSAlan Cox 	bool has_hdmi_audio;
566a227d5fSAlan Cox 	/* Should set this when detect hotplug */
576a227d5fSAlan Cox 	bool hdmi_device_connected;
586a227d5fSAlan Cox 	struct drm_device *dev;
596a227d5fSAlan Cox };
606a227d5fSAlan Cox 
cdv_hdmi_mode_set(struct drm_encoder * encoder,struct drm_display_mode * mode,struct drm_display_mode * adjusted_mode)616a227d5fSAlan Cox static void cdv_hdmi_mode_set(struct drm_encoder *encoder,
626a227d5fSAlan Cox 			struct drm_display_mode *mode,
636a227d5fSAlan Cox 			struct drm_display_mode *adjusted_mode)
646a227d5fSAlan Cox {
656a227d5fSAlan Cox 	struct drm_device *dev = encoder->dev;
66367e4408SPatrik Jakobsson 	struct gma_encoder *gma_encoder = to_gma_encoder(encoder);
67367e4408SPatrik Jakobsson 	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
686a227d5fSAlan Cox 	u32 hdmib;
696a227d5fSAlan Cox 	struct drm_crtc *crtc = encoder->crtc;
706306865dSPatrik Jakobsson 	struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
716a227d5fSAlan Cox 
726a227d5fSAlan Cox 	hdmib = (2 << 10);
736a227d5fSAlan Cox 
746a227d5fSAlan Cox 	if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
756a227d5fSAlan Cox 		hdmib |= HDMI_VSYNC_ACTIVE_HIGH;
766a227d5fSAlan Cox 	if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
776a227d5fSAlan Cox 		hdmib |= HDMI_HSYNC_ACTIVE_HIGH;
786a227d5fSAlan Cox 
796306865dSPatrik Jakobsson 	if (gma_crtc->pipe == 1)
806a227d5fSAlan Cox 		hdmib |= HDMIB_PIPE_B_SELECT;
816a227d5fSAlan Cox 
826a227d5fSAlan Cox 	if (hdmi_priv->has_hdmi_audio) {
836a227d5fSAlan Cox 		hdmib |= HDMI_AUDIO_ENABLE;
846a227d5fSAlan Cox 		hdmib |= HDMI_NULL_PACKETS_DURING_VSYNC;
856a227d5fSAlan Cox 	}
866a227d5fSAlan Cox 
876a227d5fSAlan Cox 	REG_WRITE(hdmi_priv->hdmi_reg, hdmib);
886a227d5fSAlan Cox 	REG_READ(hdmi_priv->hdmi_reg);
896a227d5fSAlan Cox }
906a227d5fSAlan Cox 
cdv_hdmi_dpms(struct drm_encoder * encoder,int mode)916a227d5fSAlan Cox static void cdv_hdmi_dpms(struct drm_encoder *encoder, int mode)
926a227d5fSAlan Cox {
936a227d5fSAlan Cox 	struct drm_device *dev = encoder->dev;
94367e4408SPatrik Jakobsson 	struct gma_encoder *gma_encoder = to_gma_encoder(encoder);
95367e4408SPatrik Jakobsson 	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
966a227d5fSAlan Cox 	u32 hdmib;
976a227d5fSAlan Cox 
986a227d5fSAlan Cox 	hdmib = REG_READ(hdmi_priv->hdmi_reg);
996a227d5fSAlan Cox 
1006a227d5fSAlan Cox 	if (mode != DRM_MODE_DPMS_ON)
1016a227d5fSAlan Cox 		REG_WRITE(hdmi_priv->hdmi_reg, hdmib & ~HDMIB_PORT_EN);
1026a227d5fSAlan Cox 	else
1036a227d5fSAlan Cox 		REG_WRITE(hdmi_priv->hdmi_reg, hdmib | HDMIB_PORT_EN);
1046a227d5fSAlan Cox 	REG_READ(hdmi_priv->hdmi_reg);
1056a227d5fSAlan Cox }
1066a227d5fSAlan Cox 
cdv_hdmi_save(struct drm_connector * connector)1076a227d5fSAlan Cox static void cdv_hdmi_save(struct drm_connector *connector)
1086a227d5fSAlan Cox {
1096a227d5fSAlan Cox 	struct drm_device *dev = connector->dev;
110367e4408SPatrik Jakobsson 	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
111367e4408SPatrik Jakobsson 	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
1126a227d5fSAlan Cox 
1136a227d5fSAlan Cox 	hdmi_priv->save_HDMIB = REG_READ(hdmi_priv->hdmi_reg);
1146a227d5fSAlan Cox }
1156a227d5fSAlan Cox 
cdv_hdmi_restore(struct drm_connector * connector)1166a227d5fSAlan Cox static void cdv_hdmi_restore(struct drm_connector *connector)
1176a227d5fSAlan Cox {
1186a227d5fSAlan Cox 	struct drm_device *dev = connector->dev;
119367e4408SPatrik Jakobsson 	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
120367e4408SPatrik Jakobsson 	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
1216a227d5fSAlan Cox 
1226a227d5fSAlan Cox 	REG_WRITE(hdmi_priv->hdmi_reg, hdmi_priv->save_HDMIB);
1236a227d5fSAlan Cox 	REG_READ(hdmi_priv->hdmi_reg);
1246a227d5fSAlan Cox }
1256a227d5fSAlan Cox 
cdv_hdmi_detect(struct drm_connector * connector,bool force)1266a227d5fSAlan Cox static enum drm_connector_status cdv_hdmi_detect(
1276a227d5fSAlan Cox 				struct drm_connector *connector, bool force)
1286a227d5fSAlan Cox {
129367e4408SPatrik Jakobsson 	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
130367e4408SPatrik Jakobsson 	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
1316a227d5fSAlan Cox 	struct edid *edid = NULL;
1326a227d5fSAlan Cox 	enum drm_connector_status status = connector_status_disconnected;
1336a227d5fSAlan Cox 
134544ef140SPatrik Jakobsson 	edid = drm_get_edid(connector, connector->ddc);
1356a227d5fSAlan Cox 
1366a227d5fSAlan Cox 	hdmi_priv->has_hdmi_sink = false;
1376a227d5fSAlan Cox 	hdmi_priv->has_hdmi_audio = false;
1386a227d5fSAlan Cox 	if (edid) {
1396a227d5fSAlan Cox 		if (edid->input & DRM_EDID_INPUT_DIGITAL) {
1406a227d5fSAlan Cox 			status = connector_status_connected;
1416a227d5fSAlan Cox 			hdmi_priv->has_hdmi_sink =
1426a227d5fSAlan Cox 						drm_detect_hdmi_monitor(edid);
1436a227d5fSAlan Cox 			hdmi_priv->has_hdmi_audio =
1446a227d5fSAlan Cox 						drm_detect_monitor_audio(edid);
1456a227d5fSAlan Cox 		}
1466a227d5fSAlan Cox 		kfree(edid);
1476a227d5fSAlan Cox 	}
1486a227d5fSAlan Cox 	return status;
1496a227d5fSAlan Cox }
1506a227d5fSAlan Cox 
cdv_hdmi_set_property(struct drm_connector * connector,struct drm_property * property,uint64_t value)1516a227d5fSAlan Cox static int cdv_hdmi_set_property(struct drm_connector *connector,
1526a227d5fSAlan Cox 				       struct drm_property *property,
1536a227d5fSAlan Cox 				       uint64_t value)
1546a227d5fSAlan Cox {
1556a227d5fSAlan Cox 	struct drm_encoder *encoder = connector->encoder;
1566a227d5fSAlan Cox 
1576a227d5fSAlan Cox 	if (!strcmp(property->name, "scaling mode") && encoder) {
1586306865dSPatrik Jakobsson 		struct gma_crtc *crtc = to_gma_crtc(encoder->crtc);
1596a227d5fSAlan Cox 		bool centre;
1606a227d5fSAlan Cox 		uint64_t curValue;
1616a227d5fSAlan Cox 
1626a227d5fSAlan Cox 		if (!crtc)
1636a227d5fSAlan Cox 			return -1;
1646a227d5fSAlan Cox 
1656a227d5fSAlan Cox 		switch (value) {
1666a227d5fSAlan Cox 		case DRM_MODE_SCALE_FULLSCREEN:
1676a227d5fSAlan Cox 			break;
1686a227d5fSAlan Cox 		case DRM_MODE_SCALE_NO_SCALE:
1696a227d5fSAlan Cox 			break;
1706a227d5fSAlan Cox 		case DRM_MODE_SCALE_ASPECT:
1716a227d5fSAlan Cox 			break;
1726a227d5fSAlan Cox 		default:
1736a227d5fSAlan Cox 			return -1;
1746a227d5fSAlan Cox 		}
1756a227d5fSAlan Cox 
176a69ac9eaSRob Clark 		if (drm_object_property_get_value(&connector->base,
1776a227d5fSAlan Cox 							property, &curValue))
1786a227d5fSAlan Cox 			return -1;
1796a227d5fSAlan Cox 
1806a227d5fSAlan Cox 		if (curValue == value)
1816a227d5fSAlan Cox 			return 0;
1826a227d5fSAlan Cox 
183a69ac9eaSRob Clark 		if (drm_object_property_set_value(&connector->base,
1846a227d5fSAlan Cox 							property, value))
1856a227d5fSAlan Cox 			return -1;
1866a227d5fSAlan Cox 
1876a227d5fSAlan Cox 		centre = (curValue == DRM_MODE_SCALE_NO_SCALE) ||
1886a227d5fSAlan Cox 			(value == DRM_MODE_SCALE_NO_SCALE);
1896a227d5fSAlan Cox 
1906a227d5fSAlan Cox 		if (crtc->saved_mode.hdisplay != 0 &&
1916a227d5fSAlan Cox 		    crtc->saved_mode.vdisplay != 0) {
1926a227d5fSAlan Cox 			if (centre) {
1936a227d5fSAlan Cox 				if (!drm_crtc_helper_set_mode(encoder->crtc, &crtc->saved_mode,
194f4510a27SMatt Roper 					    encoder->crtc->x, encoder->crtc->y, encoder->crtc->primary->fb))
1956a227d5fSAlan Cox 					return -1;
1966a227d5fSAlan Cox 			} else {
19745fe734cSJani Nikula 				const struct drm_encoder_helper_funcs *helpers
1986a227d5fSAlan Cox 						    = encoder->helper_private;
1996a227d5fSAlan Cox 				helpers->mode_set(encoder, &crtc->saved_mode,
2006a227d5fSAlan Cox 					     &crtc->saved_adjusted_mode);
2016a227d5fSAlan Cox 			}
2026a227d5fSAlan Cox 		}
2036a227d5fSAlan Cox 	}
2046a227d5fSAlan Cox 	return 0;
2056a227d5fSAlan Cox }
2066a227d5fSAlan Cox 
2076a227d5fSAlan Cox /*
2086a227d5fSAlan Cox  * Return the list of HDMI DDC modes if available.
2096a227d5fSAlan Cox  */
cdv_hdmi_get_modes(struct drm_connector * connector)2106a227d5fSAlan Cox static int cdv_hdmi_get_modes(struct drm_connector *connector)
2116a227d5fSAlan Cox {
2126a227d5fSAlan Cox 	struct edid *edid = NULL;
2136a227d5fSAlan Cox 	int ret = 0;
2146a227d5fSAlan Cox 
215544ef140SPatrik Jakobsson 	edid = drm_get_edid(connector, connector->ddc);
2166a227d5fSAlan Cox 	if (edid) {
217c555f023SDaniel Vetter 		drm_connector_update_edid_property(connector, edid);
218a12d6a07SPatrik Jakobsson 		ret = drm_add_edid_modes(connector, edid);
2196a227d5fSAlan Cox 		kfree(edid);
2206a227d5fSAlan Cox 	}
2216a227d5fSAlan Cox 	return ret;
2226a227d5fSAlan Cox }
2236a227d5fSAlan Cox 
cdv_hdmi_mode_valid(struct drm_connector * connector,struct drm_display_mode * mode)22467772782SLuc Van Oostenryck static enum drm_mode_status cdv_hdmi_mode_valid(struct drm_connector *connector,
2256a227d5fSAlan Cox 				 struct drm_display_mode *mode)
2266a227d5fSAlan Cox {
2276a227d5fSAlan Cox 	if (mode->clock > 165000)
2286a227d5fSAlan Cox 		return MODE_CLOCK_HIGH;
2296a227d5fSAlan Cox 	if (mode->clock < 20000)
2306a227d5fSAlan Cox 		return MODE_CLOCK_HIGH;
2316a227d5fSAlan Cox 
2326a227d5fSAlan Cox 	/* just in case */
2336a227d5fSAlan Cox 	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
2346a227d5fSAlan Cox 		return MODE_NO_DBLESCAN;
2356a227d5fSAlan Cox 
2366a227d5fSAlan Cox 	/* just in case */
2376a227d5fSAlan Cox 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2386a227d5fSAlan Cox 		return MODE_NO_INTERLACE;
2396a227d5fSAlan Cox 
2406a227d5fSAlan Cox 	return MODE_OK;
2416a227d5fSAlan Cox }
2426a227d5fSAlan Cox 
cdv_hdmi_destroy(struct drm_connector * connector)2436a227d5fSAlan Cox static void cdv_hdmi_destroy(struct drm_connector *connector)
2446a227d5fSAlan Cox {
24512e67ccaSPatrik Jakobsson 	struct gma_connector *gma_connector = to_gma_connector(connector);
246544ef140SPatrik Jakobsson 	struct gma_i2c_chan *ddc_bus = to_gma_i2c_chan(connector->ddc);
2476a227d5fSAlan Cox 
248544ef140SPatrik Jakobsson 	gma_i2c_destroy(ddc_bus);
2496a227d5fSAlan Cox 	drm_connector_cleanup(connector);
25012e67ccaSPatrik Jakobsson 	kfree(gma_connector);
2516a227d5fSAlan Cox }
2526a227d5fSAlan Cox 
2536a227d5fSAlan Cox static const struct drm_encoder_helper_funcs cdv_hdmi_helper_funcs = {
2546a227d5fSAlan Cox 	.dpms = cdv_hdmi_dpms,
255c9d49590SPatrik Jakobsson 	.prepare = gma_encoder_prepare,
2566a227d5fSAlan Cox 	.mode_set = cdv_hdmi_mode_set,
257c9d49590SPatrik Jakobsson 	.commit = gma_encoder_commit,
2586a227d5fSAlan Cox };
2596a227d5fSAlan Cox 
2606a227d5fSAlan Cox static const struct drm_connector_helper_funcs
2616a227d5fSAlan Cox 					cdv_hdmi_connector_helper_funcs = {
2626a227d5fSAlan Cox 	.get_modes = cdv_hdmi_get_modes,
2636a227d5fSAlan Cox 	.mode_valid = cdv_hdmi_mode_valid,
264c9d49590SPatrik Jakobsson 	.best_encoder = gma_best_encoder,
2656a227d5fSAlan Cox };
2666a227d5fSAlan Cox 
2676a227d5fSAlan Cox static const struct drm_connector_funcs cdv_hdmi_connector_funcs = {
2686a227d5fSAlan Cox 	.dpms = drm_helper_connector_dpms,
2696a227d5fSAlan Cox 	.detect = cdv_hdmi_detect,
2706a227d5fSAlan Cox 	.fill_modes = drm_helper_probe_single_connector_modes,
2716a227d5fSAlan Cox 	.set_property = cdv_hdmi_set_property,
2726a227d5fSAlan Cox 	.destroy = cdv_hdmi_destroy,
2736a227d5fSAlan Cox };
2746a227d5fSAlan Cox 
cdv_hdmi_init(struct drm_device * dev,struct psb_intel_mode_device * mode_dev,int reg)2756a227d5fSAlan Cox void cdv_hdmi_init(struct drm_device *dev,
2766a227d5fSAlan Cox 			struct psb_intel_mode_device *mode_dev, int reg)
2776a227d5fSAlan Cox {
278367e4408SPatrik Jakobsson 	struct gma_encoder *gma_encoder;
279a3d5d75fSPatrik Jakobsson 	struct gma_connector *gma_connector;
2806a227d5fSAlan Cox 	struct drm_connector *connector;
2816a227d5fSAlan Cox 	struct mid_intel_hdmi_priv *hdmi_priv;
282544ef140SPatrik Jakobsson 	struct gma_i2c_chan *ddc_bus;
283544ef140SPatrik Jakobsson 	int ddc_reg;
284544ef140SPatrik Jakobsson 	int ret;
2856a227d5fSAlan Cox 
286367e4408SPatrik Jakobsson 	gma_encoder = kzalloc(sizeof(struct gma_encoder), GFP_KERNEL);
287367e4408SPatrik Jakobsson 	if (!gma_encoder)
2886a227d5fSAlan Cox 		return;
2896a227d5fSAlan Cox 
290544ef140SPatrik Jakobsson 	gma_connector = kzalloc(sizeof(struct gma_connector), GFP_KERNEL);
291a3d5d75fSPatrik Jakobsson 	if (!gma_connector)
292544ef140SPatrik Jakobsson 		goto err_free_encoder;
293a12d6a07SPatrik Jakobsson 
294a12d6a07SPatrik Jakobsson 	hdmi_priv = kzalloc(sizeof(struct mid_intel_hdmi_priv), GFP_KERNEL);
295a12d6a07SPatrik Jakobsson 	if (!hdmi_priv)
296544ef140SPatrik Jakobsson 		goto err_free_connector;
297a12d6a07SPatrik Jakobsson 
298a3d5d75fSPatrik Jakobsson 	connector = &gma_connector->base;
299bda50031SKero van Gelder 	connector->polled = DRM_CONNECTOR_POLL_HPD;
300d56f57acSDaniel Vetter 	gma_connector->save = cdv_hdmi_save;
301d56f57acSDaniel Vetter 	gma_connector->restore = cdv_hdmi_restore;
302d56f57acSDaniel Vetter 
303544ef140SPatrik Jakobsson 	switch (reg) {
304544ef140SPatrik Jakobsson 	case SDVOB:
305544ef140SPatrik Jakobsson 		ddc_reg = GPIOE;
306544ef140SPatrik Jakobsson 		gma_encoder->ddi_select = DDI0_SELECT;
307544ef140SPatrik Jakobsson 		break;
308544ef140SPatrik Jakobsson 	case SDVOC:
309544ef140SPatrik Jakobsson 		ddc_reg = GPIOD;
310544ef140SPatrik Jakobsson 		gma_encoder->ddi_select = DDI1_SELECT;
311544ef140SPatrik Jakobsson 		break;
312544ef140SPatrik Jakobsson 	default:
313544ef140SPatrik Jakobsson 		DRM_ERROR("unknown reg 0x%x for HDMI\n", reg);
314544ef140SPatrik Jakobsson 		goto err_free_hdmi_priv;
315544ef140SPatrik Jakobsson 	}
3166a227d5fSAlan Cox 
317544ef140SPatrik Jakobsson 	ddc_bus = gma_i2c_create(dev, ddc_reg,
318544ef140SPatrik Jakobsson 				 (reg == SDVOB) ? "HDMIB" : "HDMIC");
319544ef140SPatrik Jakobsson 	if (!ddc_bus) {
320544ef140SPatrik Jakobsson 		dev_err(dev->dev, "No ddc adapter available!\n");
321544ef140SPatrik Jakobsson 		goto err_free_hdmi_priv;
322544ef140SPatrik Jakobsson 	}
323544ef140SPatrik Jakobsson 
324544ef140SPatrik Jakobsson 	ret = drm_connector_init_with_ddc(dev, connector,
325544ef140SPatrik Jakobsson 					  &cdv_hdmi_connector_funcs,
326544ef140SPatrik Jakobsson 					  DRM_MODE_CONNECTOR_DVID,
327544ef140SPatrik Jakobsson 					  &ddc_bus->base);
328544ef140SPatrik Jakobsson 	if (ret)
329544ef140SPatrik Jakobsson 		goto err_ddc_destroy;
330544ef140SPatrik Jakobsson 
331544ef140SPatrik Jakobsson 	ret = drm_simple_encoder_init(dev, &gma_encoder->base,
332544ef140SPatrik Jakobsson 				      DRM_MODE_ENCODER_TMDS);
333544ef140SPatrik Jakobsson 	if (ret)
334544ef140SPatrik Jakobsson 		goto err_connector_cleanup;
3356a227d5fSAlan Cox 
336367e4408SPatrik Jakobsson 	gma_connector_attach_encoder(gma_connector, gma_encoder);
337367e4408SPatrik Jakobsson 	gma_encoder->type = INTEL_OUTPUT_HDMI;
3386a227d5fSAlan Cox 	hdmi_priv->hdmi_reg = reg;
3396a227d5fSAlan Cox 	hdmi_priv->has_hdmi_sink = false;
340367e4408SPatrik Jakobsson 	gma_encoder->dev_priv = hdmi_priv;
3416a227d5fSAlan Cox 
342544ef140SPatrik Jakobsson 	drm_encoder_helper_add(&gma_encoder->base, &cdv_hdmi_helper_funcs);
3436a227d5fSAlan Cox 	drm_connector_helper_add(connector,
3446a227d5fSAlan Cox 				 &cdv_hdmi_connector_helper_funcs);
3456a227d5fSAlan Cox 	connector->display_info.subpixel_order = SubPixelHorizontalRGB;
3466a227d5fSAlan Cox 	connector->interlace_allowed = false;
3476a227d5fSAlan Cox 	connector->doublescan_allowed = false;
3486a227d5fSAlan Cox 
349a69ac9eaSRob Clark 	drm_object_attach_property(&connector->base,
350a12d6a07SPatrik Jakobsson 				      dev->mode_config.scaling_mode_property,
351a12d6a07SPatrik Jakobsson 				      DRM_MODE_SCALE_FULLSCREEN);
3526a227d5fSAlan Cox 
3536a227d5fSAlan Cox 	hdmi_priv->dev = dev;
3546a227d5fSAlan Cox 	return;
3556a227d5fSAlan Cox 
356544ef140SPatrik Jakobsson err_connector_cleanup:
357a12d6a07SPatrik Jakobsson 	drm_connector_cleanup(connector);
358544ef140SPatrik Jakobsson err_ddc_destroy:
359544ef140SPatrik Jakobsson 	gma_i2c_destroy(ddc_bus);
360544ef140SPatrik Jakobsson err_free_hdmi_priv:
361544ef140SPatrik Jakobsson 	kfree(hdmi_priv);
362544ef140SPatrik Jakobsson err_free_connector:
363a3d5d75fSPatrik Jakobsson 	kfree(gma_connector);
364544ef140SPatrik Jakobsson err_free_encoder:
365367e4408SPatrik Jakobsson 	kfree(gma_encoder);
3666a227d5fSAlan Cox }
367