blob: d1b95b70af6178990b052029926b6d78ef14956b [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2004 ATI Technologies Inc., Markham, Ontario
3 * Copyright 2007-8 Advanced Micro Devices, Inc.
4 * Copyright 2008 Red Hat Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 */
27#include "drmP.h"
28#include "radeon_drm.h"
29#include "radeon.h"
30#include "atom.h"
31
32#ifdef CONFIG_PPC_PMAC
33/* not sure which of these are needed */
34#include <asm/machdep.h>
35#include <asm/pmac_feature.h>
36#include <asm/prom.h>
37#include <asm/pci-bridge.h>
38#endif /* CONFIG_PPC_PMAC */
39
40/* from radeon_encoder.c */
41extern uint32_t
Alex Deucher5137ee92010-08-12 18:58:47 -040042radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
43 uint8_t dac);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020044extern void radeon_link_encoder_connector(struct drm_device *dev);
45
46/* from radeon_connector.c */
47extern void
48radeon_add_legacy_connector(struct drm_device *dev,
49 uint32_t connector_id,
50 uint32_t supported_device,
51 int connector_type,
Alex Deucherb75fad02009-11-05 13:16:01 -050052 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -050053 uint16_t connector_object_id,
54 struct radeon_hpd *hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020055
56/* from radeon_legacy_encoder.c */
57extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040058radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
Jerome Glisse771fe6b2009-06-05 14:42:42 +020059 uint32_t supported_device);
60
61/* old legacy ATI BIOS routines */
62
63/* COMBIOS table offsets */
64enum radeon_combios_table_offset {
65 /* absolute offset tables */
66 COMBIOS_ASIC_INIT_1_TABLE,
67 COMBIOS_BIOS_SUPPORT_TABLE,
68 COMBIOS_DAC_PROGRAMMING_TABLE,
69 COMBIOS_MAX_COLOR_DEPTH_TABLE,
70 COMBIOS_CRTC_INFO_TABLE,
71 COMBIOS_PLL_INFO_TABLE,
72 COMBIOS_TV_INFO_TABLE,
73 COMBIOS_DFP_INFO_TABLE,
74 COMBIOS_HW_CONFIG_INFO_TABLE,
75 COMBIOS_MULTIMEDIA_INFO_TABLE,
76 COMBIOS_TV_STD_PATCH_TABLE,
77 COMBIOS_LCD_INFO_TABLE,
78 COMBIOS_MOBILE_INFO_TABLE,
79 COMBIOS_PLL_INIT_TABLE,
80 COMBIOS_MEM_CONFIG_TABLE,
81 COMBIOS_SAVE_MASK_TABLE,
82 COMBIOS_HARDCODED_EDID_TABLE,
83 COMBIOS_ASIC_INIT_2_TABLE,
84 COMBIOS_CONNECTOR_INFO_TABLE,
85 COMBIOS_DYN_CLK_1_TABLE,
86 COMBIOS_RESERVED_MEM_TABLE,
87 COMBIOS_EXT_TMDS_INFO_TABLE,
88 COMBIOS_MEM_CLK_INFO_TABLE,
89 COMBIOS_EXT_DAC_INFO_TABLE,
90 COMBIOS_MISC_INFO_TABLE,
91 COMBIOS_CRT_INFO_TABLE,
92 COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE,
93 COMBIOS_COMPONENT_VIDEO_INFO_TABLE,
94 COMBIOS_FAN_SPEED_INFO_TABLE,
95 COMBIOS_OVERDRIVE_INFO_TABLE,
96 COMBIOS_OEM_INFO_TABLE,
97 COMBIOS_DYN_CLK_2_TABLE,
98 COMBIOS_POWER_CONNECTOR_INFO_TABLE,
99 COMBIOS_I2C_INFO_TABLE,
100 /* relative offset tables */
101 COMBIOS_ASIC_INIT_3_TABLE, /* offset from misc info */
102 COMBIOS_ASIC_INIT_4_TABLE, /* offset from misc info */
103 COMBIOS_DETECTED_MEM_TABLE, /* offset from misc info */
104 COMBIOS_ASIC_INIT_5_TABLE, /* offset from misc info */
105 COMBIOS_RAM_RESET_TABLE, /* offset from mem config */
106 COMBIOS_POWERPLAY_INFO_TABLE, /* offset from mobile info */
107 COMBIOS_GPIO_INFO_TABLE, /* offset from mobile info */
108 COMBIOS_LCD_DDC_INFO_TABLE, /* offset from mobile info */
109 COMBIOS_TMDS_POWER_TABLE, /* offset from mobile info */
110 COMBIOS_TMDS_POWER_ON_TABLE, /* offset from tmds power */
111 COMBIOS_TMDS_POWER_OFF_TABLE, /* offset from tmds power */
112};
113
114enum radeon_combios_ddc {
115 DDC_NONE_DETECTED,
116 DDC_MONID,
117 DDC_DVI,
118 DDC_VGA,
119 DDC_CRT2,
120 DDC_LCD,
121 DDC_GPIO,
122};
123
124enum radeon_combios_connector {
125 CONNECTOR_NONE_LEGACY,
126 CONNECTOR_PROPRIETARY_LEGACY,
127 CONNECTOR_CRT_LEGACY,
128 CONNECTOR_DVI_I_LEGACY,
129 CONNECTOR_DVI_D_LEGACY,
130 CONNECTOR_CTV_LEGACY,
131 CONNECTOR_STV_LEGACY,
132 CONNECTOR_UNSUPPORTED_LEGACY
133};
134
135const int legacy_connector_convert[] = {
136 DRM_MODE_CONNECTOR_Unknown,
137 DRM_MODE_CONNECTOR_DVID,
138 DRM_MODE_CONNECTOR_VGA,
139 DRM_MODE_CONNECTOR_DVII,
140 DRM_MODE_CONNECTOR_DVID,
141 DRM_MODE_CONNECTOR_Composite,
142 DRM_MODE_CONNECTOR_SVIDEO,
143 DRM_MODE_CONNECTOR_Unknown,
144};
145
146static uint16_t combios_get_table_offset(struct drm_device *dev,
147 enum radeon_combios_table_offset table)
148{
149 struct radeon_device *rdev = dev->dev_private;
150 int rev;
151 uint16_t offset = 0, check_offset;
152
Michel Dänzer03047cd2010-02-10 11:05:11 +0100153 if (!rdev->bios)
154 return 0;
155
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200156 switch (table) {
157 /* absolute offset tables */
158 case COMBIOS_ASIC_INIT_1_TABLE:
159 check_offset = RBIOS16(rdev->bios_header_start + 0xc);
160 if (check_offset)
161 offset = check_offset;
162 break;
163 case COMBIOS_BIOS_SUPPORT_TABLE:
164 check_offset = RBIOS16(rdev->bios_header_start + 0x14);
165 if (check_offset)
166 offset = check_offset;
167 break;
168 case COMBIOS_DAC_PROGRAMMING_TABLE:
169 check_offset = RBIOS16(rdev->bios_header_start + 0x2a);
170 if (check_offset)
171 offset = check_offset;
172 break;
173 case COMBIOS_MAX_COLOR_DEPTH_TABLE:
174 check_offset = RBIOS16(rdev->bios_header_start + 0x2c);
175 if (check_offset)
176 offset = check_offset;
177 break;
178 case COMBIOS_CRTC_INFO_TABLE:
179 check_offset = RBIOS16(rdev->bios_header_start + 0x2e);
180 if (check_offset)
181 offset = check_offset;
182 break;
183 case COMBIOS_PLL_INFO_TABLE:
184 check_offset = RBIOS16(rdev->bios_header_start + 0x30);
185 if (check_offset)
186 offset = check_offset;
187 break;
188 case COMBIOS_TV_INFO_TABLE:
189 check_offset = RBIOS16(rdev->bios_header_start + 0x32);
190 if (check_offset)
191 offset = check_offset;
192 break;
193 case COMBIOS_DFP_INFO_TABLE:
194 check_offset = RBIOS16(rdev->bios_header_start + 0x34);
195 if (check_offset)
196 offset = check_offset;
197 break;
198 case COMBIOS_HW_CONFIG_INFO_TABLE:
199 check_offset = RBIOS16(rdev->bios_header_start + 0x36);
200 if (check_offset)
201 offset = check_offset;
202 break;
203 case COMBIOS_MULTIMEDIA_INFO_TABLE:
204 check_offset = RBIOS16(rdev->bios_header_start + 0x38);
205 if (check_offset)
206 offset = check_offset;
207 break;
208 case COMBIOS_TV_STD_PATCH_TABLE:
209 check_offset = RBIOS16(rdev->bios_header_start + 0x3e);
210 if (check_offset)
211 offset = check_offset;
212 break;
213 case COMBIOS_LCD_INFO_TABLE:
214 check_offset = RBIOS16(rdev->bios_header_start + 0x40);
215 if (check_offset)
216 offset = check_offset;
217 break;
218 case COMBIOS_MOBILE_INFO_TABLE:
219 check_offset = RBIOS16(rdev->bios_header_start + 0x42);
220 if (check_offset)
221 offset = check_offset;
222 break;
223 case COMBIOS_PLL_INIT_TABLE:
224 check_offset = RBIOS16(rdev->bios_header_start + 0x46);
225 if (check_offset)
226 offset = check_offset;
227 break;
228 case COMBIOS_MEM_CONFIG_TABLE:
229 check_offset = RBIOS16(rdev->bios_header_start + 0x48);
230 if (check_offset)
231 offset = check_offset;
232 break;
233 case COMBIOS_SAVE_MASK_TABLE:
234 check_offset = RBIOS16(rdev->bios_header_start + 0x4a);
235 if (check_offset)
236 offset = check_offset;
237 break;
238 case COMBIOS_HARDCODED_EDID_TABLE:
239 check_offset = RBIOS16(rdev->bios_header_start + 0x4c);
240 if (check_offset)
241 offset = check_offset;
242 break;
243 case COMBIOS_ASIC_INIT_2_TABLE:
244 check_offset = RBIOS16(rdev->bios_header_start + 0x4e);
245 if (check_offset)
246 offset = check_offset;
247 break;
248 case COMBIOS_CONNECTOR_INFO_TABLE:
249 check_offset = RBIOS16(rdev->bios_header_start + 0x50);
250 if (check_offset)
251 offset = check_offset;
252 break;
253 case COMBIOS_DYN_CLK_1_TABLE:
254 check_offset = RBIOS16(rdev->bios_header_start + 0x52);
255 if (check_offset)
256 offset = check_offset;
257 break;
258 case COMBIOS_RESERVED_MEM_TABLE:
259 check_offset = RBIOS16(rdev->bios_header_start + 0x54);
260 if (check_offset)
261 offset = check_offset;
262 break;
263 case COMBIOS_EXT_TMDS_INFO_TABLE:
264 check_offset = RBIOS16(rdev->bios_header_start + 0x58);
265 if (check_offset)
266 offset = check_offset;
267 break;
268 case COMBIOS_MEM_CLK_INFO_TABLE:
269 check_offset = RBIOS16(rdev->bios_header_start + 0x5a);
270 if (check_offset)
271 offset = check_offset;
272 break;
273 case COMBIOS_EXT_DAC_INFO_TABLE:
274 check_offset = RBIOS16(rdev->bios_header_start + 0x5c);
275 if (check_offset)
276 offset = check_offset;
277 break;
278 case COMBIOS_MISC_INFO_TABLE:
279 check_offset = RBIOS16(rdev->bios_header_start + 0x5e);
280 if (check_offset)
281 offset = check_offset;
282 break;
283 case COMBIOS_CRT_INFO_TABLE:
284 check_offset = RBIOS16(rdev->bios_header_start + 0x60);
285 if (check_offset)
286 offset = check_offset;
287 break;
288 case COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE:
289 check_offset = RBIOS16(rdev->bios_header_start + 0x62);
290 if (check_offset)
291 offset = check_offset;
292 break;
293 case COMBIOS_COMPONENT_VIDEO_INFO_TABLE:
294 check_offset = RBIOS16(rdev->bios_header_start + 0x64);
295 if (check_offset)
296 offset = check_offset;
297 break;
298 case COMBIOS_FAN_SPEED_INFO_TABLE:
299 check_offset = RBIOS16(rdev->bios_header_start + 0x66);
300 if (check_offset)
301 offset = check_offset;
302 break;
303 case COMBIOS_OVERDRIVE_INFO_TABLE:
304 check_offset = RBIOS16(rdev->bios_header_start + 0x68);
305 if (check_offset)
306 offset = check_offset;
307 break;
308 case COMBIOS_OEM_INFO_TABLE:
309 check_offset = RBIOS16(rdev->bios_header_start + 0x6a);
310 if (check_offset)
311 offset = check_offset;
312 break;
313 case COMBIOS_DYN_CLK_2_TABLE:
314 check_offset = RBIOS16(rdev->bios_header_start + 0x6c);
315 if (check_offset)
316 offset = check_offset;
317 break;
318 case COMBIOS_POWER_CONNECTOR_INFO_TABLE:
319 check_offset = RBIOS16(rdev->bios_header_start + 0x6e);
320 if (check_offset)
321 offset = check_offset;
322 break;
323 case COMBIOS_I2C_INFO_TABLE:
324 check_offset = RBIOS16(rdev->bios_header_start + 0x70);
325 if (check_offset)
326 offset = check_offset;
327 break;
328 /* relative offset tables */
329 case COMBIOS_ASIC_INIT_3_TABLE: /* offset from misc info */
330 check_offset =
331 combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
332 if (check_offset) {
333 rev = RBIOS8(check_offset);
334 if (rev > 0) {
335 check_offset = RBIOS16(check_offset + 0x3);
336 if (check_offset)
337 offset = check_offset;
338 }
339 }
340 break;
341 case COMBIOS_ASIC_INIT_4_TABLE: /* offset from misc info */
342 check_offset =
343 combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
344 if (check_offset) {
345 rev = RBIOS8(check_offset);
346 if (rev > 0) {
347 check_offset = RBIOS16(check_offset + 0x5);
348 if (check_offset)
349 offset = check_offset;
350 }
351 }
352 break;
353 case COMBIOS_DETECTED_MEM_TABLE: /* offset from misc info */
354 check_offset =
355 combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
356 if (check_offset) {
357 rev = RBIOS8(check_offset);
358 if (rev > 0) {
359 check_offset = RBIOS16(check_offset + 0x7);
360 if (check_offset)
361 offset = check_offset;
362 }
363 }
364 break;
365 case COMBIOS_ASIC_INIT_5_TABLE: /* offset from misc info */
366 check_offset =
367 combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
368 if (check_offset) {
369 rev = RBIOS8(check_offset);
370 if (rev == 2) {
371 check_offset = RBIOS16(check_offset + 0x9);
372 if (check_offset)
373 offset = check_offset;
374 }
375 }
376 break;
377 case COMBIOS_RAM_RESET_TABLE: /* offset from mem config */
378 check_offset =
379 combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
380 if (check_offset) {
381 while (RBIOS8(check_offset++));
382 check_offset += 2;
383 if (check_offset)
384 offset = check_offset;
385 }
386 break;
387 case COMBIOS_POWERPLAY_INFO_TABLE: /* offset from mobile info */
388 check_offset =
389 combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
390 if (check_offset) {
391 check_offset = RBIOS16(check_offset + 0x11);
392 if (check_offset)
393 offset = check_offset;
394 }
395 break;
396 case COMBIOS_GPIO_INFO_TABLE: /* offset from mobile info */
397 check_offset =
398 combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
399 if (check_offset) {
400 check_offset = RBIOS16(check_offset + 0x13);
401 if (check_offset)
402 offset = check_offset;
403 }
404 break;
405 case COMBIOS_LCD_DDC_INFO_TABLE: /* offset from mobile info */
406 check_offset =
407 combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
408 if (check_offset) {
409 check_offset = RBIOS16(check_offset + 0x15);
410 if (check_offset)
411 offset = check_offset;
412 }
413 break;
414 case COMBIOS_TMDS_POWER_TABLE: /* offset from mobile info */
415 check_offset =
416 combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
417 if (check_offset) {
418 check_offset = RBIOS16(check_offset + 0x17);
419 if (check_offset)
420 offset = check_offset;
421 }
422 break;
423 case COMBIOS_TMDS_POWER_ON_TABLE: /* offset from tmds power */
424 check_offset =
425 combios_get_table_offset(dev, COMBIOS_TMDS_POWER_TABLE);
426 if (check_offset) {
427 check_offset = RBIOS16(check_offset + 0x2);
428 if (check_offset)
429 offset = check_offset;
430 }
431 break;
432 case COMBIOS_TMDS_POWER_OFF_TABLE: /* offset from tmds power */
433 check_offset =
434 combios_get_table_offset(dev, COMBIOS_TMDS_POWER_TABLE);
435 if (check_offset) {
436 check_offset = RBIOS16(check_offset + 0x4);
437 if (check_offset)
438 offset = check_offset;
439 }
440 break;
441 default:
442 break;
443 }
444
445 return offset;
446
447}
448
Alex Deucher3c537882010-02-05 04:21:19 -0500449bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev)
450{
Alex Deucherfafcf942011-03-23 08:10:10 +0000451 int edid_info, size;
Alex Deucher3c537882010-02-05 04:21:19 -0500452 struct edid *edid;
Adam Jackson7466f4c2010-03-29 21:43:23 +0000453 unsigned char *raw;
Alex Deucher3c537882010-02-05 04:21:19 -0500454 edid_info = combios_get_table_offset(rdev->ddev, COMBIOS_HARDCODED_EDID_TABLE);
455 if (!edid_info)
456 return false;
457
Adam Jackson7466f4c2010-03-29 21:43:23 +0000458 raw = rdev->bios + edid_info;
Alex Deucherfafcf942011-03-23 08:10:10 +0000459 size = EDID_LENGTH * (raw[0x7e] + 1);
460 edid = kmalloc(size, GFP_KERNEL);
Alex Deucher3c537882010-02-05 04:21:19 -0500461 if (edid == NULL)
462 return false;
463
Alex Deucherfafcf942011-03-23 08:10:10 +0000464 memcpy((unsigned char *)edid, raw, size);
Alex Deucher3c537882010-02-05 04:21:19 -0500465
466 if (!drm_edid_is_valid(edid)) {
467 kfree(edid);
468 return false;
469 }
470
471 rdev->mode_info.bios_hardcoded_edid = edid;
Alex Deucherfafcf942011-03-23 08:10:10 +0000472 rdev->mode_info.bios_hardcoded_edid_size = size;
Alex Deucher3c537882010-02-05 04:21:19 -0500473 return true;
474}
475
Alex Deucherc324acd2010-12-08 22:13:06 -0500476/* this is used for atom LCDs as well */
Alex Deucher3c537882010-02-05 04:21:19 -0500477struct edid *
Alex Deucherc324acd2010-12-08 22:13:06 -0500478radeon_bios_get_hardcoded_edid(struct radeon_device *rdev)
Alex Deucher3c537882010-02-05 04:21:19 -0500479{
Alex Deucherfafcf942011-03-23 08:10:10 +0000480 struct edid *edid;
481
482 if (rdev->mode_info.bios_hardcoded_edid) {
483 edid = kmalloc(rdev->mode_info.bios_hardcoded_edid_size, GFP_KERNEL);
484 if (edid) {
485 memcpy((unsigned char *)edid,
486 (unsigned char *)rdev->mode_info.bios_hardcoded_edid,
487 rdev->mode_info.bios_hardcoded_edid_size);
488 return edid;
489 }
490 }
Alex Deucher3c537882010-02-05 04:21:19 -0500491 return NULL;
492}
493
Alex Deucher6a93cb22009-11-23 17:39:28 -0500494static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
Alex Deucher179e8072010-08-05 21:21:17 -0400495 enum radeon_combios_ddc ddc,
496 u32 clk_mask,
497 u32 data_mask)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200498{
499 struct radeon_i2c_bus_rec i2c;
Alex Deucher179e8072010-08-05 21:21:17 -0400500 int ddc_line = 0;
501
502 /* ddc id = mask reg
503 * DDC_NONE_DETECTED = none
504 * DDC_DVI = RADEON_GPIO_DVI_DDC
505 * DDC_VGA = RADEON_GPIO_VGA_DDC
506 * DDC_LCD = RADEON_GPIOPAD_MASK
507 * DDC_GPIO = RADEON_MDGPIO_MASK
Alex Deucher508c8d62011-05-03 19:47:44 -0400508 * r1xx
Alex Deucher179e8072010-08-05 21:21:17 -0400509 * DDC_MONID = RADEON_GPIO_MONID
510 * DDC_CRT2 = RADEON_GPIO_CRT2_DDC
Alex Deucher508c8d62011-05-03 19:47:44 -0400511 * r200
Alex Deucher179e8072010-08-05 21:21:17 -0400512 * DDC_MONID = RADEON_GPIO_MONID
513 * DDC_CRT2 = RADEON_GPIO_DVI_DDC
Alex Deucher508c8d62011-05-03 19:47:44 -0400514 * r300/r350
515 * DDC_MONID = RADEON_GPIO_DVI_DDC
516 * DDC_CRT2 = RADEON_GPIO_DVI_DDC
517 * rv2xx/rv3xx
518 * DDC_MONID = RADEON_GPIO_MONID
519 * DDC_CRT2 = RADEON_GPIO_MONID
Alex Deucher179e8072010-08-05 21:21:17 -0400520 * rs3xx/rs4xx
521 * DDC_MONID = RADEON_GPIOPAD_MASK
522 * DDC_CRT2 = RADEON_GPIO_MONID
523 */
524 switch (ddc) {
525 case DDC_NONE_DETECTED:
526 default:
527 ddc_line = 0;
528 break;
529 case DDC_DVI:
530 ddc_line = RADEON_GPIO_DVI_DDC;
531 break;
532 case DDC_VGA:
533 ddc_line = RADEON_GPIO_VGA_DDC;
534 break;
535 case DDC_LCD:
536 ddc_line = RADEON_GPIOPAD_MASK;
537 break;
538 case DDC_GPIO:
539 ddc_line = RADEON_MDGPIO_MASK;
540 break;
541 case DDC_MONID:
542 if (rdev->family == CHIP_RS300 ||
543 rdev->family == CHIP_RS400 ||
544 rdev->family == CHIP_RS480)
545 ddc_line = RADEON_GPIOPAD_MASK;
Alex Deucher508c8d62011-05-03 19:47:44 -0400546 else if (rdev->family == CHIP_R300 ||
Alex Deucher776f2b72011-05-04 15:14:44 +0000547 rdev->family == CHIP_R350) {
Alex Deucher508c8d62011-05-03 19:47:44 -0400548 ddc_line = RADEON_GPIO_DVI_DDC;
Alex Deucher776f2b72011-05-04 15:14:44 +0000549 ddc = DDC_DVI;
550 } else
Alex Deucher179e8072010-08-05 21:21:17 -0400551 ddc_line = RADEON_GPIO_MONID;
552 break;
553 case DDC_CRT2:
Alex Deucher508c8d62011-05-03 19:47:44 -0400554 if (rdev->family == CHIP_R200 ||
555 rdev->family == CHIP_R300 ||
Alex Deucher776f2b72011-05-04 15:14:44 +0000556 rdev->family == CHIP_R350) {
Alex Deucher179e8072010-08-05 21:21:17 -0400557 ddc_line = RADEON_GPIO_DVI_DDC;
Alex Deucher776f2b72011-05-04 15:14:44 +0000558 ddc = DDC_DVI;
559 } else if (rdev->family == CHIP_RS300 ||
560 rdev->family == CHIP_RS400 ||
561 rdev->family == CHIP_RS480)
Alex Deucher508c8d62011-05-03 19:47:44 -0400562 ddc_line = RADEON_GPIO_MONID;
Alex Deucher776f2b72011-05-04 15:14:44 +0000563 else if (rdev->family >= CHIP_RV350) {
564 ddc_line = RADEON_GPIO_MONID;
565 ddc = DDC_MONID;
566 } else
Alex Deucher179e8072010-08-05 21:21:17 -0400567 ddc_line = RADEON_GPIO_CRT2_DDC;
568 break;
569 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200570
Alex Deucher6a93cb22009-11-23 17:39:28 -0500571 if (ddc_line == RADEON_GPIOPAD_MASK) {
572 i2c.mask_clk_reg = RADEON_GPIOPAD_MASK;
573 i2c.mask_data_reg = RADEON_GPIOPAD_MASK;
574 i2c.a_clk_reg = RADEON_GPIOPAD_A;
575 i2c.a_data_reg = RADEON_GPIOPAD_A;
576 i2c.en_clk_reg = RADEON_GPIOPAD_EN;
577 i2c.en_data_reg = RADEON_GPIOPAD_EN;
578 i2c.y_clk_reg = RADEON_GPIOPAD_Y;
579 i2c.y_data_reg = RADEON_GPIOPAD_Y;
580 } else if (ddc_line == RADEON_MDGPIO_MASK) {
581 i2c.mask_clk_reg = RADEON_MDGPIO_MASK;
582 i2c.mask_data_reg = RADEON_MDGPIO_MASK;
583 i2c.a_clk_reg = RADEON_MDGPIO_A;
584 i2c.a_data_reg = RADEON_MDGPIO_A;
585 i2c.en_clk_reg = RADEON_MDGPIO_EN;
586 i2c.en_data_reg = RADEON_MDGPIO_EN;
587 i2c.y_clk_reg = RADEON_MDGPIO_Y;
588 i2c.y_data_reg = RADEON_MDGPIO_Y;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200589 } else {
590 i2c.mask_clk_reg = ddc_line;
591 i2c.mask_data_reg = ddc_line;
592 i2c.a_clk_reg = ddc_line;
593 i2c.a_data_reg = ddc_line;
Alex Deucher9b9fe722009-11-10 15:59:44 -0500594 i2c.en_clk_reg = ddc_line;
595 i2c.en_data_reg = ddc_line;
596 i2c.y_clk_reg = ddc_line;
597 i2c.y_data_reg = ddc_line;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200598 }
599
Alex Deucher179e8072010-08-05 21:21:17 -0400600 if (clk_mask && data_mask) {
Alex Deucherbe663052010-11-18 17:18:08 -0500601 /* system specific masks */
Alex Deucher179e8072010-08-05 21:21:17 -0400602 i2c.mask_clk_mask = clk_mask;
603 i2c.mask_data_mask = data_mask;
604 i2c.a_clk_mask = clk_mask;
605 i2c.a_data_mask = data_mask;
606 i2c.en_clk_mask = clk_mask;
607 i2c.en_data_mask = data_mask;
608 i2c.y_clk_mask = clk_mask;
609 i2c.y_data_mask = data_mask;
Alex Deucherbe663052010-11-18 17:18:08 -0500610 } else if ((ddc_line == RADEON_GPIOPAD_MASK) ||
611 (ddc_line == RADEON_MDGPIO_MASK)) {
612 /* default gpiopad masks */
613 i2c.mask_clk_mask = (0x20 << 8);
614 i2c.mask_data_mask = 0x80;
615 i2c.a_clk_mask = (0x20 << 8);
616 i2c.a_data_mask = 0x80;
617 i2c.en_clk_mask = (0x20 << 8);
618 i2c.en_data_mask = 0x80;
619 i2c.y_clk_mask = (0x20 << 8);
620 i2c.y_data_mask = 0x80;
Alex Deucher179e8072010-08-05 21:21:17 -0400621 } else {
Alex Deucherbe663052010-11-18 17:18:08 -0500622 /* default masks for ddc pads */
Alex Deucher179e8072010-08-05 21:21:17 -0400623 i2c.mask_clk_mask = RADEON_GPIO_EN_1;
624 i2c.mask_data_mask = RADEON_GPIO_EN_0;
625 i2c.a_clk_mask = RADEON_GPIO_A_1;
626 i2c.a_data_mask = RADEON_GPIO_A_0;
627 i2c.en_clk_mask = RADEON_GPIO_EN_1;
628 i2c.en_data_mask = RADEON_GPIO_EN_0;
629 i2c.y_clk_mask = RADEON_GPIO_Y_1;
630 i2c.y_data_mask = RADEON_GPIO_Y_0;
631 }
632
Alex Deucher40bacf12009-12-23 03:23:21 -0500633 switch (rdev->family) {
634 case CHIP_R100:
635 case CHIP_RV100:
636 case CHIP_RS100:
637 case CHIP_RV200:
638 case CHIP_RS200:
639 case CHIP_RS300:
640 switch (ddc_line) {
641 case RADEON_GPIO_DVI_DDC:
Alex Deucherb28ea412010-03-12 13:30:49 -0500642 i2c.hw_capable = true;
Alex Deucher40bacf12009-12-23 03:23:21 -0500643 break;
644 default:
645 i2c.hw_capable = false;
646 break;
647 }
648 break;
649 case CHIP_R200:
650 switch (ddc_line) {
651 case RADEON_GPIO_DVI_DDC:
652 case RADEON_GPIO_MONID:
653 i2c.hw_capable = true;
654 break;
655 default:
656 i2c.hw_capable = false;
657 break;
658 }
659 break;
660 case CHIP_RV250:
661 case CHIP_RV280:
662 switch (ddc_line) {
663 case RADEON_GPIO_VGA_DDC:
664 case RADEON_GPIO_DVI_DDC:
665 case RADEON_GPIO_CRT2_DDC:
666 i2c.hw_capable = true;
667 break;
668 default:
669 i2c.hw_capable = false;
670 break;
671 }
672 break;
673 case CHIP_R300:
674 case CHIP_R350:
675 switch (ddc_line) {
676 case RADEON_GPIO_VGA_DDC:
677 case RADEON_GPIO_DVI_DDC:
678 i2c.hw_capable = true;
679 break;
680 default:
681 i2c.hw_capable = false;
682 break;
683 }
684 break;
685 case CHIP_RV350:
686 case CHIP_RV380:
687 case CHIP_RS400:
688 case CHIP_RS480:
Alex Deucher6a93cb22009-11-23 17:39:28 -0500689 switch (ddc_line) {
690 case RADEON_GPIO_VGA_DDC:
691 case RADEON_GPIO_DVI_DDC:
692 i2c.hw_capable = true;
693 break;
694 case RADEON_GPIO_MONID:
695 /* hw i2c on RADEON_GPIO_MONID doesn't seem to work
696 * reliably on some pre-r4xx hardware; not sure why.
697 */
698 i2c.hw_capable = false;
699 break;
700 default:
701 i2c.hw_capable = false;
702 break;
703 }
Alex Deucher40bacf12009-12-23 03:23:21 -0500704 break;
705 default:
706 i2c.hw_capable = false;
707 break;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500708 }
709 i2c.mm_i2c = false;
Alex Deucherf376b942010-08-05 21:21:16 -0400710
Alex Deucher179e8072010-08-05 21:21:17 -0400711 i2c.i2c_id = ddc;
Alex Deucher8e36ed02010-05-18 19:26:47 -0400712 i2c.hpd = RADEON_HPD_NONE;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500713
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200714 if (ddc_line)
715 i2c.valid = true;
716 else
717 i2c.valid = false;
718
719 return i2c;
720}
721
Alex Deucherf376b942010-08-05 21:21:16 -0400722void radeon_combios_i2c_init(struct radeon_device *rdev)
723{
724 struct drm_device *dev = rdev->ddev;
725 struct radeon_i2c_bus_rec i2c;
726
Alex Deucher508c8d62011-05-03 19:47:44 -0400727 /* actual hw pads
728 * r1xx/rs2xx/rs3xx
729 * 0x60, 0x64, 0x68, 0x6c, gpiopads, mm
730 * r200
731 * 0x60, 0x64, 0x68, mm
732 * r300/r350
733 * 0x60, 0x64, mm
734 * rv2xx/rv3xx/rs4xx
735 * 0x60, 0x64, 0x68, gpiopads, mm
736 */
Alex Deucherf376b942010-08-05 21:21:16 -0400737
Alex Deucher508c8d62011-05-03 19:47:44 -0400738 /* 0x60 */
Alex Deucher179e8072010-08-05 21:21:17 -0400739 i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
740 rdev->i2c_bus[0] = radeon_i2c_create(dev, &i2c, "DVI_DDC");
Alex Deucher508c8d62011-05-03 19:47:44 -0400741 /* 0x64 */
Alex Deucher179e8072010-08-05 21:21:17 -0400742 i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
743 rdev->i2c_bus[1] = radeon_i2c_create(dev, &i2c, "VGA_DDC");
Alex Deucherf376b942010-08-05 21:21:16 -0400744
Alex Deucher508c8d62011-05-03 19:47:44 -0400745 /* mm i2c */
Alex Deucherf376b942010-08-05 21:21:16 -0400746 i2c.valid = true;
747 i2c.hw_capable = true;
748 i2c.mm_i2c = true;
Alex Deucher179e8072010-08-05 21:21:17 -0400749 i2c.i2c_id = 0xa0;
750 rdev->i2c_bus[2] = radeon_i2c_create(dev, &i2c, "MM_I2C");
751
Alex Deucher508c8d62011-05-03 19:47:44 -0400752 if (rdev->family == CHIP_R300 ||
753 rdev->family == CHIP_R350) {
754 /* only 2 sw i2c pads */
755 } else if (rdev->family == CHIP_RS300 ||
756 rdev->family == CHIP_RS400 ||
757 rdev->family == CHIP_RS480) {
Alex Deucher179e8072010-08-05 21:21:17 -0400758 u16 offset;
759 u8 id, blocks, clk, data;
760 int i;
761
Alex Deucher508c8d62011-05-03 19:47:44 -0400762 /* 0x68 */
Alex Deucher179e8072010-08-05 21:21:17 -0400763 i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
764 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
765
766 offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE);
767 if (offset) {
768 blocks = RBIOS8(offset + 2);
769 for (i = 0; i < blocks; i++) {
770 id = RBIOS8(offset + 3 + (i * 5) + 0);
771 if (id == 136) {
772 clk = RBIOS8(offset + 3 + (i * 5) + 3);
773 data = RBIOS8(offset + 3 + (i * 5) + 4);
Alex Deucher508c8d62011-05-03 19:47:44 -0400774 /* gpiopad */
Alex Deucher179e8072010-08-05 21:21:17 -0400775 i2c = combios_setup_i2c_bus(rdev, DDC_MONID,
Alex Deucher791cfe22010-11-21 10:58:05 -0500776 (1 << clk), (1 << data));
Alex Deucher179e8072010-08-05 21:21:17 -0400777 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "GPIOPAD_MASK");
778 break;
779 }
780 }
781 }
Alex Deucher508c8d62011-05-03 19:47:44 -0400782 } else if (rdev->family >= CHIP_R200) {
783 /* 0x68 */
Alex Deucher179e8072010-08-05 21:21:17 -0400784 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
785 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
786 } else {
Alex Deucher508c8d62011-05-03 19:47:44 -0400787 /* 0x68 */
Alex Deucher179e8072010-08-05 21:21:17 -0400788 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
789 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
Alex Deucher508c8d62011-05-03 19:47:44 -0400790 /* 0x6c */
Alex Deucher179e8072010-08-05 21:21:17 -0400791 i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
792 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "CRT2_DDC");
793 }
Alex Deucherf376b942010-08-05 21:21:16 -0400794}
795
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200796bool radeon_combios_get_clock_info(struct drm_device *dev)
797{
798 struct radeon_device *rdev = dev->dev_private;
799 uint16_t pll_info;
800 struct radeon_pll *p1pll = &rdev->clock.p1pll;
801 struct radeon_pll *p2pll = &rdev->clock.p2pll;
802 struct radeon_pll *spll = &rdev->clock.spll;
803 struct radeon_pll *mpll = &rdev->clock.mpll;
804 int8_t rev;
805 uint16_t sclk, mclk;
806
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200807 pll_info = combios_get_table_offset(dev, COMBIOS_PLL_INFO_TABLE);
808 if (pll_info) {
809 rev = RBIOS8(pll_info);
810
811 /* pixel clocks */
812 p1pll->reference_freq = RBIOS16(pll_info + 0xe);
813 p1pll->reference_div = RBIOS16(pll_info + 0x10);
814 p1pll->pll_out_min = RBIOS32(pll_info + 0x12);
815 p1pll->pll_out_max = RBIOS32(pll_info + 0x16);
Alex Deucher86cb2bb2010-03-08 12:55:16 -0500816 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
817 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200818
819 if (rev > 9) {
820 p1pll->pll_in_min = RBIOS32(pll_info + 0x36);
821 p1pll->pll_in_max = RBIOS32(pll_info + 0x3a);
822 } else {
823 p1pll->pll_in_min = 40;
824 p1pll->pll_in_max = 500;
825 }
826 *p2pll = *p1pll;
827
828 /* system clock */
829 spll->reference_freq = RBIOS16(pll_info + 0x1a);
830 spll->reference_div = RBIOS16(pll_info + 0x1c);
831 spll->pll_out_min = RBIOS32(pll_info + 0x1e);
832 spll->pll_out_max = RBIOS32(pll_info + 0x22);
833
834 if (rev > 10) {
835 spll->pll_in_min = RBIOS32(pll_info + 0x48);
836 spll->pll_in_max = RBIOS32(pll_info + 0x4c);
837 } else {
838 /* ??? */
839 spll->pll_in_min = 40;
840 spll->pll_in_max = 500;
841 }
842
843 /* memory clock */
844 mpll->reference_freq = RBIOS16(pll_info + 0x26);
845 mpll->reference_div = RBIOS16(pll_info + 0x28);
846 mpll->pll_out_min = RBIOS32(pll_info + 0x2a);
847 mpll->pll_out_max = RBIOS32(pll_info + 0x2e);
848
849 if (rev > 10) {
850 mpll->pll_in_min = RBIOS32(pll_info + 0x5a);
851 mpll->pll_in_max = RBIOS32(pll_info + 0x5e);
852 } else {
853 /* ??? */
854 mpll->pll_in_min = 40;
855 mpll->pll_in_max = 500;
856 }
857
858 /* default sclk/mclk */
859 sclk = RBIOS16(pll_info + 0xa);
860 mclk = RBIOS16(pll_info + 0x8);
861 if (sclk == 0)
862 sclk = 200 * 100;
863 if (mclk == 0)
864 mclk = 200 * 100;
865
866 rdev->clock.default_sclk = sclk;
867 rdev->clock.default_mclk = mclk;
868
Alex Deucherb20f9be2011-06-08 13:01:11 -0400869 if (RBIOS32(pll_info + 0x16))
870 rdev->clock.max_pixel_clock = RBIOS32(pll_info + 0x16);
871 else
872 rdev->clock.max_pixel_clock = 35000; /* might need something asic specific */
873
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200874 return true;
875 }
876 return false;
877}
878
Alex Deucher06b64762010-01-05 11:27:29 -0500879bool radeon_combios_sideport_present(struct radeon_device *rdev)
880{
881 struct drm_device *dev = rdev->ddev;
882 u16 igp_info;
883
Alex Deucher4c70b2e2010-08-02 19:39:15 -0400884 /* sideport is AMD only */
885 if (rdev->family == CHIP_RS400)
886 return false;
887
Alex Deucher06b64762010-01-05 11:27:29 -0500888 igp_info = combios_get_table_offset(dev, COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE);
889
890 if (igp_info) {
891 if (RBIOS16(igp_info + 0x4))
892 return true;
893 }
894 return false;
895}
896
Alex Deucher246263c2009-12-29 12:09:17 -0500897static const uint32_t default_primarydac_adj[CHIP_LAST] = {
898 0x00000808, /* r100 */
899 0x00000808, /* rv100 */
900 0x00000808, /* rs100 */
901 0x00000808, /* rv200 */
902 0x00000808, /* rs200 */
903 0x00000808, /* r200 */
904 0x00000808, /* rv250 */
905 0x00000000, /* rs300 */
906 0x00000808, /* rv280 */
907 0x00000808, /* r300 */
908 0x00000808, /* r350 */
909 0x00000808, /* rv350 */
910 0x00000808, /* rv380 */
911 0x00000808, /* r420 */
912 0x00000808, /* r423 */
913 0x00000808, /* rv410 */
914 0x00000000, /* rs400 */
915 0x00000000, /* rs480 */
916};
917
918static void radeon_legacy_get_primary_dac_info_from_table(struct radeon_device *rdev,
919 struct radeon_encoder_primary_dac *p_dac)
920{
921 p_dac->ps2_pdac_adj = default_primarydac_adj[rdev->family];
922 return;
923}
924
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200925struct radeon_encoder_primary_dac *radeon_combios_get_primary_dac_info(struct
926 radeon_encoder
927 *encoder)
928{
929 struct drm_device *dev = encoder->base.dev;
930 struct radeon_device *rdev = dev->dev_private;
931 uint16_t dac_info;
932 uint8_t rev, bg, dac;
933 struct radeon_encoder_primary_dac *p_dac = NULL;
Alex Deucher246263c2009-12-29 12:09:17 -0500934 int found = 0;
935
936 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac),
937 GFP_KERNEL);
938
939 if (!p_dac)
940 return NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200941
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200942 /* check CRT table */
943 dac_info = combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
944 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200945 rev = RBIOS8(dac_info) & 0x3;
946 if (rev < 2) {
947 bg = RBIOS8(dac_info + 0x2) & 0xf;
948 dac = (RBIOS8(dac_info + 0x2) >> 4) & 0xf;
949 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
950 } else {
951 bg = RBIOS8(dac_info + 0x2) & 0xf;
952 dac = RBIOS8(dac_info + 0x3) & 0xf;
953 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
954 }
Alex Deucher3a89b4a2010-04-06 12:35:26 -0400955 /* if the values are all zeros, use the table */
956 if (p_dac->ps2_pdac_adj)
957 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200958 }
959
Alex Deucher246263c2009-12-29 12:09:17 -0500960 if (!found) /* fallback to defaults */
961 radeon_legacy_get_primary_dac_info_from_table(rdev, p_dac);
962
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200963 return p_dac;
964}
965
Alex Deucherd79766f2009-12-17 19:00:29 -0500966enum radeon_tv_std
967radeon_combios_get_tv_info(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200968{
Alex Deucherd79766f2009-12-17 19:00:29 -0500969 struct drm_device *dev = rdev->ddev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200970 uint16_t tv_info;
971 enum radeon_tv_std tv_std = TV_STD_NTSC;
972
973 tv_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
974 if (tv_info) {
975 if (RBIOS8(tv_info + 6) == 'T') {
976 switch (RBIOS8(tv_info + 7) & 0xf) {
977 case 1:
978 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -0400979 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200980 break;
981 case 2:
982 tv_std = TV_STD_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -0400983 DRM_DEBUG_KMS("Default TV standard: PAL\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200984 break;
985 case 3:
986 tv_std = TV_STD_PAL_M;
Alex Deucher40f76d82010-10-07 22:38:42 -0400987 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200988 break;
989 case 4:
990 tv_std = TV_STD_PAL_60;
Alex Deucher40f76d82010-10-07 22:38:42 -0400991 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200992 break;
993 case 5:
994 tv_std = TV_STD_NTSC_J;
Alex Deucher40f76d82010-10-07 22:38:42 -0400995 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200996 break;
997 case 6:
998 tv_std = TV_STD_SCART_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -0400999 DRM_DEBUG_KMS("Default TV standard: SCART-PAL\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001000 break;
1001 default:
1002 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001003 DRM_DEBUG_KMS
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001004 ("Unknown TV standard; defaulting to NTSC\n");
1005 break;
1006 }
1007
1008 switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) {
1009 case 0:
Alex Deucher40f76d82010-10-07 22:38:42 -04001010 DRM_DEBUG_KMS("29.498928713 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001011 break;
1012 case 1:
Alex Deucher40f76d82010-10-07 22:38:42 -04001013 DRM_DEBUG_KMS("28.636360000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001014 break;
1015 case 2:
Alex Deucher40f76d82010-10-07 22:38:42 -04001016 DRM_DEBUG_KMS("14.318180000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001017 break;
1018 case 3:
Alex Deucher40f76d82010-10-07 22:38:42 -04001019 DRM_DEBUG_KMS("27.000000000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001020 break;
1021 default:
1022 break;
1023 }
1024 }
1025 }
1026 return tv_std;
1027}
1028
1029static const uint32_t default_tvdac_adj[CHIP_LAST] = {
1030 0x00000000, /* r100 */
1031 0x00280000, /* rv100 */
1032 0x00000000, /* rs100 */
1033 0x00880000, /* rv200 */
1034 0x00000000, /* rs200 */
1035 0x00000000, /* r200 */
1036 0x00770000, /* rv250 */
1037 0x00290000, /* rs300 */
1038 0x00560000, /* rv280 */
1039 0x00780000, /* r300 */
1040 0x00770000, /* r350 */
1041 0x00780000, /* rv350 */
1042 0x00780000, /* rv380 */
1043 0x01080000, /* r420 */
1044 0x01080000, /* r423 */
1045 0x01080000, /* rv410 */
1046 0x00780000, /* rs400 */
1047 0x00780000, /* rs480 */
1048};
1049
Dave Airlie6a719e02009-08-17 10:19:51 +10001050static void radeon_legacy_get_tv_dac_info_from_table(struct radeon_device *rdev,
1051 struct radeon_encoder_tv_dac *tv_dac)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001052{
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001053 tv_dac->ps2_tvdac_adj = default_tvdac_adj[rdev->family];
1054 if ((rdev->flags & RADEON_IS_MOBILITY) && (rdev->family == CHIP_RV250))
1055 tv_dac->ps2_tvdac_adj = 0x00880000;
1056 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1057 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Dave Airlie6a719e02009-08-17 10:19:51 +10001058 return;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001059}
1060
1061struct radeon_encoder_tv_dac *radeon_combios_get_tv_dac_info(struct
1062 radeon_encoder
1063 *encoder)
1064{
1065 struct drm_device *dev = encoder->base.dev;
1066 struct radeon_device *rdev = dev->dev_private;
1067 uint16_t dac_info;
1068 uint8_t rev, bg, dac;
1069 struct radeon_encoder_tv_dac *tv_dac = NULL;
Dave Airlie6a719e02009-08-17 10:19:51 +10001070 int found = 0;
1071
1072 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1073 if (!tv_dac)
1074 return NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001075
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001076 /* first check TV table */
1077 dac_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
1078 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001079 rev = RBIOS8(dac_info + 0x3);
1080 if (rev > 4) {
1081 bg = RBIOS8(dac_info + 0xc) & 0xf;
1082 dac = RBIOS8(dac_info + 0xd) & 0xf;
1083 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1084
1085 bg = RBIOS8(dac_info + 0xe) & 0xf;
1086 dac = RBIOS8(dac_info + 0xf) & 0xf;
1087 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1088
1089 bg = RBIOS8(dac_info + 0x10) & 0xf;
1090 dac = RBIOS8(dac_info + 0x11) & 0xf;
1091 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001092 /* if the values are all zeros, use the table */
1093 if (tv_dac->ps2_tvdac_adj)
1094 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001095 } else if (rev > 1) {
1096 bg = RBIOS8(dac_info + 0xc) & 0xf;
1097 dac = (RBIOS8(dac_info + 0xc) >> 4) & 0xf;
1098 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1099
1100 bg = RBIOS8(dac_info + 0xd) & 0xf;
1101 dac = (RBIOS8(dac_info + 0xd) >> 4) & 0xf;
1102 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1103
1104 bg = RBIOS8(dac_info + 0xe) & 0xf;
1105 dac = (RBIOS8(dac_info + 0xe) >> 4) & 0xf;
1106 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001107 /* if the values are all zeros, use the table */
1108 if (tv_dac->ps2_tvdac_adj)
1109 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001110 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001111 tv_dac->tv_std = radeon_combios_get_tv_info(rdev);
Dave Airlie6a719e02009-08-17 10:19:51 +10001112 }
1113 if (!found) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001114 /* then check CRT table */
1115 dac_info =
1116 combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
1117 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001118 rev = RBIOS8(dac_info) & 0x3;
1119 if (rev < 2) {
1120 bg = RBIOS8(dac_info + 0x3) & 0xf;
1121 dac = (RBIOS8(dac_info + 0x3) >> 4) & 0xf;
1122 tv_dac->ps2_tvdac_adj =
1123 (bg << 16) | (dac << 20);
1124 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1125 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001126 /* if the values are all zeros, use the table */
1127 if (tv_dac->ps2_tvdac_adj)
1128 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001129 } else {
1130 bg = RBIOS8(dac_info + 0x4) & 0xf;
1131 dac = RBIOS8(dac_info + 0x5) & 0xf;
1132 tv_dac->ps2_tvdac_adj =
1133 (bg << 16) | (dac << 20);
1134 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1135 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001136 /* if the values are all zeros, use the table */
1137 if (tv_dac->ps2_tvdac_adj)
1138 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001139 }
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001140 } else {
1141 DRM_INFO("No TV DAC info found in BIOS\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001142 }
1143 }
1144
Dave Airlie6a719e02009-08-17 10:19:51 +10001145 if (!found) /* fallback to defaults */
1146 radeon_legacy_get_tv_dac_info_from_table(rdev, tv_dac);
1147
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001148 return tv_dac;
1149}
1150
1151static struct radeon_encoder_lvds *radeon_legacy_get_lvds_info_from_regs(struct
1152 radeon_device
1153 *rdev)
1154{
1155 struct radeon_encoder_lvds *lvds = NULL;
1156 uint32_t fp_vert_stretch, fp_horz_stretch;
1157 uint32_t ppll_div_sel, ppll_val;
Michel Dänzer8b5c7442009-06-17 18:28:38 +02001158 uint32_t lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001159
1160 lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
1161
1162 if (!lvds)
1163 return NULL;
1164
1165 fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH);
1166 fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH);
1167
Michel Dänzer8b5c7442009-06-17 18:28:38 +02001168 /* These should be fail-safe defaults, fingers crossed */
1169 lvds->panel_pwr_delay = 200;
1170 lvds->panel_vcc_delay = 2000;
1171
1172 lvds->lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
1173 lvds->panel_digon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) & 0xf;
1174 lvds->panel_blon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY2_SHIFT) & 0xf;
1175
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001176 if (fp_vert_stretch & RADEON_VERT_STRETCH_ENABLE)
Alex Deucherde2103e2009-10-09 15:14:30 -04001177 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001178 ((fp_vert_stretch & RADEON_VERT_PANEL_SIZE) >>
1179 RADEON_VERT_PANEL_SHIFT) + 1;
1180 else
Alex Deucherde2103e2009-10-09 15:14:30 -04001181 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001182 (RREG32(RADEON_CRTC_V_TOTAL_DISP) >> 16) + 1;
1183
1184 if (fp_horz_stretch & RADEON_HORZ_STRETCH_ENABLE)
Alex Deucherde2103e2009-10-09 15:14:30 -04001185 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001186 (((fp_horz_stretch & RADEON_HORZ_PANEL_SIZE) >>
1187 RADEON_HORZ_PANEL_SHIFT) + 1) * 8;
1188 else
Alex Deucherde2103e2009-10-09 15:14:30 -04001189 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001190 ((RREG32(RADEON_CRTC_H_TOTAL_DISP) >> 16) + 1) * 8;
1191
Alex Deucherde2103e2009-10-09 15:14:30 -04001192 if ((lvds->native_mode.hdisplay < 640) ||
1193 (lvds->native_mode.vdisplay < 480)) {
1194 lvds->native_mode.hdisplay = 640;
1195 lvds->native_mode.vdisplay = 480;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001196 }
1197
1198 ppll_div_sel = RREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3;
1199 ppll_val = RREG32_PLL(RADEON_PPLL_DIV_0 + ppll_div_sel);
1200 if ((ppll_val & 0x000707ff) == 0x1bb)
1201 lvds->use_bios_dividers = false;
1202 else {
1203 lvds->panel_ref_divider =
1204 RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
1205 lvds->panel_post_divider = (ppll_val >> 16) & 0x7;
1206 lvds->panel_fb_divider = ppll_val & 0x7ff;
1207
1208 if ((lvds->panel_ref_divider != 0) &&
1209 (lvds->panel_fb_divider > 3))
1210 lvds->use_bios_dividers = true;
1211 }
1212 lvds->panel_vcc_delay = 200;
1213
1214 DRM_INFO("Panel info derived from registers\n");
Alex Deucherde2103e2009-10-09 15:14:30 -04001215 DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
1216 lvds->native_mode.vdisplay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001217
1218 return lvds;
1219}
1220
1221struct radeon_encoder_lvds *radeon_combios_get_lvds_info(struct radeon_encoder
1222 *encoder)
1223{
1224 struct drm_device *dev = encoder->base.dev;
1225 struct radeon_device *rdev = dev->dev_private;
1226 uint16_t lcd_info;
1227 uint32_t panel_setup;
1228 char stmp[30];
1229 int tmp, i;
1230 struct radeon_encoder_lvds *lvds = NULL;
1231
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001232 lcd_info = combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
1233
1234 if (lcd_info) {
1235 lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
1236
1237 if (!lvds)
1238 return NULL;
1239
1240 for (i = 0; i < 24; i++)
1241 stmp[i] = RBIOS8(lcd_info + i + 1);
1242 stmp[24] = 0;
1243
1244 DRM_INFO("Panel ID String: %s\n", stmp);
1245
Alex Deucherde2103e2009-10-09 15:14:30 -04001246 lvds->native_mode.hdisplay = RBIOS16(lcd_info + 0x19);
1247 lvds->native_mode.vdisplay = RBIOS16(lcd_info + 0x1b);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001248
Alex Deucherde2103e2009-10-09 15:14:30 -04001249 DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
1250 lvds->native_mode.vdisplay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001251
1252 lvds->panel_vcc_delay = RBIOS16(lcd_info + 0x2c);
Andrew Morton94cf6432010-02-02 14:40:29 -08001253 lvds->panel_vcc_delay = min_t(u16, lvds->panel_vcc_delay, 2000);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001254
1255 lvds->panel_pwr_delay = RBIOS8(lcd_info + 0x24);
1256 lvds->panel_digon_delay = RBIOS16(lcd_info + 0x38) & 0xf;
1257 lvds->panel_blon_delay = (RBIOS16(lcd_info + 0x38) >> 4) & 0xf;
1258
1259 lvds->panel_ref_divider = RBIOS16(lcd_info + 0x2e);
1260 lvds->panel_post_divider = RBIOS8(lcd_info + 0x30);
1261 lvds->panel_fb_divider = RBIOS16(lcd_info + 0x31);
1262 if ((lvds->panel_ref_divider != 0) &&
1263 (lvds->panel_fb_divider > 3))
1264 lvds->use_bios_dividers = true;
1265
1266 panel_setup = RBIOS32(lcd_info + 0x39);
1267 lvds->lvds_gen_cntl = 0xff00;
1268 if (panel_setup & 0x1)
1269 lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_FORMAT;
1270
1271 if ((panel_setup >> 4) & 0x1)
1272 lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_TYPE;
1273
1274 switch ((panel_setup >> 8) & 0x7) {
1275 case 0:
1276 lvds->lvds_gen_cntl |= RADEON_LVDS_NO_FM;
1277 break;
1278 case 1:
1279 lvds->lvds_gen_cntl |= RADEON_LVDS_2_GREY;
1280 break;
1281 case 2:
1282 lvds->lvds_gen_cntl |= RADEON_LVDS_4_GREY;
1283 break;
1284 default:
1285 break;
1286 }
1287
1288 if ((panel_setup >> 16) & 0x1)
1289 lvds->lvds_gen_cntl |= RADEON_LVDS_FP_POL_LOW;
1290
1291 if ((panel_setup >> 17) & 0x1)
1292 lvds->lvds_gen_cntl |= RADEON_LVDS_LP_POL_LOW;
1293
1294 if ((panel_setup >> 18) & 0x1)
1295 lvds->lvds_gen_cntl |= RADEON_LVDS_DTM_POL_LOW;
1296
1297 if ((panel_setup >> 23) & 0x1)
1298 lvds->lvds_gen_cntl |= RADEON_LVDS_BL_CLK_SEL;
1299
1300 lvds->lvds_gen_cntl |= (panel_setup & 0xf0000000);
1301
1302 for (i = 0; i < 32; i++) {
1303 tmp = RBIOS16(lcd_info + 64 + i * 2);
1304 if (tmp == 0)
1305 break;
1306
Alex Deucherde2103e2009-10-09 15:14:30 -04001307 if ((RBIOS16(tmp) == lvds->native_mode.hdisplay) &&
Alex Deucher68b61a72010-05-18 00:30:05 -04001308 (RBIOS16(tmp + 2) == lvds->native_mode.vdisplay)) {
1309 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1310 (RBIOS16(tmp + 17) - RBIOS16(tmp + 19)) * 8;
1311 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1312 (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) - 1) * 8;
1313 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1314 (RBIOS8(tmp + 23) * 8);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001315
Alex Deucher68b61a72010-05-18 00:30:05 -04001316 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1317 (RBIOS16(tmp + 24) - RBIOS16(tmp + 26));
1318 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1319 ((RBIOS16(tmp + 28) & 0x7ff) - RBIOS16(tmp + 26));
1320 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1321 ((RBIOS16(tmp + 28) & 0xf800) >> 11);
Alex Deucherde2103e2009-10-09 15:14:30 -04001322
1323 lvds->native_mode.clock = RBIOS16(tmp + 9) * 10;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001324 lvds->native_mode.flags = 0;
Alex Deucherde2103e2009-10-09 15:14:30 -04001325 /* set crtc values */
1326 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
1327
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001328 }
1329 }
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001330 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001331 DRM_INFO("No panel info found in BIOS\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +02001332 lvds = radeon_legacy_get_lvds_info_from_regs(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001333 }
Michel Dänzer03047cd2010-02-10 11:05:11 +01001334
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +02001335 if (lvds)
1336 encoder->native_mode = lvds->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001337 return lvds;
1338}
1339
1340static const struct radeon_tmds_pll default_tmds_pll[CHIP_LAST][4] = {
1341 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R100 */
1342 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV100 */
1343 {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS100 */
1344 {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV200 */
1345 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RS200 */
1346 {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R200 */
1347 {{15500, 0x81b}, {0xffffffff, 0x83f}, {0, 0}, {0, 0}}, /* CHIP_RV250 */
1348 {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS300 */
1349 {{13000, 0x400f4}, {15000, 0x400f7}, {0xffffffff, 0x40111}, {0, 0}}, /* CHIP_RV280 */
1350 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R300 */
1351 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R350 */
1352 {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV350 */
1353 {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV380 */
1354 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R420 */
1355 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R423 */
1356 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RV410 */
Alex Deucherfcec5702009-11-10 21:25:07 -05001357 { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS400 */
1358 { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS480 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001359};
1360
Dave Airlie445282d2009-09-09 17:40:54 +10001361bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
1362 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001363{
Dave Airlie445282d2009-09-09 17:40:54 +10001364 struct drm_device *dev = encoder->base.dev;
1365 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001366 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001367
1368 for (i = 0; i < 4; i++) {
1369 tmds->tmds_pll[i].value =
Dave Airlie445282d2009-09-09 17:40:54 +10001370 default_tmds_pll[rdev->family][i].value;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001371 tmds->tmds_pll[i].freq = default_tmds_pll[rdev->family][i].freq;
1372 }
1373
Dave Airlie445282d2009-09-09 17:40:54 +10001374 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001375}
1376
Dave Airlie445282d2009-09-09 17:40:54 +10001377bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
1378 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001379{
1380 struct drm_device *dev = encoder->base.dev;
1381 struct radeon_device *rdev = dev->dev_private;
1382 uint16_t tmds_info;
1383 int i, n;
1384 uint8_t ver;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001385
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001386 tmds_info = combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
1387
1388 if (tmds_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001389 ver = RBIOS8(tmds_info);
Alex Deucher40f76d82010-10-07 22:38:42 -04001390 DRM_DEBUG_KMS("DFP table revision: %d\n", ver);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001391 if (ver == 3) {
1392 n = RBIOS8(tmds_info + 5) + 1;
1393 if (n > 4)
1394 n = 4;
1395 for (i = 0; i < n; i++) {
1396 tmds->tmds_pll[i].value =
1397 RBIOS32(tmds_info + i * 10 + 0x08);
1398 tmds->tmds_pll[i].freq =
1399 RBIOS16(tmds_info + i * 10 + 0x10);
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001400 DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001401 tmds->tmds_pll[i].freq,
1402 tmds->tmds_pll[i].value);
1403 }
1404 } else if (ver == 4) {
1405 int stride = 0;
1406 n = RBIOS8(tmds_info + 5) + 1;
1407 if (n > 4)
1408 n = 4;
1409 for (i = 0; i < n; i++) {
1410 tmds->tmds_pll[i].value =
1411 RBIOS32(tmds_info + stride + 0x08);
1412 tmds->tmds_pll[i].freq =
1413 RBIOS16(tmds_info + stride + 0x10);
1414 if (i == 0)
1415 stride += 10;
1416 else
1417 stride += 6;
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001418 DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001419 tmds->tmds_pll[i].freq,
1420 tmds->tmds_pll[i].value);
1421 }
1422 }
Alex Deucherfcec5702009-11-10 21:25:07 -05001423 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001424 DRM_INFO("No TMDS info found in BIOS\n");
Alex Deucherfcec5702009-11-10 21:25:07 -05001425 return false;
1426 }
Dave Airlie445282d2009-09-09 17:40:54 +10001427 return true;
1428}
1429
Alex Deucherfcec5702009-11-10 21:25:07 -05001430bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
1431 struct radeon_encoder_ext_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001432{
1433 struct drm_device *dev = encoder->base.dev;
1434 struct radeon_device *rdev = dev->dev_private;
Alex Deucherfcec5702009-11-10 21:25:07 -05001435 struct radeon_i2c_bus_rec i2c_bus;
1436
1437 /* default for macs */
Alex Deucher179e8072010-08-05 21:21:17 -04001438 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
Alex Deucherf376b942010-08-05 21:21:16 -04001439 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucherfcec5702009-11-10 21:25:07 -05001440
1441 /* XXX some macs have duallink chips */
1442 switch (rdev->mode_info.connector_table) {
1443 case CT_POWERBOOK_EXTERNAL:
1444 case CT_MINI_EXTERNAL:
1445 default:
1446 tmds->dvo_chip = DVO_SIL164;
1447 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1448 break;
1449 }
1450
1451 return true;
1452}
1453
1454bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
1455 struct radeon_encoder_ext_tmds *tmds)
1456{
1457 struct drm_device *dev = encoder->base.dev;
1458 struct radeon_device *rdev = dev->dev_private;
1459 uint16_t offset;
Alex Deucher179e8072010-08-05 21:21:17 -04001460 uint8_t ver;
Alex Deucherfcec5702009-11-10 21:25:07 -05001461 enum radeon_combios_ddc gpio;
1462 struct radeon_i2c_bus_rec i2c_bus;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001463
Alex Deucherfcec5702009-11-10 21:25:07 -05001464 tmds->i2c_bus = NULL;
1465 if (rdev->flags & RADEON_IS_IGP) {
Alex Deucher179e8072010-08-05 21:21:17 -04001466 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1467 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1468 tmds->dvo_chip = DVO_SIL164;
1469 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
Alex Deucherfcec5702009-11-10 21:25:07 -05001470 } else {
1471 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
1472 if (offset) {
1473 ver = RBIOS8(offset);
Alex Deucher40f76d82010-10-07 22:38:42 -04001474 DRM_DEBUG_KMS("External TMDS Table revision: %d\n", ver);
Alex Deucherfcec5702009-11-10 21:25:07 -05001475 tmds->slave_addr = RBIOS8(offset + 4 + 2);
1476 tmds->slave_addr >>= 1; /* 7 bit addressing */
1477 gpio = RBIOS8(offset + 4 + 3);
Alex Deucher179e8072010-08-05 21:21:17 -04001478 if (gpio == DDC_LCD) {
1479 /* MM i2c */
Alex Deucher40bacf12009-12-23 03:23:21 -05001480 i2c_bus.valid = true;
1481 i2c_bus.hw_capable = true;
1482 i2c_bus.mm_i2c = true;
Alex Deucher179e8072010-08-05 21:21:17 -04001483 i2c_bus.i2c_id = 0xa0;
1484 } else
1485 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
1486 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucherfcec5702009-11-10 21:25:07 -05001487 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001488 }
Alex Deucherfcec5702009-11-10 21:25:07 -05001489
1490 if (!tmds->i2c_bus) {
1491 DRM_INFO("No valid Ext TMDS info found in BIOS\n");
1492 return false;
1493 }
1494
1495 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001496}
1497
1498bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1499{
1500 struct radeon_device *rdev = dev->dev_private;
1501 struct radeon_i2c_bus_rec ddc_i2c;
Alex Deuchereed45b32009-12-04 14:45:27 -05001502 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001503
1504 rdev->mode_info.connector_table = radeon_connector_table;
1505 if (rdev->mode_info.connector_table == CT_NONE) {
1506#ifdef CONFIG_PPC_PMAC
Grant Likely71a157e2010-02-01 21:34:14 -07001507 if (of_machine_is_compatible("PowerBook3,3")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001508 /* powerbook with VGA */
1509 rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
Grant Likely71a157e2010-02-01 21:34:14 -07001510 } else if (of_machine_is_compatible("PowerBook3,4") ||
1511 of_machine_is_compatible("PowerBook3,5")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001512 /* powerbook with internal tmds */
1513 rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001514 } else if (of_machine_is_compatible("PowerBook5,1") ||
1515 of_machine_is_compatible("PowerBook5,2") ||
1516 of_machine_is_compatible("PowerBook5,3") ||
1517 of_machine_is_compatible("PowerBook5,4") ||
1518 of_machine_is_compatible("PowerBook5,5")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001519 /* powerbook with external single link tmds (sil164) */
1520 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001521 } else if (of_machine_is_compatible("PowerBook5,6")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001522 /* powerbook with external dual or single link tmds */
1523 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001524 } else if (of_machine_is_compatible("PowerBook5,7") ||
1525 of_machine_is_compatible("PowerBook5,8") ||
1526 of_machine_is_compatible("PowerBook5,9")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001527 /* PowerBook6,2 ? */
1528 /* powerbook with external dual link tmds (sil1178?) */
1529 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001530 } else if (of_machine_is_compatible("PowerBook4,1") ||
1531 of_machine_is_compatible("PowerBook4,2") ||
1532 of_machine_is_compatible("PowerBook4,3") ||
1533 of_machine_is_compatible("PowerBook6,3") ||
1534 of_machine_is_compatible("PowerBook6,5") ||
1535 of_machine_is_compatible("PowerBook6,7")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001536 /* ibook */
1537 rdev->mode_info.connector_table = CT_IBOOK;
Grant Likely71a157e2010-02-01 21:34:14 -07001538 } else if (of_machine_is_compatible("PowerMac4,4")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001539 /* emac */
1540 rdev->mode_info.connector_table = CT_EMAC;
Grant Likely71a157e2010-02-01 21:34:14 -07001541 } else if (of_machine_is_compatible("PowerMac10,1")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001542 /* mini with internal tmds */
1543 rdev->mode_info.connector_table = CT_MINI_INTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001544 } else if (of_machine_is_compatible("PowerMac10,2")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001545 /* mini with external tmds */
1546 rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001547 } else if (of_machine_is_compatible("PowerMac12,1")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001548 /* PowerMac8,1 ? */
1549 /* imac g5 isight */
1550 rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
Alex Deucheraa74fbb2010-09-07 14:41:30 -04001551 } else if ((rdev->pdev->device == 0x4a48) &&
1552 (rdev->pdev->subsystem_vendor == 0x1002) &&
1553 (rdev->pdev->subsystem_device == 0x4a48)) {
1554 /* Mac X800 */
1555 rdev->mode_info.connector_table = CT_MAC_X800;
Alex Deucher9fad3212011-02-07 13:15:28 -05001556 } else if ((rdev->pdev->device == 0x4150) &&
1557 (rdev->pdev->subsystem_vendor == 0x1002) &&
1558 (rdev->pdev->subsystem_device == 0x4150)) {
1559 /* Mac G5 9600 */
1560 rdev->mode_info.connector_table = CT_MAC_G5_9600;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001561 } else
1562#endif /* CONFIG_PPC_PMAC */
Dave Airlie76a71422010-06-11 01:09:05 -04001563#ifdef CONFIG_PPC64
1564 if (ASIC_IS_RN50(rdev))
1565 rdev->mode_info.connector_table = CT_RN50_POWER;
1566 else
1567#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001568 rdev->mode_info.connector_table = CT_GENERIC;
1569 }
1570
1571 switch (rdev->mode_info.connector_table) {
1572 case CT_GENERIC:
1573 DRM_INFO("Connector Table: %d (generic)\n",
1574 rdev->mode_info.connector_table);
1575 /* these are the most common settings */
1576 if (rdev->flags & RADEON_SINGLE_CRTC) {
1577 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001578 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001579 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001580 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001581 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001582 ATOM_DEVICE_CRT1_SUPPORT,
1583 1),
1584 ATOM_DEVICE_CRT1_SUPPORT);
1585 radeon_add_legacy_connector(dev, 0,
1586 ATOM_DEVICE_CRT1_SUPPORT,
1587 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001588 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001589 CONNECTOR_OBJECT_ID_VGA,
1590 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001591 } else if (rdev->flags & RADEON_IS_MOBILITY) {
1592 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001593 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001594 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001595 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001596 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001597 ATOM_DEVICE_LCD1_SUPPORT,
1598 0),
1599 ATOM_DEVICE_LCD1_SUPPORT);
1600 radeon_add_legacy_connector(dev, 0,
1601 ATOM_DEVICE_LCD1_SUPPORT,
1602 DRM_MODE_CONNECTOR_LVDS,
Alex Deucherb75fad02009-11-05 13:16:01 -05001603 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001604 CONNECTOR_OBJECT_ID_LVDS,
1605 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001606
1607 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001608 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001609 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001610 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001611 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001612 ATOM_DEVICE_CRT1_SUPPORT,
1613 1),
1614 ATOM_DEVICE_CRT1_SUPPORT);
1615 radeon_add_legacy_connector(dev, 1,
1616 ATOM_DEVICE_CRT1_SUPPORT,
1617 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001618 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001619 CONNECTOR_OBJECT_ID_VGA,
1620 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001621 } else {
1622 /* DVI-I - tv dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001623 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001624 hpd.hpd = RADEON_HPD_1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001625 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001626 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001627 ATOM_DEVICE_DFP1_SUPPORT,
1628 0),
1629 ATOM_DEVICE_DFP1_SUPPORT);
1630 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001631 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001632 ATOM_DEVICE_CRT2_SUPPORT,
1633 2),
1634 ATOM_DEVICE_CRT2_SUPPORT);
1635 radeon_add_legacy_connector(dev, 0,
1636 ATOM_DEVICE_DFP1_SUPPORT |
1637 ATOM_DEVICE_CRT2_SUPPORT,
1638 DRM_MODE_CONNECTOR_DVII,
Alex Deucherb75fad02009-11-05 13:16:01 -05001639 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001640 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1641 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001642
1643 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001644 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001645 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001646 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001647 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001648 ATOM_DEVICE_CRT1_SUPPORT,
1649 1),
1650 ATOM_DEVICE_CRT1_SUPPORT);
1651 radeon_add_legacy_connector(dev, 1,
1652 ATOM_DEVICE_CRT1_SUPPORT,
1653 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001654 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001655 CONNECTOR_OBJECT_ID_VGA,
1656 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001657 }
1658
1659 if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
1660 /* TV - tv dac */
Alex Deuchereed45b32009-12-04 14:45:27 -05001661 ddc_i2c.valid = false;
1662 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001663 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001664 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001665 ATOM_DEVICE_TV1_SUPPORT,
1666 2),
1667 ATOM_DEVICE_TV1_SUPPORT);
1668 radeon_add_legacy_connector(dev, 2,
1669 ATOM_DEVICE_TV1_SUPPORT,
1670 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001671 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001672 CONNECTOR_OBJECT_ID_SVIDEO,
1673 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001674 }
1675 break;
1676 case CT_IBOOK:
1677 DRM_INFO("Connector Table: %d (ibook)\n",
1678 rdev->mode_info.connector_table);
1679 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001680 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001681 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001682 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001683 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001684 ATOM_DEVICE_LCD1_SUPPORT,
1685 0),
1686 ATOM_DEVICE_LCD1_SUPPORT);
1687 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001688 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001689 CONNECTOR_OBJECT_ID_LVDS,
1690 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001691 /* VGA - TV DAC */
Alex Deucher179e8072010-08-05 21:21:17 -04001692 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001693 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001694 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001695 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001696 ATOM_DEVICE_CRT2_SUPPORT,
1697 2),
1698 ATOM_DEVICE_CRT2_SUPPORT);
1699 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001700 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001701 CONNECTOR_OBJECT_ID_VGA,
1702 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001703 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001704 ddc_i2c.valid = false;
1705 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001706 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001707 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001708 ATOM_DEVICE_TV1_SUPPORT,
1709 2),
1710 ATOM_DEVICE_TV1_SUPPORT);
1711 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1712 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001713 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001714 CONNECTOR_OBJECT_ID_SVIDEO,
1715 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001716 break;
1717 case CT_POWERBOOK_EXTERNAL:
1718 DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
1719 rdev->mode_info.connector_table);
1720 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001721 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001722 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001723 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001724 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001725 ATOM_DEVICE_LCD1_SUPPORT,
1726 0),
1727 ATOM_DEVICE_LCD1_SUPPORT);
1728 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001729 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001730 CONNECTOR_OBJECT_ID_LVDS,
1731 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001732 /* DVI-I - primary dac, ext tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001733 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001734 hpd.hpd = RADEON_HPD_2; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001735 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001736 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001737 ATOM_DEVICE_DFP2_SUPPORT,
1738 0),
1739 ATOM_DEVICE_DFP2_SUPPORT);
1740 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001741 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001742 ATOM_DEVICE_CRT1_SUPPORT,
1743 1),
1744 ATOM_DEVICE_CRT1_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05001745 /* XXX some are SL */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001746 radeon_add_legacy_connector(dev, 1,
1747 ATOM_DEVICE_DFP2_SUPPORT |
1748 ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001749 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001750 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
1751 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001752 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001753 ddc_i2c.valid = false;
1754 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001755 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001756 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001757 ATOM_DEVICE_TV1_SUPPORT,
1758 2),
1759 ATOM_DEVICE_TV1_SUPPORT);
1760 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1761 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001762 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001763 CONNECTOR_OBJECT_ID_SVIDEO,
1764 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001765 break;
1766 case CT_POWERBOOK_INTERNAL:
1767 DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
1768 rdev->mode_info.connector_table);
1769 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001770 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001771 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001772 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001773 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001774 ATOM_DEVICE_LCD1_SUPPORT,
1775 0),
1776 ATOM_DEVICE_LCD1_SUPPORT);
1777 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001778 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001779 CONNECTOR_OBJECT_ID_LVDS,
1780 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001781 /* DVI-I - primary dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001782 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001783 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001784 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001785 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001786 ATOM_DEVICE_DFP1_SUPPORT,
1787 0),
1788 ATOM_DEVICE_DFP1_SUPPORT);
1789 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001790 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001791 ATOM_DEVICE_CRT1_SUPPORT,
1792 1),
1793 ATOM_DEVICE_CRT1_SUPPORT);
1794 radeon_add_legacy_connector(dev, 1,
1795 ATOM_DEVICE_DFP1_SUPPORT |
1796 ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001797 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001798 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1799 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001800 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001801 ddc_i2c.valid = false;
1802 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001803 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001804 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001805 ATOM_DEVICE_TV1_SUPPORT,
1806 2),
1807 ATOM_DEVICE_TV1_SUPPORT);
1808 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1809 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001810 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001811 CONNECTOR_OBJECT_ID_SVIDEO,
1812 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001813 break;
1814 case CT_POWERBOOK_VGA:
1815 DRM_INFO("Connector Table: %d (powerbook vga)\n",
1816 rdev->mode_info.connector_table);
1817 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001818 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001819 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001820 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001821 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001822 ATOM_DEVICE_LCD1_SUPPORT,
1823 0),
1824 ATOM_DEVICE_LCD1_SUPPORT);
1825 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001826 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001827 CONNECTOR_OBJECT_ID_LVDS,
1828 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001829 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001830 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001831 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001832 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001833 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001834 ATOM_DEVICE_CRT1_SUPPORT,
1835 1),
1836 ATOM_DEVICE_CRT1_SUPPORT);
1837 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001838 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001839 CONNECTOR_OBJECT_ID_VGA,
1840 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001841 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001842 ddc_i2c.valid = false;
1843 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001844 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001845 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001846 ATOM_DEVICE_TV1_SUPPORT,
1847 2),
1848 ATOM_DEVICE_TV1_SUPPORT);
1849 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1850 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001851 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001852 CONNECTOR_OBJECT_ID_SVIDEO,
1853 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001854 break;
1855 case CT_MINI_EXTERNAL:
1856 DRM_INFO("Connector Table: %d (mini external tmds)\n",
1857 rdev->mode_info.connector_table);
1858 /* DVI-I - tv dac, ext tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001859 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001860 hpd.hpd = RADEON_HPD_2; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001861 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001862 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001863 ATOM_DEVICE_DFP2_SUPPORT,
1864 0),
1865 ATOM_DEVICE_DFP2_SUPPORT);
1866 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001867 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001868 ATOM_DEVICE_CRT2_SUPPORT,
1869 2),
1870 ATOM_DEVICE_CRT2_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05001871 /* XXX are any DL? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001872 radeon_add_legacy_connector(dev, 0,
1873 ATOM_DEVICE_DFP2_SUPPORT |
1874 ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001875 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001876 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1877 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001878 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001879 ddc_i2c.valid = false;
1880 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001881 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001882 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001883 ATOM_DEVICE_TV1_SUPPORT,
1884 2),
1885 ATOM_DEVICE_TV1_SUPPORT);
1886 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
1887 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001888 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001889 CONNECTOR_OBJECT_ID_SVIDEO,
1890 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001891 break;
1892 case CT_MINI_INTERNAL:
1893 DRM_INFO("Connector Table: %d (mini internal tmds)\n",
1894 rdev->mode_info.connector_table);
1895 /* DVI-I - tv dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001896 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001897 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001898 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001899 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001900 ATOM_DEVICE_DFP1_SUPPORT,
1901 0),
1902 ATOM_DEVICE_DFP1_SUPPORT);
1903 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001904 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001905 ATOM_DEVICE_CRT2_SUPPORT,
1906 2),
1907 ATOM_DEVICE_CRT2_SUPPORT);
1908 radeon_add_legacy_connector(dev, 0,
1909 ATOM_DEVICE_DFP1_SUPPORT |
1910 ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001911 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001912 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1913 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001914 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001915 ddc_i2c.valid = false;
1916 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001917 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001918 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001919 ATOM_DEVICE_TV1_SUPPORT,
1920 2),
1921 ATOM_DEVICE_TV1_SUPPORT);
1922 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
1923 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001924 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001925 CONNECTOR_OBJECT_ID_SVIDEO,
1926 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001927 break;
1928 case CT_IMAC_G5_ISIGHT:
1929 DRM_INFO("Connector Table: %d (imac g5 isight)\n",
1930 rdev->mode_info.connector_table);
1931 /* DVI-D - int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001932 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001933 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001934 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001935 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001936 ATOM_DEVICE_DFP1_SUPPORT,
1937 0),
1938 ATOM_DEVICE_DFP1_SUPPORT);
1939 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001940 DRM_MODE_CONNECTOR_DVID, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001941 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
1942 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001943 /* VGA - tv dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001944 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001945 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001946 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001947 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001948 ATOM_DEVICE_CRT2_SUPPORT,
1949 2),
1950 ATOM_DEVICE_CRT2_SUPPORT);
1951 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001952 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001953 CONNECTOR_OBJECT_ID_VGA,
1954 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001955 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001956 ddc_i2c.valid = false;
1957 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001958 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001959 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001960 ATOM_DEVICE_TV1_SUPPORT,
1961 2),
1962 ATOM_DEVICE_TV1_SUPPORT);
1963 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1964 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001965 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001966 CONNECTOR_OBJECT_ID_SVIDEO,
1967 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001968 break;
1969 case CT_EMAC:
1970 DRM_INFO("Connector Table: %d (emac)\n",
1971 rdev->mode_info.connector_table);
1972 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001973 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001974 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001975 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001976 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001977 ATOM_DEVICE_CRT1_SUPPORT,
1978 1),
1979 ATOM_DEVICE_CRT1_SUPPORT);
1980 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001981 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001982 CONNECTOR_OBJECT_ID_VGA,
1983 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001984 /* VGA - tv dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001985 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001986 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001987 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001988 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001989 ATOM_DEVICE_CRT2_SUPPORT,
1990 2),
1991 ATOM_DEVICE_CRT2_SUPPORT);
1992 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001993 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001994 CONNECTOR_OBJECT_ID_VGA,
1995 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001996 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001997 ddc_i2c.valid = false;
1998 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001999 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002000 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002001 ATOM_DEVICE_TV1_SUPPORT,
2002 2),
2003 ATOM_DEVICE_TV1_SUPPORT);
2004 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
2005 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05002006 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002007 CONNECTOR_OBJECT_ID_SVIDEO,
2008 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002009 break;
Dave Airlie76a71422010-06-11 01:09:05 -04002010 case CT_RN50_POWER:
2011 DRM_INFO("Connector Table: %d (rn50-power)\n",
2012 rdev->mode_info.connector_table);
2013 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04002014 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Dave Airlie76a71422010-06-11 01:09:05 -04002015 hpd.hpd = RADEON_HPD_NONE;
2016 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002017 radeon_get_encoder_enum(dev,
Dave Airlie76a71422010-06-11 01:09:05 -04002018 ATOM_DEVICE_CRT1_SUPPORT,
2019 1),
2020 ATOM_DEVICE_CRT1_SUPPORT);
2021 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
2022 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
2023 CONNECTOR_OBJECT_ID_VGA,
2024 &hpd);
Alex Deucher179e8072010-08-05 21:21:17 -04002025 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Dave Airlie76a71422010-06-11 01:09:05 -04002026 hpd.hpd = RADEON_HPD_NONE;
2027 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002028 radeon_get_encoder_enum(dev,
Dave Airlie76a71422010-06-11 01:09:05 -04002029 ATOM_DEVICE_CRT2_SUPPORT,
2030 2),
2031 ATOM_DEVICE_CRT2_SUPPORT);
2032 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
2033 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
2034 CONNECTOR_OBJECT_ID_VGA,
2035 &hpd);
2036 break;
Alex Deucheraa74fbb2010-09-07 14:41:30 -04002037 case CT_MAC_X800:
2038 DRM_INFO("Connector Table: %d (mac x800)\n",
2039 rdev->mode_info.connector_table);
2040 /* DVI - primary dac, internal tmds */
2041 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2042 hpd.hpd = RADEON_HPD_1; /* ??? */
2043 radeon_add_legacy_encoder(dev,
2044 radeon_get_encoder_enum(dev,
2045 ATOM_DEVICE_DFP1_SUPPORT,
2046 0),
2047 ATOM_DEVICE_DFP1_SUPPORT);
2048 radeon_add_legacy_encoder(dev,
2049 radeon_get_encoder_enum(dev,
2050 ATOM_DEVICE_CRT1_SUPPORT,
2051 1),
2052 ATOM_DEVICE_CRT1_SUPPORT);
2053 radeon_add_legacy_connector(dev, 0,
2054 ATOM_DEVICE_DFP1_SUPPORT |
2055 ATOM_DEVICE_CRT1_SUPPORT,
2056 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2057 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2058 &hpd);
2059 /* DVI - tv dac, dvo */
2060 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
2061 hpd.hpd = RADEON_HPD_2; /* ??? */
2062 radeon_add_legacy_encoder(dev,
2063 radeon_get_encoder_enum(dev,
2064 ATOM_DEVICE_DFP2_SUPPORT,
2065 0),
2066 ATOM_DEVICE_DFP2_SUPPORT);
2067 radeon_add_legacy_encoder(dev,
2068 radeon_get_encoder_enum(dev,
2069 ATOM_DEVICE_CRT2_SUPPORT,
2070 2),
2071 ATOM_DEVICE_CRT2_SUPPORT);
2072 radeon_add_legacy_connector(dev, 1,
2073 ATOM_DEVICE_DFP2_SUPPORT |
2074 ATOM_DEVICE_CRT2_SUPPORT,
2075 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2076 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
2077 &hpd);
2078 break;
Alex Deucher9fad3212011-02-07 13:15:28 -05002079 case CT_MAC_G5_9600:
2080 DRM_INFO("Connector Table: %d (mac g5 9600)\n",
2081 rdev->mode_info.connector_table);
2082 /* DVI - tv dac, dvo */
2083 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2084 hpd.hpd = RADEON_HPD_1; /* ??? */
2085 radeon_add_legacy_encoder(dev,
2086 radeon_get_encoder_enum(dev,
2087 ATOM_DEVICE_DFP2_SUPPORT,
2088 0),
2089 ATOM_DEVICE_DFP2_SUPPORT);
2090 radeon_add_legacy_encoder(dev,
2091 radeon_get_encoder_enum(dev,
2092 ATOM_DEVICE_CRT2_SUPPORT,
2093 2),
2094 ATOM_DEVICE_CRT2_SUPPORT);
2095 radeon_add_legacy_connector(dev, 0,
2096 ATOM_DEVICE_DFP2_SUPPORT |
2097 ATOM_DEVICE_CRT2_SUPPORT,
2098 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2099 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2100 &hpd);
2101 /* ADC - primary dac, internal tmds */
2102 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
2103 hpd.hpd = RADEON_HPD_2; /* ??? */
2104 radeon_add_legacy_encoder(dev,
2105 radeon_get_encoder_enum(dev,
2106 ATOM_DEVICE_DFP1_SUPPORT,
2107 0),
2108 ATOM_DEVICE_DFP1_SUPPORT);
2109 radeon_add_legacy_encoder(dev,
2110 radeon_get_encoder_enum(dev,
2111 ATOM_DEVICE_CRT1_SUPPORT,
2112 1),
2113 ATOM_DEVICE_CRT1_SUPPORT);
2114 radeon_add_legacy_connector(dev, 1,
2115 ATOM_DEVICE_DFP1_SUPPORT |
2116 ATOM_DEVICE_CRT1_SUPPORT,
2117 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2118 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2119 &hpd);
Alex Deucherbeb47272011-04-02 09:09:08 -04002120 /* TV - TV DAC */
2121 ddc_i2c.valid = false;
2122 hpd.hpd = RADEON_HPD_NONE;
2123 radeon_add_legacy_encoder(dev,
2124 radeon_get_encoder_enum(dev,
2125 ATOM_DEVICE_TV1_SUPPORT,
2126 2),
2127 ATOM_DEVICE_TV1_SUPPORT);
2128 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
2129 DRM_MODE_CONNECTOR_SVIDEO,
2130 &ddc_i2c,
2131 CONNECTOR_OBJECT_ID_SVIDEO,
2132 &hpd);
Alex Deucher9fad3212011-02-07 13:15:28 -05002133 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002134 default:
2135 DRM_INFO("Connector table: %d (invalid)\n",
2136 rdev->mode_info.connector_table);
2137 return false;
2138 }
2139
2140 radeon_link_encoder_connector(dev);
2141
2142 return true;
2143}
2144
2145static bool radeon_apply_legacy_quirks(struct drm_device *dev,
2146 int bios_index,
2147 enum radeon_combios_connector
2148 *legacy_connector,
Alex Deuchereed45b32009-12-04 14:45:27 -05002149 struct radeon_i2c_bus_rec *ddc_i2c,
2150 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002151{
Alex Deucherfcec5702009-11-10 21:25:07 -05002152
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002153 /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
2154 one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
2155 if (dev->pdev->device == 0x515e &&
2156 dev->pdev->subsystem_vendor == 0x1014) {
2157 if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
2158 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
2159 return false;
2160 }
2161
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002162 /* X300 card with extra non-existent DVI port */
2163 if (dev->pdev->device == 0x5B60 &&
2164 dev->pdev->subsystem_vendor == 0x17af &&
2165 dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
2166 if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
2167 return false;
2168 }
2169
2170 return true;
2171}
2172
Alex Deucher790cfb32009-10-15 23:26:09 -04002173static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
2174{
2175 /* Acer 5102 has non-existent TV port */
2176 if (dev->pdev->device == 0x5975 &&
2177 dev->pdev->subsystem_vendor == 0x1025 &&
2178 dev->pdev->subsystem_device == 0x009f)
2179 return false;
2180
Alex Deucherfc7f7112009-10-28 01:46:54 -04002181 /* HP dc5750 has non-existent TV port */
2182 if (dev->pdev->device == 0x5974 &&
2183 dev->pdev->subsystem_vendor == 0x103c &&
2184 dev->pdev->subsystem_device == 0x280a)
2185 return false;
2186
Alex Deucherfd874ad2009-11-16 18:33:51 -05002187 /* MSI S270 has non-existent TV port */
2188 if (dev->pdev->device == 0x5955 &&
2189 dev->pdev->subsystem_vendor == 0x1462 &&
2190 dev->pdev->subsystem_device == 0x0131)
2191 return false;
2192
Alex Deucher790cfb32009-10-15 23:26:09 -04002193 return true;
2194}
2195
Alex Deucherb75fad02009-11-05 13:16:01 -05002196static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
2197{
2198 struct radeon_device *rdev = dev->dev_private;
2199 uint32_t ext_tmds_info;
2200
2201 if (rdev->flags & RADEON_IS_IGP) {
2202 if (is_dvi_d)
2203 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
2204 else
2205 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2206 }
2207 ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
2208 if (ext_tmds_info) {
2209 uint8_t rev = RBIOS8(ext_tmds_info);
2210 uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
2211 if (rev >= 3) {
2212 if (is_dvi_d)
2213 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
2214 else
2215 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
2216 } else {
2217 if (flags & 1) {
2218 if (is_dvi_d)
2219 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
2220 else
2221 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
2222 }
2223 }
2224 }
2225 if (is_dvi_d)
2226 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
2227 else
2228 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2229}
2230
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002231bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2232{
2233 struct radeon_device *rdev = dev->dev_private;
2234 uint32_t conn_info, entry, devices;
Alex Deucherb75fad02009-11-05 13:16:01 -05002235 uint16_t tmp, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002236 enum radeon_combios_ddc ddc_type;
2237 enum radeon_combios_connector connector;
2238 int i = 0;
2239 struct radeon_i2c_bus_rec ddc_i2c;
Alex Deuchereed45b32009-12-04 14:45:27 -05002240 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002241
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002242 conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
2243 if (conn_info) {
2244 for (i = 0; i < 4; i++) {
2245 entry = conn_info + 2 + i * 2;
2246
2247 if (!RBIOS16(entry))
2248 break;
2249
2250 tmp = RBIOS16(entry);
2251
2252 connector = (tmp >> 12) & 0xf;
2253
2254 ddc_type = (tmp >> 8) & 0xf;
Alex Deucher179e8072010-08-05 21:21:17 -04002255 ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002256
Alex Deuchereed45b32009-12-04 14:45:27 -05002257 switch (connector) {
2258 case CONNECTOR_PROPRIETARY_LEGACY:
2259 case CONNECTOR_DVI_I_LEGACY:
2260 case CONNECTOR_DVI_D_LEGACY:
2261 if ((tmp >> 4) & 0x1)
2262 hpd.hpd = RADEON_HPD_2;
2263 else
2264 hpd.hpd = RADEON_HPD_1;
2265 break;
2266 default:
2267 hpd.hpd = RADEON_HPD_NONE;
2268 break;
2269 }
2270
Alex Deucher2d152c62009-10-15 23:08:05 -04002271 if (!radeon_apply_legacy_quirks(dev, i, &connector,
Alex Deuchereed45b32009-12-04 14:45:27 -05002272 &ddc_i2c, &hpd))
Alex Deucher2d152c62009-10-15 23:08:05 -04002273 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002274
2275 switch (connector) {
2276 case CONNECTOR_PROPRIETARY_LEGACY:
2277 if ((tmp >> 4) & 0x1)
2278 devices = ATOM_DEVICE_DFP2_SUPPORT;
2279 else
2280 devices = ATOM_DEVICE_DFP1_SUPPORT;
2281 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002282 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002283 (dev, devices, 0),
2284 devices);
2285 radeon_add_legacy_connector(dev, i, devices,
2286 legacy_connector_convert
2287 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002288 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002289 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
2290 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002291 break;
2292 case CONNECTOR_CRT_LEGACY:
2293 if (tmp & 0x1) {
2294 devices = ATOM_DEVICE_CRT2_SUPPORT;
2295 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002296 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002297 (dev,
2298 ATOM_DEVICE_CRT2_SUPPORT,
2299 2),
2300 ATOM_DEVICE_CRT2_SUPPORT);
2301 } else {
2302 devices = ATOM_DEVICE_CRT1_SUPPORT;
2303 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002304 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002305 (dev,
2306 ATOM_DEVICE_CRT1_SUPPORT,
2307 1),
2308 ATOM_DEVICE_CRT1_SUPPORT);
2309 }
2310 radeon_add_legacy_connector(dev,
2311 i,
2312 devices,
2313 legacy_connector_convert
2314 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002315 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002316 CONNECTOR_OBJECT_ID_VGA,
2317 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002318 break;
2319 case CONNECTOR_DVI_I_LEGACY:
2320 devices = 0;
2321 if (tmp & 0x1) {
2322 devices |= ATOM_DEVICE_CRT2_SUPPORT;
2323 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002324 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002325 (dev,
2326 ATOM_DEVICE_CRT2_SUPPORT,
2327 2),
2328 ATOM_DEVICE_CRT2_SUPPORT);
2329 } else {
2330 devices |= ATOM_DEVICE_CRT1_SUPPORT;
2331 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002332 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002333 (dev,
2334 ATOM_DEVICE_CRT1_SUPPORT,
2335 1),
2336 ATOM_DEVICE_CRT1_SUPPORT);
2337 }
2338 if ((tmp >> 4) & 0x1) {
2339 devices |= ATOM_DEVICE_DFP2_SUPPORT;
2340 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002341 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002342 (dev,
2343 ATOM_DEVICE_DFP2_SUPPORT,
2344 0),
2345 ATOM_DEVICE_DFP2_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05002346 connector_object_id = combios_check_dl_dvi(dev, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002347 } else {
2348 devices |= ATOM_DEVICE_DFP1_SUPPORT;
2349 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002350 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002351 (dev,
2352 ATOM_DEVICE_DFP1_SUPPORT,
2353 0),
2354 ATOM_DEVICE_DFP1_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05002355 connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002356 }
2357 radeon_add_legacy_connector(dev,
2358 i,
2359 devices,
2360 legacy_connector_convert
2361 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002362 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002363 connector_object_id,
2364 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002365 break;
2366 case CONNECTOR_DVI_D_LEGACY:
Alex Deucherb75fad02009-11-05 13:16:01 -05002367 if ((tmp >> 4) & 0x1) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002368 devices = ATOM_DEVICE_DFP2_SUPPORT;
Alex Deucherb75fad02009-11-05 13:16:01 -05002369 connector_object_id = combios_check_dl_dvi(dev, 1);
2370 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002371 devices = ATOM_DEVICE_DFP1_SUPPORT;
Alex Deucherb75fad02009-11-05 13:16:01 -05002372 connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2373 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002374 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002375 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002376 (dev, devices, 0),
2377 devices);
2378 radeon_add_legacy_connector(dev, i, devices,
2379 legacy_connector_convert
2380 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002381 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002382 connector_object_id,
2383 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002384 break;
2385 case CONNECTOR_CTV_LEGACY:
2386 case CONNECTOR_STV_LEGACY:
2387 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002388 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002389 (dev,
2390 ATOM_DEVICE_TV1_SUPPORT,
2391 2),
2392 ATOM_DEVICE_TV1_SUPPORT);
2393 radeon_add_legacy_connector(dev, i,
2394 ATOM_DEVICE_TV1_SUPPORT,
2395 legacy_connector_convert
2396 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002397 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002398 CONNECTOR_OBJECT_ID_SVIDEO,
2399 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002400 break;
2401 default:
2402 DRM_ERROR("Unknown connector type: %d\n",
2403 connector);
2404 continue;
2405 }
2406
2407 }
2408 } else {
2409 uint16_t tmds_info =
2410 combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
2411 if (tmds_info) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002412 DRM_DEBUG_KMS("Found DFP table, assuming DVI connector\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002413
2414 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002415 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002416 ATOM_DEVICE_CRT1_SUPPORT,
2417 1),
2418 ATOM_DEVICE_CRT1_SUPPORT);
2419 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002420 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002421 ATOM_DEVICE_DFP1_SUPPORT,
2422 0),
2423 ATOM_DEVICE_DFP1_SUPPORT);
2424
Alex Deucher179e8072010-08-05 21:21:17 -04002425 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deucher8e36ed02010-05-18 19:26:47 -04002426 hpd.hpd = RADEON_HPD_1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002427 radeon_add_legacy_connector(dev,
2428 0,
2429 ATOM_DEVICE_CRT1_SUPPORT |
2430 ATOM_DEVICE_DFP1_SUPPORT,
2431 DRM_MODE_CONNECTOR_DVII,
Alex Deucherb75fad02009-11-05 13:16:01 -05002432 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002433 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2434 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002435 } else {
Alex Deucherd0c403e2009-10-15 23:38:32 -04002436 uint16_t crt_info =
2437 combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002438 DRM_DEBUG_KMS("Found CRT table, assuming VGA connector\n");
Alex Deucherd0c403e2009-10-15 23:38:32 -04002439 if (crt_info) {
2440 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002441 radeon_get_encoder_enum(dev,
Alex Deucherd0c403e2009-10-15 23:38:32 -04002442 ATOM_DEVICE_CRT1_SUPPORT,
2443 1),
2444 ATOM_DEVICE_CRT1_SUPPORT);
Alex Deucher179e8072010-08-05 21:21:17 -04002445 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05002446 hpd.hpd = RADEON_HPD_NONE;
Alex Deucherd0c403e2009-10-15 23:38:32 -04002447 radeon_add_legacy_connector(dev,
2448 0,
2449 ATOM_DEVICE_CRT1_SUPPORT,
2450 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05002451 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002452 CONNECTOR_OBJECT_ID_VGA,
2453 &hpd);
Alex Deucherd0c403e2009-10-15 23:38:32 -04002454 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002455 DRM_DEBUG_KMS("No connector info found\n");
Alex Deucherd0c403e2009-10-15 23:38:32 -04002456 return false;
2457 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002458 }
2459 }
2460
2461 if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
2462 uint16_t lcd_info =
2463 combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
2464 if (lcd_info) {
2465 uint16_t lcd_ddc_info =
2466 combios_get_table_offset(dev,
2467 COMBIOS_LCD_DDC_INFO_TABLE);
2468
2469 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002470 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002471 ATOM_DEVICE_LCD1_SUPPORT,
2472 0),
2473 ATOM_DEVICE_LCD1_SUPPORT);
2474
2475 if (lcd_ddc_info) {
2476 ddc_type = RBIOS8(lcd_ddc_info + 2);
2477 switch (ddc_type) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002478 case DDC_LCD:
2479 ddc_i2c =
Alex Deucher179e8072010-08-05 21:21:17 -04002480 combios_setup_i2c_bus(rdev,
2481 DDC_LCD,
2482 RBIOS32(lcd_ddc_info + 3),
2483 RBIOS32(lcd_ddc_info + 7));
Alex Deucherf376b942010-08-05 21:21:16 -04002484 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002485 break;
2486 case DDC_GPIO:
2487 ddc_i2c =
Alex Deucher179e8072010-08-05 21:21:17 -04002488 combios_setup_i2c_bus(rdev,
2489 DDC_GPIO,
2490 RBIOS32(lcd_ddc_info + 3),
2491 RBIOS32(lcd_ddc_info + 7));
Alex Deucherf376b942010-08-05 21:21:16 -04002492 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002493 break;
2494 default:
Alex Deucher179e8072010-08-05 21:21:17 -04002495 ddc_i2c =
2496 combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002497 break;
2498 }
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002499 DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002500 } else
2501 ddc_i2c.valid = false;
2502
Alex Deuchereed45b32009-12-04 14:45:27 -05002503 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002504 radeon_add_legacy_connector(dev,
2505 5,
2506 ATOM_DEVICE_LCD1_SUPPORT,
2507 DRM_MODE_CONNECTOR_LVDS,
Alex Deucherb75fad02009-11-05 13:16:01 -05002508 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002509 CONNECTOR_OBJECT_ID_LVDS,
2510 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002511 }
2512 }
2513
2514 /* check TV table */
2515 if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
2516 uint32_t tv_info =
2517 combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
2518 if (tv_info) {
2519 if (RBIOS8(tv_info + 6) == 'T') {
Alex Deucher790cfb32009-10-15 23:26:09 -04002520 if (radeon_apply_legacy_tv_quirks(dev)) {
Alex Deuchereed45b32009-12-04 14:45:27 -05002521 hpd.hpd = RADEON_HPD_NONE;
Dave Airlied294ed62010-06-08 13:04:50 +10002522 ddc_i2c.valid = false;
Alex Deucher790cfb32009-10-15 23:26:09 -04002523 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002524 radeon_get_encoder_enum
Alex Deucher790cfb32009-10-15 23:26:09 -04002525 (dev,
2526 ATOM_DEVICE_TV1_SUPPORT,
2527 2),
2528 ATOM_DEVICE_TV1_SUPPORT);
2529 radeon_add_legacy_connector(dev, 6,
2530 ATOM_DEVICE_TV1_SUPPORT,
2531 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05002532 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002533 CONNECTOR_OBJECT_ID_SVIDEO,
2534 &hpd);
Alex Deucher790cfb32009-10-15 23:26:09 -04002535 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002536 }
2537 }
2538 }
2539
2540 radeon_link_encoder_connector(dev);
2541
2542 return true;
2543}
2544
Alex Deucher63f7d982011-05-03 12:44:54 -04002545static const char *thermal_controller_names[] = {
2546 "NONE",
2547 "lm63",
2548 "adm1032",
2549};
2550
Alex Deucher56278a82009-12-28 13:58:44 -05002551void radeon_combios_get_power_modes(struct radeon_device *rdev)
2552{
2553 struct drm_device *dev = rdev->ddev;
2554 u16 offset, misc, misc2 = 0;
2555 u8 rev, blocks, tmp;
2556 int state_index = 0;
2557
Alex Deuchera48b9b42010-04-22 14:03:55 -04002558 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05002559
Alex Deucher0975b162011-02-02 18:42:03 -05002560 /* allocate 2 power states */
2561 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * 2, GFP_KERNEL);
2562 if (!rdev->pm.power_state) {
2563 rdev->pm.default_power_state_index = state_index;
2564 rdev->pm.num_power_states = 0;
2565
2566 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2567 rdev->pm.current_clock_mode_index = 0;
2568 return;
2569 }
2570
Alex Deucher63f7d982011-05-03 12:44:54 -04002571 /* check for a thermal chip */
2572 offset = combios_get_table_offset(dev, COMBIOS_OVERDRIVE_INFO_TABLE);
2573 if (offset) {
2574 u8 thermal_controller = 0, gpio = 0, i2c_addr = 0, clk_bit = 0, data_bit = 0;
2575 struct radeon_i2c_bus_rec i2c_bus;
2576
2577 rev = RBIOS8(offset);
2578
2579 if (rev == 0) {
2580 thermal_controller = RBIOS8(offset + 3);
2581 gpio = RBIOS8(offset + 4) & 0x3f;
2582 i2c_addr = RBIOS8(offset + 5);
2583 } else if (rev == 1) {
2584 thermal_controller = RBIOS8(offset + 4);
2585 gpio = RBIOS8(offset + 5) & 0x3f;
2586 i2c_addr = RBIOS8(offset + 6);
2587 } else if (rev == 2) {
2588 thermal_controller = RBIOS8(offset + 4);
2589 gpio = RBIOS8(offset + 5) & 0x3f;
2590 i2c_addr = RBIOS8(offset + 6);
2591 clk_bit = RBIOS8(offset + 0xa);
2592 data_bit = RBIOS8(offset + 0xb);
2593 }
2594 if ((thermal_controller > 0) && (thermal_controller < 3)) {
2595 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2596 thermal_controller_names[thermal_controller],
2597 i2c_addr >> 1);
2598 if (gpio == DDC_LCD) {
2599 /* MM i2c */
2600 i2c_bus.valid = true;
2601 i2c_bus.hw_capable = true;
2602 i2c_bus.mm_i2c = true;
2603 i2c_bus.i2c_id = 0xa0;
2604 } else if (gpio == DDC_GPIO)
2605 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 1 << clk_bit, 1 << data_bit);
2606 else
2607 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
2608 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2609 if (rdev->pm.i2c_bus) {
2610 struct i2c_board_info info = { };
2611 const char *name = thermal_controller_names[thermal_controller];
2612 info.addr = i2c_addr >> 1;
2613 strlcpy(info.type, name, sizeof(info.type));
2614 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2615 }
2616 }
2617 }
2618
Alex Deucher56278a82009-12-28 13:58:44 -05002619 if (rdev->flags & RADEON_IS_MOBILITY) {
2620 offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
2621 if (offset) {
2622 rev = RBIOS8(offset);
2623 blocks = RBIOS8(offset + 0x2);
2624 /* power mode 0 tends to be the only valid one */
2625 rdev->pm.power_state[state_index].num_clock_modes = 1;
2626 rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
2627 rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
2628 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2629 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2630 goto default_mode;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002631 rdev->pm.power_state[state_index].type =
2632 POWER_STATE_TYPE_BATTERY;
Alex Deucher56278a82009-12-28 13:58:44 -05002633 misc = RBIOS16(offset + 0x5 + 0x0);
2634 if (rev > 4)
2635 misc2 = RBIOS16(offset + 0x5 + 0xe);
Alex Deucher79daedc2010-04-22 14:25:19 -04002636 rdev->pm.power_state[state_index].misc = misc;
2637 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher56278a82009-12-28 13:58:44 -05002638 if (misc & 0x4) {
2639 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
2640 if (misc & 0x8)
2641 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2642 true;
2643 else
2644 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2645 false;
2646 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
2647 if (rev < 6) {
2648 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
2649 RBIOS16(offset + 0x5 + 0xb) * 4;
2650 tmp = RBIOS8(offset + 0x5 + 0xd);
2651 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
2652 } else {
2653 u8 entries = RBIOS8(offset + 0x5 + 0xb);
2654 u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
2655 if (entries && voltage_table_offset) {
2656 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
2657 RBIOS16(voltage_table_offset) * 4;
2658 tmp = RBIOS8(voltage_table_offset + 0x2);
2659 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
2660 } else
2661 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
2662 }
2663 switch ((misc2 & 0x700) >> 8) {
2664 case 0:
2665 default:
2666 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
2667 break;
2668 case 1:
2669 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
2670 break;
2671 case 2:
2672 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
2673 break;
2674 case 3:
2675 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
2676 break;
2677 case 4:
2678 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
2679 break;
2680 }
2681 } else
2682 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2683 if (rev > 6)
Alex Deucher79daedc2010-04-22 14:25:19 -04002684 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05002685 RBIOS8(offset + 0x5 + 0x10);
Alex Deucherd7311172010-05-03 01:13:14 -04002686 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05002687 state_index++;
2688 } else {
2689 /* XXX figure out some good default low power mode for mobility cards w/out power tables */
2690 }
2691 } else {
2692 /* XXX figure out some good default low power mode for desktop cards */
2693 }
2694
2695default_mode:
2696 /* add the default mode */
Alex Deucher0ec0e742009-12-23 13:21:58 -05002697 rdev->pm.power_state[state_index].type =
2698 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05002699 rdev->pm.power_state[state_index].num_clock_modes = 1;
2700 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2701 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2702 rdev->pm.power_state[state_index].default_clock_mode = &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucher84d88f42010-05-27 17:01:42 -04002703 if ((state_index > 0) &&
Alex Deucher8de016e2010-06-03 21:28:23 -04002704 (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
Alex Deucher84d88f42010-05-27 17:01:42 -04002705 rdev->pm.power_state[state_index].clock_info[0].voltage =
2706 rdev->pm.power_state[0].clock_info[0].voltage;
2707 else
2708 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
Alex Deucher79daedc2010-04-22 14:25:19 -04002709 rdev->pm.power_state[state_index].pcie_lanes = 16;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002710 rdev->pm.power_state[state_index].flags = 0;
2711 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05002712 rdev->pm.num_power_states = state_index + 1;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002713
Alex Deuchera48b9b42010-04-22 14:03:55 -04002714 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2715 rdev->pm.current_clock_mode_index = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002716}
2717
Alex Deucherfcec5702009-11-10 21:25:07 -05002718void radeon_external_tmds_setup(struct drm_encoder *encoder)
2719{
2720 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2721 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
2722
2723 if (!tmds)
2724 return;
2725
2726 switch (tmds->dvo_chip) {
2727 case DVO_SIL164:
2728 /* sil 164 */
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002729 radeon_i2c_put_byte(tmds->i2c_bus,
2730 tmds->slave_addr,
2731 0x08, 0x30);
2732 radeon_i2c_put_byte(tmds->i2c_bus,
Alex Deucherfcec5702009-11-10 21:25:07 -05002733 tmds->slave_addr,
2734 0x09, 0x00);
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002735 radeon_i2c_put_byte(tmds->i2c_bus,
2736 tmds->slave_addr,
2737 0x0a, 0x90);
2738 radeon_i2c_put_byte(tmds->i2c_bus,
2739 tmds->slave_addr,
2740 0x0c, 0x89);
2741 radeon_i2c_put_byte(tmds->i2c_bus,
Alex Deucherfcec5702009-11-10 21:25:07 -05002742 tmds->slave_addr,
2743 0x08, 0x3b);
Alex Deucherfcec5702009-11-10 21:25:07 -05002744 break;
2745 case DVO_SIL1178:
2746 /* sil 1178 - untested */
2747 /*
2748 * 0x0f, 0x44
2749 * 0x0f, 0x4c
2750 * 0x0e, 0x01
2751 * 0x0a, 0x80
2752 * 0x09, 0x30
2753 * 0x0c, 0xc9
2754 * 0x0d, 0x70
2755 * 0x08, 0x32
2756 * 0x08, 0x33
2757 */
2758 break;
2759 default:
2760 break;
2761 }
2762
2763}
2764
2765bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
2766{
2767 struct drm_device *dev = encoder->dev;
2768 struct radeon_device *rdev = dev->dev_private;
2769 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2770 uint16_t offset;
2771 uint8_t blocks, slave_addr, rev;
2772 uint32_t index, id;
2773 uint32_t reg, val, and_mask, or_mask;
2774 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
2775
Alex Deucherfcec5702009-11-10 21:25:07 -05002776 if (!tmds)
2777 return false;
2778
2779 if (rdev->flags & RADEON_IS_IGP) {
2780 offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
2781 rev = RBIOS8(offset);
2782 if (offset) {
2783 rev = RBIOS8(offset);
2784 if (rev > 1) {
2785 blocks = RBIOS8(offset + 3);
2786 index = offset + 4;
2787 while (blocks > 0) {
2788 id = RBIOS16(index);
2789 index += 2;
2790 switch (id >> 13) {
2791 case 0:
2792 reg = (id & 0x1fff) * 4;
2793 val = RBIOS32(index);
2794 index += 4;
2795 WREG32(reg, val);
2796 break;
2797 case 2:
2798 reg = (id & 0x1fff) * 4;
2799 and_mask = RBIOS32(index);
2800 index += 4;
2801 or_mask = RBIOS32(index);
2802 index += 4;
2803 val = RREG32(reg);
2804 val = (val & and_mask) | or_mask;
2805 WREG32(reg, val);
2806 break;
2807 case 3:
2808 val = RBIOS16(index);
2809 index += 2;
2810 udelay(val);
2811 break;
2812 case 4:
2813 val = RBIOS16(index);
2814 index += 2;
2815 udelay(val * 1000);
2816 break;
2817 case 6:
2818 slave_addr = id & 0xff;
2819 slave_addr >>= 1; /* 7 bit addressing */
2820 index++;
2821 reg = RBIOS8(index);
2822 index++;
2823 val = RBIOS8(index);
2824 index++;
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002825 radeon_i2c_put_byte(tmds->i2c_bus,
2826 slave_addr,
2827 reg, val);
Alex Deucherfcec5702009-11-10 21:25:07 -05002828 break;
2829 default:
2830 DRM_ERROR("Unknown id %d\n", id >> 13);
2831 break;
2832 }
2833 blocks--;
2834 }
2835 return true;
2836 }
2837 }
2838 } else {
2839 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
2840 if (offset) {
2841 index = offset + 10;
2842 id = RBIOS16(index);
2843 while (id != 0xffff) {
2844 index += 2;
2845 switch (id >> 13) {
2846 case 0:
2847 reg = (id & 0x1fff) * 4;
2848 val = RBIOS32(index);
2849 WREG32(reg, val);
2850 break;
2851 case 2:
2852 reg = (id & 0x1fff) * 4;
2853 and_mask = RBIOS32(index);
2854 index += 4;
2855 or_mask = RBIOS32(index);
2856 index += 4;
2857 val = RREG32(reg);
2858 val = (val & and_mask) | or_mask;
2859 WREG32(reg, val);
2860 break;
2861 case 4:
2862 val = RBIOS16(index);
2863 index += 2;
2864 udelay(val);
2865 break;
2866 case 5:
2867 reg = id & 0x1fff;
2868 and_mask = RBIOS32(index);
2869 index += 4;
2870 or_mask = RBIOS32(index);
2871 index += 4;
2872 val = RREG32_PLL(reg);
2873 val = (val & and_mask) | or_mask;
2874 WREG32_PLL(reg, val);
2875 break;
2876 case 6:
2877 reg = id & 0x1fff;
2878 val = RBIOS8(index);
2879 index += 1;
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002880 radeon_i2c_put_byte(tmds->i2c_bus,
2881 tmds->slave_addr,
2882 reg, val);
Alex Deucherfcec5702009-11-10 21:25:07 -05002883 break;
2884 default:
2885 DRM_ERROR("Unknown id %d\n", id >> 13);
2886 break;
2887 }
2888 id = RBIOS16(index);
2889 }
2890 return true;
2891 }
2892 }
2893 return false;
2894}
2895
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002896static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
2897{
2898 struct radeon_device *rdev = dev->dev_private;
2899
2900 if (offset) {
2901 while (RBIOS16(offset)) {
2902 uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
2903 uint32_t addr = (RBIOS16(offset) & 0x1fff);
2904 uint32_t val, and_mask, or_mask;
2905 uint32_t tmp;
2906
2907 offset += 2;
2908 switch (cmd) {
2909 case 0:
2910 val = RBIOS32(offset);
2911 offset += 4;
2912 WREG32(addr, val);
2913 break;
2914 case 1:
2915 val = RBIOS32(offset);
2916 offset += 4;
2917 WREG32(addr, val);
2918 break;
2919 case 2:
2920 and_mask = RBIOS32(offset);
2921 offset += 4;
2922 or_mask = RBIOS32(offset);
2923 offset += 4;
2924 tmp = RREG32(addr);
2925 tmp &= and_mask;
2926 tmp |= or_mask;
2927 WREG32(addr, tmp);
2928 break;
2929 case 3:
2930 and_mask = RBIOS32(offset);
2931 offset += 4;
2932 or_mask = RBIOS32(offset);
2933 offset += 4;
2934 tmp = RREG32(addr);
2935 tmp &= and_mask;
2936 tmp |= or_mask;
2937 WREG32(addr, tmp);
2938 break;
2939 case 4:
2940 val = RBIOS16(offset);
2941 offset += 2;
2942 udelay(val);
2943 break;
2944 case 5:
2945 val = RBIOS16(offset);
2946 offset += 2;
2947 switch (addr) {
2948 case 8:
2949 while (val--) {
2950 if (!
2951 (RREG32_PLL
2952 (RADEON_CLK_PWRMGT_CNTL) &
2953 RADEON_MC_BUSY))
2954 break;
2955 }
2956 break;
2957 case 9:
2958 while (val--) {
2959 if ((RREG32(RADEON_MC_STATUS) &
2960 RADEON_MC_IDLE))
2961 break;
2962 }
2963 break;
2964 default:
2965 break;
2966 }
2967 break;
2968 default:
2969 break;
2970 }
2971 }
2972 }
2973}
2974
2975static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
2976{
2977 struct radeon_device *rdev = dev->dev_private;
2978
2979 if (offset) {
2980 while (RBIOS8(offset)) {
2981 uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
2982 uint8_t addr = (RBIOS8(offset) & 0x3f);
2983 uint32_t val, shift, tmp;
2984 uint32_t and_mask, or_mask;
2985
2986 offset++;
2987 switch (cmd) {
2988 case 0:
2989 val = RBIOS32(offset);
2990 offset += 4;
2991 WREG32_PLL(addr, val);
2992 break;
2993 case 1:
2994 shift = RBIOS8(offset) * 8;
2995 offset++;
2996 and_mask = RBIOS8(offset) << shift;
2997 and_mask |= ~(0xff << shift);
2998 offset++;
2999 or_mask = RBIOS8(offset) << shift;
3000 offset++;
3001 tmp = RREG32_PLL(addr);
3002 tmp &= and_mask;
3003 tmp |= or_mask;
3004 WREG32_PLL(addr, tmp);
3005 break;
3006 case 2:
3007 case 3:
3008 tmp = 1000;
3009 switch (addr) {
3010 case 1:
3011 udelay(150);
3012 break;
3013 case 2:
3014 udelay(1000);
3015 break;
3016 case 3:
3017 while (tmp--) {
3018 if (!
3019 (RREG32_PLL
3020 (RADEON_CLK_PWRMGT_CNTL) &
3021 RADEON_MC_BUSY))
3022 break;
3023 }
3024 break;
3025 case 4:
3026 while (tmp--) {
3027 if (RREG32_PLL
3028 (RADEON_CLK_PWRMGT_CNTL) &
3029 RADEON_DLL_READY)
3030 break;
3031 }
3032 break;
3033 case 5:
3034 tmp =
3035 RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
3036 if (tmp & RADEON_CG_NO1_DEBUG_0) {
3037#if 0
3038 uint32_t mclk_cntl =
3039 RREG32_PLL
3040 (RADEON_MCLK_CNTL);
3041 mclk_cntl &= 0xffff0000;
3042 /*mclk_cntl |= 0x00001111;*//* ??? */
3043 WREG32_PLL(RADEON_MCLK_CNTL,
3044 mclk_cntl);
3045 udelay(10000);
3046#endif
3047 WREG32_PLL
3048 (RADEON_CLK_PWRMGT_CNTL,
3049 tmp &
3050 ~RADEON_CG_NO1_DEBUG_0);
3051 udelay(10000);
3052 }
3053 break;
3054 default:
3055 break;
3056 }
3057 break;
3058 default:
3059 break;
3060 }
3061 }
3062 }
3063}
3064
3065static void combios_parse_ram_reset_table(struct drm_device *dev,
3066 uint16_t offset)
3067{
3068 struct radeon_device *rdev = dev->dev_private;
3069 uint32_t tmp;
3070
3071 if (offset) {
3072 uint8_t val = RBIOS8(offset);
3073 while (val != 0xff) {
3074 offset++;
3075
3076 if (val == 0x0f) {
3077 uint32_t channel_complete_mask;
3078
3079 if (ASIC_IS_R300(rdev))
3080 channel_complete_mask =
3081 R300_MEM_PWRUP_COMPLETE;
3082 else
3083 channel_complete_mask =
3084 RADEON_MEM_PWRUP_COMPLETE;
3085 tmp = 20000;
3086 while (tmp--) {
3087 if ((RREG32(RADEON_MEM_STR_CNTL) &
3088 channel_complete_mask) ==
3089 channel_complete_mask)
3090 break;
3091 }
3092 } else {
3093 uint32_t or_mask = RBIOS16(offset);
3094 offset += 2;
3095
3096 tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
3097 tmp &= RADEON_SDRAM_MODE_MASK;
3098 tmp |= or_mask;
3099 WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
3100
3101 or_mask = val << 24;
3102 tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
3103 tmp &= RADEON_B3MEM_RESET_MASK;
3104 tmp |= or_mask;
3105 WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
3106 }
3107 val = RBIOS8(offset);
3108 }
3109 }
3110}
3111
3112static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
3113 int mem_addr_mapping)
3114{
3115 struct radeon_device *rdev = dev->dev_private;
3116 uint32_t mem_cntl;
3117 uint32_t mem_size;
3118 uint32_t addr = 0;
3119
3120 mem_cntl = RREG32(RADEON_MEM_CNTL);
3121 if (mem_cntl & RV100_HALF_MODE)
3122 ram /= 2;
3123 mem_size = ram;
3124 mem_cntl &= ~(0xff << 8);
3125 mem_cntl |= (mem_addr_mapping & 0xff) << 8;
3126 WREG32(RADEON_MEM_CNTL, mem_cntl);
3127 RREG32(RADEON_MEM_CNTL);
3128
3129 /* sdram reset ? */
3130
3131 /* something like this???? */
3132 while (ram--) {
3133 addr = ram * 1024 * 1024;
3134 /* write to each page */
3135 WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
3136 WREG32(RADEON_MM_DATA, 0xdeadbeef);
3137 /* read back and verify */
3138 WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
3139 if (RREG32(RADEON_MM_DATA) != 0xdeadbeef)
3140 return 0;
3141 }
3142
3143 return mem_size;
3144}
3145
3146static void combios_write_ram_size(struct drm_device *dev)
3147{
3148 struct radeon_device *rdev = dev->dev_private;
3149 uint8_t rev;
3150 uint16_t offset;
3151 uint32_t mem_size = 0;
3152 uint32_t mem_cntl = 0;
3153
3154 /* should do something smarter here I guess... */
3155 if (rdev->flags & RADEON_IS_IGP)
3156 return;
3157
3158 /* first check detected mem table */
3159 offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
3160 if (offset) {
3161 rev = RBIOS8(offset);
3162 if (rev < 3) {
3163 mem_cntl = RBIOS32(offset + 1);
3164 mem_size = RBIOS16(offset + 5);
Alex Deucher4ce91982010-06-30 12:13:55 -04003165 if ((rdev->family < CHIP_R200) &&
3166 !ASIC_IS_RN50(rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003167 WREG32(RADEON_MEM_CNTL, mem_cntl);
3168 }
3169 }
3170
3171 if (!mem_size) {
3172 offset =
3173 combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
3174 if (offset) {
3175 rev = RBIOS8(offset - 1);
3176 if (rev < 1) {
Alex Deucher4ce91982010-06-30 12:13:55 -04003177 if ((rdev->family < CHIP_R200)
3178 && !ASIC_IS_RN50(rdev)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003179 int ram = 0;
3180 int mem_addr_mapping = 0;
3181
3182 while (RBIOS8(offset)) {
3183 ram = RBIOS8(offset);
3184 mem_addr_mapping =
3185 RBIOS8(offset + 1);
3186 if (mem_addr_mapping != 0x25)
3187 ram *= 2;
3188 mem_size =
3189 combios_detect_ram(dev, ram,
3190 mem_addr_mapping);
3191 if (mem_size)
3192 break;
3193 offset += 2;
3194 }
3195 } else
3196 mem_size = RBIOS8(offset);
3197 } else {
3198 mem_size = RBIOS8(offset);
3199 mem_size *= 2; /* convert to MB */
3200 }
3201 }
3202 }
3203
3204 mem_size *= (1024 * 1024); /* convert to bytes */
3205 WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
3206}
3207
3208void radeon_combios_dyn_clk_setup(struct drm_device *dev, int enable)
3209{
3210 uint16_t dyn_clk_info =
3211 combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
3212
3213 if (dyn_clk_info)
3214 combios_parse_pll_table(dev, dyn_clk_info);
3215}
3216
3217void radeon_combios_asic_init(struct drm_device *dev)
3218{
3219 struct radeon_device *rdev = dev->dev_private;
3220 uint16_t table;
3221
3222 /* port hardcoded mac stuff from radeonfb */
3223 if (rdev->bios == NULL)
3224 return;
3225
3226 /* ASIC INIT 1 */
3227 table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
3228 if (table)
3229 combios_parse_mmio_table(dev, table);
3230
3231 /* PLL INIT */
3232 table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
3233 if (table)
3234 combios_parse_pll_table(dev, table);
3235
3236 /* ASIC INIT 2 */
3237 table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
3238 if (table)
3239 combios_parse_mmio_table(dev, table);
3240
3241 if (!(rdev->flags & RADEON_IS_IGP)) {
3242 /* ASIC INIT 4 */
3243 table =
3244 combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
3245 if (table)
3246 combios_parse_mmio_table(dev, table);
3247
3248 /* RAM RESET */
3249 table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
3250 if (table)
3251 combios_parse_ram_reset_table(dev, table);
3252
3253 /* ASIC INIT 3 */
3254 table =
3255 combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
3256 if (table)
3257 combios_parse_mmio_table(dev, table);
3258
3259 /* write CONFIG_MEMSIZE */
3260 combios_write_ram_size(dev);
3261 }
3262
Dave Airlie580b4ff2010-06-30 13:26:11 +10003263 /* quirk for rs4xx HP nx6125 laptop to make it resume
3264 * - it hangs on resume inside the dynclk 1 table.
3265 */
3266 if (rdev->family == CHIP_RS480 &&
3267 rdev->pdev->subsystem_vendor == 0x103c &&
3268 rdev->pdev->subsystem_device == 0x308b)
3269 return;
3270
Alex Deucher52fa2bb2010-07-21 23:54:35 -04003271 /* quirk for rs4xx HP dv5000 laptop to make it resume
3272 * - it hangs on resume inside the dynclk 1 table.
3273 */
3274 if (rdev->family == CHIP_RS480 &&
3275 rdev->pdev->subsystem_vendor == 0x103c &&
3276 rdev->pdev->subsystem_device == 0x30a4)
3277 return;
3278
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003279 /* DYN CLK 1 */
3280 table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
3281 if (table)
3282 combios_parse_pll_table(dev, table);
3283
3284}
3285
3286void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
3287{
3288 struct radeon_device *rdev = dev->dev_private;
3289 uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
3290
3291 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
3292 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3293 bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
3294
3295 /* let the bios control the backlight */
3296 bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
3297
3298 /* tell the bios not to handle mode switching */
3299 bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
3300 RADEON_ACC_MODE_CHANGE);
3301
3302 /* tell the bios a driver is loaded */
3303 bios_7_scratch |= RADEON_DRV_LOADED;
3304
3305 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
3306 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3307 WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
3308}
3309
3310void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
3311{
3312 struct drm_device *dev = encoder->dev;
3313 struct radeon_device *rdev = dev->dev_private;
3314 uint32_t bios_6_scratch;
3315
3316 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3317
3318 if (lock)
3319 bios_6_scratch |= RADEON_DRIVER_CRITICAL;
3320 else
3321 bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
3322
3323 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3324}
3325
3326void
3327radeon_combios_connected_scratch_regs(struct drm_connector *connector,
3328 struct drm_encoder *encoder,
3329 bool connected)
3330{
3331 struct drm_device *dev = connector->dev;
3332 struct radeon_device *rdev = dev->dev_private;
3333 struct radeon_connector *radeon_connector =
3334 to_radeon_connector(connector);
3335 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3336 uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
3337 uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
3338
3339 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
3340 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
3341 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003342 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003343 /* fix me */
3344 bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
3345 /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
3346 bios_5_scratch |= RADEON_TV1_ON;
3347 bios_5_scratch |= RADEON_ACC_REQ_TV1;
3348 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003349 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003350 bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
3351 bios_5_scratch &= ~RADEON_TV1_ON;
3352 bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
3353 }
3354 }
3355 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
3356 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
3357 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003358 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003359 bios_4_scratch |= RADEON_LCD1_ATTACHED;
3360 bios_5_scratch |= RADEON_LCD1_ON;
3361 bios_5_scratch |= RADEON_ACC_REQ_LCD1;
3362 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003363 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003364 bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
3365 bios_5_scratch &= ~RADEON_LCD1_ON;
3366 bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
3367 }
3368 }
3369 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
3370 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
3371 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003372 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003373 bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
3374 bios_5_scratch |= RADEON_CRT1_ON;
3375 bios_5_scratch |= RADEON_ACC_REQ_CRT1;
3376 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003377 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003378 bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
3379 bios_5_scratch &= ~RADEON_CRT1_ON;
3380 bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
3381 }
3382 }
3383 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
3384 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
3385 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003386 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003387 bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
3388 bios_5_scratch |= RADEON_CRT2_ON;
3389 bios_5_scratch |= RADEON_ACC_REQ_CRT2;
3390 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003391 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003392 bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
3393 bios_5_scratch &= ~RADEON_CRT2_ON;
3394 bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
3395 }
3396 }
3397 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
3398 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
3399 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003400 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003401 bios_4_scratch |= RADEON_DFP1_ATTACHED;
3402 bios_5_scratch |= RADEON_DFP1_ON;
3403 bios_5_scratch |= RADEON_ACC_REQ_DFP1;
3404 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003405 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003406 bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
3407 bios_5_scratch &= ~RADEON_DFP1_ON;
3408 bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
3409 }
3410 }
3411 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
3412 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
3413 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003414 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003415 bios_4_scratch |= RADEON_DFP2_ATTACHED;
3416 bios_5_scratch |= RADEON_DFP2_ON;
3417 bios_5_scratch |= RADEON_ACC_REQ_DFP2;
3418 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003419 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003420 bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
3421 bios_5_scratch &= ~RADEON_DFP2_ON;
3422 bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
3423 }
3424 }
3425 WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
3426 WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
3427}
3428
3429void
3430radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
3431{
3432 struct drm_device *dev = encoder->dev;
3433 struct radeon_device *rdev = dev->dev_private;
3434 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3435 uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
3436
3437 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
3438 bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
3439 bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
3440 }
3441 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3442 bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
3443 bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
3444 }
3445 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3446 bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
3447 bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
3448 }
3449 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3450 bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
3451 bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
3452 }
3453 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3454 bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
3455 bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
3456 }
3457 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3458 bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
3459 bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
3460 }
3461 WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
3462}
3463
3464void
3465radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
3466{
3467 struct drm_device *dev = encoder->dev;
3468 struct radeon_device *rdev = dev->dev_private;
3469 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3470 uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3471
3472 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
3473 if (on)
3474 bios_6_scratch |= RADEON_TV_DPMS_ON;
3475 else
3476 bios_6_scratch &= ~RADEON_TV_DPMS_ON;
3477 }
3478 if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
3479 if (on)
3480 bios_6_scratch |= RADEON_CRT_DPMS_ON;
3481 else
3482 bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
3483 }
3484 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
3485 if (on)
3486 bios_6_scratch |= RADEON_LCD_DPMS_ON;
3487 else
3488 bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
3489 }
3490 if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
3491 if (on)
3492 bios_6_scratch |= RADEON_DFP_DPMS_ON;
3493 else
3494 bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
3495 }
3496 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3497}