2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2007 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
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:
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
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.
26 * Eric Anholt <eric@anholt.net>
29 #include <linux/delay.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/slab.h>
35 #include <drm/drm_crtc.h>
36 #include <drm/drm_edid.h>
39 #include "psb_intel_drv.h"
40 #include "psb_intel_reg.h"
41 #include "psb_intel_sdvo_regs.h"
43 #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
44 #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
45 #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
46 #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0)
48 #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
51 #define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
52 #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
53 #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
54 #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
57 static const char *tv_format_names
[] = {
58 "NTSC_M" , "NTSC_J" , "NTSC_443",
59 "PAL_B" , "PAL_D" , "PAL_G" ,
60 "PAL_H" , "PAL_I" , "PAL_M" ,
61 "PAL_N" , "PAL_NC" , "PAL_60" ,
62 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
63 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
67 struct psb_intel_sdvo
{
68 struct gma_encoder base
;
70 struct i2c_adapter
*i2c
;
73 struct i2c_adapter ddc
;
75 /* Register for the SDVO device: SDVOB or SDVOC */
78 /* Active outputs controlled by this SDVO output */
79 uint16_t controlled_output
;
82 * Capabilities of the SDVO device returned by
83 * i830_sdvo_get_capabilities()
85 struct psb_intel_sdvo_caps caps
;
87 /* Pixel clock limitations reported by the SDVO device, in kHz */
88 int pixel_clock_min
, pixel_clock_max
;
91 * For multiple function SDVO device,
92 * this is for current attached outputs.
94 uint16_t attached_output
;
97 * This is used to select the color range of RBG outputs in HDMI mode.
98 * It is only valid when using TMDS encoding and 8 bit per color mode.
100 uint32_t color_range
;
103 * This is set if we're going to treat the device as TV-out.
105 * While we have these nice friendly flags for output types that ought
106 * to decide this for us, the S-Video output on our HDMI+S-Video card
107 * shows up as RGB1 (VGA).
111 /* This is for current tv format name */
115 * This is set if we treat the device as HDMI, instead of DVI.
118 bool has_hdmi_monitor
;
122 * This is set if we detect output of sdvo device as LVDS and
123 * have a valid fixed mode to use with the panel.
128 * This is sdvo fixed pannel mode pointer
130 struct drm_display_mode
*sdvo_lvds_fixed_mode
;
132 /* DDC bus used by this SDVO encoder */
135 /* Input timings for adjusted_mode */
136 struct psb_intel_sdvo_dtd input_dtd
;
138 /* Saved SDVO output states */
139 uint32_t saveSDVO
; /* Can be SDVOB or SDVOC depending on sdvo_reg */
142 struct psb_intel_sdvo_connector
{
143 struct gma_connector base
;
145 /* Mark the type of connector */
146 uint16_t output_flag
;
150 /* This contains all current supported TV format */
151 u8 tv_format_supported
[ARRAY_SIZE(tv_format_names
)];
152 int format_supported_num
;
153 struct drm_property
*tv_format
;
155 /* add the property for the SDVO-TV */
156 struct drm_property
*left
;
157 struct drm_property
*right
;
158 struct drm_property
*top
;
159 struct drm_property
*bottom
;
160 struct drm_property
*hpos
;
161 struct drm_property
*vpos
;
162 struct drm_property
*contrast
;
163 struct drm_property
*saturation
;
164 struct drm_property
*hue
;
165 struct drm_property
*sharpness
;
166 struct drm_property
*flicker_filter
;
167 struct drm_property
*flicker_filter_adaptive
;
168 struct drm_property
*flicker_filter_2d
;
169 struct drm_property
*tv_chroma_filter
;
170 struct drm_property
*tv_luma_filter
;
171 struct drm_property
*dot_crawl
;
173 /* add the property for the SDVO-TV/LVDS */
174 struct drm_property
*brightness
;
176 /* Add variable to record current setting for the above property */
177 u32 left_margin
, right_margin
, top_margin
, bottom_margin
;
179 /* this is to get the range of margin.*/
180 u32 max_hscan
, max_vscan
;
181 u32 max_hpos
, cur_hpos
;
182 u32 max_vpos
, cur_vpos
;
183 u32 cur_brightness
, max_brightness
;
184 u32 cur_contrast
, max_contrast
;
185 u32 cur_saturation
, max_saturation
;
186 u32 cur_hue
, max_hue
;
187 u32 cur_sharpness
, max_sharpness
;
188 u32 cur_flicker_filter
, max_flicker_filter
;
189 u32 cur_flicker_filter_adaptive
, max_flicker_filter_adaptive
;
190 u32 cur_flicker_filter_2d
, max_flicker_filter_2d
;
191 u32 cur_tv_chroma_filter
, max_tv_chroma_filter
;
192 u32 cur_tv_luma_filter
, max_tv_luma_filter
;
193 u32 cur_dot_crawl
, max_dot_crawl
;
196 static struct psb_intel_sdvo
*to_psb_intel_sdvo(struct drm_encoder
*encoder
)
198 return container_of(encoder
, struct psb_intel_sdvo
, base
.base
);
201 static struct psb_intel_sdvo
*intel_attached_sdvo(struct drm_connector
*connector
)
203 return container_of(gma_attached_encoder(connector
),
204 struct psb_intel_sdvo
, base
);
207 static struct psb_intel_sdvo_connector
*to_psb_intel_sdvo_connector(struct drm_connector
*connector
)
209 return container_of(to_gma_connector(connector
), struct psb_intel_sdvo_connector
, base
);
213 psb_intel_sdvo_output_setup(struct psb_intel_sdvo
*psb_intel_sdvo
, uint16_t flags
);
215 psb_intel_sdvo_tv_create_property(struct psb_intel_sdvo
*psb_intel_sdvo
,
216 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
,
219 psb_intel_sdvo_create_enhance_property(struct psb_intel_sdvo
*psb_intel_sdvo
,
220 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
);
223 * Writes the SDVOB or SDVOC with the given value, but always writes both
224 * SDVOB and SDVOC to work around apparent hardware issues (according to
225 * comments in the BIOS).
227 static void psb_intel_sdvo_write_sdvox(struct psb_intel_sdvo
*psb_intel_sdvo
, u32 val
)
229 struct drm_device
*dev
= psb_intel_sdvo
->base
.base
.dev
;
230 u32 bval
= val
, cval
= val
;
232 int need_aux
= IS_MRST(dev
) ? 1 : 0;
234 for (j
= 0; j
<= need_aux
; j
++) {
235 if (psb_intel_sdvo
->sdvo_reg
== SDVOB
)
236 cval
= REG_READ_WITH_AUX(SDVOC
, j
);
238 bval
= REG_READ_WITH_AUX(SDVOB
, j
);
241 * Write the registers twice for luck. Sometimes,
242 * writing them only once doesn't appear to 'stick'.
243 * The BIOS does this too. Yay, magic
245 for (i
= 0; i
< 2; i
++) {
246 REG_WRITE_WITH_AUX(SDVOB
, bval
, j
);
247 REG_READ_WITH_AUX(SDVOB
, j
);
248 REG_WRITE_WITH_AUX(SDVOC
, cval
, j
);
249 REG_READ_WITH_AUX(SDVOC
, j
);
254 static bool psb_intel_sdvo_read_byte(struct psb_intel_sdvo
*psb_intel_sdvo
, u8 addr
, u8
*ch
)
256 struct i2c_msg msgs
[] = {
258 .addr
= psb_intel_sdvo
->slave_addr
,
264 .addr
= psb_intel_sdvo
->slave_addr
,
272 if ((ret
= i2c_transfer(psb_intel_sdvo
->i2c
, msgs
, 2)) == 2)
275 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret
);
279 #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
280 /** Mapping of command numbers to names, for debug output */
281 static const struct _sdvo_cmd_name
{
284 } sdvo_cmd_names
[] = {
285 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET
),
286 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS
),
287 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV
),
288 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS
),
289 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS
),
290 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS
),
291 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP
),
292 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP
),
293 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS
),
294 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT
),
295 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG
),
296 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG
),
297 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE
),
298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT
),
299 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT
),
300 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1
),
301 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2
),
302 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1
),
303 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2
),
304 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1
),
305 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1
),
306 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2
),
307 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1
),
308 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2
),
309 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING
),
310 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1
),
311 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2
),
312 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE
),
313 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE
),
314 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS
),
315 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT
),
316 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT
),
317 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS
),
318 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT
),
319 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT
),
320 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES
),
321 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE
),
322 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE
),
323 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE
),
324 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH
),
325 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT
),
326 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT
),
327 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS
),
329 /* Add the op code for SDVO enhancements */
330 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HPOS
),
331 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HPOS
),
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HPOS
),
333 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_VPOS
),
334 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_VPOS
),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_VPOS
),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION
),
337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION
),
338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION
),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE
),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE
),
341 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE
),
342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST
),
343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST
),
344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST
),
345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS
),
346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS
),
347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS
),
348 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H
),
349 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H
),
350 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H
),
351 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V
),
352 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V
),
353 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V
),
354 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER
),
355 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER
),
356 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER
),
357 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_ADAPTIVE
),
358 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_ADAPTIVE
),
359 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_ADAPTIVE
),
360 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_2D
),
361 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_2D
),
362 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_2D
),
363 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SHARPNESS
),
364 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SHARPNESS
),
365 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SHARPNESS
),
366 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DOT_CRAWL
),
367 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DOT_CRAWL
),
368 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_CHROMA_FILTER
),
369 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_CHROMA_FILTER
),
370 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_CHROMA_FILTER
),
371 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_LUMA_FILTER
),
372 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_LUMA_FILTER
),
373 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_LUMA_FILTER
),
376 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE
),
377 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE
),
378 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE
),
379 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI
),
380 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI
),
381 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP
),
382 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY
),
383 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY
),
384 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER
),
385 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT
),
386 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT
),
387 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX
),
388 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX
),
389 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO
),
390 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT
),
391 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT
),
392 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE
),
393 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE
),
394 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA
),
395 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA
),
398 #define IS_SDVOB(reg) (reg == SDVOB)
399 #define SDVO_NAME(svdo) (IS_SDVOB((svdo)->sdvo_reg) ? "SDVOB" : "SDVOC")
401 static void psb_intel_sdvo_debug_write(struct psb_intel_sdvo
*psb_intel_sdvo
, u8 cmd
,
402 const void *args
, int args_len
)
406 DRM_DEBUG_KMS("%s: W: %02X ",
407 SDVO_NAME(psb_intel_sdvo
), cmd
);
408 for (i
= 0; i
< args_len
; i
++)
409 DRM_DEBUG_KMS("%02X ", ((u8
*)args
)[i
]);
412 for (i
= 0; i
< ARRAY_SIZE(sdvo_cmd_names
); i
++) {
413 if (cmd
== sdvo_cmd_names
[i
].cmd
) {
414 DRM_DEBUG_KMS("(%s)", sdvo_cmd_names
[i
].name
);
418 if (i
== ARRAY_SIZE(sdvo_cmd_names
))
419 DRM_DEBUG_KMS("(%02X)", cmd
);
423 static const char *cmd_status_names
[] = {
429 "Target not specified",
430 "Scaling not supported"
433 #define MAX_ARG_LEN 32
435 static bool psb_intel_sdvo_write_cmd(struct psb_intel_sdvo
*psb_intel_sdvo
, u8 cmd
,
436 const void *args
, int args_len
)
438 u8 buf
[MAX_ARG_LEN
*2 + 2], status
;
439 struct i2c_msg msgs
[MAX_ARG_LEN
+ 3];
442 if (args_len
> MAX_ARG_LEN
) {
443 DRM_ERROR("Need to increase arg length\n");
447 psb_intel_sdvo_debug_write(psb_intel_sdvo
, cmd
, args
, args_len
);
449 for (i
= 0; i
< args_len
; i
++) {
450 msgs
[i
].addr
= psb_intel_sdvo
->slave_addr
;
453 msgs
[i
].buf
= buf
+ 2 *i
;
454 buf
[2*i
+ 0] = SDVO_I2C_ARG_0
- i
;
455 buf
[2*i
+ 1] = ((u8
*)args
)[i
];
457 msgs
[i
].addr
= psb_intel_sdvo
->slave_addr
;
460 msgs
[i
].buf
= buf
+ 2*i
;
461 buf
[2*i
+ 0] = SDVO_I2C_OPCODE
;
464 /* the following two are to read the response */
465 status
= SDVO_I2C_CMD_STATUS
;
466 msgs
[i
+1].addr
= psb_intel_sdvo
->slave_addr
;
469 msgs
[i
+1].buf
= &status
;
471 msgs
[i
+2].addr
= psb_intel_sdvo
->slave_addr
;
472 msgs
[i
+2].flags
= I2C_M_RD
;
474 msgs
[i
+2].buf
= &status
;
476 ret
= i2c_transfer(psb_intel_sdvo
->i2c
, msgs
, i
+3);
478 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret
);
482 /* failure in I2C transfer */
483 DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret
, i
+3);
490 static bool psb_intel_sdvo_read_response(struct psb_intel_sdvo
*psb_intel_sdvo
,
491 void *response
, int response_len
)
497 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(psb_intel_sdvo
));
500 * The documentation states that all commands will be
501 * processed within 15µs, and that we need only poll
502 * the status byte a maximum of 3 times in order for the
503 * command to be complete.
505 * Check 5 times in case the hardware failed to read the docs.
507 if (!psb_intel_sdvo_read_byte(psb_intel_sdvo
,
512 while ((status
== SDVO_CMD_STATUS_PENDING
||
513 status
== SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED
) && retry
--) {
515 if (!psb_intel_sdvo_read_byte(psb_intel_sdvo
,
521 if (status
<= SDVO_CMD_STATUS_SCALING_NOT_SUPP
)
522 DRM_DEBUG_KMS("(%s)", cmd_status_names
[status
]);
524 DRM_DEBUG_KMS("(??? %d)", status
);
526 if (status
!= SDVO_CMD_STATUS_SUCCESS
)
529 /* Read the command response */
530 for (i
= 0; i
< response_len
; i
++) {
531 if (!psb_intel_sdvo_read_byte(psb_intel_sdvo
,
532 SDVO_I2C_RETURN_0
+ i
,
533 &((u8
*)response
)[i
]))
535 DRM_DEBUG_KMS(" %02X", ((u8
*)response
)[i
]);
541 DRM_DEBUG_KMS("... failed\n");
545 static int psb_intel_sdvo_get_pixel_multiplier(struct drm_display_mode
*mode
)
547 if (mode
->clock
>= 100000)
549 else if (mode
->clock
>= 50000)
555 static bool psb_intel_sdvo_set_control_bus_switch(struct psb_intel_sdvo
*psb_intel_sdvo
,
558 /* This must be the immediately preceding write before the i2c xfer */
559 return psb_intel_sdvo_write_cmd(psb_intel_sdvo
,
560 SDVO_CMD_SET_CONTROL_BUS_SWITCH
,
564 static bool psb_intel_sdvo_set_value(struct psb_intel_sdvo
*psb_intel_sdvo
, u8 cmd
, const void *data
, int len
)
566 if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo
, cmd
, data
, len
))
569 return psb_intel_sdvo_read_response(psb_intel_sdvo
, NULL
, 0);
573 psb_intel_sdvo_get_value(struct psb_intel_sdvo
*psb_intel_sdvo
, u8 cmd
, void *value
, int len
)
575 if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo
, cmd
, NULL
, 0))
578 return psb_intel_sdvo_read_response(psb_intel_sdvo
, value
, len
);
581 static bool psb_intel_sdvo_set_target_input(struct psb_intel_sdvo
*psb_intel_sdvo
)
583 struct psb_intel_sdvo_set_target_input_args targets
= {0};
584 return psb_intel_sdvo_set_value(psb_intel_sdvo
,
585 SDVO_CMD_SET_TARGET_INPUT
,
586 &targets
, sizeof(targets
));
590 * Return whether each input is trained.
592 * This function is making an assumption about the layout of the response,
593 * which should be checked against the docs.
595 static bool psb_intel_sdvo_get_trained_inputs(struct psb_intel_sdvo
*psb_intel_sdvo
, bool *input_1
, bool *input_2
)
597 struct psb_intel_sdvo_get_trained_inputs_response response
;
599 BUILD_BUG_ON(sizeof(response
) != 1);
600 if (!psb_intel_sdvo_get_value(psb_intel_sdvo
, SDVO_CMD_GET_TRAINED_INPUTS
,
601 &response
, sizeof(response
)))
604 *input_1
= response
.input0_trained
;
605 *input_2
= response
.input1_trained
;
609 static bool psb_intel_sdvo_set_active_outputs(struct psb_intel_sdvo
*psb_intel_sdvo
,
612 return psb_intel_sdvo_set_value(psb_intel_sdvo
,
613 SDVO_CMD_SET_ACTIVE_OUTPUTS
,
614 &outputs
, sizeof(outputs
));
617 static bool psb_intel_sdvo_set_encoder_power_state(struct psb_intel_sdvo
*psb_intel_sdvo
,
620 u8 state
= SDVO_ENCODER_STATE_ON
;
623 case DRM_MODE_DPMS_ON
:
624 state
= SDVO_ENCODER_STATE_ON
;
626 case DRM_MODE_DPMS_STANDBY
:
627 state
= SDVO_ENCODER_STATE_STANDBY
;
629 case DRM_MODE_DPMS_SUSPEND
:
630 state
= SDVO_ENCODER_STATE_SUSPEND
;
632 case DRM_MODE_DPMS_OFF
:
633 state
= SDVO_ENCODER_STATE_OFF
;
637 return psb_intel_sdvo_set_value(psb_intel_sdvo
,
638 SDVO_CMD_SET_ENCODER_POWER_STATE
, &state
, sizeof(state
));
641 static bool psb_intel_sdvo_get_input_pixel_clock_range(struct psb_intel_sdvo
*psb_intel_sdvo
,
645 struct psb_intel_sdvo_pixel_clock_range clocks
;
647 BUILD_BUG_ON(sizeof(clocks
) != 4);
648 if (!psb_intel_sdvo_get_value(psb_intel_sdvo
,
649 SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE
,
650 &clocks
, sizeof(clocks
)))
653 /* Convert the values from units of 10 kHz to kHz. */
654 *clock_min
= clocks
.min
* 10;
655 *clock_max
= clocks
.max
* 10;
659 static bool psb_intel_sdvo_set_target_output(struct psb_intel_sdvo
*psb_intel_sdvo
,
662 return psb_intel_sdvo_set_value(psb_intel_sdvo
,
663 SDVO_CMD_SET_TARGET_OUTPUT
,
664 &outputs
, sizeof(outputs
));
667 static bool psb_intel_sdvo_set_timing(struct psb_intel_sdvo
*psb_intel_sdvo
, u8 cmd
,
668 struct psb_intel_sdvo_dtd
*dtd
)
670 return psb_intel_sdvo_set_value(psb_intel_sdvo
, cmd
, &dtd
->part1
, sizeof(dtd
->part1
)) &&
671 psb_intel_sdvo_set_value(psb_intel_sdvo
, cmd
+ 1, &dtd
->part2
, sizeof(dtd
->part2
));
674 static bool psb_intel_sdvo_set_input_timing(struct psb_intel_sdvo
*psb_intel_sdvo
,
675 struct psb_intel_sdvo_dtd
*dtd
)
677 return psb_intel_sdvo_set_timing(psb_intel_sdvo
,
678 SDVO_CMD_SET_INPUT_TIMINGS_PART1
, dtd
);
681 static bool psb_intel_sdvo_set_output_timing(struct psb_intel_sdvo
*psb_intel_sdvo
,
682 struct psb_intel_sdvo_dtd
*dtd
)
684 return psb_intel_sdvo_set_timing(psb_intel_sdvo
,
685 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1
, dtd
);
689 psb_intel_sdvo_create_preferred_input_timing(struct psb_intel_sdvo
*psb_intel_sdvo
,
694 struct psb_intel_sdvo_preferred_input_timing_args args
;
696 memset(&args
, 0, sizeof(args
));
699 args
.height
= height
;
702 if (psb_intel_sdvo
->is_lvds
&&
703 (psb_intel_sdvo
->sdvo_lvds_fixed_mode
->hdisplay
!= width
||
704 psb_intel_sdvo
->sdvo_lvds_fixed_mode
->vdisplay
!= height
))
707 return psb_intel_sdvo_set_value(psb_intel_sdvo
,
708 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING
,
709 &args
, sizeof(args
));
712 static bool psb_intel_sdvo_get_preferred_input_timing(struct psb_intel_sdvo
*psb_intel_sdvo
,
713 struct psb_intel_sdvo_dtd
*dtd
)
715 BUILD_BUG_ON(sizeof(dtd
->part1
) != 8);
716 BUILD_BUG_ON(sizeof(dtd
->part2
) != 8);
717 return psb_intel_sdvo_get_value(psb_intel_sdvo
, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1
,
718 &dtd
->part1
, sizeof(dtd
->part1
)) &&
719 psb_intel_sdvo_get_value(psb_intel_sdvo
, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2
,
720 &dtd
->part2
, sizeof(dtd
->part2
));
723 static bool psb_intel_sdvo_set_clock_rate_mult(struct psb_intel_sdvo
*psb_intel_sdvo
, u8 val
)
725 return psb_intel_sdvo_set_value(psb_intel_sdvo
, SDVO_CMD_SET_CLOCK_RATE_MULT
, &val
, 1);
728 static void psb_intel_sdvo_get_dtd_from_mode(struct psb_intel_sdvo_dtd
*dtd
,
729 const struct drm_display_mode
*mode
)
731 uint16_t width
, height
;
732 uint16_t h_blank_len
, h_sync_len
, v_blank_len
, v_sync_len
;
733 uint16_t h_sync_offset
, v_sync_offset
;
735 width
= mode
->crtc_hdisplay
;
736 height
= mode
->crtc_vdisplay
;
738 /* do some mode translations */
739 h_blank_len
= mode
->crtc_hblank_end
- mode
->crtc_hblank_start
;
740 h_sync_len
= mode
->crtc_hsync_end
- mode
->crtc_hsync_start
;
742 v_blank_len
= mode
->crtc_vblank_end
- mode
->crtc_vblank_start
;
743 v_sync_len
= mode
->crtc_vsync_end
- mode
->crtc_vsync_start
;
745 h_sync_offset
= mode
->crtc_hsync_start
- mode
->crtc_hblank_start
;
746 v_sync_offset
= mode
->crtc_vsync_start
- mode
->crtc_vblank_start
;
748 dtd
->part1
.clock
= mode
->clock
/ 10;
749 dtd
->part1
.h_active
= width
& 0xff;
750 dtd
->part1
.h_blank
= h_blank_len
& 0xff;
751 dtd
->part1
.h_high
= (((width
>> 8) & 0xf) << 4) |
752 ((h_blank_len
>> 8) & 0xf);
753 dtd
->part1
.v_active
= height
& 0xff;
754 dtd
->part1
.v_blank
= v_blank_len
& 0xff;
755 dtd
->part1
.v_high
= (((height
>> 8) & 0xf) << 4) |
756 ((v_blank_len
>> 8) & 0xf);
758 dtd
->part2
.h_sync_off
= h_sync_offset
& 0xff;
759 dtd
->part2
.h_sync_width
= h_sync_len
& 0xff;
760 dtd
->part2
.v_sync_off_width
= (v_sync_offset
& 0xf) << 4 |
762 dtd
->part2
.sync_off_width_high
= ((h_sync_offset
& 0x300) >> 2) |
763 ((h_sync_len
& 0x300) >> 4) | ((v_sync_offset
& 0x30) >> 2) |
764 ((v_sync_len
& 0x30) >> 4);
766 dtd
->part2
.dtd_flags
= 0x18;
767 if (mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
768 dtd
->part2
.dtd_flags
|= 0x2;
769 if (mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
770 dtd
->part2
.dtd_flags
|= 0x4;
772 dtd
->part2
.sdvo_flags
= 0;
773 dtd
->part2
.v_sync_off_high
= v_sync_offset
& 0xc0;
774 dtd
->part2
.reserved
= 0;
777 static void psb_intel_sdvo_get_mode_from_dtd(struct drm_display_mode
* mode
,
778 const struct psb_intel_sdvo_dtd
*dtd
)
780 mode
->hdisplay
= dtd
->part1
.h_active
;
781 mode
->hdisplay
+= ((dtd
->part1
.h_high
>> 4) & 0x0f) << 8;
782 mode
->hsync_start
= mode
->hdisplay
+ dtd
->part2
.h_sync_off
;
783 mode
->hsync_start
+= (dtd
->part2
.sync_off_width_high
& 0xc0) << 2;
784 mode
->hsync_end
= mode
->hsync_start
+ dtd
->part2
.h_sync_width
;
785 mode
->hsync_end
+= (dtd
->part2
.sync_off_width_high
& 0x30) << 4;
786 mode
->htotal
= mode
->hdisplay
+ dtd
->part1
.h_blank
;
787 mode
->htotal
+= (dtd
->part1
.h_high
& 0xf) << 8;
789 mode
->vdisplay
= dtd
->part1
.v_active
;
790 mode
->vdisplay
+= ((dtd
->part1
.v_high
>> 4) & 0x0f) << 8;
791 mode
->vsync_start
= mode
->vdisplay
;
792 mode
->vsync_start
+= (dtd
->part2
.v_sync_off_width
>> 4) & 0xf;
793 mode
->vsync_start
+= (dtd
->part2
.sync_off_width_high
& 0x0c) << 2;
794 mode
->vsync_start
+= dtd
->part2
.v_sync_off_high
& 0xc0;
795 mode
->vsync_end
= mode
->vsync_start
+
796 (dtd
->part2
.v_sync_off_width
& 0xf);
797 mode
->vsync_end
+= (dtd
->part2
.sync_off_width_high
& 0x3) << 4;
798 mode
->vtotal
= mode
->vdisplay
+ dtd
->part1
.v_blank
;
799 mode
->vtotal
+= (dtd
->part1
.v_high
& 0xf) << 8;
801 mode
->clock
= dtd
->part1
.clock
* 10;
803 mode
->flags
&= ~(DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
);
804 if (dtd
->part2
.dtd_flags
& 0x2)
805 mode
->flags
|= DRM_MODE_FLAG_PHSYNC
;
806 if (dtd
->part2
.dtd_flags
& 0x4)
807 mode
->flags
|= DRM_MODE_FLAG_PVSYNC
;
810 static bool psb_intel_sdvo_check_supp_encode(struct psb_intel_sdvo
*psb_intel_sdvo
)
812 struct psb_intel_sdvo_encode encode
;
814 BUILD_BUG_ON(sizeof(encode
) != 2);
815 return psb_intel_sdvo_get_value(psb_intel_sdvo
,
816 SDVO_CMD_GET_SUPP_ENCODE
,
817 &encode
, sizeof(encode
));
820 static bool psb_intel_sdvo_set_encode(struct psb_intel_sdvo
*psb_intel_sdvo
,
823 return psb_intel_sdvo_set_value(psb_intel_sdvo
, SDVO_CMD_SET_ENCODE
, &mode
, 1);
826 static bool psb_intel_sdvo_set_colorimetry(struct psb_intel_sdvo
*psb_intel_sdvo
,
829 return psb_intel_sdvo_set_value(psb_intel_sdvo
, SDVO_CMD_SET_COLORIMETRY
, &mode
, 1);
833 static void psb_intel_sdvo_dump_hdmi_buf(struct psb_intel_sdvo
*psb_intel_sdvo
)
836 uint8_t set_buf_index
[2];
842 psb_intel_sdvo_get_value(encoder
, SDVO_CMD_GET_HBUF_AV_SPLIT
, &av_split
, 1);
844 for (i
= 0; i
<= av_split
; i
++) {
845 set_buf_index
[0] = i
; set_buf_index
[1] = 0;
846 psb_intel_sdvo_write_cmd(encoder
, SDVO_CMD_SET_HBUF_INDEX
,
848 psb_intel_sdvo_write_cmd(encoder
, SDVO_CMD_GET_HBUF_INFO
, NULL
, 0);
849 psb_intel_sdvo_read_response(encoder
, &buf_size
, 1);
852 for (j
= 0; j
<= buf_size
; j
+= 8) {
853 psb_intel_sdvo_write_cmd(encoder
, SDVO_CMD_GET_HBUF_DATA
,
855 psb_intel_sdvo_read_response(encoder
, pos
, 8);
862 static bool psb_intel_sdvo_set_avi_infoframe(struct psb_intel_sdvo
*psb_intel_sdvo
)
864 DRM_INFO("HDMI is not supported yet");
868 struct dip_infoframe avi_if
= {
869 .type
= DIP_TYPE_AVI
,
870 .ver
= DIP_VERSION_AVI
,
873 uint8_t tx_rate
= SDVO_HBUF_TX_VSYNC
;
874 uint8_t set_buf_index
[2] = { 1, 0 };
875 uint64_t *data
= (uint64_t *)&avi_if
;
878 intel_dip_infoframe_csum(&avi_if
);
880 if (!psb_intel_sdvo_set_value(psb_intel_sdvo
,
881 SDVO_CMD_SET_HBUF_INDEX
,
885 for (i
= 0; i
< sizeof(avi_if
); i
+= 8) {
886 if (!psb_intel_sdvo_set_value(psb_intel_sdvo
,
887 SDVO_CMD_SET_HBUF_DATA
,
893 return psb_intel_sdvo_set_value(psb_intel_sdvo
,
894 SDVO_CMD_SET_HBUF_TXRATE
,
899 static bool psb_intel_sdvo_set_tv_format(struct psb_intel_sdvo
*psb_intel_sdvo
)
901 struct psb_intel_sdvo_tv_format format
;
904 format_map
= 1 << psb_intel_sdvo
->tv_format_index
;
905 memset(&format
, 0, sizeof(format
));
906 memcpy(&format
, &format_map
, min(sizeof(format
), sizeof(format_map
)));
908 BUILD_BUG_ON(sizeof(format
) != 6);
909 return psb_intel_sdvo_set_value(psb_intel_sdvo
,
910 SDVO_CMD_SET_TV_FORMAT
,
911 &format
, sizeof(format
));
915 psb_intel_sdvo_set_output_timings_from_mode(struct psb_intel_sdvo
*psb_intel_sdvo
,
916 const struct drm_display_mode
*mode
)
918 struct psb_intel_sdvo_dtd output_dtd
;
920 if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo
,
921 psb_intel_sdvo
->attached_output
))
924 psb_intel_sdvo_get_dtd_from_mode(&output_dtd
, mode
);
925 if (!psb_intel_sdvo_set_output_timing(psb_intel_sdvo
, &output_dtd
))
932 psb_intel_sdvo_set_input_timings_for_mode(struct psb_intel_sdvo
*psb_intel_sdvo
,
933 const struct drm_display_mode
*mode
,
934 struct drm_display_mode
*adjusted_mode
)
936 /* Reset the input timing to the screen. Assume always input 0. */
937 if (!psb_intel_sdvo_set_target_input(psb_intel_sdvo
))
940 if (!psb_intel_sdvo_create_preferred_input_timing(psb_intel_sdvo
,
946 if (!psb_intel_sdvo_get_preferred_input_timing(psb_intel_sdvo
,
947 &psb_intel_sdvo
->input_dtd
))
950 psb_intel_sdvo_get_mode_from_dtd(adjusted_mode
, &psb_intel_sdvo
->input_dtd
);
952 drm_mode_set_crtcinfo(adjusted_mode
, 0);
956 static bool psb_intel_sdvo_mode_fixup(struct drm_encoder
*encoder
,
957 const struct drm_display_mode
*mode
,
958 struct drm_display_mode
*adjusted_mode
)
960 struct psb_intel_sdvo
*psb_intel_sdvo
= to_psb_intel_sdvo(encoder
);
963 /* We need to construct preferred input timings based on our
964 * output timings. To do that, we have to set the output
965 * timings, even though this isn't really the right place in
966 * the sequence to do it. Oh well.
968 if (psb_intel_sdvo
->is_tv
) {
969 if (!psb_intel_sdvo_set_output_timings_from_mode(psb_intel_sdvo
, mode
))
972 (void) psb_intel_sdvo_set_input_timings_for_mode(psb_intel_sdvo
,
975 } else if (psb_intel_sdvo
->is_lvds
) {
976 if (!psb_intel_sdvo_set_output_timings_from_mode(psb_intel_sdvo
,
977 psb_intel_sdvo
->sdvo_lvds_fixed_mode
))
980 (void) psb_intel_sdvo_set_input_timings_for_mode(psb_intel_sdvo
,
985 /* Make the CRTC code factor in the SDVO pixel multiplier. The
986 * SDVO device will factor out the multiplier during mode_set.
988 multiplier
= psb_intel_sdvo_get_pixel_multiplier(adjusted_mode
);
989 psb_intel_mode_set_pixel_multiplier(adjusted_mode
, multiplier
);
994 static void psb_intel_sdvo_mode_set(struct drm_encoder
*encoder
,
995 struct drm_display_mode
*mode
,
996 struct drm_display_mode
*adjusted_mode
)
998 struct drm_device
*dev
= encoder
->dev
;
999 struct drm_crtc
*crtc
= encoder
->crtc
;
1000 struct gma_crtc
*gma_crtc
= to_gma_crtc(crtc
);
1001 struct psb_intel_sdvo
*psb_intel_sdvo
= to_psb_intel_sdvo(encoder
);
1003 struct psb_intel_sdvo_in_out_map in_out
;
1004 struct psb_intel_sdvo_dtd input_dtd
;
1005 int pixel_multiplier
= psb_intel_mode_get_pixel_multiplier(adjusted_mode
);
1007 int need_aux
= IS_MRST(dev
) ? 1 : 0;
1012 /* First, set the input mapping for the first input to our controlled
1013 * output. This is only correct if we're a single-input device, in
1014 * which case the first input is the output from the appropriate SDVO
1015 * channel on the motherboard. In a two-input device, the first input
1016 * will be SDVOB and the second SDVOC.
1018 in_out
.in0
= psb_intel_sdvo
->attached_output
;
1021 psb_intel_sdvo_set_value(psb_intel_sdvo
,
1022 SDVO_CMD_SET_IN_OUT_MAP
,
1023 &in_out
, sizeof(in_out
));
1025 /* Set the output timings to the screen */
1026 if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo
,
1027 psb_intel_sdvo
->attached_output
))
1030 /* We have tried to get input timing in mode_fixup, and filled into
1033 if (psb_intel_sdvo
->is_tv
|| psb_intel_sdvo
->is_lvds
) {
1034 input_dtd
= psb_intel_sdvo
->input_dtd
;
1036 /* Set the output timing to the screen */
1037 if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo
,
1038 psb_intel_sdvo
->attached_output
))
1041 psb_intel_sdvo_get_dtd_from_mode(&input_dtd
, adjusted_mode
);
1042 (void) psb_intel_sdvo_set_output_timing(psb_intel_sdvo
, &input_dtd
);
1045 /* Set the input timing to the screen. Assume always input 0. */
1046 if (!psb_intel_sdvo_set_target_input(psb_intel_sdvo
))
1049 if (psb_intel_sdvo
->has_hdmi_monitor
) {
1050 psb_intel_sdvo_set_encode(psb_intel_sdvo
, SDVO_ENCODE_HDMI
);
1051 psb_intel_sdvo_set_colorimetry(psb_intel_sdvo
,
1052 SDVO_COLORIMETRY_RGB256
);
1053 psb_intel_sdvo_set_avi_infoframe(psb_intel_sdvo
);
1055 psb_intel_sdvo_set_encode(psb_intel_sdvo
, SDVO_ENCODE_DVI
);
1057 if (psb_intel_sdvo
->is_tv
&&
1058 !psb_intel_sdvo_set_tv_format(psb_intel_sdvo
))
1061 (void) psb_intel_sdvo_set_input_timing(psb_intel_sdvo
, &input_dtd
);
1063 switch (pixel_multiplier
) {
1065 case 1: rate
= SDVO_CLOCK_RATE_MULT_1X
; break;
1066 case 2: rate
= SDVO_CLOCK_RATE_MULT_2X
; break;
1067 case 4: rate
= SDVO_CLOCK_RATE_MULT_4X
; break;
1069 if (!psb_intel_sdvo_set_clock_rate_mult(psb_intel_sdvo
, rate
))
1072 /* Set the SDVO control regs. */
1074 sdvox
= REG_READ_AUX(psb_intel_sdvo
->sdvo_reg
);
1076 sdvox
= REG_READ(psb_intel_sdvo
->sdvo_reg
);
1078 switch (psb_intel_sdvo
->sdvo_reg
) {
1080 sdvox
&= SDVOB_PRESERVE_MASK
;
1083 sdvox
&= SDVOC_PRESERVE_MASK
;
1086 sdvox
|= (9 << 19) | SDVO_BORDER_ENABLE
;
1088 if (gma_crtc
->pipe
== 1)
1089 sdvox
|= SDVO_PIPE_B_SELECT
;
1090 if (psb_intel_sdvo
->has_hdmi_audio
)
1091 sdvox
|= SDVO_AUDIO_ENABLE
;
1093 /* FIXME: Check if this is needed for PSB
1094 sdvox |= (pixel_multiplier - 1) << SDVO_PORT_MULTIPLY_SHIFT;
1097 if (input_dtd
.part2
.sdvo_flags
& SDVO_NEED_TO_STALL
)
1098 sdvox
|= SDVO_STALL_SELECT
;
1099 psb_intel_sdvo_write_sdvox(psb_intel_sdvo
, sdvox
);
1102 static void psb_intel_sdvo_dpms(struct drm_encoder
*encoder
, int mode
)
1104 struct drm_device
*dev
= encoder
->dev
;
1105 struct psb_intel_sdvo
*psb_intel_sdvo
= to_psb_intel_sdvo(encoder
);
1108 int need_aux
= IS_MRST(dev
) ? 1 : 0;
1111 case DRM_MODE_DPMS_ON
:
1112 DRM_DEBUG("DPMS_ON");
1114 case DRM_MODE_DPMS_OFF
:
1115 DRM_DEBUG("DPMS_OFF");
1118 DRM_DEBUG("DPMS: %d", mode
);
1121 if (mode
!= DRM_MODE_DPMS_ON
) {
1122 psb_intel_sdvo_set_active_outputs(psb_intel_sdvo
, 0);
1124 psb_intel_sdvo_set_encoder_power_state(psb_intel_sdvo
, mode
);
1126 if (mode
== DRM_MODE_DPMS_OFF
) {
1128 temp
= REG_READ_AUX(psb_intel_sdvo
->sdvo_reg
);
1130 temp
= REG_READ(psb_intel_sdvo
->sdvo_reg
);
1132 if ((temp
& SDVO_ENABLE
) != 0) {
1133 psb_intel_sdvo_write_sdvox(psb_intel_sdvo
, temp
& ~SDVO_ENABLE
);
1137 bool input1
, input2
;
1141 temp
= REG_READ_AUX(psb_intel_sdvo
->sdvo_reg
);
1143 temp
= REG_READ(psb_intel_sdvo
->sdvo_reg
);
1145 if ((temp
& SDVO_ENABLE
) == 0)
1146 psb_intel_sdvo_write_sdvox(psb_intel_sdvo
, temp
| SDVO_ENABLE
);
1148 for (i
= 0; i
< 2; i
++)
1149 gma_wait_for_vblank(dev
);
1151 status
= psb_intel_sdvo_get_trained_inputs(psb_intel_sdvo
, &input1
, &input2
);
1152 /* Warn if the device reported failure to sync.
1153 * A lot of SDVO devices fail to notify of sync, but it's
1154 * a given it the status is a success, we succeeded.
1156 if (status
== SDVO_CMD_STATUS_SUCCESS
&& !input1
) {
1157 DRM_DEBUG_KMS("First %s output reported failure to "
1158 "sync\n", SDVO_NAME(psb_intel_sdvo
));
1162 psb_intel_sdvo_set_encoder_power_state(psb_intel_sdvo
, mode
);
1163 psb_intel_sdvo_set_active_outputs(psb_intel_sdvo
, psb_intel_sdvo
->attached_output
);
1168 static enum drm_mode_status
psb_intel_sdvo_mode_valid(struct drm_connector
*connector
,
1169 struct drm_display_mode
*mode
)
1171 struct psb_intel_sdvo
*psb_intel_sdvo
= intel_attached_sdvo(connector
);
1173 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
1174 return MODE_NO_DBLESCAN
;
1176 if (psb_intel_sdvo
->pixel_clock_min
> mode
->clock
)
1177 return MODE_CLOCK_LOW
;
1179 if (psb_intel_sdvo
->pixel_clock_max
< mode
->clock
)
1180 return MODE_CLOCK_HIGH
;
1182 if (psb_intel_sdvo
->is_lvds
) {
1183 if (mode
->hdisplay
> psb_intel_sdvo
->sdvo_lvds_fixed_mode
->hdisplay
)
1186 if (mode
->vdisplay
> psb_intel_sdvo
->sdvo_lvds_fixed_mode
->vdisplay
)
1193 static bool psb_intel_sdvo_get_capabilities(struct psb_intel_sdvo
*psb_intel_sdvo
, struct psb_intel_sdvo_caps
*caps
)
1195 BUILD_BUG_ON(sizeof(*caps
) != 8);
1196 if (!psb_intel_sdvo_get_value(psb_intel_sdvo
,
1197 SDVO_CMD_GET_DEVICE_CAPS
,
1198 caps
, sizeof(*caps
)))
1201 DRM_DEBUG_KMS("SDVO capabilities:\n"
1204 " device_rev_id: %d\n"
1205 " sdvo_version_major: %d\n"
1206 " sdvo_version_minor: %d\n"
1207 " sdvo_inputs_mask: %d\n"
1208 " smooth_scaling: %d\n"
1209 " sharp_scaling: %d\n"
1211 " down_scaling: %d\n"
1212 " stall_support: %d\n"
1213 " output_flags: %d\n",
1216 caps
->device_rev_id
,
1217 caps
->sdvo_version_major
,
1218 caps
->sdvo_version_minor
,
1219 caps
->sdvo_inputs_mask
,
1220 caps
->smooth_scaling
,
1221 caps
->sharp_scaling
,
1224 caps
->stall_support
,
1225 caps
->output_flags
);
1232 struct drm_connector
* psb_intel_sdvo_find(struct drm_device
*dev
, int sdvoB
)
1234 struct drm_connector
*connector
= NULL
;
1235 struct psb_intel_sdvo
*iout
= NULL
;
1236 struct psb_intel_sdvo
*sdvo
;
1238 /* find the sdvo connector */
1239 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1240 iout
= to_psb_intel_sdvo(connector
);
1242 if (iout
->type
!= INTEL_OUTPUT_SDVO
)
1245 sdvo
= iout
->dev_priv
;
1247 if (sdvo
->sdvo_reg
== SDVOB
&& sdvoB
)
1250 if (sdvo
->sdvo_reg
== SDVOC
&& !sdvoB
)
1258 int psb_intel_sdvo_supports_hotplug(struct drm_connector
*connector
)
1262 struct psb_intel_sdvo
*psb_intel_sdvo
;
1263 DRM_DEBUG_KMS("\n");
1268 psb_intel_sdvo
= to_psb_intel_sdvo(connector
);
1270 return psb_intel_sdvo_get_value(psb_intel_sdvo
, SDVO_CMD_GET_HOT_PLUG_SUPPORT
,
1271 &response
, 2) && response
[0];
1274 void psb_intel_sdvo_set_hotplug(struct drm_connector
*connector
, int on
)
1278 struct psb_intel_sdvo
*psb_intel_sdvo
= to_psb_intel_sdvo(connector
);
1280 psb_intel_sdvo_write_cmd(psb_intel_sdvo
, SDVO_CMD_GET_ACTIVE_HOT_PLUG
, NULL
, 0);
1281 psb_intel_sdvo_read_response(psb_intel_sdvo
, &response
, 2);
1284 psb_intel_sdvo_write_cmd(psb_intel_sdvo
, SDVO_CMD_GET_HOT_PLUG_SUPPORT
, NULL
, 0);
1285 status
= psb_intel_sdvo_read_response(psb_intel_sdvo
, &response
, 2);
1287 psb_intel_sdvo_write_cmd(psb_intel_sdvo
, SDVO_CMD_SET_ACTIVE_HOT_PLUG
, &response
, 2);
1291 psb_intel_sdvo_write_cmd(psb_intel_sdvo
, SDVO_CMD_SET_ACTIVE_HOT_PLUG
, &response
, 2);
1294 psb_intel_sdvo_write_cmd(psb_intel_sdvo
, SDVO_CMD_GET_ACTIVE_HOT_PLUG
, NULL
, 0);
1295 psb_intel_sdvo_read_response(psb_intel_sdvo
, &response
, 2);
1300 psb_intel_sdvo_multifunc_encoder(struct psb_intel_sdvo
*psb_intel_sdvo
)
1302 /* Is there more than one type of output? */
1303 int caps
= psb_intel_sdvo
->caps
.output_flags
& 0xf;
1304 return caps
& -caps
;
1307 static struct edid
*
1308 psb_intel_sdvo_get_edid(struct drm_connector
*connector
)
1310 struct psb_intel_sdvo
*sdvo
= intel_attached_sdvo(connector
);
1311 return drm_get_edid(connector
, &sdvo
->ddc
);
1314 /* Mac mini hack -- use the same DDC as the analog connector */
1315 static struct edid
*
1316 psb_intel_sdvo_get_analog_edid(struct drm_connector
*connector
)
1318 struct drm_psb_private
*dev_priv
= connector
->dev
->dev_private
;
1320 return drm_get_edid(connector
,
1321 &dev_priv
->gmbus
[dev_priv
->crt_ddc_pin
].adapter
);
1324 static enum drm_connector_status
1325 psb_intel_sdvo_hdmi_sink_detect(struct drm_connector
*connector
)
1327 struct psb_intel_sdvo
*psb_intel_sdvo
= intel_attached_sdvo(connector
);
1328 enum drm_connector_status status
;
1331 edid
= psb_intel_sdvo_get_edid(connector
);
1333 if (edid
== NULL
&& psb_intel_sdvo_multifunc_encoder(psb_intel_sdvo
)) {
1334 u8 ddc
, saved_ddc
= psb_intel_sdvo
->ddc_bus
;
1337 * Don't use the 1 as the argument of DDC bus switch to get
1338 * the EDID. It is used for SDVO SPD ROM.
1340 for (ddc
= psb_intel_sdvo
->ddc_bus
>> 1; ddc
> 1; ddc
>>= 1) {
1341 psb_intel_sdvo
->ddc_bus
= ddc
;
1342 edid
= psb_intel_sdvo_get_edid(connector
);
1347 * If we found the EDID on the other bus,
1348 * assume that is the correct DDC bus.
1351 psb_intel_sdvo
->ddc_bus
= saved_ddc
;
1355 * When there is no edid and no monitor is connected with VGA
1356 * port, try to use the CRT ddc to read the EDID for DVI-connector.
1359 edid
= psb_intel_sdvo_get_analog_edid(connector
);
1361 status
= connector_status_unknown
;
1363 /* DDC bus is shared, match EDID to connector type */
1364 if (edid
->input
& DRM_EDID_INPUT_DIGITAL
) {
1365 status
= connector_status_connected
;
1366 if (psb_intel_sdvo
->is_hdmi
) {
1367 psb_intel_sdvo
->has_hdmi_monitor
= drm_detect_hdmi_monitor(edid
);
1368 psb_intel_sdvo
->has_hdmi_audio
= drm_detect_monitor_audio(edid
);
1371 status
= connector_status_disconnected
;
1375 if (status
== connector_status_connected
) {
1376 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
= to_psb_intel_sdvo_connector(connector
);
1377 if (psb_intel_sdvo_connector
->force_audio
)
1378 psb_intel_sdvo
->has_hdmi_audio
= psb_intel_sdvo_connector
->force_audio
> 0;
1384 static enum drm_connector_status
1385 psb_intel_sdvo_detect(struct drm_connector
*connector
, bool force
)
1388 struct psb_intel_sdvo
*psb_intel_sdvo
= intel_attached_sdvo(connector
);
1389 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
= to_psb_intel_sdvo_connector(connector
);
1390 enum drm_connector_status ret
;
1392 if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo
,
1393 SDVO_CMD_GET_ATTACHED_DISPLAYS
, NULL
, 0))
1394 return connector_status_unknown
;
1396 /* add 30ms delay when the output type might be TV */
1397 if (psb_intel_sdvo
->caps
.output_flags
&
1398 (SDVO_OUTPUT_SVID0
| SDVO_OUTPUT_CVBS0
))
1401 if (!psb_intel_sdvo_read_response(psb_intel_sdvo
, &response
, 2))
1402 return connector_status_unknown
;
1404 DRM_DEBUG_KMS("SDVO response %d %d [%x]\n",
1405 response
& 0xff, response
>> 8,
1406 psb_intel_sdvo_connector
->output_flag
);
1409 return connector_status_disconnected
;
1411 psb_intel_sdvo
->attached_output
= response
;
1413 psb_intel_sdvo
->has_hdmi_monitor
= false;
1414 psb_intel_sdvo
->has_hdmi_audio
= false;
1416 if ((psb_intel_sdvo_connector
->output_flag
& response
) == 0)
1417 ret
= connector_status_disconnected
;
1418 else if (IS_TMDS(psb_intel_sdvo_connector
))
1419 ret
= psb_intel_sdvo_hdmi_sink_detect(connector
);
1423 /* if we have an edid check it matches the connection */
1424 edid
= psb_intel_sdvo_get_edid(connector
);
1426 edid
= psb_intel_sdvo_get_analog_edid(connector
);
1428 if (edid
->input
& DRM_EDID_INPUT_DIGITAL
)
1429 ret
= connector_status_disconnected
;
1431 ret
= connector_status_connected
;
1434 ret
= connector_status_connected
;
1437 /* May update encoder flag for like clock for SDVO TV, etc.*/
1438 if (ret
== connector_status_connected
) {
1439 psb_intel_sdvo
->is_tv
= false;
1440 psb_intel_sdvo
->is_lvds
= false;
1441 psb_intel_sdvo
->base
.needs_tv_clock
= false;
1443 if (response
& SDVO_TV_MASK
) {
1444 psb_intel_sdvo
->is_tv
= true;
1445 psb_intel_sdvo
->base
.needs_tv_clock
= true;
1447 if (response
& SDVO_LVDS_MASK
)
1448 psb_intel_sdvo
->is_lvds
= psb_intel_sdvo
->sdvo_lvds_fixed_mode
!= NULL
;
1454 static void psb_intel_sdvo_get_ddc_modes(struct drm_connector
*connector
)
1458 /* set the bus switch and get the modes */
1459 edid
= psb_intel_sdvo_get_edid(connector
);
1462 * Mac mini hack. On this device, the DVI-I connector shares one DDC
1463 * link between analog and digital outputs. So, if the regular SDVO
1464 * DDC fails, check to see if the analog output is disconnected, in
1465 * which case we'll look there for the digital DDC data.
1468 edid
= psb_intel_sdvo_get_analog_edid(connector
);
1471 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
= to_psb_intel_sdvo_connector(connector
);
1472 bool monitor_is_digital
= !!(edid
->input
& DRM_EDID_INPUT_DIGITAL
);
1473 bool connector_is_digital
= !!IS_TMDS(psb_intel_sdvo_connector
);
1475 if (connector_is_digital
== monitor_is_digital
) {
1476 drm_connector_update_edid_property(connector
, edid
);
1477 drm_add_edid_modes(connector
, edid
);
1485 * Set of SDVO TV modes.
1486 * Note! This is in reply order (see loop in get_tv_modes).
1487 * XXX: all 60Hz refresh?
1489 static const struct drm_display_mode sdvo_tv_modes
[] = {
1490 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER
, 5815, 320, 321, 384,
1491 416, 0, 200, 201, 232, 233, 0,
1492 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1493 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER
, 6814, 320, 321, 384,
1494 416, 0, 240, 241, 272, 273, 0,
1495 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1496 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER
, 9910, 400, 401, 464,
1497 496, 0, 300, 301, 332, 333, 0,
1498 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1499 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER
, 16913, 640, 641, 704,
1500 736, 0, 350, 351, 382, 383, 0,
1501 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1502 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER
, 19121, 640, 641, 704,
1503 736, 0, 400, 401, 432, 433, 0,
1504 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1505 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 22654, 640, 641, 704,
1506 736, 0, 480, 481, 512, 513, 0,
1507 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1508 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER
, 24624, 704, 705, 768,
1509 800, 0, 480, 481, 512, 513, 0,
1510 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1511 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER
, 29232, 704, 705, 768,
1512 800, 0, 576, 577, 608, 609, 0,
1513 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1514 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER
, 18751, 720, 721, 784,
1515 816, 0, 350, 351, 382, 383, 0,
1516 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1517 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER
, 21199, 720, 721, 784,
1518 816, 0, 400, 401, 432, 433, 0,
1519 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1520 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 25116, 720, 721, 784,
1521 816, 0, 480, 481, 512, 513, 0,
1522 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1523 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER
, 28054, 720, 721, 784,
1524 816, 0, 540, 541, 572, 573, 0,
1525 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1526 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 29816, 720, 721, 784,
1527 816, 0, 576, 577, 608, 609, 0,
1528 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1529 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER
, 31570, 768, 769, 832,
1530 864, 0, 576, 577, 608, 609, 0,
1531 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1532 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 34030, 800, 801, 864,
1533 896, 0, 600, 601, 632, 633, 0,
1534 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1535 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER
, 36581, 832, 833, 896,
1536 928, 0, 624, 625, 656, 657, 0,
1537 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1538 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER
, 48707, 920, 921, 984,
1539 1016, 0, 766, 767, 798, 799, 0,
1540 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1541 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 53827, 1024, 1025, 1088,
1542 1120, 0, 768, 769, 800, 801, 0,
1543 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1544 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 87265, 1280, 1281, 1344,
1545 1376, 0, 1024, 1025, 1056, 1057, 0,
1546 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
1549 static void psb_intel_sdvo_get_tv_modes(struct drm_connector
*connector
)
1551 struct psb_intel_sdvo
*psb_intel_sdvo
= intel_attached_sdvo(connector
);
1552 struct psb_intel_sdvo_sdtv_resolution_request tv_res
;
1553 uint32_t reply
= 0, format_map
= 0;
1556 /* Read the list of supported input resolutions for the selected TV
1559 format_map
= 1 << psb_intel_sdvo
->tv_format_index
;
1560 memcpy(&tv_res
, &format_map
,
1561 min(sizeof(format_map
), sizeof(struct psb_intel_sdvo_sdtv_resolution_request
)));
1563 if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo
, psb_intel_sdvo
->attached_output
))
1566 BUILD_BUG_ON(sizeof(tv_res
) != 3);
1567 if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo
,
1568 SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT
,
1569 &tv_res
, sizeof(tv_res
)))
1571 if (!psb_intel_sdvo_read_response(psb_intel_sdvo
, &reply
, 3))
1574 for (i
= 0; i
< ARRAY_SIZE(sdvo_tv_modes
); i
++)
1575 if (reply
& (1 << i
)) {
1576 struct drm_display_mode
*nmode
;
1577 nmode
= drm_mode_duplicate(connector
->dev
,
1580 drm_mode_probed_add(connector
, nmode
);
1584 static void psb_intel_sdvo_get_lvds_modes(struct drm_connector
*connector
)
1586 struct psb_intel_sdvo
*psb_intel_sdvo
= intel_attached_sdvo(connector
);
1587 struct drm_psb_private
*dev_priv
= connector
->dev
->dev_private
;
1588 struct drm_display_mode
*newmode
;
1591 * Attempt to get the mode list from DDC.
1592 * Assume that the preferred modes are
1593 * arranged in priority order.
1595 psb_intel_ddc_get_modes(connector
, psb_intel_sdvo
->i2c
);
1596 if (list_empty(&connector
->probed_modes
) == false)
1599 /* Fetch modes from VBT */
1600 if (dev_priv
->sdvo_lvds_vbt_mode
!= NULL
) {
1601 newmode
= drm_mode_duplicate(connector
->dev
,
1602 dev_priv
->sdvo_lvds_vbt_mode
);
1603 if (newmode
!= NULL
) {
1604 /* Guarantee the mode is preferred */
1605 newmode
->type
= (DRM_MODE_TYPE_PREFERRED
|
1606 DRM_MODE_TYPE_DRIVER
);
1607 drm_mode_probed_add(connector
, newmode
);
1612 list_for_each_entry(newmode
, &connector
->probed_modes
, head
) {
1613 if (newmode
->type
& DRM_MODE_TYPE_PREFERRED
) {
1614 psb_intel_sdvo
->sdvo_lvds_fixed_mode
=
1615 drm_mode_duplicate(connector
->dev
, newmode
);
1617 drm_mode_set_crtcinfo(psb_intel_sdvo
->sdvo_lvds_fixed_mode
,
1620 psb_intel_sdvo
->is_lvds
= true;
1627 static int psb_intel_sdvo_get_modes(struct drm_connector
*connector
)
1629 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
= to_psb_intel_sdvo_connector(connector
);
1631 if (IS_TV(psb_intel_sdvo_connector
))
1632 psb_intel_sdvo_get_tv_modes(connector
);
1633 else if (IS_LVDS(psb_intel_sdvo_connector
))
1634 psb_intel_sdvo_get_lvds_modes(connector
);
1636 psb_intel_sdvo_get_ddc_modes(connector
);
1638 return !list_empty(&connector
->probed_modes
);
1641 static void psb_intel_sdvo_destroy(struct drm_connector
*connector
)
1643 drm_connector_unregister(connector
);
1644 drm_connector_cleanup(connector
);
1648 static bool psb_intel_sdvo_detect_hdmi_audio(struct drm_connector
*connector
)
1650 struct psb_intel_sdvo
*psb_intel_sdvo
= intel_attached_sdvo(connector
);
1652 bool has_audio
= false;
1654 if (!psb_intel_sdvo
->is_hdmi
)
1657 edid
= psb_intel_sdvo_get_edid(connector
);
1658 if (edid
!= NULL
&& edid
->input
& DRM_EDID_INPUT_DIGITAL
)
1659 has_audio
= drm_detect_monitor_audio(edid
);
1665 psb_intel_sdvo_set_property(struct drm_connector
*connector
,
1666 struct drm_property
*property
,
1669 struct psb_intel_sdvo
*psb_intel_sdvo
= intel_attached_sdvo(connector
);
1670 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
= to_psb_intel_sdvo_connector(connector
);
1671 struct drm_psb_private
*dev_priv
= connector
->dev
->dev_private
;
1672 uint16_t temp_value
;
1676 ret
= drm_object_property_set_value(&connector
->base
, property
, val
);
1680 if (property
== dev_priv
->force_audio_property
) {
1684 if (i
== psb_intel_sdvo_connector
->force_audio
)
1687 psb_intel_sdvo_connector
->force_audio
= i
;
1690 has_audio
= psb_intel_sdvo_detect_hdmi_audio(connector
);
1694 if (has_audio
== psb_intel_sdvo
->has_hdmi_audio
)
1697 psb_intel_sdvo
->has_hdmi_audio
= has_audio
;
1701 if (property
== dev_priv
->broadcast_rgb_property
) {
1702 if (val
== !!psb_intel_sdvo
->color_range
)
1705 psb_intel_sdvo
->color_range
= val
? SDVO_COLOR_RANGE_16_235
: 0;
1709 #define CHECK_PROPERTY(name, NAME) \
1710 if (psb_intel_sdvo_connector->name == property) { \
1711 if (psb_intel_sdvo_connector->cur_##name == temp_value) return 0; \
1712 if (psb_intel_sdvo_connector->max_##name < temp_value) return -EINVAL; \
1713 cmd = SDVO_CMD_SET_##NAME; \
1714 psb_intel_sdvo_connector->cur_##name = temp_value; \
1718 if (property
== psb_intel_sdvo_connector
->tv_format
) {
1719 if (val
>= ARRAY_SIZE(tv_format_names
))
1722 if (psb_intel_sdvo
->tv_format_index
==
1723 psb_intel_sdvo_connector
->tv_format_supported
[val
])
1726 psb_intel_sdvo
->tv_format_index
= psb_intel_sdvo_connector
->tv_format_supported
[val
];
1728 } else if (IS_TV_OR_LVDS(psb_intel_sdvo_connector
)) {
1730 if (psb_intel_sdvo_connector
->left
== property
) {
1731 drm_object_property_set_value(&connector
->base
,
1732 psb_intel_sdvo_connector
->right
, val
);
1733 if (psb_intel_sdvo_connector
->left_margin
== temp_value
)
1736 psb_intel_sdvo_connector
->left_margin
= temp_value
;
1737 psb_intel_sdvo_connector
->right_margin
= temp_value
;
1738 temp_value
= psb_intel_sdvo_connector
->max_hscan
-
1739 psb_intel_sdvo_connector
->left_margin
;
1740 cmd
= SDVO_CMD_SET_OVERSCAN_H
;
1742 } else if (psb_intel_sdvo_connector
->right
== property
) {
1743 drm_object_property_set_value(&connector
->base
,
1744 psb_intel_sdvo_connector
->left
, val
);
1745 if (psb_intel_sdvo_connector
->right_margin
== temp_value
)
1748 psb_intel_sdvo_connector
->left_margin
= temp_value
;
1749 psb_intel_sdvo_connector
->right_margin
= temp_value
;
1750 temp_value
= psb_intel_sdvo_connector
->max_hscan
-
1751 psb_intel_sdvo_connector
->left_margin
;
1752 cmd
= SDVO_CMD_SET_OVERSCAN_H
;
1754 } else if (psb_intel_sdvo_connector
->top
== property
) {
1755 drm_object_property_set_value(&connector
->base
,
1756 psb_intel_sdvo_connector
->bottom
, val
);
1757 if (psb_intel_sdvo_connector
->top_margin
== temp_value
)
1760 psb_intel_sdvo_connector
->top_margin
= temp_value
;
1761 psb_intel_sdvo_connector
->bottom_margin
= temp_value
;
1762 temp_value
= psb_intel_sdvo_connector
->max_vscan
-
1763 psb_intel_sdvo_connector
->top_margin
;
1764 cmd
= SDVO_CMD_SET_OVERSCAN_V
;
1766 } else if (psb_intel_sdvo_connector
->bottom
== property
) {
1767 drm_object_property_set_value(&connector
->base
,
1768 psb_intel_sdvo_connector
->top
, val
);
1769 if (psb_intel_sdvo_connector
->bottom_margin
== temp_value
)
1772 psb_intel_sdvo_connector
->top_margin
= temp_value
;
1773 psb_intel_sdvo_connector
->bottom_margin
= temp_value
;
1774 temp_value
= psb_intel_sdvo_connector
->max_vscan
-
1775 psb_intel_sdvo_connector
->top_margin
;
1776 cmd
= SDVO_CMD_SET_OVERSCAN_V
;
1779 CHECK_PROPERTY(hpos
, HPOS
)
1780 CHECK_PROPERTY(vpos
, VPOS
)
1781 CHECK_PROPERTY(saturation
, SATURATION
)
1782 CHECK_PROPERTY(contrast
, CONTRAST
)
1783 CHECK_PROPERTY(hue
, HUE
)
1784 CHECK_PROPERTY(brightness
, BRIGHTNESS
)
1785 CHECK_PROPERTY(sharpness
, SHARPNESS
)
1786 CHECK_PROPERTY(flicker_filter
, FLICKER_FILTER
)
1787 CHECK_PROPERTY(flicker_filter_2d
, FLICKER_FILTER_2D
)
1788 CHECK_PROPERTY(flicker_filter_adaptive
, FLICKER_FILTER_ADAPTIVE
)
1789 CHECK_PROPERTY(tv_chroma_filter
, TV_CHROMA_FILTER
)
1790 CHECK_PROPERTY(tv_luma_filter
, TV_LUMA_FILTER
)
1791 CHECK_PROPERTY(dot_crawl
, DOT_CRAWL
)
1794 return -EINVAL
; /* unknown property */
1797 if (!psb_intel_sdvo_set_value(psb_intel_sdvo
, cmd
, &temp_value
, 2))
1802 if (psb_intel_sdvo
->base
.base
.crtc
) {
1803 struct drm_crtc
*crtc
= psb_intel_sdvo
->base
.base
.crtc
;
1804 drm_crtc_helper_set_mode(crtc
, &crtc
->mode
, crtc
->x
,
1805 crtc
->y
, crtc
->primary
->fb
);
1809 #undef CHECK_PROPERTY
1812 static void psb_intel_sdvo_save(struct drm_connector
*connector
)
1814 struct drm_device
*dev
= connector
->dev
;
1815 struct gma_encoder
*gma_encoder
= gma_attached_encoder(connector
);
1816 struct psb_intel_sdvo
*sdvo
= to_psb_intel_sdvo(&gma_encoder
->base
);
1818 sdvo
->saveSDVO
= REG_READ(sdvo
->sdvo_reg
);
1821 static void psb_intel_sdvo_restore(struct drm_connector
*connector
)
1823 struct drm_device
*dev
= connector
->dev
;
1824 struct drm_encoder
*encoder
= &gma_attached_encoder(connector
)->base
;
1825 struct psb_intel_sdvo
*sdvo
= to_psb_intel_sdvo(encoder
);
1826 struct drm_crtc
*crtc
= encoder
->crtc
;
1828 REG_WRITE(sdvo
->sdvo_reg
, sdvo
->saveSDVO
);
1830 /* Force a full mode set on the crtc. We're supposed to have the
1831 mode_config lock already. */
1832 if (connector
->status
== connector_status_connected
)
1833 drm_crtc_helper_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
,
1837 static const struct drm_encoder_helper_funcs psb_intel_sdvo_helper_funcs
= {
1838 .dpms
= psb_intel_sdvo_dpms
,
1839 .mode_fixup
= psb_intel_sdvo_mode_fixup
,
1840 .prepare
= gma_encoder_prepare
,
1841 .mode_set
= psb_intel_sdvo_mode_set
,
1842 .commit
= gma_encoder_commit
,
1845 static const struct drm_connector_funcs psb_intel_sdvo_connector_funcs
= {
1846 .dpms
= drm_helper_connector_dpms
,
1847 .detect
= psb_intel_sdvo_detect
,
1848 .fill_modes
= drm_helper_probe_single_connector_modes
,
1849 .set_property
= psb_intel_sdvo_set_property
,
1850 .destroy
= psb_intel_sdvo_destroy
,
1853 static const struct drm_connector_helper_funcs psb_intel_sdvo_connector_helper_funcs
= {
1854 .get_modes
= psb_intel_sdvo_get_modes
,
1855 .mode_valid
= psb_intel_sdvo_mode_valid
,
1856 .best_encoder
= gma_best_encoder
,
1859 static void psb_intel_sdvo_enc_destroy(struct drm_encoder
*encoder
)
1861 struct psb_intel_sdvo
*psb_intel_sdvo
= to_psb_intel_sdvo(encoder
);
1863 if (psb_intel_sdvo
->sdvo_lvds_fixed_mode
!= NULL
)
1864 drm_mode_destroy(encoder
->dev
,
1865 psb_intel_sdvo
->sdvo_lvds_fixed_mode
);
1867 i2c_del_adapter(&psb_intel_sdvo
->ddc
);
1868 gma_encoder_destroy(encoder
);
1871 static const struct drm_encoder_funcs psb_intel_sdvo_enc_funcs
= {
1872 .destroy
= psb_intel_sdvo_enc_destroy
,
1876 psb_intel_sdvo_guess_ddc_bus(struct psb_intel_sdvo
*sdvo
)
1878 /* FIXME: At the moment, ddc_bus = 2 is the only thing that works.
1879 * We need to figure out if this is true for all available poulsbo
1880 * hardware, or if we need to fiddle with the guessing code above.
1881 * The problem might go away if we can parse sdvo mappings from bios */
1886 unsigned int num_bits
;
1888 /* Make a mask of outputs less than or equal to our own priority in the
1891 switch (sdvo
->controlled_output
) {
1892 case SDVO_OUTPUT_LVDS1
:
1893 mask
|= SDVO_OUTPUT_LVDS1
;
1894 case SDVO_OUTPUT_LVDS0
:
1895 mask
|= SDVO_OUTPUT_LVDS0
;
1896 case SDVO_OUTPUT_TMDS1
:
1897 mask
|= SDVO_OUTPUT_TMDS1
;
1898 case SDVO_OUTPUT_TMDS0
:
1899 mask
|= SDVO_OUTPUT_TMDS0
;
1900 case SDVO_OUTPUT_RGB1
:
1901 mask
|= SDVO_OUTPUT_RGB1
;
1902 case SDVO_OUTPUT_RGB0
:
1903 mask
|= SDVO_OUTPUT_RGB0
;
1907 /* Count bits to find what number we are in the priority list. */
1908 mask
&= sdvo
->caps
.output_flags
;
1909 num_bits
= hweight16(mask
);
1910 /* If more than 3 outputs, default to DDC bus 3 for now. */
1914 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
1915 sdvo
->ddc_bus
= 1 << num_bits
;
1920 * Choose the appropriate DDC bus for control bus switch command for this
1921 * SDVO output based on the controlled output.
1923 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
1924 * outputs, then LVDS outputs.
1927 psb_intel_sdvo_select_ddc_bus(struct drm_psb_private
*dev_priv
,
1928 struct psb_intel_sdvo
*sdvo
, u32 reg
)
1930 struct sdvo_device_mapping
*mapping
;
1933 mapping
= &(dev_priv
->sdvo_mappings
[0]);
1935 mapping
= &(dev_priv
->sdvo_mappings
[1]);
1937 if (mapping
->initialized
)
1938 sdvo
->ddc_bus
= 1 << ((mapping
->ddc_pin
& 0xf0) >> 4);
1940 psb_intel_sdvo_guess_ddc_bus(sdvo
);
1944 psb_intel_sdvo_select_i2c_bus(struct drm_psb_private
*dev_priv
,
1945 struct psb_intel_sdvo
*sdvo
, u32 reg
)
1947 struct sdvo_device_mapping
*mapping
;
1951 mapping
= &dev_priv
->sdvo_mappings
[0];
1953 mapping
= &dev_priv
->sdvo_mappings
[1];
1955 pin
= GMBUS_PORT_DPB
;
1956 speed
= GMBUS_RATE_1MHZ
>> 8;
1957 if (mapping
->initialized
) {
1958 pin
= mapping
->i2c_pin
;
1959 speed
= mapping
->i2c_speed
;
1962 if (pin
< GMBUS_NUM_PORTS
) {
1963 sdvo
->i2c
= &dev_priv
->gmbus
[pin
].adapter
;
1964 gma_intel_gmbus_set_speed(sdvo
->i2c
, speed
);
1965 gma_intel_gmbus_force_bit(sdvo
->i2c
, true);
1967 sdvo
->i2c
= &dev_priv
->gmbus
[GMBUS_PORT_DPB
].adapter
;
1971 psb_intel_sdvo_is_hdmi_connector(struct psb_intel_sdvo
*psb_intel_sdvo
, int device
)
1973 return psb_intel_sdvo_check_supp_encode(psb_intel_sdvo
);
1977 psb_intel_sdvo_get_slave_addr(struct drm_device
*dev
, int sdvo_reg
)
1979 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
1980 struct sdvo_device_mapping
*my_mapping
, *other_mapping
;
1982 if (IS_SDVOB(sdvo_reg
)) {
1983 my_mapping
= &dev_priv
->sdvo_mappings
[0];
1984 other_mapping
= &dev_priv
->sdvo_mappings
[1];
1986 my_mapping
= &dev_priv
->sdvo_mappings
[1];
1987 other_mapping
= &dev_priv
->sdvo_mappings
[0];
1990 /* If the BIOS described our SDVO device, take advantage of it. */
1991 if (my_mapping
->slave_addr
)
1992 return my_mapping
->slave_addr
;
1994 /* If the BIOS only described a different SDVO device, use the
1995 * address that it isn't using.
1997 if (other_mapping
->slave_addr
) {
1998 if (other_mapping
->slave_addr
== 0x70)
2004 /* No SDVO device info is found for another DVO port,
2005 * so use mapping assumption we had before BIOS parsing.
2007 if (IS_SDVOB(sdvo_reg
))
2014 psb_intel_sdvo_connector_init(struct psb_intel_sdvo_connector
*connector
,
2015 struct psb_intel_sdvo
*encoder
)
2017 drm_connector_init(encoder
->base
.base
.dev
,
2018 &connector
->base
.base
,
2019 &psb_intel_sdvo_connector_funcs
,
2020 connector
->base
.base
.connector_type
);
2022 drm_connector_helper_add(&connector
->base
.base
,
2023 &psb_intel_sdvo_connector_helper_funcs
);
2025 connector
->base
.base
.interlace_allowed
= 0;
2026 connector
->base
.base
.doublescan_allowed
= 0;
2027 connector
->base
.base
.display_info
.subpixel_order
= SubPixelHorizontalRGB
;
2029 connector
->base
.save
= psb_intel_sdvo_save
;
2030 connector
->base
.restore
= psb_intel_sdvo_restore
;
2032 gma_connector_attach_encoder(&connector
->base
, &encoder
->base
);
2033 drm_connector_register(&connector
->base
.base
);
2037 psb_intel_sdvo_add_hdmi_properties(struct psb_intel_sdvo_connector
*connector
)
2039 /* FIXME: We don't support HDMI at the moment
2040 struct drm_device *dev = connector->base.base.dev;
2042 intel_attach_force_audio_property(&connector->base.base);
2043 intel_attach_broadcast_rgb_property(&connector->base.base);
2048 psb_intel_sdvo_dvi_init(struct psb_intel_sdvo
*psb_intel_sdvo
, int device
)
2050 struct drm_encoder
*encoder
= &psb_intel_sdvo
->base
.base
;
2051 struct drm_connector
*connector
;
2052 struct gma_connector
*intel_connector
;
2053 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
;
2055 psb_intel_sdvo_connector
= kzalloc(sizeof(struct psb_intel_sdvo_connector
), GFP_KERNEL
);
2056 if (!psb_intel_sdvo_connector
)
2060 psb_intel_sdvo
->controlled_output
|= SDVO_OUTPUT_TMDS0
;
2061 psb_intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_TMDS0
;
2062 } else if (device
== 1) {
2063 psb_intel_sdvo
->controlled_output
|= SDVO_OUTPUT_TMDS1
;
2064 psb_intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_TMDS1
;
2067 intel_connector
= &psb_intel_sdvo_connector
->base
;
2068 connector
= &intel_connector
->base
;
2069 // connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
2070 encoder
->encoder_type
= DRM_MODE_ENCODER_TMDS
;
2071 connector
->connector_type
= DRM_MODE_CONNECTOR_DVID
;
2073 if (psb_intel_sdvo_is_hdmi_connector(psb_intel_sdvo
, device
)) {
2074 connector
->connector_type
= DRM_MODE_CONNECTOR_HDMIA
;
2075 psb_intel_sdvo
->is_hdmi
= true;
2077 psb_intel_sdvo
->base
.clone_mask
= ((1 << INTEL_SDVO_NON_TV_CLONE_BIT
) |
2078 (1 << INTEL_ANALOG_CLONE_BIT
));
2080 psb_intel_sdvo_connector_init(psb_intel_sdvo_connector
, psb_intel_sdvo
);
2081 if (psb_intel_sdvo
->is_hdmi
)
2082 psb_intel_sdvo_add_hdmi_properties(psb_intel_sdvo_connector
);
2088 psb_intel_sdvo_tv_init(struct psb_intel_sdvo
*psb_intel_sdvo
, int type
)
2090 struct drm_encoder
*encoder
= &psb_intel_sdvo
->base
.base
;
2091 struct drm_connector
*connector
;
2092 struct gma_connector
*intel_connector
;
2093 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
;
2095 psb_intel_sdvo_connector
= kzalloc(sizeof(struct psb_intel_sdvo_connector
), GFP_KERNEL
);
2096 if (!psb_intel_sdvo_connector
)
2099 intel_connector
= &psb_intel_sdvo_connector
->base
;
2100 connector
= &intel_connector
->base
;
2101 encoder
->encoder_type
= DRM_MODE_ENCODER_TVDAC
;
2102 connector
->connector_type
= DRM_MODE_CONNECTOR_SVIDEO
;
2104 psb_intel_sdvo
->controlled_output
|= type
;
2105 psb_intel_sdvo_connector
->output_flag
= type
;
2107 psb_intel_sdvo
->is_tv
= true;
2108 psb_intel_sdvo
->base
.needs_tv_clock
= true;
2109 psb_intel_sdvo
->base
.clone_mask
= 1 << INTEL_SDVO_TV_CLONE_BIT
;
2111 psb_intel_sdvo_connector_init(psb_intel_sdvo_connector
, psb_intel_sdvo
);
2113 if (!psb_intel_sdvo_tv_create_property(psb_intel_sdvo
, psb_intel_sdvo_connector
, type
))
2116 if (!psb_intel_sdvo_create_enhance_property(psb_intel_sdvo
, psb_intel_sdvo_connector
))
2122 psb_intel_sdvo_destroy(connector
);
2127 psb_intel_sdvo_analog_init(struct psb_intel_sdvo
*psb_intel_sdvo
, int device
)
2129 struct drm_encoder
*encoder
= &psb_intel_sdvo
->base
.base
;
2130 struct drm_connector
*connector
;
2131 struct gma_connector
*intel_connector
;
2132 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
;
2134 psb_intel_sdvo_connector
= kzalloc(sizeof(struct psb_intel_sdvo_connector
), GFP_KERNEL
);
2135 if (!psb_intel_sdvo_connector
)
2138 intel_connector
= &psb_intel_sdvo_connector
->base
;
2139 connector
= &intel_connector
->base
;
2140 connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
2141 encoder
->encoder_type
= DRM_MODE_ENCODER_DAC
;
2142 connector
->connector_type
= DRM_MODE_CONNECTOR_VGA
;
2145 psb_intel_sdvo
->controlled_output
|= SDVO_OUTPUT_RGB0
;
2146 psb_intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_RGB0
;
2147 } else if (device
== 1) {
2148 psb_intel_sdvo
->controlled_output
|= SDVO_OUTPUT_RGB1
;
2149 psb_intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_RGB1
;
2152 psb_intel_sdvo
->base
.clone_mask
= ((1 << INTEL_SDVO_NON_TV_CLONE_BIT
) |
2153 (1 << INTEL_ANALOG_CLONE_BIT
));
2155 psb_intel_sdvo_connector_init(psb_intel_sdvo_connector
,
2161 psb_intel_sdvo_lvds_init(struct psb_intel_sdvo
*psb_intel_sdvo
, int device
)
2163 struct drm_encoder
*encoder
= &psb_intel_sdvo
->base
.base
;
2164 struct drm_connector
*connector
;
2165 struct gma_connector
*intel_connector
;
2166 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
;
2168 psb_intel_sdvo_connector
= kzalloc(sizeof(struct psb_intel_sdvo_connector
), GFP_KERNEL
);
2169 if (!psb_intel_sdvo_connector
)
2172 intel_connector
= &psb_intel_sdvo_connector
->base
;
2173 connector
= &intel_connector
->base
;
2174 encoder
->encoder_type
= DRM_MODE_ENCODER_LVDS
;
2175 connector
->connector_type
= DRM_MODE_CONNECTOR_LVDS
;
2178 psb_intel_sdvo
->controlled_output
|= SDVO_OUTPUT_LVDS0
;
2179 psb_intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_LVDS0
;
2180 } else if (device
== 1) {
2181 psb_intel_sdvo
->controlled_output
|= SDVO_OUTPUT_LVDS1
;
2182 psb_intel_sdvo_connector
->output_flag
= SDVO_OUTPUT_LVDS1
;
2185 psb_intel_sdvo
->base
.clone_mask
= ((1 << INTEL_ANALOG_CLONE_BIT
) |
2186 (1 << INTEL_SDVO_LVDS_CLONE_BIT
));
2188 psb_intel_sdvo_connector_init(psb_intel_sdvo_connector
, psb_intel_sdvo
);
2189 if (!psb_intel_sdvo_create_enhance_property(psb_intel_sdvo
, psb_intel_sdvo_connector
))
2195 psb_intel_sdvo_destroy(connector
);
2200 psb_intel_sdvo_output_setup(struct psb_intel_sdvo
*psb_intel_sdvo
, uint16_t flags
)
2202 psb_intel_sdvo
->is_tv
= false;
2203 psb_intel_sdvo
->base
.needs_tv_clock
= false;
2204 psb_intel_sdvo
->is_lvds
= false;
2206 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
2208 if (flags
& SDVO_OUTPUT_TMDS0
)
2209 if (!psb_intel_sdvo_dvi_init(psb_intel_sdvo
, 0))
2212 if ((flags
& SDVO_TMDS_MASK
) == SDVO_TMDS_MASK
)
2213 if (!psb_intel_sdvo_dvi_init(psb_intel_sdvo
, 1))
2216 /* TV has no XXX1 function block */
2217 if (flags
& SDVO_OUTPUT_SVID0
)
2218 if (!psb_intel_sdvo_tv_init(psb_intel_sdvo
, SDVO_OUTPUT_SVID0
))
2221 if (flags
& SDVO_OUTPUT_CVBS0
)
2222 if (!psb_intel_sdvo_tv_init(psb_intel_sdvo
, SDVO_OUTPUT_CVBS0
))
2225 if (flags
& SDVO_OUTPUT_RGB0
)
2226 if (!psb_intel_sdvo_analog_init(psb_intel_sdvo
, 0))
2229 if ((flags
& SDVO_RGB_MASK
) == SDVO_RGB_MASK
)
2230 if (!psb_intel_sdvo_analog_init(psb_intel_sdvo
, 1))
2233 if (flags
& SDVO_OUTPUT_LVDS0
)
2234 if (!psb_intel_sdvo_lvds_init(psb_intel_sdvo
, 0))
2237 if ((flags
& SDVO_LVDS_MASK
) == SDVO_LVDS_MASK
)
2238 if (!psb_intel_sdvo_lvds_init(psb_intel_sdvo
, 1))
2241 if ((flags
& SDVO_OUTPUT_MASK
) == 0) {
2242 unsigned char bytes
[2];
2244 psb_intel_sdvo
->controlled_output
= 0;
2245 memcpy(bytes
, &psb_intel_sdvo
->caps
.output_flags
, 2);
2246 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2247 SDVO_NAME(psb_intel_sdvo
),
2248 bytes
[0], bytes
[1]);
2251 psb_intel_sdvo
->base
.crtc_mask
= (1 << 0) | (1 << 1);
2256 static bool psb_intel_sdvo_tv_create_property(struct psb_intel_sdvo
*psb_intel_sdvo
,
2257 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
,
2260 struct drm_device
*dev
= psb_intel_sdvo
->base
.base
.dev
;
2261 struct psb_intel_sdvo_tv_format format
;
2262 uint32_t format_map
, i
;
2264 if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo
, type
))
2267 BUILD_BUG_ON(sizeof(format
) != 6);
2268 if (!psb_intel_sdvo_get_value(psb_intel_sdvo
,
2269 SDVO_CMD_GET_SUPPORTED_TV_FORMATS
,
2270 &format
, sizeof(format
)))
2273 memcpy(&format_map
, &format
, min(sizeof(format_map
), sizeof(format
)));
2275 if (format_map
== 0)
2278 psb_intel_sdvo_connector
->format_supported_num
= 0;
2279 for (i
= 0 ; i
< ARRAY_SIZE(tv_format_names
); i
++)
2280 if (format_map
& (1 << i
))
2281 psb_intel_sdvo_connector
->tv_format_supported
[psb_intel_sdvo_connector
->format_supported_num
++] = i
;
2284 psb_intel_sdvo_connector
->tv_format
=
2285 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
2286 "mode", psb_intel_sdvo_connector
->format_supported_num
);
2287 if (!psb_intel_sdvo_connector
->tv_format
)
2290 for (i
= 0; i
< psb_intel_sdvo_connector
->format_supported_num
; i
++)
2291 drm_property_add_enum(
2292 psb_intel_sdvo_connector
->tv_format
,
2293 i
, tv_format_names
[psb_intel_sdvo_connector
->tv_format_supported
[i
]]);
2295 psb_intel_sdvo
->tv_format_index
= psb_intel_sdvo_connector
->tv_format_supported
[0];
2296 drm_object_attach_property(&psb_intel_sdvo_connector
->base
.base
.base
,
2297 psb_intel_sdvo_connector
->tv_format
, 0);
2302 #define ENHANCEMENT(name, NAME) do { \
2303 if (enhancements.name) { \
2304 if (!psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
2305 !psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
2307 psb_intel_sdvo_connector->max_##name = data_value[0]; \
2308 psb_intel_sdvo_connector->cur_##name = response; \
2309 psb_intel_sdvo_connector->name = \
2310 drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
2311 if (!psb_intel_sdvo_connector->name) return false; \
2312 drm_object_attach_property(&connector->base, \
2313 psb_intel_sdvo_connector->name, \
2314 psb_intel_sdvo_connector->cur_##name); \
2315 DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
2316 data_value[0], data_value[1], response); \
2321 psb_intel_sdvo_create_enhance_property_tv(struct psb_intel_sdvo
*psb_intel_sdvo
,
2322 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
,
2323 struct psb_intel_sdvo_enhancements_reply enhancements
)
2325 struct drm_device
*dev
= psb_intel_sdvo
->base
.base
.dev
;
2326 struct drm_connector
*connector
= &psb_intel_sdvo_connector
->base
.base
;
2327 uint16_t response
, data_value
[2];
2329 /* when horizontal overscan is supported, Add the left/right property */
2330 if (enhancements
.overscan_h
) {
2331 if (!psb_intel_sdvo_get_value(psb_intel_sdvo
,
2332 SDVO_CMD_GET_MAX_OVERSCAN_H
,
2336 if (!psb_intel_sdvo_get_value(psb_intel_sdvo
,
2337 SDVO_CMD_GET_OVERSCAN_H
,
2341 psb_intel_sdvo_connector
->max_hscan
= data_value
[0];
2342 psb_intel_sdvo_connector
->left_margin
= data_value
[0] - response
;
2343 psb_intel_sdvo_connector
->right_margin
= psb_intel_sdvo_connector
->left_margin
;
2344 psb_intel_sdvo_connector
->left
=
2345 drm_property_create_range(dev
, 0, "left_margin", 0, data_value
[0]);
2346 if (!psb_intel_sdvo_connector
->left
)
2349 drm_object_attach_property(&connector
->base
,
2350 psb_intel_sdvo_connector
->left
,
2351 psb_intel_sdvo_connector
->left_margin
);
2353 psb_intel_sdvo_connector
->right
=
2354 drm_property_create_range(dev
, 0, "right_margin", 0, data_value
[0]);
2355 if (!psb_intel_sdvo_connector
->right
)
2358 drm_object_attach_property(&connector
->base
,
2359 psb_intel_sdvo_connector
->right
,
2360 psb_intel_sdvo_connector
->right_margin
);
2361 DRM_DEBUG_KMS("h_overscan: max %d, "
2362 "default %d, current %d\n",
2363 data_value
[0], data_value
[1], response
);
2366 if (enhancements
.overscan_v
) {
2367 if (!psb_intel_sdvo_get_value(psb_intel_sdvo
,
2368 SDVO_CMD_GET_MAX_OVERSCAN_V
,
2372 if (!psb_intel_sdvo_get_value(psb_intel_sdvo
,
2373 SDVO_CMD_GET_OVERSCAN_V
,
2377 psb_intel_sdvo_connector
->max_vscan
= data_value
[0];
2378 psb_intel_sdvo_connector
->top_margin
= data_value
[0] - response
;
2379 psb_intel_sdvo_connector
->bottom_margin
= psb_intel_sdvo_connector
->top_margin
;
2380 psb_intel_sdvo_connector
->top
=
2381 drm_property_create_range(dev
, 0, "top_margin", 0, data_value
[0]);
2382 if (!psb_intel_sdvo_connector
->top
)
2385 drm_object_attach_property(&connector
->base
,
2386 psb_intel_sdvo_connector
->top
,
2387 psb_intel_sdvo_connector
->top_margin
);
2389 psb_intel_sdvo_connector
->bottom
=
2390 drm_property_create_range(dev
, 0, "bottom_margin", 0, data_value
[0]);
2391 if (!psb_intel_sdvo_connector
->bottom
)
2394 drm_object_attach_property(&connector
->base
,
2395 psb_intel_sdvo_connector
->bottom
,
2396 psb_intel_sdvo_connector
->bottom_margin
);
2397 DRM_DEBUG_KMS("v_overscan: max %d, "
2398 "default %d, current %d\n",
2399 data_value
[0], data_value
[1], response
);
2402 ENHANCEMENT(hpos
, HPOS
);
2403 ENHANCEMENT(vpos
, VPOS
);
2404 ENHANCEMENT(saturation
, SATURATION
);
2405 ENHANCEMENT(contrast
, CONTRAST
);
2406 ENHANCEMENT(hue
, HUE
);
2407 ENHANCEMENT(sharpness
, SHARPNESS
);
2408 ENHANCEMENT(brightness
, BRIGHTNESS
);
2409 ENHANCEMENT(flicker_filter
, FLICKER_FILTER
);
2410 ENHANCEMENT(flicker_filter_adaptive
, FLICKER_FILTER_ADAPTIVE
);
2411 ENHANCEMENT(flicker_filter_2d
, FLICKER_FILTER_2D
);
2412 ENHANCEMENT(tv_chroma_filter
, TV_CHROMA_FILTER
);
2413 ENHANCEMENT(tv_luma_filter
, TV_LUMA_FILTER
);
2415 if (enhancements
.dot_crawl
) {
2416 if (!psb_intel_sdvo_get_value(psb_intel_sdvo
, SDVO_CMD_GET_DOT_CRAWL
, &response
, 2))
2419 psb_intel_sdvo_connector
->max_dot_crawl
= 1;
2420 psb_intel_sdvo_connector
->cur_dot_crawl
= response
& 0x1;
2421 psb_intel_sdvo_connector
->dot_crawl
=
2422 drm_property_create_range(dev
, 0, "dot_crawl", 0, 1);
2423 if (!psb_intel_sdvo_connector
->dot_crawl
)
2426 drm_object_attach_property(&connector
->base
,
2427 psb_intel_sdvo_connector
->dot_crawl
,
2428 psb_intel_sdvo_connector
->cur_dot_crawl
);
2429 DRM_DEBUG_KMS("dot crawl: current %d\n", response
);
2436 psb_intel_sdvo_create_enhance_property_lvds(struct psb_intel_sdvo
*psb_intel_sdvo
,
2437 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
,
2438 struct psb_intel_sdvo_enhancements_reply enhancements
)
2440 struct drm_device
*dev
= psb_intel_sdvo
->base
.base
.dev
;
2441 struct drm_connector
*connector
= &psb_intel_sdvo_connector
->base
.base
;
2442 uint16_t response
, data_value
[2];
2444 ENHANCEMENT(brightness
, BRIGHTNESS
);
2450 static bool psb_intel_sdvo_create_enhance_property(struct psb_intel_sdvo
*psb_intel_sdvo
,
2451 struct psb_intel_sdvo_connector
*psb_intel_sdvo_connector
)
2454 struct psb_intel_sdvo_enhancements_reply reply
;
2458 BUILD_BUG_ON(sizeof(enhancements
) != 2);
2460 enhancements
.response
= 0;
2461 psb_intel_sdvo_get_value(psb_intel_sdvo
,
2462 SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS
,
2463 &enhancements
, sizeof(enhancements
));
2464 if (enhancements
.response
== 0) {
2465 DRM_DEBUG_KMS("No enhancement is supported\n");
2469 if (IS_TV(psb_intel_sdvo_connector
))
2470 return psb_intel_sdvo_create_enhance_property_tv(psb_intel_sdvo
, psb_intel_sdvo_connector
, enhancements
.reply
);
2471 else if(IS_LVDS(psb_intel_sdvo_connector
))
2472 return psb_intel_sdvo_create_enhance_property_lvds(psb_intel_sdvo
, psb_intel_sdvo_connector
, enhancements
.reply
);
2477 static int psb_intel_sdvo_ddc_proxy_xfer(struct i2c_adapter
*adapter
,
2478 struct i2c_msg
*msgs
,
2481 struct psb_intel_sdvo
*sdvo
= adapter
->algo_data
;
2483 if (!psb_intel_sdvo_set_control_bus_switch(sdvo
, sdvo
->ddc_bus
))
2486 return sdvo
->i2c
->algo
->master_xfer(sdvo
->i2c
, msgs
, num
);
2489 static u32
psb_intel_sdvo_ddc_proxy_func(struct i2c_adapter
*adapter
)
2491 struct psb_intel_sdvo
*sdvo
= adapter
->algo_data
;
2492 return sdvo
->i2c
->algo
->functionality(sdvo
->i2c
);
2495 static const struct i2c_algorithm psb_intel_sdvo_ddc_proxy
= {
2496 .master_xfer
= psb_intel_sdvo_ddc_proxy_xfer
,
2497 .functionality
= psb_intel_sdvo_ddc_proxy_func
2501 psb_intel_sdvo_init_ddc_proxy(struct psb_intel_sdvo
*sdvo
,
2502 struct drm_device
*dev
)
2504 sdvo
->ddc
.owner
= THIS_MODULE
;
2505 sdvo
->ddc
.class = I2C_CLASS_DDC
;
2506 snprintf(sdvo
->ddc
.name
, I2C_NAME_SIZE
, "SDVO DDC proxy");
2507 sdvo
->ddc
.dev
.parent
= &dev
->pdev
->dev
;
2508 sdvo
->ddc
.algo_data
= sdvo
;
2509 sdvo
->ddc
.algo
= &psb_intel_sdvo_ddc_proxy
;
2511 return i2c_add_adapter(&sdvo
->ddc
) == 0;
2514 bool psb_intel_sdvo_init(struct drm_device
*dev
, int sdvo_reg
)
2516 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
2517 struct gma_encoder
*gma_encoder
;
2518 struct psb_intel_sdvo
*psb_intel_sdvo
;
2521 psb_intel_sdvo
= kzalloc(sizeof(struct psb_intel_sdvo
), GFP_KERNEL
);
2522 if (!psb_intel_sdvo
)
2525 psb_intel_sdvo
->sdvo_reg
= sdvo_reg
;
2526 psb_intel_sdvo
->slave_addr
= psb_intel_sdvo_get_slave_addr(dev
, sdvo_reg
) >> 1;
2527 psb_intel_sdvo_select_i2c_bus(dev_priv
, psb_intel_sdvo
, sdvo_reg
);
2528 if (!psb_intel_sdvo_init_ddc_proxy(psb_intel_sdvo
, dev
)) {
2529 kfree(psb_intel_sdvo
);
2533 /* encoder type will be decided later */
2534 gma_encoder
= &psb_intel_sdvo
->base
;
2535 gma_encoder
->type
= INTEL_OUTPUT_SDVO
;
2536 drm_encoder_init(dev
, &gma_encoder
->base
, &psb_intel_sdvo_enc_funcs
,
2539 /* Read the regs to test if we can talk to the device */
2540 for (i
= 0; i
< 0x40; i
++) {
2543 if (!psb_intel_sdvo_read_byte(psb_intel_sdvo
, i
, &byte
)) {
2544 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
2545 IS_SDVOB(sdvo_reg
) ? 'B' : 'C');
2550 if (IS_SDVOB(sdvo_reg
))
2551 dev_priv
->hotplug_supported_mask
|= SDVOB_HOTPLUG_INT_STATUS
;
2553 dev_priv
->hotplug_supported_mask
|= SDVOC_HOTPLUG_INT_STATUS
;
2555 drm_encoder_helper_add(&gma_encoder
->base
, &psb_intel_sdvo_helper_funcs
);
2557 /* In default case sdvo lvds is false */
2558 if (!psb_intel_sdvo_get_capabilities(psb_intel_sdvo
, &psb_intel_sdvo
->caps
))
2561 if (psb_intel_sdvo_output_setup(psb_intel_sdvo
,
2562 psb_intel_sdvo
->caps
.output_flags
) != true) {
2563 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
2564 IS_SDVOB(sdvo_reg
) ? 'B' : 'C');
2568 psb_intel_sdvo_select_ddc_bus(dev_priv
, psb_intel_sdvo
, sdvo_reg
);
2570 /* Set the input timing to the screen. Assume always input 0. */
2571 if (!psb_intel_sdvo_set_target_input(psb_intel_sdvo
))
2574 if (!psb_intel_sdvo_get_input_pixel_clock_range(psb_intel_sdvo
,
2575 &psb_intel_sdvo
->pixel_clock_min
,
2576 &psb_intel_sdvo
->pixel_clock_max
))
2579 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
2580 "clock range %dMHz - %dMHz, "
2581 "input 1: %c, input 2: %c, "
2582 "output 1: %c, output 2: %c\n",
2583 SDVO_NAME(psb_intel_sdvo
),
2584 psb_intel_sdvo
->caps
.vendor_id
, psb_intel_sdvo
->caps
.device_id
,
2585 psb_intel_sdvo
->caps
.device_rev_id
,
2586 psb_intel_sdvo
->pixel_clock_min
/ 1000,
2587 psb_intel_sdvo
->pixel_clock_max
/ 1000,
2588 (psb_intel_sdvo
->caps
.sdvo_inputs_mask
& 0x1) ? 'Y' : 'N',
2589 (psb_intel_sdvo
->caps
.sdvo_inputs_mask
& 0x2) ? 'Y' : 'N',
2590 /* check currently supported outputs */
2591 psb_intel_sdvo
->caps
.output_flags
&
2592 (SDVO_OUTPUT_TMDS0
| SDVO_OUTPUT_RGB0
) ? 'Y' : 'N',
2593 psb_intel_sdvo
->caps
.output_flags
&
2594 (SDVO_OUTPUT_TMDS1
| SDVO_OUTPUT_RGB1
) ? 'Y' : 'N');
2598 drm_encoder_cleanup(&gma_encoder
->base
);
2599 i2c_del_adapter(&psb_intel_sdvo
->ddc
);
2600 kfree(psb_intel_sdvo
);