blob: ded122c1ae2d5d9d294b0640445b0e11b07c83bd [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2007 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Eric Anholt <eric@anholt.net>
27 */
28#include <linux/i2c.h>
29#include <linux/delay.h>
30#include "drmP.h"
31#include "drm.h"
32#include "drm_crtc.h"
33#include "intel_drv.h"
34#include "i915_drm.h"
35#include "i915_drv.h"
36#include "intel_sdvo_regs.h"
37
38#undef SDVO_DEBUG
39
40struct intel_sdvo_priv {
41 struct intel_i2c_chan *i2c_bus;
42 int slaveaddr;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080043
44 /* Register for the SDVO device: SDVOB or SDVOC */
Jesse Barnes79e53942008-11-07 14:24:08 -080045 int output_device;
46
Jesse Barnese2f0ba92009-02-02 15:11:52 -080047 /* Active outputs controlled by this SDVO output */
48 uint16_t controlled_output;
Jesse Barnes79e53942008-11-07 14:24:08 -080049
Jesse Barnese2f0ba92009-02-02 15:11:52 -080050 /*
51 * Capabilities of the SDVO device returned by
52 * i830_sdvo_get_capabilities()
53 */
Jesse Barnes79e53942008-11-07 14:24:08 -080054 struct intel_sdvo_caps caps;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080055
56 /* Pixel clock limitations reported by the SDVO device, in kHz */
Jesse Barnes79e53942008-11-07 14:24:08 -080057 int pixel_clock_min, pixel_clock_max;
58
Jesse Barnese2f0ba92009-02-02 15:11:52 -080059 /**
60 * This is set if we're going to treat the device as TV-out.
61 *
62 * While we have these nice friendly flags for output types that ought
63 * to decide this for us, the S-Video output on our HDMI+S-Video card
64 * shows up as RGB1 (VGA).
65 */
66 bool is_tv;
67
68 /**
69 * This is set if we treat the device as HDMI, instead of DVI.
70 */
71 bool is_hdmi;
Ma Ling7086c872009-05-13 11:20:06 +080072 /**
73 * This is set if we detect output of sdvo device as LVDS.
74 */
75 bool is_lvds;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080076
77 /**
78 * Returned SDTV resolutions allowed for the current format, if the
79 * device reported it.
80 */
81 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
82
83 /**
84 * Current selected TV format.
85 *
86 * This is stored in the same structure that's passed to the device, for
87 * convenience.
88 */
89 struct intel_sdvo_tv_format tv_format;
90
91 /*
92 * supported encoding mode, used to determine whether HDMI is
93 * supported
94 */
95 struct intel_sdvo_encode encode;
96
97 /* DDC bus used by this SDVO output */
98 uint8_t ddc_bus;
99
Jesse Barnes79e53942008-11-07 14:24:08 -0800100 int save_sdvo_mult;
101 u16 save_active_outputs;
102 struct intel_sdvo_dtd save_input_dtd_1, save_input_dtd_2;
103 struct intel_sdvo_dtd save_output_dtd[16];
104 u32 save_SDVOX;
105};
106
107/**
108 * Writes the SDVOB or SDVOC with the given value, but always writes both
109 * SDVOB and SDVOC to work around apparent hardware issues (according to
110 * comments in the BIOS).
111 */
Hannes Ederb358d0a2008-12-18 21:18:47 +0100112static void intel_sdvo_write_sdvox(struct intel_output *intel_output, u32 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800113{
114 struct drm_device *dev = intel_output->base.dev;
115 struct drm_i915_private *dev_priv = dev->dev_private;
116 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
117 u32 bval = val, cval = val;
118 int i;
119
120 if (sdvo_priv->output_device == SDVOB) {
121 cval = I915_READ(SDVOC);
122 } else {
123 bval = I915_READ(SDVOB);
124 }
125 /*
126 * Write the registers twice for luck. Sometimes,
127 * writing them only once doesn't appear to 'stick'.
128 * The BIOS does this too. Yay, magic
129 */
130 for (i = 0; i < 2; i++)
131 {
132 I915_WRITE(SDVOB, bval);
133 I915_READ(SDVOB);
134 I915_WRITE(SDVOC, cval);
135 I915_READ(SDVOC);
136 }
137}
138
139static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr,
140 u8 *ch)
141{
142 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
143 u8 out_buf[2];
144 u8 buf[2];
145 int ret;
146
147 struct i2c_msg msgs[] = {
148 {
149 .addr = sdvo_priv->i2c_bus->slave_addr,
150 .flags = 0,
151 .len = 1,
152 .buf = out_buf,
153 },
154 {
155 .addr = sdvo_priv->i2c_bus->slave_addr,
156 .flags = I2C_M_RD,
157 .len = 1,
158 .buf = buf,
159 }
160 };
161
162 out_buf[0] = addr;
163 out_buf[1] = 0;
164
165 if ((ret = i2c_transfer(&sdvo_priv->i2c_bus->adapter, msgs, 2)) == 2)
166 {
167 *ch = buf[0];
168 return true;
169 }
170
171 DRM_DEBUG("i2c transfer returned %d\n", ret);
172 return false;
173}
174
175static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr,
176 u8 ch)
177{
178 u8 out_buf[2];
179 struct i2c_msg msgs[] = {
180 {
181 .addr = intel_output->i2c_bus->slave_addr,
182 .flags = 0,
183 .len = 2,
184 .buf = out_buf,
185 }
186 };
187
188 out_buf[0] = addr;
189 out_buf[1] = ch;
190
191 if (i2c_transfer(&intel_output->i2c_bus->adapter, msgs, 1) == 1)
192 {
193 return true;
194 }
195 return false;
196}
197
198#define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
199/** Mapping of command numbers to names, for debug output */
Tobias Klauser005568b2009-02-09 22:02:42 +0100200static const struct _sdvo_cmd_name {
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800201 u8 cmd;
202 char *name;
Jesse Barnes79e53942008-11-07 14:24:08 -0800203} sdvo_cmd_names[] = {
204 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
205 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
206 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
207 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
208 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
209 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
210 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
211 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
212 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
213 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
214 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
215 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
216 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
217 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
218 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
219 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
220 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
221 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
222 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
223 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
224 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
225 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
226 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
227 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
228 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
229 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
230 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
231 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
232 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
233 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
234 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
235 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
236 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
237 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
238 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800239 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
240 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
241 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
242 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
Jesse Barnes79e53942008-11-07 14:24:08 -0800243 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800244 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
245 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
246 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
247 /* HDMI op code */
248 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
249 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
250 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
251 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
252 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
253 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
254 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
255 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
256 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
257 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
258 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
259 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
260 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
261 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
262 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
263 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
264 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
265 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
266 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
267 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
Jesse Barnes79e53942008-11-07 14:24:08 -0800268};
269
270#define SDVO_NAME(dev_priv) ((dev_priv)->output_device == SDVOB ? "SDVOB" : "SDVOC")
271#define SDVO_PRIV(output) ((struct intel_sdvo_priv *) (output)->dev_priv)
272
273#ifdef SDVO_DEBUG
274static void intel_sdvo_debug_write(struct intel_output *intel_output, u8 cmd,
275 void *args, int args_len)
276{
277 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
278 int i;
279
Zhenyu Wang33b52962009-03-24 14:02:40 +0800280 printk(KERN_DEBUG "%s: W: %02X ", SDVO_NAME(sdvo_priv), cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800281 for (i = 0; i < args_len; i++)
Zhenyu Wang33b52962009-03-24 14:02:40 +0800282 printk(KERN_DEBUG "%02X ", ((u8 *)args)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800283 for (; i < 8; i++)
Zhenyu Wang33b52962009-03-24 14:02:40 +0800284 printk(KERN_DEBUG " ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800285 for (i = 0; i < sizeof(sdvo_cmd_names) / sizeof(sdvo_cmd_names[0]); i++) {
286 if (cmd == sdvo_cmd_names[i].cmd) {
Zhenyu Wang33b52962009-03-24 14:02:40 +0800287 printk(KERN_DEBUG "(%s)", sdvo_cmd_names[i].name);
Jesse Barnes79e53942008-11-07 14:24:08 -0800288 break;
289 }
290 }
291 if (i == sizeof(sdvo_cmd_names)/ sizeof(sdvo_cmd_names[0]))
Zhenyu Wang33b52962009-03-24 14:02:40 +0800292 printk(KERN_DEBUG "(%02X)", cmd);
293 printk(KERN_DEBUG "\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800294}
295#else
296#define intel_sdvo_debug_write(o, c, a, l)
297#endif
298
299static void intel_sdvo_write_cmd(struct intel_output *intel_output, u8 cmd,
300 void *args, int args_len)
301{
302 int i;
303
304 intel_sdvo_debug_write(intel_output, cmd, args, args_len);
305
306 for (i = 0; i < args_len; i++) {
307 intel_sdvo_write_byte(intel_output, SDVO_I2C_ARG_0 - i,
308 ((u8*)args)[i]);
309 }
310
311 intel_sdvo_write_byte(intel_output, SDVO_I2C_OPCODE, cmd);
312}
313
314#ifdef SDVO_DEBUG
315static const char *cmd_status_names[] = {
316 "Power on",
317 "Success",
318 "Not supported",
319 "Invalid arg",
320 "Pending",
321 "Target not specified",
322 "Scaling not supported"
323};
324
325static void intel_sdvo_debug_response(struct intel_output *intel_output,
326 void *response, int response_len,
327 u8 status)
328{
329 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
Zhenyu Wang33b52962009-03-24 14:02:40 +0800330 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -0800331
Zhenyu Wang33b52962009-03-24 14:02:40 +0800332 printk(KERN_DEBUG "%s: R: ", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -0800333 for (i = 0; i < response_len; i++)
Zhenyu Wang33b52962009-03-24 14:02:40 +0800334 printk(KERN_DEBUG "%02X ", ((u8 *)response)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800335 for (; i < 8; i++)
Zhenyu Wang33b52962009-03-24 14:02:40 +0800336 printk(KERN_DEBUG " ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800337 if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
Zhenyu Wang33b52962009-03-24 14:02:40 +0800338 printk(KERN_DEBUG "(%s)", cmd_status_names[status]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800339 else
Zhenyu Wang33b52962009-03-24 14:02:40 +0800340 printk(KERN_DEBUG "(??? %d)", status);
341 printk(KERN_DEBUG "\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800342}
343#else
344#define intel_sdvo_debug_response(o, r, l, s)
345#endif
346
347static u8 intel_sdvo_read_response(struct intel_output *intel_output,
348 void *response, int response_len)
349{
350 int i;
351 u8 status;
352 u8 retry = 50;
353
354 while (retry--) {
355 /* Read the command response */
356 for (i = 0; i < response_len; i++) {
357 intel_sdvo_read_byte(intel_output,
358 SDVO_I2C_RETURN_0 + i,
359 &((u8 *)response)[i]);
360 }
361
362 /* read the return status */
363 intel_sdvo_read_byte(intel_output, SDVO_I2C_CMD_STATUS,
364 &status);
365
366 intel_sdvo_debug_response(intel_output, response, response_len,
367 status);
368 if (status != SDVO_CMD_STATUS_PENDING)
369 return status;
370
371 mdelay(50);
372 }
373
374 return status;
375}
376
Hannes Ederb358d0a2008-12-18 21:18:47 +0100377static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800378{
379 if (mode->clock >= 100000)
380 return 1;
381 else if (mode->clock >= 50000)
382 return 2;
383 else
384 return 4;
385}
386
387/**
388 * Don't check status code from this as it switches the bus back to the
389 * SDVO chips which defeats the purpose of doing a bus switch in the first
390 * place.
391 */
Hannes Ederb358d0a2008-12-18 21:18:47 +0100392static void intel_sdvo_set_control_bus_switch(struct intel_output *intel_output,
393 u8 target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800394{
395 intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_CONTROL_BUS_SWITCH, &target, 1);
396}
397
398static bool intel_sdvo_set_target_input(struct intel_output *intel_output, bool target_0, bool target_1)
399{
400 struct intel_sdvo_set_target_input_args targets = {0};
401 u8 status;
402
403 if (target_0 && target_1)
404 return SDVO_CMD_STATUS_NOTSUPP;
405
406 if (target_1)
407 targets.target_1 = 1;
408
409 intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_TARGET_INPUT, &targets,
410 sizeof(targets));
411
412 status = intel_sdvo_read_response(intel_output, NULL, 0);
413
414 return (status == SDVO_CMD_STATUS_SUCCESS);
415}
416
417/**
418 * Return whether each input is trained.
419 *
420 * This function is making an assumption about the layout of the response,
421 * which should be checked against the docs.
422 */
423static bool intel_sdvo_get_trained_inputs(struct intel_output *intel_output, bool *input_1, bool *input_2)
424{
425 struct intel_sdvo_get_trained_inputs_response response;
426 u8 status;
427
428 intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0);
429 status = intel_sdvo_read_response(intel_output, &response, sizeof(response));
430 if (status != SDVO_CMD_STATUS_SUCCESS)
431 return false;
432
433 *input_1 = response.input0_trained;
434 *input_2 = response.input1_trained;
435 return true;
436}
437
438static bool intel_sdvo_get_active_outputs(struct intel_output *intel_output,
439 u16 *outputs)
440{
441 u8 status;
442
443 intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_OUTPUTS, NULL, 0);
444 status = intel_sdvo_read_response(intel_output, outputs, sizeof(*outputs));
445
446 return (status == SDVO_CMD_STATUS_SUCCESS);
447}
448
449static bool intel_sdvo_set_active_outputs(struct intel_output *intel_output,
450 u16 outputs)
451{
452 u8 status;
453
454 intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs,
455 sizeof(outputs));
456 status = intel_sdvo_read_response(intel_output, NULL, 0);
457 return (status == SDVO_CMD_STATUS_SUCCESS);
458}
459
460static bool intel_sdvo_set_encoder_power_state(struct intel_output *intel_output,
461 int mode)
462{
463 u8 status, state = SDVO_ENCODER_STATE_ON;
464
465 switch (mode) {
466 case DRM_MODE_DPMS_ON:
467 state = SDVO_ENCODER_STATE_ON;
468 break;
469 case DRM_MODE_DPMS_STANDBY:
470 state = SDVO_ENCODER_STATE_STANDBY;
471 break;
472 case DRM_MODE_DPMS_SUSPEND:
473 state = SDVO_ENCODER_STATE_SUSPEND;
474 break;
475 case DRM_MODE_DPMS_OFF:
476 state = SDVO_ENCODER_STATE_OFF;
477 break;
478 }
479
480 intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ENCODER_POWER_STATE, &state,
481 sizeof(state));
482 status = intel_sdvo_read_response(intel_output, NULL, 0);
483
484 return (status == SDVO_CMD_STATUS_SUCCESS);
485}
486
487static bool intel_sdvo_get_input_pixel_clock_range(struct intel_output *intel_output,
488 int *clock_min,
489 int *clock_max)
490{
491 struct intel_sdvo_pixel_clock_range clocks;
492 u8 status;
493
494 intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
495 NULL, 0);
496
497 status = intel_sdvo_read_response(intel_output, &clocks, sizeof(clocks));
498
499 if (status != SDVO_CMD_STATUS_SUCCESS)
500 return false;
501
502 /* Convert the values from units of 10 kHz to kHz. */
503 *clock_min = clocks.min * 10;
504 *clock_max = clocks.max * 10;
505
506 return true;
507}
508
509static bool intel_sdvo_set_target_output(struct intel_output *intel_output,
510 u16 outputs)
511{
512 u8 status;
513
514 intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_TARGET_OUTPUT, &outputs,
515 sizeof(outputs));
516
517 status = intel_sdvo_read_response(intel_output, NULL, 0);
518 return (status == SDVO_CMD_STATUS_SUCCESS);
519}
520
521static bool intel_sdvo_get_timing(struct intel_output *intel_output, u8 cmd,
522 struct intel_sdvo_dtd *dtd)
523{
524 u8 status;
525
526 intel_sdvo_write_cmd(intel_output, cmd, NULL, 0);
527 status = intel_sdvo_read_response(intel_output, &dtd->part1,
528 sizeof(dtd->part1));
529 if (status != SDVO_CMD_STATUS_SUCCESS)
530 return false;
531
532 intel_sdvo_write_cmd(intel_output, cmd + 1, NULL, 0);
533 status = intel_sdvo_read_response(intel_output, &dtd->part2,
534 sizeof(dtd->part2));
535 if (status != SDVO_CMD_STATUS_SUCCESS)
536 return false;
537
538 return true;
539}
540
541static bool intel_sdvo_get_input_timing(struct intel_output *intel_output,
542 struct intel_sdvo_dtd *dtd)
543{
544 return intel_sdvo_get_timing(intel_output,
545 SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
546}
547
548static bool intel_sdvo_get_output_timing(struct intel_output *intel_output,
549 struct intel_sdvo_dtd *dtd)
550{
551 return intel_sdvo_get_timing(intel_output,
552 SDVO_CMD_GET_OUTPUT_TIMINGS_PART1, dtd);
553}
554
555static bool intel_sdvo_set_timing(struct intel_output *intel_output, u8 cmd,
556 struct intel_sdvo_dtd *dtd)
557{
558 u8 status;
559
560 intel_sdvo_write_cmd(intel_output, cmd, &dtd->part1, sizeof(dtd->part1));
561 status = intel_sdvo_read_response(intel_output, NULL, 0);
562 if (status != SDVO_CMD_STATUS_SUCCESS)
563 return false;
564
565 intel_sdvo_write_cmd(intel_output, cmd + 1, &dtd->part2, sizeof(dtd->part2));
566 status = intel_sdvo_read_response(intel_output, NULL, 0);
567 if (status != SDVO_CMD_STATUS_SUCCESS)
568 return false;
569
570 return true;
571}
572
573static bool intel_sdvo_set_input_timing(struct intel_output *intel_output,
574 struct intel_sdvo_dtd *dtd)
575{
576 return intel_sdvo_set_timing(intel_output,
577 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
578}
579
580static bool intel_sdvo_set_output_timing(struct intel_output *intel_output,
581 struct intel_sdvo_dtd *dtd)
582{
583 return intel_sdvo_set_timing(intel_output,
584 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
585}
586
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800587static bool
588intel_sdvo_create_preferred_input_timing(struct intel_output *output,
589 uint16_t clock,
590 uint16_t width,
591 uint16_t height)
592{
593 struct intel_sdvo_preferred_input_timing_args args;
594 uint8_t status;
595
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800596 memset(&args, 0, sizeof(args));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800597 args.clock = clock;
598 args.width = width;
599 args.height = height;
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800600 args.interlace = 0;
601 args.scaled = 0;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800602 intel_sdvo_write_cmd(output, SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
603 &args, sizeof(args));
604 status = intel_sdvo_read_response(output, NULL, 0);
605 if (status != SDVO_CMD_STATUS_SUCCESS)
606 return false;
607
608 return true;
609}
610
611static bool intel_sdvo_get_preferred_input_timing(struct intel_output *output,
612 struct intel_sdvo_dtd *dtd)
613{
614 bool status;
615
616 intel_sdvo_write_cmd(output, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
617 NULL, 0);
618
619 status = intel_sdvo_read_response(output, &dtd->part1,
620 sizeof(dtd->part1));
621 if (status != SDVO_CMD_STATUS_SUCCESS)
622 return false;
623
624 intel_sdvo_write_cmd(output, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
625 NULL, 0);
626
627 status = intel_sdvo_read_response(output, &dtd->part2,
628 sizeof(dtd->part2));
629 if (status != SDVO_CMD_STATUS_SUCCESS)
630 return false;
631
632 return false;
633}
Jesse Barnes79e53942008-11-07 14:24:08 -0800634
635static int intel_sdvo_get_clock_rate_mult(struct intel_output *intel_output)
636{
637 u8 response, status;
638
639 intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_CLOCK_RATE_MULT, NULL, 0);
640 status = intel_sdvo_read_response(intel_output, &response, 1);
641
642 if (status != SDVO_CMD_STATUS_SUCCESS) {
643 DRM_DEBUG("Couldn't get SDVO clock rate multiplier\n");
644 return SDVO_CLOCK_RATE_MULT_1X;
645 } else {
646 DRM_DEBUG("Current clock rate multiplier: %d\n", response);
647 }
648
649 return response;
650}
651
652static bool intel_sdvo_set_clock_rate_mult(struct intel_output *intel_output, u8 val)
653{
654 u8 status;
655
656 intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
657 status = intel_sdvo_read_response(intel_output, NULL, 0);
658 if (status != SDVO_CMD_STATUS_SUCCESS)
659 return false;
660
661 return true;
662}
663
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800664static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
665 struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800666{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800667 uint16_t width, height;
668 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
669 uint16_t h_sync_offset, v_sync_offset;
Jesse Barnes79e53942008-11-07 14:24:08 -0800670
671 width = mode->crtc_hdisplay;
672 height = mode->crtc_vdisplay;
673
674 /* do some mode translations */
675 h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start;
676 h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
677
678 v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start;
679 v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
680
681 h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start;
682 v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start;
683
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800684 dtd->part1.clock = mode->clock / 10;
685 dtd->part1.h_active = width & 0xff;
686 dtd->part1.h_blank = h_blank_len & 0xff;
687 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800688 ((h_blank_len >> 8) & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800689 dtd->part1.v_active = height & 0xff;
690 dtd->part1.v_blank = v_blank_len & 0xff;
691 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800692 ((v_blank_len >> 8) & 0xf);
693
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800694 dtd->part2.h_sync_off = h_sync_offset & 0xff;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800695 dtd->part2.h_sync_width = h_sync_len & 0xff;
696 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
Jesse Barnes79e53942008-11-07 14:24:08 -0800697 (v_sync_len & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800698 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800699 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
700 ((v_sync_len & 0x30) >> 4);
701
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800702 dtd->part2.dtd_flags = 0x18;
Jesse Barnes79e53942008-11-07 14:24:08 -0800703 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800704 dtd->part2.dtd_flags |= 0x2;
Jesse Barnes79e53942008-11-07 14:24:08 -0800705 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800706 dtd->part2.dtd_flags |= 0x4;
Jesse Barnes79e53942008-11-07 14:24:08 -0800707
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800708 dtd->part2.sdvo_flags = 0;
709 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
710 dtd->part2.reserved = 0;
711}
Jesse Barnes79e53942008-11-07 14:24:08 -0800712
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800713static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
714 struct intel_sdvo_dtd *dtd)
715{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800716 mode->hdisplay = dtd->part1.h_active;
717 mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
718 mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800719 mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800720 mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
721 mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
722 mode->htotal = mode->hdisplay + dtd->part1.h_blank;
723 mode->htotal += (dtd->part1.h_high & 0xf) << 8;
724
725 mode->vdisplay = dtd->part1.v_active;
726 mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
727 mode->vsync_start = mode->vdisplay;
728 mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800729 mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800730 mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
731 mode->vsync_end = mode->vsync_start +
732 (dtd->part2.v_sync_off_width & 0xf);
733 mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
734 mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
735 mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
736
737 mode->clock = dtd->part1.clock * 10;
738
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800739 mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800740 if (dtd->part2.dtd_flags & 0x2)
741 mode->flags |= DRM_MODE_FLAG_PHSYNC;
742 if (dtd->part2.dtd_flags & 0x4)
743 mode->flags |= DRM_MODE_FLAG_PVSYNC;
744}
745
746static bool intel_sdvo_get_supp_encode(struct intel_output *output,
747 struct intel_sdvo_encode *encode)
748{
749 uint8_t status;
750
751 intel_sdvo_write_cmd(output, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0);
752 status = intel_sdvo_read_response(output, encode, sizeof(*encode));
753 if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */
754 memset(encode, 0, sizeof(*encode));
755 return false;
756 }
757
758 return true;
759}
760
761static bool intel_sdvo_set_encode(struct intel_output *output, uint8_t mode)
762{
763 uint8_t status;
764
765 intel_sdvo_write_cmd(output, SDVO_CMD_SET_ENCODE, &mode, 1);
766 status = intel_sdvo_read_response(output, NULL, 0);
767
768 return (status == SDVO_CMD_STATUS_SUCCESS);
769}
770
771static bool intel_sdvo_set_colorimetry(struct intel_output *output,
772 uint8_t mode)
773{
774 uint8_t status;
775
776 intel_sdvo_write_cmd(output, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
777 status = intel_sdvo_read_response(output, NULL, 0);
778
779 return (status == SDVO_CMD_STATUS_SUCCESS);
780}
781
782#if 0
783static void intel_sdvo_dump_hdmi_buf(struct intel_output *output)
784{
785 int i, j;
786 uint8_t set_buf_index[2];
787 uint8_t av_split;
788 uint8_t buf_size;
789 uint8_t buf[48];
790 uint8_t *pos;
791
792 intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0);
793 intel_sdvo_read_response(output, &av_split, 1);
794
795 for (i = 0; i <= av_split; i++) {
796 set_buf_index[0] = i; set_buf_index[1] = 0;
797 intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_INDEX,
798 set_buf_index, 2);
799 intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
800 intel_sdvo_read_response(output, &buf_size, 1);
801
802 pos = buf;
803 for (j = 0; j <= buf_size; j += 8) {
804 intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_DATA,
805 NULL, 0);
806 intel_sdvo_read_response(output, pos, 8);
807 pos += 8;
808 }
809 }
810}
811#endif
812
813static void intel_sdvo_set_hdmi_buf(struct intel_output *output, int index,
814 uint8_t *data, int8_t size, uint8_t tx_rate)
815{
816 uint8_t set_buf_index[2];
817
818 set_buf_index[0] = index;
819 set_buf_index[1] = 0;
820
821 intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_INDEX, set_buf_index, 2);
822
823 for (; size > 0; size -= 8) {
824 intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_DATA, data, 8);
825 data += 8;
826 }
827
828 intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1);
829}
830
831static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size)
832{
833 uint8_t csum = 0;
834 int i;
835
836 for (i = 0; i < size; i++)
837 csum += data[i];
838
839 return 0x100 - csum;
840}
841
842#define DIP_TYPE_AVI 0x82
843#define DIP_VERSION_AVI 0x2
844#define DIP_LEN_AVI 13
845
846struct dip_infoframe {
847 uint8_t type;
848 uint8_t version;
849 uint8_t len;
850 uint8_t checksum;
851 union {
852 struct {
853 /* Packet Byte #1 */
854 uint8_t S:2;
855 uint8_t B:2;
856 uint8_t A:1;
857 uint8_t Y:2;
858 uint8_t rsvd1:1;
859 /* Packet Byte #2 */
860 uint8_t R:4;
861 uint8_t M:2;
862 uint8_t C:2;
863 /* Packet Byte #3 */
864 uint8_t SC:2;
865 uint8_t Q:2;
866 uint8_t EC:3;
867 uint8_t ITC:1;
868 /* Packet Byte #4 */
869 uint8_t VIC:7;
870 uint8_t rsvd2:1;
871 /* Packet Byte #5 */
872 uint8_t PR:4;
873 uint8_t rsvd3:4;
874 /* Packet Byte #6~13 */
875 uint16_t top_bar_end;
876 uint16_t bottom_bar_start;
877 uint16_t left_bar_end;
878 uint16_t right_bar_start;
879 } avi;
880 struct {
881 /* Packet Byte #1 */
882 uint8_t channel_count:3;
883 uint8_t rsvd1:1;
884 uint8_t coding_type:4;
885 /* Packet Byte #2 */
886 uint8_t sample_size:2; /* SS0, SS1 */
887 uint8_t sample_frequency:3;
888 uint8_t rsvd2:3;
889 /* Packet Byte #3 */
890 uint8_t coding_type_private:5;
891 uint8_t rsvd3:3;
892 /* Packet Byte #4 */
893 uint8_t channel_allocation;
894 /* Packet Byte #5 */
895 uint8_t rsvd4:3;
896 uint8_t level_shift:4;
897 uint8_t downmix_inhibit:1;
898 } audio;
899 uint8_t payload[28];
900 } __attribute__ ((packed)) u;
901} __attribute__((packed));
902
903static void intel_sdvo_set_avi_infoframe(struct intel_output *output,
904 struct drm_display_mode * mode)
905{
906 struct dip_infoframe avi_if = {
907 .type = DIP_TYPE_AVI,
908 .version = DIP_VERSION_AVI,
909 .len = DIP_LEN_AVI,
910 };
911
912 avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if,
913 4 + avi_if.len);
914 intel_sdvo_set_hdmi_buf(output, 1, (uint8_t *)&avi_if, 4 + avi_if.len,
915 SDVO_HBUF_TX_VSYNC);
916}
917
Zhenyu Wang7026d4a2009-03-24 14:02:43 +0800918static void intel_sdvo_set_tv_format(struct intel_output *output)
919{
920 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
921 struct intel_sdvo_tv_format *format, unset;
922 u8 status;
923
924 format = &sdvo_priv->tv_format;
925 memset(&unset, 0, sizeof(unset));
926 if (memcmp(format, &unset, sizeof(*format))) {
927 DRM_DEBUG("%s: Choosing default TV format of NTSC-M\n",
928 SDVO_NAME(sdvo_priv));
929 format->ntsc_m = 1;
930 intel_sdvo_write_cmd(output, SDVO_CMD_SET_TV_FORMAT, format,
931 sizeof(*format));
932 status = intel_sdvo_read_response(output, NULL, 0);
933 if (status != SDVO_CMD_STATUS_SUCCESS)
934 DRM_DEBUG("%s: Failed to set TV format\n",
935 SDVO_NAME(sdvo_priv));
936 }
937}
938
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800939static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
940 struct drm_display_mode *mode,
941 struct drm_display_mode *adjusted_mode)
942{
943 struct intel_output *output = enc_to_intel_output(encoder);
944 struct intel_sdvo_priv *dev_priv = output->dev_priv;
945
946 if (!dev_priv->is_tv) {
947 /* Make the CRTC code factor in the SDVO pixel multiplier. The
948 * SDVO device will be told of the multiplier during mode_set.
949 */
950 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
951 } else {
952 struct intel_sdvo_dtd output_dtd;
953 bool success;
954
955 /* We need to construct preferred input timings based on our
956 * output timings. To do that, we have to set the output
957 * timings, even though this isn't really the right place in
958 * the sequence to do it. Oh well.
959 */
960
961
962 /* Set output timings */
963 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
964 intel_sdvo_set_target_output(output,
965 dev_priv->controlled_output);
966 intel_sdvo_set_output_timing(output, &output_dtd);
967
968 /* Set the input timing to the screen. Assume always input 0. */
969 intel_sdvo_set_target_input(output, true, false);
970
971
972 success = intel_sdvo_create_preferred_input_timing(output,
973 mode->clock / 10,
974 mode->hdisplay,
975 mode->vdisplay);
976 if (success) {
977 struct intel_sdvo_dtd input_dtd;
978
979 intel_sdvo_get_preferred_input_timing(output,
980 &input_dtd);
981 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
982
Zhenyu Wang7026d4a2009-03-24 14:02:43 +0800983 drm_mode_set_crtcinfo(adjusted_mode, 0);
984
985 mode->clock = adjusted_mode->clock;
986
987 adjusted_mode->clock *=
988 intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800989 } else {
990 return false;
991 }
992 }
993 return true;
994}
995
996static void intel_sdvo_mode_set(struct drm_encoder *encoder,
997 struct drm_display_mode *mode,
998 struct drm_display_mode *adjusted_mode)
999{
1000 struct drm_device *dev = encoder->dev;
1001 struct drm_i915_private *dev_priv = dev->dev_private;
1002 struct drm_crtc *crtc = encoder->crtc;
1003 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1004 struct intel_output *output = enc_to_intel_output(encoder);
1005 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
1006 u32 sdvox = 0;
1007 int sdvo_pixel_multiply;
1008 struct intel_sdvo_in_out_map in_out;
1009 struct intel_sdvo_dtd input_dtd;
1010 u8 status;
1011
1012 if (!mode)
1013 return;
1014
1015 /* First, set the input mapping for the first input to our controlled
1016 * output. This is only correct if we're a single-input device, in
1017 * which case the first input is the output from the appropriate SDVO
1018 * channel on the motherboard. In a two-input device, the first input
1019 * will be SDVOB and the second SDVOC.
1020 */
1021 in_out.in0 = sdvo_priv->controlled_output;
1022 in_out.in1 = 0;
1023
1024 intel_sdvo_write_cmd(output, SDVO_CMD_SET_IN_OUT_MAP,
1025 &in_out, sizeof(in_out));
1026 status = intel_sdvo_read_response(output, NULL, 0);
1027
1028 if (sdvo_priv->is_hdmi) {
1029 intel_sdvo_set_avi_infoframe(output, mode);
1030 sdvox |= SDVO_AUDIO_ENABLE;
1031 }
1032
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001033 /* We have tried to get input timing in mode_fixup, and filled into
1034 adjusted_mode */
1035 if (sdvo_priv->is_tv)
1036 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
1037 else
1038 intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001039
1040 /* If it's a TV, we already set the output timing in mode_fixup.
1041 * Otherwise, the output timing is equal to the input timing.
1042 */
1043 if (!sdvo_priv->is_tv) {
1044 /* Set the output timing to the screen */
1045 intel_sdvo_set_target_output(output,
1046 sdvo_priv->controlled_output);
1047 intel_sdvo_set_output_timing(output, &input_dtd);
1048 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001049
1050 /* Set the input timing to the screen. Assume always input 0. */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001051 intel_sdvo_set_target_input(output, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08001052
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001053 if (sdvo_priv->is_tv)
1054 intel_sdvo_set_tv_format(output);
1055
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001056 /* We would like to use intel_sdvo_create_preferred_input_timing() to
Jesse Barnes79e53942008-11-07 14:24:08 -08001057 * provide the device with a timing it can support, if it supports that
1058 * feature. However, presumably we would need to adjust the CRTC to
1059 * output the preferred timing, and we don't support that currently.
1060 */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001061#if 0
1062 success = intel_sdvo_create_preferred_input_timing(output, clock,
1063 width, height);
1064 if (success) {
1065 struct intel_sdvo_dtd *input_dtd;
1066
1067 intel_sdvo_get_preferred_input_timing(output, &input_dtd);
1068 intel_sdvo_set_input_timing(output, &input_dtd);
1069 }
1070#else
1071 intel_sdvo_set_input_timing(output, &input_dtd);
1072#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001073
1074 switch (intel_sdvo_get_pixel_multiplier(mode)) {
1075 case 1:
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001076 intel_sdvo_set_clock_rate_mult(output,
Jesse Barnes79e53942008-11-07 14:24:08 -08001077 SDVO_CLOCK_RATE_MULT_1X);
1078 break;
1079 case 2:
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001080 intel_sdvo_set_clock_rate_mult(output,
Jesse Barnes79e53942008-11-07 14:24:08 -08001081 SDVO_CLOCK_RATE_MULT_2X);
1082 break;
1083 case 4:
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001084 intel_sdvo_set_clock_rate_mult(output,
Jesse Barnes79e53942008-11-07 14:24:08 -08001085 SDVO_CLOCK_RATE_MULT_4X);
1086 break;
1087 }
1088
1089 /* Set the SDVO control regs. */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001090 if (IS_I965G(dev)) {
1091 sdvox |= SDVO_BORDER_ENABLE |
1092 SDVO_VSYNC_ACTIVE_HIGH |
1093 SDVO_HSYNC_ACTIVE_HIGH;
1094 } else {
1095 sdvox |= I915_READ(sdvo_priv->output_device);
1096 switch (sdvo_priv->output_device) {
1097 case SDVOB:
1098 sdvox &= SDVOB_PRESERVE_MASK;
1099 break;
1100 case SDVOC:
1101 sdvox &= SDVOC_PRESERVE_MASK;
1102 break;
1103 }
1104 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1105 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001106 if (intel_crtc->pipe == 1)
1107 sdvox |= SDVO_PIPE_B_SELECT;
1108
1109 sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
1110 if (IS_I965G(dev)) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001111 /* done in crtc_mode_set as the dpll_md reg must be written early */
1112 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
1113 /* done in crtc_mode_set as it lives inside the dpll register */
Jesse Barnes79e53942008-11-07 14:24:08 -08001114 } else {
1115 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
1116 }
1117
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001118 intel_sdvo_write_sdvox(output, sdvox);
Jesse Barnes79e53942008-11-07 14:24:08 -08001119}
1120
1121static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1122{
1123 struct drm_device *dev = encoder->dev;
1124 struct drm_i915_private *dev_priv = dev->dev_private;
1125 struct intel_output *intel_output = enc_to_intel_output(encoder);
1126 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1127 u32 temp;
1128
1129 if (mode != DRM_MODE_DPMS_ON) {
1130 intel_sdvo_set_active_outputs(intel_output, 0);
1131 if (0)
1132 intel_sdvo_set_encoder_power_state(intel_output, mode);
1133
1134 if (mode == DRM_MODE_DPMS_OFF) {
1135 temp = I915_READ(sdvo_priv->output_device);
1136 if ((temp & SDVO_ENABLE) != 0) {
1137 intel_sdvo_write_sdvox(intel_output, temp & ~SDVO_ENABLE);
1138 }
1139 }
1140 } else {
1141 bool input1, input2;
1142 int i;
1143 u8 status;
1144
1145 temp = I915_READ(sdvo_priv->output_device);
1146 if ((temp & SDVO_ENABLE) == 0)
1147 intel_sdvo_write_sdvox(intel_output, temp | SDVO_ENABLE);
1148 for (i = 0; i < 2; i++)
1149 intel_wait_for_vblank(dev);
1150
1151 status = intel_sdvo_get_trained_inputs(intel_output, &input1,
1152 &input2);
1153
1154
1155 /* Warn if the device reported failure to sync.
1156 * A lot of SDVO devices fail to notify of sync, but it's
1157 * a given it the status is a success, we succeeded.
1158 */
1159 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
1160 DRM_DEBUG("First %s output reported failure to sync\n",
1161 SDVO_NAME(sdvo_priv));
1162 }
1163
1164 if (0)
1165 intel_sdvo_set_encoder_power_state(intel_output, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001166 intel_sdvo_set_active_outputs(intel_output, sdvo_priv->controlled_output);
Jesse Barnes79e53942008-11-07 14:24:08 -08001167 }
1168 return;
1169}
1170
1171static void intel_sdvo_save(struct drm_connector *connector)
1172{
1173 struct drm_device *dev = connector->dev;
1174 struct drm_i915_private *dev_priv = dev->dev_private;
1175 struct intel_output *intel_output = to_intel_output(connector);
1176 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1177 int o;
1178
1179 sdvo_priv->save_sdvo_mult = intel_sdvo_get_clock_rate_mult(intel_output);
1180 intel_sdvo_get_active_outputs(intel_output, &sdvo_priv->save_active_outputs);
1181
1182 if (sdvo_priv->caps.sdvo_inputs_mask & 0x1) {
1183 intel_sdvo_set_target_input(intel_output, true, false);
1184 intel_sdvo_get_input_timing(intel_output,
1185 &sdvo_priv->save_input_dtd_1);
1186 }
1187
1188 if (sdvo_priv->caps.sdvo_inputs_mask & 0x2) {
1189 intel_sdvo_set_target_input(intel_output, false, true);
1190 intel_sdvo_get_input_timing(intel_output,
1191 &sdvo_priv->save_input_dtd_2);
1192 }
1193
1194 for (o = SDVO_OUTPUT_FIRST; o <= SDVO_OUTPUT_LAST; o++)
1195 {
1196 u16 this_output = (1 << o);
1197 if (sdvo_priv->caps.output_flags & this_output)
1198 {
1199 intel_sdvo_set_target_output(intel_output, this_output);
1200 intel_sdvo_get_output_timing(intel_output,
1201 &sdvo_priv->save_output_dtd[o]);
1202 }
1203 }
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001204 if (sdvo_priv->is_tv) {
1205 /* XXX: Save TV format/enhancements. */
1206 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001207
1208 sdvo_priv->save_SDVOX = I915_READ(sdvo_priv->output_device);
1209}
1210
1211static void intel_sdvo_restore(struct drm_connector *connector)
1212{
1213 struct drm_device *dev = connector->dev;
Jesse Barnes79e53942008-11-07 14:24:08 -08001214 struct intel_output *intel_output = to_intel_output(connector);
1215 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1216 int o;
1217 int i;
1218 bool input1, input2;
1219 u8 status;
1220
1221 intel_sdvo_set_active_outputs(intel_output, 0);
1222
1223 for (o = SDVO_OUTPUT_FIRST; o <= SDVO_OUTPUT_LAST; o++)
1224 {
1225 u16 this_output = (1 << o);
1226 if (sdvo_priv->caps.output_flags & this_output) {
1227 intel_sdvo_set_target_output(intel_output, this_output);
1228 intel_sdvo_set_output_timing(intel_output, &sdvo_priv->save_output_dtd[o]);
1229 }
1230 }
1231
1232 if (sdvo_priv->caps.sdvo_inputs_mask & 0x1) {
1233 intel_sdvo_set_target_input(intel_output, true, false);
1234 intel_sdvo_set_input_timing(intel_output, &sdvo_priv->save_input_dtd_1);
1235 }
1236
1237 if (sdvo_priv->caps.sdvo_inputs_mask & 0x2) {
1238 intel_sdvo_set_target_input(intel_output, false, true);
1239 intel_sdvo_set_input_timing(intel_output, &sdvo_priv->save_input_dtd_2);
1240 }
1241
1242 intel_sdvo_set_clock_rate_mult(intel_output, sdvo_priv->save_sdvo_mult);
1243
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001244 if (sdvo_priv->is_tv) {
1245 /* XXX: Restore TV format/enhancements. */
1246 }
1247
1248 intel_sdvo_write_sdvox(intel_output, sdvo_priv->save_SDVOX);
Jesse Barnes79e53942008-11-07 14:24:08 -08001249
1250 if (sdvo_priv->save_SDVOX & SDVO_ENABLE)
1251 {
1252 for (i = 0; i < 2; i++)
1253 intel_wait_for_vblank(dev);
1254 status = intel_sdvo_get_trained_inputs(intel_output, &input1, &input2);
1255 if (status == SDVO_CMD_STATUS_SUCCESS && !input1)
1256 DRM_DEBUG("First %s output reported failure to sync\n",
1257 SDVO_NAME(sdvo_priv));
1258 }
1259
1260 intel_sdvo_set_active_outputs(intel_output, sdvo_priv->save_active_outputs);
1261}
1262
1263static int intel_sdvo_mode_valid(struct drm_connector *connector,
1264 struct drm_display_mode *mode)
1265{
1266 struct intel_output *intel_output = to_intel_output(connector);
1267 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1268
1269 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1270 return MODE_NO_DBLESCAN;
1271
1272 if (sdvo_priv->pixel_clock_min > mode->clock)
1273 return MODE_CLOCK_LOW;
1274
1275 if (sdvo_priv->pixel_clock_max < mode->clock)
1276 return MODE_CLOCK_HIGH;
1277
1278 return MODE_OK;
1279}
1280
1281static bool intel_sdvo_get_capabilities(struct intel_output *intel_output, struct intel_sdvo_caps *caps)
1282{
1283 u8 status;
1284
1285 intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0);
1286 status = intel_sdvo_read_response(intel_output, caps, sizeof(*caps));
1287 if (status != SDVO_CMD_STATUS_SUCCESS)
1288 return false;
1289
1290 return true;
1291}
1292
1293struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB)
1294{
1295 struct drm_connector *connector = NULL;
1296 struct intel_output *iout = NULL;
1297 struct intel_sdvo_priv *sdvo;
1298
1299 /* find the sdvo connector */
1300 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1301 iout = to_intel_output(connector);
1302
1303 if (iout->type != INTEL_OUTPUT_SDVO)
1304 continue;
1305
1306 sdvo = iout->dev_priv;
1307
1308 if (sdvo->output_device == SDVOB && sdvoB)
1309 return connector;
1310
1311 if (sdvo->output_device == SDVOC && !sdvoB)
1312 return connector;
1313
1314 }
1315
1316 return NULL;
1317}
1318
1319int intel_sdvo_supports_hotplug(struct drm_connector *connector)
1320{
1321 u8 response[2];
1322 u8 status;
1323 struct intel_output *intel_output;
1324 DRM_DEBUG("\n");
1325
1326 if (!connector)
1327 return 0;
1328
1329 intel_output = to_intel_output(connector);
1330
1331 intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1332 status = intel_sdvo_read_response(intel_output, &response, 2);
1333
1334 if (response[0] !=0)
1335 return 1;
1336
1337 return 0;
1338}
1339
1340void intel_sdvo_set_hotplug(struct drm_connector *connector, int on)
1341{
1342 u8 response[2];
1343 u8 status;
1344 struct intel_output *intel_output = to_intel_output(connector);
1345
1346 intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1347 intel_sdvo_read_response(intel_output, &response, 2);
1348
1349 if (on) {
1350 intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1351 status = intel_sdvo_read_response(intel_output, &response, 2);
1352
1353 intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
1354 } else {
1355 response[0] = 0;
1356 response[1] = 0;
1357 intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
1358 }
1359
1360 intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1361 intel_sdvo_read_response(intel_output, &response, 2);
1362}
1363
Ma Ling9dff6af2009-04-02 13:13:26 +08001364static void
1365intel_sdvo_hdmi_sink_detect(struct drm_connector *connector)
1366{
1367 struct intel_output *intel_output = to_intel_output(connector);
1368 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1369 struct edid *edid = NULL;
1370
1371 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
1372 edid = drm_get_edid(&intel_output->base,
1373 &intel_output->ddc_bus->adapter);
1374 if (edid != NULL) {
1375 sdvo_priv->is_hdmi = drm_detect_hdmi_monitor(edid);
1376 kfree(edid);
1377 intel_output->base.display_info.raw_edid = NULL;
1378 }
1379}
1380
Jesse Barnes79e53942008-11-07 14:24:08 -08001381static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector)
1382{
1383 u8 response[2];
1384 u8 status;
1385 struct intel_output *intel_output = to_intel_output(connector);
1386
1387 intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0);
1388 status = intel_sdvo_read_response(intel_output, &response, 2);
1389
1390 DRM_DEBUG("SDVO response %d %d\n", response[0], response[1]);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001391
1392 if (status != SDVO_CMD_STATUS_SUCCESS)
1393 return connector_status_unknown;
1394
Ma Ling9dff6af2009-04-02 13:13:26 +08001395 if ((response[0] != 0) || (response[1] != 0)) {
1396 intel_sdvo_hdmi_sink_detect(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001397 return connector_status_connected;
Ma Ling9dff6af2009-04-02 13:13:26 +08001398 } else
Jesse Barnes79e53942008-11-07 14:24:08 -08001399 return connector_status_disconnected;
1400}
1401
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001402static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
Jesse Barnes79e53942008-11-07 14:24:08 -08001403{
1404 struct intel_output *intel_output = to_intel_output(connector);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001405 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001406
1407 /* set the bus switch and get the modes */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001408 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -08001409 intel_ddc_get_modes(intel_output);
1410
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001411#if 0
1412 struct drm_device *dev = encoder->dev;
1413 struct drm_i915_private *dev_priv = dev->dev_private;
1414 /* Mac mini hack. On this device, I get DDC through the analog, which
1415 * load-detects as disconnected. I fail to DDC through the SDVO DDC,
1416 * but it does load-detect as connected. So, just steal the DDC bits
1417 * from analog when we fail at finding it the right way.
1418 */
1419 crt = xf86_config->output[0];
1420 intel_output = crt->driver_private;
1421 if (intel_output->type == I830_OUTPUT_ANALOG &&
1422 crt->funcs->detect(crt) == XF86OutputStatusDisconnected) {
1423 I830I2CInit(pScrn, &intel_output->pDDCBus, GPIOA, "CRTDDC_A");
1424 edid_mon = xf86OutputGetEDID(crt, intel_output->pDDCBus);
1425 xf86DestroyI2CBusRec(intel_output->pDDCBus, true, true);
1426 }
1427 if (edid_mon) {
1428 xf86OutputSetEDID(output, edid_mon);
1429 modes = xf86OutputGetEDIDModes(output);
1430 }
1431#endif
1432}
1433
1434/**
1435 * This function checks the current TV format, and chooses a default if
1436 * it hasn't been set.
1437 */
1438static void
1439intel_sdvo_check_tv_format(struct intel_output *output)
1440{
1441 struct intel_sdvo_priv *dev_priv = output->dev_priv;
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001442 struct intel_sdvo_tv_format format;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001443 uint8_t status;
1444
1445 intel_sdvo_write_cmd(output, SDVO_CMD_GET_TV_FORMAT, NULL, 0);
1446 status = intel_sdvo_read_response(output, &format, sizeof(format));
1447 if (status != SDVO_CMD_STATUS_SUCCESS)
1448 return;
1449
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001450 memcpy(&dev_priv->tv_format, &format, sizeof(format));
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001451}
1452
1453/*
1454 * Set of SDVO TV modes.
1455 * Note! This is in reply order (see loop in get_tv_modes).
1456 * XXX: all 60Hz refresh?
1457 */
1458struct drm_display_mode sdvo_tv_modes[] = {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001459 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
1460 416, 0, 200, 201, 232, 233, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001461 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001462 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
1463 416, 0, 240, 241, 272, 273, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001464 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001465 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
1466 496, 0, 300, 301, 332, 333, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001467 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001468 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
1469 736, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001470 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001471 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
1472 736, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001473 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001474 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
1475 736, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001476 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001477 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
1478 800, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001479 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001480 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
1481 800, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001482 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001483 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
1484 816, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001485 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001486 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
1487 816, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001488 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001489 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
1490 816, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001491 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001492 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
1493 816, 0, 540, 541, 572, 573, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001494 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001495 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
1496 816, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001497 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001498 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
1499 864, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001500 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001501 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
1502 896, 0, 600, 601, 632, 633, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001503 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001504 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
1505 928, 0, 624, 625, 656, 657, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001506 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001507 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
1508 1016, 0, 766, 767, 798, 799, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001509 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001510 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
1511 1120, 0, 768, 769, 800, 801, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001512 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001513 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
1514 1376, 0, 1024, 1025, 1056, 1057, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001515 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1516};
1517
1518static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1519{
1520 struct intel_output *output = to_intel_output(connector);
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001521 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
1522 struct intel_sdvo_sdtv_resolution_request tv_res;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001523 uint32_t reply = 0;
1524 uint8_t status;
1525 int i = 0;
1526
1527 intel_sdvo_check_tv_format(output);
1528
1529 /* Read the list of supported input resolutions for the selected TV
1530 * format.
1531 */
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001532 memset(&tv_res, 0, sizeof(tv_res));
1533 memcpy(&tv_res, &sdvo_priv->tv_format, sizeof(tv_res));
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001534 intel_sdvo_write_cmd(output, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001535 &tv_res, sizeof(tv_res));
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001536 status = intel_sdvo_read_response(output, &reply, 3);
1537 if (status != SDVO_CMD_STATUS_SUCCESS)
1538 return;
1539
1540 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001541 if (reply & (1 << i)) {
1542 struct drm_display_mode *nmode;
1543 nmode = drm_mode_duplicate(connector->dev,
1544 &sdvo_tv_modes[i]);
1545 if (nmode)
1546 drm_mode_probed_add(connector, nmode);
1547 }
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001548}
1549
Ma Ling7086c872009-05-13 11:20:06 +08001550static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1551{
1552 struct intel_output *intel_output = to_intel_output(connector);
1553 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1554 struct drm_i915_private *dev_priv = connector->dev->dev_private;
1555
1556 /*
1557 * Attempt to get the mode list from DDC.
1558 * Assume that the preferred modes are
1559 * arranged in priority order.
1560 */
1561 /* set the bus switch and get the modes */
1562 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
1563 intel_ddc_get_modes(intel_output);
1564 if (list_empty(&connector->probed_modes) == false)
1565 return;
1566
1567 /* Fetch modes from VBT */
1568 if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
1569 struct drm_display_mode *newmode;
1570 newmode = drm_mode_duplicate(connector->dev,
1571 dev_priv->sdvo_lvds_vbt_mode);
1572 if (newmode != NULL) {
1573 /* Guarantee the mode is preferred */
1574 newmode->type = (DRM_MODE_TYPE_PREFERRED |
1575 DRM_MODE_TYPE_DRIVER);
1576 drm_mode_probed_add(connector, newmode);
1577 }
1578 }
1579}
1580
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001581static int intel_sdvo_get_modes(struct drm_connector *connector)
1582{
1583 struct intel_output *output = to_intel_output(connector);
1584 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
1585
1586 if (sdvo_priv->is_tv)
1587 intel_sdvo_get_tv_modes(connector);
Ma Ling7086c872009-05-13 11:20:06 +08001588 else if (sdvo_priv->is_lvds == true)
1589 intel_sdvo_get_lvds_modes(connector);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001590 else
1591 intel_sdvo_get_ddc_modes(connector);
1592
Jesse Barnes79e53942008-11-07 14:24:08 -08001593 if (list_empty(&connector->probed_modes))
1594 return 0;
1595 return 1;
1596}
1597
1598static void intel_sdvo_destroy(struct drm_connector *connector)
1599{
1600 struct intel_output *intel_output = to_intel_output(connector);
1601
1602 if (intel_output->i2c_bus)
1603 intel_i2c_destroy(intel_output->i2c_bus);
1604 drm_sysfs_connector_remove(connector);
1605 drm_connector_cleanup(connector);
1606 kfree(intel_output);
1607}
1608
1609static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
1610 .dpms = intel_sdvo_dpms,
1611 .mode_fixup = intel_sdvo_mode_fixup,
1612 .prepare = intel_encoder_prepare,
1613 .mode_set = intel_sdvo_mode_set,
1614 .commit = intel_encoder_commit,
1615};
1616
1617static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
1618 .save = intel_sdvo_save,
1619 .restore = intel_sdvo_restore,
1620 .detect = intel_sdvo_detect,
1621 .fill_modes = drm_helper_probe_single_connector_modes,
1622 .destroy = intel_sdvo_destroy,
1623};
1624
1625static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
1626 .get_modes = intel_sdvo_get_modes,
1627 .mode_valid = intel_sdvo_mode_valid,
1628 .best_encoder = intel_best_encoder,
1629};
1630
Hannes Ederb358d0a2008-12-18 21:18:47 +01001631static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -08001632{
1633 drm_encoder_cleanup(encoder);
1634}
1635
1636static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
1637 .destroy = intel_sdvo_enc_destroy,
1638};
1639
1640
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001641/**
1642 * Choose the appropriate DDC bus for control bus switch command for this
1643 * SDVO output based on the controlled output.
1644 *
1645 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
1646 * outputs, then LVDS outputs.
1647 */
1648static void
1649intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv)
1650{
1651 uint16_t mask = 0;
1652 unsigned int num_bits;
1653
1654 /* Make a mask of outputs less than or equal to our own priority in the
1655 * list.
1656 */
1657 switch (dev_priv->controlled_output) {
1658 case SDVO_OUTPUT_LVDS1:
1659 mask |= SDVO_OUTPUT_LVDS1;
1660 case SDVO_OUTPUT_LVDS0:
1661 mask |= SDVO_OUTPUT_LVDS0;
1662 case SDVO_OUTPUT_TMDS1:
1663 mask |= SDVO_OUTPUT_TMDS1;
1664 case SDVO_OUTPUT_TMDS0:
1665 mask |= SDVO_OUTPUT_TMDS0;
1666 case SDVO_OUTPUT_RGB1:
1667 mask |= SDVO_OUTPUT_RGB1;
1668 case SDVO_OUTPUT_RGB0:
1669 mask |= SDVO_OUTPUT_RGB0;
1670 break;
1671 }
1672
1673 /* Count bits to find what number we are in the priority list. */
1674 mask &= dev_priv->caps.output_flags;
1675 num_bits = hweight16(mask);
1676 if (num_bits > 3) {
1677 /* if more than 3 outputs, default to DDC bus 3 for now */
1678 num_bits = 3;
1679 }
1680
1681 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
1682 dev_priv->ddc_bus = 1 << num_bits;
1683}
1684
1685static bool
1686intel_sdvo_get_digital_encoding_mode(struct intel_output *output)
1687{
1688 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
1689 uint8_t status;
1690
1691 intel_sdvo_set_target_output(output, sdvo_priv->controlled_output);
1692
1693 intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0);
1694 status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1);
1695 if (status != SDVO_CMD_STATUS_SUCCESS)
1696 return false;
1697 return true;
1698}
1699
Eric Anholt7d573822009-01-02 13:33:00 -08001700bool intel_sdvo_init(struct drm_device *dev, int output_device)
Jesse Barnes79e53942008-11-07 14:24:08 -08001701{
1702 struct drm_connector *connector;
1703 struct intel_output *intel_output;
1704 struct intel_sdvo_priv *sdvo_priv;
1705 struct intel_i2c_chan *i2cbus = NULL;
1706 int connector_type;
1707 u8 ch[0x40];
1708 int i;
1709 int encoder_type, output_id;
1710
1711 intel_output = kcalloc(sizeof(struct intel_output)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL);
1712 if (!intel_output) {
Eric Anholt7d573822009-01-02 13:33:00 -08001713 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08001714 }
1715
Jesse Barnes79e53942008-11-07 14:24:08 -08001716 sdvo_priv = (struct intel_sdvo_priv *)(intel_output + 1);
1717 intel_output->type = INTEL_OUTPUT_SDVO;
1718
Jesse Barnes79e53942008-11-07 14:24:08 -08001719 /* setup the DDC bus. */
1720 if (output_device == SDVOB)
1721 i2cbus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB");
1722 else
1723 i2cbus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC");
1724
1725 if (!i2cbus)
Jonas Bonnad5b2a62009-05-15 09:10:41 +02001726 goto err_inteloutput;
Jesse Barnes79e53942008-11-07 14:24:08 -08001727
1728 sdvo_priv->i2c_bus = i2cbus;
1729
1730 if (output_device == SDVOB) {
1731 output_id = 1;
1732 sdvo_priv->i2c_bus->slave_addr = 0x38;
1733 } else {
1734 output_id = 2;
1735 sdvo_priv->i2c_bus->slave_addr = 0x39;
1736 }
1737
1738 sdvo_priv->output_device = output_device;
1739 intel_output->i2c_bus = i2cbus;
1740 intel_output->dev_priv = sdvo_priv;
1741
Jesse Barnes79e53942008-11-07 14:24:08 -08001742 /* Read the regs to test if we can talk to the device */
1743 for (i = 0; i < 0x40; i++) {
1744 if (!intel_sdvo_read_byte(intel_output, i, &ch[i])) {
1745 DRM_DEBUG("No SDVO device found on SDVO%c\n",
1746 output_device == SDVOB ? 'B' : 'C');
1747 goto err_i2c;
1748 }
1749 }
1750
Ma Ling7086c872009-05-13 11:20:06 +08001751 /* In defaut case sdvo lvds is false */
1752 sdvo_priv->is_lvds = false;
Jesse Barnes79e53942008-11-07 14:24:08 -08001753 intel_sdvo_get_capabilities(intel_output, &sdvo_priv->caps);
1754
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001755 if (sdvo_priv->caps.output_flags &
1756 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
1757 if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_TMDS0)
1758 sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS0;
1759 else
1760 sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS1;
Jesse Barnes79e53942008-11-07 14:24:08 -08001761
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001762 encoder_type = DRM_MODE_ENCODER_TMDS;
1763 connector_type = DRM_MODE_CONNECTOR_DVID;
1764
1765 if (intel_sdvo_get_supp_encode(intel_output,
1766 &sdvo_priv->encode) &&
1767 intel_sdvo_get_digital_encoding_mode(intel_output) &&
1768 sdvo_priv->is_hdmi) {
1769 /* enable hdmi encoding mode if supported */
1770 intel_sdvo_set_encode(intel_output, SDVO_ENCODE_HDMI);
1771 intel_sdvo_set_colorimetry(intel_output,
1772 SDVO_COLORIMETRY_RGB256);
1773 connector_type = DRM_MODE_CONNECTOR_HDMIA;
1774 }
1775 }
1776 else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_SVID0)
Jesse Barnes79e53942008-11-07 14:24:08 -08001777 {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001778 sdvo_priv->controlled_output = SDVO_OUTPUT_SVID0;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001779 encoder_type = DRM_MODE_ENCODER_TVDAC;
1780 connector_type = DRM_MODE_CONNECTOR_SVIDEO;
1781 sdvo_priv->is_tv = true;
1782 intel_output->needs_tv_clock = true;
1783 }
1784 else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_RGB0)
1785 {
1786 sdvo_priv->controlled_output = SDVO_OUTPUT_RGB0;
Jesse Barnes79e53942008-11-07 14:24:08 -08001787 encoder_type = DRM_MODE_ENCODER_DAC;
1788 connector_type = DRM_MODE_CONNECTOR_VGA;
1789 }
1790 else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_RGB1)
1791 {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001792 sdvo_priv->controlled_output = SDVO_OUTPUT_RGB1;
Jesse Barnes79e53942008-11-07 14:24:08 -08001793 encoder_type = DRM_MODE_ENCODER_DAC;
1794 connector_type = DRM_MODE_CONNECTOR_VGA;
1795 }
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001796 else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_LVDS0)
Jesse Barnes79e53942008-11-07 14:24:08 -08001797 {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001798 sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS0;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001799 encoder_type = DRM_MODE_ENCODER_LVDS;
1800 connector_type = DRM_MODE_CONNECTOR_LVDS;
Ma Ling7086c872009-05-13 11:20:06 +08001801 sdvo_priv->is_lvds = true;
Jesse Barnes79e53942008-11-07 14:24:08 -08001802 }
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001803 else if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_LVDS1)
Jesse Barnes79e53942008-11-07 14:24:08 -08001804 {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001805 sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS1;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001806 encoder_type = DRM_MODE_ENCODER_LVDS;
1807 connector_type = DRM_MODE_CONNECTOR_LVDS;
Ma Ling7086c872009-05-13 11:20:06 +08001808 sdvo_priv->is_lvds = true;
Jesse Barnes79e53942008-11-07 14:24:08 -08001809 }
1810 else
1811 {
1812 unsigned char bytes[2];
1813
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001814 sdvo_priv->controlled_output = 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08001815 memcpy (bytes, &sdvo_priv->caps.output_flags, 2);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001816 DRM_DEBUG("%s: Unknown SDVO output type (0x%02x%02x)\n",
Jesse Barnes79e53942008-11-07 14:24:08 -08001817 SDVO_NAME(sdvo_priv),
1818 bytes[0], bytes[1]);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001819 encoder_type = DRM_MODE_ENCODER_NONE;
1820 connector_type = DRM_MODE_CONNECTOR_Unknown;
Jesse Barnes79e53942008-11-07 14:24:08 -08001821 goto err_i2c;
1822 }
1823
Jonas Bonnad5b2a62009-05-15 09:10:41 +02001824 connector = &intel_output->base;
1825 drm_connector_init(dev, connector, &intel_sdvo_connector_funcs,
1826 connector_type);
1827 drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
1828 connector->interlace_allowed = 0;
1829 connector->doublescan_allowed = 0;
1830 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
1831
Jesse Barnes79e53942008-11-07 14:24:08 -08001832 drm_encoder_init(dev, &intel_output->enc, &intel_sdvo_enc_funcs, encoder_type);
1833 drm_encoder_helper_add(&intel_output->enc, &intel_sdvo_helper_funcs);
Jesse Barnes79e53942008-11-07 14:24:08 -08001834
1835 drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc);
1836 drm_sysfs_connector_add(connector);
1837
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001838 intel_sdvo_select_ddc_bus(sdvo_priv);
1839
Jesse Barnes79e53942008-11-07 14:24:08 -08001840 /* Set the input timing to the screen. Assume always input 0. */
1841 intel_sdvo_set_target_input(intel_output, true, false);
1842
1843 intel_sdvo_get_input_pixel_clock_range(intel_output,
1844 &sdvo_priv->pixel_clock_min,
1845 &sdvo_priv->pixel_clock_max);
1846
1847
1848 DRM_DEBUG("%s device VID/DID: %02X:%02X.%02X, "
1849 "clock range %dMHz - %dMHz, "
1850 "input 1: %c, input 2: %c, "
1851 "output 1: %c, output 2: %c\n",
1852 SDVO_NAME(sdvo_priv),
1853 sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id,
1854 sdvo_priv->caps.device_rev_id,
1855 sdvo_priv->pixel_clock_min / 1000,
1856 sdvo_priv->pixel_clock_max / 1000,
1857 (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
1858 (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
1859 /* check currently supported outputs */
1860 sdvo_priv->caps.output_flags &
1861 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
1862 sdvo_priv->caps.output_flags &
1863 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
1864
1865 intel_output->ddc_bus = i2cbus;
1866
Eric Anholt7d573822009-01-02 13:33:00 -08001867 return true;
Jesse Barnes79e53942008-11-07 14:24:08 -08001868
1869err_i2c:
1870 intel_i2c_destroy(intel_output->i2c_bus);
Jonas Bonnad5b2a62009-05-15 09:10:41 +02001871err_inteloutput:
Jesse Barnes79e53942008-11-07 14:24:08 -08001872 kfree(intel_output);
1873
Eric Anholt7d573822009-01-02 13:33:00 -08001874 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08001875}