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
,
51 struct radeon_hpd
*hpd
);
53 /* from radeon_legacy_encoder.c */
55 radeon_add_legacy_encoder(struct drm_device
*dev
, uint32_t encoder_id
,
56 uint32_t supported_device
);
58 union atom_supported_devices
{
59 struct _ATOM_SUPPORTED_DEVICES_INFO info
;
60 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2
;
61 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1
;
64 static inline struct radeon_i2c_bus_rec
radeon_lookup_i2c_gpio(struct radeon_device
*rdev
,
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
;
72 uint16_t data_offset
, size
;
75 memset(&i2c
, 0, sizeof(struct radeon_i2c_bus_rec
));
78 if (atom_parse_data_header(ctx
, index
, &size
, NULL
, NULL
, &data_offset
)) {
79 i2c_info
= (struct _ATOM_GPIO_I2C_INFO
*)(ctx
->bios
+ data_offset
);
81 num_indices
= (size
- sizeof(ATOM_COMMON_TABLE_HEADER
)) /
82 sizeof(ATOM_GPIO_I2C_ASSIGMENT
);
84 for (i
= 0; i
< num_indices
; i
++) {
85 gpio
= &i2c_info
->asGPIO_Info
[i
];
87 if (gpio
->sucI2cId
.ucAccess
== id
) {
88 i2c
.mask_clk_reg
= le16_to_cpu(gpio
->usClkMaskRegisterIndex
) * 4;
89 i2c
.mask_data_reg
= le16_to_cpu(gpio
->usDataMaskRegisterIndex
) * 4;
90 i2c
.en_clk_reg
= le16_to_cpu(gpio
->usClkEnRegisterIndex
) * 4;
91 i2c
.en_data_reg
= le16_to_cpu(gpio
->usDataEnRegisterIndex
) * 4;
92 i2c
.y_clk_reg
= le16_to_cpu(gpio
->usClkY_RegisterIndex
) * 4;
93 i2c
.y_data_reg
= le16_to_cpu(gpio
->usDataY_RegisterIndex
) * 4;
94 i2c
.a_clk_reg
= le16_to_cpu(gpio
->usClkA_RegisterIndex
) * 4;
95 i2c
.a_data_reg
= le16_to_cpu(gpio
->usDataA_RegisterIndex
) * 4;
96 i2c
.mask_clk_mask
= (1 << gpio
->ucClkMaskShift
);
97 i2c
.mask_data_mask
= (1 << gpio
->ucDataMaskShift
);
98 i2c
.en_clk_mask
= (1 << gpio
->ucClkEnShift
);
99 i2c
.en_data_mask
= (1 << gpio
->ucDataEnShift
);
100 i2c
.y_clk_mask
= (1 << gpio
->ucClkY_Shift
);
101 i2c
.y_data_mask
= (1 << gpio
->ucDataY_Shift
);
102 i2c
.a_clk_mask
= (1 << gpio
->ucClkA_Shift
);
103 i2c
.a_data_mask
= (1 << gpio
->ucDataA_Shift
);
105 if (gpio
->sucI2cId
.sbfAccess
.bfHW_Capable
)
106 i2c
.hw_capable
= true;
108 i2c
.hw_capable
= false;
110 if (gpio
->sucI2cId
.ucAccess
== 0xa0)
115 i2c
.i2c_id
= gpio
->sucI2cId
.ucAccess
;
117 if (i2c
.mask_clk_reg
)
127 void radeon_atombios_i2c_init(struct radeon_device
*rdev
)
129 struct atom_context
*ctx
= rdev
->mode_info
.atom_context
;
130 ATOM_GPIO_I2C_ASSIGMENT
*gpio
;
131 struct radeon_i2c_bus_rec i2c
;
132 int index
= GetIndexIntoMasterTable(DATA
, GPIO_I2C_Info
);
133 struct _ATOM_GPIO_I2C_INFO
*i2c_info
;
134 uint16_t data_offset
, size
;
138 memset(&i2c
, 0, sizeof(struct radeon_i2c_bus_rec
));
140 if (atom_parse_data_header(ctx
, index
, &size
, NULL
, NULL
, &data_offset
)) {
141 i2c_info
= (struct _ATOM_GPIO_I2C_INFO
*)(ctx
->bios
+ data_offset
);
143 num_indices
= (size
- sizeof(ATOM_COMMON_TABLE_HEADER
)) /
144 sizeof(ATOM_GPIO_I2C_ASSIGMENT
);
146 for (i
= 0; i
< num_indices
; i
++) {
147 gpio
= &i2c_info
->asGPIO_Info
[i
];
149 i2c
.mask_clk_reg
= le16_to_cpu(gpio
->usClkMaskRegisterIndex
) * 4;
150 i2c
.mask_data_reg
= le16_to_cpu(gpio
->usDataMaskRegisterIndex
) * 4;
151 i2c
.en_clk_reg
= le16_to_cpu(gpio
->usClkEnRegisterIndex
) * 4;
152 i2c
.en_data_reg
= le16_to_cpu(gpio
->usDataEnRegisterIndex
) * 4;
153 i2c
.y_clk_reg
= le16_to_cpu(gpio
->usClkY_RegisterIndex
) * 4;
154 i2c
.y_data_reg
= le16_to_cpu(gpio
->usDataY_RegisterIndex
) * 4;
155 i2c
.a_clk_reg
= le16_to_cpu(gpio
->usClkA_RegisterIndex
) * 4;
156 i2c
.a_data_reg
= le16_to_cpu(gpio
->usDataA_RegisterIndex
) * 4;
157 i2c
.mask_clk_mask
= (1 << gpio
->ucClkMaskShift
);
158 i2c
.mask_data_mask
= (1 << gpio
->ucDataMaskShift
);
159 i2c
.en_clk_mask
= (1 << gpio
->ucClkEnShift
);
160 i2c
.en_data_mask
= (1 << gpio
->ucDataEnShift
);
161 i2c
.y_clk_mask
= (1 << gpio
->ucClkY_Shift
);
162 i2c
.y_data_mask
= (1 << gpio
->ucDataY_Shift
);
163 i2c
.a_clk_mask
= (1 << gpio
->ucClkA_Shift
);
164 i2c
.a_data_mask
= (1 << gpio
->ucDataA_Shift
);
166 if (gpio
->sucI2cId
.sbfAccess
.bfHW_Capable
)
167 i2c
.hw_capable
= true;
169 i2c
.hw_capable
= false;
171 if (gpio
->sucI2cId
.ucAccess
== 0xa0)
176 i2c
.i2c_id
= gpio
->sucI2cId
.ucAccess
;
178 if (i2c
.mask_clk_reg
) {
180 sprintf(stmp
, "0x%x", i2c
.i2c_id
);
181 rdev
->i2c_bus
[i
] = radeon_i2c_create(rdev
->ddev
, &i2c
, stmp
);
187 static inline struct radeon_gpio_rec
radeon_lookup_gpio(struct radeon_device
*rdev
,
190 struct atom_context
*ctx
= rdev
->mode_info
.atom_context
;
191 struct radeon_gpio_rec gpio
;
192 int index
= GetIndexIntoMasterTable(DATA
, GPIO_Pin_LUT
);
193 struct _ATOM_GPIO_PIN_LUT
*gpio_info
;
194 ATOM_GPIO_PIN_ASSIGNMENT
*pin
;
195 u16 data_offset
, size
;
198 memset(&gpio
, 0, sizeof(struct radeon_gpio_rec
));
201 if (atom_parse_data_header(ctx
, index
, &size
, NULL
, NULL
, &data_offset
)) {
202 gpio_info
= (struct _ATOM_GPIO_PIN_LUT
*)(ctx
->bios
+ data_offset
);
204 num_indices
= (size
- sizeof(ATOM_COMMON_TABLE_HEADER
)) /
205 sizeof(ATOM_GPIO_PIN_ASSIGNMENT
);
207 for (i
= 0; i
< num_indices
; i
++) {
208 pin
= &gpio_info
->asGPIO_Pin
[i
];
209 if (id
== pin
->ucGPIO_ID
) {
210 gpio
.id
= pin
->ucGPIO_ID
;
211 gpio
.reg
= pin
->usGpioPin_AIndex
* 4;
212 gpio
.mask
= (1 << pin
->ucGpioPinBitShift
);
222 static struct radeon_hpd
radeon_atom_get_hpd_info_from_gpio(struct radeon_device
*rdev
,
223 struct radeon_gpio_rec
*gpio
)
225 struct radeon_hpd hpd
;
228 if (ASIC_IS_DCE4(rdev
))
229 reg
= EVERGREEN_DC_GPIO_HPD_A
;
231 reg
= AVIVO_DC_GPIO_HPD_A
;
234 if (gpio
->reg
== reg
) {
237 hpd
.hpd
= RADEON_HPD_1
;
240 hpd
.hpd
= RADEON_HPD_2
;
243 hpd
.hpd
= RADEON_HPD_3
;
246 hpd
.hpd
= RADEON_HPD_4
;
249 hpd
.hpd
= RADEON_HPD_5
;
252 hpd
.hpd
= RADEON_HPD_6
;
255 hpd
.hpd
= RADEON_HPD_NONE
;
259 hpd
.hpd
= RADEON_HPD_NONE
;
263 static bool radeon_atom_apply_quirks(struct drm_device
*dev
,
264 uint32_t supported_device
,
266 struct radeon_i2c_bus_rec
*i2c_bus
,
268 struct radeon_hpd
*hpd
)
271 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
272 if ((dev
->pdev
->device
== 0x791e) &&
273 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
274 (dev
->pdev
->subsystem_device
== 0x826d)) {
275 if ((*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) &&
276 (supported_device
== ATOM_DEVICE_DFP3_SUPPORT
))
277 *connector_type
= DRM_MODE_CONNECTOR_DVID
;
280 /* Asrock RS600 board lists the DVI port as HDMI */
281 if ((dev
->pdev
->device
== 0x7941) &&
282 (dev
->pdev
->subsystem_vendor
== 0x1849) &&
283 (dev
->pdev
->subsystem_device
== 0x7941)) {
284 if ((*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) &&
285 (supported_device
== ATOM_DEVICE_DFP3_SUPPORT
))
286 *connector_type
= DRM_MODE_CONNECTOR_DVID
;
289 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
290 if ((dev
->pdev
->device
== 0x7941) &&
291 (dev
->pdev
->subsystem_vendor
== 0x147b) &&
292 (dev
->pdev
->subsystem_device
== 0x2412)) {
293 if (*connector_type
== DRM_MODE_CONNECTOR_DVII
)
297 /* Falcon NW laptop lists vga ddc line for LVDS */
298 if ((dev
->pdev
->device
== 0x5653) &&
299 (dev
->pdev
->subsystem_vendor
== 0x1462) &&
300 (dev
->pdev
->subsystem_device
== 0x0291)) {
301 if (*connector_type
== DRM_MODE_CONNECTOR_LVDS
) {
302 i2c_bus
->valid
= false;
307 /* HIS X1300 is DVI+VGA, not DVI+DVI */
308 if ((dev
->pdev
->device
== 0x7146) &&
309 (dev
->pdev
->subsystem_vendor
== 0x17af) &&
310 (dev
->pdev
->subsystem_device
== 0x2058)) {
311 if (supported_device
== ATOM_DEVICE_DFP1_SUPPORT
)
315 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
316 if ((dev
->pdev
->device
== 0x7142) &&
317 (dev
->pdev
->subsystem_vendor
== 0x1458) &&
318 (dev
->pdev
->subsystem_device
== 0x2134)) {
319 if (supported_device
== ATOM_DEVICE_DFP1_SUPPORT
)
325 if ((dev
->pdev
->device
== 0x71C5) &&
326 (dev
->pdev
->subsystem_vendor
== 0x106b) &&
327 (dev
->pdev
->subsystem_device
== 0x0080)) {
328 if ((supported_device
== ATOM_DEVICE_CRT1_SUPPORT
) ||
329 (supported_device
== ATOM_DEVICE_DFP2_SUPPORT
))
331 if (supported_device
== ATOM_DEVICE_CRT2_SUPPORT
)
335 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
336 if ((dev
->pdev
->device
== 0x9598) &&
337 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
338 (dev
->pdev
->subsystem_device
== 0x01da)) {
339 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
340 *connector_type
= DRM_MODE_CONNECTOR_DVII
;
344 /* ASUS HD 3600 board lists the DVI port as HDMI */
345 if ((dev
->pdev
->device
== 0x9598) &&
346 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
347 (dev
->pdev
->subsystem_device
== 0x01e4)) {
348 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
349 *connector_type
= DRM_MODE_CONNECTOR_DVII
;
353 /* ASUS HD 3450 board lists the DVI port as HDMI */
354 if ((dev
->pdev
->device
== 0x95C5) &&
355 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
356 (dev
->pdev
->subsystem_device
== 0x01e2)) {
357 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
358 *connector_type
= DRM_MODE_CONNECTOR_DVII
;
362 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
363 * HDMI + VGA reporting as HDMI
365 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
366 if (supported_device
& (ATOM_DEVICE_CRT_SUPPORT
)) {
367 *connector_type
= DRM_MODE_CONNECTOR_VGA
;
372 /* Acer laptop reports DVI-D as DVI-I */
373 if ((dev
->pdev
->device
== 0x95c4) &&
374 (dev
->pdev
->subsystem_vendor
== 0x1025) &&
375 (dev
->pdev
->subsystem_device
== 0x013c)) {
376 if ((*connector_type
== DRM_MODE_CONNECTOR_DVII
) &&
377 (supported_device
== ATOM_DEVICE_DFP1_SUPPORT
))
378 *connector_type
= DRM_MODE_CONNECTOR_DVID
;
381 /* XFX Pine Group device rv730 reports no VGA DDC lines
382 * even though they are wired up to record 0x93
384 if ((dev
->pdev
->device
== 0x9498) &&
385 (dev
->pdev
->subsystem_vendor
== 0x1682) &&
386 (dev
->pdev
->subsystem_device
== 0x2452)) {
387 struct radeon_device
*rdev
= dev
->dev_private
;
388 *i2c_bus
= radeon_lookup_i2c_gpio(rdev
, 0x93);
393 const int supported_devices_connector_convert
[] = {
394 DRM_MODE_CONNECTOR_Unknown
,
395 DRM_MODE_CONNECTOR_VGA
,
396 DRM_MODE_CONNECTOR_DVII
,
397 DRM_MODE_CONNECTOR_DVID
,
398 DRM_MODE_CONNECTOR_DVIA
,
399 DRM_MODE_CONNECTOR_SVIDEO
,
400 DRM_MODE_CONNECTOR_Composite
,
401 DRM_MODE_CONNECTOR_LVDS
,
402 DRM_MODE_CONNECTOR_Unknown
,
403 DRM_MODE_CONNECTOR_Unknown
,
404 DRM_MODE_CONNECTOR_HDMIA
,
405 DRM_MODE_CONNECTOR_HDMIB
,
406 DRM_MODE_CONNECTOR_Unknown
,
407 DRM_MODE_CONNECTOR_Unknown
,
408 DRM_MODE_CONNECTOR_9PinDIN
,
409 DRM_MODE_CONNECTOR_DisplayPort
412 const uint16_t supported_devices_connector_object_id_convert
[] = {
413 CONNECTOR_OBJECT_ID_NONE
,
414 CONNECTOR_OBJECT_ID_VGA
,
415 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I
, /* not all boards support DL */
416 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D
, /* not all boards support DL */
417 CONNECTOR_OBJECT_ID_VGA
, /* technically DVI-A */
418 CONNECTOR_OBJECT_ID_COMPOSITE
,
419 CONNECTOR_OBJECT_ID_SVIDEO
,
420 CONNECTOR_OBJECT_ID_LVDS
,
421 CONNECTOR_OBJECT_ID_9PIN_DIN
,
422 CONNECTOR_OBJECT_ID_9PIN_DIN
,
423 CONNECTOR_OBJECT_ID_DISPLAYPORT
,
424 CONNECTOR_OBJECT_ID_HDMI_TYPE_A
,
425 CONNECTOR_OBJECT_ID_HDMI_TYPE_B
,
426 CONNECTOR_OBJECT_ID_SVIDEO
429 const int object_connector_convert
[] = {
430 DRM_MODE_CONNECTOR_Unknown
,
431 DRM_MODE_CONNECTOR_DVII
,
432 DRM_MODE_CONNECTOR_DVII
,
433 DRM_MODE_CONNECTOR_DVID
,
434 DRM_MODE_CONNECTOR_DVID
,
435 DRM_MODE_CONNECTOR_VGA
,
436 DRM_MODE_CONNECTOR_Composite
,
437 DRM_MODE_CONNECTOR_SVIDEO
,
438 DRM_MODE_CONNECTOR_Unknown
,
439 DRM_MODE_CONNECTOR_Unknown
,
440 DRM_MODE_CONNECTOR_9PinDIN
,
441 DRM_MODE_CONNECTOR_Unknown
,
442 DRM_MODE_CONNECTOR_HDMIA
,
443 DRM_MODE_CONNECTOR_HDMIB
,
444 DRM_MODE_CONNECTOR_LVDS
,
445 DRM_MODE_CONNECTOR_9PinDIN
,
446 DRM_MODE_CONNECTOR_Unknown
,
447 DRM_MODE_CONNECTOR_Unknown
,
448 DRM_MODE_CONNECTOR_Unknown
,
449 DRM_MODE_CONNECTOR_DisplayPort
,
450 DRM_MODE_CONNECTOR_eDP
,
451 DRM_MODE_CONNECTOR_Unknown
454 bool radeon_get_atom_connector_info_from_object_table(struct drm_device
*dev
)
456 struct radeon_device
*rdev
= dev
->dev_private
;
457 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
458 struct atom_context
*ctx
= mode_info
->atom_context
;
459 int index
= GetIndexIntoMasterTable(DATA
, Object_Header
);
460 u16 size
, data_offset
;
462 ATOM_CONNECTOR_OBJECT_TABLE
*con_obj
;
463 ATOM_DISPLAY_OBJECT_PATH_TABLE
*path_obj
;
464 ATOM_OBJECT_HEADER
*obj_header
;
465 int i
, j
, path_size
, device_support
;
467 u16 igp_lane_info
, conn_id
, connector_object_id
;
469 struct radeon_i2c_bus_rec ddc_bus
;
470 struct radeon_gpio_rec gpio
;
471 struct radeon_hpd hpd
;
473 if (!atom_parse_data_header(ctx
, index
, &size
, &frev
, &crev
, &data_offset
))
479 obj_header
= (ATOM_OBJECT_HEADER
*) (ctx
->bios
+ data_offset
);
480 path_obj
= (ATOM_DISPLAY_OBJECT_PATH_TABLE
*)
481 (ctx
->bios
+ data_offset
+
482 le16_to_cpu(obj_header
->usDisplayPathTableOffset
));
483 con_obj
= (ATOM_CONNECTOR_OBJECT_TABLE
*)
484 (ctx
->bios
+ data_offset
+
485 le16_to_cpu(obj_header
->usConnectorObjectTableOffset
));
486 device_support
= le16_to_cpu(obj_header
->usDeviceSupport
);
489 for (i
= 0; i
< path_obj
->ucNumOfDispPath
; i
++) {
490 uint8_t *addr
= (uint8_t *) path_obj
->asDispPath
;
491 ATOM_DISPLAY_OBJECT_PATH
*path
;
493 path
= (ATOM_DISPLAY_OBJECT_PATH
*) addr
;
494 path_size
+= le16_to_cpu(path
->usSize
);
496 if (device_support
& le16_to_cpu(path
->usDeviceTag
)) {
497 uint8_t con_obj_id
, con_obj_num
, con_obj_type
;
500 (le16_to_cpu(path
->usConnObjectId
) & OBJECT_ID_MASK
)
503 (le16_to_cpu(path
->usConnObjectId
) & ENUM_ID_MASK
)
506 (le16_to_cpu(path
->usConnObjectId
) &
507 OBJECT_TYPE_MASK
) >> OBJECT_TYPE_SHIFT
;
509 /* TODO CV support */
510 if (le16_to_cpu(path
->usDeviceTag
) ==
511 ATOM_DEVICE_CV_SUPPORT
)
515 if ((rdev
->flags
& RADEON_IS_IGP
) &&
517 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR
)) {
518 uint16_t igp_offset
= 0;
519 ATOM_INTEGRATED_SYSTEM_INFO_V2
*igp_obj
;
522 GetIndexIntoMasterTable(DATA
,
523 IntegratedSystemInfo
);
525 if (atom_parse_data_header(ctx
, index
, &size
, &frev
,
526 &crev
, &igp_offset
)) {
530 (ATOM_INTEGRATED_SYSTEM_INFO_V2
531 *) (ctx
->bios
+ igp_offset
);
534 uint32_t slot_config
, ct
;
536 if (con_obj_num
== 1)
545 ct
= (slot_config
>> 16) & 0xff;
547 object_connector_convert
549 connector_object_id
= ct
;
551 slot_config
& 0xffff;
559 object_connector_convert
[con_obj_id
];
560 connector_object_id
= con_obj_id
;
565 object_connector_convert
[con_obj_id
];
566 connector_object_id
= con_obj_id
;
569 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
572 for (j
= 0; j
< ((le16_to_cpu(path
->usSize
) - 8) / 2);
574 uint8_t enc_obj_id
, enc_obj_num
, enc_obj_type
;
577 (le16_to_cpu(path
->usGraphicObjIds
[j
]) &
578 OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
580 (le16_to_cpu(path
->usGraphicObjIds
[j
]) &
581 ENUM_ID_MASK
) >> ENUM_ID_SHIFT
;
583 (le16_to_cpu(path
->usGraphicObjIds
[j
]) &
584 OBJECT_TYPE_MASK
) >> OBJECT_TYPE_SHIFT
;
586 /* FIXME: add support for router objects */
587 if (enc_obj_type
== GRAPH_OBJECT_TYPE_ENCODER
) {
588 if (enc_obj_num
== 2)
593 radeon_add_atom_encoder(dev
,
602 /* look up gpio for ddc, hpd */
603 ddc_bus
.valid
= false;
604 hpd
.hpd
= RADEON_HPD_NONE
;
605 if ((le16_to_cpu(path
->usDeviceTag
) &
606 (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
)) == 0) {
607 for (j
= 0; j
< con_obj
->ucNumberOfObjects
; j
++) {
608 if (le16_to_cpu(path
->usConnObjectId
) ==
609 le16_to_cpu(con_obj
->asObjects
[j
].
611 ATOM_COMMON_RECORD_HEADER
613 (ATOM_COMMON_RECORD_HEADER
615 (ctx
->bios
+ data_offset
+
616 le16_to_cpu(con_obj
->
619 ATOM_I2C_RECORD
*i2c_record
;
620 ATOM_HPD_INT_RECORD
*hpd_record
;
621 ATOM_I2C_ID_CONFIG_ACCESS
*i2c_config
;
623 while (record
->ucRecordType
> 0
626 ATOM_MAX_OBJECT_RECORD_NUMBER
) {
627 switch (record
->ucRecordType
) {
628 case ATOM_I2C_RECORD_TYPE
:
633 (ATOM_I2C_ID_CONFIG_ACCESS
*)
634 &i2c_record
->sucI2cId
;
635 ddc_bus
= radeon_lookup_i2c_gpio(rdev
,
639 case ATOM_HPD_INT_RECORD_TYPE
:
641 (ATOM_HPD_INT_RECORD
*)
643 gpio
= radeon_lookup_gpio(rdev
,
644 hpd_record
->ucHPDIntGPIOID
);
645 hpd
= radeon_atom_get_hpd_info_from_gpio(rdev
, &gpio
);
646 hpd
.plugged_state
= hpd_record
->ucPlugged_PinState
;
650 (ATOM_COMMON_RECORD_HEADER
661 /* needed for aux chan transactions */
662 ddc_bus
.hpd
= hpd
.hpd
;
664 conn_id
= le16_to_cpu(path
->usConnObjectId
);
666 if (!radeon_atom_apply_quirks
667 (dev
, le16_to_cpu(path
->usDeviceTag
), &connector_type
,
668 &ddc_bus
, &conn_id
, &hpd
))
671 radeon_add_atom_connector(dev
,
675 connector_type
, &ddc_bus
,
676 linkb
, igp_lane_info
,
683 radeon_link_encoder_connector(dev
);
688 static uint16_t atombios_get_connector_object_id(struct drm_device
*dev
,
692 struct radeon_device
*rdev
= dev
->dev_private
;
694 if (rdev
->flags
& RADEON_IS_IGP
) {
695 return supported_devices_connector_object_id_convert
697 } else if (((connector_type
== DRM_MODE_CONNECTOR_DVII
) ||
698 (connector_type
== DRM_MODE_CONNECTOR_DVID
)) &&
699 (devices
& ATOM_DEVICE_DFP2_SUPPORT
)) {
700 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
701 struct atom_context
*ctx
= mode_info
->atom_context
;
702 int index
= GetIndexIntoMasterTable(DATA
, XTMDS_Info
);
703 uint16_t size
, data_offset
;
705 ATOM_XTMDS_INFO
*xtmds
;
707 if (atom_parse_data_header(ctx
, index
, &size
, &frev
, &crev
, &data_offset
)) {
708 xtmds
= (ATOM_XTMDS_INFO
*)(ctx
->bios
+ data_offset
);
710 if (xtmds
->ucSupportedLink
& ATOM_XTMDS_SUPPORTED_DUALLINK
) {
711 if (connector_type
== DRM_MODE_CONNECTOR_DVII
)
712 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I
;
714 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D
;
716 if (connector_type
== DRM_MODE_CONNECTOR_DVII
)
717 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I
;
719 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D
;
722 return supported_devices_connector_object_id_convert
725 return supported_devices_connector_object_id_convert
730 struct bios_connector
{
735 struct radeon_i2c_bus_rec ddc_bus
;
736 struct radeon_hpd hpd
;
739 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
743 struct radeon_device
*rdev
= dev
->dev_private
;
744 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
745 struct atom_context
*ctx
= mode_info
->atom_context
;
746 int index
= GetIndexIntoMasterTable(DATA
, SupportedDevicesInfo
);
747 uint16_t size
, data_offset
;
749 uint16_t device_support
;
751 union atom_supported_devices
*supported_devices
;
752 int i
, j
, max_device
;
753 struct bios_connector
*bios_connectors
;
754 size_t bc_size
= sizeof(*bios_connectors
) * ATOM_MAX_SUPPORTED_DEVICE
;
756 bios_connectors
= kzalloc(bc_size
, GFP_KERNEL
);
757 if (!bios_connectors
)
760 if (!atom_parse_data_header(ctx
, index
, &size
, &frev
, &crev
,
762 kfree(bios_connectors
);
767 (union atom_supported_devices
*)(ctx
->bios
+ data_offset
);
769 device_support
= le16_to_cpu(supported_devices
->info
.usDeviceSupport
);
772 max_device
= ATOM_MAX_SUPPORTED_DEVICE
;
774 max_device
= ATOM_MAX_SUPPORTED_DEVICE_INFO
;
776 for (i
= 0; i
< max_device
; i
++) {
777 ATOM_CONNECTOR_INFO_I2C ci
=
778 supported_devices
->info
.asConnInfo
[i
];
780 bios_connectors
[i
].valid
= false;
782 if (!(device_support
& (1 << i
))) {
786 if (i
== ATOM_DEVICE_CV_INDEX
) {
787 DRM_DEBUG_KMS("Skipping Component Video\n");
791 bios_connectors
[i
].connector_type
=
792 supported_devices_connector_convert
[ci
.sucConnectorInfo
.
796 if (bios_connectors
[i
].connector_type
==
797 DRM_MODE_CONNECTOR_Unknown
)
800 dac
= ci
.sucConnectorInfo
.sbfAccess
.bfAssociatedDAC
;
802 bios_connectors
[i
].line_mux
=
803 ci
.sucI2cId
.ucAccess
;
805 /* give tv unique connector ids */
806 if (i
== ATOM_DEVICE_TV1_INDEX
) {
807 bios_connectors
[i
].ddc_bus
.valid
= false;
808 bios_connectors
[i
].line_mux
= 50;
809 } else if (i
== ATOM_DEVICE_TV2_INDEX
) {
810 bios_connectors
[i
].ddc_bus
.valid
= false;
811 bios_connectors
[i
].line_mux
= 51;
812 } else if (i
== ATOM_DEVICE_CV_INDEX
) {
813 bios_connectors
[i
].ddc_bus
.valid
= false;
814 bios_connectors
[i
].line_mux
= 52;
816 bios_connectors
[i
].ddc_bus
=
817 radeon_lookup_i2c_gpio(rdev
,
818 bios_connectors
[i
].line_mux
);
820 if ((crev
> 1) && (frev
> 1)) {
821 u8 isb
= supported_devices
->info_2d1
.asIntSrcInfo
[i
].ucIntSrcBitmap
;
824 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_1
;
827 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_2
;
830 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_NONE
;
834 if (i
== ATOM_DEVICE_DFP1_INDEX
)
835 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_1
;
836 else if (i
== ATOM_DEVICE_DFP2_INDEX
)
837 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_2
;
839 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_NONE
;
842 /* Always set the connector type to VGA for CRT1/CRT2. if they are
843 * shared with a DVI port, we'll pick up the DVI connector when we
844 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
846 if (i
== ATOM_DEVICE_CRT1_INDEX
|| i
== ATOM_DEVICE_CRT2_INDEX
)
847 bios_connectors
[i
].connector_type
=
848 DRM_MODE_CONNECTOR_VGA
;
850 if (!radeon_atom_apply_quirks
851 (dev
, (1 << i
), &bios_connectors
[i
].connector_type
,
852 &bios_connectors
[i
].ddc_bus
, &bios_connectors
[i
].line_mux
,
853 &bios_connectors
[i
].hpd
))
856 bios_connectors
[i
].valid
= true;
857 bios_connectors
[i
].devices
= (1 << i
);
859 if (ASIC_IS_AVIVO(rdev
) || radeon_r4xx_atom
)
860 radeon_add_atom_encoder(dev
,
861 radeon_get_encoder_id(dev
,
866 radeon_add_legacy_encoder(dev
,
867 radeon_get_encoder_id(dev
,
873 /* combine shared connectors */
874 for (i
= 0; i
< max_device
; i
++) {
875 if (bios_connectors
[i
].valid
) {
876 for (j
= 0; j
< max_device
; j
++) {
877 if (bios_connectors
[j
].valid
&& (i
!= j
)) {
878 if (bios_connectors
[i
].line_mux
==
879 bios_connectors
[j
].line_mux
) {
880 /* make sure not to combine LVDS */
881 if (bios_connectors
[i
].devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
882 bios_connectors
[i
].line_mux
= 53;
883 bios_connectors
[i
].ddc_bus
.valid
= false;
886 if (bios_connectors
[j
].devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
887 bios_connectors
[j
].line_mux
= 53;
888 bios_connectors
[j
].ddc_bus
.valid
= false;
891 /* combine analog and digital for DVI-I */
892 if (((bios_connectors
[i
].devices
& (ATOM_DEVICE_DFP_SUPPORT
)) &&
893 (bios_connectors
[j
].devices
& (ATOM_DEVICE_CRT_SUPPORT
))) ||
894 ((bios_connectors
[j
].devices
& (ATOM_DEVICE_DFP_SUPPORT
)) &&
895 (bios_connectors
[i
].devices
& (ATOM_DEVICE_CRT_SUPPORT
)))) {
896 bios_connectors
[i
].devices
|=
897 bios_connectors
[j
].devices
;
898 bios_connectors
[i
].connector_type
=
899 DRM_MODE_CONNECTOR_DVII
;
900 if (bios_connectors
[j
].devices
& (ATOM_DEVICE_DFP_SUPPORT
))
901 bios_connectors
[i
].hpd
=
902 bios_connectors
[j
].hpd
;
903 bios_connectors
[j
].valid
= false;
911 /* add the connectors */
912 for (i
= 0; i
< max_device
; i
++) {
913 if (bios_connectors
[i
].valid
) {
914 uint16_t connector_object_id
=
915 atombios_get_connector_object_id(dev
,
916 bios_connectors
[i
].connector_type
,
917 bios_connectors
[i
].devices
);
918 radeon_add_atom_connector(dev
,
919 bios_connectors
[i
].line_mux
,
920 bios_connectors
[i
].devices
,
923 &bios_connectors
[i
].ddc_bus
,
926 &bios_connectors
[i
].hpd
);
930 radeon_link_encoder_connector(dev
);
932 kfree(bios_connectors
);
936 union firmware_info
{
937 ATOM_FIRMWARE_INFO info
;
938 ATOM_FIRMWARE_INFO_V1_2 info_12
;
939 ATOM_FIRMWARE_INFO_V1_3 info_13
;
940 ATOM_FIRMWARE_INFO_V1_4 info_14
;
941 ATOM_FIRMWARE_INFO_V2_1 info_21
;
944 bool radeon_atom_get_clock_info(struct drm_device
*dev
)
946 struct radeon_device
*rdev
= dev
->dev_private
;
947 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
948 int index
= GetIndexIntoMasterTable(DATA
, FirmwareInfo
);
949 union firmware_info
*firmware_info
;
951 struct radeon_pll
*p1pll
= &rdev
->clock
.p1pll
;
952 struct radeon_pll
*p2pll
= &rdev
->clock
.p2pll
;
953 struct radeon_pll
*dcpll
= &rdev
->clock
.dcpll
;
954 struct radeon_pll
*spll
= &rdev
->clock
.spll
;
955 struct radeon_pll
*mpll
= &rdev
->clock
.mpll
;
956 uint16_t data_offset
;
958 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
959 &frev
, &crev
, &data_offset
)) {
961 (union firmware_info
*)(mode_info
->atom_context
->bios
+
964 p1pll
->reference_freq
=
965 le16_to_cpu(firmware_info
->info
.usReferenceClock
);
966 p1pll
->reference_div
= 0;
970 le16_to_cpu(firmware_info
->info
.usMinPixelClockPLL_Output
);
973 le32_to_cpu(firmware_info
->info_12
.ulMinPixelClockPLL_Output
);
975 le32_to_cpu(firmware_info
->info
.ulMaxPixelClockPLL_Output
);
978 p1pll
->lcd_pll_out_min
=
979 le16_to_cpu(firmware_info
->info_14
.usLcdMinPixelClockPLL_Output
) * 100;
980 if (p1pll
->lcd_pll_out_min
== 0)
981 p1pll
->lcd_pll_out_min
= p1pll
->pll_out_min
;
982 p1pll
->lcd_pll_out_max
=
983 le16_to_cpu(firmware_info
->info_14
.usLcdMaxPixelClockPLL_Output
) * 100;
984 if (p1pll
->lcd_pll_out_max
== 0)
985 p1pll
->lcd_pll_out_max
= p1pll
->pll_out_max
;
987 p1pll
->lcd_pll_out_min
= p1pll
->pll_out_min
;
988 p1pll
->lcd_pll_out_max
= p1pll
->pll_out_max
;
991 if (p1pll
->pll_out_min
== 0) {
992 if (ASIC_IS_AVIVO(rdev
))
993 p1pll
->pll_out_min
= 64800;
995 p1pll
->pll_out_min
= 20000;
996 } else if (p1pll
->pll_out_min
> 64800) {
997 /* Limiting the pll output range is a good thing generally as
998 * it limits the number of possible pll combinations for a given
999 * frequency presumably to the ones that work best on each card.
1000 * However, certain duallink DVI monitors seem to like
1001 * pll combinations that would be limited by this at least on
1002 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
1005 if (!radeon_new_pll
)
1006 p1pll
->pll_out_min
= 64800;
1010 le16_to_cpu(firmware_info
->info
.usMinPixelClockPLL_Input
);
1012 le16_to_cpu(firmware_info
->info
.usMaxPixelClockPLL_Input
);
1017 spll
->reference_freq
=
1018 le16_to_cpu(firmware_info
->info
.usReferenceClock
);
1019 spll
->reference_div
= 0;
1022 le16_to_cpu(firmware_info
->info
.usMinEngineClockPLL_Output
);
1024 le32_to_cpu(firmware_info
->info
.ulMaxEngineClockPLL_Output
);
1027 if (spll
->pll_out_min
== 0) {
1028 if (ASIC_IS_AVIVO(rdev
))
1029 spll
->pll_out_min
= 64800;
1031 spll
->pll_out_min
= 20000;
1035 le16_to_cpu(firmware_info
->info
.usMinEngineClockPLL_Input
);
1037 le16_to_cpu(firmware_info
->info
.usMaxEngineClockPLL_Input
);
1040 mpll
->reference_freq
=
1041 le16_to_cpu(firmware_info
->info
.usReferenceClock
);
1042 mpll
->reference_div
= 0;
1045 le16_to_cpu(firmware_info
->info
.usMinMemoryClockPLL_Output
);
1047 le32_to_cpu(firmware_info
->info
.ulMaxMemoryClockPLL_Output
);
1050 if (mpll
->pll_out_min
== 0) {
1051 if (ASIC_IS_AVIVO(rdev
))
1052 mpll
->pll_out_min
= 64800;
1054 mpll
->pll_out_min
= 20000;
1058 le16_to_cpu(firmware_info
->info
.usMinMemoryClockPLL_Input
);
1060 le16_to_cpu(firmware_info
->info
.usMaxMemoryClockPLL_Input
);
1062 rdev
->clock
.default_sclk
=
1063 le32_to_cpu(firmware_info
->info
.ulDefaultEngineClock
);
1064 rdev
->clock
.default_mclk
=
1065 le32_to_cpu(firmware_info
->info
.ulDefaultMemoryClock
);
1067 if (ASIC_IS_DCE4(rdev
)) {
1068 rdev
->clock
.default_dispclk
=
1069 le32_to_cpu(firmware_info
->info_21
.ulDefaultDispEngineClkFreq
);
1070 if (rdev
->clock
.default_dispclk
== 0)
1071 rdev
->clock
.default_dispclk
= 60000; /* 600 Mhz */
1072 rdev
->clock
.dp_extclk
=
1073 le16_to_cpu(firmware_info
->info_21
.usUniphyDPModeExtClkFreq
);
1084 struct _ATOM_INTEGRATED_SYSTEM_INFO info
;
1085 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2
;
1088 bool radeon_atombios_sideport_present(struct radeon_device
*rdev
)
1090 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1091 int index
= GetIndexIntoMasterTable(DATA
, IntegratedSystemInfo
);
1092 union igp_info
*igp_info
;
1096 /* sideport is AMD only */
1097 if (rdev
->family
== CHIP_RS600
)
1100 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1101 &frev
, &crev
, &data_offset
)) {
1102 igp_info
= (union igp_info
*)(mode_info
->atom_context
->bios
+
1106 if (igp_info
->info
.ulBootUpMemoryClock
)
1110 if (igp_info
->info_2
.ucMemoryType
& 0x0f)
1114 DRM_ERROR("Unsupported IGP table: %d %d\n", frev
, crev
);
1121 bool radeon_atombios_get_tmds_info(struct radeon_encoder
*encoder
,
1122 struct radeon_encoder_int_tmds
*tmds
)
1124 struct drm_device
*dev
= encoder
->base
.dev
;
1125 struct radeon_device
*rdev
= dev
->dev_private
;
1126 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1127 int index
= GetIndexIntoMasterTable(DATA
, TMDS_Info
);
1128 uint16_t data_offset
;
1129 struct _ATOM_TMDS_INFO
*tmds_info
;
1134 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1135 &frev
, &crev
, &data_offset
)) {
1137 (struct _ATOM_TMDS_INFO
*)(mode_info
->atom_context
->bios
+
1140 maxfreq
= le16_to_cpu(tmds_info
->usMaxFrequency
);
1141 for (i
= 0; i
< 4; i
++) {
1142 tmds
->tmds_pll
[i
].freq
=
1143 le16_to_cpu(tmds_info
->asMiscInfo
[i
].usFrequency
);
1144 tmds
->tmds_pll
[i
].value
=
1145 tmds_info
->asMiscInfo
[i
].ucPLL_ChargePump
& 0x3f;
1146 tmds
->tmds_pll
[i
].value
|=
1147 (tmds_info
->asMiscInfo
[i
].
1148 ucPLL_VCO_Gain
& 0x3f) << 6;
1149 tmds
->tmds_pll
[i
].value
|=
1150 (tmds_info
->asMiscInfo
[i
].
1151 ucPLL_DutyCycle
& 0xf) << 12;
1152 tmds
->tmds_pll
[i
].value
|=
1153 (tmds_info
->asMiscInfo
[i
].
1154 ucPLL_VoltageSwing
& 0xf) << 16;
1156 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
1157 tmds
->tmds_pll
[i
].freq
,
1158 tmds
->tmds_pll
[i
].value
);
1160 if (maxfreq
== tmds
->tmds_pll
[i
].freq
) {
1161 tmds
->tmds_pll
[i
].freq
= 0xffffffff;
1170 static struct radeon_atom_ss
*radeon_atombios_get_ss_info(struct
1175 struct drm_device
*dev
= encoder
->base
.dev
;
1176 struct radeon_device
*rdev
= dev
->dev_private
;
1177 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1178 int index
= GetIndexIntoMasterTable(DATA
, PPLL_SS_Info
);
1179 uint16_t data_offset
;
1180 struct _ATOM_SPREAD_SPECTRUM_INFO
*ss_info
;
1182 struct radeon_atom_ss
*ss
= NULL
;
1185 if (id
> ATOM_MAX_SS_ENTRY
)
1188 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1189 &frev
, &crev
, &data_offset
)) {
1191 (struct _ATOM_SPREAD_SPECTRUM_INFO
*)(mode_info
->atom_context
->bios
+ data_offset
);
1194 kzalloc(sizeof(struct radeon_atom_ss
), GFP_KERNEL
);
1199 for (i
= 0; i
< ATOM_MAX_SS_ENTRY
; i
++) {
1200 if (ss_info
->asSS_Info
[i
].ucSS_Id
== id
) {
1202 le16_to_cpu(ss_info
->asSS_Info
[i
].usSpreadSpectrumPercentage
);
1203 ss
->type
= ss_info
->asSS_Info
[i
].ucSpreadSpectrumType
;
1204 ss
->step
= ss_info
->asSS_Info
[i
].ucSS_Step
;
1205 ss
->delay
= ss_info
->asSS_Info
[i
].ucSS_Delay
;
1206 ss
->range
= ss_info
->asSS_Info
[i
].ucSS_Range
;
1207 ss
->refdiv
= ss_info
->asSS_Info
[i
].ucRecommendedRef_Div
;
1216 struct _ATOM_LVDS_INFO info
;
1217 struct _ATOM_LVDS_INFO_V12 info_12
;
1220 struct radeon_encoder_atom_dig
*radeon_atombios_get_lvds_info(struct
1224 struct drm_device
*dev
= encoder
->base
.dev
;
1225 struct radeon_device
*rdev
= dev
->dev_private
;
1226 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1227 int index
= GetIndexIntoMasterTable(DATA
, LVDS_Info
);
1228 uint16_t data_offset
, misc
;
1229 union lvds_info
*lvds_info
;
1231 struct radeon_encoder_atom_dig
*lvds
= NULL
;
1233 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1234 &frev
, &crev
, &data_offset
)) {
1236 (union lvds_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
1238 kzalloc(sizeof(struct radeon_encoder_atom_dig
), GFP_KERNEL
);
1243 lvds
->native_mode
.clock
=
1244 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usPixClk
) * 10;
1245 lvds
->native_mode
.hdisplay
=
1246 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHActive
);
1247 lvds
->native_mode
.vdisplay
=
1248 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVActive
);
1249 lvds
->native_mode
.htotal
= lvds
->native_mode
.hdisplay
+
1250 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHBlanking_Time
);
1251 lvds
->native_mode
.hsync_start
= lvds
->native_mode
.hdisplay
+
1252 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHSyncOffset
);
1253 lvds
->native_mode
.hsync_end
= lvds
->native_mode
.hsync_start
+
1254 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHSyncWidth
);
1255 lvds
->native_mode
.vtotal
= lvds
->native_mode
.vdisplay
+
1256 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVBlanking_Time
);
1257 lvds
->native_mode
.vsync_start
= lvds
->native_mode
.vdisplay
+
1258 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVSyncOffset
);
1259 lvds
->native_mode
.vsync_end
= lvds
->native_mode
.vsync_start
+
1260 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVSyncWidth
);
1261 lvds
->panel_pwr_delay
=
1262 le16_to_cpu(lvds_info
->info
.usOffDelayInMs
);
1263 lvds
->lvds_misc
= lvds_info
->info
.ucLVDS_Misc
;
1265 misc
= le16_to_cpu(lvds_info
->info
.sLCDTiming
.susModeMiscInfo
.usAccess
);
1266 if (misc
& ATOM_VSYNC_POLARITY
)
1267 lvds
->native_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
1268 if (misc
& ATOM_HSYNC_POLARITY
)
1269 lvds
->native_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
1270 if (misc
& ATOM_COMPOSITESYNC
)
1271 lvds
->native_mode
.flags
|= DRM_MODE_FLAG_CSYNC
;
1272 if (misc
& ATOM_INTERLACE
)
1273 lvds
->native_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
1274 if (misc
& ATOM_DOUBLE_CLOCK_MODE
)
1275 lvds
->native_mode
.flags
|= DRM_MODE_FLAG_DBLSCAN
;
1277 /* set crtc values */
1278 drm_mode_set_crtcinfo(&lvds
->native_mode
, CRTC_INTERLACE_HALVE_V
);
1280 lvds
->ss
= radeon_atombios_get_ss_info(encoder
, lvds_info
->info
.ucSS_Id
);
1282 if (ASIC_IS_AVIVO(rdev
)) {
1283 if (radeon_new_pll
== 0)
1284 lvds
->pll_algo
= PLL_ALGO_LEGACY
;
1286 lvds
->pll_algo
= PLL_ALGO_NEW
;
1288 if (radeon_new_pll
== 1)
1289 lvds
->pll_algo
= PLL_ALGO_NEW
;
1291 lvds
->pll_algo
= PLL_ALGO_LEGACY
;
1294 encoder
->native_mode
= lvds
->native_mode
;
1299 struct radeon_encoder_primary_dac
*
1300 radeon_atombios_get_primary_dac_info(struct radeon_encoder
*encoder
)
1302 struct drm_device
*dev
= encoder
->base
.dev
;
1303 struct radeon_device
*rdev
= dev
->dev_private
;
1304 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1305 int index
= GetIndexIntoMasterTable(DATA
, CompassionateData
);
1306 uint16_t data_offset
;
1307 struct _COMPASSIONATE_DATA
*dac_info
;
1310 struct radeon_encoder_primary_dac
*p_dac
= NULL
;
1312 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1313 &frev
, &crev
, &data_offset
)) {
1314 dac_info
= (struct _COMPASSIONATE_DATA
*)
1315 (mode_info
->atom_context
->bios
+ data_offset
);
1317 p_dac
= kzalloc(sizeof(struct radeon_encoder_primary_dac
), GFP_KERNEL
);
1322 bg
= dac_info
->ucDAC1_BG_Adjustment
;
1323 dac
= dac_info
->ucDAC1_DAC_Adjustment
;
1324 p_dac
->ps2_pdac_adj
= (bg
<< 8) | (dac
);
1330 bool radeon_atom_get_tv_timings(struct radeon_device
*rdev
, int index
,
1331 struct drm_display_mode
*mode
)
1333 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1334 ATOM_ANALOG_TV_INFO
*tv_info
;
1335 ATOM_ANALOG_TV_INFO_V1_2
*tv_info_v1_2
;
1336 ATOM_DTD_FORMAT
*dtd_timings
;
1337 int data_index
= GetIndexIntoMasterTable(DATA
, AnalogTV_Info
);
1339 u16 data_offset
, misc
;
1341 if (!atom_parse_data_header(mode_info
->atom_context
, data_index
, NULL
,
1342 &frev
, &crev
, &data_offset
))
1347 tv_info
= (ATOM_ANALOG_TV_INFO
*)(mode_info
->atom_context
->bios
+ data_offset
);
1348 if (index
>= MAX_SUPPORTED_TV_TIMING
)
1351 mode
->crtc_htotal
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_Total
);
1352 mode
->crtc_hdisplay
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_Disp
);
1353 mode
->crtc_hsync_start
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_SyncStart
);
1354 mode
->crtc_hsync_end
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_SyncStart
) +
1355 le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_SyncWidth
);
1357 mode
->crtc_vtotal
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_Total
);
1358 mode
->crtc_vdisplay
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_Disp
);
1359 mode
->crtc_vsync_start
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_SyncStart
);
1360 mode
->crtc_vsync_end
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_SyncStart
) +
1361 le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_SyncWidth
);
1364 misc
= le16_to_cpu(tv_info
->aModeTimings
[index
].susModeMiscInfo
.usAccess
);
1365 if (misc
& ATOM_VSYNC_POLARITY
)
1366 mode
->flags
|= DRM_MODE_FLAG_NVSYNC
;
1367 if (misc
& ATOM_HSYNC_POLARITY
)
1368 mode
->flags
|= DRM_MODE_FLAG_NHSYNC
;
1369 if (misc
& ATOM_COMPOSITESYNC
)
1370 mode
->flags
|= DRM_MODE_FLAG_CSYNC
;
1371 if (misc
& ATOM_INTERLACE
)
1372 mode
->flags
|= DRM_MODE_FLAG_INTERLACE
;
1373 if (misc
& ATOM_DOUBLE_CLOCK_MODE
)
1374 mode
->flags
|= DRM_MODE_FLAG_DBLSCAN
;
1376 mode
->clock
= le16_to_cpu(tv_info
->aModeTimings
[index
].usPixelClock
) * 10;
1379 /* PAL timings appear to have wrong values for totals */
1380 mode
->crtc_htotal
-= 1;
1381 mode
->crtc_vtotal
-= 1;
1385 tv_info_v1_2
= (ATOM_ANALOG_TV_INFO_V1_2
*)(mode_info
->atom_context
->bios
+ data_offset
);
1386 if (index
>= MAX_SUPPORTED_TV_TIMING_V1_2
)
1389 dtd_timings
= &tv_info_v1_2
->aModeTimings
[index
];
1390 mode
->crtc_htotal
= le16_to_cpu(dtd_timings
->usHActive
) +
1391 le16_to_cpu(dtd_timings
->usHBlanking_Time
);
1392 mode
->crtc_hdisplay
= le16_to_cpu(dtd_timings
->usHActive
);
1393 mode
->crtc_hsync_start
= le16_to_cpu(dtd_timings
->usHActive
) +
1394 le16_to_cpu(dtd_timings
->usHSyncOffset
);
1395 mode
->crtc_hsync_end
= mode
->crtc_hsync_start
+
1396 le16_to_cpu(dtd_timings
->usHSyncWidth
);
1398 mode
->crtc_vtotal
= le16_to_cpu(dtd_timings
->usVActive
) +
1399 le16_to_cpu(dtd_timings
->usVBlanking_Time
);
1400 mode
->crtc_vdisplay
= le16_to_cpu(dtd_timings
->usVActive
);
1401 mode
->crtc_vsync_start
= le16_to_cpu(dtd_timings
->usVActive
) +
1402 le16_to_cpu(dtd_timings
->usVSyncOffset
);
1403 mode
->crtc_vsync_end
= mode
->crtc_vsync_start
+
1404 le16_to_cpu(dtd_timings
->usVSyncWidth
);
1407 misc
= le16_to_cpu(dtd_timings
->susModeMiscInfo
.usAccess
);
1408 if (misc
& ATOM_VSYNC_POLARITY
)
1409 mode
->flags
|= DRM_MODE_FLAG_NVSYNC
;
1410 if (misc
& ATOM_HSYNC_POLARITY
)
1411 mode
->flags
|= DRM_MODE_FLAG_NHSYNC
;
1412 if (misc
& ATOM_COMPOSITESYNC
)
1413 mode
->flags
|= DRM_MODE_FLAG_CSYNC
;
1414 if (misc
& ATOM_INTERLACE
)
1415 mode
->flags
|= DRM_MODE_FLAG_INTERLACE
;
1416 if (misc
& ATOM_DOUBLE_CLOCK_MODE
)
1417 mode
->flags
|= DRM_MODE_FLAG_DBLSCAN
;
1419 mode
->clock
= le16_to_cpu(dtd_timings
->usPixClk
) * 10;
1426 radeon_atombios_get_tv_info(struct radeon_device
*rdev
)
1428 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1429 int index
= GetIndexIntoMasterTable(DATA
, AnalogTV_Info
);
1430 uint16_t data_offset
;
1432 struct _ATOM_ANALOG_TV_INFO
*tv_info
;
1433 enum radeon_tv_std tv_std
= TV_STD_NTSC
;
1435 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1436 &frev
, &crev
, &data_offset
)) {
1438 tv_info
= (struct _ATOM_ANALOG_TV_INFO
*)
1439 (mode_info
->atom_context
->bios
+ data_offset
);
1441 switch (tv_info
->ucTV_BootUpDefaultStandard
) {
1443 tv_std
= TV_STD_NTSC
;
1444 DRM_INFO("Default TV standard: NTSC\n");
1447 tv_std
= TV_STD_NTSC_J
;
1448 DRM_INFO("Default TV standard: NTSC-J\n");
1451 tv_std
= TV_STD_PAL
;
1452 DRM_INFO("Default TV standard: PAL\n");
1455 tv_std
= TV_STD_PAL_M
;
1456 DRM_INFO("Default TV standard: PAL-M\n");
1459 tv_std
= TV_STD_PAL_N
;
1460 DRM_INFO("Default TV standard: PAL-N\n");
1463 tv_std
= TV_STD_PAL_CN
;
1464 DRM_INFO("Default TV standard: PAL-CN\n");
1467 tv_std
= TV_STD_PAL_60
;
1468 DRM_INFO("Default TV standard: PAL-60\n");
1471 tv_std
= TV_STD_SECAM
;
1472 DRM_INFO("Default TV standard: SECAM\n");
1475 tv_std
= TV_STD_NTSC
;
1476 DRM_INFO("Unknown TV standard; defaulting to NTSC\n");
1483 struct radeon_encoder_tv_dac
*
1484 radeon_atombios_get_tv_dac_info(struct radeon_encoder
*encoder
)
1486 struct drm_device
*dev
= encoder
->base
.dev
;
1487 struct radeon_device
*rdev
= dev
->dev_private
;
1488 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1489 int index
= GetIndexIntoMasterTable(DATA
, CompassionateData
);
1490 uint16_t data_offset
;
1491 struct _COMPASSIONATE_DATA
*dac_info
;
1494 struct radeon_encoder_tv_dac
*tv_dac
= NULL
;
1496 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1497 &frev
, &crev
, &data_offset
)) {
1499 dac_info
= (struct _COMPASSIONATE_DATA
*)
1500 (mode_info
->atom_context
->bios
+ data_offset
);
1502 tv_dac
= kzalloc(sizeof(struct radeon_encoder_tv_dac
), GFP_KERNEL
);
1507 bg
= dac_info
->ucDAC2_CRT2_BG_Adjustment
;
1508 dac
= dac_info
->ucDAC2_CRT2_DAC_Adjustment
;
1509 tv_dac
->ps2_tvdac_adj
= (bg
<< 16) | (dac
<< 20);
1511 bg
= dac_info
->ucDAC2_PAL_BG_Adjustment
;
1512 dac
= dac_info
->ucDAC2_PAL_DAC_Adjustment
;
1513 tv_dac
->pal_tvdac_adj
= (bg
<< 16) | (dac
<< 20);
1515 bg
= dac_info
->ucDAC2_NTSC_BG_Adjustment
;
1516 dac
= dac_info
->ucDAC2_NTSC_DAC_Adjustment
;
1517 tv_dac
->ntsc_tvdac_adj
= (bg
<< 16) | (dac
<< 20);
1519 tv_dac
->tv_std
= radeon_atombios_get_tv_info(rdev
);
1524 static const char *thermal_controller_names
[] = {
1535 static const char *pp_lib_thermal_controller_names
[] = {
1548 "adt7473 with internal",
1553 struct _ATOM_POWERPLAY_INFO info
;
1554 struct _ATOM_POWERPLAY_INFO_V2 info_2
;
1555 struct _ATOM_POWERPLAY_INFO_V3 info_3
;
1556 struct _ATOM_PPLIB_POWERPLAYTABLE info_4
;
1559 void radeon_atombios_get_power_modes(struct radeon_device
*rdev
)
1561 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1562 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
1565 u32 misc
, misc2
= 0, sclk
, mclk
;
1566 union power_info
*power_info
;
1567 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
;
1568 struct _ATOM_PPLIB_STATE
*power_state
;
1569 int num_modes
= 0, i
, j
;
1570 int state_index
= 0, mode_index
= 0;
1571 struct radeon_i2c_bus_rec i2c_bus
;
1573 rdev
->pm
.default_power_state_index
= -1;
1575 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1576 &frev
, &crev
, &data_offset
)) {
1577 power_info
= (union power_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
1579 /* add the i2c bus for thermal/fan chip */
1580 if (power_info
->info
.ucOverdriveThermalController
> 0) {
1581 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
1582 thermal_controller_names
[power_info
->info
.ucOverdriveThermalController
],
1583 power_info
->info
.ucOverdriveControllerAddress
>> 1);
1584 i2c_bus
= radeon_lookup_i2c_gpio(rdev
, power_info
->info
.ucOverdriveI2cLine
);
1585 rdev
->pm
.i2c_bus
= radeon_i2c_lookup(rdev
, &i2c_bus
);
1586 if (rdev
->pm
.i2c_bus
) {
1587 struct i2c_board_info info
= { };
1588 const char *name
= thermal_controller_names
[power_info
->info
.
1589 ucOverdriveThermalController
];
1590 info
.addr
= power_info
->info
.ucOverdriveControllerAddress
>> 1;
1591 strlcpy(info
.type
, name
, sizeof(info
.type
));
1592 i2c_new_device(&rdev
->pm
.i2c_bus
->adapter
, &info
);
1595 num_modes
= power_info
->info
.ucNumOfPowerModeEntries
;
1596 if (num_modes
> ATOM_MAX_NUMBEROF_POWER_BLOCK
)
1597 num_modes
= ATOM_MAX_NUMBEROF_POWER_BLOCK
;
1598 /* last mode is usually default, array is low to high */
1599 for (i
= 0; i
< num_modes
; i
++) {
1600 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
= VOLTAGE_NONE
;
1603 rdev
->pm
.power_state
[state_index
].num_clock_modes
= 1;
1604 rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
=
1605 le16_to_cpu(power_info
->info
.asPowerPlayInfo
[i
].usMemoryClock
);
1606 rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
=
1607 le16_to_cpu(power_info
->info
.asPowerPlayInfo
[i
].usEngineClock
);
1608 /* skip invalid modes */
1609 if ((rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
== 0) ||
1610 (rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
== 0))
1612 rdev
->pm
.power_state
[state_index
].pcie_lanes
=
1613 power_info
->info
.asPowerPlayInfo
[i
].ucNumPciELanes
;
1614 misc
= le32_to_cpu(power_info
->info
.asPowerPlayInfo
[i
].ulMiscInfo
);
1615 if ((misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT
) ||
1616 (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)) {
1617 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
1619 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.gpio
=
1620 radeon_lookup_gpio(rdev
,
1621 power_info
->info
.asPowerPlayInfo
[i
].ucVoltageDropIndex
);
1622 if (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)
1623 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
1626 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
1628 } else if (misc
& ATOM_PM_MISCINFO_PROGRAM_VOLTAGE
) {
1629 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
1631 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddc_id
=
1632 power_info
->info
.asPowerPlayInfo
[i
].ucVoltageDropIndex
;
1634 rdev
->pm
.power_state
[state_index
].flags
= RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1635 rdev
->pm
.power_state
[state_index
].misc
= misc
;
1636 /* order matters! */
1637 if (misc
& ATOM_PM_MISCINFO_POWER_SAVING_MODE
)
1638 rdev
->pm
.power_state
[state_index
].type
=
1639 POWER_STATE_TYPE_POWERSAVE
;
1640 if (misc
& ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE
)
1641 rdev
->pm
.power_state
[state_index
].type
=
1642 POWER_STATE_TYPE_BATTERY
;
1643 if (misc
& ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE
)
1644 rdev
->pm
.power_state
[state_index
].type
=
1645 POWER_STATE_TYPE_BATTERY
;
1646 if (misc
& ATOM_PM_MISCINFO_LOAD_BALANCE_EN
)
1647 rdev
->pm
.power_state
[state_index
].type
=
1648 POWER_STATE_TYPE_BALANCED
;
1649 if (misc
& ATOM_PM_MISCINFO_3D_ACCELERATION_EN
) {
1650 rdev
->pm
.power_state
[state_index
].type
=
1651 POWER_STATE_TYPE_PERFORMANCE
;
1652 rdev
->pm
.power_state
[state_index
].flags
&=
1653 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1655 if (misc
& ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE
) {
1656 rdev
->pm
.power_state
[state_index
].type
=
1657 POWER_STATE_TYPE_DEFAULT
;
1658 rdev
->pm
.default_power_state_index
= state_index
;
1659 rdev
->pm
.power_state
[state_index
].default_clock_mode
=
1660 &rdev
->pm
.power_state
[state_index
].clock_info
[0];
1661 rdev
->pm
.power_state
[state_index
].flags
&=
1662 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1663 } else if (state_index
== 0) {
1664 rdev
->pm
.power_state
[state_index
].clock_info
[0].flags
|=
1665 RADEON_PM_MODE_NO_DISPLAY
;
1670 rdev
->pm
.power_state
[state_index
].num_clock_modes
= 1;
1671 rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
=
1672 le32_to_cpu(power_info
->info_2
.asPowerPlayInfo
[i
].ulMemoryClock
);
1673 rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
=
1674 le32_to_cpu(power_info
->info_2
.asPowerPlayInfo
[i
].ulEngineClock
);
1675 /* skip invalid modes */
1676 if ((rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
== 0) ||
1677 (rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
== 0))
1679 rdev
->pm
.power_state
[state_index
].pcie_lanes
=
1680 power_info
->info_2
.asPowerPlayInfo
[i
].ucNumPciELanes
;
1681 misc
= le32_to_cpu(power_info
->info_2
.asPowerPlayInfo
[i
].ulMiscInfo
);
1682 misc2
= le32_to_cpu(power_info
->info_2
.asPowerPlayInfo
[i
].ulMiscInfo2
);
1683 if ((misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT
) ||
1684 (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)) {
1685 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
1687 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.gpio
=
1688 radeon_lookup_gpio(rdev
,
1689 power_info
->info_2
.asPowerPlayInfo
[i
].ucVoltageDropIndex
);
1690 if (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)
1691 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
1694 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
1696 } else if (misc
& ATOM_PM_MISCINFO_PROGRAM_VOLTAGE
) {
1697 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
1699 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddc_id
=
1700 power_info
->info_2
.asPowerPlayInfo
[i
].ucVoltageDropIndex
;
1702 rdev
->pm
.power_state
[state_index
].flags
= RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1703 rdev
->pm
.power_state
[state_index
].misc
= misc
;
1704 rdev
->pm
.power_state
[state_index
].misc2
= misc2
;
1705 /* order matters! */
1706 if (misc
& ATOM_PM_MISCINFO_POWER_SAVING_MODE
)
1707 rdev
->pm
.power_state
[state_index
].type
=
1708 POWER_STATE_TYPE_POWERSAVE
;
1709 if (misc
& ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE
)
1710 rdev
->pm
.power_state
[state_index
].type
=
1711 POWER_STATE_TYPE_BATTERY
;
1712 if (misc
& ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE
)
1713 rdev
->pm
.power_state
[state_index
].type
=
1714 POWER_STATE_TYPE_BATTERY
;
1715 if (misc
& ATOM_PM_MISCINFO_LOAD_BALANCE_EN
)
1716 rdev
->pm
.power_state
[state_index
].type
=
1717 POWER_STATE_TYPE_BALANCED
;
1718 if (misc
& ATOM_PM_MISCINFO_3D_ACCELERATION_EN
) {
1719 rdev
->pm
.power_state
[state_index
].type
=
1720 POWER_STATE_TYPE_PERFORMANCE
;
1721 rdev
->pm
.power_state
[state_index
].flags
&=
1722 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1724 if (misc2
& ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE
)
1725 rdev
->pm
.power_state
[state_index
].type
=
1726 POWER_STATE_TYPE_BALANCED
;
1727 if (misc2
& ATOM_PM_MISCINFO2_MULTI_DISPLAY_SUPPORT
)
1728 rdev
->pm
.power_state
[state_index
].flags
&=
1729 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1730 if (misc
& ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE
) {
1731 rdev
->pm
.power_state
[state_index
].type
=
1732 POWER_STATE_TYPE_DEFAULT
;
1733 rdev
->pm
.default_power_state_index
= state_index
;
1734 rdev
->pm
.power_state
[state_index
].default_clock_mode
=
1735 &rdev
->pm
.power_state
[state_index
].clock_info
[0];
1736 rdev
->pm
.power_state
[state_index
].flags
&=
1737 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1738 } else if (state_index
== 0) {
1739 rdev
->pm
.power_state
[state_index
].clock_info
[0].flags
|=
1740 RADEON_PM_MODE_NO_DISPLAY
;
1745 rdev
->pm
.power_state
[state_index
].num_clock_modes
= 1;
1746 rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
=
1747 le32_to_cpu(power_info
->info_3
.asPowerPlayInfo
[i
].ulMemoryClock
);
1748 rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
=
1749 le32_to_cpu(power_info
->info_3
.asPowerPlayInfo
[i
].ulEngineClock
);
1750 /* skip invalid modes */
1751 if ((rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
== 0) ||
1752 (rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
== 0))
1754 rdev
->pm
.power_state
[state_index
].pcie_lanes
=
1755 power_info
->info_3
.asPowerPlayInfo
[i
].ucNumPciELanes
;
1756 misc
= le32_to_cpu(power_info
->info_3
.asPowerPlayInfo
[i
].ulMiscInfo
);
1757 misc2
= le32_to_cpu(power_info
->info_3
.asPowerPlayInfo
[i
].ulMiscInfo2
);
1758 if ((misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT
) ||
1759 (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)) {
1760 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
1762 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.gpio
=
1763 radeon_lookup_gpio(rdev
,
1764 power_info
->info_3
.asPowerPlayInfo
[i
].ucVoltageDropIndex
);
1765 if (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)
1766 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
1769 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
1771 } else if (misc
& ATOM_PM_MISCINFO_PROGRAM_VOLTAGE
) {
1772 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
1774 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddc_id
=
1775 power_info
->info_3
.asPowerPlayInfo
[i
].ucVoltageDropIndex
;
1776 if (misc2
& ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN
) {
1777 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddci_enabled
=
1779 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddci_id
=
1780 power_info
->info_3
.asPowerPlayInfo
[i
].ucVDDCI_VoltageDropIndex
;
1783 rdev
->pm
.power_state
[state_index
].flags
= RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1784 rdev
->pm
.power_state
[state_index
].misc
= misc
;
1785 rdev
->pm
.power_state
[state_index
].misc2
= misc2
;
1786 /* order matters! */
1787 if (misc
& ATOM_PM_MISCINFO_POWER_SAVING_MODE
)
1788 rdev
->pm
.power_state
[state_index
].type
=
1789 POWER_STATE_TYPE_POWERSAVE
;
1790 if (misc
& ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE
)
1791 rdev
->pm
.power_state
[state_index
].type
=
1792 POWER_STATE_TYPE_BATTERY
;
1793 if (misc
& ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE
)
1794 rdev
->pm
.power_state
[state_index
].type
=
1795 POWER_STATE_TYPE_BATTERY
;
1796 if (misc
& ATOM_PM_MISCINFO_LOAD_BALANCE_EN
)
1797 rdev
->pm
.power_state
[state_index
].type
=
1798 POWER_STATE_TYPE_BALANCED
;
1799 if (misc
& ATOM_PM_MISCINFO_3D_ACCELERATION_EN
) {
1800 rdev
->pm
.power_state
[state_index
].type
=
1801 POWER_STATE_TYPE_PERFORMANCE
;
1802 rdev
->pm
.power_state
[state_index
].flags
&=
1803 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1805 if (misc2
& ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE
)
1806 rdev
->pm
.power_state
[state_index
].type
=
1807 POWER_STATE_TYPE_BALANCED
;
1808 if (misc
& ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE
) {
1809 rdev
->pm
.power_state
[state_index
].type
=
1810 POWER_STATE_TYPE_DEFAULT
;
1811 rdev
->pm
.default_power_state_index
= state_index
;
1812 rdev
->pm
.power_state
[state_index
].default_clock_mode
=
1813 &rdev
->pm
.power_state
[state_index
].clock_info
[0];
1814 } else if (state_index
== 0) {
1815 rdev
->pm
.power_state
[state_index
].clock_info
[0].flags
|=
1816 RADEON_PM_MODE_NO_DISPLAY
;
1822 /* last mode is usually default */
1823 if (rdev
->pm
.default_power_state_index
== -1) {
1824 rdev
->pm
.power_state
[state_index
- 1].type
=
1825 POWER_STATE_TYPE_DEFAULT
;
1826 rdev
->pm
.default_power_state_index
= state_index
- 1;
1827 rdev
->pm
.power_state
[state_index
- 1].default_clock_mode
=
1828 &rdev
->pm
.power_state
[state_index
- 1].clock_info
[0];
1829 rdev
->pm
.power_state
[state_index
].flags
&=
1830 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1831 rdev
->pm
.power_state
[state_index
].misc
= 0;
1832 rdev
->pm
.power_state
[state_index
].misc2
= 0;
1835 int fw_index
= GetIndexIntoMasterTable(DATA
, FirmwareInfo
);
1836 uint8_t fw_frev
, fw_crev
;
1837 uint16_t fw_data_offset
, vddc
= 0;
1838 union firmware_info
*firmware_info
;
1839 ATOM_PPLIB_THERMALCONTROLLER
*controller
= &power_info
->info_4
.sThermalController
;
1841 if (atom_parse_data_header(mode_info
->atom_context
, fw_index
, NULL
,
1842 &fw_frev
, &fw_crev
, &fw_data_offset
)) {
1844 (union firmware_info
*)(mode_info
->atom_context
->bios
+
1846 vddc
= firmware_info
->info_14
.usBootUpVDDCVoltage
;
1849 /* add the i2c bus for thermal/fan chip */
1850 if (controller
->ucType
> 0) {
1851 if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_RV6xx
) {
1852 DRM_INFO("Internal thermal controller %s fan control\n",
1853 (controller
->ucFanParameters
&
1854 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
1855 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_RV6XX
;
1856 } else if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_RV770
) {
1857 DRM_INFO("Internal thermal controller %s fan control\n",
1858 (controller
->ucFanParameters
&
1859 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
1860 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_RV770
;
1861 } else if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_EVERGREEN
) {
1862 DRM_INFO("Internal thermal controller %s fan control\n",
1863 (controller
->ucFanParameters
&
1864 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
1865 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_EVERGREEN
;
1866 } else if ((controller
->ucType
==
1867 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO
) ||
1868 (controller
->ucType
==
1869 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL
)) {
1870 DRM_INFO("Special thermal controller config\n");
1872 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
1873 pp_lib_thermal_controller_names
[controller
->ucType
],
1874 controller
->ucI2cAddress
>> 1,
1875 (controller
->ucFanParameters
&
1876 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
1877 i2c_bus
= radeon_lookup_i2c_gpio(rdev
, controller
->ucI2cLine
);
1878 rdev
->pm
.i2c_bus
= radeon_i2c_lookup(rdev
, &i2c_bus
);
1879 if (rdev
->pm
.i2c_bus
) {
1880 struct i2c_board_info info
= { };
1881 const char *name
= pp_lib_thermal_controller_names
[controller
->ucType
];
1882 info
.addr
= controller
->ucI2cAddress
>> 1;
1883 strlcpy(info
.type
, name
, sizeof(info
.type
));
1884 i2c_new_device(&rdev
->pm
.i2c_bus
->adapter
, &info
);
1889 /* first mode is usually default, followed by low to high */
1890 for (i
= 0; i
< power_info
->info_4
.ucNumStates
; i
++) {
1892 power_state
= (struct _ATOM_PPLIB_STATE
*)
1893 (mode_info
->atom_context
->bios
+
1895 le16_to_cpu(power_info
->info_4
.usStateArrayOffset
) +
1896 i
* power_info
->info_4
.ucStateEntrySize
);
1897 non_clock_info
= (struct _ATOM_PPLIB_NONCLOCK_INFO
*)
1898 (mode_info
->atom_context
->bios
+
1900 le16_to_cpu(power_info
->info_4
.usNonClockInfoArrayOffset
) +
1901 (power_state
->ucNonClockStateIndex
*
1902 power_info
->info_4
.ucNonClockSize
));
1903 for (j
= 0; j
< (power_info
->info_4
.ucStateEntrySize
- 1); j
++) {
1904 if (rdev
->flags
& RADEON_IS_IGP
) {
1905 struct _ATOM_PPLIB_RS780_CLOCK_INFO
*clock_info
=
1906 (struct _ATOM_PPLIB_RS780_CLOCK_INFO
*)
1907 (mode_info
->atom_context
->bios
+
1909 le16_to_cpu(power_info
->info_4
.usClockInfoArrayOffset
) +
1910 (power_state
->ucClockStateIndices
[j
] *
1911 power_info
->info_4
.ucClockInfoSize
));
1912 sclk
= le16_to_cpu(clock_info
->usLowEngineClockLow
);
1913 sclk
|= clock_info
->ucLowEngineClockHigh
<< 16;
1914 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
= sclk
;
1915 /* skip invalid modes */
1916 if (rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
== 0)
1918 /* voltage works differently on IGPs */
1920 } else if (ASIC_IS_DCE4(rdev
)) {
1921 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO
*clock_info
=
1922 (struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO
*)
1923 (mode_info
->atom_context
->bios
+
1925 le16_to_cpu(power_info
->info_4
.usClockInfoArrayOffset
) +
1926 (power_state
->ucClockStateIndices
[j
] *
1927 power_info
->info_4
.ucClockInfoSize
));
1928 sclk
= le16_to_cpu(clock_info
->usEngineClockLow
);
1929 sclk
|= clock_info
->ucEngineClockHigh
<< 16;
1930 mclk
= le16_to_cpu(clock_info
->usMemoryClockLow
);
1931 mclk
|= clock_info
->ucMemoryClockHigh
<< 16;
1932 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].mclk
= mclk
;
1933 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
= sclk
;
1934 /* skip invalid modes */
1935 if ((rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].mclk
== 0) ||
1936 (rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
== 0))
1938 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.type
=
1940 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.voltage
=
1945 struct _ATOM_PPLIB_R600_CLOCK_INFO
*clock_info
=
1946 (struct _ATOM_PPLIB_R600_CLOCK_INFO
*)
1947 (mode_info
->atom_context
->bios
+
1949 le16_to_cpu(power_info
->info_4
.usClockInfoArrayOffset
) +
1950 (power_state
->ucClockStateIndices
[j
] *
1951 power_info
->info_4
.ucClockInfoSize
));
1952 sclk
= le16_to_cpu(clock_info
->usEngineClockLow
);
1953 sclk
|= clock_info
->ucEngineClockHigh
<< 16;
1954 mclk
= le16_to_cpu(clock_info
->usMemoryClockLow
);
1955 mclk
|= clock_info
->ucMemoryClockHigh
<< 16;
1956 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].mclk
= mclk
;
1957 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
= sclk
;
1958 /* skip invalid modes */
1959 if ((rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].mclk
== 0) ||
1960 (rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
== 0))
1962 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.type
=
1964 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.voltage
=
1969 rdev
->pm
.power_state
[state_index
].num_clock_modes
= mode_index
;
1971 misc
= le32_to_cpu(non_clock_info
->ulCapsAndSettings
);
1972 misc2
= le16_to_cpu(non_clock_info
->usClassification
);
1973 rdev
->pm
.power_state
[state_index
].misc
= misc
;
1974 rdev
->pm
.power_state
[state_index
].misc2
= misc2
;
1975 rdev
->pm
.power_state
[state_index
].pcie_lanes
=
1976 ((misc
& ATOM_PPLIB_PCIE_LINK_WIDTH_MASK
) >>
1977 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT
) + 1;
1978 switch (misc2
& ATOM_PPLIB_CLASSIFICATION_UI_MASK
) {
1979 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY
:
1980 rdev
->pm
.power_state
[state_index
].type
=
1981 POWER_STATE_TYPE_BATTERY
;
1983 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED
:
1984 rdev
->pm
.power_state
[state_index
].type
=
1985 POWER_STATE_TYPE_BALANCED
;
1987 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE
:
1988 rdev
->pm
.power_state
[state_index
].type
=
1989 POWER_STATE_TYPE_PERFORMANCE
;
1992 rdev
->pm
.power_state
[state_index
].flags
= 0;
1993 if (misc
& ATOM_PPLIB_SINGLE_DISPLAY_ONLY
)
1994 rdev
->pm
.power_state
[state_index
].flags
|=
1995 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
1996 if (misc2
& ATOM_PPLIB_CLASSIFICATION_BOOT
) {
1997 rdev
->pm
.power_state
[state_index
].type
=
1998 POWER_STATE_TYPE_DEFAULT
;
1999 rdev
->pm
.default_power_state_index
= state_index
;
2000 rdev
->pm
.power_state
[state_index
].default_clock_mode
=
2001 &rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
- 1];
2002 /* patch the table values with the default slck/mclk from firmware info */
2003 for (j
= 0; j
< mode_index
; j
++) {
2004 rdev
->pm
.power_state
[state_index
].clock_info
[j
].mclk
=
2005 rdev
->clock
.default_mclk
;
2006 rdev
->pm
.power_state
[state_index
].clock_info
[j
].sclk
=
2007 rdev
->clock
.default_sclk
;
2009 rdev
->pm
.power_state
[state_index
].clock_info
[j
].voltage
.voltage
=
2016 /* if multiple clock modes, mark the lowest as no display */
2017 for (i
= 0; i
< state_index
; i
++) {
2018 if (rdev
->pm
.power_state
[i
].num_clock_modes
> 1)
2019 rdev
->pm
.power_state
[i
].clock_info
[0].flags
|=
2020 RADEON_PM_MODE_NO_DISPLAY
;
2022 /* first mode is usually default */
2023 if (rdev
->pm
.default_power_state_index
== -1) {
2024 rdev
->pm
.power_state
[0].type
=
2025 POWER_STATE_TYPE_DEFAULT
;
2026 rdev
->pm
.default_power_state_index
= 0;
2027 rdev
->pm
.power_state
[0].default_clock_mode
=
2028 &rdev
->pm
.power_state
[0].clock_info
[0];
2032 /* add the default mode */
2033 rdev
->pm
.power_state
[state_index
].type
=
2034 POWER_STATE_TYPE_DEFAULT
;
2035 rdev
->pm
.power_state
[state_index
].num_clock_modes
= 1;
2036 rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
= rdev
->clock
.default_mclk
;
2037 rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
= rdev
->clock
.default_sclk
;
2038 rdev
->pm
.power_state
[state_index
].default_clock_mode
=
2039 &rdev
->pm
.power_state
[state_index
].clock_info
[0];
2040 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
= VOLTAGE_NONE
;
2041 rdev
->pm
.power_state
[state_index
].pcie_lanes
= 16;
2042 rdev
->pm
.default_power_state_index
= state_index
;
2043 rdev
->pm
.power_state
[state_index
].flags
= 0;
2047 rdev
->pm
.num_power_states
= state_index
;
2049 rdev
->pm
.current_power_state_index
= rdev
->pm
.default_power_state_index
;
2050 rdev
->pm
.current_clock_mode_index
= 0;
2051 rdev
->pm
.current_vddc
= rdev
->pm
.power_state
[rdev
->pm
.default_power_state_index
].clock_info
[0].voltage
.voltage
;
2054 void radeon_atom_set_clock_gating(struct radeon_device
*rdev
, int enable
)
2056 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args
;
2057 int index
= GetIndexIntoMasterTable(COMMAND
, DynamicClockGating
);
2059 args
.ucEnable
= enable
;
2061 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2064 uint32_t radeon_atom_get_engine_clock(struct radeon_device
*rdev
)
2066 GET_ENGINE_CLOCK_PS_ALLOCATION args
;
2067 int index
= GetIndexIntoMasterTable(COMMAND
, GetEngineClock
);
2069 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2070 return args
.ulReturnEngineClock
;
2073 uint32_t radeon_atom_get_memory_clock(struct radeon_device
*rdev
)
2075 GET_MEMORY_CLOCK_PS_ALLOCATION args
;
2076 int index
= GetIndexIntoMasterTable(COMMAND
, GetMemoryClock
);
2078 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2079 return args
.ulReturnMemoryClock
;
2082 void radeon_atom_set_engine_clock(struct radeon_device
*rdev
,
2085 SET_ENGINE_CLOCK_PS_ALLOCATION args
;
2086 int index
= GetIndexIntoMasterTable(COMMAND
, SetEngineClock
);
2088 args
.ulTargetEngineClock
= eng_clock
; /* 10 khz */
2090 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2093 void radeon_atom_set_memory_clock(struct radeon_device
*rdev
,
2096 SET_MEMORY_CLOCK_PS_ALLOCATION args
;
2097 int index
= GetIndexIntoMasterTable(COMMAND
, SetMemoryClock
);
2099 if (rdev
->flags
& RADEON_IS_IGP
)
2102 args
.ulTargetMemoryClock
= mem_clock
; /* 10 khz */
2104 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2108 struct _SET_VOLTAGE_PS_ALLOCATION alloc
;
2109 struct _SET_VOLTAGE_PARAMETERS v1
;
2110 struct _SET_VOLTAGE_PARAMETERS_V2 v2
;
2113 void radeon_atom_set_voltage(struct radeon_device
*rdev
, u16 level
)
2115 union set_voltage args
;
2116 int index
= GetIndexIntoMasterTable(COMMAND
, SetVoltage
);
2117 u8 frev
, crev
, volt_index
= level
;
2119 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
2124 args
.v1
.ucVoltageType
= SET_VOLTAGE_TYPE_ASIC_VDDC
;
2125 args
.v1
.ucVoltageMode
= SET_ASIC_VOLTAGE_MODE_ALL_SOURCE
;
2126 args
.v1
.ucVoltageIndex
= volt_index
;
2129 args
.v2
.ucVoltageType
= SET_VOLTAGE_TYPE_ASIC_VDDC
;
2130 args
.v2
.ucVoltageMode
= SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE
;
2131 args
.v2
.usVoltageLevel
= cpu_to_le16(level
);
2134 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
2138 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2143 void radeon_atom_initialize_bios_scratch_regs(struct drm_device
*dev
)
2145 struct radeon_device
*rdev
= dev
->dev_private
;
2146 uint32_t bios_2_scratch
, bios_6_scratch
;
2148 if (rdev
->family
>= CHIP_R600
) {
2149 bios_2_scratch
= RREG32(R600_BIOS_2_SCRATCH
);
2150 bios_6_scratch
= RREG32(R600_BIOS_6_SCRATCH
);
2152 bios_2_scratch
= RREG32(RADEON_BIOS_2_SCRATCH
);
2153 bios_6_scratch
= RREG32(RADEON_BIOS_6_SCRATCH
);
2156 /* let the bios control the backlight */
2157 bios_2_scratch
&= ~ATOM_S2_VRI_BRIGHT_ENABLE
;
2159 /* tell the bios not to handle mode switching */
2160 bios_6_scratch
|= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH
| ATOM_S6_ACC_MODE
);
2162 if (rdev
->family
>= CHIP_R600
) {
2163 WREG32(R600_BIOS_2_SCRATCH
, bios_2_scratch
);
2164 WREG32(R600_BIOS_6_SCRATCH
, bios_6_scratch
);
2166 WREG32(RADEON_BIOS_2_SCRATCH
, bios_2_scratch
);
2167 WREG32(RADEON_BIOS_6_SCRATCH
, bios_6_scratch
);
2172 void radeon_save_bios_scratch_regs(struct radeon_device
*rdev
)
2174 uint32_t scratch_reg
;
2177 if (rdev
->family
>= CHIP_R600
)
2178 scratch_reg
= R600_BIOS_0_SCRATCH
;
2180 scratch_reg
= RADEON_BIOS_0_SCRATCH
;
2182 for (i
= 0; i
< RADEON_BIOS_NUM_SCRATCH
; i
++)
2183 rdev
->bios_scratch
[i
] = RREG32(scratch_reg
+ (i
* 4));
2186 void radeon_restore_bios_scratch_regs(struct radeon_device
*rdev
)
2188 uint32_t scratch_reg
;
2191 if (rdev
->family
>= CHIP_R600
)
2192 scratch_reg
= R600_BIOS_0_SCRATCH
;
2194 scratch_reg
= RADEON_BIOS_0_SCRATCH
;
2196 for (i
= 0; i
< RADEON_BIOS_NUM_SCRATCH
; i
++)
2197 WREG32(scratch_reg
+ (i
* 4), rdev
->bios_scratch
[i
]);
2200 void radeon_atom_output_lock(struct drm_encoder
*encoder
, bool lock
)
2202 struct drm_device
*dev
= encoder
->dev
;
2203 struct radeon_device
*rdev
= dev
->dev_private
;
2204 uint32_t bios_6_scratch
;
2206 if (rdev
->family
>= CHIP_R600
)
2207 bios_6_scratch
= RREG32(R600_BIOS_6_SCRATCH
);
2209 bios_6_scratch
= RREG32(RADEON_BIOS_6_SCRATCH
);
2212 bios_6_scratch
|= ATOM_S6_CRITICAL_STATE
;
2214 bios_6_scratch
&= ~ATOM_S6_CRITICAL_STATE
;
2216 if (rdev
->family
>= CHIP_R600
)
2217 WREG32(R600_BIOS_6_SCRATCH
, bios_6_scratch
);
2219 WREG32(RADEON_BIOS_6_SCRATCH
, bios_6_scratch
);
2222 /* at some point we may want to break this out into individual functions */
2224 radeon_atombios_connected_scratch_regs(struct drm_connector
*connector
,
2225 struct drm_encoder
*encoder
,
2228 struct drm_device
*dev
= connector
->dev
;
2229 struct radeon_device
*rdev
= dev
->dev_private
;
2230 struct radeon_connector
*radeon_connector
=
2231 to_radeon_connector(connector
);
2232 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
2233 uint32_t bios_0_scratch
, bios_3_scratch
, bios_6_scratch
;
2235 if (rdev
->family
>= CHIP_R600
) {
2236 bios_0_scratch
= RREG32(R600_BIOS_0_SCRATCH
);
2237 bios_3_scratch
= RREG32(R600_BIOS_3_SCRATCH
);
2238 bios_6_scratch
= RREG32(R600_BIOS_6_SCRATCH
);
2240 bios_0_scratch
= RREG32(RADEON_BIOS_0_SCRATCH
);
2241 bios_3_scratch
= RREG32(RADEON_BIOS_3_SCRATCH
);
2242 bios_6_scratch
= RREG32(RADEON_BIOS_6_SCRATCH
);
2245 if ((radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) &&
2246 (radeon_connector
->devices
& ATOM_DEVICE_TV1_SUPPORT
)) {
2248 DRM_DEBUG_KMS("TV1 connected\n");
2249 bios_3_scratch
|= ATOM_S3_TV1_ACTIVE
;
2250 bios_6_scratch
|= ATOM_S6_ACC_REQ_TV1
;
2252 DRM_DEBUG_KMS("TV1 disconnected\n");
2253 bios_0_scratch
&= ~ATOM_S0_TV1_MASK
;
2254 bios_3_scratch
&= ~ATOM_S3_TV1_ACTIVE
;
2255 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_TV1
;
2258 if ((radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) &&
2259 (radeon_connector
->devices
& ATOM_DEVICE_CV_SUPPORT
)) {
2261 DRM_DEBUG_KMS("CV connected\n");
2262 bios_3_scratch
|= ATOM_S3_CV_ACTIVE
;
2263 bios_6_scratch
|= ATOM_S6_ACC_REQ_CV
;
2265 DRM_DEBUG_KMS("CV disconnected\n");
2266 bios_0_scratch
&= ~ATOM_S0_CV_MASK
;
2267 bios_3_scratch
&= ~ATOM_S3_CV_ACTIVE
;
2268 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_CV
;
2271 if ((radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) &&
2272 (radeon_connector
->devices
& ATOM_DEVICE_LCD1_SUPPORT
)) {
2274 DRM_DEBUG_KMS("LCD1 connected\n");
2275 bios_0_scratch
|= ATOM_S0_LCD1
;
2276 bios_3_scratch
|= ATOM_S3_LCD1_ACTIVE
;
2277 bios_6_scratch
|= ATOM_S6_ACC_REQ_LCD1
;
2279 DRM_DEBUG_KMS("LCD1 disconnected\n");
2280 bios_0_scratch
&= ~ATOM_S0_LCD1
;
2281 bios_3_scratch
&= ~ATOM_S3_LCD1_ACTIVE
;
2282 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_LCD1
;
2285 if ((radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) &&
2286 (radeon_connector
->devices
& ATOM_DEVICE_CRT1_SUPPORT
)) {
2288 DRM_DEBUG_KMS("CRT1 connected\n");
2289 bios_0_scratch
|= ATOM_S0_CRT1_COLOR
;
2290 bios_3_scratch
|= ATOM_S3_CRT1_ACTIVE
;
2291 bios_6_scratch
|= ATOM_S6_ACC_REQ_CRT1
;
2293 DRM_DEBUG_KMS("CRT1 disconnected\n");
2294 bios_0_scratch
&= ~ATOM_S0_CRT1_MASK
;
2295 bios_3_scratch
&= ~ATOM_S3_CRT1_ACTIVE
;
2296 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_CRT1
;
2299 if ((radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) &&
2300 (radeon_connector
->devices
& ATOM_DEVICE_CRT2_SUPPORT
)) {
2302 DRM_DEBUG_KMS("CRT2 connected\n");
2303 bios_0_scratch
|= ATOM_S0_CRT2_COLOR
;
2304 bios_3_scratch
|= ATOM_S3_CRT2_ACTIVE
;
2305 bios_6_scratch
|= ATOM_S6_ACC_REQ_CRT2
;
2307 DRM_DEBUG_KMS("CRT2 disconnected\n");
2308 bios_0_scratch
&= ~ATOM_S0_CRT2_MASK
;
2309 bios_3_scratch
&= ~ATOM_S3_CRT2_ACTIVE
;
2310 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_CRT2
;
2313 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP1_SUPPORT
) &&
2314 (radeon_connector
->devices
& ATOM_DEVICE_DFP1_SUPPORT
)) {
2316 DRM_DEBUG_KMS("DFP1 connected\n");
2317 bios_0_scratch
|= ATOM_S0_DFP1
;
2318 bios_3_scratch
|= ATOM_S3_DFP1_ACTIVE
;
2319 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP1
;
2321 DRM_DEBUG_KMS("DFP1 disconnected\n");
2322 bios_0_scratch
&= ~ATOM_S0_DFP1
;
2323 bios_3_scratch
&= ~ATOM_S3_DFP1_ACTIVE
;
2324 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP1
;
2327 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
) &&
2328 (radeon_connector
->devices
& ATOM_DEVICE_DFP2_SUPPORT
)) {
2330 DRM_DEBUG_KMS("DFP2 connected\n");
2331 bios_0_scratch
|= ATOM_S0_DFP2
;
2332 bios_3_scratch
|= ATOM_S3_DFP2_ACTIVE
;
2333 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP2
;
2335 DRM_DEBUG_KMS("DFP2 disconnected\n");
2336 bios_0_scratch
&= ~ATOM_S0_DFP2
;
2337 bios_3_scratch
&= ~ATOM_S3_DFP2_ACTIVE
;
2338 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP2
;
2341 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP3_SUPPORT
) &&
2342 (radeon_connector
->devices
& ATOM_DEVICE_DFP3_SUPPORT
)) {
2344 DRM_DEBUG_KMS("DFP3 connected\n");
2345 bios_0_scratch
|= ATOM_S0_DFP3
;
2346 bios_3_scratch
|= ATOM_S3_DFP3_ACTIVE
;
2347 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP3
;
2349 DRM_DEBUG_KMS("DFP3 disconnected\n");
2350 bios_0_scratch
&= ~ATOM_S0_DFP3
;
2351 bios_3_scratch
&= ~ATOM_S3_DFP3_ACTIVE
;
2352 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP3
;
2355 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP4_SUPPORT
) &&
2356 (radeon_connector
->devices
& ATOM_DEVICE_DFP4_SUPPORT
)) {
2358 DRM_DEBUG_KMS("DFP4 connected\n");
2359 bios_0_scratch
|= ATOM_S0_DFP4
;
2360 bios_3_scratch
|= ATOM_S3_DFP4_ACTIVE
;
2361 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP4
;
2363 DRM_DEBUG_KMS("DFP4 disconnected\n");
2364 bios_0_scratch
&= ~ATOM_S0_DFP4
;
2365 bios_3_scratch
&= ~ATOM_S3_DFP4_ACTIVE
;
2366 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP4
;
2369 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP5_SUPPORT
) &&
2370 (radeon_connector
->devices
& ATOM_DEVICE_DFP5_SUPPORT
)) {
2372 DRM_DEBUG_KMS("DFP5 connected\n");
2373 bios_0_scratch
|= ATOM_S0_DFP5
;
2374 bios_3_scratch
|= ATOM_S3_DFP5_ACTIVE
;
2375 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP5
;
2377 DRM_DEBUG_KMS("DFP5 disconnected\n");
2378 bios_0_scratch
&= ~ATOM_S0_DFP5
;
2379 bios_3_scratch
&= ~ATOM_S3_DFP5_ACTIVE
;
2380 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP5
;
2384 if (rdev
->family
>= CHIP_R600
) {
2385 WREG32(R600_BIOS_0_SCRATCH
, bios_0_scratch
);
2386 WREG32(R600_BIOS_3_SCRATCH
, bios_3_scratch
);
2387 WREG32(R600_BIOS_6_SCRATCH
, bios_6_scratch
);
2389 WREG32(RADEON_BIOS_0_SCRATCH
, bios_0_scratch
);
2390 WREG32(RADEON_BIOS_3_SCRATCH
, bios_3_scratch
);
2391 WREG32(RADEON_BIOS_6_SCRATCH
, bios_6_scratch
);
2396 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder
*encoder
, int crtc
)
2398 struct drm_device
*dev
= encoder
->dev
;
2399 struct radeon_device
*rdev
= dev
->dev_private
;
2400 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
2401 uint32_t bios_3_scratch
;
2403 if (rdev
->family
>= CHIP_R600
)
2404 bios_3_scratch
= RREG32(R600_BIOS_3_SCRATCH
);
2406 bios_3_scratch
= RREG32(RADEON_BIOS_3_SCRATCH
);
2408 if (radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
2409 bios_3_scratch
&= ~ATOM_S3_TV1_CRTC_ACTIVE
;
2410 bios_3_scratch
|= (crtc
<< 18);
2412 if (radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
2413 bios_3_scratch
&= ~ATOM_S3_CV_CRTC_ACTIVE
;
2414 bios_3_scratch
|= (crtc
<< 24);
2416 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
2417 bios_3_scratch
&= ~ATOM_S3_CRT1_CRTC_ACTIVE
;
2418 bios_3_scratch
|= (crtc
<< 16);
2420 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
2421 bios_3_scratch
&= ~ATOM_S3_CRT2_CRTC_ACTIVE
;
2422 bios_3_scratch
|= (crtc
<< 20);
2424 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) {
2425 bios_3_scratch
&= ~ATOM_S3_LCD1_CRTC_ACTIVE
;
2426 bios_3_scratch
|= (crtc
<< 17);
2428 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP1_SUPPORT
) {
2429 bios_3_scratch
&= ~ATOM_S3_DFP1_CRTC_ACTIVE
;
2430 bios_3_scratch
|= (crtc
<< 19);
2432 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
) {
2433 bios_3_scratch
&= ~ATOM_S3_DFP2_CRTC_ACTIVE
;
2434 bios_3_scratch
|= (crtc
<< 23);
2436 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP3_SUPPORT
) {
2437 bios_3_scratch
&= ~ATOM_S3_DFP3_CRTC_ACTIVE
;
2438 bios_3_scratch
|= (crtc
<< 25);
2441 if (rdev
->family
>= CHIP_R600
)
2442 WREG32(R600_BIOS_3_SCRATCH
, bios_3_scratch
);
2444 WREG32(RADEON_BIOS_3_SCRATCH
, bios_3_scratch
);
2448 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder
*encoder
, bool on
)
2450 struct drm_device
*dev
= encoder
->dev
;
2451 struct radeon_device
*rdev
= dev
->dev_private
;
2452 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
2453 uint32_t bios_2_scratch
;
2455 if (rdev
->family
>= CHIP_R600
)
2456 bios_2_scratch
= RREG32(R600_BIOS_2_SCRATCH
);
2458 bios_2_scratch
= RREG32(RADEON_BIOS_2_SCRATCH
);
2460 if (radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
2462 bios_2_scratch
&= ~ATOM_S2_TV1_DPMS_STATE
;
2464 bios_2_scratch
|= ATOM_S2_TV1_DPMS_STATE
;
2466 if (radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
2468 bios_2_scratch
&= ~ATOM_S2_CV_DPMS_STATE
;
2470 bios_2_scratch
|= ATOM_S2_CV_DPMS_STATE
;
2472 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
2474 bios_2_scratch
&= ~ATOM_S2_CRT1_DPMS_STATE
;
2476 bios_2_scratch
|= ATOM_S2_CRT1_DPMS_STATE
;
2478 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
2480 bios_2_scratch
&= ~ATOM_S2_CRT2_DPMS_STATE
;
2482 bios_2_scratch
|= ATOM_S2_CRT2_DPMS_STATE
;
2484 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) {
2486 bios_2_scratch
&= ~ATOM_S2_LCD1_DPMS_STATE
;
2488 bios_2_scratch
|= ATOM_S2_LCD1_DPMS_STATE
;
2490 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP1_SUPPORT
) {
2492 bios_2_scratch
&= ~ATOM_S2_DFP1_DPMS_STATE
;
2494 bios_2_scratch
|= ATOM_S2_DFP1_DPMS_STATE
;
2496 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
) {
2498 bios_2_scratch
&= ~ATOM_S2_DFP2_DPMS_STATE
;
2500 bios_2_scratch
|= ATOM_S2_DFP2_DPMS_STATE
;
2502 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP3_SUPPORT
) {
2504 bios_2_scratch
&= ~ATOM_S2_DFP3_DPMS_STATE
;
2506 bios_2_scratch
|= ATOM_S2_DFP3_DPMS_STATE
;
2508 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP4_SUPPORT
) {
2510 bios_2_scratch
&= ~ATOM_S2_DFP4_DPMS_STATE
;
2512 bios_2_scratch
|= ATOM_S2_DFP4_DPMS_STATE
;
2514 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP5_SUPPORT
) {
2516 bios_2_scratch
&= ~ATOM_S2_DFP5_DPMS_STATE
;
2518 bios_2_scratch
|= ATOM_S2_DFP5_DPMS_STATE
;
2521 if (rdev
->family
>= CHIP_R600
)
2522 WREG32(R600_BIOS_2_SCRATCH
, bios_2_scratch
);
2524 WREG32(RADEON_BIOS_2_SCRATCH
, bios_2_scratch
);