2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Authors: Dave Airlie
27 #include "radeon_drm.h"
31 #include "atom-bits.h"
33 /* from radeon_encoder.c */
35 radeon_get_encoder_id(struct drm_device
*dev
, uint32_t supported_device
,
37 extern void radeon_link_encoder_connector(struct drm_device
*dev
);
39 radeon_add_atom_encoder(struct drm_device
*dev
, uint32_t encoder_id
,
40 uint32_t supported_device
);
42 /* from radeon_connector.c */
44 radeon_add_atom_connector(struct drm_device
*dev
,
45 uint32_t connector_id
,
46 uint32_t supported_device
,
48 struct radeon_i2c_bus_rec
*i2c_bus
,
49 bool linkb
, uint32_t igp_lane_info
,
50 uint16_t connector_object_id
);
52 /* from radeon_legacy_encoder.c */
54 radeon_add_legacy_encoder(struct drm_device
*dev
, uint32_t encoder_id
,
55 uint32_t supported_device
);
57 union atom_supported_devices
{
58 struct _ATOM_SUPPORTED_DEVICES_INFO info
;
59 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2
;
60 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1
;
63 static inline struct radeon_i2c_bus_rec
radeon_lookup_gpio(struct drm_device
66 struct radeon_device
*rdev
= dev
->dev_private
;
67 struct atom_context
*ctx
= rdev
->mode_info
.atom_context
;
68 ATOM_GPIO_I2C_ASSIGMENT gpio
;
69 struct radeon_i2c_bus_rec i2c
;
70 int index
= GetIndexIntoMasterTable(DATA
, GPIO_I2C_Info
);
71 struct _ATOM_GPIO_I2C_INFO
*i2c_info
;
74 memset(&i2c
, 0, sizeof(struct radeon_i2c_bus_rec
));
77 atom_parse_data_header(ctx
, index
, NULL
, NULL
, NULL
, &data_offset
);
79 i2c_info
= (struct _ATOM_GPIO_I2C_INFO
*)(ctx
->bios
+ data_offset
);
81 gpio
= i2c_info
->asGPIO_Info
[id
];
83 i2c
.mask_clk_reg
= le16_to_cpu(gpio
.usClkMaskRegisterIndex
) * 4;
84 i2c
.mask_data_reg
= le16_to_cpu(gpio
.usDataMaskRegisterIndex
) * 4;
85 i2c
.put_clk_reg
= le16_to_cpu(gpio
.usClkEnRegisterIndex
) * 4;
86 i2c
.put_data_reg
= le16_to_cpu(gpio
.usDataEnRegisterIndex
) * 4;
87 i2c
.get_clk_reg
= le16_to_cpu(gpio
.usClkY_RegisterIndex
) * 4;
88 i2c
.get_data_reg
= le16_to_cpu(gpio
.usDataY_RegisterIndex
) * 4;
89 i2c
.a_clk_reg
= le16_to_cpu(gpio
.usClkA_RegisterIndex
) * 4;
90 i2c
.a_data_reg
= le16_to_cpu(gpio
.usDataA_RegisterIndex
) * 4;
91 i2c
.mask_clk_mask
= (1 << gpio
.ucClkMaskShift
);
92 i2c
.mask_data_mask
= (1 << gpio
.ucDataMaskShift
);
93 i2c
.put_clk_mask
= (1 << gpio
.ucClkEnShift
);
94 i2c
.put_data_mask
= (1 << gpio
.ucDataEnShift
);
95 i2c
.get_clk_mask
= (1 << gpio
.ucClkY_Shift
);
96 i2c
.get_data_mask
= (1 << gpio
.ucDataY_Shift
);
97 i2c
.a_clk_mask
= (1 << gpio
.ucClkA_Shift
);
98 i2c
.a_data_mask
= (1 << gpio
.ucDataA_Shift
);
104 static bool radeon_atom_apply_quirks(struct drm_device
*dev
,
105 uint32_t supported_device
,
107 struct radeon_i2c_bus_rec
*i2c_bus
,
111 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
112 if ((dev
->pdev
->device
== 0x791e) &&
113 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
114 (dev
->pdev
->subsystem_device
== 0x826d)) {
115 if ((*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) &&
116 (supported_device
== ATOM_DEVICE_DFP3_SUPPORT
))
117 *connector_type
= DRM_MODE_CONNECTOR_DVID
;
120 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
121 if ((dev
->pdev
->device
== 0x7941) &&
122 (dev
->pdev
->subsystem_vendor
== 0x147b) &&
123 (dev
->pdev
->subsystem_device
== 0x2412)) {
124 if (*connector_type
== DRM_MODE_CONNECTOR_DVII
)
128 /* Falcon NW laptop lists vga ddc line for LVDS */
129 if ((dev
->pdev
->device
== 0x5653) &&
130 (dev
->pdev
->subsystem_vendor
== 0x1462) &&
131 (dev
->pdev
->subsystem_device
== 0x0291)) {
132 if (*connector_type
== DRM_MODE_CONNECTOR_LVDS
) {
133 i2c_bus
->valid
= false;
139 if ((dev
->pdev
->device
== 0x71C5) &&
140 (dev
->pdev
->subsystem_vendor
== 0x106b) &&
141 (dev
->pdev
->subsystem_device
== 0x0080)) {
142 if ((supported_device
== ATOM_DEVICE_CRT1_SUPPORT
) ||
143 (supported_device
== ATOM_DEVICE_DFP2_SUPPORT
))
147 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
148 if ((dev
->pdev
->device
== 0x9598) &&
149 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
150 (dev
->pdev
->subsystem_device
== 0x01da)) {
151 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
152 *connector_type
= DRM_MODE_CONNECTOR_DVII
;
156 /* ASUS HD 3450 board lists the DVI port as HDMI */
157 if ((dev
->pdev
->device
== 0x95C5) &&
158 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
159 (dev
->pdev
->subsystem_device
== 0x01e2)) {
160 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
161 *connector_type
= DRM_MODE_CONNECTOR_DVII
;
165 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
166 * HDMI + VGA reporting as HDMI
168 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
169 if (supported_device
& (ATOM_DEVICE_CRT_SUPPORT
)) {
170 *connector_type
= DRM_MODE_CONNECTOR_VGA
;
178 const int supported_devices_connector_convert
[] = {
179 DRM_MODE_CONNECTOR_Unknown
,
180 DRM_MODE_CONNECTOR_VGA
,
181 DRM_MODE_CONNECTOR_DVII
,
182 DRM_MODE_CONNECTOR_DVID
,
183 DRM_MODE_CONNECTOR_DVIA
,
184 DRM_MODE_CONNECTOR_SVIDEO
,
185 DRM_MODE_CONNECTOR_Composite
,
186 DRM_MODE_CONNECTOR_LVDS
,
187 DRM_MODE_CONNECTOR_Unknown
,
188 DRM_MODE_CONNECTOR_Unknown
,
189 DRM_MODE_CONNECTOR_HDMIA
,
190 DRM_MODE_CONNECTOR_HDMIB
,
191 DRM_MODE_CONNECTOR_Unknown
,
192 DRM_MODE_CONNECTOR_Unknown
,
193 DRM_MODE_CONNECTOR_9PinDIN
,
194 DRM_MODE_CONNECTOR_DisplayPort
197 const uint16_t supported_devices_connector_object_id_convert
[] = {
198 CONNECTOR_OBJECT_ID_NONE
,
199 CONNECTOR_OBJECT_ID_VGA
,
200 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I
, /* not all boards support DL */
201 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D
, /* not all boards support DL */
202 CONNECTOR_OBJECT_ID_VGA
, /* technically DVI-A */
203 CONNECTOR_OBJECT_ID_COMPOSITE
,
204 CONNECTOR_OBJECT_ID_SVIDEO
,
205 CONNECTOR_OBJECT_ID_LVDS
,
206 CONNECTOR_OBJECT_ID_9PIN_DIN
,
207 CONNECTOR_OBJECT_ID_9PIN_DIN
,
208 CONNECTOR_OBJECT_ID_DISPLAYPORT
,
209 CONNECTOR_OBJECT_ID_HDMI_TYPE_A
,
210 CONNECTOR_OBJECT_ID_HDMI_TYPE_B
,
211 CONNECTOR_OBJECT_ID_SVIDEO
214 const int object_connector_convert
[] = {
215 DRM_MODE_CONNECTOR_Unknown
,
216 DRM_MODE_CONNECTOR_DVII
,
217 DRM_MODE_CONNECTOR_DVII
,
218 DRM_MODE_CONNECTOR_DVID
,
219 DRM_MODE_CONNECTOR_DVID
,
220 DRM_MODE_CONNECTOR_VGA
,
221 DRM_MODE_CONNECTOR_Composite
,
222 DRM_MODE_CONNECTOR_SVIDEO
,
223 DRM_MODE_CONNECTOR_Unknown
,
224 DRM_MODE_CONNECTOR_Unknown
,
225 DRM_MODE_CONNECTOR_9PinDIN
,
226 DRM_MODE_CONNECTOR_Unknown
,
227 DRM_MODE_CONNECTOR_HDMIA
,
228 DRM_MODE_CONNECTOR_HDMIB
,
229 DRM_MODE_CONNECTOR_LVDS
,
230 DRM_MODE_CONNECTOR_9PinDIN
,
231 DRM_MODE_CONNECTOR_Unknown
,
232 DRM_MODE_CONNECTOR_Unknown
,
233 DRM_MODE_CONNECTOR_Unknown
,
234 DRM_MODE_CONNECTOR_DisplayPort
237 bool radeon_get_atom_connector_info_from_object_table(struct drm_device
*dev
)
239 struct radeon_device
*rdev
= dev
->dev_private
;
240 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
241 struct atom_context
*ctx
= mode_info
->atom_context
;
242 int index
= GetIndexIntoMasterTable(DATA
, Object_Header
);
243 uint16_t size
, data_offset
;
244 uint8_t frev
, crev
, line_mux
= 0;
245 ATOM_CONNECTOR_OBJECT_TABLE
*con_obj
;
246 ATOM_DISPLAY_OBJECT_PATH_TABLE
*path_obj
;
247 ATOM_OBJECT_HEADER
*obj_header
;
248 int i
, j
, path_size
, device_support
;
250 uint16_t igp_lane_info
, conn_id
, connector_object_id
;
252 struct radeon_i2c_bus_rec ddc_bus
;
254 atom_parse_data_header(ctx
, index
, &size
, &frev
, &crev
, &data_offset
);
256 if (data_offset
== 0)
262 obj_header
= (ATOM_OBJECT_HEADER
*) (ctx
->bios
+ data_offset
);
263 path_obj
= (ATOM_DISPLAY_OBJECT_PATH_TABLE
*)
264 (ctx
->bios
+ data_offset
+
265 le16_to_cpu(obj_header
->usDisplayPathTableOffset
));
266 con_obj
= (ATOM_CONNECTOR_OBJECT_TABLE
*)
267 (ctx
->bios
+ data_offset
+
268 le16_to_cpu(obj_header
->usConnectorObjectTableOffset
));
269 device_support
= le16_to_cpu(obj_header
->usDeviceSupport
);
272 for (i
= 0; i
< path_obj
->ucNumOfDispPath
; i
++) {
273 uint8_t *addr
= (uint8_t *) path_obj
->asDispPath
;
274 ATOM_DISPLAY_OBJECT_PATH
*path
;
276 path
= (ATOM_DISPLAY_OBJECT_PATH
*) addr
;
277 path_size
+= le16_to_cpu(path
->usSize
);
280 if (device_support
& le16_to_cpu(path
->usDeviceTag
)) {
281 uint8_t con_obj_id
, con_obj_num
, con_obj_type
;
284 (le16_to_cpu(path
->usConnObjectId
) & OBJECT_ID_MASK
)
287 (le16_to_cpu(path
->usConnObjectId
) & ENUM_ID_MASK
)
290 (le16_to_cpu(path
->usConnObjectId
) &
291 OBJECT_TYPE_MASK
) >> OBJECT_TYPE_SHIFT
;
293 /* TODO CV support */
294 if (le16_to_cpu(path
->usDeviceTag
) ==
295 ATOM_DEVICE_CV_SUPPORT
)
299 if ((rdev
->flags
& RADEON_IS_IGP
) &&
301 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR
)) {
302 uint16_t igp_offset
= 0;
303 ATOM_INTEGRATED_SYSTEM_INFO_V2
*igp_obj
;
306 GetIndexIntoMasterTable(DATA
,
307 IntegratedSystemInfo
);
309 atom_parse_data_header(ctx
, index
, &size
, &frev
,
314 (ATOM_INTEGRATED_SYSTEM_INFO_V2
315 *) (ctx
->bios
+ igp_offset
);
318 uint32_t slot_config
, ct
;
320 if (con_obj_num
== 1)
329 ct
= (slot_config
>> 16) & 0xff;
331 object_connector_convert
333 connector_object_id
= ct
;
335 slot_config
& 0xffff;
343 object_connector_convert
[con_obj_id
];
344 connector_object_id
= con_obj_id
;
347 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
350 for (j
= 0; j
< ((le16_to_cpu(path
->usSize
) - 8) / 2);
352 uint8_t enc_obj_id
, enc_obj_num
, enc_obj_type
;
355 (le16_to_cpu(path
->usGraphicObjIds
[j
]) &
356 OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
358 (le16_to_cpu(path
->usGraphicObjIds
[j
]) &
359 ENUM_ID_MASK
) >> ENUM_ID_SHIFT
;
361 (le16_to_cpu(path
->usGraphicObjIds
[j
]) &
362 OBJECT_TYPE_MASK
) >> OBJECT_TYPE_SHIFT
;
364 /* FIXME: add support for router objects */
365 if (enc_obj_type
== GRAPH_OBJECT_TYPE_ENCODER
) {
366 if (enc_obj_num
== 2)
371 radeon_add_atom_encoder(dev
,
380 /* look up gpio for ddc */
381 if ((le16_to_cpu(path
->usDeviceTag
) &
382 (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
))
384 for (j
= 0; j
< con_obj
->ucNumberOfObjects
; j
++) {
385 if (le16_to_cpu(path
->usConnObjectId
) ==
386 le16_to_cpu(con_obj
->asObjects
[j
].
388 ATOM_COMMON_RECORD_HEADER
390 (ATOM_COMMON_RECORD_HEADER
392 (ctx
->bios
+ data_offset
+
393 le16_to_cpu(con_obj
->
396 ATOM_I2C_RECORD
*i2c_record
;
398 while (record
->ucRecordType
> 0
401 ATOM_MAX_OBJECT_RECORD_NUMBER
) {
404 case ATOM_I2C_RECORD_TYPE
:
415 (ATOM_COMMON_RECORD_HEADER
427 if ((le16_to_cpu(path
->usDeviceTag
) ==
428 ATOM_DEVICE_TV1_SUPPORT
)
429 || (le16_to_cpu(path
->usDeviceTag
) ==
430 ATOM_DEVICE_TV2_SUPPORT
)
431 || (le16_to_cpu(path
->usDeviceTag
) ==
432 ATOM_DEVICE_CV_SUPPORT
))
433 ddc_bus
.valid
= false;
435 ddc_bus
= radeon_lookup_gpio(dev
, line_mux
);
437 conn_id
= le16_to_cpu(path
->usConnObjectId
);
439 if (!radeon_atom_apply_quirks
440 (dev
, le16_to_cpu(path
->usDeviceTag
), &connector_type
,
444 radeon_add_atom_connector(dev
,
448 connector_type
, &ddc_bus
,
449 linkb
, igp_lane_info
,
450 connector_object_id
);
455 radeon_link_encoder_connector(dev
);
460 static uint16_t atombios_get_connector_object_id(struct drm_device
*dev
,
464 struct radeon_device
*rdev
= dev
->dev_private
;
466 if (rdev
->flags
& RADEON_IS_IGP
) {
467 return supported_devices_connector_object_id_convert
469 } else if (((connector_type
== DRM_MODE_CONNECTOR_DVII
) ||
470 (connector_type
== DRM_MODE_CONNECTOR_DVID
)) &&
471 (devices
& ATOM_DEVICE_DFP2_SUPPORT
)) {
472 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
473 struct atom_context
*ctx
= mode_info
->atom_context
;
474 int index
= GetIndexIntoMasterTable(DATA
, XTMDS_Info
);
475 uint16_t size
, data_offset
;
477 ATOM_XTMDS_INFO
*xtmds
;
479 atom_parse_data_header(ctx
, index
, &size
, &frev
, &crev
, &data_offset
);
480 xtmds
= (ATOM_XTMDS_INFO
*)(ctx
->bios
+ data_offset
);
482 if (xtmds
->ucSupportedLink
& ATOM_XTMDS_SUPPORTED_DUALLINK
) {
483 if (connector_type
== DRM_MODE_CONNECTOR_DVII
)
484 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I
;
486 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D
;
488 if (connector_type
== DRM_MODE_CONNECTOR_DVII
)
489 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I
;
491 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D
;
494 return supported_devices_connector_object_id_convert
499 struct bios_connector
{
504 struct radeon_i2c_bus_rec ddc_bus
;
507 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
511 struct radeon_device
*rdev
= dev
->dev_private
;
512 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
513 struct atom_context
*ctx
= mode_info
->atom_context
;
514 int index
= GetIndexIntoMasterTable(DATA
, SupportedDevicesInfo
);
515 uint16_t size
, data_offset
;
517 uint16_t device_support
;
519 union atom_supported_devices
*supported_devices
;
521 struct bios_connector bios_connectors
[ATOM_MAX_SUPPORTED_DEVICE
];
523 atom_parse_data_header(ctx
, index
, &size
, &frev
, &crev
, &data_offset
);
526 (union atom_supported_devices
*)(ctx
->bios
+ data_offset
);
528 device_support
= le16_to_cpu(supported_devices
->info
.usDeviceSupport
);
530 for (i
= 0; i
< ATOM_MAX_SUPPORTED_DEVICE
; i
++) {
531 ATOM_CONNECTOR_INFO_I2C ci
=
532 supported_devices
->info
.asConnInfo
[i
];
534 bios_connectors
[i
].valid
= false;
536 if (!(device_support
& (1 << i
))) {
540 if (i
== ATOM_DEVICE_CV_INDEX
) {
541 DRM_DEBUG("Skipping Component Video\n");
545 bios_connectors
[i
].connector_type
=
546 supported_devices_connector_convert
[ci
.sucConnectorInfo
.
550 if (bios_connectors
[i
].connector_type
==
551 DRM_MODE_CONNECTOR_Unknown
)
554 dac
= ci
.sucConnectorInfo
.sbfAccess
.bfAssociatedDAC
;
556 if ((rdev
->family
== CHIP_RS690
) ||
557 (rdev
->family
== CHIP_RS740
)) {
558 if ((i
== ATOM_DEVICE_DFP2_INDEX
)
559 && (ci
.sucI2cId
.sbfAccess
.bfI2C_LineMux
== 2))
560 bios_connectors
[i
].line_mux
=
561 ci
.sucI2cId
.sbfAccess
.bfI2C_LineMux
+ 1;
562 else if ((i
== ATOM_DEVICE_DFP3_INDEX
)
563 && (ci
.sucI2cId
.sbfAccess
.bfI2C_LineMux
== 1))
564 bios_connectors
[i
].line_mux
=
565 ci
.sucI2cId
.sbfAccess
.bfI2C_LineMux
+ 1;
567 bios_connectors
[i
].line_mux
=
568 ci
.sucI2cId
.sbfAccess
.bfI2C_LineMux
;
570 bios_connectors
[i
].line_mux
=
571 ci
.sucI2cId
.sbfAccess
.bfI2C_LineMux
;
573 /* give tv unique connector ids */
574 if (i
== ATOM_DEVICE_TV1_INDEX
) {
575 bios_connectors
[i
].ddc_bus
.valid
= false;
576 bios_connectors
[i
].line_mux
= 50;
577 } else if (i
== ATOM_DEVICE_TV2_INDEX
) {
578 bios_connectors
[i
].ddc_bus
.valid
= false;
579 bios_connectors
[i
].line_mux
= 51;
580 } else if (i
== ATOM_DEVICE_CV_INDEX
) {
581 bios_connectors
[i
].ddc_bus
.valid
= false;
582 bios_connectors
[i
].line_mux
= 52;
584 bios_connectors
[i
].ddc_bus
=
585 radeon_lookup_gpio(dev
,
586 bios_connectors
[i
].line_mux
);
588 /* Always set the connector type to VGA for CRT1/CRT2. if they are
589 * shared with a DVI port, we'll pick up the DVI connector when we
590 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
592 if (i
== ATOM_DEVICE_CRT1_INDEX
|| i
== ATOM_DEVICE_CRT2_INDEX
)
593 bios_connectors
[i
].connector_type
=
594 DRM_MODE_CONNECTOR_VGA
;
596 if (!radeon_atom_apply_quirks
597 (dev
, (1 << i
), &bios_connectors
[i
].connector_type
,
598 &bios_connectors
[i
].ddc_bus
, &bios_connectors
[i
].line_mux
))
601 bios_connectors
[i
].valid
= true;
602 bios_connectors
[i
].devices
= (1 << i
);
604 if (ASIC_IS_AVIVO(rdev
) || radeon_r4xx_atom
)
605 radeon_add_atom_encoder(dev
,
606 radeon_get_encoder_id(dev
,
611 radeon_add_legacy_encoder(dev
,
612 radeon_get_encoder_id(dev
,
619 /* combine shared connectors */
620 for (i
= 0; i
< ATOM_MAX_SUPPORTED_DEVICE
; i
++) {
621 if (bios_connectors
[i
].valid
) {
622 for (j
= 0; j
< ATOM_MAX_SUPPORTED_DEVICE
; j
++) {
623 if (bios_connectors
[j
].valid
&& (i
!= j
)) {
624 if (bios_connectors
[i
].line_mux
==
625 bios_connectors
[j
].line_mux
) {
626 if (((bios_connectors
[i
].
628 (ATOM_DEVICE_DFP_SUPPORT
))
629 && (bios_connectors
[j
].
631 (ATOM_DEVICE_CRT_SUPPORT
)))
633 ((bios_connectors
[j
].
635 (ATOM_DEVICE_DFP_SUPPORT
))
636 && (bios_connectors
[i
].
638 (ATOM_DEVICE_CRT_SUPPORT
)))) {
645 DRM_MODE_CONNECTOR_DVII
;
655 /* add the connectors */
656 for (i
= 0; i
< ATOM_MAX_SUPPORTED_DEVICE
; i
++) {
657 if (bios_connectors
[i
].valid
) {
658 uint16_t connector_object_id
=
659 atombios_get_connector_object_id(dev
,
660 bios_connectors
[i
].connector_type
,
661 bios_connectors
[i
].devices
);
662 radeon_add_atom_connector(dev
,
663 bios_connectors
[i
].line_mux
,
664 bios_connectors
[i
].devices
,
667 &bios_connectors
[i
].ddc_bus
,
669 connector_object_id
);
673 radeon_link_encoder_connector(dev
);
678 union firmware_info
{
679 ATOM_FIRMWARE_INFO info
;
680 ATOM_FIRMWARE_INFO_V1_2 info_12
;
681 ATOM_FIRMWARE_INFO_V1_3 info_13
;
682 ATOM_FIRMWARE_INFO_V1_4 info_14
;
685 bool radeon_atom_get_clock_info(struct drm_device
*dev
)
687 struct radeon_device
*rdev
= dev
->dev_private
;
688 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
689 int index
= GetIndexIntoMasterTable(DATA
, FirmwareInfo
);
690 union firmware_info
*firmware_info
;
692 struct radeon_pll
*p1pll
= &rdev
->clock
.p1pll
;
693 struct radeon_pll
*p2pll
= &rdev
->clock
.p2pll
;
694 struct radeon_pll
*spll
= &rdev
->clock
.spll
;
695 struct radeon_pll
*mpll
= &rdev
->clock
.mpll
;
696 uint16_t data_offset
;
698 atom_parse_data_header(mode_info
->atom_context
, index
, NULL
, &frev
,
699 &crev
, &data_offset
);
702 (union firmware_info
*)(mode_info
->atom_context
->bios
+
707 p1pll
->reference_freq
=
708 le16_to_cpu(firmware_info
->info
.usReferenceClock
);
709 p1pll
->reference_div
= 0;
713 le16_to_cpu(firmware_info
->info
.usMinPixelClockPLL_Output
);
716 le32_to_cpu(firmware_info
->info_12
.ulMinPixelClockPLL_Output
);
718 le32_to_cpu(firmware_info
->info
.ulMaxPixelClockPLL_Output
);
720 if (p1pll
->pll_out_min
== 0) {
721 if (ASIC_IS_AVIVO(rdev
))
722 p1pll
->pll_out_min
= 64800;
724 p1pll
->pll_out_min
= 20000;
725 } else if (p1pll
->pll_out_min
> 64800) {
726 /* Limiting the pll output range is a good thing generally as
727 * it limits the number of possible pll combinations for a given
728 * frequency presumably to the ones that work best on each card.
729 * However, certain duallink DVI monitors seem to like
730 * pll combinations that would be limited by this at least on
731 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
734 p1pll
->pll_out_min
= 64800;
738 le16_to_cpu(firmware_info
->info
.usMinPixelClockPLL_Input
);
740 le16_to_cpu(firmware_info
->info
.usMaxPixelClockPLL_Input
);
745 spll
->reference_freq
=
746 le16_to_cpu(firmware_info
->info
.usReferenceClock
);
747 spll
->reference_div
= 0;
750 le16_to_cpu(firmware_info
->info
.usMinEngineClockPLL_Output
);
752 le32_to_cpu(firmware_info
->info
.ulMaxEngineClockPLL_Output
);
755 if (spll
->pll_out_min
== 0) {
756 if (ASIC_IS_AVIVO(rdev
))
757 spll
->pll_out_min
= 64800;
759 spll
->pll_out_min
= 20000;
763 le16_to_cpu(firmware_info
->info
.usMinEngineClockPLL_Input
);
765 le16_to_cpu(firmware_info
->info
.usMaxEngineClockPLL_Input
);
768 mpll
->reference_freq
=
769 le16_to_cpu(firmware_info
->info
.usReferenceClock
);
770 mpll
->reference_div
= 0;
773 le16_to_cpu(firmware_info
->info
.usMinMemoryClockPLL_Output
);
775 le32_to_cpu(firmware_info
->info
.ulMaxMemoryClockPLL_Output
);
778 if (mpll
->pll_out_min
== 0) {
779 if (ASIC_IS_AVIVO(rdev
))
780 mpll
->pll_out_min
= 64800;
782 mpll
->pll_out_min
= 20000;
786 le16_to_cpu(firmware_info
->info
.usMinMemoryClockPLL_Input
);
788 le16_to_cpu(firmware_info
->info
.usMaxMemoryClockPLL_Input
);
790 rdev
->clock
.default_sclk
=
791 le32_to_cpu(firmware_info
->info
.ulDefaultEngineClock
);
792 rdev
->clock
.default_mclk
=
793 le32_to_cpu(firmware_info
->info
.ulDefaultMemoryClock
);
800 bool radeon_atombios_get_tmds_info(struct radeon_encoder
*encoder
,
801 struct radeon_encoder_int_tmds
*tmds
)
803 struct drm_device
*dev
= encoder
->base
.dev
;
804 struct radeon_device
*rdev
= dev
->dev_private
;
805 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
806 int index
= GetIndexIntoMasterTable(DATA
, TMDS_Info
);
807 uint16_t data_offset
;
808 struct _ATOM_TMDS_INFO
*tmds_info
;
813 atom_parse_data_header(mode_info
->atom_context
, index
, NULL
, &frev
,
814 &crev
, &data_offset
);
817 (struct _ATOM_TMDS_INFO
*)(mode_info
->atom_context
->bios
+
821 maxfreq
= le16_to_cpu(tmds_info
->usMaxFrequency
);
822 for (i
= 0; i
< 4; i
++) {
823 tmds
->tmds_pll
[i
].freq
=
824 le16_to_cpu(tmds_info
->asMiscInfo
[i
].usFrequency
);
825 tmds
->tmds_pll
[i
].value
=
826 tmds_info
->asMiscInfo
[i
].ucPLL_ChargePump
& 0x3f;
827 tmds
->tmds_pll
[i
].value
|=
828 (tmds_info
->asMiscInfo
[i
].
829 ucPLL_VCO_Gain
& 0x3f) << 6;
830 tmds
->tmds_pll
[i
].value
|=
831 (tmds_info
->asMiscInfo
[i
].
832 ucPLL_DutyCycle
& 0xf) << 12;
833 tmds
->tmds_pll
[i
].value
|=
834 (tmds_info
->asMiscInfo
[i
].
835 ucPLL_VoltageSwing
& 0xf) << 16;
837 DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
838 tmds
->tmds_pll
[i
].freq
,
839 tmds
->tmds_pll
[i
].value
);
841 if (maxfreq
== tmds
->tmds_pll
[i
].freq
) {
842 tmds
->tmds_pll
[i
].freq
= 0xffffffff;
851 static struct radeon_atom_ss
*radeon_atombios_get_ss_info(struct
856 struct drm_device
*dev
= encoder
->base
.dev
;
857 struct radeon_device
*rdev
= dev
->dev_private
;
858 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
859 int index
= GetIndexIntoMasterTable(DATA
, PPLL_SS_Info
);
860 uint16_t data_offset
;
861 struct _ATOM_SPREAD_SPECTRUM_INFO
*ss_info
;
863 struct radeon_atom_ss
*ss
= NULL
;
865 if (id
> ATOM_MAX_SS_ENTRY
)
868 atom_parse_data_header(mode_info
->atom_context
, index
, NULL
, &frev
,
869 &crev
, &data_offset
);
872 (struct _ATOM_SPREAD_SPECTRUM_INFO
*)(mode_info
->atom_context
->bios
+ data_offset
);
876 kzalloc(sizeof(struct radeon_atom_ss
), GFP_KERNEL
);
881 ss
->percentage
= le16_to_cpu(ss_info
->asSS_Info
[id
].usSpreadSpectrumPercentage
);
882 ss
->type
= ss_info
->asSS_Info
[id
].ucSpreadSpectrumType
;
883 ss
->step
= ss_info
->asSS_Info
[id
].ucSS_Step
;
884 ss
->delay
= ss_info
->asSS_Info
[id
].ucSS_Delay
;
885 ss
->range
= ss_info
->asSS_Info
[id
].ucSS_Range
;
886 ss
->refdiv
= ss_info
->asSS_Info
[id
].ucRecommendedRef_Div
;
892 struct _ATOM_LVDS_INFO info
;
893 struct _ATOM_LVDS_INFO_V12 info_12
;
896 struct radeon_encoder_atom_dig
*radeon_atombios_get_lvds_info(struct
900 struct drm_device
*dev
= encoder
->base
.dev
;
901 struct radeon_device
*rdev
= dev
->dev_private
;
902 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
903 int index
= GetIndexIntoMasterTable(DATA
, LVDS_Info
);
904 uint16_t data_offset
;
905 union lvds_info
*lvds_info
;
907 struct radeon_encoder_atom_dig
*lvds
= NULL
;
909 atom_parse_data_header(mode_info
->atom_context
, index
, NULL
, &frev
,
910 &crev
, &data_offset
);
913 (union lvds_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
917 kzalloc(sizeof(struct radeon_encoder_atom_dig
), GFP_KERNEL
);
922 lvds
->native_mode
.clock
=
923 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usPixClk
) * 10;
924 lvds
->native_mode
.hdisplay
=
925 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHActive
);
926 lvds
->native_mode
.vdisplay
=
927 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVActive
);
928 lvds
->native_mode
.htotal
= lvds
->native_mode
.hdisplay
+
929 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHBlanking_Time
);
930 lvds
->native_mode
.hsync_start
= lvds
->native_mode
.hdisplay
+
931 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHSyncOffset
);
932 lvds
->native_mode
.hsync_end
= lvds
->native_mode
.hsync_start
+
933 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHSyncWidth
);
934 lvds
->native_mode
.vtotal
= lvds
->native_mode
.vdisplay
+
935 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVBlanking_Time
);
936 lvds
->native_mode
.vsync_start
= lvds
->native_mode
.vdisplay
+
937 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVSyncWidth
);
938 lvds
->native_mode
.vsync_end
= lvds
->native_mode
.vsync_start
+
939 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVSyncWidth
);
940 lvds
->panel_pwr_delay
=
941 le16_to_cpu(lvds_info
->info
.usOffDelayInMs
);
942 lvds
->lvds_misc
= lvds_info
->info
.ucLVDS_Misc
;
943 /* set crtc values */
944 drm_mode_set_crtcinfo(&lvds
->native_mode
, CRTC_INTERLACE_HALVE_V
);
946 lvds
->ss
= radeon_atombios_get_ss_info(encoder
, lvds_info
->info
.ucSS_Id
);
948 encoder
->native_mode
= lvds
->native_mode
;
953 struct radeon_encoder_primary_dac
*
954 radeon_atombios_get_primary_dac_info(struct radeon_encoder
*encoder
)
956 struct drm_device
*dev
= encoder
->base
.dev
;
957 struct radeon_device
*rdev
= dev
->dev_private
;
958 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
959 int index
= GetIndexIntoMasterTable(DATA
, CompassionateData
);
960 uint16_t data_offset
;
961 struct _COMPASSIONATE_DATA
*dac_info
;
964 struct radeon_encoder_primary_dac
*p_dac
= NULL
;
966 atom_parse_data_header(mode_info
->atom_context
, index
, NULL
, &frev
, &crev
, &data_offset
);
968 dac_info
= (struct _COMPASSIONATE_DATA
*)(mode_info
->atom_context
->bios
+ data_offset
);
971 p_dac
= kzalloc(sizeof(struct radeon_encoder_primary_dac
), GFP_KERNEL
);
976 bg
= dac_info
->ucDAC1_BG_Adjustment
;
977 dac
= dac_info
->ucDAC1_DAC_Adjustment
;
978 p_dac
->ps2_pdac_adj
= (bg
<< 8) | (dac
);
984 bool radeon_atom_get_tv_timings(struct radeon_device
*rdev
, int index
,
985 struct drm_display_mode
*mode
)
987 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
988 ATOM_ANALOG_TV_INFO
*tv_info
;
989 ATOM_ANALOG_TV_INFO_V1_2
*tv_info_v1_2
;
990 ATOM_DTD_FORMAT
*dtd_timings
;
991 int data_index
= GetIndexIntoMasterTable(DATA
, AnalogTV_Info
);
993 u16 data_offset
, misc
;
995 atom_parse_data_header(mode_info
->atom_context
, data_index
, NULL
, &frev
, &crev
, &data_offset
);
999 tv_info
= (ATOM_ANALOG_TV_INFO
*)(mode_info
->atom_context
->bios
+ data_offset
);
1000 if (index
> MAX_SUPPORTED_TV_TIMING
)
1003 mode
->crtc_htotal
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_Total
);
1004 mode
->crtc_hdisplay
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_Disp
);
1005 mode
->crtc_hsync_start
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_SyncStart
);
1006 mode
->crtc_hsync_end
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_SyncStart
) +
1007 le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_SyncWidth
);
1009 mode
->crtc_vtotal
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_Total
);
1010 mode
->crtc_vdisplay
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_Disp
);
1011 mode
->crtc_vsync_start
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_SyncStart
);
1012 mode
->crtc_vsync_end
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_SyncStart
) +
1013 le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_SyncWidth
);
1016 misc
= le16_to_cpu(tv_info
->aModeTimings
[index
].susModeMiscInfo
.usAccess
);
1017 if (misc
& ATOM_VSYNC_POLARITY
)
1018 mode
->flags
|= DRM_MODE_FLAG_NVSYNC
;
1019 if (misc
& ATOM_HSYNC_POLARITY
)
1020 mode
->flags
|= DRM_MODE_FLAG_NHSYNC
;
1021 if (misc
& ATOM_COMPOSITESYNC
)
1022 mode
->flags
|= DRM_MODE_FLAG_CSYNC
;
1023 if (misc
& ATOM_INTERLACE
)
1024 mode
->flags
|= DRM_MODE_FLAG_INTERLACE
;
1025 if (misc
& ATOM_DOUBLE_CLOCK_MODE
)
1026 mode
->flags
|= DRM_MODE_FLAG_DBLSCAN
;
1028 mode
->clock
= le16_to_cpu(tv_info
->aModeTimings
[index
].usPixelClock
) * 10;
1031 /* PAL timings appear to have wrong values for totals */
1032 mode
->crtc_htotal
-= 1;
1033 mode
->crtc_vtotal
-= 1;
1037 tv_info_v1_2
= (ATOM_ANALOG_TV_INFO_V1_2
*)(mode_info
->atom_context
->bios
+ data_offset
);
1038 if (index
> MAX_SUPPORTED_TV_TIMING_V1_2
)
1041 dtd_timings
= &tv_info_v1_2
->aModeTimings
[index
];
1042 mode
->crtc_htotal
= le16_to_cpu(dtd_timings
->usHActive
) +
1043 le16_to_cpu(dtd_timings
->usHBlanking_Time
);
1044 mode
->crtc_hdisplay
= le16_to_cpu(dtd_timings
->usHActive
);
1045 mode
->crtc_hsync_start
= le16_to_cpu(dtd_timings
->usHActive
) +
1046 le16_to_cpu(dtd_timings
->usHSyncOffset
);
1047 mode
->crtc_hsync_end
= mode
->crtc_hsync_start
+
1048 le16_to_cpu(dtd_timings
->usHSyncWidth
);
1050 mode
->crtc_vtotal
= le16_to_cpu(dtd_timings
->usVActive
) +
1051 le16_to_cpu(dtd_timings
->usVBlanking_Time
);
1052 mode
->crtc_vdisplay
= le16_to_cpu(dtd_timings
->usVActive
);
1053 mode
->crtc_vsync_start
= le16_to_cpu(dtd_timings
->usVActive
) +
1054 le16_to_cpu(dtd_timings
->usVSyncOffset
);
1055 mode
->crtc_vsync_end
= mode
->crtc_vsync_start
+
1056 le16_to_cpu(dtd_timings
->usVSyncWidth
);
1059 misc
= le16_to_cpu(dtd_timings
->susModeMiscInfo
.usAccess
);
1060 if (misc
& ATOM_VSYNC_POLARITY
)
1061 mode
->flags
|= DRM_MODE_FLAG_NVSYNC
;
1062 if (misc
& ATOM_HSYNC_POLARITY
)
1063 mode
->flags
|= DRM_MODE_FLAG_NHSYNC
;
1064 if (misc
& ATOM_COMPOSITESYNC
)
1065 mode
->flags
|= DRM_MODE_FLAG_CSYNC
;
1066 if (misc
& ATOM_INTERLACE
)
1067 mode
->flags
|= DRM_MODE_FLAG_INTERLACE
;
1068 if (misc
& ATOM_DOUBLE_CLOCK_MODE
)
1069 mode
->flags
|= DRM_MODE_FLAG_DBLSCAN
;
1071 mode
->clock
= le16_to_cpu(dtd_timings
->usPixClk
) * 10;
1077 struct radeon_encoder_tv_dac
*
1078 radeon_atombios_get_tv_dac_info(struct radeon_encoder
*encoder
)
1080 struct drm_device
*dev
= encoder
->base
.dev
;
1081 struct radeon_device
*rdev
= dev
->dev_private
;
1082 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1083 int index
= GetIndexIntoMasterTable(DATA
, CompassionateData
);
1084 uint16_t data_offset
;
1085 struct _COMPASSIONATE_DATA
*dac_info
;
1088 struct radeon_encoder_tv_dac
*tv_dac
= NULL
;
1090 atom_parse_data_header(mode_info
->atom_context
, index
, NULL
, &frev
, &crev
, &data_offset
);
1092 dac_info
= (struct _COMPASSIONATE_DATA
*)(mode_info
->atom_context
->bios
+ data_offset
);
1095 tv_dac
= kzalloc(sizeof(struct radeon_encoder_tv_dac
), GFP_KERNEL
);
1100 bg
= dac_info
->ucDAC2_CRT2_BG_Adjustment
;
1101 dac
= dac_info
->ucDAC2_CRT2_DAC_Adjustment
;
1102 tv_dac
->ps2_tvdac_adj
= (bg
<< 16) | (dac
<< 20);
1104 bg
= dac_info
->ucDAC2_PAL_BG_Adjustment
;
1105 dac
= dac_info
->ucDAC2_PAL_DAC_Adjustment
;
1106 tv_dac
->pal_tvdac_adj
= (bg
<< 16) | (dac
<< 20);
1108 bg
= dac_info
->ucDAC2_NTSC_BG_Adjustment
;
1109 dac
= dac_info
->ucDAC2_NTSC_DAC_Adjustment
;
1110 tv_dac
->ntsc_tvdac_adj
= (bg
<< 16) | (dac
<< 20);
1116 void radeon_atom_set_clock_gating(struct radeon_device
*rdev
, int enable
)
1118 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args
;
1119 int index
= GetIndexIntoMasterTable(COMMAND
, DynamicClockGating
);
1121 args
.ucEnable
= enable
;
1123 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1126 void radeon_atom_static_pwrmgt_setup(struct radeon_device
*rdev
, int enable
)
1128 ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args
;
1129 int index
= GetIndexIntoMasterTable(COMMAND
, EnableASIC_StaticPwrMgt
);
1131 args
.ucEnable
= enable
;
1133 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1136 uint32_t radeon_atom_get_engine_clock(struct radeon_device
*rdev
)
1138 GET_ENGINE_CLOCK_PS_ALLOCATION args
;
1139 int index
= GetIndexIntoMasterTable(COMMAND
, GetEngineClock
);
1141 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1142 return args
.ulReturnEngineClock
;
1145 uint32_t radeon_atom_get_memory_clock(struct radeon_device
*rdev
)
1147 GET_MEMORY_CLOCK_PS_ALLOCATION args
;
1148 int index
= GetIndexIntoMasterTable(COMMAND
, GetMemoryClock
);
1150 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1151 return args
.ulReturnMemoryClock
;
1154 void radeon_atom_set_engine_clock(struct radeon_device
*rdev
,
1157 SET_ENGINE_CLOCK_PS_ALLOCATION args
;
1158 int index
= GetIndexIntoMasterTable(COMMAND
, SetEngineClock
);
1160 args
.ulTargetEngineClock
= eng_clock
; /* 10 khz */
1162 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1165 void radeon_atom_set_memory_clock(struct radeon_device
*rdev
,
1168 SET_MEMORY_CLOCK_PS_ALLOCATION args
;
1169 int index
= GetIndexIntoMasterTable(COMMAND
, SetMemoryClock
);
1171 if (rdev
->flags
& RADEON_IS_IGP
)
1174 args
.ulTargetMemoryClock
= mem_clock
; /* 10 khz */
1176 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1179 void radeon_atom_initialize_bios_scratch_regs(struct drm_device
*dev
)
1181 struct radeon_device
*rdev
= dev
->dev_private
;
1182 uint32_t bios_2_scratch
, bios_6_scratch
;
1184 if (rdev
->family
>= CHIP_R600
) {
1185 bios_2_scratch
= RREG32(R600_BIOS_2_SCRATCH
);
1186 bios_6_scratch
= RREG32(R600_BIOS_6_SCRATCH
);
1188 bios_2_scratch
= RREG32(RADEON_BIOS_2_SCRATCH
);
1189 bios_6_scratch
= RREG32(RADEON_BIOS_6_SCRATCH
);
1192 /* let the bios control the backlight */
1193 bios_2_scratch
&= ~ATOM_S2_VRI_BRIGHT_ENABLE
;
1195 /* tell the bios not to handle mode switching */
1196 bios_6_scratch
|= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH
| ATOM_S6_ACC_MODE
);
1198 if (rdev
->family
>= CHIP_R600
) {
1199 WREG32(R600_BIOS_2_SCRATCH
, bios_2_scratch
);
1200 WREG32(R600_BIOS_6_SCRATCH
, bios_6_scratch
);
1202 WREG32(RADEON_BIOS_2_SCRATCH
, bios_2_scratch
);
1203 WREG32(RADEON_BIOS_6_SCRATCH
, bios_6_scratch
);
1208 void radeon_save_bios_scratch_regs(struct radeon_device
*rdev
)
1210 uint32_t scratch_reg
;
1213 if (rdev
->family
>= CHIP_R600
)
1214 scratch_reg
= R600_BIOS_0_SCRATCH
;
1216 scratch_reg
= RADEON_BIOS_0_SCRATCH
;
1218 for (i
= 0; i
< RADEON_BIOS_NUM_SCRATCH
; i
++)
1219 rdev
->bios_scratch
[i
] = RREG32(scratch_reg
+ (i
* 4));
1222 void radeon_restore_bios_scratch_regs(struct radeon_device
*rdev
)
1224 uint32_t scratch_reg
;
1227 if (rdev
->family
>= CHIP_R600
)
1228 scratch_reg
= R600_BIOS_0_SCRATCH
;
1230 scratch_reg
= RADEON_BIOS_0_SCRATCH
;
1232 for (i
= 0; i
< RADEON_BIOS_NUM_SCRATCH
; i
++)
1233 WREG32(scratch_reg
+ (i
* 4), rdev
->bios_scratch
[i
]);
1236 void radeon_atom_output_lock(struct drm_encoder
*encoder
, bool lock
)
1238 struct drm_device
*dev
= encoder
->dev
;
1239 struct radeon_device
*rdev
= dev
->dev_private
;
1240 uint32_t bios_6_scratch
;
1242 if (rdev
->family
>= CHIP_R600
)
1243 bios_6_scratch
= RREG32(R600_BIOS_6_SCRATCH
);
1245 bios_6_scratch
= RREG32(RADEON_BIOS_6_SCRATCH
);
1248 bios_6_scratch
|= ATOM_S6_CRITICAL_STATE
;
1250 bios_6_scratch
&= ~ATOM_S6_CRITICAL_STATE
;
1252 if (rdev
->family
>= CHIP_R600
)
1253 WREG32(R600_BIOS_6_SCRATCH
, bios_6_scratch
);
1255 WREG32(RADEON_BIOS_6_SCRATCH
, bios_6_scratch
);
1258 /* at some point we may want to break this out into individual functions */
1260 radeon_atombios_connected_scratch_regs(struct drm_connector
*connector
,
1261 struct drm_encoder
*encoder
,
1264 struct drm_device
*dev
= connector
->dev
;
1265 struct radeon_device
*rdev
= dev
->dev_private
;
1266 struct radeon_connector
*radeon_connector
=
1267 to_radeon_connector(connector
);
1268 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1269 uint32_t bios_0_scratch
, bios_3_scratch
, bios_6_scratch
;
1271 if (rdev
->family
>= CHIP_R600
) {
1272 bios_0_scratch
= RREG32(R600_BIOS_0_SCRATCH
);
1273 bios_3_scratch
= RREG32(R600_BIOS_3_SCRATCH
);
1274 bios_6_scratch
= RREG32(R600_BIOS_6_SCRATCH
);
1276 bios_0_scratch
= RREG32(RADEON_BIOS_0_SCRATCH
);
1277 bios_3_scratch
= RREG32(RADEON_BIOS_3_SCRATCH
);
1278 bios_6_scratch
= RREG32(RADEON_BIOS_6_SCRATCH
);
1281 if ((radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) &&
1282 (radeon_connector
->devices
& ATOM_DEVICE_TV1_SUPPORT
)) {
1284 DRM_DEBUG("TV1 connected\n");
1285 bios_3_scratch
|= ATOM_S3_TV1_ACTIVE
;
1286 bios_6_scratch
|= ATOM_S6_ACC_REQ_TV1
;
1288 DRM_DEBUG("TV1 disconnected\n");
1289 bios_0_scratch
&= ~ATOM_S0_TV1_MASK
;
1290 bios_3_scratch
&= ~ATOM_S3_TV1_ACTIVE
;
1291 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_TV1
;
1294 if ((radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) &&
1295 (radeon_connector
->devices
& ATOM_DEVICE_CV_SUPPORT
)) {
1297 DRM_DEBUG("CV connected\n");
1298 bios_3_scratch
|= ATOM_S3_CV_ACTIVE
;
1299 bios_6_scratch
|= ATOM_S6_ACC_REQ_CV
;
1301 DRM_DEBUG("CV disconnected\n");
1302 bios_0_scratch
&= ~ATOM_S0_CV_MASK
;
1303 bios_3_scratch
&= ~ATOM_S3_CV_ACTIVE
;
1304 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_CV
;
1307 if ((radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) &&
1308 (radeon_connector
->devices
& ATOM_DEVICE_LCD1_SUPPORT
)) {
1310 DRM_DEBUG("LCD1 connected\n");
1311 bios_0_scratch
|= ATOM_S0_LCD1
;
1312 bios_3_scratch
|= ATOM_S3_LCD1_ACTIVE
;
1313 bios_6_scratch
|= ATOM_S6_ACC_REQ_LCD1
;
1315 DRM_DEBUG("LCD1 disconnected\n");
1316 bios_0_scratch
&= ~ATOM_S0_LCD1
;
1317 bios_3_scratch
&= ~ATOM_S3_LCD1_ACTIVE
;
1318 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_LCD1
;
1321 if ((radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) &&
1322 (radeon_connector
->devices
& ATOM_DEVICE_CRT1_SUPPORT
)) {
1324 DRM_DEBUG("CRT1 connected\n");
1325 bios_0_scratch
|= ATOM_S0_CRT1_COLOR
;
1326 bios_3_scratch
|= ATOM_S3_CRT1_ACTIVE
;
1327 bios_6_scratch
|= ATOM_S6_ACC_REQ_CRT1
;
1329 DRM_DEBUG("CRT1 disconnected\n");
1330 bios_0_scratch
&= ~ATOM_S0_CRT1_MASK
;
1331 bios_3_scratch
&= ~ATOM_S3_CRT1_ACTIVE
;
1332 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_CRT1
;
1335 if ((radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) &&
1336 (radeon_connector
->devices
& ATOM_DEVICE_CRT2_SUPPORT
)) {
1338 DRM_DEBUG("CRT2 connected\n");
1339 bios_0_scratch
|= ATOM_S0_CRT2_COLOR
;
1340 bios_3_scratch
|= ATOM_S3_CRT2_ACTIVE
;
1341 bios_6_scratch
|= ATOM_S6_ACC_REQ_CRT2
;
1343 DRM_DEBUG("CRT2 disconnected\n");
1344 bios_0_scratch
&= ~ATOM_S0_CRT2_MASK
;
1345 bios_3_scratch
&= ~ATOM_S3_CRT2_ACTIVE
;
1346 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_CRT2
;
1349 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP1_SUPPORT
) &&
1350 (radeon_connector
->devices
& ATOM_DEVICE_DFP1_SUPPORT
)) {
1352 DRM_DEBUG("DFP1 connected\n");
1353 bios_0_scratch
|= ATOM_S0_DFP1
;
1354 bios_3_scratch
|= ATOM_S3_DFP1_ACTIVE
;
1355 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP1
;
1357 DRM_DEBUG("DFP1 disconnected\n");
1358 bios_0_scratch
&= ~ATOM_S0_DFP1
;
1359 bios_3_scratch
&= ~ATOM_S3_DFP1_ACTIVE
;
1360 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP1
;
1363 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
) &&
1364 (radeon_connector
->devices
& ATOM_DEVICE_DFP2_SUPPORT
)) {
1366 DRM_DEBUG("DFP2 connected\n");
1367 bios_0_scratch
|= ATOM_S0_DFP2
;
1368 bios_3_scratch
|= ATOM_S3_DFP2_ACTIVE
;
1369 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP2
;
1371 DRM_DEBUG("DFP2 disconnected\n");
1372 bios_0_scratch
&= ~ATOM_S0_DFP2
;
1373 bios_3_scratch
&= ~ATOM_S3_DFP2_ACTIVE
;
1374 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP2
;
1377 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP3_SUPPORT
) &&
1378 (radeon_connector
->devices
& ATOM_DEVICE_DFP3_SUPPORT
)) {
1380 DRM_DEBUG("DFP3 connected\n");
1381 bios_0_scratch
|= ATOM_S0_DFP3
;
1382 bios_3_scratch
|= ATOM_S3_DFP3_ACTIVE
;
1383 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP3
;
1385 DRM_DEBUG("DFP3 disconnected\n");
1386 bios_0_scratch
&= ~ATOM_S0_DFP3
;
1387 bios_3_scratch
&= ~ATOM_S3_DFP3_ACTIVE
;
1388 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP3
;
1391 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP4_SUPPORT
) &&
1392 (radeon_connector
->devices
& ATOM_DEVICE_DFP4_SUPPORT
)) {
1394 DRM_DEBUG("DFP4 connected\n");
1395 bios_0_scratch
|= ATOM_S0_DFP4
;
1396 bios_3_scratch
|= ATOM_S3_DFP4_ACTIVE
;
1397 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP4
;
1399 DRM_DEBUG("DFP4 disconnected\n");
1400 bios_0_scratch
&= ~ATOM_S0_DFP4
;
1401 bios_3_scratch
&= ~ATOM_S3_DFP4_ACTIVE
;
1402 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP4
;
1405 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP5_SUPPORT
) &&
1406 (radeon_connector
->devices
& ATOM_DEVICE_DFP5_SUPPORT
)) {
1408 DRM_DEBUG("DFP5 connected\n");
1409 bios_0_scratch
|= ATOM_S0_DFP5
;
1410 bios_3_scratch
|= ATOM_S3_DFP5_ACTIVE
;
1411 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP5
;
1413 DRM_DEBUG("DFP5 disconnected\n");
1414 bios_0_scratch
&= ~ATOM_S0_DFP5
;
1415 bios_3_scratch
&= ~ATOM_S3_DFP5_ACTIVE
;
1416 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP5
;
1420 if (rdev
->family
>= CHIP_R600
) {
1421 WREG32(R600_BIOS_0_SCRATCH
, bios_0_scratch
);
1422 WREG32(R600_BIOS_3_SCRATCH
, bios_3_scratch
);
1423 WREG32(R600_BIOS_6_SCRATCH
, bios_6_scratch
);
1425 WREG32(RADEON_BIOS_0_SCRATCH
, bios_0_scratch
);
1426 WREG32(RADEON_BIOS_3_SCRATCH
, bios_3_scratch
);
1427 WREG32(RADEON_BIOS_6_SCRATCH
, bios_6_scratch
);
1432 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder
*encoder
, int crtc
)
1434 struct drm_device
*dev
= encoder
->dev
;
1435 struct radeon_device
*rdev
= dev
->dev_private
;
1436 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1437 uint32_t bios_3_scratch
;
1439 if (rdev
->family
>= CHIP_R600
)
1440 bios_3_scratch
= RREG32(R600_BIOS_3_SCRATCH
);
1442 bios_3_scratch
= RREG32(RADEON_BIOS_3_SCRATCH
);
1444 if (radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
1445 bios_3_scratch
&= ~ATOM_S3_TV1_CRTC_ACTIVE
;
1446 bios_3_scratch
|= (crtc
<< 18);
1448 if (radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
1449 bios_3_scratch
&= ~ATOM_S3_CV_CRTC_ACTIVE
;
1450 bios_3_scratch
|= (crtc
<< 24);
1452 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
1453 bios_3_scratch
&= ~ATOM_S3_CRT1_CRTC_ACTIVE
;
1454 bios_3_scratch
|= (crtc
<< 16);
1456 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
1457 bios_3_scratch
&= ~ATOM_S3_CRT2_CRTC_ACTIVE
;
1458 bios_3_scratch
|= (crtc
<< 20);
1460 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) {
1461 bios_3_scratch
&= ~ATOM_S3_LCD1_CRTC_ACTIVE
;
1462 bios_3_scratch
|= (crtc
<< 17);
1464 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP1_SUPPORT
) {
1465 bios_3_scratch
&= ~ATOM_S3_DFP1_CRTC_ACTIVE
;
1466 bios_3_scratch
|= (crtc
<< 19);
1468 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
) {
1469 bios_3_scratch
&= ~ATOM_S3_DFP2_CRTC_ACTIVE
;
1470 bios_3_scratch
|= (crtc
<< 23);
1472 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP3_SUPPORT
) {
1473 bios_3_scratch
&= ~ATOM_S3_DFP3_CRTC_ACTIVE
;
1474 bios_3_scratch
|= (crtc
<< 25);
1477 if (rdev
->family
>= CHIP_R600
)
1478 WREG32(R600_BIOS_3_SCRATCH
, bios_3_scratch
);
1480 WREG32(RADEON_BIOS_3_SCRATCH
, bios_3_scratch
);
1484 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder
*encoder
, bool on
)
1486 struct drm_device
*dev
= encoder
->dev
;
1487 struct radeon_device
*rdev
= dev
->dev_private
;
1488 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1489 uint32_t bios_2_scratch
;
1491 if (rdev
->family
>= CHIP_R600
)
1492 bios_2_scratch
= RREG32(R600_BIOS_2_SCRATCH
);
1494 bios_2_scratch
= RREG32(RADEON_BIOS_2_SCRATCH
);
1496 if (radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
1498 bios_2_scratch
&= ~ATOM_S2_TV1_DPMS_STATE
;
1500 bios_2_scratch
|= ATOM_S2_TV1_DPMS_STATE
;
1502 if (radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
1504 bios_2_scratch
&= ~ATOM_S2_CV_DPMS_STATE
;
1506 bios_2_scratch
|= ATOM_S2_CV_DPMS_STATE
;
1508 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
1510 bios_2_scratch
&= ~ATOM_S2_CRT1_DPMS_STATE
;
1512 bios_2_scratch
|= ATOM_S2_CRT1_DPMS_STATE
;
1514 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
1516 bios_2_scratch
&= ~ATOM_S2_CRT2_DPMS_STATE
;
1518 bios_2_scratch
|= ATOM_S2_CRT2_DPMS_STATE
;
1520 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) {
1522 bios_2_scratch
&= ~ATOM_S2_LCD1_DPMS_STATE
;
1524 bios_2_scratch
|= ATOM_S2_LCD1_DPMS_STATE
;
1526 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP1_SUPPORT
) {
1528 bios_2_scratch
&= ~ATOM_S2_DFP1_DPMS_STATE
;
1530 bios_2_scratch
|= ATOM_S2_DFP1_DPMS_STATE
;
1532 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
) {
1534 bios_2_scratch
&= ~ATOM_S2_DFP2_DPMS_STATE
;
1536 bios_2_scratch
|= ATOM_S2_DFP2_DPMS_STATE
;
1538 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP3_SUPPORT
) {
1540 bios_2_scratch
&= ~ATOM_S2_DFP3_DPMS_STATE
;
1542 bios_2_scratch
|= ATOM_S2_DFP3_DPMS_STATE
;
1544 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP4_SUPPORT
) {
1546 bios_2_scratch
&= ~ATOM_S2_DFP4_DPMS_STATE
;
1548 bios_2_scratch
|= ATOM_S2_DFP4_DPMS_STATE
;
1550 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP5_SUPPORT
) {
1552 bios_2_scratch
&= ~ATOM_S2_DFP5_DPMS_STATE
;
1554 bios_2_scratch
|= ATOM_S2_DFP5_DPMS_STATE
;
1557 if (rdev
->family
>= CHIP_R600
)
1558 WREG32(R600_BIOS_2_SCRATCH
, bios_2_scratch
);
1560 WREG32(RADEON_BIOS_2_SCRATCH
, bios_2_scratch
);