Loading...
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 <drm/drmP.h>
31#include <drm/drm.h>
32#include <drm/drm_crtc.h>
33#include <drm/drm_edid.h>
34#include "psb_intel_drv.h"
35#include "psb_drv.h"
36#include "psb_intel_reg.h"
37#include "cdv_device.h"
38#include <linux/pm_runtime.h>
39
40/* hdmi control bits */
41#define HDMI_NULL_PACKETS_DURING_VSYNC (1 << 9)
42#define HDMI_BORDER_ENABLE (1 << 7)
43#define HDMI_AUDIO_ENABLE (1 << 6)
44#define HDMI_VSYNC_ACTIVE_HIGH (1 << 4)
45#define HDMI_HSYNC_ACTIVE_HIGH (1 << 3)
46/* hdmi-b control bits */
47#define HDMIB_PIPE_B_SELECT (1 << 30)
48
49
50struct mid_intel_hdmi_priv {
51 u32 hdmi_reg;
52 u32 save_HDMIB;
53 bool has_hdmi_sink;
54 bool has_hdmi_audio;
55 /* Should set this when detect hotplug */
56 bool hdmi_device_connected;
57 struct mdfld_hdmi_i2c *i2c_bus;
58 struct i2c_adapter *hdmi_i2c_adapter; /* for control functions */
59 struct drm_device *dev;
60};
61
62static void cdv_hdmi_mode_set(struct drm_encoder *encoder,
63 struct drm_display_mode *mode,
64 struct drm_display_mode *adjusted_mode)
65{
66 struct drm_device *dev = encoder->dev;
67 struct gma_encoder *gma_encoder = to_gma_encoder(encoder);
68 struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
69 u32 hdmib;
70 struct drm_crtc *crtc = encoder->crtc;
71 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
72
73 hdmib = (2 << 10);
74
75 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
76 hdmib |= HDMI_VSYNC_ACTIVE_HIGH;
77 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
78 hdmib |= HDMI_HSYNC_ACTIVE_HIGH;
79
80 if (gma_crtc->pipe == 1)
81 hdmib |= HDMIB_PIPE_B_SELECT;
82
83 if (hdmi_priv->has_hdmi_audio) {
84 hdmib |= HDMI_AUDIO_ENABLE;
85 hdmib |= HDMI_NULL_PACKETS_DURING_VSYNC;
86 }
87
88 REG_WRITE(hdmi_priv->hdmi_reg, hdmib);
89 REG_READ(hdmi_priv->hdmi_reg);
90}
91
92static void cdv_hdmi_dpms(struct drm_encoder *encoder, int mode)
93{
94 struct drm_device *dev = encoder->dev;
95 struct gma_encoder *gma_encoder = to_gma_encoder(encoder);
96 struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
97 u32 hdmib;
98
99 hdmib = REG_READ(hdmi_priv->hdmi_reg);
100
101 if (mode != DRM_MODE_DPMS_ON)
102 REG_WRITE(hdmi_priv->hdmi_reg, hdmib & ~HDMIB_PORT_EN);
103 else
104 REG_WRITE(hdmi_priv->hdmi_reg, hdmib | HDMIB_PORT_EN);
105 REG_READ(hdmi_priv->hdmi_reg);
106}
107
108static void cdv_hdmi_save(struct drm_connector *connector)
109{
110 struct drm_device *dev = connector->dev;
111 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
112 struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
113
114 hdmi_priv->save_HDMIB = REG_READ(hdmi_priv->hdmi_reg);
115}
116
117static void cdv_hdmi_restore(struct drm_connector *connector)
118{
119 struct drm_device *dev = connector->dev;
120 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
121 struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
122
123 REG_WRITE(hdmi_priv->hdmi_reg, hdmi_priv->save_HDMIB);
124 REG_READ(hdmi_priv->hdmi_reg);
125}
126
127static enum drm_connector_status cdv_hdmi_detect(
128 struct drm_connector *connector, bool force)
129{
130 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
131 struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
132 struct edid *edid = NULL;
133 enum drm_connector_status status = connector_status_disconnected;
134
135 edid = drm_get_edid(connector, &gma_encoder->i2c_bus->adapter);
136
137 hdmi_priv->has_hdmi_sink = false;
138 hdmi_priv->has_hdmi_audio = false;
139 if (edid) {
140 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
141 status = connector_status_connected;
142 hdmi_priv->has_hdmi_sink =
143 drm_detect_hdmi_monitor(edid);
144 hdmi_priv->has_hdmi_audio =
145 drm_detect_monitor_audio(edid);
146 }
147 kfree(edid);
148 }
149 return status;
150}
151
152static int cdv_hdmi_set_property(struct drm_connector *connector,
153 struct drm_property *property,
154 uint64_t value)
155{
156 struct drm_encoder *encoder = connector->encoder;
157
158 if (!strcmp(property->name, "scaling mode") && encoder) {
159 struct gma_crtc *crtc = to_gma_crtc(encoder->crtc);
160 bool centre;
161 uint64_t curValue;
162
163 if (!crtc)
164 return -1;
165
166 switch (value) {
167 case DRM_MODE_SCALE_FULLSCREEN:
168 break;
169 case DRM_MODE_SCALE_NO_SCALE:
170 break;
171 case DRM_MODE_SCALE_ASPECT:
172 break;
173 default:
174 return -1;
175 }
176
177 if (drm_object_property_get_value(&connector->base,
178 property, &curValue))
179 return -1;
180
181 if (curValue == value)
182 return 0;
183
184 if (drm_object_property_set_value(&connector->base,
185 property, value))
186 return -1;
187
188 centre = (curValue == DRM_MODE_SCALE_NO_SCALE) ||
189 (value == DRM_MODE_SCALE_NO_SCALE);
190
191 if (crtc->saved_mode.hdisplay != 0 &&
192 crtc->saved_mode.vdisplay != 0) {
193 if (centre) {
194 if (!drm_crtc_helper_set_mode(encoder->crtc, &crtc->saved_mode,
195 encoder->crtc->x, encoder->crtc->y, encoder->crtc->primary->fb))
196 return -1;
197 } else {
198 const struct drm_encoder_helper_funcs *helpers
199 = encoder->helper_private;
200 helpers->mode_set(encoder, &crtc->saved_mode,
201 &crtc->saved_adjusted_mode);
202 }
203 }
204 }
205 return 0;
206}
207
208/*
209 * Return the list of HDMI DDC modes if available.
210 */
211static int cdv_hdmi_get_modes(struct drm_connector *connector)
212{
213 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
214 struct edid *edid = NULL;
215 int ret = 0;
216
217 edid = drm_get_edid(connector, &gma_encoder->i2c_bus->adapter);
218 if (edid) {
219 drm_mode_connector_update_edid_property(connector, edid);
220 ret = drm_add_edid_modes(connector, edid);
221 kfree(edid);
222 }
223 return ret;
224}
225
226static int cdv_hdmi_mode_valid(struct drm_connector *connector,
227 struct drm_display_mode *mode)
228{
229 if (mode->clock > 165000)
230 return MODE_CLOCK_HIGH;
231 if (mode->clock < 20000)
232 return MODE_CLOCK_HIGH;
233
234 /* just in case */
235 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
236 return MODE_NO_DBLESCAN;
237
238 /* just in case */
239 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
240 return MODE_NO_INTERLACE;
241
242 return MODE_OK;
243}
244
245static void cdv_hdmi_destroy(struct drm_connector *connector)
246{
247 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
248
249 if (gma_encoder->i2c_bus)
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}
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_edid.h>
32#include <drm/drm_simple_kms_helper.h>
33
34#include "cdv_device.h"
35#include "psb_drv.h"
36#include "psb_intel_drv.h"
37#include "psb_intel_reg.h"
38
39/* hdmi control bits */
40#define HDMI_NULL_PACKETS_DURING_VSYNC (1 << 9)
41#define HDMI_BORDER_ENABLE (1 << 7)
42#define HDMI_AUDIO_ENABLE (1 << 6)
43#define HDMI_VSYNC_ACTIVE_HIGH (1 << 4)
44#define HDMI_HSYNC_ACTIVE_HIGH (1 << 3)
45/* hdmi-b control bits */
46#define HDMIB_PIPE_B_SELECT (1 << 30)
47
48
49struct mid_intel_hdmi_priv {
50 u32 hdmi_reg;
51 u32 save_HDMIB;
52 bool has_hdmi_sink;
53 bool has_hdmi_audio;
54 /* Should set this when detect hotplug */
55 bool hdmi_device_connected;
56 struct i2c_adapter *hdmi_i2c_adapter; /* for control functions */
57 struct drm_device *dev;
58};
59
60static void cdv_hdmi_mode_set(struct drm_encoder *encoder,
61 struct drm_display_mode *mode,
62 struct drm_display_mode *adjusted_mode)
63{
64 struct drm_device *dev = encoder->dev;
65 struct gma_encoder *gma_encoder = to_gma_encoder(encoder);
66 struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
67 u32 hdmib;
68 struct drm_crtc *crtc = encoder->crtc;
69 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
70
71 hdmib = (2 << 10);
72
73 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
74 hdmib |= HDMI_VSYNC_ACTIVE_HIGH;
75 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
76 hdmib |= HDMI_HSYNC_ACTIVE_HIGH;
77
78 if (gma_crtc->pipe == 1)
79 hdmib |= HDMIB_PIPE_B_SELECT;
80
81 if (hdmi_priv->has_hdmi_audio) {
82 hdmib |= HDMI_AUDIO_ENABLE;
83 hdmib |= HDMI_NULL_PACKETS_DURING_VSYNC;
84 }
85
86 REG_WRITE(hdmi_priv->hdmi_reg, hdmib);
87 REG_READ(hdmi_priv->hdmi_reg);
88}
89
90static void cdv_hdmi_dpms(struct drm_encoder *encoder, int mode)
91{
92 struct drm_device *dev = encoder->dev;
93 struct gma_encoder *gma_encoder = to_gma_encoder(encoder);
94 struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
95 u32 hdmib;
96
97 hdmib = REG_READ(hdmi_priv->hdmi_reg);
98
99 if (mode != DRM_MODE_DPMS_ON)
100 REG_WRITE(hdmi_priv->hdmi_reg, hdmib & ~HDMIB_PORT_EN);
101 else
102 REG_WRITE(hdmi_priv->hdmi_reg, hdmib | HDMIB_PORT_EN);
103 REG_READ(hdmi_priv->hdmi_reg);
104}
105
106static void cdv_hdmi_save(struct drm_connector *connector)
107{
108 struct drm_device *dev = connector->dev;
109 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
110 struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
111
112 hdmi_priv->save_HDMIB = REG_READ(hdmi_priv->hdmi_reg);
113}
114
115static void cdv_hdmi_restore(struct drm_connector *connector)
116{
117 struct drm_device *dev = connector->dev;
118 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
119 struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
120
121 REG_WRITE(hdmi_priv->hdmi_reg, hdmi_priv->save_HDMIB);
122 REG_READ(hdmi_priv->hdmi_reg);
123}
124
125static enum drm_connector_status cdv_hdmi_detect(
126 struct drm_connector *connector, bool force)
127{
128 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
129 struct mid_intel_hdmi_priv *hdmi_priv = gma_encoder->dev_priv;
130 struct edid *edid = NULL;
131 enum drm_connector_status status = connector_status_disconnected;
132
133 edid = drm_get_edid(connector, &gma_encoder->i2c_bus->adapter);
134
135 hdmi_priv->has_hdmi_sink = false;
136 hdmi_priv->has_hdmi_audio = false;
137 if (edid) {
138 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
139 status = connector_status_connected;
140 hdmi_priv->has_hdmi_sink =
141 drm_detect_hdmi_monitor(edid);
142 hdmi_priv->has_hdmi_audio =
143 drm_detect_monitor_audio(edid);
144 }
145 kfree(edid);
146 }
147 return status;
148}
149
150static int cdv_hdmi_set_property(struct drm_connector *connector,
151 struct drm_property *property,
152 uint64_t value)
153{
154 struct drm_encoder *encoder = connector->encoder;
155
156 if (!strcmp(property->name, "scaling mode") && encoder) {
157 struct gma_crtc *crtc = to_gma_crtc(encoder->crtc);
158 bool centre;
159 uint64_t curValue;
160
161 if (!crtc)
162 return -1;
163
164 switch (value) {
165 case DRM_MODE_SCALE_FULLSCREEN:
166 break;
167 case DRM_MODE_SCALE_NO_SCALE:
168 break;
169 case DRM_MODE_SCALE_ASPECT:
170 break;
171 default:
172 return -1;
173 }
174
175 if (drm_object_property_get_value(&connector->base,
176 property, &curValue))
177 return -1;
178
179 if (curValue == value)
180 return 0;
181
182 if (drm_object_property_set_value(&connector->base,
183 property, value))
184 return -1;
185
186 centre = (curValue == DRM_MODE_SCALE_NO_SCALE) ||
187 (value == DRM_MODE_SCALE_NO_SCALE);
188
189 if (crtc->saved_mode.hdisplay != 0 &&
190 crtc->saved_mode.vdisplay != 0) {
191 if (centre) {
192 if (!drm_crtc_helper_set_mode(encoder->crtc, &crtc->saved_mode,
193 encoder->crtc->x, encoder->crtc->y, encoder->crtc->primary->fb))
194 return -1;
195 } else {
196 const struct drm_encoder_helper_funcs *helpers
197 = encoder->helper_private;
198 helpers->mode_set(encoder, &crtc->saved_mode,
199 &crtc->saved_adjusted_mode);
200 }
201 }
202 }
203 return 0;
204}
205
206/*
207 * Return the list of HDMI DDC modes if available.
208 */
209static int cdv_hdmi_get_modes(struct drm_connector *connector)
210{
211 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
212 struct edid *edid = NULL;
213 int ret = 0;
214
215 edid = drm_get_edid(connector, &gma_encoder->i2c_bus->adapter);
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_encoder *gma_encoder = gma_attached_encoder(connector);
246
247 psb_intel_i2c_destroy(gma_encoder->i2c_bus);
248 drm_connector_unregister(connector);
249 drm_connector_cleanup(connector);
250 kfree(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 drm_encoder *encoder;
282 struct mid_intel_hdmi_priv *hdmi_priv;
283 int ddc_bus;
284
285 gma_encoder = kzalloc(sizeof(struct gma_encoder), GFP_KERNEL);
286
287 if (!gma_encoder)
288 return;
289
290 gma_connector = kzalloc(sizeof(struct gma_connector),
291 GFP_KERNEL);
292
293 if (!gma_connector)
294 goto err_connector;
295
296 hdmi_priv = kzalloc(sizeof(struct mid_intel_hdmi_priv), GFP_KERNEL);
297
298 if (!hdmi_priv)
299 goto err_priv;
300
301 connector = &gma_connector->base;
302 connector->polled = DRM_CONNECTOR_POLL_HPD;
303 gma_connector->save = cdv_hdmi_save;
304 gma_connector->restore = cdv_hdmi_restore;
305
306 encoder = &gma_encoder->base;
307 drm_connector_init(dev, connector,
308 &cdv_hdmi_connector_funcs,
309 DRM_MODE_CONNECTOR_DVID);
310
311 drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_TMDS);
312
313 gma_connector_attach_encoder(gma_connector, gma_encoder);
314 gma_encoder->type = INTEL_OUTPUT_HDMI;
315 hdmi_priv->hdmi_reg = reg;
316 hdmi_priv->has_hdmi_sink = false;
317 gma_encoder->dev_priv = hdmi_priv;
318
319 drm_encoder_helper_add(encoder, &cdv_hdmi_helper_funcs);
320 drm_connector_helper_add(connector,
321 &cdv_hdmi_connector_helper_funcs);
322 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
323 connector->interlace_allowed = false;
324 connector->doublescan_allowed = false;
325
326 drm_object_attach_property(&connector->base,
327 dev->mode_config.scaling_mode_property,
328 DRM_MODE_SCALE_FULLSCREEN);
329
330 switch (reg) {
331 case SDVOB:
332 ddc_bus = GPIOE;
333 gma_encoder->ddi_select = DDI0_SELECT;
334 break;
335 case SDVOC:
336 ddc_bus = GPIOD;
337 gma_encoder->ddi_select = DDI1_SELECT;
338 break;
339 default:
340 DRM_ERROR("unknown reg 0x%x for HDMI\n", reg);
341 goto failed_ddc;
342 break;
343 }
344
345 gma_encoder->i2c_bus = psb_intel_i2c_create(dev,
346 ddc_bus, (reg == SDVOB) ? "HDMIB" : "HDMIC");
347
348 if (!gma_encoder->i2c_bus) {
349 dev_err(dev->dev, "No ddc adapter available!\n");
350 goto failed_ddc;
351 }
352
353 hdmi_priv->hdmi_i2c_adapter = &(gma_encoder->i2c_bus->adapter);
354 hdmi_priv->dev = dev;
355 drm_connector_register(connector);
356 return;
357
358failed_ddc:
359 drm_encoder_cleanup(encoder);
360 drm_connector_cleanup(connector);
361err_priv:
362 kfree(gma_connector);
363err_connector:
364 kfree(gma_encoder);
365}