blob: 5e1474cde4b4245b7ce8c6b6968da03568a6dc5f [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
42radeon_get_encoder_id(struct drm_device *dev, uint32_t supported_device,
43 uint8_t dac);
44extern 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
58radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id,
59 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{
451 int edid_info;
452 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;
459 edid = kmalloc(EDID_LENGTH * (raw[0x7e] + 1), GFP_KERNEL);
Alex Deucher3c537882010-02-05 04:21:19 -0500460 if (edid == NULL)
461 return false;
462
Adam Jackson7466f4c2010-03-29 21:43:23 +0000463 memcpy((unsigned char *)edid, raw, EDID_LENGTH * (raw[0x7e] + 1));
Alex Deucher3c537882010-02-05 04:21:19 -0500464
465 if (!drm_edid_is_valid(edid)) {
466 kfree(edid);
467 return false;
468 }
469
470 rdev->mode_info.bios_hardcoded_edid = edid;
471 return true;
472}
473
474struct edid *
475radeon_combios_get_hardcoded_edid(struct radeon_device *rdev)
476{
477 if (rdev->mode_info.bios_hardcoded_edid)
478 return rdev->mode_info.bios_hardcoded_edid;
479 return NULL;
480}
481
Alex Deucher6a93cb22009-11-23 17:39:28 -0500482static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
483 int ddc_line)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200484{
485 struct radeon_i2c_bus_rec i2c;
486
Alex Deucher6a93cb22009-11-23 17:39:28 -0500487 if (ddc_line == RADEON_GPIOPAD_MASK) {
488 i2c.mask_clk_reg = RADEON_GPIOPAD_MASK;
489 i2c.mask_data_reg = RADEON_GPIOPAD_MASK;
490 i2c.a_clk_reg = RADEON_GPIOPAD_A;
491 i2c.a_data_reg = RADEON_GPIOPAD_A;
492 i2c.en_clk_reg = RADEON_GPIOPAD_EN;
493 i2c.en_data_reg = RADEON_GPIOPAD_EN;
494 i2c.y_clk_reg = RADEON_GPIOPAD_Y;
495 i2c.y_data_reg = RADEON_GPIOPAD_Y;
496 } else if (ddc_line == RADEON_MDGPIO_MASK) {
497 i2c.mask_clk_reg = RADEON_MDGPIO_MASK;
498 i2c.mask_data_reg = RADEON_MDGPIO_MASK;
499 i2c.a_clk_reg = RADEON_MDGPIO_A;
500 i2c.a_data_reg = RADEON_MDGPIO_A;
501 i2c.en_clk_reg = RADEON_MDGPIO_EN;
502 i2c.en_data_reg = RADEON_MDGPIO_EN;
503 i2c.y_clk_reg = RADEON_MDGPIO_Y;
504 i2c.y_data_reg = RADEON_MDGPIO_Y;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200505 } else {
Alex Deucher6a93cb22009-11-23 17:39:28 -0500506 i2c.mask_clk_mask = RADEON_GPIO_EN_1;
507 i2c.mask_data_mask = RADEON_GPIO_EN_0;
508 i2c.a_clk_mask = RADEON_GPIO_A_1;
509 i2c.a_data_mask = RADEON_GPIO_A_0;
510 i2c.en_clk_mask = RADEON_GPIO_EN_1;
511 i2c.en_data_mask = RADEON_GPIO_EN_0;
512 i2c.y_clk_mask = RADEON_GPIO_Y_1;
513 i2c.y_data_mask = RADEON_GPIO_Y_0;
514
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200515 i2c.mask_clk_reg = ddc_line;
516 i2c.mask_data_reg = ddc_line;
517 i2c.a_clk_reg = ddc_line;
518 i2c.a_data_reg = ddc_line;
Alex Deucher9b9fe722009-11-10 15:59:44 -0500519 i2c.en_clk_reg = ddc_line;
520 i2c.en_data_reg = ddc_line;
521 i2c.y_clk_reg = ddc_line;
522 i2c.y_data_reg = ddc_line;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200523 }
524
Alex Deucher40bacf12009-12-23 03:23:21 -0500525 switch (rdev->family) {
526 case CHIP_R100:
527 case CHIP_RV100:
528 case CHIP_RS100:
529 case CHIP_RV200:
530 case CHIP_RS200:
531 case CHIP_RS300:
532 switch (ddc_line) {
533 case RADEON_GPIO_DVI_DDC:
Alex Deucherb28ea412010-03-12 13:30:49 -0500534 i2c.hw_capable = true;
Alex Deucher40bacf12009-12-23 03:23:21 -0500535 break;
536 default:
537 i2c.hw_capable = false;
538 break;
539 }
540 break;
541 case CHIP_R200:
542 switch (ddc_line) {
543 case RADEON_GPIO_DVI_DDC:
544 case RADEON_GPIO_MONID:
545 i2c.hw_capable = true;
546 break;
547 default:
548 i2c.hw_capable = false;
549 break;
550 }
551 break;
552 case CHIP_RV250:
553 case CHIP_RV280:
554 switch (ddc_line) {
555 case RADEON_GPIO_VGA_DDC:
556 case RADEON_GPIO_DVI_DDC:
557 case RADEON_GPIO_CRT2_DDC:
558 i2c.hw_capable = true;
559 break;
560 default:
561 i2c.hw_capable = false;
562 break;
563 }
564 break;
565 case CHIP_R300:
566 case CHIP_R350:
567 switch (ddc_line) {
568 case RADEON_GPIO_VGA_DDC:
569 case RADEON_GPIO_DVI_DDC:
570 i2c.hw_capable = true;
571 break;
572 default:
573 i2c.hw_capable = false;
574 break;
575 }
576 break;
577 case CHIP_RV350:
578 case CHIP_RV380:
579 case CHIP_RS400:
580 case CHIP_RS480:
Alex Deucher6a93cb22009-11-23 17:39:28 -0500581 switch (ddc_line) {
582 case RADEON_GPIO_VGA_DDC:
583 case RADEON_GPIO_DVI_DDC:
584 i2c.hw_capable = true;
585 break;
586 case RADEON_GPIO_MONID:
587 /* hw i2c on RADEON_GPIO_MONID doesn't seem to work
588 * reliably on some pre-r4xx hardware; not sure why.
589 */
590 i2c.hw_capable = false;
591 break;
592 default:
593 i2c.hw_capable = false;
594 break;
595 }
Alex Deucher40bacf12009-12-23 03:23:21 -0500596 break;
597 default:
598 i2c.hw_capable = false;
599 break;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500600 }
601 i2c.mm_i2c = false;
602 i2c.i2c_id = 0;
Alex Deucher8e36ed02010-05-18 19:26:47 -0400603 i2c.hpd = RADEON_HPD_NONE;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500604
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200605 if (ddc_line)
606 i2c.valid = true;
607 else
608 i2c.valid = false;
609
610 return i2c;
611}
612
613bool radeon_combios_get_clock_info(struct drm_device *dev)
614{
615 struct radeon_device *rdev = dev->dev_private;
616 uint16_t pll_info;
617 struct radeon_pll *p1pll = &rdev->clock.p1pll;
618 struct radeon_pll *p2pll = &rdev->clock.p2pll;
619 struct radeon_pll *spll = &rdev->clock.spll;
620 struct radeon_pll *mpll = &rdev->clock.mpll;
621 int8_t rev;
622 uint16_t sclk, mclk;
623
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200624 pll_info = combios_get_table_offset(dev, COMBIOS_PLL_INFO_TABLE);
625 if (pll_info) {
626 rev = RBIOS8(pll_info);
627
628 /* pixel clocks */
629 p1pll->reference_freq = RBIOS16(pll_info + 0xe);
630 p1pll->reference_div = RBIOS16(pll_info + 0x10);
631 p1pll->pll_out_min = RBIOS32(pll_info + 0x12);
632 p1pll->pll_out_max = RBIOS32(pll_info + 0x16);
Alex Deucher86cb2bb2010-03-08 12:55:16 -0500633 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
634 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200635
636 if (rev > 9) {
637 p1pll->pll_in_min = RBIOS32(pll_info + 0x36);
638 p1pll->pll_in_max = RBIOS32(pll_info + 0x3a);
639 } else {
640 p1pll->pll_in_min = 40;
641 p1pll->pll_in_max = 500;
642 }
643 *p2pll = *p1pll;
644
645 /* system clock */
646 spll->reference_freq = RBIOS16(pll_info + 0x1a);
647 spll->reference_div = RBIOS16(pll_info + 0x1c);
648 spll->pll_out_min = RBIOS32(pll_info + 0x1e);
649 spll->pll_out_max = RBIOS32(pll_info + 0x22);
650
651 if (rev > 10) {
652 spll->pll_in_min = RBIOS32(pll_info + 0x48);
653 spll->pll_in_max = RBIOS32(pll_info + 0x4c);
654 } else {
655 /* ??? */
656 spll->pll_in_min = 40;
657 spll->pll_in_max = 500;
658 }
659
660 /* memory clock */
661 mpll->reference_freq = RBIOS16(pll_info + 0x26);
662 mpll->reference_div = RBIOS16(pll_info + 0x28);
663 mpll->pll_out_min = RBIOS32(pll_info + 0x2a);
664 mpll->pll_out_max = RBIOS32(pll_info + 0x2e);
665
666 if (rev > 10) {
667 mpll->pll_in_min = RBIOS32(pll_info + 0x5a);
668 mpll->pll_in_max = RBIOS32(pll_info + 0x5e);
669 } else {
670 /* ??? */
671 mpll->pll_in_min = 40;
672 mpll->pll_in_max = 500;
673 }
674
675 /* default sclk/mclk */
676 sclk = RBIOS16(pll_info + 0xa);
677 mclk = RBIOS16(pll_info + 0x8);
678 if (sclk == 0)
679 sclk = 200 * 100;
680 if (mclk == 0)
681 mclk = 200 * 100;
682
683 rdev->clock.default_sclk = sclk;
684 rdev->clock.default_mclk = mclk;
685
686 return true;
687 }
688 return false;
689}
690
Alex Deucher06b64762010-01-05 11:27:29 -0500691bool radeon_combios_sideport_present(struct radeon_device *rdev)
692{
693 struct drm_device *dev = rdev->ddev;
694 u16 igp_info;
695
Alex Deucher4c70b2e2010-08-02 19:39:15 -0400696 /* sideport is AMD only */
697 if (rdev->family == CHIP_RS400)
698 return false;
699
Alex Deucher06b64762010-01-05 11:27:29 -0500700 igp_info = combios_get_table_offset(dev, COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE);
701
702 if (igp_info) {
703 if (RBIOS16(igp_info + 0x4))
704 return true;
705 }
706 return false;
707}
708
Alex Deucher246263c2009-12-29 12:09:17 -0500709static const uint32_t default_primarydac_adj[CHIP_LAST] = {
710 0x00000808, /* r100 */
711 0x00000808, /* rv100 */
712 0x00000808, /* rs100 */
713 0x00000808, /* rv200 */
714 0x00000808, /* rs200 */
715 0x00000808, /* r200 */
716 0x00000808, /* rv250 */
717 0x00000000, /* rs300 */
718 0x00000808, /* rv280 */
719 0x00000808, /* r300 */
720 0x00000808, /* r350 */
721 0x00000808, /* rv350 */
722 0x00000808, /* rv380 */
723 0x00000808, /* r420 */
724 0x00000808, /* r423 */
725 0x00000808, /* rv410 */
726 0x00000000, /* rs400 */
727 0x00000000, /* rs480 */
728};
729
730static void radeon_legacy_get_primary_dac_info_from_table(struct radeon_device *rdev,
731 struct radeon_encoder_primary_dac *p_dac)
732{
733 p_dac->ps2_pdac_adj = default_primarydac_adj[rdev->family];
734 return;
735}
736
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200737struct radeon_encoder_primary_dac *radeon_combios_get_primary_dac_info(struct
738 radeon_encoder
739 *encoder)
740{
741 struct drm_device *dev = encoder->base.dev;
742 struct radeon_device *rdev = dev->dev_private;
743 uint16_t dac_info;
744 uint8_t rev, bg, dac;
745 struct radeon_encoder_primary_dac *p_dac = NULL;
Alex Deucher246263c2009-12-29 12:09:17 -0500746 int found = 0;
747
748 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac),
749 GFP_KERNEL);
750
751 if (!p_dac)
752 return NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200753
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200754 /* check CRT table */
755 dac_info = combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
756 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200757 rev = RBIOS8(dac_info) & 0x3;
758 if (rev < 2) {
759 bg = RBIOS8(dac_info + 0x2) & 0xf;
760 dac = (RBIOS8(dac_info + 0x2) >> 4) & 0xf;
761 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
762 } else {
763 bg = RBIOS8(dac_info + 0x2) & 0xf;
764 dac = RBIOS8(dac_info + 0x3) & 0xf;
765 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
766 }
Alex Deucher3a89b4a2010-04-06 12:35:26 -0400767 /* if the values are all zeros, use the table */
768 if (p_dac->ps2_pdac_adj)
769 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200770 }
771
Alex Deucher246263c2009-12-29 12:09:17 -0500772 if (!found) /* fallback to defaults */
773 radeon_legacy_get_primary_dac_info_from_table(rdev, p_dac);
774
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200775 return p_dac;
776}
777
Alex Deucherd79766f2009-12-17 19:00:29 -0500778enum radeon_tv_std
779radeon_combios_get_tv_info(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200780{
Alex Deucherd79766f2009-12-17 19:00:29 -0500781 struct drm_device *dev = rdev->ddev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200782 uint16_t tv_info;
783 enum radeon_tv_std tv_std = TV_STD_NTSC;
784
785 tv_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
786 if (tv_info) {
787 if (RBIOS8(tv_info + 6) == 'T') {
788 switch (RBIOS8(tv_info + 7) & 0xf) {
789 case 1:
790 tv_std = TV_STD_NTSC;
791 DRM_INFO("Default TV standard: NTSC\n");
792 break;
793 case 2:
794 tv_std = TV_STD_PAL;
795 DRM_INFO("Default TV standard: PAL\n");
796 break;
797 case 3:
798 tv_std = TV_STD_PAL_M;
799 DRM_INFO("Default TV standard: PAL-M\n");
800 break;
801 case 4:
802 tv_std = TV_STD_PAL_60;
803 DRM_INFO("Default TV standard: PAL-60\n");
804 break;
805 case 5:
806 tv_std = TV_STD_NTSC_J;
807 DRM_INFO("Default TV standard: NTSC-J\n");
808 break;
809 case 6:
810 tv_std = TV_STD_SCART_PAL;
811 DRM_INFO("Default TV standard: SCART-PAL\n");
812 break;
813 default:
814 tv_std = TV_STD_NTSC;
815 DRM_INFO
816 ("Unknown TV standard; defaulting to NTSC\n");
817 break;
818 }
819
820 switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) {
821 case 0:
822 DRM_INFO("29.498928713 MHz TV ref clk\n");
823 break;
824 case 1:
825 DRM_INFO("28.636360000 MHz TV ref clk\n");
826 break;
827 case 2:
828 DRM_INFO("14.318180000 MHz TV ref clk\n");
829 break;
830 case 3:
831 DRM_INFO("27.000000000 MHz TV ref clk\n");
832 break;
833 default:
834 break;
835 }
836 }
837 }
838 return tv_std;
839}
840
841static const uint32_t default_tvdac_adj[CHIP_LAST] = {
842 0x00000000, /* r100 */
843 0x00280000, /* rv100 */
844 0x00000000, /* rs100 */
845 0x00880000, /* rv200 */
846 0x00000000, /* rs200 */
847 0x00000000, /* r200 */
848 0x00770000, /* rv250 */
849 0x00290000, /* rs300 */
850 0x00560000, /* rv280 */
851 0x00780000, /* r300 */
852 0x00770000, /* r350 */
853 0x00780000, /* rv350 */
854 0x00780000, /* rv380 */
855 0x01080000, /* r420 */
856 0x01080000, /* r423 */
857 0x01080000, /* rv410 */
858 0x00780000, /* rs400 */
859 0x00780000, /* rs480 */
860};
861
Dave Airlie6a719e02009-08-17 10:19:51 +1000862static void radeon_legacy_get_tv_dac_info_from_table(struct radeon_device *rdev,
863 struct radeon_encoder_tv_dac *tv_dac)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200864{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200865 tv_dac->ps2_tvdac_adj = default_tvdac_adj[rdev->family];
866 if ((rdev->flags & RADEON_IS_MOBILITY) && (rdev->family == CHIP_RV250))
867 tv_dac->ps2_tvdac_adj = 0x00880000;
868 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
869 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Dave Airlie6a719e02009-08-17 10:19:51 +1000870 return;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200871}
872
873struct radeon_encoder_tv_dac *radeon_combios_get_tv_dac_info(struct
874 radeon_encoder
875 *encoder)
876{
877 struct drm_device *dev = encoder->base.dev;
878 struct radeon_device *rdev = dev->dev_private;
879 uint16_t dac_info;
880 uint8_t rev, bg, dac;
881 struct radeon_encoder_tv_dac *tv_dac = NULL;
Dave Airlie6a719e02009-08-17 10:19:51 +1000882 int found = 0;
883
884 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
885 if (!tv_dac)
886 return NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200887
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200888 /* first check TV table */
889 dac_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
890 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200891 rev = RBIOS8(dac_info + 0x3);
892 if (rev > 4) {
893 bg = RBIOS8(dac_info + 0xc) & 0xf;
894 dac = RBIOS8(dac_info + 0xd) & 0xf;
895 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
896
897 bg = RBIOS8(dac_info + 0xe) & 0xf;
898 dac = RBIOS8(dac_info + 0xf) & 0xf;
899 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
900
901 bg = RBIOS8(dac_info + 0x10) & 0xf;
902 dac = RBIOS8(dac_info + 0x11) & 0xf;
903 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
Alex Deucher3a89b4a2010-04-06 12:35:26 -0400904 /* if the values are all zeros, use the table */
905 if (tv_dac->ps2_tvdac_adj)
906 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200907 } else if (rev > 1) {
908 bg = RBIOS8(dac_info + 0xc) & 0xf;
909 dac = (RBIOS8(dac_info + 0xc) >> 4) & 0xf;
910 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
911
912 bg = RBIOS8(dac_info + 0xd) & 0xf;
913 dac = (RBIOS8(dac_info + 0xd) >> 4) & 0xf;
914 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
915
916 bg = RBIOS8(dac_info + 0xe) & 0xf;
917 dac = (RBIOS8(dac_info + 0xe) >> 4) & 0xf;
918 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
Alex Deucher3a89b4a2010-04-06 12:35:26 -0400919 /* if the values are all zeros, use the table */
920 if (tv_dac->ps2_tvdac_adj)
921 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200922 }
Alex Deucherd79766f2009-12-17 19:00:29 -0500923 tv_dac->tv_std = radeon_combios_get_tv_info(rdev);
Dave Airlie6a719e02009-08-17 10:19:51 +1000924 }
925 if (!found) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200926 /* then check CRT table */
927 dac_info =
928 combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
929 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200930 rev = RBIOS8(dac_info) & 0x3;
931 if (rev < 2) {
932 bg = RBIOS8(dac_info + 0x3) & 0xf;
933 dac = (RBIOS8(dac_info + 0x3) >> 4) & 0xf;
934 tv_dac->ps2_tvdac_adj =
935 (bg << 16) | (dac << 20);
936 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
937 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Alex Deucher3a89b4a2010-04-06 12:35:26 -0400938 /* if the values are all zeros, use the table */
939 if (tv_dac->ps2_tvdac_adj)
940 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200941 } else {
942 bg = RBIOS8(dac_info + 0x4) & 0xf;
943 dac = RBIOS8(dac_info + 0x5) & 0xf;
944 tv_dac->ps2_tvdac_adj =
945 (bg << 16) | (dac << 20);
946 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
947 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Alex Deucher3a89b4a2010-04-06 12:35:26 -0400948 /* if the values are all zeros, use the table */
949 if (tv_dac->ps2_tvdac_adj)
950 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200951 }
Alex Deucher6fe7ac32009-06-12 17:26:08 +0000952 } else {
953 DRM_INFO("No TV DAC info found in BIOS\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200954 }
955 }
956
Dave Airlie6a719e02009-08-17 10:19:51 +1000957 if (!found) /* fallback to defaults */
958 radeon_legacy_get_tv_dac_info_from_table(rdev, tv_dac);
959
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200960 return tv_dac;
961}
962
963static struct radeon_encoder_lvds *radeon_legacy_get_lvds_info_from_regs(struct
964 radeon_device
965 *rdev)
966{
967 struct radeon_encoder_lvds *lvds = NULL;
968 uint32_t fp_vert_stretch, fp_horz_stretch;
969 uint32_t ppll_div_sel, ppll_val;
Michel Dänzer8b5c7442009-06-17 18:28:38 +0200970 uint32_t lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200971
972 lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
973
974 if (!lvds)
975 return NULL;
976
977 fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH);
978 fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH);
979
Michel Dänzer8b5c7442009-06-17 18:28:38 +0200980 /* These should be fail-safe defaults, fingers crossed */
981 lvds->panel_pwr_delay = 200;
982 lvds->panel_vcc_delay = 2000;
983
984 lvds->lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
985 lvds->panel_digon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) & 0xf;
986 lvds->panel_blon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY2_SHIFT) & 0xf;
987
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200988 if (fp_vert_stretch & RADEON_VERT_STRETCH_ENABLE)
Alex Deucherde2103e2009-10-09 15:14:30 -0400989 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200990 ((fp_vert_stretch & RADEON_VERT_PANEL_SIZE) >>
991 RADEON_VERT_PANEL_SHIFT) + 1;
992 else
Alex Deucherde2103e2009-10-09 15:14:30 -0400993 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200994 (RREG32(RADEON_CRTC_V_TOTAL_DISP) >> 16) + 1;
995
996 if (fp_horz_stretch & RADEON_HORZ_STRETCH_ENABLE)
Alex Deucherde2103e2009-10-09 15:14:30 -0400997 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200998 (((fp_horz_stretch & RADEON_HORZ_PANEL_SIZE) >>
999 RADEON_HORZ_PANEL_SHIFT) + 1) * 8;
1000 else
Alex Deucherde2103e2009-10-09 15:14:30 -04001001 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001002 ((RREG32(RADEON_CRTC_H_TOTAL_DISP) >> 16) + 1) * 8;
1003
Alex Deucherde2103e2009-10-09 15:14:30 -04001004 if ((lvds->native_mode.hdisplay < 640) ||
1005 (lvds->native_mode.vdisplay < 480)) {
1006 lvds->native_mode.hdisplay = 640;
1007 lvds->native_mode.vdisplay = 480;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001008 }
1009
1010 ppll_div_sel = RREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3;
1011 ppll_val = RREG32_PLL(RADEON_PPLL_DIV_0 + ppll_div_sel);
1012 if ((ppll_val & 0x000707ff) == 0x1bb)
1013 lvds->use_bios_dividers = false;
1014 else {
1015 lvds->panel_ref_divider =
1016 RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
1017 lvds->panel_post_divider = (ppll_val >> 16) & 0x7;
1018 lvds->panel_fb_divider = ppll_val & 0x7ff;
1019
1020 if ((lvds->panel_ref_divider != 0) &&
1021 (lvds->panel_fb_divider > 3))
1022 lvds->use_bios_dividers = true;
1023 }
1024 lvds->panel_vcc_delay = 200;
1025
1026 DRM_INFO("Panel info derived from registers\n");
Alex Deucherde2103e2009-10-09 15:14:30 -04001027 DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
1028 lvds->native_mode.vdisplay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001029
1030 return lvds;
1031}
1032
1033struct radeon_encoder_lvds *radeon_combios_get_lvds_info(struct radeon_encoder
1034 *encoder)
1035{
1036 struct drm_device *dev = encoder->base.dev;
1037 struct radeon_device *rdev = dev->dev_private;
1038 uint16_t lcd_info;
1039 uint32_t panel_setup;
1040 char stmp[30];
1041 int tmp, i;
1042 struct radeon_encoder_lvds *lvds = NULL;
1043
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001044 lcd_info = combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
1045
1046 if (lcd_info) {
1047 lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
1048
1049 if (!lvds)
1050 return NULL;
1051
1052 for (i = 0; i < 24; i++)
1053 stmp[i] = RBIOS8(lcd_info + i + 1);
1054 stmp[24] = 0;
1055
1056 DRM_INFO("Panel ID String: %s\n", stmp);
1057
Alex Deucherde2103e2009-10-09 15:14:30 -04001058 lvds->native_mode.hdisplay = RBIOS16(lcd_info + 0x19);
1059 lvds->native_mode.vdisplay = RBIOS16(lcd_info + 0x1b);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001060
Alex Deucherde2103e2009-10-09 15:14:30 -04001061 DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
1062 lvds->native_mode.vdisplay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001063
1064 lvds->panel_vcc_delay = RBIOS16(lcd_info + 0x2c);
Andrew Morton94cf6432010-02-02 14:40:29 -08001065 lvds->panel_vcc_delay = min_t(u16, lvds->panel_vcc_delay, 2000);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001066
1067 lvds->panel_pwr_delay = RBIOS8(lcd_info + 0x24);
1068 lvds->panel_digon_delay = RBIOS16(lcd_info + 0x38) & 0xf;
1069 lvds->panel_blon_delay = (RBIOS16(lcd_info + 0x38) >> 4) & 0xf;
1070
1071 lvds->panel_ref_divider = RBIOS16(lcd_info + 0x2e);
1072 lvds->panel_post_divider = RBIOS8(lcd_info + 0x30);
1073 lvds->panel_fb_divider = RBIOS16(lcd_info + 0x31);
1074 if ((lvds->panel_ref_divider != 0) &&
1075 (lvds->panel_fb_divider > 3))
1076 lvds->use_bios_dividers = true;
1077
1078 panel_setup = RBIOS32(lcd_info + 0x39);
1079 lvds->lvds_gen_cntl = 0xff00;
1080 if (panel_setup & 0x1)
1081 lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_FORMAT;
1082
1083 if ((panel_setup >> 4) & 0x1)
1084 lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_TYPE;
1085
1086 switch ((panel_setup >> 8) & 0x7) {
1087 case 0:
1088 lvds->lvds_gen_cntl |= RADEON_LVDS_NO_FM;
1089 break;
1090 case 1:
1091 lvds->lvds_gen_cntl |= RADEON_LVDS_2_GREY;
1092 break;
1093 case 2:
1094 lvds->lvds_gen_cntl |= RADEON_LVDS_4_GREY;
1095 break;
1096 default:
1097 break;
1098 }
1099
1100 if ((panel_setup >> 16) & 0x1)
1101 lvds->lvds_gen_cntl |= RADEON_LVDS_FP_POL_LOW;
1102
1103 if ((panel_setup >> 17) & 0x1)
1104 lvds->lvds_gen_cntl |= RADEON_LVDS_LP_POL_LOW;
1105
1106 if ((panel_setup >> 18) & 0x1)
1107 lvds->lvds_gen_cntl |= RADEON_LVDS_DTM_POL_LOW;
1108
1109 if ((panel_setup >> 23) & 0x1)
1110 lvds->lvds_gen_cntl |= RADEON_LVDS_BL_CLK_SEL;
1111
1112 lvds->lvds_gen_cntl |= (panel_setup & 0xf0000000);
1113
1114 for (i = 0; i < 32; i++) {
1115 tmp = RBIOS16(lcd_info + 64 + i * 2);
1116 if (tmp == 0)
1117 break;
1118
Alex Deucherde2103e2009-10-09 15:14:30 -04001119 if ((RBIOS16(tmp) == lvds->native_mode.hdisplay) &&
Alex Deucher68b61a72010-05-18 00:30:05 -04001120 (RBIOS16(tmp + 2) == lvds->native_mode.vdisplay)) {
1121 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1122 (RBIOS16(tmp + 17) - RBIOS16(tmp + 19)) * 8;
1123 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1124 (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) - 1) * 8;
1125 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1126 (RBIOS8(tmp + 23) * 8);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001127
Alex Deucher68b61a72010-05-18 00:30:05 -04001128 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1129 (RBIOS16(tmp + 24) - RBIOS16(tmp + 26));
1130 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1131 ((RBIOS16(tmp + 28) & 0x7ff) - RBIOS16(tmp + 26));
1132 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1133 ((RBIOS16(tmp + 28) & 0xf800) >> 11);
Alex Deucherde2103e2009-10-09 15:14:30 -04001134
1135 lvds->native_mode.clock = RBIOS16(tmp + 9) * 10;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001136 lvds->native_mode.flags = 0;
Alex Deucherde2103e2009-10-09 15:14:30 -04001137 /* set crtc values */
1138 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
1139
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001140 }
1141 }
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001142 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001143 DRM_INFO("No panel info found in BIOS\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +02001144 lvds = radeon_legacy_get_lvds_info_from_regs(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001145 }
Michel Dänzer03047cd2010-02-10 11:05:11 +01001146
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +02001147 if (lvds)
1148 encoder->native_mode = lvds->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001149 return lvds;
1150}
1151
1152static const struct radeon_tmds_pll default_tmds_pll[CHIP_LAST][4] = {
1153 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R100 */
1154 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV100 */
1155 {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS100 */
1156 {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV200 */
1157 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RS200 */
1158 {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R200 */
1159 {{15500, 0x81b}, {0xffffffff, 0x83f}, {0, 0}, {0, 0}}, /* CHIP_RV250 */
1160 {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS300 */
1161 {{13000, 0x400f4}, {15000, 0x400f7}, {0xffffffff, 0x40111}, {0, 0}}, /* CHIP_RV280 */
1162 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R300 */
1163 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R350 */
1164 {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV350 */
1165 {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV380 */
1166 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R420 */
1167 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R423 */
1168 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RV410 */
Alex Deucherfcec5702009-11-10 21:25:07 -05001169 { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS400 */
1170 { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS480 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001171};
1172
Dave Airlie445282d2009-09-09 17:40:54 +10001173bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
1174 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001175{
Dave Airlie445282d2009-09-09 17:40:54 +10001176 struct drm_device *dev = encoder->base.dev;
1177 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001178 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001179
1180 for (i = 0; i < 4; i++) {
1181 tmds->tmds_pll[i].value =
Dave Airlie445282d2009-09-09 17:40:54 +10001182 default_tmds_pll[rdev->family][i].value;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001183 tmds->tmds_pll[i].freq = default_tmds_pll[rdev->family][i].freq;
1184 }
1185
Dave Airlie445282d2009-09-09 17:40:54 +10001186 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001187}
1188
Dave Airlie445282d2009-09-09 17:40:54 +10001189bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
1190 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001191{
1192 struct drm_device *dev = encoder->base.dev;
1193 struct radeon_device *rdev = dev->dev_private;
1194 uint16_t tmds_info;
1195 int i, n;
1196 uint8_t ver;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001197
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001198 tmds_info = combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
1199
1200 if (tmds_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001201 ver = RBIOS8(tmds_info);
1202 DRM_INFO("DFP table revision: %d\n", ver);
1203 if (ver == 3) {
1204 n = RBIOS8(tmds_info + 5) + 1;
1205 if (n > 4)
1206 n = 4;
1207 for (i = 0; i < n; i++) {
1208 tmds->tmds_pll[i].value =
1209 RBIOS32(tmds_info + i * 10 + 0x08);
1210 tmds->tmds_pll[i].freq =
1211 RBIOS16(tmds_info + i * 10 + 0x10);
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001212 DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001213 tmds->tmds_pll[i].freq,
1214 tmds->tmds_pll[i].value);
1215 }
1216 } else if (ver == 4) {
1217 int stride = 0;
1218 n = RBIOS8(tmds_info + 5) + 1;
1219 if (n > 4)
1220 n = 4;
1221 for (i = 0; i < n; i++) {
1222 tmds->tmds_pll[i].value =
1223 RBIOS32(tmds_info + stride + 0x08);
1224 tmds->tmds_pll[i].freq =
1225 RBIOS16(tmds_info + stride + 0x10);
1226 if (i == 0)
1227 stride += 10;
1228 else
1229 stride += 6;
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001230 DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001231 tmds->tmds_pll[i].freq,
1232 tmds->tmds_pll[i].value);
1233 }
1234 }
Alex Deucherfcec5702009-11-10 21:25:07 -05001235 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001236 DRM_INFO("No TMDS info found in BIOS\n");
Alex Deucherfcec5702009-11-10 21:25:07 -05001237 return false;
1238 }
Dave Airlie445282d2009-09-09 17:40:54 +10001239 return true;
1240}
1241
Alex Deucherfcec5702009-11-10 21:25:07 -05001242bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
1243 struct radeon_encoder_ext_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001244{
1245 struct drm_device *dev = encoder->base.dev;
1246 struct radeon_device *rdev = dev->dev_private;
Alex Deucherfcec5702009-11-10 21:25:07 -05001247 struct radeon_i2c_bus_rec i2c_bus;
1248
1249 /* default for macs */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001250 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
Alex Deucherfcec5702009-11-10 21:25:07 -05001251 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1252
1253 /* XXX some macs have duallink chips */
1254 switch (rdev->mode_info.connector_table) {
1255 case CT_POWERBOOK_EXTERNAL:
1256 case CT_MINI_EXTERNAL:
1257 default:
1258 tmds->dvo_chip = DVO_SIL164;
1259 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1260 break;
1261 }
1262
1263 return true;
1264}
1265
1266bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
1267 struct radeon_encoder_ext_tmds *tmds)
1268{
1269 struct drm_device *dev = encoder->base.dev;
1270 struct radeon_device *rdev = dev->dev_private;
1271 uint16_t offset;
1272 uint8_t ver, id, blocks, clk, data;
1273 int i;
1274 enum radeon_combios_ddc gpio;
1275 struct radeon_i2c_bus_rec i2c_bus;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001276
Alex Deucherfcec5702009-11-10 21:25:07 -05001277 tmds->i2c_bus = NULL;
1278 if (rdev->flags & RADEON_IS_IGP) {
1279 offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE);
1280 if (offset) {
1281 ver = RBIOS8(offset);
1282 DRM_INFO("GPIO Table revision: %d\n", ver);
1283 blocks = RBIOS8(offset + 2);
1284 for (i = 0; i < blocks; i++) {
1285 id = RBIOS8(offset + 3 + (i * 5) + 0);
1286 if (id == 136) {
1287 clk = RBIOS8(offset + 3 + (i * 5) + 3);
1288 data = RBIOS8(offset + 3 + (i * 5) + 4);
1289 i2c_bus.valid = true;
1290 i2c_bus.mask_clk_mask = (1 << clk);
1291 i2c_bus.mask_data_mask = (1 << data);
1292 i2c_bus.a_clk_mask = (1 << clk);
1293 i2c_bus.a_data_mask = (1 << data);
1294 i2c_bus.en_clk_mask = (1 << clk);
1295 i2c_bus.en_data_mask = (1 << data);
1296 i2c_bus.y_clk_mask = (1 << clk);
1297 i2c_bus.y_data_mask = (1 << data);
1298 i2c_bus.mask_clk_reg = RADEON_GPIOPAD_MASK;
1299 i2c_bus.mask_data_reg = RADEON_GPIOPAD_MASK;
1300 i2c_bus.a_clk_reg = RADEON_GPIOPAD_A;
1301 i2c_bus.a_data_reg = RADEON_GPIOPAD_A;
1302 i2c_bus.en_clk_reg = RADEON_GPIOPAD_EN;
1303 i2c_bus.en_data_reg = RADEON_GPIOPAD_EN;
1304 i2c_bus.y_clk_reg = RADEON_GPIOPAD_Y;
1305 i2c_bus.y_data_reg = RADEON_GPIOPAD_Y;
1306 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1307 tmds->dvo_chip = DVO_SIL164;
1308 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1309 break;
1310 }
1311 }
1312 }
1313 } else {
1314 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
1315 if (offset) {
1316 ver = RBIOS8(offset);
1317 DRM_INFO("External TMDS Table revision: %d\n", ver);
1318 tmds->slave_addr = RBIOS8(offset + 4 + 2);
1319 tmds->slave_addr >>= 1; /* 7 bit addressing */
1320 gpio = RBIOS8(offset + 4 + 3);
1321 switch (gpio) {
1322 case DDC_MONID:
Alex Deucher6a93cb22009-11-23 17:39:28 -05001323 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
Alex Deucherfcec5702009-11-10 21:25:07 -05001324 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1325 break;
1326 case DDC_DVI:
Alex Deucher6a93cb22009-11-23 17:39:28 -05001327 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
Alex Deucherfcec5702009-11-10 21:25:07 -05001328 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1329 break;
1330 case DDC_VGA:
Alex Deucher6a93cb22009-11-23 17:39:28 -05001331 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Alex Deucherfcec5702009-11-10 21:25:07 -05001332 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1333 break;
1334 case DDC_CRT2:
1335 /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */
1336 if (rdev->family >= CHIP_R300)
Alex Deucher6a93cb22009-11-23 17:39:28 -05001337 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
Alex Deucherfcec5702009-11-10 21:25:07 -05001338 else
Alex Deucher6a93cb22009-11-23 17:39:28 -05001339 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
Alex Deucherfcec5702009-11-10 21:25:07 -05001340 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1341 break;
1342 case DDC_LCD: /* MM i2c */
Alex Deucher40bacf12009-12-23 03:23:21 -05001343 i2c_bus.valid = true;
1344 i2c_bus.hw_capable = true;
1345 i2c_bus.mm_i2c = true;
1346 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
Alex Deucherfcec5702009-11-10 21:25:07 -05001347 break;
1348 default:
1349 DRM_ERROR("Unsupported gpio %d\n", gpio);
1350 break;
1351 }
1352 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001353 }
Alex Deucherfcec5702009-11-10 21:25:07 -05001354
1355 if (!tmds->i2c_bus) {
1356 DRM_INFO("No valid Ext TMDS info found in BIOS\n");
1357 return false;
1358 }
1359
1360 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001361}
1362
1363bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1364{
1365 struct radeon_device *rdev = dev->dev_private;
1366 struct radeon_i2c_bus_rec ddc_i2c;
Alex Deuchereed45b32009-12-04 14:45:27 -05001367 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001368
1369 rdev->mode_info.connector_table = radeon_connector_table;
1370 if (rdev->mode_info.connector_table == CT_NONE) {
1371#ifdef CONFIG_PPC_PMAC
Grant Likely71a157e2010-02-01 21:34:14 -07001372 if (of_machine_is_compatible("PowerBook3,3")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001373 /* powerbook with VGA */
1374 rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
Grant Likely71a157e2010-02-01 21:34:14 -07001375 } else if (of_machine_is_compatible("PowerBook3,4") ||
1376 of_machine_is_compatible("PowerBook3,5")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001377 /* powerbook with internal tmds */
1378 rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001379 } else if (of_machine_is_compatible("PowerBook5,1") ||
1380 of_machine_is_compatible("PowerBook5,2") ||
1381 of_machine_is_compatible("PowerBook5,3") ||
1382 of_machine_is_compatible("PowerBook5,4") ||
1383 of_machine_is_compatible("PowerBook5,5")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001384 /* powerbook with external single link tmds (sil164) */
1385 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001386 } else if (of_machine_is_compatible("PowerBook5,6")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001387 /* powerbook with external dual or single link tmds */
1388 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001389 } else if (of_machine_is_compatible("PowerBook5,7") ||
1390 of_machine_is_compatible("PowerBook5,8") ||
1391 of_machine_is_compatible("PowerBook5,9")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001392 /* PowerBook6,2 ? */
1393 /* powerbook with external dual link tmds (sil1178?) */
1394 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001395 } else if (of_machine_is_compatible("PowerBook4,1") ||
1396 of_machine_is_compatible("PowerBook4,2") ||
1397 of_machine_is_compatible("PowerBook4,3") ||
1398 of_machine_is_compatible("PowerBook6,3") ||
1399 of_machine_is_compatible("PowerBook6,5") ||
1400 of_machine_is_compatible("PowerBook6,7")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001401 /* ibook */
1402 rdev->mode_info.connector_table = CT_IBOOK;
Grant Likely71a157e2010-02-01 21:34:14 -07001403 } else if (of_machine_is_compatible("PowerMac4,4")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001404 /* emac */
1405 rdev->mode_info.connector_table = CT_EMAC;
Grant Likely71a157e2010-02-01 21:34:14 -07001406 } else if (of_machine_is_compatible("PowerMac10,1")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001407 /* mini with internal tmds */
1408 rdev->mode_info.connector_table = CT_MINI_INTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001409 } else if (of_machine_is_compatible("PowerMac10,2")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001410 /* mini with external tmds */
1411 rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001412 } else if (of_machine_is_compatible("PowerMac12,1")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001413 /* PowerMac8,1 ? */
1414 /* imac g5 isight */
1415 rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
1416 } else
1417#endif /* CONFIG_PPC_PMAC */
Dave Airlie76a71422010-06-11 01:09:05 -04001418#ifdef CONFIG_PPC64
1419 if (ASIC_IS_RN50(rdev))
1420 rdev->mode_info.connector_table = CT_RN50_POWER;
1421 else
1422#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001423 rdev->mode_info.connector_table = CT_GENERIC;
1424 }
1425
1426 switch (rdev->mode_info.connector_table) {
1427 case CT_GENERIC:
1428 DRM_INFO("Connector Table: %d (generic)\n",
1429 rdev->mode_info.connector_table);
1430 /* these are the most common settings */
1431 if (rdev->flags & RADEON_SINGLE_CRTC) {
1432 /* VGA - primary dac */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001433 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001434 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001435 radeon_add_legacy_encoder(dev,
1436 radeon_get_encoder_id(dev,
1437 ATOM_DEVICE_CRT1_SUPPORT,
1438 1),
1439 ATOM_DEVICE_CRT1_SUPPORT);
1440 radeon_add_legacy_connector(dev, 0,
1441 ATOM_DEVICE_CRT1_SUPPORT,
1442 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001443 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001444 CONNECTOR_OBJECT_ID_VGA,
1445 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001446 } else if (rdev->flags & RADEON_IS_MOBILITY) {
1447 /* LVDS */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001448 ddc_i2c = combios_setup_i2c_bus(rdev, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001449 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001450 radeon_add_legacy_encoder(dev,
1451 radeon_get_encoder_id(dev,
1452 ATOM_DEVICE_LCD1_SUPPORT,
1453 0),
1454 ATOM_DEVICE_LCD1_SUPPORT);
1455 radeon_add_legacy_connector(dev, 0,
1456 ATOM_DEVICE_LCD1_SUPPORT,
1457 DRM_MODE_CONNECTOR_LVDS,
Alex Deucherb75fad02009-11-05 13:16:01 -05001458 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001459 CONNECTOR_OBJECT_ID_LVDS,
1460 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001461
1462 /* VGA - primary dac */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001463 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001464 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001465 radeon_add_legacy_encoder(dev,
1466 radeon_get_encoder_id(dev,
1467 ATOM_DEVICE_CRT1_SUPPORT,
1468 1),
1469 ATOM_DEVICE_CRT1_SUPPORT);
1470 radeon_add_legacy_connector(dev, 1,
1471 ATOM_DEVICE_CRT1_SUPPORT,
1472 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001473 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001474 CONNECTOR_OBJECT_ID_VGA,
1475 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001476 } else {
1477 /* DVI-I - tv dac, int tmds */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001478 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001479 hpd.hpd = RADEON_HPD_1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001480 radeon_add_legacy_encoder(dev,
1481 radeon_get_encoder_id(dev,
1482 ATOM_DEVICE_DFP1_SUPPORT,
1483 0),
1484 ATOM_DEVICE_DFP1_SUPPORT);
1485 radeon_add_legacy_encoder(dev,
1486 radeon_get_encoder_id(dev,
1487 ATOM_DEVICE_CRT2_SUPPORT,
1488 2),
1489 ATOM_DEVICE_CRT2_SUPPORT);
1490 radeon_add_legacy_connector(dev, 0,
1491 ATOM_DEVICE_DFP1_SUPPORT |
1492 ATOM_DEVICE_CRT2_SUPPORT,
1493 DRM_MODE_CONNECTOR_DVII,
Alex Deucherb75fad02009-11-05 13:16:01 -05001494 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001495 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1496 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001497
1498 /* VGA - primary dac */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001499 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001500 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001501 radeon_add_legacy_encoder(dev,
1502 radeon_get_encoder_id(dev,
1503 ATOM_DEVICE_CRT1_SUPPORT,
1504 1),
1505 ATOM_DEVICE_CRT1_SUPPORT);
1506 radeon_add_legacy_connector(dev, 1,
1507 ATOM_DEVICE_CRT1_SUPPORT,
1508 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001509 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001510 CONNECTOR_OBJECT_ID_VGA,
1511 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001512 }
1513
1514 if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
1515 /* TV - tv dac */
Alex Deuchereed45b32009-12-04 14:45:27 -05001516 ddc_i2c.valid = false;
1517 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001518 radeon_add_legacy_encoder(dev,
1519 radeon_get_encoder_id(dev,
1520 ATOM_DEVICE_TV1_SUPPORT,
1521 2),
1522 ATOM_DEVICE_TV1_SUPPORT);
1523 radeon_add_legacy_connector(dev, 2,
1524 ATOM_DEVICE_TV1_SUPPORT,
1525 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001526 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001527 CONNECTOR_OBJECT_ID_SVIDEO,
1528 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001529 }
1530 break;
1531 case CT_IBOOK:
1532 DRM_INFO("Connector Table: %d (ibook)\n",
1533 rdev->mode_info.connector_table);
1534 /* LVDS */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001535 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001536 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001537 radeon_add_legacy_encoder(dev,
1538 radeon_get_encoder_id(dev,
1539 ATOM_DEVICE_LCD1_SUPPORT,
1540 0),
1541 ATOM_DEVICE_LCD1_SUPPORT);
1542 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001543 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001544 CONNECTOR_OBJECT_ID_LVDS,
1545 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001546 /* VGA - TV DAC */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001547 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001548 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001549 radeon_add_legacy_encoder(dev,
1550 radeon_get_encoder_id(dev,
1551 ATOM_DEVICE_CRT2_SUPPORT,
1552 2),
1553 ATOM_DEVICE_CRT2_SUPPORT);
1554 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001555 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001556 CONNECTOR_OBJECT_ID_VGA,
1557 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001558 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001559 ddc_i2c.valid = false;
1560 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001561 radeon_add_legacy_encoder(dev,
1562 radeon_get_encoder_id(dev,
1563 ATOM_DEVICE_TV1_SUPPORT,
1564 2),
1565 ATOM_DEVICE_TV1_SUPPORT);
1566 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1567 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001568 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001569 CONNECTOR_OBJECT_ID_SVIDEO,
1570 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001571 break;
1572 case CT_POWERBOOK_EXTERNAL:
1573 DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
1574 rdev->mode_info.connector_table);
1575 /* LVDS */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001576 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001577 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001578 radeon_add_legacy_encoder(dev,
1579 radeon_get_encoder_id(dev,
1580 ATOM_DEVICE_LCD1_SUPPORT,
1581 0),
1582 ATOM_DEVICE_LCD1_SUPPORT);
1583 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001584 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001585 CONNECTOR_OBJECT_ID_LVDS,
1586 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001587 /* DVI-I - primary dac, ext tmds */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001588 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001589 hpd.hpd = RADEON_HPD_2; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001590 radeon_add_legacy_encoder(dev,
1591 radeon_get_encoder_id(dev,
1592 ATOM_DEVICE_DFP2_SUPPORT,
1593 0),
1594 ATOM_DEVICE_DFP2_SUPPORT);
1595 radeon_add_legacy_encoder(dev,
1596 radeon_get_encoder_id(dev,
1597 ATOM_DEVICE_CRT1_SUPPORT,
1598 1),
1599 ATOM_DEVICE_CRT1_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05001600 /* XXX some are SL */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001601 radeon_add_legacy_connector(dev, 1,
1602 ATOM_DEVICE_DFP2_SUPPORT |
1603 ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001604 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001605 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
1606 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001607 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001608 ddc_i2c.valid = false;
1609 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001610 radeon_add_legacy_encoder(dev,
1611 radeon_get_encoder_id(dev,
1612 ATOM_DEVICE_TV1_SUPPORT,
1613 2),
1614 ATOM_DEVICE_TV1_SUPPORT);
1615 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1616 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001617 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001618 CONNECTOR_OBJECT_ID_SVIDEO,
1619 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001620 break;
1621 case CT_POWERBOOK_INTERNAL:
1622 DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
1623 rdev->mode_info.connector_table);
1624 /* LVDS */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001625 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001626 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001627 radeon_add_legacy_encoder(dev,
1628 radeon_get_encoder_id(dev,
1629 ATOM_DEVICE_LCD1_SUPPORT,
1630 0),
1631 ATOM_DEVICE_LCD1_SUPPORT);
1632 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001633 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001634 CONNECTOR_OBJECT_ID_LVDS,
1635 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001636 /* DVI-I - primary dac, int tmds */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001637 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001638 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001639 radeon_add_legacy_encoder(dev,
1640 radeon_get_encoder_id(dev,
1641 ATOM_DEVICE_DFP1_SUPPORT,
1642 0),
1643 ATOM_DEVICE_DFP1_SUPPORT);
1644 radeon_add_legacy_encoder(dev,
1645 radeon_get_encoder_id(dev,
1646 ATOM_DEVICE_CRT1_SUPPORT,
1647 1),
1648 ATOM_DEVICE_CRT1_SUPPORT);
1649 radeon_add_legacy_connector(dev, 1,
1650 ATOM_DEVICE_DFP1_SUPPORT |
1651 ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001652 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001653 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1654 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001655 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001656 ddc_i2c.valid = false;
1657 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001658 radeon_add_legacy_encoder(dev,
1659 radeon_get_encoder_id(dev,
1660 ATOM_DEVICE_TV1_SUPPORT,
1661 2),
1662 ATOM_DEVICE_TV1_SUPPORT);
1663 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1664 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001665 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001666 CONNECTOR_OBJECT_ID_SVIDEO,
1667 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001668 break;
1669 case CT_POWERBOOK_VGA:
1670 DRM_INFO("Connector Table: %d (powerbook vga)\n",
1671 rdev->mode_info.connector_table);
1672 /* LVDS */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001673 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001674 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001675 radeon_add_legacy_encoder(dev,
1676 radeon_get_encoder_id(dev,
1677 ATOM_DEVICE_LCD1_SUPPORT,
1678 0),
1679 ATOM_DEVICE_LCD1_SUPPORT);
1680 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001681 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001682 CONNECTOR_OBJECT_ID_LVDS,
1683 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001684 /* VGA - primary dac */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001685 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001686 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001687 radeon_add_legacy_encoder(dev,
1688 radeon_get_encoder_id(dev,
1689 ATOM_DEVICE_CRT1_SUPPORT,
1690 1),
1691 ATOM_DEVICE_CRT1_SUPPORT);
1692 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001693 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001694 CONNECTOR_OBJECT_ID_VGA,
1695 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001696 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001697 ddc_i2c.valid = false;
1698 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001699 radeon_add_legacy_encoder(dev,
1700 radeon_get_encoder_id(dev,
1701 ATOM_DEVICE_TV1_SUPPORT,
1702 2),
1703 ATOM_DEVICE_TV1_SUPPORT);
1704 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1705 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001706 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001707 CONNECTOR_OBJECT_ID_SVIDEO,
1708 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001709 break;
1710 case CT_MINI_EXTERNAL:
1711 DRM_INFO("Connector Table: %d (mini external tmds)\n",
1712 rdev->mode_info.connector_table);
1713 /* DVI-I - tv dac, ext tmds */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001714 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001715 hpd.hpd = RADEON_HPD_2; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001716 radeon_add_legacy_encoder(dev,
1717 radeon_get_encoder_id(dev,
1718 ATOM_DEVICE_DFP2_SUPPORT,
1719 0),
1720 ATOM_DEVICE_DFP2_SUPPORT);
1721 radeon_add_legacy_encoder(dev,
1722 radeon_get_encoder_id(dev,
1723 ATOM_DEVICE_CRT2_SUPPORT,
1724 2),
1725 ATOM_DEVICE_CRT2_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05001726 /* XXX are any DL? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001727 radeon_add_legacy_connector(dev, 0,
1728 ATOM_DEVICE_DFP2_SUPPORT |
1729 ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001730 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001731 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1732 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001733 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001734 ddc_i2c.valid = false;
1735 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001736 radeon_add_legacy_encoder(dev,
1737 radeon_get_encoder_id(dev,
1738 ATOM_DEVICE_TV1_SUPPORT,
1739 2),
1740 ATOM_DEVICE_TV1_SUPPORT);
1741 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
1742 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001743 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001744 CONNECTOR_OBJECT_ID_SVIDEO,
1745 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001746 break;
1747 case CT_MINI_INTERNAL:
1748 DRM_INFO("Connector Table: %d (mini internal tmds)\n",
1749 rdev->mode_info.connector_table);
1750 /* DVI-I - tv dac, int tmds */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001751 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001752 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001753 radeon_add_legacy_encoder(dev,
1754 radeon_get_encoder_id(dev,
1755 ATOM_DEVICE_DFP1_SUPPORT,
1756 0),
1757 ATOM_DEVICE_DFP1_SUPPORT);
1758 radeon_add_legacy_encoder(dev,
1759 radeon_get_encoder_id(dev,
1760 ATOM_DEVICE_CRT2_SUPPORT,
1761 2),
1762 ATOM_DEVICE_CRT2_SUPPORT);
1763 radeon_add_legacy_connector(dev, 0,
1764 ATOM_DEVICE_DFP1_SUPPORT |
1765 ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001766 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001767 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1768 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001769 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001770 ddc_i2c.valid = false;
1771 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001772 radeon_add_legacy_encoder(dev,
1773 radeon_get_encoder_id(dev,
1774 ATOM_DEVICE_TV1_SUPPORT,
1775 2),
1776 ATOM_DEVICE_TV1_SUPPORT);
1777 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
1778 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001779 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001780 CONNECTOR_OBJECT_ID_SVIDEO,
1781 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001782 break;
1783 case CT_IMAC_G5_ISIGHT:
1784 DRM_INFO("Connector Table: %d (imac g5 isight)\n",
1785 rdev->mode_info.connector_table);
1786 /* DVI-D - int tmds */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001787 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
Alex Deuchereed45b32009-12-04 14:45:27 -05001788 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001789 radeon_add_legacy_encoder(dev,
1790 radeon_get_encoder_id(dev,
1791 ATOM_DEVICE_DFP1_SUPPORT,
1792 0),
1793 ATOM_DEVICE_DFP1_SUPPORT);
1794 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001795 DRM_MODE_CONNECTOR_DVID, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001796 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
1797 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001798 /* VGA - tv dac */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001799 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001800 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001801 radeon_add_legacy_encoder(dev,
1802 radeon_get_encoder_id(dev,
1803 ATOM_DEVICE_CRT2_SUPPORT,
1804 2),
1805 ATOM_DEVICE_CRT2_SUPPORT);
1806 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001807 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001808 CONNECTOR_OBJECT_ID_VGA,
1809 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001810 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001811 ddc_i2c.valid = false;
1812 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001813 radeon_add_legacy_encoder(dev,
1814 radeon_get_encoder_id(dev,
1815 ATOM_DEVICE_TV1_SUPPORT,
1816 2),
1817 ATOM_DEVICE_TV1_SUPPORT);
1818 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1819 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001820 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001821 CONNECTOR_OBJECT_ID_SVIDEO,
1822 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001823 break;
1824 case CT_EMAC:
1825 DRM_INFO("Connector Table: %d (emac)\n",
1826 rdev->mode_info.connector_table);
1827 /* VGA - primary dac */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001828 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001829 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001830 radeon_add_legacy_encoder(dev,
1831 radeon_get_encoder_id(dev,
1832 ATOM_DEVICE_CRT1_SUPPORT,
1833 1),
1834 ATOM_DEVICE_CRT1_SUPPORT);
1835 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001836 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001837 CONNECTOR_OBJECT_ID_VGA,
1838 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001839 /* VGA - tv dac */
Alex Deucher6a93cb22009-11-23 17:39:28 -05001840 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05001841 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001842 radeon_add_legacy_encoder(dev,
1843 radeon_get_encoder_id(dev,
1844 ATOM_DEVICE_CRT2_SUPPORT,
1845 2),
1846 ATOM_DEVICE_CRT2_SUPPORT);
1847 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001848 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001849 CONNECTOR_OBJECT_ID_VGA,
1850 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001851 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001852 ddc_i2c.valid = false;
1853 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001854 radeon_add_legacy_encoder(dev,
1855 radeon_get_encoder_id(dev,
1856 ATOM_DEVICE_TV1_SUPPORT,
1857 2),
1858 ATOM_DEVICE_TV1_SUPPORT);
1859 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1860 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001861 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001862 CONNECTOR_OBJECT_ID_SVIDEO,
1863 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001864 break;
Dave Airlie76a71422010-06-11 01:09:05 -04001865 case CT_RN50_POWER:
1866 DRM_INFO("Connector Table: %d (rn50-power)\n",
1867 rdev->mode_info.connector_table);
1868 /* VGA - primary dac */
1869 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
1870 hpd.hpd = RADEON_HPD_NONE;
1871 radeon_add_legacy_encoder(dev,
1872 radeon_get_encoder_id(dev,
1873 ATOM_DEVICE_CRT1_SUPPORT,
1874 1),
1875 ATOM_DEVICE_CRT1_SUPPORT);
1876 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
1877 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
1878 CONNECTOR_OBJECT_ID_VGA,
1879 &hpd);
1880 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
1881 hpd.hpd = RADEON_HPD_NONE;
1882 radeon_add_legacy_encoder(dev,
1883 radeon_get_encoder_id(dev,
1884 ATOM_DEVICE_CRT2_SUPPORT,
1885 2),
1886 ATOM_DEVICE_CRT2_SUPPORT);
1887 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
1888 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
1889 CONNECTOR_OBJECT_ID_VGA,
1890 &hpd);
1891 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001892 default:
1893 DRM_INFO("Connector table: %d (invalid)\n",
1894 rdev->mode_info.connector_table);
1895 return false;
1896 }
1897
1898 radeon_link_encoder_connector(dev);
1899
1900 return true;
1901}
1902
1903static bool radeon_apply_legacy_quirks(struct drm_device *dev,
1904 int bios_index,
1905 enum radeon_combios_connector
1906 *legacy_connector,
Alex Deuchereed45b32009-12-04 14:45:27 -05001907 struct radeon_i2c_bus_rec *ddc_i2c,
1908 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001909{
1910 struct radeon_device *rdev = dev->dev_private;
1911
1912 /* XPRESS DDC quirks */
1913 if ((rdev->family == CHIP_RS400 ||
1914 rdev->family == CHIP_RS480) &&
1915 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
Alex Deucher6a93cb22009-11-23 17:39:28 -05001916 *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001917 else if ((rdev->family == CHIP_RS400 ||
1918 rdev->family == CHIP_RS480) &&
1919 ddc_i2c->mask_clk_reg == RADEON_GPIO_MONID) {
Alex Deucher6a93cb22009-11-23 17:39:28 -05001920 *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIOPAD_MASK);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001921 ddc_i2c->mask_clk_mask = (0x20 << 8);
1922 ddc_i2c->mask_data_mask = 0x80;
1923 ddc_i2c->a_clk_mask = (0x20 << 8);
1924 ddc_i2c->a_data_mask = 0x80;
Alex Deucher9b9fe722009-11-10 15:59:44 -05001925 ddc_i2c->en_clk_mask = (0x20 << 8);
1926 ddc_i2c->en_data_mask = 0x80;
1927 ddc_i2c->y_clk_mask = (0x20 << 8);
1928 ddc_i2c->y_data_mask = 0x80;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001929 }
1930
Alex Deucherfcec5702009-11-10 21:25:07 -05001931 /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */
1932 if ((rdev->family >= CHIP_R300) &&
1933 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
Alex Deucher6a93cb22009-11-23 17:39:28 -05001934 *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
Alex Deucherfcec5702009-11-10 21:25:07 -05001935
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001936 /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
1937 one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
1938 if (dev->pdev->device == 0x515e &&
1939 dev->pdev->subsystem_vendor == 0x1014) {
1940 if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
1941 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
1942 return false;
1943 }
1944
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001945 /* X300 card with extra non-existent DVI port */
1946 if (dev->pdev->device == 0x5B60 &&
1947 dev->pdev->subsystem_vendor == 0x17af &&
1948 dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
1949 if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
1950 return false;
1951 }
1952
1953 return true;
1954}
1955
Alex Deucher790cfb32009-10-15 23:26:09 -04001956static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
1957{
1958 /* Acer 5102 has non-existent TV port */
1959 if (dev->pdev->device == 0x5975 &&
1960 dev->pdev->subsystem_vendor == 0x1025 &&
1961 dev->pdev->subsystem_device == 0x009f)
1962 return false;
1963
Alex Deucherfc7f7112009-10-28 01:46:54 -04001964 /* HP dc5750 has non-existent TV port */
1965 if (dev->pdev->device == 0x5974 &&
1966 dev->pdev->subsystem_vendor == 0x103c &&
1967 dev->pdev->subsystem_device == 0x280a)
1968 return false;
1969
Alex Deucherfd874ad2009-11-16 18:33:51 -05001970 /* MSI S270 has non-existent TV port */
1971 if (dev->pdev->device == 0x5955 &&
1972 dev->pdev->subsystem_vendor == 0x1462 &&
1973 dev->pdev->subsystem_device == 0x0131)
1974 return false;
1975
Alex Deucher790cfb32009-10-15 23:26:09 -04001976 return true;
1977}
1978
Alex Deucherb75fad02009-11-05 13:16:01 -05001979static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
1980{
1981 struct radeon_device *rdev = dev->dev_private;
1982 uint32_t ext_tmds_info;
1983
1984 if (rdev->flags & RADEON_IS_IGP) {
1985 if (is_dvi_d)
1986 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
1987 else
1988 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
1989 }
1990 ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
1991 if (ext_tmds_info) {
1992 uint8_t rev = RBIOS8(ext_tmds_info);
1993 uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
1994 if (rev >= 3) {
1995 if (is_dvi_d)
1996 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
1997 else
1998 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
1999 } else {
2000 if (flags & 1) {
2001 if (is_dvi_d)
2002 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
2003 else
2004 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
2005 }
2006 }
2007 }
2008 if (is_dvi_d)
2009 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
2010 else
2011 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2012}
2013
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002014bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2015{
2016 struct radeon_device *rdev = dev->dev_private;
2017 uint32_t conn_info, entry, devices;
Alex Deucherb75fad02009-11-05 13:16:01 -05002018 uint16_t tmp, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002019 enum radeon_combios_ddc ddc_type;
2020 enum radeon_combios_connector connector;
2021 int i = 0;
2022 struct radeon_i2c_bus_rec ddc_i2c;
Alex Deuchereed45b32009-12-04 14:45:27 -05002023 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002024
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002025 conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
2026 if (conn_info) {
2027 for (i = 0; i < 4; i++) {
2028 entry = conn_info + 2 + i * 2;
2029
2030 if (!RBIOS16(entry))
2031 break;
2032
2033 tmp = RBIOS16(entry);
2034
2035 connector = (tmp >> 12) & 0xf;
2036
2037 ddc_type = (tmp >> 8) & 0xf;
2038 switch (ddc_type) {
2039 case DDC_MONID:
2040 ddc_i2c =
Alex Deucher6a93cb22009-11-23 17:39:28 -05002041 combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002042 break;
2043 case DDC_DVI:
2044 ddc_i2c =
Alex Deucher6a93cb22009-11-23 17:39:28 -05002045 combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002046 break;
2047 case DDC_VGA:
2048 ddc_i2c =
Alex Deucher6a93cb22009-11-23 17:39:28 -05002049 combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002050 break;
2051 case DDC_CRT2:
2052 ddc_i2c =
Alex Deucher6a93cb22009-11-23 17:39:28 -05002053 combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002054 break;
2055 default:
Dave Airlied294ed62010-06-08 13:04:50 +10002056 ddc_i2c.valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002057 break;
2058 }
2059
Alex Deuchereed45b32009-12-04 14:45:27 -05002060 switch (connector) {
2061 case CONNECTOR_PROPRIETARY_LEGACY:
2062 case CONNECTOR_DVI_I_LEGACY:
2063 case CONNECTOR_DVI_D_LEGACY:
2064 if ((tmp >> 4) & 0x1)
2065 hpd.hpd = RADEON_HPD_2;
2066 else
2067 hpd.hpd = RADEON_HPD_1;
2068 break;
2069 default:
2070 hpd.hpd = RADEON_HPD_NONE;
2071 break;
2072 }
2073
Alex Deucher2d152c62009-10-15 23:08:05 -04002074 if (!radeon_apply_legacy_quirks(dev, i, &connector,
Alex Deuchereed45b32009-12-04 14:45:27 -05002075 &ddc_i2c, &hpd))
Alex Deucher2d152c62009-10-15 23:08:05 -04002076 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002077
2078 switch (connector) {
2079 case CONNECTOR_PROPRIETARY_LEGACY:
2080 if ((tmp >> 4) & 0x1)
2081 devices = ATOM_DEVICE_DFP2_SUPPORT;
2082 else
2083 devices = ATOM_DEVICE_DFP1_SUPPORT;
2084 radeon_add_legacy_encoder(dev,
2085 radeon_get_encoder_id
2086 (dev, devices, 0),
2087 devices);
2088 radeon_add_legacy_connector(dev, i, devices,
2089 legacy_connector_convert
2090 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002091 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002092 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
2093 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002094 break;
2095 case CONNECTOR_CRT_LEGACY:
2096 if (tmp & 0x1) {
2097 devices = ATOM_DEVICE_CRT2_SUPPORT;
2098 radeon_add_legacy_encoder(dev,
2099 radeon_get_encoder_id
2100 (dev,
2101 ATOM_DEVICE_CRT2_SUPPORT,
2102 2),
2103 ATOM_DEVICE_CRT2_SUPPORT);
2104 } else {
2105 devices = ATOM_DEVICE_CRT1_SUPPORT;
2106 radeon_add_legacy_encoder(dev,
2107 radeon_get_encoder_id
2108 (dev,
2109 ATOM_DEVICE_CRT1_SUPPORT,
2110 1),
2111 ATOM_DEVICE_CRT1_SUPPORT);
2112 }
2113 radeon_add_legacy_connector(dev,
2114 i,
2115 devices,
2116 legacy_connector_convert
2117 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002118 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002119 CONNECTOR_OBJECT_ID_VGA,
2120 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002121 break;
2122 case CONNECTOR_DVI_I_LEGACY:
2123 devices = 0;
2124 if (tmp & 0x1) {
2125 devices |= ATOM_DEVICE_CRT2_SUPPORT;
2126 radeon_add_legacy_encoder(dev,
2127 radeon_get_encoder_id
2128 (dev,
2129 ATOM_DEVICE_CRT2_SUPPORT,
2130 2),
2131 ATOM_DEVICE_CRT2_SUPPORT);
2132 } else {
2133 devices |= ATOM_DEVICE_CRT1_SUPPORT;
2134 radeon_add_legacy_encoder(dev,
2135 radeon_get_encoder_id
2136 (dev,
2137 ATOM_DEVICE_CRT1_SUPPORT,
2138 1),
2139 ATOM_DEVICE_CRT1_SUPPORT);
2140 }
2141 if ((tmp >> 4) & 0x1) {
2142 devices |= ATOM_DEVICE_DFP2_SUPPORT;
2143 radeon_add_legacy_encoder(dev,
2144 radeon_get_encoder_id
2145 (dev,
2146 ATOM_DEVICE_DFP2_SUPPORT,
2147 0),
2148 ATOM_DEVICE_DFP2_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05002149 connector_object_id = combios_check_dl_dvi(dev, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002150 } else {
2151 devices |= ATOM_DEVICE_DFP1_SUPPORT;
2152 radeon_add_legacy_encoder(dev,
2153 radeon_get_encoder_id
2154 (dev,
2155 ATOM_DEVICE_DFP1_SUPPORT,
2156 0),
2157 ATOM_DEVICE_DFP1_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05002158 connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002159 }
2160 radeon_add_legacy_connector(dev,
2161 i,
2162 devices,
2163 legacy_connector_convert
2164 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002165 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002166 connector_object_id,
2167 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002168 break;
2169 case CONNECTOR_DVI_D_LEGACY:
Alex Deucherb75fad02009-11-05 13:16:01 -05002170 if ((tmp >> 4) & 0x1) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002171 devices = ATOM_DEVICE_DFP2_SUPPORT;
Alex Deucherb75fad02009-11-05 13:16:01 -05002172 connector_object_id = combios_check_dl_dvi(dev, 1);
2173 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002174 devices = ATOM_DEVICE_DFP1_SUPPORT;
Alex Deucherb75fad02009-11-05 13:16:01 -05002175 connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2176 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002177 radeon_add_legacy_encoder(dev,
2178 radeon_get_encoder_id
2179 (dev, devices, 0),
2180 devices);
2181 radeon_add_legacy_connector(dev, i, devices,
2182 legacy_connector_convert
2183 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002184 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002185 connector_object_id,
2186 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002187 break;
2188 case CONNECTOR_CTV_LEGACY:
2189 case CONNECTOR_STV_LEGACY:
2190 radeon_add_legacy_encoder(dev,
2191 radeon_get_encoder_id
2192 (dev,
2193 ATOM_DEVICE_TV1_SUPPORT,
2194 2),
2195 ATOM_DEVICE_TV1_SUPPORT);
2196 radeon_add_legacy_connector(dev, i,
2197 ATOM_DEVICE_TV1_SUPPORT,
2198 legacy_connector_convert
2199 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002200 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002201 CONNECTOR_OBJECT_ID_SVIDEO,
2202 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002203 break;
2204 default:
2205 DRM_ERROR("Unknown connector type: %d\n",
2206 connector);
2207 continue;
2208 }
2209
2210 }
2211 } else {
2212 uint16_t tmds_info =
2213 combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
2214 if (tmds_info) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002215 DRM_DEBUG_KMS("Found DFP table, assuming DVI connector\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002216
2217 radeon_add_legacy_encoder(dev,
2218 radeon_get_encoder_id(dev,
2219 ATOM_DEVICE_CRT1_SUPPORT,
2220 1),
2221 ATOM_DEVICE_CRT1_SUPPORT);
2222 radeon_add_legacy_encoder(dev,
2223 radeon_get_encoder_id(dev,
2224 ATOM_DEVICE_DFP1_SUPPORT,
2225 0),
2226 ATOM_DEVICE_DFP1_SUPPORT);
2227
Alex Deucher6a93cb22009-11-23 17:39:28 -05002228 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
Alex Deucher8e36ed02010-05-18 19:26:47 -04002229 hpd.hpd = RADEON_HPD_1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002230 radeon_add_legacy_connector(dev,
2231 0,
2232 ATOM_DEVICE_CRT1_SUPPORT |
2233 ATOM_DEVICE_DFP1_SUPPORT,
2234 DRM_MODE_CONNECTOR_DVII,
Alex Deucherb75fad02009-11-05 13:16:01 -05002235 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002236 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2237 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002238 } else {
Alex Deucherd0c403e2009-10-15 23:38:32 -04002239 uint16_t crt_info =
2240 combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002241 DRM_DEBUG_KMS("Found CRT table, assuming VGA connector\n");
Alex Deucherd0c403e2009-10-15 23:38:32 -04002242 if (crt_info) {
2243 radeon_add_legacy_encoder(dev,
2244 radeon_get_encoder_id(dev,
2245 ATOM_DEVICE_CRT1_SUPPORT,
2246 1),
2247 ATOM_DEVICE_CRT1_SUPPORT);
Alex Deucher6a93cb22009-11-23 17:39:28 -05002248 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
Alex Deuchereed45b32009-12-04 14:45:27 -05002249 hpd.hpd = RADEON_HPD_NONE;
Alex Deucherd0c403e2009-10-15 23:38:32 -04002250 radeon_add_legacy_connector(dev,
2251 0,
2252 ATOM_DEVICE_CRT1_SUPPORT,
2253 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05002254 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002255 CONNECTOR_OBJECT_ID_VGA,
2256 &hpd);
Alex Deucherd0c403e2009-10-15 23:38:32 -04002257 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002258 DRM_DEBUG_KMS("No connector info found\n");
Alex Deucherd0c403e2009-10-15 23:38:32 -04002259 return false;
2260 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002261 }
2262 }
2263
2264 if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
2265 uint16_t lcd_info =
2266 combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
2267 if (lcd_info) {
2268 uint16_t lcd_ddc_info =
2269 combios_get_table_offset(dev,
2270 COMBIOS_LCD_DDC_INFO_TABLE);
2271
2272 radeon_add_legacy_encoder(dev,
2273 radeon_get_encoder_id(dev,
2274 ATOM_DEVICE_LCD1_SUPPORT,
2275 0),
2276 ATOM_DEVICE_LCD1_SUPPORT);
2277
2278 if (lcd_ddc_info) {
2279 ddc_type = RBIOS8(lcd_ddc_info + 2);
2280 switch (ddc_type) {
2281 case DDC_MONID:
2282 ddc_i2c =
2283 combios_setup_i2c_bus
Alex Deucher6a93cb22009-11-23 17:39:28 -05002284 (rdev, RADEON_GPIO_MONID);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002285 break;
2286 case DDC_DVI:
2287 ddc_i2c =
2288 combios_setup_i2c_bus
Alex Deucher6a93cb22009-11-23 17:39:28 -05002289 (rdev, RADEON_GPIO_DVI_DDC);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002290 break;
2291 case DDC_VGA:
2292 ddc_i2c =
2293 combios_setup_i2c_bus
Alex Deucher6a93cb22009-11-23 17:39:28 -05002294 (rdev, RADEON_GPIO_VGA_DDC);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002295 break;
2296 case DDC_CRT2:
2297 ddc_i2c =
2298 combios_setup_i2c_bus
Alex Deucher6a93cb22009-11-23 17:39:28 -05002299 (rdev, RADEON_GPIO_CRT2_DDC);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002300 break;
2301 case DDC_LCD:
2302 ddc_i2c =
2303 combios_setup_i2c_bus
Alex Deucher6a93cb22009-11-23 17:39:28 -05002304 (rdev, RADEON_GPIOPAD_MASK);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002305 ddc_i2c.mask_clk_mask =
2306 RBIOS32(lcd_ddc_info + 3);
2307 ddc_i2c.mask_data_mask =
2308 RBIOS32(lcd_ddc_info + 7);
2309 ddc_i2c.a_clk_mask =
2310 RBIOS32(lcd_ddc_info + 3);
2311 ddc_i2c.a_data_mask =
2312 RBIOS32(lcd_ddc_info + 7);
Alex Deucher9b9fe722009-11-10 15:59:44 -05002313 ddc_i2c.en_clk_mask =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002314 RBIOS32(lcd_ddc_info + 3);
Alex Deucher9b9fe722009-11-10 15:59:44 -05002315 ddc_i2c.en_data_mask =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002316 RBIOS32(lcd_ddc_info + 7);
Alex Deucher9b9fe722009-11-10 15:59:44 -05002317 ddc_i2c.y_clk_mask =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002318 RBIOS32(lcd_ddc_info + 3);
Alex Deucher9b9fe722009-11-10 15:59:44 -05002319 ddc_i2c.y_data_mask =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002320 RBIOS32(lcd_ddc_info + 7);
2321 break;
2322 case DDC_GPIO:
2323 ddc_i2c =
2324 combios_setup_i2c_bus
Alex Deucher6a93cb22009-11-23 17:39:28 -05002325 (rdev, RADEON_MDGPIO_MASK);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002326 ddc_i2c.mask_clk_mask =
2327 RBIOS32(lcd_ddc_info + 3);
2328 ddc_i2c.mask_data_mask =
2329 RBIOS32(lcd_ddc_info + 7);
2330 ddc_i2c.a_clk_mask =
2331 RBIOS32(lcd_ddc_info + 3);
2332 ddc_i2c.a_data_mask =
2333 RBIOS32(lcd_ddc_info + 7);
Alex Deucher9b9fe722009-11-10 15:59:44 -05002334 ddc_i2c.en_clk_mask =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002335 RBIOS32(lcd_ddc_info + 3);
Alex Deucher9b9fe722009-11-10 15:59:44 -05002336 ddc_i2c.en_data_mask =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002337 RBIOS32(lcd_ddc_info + 7);
Alex Deucher9b9fe722009-11-10 15:59:44 -05002338 ddc_i2c.y_clk_mask =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002339 RBIOS32(lcd_ddc_info + 3);
Alex Deucher9b9fe722009-11-10 15:59:44 -05002340 ddc_i2c.y_data_mask =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002341 RBIOS32(lcd_ddc_info + 7);
2342 break;
2343 default:
2344 ddc_i2c.valid = false;
2345 break;
2346 }
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002347 DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002348 } else
2349 ddc_i2c.valid = false;
2350
Alex Deuchereed45b32009-12-04 14:45:27 -05002351 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002352 radeon_add_legacy_connector(dev,
2353 5,
2354 ATOM_DEVICE_LCD1_SUPPORT,
2355 DRM_MODE_CONNECTOR_LVDS,
Alex Deucherb75fad02009-11-05 13:16:01 -05002356 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002357 CONNECTOR_OBJECT_ID_LVDS,
2358 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002359 }
2360 }
2361
2362 /* check TV table */
2363 if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
2364 uint32_t tv_info =
2365 combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
2366 if (tv_info) {
2367 if (RBIOS8(tv_info + 6) == 'T') {
Alex Deucher790cfb32009-10-15 23:26:09 -04002368 if (radeon_apply_legacy_tv_quirks(dev)) {
Alex Deuchereed45b32009-12-04 14:45:27 -05002369 hpd.hpd = RADEON_HPD_NONE;
Dave Airlied294ed62010-06-08 13:04:50 +10002370 ddc_i2c.valid = false;
Alex Deucher790cfb32009-10-15 23:26:09 -04002371 radeon_add_legacy_encoder(dev,
2372 radeon_get_encoder_id
2373 (dev,
2374 ATOM_DEVICE_TV1_SUPPORT,
2375 2),
2376 ATOM_DEVICE_TV1_SUPPORT);
2377 radeon_add_legacy_connector(dev, 6,
2378 ATOM_DEVICE_TV1_SUPPORT,
2379 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05002380 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002381 CONNECTOR_OBJECT_ID_SVIDEO,
2382 &hpd);
Alex Deucher790cfb32009-10-15 23:26:09 -04002383 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002384 }
2385 }
2386 }
2387
2388 radeon_link_encoder_connector(dev);
2389
2390 return true;
2391}
2392
Alex Deucher56278a82009-12-28 13:58:44 -05002393void radeon_combios_get_power_modes(struct radeon_device *rdev)
2394{
2395 struct drm_device *dev = rdev->ddev;
2396 u16 offset, misc, misc2 = 0;
2397 u8 rev, blocks, tmp;
2398 int state_index = 0;
2399
Alex Deuchera48b9b42010-04-22 14:03:55 -04002400 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05002401
Alex Deucher56278a82009-12-28 13:58:44 -05002402 if (rdev->flags & RADEON_IS_MOBILITY) {
2403 offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
2404 if (offset) {
2405 rev = RBIOS8(offset);
2406 blocks = RBIOS8(offset + 0x2);
2407 /* power mode 0 tends to be the only valid one */
2408 rdev->pm.power_state[state_index].num_clock_modes = 1;
2409 rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
2410 rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
2411 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2412 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2413 goto default_mode;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002414 rdev->pm.power_state[state_index].type =
2415 POWER_STATE_TYPE_BATTERY;
Alex Deucher56278a82009-12-28 13:58:44 -05002416 misc = RBIOS16(offset + 0x5 + 0x0);
2417 if (rev > 4)
2418 misc2 = RBIOS16(offset + 0x5 + 0xe);
Alex Deucher79daedc2010-04-22 14:25:19 -04002419 rdev->pm.power_state[state_index].misc = misc;
2420 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher56278a82009-12-28 13:58:44 -05002421 if (misc & 0x4) {
2422 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
2423 if (misc & 0x8)
2424 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2425 true;
2426 else
2427 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2428 false;
2429 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
2430 if (rev < 6) {
2431 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
2432 RBIOS16(offset + 0x5 + 0xb) * 4;
2433 tmp = RBIOS8(offset + 0x5 + 0xd);
2434 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
2435 } else {
2436 u8 entries = RBIOS8(offset + 0x5 + 0xb);
2437 u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
2438 if (entries && voltage_table_offset) {
2439 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
2440 RBIOS16(voltage_table_offset) * 4;
2441 tmp = RBIOS8(voltage_table_offset + 0x2);
2442 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
2443 } else
2444 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
2445 }
2446 switch ((misc2 & 0x700) >> 8) {
2447 case 0:
2448 default:
2449 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
2450 break;
2451 case 1:
2452 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
2453 break;
2454 case 2:
2455 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
2456 break;
2457 case 3:
2458 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
2459 break;
2460 case 4:
2461 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
2462 break;
2463 }
2464 } else
2465 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2466 if (rev > 6)
Alex Deucher79daedc2010-04-22 14:25:19 -04002467 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05002468 RBIOS8(offset + 0x5 + 0x10);
Alex Deucherd7311172010-05-03 01:13:14 -04002469 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05002470 state_index++;
2471 } else {
2472 /* XXX figure out some good default low power mode for mobility cards w/out power tables */
2473 }
2474 } else {
2475 /* XXX figure out some good default low power mode for desktop cards */
2476 }
2477
2478default_mode:
2479 /* add the default mode */
Alex Deucher0ec0e742009-12-23 13:21:58 -05002480 rdev->pm.power_state[state_index].type =
2481 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05002482 rdev->pm.power_state[state_index].num_clock_modes = 1;
2483 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2484 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2485 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 -04002486 if ((state_index > 0) &&
Alex Deucher8de016e2010-06-03 21:28:23 -04002487 (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
Alex Deucher84d88f42010-05-27 17:01:42 -04002488 rdev->pm.power_state[state_index].clock_info[0].voltage =
2489 rdev->pm.power_state[0].clock_info[0].voltage;
2490 else
2491 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
Alex Deucher79daedc2010-04-22 14:25:19 -04002492 rdev->pm.power_state[state_index].pcie_lanes = 16;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002493 rdev->pm.power_state[state_index].flags = 0;
2494 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05002495 rdev->pm.num_power_states = state_index + 1;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002496
Alex Deuchera48b9b42010-04-22 14:03:55 -04002497 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2498 rdev->pm.current_clock_mode_index = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002499}
2500
Alex Deucherfcec5702009-11-10 21:25:07 -05002501void radeon_external_tmds_setup(struct drm_encoder *encoder)
2502{
2503 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2504 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
2505
2506 if (!tmds)
2507 return;
2508
2509 switch (tmds->dvo_chip) {
2510 case DVO_SIL164:
2511 /* sil 164 */
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002512 radeon_i2c_put_byte(tmds->i2c_bus,
2513 tmds->slave_addr,
2514 0x08, 0x30);
2515 radeon_i2c_put_byte(tmds->i2c_bus,
Alex Deucherfcec5702009-11-10 21:25:07 -05002516 tmds->slave_addr,
2517 0x09, 0x00);
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002518 radeon_i2c_put_byte(tmds->i2c_bus,
2519 tmds->slave_addr,
2520 0x0a, 0x90);
2521 radeon_i2c_put_byte(tmds->i2c_bus,
2522 tmds->slave_addr,
2523 0x0c, 0x89);
2524 radeon_i2c_put_byte(tmds->i2c_bus,
Alex Deucherfcec5702009-11-10 21:25:07 -05002525 tmds->slave_addr,
2526 0x08, 0x3b);
Alex Deucherfcec5702009-11-10 21:25:07 -05002527 break;
2528 case DVO_SIL1178:
2529 /* sil 1178 - untested */
2530 /*
2531 * 0x0f, 0x44
2532 * 0x0f, 0x4c
2533 * 0x0e, 0x01
2534 * 0x0a, 0x80
2535 * 0x09, 0x30
2536 * 0x0c, 0xc9
2537 * 0x0d, 0x70
2538 * 0x08, 0x32
2539 * 0x08, 0x33
2540 */
2541 break;
2542 default:
2543 break;
2544 }
2545
2546}
2547
2548bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
2549{
2550 struct drm_device *dev = encoder->dev;
2551 struct radeon_device *rdev = dev->dev_private;
2552 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2553 uint16_t offset;
2554 uint8_t blocks, slave_addr, rev;
2555 uint32_t index, id;
2556 uint32_t reg, val, and_mask, or_mask;
2557 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
2558
Alex Deucherfcec5702009-11-10 21:25:07 -05002559 if (!tmds)
2560 return false;
2561
2562 if (rdev->flags & RADEON_IS_IGP) {
2563 offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
2564 rev = RBIOS8(offset);
2565 if (offset) {
2566 rev = RBIOS8(offset);
2567 if (rev > 1) {
2568 blocks = RBIOS8(offset + 3);
2569 index = offset + 4;
2570 while (blocks > 0) {
2571 id = RBIOS16(index);
2572 index += 2;
2573 switch (id >> 13) {
2574 case 0:
2575 reg = (id & 0x1fff) * 4;
2576 val = RBIOS32(index);
2577 index += 4;
2578 WREG32(reg, val);
2579 break;
2580 case 2:
2581 reg = (id & 0x1fff) * 4;
2582 and_mask = RBIOS32(index);
2583 index += 4;
2584 or_mask = RBIOS32(index);
2585 index += 4;
2586 val = RREG32(reg);
2587 val = (val & and_mask) | or_mask;
2588 WREG32(reg, val);
2589 break;
2590 case 3:
2591 val = RBIOS16(index);
2592 index += 2;
2593 udelay(val);
2594 break;
2595 case 4:
2596 val = RBIOS16(index);
2597 index += 2;
2598 udelay(val * 1000);
2599 break;
2600 case 6:
2601 slave_addr = id & 0xff;
2602 slave_addr >>= 1; /* 7 bit addressing */
2603 index++;
2604 reg = RBIOS8(index);
2605 index++;
2606 val = RBIOS8(index);
2607 index++;
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002608 radeon_i2c_put_byte(tmds->i2c_bus,
2609 slave_addr,
2610 reg, val);
Alex Deucherfcec5702009-11-10 21:25:07 -05002611 break;
2612 default:
2613 DRM_ERROR("Unknown id %d\n", id >> 13);
2614 break;
2615 }
2616 blocks--;
2617 }
2618 return true;
2619 }
2620 }
2621 } else {
2622 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
2623 if (offset) {
2624 index = offset + 10;
2625 id = RBIOS16(index);
2626 while (id != 0xffff) {
2627 index += 2;
2628 switch (id >> 13) {
2629 case 0:
2630 reg = (id & 0x1fff) * 4;
2631 val = RBIOS32(index);
2632 WREG32(reg, val);
2633 break;
2634 case 2:
2635 reg = (id & 0x1fff) * 4;
2636 and_mask = RBIOS32(index);
2637 index += 4;
2638 or_mask = RBIOS32(index);
2639 index += 4;
2640 val = RREG32(reg);
2641 val = (val & and_mask) | or_mask;
2642 WREG32(reg, val);
2643 break;
2644 case 4:
2645 val = RBIOS16(index);
2646 index += 2;
2647 udelay(val);
2648 break;
2649 case 5:
2650 reg = id & 0x1fff;
2651 and_mask = RBIOS32(index);
2652 index += 4;
2653 or_mask = RBIOS32(index);
2654 index += 4;
2655 val = RREG32_PLL(reg);
2656 val = (val & and_mask) | or_mask;
2657 WREG32_PLL(reg, val);
2658 break;
2659 case 6:
2660 reg = id & 0x1fff;
2661 val = RBIOS8(index);
2662 index += 1;
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002663 radeon_i2c_put_byte(tmds->i2c_bus,
2664 tmds->slave_addr,
2665 reg, val);
Alex Deucherfcec5702009-11-10 21:25:07 -05002666 break;
2667 default:
2668 DRM_ERROR("Unknown id %d\n", id >> 13);
2669 break;
2670 }
2671 id = RBIOS16(index);
2672 }
2673 return true;
2674 }
2675 }
2676 return false;
2677}
2678
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002679static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
2680{
2681 struct radeon_device *rdev = dev->dev_private;
2682
2683 if (offset) {
2684 while (RBIOS16(offset)) {
2685 uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
2686 uint32_t addr = (RBIOS16(offset) & 0x1fff);
2687 uint32_t val, and_mask, or_mask;
2688 uint32_t tmp;
2689
2690 offset += 2;
2691 switch (cmd) {
2692 case 0:
2693 val = RBIOS32(offset);
2694 offset += 4;
2695 WREG32(addr, val);
2696 break;
2697 case 1:
2698 val = RBIOS32(offset);
2699 offset += 4;
2700 WREG32(addr, val);
2701 break;
2702 case 2:
2703 and_mask = RBIOS32(offset);
2704 offset += 4;
2705 or_mask = RBIOS32(offset);
2706 offset += 4;
2707 tmp = RREG32(addr);
2708 tmp &= and_mask;
2709 tmp |= or_mask;
2710 WREG32(addr, tmp);
2711 break;
2712 case 3:
2713 and_mask = RBIOS32(offset);
2714 offset += 4;
2715 or_mask = RBIOS32(offset);
2716 offset += 4;
2717 tmp = RREG32(addr);
2718 tmp &= and_mask;
2719 tmp |= or_mask;
2720 WREG32(addr, tmp);
2721 break;
2722 case 4:
2723 val = RBIOS16(offset);
2724 offset += 2;
2725 udelay(val);
2726 break;
2727 case 5:
2728 val = RBIOS16(offset);
2729 offset += 2;
2730 switch (addr) {
2731 case 8:
2732 while (val--) {
2733 if (!
2734 (RREG32_PLL
2735 (RADEON_CLK_PWRMGT_CNTL) &
2736 RADEON_MC_BUSY))
2737 break;
2738 }
2739 break;
2740 case 9:
2741 while (val--) {
2742 if ((RREG32(RADEON_MC_STATUS) &
2743 RADEON_MC_IDLE))
2744 break;
2745 }
2746 break;
2747 default:
2748 break;
2749 }
2750 break;
2751 default:
2752 break;
2753 }
2754 }
2755 }
2756}
2757
2758static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
2759{
2760 struct radeon_device *rdev = dev->dev_private;
2761
2762 if (offset) {
2763 while (RBIOS8(offset)) {
2764 uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
2765 uint8_t addr = (RBIOS8(offset) & 0x3f);
2766 uint32_t val, shift, tmp;
2767 uint32_t and_mask, or_mask;
2768
2769 offset++;
2770 switch (cmd) {
2771 case 0:
2772 val = RBIOS32(offset);
2773 offset += 4;
2774 WREG32_PLL(addr, val);
2775 break;
2776 case 1:
2777 shift = RBIOS8(offset) * 8;
2778 offset++;
2779 and_mask = RBIOS8(offset) << shift;
2780 and_mask |= ~(0xff << shift);
2781 offset++;
2782 or_mask = RBIOS8(offset) << shift;
2783 offset++;
2784 tmp = RREG32_PLL(addr);
2785 tmp &= and_mask;
2786 tmp |= or_mask;
2787 WREG32_PLL(addr, tmp);
2788 break;
2789 case 2:
2790 case 3:
2791 tmp = 1000;
2792 switch (addr) {
2793 case 1:
2794 udelay(150);
2795 break;
2796 case 2:
2797 udelay(1000);
2798 break;
2799 case 3:
2800 while (tmp--) {
2801 if (!
2802 (RREG32_PLL
2803 (RADEON_CLK_PWRMGT_CNTL) &
2804 RADEON_MC_BUSY))
2805 break;
2806 }
2807 break;
2808 case 4:
2809 while (tmp--) {
2810 if (RREG32_PLL
2811 (RADEON_CLK_PWRMGT_CNTL) &
2812 RADEON_DLL_READY)
2813 break;
2814 }
2815 break;
2816 case 5:
2817 tmp =
2818 RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
2819 if (tmp & RADEON_CG_NO1_DEBUG_0) {
2820#if 0
2821 uint32_t mclk_cntl =
2822 RREG32_PLL
2823 (RADEON_MCLK_CNTL);
2824 mclk_cntl &= 0xffff0000;
2825 /*mclk_cntl |= 0x00001111;*//* ??? */
2826 WREG32_PLL(RADEON_MCLK_CNTL,
2827 mclk_cntl);
2828 udelay(10000);
2829#endif
2830 WREG32_PLL
2831 (RADEON_CLK_PWRMGT_CNTL,
2832 tmp &
2833 ~RADEON_CG_NO1_DEBUG_0);
2834 udelay(10000);
2835 }
2836 break;
2837 default:
2838 break;
2839 }
2840 break;
2841 default:
2842 break;
2843 }
2844 }
2845 }
2846}
2847
2848static void combios_parse_ram_reset_table(struct drm_device *dev,
2849 uint16_t offset)
2850{
2851 struct radeon_device *rdev = dev->dev_private;
2852 uint32_t tmp;
2853
2854 if (offset) {
2855 uint8_t val = RBIOS8(offset);
2856 while (val != 0xff) {
2857 offset++;
2858
2859 if (val == 0x0f) {
2860 uint32_t channel_complete_mask;
2861
2862 if (ASIC_IS_R300(rdev))
2863 channel_complete_mask =
2864 R300_MEM_PWRUP_COMPLETE;
2865 else
2866 channel_complete_mask =
2867 RADEON_MEM_PWRUP_COMPLETE;
2868 tmp = 20000;
2869 while (tmp--) {
2870 if ((RREG32(RADEON_MEM_STR_CNTL) &
2871 channel_complete_mask) ==
2872 channel_complete_mask)
2873 break;
2874 }
2875 } else {
2876 uint32_t or_mask = RBIOS16(offset);
2877 offset += 2;
2878
2879 tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
2880 tmp &= RADEON_SDRAM_MODE_MASK;
2881 tmp |= or_mask;
2882 WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
2883
2884 or_mask = val << 24;
2885 tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
2886 tmp &= RADEON_B3MEM_RESET_MASK;
2887 tmp |= or_mask;
2888 WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
2889 }
2890 val = RBIOS8(offset);
2891 }
2892 }
2893}
2894
2895static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
2896 int mem_addr_mapping)
2897{
2898 struct radeon_device *rdev = dev->dev_private;
2899 uint32_t mem_cntl;
2900 uint32_t mem_size;
2901 uint32_t addr = 0;
2902
2903 mem_cntl = RREG32(RADEON_MEM_CNTL);
2904 if (mem_cntl & RV100_HALF_MODE)
2905 ram /= 2;
2906 mem_size = ram;
2907 mem_cntl &= ~(0xff << 8);
2908 mem_cntl |= (mem_addr_mapping & 0xff) << 8;
2909 WREG32(RADEON_MEM_CNTL, mem_cntl);
2910 RREG32(RADEON_MEM_CNTL);
2911
2912 /* sdram reset ? */
2913
2914 /* something like this???? */
2915 while (ram--) {
2916 addr = ram * 1024 * 1024;
2917 /* write to each page */
2918 WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
2919 WREG32(RADEON_MM_DATA, 0xdeadbeef);
2920 /* read back and verify */
2921 WREG32(RADEON_MM_INDEX, (addr) | RADEON_MM_APER);
2922 if (RREG32(RADEON_MM_DATA) != 0xdeadbeef)
2923 return 0;
2924 }
2925
2926 return mem_size;
2927}
2928
2929static void combios_write_ram_size(struct drm_device *dev)
2930{
2931 struct radeon_device *rdev = dev->dev_private;
2932 uint8_t rev;
2933 uint16_t offset;
2934 uint32_t mem_size = 0;
2935 uint32_t mem_cntl = 0;
2936
2937 /* should do something smarter here I guess... */
2938 if (rdev->flags & RADEON_IS_IGP)
2939 return;
2940
2941 /* first check detected mem table */
2942 offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
2943 if (offset) {
2944 rev = RBIOS8(offset);
2945 if (rev < 3) {
2946 mem_cntl = RBIOS32(offset + 1);
2947 mem_size = RBIOS16(offset + 5);
Alex Deucher4ce91982010-06-30 12:13:55 -04002948 if ((rdev->family < CHIP_R200) &&
2949 !ASIC_IS_RN50(rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002950 WREG32(RADEON_MEM_CNTL, mem_cntl);
2951 }
2952 }
2953
2954 if (!mem_size) {
2955 offset =
2956 combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
2957 if (offset) {
2958 rev = RBIOS8(offset - 1);
2959 if (rev < 1) {
Alex Deucher4ce91982010-06-30 12:13:55 -04002960 if ((rdev->family < CHIP_R200)
2961 && !ASIC_IS_RN50(rdev)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002962 int ram = 0;
2963 int mem_addr_mapping = 0;
2964
2965 while (RBIOS8(offset)) {
2966 ram = RBIOS8(offset);
2967 mem_addr_mapping =
2968 RBIOS8(offset + 1);
2969 if (mem_addr_mapping != 0x25)
2970 ram *= 2;
2971 mem_size =
2972 combios_detect_ram(dev, ram,
2973 mem_addr_mapping);
2974 if (mem_size)
2975 break;
2976 offset += 2;
2977 }
2978 } else
2979 mem_size = RBIOS8(offset);
2980 } else {
2981 mem_size = RBIOS8(offset);
2982 mem_size *= 2; /* convert to MB */
2983 }
2984 }
2985 }
2986
2987 mem_size *= (1024 * 1024); /* convert to bytes */
2988 WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
2989}
2990
2991void radeon_combios_dyn_clk_setup(struct drm_device *dev, int enable)
2992{
2993 uint16_t dyn_clk_info =
2994 combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
2995
2996 if (dyn_clk_info)
2997 combios_parse_pll_table(dev, dyn_clk_info);
2998}
2999
3000void radeon_combios_asic_init(struct drm_device *dev)
3001{
3002 struct radeon_device *rdev = dev->dev_private;
3003 uint16_t table;
3004
3005 /* port hardcoded mac stuff from radeonfb */
3006 if (rdev->bios == NULL)
3007 return;
3008
3009 /* ASIC INIT 1 */
3010 table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
3011 if (table)
3012 combios_parse_mmio_table(dev, table);
3013
3014 /* PLL INIT */
3015 table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
3016 if (table)
3017 combios_parse_pll_table(dev, table);
3018
3019 /* ASIC INIT 2 */
3020 table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
3021 if (table)
3022 combios_parse_mmio_table(dev, table);
3023
3024 if (!(rdev->flags & RADEON_IS_IGP)) {
3025 /* ASIC INIT 4 */
3026 table =
3027 combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
3028 if (table)
3029 combios_parse_mmio_table(dev, table);
3030
3031 /* RAM RESET */
3032 table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
3033 if (table)
3034 combios_parse_ram_reset_table(dev, table);
3035
3036 /* ASIC INIT 3 */
3037 table =
3038 combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
3039 if (table)
3040 combios_parse_mmio_table(dev, table);
3041
3042 /* write CONFIG_MEMSIZE */
3043 combios_write_ram_size(dev);
3044 }
3045
Dave Airlie580b4ff2010-06-30 13:26:11 +10003046 /* quirk for rs4xx HP nx6125 laptop to make it resume
3047 * - it hangs on resume inside the dynclk 1 table.
3048 */
3049 if (rdev->family == CHIP_RS480 &&
3050 rdev->pdev->subsystem_vendor == 0x103c &&
3051 rdev->pdev->subsystem_device == 0x308b)
3052 return;
3053
Alex Deucher52fa2bb2010-07-21 23:54:35 -04003054 /* quirk for rs4xx HP dv5000 laptop to make it resume
3055 * - it hangs on resume inside the dynclk 1 table.
3056 */
3057 if (rdev->family == CHIP_RS480 &&
3058 rdev->pdev->subsystem_vendor == 0x103c &&
3059 rdev->pdev->subsystem_device == 0x30a4)
3060 return;
3061
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003062 /* DYN CLK 1 */
3063 table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
3064 if (table)
3065 combios_parse_pll_table(dev, table);
3066
3067}
3068
3069void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
3070{
3071 struct radeon_device *rdev = dev->dev_private;
3072 uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
3073
3074 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
3075 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3076 bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
3077
3078 /* let the bios control the backlight */
3079 bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
3080
3081 /* tell the bios not to handle mode switching */
3082 bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
3083 RADEON_ACC_MODE_CHANGE);
3084
3085 /* tell the bios a driver is loaded */
3086 bios_7_scratch |= RADEON_DRV_LOADED;
3087
3088 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
3089 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3090 WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
3091}
3092
3093void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
3094{
3095 struct drm_device *dev = encoder->dev;
3096 struct radeon_device *rdev = dev->dev_private;
3097 uint32_t bios_6_scratch;
3098
3099 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3100
3101 if (lock)
3102 bios_6_scratch |= RADEON_DRIVER_CRITICAL;
3103 else
3104 bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
3105
3106 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3107}
3108
3109void
3110radeon_combios_connected_scratch_regs(struct drm_connector *connector,
3111 struct drm_encoder *encoder,
3112 bool connected)
3113{
3114 struct drm_device *dev = connector->dev;
3115 struct radeon_device *rdev = dev->dev_private;
3116 struct radeon_connector *radeon_connector =
3117 to_radeon_connector(connector);
3118 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3119 uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
3120 uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
3121
3122 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
3123 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
3124 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003125 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003126 /* fix me */
3127 bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
3128 /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
3129 bios_5_scratch |= RADEON_TV1_ON;
3130 bios_5_scratch |= RADEON_ACC_REQ_TV1;
3131 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003132 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003133 bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
3134 bios_5_scratch &= ~RADEON_TV1_ON;
3135 bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
3136 }
3137 }
3138 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
3139 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
3140 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003141 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003142 bios_4_scratch |= RADEON_LCD1_ATTACHED;
3143 bios_5_scratch |= RADEON_LCD1_ON;
3144 bios_5_scratch |= RADEON_ACC_REQ_LCD1;
3145 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003146 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003147 bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
3148 bios_5_scratch &= ~RADEON_LCD1_ON;
3149 bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
3150 }
3151 }
3152 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
3153 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
3154 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003155 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003156 bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
3157 bios_5_scratch |= RADEON_CRT1_ON;
3158 bios_5_scratch |= RADEON_ACC_REQ_CRT1;
3159 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003160 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003161 bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
3162 bios_5_scratch &= ~RADEON_CRT1_ON;
3163 bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
3164 }
3165 }
3166 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
3167 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
3168 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003169 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003170 bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
3171 bios_5_scratch |= RADEON_CRT2_ON;
3172 bios_5_scratch |= RADEON_ACC_REQ_CRT2;
3173 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003174 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003175 bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
3176 bios_5_scratch &= ~RADEON_CRT2_ON;
3177 bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
3178 }
3179 }
3180 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
3181 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
3182 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003183 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003184 bios_4_scratch |= RADEON_DFP1_ATTACHED;
3185 bios_5_scratch |= RADEON_DFP1_ON;
3186 bios_5_scratch |= RADEON_ACC_REQ_DFP1;
3187 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003188 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003189 bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
3190 bios_5_scratch &= ~RADEON_DFP1_ON;
3191 bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
3192 }
3193 }
3194 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
3195 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
3196 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003197 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003198 bios_4_scratch |= RADEON_DFP2_ATTACHED;
3199 bios_5_scratch |= RADEON_DFP2_ON;
3200 bios_5_scratch |= RADEON_ACC_REQ_DFP2;
3201 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003202 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003203 bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
3204 bios_5_scratch &= ~RADEON_DFP2_ON;
3205 bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
3206 }
3207 }
3208 WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
3209 WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
3210}
3211
3212void
3213radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
3214{
3215 struct drm_device *dev = encoder->dev;
3216 struct radeon_device *rdev = dev->dev_private;
3217 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3218 uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
3219
3220 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
3221 bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
3222 bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
3223 }
3224 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3225 bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
3226 bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
3227 }
3228 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3229 bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
3230 bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
3231 }
3232 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3233 bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
3234 bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
3235 }
3236 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3237 bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
3238 bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
3239 }
3240 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3241 bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
3242 bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
3243 }
3244 WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
3245}
3246
3247void
3248radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
3249{
3250 struct drm_device *dev = encoder->dev;
3251 struct radeon_device *rdev = dev->dev_private;
3252 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3253 uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3254
3255 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
3256 if (on)
3257 bios_6_scratch |= RADEON_TV_DPMS_ON;
3258 else
3259 bios_6_scratch &= ~RADEON_TV_DPMS_ON;
3260 }
3261 if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
3262 if (on)
3263 bios_6_scratch |= RADEON_CRT_DPMS_ON;
3264 else
3265 bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
3266 }
3267 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
3268 if (on)
3269 bios_6_scratch |= RADEON_LCD_DPMS_ON;
3270 else
3271 bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
3272 }
3273 if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
3274 if (on)
3275 bios_6_scratch |= RADEON_DFP_DPMS_ON;
3276 else
3277 bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
3278 }
3279 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3280}