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 <linux/pci.h>
29 #include <drm/drm_device.h>
30 #include <drm/radeon_drm.h>
35 #include "atom-bits.h"
36 #include "radeon_asic.h"
37 #include "radeon_atombios.h"
38 #include "radeon_legacy_encoders.h"
40 union atom_supported_devices
{
41 struct _ATOM_SUPPORTED_DEVICES_INFO info
;
42 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2
;
43 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1
;
46 static void radeon_lookup_i2c_gpio_quirks(struct radeon_device
*rdev
,
47 ATOM_GPIO_I2C_ASSIGMENT
*gpio
,
50 /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
51 if ((rdev
->family
== CHIP_R420
) ||
52 (rdev
->family
== CHIP_R423
) ||
53 (rdev
->family
== CHIP_RV410
)) {
54 if ((le16_to_cpu(gpio
->usClkMaskRegisterIndex
) == 0x0018) ||
55 (le16_to_cpu(gpio
->usClkMaskRegisterIndex
) == 0x0019) ||
56 (le16_to_cpu(gpio
->usClkMaskRegisterIndex
) == 0x001a)) {
57 gpio
->ucClkMaskShift
= 0x19;
58 gpio
->ucDataMaskShift
= 0x18;
62 /* some evergreen boards have bad data for this entry */
63 if (ASIC_IS_DCE4(rdev
)) {
65 (le16_to_cpu(gpio
->usClkMaskRegisterIndex
) == 0x1936) &&
66 (gpio
->sucI2cId
.ucAccess
== 0)) {
67 gpio
->sucI2cId
.ucAccess
= 0x97;
68 gpio
->ucDataMaskShift
= 8;
69 gpio
->ucDataEnShift
= 8;
70 gpio
->ucDataY_Shift
= 8;
71 gpio
->ucDataA_Shift
= 8;
75 /* some DCE3 boards have bad data for this entry */
76 if (ASIC_IS_DCE3(rdev
)) {
78 (le16_to_cpu(gpio
->usClkMaskRegisterIndex
) == 0x1fda) &&
79 (gpio
->sucI2cId
.ucAccess
== 0x94))
80 gpio
->sucI2cId
.ucAccess
= 0x14;
84 static struct radeon_i2c_bus_rec
radeon_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT
*gpio
)
86 struct radeon_i2c_bus_rec i2c
;
88 memset(&i2c
, 0, sizeof(struct radeon_i2c_bus_rec
));
90 i2c
.mask_clk_reg
= le16_to_cpu(gpio
->usClkMaskRegisterIndex
) * 4;
91 i2c
.mask_data_reg
= le16_to_cpu(gpio
->usDataMaskRegisterIndex
) * 4;
92 i2c
.en_clk_reg
= le16_to_cpu(gpio
->usClkEnRegisterIndex
) * 4;
93 i2c
.en_data_reg
= le16_to_cpu(gpio
->usDataEnRegisterIndex
) * 4;
94 i2c
.y_clk_reg
= le16_to_cpu(gpio
->usClkY_RegisterIndex
) * 4;
95 i2c
.y_data_reg
= le16_to_cpu(gpio
->usDataY_RegisterIndex
) * 4;
96 i2c
.a_clk_reg
= le16_to_cpu(gpio
->usClkA_RegisterIndex
) * 4;
97 i2c
.a_data_reg
= le16_to_cpu(gpio
->usDataA_RegisterIndex
) * 4;
98 i2c
.mask_clk_mask
= (1 << gpio
->ucClkMaskShift
);
99 i2c
.mask_data_mask
= (1 << gpio
->ucDataMaskShift
);
100 i2c
.en_clk_mask
= (1 << gpio
->ucClkEnShift
);
101 i2c
.en_data_mask
= (1 << gpio
->ucDataEnShift
);
102 i2c
.y_clk_mask
= (1 << gpio
->ucClkY_Shift
);
103 i2c
.y_data_mask
= (1 << gpio
->ucDataY_Shift
);
104 i2c
.a_clk_mask
= (1 << gpio
->ucClkA_Shift
);
105 i2c
.a_data_mask
= (1 << gpio
->ucDataA_Shift
);
107 if (gpio
->sucI2cId
.sbfAccess
.bfHW_Capable
)
108 i2c
.hw_capable
= true;
110 i2c
.hw_capable
= false;
112 if (gpio
->sucI2cId
.ucAccess
== 0xa0)
117 i2c
.i2c_id
= gpio
->sucI2cId
.ucAccess
;
119 if (i2c
.mask_clk_reg
)
127 static struct radeon_i2c_bus_rec
radeon_lookup_i2c_gpio(struct radeon_device
*rdev
,
130 struct atom_context
*ctx
= rdev
->mode_info
.atom_context
;
131 ATOM_GPIO_I2C_ASSIGMENT
*gpio
;
132 struct radeon_i2c_bus_rec i2c
;
133 int index
= GetIndexIntoMasterTable(DATA
, GPIO_I2C_Info
);
134 struct _ATOM_GPIO_I2C_INFO
*i2c_info
;
135 uint16_t data_offset
, size
;
138 memset(&i2c
, 0, sizeof(struct radeon_i2c_bus_rec
));
141 if (atom_parse_data_header(ctx
, index
, &size
, NULL
, NULL
, &data_offset
)) {
142 i2c_info
= (struct _ATOM_GPIO_I2C_INFO
*)(ctx
->bios
+ data_offset
);
144 num_indices
= (size
- sizeof(ATOM_COMMON_TABLE_HEADER
)) /
145 sizeof(ATOM_GPIO_I2C_ASSIGMENT
);
147 gpio
= &i2c_info
->asGPIO_Info
[0];
148 for (i
= 0; i
< num_indices
; i
++) {
150 radeon_lookup_i2c_gpio_quirks(rdev
, gpio
, i
);
152 if (gpio
->sucI2cId
.ucAccess
== id
) {
153 i2c
= radeon_get_bus_rec_for_i2c_gpio(gpio
);
156 gpio
= (ATOM_GPIO_I2C_ASSIGMENT
*)
157 ((u8
*)gpio
+ sizeof(ATOM_GPIO_I2C_ASSIGMENT
));
164 void radeon_atombios_i2c_init(struct radeon_device
*rdev
)
166 struct atom_context
*ctx
= rdev
->mode_info
.atom_context
;
167 ATOM_GPIO_I2C_ASSIGMENT
*gpio
;
168 struct radeon_i2c_bus_rec i2c
;
169 int index
= GetIndexIntoMasterTable(DATA
, GPIO_I2C_Info
);
170 struct _ATOM_GPIO_I2C_INFO
*i2c_info
;
171 uint16_t data_offset
, size
;
175 if (atom_parse_data_header(ctx
, index
, &size
, NULL
, NULL
, &data_offset
)) {
176 i2c_info
= (struct _ATOM_GPIO_I2C_INFO
*)(ctx
->bios
+ data_offset
);
178 num_indices
= (size
- sizeof(ATOM_COMMON_TABLE_HEADER
)) /
179 sizeof(ATOM_GPIO_I2C_ASSIGMENT
);
181 gpio
= &i2c_info
->asGPIO_Info
[0];
182 for (i
= 0; i
< num_indices
; i
++) {
183 radeon_lookup_i2c_gpio_quirks(rdev
, gpio
, i
);
185 i2c
= radeon_get_bus_rec_for_i2c_gpio(gpio
);
188 sprintf(stmp
, "0x%x", i2c
.i2c_id
);
189 rdev
->i2c_bus
[i
] = radeon_i2c_create(rdev
->ddev
, &i2c
, stmp
);
191 gpio
= (ATOM_GPIO_I2C_ASSIGMENT
*)
192 ((u8
*)gpio
+ sizeof(ATOM_GPIO_I2C_ASSIGMENT
));
197 struct radeon_gpio_rec
radeon_atombios_lookup_gpio(struct radeon_device
*rdev
,
200 struct atom_context
*ctx
= rdev
->mode_info
.atom_context
;
201 struct radeon_gpio_rec gpio
;
202 int index
= GetIndexIntoMasterTable(DATA
, GPIO_Pin_LUT
);
203 struct _ATOM_GPIO_PIN_LUT
*gpio_info
;
204 ATOM_GPIO_PIN_ASSIGNMENT
*pin
;
205 u16 data_offset
, size
;
208 memset(&gpio
, 0, sizeof(struct radeon_gpio_rec
));
211 if (atom_parse_data_header(ctx
, index
, &size
, NULL
, NULL
, &data_offset
)) {
212 gpio_info
= (struct _ATOM_GPIO_PIN_LUT
*)(ctx
->bios
+ data_offset
);
214 num_indices
= (size
- sizeof(ATOM_COMMON_TABLE_HEADER
)) /
215 sizeof(ATOM_GPIO_PIN_ASSIGNMENT
);
217 pin
= gpio_info
->asGPIO_Pin
;
218 for (i
= 0; i
< num_indices
; i
++) {
219 if (id
== pin
->ucGPIO_ID
) {
220 gpio
.id
= pin
->ucGPIO_ID
;
221 gpio
.reg
= le16_to_cpu(pin
->usGpioPin_AIndex
) * 4;
222 gpio
.shift
= pin
->ucGpioPinBitShift
;
223 gpio
.mask
= (1 << pin
->ucGpioPinBitShift
);
227 pin
= (ATOM_GPIO_PIN_ASSIGNMENT
*)
228 ((u8
*)pin
+ sizeof(ATOM_GPIO_PIN_ASSIGNMENT
));
235 static struct radeon_hpd
radeon_atom_get_hpd_info_from_gpio(struct radeon_device
*rdev
,
236 struct radeon_gpio_rec
*gpio
)
238 struct radeon_hpd hpd
;
241 memset(&hpd
, 0, sizeof(struct radeon_hpd
));
243 if (ASIC_IS_DCE6(rdev
))
244 reg
= SI_DC_GPIO_HPD_A
;
245 else if (ASIC_IS_DCE4(rdev
))
246 reg
= EVERGREEN_DC_GPIO_HPD_A
;
248 reg
= AVIVO_DC_GPIO_HPD_A
;
251 if (gpio
->reg
== reg
) {
254 hpd
.hpd
= RADEON_HPD_1
;
257 hpd
.hpd
= RADEON_HPD_2
;
260 hpd
.hpd
= RADEON_HPD_3
;
263 hpd
.hpd
= RADEON_HPD_4
;
266 hpd
.hpd
= RADEON_HPD_5
;
269 hpd
.hpd
= RADEON_HPD_6
;
272 hpd
.hpd
= RADEON_HPD_NONE
;
276 hpd
.hpd
= RADEON_HPD_NONE
;
280 static bool radeon_atom_apply_quirks(struct drm_device
*dev
,
281 uint32_t supported_device
,
283 struct radeon_i2c_bus_rec
*i2c_bus
,
285 struct radeon_hpd
*hpd
)
288 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
289 if ((dev
->pdev
->device
== 0x791e) &&
290 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
291 (dev
->pdev
->subsystem_device
== 0x826d)) {
292 if ((*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) &&
293 (supported_device
== ATOM_DEVICE_DFP3_SUPPORT
))
294 *connector_type
= DRM_MODE_CONNECTOR_DVID
;
297 /* Asrock RS600 board lists the DVI port as HDMI */
298 if ((dev
->pdev
->device
== 0x7941) &&
299 (dev
->pdev
->subsystem_vendor
== 0x1849) &&
300 (dev
->pdev
->subsystem_device
== 0x7941)) {
301 if ((*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) &&
302 (supported_device
== ATOM_DEVICE_DFP3_SUPPORT
))
303 *connector_type
= DRM_MODE_CONNECTOR_DVID
;
306 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
307 if ((dev
->pdev
->device
== 0x796e) &&
308 (dev
->pdev
->subsystem_vendor
== 0x1462) &&
309 (dev
->pdev
->subsystem_device
== 0x7302)) {
310 if ((supported_device
== ATOM_DEVICE_DFP2_SUPPORT
) ||
311 (supported_device
== ATOM_DEVICE_DFP3_SUPPORT
))
315 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
316 if ((dev
->pdev
->device
== 0x7941) &&
317 (dev
->pdev
->subsystem_vendor
== 0x147b) &&
318 (dev
->pdev
->subsystem_device
== 0x2412)) {
319 if (*connector_type
== DRM_MODE_CONNECTOR_DVII
)
323 /* Falcon NW laptop lists vga ddc line for LVDS */
324 if ((dev
->pdev
->device
== 0x5653) &&
325 (dev
->pdev
->subsystem_vendor
== 0x1462) &&
326 (dev
->pdev
->subsystem_device
== 0x0291)) {
327 if (*connector_type
== DRM_MODE_CONNECTOR_LVDS
) {
328 i2c_bus
->valid
= false;
333 /* HIS X1300 is DVI+VGA, not DVI+DVI */
334 if ((dev
->pdev
->device
== 0x7146) &&
335 (dev
->pdev
->subsystem_vendor
== 0x17af) &&
336 (dev
->pdev
->subsystem_device
== 0x2058)) {
337 if (supported_device
== ATOM_DEVICE_DFP1_SUPPORT
)
341 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
342 if ((dev
->pdev
->device
== 0x7142) &&
343 (dev
->pdev
->subsystem_vendor
== 0x1458) &&
344 (dev
->pdev
->subsystem_device
== 0x2134)) {
345 if (supported_device
== ATOM_DEVICE_DFP1_SUPPORT
)
351 if ((dev
->pdev
->device
== 0x71C5) &&
352 (dev
->pdev
->subsystem_vendor
== 0x106b) &&
353 (dev
->pdev
->subsystem_device
== 0x0080)) {
354 if ((supported_device
== ATOM_DEVICE_CRT1_SUPPORT
) ||
355 (supported_device
== ATOM_DEVICE_DFP2_SUPPORT
))
357 if (supported_device
== ATOM_DEVICE_CRT2_SUPPORT
)
361 /* mac rv630, rv730, others */
362 if ((supported_device
== ATOM_DEVICE_TV1_SUPPORT
) &&
363 (*connector_type
== DRM_MODE_CONNECTOR_DVII
)) {
364 *connector_type
= DRM_MODE_CONNECTOR_9PinDIN
;
365 *line_mux
= CONNECTOR_7PIN_DIN_ENUM_ID1
;
368 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
369 if ((dev
->pdev
->device
== 0x9598) &&
370 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
371 (dev
->pdev
->subsystem_device
== 0x01da)) {
372 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
373 *connector_type
= DRM_MODE_CONNECTOR_DVII
;
377 /* ASUS HD 3600 board lists the DVI port as HDMI */
378 if ((dev
->pdev
->device
== 0x9598) &&
379 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
380 (dev
->pdev
->subsystem_device
== 0x01e4)) {
381 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
382 *connector_type
= DRM_MODE_CONNECTOR_DVII
;
386 /* ASUS HD 3450 board lists the DVI port as HDMI */
387 if ((dev
->pdev
->device
== 0x95C5) &&
388 (dev
->pdev
->subsystem_vendor
== 0x1043) &&
389 (dev
->pdev
->subsystem_device
== 0x01e2)) {
390 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
391 *connector_type
= DRM_MODE_CONNECTOR_DVII
;
395 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
396 * HDMI + VGA reporting as HDMI
398 if (*connector_type
== DRM_MODE_CONNECTOR_HDMIA
) {
399 if (supported_device
& (ATOM_DEVICE_CRT_SUPPORT
)) {
400 *connector_type
= DRM_MODE_CONNECTOR_VGA
;
405 /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port
406 * on the laptop and a DVI port on the docking station and
407 * both share the same encoder, hpd pin, and ddc line.
408 * So while the bios table is technically correct,
409 * we drop the DVI port here since xrandr has no concept of
410 * encoders and will try and drive both connectors
411 * with different crtcs which isn't possible on the hardware
412 * side and leaves no crtcs for LVDS or VGA.
414 if (((dev
->pdev
->device
== 0x95c4) || (dev
->pdev
->device
== 0x9591)) &&
415 (dev
->pdev
->subsystem_vendor
== 0x1025) &&
416 (dev
->pdev
->subsystem_device
== 0x013c)) {
417 if ((*connector_type
== DRM_MODE_CONNECTOR_DVII
) &&
418 (supported_device
== ATOM_DEVICE_DFP1_SUPPORT
)) {
419 /* actually it's a DVI-D port not DVI-I */
420 *connector_type
= DRM_MODE_CONNECTOR_DVID
;
425 /* XFX Pine Group device rv730 reports no VGA DDC lines
426 * even though they are wired up to record 0x93
428 if ((dev
->pdev
->device
== 0x9498) &&
429 (dev
->pdev
->subsystem_vendor
== 0x1682) &&
430 (dev
->pdev
->subsystem_device
== 0x2452) &&
431 (i2c_bus
->valid
== false) &&
432 !(supported_device
& (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
))) {
433 struct radeon_device
*rdev
= dev
->dev_private
;
434 *i2c_bus
= radeon_lookup_i2c_gpio(rdev
, 0x93);
437 /* Fujitsu D3003-S2 board lists DVI-I as DVI-D and VGA */
438 if (((dev
->pdev
->device
== 0x9802) ||
439 (dev
->pdev
->device
== 0x9805) ||
440 (dev
->pdev
->device
== 0x9806)) &&
441 (dev
->pdev
->subsystem_vendor
== 0x1734) &&
442 (dev
->pdev
->subsystem_device
== 0x11bd)) {
443 if (*connector_type
== DRM_MODE_CONNECTOR_VGA
) {
444 *connector_type
= DRM_MODE_CONNECTOR_DVII
;
446 } else if (*connector_type
== DRM_MODE_CONNECTOR_DVID
) {
447 *connector_type
= DRM_MODE_CONNECTOR_DVII
;
454 static const int supported_devices_connector_convert
[] = {
455 DRM_MODE_CONNECTOR_Unknown
,
456 DRM_MODE_CONNECTOR_VGA
,
457 DRM_MODE_CONNECTOR_DVII
,
458 DRM_MODE_CONNECTOR_DVID
,
459 DRM_MODE_CONNECTOR_DVIA
,
460 DRM_MODE_CONNECTOR_SVIDEO
,
461 DRM_MODE_CONNECTOR_Composite
,
462 DRM_MODE_CONNECTOR_LVDS
,
463 DRM_MODE_CONNECTOR_Unknown
,
464 DRM_MODE_CONNECTOR_Unknown
,
465 DRM_MODE_CONNECTOR_HDMIA
,
466 DRM_MODE_CONNECTOR_HDMIB
,
467 DRM_MODE_CONNECTOR_Unknown
,
468 DRM_MODE_CONNECTOR_Unknown
,
469 DRM_MODE_CONNECTOR_9PinDIN
,
470 DRM_MODE_CONNECTOR_DisplayPort
473 static const uint16_t supported_devices_connector_object_id_convert
[] = {
474 CONNECTOR_OBJECT_ID_NONE
,
475 CONNECTOR_OBJECT_ID_VGA
,
476 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I
, /* not all boards support DL */
477 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D
, /* not all boards support DL */
478 CONNECTOR_OBJECT_ID_VGA
, /* technically DVI-A */
479 CONNECTOR_OBJECT_ID_COMPOSITE
,
480 CONNECTOR_OBJECT_ID_SVIDEO
,
481 CONNECTOR_OBJECT_ID_LVDS
,
482 CONNECTOR_OBJECT_ID_9PIN_DIN
,
483 CONNECTOR_OBJECT_ID_9PIN_DIN
,
484 CONNECTOR_OBJECT_ID_DISPLAYPORT
,
485 CONNECTOR_OBJECT_ID_HDMI_TYPE_A
,
486 CONNECTOR_OBJECT_ID_HDMI_TYPE_B
,
487 CONNECTOR_OBJECT_ID_SVIDEO
490 static const int object_connector_convert
[] = {
491 DRM_MODE_CONNECTOR_Unknown
,
492 DRM_MODE_CONNECTOR_DVII
,
493 DRM_MODE_CONNECTOR_DVII
,
494 DRM_MODE_CONNECTOR_DVID
,
495 DRM_MODE_CONNECTOR_DVID
,
496 DRM_MODE_CONNECTOR_VGA
,
497 DRM_MODE_CONNECTOR_Composite
,
498 DRM_MODE_CONNECTOR_SVIDEO
,
499 DRM_MODE_CONNECTOR_Unknown
,
500 DRM_MODE_CONNECTOR_Unknown
,
501 DRM_MODE_CONNECTOR_9PinDIN
,
502 DRM_MODE_CONNECTOR_Unknown
,
503 DRM_MODE_CONNECTOR_HDMIA
,
504 DRM_MODE_CONNECTOR_HDMIB
,
505 DRM_MODE_CONNECTOR_LVDS
,
506 DRM_MODE_CONNECTOR_9PinDIN
,
507 DRM_MODE_CONNECTOR_Unknown
,
508 DRM_MODE_CONNECTOR_Unknown
,
509 DRM_MODE_CONNECTOR_Unknown
,
510 DRM_MODE_CONNECTOR_DisplayPort
,
511 DRM_MODE_CONNECTOR_eDP
,
512 DRM_MODE_CONNECTOR_Unknown
515 bool radeon_get_atom_connector_info_from_object_table(struct drm_device
*dev
)
517 struct radeon_device
*rdev
= dev
->dev_private
;
518 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
519 struct atom_context
*ctx
= mode_info
->atom_context
;
520 int index
= GetIndexIntoMasterTable(DATA
, Object_Header
);
521 u16 size
, data_offset
;
523 ATOM_CONNECTOR_OBJECT_TABLE
*con_obj
;
524 ATOM_ENCODER_OBJECT_TABLE
*enc_obj
;
525 ATOM_OBJECT_TABLE
*router_obj
;
526 ATOM_DISPLAY_OBJECT_PATH_TABLE
*path_obj
;
527 ATOM_OBJECT_HEADER
*obj_header
;
528 int i
, j
, k
, path_size
, device_support
;
530 u16 igp_lane_info
, conn_id
, connector_object_id
;
531 struct radeon_i2c_bus_rec ddc_bus
;
532 struct radeon_router router
;
533 struct radeon_gpio_rec gpio
;
534 struct radeon_hpd hpd
;
536 if (!atom_parse_data_header(ctx
, index
, &size
, &frev
, &crev
, &data_offset
))
542 obj_header
= (ATOM_OBJECT_HEADER
*) (ctx
->bios
+ data_offset
);
543 path_obj
= (ATOM_DISPLAY_OBJECT_PATH_TABLE
*)
544 (ctx
->bios
+ data_offset
+
545 le16_to_cpu(obj_header
->usDisplayPathTableOffset
));
546 con_obj
= (ATOM_CONNECTOR_OBJECT_TABLE
*)
547 (ctx
->bios
+ data_offset
+
548 le16_to_cpu(obj_header
->usConnectorObjectTableOffset
));
549 enc_obj
= (ATOM_ENCODER_OBJECT_TABLE
*)
550 (ctx
->bios
+ data_offset
+
551 le16_to_cpu(obj_header
->usEncoderObjectTableOffset
));
552 router_obj
= (ATOM_OBJECT_TABLE
*)
553 (ctx
->bios
+ data_offset
+
554 le16_to_cpu(obj_header
->usRouterObjectTableOffset
));
555 device_support
= le16_to_cpu(obj_header
->usDeviceSupport
);
558 for (i
= 0; i
< path_obj
->ucNumOfDispPath
; i
++) {
559 uint8_t *addr
= (uint8_t *) path_obj
->asDispPath
;
560 ATOM_DISPLAY_OBJECT_PATH
*path
;
562 path
= (ATOM_DISPLAY_OBJECT_PATH
*) addr
;
563 path_size
+= le16_to_cpu(path
->usSize
);
565 if (device_support
& le16_to_cpu(path
->usDeviceTag
)) {
566 uint8_t con_obj_id
, con_obj_num
;
569 (le16_to_cpu(path
->usConnObjectId
) & OBJECT_ID_MASK
)
572 (le16_to_cpu(path
->usConnObjectId
) & ENUM_ID_MASK
)
575 /* TODO CV support */
576 if (le16_to_cpu(path
->usDeviceTag
) ==
577 ATOM_DEVICE_CV_SUPPORT
)
581 if ((rdev
->flags
& RADEON_IS_IGP
) &&
583 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR
)) {
584 uint16_t igp_offset
= 0;
585 ATOM_INTEGRATED_SYSTEM_INFO_V2
*igp_obj
;
588 GetIndexIntoMasterTable(DATA
,
589 IntegratedSystemInfo
);
591 if (atom_parse_data_header(ctx
, index
, &size
, &frev
,
592 &crev
, &igp_offset
)) {
596 (ATOM_INTEGRATED_SYSTEM_INFO_V2
597 *) (ctx
->bios
+ igp_offset
);
600 uint32_t slot_config
, ct
;
602 if (con_obj_num
== 1)
611 ct
= (slot_config
>> 16) & 0xff;
613 object_connector_convert
615 connector_object_id
= ct
;
617 slot_config
& 0xffff;
625 object_connector_convert
[con_obj_id
];
626 connector_object_id
= con_obj_id
;
631 object_connector_convert
[con_obj_id
];
632 connector_object_id
= con_obj_id
;
635 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
638 router
.ddc_valid
= false;
639 router
.cd_valid
= false;
640 for (j
= 0; j
< ((le16_to_cpu(path
->usSize
) - 8) / 2); j
++) {
641 uint8_t grph_obj_type
=
642 (le16_to_cpu(path
->usGraphicObjIds
[j
]) &
643 OBJECT_TYPE_MASK
) >> OBJECT_TYPE_SHIFT
;
645 if (grph_obj_type
== GRAPH_OBJECT_TYPE_ENCODER
) {
646 for (k
= 0; k
< enc_obj
->ucNumberOfObjects
; k
++) {
647 u16 encoder_obj
= le16_to_cpu(enc_obj
->asObjects
[k
].usObjectID
);
648 if (le16_to_cpu(path
->usGraphicObjIds
[j
]) == encoder_obj
) {
649 ATOM_COMMON_RECORD_HEADER
*record
= (ATOM_COMMON_RECORD_HEADER
*)
650 (ctx
->bios
+ data_offset
+
651 le16_to_cpu(enc_obj
->asObjects
[k
].usRecordOffset
));
652 ATOM_ENCODER_CAP_RECORD
*cap_record
;
655 while (record
->ucRecordSize
> 0 &&
656 record
->ucRecordType
> 0 &&
657 record
->ucRecordType
<= ATOM_MAX_OBJECT_RECORD_NUMBER
) {
658 switch (record
->ucRecordType
) {
659 case ATOM_ENCODER_CAP_RECORD_TYPE
:
660 cap_record
=(ATOM_ENCODER_CAP_RECORD
*)
662 caps
= le16_to_cpu(cap_record
->usEncoderCap
);
665 record
= (ATOM_COMMON_RECORD_HEADER
*)
666 ((char *)record
+ record
->ucRecordSize
);
668 radeon_add_atom_encoder(dev
,
676 } else if (grph_obj_type
== GRAPH_OBJECT_TYPE_ROUTER
) {
677 for (k
= 0; k
< router_obj
->ucNumberOfObjects
; k
++) {
678 u16 router_obj_id
= le16_to_cpu(router_obj
->asObjects
[k
].usObjectID
);
679 if (le16_to_cpu(path
->usGraphicObjIds
[j
]) == router_obj_id
) {
680 ATOM_COMMON_RECORD_HEADER
*record
= (ATOM_COMMON_RECORD_HEADER
*)
681 (ctx
->bios
+ data_offset
+
682 le16_to_cpu(router_obj
->asObjects
[k
].usRecordOffset
));
683 ATOM_I2C_RECORD
*i2c_record
;
684 ATOM_I2C_ID_CONFIG_ACCESS
*i2c_config
;
685 ATOM_ROUTER_DDC_PATH_SELECT_RECORD
*ddc_path
;
686 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD
*cd_path
;
687 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT
*router_src_dst_table
=
688 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT
*)
689 (ctx
->bios
+ data_offset
+
690 le16_to_cpu(router_obj
->asObjects
[k
].usSrcDstTableOffset
));
691 u8
*num_dst_objs
= (u8
*)
692 ((u8
*)router_src_dst_table
+ 1 +
693 (router_src_dst_table
->ucNumberOfSrc
* 2));
694 u16
*dst_objs
= (u16
*)(num_dst_objs
+ 1);
697 router
.router_id
= router_obj_id
;
698 for (enum_id
= 0; enum_id
< (*num_dst_objs
); enum_id
++) {
699 if (le16_to_cpu(path
->usConnObjectId
) ==
700 le16_to_cpu(dst_objs
[enum_id
]))
704 while (record
->ucRecordSize
> 0 &&
705 record
->ucRecordType
> 0 &&
706 record
->ucRecordType
<= ATOM_MAX_OBJECT_RECORD_NUMBER
) {
707 switch (record
->ucRecordType
) {
708 case ATOM_I2C_RECORD_TYPE
:
713 (ATOM_I2C_ID_CONFIG_ACCESS
*)
714 &i2c_record
->sucI2cId
;
716 radeon_lookup_i2c_gpio(rdev
,
719 router
.i2c_addr
= i2c_record
->ucI2CAddr
>> 1;
721 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE
:
722 ddc_path
= (ATOM_ROUTER_DDC_PATH_SELECT_RECORD
*)
724 router
.ddc_valid
= true;
725 router
.ddc_mux_type
= ddc_path
->ucMuxType
;
726 router
.ddc_mux_control_pin
= ddc_path
->ucMuxControlPin
;
727 router
.ddc_mux_state
= ddc_path
->ucMuxState
[enum_id
];
729 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE
:
730 cd_path
= (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD
*)
732 router
.cd_valid
= true;
733 router
.cd_mux_type
= cd_path
->ucMuxType
;
734 router
.cd_mux_control_pin
= cd_path
->ucMuxControlPin
;
735 router
.cd_mux_state
= cd_path
->ucMuxState
[enum_id
];
738 record
= (ATOM_COMMON_RECORD_HEADER
*)
739 ((char *)record
+ record
->ucRecordSize
);
746 /* look up gpio for ddc, hpd */
747 ddc_bus
.valid
= false;
748 hpd
.hpd
= RADEON_HPD_NONE
;
749 if ((le16_to_cpu(path
->usDeviceTag
) &
750 (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
)) == 0) {
751 for (j
= 0; j
< con_obj
->ucNumberOfObjects
; j
++) {
752 if (le16_to_cpu(path
->usConnObjectId
) ==
753 le16_to_cpu(con_obj
->asObjects
[j
].
755 ATOM_COMMON_RECORD_HEADER
757 (ATOM_COMMON_RECORD_HEADER
759 (ctx
->bios
+ data_offset
+
760 le16_to_cpu(con_obj
->
763 ATOM_I2C_RECORD
*i2c_record
;
764 ATOM_HPD_INT_RECORD
*hpd_record
;
765 ATOM_I2C_ID_CONFIG_ACCESS
*i2c_config
;
767 while (record
->ucRecordSize
> 0 &&
768 record
->ucRecordType
> 0 &&
769 record
->ucRecordType
<= ATOM_MAX_OBJECT_RECORD_NUMBER
) {
770 switch (record
->ucRecordType
) {
771 case ATOM_I2C_RECORD_TYPE
:
776 (ATOM_I2C_ID_CONFIG_ACCESS
*)
777 &i2c_record
->sucI2cId
;
778 ddc_bus
= radeon_lookup_i2c_gpio(rdev
,
782 case ATOM_HPD_INT_RECORD_TYPE
:
784 (ATOM_HPD_INT_RECORD
*)
786 gpio
= radeon_atombios_lookup_gpio(rdev
,
787 hpd_record
->ucHPDIntGPIOID
);
788 hpd
= radeon_atom_get_hpd_info_from_gpio(rdev
, &gpio
);
789 hpd
.plugged_state
= hpd_record
->ucPlugged_PinState
;
793 (ATOM_COMMON_RECORD_HEADER
804 /* needed for aux chan transactions */
805 ddc_bus
.hpd
= hpd
.hpd
;
807 conn_id
= le16_to_cpu(path
->usConnObjectId
);
809 if (!radeon_atom_apply_quirks
810 (dev
, le16_to_cpu(path
->usDeviceTag
), &connector_type
,
811 &ddc_bus
, &conn_id
, &hpd
))
814 radeon_add_atom_connector(dev
,
818 connector_type
, &ddc_bus
,
827 radeon_link_encoder_connector(dev
);
829 radeon_setup_mst_connector(dev
);
833 static uint16_t atombios_get_connector_object_id(struct drm_device
*dev
,
837 struct radeon_device
*rdev
= dev
->dev_private
;
839 if (rdev
->flags
& RADEON_IS_IGP
) {
840 return supported_devices_connector_object_id_convert
842 } else if (((connector_type
== DRM_MODE_CONNECTOR_DVII
) ||
843 (connector_type
== DRM_MODE_CONNECTOR_DVID
)) &&
844 (devices
& ATOM_DEVICE_DFP2_SUPPORT
)) {
845 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
846 struct atom_context
*ctx
= mode_info
->atom_context
;
847 int index
= GetIndexIntoMasterTable(DATA
, XTMDS_Info
);
848 uint16_t size
, data_offset
;
850 ATOM_XTMDS_INFO
*xtmds
;
852 if (atom_parse_data_header(ctx
, index
, &size
, &frev
, &crev
, &data_offset
)) {
853 xtmds
= (ATOM_XTMDS_INFO
*)(ctx
->bios
+ data_offset
);
855 if (xtmds
->ucSupportedLink
& ATOM_XTMDS_SUPPORTED_DUALLINK
) {
856 if (connector_type
== DRM_MODE_CONNECTOR_DVII
)
857 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I
;
859 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D
;
861 if (connector_type
== DRM_MODE_CONNECTOR_DVII
)
862 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I
;
864 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D
;
867 return supported_devices_connector_object_id_convert
870 return supported_devices_connector_object_id_convert
875 struct bios_connector
{
880 struct radeon_i2c_bus_rec ddc_bus
;
881 struct radeon_hpd hpd
;
884 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
888 struct radeon_device
*rdev
= dev
->dev_private
;
889 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
890 struct atom_context
*ctx
= mode_info
->atom_context
;
891 int index
= GetIndexIntoMasterTable(DATA
, SupportedDevicesInfo
);
892 uint16_t size
, data_offset
;
894 uint16_t device_support
;
896 union atom_supported_devices
*supported_devices
;
897 int i
, j
, max_device
;
898 struct bios_connector
*bios_connectors
;
899 size_t bc_size
= sizeof(*bios_connectors
) * ATOM_MAX_SUPPORTED_DEVICE
;
900 struct radeon_router router
;
902 router
.ddc_valid
= false;
903 router
.cd_valid
= false;
905 bios_connectors
= kzalloc(bc_size
, GFP_KERNEL
);
906 if (!bios_connectors
)
909 if (!atom_parse_data_header(ctx
, index
, &size
, &frev
, &crev
,
911 kfree(bios_connectors
);
916 (union atom_supported_devices
*)(ctx
->bios
+ data_offset
);
918 device_support
= le16_to_cpu(supported_devices
->info
.usDeviceSupport
);
921 max_device
= ATOM_MAX_SUPPORTED_DEVICE
;
923 max_device
= ATOM_MAX_SUPPORTED_DEVICE_INFO
;
925 for (i
= 0; i
< max_device
; i
++) {
926 ATOM_CONNECTOR_INFO_I2C ci
=
927 supported_devices
->info
.asConnInfo
[i
];
929 bios_connectors
[i
].valid
= false;
931 if (!(device_support
& (1 << i
))) {
935 if (i
== ATOM_DEVICE_CV_INDEX
) {
936 DRM_DEBUG_KMS("Skipping Component Video\n");
940 bios_connectors
[i
].connector_type
=
941 supported_devices_connector_convert
[ci
.sucConnectorInfo
.
945 if (bios_connectors
[i
].connector_type
==
946 DRM_MODE_CONNECTOR_Unknown
)
949 dac
= ci
.sucConnectorInfo
.sbfAccess
.bfAssociatedDAC
;
951 bios_connectors
[i
].line_mux
=
952 ci
.sucI2cId
.ucAccess
;
954 /* give tv unique connector ids */
955 if (i
== ATOM_DEVICE_TV1_INDEX
) {
956 bios_connectors
[i
].ddc_bus
.valid
= false;
957 bios_connectors
[i
].line_mux
= 50;
958 } else if (i
== ATOM_DEVICE_TV2_INDEX
) {
959 bios_connectors
[i
].ddc_bus
.valid
= false;
960 bios_connectors
[i
].line_mux
= 51;
961 } else if (i
== ATOM_DEVICE_CV_INDEX
) {
962 bios_connectors
[i
].ddc_bus
.valid
= false;
963 bios_connectors
[i
].line_mux
= 52;
965 bios_connectors
[i
].ddc_bus
=
966 radeon_lookup_i2c_gpio(rdev
,
967 bios_connectors
[i
].line_mux
);
969 if ((crev
> 1) && (frev
> 1)) {
970 u8 isb
= supported_devices
->info_2d1
.asIntSrcInfo
[i
].ucIntSrcBitmap
;
973 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_1
;
976 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_2
;
979 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_NONE
;
983 if (i
== ATOM_DEVICE_DFP1_INDEX
)
984 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_1
;
985 else if (i
== ATOM_DEVICE_DFP2_INDEX
)
986 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_2
;
988 bios_connectors
[i
].hpd
.hpd
= RADEON_HPD_NONE
;
991 /* Always set the connector type to VGA for CRT1/CRT2. if they are
992 * shared with a DVI port, we'll pick up the DVI connector when we
993 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
995 if (i
== ATOM_DEVICE_CRT1_INDEX
|| i
== ATOM_DEVICE_CRT2_INDEX
)
996 bios_connectors
[i
].connector_type
=
997 DRM_MODE_CONNECTOR_VGA
;
999 if (!radeon_atom_apply_quirks
1000 (dev
, (1 << i
), &bios_connectors
[i
].connector_type
,
1001 &bios_connectors
[i
].ddc_bus
, &bios_connectors
[i
].line_mux
,
1002 &bios_connectors
[i
].hpd
))
1005 bios_connectors
[i
].valid
= true;
1006 bios_connectors
[i
].devices
= (1 << i
);
1008 if (ASIC_IS_AVIVO(rdev
) || radeon_r4xx_atom
)
1009 radeon_add_atom_encoder(dev
,
1010 radeon_get_encoder_enum(dev
,
1016 radeon_add_legacy_encoder(dev
,
1017 radeon_get_encoder_enum(dev
,
1023 /* combine shared connectors */
1024 for (i
= 0; i
< max_device
; i
++) {
1025 if (bios_connectors
[i
].valid
) {
1026 for (j
= 0; j
< max_device
; j
++) {
1027 if (bios_connectors
[j
].valid
&& (i
!= j
)) {
1028 if (bios_connectors
[i
].line_mux
==
1029 bios_connectors
[j
].line_mux
) {
1030 /* make sure not to combine LVDS */
1031 if (bios_connectors
[i
].devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
1032 bios_connectors
[i
].line_mux
= 53;
1033 bios_connectors
[i
].ddc_bus
.valid
= false;
1036 if (bios_connectors
[j
].devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
1037 bios_connectors
[j
].line_mux
= 53;
1038 bios_connectors
[j
].ddc_bus
.valid
= false;
1041 /* combine analog and digital for DVI-I */
1042 if (((bios_connectors
[i
].devices
& (ATOM_DEVICE_DFP_SUPPORT
)) &&
1043 (bios_connectors
[j
].devices
& (ATOM_DEVICE_CRT_SUPPORT
))) ||
1044 ((bios_connectors
[j
].devices
& (ATOM_DEVICE_DFP_SUPPORT
)) &&
1045 (bios_connectors
[i
].devices
& (ATOM_DEVICE_CRT_SUPPORT
)))) {
1046 bios_connectors
[i
].devices
|=
1047 bios_connectors
[j
].devices
;
1048 bios_connectors
[i
].connector_type
=
1049 DRM_MODE_CONNECTOR_DVII
;
1050 if (bios_connectors
[j
].devices
& (ATOM_DEVICE_DFP_SUPPORT
))
1051 bios_connectors
[i
].hpd
=
1052 bios_connectors
[j
].hpd
;
1053 bios_connectors
[j
].valid
= false;
1061 /* add the connectors */
1062 for (i
= 0; i
< max_device
; i
++) {
1063 if (bios_connectors
[i
].valid
) {
1064 uint16_t connector_object_id
=
1065 atombios_get_connector_object_id(dev
,
1066 bios_connectors
[i
].connector_type
,
1067 bios_connectors
[i
].devices
);
1068 radeon_add_atom_connector(dev
,
1069 bios_connectors
[i
].line_mux
,
1070 bios_connectors
[i
].devices
,
1073 &bios_connectors
[i
].ddc_bus
,
1075 connector_object_id
,
1076 &bios_connectors
[i
].hpd
,
1081 radeon_link_encoder_connector(dev
);
1083 kfree(bios_connectors
);
1087 union firmware_info
{
1088 ATOM_FIRMWARE_INFO info
;
1089 ATOM_FIRMWARE_INFO_V1_2 info_12
;
1090 ATOM_FIRMWARE_INFO_V1_3 info_13
;
1091 ATOM_FIRMWARE_INFO_V1_4 info_14
;
1092 ATOM_FIRMWARE_INFO_V2_1 info_21
;
1093 ATOM_FIRMWARE_INFO_V2_2 info_22
;
1097 struct _ATOM_INTEGRATED_SYSTEM_INFO info
;
1098 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2
;
1099 struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6
;
1100 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7
;
1101 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8
;
1104 static void radeon_atombios_get_dentist_vco_freq(struct radeon_device
*rdev
)
1106 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1107 int index
= GetIndexIntoMasterTable(DATA
, IntegratedSystemInfo
);
1108 union igp_info
*igp_info
;
1112 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1113 &frev
, &crev
, &data_offset
)) {
1114 igp_info
= (union igp_info
*)(mode_info
->atom_context
->bios
+
1116 rdev
->clock
.vco_freq
=
1117 le32_to_cpu(igp_info
->info_6
.ulDentistVCOFreq
);
1121 bool radeon_atom_get_clock_info(struct drm_device
*dev
)
1123 struct radeon_device
*rdev
= dev
->dev_private
;
1124 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1125 int index
= GetIndexIntoMasterTable(DATA
, FirmwareInfo
);
1126 union firmware_info
*firmware_info
;
1128 struct radeon_pll
*p1pll
= &rdev
->clock
.p1pll
;
1129 struct radeon_pll
*p2pll
= &rdev
->clock
.p2pll
;
1130 struct radeon_pll
*dcpll
= &rdev
->clock
.dcpll
;
1131 struct radeon_pll
*spll
= &rdev
->clock
.spll
;
1132 struct radeon_pll
*mpll
= &rdev
->clock
.mpll
;
1133 uint16_t data_offset
;
1135 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1136 &frev
, &crev
, &data_offset
)) {
1138 (union firmware_info
*)(mode_info
->atom_context
->bios
+
1141 p1pll
->reference_freq
=
1142 le16_to_cpu(firmware_info
->info
.usReferenceClock
);
1143 p1pll
->reference_div
= 0;
1145 if ((frev
< 2) && (crev
< 2))
1146 p1pll
->pll_out_min
=
1147 le16_to_cpu(firmware_info
->info
.usMinPixelClockPLL_Output
);
1149 p1pll
->pll_out_min
=
1150 le32_to_cpu(firmware_info
->info_12
.ulMinPixelClockPLL_Output
);
1151 p1pll
->pll_out_max
=
1152 le32_to_cpu(firmware_info
->info
.ulMaxPixelClockPLL_Output
);
1154 if (((frev
< 2) && (crev
>= 4)) || (frev
>= 2)) {
1155 p1pll
->lcd_pll_out_min
=
1156 le16_to_cpu(firmware_info
->info_14
.usLcdMinPixelClockPLL_Output
) * 100;
1157 if (p1pll
->lcd_pll_out_min
== 0)
1158 p1pll
->lcd_pll_out_min
= p1pll
->pll_out_min
;
1159 p1pll
->lcd_pll_out_max
=
1160 le16_to_cpu(firmware_info
->info_14
.usLcdMaxPixelClockPLL_Output
) * 100;
1161 if (p1pll
->lcd_pll_out_max
== 0)
1162 p1pll
->lcd_pll_out_max
= p1pll
->pll_out_max
;
1164 p1pll
->lcd_pll_out_min
= p1pll
->pll_out_min
;
1165 p1pll
->lcd_pll_out_max
= p1pll
->pll_out_max
;
1168 if (p1pll
->pll_out_min
== 0) {
1169 if (ASIC_IS_AVIVO(rdev
))
1170 p1pll
->pll_out_min
= 64800;
1172 p1pll
->pll_out_min
= 20000;
1176 le16_to_cpu(firmware_info
->info
.usMinPixelClockPLL_Input
);
1178 le16_to_cpu(firmware_info
->info
.usMaxPixelClockPLL_Input
);
1183 if (ASIC_IS_DCE4(rdev
))
1184 spll
->reference_freq
=
1185 le16_to_cpu(firmware_info
->info_21
.usCoreReferenceClock
);
1187 spll
->reference_freq
=
1188 le16_to_cpu(firmware_info
->info
.usReferenceClock
);
1189 spll
->reference_div
= 0;
1192 le16_to_cpu(firmware_info
->info
.usMinEngineClockPLL_Output
);
1194 le32_to_cpu(firmware_info
->info
.ulMaxEngineClockPLL_Output
);
1197 if (spll
->pll_out_min
== 0) {
1198 if (ASIC_IS_AVIVO(rdev
))
1199 spll
->pll_out_min
= 64800;
1201 spll
->pll_out_min
= 20000;
1205 le16_to_cpu(firmware_info
->info
.usMinEngineClockPLL_Input
);
1207 le16_to_cpu(firmware_info
->info
.usMaxEngineClockPLL_Input
);
1210 if (ASIC_IS_DCE4(rdev
))
1211 mpll
->reference_freq
=
1212 le16_to_cpu(firmware_info
->info_21
.usMemoryReferenceClock
);
1214 mpll
->reference_freq
=
1215 le16_to_cpu(firmware_info
->info
.usReferenceClock
);
1216 mpll
->reference_div
= 0;
1219 le16_to_cpu(firmware_info
->info
.usMinMemoryClockPLL_Output
);
1221 le32_to_cpu(firmware_info
->info
.ulMaxMemoryClockPLL_Output
);
1224 if (mpll
->pll_out_min
== 0) {
1225 if (ASIC_IS_AVIVO(rdev
))
1226 mpll
->pll_out_min
= 64800;
1228 mpll
->pll_out_min
= 20000;
1232 le16_to_cpu(firmware_info
->info
.usMinMemoryClockPLL_Input
);
1234 le16_to_cpu(firmware_info
->info
.usMaxMemoryClockPLL_Input
);
1236 rdev
->clock
.default_sclk
=
1237 le32_to_cpu(firmware_info
->info
.ulDefaultEngineClock
);
1238 rdev
->clock
.default_mclk
=
1239 le32_to_cpu(firmware_info
->info
.ulDefaultMemoryClock
);
1241 if (ASIC_IS_DCE4(rdev
)) {
1242 rdev
->clock
.default_dispclk
=
1243 le32_to_cpu(firmware_info
->info_21
.ulDefaultDispEngineClkFreq
);
1244 if (rdev
->clock
.default_dispclk
== 0) {
1245 if (ASIC_IS_DCE6(rdev
))
1246 rdev
->clock
.default_dispclk
= 60000; /* 600 Mhz */
1247 else if (ASIC_IS_DCE5(rdev
))
1248 rdev
->clock
.default_dispclk
= 54000; /* 540 Mhz */
1250 rdev
->clock
.default_dispclk
= 60000; /* 600 Mhz */
1252 /* set a reasonable default for DP */
1253 if (ASIC_IS_DCE6(rdev
) && (rdev
->clock
.default_dispclk
< 53900)) {
1254 DRM_INFO("Changing default dispclk from %dMhz to 600Mhz\n",
1255 rdev
->clock
.default_dispclk
/ 100);
1256 rdev
->clock
.default_dispclk
= 60000;
1258 rdev
->clock
.dp_extclk
=
1259 le16_to_cpu(firmware_info
->info_21
.usUniphyDPModeExtClkFreq
);
1260 rdev
->clock
.current_dispclk
= rdev
->clock
.default_dispclk
;
1264 rdev
->clock
.max_pixel_clock
= le16_to_cpu(firmware_info
->info
.usMaxPixelClock
);
1265 if (rdev
->clock
.max_pixel_clock
== 0)
1266 rdev
->clock
.max_pixel_clock
= 40000;
1268 /* not technically a clock, but... */
1269 rdev
->mode_info
.firmware_flags
=
1270 le16_to_cpu(firmware_info
->info
.usFirmwareCapability
.susAccess
);
1272 if (ASIC_IS_DCE8(rdev
))
1273 rdev
->clock
.vco_freq
=
1274 le32_to_cpu(firmware_info
->info_22
.ulGPUPLL_OutputFreq
);
1275 else if (ASIC_IS_DCE5(rdev
))
1276 rdev
->clock
.vco_freq
= rdev
->clock
.current_dispclk
;
1277 else if (ASIC_IS_DCE41(rdev
))
1278 radeon_atombios_get_dentist_vco_freq(rdev
);
1280 rdev
->clock
.vco_freq
= rdev
->clock
.current_dispclk
;
1282 if (rdev
->clock
.vco_freq
== 0)
1283 rdev
->clock
.vco_freq
= 360000; /* 3.6 GHz */
1291 bool radeon_atombios_sideport_present(struct radeon_device
*rdev
)
1293 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1294 int index
= GetIndexIntoMasterTable(DATA
, IntegratedSystemInfo
);
1295 union igp_info
*igp_info
;
1299 /* sideport is AMD only */
1300 if (rdev
->family
== CHIP_RS600
)
1303 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1304 &frev
, &crev
, &data_offset
)) {
1305 igp_info
= (union igp_info
*)(mode_info
->atom_context
->bios
+
1309 if (le32_to_cpu(igp_info
->info
.ulBootUpMemoryClock
))
1313 if (le32_to_cpu(igp_info
->info_2
.ulBootUpSidePortClock
))
1317 DRM_ERROR("Unsupported IGP table: %d %d\n", frev
, crev
);
1324 bool radeon_atombios_get_tmds_info(struct radeon_encoder
*encoder
,
1325 struct radeon_encoder_int_tmds
*tmds
)
1327 struct drm_device
*dev
= encoder
->base
.dev
;
1328 struct radeon_device
*rdev
= dev
->dev_private
;
1329 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1330 int index
= GetIndexIntoMasterTable(DATA
, TMDS_Info
);
1331 uint16_t data_offset
;
1332 struct _ATOM_TMDS_INFO
*tmds_info
;
1337 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1338 &frev
, &crev
, &data_offset
)) {
1340 (struct _ATOM_TMDS_INFO
*)(mode_info
->atom_context
->bios
+
1343 maxfreq
= le16_to_cpu(tmds_info
->usMaxFrequency
);
1344 for (i
= 0; i
< 4; i
++) {
1345 tmds
->tmds_pll
[i
].freq
=
1346 le16_to_cpu(tmds_info
->asMiscInfo
[i
].usFrequency
);
1347 tmds
->tmds_pll
[i
].value
=
1348 tmds_info
->asMiscInfo
[i
].ucPLL_ChargePump
& 0x3f;
1349 tmds
->tmds_pll
[i
].value
|=
1350 (tmds_info
->asMiscInfo
[i
].
1351 ucPLL_VCO_Gain
& 0x3f) << 6;
1352 tmds
->tmds_pll
[i
].value
|=
1353 (tmds_info
->asMiscInfo
[i
].
1354 ucPLL_DutyCycle
& 0xf) << 12;
1355 tmds
->tmds_pll
[i
].value
|=
1356 (tmds_info
->asMiscInfo
[i
].
1357 ucPLL_VoltageSwing
& 0xf) << 16;
1359 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
1360 tmds
->tmds_pll
[i
].freq
,
1361 tmds
->tmds_pll
[i
].value
);
1363 if (maxfreq
== tmds
->tmds_pll
[i
].freq
) {
1364 tmds
->tmds_pll
[i
].freq
= 0xffffffff;
1373 bool radeon_atombios_get_ppll_ss_info(struct radeon_device
*rdev
,
1374 struct radeon_atom_ss
*ss
,
1377 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1378 int index
= GetIndexIntoMasterTable(DATA
, PPLL_SS_Info
);
1379 uint16_t data_offset
, size
;
1380 struct _ATOM_SPREAD_SPECTRUM_INFO
*ss_info
;
1381 struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT
*ss_assign
;
1385 memset(ss
, 0, sizeof(struct radeon_atom_ss
));
1386 if (atom_parse_data_header(mode_info
->atom_context
, index
, &size
,
1387 &frev
, &crev
, &data_offset
)) {
1389 (struct _ATOM_SPREAD_SPECTRUM_INFO
*)(mode_info
->atom_context
->bios
+ data_offset
);
1391 num_indices
= (size
- sizeof(ATOM_COMMON_TABLE_HEADER
)) /
1392 sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT
);
1393 ss_assign
= (struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT
*)
1394 ((u8
*)&ss_info
->asSS_Info
[0]);
1395 for (i
= 0; i
< num_indices
; i
++) {
1396 if (ss_assign
->ucSS_Id
== id
) {
1398 le16_to_cpu(ss_assign
->usSpreadSpectrumPercentage
);
1399 ss
->type
= ss_assign
->ucSpreadSpectrumType
;
1400 ss
->step
= ss_assign
->ucSS_Step
;
1401 ss
->delay
= ss_assign
->ucSS_Delay
;
1402 ss
->range
= ss_assign
->ucSS_Range
;
1403 ss
->refdiv
= ss_assign
->ucRecommendedRef_Div
;
1406 ss_assign
= (struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT
*)
1407 ((u8
*)ss_assign
+ sizeof(struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT
));
1413 static void radeon_atombios_get_igp_ss_overrides(struct radeon_device
*rdev
,
1414 struct radeon_atom_ss
*ss
,
1417 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1418 int index
= GetIndexIntoMasterTable(DATA
, IntegratedSystemInfo
);
1419 u16 data_offset
, size
;
1420 union igp_info
*igp_info
;
1422 u16 percentage
= 0, rate
= 0;
1424 /* get any igp specific overrides */
1425 if (atom_parse_data_header(mode_info
->atom_context
, index
, &size
,
1426 &frev
, &crev
, &data_offset
)) {
1427 igp_info
= (union igp_info
*)
1428 (mode_info
->atom_context
->bios
+ data_offset
);
1432 case ASIC_INTERNAL_SS_ON_TMDS
:
1433 percentage
= le16_to_cpu(igp_info
->info_6
.usDVISSPercentage
);
1434 rate
= le16_to_cpu(igp_info
->info_6
.usDVISSpreadRateIn10Hz
);
1436 case ASIC_INTERNAL_SS_ON_HDMI
:
1437 percentage
= le16_to_cpu(igp_info
->info_6
.usHDMISSPercentage
);
1438 rate
= le16_to_cpu(igp_info
->info_6
.usHDMISSpreadRateIn10Hz
);
1440 case ASIC_INTERNAL_SS_ON_LVDS
:
1441 percentage
= le16_to_cpu(igp_info
->info_6
.usLvdsSSPercentage
);
1442 rate
= le16_to_cpu(igp_info
->info_6
.usLvdsSSpreadRateIn10Hz
);
1448 case ASIC_INTERNAL_SS_ON_TMDS
:
1449 percentage
= le16_to_cpu(igp_info
->info_7
.usDVISSPercentage
);
1450 rate
= le16_to_cpu(igp_info
->info_7
.usDVISSpreadRateIn10Hz
);
1452 case ASIC_INTERNAL_SS_ON_HDMI
:
1453 percentage
= le16_to_cpu(igp_info
->info_7
.usHDMISSPercentage
);
1454 rate
= le16_to_cpu(igp_info
->info_7
.usHDMISSpreadRateIn10Hz
);
1456 case ASIC_INTERNAL_SS_ON_LVDS
:
1457 percentage
= le16_to_cpu(igp_info
->info_7
.usLvdsSSPercentage
);
1458 rate
= le16_to_cpu(igp_info
->info_7
.usLvdsSSpreadRateIn10Hz
);
1464 case ASIC_INTERNAL_SS_ON_TMDS
:
1465 percentage
= le16_to_cpu(igp_info
->info_8
.usDVISSPercentage
);
1466 rate
= le16_to_cpu(igp_info
->info_8
.usDVISSpreadRateIn10Hz
);
1468 case ASIC_INTERNAL_SS_ON_HDMI
:
1469 percentage
= le16_to_cpu(igp_info
->info_8
.usHDMISSPercentage
);
1470 rate
= le16_to_cpu(igp_info
->info_8
.usHDMISSpreadRateIn10Hz
);
1472 case ASIC_INTERNAL_SS_ON_LVDS
:
1473 percentage
= le16_to_cpu(igp_info
->info_8
.usLvdsSSPercentage
);
1474 rate
= le16_to_cpu(igp_info
->info_8
.usLvdsSSpreadRateIn10Hz
);
1479 DRM_ERROR("Unsupported IGP table: %d %d\n", frev
, crev
);
1483 ss
->percentage
= percentage
;
1489 union asic_ss_info
{
1490 struct _ATOM_ASIC_INTERNAL_SS_INFO info
;
1491 struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2
;
1492 struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3
;
1495 union asic_ss_assignment
{
1496 struct _ATOM_ASIC_SS_ASSIGNMENT v1
;
1497 struct _ATOM_ASIC_SS_ASSIGNMENT_V2 v2
;
1498 struct _ATOM_ASIC_SS_ASSIGNMENT_V3 v3
;
1501 bool radeon_atombios_get_asic_ss_info(struct radeon_device
*rdev
,
1502 struct radeon_atom_ss
*ss
,
1505 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1506 int index
= GetIndexIntoMasterTable(DATA
, ASIC_InternalSS_Info
);
1507 uint16_t data_offset
, size
;
1508 union asic_ss_info
*ss_info
;
1509 union asic_ss_assignment
*ss_assign
;
1513 if (id
== ASIC_INTERNAL_MEMORY_SS
) {
1514 if (!(rdev
->mode_info
.firmware_flags
& ATOM_BIOS_INFO_MEMORY_CLOCK_SS_SUPPORT
))
1517 if (id
== ASIC_INTERNAL_ENGINE_SS
) {
1518 if (!(rdev
->mode_info
.firmware_flags
& ATOM_BIOS_INFO_ENGINE_CLOCK_SS_SUPPORT
))
1522 memset(ss
, 0, sizeof(struct radeon_atom_ss
));
1523 if (atom_parse_data_header(mode_info
->atom_context
, index
, &size
,
1524 &frev
, &crev
, &data_offset
)) {
1527 (union asic_ss_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
1531 num_indices
= (size
- sizeof(ATOM_COMMON_TABLE_HEADER
)) /
1532 sizeof(ATOM_ASIC_SS_ASSIGNMENT
);
1534 ss_assign
= (union asic_ss_assignment
*)((u8
*)&ss_info
->info
.asSpreadSpectrum
[0]);
1535 for (i
= 0; i
< num_indices
; i
++) {
1536 if ((ss_assign
->v1
.ucClockIndication
== id
) &&
1537 (clock
<= le32_to_cpu(ss_assign
->v1
.ulTargetClockRange
))) {
1539 le16_to_cpu(ss_assign
->v1
.usSpreadSpectrumPercentage
);
1540 ss
->type
= ss_assign
->v1
.ucSpreadSpectrumMode
;
1541 ss
->rate
= le16_to_cpu(ss_assign
->v1
.usSpreadRateInKhz
);
1542 ss
->percentage_divider
= 100;
1545 ss_assign
= (union asic_ss_assignment
*)
1546 ((u8
*)ss_assign
+ sizeof(ATOM_ASIC_SS_ASSIGNMENT
));
1550 num_indices
= (size
- sizeof(ATOM_COMMON_TABLE_HEADER
)) /
1551 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2
);
1552 ss_assign
= (union asic_ss_assignment
*)((u8
*)&ss_info
->info_2
.asSpreadSpectrum
[0]);
1553 for (i
= 0; i
< num_indices
; i
++) {
1554 if ((ss_assign
->v2
.ucClockIndication
== id
) &&
1555 (clock
<= le32_to_cpu(ss_assign
->v2
.ulTargetClockRange
))) {
1557 le16_to_cpu(ss_assign
->v2
.usSpreadSpectrumPercentage
);
1558 ss
->type
= ss_assign
->v2
.ucSpreadSpectrumMode
;
1559 ss
->rate
= le16_to_cpu(ss_assign
->v2
.usSpreadRateIn10Hz
);
1560 ss
->percentage_divider
= 100;
1562 ((id
== ASIC_INTERNAL_ENGINE_SS
) ||
1563 (id
== ASIC_INTERNAL_MEMORY_SS
)))
1567 ss_assign
= (union asic_ss_assignment
*)
1568 ((u8
*)ss_assign
+ sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2
));
1572 num_indices
= (size
- sizeof(ATOM_COMMON_TABLE_HEADER
)) /
1573 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3
);
1574 ss_assign
= (union asic_ss_assignment
*)((u8
*)&ss_info
->info_3
.asSpreadSpectrum
[0]);
1575 for (i
= 0; i
< num_indices
; i
++) {
1576 if ((ss_assign
->v3
.ucClockIndication
== id
) &&
1577 (clock
<= le32_to_cpu(ss_assign
->v3
.ulTargetClockRange
))) {
1579 le16_to_cpu(ss_assign
->v3
.usSpreadSpectrumPercentage
);
1580 ss
->type
= ss_assign
->v3
.ucSpreadSpectrumMode
;
1581 ss
->rate
= le16_to_cpu(ss_assign
->v3
.usSpreadRateIn10Hz
);
1582 if (ss_assign
->v3
.ucSpreadSpectrumMode
&
1583 SS_MODE_V3_PERCENTAGE_DIV_BY_1000_MASK
)
1584 ss
->percentage_divider
= 1000;
1586 ss
->percentage_divider
= 100;
1587 if ((id
== ASIC_INTERNAL_ENGINE_SS
) ||
1588 (id
== ASIC_INTERNAL_MEMORY_SS
))
1590 if (rdev
->flags
& RADEON_IS_IGP
)
1591 radeon_atombios_get_igp_ss_overrides(rdev
, ss
, id
);
1594 ss_assign
= (union asic_ss_assignment
*)
1595 ((u8
*)ss_assign
+ sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3
));
1599 DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev
, crev
);
1608 struct _ATOM_LVDS_INFO info
;
1609 struct _ATOM_LVDS_INFO_V12 info_12
;
1612 struct radeon_encoder_atom_dig
*radeon_atombios_get_lvds_info(struct
1616 struct drm_device
*dev
= encoder
->base
.dev
;
1617 struct radeon_device
*rdev
= dev
->dev_private
;
1618 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1619 int index
= GetIndexIntoMasterTable(DATA
, LVDS_Info
);
1620 uint16_t data_offset
, misc
;
1621 union lvds_info
*lvds_info
;
1623 struct radeon_encoder_atom_dig
*lvds
= NULL
;
1624 int encoder_enum
= (encoder
->encoder_enum
& ENUM_ID_MASK
) >> ENUM_ID_SHIFT
;
1626 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1627 &frev
, &crev
, &data_offset
)) {
1629 (union lvds_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
1631 kzalloc(sizeof(struct radeon_encoder_atom_dig
), GFP_KERNEL
);
1636 lvds
->native_mode
.clock
=
1637 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usPixClk
) * 10;
1638 lvds
->native_mode
.hdisplay
=
1639 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHActive
);
1640 lvds
->native_mode
.vdisplay
=
1641 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVActive
);
1642 lvds
->native_mode
.htotal
= lvds
->native_mode
.hdisplay
+
1643 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHBlanking_Time
);
1644 lvds
->native_mode
.hsync_start
= lvds
->native_mode
.hdisplay
+
1645 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHSyncOffset
);
1646 lvds
->native_mode
.hsync_end
= lvds
->native_mode
.hsync_start
+
1647 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usHSyncWidth
);
1648 lvds
->native_mode
.vtotal
= lvds
->native_mode
.vdisplay
+
1649 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVBlanking_Time
);
1650 lvds
->native_mode
.vsync_start
= lvds
->native_mode
.vdisplay
+
1651 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVSyncOffset
);
1652 lvds
->native_mode
.vsync_end
= lvds
->native_mode
.vsync_start
+
1653 le16_to_cpu(lvds_info
->info
.sLCDTiming
.usVSyncWidth
);
1654 lvds
->panel_pwr_delay
=
1655 le16_to_cpu(lvds_info
->info
.usOffDelayInMs
);
1656 lvds
->lcd_misc
= lvds_info
->info
.ucLVDS_Misc
;
1658 misc
= le16_to_cpu(lvds_info
->info
.sLCDTiming
.susModeMiscInfo
.usAccess
);
1659 if (misc
& ATOM_VSYNC_POLARITY
)
1660 lvds
->native_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
1661 if (misc
& ATOM_HSYNC_POLARITY
)
1662 lvds
->native_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
1663 if (misc
& ATOM_COMPOSITESYNC
)
1664 lvds
->native_mode
.flags
|= DRM_MODE_FLAG_CSYNC
;
1665 if (misc
& ATOM_INTERLACE
)
1666 lvds
->native_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
1667 if (misc
& ATOM_DOUBLE_CLOCK_MODE
)
1668 lvds
->native_mode
.flags
|= DRM_MODE_FLAG_DBLSCAN
;
1670 lvds
->native_mode
.width_mm
= le16_to_cpu(lvds_info
->info
.sLCDTiming
.usImageHSize
);
1671 lvds
->native_mode
.height_mm
= le16_to_cpu(lvds_info
->info
.sLCDTiming
.usImageVSize
);
1673 /* set crtc values */
1674 drm_mode_set_crtcinfo(&lvds
->native_mode
, CRTC_INTERLACE_HALVE_V
);
1676 lvds
->lcd_ss_id
= lvds_info
->info
.ucSS_Id
;
1678 encoder
->native_mode
= lvds
->native_mode
;
1680 if (encoder_enum
== 2)
1683 lvds
->linkb
= false;
1685 /* parse the lcd record table */
1686 if (le16_to_cpu(lvds_info
->info
.usModePatchTableOffset
)) {
1687 ATOM_FAKE_EDID_PATCH_RECORD
*fake_edid_record
;
1688 ATOM_PANEL_RESOLUTION_PATCH_RECORD
*panel_res_record
;
1689 bool bad_record
= false;
1692 if ((frev
== 1) && (crev
< 2))
1694 record
= (u8
*)(mode_info
->atom_context
->bios
+
1695 le16_to_cpu(lvds_info
->info
.usModePatchTableOffset
));
1698 record
= (u8
*)(mode_info
->atom_context
->bios
+
1700 le16_to_cpu(lvds_info
->info
.usModePatchTableOffset
));
1701 while (*record
!= ATOM_RECORD_END_TYPE
) {
1703 case LCD_MODE_PATCH_RECORD_MODE_TYPE
:
1704 record
+= sizeof(ATOM_PATCH_RECORD_MODE
);
1706 case LCD_RTS_RECORD_TYPE
:
1707 record
+= sizeof(ATOM_LCD_RTS_RECORD
);
1709 case LCD_CAP_RECORD_TYPE
:
1710 record
+= sizeof(ATOM_LCD_MODE_CONTROL_CAP
);
1712 case LCD_FAKE_EDID_PATCH_RECORD_TYPE
:
1713 fake_edid_record
= (ATOM_FAKE_EDID_PATCH_RECORD
*)record
;
1714 if (fake_edid_record
->ucFakeEDIDLength
) {
1717 max((int)EDID_LENGTH
, (int)fake_edid_record
->ucFakeEDIDLength
);
1718 edid
= kmalloc(edid_size
, GFP_KERNEL
);
1720 memcpy((u8
*)edid
, (u8
*)&fake_edid_record
->ucFakeEDIDString
[0],
1721 fake_edid_record
->ucFakeEDIDLength
);
1723 if (drm_edid_is_valid(edid
)) {
1724 rdev
->mode_info
.bios_hardcoded_edid
= edid
;
1725 rdev
->mode_info
.bios_hardcoded_edid_size
= edid_size
;
1730 record
+= fake_edid_record
->ucFakeEDIDLength
?
1731 fake_edid_record
->ucFakeEDIDLength
+ 2 :
1732 sizeof(ATOM_FAKE_EDID_PATCH_RECORD
);
1734 case LCD_PANEL_RESOLUTION_RECORD_TYPE
:
1735 panel_res_record
= (ATOM_PANEL_RESOLUTION_PATCH_RECORD
*)record
;
1736 lvds
->native_mode
.width_mm
= panel_res_record
->usHSize
;
1737 lvds
->native_mode
.height_mm
= panel_res_record
->usVSize
;
1738 record
+= sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD
);
1741 DRM_ERROR("Bad LCD record %d\n", *record
);
1753 struct radeon_encoder_primary_dac
*
1754 radeon_atombios_get_primary_dac_info(struct radeon_encoder
*encoder
)
1756 struct drm_device
*dev
= encoder
->base
.dev
;
1757 struct radeon_device
*rdev
= dev
->dev_private
;
1758 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1759 int index
= GetIndexIntoMasterTable(DATA
, CompassionateData
);
1760 uint16_t data_offset
;
1761 struct _COMPASSIONATE_DATA
*dac_info
;
1764 struct radeon_encoder_primary_dac
*p_dac
= NULL
;
1766 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1767 &frev
, &crev
, &data_offset
)) {
1768 dac_info
= (struct _COMPASSIONATE_DATA
*)
1769 (mode_info
->atom_context
->bios
+ data_offset
);
1771 p_dac
= kzalloc(sizeof(struct radeon_encoder_primary_dac
), GFP_KERNEL
);
1776 bg
= dac_info
->ucDAC1_BG_Adjustment
;
1777 dac
= dac_info
->ucDAC1_DAC_Adjustment
;
1778 p_dac
->ps2_pdac_adj
= (bg
<< 8) | (dac
);
1784 bool radeon_atom_get_tv_timings(struct radeon_device
*rdev
, int index
,
1785 struct drm_display_mode
*mode
)
1787 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1788 ATOM_ANALOG_TV_INFO
*tv_info
;
1789 ATOM_ANALOG_TV_INFO_V1_2
*tv_info_v1_2
;
1790 ATOM_DTD_FORMAT
*dtd_timings
;
1791 int data_index
= GetIndexIntoMasterTable(DATA
, AnalogTV_Info
);
1793 u16 data_offset
, misc
;
1795 if (!atom_parse_data_header(mode_info
->atom_context
, data_index
, NULL
,
1796 &frev
, &crev
, &data_offset
))
1801 tv_info
= (ATOM_ANALOG_TV_INFO
*)(mode_info
->atom_context
->bios
+ data_offset
);
1802 if (index
>= MAX_SUPPORTED_TV_TIMING
)
1805 mode
->crtc_htotal
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_Total
);
1806 mode
->crtc_hdisplay
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_Disp
);
1807 mode
->crtc_hsync_start
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_SyncStart
);
1808 mode
->crtc_hsync_end
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_SyncStart
) +
1809 le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_H_SyncWidth
);
1811 mode
->crtc_vtotal
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_Total
);
1812 mode
->crtc_vdisplay
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_Disp
);
1813 mode
->crtc_vsync_start
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_SyncStart
);
1814 mode
->crtc_vsync_end
= le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_SyncStart
) +
1815 le16_to_cpu(tv_info
->aModeTimings
[index
].usCRTC_V_SyncWidth
);
1818 misc
= le16_to_cpu(tv_info
->aModeTimings
[index
].susModeMiscInfo
.usAccess
);
1819 if (misc
& ATOM_VSYNC_POLARITY
)
1820 mode
->flags
|= DRM_MODE_FLAG_NVSYNC
;
1821 if (misc
& ATOM_HSYNC_POLARITY
)
1822 mode
->flags
|= DRM_MODE_FLAG_NHSYNC
;
1823 if (misc
& ATOM_COMPOSITESYNC
)
1824 mode
->flags
|= DRM_MODE_FLAG_CSYNC
;
1825 if (misc
& ATOM_INTERLACE
)
1826 mode
->flags
|= DRM_MODE_FLAG_INTERLACE
;
1827 if (misc
& ATOM_DOUBLE_CLOCK_MODE
)
1828 mode
->flags
|= DRM_MODE_FLAG_DBLSCAN
;
1830 mode
->crtc_clock
= mode
->clock
=
1831 le16_to_cpu(tv_info
->aModeTimings
[index
].usPixelClock
) * 10;
1834 /* PAL timings appear to have wrong values for totals */
1835 mode
->crtc_htotal
-= 1;
1836 mode
->crtc_vtotal
-= 1;
1840 tv_info_v1_2
= (ATOM_ANALOG_TV_INFO_V1_2
*)(mode_info
->atom_context
->bios
+ data_offset
);
1841 if (index
>= MAX_SUPPORTED_TV_TIMING_V1_2
)
1844 dtd_timings
= &tv_info_v1_2
->aModeTimings
[index
];
1845 mode
->crtc_htotal
= le16_to_cpu(dtd_timings
->usHActive
) +
1846 le16_to_cpu(dtd_timings
->usHBlanking_Time
);
1847 mode
->crtc_hdisplay
= le16_to_cpu(dtd_timings
->usHActive
);
1848 mode
->crtc_hsync_start
= le16_to_cpu(dtd_timings
->usHActive
) +
1849 le16_to_cpu(dtd_timings
->usHSyncOffset
);
1850 mode
->crtc_hsync_end
= mode
->crtc_hsync_start
+
1851 le16_to_cpu(dtd_timings
->usHSyncWidth
);
1853 mode
->crtc_vtotal
= le16_to_cpu(dtd_timings
->usVActive
) +
1854 le16_to_cpu(dtd_timings
->usVBlanking_Time
);
1855 mode
->crtc_vdisplay
= le16_to_cpu(dtd_timings
->usVActive
);
1856 mode
->crtc_vsync_start
= le16_to_cpu(dtd_timings
->usVActive
) +
1857 le16_to_cpu(dtd_timings
->usVSyncOffset
);
1858 mode
->crtc_vsync_end
= mode
->crtc_vsync_start
+
1859 le16_to_cpu(dtd_timings
->usVSyncWidth
);
1862 misc
= le16_to_cpu(dtd_timings
->susModeMiscInfo
.usAccess
);
1863 if (misc
& ATOM_VSYNC_POLARITY
)
1864 mode
->flags
|= DRM_MODE_FLAG_NVSYNC
;
1865 if (misc
& ATOM_HSYNC_POLARITY
)
1866 mode
->flags
|= DRM_MODE_FLAG_NHSYNC
;
1867 if (misc
& ATOM_COMPOSITESYNC
)
1868 mode
->flags
|= DRM_MODE_FLAG_CSYNC
;
1869 if (misc
& ATOM_INTERLACE
)
1870 mode
->flags
|= DRM_MODE_FLAG_INTERLACE
;
1871 if (misc
& ATOM_DOUBLE_CLOCK_MODE
)
1872 mode
->flags
|= DRM_MODE_FLAG_DBLSCAN
;
1874 mode
->crtc_clock
= mode
->clock
=
1875 le16_to_cpu(dtd_timings
->usPixClk
) * 10;
1882 radeon_atombios_get_tv_info(struct radeon_device
*rdev
)
1884 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1885 int index
= GetIndexIntoMasterTable(DATA
, AnalogTV_Info
);
1886 uint16_t data_offset
;
1888 struct _ATOM_ANALOG_TV_INFO
*tv_info
;
1889 enum radeon_tv_std tv_std
= TV_STD_NTSC
;
1891 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1892 &frev
, &crev
, &data_offset
)) {
1894 tv_info
= (struct _ATOM_ANALOG_TV_INFO
*)
1895 (mode_info
->atom_context
->bios
+ data_offset
);
1897 switch (tv_info
->ucTV_BootUpDefaultStandard
) {
1899 tv_std
= TV_STD_NTSC
;
1900 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
1903 tv_std
= TV_STD_NTSC_J
;
1904 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
1907 tv_std
= TV_STD_PAL
;
1908 DRM_DEBUG_KMS("Default TV standard: PAL\n");
1911 tv_std
= TV_STD_PAL_M
;
1912 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
1915 tv_std
= TV_STD_PAL_N
;
1916 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
1919 tv_std
= TV_STD_PAL_CN
;
1920 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
1923 tv_std
= TV_STD_PAL_60
;
1924 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
1927 tv_std
= TV_STD_SECAM
;
1928 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
1931 tv_std
= TV_STD_NTSC
;
1932 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
1939 struct radeon_encoder_tv_dac
*
1940 radeon_atombios_get_tv_dac_info(struct radeon_encoder
*encoder
)
1942 struct drm_device
*dev
= encoder
->base
.dev
;
1943 struct radeon_device
*rdev
= dev
->dev_private
;
1944 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
1945 int index
= GetIndexIntoMasterTable(DATA
, CompassionateData
);
1946 uint16_t data_offset
;
1947 struct _COMPASSIONATE_DATA
*dac_info
;
1950 struct radeon_encoder_tv_dac
*tv_dac
= NULL
;
1952 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
1953 &frev
, &crev
, &data_offset
)) {
1955 dac_info
= (struct _COMPASSIONATE_DATA
*)
1956 (mode_info
->atom_context
->bios
+ data_offset
);
1958 tv_dac
= kzalloc(sizeof(struct radeon_encoder_tv_dac
), GFP_KERNEL
);
1963 bg
= dac_info
->ucDAC2_CRT2_BG_Adjustment
;
1964 dac
= dac_info
->ucDAC2_CRT2_DAC_Adjustment
;
1965 tv_dac
->ps2_tvdac_adj
= (bg
<< 16) | (dac
<< 20);
1967 bg
= dac_info
->ucDAC2_PAL_BG_Adjustment
;
1968 dac
= dac_info
->ucDAC2_PAL_DAC_Adjustment
;
1969 tv_dac
->pal_tvdac_adj
= (bg
<< 16) | (dac
<< 20);
1971 bg
= dac_info
->ucDAC2_NTSC_BG_Adjustment
;
1972 dac
= dac_info
->ucDAC2_NTSC_DAC_Adjustment
;
1973 tv_dac
->ntsc_tvdac_adj
= (bg
<< 16) | (dac
<< 20);
1975 tv_dac
->tv_std
= radeon_atombios_get_tv_info(rdev
);
1980 static const char *thermal_controller_names
[] = {
1991 static const char *pp_lib_thermal_controller_names
[] = {
2014 struct _ATOM_POWERPLAY_INFO info
;
2015 struct _ATOM_POWERPLAY_INFO_V2 info_2
;
2016 struct _ATOM_POWERPLAY_INFO_V3 info_3
;
2017 struct _ATOM_PPLIB_POWERPLAYTABLE pplib
;
2018 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2
;
2019 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3
;
2022 union pplib_clock_info
{
2023 struct _ATOM_PPLIB_R600_CLOCK_INFO r600
;
2024 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780
;
2025 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen
;
2026 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo
;
2027 struct _ATOM_PPLIB_SI_CLOCK_INFO si
;
2028 struct _ATOM_PPLIB_CI_CLOCK_INFO ci
;
2031 union pplib_power_state
{
2032 struct _ATOM_PPLIB_STATE v1
;
2033 struct _ATOM_PPLIB_STATE_V2 v2
;
2036 static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device
*rdev
,
2038 u32 misc
, u32 misc2
)
2040 rdev
->pm
.power_state
[state_index
].misc
= misc
;
2041 rdev
->pm
.power_state
[state_index
].misc2
= misc2
;
2042 /* order matters! */
2043 if (misc
& ATOM_PM_MISCINFO_POWER_SAVING_MODE
)
2044 rdev
->pm
.power_state
[state_index
].type
=
2045 POWER_STATE_TYPE_POWERSAVE
;
2046 if (misc
& ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE
)
2047 rdev
->pm
.power_state
[state_index
].type
=
2048 POWER_STATE_TYPE_BATTERY
;
2049 if (misc
& ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE
)
2050 rdev
->pm
.power_state
[state_index
].type
=
2051 POWER_STATE_TYPE_BATTERY
;
2052 if (misc
& ATOM_PM_MISCINFO_LOAD_BALANCE_EN
)
2053 rdev
->pm
.power_state
[state_index
].type
=
2054 POWER_STATE_TYPE_BALANCED
;
2055 if (misc
& ATOM_PM_MISCINFO_3D_ACCELERATION_EN
) {
2056 rdev
->pm
.power_state
[state_index
].type
=
2057 POWER_STATE_TYPE_PERFORMANCE
;
2058 rdev
->pm
.power_state
[state_index
].flags
&=
2059 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
2061 if (misc2
& ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE
)
2062 rdev
->pm
.power_state
[state_index
].type
=
2063 POWER_STATE_TYPE_BALANCED
;
2064 if (misc
& ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE
) {
2065 rdev
->pm
.power_state
[state_index
].type
=
2066 POWER_STATE_TYPE_DEFAULT
;
2067 rdev
->pm
.default_power_state_index
= state_index
;
2068 rdev
->pm
.power_state
[state_index
].default_clock_mode
=
2069 &rdev
->pm
.power_state
[state_index
].clock_info
[0];
2070 } else if (state_index
== 0) {
2071 rdev
->pm
.power_state
[state_index
].clock_info
[0].flags
|=
2072 RADEON_PM_MODE_NO_DISPLAY
;
2076 static int radeon_atombios_parse_power_table_1_3(struct radeon_device
*rdev
)
2078 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
2079 u32 misc
, misc2
= 0;
2080 int num_modes
= 0, i
;
2081 int state_index
= 0;
2082 struct radeon_i2c_bus_rec i2c_bus
;
2083 union power_info
*power_info
;
2084 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
2088 if (!atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
2089 &frev
, &crev
, &data_offset
))
2091 power_info
= (union power_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
2093 /* add the i2c bus for thermal/fan chip */
2094 if ((power_info
->info
.ucOverdriveThermalController
> 0) &&
2095 (power_info
->info
.ucOverdriveThermalController
< ARRAY_SIZE(thermal_controller_names
))) {
2096 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2097 thermal_controller_names
[power_info
->info
.ucOverdriveThermalController
],
2098 power_info
->info
.ucOverdriveControllerAddress
>> 1);
2099 i2c_bus
= radeon_lookup_i2c_gpio(rdev
, power_info
->info
.ucOverdriveI2cLine
);
2100 rdev
->pm
.i2c_bus
= radeon_i2c_lookup(rdev
, &i2c_bus
);
2101 if (rdev
->pm
.i2c_bus
) {
2102 struct i2c_board_info info
= { };
2103 const char *name
= thermal_controller_names
[power_info
->info
.
2104 ucOverdriveThermalController
];
2105 info
.addr
= power_info
->info
.ucOverdriveControllerAddress
>> 1;
2106 strlcpy(info
.type
, name
, sizeof(info
.type
));
2107 i2c_new_client_device(&rdev
->pm
.i2c_bus
->adapter
, &info
);
2110 num_modes
= power_info
->info
.ucNumOfPowerModeEntries
;
2111 if (num_modes
> ATOM_MAX_NUMBEROF_POWER_BLOCK
)
2112 num_modes
= ATOM_MAX_NUMBEROF_POWER_BLOCK
;
2115 rdev
->pm
.power_state
= kcalloc(num_modes
,
2116 sizeof(struct radeon_power_state
),
2118 if (!rdev
->pm
.power_state
)
2120 /* last mode is usually default, array is low to high */
2121 for (i
= 0; i
< num_modes
; i
++) {
2122 rdev
->pm
.power_state
[state_index
].clock_info
=
2123 kcalloc(1, sizeof(struct radeon_pm_clock_info
),
2125 if (!rdev
->pm
.power_state
[state_index
].clock_info
)
2127 rdev
->pm
.power_state
[state_index
].num_clock_modes
= 1;
2128 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
= VOLTAGE_NONE
;
2131 rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
=
2132 le16_to_cpu(power_info
->info
.asPowerPlayInfo
[i
].usMemoryClock
);
2133 rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
=
2134 le16_to_cpu(power_info
->info
.asPowerPlayInfo
[i
].usEngineClock
);
2135 /* skip invalid modes */
2136 if ((rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
== 0) ||
2137 (rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
== 0))
2139 rdev
->pm
.power_state
[state_index
].pcie_lanes
=
2140 power_info
->info
.asPowerPlayInfo
[i
].ucNumPciELanes
;
2141 misc
= le32_to_cpu(power_info
->info
.asPowerPlayInfo
[i
].ulMiscInfo
);
2142 if ((misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT
) ||
2143 (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)) {
2144 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
2146 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.gpio
=
2147 radeon_atombios_lookup_gpio(rdev
,
2148 power_info
->info
.asPowerPlayInfo
[i
].ucVoltageDropIndex
);
2149 if (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)
2150 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
2153 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
2155 } else if (misc
& ATOM_PM_MISCINFO_PROGRAM_VOLTAGE
) {
2156 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
2158 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddc_id
=
2159 power_info
->info
.asPowerPlayInfo
[i
].ucVoltageDropIndex
;
2161 rdev
->pm
.power_state
[state_index
].flags
= RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
2162 radeon_atombios_parse_misc_flags_1_3(rdev
, state_index
, misc
, 0);
2166 rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
=
2167 le32_to_cpu(power_info
->info_2
.asPowerPlayInfo
[i
].ulMemoryClock
);
2168 rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
=
2169 le32_to_cpu(power_info
->info_2
.asPowerPlayInfo
[i
].ulEngineClock
);
2170 /* skip invalid modes */
2171 if ((rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
== 0) ||
2172 (rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
== 0))
2174 rdev
->pm
.power_state
[state_index
].pcie_lanes
=
2175 power_info
->info_2
.asPowerPlayInfo
[i
].ucNumPciELanes
;
2176 misc
= le32_to_cpu(power_info
->info_2
.asPowerPlayInfo
[i
].ulMiscInfo
);
2177 misc2
= le32_to_cpu(power_info
->info_2
.asPowerPlayInfo
[i
].ulMiscInfo2
);
2178 if ((misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT
) ||
2179 (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)) {
2180 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
2182 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.gpio
=
2183 radeon_atombios_lookup_gpio(rdev
,
2184 power_info
->info_2
.asPowerPlayInfo
[i
].ucVoltageDropIndex
);
2185 if (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)
2186 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
2189 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
2191 } else if (misc
& ATOM_PM_MISCINFO_PROGRAM_VOLTAGE
) {
2192 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
2194 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddc_id
=
2195 power_info
->info_2
.asPowerPlayInfo
[i
].ucVoltageDropIndex
;
2197 rdev
->pm
.power_state
[state_index
].flags
= RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
2198 radeon_atombios_parse_misc_flags_1_3(rdev
, state_index
, misc
, misc2
);
2202 rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
=
2203 le32_to_cpu(power_info
->info_3
.asPowerPlayInfo
[i
].ulMemoryClock
);
2204 rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
=
2205 le32_to_cpu(power_info
->info_3
.asPowerPlayInfo
[i
].ulEngineClock
);
2206 /* skip invalid modes */
2207 if ((rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
== 0) ||
2208 (rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
== 0))
2210 rdev
->pm
.power_state
[state_index
].pcie_lanes
=
2211 power_info
->info_3
.asPowerPlayInfo
[i
].ucNumPciELanes
;
2212 misc
= le32_to_cpu(power_info
->info_3
.asPowerPlayInfo
[i
].ulMiscInfo
);
2213 misc2
= le32_to_cpu(power_info
->info_3
.asPowerPlayInfo
[i
].ulMiscInfo2
);
2214 if ((misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT
) ||
2215 (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)) {
2216 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
2218 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.gpio
=
2219 radeon_atombios_lookup_gpio(rdev
,
2220 power_info
->info_3
.asPowerPlayInfo
[i
].ucVoltageDropIndex
);
2221 if (misc
& ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH
)
2222 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
2225 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.active_high
=
2227 } else if (misc
& ATOM_PM_MISCINFO_PROGRAM_VOLTAGE
) {
2228 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
=
2230 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddc_id
=
2231 power_info
->info_3
.asPowerPlayInfo
[i
].ucVoltageDropIndex
;
2232 if (misc2
& ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN
) {
2233 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddci_enabled
=
2235 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddci_id
=
2236 power_info
->info_3
.asPowerPlayInfo
[i
].ucVDDCI_VoltageDropIndex
;
2239 rdev
->pm
.power_state
[state_index
].flags
= RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
2240 radeon_atombios_parse_misc_flags_1_3(rdev
, state_index
, misc
, misc2
);
2245 /* last mode is usually default */
2246 if (rdev
->pm
.default_power_state_index
== -1) {
2247 rdev
->pm
.power_state
[state_index
- 1].type
=
2248 POWER_STATE_TYPE_DEFAULT
;
2249 rdev
->pm
.default_power_state_index
= state_index
- 1;
2250 rdev
->pm
.power_state
[state_index
- 1].default_clock_mode
=
2251 &rdev
->pm
.power_state
[state_index
- 1].clock_info
[0];
2252 rdev
->pm
.power_state
[state_index
].flags
&=
2253 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
2254 rdev
->pm
.power_state
[state_index
].misc
= 0;
2255 rdev
->pm
.power_state
[state_index
].misc2
= 0;
2260 static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device
*rdev
,
2261 ATOM_PPLIB_THERMALCONTROLLER
*controller
)
2263 struct radeon_i2c_bus_rec i2c_bus
;
2265 /* add the i2c bus for thermal/fan chip */
2266 if (controller
->ucType
> 0) {
2267 if (controller
->ucFanParameters
& ATOM_PP_FANPARAMETERS_NOFAN
)
2268 rdev
->pm
.no_fan
= true;
2269 rdev
->pm
.fan_pulses_per_revolution
=
2270 controller
->ucFanParameters
& ATOM_PP_FANPARAMETERS_TACHOMETER_PULSES_PER_REVOLUTION_MASK
;
2271 if (rdev
->pm
.fan_pulses_per_revolution
) {
2272 rdev
->pm
.fan_min_rpm
= controller
->ucFanMinRPM
;
2273 rdev
->pm
.fan_max_rpm
= controller
->ucFanMaxRPM
;
2275 if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_RV6xx
) {
2276 DRM_INFO("Internal thermal controller %s fan control\n",
2277 (controller
->ucFanParameters
&
2278 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2279 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_RV6XX
;
2280 } else if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_RV770
) {
2281 DRM_INFO("Internal thermal controller %s fan control\n",
2282 (controller
->ucFanParameters
&
2283 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2284 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_RV770
;
2285 } else if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_EVERGREEN
) {
2286 DRM_INFO("Internal thermal controller %s fan control\n",
2287 (controller
->ucFanParameters
&
2288 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2289 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_EVERGREEN
;
2290 } else if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_SUMO
) {
2291 DRM_INFO("Internal thermal controller %s fan control\n",
2292 (controller
->ucFanParameters
&
2293 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2294 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_SUMO
;
2295 } else if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_NISLANDS
) {
2296 DRM_INFO("Internal thermal controller %s fan control\n",
2297 (controller
->ucFanParameters
&
2298 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2299 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_NI
;
2300 } else if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_SISLANDS
) {
2301 DRM_INFO("Internal thermal controller %s fan control\n",
2302 (controller
->ucFanParameters
&
2303 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2304 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_SI
;
2305 } else if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_CISLANDS
) {
2306 DRM_INFO("Internal thermal controller %s fan control\n",
2307 (controller
->ucFanParameters
&
2308 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2309 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_CI
;
2310 } else if (controller
->ucType
== ATOM_PP_THERMALCONTROLLER_KAVERI
) {
2311 DRM_INFO("Internal thermal controller %s fan control\n",
2312 (controller
->ucFanParameters
&
2313 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2314 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_KV
;
2315 } else if (controller
->ucType
==
2316 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO
) {
2317 DRM_INFO("External GPIO thermal controller %s fan control\n",
2318 (controller
->ucFanParameters
&
2319 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2320 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_EXTERNAL_GPIO
;
2321 } else if (controller
->ucType
==
2322 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL
) {
2323 DRM_INFO("ADT7473 with internal thermal controller %s fan control\n",
2324 (controller
->ucFanParameters
&
2325 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2326 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_ADT7473_WITH_INTERNAL
;
2327 } else if (controller
->ucType
==
2328 ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL
) {
2329 DRM_INFO("EMC2103 with internal thermal controller %s fan control\n",
2330 (controller
->ucFanParameters
&
2331 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2332 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_EMC2103_WITH_INTERNAL
;
2333 } else if (controller
->ucType
< ARRAY_SIZE(pp_lib_thermal_controller_names
)) {
2334 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2335 pp_lib_thermal_controller_names
[controller
->ucType
],
2336 controller
->ucI2cAddress
>> 1,
2337 (controller
->ucFanParameters
&
2338 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2339 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_EXTERNAL
;
2340 i2c_bus
= radeon_lookup_i2c_gpio(rdev
, controller
->ucI2cLine
);
2341 rdev
->pm
.i2c_bus
= radeon_i2c_lookup(rdev
, &i2c_bus
);
2342 if (rdev
->pm
.i2c_bus
) {
2343 struct i2c_board_info info
= { };
2344 const char *name
= pp_lib_thermal_controller_names
[controller
->ucType
];
2345 info
.addr
= controller
->ucI2cAddress
>> 1;
2346 strlcpy(info
.type
, name
, sizeof(info
.type
));
2347 i2c_new_client_device(&rdev
->pm
.i2c_bus
->adapter
, &info
);
2350 DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
2352 controller
->ucI2cAddress
>> 1,
2353 (controller
->ucFanParameters
&
2354 ATOM_PP_FANPARAMETERS_NOFAN
) ? "without" : "with");
2359 void radeon_atombios_get_default_voltages(struct radeon_device
*rdev
,
2360 u16
*vddc
, u16
*vddci
, u16
*mvdd
)
2362 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
2363 int index
= GetIndexIntoMasterTable(DATA
, FirmwareInfo
);
2366 union firmware_info
*firmware_info
;
2372 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
2373 &frev
, &crev
, &data_offset
)) {
2375 (union firmware_info
*)(mode_info
->atom_context
->bios
+
2377 *vddc
= le16_to_cpu(firmware_info
->info_14
.usBootUpVDDCVoltage
);
2378 if ((frev
== 2) && (crev
>= 2)) {
2379 *vddci
= le16_to_cpu(firmware_info
->info_22
.usBootUpVDDCIVoltage
);
2380 *mvdd
= le16_to_cpu(firmware_info
->info_22
.usBootUpMVDDCVoltage
);
2385 static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device
*rdev
,
2386 int state_index
, int mode_index
,
2387 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
)
2390 u32 misc
= le32_to_cpu(non_clock_info
->ulCapsAndSettings
);
2391 u32 misc2
= le16_to_cpu(non_clock_info
->usClassification
);
2392 u16 vddc
, vddci
, mvdd
;
2394 radeon_atombios_get_default_voltages(rdev
, &vddc
, &vddci
, &mvdd
);
2396 rdev
->pm
.power_state
[state_index
].misc
= misc
;
2397 rdev
->pm
.power_state
[state_index
].misc2
= misc2
;
2398 rdev
->pm
.power_state
[state_index
].pcie_lanes
=
2399 ((misc
& ATOM_PPLIB_PCIE_LINK_WIDTH_MASK
) >>
2400 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT
) + 1;
2401 switch (misc2
& ATOM_PPLIB_CLASSIFICATION_UI_MASK
) {
2402 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY
:
2403 rdev
->pm
.power_state
[state_index
].type
=
2404 POWER_STATE_TYPE_BATTERY
;
2406 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED
:
2407 rdev
->pm
.power_state
[state_index
].type
=
2408 POWER_STATE_TYPE_BALANCED
;
2410 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE
:
2411 rdev
->pm
.power_state
[state_index
].type
=
2412 POWER_STATE_TYPE_PERFORMANCE
;
2414 case ATOM_PPLIB_CLASSIFICATION_UI_NONE
:
2415 if (misc2
& ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE
)
2416 rdev
->pm
.power_state
[state_index
].type
=
2417 POWER_STATE_TYPE_PERFORMANCE
;
2420 rdev
->pm
.power_state
[state_index
].flags
= 0;
2421 if (misc
& ATOM_PPLIB_SINGLE_DISPLAY_ONLY
)
2422 rdev
->pm
.power_state
[state_index
].flags
|=
2423 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
;
2424 if (misc2
& ATOM_PPLIB_CLASSIFICATION_BOOT
) {
2425 rdev
->pm
.power_state
[state_index
].type
=
2426 POWER_STATE_TYPE_DEFAULT
;
2427 rdev
->pm
.default_power_state_index
= state_index
;
2428 rdev
->pm
.power_state
[state_index
].default_clock_mode
=
2429 &rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
- 1];
2430 if ((rdev
->family
>= CHIP_BARTS
) && !(rdev
->flags
& RADEON_IS_IGP
)) {
2431 /* NI chips post without MC ucode, so default clocks are strobe mode only */
2432 rdev
->pm
.default_sclk
= rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
;
2433 rdev
->pm
.default_mclk
= rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
;
2434 rdev
->pm
.default_vddc
= rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.voltage
;
2435 rdev
->pm
.default_vddci
= rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.vddci
;
2439 if (ASIC_IS_DCE4(rdev
))
2440 radeon_atom_get_max_voltage(rdev
,
2441 SET_VOLTAGE_TYPE_ASIC_VDDCI
,
2443 /* patch the table values with the default sclk/mclk from firmware info */
2444 for (j
= 0; j
< mode_index
; j
++) {
2445 rdev
->pm
.power_state
[state_index
].clock_info
[j
].mclk
=
2446 rdev
->clock
.default_mclk
;
2447 rdev
->pm
.power_state
[state_index
].clock_info
[j
].sclk
=
2448 rdev
->clock
.default_sclk
;
2450 rdev
->pm
.power_state
[state_index
].clock_info
[j
].voltage
.voltage
=
2453 rdev
->pm
.power_state
[state_index
].clock_info
[j
].voltage
.vddci
=
2460 static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device
*rdev
,
2461 int state_index
, int mode_index
,
2462 union pplib_clock_info
*clock_info
)
2467 if (rdev
->flags
& RADEON_IS_IGP
) {
2468 if (rdev
->family
>= CHIP_PALM
) {
2469 sclk
= le16_to_cpu(clock_info
->sumo
.usEngineClockLow
);
2470 sclk
|= clock_info
->sumo
.ucEngineClockHigh
<< 16;
2471 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
= sclk
;
2473 sclk
= le16_to_cpu(clock_info
->rs780
.usLowEngineClockLow
);
2474 sclk
|= clock_info
->rs780
.ucLowEngineClockHigh
<< 16;
2475 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
= sclk
;
2477 } else if (rdev
->family
>= CHIP_BONAIRE
) {
2478 sclk
= le16_to_cpu(clock_info
->ci
.usEngineClockLow
);
2479 sclk
|= clock_info
->ci
.ucEngineClockHigh
<< 16;
2480 mclk
= le16_to_cpu(clock_info
->ci
.usMemoryClockLow
);
2481 mclk
|= clock_info
->ci
.ucMemoryClockHigh
<< 16;
2482 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].mclk
= mclk
;
2483 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
= sclk
;
2484 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.type
=
2486 } else if (rdev
->family
>= CHIP_TAHITI
) {
2487 sclk
= le16_to_cpu(clock_info
->si
.usEngineClockLow
);
2488 sclk
|= clock_info
->si
.ucEngineClockHigh
<< 16;
2489 mclk
= le16_to_cpu(clock_info
->si
.usMemoryClockLow
);
2490 mclk
|= clock_info
->si
.ucMemoryClockHigh
<< 16;
2491 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].mclk
= mclk
;
2492 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
= sclk
;
2493 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.type
=
2495 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.voltage
=
2496 le16_to_cpu(clock_info
->si
.usVDDC
);
2497 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.vddci
=
2498 le16_to_cpu(clock_info
->si
.usVDDCI
);
2499 } else if (rdev
->family
>= CHIP_CEDAR
) {
2500 sclk
= le16_to_cpu(clock_info
->evergreen
.usEngineClockLow
);
2501 sclk
|= clock_info
->evergreen
.ucEngineClockHigh
<< 16;
2502 mclk
= le16_to_cpu(clock_info
->evergreen
.usMemoryClockLow
);
2503 mclk
|= clock_info
->evergreen
.ucMemoryClockHigh
<< 16;
2504 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].mclk
= mclk
;
2505 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
= sclk
;
2506 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.type
=
2508 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.voltage
=
2509 le16_to_cpu(clock_info
->evergreen
.usVDDC
);
2510 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.vddci
=
2511 le16_to_cpu(clock_info
->evergreen
.usVDDCI
);
2513 sclk
= le16_to_cpu(clock_info
->r600
.usEngineClockLow
);
2514 sclk
|= clock_info
->r600
.ucEngineClockHigh
<< 16;
2515 mclk
= le16_to_cpu(clock_info
->r600
.usMemoryClockLow
);
2516 mclk
|= clock_info
->r600
.ucMemoryClockHigh
<< 16;
2517 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].mclk
= mclk
;
2518 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
= sclk
;
2519 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.type
=
2521 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.voltage
=
2522 le16_to_cpu(clock_info
->r600
.usVDDC
);
2525 /* patch up vddc if necessary */
2526 switch (rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.voltage
) {
2527 case ATOM_VIRTUAL_VOLTAGE_ID0
:
2528 case ATOM_VIRTUAL_VOLTAGE_ID1
:
2529 case ATOM_VIRTUAL_VOLTAGE_ID2
:
2530 case ATOM_VIRTUAL_VOLTAGE_ID3
:
2531 case ATOM_VIRTUAL_VOLTAGE_ID4
:
2532 case ATOM_VIRTUAL_VOLTAGE_ID5
:
2533 case ATOM_VIRTUAL_VOLTAGE_ID6
:
2534 case ATOM_VIRTUAL_VOLTAGE_ID7
:
2535 if (radeon_atom_get_max_vddc(rdev
, VOLTAGE_TYPE_VDDC
,
2536 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.voltage
,
2538 rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].voltage
.voltage
= vddc
;
2544 if (rdev
->flags
& RADEON_IS_IGP
) {
2545 /* skip invalid modes */
2546 if (rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
== 0)
2549 /* skip invalid modes */
2550 if ((rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].mclk
== 0) ||
2551 (rdev
->pm
.power_state
[state_index
].clock_info
[mode_index
].sclk
== 0))
2557 static int radeon_atombios_parse_power_table_4_5(struct radeon_device
*rdev
)
2559 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
2560 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
;
2561 union pplib_power_state
*power_state
;
2563 int state_index
= 0, mode_index
= 0;
2564 union pplib_clock_info
*clock_info
;
2566 union power_info
*power_info
;
2567 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
2571 if (!atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
2572 &frev
, &crev
, &data_offset
))
2574 power_info
= (union power_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
2576 radeon_atombios_add_pplib_thermal_controller(rdev
, &power_info
->pplib
.sThermalController
);
2577 if (power_info
->pplib
.ucNumStates
== 0)
2579 rdev
->pm
.power_state
= kcalloc(power_info
->pplib
.ucNumStates
,
2580 sizeof(struct radeon_power_state
),
2582 if (!rdev
->pm
.power_state
)
2584 /* first mode is usually default, followed by low to high */
2585 for (i
= 0; i
< power_info
->pplib
.ucNumStates
; i
++) {
2587 power_state
= (union pplib_power_state
*)
2588 (mode_info
->atom_context
->bios
+ data_offset
+
2589 le16_to_cpu(power_info
->pplib
.usStateArrayOffset
) +
2590 i
* power_info
->pplib
.ucStateEntrySize
);
2591 non_clock_info
= (struct _ATOM_PPLIB_NONCLOCK_INFO
*)
2592 (mode_info
->atom_context
->bios
+ data_offset
+
2593 le16_to_cpu(power_info
->pplib
.usNonClockInfoArrayOffset
) +
2594 (power_state
->v1
.ucNonClockStateIndex
*
2595 power_info
->pplib
.ucNonClockSize
));
2596 rdev
->pm
.power_state
[i
].clock_info
=
2597 kcalloc((power_info
->pplib
.ucStateEntrySize
- 1) ?
2598 (power_info
->pplib
.ucStateEntrySize
- 1) : 1,
2599 sizeof(struct radeon_pm_clock_info
),
2601 if (!rdev
->pm
.power_state
[i
].clock_info
)
2603 if (power_info
->pplib
.ucStateEntrySize
- 1) {
2604 for (j
= 0; j
< (power_info
->pplib
.ucStateEntrySize
- 1); j
++) {
2605 clock_info
= (union pplib_clock_info
*)
2606 (mode_info
->atom_context
->bios
+ data_offset
+
2607 le16_to_cpu(power_info
->pplib
.usClockInfoArrayOffset
) +
2608 (power_state
->v1
.ucClockStateIndices
[j
] *
2609 power_info
->pplib
.ucClockInfoSize
));
2610 valid
= radeon_atombios_parse_pplib_clock_info(rdev
,
2611 state_index
, mode_index
,
2617 rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
=
2618 rdev
->clock
.default_mclk
;
2619 rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
=
2620 rdev
->clock
.default_sclk
;
2623 rdev
->pm
.power_state
[state_index
].num_clock_modes
= mode_index
;
2625 radeon_atombios_parse_pplib_non_clock_info(rdev
, state_index
, mode_index
,
2630 /* if multiple clock modes, mark the lowest as no display */
2631 for (i
= 0; i
< state_index
; i
++) {
2632 if (rdev
->pm
.power_state
[i
].num_clock_modes
> 1)
2633 rdev
->pm
.power_state
[i
].clock_info
[0].flags
|=
2634 RADEON_PM_MODE_NO_DISPLAY
;
2636 /* first mode is usually default */
2637 if (rdev
->pm
.default_power_state_index
== -1) {
2638 rdev
->pm
.power_state
[0].type
=
2639 POWER_STATE_TYPE_DEFAULT
;
2640 rdev
->pm
.default_power_state_index
= 0;
2641 rdev
->pm
.power_state
[0].default_clock_mode
=
2642 &rdev
->pm
.power_state
[0].clock_info
[0];
2647 static int radeon_atombios_parse_power_table_6(struct radeon_device
*rdev
)
2649 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
2650 struct _ATOM_PPLIB_NONCLOCK_INFO
*non_clock_info
;
2651 union pplib_power_state
*power_state
;
2652 int i
, j
, non_clock_array_index
, clock_array_index
;
2653 int state_index
= 0, mode_index
= 0;
2654 union pplib_clock_info
*clock_info
;
2655 struct _StateArray
*state_array
;
2656 struct _ClockInfoArray
*clock_info_array
;
2657 struct _NonClockInfoArray
*non_clock_info_array
;
2659 union power_info
*power_info
;
2660 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
2663 u8
*power_state_offset
;
2665 if (!atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
2666 &frev
, &crev
, &data_offset
))
2668 power_info
= (union power_info
*)(mode_info
->atom_context
->bios
+ data_offset
);
2670 radeon_atombios_add_pplib_thermal_controller(rdev
, &power_info
->pplib
.sThermalController
);
2671 state_array
= (struct _StateArray
*)
2672 (mode_info
->atom_context
->bios
+ data_offset
+
2673 le16_to_cpu(power_info
->pplib
.usStateArrayOffset
));
2674 clock_info_array
= (struct _ClockInfoArray
*)
2675 (mode_info
->atom_context
->bios
+ data_offset
+
2676 le16_to_cpu(power_info
->pplib
.usClockInfoArrayOffset
));
2677 non_clock_info_array
= (struct _NonClockInfoArray
*)
2678 (mode_info
->atom_context
->bios
+ data_offset
+
2679 le16_to_cpu(power_info
->pplib
.usNonClockInfoArrayOffset
));
2680 if (state_array
->ucNumEntries
== 0)
2682 rdev
->pm
.power_state
= kcalloc(state_array
->ucNumEntries
,
2683 sizeof(struct radeon_power_state
),
2685 if (!rdev
->pm
.power_state
)
2687 power_state_offset
= (u8
*)state_array
->states
;
2688 for (i
= 0; i
< state_array
->ucNumEntries
; i
++) {
2690 power_state
= (union pplib_power_state
*)power_state_offset
;
2691 non_clock_array_index
= power_state
->v2
.nonClockInfoIndex
;
2692 non_clock_info
= (struct _ATOM_PPLIB_NONCLOCK_INFO
*)
2693 &non_clock_info_array
->nonClockInfo
[non_clock_array_index
];
2694 rdev
->pm
.power_state
[i
].clock_info
=
2695 kcalloc(power_state
->v2
.ucNumDPMLevels
?
2696 power_state
->v2
.ucNumDPMLevels
: 1,
2697 sizeof(struct radeon_pm_clock_info
),
2699 if (!rdev
->pm
.power_state
[i
].clock_info
)
2701 if (power_state
->v2
.ucNumDPMLevels
) {
2702 for (j
= 0; j
< power_state
->v2
.ucNumDPMLevels
; j
++) {
2703 clock_array_index
= power_state
->v2
.clockInfoIndex
[j
];
2704 clock_info
= (union pplib_clock_info
*)
2705 &clock_info_array
->clockInfo
[clock_array_index
* clock_info_array
->ucEntrySize
];
2706 valid
= radeon_atombios_parse_pplib_clock_info(rdev
,
2707 state_index
, mode_index
,
2713 rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
=
2714 rdev
->clock
.default_mclk
;
2715 rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
=
2716 rdev
->clock
.default_sclk
;
2719 rdev
->pm
.power_state
[state_index
].num_clock_modes
= mode_index
;
2721 radeon_atombios_parse_pplib_non_clock_info(rdev
, state_index
, mode_index
,
2725 power_state_offset
+= 2 + power_state
->v2
.ucNumDPMLevels
;
2727 /* if multiple clock modes, mark the lowest as no display */
2728 for (i
= 0; i
< state_index
; i
++) {
2729 if (rdev
->pm
.power_state
[i
].num_clock_modes
> 1)
2730 rdev
->pm
.power_state
[i
].clock_info
[0].flags
|=
2731 RADEON_PM_MODE_NO_DISPLAY
;
2733 /* first mode is usually default */
2734 if (rdev
->pm
.default_power_state_index
== -1) {
2735 rdev
->pm
.power_state
[0].type
=
2736 POWER_STATE_TYPE_DEFAULT
;
2737 rdev
->pm
.default_power_state_index
= 0;
2738 rdev
->pm
.power_state
[0].default_clock_mode
=
2739 &rdev
->pm
.power_state
[0].clock_info
[0];
2744 void radeon_atombios_get_power_modes(struct radeon_device
*rdev
)
2746 struct radeon_mode_info
*mode_info
= &rdev
->mode_info
;
2747 int index
= GetIndexIntoMasterTable(DATA
, PowerPlayInfo
);
2750 int state_index
= 0;
2752 rdev
->pm
.default_power_state_index
= -1;
2754 if (atom_parse_data_header(mode_info
->atom_context
, index
, NULL
,
2755 &frev
, &crev
, &data_offset
)) {
2760 state_index
= radeon_atombios_parse_power_table_1_3(rdev
);
2764 state_index
= radeon_atombios_parse_power_table_4_5(rdev
);
2767 state_index
= radeon_atombios_parse_power_table_6(rdev
);
2774 if (state_index
== 0) {
2775 rdev
->pm
.power_state
= kzalloc(sizeof(struct radeon_power_state
), GFP_KERNEL
);
2776 if (rdev
->pm
.power_state
) {
2777 rdev
->pm
.power_state
[0].clock_info
=
2779 sizeof(struct radeon_pm_clock_info
),
2781 if (rdev
->pm
.power_state
[0].clock_info
) {
2782 /* add the default mode */
2783 rdev
->pm
.power_state
[state_index
].type
=
2784 POWER_STATE_TYPE_DEFAULT
;
2785 rdev
->pm
.power_state
[state_index
].num_clock_modes
= 1;
2786 rdev
->pm
.power_state
[state_index
].clock_info
[0].mclk
= rdev
->clock
.default_mclk
;
2787 rdev
->pm
.power_state
[state_index
].clock_info
[0].sclk
= rdev
->clock
.default_sclk
;
2788 rdev
->pm
.power_state
[state_index
].default_clock_mode
=
2789 &rdev
->pm
.power_state
[state_index
].clock_info
[0];
2790 rdev
->pm
.power_state
[state_index
].clock_info
[0].voltage
.type
= VOLTAGE_NONE
;
2791 rdev
->pm
.power_state
[state_index
].pcie_lanes
= 16;
2792 rdev
->pm
.default_power_state_index
= state_index
;
2793 rdev
->pm
.power_state
[state_index
].flags
= 0;
2799 rdev
->pm
.num_power_states
= state_index
;
2801 rdev
->pm
.current_power_state_index
= rdev
->pm
.default_power_state_index
;
2802 rdev
->pm
.current_clock_mode_index
= 0;
2803 if (rdev
->pm
.default_power_state_index
>= 0)
2804 rdev
->pm
.current_vddc
=
2805 rdev
->pm
.power_state
[rdev
->pm
.default_power_state_index
].clock_info
[0].voltage
.voltage
;
2807 rdev
->pm
.current_vddc
= 0;
2810 union get_clock_dividers
{
2811 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS v1
;
2812 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2 v2
;
2813 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3 v3
;
2814 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V4 v4
;
2815 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V5 v5
;
2816 struct _COMPUTE_GPU_CLOCK_INPUT_PARAMETERS_V1_6 v6_in
;
2817 struct _COMPUTE_GPU_CLOCK_OUTPUT_PARAMETERS_V1_6 v6_out
;
2820 int radeon_atom_get_clock_dividers(struct radeon_device
*rdev
,
2824 struct atom_clock_dividers
*dividers
)
2826 union get_clock_dividers args
;
2827 int index
= GetIndexIntoMasterTable(COMMAND
, ComputeMemoryEnginePLL
);
2830 memset(&args
, 0, sizeof(args
));
2831 memset(dividers
, 0, sizeof(struct atom_clock_dividers
));
2833 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
2839 args
.v1
.ucAction
= clock_type
;
2840 args
.v1
.ulClock
= cpu_to_le32(clock
); /* 10 khz */
2842 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2844 dividers
->post_div
= args
.v1
.ucPostDiv
;
2845 dividers
->fb_div
= args
.v1
.ucFbDiv
;
2846 dividers
->enable_post_div
= true;
2851 /* r6xx, r7xx, evergreen, ni, si */
2852 if (rdev
->family
<= CHIP_RV770
) {
2853 args
.v2
.ucAction
= clock_type
;
2854 args
.v2
.ulClock
= cpu_to_le32(clock
); /* 10 khz */
2856 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2858 dividers
->post_div
= args
.v2
.ucPostDiv
;
2859 dividers
->fb_div
= le16_to_cpu(args
.v2
.usFbDiv
);
2860 dividers
->ref_div
= args
.v2
.ucAction
;
2861 if (rdev
->family
== CHIP_RV770
) {
2862 dividers
->enable_post_div
= (le32_to_cpu(args
.v2
.ulClock
) & (1 << 24)) ?
2864 dividers
->vco_mode
= (le32_to_cpu(args
.v2
.ulClock
) & (1 << 25)) ? 1 : 0;
2866 dividers
->enable_post_div
= (dividers
->fb_div
& 1) ? true : false;
2868 if (clock_type
== COMPUTE_ENGINE_PLL_PARAM
) {
2869 args
.v3
.ulClockParams
= cpu_to_le32((clock_type
<< 24) | clock
);
2871 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2873 dividers
->post_div
= args
.v3
.ucPostDiv
;
2874 dividers
->enable_post_div
= (args
.v3
.ucCntlFlag
&
2875 ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN
) ? true : false;
2876 dividers
->enable_dithen
= (args
.v3
.ucCntlFlag
&
2877 ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE
) ? false : true;
2878 dividers
->whole_fb_div
= le16_to_cpu(args
.v3
.ulFbDiv
.usFbDiv
);
2879 dividers
->frac_fb_div
= le16_to_cpu(args
.v3
.ulFbDiv
.usFbDivFrac
);
2880 dividers
->ref_div
= args
.v3
.ucRefDiv
;
2881 dividers
->vco_mode
= (args
.v3
.ucCntlFlag
&
2882 ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE
) ? 1 : 0;
2884 /* for SI we use ComputeMemoryClockParam for memory plls */
2885 if (rdev
->family
>= CHIP_TAHITI
)
2887 args
.v5
.ulClockParams
= cpu_to_le32((clock_type
<< 24) | clock
);
2889 args
.v5
.ucInputFlag
= ATOM_PLL_INPUT_FLAG_PLL_STROBE_MODE_EN
;
2891 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2893 dividers
->post_div
= args
.v5
.ucPostDiv
;
2894 dividers
->enable_post_div
= (args
.v5
.ucCntlFlag
&
2895 ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN
) ? true : false;
2896 dividers
->enable_dithen
= (args
.v5
.ucCntlFlag
&
2897 ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE
) ? false : true;
2898 dividers
->whole_fb_div
= le16_to_cpu(args
.v5
.ulFbDiv
.usFbDiv
);
2899 dividers
->frac_fb_div
= le16_to_cpu(args
.v5
.ulFbDiv
.usFbDivFrac
);
2900 dividers
->ref_div
= args
.v5
.ucRefDiv
;
2901 dividers
->vco_mode
= (args
.v5
.ucCntlFlag
&
2902 ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE
) ? 1 : 0;
2908 args
.v4
.ulClock
= cpu_to_le32(clock
); /* 10 khz */
2910 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2912 dividers
->post_divider
= dividers
->post_div
= args
.v4
.ucPostDiv
;
2913 dividers
->real_clock
= le32_to_cpu(args
.v4
.ulClock
);
2917 /* COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, COMPUTE_GPUCLK_INPUT_FLAG_SCLK */
2918 args
.v6_in
.ulClock
.ulComputeClockFlag
= clock_type
;
2919 args
.v6_in
.ulClock
.ulClockFreq
= cpu_to_le32(clock
); /* 10 khz */
2921 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2923 dividers
->whole_fb_div
= le16_to_cpu(args
.v6_out
.ulFbDiv
.usFbDiv
);
2924 dividers
->frac_fb_div
= le16_to_cpu(args
.v6_out
.ulFbDiv
.usFbDivFrac
);
2925 dividers
->ref_div
= args
.v6_out
.ucPllRefDiv
;
2926 dividers
->post_div
= args
.v6_out
.ucPllPostDiv
;
2927 dividers
->flags
= args
.v6_out
.ucPllCntlFlag
;
2928 dividers
->real_clock
= le32_to_cpu(args
.v6_out
.ulClock
.ulClock
);
2929 dividers
->post_divider
= args
.v6_out
.ulClock
.ucPostDiv
;
2937 int radeon_atom_get_memory_pll_dividers(struct radeon_device
*rdev
,
2940 struct atom_mpll_param
*mpll_param
)
2942 COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args
;
2943 int index
= GetIndexIntoMasterTable(COMMAND
, ComputeMemoryClockParam
);
2946 memset(&args
, 0, sizeof(args
));
2947 memset(mpll_param
, 0, sizeof(struct atom_mpll_param
));
2949 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
2957 args
.ulClock
= cpu_to_le32(clock
); /* 10 khz */
2958 args
.ucInputFlag
= 0;
2960 args
.ucInputFlag
|= MPLL_INPUT_FLAG_STROBE_MODE_EN
;
2962 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2964 mpll_param
->clkfrac
= le16_to_cpu(args
.ulFbDiv
.usFbDivFrac
);
2965 mpll_param
->clkf
= le16_to_cpu(args
.ulFbDiv
.usFbDiv
);
2966 mpll_param
->post_div
= args
.ucPostDiv
;
2967 mpll_param
->dll_speed
= args
.ucDllSpeed
;
2968 mpll_param
->bwcntl
= args
.ucBWCntl
;
2969 mpll_param
->vco_mode
=
2970 (args
.ucPllCntlFlag
& MPLL_CNTL_FLAG_VCO_MODE_MASK
);
2971 mpll_param
->yclk_sel
=
2972 (args
.ucPllCntlFlag
& MPLL_CNTL_FLAG_BYPASS_DQ_PLL
) ? 1 : 0;
2974 (args
.ucPllCntlFlag
& MPLL_CNTL_FLAG_QDR_ENABLE
) ? 1 : 0;
2975 mpll_param
->half_rate
=
2976 (args
.ucPllCntlFlag
& MPLL_CNTL_FLAG_AD_HALF_RATE
) ? 1 : 0;
2988 void radeon_atom_set_clock_gating(struct radeon_device
*rdev
, int enable
)
2990 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args
;
2991 int index
= GetIndexIntoMasterTable(COMMAND
, DynamicClockGating
);
2993 args
.ucEnable
= enable
;
2995 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
2998 uint32_t radeon_atom_get_engine_clock(struct radeon_device
*rdev
)
3000 GET_ENGINE_CLOCK_PS_ALLOCATION args
;
3001 int index
= GetIndexIntoMasterTable(COMMAND
, GetEngineClock
);
3003 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3004 return le32_to_cpu(args
.ulReturnEngineClock
);
3007 uint32_t radeon_atom_get_memory_clock(struct radeon_device
*rdev
)
3009 GET_MEMORY_CLOCK_PS_ALLOCATION args
;
3010 int index
= GetIndexIntoMasterTable(COMMAND
, GetMemoryClock
);
3012 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3013 return le32_to_cpu(args
.ulReturnMemoryClock
);
3016 void radeon_atom_set_engine_clock(struct radeon_device
*rdev
,
3019 SET_ENGINE_CLOCK_PS_ALLOCATION args
;
3020 int index
= GetIndexIntoMasterTable(COMMAND
, SetEngineClock
);
3022 args
.ulTargetEngineClock
= cpu_to_le32(eng_clock
); /* 10 khz */
3024 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3027 void radeon_atom_set_memory_clock(struct radeon_device
*rdev
,
3030 SET_MEMORY_CLOCK_PS_ALLOCATION args
;
3031 int index
= GetIndexIntoMasterTable(COMMAND
, SetMemoryClock
);
3033 if (rdev
->flags
& RADEON_IS_IGP
)
3036 args
.ulTargetMemoryClock
= cpu_to_le32(mem_clock
); /* 10 khz */
3038 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3041 void radeon_atom_set_engine_dram_timings(struct radeon_device
*rdev
,
3042 u32 eng_clock
, u32 mem_clock
)
3044 SET_ENGINE_CLOCK_PS_ALLOCATION args
;
3045 int index
= GetIndexIntoMasterTable(COMMAND
, DynamicMemorySettings
);
3048 memset(&args
, 0, sizeof(args
));
3050 tmp
= eng_clock
& SET_CLOCK_FREQ_MASK
;
3051 tmp
|= (COMPUTE_ENGINE_PLL_PARAM
<< 24);
3053 args
.ulTargetEngineClock
= cpu_to_le32(tmp
);
3055 args
.sReserved
.ulClock
= cpu_to_le32(mem_clock
& SET_CLOCK_FREQ_MASK
);
3057 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3060 void radeon_atom_update_memory_dll(struct radeon_device
*rdev
,
3064 int index
= GetIndexIntoMasterTable(COMMAND
, DynamicMemorySettings
);
3066 args
= cpu_to_le32(mem_clock
); /* 10 khz */
3068 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3071 void radeon_atom_set_ac_timing(struct radeon_device
*rdev
,
3074 SET_MEMORY_CLOCK_PS_ALLOCATION args
;
3075 int index
= GetIndexIntoMasterTable(COMMAND
, DynamicMemorySettings
);
3076 u32 tmp
= mem_clock
| (COMPUTE_MEMORY_PLL_PARAM
<< 24);
3078 args
.ulTargetMemoryClock
= cpu_to_le32(tmp
); /* 10 khz */
3080 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3084 struct _SET_VOLTAGE_PS_ALLOCATION alloc
;
3085 struct _SET_VOLTAGE_PARAMETERS v1
;
3086 struct _SET_VOLTAGE_PARAMETERS_V2 v2
;
3087 struct _SET_VOLTAGE_PARAMETERS_V1_3 v3
;
3090 void radeon_atom_set_voltage(struct radeon_device
*rdev
, u16 voltage_level
, u8 voltage_type
)
3092 union set_voltage args
;
3093 int index
= GetIndexIntoMasterTable(COMMAND
, SetVoltage
);
3094 u8 frev
, crev
, volt_index
= voltage_level
;
3096 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
3099 /* 0xff01 is a flag rather then an actual voltage */
3100 if (voltage_level
== 0xff01)
3105 args
.v1
.ucVoltageType
= voltage_type
;
3106 args
.v1
.ucVoltageMode
= SET_ASIC_VOLTAGE_MODE_ALL_SOURCE
;
3107 args
.v1
.ucVoltageIndex
= volt_index
;
3110 args
.v2
.ucVoltageType
= voltage_type
;
3111 args
.v2
.ucVoltageMode
= SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE
;
3112 args
.v2
.usVoltageLevel
= cpu_to_le16(voltage_level
);
3115 args
.v3
.ucVoltageType
= voltage_type
;
3116 args
.v3
.ucVoltageMode
= ATOM_SET_VOLTAGE
;
3117 args
.v3
.usVoltageLevel
= cpu_to_le16(voltage_level
);
3120 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3124 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3127 int radeon_atom_get_max_vddc(struct radeon_device
*rdev
, u8 voltage_type
,
3128 u16 voltage_id
, u16
*voltage
)
3130 union set_voltage args
;
3131 int index
= GetIndexIntoMasterTable(COMMAND
, SetVoltage
);
3134 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
3141 args
.v2
.ucVoltageType
= SET_VOLTAGE_GET_MAX_VOLTAGE
;
3142 args
.v2
.ucVoltageMode
= 0;
3143 args
.v2
.usVoltageLevel
= 0;
3145 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3147 *voltage
= le16_to_cpu(args
.v2
.usVoltageLevel
);
3150 args
.v3
.ucVoltageType
= voltage_type
;
3151 args
.v3
.ucVoltageMode
= ATOM_GET_VOLTAGE_LEVEL
;
3152 args
.v3
.usVoltageLevel
= cpu_to_le16(voltage_id
);
3154 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3156 *voltage
= le16_to_cpu(args
.v3
.usVoltageLevel
);
3159 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3166 int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device
*rdev
,
3170 return radeon_atom_get_max_vddc(rdev
, VOLTAGE_TYPE_VDDC
, leakage_idx
, voltage
);
3173 int radeon_atom_get_leakage_id_from_vbios(struct radeon_device
*rdev
,
3176 union set_voltage args
;
3177 int index
= GetIndexIntoMasterTable(COMMAND
, SetVoltage
);
3180 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
3186 args
.v3
.ucVoltageType
= 0;
3187 args
.v3
.ucVoltageMode
= ATOM_GET_LEAKAGE_ID
;
3188 args
.v3
.usVoltageLevel
= 0;
3190 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3192 *leakage_id
= le16_to_cpu(args
.v3
.usVoltageLevel
);
3195 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3202 int radeon_atom_get_leakage_vddc_based_on_leakage_params(struct radeon_device
*rdev
,
3203 u16
*vddc
, u16
*vddci
,
3204 u16 virtual_voltage_id
,
3205 u16 vbios_voltage_id
)
3207 int index
= GetIndexIntoMasterTable(DATA
, ASIC_ProfilingInfo
);
3209 u16 data_offset
, size
;
3211 ATOM_ASIC_PROFILING_INFO_V2_1
*profile
;
3212 u16
*leakage_bin
, *vddc_id_buf
, *vddc_buf
, *vddci_id_buf
, *vddci_buf
;
3217 if (!atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
3218 &frev
, &crev
, &data_offset
))
3221 profile
= (ATOM_ASIC_PROFILING_INFO_V2_1
*)
3222 (rdev
->mode_info
.atom_context
->bios
+ data_offset
);
3230 if (size
< sizeof(ATOM_ASIC_PROFILING_INFO_V2_1
))
3232 leakage_bin
= (u16
*)
3233 (rdev
->mode_info
.atom_context
->bios
+ data_offset
+
3234 le16_to_cpu(profile
->usLeakageBinArrayOffset
));
3235 vddc_id_buf
= (u16
*)
3236 (rdev
->mode_info
.atom_context
->bios
+ data_offset
+
3237 le16_to_cpu(profile
->usElbVDDC_IdArrayOffset
));
3239 (rdev
->mode_info
.atom_context
->bios
+ data_offset
+
3240 le16_to_cpu(profile
->usElbVDDC_LevelArrayOffset
));
3241 vddci_id_buf
= (u16
*)
3242 (rdev
->mode_info
.atom_context
->bios
+ data_offset
+
3243 le16_to_cpu(profile
->usElbVDDCI_IdArrayOffset
));
3245 (rdev
->mode_info
.atom_context
->bios
+ data_offset
+
3246 le16_to_cpu(profile
->usElbVDDCI_LevelArrayOffset
));
3248 if (profile
->ucElbVDDC_Num
> 0) {
3249 for (i
= 0; i
< profile
->ucElbVDDC_Num
; i
++) {
3250 if (vddc_id_buf
[i
] == virtual_voltage_id
) {
3251 for (j
= 0; j
< profile
->ucLeakageBinNum
; j
++) {
3252 if (vbios_voltage_id
<= leakage_bin
[j
]) {
3253 *vddc
= vddc_buf
[j
* profile
->ucElbVDDC_Num
+ i
];
3261 if (profile
->ucElbVDDCI_Num
> 0) {
3262 for (i
= 0; i
< profile
->ucElbVDDCI_Num
; i
++) {
3263 if (vddci_id_buf
[i
] == virtual_voltage_id
) {
3264 for (j
= 0; j
< profile
->ucLeakageBinNum
; j
++) {
3265 if (vbios_voltage_id
<= leakage_bin
[j
]) {
3266 *vddci
= vddci_buf
[j
* profile
->ucElbVDDCI_Num
+ i
];
3276 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3281 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3288 union get_voltage_info
{
3289 struct _GET_VOLTAGE_INFO_INPUT_PARAMETER_V1_2 in
;
3290 struct _GET_EVV_VOLTAGE_INFO_OUTPUT_PARAMETER_V1_2 evv_out
;
3293 int radeon_atom_get_voltage_evv(struct radeon_device
*rdev
,
3294 u16 virtual_voltage_id
,
3297 int index
= GetIndexIntoMasterTable(COMMAND
, GetVoltageInfo
);
3299 u32 count
= rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.count
;
3300 union get_voltage_info args
;
3302 for (entry_id
= 0; entry_id
< count
; entry_id
++) {
3303 if (rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
[entry_id
].v
==
3308 if (entry_id
>= count
)
3311 args
.in
.ucVoltageType
= VOLTAGE_TYPE_VDDC
;
3312 args
.in
.ucVoltageMode
= ATOM_GET_VOLTAGE_EVV_VOLTAGE
;
3313 args
.in
.usVoltageLevel
= cpu_to_le16(virtual_voltage_id
);
3314 args
.in
.ulSCLKFreq
=
3315 cpu_to_le32(rdev
->pm
.dpm
.dyn_state
.vddc_dependency_on_sclk
.entries
[entry_id
].clk
);
3317 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3319 *voltage
= le16_to_cpu(args
.evv_out
.usVoltageLevel
);
3324 int radeon_atom_get_voltage_gpio_settings(struct radeon_device
*rdev
,
3325 u16 voltage_level
, u8 voltage_type
,
3326 u32
*gpio_value
, u32
*gpio_mask
)
3328 union set_voltage args
;
3329 int index
= GetIndexIntoMasterTable(COMMAND
, SetVoltage
);
3332 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
3339 args
.v2
.ucVoltageType
= voltage_type
;
3340 args
.v2
.ucVoltageMode
= SET_ASIC_VOLTAGE_MODE_GET_GPIOMASK
;
3341 args
.v2
.usVoltageLevel
= cpu_to_le16(voltage_level
);
3343 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3345 *gpio_mask
= le32_to_cpu(*(u32
*)&args
.v2
);
3347 args
.v2
.ucVoltageType
= voltage_type
;
3348 args
.v2
.ucVoltageMode
= SET_ASIC_VOLTAGE_MODE_GET_GPIOVAL
;
3349 args
.v2
.usVoltageLevel
= cpu_to_le16(voltage_level
);
3351 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
3353 *gpio_value
= le32_to_cpu(*(u32
*)&args
.v2
);
3356 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3363 union voltage_object_info
{
3364 struct _ATOM_VOLTAGE_OBJECT_INFO v1
;
3365 struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2
;
3366 struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3
;
3369 union voltage_object
{
3370 struct _ATOM_VOLTAGE_OBJECT v1
;
3371 struct _ATOM_VOLTAGE_OBJECT_V2 v2
;
3372 union _ATOM_VOLTAGE_OBJECT_V3 v3
;
3375 static ATOM_VOLTAGE_OBJECT
*atom_lookup_voltage_object_v1(ATOM_VOLTAGE_OBJECT_INFO
*v1
,
3378 u32 size
= le16_to_cpu(v1
->sHeader
.usStructureSize
);
3379 u32 offset
= offsetof(ATOM_VOLTAGE_OBJECT_INFO
, asVoltageObj
[0]);
3380 u8
*start
= (u8
*)v1
;
3382 while (offset
< size
) {
3383 ATOM_VOLTAGE_OBJECT
*vo
= (ATOM_VOLTAGE_OBJECT
*)(start
+ offset
);
3384 if (vo
->ucVoltageType
== voltage_type
)
3386 offset
+= offsetof(ATOM_VOLTAGE_OBJECT
, asFormula
.ucVIDAdjustEntries
) +
3387 vo
->asFormula
.ucNumOfVoltageEntries
;
3392 static ATOM_VOLTAGE_OBJECT_V2
*atom_lookup_voltage_object_v2(ATOM_VOLTAGE_OBJECT_INFO_V2
*v2
,
3395 u32 size
= le16_to_cpu(v2
->sHeader
.usStructureSize
);
3396 u32 offset
= offsetof(ATOM_VOLTAGE_OBJECT_INFO_V2
, asVoltageObj
[0]);
3397 u8
*start
= (u8
*)v2
;
3399 while (offset
< size
) {
3400 ATOM_VOLTAGE_OBJECT_V2
*vo
= (ATOM_VOLTAGE_OBJECT_V2
*)(start
+ offset
);
3401 if (vo
->ucVoltageType
== voltage_type
)
3403 offset
+= offsetof(ATOM_VOLTAGE_OBJECT_V2
, asFormula
.asVIDAdjustEntries
) +
3404 (vo
->asFormula
.ucNumOfVoltageEntries
* sizeof(VOLTAGE_LUT_ENTRY
));
3409 static ATOM_VOLTAGE_OBJECT_V3
*atom_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1
*v3
,
3410 u8 voltage_type
, u8 voltage_mode
)
3412 u32 size
= le16_to_cpu(v3
->sHeader
.usStructureSize
);
3413 u32 offset
= offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1
, asVoltageObj
[0]);
3414 u8
*start
= (u8
*)v3
;
3416 while (offset
< size
) {
3417 ATOM_VOLTAGE_OBJECT_V3
*vo
= (ATOM_VOLTAGE_OBJECT_V3
*)(start
+ offset
);
3418 if ((vo
->asGpioVoltageObj
.sHeader
.ucVoltageType
== voltage_type
) &&
3419 (vo
->asGpioVoltageObj
.sHeader
.ucVoltageMode
== voltage_mode
))
3421 offset
+= le16_to_cpu(vo
->asGpioVoltageObj
.sHeader
.usSize
);
3427 radeon_atom_is_voltage_gpio(struct radeon_device
*rdev
,
3428 u8 voltage_type
, u8 voltage_mode
)
3430 int index
= GetIndexIntoMasterTable(DATA
, VoltageObjectInfo
);
3432 u16 data_offset
, size
;
3433 union voltage_object_info
*voltage_info
;
3434 union voltage_object
*voltage_object
= NULL
;
3436 if (atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
3437 &frev
, &crev
, &data_offset
)) {
3438 voltage_info
= (union voltage_object_info
*)
3439 (rdev
->mode_info
.atom_context
->bios
+ data_offset
);
3446 voltage_object
= (union voltage_object
*)
3447 atom_lookup_voltage_object_v1(&voltage_info
->v1
, voltage_type
);
3448 if (voltage_object
&&
3449 (voltage_object
->v1
.asControl
.ucVoltageControlId
== VOLTAGE_CONTROLLED_BY_GPIO
))
3453 voltage_object
= (union voltage_object
*)
3454 atom_lookup_voltage_object_v2(&voltage_info
->v2
, voltage_type
);
3455 if (voltage_object
&&
3456 (voltage_object
->v2
.asControl
.ucVoltageControlId
== VOLTAGE_CONTROLLED_BY_GPIO
))
3460 DRM_ERROR("unknown voltage object table\n");
3467 if (atom_lookup_voltage_object_v3(&voltage_info
->v3
,
3468 voltage_type
, voltage_mode
))
3472 DRM_ERROR("unknown voltage object table\n");
3477 DRM_ERROR("unknown voltage object table\n");
3485 int radeon_atom_get_svi2_info(struct radeon_device
*rdev
,
3487 u8
*svd_gpio_id
, u8
*svc_gpio_id
)
3489 int index
= GetIndexIntoMasterTable(DATA
, VoltageObjectInfo
);
3491 u16 data_offset
, size
;
3492 union voltage_object_info
*voltage_info
;
3493 union voltage_object
*voltage_object
= NULL
;
3495 if (atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
3496 &frev
, &crev
, &data_offset
)) {
3497 voltage_info
= (union voltage_object_info
*)
3498 (rdev
->mode_info
.atom_context
->bios
+ data_offset
);
3504 voltage_object
= (union voltage_object
*)
3505 atom_lookup_voltage_object_v3(&voltage_info
->v3
,
3508 if (voltage_object
) {
3509 *svd_gpio_id
= voltage_object
->v3
.asSVID2Obj
.ucSVDGpioId
;
3510 *svc_gpio_id
= voltage_object
->v3
.asSVID2Obj
.ucSVCGpioId
;
3516 DRM_ERROR("unknown voltage object table\n");
3521 DRM_ERROR("unknown voltage object table\n");
3529 int radeon_atom_get_max_voltage(struct radeon_device
*rdev
,
3530 u8 voltage_type
, u16
*max_voltage
)
3532 int index
= GetIndexIntoMasterTable(DATA
, VoltageObjectInfo
);
3534 u16 data_offset
, size
;
3535 union voltage_object_info
*voltage_info
;
3536 union voltage_object
*voltage_object
= NULL
;
3538 if (atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
3539 &frev
, &crev
, &data_offset
)) {
3540 voltage_info
= (union voltage_object_info
*)
3541 (rdev
->mode_info
.atom_context
->bios
+ data_offset
);
3545 voltage_object
= (union voltage_object
*)
3546 atom_lookup_voltage_object_v1(&voltage_info
->v1
, voltage_type
);
3547 if (voltage_object
) {
3548 ATOM_VOLTAGE_FORMULA
*formula
=
3549 &voltage_object
->v1
.asFormula
;
3550 if (formula
->ucFlag
& 1)
3552 le16_to_cpu(formula
->usVoltageBaseLevel
) +
3553 formula
->ucNumOfVoltageEntries
/ 2 *
3554 le16_to_cpu(formula
->usVoltageStep
);
3557 le16_to_cpu(formula
->usVoltageBaseLevel
) +
3558 (formula
->ucNumOfVoltageEntries
- 1) *
3559 le16_to_cpu(formula
->usVoltageStep
);
3564 voltage_object
= (union voltage_object
*)
3565 atom_lookup_voltage_object_v2(&voltage_info
->v2
, voltage_type
);
3566 if (voltage_object
) {
3567 ATOM_VOLTAGE_FORMULA_V2
*formula
=
3568 &voltage_object
->v2
.asFormula
;
3569 if (formula
->ucNumOfVoltageEntries
) {
3570 VOLTAGE_LUT_ENTRY
*lut
= (VOLTAGE_LUT_ENTRY
*)
3571 ((u8
*)&formula
->asVIDAdjustEntries
[0] +
3572 (sizeof(VOLTAGE_LUT_ENTRY
) * (formula
->ucNumOfVoltageEntries
- 1)));
3574 le16_to_cpu(lut
->usVoltageValue
);
3580 DRM_ERROR("unknown voltage object table\n");
3588 int radeon_atom_get_min_voltage(struct radeon_device
*rdev
,
3589 u8 voltage_type
, u16
*min_voltage
)
3591 int index
= GetIndexIntoMasterTable(DATA
, VoltageObjectInfo
);
3593 u16 data_offset
, size
;
3594 union voltage_object_info
*voltage_info
;
3595 union voltage_object
*voltage_object
= NULL
;
3597 if (atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
3598 &frev
, &crev
, &data_offset
)) {
3599 voltage_info
= (union voltage_object_info
*)
3600 (rdev
->mode_info
.atom_context
->bios
+ data_offset
);
3604 voltage_object
= (union voltage_object
*)
3605 atom_lookup_voltage_object_v1(&voltage_info
->v1
, voltage_type
);
3606 if (voltage_object
) {
3607 ATOM_VOLTAGE_FORMULA
*formula
=
3608 &voltage_object
->v1
.asFormula
;
3610 le16_to_cpu(formula
->usVoltageBaseLevel
);
3615 voltage_object
= (union voltage_object
*)
3616 atom_lookup_voltage_object_v2(&voltage_info
->v2
, voltage_type
);
3617 if (voltage_object
) {
3618 ATOM_VOLTAGE_FORMULA_V2
*formula
=
3619 &voltage_object
->v2
.asFormula
;
3620 if (formula
->ucNumOfVoltageEntries
) {
3622 le16_to_cpu(formula
->asVIDAdjustEntries
[
3630 DRM_ERROR("unknown voltage object table\n");
3638 int radeon_atom_get_voltage_step(struct radeon_device
*rdev
,
3639 u8 voltage_type
, u16
*voltage_step
)
3641 int index
= GetIndexIntoMasterTable(DATA
, VoltageObjectInfo
);
3643 u16 data_offset
, size
;
3644 union voltage_object_info
*voltage_info
;
3645 union voltage_object
*voltage_object
= NULL
;
3647 if (atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
3648 &frev
, &crev
, &data_offset
)) {
3649 voltage_info
= (union voltage_object_info
*)
3650 (rdev
->mode_info
.atom_context
->bios
+ data_offset
);
3654 voltage_object
= (union voltage_object
*)
3655 atom_lookup_voltage_object_v1(&voltage_info
->v1
, voltage_type
);
3656 if (voltage_object
) {
3657 ATOM_VOLTAGE_FORMULA
*formula
=
3658 &voltage_object
->v1
.asFormula
;
3659 if (formula
->ucFlag
& 1)
3661 (le16_to_cpu(formula
->usVoltageStep
) + 1) / 2;
3664 le16_to_cpu(formula
->usVoltageStep
);
3671 DRM_ERROR("unknown voltage object table\n");
3679 int radeon_atom_round_to_true_voltage(struct radeon_device
*rdev
,
3681 u16 nominal_voltage
,
3684 u16 min_voltage
, max_voltage
, voltage_step
;
3686 if (radeon_atom_get_max_voltage(rdev
, voltage_type
, &max_voltage
))
3688 if (radeon_atom_get_min_voltage(rdev
, voltage_type
, &min_voltage
))
3690 if (radeon_atom_get_voltage_step(rdev
, voltage_type
, &voltage_step
))
3693 if (nominal_voltage
<= min_voltage
)
3694 *true_voltage
= min_voltage
;
3695 else if (nominal_voltage
>= max_voltage
)
3696 *true_voltage
= max_voltage
;
3698 *true_voltage
= min_voltage
+
3699 ((nominal_voltage
- min_voltage
) / voltage_step
) *
3705 int radeon_atom_get_voltage_table(struct radeon_device
*rdev
,
3706 u8 voltage_type
, u8 voltage_mode
,
3707 struct atom_voltage_table
*voltage_table
)
3709 int index
= GetIndexIntoMasterTable(DATA
, VoltageObjectInfo
);
3711 u16 data_offset
, size
;
3713 union voltage_object_info
*voltage_info
;
3714 union voltage_object
*voltage_object
= NULL
;
3716 if (atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
3717 &frev
, &crev
, &data_offset
)) {
3718 voltage_info
= (union voltage_object_info
*)
3719 (rdev
->mode_info
.atom_context
->bios
+ data_offset
);
3726 DRM_ERROR("old table version %d, %d\n", frev
, crev
);
3729 voltage_object
= (union voltage_object
*)
3730 atom_lookup_voltage_object_v2(&voltage_info
->v2
, voltage_type
);
3731 if (voltage_object
) {
3732 ATOM_VOLTAGE_FORMULA_V2
*formula
=
3733 &voltage_object
->v2
.asFormula
;
3734 VOLTAGE_LUT_ENTRY
*lut
;
3735 if (formula
->ucNumOfVoltageEntries
> MAX_VOLTAGE_ENTRIES
)
3737 lut
= &formula
->asVIDAdjustEntries
[0];
3738 for (i
= 0; i
< formula
->ucNumOfVoltageEntries
; i
++) {
3739 voltage_table
->entries
[i
].value
=
3740 le16_to_cpu(lut
->usVoltageValue
);
3741 ret
= radeon_atom_get_voltage_gpio_settings(rdev
,
3742 voltage_table
->entries
[i
].value
,
3744 &voltage_table
->entries
[i
].smio_low
,
3745 &voltage_table
->mask_low
);
3748 lut
= (VOLTAGE_LUT_ENTRY
*)
3749 ((u8
*)lut
+ sizeof(VOLTAGE_LUT_ENTRY
));
3751 voltage_table
->count
= formula
->ucNumOfVoltageEntries
;
3756 DRM_ERROR("unknown voltage object table\n");
3763 voltage_object
= (union voltage_object
*)
3764 atom_lookup_voltage_object_v3(&voltage_info
->v3
,
3765 voltage_type
, voltage_mode
);
3766 if (voltage_object
) {
3767 ATOM_GPIO_VOLTAGE_OBJECT_V3
*gpio
=
3768 &voltage_object
->v3
.asGpioVoltageObj
;
3769 VOLTAGE_LUT_ENTRY_V2
*lut
;
3770 if (gpio
->ucGpioEntryNum
> MAX_VOLTAGE_ENTRIES
)
3772 lut
= &gpio
->asVolGpioLut
[0];
3773 for (i
= 0; i
< gpio
->ucGpioEntryNum
; i
++) {
3774 voltage_table
->entries
[i
].value
=
3775 le16_to_cpu(lut
->usVoltageValue
);
3776 voltage_table
->entries
[i
].smio_low
=
3777 le32_to_cpu(lut
->ulVoltageId
);
3778 lut
= (VOLTAGE_LUT_ENTRY_V2
*)
3779 ((u8
*)lut
+ sizeof(VOLTAGE_LUT_ENTRY_V2
));
3781 voltage_table
->mask_low
= le32_to_cpu(gpio
->ulGpioMaskVal
);
3782 voltage_table
->count
= gpio
->ucGpioEntryNum
;
3783 voltage_table
->phase_delay
= gpio
->ucPhaseDelay
;
3788 DRM_ERROR("unknown voltage object table\n");
3793 DRM_ERROR("unknown voltage object table\n");
3801 struct _ATOM_VRAM_INFO_V3 v1_3
;
3802 struct _ATOM_VRAM_INFO_V4 v1_4
;
3803 struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1
;
3806 int radeon_atom_get_memory_info(struct radeon_device
*rdev
,
3807 u8 module_index
, struct atom_memory_info
*mem_info
)
3809 int index
= GetIndexIntoMasterTable(DATA
, VRAM_Info
);
3811 u16 data_offset
, size
;
3812 union vram_info
*vram_info
;
3814 memset(mem_info
, 0, sizeof(struct atom_memory_info
));
3816 if (atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
3817 &frev
, &crev
, &data_offset
)) {
3818 vram_info
= (union vram_info
*)
3819 (rdev
->mode_info
.atom_context
->bios
+ data_offset
);
3825 if (module_index
< vram_info
->v1_3
.ucNumOfVRAMModule
) {
3826 ATOM_VRAM_MODULE_V3
*vram_module
=
3827 (ATOM_VRAM_MODULE_V3
*)vram_info
->v1_3
.aVramInfo
;
3829 for (i
= 0; i
< module_index
; i
++) {
3830 if (le16_to_cpu(vram_module
->usSize
) == 0)
3832 vram_module
= (ATOM_VRAM_MODULE_V3
*)
3833 ((u8
*)vram_module
+ le16_to_cpu(vram_module
->usSize
));
3835 mem_info
->mem_vendor
= vram_module
->asMemory
.ucMemoryVenderID
& 0xf;
3836 mem_info
->mem_type
= vram_module
->asMemory
.ucMemoryType
& 0xf0;
3841 /* r7xx, evergreen */
3842 if (module_index
< vram_info
->v1_4
.ucNumOfVRAMModule
) {
3843 ATOM_VRAM_MODULE_V4
*vram_module
=
3844 (ATOM_VRAM_MODULE_V4
*)vram_info
->v1_4
.aVramInfo
;
3846 for (i
= 0; i
< module_index
; i
++) {
3847 if (le16_to_cpu(vram_module
->usModuleSize
) == 0)
3849 vram_module
= (ATOM_VRAM_MODULE_V4
*)
3850 ((u8
*)vram_module
+ le16_to_cpu(vram_module
->usModuleSize
));
3852 mem_info
->mem_vendor
= vram_module
->ucMemoryVenderID
& 0xf;
3853 mem_info
->mem_type
= vram_module
->ucMemoryType
& 0xf0;
3858 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3866 if (module_index
< vram_info
->v2_1
.ucNumOfVRAMModule
) {
3867 ATOM_VRAM_MODULE_V7
*vram_module
=
3868 (ATOM_VRAM_MODULE_V7
*)vram_info
->v2_1
.aVramInfo
;
3870 for (i
= 0; i
< module_index
; i
++) {
3871 if (le16_to_cpu(vram_module
->usModuleSize
) == 0)
3873 vram_module
= (ATOM_VRAM_MODULE_V7
*)
3874 ((u8
*)vram_module
+ le16_to_cpu(vram_module
->usModuleSize
));
3876 mem_info
->mem_vendor
= vram_module
->ucMemoryVenderID
& 0xf;
3877 mem_info
->mem_type
= vram_module
->ucMemoryType
& 0xf0;
3882 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3887 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3895 int radeon_atom_get_mclk_range_table(struct radeon_device
*rdev
,
3896 bool gddr5
, u8 module_index
,
3897 struct atom_memory_clock_range_table
*mclk_range_table
)
3899 int index
= GetIndexIntoMasterTable(DATA
, VRAM_Info
);
3901 u16 data_offset
, size
;
3902 union vram_info
*vram_info
;
3903 u32 mem_timing_size
= gddr5
?
3904 sizeof(ATOM_MEMORY_TIMING_FORMAT_V2
) : sizeof(ATOM_MEMORY_TIMING_FORMAT
);
3906 memset(mclk_range_table
, 0, sizeof(struct atom_memory_clock_range_table
));
3908 if (atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
3909 &frev
, &crev
, &data_offset
)) {
3910 vram_info
= (union vram_info
*)
3911 (rdev
->mode_info
.atom_context
->bios
+ data_offset
);
3916 DRM_ERROR("old table version %d, %d\n", frev
, crev
);
3919 /* r7xx, evergreen */
3920 if (module_index
< vram_info
->v1_4
.ucNumOfVRAMModule
) {
3921 ATOM_VRAM_MODULE_V4
*vram_module
=
3922 (ATOM_VRAM_MODULE_V4
*)vram_info
->v1_4
.aVramInfo
;
3923 ATOM_MEMORY_TIMING_FORMAT
*format
;
3925 for (i
= 0; i
< module_index
; i
++) {
3926 if (le16_to_cpu(vram_module
->usModuleSize
) == 0)
3928 vram_module
= (ATOM_VRAM_MODULE_V4
*)
3929 ((u8
*)vram_module
+ le16_to_cpu(vram_module
->usModuleSize
));
3931 mclk_range_table
->num_entries
= (u8
)
3932 ((le16_to_cpu(vram_module
->usModuleSize
) - offsetof(ATOM_VRAM_MODULE_V4
, asMemTiming
)) /
3934 format
= &vram_module
->asMemTiming
[0];
3935 for (i
= 0; i
< mclk_range_table
->num_entries
; i
++) {
3936 mclk_range_table
->mclk
[i
] = le32_to_cpu(format
->ulClkRange
);
3937 format
= (ATOM_MEMORY_TIMING_FORMAT
*)
3938 ((u8
*)format
+ mem_timing_size
);
3944 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3949 DRM_ERROR("new table version %d, %d\n", frev
, crev
);
3952 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
3960 #define MEM_ID_MASK 0xff000000
3961 #define MEM_ID_SHIFT 24
3962 #define CLOCK_RANGE_MASK 0x00ffffff
3963 #define CLOCK_RANGE_SHIFT 0
3964 #define LOW_NIBBLE_MASK 0xf
3965 #define DATA_EQU_PREV 0
3966 #define DATA_FROM_TABLE 4
3968 int radeon_atom_init_mc_reg_table(struct radeon_device
*rdev
,
3970 struct atom_mc_reg_table
*reg_table
)
3972 int index
= GetIndexIntoMasterTable(DATA
, VRAM_Info
);
3973 u8 frev
, crev
, num_entries
, t_mem_id
, num_ranges
= 0;
3975 u16 data_offset
, size
;
3976 union vram_info
*vram_info
;
3978 memset(reg_table
, 0, sizeof(struct atom_mc_reg_table
));
3980 if (atom_parse_data_header(rdev
->mode_info
.atom_context
, index
, &size
,
3981 &frev
, &crev
, &data_offset
)) {
3982 vram_info
= (union vram_info
*)
3983 (rdev
->mode_info
.atom_context
->bios
+ data_offset
);
3986 DRM_ERROR("old table version %d, %d\n", frev
, crev
);
3991 if (module_index
< vram_info
->v2_1
.ucNumOfVRAMModule
) {
3992 ATOM_INIT_REG_BLOCK
*reg_block
=
3993 (ATOM_INIT_REG_BLOCK
*)
3994 ((u8
*)vram_info
+ le16_to_cpu(vram_info
->v2_1
.usMemClkPatchTblOffset
));
3995 ATOM_MEMORY_SETTING_DATA_BLOCK
*reg_data
=
3996 (ATOM_MEMORY_SETTING_DATA_BLOCK
*)
3997 ((u8
*)reg_block
+ (2 * sizeof(u16
)) +
3998 le16_to_cpu(reg_block
->usRegIndexTblSize
));
3999 ATOM_INIT_REG_INDEX_FORMAT
*format
= ®_block
->asRegIndexBuf
[0];
4000 num_entries
= (u8
)((le16_to_cpu(reg_block
->usRegIndexTblSize
)) /
4001 sizeof(ATOM_INIT_REG_INDEX_FORMAT
)) - 1;
4002 if (num_entries
> VBIOS_MC_REGISTER_ARRAY_SIZE
)
4004 while (i
< num_entries
) {
4005 if (format
->ucPreRegDataLength
& ACCESS_PLACEHOLDER
)
4007 reg_table
->mc_reg_address
[i
].s1
=
4008 (u16
)(le16_to_cpu(format
->usRegIndex
));
4009 reg_table
->mc_reg_address
[i
].pre_reg_data
=
4010 (u8
)(format
->ucPreRegDataLength
);
4012 format
= (ATOM_INIT_REG_INDEX_FORMAT
*)
4013 ((u8
*)format
+ sizeof(ATOM_INIT_REG_INDEX_FORMAT
));
4015 reg_table
->last
= i
;
4016 while ((le32_to_cpu(*(u32
*)reg_data
) != END_OF_REG_DATA_BLOCK
) &&
4017 (num_ranges
< VBIOS_MAX_AC_TIMING_ENTRIES
)) {
4018 t_mem_id
= (u8
)((le32_to_cpu(*(u32
*)reg_data
) & MEM_ID_MASK
)
4020 if (module_index
== t_mem_id
) {
4021 reg_table
->mc_reg_table_entry
[num_ranges
].mclk_max
=
4022 (u32
)((le32_to_cpu(*(u32
*)reg_data
) & CLOCK_RANGE_MASK
)
4023 >> CLOCK_RANGE_SHIFT
);
4024 for (i
= 0, j
= 1; i
< reg_table
->last
; i
++) {
4025 if ((reg_table
->mc_reg_address
[i
].pre_reg_data
& LOW_NIBBLE_MASK
) == DATA_FROM_TABLE
) {
4026 reg_table
->mc_reg_table_entry
[num_ranges
].mc_data
[i
] =
4027 (u32
)le32_to_cpu(*((u32
*)reg_data
+ j
));
4029 } else if ((reg_table
->mc_reg_address
[i
].pre_reg_data
& LOW_NIBBLE_MASK
) == DATA_EQU_PREV
) {
4030 reg_table
->mc_reg_table_entry
[num_ranges
].mc_data
[i
] =
4031 reg_table
->mc_reg_table_entry
[num_ranges
].mc_data
[i
- 1];
4036 reg_data
= (ATOM_MEMORY_SETTING_DATA_BLOCK
*)
4037 ((u8
*)reg_data
+ le16_to_cpu(reg_block
->usRegDataBlkSize
));
4039 if (le32_to_cpu(*(u32
*)reg_data
) != END_OF_REG_DATA_BLOCK
)
4041 reg_table
->num_entries
= num_ranges
;
4046 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
4051 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
4059 void radeon_atom_initialize_bios_scratch_regs(struct drm_device
*dev
)
4061 struct radeon_device
*rdev
= dev
->dev_private
;
4062 uint32_t bios_2_scratch
, bios_6_scratch
;
4064 if (rdev
->family
>= CHIP_R600
) {
4065 bios_2_scratch
= RREG32(R600_BIOS_2_SCRATCH
);
4066 bios_6_scratch
= RREG32(R600_BIOS_6_SCRATCH
);
4068 bios_2_scratch
= RREG32(RADEON_BIOS_2_SCRATCH
);
4069 bios_6_scratch
= RREG32(RADEON_BIOS_6_SCRATCH
);
4072 /* let the bios control the backlight */
4073 bios_2_scratch
&= ~ATOM_S2_VRI_BRIGHT_ENABLE
;
4075 /* tell the bios not to handle mode switching */
4076 bios_6_scratch
|= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH
;
4078 /* clear the vbios dpms state */
4079 if (ASIC_IS_DCE4(rdev
))
4080 bios_2_scratch
&= ~ATOM_S2_DEVICE_DPMS_STATE
;
4082 if (rdev
->family
>= CHIP_R600
) {
4083 WREG32(R600_BIOS_2_SCRATCH
, bios_2_scratch
);
4084 WREG32(R600_BIOS_6_SCRATCH
, bios_6_scratch
);
4086 WREG32(RADEON_BIOS_2_SCRATCH
, bios_2_scratch
);
4087 WREG32(RADEON_BIOS_6_SCRATCH
, bios_6_scratch
);
4092 void radeon_save_bios_scratch_regs(struct radeon_device
*rdev
)
4094 uint32_t scratch_reg
;
4097 if (rdev
->family
>= CHIP_R600
)
4098 scratch_reg
= R600_BIOS_0_SCRATCH
;
4100 scratch_reg
= RADEON_BIOS_0_SCRATCH
;
4102 for (i
= 0; i
< RADEON_BIOS_NUM_SCRATCH
; i
++)
4103 rdev
->bios_scratch
[i
] = RREG32(scratch_reg
+ (i
* 4));
4106 void radeon_restore_bios_scratch_regs(struct radeon_device
*rdev
)
4108 uint32_t scratch_reg
;
4111 if (rdev
->family
>= CHIP_R600
)
4112 scratch_reg
= R600_BIOS_0_SCRATCH
;
4114 scratch_reg
= RADEON_BIOS_0_SCRATCH
;
4116 for (i
= 0; i
< RADEON_BIOS_NUM_SCRATCH
; i
++)
4117 WREG32(scratch_reg
+ (i
* 4), rdev
->bios_scratch
[i
]);
4120 void radeon_atom_output_lock(struct drm_encoder
*encoder
, bool lock
)
4122 struct drm_device
*dev
= encoder
->dev
;
4123 struct radeon_device
*rdev
= dev
->dev_private
;
4124 uint32_t bios_6_scratch
;
4126 if (rdev
->family
>= CHIP_R600
)
4127 bios_6_scratch
= RREG32(R600_BIOS_6_SCRATCH
);
4129 bios_6_scratch
= RREG32(RADEON_BIOS_6_SCRATCH
);
4132 bios_6_scratch
|= ATOM_S6_CRITICAL_STATE
;
4133 bios_6_scratch
&= ~ATOM_S6_ACC_MODE
;
4135 bios_6_scratch
&= ~ATOM_S6_CRITICAL_STATE
;
4136 bios_6_scratch
|= ATOM_S6_ACC_MODE
;
4139 if (rdev
->family
>= CHIP_R600
)
4140 WREG32(R600_BIOS_6_SCRATCH
, bios_6_scratch
);
4142 WREG32(RADEON_BIOS_6_SCRATCH
, bios_6_scratch
);
4145 /* at some point we may want to break this out into individual functions */
4147 radeon_atombios_connected_scratch_regs(struct drm_connector
*connector
,
4148 struct drm_encoder
*encoder
,
4151 struct drm_device
*dev
= connector
->dev
;
4152 struct radeon_device
*rdev
= dev
->dev_private
;
4153 struct radeon_connector
*radeon_connector
=
4154 to_radeon_connector(connector
);
4155 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
4156 uint32_t bios_0_scratch
, bios_3_scratch
, bios_6_scratch
;
4158 if (rdev
->family
>= CHIP_R600
) {
4159 bios_0_scratch
= RREG32(R600_BIOS_0_SCRATCH
);
4160 bios_3_scratch
= RREG32(R600_BIOS_3_SCRATCH
);
4161 bios_6_scratch
= RREG32(R600_BIOS_6_SCRATCH
);
4163 bios_0_scratch
= RREG32(RADEON_BIOS_0_SCRATCH
);
4164 bios_3_scratch
= RREG32(RADEON_BIOS_3_SCRATCH
);
4165 bios_6_scratch
= RREG32(RADEON_BIOS_6_SCRATCH
);
4168 if ((radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) &&
4169 (radeon_connector
->devices
& ATOM_DEVICE_TV1_SUPPORT
)) {
4171 DRM_DEBUG_KMS("TV1 connected\n");
4172 bios_3_scratch
|= ATOM_S3_TV1_ACTIVE
;
4173 bios_6_scratch
|= ATOM_S6_ACC_REQ_TV1
;
4175 DRM_DEBUG_KMS("TV1 disconnected\n");
4176 bios_0_scratch
&= ~ATOM_S0_TV1_MASK
;
4177 bios_3_scratch
&= ~ATOM_S3_TV1_ACTIVE
;
4178 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_TV1
;
4181 if ((radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) &&
4182 (radeon_connector
->devices
& ATOM_DEVICE_CV_SUPPORT
)) {
4184 DRM_DEBUG_KMS("CV connected\n");
4185 bios_3_scratch
|= ATOM_S3_CV_ACTIVE
;
4186 bios_6_scratch
|= ATOM_S6_ACC_REQ_CV
;
4188 DRM_DEBUG_KMS("CV disconnected\n");
4189 bios_0_scratch
&= ~ATOM_S0_CV_MASK
;
4190 bios_3_scratch
&= ~ATOM_S3_CV_ACTIVE
;
4191 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_CV
;
4194 if ((radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) &&
4195 (radeon_connector
->devices
& ATOM_DEVICE_LCD1_SUPPORT
)) {
4197 DRM_DEBUG_KMS("LCD1 connected\n");
4198 bios_0_scratch
|= ATOM_S0_LCD1
;
4199 bios_3_scratch
|= ATOM_S3_LCD1_ACTIVE
;
4200 bios_6_scratch
|= ATOM_S6_ACC_REQ_LCD1
;
4202 DRM_DEBUG_KMS("LCD1 disconnected\n");
4203 bios_0_scratch
&= ~ATOM_S0_LCD1
;
4204 bios_3_scratch
&= ~ATOM_S3_LCD1_ACTIVE
;
4205 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_LCD1
;
4208 if ((radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) &&
4209 (radeon_connector
->devices
& ATOM_DEVICE_CRT1_SUPPORT
)) {
4211 DRM_DEBUG_KMS("CRT1 connected\n");
4212 bios_0_scratch
|= ATOM_S0_CRT1_COLOR
;
4213 bios_3_scratch
|= ATOM_S3_CRT1_ACTIVE
;
4214 bios_6_scratch
|= ATOM_S6_ACC_REQ_CRT1
;
4216 DRM_DEBUG_KMS("CRT1 disconnected\n");
4217 bios_0_scratch
&= ~ATOM_S0_CRT1_MASK
;
4218 bios_3_scratch
&= ~ATOM_S3_CRT1_ACTIVE
;
4219 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_CRT1
;
4222 if ((radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) &&
4223 (radeon_connector
->devices
& ATOM_DEVICE_CRT2_SUPPORT
)) {
4225 DRM_DEBUG_KMS("CRT2 connected\n");
4226 bios_0_scratch
|= ATOM_S0_CRT2_COLOR
;
4227 bios_3_scratch
|= ATOM_S3_CRT2_ACTIVE
;
4228 bios_6_scratch
|= ATOM_S6_ACC_REQ_CRT2
;
4230 DRM_DEBUG_KMS("CRT2 disconnected\n");
4231 bios_0_scratch
&= ~ATOM_S0_CRT2_MASK
;
4232 bios_3_scratch
&= ~ATOM_S3_CRT2_ACTIVE
;
4233 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_CRT2
;
4236 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP1_SUPPORT
) &&
4237 (radeon_connector
->devices
& ATOM_DEVICE_DFP1_SUPPORT
)) {
4239 DRM_DEBUG_KMS("DFP1 connected\n");
4240 bios_0_scratch
|= ATOM_S0_DFP1
;
4241 bios_3_scratch
|= ATOM_S3_DFP1_ACTIVE
;
4242 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP1
;
4244 DRM_DEBUG_KMS("DFP1 disconnected\n");
4245 bios_0_scratch
&= ~ATOM_S0_DFP1
;
4246 bios_3_scratch
&= ~ATOM_S3_DFP1_ACTIVE
;
4247 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP1
;
4250 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
) &&
4251 (radeon_connector
->devices
& ATOM_DEVICE_DFP2_SUPPORT
)) {
4253 DRM_DEBUG_KMS("DFP2 connected\n");
4254 bios_0_scratch
|= ATOM_S0_DFP2
;
4255 bios_3_scratch
|= ATOM_S3_DFP2_ACTIVE
;
4256 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP2
;
4258 DRM_DEBUG_KMS("DFP2 disconnected\n");
4259 bios_0_scratch
&= ~ATOM_S0_DFP2
;
4260 bios_3_scratch
&= ~ATOM_S3_DFP2_ACTIVE
;
4261 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP2
;
4264 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP3_SUPPORT
) &&
4265 (radeon_connector
->devices
& ATOM_DEVICE_DFP3_SUPPORT
)) {
4267 DRM_DEBUG_KMS("DFP3 connected\n");
4268 bios_0_scratch
|= ATOM_S0_DFP3
;
4269 bios_3_scratch
|= ATOM_S3_DFP3_ACTIVE
;
4270 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP3
;
4272 DRM_DEBUG_KMS("DFP3 disconnected\n");
4273 bios_0_scratch
&= ~ATOM_S0_DFP3
;
4274 bios_3_scratch
&= ~ATOM_S3_DFP3_ACTIVE
;
4275 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP3
;
4278 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP4_SUPPORT
) &&
4279 (radeon_connector
->devices
& ATOM_DEVICE_DFP4_SUPPORT
)) {
4281 DRM_DEBUG_KMS("DFP4 connected\n");
4282 bios_0_scratch
|= ATOM_S0_DFP4
;
4283 bios_3_scratch
|= ATOM_S3_DFP4_ACTIVE
;
4284 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP4
;
4286 DRM_DEBUG_KMS("DFP4 disconnected\n");
4287 bios_0_scratch
&= ~ATOM_S0_DFP4
;
4288 bios_3_scratch
&= ~ATOM_S3_DFP4_ACTIVE
;
4289 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP4
;
4292 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP5_SUPPORT
) &&
4293 (radeon_connector
->devices
& ATOM_DEVICE_DFP5_SUPPORT
)) {
4295 DRM_DEBUG_KMS("DFP5 connected\n");
4296 bios_0_scratch
|= ATOM_S0_DFP5
;
4297 bios_3_scratch
|= ATOM_S3_DFP5_ACTIVE
;
4298 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP5
;
4300 DRM_DEBUG_KMS("DFP5 disconnected\n");
4301 bios_0_scratch
&= ~ATOM_S0_DFP5
;
4302 bios_3_scratch
&= ~ATOM_S3_DFP5_ACTIVE
;
4303 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP5
;
4306 if ((radeon_encoder
->devices
& ATOM_DEVICE_DFP6_SUPPORT
) &&
4307 (radeon_connector
->devices
& ATOM_DEVICE_DFP6_SUPPORT
)) {
4309 DRM_DEBUG_KMS("DFP6 connected\n");
4310 bios_0_scratch
|= ATOM_S0_DFP6
;
4311 bios_3_scratch
|= ATOM_S3_DFP6_ACTIVE
;
4312 bios_6_scratch
|= ATOM_S6_ACC_REQ_DFP6
;
4314 DRM_DEBUG_KMS("DFP6 disconnected\n");
4315 bios_0_scratch
&= ~ATOM_S0_DFP6
;
4316 bios_3_scratch
&= ~ATOM_S3_DFP6_ACTIVE
;
4317 bios_6_scratch
&= ~ATOM_S6_ACC_REQ_DFP6
;
4321 if (rdev
->family
>= CHIP_R600
) {
4322 WREG32(R600_BIOS_0_SCRATCH
, bios_0_scratch
);
4323 WREG32(R600_BIOS_3_SCRATCH
, bios_3_scratch
);
4324 WREG32(R600_BIOS_6_SCRATCH
, bios_6_scratch
);
4326 WREG32(RADEON_BIOS_0_SCRATCH
, bios_0_scratch
);
4327 WREG32(RADEON_BIOS_3_SCRATCH
, bios_3_scratch
);
4328 WREG32(RADEON_BIOS_6_SCRATCH
, bios_6_scratch
);
4333 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder
*encoder
, int crtc
)
4335 struct drm_device
*dev
= encoder
->dev
;
4336 struct radeon_device
*rdev
= dev
->dev_private
;
4337 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
4338 uint32_t bios_3_scratch
;
4340 if (ASIC_IS_DCE4(rdev
))
4343 if (rdev
->family
>= CHIP_R600
)
4344 bios_3_scratch
= RREG32(R600_BIOS_3_SCRATCH
);
4346 bios_3_scratch
= RREG32(RADEON_BIOS_3_SCRATCH
);
4348 if (radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
4349 bios_3_scratch
&= ~ATOM_S3_TV1_CRTC_ACTIVE
;
4350 bios_3_scratch
|= (crtc
<< 18);
4352 if (radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
4353 bios_3_scratch
&= ~ATOM_S3_CV_CRTC_ACTIVE
;
4354 bios_3_scratch
|= (crtc
<< 24);
4356 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
4357 bios_3_scratch
&= ~ATOM_S3_CRT1_CRTC_ACTIVE
;
4358 bios_3_scratch
|= (crtc
<< 16);
4360 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
4361 bios_3_scratch
&= ~ATOM_S3_CRT2_CRTC_ACTIVE
;
4362 bios_3_scratch
|= (crtc
<< 20);
4364 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) {
4365 bios_3_scratch
&= ~ATOM_S3_LCD1_CRTC_ACTIVE
;
4366 bios_3_scratch
|= (crtc
<< 17);
4368 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP1_SUPPORT
) {
4369 bios_3_scratch
&= ~ATOM_S3_DFP1_CRTC_ACTIVE
;
4370 bios_3_scratch
|= (crtc
<< 19);
4372 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
) {
4373 bios_3_scratch
&= ~ATOM_S3_DFP2_CRTC_ACTIVE
;
4374 bios_3_scratch
|= (crtc
<< 23);
4376 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP3_SUPPORT
) {
4377 bios_3_scratch
&= ~ATOM_S3_DFP3_CRTC_ACTIVE
;
4378 bios_3_scratch
|= (crtc
<< 25);
4381 if (rdev
->family
>= CHIP_R600
)
4382 WREG32(R600_BIOS_3_SCRATCH
, bios_3_scratch
);
4384 WREG32(RADEON_BIOS_3_SCRATCH
, bios_3_scratch
);
4388 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder
*encoder
, bool on
)
4390 struct drm_device
*dev
= encoder
->dev
;
4391 struct radeon_device
*rdev
= dev
->dev_private
;
4392 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
4393 uint32_t bios_2_scratch
;
4395 if (ASIC_IS_DCE4(rdev
))
4398 if (rdev
->family
>= CHIP_R600
)
4399 bios_2_scratch
= RREG32(R600_BIOS_2_SCRATCH
);
4401 bios_2_scratch
= RREG32(RADEON_BIOS_2_SCRATCH
);
4403 if (radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
4405 bios_2_scratch
&= ~ATOM_S2_TV1_DPMS_STATE
;
4407 bios_2_scratch
|= ATOM_S2_TV1_DPMS_STATE
;
4409 if (radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
4411 bios_2_scratch
&= ~ATOM_S2_CV_DPMS_STATE
;
4413 bios_2_scratch
|= ATOM_S2_CV_DPMS_STATE
;
4415 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
4417 bios_2_scratch
&= ~ATOM_S2_CRT1_DPMS_STATE
;
4419 bios_2_scratch
|= ATOM_S2_CRT1_DPMS_STATE
;
4421 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
4423 bios_2_scratch
&= ~ATOM_S2_CRT2_DPMS_STATE
;
4425 bios_2_scratch
|= ATOM_S2_CRT2_DPMS_STATE
;
4427 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) {
4429 bios_2_scratch
&= ~ATOM_S2_LCD1_DPMS_STATE
;
4431 bios_2_scratch
|= ATOM_S2_LCD1_DPMS_STATE
;
4433 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP1_SUPPORT
) {
4435 bios_2_scratch
&= ~ATOM_S2_DFP1_DPMS_STATE
;
4437 bios_2_scratch
|= ATOM_S2_DFP1_DPMS_STATE
;
4439 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
) {
4441 bios_2_scratch
&= ~ATOM_S2_DFP2_DPMS_STATE
;
4443 bios_2_scratch
|= ATOM_S2_DFP2_DPMS_STATE
;
4445 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP3_SUPPORT
) {
4447 bios_2_scratch
&= ~ATOM_S2_DFP3_DPMS_STATE
;
4449 bios_2_scratch
|= ATOM_S2_DFP3_DPMS_STATE
;
4451 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP4_SUPPORT
) {
4453 bios_2_scratch
&= ~ATOM_S2_DFP4_DPMS_STATE
;
4455 bios_2_scratch
|= ATOM_S2_DFP4_DPMS_STATE
;
4457 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP5_SUPPORT
) {
4459 bios_2_scratch
&= ~ATOM_S2_DFP5_DPMS_STATE
;
4461 bios_2_scratch
|= ATOM_S2_DFP5_DPMS_STATE
;
4464 if (rdev
->family
>= CHIP_R600
)
4465 WREG32(R600_BIOS_2_SCRATCH
, bios_2_scratch
);
4467 WREG32(RADEON_BIOS_2_SCRATCH
, bios_2_scratch
);