2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Authors: Dave Airlie
27 #include "radeon_drm.h"
31 #include "atom-bits.h"
33 /* from radeon_encoder.c */
35 radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
37 extern void radeon_link_encoder_connector(struct drm_device *dev);
39 radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
40 uint32_t supported_device, u16 caps);
42 /* from radeon_connector.c */
44 radeon_add_atom_connector(struct drm_device *dev,
45 uint32_t connector_id,
46 uint32_t supported_device,
48 struct radeon_i2c_bus_rec *i2c_bus,
49 uint32_t igp_lane_info,
50 uint16_t connector_object_id,
51 struct radeon_hpd *hpd,
52 struct radeon_router *router);
54 /* from radeon_legacy_encoder.c */
56 radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
57 uint32_t supported_device);
59 union atom_supported_devices {
60 struct _ATOM_SUPPORTED_DEVICES_INFO info;
61 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
62 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
65 static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
68 struct atom_context *ctx = rdev->mode_info.atom_context;
69 ATOM_GPIO_I2C_ASSIGMENT *gpio;
70 struct radeon_i2c_bus_rec i2c;
71 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
72 struct _ATOM_GPIO_I2C_INFO *i2c_info;
73 uint16_t data_offset, size;
76 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
79 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
80 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
82 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
83 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
85 for (i = 0; i < num_indices; i++) {
86 gpio = &i2c_info->asGPIO_Info[i];
88 /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
89 if ((rdev->family == CHIP_R420) ||
90 (rdev->family == CHIP_R423) ||
91 (rdev->family == CHIP_RV410)) {
92 if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
93 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
94 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
95 gpio->ucClkMaskShift = 0x19;
96 gpio->ucDataMaskShift = 0x18;
100 /* some evergreen boards have bad data for this entry */
101 if (ASIC_IS_DCE4(rdev)) {
103 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
104 (gpio->sucI2cId.ucAccess == 0)) {
105 gpio->sucI2cId.ucAccess = 0x97;
106 gpio->ucDataMaskShift = 8;
107 gpio->ucDataEnShift = 8;
108 gpio->ucDataY_Shift = 8;
109 gpio->ucDataA_Shift = 8;
113 /* some DCE3 boards have bad data for this entry */
114 if (ASIC_IS_DCE3(rdev)) {
116 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
117 (gpio->sucI2cId.ucAccess == 0x94))
118 gpio->sucI2cId.ucAccess = 0x14;
121 if (gpio->sucI2cId.ucAccess == id) {
122 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
123 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
124 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
125 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
126 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
127 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
128 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
129 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
130 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
131 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
132 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
133 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
134 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
135 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
136 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
137 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
139 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
140 i2c.hw_capable = true;
142 i2c.hw_capable = false;
144 if (gpio->sucI2cId.ucAccess == 0xa0)
149 i2c.i2c_id = gpio->sucI2cId.ucAccess;
151 if (i2c.mask_clk_reg)
161 void radeon_atombios_i2c_init(struct radeon_device *rdev)
163 struct atom_context *ctx = rdev->mode_info.atom_context;
164 ATOM_GPIO_I2C_ASSIGMENT *gpio;
165 struct radeon_i2c_bus_rec i2c;
166 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
167 struct _ATOM_GPIO_I2C_INFO *i2c_info;
168 uint16_t data_offset, size;
172 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
174 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
175 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
177 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
178 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
180 for (i = 0; i < num_indices; i++) {
181 gpio = &i2c_info->asGPIO_Info[i];
184 /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
185 if ((rdev->family == CHIP_R420) ||
186 (rdev->family == CHIP_R423) ||
187 (rdev->family == CHIP_RV410)) {
188 if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
189 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
190 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
191 gpio->ucClkMaskShift = 0x19;
192 gpio->ucDataMaskShift = 0x18;
196 /* some evergreen boards have bad data for this entry */
197 if (ASIC_IS_DCE4(rdev)) {
199 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
200 (gpio->sucI2cId.ucAccess == 0)) {
201 gpio->sucI2cId.ucAccess = 0x97;
202 gpio->ucDataMaskShift = 8;
203 gpio->ucDataEnShift = 8;
204 gpio->ucDataY_Shift = 8;
205 gpio->ucDataA_Shift = 8;
209 /* some DCE3 boards have bad data for this entry */
210 if (ASIC_IS_DCE3(rdev)) {
212 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
213 (gpio->sucI2cId.ucAccess == 0x94))
214 gpio->sucI2cId.ucAccess = 0x14;
217 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
218 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
219 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
220 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
221 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
222 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
223 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
224 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
225 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
226 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
227 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
228 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
229 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
230 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
231 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
232 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
234 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
235 i2c.hw_capable = true;
237 i2c.hw_capable = false;
239 if (gpio->sucI2cId.ucAccess == 0xa0)
244 i2c.i2c_id = gpio->sucI2cId.ucAccess;
246 if (i2c.mask_clk_reg) {
248 sprintf(stmp, "0x%x", i2c.i2c_id);
249 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
255 static struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
258 struct atom_context *ctx = rdev->mode_info.atom_context;
259 struct radeon_gpio_rec gpio;
260 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
261 struct _ATOM_GPIO_PIN_LUT *gpio_info;
262 ATOM_GPIO_PIN_ASSIGNMENT *pin;
263 u16 data_offset, size;
266 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
269 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
270 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
272 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
273 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
275 for (i = 0; i < num_indices; i++) {
276 pin = &gpio_info->asGPIO_Pin[i];
277 if (id == pin->ucGPIO_ID) {
278 gpio.id = pin->ucGPIO_ID;
279 gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex) * 4;
280 gpio.mask = (1 << pin->ucGpioPinBitShift);
290 static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
291 struct radeon_gpio_rec *gpio)
293 struct radeon_hpd hpd;
296 memset(&hpd, 0, sizeof(struct radeon_hpd));
298 if (ASIC_IS_DCE4(rdev))
299 reg = EVERGREEN_DC_GPIO_HPD_A;
301 reg = AVIVO_DC_GPIO_HPD_A;
304 if (gpio->reg == reg) {
307 hpd.hpd = RADEON_HPD_1;
310 hpd.hpd = RADEON_HPD_2;
313 hpd.hpd = RADEON_HPD_3;
316 hpd.hpd = RADEON_HPD_4;
319 hpd.hpd = RADEON_HPD_5;
322 hpd.hpd = RADEON_HPD_6;
325 hpd.hpd = RADEON_HPD_NONE;
329 hpd.hpd = RADEON_HPD_NONE;
333 static bool radeon_atom_apply_quirks(struct drm_device *dev,
334 uint32_t supported_device,
336 struct radeon_i2c_bus_rec *i2c_bus,
338 struct radeon_hpd *hpd)
341 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
342 if ((dev->pdev->device == 0x791e) &&
343 (dev->pdev->subsystem_vendor == 0x1043) &&
344 (dev->pdev->subsystem_device == 0x826d)) {
345 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
346 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
347 *connector_type = DRM_MODE_CONNECTOR_DVID;
350 /* Asrock RS600 board lists the DVI port as HDMI */
351 if ((dev->pdev->device == 0x7941) &&
352 (dev->pdev->subsystem_vendor == 0x1849) &&
353 (dev->pdev->subsystem_device == 0x7941)) {
354 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
355 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
356 *connector_type = DRM_MODE_CONNECTOR_DVID;
359 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
360 if ((dev->pdev->device == 0x796e) &&
361 (dev->pdev->subsystem_vendor == 0x1462) &&
362 (dev->pdev->subsystem_device == 0x7302)) {
363 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
364 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
368 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
369 if ((dev->pdev->device == 0x7941) &&
370 (dev->pdev->subsystem_vendor == 0x147b) &&
371 (dev->pdev->subsystem_device == 0x2412)) {
372 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
376 /* Falcon NW laptop lists vga ddc line for LVDS */
377 if ((dev->pdev->device == 0x5653) &&
378 (dev->pdev->subsystem_vendor == 0x1462) &&
379 (dev->pdev->subsystem_device == 0x0291)) {
380 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
381 i2c_bus->valid = false;
386 /* HIS X1300 is DVI+VGA, not DVI+DVI */
387 if ((dev->pdev->device == 0x7146) &&
388 (dev->pdev->subsystem_vendor == 0x17af) &&
389 (dev->pdev->subsystem_device == 0x2058)) {
390 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
394 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
395 if ((dev->pdev->device == 0x7142) &&
396 (dev->pdev->subsystem_vendor == 0x1458) &&
397 (dev->pdev->subsystem_device == 0x2134)) {
398 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
404 if ((dev->pdev->device == 0x71C5) &&
405 (dev->pdev->subsystem_vendor == 0x106b) &&
406 (dev->pdev->subsystem_device == 0x0080)) {
407 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
408 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
410 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
414 /* mac rv630, rv730, others */
415 if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
416 (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
417 *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
418 *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
421 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
422 if ((dev->pdev->device == 0x9598) &&
423 (dev->pdev->subsystem_vendor == 0x1043) &&
424 (dev->pdev->subsystem_device == 0x01da)) {
425 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
426 *connector_type = DRM_MODE_CONNECTOR_DVII;
430 /* ASUS HD 3600 board lists the DVI port as HDMI */
431 if ((dev->pdev->device == 0x9598) &&
432 (dev->pdev->subsystem_vendor == 0x1043) &&
433 (dev->pdev->subsystem_device == 0x01e4)) {
434 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
435 *connector_type = DRM_MODE_CONNECTOR_DVII;
439 /* ASUS HD 3450 board lists the DVI port as HDMI */
440 if ((dev->pdev->device == 0x95C5) &&
441 (dev->pdev->subsystem_vendor == 0x1043) &&
442 (dev->pdev->subsystem_device == 0x01e2)) {
443 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
444 *connector_type = DRM_MODE_CONNECTOR_DVII;
448 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
449 * HDMI + VGA reporting as HDMI
451 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
452 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
453 *connector_type = DRM_MODE_CONNECTOR_VGA;
458 /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port
459 * on the laptop and a DVI port on the docking station and
460 * both share the same encoder, hpd pin, and ddc line.
461 * So while the bios table is technically correct,
462 * we drop the DVI port here since xrandr has no concept of
463 * encoders and will try and drive both connectors
464 * with different crtcs which isn't possible on the hardware
465 * side and leaves no crtcs for LVDS or VGA.
467 if (((dev->pdev->device == 0x95c4) || (dev->pdev->device == 0x9591)) &&
468 (dev->pdev->subsystem_vendor == 0x1025) &&
469 (dev->pdev->subsystem_device == 0x013c)) {
470 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
471 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
472 /* actually it's a DVI-D port not DVI-I */
473 *connector_type = DRM_MODE_CONNECTOR_DVID;
478 /* XFX Pine Group device rv730 reports no VGA DDC lines
479 * even though they are wired up to record 0x93
481 if ((dev->pdev->device == 0x9498) &&
482 (dev->pdev->subsystem_vendor == 0x1682) &&
483 (dev->pdev->subsystem_device == 0x2452)) {
484 struct radeon_device *rdev = dev->dev_private;
485 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
490 const int supported_devices_connector_convert[] = {
491 DRM_MODE_CONNECTOR_Unknown,
492 DRM_MODE_CONNECTOR_VGA,
493 DRM_MODE_CONNECTOR_DVII,
494 DRM_MODE_CONNECTOR_DVID,
495 DRM_MODE_CONNECTOR_DVIA,
496 DRM_MODE_CONNECTOR_SVIDEO,
497 DRM_MODE_CONNECTOR_Composite,
498 DRM_MODE_CONNECTOR_LVDS,
499 DRM_MODE_CONNECTOR_Unknown,
500 DRM_MODE_CONNECTOR_Unknown,
501 DRM_MODE_CONNECTOR_HDMIA,
502 DRM_MODE_CONNECTOR_HDMIB,
503 DRM_MODE_CONNECTOR_Unknown,
504 DRM_MODE_CONNECTOR_Unknown,
505 DRM_MODE_CONNECTOR_9PinDIN,
506 DRM_MODE_CONNECTOR_DisplayPort
509 const uint16_t supported_devices_connector_object_id_convert[] = {
510 CONNECTOR_OBJECT_ID_NONE,
511 CONNECTOR_OBJECT_ID_VGA,
512 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
513 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
514 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
515 CONNECTOR_OBJECT_ID_COMPOSITE,
516 CONNECTOR_OBJECT_ID_SVIDEO,
517 CONNECTOR_OBJECT_ID_LVDS,
518 CONNECTOR_OBJECT_ID_9PIN_DIN,
519 CONNECTOR_OBJECT_ID_9PIN_DIN,
520 CONNECTOR_OBJECT_ID_DISPLAYPORT,
521 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
522 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
523 CONNECTOR_OBJECT_ID_SVIDEO
526 const int object_connector_convert[] = {
527 DRM_MODE_CONNECTOR_Unknown,
528 DRM_MODE_CONNECTOR_DVII,
529 DRM_MODE_CONNECTOR_DVII,
530 DRM_MODE_CONNECTOR_DVID,
531 DRM_MODE_CONNECTOR_DVID,
532 DRM_MODE_CONNECTOR_VGA,
533 DRM_MODE_CONNECTOR_Composite,
534 DRM_MODE_CONNECTOR_SVIDEO,
535 DRM_MODE_CONNECTOR_Unknown,
536 DRM_MODE_CONNECTOR_Unknown,
537 DRM_MODE_CONNECTOR_9PinDIN,
538 DRM_MODE_CONNECTOR_Unknown,
539 DRM_MODE_CONNECTOR_HDMIA,
540 DRM_MODE_CONNECTOR_HDMIB,
541 DRM_MODE_CONNECTOR_LVDS,
542 DRM_MODE_CONNECTOR_9PinDIN,
543 DRM_MODE_CONNECTOR_Unknown,
544 DRM_MODE_CONNECTOR_Unknown,
545 DRM_MODE_CONNECTOR_Unknown,
546 DRM_MODE_CONNECTOR_DisplayPort,
547 DRM_MODE_CONNECTOR_eDP,
548 DRM_MODE_CONNECTOR_Unknown
551 bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
553 struct radeon_device *rdev = dev->dev_private;
554 struct radeon_mode_info *mode_info = &rdev->mode_info;
555 struct atom_context *ctx = mode_info->atom_context;
556 int index = GetIndexIntoMasterTable(DATA, Object_Header);
557 u16 size, data_offset;
559 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
560 ATOM_ENCODER_OBJECT_TABLE *enc_obj;
561 ATOM_OBJECT_TABLE *router_obj;
562 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
563 ATOM_OBJECT_HEADER *obj_header;
564 int i, j, k, path_size, device_support;
566 u16 igp_lane_info, conn_id, connector_object_id;
567 struct radeon_i2c_bus_rec ddc_bus;
568 struct radeon_router router;
569 struct radeon_gpio_rec gpio;
570 struct radeon_hpd hpd;
572 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
578 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
579 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
580 (ctx->bios + data_offset +
581 le16_to_cpu(obj_header->usDisplayPathTableOffset));
582 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
583 (ctx->bios + data_offset +
584 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
585 enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
586 (ctx->bios + data_offset +
587 le16_to_cpu(obj_header->usEncoderObjectTableOffset));
588 router_obj = (ATOM_OBJECT_TABLE *)
589 (ctx->bios + data_offset +
590 le16_to_cpu(obj_header->usRouterObjectTableOffset));
591 device_support = le16_to_cpu(obj_header->usDeviceSupport);
594 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
595 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
596 ATOM_DISPLAY_OBJECT_PATH *path;
598 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
599 path_size += le16_to_cpu(path->usSize);
601 if (device_support & le16_to_cpu(path->usDeviceTag)) {
602 uint8_t con_obj_id, con_obj_num, con_obj_type;
605 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
608 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
611 (le16_to_cpu(path->usConnObjectId) &
612 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
614 /* TODO CV support */
615 if (le16_to_cpu(path->usDeviceTag) ==
616 ATOM_DEVICE_CV_SUPPORT)
620 if ((rdev->flags & RADEON_IS_IGP) &&
622 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
623 uint16_t igp_offset = 0;
624 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
627 GetIndexIntoMasterTable(DATA,
628 IntegratedSystemInfo);
630 if (atom_parse_data_header(ctx, index, &size, &frev,
631 &crev, &igp_offset)) {
635 (ATOM_INTEGRATED_SYSTEM_INFO_V2
636 *) (ctx->bios + igp_offset);
639 uint32_t slot_config, ct;
641 if (con_obj_num == 1)
650 ct = (slot_config >> 16) & 0xff;
652 object_connector_convert
654 connector_object_id = ct;
656 slot_config & 0xffff;
664 object_connector_convert[con_obj_id];
665 connector_object_id = con_obj_id;
670 object_connector_convert[con_obj_id];
671 connector_object_id = con_obj_id;
674 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
677 router.ddc_valid = false;
678 router.cd_valid = false;
679 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
680 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
683 (le16_to_cpu(path->usGraphicObjIds[j]) &
684 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
686 (le16_to_cpu(path->usGraphicObjIds[j]) &
687 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
689 (le16_to_cpu(path->usGraphicObjIds[j]) &
690 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
692 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
693 for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
694 u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
695 if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
696 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
697 (ctx->bios + data_offset +
698 le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
699 ATOM_ENCODER_CAP_RECORD *cap_record;
702 while (record->ucRecordSize > 0 &&
703 record->ucRecordType > 0 &&
704 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
705 switch (record->ucRecordType) {
706 case ATOM_ENCODER_CAP_RECORD_TYPE:
707 cap_record =(ATOM_ENCODER_CAP_RECORD *)
709 caps = le16_to_cpu(cap_record->usEncoderCap);
712 record = (ATOM_COMMON_RECORD_HEADER *)
713 ((char *)record + record->ucRecordSize);
715 radeon_add_atom_encoder(dev,
723 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
724 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
725 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
726 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
727 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
728 (ctx->bios + data_offset +
729 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
730 ATOM_I2C_RECORD *i2c_record;
731 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
732 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
733 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
734 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
735 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
736 (ctx->bios + data_offset +
737 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
740 router.router_id = router_obj_id;
741 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
743 if (le16_to_cpu(path->usConnObjectId) ==
744 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
748 while (record->ucRecordSize > 0 &&
749 record->ucRecordType > 0 &&
750 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
751 switch (record->ucRecordType) {
752 case ATOM_I2C_RECORD_TYPE:
757 (ATOM_I2C_ID_CONFIG_ACCESS *)
758 &i2c_record->sucI2cId;
760 radeon_lookup_i2c_gpio(rdev,
763 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
765 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
766 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
768 router.ddc_valid = true;
769 router.ddc_mux_type = ddc_path->ucMuxType;
770 router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
771 router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
773 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
774 cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
776 router.cd_valid = true;
777 router.cd_mux_type = cd_path->ucMuxType;
778 router.cd_mux_control_pin = cd_path->ucMuxControlPin;
779 router.cd_mux_state = cd_path->ucMuxState[enum_id];
782 record = (ATOM_COMMON_RECORD_HEADER *)
783 ((char *)record + record->ucRecordSize);
790 /* look up gpio for ddc, hpd */
791 ddc_bus.valid = false;
792 hpd.hpd = RADEON_HPD_NONE;
793 if ((le16_to_cpu(path->usDeviceTag) &
794 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
795 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
796 if (le16_to_cpu(path->usConnObjectId) ==
797 le16_to_cpu(con_obj->asObjects[j].
799 ATOM_COMMON_RECORD_HEADER
801 (ATOM_COMMON_RECORD_HEADER
803 (ctx->bios + data_offset +
804 le16_to_cpu(con_obj->
807 ATOM_I2C_RECORD *i2c_record;
808 ATOM_HPD_INT_RECORD *hpd_record;
809 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
811 while (record->ucRecordSize > 0 &&
812 record->ucRecordType > 0 &&
813 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
814 switch (record->ucRecordType) {
815 case ATOM_I2C_RECORD_TYPE:
820 (ATOM_I2C_ID_CONFIG_ACCESS *)
821 &i2c_record->sucI2cId;
822 ddc_bus = radeon_lookup_i2c_gpio(rdev,
826 case ATOM_HPD_INT_RECORD_TYPE:
828 (ATOM_HPD_INT_RECORD *)
830 gpio = radeon_lookup_gpio(rdev,
831 hpd_record->ucHPDIntGPIOID);
832 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
833 hpd.plugged_state = hpd_record->ucPlugged_PinState;
837 (ATOM_COMMON_RECORD_HEADER
848 /* needed for aux chan transactions */
849 ddc_bus.hpd = hpd.hpd;
851 conn_id = le16_to_cpu(path->usConnObjectId);
853 if (!radeon_atom_apply_quirks
854 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
855 &ddc_bus, &conn_id, &hpd))
858 radeon_add_atom_connector(dev,
862 connector_type, &ddc_bus,
871 radeon_link_encoder_connector(dev);
876 static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
880 struct radeon_device *rdev = dev->dev_private;
882 if (rdev->flags & RADEON_IS_IGP) {
883 return supported_devices_connector_object_id_convert
885 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
886 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
887 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
888 struct radeon_mode_info *mode_info = &rdev->mode_info;
889 struct atom_context *ctx = mode_info->atom_context;
890 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
891 uint16_t size, data_offset;
893 ATOM_XTMDS_INFO *xtmds;
895 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
896 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
898 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
899 if (connector_type == DRM_MODE_CONNECTOR_DVII)
900 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
902 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
904 if (connector_type == DRM_MODE_CONNECTOR_DVII)
905 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
907 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
910 return supported_devices_connector_object_id_convert
913 return supported_devices_connector_object_id_convert
918 struct bios_connector {
923 struct radeon_i2c_bus_rec ddc_bus;
924 struct radeon_hpd hpd;
927 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
931 struct radeon_device *rdev = dev->dev_private;
932 struct radeon_mode_info *mode_info = &rdev->mode_info;
933 struct atom_context *ctx = mode_info->atom_context;
934 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
935 uint16_t size, data_offset;
937 uint16_t device_support;
939 union atom_supported_devices *supported_devices;
940 int i, j, max_device;
941 struct bios_connector *bios_connectors;
942 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
943 struct radeon_router router;
945 router.ddc_valid = false;
946 router.cd_valid = false;
948 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
949 if (!bios_connectors)
952 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
954 kfree(bios_connectors);
959 (union atom_supported_devices *)(ctx->bios + data_offset);
961 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
964 max_device = ATOM_MAX_SUPPORTED_DEVICE;
966 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
968 for (i = 0; i < max_device; i++) {
969 ATOM_CONNECTOR_INFO_I2C ci =
970 supported_devices->info.asConnInfo[i];
972 bios_connectors[i].valid = false;
974 if (!(device_support & (1 << i))) {
978 if (i == ATOM_DEVICE_CV_INDEX) {
979 DRM_DEBUG_KMS("Skipping Component Video\n");
983 bios_connectors[i].connector_type =
984 supported_devices_connector_convert[ci.sucConnectorInfo.
988 if (bios_connectors[i].connector_type ==
989 DRM_MODE_CONNECTOR_Unknown)
992 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
994 bios_connectors[i].line_mux =
995 ci.sucI2cId.ucAccess;
997 /* give tv unique connector ids */
998 if (i == ATOM_DEVICE_TV1_INDEX) {
999 bios_connectors[i].ddc_bus.valid = false;
1000 bios_connectors[i].line_mux = 50;
1001 } else if (i == ATOM_DEVICE_TV2_INDEX) {
1002 bios_connectors[i].ddc_bus.valid = false;
1003 bios_connectors[i].line_mux = 51;
1004 } else if (i == ATOM_DEVICE_CV_INDEX) {
1005 bios_connectors[i].ddc_bus.valid = false;
1006 bios_connectors[i].line_mux = 52;
1008 bios_connectors[i].ddc_bus =
1009 radeon_lookup_i2c_gpio(rdev,
1010 bios_connectors[i].line_mux);
1012 if ((crev > 1) && (frev > 1)) {
1013 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
1016 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
1019 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
1022 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
1026 if (i == ATOM_DEVICE_DFP1_INDEX)
1027 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
1028 else if (i == ATOM_DEVICE_DFP2_INDEX)
1029 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
1031 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
1034 /* Always set the connector type to VGA for CRT1/CRT2. if they are
1035 * shared with a DVI port, we'll pick up the DVI connector when we
1036 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
1038 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
1039 bios_connectors[i].connector_type =
1040 DRM_MODE_CONNECTOR_VGA;
1042 if (!radeon_atom_apply_quirks
1043 (dev, (1 << i), &bios_connectors[i].connector_type,
1044 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
1045 &bios_connectors[i].hpd))
1048 bios_connectors[i].valid = true;
1049 bios_connectors[i].devices = (1 << i);
1051 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
1052 radeon_add_atom_encoder(dev,
1053 radeon_get_encoder_enum(dev,
1059 radeon_add_legacy_encoder(dev,
1060 radeon_get_encoder_enum(dev,
1066 /* combine shared connectors */
1067 for (i = 0; i < max_device; i++) {
1068 if (bios_connectors[i].valid) {
1069 for (j = 0; j < max_device; j++) {
1070 if (bios_connectors[j].valid && (i != j)) {
1071 if (bios_connectors[i].line_mux ==
1072 bios_connectors[j].line_mux) {
1073 /* make sure not to combine LVDS */
1074 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1075 bios_connectors[i].line_mux = 53;
1076 bios_connectors[i].ddc_bus.valid = false;
1079 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1080 bios_connectors[j].line_mux = 53;
1081 bios_connectors[j].ddc_bus.valid = false;
1084 /* combine analog and digital for DVI-I */
1085 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1086 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
1087 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1088 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
1089 bios_connectors[i].devices |=
1090 bios_connectors[j].devices;
1091 bios_connectors[i].connector_type =
1092 DRM_MODE_CONNECTOR_DVII;
1093 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
1094 bios_connectors[i].hpd =
1095 bios_connectors[j].hpd;
1096 bios_connectors[j].valid = false;
1104 /* add the connectors */
1105 for (i = 0; i < max_device; i++) {
1106 if (bios_connectors[i].valid) {
1107 uint16_t connector_object_id =
1108 atombios_get_connector_object_id(dev,
1109 bios_connectors[i].connector_type,
1110 bios_connectors[i].devices);
1111 radeon_add_atom_connector(dev,
1112 bios_connectors[i].line_mux,
1113 bios_connectors[i].devices,
1116 &bios_connectors[i].ddc_bus,
1118 connector_object_id,
1119 &bios_connectors[i].hpd,
1124 radeon_link_encoder_connector(dev);
1126 kfree(bios_connectors);
1130 union firmware_info {
1131 ATOM_FIRMWARE_INFO info;
1132 ATOM_FIRMWARE_INFO_V1_2 info_12;
1133 ATOM_FIRMWARE_INFO_V1_3 info_13;
1134 ATOM_FIRMWARE_INFO_V1_4 info_14;
1135 ATOM_FIRMWARE_INFO_V2_1 info_21;
1136 ATOM_FIRMWARE_INFO_V2_2 info_22;
1139 bool radeon_atom_get_clock_info(struct drm_device *dev)
1141 struct radeon_device *rdev = dev->dev_private;
1142 struct radeon_mode_info *mode_info = &rdev->mode_info;
1143 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1144 union firmware_info *firmware_info;
1146 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1147 struct radeon_pll *p2pll = &rdev->clock.p2pll;
1148 struct radeon_pll *dcpll = &rdev->clock.dcpll;
1149 struct radeon_pll *spll = &rdev->clock.spll;
1150 struct radeon_pll *mpll = &rdev->clock.mpll;
1151 uint16_t data_offset;
1153 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1154 &frev, &crev, &data_offset)) {
1156 (union firmware_info *)(mode_info->atom_context->bios +
1159 p1pll->reference_freq =
1160 le16_to_cpu(firmware_info->info.usReferenceClock);
1161 p1pll->reference_div = 0;
1164 p1pll->pll_out_min =
1165 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1167 p1pll->pll_out_min =
1168 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
1169 p1pll->pll_out_max =
1170 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1173 p1pll->lcd_pll_out_min =
1174 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1175 if (p1pll->lcd_pll_out_min == 0)
1176 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1177 p1pll->lcd_pll_out_max =
1178 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1179 if (p1pll->lcd_pll_out_max == 0)
1180 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1182 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1183 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1186 if (p1pll->pll_out_min == 0) {
1187 if (ASIC_IS_AVIVO(rdev))
1188 p1pll->pll_out_min = 64800;
1190 p1pll->pll_out_min = 20000;
1194 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1196 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1201 if (ASIC_IS_DCE4(rdev))
1202 spll->reference_freq =
1203 le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
1205 spll->reference_freq =
1206 le16_to_cpu(firmware_info->info.usReferenceClock);
1207 spll->reference_div = 0;
1210 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1212 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1215 if (spll->pll_out_min == 0) {
1216 if (ASIC_IS_AVIVO(rdev))
1217 spll->pll_out_min = 64800;
1219 spll->pll_out_min = 20000;
1223 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1225 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1228 if (ASIC_IS_DCE4(rdev))
1229 mpll->reference_freq =
1230 le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
1232 mpll->reference_freq =
1233 le16_to_cpu(firmware_info->info.usReferenceClock);
1234 mpll->reference_div = 0;
1237 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1239 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1242 if (mpll->pll_out_min == 0) {
1243 if (ASIC_IS_AVIVO(rdev))
1244 mpll->pll_out_min = 64800;
1246 mpll->pll_out_min = 20000;
1250 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1252 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1254 rdev->clock.default_sclk =
1255 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1256 rdev->clock.default_mclk =
1257 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1259 if (ASIC_IS_DCE4(rdev)) {
1260 rdev->clock.default_dispclk =
1261 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
1262 if (rdev->clock.default_dispclk == 0) {
1263 if (ASIC_IS_DCE5(rdev))
1264 rdev->clock.default_dispclk = 54000; /* 540 Mhz */
1266 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1268 rdev->clock.dp_extclk =
1269 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
1273 rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
1274 if (rdev->clock.max_pixel_clock == 0)
1275 rdev->clock.max_pixel_clock = 40000;
1284 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1285 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1288 bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1290 struct radeon_mode_info *mode_info = &rdev->mode_info;
1291 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1292 union igp_info *igp_info;
1296 /* sideport is AMD only */
1297 if (rdev->family == CHIP_RS600)
1300 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1301 &frev, &crev, &data_offset)) {
1302 igp_info = (union igp_info *)(mode_info->atom_context->bios +
1306 if (le32_to_cpu(igp_info->info.ulBootUpMemoryClock))
1310 if (le32_to_cpu(igp_info->info_2.ulBootUpSidePortClock))
1314 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1321 bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1322 struct radeon_encoder_int_tmds *tmds)
1324 struct drm_device *dev = encoder->base.dev;
1325 struct radeon_device *rdev = dev->dev_private;
1326 struct radeon_mode_info *mode_info = &rdev->mode_info;
1327 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1328 uint16_t data_offset;
1329 struct _ATOM_TMDS_INFO *tmds_info;
1334 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1335 &frev, &crev, &data_offset)) {
1337 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1340 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1341 for (i = 0; i < 4; i++) {
1342 tmds->tmds_pll[i].freq =
1343 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1344 tmds->tmds_pll[i].value =
1345 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1346 tmds->tmds_pll[i].value |=
1347 (tmds_info->asMiscInfo[i].
1348 ucPLL_VCO_Gain & 0x3f) << 6;
1349 tmds->tmds_pll[i].value |=
1350 (tmds_info->asMiscInfo[i].
1351 ucPLL_DutyCycle & 0xf) << 12;
1352 tmds->tmds_pll[i].value |=
1353 (tmds_info->asMiscInfo[i].
1354 ucPLL_VoltageSwing & 0xf) << 16;
1356 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
1357 tmds->tmds_pll[i].freq,
1358 tmds->tmds_pll[i].value);
1360 if (maxfreq == tmds->tmds_pll[i].freq) {
1361 tmds->tmds_pll[i].freq = 0xffffffff;
1370 bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
1371 struct radeon_atom_ss *ss,
1374 struct radeon_mode_info *mode_info = &rdev->mode_info;
1375 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
1376 uint16_t data_offset, size;
1377 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1381 memset(ss, 0, sizeof(struct radeon_atom_ss));
1382 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1383 &frev, &crev, &data_offset)) {
1385 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
1387 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1388 sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
1390 for (i = 0; i < num_indices; i++) {
1391 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1393 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1394 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1395 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1396 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1397 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1398 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
1406 static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
1407 struct radeon_atom_ss *ss,
1410 struct radeon_mode_info *mode_info = &rdev->mode_info;
1411 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1412 u16 data_offset, size;
1413 struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *igp_info;
1415 u16 percentage = 0, rate = 0;
1417 /* get any igp specific overrides */
1418 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1419 &frev, &crev, &data_offset)) {
1420 igp_info = (struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *)
1421 (mode_info->atom_context->bios + data_offset);
1423 case ASIC_INTERNAL_SS_ON_TMDS:
1424 percentage = le16_to_cpu(igp_info->usDVISSPercentage);
1425 rate = le16_to_cpu(igp_info->usDVISSpreadRateIn10Hz);
1427 case ASIC_INTERNAL_SS_ON_HDMI:
1428 percentage = le16_to_cpu(igp_info->usHDMISSPercentage);
1429 rate = le16_to_cpu(igp_info->usHDMISSpreadRateIn10Hz);
1431 case ASIC_INTERNAL_SS_ON_LVDS:
1432 percentage = le16_to_cpu(igp_info->usLvdsSSPercentage);
1433 rate = le16_to_cpu(igp_info->usLvdsSSpreadRateIn10Hz);
1437 ss->percentage = percentage;
1443 union asic_ss_info {
1444 struct _ATOM_ASIC_INTERNAL_SS_INFO info;
1445 struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
1446 struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
1449 bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
1450 struct radeon_atom_ss *ss,
1453 struct radeon_mode_info *mode_info = &rdev->mode_info;
1454 int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
1455 uint16_t data_offset, size;
1456 union asic_ss_info *ss_info;
1460 memset(ss, 0, sizeof(struct radeon_atom_ss));
1461 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1462 &frev, &crev, &data_offset)) {
1465 (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
1469 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1470 sizeof(ATOM_ASIC_SS_ASSIGNMENT);
1472 for (i = 0; i < num_indices; i++) {
1473 if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
1474 (clock <= le32_to_cpu(ss_info->info.asSpreadSpectrum[i].ulTargetClockRange))) {
1476 le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1477 ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1478 ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
1484 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1485 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
1486 for (i = 0; i < num_indices; i++) {
1487 if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
1488 (clock <= le32_to_cpu(ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange))) {
1490 le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1491 ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1492 ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
1498 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1499 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
1500 for (i = 0; i < num_indices; i++) {
1501 if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
1502 (clock <= le32_to_cpu(ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange))) {
1504 le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1505 ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1506 ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
1507 if (rdev->flags & RADEON_IS_IGP)
1508 radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
1514 DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
1523 struct _ATOM_LVDS_INFO info;
1524 struct _ATOM_LVDS_INFO_V12 info_12;
1527 struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1531 struct drm_device *dev = encoder->base.dev;
1532 struct radeon_device *rdev = dev->dev_private;
1533 struct radeon_mode_info *mode_info = &rdev->mode_info;
1534 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
1535 uint16_t data_offset, misc;
1536 union lvds_info *lvds_info;
1538 struct radeon_encoder_atom_dig *lvds = NULL;
1539 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
1541 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1542 &frev, &crev, &data_offset)) {
1544 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
1546 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1551 lvds->native_mode.clock =
1552 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
1553 lvds->native_mode.hdisplay =
1554 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
1555 lvds->native_mode.vdisplay =
1556 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
1557 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1558 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1559 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1560 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1561 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1562 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1563 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1564 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1565 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1566 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
1567 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1568 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
1569 lvds->panel_pwr_delay =
1570 le16_to_cpu(lvds_info->info.usOffDelayInMs);
1571 lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
1573 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1574 if (misc & ATOM_VSYNC_POLARITY)
1575 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1576 if (misc & ATOM_HSYNC_POLARITY)
1577 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1578 if (misc & ATOM_COMPOSITESYNC)
1579 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1580 if (misc & ATOM_INTERLACE)
1581 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1582 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1583 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1585 lvds->native_mode.width_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageHSize);
1586 lvds->native_mode.height_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageVSize);
1588 /* set crtc values */
1589 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
1591 lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
1593 encoder->native_mode = lvds->native_mode;
1595 if (encoder_enum == 2)
1598 lvds->linkb = false;
1600 /* parse the lcd record table */
1601 if (le16_to_cpu(lvds_info->info.usModePatchTableOffset)) {
1602 ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
1603 ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
1604 bool bad_record = false;
1607 if ((frev == 1) && (crev < 2))
1609 record = (u8 *)(mode_info->atom_context->bios +
1610 le16_to_cpu(lvds_info->info.usModePatchTableOffset));
1613 record = (u8 *)(mode_info->atom_context->bios +
1615 le16_to_cpu(lvds_info->info.usModePatchTableOffset));
1616 while (*record != ATOM_RECORD_END_TYPE) {
1618 case LCD_MODE_PATCH_RECORD_MODE_TYPE:
1619 record += sizeof(ATOM_PATCH_RECORD_MODE);
1621 case LCD_RTS_RECORD_TYPE:
1622 record += sizeof(ATOM_LCD_RTS_RECORD);
1624 case LCD_CAP_RECORD_TYPE:
1625 record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
1627 case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
1628 fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
1629 if (fake_edid_record->ucFakeEDIDLength) {
1632 max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
1633 edid = kmalloc(edid_size, GFP_KERNEL);
1635 memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
1636 fake_edid_record->ucFakeEDIDLength);
1638 if (drm_edid_is_valid(edid)) {
1639 rdev->mode_info.bios_hardcoded_edid = edid;
1640 rdev->mode_info.bios_hardcoded_edid_size = edid_size;
1645 record += sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
1647 case LCD_PANEL_RESOLUTION_RECORD_TYPE:
1648 panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
1649 lvds->native_mode.width_mm = panel_res_record->usHSize;
1650 lvds->native_mode.height_mm = panel_res_record->usVSize;
1651 record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
1654 DRM_ERROR("Bad LCD record %d\n", *record);
1666 struct radeon_encoder_primary_dac *
1667 radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1669 struct drm_device *dev = encoder->base.dev;
1670 struct radeon_device *rdev = dev->dev_private;
1671 struct radeon_mode_info *mode_info = &rdev->mode_info;
1672 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1673 uint16_t data_offset;
1674 struct _COMPASSIONATE_DATA *dac_info;
1677 struct radeon_encoder_primary_dac *p_dac = NULL;
1679 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1680 &frev, &crev, &data_offset)) {
1681 dac_info = (struct _COMPASSIONATE_DATA *)
1682 (mode_info->atom_context->bios + data_offset);
1684 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1689 bg = dac_info->ucDAC1_BG_Adjustment;
1690 dac = dac_info->ucDAC1_DAC_Adjustment;
1691 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1697 bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
1698 struct drm_display_mode *mode)
1700 struct radeon_mode_info *mode_info = &rdev->mode_info;
1701 ATOM_ANALOG_TV_INFO *tv_info;
1702 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1703 ATOM_DTD_FORMAT *dtd_timings;
1704 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1706 u16 data_offset, misc;
1708 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1709 &frev, &crev, &data_offset))
1714 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1715 if (index >= MAX_SUPPORTED_TV_TIMING)
1718 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1719 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1720 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1721 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1722 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
1724 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1725 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1726 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1727 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1728 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
1731 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1732 if (misc & ATOM_VSYNC_POLARITY)
1733 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1734 if (misc & ATOM_HSYNC_POLARITY)
1735 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1736 if (misc & ATOM_COMPOSITESYNC)
1737 mode->flags |= DRM_MODE_FLAG_CSYNC;
1738 if (misc & ATOM_INTERLACE)
1739 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1740 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1741 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1743 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
1746 /* PAL timings appear to have wrong values for totals */
1747 mode->crtc_htotal -= 1;
1748 mode->crtc_vtotal -= 1;
1752 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
1753 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
1756 dtd_timings = &tv_info_v1_2->aModeTimings[index];
1757 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1758 le16_to_cpu(dtd_timings->usHBlanking_Time);
1759 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1760 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1761 le16_to_cpu(dtd_timings->usHSyncOffset);
1762 mode->crtc_hsync_end = mode->crtc_hsync_start +
1763 le16_to_cpu(dtd_timings->usHSyncWidth);
1765 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1766 le16_to_cpu(dtd_timings->usVBlanking_Time);
1767 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1768 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1769 le16_to_cpu(dtd_timings->usVSyncOffset);
1770 mode->crtc_vsync_end = mode->crtc_vsync_start +
1771 le16_to_cpu(dtd_timings->usVSyncWidth);
1774 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1775 if (misc & ATOM_VSYNC_POLARITY)
1776 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1777 if (misc & ATOM_HSYNC_POLARITY)
1778 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1779 if (misc & ATOM_COMPOSITESYNC)
1780 mode->flags |= DRM_MODE_FLAG_CSYNC;
1781 if (misc & ATOM_INTERLACE)
1782 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1783 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1784 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1786 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
1793 radeon_atombios_get_tv_info(struct radeon_device *rdev)
1795 struct radeon_mode_info *mode_info = &rdev->mode_info;
1796 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1797 uint16_t data_offset;
1799 struct _ATOM_ANALOG_TV_INFO *tv_info;
1800 enum radeon_tv_std tv_std = TV_STD_NTSC;
1802 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1803 &frev, &crev, &data_offset)) {
1805 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1806 (mode_info->atom_context->bios + data_offset);
1808 switch (tv_info->ucTV_BootUpDefaultStandard) {
1810 tv_std = TV_STD_NTSC;
1811 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
1814 tv_std = TV_STD_NTSC_J;
1815 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
1818 tv_std = TV_STD_PAL;
1819 DRM_DEBUG_KMS("Default TV standard: PAL\n");
1822 tv_std = TV_STD_PAL_M;
1823 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
1826 tv_std = TV_STD_PAL_N;
1827 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
1830 tv_std = TV_STD_PAL_CN;
1831 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
1834 tv_std = TV_STD_PAL_60;
1835 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
1838 tv_std = TV_STD_SECAM;
1839 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
1842 tv_std = TV_STD_NTSC;
1843 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
1850 struct radeon_encoder_tv_dac *
1851 radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1853 struct drm_device *dev = encoder->base.dev;
1854 struct radeon_device *rdev = dev->dev_private;
1855 struct radeon_mode_info *mode_info = &rdev->mode_info;
1856 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1857 uint16_t data_offset;
1858 struct _COMPASSIONATE_DATA *dac_info;
1861 struct radeon_encoder_tv_dac *tv_dac = NULL;
1863 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1864 &frev, &crev, &data_offset)) {
1866 dac_info = (struct _COMPASSIONATE_DATA *)
1867 (mode_info->atom_context->bios + data_offset);
1869 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1874 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1875 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1876 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1878 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1879 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1880 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1882 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1883 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1884 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1886 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
1891 static const char *thermal_controller_names[] = {
1902 static const char *pp_lib_thermal_controller_names[] = {
1922 struct _ATOM_POWERPLAY_INFO info;
1923 struct _ATOM_POWERPLAY_INFO_V2 info_2;
1924 struct _ATOM_POWERPLAY_INFO_V3 info_3;
1925 struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
1926 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
1927 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
1930 union pplib_clock_info {
1931 struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
1932 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
1933 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
1934 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
1937 union pplib_power_state {
1938 struct _ATOM_PPLIB_STATE v1;
1939 struct _ATOM_PPLIB_STATE_V2 v2;
1942 static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
1944 u32 misc, u32 misc2)
1946 rdev->pm.power_state[state_index].misc = misc;
1947 rdev->pm.power_state[state_index].misc2 = misc2;
1948 /* order matters! */
1949 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1950 rdev->pm.power_state[state_index].type =
1951 POWER_STATE_TYPE_POWERSAVE;
1952 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1953 rdev->pm.power_state[state_index].type =
1954 POWER_STATE_TYPE_BATTERY;
1955 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1956 rdev->pm.power_state[state_index].type =
1957 POWER_STATE_TYPE_BATTERY;
1958 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1959 rdev->pm.power_state[state_index].type =
1960 POWER_STATE_TYPE_BALANCED;
1961 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
1962 rdev->pm.power_state[state_index].type =
1963 POWER_STATE_TYPE_PERFORMANCE;
1964 rdev->pm.power_state[state_index].flags &=
1965 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1967 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1968 rdev->pm.power_state[state_index].type =
1969 POWER_STATE_TYPE_BALANCED;
1970 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
1971 rdev->pm.power_state[state_index].type =
1972 POWER_STATE_TYPE_DEFAULT;
1973 rdev->pm.default_power_state_index = state_index;
1974 rdev->pm.power_state[state_index].default_clock_mode =
1975 &rdev->pm.power_state[state_index].clock_info[0];
1976 } else if (state_index == 0) {
1977 rdev->pm.power_state[state_index].clock_info[0].flags |=
1978 RADEON_PM_MODE_NO_DISPLAY;
1982 static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
1984 struct radeon_mode_info *mode_info = &rdev->mode_info;
1985 u32 misc, misc2 = 0;
1986 int num_modes = 0, i;
1987 int state_index = 0;
1988 struct radeon_i2c_bus_rec i2c_bus;
1989 union power_info *power_info;
1990 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
1994 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
1995 &frev, &crev, &data_offset))
1997 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
1999 /* add the i2c bus for thermal/fan chip */
2000 if (power_info->info.ucOverdriveThermalController > 0) {
2001 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2002 thermal_controller_names[power_info->info.ucOverdriveThermalController],
2003 power_info->info.ucOverdriveControllerAddress >> 1);
2004 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
2005 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2006 if (rdev->pm.i2c_bus) {
2007 struct i2c_board_info info = { };
2008 const char *name = thermal_controller_names[power_info->info.
2009 ucOverdriveThermalController];
2010 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
2011 strlcpy(info.type, name, sizeof(info.type));
2012 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2015 num_modes = power_info->info.ucNumOfPowerModeEntries;
2016 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
2017 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
2018 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
2019 if (!rdev->pm.power_state)
2021 /* last mode is usually default, array is low to high */
2022 for (i = 0; i < num_modes; i++) {
2023 rdev->pm.power_state[state_index].clock_info =
2024 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2025 if (!rdev->pm.power_state[state_index].clock_info)
2027 rdev->pm.power_state[state_index].num_clock_modes = 1;
2028 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2031 rdev->pm.power_state[state_index].clock_info[0].mclk =
2032 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
2033 rdev->pm.power_state[state_index].clock_info[0].sclk =
2034 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
2035 /* skip invalid modes */
2036 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2037 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2039 rdev->pm.power_state[state_index].pcie_lanes =
2040 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
2041 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
2042 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2043 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2044 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2046 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2047 radeon_lookup_gpio(rdev,
2048 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
2049 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2050 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2053 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2055 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2056 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2058 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2059 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
2061 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2062 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
2066 rdev->pm.power_state[state_index].clock_info[0].mclk =
2067 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
2068 rdev->pm.power_state[state_index].clock_info[0].sclk =
2069 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
2070 /* skip invalid modes */
2071 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2072 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2074 rdev->pm.power_state[state_index].pcie_lanes =
2075 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
2076 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
2077 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
2078 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2079 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2080 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2082 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2083 radeon_lookup_gpio(rdev,
2084 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
2085 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2086 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2089 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2091 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2092 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2094 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2095 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
2097 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2098 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2102 rdev->pm.power_state[state_index].clock_info[0].mclk =
2103 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
2104 rdev->pm.power_state[state_index].clock_info[0].sclk =
2105 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
2106 /* skip invalid modes */
2107 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2108 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2110 rdev->pm.power_state[state_index].pcie_lanes =
2111 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
2112 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
2113 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
2114 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2115 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2116 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2118 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2119 radeon_lookup_gpio(rdev,
2120 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
2121 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2122 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2125 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2127 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2128 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2130 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2131 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
2132 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
2133 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
2135 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
2136 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
2139 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2140 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2145 /* last mode is usually default */
2146 if (rdev->pm.default_power_state_index == -1) {
2147 rdev->pm.power_state[state_index - 1].type =
2148 POWER_STATE_TYPE_DEFAULT;
2149 rdev->pm.default_power_state_index = state_index - 1;
2150 rdev->pm.power_state[state_index - 1].default_clock_mode =
2151 &rdev->pm.power_state[state_index - 1].clock_info[0];
2152 rdev->pm.power_state[state_index].flags &=
2153 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2154 rdev->pm.power_state[state_index].misc = 0;
2155 rdev->pm.power_state[state_index].misc2 = 0;
2160 static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
2161 ATOM_PPLIB_THERMALCONTROLLER *controller)
2163 struct radeon_i2c_bus_rec i2c_bus;
2165 /* add the i2c bus for thermal/fan chip */
2166 if (controller->ucType > 0) {
2167 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
2168 DRM_INFO("Internal thermal controller %s fan control\n",
2169 (controller->ucFanParameters &
2170 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2171 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
2172 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
2173 DRM_INFO("Internal thermal controller %s fan control\n",
2174 (controller->ucFanParameters &
2175 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2176 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
2177 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
2178 DRM_INFO("Internal thermal controller %s fan control\n",
2179 (controller->ucFanParameters &
2180 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2181 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
2182 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
2183 DRM_INFO("Internal thermal controller %s fan control\n",
2184 (controller->ucFanParameters &
2185 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2186 rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
2187 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
2188 DRM_INFO("Internal thermal controller %s fan control\n",
2189 (controller->ucFanParameters &
2190 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2191 rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
2192 } else if ((controller->ucType ==
2193 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
2194 (controller->ucType ==
2195 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
2196 (controller->ucType ==
2197 ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
2198 DRM_INFO("Special thermal controller config\n");
2200 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2201 pp_lib_thermal_controller_names[controller->ucType],
2202 controller->ucI2cAddress >> 1,
2203 (controller->ucFanParameters &
2204 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2205 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
2206 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2207 if (rdev->pm.i2c_bus) {
2208 struct i2c_board_info info = { };
2209 const char *name = pp_lib_thermal_controller_names[controller->ucType];
2210 info.addr = controller->ucI2cAddress >> 1;
2211 strlcpy(info.type, name, sizeof(info.type));
2212 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2218 static void radeon_atombios_get_default_voltages(struct radeon_device *rdev,
2219 u16 *vddc, u16 *vddci)
2221 struct radeon_mode_info *mode_info = &rdev->mode_info;
2222 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
2225 union firmware_info *firmware_info;
2230 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2231 &frev, &crev, &data_offset)) {
2233 (union firmware_info *)(mode_info->atom_context->bios +
2235 *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
2236 if ((frev == 2) && (crev >= 2))
2237 *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
2241 static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
2242 int state_index, int mode_index,
2243 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
2246 u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
2247 u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
2250 radeon_atombios_get_default_voltages(rdev, &vddc, &vddci);
2252 rdev->pm.power_state[state_index].misc = misc;
2253 rdev->pm.power_state[state_index].misc2 = misc2;
2254 rdev->pm.power_state[state_index].pcie_lanes =
2255 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2256 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2257 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2258 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2259 rdev->pm.power_state[state_index].type =
2260 POWER_STATE_TYPE_BATTERY;
2262 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2263 rdev->pm.power_state[state_index].type =
2264 POWER_STATE_TYPE_BALANCED;
2266 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2267 rdev->pm.power_state[state_index].type =
2268 POWER_STATE_TYPE_PERFORMANCE;
2270 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2271 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2272 rdev->pm.power_state[state_index].type =
2273 POWER_STATE_TYPE_PERFORMANCE;
2276 rdev->pm.power_state[state_index].flags = 0;
2277 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2278 rdev->pm.power_state[state_index].flags |=
2279 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2280 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
2281 rdev->pm.power_state[state_index].type =
2282 POWER_STATE_TYPE_DEFAULT;
2283 rdev->pm.default_power_state_index = state_index;
2284 rdev->pm.power_state[state_index].default_clock_mode =
2285 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
2286 if (ASIC_IS_DCE5(rdev) && !(rdev->flags & RADEON_IS_IGP)) {
2287 /* NI chips post without MC ucode, so default clocks are strobe mode only */
2288 rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
2289 rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
2290 rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
2291 rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
2293 /* patch the table values with the default slck/mclk from firmware info */
2294 for (j = 0; j < mode_index; j++) {
2295 rdev->pm.power_state[state_index].clock_info[j].mclk =
2296 rdev->clock.default_mclk;
2297 rdev->pm.power_state[state_index].clock_info[j].sclk =
2298 rdev->clock.default_sclk;
2300 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2307 static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
2308 int state_index, int mode_index,
2309 union pplib_clock_info *clock_info)
2313 if (rdev->flags & RADEON_IS_IGP) {
2314 if (rdev->family >= CHIP_PALM) {
2315 sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
2316 sclk |= clock_info->sumo.ucEngineClockHigh << 16;
2317 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2319 sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
2320 sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
2321 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2323 } else if (ASIC_IS_DCE4(rdev)) {
2324 sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
2325 sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
2326 mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
2327 mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
2328 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2329 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2330 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2332 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2333 le16_to_cpu(clock_info->evergreen.usVDDC);
2334 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
2335 le16_to_cpu(clock_info->evergreen.usVDDCI);
2337 sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
2338 sclk |= clock_info->r600.ucEngineClockHigh << 16;
2339 mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
2340 mclk |= clock_info->r600.ucMemoryClockHigh << 16;
2341 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2342 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2343 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2345 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2346 le16_to_cpu(clock_info->r600.usVDDC);
2349 /* patch up vddc if necessary */
2350 if (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage == 0xff01) {
2353 if (radeon_atom_get_max_vddc(rdev, &vddc) == 0)
2354 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
2357 if (rdev->flags & RADEON_IS_IGP) {
2358 /* skip invalid modes */
2359 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2362 /* skip invalid modes */
2363 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2364 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2370 static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
2372 struct radeon_mode_info *mode_info = &rdev->mode_info;
2373 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2374 union pplib_power_state *power_state;
2376 int state_index = 0, mode_index = 0;
2377 union pplib_clock_info *clock_info;
2379 union power_info *power_info;
2380 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2384 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2385 &frev, &crev, &data_offset))
2387 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2389 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
2390 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2391 power_info->pplib.ucNumStates, GFP_KERNEL);
2392 if (!rdev->pm.power_state)
2394 /* first mode is usually default, followed by low to high */
2395 for (i = 0; i < power_info->pplib.ucNumStates; i++) {
2397 power_state = (union pplib_power_state *)
2398 (mode_info->atom_context->bios + data_offset +
2399 le16_to_cpu(power_info->pplib.usStateArrayOffset) +
2400 i * power_info->pplib.ucStateEntrySize);
2401 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2402 (mode_info->atom_context->bios + data_offset +
2403 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
2404 (power_state->v1.ucNonClockStateIndex *
2405 power_info->pplib.ucNonClockSize));
2406 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2407 ((power_info->pplib.ucStateEntrySize - 1) ?
2408 (power_info->pplib.ucStateEntrySize - 1) : 1),
2410 if (!rdev->pm.power_state[i].clock_info)
2412 if (power_info->pplib.ucStateEntrySize - 1) {
2413 for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
2414 clock_info = (union pplib_clock_info *)
2415 (mode_info->atom_context->bios + data_offset +
2416 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
2417 (power_state->v1.ucClockStateIndices[j] *
2418 power_info->pplib.ucClockInfoSize));
2419 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2420 state_index, mode_index,
2426 rdev->pm.power_state[state_index].clock_info[0].mclk =
2427 rdev->clock.default_mclk;
2428 rdev->pm.power_state[state_index].clock_info[0].sclk =
2429 rdev->clock.default_sclk;
2432 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2434 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2439 /* if multiple clock modes, mark the lowest as no display */
2440 for (i = 0; i < state_index; i++) {
2441 if (rdev->pm.power_state[i].num_clock_modes > 1)
2442 rdev->pm.power_state[i].clock_info[0].flags |=
2443 RADEON_PM_MODE_NO_DISPLAY;
2445 /* first mode is usually default */
2446 if (rdev->pm.default_power_state_index == -1) {
2447 rdev->pm.power_state[0].type =
2448 POWER_STATE_TYPE_DEFAULT;
2449 rdev->pm.default_power_state_index = 0;
2450 rdev->pm.power_state[0].default_clock_mode =
2451 &rdev->pm.power_state[0].clock_info[0];
2456 static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
2458 struct radeon_mode_info *mode_info = &rdev->mode_info;
2459 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2460 union pplib_power_state *power_state;
2461 int i, j, non_clock_array_index, clock_array_index;
2462 int state_index = 0, mode_index = 0;
2463 union pplib_clock_info *clock_info;
2464 struct StateArray *state_array;
2465 struct ClockInfoArray *clock_info_array;
2466 struct NonClockInfoArray *non_clock_info_array;
2468 union power_info *power_info;
2469 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2473 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2474 &frev, &crev, &data_offset))
2476 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2478 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
2479 state_array = (struct StateArray *)
2480 (mode_info->atom_context->bios + data_offset +
2481 le16_to_cpu(power_info->pplib.usStateArrayOffset));
2482 clock_info_array = (struct ClockInfoArray *)
2483 (mode_info->atom_context->bios + data_offset +
2484 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
2485 non_clock_info_array = (struct NonClockInfoArray *)
2486 (mode_info->atom_context->bios + data_offset +
2487 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
2488 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2489 state_array->ucNumEntries, GFP_KERNEL);
2490 if (!rdev->pm.power_state)
2492 for (i = 0; i < state_array->ucNumEntries; i++) {
2494 power_state = (union pplib_power_state *)&state_array->states[i];
2495 /* XXX this might be an inagua bug... */
2496 non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
2497 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2498 &non_clock_info_array->nonClockInfo[non_clock_array_index];
2499 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2500 (power_state->v2.ucNumDPMLevels ?
2501 power_state->v2.ucNumDPMLevels : 1),
2503 if (!rdev->pm.power_state[i].clock_info)
2505 if (power_state->v2.ucNumDPMLevels) {
2506 for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2507 clock_array_index = power_state->v2.clockInfoIndex[j];
2508 /* XXX this might be an inagua bug... */
2509 if (clock_array_index >= clock_info_array->ucNumEntries)
2511 clock_info = (union pplib_clock_info *)
2512 &clock_info_array->clockInfo[clock_array_index];
2513 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2514 state_index, mode_index,
2520 rdev->pm.power_state[state_index].clock_info[0].mclk =
2521 rdev->clock.default_mclk;
2522 rdev->pm.power_state[state_index].clock_info[0].sclk =
2523 rdev->clock.default_sclk;
2526 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2528 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2533 /* if multiple clock modes, mark the lowest as no display */
2534 for (i = 0; i < state_index; i++) {
2535 if (rdev->pm.power_state[i].num_clock_modes > 1)
2536 rdev->pm.power_state[i].clock_info[0].flags |=
2537 RADEON_PM_MODE_NO_DISPLAY;
2539 /* first mode is usually default */
2540 if (rdev->pm.default_power_state_index == -1) {
2541 rdev->pm.power_state[0].type =
2542 POWER_STATE_TYPE_DEFAULT;
2543 rdev->pm.default_power_state_index = 0;
2544 rdev->pm.power_state[0].default_clock_mode =
2545 &rdev->pm.power_state[0].clock_info[0];
2550 void radeon_atombios_get_power_modes(struct radeon_device *rdev)
2552 struct radeon_mode_info *mode_info = &rdev->mode_info;
2553 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2556 int state_index = 0;
2558 rdev->pm.default_power_state_index = -1;
2560 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2561 &frev, &crev, &data_offset)) {
2566 state_index = radeon_atombios_parse_power_table_1_3(rdev);
2570 state_index = radeon_atombios_parse_power_table_4_5(rdev);
2573 state_index = radeon_atombios_parse_power_table_6(rdev);
2579 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
2580 if (rdev->pm.power_state) {
2581 rdev->pm.power_state[0].clock_info =
2582 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2583 if (rdev->pm.power_state[0].clock_info) {
2584 /* add the default mode */
2585 rdev->pm.power_state[state_index].type =
2586 POWER_STATE_TYPE_DEFAULT;
2587 rdev->pm.power_state[state_index].num_clock_modes = 1;
2588 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2589 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2590 rdev->pm.power_state[state_index].default_clock_mode =
2591 &rdev->pm.power_state[state_index].clock_info[0];
2592 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2593 rdev->pm.power_state[state_index].pcie_lanes = 16;
2594 rdev->pm.default_power_state_index = state_index;
2595 rdev->pm.power_state[state_index].flags = 0;
2601 rdev->pm.num_power_states = state_index;
2603 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2604 rdev->pm.current_clock_mode_index = 0;
2605 rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
2608 void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2610 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2611 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2613 args.ucEnable = enable;
2615 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2618 uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2620 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2621 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2623 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2624 return le32_to_cpu(args.ulReturnEngineClock);
2627 uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2629 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2630 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2632 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2633 return le32_to_cpu(args.ulReturnMemoryClock);
2636 void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2639 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2640 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2642 args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */
2644 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2647 void radeon_atom_set_memory_clock(struct radeon_device *rdev,
2650 SET_MEMORY_CLOCK_PS_ALLOCATION args;
2651 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
2653 if (rdev->flags & RADEON_IS_IGP)
2656 args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */
2658 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2662 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2663 struct _SET_VOLTAGE_PARAMETERS v1;
2664 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2667 void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
2669 union set_voltage args;
2670 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
2671 u8 frev, crev, volt_index = voltage_level;
2673 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2676 /* 0xff01 is a flag rather then an actual voltage */
2677 if (voltage_level == 0xff01)
2682 args.v1.ucVoltageType = voltage_type;
2683 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
2684 args.v1.ucVoltageIndex = volt_index;
2687 args.v2.ucVoltageType = voltage_type;
2688 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
2689 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
2692 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2696 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2699 int radeon_atom_get_max_vddc(struct radeon_device *rdev,
2702 union set_voltage args;
2703 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
2706 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2713 args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
2714 args.v2.ucVoltageMode = 0;
2715 args.v2.usVoltageLevel = 0;
2717 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2719 *voltage = le16_to_cpu(args.v2.usVoltageLevel);
2722 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2729 void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
2731 struct radeon_device *rdev = dev->dev_private;
2732 uint32_t bios_2_scratch, bios_6_scratch;
2734 if (rdev->family >= CHIP_R600) {
2735 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2736 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2738 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
2739 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2742 /* let the bios control the backlight */
2743 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
2745 /* tell the bios not to handle mode switching */
2746 bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
2748 if (rdev->family >= CHIP_R600) {
2749 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2750 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2752 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2753 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2758 void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
2760 uint32_t scratch_reg;
2763 if (rdev->family >= CHIP_R600)
2764 scratch_reg = R600_BIOS_0_SCRATCH;
2766 scratch_reg = RADEON_BIOS_0_SCRATCH;
2768 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2769 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
2772 void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
2774 uint32_t scratch_reg;
2777 if (rdev->family >= CHIP_R600)
2778 scratch_reg = R600_BIOS_0_SCRATCH;
2780 scratch_reg = RADEON_BIOS_0_SCRATCH;
2782 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2783 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
2786 void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
2788 struct drm_device *dev = encoder->dev;
2789 struct radeon_device *rdev = dev->dev_private;
2790 uint32_t bios_6_scratch;
2792 if (rdev->family >= CHIP_R600)
2793 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2795 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2798 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
2799 bios_6_scratch &= ~ATOM_S6_ACC_MODE;
2801 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
2802 bios_6_scratch |= ATOM_S6_ACC_MODE;
2805 if (rdev->family >= CHIP_R600)
2806 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2808 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2811 /* at some point we may want to break this out into individual functions */
2813 radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
2814 struct drm_encoder *encoder,
2817 struct drm_device *dev = connector->dev;
2818 struct radeon_device *rdev = dev->dev_private;
2819 struct radeon_connector *radeon_connector =
2820 to_radeon_connector(connector);
2821 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2822 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
2824 if (rdev->family >= CHIP_R600) {
2825 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2826 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2827 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2829 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2830 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2831 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2834 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
2835 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
2837 DRM_DEBUG_KMS("TV1 connected\n");
2838 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
2839 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
2841 DRM_DEBUG_KMS("TV1 disconnected\n");
2842 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
2843 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
2844 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
2847 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
2848 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
2850 DRM_DEBUG_KMS("CV connected\n");
2851 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
2852 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
2854 DRM_DEBUG_KMS("CV disconnected\n");
2855 bios_0_scratch &= ~ATOM_S0_CV_MASK;
2856 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
2857 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
2860 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
2861 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
2863 DRM_DEBUG_KMS("LCD1 connected\n");
2864 bios_0_scratch |= ATOM_S0_LCD1;
2865 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
2866 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
2868 DRM_DEBUG_KMS("LCD1 disconnected\n");
2869 bios_0_scratch &= ~ATOM_S0_LCD1;
2870 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
2871 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
2874 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
2875 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
2877 DRM_DEBUG_KMS("CRT1 connected\n");
2878 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
2879 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
2880 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
2882 DRM_DEBUG_KMS("CRT1 disconnected\n");
2883 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
2884 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
2885 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
2888 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
2889 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
2891 DRM_DEBUG_KMS("CRT2 connected\n");
2892 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
2893 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
2894 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
2896 DRM_DEBUG_KMS("CRT2 disconnected\n");
2897 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
2898 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
2899 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
2902 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
2903 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
2905 DRM_DEBUG_KMS("DFP1 connected\n");
2906 bios_0_scratch |= ATOM_S0_DFP1;
2907 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
2908 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
2910 DRM_DEBUG_KMS("DFP1 disconnected\n");
2911 bios_0_scratch &= ~ATOM_S0_DFP1;
2912 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
2913 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
2916 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
2917 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
2919 DRM_DEBUG_KMS("DFP2 connected\n");
2920 bios_0_scratch |= ATOM_S0_DFP2;
2921 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
2922 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
2924 DRM_DEBUG_KMS("DFP2 disconnected\n");
2925 bios_0_scratch &= ~ATOM_S0_DFP2;
2926 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
2927 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
2930 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
2931 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
2933 DRM_DEBUG_KMS("DFP3 connected\n");
2934 bios_0_scratch |= ATOM_S0_DFP3;
2935 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
2936 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
2938 DRM_DEBUG_KMS("DFP3 disconnected\n");
2939 bios_0_scratch &= ~ATOM_S0_DFP3;
2940 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
2941 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
2944 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
2945 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
2947 DRM_DEBUG_KMS("DFP4 connected\n");
2948 bios_0_scratch |= ATOM_S0_DFP4;
2949 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
2950 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
2952 DRM_DEBUG_KMS("DFP4 disconnected\n");
2953 bios_0_scratch &= ~ATOM_S0_DFP4;
2954 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
2955 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
2958 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
2959 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
2961 DRM_DEBUG_KMS("DFP5 connected\n");
2962 bios_0_scratch |= ATOM_S0_DFP5;
2963 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
2964 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
2966 DRM_DEBUG_KMS("DFP5 disconnected\n");
2967 bios_0_scratch &= ~ATOM_S0_DFP5;
2968 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2969 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2973 if (rdev->family >= CHIP_R600) {
2974 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2975 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2976 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2978 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
2979 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2980 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2985 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
2987 struct drm_device *dev = encoder->dev;
2988 struct radeon_device *rdev = dev->dev_private;
2989 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2990 uint32_t bios_3_scratch;
2992 if (rdev->family >= CHIP_R600)
2993 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2995 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2997 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2998 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
2999 bios_3_scratch |= (crtc << 18);
3001 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
3002 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
3003 bios_3_scratch |= (crtc << 24);
3005 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3006 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
3007 bios_3_scratch |= (crtc << 16);
3009 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3010 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
3011 bios_3_scratch |= (crtc << 20);
3013 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3014 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
3015 bios_3_scratch |= (crtc << 17);
3017 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3018 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
3019 bios_3_scratch |= (crtc << 19);
3021 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3022 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
3023 bios_3_scratch |= (crtc << 23);
3025 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
3026 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
3027 bios_3_scratch |= (crtc << 25);
3030 if (rdev->family >= CHIP_R600)
3031 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
3033 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
3037 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
3039 struct drm_device *dev = encoder->dev;
3040 struct radeon_device *rdev = dev->dev_private;
3041 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3042 uint32_t bios_2_scratch;
3044 if (rdev->family >= CHIP_R600)
3045 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
3047 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
3049 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
3051 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
3053 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
3055 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
3057 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
3059 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
3061 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3063 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
3065 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
3067 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3069 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
3071 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
3073 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3075 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
3077 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
3079 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3081 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
3083 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
3085 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3087 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
3089 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
3091 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
3093 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
3095 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
3097 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
3099 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
3101 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
3103 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
3105 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
3107 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
3110 if (rdev->family >= CHIP_R600)
3111 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
3113 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);