Home | History | Annotate | Line # | Download | only in radeon
      1  1.3  riastrad /*	$NetBSD: radeon_combios.c,v 1.4 2021/12/18 23:45:43 riastradh Exp $	*/
      2  1.3  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2004 ATI Technologies Inc., Markham, Ontario
      5  1.1  riastrad  * Copyright 2007-8 Advanced Micro Devices, Inc.
      6  1.1  riastrad  * Copyright 2008 Red Hat Inc.
      7  1.1  riastrad  *
      8  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      9  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
     10  1.1  riastrad  * to deal in the Software without restriction, including without limitation
     11  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     12  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     13  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     14  1.1  riastrad  *
     15  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     16  1.1  riastrad  * all copies or substantial portions of the Software.
     17  1.1  riastrad  *
     18  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     19  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     21  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     22  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     23  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     24  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     25  1.1  riastrad  *
     26  1.1  riastrad  * Authors: Dave Airlie
     27  1.1  riastrad  *          Alex Deucher
     28  1.1  riastrad  */
     29  1.4  riastrad 
     30  1.3  riastrad #include <sys/cdefs.h>
     31  1.3  riastrad __KERNEL_RCSID(0, "$NetBSD: radeon_combios.c,v 1.4 2021/12/18 23:45:43 riastradh Exp $");
     32  1.3  riastrad 
     33  1.4  riastrad #include <linux/pci.h>
     34  1.4  riastrad 
     35  1.4  riastrad #include <drm/drm_device.h>
     36  1.1  riastrad #include <drm/radeon_drm.h>
     37  1.4  riastrad 
     38  1.1  riastrad #include "radeon.h"
     39  1.1  riastrad #include "atom.h"
     40  1.1  riastrad 
     41  1.1  riastrad #ifdef CONFIG_PPC_PMAC
     42  1.1  riastrad /* not sure which of these are needed */
     43  1.1  riastrad #include <asm/machdep.h>
     44  1.1  riastrad #include <asm/pmac_feature.h>
     45  1.1  riastrad #include <asm/prom.h>
     46  1.1  riastrad #endif /* CONFIG_PPC_PMAC */
     47  1.1  riastrad 
     48  1.1  riastrad /* from radeon_legacy_encoder.c */
     49  1.1  riastrad extern void
     50  1.1  riastrad radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
     51  1.1  riastrad 			  uint32_t supported_device);
     52  1.1  riastrad 
     53  1.1  riastrad /* old legacy ATI BIOS routines */
     54  1.1  riastrad 
     55  1.1  riastrad /* COMBIOS table offsets */
     56  1.1  riastrad enum radeon_combios_table_offset {
     57  1.1  riastrad 	/* absolute offset tables */
     58  1.1  riastrad 	COMBIOS_ASIC_INIT_1_TABLE,
     59  1.1  riastrad 	COMBIOS_BIOS_SUPPORT_TABLE,
     60  1.1  riastrad 	COMBIOS_DAC_PROGRAMMING_TABLE,
     61  1.1  riastrad 	COMBIOS_MAX_COLOR_DEPTH_TABLE,
     62  1.1  riastrad 	COMBIOS_CRTC_INFO_TABLE,
     63  1.1  riastrad 	COMBIOS_PLL_INFO_TABLE,
     64  1.1  riastrad 	COMBIOS_TV_INFO_TABLE,
     65  1.1  riastrad 	COMBIOS_DFP_INFO_TABLE,
     66  1.1  riastrad 	COMBIOS_HW_CONFIG_INFO_TABLE,
     67  1.1  riastrad 	COMBIOS_MULTIMEDIA_INFO_TABLE,
     68  1.1  riastrad 	COMBIOS_TV_STD_PATCH_TABLE,
     69  1.1  riastrad 	COMBIOS_LCD_INFO_TABLE,
     70  1.1  riastrad 	COMBIOS_MOBILE_INFO_TABLE,
     71  1.1  riastrad 	COMBIOS_PLL_INIT_TABLE,
     72  1.1  riastrad 	COMBIOS_MEM_CONFIG_TABLE,
     73  1.1  riastrad 	COMBIOS_SAVE_MASK_TABLE,
     74  1.1  riastrad 	COMBIOS_HARDCODED_EDID_TABLE,
     75  1.1  riastrad 	COMBIOS_ASIC_INIT_2_TABLE,
     76  1.1  riastrad 	COMBIOS_CONNECTOR_INFO_TABLE,
     77  1.1  riastrad 	COMBIOS_DYN_CLK_1_TABLE,
     78  1.1  riastrad 	COMBIOS_RESERVED_MEM_TABLE,
     79  1.1  riastrad 	COMBIOS_EXT_TMDS_INFO_TABLE,
     80  1.1  riastrad 	COMBIOS_MEM_CLK_INFO_TABLE,
     81  1.1  riastrad 	COMBIOS_EXT_DAC_INFO_TABLE,
     82  1.1  riastrad 	COMBIOS_MISC_INFO_TABLE,
     83  1.1  riastrad 	COMBIOS_CRT_INFO_TABLE,
     84  1.1  riastrad 	COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE,
     85  1.1  riastrad 	COMBIOS_COMPONENT_VIDEO_INFO_TABLE,
     86  1.1  riastrad 	COMBIOS_FAN_SPEED_INFO_TABLE,
     87  1.1  riastrad 	COMBIOS_OVERDRIVE_INFO_TABLE,
     88  1.1  riastrad 	COMBIOS_OEM_INFO_TABLE,
     89  1.1  riastrad 	COMBIOS_DYN_CLK_2_TABLE,
     90  1.1  riastrad 	COMBIOS_POWER_CONNECTOR_INFO_TABLE,
     91  1.1  riastrad 	COMBIOS_I2C_INFO_TABLE,
     92  1.1  riastrad 	/* relative offset tables */
     93  1.1  riastrad 	COMBIOS_ASIC_INIT_3_TABLE,	/* offset from misc info */
     94  1.1  riastrad 	COMBIOS_ASIC_INIT_4_TABLE,	/* offset from misc info */
     95  1.1  riastrad 	COMBIOS_DETECTED_MEM_TABLE,	/* offset from misc info */
     96  1.1  riastrad 	COMBIOS_ASIC_INIT_5_TABLE,	/* offset from misc info */
     97  1.1  riastrad 	COMBIOS_RAM_RESET_TABLE,	/* offset from mem config */
     98  1.1  riastrad 	COMBIOS_POWERPLAY_INFO_TABLE,	/* offset from mobile info */
     99  1.1  riastrad 	COMBIOS_GPIO_INFO_TABLE,	/* offset from mobile info */
    100  1.1  riastrad 	COMBIOS_LCD_DDC_INFO_TABLE,	/* offset from mobile info */
    101  1.1  riastrad 	COMBIOS_TMDS_POWER_TABLE,	/* offset from mobile info */
    102  1.1  riastrad 	COMBIOS_TMDS_POWER_ON_TABLE,	/* offset from tmds power */
    103  1.1  riastrad 	COMBIOS_TMDS_POWER_OFF_TABLE,	/* offset from tmds power */
    104  1.1  riastrad };
    105  1.1  riastrad 
    106  1.1  riastrad enum radeon_combios_ddc {
    107  1.1  riastrad 	DDC_NONE_DETECTED,
    108  1.1  riastrad 	DDC_MONID,
    109  1.1  riastrad 	DDC_DVI,
    110  1.1  riastrad 	DDC_VGA,
    111  1.1  riastrad 	DDC_CRT2,
    112  1.1  riastrad 	DDC_LCD,
    113  1.1  riastrad 	DDC_GPIO,
    114  1.1  riastrad };
    115  1.1  riastrad 
    116  1.1  riastrad enum radeon_combios_connector {
    117  1.1  riastrad 	CONNECTOR_NONE_LEGACY,
    118  1.1  riastrad 	CONNECTOR_PROPRIETARY_LEGACY,
    119  1.1  riastrad 	CONNECTOR_CRT_LEGACY,
    120  1.1  riastrad 	CONNECTOR_DVI_I_LEGACY,
    121  1.1  riastrad 	CONNECTOR_DVI_D_LEGACY,
    122  1.1  riastrad 	CONNECTOR_CTV_LEGACY,
    123  1.1  riastrad 	CONNECTOR_STV_LEGACY,
    124  1.1  riastrad 	CONNECTOR_UNSUPPORTED_LEGACY
    125  1.1  riastrad };
    126  1.1  riastrad 
    127  1.3  riastrad static const int legacy_connector_convert[] = {
    128  1.1  riastrad 	DRM_MODE_CONNECTOR_Unknown,
    129  1.1  riastrad 	DRM_MODE_CONNECTOR_DVID,
    130  1.1  riastrad 	DRM_MODE_CONNECTOR_VGA,
    131  1.1  riastrad 	DRM_MODE_CONNECTOR_DVII,
    132  1.1  riastrad 	DRM_MODE_CONNECTOR_DVID,
    133  1.1  riastrad 	DRM_MODE_CONNECTOR_Composite,
    134  1.1  riastrad 	DRM_MODE_CONNECTOR_SVIDEO,
    135  1.1  riastrad 	DRM_MODE_CONNECTOR_Unknown,
    136  1.1  riastrad };
    137  1.1  riastrad 
    138  1.1  riastrad static uint16_t combios_get_table_offset(struct drm_device *dev,
    139  1.1  riastrad 					 enum radeon_combios_table_offset table)
    140  1.1  riastrad {
    141  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
    142  1.1  riastrad 	int rev, size;
    143  1.1  riastrad 	uint16_t offset = 0, check_offset;
    144  1.1  riastrad 
    145  1.1  riastrad 	if (!rdev->bios)
    146  1.1  riastrad 		return 0;
    147  1.1  riastrad 
    148  1.1  riastrad 	switch (table) {
    149  1.1  riastrad 		/* absolute offset tables */
    150  1.1  riastrad 	case COMBIOS_ASIC_INIT_1_TABLE:
    151  1.1  riastrad 		check_offset = 0xc;
    152  1.1  riastrad 		break;
    153  1.1  riastrad 	case COMBIOS_BIOS_SUPPORT_TABLE:
    154  1.1  riastrad 		check_offset = 0x14;
    155  1.1  riastrad 		break;
    156  1.1  riastrad 	case COMBIOS_DAC_PROGRAMMING_TABLE:
    157  1.1  riastrad 		check_offset = 0x2a;
    158  1.1  riastrad 		break;
    159  1.1  riastrad 	case COMBIOS_MAX_COLOR_DEPTH_TABLE:
    160  1.1  riastrad 		check_offset = 0x2c;
    161  1.1  riastrad 		break;
    162  1.1  riastrad 	case COMBIOS_CRTC_INFO_TABLE:
    163  1.1  riastrad 		check_offset = 0x2e;
    164  1.1  riastrad 		break;
    165  1.1  riastrad 	case COMBIOS_PLL_INFO_TABLE:
    166  1.1  riastrad 		check_offset = 0x30;
    167  1.1  riastrad 		break;
    168  1.1  riastrad 	case COMBIOS_TV_INFO_TABLE:
    169  1.1  riastrad 		check_offset = 0x32;
    170  1.1  riastrad 		break;
    171  1.1  riastrad 	case COMBIOS_DFP_INFO_TABLE:
    172  1.1  riastrad 		check_offset = 0x34;
    173  1.1  riastrad 		break;
    174  1.1  riastrad 	case COMBIOS_HW_CONFIG_INFO_TABLE:
    175  1.1  riastrad 		check_offset = 0x36;
    176  1.1  riastrad 		break;
    177  1.1  riastrad 	case COMBIOS_MULTIMEDIA_INFO_TABLE:
    178  1.1  riastrad 		check_offset = 0x38;
    179  1.1  riastrad 		break;
    180  1.1  riastrad 	case COMBIOS_TV_STD_PATCH_TABLE:
    181  1.1  riastrad 		check_offset = 0x3e;
    182  1.1  riastrad 		break;
    183  1.1  riastrad 	case COMBIOS_LCD_INFO_TABLE:
    184  1.1  riastrad 		check_offset = 0x40;
    185  1.1  riastrad 		break;
    186  1.1  riastrad 	case COMBIOS_MOBILE_INFO_TABLE:
    187  1.1  riastrad 		check_offset = 0x42;
    188  1.1  riastrad 		break;
    189  1.1  riastrad 	case COMBIOS_PLL_INIT_TABLE:
    190  1.1  riastrad 		check_offset = 0x46;
    191  1.1  riastrad 		break;
    192  1.1  riastrad 	case COMBIOS_MEM_CONFIG_TABLE:
    193  1.1  riastrad 		check_offset = 0x48;
    194  1.1  riastrad 		break;
    195  1.1  riastrad 	case COMBIOS_SAVE_MASK_TABLE:
    196  1.1  riastrad 		check_offset = 0x4a;
    197  1.1  riastrad 		break;
    198  1.1  riastrad 	case COMBIOS_HARDCODED_EDID_TABLE:
    199  1.1  riastrad 		check_offset = 0x4c;
    200  1.1  riastrad 		break;
    201  1.1  riastrad 	case COMBIOS_ASIC_INIT_2_TABLE:
    202  1.1  riastrad 		check_offset = 0x4e;
    203  1.1  riastrad 		break;
    204  1.1  riastrad 	case COMBIOS_CONNECTOR_INFO_TABLE:
    205  1.1  riastrad 		check_offset = 0x50;
    206  1.1  riastrad 		break;
    207  1.1  riastrad 	case COMBIOS_DYN_CLK_1_TABLE:
    208  1.1  riastrad 		check_offset = 0x52;
    209  1.1  riastrad 		break;
    210  1.1  riastrad 	case COMBIOS_RESERVED_MEM_TABLE:
    211  1.1  riastrad 		check_offset = 0x54;
    212  1.1  riastrad 		break;
    213  1.1  riastrad 	case COMBIOS_EXT_TMDS_INFO_TABLE:
    214  1.1  riastrad 		check_offset = 0x58;
    215  1.1  riastrad 		break;
    216  1.1  riastrad 	case COMBIOS_MEM_CLK_INFO_TABLE:
    217  1.1  riastrad 		check_offset = 0x5a;
    218  1.1  riastrad 		break;
    219  1.1  riastrad 	case COMBIOS_EXT_DAC_INFO_TABLE:
    220  1.1  riastrad 		check_offset = 0x5c;
    221  1.1  riastrad 		break;
    222  1.1  riastrad 	case COMBIOS_MISC_INFO_TABLE:
    223  1.1  riastrad 		check_offset = 0x5e;
    224  1.1  riastrad 		break;
    225  1.1  riastrad 	case COMBIOS_CRT_INFO_TABLE:
    226  1.1  riastrad 		check_offset = 0x60;
    227  1.1  riastrad 		break;
    228  1.1  riastrad 	case COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE:
    229  1.1  riastrad 		check_offset = 0x62;
    230  1.1  riastrad 		break;
    231  1.1  riastrad 	case COMBIOS_COMPONENT_VIDEO_INFO_TABLE:
    232  1.1  riastrad 		check_offset = 0x64;
    233  1.1  riastrad 		break;
    234  1.1  riastrad 	case COMBIOS_FAN_SPEED_INFO_TABLE:
    235  1.1  riastrad 		check_offset = 0x66;
    236  1.1  riastrad 		break;
    237  1.1  riastrad 	case COMBIOS_OVERDRIVE_INFO_TABLE:
    238  1.1  riastrad 		check_offset = 0x68;
    239  1.1  riastrad 		break;
    240  1.1  riastrad 	case COMBIOS_OEM_INFO_TABLE:
    241  1.1  riastrad 		check_offset = 0x6a;
    242  1.1  riastrad 		break;
    243  1.1  riastrad 	case COMBIOS_DYN_CLK_2_TABLE:
    244  1.1  riastrad 		check_offset = 0x6c;
    245  1.1  riastrad 		break;
    246  1.1  riastrad 	case COMBIOS_POWER_CONNECTOR_INFO_TABLE:
    247  1.1  riastrad 		check_offset = 0x6e;
    248  1.1  riastrad 		break;
    249  1.1  riastrad 	case COMBIOS_I2C_INFO_TABLE:
    250  1.1  riastrad 		check_offset = 0x70;
    251  1.1  riastrad 		break;
    252  1.1  riastrad 		/* relative offset tables */
    253  1.1  riastrad 	case COMBIOS_ASIC_INIT_3_TABLE:	/* offset from misc info */
    254  1.1  riastrad 		check_offset =
    255  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
    256  1.1  riastrad 		if (check_offset) {
    257  1.1  riastrad 			rev = RBIOS8(check_offset);
    258  1.1  riastrad 			if (rev > 0) {
    259  1.1  riastrad 				check_offset = RBIOS16(check_offset + 0x3);
    260  1.1  riastrad 				if (check_offset)
    261  1.1  riastrad 					offset = check_offset;
    262  1.1  riastrad 			}
    263  1.1  riastrad 		}
    264  1.1  riastrad 		break;
    265  1.1  riastrad 	case COMBIOS_ASIC_INIT_4_TABLE:	/* offset from misc info */
    266  1.1  riastrad 		check_offset =
    267  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
    268  1.1  riastrad 		if (check_offset) {
    269  1.1  riastrad 			rev = RBIOS8(check_offset);
    270  1.1  riastrad 			if (rev > 0) {
    271  1.1  riastrad 				check_offset = RBIOS16(check_offset + 0x5);
    272  1.1  riastrad 				if (check_offset)
    273  1.1  riastrad 					offset = check_offset;
    274  1.1  riastrad 			}
    275  1.1  riastrad 		}
    276  1.1  riastrad 		break;
    277  1.1  riastrad 	case COMBIOS_DETECTED_MEM_TABLE:	/* offset from misc info */
    278  1.1  riastrad 		check_offset =
    279  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
    280  1.1  riastrad 		if (check_offset) {
    281  1.1  riastrad 			rev = RBIOS8(check_offset);
    282  1.1  riastrad 			if (rev > 0) {
    283  1.1  riastrad 				check_offset = RBIOS16(check_offset + 0x7);
    284  1.1  riastrad 				if (check_offset)
    285  1.1  riastrad 					offset = check_offset;
    286  1.1  riastrad 			}
    287  1.1  riastrad 		}
    288  1.1  riastrad 		break;
    289  1.1  riastrad 	case COMBIOS_ASIC_INIT_5_TABLE:	/* offset from misc info */
    290  1.1  riastrad 		check_offset =
    291  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_MISC_INFO_TABLE);
    292  1.1  riastrad 		if (check_offset) {
    293  1.1  riastrad 			rev = RBIOS8(check_offset);
    294  1.1  riastrad 			if (rev == 2) {
    295  1.1  riastrad 				check_offset = RBIOS16(check_offset + 0x9);
    296  1.1  riastrad 				if (check_offset)
    297  1.1  riastrad 					offset = check_offset;
    298  1.1  riastrad 			}
    299  1.1  riastrad 		}
    300  1.1  riastrad 		break;
    301  1.1  riastrad 	case COMBIOS_RAM_RESET_TABLE:	/* offset from mem config */
    302  1.1  riastrad 		check_offset =
    303  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
    304  1.1  riastrad 		if (check_offset) {
    305  1.1  riastrad 			while (RBIOS8(check_offset++));
    306  1.1  riastrad 			check_offset += 2;
    307  1.1  riastrad 			if (check_offset)
    308  1.1  riastrad 				offset = check_offset;
    309  1.1  riastrad 		}
    310  1.1  riastrad 		break;
    311  1.1  riastrad 	case COMBIOS_POWERPLAY_INFO_TABLE:	/* offset from mobile info */
    312  1.1  riastrad 		check_offset =
    313  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
    314  1.1  riastrad 		if (check_offset) {
    315  1.1  riastrad 			check_offset = RBIOS16(check_offset + 0x11);
    316  1.1  riastrad 			if (check_offset)
    317  1.1  riastrad 				offset = check_offset;
    318  1.1  riastrad 		}
    319  1.1  riastrad 		break;
    320  1.1  riastrad 	case COMBIOS_GPIO_INFO_TABLE:	/* offset from mobile info */
    321  1.1  riastrad 		check_offset =
    322  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
    323  1.1  riastrad 		if (check_offset) {
    324  1.1  riastrad 			check_offset = RBIOS16(check_offset + 0x13);
    325  1.1  riastrad 			if (check_offset)
    326  1.1  riastrad 				offset = check_offset;
    327  1.1  riastrad 		}
    328  1.1  riastrad 		break;
    329  1.1  riastrad 	case COMBIOS_LCD_DDC_INFO_TABLE:	/* offset from mobile info */
    330  1.1  riastrad 		check_offset =
    331  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
    332  1.1  riastrad 		if (check_offset) {
    333  1.1  riastrad 			check_offset = RBIOS16(check_offset + 0x15);
    334  1.1  riastrad 			if (check_offset)
    335  1.1  riastrad 				offset = check_offset;
    336  1.1  riastrad 		}
    337  1.1  riastrad 		break;
    338  1.1  riastrad 	case COMBIOS_TMDS_POWER_TABLE:	/* offset from mobile info */
    339  1.1  riastrad 		check_offset =
    340  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_MOBILE_INFO_TABLE);
    341  1.1  riastrad 		if (check_offset) {
    342  1.1  riastrad 			check_offset = RBIOS16(check_offset + 0x17);
    343  1.1  riastrad 			if (check_offset)
    344  1.1  riastrad 				offset = check_offset;
    345  1.1  riastrad 		}
    346  1.1  riastrad 		break;
    347  1.1  riastrad 	case COMBIOS_TMDS_POWER_ON_TABLE:	/* offset from tmds power */
    348  1.1  riastrad 		check_offset =
    349  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_TMDS_POWER_TABLE);
    350  1.1  riastrad 		if (check_offset) {
    351  1.1  riastrad 			check_offset = RBIOS16(check_offset + 0x2);
    352  1.1  riastrad 			if (check_offset)
    353  1.1  riastrad 				offset = check_offset;
    354  1.1  riastrad 		}
    355  1.1  riastrad 		break;
    356  1.1  riastrad 	case COMBIOS_TMDS_POWER_OFF_TABLE:	/* offset from tmds power */
    357  1.1  riastrad 		check_offset =
    358  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_TMDS_POWER_TABLE);
    359  1.1  riastrad 		if (check_offset) {
    360  1.1  riastrad 			check_offset = RBIOS16(check_offset + 0x4);
    361  1.1  riastrad 			if (check_offset)
    362  1.1  riastrad 				offset = check_offset;
    363  1.1  riastrad 		}
    364  1.1  riastrad 		break;
    365  1.1  riastrad 	default:
    366  1.1  riastrad 		check_offset = 0;
    367  1.1  riastrad 		break;
    368  1.1  riastrad 	}
    369  1.1  riastrad 
    370  1.1  riastrad 	size = RBIOS8(rdev->bios_header_start + 0x6);
    371  1.1  riastrad 	/* check absolute offset tables */
    372  1.1  riastrad 	if (table < COMBIOS_ASIC_INIT_3_TABLE && check_offset && check_offset < size)
    373  1.1  riastrad 		offset = RBIOS16(rdev->bios_header_start + check_offset);
    374  1.1  riastrad 
    375  1.1  riastrad 	return offset;
    376  1.1  riastrad }
    377  1.1  riastrad 
    378  1.1  riastrad bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev)
    379  1.1  riastrad {
    380  1.1  riastrad 	int edid_info, size;
    381  1.1  riastrad 	struct edid *edid;
    382  1.1  riastrad 	unsigned char *raw;
    383  1.1  riastrad 	edid_info = combios_get_table_offset(rdev->ddev, COMBIOS_HARDCODED_EDID_TABLE);
    384  1.1  riastrad 	if (!edid_info)
    385  1.1  riastrad 		return false;
    386  1.1  riastrad 
    387  1.1  riastrad 	raw = rdev->bios + edid_info;
    388  1.1  riastrad 	size = EDID_LENGTH * (raw[0x7e] + 1);
    389  1.1  riastrad 	edid = kmalloc(size, GFP_KERNEL);
    390  1.1  riastrad 	if (edid == NULL)
    391  1.1  riastrad 		return false;
    392  1.1  riastrad 
    393  1.1  riastrad 	memcpy((unsigned char *)edid, raw, size);
    394  1.1  riastrad 
    395  1.1  riastrad 	if (!drm_edid_is_valid(edid)) {
    396  1.1  riastrad 		kfree(edid);
    397  1.1  riastrad 		return false;
    398  1.1  riastrad 	}
    399  1.1  riastrad 
    400  1.1  riastrad 	rdev->mode_info.bios_hardcoded_edid = edid;
    401  1.1  riastrad 	rdev->mode_info.bios_hardcoded_edid_size = size;
    402  1.1  riastrad 	return true;
    403  1.1  riastrad }
    404  1.1  riastrad 
    405  1.1  riastrad /* this is used for atom LCDs as well */
    406  1.1  riastrad struct edid *
    407  1.1  riastrad radeon_bios_get_hardcoded_edid(struct radeon_device *rdev)
    408  1.1  riastrad {
    409  1.1  riastrad 	struct edid *edid;
    410  1.1  riastrad 
    411  1.1  riastrad 	if (rdev->mode_info.bios_hardcoded_edid) {
    412  1.1  riastrad 		edid = kmalloc(rdev->mode_info.bios_hardcoded_edid_size, GFP_KERNEL);
    413  1.1  riastrad 		if (edid) {
    414  1.1  riastrad 			memcpy((unsigned char *)edid,
    415  1.1  riastrad 			       (unsigned char *)rdev->mode_info.bios_hardcoded_edid,
    416  1.1  riastrad 			       rdev->mode_info.bios_hardcoded_edid_size);
    417  1.1  riastrad 			return edid;
    418  1.1  riastrad 		}
    419  1.1  riastrad 	}
    420  1.1  riastrad 	return NULL;
    421  1.1  riastrad }
    422  1.1  riastrad 
    423  1.1  riastrad static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
    424  1.1  riastrad 						       enum radeon_combios_ddc ddc,
    425  1.1  riastrad 						       u32 clk_mask,
    426  1.1  riastrad 						       u32 data_mask)
    427  1.1  riastrad {
    428  1.1  riastrad 	struct radeon_i2c_bus_rec i2c;
    429  1.1  riastrad 	int ddc_line = 0;
    430  1.1  riastrad 
    431  1.1  riastrad 	/* ddc id            = mask reg
    432  1.1  riastrad 	 * DDC_NONE_DETECTED = none
    433  1.1  riastrad 	 * DDC_DVI           = RADEON_GPIO_DVI_DDC
    434  1.1  riastrad 	 * DDC_VGA           = RADEON_GPIO_VGA_DDC
    435  1.1  riastrad 	 * DDC_LCD           = RADEON_GPIOPAD_MASK
    436  1.1  riastrad 	 * DDC_GPIO          = RADEON_MDGPIO_MASK
    437  1.1  riastrad 	 * r1xx
    438  1.1  riastrad 	 * DDC_MONID         = RADEON_GPIO_MONID
    439  1.1  riastrad 	 * DDC_CRT2          = RADEON_GPIO_CRT2_DDC
    440  1.1  riastrad 	 * r200
    441  1.1  riastrad 	 * DDC_MONID         = RADEON_GPIO_MONID
    442  1.1  riastrad 	 * DDC_CRT2          = RADEON_GPIO_DVI_DDC
    443  1.1  riastrad 	 * r300/r350
    444  1.1  riastrad 	 * DDC_MONID         = RADEON_GPIO_DVI_DDC
    445  1.1  riastrad 	 * DDC_CRT2          = RADEON_GPIO_DVI_DDC
    446  1.1  riastrad 	 * rv2xx/rv3xx
    447  1.1  riastrad 	 * DDC_MONID         = RADEON_GPIO_MONID
    448  1.1  riastrad 	 * DDC_CRT2          = RADEON_GPIO_MONID
    449  1.1  riastrad 	 * rs3xx/rs4xx
    450  1.1  riastrad 	 * DDC_MONID         = RADEON_GPIOPAD_MASK
    451  1.1  riastrad 	 * DDC_CRT2          = RADEON_GPIO_MONID
    452  1.1  riastrad 	 */
    453  1.1  riastrad 	switch (ddc) {
    454  1.1  riastrad 	case DDC_NONE_DETECTED:
    455  1.1  riastrad 	default:
    456  1.1  riastrad 		ddc_line = 0;
    457  1.1  riastrad 		break;
    458  1.1  riastrad 	case DDC_DVI:
    459  1.1  riastrad 		ddc_line = RADEON_GPIO_DVI_DDC;
    460  1.1  riastrad 		break;
    461  1.1  riastrad 	case DDC_VGA:
    462  1.1  riastrad 		ddc_line = RADEON_GPIO_VGA_DDC;
    463  1.1  riastrad 		break;
    464  1.1  riastrad 	case DDC_LCD:
    465  1.1  riastrad 		ddc_line = RADEON_GPIOPAD_MASK;
    466  1.1  riastrad 		break;
    467  1.1  riastrad 	case DDC_GPIO:
    468  1.1  riastrad 		ddc_line = RADEON_MDGPIO_MASK;
    469  1.1  riastrad 		break;
    470  1.1  riastrad 	case DDC_MONID:
    471  1.1  riastrad 		if (rdev->family == CHIP_RS300 ||
    472  1.1  riastrad 		    rdev->family == CHIP_RS400 ||
    473  1.1  riastrad 		    rdev->family == CHIP_RS480)
    474  1.1  riastrad 			ddc_line = RADEON_GPIOPAD_MASK;
    475  1.1  riastrad 		else if (rdev->family == CHIP_R300 ||
    476  1.1  riastrad 			 rdev->family == CHIP_R350) {
    477  1.1  riastrad 			ddc_line = RADEON_GPIO_DVI_DDC;
    478  1.1  riastrad 			ddc = DDC_DVI;
    479  1.1  riastrad 		} else
    480  1.1  riastrad 			ddc_line = RADEON_GPIO_MONID;
    481  1.1  riastrad 		break;
    482  1.1  riastrad 	case DDC_CRT2:
    483  1.1  riastrad 		if (rdev->family == CHIP_R200 ||
    484  1.1  riastrad 		    rdev->family == CHIP_R300 ||
    485  1.1  riastrad 		    rdev->family == CHIP_R350) {
    486  1.1  riastrad 			ddc_line = RADEON_GPIO_DVI_DDC;
    487  1.1  riastrad 			ddc = DDC_DVI;
    488  1.1  riastrad 		} else if (rdev->family == CHIP_RS300 ||
    489  1.1  riastrad 			   rdev->family == CHIP_RS400 ||
    490  1.1  riastrad 			   rdev->family == CHIP_RS480)
    491  1.1  riastrad 			ddc_line = RADEON_GPIO_MONID;
    492  1.1  riastrad 		else if (rdev->family >= CHIP_RV350) {
    493  1.1  riastrad 			ddc_line = RADEON_GPIO_MONID;
    494  1.1  riastrad 			ddc = DDC_MONID;
    495  1.1  riastrad 		} else
    496  1.1  riastrad 			ddc_line = RADEON_GPIO_CRT2_DDC;
    497  1.1  riastrad 		break;
    498  1.1  riastrad 	}
    499  1.1  riastrad 
    500  1.1  riastrad 	if (ddc_line == RADEON_GPIOPAD_MASK) {
    501  1.1  riastrad 		i2c.mask_clk_reg = RADEON_GPIOPAD_MASK;
    502  1.1  riastrad 		i2c.mask_data_reg = RADEON_GPIOPAD_MASK;
    503  1.1  riastrad 		i2c.a_clk_reg = RADEON_GPIOPAD_A;
    504  1.1  riastrad 		i2c.a_data_reg = RADEON_GPIOPAD_A;
    505  1.1  riastrad 		i2c.en_clk_reg = RADEON_GPIOPAD_EN;
    506  1.1  riastrad 		i2c.en_data_reg = RADEON_GPIOPAD_EN;
    507  1.1  riastrad 		i2c.y_clk_reg = RADEON_GPIOPAD_Y;
    508  1.1  riastrad 		i2c.y_data_reg = RADEON_GPIOPAD_Y;
    509  1.1  riastrad 	} else if (ddc_line == RADEON_MDGPIO_MASK) {
    510  1.1  riastrad 		i2c.mask_clk_reg = RADEON_MDGPIO_MASK;
    511  1.1  riastrad 		i2c.mask_data_reg = RADEON_MDGPIO_MASK;
    512  1.1  riastrad 		i2c.a_clk_reg = RADEON_MDGPIO_A;
    513  1.1  riastrad 		i2c.a_data_reg = RADEON_MDGPIO_A;
    514  1.1  riastrad 		i2c.en_clk_reg = RADEON_MDGPIO_EN;
    515  1.1  riastrad 		i2c.en_data_reg = RADEON_MDGPIO_EN;
    516  1.1  riastrad 		i2c.y_clk_reg = RADEON_MDGPIO_Y;
    517  1.1  riastrad 		i2c.y_data_reg = RADEON_MDGPIO_Y;
    518  1.1  riastrad 	} else {
    519  1.1  riastrad 		i2c.mask_clk_reg = ddc_line;
    520  1.1  riastrad 		i2c.mask_data_reg = ddc_line;
    521  1.1  riastrad 		i2c.a_clk_reg = ddc_line;
    522  1.1  riastrad 		i2c.a_data_reg = ddc_line;
    523  1.1  riastrad 		i2c.en_clk_reg = ddc_line;
    524  1.1  riastrad 		i2c.en_data_reg = ddc_line;
    525  1.1  riastrad 		i2c.y_clk_reg = ddc_line;
    526  1.1  riastrad 		i2c.y_data_reg = ddc_line;
    527  1.1  riastrad 	}
    528  1.1  riastrad 
    529  1.1  riastrad 	if (clk_mask && data_mask) {
    530  1.1  riastrad 		/* system specific masks */
    531  1.1  riastrad 		i2c.mask_clk_mask = clk_mask;
    532  1.1  riastrad 		i2c.mask_data_mask = data_mask;
    533  1.1  riastrad 		i2c.a_clk_mask = clk_mask;
    534  1.1  riastrad 		i2c.a_data_mask = data_mask;
    535  1.1  riastrad 		i2c.en_clk_mask = clk_mask;
    536  1.1  riastrad 		i2c.en_data_mask = data_mask;
    537  1.1  riastrad 		i2c.y_clk_mask = clk_mask;
    538  1.1  riastrad 		i2c.y_data_mask = data_mask;
    539  1.1  riastrad 	} else if ((ddc_line == RADEON_GPIOPAD_MASK) ||
    540  1.1  riastrad 		   (ddc_line == RADEON_MDGPIO_MASK)) {
    541  1.1  riastrad 		/* default gpiopad masks */
    542  1.1  riastrad 		i2c.mask_clk_mask = (0x20 << 8);
    543  1.1  riastrad 		i2c.mask_data_mask = 0x80;
    544  1.1  riastrad 		i2c.a_clk_mask = (0x20 << 8);
    545  1.1  riastrad 		i2c.a_data_mask = 0x80;
    546  1.1  riastrad 		i2c.en_clk_mask = (0x20 << 8);
    547  1.1  riastrad 		i2c.en_data_mask = 0x80;
    548  1.1  riastrad 		i2c.y_clk_mask = (0x20 << 8);
    549  1.1  riastrad 		i2c.y_data_mask = 0x80;
    550  1.1  riastrad 	} else {
    551  1.1  riastrad 		/* default masks for ddc pads */
    552  1.1  riastrad 		i2c.mask_clk_mask = RADEON_GPIO_MASK_1;
    553  1.1  riastrad 		i2c.mask_data_mask = RADEON_GPIO_MASK_0;
    554  1.1  riastrad 		i2c.a_clk_mask = RADEON_GPIO_A_1;
    555  1.1  riastrad 		i2c.a_data_mask = RADEON_GPIO_A_0;
    556  1.1  riastrad 		i2c.en_clk_mask = RADEON_GPIO_EN_1;
    557  1.1  riastrad 		i2c.en_data_mask = RADEON_GPIO_EN_0;
    558  1.1  riastrad 		i2c.y_clk_mask = RADEON_GPIO_Y_1;
    559  1.1  riastrad 		i2c.y_data_mask = RADEON_GPIO_Y_0;
    560  1.1  riastrad 	}
    561  1.1  riastrad 
    562  1.1  riastrad 	switch (rdev->family) {
    563  1.1  riastrad 	case CHIP_R100:
    564  1.1  riastrad 	case CHIP_RV100:
    565  1.1  riastrad 	case CHIP_RS100:
    566  1.1  riastrad 	case CHIP_RV200:
    567  1.1  riastrad 	case CHIP_RS200:
    568  1.1  riastrad 	case CHIP_RS300:
    569  1.1  riastrad 		switch (ddc_line) {
    570  1.1  riastrad 		case RADEON_GPIO_DVI_DDC:
    571  1.1  riastrad 			i2c.hw_capable = true;
    572  1.1  riastrad 			break;
    573  1.1  riastrad 		default:
    574  1.1  riastrad 			i2c.hw_capable = false;
    575  1.1  riastrad 			break;
    576  1.1  riastrad 		}
    577  1.1  riastrad 		break;
    578  1.1  riastrad 	case CHIP_R200:
    579  1.1  riastrad 		switch (ddc_line) {
    580  1.1  riastrad 		case RADEON_GPIO_DVI_DDC:
    581  1.1  riastrad 		case RADEON_GPIO_MONID:
    582  1.1  riastrad 			i2c.hw_capable = true;
    583  1.1  riastrad 			break;
    584  1.1  riastrad 		default:
    585  1.1  riastrad 			i2c.hw_capable = false;
    586  1.1  riastrad 			break;
    587  1.1  riastrad 		}
    588  1.1  riastrad 		break;
    589  1.1  riastrad 	case CHIP_RV250:
    590  1.1  riastrad 	case CHIP_RV280:
    591  1.1  riastrad 		switch (ddc_line) {
    592  1.1  riastrad 		case RADEON_GPIO_VGA_DDC:
    593  1.1  riastrad 		case RADEON_GPIO_DVI_DDC:
    594  1.1  riastrad 		case RADEON_GPIO_CRT2_DDC:
    595  1.1  riastrad 			i2c.hw_capable = true;
    596  1.1  riastrad 			break;
    597  1.1  riastrad 		default:
    598  1.1  riastrad 			i2c.hw_capable = false;
    599  1.1  riastrad 			break;
    600  1.1  riastrad 		}
    601  1.1  riastrad 		break;
    602  1.1  riastrad 	case CHIP_R300:
    603  1.1  riastrad 	case CHIP_R350:
    604  1.1  riastrad 		switch (ddc_line) {
    605  1.1  riastrad 		case RADEON_GPIO_VGA_DDC:
    606  1.1  riastrad 		case RADEON_GPIO_DVI_DDC:
    607  1.1  riastrad 			i2c.hw_capable = true;
    608  1.1  riastrad 			break;
    609  1.1  riastrad 		default:
    610  1.1  riastrad 			i2c.hw_capable = false;
    611  1.1  riastrad 			break;
    612  1.1  riastrad 		}
    613  1.1  riastrad 		break;
    614  1.1  riastrad 	case CHIP_RV350:
    615  1.1  riastrad 	case CHIP_RV380:
    616  1.1  riastrad 	case CHIP_RS400:
    617  1.1  riastrad 	case CHIP_RS480:
    618  1.1  riastrad 		switch (ddc_line) {
    619  1.1  riastrad 		case RADEON_GPIO_VGA_DDC:
    620  1.1  riastrad 		case RADEON_GPIO_DVI_DDC:
    621  1.1  riastrad 			i2c.hw_capable = true;
    622  1.1  riastrad 			break;
    623  1.1  riastrad 		case RADEON_GPIO_MONID:
    624  1.1  riastrad 			/* hw i2c on RADEON_GPIO_MONID doesn't seem to work
    625  1.1  riastrad 			 * reliably on some pre-r4xx hardware; not sure why.
    626  1.1  riastrad 			 */
    627  1.1  riastrad 			i2c.hw_capable = false;
    628  1.1  riastrad 			break;
    629  1.1  riastrad 		default:
    630  1.1  riastrad 			i2c.hw_capable = false;
    631  1.1  riastrad 			break;
    632  1.1  riastrad 		}
    633  1.1  riastrad 		break;
    634  1.1  riastrad 	default:
    635  1.1  riastrad 		i2c.hw_capable = false;
    636  1.1  riastrad 		break;
    637  1.1  riastrad 	}
    638  1.1  riastrad 	i2c.mm_i2c = false;
    639  1.1  riastrad 
    640  1.1  riastrad 	i2c.i2c_id = ddc;
    641  1.1  riastrad 	i2c.hpd = RADEON_HPD_NONE;
    642  1.1  riastrad 
    643  1.1  riastrad 	if (ddc_line)
    644  1.1  riastrad 		i2c.valid = true;
    645  1.1  riastrad 	else
    646  1.1  riastrad 		i2c.valid = false;
    647  1.1  riastrad 
    648  1.1  riastrad 	return i2c;
    649  1.1  riastrad }
    650  1.1  riastrad 
    651  1.1  riastrad static struct radeon_i2c_bus_rec radeon_combios_get_i2c_info_from_table(struct radeon_device *rdev)
    652  1.1  riastrad {
    653  1.1  riastrad 	struct drm_device *dev = rdev->ddev;
    654  1.1  riastrad 	struct radeon_i2c_bus_rec i2c;
    655  1.1  riastrad 	u16 offset;
    656  1.1  riastrad 	u8 id, blocks, clk, data;
    657  1.1  riastrad 	int i;
    658  1.1  riastrad 
    659  1.1  riastrad 	i2c.valid = false;
    660  1.1  riastrad 
    661  1.1  riastrad 	offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE);
    662  1.1  riastrad 	if (offset) {
    663  1.1  riastrad 		blocks = RBIOS8(offset + 2);
    664  1.1  riastrad 		for (i = 0; i < blocks; i++) {
    665  1.1  riastrad 			id = RBIOS8(offset + 3 + (i * 5) + 0);
    666  1.1  riastrad 			if (id == 136) {
    667  1.1  riastrad 				clk = RBIOS8(offset + 3 + (i * 5) + 3);
    668  1.1  riastrad 				data = RBIOS8(offset + 3 + (i * 5) + 4);
    669  1.1  riastrad 				/* gpiopad */
    670  1.1  riastrad 				i2c = combios_setup_i2c_bus(rdev, DDC_MONID,
    671  1.1  riastrad 							    (1 << clk), (1 << data));
    672  1.1  riastrad 				break;
    673  1.1  riastrad 			}
    674  1.1  riastrad 		}
    675  1.1  riastrad 	}
    676  1.1  riastrad 	return i2c;
    677  1.1  riastrad }
    678  1.1  riastrad 
    679  1.1  riastrad void radeon_combios_i2c_init(struct radeon_device *rdev)
    680  1.1  riastrad {
    681  1.1  riastrad 	struct drm_device *dev = rdev->ddev;
    682  1.1  riastrad 	struct radeon_i2c_bus_rec i2c;
    683  1.1  riastrad 
    684  1.1  riastrad 	/* actual hw pads
    685  1.1  riastrad 	 * r1xx/rs2xx/rs3xx
    686  1.1  riastrad 	 * 0x60, 0x64, 0x68, 0x6c, gpiopads, mm
    687  1.1  riastrad 	 * r200
    688  1.1  riastrad 	 * 0x60, 0x64, 0x68, mm
    689  1.1  riastrad 	 * r300/r350
    690  1.1  riastrad 	 * 0x60, 0x64, mm
    691  1.1  riastrad 	 * rv2xx/rv3xx/rs4xx
    692  1.1  riastrad 	 * 0x60, 0x64, 0x68, gpiopads, mm
    693  1.1  riastrad 	 */
    694  1.1  riastrad 
    695  1.1  riastrad 	/* 0x60 */
    696  1.1  riastrad 	i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
    697  1.1  riastrad 	rdev->i2c_bus[0] = radeon_i2c_create(dev, &i2c, "DVI_DDC");
    698  1.1  riastrad 	/* 0x64 */
    699  1.1  riastrad 	i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
    700  1.1  riastrad 	rdev->i2c_bus[1] = radeon_i2c_create(dev, &i2c, "VGA_DDC");
    701  1.1  riastrad 
    702  1.1  riastrad 	/* mm i2c */
    703  1.1  riastrad 	i2c.valid = true;
    704  1.1  riastrad 	i2c.hw_capable = true;
    705  1.1  riastrad 	i2c.mm_i2c = true;
    706  1.1  riastrad 	i2c.i2c_id = 0xa0;
    707  1.1  riastrad 	rdev->i2c_bus[2] = radeon_i2c_create(dev, &i2c, "MM_I2C");
    708  1.1  riastrad 
    709  1.1  riastrad 	if (rdev->family == CHIP_R300 ||
    710  1.1  riastrad 	    rdev->family == CHIP_R350) {
    711  1.1  riastrad 		/* only 2 sw i2c pads */
    712  1.1  riastrad 	} else if (rdev->family == CHIP_RS300 ||
    713  1.1  riastrad 		   rdev->family == CHIP_RS400 ||
    714  1.1  riastrad 		   rdev->family == CHIP_RS480) {
    715  1.1  riastrad 		/* 0x68 */
    716  1.1  riastrad 		i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
    717  1.1  riastrad 		rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
    718  1.1  riastrad 
    719  1.1  riastrad 		/* gpiopad */
    720  1.1  riastrad 		i2c = radeon_combios_get_i2c_info_from_table(rdev);
    721  1.1  riastrad 		if (i2c.valid)
    722  1.1  riastrad 			rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "GPIOPAD_MASK");
    723  1.1  riastrad 	} else if ((rdev->family == CHIP_R200) ||
    724  1.1  riastrad 		   (rdev->family >= CHIP_R300)) {
    725  1.1  riastrad 		/* 0x68 */
    726  1.1  riastrad 		i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
    727  1.1  riastrad 		rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
    728  1.1  riastrad 	} else {
    729  1.1  riastrad 		/* 0x68 */
    730  1.1  riastrad 		i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
    731  1.1  riastrad 		rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
    732  1.1  riastrad 		/* 0x6c */
    733  1.1  riastrad 		i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
    734  1.1  riastrad 		rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "CRT2_DDC");
    735  1.1  riastrad 	}
    736  1.1  riastrad }
    737  1.1  riastrad 
    738  1.1  riastrad bool radeon_combios_get_clock_info(struct drm_device *dev)
    739  1.1  riastrad {
    740  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
    741  1.1  riastrad 	uint16_t pll_info;
    742  1.1  riastrad 	struct radeon_pll *p1pll = &rdev->clock.p1pll;
    743  1.1  riastrad 	struct radeon_pll *p2pll = &rdev->clock.p2pll;
    744  1.1  riastrad 	struct radeon_pll *spll = &rdev->clock.spll;
    745  1.1  riastrad 	struct radeon_pll *mpll = &rdev->clock.mpll;
    746  1.1  riastrad 	int8_t rev;
    747  1.1  riastrad 	uint16_t sclk, mclk;
    748  1.1  riastrad 
    749  1.1  riastrad 	pll_info = combios_get_table_offset(dev, COMBIOS_PLL_INFO_TABLE);
    750  1.1  riastrad 	if (pll_info) {
    751  1.1  riastrad 		rev = RBIOS8(pll_info);
    752  1.1  riastrad 
    753  1.1  riastrad 		/* pixel clocks */
    754  1.1  riastrad 		p1pll->reference_freq = RBIOS16(pll_info + 0xe);
    755  1.1  riastrad 		p1pll->reference_div = RBIOS16(pll_info + 0x10);
    756  1.1  riastrad 		p1pll->pll_out_min = RBIOS32(pll_info + 0x12);
    757  1.1  riastrad 		p1pll->pll_out_max = RBIOS32(pll_info + 0x16);
    758  1.1  riastrad 		p1pll->lcd_pll_out_min = p1pll->pll_out_min;
    759  1.1  riastrad 		p1pll->lcd_pll_out_max = p1pll->pll_out_max;
    760  1.1  riastrad 
    761  1.1  riastrad 		if (rev > 9) {
    762  1.1  riastrad 			p1pll->pll_in_min = RBIOS32(pll_info + 0x36);
    763  1.1  riastrad 			p1pll->pll_in_max = RBIOS32(pll_info + 0x3a);
    764  1.1  riastrad 		} else {
    765  1.1  riastrad 			p1pll->pll_in_min = 40;
    766  1.1  riastrad 			p1pll->pll_in_max = 500;
    767  1.1  riastrad 		}
    768  1.1  riastrad 		*p2pll = *p1pll;
    769  1.1  riastrad 
    770  1.1  riastrad 		/* system clock */
    771  1.1  riastrad 		spll->reference_freq = RBIOS16(pll_info + 0x1a);
    772  1.1  riastrad 		spll->reference_div = RBIOS16(pll_info + 0x1c);
    773  1.1  riastrad 		spll->pll_out_min = RBIOS32(pll_info + 0x1e);
    774  1.1  riastrad 		spll->pll_out_max = RBIOS32(pll_info + 0x22);
    775  1.1  riastrad 
    776  1.1  riastrad 		if (rev > 10) {
    777  1.1  riastrad 			spll->pll_in_min = RBIOS32(pll_info + 0x48);
    778  1.1  riastrad 			spll->pll_in_max = RBIOS32(pll_info + 0x4c);
    779  1.1  riastrad 		} else {
    780  1.1  riastrad 			/* ??? */
    781  1.1  riastrad 			spll->pll_in_min = 40;
    782  1.1  riastrad 			spll->pll_in_max = 500;
    783  1.1  riastrad 		}
    784  1.1  riastrad 
    785  1.1  riastrad 		/* memory clock */
    786  1.1  riastrad 		mpll->reference_freq = RBIOS16(pll_info + 0x26);
    787  1.1  riastrad 		mpll->reference_div = RBIOS16(pll_info + 0x28);
    788  1.1  riastrad 		mpll->pll_out_min = RBIOS32(pll_info + 0x2a);
    789  1.1  riastrad 		mpll->pll_out_max = RBIOS32(pll_info + 0x2e);
    790  1.1  riastrad 
    791  1.1  riastrad 		if (rev > 10) {
    792  1.1  riastrad 			mpll->pll_in_min = RBIOS32(pll_info + 0x5a);
    793  1.1  riastrad 			mpll->pll_in_max = RBIOS32(pll_info + 0x5e);
    794  1.1  riastrad 		} else {
    795  1.1  riastrad 			/* ??? */
    796  1.1  riastrad 			mpll->pll_in_min = 40;
    797  1.1  riastrad 			mpll->pll_in_max = 500;
    798  1.1  riastrad 		}
    799  1.1  riastrad 
    800  1.1  riastrad 		/* default sclk/mclk */
    801  1.1  riastrad 		sclk = RBIOS16(pll_info + 0xa);
    802  1.1  riastrad 		mclk = RBIOS16(pll_info + 0x8);
    803  1.1  riastrad 		if (sclk == 0)
    804  1.1  riastrad 			sclk = 200 * 100;
    805  1.1  riastrad 		if (mclk == 0)
    806  1.1  riastrad 			mclk = 200 * 100;
    807  1.1  riastrad 
    808  1.1  riastrad 		rdev->clock.default_sclk = sclk;
    809  1.1  riastrad 		rdev->clock.default_mclk = mclk;
    810  1.1  riastrad 
    811  1.1  riastrad 		if (RBIOS32(pll_info + 0x16))
    812  1.1  riastrad 			rdev->clock.max_pixel_clock = RBIOS32(pll_info + 0x16);
    813  1.1  riastrad 		else
    814  1.1  riastrad 			rdev->clock.max_pixel_clock = 35000; /* might need something asic specific */
    815  1.1  riastrad 
    816  1.1  riastrad 		return true;
    817  1.1  riastrad 	}
    818  1.1  riastrad 	return false;
    819  1.1  riastrad }
    820  1.1  riastrad 
    821  1.1  riastrad bool radeon_combios_sideport_present(struct radeon_device *rdev)
    822  1.1  riastrad {
    823  1.1  riastrad 	struct drm_device *dev = rdev->ddev;
    824  1.1  riastrad 	u16 igp_info;
    825  1.1  riastrad 
    826  1.1  riastrad 	/* sideport is AMD only */
    827  1.1  riastrad 	if (rdev->family == CHIP_RS400)
    828  1.1  riastrad 		return false;
    829  1.1  riastrad 
    830  1.1  riastrad 	igp_info = combios_get_table_offset(dev, COMBIOS_INTEGRATED_SYSTEM_INFO_TABLE);
    831  1.1  riastrad 
    832  1.1  riastrad 	if (igp_info) {
    833  1.1  riastrad 		if (RBIOS16(igp_info + 0x4))
    834  1.1  riastrad 			return true;
    835  1.1  riastrad 	}
    836  1.1  riastrad 	return false;
    837  1.1  riastrad }
    838  1.1  riastrad 
    839  1.1  riastrad static const uint32_t default_primarydac_adj[CHIP_LAST] = {
    840  1.1  riastrad 	0x00000808,		/* r100  */
    841  1.1  riastrad 	0x00000808,		/* rv100 */
    842  1.1  riastrad 	0x00000808,		/* rs100 */
    843  1.1  riastrad 	0x00000808,		/* rv200 */
    844  1.1  riastrad 	0x00000808,		/* rs200 */
    845  1.1  riastrad 	0x00000808,		/* r200  */
    846  1.1  riastrad 	0x00000808,		/* rv250 */
    847  1.1  riastrad 	0x00000000,		/* rs300 */
    848  1.1  riastrad 	0x00000808,		/* rv280 */
    849  1.1  riastrad 	0x00000808,		/* r300  */
    850  1.1  riastrad 	0x00000808,		/* r350  */
    851  1.1  riastrad 	0x00000808,		/* rv350 */
    852  1.1  riastrad 	0x00000808,		/* rv380 */
    853  1.1  riastrad 	0x00000808,		/* r420  */
    854  1.1  riastrad 	0x00000808,		/* r423  */
    855  1.1  riastrad 	0x00000808,		/* rv410 */
    856  1.1  riastrad 	0x00000000,		/* rs400 */
    857  1.1  riastrad 	0x00000000,		/* rs480 */
    858  1.1  riastrad };
    859  1.1  riastrad 
    860  1.1  riastrad static void radeon_legacy_get_primary_dac_info_from_table(struct radeon_device *rdev,
    861  1.1  riastrad 							  struct radeon_encoder_primary_dac *p_dac)
    862  1.1  riastrad {
    863  1.1  riastrad 	p_dac->ps2_pdac_adj = default_primarydac_adj[rdev->family];
    864  1.1  riastrad 	return;
    865  1.1  riastrad }
    866  1.1  riastrad 
    867  1.1  riastrad struct radeon_encoder_primary_dac *radeon_combios_get_primary_dac_info(struct
    868  1.1  riastrad 								       radeon_encoder
    869  1.1  riastrad 								       *encoder)
    870  1.1  riastrad {
    871  1.1  riastrad 	struct drm_device *dev = encoder->base.dev;
    872  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
    873  1.1  riastrad 	uint16_t dac_info;
    874  1.1  riastrad 	uint8_t rev, bg, dac;
    875  1.1  riastrad 	struct radeon_encoder_primary_dac *p_dac = NULL;
    876  1.1  riastrad 	int found = 0;
    877  1.1  riastrad 
    878  1.1  riastrad 	p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac),
    879  1.1  riastrad 			GFP_KERNEL);
    880  1.1  riastrad 
    881  1.1  riastrad 	if (!p_dac)
    882  1.1  riastrad 		return NULL;
    883  1.1  riastrad 
    884  1.1  riastrad 	/* check CRT table */
    885  1.1  riastrad 	dac_info = combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
    886  1.1  riastrad 	if (dac_info) {
    887  1.1  riastrad 		rev = RBIOS8(dac_info) & 0x3;
    888  1.1  riastrad 		if (rev < 2) {
    889  1.1  riastrad 			bg = RBIOS8(dac_info + 0x2) & 0xf;
    890  1.1  riastrad 			dac = (RBIOS8(dac_info + 0x2) >> 4) & 0xf;
    891  1.1  riastrad 			p_dac->ps2_pdac_adj = (bg << 8) | (dac);
    892  1.1  riastrad 		} else {
    893  1.1  riastrad 			bg = RBIOS8(dac_info + 0x2) & 0xf;
    894  1.1  riastrad 			dac = RBIOS8(dac_info + 0x3) & 0xf;
    895  1.1  riastrad 			p_dac->ps2_pdac_adj = (bg << 8) | (dac);
    896  1.1  riastrad 		}
    897  1.1  riastrad 		/* if the values are zeros, use the table */
    898  1.1  riastrad 		if ((dac == 0) || (bg == 0))
    899  1.1  riastrad 			found = 0;
    900  1.1  riastrad 		else
    901  1.1  riastrad 			found = 1;
    902  1.1  riastrad 	}
    903  1.1  riastrad 
    904  1.1  riastrad 	/* quirks */
    905  1.1  riastrad 	/* Radeon 7000 (RV100) */
    906  1.1  riastrad 	if (((dev->pdev->device == 0x5159) &&
    907  1.1  riastrad 	    (dev->pdev->subsystem_vendor == 0x174B) &&
    908  1.1  riastrad 	    (dev->pdev->subsystem_device == 0x7c28)) ||
    909  1.1  riastrad 	/* Radeon 9100 (R200) */
    910  1.1  riastrad 	   ((dev->pdev->device == 0x514D) &&
    911  1.1  riastrad 	    (dev->pdev->subsystem_vendor == 0x174B) &&
    912  1.1  riastrad 	    (dev->pdev->subsystem_device == 0x7149))) {
    913  1.1  riastrad 		/* vbios value is bad, use the default */
    914  1.1  riastrad 		found = 0;
    915  1.1  riastrad 	}
    916  1.1  riastrad 
    917  1.1  riastrad 	if (!found) /* fallback to defaults */
    918  1.1  riastrad 		radeon_legacy_get_primary_dac_info_from_table(rdev, p_dac);
    919  1.1  riastrad 
    920  1.1  riastrad 	return p_dac;
    921  1.1  riastrad }
    922  1.1  riastrad 
    923  1.1  riastrad enum radeon_tv_std
    924  1.1  riastrad radeon_combios_get_tv_info(struct radeon_device *rdev)
    925  1.1  riastrad {
    926  1.1  riastrad 	struct drm_device *dev = rdev->ddev;
    927  1.1  riastrad 	uint16_t tv_info;
    928  1.1  riastrad 	enum radeon_tv_std tv_std = TV_STD_NTSC;
    929  1.1  riastrad 
    930  1.1  riastrad 	tv_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
    931  1.1  riastrad 	if (tv_info) {
    932  1.1  riastrad 		if (RBIOS8(tv_info + 6) == 'T') {
    933  1.1  riastrad 			switch (RBIOS8(tv_info + 7) & 0xf) {
    934  1.1  riastrad 			case 1:
    935  1.1  riastrad 				tv_std = TV_STD_NTSC;
    936  1.1  riastrad 				DRM_DEBUG_KMS("Default TV standard: NTSC\n");
    937  1.1  riastrad 				break;
    938  1.1  riastrad 			case 2:
    939  1.1  riastrad 				tv_std = TV_STD_PAL;
    940  1.1  riastrad 				DRM_DEBUG_KMS("Default TV standard: PAL\n");
    941  1.1  riastrad 				break;
    942  1.1  riastrad 			case 3:
    943  1.1  riastrad 				tv_std = TV_STD_PAL_M;
    944  1.1  riastrad 				DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
    945  1.1  riastrad 				break;
    946  1.1  riastrad 			case 4:
    947  1.1  riastrad 				tv_std = TV_STD_PAL_60;
    948  1.1  riastrad 				DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
    949  1.1  riastrad 				break;
    950  1.1  riastrad 			case 5:
    951  1.1  riastrad 				tv_std = TV_STD_NTSC_J;
    952  1.1  riastrad 				DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
    953  1.1  riastrad 				break;
    954  1.1  riastrad 			case 6:
    955  1.1  riastrad 				tv_std = TV_STD_SCART_PAL;
    956  1.1  riastrad 				DRM_DEBUG_KMS("Default TV standard: SCART-PAL\n");
    957  1.1  riastrad 				break;
    958  1.1  riastrad 			default:
    959  1.1  riastrad 				tv_std = TV_STD_NTSC;
    960  1.1  riastrad 				DRM_DEBUG_KMS
    961  1.1  riastrad 				    ("Unknown TV standard; defaulting to NTSC\n");
    962  1.1  riastrad 				break;
    963  1.1  riastrad 			}
    964  1.1  riastrad 
    965  1.1  riastrad 			switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) {
    966  1.1  riastrad 			case 0:
    967  1.1  riastrad 				DRM_DEBUG_KMS("29.498928713 MHz TV ref clk\n");
    968  1.1  riastrad 				break;
    969  1.1  riastrad 			case 1:
    970  1.1  riastrad 				DRM_DEBUG_KMS("28.636360000 MHz TV ref clk\n");
    971  1.1  riastrad 				break;
    972  1.1  riastrad 			case 2:
    973  1.1  riastrad 				DRM_DEBUG_KMS("14.318180000 MHz TV ref clk\n");
    974  1.1  riastrad 				break;
    975  1.1  riastrad 			case 3:
    976  1.1  riastrad 				DRM_DEBUG_KMS("27.000000000 MHz TV ref clk\n");
    977  1.1  riastrad 				break;
    978  1.1  riastrad 			default:
    979  1.1  riastrad 				break;
    980  1.1  riastrad 			}
    981  1.1  riastrad 		}
    982  1.1  riastrad 	}
    983  1.1  riastrad 	return tv_std;
    984  1.1  riastrad }
    985  1.1  riastrad 
    986  1.1  riastrad static const uint32_t default_tvdac_adj[CHIP_LAST] = {
    987  1.1  riastrad 	0x00000000,		/* r100  */
    988  1.1  riastrad 	0x00280000,		/* rv100 */
    989  1.1  riastrad 	0x00000000,		/* rs100 */
    990  1.1  riastrad 	0x00880000,		/* rv200 */
    991  1.1  riastrad 	0x00000000,		/* rs200 */
    992  1.1  riastrad 	0x00000000,		/* r200  */
    993  1.1  riastrad 	0x00770000,		/* rv250 */
    994  1.1  riastrad 	0x00290000,		/* rs300 */
    995  1.1  riastrad 	0x00560000,		/* rv280 */
    996  1.1  riastrad 	0x00780000,		/* r300  */
    997  1.1  riastrad 	0x00770000,		/* r350  */
    998  1.1  riastrad 	0x00780000,		/* rv350 */
    999  1.1  riastrad 	0x00780000,		/* rv380 */
   1000  1.1  riastrad 	0x01080000,		/* r420  */
   1001  1.1  riastrad 	0x01080000,		/* r423  */
   1002  1.1  riastrad 	0x01080000,		/* rv410 */
   1003  1.1  riastrad 	0x00780000,		/* rs400 */
   1004  1.1  riastrad 	0x00780000,		/* rs480 */
   1005  1.1  riastrad };
   1006  1.1  riastrad 
   1007  1.1  riastrad static void radeon_legacy_get_tv_dac_info_from_table(struct radeon_device *rdev,
   1008  1.1  riastrad 						     struct radeon_encoder_tv_dac *tv_dac)
   1009  1.1  riastrad {
   1010  1.1  riastrad 	tv_dac->ps2_tvdac_adj = default_tvdac_adj[rdev->family];
   1011  1.1  riastrad 	if ((rdev->flags & RADEON_IS_MOBILITY) && (rdev->family == CHIP_RV250))
   1012  1.1  riastrad 		tv_dac->ps2_tvdac_adj = 0x00880000;
   1013  1.1  riastrad 	tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
   1014  1.1  riastrad 	tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
   1015  1.1  riastrad 	return;
   1016  1.1  riastrad }
   1017  1.1  riastrad 
   1018  1.1  riastrad struct radeon_encoder_tv_dac *radeon_combios_get_tv_dac_info(struct
   1019  1.1  riastrad 							     radeon_encoder
   1020  1.1  riastrad 							     *encoder)
   1021  1.1  riastrad {
   1022  1.1  riastrad 	struct drm_device *dev = encoder->base.dev;
   1023  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   1024  1.1  riastrad 	uint16_t dac_info;
   1025  1.1  riastrad 	uint8_t rev, bg, dac;
   1026  1.1  riastrad 	struct radeon_encoder_tv_dac *tv_dac = NULL;
   1027  1.1  riastrad 	int found = 0;
   1028  1.1  riastrad 
   1029  1.1  riastrad 	tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
   1030  1.1  riastrad 	if (!tv_dac)
   1031  1.1  riastrad 		return NULL;
   1032  1.1  riastrad 
   1033  1.1  riastrad 	/* first check TV table */
   1034  1.1  riastrad 	dac_info = combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
   1035  1.1  riastrad 	if (dac_info) {
   1036  1.1  riastrad 		rev = RBIOS8(dac_info + 0x3);
   1037  1.1  riastrad 		if (rev > 4) {
   1038  1.1  riastrad 			bg = RBIOS8(dac_info + 0xc) & 0xf;
   1039  1.1  riastrad 			dac = RBIOS8(dac_info + 0xd) & 0xf;
   1040  1.1  riastrad 			tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
   1041  1.1  riastrad 
   1042  1.1  riastrad 			bg = RBIOS8(dac_info + 0xe) & 0xf;
   1043  1.1  riastrad 			dac = RBIOS8(dac_info + 0xf) & 0xf;
   1044  1.1  riastrad 			tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
   1045  1.1  riastrad 
   1046  1.1  riastrad 			bg = RBIOS8(dac_info + 0x10) & 0xf;
   1047  1.1  riastrad 			dac = RBIOS8(dac_info + 0x11) & 0xf;
   1048  1.1  riastrad 			tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
   1049  1.1  riastrad 			/* if the values are all zeros, use the table */
   1050  1.1  riastrad 			if (tv_dac->ps2_tvdac_adj)
   1051  1.1  riastrad 				found = 1;
   1052  1.1  riastrad 		} else if (rev > 1) {
   1053  1.1  riastrad 			bg = RBIOS8(dac_info + 0xc) & 0xf;
   1054  1.1  riastrad 			dac = (RBIOS8(dac_info + 0xc) >> 4) & 0xf;
   1055  1.1  riastrad 			tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
   1056  1.1  riastrad 
   1057  1.1  riastrad 			bg = RBIOS8(dac_info + 0xd) & 0xf;
   1058  1.1  riastrad 			dac = (RBIOS8(dac_info + 0xd) >> 4) & 0xf;
   1059  1.1  riastrad 			tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
   1060  1.1  riastrad 
   1061  1.1  riastrad 			bg = RBIOS8(dac_info + 0xe) & 0xf;
   1062  1.1  riastrad 			dac = (RBIOS8(dac_info + 0xe) >> 4) & 0xf;
   1063  1.1  riastrad 			tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
   1064  1.1  riastrad 			/* if the values are all zeros, use the table */
   1065  1.1  riastrad 			if (tv_dac->ps2_tvdac_adj)
   1066  1.1  riastrad 				found = 1;
   1067  1.1  riastrad 		}
   1068  1.1  riastrad 		tv_dac->tv_std = radeon_combios_get_tv_info(rdev);
   1069  1.1  riastrad 	}
   1070  1.1  riastrad 	if (!found) {
   1071  1.1  riastrad 		/* then check CRT table */
   1072  1.1  riastrad 		dac_info =
   1073  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
   1074  1.1  riastrad 		if (dac_info) {
   1075  1.1  riastrad 			rev = RBIOS8(dac_info) & 0x3;
   1076  1.1  riastrad 			if (rev < 2) {
   1077  1.1  riastrad 				bg = RBIOS8(dac_info + 0x3) & 0xf;
   1078  1.1  riastrad 				dac = (RBIOS8(dac_info + 0x3) >> 4) & 0xf;
   1079  1.1  riastrad 				tv_dac->ps2_tvdac_adj =
   1080  1.1  riastrad 				    (bg << 16) | (dac << 20);
   1081  1.1  riastrad 				tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
   1082  1.1  riastrad 				tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
   1083  1.1  riastrad 				/* if the values are all zeros, use the table */
   1084  1.1  riastrad 				if (tv_dac->ps2_tvdac_adj)
   1085  1.1  riastrad 					found = 1;
   1086  1.1  riastrad 			} else {
   1087  1.1  riastrad 				bg = RBIOS8(dac_info + 0x4) & 0xf;
   1088  1.1  riastrad 				dac = RBIOS8(dac_info + 0x5) & 0xf;
   1089  1.1  riastrad 				tv_dac->ps2_tvdac_adj =
   1090  1.1  riastrad 				    (bg << 16) | (dac << 20);
   1091  1.1  riastrad 				tv_dac->pal_tvdac_adj = tv_dac->ps2_tvdac_adj;
   1092  1.1  riastrad 				tv_dac->ntsc_tvdac_adj = tv_dac->ps2_tvdac_adj;
   1093  1.1  riastrad 				/* if the values are all zeros, use the table */
   1094  1.1  riastrad 				if (tv_dac->ps2_tvdac_adj)
   1095  1.1  riastrad 					found = 1;
   1096  1.1  riastrad 			}
   1097  1.1  riastrad 		} else {
   1098  1.1  riastrad 			DRM_INFO("No TV DAC info found in BIOS\n");
   1099  1.1  riastrad 		}
   1100  1.1  riastrad 	}
   1101  1.1  riastrad 
   1102  1.1  riastrad 	if (!found) /* fallback to defaults */
   1103  1.1  riastrad 		radeon_legacy_get_tv_dac_info_from_table(rdev, tv_dac);
   1104  1.1  riastrad 
   1105  1.1  riastrad 	return tv_dac;
   1106  1.1  riastrad }
   1107  1.1  riastrad 
   1108  1.1  riastrad static struct radeon_encoder_lvds *radeon_legacy_get_lvds_info_from_regs(struct
   1109  1.1  riastrad 									 radeon_device
   1110  1.1  riastrad 									 *rdev)
   1111  1.1  riastrad {
   1112  1.1  riastrad 	struct radeon_encoder_lvds *lvds = NULL;
   1113  1.1  riastrad 	uint32_t fp_vert_stretch, fp_horz_stretch;
   1114  1.1  riastrad 	uint32_t ppll_div_sel, ppll_val;
   1115  1.1  riastrad 	uint32_t lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
   1116  1.1  riastrad 
   1117  1.1  riastrad 	lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
   1118  1.1  riastrad 
   1119  1.1  riastrad 	if (!lvds)
   1120  1.1  riastrad 		return NULL;
   1121  1.1  riastrad 
   1122  1.1  riastrad 	fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH);
   1123  1.1  riastrad 	fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH);
   1124  1.1  riastrad 
   1125  1.1  riastrad 	/* These should be fail-safe defaults, fingers crossed */
   1126  1.1  riastrad 	lvds->panel_pwr_delay = 200;
   1127  1.1  riastrad 	lvds->panel_vcc_delay = 2000;
   1128  1.1  riastrad 
   1129  1.1  riastrad 	lvds->lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
   1130  1.1  riastrad 	lvds->panel_digon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) & 0xf;
   1131  1.1  riastrad 	lvds->panel_blon_delay = (lvds_ss_gen_cntl >> RADEON_LVDS_PWRSEQ_DELAY2_SHIFT) & 0xf;
   1132  1.1  riastrad 
   1133  1.1  riastrad 	if (fp_vert_stretch & RADEON_VERT_STRETCH_ENABLE)
   1134  1.1  riastrad 		lvds->native_mode.vdisplay =
   1135  1.1  riastrad 		    ((fp_vert_stretch & RADEON_VERT_PANEL_SIZE) >>
   1136  1.1  riastrad 		     RADEON_VERT_PANEL_SHIFT) + 1;
   1137  1.1  riastrad 	else
   1138  1.1  riastrad 		lvds->native_mode.vdisplay =
   1139  1.1  riastrad 		    (RREG32(RADEON_CRTC_V_TOTAL_DISP) >> 16) + 1;
   1140  1.1  riastrad 
   1141  1.1  riastrad 	if (fp_horz_stretch & RADEON_HORZ_STRETCH_ENABLE)
   1142  1.1  riastrad 		lvds->native_mode.hdisplay =
   1143  1.1  riastrad 		    (((fp_horz_stretch & RADEON_HORZ_PANEL_SIZE) >>
   1144  1.1  riastrad 		      RADEON_HORZ_PANEL_SHIFT) + 1) * 8;
   1145  1.1  riastrad 	else
   1146  1.1  riastrad 		lvds->native_mode.hdisplay =
   1147  1.1  riastrad 		    ((RREG32(RADEON_CRTC_H_TOTAL_DISP) >> 16) + 1) * 8;
   1148  1.1  riastrad 
   1149  1.1  riastrad 	if ((lvds->native_mode.hdisplay < 640) ||
   1150  1.1  riastrad 	    (lvds->native_mode.vdisplay < 480)) {
   1151  1.1  riastrad 		lvds->native_mode.hdisplay = 640;
   1152  1.1  riastrad 		lvds->native_mode.vdisplay = 480;
   1153  1.1  riastrad 	}
   1154  1.1  riastrad 
   1155  1.1  riastrad 	ppll_div_sel = RREG8(RADEON_CLOCK_CNTL_INDEX + 1) & 0x3;
   1156  1.1  riastrad 	ppll_val = RREG32_PLL(RADEON_PPLL_DIV_0 + ppll_div_sel);
   1157  1.1  riastrad 	if ((ppll_val & 0x000707ff) == 0x1bb)
   1158  1.1  riastrad 		lvds->use_bios_dividers = false;
   1159  1.1  riastrad 	else {
   1160  1.1  riastrad 		lvds->panel_ref_divider =
   1161  1.1  riastrad 		    RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
   1162  1.1  riastrad 		lvds->panel_post_divider = (ppll_val >> 16) & 0x7;
   1163  1.1  riastrad 		lvds->panel_fb_divider = ppll_val & 0x7ff;
   1164  1.1  riastrad 
   1165  1.1  riastrad 		if ((lvds->panel_ref_divider != 0) &&
   1166  1.1  riastrad 		    (lvds->panel_fb_divider > 3))
   1167  1.1  riastrad 			lvds->use_bios_dividers = true;
   1168  1.1  riastrad 	}
   1169  1.1  riastrad 	lvds->panel_vcc_delay = 200;
   1170  1.1  riastrad 
   1171  1.1  riastrad 	DRM_INFO("Panel info derived from registers\n");
   1172  1.1  riastrad 	DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
   1173  1.1  riastrad 		 lvds->native_mode.vdisplay);
   1174  1.1  riastrad 
   1175  1.1  riastrad 	return lvds;
   1176  1.1  riastrad }
   1177  1.1  riastrad 
   1178  1.1  riastrad struct radeon_encoder_lvds *radeon_combios_get_lvds_info(struct radeon_encoder
   1179  1.1  riastrad 							 *encoder)
   1180  1.1  riastrad {
   1181  1.1  riastrad 	struct drm_device *dev = encoder->base.dev;
   1182  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   1183  1.1  riastrad 	uint16_t lcd_info;
   1184  1.1  riastrad 	uint32_t panel_setup;
   1185  1.1  riastrad 	char stmp[30];
   1186  1.1  riastrad 	int tmp, i;
   1187  1.1  riastrad 	struct radeon_encoder_lvds *lvds = NULL;
   1188  1.1  riastrad 
   1189  1.1  riastrad 	lcd_info = combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
   1190  1.1  riastrad 
   1191  1.1  riastrad 	if (lcd_info) {
   1192  1.1  riastrad 		lvds = kzalloc(sizeof(struct radeon_encoder_lvds), GFP_KERNEL);
   1193  1.1  riastrad 
   1194  1.1  riastrad 		if (!lvds)
   1195  1.1  riastrad 			return NULL;
   1196  1.1  riastrad 
   1197  1.1  riastrad 		for (i = 0; i < 24; i++)
   1198  1.1  riastrad 			stmp[i] = RBIOS8(lcd_info + i + 1);
   1199  1.1  riastrad 		stmp[24] = 0;
   1200  1.1  riastrad 
   1201  1.1  riastrad 		DRM_INFO("Panel ID String: %s\n", stmp);
   1202  1.1  riastrad 
   1203  1.1  riastrad 		lvds->native_mode.hdisplay = RBIOS16(lcd_info + 0x19);
   1204  1.1  riastrad 		lvds->native_mode.vdisplay = RBIOS16(lcd_info + 0x1b);
   1205  1.1  riastrad 
   1206  1.1  riastrad 		DRM_INFO("Panel Size %dx%d\n", lvds->native_mode.hdisplay,
   1207  1.1  riastrad 			 lvds->native_mode.vdisplay);
   1208  1.1  riastrad 
   1209  1.1  riastrad 		lvds->panel_vcc_delay = RBIOS16(lcd_info + 0x2c);
   1210  1.1  riastrad 		lvds->panel_vcc_delay = min_t(u16, lvds->panel_vcc_delay, 2000);
   1211  1.1  riastrad 
   1212  1.1  riastrad 		lvds->panel_pwr_delay = RBIOS8(lcd_info + 0x24);
   1213  1.1  riastrad 		lvds->panel_digon_delay = RBIOS16(lcd_info + 0x38) & 0xf;
   1214  1.1  riastrad 		lvds->panel_blon_delay = (RBIOS16(lcd_info + 0x38) >> 4) & 0xf;
   1215  1.1  riastrad 
   1216  1.1  riastrad 		lvds->panel_ref_divider = RBIOS16(lcd_info + 0x2e);
   1217  1.1  riastrad 		lvds->panel_post_divider = RBIOS8(lcd_info + 0x30);
   1218  1.1  riastrad 		lvds->panel_fb_divider = RBIOS16(lcd_info + 0x31);
   1219  1.1  riastrad 		if ((lvds->panel_ref_divider != 0) &&
   1220  1.1  riastrad 		    (lvds->panel_fb_divider > 3))
   1221  1.1  riastrad 			lvds->use_bios_dividers = true;
   1222  1.1  riastrad 
   1223  1.1  riastrad 		panel_setup = RBIOS32(lcd_info + 0x39);
   1224  1.1  riastrad 		lvds->lvds_gen_cntl = 0xff00;
   1225  1.1  riastrad 		if (panel_setup & 0x1)
   1226  1.1  riastrad 			lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_FORMAT;
   1227  1.1  riastrad 
   1228  1.1  riastrad 		if ((panel_setup >> 4) & 0x1)
   1229  1.1  riastrad 			lvds->lvds_gen_cntl |= RADEON_LVDS_PANEL_TYPE;
   1230  1.1  riastrad 
   1231  1.1  riastrad 		switch ((panel_setup >> 8) & 0x7) {
   1232  1.1  riastrad 		case 0:
   1233  1.1  riastrad 			lvds->lvds_gen_cntl |= RADEON_LVDS_NO_FM;
   1234  1.1  riastrad 			break;
   1235  1.1  riastrad 		case 1:
   1236  1.1  riastrad 			lvds->lvds_gen_cntl |= RADEON_LVDS_2_GREY;
   1237  1.1  riastrad 			break;
   1238  1.1  riastrad 		case 2:
   1239  1.1  riastrad 			lvds->lvds_gen_cntl |= RADEON_LVDS_4_GREY;
   1240  1.1  riastrad 			break;
   1241  1.1  riastrad 		default:
   1242  1.1  riastrad 			break;
   1243  1.1  riastrad 		}
   1244  1.1  riastrad 
   1245  1.1  riastrad 		if ((panel_setup >> 16) & 0x1)
   1246  1.1  riastrad 			lvds->lvds_gen_cntl |= RADEON_LVDS_FP_POL_LOW;
   1247  1.1  riastrad 
   1248  1.1  riastrad 		if ((panel_setup >> 17) & 0x1)
   1249  1.1  riastrad 			lvds->lvds_gen_cntl |= RADEON_LVDS_LP_POL_LOW;
   1250  1.1  riastrad 
   1251  1.1  riastrad 		if ((panel_setup >> 18) & 0x1)
   1252  1.1  riastrad 			lvds->lvds_gen_cntl |= RADEON_LVDS_DTM_POL_LOW;
   1253  1.1  riastrad 
   1254  1.1  riastrad 		if ((panel_setup >> 23) & 0x1)
   1255  1.1  riastrad 			lvds->lvds_gen_cntl |= RADEON_LVDS_BL_CLK_SEL;
   1256  1.1  riastrad 
   1257  1.1  riastrad 		lvds->lvds_gen_cntl |= (panel_setup & 0xf0000000);
   1258  1.1  riastrad 
   1259  1.1  riastrad 		for (i = 0; i < 32; i++) {
   1260  1.1  riastrad 			tmp = RBIOS16(lcd_info + 64 + i * 2);
   1261  1.1  riastrad 			if (tmp == 0)
   1262  1.1  riastrad 				break;
   1263  1.1  riastrad 
   1264  1.1  riastrad 			if ((RBIOS16(tmp) == lvds->native_mode.hdisplay) &&
   1265  1.1  riastrad 			    (RBIOS16(tmp + 2) == lvds->native_mode.vdisplay)) {
   1266  1.3  riastrad 				u32 hss = (RBIOS16(tmp + 21) - RBIOS16(tmp + 19) - 1) * 8;
   1267  1.3  riastrad 
   1268  1.3  riastrad 				if (hss > lvds->native_mode.hdisplay)
   1269  1.3  riastrad 					hss = (10 - 1) * 8;
   1270  1.3  riastrad 
   1271  1.1  riastrad 				lvds->native_mode.htotal = lvds->native_mode.hdisplay +
   1272  1.1  riastrad 					(RBIOS16(tmp + 17) - RBIOS16(tmp + 19)) * 8;
   1273  1.1  riastrad 				lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
   1274  1.3  riastrad 					hss;
   1275  1.1  riastrad 				lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
   1276  1.1  riastrad 					(RBIOS8(tmp + 23) * 8);
   1277  1.1  riastrad 
   1278  1.1  riastrad 				lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
   1279  1.1  riastrad 					(RBIOS16(tmp + 24) - RBIOS16(tmp + 26));
   1280  1.1  riastrad 				lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
   1281  1.1  riastrad 					((RBIOS16(tmp + 28) & 0x7ff) - RBIOS16(tmp + 26));
   1282  1.1  riastrad 				lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
   1283  1.1  riastrad 					((RBIOS16(tmp + 28) & 0xf800) >> 11);
   1284  1.1  riastrad 
   1285  1.1  riastrad 				lvds->native_mode.clock = RBIOS16(tmp + 9) * 10;
   1286  1.1  riastrad 				lvds->native_mode.flags = 0;
   1287  1.1  riastrad 				/* set crtc values */
   1288  1.1  riastrad 				drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
   1289  1.1  riastrad 
   1290  1.1  riastrad 			}
   1291  1.1  riastrad 		}
   1292  1.1  riastrad 	} else {
   1293  1.1  riastrad 		DRM_INFO("No panel info found in BIOS\n");
   1294  1.1  riastrad 		lvds = radeon_legacy_get_lvds_info_from_regs(rdev);
   1295  1.1  riastrad 	}
   1296  1.1  riastrad 
   1297  1.1  riastrad 	if (lvds)
   1298  1.1  riastrad 		encoder->native_mode = lvds->native_mode;
   1299  1.1  riastrad 	return lvds;
   1300  1.1  riastrad }
   1301  1.1  riastrad 
   1302  1.1  riastrad static const struct radeon_tmds_pll default_tmds_pll[CHIP_LAST][4] = {
   1303  1.1  riastrad 	{{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}},	/* CHIP_R100  */
   1304  1.1  riastrad 	{{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}},	/* CHIP_RV100 */
   1305  1.1  riastrad 	{{0, 0}, {0, 0}, {0, 0}, {0, 0}},	/* CHIP_RS100 */
   1306  1.1  riastrad 	{{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}},	/* CHIP_RV200 */
   1307  1.1  riastrad 	{{12000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}},	/* CHIP_RS200 */
   1308  1.1  riastrad 	{{15000, 0xa1b}, {0xffffffff, 0xa3f}, {0, 0}, {0, 0}},	/* CHIP_R200  */
   1309  1.1  riastrad 	{{15500, 0x81b}, {0xffffffff, 0x83f}, {0, 0}, {0, 0}},	/* CHIP_RV250 */
   1310  1.1  riastrad 	{{0, 0}, {0, 0}, {0, 0}, {0, 0}},	/* CHIP_RS300 */
   1311  1.1  riastrad 	{{13000, 0x400f4}, {15000, 0x400f7}, {0xffffffff, 0x40111}, {0, 0}},	/* CHIP_RV280 */
   1312  1.1  riastrad 	{{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}},	/* CHIP_R300  */
   1313  1.1  riastrad 	{{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}},	/* CHIP_R350  */
   1314  1.1  riastrad 	{{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}},	/* CHIP_RV350 */
   1315  1.1  riastrad 	{{15000, 0xb0155}, {0xffffffff, 0xb01cb}, {0, 0}, {0, 0}},	/* CHIP_RV380 */
   1316  1.1  riastrad 	{{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}},	/* CHIP_R420  */
   1317  1.1  riastrad 	{{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}},	/* CHIP_R423  */
   1318  1.1  riastrad 	{{0xffffffff, 0xb01cb}, {0, 0}, {0, 0}, {0, 0}},	/* CHIP_RV410 */
   1319  1.1  riastrad 	{ {0, 0}, {0, 0}, {0, 0}, {0, 0} },	/* CHIP_RS400 */
   1320  1.1  riastrad 	{ {0, 0}, {0, 0}, {0, 0}, {0, 0} },	/* CHIP_RS480 */
   1321  1.1  riastrad };
   1322  1.1  riastrad 
   1323  1.1  riastrad bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
   1324  1.1  riastrad 					    struct radeon_encoder_int_tmds *tmds)
   1325  1.1  riastrad {
   1326  1.1  riastrad 	struct drm_device *dev = encoder->base.dev;
   1327  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   1328  1.1  riastrad 	int i;
   1329  1.1  riastrad 
   1330  1.1  riastrad 	for (i = 0; i < 4; i++) {
   1331  1.1  riastrad 		tmds->tmds_pll[i].value =
   1332  1.1  riastrad 			default_tmds_pll[rdev->family][i].value;
   1333  1.1  riastrad 		tmds->tmds_pll[i].freq = default_tmds_pll[rdev->family][i].freq;
   1334  1.1  riastrad 	}
   1335  1.1  riastrad 
   1336  1.1  riastrad 	return true;
   1337  1.1  riastrad }
   1338  1.1  riastrad 
   1339  1.1  riastrad bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
   1340  1.1  riastrad 					      struct radeon_encoder_int_tmds *tmds)
   1341  1.1  riastrad {
   1342  1.1  riastrad 	struct drm_device *dev = encoder->base.dev;
   1343  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   1344  1.1  riastrad 	uint16_t tmds_info;
   1345  1.1  riastrad 	int i, n;
   1346  1.1  riastrad 	uint8_t ver;
   1347  1.1  riastrad 
   1348  1.1  riastrad 	tmds_info = combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
   1349  1.1  riastrad 
   1350  1.1  riastrad 	if (tmds_info) {
   1351  1.1  riastrad 		ver = RBIOS8(tmds_info);
   1352  1.1  riastrad 		DRM_DEBUG_KMS("DFP table revision: %d\n", ver);
   1353  1.1  riastrad 		if (ver == 3) {
   1354  1.1  riastrad 			n = RBIOS8(tmds_info + 5) + 1;
   1355  1.1  riastrad 			if (n > 4)
   1356  1.1  riastrad 				n = 4;
   1357  1.1  riastrad 			for (i = 0; i < n; i++) {
   1358  1.1  riastrad 				tmds->tmds_pll[i].value =
   1359  1.1  riastrad 				    RBIOS32(tmds_info + i * 10 + 0x08);
   1360  1.1  riastrad 				tmds->tmds_pll[i].freq =
   1361  1.1  riastrad 				    RBIOS16(tmds_info + i * 10 + 0x10);
   1362  1.1  riastrad 				DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
   1363  1.1  riastrad 					  tmds->tmds_pll[i].freq,
   1364  1.1  riastrad 					  tmds->tmds_pll[i].value);
   1365  1.1  riastrad 			}
   1366  1.1  riastrad 		} else if (ver == 4) {
   1367  1.1  riastrad 			int stride = 0;
   1368  1.1  riastrad 			n = RBIOS8(tmds_info + 5) + 1;
   1369  1.1  riastrad 			if (n > 4)
   1370  1.1  riastrad 				n = 4;
   1371  1.1  riastrad 			for (i = 0; i < n; i++) {
   1372  1.1  riastrad 				tmds->tmds_pll[i].value =
   1373  1.1  riastrad 				    RBIOS32(tmds_info + stride + 0x08);
   1374  1.1  riastrad 				tmds->tmds_pll[i].freq =
   1375  1.1  riastrad 				    RBIOS16(tmds_info + stride + 0x10);
   1376  1.1  riastrad 				if (i == 0)
   1377  1.1  riastrad 					stride += 10;
   1378  1.1  riastrad 				else
   1379  1.1  riastrad 					stride += 6;
   1380  1.1  riastrad 				DRM_DEBUG_KMS("TMDS PLL From COMBIOS %u %x\n",
   1381  1.1  riastrad 					  tmds->tmds_pll[i].freq,
   1382  1.1  riastrad 					  tmds->tmds_pll[i].value);
   1383  1.1  riastrad 			}
   1384  1.1  riastrad 		}
   1385  1.1  riastrad 	} else {
   1386  1.1  riastrad 		DRM_INFO("No TMDS info found in BIOS\n");
   1387  1.1  riastrad 		return false;
   1388  1.1  riastrad 	}
   1389  1.1  riastrad 	return true;
   1390  1.1  riastrad }
   1391  1.1  riastrad 
   1392  1.1  riastrad bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
   1393  1.1  riastrad 						struct radeon_encoder_ext_tmds *tmds)
   1394  1.1  riastrad {
   1395  1.1  riastrad 	struct drm_device *dev = encoder->base.dev;
   1396  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   1397  1.1  riastrad 	struct radeon_i2c_bus_rec i2c_bus;
   1398  1.1  riastrad 
   1399  1.1  riastrad 	/* default for macs */
   1400  1.1  riastrad 	i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
   1401  1.1  riastrad 	tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
   1402  1.1  riastrad 
   1403  1.1  riastrad 	/* XXX some macs have duallink chips */
   1404  1.1  riastrad 	switch (rdev->mode_info.connector_table) {
   1405  1.1  riastrad 	case CT_POWERBOOK_EXTERNAL:
   1406  1.1  riastrad 	case CT_MINI_EXTERNAL:
   1407  1.1  riastrad 	default:
   1408  1.1  riastrad 		tmds->dvo_chip = DVO_SIL164;
   1409  1.1  riastrad 		tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
   1410  1.1  riastrad 		break;
   1411  1.1  riastrad 	}
   1412  1.1  riastrad 
   1413  1.1  riastrad 	return true;
   1414  1.1  riastrad }
   1415  1.1  riastrad 
   1416  1.1  riastrad bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
   1417  1.1  riastrad 						  struct radeon_encoder_ext_tmds *tmds)
   1418  1.1  riastrad {
   1419  1.1  riastrad 	struct drm_device *dev = encoder->base.dev;
   1420  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   1421  1.1  riastrad 	uint16_t offset;
   1422  1.1  riastrad 	uint8_t ver;
   1423  1.1  riastrad 	enum radeon_combios_ddc gpio;
   1424  1.1  riastrad 	struct radeon_i2c_bus_rec i2c_bus;
   1425  1.1  riastrad 
   1426  1.1  riastrad 	tmds->i2c_bus = NULL;
   1427  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP) {
   1428  1.1  riastrad 		i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
   1429  1.1  riastrad 		tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
   1430  1.1  riastrad 		tmds->dvo_chip = DVO_SIL164;
   1431  1.1  riastrad 		tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
   1432  1.1  riastrad 	} else {
   1433  1.1  riastrad 		offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
   1434  1.1  riastrad 		if (offset) {
   1435  1.1  riastrad 			ver = RBIOS8(offset);
   1436  1.1  riastrad 			DRM_DEBUG_KMS("External TMDS Table revision: %d\n", ver);
   1437  1.1  riastrad 			tmds->slave_addr = RBIOS8(offset + 4 + 2);
   1438  1.1  riastrad 			tmds->slave_addr >>= 1; /* 7 bit addressing */
   1439  1.1  riastrad 			gpio = RBIOS8(offset + 4 + 3);
   1440  1.1  riastrad 			if (gpio == DDC_LCD) {
   1441  1.1  riastrad 				/* MM i2c */
   1442  1.1  riastrad 				i2c_bus.valid = true;
   1443  1.1  riastrad 				i2c_bus.hw_capable = true;
   1444  1.1  riastrad 				i2c_bus.mm_i2c = true;
   1445  1.1  riastrad 				i2c_bus.i2c_id = 0xa0;
   1446  1.1  riastrad 			} else
   1447  1.1  riastrad 				i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
   1448  1.1  riastrad 			tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
   1449  1.1  riastrad 		}
   1450  1.1  riastrad 	}
   1451  1.1  riastrad 
   1452  1.1  riastrad 	if (!tmds->i2c_bus) {
   1453  1.1  riastrad 		DRM_INFO("No valid Ext TMDS info found in BIOS\n");
   1454  1.1  riastrad 		return false;
   1455  1.1  riastrad 	}
   1456  1.1  riastrad 
   1457  1.1  riastrad 	return true;
   1458  1.1  riastrad }
   1459  1.1  riastrad 
   1460  1.1  riastrad bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
   1461  1.1  riastrad {
   1462  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   1463  1.1  riastrad 	struct radeon_i2c_bus_rec ddc_i2c;
   1464  1.1  riastrad 	struct radeon_hpd hpd;
   1465  1.1  riastrad 
   1466  1.1  riastrad 	rdev->mode_info.connector_table = radeon_connector_table;
   1467  1.1  riastrad 	if (rdev->mode_info.connector_table == CT_NONE) {
   1468  1.1  riastrad #ifdef CONFIG_PPC_PMAC
   1469  1.1  riastrad 		if (of_machine_is_compatible("PowerBook3,3")) {
   1470  1.1  riastrad 			/* powerbook with VGA */
   1471  1.1  riastrad 			rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
   1472  1.1  riastrad 		} else if (of_machine_is_compatible("PowerBook3,4") ||
   1473  1.1  riastrad 			   of_machine_is_compatible("PowerBook3,5")) {
   1474  1.1  riastrad 			/* powerbook with internal tmds */
   1475  1.1  riastrad 			rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
   1476  1.1  riastrad 		} else if (of_machine_is_compatible("PowerBook5,1") ||
   1477  1.1  riastrad 			   of_machine_is_compatible("PowerBook5,2") ||
   1478  1.1  riastrad 			   of_machine_is_compatible("PowerBook5,3") ||
   1479  1.1  riastrad 			   of_machine_is_compatible("PowerBook5,4") ||
   1480  1.1  riastrad 			   of_machine_is_compatible("PowerBook5,5")) {
   1481  1.1  riastrad 			/* powerbook with external single link tmds (sil164) */
   1482  1.1  riastrad 			rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
   1483  1.1  riastrad 		} else if (of_machine_is_compatible("PowerBook5,6")) {
   1484  1.1  riastrad 			/* powerbook with external dual or single link tmds */
   1485  1.1  riastrad 			rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
   1486  1.1  riastrad 		} else if (of_machine_is_compatible("PowerBook5,7") ||
   1487  1.1  riastrad 			   of_machine_is_compatible("PowerBook5,8") ||
   1488  1.1  riastrad 			   of_machine_is_compatible("PowerBook5,9")) {
   1489  1.1  riastrad 			/* PowerBook6,2 ? */
   1490  1.1  riastrad 			/* powerbook with external dual link tmds (sil1178?) */
   1491  1.1  riastrad 			rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
   1492  1.1  riastrad 		} else if (of_machine_is_compatible("PowerBook4,1") ||
   1493  1.1  riastrad 			   of_machine_is_compatible("PowerBook4,2") ||
   1494  1.1  riastrad 			   of_machine_is_compatible("PowerBook4,3") ||
   1495  1.1  riastrad 			   of_machine_is_compatible("PowerBook6,3") ||
   1496  1.1  riastrad 			   of_machine_is_compatible("PowerBook6,5") ||
   1497  1.1  riastrad 			   of_machine_is_compatible("PowerBook6,7")) {
   1498  1.1  riastrad 			/* ibook */
   1499  1.1  riastrad 			rdev->mode_info.connector_table = CT_IBOOK;
   1500  1.1  riastrad 		} else if (of_machine_is_compatible("PowerMac3,5")) {
   1501  1.1  riastrad 			/* PowerMac G4 Silver radeon 7500 */
   1502  1.1  riastrad 			rdev->mode_info.connector_table = CT_MAC_G4_SILVER;
   1503  1.1  riastrad 		} else if (of_machine_is_compatible("PowerMac4,4")) {
   1504  1.1  riastrad 			/* emac */
   1505  1.1  riastrad 			rdev->mode_info.connector_table = CT_EMAC;
   1506  1.1  riastrad 		} else if (of_machine_is_compatible("PowerMac10,1")) {
   1507  1.1  riastrad 			/* mini with internal tmds */
   1508  1.1  riastrad 			rdev->mode_info.connector_table = CT_MINI_INTERNAL;
   1509  1.1  riastrad 		} else if (of_machine_is_compatible("PowerMac10,2")) {
   1510  1.1  riastrad 			/* mini with external tmds */
   1511  1.1  riastrad 			rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
   1512  1.1  riastrad 		} else if (of_machine_is_compatible("PowerMac12,1")) {
   1513  1.1  riastrad 			/* PowerMac8,1 ? */
   1514  1.1  riastrad 			/* imac g5 isight */
   1515  1.1  riastrad 			rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
   1516  1.1  riastrad 		} else if ((rdev->pdev->device == 0x4a48) &&
   1517  1.1  riastrad 			   (rdev->pdev->subsystem_vendor == 0x1002) &&
   1518  1.1  riastrad 			   (rdev->pdev->subsystem_device == 0x4a48)) {
   1519  1.1  riastrad 			/* Mac X800 */
   1520  1.1  riastrad 			rdev->mode_info.connector_table = CT_MAC_X800;
   1521  1.1  riastrad 		} else if ((of_machine_is_compatible("PowerMac7,2") ||
   1522  1.1  riastrad 			    of_machine_is_compatible("PowerMac7,3")) &&
   1523  1.1  riastrad 			   (rdev->pdev->device == 0x4150) &&
   1524  1.1  riastrad 			   (rdev->pdev->subsystem_vendor == 0x1002) &&
   1525  1.1  riastrad 			   (rdev->pdev->subsystem_device == 0x4150)) {
   1526  1.1  riastrad 			/* Mac G5 tower 9600 */
   1527  1.1  riastrad 			rdev->mode_info.connector_table = CT_MAC_G5_9600;
   1528  1.1  riastrad 		} else if ((rdev->pdev->device == 0x4c66) &&
   1529  1.1  riastrad 			   (rdev->pdev->subsystem_vendor == 0x1002) &&
   1530  1.1  riastrad 			   (rdev->pdev->subsystem_device == 0x4c66)) {
   1531  1.1  riastrad 			/* SAM440ep RV250 embedded board */
   1532  1.1  riastrad 			rdev->mode_info.connector_table = CT_SAM440EP;
   1533  1.1  riastrad 		} else
   1534  1.1  riastrad #endif /* CONFIG_PPC_PMAC */
   1535  1.1  riastrad #ifdef CONFIG_PPC64
   1536  1.1  riastrad 		if (ASIC_IS_RN50(rdev))
   1537  1.1  riastrad 			rdev->mode_info.connector_table = CT_RN50_POWER;
   1538  1.1  riastrad 		else
   1539  1.1  riastrad #endif
   1540  1.1  riastrad 			rdev->mode_info.connector_table = CT_GENERIC;
   1541  1.1  riastrad 	}
   1542  1.1  riastrad 
   1543  1.1  riastrad 	switch (rdev->mode_info.connector_table) {
   1544  1.1  riastrad 	case CT_GENERIC:
   1545  1.1  riastrad 		DRM_INFO("Connector Table: %d (generic)\n",
   1546  1.1  riastrad 			 rdev->mode_info.connector_table);
   1547  1.1  riastrad 		/* these are the most common settings */
   1548  1.1  riastrad 		if (rdev->flags & RADEON_SINGLE_CRTC) {
   1549  1.1  riastrad 			/* VGA - primary dac */
   1550  1.1  riastrad 			ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   1551  1.1  riastrad 			hpd.hpd = RADEON_HPD_NONE;
   1552  1.1  riastrad 			radeon_add_legacy_encoder(dev,
   1553  1.1  riastrad 						  radeon_get_encoder_enum(dev,
   1554  1.1  riastrad 									ATOM_DEVICE_CRT1_SUPPORT,
   1555  1.1  riastrad 									1),
   1556  1.1  riastrad 						  ATOM_DEVICE_CRT1_SUPPORT);
   1557  1.1  riastrad 			radeon_add_legacy_connector(dev, 0,
   1558  1.1  riastrad 						    ATOM_DEVICE_CRT1_SUPPORT,
   1559  1.1  riastrad 						    DRM_MODE_CONNECTOR_VGA,
   1560  1.1  riastrad 						    &ddc_i2c,
   1561  1.1  riastrad 						    CONNECTOR_OBJECT_ID_VGA,
   1562  1.1  riastrad 						    &hpd);
   1563  1.1  riastrad 		} else if (rdev->flags & RADEON_IS_MOBILITY) {
   1564  1.1  riastrad 			/* LVDS */
   1565  1.1  riastrad 			ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
   1566  1.1  riastrad 			hpd.hpd = RADEON_HPD_NONE;
   1567  1.1  riastrad 			radeon_add_legacy_encoder(dev,
   1568  1.1  riastrad 						  radeon_get_encoder_enum(dev,
   1569  1.1  riastrad 									ATOM_DEVICE_LCD1_SUPPORT,
   1570  1.1  riastrad 									0),
   1571  1.1  riastrad 						  ATOM_DEVICE_LCD1_SUPPORT);
   1572  1.1  riastrad 			radeon_add_legacy_connector(dev, 0,
   1573  1.1  riastrad 						    ATOM_DEVICE_LCD1_SUPPORT,
   1574  1.1  riastrad 						    DRM_MODE_CONNECTOR_LVDS,
   1575  1.1  riastrad 						    &ddc_i2c,
   1576  1.1  riastrad 						    CONNECTOR_OBJECT_ID_LVDS,
   1577  1.1  riastrad 						    &hpd);
   1578  1.1  riastrad 
   1579  1.1  riastrad 			/* VGA - primary dac */
   1580  1.1  riastrad 			ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   1581  1.1  riastrad 			hpd.hpd = RADEON_HPD_NONE;
   1582  1.1  riastrad 			radeon_add_legacy_encoder(dev,
   1583  1.1  riastrad 						  radeon_get_encoder_enum(dev,
   1584  1.1  riastrad 									ATOM_DEVICE_CRT1_SUPPORT,
   1585  1.1  riastrad 									1),
   1586  1.1  riastrad 						  ATOM_DEVICE_CRT1_SUPPORT);
   1587  1.1  riastrad 			radeon_add_legacy_connector(dev, 1,
   1588  1.1  riastrad 						    ATOM_DEVICE_CRT1_SUPPORT,
   1589  1.1  riastrad 						    DRM_MODE_CONNECTOR_VGA,
   1590  1.1  riastrad 						    &ddc_i2c,
   1591  1.1  riastrad 						    CONNECTOR_OBJECT_ID_VGA,
   1592  1.1  riastrad 						    &hpd);
   1593  1.1  riastrad 		} else {
   1594  1.1  riastrad 			/* DVI-I - tv dac, int tmds */
   1595  1.1  riastrad 			ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   1596  1.1  riastrad 			hpd.hpd = RADEON_HPD_1;
   1597  1.1  riastrad 			radeon_add_legacy_encoder(dev,
   1598  1.1  riastrad 						  radeon_get_encoder_enum(dev,
   1599  1.1  riastrad 									ATOM_DEVICE_DFP1_SUPPORT,
   1600  1.1  riastrad 									0),
   1601  1.1  riastrad 						  ATOM_DEVICE_DFP1_SUPPORT);
   1602  1.1  riastrad 			radeon_add_legacy_encoder(dev,
   1603  1.1  riastrad 						  radeon_get_encoder_enum(dev,
   1604  1.1  riastrad 									ATOM_DEVICE_CRT2_SUPPORT,
   1605  1.1  riastrad 									2),
   1606  1.1  riastrad 						  ATOM_DEVICE_CRT2_SUPPORT);
   1607  1.1  riastrad 			radeon_add_legacy_connector(dev, 0,
   1608  1.1  riastrad 						    ATOM_DEVICE_DFP1_SUPPORT |
   1609  1.1  riastrad 						    ATOM_DEVICE_CRT2_SUPPORT,
   1610  1.1  riastrad 						    DRM_MODE_CONNECTOR_DVII,
   1611  1.1  riastrad 						    &ddc_i2c,
   1612  1.1  riastrad 						    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
   1613  1.1  riastrad 						    &hpd);
   1614  1.1  riastrad 
   1615  1.1  riastrad 			/* VGA - primary dac */
   1616  1.1  riastrad 			ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   1617  1.1  riastrad 			hpd.hpd = RADEON_HPD_NONE;
   1618  1.1  riastrad 			radeon_add_legacy_encoder(dev,
   1619  1.1  riastrad 						  radeon_get_encoder_enum(dev,
   1620  1.1  riastrad 									ATOM_DEVICE_CRT1_SUPPORT,
   1621  1.1  riastrad 									1),
   1622  1.1  riastrad 						  ATOM_DEVICE_CRT1_SUPPORT);
   1623  1.1  riastrad 			radeon_add_legacy_connector(dev, 1,
   1624  1.1  riastrad 						    ATOM_DEVICE_CRT1_SUPPORT,
   1625  1.1  riastrad 						    DRM_MODE_CONNECTOR_VGA,
   1626  1.1  riastrad 						    &ddc_i2c,
   1627  1.1  riastrad 						    CONNECTOR_OBJECT_ID_VGA,
   1628  1.1  riastrad 						    &hpd);
   1629  1.1  riastrad 		}
   1630  1.1  riastrad 
   1631  1.1  riastrad 		if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
   1632  1.1  riastrad 			/* TV - tv dac */
   1633  1.1  riastrad 			ddc_i2c.valid = false;
   1634  1.1  riastrad 			hpd.hpd = RADEON_HPD_NONE;
   1635  1.1  riastrad 			radeon_add_legacy_encoder(dev,
   1636  1.1  riastrad 						  radeon_get_encoder_enum(dev,
   1637  1.1  riastrad 									ATOM_DEVICE_TV1_SUPPORT,
   1638  1.1  riastrad 									2),
   1639  1.1  riastrad 						  ATOM_DEVICE_TV1_SUPPORT);
   1640  1.1  riastrad 			radeon_add_legacy_connector(dev, 2,
   1641  1.1  riastrad 						    ATOM_DEVICE_TV1_SUPPORT,
   1642  1.1  riastrad 						    DRM_MODE_CONNECTOR_SVIDEO,
   1643  1.1  riastrad 						    &ddc_i2c,
   1644  1.1  riastrad 						    CONNECTOR_OBJECT_ID_SVIDEO,
   1645  1.1  riastrad 						    &hpd);
   1646  1.1  riastrad 		}
   1647  1.1  riastrad 		break;
   1648  1.1  riastrad 	case CT_IBOOK:
   1649  1.1  riastrad 		DRM_INFO("Connector Table: %d (ibook)\n",
   1650  1.1  riastrad 			 rdev->mode_info.connector_table);
   1651  1.1  riastrad 		/* LVDS */
   1652  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   1653  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1654  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1655  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1656  1.1  riastrad 								ATOM_DEVICE_LCD1_SUPPORT,
   1657  1.1  riastrad 								0),
   1658  1.1  riastrad 					  ATOM_DEVICE_LCD1_SUPPORT);
   1659  1.1  riastrad 		radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
   1660  1.1  riastrad 					    DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
   1661  1.1  riastrad 					    CONNECTOR_OBJECT_ID_LVDS,
   1662  1.1  riastrad 					    &hpd);
   1663  1.1  riastrad 		/* VGA - TV DAC */
   1664  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   1665  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1666  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1667  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1668  1.1  riastrad 								ATOM_DEVICE_CRT2_SUPPORT,
   1669  1.1  riastrad 								2),
   1670  1.1  riastrad 					  ATOM_DEVICE_CRT2_SUPPORT);
   1671  1.1  riastrad 		radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
   1672  1.1  riastrad 					    DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
   1673  1.1  riastrad 					    CONNECTOR_OBJECT_ID_VGA,
   1674  1.1  riastrad 					    &hpd);
   1675  1.1  riastrad 		/* TV - TV DAC */
   1676  1.1  riastrad 		ddc_i2c.valid = false;
   1677  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1678  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1679  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1680  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   1681  1.1  riastrad 								2),
   1682  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   1683  1.1  riastrad 		radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
   1684  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   1685  1.1  riastrad 					    &ddc_i2c,
   1686  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   1687  1.1  riastrad 					    &hpd);
   1688  1.1  riastrad 		break;
   1689  1.1  riastrad 	case CT_POWERBOOK_EXTERNAL:
   1690  1.1  riastrad 		DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
   1691  1.1  riastrad 			 rdev->mode_info.connector_table);
   1692  1.1  riastrad 		/* LVDS */
   1693  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   1694  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1695  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1696  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1697  1.1  riastrad 								ATOM_DEVICE_LCD1_SUPPORT,
   1698  1.1  riastrad 								0),
   1699  1.1  riastrad 					  ATOM_DEVICE_LCD1_SUPPORT);
   1700  1.1  riastrad 		radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
   1701  1.1  riastrad 					    DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
   1702  1.1  riastrad 					    CONNECTOR_OBJECT_ID_LVDS,
   1703  1.1  riastrad 					    &hpd);
   1704  1.1  riastrad 		/* DVI-I - primary dac, ext tmds */
   1705  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   1706  1.1  riastrad 		hpd.hpd = RADEON_HPD_2; /* ??? */
   1707  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1708  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1709  1.1  riastrad 								ATOM_DEVICE_DFP2_SUPPORT,
   1710  1.1  riastrad 								0),
   1711  1.1  riastrad 					  ATOM_DEVICE_DFP2_SUPPORT);
   1712  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1713  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1714  1.1  riastrad 								ATOM_DEVICE_CRT1_SUPPORT,
   1715  1.1  riastrad 								1),
   1716  1.1  riastrad 					  ATOM_DEVICE_CRT1_SUPPORT);
   1717  1.1  riastrad 		/* XXX some are SL */
   1718  1.1  riastrad 		radeon_add_legacy_connector(dev, 1,
   1719  1.1  riastrad 					    ATOM_DEVICE_DFP2_SUPPORT |
   1720  1.1  riastrad 					    ATOM_DEVICE_CRT1_SUPPORT,
   1721  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
   1722  1.1  riastrad 					    CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
   1723  1.1  riastrad 					    &hpd);
   1724  1.1  riastrad 		/* TV - TV DAC */
   1725  1.1  riastrad 		ddc_i2c.valid = false;
   1726  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1727  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1728  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1729  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   1730  1.1  riastrad 								2),
   1731  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   1732  1.1  riastrad 		radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
   1733  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   1734  1.1  riastrad 					    &ddc_i2c,
   1735  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   1736  1.1  riastrad 					    &hpd);
   1737  1.1  riastrad 		break;
   1738  1.1  riastrad 	case CT_POWERBOOK_INTERNAL:
   1739  1.1  riastrad 		DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
   1740  1.1  riastrad 			 rdev->mode_info.connector_table);
   1741  1.1  riastrad 		/* LVDS */
   1742  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   1743  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1744  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1745  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1746  1.1  riastrad 								ATOM_DEVICE_LCD1_SUPPORT,
   1747  1.1  riastrad 								0),
   1748  1.1  riastrad 					  ATOM_DEVICE_LCD1_SUPPORT);
   1749  1.1  riastrad 		radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
   1750  1.1  riastrad 					    DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
   1751  1.1  riastrad 					    CONNECTOR_OBJECT_ID_LVDS,
   1752  1.1  riastrad 					    &hpd);
   1753  1.1  riastrad 		/* DVI-I - primary dac, int tmds */
   1754  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   1755  1.1  riastrad 		hpd.hpd = RADEON_HPD_1; /* ??? */
   1756  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1757  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1758  1.1  riastrad 								ATOM_DEVICE_DFP1_SUPPORT,
   1759  1.1  riastrad 								0),
   1760  1.1  riastrad 					  ATOM_DEVICE_DFP1_SUPPORT);
   1761  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1762  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1763  1.1  riastrad 								ATOM_DEVICE_CRT1_SUPPORT,
   1764  1.1  riastrad 								1),
   1765  1.1  riastrad 					  ATOM_DEVICE_CRT1_SUPPORT);
   1766  1.1  riastrad 		radeon_add_legacy_connector(dev, 1,
   1767  1.1  riastrad 					    ATOM_DEVICE_DFP1_SUPPORT |
   1768  1.1  riastrad 					    ATOM_DEVICE_CRT1_SUPPORT,
   1769  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
   1770  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
   1771  1.1  riastrad 					    &hpd);
   1772  1.1  riastrad 		/* TV - TV DAC */
   1773  1.1  riastrad 		ddc_i2c.valid = false;
   1774  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1775  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1776  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1777  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   1778  1.1  riastrad 								2),
   1779  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   1780  1.1  riastrad 		radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
   1781  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   1782  1.1  riastrad 					    &ddc_i2c,
   1783  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   1784  1.1  riastrad 					    &hpd);
   1785  1.1  riastrad 		break;
   1786  1.1  riastrad 	case CT_POWERBOOK_VGA:
   1787  1.1  riastrad 		DRM_INFO("Connector Table: %d (powerbook vga)\n",
   1788  1.1  riastrad 			 rdev->mode_info.connector_table);
   1789  1.1  riastrad 		/* LVDS */
   1790  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   1791  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1792  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1793  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1794  1.1  riastrad 								ATOM_DEVICE_LCD1_SUPPORT,
   1795  1.1  riastrad 								0),
   1796  1.1  riastrad 					  ATOM_DEVICE_LCD1_SUPPORT);
   1797  1.1  riastrad 		radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
   1798  1.1  riastrad 					    DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
   1799  1.1  riastrad 					    CONNECTOR_OBJECT_ID_LVDS,
   1800  1.1  riastrad 					    &hpd);
   1801  1.1  riastrad 		/* VGA - primary dac */
   1802  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   1803  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1804  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1805  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1806  1.1  riastrad 								ATOM_DEVICE_CRT1_SUPPORT,
   1807  1.1  riastrad 								1),
   1808  1.1  riastrad 					  ATOM_DEVICE_CRT1_SUPPORT);
   1809  1.1  riastrad 		radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
   1810  1.1  riastrad 					    DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
   1811  1.1  riastrad 					    CONNECTOR_OBJECT_ID_VGA,
   1812  1.1  riastrad 					    &hpd);
   1813  1.1  riastrad 		/* TV - TV DAC */
   1814  1.1  riastrad 		ddc_i2c.valid = false;
   1815  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1816  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1817  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1818  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   1819  1.1  riastrad 								2),
   1820  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   1821  1.1  riastrad 		radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
   1822  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   1823  1.1  riastrad 					    &ddc_i2c,
   1824  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   1825  1.1  riastrad 					    &hpd);
   1826  1.1  riastrad 		break;
   1827  1.1  riastrad 	case CT_MINI_EXTERNAL:
   1828  1.1  riastrad 		DRM_INFO("Connector Table: %d (mini external tmds)\n",
   1829  1.1  riastrad 			 rdev->mode_info.connector_table);
   1830  1.1  riastrad 		/* DVI-I - tv dac, ext tmds */
   1831  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
   1832  1.1  riastrad 		hpd.hpd = RADEON_HPD_2; /* ??? */
   1833  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1834  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1835  1.1  riastrad 								ATOM_DEVICE_DFP2_SUPPORT,
   1836  1.1  riastrad 								0),
   1837  1.1  riastrad 					  ATOM_DEVICE_DFP2_SUPPORT);
   1838  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1839  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1840  1.1  riastrad 								ATOM_DEVICE_CRT2_SUPPORT,
   1841  1.1  riastrad 								2),
   1842  1.1  riastrad 					  ATOM_DEVICE_CRT2_SUPPORT);
   1843  1.1  riastrad 		/* XXX are any DL? */
   1844  1.1  riastrad 		radeon_add_legacy_connector(dev, 0,
   1845  1.1  riastrad 					    ATOM_DEVICE_DFP2_SUPPORT |
   1846  1.1  riastrad 					    ATOM_DEVICE_CRT2_SUPPORT,
   1847  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
   1848  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
   1849  1.1  riastrad 					    &hpd);
   1850  1.1  riastrad 		/* TV - TV DAC */
   1851  1.1  riastrad 		ddc_i2c.valid = false;
   1852  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1853  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1854  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1855  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   1856  1.1  riastrad 								2),
   1857  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   1858  1.1  riastrad 		radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
   1859  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   1860  1.1  riastrad 					    &ddc_i2c,
   1861  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   1862  1.1  riastrad 					    &hpd);
   1863  1.1  riastrad 		break;
   1864  1.1  riastrad 	case CT_MINI_INTERNAL:
   1865  1.1  riastrad 		DRM_INFO("Connector Table: %d (mini internal tmds)\n",
   1866  1.1  riastrad 			 rdev->mode_info.connector_table);
   1867  1.1  riastrad 		/* DVI-I - tv dac, int tmds */
   1868  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
   1869  1.1  riastrad 		hpd.hpd = RADEON_HPD_1; /* ??? */
   1870  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1871  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1872  1.1  riastrad 								ATOM_DEVICE_DFP1_SUPPORT,
   1873  1.1  riastrad 								0),
   1874  1.1  riastrad 					  ATOM_DEVICE_DFP1_SUPPORT);
   1875  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1876  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1877  1.1  riastrad 								ATOM_DEVICE_CRT2_SUPPORT,
   1878  1.1  riastrad 								2),
   1879  1.1  riastrad 					  ATOM_DEVICE_CRT2_SUPPORT);
   1880  1.1  riastrad 		radeon_add_legacy_connector(dev, 0,
   1881  1.1  riastrad 					    ATOM_DEVICE_DFP1_SUPPORT |
   1882  1.1  riastrad 					    ATOM_DEVICE_CRT2_SUPPORT,
   1883  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
   1884  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
   1885  1.1  riastrad 					    &hpd);
   1886  1.1  riastrad 		/* TV - TV DAC */
   1887  1.1  riastrad 		ddc_i2c.valid = false;
   1888  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1889  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1890  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1891  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   1892  1.1  riastrad 								2),
   1893  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   1894  1.1  riastrad 		radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_TV1_SUPPORT,
   1895  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   1896  1.1  riastrad 					    &ddc_i2c,
   1897  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   1898  1.1  riastrad 					    &hpd);
   1899  1.1  riastrad 		break;
   1900  1.1  riastrad 	case CT_IMAC_G5_ISIGHT:
   1901  1.1  riastrad 		DRM_INFO("Connector Table: %d (imac g5 isight)\n",
   1902  1.1  riastrad 			 rdev->mode_info.connector_table);
   1903  1.1  riastrad 		/* DVI-D - int tmds */
   1904  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
   1905  1.1  riastrad 		hpd.hpd = RADEON_HPD_1; /* ??? */
   1906  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1907  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1908  1.1  riastrad 								ATOM_DEVICE_DFP1_SUPPORT,
   1909  1.1  riastrad 								0),
   1910  1.1  riastrad 					  ATOM_DEVICE_DFP1_SUPPORT);
   1911  1.1  riastrad 		radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_DFP1_SUPPORT,
   1912  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVID, &ddc_i2c,
   1913  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
   1914  1.1  riastrad 					    &hpd);
   1915  1.1  riastrad 		/* VGA - tv dac */
   1916  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   1917  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1918  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1919  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1920  1.1  riastrad 								ATOM_DEVICE_CRT2_SUPPORT,
   1921  1.1  riastrad 								2),
   1922  1.1  riastrad 					  ATOM_DEVICE_CRT2_SUPPORT);
   1923  1.1  riastrad 		radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
   1924  1.1  riastrad 					    DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
   1925  1.1  riastrad 					    CONNECTOR_OBJECT_ID_VGA,
   1926  1.1  riastrad 					    &hpd);
   1927  1.1  riastrad 		/* TV - TV DAC */
   1928  1.1  riastrad 		ddc_i2c.valid = false;
   1929  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1930  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1931  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1932  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   1933  1.1  riastrad 								2),
   1934  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   1935  1.1  riastrad 		radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
   1936  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   1937  1.1  riastrad 					    &ddc_i2c,
   1938  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   1939  1.1  riastrad 					    &hpd);
   1940  1.1  riastrad 		break;
   1941  1.1  riastrad 	case CT_EMAC:
   1942  1.1  riastrad 		DRM_INFO("Connector Table: %d (emac)\n",
   1943  1.1  riastrad 			 rdev->mode_info.connector_table);
   1944  1.1  riastrad 		/* VGA - primary dac */
   1945  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   1946  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1947  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1948  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1949  1.1  riastrad 								ATOM_DEVICE_CRT1_SUPPORT,
   1950  1.1  riastrad 								1),
   1951  1.1  riastrad 					  ATOM_DEVICE_CRT1_SUPPORT);
   1952  1.1  riastrad 		radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
   1953  1.1  riastrad 					    DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
   1954  1.1  riastrad 					    CONNECTOR_OBJECT_ID_VGA,
   1955  1.1  riastrad 					    &hpd);
   1956  1.1  riastrad 		/* VGA - tv dac */
   1957  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
   1958  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1959  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1960  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1961  1.1  riastrad 								ATOM_DEVICE_CRT2_SUPPORT,
   1962  1.1  riastrad 								2),
   1963  1.1  riastrad 					  ATOM_DEVICE_CRT2_SUPPORT);
   1964  1.1  riastrad 		radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
   1965  1.1  riastrad 					    DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
   1966  1.1  riastrad 					    CONNECTOR_OBJECT_ID_VGA,
   1967  1.1  riastrad 					    &hpd);
   1968  1.1  riastrad 		/* TV - TV DAC */
   1969  1.1  riastrad 		ddc_i2c.valid = false;
   1970  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1971  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1972  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1973  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   1974  1.1  riastrad 								2),
   1975  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   1976  1.1  riastrad 		radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
   1977  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   1978  1.1  riastrad 					    &ddc_i2c,
   1979  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   1980  1.1  riastrad 					    &hpd);
   1981  1.1  riastrad 		break;
   1982  1.1  riastrad 	case CT_RN50_POWER:
   1983  1.1  riastrad 		DRM_INFO("Connector Table: %d (rn50-power)\n",
   1984  1.1  riastrad 			 rdev->mode_info.connector_table);
   1985  1.1  riastrad 		/* VGA - primary dac */
   1986  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   1987  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1988  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   1989  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   1990  1.1  riastrad 								ATOM_DEVICE_CRT1_SUPPORT,
   1991  1.1  riastrad 								1),
   1992  1.1  riastrad 					  ATOM_DEVICE_CRT1_SUPPORT);
   1993  1.1  riastrad 		radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_CRT1_SUPPORT,
   1994  1.1  riastrad 					    DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
   1995  1.1  riastrad 					    CONNECTOR_OBJECT_ID_VGA,
   1996  1.1  riastrad 					    &hpd);
   1997  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
   1998  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   1999  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2000  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2001  1.1  riastrad 								ATOM_DEVICE_CRT2_SUPPORT,
   2002  1.1  riastrad 								2),
   2003  1.1  riastrad 					  ATOM_DEVICE_CRT2_SUPPORT);
   2004  1.1  riastrad 		radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT2_SUPPORT,
   2005  1.1  riastrad 					    DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
   2006  1.1  riastrad 					    CONNECTOR_OBJECT_ID_VGA,
   2007  1.1  riastrad 					    &hpd);
   2008  1.1  riastrad 		break;
   2009  1.1  riastrad 	case CT_MAC_X800:
   2010  1.1  riastrad 		DRM_INFO("Connector Table: %d (mac x800)\n",
   2011  1.1  riastrad 			 rdev->mode_info.connector_table);
   2012  1.1  riastrad 		/* DVI - primary dac, internal tmds */
   2013  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   2014  1.1  riastrad 		hpd.hpd = RADEON_HPD_1; /* ??? */
   2015  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2016  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2017  1.1  riastrad 								  ATOM_DEVICE_DFP1_SUPPORT,
   2018  1.1  riastrad 								  0),
   2019  1.1  riastrad 					  ATOM_DEVICE_DFP1_SUPPORT);
   2020  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2021  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2022  1.1  riastrad 								  ATOM_DEVICE_CRT1_SUPPORT,
   2023  1.1  riastrad 								  1),
   2024  1.1  riastrad 					  ATOM_DEVICE_CRT1_SUPPORT);
   2025  1.1  riastrad 		radeon_add_legacy_connector(dev, 0,
   2026  1.1  riastrad 					    ATOM_DEVICE_DFP1_SUPPORT |
   2027  1.1  riastrad 					    ATOM_DEVICE_CRT1_SUPPORT,
   2028  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
   2029  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
   2030  1.1  riastrad 					    &hpd);
   2031  1.1  riastrad 		/* DVI - tv dac, dvo */
   2032  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
   2033  1.1  riastrad 		hpd.hpd = RADEON_HPD_2; /* ??? */
   2034  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2035  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2036  1.1  riastrad 								  ATOM_DEVICE_DFP2_SUPPORT,
   2037  1.1  riastrad 								  0),
   2038  1.1  riastrad 					  ATOM_DEVICE_DFP2_SUPPORT);
   2039  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2040  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2041  1.1  riastrad 								  ATOM_DEVICE_CRT2_SUPPORT,
   2042  1.1  riastrad 								  2),
   2043  1.1  riastrad 					  ATOM_DEVICE_CRT2_SUPPORT);
   2044  1.1  riastrad 		radeon_add_legacy_connector(dev, 1,
   2045  1.1  riastrad 					    ATOM_DEVICE_DFP2_SUPPORT |
   2046  1.1  riastrad 					    ATOM_DEVICE_CRT2_SUPPORT,
   2047  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
   2048  1.1  riastrad 					    CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
   2049  1.1  riastrad 					    &hpd);
   2050  1.1  riastrad 		break;
   2051  1.1  riastrad 	case CT_MAC_G5_9600:
   2052  1.1  riastrad 		DRM_INFO("Connector Table: %d (mac g5 9600)\n",
   2053  1.1  riastrad 			 rdev->mode_info.connector_table);
   2054  1.1  riastrad 		/* DVI - tv dac, dvo */
   2055  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   2056  1.1  riastrad 		hpd.hpd = RADEON_HPD_1; /* ??? */
   2057  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2058  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2059  1.1  riastrad 								  ATOM_DEVICE_DFP2_SUPPORT,
   2060  1.1  riastrad 								  0),
   2061  1.1  riastrad 					  ATOM_DEVICE_DFP2_SUPPORT);
   2062  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2063  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2064  1.1  riastrad 								  ATOM_DEVICE_CRT2_SUPPORT,
   2065  1.1  riastrad 								  2),
   2066  1.1  riastrad 					  ATOM_DEVICE_CRT2_SUPPORT);
   2067  1.1  riastrad 		radeon_add_legacy_connector(dev, 0,
   2068  1.1  riastrad 					    ATOM_DEVICE_DFP2_SUPPORT |
   2069  1.1  riastrad 					    ATOM_DEVICE_CRT2_SUPPORT,
   2070  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
   2071  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
   2072  1.1  riastrad 					    &hpd);
   2073  1.1  riastrad 		/* ADC - primary dac, internal tmds */
   2074  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   2075  1.1  riastrad 		hpd.hpd = RADEON_HPD_2; /* ??? */
   2076  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2077  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2078  1.1  riastrad 								  ATOM_DEVICE_DFP1_SUPPORT,
   2079  1.1  riastrad 								  0),
   2080  1.1  riastrad 					  ATOM_DEVICE_DFP1_SUPPORT);
   2081  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2082  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2083  1.1  riastrad 								  ATOM_DEVICE_CRT1_SUPPORT,
   2084  1.1  riastrad 								  1),
   2085  1.1  riastrad 					  ATOM_DEVICE_CRT1_SUPPORT);
   2086  1.1  riastrad 		radeon_add_legacy_connector(dev, 1,
   2087  1.1  riastrad 					    ATOM_DEVICE_DFP1_SUPPORT |
   2088  1.1  riastrad 					    ATOM_DEVICE_CRT1_SUPPORT,
   2089  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
   2090  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
   2091  1.1  riastrad 					    &hpd);
   2092  1.1  riastrad 		/* TV - TV DAC */
   2093  1.1  riastrad 		ddc_i2c.valid = false;
   2094  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   2095  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2096  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2097  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   2098  1.1  riastrad 								2),
   2099  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   2100  1.1  riastrad 		radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
   2101  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   2102  1.1  riastrad 					    &ddc_i2c,
   2103  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   2104  1.1  riastrad 					    &hpd);
   2105  1.1  riastrad 		break;
   2106  1.1  riastrad 	case CT_SAM440EP:
   2107  1.1  riastrad 		DRM_INFO("Connector Table: %d (SAM440ep embedded board)\n",
   2108  1.1  riastrad 			 rdev->mode_info.connector_table);
   2109  1.1  riastrad 		/* LVDS */
   2110  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
   2111  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   2112  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2113  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2114  1.1  riastrad 								ATOM_DEVICE_LCD1_SUPPORT,
   2115  1.1  riastrad 								0),
   2116  1.1  riastrad 					  ATOM_DEVICE_LCD1_SUPPORT);
   2117  1.1  riastrad 		radeon_add_legacy_connector(dev, 0, ATOM_DEVICE_LCD1_SUPPORT,
   2118  1.1  riastrad 					    DRM_MODE_CONNECTOR_LVDS, &ddc_i2c,
   2119  1.1  riastrad 					    CONNECTOR_OBJECT_ID_LVDS,
   2120  1.1  riastrad 					    &hpd);
   2121  1.1  riastrad 		/* DVI-I - secondary dac, int tmds */
   2122  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   2123  1.1  riastrad 		hpd.hpd = RADEON_HPD_1; /* ??? */
   2124  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2125  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2126  1.1  riastrad 								ATOM_DEVICE_DFP1_SUPPORT,
   2127  1.1  riastrad 								0),
   2128  1.1  riastrad 					  ATOM_DEVICE_DFP1_SUPPORT);
   2129  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2130  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2131  1.1  riastrad 								ATOM_DEVICE_CRT2_SUPPORT,
   2132  1.1  riastrad 								2),
   2133  1.1  riastrad 					  ATOM_DEVICE_CRT2_SUPPORT);
   2134  1.1  riastrad 		radeon_add_legacy_connector(dev, 1,
   2135  1.1  riastrad 					    ATOM_DEVICE_DFP1_SUPPORT |
   2136  1.1  riastrad 					    ATOM_DEVICE_CRT2_SUPPORT,
   2137  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
   2138  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
   2139  1.1  riastrad 					    &hpd);
   2140  1.1  riastrad 		/* VGA - primary dac */
   2141  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   2142  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   2143  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2144  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2145  1.1  riastrad 								ATOM_DEVICE_CRT1_SUPPORT,
   2146  1.1  riastrad 								1),
   2147  1.1  riastrad 					  ATOM_DEVICE_CRT1_SUPPORT);
   2148  1.1  riastrad 		radeon_add_legacy_connector(dev, 2,
   2149  1.1  riastrad 					    ATOM_DEVICE_CRT1_SUPPORT,
   2150  1.1  riastrad 					    DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
   2151  1.1  riastrad 					    CONNECTOR_OBJECT_ID_VGA,
   2152  1.1  riastrad 					    &hpd);
   2153  1.1  riastrad 		/* TV - TV DAC */
   2154  1.1  riastrad 		ddc_i2c.valid = false;
   2155  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   2156  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2157  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2158  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   2159  1.1  riastrad 								2),
   2160  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   2161  1.1  riastrad 		radeon_add_legacy_connector(dev, 3, ATOM_DEVICE_TV1_SUPPORT,
   2162  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   2163  1.1  riastrad 					    &ddc_i2c,
   2164  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   2165  1.1  riastrad 					    &hpd);
   2166  1.1  riastrad 		break;
   2167  1.1  riastrad 	case CT_MAC_G4_SILVER:
   2168  1.1  riastrad 		DRM_INFO("Connector Table: %d (mac g4 silver)\n",
   2169  1.1  riastrad 			 rdev->mode_info.connector_table);
   2170  1.1  riastrad 		/* DVI-I - tv dac, int tmds */
   2171  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   2172  1.1  riastrad 		hpd.hpd = RADEON_HPD_1; /* ??? */
   2173  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2174  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2175  1.1  riastrad 								ATOM_DEVICE_DFP1_SUPPORT,
   2176  1.1  riastrad 								0),
   2177  1.1  riastrad 					  ATOM_DEVICE_DFP1_SUPPORT);
   2178  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2179  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2180  1.1  riastrad 								ATOM_DEVICE_CRT2_SUPPORT,
   2181  1.1  riastrad 								2),
   2182  1.1  riastrad 					  ATOM_DEVICE_CRT2_SUPPORT);
   2183  1.1  riastrad 		radeon_add_legacy_connector(dev, 0,
   2184  1.1  riastrad 					    ATOM_DEVICE_DFP1_SUPPORT |
   2185  1.1  riastrad 					    ATOM_DEVICE_CRT2_SUPPORT,
   2186  1.1  riastrad 					    DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
   2187  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
   2188  1.1  riastrad 					    &hpd);
   2189  1.1  riastrad 		/* VGA - primary dac */
   2190  1.1  riastrad 		ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   2191  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   2192  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2193  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2194  1.1  riastrad 								ATOM_DEVICE_CRT1_SUPPORT,
   2195  1.1  riastrad 								1),
   2196  1.1  riastrad 					  ATOM_DEVICE_CRT1_SUPPORT);
   2197  1.1  riastrad 		radeon_add_legacy_connector(dev, 1, ATOM_DEVICE_CRT1_SUPPORT,
   2198  1.1  riastrad 					    DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
   2199  1.1  riastrad 					    CONNECTOR_OBJECT_ID_VGA,
   2200  1.1  riastrad 					    &hpd);
   2201  1.1  riastrad 		/* TV - TV DAC */
   2202  1.1  riastrad 		ddc_i2c.valid = false;
   2203  1.1  riastrad 		hpd.hpd = RADEON_HPD_NONE;
   2204  1.1  riastrad 		radeon_add_legacy_encoder(dev,
   2205  1.1  riastrad 					  radeon_get_encoder_enum(dev,
   2206  1.1  riastrad 								ATOM_DEVICE_TV1_SUPPORT,
   2207  1.1  riastrad 								2),
   2208  1.1  riastrad 					  ATOM_DEVICE_TV1_SUPPORT);
   2209  1.1  riastrad 		radeon_add_legacy_connector(dev, 2, ATOM_DEVICE_TV1_SUPPORT,
   2210  1.1  riastrad 					    DRM_MODE_CONNECTOR_SVIDEO,
   2211  1.1  riastrad 					    &ddc_i2c,
   2212  1.1  riastrad 					    CONNECTOR_OBJECT_ID_SVIDEO,
   2213  1.1  riastrad 					    &hpd);
   2214  1.1  riastrad 		break;
   2215  1.1  riastrad 	default:
   2216  1.1  riastrad 		DRM_INFO("Connector table: %d (invalid)\n",
   2217  1.1  riastrad 			 rdev->mode_info.connector_table);
   2218  1.1  riastrad 		return false;
   2219  1.1  riastrad 	}
   2220  1.1  riastrad 
   2221  1.1  riastrad 	radeon_link_encoder_connector(dev);
   2222  1.1  riastrad 
   2223  1.1  riastrad 	return true;
   2224  1.1  riastrad }
   2225  1.1  riastrad 
   2226  1.1  riastrad static bool radeon_apply_legacy_quirks(struct drm_device *dev,
   2227  1.1  riastrad 				       int bios_index,
   2228  1.1  riastrad 				       enum radeon_combios_connector
   2229  1.1  riastrad 				       *legacy_connector,
   2230  1.1  riastrad 				       struct radeon_i2c_bus_rec *ddc_i2c,
   2231  1.1  riastrad 				       struct radeon_hpd *hpd)
   2232  1.1  riastrad {
   2233  1.1  riastrad 
   2234  1.1  riastrad 	/* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
   2235  1.1  riastrad 	   one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
   2236  1.1  riastrad 	if (dev->pdev->device == 0x515e &&
   2237  1.1  riastrad 	    dev->pdev->subsystem_vendor == 0x1014) {
   2238  1.1  riastrad 		if (*legacy_connector == CONNECTOR_CRT_LEGACY &&
   2239  1.1  riastrad 		    ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
   2240  1.1  riastrad 			return false;
   2241  1.1  riastrad 	}
   2242  1.1  riastrad 
   2243  1.1  riastrad 	/* X300 card with extra non-existent DVI port */
   2244  1.1  riastrad 	if (dev->pdev->device == 0x5B60 &&
   2245  1.1  riastrad 	    dev->pdev->subsystem_vendor == 0x17af &&
   2246  1.1  riastrad 	    dev->pdev->subsystem_device == 0x201e && bios_index == 2) {
   2247  1.1  riastrad 		if (*legacy_connector == CONNECTOR_DVI_I_LEGACY)
   2248  1.1  riastrad 			return false;
   2249  1.1  riastrad 	}
   2250  1.1  riastrad 
   2251  1.1  riastrad 	return true;
   2252  1.1  riastrad }
   2253  1.1  riastrad 
   2254  1.1  riastrad static bool radeon_apply_legacy_tv_quirks(struct drm_device *dev)
   2255  1.1  riastrad {
   2256  1.1  riastrad 	/* Acer 5102 has non-existent TV port */
   2257  1.1  riastrad 	if (dev->pdev->device == 0x5975 &&
   2258  1.1  riastrad 	    dev->pdev->subsystem_vendor == 0x1025 &&
   2259  1.1  riastrad 	    dev->pdev->subsystem_device == 0x009f)
   2260  1.1  riastrad 		return false;
   2261  1.1  riastrad 
   2262  1.1  riastrad 	/* HP dc5750 has non-existent TV port */
   2263  1.1  riastrad 	if (dev->pdev->device == 0x5974 &&
   2264  1.1  riastrad 	    dev->pdev->subsystem_vendor == 0x103c &&
   2265  1.1  riastrad 	    dev->pdev->subsystem_device == 0x280a)
   2266  1.1  riastrad 		return false;
   2267  1.1  riastrad 
   2268  1.1  riastrad 	/* MSI S270 has non-existent TV port */
   2269  1.1  riastrad 	if (dev->pdev->device == 0x5955 &&
   2270  1.1  riastrad 	    dev->pdev->subsystem_vendor == 0x1462 &&
   2271  1.1  riastrad 	    dev->pdev->subsystem_device == 0x0131)
   2272  1.1  riastrad 		return false;
   2273  1.1  riastrad 
   2274  1.1  riastrad 	return true;
   2275  1.1  riastrad }
   2276  1.1  riastrad 
   2277  1.1  riastrad static uint16_t combios_check_dl_dvi(struct drm_device *dev, int is_dvi_d)
   2278  1.1  riastrad {
   2279  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   2280  1.1  riastrad 	uint32_t ext_tmds_info;
   2281  1.1  riastrad 
   2282  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP) {
   2283  1.1  riastrad 		if (is_dvi_d)
   2284  1.1  riastrad 			return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
   2285  1.1  riastrad 		else
   2286  1.1  riastrad 			return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
   2287  1.1  riastrad 	}
   2288  1.1  riastrad 	ext_tmds_info = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
   2289  1.1  riastrad 	if (ext_tmds_info) {
   2290  1.1  riastrad 		uint8_t rev = RBIOS8(ext_tmds_info);
   2291  1.1  riastrad 		uint8_t flags = RBIOS8(ext_tmds_info + 4 + 5);
   2292  1.1  riastrad 		if (rev >= 3) {
   2293  1.1  riastrad 			if (is_dvi_d)
   2294  1.1  riastrad 				return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
   2295  1.1  riastrad 			else
   2296  1.1  riastrad 				return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
   2297  1.1  riastrad 		} else {
   2298  1.1  riastrad 			if (flags & 1) {
   2299  1.1  riastrad 				if (is_dvi_d)
   2300  1.1  riastrad 					return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
   2301  1.1  riastrad 				else
   2302  1.1  riastrad 					return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
   2303  1.1  riastrad 			}
   2304  1.1  riastrad 		}
   2305  1.1  riastrad 	}
   2306  1.1  riastrad 	if (is_dvi_d)
   2307  1.1  riastrad 		return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
   2308  1.1  riastrad 	else
   2309  1.1  riastrad 		return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
   2310  1.1  riastrad }
   2311  1.1  riastrad 
   2312  1.1  riastrad bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
   2313  1.1  riastrad {
   2314  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   2315  1.1  riastrad 	uint32_t conn_info, entry, devices;
   2316  1.1  riastrad 	uint16_t tmp, connector_object_id;
   2317  1.1  riastrad 	enum radeon_combios_ddc ddc_type;
   2318  1.1  riastrad 	enum radeon_combios_connector connector;
   2319  1.1  riastrad 	int i = 0;
   2320  1.1  riastrad 	struct radeon_i2c_bus_rec ddc_i2c;
   2321  1.1  riastrad 	struct radeon_hpd hpd;
   2322  1.1  riastrad 
   2323  1.1  riastrad 	conn_info = combios_get_table_offset(dev, COMBIOS_CONNECTOR_INFO_TABLE);
   2324  1.1  riastrad 	if (conn_info) {
   2325  1.1  riastrad 		for (i = 0; i < 4; i++) {
   2326  1.1  riastrad 			entry = conn_info + 2 + i * 2;
   2327  1.1  riastrad 
   2328  1.1  riastrad 			if (!RBIOS16(entry))
   2329  1.1  riastrad 				break;
   2330  1.1  riastrad 
   2331  1.1  riastrad 			tmp = RBIOS16(entry);
   2332  1.1  riastrad 
   2333  1.1  riastrad 			connector = (tmp >> 12) & 0xf;
   2334  1.1  riastrad 
   2335  1.1  riastrad 			ddc_type = (tmp >> 8) & 0xf;
   2336  1.1  riastrad 			if (ddc_type == 5)
   2337  1.1  riastrad 				ddc_i2c = radeon_combios_get_i2c_info_from_table(rdev);
   2338  1.1  riastrad 			else
   2339  1.1  riastrad 				ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
   2340  1.1  riastrad 
   2341  1.1  riastrad 			switch (connector) {
   2342  1.1  riastrad 			case CONNECTOR_PROPRIETARY_LEGACY:
   2343  1.1  riastrad 			case CONNECTOR_DVI_I_LEGACY:
   2344  1.1  riastrad 			case CONNECTOR_DVI_D_LEGACY:
   2345  1.1  riastrad 				if ((tmp >> 4) & 0x1)
   2346  1.1  riastrad 					hpd.hpd = RADEON_HPD_2;
   2347  1.1  riastrad 				else
   2348  1.1  riastrad 					hpd.hpd = RADEON_HPD_1;
   2349  1.1  riastrad 				break;
   2350  1.1  riastrad 			default:
   2351  1.1  riastrad 				hpd.hpd = RADEON_HPD_NONE;
   2352  1.1  riastrad 				break;
   2353  1.1  riastrad 			}
   2354  1.1  riastrad 
   2355  1.1  riastrad 			if (!radeon_apply_legacy_quirks(dev, i, &connector,
   2356  1.1  riastrad 							&ddc_i2c, &hpd))
   2357  1.1  riastrad 				continue;
   2358  1.1  riastrad 
   2359  1.1  riastrad 			switch (connector) {
   2360  1.1  riastrad 			case CONNECTOR_PROPRIETARY_LEGACY:
   2361  1.1  riastrad 				if ((tmp >> 4) & 0x1)
   2362  1.1  riastrad 					devices = ATOM_DEVICE_DFP2_SUPPORT;
   2363  1.1  riastrad 				else
   2364  1.1  riastrad 					devices = ATOM_DEVICE_DFP1_SUPPORT;
   2365  1.1  riastrad 				radeon_add_legacy_encoder(dev,
   2366  1.1  riastrad 							  radeon_get_encoder_enum
   2367  1.1  riastrad 							  (dev, devices, 0),
   2368  1.1  riastrad 							  devices);
   2369  1.1  riastrad 				radeon_add_legacy_connector(dev, i, devices,
   2370  1.1  riastrad 							    legacy_connector_convert
   2371  1.1  riastrad 							    [connector],
   2372  1.1  riastrad 							    &ddc_i2c,
   2373  1.1  riastrad 							    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
   2374  1.1  riastrad 							    &hpd);
   2375  1.1  riastrad 				break;
   2376  1.1  riastrad 			case CONNECTOR_CRT_LEGACY:
   2377  1.1  riastrad 				if (tmp & 0x1) {
   2378  1.1  riastrad 					devices = ATOM_DEVICE_CRT2_SUPPORT;
   2379  1.1  riastrad 					radeon_add_legacy_encoder(dev,
   2380  1.1  riastrad 								  radeon_get_encoder_enum
   2381  1.1  riastrad 								  (dev,
   2382  1.1  riastrad 								   ATOM_DEVICE_CRT2_SUPPORT,
   2383  1.1  riastrad 								   2),
   2384  1.1  riastrad 								  ATOM_DEVICE_CRT2_SUPPORT);
   2385  1.1  riastrad 				} else {
   2386  1.1  riastrad 					devices = ATOM_DEVICE_CRT1_SUPPORT;
   2387  1.1  riastrad 					radeon_add_legacy_encoder(dev,
   2388  1.1  riastrad 								  radeon_get_encoder_enum
   2389  1.1  riastrad 								  (dev,
   2390  1.1  riastrad 								   ATOM_DEVICE_CRT1_SUPPORT,
   2391  1.1  riastrad 								   1),
   2392  1.1  riastrad 								  ATOM_DEVICE_CRT1_SUPPORT);
   2393  1.1  riastrad 				}
   2394  1.1  riastrad 				radeon_add_legacy_connector(dev,
   2395  1.1  riastrad 							    i,
   2396  1.1  riastrad 							    devices,
   2397  1.1  riastrad 							    legacy_connector_convert
   2398  1.1  riastrad 							    [connector],
   2399  1.1  riastrad 							    &ddc_i2c,
   2400  1.1  riastrad 							    CONNECTOR_OBJECT_ID_VGA,
   2401  1.1  riastrad 							    &hpd);
   2402  1.1  riastrad 				break;
   2403  1.1  riastrad 			case CONNECTOR_DVI_I_LEGACY:
   2404  1.1  riastrad 				devices = 0;
   2405  1.1  riastrad 				if (tmp & 0x1) {
   2406  1.1  riastrad 					devices |= ATOM_DEVICE_CRT2_SUPPORT;
   2407  1.1  riastrad 					radeon_add_legacy_encoder(dev,
   2408  1.1  riastrad 								  radeon_get_encoder_enum
   2409  1.1  riastrad 								  (dev,
   2410  1.1  riastrad 								   ATOM_DEVICE_CRT2_SUPPORT,
   2411  1.1  riastrad 								   2),
   2412  1.1  riastrad 								  ATOM_DEVICE_CRT2_SUPPORT);
   2413  1.1  riastrad 				} else {
   2414  1.1  riastrad 					devices |= ATOM_DEVICE_CRT1_SUPPORT;
   2415  1.1  riastrad 					radeon_add_legacy_encoder(dev,
   2416  1.1  riastrad 								  radeon_get_encoder_enum
   2417  1.1  riastrad 								  (dev,
   2418  1.1  riastrad 								   ATOM_DEVICE_CRT1_SUPPORT,
   2419  1.1  riastrad 								   1),
   2420  1.1  riastrad 								  ATOM_DEVICE_CRT1_SUPPORT);
   2421  1.1  riastrad 				}
   2422  1.1  riastrad 				/* RV100 board with external TDMS bit mis-set.
   2423  1.1  riastrad 				 * Actually uses internal TMDS, clear the bit.
   2424  1.1  riastrad 				 */
   2425  1.1  riastrad 				if (dev->pdev->device == 0x5159 &&
   2426  1.1  riastrad 				    dev->pdev->subsystem_vendor == 0x1014 &&
   2427  1.1  riastrad 				    dev->pdev->subsystem_device == 0x029A) {
   2428  1.1  riastrad 					tmp &= ~(1 << 4);
   2429  1.1  riastrad 				}
   2430  1.1  riastrad 				if ((tmp >> 4) & 0x1) {
   2431  1.1  riastrad 					devices |= ATOM_DEVICE_DFP2_SUPPORT;
   2432  1.1  riastrad 					radeon_add_legacy_encoder(dev,
   2433  1.1  riastrad 								  radeon_get_encoder_enum
   2434  1.1  riastrad 								  (dev,
   2435  1.1  riastrad 								   ATOM_DEVICE_DFP2_SUPPORT,
   2436  1.1  riastrad 								   0),
   2437  1.1  riastrad 								  ATOM_DEVICE_DFP2_SUPPORT);
   2438  1.1  riastrad 					connector_object_id = combios_check_dl_dvi(dev, 0);
   2439  1.1  riastrad 				} else {
   2440  1.1  riastrad 					devices |= ATOM_DEVICE_DFP1_SUPPORT;
   2441  1.1  riastrad 					radeon_add_legacy_encoder(dev,
   2442  1.1  riastrad 								  radeon_get_encoder_enum
   2443  1.1  riastrad 								  (dev,
   2444  1.1  riastrad 								   ATOM_DEVICE_DFP1_SUPPORT,
   2445  1.1  riastrad 								   0),
   2446  1.1  riastrad 								  ATOM_DEVICE_DFP1_SUPPORT);
   2447  1.1  riastrad 					connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
   2448  1.1  riastrad 				}
   2449  1.1  riastrad 				radeon_add_legacy_connector(dev,
   2450  1.1  riastrad 							    i,
   2451  1.1  riastrad 							    devices,
   2452  1.1  riastrad 							    legacy_connector_convert
   2453  1.1  riastrad 							    [connector],
   2454  1.1  riastrad 							    &ddc_i2c,
   2455  1.1  riastrad 							    connector_object_id,
   2456  1.1  riastrad 							    &hpd);
   2457  1.1  riastrad 				break;
   2458  1.1  riastrad 			case CONNECTOR_DVI_D_LEGACY:
   2459  1.1  riastrad 				if ((tmp >> 4) & 0x1) {
   2460  1.1  riastrad 					devices = ATOM_DEVICE_DFP2_SUPPORT;
   2461  1.1  riastrad 					connector_object_id = combios_check_dl_dvi(dev, 1);
   2462  1.1  riastrad 				} else {
   2463  1.1  riastrad 					devices = ATOM_DEVICE_DFP1_SUPPORT;
   2464  1.1  riastrad 					connector_object_id = CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
   2465  1.1  riastrad 				}
   2466  1.1  riastrad 				radeon_add_legacy_encoder(dev,
   2467  1.1  riastrad 							  radeon_get_encoder_enum
   2468  1.1  riastrad 							  (dev, devices, 0),
   2469  1.1  riastrad 							  devices);
   2470  1.1  riastrad 				radeon_add_legacy_connector(dev, i, devices,
   2471  1.1  riastrad 							    legacy_connector_convert
   2472  1.1  riastrad 							    [connector],
   2473  1.1  riastrad 							    &ddc_i2c,
   2474  1.1  riastrad 							    connector_object_id,
   2475  1.1  riastrad 							    &hpd);
   2476  1.1  riastrad 				break;
   2477  1.1  riastrad 			case CONNECTOR_CTV_LEGACY:
   2478  1.1  riastrad 			case CONNECTOR_STV_LEGACY:
   2479  1.1  riastrad 				radeon_add_legacy_encoder(dev,
   2480  1.1  riastrad 							  radeon_get_encoder_enum
   2481  1.1  riastrad 							  (dev,
   2482  1.1  riastrad 							   ATOM_DEVICE_TV1_SUPPORT,
   2483  1.1  riastrad 							   2),
   2484  1.1  riastrad 							  ATOM_DEVICE_TV1_SUPPORT);
   2485  1.1  riastrad 				radeon_add_legacy_connector(dev, i,
   2486  1.1  riastrad 							    ATOM_DEVICE_TV1_SUPPORT,
   2487  1.1  riastrad 							    legacy_connector_convert
   2488  1.1  riastrad 							    [connector],
   2489  1.1  riastrad 							    &ddc_i2c,
   2490  1.1  riastrad 							    CONNECTOR_OBJECT_ID_SVIDEO,
   2491  1.1  riastrad 							    &hpd);
   2492  1.1  riastrad 				break;
   2493  1.1  riastrad 			default:
   2494  1.1  riastrad 				DRM_ERROR("Unknown connector type: %d\n",
   2495  1.1  riastrad 					  connector);
   2496  1.1  riastrad 				continue;
   2497  1.1  riastrad 			}
   2498  1.1  riastrad 
   2499  1.1  riastrad 		}
   2500  1.1  riastrad 	} else {
   2501  1.1  riastrad 		uint16_t tmds_info =
   2502  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_DFP_INFO_TABLE);
   2503  1.1  riastrad 		if (tmds_info) {
   2504  1.1  riastrad 			DRM_DEBUG_KMS("Found DFP table, assuming DVI connector\n");
   2505  1.1  riastrad 
   2506  1.1  riastrad 			radeon_add_legacy_encoder(dev,
   2507  1.1  riastrad 						  radeon_get_encoder_enum(dev,
   2508  1.1  riastrad 									ATOM_DEVICE_CRT1_SUPPORT,
   2509  1.1  riastrad 									1),
   2510  1.1  riastrad 						  ATOM_DEVICE_CRT1_SUPPORT);
   2511  1.1  riastrad 			radeon_add_legacy_encoder(dev,
   2512  1.1  riastrad 						  radeon_get_encoder_enum(dev,
   2513  1.1  riastrad 									ATOM_DEVICE_DFP1_SUPPORT,
   2514  1.1  riastrad 									0),
   2515  1.1  riastrad 						  ATOM_DEVICE_DFP1_SUPPORT);
   2516  1.1  riastrad 
   2517  1.1  riastrad 			ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
   2518  1.1  riastrad 			hpd.hpd = RADEON_HPD_1;
   2519  1.1  riastrad 			radeon_add_legacy_connector(dev,
   2520  1.1  riastrad 						    0,
   2521  1.1  riastrad 						    ATOM_DEVICE_CRT1_SUPPORT |
   2522  1.1  riastrad 						    ATOM_DEVICE_DFP1_SUPPORT,
   2523  1.1  riastrad 						    DRM_MODE_CONNECTOR_DVII,
   2524  1.1  riastrad 						    &ddc_i2c,
   2525  1.1  riastrad 						    CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
   2526  1.1  riastrad 						    &hpd);
   2527  1.1  riastrad 		} else {
   2528  1.1  riastrad 			uint16_t crt_info =
   2529  1.1  riastrad 				combios_get_table_offset(dev, COMBIOS_CRT_INFO_TABLE);
   2530  1.1  riastrad 			DRM_DEBUG_KMS("Found CRT table, assuming VGA connector\n");
   2531  1.1  riastrad 			if (crt_info) {
   2532  1.1  riastrad 				radeon_add_legacy_encoder(dev,
   2533  1.1  riastrad 							  radeon_get_encoder_enum(dev,
   2534  1.1  riastrad 										ATOM_DEVICE_CRT1_SUPPORT,
   2535  1.1  riastrad 										1),
   2536  1.1  riastrad 							  ATOM_DEVICE_CRT1_SUPPORT);
   2537  1.1  riastrad 				ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
   2538  1.1  riastrad 				hpd.hpd = RADEON_HPD_NONE;
   2539  1.1  riastrad 				radeon_add_legacy_connector(dev,
   2540  1.1  riastrad 							    0,
   2541  1.1  riastrad 							    ATOM_DEVICE_CRT1_SUPPORT,
   2542  1.1  riastrad 							    DRM_MODE_CONNECTOR_VGA,
   2543  1.1  riastrad 							    &ddc_i2c,
   2544  1.1  riastrad 							    CONNECTOR_OBJECT_ID_VGA,
   2545  1.1  riastrad 							    &hpd);
   2546  1.1  riastrad 			} else {
   2547  1.1  riastrad 				DRM_DEBUG_KMS("No connector info found\n");
   2548  1.1  riastrad 				return false;
   2549  1.1  riastrad 			}
   2550  1.1  riastrad 		}
   2551  1.1  riastrad 	}
   2552  1.1  riastrad 
   2553  1.1  riastrad 	if (rdev->flags & RADEON_IS_MOBILITY || rdev->flags & RADEON_IS_IGP) {
   2554  1.1  riastrad 		uint16_t lcd_info =
   2555  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_LCD_INFO_TABLE);
   2556  1.1  riastrad 		if (lcd_info) {
   2557  1.1  riastrad 			uint16_t lcd_ddc_info =
   2558  1.1  riastrad 			    combios_get_table_offset(dev,
   2559  1.1  riastrad 						     COMBIOS_LCD_DDC_INFO_TABLE);
   2560  1.1  riastrad 
   2561  1.1  riastrad 			radeon_add_legacy_encoder(dev,
   2562  1.1  riastrad 						  radeon_get_encoder_enum(dev,
   2563  1.1  riastrad 									ATOM_DEVICE_LCD1_SUPPORT,
   2564  1.1  riastrad 									0),
   2565  1.1  riastrad 						  ATOM_DEVICE_LCD1_SUPPORT);
   2566  1.1  riastrad 
   2567  1.1  riastrad 			if (lcd_ddc_info) {
   2568  1.1  riastrad 				ddc_type = RBIOS8(lcd_ddc_info + 2);
   2569  1.1  riastrad 				switch (ddc_type) {
   2570  1.1  riastrad 				case DDC_LCD:
   2571  1.1  riastrad 					ddc_i2c =
   2572  1.1  riastrad 						combios_setup_i2c_bus(rdev,
   2573  1.1  riastrad 								      DDC_LCD,
   2574  1.1  riastrad 								      RBIOS32(lcd_ddc_info + 3),
   2575  1.1  riastrad 								      RBIOS32(lcd_ddc_info + 7));
   2576  1.1  riastrad 					radeon_i2c_add(rdev, &ddc_i2c, "LCD");
   2577  1.1  riastrad 					break;
   2578  1.1  riastrad 				case DDC_GPIO:
   2579  1.1  riastrad 					ddc_i2c =
   2580  1.1  riastrad 						combios_setup_i2c_bus(rdev,
   2581  1.1  riastrad 								      DDC_GPIO,
   2582  1.1  riastrad 								      RBIOS32(lcd_ddc_info + 3),
   2583  1.1  riastrad 								      RBIOS32(lcd_ddc_info + 7));
   2584  1.1  riastrad 					radeon_i2c_add(rdev, &ddc_i2c, "LCD");
   2585  1.1  riastrad 					break;
   2586  1.1  riastrad 				default:
   2587  1.1  riastrad 					ddc_i2c =
   2588  1.1  riastrad 						combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
   2589  1.1  riastrad 					break;
   2590  1.1  riastrad 				}
   2591  1.1  riastrad 				DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
   2592  1.1  riastrad 			} else
   2593  1.1  riastrad 				ddc_i2c.valid = false;
   2594  1.1  riastrad 
   2595  1.1  riastrad 			hpd.hpd = RADEON_HPD_NONE;
   2596  1.1  riastrad 			radeon_add_legacy_connector(dev,
   2597  1.1  riastrad 						    5,
   2598  1.1  riastrad 						    ATOM_DEVICE_LCD1_SUPPORT,
   2599  1.1  riastrad 						    DRM_MODE_CONNECTOR_LVDS,
   2600  1.1  riastrad 						    &ddc_i2c,
   2601  1.1  riastrad 						    CONNECTOR_OBJECT_ID_LVDS,
   2602  1.1  riastrad 						    &hpd);
   2603  1.1  riastrad 		}
   2604  1.1  riastrad 	}
   2605  1.1  riastrad 
   2606  1.1  riastrad 	/* check TV table */
   2607  1.1  riastrad 	if (rdev->family != CHIP_R100 && rdev->family != CHIP_R200) {
   2608  1.1  riastrad 		uint32_t tv_info =
   2609  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_TV_INFO_TABLE);
   2610  1.1  riastrad 		if (tv_info) {
   2611  1.1  riastrad 			if (RBIOS8(tv_info + 6) == 'T') {
   2612  1.1  riastrad 				if (radeon_apply_legacy_tv_quirks(dev)) {
   2613  1.1  riastrad 					hpd.hpd = RADEON_HPD_NONE;
   2614  1.1  riastrad 					ddc_i2c.valid = false;
   2615  1.1  riastrad 					radeon_add_legacy_encoder(dev,
   2616  1.1  riastrad 								  radeon_get_encoder_enum
   2617  1.1  riastrad 								  (dev,
   2618  1.1  riastrad 								   ATOM_DEVICE_TV1_SUPPORT,
   2619  1.1  riastrad 								   2),
   2620  1.1  riastrad 								  ATOM_DEVICE_TV1_SUPPORT);
   2621  1.1  riastrad 					radeon_add_legacy_connector(dev, 6,
   2622  1.1  riastrad 								    ATOM_DEVICE_TV1_SUPPORT,
   2623  1.1  riastrad 								    DRM_MODE_CONNECTOR_SVIDEO,
   2624  1.1  riastrad 								    &ddc_i2c,
   2625  1.1  riastrad 								    CONNECTOR_OBJECT_ID_SVIDEO,
   2626  1.1  riastrad 								    &hpd);
   2627  1.1  riastrad 				}
   2628  1.1  riastrad 			}
   2629  1.1  riastrad 		}
   2630  1.1  riastrad 	}
   2631  1.1  riastrad 
   2632  1.1  riastrad 	radeon_link_encoder_connector(dev);
   2633  1.1  riastrad 
   2634  1.1  riastrad 	return true;
   2635  1.1  riastrad }
   2636  1.1  riastrad 
   2637  1.1  riastrad static const char *thermal_controller_names[] = {
   2638  1.1  riastrad 	"NONE",
   2639  1.1  riastrad 	"lm63",
   2640  1.1  riastrad 	"adm1032",
   2641  1.1  riastrad };
   2642  1.1  riastrad 
   2643  1.1  riastrad void radeon_combios_get_power_modes(struct radeon_device *rdev)
   2644  1.1  riastrad {
   2645  1.1  riastrad 	struct drm_device *dev = rdev->ddev;
   2646  1.1  riastrad 	u16 offset, misc, misc2 = 0;
   2647  1.4  riastrad 	u8 rev, tmp;
   2648  1.1  riastrad 	int state_index = 0;
   2649  1.1  riastrad 	struct radeon_i2c_bus_rec i2c_bus;
   2650  1.1  riastrad 
   2651  1.1  riastrad 	rdev->pm.default_power_state_index = -1;
   2652  1.1  riastrad 
   2653  1.1  riastrad 	/* allocate 2 power states */
   2654  1.4  riastrad 	rdev->pm.power_state = kcalloc(2, sizeof(struct radeon_power_state),
   2655  1.4  riastrad 				       GFP_KERNEL);
   2656  1.1  riastrad 	if (rdev->pm.power_state) {
   2657  1.1  riastrad 		/* allocate 1 clock mode per state */
   2658  1.1  riastrad 		rdev->pm.power_state[0].clock_info =
   2659  1.4  riastrad 			kcalloc(1, sizeof(struct radeon_pm_clock_info),
   2660  1.4  riastrad 				GFP_KERNEL);
   2661  1.1  riastrad 		rdev->pm.power_state[1].clock_info =
   2662  1.4  riastrad 			kcalloc(1, sizeof(struct radeon_pm_clock_info),
   2663  1.4  riastrad 				GFP_KERNEL);
   2664  1.1  riastrad 		if (!rdev->pm.power_state[0].clock_info ||
   2665  1.1  riastrad 		    !rdev->pm.power_state[1].clock_info)
   2666  1.1  riastrad 			goto pm_failed;
   2667  1.1  riastrad 	} else
   2668  1.1  riastrad 		goto pm_failed;
   2669  1.1  riastrad 
   2670  1.1  riastrad 	/* check for a thermal chip */
   2671  1.1  riastrad 	offset = combios_get_table_offset(dev, COMBIOS_OVERDRIVE_INFO_TABLE);
   2672  1.1  riastrad 	if (offset) {
   2673  1.1  riastrad 		u8 thermal_controller = 0, gpio = 0, i2c_addr = 0, clk_bit = 0, data_bit = 0;
   2674  1.1  riastrad 
   2675  1.1  riastrad 		rev = RBIOS8(offset);
   2676  1.1  riastrad 
   2677  1.1  riastrad 		if (rev == 0) {
   2678  1.1  riastrad 			thermal_controller = RBIOS8(offset + 3);
   2679  1.1  riastrad 			gpio = RBIOS8(offset + 4) & 0x3f;
   2680  1.1  riastrad 			i2c_addr = RBIOS8(offset + 5);
   2681  1.1  riastrad 		} else if (rev == 1) {
   2682  1.1  riastrad 			thermal_controller = RBIOS8(offset + 4);
   2683  1.1  riastrad 			gpio = RBIOS8(offset + 5) & 0x3f;
   2684  1.1  riastrad 			i2c_addr = RBIOS8(offset + 6);
   2685  1.1  riastrad 		} else if (rev == 2) {
   2686  1.1  riastrad 			thermal_controller = RBIOS8(offset + 4);
   2687  1.1  riastrad 			gpio = RBIOS8(offset + 5) & 0x3f;
   2688  1.1  riastrad 			i2c_addr = RBIOS8(offset + 6);
   2689  1.1  riastrad 			clk_bit = RBIOS8(offset + 0xa);
   2690  1.1  riastrad 			data_bit = RBIOS8(offset + 0xb);
   2691  1.1  riastrad 		}
   2692  1.1  riastrad 		if ((thermal_controller > 0) && (thermal_controller < 3)) {
   2693  1.1  riastrad 			DRM_INFO("Possible %s thermal controller at 0x%02x\n",
   2694  1.1  riastrad 				 thermal_controller_names[thermal_controller],
   2695  1.1  riastrad 				 i2c_addr >> 1);
   2696  1.1  riastrad 			if (gpio == DDC_LCD) {
   2697  1.1  riastrad 				/* MM i2c */
   2698  1.1  riastrad 				i2c_bus.valid = true;
   2699  1.1  riastrad 				i2c_bus.hw_capable = true;
   2700  1.1  riastrad 				i2c_bus.mm_i2c = true;
   2701  1.1  riastrad 				i2c_bus.i2c_id = 0xa0;
   2702  1.1  riastrad 			} else if (gpio == DDC_GPIO)
   2703  1.1  riastrad 				i2c_bus = combios_setup_i2c_bus(rdev, gpio, 1 << clk_bit, 1 << data_bit);
   2704  1.1  riastrad 			else
   2705  1.1  riastrad 				i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
   2706  1.1  riastrad 			rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
   2707  1.1  riastrad 			if (rdev->pm.i2c_bus) {
   2708  1.1  riastrad 				struct i2c_board_info info = { };
   2709  1.1  riastrad 				const char *name = thermal_controller_names[thermal_controller];
   2710  1.1  riastrad 				info.addr = i2c_addr >> 1;
   2711  1.1  riastrad 				strlcpy(info.type, name, sizeof(info.type));
   2712  1.1  riastrad 				i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
   2713  1.1  riastrad 			}
   2714  1.1  riastrad 		}
   2715  1.1  riastrad 	} else {
   2716  1.1  riastrad 		/* boards with a thermal chip, but no overdrive table */
   2717  1.1  riastrad 
   2718  1.1  riastrad 		/* Asus 9600xt has an f75375 on the monid bus */
   2719  1.1  riastrad 		if ((dev->pdev->device == 0x4152) &&
   2720  1.1  riastrad 		    (dev->pdev->subsystem_vendor == 0x1043) &&
   2721  1.1  riastrad 		    (dev->pdev->subsystem_device == 0xc002)) {
   2722  1.1  riastrad 			i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
   2723  1.1  riastrad 			rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
   2724  1.1  riastrad 			if (rdev->pm.i2c_bus) {
   2725  1.1  riastrad 				struct i2c_board_info info = { };
   2726  1.1  riastrad 				const char *name = "f75375";
   2727  1.1  riastrad 				info.addr = 0x28;
   2728  1.1  riastrad 				strlcpy(info.type, name, sizeof(info.type));
   2729  1.1  riastrad 				i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
   2730  1.1  riastrad 				DRM_INFO("Possible %s thermal controller at 0x%02x\n",
   2731  1.1  riastrad 					 name, info.addr);
   2732  1.1  riastrad 			}
   2733  1.1  riastrad 		}
   2734  1.1  riastrad 	}
   2735  1.1  riastrad 
   2736  1.1  riastrad 	if (rdev->flags & RADEON_IS_MOBILITY) {
   2737  1.1  riastrad 		offset = combios_get_table_offset(dev, COMBIOS_POWERPLAY_INFO_TABLE);
   2738  1.1  riastrad 		if (offset) {
   2739  1.1  riastrad 			rev = RBIOS8(offset);
   2740  1.1  riastrad 			/* power mode 0 tends to be the only valid one */
   2741  1.1  riastrad 			rdev->pm.power_state[state_index].num_clock_modes = 1;
   2742  1.1  riastrad 			rdev->pm.power_state[state_index].clock_info[0].mclk = RBIOS32(offset + 0x5 + 0x2);
   2743  1.1  riastrad 			rdev->pm.power_state[state_index].clock_info[0].sclk = RBIOS32(offset + 0x5 + 0x6);
   2744  1.1  riastrad 			if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
   2745  1.1  riastrad 			    (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
   2746  1.1  riastrad 				goto default_mode;
   2747  1.1  riastrad 			rdev->pm.power_state[state_index].type =
   2748  1.1  riastrad 				POWER_STATE_TYPE_BATTERY;
   2749  1.1  riastrad 			misc = RBIOS16(offset + 0x5 + 0x0);
   2750  1.1  riastrad 			if (rev > 4)
   2751  1.1  riastrad 				misc2 = RBIOS16(offset + 0x5 + 0xe);
   2752  1.1  riastrad 			rdev->pm.power_state[state_index].misc = misc;
   2753  1.1  riastrad 			rdev->pm.power_state[state_index].misc2 = misc2;
   2754  1.1  riastrad 			if (misc & 0x4) {
   2755  1.1  riastrad 				rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_GPIO;
   2756  1.1  riastrad 				if (misc & 0x8)
   2757  1.1  riastrad 					rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
   2758  1.1  riastrad 						true;
   2759  1.1  riastrad 				else
   2760  1.1  riastrad 					rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
   2761  1.1  riastrad 						false;
   2762  1.1  riastrad 				rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = true;
   2763  1.1  riastrad 				if (rev < 6) {
   2764  1.1  riastrad 					rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
   2765  1.1  riastrad 						RBIOS16(offset + 0x5 + 0xb) * 4;
   2766  1.1  riastrad 					tmp = RBIOS8(offset + 0x5 + 0xd);
   2767  1.1  riastrad 					rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
   2768  1.1  riastrad 				} else {
   2769  1.1  riastrad 					u8 entries = RBIOS8(offset + 0x5 + 0xb);
   2770  1.1  riastrad 					u16 voltage_table_offset = RBIOS16(offset + 0x5 + 0xc);
   2771  1.1  riastrad 					if (entries && voltage_table_offset) {
   2772  1.1  riastrad 						rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.reg =
   2773  1.1  riastrad 							RBIOS16(voltage_table_offset) * 4;
   2774  1.1  riastrad 						tmp = RBIOS8(voltage_table_offset + 0x2);
   2775  1.1  riastrad 						rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.mask = (1 << tmp);
   2776  1.1  riastrad 					} else
   2777  1.1  riastrad 						rdev->pm.power_state[state_index].clock_info[0].voltage.gpio.valid = false;
   2778  1.1  riastrad 				}
   2779  1.1  riastrad 				switch ((misc2 & 0x700) >> 8) {
   2780  1.1  riastrad 				case 0:
   2781  1.1  riastrad 				default:
   2782  1.1  riastrad 					rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 0;
   2783  1.1  riastrad 					break;
   2784  1.1  riastrad 				case 1:
   2785  1.1  riastrad 					rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 33;
   2786  1.1  riastrad 					break;
   2787  1.1  riastrad 				case 2:
   2788  1.1  riastrad 					rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 66;
   2789  1.1  riastrad 					break;
   2790  1.1  riastrad 				case 3:
   2791  1.1  riastrad 					rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 99;
   2792  1.1  riastrad 					break;
   2793  1.1  riastrad 				case 4:
   2794  1.1  riastrad 					rdev->pm.power_state[state_index].clock_info[0].voltage.delay = 132;
   2795  1.1  riastrad 					break;
   2796  1.1  riastrad 				}
   2797  1.1  riastrad 			} else
   2798  1.1  riastrad 				rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
   2799  1.1  riastrad 			if (rev > 6)
   2800  1.1  riastrad 				rdev->pm.power_state[state_index].pcie_lanes =
   2801  1.1  riastrad 					RBIOS8(offset + 0x5 + 0x10);
   2802  1.1  riastrad 			rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
   2803  1.1  riastrad 			state_index++;
   2804  1.1  riastrad 		} else {
   2805  1.1  riastrad 			/* XXX figure out some good default low power mode for mobility cards w/out power tables */
   2806  1.1  riastrad 		}
   2807  1.1  riastrad 	} else {
   2808  1.1  riastrad 		/* XXX figure out some good default low power mode for desktop cards */
   2809  1.1  riastrad 	}
   2810  1.1  riastrad 
   2811  1.1  riastrad default_mode:
   2812  1.1  riastrad 	/* add the default mode */
   2813  1.1  riastrad 	rdev->pm.power_state[state_index].type =
   2814  1.1  riastrad 		POWER_STATE_TYPE_DEFAULT;
   2815  1.1  riastrad 	rdev->pm.power_state[state_index].num_clock_modes = 1;
   2816  1.1  riastrad 	rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
   2817  1.1  riastrad 	rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
   2818  1.1  riastrad 	rdev->pm.power_state[state_index].default_clock_mode = &rdev->pm.power_state[state_index].clock_info[0];
   2819  1.1  riastrad 	if ((state_index > 0) &&
   2820  1.1  riastrad 	    (rdev->pm.power_state[0].clock_info[0].voltage.type == VOLTAGE_GPIO))
   2821  1.1  riastrad 		rdev->pm.power_state[state_index].clock_info[0].voltage =
   2822  1.1  riastrad 			rdev->pm.power_state[0].clock_info[0].voltage;
   2823  1.1  riastrad 	else
   2824  1.1  riastrad 		rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
   2825  1.1  riastrad 	rdev->pm.power_state[state_index].pcie_lanes = 16;
   2826  1.1  riastrad 	rdev->pm.power_state[state_index].flags = 0;
   2827  1.1  riastrad 	rdev->pm.default_power_state_index = state_index;
   2828  1.1  riastrad 	rdev->pm.num_power_states = state_index + 1;
   2829  1.1  riastrad 
   2830  1.1  riastrad 	rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
   2831  1.1  riastrad 	rdev->pm.current_clock_mode_index = 0;
   2832  1.1  riastrad 	return;
   2833  1.1  riastrad 
   2834  1.1  riastrad pm_failed:
   2835  1.1  riastrad 	rdev->pm.default_power_state_index = state_index;
   2836  1.1  riastrad 	rdev->pm.num_power_states = 0;
   2837  1.1  riastrad 
   2838  1.1  riastrad 	rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
   2839  1.1  riastrad 	rdev->pm.current_clock_mode_index = 0;
   2840  1.1  riastrad }
   2841  1.1  riastrad 
   2842  1.1  riastrad void radeon_external_tmds_setup(struct drm_encoder *encoder)
   2843  1.1  riastrad {
   2844  1.1  riastrad 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
   2845  1.1  riastrad 	struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
   2846  1.1  riastrad 
   2847  1.1  riastrad 	if (!tmds)
   2848  1.1  riastrad 		return;
   2849  1.1  riastrad 
   2850  1.1  riastrad 	switch (tmds->dvo_chip) {
   2851  1.1  riastrad 	case DVO_SIL164:
   2852  1.1  riastrad 		/* sil 164 */
   2853  1.1  riastrad 		radeon_i2c_put_byte(tmds->i2c_bus,
   2854  1.1  riastrad 				    tmds->slave_addr,
   2855  1.1  riastrad 				    0x08, 0x30);
   2856  1.1  riastrad 		radeon_i2c_put_byte(tmds->i2c_bus,
   2857  1.1  riastrad 				       tmds->slave_addr,
   2858  1.1  riastrad 				       0x09, 0x00);
   2859  1.1  riastrad 		radeon_i2c_put_byte(tmds->i2c_bus,
   2860  1.1  riastrad 				    tmds->slave_addr,
   2861  1.1  riastrad 				    0x0a, 0x90);
   2862  1.1  riastrad 		radeon_i2c_put_byte(tmds->i2c_bus,
   2863  1.1  riastrad 				    tmds->slave_addr,
   2864  1.1  riastrad 				    0x0c, 0x89);
   2865  1.1  riastrad 		radeon_i2c_put_byte(tmds->i2c_bus,
   2866  1.1  riastrad 				       tmds->slave_addr,
   2867  1.1  riastrad 				       0x08, 0x3b);
   2868  1.1  riastrad 		break;
   2869  1.1  riastrad 	case DVO_SIL1178:
   2870  1.1  riastrad 		/* sil 1178 - untested */
   2871  1.1  riastrad 		/*
   2872  1.1  riastrad 		 * 0x0f, 0x44
   2873  1.1  riastrad 		 * 0x0f, 0x4c
   2874  1.1  riastrad 		 * 0x0e, 0x01
   2875  1.1  riastrad 		 * 0x0a, 0x80
   2876  1.1  riastrad 		 * 0x09, 0x30
   2877  1.1  riastrad 		 * 0x0c, 0xc9
   2878  1.1  riastrad 		 * 0x0d, 0x70
   2879  1.1  riastrad 		 * 0x08, 0x32
   2880  1.1  riastrad 		 * 0x08, 0x33
   2881  1.1  riastrad 		 */
   2882  1.1  riastrad 		break;
   2883  1.1  riastrad 	default:
   2884  1.1  riastrad 		break;
   2885  1.1  riastrad 	}
   2886  1.1  riastrad 
   2887  1.1  riastrad }
   2888  1.1  riastrad 
   2889  1.1  riastrad bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder)
   2890  1.1  riastrad {
   2891  1.1  riastrad 	struct drm_device *dev = encoder->dev;
   2892  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   2893  1.1  riastrad 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
   2894  1.1  riastrad 	uint16_t offset;
   2895  1.1  riastrad 	uint8_t blocks, slave_addr, rev;
   2896  1.1  riastrad 	uint32_t index, id;
   2897  1.1  riastrad 	uint32_t reg, val, and_mask, or_mask;
   2898  1.1  riastrad 	struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
   2899  1.1  riastrad 
   2900  1.1  riastrad 	if (!tmds)
   2901  1.1  riastrad 		return false;
   2902  1.1  riastrad 
   2903  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP) {
   2904  1.1  riastrad 		offset = combios_get_table_offset(dev, COMBIOS_TMDS_POWER_ON_TABLE);
   2905  1.1  riastrad 		rev = RBIOS8(offset);
   2906  1.1  riastrad 		if (offset) {
   2907  1.1  riastrad 			rev = RBIOS8(offset);
   2908  1.1  riastrad 			if (rev > 1) {
   2909  1.1  riastrad 				blocks = RBIOS8(offset + 3);
   2910  1.1  riastrad 				index = offset + 4;
   2911  1.1  riastrad 				while (blocks > 0) {
   2912  1.1  riastrad 					id = RBIOS16(index);
   2913  1.1  riastrad 					index += 2;
   2914  1.1  riastrad 					switch (id >> 13) {
   2915  1.1  riastrad 					case 0:
   2916  1.1  riastrad 						reg = (id & 0x1fff) * 4;
   2917  1.1  riastrad 						val = RBIOS32(index);
   2918  1.1  riastrad 						index += 4;
   2919  1.1  riastrad 						WREG32(reg, val);
   2920  1.1  riastrad 						break;
   2921  1.1  riastrad 					case 2:
   2922  1.1  riastrad 						reg = (id & 0x1fff) * 4;
   2923  1.1  riastrad 						and_mask = RBIOS32(index);
   2924  1.1  riastrad 						index += 4;
   2925  1.1  riastrad 						or_mask = RBIOS32(index);
   2926  1.1  riastrad 						index += 4;
   2927  1.1  riastrad 						val = RREG32(reg);
   2928  1.1  riastrad 						val = (val & and_mask) | or_mask;
   2929  1.1  riastrad 						WREG32(reg, val);
   2930  1.1  riastrad 						break;
   2931  1.1  riastrad 					case 3:
   2932  1.1  riastrad 						val = RBIOS16(index);
   2933  1.1  riastrad 						index += 2;
   2934  1.1  riastrad 						udelay(val);
   2935  1.1  riastrad 						break;
   2936  1.1  riastrad 					case 4:
   2937  1.1  riastrad 						val = RBIOS16(index);
   2938  1.1  riastrad 						index += 2;
   2939  1.1  riastrad 						mdelay(val);
   2940  1.1  riastrad 						break;
   2941  1.1  riastrad 					case 6:
   2942  1.1  riastrad 						slave_addr = id & 0xff;
   2943  1.1  riastrad 						slave_addr >>= 1; /* 7 bit addressing */
   2944  1.1  riastrad 						index++;
   2945  1.1  riastrad 						reg = RBIOS8(index);
   2946  1.1  riastrad 						index++;
   2947  1.1  riastrad 						val = RBIOS8(index);
   2948  1.1  riastrad 						index++;
   2949  1.1  riastrad 						radeon_i2c_put_byte(tmds->i2c_bus,
   2950  1.1  riastrad 								    slave_addr,
   2951  1.1  riastrad 								    reg, val);
   2952  1.1  riastrad 						break;
   2953  1.1  riastrad 					default:
   2954  1.1  riastrad 						DRM_ERROR("Unknown id %d\n", id >> 13);
   2955  1.1  riastrad 						break;
   2956  1.1  riastrad 					}
   2957  1.1  riastrad 					blocks--;
   2958  1.1  riastrad 				}
   2959  1.1  riastrad 				return true;
   2960  1.1  riastrad 			}
   2961  1.1  riastrad 		}
   2962  1.1  riastrad 	} else {
   2963  1.1  riastrad 		offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
   2964  1.1  riastrad 		if (offset) {
   2965  1.1  riastrad 			index = offset + 10;
   2966  1.1  riastrad 			id = RBIOS16(index);
   2967  1.1  riastrad 			while (id != 0xffff) {
   2968  1.1  riastrad 				index += 2;
   2969  1.1  riastrad 				switch (id >> 13) {
   2970  1.1  riastrad 				case 0:
   2971  1.1  riastrad 					reg = (id & 0x1fff) * 4;
   2972  1.1  riastrad 					val = RBIOS32(index);
   2973  1.1  riastrad 					WREG32(reg, val);
   2974  1.1  riastrad 					break;
   2975  1.1  riastrad 				case 2:
   2976  1.1  riastrad 					reg = (id & 0x1fff) * 4;
   2977  1.1  riastrad 					and_mask = RBIOS32(index);
   2978  1.1  riastrad 					index += 4;
   2979  1.1  riastrad 					or_mask = RBIOS32(index);
   2980  1.1  riastrad 					index += 4;
   2981  1.1  riastrad 					val = RREG32(reg);
   2982  1.1  riastrad 					val = (val & and_mask) | or_mask;
   2983  1.1  riastrad 					WREG32(reg, val);
   2984  1.1  riastrad 					break;
   2985  1.1  riastrad 				case 4:
   2986  1.1  riastrad 					val = RBIOS16(index);
   2987  1.1  riastrad 					index += 2;
   2988  1.1  riastrad 					udelay(val);
   2989  1.1  riastrad 					break;
   2990  1.1  riastrad 				case 5:
   2991  1.1  riastrad 					reg = id & 0x1fff;
   2992  1.1  riastrad 					and_mask = RBIOS32(index);
   2993  1.1  riastrad 					index += 4;
   2994  1.1  riastrad 					or_mask = RBIOS32(index);
   2995  1.1  riastrad 					index += 4;
   2996  1.1  riastrad 					val = RREG32_PLL(reg);
   2997  1.1  riastrad 					val = (val & and_mask) | or_mask;
   2998  1.1  riastrad 					WREG32_PLL(reg, val);
   2999  1.1  riastrad 					break;
   3000  1.1  riastrad 				case 6:
   3001  1.1  riastrad 					reg = id & 0x1fff;
   3002  1.1  riastrad 					val = RBIOS8(index);
   3003  1.1  riastrad 					index += 1;
   3004  1.1  riastrad 					radeon_i2c_put_byte(tmds->i2c_bus,
   3005  1.1  riastrad 							    tmds->slave_addr,
   3006  1.1  riastrad 							    reg, val);
   3007  1.1  riastrad 					break;
   3008  1.1  riastrad 				default:
   3009  1.1  riastrad 					DRM_ERROR("Unknown id %d\n", id >> 13);
   3010  1.1  riastrad 					break;
   3011  1.1  riastrad 				}
   3012  1.1  riastrad 				id = RBIOS16(index);
   3013  1.1  riastrad 			}
   3014  1.1  riastrad 			return true;
   3015  1.1  riastrad 		}
   3016  1.1  riastrad 	}
   3017  1.1  riastrad 	return false;
   3018  1.1  riastrad }
   3019  1.1  riastrad 
   3020  1.1  riastrad static void combios_parse_mmio_table(struct drm_device *dev, uint16_t offset)
   3021  1.1  riastrad {
   3022  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3023  1.1  riastrad 
   3024  1.1  riastrad 	if (offset) {
   3025  1.1  riastrad 		while (RBIOS16(offset)) {
   3026  1.1  riastrad 			uint16_t cmd = ((RBIOS16(offset) & 0xe000) >> 13);
   3027  1.1  riastrad 			uint32_t addr = (RBIOS16(offset) & 0x1fff);
   3028  1.1  riastrad 			uint32_t val, and_mask, or_mask;
   3029  1.1  riastrad 			uint32_t tmp;
   3030  1.1  riastrad 
   3031  1.1  riastrad 			offset += 2;
   3032  1.1  riastrad 			switch (cmd) {
   3033  1.1  riastrad 			case 0:
   3034  1.1  riastrad 				val = RBIOS32(offset);
   3035  1.1  riastrad 				offset += 4;
   3036  1.1  riastrad 				WREG32(addr, val);
   3037  1.1  riastrad 				break;
   3038  1.1  riastrad 			case 1:
   3039  1.1  riastrad 				val = RBIOS32(offset);
   3040  1.1  riastrad 				offset += 4;
   3041  1.1  riastrad 				WREG32(addr, val);
   3042  1.1  riastrad 				break;
   3043  1.1  riastrad 			case 2:
   3044  1.1  riastrad 				and_mask = RBIOS32(offset);
   3045  1.1  riastrad 				offset += 4;
   3046  1.1  riastrad 				or_mask = RBIOS32(offset);
   3047  1.1  riastrad 				offset += 4;
   3048  1.1  riastrad 				tmp = RREG32(addr);
   3049  1.1  riastrad 				tmp &= and_mask;
   3050  1.1  riastrad 				tmp |= or_mask;
   3051  1.1  riastrad 				WREG32(addr, tmp);
   3052  1.1  riastrad 				break;
   3053  1.1  riastrad 			case 3:
   3054  1.1  riastrad 				and_mask = RBIOS32(offset);
   3055  1.1  riastrad 				offset += 4;
   3056  1.1  riastrad 				or_mask = RBIOS32(offset);
   3057  1.1  riastrad 				offset += 4;
   3058  1.1  riastrad 				tmp = RREG32(addr);
   3059  1.1  riastrad 				tmp &= and_mask;
   3060  1.1  riastrad 				tmp |= or_mask;
   3061  1.1  riastrad 				WREG32(addr, tmp);
   3062  1.1  riastrad 				break;
   3063  1.1  riastrad 			case 4:
   3064  1.1  riastrad 				val = RBIOS16(offset);
   3065  1.1  riastrad 				offset += 2;
   3066  1.1  riastrad 				udelay(val);
   3067  1.1  riastrad 				break;
   3068  1.1  riastrad 			case 5:
   3069  1.1  riastrad 				val = RBIOS16(offset);
   3070  1.1  riastrad 				offset += 2;
   3071  1.1  riastrad 				switch (addr) {
   3072  1.1  riastrad 				case 8:
   3073  1.1  riastrad 					while (val--) {
   3074  1.1  riastrad 						if (!
   3075  1.1  riastrad 						    (RREG32_PLL
   3076  1.1  riastrad 						     (RADEON_CLK_PWRMGT_CNTL) &
   3077  1.1  riastrad 						     RADEON_MC_BUSY))
   3078  1.1  riastrad 							break;
   3079  1.1  riastrad 					}
   3080  1.1  riastrad 					break;
   3081  1.1  riastrad 				case 9:
   3082  1.1  riastrad 					while (val--) {
   3083  1.1  riastrad 						if ((RREG32(RADEON_MC_STATUS) &
   3084  1.1  riastrad 						     RADEON_MC_IDLE))
   3085  1.1  riastrad 							break;
   3086  1.1  riastrad 					}
   3087  1.1  riastrad 					break;
   3088  1.1  riastrad 				default:
   3089  1.1  riastrad 					break;
   3090  1.1  riastrad 				}
   3091  1.1  riastrad 				break;
   3092  1.1  riastrad 			default:
   3093  1.1  riastrad 				break;
   3094  1.1  riastrad 			}
   3095  1.1  riastrad 		}
   3096  1.1  riastrad 	}
   3097  1.1  riastrad }
   3098  1.1  riastrad 
   3099  1.1  riastrad static void combios_parse_pll_table(struct drm_device *dev, uint16_t offset)
   3100  1.1  riastrad {
   3101  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3102  1.1  riastrad 
   3103  1.1  riastrad 	if (offset) {
   3104  1.1  riastrad 		while (RBIOS8(offset)) {
   3105  1.1  riastrad 			uint8_t cmd = ((RBIOS8(offset) & 0xc0) >> 6);
   3106  1.1  riastrad 			uint8_t addr = (RBIOS8(offset) & 0x3f);
   3107  1.1  riastrad 			uint32_t val, shift, tmp;
   3108  1.1  riastrad 			uint32_t and_mask, or_mask;
   3109  1.1  riastrad 
   3110  1.1  riastrad 			offset++;
   3111  1.1  riastrad 			switch (cmd) {
   3112  1.1  riastrad 			case 0:
   3113  1.1  riastrad 				val = RBIOS32(offset);
   3114  1.1  riastrad 				offset += 4;
   3115  1.1  riastrad 				WREG32_PLL(addr, val);
   3116  1.1  riastrad 				break;
   3117  1.1  riastrad 			case 1:
   3118  1.1  riastrad 				shift = RBIOS8(offset) * 8;
   3119  1.1  riastrad 				offset++;
   3120  1.1  riastrad 				and_mask = RBIOS8(offset) << shift;
   3121  1.1  riastrad 				and_mask |= ~(0xff << shift);
   3122  1.1  riastrad 				offset++;
   3123  1.1  riastrad 				or_mask = RBIOS8(offset) << shift;
   3124  1.1  riastrad 				offset++;
   3125  1.1  riastrad 				tmp = RREG32_PLL(addr);
   3126  1.1  riastrad 				tmp &= and_mask;
   3127  1.1  riastrad 				tmp |= or_mask;
   3128  1.1  riastrad 				WREG32_PLL(addr, tmp);
   3129  1.1  riastrad 				break;
   3130  1.1  riastrad 			case 2:
   3131  1.1  riastrad 			case 3:
   3132  1.1  riastrad 				tmp = 1000;
   3133  1.1  riastrad 				switch (addr) {
   3134  1.1  riastrad 				case 1:
   3135  1.1  riastrad 					udelay(150);
   3136  1.1  riastrad 					break;
   3137  1.1  riastrad 				case 2:
   3138  1.1  riastrad 					mdelay(1);
   3139  1.1  riastrad 					break;
   3140  1.1  riastrad 				case 3:
   3141  1.1  riastrad 					while (tmp--) {
   3142  1.1  riastrad 						if (!
   3143  1.1  riastrad 						    (RREG32_PLL
   3144  1.1  riastrad 						     (RADEON_CLK_PWRMGT_CNTL) &
   3145  1.1  riastrad 						     RADEON_MC_BUSY))
   3146  1.1  riastrad 							break;
   3147  1.1  riastrad 					}
   3148  1.1  riastrad 					break;
   3149  1.1  riastrad 				case 4:
   3150  1.1  riastrad 					while (tmp--) {
   3151  1.1  riastrad 						if (RREG32_PLL
   3152  1.1  riastrad 						    (RADEON_CLK_PWRMGT_CNTL) &
   3153  1.1  riastrad 						    RADEON_DLL_READY)
   3154  1.1  riastrad 							break;
   3155  1.1  riastrad 					}
   3156  1.1  riastrad 					break;
   3157  1.1  riastrad 				case 5:
   3158  1.1  riastrad 					tmp =
   3159  1.1  riastrad 					    RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
   3160  1.1  riastrad 					if (tmp & RADEON_CG_NO1_DEBUG_0) {
   3161  1.1  riastrad #if 0
   3162  1.1  riastrad 						uint32_t mclk_cntl =
   3163  1.1  riastrad 						    RREG32_PLL
   3164  1.1  riastrad 						    (RADEON_MCLK_CNTL);
   3165  1.1  riastrad 						mclk_cntl &= 0xffff0000;
   3166  1.1  riastrad 						/*mclk_cntl |= 0x00001111;*//* ??? */
   3167  1.1  riastrad 						WREG32_PLL(RADEON_MCLK_CNTL,
   3168  1.1  riastrad 							   mclk_cntl);
   3169  1.1  riastrad 						mdelay(10);
   3170  1.1  riastrad #endif
   3171  1.1  riastrad 						WREG32_PLL
   3172  1.1  riastrad 						    (RADEON_CLK_PWRMGT_CNTL,
   3173  1.1  riastrad 						     tmp &
   3174  1.1  riastrad 						     ~RADEON_CG_NO1_DEBUG_0);
   3175  1.1  riastrad 						mdelay(10);
   3176  1.1  riastrad 					}
   3177  1.1  riastrad 					break;
   3178  1.1  riastrad 				default:
   3179  1.1  riastrad 					break;
   3180  1.1  riastrad 				}
   3181  1.1  riastrad 				break;
   3182  1.1  riastrad 			default:
   3183  1.1  riastrad 				break;
   3184  1.1  riastrad 			}
   3185  1.1  riastrad 		}
   3186  1.1  riastrad 	}
   3187  1.1  riastrad }
   3188  1.1  riastrad 
   3189  1.1  riastrad static void combios_parse_ram_reset_table(struct drm_device *dev,
   3190  1.1  riastrad 					  uint16_t offset)
   3191  1.1  riastrad {
   3192  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3193  1.1  riastrad 	uint32_t tmp;
   3194  1.1  riastrad 
   3195  1.1  riastrad 	if (offset) {
   3196  1.1  riastrad 		uint8_t val = RBIOS8(offset);
   3197  1.1  riastrad 		while (val != 0xff) {
   3198  1.1  riastrad 			offset++;
   3199  1.1  riastrad 
   3200  1.1  riastrad 			if (val == 0x0f) {
   3201  1.1  riastrad 				uint32_t channel_complete_mask;
   3202  1.1  riastrad 
   3203  1.1  riastrad 				if (ASIC_IS_R300(rdev))
   3204  1.1  riastrad 					channel_complete_mask =
   3205  1.1  riastrad 					    R300_MEM_PWRUP_COMPLETE;
   3206  1.1  riastrad 				else
   3207  1.1  riastrad 					channel_complete_mask =
   3208  1.1  riastrad 					    RADEON_MEM_PWRUP_COMPLETE;
   3209  1.1  riastrad 				tmp = 20000;
   3210  1.1  riastrad 				while (tmp--) {
   3211  1.1  riastrad 					if ((RREG32(RADEON_MEM_STR_CNTL) &
   3212  1.1  riastrad 					     channel_complete_mask) ==
   3213  1.1  riastrad 					    channel_complete_mask)
   3214  1.1  riastrad 						break;
   3215  1.1  riastrad 				}
   3216  1.1  riastrad 			} else {
   3217  1.1  riastrad 				uint32_t or_mask = RBIOS16(offset);
   3218  1.1  riastrad 				offset += 2;
   3219  1.1  riastrad 
   3220  1.1  riastrad 				tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
   3221  1.1  riastrad 				tmp &= RADEON_SDRAM_MODE_MASK;
   3222  1.1  riastrad 				tmp |= or_mask;
   3223  1.1  riastrad 				WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
   3224  1.1  riastrad 
   3225  1.1  riastrad 				or_mask = val << 24;
   3226  1.1  riastrad 				tmp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
   3227  1.1  riastrad 				tmp &= RADEON_B3MEM_RESET_MASK;
   3228  1.1  riastrad 				tmp |= or_mask;
   3229  1.1  riastrad 				WREG32(RADEON_MEM_SDRAM_MODE_REG, tmp);
   3230  1.1  riastrad 			}
   3231  1.1  riastrad 			val = RBIOS8(offset);
   3232  1.1  riastrad 		}
   3233  1.1  riastrad 	}
   3234  1.1  riastrad }
   3235  1.1  riastrad 
   3236  1.1  riastrad static uint32_t combios_detect_ram(struct drm_device *dev, int ram,
   3237  1.1  riastrad 				   int mem_addr_mapping)
   3238  1.1  riastrad {
   3239  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3240  1.1  riastrad 	uint32_t mem_cntl;
   3241  1.1  riastrad 	uint32_t mem_size;
   3242  1.1  riastrad 	uint32_t addr = 0;
   3243  1.1  riastrad 
   3244  1.1  riastrad 	mem_cntl = RREG32(RADEON_MEM_CNTL);
   3245  1.1  riastrad 	if (mem_cntl & RV100_HALF_MODE)
   3246  1.1  riastrad 		ram /= 2;
   3247  1.1  riastrad 	mem_size = ram;
   3248  1.1  riastrad 	mem_cntl &= ~(0xff << 8);
   3249  1.1  riastrad 	mem_cntl |= (mem_addr_mapping & 0xff) << 8;
   3250  1.1  riastrad 	WREG32(RADEON_MEM_CNTL, mem_cntl);
   3251  1.1  riastrad 	RREG32(RADEON_MEM_CNTL);
   3252  1.1  riastrad 
   3253  1.1  riastrad 	/* sdram reset ? */
   3254  1.1  riastrad 
   3255  1.1  riastrad 	/* something like this????  */
   3256  1.1  riastrad 	while (ram--) {
   3257  1.1  riastrad 		addr = ram * 1024 * 1024;
   3258  1.1  riastrad 		/* write to each page */
   3259  1.1  riastrad 		WREG32_IDX((addr) | RADEON_MM_APER, 0xdeadbeef);
   3260  1.1  riastrad 		/* read back and verify */
   3261  1.1  riastrad 		if (RREG32_IDX((addr) | RADEON_MM_APER) != 0xdeadbeef)
   3262  1.1  riastrad 			return 0;
   3263  1.1  riastrad 	}
   3264  1.1  riastrad 
   3265  1.1  riastrad 	return mem_size;
   3266  1.1  riastrad }
   3267  1.1  riastrad 
   3268  1.1  riastrad static void combios_write_ram_size(struct drm_device *dev)
   3269  1.1  riastrad {
   3270  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3271  1.1  riastrad 	uint8_t rev;
   3272  1.1  riastrad 	uint16_t offset;
   3273  1.1  riastrad 	uint32_t mem_size = 0;
   3274  1.1  riastrad 	uint32_t mem_cntl = 0;
   3275  1.1  riastrad 
   3276  1.1  riastrad 	/* should do something smarter here I guess... */
   3277  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP)
   3278  1.1  riastrad 		return;
   3279  1.1  riastrad 
   3280  1.1  riastrad 	/* first check detected mem table */
   3281  1.1  riastrad 	offset = combios_get_table_offset(dev, COMBIOS_DETECTED_MEM_TABLE);
   3282  1.1  riastrad 	if (offset) {
   3283  1.1  riastrad 		rev = RBIOS8(offset);
   3284  1.1  riastrad 		if (rev < 3) {
   3285  1.1  riastrad 			mem_cntl = RBIOS32(offset + 1);
   3286  1.1  riastrad 			mem_size = RBIOS16(offset + 5);
   3287  1.1  riastrad 			if ((rdev->family < CHIP_R200) &&
   3288  1.1  riastrad 			    !ASIC_IS_RN50(rdev))
   3289  1.1  riastrad 				WREG32(RADEON_MEM_CNTL, mem_cntl);
   3290  1.1  riastrad 		}
   3291  1.1  riastrad 	}
   3292  1.1  riastrad 
   3293  1.1  riastrad 	if (!mem_size) {
   3294  1.1  riastrad 		offset =
   3295  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_MEM_CONFIG_TABLE);
   3296  1.1  riastrad 		if (offset) {
   3297  1.1  riastrad 			rev = RBIOS8(offset - 1);
   3298  1.1  riastrad 			if (rev < 1) {
   3299  1.1  riastrad 				if ((rdev->family < CHIP_R200)
   3300  1.1  riastrad 				    && !ASIC_IS_RN50(rdev)) {
   3301  1.1  riastrad 					int ram = 0;
   3302  1.1  riastrad 					int mem_addr_mapping = 0;
   3303  1.1  riastrad 
   3304  1.1  riastrad 					while (RBIOS8(offset)) {
   3305  1.1  riastrad 						ram = RBIOS8(offset);
   3306  1.1  riastrad 						mem_addr_mapping =
   3307  1.1  riastrad 						    RBIOS8(offset + 1);
   3308  1.1  riastrad 						if (mem_addr_mapping != 0x25)
   3309  1.1  riastrad 							ram *= 2;
   3310  1.1  riastrad 						mem_size =
   3311  1.1  riastrad 						    combios_detect_ram(dev, ram,
   3312  1.1  riastrad 								       mem_addr_mapping);
   3313  1.1  riastrad 						if (mem_size)
   3314  1.1  riastrad 							break;
   3315  1.1  riastrad 						offset += 2;
   3316  1.1  riastrad 					}
   3317  1.1  riastrad 				} else
   3318  1.1  riastrad 					mem_size = RBIOS8(offset);
   3319  1.1  riastrad 			} else {
   3320  1.1  riastrad 				mem_size = RBIOS8(offset);
   3321  1.1  riastrad 				mem_size *= 2;	/* convert to MB */
   3322  1.1  riastrad 			}
   3323  1.1  riastrad 		}
   3324  1.1  riastrad 	}
   3325  1.1  riastrad 
   3326  1.1  riastrad 	mem_size *= (1024 * 1024);	/* convert to bytes */
   3327  1.1  riastrad 	WREG32(RADEON_CONFIG_MEMSIZE, mem_size);
   3328  1.1  riastrad }
   3329  1.1  riastrad 
   3330  1.1  riastrad void radeon_combios_asic_init(struct drm_device *dev)
   3331  1.1  riastrad {
   3332  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3333  1.1  riastrad 	uint16_t table;
   3334  1.1  riastrad 
   3335  1.1  riastrad 	/* port hardcoded mac stuff from radeonfb */
   3336  1.1  riastrad 	if (rdev->bios == NULL)
   3337  1.1  riastrad 		return;
   3338  1.1  riastrad 
   3339  1.1  riastrad 	/* ASIC INIT 1 */
   3340  1.1  riastrad 	table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_1_TABLE);
   3341  1.1  riastrad 	if (table)
   3342  1.1  riastrad 		combios_parse_mmio_table(dev, table);
   3343  1.1  riastrad 
   3344  1.1  riastrad 	/* PLL INIT */
   3345  1.1  riastrad 	table = combios_get_table_offset(dev, COMBIOS_PLL_INIT_TABLE);
   3346  1.1  riastrad 	if (table)
   3347  1.1  riastrad 		combios_parse_pll_table(dev, table);
   3348  1.1  riastrad 
   3349  1.1  riastrad 	/* ASIC INIT 2 */
   3350  1.1  riastrad 	table = combios_get_table_offset(dev, COMBIOS_ASIC_INIT_2_TABLE);
   3351  1.1  riastrad 	if (table)
   3352  1.1  riastrad 		combios_parse_mmio_table(dev, table);
   3353  1.1  riastrad 
   3354  1.1  riastrad 	if (!(rdev->flags & RADEON_IS_IGP)) {
   3355  1.1  riastrad 		/* ASIC INIT 4 */
   3356  1.1  riastrad 		table =
   3357  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_ASIC_INIT_4_TABLE);
   3358  1.1  riastrad 		if (table)
   3359  1.1  riastrad 			combios_parse_mmio_table(dev, table);
   3360  1.1  riastrad 
   3361  1.1  riastrad 		/* RAM RESET */
   3362  1.1  riastrad 		table = combios_get_table_offset(dev, COMBIOS_RAM_RESET_TABLE);
   3363  1.1  riastrad 		if (table)
   3364  1.1  riastrad 			combios_parse_ram_reset_table(dev, table);
   3365  1.1  riastrad 
   3366  1.1  riastrad 		/* ASIC INIT 3 */
   3367  1.1  riastrad 		table =
   3368  1.1  riastrad 		    combios_get_table_offset(dev, COMBIOS_ASIC_INIT_3_TABLE);
   3369  1.1  riastrad 		if (table)
   3370  1.1  riastrad 			combios_parse_mmio_table(dev, table);
   3371  1.1  riastrad 
   3372  1.1  riastrad 		/* write CONFIG_MEMSIZE */
   3373  1.1  riastrad 		combios_write_ram_size(dev);
   3374  1.1  riastrad 	}
   3375  1.1  riastrad 
   3376  1.1  riastrad 	/* quirk for rs4xx HP nx6125 laptop to make it resume
   3377  1.1  riastrad 	 * - it hangs on resume inside the dynclk 1 table.
   3378  1.1  riastrad 	 */
   3379  1.1  riastrad 	if (rdev->family == CHIP_RS480 &&
   3380  1.1  riastrad 	    rdev->pdev->subsystem_vendor == 0x103c &&
   3381  1.1  riastrad 	    rdev->pdev->subsystem_device == 0x308b)
   3382  1.1  riastrad 		return;
   3383  1.1  riastrad 
   3384  1.1  riastrad 	/* quirk for rs4xx HP dv5000 laptop to make it resume
   3385  1.1  riastrad 	 * - it hangs on resume inside the dynclk 1 table.
   3386  1.1  riastrad 	 */
   3387  1.1  riastrad 	if (rdev->family == CHIP_RS480 &&
   3388  1.1  riastrad 	    rdev->pdev->subsystem_vendor == 0x103c &&
   3389  1.1  riastrad 	    rdev->pdev->subsystem_device == 0x30a4)
   3390  1.1  riastrad 		return;
   3391  1.1  riastrad 
   3392  1.1  riastrad 	/* quirk for rs4xx Compaq Presario V5245EU laptop to make it resume
   3393  1.1  riastrad 	 * - it hangs on resume inside the dynclk 1 table.
   3394  1.1  riastrad 	 */
   3395  1.1  riastrad 	if (rdev->family == CHIP_RS480 &&
   3396  1.1  riastrad 	    rdev->pdev->subsystem_vendor == 0x103c &&
   3397  1.1  riastrad 	    rdev->pdev->subsystem_device == 0x30ae)
   3398  1.1  riastrad 		return;
   3399  1.1  riastrad 
   3400  1.3  riastrad 	/* quirk for rs4xx HP Compaq dc5750 Small Form Factor to make it resume
   3401  1.3  riastrad 	 * - it hangs on resume inside the dynclk 1 table.
   3402  1.3  riastrad 	 */
   3403  1.3  riastrad 	if (rdev->family == CHIP_RS480 &&
   3404  1.3  riastrad 	    rdev->pdev->subsystem_vendor == 0x103c &&
   3405  1.3  riastrad 	    rdev->pdev->subsystem_device == 0x280a)
   3406  1.3  riastrad 		return;
   3407  1.3  riastrad 	/* quirk for rs4xx Toshiba Sattellite L20-183 latop to make it resume
   3408  1.3  riastrad 	 * - it hangs on resume inside the dynclk 1 table.
   3409  1.3  riastrad 	 */
   3410  1.3  riastrad 	if (rdev->family == CHIP_RS400 &&
   3411  1.3  riastrad 	    rdev->pdev->subsystem_vendor == 0x1179 &&
   3412  1.3  riastrad 	    rdev->pdev->subsystem_device == 0xff31)
   3413  1.3  riastrad 	        return;
   3414  1.3  riastrad 
   3415  1.1  riastrad 	/* DYN CLK 1 */
   3416  1.1  riastrad 	table = combios_get_table_offset(dev, COMBIOS_DYN_CLK_1_TABLE);
   3417  1.1  riastrad 	if (table)
   3418  1.1  riastrad 		combios_parse_pll_table(dev, table);
   3419  1.1  riastrad 
   3420  1.1  riastrad }
   3421  1.1  riastrad 
   3422  1.1  riastrad void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev)
   3423  1.1  riastrad {
   3424  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3425  1.1  riastrad 	uint32_t bios_0_scratch, bios_6_scratch, bios_7_scratch;
   3426  1.1  riastrad 
   3427  1.1  riastrad 	bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
   3428  1.1  riastrad 	bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
   3429  1.1  riastrad 	bios_7_scratch = RREG32(RADEON_BIOS_7_SCRATCH);
   3430  1.1  riastrad 
   3431  1.1  riastrad 	/* let the bios control the backlight */
   3432  1.1  riastrad 	bios_0_scratch &= ~RADEON_DRIVER_BRIGHTNESS_EN;
   3433  1.1  riastrad 
   3434  1.1  riastrad 	/* tell the bios not to handle mode switching */
   3435  1.1  riastrad 	bios_6_scratch |= (RADEON_DISPLAY_SWITCHING_DIS |
   3436  1.1  riastrad 			   RADEON_ACC_MODE_CHANGE);
   3437  1.1  riastrad 
   3438  1.1  riastrad 	/* tell the bios a driver is loaded */
   3439  1.1  riastrad 	bios_7_scratch |= RADEON_DRV_LOADED;
   3440  1.1  riastrad 
   3441  1.1  riastrad 	WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
   3442  1.1  riastrad 	WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
   3443  1.1  riastrad 	WREG32(RADEON_BIOS_7_SCRATCH, bios_7_scratch);
   3444  1.1  riastrad }
   3445  1.1  riastrad 
   3446  1.1  riastrad void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock)
   3447  1.1  riastrad {
   3448  1.1  riastrad 	struct drm_device *dev = encoder->dev;
   3449  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3450  1.1  riastrad 	uint32_t bios_6_scratch;
   3451  1.1  riastrad 
   3452  1.1  riastrad 	bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
   3453  1.1  riastrad 
   3454  1.1  riastrad 	if (lock)
   3455  1.1  riastrad 		bios_6_scratch |= RADEON_DRIVER_CRITICAL;
   3456  1.1  riastrad 	else
   3457  1.1  riastrad 		bios_6_scratch &= ~RADEON_DRIVER_CRITICAL;
   3458  1.1  riastrad 
   3459  1.1  riastrad 	WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
   3460  1.1  riastrad }
   3461  1.1  riastrad 
   3462  1.1  riastrad void
   3463  1.1  riastrad radeon_combios_connected_scratch_regs(struct drm_connector *connector,
   3464  1.1  riastrad 				      struct drm_encoder *encoder,
   3465  1.1  riastrad 				      bool connected)
   3466  1.1  riastrad {
   3467  1.1  riastrad 	struct drm_device *dev = connector->dev;
   3468  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3469  1.1  riastrad 	struct radeon_connector *radeon_connector =
   3470  1.1  riastrad 	    to_radeon_connector(connector);
   3471  1.1  riastrad 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
   3472  1.1  riastrad 	uint32_t bios_4_scratch = RREG32(RADEON_BIOS_4_SCRATCH);
   3473  1.1  riastrad 	uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
   3474  1.1  riastrad 
   3475  1.1  riastrad 	if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
   3476  1.1  riastrad 	    (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
   3477  1.1  riastrad 		if (connected) {
   3478  1.1  riastrad 			DRM_DEBUG_KMS("TV1 connected\n");
   3479  1.1  riastrad 			/* fix me */
   3480  1.1  riastrad 			bios_4_scratch |= RADEON_TV1_ATTACHED_SVIDEO;
   3481  1.1  riastrad 			/*save->bios_4_scratch |= RADEON_TV1_ATTACHED_COMP; */
   3482  1.1  riastrad 			bios_5_scratch |= RADEON_TV1_ON;
   3483  1.1  riastrad 			bios_5_scratch |= RADEON_ACC_REQ_TV1;
   3484  1.1  riastrad 		} else {
   3485  1.1  riastrad 			DRM_DEBUG_KMS("TV1 disconnected\n");
   3486  1.1  riastrad 			bios_4_scratch &= ~RADEON_TV1_ATTACHED_MASK;
   3487  1.1  riastrad 			bios_5_scratch &= ~RADEON_TV1_ON;
   3488  1.1  riastrad 			bios_5_scratch &= ~RADEON_ACC_REQ_TV1;
   3489  1.1  riastrad 		}
   3490  1.1  riastrad 	}
   3491  1.1  riastrad 	if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
   3492  1.1  riastrad 	    (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
   3493  1.1  riastrad 		if (connected) {
   3494  1.1  riastrad 			DRM_DEBUG_KMS("LCD1 connected\n");
   3495  1.1  riastrad 			bios_4_scratch |= RADEON_LCD1_ATTACHED;
   3496  1.1  riastrad 			bios_5_scratch |= RADEON_LCD1_ON;
   3497  1.1  riastrad 			bios_5_scratch |= RADEON_ACC_REQ_LCD1;
   3498  1.1  riastrad 		} else {
   3499  1.1  riastrad 			DRM_DEBUG_KMS("LCD1 disconnected\n");
   3500  1.1  riastrad 			bios_4_scratch &= ~RADEON_LCD1_ATTACHED;
   3501  1.1  riastrad 			bios_5_scratch &= ~RADEON_LCD1_ON;
   3502  1.1  riastrad 			bios_5_scratch &= ~RADEON_ACC_REQ_LCD1;
   3503  1.1  riastrad 		}
   3504  1.1  riastrad 	}
   3505  1.1  riastrad 	if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
   3506  1.1  riastrad 	    (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
   3507  1.1  riastrad 		if (connected) {
   3508  1.1  riastrad 			DRM_DEBUG_KMS("CRT1 connected\n");
   3509  1.1  riastrad 			bios_4_scratch |= RADEON_CRT1_ATTACHED_COLOR;
   3510  1.1  riastrad 			bios_5_scratch |= RADEON_CRT1_ON;
   3511  1.1  riastrad 			bios_5_scratch |= RADEON_ACC_REQ_CRT1;
   3512  1.1  riastrad 		} else {
   3513  1.1  riastrad 			DRM_DEBUG_KMS("CRT1 disconnected\n");
   3514  1.1  riastrad 			bios_4_scratch &= ~RADEON_CRT1_ATTACHED_MASK;
   3515  1.1  riastrad 			bios_5_scratch &= ~RADEON_CRT1_ON;
   3516  1.1  riastrad 			bios_5_scratch &= ~RADEON_ACC_REQ_CRT1;
   3517  1.1  riastrad 		}
   3518  1.1  riastrad 	}
   3519  1.1  riastrad 	if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
   3520  1.1  riastrad 	    (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
   3521  1.1  riastrad 		if (connected) {
   3522  1.1  riastrad 			DRM_DEBUG_KMS("CRT2 connected\n");
   3523  1.1  riastrad 			bios_4_scratch |= RADEON_CRT2_ATTACHED_COLOR;
   3524  1.1  riastrad 			bios_5_scratch |= RADEON_CRT2_ON;
   3525  1.1  riastrad 			bios_5_scratch |= RADEON_ACC_REQ_CRT2;
   3526  1.1  riastrad 		} else {
   3527  1.1  riastrad 			DRM_DEBUG_KMS("CRT2 disconnected\n");
   3528  1.1  riastrad 			bios_4_scratch &= ~RADEON_CRT2_ATTACHED_MASK;
   3529  1.1  riastrad 			bios_5_scratch &= ~RADEON_CRT2_ON;
   3530  1.1  riastrad 			bios_5_scratch &= ~RADEON_ACC_REQ_CRT2;
   3531  1.1  riastrad 		}
   3532  1.1  riastrad 	}
   3533  1.1  riastrad 	if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
   3534  1.1  riastrad 	    (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
   3535  1.1  riastrad 		if (connected) {
   3536  1.1  riastrad 			DRM_DEBUG_KMS("DFP1 connected\n");
   3537  1.1  riastrad 			bios_4_scratch |= RADEON_DFP1_ATTACHED;
   3538  1.1  riastrad 			bios_5_scratch |= RADEON_DFP1_ON;
   3539  1.1  riastrad 			bios_5_scratch |= RADEON_ACC_REQ_DFP1;
   3540  1.1  riastrad 		} else {
   3541  1.1  riastrad 			DRM_DEBUG_KMS("DFP1 disconnected\n");
   3542  1.1  riastrad 			bios_4_scratch &= ~RADEON_DFP1_ATTACHED;
   3543  1.1  riastrad 			bios_5_scratch &= ~RADEON_DFP1_ON;
   3544  1.1  riastrad 			bios_5_scratch &= ~RADEON_ACC_REQ_DFP1;
   3545  1.1  riastrad 		}
   3546  1.1  riastrad 	}
   3547  1.1  riastrad 	if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
   3548  1.1  riastrad 	    (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
   3549  1.1  riastrad 		if (connected) {
   3550  1.1  riastrad 			DRM_DEBUG_KMS("DFP2 connected\n");
   3551  1.1  riastrad 			bios_4_scratch |= RADEON_DFP2_ATTACHED;
   3552  1.1  riastrad 			bios_5_scratch |= RADEON_DFP2_ON;
   3553  1.1  riastrad 			bios_5_scratch |= RADEON_ACC_REQ_DFP2;
   3554  1.1  riastrad 		} else {
   3555  1.1  riastrad 			DRM_DEBUG_KMS("DFP2 disconnected\n");
   3556  1.1  riastrad 			bios_4_scratch &= ~RADEON_DFP2_ATTACHED;
   3557  1.1  riastrad 			bios_5_scratch &= ~RADEON_DFP2_ON;
   3558  1.1  riastrad 			bios_5_scratch &= ~RADEON_ACC_REQ_DFP2;
   3559  1.1  riastrad 		}
   3560  1.1  riastrad 	}
   3561  1.1  riastrad 	WREG32(RADEON_BIOS_4_SCRATCH, bios_4_scratch);
   3562  1.1  riastrad 	WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
   3563  1.1  riastrad }
   3564  1.1  riastrad 
   3565  1.1  riastrad void
   3566  1.1  riastrad radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
   3567  1.1  riastrad {
   3568  1.1  riastrad 	struct drm_device *dev = encoder->dev;
   3569  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3570  1.1  riastrad 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
   3571  1.1  riastrad 	uint32_t bios_5_scratch = RREG32(RADEON_BIOS_5_SCRATCH);
   3572  1.1  riastrad 
   3573  1.1  riastrad 	if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
   3574  1.1  riastrad 		bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
   3575  1.1  riastrad 		bios_5_scratch |= (crtc << RADEON_TV1_CRTC_SHIFT);
   3576  1.1  riastrad 	}
   3577  1.1  riastrad 	if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
   3578  1.1  riastrad 		bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
   3579  1.1  riastrad 		bios_5_scratch |= (crtc << RADEON_CRT1_CRTC_SHIFT);
   3580  1.1  riastrad 	}
   3581  1.1  riastrad 	if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
   3582  1.1  riastrad 		bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
   3583  1.1  riastrad 		bios_5_scratch |= (crtc << RADEON_CRT2_CRTC_SHIFT);
   3584  1.1  riastrad 	}
   3585  1.1  riastrad 	if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
   3586  1.1  riastrad 		bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
   3587  1.1  riastrad 		bios_5_scratch |= (crtc << RADEON_LCD1_CRTC_SHIFT);
   3588  1.1  riastrad 	}
   3589  1.1  riastrad 	if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
   3590  1.1  riastrad 		bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
   3591  1.1  riastrad 		bios_5_scratch |= (crtc << RADEON_DFP1_CRTC_SHIFT);
   3592  1.1  riastrad 	}
   3593  1.1  riastrad 	if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
   3594  1.1  riastrad 		bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
   3595  1.1  riastrad 		bios_5_scratch |= (crtc << RADEON_DFP2_CRTC_SHIFT);
   3596  1.1  riastrad 	}
   3597  1.1  riastrad 	WREG32(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
   3598  1.1  riastrad }
   3599  1.1  riastrad 
   3600  1.1  riastrad void
   3601  1.1  riastrad radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
   3602  1.1  riastrad {
   3603  1.1  riastrad 	struct drm_device *dev = encoder->dev;
   3604  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   3605  1.1  riastrad 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
   3606  1.1  riastrad 	uint32_t bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
   3607  1.1  riastrad 
   3608  1.1  riastrad 	if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
   3609  1.1  riastrad 		if (on)
   3610  1.1  riastrad 			bios_6_scratch |= RADEON_TV_DPMS_ON;
   3611  1.1  riastrad 		else
   3612  1.1  riastrad 			bios_6_scratch &= ~RADEON_TV_DPMS_ON;
   3613  1.1  riastrad 	}
   3614  1.1  riastrad 	if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
   3615  1.1  riastrad 		if (on)
   3616  1.1  riastrad 			bios_6_scratch |= RADEON_CRT_DPMS_ON;
   3617  1.1  riastrad 		else
   3618  1.1  riastrad 			bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
   3619  1.1  riastrad 	}
   3620  1.1  riastrad 	if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
   3621  1.1  riastrad 		if (on)
   3622  1.1  riastrad 			bios_6_scratch |= RADEON_LCD_DPMS_ON;
   3623  1.1  riastrad 		else
   3624  1.1  riastrad 			bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
   3625  1.1  riastrad 	}
   3626  1.1  riastrad 	if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
   3627  1.1  riastrad 		if (on)
   3628  1.1  riastrad 			bios_6_scratch |= RADEON_DFP_DPMS_ON;
   3629  1.1  riastrad 		else
   3630  1.1  riastrad 			bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
   3631  1.1  riastrad 	}
   3632  1.1  riastrad 	WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
   3633  1.1  riastrad }
   3634