blob: 8528b81cd64fc7db2131ab853dc7ab66577d14ab [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 */
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/drmP.h>
28#include <drm/radeon_drm.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020029#include "radeon.h"
30#include "atom.h"
31
32#ifdef CONFIG_PPC_PMAC
33/* not sure which of these are needed */
34#include <asm/machdep.h>
35#include <asm/pmac_feature.h>
36#include <asm/prom.h>
37#include <asm/pci-bridge.h>
38#endif /* CONFIG_PPC_PMAC */
39
40/* from radeon_encoder.c */
41extern uint32_t
Alex Deucher5137ee92010-08-12 18:58:47 -040042radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
43 uint8_t dac);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020044extern void radeon_link_encoder_connector(struct drm_device *dev);
45
46/* from radeon_connector.c */
47extern void
48radeon_add_legacy_connector(struct drm_device *dev,
49 uint32_t connector_id,
50 uint32_t supported_device,
51 int connector_type,
Alex Deucherb75fad02009-11-05 13:16:01 -050052 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -050053 uint16_t connector_object_id,
54 struct radeon_hpd *hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020055
56/* from radeon_legacy_encoder.c */
57extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040058radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
Jerome Glisse771fe6b2009-06-05 14:42:42 +020059 uint32_t supported_device);
60
61/* old legacy ATI BIOS routines */
62
63/* COMBIOS table offsets */
64enum radeon_combios_table_offset {
65 /* absolute offset tables */
66 COMBIOS_ASIC_INIT_1_TABLE,
67 COMBIOS_BIOS_SUPPORT_TABLE,
68 COMBIOS_DAC_PROGRAMMING_TABLE,
69 COMBIOS_MAX_COLOR_DEPTH_TABLE,
70 COMBIOS_CRTC_INFO_TABLE,
71 COMBIOS_PLL_INFO_TABLE,
72 COMBIOS_TV_INFO_TABLE,
73 COMBIOS_DFP_INFO_TABLE,
74 COMBIOS_HW_CONFIG_INFO_TABLE,
75 COMBIOS_MULTIMEDIA_INFO_TABLE,
76 COMBIOS_TV_STD_PATCH_TABLE,
77 COMBIOS_LCD_INFO_TABLE,
78 COMBIOS_MOBILE_INFO_TABLE,
79 COMBIOS_PLL_INIT_TABLE,
80 COMBIOS_MEM_CONFIG_TABLE,
81 COMBIOS_SAVE_MASK_TABLE,
82 COMBIOS_HARDCODED_EDID_TABLE,
83 COMBIOS_ASIC_INIT_2_TABLE,
84 COMBIOS_CONNECTOR_INFO_TABLE,
85 COMBIOS_DYN_CLK_1_TABLE,
86 COMBIOS_RESERVED_MEM_TABLE,
87 COMBIOS_EXT_TMDS_INFO_TABLE,
88 COMBIOS_MEM_CLK_INFO_TABLE,
89 COMBIOS_EXT_DAC_INFO_TABLE,
90 COMBIOS_MISC_INFO_TABLE,
91 COMBIOS_CRT_INFO_TABLE,
92 COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE,
93 COMBIOS_COMPONENT_VIDEO_INFO_TABLE,
94 COMBIOS_FAN_SPEED_INFO_TABLE,
95 COMBIOS_OVERDRIVE_INFO_TABLE,
96 COMBIOS_OEM_INFO_TABLE,
97 COMBIOS_DYN_CLK_2_TABLE,
98 COMBIOS_POWER_CONNECTOR_INFO_TABLE,
99 COMBIOS_I2C_INFO_TABLE,
100 /* relative offset tables */
101 COMBIOS_ASIC_INIT_3_TABLE, /* offset from misc info */
102 COMBIOS_ASIC_INIT_4_TABLE, /* offset from misc info */
103 COMBIOS_DETECTED_MEM_TABLE, /* offset from misc info */
104 COMBIOS_ASIC_INIT_5_TABLE, /* offset from misc info */
105 COMBIOS_RAM_RESET_TABLE, /* offset from mem config */
106 COMBIOS_POWERPLAY_INFO_TABLE, /* offset from mobile info */
107 COMBIOS_GPIO_INFO_TABLE, /* offset from mobile info */
108 COMBIOS_LCD_DDC_INFO_TABLE, /* offset from mobile info */
109 COMBIOS_TMDS_POWER_TABLE, /* offset from mobile info */
110 COMBIOS_TMDS_POWER_ON_TABLE, /* offset from tmds power */
111 COMBIOS_TMDS_POWER_OFF_TABLE, /* offset from tmds power */
112};
113
114enum radeon_combios_ddc {
115 DDC_NONE_DETECTED,
116 DDC_MONID,
117 DDC_DVI,
118 DDC_VGA,
119 DDC_CRT2,
120 DDC_LCD,
121 DDC_GPIO,
122};
123
124enum radeon_combios_connector {
125 CONNECTOR_NONE_LEGACY,
126 CONNECTOR_PROPRIETARY_LEGACY,
127 CONNECTOR_CRT_LEGACY,
128 CONNECTOR_DVI_I_LEGACY,
129 CONNECTOR_DVI_D_LEGACY,
130 CONNECTOR_CTV_LEGACY,
131 CONNECTOR_STV_LEGACY,
132 CONNECTOR_UNSUPPORTED_LEGACY
133};
134
135const int legacy_connector_convert[] = {
136 DRM_MODE_CONNECTOR_Unknown,
137 DRM_MODE_CONNECTOR_DVID,
138 DRM_MODE_CONNECTOR_VGA,
139 DRM_MODE_CONNECTOR_DVII,
140 DRM_MODE_CONNECTOR_DVID,
141 DRM_MODE_CONNECTOR_Composite,
142 DRM_MODE_CONNECTOR_SVIDEO,
143 DRM_MODE_CONNECTOR_Unknown,
144};
145
146static uint16_t combios_get_table_offset(struct drm_device *dev,
147 enum radeon_combios_table_offset table)
148{
149 struct radeon_device *rdev = dev->dev_private;
150 int rev;
151 uint16_t offset = 0, check_offset;
152
Michel Dänzer03047cd2010-02-10 11:05:11 +0100153 if (!rdev->bios)
154 return 0;
155
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200156 switch (table) {
157 /* absolute offset tables */
158 case COMBIOS_ASIC_INIT_1_TABLE:
159 check_offset = RBIOS16(rdev->bios_header_start + 0xc);
160 if (check_offset)
161 offset = check_offset;
162 break;
163 case COMBIOS_BIOS_SUPPORT_TABLE:
164 check_offset = RBIOS16(rdev->bios_header_start + 0x14);
165 if (check_offset)
166 offset = check_offset;
167 break;
168 case COMBIOS_DAC_PROGRAMMING_TABLE:
169 check_offset = RBIOS16(rdev->bios_header_start + 0x2a);
170 if (check_offset)
171 offset = check_offset;
172 break;
173 case COMBIOS_MAX_COLOR_DEPTH_TABLE:
174 check_offset = RBIOS16(rdev->bios_header_start + 0x2c);
175 if (check_offset)
176 offset = check_offset;
177 break;
178 case COMBIOS_CRTC_INFO_TABLE:
179 check_offset = RBIOS16(rdev->bios_header_start + 0x2e);
180 if (check_offset)
181 offset = check_offset;
182 break;
183 case COMBIOS_PLL_INFO_TABLE:
184 check_offset = RBIOS16(rdev->bios_header_start + 0x30);
185 if (check_offset)
186 offset = check_offset;
187 break;
188 case COMBIOS_TV_INFO_TABLE:
189 check_offset = RBIOS16(rdev->bios_header_start + 0x32);
190 if (check_offset)
191 offset = check_offset;
192 break;
193 case COMBIOS_DFP_INFO_TABLE:
194 check_offset = RBIOS16(rdev->bios_header_start + 0x34);
195 if (check_offset)
196 offset = check_offset;
197 break;
198 case COMBIOS_HW_CONFIG_INFO_TABLE:
199 check_offset = RBIOS16(rdev->bios_header_start + 0x36);
200 if (check_offset)
201 offset = check_offset;
202 break;
203 case COMBIOS_MULTIMEDIA_INFO_TABLE:
204 check_offset = RBIOS16(rdev->bios_header_start + 0x38);
205 if (check_offset)
206 offset = check_offset;
207 break;
208 case COMBIOS_TV_STD_PATCH_TABLE:
209 check_offset = RBIOS16(rdev->bios_header_start + 0x3e);
210 if (check_offset)
211 offset = check_offset;
212 break;
213 case COMBIOS_LCD_INFO_TABLE:
214 check_offset = RBIOS16(rdev->bios_header_start + 0x40);
215 if (check_offset)
216 offset = check_offset;
217 break;
218 case COMBIOS_MOBILE_INFO_TABLE:
219 check_offset = RBIOS16(rdev->bios_header_start + 0x42);
220 if (check_offset)
221 offset = check_offset;
222 break;
223 case COMBIOS_PLL_INIT_TABLE:
224 check_offset = RBIOS16(rdev->bios_header_start + 0x46);
225 if (check_offset)
226 offset = check_offset;
227 break;
228 case COMBIOS_MEM_CONFIG_TABLE:
229 check_offset = RBIOS16(rdev->bios_header_start + 0x48);
230 if (check_offset)
231 offset = check_offset;
232 break;
233 case COMBIOS_SAVE_MASK_TABLE:
234 check_offset = RBIOS16(rdev->bios_header_start + 0x4a);
235 if (check_offset)
236 offset = check_offset;
237 break;
238 case COMBIOS_HARDCODED_EDID_TABLE:
239 check_offset = RBIOS16(rdev->bios_header_start + 0x4c);
240 if (check_offset)
241 offset = check_offset;
242 break;
243 case COMBIOS_ASIC_INIT_2_TABLE:
244 check_offset = RBIOS16(rdev->bios_header_start + 0x4e);
245 if (check_offset)
246 offset = check_offset;
247 break;
248 case COMBIOS_CONNECTOR_INFO_TABLE:
249 check_offset = RBIOS16(rdev->bios_header_start + 0x50);
250 if (check_offset)
251 offset = check_offset;
252 break;
253 case COMBIOS_DYN_CLK_1_TABLE:
254 check_offset = RBIOS16(rdev->bios_header_start + 0x52);
255 if (check_offset)
256 offset = check_offset;
257 break;
258 case COMBIOS_RESERVED_MEM_TABLE:
259 check_offset = RBIOS16(rdev->bios_header_start + 0x54);
260 if (check_offset)
261 offset = check_offset;
262 break;
263 case COMBIOS_EXT_TMDS_INFO_TABLE:
264 check_offset = RBIOS16(rdev->bios_header_start + 0x58);
265 if (check_offset)
266 offset = check_offset;
267 break;
268 case COMBIOS_MEM_CLK_INFO_TABLE:
269 check_offset = RBIOS16(rdev->bios_header_start + 0x5a);
270 if (check_offset)
271 offset = check_offset;
272 break;
273 case COMBIOS_EXT_DAC_INFO_TABLE:
274 check_offset = RBIOS16(rdev->bios_header_start + 0x5c);
275 if (check_offset)
276 offset = check_offset;
277 break;
278 case COMBIOS_MISC_INFO_TABLE:
279 check_offset = RBIOS16(rdev->bios_header_start + 0x5e);
280 if (check_offset)
281 offset = check_offset;
282 break;
283 case COMBIOS_CRT_INFO_TABLE:
284 check_offset = RBIOS16(rdev->bios_header_start + 0x60);
285 if (check_offset)
286 offset = check_offset;
287 break;
288 case COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE:
289 check_offset = RBIOS16(rdev->bios_header_start + 0x62);
290 if (check_offset)
291 offset = check_offset;
292 break;
293 case COMBIOS_COMPONENT_VIDEO_INFO_TABLE:
294 check_offset = RBIOS16(rdev->bios_header_start + 0x64);
295 if (check_offset)
296 offset = check_offset;
297 break;
298 case COMBIOS_FAN_SPEED_INFO_TABLE:
299 check_offset = RBIOS16(rdev->bios_header_start + 0x66);
300 if (check_offset)
301 offset = check_offset;
302 break;
303 case COMBIOS_OVERDRIVE_INFO_TABLE:
304 check_offset = RBIOS16(rdev->bios_header_start + 0x68);
305 if (check_offset)
306 offset = check_offset;
307 break;
308 case COMBIOS_OEM_INFO_TABLE:
309 check_offset = RBIOS16(rdev->bios_header_start + 0x6a);
310 if (check_offset)
311 offset = check_offset;
312 break;
313 case COMBIOS_DYN_CLK_2_TABLE:
314 check_offset = RBIOS16(rdev->bios_header_start + 0x6c);
315 if (check_offset)
316 offset = check_offset;
317 break;
318 case COMBIOS_POWER_CONNECTOR_INFO_TABLE:
319 check_offset = RBIOS16(rdev->bios_header_start + 0x6e);
320 if (check_offset)
321 offset = check_offset;
322 break;
323 case COMBIOS_I2C_INFO_TABLE:
324 check_offset = RBIOS16(rdev->bios_header_start + 0x70);
325 if (check_offset)
326 offset = check_offset;
327 break;
328 /* relative offset tables */
329 case COMBIOS_ASIC_INIT_3_TABLE: /* offset from misc info */
330 check_offset =
331 combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
332 if (check_offset) {
333 rev = RBIOS8(check_offset);
334 if (rev > 0) {
335 check_offset = RBIOS16(check_offset + 0x3);
336 if (check_offset)
337 offset = check_offset;
338 }
339 }
340 break;
341 case COMBIOS_ASIC_INIT_4_TABLE: /* offset from misc info */
342 check_offset =
343 combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
344 if (check_offset) {
345 rev = RBIOS8(check_offset);
346 if (rev > 0) {
347 check_offset = RBIOS16(check_offset + 0x5);
348 if (check_offset)
349 offset = check_offset;
350 }
351 }
352 break;
353 case COMBIOS_DETECTED_MEM_TABLE: /* offset from misc info */
354 check_offset =
355 combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
356 if (check_offset) {
357 rev = RBIOS8(check_offset);
358 if (rev > 0) {
359 check_offset = RBIOS16(check_offset + 0x7);
360 if (check_offset)
361 offset = check_offset;
362 }
363 }
364 break;
365 case COMBIOS_ASIC_INIT_5_TABLE: /* offset from misc info */
366 check_offset =
367 combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
368 if (check_offset) {
369 rev = RBIOS8(check_offset);
370 if (rev == 2) {
371 check_offset = RBIOS16(check_offset + 0x9);
372 if (check_offset)
373 offset = check_offset;
374 }
375 }
376 break;
377 case COMBIOS_RAM_RESET_TABLE: /* offset from mem config */
378 check_offset =
379 combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
380 if (check_offset) {
381 while (RBIOS8(check_offset++));
382 check_offset += 2;
383 if (check_offset)
384 offset = check_offset;
385 }
386 break;
387 case COMBIOS_POWERPLAY_INFO_TABLE: /* offset from mobile info */
388 check_offset =
389 combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
390 if (check_offset) {
391 check_offset = RBIOS16(check_offset + 0x11);
392 if (check_offset)
393 offset = check_offset;
394 }
395 break;
396 case COMBIOS_GPIO_INFO_TABLE: /* offset from mobile info */
397 check_offset =
398 combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
399 if (check_offset) {
400 check_offset = RBIOS16(check_offset + 0x13);
401 if (check_offset)
402 offset = check_offset;
403 }
404 break;
405 case COMBIOS_LCD_DDC_INFO_TABLE: /* offset from mobile info */
406 check_offset =
407 combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
408 if (check_offset) {
409 check_offset = RBIOS16(check_offset + 0x15);
410 if (check_offset)
411 offset = check_offset;
412 }
413 break;
414 case COMBIOS_TMDS_POWER_TABLE: /* offset from mobile info */
415 check_offset =
416 combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
417 if (check_offset) {
418 check_offset = RBIOS16(check_offset + 0x17);
419 if (check_offset)
420 offset = check_offset;
421 }
422 break;
423 case COMBIOS_TMDS_POWER_ON_TABLE: /* offset from tmds power */
424 check_offset =
425 combios_get_table_offset(dev, COMBIOS_TMDS_POWER_TABLE);
426 if (check_offset) {
427 check_offset = RBIOS16(check_offset + 0x2);
428 if (check_offset)
429 offset = check_offset;
430 }
431 break;
432 case COMBIOS_TMDS_POWER_OFF_TABLE: /* offset from tmds power */
433 check_offset =
434 combios_get_table_offset(dev, COMBIOS_TMDS_POWER_TABLE);
435 if (check_offset) {
436 check_offset = RBIOS16(check_offset + 0x4);
437 if (check_offset)
438 offset = check_offset;
439 }
440 break;
441 default:
442 break;
443 }
444
445 return offset;
446
447}
448
Alex Deucher3c537882010-02-05 04:21:19 -0500449bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev)
450{
Alex Deucherfafcf942011-03-23 08:10:10 +0000451 int edid_info, size;
Alex Deucher3c537882010-02-05 04:21:19 -0500452 struct edid *edid;
Adam Jackson7466f4c2010-03-29 21:43:23 +0000453 unsigned char *raw;
Alex Deucher3c537882010-02-05 04:21:19 -0500454 edid_info = combios_get_table_offset(rdev->ddev, COMBIOS_HARDCODED_EDID_TABLE);
455 if (!edid_info)
456 return false;
457
Adam Jackson7466f4c2010-03-29 21:43:23 +0000458 raw = rdev->bios + edid_info;
Alex Deucherfafcf942011-03-23 08:10:10 +0000459 size = EDID_LENGTH * (raw[0x7e] + 1);
460 edid = kmalloc(size, GFP_KERNEL);
Alex Deucher3c537882010-02-05 04:21:19 -0500461 if (edid == NULL)
462 return false;
463
Alex Deucherfafcf942011-03-23 08:10:10 +0000464 memcpy((unsigned char *)edid, raw, size);
Alex Deucher3c537882010-02-05 04:21:19 -0500465
466 if (!drm_edid_is_valid(edid)) {
467 kfree(edid);
468 return false;
469 }
470
471 rdev->mode_info.bios_hardcoded_edid = edid;
Alex Deucherfafcf942011-03-23 08:10:10 +0000472 rdev->mode_info.bios_hardcoded_edid_size = size;
Alex Deucher3c537882010-02-05 04:21:19 -0500473 return true;
474}
475
Alex Deucherc324acd2010-12-08 22:13:06 -0500476/* this is used for atom LCDs as well */
Alex Deucher3c537882010-02-05 04:21:19 -0500477struct edid *
Alex Deucherc324acd2010-12-08 22:13:06 -0500478radeon_bios_get_hardcoded_edid(struct radeon_device *rdev)
Alex Deucher3c537882010-02-05 04:21:19 -0500479{
Alex Deucherfafcf942011-03-23 08:10:10 +0000480 struct edid *edid;
481
482 if (rdev->mode_info.bios_hardcoded_edid) {
483 edid = kmalloc(rdev->mode_info.bios_hardcoded_edid_size, GFP_KERNEL);
484 if (edid) {
485 memcpy((unsigned char *)edid,
486 (unsigned char *)rdev->mode_info.bios_hardcoded_edid,
487 rdev->mode_info.bios_hardcoded_edid_size);
488 return edid;
489 }
490 }
Alex Deucher3c537882010-02-05 04:21:19 -0500491 return NULL;
492}
493
Alex Deucher6a93cb22009-11-23 17:39:28 -0500494static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
Alex Deucher179e8072010-08-05 21:21:17 -0400495 enum radeon_combios_ddc ddc,
496 u32 clk_mask,
497 u32 data_mask)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200498{
499 struct radeon_i2c_bus_rec i2c;
Alex Deucher179e8072010-08-05 21:21:17 -0400500 int ddc_line = 0;
501
502 /* ddc id = mask reg
503 * DDC_NONE_DETECTED = none
504 * DDC_DVI = RADEON_GPIO_DVI_DDC
505 * DDC_VGA = RADEON_GPIO_VGA_DDC
506 * DDC_LCD = RADEON_GPIOPAD_MASK
507 * DDC_GPIO = RADEON_MDGPIO_MASK
Alex Deucher508c8d62011-05-03 19:47:44 -0400508 * r1xx
Alex Deucher179e8072010-08-05 21:21:17 -0400509 * DDC_MONID = RADEON_GPIO_MONID
510 * DDC_CRT2 = RADEON_GPIO_CRT2_DDC
Alex Deucher508c8d62011-05-03 19:47:44 -0400511 * r200
Alex Deucher179e8072010-08-05 21:21:17 -0400512 * DDC_MONID = RADEON_GPIO_MONID
513 * DDC_CRT2 = RADEON_GPIO_DVI_DDC
Alex Deucher508c8d62011-05-03 19:47:44 -0400514 * r300/r350
515 * DDC_MONID = RADEON_GPIO_DVI_DDC
516 * DDC_CRT2 = RADEON_GPIO_DVI_DDC
517 * rv2xx/rv3xx
518 * DDC_MONID = RADEON_GPIO_MONID
519 * DDC_CRT2 = RADEON_GPIO_MONID
Alex Deucher179e8072010-08-05 21:21:17 -0400520 * rs3xx/rs4xx
521 * DDC_MONID = RADEON_GPIOPAD_MASK
522 * DDC_CRT2 = RADEON_GPIO_MONID
523 */
524 switch (ddc) {
525 case DDC_NONE_DETECTED:
526 default:
527 ddc_line = 0;
528 break;
529 case DDC_DVI:
530 ddc_line = RADEON_GPIO_DVI_DDC;
531 break;
532 case DDC_VGA:
533 ddc_line = RADEON_GPIO_VGA_DDC;
534 break;
535 case DDC_LCD:
536 ddc_line = RADEON_GPIOPAD_MASK;
537 break;
538 case DDC_GPIO:
539 ddc_line = RADEON_MDGPIO_MASK;
540 break;
541 case DDC_MONID:
542 if (rdev->family == CHIP_RS300 ||
543 rdev->family == CHIP_RS400 ||
544 rdev->family == CHIP_RS480)
545 ddc_line = RADEON_GPIOPAD_MASK;
Alex Deucher508c8d62011-05-03 19:47:44 -0400546 else if (rdev->family == CHIP_R300 ||
Alex Deucher776f2b72011-05-04 15:14:44 +0000547 rdev->family == CHIP_R350) {
Alex Deucher508c8d62011-05-03 19:47:44 -0400548 ddc_line = RADEON_GPIO_DVI_DDC;
Alex Deucher776f2b72011-05-04 15:14:44 +0000549 ddc = DDC_DVI;
550 } else
Alex Deucher179e8072010-08-05 21:21:17 -0400551 ddc_line = RADEON_GPIO_MONID;
552 break;
553 case DDC_CRT2:
Alex Deucher508c8d62011-05-03 19:47:44 -0400554 if (rdev->family == CHIP_R200 ||
555 rdev->family == CHIP_R300 ||
Alex Deucher776f2b72011-05-04 15:14:44 +0000556 rdev->family == CHIP_R350) {
Alex Deucher179e8072010-08-05 21:21:17 -0400557 ddc_line = RADEON_GPIO_DVI_DDC;
Alex Deucher776f2b72011-05-04 15:14:44 +0000558 ddc = DDC_DVI;
559 } else if (rdev->family == CHIP_RS300 ||
560 rdev->family == CHIP_RS400 ||
561 rdev->family == CHIP_RS480)
Alex Deucher508c8d62011-05-03 19:47:44 -0400562 ddc_line = RADEON_GPIO_MONID;
Alex Deucher776f2b72011-05-04 15:14:44 +0000563 else if (rdev->family >= CHIP_RV350) {
564 ddc_line = RADEON_GPIO_MONID;
565 ddc = DDC_MONID;
566 } else
Alex Deucher179e8072010-08-05 21:21:17 -0400567 ddc_line = RADEON_GPIO_CRT2_DDC;
568 break;
569 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200570
Alex Deucher6a93cb22009-11-23 17:39:28 -0500571 if (ddc_line == RADEON_GPIOPAD_MASK) {
572 i2c.mask_clk_reg = RADEON_GPIOPAD_MASK;
573 i2c.mask_data_reg = RADEON_GPIOPAD_MASK;
574 i2c.a_clk_reg = RADEON_GPIOPAD_A;
575 i2c.a_data_reg = RADEON_GPIOPAD_A;
576 i2c.en_clk_reg = RADEON_GPIOPAD_EN;
577 i2c.en_data_reg = RADEON_GPIOPAD_EN;
578 i2c.y_clk_reg = RADEON_GPIOPAD_Y;
579 i2c.y_data_reg = RADEON_GPIOPAD_Y;
580 } else if (ddc_line == RADEON_MDGPIO_MASK) {
581 i2c.mask_clk_reg = RADEON_MDGPIO_MASK;
582 i2c.mask_data_reg = RADEON_MDGPIO_MASK;
583 i2c.a_clk_reg = RADEON_MDGPIO_A;
584 i2c.a_data_reg = RADEON_MDGPIO_A;
585 i2c.en_clk_reg = RADEON_MDGPIO_EN;
586 i2c.en_data_reg = RADEON_MDGPIO_EN;
587 i2c.y_clk_reg = RADEON_MDGPIO_Y;
588 i2c.y_data_reg = RADEON_MDGPIO_Y;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200589 } else {
590 i2c.mask_clk_reg = ddc_line;
591 i2c.mask_data_reg = ddc_line;
592 i2c.a_clk_reg = ddc_line;
593 i2c.a_data_reg = ddc_line;
Alex Deucher9b9fe722009-11-10 15:59:44 -0500594 i2c.en_clk_reg = ddc_line;
595 i2c.en_data_reg = ddc_line;
596 i2c.y_clk_reg = ddc_line;
597 i2c.y_data_reg = ddc_line;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200598 }
599
Alex Deucher179e8072010-08-05 21:21:17 -0400600 if (clk_mask && data_mask) {
Alex Deucherbe663052010-11-18 17:18:08 -0500601 /* system specific masks */
Alex Deucher179e8072010-08-05 21:21:17 -0400602 i2c.mask_clk_mask = clk_mask;
603 i2c.mask_data_mask = data_mask;
604 i2c.a_clk_mask = clk_mask;
605 i2c.a_data_mask = data_mask;
606 i2c.en_clk_mask = clk_mask;
607 i2c.en_data_mask = data_mask;
608 i2c.y_clk_mask = clk_mask;
609 i2c.y_data_mask = data_mask;
Alex Deucherbe663052010-11-18 17:18:08 -0500610 } else if ((ddc_line == RADEON_GPIOPAD_MASK) ||
611 (ddc_line == RADEON_MDGPIO_MASK)) {
612 /* default gpiopad masks */
613 i2c.mask_clk_mask = (0x20 << 8);
614 i2c.mask_data_mask = 0x80;
615 i2c.a_clk_mask = (0x20 << 8);
616 i2c.a_data_mask = 0x80;
617 i2c.en_clk_mask = (0x20 << 8);
618 i2c.en_data_mask = 0x80;
619 i2c.y_clk_mask = (0x20 << 8);
620 i2c.y_data_mask = 0x80;
Alex Deucher179e8072010-08-05 21:21:17 -0400621 } else {
Alex Deucherbe663052010-11-18 17:18:08 -0500622 /* default masks for ddc pads */
Jean Delvare286e0c92011-10-06 18:16:24 +0200623 i2c.mask_clk_mask = RADEON_GPIO_MASK_1;
624 i2c.mask_data_mask = RADEON_GPIO_MASK_0;
Alex Deucher179e8072010-08-05 21:21:17 -0400625 i2c.a_clk_mask = RADEON_GPIO_A_1;
626 i2c.a_data_mask = RADEON_GPIO_A_0;
627 i2c.en_clk_mask = RADEON_GPIO_EN_1;
628 i2c.en_data_mask = RADEON_GPIO_EN_0;
629 i2c.y_clk_mask = RADEON_GPIO_Y_1;
630 i2c.y_data_mask = RADEON_GPIO_Y_0;
631 }
632
Alex Deucher40bacf12009-12-23 03:23:21 -0500633 switch (rdev->family) {
634 case CHIP_R100:
635 case CHIP_RV100:
636 case CHIP_RS100:
637 case CHIP_RV200:
638 case CHIP_RS200:
639 case CHIP_RS300:
640 switch (ddc_line) {
641 case RADEON_GPIO_DVI_DDC:
Alex Deucherb28ea412010-03-12 13:30:49 -0500642 i2c.hw_capable = true;
Alex Deucher40bacf12009-12-23 03:23:21 -0500643 break;
644 default:
645 i2c.hw_capable = false;
646 break;
647 }
648 break;
649 case CHIP_R200:
650 switch (ddc_line) {
651 case RADEON_GPIO_DVI_DDC:
652 case RADEON_GPIO_MONID:
653 i2c.hw_capable = true;
654 break;
655 default:
656 i2c.hw_capable = false;
657 break;
658 }
659 break;
660 case CHIP_RV250:
661 case CHIP_RV280:
662 switch (ddc_line) {
663 case RADEON_GPIO_VGA_DDC:
664 case RADEON_GPIO_DVI_DDC:
665 case RADEON_GPIO_CRT2_DDC:
666 i2c.hw_capable = true;
667 break;
668 default:
669 i2c.hw_capable = false;
670 break;
671 }
672 break;
673 case CHIP_R300:
674 case CHIP_R350:
675 switch (ddc_line) {
676 case RADEON_GPIO_VGA_DDC:
677 case RADEON_GPIO_DVI_DDC:
678 i2c.hw_capable = true;
679 break;
680 default:
681 i2c.hw_capable = false;
682 break;
683 }
684 break;
685 case CHIP_RV350:
686 case CHIP_RV380:
687 case CHIP_RS400:
688 case CHIP_RS480:
Alex Deucher6a93cb22009-11-23 17:39:28 -0500689 switch (ddc_line) {
690 case RADEON_GPIO_VGA_DDC:
691 case RADEON_GPIO_DVI_DDC:
692 i2c.hw_capable = true;
693 break;
694 case RADEON_GPIO_MONID:
695 /* hw i2c on RADEON_GPIO_MONID doesn't seem to work
696 * reliably on some pre-r4xx hardware; not sure why.
697 */
698 i2c.hw_capable = false;
699 break;
700 default:
701 i2c.hw_capable = false;
702 break;
703 }
Alex Deucher40bacf12009-12-23 03:23:21 -0500704 break;
705 default:
706 i2c.hw_capable = false;
707 break;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500708 }
709 i2c.mm_i2c = false;
Alex Deucherf376b942010-08-05 21:21:16 -0400710
Alex Deucher179e8072010-08-05 21:21:17 -0400711 i2c.i2c_id = ddc;
Alex Deucher8e36ed02010-05-18 19:26:47 -0400712 i2c.hpd = RADEON_HPD_NONE;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500713
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200714 if (ddc_line)
715 i2c.valid = true;
716 else
717 i2c.valid = false;
718
719 return i2c;
720}
721
Alex Deucher3d61bd42012-07-19 20:11:44 -0400722static struct radeon_i2c_bus_rec radeon_combios_get_i2c_info_from_table(struct radeon_device *rdev)
723{
724 struct drm_device *dev = rdev->ddev;
725 struct radeon_i2c_bus_rec i2c;
726 u16 offset;
727 u8 id, blocks, clk, data;
728 int i;
729
730 i2c.valid = false;
731
732 offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE);
733 if (offset) {
734 blocks = RBIOS8(offset + 2);
735 for (i = 0; i < blocks; i++) {
736 id = RBIOS8(offset + 3 + (i * 5) + 0);
737 if (id == 136) {
738 clk = RBIOS8(offset + 3 + (i * 5) + 3);
739 data = RBIOS8(offset + 3 + (i * 5) + 4);
740 /* gpiopad */
741 i2c = combios_setup_i2c_bus(rdev, DDC_MONID,
742 (1 << clk), (1 << data));
743 break;
744 }
745 }
746 }
747 return i2c;
748}
749
Alex Deucherf376b942010-08-05 21:21:16 -0400750void radeon_combios_i2c_init(struct radeon_device *rdev)
751{
752 struct drm_device *dev = rdev->ddev;
753 struct radeon_i2c_bus_rec i2c;
754
Alex Deucher508c8d62011-05-03 19:47:44 -0400755 /* actual hw pads
756 * r1xx/rs2xx/rs3xx
757 * 0x60, 0x64, 0x68, 0x6c, gpiopads, mm
758 * r200
759 * 0x60, 0x64, 0x68, mm
760 * r300/r350
761 * 0x60, 0x64, mm
762 * rv2xx/rv3xx/rs4xx
763 * 0x60, 0x64, 0x68, gpiopads, mm
764 */
Alex Deucherf376b942010-08-05 21:21:16 -0400765
Alex Deucher508c8d62011-05-03 19:47:44 -0400766 /* 0x60 */
Alex Deucher179e8072010-08-05 21:21:17 -0400767 i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
768 rdev->i2c_bus[0] = radeon_i2c_create(dev, &i2c, "DVI_DDC");
Alex Deucher508c8d62011-05-03 19:47:44 -0400769 /* 0x64 */
Alex Deucher179e8072010-08-05 21:21:17 -0400770 i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
771 rdev->i2c_bus[1] = radeon_i2c_create(dev, &i2c, "VGA_DDC");
Alex Deucherf376b942010-08-05 21:21:16 -0400772
Alex Deucher508c8d62011-05-03 19:47:44 -0400773 /* mm i2c */
Alex Deucherf376b942010-08-05 21:21:16 -0400774 i2c.valid = true;
775 i2c.hw_capable = true;
776 i2c.mm_i2c = true;
Alex Deucher179e8072010-08-05 21:21:17 -0400777 i2c.i2c_id = 0xa0;
778 rdev->i2c_bus[2] = radeon_i2c_create(dev, &i2c, "MM_I2C");
779
Alex Deucher508c8d62011-05-03 19:47:44 -0400780 if (rdev->family == CHIP_R300 ||
781 rdev->family == CHIP_R350) {
782 /* only 2 sw i2c pads */
783 } else if (rdev->family == CHIP_RS300 ||
784 rdev->family == CHIP_RS400 ||
785 rdev->family == CHIP_RS480) {
Alex Deucher508c8d62011-05-03 19:47:44 -0400786 /* 0x68 */
Alex Deucher179e8072010-08-05 21:21:17 -0400787 i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
788 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
789
Alex Deucher3d61bd42012-07-19 20:11:44 -0400790 /* gpiopad */
791 i2c = radeon_combios_get_i2c_info_from_table(rdev);
792 if (i2c.valid)
793 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "GPIOPAD_MASK");
Alex Deucher6dd66632011-07-23 18:02:04 +0000794 } else if ((rdev->family == CHIP_R200) ||
795 (rdev->family >= CHIP_R300)) {
Alex Deucher508c8d62011-05-03 19:47:44 -0400796 /* 0x68 */
Alex Deucher179e8072010-08-05 21:21:17 -0400797 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
798 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
799 } else {
Alex Deucher508c8d62011-05-03 19:47:44 -0400800 /* 0x68 */
Alex Deucher179e8072010-08-05 21:21:17 -0400801 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
802 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
Alex Deucher508c8d62011-05-03 19:47:44 -0400803 /* 0x6c */
Alex Deucher179e8072010-08-05 21:21:17 -0400804 i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
805 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "CRT2_DDC");
806 }
Alex Deucherf376b942010-08-05 21:21:16 -0400807}
808
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200809bool radeon_combios_get_clock_info(struct drm_device *dev)
810{
811 struct radeon_device *rdev = dev->dev_private;
812 uint16_t pll_info;
813 struct radeon_pll *p1pll = &rdev->clock.p1pll;
814 struct radeon_pll *p2pll = &rdev->clock.p2pll;
815 struct radeon_pll *spll = &rdev->clock.spll;
816 struct radeon_pll *mpll = &rdev->clock.mpll;
817 int8_t rev;
818 uint16_t sclk, mclk;
819
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200820 pll_info = combios_get_table_offset(dev, COMBIOS_PLL_INFO_TABLE);
821 if (pll_info) {
822 rev = RBIOS8(pll_info);
823
824 /* pixel clocks */
825 p1pll->reference_freq = RBIOS16(pll_info + 0xe);
826 p1pll->reference_div = RBIOS16(pll_info + 0x10);
827 p1pll->pll_out_min = RBIOS32(pll_info + 0x12);
828 p1pll->pll_out_max = RBIOS32(pll_info + 0x16);
Alex Deucher86cb2bb2010-03-08 12:55:16 -0500829 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
830 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200831
832 if (rev > 9) {
833 p1pll->pll_in_min = RBIOS32(pll_info + 0x36);
834 p1pll->pll_in_max = RBIOS32(pll_info + 0x3a);
835 } else {
836 p1pll->pll_in_min = 40;
837 p1pll->pll_in_max = 500;
838 }
839 *p2pll = *p1pll;
840
841 /* system clock */
842 spll->reference_freq = RBIOS16(pll_info + 0x1a);
843 spll->reference_div = RBIOS16(pll_info + 0x1c);
844 spll->pll_out_min = RBIOS32(pll_info + 0x1e);
845 spll->pll_out_max = RBIOS32(pll_info + 0x22);
846
847 if (rev > 10) {
848 spll->pll_in_min = RBIOS32(pll_info + 0x48);
849 spll->pll_in_max = RBIOS32(pll_info + 0x4c);
850 } else {
851 /* ??? */
852 spll->pll_in_min = 40;
853 spll->pll_in_max = 500;
854 }
855
856 /* memory clock */
857 mpll->reference_freq = RBIOS16(pll_info + 0x26);
858 mpll->reference_div = RBIOS16(pll_info + 0x28);
859 mpll->pll_out_min = RBIOS32(pll_info + 0x2a);
860 mpll->pll_out_max = RBIOS32(pll_info + 0x2e);
861
862 if (rev > 10) {
863 mpll->pll_in_min = RBIOS32(pll_info + 0x5a);
864 mpll->pll_in_max = RBIOS32(pll_info + 0x5e);
865 } else {
866 /* ??? */
867 mpll->pll_in_min = 40;
868 mpll->pll_in_max = 500;
869 }
870
871 /* default sclk/mclk */
872 sclk = RBIOS16(pll_info + 0xa);
873 mclk = RBIOS16(pll_info + 0x8);
874 if (sclk == 0)
875 sclk = 200 * 100;
876 if (mclk == 0)
877 mclk = 200 * 100;
878
879 rdev->clock.default_sclk = sclk;
880 rdev->clock.default_mclk = mclk;
881
Alex Deucherb20f9be2011-06-08 13:01:11 -0400882 if (RBIOS32(pll_info + 0x16))
883 rdev->clock.max_pixel_clock = RBIOS32(pll_info + 0x16);
884 else
885 rdev->clock.max_pixel_clock = 35000; /* might need something asic specific */
886
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200887 return true;
888 }
889 return false;
890}
891
Alex Deucher06b64762010-01-05 11:27:29 -0500892bool radeon_combios_sideport_present(struct radeon_device *rdev)
893{
894 struct drm_device *dev = rdev->ddev;
895 u16 igp_info;
896
Alex Deucher4c70b2e2010-08-02 19:39:15 -0400897 /* sideport is AMD only */
898 if (rdev->family == CHIP_RS400)
899 return false;
900
Alex Deucher06b64762010-01-05 11:27:29 -0500901 igp_info = combios_get_table_offset(dev, COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE);
902
903 if (igp_info) {
904 if (RBIOS16(igp_info + 0x4))
905 return true;
906 }
907 return false;
908}
909
Alex Deucher246263c2009-12-29 12:09:17 -0500910static const uint32_t default_primarydac_adj[CHIP_LAST] = {
911 0x00000808, /* r100 */
912 0x00000808, /* rv100 */
913 0x00000808, /* rs100 */
914 0x00000808, /* rv200 */
915 0x00000808, /* rs200 */
916 0x00000808, /* r200 */
917 0x00000808, /* rv250 */
918 0x00000000, /* rs300 */
919 0x00000808, /* rv280 */
920 0x00000808, /* r300 */
921 0x00000808, /* r350 */
922 0x00000808, /* rv350 */
923 0x00000808, /* rv380 */
924 0x00000808, /* r420 */
925 0x00000808, /* r423 */
926 0x00000808, /* rv410 */
927 0x00000000, /* rs400 */
928 0x00000000, /* rs480 */
929};
930
931static void radeon_legacy_get_primary_dac_info_from_table(struct radeon_device *rdev,
932 struct radeon_encoder_primary_dac *p_dac)
933{
934 p_dac->ps2_pdac_adj = default_primarydac_adj[rdev->family];
935 return;
936}
937
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200938struct radeon_encoder_primary_dac *radeon_combios_get_primary_dac_info(struct
939 radeon_encoder
940 *encoder)
941{
942 struct drm_device *dev = encoder->base.dev;
943 struct radeon_device *rdev = dev->dev_private;
944 uint16_t dac_info;
945 uint8_t rev, bg, dac;
946 struct radeon_encoder_primary_dac *p_dac = NULL;
Alex Deucher246263c2009-12-29 12:09:17 -0500947 int found = 0;
948
949 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac),
950 GFP_KERNEL);
951
952 if (!p_dac)
953 return NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200954
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200955 /* check CRT table */
956 dac_info = combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
957 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200958 rev = RBIOS8(dac_info) & 0x3;
959 if (rev < 2) {
960 bg = RBIOS8(dac_info + 0x2) & 0xf;
961 dac = (RBIOS8(dac_info + 0x2) >> 4) & 0xf;
962 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
963 } else {
964 bg = RBIOS8(dac_info + 0x2) & 0xf;
965 dac = RBIOS8(dac_info + 0x3) & 0xf;
966 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
967 }
Alex Deucher3a89b4a2010-04-06 12:35:26 -0400968 /* if the values are all zeros, use the table */
969 if (p_dac->ps2_pdac_adj)
970 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200971 }
972
Alex Deuchere8fc4132013-02-27 12:01:58 -0500973 /* quirks */
Ondrej Zaryf7929f32013-07-19 21:08:48 +0200974 /* Radeon 7000 (RV100) */
975 if (((dev->pdev->device == 0x5159) &&
Alex Deuchere8fc4132013-02-27 12:01:58 -0500976 (dev->pdev->subsystem_vendor == 0x174B) &&
Ondrej Zaryf7929f32013-07-19 21:08:48 +0200977 (dev->pdev->subsystem_device == 0x7c28)) ||
978 /* Radeon 9100 (R200) */
979 ((dev->pdev->device == 0x514D) &&
980 (dev->pdev->subsystem_vendor == 0x174B) &&
981 (dev->pdev->subsystem_device == 0x7149))) {
Alex Deuchere8fc4132013-02-27 12:01:58 -0500982 /* vbios value is bad, use the default */
983 found = 0;
984 }
985
Alex Deucher246263c2009-12-29 12:09:17 -0500986 if (!found) /* fallback to defaults */
987 radeon_legacy_get_primary_dac_info_from_table(rdev, p_dac);
988
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200989 return p_dac;
990}
991
Alex Deucherd79766f2009-12-17 19:00:29 -0500992enum radeon_tv_std
993radeon_combios_get_tv_info(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200994{
Alex Deucherd79766f2009-12-17 19:00:29 -0500995 struct drm_device *dev = rdev->ddev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200996 uint16_t tv_info;
997 enum radeon_tv_std tv_std = TV_STD_NTSC;
998
999 tv_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
1000 if (tv_info) {
1001 if (RBIOS8(tv_info + 6) == 'T') {
1002 switch (RBIOS8(tv_info + 7) & 0xf) {
1003 case 1:
1004 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001005 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001006 break;
1007 case 2:
1008 tv_std = TV_STD_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -04001009 DRM_DEBUG_KMS("Default TV standard: PAL\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001010 break;
1011 case 3:
1012 tv_std = TV_STD_PAL_M;
Alex Deucher40f76d82010-10-07 22:38:42 -04001013 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001014 break;
1015 case 4:
1016 tv_std = TV_STD_PAL_60;
Alex Deucher40f76d82010-10-07 22:38:42 -04001017 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001018 break;
1019 case 5:
1020 tv_std = TV_STD_NTSC_J;
Alex Deucher40f76d82010-10-07 22:38:42 -04001021 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001022 break;
1023 case 6:
1024 tv_std = TV_STD_SCART_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -04001025 DRM_DEBUG_KMS("Default TV standard: SCART-PAL\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001026 break;
1027 default:
1028 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001029 DRM_DEBUG_KMS
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001030 ("Unknown TV standard; defaulting to NTSC\n");
1031 break;
1032 }
1033
1034 switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) {
1035 case 0:
Alex Deucher40f76d82010-10-07 22:38:42 -04001036 DRM_DEBUG_KMS("29.498928713 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001037 break;
1038 case 1:
Alex Deucher40f76d82010-10-07 22:38:42 -04001039 DRM_DEBUG_KMS("28.636360000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001040 break;
1041 case 2:
Alex Deucher40f76d82010-10-07 22:38:42 -04001042 DRM_DEBUG_KMS("14.318180000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001043 break;
1044 case 3:
Alex Deucher40f76d82010-10-07 22:38:42 -04001045 DRM_DEBUG_KMS("27.000000000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001046 break;
1047 default:
1048 break;
1049 }
1050 }
1051 }
1052 return tv_std;
1053}
1054
1055static const uint32_t default_tvdac_adj[CHIP_LAST] = {
1056 0x00000000, /* r100 */
1057 0x00280000, /* rv100 */
1058 0x00000000, /* rs100 */
1059 0x00880000, /* rv200 */
1060 0x00000000, /* rs200 */
1061 0x00000000, /* r200 */
1062 0x00770000, /* rv250 */
1063 0x00290000, /* rs300 */
1064 0x00560000, /* rv280 */
1065 0x00780000, /* r300 */
1066 0x00770000, /* r350 */
1067 0x00780000, /* rv350 */
1068 0x00780000, /* rv380 */
1069 0x01080000, /* r420 */
1070 0x01080000, /* r423 */
1071 0x01080000, /* rv410 */
1072 0x00780000, /* rs400 */
1073 0x00780000, /* rs480 */
1074};
1075
Dave Airlie6a719e02009-08-17 10:19:51 +10001076static void radeon_legacy_get_tv_dac_info_from_table(struct radeon_device *rdev,
1077 struct radeon_encoder_tv_dac *tv_dac)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001078{
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001079 tv_dac->ps2_tvdac_adj = default_tvdac_adj[rdev->family];
1080 if ((rdev->flags & RADEON_IS_MOBILITY) && (rdev->family == CHIP_RV250))
1081 tv_dac->ps2_tvdac_adj = 0x00880000;
1082 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1083 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Dave Airlie6a719e02009-08-17 10:19:51 +10001084 return;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001085}
1086
1087struct radeon_encoder_tv_dac *radeon_combios_get_tv_dac_info(struct
1088 radeon_encoder
1089 *encoder)
1090{
1091 struct drm_device *dev = encoder->base.dev;
1092 struct radeon_device *rdev = dev->dev_private;
1093 uint16_t dac_info;
1094 uint8_t rev, bg, dac;
1095 struct radeon_encoder_tv_dac *tv_dac = NULL;
Dave Airlie6a719e02009-08-17 10:19:51 +10001096 int found = 0;
1097
1098 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1099 if (!tv_dac)
1100 return NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001101
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001102 /* first check TV table */
1103 dac_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
1104 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001105 rev = RBIOS8(dac_info + 0x3);
1106 if (rev > 4) {
1107 bg = RBIOS8(dac_info + 0xc) & 0xf;
1108 dac = RBIOS8(dac_info + 0xd) & 0xf;
1109 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1110
1111 bg = RBIOS8(dac_info + 0xe) & 0xf;
1112 dac = RBIOS8(dac_info + 0xf) & 0xf;
1113 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1114
1115 bg = RBIOS8(dac_info + 0x10) & 0xf;
1116 dac = RBIOS8(dac_info + 0x11) & 0xf;
1117 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001118 /* if the values are all zeros, use the table */
1119 if (tv_dac->ps2_tvdac_adj)
1120 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001121 } else if (rev > 1) {
1122 bg = RBIOS8(dac_info + 0xc) & 0xf;
1123 dac = (RBIOS8(dac_info + 0xc) >> 4) & 0xf;
1124 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1125
1126 bg = RBIOS8(dac_info + 0xd) & 0xf;
1127 dac = (RBIOS8(dac_info + 0xd) >> 4) & 0xf;
1128 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1129
1130 bg = RBIOS8(dac_info + 0xe) & 0xf;
1131 dac = (RBIOS8(dac_info + 0xe) >> 4) & 0xf;
1132 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001133 /* if the values are all zeros, use the table */
1134 if (tv_dac->ps2_tvdac_adj)
1135 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001136 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001137 tv_dac->tv_std = radeon_combios_get_tv_info(rdev);
Dave Airlie6a719e02009-08-17 10:19:51 +10001138 }
1139 if (!found) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001140 /* then check CRT table */
1141 dac_info =
1142 combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
1143 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001144 rev = RBIOS8(dac_info) & 0x3;
1145 if (rev < 2) {
1146 bg = RBIOS8(dac_info + 0x3) & 0xf;
1147 dac = (RBIOS8(dac_info + 0x3) >> 4) & 0xf;
1148 tv_dac->ps2_tvdac_adj =
1149 (bg << 16) | (dac << 20);
1150 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1151 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001152 /* if the values are all zeros, use the table */
1153 if (tv_dac->ps2_tvdac_adj)
1154 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001155 } else {
1156 bg = RBIOS8(dac_info + 0x4) & 0xf;
1157 dac = RBIOS8(dac_info + 0x5) & 0xf;
1158 tv_dac->ps2_tvdac_adj =
1159 (bg << 16) | (dac << 20);
1160 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1161 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001162 /* if the values are all zeros, use the table */
1163 if (tv_dac->ps2_tvdac_adj)
1164 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001165 }
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001166 } else {
1167 DRM_INFO("No TV DAC info found in BIOS\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001168 }
1169 }
1170
Dave Airlie6a719e02009-08-17 10:19:51 +10001171 if (!found) /* fallback to defaults */
1172 radeon_legacy_get_tv_dac_info_from_table(rdev, tv_dac);
1173
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001174 return tv_dac;
1175}
1176
1177static struct radeon_encoder_lvds *radeon_legacy_get_lvds_info_from_regs(struct
1178 radeon_device
1179 *rdev)
1180{
1181 struct radeon_encoder_lvds *lvds = NULL;
1182 uint32_t fp_vert_stretch, fp_horz_stretch;
1183 uint32_t ppll_div_sel, ppll_val;
Michel Dänzer8b5c7442009-06-17 18:28:38 +02001184 uint32_t lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001185
1186 lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
1187
1188 if (!lvds)
1189 return NULL;
1190
1191 fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH);
1192 fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH);
1193
Michel Dänzer8b5c7442009-06-17 18:28:38 +02001194 /* These should be fail-safe defaults, fingers crossed */
1195 lvds->panel_pwr_delay = 200;
1196 lvds->panel_vcc_delay = 2000;
1197
1198 lvds->lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
1199 lvds->panel_digon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) & 0xf;
1200 lvds->panel_blon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY2_SHIFT) & 0xf;
1201
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001202 if (fp_vert_stretch & RADEON_VERT_STRETCH_ENABLE)
Alex Deucherde2103e2009-10-09 15:14:30 -04001203 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001204 ((fp_vert_stretch & RADEON_VERT_PANEL_SIZE) >>
1205 RADEON_VERT_PANEL_SHIFT) + 1;
1206 else
Alex Deucherde2103e2009-10-09 15:14:30 -04001207 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001208 (RREG32(RADEON_CRTC_V_TOTAL_DISP) >> 16) + 1;
1209
1210 if (fp_horz_stretch & RADEON_HORZ_STRETCH_ENABLE)
Alex Deucherde2103e2009-10-09 15:14:30 -04001211 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001212 (((fp_horz_stretch & RADEON_HORZ_PANEL_SIZE) >>
1213 RADEON_HORZ_PANEL_SHIFT) + 1) * 8;
1214 else
Alex Deucherde2103e2009-10-09 15:14:30 -04001215 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001216 ((RREG32(RADEON_CRTC_H_TOTAL_DISP) >> 16) + 1) * 8;
1217
Alex Deucherde2103e2009-10-09 15:14:30 -04001218 if ((lvds->native_mode.hdisplay < 640) ||
1219 (lvds->native_mode.vdisplay < 480)) {
1220 lvds->native_mode.hdisplay = 640;
1221 lvds->native_mode.vdisplay = 480;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001222 }
1223
1224 ppll_div_sel = RREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3;
1225 ppll_val = RREG32_PLL(RADEON_PPLL_DIV_0 + ppll_div_sel);
1226 if ((ppll_val & 0x000707ff) == 0x1bb)
1227 lvds->use_bios_dividers = false;
1228 else {
1229 lvds->panel_ref_divider =
1230 RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
1231 lvds->panel_post_divider = (ppll_val >> 16) & 0x7;
1232 lvds->panel_fb_divider = ppll_val & 0x7ff;
1233
1234 if ((lvds->panel_ref_divider != 0) &&
1235 (lvds->panel_fb_divider > 3))
1236 lvds->use_bios_dividers = true;
1237 }
1238 lvds->panel_vcc_delay = 200;
1239
1240 DRM_INFO("Panel info derived from registers\n");
Alex Deucherde2103e2009-10-09 15:14:30 -04001241 DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
1242 lvds->native_mode.vdisplay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001243
1244 return lvds;
1245}
1246
1247struct radeon_encoder_lvds *radeon_combios_get_lvds_info(struct radeon_encoder
1248 *encoder)
1249{
1250 struct drm_device *dev = encoder->base.dev;
1251 struct radeon_device *rdev = dev->dev_private;
1252 uint16_t lcd_info;
1253 uint32_t panel_setup;
1254 char stmp[30];
1255 int tmp, i;
1256 struct radeon_encoder_lvds *lvds = NULL;
1257
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001258 lcd_info = combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
1259
1260 if (lcd_info) {
1261 lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
1262
1263 if (!lvds)
1264 return NULL;
1265
1266 for (i = 0; i < 24; i++)
1267 stmp[i] = RBIOS8(lcd_info + i + 1);
1268 stmp[24] = 0;
1269
1270 DRM_INFO("Panel ID String: %s\n", stmp);
1271
Alex Deucherde2103e2009-10-09 15:14:30 -04001272 lvds->native_mode.hdisplay = RBIOS16(lcd_info + 0x19);
1273 lvds->native_mode.vdisplay = RBIOS16(lcd_info + 0x1b);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001274
Alex Deucherde2103e2009-10-09 15:14:30 -04001275 DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
1276 lvds->native_mode.vdisplay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001277
1278 lvds->panel_vcc_delay = RBIOS16(lcd_info + 0x2c);
Andrew Morton94cf6432010-02-02 14:40:29 -08001279 lvds->panel_vcc_delay = min_t(u16, lvds->panel_vcc_delay, 2000);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001280
1281 lvds->panel_pwr_delay = RBIOS8(lcd_info + 0x24);
1282 lvds->panel_digon_delay = RBIOS16(lcd_info + 0x38) & 0xf;
1283 lvds->panel_blon_delay = (RBIOS16(lcd_info + 0x38) >> 4) & 0xf;
1284
1285 lvds->panel_ref_divider = RBIOS16(lcd_info + 0x2e);
1286 lvds->panel_post_divider = RBIOS8(lcd_info + 0x30);
1287 lvds->panel_fb_divider = RBIOS16(lcd_info + 0x31);
1288 if ((lvds->panel_ref_divider != 0) &&
1289 (lvds->panel_fb_divider > 3))
1290 lvds->use_bios_dividers = true;
1291
1292 panel_setup = RBIOS32(lcd_info + 0x39);
1293 lvds->lvds_gen_cntl = 0xff00;
1294 if (panel_setup & 0x1)
1295 lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_FORMAT;
1296
1297 if ((panel_setup >> 4) & 0x1)
1298 lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_TYPE;
1299
1300 switch ((panel_setup >> 8) & 0x7) {
1301 case 0:
1302 lvds->lvds_gen_cntl |= RADEON_LVDS_NO_FM;
1303 break;
1304 case 1:
1305 lvds->lvds_gen_cntl |= RADEON_LVDS_2_GREY;
1306 break;
1307 case 2:
1308 lvds->lvds_gen_cntl |= RADEON_LVDS_4_GREY;
1309 break;
1310 default:
1311 break;
1312 }
1313
1314 if ((panel_setup >> 16) & 0x1)
1315 lvds->lvds_gen_cntl |= RADEON_LVDS_FP_POL_LOW;
1316
1317 if ((panel_setup >> 17) & 0x1)
1318 lvds->lvds_gen_cntl |= RADEON_LVDS_LP_POL_LOW;
1319
1320 if ((panel_setup >> 18) & 0x1)
1321 lvds->lvds_gen_cntl |= RADEON_LVDS_DTM_POL_LOW;
1322
1323 if ((panel_setup >> 23) & 0x1)
1324 lvds->lvds_gen_cntl |= RADEON_LVDS_BL_CLK_SEL;
1325
1326 lvds->lvds_gen_cntl |= (panel_setup & 0xf0000000);
1327
1328 for (i = 0; i < 32; i++) {
1329 tmp = RBIOS16(lcd_info + 64 + i * 2);
1330 if (tmp == 0)
1331 break;
1332
Alex Deucherde2103e2009-10-09 15:14:30 -04001333 if ((RBIOS16(tmp) == lvds->native_mode.hdisplay) &&
Alex Deucher68b61a72010-05-18 00:30:05 -04001334 (RBIOS16(tmp + 2) == lvds->native_mode.vdisplay)) {
1335 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1336 (RBIOS16(tmp + 17) - RBIOS16(tmp + 19)) * 8;
1337 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1338 (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) - 1) * 8;
1339 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1340 (RBIOS8(tmp + 23) * 8);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001341
Alex Deucher68b61a72010-05-18 00:30:05 -04001342 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1343 (RBIOS16(tmp + 24) - RBIOS16(tmp + 26));
1344 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1345 ((RBIOS16(tmp + 28) & 0x7ff) - RBIOS16(tmp + 26));
1346 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1347 ((RBIOS16(tmp + 28) & 0xf800) >> 11);
Alex Deucherde2103e2009-10-09 15:14:30 -04001348
1349 lvds->native_mode.clock = RBIOS16(tmp + 9) * 10;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001350 lvds->native_mode.flags = 0;
Alex Deucherde2103e2009-10-09 15:14:30 -04001351 /* set crtc values */
1352 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
1353
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001354 }
1355 }
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001356 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001357 DRM_INFO("No panel info found in BIOS\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +02001358 lvds = radeon_legacy_get_lvds_info_from_regs(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001359 }
Michel Dänzer03047cd2010-02-10 11:05:11 +01001360
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +02001361 if (lvds)
1362 encoder->native_mode = lvds->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001363 return lvds;
1364}
1365
1366static const struct radeon_tmds_pll default_tmds_pll[CHIP_LAST][4] = {
1367 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R100 */
1368 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV100 */
1369 {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS100 */
1370 {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV200 */
1371 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RS200 */
1372 {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R200 */
1373 {{15500, 0x81b}, {0xffffffff, 0x83f}, {0, 0}, {0, 0}}, /* CHIP_RV250 */
1374 {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS300 */
1375 {{13000, 0x400f4}, {15000, 0x400f7}, {0xffffffff, 0x40111}, {0, 0}}, /* CHIP_RV280 */
1376 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R300 */
1377 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R350 */
1378 {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV350 */
1379 {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV380 */
1380 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R420 */
1381 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R423 */
1382 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RV410 */
Alex Deucherfcec5702009-11-10 21:25:07 -05001383 { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS400 */
1384 { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS480 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001385};
1386
Dave Airlie445282d2009-09-09 17:40:54 +10001387bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
1388 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001389{
Dave Airlie445282d2009-09-09 17:40:54 +10001390 struct drm_device *dev = encoder->base.dev;
1391 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001392 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001393
1394 for (i = 0; i < 4; i++) {
1395 tmds->tmds_pll[i].value =
Dave Airlie445282d2009-09-09 17:40:54 +10001396 default_tmds_pll[rdev->family][i].value;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001397 tmds->tmds_pll[i].freq = default_tmds_pll[rdev->family][i].freq;
1398 }
1399
Dave Airlie445282d2009-09-09 17:40:54 +10001400 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001401}
1402
Dave Airlie445282d2009-09-09 17:40:54 +10001403bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
1404 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001405{
1406 struct drm_device *dev = encoder->base.dev;
1407 struct radeon_device *rdev = dev->dev_private;
1408 uint16_t tmds_info;
1409 int i, n;
1410 uint8_t ver;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001411
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001412 tmds_info = combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
1413
1414 if (tmds_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001415 ver = RBIOS8(tmds_info);
Alex Deucher40f76d82010-10-07 22:38:42 -04001416 DRM_DEBUG_KMS("DFP table revision: %d\n", ver);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001417 if (ver == 3) {
1418 n = RBIOS8(tmds_info + 5) + 1;
1419 if (n > 4)
1420 n = 4;
1421 for (i = 0; i < n; i++) {
1422 tmds->tmds_pll[i].value =
1423 RBIOS32(tmds_info + i * 10 + 0x08);
1424 tmds->tmds_pll[i].freq =
1425 RBIOS16(tmds_info + i * 10 + 0x10);
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001426 DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001427 tmds->tmds_pll[i].freq,
1428 tmds->tmds_pll[i].value);
1429 }
1430 } else if (ver == 4) {
1431 int stride = 0;
1432 n = RBIOS8(tmds_info + 5) + 1;
1433 if (n > 4)
1434 n = 4;
1435 for (i = 0; i < n; i++) {
1436 tmds->tmds_pll[i].value =
1437 RBIOS32(tmds_info + stride + 0x08);
1438 tmds->tmds_pll[i].freq =
1439 RBIOS16(tmds_info + stride + 0x10);
1440 if (i == 0)
1441 stride += 10;
1442 else
1443 stride += 6;
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001444 DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001445 tmds->tmds_pll[i].freq,
1446 tmds->tmds_pll[i].value);
1447 }
1448 }
Alex Deucherfcec5702009-11-10 21:25:07 -05001449 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001450 DRM_INFO("No TMDS info found in BIOS\n");
Alex Deucherfcec5702009-11-10 21:25:07 -05001451 return false;
1452 }
Dave Airlie445282d2009-09-09 17:40:54 +10001453 return true;
1454}
1455
Alex Deucherfcec5702009-11-10 21:25:07 -05001456bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
1457 struct radeon_encoder_ext_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001458{
1459 struct drm_device *dev = encoder->base.dev;
1460 struct radeon_device *rdev = dev->dev_private;
Alex Deucherfcec5702009-11-10 21:25:07 -05001461 struct radeon_i2c_bus_rec i2c_bus;
1462
1463 /* default for macs */
Alex Deucher179e8072010-08-05 21:21:17 -04001464 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
Alex Deucherf376b942010-08-05 21:21:16 -04001465 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucherfcec5702009-11-10 21:25:07 -05001466
1467 /* XXX some macs have duallink chips */
1468 switch (rdev->mode_info.connector_table) {
1469 case CT_POWERBOOK_EXTERNAL:
1470 case CT_MINI_EXTERNAL:
1471 default:
1472 tmds->dvo_chip = DVO_SIL164;
1473 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1474 break;
1475 }
1476
1477 return true;
1478}
1479
1480bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
1481 struct radeon_encoder_ext_tmds *tmds)
1482{
1483 struct drm_device *dev = encoder->base.dev;
1484 struct radeon_device *rdev = dev->dev_private;
1485 uint16_t offset;
Alex Deucher179e8072010-08-05 21:21:17 -04001486 uint8_t ver;
Alex Deucherfcec5702009-11-10 21:25:07 -05001487 enum radeon_combios_ddc gpio;
1488 struct radeon_i2c_bus_rec i2c_bus;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001489
Alex Deucherfcec5702009-11-10 21:25:07 -05001490 tmds->i2c_bus = NULL;
1491 if (rdev->flags & RADEON_IS_IGP) {
Alex Deucher179e8072010-08-05 21:21:17 -04001492 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1493 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1494 tmds->dvo_chip = DVO_SIL164;
1495 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
Alex Deucherfcec5702009-11-10 21:25:07 -05001496 } else {
1497 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
1498 if (offset) {
1499 ver = RBIOS8(offset);
Alex Deucher40f76d82010-10-07 22:38:42 -04001500 DRM_DEBUG_KMS("External TMDS Table revision: %d\n", ver);
Alex Deucherfcec5702009-11-10 21:25:07 -05001501 tmds->slave_addr = RBIOS8(offset + 4 + 2);
1502 tmds->slave_addr >>= 1; /* 7 bit addressing */
1503 gpio = RBIOS8(offset + 4 + 3);
Alex Deucher179e8072010-08-05 21:21:17 -04001504 if (gpio == DDC_LCD) {
1505 /* MM i2c */
Alex Deucher40bacf12009-12-23 03:23:21 -05001506 i2c_bus.valid = true;
1507 i2c_bus.hw_capable = true;
1508 i2c_bus.mm_i2c = true;
Alex Deucher179e8072010-08-05 21:21:17 -04001509 i2c_bus.i2c_id = 0xa0;
1510 } else
1511 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
1512 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucherfcec5702009-11-10 21:25:07 -05001513 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001514 }
Alex Deucherfcec5702009-11-10 21:25:07 -05001515
1516 if (!tmds->i2c_bus) {
1517 DRM_INFO("No valid Ext TMDS info found in BIOS\n");
1518 return false;
1519 }
1520
1521 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001522}
1523
1524bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1525{
1526 struct radeon_device *rdev = dev->dev_private;
1527 struct radeon_i2c_bus_rec ddc_i2c;
Alex Deuchereed45b32009-12-04 14:45:27 -05001528 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001529
1530 rdev->mode_info.connector_table = radeon_connector_table;
1531 if (rdev->mode_info.connector_table == CT_NONE) {
1532#ifdef CONFIG_PPC_PMAC
Grant Likely71a157e2010-02-01 21:34:14 -07001533 if (of_machine_is_compatible("PowerBook3,3")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001534 /* powerbook with VGA */
1535 rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
Grant Likely71a157e2010-02-01 21:34:14 -07001536 } else if (of_machine_is_compatible("PowerBook3,4") ||
1537 of_machine_is_compatible("PowerBook3,5")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001538 /* powerbook with internal tmds */
1539 rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001540 } else if (of_machine_is_compatible("PowerBook5,1") ||
1541 of_machine_is_compatible("PowerBook5,2") ||
1542 of_machine_is_compatible("PowerBook5,3") ||
1543 of_machine_is_compatible("PowerBook5,4") ||
1544 of_machine_is_compatible("PowerBook5,5")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001545 /* powerbook with external single link tmds (sil164) */
1546 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001547 } else if (of_machine_is_compatible("PowerBook5,6")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001548 /* powerbook with external dual or single link tmds */
1549 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001550 } else if (of_machine_is_compatible("PowerBook5,7") ||
1551 of_machine_is_compatible("PowerBook5,8") ||
1552 of_machine_is_compatible("PowerBook5,9")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001553 /* PowerBook6,2 ? */
1554 /* powerbook with external dual link tmds (sil1178?) */
1555 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001556 } else if (of_machine_is_compatible("PowerBook4,1") ||
1557 of_machine_is_compatible("PowerBook4,2") ||
1558 of_machine_is_compatible("PowerBook4,3") ||
1559 of_machine_is_compatible("PowerBook6,3") ||
1560 of_machine_is_compatible("PowerBook6,5") ||
1561 of_machine_is_compatible("PowerBook6,7")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001562 /* ibook */
1563 rdev->mode_info.connector_table = CT_IBOOK;
Alex Deuchercafa59b2012-12-20 16:35:47 -05001564 } else if (of_machine_is_compatible("PowerMac3,5")) {
1565 /* PowerMac G4 Silver radeon 7500 */
1566 rdev->mode_info.connector_table = CT_MAC_G4_SILVER;
Grant Likely71a157e2010-02-01 21:34:14 -07001567 } else if (of_machine_is_compatible("PowerMac4,4")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001568 /* emac */
1569 rdev->mode_info.connector_table = CT_EMAC;
Grant Likely71a157e2010-02-01 21:34:14 -07001570 } else if (of_machine_is_compatible("PowerMac10,1")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001571 /* mini with internal tmds */
1572 rdev->mode_info.connector_table = CT_MINI_INTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001573 } else if (of_machine_is_compatible("PowerMac10,2")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001574 /* mini with external tmds */
1575 rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001576 } else if (of_machine_is_compatible("PowerMac12,1")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001577 /* PowerMac8,1 ? */
1578 /* imac g5 isight */
1579 rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
Alex Deucheraa74fbb2010-09-07 14:41:30 -04001580 } else if ((rdev->pdev->device == 0x4a48) &&
1581 (rdev->pdev->subsystem_vendor == 0x1002) &&
1582 (rdev->pdev->subsystem_device == 0x4a48)) {
1583 /* Mac X800 */
1584 rdev->mode_info.connector_table = CT_MAC_X800;
Alex Deucher7c88d2b2011-06-14 15:27:38 +00001585 } else if ((of_machine_is_compatible("PowerMac7,2") ||
1586 of_machine_is_compatible("PowerMac7,3")) &&
1587 (rdev->pdev->device == 0x4150) &&
1588 (rdev->pdev->subsystem_vendor == 0x1002) &&
1589 (rdev->pdev->subsystem_device == 0x4150)) {
1590 /* Mac G5 tower 9600 */
Alex Deucher9fad3212011-02-07 13:15:28 -05001591 rdev->mode_info.connector_table = CT_MAC_G5_9600;
Alex Deucher6a556032012-05-02 12:10:21 -04001592 } else if ((rdev->pdev->device == 0x4c66) &&
1593 (rdev->pdev->subsystem_vendor == 0x1002) &&
1594 (rdev->pdev->subsystem_device == 0x4c66)) {
1595 /* SAM440ep RV250 embedded board */
1596 rdev->mode_info.connector_table = CT_SAM440EP;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001597 } else
1598#endif /* CONFIG_PPC_PMAC */
Dave Airlie76a71422010-06-11 01:09:05 -04001599#ifdef CONFIG_PPC64
1600 if (ASIC_IS_RN50(rdev))
1601 rdev->mode_info.connector_table = CT_RN50_POWER;
1602 else
1603#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001604 rdev->mode_info.connector_table = CT_GENERIC;
1605 }
1606
1607 switch (rdev->mode_info.connector_table) {
1608 case CT_GENERIC:
1609 DRM_INFO("Connector Table: %d (generic)\n",
1610 rdev->mode_info.connector_table);
1611 /* these are the most common settings */
1612 if (rdev->flags & RADEON_SINGLE_CRTC) {
1613 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001614 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001615 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001616 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001617 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001618 ATOM_DEVICE_CRT1_SUPPORT,
1619 1),
1620 ATOM_DEVICE_CRT1_SUPPORT);
1621 radeon_add_legacy_connector(dev, 0,
1622 ATOM_DEVICE_CRT1_SUPPORT,
1623 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001624 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001625 CONNECTOR_OBJECT_ID_VGA,
1626 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001627 } else if (rdev->flags & RADEON_IS_MOBILITY) {
1628 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001629 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001630 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001631 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001632 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001633 ATOM_DEVICE_LCD1_SUPPORT,
1634 0),
1635 ATOM_DEVICE_LCD1_SUPPORT);
1636 radeon_add_legacy_connector(dev, 0,
1637 ATOM_DEVICE_LCD1_SUPPORT,
1638 DRM_MODE_CONNECTOR_LVDS,
Alex Deucherb75fad02009-11-05 13:16:01 -05001639 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001640 CONNECTOR_OBJECT_ID_LVDS,
1641 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001642
1643 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001644 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001645 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001646 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001647 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001648 ATOM_DEVICE_CRT1_SUPPORT,
1649 1),
1650 ATOM_DEVICE_CRT1_SUPPORT);
1651 radeon_add_legacy_connector(dev, 1,
1652 ATOM_DEVICE_CRT1_SUPPORT,
1653 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001654 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001655 CONNECTOR_OBJECT_ID_VGA,
1656 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001657 } else {
1658 /* DVI-I - tv dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001659 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001660 hpd.hpd = RADEON_HPD_1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001661 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001662 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001663 ATOM_DEVICE_DFP1_SUPPORT,
1664 0),
1665 ATOM_DEVICE_DFP1_SUPPORT);
1666 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001667 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001668 ATOM_DEVICE_CRT2_SUPPORT,
1669 2),
1670 ATOM_DEVICE_CRT2_SUPPORT);
1671 radeon_add_legacy_connector(dev, 0,
1672 ATOM_DEVICE_DFP1_SUPPORT |
1673 ATOM_DEVICE_CRT2_SUPPORT,
1674 DRM_MODE_CONNECTOR_DVII,
Alex Deucherb75fad02009-11-05 13:16:01 -05001675 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001676 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1677 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001678
1679 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001680 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001681 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001682 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001683 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001684 ATOM_DEVICE_CRT1_SUPPORT,
1685 1),
1686 ATOM_DEVICE_CRT1_SUPPORT);
1687 radeon_add_legacy_connector(dev, 1,
1688 ATOM_DEVICE_CRT1_SUPPORT,
1689 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001690 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001691 CONNECTOR_OBJECT_ID_VGA,
1692 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001693 }
1694
1695 if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
1696 /* 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,
Alex Deucher5137ee92010-08-12 18:58:47 -04001700 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001701 ATOM_DEVICE_TV1_SUPPORT,
1702 2),
1703 ATOM_DEVICE_TV1_SUPPORT);
1704 radeon_add_legacy_connector(dev, 2,
1705 ATOM_DEVICE_TV1_SUPPORT,
1706 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001707 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001708 CONNECTOR_OBJECT_ID_SVIDEO,
1709 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001710 }
1711 break;
1712 case CT_IBOOK:
1713 DRM_INFO("Connector Table: %d (ibook)\n",
1714 rdev->mode_info.connector_table);
1715 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001716 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001717 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001718 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001719 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001720 ATOM_DEVICE_LCD1_SUPPORT,
1721 0),
1722 ATOM_DEVICE_LCD1_SUPPORT);
1723 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001724 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001725 CONNECTOR_OBJECT_ID_LVDS,
1726 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001727 /* VGA - TV DAC */
Alex Deucher179e8072010-08-05 21:21:17 -04001728 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001729 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001730 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001731 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001732 ATOM_DEVICE_CRT2_SUPPORT,
1733 2),
1734 ATOM_DEVICE_CRT2_SUPPORT);
1735 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001736 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001737 CONNECTOR_OBJECT_ID_VGA,
1738 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001739 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001740 ddc_i2c.valid = false;
1741 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001742 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001743 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001744 ATOM_DEVICE_TV1_SUPPORT,
1745 2),
1746 ATOM_DEVICE_TV1_SUPPORT);
1747 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1748 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001749 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001750 CONNECTOR_OBJECT_ID_SVIDEO,
1751 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001752 break;
1753 case CT_POWERBOOK_EXTERNAL:
1754 DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
1755 rdev->mode_info.connector_table);
1756 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001757 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001758 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001759 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001760 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001761 ATOM_DEVICE_LCD1_SUPPORT,
1762 0),
1763 ATOM_DEVICE_LCD1_SUPPORT);
1764 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001765 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001766 CONNECTOR_OBJECT_ID_LVDS,
1767 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001768 /* DVI-I - primary dac, ext tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001769 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001770 hpd.hpd = RADEON_HPD_2; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001771 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001772 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001773 ATOM_DEVICE_DFP2_SUPPORT,
1774 0),
1775 ATOM_DEVICE_DFP2_SUPPORT);
1776 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001777 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001778 ATOM_DEVICE_CRT1_SUPPORT,
1779 1),
1780 ATOM_DEVICE_CRT1_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05001781 /* XXX some are SL */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001782 radeon_add_legacy_connector(dev, 1,
1783 ATOM_DEVICE_DFP2_SUPPORT |
1784 ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001785 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001786 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
1787 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001788 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001789 ddc_i2c.valid = false;
1790 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001791 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001792 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001793 ATOM_DEVICE_TV1_SUPPORT,
1794 2),
1795 ATOM_DEVICE_TV1_SUPPORT);
1796 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1797 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001798 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001799 CONNECTOR_OBJECT_ID_SVIDEO,
1800 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001801 break;
1802 case CT_POWERBOOK_INTERNAL:
1803 DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
1804 rdev->mode_info.connector_table);
1805 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001806 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001807 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001808 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001809 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001810 ATOM_DEVICE_LCD1_SUPPORT,
1811 0),
1812 ATOM_DEVICE_LCD1_SUPPORT);
1813 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001814 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001815 CONNECTOR_OBJECT_ID_LVDS,
1816 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001817 /* DVI-I - primary dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001818 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001819 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001820 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001821 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001822 ATOM_DEVICE_DFP1_SUPPORT,
1823 0),
1824 ATOM_DEVICE_DFP1_SUPPORT);
1825 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001826 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001827 ATOM_DEVICE_CRT1_SUPPORT,
1828 1),
1829 ATOM_DEVICE_CRT1_SUPPORT);
1830 radeon_add_legacy_connector(dev, 1,
1831 ATOM_DEVICE_DFP1_SUPPORT |
1832 ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001833 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001834 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1835 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001836 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001837 ddc_i2c.valid = false;
1838 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001839 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001840 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001841 ATOM_DEVICE_TV1_SUPPORT,
1842 2),
1843 ATOM_DEVICE_TV1_SUPPORT);
1844 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1845 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001846 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001847 CONNECTOR_OBJECT_ID_SVIDEO,
1848 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001849 break;
1850 case CT_POWERBOOK_VGA:
1851 DRM_INFO("Connector Table: %d (powerbook vga)\n",
1852 rdev->mode_info.connector_table);
1853 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001854 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001855 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001856 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001857 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001858 ATOM_DEVICE_LCD1_SUPPORT,
1859 0),
1860 ATOM_DEVICE_LCD1_SUPPORT);
1861 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001862 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001863 CONNECTOR_OBJECT_ID_LVDS,
1864 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001865 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001866 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001867 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001868 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001869 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001870 ATOM_DEVICE_CRT1_SUPPORT,
1871 1),
1872 ATOM_DEVICE_CRT1_SUPPORT);
1873 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001874 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001875 CONNECTOR_OBJECT_ID_VGA,
1876 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001877 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001878 ddc_i2c.valid = false;
1879 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001880 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001881 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001882 ATOM_DEVICE_TV1_SUPPORT,
1883 2),
1884 ATOM_DEVICE_TV1_SUPPORT);
1885 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1886 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001887 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001888 CONNECTOR_OBJECT_ID_SVIDEO,
1889 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001890 break;
1891 case CT_MINI_EXTERNAL:
1892 DRM_INFO("Connector Table: %d (mini external tmds)\n",
1893 rdev->mode_info.connector_table);
1894 /* DVI-I - tv dac, ext tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001895 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001896 hpd.hpd = RADEON_HPD_2; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001897 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001898 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001899 ATOM_DEVICE_DFP2_SUPPORT,
1900 0),
1901 ATOM_DEVICE_DFP2_SUPPORT);
1902 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001903 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001904 ATOM_DEVICE_CRT2_SUPPORT,
1905 2),
1906 ATOM_DEVICE_CRT2_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05001907 /* XXX are any DL? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001908 radeon_add_legacy_connector(dev, 0,
1909 ATOM_DEVICE_DFP2_SUPPORT |
1910 ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001911 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001912 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1913 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001914 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001915 ddc_i2c.valid = false;
1916 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001917 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001918 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001919 ATOM_DEVICE_TV1_SUPPORT,
1920 2),
1921 ATOM_DEVICE_TV1_SUPPORT);
1922 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
1923 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001924 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001925 CONNECTOR_OBJECT_ID_SVIDEO,
1926 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001927 break;
1928 case CT_MINI_INTERNAL:
1929 DRM_INFO("Connector Table: %d (mini internal tmds)\n",
1930 rdev->mode_info.connector_table);
1931 /* DVI-I - tv dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001932 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001933 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001934 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001935 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001936 ATOM_DEVICE_DFP1_SUPPORT,
1937 0),
1938 ATOM_DEVICE_DFP1_SUPPORT);
1939 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001940 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001941 ATOM_DEVICE_CRT2_SUPPORT,
1942 2),
1943 ATOM_DEVICE_CRT2_SUPPORT);
1944 radeon_add_legacy_connector(dev, 0,
1945 ATOM_DEVICE_DFP1_SUPPORT |
1946 ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001947 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001948 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1949 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001950 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001951 ddc_i2c.valid = false;
1952 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001953 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001954 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001955 ATOM_DEVICE_TV1_SUPPORT,
1956 2),
1957 ATOM_DEVICE_TV1_SUPPORT);
1958 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
1959 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001960 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001961 CONNECTOR_OBJECT_ID_SVIDEO,
1962 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001963 break;
1964 case CT_IMAC_G5_ISIGHT:
1965 DRM_INFO("Connector Table: %d (imac g5 isight)\n",
1966 rdev->mode_info.connector_table);
1967 /* DVI-D - int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001968 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001969 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001970 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001971 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001972 ATOM_DEVICE_DFP1_SUPPORT,
1973 0),
1974 ATOM_DEVICE_DFP1_SUPPORT);
1975 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001976 DRM_MODE_CONNECTOR_DVID, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001977 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
1978 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001979 /* VGA - tv dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001980 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001981 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001982 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001983 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001984 ATOM_DEVICE_CRT2_SUPPORT,
1985 2),
1986 ATOM_DEVICE_CRT2_SUPPORT);
1987 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001988 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001989 CONNECTOR_OBJECT_ID_VGA,
1990 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001991 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001992 ddc_i2c.valid = false;
1993 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001994 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001995 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001996 ATOM_DEVICE_TV1_SUPPORT,
1997 2),
1998 ATOM_DEVICE_TV1_SUPPORT);
1999 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
2000 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05002001 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002002 CONNECTOR_OBJECT_ID_SVIDEO,
2003 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002004 break;
2005 case CT_EMAC:
2006 DRM_INFO("Connector Table: %d (emac)\n",
2007 rdev->mode_info.connector_table);
2008 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04002009 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05002010 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002011 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002012 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002013 ATOM_DEVICE_CRT1_SUPPORT,
2014 1),
2015 ATOM_DEVICE_CRT1_SUPPORT);
2016 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05002017 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002018 CONNECTOR_OBJECT_ID_VGA,
2019 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002020 /* VGA - tv dac */
Alex Deucher179e8072010-08-05 21:21:17 -04002021 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05002022 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002023 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002024 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002025 ATOM_DEVICE_CRT2_SUPPORT,
2026 2),
2027 ATOM_DEVICE_CRT2_SUPPORT);
2028 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05002029 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002030 CONNECTOR_OBJECT_ID_VGA,
2031 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002032 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05002033 ddc_i2c.valid = false;
2034 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002035 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002036 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002037 ATOM_DEVICE_TV1_SUPPORT,
2038 2),
2039 ATOM_DEVICE_TV1_SUPPORT);
2040 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
2041 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05002042 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002043 CONNECTOR_OBJECT_ID_SVIDEO,
2044 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002045 break;
Dave Airlie76a71422010-06-11 01:09:05 -04002046 case CT_RN50_POWER:
2047 DRM_INFO("Connector Table: %d (rn50-power)\n",
2048 rdev->mode_info.connector_table);
2049 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04002050 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Dave Airlie76a71422010-06-11 01:09:05 -04002051 hpd.hpd = RADEON_HPD_NONE;
2052 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002053 radeon_get_encoder_enum(dev,
Dave Airlie76a71422010-06-11 01:09:05 -04002054 ATOM_DEVICE_CRT1_SUPPORT,
2055 1),
2056 ATOM_DEVICE_CRT1_SUPPORT);
2057 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
2058 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
2059 CONNECTOR_OBJECT_ID_VGA,
2060 &hpd);
Alex Deucher179e8072010-08-05 21:21:17 -04002061 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Dave Airlie76a71422010-06-11 01:09:05 -04002062 hpd.hpd = RADEON_HPD_NONE;
2063 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002064 radeon_get_encoder_enum(dev,
Dave Airlie76a71422010-06-11 01:09:05 -04002065 ATOM_DEVICE_CRT2_SUPPORT,
2066 2),
2067 ATOM_DEVICE_CRT2_SUPPORT);
2068 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
2069 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
2070 CONNECTOR_OBJECT_ID_VGA,
2071 &hpd);
2072 break;
Alex Deucheraa74fbb2010-09-07 14:41:30 -04002073 case CT_MAC_X800:
2074 DRM_INFO("Connector Table: %d (mac x800)\n",
2075 rdev->mode_info.connector_table);
2076 /* DVI - primary dac, internal tmds */
2077 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2078 hpd.hpd = RADEON_HPD_1; /* ??? */
2079 radeon_add_legacy_encoder(dev,
2080 radeon_get_encoder_enum(dev,
2081 ATOM_DEVICE_DFP1_SUPPORT,
2082 0),
2083 ATOM_DEVICE_DFP1_SUPPORT);
2084 radeon_add_legacy_encoder(dev,
2085 radeon_get_encoder_enum(dev,
2086 ATOM_DEVICE_CRT1_SUPPORT,
2087 1),
2088 ATOM_DEVICE_CRT1_SUPPORT);
2089 radeon_add_legacy_connector(dev, 0,
2090 ATOM_DEVICE_DFP1_SUPPORT |
2091 ATOM_DEVICE_CRT1_SUPPORT,
2092 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2093 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2094 &hpd);
2095 /* DVI - tv dac, dvo */
2096 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
2097 hpd.hpd = RADEON_HPD_2; /* ??? */
2098 radeon_add_legacy_encoder(dev,
2099 radeon_get_encoder_enum(dev,
2100 ATOM_DEVICE_DFP2_SUPPORT,
2101 0),
2102 ATOM_DEVICE_DFP2_SUPPORT);
2103 radeon_add_legacy_encoder(dev,
2104 radeon_get_encoder_enum(dev,
2105 ATOM_DEVICE_CRT2_SUPPORT,
2106 2),
2107 ATOM_DEVICE_CRT2_SUPPORT);
2108 radeon_add_legacy_connector(dev, 1,
2109 ATOM_DEVICE_DFP2_SUPPORT |
2110 ATOM_DEVICE_CRT2_SUPPORT,
2111 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2112 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
2113 &hpd);
2114 break;
Alex Deucher9fad3212011-02-07 13:15:28 -05002115 case CT_MAC_G5_9600:
2116 DRM_INFO("Connector Table: %d (mac g5 9600)\n",
2117 rdev->mode_info.connector_table);
2118 /* DVI - tv dac, dvo */
2119 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2120 hpd.hpd = RADEON_HPD_1; /* ??? */
2121 radeon_add_legacy_encoder(dev,
2122 radeon_get_encoder_enum(dev,
2123 ATOM_DEVICE_DFP2_SUPPORT,
2124 0),
2125 ATOM_DEVICE_DFP2_SUPPORT);
2126 radeon_add_legacy_encoder(dev,
2127 radeon_get_encoder_enum(dev,
2128 ATOM_DEVICE_CRT2_SUPPORT,
2129 2),
2130 ATOM_DEVICE_CRT2_SUPPORT);
2131 radeon_add_legacy_connector(dev, 0,
2132 ATOM_DEVICE_DFP2_SUPPORT |
2133 ATOM_DEVICE_CRT2_SUPPORT,
2134 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2135 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2136 &hpd);
2137 /* ADC - primary dac, internal tmds */
2138 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
2139 hpd.hpd = RADEON_HPD_2; /* ??? */
2140 radeon_add_legacy_encoder(dev,
2141 radeon_get_encoder_enum(dev,
2142 ATOM_DEVICE_DFP1_SUPPORT,
2143 0),
2144 ATOM_DEVICE_DFP1_SUPPORT);
2145 radeon_add_legacy_encoder(dev,
2146 radeon_get_encoder_enum(dev,
2147 ATOM_DEVICE_CRT1_SUPPORT,
2148 1),
2149 ATOM_DEVICE_CRT1_SUPPORT);
2150 radeon_add_legacy_connector(dev, 1,
2151 ATOM_DEVICE_DFP1_SUPPORT |
2152 ATOM_DEVICE_CRT1_SUPPORT,
2153 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2154 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2155 &hpd);
Alex Deucherbeb47272011-04-02 09:09:08 -04002156 /* TV - TV DAC */
2157 ddc_i2c.valid = false;
2158 hpd.hpd = RADEON_HPD_NONE;
2159 radeon_add_legacy_encoder(dev,
2160 radeon_get_encoder_enum(dev,
2161 ATOM_DEVICE_TV1_SUPPORT,
2162 2),
2163 ATOM_DEVICE_TV1_SUPPORT);
2164 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
2165 DRM_MODE_CONNECTOR_SVIDEO,
2166 &ddc_i2c,
2167 CONNECTOR_OBJECT_ID_SVIDEO,
2168 &hpd);
Alex Deucher9fad3212011-02-07 13:15:28 -05002169 break;
Alex Deucher6a556032012-05-02 12:10:21 -04002170 case CT_SAM440EP:
2171 DRM_INFO("Connector Table: %d (SAM440ep embedded board)\n",
2172 rdev->mode_info.connector_table);
2173 /* LVDS */
2174 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
2175 hpd.hpd = RADEON_HPD_NONE;
2176 radeon_add_legacy_encoder(dev,
2177 radeon_get_encoder_enum(dev,
2178 ATOM_DEVICE_LCD1_SUPPORT,
2179 0),
2180 ATOM_DEVICE_LCD1_SUPPORT);
2181 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
2182 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
2183 CONNECTOR_OBJECT_ID_LVDS,
2184 &hpd);
2185 /* DVI-I - secondary dac, int tmds */
2186 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2187 hpd.hpd = RADEON_HPD_1; /* ??? */
2188 radeon_add_legacy_encoder(dev,
2189 radeon_get_encoder_enum(dev,
2190 ATOM_DEVICE_DFP1_SUPPORT,
2191 0),
2192 ATOM_DEVICE_DFP1_SUPPORT);
2193 radeon_add_legacy_encoder(dev,
2194 radeon_get_encoder_enum(dev,
2195 ATOM_DEVICE_CRT2_SUPPORT,
2196 2),
2197 ATOM_DEVICE_CRT2_SUPPORT);
2198 radeon_add_legacy_connector(dev, 1,
2199 ATOM_DEVICE_DFP1_SUPPORT |
2200 ATOM_DEVICE_CRT2_SUPPORT,
2201 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2202 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2203 &hpd);
2204 /* VGA - primary dac */
2205 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
2206 hpd.hpd = RADEON_HPD_NONE;
2207 radeon_add_legacy_encoder(dev,
2208 radeon_get_encoder_enum(dev,
2209 ATOM_DEVICE_CRT1_SUPPORT,
2210 1),
2211 ATOM_DEVICE_CRT1_SUPPORT);
2212 radeon_add_legacy_connector(dev, 2,
2213 ATOM_DEVICE_CRT1_SUPPORT,
2214 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
2215 CONNECTOR_OBJECT_ID_VGA,
2216 &hpd);
2217 /* TV - TV DAC */
2218 ddc_i2c.valid = false;
2219 hpd.hpd = RADEON_HPD_NONE;
2220 radeon_add_legacy_encoder(dev,
2221 radeon_get_encoder_enum(dev,
2222 ATOM_DEVICE_TV1_SUPPORT,
2223 2),
2224 ATOM_DEVICE_TV1_SUPPORT);
2225 radeon_add_legacy_connector(dev, 3, ATOM_DEVICE_TV1_SUPPORT,
2226 DRM_MODE_CONNECTOR_SVIDEO,
2227 &ddc_i2c,
2228 CONNECTOR_OBJECT_ID_SVIDEO,
2229 &hpd);
2230 break;
Alex Deuchercafa59b2012-12-20 16:35:47 -05002231 case CT_MAC_G4_SILVER:
2232 DRM_INFO("Connector Table: %d (mac g4 silver)\n",
2233 rdev->mode_info.connector_table);
2234 /* DVI-I - tv dac, int tmds */
2235 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2236 hpd.hpd = RADEON_HPD_1; /* ??? */
2237 radeon_add_legacy_encoder(dev,
2238 radeon_get_encoder_enum(dev,
2239 ATOM_DEVICE_DFP1_SUPPORT,
2240 0),
2241 ATOM_DEVICE_DFP1_SUPPORT);
2242 radeon_add_legacy_encoder(dev,
2243 radeon_get_encoder_enum(dev,
2244 ATOM_DEVICE_CRT2_SUPPORT,
2245 2),
2246 ATOM_DEVICE_CRT2_SUPPORT);
2247 radeon_add_legacy_connector(dev, 0,
2248 ATOM_DEVICE_DFP1_SUPPORT |
2249 ATOM_DEVICE_CRT2_SUPPORT,
2250 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2251 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2252 &hpd);
2253 /* VGA - primary dac */
2254 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
2255 hpd.hpd = RADEON_HPD_NONE;
2256 radeon_add_legacy_encoder(dev,
2257 radeon_get_encoder_enum(dev,
2258 ATOM_DEVICE_CRT1_SUPPORT,
2259 1),
2260 ATOM_DEVICE_CRT1_SUPPORT);
2261 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
2262 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
2263 CONNECTOR_OBJECT_ID_VGA,
2264 &hpd);
2265 /* TV - TV DAC */
2266 ddc_i2c.valid = false;
2267 hpd.hpd = RADEON_HPD_NONE;
2268 radeon_add_legacy_encoder(dev,
2269 radeon_get_encoder_enum(dev,
2270 ATOM_DEVICE_TV1_SUPPORT,
2271 2),
2272 ATOM_DEVICE_TV1_SUPPORT);
2273 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
2274 DRM_MODE_CONNECTOR_SVIDEO,
2275 &ddc_i2c,
2276 CONNECTOR_OBJECT_ID_SVIDEO,
2277 &hpd);
2278 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002279 default:
2280 DRM_INFO("Connector table: %d (invalid)\n",
2281 rdev->mode_info.connector_table);
2282 return false;
2283 }
2284
2285 radeon_link_encoder_connector(dev);
2286
2287 return true;
2288}
2289
2290static bool radeon_apply_legacy_quirks(struct drm_device *dev,
2291 int bios_index,
2292 enum radeon_combios_connector
2293 *legacy_connector,
Alex Deuchereed45b32009-12-04 14:45:27 -05002294 struct radeon_i2c_bus_rec *ddc_i2c,
2295 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002296{
Alex Deucherfcec5702009-11-10 21:25:07 -05002297
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002298 /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
2299 one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
2300 if (dev->pdev->device == 0x515e &&
2301 dev->pdev->subsystem_vendor == 0x1014) {
2302 if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
2303 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
2304 return false;
2305 }
2306
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002307 /* X300 card with extra non-existent DVI port */
2308 if (dev->pdev->device == 0x5B60 &&
2309 dev->pdev->subsystem_vendor == 0x17af &&
2310 dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
2311 if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
2312 return false;
2313 }
2314
2315 return true;
2316}
2317
Alex Deucher790cfb32009-10-15 23:26:09 -04002318static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
2319{
2320 /* Acer 5102 has non-existent TV port */
2321 if (dev->pdev->device == 0x5975 &&
2322 dev->pdev->subsystem_vendor == 0x1025 &&
2323 dev->pdev->subsystem_device == 0x009f)
2324 return false;
2325
Alex Deucherfc7f7112009-10-28 01:46:54 -04002326 /* HP dc5750 has non-existent TV port */
2327 if (dev->pdev->device == 0x5974 &&
2328 dev->pdev->subsystem_vendor == 0x103c &&
2329 dev->pdev->subsystem_device == 0x280a)
2330 return false;
2331
Alex Deucherfd874ad2009-11-16 18:33:51 -05002332 /* MSI S270 has non-existent TV port */
2333 if (dev->pdev->device == 0x5955 &&
2334 dev->pdev->subsystem_vendor == 0x1462 &&
2335 dev->pdev->subsystem_device == 0x0131)
2336 return false;
2337
Alex Deucher790cfb32009-10-15 23:26:09 -04002338 return true;
2339}
2340
Alex Deucherb75fad02009-11-05 13:16:01 -05002341static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
2342{
2343 struct radeon_device *rdev = dev->dev_private;
2344 uint32_t ext_tmds_info;
2345
2346 if (rdev->flags & RADEON_IS_IGP) {
2347 if (is_dvi_d)
2348 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
2349 else
2350 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2351 }
2352 ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
2353 if (ext_tmds_info) {
2354 uint8_t rev = RBIOS8(ext_tmds_info);
2355 uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
2356 if (rev >= 3) {
2357 if (is_dvi_d)
2358 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
2359 else
2360 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
2361 } else {
2362 if (flags & 1) {
2363 if (is_dvi_d)
2364 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
2365 else
2366 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
2367 }
2368 }
2369 }
2370 if (is_dvi_d)
2371 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
2372 else
2373 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2374}
2375
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002376bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2377{
2378 struct radeon_device *rdev = dev->dev_private;
2379 uint32_t conn_info, entry, devices;
Alex Deucherb75fad02009-11-05 13:16:01 -05002380 uint16_t tmp, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002381 enum radeon_combios_ddc ddc_type;
2382 enum radeon_combios_connector connector;
2383 int i = 0;
2384 struct radeon_i2c_bus_rec ddc_i2c;
Alex Deuchereed45b32009-12-04 14:45:27 -05002385 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002386
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002387 conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
2388 if (conn_info) {
2389 for (i = 0; i < 4; i++) {
2390 entry = conn_info + 2 + i * 2;
2391
2392 if (!RBIOS16(entry))
2393 break;
2394
2395 tmp = RBIOS16(entry);
2396
2397 connector = (tmp >> 12) & 0xf;
2398
2399 ddc_type = (tmp >> 8) & 0xf;
Alex Deucher3d61bd42012-07-19 20:11:44 -04002400 if (ddc_type == 5)
2401 ddc_i2c = radeon_combios_get_i2c_info_from_table(rdev);
2402 else
2403 ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002404
Alex Deuchereed45b32009-12-04 14:45:27 -05002405 switch (connector) {
2406 case CONNECTOR_PROPRIETARY_LEGACY:
2407 case CONNECTOR_DVI_I_LEGACY:
2408 case CONNECTOR_DVI_D_LEGACY:
2409 if ((tmp >> 4) & 0x1)
2410 hpd.hpd = RADEON_HPD_2;
2411 else
2412 hpd.hpd = RADEON_HPD_1;
2413 break;
2414 default:
2415 hpd.hpd = RADEON_HPD_NONE;
2416 break;
2417 }
2418
Alex Deucher2d152c62009-10-15 23:08:05 -04002419 if (!radeon_apply_legacy_quirks(dev, i, &connector,
Alex Deuchereed45b32009-12-04 14:45:27 -05002420 &ddc_i2c, &hpd))
Alex Deucher2d152c62009-10-15 23:08:05 -04002421 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002422
2423 switch (connector) {
2424 case CONNECTOR_PROPRIETARY_LEGACY:
2425 if ((tmp >> 4) & 0x1)
2426 devices = ATOM_DEVICE_DFP2_SUPPORT;
2427 else
2428 devices = ATOM_DEVICE_DFP1_SUPPORT;
2429 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002430 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002431 (dev, devices, 0),
2432 devices);
2433 radeon_add_legacy_connector(dev, i, devices,
2434 legacy_connector_convert
2435 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002436 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002437 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
2438 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002439 break;
2440 case CONNECTOR_CRT_LEGACY:
2441 if (tmp & 0x1) {
2442 devices = ATOM_DEVICE_CRT2_SUPPORT;
2443 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002444 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002445 (dev,
2446 ATOM_DEVICE_CRT2_SUPPORT,
2447 2),
2448 ATOM_DEVICE_CRT2_SUPPORT);
2449 } else {
2450 devices = ATOM_DEVICE_CRT1_SUPPORT;
2451 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002452 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002453 (dev,
2454 ATOM_DEVICE_CRT1_SUPPORT,
2455 1),
2456 ATOM_DEVICE_CRT1_SUPPORT);
2457 }
2458 radeon_add_legacy_connector(dev,
2459 i,
2460 devices,
2461 legacy_connector_convert
2462 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002463 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002464 CONNECTOR_OBJECT_ID_VGA,
2465 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002466 break;
2467 case CONNECTOR_DVI_I_LEGACY:
2468 devices = 0;
2469 if (tmp & 0x1) {
2470 devices |= ATOM_DEVICE_CRT2_SUPPORT;
2471 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002472 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002473 (dev,
2474 ATOM_DEVICE_CRT2_SUPPORT,
2475 2),
2476 ATOM_DEVICE_CRT2_SUPPORT);
2477 } else {
2478 devices |= ATOM_DEVICE_CRT1_SUPPORT;
2479 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002480 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002481 (dev,
2482 ATOM_DEVICE_CRT1_SUPPORT,
2483 1),
2484 ATOM_DEVICE_CRT1_SUPPORT);
2485 }
Alex Deucher9200ee42013-01-29 16:36:47 -05002486 /* RV100 board with external TDMS bit mis-set.
2487 * Actually uses internal TMDS, clear the bit.
2488 */
2489 if (dev->pdev->device == 0x5159 &&
2490 dev->pdev->subsystem_vendor == 0x1014 &&
2491 dev->pdev->subsystem_device == 0x029A) {
2492 tmp &= ~(1 << 4);
2493 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002494 if ((tmp >> 4) & 0x1) {
2495 devices |= ATOM_DEVICE_DFP2_SUPPORT;
2496 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002497 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002498 (dev,
2499 ATOM_DEVICE_DFP2_SUPPORT,
2500 0),
2501 ATOM_DEVICE_DFP2_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05002502 connector_object_id = combios_check_dl_dvi(dev, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002503 } else {
2504 devices |= ATOM_DEVICE_DFP1_SUPPORT;
2505 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002506 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002507 (dev,
2508 ATOM_DEVICE_DFP1_SUPPORT,
2509 0),
2510 ATOM_DEVICE_DFP1_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05002511 connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002512 }
2513 radeon_add_legacy_connector(dev,
2514 i,
2515 devices,
2516 legacy_connector_convert
2517 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002518 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002519 connector_object_id,
2520 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002521 break;
2522 case CONNECTOR_DVI_D_LEGACY:
Alex Deucherb75fad02009-11-05 13:16:01 -05002523 if ((tmp >> 4) & 0x1) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002524 devices = ATOM_DEVICE_DFP2_SUPPORT;
Alex Deucherb75fad02009-11-05 13:16:01 -05002525 connector_object_id = combios_check_dl_dvi(dev, 1);
2526 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002527 devices = ATOM_DEVICE_DFP1_SUPPORT;
Alex Deucherb75fad02009-11-05 13:16:01 -05002528 connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2529 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002530 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002531 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002532 (dev, devices, 0),
2533 devices);
2534 radeon_add_legacy_connector(dev, i, devices,
2535 legacy_connector_convert
2536 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002537 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002538 connector_object_id,
2539 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002540 break;
2541 case CONNECTOR_CTV_LEGACY:
2542 case CONNECTOR_STV_LEGACY:
2543 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002544 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002545 (dev,
2546 ATOM_DEVICE_TV1_SUPPORT,
2547 2),
2548 ATOM_DEVICE_TV1_SUPPORT);
2549 radeon_add_legacy_connector(dev, i,
2550 ATOM_DEVICE_TV1_SUPPORT,
2551 legacy_connector_convert
2552 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002553 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002554 CONNECTOR_OBJECT_ID_SVIDEO,
2555 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002556 break;
2557 default:
2558 DRM_ERROR("Unknown connector type: %d\n",
2559 connector);
2560 continue;
2561 }
2562
2563 }
2564 } else {
2565 uint16_t tmds_info =
2566 combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
2567 if (tmds_info) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002568 DRM_DEBUG_KMS("Found DFP table, assuming DVI connector\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002569
2570 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002571 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002572 ATOM_DEVICE_CRT1_SUPPORT,
2573 1),
2574 ATOM_DEVICE_CRT1_SUPPORT);
2575 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002576 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002577 ATOM_DEVICE_DFP1_SUPPORT,
2578 0),
2579 ATOM_DEVICE_DFP1_SUPPORT);
2580
Alex Deucher179e8072010-08-05 21:21:17 -04002581 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deucher8e36ed02010-05-18 19:26:47 -04002582 hpd.hpd = RADEON_HPD_1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002583 radeon_add_legacy_connector(dev,
2584 0,
2585 ATOM_DEVICE_CRT1_SUPPORT |
2586 ATOM_DEVICE_DFP1_SUPPORT,
2587 DRM_MODE_CONNECTOR_DVII,
Alex Deucherb75fad02009-11-05 13:16:01 -05002588 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002589 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2590 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002591 } else {
Alex Deucherd0c403e2009-10-15 23:38:32 -04002592 uint16_t crt_info =
2593 combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002594 DRM_DEBUG_KMS("Found CRT table, assuming VGA connector\n");
Alex Deucherd0c403e2009-10-15 23:38:32 -04002595 if (crt_info) {
2596 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002597 radeon_get_encoder_enum(dev,
Alex Deucherd0c403e2009-10-15 23:38:32 -04002598 ATOM_DEVICE_CRT1_SUPPORT,
2599 1),
2600 ATOM_DEVICE_CRT1_SUPPORT);
Alex Deucher179e8072010-08-05 21:21:17 -04002601 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05002602 hpd.hpd = RADEON_HPD_NONE;
Alex Deucherd0c403e2009-10-15 23:38:32 -04002603 radeon_add_legacy_connector(dev,
2604 0,
2605 ATOM_DEVICE_CRT1_SUPPORT,
2606 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05002607 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002608 CONNECTOR_OBJECT_ID_VGA,
2609 &hpd);
Alex Deucherd0c403e2009-10-15 23:38:32 -04002610 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002611 DRM_DEBUG_KMS("No connector info found\n");
Alex Deucherd0c403e2009-10-15 23:38:32 -04002612 return false;
2613 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002614 }
2615 }
2616
2617 if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
2618 uint16_t lcd_info =
2619 combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
2620 if (lcd_info) {
2621 uint16_t lcd_ddc_info =
2622 combios_get_table_offset(dev,
2623 COMBIOS_LCD_DDC_INFO_TABLE);
2624
2625 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002626 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002627 ATOM_DEVICE_LCD1_SUPPORT,
2628 0),
2629 ATOM_DEVICE_LCD1_SUPPORT);
2630
2631 if (lcd_ddc_info) {
2632 ddc_type = RBIOS8(lcd_ddc_info + 2);
2633 switch (ddc_type) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002634 case DDC_LCD:
2635 ddc_i2c =
Alex Deucher179e8072010-08-05 21:21:17 -04002636 combios_setup_i2c_bus(rdev,
2637 DDC_LCD,
2638 RBIOS32(lcd_ddc_info + 3),
2639 RBIOS32(lcd_ddc_info + 7));
Alex Deucherf376b942010-08-05 21:21:16 -04002640 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002641 break;
2642 case DDC_GPIO:
2643 ddc_i2c =
Alex Deucher179e8072010-08-05 21:21:17 -04002644 combios_setup_i2c_bus(rdev,
2645 DDC_GPIO,
2646 RBIOS32(lcd_ddc_info + 3),
2647 RBIOS32(lcd_ddc_info + 7));
Alex Deucherf376b942010-08-05 21:21:16 -04002648 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002649 break;
2650 default:
Alex Deucher179e8072010-08-05 21:21:17 -04002651 ddc_i2c =
2652 combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002653 break;
2654 }
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002655 DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002656 } else
2657 ddc_i2c.valid = false;
2658
Alex Deuchereed45b32009-12-04 14:45:27 -05002659 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002660 radeon_add_legacy_connector(dev,
2661 5,
2662 ATOM_DEVICE_LCD1_SUPPORT,
2663 DRM_MODE_CONNECTOR_LVDS,
Alex Deucherb75fad02009-11-05 13:16:01 -05002664 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002665 CONNECTOR_OBJECT_ID_LVDS,
2666 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002667 }
2668 }
2669
2670 /* check TV table */
2671 if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
2672 uint32_t tv_info =
2673 combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
2674 if (tv_info) {
2675 if (RBIOS8(tv_info + 6) == 'T') {
Alex Deucher790cfb32009-10-15 23:26:09 -04002676 if (radeon_apply_legacy_tv_quirks(dev)) {
Alex Deuchereed45b32009-12-04 14:45:27 -05002677 hpd.hpd = RADEON_HPD_NONE;
Dave Airlied294ed62010-06-08 13:04:50 +10002678 ddc_i2c.valid = false;
Alex Deucher790cfb32009-10-15 23:26:09 -04002679 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002680 radeon_get_encoder_enum
Alex Deucher790cfb32009-10-15 23:26:09 -04002681 (dev,
2682 ATOM_DEVICE_TV1_SUPPORT,
2683 2),
2684 ATOM_DEVICE_TV1_SUPPORT);
2685 radeon_add_legacy_connector(dev, 6,
2686 ATOM_DEVICE_TV1_SUPPORT,
2687 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05002688 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002689 CONNECTOR_OBJECT_ID_SVIDEO,
2690 &hpd);
Alex Deucher790cfb32009-10-15 23:26:09 -04002691 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002692 }
2693 }
2694 }
2695
2696 radeon_link_encoder_connector(dev);
2697
2698 return true;
2699}
2700
Alex Deucher63f7d982011-05-03 12:44:54 -04002701static const char *thermal_controller_names[] = {
2702 "NONE",
2703 "lm63",
2704 "adm1032",
2705};
2706
Alex Deucher56278a82009-12-28 13:58:44 -05002707void radeon_combios_get_power_modes(struct radeon_device *rdev)
2708{
2709 struct drm_device *dev = rdev->ddev;
2710 u16 offset, misc, misc2 = 0;
2711 u8 rev, blocks, tmp;
2712 int state_index = 0;
Alex Deucherc41b9ee2011-07-30 18:12:24 +00002713 struct radeon_i2c_bus_rec i2c_bus;
Alex Deucher56278a82009-12-28 13:58:44 -05002714
Alex Deuchera48b9b42010-04-22 14:03:55 -04002715 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05002716
Alex Deucher0975b162011-02-02 18:42:03 -05002717 /* allocate 2 power states */
2718 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * 2, GFP_KERNEL);
Alex Deuchera7c36fd2011-11-12 11:57:29 -05002719 if (rdev->pm.power_state) {
2720 /* allocate 1 clock mode per state */
2721 rdev->pm.power_state[0].clock_info =
2722 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2723 rdev->pm.power_state[1].clock_info =
2724 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2725 if (!rdev->pm.power_state[0].clock_info ||
2726 !rdev->pm.power_state[1].clock_info)
2727 goto pm_failed;
2728 } else
2729 goto pm_failed;
Alex Deucher0975b162011-02-02 18:42:03 -05002730
Alex Deucher63f7d982011-05-03 12:44:54 -04002731 /* check for a thermal chip */
2732 offset = combios_get_table_offset(dev, COMBIOS_OVERDRIVE_INFO_TABLE);
2733 if (offset) {
2734 u8 thermal_controller = 0, gpio = 0, i2c_addr = 0, clk_bit = 0, data_bit = 0;
Alex Deucher63f7d982011-05-03 12:44:54 -04002735
2736 rev = RBIOS8(offset);
2737
2738 if (rev == 0) {
2739 thermal_controller = RBIOS8(offset + 3);
2740 gpio = RBIOS8(offset + 4) & 0x3f;
2741 i2c_addr = RBIOS8(offset + 5);
2742 } else if (rev == 1) {
2743 thermal_controller = RBIOS8(offset + 4);
2744 gpio = RBIOS8(offset + 5) & 0x3f;
2745 i2c_addr = RBIOS8(offset + 6);
2746 } else if (rev == 2) {
2747 thermal_controller = RBIOS8(offset + 4);
2748 gpio = RBIOS8(offset + 5) & 0x3f;
2749 i2c_addr = RBIOS8(offset + 6);
2750 clk_bit = RBIOS8(offset + 0xa);
2751 data_bit = RBIOS8(offset + 0xb);
2752 }
2753 if ((thermal_controller > 0) && (thermal_controller < 3)) {
2754 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2755 thermal_controller_names[thermal_controller],
2756 i2c_addr >> 1);
2757 if (gpio == DDC_LCD) {
2758 /* MM i2c */
2759 i2c_bus.valid = true;
2760 i2c_bus.hw_capable = true;
2761 i2c_bus.mm_i2c = true;
2762 i2c_bus.i2c_id = 0xa0;
2763 } else if (gpio == DDC_GPIO)
2764 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 1 << clk_bit, 1 << data_bit);
2765 else
2766 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
2767 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2768 if (rdev->pm.i2c_bus) {
2769 struct i2c_board_info info = { };
2770 const char *name = thermal_controller_names[thermal_controller];
2771 info.addr = i2c_addr >> 1;
2772 strlcpy(info.type, name, sizeof(info.type));
2773 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2774 }
2775 }
Alex Deucherc41b9ee2011-07-30 18:12:24 +00002776 } else {
2777 /* boards with a thermal chip, but no overdrive table */
2778
2779 /* Asus 9600xt has an f75375 on the monid bus */
2780 if ((dev->pdev->device == 0x4152) &&
2781 (dev->pdev->subsystem_vendor == 0x1043) &&
2782 (dev->pdev->subsystem_device == 0xc002)) {
2783 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
2784 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2785 if (rdev->pm.i2c_bus) {
2786 struct i2c_board_info info = { };
2787 const char *name = "f75375";
2788 info.addr = 0x28;
2789 strlcpy(info.type, name, sizeof(info.type));
2790 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2791 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2792 name, info.addr);
2793 }
2794 }
Alex Deucher63f7d982011-05-03 12:44:54 -04002795 }
2796
Alex Deucher56278a82009-12-28 13:58:44 -05002797 if (rdev->flags & RADEON_IS_MOBILITY) {
2798 offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
2799 if (offset) {
2800 rev = RBIOS8(offset);
2801 blocks = RBIOS8(offset + 0x2);
2802 /* power mode 0 tends to be the only valid one */
2803 rdev->pm.power_state[state_index].num_clock_modes = 1;
2804 rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
2805 rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
2806 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2807 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2808 goto default_mode;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002809 rdev->pm.power_state[state_index].type =
2810 POWER_STATE_TYPE_BATTERY;
Alex Deucher56278a82009-12-28 13:58:44 -05002811 misc = RBIOS16(offset + 0x5 + 0x0);
2812 if (rev > 4)
2813 misc2 = RBIOS16(offset + 0x5 + 0xe);
Alex Deucher79daedc2010-04-22 14:25:19 -04002814 rdev->pm.power_state[state_index].misc = misc;
2815 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher56278a82009-12-28 13:58:44 -05002816 if (misc & 0x4) {
2817 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
2818 if (misc & 0x8)
2819 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2820 true;
2821 else
2822 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2823 false;
2824 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
2825 if (rev < 6) {
2826 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
2827 RBIOS16(offset + 0x5 + 0xb) * 4;
2828 tmp = RBIOS8(offset + 0x5 + 0xd);
2829 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
2830 } else {
2831 u8 entries = RBIOS8(offset + 0x5 + 0xb);
2832 u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
2833 if (entries && voltage_table_offset) {
2834 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
2835 RBIOS16(voltage_table_offset) * 4;
2836 tmp = RBIOS8(voltage_table_offset + 0x2);
2837 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
2838 } else
2839 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
2840 }
2841 switch ((misc2 & 0x700) >> 8) {
2842 case 0:
2843 default:
2844 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
2845 break;
2846 case 1:
2847 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
2848 break;
2849 case 2:
2850 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
2851 break;
2852 case 3:
2853 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
2854 break;
2855 case 4:
2856 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
2857 break;
2858 }
2859 } else
2860 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2861 if (rev > 6)
Alex Deucher79daedc2010-04-22 14:25:19 -04002862 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05002863 RBIOS8(offset + 0x5 + 0x10);
Alex Deucherd7311172010-05-03 01:13:14 -04002864 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05002865 state_index++;
2866 } else {
2867 /* XXX figure out some good default low power mode for mobility cards w/out power tables */
2868 }
2869 } else {
2870 /* XXX figure out some good default low power mode for desktop cards */
2871 }
2872
2873default_mode:
2874 /* add the default mode */
Alex Deucher0ec0e742009-12-23 13:21:58 -05002875 rdev->pm.power_state[state_index].type =
2876 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05002877 rdev->pm.power_state[state_index].num_clock_modes = 1;
2878 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2879 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2880 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 -04002881 if ((state_index > 0) &&
Alex Deucher8de016e2010-06-03 21:28:23 -04002882 (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
Alex Deucher84d88f42010-05-27 17:01:42 -04002883 rdev->pm.power_state[state_index].clock_info[0].voltage =
2884 rdev->pm.power_state[0].clock_info[0].voltage;
2885 else
2886 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
Alex Deucher79daedc2010-04-22 14:25:19 -04002887 rdev->pm.power_state[state_index].pcie_lanes = 16;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002888 rdev->pm.power_state[state_index].flags = 0;
2889 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05002890 rdev->pm.num_power_states = state_index + 1;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002891
Alex Deuchera48b9b42010-04-22 14:03:55 -04002892 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2893 rdev->pm.current_clock_mode_index = 0;
Alex Deuchera7c36fd2011-11-12 11:57:29 -05002894 return;
2895
2896pm_failed:
2897 rdev->pm.default_power_state_index = state_index;
2898 rdev->pm.num_power_states = 0;
2899
2900 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2901 rdev->pm.current_clock_mode_index = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002902}
2903
Alex Deucherfcec5702009-11-10 21:25:07 -05002904void radeon_external_tmds_setup(struct drm_encoder *encoder)
2905{
2906 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2907 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
2908
2909 if (!tmds)
2910 return;
2911
2912 switch (tmds->dvo_chip) {
2913 case DVO_SIL164:
2914 /* sil 164 */
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002915 radeon_i2c_put_byte(tmds->i2c_bus,
2916 tmds->slave_addr,
2917 0x08, 0x30);
2918 radeon_i2c_put_byte(tmds->i2c_bus,
Alex Deucherfcec5702009-11-10 21:25:07 -05002919 tmds->slave_addr,
2920 0x09, 0x00);
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002921 radeon_i2c_put_byte(tmds->i2c_bus,
2922 tmds->slave_addr,
2923 0x0a, 0x90);
2924 radeon_i2c_put_byte(tmds->i2c_bus,
2925 tmds->slave_addr,
2926 0x0c, 0x89);
2927 radeon_i2c_put_byte(tmds->i2c_bus,
Alex Deucherfcec5702009-11-10 21:25:07 -05002928 tmds->slave_addr,
2929 0x08, 0x3b);
Alex Deucherfcec5702009-11-10 21:25:07 -05002930 break;
2931 case DVO_SIL1178:
2932 /* sil 1178 - untested */
2933 /*
2934 * 0x0f, 0x44
2935 * 0x0f, 0x4c
2936 * 0x0e, 0x01
2937 * 0x0a, 0x80
2938 * 0x09, 0x30
2939 * 0x0c, 0xc9
2940 * 0x0d, 0x70
2941 * 0x08, 0x32
2942 * 0x08, 0x33
2943 */
2944 break;
2945 default:
2946 break;
2947 }
2948
2949}
2950
2951bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
2952{
2953 struct drm_device *dev = encoder->dev;
2954 struct radeon_device *rdev = dev->dev_private;
2955 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2956 uint16_t offset;
2957 uint8_t blocks, slave_addr, rev;
2958 uint32_t index, id;
2959 uint32_t reg, val, and_mask, or_mask;
2960 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
2961
Alex Deucherfcec5702009-11-10 21:25:07 -05002962 if (!tmds)
2963 return false;
2964
2965 if (rdev->flags & RADEON_IS_IGP) {
2966 offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
2967 rev = RBIOS8(offset);
2968 if (offset) {
2969 rev = RBIOS8(offset);
2970 if (rev > 1) {
2971 blocks = RBIOS8(offset + 3);
2972 index = offset + 4;
2973 while (blocks > 0) {
2974 id = RBIOS16(index);
2975 index += 2;
2976 switch (id >> 13) {
2977 case 0:
2978 reg = (id & 0x1fff) * 4;
2979 val = RBIOS32(index);
2980 index += 4;
2981 WREG32(reg, val);
2982 break;
2983 case 2:
2984 reg = (id & 0x1fff) * 4;
2985 and_mask = RBIOS32(index);
2986 index += 4;
2987 or_mask = RBIOS32(index);
2988 index += 4;
2989 val = RREG32(reg);
2990 val = (val & and_mask) | or_mask;
2991 WREG32(reg, val);
2992 break;
2993 case 3:
2994 val = RBIOS16(index);
2995 index += 2;
2996 udelay(val);
2997 break;
2998 case 4:
2999 val = RBIOS16(index);
3000 index += 2;
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003001 mdelay(val);
Alex Deucherfcec5702009-11-10 21:25:07 -05003002 break;
3003 case 6:
3004 slave_addr = id & 0xff;
3005 slave_addr >>= 1; /* 7 bit addressing */
3006 index++;
3007 reg = RBIOS8(index);
3008 index++;
3009 val = RBIOS8(index);
3010 index++;
Alex Deucher5a6f98f2009-12-22 15:04:48 -05003011 radeon_i2c_put_byte(tmds->i2c_bus,
3012 slave_addr,
3013 reg, val);
Alex Deucherfcec5702009-11-10 21:25:07 -05003014 break;
3015 default:
3016 DRM_ERROR("Unknown id %d\n", id >> 13);
3017 break;
3018 }
3019 blocks--;
3020 }
3021 return true;
3022 }
3023 }
3024 } else {
3025 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
3026 if (offset) {
3027 index = offset + 10;
3028 id = RBIOS16(index);
3029 while (id != 0xffff) {
3030 index += 2;
3031 switch (id >> 13) {
3032 case 0:
3033 reg = (id & 0x1fff) * 4;
3034 val = RBIOS32(index);
3035 WREG32(reg, val);
3036 break;
3037 case 2:
3038 reg = (id & 0x1fff) * 4;
3039 and_mask = RBIOS32(index);
3040 index += 4;
3041 or_mask = RBIOS32(index);
3042 index += 4;
3043 val = RREG32(reg);
3044 val = (val & and_mask) | or_mask;
3045 WREG32(reg, val);
3046 break;
3047 case 4:
3048 val = RBIOS16(index);
3049 index += 2;
3050 udelay(val);
3051 break;
3052 case 5:
3053 reg = id & 0x1fff;
3054 and_mask = RBIOS32(index);
3055 index += 4;
3056 or_mask = RBIOS32(index);
3057 index += 4;
3058 val = RREG32_PLL(reg);
3059 val = (val & and_mask) | or_mask;
3060 WREG32_PLL(reg, val);
3061 break;
3062 case 6:
3063 reg = id & 0x1fff;
3064 val = RBIOS8(index);
3065 index += 1;
Alex Deucher5a6f98f2009-12-22 15:04:48 -05003066 radeon_i2c_put_byte(tmds->i2c_bus,
3067 tmds->slave_addr,
3068 reg, val);
Alex Deucherfcec5702009-11-10 21:25:07 -05003069 break;
3070 default:
3071 DRM_ERROR("Unknown id %d\n", id >> 13);
3072 break;
3073 }
3074 id = RBIOS16(index);
3075 }
3076 return true;
3077 }
3078 }
3079 return false;
3080}
3081
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003082static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
3083{
3084 struct radeon_device *rdev = dev->dev_private;
3085
3086 if (offset) {
3087 while (RBIOS16(offset)) {
3088 uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
3089 uint32_t addr = (RBIOS16(offset) & 0x1fff);
3090 uint32_t val, and_mask, or_mask;
3091 uint32_t tmp;
3092
3093 offset += 2;
3094 switch (cmd) {
3095 case 0:
3096 val = RBIOS32(offset);
3097 offset += 4;
3098 WREG32(addr, val);
3099 break;
3100 case 1:
3101 val = RBIOS32(offset);
3102 offset += 4;
3103 WREG32(addr, val);
3104 break;
3105 case 2:
3106 and_mask = RBIOS32(offset);
3107 offset += 4;
3108 or_mask = RBIOS32(offset);
3109 offset += 4;
3110 tmp = RREG32(addr);
3111 tmp &= and_mask;
3112 tmp |= or_mask;
3113 WREG32(addr, tmp);
3114 break;
3115 case 3:
3116 and_mask = RBIOS32(offset);
3117 offset += 4;
3118 or_mask = RBIOS32(offset);
3119 offset += 4;
3120 tmp = RREG32(addr);
3121 tmp &= and_mask;
3122 tmp |= or_mask;
3123 WREG32(addr, tmp);
3124 break;
3125 case 4:
3126 val = RBIOS16(offset);
3127 offset += 2;
3128 udelay(val);
3129 break;
3130 case 5:
3131 val = RBIOS16(offset);
3132 offset += 2;
3133 switch (addr) {
3134 case 8:
3135 while (val--) {
3136 if (!
3137 (RREG32_PLL
3138 (RADEON_CLK_PWRMGT_CNTL) &
3139 RADEON_MC_BUSY))
3140 break;
3141 }
3142 break;
3143 case 9:
3144 while (val--) {
3145 if ((RREG32(RADEON_MC_STATUS) &
3146 RADEON_MC_IDLE))
3147 break;
3148 }
3149 break;
3150 default:
3151 break;
3152 }
3153 break;
3154 default:
3155 break;
3156 }
3157 }
3158 }
3159}
3160
3161static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
3162{
3163 struct radeon_device *rdev = dev->dev_private;
3164
3165 if (offset) {
3166 while (RBIOS8(offset)) {
3167 uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
3168 uint8_t addr = (RBIOS8(offset) & 0x3f);
3169 uint32_t val, shift, tmp;
3170 uint32_t and_mask, or_mask;
3171
3172 offset++;
3173 switch (cmd) {
3174 case 0:
3175 val = RBIOS32(offset);
3176 offset += 4;
3177 WREG32_PLL(addr, val);
3178 break;
3179 case 1:
3180 shift = RBIOS8(offset) * 8;
3181 offset++;
3182 and_mask = RBIOS8(offset) << shift;
3183 and_mask |= ~(0xff << shift);
3184 offset++;
3185 or_mask = RBIOS8(offset) << shift;
3186 offset++;
3187 tmp = RREG32_PLL(addr);
3188 tmp &= and_mask;
3189 tmp |= or_mask;
3190 WREG32_PLL(addr, tmp);
3191 break;
3192 case 2:
3193 case 3:
3194 tmp = 1000;
3195 switch (addr) {
3196 case 1:
3197 udelay(150);
3198 break;
3199 case 2:
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003200 mdelay(1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003201 break;
3202 case 3:
3203 while (tmp--) {
3204 if (!
3205 (RREG32_PLL
3206 (RADEON_CLK_PWRMGT_CNTL) &
3207 RADEON_MC_BUSY))
3208 break;
3209 }
3210 break;
3211 case 4:
3212 while (tmp--) {
3213 if (RREG32_PLL
3214 (RADEON_CLK_PWRMGT_CNTL) &
3215 RADEON_DLL_READY)
3216 break;
3217 }
3218 break;
3219 case 5:
3220 tmp =
3221 RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
3222 if (tmp & RADEON_CG_NO1_DEBUG_0) {
3223#if 0
3224 uint32_t mclk_cntl =
3225 RREG32_PLL
3226 (RADEON_MCLK_CNTL);
3227 mclk_cntl &= 0xffff0000;
3228 /*mclk_cntl |= 0x00001111;*//* ??? */
3229 WREG32_PLL(RADEON_MCLK_CNTL,
3230 mclk_cntl);
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003231 mdelay(10);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003232#endif
3233 WREG32_PLL
3234 (RADEON_CLK_PWRMGT_CNTL,
3235 tmp &
3236 ~RADEON_CG_NO1_DEBUG_0);
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003237 mdelay(10);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003238 }
3239 break;
3240 default:
3241 break;
3242 }
3243 break;
3244 default:
3245 break;
3246 }
3247 }
3248 }
3249}
3250
3251static void combios_parse_ram_reset_table(struct drm_device *dev,
3252 uint16_t offset)
3253{
3254 struct radeon_device *rdev = dev->dev_private;
3255 uint32_t tmp;
3256
3257 if (offset) {
3258 uint8_t val = RBIOS8(offset);
3259 while (val != 0xff) {
3260 offset++;
3261
3262 if (val == 0x0f) {
3263 uint32_t channel_complete_mask;
3264
3265 if (ASIC_IS_R300(rdev))
3266 channel_complete_mask =
3267 R300_MEM_PWRUP_COMPLETE;
3268 else
3269 channel_complete_mask =
3270 RADEON_MEM_PWRUP_COMPLETE;
3271 tmp = 20000;
3272 while (tmp--) {
3273 if ((RREG32(RADEON_MEM_STR_CNTL) &
3274 channel_complete_mask) ==
3275 channel_complete_mask)
3276 break;
3277 }
3278 } else {
3279 uint32_t or_mask = RBIOS16(offset);
3280 offset += 2;
3281
3282 tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
3283 tmp &= RADEON_SDRAM_MODE_MASK;
3284 tmp |= or_mask;
3285 WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
3286
3287 or_mask = val << 24;
3288 tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
3289 tmp &= RADEON_B3MEM_RESET_MASK;
3290 tmp |= or_mask;
3291 WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
3292 }
3293 val = RBIOS8(offset);
3294 }
3295 }
3296}
3297
3298static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
3299 int mem_addr_mapping)
3300{
3301 struct radeon_device *rdev = dev->dev_private;
3302 uint32_t mem_cntl;
3303 uint32_t mem_size;
3304 uint32_t addr = 0;
3305
3306 mem_cntl = RREG32(RADEON_MEM_CNTL);
3307 if (mem_cntl & RV100_HALF_MODE)
3308 ram /= 2;
3309 mem_size = ram;
3310 mem_cntl &= ~(0xff << 8);
3311 mem_cntl |= (mem_addr_mapping & 0xff) << 8;
3312 WREG32(RADEON_MEM_CNTL, mem_cntl);
3313 RREG32(RADEON_MEM_CNTL);
3314
3315 /* sdram reset ? */
3316
3317 /* something like this???? */
3318 while (ram--) {
3319 addr = ram * 1024 * 1024;
3320 /* write to each page */
Daniel Vetter2ef9bdf2012-12-02 14:02:51 +01003321 WREG32_IDX((addr) | RADEON_MM_APER, 0xdeadbeef);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003322 /* read back and verify */
Daniel Vetter2ef9bdf2012-12-02 14:02:51 +01003323 if (RREG32_IDX((addr) | RADEON_MM_APER) != 0xdeadbeef)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003324 return 0;
3325 }
3326
3327 return mem_size;
3328}
3329
3330static void combios_write_ram_size(struct drm_device *dev)
3331{
3332 struct radeon_device *rdev = dev->dev_private;
3333 uint8_t rev;
3334 uint16_t offset;
3335 uint32_t mem_size = 0;
3336 uint32_t mem_cntl = 0;
3337
3338 /* should do something smarter here I guess... */
3339 if (rdev->flags & RADEON_IS_IGP)
3340 return;
3341
3342 /* first check detected mem table */
3343 offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
3344 if (offset) {
3345 rev = RBIOS8(offset);
3346 if (rev < 3) {
3347 mem_cntl = RBIOS32(offset + 1);
3348 mem_size = RBIOS16(offset + 5);
Alex Deucher4ce91982010-06-30 12:13:55 -04003349 if ((rdev->family < CHIP_R200) &&
3350 !ASIC_IS_RN50(rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003351 WREG32(RADEON_MEM_CNTL, mem_cntl);
3352 }
3353 }
3354
3355 if (!mem_size) {
3356 offset =
3357 combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
3358 if (offset) {
3359 rev = RBIOS8(offset - 1);
3360 if (rev < 1) {
Alex Deucher4ce91982010-06-30 12:13:55 -04003361 if ((rdev->family < CHIP_R200)
3362 && !ASIC_IS_RN50(rdev)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003363 int ram = 0;
3364 int mem_addr_mapping = 0;
3365
3366 while (RBIOS8(offset)) {
3367 ram = RBIOS8(offset);
3368 mem_addr_mapping =
3369 RBIOS8(offset + 1);
3370 if (mem_addr_mapping != 0x25)
3371 ram *= 2;
3372 mem_size =
3373 combios_detect_ram(dev, ram,
3374 mem_addr_mapping);
3375 if (mem_size)
3376 break;
3377 offset += 2;
3378 }
3379 } else
3380 mem_size = RBIOS8(offset);
3381 } else {
3382 mem_size = RBIOS8(offset);
3383 mem_size *= 2; /* convert to MB */
3384 }
3385 }
3386 }
3387
3388 mem_size *= (1024 * 1024); /* convert to bytes */
3389 WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
3390}
3391
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003392void radeon_combios_asic_init(struct drm_device *dev)
3393{
3394 struct radeon_device *rdev = dev->dev_private;
3395 uint16_t table;
3396
3397 /* port hardcoded mac stuff from radeonfb */
3398 if (rdev->bios == NULL)
3399 return;
3400
3401 /* ASIC INIT 1 */
3402 table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
3403 if (table)
3404 combios_parse_mmio_table(dev, table);
3405
3406 /* PLL INIT */
3407 table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
3408 if (table)
3409 combios_parse_pll_table(dev, table);
3410
3411 /* ASIC INIT 2 */
3412 table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
3413 if (table)
3414 combios_parse_mmio_table(dev, table);
3415
3416 if (!(rdev->flags & RADEON_IS_IGP)) {
3417 /* ASIC INIT 4 */
3418 table =
3419 combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
3420 if (table)
3421 combios_parse_mmio_table(dev, table);
3422
3423 /* RAM RESET */
3424 table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
3425 if (table)
3426 combios_parse_ram_reset_table(dev, table);
3427
3428 /* ASIC INIT 3 */
3429 table =
3430 combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
3431 if (table)
3432 combios_parse_mmio_table(dev, table);
3433
3434 /* write CONFIG_MEMSIZE */
3435 combios_write_ram_size(dev);
3436 }
3437
Dave Airlie580b4ff2010-06-30 13:26:11 +10003438 /* quirk for rs4xx HP nx6125 laptop to make it resume
3439 * - it hangs on resume inside the dynclk 1 table.
3440 */
3441 if (rdev->family == CHIP_RS480 &&
3442 rdev->pdev->subsystem_vendor == 0x103c &&
3443 rdev->pdev->subsystem_device == 0x308b)
3444 return;
3445
Alex Deucher52fa2bb2010-07-21 23:54:35 -04003446 /* quirk for rs4xx HP dv5000 laptop to make it resume
3447 * - it hangs on resume inside the dynclk 1 table.
3448 */
3449 if (rdev->family == CHIP_RS480 &&
3450 rdev->pdev->subsystem_vendor == 0x103c &&
3451 rdev->pdev->subsystem_device == 0x30a4)
3452 return;
3453
Alex Deucher302a8e82011-08-29 14:55:25 +00003454 /* quirk for rs4xx Compaq Presario V5245EU laptop to make it resume
3455 * - it hangs on resume inside the dynclk 1 table.
3456 */
3457 if (rdev->family == CHIP_RS480 &&
3458 rdev->pdev->subsystem_vendor == 0x103c &&
3459 rdev->pdev->subsystem_device == 0x30ae)
3460 return;
3461
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003462 /* DYN CLK 1 */
3463 table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
3464 if (table)
3465 combios_parse_pll_table(dev, table);
3466
3467}
3468
3469void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
3470{
3471 struct radeon_device *rdev = dev->dev_private;
3472 uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
3473
3474 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
3475 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3476 bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
3477
3478 /* let the bios control the backlight */
3479 bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
3480
3481 /* tell the bios not to handle mode switching */
3482 bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
3483 RADEON_ACC_MODE_CHANGE);
3484
3485 /* tell the bios a driver is loaded */
3486 bios_7_scratch |= RADEON_DRV_LOADED;
3487
3488 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
3489 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3490 WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
3491}
3492
3493void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
3494{
3495 struct drm_device *dev = encoder->dev;
3496 struct radeon_device *rdev = dev->dev_private;
3497 uint32_t bios_6_scratch;
3498
3499 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3500
3501 if (lock)
3502 bios_6_scratch |= RADEON_DRIVER_CRITICAL;
3503 else
3504 bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
3505
3506 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3507}
3508
3509void
3510radeon_combios_connected_scratch_regs(struct drm_connector *connector,
3511 struct drm_encoder *encoder,
3512 bool connected)
3513{
3514 struct drm_device *dev = connector->dev;
3515 struct radeon_device *rdev = dev->dev_private;
3516 struct radeon_connector *radeon_connector =
3517 to_radeon_connector(connector);
3518 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3519 uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
3520 uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
3521
3522 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
3523 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
3524 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003525 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003526 /* fix me */
3527 bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
3528 /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
3529 bios_5_scratch |= RADEON_TV1_ON;
3530 bios_5_scratch |= RADEON_ACC_REQ_TV1;
3531 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003532 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003533 bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
3534 bios_5_scratch &= ~RADEON_TV1_ON;
3535 bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
3536 }
3537 }
3538 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
3539 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
3540 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003541 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003542 bios_4_scratch |= RADEON_LCD1_ATTACHED;
3543 bios_5_scratch |= RADEON_LCD1_ON;
3544 bios_5_scratch |= RADEON_ACC_REQ_LCD1;
3545 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003546 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003547 bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
3548 bios_5_scratch &= ~RADEON_LCD1_ON;
3549 bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
3550 }
3551 }
3552 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
3553 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
3554 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003555 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003556 bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
3557 bios_5_scratch |= RADEON_CRT1_ON;
3558 bios_5_scratch |= RADEON_ACC_REQ_CRT1;
3559 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003560 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003561 bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
3562 bios_5_scratch &= ~RADEON_CRT1_ON;
3563 bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
3564 }
3565 }
3566 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
3567 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
3568 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003569 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003570 bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
3571 bios_5_scratch |= RADEON_CRT2_ON;
3572 bios_5_scratch |= RADEON_ACC_REQ_CRT2;
3573 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003574 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003575 bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
3576 bios_5_scratch &= ~RADEON_CRT2_ON;
3577 bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
3578 }
3579 }
3580 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
3581 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
3582 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003583 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003584 bios_4_scratch |= RADEON_DFP1_ATTACHED;
3585 bios_5_scratch |= RADEON_DFP1_ON;
3586 bios_5_scratch |= RADEON_ACC_REQ_DFP1;
3587 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003588 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003589 bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
3590 bios_5_scratch &= ~RADEON_DFP1_ON;
3591 bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
3592 }
3593 }
3594 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
3595 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
3596 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003597 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003598 bios_4_scratch |= RADEON_DFP2_ATTACHED;
3599 bios_5_scratch |= RADEON_DFP2_ON;
3600 bios_5_scratch |= RADEON_ACC_REQ_DFP2;
3601 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003602 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003603 bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
3604 bios_5_scratch &= ~RADEON_DFP2_ON;
3605 bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
3606 }
3607 }
3608 WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
3609 WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
3610}
3611
3612void
3613radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
3614{
3615 struct drm_device *dev = encoder->dev;
3616 struct radeon_device *rdev = dev->dev_private;
3617 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3618 uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
3619
3620 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
3621 bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
3622 bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
3623 }
3624 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3625 bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
3626 bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
3627 }
3628 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3629 bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
3630 bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
3631 }
3632 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3633 bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
3634 bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
3635 }
3636 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3637 bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
3638 bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
3639 }
3640 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3641 bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
3642 bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
3643 }
3644 WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
3645}
3646
3647void
3648radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
3649{
3650 struct drm_device *dev = encoder->dev;
3651 struct radeon_device *rdev = dev->dev_private;
3652 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3653 uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3654
3655 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
3656 if (on)
3657 bios_6_scratch |= RADEON_TV_DPMS_ON;
3658 else
3659 bios_6_scratch &= ~RADEON_TV_DPMS_ON;
3660 }
3661 if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
3662 if (on)
3663 bios_6_scratch |= RADEON_CRT_DPMS_ON;
3664 else
3665 bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
3666 }
3667 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
3668 if (on)
3669 bios_6_scratch |= RADEON_LCD_DPMS_ON;
3670 else
3671 bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
3672 }
3673 if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
3674 if (on)
3675 bios_6_scratch |= RADEON_DFP_DPMS_ON;
3676 else
3677 bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
3678 }
3679 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3680}