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