Linux Audio

Check our new training course

Embedded Linux training

Mar 10-20, 2025, special US time zones
Register
Loading...
v5.4
  1/*
  2 * Copyright © 2006-2011 Intel Corporation
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining a
  5 * copy of this software and associated documentation files (the "Software"),
  6 * to deal in the Software without restriction, including without limitation
  7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8 * and/or sell copies of the Software, and to permit persons to whom the
  9 * Software is furnished to do so, subject to the following conditions:
 10 *
 11 * The above copyright notice and this permission notice (including the next
 12 * paragraph) shall be included in all copies or substantial portions of the
 13 * Software.
 14 *
 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 21 * DEALINGS IN THE SOFTWARE.
 22 *
 23 * Authors:
 24 *	jim liu <jim.liu@intel.com>
 25 *
 26 * FIXME:
 27 *	We should probably make this generic and share it with Medfield
 28 */
 29
 30#include <linux/pm_runtime.h>
 31
 32#include <drm/drm.h>
 33#include <drm/drm_crtc.h>
 
 34#include <drm/drm_edid.h>
 
 
 35
 36#include "cdv_device.h"
 37#include "psb_drv.h"
 38#include "psb_intel_drv.h"
 39#include "psb_intel_reg.h"
 40
 41/* hdmi control bits */
 42#define HDMI_NULL_PACKETS_DURING_VSYNC	(1 << 9)
 43#define HDMI_BORDER_ENABLE		(1 << 7)
 44#define HDMI_AUDIO_ENABLE		(1 << 6)
 45#define HDMI_VSYNC_ACTIVE_HIGH		(1 << 4)
 46#define HDMI_HSYNC_ACTIVE_HIGH		(1 << 3)
 47/* hdmi-b control bits */
 48#define	HDMIB_PIPE_B_SELECT		(1 << 30)
 49
 50
 51struct mid_intel_hdmi_priv {
 52	u32 hdmi_reg;
 53	u32 save_HDMIB;
 54	bool has_hdmi_sink;
 55	bool has_hdmi_audio;
 56	/* Should set this when detect hotplug */
 57	bool hdmi_device_connected;
 58	struct mdfld_hdmi_i2c *i2c_bus;
 59	struct i2c_adapter *hdmi_i2c_adapter;	/* for control functions */
 60	struct drm_device *dev;
 61};
 62
 63static void cdv_hdmi_mode_set(struct drm_encoder *encoder,
 64			struct drm_display_mode *mode,
 65			struct drm_display_mode *adjusted_mode)
 66{
 67	struct drm_device *dev = encoder->dev;
 68	struct gma_encoder *gma_encoder = to_gma_encoder(encoder);
 69	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
 70	u32 hdmib;
 71	struct drm_crtc *crtc = encoder->crtc;
 72	struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
 73
 74	hdmib = (2 << 10);
 75
 76	if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
 77		hdmib |= HDMI_VSYNC_ACTIVE_HIGH;
 78	if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
 79		hdmib |= HDMI_HSYNC_ACTIVE_HIGH;
 80
 81	if (gma_crtc->pipe == 1)
 82		hdmib |= HDMIB_PIPE_B_SELECT;
 83
 84	if (hdmi_priv->has_hdmi_audio) {
 85		hdmib |= HDMI_AUDIO_ENABLE;
 86		hdmib |= HDMI_NULL_PACKETS_DURING_VSYNC;
 87	}
 88
 89	REG_WRITE(hdmi_priv->hdmi_reg, hdmib);
 90	REG_READ(hdmi_priv->hdmi_reg);
 91}
 92
 93static void cdv_hdmi_dpms(struct drm_encoder *encoder, int mode)
 94{
 95	struct drm_device *dev = encoder->dev;
 96	struct gma_encoder *gma_encoder = to_gma_encoder(encoder);
 97	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
 98	u32 hdmib;
 99
100	hdmib = REG_READ(hdmi_priv->hdmi_reg);
101
102	if (mode != DRM_MODE_DPMS_ON)
103		REG_WRITE(hdmi_priv->hdmi_reg, hdmib & ~HDMIB_PORT_EN);
104	else
105		REG_WRITE(hdmi_priv->hdmi_reg, hdmib | HDMIB_PORT_EN);
106	REG_READ(hdmi_priv->hdmi_reg);
107}
108
109static void cdv_hdmi_save(struct drm_connector *connector)
110{
111	struct drm_device *dev = connector->dev;
112	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
113	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
114
115	hdmi_priv->save_HDMIB = REG_READ(hdmi_priv->hdmi_reg);
116}
117
118static void cdv_hdmi_restore(struct drm_connector *connector)
119{
120	struct drm_device *dev = connector->dev;
121	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
122	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
123
124	REG_WRITE(hdmi_priv->hdmi_reg, hdmi_priv->save_HDMIB);
125	REG_READ(hdmi_priv->hdmi_reg);
126}
127
128static enum drm_connector_status cdv_hdmi_detect(
129				struct drm_connector *connector, bool force)
130{
131	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
132	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
133	struct edid *edid = NULL;
134	enum drm_connector_status status = connector_status_disconnected;
135
136	edid = drm_get_edid(connector, &gma_encoder->i2c_bus->adapter);
137
138	hdmi_priv->has_hdmi_sink = false;
139	hdmi_priv->has_hdmi_audio = false;
140	if (edid) {
141		if (edid->input & DRM_EDID_INPUT_DIGITAL) {
142			status = connector_status_connected;
143			hdmi_priv->has_hdmi_sink =
144						drm_detect_hdmi_monitor(edid);
145			hdmi_priv->has_hdmi_audio =
146						drm_detect_monitor_audio(edid);
147		}
148		kfree(edid);
149	}
150	return status;
151}
152
153static int cdv_hdmi_set_property(struct drm_connector *connector,
154				       struct drm_property *property,
155				       uint64_t value)
156{
157	struct drm_encoder *encoder = connector->encoder;
158
159	if (!strcmp(property->name, "scaling mode") && encoder) {
160		struct gma_crtc *crtc = to_gma_crtc(encoder->crtc);
161		bool centre;
162		uint64_t curValue;
163
164		if (!crtc)
165			return -1;
166
167		switch (value) {
168		case DRM_MODE_SCALE_FULLSCREEN:
169			break;
170		case DRM_MODE_SCALE_NO_SCALE:
171			break;
172		case DRM_MODE_SCALE_ASPECT:
173			break;
174		default:
175			return -1;
176		}
177
178		if (drm_object_property_get_value(&connector->base,
179							property, &curValue))
180			return -1;
181
182		if (curValue == value)
183			return 0;
184
185		if (drm_object_property_set_value(&connector->base,
186							property, value))
187			return -1;
188
189		centre = (curValue == DRM_MODE_SCALE_NO_SCALE) ||
190			(value == DRM_MODE_SCALE_NO_SCALE);
191
192		if (crtc->saved_mode.hdisplay != 0 &&
193		    crtc->saved_mode.vdisplay != 0) {
194			if (centre) {
195				if (!drm_crtc_helper_set_mode(encoder->crtc, &crtc->saved_mode,
196					    encoder->crtc->x, encoder->crtc->y, encoder->crtc->primary->fb))
197					return -1;
198			} else {
199				const struct drm_encoder_helper_funcs *helpers
200						    = encoder->helper_private;
201				helpers->mode_set(encoder, &crtc->saved_mode,
202					     &crtc->saved_adjusted_mode);
203			}
204		}
205	}
206	return 0;
207}
208
209/*
210 * Return the list of HDMI DDC modes if available.
211 */
212static int cdv_hdmi_get_modes(struct drm_connector *connector)
213{
214	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
215	struct edid *edid = NULL;
216	int ret = 0;
217
218	edid = drm_get_edid(connector, &gma_encoder->i2c_bus->adapter);
219	if (edid) {
220		drm_connector_update_edid_property(connector, edid);
221		ret = drm_add_edid_modes(connector, edid);
222		kfree(edid);
223	}
224	return ret;
225}
226
227static enum drm_mode_status cdv_hdmi_mode_valid(struct drm_connector *connector,
228				 struct drm_display_mode *mode)
229{
230	if (mode->clock > 165000)
231		return MODE_CLOCK_HIGH;
232	if (mode->clock < 20000)
233		return MODE_CLOCK_HIGH;
234
235	/* just in case */
236	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
237		return MODE_NO_DBLESCAN;
238
239	/* just in case */
240	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
241		return MODE_NO_INTERLACE;
242
243	return MODE_OK;
244}
245
246static void cdv_hdmi_destroy(struct drm_connector *connector)
247{
248	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
 
249
250	psb_intel_i2c_destroy(gma_encoder->i2c_bus);
251	drm_connector_unregister(connector);
252	drm_connector_cleanup(connector);
253	kfree(connector);
254}
255
256static const struct drm_encoder_helper_funcs cdv_hdmi_helper_funcs = {
257	.dpms = cdv_hdmi_dpms,
258	.prepare = gma_encoder_prepare,
259	.mode_set = cdv_hdmi_mode_set,
260	.commit = gma_encoder_commit,
261};
262
263static const struct drm_connector_helper_funcs
264					cdv_hdmi_connector_helper_funcs = {
265	.get_modes = cdv_hdmi_get_modes,
266	.mode_valid = cdv_hdmi_mode_valid,
267	.best_encoder = gma_best_encoder,
268};
269
270static const struct drm_connector_funcs cdv_hdmi_connector_funcs = {
271	.dpms = drm_helper_connector_dpms,
272	.detect = cdv_hdmi_detect,
273	.fill_modes = drm_helper_probe_single_connector_modes,
274	.set_property = cdv_hdmi_set_property,
275	.destroy = cdv_hdmi_destroy,
276};
277
278void cdv_hdmi_init(struct drm_device *dev,
279			struct psb_intel_mode_device *mode_dev, int reg)
280{
281	struct gma_encoder *gma_encoder;
282	struct gma_connector *gma_connector;
283	struct drm_connector *connector;
284	struct drm_encoder *encoder;
285	struct mid_intel_hdmi_priv *hdmi_priv;
286	int ddc_bus;
 
 
287
288	gma_encoder = kzalloc(sizeof(struct gma_encoder), GFP_KERNEL);
289
290	if (!gma_encoder)
291		return;
292
293	gma_connector = kzalloc(sizeof(struct gma_connector),
294				      GFP_KERNEL);
295
296	if (!gma_connector)
297		goto err_connector;
298
299	hdmi_priv = kzalloc(sizeof(struct mid_intel_hdmi_priv), GFP_KERNEL);
300
301	if (!hdmi_priv)
302		goto err_priv;
303
304	connector = &gma_connector->base;
305	connector->polled = DRM_CONNECTOR_POLL_HPD;
306	gma_connector->save = cdv_hdmi_save;
307	gma_connector->restore = cdv_hdmi_restore;
308
309	encoder = &gma_encoder->base;
310	drm_connector_init(dev, connector,
311			   &cdv_hdmi_connector_funcs,
312			   DRM_MODE_CONNECTOR_DVID);
 
 
 
 
 
 
 
 
 
313
314	drm_encoder_init(dev, encoder, &psb_intel_lvds_enc_funcs,
315			 DRM_MODE_ENCODER_TMDS, NULL);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
317	gma_connector_attach_encoder(gma_connector, gma_encoder);
318	gma_encoder->type = INTEL_OUTPUT_HDMI;
319	hdmi_priv->hdmi_reg = reg;
320	hdmi_priv->has_hdmi_sink = false;
321	gma_encoder->dev_priv = hdmi_priv;
322
323	drm_encoder_helper_add(encoder, &cdv_hdmi_helper_funcs);
324	drm_connector_helper_add(connector,
325				 &cdv_hdmi_connector_helper_funcs);
326	connector->display_info.subpixel_order = SubPixelHorizontalRGB;
327	connector->interlace_allowed = false;
328	connector->doublescan_allowed = false;
329
330	drm_object_attach_property(&connector->base,
331				      dev->mode_config.scaling_mode_property,
332				      DRM_MODE_SCALE_FULLSCREEN);
333
334	switch (reg) {
335	case SDVOB:
336		ddc_bus = GPIOE;
337		gma_encoder->ddi_select = DDI0_SELECT;
338		break;
339	case SDVOC:
340		ddc_bus = GPIOD;
341		gma_encoder->ddi_select = DDI1_SELECT;
342		break;
343	default:
344		DRM_ERROR("unknown reg 0x%x for HDMI\n", reg);
345		goto failed_ddc;
346		break;
347	}
348
349	gma_encoder->i2c_bus = psb_intel_i2c_create(dev,
350				ddc_bus, (reg == SDVOB) ? "HDMIB" : "HDMIC");
351
352	if (!gma_encoder->i2c_bus) {
353		dev_err(dev->dev, "No ddc adapter available!\n");
354		goto failed_ddc;
355	}
356
357	hdmi_priv->hdmi_i2c_adapter = &(gma_encoder->i2c_bus->adapter);
358	hdmi_priv->dev = dev;
359	drm_connector_register(connector);
360	return;
361
362failed_ddc:
363	drm_encoder_cleanup(encoder);
364	drm_connector_cleanup(connector);
365err_priv:
 
 
 
 
366	kfree(gma_connector);
367err_connector:
368	kfree(gma_encoder);
369}
v6.8
  1/*
  2 * Copyright © 2006-2011 Intel Corporation
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining a
  5 * copy of this software and associated documentation files (the "Software"),
  6 * to deal in the Software without restriction, including without limitation
  7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8 * and/or sell copies of the Software, and to permit persons to whom the
  9 * Software is furnished to do so, subject to the following conditions:
 10 *
 11 * The above copyright notice and this permission notice (including the next
 12 * paragraph) shall be included in all copies or substantial portions of the
 13 * Software.
 14 *
 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 21 * DEALINGS IN THE SOFTWARE.
 22 *
 23 * Authors:
 24 *	jim liu <jim.liu@intel.com>
 
 
 
 25 */
 26
 27#include <linux/pm_runtime.h>
 28
 29#include <drm/drm.h>
 30#include <drm/drm_crtc.h>
 31#include <drm/drm_crtc_helper.h>
 32#include <drm/drm_edid.h>
 33#include <drm/drm_modeset_helper_vtables.h>
 34#include <drm/drm_simple_kms_helper.h>
 35
 36#include "cdv_device.h"
 37#include "psb_drv.h"
 38#include "psb_intel_drv.h"
 39#include "psb_intel_reg.h"
 40
 41/* hdmi control bits */
 42#define HDMI_NULL_PACKETS_DURING_VSYNC	(1 << 9)
 43#define HDMI_BORDER_ENABLE		(1 << 7)
 44#define HDMI_AUDIO_ENABLE		(1 << 6)
 45#define HDMI_VSYNC_ACTIVE_HIGH		(1 << 4)
 46#define HDMI_HSYNC_ACTIVE_HIGH		(1 << 3)
 47/* hdmi-b control bits */
 48#define	HDMIB_PIPE_B_SELECT		(1 << 30)
 49
 50
 51struct mid_intel_hdmi_priv {
 52	u32 hdmi_reg;
 53	u32 save_HDMIB;
 54	bool has_hdmi_sink;
 55	bool has_hdmi_audio;
 56	/* Should set this when detect hotplug */
 57	bool hdmi_device_connected;
 
 
 58	struct drm_device *dev;
 59};
 60
 61static void cdv_hdmi_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 gma_encoder *gma_encoder = to_gma_encoder(encoder);
 67	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
 68	u32 hdmib;
 69	struct drm_crtc *crtc = encoder->crtc;
 70	struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
 71
 72	hdmib = (2 << 10);
 73
 74	if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
 75		hdmib |= HDMI_VSYNC_ACTIVE_HIGH;
 76	if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
 77		hdmib |= HDMI_HSYNC_ACTIVE_HIGH;
 78
 79	if (gma_crtc->pipe == 1)
 80		hdmib |= HDMIB_PIPE_B_SELECT;
 81
 82	if (hdmi_priv->has_hdmi_audio) {
 83		hdmib |= HDMI_AUDIO_ENABLE;
 84		hdmib |= HDMI_NULL_PACKETS_DURING_VSYNC;
 85	}
 86
 87	REG_WRITE(hdmi_priv->hdmi_reg, hdmib);
 88	REG_READ(hdmi_priv->hdmi_reg);
 89}
 90
 91static void cdv_hdmi_dpms(struct drm_encoder *encoder, int mode)
 92{
 93	struct drm_device *dev = encoder->dev;
 94	struct gma_encoder *gma_encoder = to_gma_encoder(encoder);
 95	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
 96	u32 hdmib;
 97
 98	hdmib = REG_READ(hdmi_priv->hdmi_reg);
 99
100	if (mode != DRM_MODE_DPMS_ON)
101		REG_WRITE(hdmi_priv->hdmi_reg, hdmib & ~HDMIB_PORT_EN);
102	else
103		REG_WRITE(hdmi_priv->hdmi_reg, hdmib | HDMIB_PORT_EN);
104	REG_READ(hdmi_priv->hdmi_reg);
105}
106
107static void cdv_hdmi_save(struct drm_connector *connector)
108{
109	struct drm_device *dev = connector->dev;
110	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
111	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
112
113	hdmi_priv->save_HDMIB = REG_READ(hdmi_priv->hdmi_reg);
114}
115
116static void cdv_hdmi_restore(struct drm_connector *connector)
117{
118	struct drm_device *dev = connector->dev;
119	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
120	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
121
122	REG_WRITE(hdmi_priv->hdmi_reg, hdmi_priv->save_HDMIB);
123	REG_READ(hdmi_priv->hdmi_reg);
124}
125
126static enum drm_connector_status cdv_hdmi_detect(
127				struct drm_connector *connector, bool force)
128{
129	struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
130	struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
131	struct edid *edid = NULL;
132	enum drm_connector_status status = connector_status_disconnected;
133
134	edid = drm_get_edid(connector, connector->ddc);
135
136	hdmi_priv->has_hdmi_sink = false;
137	hdmi_priv->has_hdmi_audio = false;
138	if (edid) {
139		if (edid->input & DRM_EDID_INPUT_DIGITAL) {
140			status = connector_status_connected;
141			hdmi_priv->has_hdmi_sink =
142						drm_detect_hdmi_monitor(edid);
143			hdmi_priv->has_hdmi_audio =
144						drm_detect_monitor_audio(edid);
145		}
146		kfree(edid);
147	}
148	return status;
149}
150
151static int cdv_hdmi_set_property(struct drm_connector *connector,
152				       struct drm_property *property,
153				       uint64_t value)
154{
155	struct drm_encoder *encoder = connector->encoder;
156
157	if (!strcmp(property->name, "scaling mode") && encoder) {
158		struct gma_crtc *crtc = to_gma_crtc(encoder->crtc);
159		bool centre;
160		uint64_t curValue;
161
162		if (!crtc)
163			return -1;
164
165		switch (value) {
166		case DRM_MODE_SCALE_FULLSCREEN:
167			break;
168		case DRM_MODE_SCALE_NO_SCALE:
169			break;
170		case DRM_MODE_SCALE_ASPECT:
171			break;
172		default:
173			return -1;
174		}
175
176		if (drm_object_property_get_value(&connector->base,
177							property, &curValue))
178			return -1;
179
180		if (curValue == value)
181			return 0;
182
183		if (drm_object_property_set_value(&connector->base,
184							property, value))
185			return -1;
186
187		centre = (curValue == DRM_MODE_SCALE_NO_SCALE) ||
188			(value == DRM_MODE_SCALE_NO_SCALE);
189
190		if (crtc->saved_mode.hdisplay != 0 &&
191		    crtc->saved_mode.vdisplay != 0) {
192			if (centre) {
193				if (!drm_crtc_helper_set_mode(encoder->crtc, &crtc->saved_mode,
194					    encoder->crtc->x, encoder->crtc->y, encoder->crtc->primary->fb))
195					return -1;
196			} else {
197				const struct drm_encoder_helper_funcs *helpers
198						    = encoder->helper_private;
199				helpers->mode_set(encoder, &crtc->saved_mode,
200					     &crtc->saved_adjusted_mode);
201			}
202		}
203	}
204	return 0;
205}
206
207/*
208 * Return the list of HDMI DDC modes if available.
209 */
210static int cdv_hdmi_get_modes(struct drm_connector *connector)
211{
 
212	struct edid *edid = NULL;
213	int ret = 0;
214
215	edid = drm_get_edid(connector, connector->ddc);
216	if (edid) {
217		drm_connector_update_edid_property(connector, edid);
218		ret = drm_add_edid_modes(connector, edid);
219		kfree(edid);
220	}
221	return ret;
222}
223
224static enum drm_mode_status cdv_hdmi_mode_valid(struct drm_connector *connector,
225				 struct drm_display_mode *mode)
226{
227	if (mode->clock > 165000)
228		return MODE_CLOCK_HIGH;
229	if (mode->clock < 20000)
230		return MODE_CLOCK_HIGH;
231
232	/* just in case */
233	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
234		return MODE_NO_DBLESCAN;
235
236	/* just in case */
237	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
238		return MODE_NO_INTERLACE;
239
240	return MODE_OK;
241}
242
243static void cdv_hdmi_destroy(struct drm_connector *connector)
244{
245	struct gma_connector *gma_connector = to_gma_connector(connector);
246	struct gma_i2c_chan *ddc_bus = to_gma_i2c_chan(connector->ddc);
247
248	gma_i2c_destroy(ddc_bus);
 
249	drm_connector_cleanup(connector);
250	kfree(gma_connector);
251}
252
253static const struct drm_encoder_helper_funcs cdv_hdmi_helper_funcs = {
254	.dpms = cdv_hdmi_dpms,
255	.prepare = gma_encoder_prepare,
256	.mode_set = cdv_hdmi_mode_set,
257	.commit = gma_encoder_commit,
258};
259
260static const struct drm_connector_helper_funcs
261					cdv_hdmi_connector_helper_funcs = {
262	.get_modes = cdv_hdmi_get_modes,
263	.mode_valid = cdv_hdmi_mode_valid,
264	.best_encoder = gma_best_encoder,
265};
266
267static const struct drm_connector_funcs cdv_hdmi_connector_funcs = {
268	.dpms = drm_helper_connector_dpms,
269	.detect = cdv_hdmi_detect,
270	.fill_modes = drm_helper_probe_single_connector_modes,
271	.set_property = cdv_hdmi_set_property,
272	.destroy = cdv_hdmi_destroy,
273};
274
275void cdv_hdmi_init(struct drm_device *dev,
276			struct psb_intel_mode_device *mode_dev, int reg)
277{
278	struct gma_encoder *gma_encoder;
279	struct gma_connector *gma_connector;
280	struct drm_connector *connector;
 
281	struct mid_intel_hdmi_priv *hdmi_priv;
282	struct gma_i2c_chan *ddc_bus;
283	int ddc_reg;
284	int ret;
285
286	gma_encoder = kzalloc(sizeof(struct gma_encoder), GFP_KERNEL);
 
287	if (!gma_encoder)
288		return;
289
290	gma_connector = kzalloc(sizeof(struct gma_connector), GFP_KERNEL);
 
 
291	if (!gma_connector)
292		goto err_free_encoder;
293
294	hdmi_priv = kzalloc(sizeof(struct mid_intel_hdmi_priv), GFP_KERNEL);
 
295	if (!hdmi_priv)
296		goto err_free_connector;
297
298	connector = &gma_connector->base;
299	connector->polled = DRM_CONNECTOR_POLL_HPD;
300	gma_connector->save = cdv_hdmi_save;
301	gma_connector->restore = cdv_hdmi_restore;
302
303	switch (reg) {
304	case SDVOB:
305		ddc_reg = GPIOE;
306		gma_encoder->ddi_select = DDI0_SELECT;
307		break;
308	case SDVOC:
309		ddc_reg = GPIOD;
310		gma_encoder->ddi_select = DDI1_SELECT;
311		break;
312	default:
313		DRM_ERROR("unknown reg 0x%x for HDMI\n", reg);
314		goto err_free_hdmi_priv;
315	}
316
317	ddc_bus = gma_i2c_create(dev, ddc_reg,
318				 (reg == SDVOB) ? "HDMIB" : "HDMIC");
319	if (!ddc_bus) {
320		dev_err(dev->dev, "No ddc adapter available!\n");
321		goto err_free_hdmi_priv;
322	}
323
324	ret = drm_connector_init_with_ddc(dev, connector,
325					  &cdv_hdmi_connector_funcs,
326					  DRM_MODE_CONNECTOR_DVID,
327					  &ddc_bus->base);
328	if (ret)
329		goto err_ddc_destroy;
330
331	ret = drm_simple_encoder_init(dev, &gma_encoder->base,
332				      DRM_MODE_ENCODER_TMDS);
333	if (ret)
334		goto err_connector_cleanup;
335
336	gma_connector_attach_encoder(gma_connector, gma_encoder);
337	gma_encoder->type = INTEL_OUTPUT_HDMI;
338	hdmi_priv->hdmi_reg = reg;
339	hdmi_priv->has_hdmi_sink = false;
340	gma_encoder->dev_priv = hdmi_priv;
341
342	drm_encoder_helper_add(&gma_encoder->base, &cdv_hdmi_helper_funcs);
343	drm_connector_helper_add(connector,
344				 &cdv_hdmi_connector_helper_funcs);
345	connector->display_info.subpixel_order = SubPixelHorizontalRGB;
346	connector->interlace_allowed = false;
347	connector->doublescan_allowed = false;
348
349	drm_object_attach_property(&connector->base,
350				      dev->mode_config.scaling_mode_property,
351				      DRM_MODE_SCALE_FULLSCREEN);
352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353	hdmi_priv->dev = dev;
 
354	return;
355
356err_connector_cleanup:
 
357	drm_connector_cleanup(connector);
358err_ddc_destroy:
359	gma_i2c_destroy(ddc_bus);
360err_free_hdmi_priv:
361	kfree(hdmi_priv);
362err_free_connector:
363	kfree(gma_connector);
364err_free_encoder:
365	kfree(gma_encoder);
366}