blob: cf602e2d0718ed21539dafd566405c77b3d9a4ac [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
508 * r1xx/r2xx
509 * DDC_MONID = RADEON_GPIO_MONID
510 * DDC_CRT2 = RADEON_GPIO_CRT2_DDC
511 * r3xx
512 * DDC_MONID = RADEON_GPIO_MONID
513 * DDC_CRT2 = RADEON_GPIO_DVI_DDC
514 * rs3xx/rs4xx
515 * DDC_MONID = RADEON_GPIOPAD_MASK
516 * DDC_CRT2 = RADEON_GPIO_MONID
517 */
518 switch (ddc) {
519 case DDC_NONE_DETECTED:
520 default:
521 ddc_line = 0;
522 break;
523 case DDC_DVI:
524 ddc_line = RADEON_GPIO_DVI_DDC;
525 break;
526 case DDC_VGA:
527 ddc_line = RADEON_GPIO_VGA_DDC;
528 break;
529 case DDC_LCD:
530 ddc_line = RADEON_GPIOPAD_MASK;
531 break;
532 case DDC_GPIO:
533 ddc_line = RADEON_MDGPIO_MASK;
534 break;
535 case DDC_MONID:
536 if (rdev->family == CHIP_RS300 ||
537 rdev->family == CHIP_RS400 ||
538 rdev->family == CHIP_RS480)
539 ddc_line = RADEON_GPIOPAD_MASK;
540 else
541 ddc_line = RADEON_GPIO_MONID;
542 break;
543 case DDC_CRT2:
544 if (rdev->family == CHIP_RS300 ||
545 rdev->family == CHIP_RS400 ||
546 rdev->family == CHIP_RS480)
547 ddc_line = RADEON_GPIO_MONID;
548 else if (rdev->family >= CHIP_R300) {
549 ddc_line = RADEON_GPIO_DVI_DDC;
550 ddc = DDC_DVI;
551 } else
552 ddc_line = RADEON_GPIO_CRT2_DDC;
553 break;
554 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200555
Alex Deucher6a93cb22009-11-23 17:39:28 -0500556 if (ddc_line == RADEON_GPIOPAD_MASK) {
557 i2c.mask_clk_reg = RADEON_GPIOPAD_MASK;
558 i2c.mask_data_reg = RADEON_GPIOPAD_MASK;
559 i2c.a_clk_reg = RADEON_GPIOPAD_A;
560 i2c.a_data_reg = RADEON_GPIOPAD_A;
561 i2c.en_clk_reg = RADEON_GPIOPAD_EN;
562 i2c.en_data_reg = RADEON_GPIOPAD_EN;
563 i2c.y_clk_reg = RADEON_GPIOPAD_Y;
564 i2c.y_data_reg = RADEON_GPIOPAD_Y;
565 } else if (ddc_line == RADEON_MDGPIO_MASK) {
566 i2c.mask_clk_reg = RADEON_MDGPIO_MASK;
567 i2c.mask_data_reg = RADEON_MDGPIO_MASK;
568 i2c.a_clk_reg = RADEON_MDGPIO_A;
569 i2c.a_data_reg = RADEON_MDGPIO_A;
570 i2c.en_clk_reg = RADEON_MDGPIO_EN;
571 i2c.en_data_reg = RADEON_MDGPIO_EN;
572 i2c.y_clk_reg = RADEON_MDGPIO_Y;
573 i2c.y_data_reg = RADEON_MDGPIO_Y;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200574 } else {
575 i2c.mask_clk_reg = ddc_line;
576 i2c.mask_data_reg = ddc_line;
577 i2c.a_clk_reg = ddc_line;
578 i2c.a_data_reg = ddc_line;
Alex Deucher9b9fe722009-11-10 15:59:44 -0500579 i2c.en_clk_reg = ddc_line;
580 i2c.en_data_reg = ddc_line;
581 i2c.y_clk_reg = ddc_line;
582 i2c.y_data_reg = ddc_line;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200583 }
584
Alex Deucher179e8072010-08-05 21:21:17 -0400585 if (clk_mask && data_mask) {
Alex Deucherbe663052010-11-18 17:18:08 -0500586 /* system specific masks */
Alex Deucher179e8072010-08-05 21:21:17 -0400587 i2c.mask_clk_mask = clk_mask;
588 i2c.mask_data_mask = data_mask;
589 i2c.a_clk_mask = clk_mask;
590 i2c.a_data_mask = data_mask;
591 i2c.en_clk_mask = clk_mask;
592 i2c.en_data_mask = data_mask;
593 i2c.y_clk_mask = clk_mask;
594 i2c.y_data_mask = data_mask;
Alex Deucherbe663052010-11-18 17:18:08 -0500595 } else if ((ddc_line == RADEON_GPIOPAD_MASK) ||
596 (ddc_line == RADEON_MDGPIO_MASK)) {
597 /* default gpiopad masks */
598 i2c.mask_clk_mask = (0x20 << 8);
599 i2c.mask_data_mask = 0x80;
600 i2c.a_clk_mask = (0x20 << 8);
601 i2c.a_data_mask = 0x80;
602 i2c.en_clk_mask = (0x20 << 8);
603 i2c.en_data_mask = 0x80;
604 i2c.y_clk_mask = (0x20 << 8);
605 i2c.y_data_mask = 0x80;
Alex Deucher179e8072010-08-05 21:21:17 -0400606 } else {
Alex Deucherbe663052010-11-18 17:18:08 -0500607 /* default masks for ddc pads */
Alex Deucher179e8072010-08-05 21:21:17 -0400608 i2c.mask_clk_mask = RADEON_GPIO_EN_1;
609 i2c.mask_data_mask = RADEON_GPIO_EN_0;
610 i2c.a_clk_mask = RADEON_GPIO_A_1;
611 i2c.a_data_mask = RADEON_GPIO_A_0;
612 i2c.en_clk_mask = RADEON_GPIO_EN_1;
613 i2c.en_data_mask = RADEON_GPIO_EN_0;
614 i2c.y_clk_mask = RADEON_GPIO_Y_1;
615 i2c.y_data_mask = RADEON_GPIO_Y_0;
616 }
617
Alex Deucher40bacf12009-12-23 03:23:21 -0500618 switch (rdev->family) {
619 case CHIP_R100:
620 case CHIP_RV100:
621 case CHIP_RS100:
622 case CHIP_RV200:
623 case CHIP_RS200:
624 case CHIP_RS300:
625 switch (ddc_line) {
626 case RADEON_GPIO_DVI_DDC:
Alex Deucherb28ea412010-03-12 13:30:49 -0500627 i2c.hw_capable = true;
Alex Deucher40bacf12009-12-23 03:23:21 -0500628 break;
629 default:
630 i2c.hw_capable = false;
631 break;
632 }
633 break;
634 case CHIP_R200:
635 switch (ddc_line) {
636 case RADEON_GPIO_DVI_DDC:
637 case RADEON_GPIO_MONID:
638 i2c.hw_capable = true;
639 break;
640 default:
641 i2c.hw_capable = false;
642 break;
643 }
644 break;
645 case CHIP_RV250:
646 case CHIP_RV280:
647 switch (ddc_line) {
648 case RADEON_GPIO_VGA_DDC:
649 case RADEON_GPIO_DVI_DDC:
650 case RADEON_GPIO_CRT2_DDC:
651 i2c.hw_capable = true;
652 break;
653 default:
654 i2c.hw_capable = false;
655 break;
656 }
657 break;
658 case CHIP_R300:
659 case CHIP_R350:
660 switch (ddc_line) {
661 case RADEON_GPIO_VGA_DDC:
662 case RADEON_GPIO_DVI_DDC:
663 i2c.hw_capable = true;
664 break;
665 default:
666 i2c.hw_capable = false;
667 break;
668 }
669 break;
670 case CHIP_RV350:
671 case CHIP_RV380:
672 case CHIP_RS400:
673 case CHIP_RS480:
Alex Deucher6a93cb22009-11-23 17:39:28 -0500674 switch (ddc_line) {
675 case RADEON_GPIO_VGA_DDC:
676 case RADEON_GPIO_DVI_DDC:
677 i2c.hw_capable = true;
678 break;
679 case RADEON_GPIO_MONID:
680 /* hw i2c on RADEON_GPIO_MONID doesn't seem to work
681 * reliably on some pre-r4xx hardware; not sure why.
682 */
683 i2c.hw_capable = false;
684 break;
685 default:
686 i2c.hw_capable = false;
687 break;
688 }
Alex Deucher40bacf12009-12-23 03:23:21 -0500689 break;
690 default:
691 i2c.hw_capable = false;
692 break;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500693 }
694 i2c.mm_i2c = false;
Alex Deucherf376b942010-08-05 21:21:16 -0400695
Alex Deucher179e8072010-08-05 21:21:17 -0400696 i2c.i2c_id = ddc;
Alex Deucher8e36ed02010-05-18 19:26:47 -0400697 i2c.hpd = RADEON_HPD_NONE;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500698
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200699 if (ddc_line)
700 i2c.valid = true;
701 else
702 i2c.valid = false;
703
704 return i2c;
705}
706
Alex Deucherf376b942010-08-05 21:21:16 -0400707void radeon_combios_i2c_init(struct radeon_device *rdev)
708{
709 struct drm_device *dev = rdev->ddev;
710 struct radeon_i2c_bus_rec i2c;
711
Alex Deucherf376b942010-08-05 21:21:16 -0400712
Alex Deucher179e8072010-08-05 21:21:17 -0400713 i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
714 rdev->i2c_bus[0] = radeon_i2c_create(dev, &i2c, "DVI_DDC");
Alex Deucherf376b942010-08-05 21:21:16 -0400715
Alex Deucher179e8072010-08-05 21:21:17 -0400716 i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
717 rdev->i2c_bus[1] = radeon_i2c_create(dev, &i2c, "VGA_DDC");
Alex Deucherf376b942010-08-05 21:21:16 -0400718
719 i2c.valid = true;
720 i2c.hw_capable = true;
721 i2c.mm_i2c = true;
Alex Deucher179e8072010-08-05 21:21:17 -0400722 i2c.i2c_id = 0xa0;
723 rdev->i2c_bus[2] = radeon_i2c_create(dev, &i2c, "MM_I2C");
724
725 if (rdev->family == CHIP_RS300 ||
726 rdev->family == CHIP_RS400 ||
727 rdev->family == CHIP_RS480) {
728 u16 offset;
729 u8 id, blocks, clk, data;
730 int i;
731
732 i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
733 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
734
735 offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE);
736 if (offset) {
737 blocks = RBIOS8(offset + 2);
738 for (i = 0; i < blocks; i++) {
739 id = RBIOS8(offset + 3 + (i * 5) + 0);
740 if (id == 136) {
741 clk = RBIOS8(offset + 3 + (i * 5) + 3);
742 data = RBIOS8(offset + 3 + (i * 5) + 4);
743 i2c = combios_setup_i2c_bus(rdev, DDC_MONID,
Alex Deucher791cfe22010-11-21 10:58:05 -0500744 (1 << clk), (1 << data));
Alex Deucher179e8072010-08-05 21:21:17 -0400745 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "GPIOPAD_MASK");
746 break;
747 }
748 }
749 }
750
751 } else if (rdev->family >= CHIP_R300) {
752 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
753 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
754 } else {
755 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
756 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
757
758 i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
759 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "CRT2_DDC");
760 }
Alex Deucherf376b942010-08-05 21:21:16 -0400761}
762
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200763bool radeon_combios_get_clock_info(struct drm_device *dev)
764{
765 struct radeon_device *rdev = dev->dev_private;
766 uint16_t pll_info;
767 struct radeon_pll *p1pll = &rdev->clock.p1pll;
768 struct radeon_pll *p2pll = &rdev->clock.p2pll;
769 struct radeon_pll *spll = &rdev->clock.spll;
770 struct radeon_pll *mpll = &rdev->clock.mpll;
771 int8_t rev;
772 uint16_t sclk, mclk;
773
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200774 pll_info = combios_get_table_offset(dev, COMBIOS_PLL_INFO_TABLE);
775 if (pll_info) {
776 rev = RBIOS8(pll_info);
777
778 /* pixel clocks */
779 p1pll->reference_freq = RBIOS16(pll_info + 0xe);
780 p1pll->reference_div = RBIOS16(pll_info + 0x10);
781 p1pll->pll_out_min = RBIOS32(pll_info + 0x12);
782 p1pll->pll_out_max = RBIOS32(pll_info + 0x16);
Alex Deucher86cb2bb2010-03-08 12:55:16 -0500783 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
784 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200785
786 if (rev > 9) {
787 p1pll->pll_in_min = RBIOS32(pll_info + 0x36);
788 p1pll->pll_in_max = RBIOS32(pll_info + 0x3a);
789 } else {
790 p1pll->pll_in_min = 40;
791 p1pll->pll_in_max = 500;
792 }
793 *p2pll = *p1pll;
794
795 /* system clock */
796 spll->reference_freq = RBIOS16(pll_info + 0x1a);
797 spll->reference_div = RBIOS16(pll_info + 0x1c);
798 spll->pll_out_min = RBIOS32(pll_info + 0x1e);
799 spll->pll_out_max = RBIOS32(pll_info + 0x22);
800
801 if (rev > 10) {
802 spll->pll_in_min = RBIOS32(pll_info + 0x48);
803 spll->pll_in_max = RBIOS32(pll_info + 0x4c);
804 } else {
805 /* ??? */
806 spll->pll_in_min = 40;
807 spll->pll_in_max = 500;
808 }
809
810 /* memory clock */
811 mpll->reference_freq = RBIOS16(pll_info + 0x26);
812 mpll->reference_div = RBIOS16(pll_info + 0x28);
813 mpll->pll_out_min = RBIOS32(pll_info + 0x2a);
814 mpll->pll_out_max = RBIOS32(pll_info + 0x2e);
815
816 if (rev > 10) {
817 mpll->pll_in_min = RBIOS32(pll_info + 0x5a);
818 mpll->pll_in_max = RBIOS32(pll_info + 0x5e);
819 } else {
820 /* ??? */
821 mpll->pll_in_min = 40;
822 mpll->pll_in_max = 500;
823 }
824
825 /* default sclk/mclk */
826 sclk = RBIOS16(pll_info + 0xa);
827 mclk = RBIOS16(pll_info + 0x8);
828 if (sclk == 0)
829 sclk = 200 * 100;
830 if (mclk == 0)
831 mclk = 200 * 100;
832
833 rdev->clock.default_sclk = sclk;
834 rdev->clock.default_mclk = mclk;
835
836 return true;
837 }
838 return false;
839}
840
Alex Deucher06b64762010-01-05 11:27:29 -0500841bool radeon_combios_sideport_present(struct radeon_device *rdev)
842{
843 struct drm_device *dev = rdev->ddev;
844 u16 igp_info;
845
Alex Deucher4c70b2e2010-08-02 19:39:15 -0400846 /* sideport is AMD only */
847 if (rdev->family == CHIP_RS400)
848 return false;
849
Alex Deucher06b64762010-01-05 11:27:29 -0500850 igp_info = combios_get_table_offset(dev, COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE);
851
852 if (igp_info) {
853 if (RBIOS16(igp_info + 0x4))
854 return true;
855 }
856 return false;
857}
858
Alex Deucher246263c2009-12-29 12:09:17 -0500859static const uint32_t default_primarydac_adj[CHIP_LAST] = {
860 0x00000808, /* r100 */
861 0x00000808, /* rv100 */
862 0x00000808, /* rs100 */
863 0x00000808, /* rv200 */
864 0x00000808, /* rs200 */
865 0x00000808, /* r200 */
866 0x00000808, /* rv250 */
867 0x00000000, /* rs300 */
868 0x00000808, /* rv280 */
869 0x00000808, /* r300 */
870 0x00000808, /* r350 */
871 0x00000808, /* rv350 */
872 0x00000808, /* rv380 */
873 0x00000808, /* r420 */
874 0x00000808, /* r423 */
875 0x00000808, /* rv410 */
876 0x00000000, /* rs400 */
877 0x00000000, /* rs480 */
878};
879
880static void radeon_legacy_get_primary_dac_info_from_table(struct radeon_device *rdev,
881 struct radeon_encoder_primary_dac *p_dac)
882{
883 p_dac->ps2_pdac_adj = default_primarydac_adj[rdev->family];
884 return;
885}
886
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200887struct radeon_encoder_primary_dac *radeon_combios_get_primary_dac_info(struct
888 radeon_encoder
889 *encoder)
890{
891 struct drm_device *dev = encoder->base.dev;
892 struct radeon_device *rdev = dev->dev_private;
893 uint16_t dac_info;
894 uint8_t rev, bg, dac;
895 struct radeon_encoder_primary_dac *p_dac = NULL;
Alex Deucher246263c2009-12-29 12:09:17 -0500896 int found = 0;
897
898 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac),
899 GFP_KERNEL);
900
901 if (!p_dac)
902 return NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200903
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200904 /* check CRT table */
905 dac_info = combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
906 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200907 rev = RBIOS8(dac_info) & 0x3;
908 if (rev < 2) {
909 bg = RBIOS8(dac_info + 0x2) & 0xf;
910 dac = (RBIOS8(dac_info + 0x2) >> 4) & 0xf;
911 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
912 } else {
913 bg = RBIOS8(dac_info + 0x2) & 0xf;
914 dac = RBIOS8(dac_info + 0x3) & 0xf;
915 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
916 }
Alex Deucher3a89b4a2010-04-06 12:35:26 -0400917 /* if the values are all zeros, use the table */
918 if (p_dac->ps2_pdac_adj)
919 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200920 }
921
Alex Deucher246263c2009-12-29 12:09:17 -0500922 if (!found) /* fallback to defaults */
923 radeon_legacy_get_primary_dac_info_from_table(rdev, p_dac);
924
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200925 return p_dac;
926}
927
Alex Deucherd79766f2009-12-17 19:00:29 -0500928enum radeon_tv_std
929radeon_combios_get_tv_info(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200930{
Alex Deucherd79766f2009-12-17 19:00:29 -0500931 struct drm_device *dev = rdev->ddev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200932 uint16_t tv_info;
933 enum radeon_tv_std tv_std = TV_STD_NTSC;
934
935 tv_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
936 if (tv_info) {
937 if (RBIOS8(tv_info + 6) == 'T') {
938 switch (RBIOS8(tv_info + 7) & 0xf) {
939 case 1:
940 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -0400941 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200942 break;
943 case 2:
944 tv_std = TV_STD_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -0400945 DRM_DEBUG_KMS("Default TV standard: PAL\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200946 break;
947 case 3:
948 tv_std = TV_STD_PAL_M;
Alex Deucher40f76d82010-10-07 22:38:42 -0400949 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200950 break;
951 case 4:
952 tv_std = TV_STD_PAL_60;
Alex Deucher40f76d82010-10-07 22:38:42 -0400953 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200954 break;
955 case 5:
956 tv_std = TV_STD_NTSC_J;
Alex Deucher40f76d82010-10-07 22:38:42 -0400957 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200958 break;
959 case 6:
960 tv_std = TV_STD_SCART_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -0400961 DRM_DEBUG_KMS("Default TV standard: SCART-PAL\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200962 break;
963 default:
964 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -0400965 DRM_DEBUG_KMS
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200966 ("Unknown TV standard; defaulting to NTSC\n");
967 break;
968 }
969
970 switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) {
971 case 0:
Alex Deucher40f76d82010-10-07 22:38:42 -0400972 DRM_DEBUG_KMS("29.498928713 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200973 break;
974 case 1:
Alex Deucher40f76d82010-10-07 22:38:42 -0400975 DRM_DEBUG_KMS("28.636360000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200976 break;
977 case 2:
Alex Deucher40f76d82010-10-07 22:38:42 -0400978 DRM_DEBUG_KMS("14.318180000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200979 break;
980 case 3:
Alex Deucher40f76d82010-10-07 22:38:42 -0400981 DRM_DEBUG_KMS("27.000000000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200982 break;
983 default:
984 break;
985 }
986 }
987 }
988 return tv_std;
989}
990
991static const uint32_t default_tvdac_adj[CHIP_LAST] = {
992 0x00000000, /* r100 */
993 0x00280000, /* rv100 */
994 0x00000000, /* rs100 */
995 0x00880000, /* rv200 */
996 0x00000000, /* rs200 */
997 0x00000000, /* r200 */
998 0x00770000, /* rv250 */
999 0x00290000, /* rs300 */
1000 0x00560000, /* rv280 */
1001 0x00780000, /* r300 */
1002 0x00770000, /* r350 */
1003 0x00780000, /* rv350 */
1004 0x00780000, /* rv380 */
1005 0x01080000, /* r420 */
1006 0x01080000, /* r423 */
1007 0x01080000, /* rv410 */
1008 0x00780000, /* rs400 */
1009 0x00780000, /* rs480 */
1010};
1011
Dave Airlie6a719e02009-08-17 10:19:51 +10001012static void radeon_legacy_get_tv_dac_info_from_table(struct radeon_device *rdev,
1013 struct radeon_encoder_tv_dac *tv_dac)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001014{
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001015 tv_dac->ps2_tvdac_adj = default_tvdac_adj[rdev->family];
1016 if ((rdev->flags & RADEON_IS_MOBILITY) && (rdev->family == CHIP_RV250))
1017 tv_dac->ps2_tvdac_adj = 0x00880000;
1018 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1019 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Dave Airlie6a719e02009-08-17 10:19:51 +10001020 return;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001021}
1022
1023struct radeon_encoder_tv_dac *radeon_combios_get_tv_dac_info(struct
1024 radeon_encoder
1025 *encoder)
1026{
1027 struct drm_device *dev = encoder->base.dev;
1028 struct radeon_device *rdev = dev->dev_private;
1029 uint16_t dac_info;
1030 uint8_t rev, bg, dac;
1031 struct radeon_encoder_tv_dac *tv_dac = NULL;
Dave Airlie6a719e02009-08-17 10:19:51 +10001032 int found = 0;
1033
1034 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1035 if (!tv_dac)
1036 return NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001037
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001038 /* first check TV table */
1039 dac_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
1040 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001041 rev = RBIOS8(dac_info + 0x3);
1042 if (rev > 4) {
1043 bg = RBIOS8(dac_info + 0xc) & 0xf;
1044 dac = RBIOS8(dac_info + 0xd) & 0xf;
1045 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1046
1047 bg = RBIOS8(dac_info + 0xe) & 0xf;
1048 dac = RBIOS8(dac_info + 0xf) & 0xf;
1049 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1050
1051 bg = RBIOS8(dac_info + 0x10) & 0xf;
1052 dac = RBIOS8(dac_info + 0x11) & 0xf;
1053 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001054 /* if the values are all zeros, use the table */
1055 if (tv_dac->ps2_tvdac_adj)
1056 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001057 } else if (rev > 1) {
1058 bg = RBIOS8(dac_info + 0xc) & 0xf;
1059 dac = (RBIOS8(dac_info + 0xc) >> 4) & 0xf;
1060 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1061
1062 bg = RBIOS8(dac_info + 0xd) & 0xf;
1063 dac = (RBIOS8(dac_info + 0xd) >> 4) & 0xf;
1064 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1065
1066 bg = RBIOS8(dac_info + 0xe) & 0xf;
1067 dac = (RBIOS8(dac_info + 0xe) >> 4) & 0xf;
1068 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001069 /* if the values are all zeros, use the table */
1070 if (tv_dac->ps2_tvdac_adj)
1071 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001072 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001073 tv_dac->tv_std = radeon_combios_get_tv_info(rdev);
Dave Airlie6a719e02009-08-17 10:19:51 +10001074 }
1075 if (!found) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001076 /* then check CRT table */
1077 dac_info =
1078 combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
1079 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001080 rev = RBIOS8(dac_info) & 0x3;
1081 if (rev < 2) {
1082 bg = RBIOS8(dac_info + 0x3) & 0xf;
1083 dac = (RBIOS8(dac_info + 0x3) >> 4) & 0xf;
1084 tv_dac->ps2_tvdac_adj =
1085 (bg << 16) | (dac << 20);
1086 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1087 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001088 /* if the values are all zeros, use the table */
1089 if (tv_dac->ps2_tvdac_adj)
1090 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001091 } else {
1092 bg = RBIOS8(dac_info + 0x4) & 0xf;
1093 dac = RBIOS8(dac_info + 0x5) & 0xf;
1094 tv_dac->ps2_tvdac_adj =
1095 (bg << 16) | (dac << 20);
1096 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1097 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001098 /* if the values are all zeros, use the table */
1099 if (tv_dac->ps2_tvdac_adj)
1100 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001101 }
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001102 } else {
1103 DRM_INFO("No TV DAC info found in BIOS\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001104 }
1105 }
1106
Dave Airlie6a719e02009-08-17 10:19:51 +10001107 if (!found) /* fallback to defaults */
1108 radeon_legacy_get_tv_dac_info_from_table(rdev, tv_dac);
1109
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001110 return tv_dac;
1111}
1112
1113static struct radeon_encoder_lvds *radeon_legacy_get_lvds_info_from_regs(struct
1114 radeon_device
1115 *rdev)
1116{
1117 struct radeon_encoder_lvds *lvds = NULL;
1118 uint32_t fp_vert_stretch, fp_horz_stretch;
1119 uint32_t ppll_div_sel, ppll_val;
Michel Dänzer8b5c7442009-06-17 18:28:38 +02001120 uint32_t lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001121
1122 lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
1123
1124 if (!lvds)
1125 return NULL;
1126
1127 fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH);
1128 fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH);
1129
Michel Dänzer8b5c7442009-06-17 18:28:38 +02001130 /* These should be fail-safe defaults, fingers crossed */
1131 lvds->panel_pwr_delay = 200;
1132 lvds->panel_vcc_delay = 2000;
1133
1134 lvds->lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
1135 lvds->panel_digon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) & 0xf;
1136 lvds->panel_blon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY2_SHIFT) & 0xf;
1137
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001138 if (fp_vert_stretch & RADEON_VERT_STRETCH_ENABLE)
Alex Deucherde2103e2009-10-09 15:14:30 -04001139 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001140 ((fp_vert_stretch & RADEON_VERT_PANEL_SIZE) >>
1141 RADEON_VERT_PANEL_SHIFT) + 1;
1142 else
Alex Deucherde2103e2009-10-09 15:14:30 -04001143 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001144 (RREG32(RADEON_CRTC_V_TOTAL_DISP) >> 16) + 1;
1145
1146 if (fp_horz_stretch & RADEON_HORZ_STRETCH_ENABLE)
Alex Deucherde2103e2009-10-09 15:14:30 -04001147 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001148 (((fp_horz_stretch & RADEON_HORZ_PANEL_SIZE) >>
1149 RADEON_HORZ_PANEL_SHIFT) + 1) * 8;
1150 else
Alex Deucherde2103e2009-10-09 15:14:30 -04001151 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001152 ((RREG32(RADEON_CRTC_H_TOTAL_DISP) >> 16) + 1) * 8;
1153
Alex Deucherde2103e2009-10-09 15:14:30 -04001154 if ((lvds->native_mode.hdisplay < 640) ||
1155 (lvds->native_mode.vdisplay < 480)) {
1156 lvds->native_mode.hdisplay = 640;
1157 lvds->native_mode.vdisplay = 480;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001158 }
1159
1160 ppll_div_sel = RREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3;
1161 ppll_val = RREG32_PLL(RADEON_PPLL_DIV_0 + ppll_div_sel);
1162 if ((ppll_val & 0x000707ff) == 0x1bb)
1163 lvds->use_bios_dividers = false;
1164 else {
1165 lvds->panel_ref_divider =
1166 RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
1167 lvds->panel_post_divider = (ppll_val >> 16) & 0x7;
1168 lvds->panel_fb_divider = ppll_val & 0x7ff;
1169
1170 if ((lvds->panel_ref_divider != 0) &&
1171 (lvds->panel_fb_divider > 3))
1172 lvds->use_bios_dividers = true;
1173 }
1174 lvds->panel_vcc_delay = 200;
1175
1176 DRM_INFO("Panel info derived from registers\n");
Alex Deucherde2103e2009-10-09 15:14:30 -04001177 DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
1178 lvds->native_mode.vdisplay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001179
1180 return lvds;
1181}
1182
1183struct radeon_encoder_lvds *radeon_combios_get_lvds_info(struct radeon_encoder
1184 *encoder)
1185{
1186 struct drm_device *dev = encoder->base.dev;
1187 struct radeon_device *rdev = dev->dev_private;
1188 uint16_t lcd_info;
1189 uint32_t panel_setup;
1190 char stmp[30];
1191 int tmp, i;
1192 struct radeon_encoder_lvds *lvds = NULL;
1193
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001194 lcd_info = combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
1195
1196 if (lcd_info) {
1197 lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
1198
1199 if (!lvds)
1200 return NULL;
1201
1202 for (i = 0; i < 24; i++)
1203 stmp[i] = RBIOS8(lcd_info + i + 1);
1204 stmp[24] = 0;
1205
1206 DRM_INFO("Panel ID String: %s\n", stmp);
1207
Alex Deucherde2103e2009-10-09 15:14:30 -04001208 lvds->native_mode.hdisplay = RBIOS16(lcd_info + 0x19);
1209 lvds->native_mode.vdisplay = RBIOS16(lcd_info + 0x1b);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001210
Alex Deucherde2103e2009-10-09 15:14:30 -04001211 DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
1212 lvds->native_mode.vdisplay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001213
1214 lvds->panel_vcc_delay = RBIOS16(lcd_info + 0x2c);
Andrew Morton94cf6432010-02-02 14:40:29 -08001215 lvds->panel_vcc_delay = min_t(u16, lvds->panel_vcc_delay, 2000);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001216
1217 lvds->panel_pwr_delay = RBIOS8(lcd_info + 0x24);
1218 lvds->panel_digon_delay = RBIOS16(lcd_info + 0x38) & 0xf;
1219 lvds->panel_blon_delay = (RBIOS16(lcd_info + 0x38) >> 4) & 0xf;
1220
1221 lvds->panel_ref_divider = RBIOS16(lcd_info + 0x2e);
1222 lvds->panel_post_divider = RBIOS8(lcd_info + 0x30);
1223 lvds->panel_fb_divider = RBIOS16(lcd_info + 0x31);
1224 if ((lvds->panel_ref_divider != 0) &&
1225 (lvds->panel_fb_divider > 3))
1226 lvds->use_bios_dividers = true;
1227
1228 panel_setup = RBIOS32(lcd_info + 0x39);
1229 lvds->lvds_gen_cntl = 0xff00;
1230 if (panel_setup & 0x1)
1231 lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_FORMAT;
1232
1233 if ((panel_setup >> 4) & 0x1)
1234 lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_TYPE;
1235
1236 switch ((panel_setup >> 8) & 0x7) {
1237 case 0:
1238 lvds->lvds_gen_cntl |= RADEON_LVDS_NO_FM;
1239 break;
1240 case 1:
1241 lvds->lvds_gen_cntl |= RADEON_LVDS_2_GREY;
1242 break;
1243 case 2:
1244 lvds->lvds_gen_cntl |= RADEON_LVDS_4_GREY;
1245 break;
1246 default:
1247 break;
1248 }
1249
1250 if ((panel_setup >> 16) & 0x1)
1251 lvds->lvds_gen_cntl |= RADEON_LVDS_FP_POL_LOW;
1252
1253 if ((panel_setup >> 17) & 0x1)
1254 lvds->lvds_gen_cntl |= RADEON_LVDS_LP_POL_LOW;
1255
1256 if ((panel_setup >> 18) & 0x1)
1257 lvds->lvds_gen_cntl |= RADEON_LVDS_DTM_POL_LOW;
1258
1259 if ((panel_setup >> 23) & 0x1)
1260 lvds->lvds_gen_cntl |= RADEON_LVDS_BL_CLK_SEL;
1261
1262 lvds->lvds_gen_cntl |= (panel_setup & 0xf0000000);
1263
1264 for (i = 0; i < 32; i++) {
1265 tmp = RBIOS16(lcd_info + 64 + i * 2);
1266 if (tmp == 0)
1267 break;
1268
Alex Deucherde2103e2009-10-09 15:14:30 -04001269 if ((RBIOS16(tmp) == lvds->native_mode.hdisplay) &&
Alex Deucher68b61a72010-05-18 00:30:05 -04001270 (RBIOS16(tmp + 2) == lvds->native_mode.vdisplay)) {
1271 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1272 (RBIOS16(tmp + 17) - RBIOS16(tmp + 19)) * 8;
1273 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1274 (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) - 1) * 8;
1275 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1276 (RBIOS8(tmp + 23) * 8);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001277
Alex Deucher68b61a72010-05-18 00:30:05 -04001278 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1279 (RBIOS16(tmp + 24) - RBIOS16(tmp + 26));
1280 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1281 ((RBIOS16(tmp + 28) & 0x7ff) - RBIOS16(tmp + 26));
1282 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1283 ((RBIOS16(tmp + 28) & 0xf800) >> 11);
Alex Deucherde2103e2009-10-09 15:14:30 -04001284
1285 lvds->native_mode.clock = RBIOS16(tmp + 9) * 10;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001286 lvds->native_mode.flags = 0;
Alex Deucherde2103e2009-10-09 15:14:30 -04001287 /* set crtc values */
1288 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
1289
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001290 }
1291 }
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001292 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001293 DRM_INFO("No panel info found in BIOS\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +02001294 lvds = radeon_legacy_get_lvds_info_from_regs(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001295 }
Michel Dänzer03047cd2010-02-10 11:05:11 +01001296
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +02001297 if (lvds)
1298 encoder->native_mode = lvds->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001299 return lvds;
1300}
1301
1302static const struct radeon_tmds_pll default_tmds_pll[CHIP_LAST][4] = {
1303 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R100 */
1304 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV100 */
1305 {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS100 */
1306 {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV200 */
1307 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RS200 */
1308 {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R200 */
1309 {{15500, 0x81b}, {0xffffffff, 0x83f}, {0, 0}, {0, 0}}, /* CHIP_RV250 */
1310 {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS300 */
1311 {{13000, 0x400f4}, {15000, 0x400f7}, {0xffffffff, 0x40111}, {0, 0}}, /* CHIP_RV280 */
1312 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R300 */
1313 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R350 */
1314 {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV350 */
1315 {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV380 */
1316 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R420 */
1317 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R423 */
1318 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RV410 */
Alex Deucherfcec5702009-11-10 21:25:07 -05001319 { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS400 */
1320 { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS480 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001321};
1322
Dave Airlie445282d2009-09-09 17:40:54 +10001323bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
1324 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001325{
Dave Airlie445282d2009-09-09 17:40:54 +10001326 struct drm_device *dev = encoder->base.dev;
1327 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001328 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001329
1330 for (i = 0; i < 4; i++) {
1331 tmds->tmds_pll[i].value =
Dave Airlie445282d2009-09-09 17:40:54 +10001332 default_tmds_pll[rdev->family][i].value;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001333 tmds->tmds_pll[i].freq = default_tmds_pll[rdev->family][i].freq;
1334 }
1335
Dave Airlie445282d2009-09-09 17:40:54 +10001336 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001337}
1338
Dave Airlie445282d2009-09-09 17:40:54 +10001339bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
1340 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001341{
1342 struct drm_device *dev = encoder->base.dev;
1343 struct radeon_device *rdev = dev->dev_private;
1344 uint16_t tmds_info;
1345 int i, n;
1346 uint8_t ver;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001347
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001348 tmds_info = combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
1349
1350 if (tmds_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001351 ver = RBIOS8(tmds_info);
Alex Deucher40f76d82010-10-07 22:38:42 -04001352 DRM_DEBUG_KMS("DFP table revision: %d\n", ver);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001353 if (ver == 3) {
1354 n = RBIOS8(tmds_info + 5) + 1;
1355 if (n > 4)
1356 n = 4;
1357 for (i = 0; i < n; i++) {
1358 tmds->tmds_pll[i].value =
1359 RBIOS32(tmds_info + i * 10 + 0x08);
1360 tmds->tmds_pll[i].freq =
1361 RBIOS16(tmds_info + i * 10 + 0x10);
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001362 DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001363 tmds->tmds_pll[i].freq,
1364 tmds->tmds_pll[i].value);
1365 }
1366 } else if (ver == 4) {
1367 int stride = 0;
1368 n = RBIOS8(tmds_info + 5) + 1;
1369 if (n > 4)
1370 n = 4;
1371 for (i = 0; i < n; i++) {
1372 tmds->tmds_pll[i].value =
1373 RBIOS32(tmds_info + stride + 0x08);
1374 tmds->tmds_pll[i].freq =
1375 RBIOS16(tmds_info + stride + 0x10);
1376 if (i == 0)
1377 stride += 10;
1378 else
1379 stride += 6;
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001380 DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001381 tmds->tmds_pll[i].freq,
1382 tmds->tmds_pll[i].value);
1383 }
1384 }
Alex Deucherfcec5702009-11-10 21:25:07 -05001385 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001386 DRM_INFO("No TMDS info found in BIOS\n");
Alex Deucherfcec5702009-11-10 21:25:07 -05001387 return false;
1388 }
Dave Airlie445282d2009-09-09 17:40:54 +10001389 return true;
1390}
1391
Alex Deucherfcec5702009-11-10 21:25:07 -05001392bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
1393 struct radeon_encoder_ext_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001394{
1395 struct drm_device *dev = encoder->base.dev;
1396 struct radeon_device *rdev = dev->dev_private;
Alex Deucherfcec5702009-11-10 21:25:07 -05001397 struct radeon_i2c_bus_rec i2c_bus;
1398
1399 /* default for macs */
Alex Deucher179e8072010-08-05 21:21:17 -04001400 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
Alex Deucherf376b942010-08-05 21:21:16 -04001401 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucherfcec5702009-11-10 21:25:07 -05001402
1403 /* XXX some macs have duallink chips */
1404 switch (rdev->mode_info.connector_table) {
1405 case CT_POWERBOOK_EXTERNAL:
1406 case CT_MINI_EXTERNAL:
1407 default:
1408 tmds->dvo_chip = DVO_SIL164;
1409 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1410 break;
1411 }
1412
1413 return true;
1414}
1415
1416bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
1417 struct radeon_encoder_ext_tmds *tmds)
1418{
1419 struct drm_device *dev = encoder->base.dev;
1420 struct radeon_device *rdev = dev->dev_private;
1421 uint16_t offset;
Alex Deucher179e8072010-08-05 21:21:17 -04001422 uint8_t ver;
Alex Deucherfcec5702009-11-10 21:25:07 -05001423 enum radeon_combios_ddc gpio;
1424 struct radeon_i2c_bus_rec i2c_bus;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001425
Alex Deucherfcec5702009-11-10 21:25:07 -05001426 tmds->i2c_bus = NULL;
1427 if (rdev->flags & RADEON_IS_IGP) {
Alex Deucher179e8072010-08-05 21:21:17 -04001428 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1429 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1430 tmds->dvo_chip = DVO_SIL164;
1431 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
Alex Deucherfcec5702009-11-10 21:25:07 -05001432 } else {
1433 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
1434 if (offset) {
1435 ver = RBIOS8(offset);
Alex Deucher40f76d82010-10-07 22:38:42 -04001436 DRM_DEBUG_KMS("External TMDS Table revision: %d\n", ver);
Alex Deucherfcec5702009-11-10 21:25:07 -05001437 tmds->slave_addr = RBIOS8(offset + 4 + 2);
1438 tmds->slave_addr >>= 1; /* 7 bit addressing */
1439 gpio = RBIOS8(offset + 4 + 3);
Alex Deucher179e8072010-08-05 21:21:17 -04001440 if (gpio == DDC_LCD) {
1441 /* MM i2c */
Alex Deucher40bacf12009-12-23 03:23:21 -05001442 i2c_bus.valid = true;
1443 i2c_bus.hw_capable = true;
1444 i2c_bus.mm_i2c = true;
Alex Deucher179e8072010-08-05 21:21:17 -04001445 i2c_bus.i2c_id = 0xa0;
1446 } else
1447 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
1448 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucherfcec5702009-11-10 21:25:07 -05001449 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001450 }
Alex Deucherfcec5702009-11-10 21:25:07 -05001451
1452 if (!tmds->i2c_bus) {
1453 DRM_INFO("No valid Ext TMDS info found in BIOS\n");
1454 return false;
1455 }
1456
1457 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001458}
1459
1460bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1461{
1462 struct radeon_device *rdev = dev->dev_private;
1463 struct radeon_i2c_bus_rec ddc_i2c;
Alex Deuchereed45b32009-12-04 14:45:27 -05001464 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001465
1466 rdev->mode_info.connector_table = radeon_connector_table;
1467 if (rdev->mode_info.connector_table == CT_NONE) {
1468#ifdef CONFIG_PPC_PMAC
Grant Likely71a157e2010-02-01 21:34:14 -07001469 if (of_machine_is_compatible("PowerBook3,3")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001470 /* powerbook with VGA */
1471 rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
Grant Likely71a157e2010-02-01 21:34:14 -07001472 } else if (of_machine_is_compatible("PowerBook3,4") ||
1473 of_machine_is_compatible("PowerBook3,5")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001474 /* powerbook with internal tmds */
1475 rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001476 } else if (of_machine_is_compatible("PowerBook5,1") ||
1477 of_machine_is_compatible("PowerBook5,2") ||
1478 of_machine_is_compatible("PowerBook5,3") ||
1479 of_machine_is_compatible("PowerBook5,4") ||
1480 of_machine_is_compatible("PowerBook5,5")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001481 /* powerbook with external single link tmds (sil164) */
1482 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001483 } else if (of_machine_is_compatible("PowerBook5,6")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001484 /* powerbook with external dual or single link tmds */
1485 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001486 } else if (of_machine_is_compatible("PowerBook5,7") ||
1487 of_machine_is_compatible("PowerBook5,8") ||
1488 of_machine_is_compatible("PowerBook5,9")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001489 /* PowerBook6,2 ? */
1490 /* powerbook with external dual link tmds (sil1178?) */
1491 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001492 } else if (of_machine_is_compatible("PowerBook4,1") ||
1493 of_machine_is_compatible("PowerBook4,2") ||
1494 of_machine_is_compatible("PowerBook4,3") ||
1495 of_machine_is_compatible("PowerBook6,3") ||
1496 of_machine_is_compatible("PowerBook6,5") ||
1497 of_machine_is_compatible("PowerBook6,7")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001498 /* ibook */
1499 rdev->mode_info.connector_table = CT_IBOOK;
Grant Likely71a157e2010-02-01 21:34:14 -07001500 } else if (of_machine_is_compatible("PowerMac4,4")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001501 /* emac */
1502 rdev->mode_info.connector_table = CT_EMAC;
Grant Likely71a157e2010-02-01 21:34:14 -07001503 } else if (of_machine_is_compatible("PowerMac10,1")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001504 /* mini with internal tmds */
1505 rdev->mode_info.connector_table = CT_MINI_INTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001506 } else if (of_machine_is_compatible("PowerMac10,2")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001507 /* mini with external tmds */
1508 rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001509 } else if (of_machine_is_compatible("PowerMac12,1")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001510 /* PowerMac8,1 ? */
1511 /* imac g5 isight */
1512 rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
Alex Deucheraa74fbb2010-09-07 14:41:30 -04001513 } else if ((rdev->pdev->device == 0x4a48) &&
1514 (rdev->pdev->subsystem_vendor == 0x1002) &&
1515 (rdev->pdev->subsystem_device == 0x4a48)) {
1516 /* Mac X800 */
1517 rdev->mode_info.connector_table = CT_MAC_X800;
Alex Deucher9fad3212011-02-07 13:15:28 -05001518 } else if ((rdev->pdev->device == 0x4150) &&
1519 (rdev->pdev->subsystem_vendor == 0x1002) &&
1520 (rdev->pdev->subsystem_device == 0x4150)) {
1521 /* Mac G5 9600 */
1522 rdev->mode_info.connector_table = CT_MAC_G5_9600;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001523 } else
1524#endif /* CONFIG_PPC_PMAC */
Dave Airlie76a71422010-06-11 01:09:05 -04001525#ifdef CONFIG_PPC64
1526 if (ASIC_IS_RN50(rdev))
1527 rdev->mode_info.connector_table = CT_RN50_POWER;
1528 else
1529#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001530 rdev->mode_info.connector_table = CT_GENERIC;
1531 }
1532
1533 switch (rdev->mode_info.connector_table) {
1534 case CT_GENERIC:
1535 DRM_INFO("Connector Table: %d (generic)\n",
1536 rdev->mode_info.connector_table);
1537 /* these are the most common settings */
1538 if (rdev->flags & RADEON_SINGLE_CRTC) {
1539 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001540 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001541 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001542 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001543 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001544 ATOM_DEVICE_CRT1_SUPPORT,
1545 1),
1546 ATOM_DEVICE_CRT1_SUPPORT);
1547 radeon_add_legacy_connector(dev, 0,
1548 ATOM_DEVICE_CRT1_SUPPORT,
1549 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001550 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001551 CONNECTOR_OBJECT_ID_VGA,
1552 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001553 } else if (rdev->flags & RADEON_IS_MOBILITY) {
1554 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001555 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001556 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001557 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001558 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001559 ATOM_DEVICE_LCD1_SUPPORT,
1560 0),
1561 ATOM_DEVICE_LCD1_SUPPORT);
1562 radeon_add_legacy_connector(dev, 0,
1563 ATOM_DEVICE_LCD1_SUPPORT,
1564 DRM_MODE_CONNECTOR_LVDS,
Alex Deucherb75fad02009-11-05 13:16:01 -05001565 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001566 CONNECTOR_OBJECT_ID_LVDS,
1567 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001568
1569 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001570 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001571 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001572 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001573 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001574 ATOM_DEVICE_CRT1_SUPPORT,
1575 1),
1576 ATOM_DEVICE_CRT1_SUPPORT);
1577 radeon_add_legacy_connector(dev, 1,
1578 ATOM_DEVICE_CRT1_SUPPORT,
1579 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001580 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001581 CONNECTOR_OBJECT_ID_VGA,
1582 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001583 } else {
1584 /* DVI-I - tv dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001585 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001586 hpd.hpd = RADEON_HPD_1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001587 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001588 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001589 ATOM_DEVICE_DFP1_SUPPORT,
1590 0),
1591 ATOM_DEVICE_DFP1_SUPPORT);
1592 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001593 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001594 ATOM_DEVICE_CRT2_SUPPORT,
1595 2),
1596 ATOM_DEVICE_CRT2_SUPPORT);
1597 radeon_add_legacy_connector(dev, 0,
1598 ATOM_DEVICE_DFP1_SUPPORT |
1599 ATOM_DEVICE_CRT2_SUPPORT,
1600 DRM_MODE_CONNECTOR_DVII,
Alex Deucherb75fad02009-11-05 13:16:01 -05001601 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001602 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1603 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001604
1605 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001606 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001607 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001608 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001609 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001610 ATOM_DEVICE_CRT1_SUPPORT,
1611 1),
1612 ATOM_DEVICE_CRT1_SUPPORT);
1613 radeon_add_legacy_connector(dev, 1,
1614 ATOM_DEVICE_CRT1_SUPPORT,
1615 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001616 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001617 CONNECTOR_OBJECT_ID_VGA,
1618 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001619 }
1620
1621 if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
1622 /* TV - tv dac */
Alex Deuchereed45b32009-12-04 14:45:27 -05001623 ddc_i2c.valid = false;
1624 hpd.hpd = RADEON_HPD_NONE;
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_TV1_SUPPORT,
1628 2),
1629 ATOM_DEVICE_TV1_SUPPORT);
1630 radeon_add_legacy_connector(dev, 2,
1631 ATOM_DEVICE_TV1_SUPPORT,
1632 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001633 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001634 CONNECTOR_OBJECT_ID_SVIDEO,
1635 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001636 }
1637 break;
1638 case CT_IBOOK:
1639 DRM_INFO("Connector Table: %d (ibook)\n",
1640 rdev->mode_info.connector_table);
1641 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001642 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001643 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001644 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001645 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001646 ATOM_DEVICE_LCD1_SUPPORT,
1647 0),
1648 ATOM_DEVICE_LCD1_SUPPORT);
1649 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001650 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001651 CONNECTOR_OBJECT_ID_LVDS,
1652 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001653 /* VGA - TV DAC */
Alex Deucher179e8072010-08-05 21:21:17 -04001654 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001655 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001656 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001657 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001658 ATOM_DEVICE_CRT2_SUPPORT,
1659 2),
1660 ATOM_DEVICE_CRT2_SUPPORT);
1661 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001662 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001663 CONNECTOR_OBJECT_ID_VGA,
1664 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001665 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001666 ddc_i2c.valid = false;
1667 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001668 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001669 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001670 ATOM_DEVICE_TV1_SUPPORT,
1671 2),
1672 ATOM_DEVICE_TV1_SUPPORT);
1673 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1674 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001675 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001676 CONNECTOR_OBJECT_ID_SVIDEO,
1677 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001678 break;
1679 case CT_POWERBOOK_EXTERNAL:
1680 DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
1681 rdev->mode_info.connector_table);
1682 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001683 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001684 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001685 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001686 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001687 ATOM_DEVICE_LCD1_SUPPORT,
1688 0),
1689 ATOM_DEVICE_LCD1_SUPPORT);
1690 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001691 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001692 CONNECTOR_OBJECT_ID_LVDS,
1693 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001694 /* DVI-I - primary dac, ext tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001695 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001696 hpd.hpd = RADEON_HPD_2; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001697 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001698 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001699 ATOM_DEVICE_DFP2_SUPPORT,
1700 0),
1701 ATOM_DEVICE_DFP2_SUPPORT);
1702 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001703 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001704 ATOM_DEVICE_CRT1_SUPPORT,
1705 1),
1706 ATOM_DEVICE_CRT1_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05001707 /* XXX some are SL */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001708 radeon_add_legacy_connector(dev, 1,
1709 ATOM_DEVICE_DFP2_SUPPORT |
1710 ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001711 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001712 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
1713 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001714 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001715 ddc_i2c.valid = false;
1716 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001717 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001718 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001719 ATOM_DEVICE_TV1_SUPPORT,
1720 2),
1721 ATOM_DEVICE_TV1_SUPPORT);
1722 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1723 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001724 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001725 CONNECTOR_OBJECT_ID_SVIDEO,
1726 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001727 break;
1728 case CT_POWERBOOK_INTERNAL:
1729 DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
1730 rdev->mode_info.connector_table);
1731 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001732 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001733 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001734 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001735 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001736 ATOM_DEVICE_LCD1_SUPPORT,
1737 0),
1738 ATOM_DEVICE_LCD1_SUPPORT);
1739 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001740 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001741 CONNECTOR_OBJECT_ID_LVDS,
1742 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001743 /* DVI-I - primary dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001744 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001745 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001746 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001747 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001748 ATOM_DEVICE_DFP1_SUPPORT,
1749 0),
1750 ATOM_DEVICE_DFP1_SUPPORT);
1751 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001752 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001753 ATOM_DEVICE_CRT1_SUPPORT,
1754 1),
1755 ATOM_DEVICE_CRT1_SUPPORT);
1756 radeon_add_legacy_connector(dev, 1,
1757 ATOM_DEVICE_DFP1_SUPPORT |
1758 ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001759 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001760 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1761 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001762 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001763 ddc_i2c.valid = false;
1764 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001765 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001766 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001767 ATOM_DEVICE_TV1_SUPPORT,
1768 2),
1769 ATOM_DEVICE_TV1_SUPPORT);
1770 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1771 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001772 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001773 CONNECTOR_OBJECT_ID_SVIDEO,
1774 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001775 break;
1776 case CT_POWERBOOK_VGA:
1777 DRM_INFO("Connector Table: %d (powerbook vga)\n",
1778 rdev->mode_info.connector_table);
1779 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001780 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001781 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001782 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001783 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001784 ATOM_DEVICE_LCD1_SUPPORT,
1785 0),
1786 ATOM_DEVICE_LCD1_SUPPORT);
1787 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001788 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001789 CONNECTOR_OBJECT_ID_LVDS,
1790 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001791 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001792 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001793 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001794 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001795 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001796 ATOM_DEVICE_CRT1_SUPPORT,
1797 1),
1798 ATOM_DEVICE_CRT1_SUPPORT);
1799 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001800 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001801 CONNECTOR_OBJECT_ID_VGA,
1802 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001803 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001804 ddc_i2c.valid = false;
1805 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001806 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001807 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001808 ATOM_DEVICE_TV1_SUPPORT,
1809 2),
1810 ATOM_DEVICE_TV1_SUPPORT);
1811 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1812 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001813 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001814 CONNECTOR_OBJECT_ID_SVIDEO,
1815 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001816 break;
1817 case CT_MINI_EXTERNAL:
1818 DRM_INFO("Connector Table: %d (mini external tmds)\n",
1819 rdev->mode_info.connector_table);
1820 /* DVI-I - tv dac, ext tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001821 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001822 hpd.hpd = RADEON_HPD_2; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001823 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001824 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001825 ATOM_DEVICE_DFP2_SUPPORT,
1826 0),
1827 ATOM_DEVICE_DFP2_SUPPORT);
1828 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001829 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001830 ATOM_DEVICE_CRT2_SUPPORT,
1831 2),
1832 ATOM_DEVICE_CRT2_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05001833 /* XXX are any DL? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001834 radeon_add_legacy_connector(dev, 0,
1835 ATOM_DEVICE_DFP2_SUPPORT |
1836 ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001837 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001838 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1839 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001840 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001841 ddc_i2c.valid = false;
1842 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001843 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001844 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001845 ATOM_DEVICE_TV1_SUPPORT,
1846 2),
1847 ATOM_DEVICE_TV1_SUPPORT);
1848 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
1849 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001850 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001851 CONNECTOR_OBJECT_ID_SVIDEO,
1852 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001853 break;
1854 case CT_MINI_INTERNAL:
1855 DRM_INFO("Connector Table: %d (mini internal tmds)\n",
1856 rdev->mode_info.connector_table);
1857 /* DVI-I - tv dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001858 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001859 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001860 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001861 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001862 ATOM_DEVICE_DFP1_SUPPORT,
1863 0),
1864 ATOM_DEVICE_DFP1_SUPPORT);
1865 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001866 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001867 ATOM_DEVICE_CRT2_SUPPORT,
1868 2),
1869 ATOM_DEVICE_CRT2_SUPPORT);
1870 radeon_add_legacy_connector(dev, 0,
1871 ATOM_DEVICE_DFP1_SUPPORT |
1872 ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001873 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001874 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1875 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001876 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001877 ddc_i2c.valid = false;
1878 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001879 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001880 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001881 ATOM_DEVICE_TV1_SUPPORT,
1882 2),
1883 ATOM_DEVICE_TV1_SUPPORT);
1884 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
1885 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001886 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001887 CONNECTOR_OBJECT_ID_SVIDEO,
1888 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001889 break;
1890 case CT_IMAC_G5_ISIGHT:
1891 DRM_INFO("Connector Table: %d (imac g5 isight)\n",
1892 rdev->mode_info.connector_table);
1893 /* DVI-D - int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001894 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001895 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001896 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001897 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001898 ATOM_DEVICE_DFP1_SUPPORT,
1899 0),
1900 ATOM_DEVICE_DFP1_SUPPORT);
1901 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001902 DRM_MODE_CONNECTOR_DVID, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001903 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
1904 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001905 /* VGA - tv dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001906 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001907 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001908 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001909 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001910 ATOM_DEVICE_CRT2_SUPPORT,
1911 2),
1912 ATOM_DEVICE_CRT2_SUPPORT);
1913 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001914 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001915 CONNECTOR_OBJECT_ID_VGA,
1916 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001917 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001918 ddc_i2c.valid = false;
1919 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001920 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001921 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001922 ATOM_DEVICE_TV1_SUPPORT,
1923 2),
1924 ATOM_DEVICE_TV1_SUPPORT);
1925 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1926 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001927 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001928 CONNECTOR_OBJECT_ID_SVIDEO,
1929 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001930 break;
1931 case CT_EMAC:
1932 DRM_INFO("Connector Table: %d (emac)\n",
1933 rdev->mode_info.connector_table);
1934 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001935 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001936 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001937 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001938 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001939 ATOM_DEVICE_CRT1_SUPPORT,
1940 1),
1941 ATOM_DEVICE_CRT1_SUPPORT);
1942 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001943 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001944 CONNECTOR_OBJECT_ID_VGA,
1945 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001946 /* VGA - tv dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001947 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001948 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001949 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001950 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001951 ATOM_DEVICE_CRT2_SUPPORT,
1952 2),
1953 ATOM_DEVICE_CRT2_SUPPORT);
1954 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001955 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001956 CONNECTOR_OBJECT_ID_VGA,
1957 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001958 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001959 ddc_i2c.valid = false;
1960 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001961 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001962 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001963 ATOM_DEVICE_TV1_SUPPORT,
1964 2),
1965 ATOM_DEVICE_TV1_SUPPORT);
1966 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1967 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001968 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001969 CONNECTOR_OBJECT_ID_SVIDEO,
1970 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001971 break;
Dave Airlie76a71422010-06-11 01:09:05 -04001972 case CT_RN50_POWER:
1973 DRM_INFO("Connector Table: %d (rn50-power)\n",
1974 rdev->mode_info.connector_table);
1975 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001976 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Dave Airlie76a71422010-06-11 01:09:05 -04001977 hpd.hpd = RADEON_HPD_NONE;
1978 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001979 radeon_get_encoder_enum(dev,
Dave Airlie76a71422010-06-11 01:09:05 -04001980 ATOM_DEVICE_CRT1_SUPPORT,
1981 1),
1982 ATOM_DEVICE_CRT1_SUPPORT);
1983 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
1984 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
1985 CONNECTOR_OBJECT_ID_VGA,
1986 &hpd);
Alex Deucher179e8072010-08-05 21:21:17 -04001987 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Dave Airlie76a71422010-06-11 01:09:05 -04001988 hpd.hpd = RADEON_HPD_NONE;
1989 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001990 radeon_get_encoder_enum(dev,
Dave Airlie76a71422010-06-11 01:09:05 -04001991 ATOM_DEVICE_CRT2_SUPPORT,
1992 2),
1993 ATOM_DEVICE_CRT2_SUPPORT);
1994 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
1995 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
1996 CONNECTOR_OBJECT_ID_VGA,
1997 &hpd);
1998 break;
Alex Deucheraa74fbb2010-09-07 14:41:30 -04001999 case CT_MAC_X800:
2000 DRM_INFO("Connector Table: %d (mac x800)\n",
2001 rdev->mode_info.connector_table);
2002 /* DVI - primary dac, internal tmds */
2003 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2004 hpd.hpd = RADEON_HPD_1; /* ??? */
2005 radeon_add_legacy_encoder(dev,
2006 radeon_get_encoder_enum(dev,
2007 ATOM_DEVICE_DFP1_SUPPORT,
2008 0),
2009 ATOM_DEVICE_DFP1_SUPPORT);
2010 radeon_add_legacy_encoder(dev,
2011 radeon_get_encoder_enum(dev,
2012 ATOM_DEVICE_CRT1_SUPPORT,
2013 1),
2014 ATOM_DEVICE_CRT1_SUPPORT);
2015 radeon_add_legacy_connector(dev, 0,
2016 ATOM_DEVICE_DFP1_SUPPORT |
2017 ATOM_DEVICE_CRT1_SUPPORT,
2018 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2019 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2020 &hpd);
2021 /* DVI - tv dac, dvo */
2022 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
2023 hpd.hpd = RADEON_HPD_2; /* ??? */
2024 radeon_add_legacy_encoder(dev,
2025 radeon_get_encoder_enum(dev,
2026 ATOM_DEVICE_DFP2_SUPPORT,
2027 0),
2028 ATOM_DEVICE_DFP2_SUPPORT);
2029 radeon_add_legacy_encoder(dev,
2030 radeon_get_encoder_enum(dev,
2031 ATOM_DEVICE_CRT2_SUPPORT,
2032 2),
2033 ATOM_DEVICE_CRT2_SUPPORT);
2034 radeon_add_legacy_connector(dev, 1,
2035 ATOM_DEVICE_DFP2_SUPPORT |
2036 ATOM_DEVICE_CRT2_SUPPORT,
2037 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2038 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
2039 &hpd);
2040 break;
Alex Deucher9fad3212011-02-07 13:15:28 -05002041 case CT_MAC_G5_9600:
2042 DRM_INFO("Connector Table: %d (mac g5 9600)\n",
2043 rdev->mode_info.connector_table);
2044 /* DVI - tv dac, dvo */
2045 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2046 hpd.hpd = RADEON_HPD_1; /* ??? */
2047 radeon_add_legacy_encoder(dev,
2048 radeon_get_encoder_enum(dev,
2049 ATOM_DEVICE_DFP2_SUPPORT,
2050 0),
2051 ATOM_DEVICE_DFP2_SUPPORT);
2052 radeon_add_legacy_encoder(dev,
2053 radeon_get_encoder_enum(dev,
2054 ATOM_DEVICE_CRT2_SUPPORT,
2055 2),
2056 ATOM_DEVICE_CRT2_SUPPORT);
2057 radeon_add_legacy_connector(dev, 0,
2058 ATOM_DEVICE_DFP2_SUPPORT |
2059 ATOM_DEVICE_CRT2_SUPPORT,
2060 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2061 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2062 &hpd);
2063 /* ADC - primary dac, internal tmds */
2064 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
2065 hpd.hpd = RADEON_HPD_2; /* ??? */
2066 radeon_add_legacy_encoder(dev,
2067 radeon_get_encoder_enum(dev,
2068 ATOM_DEVICE_DFP1_SUPPORT,
2069 0),
2070 ATOM_DEVICE_DFP1_SUPPORT);
2071 radeon_add_legacy_encoder(dev,
2072 radeon_get_encoder_enum(dev,
2073 ATOM_DEVICE_CRT1_SUPPORT,
2074 1),
2075 ATOM_DEVICE_CRT1_SUPPORT);
2076 radeon_add_legacy_connector(dev, 1,
2077 ATOM_DEVICE_DFP1_SUPPORT |
2078 ATOM_DEVICE_CRT1_SUPPORT,
2079 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2080 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2081 &hpd);
2082 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002083 default:
2084 DRM_INFO("Connector table: %d (invalid)\n",
2085 rdev->mode_info.connector_table);
2086 return false;
2087 }
2088
2089 radeon_link_encoder_connector(dev);
2090
2091 return true;
2092}
2093
2094static bool radeon_apply_legacy_quirks(struct drm_device *dev,
2095 int bios_index,
2096 enum radeon_combios_connector
2097 *legacy_connector,
Alex Deuchereed45b32009-12-04 14:45:27 -05002098 struct radeon_i2c_bus_rec *ddc_i2c,
2099 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002100{
Alex Deucherfcec5702009-11-10 21:25:07 -05002101
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002102 /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
2103 one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
2104 if (dev->pdev->device == 0x515e &&
2105 dev->pdev->subsystem_vendor == 0x1014) {
2106 if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
2107 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
2108 return false;
2109 }
2110
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002111 /* X300 card with extra non-existent DVI port */
2112 if (dev->pdev->device == 0x5B60 &&
2113 dev->pdev->subsystem_vendor == 0x17af &&
2114 dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
2115 if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
2116 return false;
2117 }
2118
2119 return true;
2120}
2121
Alex Deucher790cfb32009-10-15 23:26:09 -04002122static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
2123{
2124 /* Acer 5102 has non-existent TV port */
2125 if (dev->pdev->device == 0x5975 &&
2126 dev->pdev->subsystem_vendor == 0x1025 &&
2127 dev->pdev->subsystem_device == 0x009f)
2128 return false;
2129
Alex Deucherfc7f7112009-10-28 01:46:54 -04002130 /* HP dc5750 has non-existent TV port */
2131 if (dev->pdev->device == 0x5974 &&
2132 dev->pdev->subsystem_vendor == 0x103c &&
2133 dev->pdev->subsystem_device == 0x280a)
2134 return false;
2135
Alex Deucherfd874ad2009-11-16 18:33:51 -05002136 /* MSI S270 has non-existent TV port */
2137 if (dev->pdev->device == 0x5955 &&
2138 dev->pdev->subsystem_vendor == 0x1462 &&
2139 dev->pdev->subsystem_device == 0x0131)
2140 return false;
2141
Alex Deucher790cfb32009-10-15 23:26:09 -04002142 return true;
2143}
2144
Alex Deucherb75fad02009-11-05 13:16:01 -05002145static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
2146{
2147 struct radeon_device *rdev = dev->dev_private;
2148 uint32_t ext_tmds_info;
2149
2150 if (rdev->flags & RADEON_IS_IGP) {
2151 if (is_dvi_d)
2152 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
2153 else
2154 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2155 }
2156 ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
2157 if (ext_tmds_info) {
2158 uint8_t rev = RBIOS8(ext_tmds_info);
2159 uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
2160 if (rev >= 3) {
2161 if (is_dvi_d)
2162 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
2163 else
2164 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
2165 } else {
2166 if (flags & 1) {
2167 if (is_dvi_d)
2168 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
2169 else
2170 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
2171 }
2172 }
2173 }
2174 if (is_dvi_d)
2175 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
2176 else
2177 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2178}
2179
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002180bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2181{
2182 struct radeon_device *rdev = dev->dev_private;
2183 uint32_t conn_info, entry, devices;
Alex Deucherb75fad02009-11-05 13:16:01 -05002184 uint16_t tmp, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002185 enum radeon_combios_ddc ddc_type;
2186 enum radeon_combios_connector connector;
2187 int i = 0;
2188 struct radeon_i2c_bus_rec ddc_i2c;
Alex Deuchereed45b32009-12-04 14:45:27 -05002189 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002190
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002191 conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
2192 if (conn_info) {
2193 for (i = 0; i < 4; i++) {
2194 entry = conn_info + 2 + i * 2;
2195
2196 if (!RBIOS16(entry))
2197 break;
2198
2199 tmp = RBIOS16(entry);
2200
2201 connector = (tmp >> 12) & 0xf;
2202
2203 ddc_type = (tmp >> 8) & 0xf;
Alex Deucher179e8072010-08-05 21:21:17 -04002204 ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002205
Alex Deuchereed45b32009-12-04 14:45:27 -05002206 switch (connector) {
2207 case CONNECTOR_PROPRIETARY_LEGACY:
2208 case CONNECTOR_DVI_I_LEGACY:
2209 case CONNECTOR_DVI_D_LEGACY:
2210 if ((tmp >> 4) & 0x1)
2211 hpd.hpd = RADEON_HPD_2;
2212 else
2213 hpd.hpd = RADEON_HPD_1;
2214 break;
2215 default:
2216 hpd.hpd = RADEON_HPD_NONE;
2217 break;
2218 }
2219
Alex Deucher2d152c62009-10-15 23:08:05 -04002220 if (!radeon_apply_legacy_quirks(dev, i, &connector,
Alex Deuchereed45b32009-12-04 14:45:27 -05002221 &ddc_i2c, &hpd))
Alex Deucher2d152c62009-10-15 23:08:05 -04002222 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002223
2224 switch (connector) {
2225 case CONNECTOR_PROPRIETARY_LEGACY:
2226 if ((tmp >> 4) & 0x1)
2227 devices = ATOM_DEVICE_DFP2_SUPPORT;
2228 else
2229 devices = ATOM_DEVICE_DFP1_SUPPORT;
2230 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002231 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002232 (dev, devices, 0),
2233 devices);
2234 radeon_add_legacy_connector(dev, i, devices,
2235 legacy_connector_convert
2236 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002237 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002238 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
2239 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002240 break;
2241 case CONNECTOR_CRT_LEGACY:
2242 if (tmp & 0x1) {
2243 devices = ATOM_DEVICE_CRT2_SUPPORT;
2244 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002245 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002246 (dev,
2247 ATOM_DEVICE_CRT2_SUPPORT,
2248 2),
2249 ATOM_DEVICE_CRT2_SUPPORT);
2250 } else {
2251 devices = ATOM_DEVICE_CRT1_SUPPORT;
2252 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002253 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002254 (dev,
2255 ATOM_DEVICE_CRT1_SUPPORT,
2256 1),
2257 ATOM_DEVICE_CRT1_SUPPORT);
2258 }
2259 radeon_add_legacy_connector(dev,
2260 i,
2261 devices,
2262 legacy_connector_convert
2263 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002264 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002265 CONNECTOR_OBJECT_ID_VGA,
2266 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002267 break;
2268 case CONNECTOR_DVI_I_LEGACY:
2269 devices = 0;
2270 if (tmp & 0x1) {
2271 devices |= ATOM_DEVICE_CRT2_SUPPORT;
2272 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002273 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002274 (dev,
2275 ATOM_DEVICE_CRT2_SUPPORT,
2276 2),
2277 ATOM_DEVICE_CRT2_SUPPORT);
2278 } else {
2279 devices |= ATOM_DEVICE_CRT1_SUPPORT;
2280 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002281 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002282 (dev,
2283 ATOM_DEVICE_CRT1_SUPPORT,
2284 1),
2285 ATOM_DEVICE_CRT1_SUPPORT);
2286 }
2287 if ((tmp >> 4) & 0x1) {
2288 devices |= ATOM_DEVICE_DFP2_SUPPORT;
2289 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002290 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002291 (dev,
2292 ATOM_DEVICE_DFP2_SUPPORT,
2293 0),
2294 ATOM_DEVICE_DFP2_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05002295 connector_object_id = combios_check_dl_dvi(dev, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002296 } else {
2297 devices |= ATOM_DEVICE_DFP1_SUPPORT;
2298 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002299 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002300 (dev,
2301 ATOM_DEVICE_DFP1_SUPPORT,
2302 0),
2303 ATOM_DEVICE_DFP1_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05002304 connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002305 }
2306 radeon_add_legacy_connector(dev,
2307 i,
2308 devices,
2309 legacy_connector_convert
2310 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002311 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002312 connector_object_id,
2313 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002314 break;
2315 case CONNECTOR_DVI_D_LEGACY:
Alex Deucherb75fad02009-11-05 13:16:01 -05002316 if ((tmp >> 4) & 0x1) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002317 devices = ATOM_DEVICE_DFP2_SUPPORT;
Alex Deucherb75fad02009-11-05 13:16:01 -05002318 connector_object_id = combios_check_dl_dvi(dev, 1);
2319 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002320 devices = ATOM_DEVICE_DFP1_SUPPORT;
Alex Deucherb75fad02009-11-05 13:16:01 -05002321 connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2322 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002323 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, devices, 0),
2326 devices);
2327 radeon_add_legacy_connector(dev, i, devices,
2328 legacy_connector_convert
2329 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002330 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002331 connector_object_id,
2332 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002333 break;
2334 case CONNECTOR_CTV_LEGACY:
2335 case CONNECTOR_STV_LEGACY:
2336 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002337 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002338 (dev,
2339 ATOM_DEVICE_TV1_SUPPORT,
2340 2),
2341 ATOM_DEVICE_TV1_SUPPORT);
2342 radeon_add_legacy_connector(dev, i,
2343 ATOM_DEVICE_TV1_SUPPORT,
2344 legacy_connector_convert
2345 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002346 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002347 CONNECTOR_OBJECT_ID_SVIDEO,
2348 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002349 break;
2350 default:
2351 DRM_ERROR("Unknown connector type: %d\n",
2352 connector);
2353 continue;
2354 }
2355
2356 }
2357 } else {
2358 uint16_t tmds_info =
2359 combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
2360 if (tmds_info) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002361 DRM_DEBUG_KMS("Found DFP table, assuming DVI connector\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002362
2363 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002364 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002365 ATOM_DEVICE_CRT1_SUPPORT,
2366 1),
2367 ATOM_DEVICE_CRT1_SUPPORT);
2368 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002369 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002370 ATOM_DEVICE_DFP1_SUPPORT,
2371 0),
2372 ATOM_DEVICE_DFP1_SUPPORT);
2373
Alex Deucher179e8072010-08-05 21:21:17 -04002374 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deucher8e36ed02010-05-18 19:26:47 -04002375 hpd.hpd = RADEON_HPD_1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002376 radeon_add_legacy_connector(dev,
2377 0,
2378 ATOM_DEVICE_CRT1_SUPPORT |
2379 ATOM_DEVICE_DFP1_SUPPORT,
2380 DRM_MODE_CONNECTOR_DVII,
Alex Deucherb75fad02009-11-05 13:16:01 -05002381 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002382 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2383 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002384 } else {
Alex Deucherd0c403e2009-10-15 23:38:32 -04002385 uint16_t crt_info =
2386 combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002387 DRM_DEBUG_KMS("Found CRT table, assuming VGA connector\n");
Alex Deucherd0c403e2009-10-15 23:38:32 -04002388 if (crt_info) {
2389 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002390 radeon_get_encoder_enum(dev,
Alex Deucherd0c403e2009-10-15 23:38:32 -04002391 ATOM_DEVICE_CRT1_SUPPORT,
2392 1),
2393 ATOM_DEVICE_CRT1_SUPPORT);
Alex Deucher179e8072010-08-05 21:21:17 -04002394 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05002395 hpd.hpd = RADEON_HPD_NONE;
Alex Deucherd0c403e2009-10-15 23:38:32 -04002396 radeon_add_legacy_connector(dev,
2397 0,
2398 ATOM_DEVICE_CRT1_SUPPORT,
2399 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05002400 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002401 CONNECTOR_OBJECT_ID_VGA,
2402 &hpd);
Alex Deucherd0c403e2009-10-15 23:38:32 -04002403 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002404 DRM_DEBUG_KMS("No connector info found\n");
Alex Deucherd0c403e2009-10-15 23:38:32 -04002405 return false;
2406 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002407 }
2408 }
2409
2410 if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
2411 uint16_t lcd_info =
2412 combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
2413 if (lcd_info) {
2414 uint16_t lcd_ddc_info =
2415 combios_get_table_offset(dev,
2416 COMBIOS_LCD_DDC_INFO_TABLE);
2417
2418 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002419 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002420 ATOM_DEVICE_LCD1_SUPPORT,
2421 0),
2422 ATOM_DEVICE_LCD1_SUPPORT);
2423
2424 if (lcd_ddc_info) {
2425 ddc_type = RBIOS8(lcd_ddc_info + 2);
2426 switch (ddc_type) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002427 case DDC_LCD:
2428 ddc_i2c =
Alex Deucher179e8072010-08-05 21:21:17 -04002429 combios_setup_i2c_bus(rdev,
2430 DDC_LCD,
2431 RBIOS32(lcd_ddc_info + 3),
2432 RBIOS32(lcd_ddc_info + 7));
Alex Deucherf376b942010-08-05 21:21:16 -04002433 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002434 break;
2435 case DDC_GPIO:
2436 ddc_i2c =
Alex Deucher179e8072010-08-05 21:21:17 -04002437 combios_setup_i2c_bus(rdev,
2438 DDC_GPIO,
2439 RBIOS32(lcd_ddc_info + 3),
2440 RBIOS32(lcd_ddc_info + 7));
Alex Deucherf376b942010-08-05 21:21:16 -04002441 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002442 break;
2443 default:
Alex Deucher179e8072010-08-05 21:21:17 -04002444 ddc_i2c =
2445 combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002446 break;
2447 }
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002448 DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002449 } else
2450 ddc_i2c.valid = false;
2451
Alex Deuchereed45b32009-12-04 14:45:27 -05002452 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002453 radeon_add_legacy_connector(dev,
2454 5,
2455 ATOM_DEVICE_LCD1_SUPPORT,
2456 DRM_MODE_CONNECTOR_LVDS,
Alex Deucherb75fad02009-11-05 13:16:01 -05002457 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002458 CONNECTOR_OBJECT_ID_LVDS,
2459 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002460 }
2461 }
2462
2463 /* check TV table */
2464 if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
2465 uint32_t tv_info =
2466 combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
2467 if (tv_info) {
2468 if (RBIOS8(tv_info + 6) == 'T') {
Alex Deucher790cfb32009-10-15 23:26:09 -04002469 if (radeon_apply_legacy_tv_quirks(dev)) {
Alex Deuchereed45b32009-12-04 14:45:27 -05002470 hpd.hpd = RADEON_HPD_NONE;
Dave Airlied294ed62010-06-08 13:04:50 +10002471 ddc_i2c.valid = false;
Alex Deucher790cfb32009-10-15 23:26:09 -04002472 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002473 radeon_get_encoder_enum
Alex Deucher790cfb32009-10-15 23:26:09 -04002474 (dev,
2475 ATOM_DEVICE_TV1_SUPPORT,
2476 2),
2477 ATOM_DEVICE_TV1_SUPPORT);
2478 radeon_add_legacy_connector(dev, 6,
2479 ATOM_DEVICE_TV1_SUPPORT,
2480 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05002481 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002482 CONNECTOR_OBJECT_ID_SVIDEO,
2483 &hpd);
Alex Deucher790cfb32009-10-15 23:26:09 -04002484 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002485 }
2486 }
2487 }
2488
2489 radeon_link_encoder_connector(dev);
2490
2491 return true;
2492}
2493
Alex Deucher56278a82009-12-28 13:58:44 -05002494void radeon_combios_get_power_modes(struct radeon_device *rdev)
2495{
2496 struct drm_device *dev = rdev->ddev;
2497 u16 offset, misc, misc2 = 0;
2498 u8 rev, blocks, tmp;
2499 int state_index = 0;
2500
Alex Deuchera48b9b42010-04-22 14:03:55 -04002501 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05002502
Alex Deucher0975b162011-02-02 18:42:03 -05002503 /* allocate 2 power states */
2504 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * 2, GFP_KERNEL);
2505 if (!rdev->pm.power_state) {
2506 rdev->pm.default_power_state_index = state_index;
2507 rdev->pm.num_power_states = 0;
2508
2509 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2510 rdev->pm.current_clock_mode_index = 0;
2511 return;
2512 }
2513
Alex Deucher56278a82009-12-28 13:58:44 -05002514 if (rdev->flags & RADEON_IS_MOBILITY) {
2515 offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
2516 if (offset) {
2517 rev = RBIOS8(offset);
2518 blocks = RBIOS8(offset + 0x2);
2519 /* power mode 0 tends to be the only valid one */
2520 rdev->pm.power_state[state_index].num_clock_modes = 1;
2521 rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
2522 rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
2523 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2524 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2525 goto default_mode;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002526 rdev->pm.power_state[state_index].type =
2527 POWER_STATE_TYPE_BATTERY;
Alex Deucher56278a82009-12-28 13:58:44 -05002528 misc = RBIOS16(offset + 0x5 + 0x0);
2529 if (rev > 4)
2530 misc2 = RBIOS16(offset + 0x5 + 0xe);
Alex Deucher79daedc2010-04-22 14:25:19 -04002531 rdev->pm.power_state[state_index].misc = misc;
2532 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher56278a82009-12-28 13:58:44 -05002533 if (misc & 0x4) {
2534 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
2535 if (misc & 0x8)
2536 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2537 true;
2538 else
2539 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2540 false;
2541 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
2542 if (rev < 6) {
2543 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
2544 RBIOS16(offset + 0x5 + 0xb) * 4;
2545 tmp = RBIOS8(offset + 0x5 + 0xd);
2546 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
2547 } else {
2548 u8 entries = RBIOS8(offset + 0x5 + 0xb);
2549 u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
2550 if (entries && voltage_table_offset) {
2551 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
2552 RBIOS16(voltage_table_offset) * 4;
2553 tmp = RBIOS8(voltage_table_offset + 0x2);
2554 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
2555 } else
2556 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
2557 }
2558 switch ((misc2 & 0x700) >> 8) {
2559 case 0:
2560 default:
2561 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
2562 break;
2563 case 1:
2564 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
2565 break;
2566 case 2:
2567 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
2568 break;
2569 case 3:
2570 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
2571 break;
2572 case 4:
2573 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
2574 break;
2575 }
2576 } else
2577 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2578 if (rev > 6)
Alex Deucher79daedc2010-04-22 14:25:19 -04002579 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05002580 RBIOS8(offset + 0x5 + 0x10);
Alex Deucherd7311172010-05-03 01:13:14 -04002581 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05002582 state_index++;
2583 } else {
2584 /* XXX figure out some good default low power mode for mobility cards w/out power tables */
2585 }
2586 } else {
2587 /* XXX figure out some good default low power mode for desktop cards */
2588 }
2589
2590default_mode:
2591 /* add the default mode */
Alex Deucher0ec0e742009-12-23 13:21:58 -05002592 rdev->pm.power_state[state_index].type =
2593 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05002594 rdev->pm.power_state[state_index].num_clock_modes = 1;
2595 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2596 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2597 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 -04002598 if ((state_index > 0) &&
Alex Deucher8de016e2010-06-03 21:28:23 -04002599 (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
Alex Deucher84d88f42010-05-27 17:01:42 -04002600 rdev->pm.power_state[state_index].clock_info[0].voltage =
2601 rdev->pm.power_state[0].clock_info[0].voltage;
2602 else
2603 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
Alex Deucher79daedc2010-04-22 14:25:19 -04002604 rdev->pm.power_state[state_index].pcie_lanes = 16;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002605 rdev->pm.power_state[state_index].flags = 0;
2606 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05002607 rdev->pm.num_power_states = state_index + 1;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002608
Alex Deuchera48b9b42010-04-22 14:03:55 -04002609 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2610 rdev->pm.current_clock_mode_index = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002611}
2612
Alex Deucherfcec5702009-11-10 21:25:07 -05002613void radeon_external_tmds_setup(struct drm_encoder *encoder)
2614{
2615 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2616 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
2617
2618 if (!tmds)
2619 return;
2620
2621 switch (tmds->dvo_chip) {
2622 case DVO_SIL164:
2623 /* sil 164 */
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002624 radeon_i2c_put_byte(tmds->i2c_bus,
2625 tmds->slave_addr,
2626 0x08, 0x30);
2627 radeon_i2c_put_byte(tmds->i2c_bus,
Alex Deucherfcec5702009-11-10 21:25:07 -05002628 tmds->slave_addr,
2629 0x09, 0x00);
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002630 radeon_i2c_put_byte(tmds->i2c_bus,
2631 tmds->slave_addr,
2632 0x0a, 0x90);
2633 radeon_i2c_put_byte(tmds->i2c_bus,
2634 tmds->slave_addr,
2635 0x0c, 0x89);
2636 radeon_i2c_put_byte(tmds->i2c_bus,
Alex Deucherfcec5702009-11-10 21:25:07 -05002637 tmds->slave_addr,
2638 0x08, 0x3b);
Alex Deucherfcec5702009-11-10 21:25:07 -05002639 break;
2640 case DVO_SIL1178:
2641 /* sil 1178 - untested */
2642 /*
2643 * 0x0f, 0x44
2644 * 0x0f, 0x4c
2645 * 0x0e, 0x01
2646 * 0x0a, 0x80
2647 * 0x09, 0x30
2648 * 0x0c, 0xc9
2649 * 0x0d, 0x70
2650 * 0x08, 0x32
2651 * 0x08, 0x33
2652 */
2653 break;
2654 default:
2655 break;
2656 }
2657
2658}
2659
2660bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
2661{
2662 struct drm_device *dev = encoder->dev;
2663 struct radeon_device *rdev = dev->dev_private;
2664 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2665 uint16_t offset;
2666 uint8_t blocks, slave_addr, rev;
2667 uint32_t index, id;
2668 uint32_t reg, val, and_mask, or_mask;
2669 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
2670
Alex Deucherfcec5702009-11-10 21:25:07 -05002671 if (!tmds)
2672 return false;
2673
2674 if (rdev->flags & RADEON_IS_IGP) {
2675 offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
2676 rev = RBIOS8(offset);
2677 if (offset) {
2678 rev = RBIOS8(offset);
2679 if (rev > 1) {
2680 blocks = RBIOS8(offset + 3);
2681 index = offset + 4;
2682 while (blocks > 0) {
2683 id = RBIOS16(index);
2684 index += 2;
2685 switch (id >> 13) {
2686 case 0:
2687 reg = (id & 0x1fff) * 4;
2688 val = RBIOS32(index);
2689 index += 4;
2690 WREG32(reg, val);
2691 break;
2692 case 2:
2693 reg = (id & 0x1fff) * 4;
2694 and_mask = RBIOS32(index);
2695 index += 4;
2696 or_mask = RBIOS32(index);
2697 index += 4;
2698 val = RREG32(reg);
2699 val = (val & and_mask) | or_mask;
2700 WREG32(reg, val);
2701 break;
2702 case 3:
2703 val = RBIOS16(index);
2704 index += 2;
2705 udelay(val);
2706 break;
2707 case 4:
2708 val = RBIOS16(index);
2709 index += 2;
2710 udelay(val * 1000);
2711 break;
2712 case 6:
2713 slave_addr = id & 0xff;
2714 slave_addr >>= 1; /* 7 bit addressing */
2715 index++;
2716 reg = RBIOS8(index);
2717 index++;
2718 val = RBIOS8(index);
2719 index++;
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002720 radeon_i2c_put_byte(tmds->i2c_bus,
2721 slave_addr,
2722 reg, val);
Alex Deucherfcec5702009-11-10 21:25:07 -05002723 break;
2724 default:
2725 DRM_ERROR("Unknown id %d\n", id >> 13);
2726 break;
2727 }
2728 blocks--;
2729 }
2730 return true;
2731 }
2732 }
2733 } else {
2734 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
2735 if (offset) {
2736 index = offset + 10;
2737 id = RBIOS16(index);
2738 while (id != 0xffff) {
2739 index += 2;
2740 switch (id >> 13) {
2741 case 0:
2742 reg = (id & 0x1fff) * 4;
2743 val = RBIOS32(index);
2744 WREG32(reg, val);
2745 break;
2746 case 2:
2747 reg = (id & 0x1fff) * 4;
2748 and_mask = RBIOS32(index);
2749 index += 4;
2750 or_mask = RBIOS32(index);
2751 index += 4;
2752 val = RREG32(reg);
2753 val = (val & and_mask) | or_mask;
2754 WREG32(reg, val);
2755 break;
2756 case 4:
2757 val = RBIOS16(index);
2758 index += 2;
2759 udelay(val);
2760 break;
2761 case 5:
2762 reg = id & 0x1fff;
2763 and_mask = RBIOS32(index);
2764 index += 4;
2765 or_mask = RBIOS32(index);
2766 index += 4;
2767 val = RREG32_PLL(reg);
2768 val = (val & and_mask) | or_mask;
2769 WREG32_PLL(reg, val);
2770 break;
2771 case 6:
2772 reg = id & 0x1fff;
2773 val = RBIOS8(index);
2774 index += 1;
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002775 radeon_i2c_put_byte(tmds->i2c_bus,
2776 tmds->slave_addr,
2777 reg, val);
Alex Deucherfcec5702009-11-10 21:25:07 -05002778 break;
2779 default:
2780 DRM_ERROR("Unknown id %d\n", id >> 13);
2781 break;
2782 }
2783 id = RBIOS16(index);
2784 }
2785 return true;
2786 }
2787 }
2788 return false;
2789}
2790
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002791static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
2792{
2793 struct radeon_device *rdev = dev->dev_private;
2794
2795 if (offset) {
2796 while (RBIOS16(offset)) {
2797 uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
2798 uint32_t addr = (RBIOS16(offset) & 0x1fff);
2799 uint32_t val, and_mask, or_mask;
2800 uint32_t tmp;
2801
2802 offset += 2;
2803 switch (cmd) {
2804 case 0:
2805 val = RBIOS32(offset);
2806 offset += 4;
2807 WREG32(addr, val);
2808 break;
2809 case 1:
2810 val = RBIOS32(offset);
2811 offset += 4;
2812 WREG32(addr, val);
2813 break;
2814 case 2:
2815 and_mask = RBIOS32(offset);
2816 offset += 4;
2817 or_mask = RBIOS32(offset);
2818 offset += 4;
2819 tmp = RREG32(addr);
2820 tmp &= and_mask;
2821 tmp |= or_mask;
2822 WREG32(addr, tmp);
2823 break;
2824 case 3:
2825 and_mask = RBIOS32(offset);
2826 offset += 4;
2827 or_mask = RBIOS32(offset);
2828 offset += 4;
2829 tmp = RREG32(addr);
2830 tmp &= and_mask;
2831 tmp |= or_mask;
2832 WREG32(addr, tmp);
2833 break;
2834 case 4:
2835 val = RBIOS16(offset);
2836 offset += 2;
2837 udelay(val);
2838 break;
2839 case 5:
2840 val = RBIOS16(offset);
2841 offset += 2;
2842 switch (addr) {
2843 case 8:
2844 while (val--) {
2845 if (!
2846 (RREG32_PLL
2847 (RADEON_CLK_PWRMGT_CNTL) &
2848 RADEON_MC_BUSY))
2849 break;
2850 }
2851 break;
2852 case 9:
2853 while (val--) {
2854 if ((RREG32(RADEON_MC_STATUS) &
2855 RADEON_MC_IDLE))
2856 break;
2857 }
2858 break;
2859 default:
2860 break;
2861 }
2862 break;
2863 default:
2864 break;
2865 }
2866 }
2867 }
2868}
2869
2870static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
2871{
2872 struct radeon_device *rdev = dev->dev_private;
2873
2874 if (offset) {
2875 while (RBIOS8(offset)) {
2876 uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
2877 uint8_t addr = (RBIOS8(offset) & 0x3f);
2878 uint32_t val, shift, tmp;
2879 uint32_t and_mask, or_mask;
2880
2881 offset++;
2882 switch (cmd) {
2883 case 0:
2884 val = RBIOS32(offset);
2885 offset += 4;
2886 WREG32_PLL(addr, val);
2887 break;
2888 case 1:
2889 shift = RBIOS8(offset) * 8;
2890 offset++;
2891 and_mask = RBIOS8(offset) << shift;
2892 and_mask |= ~(0xff << shift);
2893 offset++;
2894 or_mask = RBIOS8(offset) << shift;
2895 offset++;
2896 tmp = RREG32_PLL(addr);
2897 tmp &= and_mask;
2898 tmp |= or_mask;
2899 WREG32_PLL(addr, tmp);
2900 break;
2901 case 2:
2902 case 3:
2903 tmp = 1000;
2904 switch (addr) {
2905 case 1:
2906 udelay(150);
2907 break;
2908 case 2:
2909 udelay(1000);
2910 break;
2911 case 3:
2912 while (tmp--) {
2913 if (!
2914 (RREG32_PLL
2915 (RADEON_CLK_PWRMGT_CNTL) &
2916 RADEON_MC_BUSY))
2917 break;
2918 }
2919 break;
2920 case 4:
2921 while (tmp--) {
2922 if (RREG32_PLL
2923 (RADEON_CLK_PWRMGT_CNTL) &
2924 RADEON_DLL_READY)
2925 break;
2926 }
2927 break;
2928 case 5:
2929 tmp =
2930 RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
2931 if (tmp & RADEON_CG_NO1_DEBUG_0) {
2932#if 0
2933 uint32_t mclk_cntl =
2934 RREG32_PLL
2935 (RADEON_MCLK_CNTL);
2936 mclk_cntl &= 0xffff0000;
2937 /*mclk_cntl |= 0x00001111;*//* ??? */
2938 WREG32_PLL(RADEON_MCLK_CNTL,
2939 mclk_cntl);
2940 udelay(10000);
2941#endif
2942 WREG32_PLL
2943 (RADEON_CLK_PWRMGT_CNTL,
2944 tmp &
2945 ~RADEON_CG_NO1_DEBUG_0);
2946 udelay(10000);
2947 }
2948 break;
2949 default:
2950 break;
2951 }
2952 break;
2953 default:
2954 break;
2955 }
2956 }
2957 }
2958}
2959
2960static void combios_parse_ram_reset_table(struct drm_device *dev,
2961 uint16_t offset)
2962{
2963 struct radeon_device *rdev = dev->dev_private;
2964 uint32_t tmp;
2965
2966 if (offset) {
2967 uint8_t val = RBIOS8(offset);
2968 while (val != 0xff) {
2969 offset++;
2970
2971 if (val == 0x0f) {
2972 uint32_t channel_complete_mask;
2973
2974 if (ASIC_IS_R300(rdev))
2975 channel_complete_mask =
2976 R300_MEM_PWRUP_COMPLETE;
2977 else
2978 channel_complete_mask =
2979 RADEON_MEM_PWRUP_COMPLETE;
2980 tmp = 20000;
2981 while (tmp--) {
2982 if ((RREG32(RADEON_MEM_STR_CNTL) &
2983 channel_complete_mask) ==
2984 channel_complete_mask)
2985 break;
2986 }
2987 } else {
2988 uint32_t or_mask = RBIOS16(offset);
2989 offset += 2;
2990
2991 tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
2992 tmp &= RADEON_SDRAM_MODE_MASK;
2993 tmp |= or_mask;
2994 WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
2995
2996 or_mask = val << 24;
2997 tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
2998 tmp &= RADEON_B3MEM_RESET_MASK;
2999 tmp |= or_mask;
3000 WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
3001 }
3002 val = RBIOS8(offset);
3003 }
3004 }
3005}
3006
3007static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
3008 int mem_addr_mapping)
3009{
3010 struct radeon_device *rdev = dev->dev_private;
3011 uint32_t mem_cntl;
3012 uint32_t mem_size;
3013 uint32_t addr = 0;
3014
3015 mem_cntl = RREG32(RADEON_MEM_CNTL);
3016 if (mem_cntl & RV100_HALF_MODE)
3017 ram /= 2;
3018 mem_size = ram;
3019 mem_cntl &= ~(0xff << 8);
3020 mem_cntl |= (mem_addr_mapping & 0xff) << 8;
3021 WREG32(RADEON_MEM_CNTL, mem_cntl);
3022 RREG32(RADEON_MEM_CNTL);
3023
3024 /* sdram reset ? */
3025
3026 /* something like this???? */
3027 while (ram--) {
3028 addr = ram * 1024 * 1024;
3029 /* write to each page */
3030 WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
3031 WREG32(RADEON_MM_DATA, 0xdeadbeef);
3032 /* read back and verify */
3033 WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
3034 if (RREG32(RADEON_MM_DATA) != 0xdeadbeef)
3035 return 0;
3036 }
3037
3038 return mem_size;
3039}
3040
3041static void combios_write_ram_size(struct drm_device *dev)
3042{
3043 struct radeon_device *rdev = dev->dev_private;
3044 uint8_t rev;
3045 uint16_t offset;
3046 uint32_t mem_size = 0;
3047 uint32_t mem_cntl = 0;
3048
3049 /* should do something smarter here I guess... */
3050 if (rdev->flags & RADEON_IS_IGP)
3051 return;
3052
3053 /* first check detected mem table */
3054 offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
3055 if (offset) {
3056 rev = RBIOS8(offset);
3057 if (rev < 3) {
3058 mem_cntl = RBIOS32(offset + 1);
3059 mem_size = RBIOS16(offset + 5);
Alex Deucher4ce91982010-06-30 12:13:55 -04003060 if ((rdev->family < CHIP_R200) &&
3061 !ASIC_IS_RN50(rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003062 WREG32(RADEON_MEM_CNTL, mem_cntl);
3063 }
3064 }
3065
3066 if (!mem_size) {
3067 offset =
3068 combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
3069 if (offset) {
3070 rev = RBIOS8(offset - 1);
3071 if (rev < 1) {
Alex Deucher4ce91982010-06-30 12:13:55 -04003072 if ((rdev->family < CHIP_R200)
3073 && !ASIC_IS_RN50(rdev)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003074 int ram = 0;
3075 int mem_addr_mapping = 0;
3076
3077 while (RBIOS8(offset)) {
3078 ram = RBIOS8(offset);
3079 mem_addr_mapping =
3080 RBIOS8(offset + 1);
3081 if (mem_addr_mapping != 0x25)
3082 ram *= 2;
3083 mem_size =
3084 combios_detect_ram(dev, ram,
3085 mem_addr_mapping);
3086 if (mem_size)
3087 break;
3088 offset += 2;
3089 }
3090 } else
3091 mem_size = RBIOS8(offset);
3092 } else {
3093 mem_size = RBIOS8(offset);
3094 mem_size *= 2; /* convert to MB */
3095 }
3096 }
3097 }
3098
3099 mem_size *= (1024 * 1024); /* convert to bytes */
3100 WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
3101}
3102
3103void radeon_combios_dyn_clk_setup(struct drm_device *dev, int enable)
3104{
3105 uint16_t dyn_clk_info =
3106 combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
3107
3108 if (dyn_clk_info)
3109 combios_parse_pll_table(dev, dyn_clk_info);
3110}
3111
3112void radeon_combios_asic_init(struct drm_device *dev)
3113{
3114 struct radeon_device *rdev = dev->dev_private;
3115 uint16_t table;
3116
3117 /* port hardcoded mac stuff from radeonfb */
3118 if (rdev->bios == NULL)
3119 return;
3120
3121 /* ASIC INIT 1 */
3122 table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
3123 if (table)
3124 combios_parse_mmio_table(dev, table);
3125
3126 /* PLL INIT */
3127 table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
3128 if (table)
3129 combios_parse_pll_table(dev, table);
3130
3131 /* ASIC INIT 2 */
3132 table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
3133 if (table)
3134 combios_parse_mmio_table(dev, table);
3135
3136 if (!(rdev->flags & RADEON_IS_IGP)) {
3137 /* ASIC INIT 4 */
3138 table =
3139 combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
3140 if (table)
3141 combios_parse_mmio_table(dev, table);
3142
3143 /* RAM RESET */
3144 table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
3145 if (table)
3146 combios_parse_ram_reset_table(dev, table);
3147
3148 /* ASIC INIT 3 */
3149 table =
3150 combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
3151 if (table)
3152 combios_parse_mmio_table(dev, table);
3153
3154 /* write CONFIG_MEMSIZE */
3155 combios_write_ram_size(dev);
3156 }
3157
Dave Airlie580b4ff2010-06-30 13:26:11 +10003158 /* quirk for rs4xx HP nx6125 laptop to make it resume
3159 * - it hangs on resume inside the dynclk 1 table.
3160 */
3161 if (rdev->family == CHIP_RS480 &&
3162 rdev->pdev->subsystem_vendor == 0x103c &&
3163 rdev->pdev->subsystem_device == 0x308b)
3164 return;
3165
Alex Deucher52fa2bb2010-07-21 23:54:35 -04003166 /* quirk for rs4xx HP dv5000 laptop to make it resume
3167 * - it hangs on resume inside the dynclk 1 table.
3168 */
3169 if (rdev->family == CHIP_RS480 &&
3170 rdev->pdev->subsystem_vendor == 0x103c &&
3171 rdev->pdev->subsystem_device == 0x30a4)
3172 return;
3173
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003174 /* DYN CLK 1 */
3175 table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
3176 if (table)
3177 combios_parse_pll_table(dev, table);
3178
3179}
3180
3181void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
3182{
3183 struct radeon_device *rdev = dev->dev_private;
3184 uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
3185
3186 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
3187 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3188 bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
3189
3190 /* let the bios control the backlight */
3191 bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
3192
3193 /* tell the bios not to handle mode switching */
3194 bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
3195 RADEON_ACC_MODE_CHANGE);
3196
3197 /* tell the bios a driver is loaded */
3198 bios_7_scratch |= RADEON_DRV_LOADED;
3199
3200 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
3201 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3202 WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
3203}
3204
3205void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
3206{
3207 struct drm_device *dev = encoder->dev;
3208 struct radeon_device *rdev = dev->dev_private;
3209 uint32_t bios_6_scratch;
3210
3211 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3212
3213 if (lock)
3214 bios_6_scratch |= RADEON_DRIVER_CRITICAL;
3215 else
3216 bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
3217
3218 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3219}
3220
3221void
3222radeon_combios_connected_scratch_regs(struct drm_connector *connector,
3223 struct drm_encoder *encoder,
3224 bool connected)
3225{
3226 struct drm_device *dev = connector->dev;
3227 struct radeon_device *rdev = dev->dev_private;
3228 struct radeon_connector *radeon_connector =
3229 to_radeon_connector(connector);
3230 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3231 uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
3232 uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
3233
3234 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
3235 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
3236 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003237 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003238 /* fix me */
3239 bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
3240 /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
3241 bios_5_scratch |= RADEON_TV1_ON;
3242 bios_5_scratch |= RADEON_ACC_REQ_TV1;
3243 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003244 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003245 bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
3246 bios_5_scratch &= ~RADEON_TV1_ON;
3247 bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
3248 }
3249 }
3250 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
3251 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
3252 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003253 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003254 bios_4_scratch |= RADEON_LCD1_ATTACHED;
3255 bios_5_scratch |= RADEON_LCD1_ON;
3256 bios_5_scratch |= RADEON_ACC_REQ_LCD1;
3257 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003258 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003259 bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
3260 bios_5_scratch &= ~RADEON_LCD1_ON;
3261 bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
3262 }
3263 }
3264 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
3265 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
3266 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003267 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003268 bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
3269 bios_5_scratch |= RADEON_CRT1_ON;
3270 bios_5_scratch |= RADEON_ACC_REQ_CRT1;
3271 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003272 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003273 bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
3274 bios_5_scratch &= ~RADEON_CRT1_ON;
3275 bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
3276 }
3277 }
3278 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
3279 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
3280 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003281 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003282 bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
3283 bios_5_scratch |= RADEON_CRT2_ON;
3284 bios_5_scratch |= RADEON_ACC_REQ_CRT2;
3285 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003286 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003287 bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
3288 bios_5_scratch &= ~RADEON_CRT2_ON;
3289 bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
3290 }
3291 }
3292 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
3293 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
3294 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003295 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003296 bios_4_scratch |= RADEON_DFP1_ATTACHED;
3297 bios_5_scratch |= RADEON_DFP1_ON;
3298 bios_5_scratch |= RADEON_ACC_REQ_DFP1;
3299 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003300 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003301 bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
3302 bios_5_scratch &= ~RADEON_DFP1_ON;
3303 bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
3304 }
3305 }
3306 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
3307 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
3308 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003309 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003310 bios_4_scratch |= RADEON_DFP2_ATTACHED;
3311 bios_5_scratch |= RADEON_DFP2_ON;
3312 bios_5_scratch |= RADEON_ACC_REQ_DFP2;
3313 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003314 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003315 bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
3316 bios_5_scratch &= ~RADEON_DFP2_ON;
3317 bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
3318 }
3319 }
3320 WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
3321 WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
3322}
3323
3324void
3325radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
3326{
3327 struct drm_device *dev = encoder->dev;
3328 struct radeon_device *rdev = dev->dev_private;
3329 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3330 uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
3331
3332 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
3333 bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
3334 bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
3335 }
3336 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3337 bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
3338 bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
3339 }
3340 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3341 bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
3342 bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
3343 }
3344 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3345 bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
3346 bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
3347 }
3348 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3349 bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
3350 bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
3351 }
3352 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3353 bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
3354 bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
3355 }
3356 WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
3357}
3358
3359void
3360radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
3361{
3362 struct drm_device *dev = encoder->dev;
3363 struct radeon_device *rdev = dev->dev_private;
3364 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3365 uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3366
3367 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
3368 if (on)
3369 bios_6_scratch |= RADEON_TV_DPMS_ON;
3370 else
3371 bios_6_scratch &= ~RADEON_TV_DPMS_ON;
3372 }
3373 if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
3374 if (on)
3375 bios_6_scratch |= RADEON_CRT_DPMS_ON;
3376 else
3377 bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
3378 }
3379 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
3380 if (on)
3381 bios_6_scratch |= RADEON_LCD_DPMS_ON;
3382 else
3383 bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
3384 }
3385 if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
3386 if (on)
3387 bios_6_scratch |= RADEON_DFP_DPMS_ON;
3388 else
3389 bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
3390 }
3391 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3392}