blob: 485f82c9929d0e6e9b428ebf9ff33699cec35bf7 [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 Deucher03ed8cf2013-07-19 17:44:43 -0400968 /* if the values are zeros, use the table */
969 if ((dac == 0) || (bg == 0))
970 found = 0;
971 else
Alex Deucher3a89b4a2010-04-06 12:35:26 -0400972 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200973 }
974
Alex Deuchere8fc4132013-02-27 12:01:58 -0500975 /* quirks */
Ondrej Zaryf7929f32013-07-19 21:08:48 +0200976 /* Radeon 7000 (RV100) */
977 if (((dev->pdev->device == 0x5159) &&
Alex Deuchere8fc4132013-02-27 12:01:58 -0500978 (dev->pdev->subsystem_vendor == 0x174B) &&
Ondrej Zaryf7929f32013-07-19 21:08:48 +0200979 (dev->pdev->subsystem_device == 0x7c28)) ||
980 /* Radeon 9100 (R200) */
981 ((dev->pdev->device == 0x514D) &&
982 (dev->pdev->subsystem_vendor == 0x174B) &&
983 (dev->pdev->subsystem_device == 0x7149))) {
Alex Deuchere8fc4132013-02-27 12:01:58 -0500984 /* vbios value is bad, use the default */
985 found = 0;
986 }
987
Alex Deucher246263c2009-12-29 12:09:17 -0500988 if (!found) /* fallback to defaults */
989 radeon_legacy_get_primary_dac_info_from_table(rdev, p_dac);
990
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200991 return p_dac;
992}
993
Alex Deucherd79766f2009-12-17 19:00:29 -0500994enum radeon_tv_std
995radeon_combios_get_tv_info(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200996{
Alex Deucherd79766f2009-12-17 19:00:29 -0500997 struct drm_device *dev = rdev->ddev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200998 uint16_t tv_info;
999 enum radeon_tv_std tv_std = TV_STD_NTSC;
1000
1001 tv_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
1002 if (tv_info) {
1003 if (RBIOS8(tv_info + 6) == 'T') {
1004 switch (RBIOS8(tv_info + 7) & 0xf) {
1005 case 1:
1006 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001007 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001008 break;
1009 case 2:
1010 tv_std = TV_STD_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -04001011 DRM_DEBUG_KMS("Default TV standard: PAL\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001012 break;
1013 case 3:
1014 tv_std = TV_STD_PAL_M;
Alex Deucher40f76d82010-10-07 22:38:42 -04001015 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001016 break;
1017 case 4:
1018 tv_std = TV_STD_PAL_60;
Alex Deucher40f76d82010-10-07 22:38:42 -04001019 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001020 break;
1021 case 5:
1022 tv_std = TV_STD_NTSC_J;
Alex Deucher40f76d82010-10-07 22:38:42 -04001023 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001024 break;
1025 case 6:
1026 tv_std = TV_STD_SCART_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -04001027 DRM_DEBUG_KMS("Default TV standard: SCART-PAL\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001028 break;
1029 default:
1030 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001031 DRM_DEBUG_KMS
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001032 ("Unknown TV standard; defaulting to NTSC\n");
1033 break;
1034 }
1035
1036 switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) {
1037 case 0:
Alex Deucher40f76d82010-10-07 22:38:42 -04001038 DRM_DEBUG_KMS("29.498928713 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001039 break;
1040 case 1:
Alex Deucher40f76d82010-10-07 22:38:42 -04001041 DRM_DEBUG_KMS("28.636360000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001042 break;
1043 case 2:
Alex Deucher40f76d82010-10-07 22:38:42 -04001044 DRM_DEBUG_KMS("14.318180000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001045 break;
1046 case 3:
Alex Deucher40f76d82010-10-07 22:38:42 -04001047 DRM_DEBUG_KMS("27.000000000 MHz TV ref clk\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001048 break;
1049 default:
1050 break;
1051 }
1052 }
1053 }
1054 return tv_std;
1055}
1056
1057static const uint32_t default_tvdac_adj[CHIP_LAST] = {
1058 0x00000000, /* r100 */
1059 0x00280000, /* rv100 */
1060 0x00000000, /* rs100 */
1061 0x00880000, /* rv200 */
1062 0x00000000, /* rs200 */
1063 0x00000000, /* r200 */
1064 0x00770000, /* rv250 */
1065 0x00290000, /* rs300 */
1066 0x00560000, /* rv280 */
1067 0x00780000, /* r300 */
1068 0x00770000, /* r350 */
1069 0x00780000, /* rv350 */
1070 0x00780000, /* rv380 */
1071 0x01080000, /* r420 */
1072 0x01080000, /* r423 */
1073 0x01080000, /* rv410 */
1074 0x00780000, /* rs400 */
1075 0x00780000, /* rs480 */
1076};
1077
Dave Airlie6a719e02009-08-17 10:19:51 +10001078static void radeon_legacy_get_tv_dac_info_from_table(struct radeon_device *rdev,
1079 struct radeon_encoder_tv_dac *tv_dac)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001080{
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001081 tv_dac->ps2_tvdac_adj = default_tvdac_adj[rdev->family];
1082 if ((rdev->flags & RADEON_IS_MOBILITY) && (rdev->family == CHIP_RV250))
1083 tv_dac->ps2_tvdac_adj = 0x00880000;
1084 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1085 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Dave Airlie6a719e02009-08-17 10:19:51 +10001086 return;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001087}
1088
1089struct radeon_encoder_tv_dac *radeon_combios_get_tv_dac_info(struct
1090 radeon_encoder
1091 *encoder)
1092{
1093 struct drm_device *dev = encoder->base.dev;
1094 struct radeon_device *rdev = dev->dev_private;
1095 uint16_t dac_info;
1096 uint8_t rev, bg, dac;
1097 struct radeon_encoder_tv_dac *tv_dac = NULL;
Dave Airlie6a719e02009-08-17 10:19:51 +10001098 int found = 0;
1099
1100 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1101 if (!tv_dac)
1102 return NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001103
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001104 /* first check TV table */
1105 dac_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
1106 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001107 rev = RBIOS8(dac_info + 0x3);
1108 if (rev > 4) {
1109 bg = RBIOS8(dac_info + 0xc) & 0xf;
1110 dac = RBIOS8(dac_info + 0xd) & 0xf;
1111 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1112
1113 bg = RBIOS8(dac_info + 0xe) & 0xf;
1114 dac = RBIOS8(dac_info + 0xf) & 0xf;
1115 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1116
1117 bg = RBIOS8(dac_info + 0x10) & 0xf;
1118 dac = RBIOS8(dac_info + 0x11) & 0xf;
1119 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001120 /* if the values are all zeros, use the table */
1121 if (tv_dac->ps2_tvdac_adj)
1122 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001123 } else if (rev > 1) {
1124 bg = RBIOS8(dac_info + 0xc) & 0xf;
1125 dac = (RBIOS8(dac_info + 0xc) >> 4) & 0xf;
1126 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1127
1128 bg = RBIOS8(dac_info + 0xd) & 0xf;
1129 dac = (RBIOS8(dac_info + 0xd) >> 4) & 0xf;
1130 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1131
1132 bg = RBIOS8(dac_info + 0xe) & 0xf;
1133 dac = (RBIOS8(dac_info + 0xe) >> 4) & 0xf;
1134 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001135 /* if the values are all zeros, use the table */
1136 if (tv_dac->ps2_tvdac_adj)
1137 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001138 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001139 tv_dac->tv_std = radeon_combios_get_tv_info(rdev);
Dave Airlie6a719e02009-08-17 10:19:51 +10001140 }
1141 if (!found) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001142 /* then check CRT table */
1143 dac_info =
1144 combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
1145 if (dac_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001146 rev = RBIOS8(dac_info) & 0x3;
1147 if (rev < 2) {
1148 bg = RBIOS8(dac_info + 0x3) & 0xf;
1149 dac = (RBIOS8(dac_info + 0x3) >> 4) & 0xf;
1150 tv_dac->ps2_tvdac_adj =
1151 (bg << 16) | (dac << 20);
1152 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1153 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001154 /* if the values are all zeros, use the table */
1155 if (tv_dac->ps2_tvdac_adj)
1156 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001157 } else {
1158 bg = RBIOS8(dac_info + 0x4) & 0xf;
1159 dac = RBIOS8(dac_info + 0x5) & 0xf;
1160 tv_dac->ps2_tvdac_adj =
1161 (bg << 16) | (dac << 20);
1162 tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
1163 tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
Alex Deucher3a89b4a2010-04-06 12:35:26 -04001164 /* if the values are all zeros, use the table */
1165 if (tv_dac->ps2_tvdac_adj)
1166 found = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001167 }
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001168 } else {
1169 DRM_INFO("No TV DAC info found in BIOS\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001170 }
1171 }
1172
Dave Airlie6a719e02009-08-17 10:19:51 +10001173 if (!found) /* fallback to defaults */
1174 radeon_legacy_get_tv_dac_info_from_table(rdev, tv_dac);
1175
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001176 return tv_dac;
1177}
1178
1179static struct radeon_encoder_lvds *radeon_legacy_get_lvds_info_from_regs(struct
1180 radeon_device
1181 *rdev)
1182{
1183 struct radeon_encoder_lvds *lvds = NULL;
1184 uint32_t fp_vert_stretch, fp_horz_stretch;
1185 uint32_t ppll_div_sel, ppll_val;
Michel Dänzer8b5c7442009-06-17 18:28:38 +02001186 uint32_t lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001187
1188 lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
1189
1190 if (!lvds)
1191 return NULL;
1192
1193 fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH);
1194 fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH);
1195
Michel Dänzer8b5c7442009-06-17 18:28:38 +02001196 /* These should be fail-safe defaults, fingers crossed */
1197 lvds->panel_pwr_delay = 200;
1198 lvds->panel_vcc_delay = 2000;
1199
1200 lvds->lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
1201 lvds->panel_digon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) & 0xf;
1202 lvds->panel_blon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY2_SHIFT) & 0xf;
1203
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001204 if (fp_vert_stretch & RADEON_VERT_STRETCH_ENABLE)
Alex Deucherde2103e2009-10-09 15:14:30 -04001205 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001206 ((fp_vert_stretch & RADEON_VERT_PANEL_SIZE) >>
1207 RADEON_VERT_PANEL_SHIFT) + 1;
1208 else
Alex Deucherde2103e2009-10-09 15:14:30 -04001209 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001210 (RREG32(RADEON_CRTC_V_TOTAL_DISP) >> 16) + 1;
1211
1212 if (fp_horz_stretch & RADEON_HORZ_STRETCH_ENABLE)
Alex Deucherde2103e2009-10-09 15:14:30 -04001213 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001214 (((fp_horz_stretch & RADEON_HORZ_PANEL_SIZE) >>
1215 RADEON_HORZ_PANEL_SHIFT) + 1) * 8;
1216 else
Alex Deucherde2103e2009-10-09 15:14:30 -04001217 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001218 ((RREG32(RADEON_CRTC_H_TOTAL_DISP) >> 16) + 1) * 8;
1219
Alex Deucherde2103e2009-10-09 15:14:30 -04001220 if ((lvds->native_mode.hdisplay < 640) ||
1221 (lvds->native_mode.vdisplay < 480)) {
1222 lvds->native_mode.hdisplay = 640;
1223 lvds->native_mode.vdisplay = 480;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001224 }
1225
1226 ppll_div_sel = RREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3;
1227 ppll_val = RREG32_PLL(RADEON_PPLL_DIV_0 + ppll_div_sel);
1228 if ((ppll_val & 0x000707ff) == 0x1bb)
1229 lvds->use_bios_dividers = false;
1230 else {
1231 lvds->panel_ref_divider =
1232 RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
1233 lvds->panel_post_divider = (ppll_val >> 16) & 0x7;
1234 lvds->panel_fb_divider = ppll_val & 0x7ff;
1235
1236 if ((lvds->panel_ref_divider != 0) &&
1237 (lvds->panel_fb_divider > 3))
1238 lvds->use_bios_dividers = true;
1239 }
1240 lvds->panel_vcc_delay = 200;
1241
1242 DRM_INFO("Panel info derived from registers\n");
Alex Deucherde2103e2009-10-09 15:14:30 -04001243 DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
1244 lvds->native_mode.vdisplay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001245
1246 return lvds;
1247}
1248
1249struct radeon_encoder_lvds *radeon_combios_get_lvds_info(struct radeon_encoder
1250 *encoder)
1251{
1252 struct drm_device *dev = encoder->base.dev;
1253 struct radeon_device *rdev = dev->dev_private;
1254 uint16_t lcd_info;
1255 uint32_t panel_setup;
1256 char stmp[30];
1257 int tmp, i;
1258 struct radeon_encoder_lvds *lvds = NULL;
1259
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001260 lcd_info = combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
1261
1262 if (lcd_info) {
1263 lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
1264
1265 if (!lvds)
1266 return NULL;
1267
1268 for (i = 0; i < 24; i++)
1269 stmp[i] = RBIOS8(lcd_info + i + 1);
1270 stmp[24] = 0;
1271
1272 DRM_INFO("Panel ID String: %s\n", stmp);
1273
Alex Deucherde2103e2009-10-09 15:14:30 -04001274 lvds->native_mode.hdisplay = RBIOS16(lcd_info + 0x19);
1275 lvds->native_mode.vdisplay = RBIOS16(lcd_info + 0x1b);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001276
Alex Deucherde2103e2009-10-09 15:14:30 -04001277 DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
1278 lvds->native_mode.vdisplay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001279
1280 lvds->panel_vcc_delay = RBIOS16(lcd_info + 0x2c);
Andrew Morton94cf6432010-02-02 14:40:29 -08001281 lvds->panel_vcc_delay = min_t(u16, lvds->panel_vcc_delay, 2000);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001282
1283 lvds->panel_pwr_delay = RBIOS8(lcd_info + 0x24);
1284 lvds->panel_digon_delay = RBIOS16(lcd_info + 0x38) & 0xf;
1285 lvds->panel_blon_delay = (RBIOS16(lcd_info + 0x38) >> 4) & 0xf;
1286
1287 lvds->panel_ref_divider = RBIOS16(lcd_info + 0x2e);
1288 lvds->panel_post_divider = RBIOS8(lcd_info + 0x30);
1289 lvds->panel_fb_divider = RBIOS16(lcd_info + 0x31);
1290 if ((lvds->panel_ref_divider != 0) &&
1291 (lvds->panel_fb_divider > 3))
1292 lvds->use_bios_dividers = true;
1293
1294 panel_setup = RBIOS32(lcd_info + 0x39);
1295 lvds->lvds_gen_cntl = 0xff00;
1296 if (panel_setup & 0x1)
1297 lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_FORMAT;
1298
1299 if ((panel_setup >> 4) & 0x1)
1300 lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_TYPE;
1301
1302 switch ((panel_setup >> 8) & 0x7) {
1303 case 0:
1304 lvds->lvds_gen_cntl |= RADEON_LVDS_NO_FM;
1305 break;
1306 case 1:
1307 lvds->lvds_gen_cntl |= RADEON_LVDS_2_GREY;
1308 break;
1309 case 2:
1310 lvds->lvds_gen_cntl |= RADEON_LVDS_4_GREY;
1311 break;
1312 default:
1313 break;
1314 }
1315
1316 if ((panel_setup >> 16) & 0x1)
1317 lvds->lvds_gen_cntl |= RADEON_LVDS_FP_POL_LOW;
1318
1319 if ((panel_setup >> 17) & 0x1)
1320 lvds->lvds_gen_cntl |= RADEON_LVDS_LP_POL_LOW;
1321
1322 if ((panel_setup >> 18) & 0x1)
1323 lvds->lvds_gen_cntl |= RADEON_LVDS_DTM_POL_LOW;
1324
1325 if ((panel_setup >> 23) & 0x1)
1326 lvds->lvds_gen_cntl |= RADEON_LVDS_BL_CLK_SEL;
1327
1328 lvds->lvds_gen_cntl |= (panel_setup & 0xf0000000);
1329
1330 for (i = 0; i < 32; i++) {
1331 tmp = RBIOS16(lcd_info + 64 + i * 2);
1332 if (tmp == 0)
1333 break;
1334
Alex Deucherde2103e2009-10-09 15:14:30 -04001335 if ((RBIOS16(tmp) == lvds->native_mode.hdisplay) &&
Alex Deucher68b61a72010-05-18 00:30:05 -04001336 (RBIOS16(tmp + 2) == lvds->native_mode.vdisplay)) {
1337 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1338 (RBIOS16(tmp + 17) - RBIOS16(tmp + 19)) * 8;
1339 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1340 (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) - 1) * 8;
1341 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1342 (RBIOS8(tmp + 23) * 8);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001343
Alex Deucher68b61a72010-05-18 00:30:05 -04001344 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1345 (RBIOS16(tmp + 24) - RBIOS16(tmp + 26));
1346 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1347 ((RBIOS16(tmp + 28) & 0x7ff) - RBIOS16(tmp + 26));
1348 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1349 ((RBIOS16(tmp + 28) & 0xf800) >> 11);
Alex Deucherde2103e2009-10-09 15:14:30 -04001350
1351 lvds->native_mode.clock = RBIOS16(tmp + 9) * 10;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001352 lvds->native_mode.flags = 0;
Alex Deucherde2103e2009-10-09 15:14:30 -04001353 /* set crtc values */
1354 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
1355
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001356 }
1357 }
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001358 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001359 DRM_INFO("No panel info found in BIOS\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +02001360 lvds = radeon_legacy_get_lvds_info_from_regs(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001361 }
Michel Dänzer03047cd2010-02-10 11:05:11 +01001362
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +02001363 if (lvds)
1364 encoder->native_mode = lvds->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001365 return lvds;
1366}
1367
1368static const struct radeon_tmds_pll default_tmds_pll[CHIP_LAST][4] = {
1369 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R100 */
1370 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV100 */
1371 {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS100 */
1372 {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RV200 */
1373 {{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_RS200 */
1374 {{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}}, /* CHIP_R200 */
1375 {{15500, 0x81b}, {0xffffffff, 0x83f}, {0, 0}, {0, 0}}, /* CHIP_RV250 */
1376 {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RS300 */
1377 {{13000, 0x400f4}, {15000, 0x400f7}, {0xffffffff, 0x40111}, {0, 0}}, /* CHIP_RV280 */
1378 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R300 */
1379 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R350 */
1380 {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV350 */
1381 {{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}}, /* CHIP_RV380 */
1382 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R420 */
1383 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_R423 */
1384 {{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}}, /* CHIP_RV410 */
Alex Deucherfcec5702009-11-10 21:25:07 -05001385 { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS400 */
1386 { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* CHIP_RS480 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001387};
1388
Dave Airlie445282d2009-09-09 17:40:54 +10001389bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
1390 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001391{
Dave Airlie445282d2009-09-09 17:40:54 +10001392 struct drm_device *dev = encoder->base.dev;
1393 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001394 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001395
1396 for (i = 0; i < 4; i++) {
1397 tmds->tmds_pll[i].value =
Dave Airlie445282d2009-09-09 17:40:54 +10001398 default_tmds_pll[rdev->family][i].value;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001399 tmds->tmds_pll[i].freq = default_tmds_pll[rdev->family][i].freq;
1400 }
1401
Dave Airlie445282d2009-09-09 17:40:54 +10001402 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001403}
1404
Dave Airlie445282d2009-09-09 17:40:54 +10001405bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
1406 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001407{
1408 struct drm_device *dev = encoder->base.dev;
1409 struct radeon_device *rdev = dev->dev_private;
1410 uint16_t tmds_info;
1411 int i, n;
1412 uint8_t ver;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001413
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001414 tmds_info = combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
1415
1416 if (tmds_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001417 ver = RBIOS8(tmds_info);
Alex Deucher40f76d82010-10-07 22:38:42 -04001418 DRM_DEBUG_KMS("DFP table revision: %d\n", ver);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001419 if (ver == 3) {
1420 n = RBIOS8(tmds_info + 5) + 1;
1421 if (n > 4)
1422 n = 4;
1423 for (i = 0; i < n; i++) {
1424 tmds->tmds_pll[i].value =
1425 RBIOS32(tmds_info + i * 10 + 0x08);
1426 tmds->tmds_pll[i].freq =
1427 RBIOS16(tmds_info + i * 10 + 0x10);
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001428 DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001429 tmds->tmds_pll[i].freq,
1430 tmds->tmds_pll[i].value);
1431 }
1432 } else if (ver == 4) {
1433 int stride = 0;
1434 n = RBIOS8(tmds_info + 5) + 1;
1435 if (n > 4)
1436 n = 4;
1437 for (i = 0; i < n; i++) {
1438 tmds->tmds_pll[i].value =
1439 RBIOS32(tmds_info + stride + 0x08);
1440 tmds->tmds_pll[i].freq =
1441 RBIOS16(tmds_info + stride + 0x10);
1442 if (i == 0)
1443 stride += 10;
1444 else
1445 stride += 6;
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001446 DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001447 tmds->tmds_pll[i].freq,
1448 tmds->tmds_pll[i].value);
1449 }
1450 }
Alex Deucherfcec5702009-11-10 21:25:07 -05001451 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001452 DRM_INFO("No TMDS info found in BIOS\n");
Alex Deucherfcec5702009-11-10 21:25:07 -05001453 return false;
1454 }
Dave Airlie445282d2009-09-09 17:40:54 +10001455 return true;
1456}
1457
Alex Deucherfcec5702009-11-10 21:25:07 -05001458bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
1459 struct radeon_encoder_ext_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001460{
1461 struct drm_device *dev = encoder->base.dev;
1462 struct radeon_device *rdev = dev->dev_private;
Alex Deucherfcec5702009-11-10 21:25:07 -05001463 struct radeon_i2c_bus_rec i2c_bus;
1464
1465 /* default for macs */
Alex Deucher179e8072010-08-05 21:21:17 -04001466 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
Alex Deucherf376b942010-08-05 21:21:16 -04001467 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucherfcec5702009-11-10 21:25:07 -05001468
1469 /* XXX some macs have duallink chips */
1470 switch (rdev->mode_info.connector_table) {
1471 case CT_POWERBOOK_EXTERNAL:
1472 case CT_MINI_EXTERNAL:
1473 default:
1474 tmds->dvo_chip = DVO_SIL164;
1475 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1476 break;
1477 }
1478
1479 return true;
1480}
1481
1482bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
1483 struct radeon_encoder_ext_tmds *tmds)
1484{
1485 struct drm_device *dev = encoder->base.dev;
1486 struct radeon_device *rdev = dev->dev_private;
1487 uint16_t offset;
Alex Deucher179e8072010-08-05 21:21:17 -04001488 uint8_t ver;
Alex Deucherfcec5702009-11-10 21:25:07 -05001489 enum radeon_combios_ddc gpio;
1490 struct radeon_i2c_bus_rec i2c_bus;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001491
Alex Deucherfcec5702009-11-10 21:25:07 -05001492 tmds->i2c_bus = NULL;
1493 if (rdev->flags & RADEON_IS_IGP) {
Alex Deucher179e8072010-08-05 21:21:17 -04001494 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1495 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1496 tmds->dvo_chip = DVO_SIL164;
1497 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
Alex Deucherfcec5702009-11-10 21:25:07 -05001498 } else {
1499 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
1500 if (offset) {
1501 ver = RBIOS8(offset);
Alex Deucher40f76d82010-10-07 22:38:42 -04001502 DRM_DEBUG_KMS("External TMDS Table revision: %d\n", ver);
Alex Deucherfcec5702009-11-10 21:25:07 -05001503 tmds->slave_addr = RBIOS8(offset + 4 + 2);
1504 tmds->slave_addr >>= 1; /* 7 bit addressing */
1505 gpio = RBIOS8(offset + 4 + 3);
Alex Deucher179e8072010-08-05 21:21:17 -04001506 if (gpio == DDC_LCD) {
1507 /* MM i2c */
Alex Deucher40bacf12009-12-23 03:23:21 -05001508 i2c_bus.valid = true;
1509 i2c_bus.hw_capable = true;
1510 i2c_bus.mm_i2c = true;
Alex Deucher179e8072010-08-05 21:21:17 -04001511 i2c_bus.i2c_id = 0xa0;
1512 } else
1513 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
1514 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucherfcec5702009-11-10 21:25:07 -05001515 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001516 }
Alex Deucherfcec5702009-11-10 21:25:07 -05001517
1518 if (!tmds->i2c_bus) {
1519 DRM_INFO("No valid Ext TMDS info found in BIOS\n");
1520 return false;
1521 }
1522
1523 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001524}
1525
1526bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1527{
1528 struct radeon_device *rdev = dev->dev_private;
1529 struct radeon_i2c_bus_rec ddc_i2c;
Alex Deuchereed45b32009-12-04 14:45:27 -05001530 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001531
1532 rdev->mode_info.connector_table = radeon_connector_table;
1533 if (rdev->mode_info.connector_table == CT_NONE) {
1534#ifdef CONFIG_PPC_PMAC
Grant Likely71a157e2010-02-01 21:34:14 -07001535 if (of_machine_is_compatible("PowerBook3,3")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001536 /* powerbook with VGA */
1537 rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
Grant Likely71a157e2010-02-01 21:34:14 -07001538 } else if (of_machine_is_compatible("PowerBook3,4") ||
1539 of_machine_is_compatible("PowerBook3,5")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001540 /* powerbook with internal tmds */
1541 rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001542 } else if (of_machine_is_compatible("PowerBook5,1") ||
1543 of_machine_is_compatible("PowerBook5,2") ||
1544 of_machine_is_compatible("PowerBook5,3") ||
1545 of_machine_is_compatible("PowerBook5,4") ||
1546 of_machine_is_compatible("PowerBook5,5")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001547 /* powerbook with external single link tmds (sil164) */
1548 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001549 } else if (of_machine_is_compatible("PowerBook5,6")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001550 /* powerbook with external dual or single link tmds */
1551 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001552 } else if (of_machine_is_compatible("PowerBook5,7") ||
1553 of_machine_is_compatible("PowerBook5,8") ||
1554 of_machine_is_compatible("PowerBook5,9")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001555 /* PowerBook6,2 ? */
1556 /* powerbook with external dual link tmds (sil1178?) */
1557 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001558 } else if (of_machine_is_compatible("PowerBook4,1") ||
1559 of_machine_is_compatible("PowerBook4,2") ||
1560 of_machine_is_compatible("PowerBook4,3") ||
1561 of_machine_is_compatible("PowerBook6,3") ||
1562 of_machine_is_compatible("PowerBook6,5") ||
1563 of_machine_is_compatible("PowerBook6,7")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001564 /* ibook */
1565 rdev->mode_info.connector_table = CT_IBOOK;
Alex Deuchercafa59b2012-12-20 16:35:47 -05001566 } else if (of_machine_is_compatible("PowerMac3,5")) {
1567 /* PowerMac G4 Silver radeon 7500 */
1568 rdev->mode_info.connector_table = CT_MAC_G4_SILVER;
Grant Likely71a157e2010-02-01 21:34:14 -07001569 } else if (of_machine_is_compatible("PowerMac4,4")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001570 /* emac */
1571 rdev->mode_info.connector_table = CT_EMAC;
Grant Likely71a157e2010-02-01 21:34:14 -07001572 } else if (of_machine_is_compatible("PowerMac10,1")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001573 /* mini with internal tmds */
1574 rdev->mode_info.connector_table = CT_MINI_INTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001575 } else if (of_machine_is_compatible("PowerMac10,2")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001576 /* mini with external tmds */
1577 rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
Grant Likely71a157e2010-02-01 21:34:14 -07001578 } else if (of_machine_is_compatible("PowerMac12,1")) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001579 /* PowerMac8,1 ? */
1580 /* imac g5 isight */
1581 rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
Alex Deucheraa74fbb2010-09-07 14:41:30 -04001582 } else if ((rdev->pdev->device == 0x4a48) &&
1583 (rdev->pdev->subsystem_vendor == 0x1002) &&
1584 (rdev->pdev->subsystem_device == 0x4a48)) {
1585 /* Mac X800 */
1586 rdev->mode_info.connector_table = CT_MAC_X800;
Alex Deucher7c88d2b2011-06-14 15:27:38 +00001587 } else if ((of_machine_is_compatible("PowerMac7,2") ||
1588 of_machine_is_compatible("PowerMac7,3")) &&
1589 (rdev->pdev->device == 0x4150) &&
1590 (rdev->pdev->subsystem_vendor == 0x1002) &&
1591 (rdev->pdev->subsystem_device == 0x4150)) {
1592 /* Mac G5 tower 9600 */
Alex Deucher9fad3212011-02-07 13:15:28 -05001593 rdev->mode_info.connector_table = CT_MAC_G5_9600;
Alex Deucher6a556032012-05-02 12:10:21 -04001594 } else if ((rdev->pdev->device == 0x4c66) &&
1595 (rdev->pdev->subsystem_vendor == 0x1002) &&
1596 (rdev->pdev->subsystem_device == 0x4c66)) {
1597 /* SAM440ep RV250 embedded board */
1598 rdev->mode_info.connector_table = CT_SAM440EP;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001599 } else
1600#endif /* CONFIG_PPC_PMAC */
Dave Airlie76a71422010-06-11 01:09:05 -04001601#ifdef CONFIG_PPC64
1602 if (ASIC_IS_RN50(rdev))
1603 rdev->mode_info.connector_table = CT_RN50_POWER;
1604 else
1605#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001606 rdev->mode_info.connector_table = CT_GENERIC;
1607 }
1608
1609 switch (rdev->mode_info.connector_table) {
1610 case CT_GENERIC:
1611 DRM_INFO("Connector Table: %d (generic)\n",
1612 rdev->mode_info.connector_table);
1613 /* these are the most common settings */
1614 if (rdev->flags & RADEON_SINGLE_CRTC) {
1615 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001616 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001617 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001618 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001619 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001620 ATOM_DEVICE_CRT1_SUPPORT,
1621 1),
1622 ATOM_DEVICE_CRT1_SUPPORT);
1623 radeon_add_legacy_connector(dev, 0,
1624 ATOM_DEVICE_CRT1_SUPPORT,
1625 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001626 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001627 CONNECTOR_OBJECT_ID_VGA,
1628 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001629 } else if (rdev->flags & RADEON_IS_MOBILITY) {
1630 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001631 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001632 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001633 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001634 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001635 ATOM_DEVICE_LCD1_SUPPORT,
1636 0),
1637 ATOM_DEVICE_LCD1_SUPPORT);
1638 radeon_add_legacy_connector(dev, 0,
1639 ATOM_DEVICE_LCD1_SUPPORT,
1640 DRM_MODE_CONNECTOR_LVDS,
Alex Deucherb75fad02009-11-05 13:16:01 -05001641 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001642 CONNECTOR_OBJECT_ID_LVDS,
1643 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001644
1645 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001646 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001647 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001648 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001649 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001650 ATOM_DEVICE_CRT1_SUPPORT,
1651 1),
1652 ATOM_DEVICE_CRT1_SUPPORT);
1653 radeon_add_legacy_connector(dev, 1,
1654 ATOM_DEVICE_CRT1_SUPPORT,
1655 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001656 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001657 CONNECTOR_OBJECT_ID_VGA,
1658 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001659 } else {
1660 /* DVI-I - tv dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001661 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001662 hpd.hpd = RADEON_HPD_1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001663 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001664 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001665 ATOM_DEVICE_DFP1_SUPPORT,
1666 0),
1667 ATOM_DEVICE_DFP1_SUPPORT);
1668 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001669 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001670 ATOM_DEVICE_CRT2_SUPPORT,
1671 2),
1672 ATOM_DEVICE_CRT2_SUPPORT);
1673 radeon_add_legacy_connector(dev, 0,
1674 ATOM_DEVICE_DFP1_SUPPORT |
1675 ATOM_DEVICE_CRT2_SUPPORT,
1676 DRM_MODE_CONNECTOR_DVII,
Alex Deucherb75fad02009-11-05 13:16:01 -05001677 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001678 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1679 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001680
1681 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001682 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001683 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001684 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001685 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001686 ATOM_DEVICE_CRT1_SUPPORT,
1687 1),
1688 ATOM_DEVICE_CRT1_SUPPORT);
1689 radeon_add_legacy_connector(dev, 1,
1690 ATOM_DEVICE_CRT1_SUPPORT,
1691 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05001692 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001693 CONNECTOR_OBJECT_ID_VGA,
1694 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001695 }
1696
1697 if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
1698 /* TV - tv dac */
Alex Deuchereed45b32009-12-04 14:45:27 -05001699 ddc_i2c.valid = false;
1700 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001701 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001702 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001703 ATOM_DEVICE_TV1_SUPPORT,
1704 2),
1705 ATOM_DEVICE_TV1_SUPPORT);
1706 radeon_add_legacy_connector(dev, 2,
1707 ATOM_DEVICE_TV1_SUPPORT,
1708 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001709 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001710 CONNECTOR_OBJECT_ID_SVIDEO,
1711 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001712 }
1713 break;
1714 case CT_IBOOK:
1715 DRM_INFO("Connector Table: %d (ibook)\n",
1716 rdev->mode_info.connector_table);
1717 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001718 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001719 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001720 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001721 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001722 ATOM_DEVICE_LCD1_SUPPORT,
1723 0),
1724 ATOM_DEVICE_LCD1_SUPPORT);
1725 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001726 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001727 CONNECTOR_OBJECT_ID_LVDS,
1728 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001729 /* VGA - TV DAC */
Alex Deucher179e8072010-08-05 21:21:17 -04001730 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001731 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001732 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001733 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001734 ATOM_DEVICE_CRT2_SUPPORT,
1735 2),
1736 ATOM_DEVICE_CRT2_SUPPORT);
1737 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001738 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001739 CONNECTOR_OBJECT_ID_VGA,
1740 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001741 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001742 ddc_i2c.valid = false;
1743 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001744 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001745 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001746 ATOM_DEVICE_TV1_SUPPORT,
1747 2),
1748 ATOM_DEVICE_TV1_SUPPORT);
1749 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1750 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001751 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001752 CONNECTOR_OBJECT_ID_SVIDEO,
1753 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001754 break;
1755 case CT_POWERBOOK_EXTERNAL:
1756 DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
1757 rdev->mode_info.connector_table);
1758 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001759 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001760 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001761 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001762 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001763 ATOM_DEVICE_LCD1_SUPPORT,
1764 0),
1765 ATOM_DEVICE_LCD1_SUPPORT);
1766 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001767 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001768 CONNECTOR_OBJECT_ID_LVDS,
1769 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001770 /* DVI-I - primary dac, ext tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001771 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001772 hpd.hpd = RADEON_HPD_2; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001773 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001774 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001775 ATOM_DEVICE_DFP2_SUPPORT,
1776 0),
1777 ATOM_DEVICE_DFP2_SUPPORT);
1778 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001779 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001780 ATOM_DEVICE_CRT1_SUPPORT,
1781 1),
1782 ATOM_DEVICE_CRT1_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05001783 /* XXX some are SL */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001784 radeon_add_legacy_connector(dev, 1,
1785 ATOM_DEVICE_DFP2_SUPPORT |
1786 ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001787 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001788 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
1789 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001790 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001791 ddc_i2c.valid = false;
1792 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001793 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001794 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001795 ATOM_DEVICE_TV1_SUPPORT,
1796 2),
1797 ATOM_DEVICE_TV1_SUPPORT);
1798 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1799 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001800 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001801 CONNECTOR_OBJECT_ID_SVIDEO,
1802 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001803 break;
1804 case CT_POWERBOOK_INTERNAL:
1805 DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
1806 rdev->mode_info.connector_table);
1807 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001808 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001809 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001810 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001811 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001812 ATOM_DEVICE_LCD1_SUPPORT,
1813 0),
1814 ATOM_DEVICE_LCD1_SUPPORT);
1815 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001816 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001817 CONNECTOR_OBJECT_ID_LVDS,
1818 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001819 /* DVI-I - primary dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001820 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001821 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001822 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001823 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001824 ATOM_DEVICE_DFP1_SUPPORT,
1825 0),
1826 ATOM_DEVICE_DFP1_SUPPORT);
1827 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001828 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001829 ATOM_DEVICE_CRT1_SUPPORT,
1830 1),
1831 ATOM_DEVICE_CRT1_SUPPORT);
1832 radeon_add_legacy_connector(dev, 1,
1833 ATOM_DEVICE_DFP1_SUPPORT |
1834 ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001835 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001836 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1837 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001838 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001839 ddc_i2c.valid = false;
1840 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001841 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001842 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001843 ATOM_DEVICE_TV1_SUPPORT,
1844 2),
1845 ATOM_DEVICE_TV1_SUPPORT);
1846 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1847 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001848 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001849 CONNECTOR_OBJECT_ID_SVIDEO,
1850 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001851 break;
1852 case CT_POWERBOOK_VGA:
1853 DRM_INFO("Connector Table: %d (powerbook vga)\n",
1854 rdev->mode_info.connector_table);
1855 /* LVDS */
Alex Deucher179e8072010-08-05 21:21:17 -04001856 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001857 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001858 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001859 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001860 ATOM_DEVICE_LCD1_SUPPORT,
1861 0),
1862 ATOM_DEVICE_LCD1_SUPPORT);
1863 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001864 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001865 CONNECTOR_OBJECT_ID_LVDS,
1866 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001867 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001868 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001869 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001870 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001871 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001872 ATOM_DEVICE_CRT1_SUPPORT,
1873 1),
1874 ATOM_DEVICE_CRT1_SUPPORT);
1875 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001876 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001877 CONNECTOR_OBJECT_ID_VGA,
1878 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001879 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001880 ddc_i2c.valid = false;
1881 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001882 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001883 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001884 ATOM_DEVICE_TV1_SUPPORT,
1885 2),
1886 ATOM_DEVICE_TV1_SUPPORT);
1887 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
1888 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001889 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001890 CONNECTOR_OBJECT_ID_SVIDEO,
1891 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001892 break;
1893 case CT_MINI_EXTERNAL:
1894 DRM_INFO("Connector Table: %d (mini external tmds)\n",
1895 rdev->mode_info.connector_table);
1896 /* DVI-I - tv dac, ext tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001897 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001898 hpd.hpd = RADEON_HPD_2; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001899 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001900 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001901 ATOM_DEVICE_DFP2_SUPPORT,
1902 0),
1903 ATOM_DEVICE_DFP2_SUPPORT);
1904 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001905 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001906 ATOM_DEVICE_CRT2_SUPPORT,
1907 2),
1908 ATOM_DEVICE_CRT2_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05001909 /* XXX are any DL? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001910 radeon_add_legacy_connector(dev, 0,
1911 ATOM_DEVICE_DFP2_SUPPORT |
1912 ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001913 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001914 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1915 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001916 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001917 ddc_i2c.valid = false;
1918 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001919 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001920 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001921 ATOM_DEVICE_TV1_SUPPORT,
1922 2),
1923 ATOM_DEVICE_TV1_SUPPORT);
1924 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
1925 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001926 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001927 CONNECTOR_OBJECT_ID_SVIDEO,
1928 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001929 break;
1930 case CT_MINI_INTERNAL:
1931 DRM_INFO("Connector Table: %d (mini internal tmds)\n",
1932 rdev->mode_info.connector_table);
1933 /* DVI-I - tv dac, int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001934 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001935 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001936 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001937 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001938 ATOM_DEVICE_DFP1_SUPPORT,
1939 0),
1940 ATOM_DEVICE_DFP1_SUPPORT);
1941 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001942 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001943 ATOM_DEVICE_CRT2_SUPPORT,
1944 2),
1945 ATOM_DEVICE_CRT2_SUPPORT);
1946 radeon_add_legacy_connector(dev, 0,
1947 ATOM_DEVICE_DFP1_SUPPORT |
1948 ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001949 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001950 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1951 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001952 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001953 ddc_i2c.valid = false;
1954 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001955 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001956 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001957 ATOM_DEVICE_TV1_SUPPORT,
1958 2),
1959 ATOM_DEVICE_TV1_SUPPORT);
1960 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
1961 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05001962 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001963 CONNECTOR_OBJECT_ID_SVIDEO,
1964 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001965 break;
1966 case CT_IMAC_G5_ISIGHT:
1967 DRM_INFO("Connector Table: %d (imac g5 isight)\n",
1968 rdev->mode_info.connector_table);
1969 /* DVI-D - int tmds */
Alex Deucher179e8072010-08-05 21:21:17 -04001970 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001971 hpd.hpd = RADEON_HPD_1; /* ??? */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001972 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001973 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001974 ATOM_DEVICE_DFP1_SUPPORT,
1975 0),
1976 ATOM_DEVICE_DFP1_SUPPORT);
1977 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001978 DRM_MODE_CONNECTOR_DVID, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001979 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
1980 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001981 /* VGA - tv dac */
Alex Deucher179e8072010-08-05 21:21:17 -04001982 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05001983 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001984 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001985 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001986 ATOM_DEVICE_CRT2_SUPPORT,
1987 2),
1988 ATOM_DEVICE_CRT2_SUPPORT);
1989 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05001990 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05001991 CONNECTOR_OBJECT_ID_VGA,
1992 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001993 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05001994 ddc_i2c.valid = false;
1995 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001996 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001997 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001998 ATOM_DEVICE_TV1_SUPPORT,
1999 2),
2000 ATOM_DEVICE_TV1_SUPPORT);
2001 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
2002 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05002003 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002004 CONNECTOR_OBJECT_ID_SVIDEO,
2005 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002006 break;
2007 case CT_EMAC:
2008 DRM_INFO("Connector Table: %d (emac)\n",
2009 rdev->mode_info.connector_table);
2010 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04002011 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05002012 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002013 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002014 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002015 ATOM_DEVICE_CRT1_SUPPORT,
2016 1),
2017 ATOM_DEVICE_CRT1_SUPPORT);
2018 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05002019 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002020 CONNECTOR_OBJECT_ID_VGA,
2021 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002022 /* VGA - tv dac */
Alex Deucher179e8072010-08-05 21:21:17 -04002023 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05002024 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002025 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002026 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002027 ATOM_DEVICE_CRT2_SUPPORT,
2028 2),
2029 ATOM_DEVICE_CRT2_SUPPORT);
2030 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
Alex Deucherb75fad02009-11-05 13:16:01 -05002031 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002032 CONNECTOR_OBJECT_ID_VGA,
2033 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002034 /* TV - TV DAC */
Alex Deuchereed45b32009-12-04 14:45:27 -05002035 ddc_i2c.valid = false;
2036 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002037 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002038 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002039 ATOM_DEVICE_TV1_SUPPORT,
2040 2),
2041 ATOM_DEVICE_TV1_SUPPORT);
2042 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
2043 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05002044 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002045 CONNECTOR_OBJECT_ID_SVIDEO,
2046 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002047 break;
Dave Airlie76a71422010-06-11 01:09:05 -04002048 case CT_RN50_POWER:
2049 DRM_INFO("Connector Table: %d (rn50-power)\n",
2050 rdev->mode_info.connector_table);
2051 /* VGA - primary dac */
Alex Deucher179e8072010-08-05 21:21:17 -04002052 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Dave Airlie76a71422010-06-11 01:09:05 -04002053 hpd.hpd = RADEON_HPD_NONE;
2054 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002055 radeon_get_encoder_enum(dev,
Dave Airlie76a71422010-06-11 01:09:05 -04002056 ATOM_DEVICE_CRT1_SUPPORT,
2057 1),
2058 ATOM_DEVICE_CRT1_SUPPORT);
2059 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
2060 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
2061 CONNECTOR_OBJECT_ID_VGA,
2062 &hpd);
Alex Deucher179e8072010-08-05 21:21:17 -04002063 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
Dave Airlie76a71422010-06-11 01:09:05 -04002064 hpd.hpd = RADEON_HPD_NONE;
2065 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002066 radeon_get_encoder_enum(dev,
Dave Airlie76a71422010-06-11 01:09:05 -04002067 ATOM_DEVICE_CRT2_SUPPORT,
2068 2),
2069 ATOM_DEVICE_CRT2_SUPPORT);
2070 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
2071 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
2072 CONNECTOR_OBJECT_ID_VGA,
2073 &hpd);
2074 break;
Alex Deucheraa74fbb2010-09-07 14:41:30 -04002075 case CT_MAC_X800:
2076 DRM_INFO("Connector Table: %d (mac x800)\n",
2077 rdev->mode_info.connector_table);
2078 /* DVI - primary dac, internal tmds */
2079 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2080 hpd.hpd = RADEON_HPD_1; /* ??? */
2081 radeon_add_legacy_encoder(dev,
2082 radeon_get_encoder_enum(dev,
2083 ATOM_DEVICE_DFP1_SUPPORT,
2084 0),
2085 ATOM_DEVICE_DFP1_SUPPORT);
2086 radeon_add_legacy_encoder(dev,
2087 radeon_get_encoder_enum(dev,
2088 ATOM_DEVICE_CRT1_SUPPORT,
2089 1),
2090 ATOM_DEVICE_CRT1_SUPPORT);
2091 radeon_add_legacy_connector(dev, 0,
2092 ATOM_DEVICE_DFP1_SUPPORT |
2093 ATOM_DEVICE_CRT1_SUPPORT,
2094 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2095 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2096 &hpd);
2097 /* DVI - tv dac, dvo */
2098 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
2099 hpd.hpd = RADEON_HPD_2; /* ??? */
2100 radeon_add_legacy_encoder(dev,
2101 radeon_get_encoder_enum(dev,
2102 ATOM_DEVICE_DFP2_SUPPORT,
2103 0),
2104 ATOM_DEVICE_DFP2_SUPPORT);
2105 radeon_add_legacy_encoder(dev,
2106 radeon_get_encoder_enum(dev,
2107 ATOM_DEVICE_CRT2_SUPPORT,
2108 2),
2109 ATOM_DEVICE_CRT2_SUPPORT);
2110 radeon_add_legacy_connector(dev, 1,
2111 ATOM_DEVICE_DFP2_SUPPORT |
2112 ATOM_DEVICE_CRT2_SUPPORT,
2113 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2114 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
2115 &hpd);
2116 break;
Alex Deucher9fad3212011-02-07 13:15:28 -05002117 case CT_MAC_G5_9600:
2118 DRM_INFO("Connector Table: %d (mac g5 9600)\n",
2119 rdev->mode_info.connector_table);
2120 /* DVI - tv dac, dvo */
2121 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2122 hpd.hpd = RADEON_HPD_1; /* ??? */
2123 radeon_add_legacy_encoder(dev,
2124 radeon_get_encoder_enum(dev,
2125 ATOM_DEVICE_DFP2_SUPPORT,
2126 0),
2127 ATOM_DEVICE_DFP2_SUPPORT);
2128 radeon_add_legacy_encoder(dev,
2129 radeon_get_encoder_enum(dev,
2130 ATOM_DEVICE_CRT2_SUPPORT,
2131 2),
2132 ATOM_DEVICE_CRT2_SUPPORT);
2133 radeon_add_legacy_connector(dev, 0,
2134 ATOM_DEVICE_DFP2_SUPPORT |
2135 ATOM_DEVICE_CRT2_SUPPORT,
2136 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2137 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2138 &hpd);
2139 /* ADC - primary dac, internal tmds */
2140 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
2141 hpd.hpd = RADEON_HPD_2; /* ??? */
2142 radeon_add_legacy_encoder(dev,
2143 radeon_get_encoder_enum(dev,
2144 ATOM_DEVICE_DFP1_SUPPORT,
2145 0),
2146 ATOM_DEVICE_DFP1_SUPPORT);
2147 radeon_add_legacy_encoder(dev,
2148 radeon_get_encoder_enum(dev,
2149 ATOM_DEVICE_CRT1_SUPPORT,
2150 1),
2151 ATOM_DEVICE_CRT1_SUPPORT);
2152 radeon_add_legacy_connector(dev, 1,
2153 ATOM_DEVICE_DFP1_SUPPORT |
2154 ATOM_DEVICE_CRT1_SUPPORT,
2155 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2156 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2157 &hpd);
Alex Deucherbeb47272011-04-02 09:09:08 -04002158 /* TV - TV DAC */
2159 ddc_i2c.valid = false;
2160 hpd.hpd = RADEON_HPD_NONE;
2161 radeon_add_legacy_encoder(dev,
2162 radeon_get_encoder_enum(dev,
2163 ATOM_DEVICE_TV1_SUPPORT,
2164 2),
2165 ATOM_DEVICE_TV1_SUPPORT);
2166 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
2167 DRM_MODE_CONNECTOR_SVIDEO,
2168 &ddc_i2c,
2169 CONNECTOR_OBJECT_ID_SVIDEO,
2170 &hpd);
Alex Deucher9fad3212011-02-07 13:15:28 -05002171 break;
Alex Deucher6a556032012-05-02 12:10:21 -04002172 case CT_SAM440EP:
2173 DRM_INFO("Connector Table: %d (SAM440ep embedded board)\n",
2174 rdev->mode_info.connector_table);
2175 /* LVDS */
2176 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
2177 hpd.hpd = RADEON_HPD_NONE;
2178 radeon_add_legacy_encoder(dev,
2179 radeon_get_encoder_enum(dev,
2180 ATOM_DEVICE_LCD1_SUPPORT,
2181 0),
2182 ATOM_DEVICE_LCD1_SUPPORT);
2183 radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
2184 DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
2185 CONNECTOR_OBJECT_ID_LVDS,
2186 &hpd);
2187 /* DVI-I - secondary dac, int tmds */
2188 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2189 hpd.hpd = RADEON_HPD_1; /* ??? */
2190 radeon_add_legacy_encoder(dev,
2191 radeon_get_encoder_enum(dev,
2192 ATOM_DEVICE_DFP1_SUPPORT,
2193 0),
2194 ATOM_DEVICE_DFP1_SUPPORT);
2195 radeon_add_legacy_encoder(dev,
2196 radeon_get_encoder_enum(dev,
2197 ATOM_DEVICE_CRT2_SUPPORT,
2198 2),
2199 ATOM_DEVICE_CRT2_SUPPORT);
2200 radeon_add_legacy_connector(dev, 1,
2201 ATOM_DEVICE_DFP1_SUPPORT |
2202 ATOM_DEVICE_CRT2_SUPPORT,
2203 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2204 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2205 &hpd);
2206 /* VGA - primary dac */
2207 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
2208 hpd.hpd = RADEON_HPD_NONE;
2209 radeon_add_legacy_encoder(dev,
2210 radeon_get_encoder_enum(dev,
2211 ATOM_DEVICE_CRT1_SUPPORT,
2212 1),
2213 ATOM_DEVICE_CRT1_SUPPORT);
2214 radeon_add_legacy_connector(dev, 2,
2215 ATOM_DEVICE_CRT1_SUPPORT,
2216 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
2217 CONNECTOR_OBJECT_ID_VGA,
2218 &hpd);
2219 /* TV - TV DAC */
2220 ddc_i2c.valid = false;
2221 hpd.hpd = RADEON_HPD_NONE;
2222 radeon_add_legacy_encoder(dev,
2223 radeon_get_encoder_enum(dev,
2224 ATOM_DEVICE_TV1_SUPPORT,
2225 2),
2226 ATOM_DEVICE_TV1_SUPPORT);
2227 radeon_add_legacy_connector(dev, 3, ATOM_DEVICE_TV1_SUPPORT,
2228 DRM_MODE_CONNECTOR_SVIDEO,
2229 &ddc_i2c,
2230 CONNECTOR_OBJECT_ID_SVIDEO,
2231 &hpd);
2232 break;
Alex Deuchercafa59b2012-12-20 16:35:47 -05002233 case CT_MAC_G4_SILVER:
2234 DRM_INFO("Connector Table: %d (mac g4 silver)\n",
2235 rdev->mode_info.connector_table);
2236 /* DVI-I - tv dac, int tmds */
2237 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2238 hpd.hpd = RADEON_HPD_1; /* ??? */
2239 radeon_add_legacy_encoder(dev,
2240 radeon_get_encoder_enum(dev,
2241 ATOM_DEVICE_DFP1_SUPPORT,
2242 0),
2243 ATOM_DEVICE_DFP1_SUPPORT);
2244 radeon_add_legacy_encoder(dev,
2245 radeon_get_encoder_enum(dev,
2246 ATOM_DEVICE_CRT2_SUPPORT,
2247 2),
2248 ATOM_DEVICE_CRT2_SUPPORT);
2249 radeon_add_legacy_connector(dev, 0,
2250 ATOM_DEVICE_DFP1_SUPPORT |
2251 ATOM_DEVICE_CRT2_SUPPORT,
2252 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2253 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2254 &hpd);
2255 /* VGA - primary dac */
2256 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
2257 hpd.hpd = RADEON_HPD_NONE;
2258 radeon_add_legacy_encoder(dev,
2259 radeon_get_encoder_enum(dev,
2260 ATOM_DEVICE_CRT1_SUPPORT,
2261 1),
2262 ATOM_DEVICE_CRT1_SUPPORT);
2263 radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
2264 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
2265 CONNECTOR_OBJECT_ID_VGA,
2266 &hpd);
2267 /* TV - TV DAC */
2268 ddc_i2c.valid = false;
2269 hpd.hpd = RADEON_HPD_NONE;
2270 radeon_add_legacy_encoder(dev,
2271 radeon_get_encoder_enum(dev,
2272 ATOM_DEVICE_TV1_SUPPORT,
2273 2),
2274 ATOM_DEVICE_TV1_SUPPORT);
2275 radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
2276 DRM_MODE_CONNECTOR_SVIDEO,
2277 &ddc_i2c,
2278 CONNECTOR_OBJECT_ID_SVIDEO,
2279 &hpd);
2280 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002281 default:
2282 DRM_INFO("Connector table: %d (invalid)\n",
2283 rdev->mode_info.connector_table);
2284 return false;
2285 }
2286
2287 radeon_link_encoder_connector(dev);
2288
2289 return true;
2290}
2291
2292static bool radeon_apply_legacy_quirks(struct drm_device *dev,
2293 int bios_index,
2294 enum radeon_combios_connector
2295 *legacy_connector,
Alex Deuchereed45b32009-12-04 14:45:27 -05002296 struct radeon_i2c_bus_rec *ddc_i2c,
2297 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002298{
Alex Deucherfcec5702009-11-10 21:25:07 -05002299
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002300 /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
2301 one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
2302 if (dev->pdev->device == 0x515e &&
2303 dev->pdev->subsystem_vendor == 0x1014) {
2304 if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
2305 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
2306 return false;
2307 }
2308
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002309 /* X300 card with extra non-existent DVI port */
2310 if (dev->pdev->device == 0x5B60 &&
2311 dev->pdev->subsystem_vendor == 0x17af &&
2312 dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
2313 if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
2314 return false;
2315 }
2316
2317 return true;
2318}
2319
Alex Deucher790cfb32009-10-15 23:26:09 -04002320static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
2321{
2322 /* Acer 5102 has non-existent TV port */
2323 if (dev->pdev->device == 0x5975 &&
2324 dev->pdev->subsystem_vendor == 0x1025 &&
2325 dev->pdev->subsystem_device == 0x009f)
2326 return false;
2327
Alex Deucherfc7f7112009-10-28 01:46:54 -04002328 /* HP dc5750 has non-existent TV port */
2329 if (dev->pdev->device == 0x5974 &&
2330 dev->pdev->subsystem_vendor == 0x103c &&
2331 dev->pdev->subsystem_device == 0x280a)
2332 return false;
2333
Alex Deucherfd874ad2009-11-16 18:33:51 -05002334 /* MSI S270 has non-existent TV port */
2335 if (dev->pdev->device == 0x5955 &&
2336 dev->pdev->subsystem_vendor == 0x1462 &&
2337 dev->pdev->subsystem_device == 0x0131)
2338 return false;
2339
Alex Deucher790cfb32009-10-15 23:26:09 -04002340 return true;
2341}
2342
Alex Deucherb75fad02009-11-05 13:16:01 -05002343static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
2344{
2345 struct radeon_device *rdev = dev->dev_private;
2346 uint32_t ext_tmds_info;
2347
2348 if (rdev->flags & RADEON_IS_IGP) {
2349 if (is_dvi_d)
2350 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
2351 else
2352 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2353 }
2354 ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
2355 if (ext_tmds_info) {
2356 uint8_t rev = RBIOS8(ext_tmds_info);
2357 uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
2358 if (rev >= 3) {
2359 if (is_dvi_d)
2360 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
2361 else
2362 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
2363 } else {
2364 if (flags & 1) {
2365 if (is_dvi_d)
2366 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
2367 else
2368 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
2369 }
2370 }
2371 }
2372 if (is_dvi_d)
2373 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
2374 else
2375 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2376}
2377
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002378bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2379{
2380 struct radeon_device *rdev = dev->dev_private;
2381 uint32_t conn_info, entry, devices;
Alex Deucherb75fad02009-11-05 13:16:01 -05002382 uint16_t tmp, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002383 enum radeon_combios_ddc ddc_type;
2384 enum radeon_combios_connector connector;
2385 int i = 0;
2386 struct radeon_i2c_bus_rec ddc_i2c;
Alex Deuchereed45b32009-12-04 14:45:27 -05002387 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002388
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002389 conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
2390 if (conn_info) {
2391 for (i = 0; i < 4; i++) {
2392 entry = conn_info + 2 + i * 2;
2393
2394 if (!RBIOS16(entry))
2395 break;
2396
2397 tmp = RBIOS16(entry);
2398
2399 connector = (tmp >> 12) & 0xf;
2400
2401 ddc_type = (tmp >> 8) & 0xf;
Alex Deucher3d61bd42012-07-19 20:11:44 -04002402 if (ddc_type == 5)
2403 ddc_i2c = radeon_combios_get_i2c_info_from_table(rdev);
2404 else
2405 ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002406
Alex Deuchereed45b32009-12-04 14:45:27 -05002407 switch (connector) {
2408 case CONNECTOR_PROPRIETARY_LEGACY:
2409 case CONNECTOR_DVI_I_LEGACY:
2410 case CONNECTOR_DVI_D_LEGACY:
2411 if ((tmp >> 4) & 0x1)
2412 hpd.hpd = RADEON_HPD_2;
2413 else
2414 hpd.hpd = RADEON_HPD_1;
2415 break;
2416 default:
2417 hpd.hpd = RADEON_HPD_NONE;
2418 break;
2419 }
2420
Alex Deucher2d152c62009-10-15 23:08:05 -04002421 if (!radeon_apply_legacy_quirks(dev, i, &connector,
Alex Deuchereed45b32009-12-04 14:45:27 -05002422 &ddc_i2c, &hpd))
Alex Deucher2d152c62009-10-15 23:08:05 -04002423 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002424
2425 switch (connector) {
2426 case CONNECTOR_PROPRIETARY_LEGACY:
2427 if ((tmp >> 4) & 0x1)
2428 devices = ATOM_DEVICE_DFP2_SUPPORT;
2429 else
2430 devices = ATOM_DEVICE_DFP1_SUPPORT;
2431 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002432 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002433 (dev, devices, 0),
2434 devices);
2435 radeon_add_legacy_connector(dev, i, devices,
2436 legacy_connector_convert
2437 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002438 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002439 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
2440 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002441 break;
2442 case CONNECTOR_CRT_LEGACY:
2443 if (tmp & 0x1) {
2444 devices = ATOM_DEVICE_CRT2_SUPPORT;
2445 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002446 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002447 (dev,
2448 ATOM_DEVICE_CRT2_SUPPORT,
2449 2),
2450 ATOM_DEVICE_CRT2_SUPPORT);
2451 } else {
2452 devices = ATOM_DEVICE_CRT1_SUPPORT;
2453 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002454 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002455 (dev,
2456 ATOM_DEVICE_CRT1_SUPPORT,
2457 1),
2458 ATOM_DEVICE_CRT1_SUPPORT);
2459 }
2460 radeon_add_legacy_connector(dev,
2461 i,
2462 devices,
2463 legacy_connector_convert
2464 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002465 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002466 CONNECTOR_OBJECT_ID_VGA,
2467 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002468 break;
2469 case CONNECTOR_DVI_I_LEGACY:
2470 devices = 0;
2471 if (tmp & 0x1) {
2472 devices |= ATOM_DEVICE_CRT2_SUPPORT;
2473 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002474 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002475 (dev,
2476 ATOM_DEVICE_CRT2_SUPPORT,
2477 2),
2478 ATOM_DEVICE_CRT2_SUPPORT);
2479 } else {
2480 devices |= ATOM_DEVICE_CRT1_SUPPORT;
2481 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002482 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002483 (dev,
2484 ATOM_DEVICE_CRT1_SUPPORT,
2485 1),
2486 ATOM_DEVICE_CRT1_SUPPORT);
2487 }
Alex Deucher9200ee42013-01-29 16:36:47 -05002488 /* RV100 board with external TDMS bit mis-set.
2489 * Actually uses internal TMDS, clear the bit.
2490 */
2491 if (dev->pdev->device == 0x5159 &&
2492 dev->pdev->subsystem_vendor == 0x1014 &&
2493 dev->pdev->subsystem_device == 0x029A) {
2494 tmp &= ~(1 << 4);
2495 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002496 if ((tmp >> 4) & 0x1) {
2497 devices |= ATOM_DEVICE_DFP2_SUPPORT;
2498 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002499 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002500 (dev,
2501 ATOM_DEVICE_DFP2_SUPPORT,
2502 0),
2503 ATOM_DEVICE_DFP2_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05002504 connector_object_id = combios_check_dl_dvi(dev, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002505 } else {
2506 devices |= ATOM_DEVICE_DFP1_SUPPORT;
2507 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002508 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002509 (dev,
2510 ATOM_DEVICE_DFP1_SUPPORT,
2511 0),
2512 ATOM_DEVICE_DFP1_SUPPORT);
Alex Deucherb75fad02009-11-05 13:16:01 -05002513 connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002514 }
2515 radeon_add_legacy_connector(dev,
2516 i,
2517 devices,
2518 legacy_connector_convert
2519 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002520 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002521 connector_object_id,
2522 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002523 break;
2524 case CONNECTOR_DVI_D_LEGACY:
Alex Deucherb75fad02009-11-05 13:16:01 -05002525 if ((tmp >> 4) & 0x1) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002526 devices = ATOM_DEVICE_DFP2_SUPPORT;
Alex Deucherb75fad02009-11-05 13:16:01 -05002527 connector_object_id = combios_check_dl_dvi(dev, 1);
2528 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002529 devices = ATOM_DEVICE_DFP1_SUPPORT;
Alex Deucherb75fad02009-11-05 13:16:01 -05002530 connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
2531 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002532 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002533 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002534 (dev, devices, 0),
2535 devices);
2536 radeon_add_legacy_connector(dev, i, devices,
2537 legacy_connector_convert
2538 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002539 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002540 connector_object_id,
2541 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002542 break;
2543 case CONNECTOR_CTV_LEGACY:
2544 case CONNECTOR_STV_LEGACY:
2545 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002546 radeon_get_encoder_enum
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002547 (dev,
2548 ATOM_DEVICE_TV1_SUPPORT,
2549 2),
2550 ATOM_DEVICE_TV1_SUPPORT);
2551 radeon_add_legacy_connector(dev, i,
2552 ATOM_DEVICE_TV1_SUPPORT,
2553 legacy_connector_convert
2554 [connector],
Alex Deucherb75fad02009-11-05 13:16:01 -05002555 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002556 CONNECTOR_OBJECT_ID_SVIDEO,
2557 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002558 break;
2559 default:
2560 DRM_ERROR("Unknown connector type: %d\n",
2561 connector);
2562 continue;
2563 }
2564
2565 }
2566 } else {
2567 uint16_t tmds_info =
2568 combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
2569 if (tmds_info) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002570 DRM_DEBUG_KMS("Found DFP table, assuming DVI connector\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002571
2572 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002573 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002574 ATOM_DEVICE_CRT1_SUPPORT,
2575 1),
2576 ATOM_DEVICE_CRT1_SUPPORT);
2577 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002578 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002579 ATOM_DEVICE_DFP1_SUPPORT,
2580 0),
2581 ATOM_DEVICE_DFP1_SUPPORT);
2582
Alex Deucher179e8072010-08-05 21:21:17 -04002583 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
Alex Deucher8e36ed02010-05-18 19:26:47 -04002584 hpd.hpd = RADEON_HPD_1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002585 radeon_add_legacy_connector(dev,
2586 0,
2587 ATOM_DEVICE_CRT1_SUPPORT |
2588 ATOM_DEVICE_DFP1_SUPPORT,
2589 DRM_MODE_CONNECTOR_DVII,
Alex Deucherb75fad02009-11-05 13:16:01 -05002590 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002591 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
2592 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002593 } else {
Alex Deucherd0c403e2009-10-15 23:38:32 -04002594 uint16_t crt_info =
2595 combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002596 DRM_DEBUG_KMS("Found CRT table, assuming VGA connector\n");
Alex Deucherd0c403e2009-10-15 23:38:32 -04002597 if (crt_info) {
2598 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002599 radeon_get_encoder_enum(dev,
Alex Deucherd0c403e2009-10-15 23:38:32 -04002600 ATOM_DEVICE_CRT1_SUPPORT,
2601 1),
2602 ATOM_DEVICE_CRT1_SUPPORT);
Alex Deucher179e8072010-08-05 21:21:17 -04002603 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
Alex Deuchereed45b32009-12-04 14:45:27 -05002604 hpd.hpd = RADEON_HPD_NONE;
Alex Deucherd0c403e2009-10-15 23:38:32 -04002605 radeon_add_legacy_connector(dev,
2606 0,
2607 ATOM_DEVICE_CRT1_SUPPORT,
2608 DRM_MODE_CONNECTOR_VGA,
Alex Deucherb75fad02009-11-05 13:16:01 -05002609 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002610 CONNECTOR_OBJECT_ID_VGA,
2611 &hpd);
Alex Deucherd0c403e2009-10-15 23:38:32 -04002612 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002613 DRM_DEBUG_KMS("No connector info found\n");
Alex Deucherd0c403e2009-10-15 23:38:32 -04002614 return false;
2615 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002616 }
2617 }
2618
2619 if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
2620 uint16_t lcd_info =
2621 combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
2622 if (lcd_info) {
2623 uint16_t lcd_ddc_info =
2624 combios_get_table_offset(dev,
2625 COMBIOS_LCD_DDC_INFO_TABLE);
2626
2627 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002628 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002629 ATOM_DEVICE_LCD1_SUPPORT,
2630 0),
2631 ATOM_DEVICE_LCD1_SUPPORT);
2632
2633 if (lcd_ddc_info) {
2634 ddc_type = RBIOS8(lcd_ddc_info + 2);
2635 switch (ddc_type) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002636 case DDC_LCD:
2637 ddc_i2c =
Alex Deucher179e8072010-08-05 21:21:17 -04002638 combios_setup_i2c_bus(rdev,
2639 DDC_LCD,
2640 RBIOS32(lcd_ddc_info + 3),
2641 RBIOS32(lcd_ddc_info + 7));
Alex Deucherf376b942010-08-05 21:21:16 -04002642 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002643 break;
2644 case DDC_GPIO:
2645 ddc_i2c =
Alex Deucher179e8072010-08-05 21:21:17 -04002646 combios_setup_i2c_bus(rdev,
2647 DDC_GPIO,
2648 RBIOS32(lcd_ddc_info + 3),
2649 RBIOS32(lcd_ddc_info + 7));
Alex Deucherf376b942010-08-05 21:21:16 -04002650 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002651 break;
2652 default:
Alex Deucher179e8072010-08-05 21:21:17 -04002653 ddc_i2c =
2654 combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002655 break;
2656 }
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002657 DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002658 } else
2659 ddc_i2c.valid = false;
2660
Alex Deuchereed45b32009-12-04 14:45:27 -05002661 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002662 radeon_add_legacy_connector(dev,
2663 5,
2664 ATOM_DEVICE_LCD1_SUPPORT,
2665 DRM_MODE_CONNECTOR_LVDS,
Alex Deucherb75fad02009-11-05 13:16:01 -05002666 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002667 CONNECTOR_OBJECT_ID_LVDS,
2668 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002669 }
2670 }
2671
2672 /* check TV table */
2673 if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
2674 uint32_t tv_info =
2675 combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
2676 if (tv_info) {
2677 if (RBIOS8(tv_info + 6) == 'T') {
Alex Deucher790cfb32009-10-15 23:26:09 -04002678 if (radeon_apply_legacy_tv_quirks(dev)) {
Alex Deuchereed45b32009-12-04 14:45:27 -05002679 hpd.hpd = RADEON_HPD_NONE;
Dave Airlied294ed62010-06-08 13:04:50 +10002680 ddc_i2c.valid = false;
Alex Deucher790cfb32009-10-15 23:26:09 -04002681 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04002682 radeon_get_encoder_enum
Alex Deucher790cfb32009-10-15 23:26:09 -04002683 (dev,
2684 ATOM_DEVICE_TV1_SUPPORT,
2685 2),
2686 ATOM_DEVICE_TV1_SUPPORT);
2687 radeon_add_legacy_connector(dev, 6,
2688 ATOM_DEVICE_TV1_SUPPORT,
2689 DRM_MODE_CONNECTOR_SVIDEO,
Alex Deucherb75fad02009-11-05 13:16:01 -05002690 &ddc_i2c,
Alex Deuchereed45b32009-12-04 14:45:27 -05002691 CONNECTOR_OBJECT_ID_SVIDEO,
2692 &hpd);
Alex Deucher790cfb32009-10-15 23:26:09 -04002693 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002694 }
2695 }
2696 }
2697
2698 radeon_link_encoder_connector(dev);
2699
2700 return true;
2701}
2702
Alex Deucher63f7d982011-05-03 12:44:54 -04002703static const char *thermal_controller_names[] = {
2704 "NONE",
2705 "lm63",
2706 "adm1032",
2707};
2708
Alex Deucher56278a82009-12-28 13:58:44 -05002709void radeon_combios_get_power_modes(struct radeon_device *rdev)
2710{
2711 struct drm_device *dev = rdev->ddev;
2712 u16 offset, misc, misc2 = 0;
2713 u8 rev, blocks, tmp;
2714 int state_index = 0;
Alex Deucherc41b9ee2011-07-30 18:12:24 +00002715 struct radeon_i2c_bus_rec i2c_bus;
Alex Deucher56278a82009-12-28 13:58:44 -05002716
Alex Deuchera48b9b42010-04-22 14:03:55 -04002717 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05002718
Alex Deucher0975b162011-02-02 18:42:03 -05002719 /* allocate 2 power states */
2720 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * 2, GFP_KERNEL);
Alex Deuchera7c36fd2011-11-12 11:57:29 -05002721 if (rdev->pm.power_state) {
2722 /* allocate 1 clock mode per state */
2723 rdev->pm.power_state[0].clock_info =
2724 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2725 rdev->pm.power_state[1].clock_info =
2726 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2727 if (!rdev->pm.power_state[0].clock_info ||
2728 !rdev->pm.power_state[1].clock_info)
2729 goto pm_failed;
2730 } else
2731 goto pm_failed;
Alex Deucher0975b162011-02-02 18:42:03 -05002732
Alex Deucher63f7d982011-05-03 12:44:54 -04002733 /* check for a thermal chip */
2734 offset = combios_get_table_offset(dev, COMBIOS_OVERDRIVE_INFO_TABLE);
2735 if (offset) {
2736 u8 thermal_controller = 0, gpio = 0, i2c_addr = 0, clk_bit = 0, data_bit = 0;
Alex Deucher63f7d982011-05-03 12:44:54 -04002737
2738 rev = RBIOS8(offset);
2739
2740 if (rev == 0) {
2741 thermal_controller = RBIOS8(offset + 3);
2742 gpio = RBIOS8(offset + 4) & 0x3f;
2743 i2c_addr = RBIOS8(offset + 5);
2744 } else if (rev == 1) {
2745 thermal_controller = RBIOS8(offset + 4);
2746 gpio = RBIOS8(offset + 5) & 0x3f;
2747 i2c_addr = RBIOS8(offset + 6);
2748 } else if (rev == 2) {
2749 thermal_controller = RBIOS8(offset + 4);
2750 gpio = RBIOS8(offset + 5) & 0x3f;
2751 i2c_addr = RBIOS8(offset + 6);
2752 clk_bit = RBIOS8(offset + 0xa);
2753 data_bit = RBIOS8(offset + 0xb);
2754 }
2755 if ((thermal_controller > 0) && (thermal_controller < 3)) {
2756 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2757 thermal_controller_names[thermal_controller],
2758 i2c_addr >> 1);
2759 if (gpio == DDC_LCD) {
2760 /* MM i2c */
2761 i2c_bus.valid = true;
2762 i2c_bus.hw_capable = true;
2763 i2c_bus.mm_i2c = true;
2764 i2c_bus.i2c_id = 0xa0;
2765 } else if (gpio == DDC_GPIO)
2766 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 1 << clk_bit, 1 << data_bit);
2767 else
2768 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
2769 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2770 if (rdev->pm.i2c_bus) {
2771 struct i2c_board_info info = { };
2772 const char *name = thermal_controller_names[thermal_controller];
2773 info.addr = i2c_addr >> 1;
2774 strlcpy(info.type, name, sizeof(info.type));
2775 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2776 }
2777 }
Alex Deucherc41b9ee2011-07-30 18:12:24 +00002778 } else {
2779 /* boards with a thermal chip, but no overdrive table */
2780
2781 /* Asus 9600xt has an f75375 on the monid bus */
2782 if ((dev->pdev->device == 0x4152) &&
2783 (dev->pdev->subsystem_vendor == 0x1043) &&
2784 (dev->pdev->subsystem_device == 0xc002)) {
2785 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
2786 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2787 if (rdev->pm.i2c_bus) {
2788 struct i2c_board_info info = { };
2789 const char *name = "f75375";
2790 info.addr = 0x28;
2791 strlcpy(info.type, name, sizeof(info.type));
2792 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2793 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2794 name, info.addr);
2795 }
2796 }
Alex Deucher63f7d982011-05-03 12:44:54 -04002797 }
2798
Alex Deucher56278a82009-12-28 13:58:44 -05002799 if (rdev->flags & RADEON_IS_MOBILITY) {
2800 offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
2801 if (offset) {
2802 rev = RBIOS8(offset);
2803 blocks = RBIOS8(offset + 0x2);
2804 /* power mode 0 tends to be the only valid one */
2805 rdev->pm.power_state[state_index].num_clock_modes = 1;
2806 rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
2807 rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
2808 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2809 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2810 goto default_mode;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002811 rdev->pm.power_state[state_index].type =
2812 POWER_STATE_TYPE_BATTERY;
Alex Deucher56278a82009-12-28 13:58:44 -05002813 misc = RBIOS16(offset + 0x5 + 0x0);
2814 if (rev > 4)
2815 misc2 = RBIOS16(offset + 0x5 + 0xe);
Alex Deucher79daedc2010-04-22 14:25:19 -04002816 rdev->pm.power_state[state_index].misc = misc;
2817 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher56278a82009-12-28 13:58:44 -05002818 if (misc & 0x4) {
2819 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
2820 if (misc & 0x8)
2821 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2822 true;
2823 else
2824 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2825 false;
2826 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
2827 if (rev < 6) {
2828 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
2829 RBIOS16(offset + 0x5 + 0xb) * 4;
2830 tmp = RBIOS8(offset + 0x5 + 0xd);
2831 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
2832 } else {
2833 u8 entries = RBIOS8(offset + 0x5 + 0xb);
2834 u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
2835 if (entries && voltage_table_offset) {
2836 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
2837 RBIOS16(voltage_table_offset) * 4;
2838 tmp = RBIOS8(voltage_table_offset + 0x2);
2839 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
2840 } else
2841 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
2842 }
2843 switch ((misc2 & 0x700) >> 8) {
2844 case 0:
2845 default:
2846 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
2847 break;
2848 case 1:
2849 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
2850 break;
2851 case 2:
2852 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
2853 break;
2854 case 3:
2855 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
2856 break;
2857 case 4:
2858 rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
2859 break;
2860 }
2861 } else
2862 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2863 if (rev > 6)
Alex Deucher79daedc2010-04-22 14:25:19 -04002864 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05002865 RBIOS8(offset + 0x5 + 0x10);
Alex Deucherd7311172010-05-03 01:13:14 -04002866 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05002867 state_index++;
2868 } else {
2869 /* XXX figure out some good default low power mode for mobility cards w/out power tables */
2870 }
2871 } else {
2872 /* XXX figure out some good default low power mode for desktop cards */
2873 }
2874
2875default_mode:
2876 /* add the default mode */
Alex Deucher0ec0e742009-12-23 13:21:58 -05002877 rdev->pm.power_state[state_index].type =
2878 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05002879 rdev->pm.power_state[state_index].num_clock_modes = 1;
2880 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2881 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2882 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 -04002883 if ((state_index > 0) &&
Alex Deucher8de016e2010-06-03 21:28:23 -04002884 (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
Alex Deucher84d88f42010-05-27 17:01:42 -04002885 rdev->pm.power_state[state_index].clock_info[0].voltage =
2886 rdev->pm.power_state[0].clock_info[0].voltage;
2887 else
2888 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
Alex Deucher79daedc2010-04-22 14:25:19 -04002889 rdev->pm.power_state[state_index].pcie_lanes = 16;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002890 rdev->pm.power_state[state_index].flags = 0;
2891 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05002892 rdev->pm.num_power_states = state_index + 1;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002893
Alex Deuchera48b9b42010-04-22 14:03:55 -04002894 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2895 rdev->pm.current_clock_mode_index = 0;
Alex Deuchera7c36fd2011-11-12 11:57:29 -05002896 return;
2897
2898pm_failed:
2899 rdev->pm.default_power_state_index = state_index;
2900 rdev->pm.num_power_states = 0;
2901
2902 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2903 rdev->pm.current_clock_mode_index = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002904}
2905
Alex Deucherfcec5702009-11-10 21:25:07 -05002906void radeon_external_tmds_setup(struct drm_encoder *encoder)
2907{
2908 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2909 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
2910
2911 if (!tmds)
2912 return;
2913
2914 switch (tmds->dvo_chip) {
2915 case DVO_SIL164:
2916 /* sil 164 */
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002917 radeon_i2c_put_byte(tmds->i2c_bus,
2918 tmds->slave_addr,
2919 0x08, 0x30);
2920 radeon_i2c_put_byte(tmds->i2c_bus,
Alex Deucherfcec5702009-11-10 21:25:07 -05002921 tmds->slave_addr,
2922 0x09, 0x00);
Alex Deucher5a6f98f2009-12-22 15:04:48 -05002923 radeon_i2c_put_byte(tmds->i2c_bus,
2924 tmds->slave_addr,
2925 0x0a, 0x90);
2926 radeon_i2c_put_byte(tmds->i2c_bus,
2927 tmds->slave_addr,
2928 0x0c, 0x89);
2929 radeon_i2c_put_byte(tmds->i2c_bus,
Alex Deucherfcec5702009-11-10 21:25:07 -05002930 tmds->slave_addr,
2931 0x08, 0x3b);
Alex Deucherfcec5702009-11-10 21:25:07 -05002932 break;
2933 case DVO_SIL1178:
2934 /* sil 1178 - untested */
2935 /*
2936 * 0x0f, 0x44
2937 * 0x0f, 0x4c
2938 * 0x0e, 0x01
2939 * 0x0a, 0x80
2940 * 0x09, 0x30
2941 * 0x0c, 0xc9
2942 * 0x0d, 0x70
2943 * 0x08, 0x32
2944 * 0x08, 0x33
2945 */
2946 break;
2947 default:
2948 break;
2949 }
2950
2951}
2952
2953bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
2954{
2955 struct drm_device *dev = encoder->dev;
2956 struct radeon_device *rdev = dev->dev_private;
2957 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2958 uint16_t offset;
2959 uint8_t blocks, slave_addr, rev;
2960 uint32_t index, id;
2961 uint32_t reg, val, and_mask, or_mask;
2962 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
2963
Alex Deucherfcec5702009-11-10 21:25:07 -05002964 if (!tmds)
2965 return false;
2966
2967 if (rdev->flags & RADEON_IS_IGP) {
2968 offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
2969 rev = RBIOS8(offset);
2970 if (offset) {
2971 rev = RBIOS8(offset);
2972 if (rev > 1) {
2973 blocks = RBIOS8(offset + 3);
2974 index = offset + 4;
2975 while (blocks > 0) {
2976 id = RBIOS16(index);
2977 index += 2;
2978 switch (id >> 13) {
2979 case 0:
2980 reg = (id & 0x1fff) * 4;
2981 val = RBIOS32(index);
2982 index += 4;
2983 WREG32(reg, val);
2984 break;
2985 case 2:
2986 reg = (id & 0x1fff) * 4;
2987 and_mask = RBIOS32(index);
2988 index += 4;
2989 or_mask = RBIOS32(index);
2990 index += 4;
2991 val = RREG32(reg);
2992 val = (val & and_mask) | or_mask;
2993 WREG32(reg, val);
2994 break;
2995 case 3:
2996 val = RBIOS16(index);
2997 index += 2;
2998 udelay(val);
2999 break;
3000 case 4:
3001 val = RBIOS16(index);
3002 index += 2;
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003003 mdelay(val);
Alex Deucherfcec5702009-11-10 21:25:07 -05003004 break;
3005 case 6:
3006 slave_addr = id & 0xff;
3007 slave_addr >>= 1; /* 7 bit addressing */
3008 index++;
3009 reg = RBIOS8(index);
3010 index++;
3011 val = RBIOS8(index);
3012 index++;
Alex Deucher5a6f98f2009-12-22 15:04:48 -05003013 radeon_i2c_put_byte(tmds->i2c_bus,
3014 slave_addr,
3015 reg, val);
Alex Deucherfcec5702009-11-10 21:25:07 -05003016 break;
3017 default:
3018 DRM_ERROR("Unknown id %d\n", id >> 13);
3019 break;
3020 }
3021 blocks--;
3022 }
3023 return true;
3024 }
3025 }
3026 } else {
3027 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
3028 if (offset) {
3029 index = offset + 10;
3030 id = RBIOS16(index);
3031 while (id != 0xffff) {
3032 index += 2;
3033 switch (id >> 13) {
3034 case 0:
3035 reg = (id & 0x1fff) * 4;
3036 val = RBIOS32(index);
3037 WREG32(reg, val);
3038 break;
3039 case 2:
3040 reg = (id & 0x1fff) * 4;
3041 and_mask = RBIOS32(index);
3042 index += 4;
3043 or_mask = RBIOS32(index);
3044 index += 4;
3045 val = RREG32(reg);
3046 val = (val & and_mask) | or_mask;
3047 WREG32(reg, val);
3048 break;
3049 case 4:
3050 val = RBIOS16(index);
3051 index += 2;
3052 udelay(val);
3053 break;
3054 case 5:
3055 reg = id & 0x1fff;
3056 and_mask = RBIOS32(index);
3057 index += 4;
3058 or_mask = RBIOS32(index);
3059 index += 4;
3060 val = RREG32_PLL(reg);
3061 val = (val & and_mask) | or_mask;
3062 WREG32_PLL(reg, val);
3063 break;
3064 case 6:
3065 reg = id & 0x1fff;
3066 val = RBIOS8(index);
3067 index += 1;
Alex Deucher5a6f98f2009-12-22 15:04:48 -05003068 radeon_i2c_put_byte(tmds->i2c_bus,
3069 tmds->slave_addr,
3070 reg, val);
Alex Deucherfcec5702009-11-10 21:25:07 -05003071 break;
3072 default:
3073 DRM_ERROR("Unknown id %d\n", id >> 13);
3074 break;
3075 }
3076 id = RBIOS16(index);
3077 }
3078 return true;
3079 }
3080 }
3081 return false;
3082}
3083
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003084static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
3085{
3086 struct radeon_device *rdev = dev->dev_private;
3087
3088 if (offset) {
3089 while (RBIOS16(offset)) {
3090 uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
3091 uint32_t addr = (RBIOS16(offset) & 0x1fff);
3092 uint32_t val, and_mask, or_mask;
3093 uint32_t tmp;
3094
3095 offset += 2;
3096 switch (cmd) {
3097 case 0:
3098 val = RBIOS32(offset);
3099 offset += 4;
3100 WREG32(addr, val);
3101 break;
3102 case 1:
3103 val = RBIOS32(offset);
3104 offset += 4;
3105 WREG32(addr, val);
3106 break;
3107 case 2:
3108 and_mask = RBIOS32(offset);
3109 offset += 4;
3110 or_mask = RBIOS32(offset);
3111 offset += 4;
3112 tmp = RREG32(addr);
3113 tmp &= and_mask;
3114 tmp |= or_mask;
3115 WREG32(addr, tmp);
3116 break;
3117 case 3:
3118 and_mask = RBIOS32(offset);
3119 offset += 4;
3120 or_mask = RBIOS32(offset);
3121 offset += 4;
3122 tmp = RREG32(addr);
3123 tmp &= and_mask;
3124 tmp |= or_mask;
3125 WREG32(addr, tmp);
3126 break;
3127 case 4:
3128 val = RBIOS16(offset);
3129 offset += 2;
3130 udelay(val);
3131 break;
3132 case 5:
3133 val = RBIOS16(offset);
3134 offset += 2;
3135 switch (addr) {
3136 case 8:
3137 while (val--) {
3138 if (!
3139 (RREG32_PLL
3140 (RADEON_CLK_PWRMGT_CNTL) &
3141 RADEON_MC_BUSY))
3142 break;
3143 }
3144 break;
3145 case 9:
3146 while (val--) {
3147 if ((RREG32(RADEON_MC_STATUS) &
3148 RADEON_MC_IDLE))
3149 break;
3150 }
3151 break;
3152 default:
3153 break;
3154 }
3155 break;
3156 default:
3157 break;
3158 }
3159 }
3160 }
3161}
3162
3163static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
3164{
3165 struct radeon_device *rdev = dev->dev_private;
3166
3167 if (offset) {
3168 while (RBIOS8(offset)) {
3169 uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
3170 uint8_t addr = (RBIOS8(offset) & 0x3f);
3171 uint32_t val, shift, tmp;
3172 uint32_t and_mask, or_mask;
3173
3174 offset++;
3175 switch (cmd) {
3176 case 0:
3177 val = RBIOS32(offset);
3178 offset += 4;
3179 WREG32_PLL(addr, val);
3180 break;
3181 case 1:
3182 shift = RBIOS8(offset) * 8;
3183 offset++;
3184 and_mask = RBIOS8(offset) << shift;
3185 and_mask |= ~(0xff << shift);
3186 offset++;
3187 or_mask = RBIOS8(offset) << shift;
3188 offset++;
3189 tmp = RREG32_PLL(addr);
3190 tmp &= and_mask;
3191 tmp |= or_mask;
3192 WREG32_PLL(addr, tmp);
3193 break;
3194 case 2:
3195 case 3:
3196 tmp = 1000;
3197 switch (addr) {
3198 case 1:
3199 udelay(150);
3200 break;
3201 case 2:
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003202 mdelay(1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003203 break;
3204 case 3:
3205 while (tmp--) {
3206 if (!
3207 (RREG32_PLL
3208 (RADEON_CLK_PWRMGT_CNTL) &
3209 RADEON_MC_BUSY))
3210 break;
3211 }
3212 break;
3213 case 4:
3214 while (tmp--) {
3215 if (RREG32_PLL
3216 (RADEON_CLK_PWRMGT_CNTL) &
3217 RADEON_DLL_READY)
3218 break;
3219 }
3220 break;
3221 case 5:
3222 tmp =
3223 RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
3224 if (tmp & RADEON_CG_NO1_DEBUG_0) {
3225#if 0
3226 uint32_t mclk_cntl =
3227 RREG32_PLL
3228 (RADEON_MCLK_CNTL);
3229 mclk_cntl &= 0xffff0000;
3230 /*mclk_cntl |= 0x00001111;*//* ??? */
3231 WREG32_PLL(RADEON_MCLK_CNTL,
3232 mclk_cntl);
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003233 mdelay(10);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003234#endif
3235 WREG32_PLL
3236 (RADEON_CLK_PWRMGT_CNTL,
3237 tmp &
3238 ~RADEON_CG_NO1_DEBUG_0);
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003239 mdelay(10);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003240 }
3241 break;
3242 default:
3243 break;
3244 }
3245 break;
3246 default:
3247 break;
3248 }
3249 }
3250 }
3251}
3252
3253static void combios_parse_ram_reset_table(struct drm_device *dev,
3254 uint16_t offset)
3255{
3256 struct radeon_device *rdev = dev->dev_private;
3257 uint32_t tmp;
3258
3259 if (offset) {
3260 uint8_t val = RBIOS8(offset);
3261 while (val != 0xff) {
3262 offset++;
3263
3264 if (val == 0x0f) {
3265 uint32_t channel_complete_mask;
3266
3267 if (ASIC_IS_R300(rdev))
3268 channel_complete_mask =
3269 R300_MEM_PWRUP_COMPLETE;
3270 else
3271 channel_complete_mask =
3272 RADEON_MEM_PWRUP_COMPLETE;
3273 tmp = 20000;
3274 while (tmp--) {
3275 if ((RREG32(RADEON_MEM_STR_CNTL) &
3276 channel_complete_mask) ==
3277 channel_complete_mask)
3278 break;
3279 }
3280 } else {
3281 uint32_t or_mask = RBIOS16(offset);
3282 offset += 2;
3283
3284 tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
3285 tmp &= RADEON_SDRAM_MODE_MASK;
3286 tmp |= or_mask;
3287 WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
3288
3289 or_mask = val << 24;
3290 tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
3291 tmp &= RADEON_B3MEM_RESET_MASK;
3292 tmp |= or_mask;
3293 WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
3294 }
3295 val = RBIOS8(offset);
3296 }
3297 }
3298}
3299
3300static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
3301 int mem_addr_mapping)
3302{
3303 struct radeon_device *rdev = dev->dev_private;
3304 uint32_t mem_cntl;
3305 uint32_t mem_size;
3306 uint32_t addr = 0;
3307
3308 mem_cntl = RREG32(RADEON_MEM_CNTL);
3309 if (mem_cntl & RV100_HALF_MODE)
3310 ram /= 2;
3311 mem_size = ram;
3312 mem_cntl &= ~(0xff << 8);
3313 mem_cntl |= (mem_addr_mapping & 0xff) << 8;
3314 WREG32(RADEON_MEM_CNTL, mem_cntl);
3315 RREG32(RADEON_MEM_CNTL);
3316
3317 /* sdram reset ? */
3318
3319 /* something like this???? */
3320 while (ram--) {
3321 addr = ram * 1024 * 1024;
3322 /* write to each page */
Daniel Vetter2ef9bdf2012-12-02 14:02:51 +01003323 WREG32_IDX((addr) | RADEON_MM_APER, 0xdeadbeef);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003324 /* read back and verify */
Daniel Vetter2ef9bdf2012-12-02 14:02:51 +01003325 if (RREG32_IDX((addr) | RADEON_MM_APER) != 0xdeadbeef)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003326 return 0;
3327 }
3328
3329 return mem_size;
3330}
3331
3332static void combios_write_ram_size(struct drm_device *dev)
3333{
3334 struct radeon_device *rdev = dev->dev_private;
3335 uint8_t rev;
3336 uint16_t offset;
3337 uint32_t mem_size = 0;
3338 uint32_t mem_cntl = 0;
3339
3340 /* should do something smarter here I guess... */
3341 if (rdev->flags & RADEON_IS_IGP)
3342 return;
3343
3344 /* first check detected mem table */
3345 offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
3346 if (offset) {
3347 rev = RBIOS8(offset);
3348 if (rev < 3) {
3349 mem_cntl = RBIOS32(offset + 1);
3350 mem_size = RBIOS16(offset + 5);
Alex Deucher4ce91982010-06-30 12:13:55 -04003351 if ((rdev->family < CHIP_R200) &&
3352 !ASIC_IS_RN50(rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003353 WREG32(RADEON_MEM_CNTL, mem_cntl);
3354 }
3355 }
3356
3357 if (!mem_size) {
3358 offset =
3359 combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
3360 if (offset) {
3361 rev = RBIOS8(offset - 1);
3362 if (rev < 1) {
Alex Deucher4ce91982010-06-30 12:13:55 -04003363 if ((rdev->family < CHIP_R200)
3364 && !ASIC_IS_RN50(rdev)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003365 int ram = 0;
3366 int mem_addr_mapping = 0;
3367
3368 while (RBIOS8(offset)) {
3369 ram = RBIOS8(offset);
3370 mem_addr_mapping =
3371 RBIOS8(offset + 1);
3372 if (mem_addr_mapping != 0x25)
3373 ram *= 2;
3374 mem_size =
3375 combios_detect_ram(dev, ram,
3376 mem_addr_mapping);
3377 if (mem_size)
3378 break;
3379 offset += 2;
3380 }
3381 } else
3382 mem_size = RBIOS8(offset);
3383 } else {
3384 mem_size = RBIOS8(offset);
3385 mem_size *= 2; /* convert to MB */
3386 }
3387 }
3388 }
3389
3390 mem_size *= (1024 * 1024); /* convert to bytes */
3391 WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
3392}
3393
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003394void radeon_combios_asic_init(struct drm_device *dev)
3395{
3396 struct radeon_device *rdev = dev->dev_private;
3397 uint16_t table;
3398
3399 /* port hardcoded mac stuff from radeonfb */
3400 if (rdev->bios == NULL)
3401 return;
3402
3403 /* ASIC INIT 1 */
3404 table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
3405 if (table)
3406 combios_parse_mmio_table(dev, table);
3407
3408 /* PLL INIT */
3409 table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
3410 if (table)
3411 combios_parse_pll_table(dev, table);
3412
3413 /* ASIC INIT 2 */
3414 table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
3415 if (table)
3416 combios_parse_mmio_table(dev, table);
3417
3418 if (!(rdev->flags & RADEON_IS_IGP)) {
3419 /* ASIC INIT 4 */
3420 table =
3421 combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
3422 if (table)
3423 combios_parse_mmio_table(dev, table);
3424
3425 /* RAM RESET */
3426 table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
3427 if (table)
3428 combios_parse_ram_reset_table(dev, table);
3429
3430 /* ASIC INIT 3 */
3431 table =
3432 combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
3433 if (table)
3434 combios_parse_mmio_table(dev, table);
3435
3436 /* write CONFIG_MEMSIZE */
3437 combios_write_ram_size(dev);
3438 }
3439
Dave Airlie580b4ff2010-06-30 13:26:11 +10003440 /* quirk for rs4xx HP nx6125 laptop to make it resume
3441 * - it hangs on resume inside the dynclk 1 table.
3442 */
3443 if (rdev->family == CHIP_RS480 &&
3444 rdev->pdev->subsystem_vendor == 0x103c &&
3445 rdev->pdev->subsystem_device == 0x308b)
3446 return;
3447
Alex Deucher52fa2bb2010-07-21 23:54:35 -04003448 /* quirk for rs4xx HP dv5000 laptop to make it resume
3449 * - it hangs on resume inside the dynclk 1 table.
3450 */
3451 if (rdev->family == CHIP_RS480 &&
3452 rdev->pdev->subsystem_vendor == 0x103c &&
3453 rdev->pdev->subsystem_device == 0x30a4)
3454 return;
3455
Alex Deucher302a8e82011-08-29 14:55:25 +00003456 /* quirk for rs4xx Compaq Presario V5245EU laptop to make it resume
3457 * - it hangs on resume inside the dynclk 1 table.
3458 */
3459 if (rdev->family == CHIP_RS480 &&
3460 rdev->pdev->subsystem_vendor == 0x103c &&
3461 rdev->pdev->subsystem_device == 0x30ae)
3462 return;
3463
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003464 /* DYN CLK 1 */
3465 table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
3466 if (table)
3467 combios_parse_pll_table(dev, table);
3468
3469}
3470
3471void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
3472{
3473 struct radeon_device *rdev = dev->dev_private;
3474 uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
3475
3476 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
3477 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3478 bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
3479
3480 /* let the bios control the backlight */
3481 bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
3482
3483 /* tell the bios not to handle mode switching */
3484 bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
3485 RADEON_ACC_MODE_CHANGE);
3486
3487 /* tell the bios a driver is loaded */
3488 bios_7_scratch |= RADEON_DRV_LOADED;
3489
3490 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
3491 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3492 WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
3493}
3494
3495void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
3496{
3497 struct drm_device *dev = encoder->dev;
3498 struct radeon_device *rdev = dev->dev_private;
3499 uint32_t bios_6_scratch;
3500
3501 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3502
3503 if (lock)
3504 bios_6_scratch |= RADEON_DRIVER_CRITICAL;
3505 else
3506 bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
3507
3508 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3509}
3510
3511void
3512radeon_combios_connected_scratch_regs(struct drm_connector *connector,
3513 struct drm_encoder *encoder,
3514 bool connected)
3515{
3516 struct drm_device *dev = connector->dev;
3517 struct radeon_device *rdev = dev->dev_private;
3518 struct radeon_connector *radeon_connector =
3519 to_radeon_connector(connector);
3520 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3521 uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
3522 uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
3523
3524 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
3525 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
3526 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003527 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003528 /* fix me */
3529 bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
3530 /*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
3531 bios_5_scratch |= RADEON_TV1_ON;
3532 bios_5_scratch |= RADEON_ACC_REQ_TV1;
3533 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003534 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003535 bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
3536 bios_5_scratch &= ~RADEON_TV1_ON;
3537 bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
3538 }
3539 }
3540 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
3541 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
3542 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003543 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003544 bios_4_scratch |= RADEON_LCD1_ATTACHED;
3545 bios_5_scratch |= RADEON_LCD1_ON;
3546 bios_5_scratch |= RADEON_ACC_REQ_LCD1;
3547 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003548 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003549 bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
3550 bios_5_scratch &= ~RADEON_LCD1_ON;
3551 bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
3552 }
3553 }
3554 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
3555 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
3556 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003557 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003558 bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
3559 bios_5_scratch |= RADEON_CRT1_ON;
3560 bios_5_scratch |= RADEON_ACC_REQ_CRT1;
3561 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003562 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003563 bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
3564 bios_5_scratch &= ~RADEON_CRT1_ON;
3565 bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
3566 }
3567 }
3568 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
3569 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
3570 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003571 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003572 bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
3573 bios_5_scratch |= RADEON_CRT2_ON;
3574 bios_5_scratch |= RADEON_ACC_REQ_CRT2;
3575 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003576 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003577 bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
3578 bios_5_scratch &= ~RADEON_CRT2_ON;
3579 bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
3580 }
3581 }
3582 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
3583 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
3584 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003585 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003586 bios_4_scratch |= RADEON_DFP1_ATTACHED;
3587 bios_5_scratch |= RADEON_DFP1_ON;
3588 bios_5_scratch |= RADEON_ACC_REQ_DFP1;
3589 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003590 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003591 bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
3592 bios_5_scratch &= ~RADEON_DFP1_ON;
3593 bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
3594 }
3595 }
3596 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
3597 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
3598 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003599 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003600 bios_4_scratch |= RADEON_DFP2_ATTACHED;
3601 bios_5_scratch |= RADEON_DFP2_ON;
3602 bios_5_scratch |= RADEON_ACC_REQ_DFP2;
3603 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10003604 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003605 bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
3606 bios_5_scratch &= ~RADEON_DFP2_ON;
3607 bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
3608 }
3609 }
3610 WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
3611 WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
3612}
3613
3614void
3615radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
3616{
3617 struct drm_device *dev = encoder->dev;
3618 struct radeon_device *rdev = dev->dev_private;
3619 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3620 uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
3621
3622 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
3623 bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
3624 bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
3625 }
3626 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3627 bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
3628 bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
3629 }
3630 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3631 bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
3632 bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
3633 }
3634 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3635 bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
3636 bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
3637 }
3638 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3639 bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
3640 bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
3641 }
3642 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3643 bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
3644 bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
3645 }
3646 WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
3647}
3648
3649void
3650radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
3651{
3652 struct drm_device *dev = encoder->dev;
3653 struct radeon_device *rdev = dev->dev_private;
3654 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3655 uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
3656
3657 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
3658 if (on)
3659 bios_6_scratch |= RADEON_TV_DPMS_ON;
3660 else
3661 bios_6_scratch &= ~RADEON_TV_DPMS_ON;
3662 }
3663 if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
3664 if (on)
3665 bios_6_scratch |= RADEON_CRT_DPMS_ON;
3666 else
3667 bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
3668 }
3669 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
3670 if (on)
3671 bios_6_scratch |= RADEON_LCD_DPMS_ON;
3672 else
3673 bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
3674 }
3675 if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
3676 if (on)
3677 bios_6_scratch |= RADEON_DFP_DPMS_ON;
3678 else
3679 bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
3680 }
3681 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
3682}