Commit | Line | Data |
---|---|---|
89c78134 | 1 | /* |
5736995b PJ |
2 | * Copyright 2006 Dave Airlie <airlied@linux.ie> |
3 | * Copyright © 2006-2007 Intel Corporation | |
4 | * Jesse Barnes <jesse.barnes@intel.com> | |
89c78134 | 5 | * |
5736995b PJ |
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: | |
89c78134 | 12 | * |
5736995b PJ |
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. | |
89c78134 | 16 | * |
5736995b PJ |
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. | |
89c78134 AC |
24 | * |
25 | * Authors: | |
26 | * Eric Anholt <eric@anholt.net> | |
27 | */ | |
5736995b | 28 | #include <linux/module.h> |
89c78134 | 29 | #include <linux/i2c.h> |
5736995b | 30 | #include <linux/slab.h> |
89c78134 | 31 | #include <linux/delay.h> |
5736995b PJ |
32 | #include "drmP.h" |
33 | #include "drm.h" | |
34 | #include "drm_crtc.h" | |
35 | #include "drm_edid.h" | |
89c78134 | 36 | #include "psb_intel_drv.h" |
5736995b PJ |
37 | #include "gma_drm.h" |
38 | #include "psb_drv.h" | |
89c78134 | 39 | #include "psb_intel_sdvo_regs.h" |
5736995b PJ |
40 | #include "psb_intel_reg.h" |
41 | ||
42 | #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1) | |
43 | #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1) | |
44 | #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1) | |
45 | #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0) | |
46 | ||
47 | #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\ | |
48 | SDVO_TV_MASK) | |
49 | ||
50 | #define IS_TV(c) (c->output_flag & SDVO_TV_MASK) | |
51 | #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK) | |
52 | #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK) | |
53 | #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK)) | |
89c78134 | 54 | |
89c78134 | 55 | |
5736995b PJ |
56 | static const char *tv_format_names[] = { |
57 | "NTSC_M" , "NTSC_J" , "NTSC_443", | |
58 | "PAL_B" , "PAL_D" , "PAL_G" , | |
59 | "PAL_H" , "PAL_I" , "PAL_M" , | |
60 | "PAL_N" , "PAL_NC" , "PAL_60" , | |
61 | "SECAM_B" , "SECAM_D" , "SECAM_G" , | |
62 | "SECAM_K" , "SECAM_K1", "SECAM_L" , | |
63 | "SECAM_60" | |
64 | }; | |
65 | ||
66 | #define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names)) | |
67 | ||
68 | struct psb_intel_sdvo { | |
69 | struct psb_intel_encoder base; | |
70 | ||
71 | struct i2c_adapter *i2c; | |
72 | u8 slave_addr; | |
89c78134 | 73 | |
5736995b PJ |
74 | struct i2c_adapter ddc; |
75 | ||
76 | /* Register for the SDVO device: SDVOB or SDVOC */ | |
77 | int sdvo_reg; | |
78 | ||
79 | /* Active outputs controlled by this SDVO output */ | |
80 | uint16_t controlled_output; | |
81 | ||
82 | /* | |
83 | * Capabilities of the SDVO device returned by | |
84 | * i830_sdvo_get_capabilities() | |
85 | */ | |
89c78134 | 86 | struct psb_intel_sdvo_caps caps; |
5736995b PJ |
87 | |
88 | /* Pixel clock limitations reported by the SDVO device, in kHz */ | |
89c78134 AC |
89 | int pixel_clock_min, pixel_clock_max; |
90 | ||
5736995b PJ |
91 | /* |
92 | * For multiple function SDVO device, | |
93 | * this is for current attached outputs. | |
94 | */ | |
95 | uint16_t attached_output; | |
96 | ||
97 | /** | |
98 | * This is used to select the color range of RBG outputs in HDMI mode. | |
99 | * It is only valid when using TMDS encoding and 8 bit per color mode. | |
100 | */ | |
101 | uint32_t color_range; | |
102 | ||
103 | /** | |
104 | * This is set if we're going to treat the device as TV-out. | |
105 | * | |
106 | * While we have these nice friendly flags for output types that ought | |
107 | * to decide this for us, the S-Video output on our HDMI+S-Video card | |
108 | * shows up as RGB1 (VGA). | |
109 | */ | |
110 | bool is_tv; | |
111 | ||
112 | /* This is for current tv format name */ | |
113 | int tv_format_index; | |
114 | ||
115 | /** | |
116 | * This is set if we treat the device as HDMI, instead of DVI. | |
117 | */ | |
118 | bool is_hdmi; | |
119 | bool has_hdmi_monitor; | |
120 | bool has_hdmi_audio; | |
121 | ||
122 | /** | |
123 | * This is set if we detect output of sdvo device as LVDS and | |
124 | * have a valid fixed mode to use with the panel. | |
125 | */ | |
126 | bool is_lvds; | |
127 | ||
128 | /** | |
129 | * This is sdvo fixed pannel mode pointer | |
130 | */ | |
131 | struct drm_display_mode *sdvo_lvds_fixed_mode; | |
132 | ||
133 | /* DDC bus used by this SDVO encoder */ | |
134 | uint8_t ddc_bus; | |
135 | ||
136 | /* Input timings for adjusted_mode */ | |
137 | struct psb_intel_sdvo_dtd input_dtd; | |
138 | }; | |
89c78134 | 139 | |
5736995b PJ |
140 | struct psb_intel_sdvo_connector { |
141 | struct psb_intel_connector base; | |
142 | ||
143 | /* Mark the type of connector */ | |
144 | uint16_t output_flag; | |
145 | ||
146 | int force_audio; | |
147 | ||
148 | /* This contains all current supported TV format */ | |
149 | u8 tv_format_supported[TV_FORMAT_NUM]; | |
150 | int format_supported_num; | |
151 | struct drm_property *tv_format; | |
152 | ||
153 | /* add the property for the SDVO-TV */ | |
154 | struct drm_property *left; | |
155 | struct drm_property *right; | |
156 | struct drm_property *top; | |
157 | struct drm_property *bottom; | |
158 | struct drm_property *hpos; | |
159 | struct drm_property *vpos; | |
160 | struct drm_property *contrast; | |
161 | struct drm_property *saturation; | |
162 | struct drm_property *hue; | |
163 | struct drm_property *sharpness; | |
164 | struct drm_property *flicker_filter; | |
165 | struct drm_property *flicker_filter_adaptive; | |
166 | struct drm_property *flicker_filter_2d; | |
167 | struct drm_property *tv_chroma_filter; | |
168 | struct drm_property *tv_luma_filter; | |
169 | struct drm_property *dot_crawl; | |
170 | ||
171 | /* add the property for the SDVO-TV/LVDS */ | |
172 | struct drm_property *brightness; | |
173 | ||
174 | /* Add variable to record current setting for the above property */ | |
175 | u32 left_margin, right_margin, top_margin, bottom_margin; | |
176 | ||
177 | /* this is to get the range of margin.*/ | |
178 | u32 max_hscan, max_vscan; | |
179 | u32 max_hpos, cur_hpos; | |
180 | u32 max_vpos, cur_vpos; | |
181 | u32 cur_brightness, max_brightness; | |
182 | u32 cur_contrast, max_contrast; | |
183 | u32 cur_saturation, max_saturation; | |
184 | u32 cur_hue, max_hue; | |
185 | u32 cur_sharpness, max_sharpness; | |
186 | u32 cur_flicker_filter, max_flicker_filter; | |
187 | u32 cur_flicker_filter_adaptive, max_flicker_filter_adaptive; | |
188 | u32 cur_flicker_filter_2d, max_flicker_filter_2d; | |
189 | u32 cur_tv_chroma_filter, max_tv_chroma_filter; | |
190 | u32 cur_tv_luma_filter, max_tv_luma_filter; | |
191 | u32 cur_dot_crawl, max_dot_crawl; | |
89c78134 AC |
192 | }; |
193 | ||
5736995b PJ |
194 | static struct psb_intel_sdvo *to_psb_intel_sdvo(struct drm_encoder *encoder) |
195 | { | |
196 | return container_of(encoder, struct psb_intel_sdvo, base.base); | |
197 | } | |
198 | ||
199 | static struct psb_intel_sdvo *intel_attached_sdvo(struct drm_connector *connector) | |
200 | { | |
201 | return container_of(psb_intel_attached_encoder(connector), | |
202 | struct psb_intel_sdvo, base); | |
203 | } | |
204 | ||
205 | static struct psb_intel_sdvo_connector *to_psb_intel_sdvo_connector(struct drm_connector *connector) | |
206 | { | |
207 | return container_of(to_psb_intel_connector(connector), struct psb_intel_sdvo_connector, base); | |
208 | } | |
209 | ||
210 | static bool | |
211 | psb_intel_sdvo_output_setup(struct psb_intel_sdvo *psb_intel_sdvo, uint16_t flags); | |
212 | static bool | |
213 | psb_intel_sdvo_tv_create_property(struct psb_intel_sdvo *psb_intel_sdvo, | |
214 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector, | |
215 | int type); | |
216 | static bool | |
217 | psb_intel_sdvo_create_enhance_property(struct psb_intel_sdvo *psb_intel_sdvo, | |
218 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector); | |
219 | ||
89c78134 AC |
220 | /** |
221 | * Writes the SDVOB or SDVOC with the given value, but always writes both | |
222 | * SDVOB and SDVOC to work around apparent hardware issues (according to | |
223 | * comments in the BIOS). | |
224 | */ | |
5736995b | 225 | static void psb_intel_sdvo_write_sdvox(struct psb_intel_sdvo *psb_intel_sdvo, u32 val) |
89c78134 | 226 | { |
5736995b | 227 | struct drm_device *dev = psb_intel_sdvo->base.base.dev; |
89c78134 AC |
228 | u32 bval = val, cval = val; |
229 | int i; | |
230 | ||
5736995b | 231 | if (psb_intel_sdvo->sdvo_reg == SDVOB) { |
89c78134 | 232 | cval = REG_READ(SDVOC); |
5736995b | 233 | } else { |
89c78134 | 234 | bval = REG_READ(SDVOB); |
5736995b | 235 | } |
89c78134 AC |
236 | /* |
237 | * Write the registers twice for luck. Sometimes, | |
238 | * writing them only once doesn't appear to 'stick'. | |
239 | * The BIOS does this too. Yay, magic | |
240 | */ | |
5736995b PJ |
241 | for (i = 0; i < 2; i++) |
242 | { | |
89c78134 AC |
243 | REG_WRITE(SDVOB, bval); |
244 | REG_READ(SDVOB); | |
245 | REG_WRITE(SDVOC, cval); | |
246 | REG_READ(SDVOC); | |
247 | } | |
248 | } | |
249 | ||
5736995b | 250 | static bool psb_intel_sdvo_read_byte(struct psb_intel_sdvo *psb_intel_sdvo, u8 addr, u8 *ch) |
89c78134 | 251 | { |
89c78134 AC |
252 | struct i2c_msg msgs[] = { |
253 | { | |
5736995b PJ |
254 | .addr = psb_intel_sdvo->slave_addr, |
255 | .flags = 0, | |
256 | .len = 1, | |
257 | .buf = &addr, | |
258 | }, | |
89c78134 | 259 | { |
5736995b PJ |
260 | .addr = psb_intel_sdvo->slave_addr, |
261 | .flags = I2C_M_RD, | |
262 | .len = 1, | |
263 | .buf = ch, | |
264 | } | |
89c78134 | 265 | }; |
5736995b | 266 | int ret; |
89c78134 | 267 | |
5736995b | 268 | if ((ret = i2c_transfer(psb_intel_sdvo->i2c, msgs, 2)) == 2) |
89c78134 | 269 | return true; |
89c78134 | 270 | |
5736995b | 271 | DRM_DEBUG_KMS("i2c transfer returned %d\n", ret); |
89c78134 AC |
272 | return false; |
273 | } | |
274 | ||
275 | #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd} | |
276 | /** Mapping of command numbers to names, for debug output */ | |
277 | static const struct _sdvo_cmd_name { | |
278 | u8 cmd; | |
5736995b | 279 | const char *name; |
89c78134 | 280 | } sdvo_cmd_names[] = { |
5736995b PJ |
281 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET), |
282 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS), | |
283 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV), | |
284 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS), | |
285 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS), | |
286 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS), | |
287 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP), | |
288 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP), | |
289 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS), | |
290 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT), | |
291 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG), | |
292 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG), | |
293 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE), | |
294 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT), | |
295 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT), | |
296 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1), | |
297 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2), | |
298 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1), | |
299 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2), | |
300 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1), | |
301 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1), | |
302 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2), | |
303 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1), | |
304 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2), | |
305 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING), | |
306 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1), | |
307 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2), | |
308 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE), | |
309 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE), | |
310 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS), | |
311 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT), | |
312 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT), | |
313 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS), | |
314 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT), | |
315 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT), | |
316 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES), | |
317 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE), | |
318 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE), | |
319 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE), | |
320 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH), | |
321 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT), | |
322 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT), | |
323 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS), | |
324 | ||
325 | /* Add the op code for SDVO enhancements */ | |
326 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HPOS), | |
327 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HPOS), | |
328 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HPOS), | |
329 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_VPOS), | |
330 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_VPOS), | |
331 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_VPOS), | |
332 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION), | |
333 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION), | |
334 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION), | |
335 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE), | |
336 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE), | |
337 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE), | |
338 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST), | |
339 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST), | |
340 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST), | |
341 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS), | |
342 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS), | |
343 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS), | |
344 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H), | |
345 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H), | |
346 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H), | |
347 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V), | |
348 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V), | |
349 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V), | |
350 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER), | |
351 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER), | |
352 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER), | |
353 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_ADAPTIVE), | |
354 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_ADAPTIVE), | |
355 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_ADAPTIVE), | |
356 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_2D), | |
357 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_2D), | |
358 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_2D), | |
359 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SHARPNESS), | |
360 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SHARPNESS), | |
361 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SHARPNESS), | |
362 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DOT_CRAWL), | |
363 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DOT_CRAWL), | |
364 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_CHROMA_FILTER), | |
365 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_CHROMA_FILTER), | |
366 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_CHROMA_FILTER), | |
367 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_LUMA_FILTER), | |
368 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_LUMA_FILTER), | |
369 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_LUMA_FILTER), | |
370 | ||
371 | /* HDMI op code */ | |
372 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE), | |
373 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE), | |
374 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE), | |
375 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI), | |
376 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI), | |
377 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP), | |
378 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY), | |
379 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY), | |
380 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER), | |
381 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT), | |
382 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT), | |
383 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX), | |
384 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX), | |
385 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO), | |
386 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT), | |
387 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT), | |
388 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE), | |
389 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE), | |
390 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA), | |
391 | SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA), | |
392 | }; | |
393 | ||
394 | #define IS_SDVOB(reg) (reg == SDVOB) | |
395 | #define SDVO_NAME(svdo) (IS_SDVOB((svdo)->sdvo_reg) ? "SDVOB" : "SDVOC") | |
396 | ||
397 | static void psb_intel_sdvo_debug_write(struct psb_intel_sdvo *psb_intel_sdvo, u8 cmd, | |
398 | const void *args, int args_len) | |
399 | { | |
89c78134 AC |
400 | int i; |
401 | ||
5736995b PJ |
402 | DRM_DEBUG_KMS("%s: W: %02X ", |
403 | SDVO_NAME(psb_intel_sdvo), cmd); | |
404 | for (i = 0; i < args_len; i++) | |
405 | DRM_LOG_KMS("%02X ", ((u8 *)args)[i]); | |
406 | for (; i < 8; i++) | |
407 | DRM_LOG_KMS(" "); | |
408 | for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) { | |
409 | if (cmd == sdvo_cmd_names[i].cmd) { | |
410 | DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name); | |
411 | break; | |
89c78134 | 412 | } |
89c78134 | 413 | } |
5736995b PJ |
414 | if (i == ARRAY_SIZE(sdvo_cmd_names)) |
415 | DRM_LOG_KMS("(%02X)", cmd); | |
416 | DRM_LOG_KMS("\n"); | |
89c78134 AC |
417 | } |
418 | ||
5736995b | 419 | static const char *cmd_status_names[] = { |
89c78134 AC |
420 | "Power on", |
421 | "Success", | |
422 | "Not supported", | |
423 | "Invalid arg", | |
424 | "Pending", | |
425 | "Target not specified", | |
426 | "Scaling not supported" | |
427 | }; | |
428 | ||
5736995b PJ |
429 | static bool psb_intel_sdvo_write_cmd(struct psb_intel_sdvo *psb_intel_sdvo, u8 cmd, |
430 | const void *args, int args_len) | |
89c78134 | 431 | { |
5736995b PJ |
432 | u8 buf[args_len*2 + 2], status; |
433 | struct i2c_msg msgs[args_len + 3]; | |
434 | int i, ret; | |
435 | ||
436 | psb_intel_sdvo_debug_write(psb_intel_sdvo, cmd, args, args_len); | |
437 | ||
438 | for (i = 0; i < args_len; i++) { | |
439 | msgs[i].addr = psb_intel_sdvo->slave_addr; | |
440 | msgs[i].flags = 0; | |
441 | msgs[i].len = 2; | |
442 | msgs[i].buf = buf + 2 *i; | |
443 | buf[2*i + 0] = SDVO_I2C_ARG_0 - i; | |
444 | buf[2*i + 1] = ((u8*)args)[i]; | |
445 | } | |
446 | msgs[i].addr = psb_intel_sdvo->slave_addr; | |
447 | msgs[i].flags = 0; | |
448 | msgs[i].len = 2; | |
449 | msgs[i].buf = buf + 2*i; | |
450 | buf[2*i + 0] = SDVO_I2C_OPCODE; | |
451 | buf[2*i + 1] = cmd; | |
452 | ||
453 | /* the following two are to read the response */ | |
454 | status = SDVO_I2C_CMD_STATUS; | |
455 | msgs[i+1].addr = psb_intel_sdvo->slave_addr; | |
456 | msgs[i+1].flags = 0; | |
457 | msgs[i+1].len = 1; | |
458 | msgs[i+1].buf = &status; | |
459 | ||
460 | msgs[i+2].addr = psb_intel_sdvo->slave_addr; | |
461 | msgs[i+2].flags = I2C_M_RD; | |
462 | msgs[i+2].len = 1; | |
463 | msgs[i+2].buf = &status; | |
464 | ||
465 | ret = i2c_transfer(psb_intel_sdvo->i2c, msgs, i+3); | |
466 | if (ret < 0) { | |
467 | DRM_DEBUG_KMS("I2c transfer returned %d\n", ret); | |
468 | return false; | |
469 | } | |
470 | if (ret != i+3) { | |
471 | /* failure in I2C transfer */ | |
472 | DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret, i+3); | |
473 | return false; | |
474 | } | |
475 | ||
476 | return true; | |
477 | } | |
478 | ||
479 | static bool psb_intel_sdvo_read_response(struct psb_intel_sdvo *psb_intel_sdvo, | |
480 | void *response, int response_len) | |
481 | { | |
482 | u8 retry = 5; | |
89c78134 | 483 | u8 status; |
5736995b | 484 | int i; |
89c78134 | 485 | |
5736995b PJ |
486 | DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(psb_intel_sdvo)); |
487 | ||
488 | /* | |
489 | * The documentation states that all commands will be | |
490 | * processed within 15µs, and that we need only poll | |
491 | * the status byte a maximum of 3 times in order for the | |
492 | * command to be complete. | |
493 | * | |
494 | * Check 5 times in case the hardware failed to read the docs. | |
495 | */ | |
496 | if (!psb_intel_sdvo_read_byte(psb_intel_sdvo, | |
497 | SDVO_I2C_CMD_STATUS, | |
498 | &status)) | |
499 | goto log_fail; | |
500 | ||
501 | while (status == SDVO_CMD_STATUS_PENDING && retry--) { | |
502 | udelay(15); | |
503 | if (!psb_intel_sdvo_read_byte(psb_intel_sdvo, | |
504 | SDVO_I2C_CMD_STATUS, | |
505 | &status)) | |
506 | goto log_fail; | |
507 | } | |
89c78134 | 508 | |
5736995b PJ |
509 | if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP) |
510 | DRM_LOG_KMS("(%s)", cmd_status_names[status]); | |
511 | else | |
512 | DRM_LOG_KMS("(??? %d)", status); | |
89c78134 | 513 | |
5736995b PJ |
514 | if (status != SDVO_CMD_STATUS_SUCCESS) |
515 | goto log_fail; | |
516 | ||
517 | /* Read the command response */ | |
518 | for (i = 0; i < response_len; i++) { | |
519 | if (!psb_intel_sdvo_read_byte(psb_intel_sdvo, | |
520 | SDVO_I2C_RETURN_0 + i, | |
521 | &((u8 *)response)[i])) | |
522 | goto log_fail; | |
523 | DRM_LOG_KMS(" %02X", ((u8 *)response)[i]); | |
89c78134 | 524 | } |
5736995b PJ |
525 | DRM_LOG_KMS("\n"); |
526 | return true; | |
89c78134 | 527 | |
5736995b PJ |
528 | log_fail: |
529 | DRM_LOG_KMS("... failed\n"); | |
530 | return false; | |
89c78134 AC |
531 | } |
532 | ||
5736995b | 533 | static int psb_intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) |
89c78134 AC |
534 | { |
535 | if (mode->clock >= 100000) | |
536 | return 1; | |
537 | else if (mode->clock >= 50000) | |
538 | return 2; | |
539 | else | |
540 | return 4; | |
541 | } | |
542 | ||
5736995b PJ |
543 | static bool psb_intel_sdvo_set_control_bus_switch(struct psb_intel_sdvo *psb_intel_sdvo, |
544 | u8 ddc_bus) | |
89c78134 | 545 | { |
5736995b PJ |
546 | /* This must be the immediately preceding write before the i2c xfer */ |
547 | return psb_intel_sdvo_write_cmd(psb_intel_sdvo, | |
548 | SDVO_CMD_SET_CONTROL_BUS_SWITCH, | |
549 | &ddc_bus, 1); | |
89c78134 AC |
550 | } |
551 | ||
5736995b | 552 | static bool psb_intel_sdvo_set_value(struct psb_intel_sdvo *psb_intel_sdvo, u8 cmd, const void *data, int len) |
89c78134 | 553 | { |
5736995b PJ |
554 | if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo, cmd, data, len)) |
555 | return false; | |
89c78134 | 556 | |
5736995b PJ |
557 | return psb_intel_sdvo_read_response(psb_intel_sdvo, NULL, 0); |
558 | } | |
89c78134 | 559 | |
5736995b PJ |
560 | static bool |
561 | psb_intel_sdvo_get_value(struct psb_intel_sdvo *psb_intel_sdvo, u8 cmd, void *value, int len) | |
562 | { | |
563 | if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo, cmd, NULL, 0)) | |
564 | return false; | |
89c78134 | 565 | |
5736995b PJ |
566 | return psb_intel_sdvo_read_response(psb_intel_sdvo, value, len); |
567 | } | |
89c78134 | 568 | |
5736995b PJ |
569 | static bool psb_intel_sdvo_set_target_input(struct psb_intel_sdvo *psb_intel_sdvo) |
570 | { | |
571 | struct psb_intel_sdvo_set_target_input_args targets = {0}; | |
572 | return psb_intel_sdvo_set_value(psb_intel_sdvo, | |
573 | SDVO_CMD_SET_TARGET_INPUT, | |
574 | &targets, sizeof(targets)); | |
89c78134 AC |
575 | } |
576 | ||
577 | /** | |
578 | * Return whether each input is trained. | |
579 | * | |
580 | * This function is making an assumption about the layout of the response, | |
581 | * which should be checked against the docs. | |
582 | */ | |
5736995b | 583 | static bool psb_intel_sdvo_get_trained_inputs(struct psb_intel_sdvo *psb_intel_sdvo, bool *input_1, bool *input_2) |
89c78134 AC |
584 | { |
585 | struct psb_intel_sdvo_get_trained_inputs_response response; | |
89c78134 | 586 | |
5736995b PJ |
587 | BUILD_BUG_ON(sizeof(response) != 1); |
588 | if (!psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS, | |
589 | &response, sizeof(response))) | |
89c78134 AC |
590 | return false; |
591 | ||
592 | *input_1 = response.input0_trained; | |
593 | *input_2 = response.input1_trained; | |
594 | return true; | |
595 | } | |
596 | ||
5736995b PJ |
597 | static bool psb_intel_sdvo_set_active_outputs(struct psb_intel_sdvo *psb_intel_sdvo, |
598 | u16 outputs) | |
89c78134 | 599 | { |
5736995b PJ |
600 | return psb_intel_sdvo_set_value(psb_intel_sdvo, |
601 | SDVO_CMD_SET_ACTIVE_OUTPUTS, | |
602 | &outputs, sizeof(outputs)); | |
89c78134 AC |
603 | } |
604 | ||
5736995b PJ |
605 | static bool psb_intel_sdvo_set_encoder_power_state(struct psb_intel_sdvo *psb_intel_sdvo, |
606 | int mode) | |
89c78134 | 607 | { |
5736995b | 608 | u8 state = SDVO_ENCODER_STATE_ON; |
89c78134 AC |
609 | |
610 | switch (mode) { | |
611 | case DRM_MODE_DPMS_ON: | |
612 | state = SDVO_ENCODER_STATE_ON; | |
613 | break; | |
614 | case DRM_MODE_DPMS_STANDBY: | |
615 | state = SDVO_ENCODER_STATE_STANDBY; | |
616 | break; | |
617 | case DRM_MODE_DPMS_SUSPEND: | |
618 | state = SDVO_ENCODER_STATE_SUSPEND; | |
619 | break; | |
620 | case DRM_MODE_DPMS_OFF: | |
621 | state = SDVO_ENCODER_STATE_OFF; | |
622 | break; | |
623 | } | |
624 | ||
5736995b PJ |
625 | return psb_intel_sdvo_set_value(psb_intel_sdvo, |
626 | SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state)); | |
89c78134 AC |
627 | } |
628 | ||
5736995b | 629 | static bool psb_intel_sdvo_get_input_pixel_clock_range(struct psb_intel_sdvo *psb_intel_sdvo, |
89c78134 AC |
630 | int *clock_min, |
631 | int *clock_max) | |
632 | { | |
633 | struct psb_intel_sdvo_pixel_clock_range clocks; | |
89c78134 | 634 | |
5736995b PJ |
635 | BUILD_BUG_ON(sizeof(clocks) != 4); |
636 | if (!psb_intel_sdvo_get_value(psb_intel_sdvo, | |
637 | SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE, | |
638 | &clocks, sizeof(clocks))) | |
89c78134 AC |
639 | return false; |
640 | ||
641 | /* Convert the values from units of 10 kHz to kHz. */ | |
642 | *clock_min = clocks.min * 10; | |
643 | *clock_max = clocks.max * 10; | |
89c78134 AC |
644 | return true; |
645 | } | |
646 | ||
5736995b PJ |
647 | static bool psb_intel_sdvo_set_target_output(struct psb_intel_sdvo *psb_intel_sdvo, |
648 | u16 outputs) | |
89c78134 | 649 | { |
5736995b PJ |
650 | return psb_intel_sdvo_set_value(psb_intel_sdvo, |
651 | SDVO_CMD_SET_TARGET_OUTPUT, | |
652 | &outputs, sizeof(outputs)); | |
653 | } | |
89c78134 | 654 | |
5736995b PJ |
655 | static bool psb_intel_sdvo_set_timing(struct psb_intel_sdvo *psb_intel_sdvo, u8 cmd, |
656 | struct psb_intel_sdvo_dtd *dtd) | |
657 | { | |
658 | return psb_intel_sdvo_set_value(psb_intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) && | |
659 | psb_intel_sdvo_set_value(psb_intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2)); | |
89c78134 AC |
660 | } |
661 | ||
5736995b PJ |
662 | static bool psb_intel_sdvo_set_input_timing(struct psb_intel_sdvo *psb_intel_sdvo, |
663 | struct psb_intel_sdvo_dtd *dtd) | |
89c78134 | 664 | { |
5736995b PJ |
665 | return psb_intel_sdvo_set_timing(psb_intel_sdvo, |
666 | SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd); | |
667 | } | |
89c78134 | 668 | |
5736995b PJ |
669 | static bool psb_intel_sdvo_set_output_timing(struct psb_intel_sdvo *psb_intel_sdvo, |
670 | struct psb_intel_sdvo_dtd *dtd) | |
671 | { | |
672 | return psb_intel_sdvo_set_timing(psb_intel_sdvo, | |
673 | SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd); | |
674 | } | |
89c78134 | 675 | |
5736995b PJ |
676 | static bool |
677 | psb_intel_sdvo_create_preferred_input_timing(struct psb_intel_sdvo *psb_intel_sdvo, | |
678 | uint16_t clock, | |
679 | uint16_t width, | |
680 | uint16_t height) | |
681 | { | |
682 | struct psb_intel_sdvo_preferred_input_timing_args args; | |
683 | ||
684 | memset(&args, 0, sizeof(args)); | |
685 | args.clock = clock; | |
686 | args.width = width; | |
687 | args.height = height; | |
688 | args.interlace = 0; | |
689 | ||
690 | if (psb_intel_sdvo->is_lvds && | |
691 | (psb_intel_sdvo->sdvo_lvds_fixed_mode->hdisplay != width || | |
692 | psb_intel_sdvo->sdvo_lvds_fixed_mode->vdisplay != height)) | |
693 | args.scaled = 1; | |
694 | ||
695 | return psb_intel_sdvo_set_value(psb_intel_sdvo, | |
696 | SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING, | |
697 | &args, sizeof(args)); | |
698 | } | |
89c78134 | 699 | |
5736995b PJ |
700 | static bool psb_intel_sdvo_get_preferred_input_timing(struct psb_intel_sdvo *psb_intel_sdvo, |
701 | struct psb_intel_sdvo_dtd *dtd) | |
702 | { | |
703 | BUILD_BUG_ON(sizeof(dtd->part1) != 8); | |
704 | BUILD_BUG_ON(sizeof(dtd->part2) != 8); | |
705 | return psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1, | |
706 | &dtd->part1, sizeof(dtd->part1)) && | |
707 | psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2, | |
708 | &dtd->part2, sizeof(dtd->part2)); | |
89c78134 AC |
709 | } |
710 | ||
5736995b | 711 | static bool psb_intel_sdvo_set_clock_rate_mult(struct psb_intel_sdvo *psb_intel_sdvo, u8 val) |
89c78134 | 712 | { |
5736995b | 713 | return psb_intel_sdvo_set_value(psb_intel_sdvo, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1); |
89c78134 AC |
714 | } |
715 | ||
5736995b PJ |
716 | static void psb_intel_sdvo_get_dtd_from_mode(struct psb_intel_sdvo_dtd *dtd, |
717 | const struct drm_display_mode *mode) | |
89c78134 | 718 | { |
5736995b PJ |
719 | uint16_t width, height; |
720 | uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len; | |
721 | uint16_t h_sync_offset, v_sync_offset; | |
89c78134 | 722 | |
5736995b PJ |
723 | width = mode->crtc_hdisplay; |
724 | height = mode->crtc_vdisplay; | |
89c78134 | 725 | |
5736995b PJ |
726 | /* do some mode translations */ |
727 | h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start; | |
728 | h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start; | |
89c78134 | 729 | |
5736995b PJ |
730 | v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start; |
731 | v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start; | |
732 | ||
733 | h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start; | |
734 | v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start; | |
735 | ||
736 | dtd->part1.clock = mode->clock / 10; | |
737 | dtd->part1.h_active = width & 0xff; | |
738 | dtd->part1.h_blank = h_blank_len & 0xff; | |
739 | dtd->part1.h_high = (((width >> 8) & 0xf) << 4) | | |
740 | ((h_blank_len >> 8) & 0xf); | |
741 | dtd->part1.v_active = height & 0xff; | |
742 | dtd->part1.v_blank = v_blank_len & 0xff; | |
743 | dtd->part1.v_high = (((height >> 8) & 0xf) << 4) | | |
744 | ((v_blank_len >> 8) & 0xf); | |
745 | ||
746 | dtd->part2.h_sync_off = h_sync_offset & 0xff; | |
747 | dtd->part2.h_sync_width = h_sync_len & 0xff; | |
748 | dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 | | |
749 | (v_sync_len & 0xf); | |
750 | dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) | | |
751 | ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) | | |
752 | ((v_sync_len & 0x30) >> 4); | |
753 | ||
754 | dtd->part2.dtd_flags = 0x18; | |
755 | if (mode->flags & DRM_MODE_FLAG_PHSYNC) | |
756 | dtd->part2.dtd_flags |= 0x2; | |
757 | if (mode->flags & DRM_MODE_FLAG_PVSYNC) | |
758 | dtd->part2.dtd_flags |= 0x4; | |
759 | ||
760 | dtd->part2.sdvo_flags = 0; | |
761 | dtd->part2.v_sync_off_high = v_sync_offset & 0xc0; | |
762 | dtd->part2.reserved = 0; | |
89c78134 AC |
763 | } |
764 | ||
5736995b PJ |
765 | static void psb_intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode, |
766 | const struct psb_intel_sdvo_dtd *dtd) | |
89c78134 | 767 | { |
5736995b PJ |
768 | mode->hdisplay = dtd->part1.h_active; |
769 | mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8; | |
770 | mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off; | |
771 | mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2; | |
772 | mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width; | |
773 | mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4; | |
774 | mode->htotal = mode->hdisplay + dtd->part1.h_blank; | |
775 | mode->htotal += (dtd->part1.h_high & 0xf) << 8; | |
776 | ||
777 | mode->vdisplay = dtd->part1.v_active; | |
778 | mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8; | |
779 | mode->vsync_start = mode->vdisplay; | |
780 | mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf; | |
781 | mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2; | |
782 | mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0; | |
783 | mode->vsync_end = mode->vsync_start + | |
784 | (dtd->part2.v_sync_off_width & 0xf); | |
785 | mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4; | |
786 | mode->vtotal = mode->vdisplay + dtd->part1.v_blank; | |
787 | mode->vtotal += (dtd->part1.v_high & 0xf) << 8; | |
788 | ||
789 | mode->clock = dtd->part1.clock * 10; | |
790 | ||
791 | mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC); | |
792 | if (dtd->part2.dtd_flags & 0x2) | |
793 | mode->flags |= DRM_MODE_FLAG_PHSYNC; | |
794 | if (dtd->part2.dtd_flags & 0x4) | |
795 | mode->flags |= DRM_MODE_FLAG_PVSYNC; | |
89c78134 AC |
796 | } |
797 | ||
5736995b | 798 | static bool psb_intel_sdvo_check_supp_encode(struct psb_intel_sdvo *psb_intel_sdvo) |
89c78134 | 799 | { |
5736995b PJ |
800 | struct psb_intel_sdvo_encode encode; |
801 | ||
802 | BUILD_BUG_ON(sizeof(encode) != 2); | |
803 | return psb_intel_sdvo_get_value(psb_intel_sdvo, | |
804 | SDVO_CMD_GET_SUPP_ENCODE, | |
805 | &encode, sizeof(encode)); | |
89c78134 AC |
806 | } |
807 | ||
5736995b PJ |
808 | static bool psb_intel_sdvo_set_encode(struct psb_intel_sdvo *psb_intel_sdvo, |
809 | uint8_t mode) | |
89c78134 | 810 | { |
5736995b PJ |
811 | return psb_intel_sdvo_set_value(psb_intel_sdvo, SDVO_CMD_SET_ENCODE, &mode, 1); |
812 | } | |
89c78134 | 813 | |
5736995b PJ |
814 | static bool psb_intel_sdvo_set_colorimetry(struct psb_intel_sdvo *psb_intel_sdvo, |
815 | uint8_t mode) | |
816 | { | |
817 | return psb_intel_sdvo_set_value(psb_intel_sdvo, SDVO_CMD_SET_COLORIMETRY, &mode, 1); | |
818 | } | |
89c78134 | 819 | |
5736995b PJ |
820 | #if 0 |
821 | static void psb_intel_sdvo_dump_hdmi_buf(struct psb_intel_sdvo *psb_intel_sdvo) | |
822 | { | |
823 | int i, j; | |
824 | uint8_t set_buf_index[2]; | |
825 | uint8_t av_split; | |
826 | uint8_t buf_size; | |
827 | uint8_t buf[48]; | |
828 | uint8_t *pos; | |
829 | ||
830 | psb_intel_sdvo_get_value(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, &av_split, 1); | |
831 | ||
832 | for (i = 0; i <= av_split; i++) { | |
833 | set_buf_index[0] = i; set_buf_index[1] = 0; | |
834 | psb_intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX, | |
835 | set_buf_index, 2); | |
836 | psb_intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0); | |
837 | psb_intel_sdvo_read_response(encoder, &buf_size, 1); | |
838 | ||
839 | pos = buf; | |
840 | for (j = 0; j <= buf_size; j += 8) { | |
841 | psb_intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA, | |
842 | NULL, 0); | |
843 | psb_intel_sdvo_read_response(encoder, pos, 8); | |
844 | pos += 8; | |
845 | } | |
89c78134 | 846 | } |
89c78134 | 847 | } |
5736995b | 848 | #endif |
89c78134 | 849 | |
5736995b | 850 | static bool psb_intel_sdvo_set_avi_infoframe(struct psb_intel_sdvo *psb_intel_sdvo) |
89c78134 | 851 | { |
5736995b PJ |
852 | DRM_INFO("HDMI is not supported yet"); |
853 | ||
854 | return false; | |
855 | #if 0 | |
856 | struct dip_infoframe avi_if = { | |
857 | .type = DIP_TYPE_AVI, | |
858 | .ver = DIP_VERSION_AVI, | |
859 | .len = DIP_LEN_AVI, | |
860 | }; | |
861 | uint8_t tx_rate = SDVO_HBUF_TX_VSYNC; | |
862 | uint8_t set_buf_index[2] = { 1, 0 }; | |
863 | uint64_t *data = (uint64_t *)&avi_if; | |
864 | unsigned i; | |
89c78134 | 865 | |
5736995b | 866 | intel_dip_infoframe_csum(&avi_if); |
89c78134 | 867 | |
5736995b PJ |
868 | if (!psb_intel_sdvo_set_value(psb_intel_sdvo, |
869 | SDVO_CMD_SET_HBUF_INDEX, | |
870 | set_buf_index, 2)) | |
89c78134 AC |
871 | return false; |
872 | ||
5736995b PJ |
873 | for (i = 0; i < sizeof(avi_if); i += 8) { |
874 | if (!psb_intel_sdvo_set_value(psb_intel_sdvo, | |
875 | SDVO_CMD_SET_HBUF_DATA, | |
876 | data, 8)) | |
877 | return false; | |
878 | data++; | |
879 | } | |
880 | ||
881 | return psb_intel_sdvo_set_value(psb_intel_sdvo, | |
882 | SDVO_CMD_SET_HBUF_TXRATE, | |
883 | &tx_rate, 1); | |
884 | #endif | |
89c78134 AC |
885 | } |
886 | ||
5736995b | 887 | static bool psb_intel_sdvo_set_tv_format(struct psb_intel_sdvo *psb_intel_sdvo) |
89c78134 | 888 | { |
5736995b PJ |
889 | struct psb_intel_sdvo_tv_format format; |
890 | uint32_t format_map; | |
89c78134 | 891 | |
5736995b PJ |
892 | format_map = 1 << psb_intel_sdvo->tv_format_index; |
893 | memset(&format, 0, sizeof(format)); | |
894 | memcpy(&format, &format_map, min(sizeof(format), sizeof(format_map))); | |
89c78134 | 895 | |
5736995b PJ |
896 | BUILD_BUG_ON(sizeof(format) != 6); |
897 | return psb_intel_sdvo_set_value(psb_intel_sdvo, | |
898 | SDVO_CMD_SET_TV_FORMAT, | |
899 | &format, sizeof(format)); | |
900 | } | |
89c78134 | 901 | |
5736995b PJ |
902 | static bool |
903 | psb_intel_sdvo_set_output_timings_from_mode(struct psb_intel_sdvo *psb_intel_sdvo, | |
904 | struct drm_display_mode *mode) | |
905 | { | |
906 | struct psb_intel_sdvo_dtd output_dtd; | |
89c78134 | 907 | |
5736995b PJ |
908 | if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo, |
909 | psb_intel_sdvo->attached_output)) | |
910 | return false; | |
89c78134 | 911 | |
5736995b PJ |
912 | psb_intel_sdvo_get_dtd_from_mode(&output_dtd, mode); |
913 | if (!psb_intel_sdvo_set_output_timing(psb_intel_sdvo, &output_dtd)) | |
89c78134 | 914 | return false; |
5736995b | 915 | |
89c78134 AC |
916 | return true; |
917 | } | |
918 | ||
5736995b PJ |
919 | static bool |
920 | psb_intel_sdvo_set_input_timings_for_mode(struct psb_intel_sdvo *psb_intel_sdvo, | |
921 | struct drm_display_mode *mode, | |
922 | struct drm_display_mode *adjusted_mode) | |
89c78134 | 923 | { |
5736995b PJ |
924 | /* Reset the input timing to the screen. Assume always input 0. */ |
925 | if (!psb_intel_sdvo_set_target_input(psb_intel_sdvo)) | |
926 | return false; | |
89c78134 | 927 | |
5736995b PJ |
928 | if (!psb_intel_sdvo_create_preferred_input_timing(psb_intel_sdvo, |
929 | mode->clock / 10, | |
930 | mode->hdisplay, | |
931 | mode->vdisplay)) | |
932 | return false; | |
89c78134 | 933 | |
5736995b PJ |
934 | if (!psb_intel_sdvo_get_preferred_input_timing(psb_intel_sdvo, |
935 | &psb_intel_sdvo->input_dtd)) | |
936 | return false; | |
89c78134 | 937 | |
5736995b | 938 | psb_intel_sdvo_get_mode_from_dtd(adjusted_mode, &psb_intel_sdvo->input_dtd); |
89c78134 | 939 | |
5736995b PJ |
940 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
941 | return true; | |
89c78134 AC |
942 | } |
943 | ||
89c78134 AC |
944 | static bool psb_intel_sdvo_mode_fixup(struct drm_encoder *encoder, |
945 | struct drm_display_mode *mode, | |
946 | struct drm_display_mode *adjusted_mode) | |
947 | { | |
5736995b PJ |
948 | struct psb_intel_sdvo *psb_intel_sdvo = to_psb_intel_sdvo(encoder); |
949 | int multiplier; | |
950 | ||
951 | /* We need to construct preferred input timings based on our | |
952 | * output timings. To do that, we have to set the output | |
953 | * timings, even though this isn't really the right place in | |
954 | * the sequence to do it. Oh well. | |
89c78134 | 955 | */ |
5736995b PJ |
956 | if (psb_intel_sdvo->is_tv) { |
957 | if (!psb_intel_sdvo_set_output_timings_from_mode(psb_intel_sdvo, mode)) | |
958 | return false; | |
959 | ||
960 | (void) psb_intel_sdvo_set_input_timings_for_mode(psb_intel_sdvo, | |
961 | mode, | |
962 | adjusted_mode); | |
963 | } else if (psb_intel_sdvo->is_lvds) { | |
964 | if (!psb_intel_sdvo_set_output_timings_from_mode(psb_intel_sdvo, | |
965 | psb_intel_sdvo->sdvo_lvds_fixed_mode)) | |
966 | return false; | |
967 | ||
968 | (void) psb_intel_sdvo_set_input_timings_for_mode(psb_intel_sdvo, | |
969 | mode, | |
970 | adjusted_mode); | |
971 | } | |
972 | ||
973 | /* Make the CRTC code factor in the SDVO pixel multiplier. The | |
974 | * SDVO device will factor out the multiplier during mode_set. | |
975 | */ | |
976 | multiplier = psb_intel_sdvo_get_pixel_multiplier(adjusted_mode); | |
977 | psb_intel_mode_set_pixel_multiplier(adjusted_mode, multiplier); | |
978 | ||
89c78134 AC |
979 | return true; |
980 | } | |
981 | ||
982 | static void psb_intel_sdvo_mode_set(struct drm_encoder *encoder, | |
983 | struct drm_display_mode *mode, | |
984 | struct drm_display_mode *adjusted_mode) | |
985 | { | |
986 | struct drm_device *dev = encoder->dev; | |
987 | struct drm_crtc *crtc = encoder->crtc; | |
988 | struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc); | |
5736995b | 989 | struct psb_intel_sdvo *psb_intel_sdvo = to_psb_intel_sdvo(encoder); |
89c78134 | 990 | u32 sdvox; |
5736995b PJ |
991 | struct psb_intel_sdvo_in_out_map in_out; |
992 | struct psb_intel_sdvo_dtd input_dtd; | |
993 | int pixel_multiplier = psb_intel_mode_get_pixel_multiplier(adjusted_mode); | |
994 | int rate; | |
89c78134 AC |
995 | |
996 | if (!mode) | |
997 | return; | |
998 | ||
5736995b PJ |
999 | /* First, set the input mapping for the first input to our controlled |
1000 | * output. This is only correct if we're a single-input device, in | |
1001 | * which case the first input is the output from the appropriate SDVO | |
1002 | * channel on the motherboard. In a two-input device, the first input | |
1003 | * will be SDVOB and the second SDVOC. | |
1004 | */ | |
1005 | in_out.in0 = psb_intel_sdvo->attached_output; | |
1006 | in_out.in1 = 0; | |
89c78134 | 1007 | |
5736995b PJ |
1008 | psb_intel_sdvo_set_value(psb_intel_sdvo, |
1009 | SDVO_CMD_SET_IN_OUT_MAP, | |
1010 | &in_out, sizeof(in_out)); | |
89c78134 | 1011 | |
5736995b PJ |
1012 | /* Set the output timings to the screen */ |
1013 | if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo, | |
1014 | psb_intel_sdvo->attached_output)) | |
1015 | return; | |
89c78134 | 1016 | |
5736995b PJ |
1017 | /* We have tried to get input timing in mode_fixup, and filled into |
1018 | * adjusted_mode. | |
1019 | */ | |
1020 | if (psb_intel_sdvo->is_tv || psb_intel_sdvo->is_lvds) { | |
1021 | input_dtd = psb_intel_sdvo->input_dtd; | |
1022 | } else { | |
1023 | /* Set the output timing to the screen */ | |
1024 | if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo, | |
1025 | psb_intel_sdvo->attached_output)) | |
1026 | return; | |
89c78134 | 1027 | |
5736995b PJ |
1028 | psb_intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode); |
1029 | (void) psb_intel_sdvo_set_output_timing(psb_intel_sdvo, &input_dtd); | |
1030 | } | |
89c78134 AC |
1031 | |
1032 | /* Set the input timing to the screen. Assume always input 0. */ | |
5736995b PJ |
1033 | if (!psb_intel_sdvo_set_target_input(psb_intel_sdvo)) |
1034 | return; | |
89c78134 | 1035 | |
5736995b PJ |
1036 | if (psb_intel_sdvo->has_hdmi_monitor) { |
1037 | psb_intel_sdvo_set_encode(psb_intel_sdvo, SDVO_ENCODE_HDMI); | |
1038 | psb_intel_sdvo_set_colorimetry(psb_intel_sdvo, | |
1039 | SDVO_COLORIMETRY_RGB256); | |
1040 | psb_intel_sdvo_set_avi_infoframe(psb_intel_sdvo); | |
1041 | } else | |
1042 | psb_intel_sdvo_set_encode(psb_intel_sdvo, SDVO_ENCODE_DVI); | |
89c78134 | 1043 | |
5736995b PJ |
1044 | if (psb_intel_sdvo->is_tv && |
1045 | !psb_intel_sdvo_set_tv_format(psb_intel_sdvo)) | |
1046 | return; | |
89c78134 | 1047 | |
5736995b PJ |
1048 | (void) psb_intel_sdvo_set_input_timing(psb_intel_sdvo, &input_dtd); |
1049 | ||
1050 | switch (pixel_multiplier) { | |
1051 | default: | |
1052 | case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break; | |
1053 | case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break; | |
1054 | case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break; | |
89c78134 | 1055 | } |
5736995b PJ |
1056 | if (!psb_intel_sdvo_set_clock_rate_mult(psb_intel_sdvo, rate)) |
1057 | return; | |
89c78134 AC |
1058 | |
1059 | /* Set the SDVO control regs. */ | |
5736995b PJ |
1060 | sdvox = REG_READ(psb_intel_sdvo->sdvo_reg); |
1061 | switch (psb_intel_sdvo->sdvo_reg) { | |
89c78134 AC |
1062 | case SDVOB: |
1063 | sdvox &= SDVOB_PRESERVE_MASK; | |
1064 | break; | |
1065 | case SDVOC: | |
1066 | sdvox &= SDVOC_PRESERVE_MASK; | |
1067 | break; | |
1068 | } | |
1069 | sdvox |= (9 << 19) | SDVO_BORDER_ENABLE; | |
5736995b | 1070 | |
89c78134 AC |
1071 | if (psb_intel_crtc->pipe == 1) |
1072 | sdvox |= SDVO_PIPE_B_SELECT; | |
5736995b PJ |
1073 | if (psb_intel_sdvo->has_hdmi_audio) |
1074 | sdvox |= SDVO_AUDIO_ENABLE; | |
89c78134 | 1075 | |
5736995b PJ |
1076 | /* FIXME: Check if this is needed for PSB |
1077 | sdvox |= (pixel_multiplier - 1) << SDVO_PORT_MULTIPLY_SHIFT; | |
1078 | */ | |
89c78134 | 1079 | |
5736995b PJ |
1080 | if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL) |
1081 | sdvox |= SDVO_STALL_SELECT; | |
1082 | psb_intel_sdvo_write_sdvox(psb_intel_sdvo, sdvox); | |
89c78134 AC |
1083 | } |
1084 | ||
1085 | static void psb_intel_sdvo_dpms(struct drm_encoder *encoder, int mode) | |
1086 | { | |
1087 | struct drm_device *dev = encoder->dev; | |
5736995b | 1088 | struct psb_intel_sdvo *psb_intel_sdvo = to_psb_intel_sdvo(encoder); |
89c78134 AC |
1089 | u32 temp; |
1090 | ||
5736995b PJ |
1091 | switch (mode) { |
1092 | case DRM_MODE_DPMS_ON: | |
1093 | DRM_DEBUG("DPMS_ON"); | |
1094 | break; | |
1095 | case DRM_MODE_DPMS_OFF: | |
1096 | DRM_DEBUG("DPMS_OFF"); | |
1097 | break; | |
1098 | default: | |
1099 | DRM_DEBUG("DPMS: %d", mode); | |
1100 | } | |
1101 | ||
89c78134 | 1102 | if (mode != DRM_MODE_DPMS_ON) { |
5736995b | 1103 | psb_intel_sdvo_set_active_outputs(psb_intel_sdvo, 0); |
89c78134 | 1104 | if (0) |
5736995b | 1105 | psb_intel_sdvo_set_encoder_power_state(psb_intel_sdvo, mode); |
89c78134 AC |
1106 | |
1107 | if (mode == DRM_MODE_DPMS_OFF) { | |
5736995b | 1108 | temp = REG_READ(psb_intel_sdvo->sdvo_reg); |
89c78134 | 1109 | if ((temp & SDVO_ENABLE) != 0) { |
5736995b | 1110 | psb_intel_sdvo_write_sdvox(psb_intel_sdvo, temp & ~SDVO_ENABLE); |
89c78134 AC |
1111 | } |
1112 | } | |
1113 | } else { | |
1114 | bool input1, input2; | |
1115 | int i; | |
1116 | u8 status; | |
1117 | ||
5736995b | 1118 | temp = REG_READ(psb_intel_sdvo->sdvo_reg); |
89c78134 | 1119 | if ((temp & SDVO_ENABLE) == 0) |
5736995b | 1120 | psb_intel_sdvo_write_sdvox(psb_intel_sdvo, temp | SDVO_ENABLE); |
89c78134 AC |
1121 | for (i = 0; i < 2; i++) |
1122 | psb_intel_wait_for_vblank(dev); | |
1123 | ||
5736995b | 1124 | status = psb_intel_sdvo_get_trained_inputs(psb_intel_sdvo, &input1, &input2); |
89c78134 AC |
1125 | /* Warn if the device reported failure to sync. |
1126 | * A lot of SDVO devices fail to notify of sync, but it's | |
1127 | * a given it the status is a success, we succeeded. | |
1128 | */ | |
1129 | if (status == SDVO_CMD_STATUS_SUCCESS && !input1) { | |
5736995b PJ |
1130 | DRM_DEBUG_KMS("First %s output reported failure to " |
1131 | "sync\n", SDVO_NAME(psb_intel_sdvo)); | |
89c78134 AC |
1132 | } |
1133 | ||
1134 | if (0) | |
5736995b PJ |
1135 | psb_intel_sdvo_set_encoder_power_state(psb_intel_sdvo, mode); |
1136 | psb_intel_sdvo_set_active_outputs(psb_intel_sdvo, psb_intel_sdvo->attached_output); | |
89c78134 AC |
1137 | } |
1138 | return; | |
1139 | } | |
1140 | ||
5736995b PJ |
1141 | static int psb_intel_sdvo_mode_valid(struct drm_connector *connector, |
1142 | struct drm_display_mode *mode) | |
89c78134 | 1143 | { |
9f821c67 | 1144 | struct drm_psb_private *dev_priv = connector->dev->dev_private; |
5736995b | 1145 | struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector); |
89c78134 | 1146 | |
5736995b PJ |
1147 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
1148 | return MODE_NO_DBLESCAN; | |
89c78134 | 1149 | |
5736995b PJ |
1150 | if (psb_intel_sdvo->pixel_clock_min > mode->clock) |
1151 | return MODE_CLOCK_LOW; | |
89c78134 | 1152 | |
5736995b PJ |
1153 | if (psb_intel_sdvo->pixel_clock_max < mode->clock) |
1154 | return MODE_CLOCK_HIGH; | |
89c78134 | 1155 | |
5736995b PJ |
1156 | if (psb_intel_sdvo->is_lvds) { |
1157 | if (mode->hdisplay > psb_intel_sdvo->sdvo_lvds_fixed_mode->hdisplay) | |
1158 | return MODE_PANEL; | |
89c78134 | 1159 | |
5736995b PJ |
1160 | if (mode->vdisplay > psb_intel_sdvo->sdvo_lvds_fixed_mode->vdisplay) |
1161 | return MODE_PANEL; | |
89c78134 AC |
1162 | } |
1163 | ||
9f821c67 AC |
1164 | /* We assume worst case scenario of 32 bpp here, since we don't know */ |
1165 | if ((ALIGN(mode->hdisplay * 4, 64) * mode->vdisplay) > | |
1166 | dev_priv->vram_stolen_size) | |
1167 | return MODE_MEM; | |
1168 | ||
89c78134 AC |
1169 | return MODE_OK; |
1170 | } | |
1171 | ||
5736995b | 1172 | static bool psb_intel_sdvo_get_capabilities(struct psb_intel_sdvo *psb_intel_sdvo, struct psb_intel_sdvo_caps *caps) |
89c78134 | 1173 | { |
5736995b PJ |
1174 | BUILD_BUG_ON(sizeof(*caps) != 8); |
1175 | if (!psb_intel_sdvo_get_value(psb_intel_sdvo, | |
1176 | SDVO_CMD_GET_DEVICE_CAPS, | |
1177 | caps, sizeof(*caps))) | |
89c78134 AC |
1178 | return false; |
1179 | ||
5736995b PJ |
1180 | DRM_DEBUG_KMS("SDVO capabilities:\n" |
1181 | " vendor_id: %d\n" | |
1182 | " device_id: %d\n" | |
1183 | " device_rev_id: %d\n" | |
1184 | " sdvo_version_major: %d\n" | |
1185 | " sdvo_version_minor: %d\n" | |
1186 | " sdvo_inputs_mask: %d\n" | |
1187 | " smooth_scaling: %d\n" | |
1188 | " sharp_scaling: %d\n" | |
1189 | " up_scaling: %d\n" | |
1190 | " down_scaling: %d\n" | |
1191 | " stall_support: %d\n" | |
1192 | " output_flags: %d\n", | |
1193 | caps->vendor_id, | |
1194 | caps->device_id, | |
1195 | caps->device_rev_id, | |
1196 | caps->sdvo_version_major, | |
1197 | caps->sdvo_version_minor, | |
1198 | caps->sdvo_inputs_mask, | |
1199 | caps->smooth_scaling, | |
1200 | caps->sharp_scaling, | |
1201 | caps->up_scaling, | |
1202 | caps->down_scaling, | |
1203 | caps->stall_support, | |
1204 | caps->output_flags); | |
1205 | ||
89c78134 AC |
1206 | return true; |
1207 | } | |
1208 | ||
5736995b PJ |
1209 | /* No use! */ |
1210 | #if 0 | |
1211 | struct drm_connector* psb_intel_sdvo_find(struct drm_device *dev, int sdvoB) | |
89c78134 AC |
1212 | { |
1213 | struct drm_connector *connector = NULL; | |
5736995b PJ |
1214 | struct psb_intel_sdvo *iout = NULL; |
1215 | struct psb_intel_sdvo *sdvo; | |
89c78134 AC |
1216 | |
1217 | /* find the sdvo connector */ | |
5736995b PJ |
1218 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
1219 | iout = to_psb_intel_sdvo(connector); | |
89c78134 AC |
1220 | |
1221 | if (iout->type != INTEL_OUTPUT_SDVO) | |
1222 | continue; | |
1223 | ||
1224 | sdvo = iout->dev_priv; | |
1225 | ||
5736995b | 1226 | if (sdvo->sdvo_reg == SDVOB && sdvoB) |
89c78134 AC |
1227 | return connector; |
1228 | ||
5736995b | 1229 | if (sdvo->sdvo_reg == SDVOC && !sdvoB) |
89c78134 AC |
1230 | return connector; |
1231 | ||
1232 | } | |
1233 | ||
1234 | return NULL; | |
1235 | } | |
1236 | ||
1237 | int psb_intel_sdvo_supports_hotplug(struct drm_connector *connector) | |
1238 | { | |
1239 | u8 response[2]; | |
1240 | u8 status; | |
5736995b PJ |
1241 | struct psb_intel_sdvo *psb_intel_sdvo; |
1242 | DRM_DEBUG_KMS("\n"); | |
89c78134 AC |
1243 | |
1244 | if (!connector) | |
1245 | return 0; | |
1246 | ||
5736995b | 1247 | psb_intel_sdvo = to_psb_intel_sdvo(connector); |
89c78134 | 1248 | |
5736995b PJ |
1249 | return psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT, |
1250 | &response, 2) && response[0]; | |
89c78134 AC |
1251 | } |
1252 | ||
1253 | void psb_intel_sdvo_set_hotplug(struct drm_connector *connector, int on) | |
1254 | { | |
1255 | u8 response[2]; | |
1256 | u8 status; | |
5736995b | 1257 | struct psb_intel_sdvo *psb_intel_sdvo = to_psb_intel_sdvo(connector); |
89c78134 | 1258 | |
5736995b PJ |
1259 | psb_intel_sdvo_write_cmd(psb_intel_sdvo, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); |
1260 | psb_intel_sdvo_read_response(psb_intel_sdvo, &response, 2); | |
89c78134 AC |
1261 | |
1262 | if (on) { | |
5736995b PJ |
1263 | psb_intel_sdvo_write_cmd(psb_intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0); |
1264 | status = psb_intel_sdvo_read_response(psb_intel_sdvo, &response, 2); | |
1265 | ||
1266 | psb_intel_sdvo_write_cmd(psb_intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); | |
89c78134 AC |
1267 | } else { |
1268 | response[0] = 0; | |
1269 | response[1] = 0; | |
5736995b | 1270 | psb_intel_sdvo_write_cmd(psb_intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); |
89c78134 AC |
1271 | } |
1272 | ||
5736995b PJ |
1273 | psb_intel_sdvo_write_cmd(psb_intel_sdvo, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); |
1274 | psb_intel_sdvo_read_response(psb_intel_sdvo, &response, 2); | |
89c78134 | 1275 | } |
5736995b | 1276 | #endif |
89c78134 | 1277 | |
5736995b PJ |
1278 | static bool |
1279 | psb_intel_sdvo_multifunc_encoder(struct psb_intel_sdvo *psb_intel_sdvo) | |
89c78134 | 1280 | { |
5736995b PJ |
1281 | /* Is there more than one type of output? */ |
1282 | int caps = psb_intel_sdvo->caps.output_flags & 0xf; | |
1283 | return caps & -caps; | |
1284 | } | |
1285 | ||
1286 | static struct edid * | |
1287 | psb_intel_sdvo_get_edid(struct drm_connector *connector) | |
1288 | { | |
1289 | struct psb_intel_sdvo *sdvo = intel_attached_sdvo(connector); | |
1290 | return drm_get_edid(connector, &sdvo->ddc); | |
1291 | } | |
1292 | ||
1293 | /* Mac mini hack -- use the same DDC as the analog connector */ | |
1294 | static struct edid * | |
1295 | psb_intel_sdvo_get_analog_edid(struct drm_connector *connector) | |
1296 | { | |
1297 | struct drm_psb_private *dev_priv = connector->dev->dev_private; | |
1298 | ||
1299 | return drm_get_edid(connector, | |
1300 | &dev_priv->gmbus[dev_priv->crt_ddc_pin].adapter); | |
1301 | return NULL; | |
1302 | } | |
1303 | ||
1304 | enum drm_connector_status | |
1305 | psb_intel_sdvo_hdmi_sink_detect(struct drm_connector *connector) | |
1306 | { | |
1307 | struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector); | |
1308 | enum drm_connector_status status; | |
1309 | struct edid *edid; | |
1310 | ||
1311 | edid = psb_intel_sdvo_get_edid(connector); | |
1312 | ||
1313 | if (edid == NULL && psb_intel_sdvo_multifunc_encoder(psb_intel_sdvo)) { | |
1314 | u8 ddc, saved_ddc = psb_intel_sdvo->ddc_bus; | |
1315 | ||
1316 | /* | |
1317 | * Don't use the 1 as the argument of DDC bus switch to get | |
1318 | * the EDID. It is used for SDVO SPD ROM. | |
1319 | */ | |
1320 | for (ddc = psb_intel_sdvo->ddc_bus >> 1; ddc > 1; ddc >>= 1) { | |
1321 | psb_intel_sdvo->ddc_bus = ddc; | |
1322 | edid = psb_intel_sdvo_get_edid(connector); | |
1323 | if (edid) | |
1324 | break; | |
1325 | } | |
1326 | /* | |
1327 | * If we found the EDID on the other bus, | |
1328 | * assume that is the correct DDC bus. | |
1329 | */ | |
1330 | if (edid == NULL) | |
1331 | psb_intel_sdvo->ddc_bus = saved_ddc; | |
1332 | } | |
1333 | ||
1334 | /* | |
1335 | * When there is no edid and no monitor is connected with VGA | |
1336 | * port, try to use the CRT ddc to read the EDID for DVI-connector. | |
1337 | */ | |
1338 | if (edid == NULL) | |
1339 | edid = psb_intel_sdvo_get_analog_edid(connector); | |
1340 | ||
1341 | status = connector_status_unknown; | |
1342 | if (edid != NULL) { | |
1343 | /* DDC bus is shared, match EDID to connector type */ | |
1344 | if (edid->input & DRM_EDID_INPUT_DIGITAL) { | |
1345 | status = connector_status_connected; | |
1346 | if (psb_intel_sdvo->is_hdmi) { | |
1347 | psb_intel_sdvo->has_hdmi_monitor = drm_detect_hdmi_monitor(edid); | |
1348 | psb_intel_sdvo->has_hdmi_audio = drm_detect_monitor_audio(edid); | |
1349 | } | |
1350 | } else | |
1351 | status = connector_status_disconnected; | |
1352 | connector->display_info.raw_edid = NULL; | |
1353 | kfree(edid); | |
1354 | } | |
1355 | ||
1356 | if (status == connector_status_connected) { | |
1357 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector); | |
1358 | if (psb_intel_sdvo_connector->force_audio) | |
1359 | psb_intel_sdvo->has_hdmi_audio = psb_intel_sdvo_connector->force_audio > 0; | |
1360 | } | |
1361 | ||
1362 | return status; | |
1363 | } | |
1364 | ||
1365 | static enum drm_connector_status | |
1366 | psb_intel_sdvo_detect(struct drm_connector *connector, bool force) | |
1367 | { | |
1368 | uint16_t response; | |
1369 | struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector); | |
1370 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector); | |
1371 | enum drm_connector_status ret; | |
1372 | ||
1373 | if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo, | |
1374 | SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0)) | |
1375 | return connector_status_unknown; | |
1376 | ||
1377 | /* add 30ms delay when the output type might be TV */ | |
1378 | if (psb_intel_sdvo->caps.output_flags & | |
1379 | (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_CVBS0)) | |
1380 | mdelay(30); | |
1381 | ||
1382 | if (!psb_intel_sdvo_read_response(psb_intel_sdvo, &response, 2)) | |
1383 | return connector_status_unknown; | |
1384 | ||
1385 | DRM_DEBUG_KMS("SDVO response %d %d [%x]\n", | |
1386 | response & 0xff, response >> 8, | |
1387 | psb_intel_sdvo_connector->output_flag); | |
1388 | ||
1389 | if (response == 0) | |
89c78134 | 1390 | return connector_status_disconnected; |
5736995b PJ |
1391 | |
1392 | psb_intel_sdvo->attached_output = response; | |
1393 | ||
1394 | psb_intel_sdvo->has_hdmi_monitor = false; | |
1395 | psb_intel_sdvo->has_hdmi_audio = false; | |
1396 | ||
1397 | if ((psb_intel_sdvo_connector->output_flag & response) == 0) | |
1398 | ret = connector_status_disconnected; | |
1399 | else if (IS_TMDS(psb_intel_sdvo_connector)) | |
1400 | ret = psb_intel_sdvo_hdmi_sink_detect(connector); | |
1401 | else { | |
1402 | struct edid *edid; | |
1403 | ||
1404 | /* if we have an edid check it matches the connection */ | |
1405 | edid = psb_intel_sdvo_get_edid(connector); | |
1406 | if (edid == NULL) | |
1407 | edid = psb_intel_sdvo_get_analog_edid(connector); | |
1408 | if (edid != NULL) { | |
1409 | if (edid->input & DRM_EDID_INPUT_DIGITAL) | |
1410 | ret = connector_status_disconnected; | |
1411 | else | |
1412 | ret = connector_status_connected; | |
1413 | connector->display_info.raw_edid = NULL; | |
1414 | kfree(edid); | |
1415 | } else | |
1416 | ret = connector_status_connected; | |
1417 | } | |
1418 | ||
1419 | /* May update encoder flag for like clock for SDVO TV, etc.*/ | |
1420 | if (ret == connector_status_connected) { | |
1421 | psb_intel_sdvo->is_tv = false; | |
1422 | psb_intel_sdvo->is_lvds = false; | |
1423 | psb_intel_sdvo->base.needs_tv_clock = false; | |
1424 | ||
1425 | if (response & SDVO_TV_MASK) { | |
1426 | psb_intel_sdvo->is_tv = true; | |
1427 | psb_intel_sdvo->base.needs_tv_clock = true; | |
1428 | } | |
1429 | if (response & SDVO_LVDS_MASK) | |
1430 | psb_intel_sdvo->is_lvds = psb_intel_sdvo->sdvo_lvds_fixed_mode != NULL; | |
1431 | } | |
1432 | ||
1433 | return ret; | |
89c78134 AC |
1434 | } |
1435 | ||
5736995b | 1436 | static void psb_intel_sdvo_get_ddc_modes(struct drm_connector *connector) |
89c78134 | 1437 | { |
5736995b | 1438 | struct edid *edid; |
89c78134 AC |
1439 | |
1440 | /* set the bus switch and get the modes */ | |
5736995b | 1441 | edid = psb_intel_sdvo_get_edid(connector); |
89c78134 | 1442 | |
5736995b PJ |
1443 | /* |
1444 | * Mac mini hack. On this device, the DVI-I connector shares one DDC | |
1445 | * link between analog and digital outputs. So, if the regular SDVO | |
1446 | * DDC fails, check to see if the analog output is disconnected, in | |
1447 | * which case we'll look there for the digital DDC data. | |
1448 | */ | |
1449 | if (edid == NULL) | |
1450 | edid = psb_intel_sdvo_get_analog_edid(connector); | |
1451 | ||
1452 | if (edid != NULL) { | |
1453 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector); | |
1454 | bool monitor_is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL); | |
1455 | bool connector_is_digital = !!IS_TMDS(psb_intel_sdvo_connector); | |
1456 | ||
1457 | if (connector_is_digital == monitor_is_digital) { | |
1458 | drm_mode_connector_update_edid_property(connector, edid); | |
1459 | drm_add_edid_modes(connector, edid); | |
1460 | } | |
1461 | ||
1462 | connector->display_info.raw_edid = NULL; | |
1463 | kfree(edid); | |
1464 | } | |
1465 | } | |
1466 | ||
1467 | /* | |
1468 | * Set of SDVO TV modes. | |
1469 | * Note! This is in reply order (see loop in get_tv_modes). | |
1470 | * XXX: all 60Hz refresh? | |
1471 | */ | |
1472 | static const struct drm_display_mode sdvo_tv_modes[] = { | |
1473 | { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384, | |
1474 | 416, 0, 200, 201, 232, 233, 0, | |
1475 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1476 | { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384, | |
1477 | 416, 0, 240, 241, 272, 273, 0, | |
1478 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1479 | { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464, | |
1480 | 496, 0, 300, 301, 332, 333, 0, | |
1481 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1482 | { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704, | |
1483 | 736, 0, 350, 351, 382, 383, 0, | |
1484 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1485 | { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704, | |
1486 | 736, 0, 400, 401, 432, 433, 0, | |
1487 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1488 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704, | |
1489 | 736, 0, 480, 481, 512, 513, 0, | |
1490 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1491 | { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768, | |
1492 | 800, 0, 480, 481, 512, 513, 0, | |
1493 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1494 | { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768, | |
1495 | 800, 0, 576, 577, 608, 609, 0, | |
1496 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1497 | { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784, | |
1498 | 816, 0, 350, 351, 382, 383, 0, | |
1499 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1500 | { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784, | |
1501 | 816, 0, 400, 401, 432, 433, 0, | |
1502 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1503 | { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784, | |
1504 | 816, 0, 480, 481, 512, 513, 0, | |
1505 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1506 | { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784, | |
1507 | 816, 0, 540, 541, 572, 573, 0, | |
1508 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1509 | { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784, | |
1510 | 816, 0, 576, 577, 608, 609, 0, | |
1511 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1512 | { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832, | |
1513 | 864, 0, 576, 577, 608, 609, 0, | |
1514 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1515 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864, | |
1516 | 896, 0, 600, 601, 632, 633, 0, | |
1517 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1518 | { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896, | |
1519 | 928, 0, 624, 625, 656, 657, 0, | |
1520 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1521 | { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984, | |
1522 | 1016, 0, 766, 767, 798, 799, 0, | |
1523 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1524 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088, | |
1525 | 1120, 0, 768, 769, 800, 801, 0, | |
1526 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1527 | { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344, | |
1528 | 1376, 0, 1024, 1025, 1056, 1057, 0, | |
1529 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | |
1530 | }; | |
1531 | ||
1532 | static void psb_intel_sdvo_get_tv_modes(struct drm_connector *connector) | |
1533 | { | |
1534 | struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector); | |
1535 | struct psb_intel_sdvo_sdtv_resolution_request tv_res; | |
1536 | uint32_t reply = 0, format_map = 0; | |
1537 | int i; | |
1538 | ||
1539 | /* Read the list of supported input resolutions for the selected TV | |
1540 | * format. | |
1541 | */ | |
1542 | format_map = 1 << psb_intel_sdvo->tv_format_index; | |
1543 | memcpy(&tv_res, &format_map, | |
1544 | min(sizeof(format_map), sizeof(struct psb_intel_sdvo_sdtv_resolution_request))); | |
1545 | ||
1546 | if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo, psb_intel_sdvo->attached_output)) | |
1547 | return; | |
1548 | ||
1549 | BUILD_BUG_ON(sizeof(tv_res) != 3); | |
1550 | if (!psb_intel_sdvo_write_cmd(psb_intel_sdvo, | |
1551 | SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, | |
1552 | &tv_res, sizeof(tv_res))) | |
1553 | return; | |
1554 | if (!psb_intel_sdvo_read_response(psb_intel_sdvo, &reply, 3)) | |
1555 | return; | |
1556 | ||
1557 | for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++) | |
1558 | if (reply & (1 << i)) { | |
1559 | struct drm_display_mode *nmode; | |
1560 | nmode = drm_mode_duplicate(connector->dev, | |
1561 | &sdvo_tv_modes[i]); | |
1562 | if (nmode) | |
1563 | drm_mode_probed_add(connector, nmode); | |
1564 | } | |
1565 | } | |
1566 | ||
1567 | static void psb_intel_sdvo_get_lvds_modes(struct drm_connector *connector) | |
1568 | { | |
1569 | struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector); | |
1570 | struct drm_psb_private *dev_priv = connector->dev->dev_private; | |
1571 | struct drm_display_mode *newmode; | |
1572 | ||
1573 | /* | |
1574 | * Attempt to get the mode list from DDC. | |
1575 | * Assume that the preferred modes are | |
1576 | * arranged in priority order. | |
1577 | */ | |
1578 | psb_intel_ddc_get_modes(connector, psb_intel_sdvo->i2c); | |
1579 | if (list_empty(&connector->probed_modes) == false) | |
1580 | goto end; | |
1581 | ||
1582 | /* Fetch modes from VBT */ | |
1583 | if (dev_priv->sdvo_lvds_vbt_mode != NULL) { | |
1584 | newmode = drm_mode_duplicate(connector->dev, | |
1585 | dev_priv->sdvo_lvds_vbt_mode); | |
1586 | if (newmode != NULL) { | |
1587 | /* Guarantee the mode is preferred */ | |
1588 | newmode->type = (DRM_MODE_TYPE_PREFERRED | | |
1589 | DRM_MODE_TYPE_DRIVER); | |
1590 | drm_mode_probed_add(connector, newmode); | |
1591 | } | |
1592 | } | |
1593 | ||
1594 | end: | |
1595 | list_for_each_entry(newmode, &connector->probed_modes, head) { | |
1596 | if (newmode->type & DRM_MODE_TYPE_PREFERRED) { | |
1597 | psb_intel_sdvo->sdvo_lvds_fixed_mode = | |
1598 | drm_mode_duplicate(connector->dev, newmode); | |
1599 | ||
1600 | drm_mode_set_crtcinfo(psb_intel_sdvo->sdvo_lvds_fixed_mode, | |
1601 | 0); | |
1602 | ||
1603 | psb_intel_sdvo->is_lvds = true; | |
1604 | break; | |
1605 | } | |
1606 | } | |
1607 | ||
1608 | } | |
1609 | ||
1610 | static int psb_intel_sdvo_get_modes(struct drm_connector *connector) | |
1611 | { | |
1612 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector); | |
1613 | ||
1614 | if (IS_TV(psb_intel_sdvo_connector)) | |
1615 | psb_intel_sdvo_get_tv_modes(connector); | |
1616 | else if (IS_LVDS(psb_intel_sdvo_connector)) | |
1617 | psb_intel_sdvo_get_lvds_modes(connector); | |
1618 | else | |
1619 | psb_intel_sdvo_get_ddc_modes(connector); | |
1620 | ||
1621 | return !list_empty(&connector->probed_modes); | |
1622 | } | |
1623 | ||
1624 | static void | |
1625 | psb_intel_sdvo_destroy_enhance_property(struct drm_connector *connector) | |
1626 | { | |
1627 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector); | |
1628 | struct drm_device *dev = connector->dev; | |
1629 | ||
1630 | if (psb_intel_sdvo_connector->left) | |
1631 | drm_property_destroy(dev, psb_intel_sdvo_connector->left); | |
1632 | if (psb_intel_sdvo_connector->right) | |
1633 | drm_property_destroy(dev, psb_intel_sdvo_connector->right); | |
1634 | if (psb_intel_sdvo_connector->top) | |
1635 | drm_property_destroy(dev, psb_intel_sdvo_connector->top); | |
1636 | if (psb_intel_sdvo_connector->bottom) | |
1637 | drm_property_destroy(dev, psb_intel_sdvo_connector->bottom); | |
1638 | if (psb_intel_sdvo_connector->hpos) | |
1639 | drm_property_destroy(dev, psb_intel_sdvo_connector->hpos); | |
1640 | if (psb_intel_sdvo_connector->vpos) | |
1641 | drm_property_destroy(dev, psb_intel_sdvo_connector->vpos); | |
1642 | if (psb_intel_sdvo_connector->saturation) | |
1643 | drm_property_destroy(dev, psb_intel_sdvo_connector->saturation); | |
1644 | if (psb_intel_sdvo_connector->contrast) | |
1645 | drm_property_destroy(dev, psb_intel_sdvo_connector->contrast); | |
1646 | if (psb_intel_sdvo_connector->hue) | |
1647 | drm_property_destroy(dev, psb_intel_sdvo_connector->hue); | |
1648 | if (psb_intel_sdvo_connector->sharpness) | |
1649 | drm_property_destroy(dev, psb_intel_sdvo_connector->sharpness); | |
1650 | if (psb_intel_sdvo_connector->flicker_filter) | |
1651 | drm_property_destroy(dev, psb_intel_sdvo_connector->flicker_filter); | |
1652 | if (psb_intel_sdvo_connector->flicker_filter_2d) | |
1653 | drm_property_destroy(dev, psb_intel_sdvo_connector->flicker_filter_2d); | |
1654 | if (psb_intel_sdvo_connector->flicker_filter_adaptive) | |
1655 | drm_property_destroy(dev, psb_intel_sdvo_connector->flicker_filter_adaptive); | |
1656 | if (psb_intel_sdvo_connector->tv_luma_filter) | |
1657 | drm_property_destroy(dev, psb_intel_sdvo_connector->tv_luma_filter); | |
1658 | if (psb_intel_sdvo_connector->tv_chroma_filter) | |
1659 | drm_property_destroy(dev, psb_intel_sdvo_connector->tv_chroma_filter); | |
1660 | if (psb_intel_sdvo_connector->dot_crawl) | |
1661 | drm_property_destroy(dev, psb_intel_sdvo_connector->dot_crawl); | |
1662 | if (psb_intel_sdvo_connector->brightness) | |
1663 | drm_property_destroy(dev, psb_intel_sdvo_connector->brightness); | |
89c78134 AC |
1664 | } |
1665 | ||
1666 | static void psb_intel_sdvo_destroy(struct drm_connector *connector) | |
1667 | { | |
5736995b | 1668 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector); |
89c78134 | 1669 | |
5736995b PJ |
1670 | if (psb_intel_sdvo_connector->tv_format) |
1671 | drm_property_destroy(connector->dev, | |
1672 | psb_intel_sdvo_connector->tv_format); | |
1673 | ||
1674 | psb_intel_sdvo_destroy_enhance_property(connector); | |
89c78134 AC |
1675 | drm_sysfs_connector_remove(connector); |
1676 | drm_connector_cleanup(connector); | |
5736995b PJ |
1677 | kfree(connector); |
1678 | } | |
1679 | ||
1680 | static bool psb_intel_sdvo_detect_hdmi_audio(struct drm_connector *connector) | |
1681 | { | |
1682 | struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector); | |
1683 | struct edid *edid; | |
1684 | bool has_audio = false; | |
1685 | ||
1686 | if (!psb_intel_sdvo->is_hdmi) | |
1687 | return false; | |
1688 | ||
1689 | edid = psb_intel_sdvo_get_edid(connector); | |
1690 | if (edid != NULL && edid->input & DRM_EDID_INPUT_DIGITAL) | |
1691 | has_audio = drm_detect_monitor_audio(edid); | |
1692 | ||
1693 | return has_audio; | |
1694 | } | |
1695 | ||
1696 | static int | |
1697 | psb_intel_sdvo_set_property(struct drm_connector *connector, | |
1698 | struct drm_property *property, | |
1699 | uint64_t val) | |
1700 | { | |
1701 | struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector); | |
1702 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector = to_psb_intel_sdvo_connector(connector); | |
1703 | struct drm_psb_private *dev_priv = connector->dev->dev_private; | |
1704 | uint16_t temp_value; | |
1705 | uint8_t cmd; | |
1706 | int ret; | |
1707 | ||
1708 | ret = drm_connector_property_set_value(connector, property, val); | |
1709 | if (ret) | |
1710 | return ret; | |
1711 | ||
1712 | if (property == dev_priv->force_audio_property) { | |
1713 | int i = val; | |
1714 | bool has_audio; | |
1715 | ||
1716 | if (i == psb_intel_sdvo_connector->force_audio) | |
1717 | return 0; | |
1718 | ||
1719 | psb_intel_sdvo_connector->force_audio = i; | |
1720 | ||
1721 | if (i == 0) | |
1722 | has_audio = psb_intel_sdvo_detect_hdmi_audio(connector); | |
1723 | else | |
1724 | has_audio = i > 0; | |
1725 | ||
1726 | if (has_audio == psb_intel_sdvo->has_hdmi_audio) | |
1727 | return 0; | |
1728 | ||
1729 | psb_intel_sdvo->has_hdmi_audio = has_audio; | |
1730 | goto done; | |
1731 | } | |
1732 | ||
1733 | if (property == dev_priv->broadcast_rgb_property) { | |
1734 | if (val == !!psb_intel_sdvo->color_range) | |
1735 | return 0; | |
1736 | ||
1737 | psb_intel_sdvo->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0; | |
1738 | goto done; | |
1739 | } | |
1740 | ||
1741 | #define CHECK_PROPERTY(name, NAME) \ | |
1742 | if (psb_intel_sdvo_connector->name == property) { \ | |
1743 | if (psb_intel_sdvo_connector->cur_##name == temp_value) return 0; \ | |
1744 | if (psb_intel_sdvo_connector->max_##name < temp_value) return -EINVAL; \ | |
1745 | cmd = SDVO_CMD_SET_##NAME; \ | |
1746 | psb_intel_sdvo_connector->cur_##name = temp_value; \ | |
1747 | goto set_value; \ | |
1748 | } | |
1749 | ||
1750 | if (property == psb_intel_sdvo_connector->tv_format) { | |
1751 | if (val >= TV_FORMAT_NUM) | |
1752 | return -EINVAL; | |
1753 | ||
1754 | if (psb_intel_sdvo->tv_format_index == | |
1755 | psb_intel_sdvo_connector->tv_format_supported[val]) | |
1756 | return 0; | |
1757 | ||
1758 | psb_intel_sdvo->tv_format_index = psb_intel_sdvo_connector->tv_format_supported[val]; | |
1759 | goto done; | |
1760 | } else if (IS_TV_OR_LVDS(psb_intel_sdvo_connector)) { | |
1761 | temp_value = val; | |
1762 | if (psb_intel_sdvo_connector->left == property) { | |
1763 | drm_connector_property_set_value(connector, | |
1764 | psb_intel_sdvo_connector->right, val); | |
1765 | if (psb_intel_sdvo_connector->left_margin == temp_value) | |
1766 | return 0; | |
1767 | ||
1768 | psb_intel_sdvo_connector->left_margin = temp_value; | |
1769 | psb_intel_sdvo_connector->right_margin = temp_value; | |
1770 | temp_value = psb_intel_sdvo_connector->max_hscan - | |
1771 | psb_intel_sdvo_connector->left_margin; | |
1772 | cmd = SDVO_CMD_SET_OVERSCAN_H; | |
1773 | goto set_value; | |
1774 | } else if (psb_intel_sdvo_connector->right == property) { | |
1775 | drm_connector_property_set_value(connector, | |
1776 | psb_intel_sdvo_connector->left, val); | |
1777 | if (psb_intel_sdvo_connector->right_margin == temp_value) | |
1778 | return 0; | |
1779 | ||
1780 | psb_intel_sdvo_connector->left_margin = temp_value; | |
1781 | psb_intel_sdvo_connector->right_margin = temp_value; | |
1782 | temp_value = psb_intel_sdvo_connector->max_hscan - | |
1783 | psb_intel_sdvo_connector->left_margin; | |
1784 | cmd = SDVO_CMD_SET_OVERSCAN_H; | |
1785 | goto set_value; | |
1786 | } else if (psb_intel_sdvo_connector->top == property) { | |
1787 | drm_connector_property_set_value(connector, | |
1788 | psb_intel_sdvo_connector->bottom, val); | |
1789 | if (psb_intel_sdvo_connector->top_margin == temp_value) | |
1790 | return 0; | |
1791 | ||
1792 | psb_intel_sdvo_connector->top_margin = temp_value; | |
1793 | psb_intel_sdvo_connector->bottom_margin = temp_value; | |
1794 | temp_value = psb_intel_sdvo_connector->max_vscan - | |
1795 | psb_intel_sdvo_connector->top_margin; | |
1796 | cmd = SDVO_CMD_SET_OVERSCAN_V; | |
1797 | goto set_value; | |
1798 | } else if (psb_intel_sdvo_connector->bottom == property) { | |
1799 | drm_connector_property_set_value(connector, | |
1800 | psb_intel_sdvo_connector->top, val); | |
1801 | if (psb_intel_sdvo_connector->bottom_margin == temp_value) | |
1802 | return 0; | |
1803 | ||
1804 | psb_intel_sdvo_connector->top_margin = temp_value; | |
1805 | psb_intel_sdvo_connector->bottom_margin = temp_value; | |
1806 | temp_value = psb_intel_sdvo_connector->max_vscan - | |
1807 | psb_intel_sdvo_connector->top_margin; | |
1808 | cmd = SDVO_CMD_SET_OVERSCAN_V; | |
1809 | goto set_value; | |
1810 | } | |
1811 | CHECK_PROPERTY(hpos, HPOS) | |
1812 | CHECK_PROPERTY(vpos, VPOS) | |
1813 | CHECK_PROPERTY(saturation, SATURATION) | |
1814 | CHECK_PROPERTY(contrast, CONTRAST) | |
1815 | CHECK_PROPERTY(hue, HUE) | |
1816 | CHECK_PROPERTY(brightness, BRIGHTNESS) | |
1817 | CHECK_PROPERTY(sharpness, SHARPNESS) | |
1818 | CHECK_PROPERTY(flicker_filter, FLICKER_FILTER) | |
1819 | CHECK_PROPERTY(flicker_filter_2d, FLICKER_FILTER_2D) | |
1820 | CHECK_PROPERTY(flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE) | |
1821 | CHECK_PROPERTY(tv_chroma_filter, TV_CHROMA_FILTER) | |
1822 | CHECK_PROPERTY(tv_luma_filter, TV_LUMA_FILTER) | |
1823 | CHECK_PROPERTY(dot_crawl, DOT_CRAWL) | |
1824 | } | |
1825 | ||
1826 | return -EINVAL; /* unknown property */ | |
1827 | ||
1828 | set_value: | |
1829 | if (!psb_intel_sdvo_set_value(psb_intel_sdvo, cmd, &temp_value, 2)) | |
1830 | return -EIO; | |
1831 | ||
1832 | ||
1833 | done: | |
1834 | if (psb_intel_sdvo->base.base.crtc) { | |
1835 | struct drm_crtc *crtc = psb_intel_sdvo->base.base.crtc; | |
1836 | drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, | |
1837 | crtc->y, crtc->fb); | |
1838 | } | |
1839 | ||
1840 | return 0; | |
1841 | #undef CHECK_PROPERTY | |
89c78134 AC |
1842 | } |
1843 | ||
1844 | static const struct drm_encoder_helper_funcs psb_intel_sdvo_helper_funcs = { | |
1845 | .dpms = psb_intel_sdvo_dpms, | |
1846 | .mode_fixup = psb_intel_sdvo_mode_fixup, | |
1847 | .prepare = psb_intel_encoder_prepare, | |
1848 | .mode_set = psb_intel_sdvo_mode_set, | |
1849 | .commit = psb_intel_encoder_commit, | |
1850 | }; | |
1851 | ||
1852 | static const struct drm_connector_funcs psb_intel_sdvo_connector_funcs = { | |
1853 | .dpms = drm_helper_connector_dpms, | |
89c78134 AC |
1854 | .detect = psb_intel_sdvo_detect, |
1855 | .fill_modes = drm_helper_probe_single_connector_modes, | |
5736995b | 1856 | .set_property = psb_intel_sdvo_set_property, |
89c78134 AC |
1857 | .destroy = psb_intel_sdvo_destroy, |
1858 | }; | |
1859 | ||
5736995b | 1860 | static const struct drm_connector_helper_funcs psb_intel_sdvo_connector_helper_funcs = { |
89c78134 AC |
1861 | .get_modes = psb_intel_sdvo_get_modes, |
1862 | .mode_valid = psb_intel_sdvo_mode_valid, | |
1863 | .best_encoder = psb_intel_best_encoder, | |
1864 | }; | |
1865 | ||
5736995b | 1866 | static void psb_intel_sdvo_enc_destroy(struct drm_encoder *encoder) |
89c78134 | 1867 | { |
5736995b PJ |
1868 | struct psb_intel_sdvo *psb_intel_sdvo = to_psb_intel_sdvo(encoder); |
1869 | ||
1870 | if (psb_intel_sdvo->sdvo_lvds_fixed_mode != NULL) | |
1871 | drm_mode_destroy(encoder->dev, | |
1872 | psb_intel_sdvo->sdvo_lvds_fixed_mode); | |
1873 | ||
1874 | i2c_del_adapter(&psb_intel_sdvo->ddc); | |
1875 | psb_intel_encoder_destroy(encoder); | |
89c78134 AC |
1876 | } |
1877 | ||
1878 | static const struct drm_encoder_funcs psb_intel_sdvo_enc_funcs = { | |
1879 | .destroy = psb_intel_sdvo_enc_destroy, | |
1880 | }; | |
1881 | ||
5736995b PJ |
1882 | static void |
1883 | psb_intel_sdvo_guess_ddc_bus(struct psb_intel_sdvo *sdvo) | |
89c78134 | 1884 | { |
fea578b6 PJ |
1885 | /* FIXME: At the moment, ddc_bus = 2 is the only thing that works. |
1886 | * We need to figure out if this is true for all available poulsbo | |
1887 | * hardware, or if we need to fiddle with the guessing code above. | |
1888 | * The problem might go away if we can parse sdvo mappings from bios */ | |
1889 | sdvo->ddc_bus = 2; | |
1890 | ||
1891 | #if 0 | |
5736995b PJ |
1892 | uint16_t mask = 0; |
1893 | unsigned int num_bits; | |
89c78134 | 1894 | |
5736995b PJ |
1895 | /* Make a mask of outputs less than or equal to our own priority in the |
1896 | * list. | |
1897 | */ | |
1898 | switch (sdvo->controlled_output) { | |
1899 | case SDVO_OUTPUT_LVDS1: | |
1900 | mask |= SDVO_OUTPUT_LVDS1; | |
1901 | case SDVO_OUTPUT_LVDS0: | |
1902 | mask |= SDVO_OUTPUT_LVDS0; | |
1903 | case SDVO_OUTPUT_TMDS1: | |
1904 | mask |= SDVO_OUTPUT_TMDS1; | |
1905 | case SDVO_OUTPUT_TMDS0: | |
1906 | mask |= SDVO_OUTPUT_TMDS0; | |
1907 | case SDVO_OUTPUT_RGB1: | |
1908 | mask |= SDVO_OUTPUT_RGB1; | |
1909 | case SDVO_OUTPUT_RGB0: | |
1910 | mask |= SDVO_OUTPUT_RGB0; | |
1911 | break; | |
1912 | } | |
89c78134 | 1913 | |
5736995b PJ |
1914 | /* Count bits to find what number we are in the priority list. */ |
1915 | mask &= sdvo->caps.output_flags; | |
1916 | num_bits = hweight16(mask); | |
1917 | /* If more than 3 outputs, default to DDC bus 3 for now. */ | |
1918 | if (num_bits > 3) | |
1919 | num_bits = 3; | |
89c78134 | 1920 | |
5736995b PJ |
1921 | /* Corresponds to SDVO_CONTROL_BUS_DDCx */ |
1922 | sdvo->ddc_bus = 1 << num_bits; | |
fea578b6 | 1923 | #endif |
5736995b | 1924 | } |
89c78134 | 1925 | |
5736995b PJ |
1926 | /** |
1927 | * Choose the appropriate DDC bus for control bus switch command for this | |
1928 | * SDVO output based on the controlled output. | |
1929 | * | |
1930 | * DDC bus number assignment is in a priority order of RGB outputs, then TMDS | |
1931 | * outputs, then LVDS outputs. | |
1932 | */ | |
1933 | static void | |
1934 | psb_intel_sdvo_select_ddc_bus(struct drm_psb_private *dev_priv, | |
1935 | struct psb_intel_sdvo *sdvo, u32 reg) | |
1936 | { | |
1937 | struct sdvo_device_mapping *mapping; | |
1938 | ||
1939 | if (IS_SDVOB(reg)) | |
1940 | mapping = &(dev_priv->sdvo_mappings[0]); | |
1941 | else | |
1942 | mapping = &(dev_priv->sdvo_mappings[1]); | |
1943 | ||
1944 | if (mapping->initialized) | |
1945 | sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4); | |
1946 | else | |
1947 | psb_intel_sdvo_guess_ddc_bus(sdvo); | |
1948 | } | |
1949 | ||
1950 | static void | |
1951 | psb_intel_sdvo_select_i2c_bus(struct drm_psb_private *dev_priv, | |
1952 | struct psb_intel_sdvo *sdvo, u32 reg) | |
1953 | { | |
1954 | struct sdvo_device_mapping *mapping; | |
1955 | u8 pin, speed; | |
89c78134 | 1956 | |
5736995b PJ |
1957 | if (IS_SDVOB(reg)) |
1958 | mapping = &dev_priv->sdvo_mappings[0]; | |
89c78134 | 1959 | else |
5736995b | 1960 | mapping = &dev_priv->sdvo_mappings[1]; |
89c78134 | 1961 | |
5736995b PJ |
1962 | pin = GMBUS_PORT_DPB; |
1963 | speed = GMBUS_RATE_1MHZ >> 8; | |
1964 | if (mapping->initialized) { | |
1965 | pin = mapping->i2c_pin; | |
1966 | speed = mapping->i2c_speed; | |
1967 | } | |
89c78134 | 1968 | |
5736995b PJ |
1969 | if (pin < GMBUS_NUM_PORTS) { |
1970 | sdvo->i2c = &dev_priv->gmbus[pin].adapter; | |
1971 | gma_intel_gmbus_set_speed(sdvo->i2c, speed); | |
1972 | gma_intel_gmbus_force_bit(sdvo->i2c, true); | |
1973 | } else | |
1974 | sdvo->i2c = &dev_priv->gmbus[GMBUS_PORT_DPB].adapter; | |
1975 | } | |
89c78134 | 1976 | |
5736995b PJ |
1977 | static bool |
1978 | psb_intel_sdvo_is_hdmi_connector(struct psb_intel_sdvo *psb_intel_sdvo, int device) | |
1979 | { | |
1980 | return psb_intel_sdvo_check_supp_encode(psb_intel_sdvo); | |
1981 | } | |
1982 | ||
1983 | static u8 | |
1984 | psb_intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg) | |
1985 | { | |
1986 | struct drm_psb_private *dev_priv = dev->dev_private; | |
1987 | struct sdvo_device_mapping *my_mapping, *other_mapping; | |
1988 | ||
1989 | if (IS_SDVOB(sdvo_reg)) { | |
1990 | my_mapping = &dev_priv->sdvo_mappings[0]; | |
1991 | other_mapping = &dev_priv->sdvo_mappings[1]; | |
89c78134 | 1992 | } else { |
5736995b PJ |
1993 | my_mapping = &dev_priv->sdvo_mappings[1]; |
1994 | other_mapping = &dev_priv->sdvo_mappings[0]; | |
1995 | } | |
1996 | ||
1997 | /* If the BIOS described our SDVO device, take advantage of it. */ | |
1998 | if (my_mapping->slave_addr) | |
1999 | return my_mapping->slave_addr; | |
2000 | ||
2001 | /* If the BIOS only described a different SDVO device, use the | |
2002 | * address that it isn't using. | |
2003 | */ | |
2004 | if (other_mapping->slave_addr) { | |
2005 | if (other_mapping->slave_addr == 0x70) | |
2006 | return 0x72; | |
2007 | else | |
2008 | return 0x70; | |
2009 | } | |
2010 | ||
2011 | /* No SDVO device info is found for another DVO port, | |
2012 | * so use mapping assumption we had before BIOS parsing. | |
2013 | */ | |
2014 | if (IS_SDVOB(sdvo_reg)) | |
2015 | return 0x70; | |
2016 | else | |
2017 | return 0x72; | |
2018 | } | |
2019 | ||
2020 | static void | |
2021 | psb_intel_sdvo_connector_init(struct psb_intel_sdvo_connector *connector, | |
2022 | struct psb_intel_sdvo *encoder) | |
2023 | { | |
2024 | drm_connector_init(encoder->base.base.dev, | |
2025 | &connector->base.base, | |
2026 | &psb_intel_sdvo_connector_funcs, | |
2027 | connector->base.base.connector_type); | |
2028 | ||
2029 | drm_connector_helper_add(&connector->base.base, | |
2030 | &psb_intel_sdvo_connector_helper_funcs); | |
2031 | ||
2032 | connector->base.base.interlace_allowed = 0; | |
2033 | connector->base.base.doublescan_allowed = 0; | |
2034 | connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB; | |
2035 | ||
2036 | psb_intel_connector_attach_encoder(&connector->base, &encoder->base); | |
2037 | drm_sysfs_connector_add(&connector->base.base); | |
2038 | } | |
2039 | ||
2040 | static void | |
2041 | psb_intel_sdvo_add_hdmi_properties(struct psb_intel_sdvo_connector *connector) | |
2042 | { | |
2043 | /* FIXME: We don't support HDMI at the moment | |
2044 | struct drm_device *dev = connector->base.base.dev; | |
2045 | ||
2046 | intel_attach_force_audio_property(&connector->base.base); | |
2047 | if (INTEL_INFO(dev)->gen >= 4 && IS_MOBILE(dev)) | |
2048 | intel_attach_broadcast_rgb_property(&connector->base.base); | |
2049 | */ | |
2050 | } | |
2051 | ||
2052 | static bool | |
2053 | psb_intel_sdvo_dvi_init(struct psb_intel_sdvo *psb_intel_sdvo, int device) | |
2054 | { | |
2055 | struct drm_encoder *encoder = &psb_intel_sdvo->base.base; | |
2056 | struct drm_connector *connector; | |
2057 | struct psb_intel_connector *intel_connector; | |
2058 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector; | |
2059 | ||
2060 | psb_intel_sdvo_connector = kzalloc(sizeof(struct psb_intel_sdvo_connector), GFP_KERNEL); | |
2061 | if (!psb_intel_sdvo_connector) | |
2062 | return false; | |
2063 | ||
2064 | if (device == 0) { | |
2065 | psb_intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS0; | |
2066 | psb_intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0; | |
2067 | } else if (device == 1) { | |
2068 | psb_intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS1; | |
2069 | psb_intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1; | |
2070 | } | |
2071 | ||
2072 | intel_connector = &psb_intel_sdvo_connector->base; | |
2073 | connector = &intel_connector->base; | |
2074 | // connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT; | |
2075 | encoder->encoder_type = DRM_MODE_ENCODER_TMDS; | |
2076 | connector->connector_type = DRM_MODE_CONNECTOR_DVID; | |
2077 | ||
2078 | if (psb_intel_sdvo_is_hdmi_connector(psb_intel_sdvo, device)) { | |
2079 | connector->connector_type = DRM_MODE_CONNECTOR_HDMIA; | |
2080 | psb_intel_sdvo->is_hdmi = true; | |
2081 | } | |
2082 | psb_intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | | |
2083 | (1 << INTEL_ANALOG_CLONE_BIT)); | |
2084 | ||
2085 | psb_intel_sdvo_connector_init(psb_intel_sdvo_connector, psb_intel_sdvo); | |
2086 | if (psb_intel_sdvo->is_hdmi) | |
2087 | psb_intel_sdvo_add_hdmi_properties(psb_intel_sdvo_connector); | |
2088 | ||
2089 | return true; | |
2090 | } | |
2091 | ||
2092 | static bool | |
2093 | psb_intel_sdvo_tv_init(struct psb_intel_sdvo *psb_intel_sdvo, int type) | |
2094 | { | |
2095 | struct drm_encoder *encoder = &psb_intel_sdvo->base.base; | |
2096 | struct drm_connector *connector; | |
2097 | struct psb_intel_connector *intel_connector; | |
2098 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector; | |
2099 | ||
2100 | psb_intel_sdvo_connector = kzalloc(sizeof(struct psb_intel_sdvo_connector), GFP_KERNEL); | |
2101 | if (!psb_intel_sdvo_connector) | |
2102 | return false; | |
2103 | ||
2104 | intel_connector = &psb_intel_sdvo_connector->base; | |
2105 | connector = &intel_connector->base; | |
2106 | encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; | |
2107 | connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; | |
2108 | ||
2109 | psb_intel_sdvo->controlled_output |= type; | |
2110 | psb_intel_sdvo_connector->output_flag = type; | |
2111 | ||
2112 | psb_intel_sdvo->is_tv = true; | |
2113 | psb_intel_sdvo->base.needs_tv_clock = true; | |
2114 | psb_intel_sdvo->base.clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; | |
2115 | ||
2116 | psb_intel_sdvo_connector_init(psb_intel_sdvo_connector, psb_intel_sdvo); | |
2117 | ||
2118 | if (!psb_intel_sdvo_tv_create_property(psb_intel_sdvo, psb_intel_sdvo_connector, type)) | |
2119 | goto err; | |
2120 | ||
2121 | if (!psb_intel_sdvo_create_enhance_property(psb_intel_sdvo, psb_intel_sdvo_connector)) | |
2122 | goto err; | |
2123 | ||
2124 | return true; | |
2125 | ||
2126 | err: | |
2127 | psb_intel_sdvo_destroy(connector); | |
2128 | return false; | |
2129 | } | |
2130 | ||
2131 | static bool | |
2132 | psb_intel_sdvo_analog_init(struct psb_intel_sdvo *psb_intel_sdvo, int device) | |
2133 | { | |
2134 | struct drm_encoder *encoder = &psb_intel_sdvo->base.base; | |
2135 | struct drm_connector *connector; | |
2136 | struct psb_intel_connector *intel_connector; | |
2137 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector; | |
2138 | ||
2139 | psb_intel_sdvo_connector = kzalloc(sizeof(struct psb_intel_sdvo_connector), GFP_KERNEL); | |
2140 | if (!psb_intel_sdvo_connector) | |
2141 | return false; | |
2142 | ||
2143 | intel_connector = &psb_intel_sdvo_connector->base; | |
2144 | connector = &intel_connector->base; | |
2145 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; | |
2146 | encoder->encoder_type = DRM_MODE_ENCODER_DAC; | |
2147 | connector->connector_type = DRM_MODE_CONNECTOR_VGA; | |
2148 | ||
2149 | if (device == 0) { | |
2150 | psb_intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0; | |
2151 | psb_intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0; | |
2152 | } else if (device == 1) { | |
2153 | psb_intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1; | |
2154 | psb_intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1; | |
2155 | } | |
2156 | ||
2157 | psb_intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) | | |
2158 | (1 << INTEL_ANALOG_CLONE_BIT)); | |
2159 | ||
2160 | psb_intel_sdvo_connector_init(psb_intel_sdvo_connector, | |
2161 | psb_intel_sdvo); | |
2162 | return true; | |
2163 | } | |
2164 | ||
2165 | static bool | |
2166 | psb_intel_sdvo_lvds_init(struct psb_intel_sdvo *psb_intel_sdvo, int device) | |
2167 | { | |
2168 | struct drm_encoder *encoder = &psb_intel_sdvo->base.base; | |
2169 | struct drm_connector *connector; | |
2170 | struct psb_intel_connector *intel_connector; | |
2171 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector; | |
2172 | ||
2173 | psb_intel_sdvo_connector = kzalloc(sizeof(struct psb_intel_sdvo_connector), GFP_KERNEL); | |
2174 | if (!psb_intel_sdvo_connector) | |
2175 | return false; | |
2176 | ||
2177 | intel_connector = &psb_intel_sdvo_connector->base; | |
2178 | connector = &intel_connector->base; | |
2179 | encoder->encoder_type = DRM_MODE_ENCODER_LVDS; | |
2180 | connector->connector_type = DRM_MODE_CONNECTOR_LVDS; | |
2181 | ||
2182 | if (device == 0) { | |
2183 | psb_intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0; | |
2184 | psb_intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0; | |
2185 | } else if (device == 1) { | |
2186 | psb_intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1; | |
2187 | psb_intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1; | |
2188 | } | |
2189 | ||
2190 | psb_intel_sdvo->base.clone_mask = ((1 << INTEL_ANALOG_CLONE_BIT) | | |
2191 | (1 << INTEL_SDVO_LVDS_CLONE_BIT)); | |
2192 | ||
2193 | psb_intel_sdvo_connector_init(psb_intel_sdvo_connector, psb_intel_sdvo); | |
2194 | if (!psb_intel_sdvo_create_enhance_property(psb_intel_sdvo, psb_intel_sdvo_connector)) | |
2195 | goto err; | |
2196 | ||
2197 | return true; | |
2198 | ||
2199 | err: | |
2200 | psb_intel_sdvo_destroy(connector); | |
2201 | return false; | |
2202 | } | |
2203 | ||
2204 | static bool | |
2205 | psb_intel_sdvo_output_setup(struct psb_intel_sdvo *psb_intel_sdvo, uint16_t flags) | |
2206 | { | |
2207 | psb_intel_sdvo->is_tv = false; | |
2208 | psb_intel_sdvo->base.needs_tv_clock = false; | |
2209 | psb_intel_sdvo->is_lvds = false; | |
2210 | ||
2211 | /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/ | |
2212 | ||
2213 | if (flags & SDVO_OUTPUT_TMDS0) | |
2214 | if (!psb_intel_sdvo_dvi_init(psb_intel_sdvo, 0)) | |
2215 | return false; | |
2216 | ||
2217 | if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK) | |
2218 | if (!psb_intel_sdvo_dvi_init(psb_intel_sdvo, 1)) | |
2219 | return false; | |
2220 | ||
2221 | /* TV has no XXX1 function block */ | |
2222 | if (flags & SDVO_OUTPUT_SVID0) | |
2223 | if (!psb_intel_sdvo_tv_init(psb_intel_sdvo, SDVO_OUTPUT_SVID0)) | |
2224 | return false; | |
2225 | ||
2226 | if (flags & SDVO_OUTPUT_CVBS0) | |
2227 | if (!psb_intel_sdvo_tv_init(psb_intel_sdvo, SDVO_OUTPUT_CVBS0)) | |
2228 | return false; | |
2229 | ||
2230 | if (flags & SDVO_OUTPUT_RGB0) | |
2231 | if (!psb_intel_sdvo_analog_init(psb_intel_sdvo, 0)) | |
2232 | return false; | |
2233 | ||
2234 | if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK) | |
2235 | if (!psb_intel_sdvo_analog_init(psb_intel_sdvo, 1)) | |
2236 | return false; | |
2237 | ||
2238 | if (flags & SDVO_OUTPUT_LVDS0) | |
2239 | if (!psb_intel_sdvo_lvds_init(psb_intel_sdvo, 0)) | |
2240 | return false; | |
2241 | ||
2242 | if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK) | |
2243 | if (!psb_intel_sdvo_lvds_init(psb_intel_sdvo, 1)) | |
2244 | return false; | |
2245 | ||
2246 | if ((flags & SDVO_OUTPUT_MASK) == 0) { | |
2247 | unsigned char bytes[2]; | |
2248 | ||
2249 | psb_intel_sdvo->controlled_output = 0; | |
2250 | memcpy(bytes, &psb_intel_sdvo->caps.output_flags, 2); | |
2251 | DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n", | |
2252 | SDVO_NAME(psb_intel_sdvo), | |
2253 | bytes[0], bytes[1]); | |
2254 | return false; | |
2255 | } | |
2256 | psb_intel_sdvo->base.crtc_mask = (1 << 0) | (1 << 1); | |
2257 | ||
2258 | return true; | |
2259 | } | |
2260 | ||
2261 | static bool psb_intel_sdvo_tv_create_property(struct psb_intel_sdvo *psb_intel_sdvo, | |
2262 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector, | |
2263 | int type) | |
2264 | { | |
2265 | struct drm_device *dev = psb_intel_sdvo->base.base.dev; | |
2266 | struct psb_intel_sdvo_tv_format format; | |
2267 | uint32_t format_map, i; | |
2268 | ||
2269 | if (!psb_intel_sdvo_set_target_output(psb_intel_sdvo, type)) | |
2270 | return false; | |
2271 | ||
2272 | BUILD_BUG_ON(sizeof(format) != 6); | |
2273 | if (!psb_intel_sdvo_get_value(psb_intel_sdvo, | |
2274 | SDVO_CMD_GET_SUPPORTED_TV_FORMATS, | |
2275 | &format, sizeof(format))) | |
2276 | return false; | |
2277 | ||
2278 | memcpy(&format_map, &format, min(sizeof(format_map), sizeof(format))); | |
2279 | ||
2280 | if (format_map == 0) | |
2281 | return false; | |
2282 | ||
2283 | psb_intel_sdvo_connector->format_supported_num = 0; | |
2284 | for (i = 0 ; i < TV_FORMAT_NUM; i++) | |
2285 | if (format_map & (1 << i)) | |
2286 | psb_intel_sdvo_connector->tv_format_supported[psb_intel_sdvo_connector->format_supported_num++] = i; | |
2287 | ||
2288 | ||
2289 | psb_intel_sdvo_connector->tv_format = | |
2290 | drm_property_create(dev, DRM_MODE_PROP_ENUM, | |
2291 | "mode", psb_intel_sdvo_connector->format_supported_num); | |
2292 | if (!psb_intel_sdvo_connector->tv_format) | |
2293 | return false; | |
2294 | ||
2295 | for (i = 0; i < psb_intel_sdvo_connector->format_supported_num; i++) | |
2296 | drm_property_add_enum( | |
2297 | psb_intel_sdvo_connector->tv_format, i, | |
2298 | i, tv_format_names[psb_intel_sdvo_connector->tv_format_supported[i]]); | |
2299 | ||
2300 | psb_intel_sdvo->tv_format_index = psb_intel_sdvo_connector->tv_format_supported[0]; | |
2301 | drm_connector_attach_property(&psb_intel_sdvo_connector->base.base, | |
2302 | psb_intel_sdvo_connector->tv_format, 0); | |
2303 | return true; | |
2304 | ||
2305 | } | |
2306 | ||
2307 | #define ENHANCEMENT(name, NAME) do { \ | |
2308 | if (enhancements.name) { \ | |
2309 | if (!psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \ | |
2310 | !psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \ | |
2311 | return false; \ | |
2312 | psb_intel_sdvo_connector->max_##name = data_value[0]; \ | |
2313 | psb_intel_sdvo_connector->cur_##name = response; \ | |
2314 | psb_intel_sdvo_connector->name = \ | |
d9bc3c02 | 2315 | drm_property_create_range(dev, 0, #name, 0, data_value[0]); \ |
5736995b | 2316 | if (!psb_intel_sdvo_connector->name) return false; \ |
5736995b PJ |
2317 | drm_connector_attach_property(connector, \ |
2318 | psb_intel_sdvo_connector->name, \ | |
2319 | psb_intel_sdvo_connector->cur_##name); \ | |
2320 | DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \ | |
2321 | data_value[0], data_value[1], response); \ | |
2322 | } \ | |
2323 | } while(0) | |
2324 | ||
2325 | static bool | |
2326 | psb_intel_sdvo_create_enhance_property_tv(struct psb_intel_sdvo *psb_intel_sdvo, | |
2327 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector, | |
2328 | struct psb_intel_sdvo_enhancements_reply enhancements) | |
2329 | { | |
2330 | struct drm_device *dev = psb_intel_sdvo->base.base.dev; | |
2331 | struct drm_connector *connector = &psb_intel_sdvo_connector->base.base; | |
2332 | uint16_t response, data_value[2]; | |
2333 | ||
2334 | /* when horizontal overscan is supported, Add the left/right property */ | |
2335 | if (enhancements.overscan_h) { | |
2336 | if (!psb_intel_sdvo_get_value(psb_intel_sdvo, | |
2337 | SDVO_CMD_GET_MAX_OVERSCAN_H, | |
2338 | &data_value, 4)) | |
2339 | return false; | |
2340 | ||
2341 | if (!psb_intel_sdvo_get_value(psb_intel_sdvo, | |
2342 | SDVO_CMD_GET_OVERSCAN_H, | |
2343 | &response, 2)) | |
2344 | return false; | |
2345 | ||
2346 | psb_intel_sdvo_connector->max_hscan = data_value[0]; | |
2347 | psb_intel_sdvo_connector->left_margin = data_value[0] - response; | |
2348 | psb_intel_sdvo_connector->right_margin = psb_intel_sdvo_connector->left_margin; | |
2349 | psb_intel_sdvo_connector->left = | |
d9bc3c02 | 2350 | drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]); |
5736995b PJ |
2351 | if (!psb_intel_sdvo_connector->left) |
2352 | return false; | |
2353 | ||
5736995b PJ |
2354 | drm_connector_attach_property(connector, |
2355 | psb_intel_sdvo_connector->left, | |
2356 | psb_intel_sdvo_connector->left_margin); | |
2357 | ||
2358 | psb_intel_sdvo_connector->right = | |
d9bc3c02 | 2359 | drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]); |
5736995b PJ |
2360 | if (!psb_intel_sdvo_connector->right) |
2361 | return false; | |
2362 | ||
5736995b PJ |
2363 | drm_connector_attach_property(connector, |
2364 | psb_intel_sdvo_connector->right, | |
2365 | psb_intel_sdvo_connector->right_margin); | |
2366 | DRM_DEBUG_KMS("h_overscan: max %d, " | |
2367 | "default %d, current %d\n", | |
2368 | data_value[0], data_value[1], response); | |
2369 | } | |
2370 | ||
2371 | if (enhancements.overscan_v) { | |
2372 | if (!psb_intel_sdvo_get_value(psb_intel_sdvo, | |
2373 | SDVO_CMD_GET_MAX_OVERSCAN_V, | |
2374 | &data_value, 4)) | |
2375 | return false; | |
2376 | ||
2377 | if (!psb_intel_sdvo_get_value(psb_intel_sdvo, | |
2378 | SDVO_CMD_GET_OVERSCAN_V, | |
2379 | &response, 2)) | |
2380 | return false; | |
2381 | ||
2382 | psb_intel_sdvo_connector->max_vscan = data_value[0]; | |
2383 | psb_intel_sdvo_connector->top_margin = data_value[0] - response; | |
2384 | psb_intel_sdvo_connector->bottom_margin = psb_intel_sdvo_connector->top_margin; | |
2385 | psb_intel_sdvo_connector->top = | |
d9bc3c02 | 2386 | drm_property_create_range(dev, 0, "top_margin", 0, data_value[0]); |
5736995b PJ |
2387 | if (!psb_intel_sdvo_connector->top) |
2388 | return false; | |
2389 | ||
5736995b PJ |
2390 | drm_connector_attach_property(connector, |
2391 | psb_intel_sdvo_connector->top, | |
2392 | psb_intel_sdvo_connector->top_margin); | |
2393 | ||
2394 | psb_intel_sdvo_connector->bottom = | |
d9bc3c02 | 2395 | drm_property_create_range(dev, 0, "bottom_margin", 0, data_value[0]); |
5736995b PJ |
2396 | if (!psb_intel_sdvo_connector->bottom) |
2397 | return false; | |
2398 | ||
5736995b PJ |
2399 | drm_connector_attach_property(connector, |
2400 | psb_intel_sdvo_connector->bottom, | |
2401 | psb_intel_sdvo_connector->bottom_margin); | |
2402 | DRM_DEBUG_KMS("v_overscan: max %d, " | |
2403 | "default %d, current %d\n", | |
2404 | data_value[0], data_value[1], response); | |
2405 | } | |
2406 | ||
2407 | ENHANCEMENT(hpos, HPOS); | |
2408 | ENHANCEMENT(vpos, VPOS); | |
2409 | ENHANCEMENT(saturation, SATURATION); | |
2410 | ENHANCEMENT(contrast, CONTRAST); | |
2411 | ENHANCEMENT(hue, HUE); | |
2412 | ENHANCEMENT(sharpness, SHARPNESS); | |
2413 | ENHANCEMENT(brightness, BRIGHTNESS); | |
2414 | ENHANCEMENT(flicker_filter, FLICKER_FILTER); | |
2415 | ENHANCEMENT(flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE); | |
2416 | ENHANCEMENT(flicker_filter_2d, FLICKER_FILTER_2D); | |
2417 | ENHANCEMENT(tv_chroma_filter, TV_CHROMA_FILTER); | |
2418 | ENHANCEMENT(tv_luma_filter, TV_LUMA_FILTER); | |
2419 | ||
2420 | if (enhancements.dot_crawl) { | |
2421 | if (!psb_intel_sdvo_get_value(psb_intel_sdvo, SDVO_CMD_GET_DOT_CRAWL, &response, 2)) | |
2422 | return false; | |
2423 | ||
2424 | psb_intel_sdvo_connector->max_dot_crawl = 1; | |
2425 | psb_intel_sdvo_connector->cur_dot_crawl = response & 0x1; | |
2426 | psb_intel_sdvo_connector->dot_crawl = | |
d9bc3c02 | 2427 | drm_property_create_range(dev, 0, "dot_crawl", 0, 1); |
5736995b PJ |
2428 | if (!psb_intel_sdvo_connector->dot_crawl) |
2429 | return false; | |
2430 | ||
5736995b PJ |
2431 | drm_connector_attach_property(connector, |
2432 | psb_intel_sdvo_connector->dot_crawl, | |
2433 | psb_intel_sdvo_connector->cur_dot_crawl); | |
2434 | DRM_DEBUG_KMS("dot crawl: current %d\n", response); | |
2435 | } | |
2436 | ||
2437 | return true; | |
2438 | } | |
2439 | ||
2440 | static bool | |
2441 | psb_intel_sdvo_create_enhance_property_lvds(struct psb_intel_sdvo *psb_intel_sdvo, | |
2442 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector, | |
2443 | struct psb_intel_sdvo_enhancements_reply enhancements) | |
2444 | { | |
2445 | struct drm_device *dev = psb_intel_sdvo->base.base.dev; | |
2446 | struct drm_connector *connector = &psb_intel_sdvo_connector->base.base; | |
2447 | uint16_t response, data_value[2]; | |
2448 | ||
2449 | ENHANCEMENT(brightness, BRIGHTNESS); | |
2450 | ||
2451 | return true; | |
2452 | } | |
2453 | #undef ENHANCEMENT | |
2454 | ||
2455 | static bool psb_intel_sdvo_create_enhance_property(struct psb_intel_sdvo *psb_intel_sdvo, | |
2456 | struct psb_intel_sdvo_connector *psb_intel_sdvo_connector) | |
2457 | { | |
2458 | union { | |
2459 | struct psb_intel_sdvo_enhancements_reply reply; | |
2460 | uint16_t response; | |
2461 | } enhancements; | |
2462 | ||
2463 | BUILD_BUG_ON(sizeof(enhancements) != 2); | |
2464 | ||
2465 | enhancements.response = 0; | |
2466 | psb_intel_sdvo_get_value(psb_intel_sdvo, | |
2467 | SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, | |
2468 | &enhancements, sizeof(enhancements)); | |
2469 | if (enhancements.response == 0) { | |
2470 | DRM_DEBUG_KMS("No enhancement is supported\n"); | |
2471 | return true; | |
89c78134 AC |
2472 | } |
2473 | ||
5736995b PJ |
2474 | if (IS_TV(psb_intel_sdvo_connector)) |
2475 | return psb_intel_sdvo_create_enhance_property_tv(psb_intel_sdvo, psb_intel_sdvo_connector, enhancements.reply); | |
2476 | else if(IS_LVDS(psb_intel_sdvo_connector)) | |
2477 | return psb_intel_sdvo_create_enhance_property_lvds(psb_intel_sdvo, psb_intel_sdvo_connector, enhancements.reply); | |
2478 | else | |
2479 | return true; | |
2480 | } | |
2481 | ||
2482 | static int psb_intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter, | |
2483 | struct i2c_msg *msgs, | |
2484 | int num) | |
2485 | { | |
2486 | struct psb_intel_sdvo *sdvo = adapter->algo_data; | |
2487 | ||
2488 | if (!psb_intel_sdvo_set_control_bus_switch(sdvo, sdvo->ddc_bus)) | |
2489 | return -EIO; | |
2490 | ||
2491 | return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num); | |
2492 | } | |
2493 | ||
2494 | static u32 psb_intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter) | |
2495 | { | |
2496 | struct psb_intel_sdvo *sdvo = adapter->algo_data; | |
2497 | return sdvo->i2c->algo->functionality(sdvo->i2c); | |
2498 | } | |
2499 | ||
2500 | static const struct i2c_algorithm psb_intel_sdvo_ddc_proxy = { | |
2501 | .master_xfer = psb_intel_sdvo_ddc_proxy_xfer, | |
2502 | .functionality = psb_intel_sdvo_ddc_proxy_func | |
2503 | }; | |
2504 | ||
2505 | static bool | |
2506 | psb_intel_sdvo_init_ddc_proxy(struct psb_intel_sdvo *sdvo, | |
2507 | struct drm_device *dev) | |
2508 | { | |
2509 | sdvo->ddc.owner = THIS_MODULE; | |
2510 | sdvo->ddc.class = I2C_CLASS_DDC; | |
2511 | snprintf(sdvo->ddc.name, I2C_NAME_SIZE, "SDVO DDC proxy"); | |
2512 | sdvo->ddc.dev.parent = &dev->pdev->dev; | |
2513 | sdvo->ddc.algo_data = sdvo; | |
2514 | sdvo->ddc.algo = &psb_intel_sdvo_ddc_proxy; | |
2515 | ||
2516 | return i2c_add_adapter(&sdvo->ddc) == 0; | |
2517 | } | |
2518 | ||
2519 | bool psb_intel_sdvo_init(struct drm_device *dev, int sdvo_reg) | |
2520 | { | |
2521 | struct drm_psb_private *dev_priv = dev->dev_private; | |
2522 | struct psb_intel_encoder *psb_intel_encoder; | |
2523 | struct psb_intel_sdvo *psb_intel_sdvo; | |
2524 | int i; | |
2525 | ||
2526 | psb_intel_sdvo = kzalloc(sizeof(struct psb_intel_sdvo), GFP_KERNEL); | |
2527 | if (!psb_intel_sdvo) | |
2528 | return false; | |
2529 | ||
2530 | psb_intel_sdvo->sdvo_reg = sdvo_reg; | |
2531 | psb_intel_sdvo->slave_addr = psb_intel_sdvo_get_slave_addr(dev, sdvo_reg) >> 1; | |
2532 | psb_intel_sdvo_select_i2c_bus(dev_priv, psb_intel_sdvo, sdvo_reg); | |
2533 | if (!psb_intel_sdvo_init_ddc_proxy(psb_intel_sdvo, dev)) { | |
2534 | kfree(psb_intel_sdvo); | |
2535 | return false; | |
2536 | } | |
89c78134 | 2537 | |
5736995b PJ |
2538 | /* encoder type will be decided later */ |
2539 | psb_intel_encoder = &psb_intel_sdvo->base; | |
2540 | psb_intel_encoder->type = INTEL_OUTPUT_SDVO; | |
2541 | drm_encoder_init(dev, &psb_intel_encoder->base, &psb_intel_sdvo_enc_funcs, 0); | |
89c78134 AC |
2542 | |
2543 | /* Read the regs to test if we can talk to the device */ | |
2544 | for (i = 0; i < 0x40; i++) { | |
5736995b PJ |
2545 | u8 byte; |
2546 | ||
2547 | if (!psb_intel_sdvo_read_byte(psb_intel_sdvo, i, &byte)) { | |
2548 | DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n", | |
2549 | IS_SDVOB(sdvo_reg) ? 'B' : 'C'); | |
2550 | goto err; | |
89c78134 AC |
2551 | } |
2552 | } | |
2553 | ||
5736995b PJ |
2554 | if (IS_SDVOB(sdvo_reg)) |
2555 | dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; | |
2556 | else | |
2557 | dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; | |
89c78134 | 2558 | |
5736995b | 2559 | drm_encoder_helper_add(&psb_intel_encoder->base, &psb_intel_sdvo_helper_funcs); |
89c78134 | 2560 | |
5736995b PJ |
2561 | /* In default case sdvo lvds is false */ |
2562 | if (!psb_intel_sdvo_get_capabilities(psb_intel_sdvo, &psb_intel_sdvo->caps)) | |
2563 | goto err; | |
89c78134 | 2564 | |
5736995b PJ |
2565 | if (psb_intel_sdvo_output_setup(psb_intel_sdvo, |
2566 | psb_intel_sdvo->caps.output_flags) != true) { | |
2567 | DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n", | |
2568 | IS_SDVOB(sdvo_reg) ? 'B' : 'C'); | |
2569 | goto err; | |
2570 | } | |
89c78134 | 2571 | |
5736995b | 2572 | psb_intel_sdvo_select_ddc_bus(dev_priv, psb_intel_sdvo, sdvo_reg); |
89c78134 | 2573 | |
5736995b PJ |
2574 | /* Set the input timing to the screen. Assume always input 0. */ |
2575 | if (!psb_intel_sdvo_set_target_input(psb_intel_sdvo)) | |
2576 | goto err; | |
2577 | ||
2578 | if (!psb_intel_sdvo_get_input_pixel_clock_range(psb_intel_sdvo, | |
2579 | &psb_intel_sdvo->pixel_clock_min, | |
2580 | &psb_intel_sdvo->pixel_clock_max)) | |
2581 | goto err; | |
2582 | ||
2583 | DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, " | |
2584 | "clock range %dMHz - %dMHz, " | |
2585 | "input 1: %c, input 2: %c, " | |
2586 | "output 1: %c, output 2: %c\n", | |
2587 | SDVO_NAME(psb_intel_sdvo), | |
2588 | psb_intel_sdvo->caps.vendor_id, psb_intel_sdvo->caps.device_id, | |
2589 | psb_intel_sdvo->caps.device_rev_id, | |
2590 | psb_intel_sdvo->pixel_clock_min / 1000, | |
2591 | psb_intel_sdvo->pixel_clock_max / 1000, | |
2592 | (psb_intel_sdvo->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N', | |
2593 | (psb_intel_sdvo->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N', | |
2594 | /* check currently supported outputs */ | |
2595 | psb_intel_sdvo->caps.output_flags & | |
2596 | (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N', | |
2597 | psb_intel_sdvo->caps.output_flags & | |
2598 | (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N'); | |
2599 | return true; | |
89c78134 | 2600 | |
5736995b PJ |
2601 | err: |
2602 | drm_encoder_cleanup(&psb_intel_encoder->base); | |
2603 | i2c_del_adapter(&psb_intel_sdvo->ddc); | |
2604 | kfree(psb_intel_sdvo); | |
89c78134 | 2605 | |
5736995b | 2606 | return false; |
89c78134 | 2607 | } |