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 <drm/radeon_drm.h>
31 #include "atom-bits.h"
34 radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
35 uint32_t supported_device, u16 caps);
37 /* from radeon_legacy_encoder.c */
39 radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
40 uint32_t supported_device);
42 union atom_supported_devices {
43 struct _ATOM_SUPPORTED_DEVICES_INFO info;
44 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
45 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
48 static void radeon_lookup_i2c_gpio_quirks(struct radeon_device *rdev,
49 ATOM_GPIO_I2C_ASSIGMENT *gpio,
52 /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
53 if ((rdev->family == CHIP_R420) ||
54 (rdev->family == CHIP_R423) ||
55 (rdev->family == CHIP_RV410)) {
56 if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
57 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
58 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
59 gpio->ucClkMaskShift = 0x19;
60 gpio->ucDataMaskShift = 0x18;
64 /* some evergreen boards have bad data for this entry */
65 if (ASIC_IS_DCE4(rdev)) {
67 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
68 (gpio->sucI2cId.ucAccess == 0)) {
69 gpio->sucI2cId.ucAccess = 0x97;
70 gpio->ucDataMaskShift = 8;
71 gpio->ucDataEnShift = 8;
72 gpio->ucDataY_Shift = 8;
73 gpio->ucDataA_Shift = 8;
77 /* some DCE3 boards have bad data for this entry */
78 if (ASIC_IS_DCE3(rdev)) {
80 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
81 (gpio->sucI2cId.ucAccess == 0x94))
82 gpio->sucI2cId.ucAccess = 0x14;
86 static struct radeon_i2c_bus_rec radeon_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio)
88 struct radeon_i2c_bus_rec i2c;
90 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
92 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
93 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
94 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
95 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
96 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
97 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
98 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
99 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
100 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
101 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
102 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
103 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
104 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
105 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
106 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
107 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
109 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
110 i2c.hw_capable = true;
112 i2c.hw_capable = false;
114 if (gpio->sucI2cId.ucAccess == 0xa0)
119 i2c.i2c_id = gpio->sucI2cId.ucAccess;
121 if (i2c.mask_clk_reg)
129 static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
132 struct atom_context *ctx = rdev->mode_info.atom_context;
133 ATOM_GPIO_I2C_ASSIGMENT *gpio;
134 struct radeon_i2c_bus_rec i2c;
135 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
136 struct _ATOM_GPIO_I2C_INFO *i2c_info;
137 uint16_t data_offset, size;
140 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
143 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
144 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
146 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
147 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
149 gpio = &i2c_info->asGPIO_Info[0];
150 for (i = 0; i < num_indices; i++) {
152 radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
154 if (gpio->sucI2cId.ucAccess == id) {
155 i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
158 gpio = (ATOM_GPIO_I2C_ASSIGMENT *)
159 ((u8 *)gpio + sizeof(ATOM_GPIO_I2C_ASSIGMENT));
166 void radeon_atombios_i2c_init(struct radeon_device *rdev)
168 struct atom_context *ctx = rdev->mode_info.atom_context;
169 ATOM_GPIO_I2C_ASSIGMENT *gpio;
170 struct radeon_i2c_bus_rec i2c;
171 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
172 struct _ATOM_GPIO_I2C_INFO *i2c_info;
173 uint16_t data_offset, size;
177 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
178 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
180 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
181 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
183 gpio = &i2c_info->asGPIO_Info[0];
184 for (i = 0; i < num_indices; i++) {
185 radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
187 i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
190 sprintf(stmp, "0x%x", i2c.i2c_id);
191 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
193 gpio = (ATOM_GPIO_I2C_ASSIGMENT *)
194 ((u8 *)gpio + sizeof(ATOM_GPIO_I2C_ASSIGMENT));
199 static struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
202 struct atom_context *ctx = rdev->mode_info.atom_context;
203 struct radeon_gpio_rec gpio;
204 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
205 struct _ATOM_GPIO_PIN_LUT *gpio_info;
206 ATOM_GPIO_PIN_ASSIGNMENT *pin;
207 u16 data_offset, size;
210 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
213 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
214 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
216 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
217 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
219 pin = gpio_info->asGPIO_Pin;
220 for (i = 0; i < num_indices; i++) {
221 if (id == pin->ucGPIO_ID) {
222 gpio.id = pin->ucGPIO_ID;
223 gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex) * 4;
224 gpio.mask = (1 << pin->ucGpioPinBitShift);
228 pin = (ATOM_GPIO_PIN_ASSIGNMENT *)
229 ((u8 *)pin + sizeof(ATOM_GPIO_PIN_ASSIGNMENT));
236 static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
237 struct radeon_gpio_rec *gpio)
239 struct radeon_hpd hpd;
242 memset(&hpd, 0, sizeof(struct radeon_hpd));
244 if (ASIC_IS_DCE6(rdev))
245 reg = SI_DC_GPIO_HPD_A;
246 else if (ASIC_IS_DCE4(rdev))
247 reg = EVERGREEN_DC_GPIO_HPD_A;
249 reg = AVIVO_DC_GPIO_HPD_A;
252 if (gpio->reg == reg) {
255 hpd.hpd = RADEON_HPD_1;
258 hpd.hpd = RADEON_HPD_2;
261 hpd.hpd = RADEON_HPD_3;
264 hpd.hpd = RADEON_HPD_4;
267 hpd.hpd = RADEON_HPD_5;
270 hpd.hpd = RADEON_HPD_6;
273 hpd.hpd = RADEON_HPD_NONE;
277 hpd.hpd = RADEON_HPD_NONE;
281 static bool radeon_atom_apply_quirks(struct drm_device *dev,
282 uint32_t supported_device,
284 struct radeon_i2c_bus_rec *i2c_bus,
286 struct radeon_hpd *hpd)
289 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
290 if ((dev->pdev->device == 0x791e) &&
291 (dev->pdev->subsystem_vendor == 0x1043) &&
292 (dev->pdev->subsystem_device == 0x826d)) {
293 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
294 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
295 *connector_type = DRM_MODE_CONNECTOR_DVID;
298 /* Asrock RS600 board lists the DVI port as HDMI */
299 if ((dev->pdev->device == 0x7941) &&
300 (dev->pdev->subsystem_vendor == 0x1849) &&
301 (dev->pdev->subsystem_device == 0x7941)) {
302 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
303 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
304 *connector_type = DRM_MODE_CONNECTOR_DVID;
307 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
308 if ((dev->pdev->device == 0x796e) &&
309 (dev->pdev->subsystem_vendor == 0x1462) &&
310 (dev->pdev->subsystem_device == 0x7302)) {
311 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
312 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
316 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
317 if ((dev->pdev->device == 0x7941) &&
318 (dev->pdev->subsystem_vendor == 0x147b) &&
319 (dev->pdev->subsystem_device == 0x2412)) {
320 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
324 /* Falcon NW laptop lists vga ddc line for LVDS */
325 if ((dev->pdev->device == 0x5653) &&
326 (dev->pdev->subsystem_vendor == 0x1462) &&
327 (dev->pdev->subsystem_device == 0x0291)) {
328 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
329 i2c_bus->valid = false;
334 /* HIS X1300 is DVI+VGA, not DVI+DVI */
335 if ((dev->pdev->device == 0x7146) &&
336 (dev->pdev->subsystem_vendor == 0x17af) &&
337 (dev->pdev->subsystem_device == 0x2058)) {
338 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
342 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
343 if ((dev->pdev->device == 0x7142) &&
344 (dev->pdev->subsystem_vendor == 0x1458) &&
345 (dev->pdev->subsystem_device == 0x2134)) {
346 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
352 if ((dev->pdev->device == 0x71C5) &&
353 (dev->pdev->subsystem_vendor == 0x106b) &&
354 (dev->pdev->subsystem_device == 0x0080)) {
355 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
356 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
358 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
362 /* mac rv630, rv730, others */
363 if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
364 (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
365 *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
366 *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
369 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
370 if ((dev->pdev->device == 0x9598) &&
371 (dev->pdev->subsystem_vendor == 0x1043) &&
372 (dev->pdev->subsystem_device == 0x01da)) {
373 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
374 *connector_type = DRM_MODE_CONNECTOR_DVII;
378 /* ASUS HD 3600 board lists the DVI port as HDMI */
379 if ((dev->pdev->device == 0x9598) &&
380 (dev->pdev->subsystem_vendor == 0x1043) &&
381 (dev->pdev->subsystem_device == 0x01e4)) {
382 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
383 *connector_type = DRM_MODE_CONNECTOR_DVII;
387 /* ASUS HD 3450 board lists the DVI port as HDMI */
388 if ((dev->pdev->device == 0x95C5) &&
389 (dev->pdev->subsystem_vendor == 0x1043) &&
390 (dev->pdev->subsystem_device == 0x01e2)) {
391 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
392 *connector_type = DRM_MODE_CONNECTOR_DVII;
396 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
397 * HDMI + VGA reporting as HDMI
399 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
400 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
401 *connector_type = DRM_MODE_CONNECTOR_VGA;
406 /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port
407 * on the laptop and a DVI port on the docking station and
408 * both share the same encoder, hpd pin, and ddc line.
409 * So while the bios table is technically correct,
410 * we drop the DVI port here since xrandr has no concept of
411 * encoders and will try and drive both connectors
412 * with different crtcs which isn't possible on the hardware
413 * side and leaves no crtcs for LVDS or VGA.
415 if (((dev->pdev->device == 0x95c4) || (dev->pdev->device == 0x9591)) &&
416 (dev->pdev->subsystem_vendor == 0x1025) &&
417 (dev->pdev->subsystem_device == 0x013c)) {
418 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
419 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
420 /* actually it's a DVI-D port not DVI-I */
421 *connector_type = DRM_MODE_CONNECTOR_DVID;
426 /* XFX Pine Group device rv730 reports no VGA DDC lines
427 * even though they are wired up to record 0x93
429 if ((dev->pdev->device == 0x9498) &&
430 (dev->pdev->subsystem_vendor == 0x1682) &&
431 (dev->pdev->subsystem_device == 0x2452) &&
432 (i2c_bus->valid == false) &&
433 !(supported_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))) {
434 struct radeon_device *rdev = dev->dev_private;
435 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
438 /* Fujitsu D3003-S2 board lists DVI-I as DVI-D and VGA */
439 if (((dev->pdev->device == 0x9802) || (dev->pdev->device == 0x9806)) &&
440 (dev->pdev->subsystem_vendor == 0x1734) &&
441 (dev->pdev->subsystem_device == 0x11bd)) {
442 if (*connector_type == DRM_MODE_CONNECTOR_VGA) {
443 *connector_type = DRM_MODE_CONNECTOR_DVII;
445 } else if (*connector_type == DRM_MODE_CONNECTOR_DVID) {
446 *connector_type = DRM_MODE_CONNECTOR_DVII;
450 /* Fujitsu D3003-S2 board lists DVI-I as DVI-I and VGA */
451 if ((dev->pdev->device == 0x9805) &&
452 (dev->pdev->subsystem_vendor == 0x1734) &&
453 (dev->pdev->subsystem_device == 0x11bd)) {
454 if (*connector_type == DRM_MODE_CONNECTOR_VGA)
461 const int supported_devices_connector_convert[] = {
462 DRM_MODE_CONNECTOR_Unknown,
463 DRM_MODE_CONNECTOR_VGA,
464 DRM_MODE_CONNECTOR_DVII,
465 DRM_MODE_CONNECTOR_DVID,
466 DRM_MODE_CONNECTOR_DVIA,
467 DRM_MODE_CONNECTOR_SVIDEO,
468 DRM_MODE_CONNECTOR_Composite,
469 DRM_MODE_CONNECTOR_LVDS,
470 DRM_MODE_CONNECTOR_Unknown,
471 DRM_MODE_CONNECTOR_Unknown,
472 DRM_MODE_CONNECTOR_HDMIA,
473 DRM_MODE_CONNECTOR_HDMIB,
474 DRM_MODE_CONNECTOR_Unknown,
475 DRM_MODE_CONNECTOR_Unknown,
476 DRM_MODE_CONNECTOR_9PinDIN,
477 DRM_MODE_CONNECTOR_DisplayPort
480 const uint16_t supported_devices_connector_object_id_convert[] = {
481 CONNECTOR_OBJECT_ID_NONE,
482 CONNECTOR_OBJECT_ID_VGA,
483 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
484 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
485 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
486 CONNECTOR_OBJECT_ID_COMPOSITE,
487 CONNECTOR_OBJECT_ID_SVIDEO,
488 CONNECTOR_OBJECT_ID_LVDS,
489 CONNECTOR_OBJECT_ID_9PIN_DIN,
490 CONNECTOR_OBJECT_ID_9PIN_DIN,
491 CONNECTOR_OBJECT_ID_DISPLAYPORT,
492 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
493 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
494 CONNECTOR_OBJECT_ID_SVIDEO
497 const int object_connector_convert[] = {
498 DRM_MODE_CONNECTOR_Unknown,
499 DRM_MODE_CONNECTOR_DVII,
500 DRM_MODE_CONNECTOR_DVII,
501 DRM_MODE_CONNECTOR_DVID,
502 DRM_MODE_CONNECTOR_DVID,
503 DRM_MODE_CONNECTOR_VGA,
504 DRM_MODE_CONNECTOR_Composite,
505 DRM_MODE_CONNECTOR_SVIDEO,
506 DRM_MODE_CONNECTOR_Unknown,
507 DRM_MODE_CONNECTOR_Unknown,
508 DRM_MODE_CONNECTOR_9PinDIN,
509 DRM_MODE_CONNECTOR_Unknown,
510 DRM_MODE_CONNECTOR_HDMIA,
511 DRM_MODE_CONNECTOR_HDMIB,
512 DRM_MODE_CONNECTOR_LVDS,
513 DRM_MODE_CONNECTOR_9PinDIN,
514 DRM_MODE_CONNECTOR_Unknown,
515 DRM_MODE_CONNECTOR_Unknown,
516 DRM_MODE_CONNECTOR_Unknown,
517 DRM_MODE_CONNECTOR_DisplayPort,
518 DRM_MODE_CONNECTOR_eDP,
519 DRM_MODE_CONNECTOR_Unknown
522 bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
524 struct radeon_device *rdev = dev->dev_private;
525 struct radeon_mode_info *mode_info = &rdev->mode_info;
526 struct atom_context *ctx = mode_info->atom_context;
527 int index = GetIndexIntoMasterTable(DATA, Object_Header);
528 u16 size, data_offset;
530 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
531 ATOM_ENCODER_OBJECT_TABLE *enc_obj;
532 ATOM_OBJECT_TABLE *router_obj;
533 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
534 ATOM_OBJECT_HEADER *obj_header;
535 int i, j, k, path_size, device_support;
537 u16 igp_lane_info, conn_id, connector_object_id;
538 struct radeon_i2c_bus_rec ddc_bus;
539 struct radeon_router router;
540 struct radeon_gpio_rec gpio;
541 struct radeon_hpd hpd;
543 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
549 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
550 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
551 (ctx->bios + data_offset +
552 le16_to_cpu(obj_header->usDisplayPathTableOffset));
553 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
554 (ctx->bios + data_offset +
555 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
556 enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
557 (ctx->bios + data_offset +
558 le16_to_cpu(obj_header->usEncoderObjectTableOffset));
559 router_obj = (ATOM_OBJECT_TABLE *)
560 (ctx->bios + data_offset +
561 le16_to_cpu(obj_header->usRouterObjectTableOffset));
562 device_support = le16_to_cpu(obj_header->usDeviceSupport);
565 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
566 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
567 ATOM_DISPLAY_OBJECT_PATH *path;
569 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
570 path_size += le16_to_cpu(path->usSize);
572 if (device_support & le16_to_cpu(path->usDeviceTag)) {
573 uint8_t con_obj_id, con_obj_num, con_obj_type;
576 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
579 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
582 (le16_to_cpu(path->usConnObjectId) &
583 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
585 /* TODO CV support */
586 if (le16_to_cpu(path->usDeviceTag) ==
587 ATOM_DEVICE_CV_SUPPORT)
591 if ((rdev->flags & RADEON_IS_IGP) &&
593 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
594 uint16_t igp_offset = 0;
595 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
598 GetIndexIntoMasterTable(DATA,
599 IntegratedSystemInfo);
601 if (atom_parse_data_header(ctx, index, &size, &frev,
602 &crev, &igp_offset)) {
606 (ATOM_INTEGRATED_SYSTEM_INFO_V2
607 *) (ctx->bios + igp_offset);
610 uint32_t slot_config, ct;
612 if (con_obj_num == 1)
621 ct = (slot_config >> 16) & 0xff;
623 object_connector_convert
625 connector_object_id = ct;
627 slot_config & 0xffff;
635 object_connector_convert[con_obj_id];
636 connector_object_id = con_obj_id;
641 object_connector_convert[con_obj_id];
642 connector_object_id = con_obj_id;
645 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
648 router.ddc_valid = false;
649 router.cd_valid = false;
650 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
651 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
654 (le16_to_cpu(path->usGraphicObjIds[j]) &
655 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
657 (le16_to_cpu(path->usGraphicObjIds[j]) &
658 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
660 (le16_to_cpu(path->usGraphicObjIds[j]) &
661 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
663 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
664 for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
665 u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
666 if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
667 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
668 (ctx->bios + data_offset +
669 le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
670 ATOM_ENCODER_CAP_RECORD *cap_record;
673 while (record->ucRecordSize > 0 &&
674 record->ucRecordType > 0 &&
675 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
676 switch (record->ucRecordType) {
677 case ATOM_ENCODER_CAP_RECORD_TYPE:
678 cap_record =(ATOM_ENCODER_CAP_RECORD *)
680 caps = le16_to_cpu(cap_record->usEncoderCap);
683 record = (ATOM_COMMON_RECORD_HEADER *)
684 ((char *)record + record->ucRecordSize);
686 radeon_add_atom_encoder(dev,
694 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
695 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
696 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
697 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
698 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
699 (ctx->bios + data_offset +
700 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
701 ATOM_I2C_RECORD *i2c_record;
702 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
703 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
704 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
705 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
706 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
707 (ctx->bios + data_offset +
708 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
709 u8 *num_dst_objs = (u8 *)
710 ((u8 *)router_src_dst_table + 1 +
711 (router_src_dst_table->ucNumberOfSrc * 2));
712 u16 *dst_objs = (u16 *)(num_dst_objs + 1);
715 router.router_id = router_obj_id;
716 for (enum_id = 0; enum_id < (*num_dst_objs); enum_id++) {
717 if (le16_to_cpu(path->usConnObjectId) ==
718 le16_to_cpu(dst_objs[enum_id]))
722 while (record->ucRecordSize > 0 &&
723 record->ucRecordType > 0 &&
724 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
725 switch (record->ucRecordType) {
726 case ATOM_I2C_RECORD_TYPE:
731 (ATOM_I2C_ID_CONFIG_ACCESS *)
732 &i2c_record->sucI2cId;
734 radeon_lookup_i2c_gpio(rdev,
737 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
739 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
740 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
742 router.ddc_valid = true;
743 router.ddc_mux_type = ddc_path->ucMuxType;
744 router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
745 router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
747 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
748 cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
750 router.cd_valid = true;
751 router.cd_mux_type = cd_path->ucMuxType;
752 router.cd_mux_control_pin = cd_path->ucMuxControlPin;
753 router.cd_mux_state = cd_path->ucMuxState[enum_id];
756 record = (ATOM_COMMON_RECORD_HEADER *)
757 ((char *)record + record->ucRecordSize);
764 /* look up gpio for ddc, hpd */
765 ddc_bus.valid = false;
766 hpd.hpd = RADEON_HPD_NONE;
767 if ((le16_to_cpu(path->usDeviceTag) &
768 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
769 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
770 if (le16_to_cpu(path->usConnObjectId) ==
771 le16_to_cpu(con_obj->asObjects[j].
773 ATOM_COMMON_RECORD_HEADER
775 (ATOM_COMMON_RECORD_HEADER
777 (ctx->bios + data_offset +
778 le16_to_cpu(con_obj->
781 ATOM_I2C_RECORD *i2c_record;
782 ATOM_HPD_INT_RECORD *hpd_record;
783 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
785 while (record->ucRecordSize > 0 &&
786 record->ucRecordType > 0 &&
787 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
788 switch (record->ucRecordType) {
789 case ATOM_I2C_RECORD_TYPE:
794 (ATOM_I2C_ID_CONFIG_ACCESS *)
795 &i2c_record->sucI2cId;
796 ddc_bus = radeon_lookup_i2c_gpio(rdev,
800 case ATOM_HPD_INT_RECORD_TYPE:
802 (ATOM_HPD_INT_RECORD *)
804 gpio = radeon_lookup_gpio(rdev,
805 hpd_record->ucHPDIntGPIOID);
806 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
807 hpd.plugged_state = hpd_record->ucPlugged_PinState;
811 (ATOM_COMMON_RECORD_HEADER
822 /* needed for aux chan transactions */
823 ddc_bus.hpd = hpd.hpd;
825 conn_id = le16_to_cpu(path->usConnObjectId);
827 if (!radeon_atom_apply_quirks
828 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
829 &ddc_bus, &conn_id, &hpd))
832 radeon_add_atom_connector(dev,
836 connector_type, &ddc_bus,
845 radeon_link_encoder_connector(dev);
850 static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
854 struct radeon_device *rdev = dev->dev_private;
856 if (rdev->flags & RADEON_IS_IGP) {
857 return supported_devices_connector_object_id_convert
859 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
860 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
861 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
862 struct radeon_mode_info *mode_info = &rdev->mode_info;
863 struct atom_context *ctx = mode_info->atom_context;
864 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
865 uint16_t size, data_offset;
867 ATOM_XTMDS_INFO *xtmds;
869 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
870 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
872 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
873 if (connector_type == DRM_MODE_CONNECTOR_DVII)
874 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
876 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
878 if (connector_type == DRM_MODE_CONNECTOR_DVII)
879 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
881 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
884 return supported_devices_connector_object_id_convert
887 return supported_devices_connector_object_id_convert
892 struct bios_connector {
897 struct radeon_i2c_bus_rec ddc_bus;
898 struct radeon_hpd hpd;
901 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
905 struct radeon_device *rdev = dev->dev_private;
906 struct radeon_mode_info *mode_info = &rdev->mode_info;
907 struct atom_context *ctx = mode_info->atom_context;
908 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
909 uint16_t size, data_offset;
911 uint16_t device_support;
913 union atom_supported_devices *supported_devices;
914 int i, j, max_device;
915 struct bios_connector *bios_connectors;
916 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
917 struct radeon_router router;
919 router.ddc_valid = false;
920 router.cd_valid = false;
922 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
923 if (!bios_connectors)
926 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
928 kfree(bios_connectors);
933 (union atom_supported_devices *)(ctx->bios + data_offset);
935 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
938 max_device = ATOM_MAX_SUPPORTED_DEVICE;
940 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
942 for (i = 0; i < max_device; i++) {
943 ATOM_CONNECTOR_INFO_I2C ci =
944 supported_devices->info.asConnInfo[i];
946 bios_connectors[i].valid = false;
948 if (!(device_support & (1 << i))) {
952 if (i == ATOM_DEVICE_CV_INDEX) {
953 DRM_DEBUG_KMS("Skipping Component Video\n");
957 bios_connectors[i].connector_type =
958 supported_devices_connector_convert[ci.sucConnectorInfo.
962 if (bios_connectors[i].connector_type ==
963 DRM_MODE_CONNECTOR_Unknown)
966 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
968 bios_connectors[i].line_mux =
969 ci.sucI2cId.ucAccess;
971 /* give tv unique connector ids */
972 if (i == ATOM_DEVICE_TV1_INDEX) {
973 bios_connectors[i].ddc_bus.valid = false;
974 bios_connectors[i].line_mux = 50;
975 } else if (i == ATOM_DEVICE_TV2_INDEX) {
976 bios_connectors[i].ddc_bus.valid = false;
977 bios_connectors[i].line_mux = 51;
978 } else if (i == ATOM_DEVICE_CV_INDEX) {
979 bios_connectors[i].ddc_bus.valid = false;
980 bios_connectors[i].line_mux = 52;
982 bios_connectors[i].ddc_bus =
983 radeon_lookup_i2c_gpio(rdev,
984 bios_connectors[i].line_mux);
986 if ((crev > 1) && (frev > 1)) {
987 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
990 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
993 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
996 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
1000 if (i == ATOM_DEVICE_DFP1_INDEX)
1001 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
1002 else if (i == ATOM_DEVICE_DFP2_INDEX)
1003 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
1005 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
1008 /* Always set the connector type to VGA for CRT1/CRT2. if they are
1009 * shared with a DVI port, we'll pick up the DVI connector when we
1010 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
1012 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
1013 bios_connectors[i].connector_type =
1014 DRM_MODE_CONNECTOR_VGA;
1016 if (!radeon_atom_apply_quirks
1017 (dev, (1 << i), &bios_connectors[i].connector_type,
1018 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
1019 &bios_connectors[i].hpd))
1022 bios_connectors[i].valid = true;
1023 bios_connectors[i].devices = (1 << i);
1025 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
1026 radeon_add_atom_encoder(dev,
1027 radeon_get_encoder_enum(dev,
1033 radeon_add_legacy_encoder(dev,
1034 radeon_get_encoder_enum(dev,
1040 /* combine shared connectors */
1041 for (i = 0; i < max_device; i++) {
1042 if (bios_connectors[i].valid) {
1043 for (j = 0; j < max_device; j++) {
1044 if (bios_connectors[j].valid && (i != j)) {
1045 if (bios_connectors[i].line_mux ==
1046 bios_connectors[j].line_mux) {
1047 /* make sure not to combine LVDS */
1048 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1049 bios_connectors[i].line_mux = 53;
1050 bios_connectors[i].ddc_bus.valid = false;
1053 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1054 bios_connectors[j].line_mux = 53;
1055 bios_connectors[j].ddc_bus.valid = false;
1058 /* combine analog and digital for DVI-I */
1059 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1060 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
1061 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1062 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
1063 bios_connectors[i].devices |=
1064 bios_connectors[j].devices;
1065 bios_connectors[i].connector_type =
1066 DRM_MODE_CONNECTOR_DVII;
1067 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
1068 bios_connectors[i].hpd =
1069 bios_connectors[j].hpd;
1070 bios_connectors[j].valid = false;
1078 /* add the connectors */
1079 for (i = 0; i < max_device; i++) {
1080 if (bios_connectors[i].valid) {
1081 uint16_t connector_object_id =
1082 atombios_get_connector_object_id(dev,
1083 bios_connectors[i].connector_type,
1084 bios_connectors[i].devices);
1085 radeon_add_atom_connector(dev,
1086 bios_connectors[i].line_mux,
1087 bios_connectors[i].devices,
1090 &bios_connectors[i].ddc_bus,
1092 connector_object_id,
1093 &bios_connectors[i].hpd,
1098 radeon_link_encoder_connector(dev);
1100 kfree(bios_connectors);
1104 union firmware_info {
1105 ATOM_FIRMWARE_INFO info;
1106 ATOM_FIRMWARE_INFO_V1_2 info_12;
1107 ATOM_FIRMWARE_INFO_V1_3 info_13;
1108 ATOM_FIRMWARE_INFO_V1_4 info_14;
1109 ATOM_FIRMWARE_INFO_V2_1 info_21;
1110 ATOM_FIRMWARE_INFO_V2_2 info_22;
1113 bool radeon_atom_get_clock_info(struct drm_device *dev)
1115 struct radeon_device *rdev = dev->dev_private;
1116 struct radeon_mode_info *mode_info = &rdev->mode_info;
1117 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1118 union firmware_info *firmware_info;
1120 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1121 struct radeon_pll *p2pll = &rdev->clock.p2pll;
1122 struct radeon_pll *dcpll = &rdev->clock.dcpll;
1123 struct radeon_pll *spll = &rdev->clock.spll;
1124 struct radeon_pll *mpll = &rdev->clock.mpll;
1125 uint16_t data_offset;
1127 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1128 &frev, &crev, &data_offset)) {
1130 (union firmware_info *)(mode_info->atom_context->bios +
1133 p1pll->reference_freq =
1134 le16_to_cpu(firmware_info->info.usReferenceClock);
1135 p1pll->reference_div = 0;
1138 p1pll->pll_out_min =
1139 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1141 p1pll->pll_out_min =
1142 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
1143 p1pll->pll_out_max =
1144 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1147 p1pll->lcd_pll_out_min =
1148 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1149 if (p1pll->lcd_pll_out_min == 0)
1150 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1151 p1pll->lcd_pll_out_max =
1152 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1153 if (p1pll->lcd_pll_out_max == 0)
1154 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1156 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1157 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1160 if (p1pll->pll_out_min == 0) {
1161 if (ASIC_IS_AVIVO(rdev))
1162 p1pll->pll_out_min = 64800;
1164 p1pll->pll_out_min = 20000;
1168 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1170 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1175 if (ASIC_IS_DCE4(rdev))
1176 spll->reference_freq =
1177 le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
1179 spll->reference_freq =
1180 le16_to_cpu(firmware_info->info.usReferenceClock);
1181 spll->reference_div = 0;
1184 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1186 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1189 if (spll->pll_out_min == 0) {
1190 if (ASIC_IS_AVIVO(rdev))
1191 spll->pll_out_min = 64800;
1193 spll->pll_out_min = 20000;
1197 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1199 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1202 if (ASIC_IS_DCE4(rdev))
1203 mpll->reference_freq =
1204 le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
1206 mpll->reference_freq =
1207 le16_to_cpu(firmware_info->info.usReferenceClock);
1208 mpll->reference_div = 0;
1211 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1213 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1216 if (mpll->pll_out_min == 0) {
1217 if (ASIC_IS_AVIVO(rdev))
1218 mpll->pll_out_min = 64800;
1220 mpll->pll_out_min = 20000;
1224 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1226 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1228 rdev->clock.default_sclk =
1229 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1230 rdev->clock.default_mclk =
1231 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1233 if (ASIC_IS_DCE4(rdev)) {
1234 rdev->clock.default_dispclk =
1235 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
1236 if (rdev->clock.default_dispclk == 0) {
1237 if (ASIC_IS_DCE6(rdev))
1238 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1239 else if (ASIC_IS_DCE5(rdev))
1240 rdev->clock.default_dispclk = 54000; /* 540 Mhz */
1242 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1244 /* set a reasonable default for DP */
1245 if (ASIC_IS_DCE6(rdev) && (rdev->clock.default_dispclk < 53900)) {
1246 DRM_INFO("Changing default dispclk from %dMhz to 600Mhz\n",
1247 rdev->clock.default_dispclk / 100);
1248 rdev->clock.default_dispclk = 60000;
1250 rdev->clock.dp_extclk =
1251 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
1252 rdev->clock.current_dispclk = rdev->clock.default_dispclk;
1256 rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
1257 if (rdev->clock.max_pixel_clock == 0)
1258 rdev->clock.max_pixel_clock = 40000;
1260 /* not technically a clock, but... */
1261 rdev->mode_info.firmware_flags =
1262 le16_to_cpu(firmware_info->info.usFirmwareCapability.susAccess);
1271 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1272 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1273 struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
1274 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
1275 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8;
1278 bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1280 struct radeon_mode_info *mode_info = &rdev->mode_info;
1281 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1282 union igp_info *igp_info;
1286 /* sideport is AMD only */
1287 if (rdev->family == CHIP_RS600)
1290 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1291 &frev, &crev, &data_offset)) {
1292 igp_info = (union igp_info *)(mode_info->atom_context->bios +
1296 if (le32_to_cpu(igp_info->info.ulBootUpMemoryClock))
1300 if (le32_to_cpu(igp_info->info_2.ulBootUpSidePortClock))
1304 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1311 bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1312 struct radeon_encoder_int_tmds *tmds)
1314 struct drm_device *dev = encoder->base.dev;
1315 struct radeon_device *rdev = dev->dev_private;
1316 struct radeon_mode_info *mode_info = &rdev->mode_info;
1317 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1318 uint16_t data_offset;
1319 struct _ATOM_TMDS_INFO *tmds_info;
1324 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1325 &frev, &crev, &data_offset)) {
1327 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1330 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1331 for (i = 0; i < 4; i++) {
1332 tmds->tmds_pll[i].freq =
1333 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1334 tmds->tmds_pll[i].value =
1335 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1336 tmds->tmds_pll[i].value |=
1337 (tmds_info->asMiscInfo[i].
1338 ucPLL_VCO_Gain & 0x3f) << 6;
1339 tmds->tmds_pll[i].value |=
1340 (tmds_info->asMiscInfo[i].
1341 ucPLL_DutyCycle & 0xf) << 12;
1342 tmds->tmds_pll[i].value |=
1343 (tmds_info->asMiscInfo[i].
1344 ucPLL_VoltageSwing & 0xf) << 16;
1346 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
1347 tmds->tmds_pll[i].freq,
1348 tmds->tmds_pll[i].value);
1350 if (maxfreq == tmds->tmds_pll[i].freq) {
1351 tmds->tmds_pll[i].freq = 0xffffffff;
1360 bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
1361 struct radeon_atom_ss *ss,
1364 struct radeon_mode_info *mode_info = &rdev->mode_info;
1365 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
1366 uint16_t data_offset, size;
1367 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1368 struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT *ss_assign;
1372 memset(ss, 0, sizeof(struct radeon_atom_ss));
1373 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1374 &frev, &crev, &data_offset)) {
1376 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
1378 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1379 sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
1380 ss_assign = (struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT*)
1381 ((u8 *)&ss_info->asSS_Info[0]);
1382 for (i = 0; i < num_indices; i++) {
1383 if (ss_assign->ucSS_Id == id) {
1385 le16_to_cpu(ss_assign->usSpreadSpectrumPercentage);
1386 ss->type = ss_assign->ucSpreadSpectrumType;
1387 ss->step = ss_assign->ucSS_Step;
1388 ss->delay = ss_assign->ucSS_Delay;
1389 ss->range = ss_assign->ucSS_Range;
1390 ss->refdiv = ss_assign->ucRecommendedRef_Div;
1393 ss_assign = (struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT*)
1394 ((u8 *)ss_assign + sizeof(struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT));
1400 static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
1401 struct radeon_atom_ss *ss,
1404 struct radeon_mode_info *mode_info = &rdev->mode_info;
1405 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1406 u16 data_offset, size;
1407 union igp_info *igp_info;
1409 u16 percentage = 0, rate = 0;
1411 /* get any igp specific overrides */
1412 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1413 &frev, &crev, &data_offset)) {
1414 igp_info = (union igp_info *)
1415 (mode_info->atom_context->bios + data_offset);
1419 case ASIC_INTERNAL_SS_ON_TMDS:
1420 percentage = le16_to_cpu(igp_info->info_6.usDVISSPercentage);
1421 rate = le16_to_cpu(igp_info->info_6.usDVISSpreadRateIn10Hz);
1423 case ASIC_INTERNAL_SS_ON_HDMI:
1424 percentage = le16_to_cpu(igp_info->info_6.usHDMISSPercentage);
1425 rate = le16_to_cpu(igp_info->info_6.usHDMISSpreadRateIn10Hz);
1427 case ASIC_INTERNAL_SS_ON_LVDS:
1428 percentage = le16_to_cpu(igp_info->info_6.usLvdsSSPercentage);
1429 rate = le16_to_cpu(igp_info->info_6.usLvdsSSpreadRateIn10Hz);
1435 case ASIC_INTERNAL_SS_ON_TMDS:
1436 percentage = le16_to_cpu(igp_info->info_7.usDVISSPercentage);
1437 rate = le16_to_cpu(igp_info->info_7.usDVISSpreadRateIn10Hz);
1439 case ASIC_INTERNAL_SS_ON_HDMI:
1440 percentage = le16_to_cpu(igp_info->info_7.usHDMISSPercentage);
1441 rate = le16_to_cpu(igp_info->info_7.usHDMISSpreadRateIn10Hz);
1443 case ASIC_INTERNAL_SS_ON_LVDS:
1444 percentage = le16_to_cpu(igp_info->info_7.usLvdsSSPercentage);
1445 rate = le16_to_cpu(igp_info->info_7.usLvdsSSpreadRateIn10Hz);
1451 case ASIC_INTERNAL_SS_ON_TMDS:
1452 percentage = le16_to_cpu(igp_info->info_8.usDVISSPercentage);
1453 rate = le16_to_cpu(igp_info->info_8.usDVISSpreadRateIn10Hz);
1455 case ASIC_INTERNAL_SS_ON_HDMI:
1456 percentage = le16_to_cpu(igp_info->info_8.usHDMISSPercentage);
1457 rate = le16_to_cpu(igp_info->info_8.usHDMISSpreadRateIn10Hz);
1459 case ASIC_INTERNAL_SS_ON_LVDS:
1460 percentage = le16_to_cpu(igp_info->info_8.usLvdsSSPercentage);
1461 rate = le16_to_cpu(igp_info->info_8.usLvdsSSpreadRateIn10Hz);
1466 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1470 ss->percentage = percentage;
1476 union asic_ss_info {
1477 struct _ATOM_ASIC_INTERNAL_SS_INFO info;
1478 struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
1479 struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
1482 union asic_ss_assignment {
1483 struct _ATOM_ASIC_SS_ASSIGNMENT v1;
1484 struct _ATOM_ASIC_SS_ASSIGNMENT_V2 v2;
1485 struct _ATOM_ASIC_SS_ASSIGNMENT_V3 v3;
1488 bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
1489 struct radeon_atom_ss *ss,
1492 struct radeon_mode_info *mode_info = &rdev->mode_info;
1493 int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
1494 uint16_t data_offset, size;
1495 union asic_ss_info *ss_info;
1496 union asic_ss_assignment *ss_assign;
1500 if (id == ASIC_INTERNAL_MEMORY_SS) {
1501 if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_MEMORY_CLOCK_SS_SUPPORT))
1504 if (id == ASIC_INTERNAL_ENGINE_SS) {
1505 if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_ENGINE_CLOCK_SS_SUPPORT))
1509 memset(ss, 0, sizeof(struct radeon_atom_ss));
1510 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1511 &frev, &crev, &data_offset)) {
1514 (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
1518 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1519 sizeof(ATOM_ASIC_SS_ASSIGNMENT);
1521 ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info.asSpreadSpectrum[0]);
1522 for (i = 0; i < num_indices; i++) {
1523 if ((ss_assign->v1.ucClockIndication == id) &&
1524 (clock <= le32_to_cpu(ss_assign->v1.ulTargetClockRange))) {
1526 le16_to_cpu(ss_assign->v1.usSpreadSpectrumPercentage);
1527 ss->type = ss_assign->v1.ucSpreadSpectrumMode;
1528 ss->rate = le16_to_cpu(ss_assign->v1.usSpreadRateInKhz);
1529 ss->percentage_divider = 100;
1532 ss_assign = (union asic_ss_assignment *)
1533 ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT));
1537 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1538 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
1539 ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info_2.asSpreadSpectrum[0]);
1540 for (i = 0; i < num_indices; i++) {
1541 if ((ss_assign->v2.ucClockIndication == id) &&
1542 (clock <= le32_to_cpu(ss_assign->v2.ulTargetClockRange))) {
1544 le16_to_cpu(ss_assign->v2.usSpreadSpectrumPercentage);
1545 ss->type = ss_assign->v2.ucSpreadSpectrumMode;
1546 ss->rate = le16_to_cpu(ss_assign->v2.usSpreadRateIn10Hz);
1547 ss->percentage_divider = 100;
1549 ((id == ASIC_INTERNAL_ENGINE_SS) ||
1550 (id == ASIC_INTERNAL_MEMORY_SS)))
1554 ss_assign = (union asic_ss_assignment *)
1555 ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2));
1559 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1560 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
1561 ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info_3.asSpreadSpectrum[0]);
1562 for (i = 0; i < num_indices; i++) {
1563 if ((ss_assign->v3.ucClockIndication == id) &&
1564 (clock <= le32_to_cpu(ss_assign->v3.ulTargetClockRange))) {
1566 le16_to_cpu(ss_assign->v3.usSpreadSpectrumPercentage);
1567 ss->type = ss_assign->v3.ucSpreadSpectrumMode;
1568 ss->rate = le16_to_cpu(ss_assign->v3.usSpreadRateIn10Hz);
1569 if (ss_assign->v3.ucSpreadSpectrumMode &
1570 SS_MODE_V3_PERCENTAGE_DIV_BY_1000_MASK)
1571 ss->percentage_divider = 1000;
1573 ss->percentage_divider = 100;
1574 if ((id == ASIC_INTERNAL_ENGINE_SS) ||
1575 (id == ASIC_INTERNAL_MEMORY_SS))
1577 if (rdev->flags & RADEON_IS_IGP)
1578 radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
1581 ss_assign = (union asic_ss_assignment *)
1582 ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3));
1586 DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
1595 struct _ATOM_LVDS_INFO info;
1596 struct _ATOM_LVDS_INFO_V12 info_12;
1599 struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1603 struct drm_device *dev = encoder->base.dev;
1604 struct radeon_device *rdev = dev->dev_private;
1605 struct radeon_mode_info *mode_info = &rdev->mode_info;
1606 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
1607 uint16_t data_offset, misc;
1608 union lvds_info *lvds_info;
1610 struct radeon_encoder_atom_dig *lvds = NULL;
1611 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
1613 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1614 &frev, &crev, &data_offset)) {
1616 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
1618 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1623 lvds->native_mode.clock =
1624 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
1625 lvds->native_mode.hdisplay =
1626 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
1627 lvds->native_mode.vdisplay =
1628 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
1629 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1630 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1631 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1632 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1633 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1634 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1635 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1636 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1637 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1638 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
1639 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1640 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
1641 lvds->panel_pwr_delay =
1642 le16_to_cpu(lvds_info->info.usOffDelayInMs);
1643 lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
1645 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1646 if (misc & ATOM_VSYNC_POLARITY)
1647 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1648 if (misc & ATOM_HSYNC_POLARITY)
1649 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1650 if (misc & ATOM_COMPOSITESYNC)
1651 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1652 if (misc & ATOM_INTERLACE)
1653 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1654 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1655 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1657 lvds->native_mode.width_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageHSize);
1658 lvds->native_mode.height_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageVSize);
1660 /* set crtc values */
1661 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
1663 lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
1665 encoder->native_mode = lvds->native_mode;
1667 if (encoder_enum == 2)
1670 lvds->linkb = false;
1672 /* parse the lcd record table */
1673 if (le16_to_cpu(lvds_info->info.usModePatchTableOffset)) {
1674 ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
1675 ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
1676 bool bad_record = false;
1679 if ((frev == 1) && (crev < 2))
1681 record = (u8 *)(mode_info->atom_context->bios +
1682 le16_to_cpu(lvds_info->info.usModePatchTableOffset));
1685 record = (u8 *)(mode_info->atom_context->bios +
1687 le16_to_cpu(lvds_info->info.usModePatchTableOffset));
1688 while (*record != ATOM_RECORD_END_TYPE) {
1690 case LCD_MODE_PATCH_RECORD_MODE_TYPE:
1691 record += sizeof(ATOM_PATCH_RECORD_MODE);
1693 case LCD_RTS_RECORD_TYPE:
1694 record += sizeof(ATOM_LCD_RTS_RECORD);
1696 case LCD_CAP_RECORD_TYPE:
1697 record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
1699 case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
1700 fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
1701 if (fake_edid_record->ucFakeEDIDLength) {
1704 max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
1705 edid = kmalloc(edid_size, GFP_KERNEL);
1707 memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
1708 fake_edid_record->ucFakeEDIDLength);
1710 if (drm_edid_is_valid(edid)) {
1711 rdev->mode_info.bios_hardcoded_edid = edid;
1712 rdev->mode_info.bios_hardcoded_edid_size = edid_size;
1717 record += fake_edid_record->ucFakeEDIDLength ?
1718 fake_edid_record->ucFakeEDIDLength + 2 :
1719 sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
1721 case LCD_PANEL_RESOLUTION_RECORD_TYPE:
1722 panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
1723 lvds->native_mode.width_mm = panel_res_record->usHSize;
1724 lvds->native_mode.height_mm = panel_res_record->usVSize;
1725 record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
1728 DRM_ERROR("Bad LCD record %d\n", *record);
1740 struct radeon_encoder_primary_dac *
1741 radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1743 struct drm_device *dev = encoder->base.dev;
1744 struct radeon_device *rdev = dev->dev_private;
1745 struct radeon_mode_info *mode_info = &rdev->mode_info;
1746 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1747 uint16_t data_offset;
1748 struct _COMPASSIONATE_DATA *dac_info;
1751 struct radeon_encoder_primary_dac *p_dac = NULL;
1753 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1754 &frev, &crev, &data_offset)) {
1755 dac_info = (struct _COMPASSIONATE_DATA *)
1756 (mode_info->atom_context->bios + data_offset);
1758 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1763 bg = dac_info->ucDAC1_BG_Adjustment;
1764 dac = dac_info->ucDAC1_DAC_Adjustment;
1765 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1771 bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
1772 struct drm_display_mode *mode)
1774 struct radeon_mode_info *mode_info = &rdev->mode_info;
1775 ATOM_ANALOG_TV_INFO *tv_info;
1776 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1777 ATOM_DTD_FORMAT *dtd_timings;
1778 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1780 u16 data_offset, misc;
1782 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1783 &frev, &crev, &data_offset))
1788 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1789 if (index >= MAX_SUPPORTED_TV_TIMING)
1792 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1793 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1794 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1795 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1796 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
1798 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1799 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1800 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1801 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1802 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
1805 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1806 if (misc & ATOM_VSYNC_POLARITY)
1807 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1808 if (misc & ATOM_HSYNC_POLARITY)
1809 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1810 if (misc & ATOM_COMPOSITESYNC)
1811 mode->flags |= DRM_MODE_FLAG_CSYNC;
1812 if (misc & ATOM_INTERLACE)
1813 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1814 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1815 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1817 mode->crtc_clock = mode->clock =
1818 le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
1821 /* PAL timings appear to have wrong values for totals */
1822 mode->crtc_htotal -= 1;
1823 mode->crtc_vtotal -= 1;
1827 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
1828 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
1831 dtd_timings = &tv_info_v1_2->aModeTimings[index];
1832 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1833 le16_to_cpu(dtd_timings->usHBlanking_Time);
1834 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1835 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1836 le16_to_cpu(dtd_timings->usHSyncOffset);
1837 mode->crtc_hsync_end = mode->crtc_hsync_start +
1838 le16_to_cpu(dtd_timings->usHSyncWidth);
1840 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1841 le16_to_cpu(dtd_timings->usVBlanking_Time);
1842 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1843 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1844 le16_to_cpu(dtd_timings->usVSyncOffset);
1845 mode->crtc_vsync_end = mode->crtc_vsync_start +
1846 le16_to_cpu(dtd_timings->usVSyncWidth);
1849 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1850 if (misc & ATOM_VSYNC_POLARITY)
1851 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1852 if (misc & ATOM_HSYNC_POLARITY)
1853 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1854 if (misc & ATOM_COMPOSITESYNC)
1855 mode->flags |= DRM_MODE_FLAG_CSYNC;
1856 if (misc & ATOM_INTERLACE)
1857 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1858 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1859 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1861 mode->crtc_clock = mode->clock =
1862 le16_to_cpu(dtd_timings->usPixClk) * 10;
1869 radeon_atombios_get_tv_info(struct radeon_device *rdev)
1871 struct radeon_mode_info *mode_info = &rdev->mode_info;
1872 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1873 uint16_t data_offset;
1875 struct _ATOM_ANALOG_TV_INFO *tv_info;
1876 enum radeon_tv_std tv_std = TV_STD_NTSC;
1878 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1879 &frev, &crev, &data_offset)) {
1881 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1882 (mode_info->atom_context->bios + data_offset);
1884 switch (tv_info->ucTV_BootUpDefaultStandard) {
1886 tv_std = TV_STD_NTSC;
1887 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
1890 tv_std = TV_STD_NTSC_J;
1891 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
1894 tv_std = TV_STD_PAL;
1895 DRM_DEBUG_KMS("Default TV standard: PAL\n");
1898 tv_std = TV_STD_PAL_M;
1899 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
1902 tv_std = TV_STD_PAL_N;
1903 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
1906 tv_std = TV_STD_PAL_CN;
1907 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
1910 tv_std = TV_STD_PAL_60;
1911 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
1914 tv_std = TV_STD_SECAM;
1915 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
1918 tv_std = TV_STD_NTSC;
1919 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
1926 struct radeon_encoder_tv_dac *
1927 radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1929 struct drm_device *dev = encoder->base.dev;
1930 struct radeon_device *rdev = dev->dev_private;
1931 struct radeon_mode_info *mode_info = &rdev->mode_info;
1932 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1933 uint16_t data_offset;
1934 struct _COMPASSIONATE_DATA *dac_info;
1937 struct radeon_encoder_tv_dac *tv_dac = NULL;
1939 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1940 &frev, &crev, &data_offset)) {
1942 dac_info = (struct _COMPASSIONATE_DATA *)
1943 (mode_info->atom_context->bios + data_offset);
1945 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1950 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1951 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1952 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1954 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1955 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1956 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1958 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1959 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1960 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1962 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
1967 static const char *thermal_controller_names[] = {
1978 static const char *pp_lib_thermal_controller_names[] = {
2001 struct _ATOM_POWERPLAY_INFO info;
2002 struct _ATOM_POWERPLAY_INFO_V2 info_2;
2003 struct _ATOM_POWERPLAY_INFO_V3 info_3;
2004 struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
2005 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
2006 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
2009 union pplib_clock_info {
2010 struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
2011 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
2012 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
2013 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
2014 struct _ATOM_PPLIB_SI_CLOCK_INFO si;
2015 struct _ATOM_PPLIB_CI_CLOCK_INFO ci;
2018 union pplib_power_state {
2019 struct _ATOM_PPLIB_STATE v1;
2020 struct _ATOM_PPLIB_STATE_V2 v2;
2023 static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
2025 u32 misc, u32 misc2)
2027 rdev->pm.power_state[state_index].misc = misc;
2028 rdev->pm.power_state[state_index].misc2 = misc2;
2029 /* order matters! */
2030 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
2031 rdev->pm.power_state[state_index].type =
2032 POWER_STATE_TYPE_POWERSAVE;
2033 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
2034 rdev->pm.power_state[state_index].type =
2035 POWER_STATE_TYPE_BATTERY;
2036 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
2037 rdev->pm.power_state[state_index].type =
2038 POWER_STATE_TYPE_BATTERY;
2039 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
2040 rdev->pm.power_state[state_index].type =
2041 POWER_STATE_TYPE_BALANCED;
2042 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
2043 rdev->pm.power_state[state_index].type =
2044 POWER_STATE_TYPE_PERFORMANCE;
2045 rdev->pm.power_state[state_index].flags &=
2046 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2048 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
2049 rdev->pm.power_state[state_index].type =
2050 POWER_STATE_TYPE_BALANCED;
2051 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
2052 rdev->pm.power_state[state_index].type =
2053 POWER_STATE_TYPE_DEFAULT;
2054 rdev->pm.default_power_state_index = state_index;
2055 rdev->pm.power_state[state_index].default_clock_mode =
2056 &rdev->pm.power_state[state_index].clock_info[0];
2057 } else if (state_index == 0) {
2058 rdev->pm.power_state[state_index].clock_info[0].flags |=
2059 RADEON_PM_MODE_NO_DISPLAY;
2063 static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
2065 struct radeon_mode_info *mode_info = &rdev->mode_info;
2066 u32 misc, misc2 = 0;
2067 int num_modes = 0, i;
2068 int state_index = 0;
2069 struct radeon_i2c_bus_rec i2c_bus;
2070 union power_info *power_info;
2071 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2075 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2076 &frev, &crev, &data_offset))
2078 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2080 /* add the i2c bus for thermal/fan chip */
2081 if ((power_info->info.ucOverdriveThermalController > 0) &&
2082 (power_info->info.ucOverdriveThermalController < ARRAY_SIZE(thermal_controller_names))) {
2083 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2084 thermal_controller_names[power_info->info.ucOverdriveThermalController],
2085 power_info->info.ucOverdriveControllerAddress >> 1);
2086 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
2087 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2088 if (rdev->pm.i2c_bus) {
2089 struct i2c_board_info info = { };
2090 const char *name = thermal_controller_names[power_info->info.
2091 ucOverdriveThermalController];
2092 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
2093 strlcpy(info.type, name, sizeof(info.type));
2094 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2097 num_modes = power_info->info.ucNumOfPowerModeEntries;
2098 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
2099 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
2102 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
2103 if (!rdev->pm.power_state)
2105 /* last mode is usually default, array is low to high */
2106 for (i = 0; i < num_modes; i++) {
2107 rdev->pm.power_state[state_index].clock_info =
2108 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2109 if (!rdev->pm.power_state[state_index].clock_info)
2111 rdev->pm.power_state[state_index].num_clock_modes = 1;
2112 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2115 rdev->pm.power_state[state_index].clock_info[0].mclk =
2116 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
2117 rdev->pm.power_state[state_index].clock_info[0].sclk =
2118 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
2119 /* skip invalid modes */
2120 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2121 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2123 rdev->pm.power_state[state_index].pcie_lanes =
2124 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
2125 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
2126 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2127 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2128 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2130 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2131 radeon_lookup_gpio(rdev,
2132 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
2133 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2134 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2137 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2139 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2140 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2142 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2143 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
2145 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2146 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
2150 rdev->pm.power_state[state_index].clock_info[0].mclk =
2151 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
2152 rdev->pm.power_state[state_index].clock_info[0].sclk =
2153 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
2154 /* skip invalid modes */
2155 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2156 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2158 rdev->pm.power_state[state_index].pcie_lanes =
2159 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
2160 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
2161 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
2162 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2163 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2164 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2166 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2167 radeon_lookup_gpio(rdev,
2168 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
2169 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2170 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2173 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2175 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2176 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2178 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2179 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
2181 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2182 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2186 rdev->pm.power_state[state_index].clock_info[0].mclk =
2187 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
2188 rdev->pm.power_state[state_index].clock_info[0].sclk =
2189 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
2190 /* skip invalid modes */
2191 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2192 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2194 rdev->pm.power_state[state_index].pcie_lanes =
2195 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
2196 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
2197 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
2198 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2199 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2200 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2202 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2203 radeon_lookup_gpio(rdev,
2204 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
2205 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2206 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2209 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2211 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2212 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2214 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2215 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
2216 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
2217 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
2219 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
2220 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
2223 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2224 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2229 /* last mode is usually default */
2230 if (rdev->pm.default_power_state_index == -1) {
2231 rdev->pm.power_state[state_index - 1].type =
2232 POWER_STATE_TYPE_DEFAULT;
2233 rdev->pm.default_power_state_index = state_index - 1;
2234 rdev->pm.power_state[state_index - 1].default_clock_mode =
2235 &rdev->pm.power_state[state_index - 1].clock_info[0];
2236 rdev->pm.power_state[state_index].flags &=
2237 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2238 rdev->pm.power_state[state_index].misc = 0;
2239 rdev->pm.power_state[state_index].misc2 = 0;
2244 static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
2245 ATOM_PPLIB_THERMALCONTROLLER *controller)
2247 struct radeon_i2c_bus_rec i2c_bus;
2249 /* add the i2c bus for thermal/fan chip */
2250 if (controller->ucType > 0) {
2251 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
2252 DRM_INFO("Internal thermal controller %s fan control\n",
2253 (controller->ucFanParameters &
2254 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2255 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
2256 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
2257 DRM_INFO("Internal thermal controller %s fan control\n",
2258 (controller->ucFanParameters &
2259 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2260 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
2261 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
2262 DRM_INFO("Internal thermal controller %s fan control\n",
2263 (controller->ucFanParameters &
2264 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2265 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
2266 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
2267 DRM_INFO("Internal thermal controller %s fan control\n",
2268 (controller->ucFanParameters &
2269 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2270 rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
2271 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
2272 DRM_INFO("Internal thermal controller %s fan control\n",
2273 (controller->ucFanParameters &
2274 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2275 rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
2276 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) {
2277 DRM_INFO("Internal thermal controller %s fan control\n",
2278 (controller->ucFanParameters &
2279 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2280 rdev->pm.int_thermal_type = THERMAL_TYPE_SI;
2281 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_CISLANDS) {
2282 DRM_INFO("Internal thermal controller %s fan control\n",
2283 (controller->ucFanParameters &
2284 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2285 rdev->pm.int_thermal_type = THERMAL_TYPE_CI;
2286 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_KAVERI) {
2287 DRM_INFO("Internal thermal controller %s fan control\n",
2288 (controller->ucFanParameters &
2289 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2290 rdev->pm.int_thermal_type = THERMAL_TYPE_KV;
2291 } else if (controller->ucType ==
2292 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) {
2293 DRM_INFO("External GPIO thermal controller %s fan control\n",
2294 (controller->ucFanParameters &
2295 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2296 rdev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL_GPIO;
2297 } else if (controller->ucType ==
2298 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) {
2299 DRM_INFO("ADT7473 with internal thermal controller %s fan control\n",
2300 (controller->ucFanParameters &
2301 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2302 rdev->pm.int_thermal_type = THERMAL_TYPE_ADT7473_WITH_INTERNAL;
2303 } else if (controller->ucType ==
2304 ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL) {
2305 DRM_INFO("EMC2103 with internal thermal controller %s fan control\n",
2306 (controller->ucFanParameters &
2307 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2308 rdev->pm.int_thermal_type = THERMAL_TYPE_EMC2103_WITH_INTERNAL;
2309 } else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) {
2310 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2311 pp_lib_thermal_controller_names[controller->ucType],
2312 controller->ucI2cAddress >> 1,
2313 (controller->ucFanParameters &
2314 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2315 rdev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL;
2316 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
2317 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2318 if (rdev->pm.i2c_bus) {
2319 struct i2c_board_info info = { };
2320 const char *name = pp_lib_thermal_controller_names[controller->ucType];
2321 info.addr = controller->ucI2cAddress >> 1;
2322 strlcpy(info.type, name, sizeof(info.type));
2323 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2326 DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
2328 controller->ucI2cAddress >> 1,
2329 (controller->ucFanParameters &
2330 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2335 void radeon_atombios_get_default_voltages(struct radeon_device *rdev,
2336 u16 *vddc, u16 *vddci, u16 *mvdd)
2338 struct radeon_mode_info *mode_info = &rdev->mode_info;
2339 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
2342 union firmware_info *firmware_info;
2348 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2349 &frev, &crev, &data_offset)) {
2351 (union firmware_info *)(mode_info->atom_context->bios +
2353 *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
2354 if ((frev == 2) && (crev >= 2)) {
2355 *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
2356 *mvdd = le16_to_cpu(firmware_info->info_22.usBootUpMVDDCVoltage);
2361 static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
2362 int state_index, int mode_index,
2363 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
2366 u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
2367 u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
2368 u16 vddc, vddci, mvdd;
2370 radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd);
2372 rdev->pm.power_state[state_index].misc = misc;
2373 rdev->pm.power_state[state_index].misc2 = misc2;
2374 rdev->pm.power_state[state_index].pcie_lanes =
2375 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2376 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2377 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2378 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2379 rdev->pm.power_state[state_index].type =
2380 POWER_STATE_TYPE_BATTERY;
2382 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2383 rdev->pm.power_state[state_index].type =
2384 POWER_STATE_TYPE_BALANCED;
2386 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2387 rdev->pm.power_state[state_index].type =
2388 POWER_STATE_TYPE_PERFORMANCE;
2390 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2391 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2392 rdev->pm.power_state[state_index].type =
2393 POWER_STATE_TYPE_PERFORMANCE;
2396 rdev->pm.power_state[state_index].flags = 0;
2397 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2398 rdev->pm.power_state[state_index].flags |=
2399 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2400 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
2401 rdev->pm.power_state[state_index].type =
2402 POWER_STATE_TYPE_DEFAULT;
2403 rdev->pm.default_power_state_index = state_index;
2404 rdev->pm.power_state[state_index].default_clock_mode =
2405 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
2406 if ((rdev->family >= CHIP_BARTS) && !(rdev->flags & RADEON_IS_IGP)) {
2407 /* NI chips post without MC ucode, so default clocks are strobe mode only */
2408 rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
2409 rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
2410 rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
2411 rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
2415 if (ASIC_IS_DCE4(rdev))
2416 radeon_atom_get_max_voltage(rdev,
2417 SET_VOLTAGE_TYPE_ASIC_VDDCI,
2419 /* patch the table values with the default sclk/mclk from firmware info */
2420 for (j = 0; j < mode_index; j++) {
2421 rdev->pm.power_state[state_index].clock_info[j].mclk =
2422 rdev->clock.default_mclk;
2423 rdev->pm.power_state[state_index].clock_info[j].sclk =
2424 rdev->clock.default_sclk;
2426 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2429 rdev->pm.power_state[state_index].clock_info[j].voltage.vddci =
2436 static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
2437 int state_index, int mode_index,
2438 union pplib_clock_info *clock_info)
2443 if (rdev->flags & RADEON_IS_IGP) {
2444 if (rdev->family >= CHIP_PALM) {
2445 sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
2446 sclk |= clock_info->sumo.ucEngineClockHigh << 16;
2447 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2449 sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
2450 sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
2451 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2453 } else if (rdev->family >= CHIP_BONAIRE) {
2454 sclk = le16_to_cpu(clock_info->ci.usEngineClockLow);
2455 sclk |= clock_info->ci.ucEngineClockHigh << 16;
2456 mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow);
2457 mclk |= clock_info->ci.ucMemoryClockHigh << 16;
2458 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2459 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2460 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2462 } else if (rdev->family >= CHIP_TAHITI) {
2463 sclk = le16_to_cpu(clock_info->si.usEngineClockLow);
2464 sclk |= clock_info->si.ucEngineClockHigh << 16;
2465 mclk = le16_to_cpu(clock_info->si.usMemoryClockLow);
2466 mclk |= clock_info->si.ucMemoryClockHigh << 16;
2467 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2468 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2469 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2471 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2472 le16_to_cpu(clock_info->si.usVDDC);
2473 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
2474 le16_to_cpu(clock_info->si.usVDDCI);
2475 } else if (rdev->family >= CHIP_CEDAR) {
2476 sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
2477 sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
2478 mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
2479 mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
2480 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2481 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2482 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2484 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2485 le16_to_cpu(clock_info->evergreen.usVDDC);
2486 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
2487 le16_to_cpu(clock_info->evergreen.usVDDCI);
2489 sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
2490 sclk |= clock_info->r600.ucEngineClockHigh << 16;
2491 mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
2492 mclk |= clock_info->r600.ucMemoryClockHigh << 16;
2493 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2494 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2495 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2497 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2498 le16_to_cpu(clock_info->r600.usVDDC);
2501 /* patch up vddc if necessary */
2502 switch (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage) {
2503 case ATOM_VIRTUAL_VOLTAGE_ID0:
2504 case ATOM_VIRTUAL_VOLTAGE_ID1:
2505 case ATOM_VIRTUAL_VOLTAGE_ID2:
2506 case ATOM_VIRTUAL_VOLTAGE_ID3:
2507 case ATOM_VIRTUAL_VOLTAGE_ID4:
2508 case ATOM_VIRTUAL_VOLTAGE_ID5:
2509 case ATOM_VIRTUAL_VOLTAGE_ID6:
2510 case ATOM_VIRTUAL_VOLTAGE_ID7:
2511 if (radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC,
2512 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage,
2514 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
2520 if (rdev->flags & RADEON_IS_IGP) {
2521 /* skip invalid modes */
2522 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2525 /* skip invalid modes */
2526 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2527 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2533 static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
2535 struct radeon_mode_info *mode_info = &rdev->mode_info;
2536 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2537 union pplib_power_state *power_state;
2539 int state_index = 0, mode_index = 0;
2540 union pplib_clock_info *clock_info;
2542 union power_info *power_info;
2543 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2547 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2548 &frev, &crev, &data_offset))
2550 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2552 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
2553 if (power_info->pplib.ucNumStates == 0)
2555 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2556 power_info->pplib.ucNumStates, GFP_KERNEL);
2557 if (!rdev->pm.power_state)
2559 /* first mode is usually default, followed by low to high */
2560 for (i = 0; i < power_info->pplib.ucNumStates; i++) {
2562 power_state = (union pplib_power_state *)
2563 (mode_info->atom_context->bios + data_offset +
2564 le16_to_cpu(power_info->pplib.usStateArrayOffset) +
2565 i * power_info->pplib.ucStateEntrySize);
2566 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2567 (mode_info->atom_context->bios + data_offset +
2568 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
2569 (power_state->v1.ucNonClockStateIndex *
2570 power_info->pplib.ucNonClockSize));
2571 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2572 ((power_info->pplib.ucStateEntrySize - 1) ?
2573 (power_info->pplib.ucStateEntrySize - 1) : 1),
2575 if (!rdev->pm.power_state[i].clock_info)
2577 if (power_info->pplib.ucStateEntrySize - 1) {
2578 for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
2579 clock_info = (union pplib_clock_info *)
2580 (mode_info->atom_context->bios + data_offset +
2581 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
2582 (power_state->v1.ucClockStateIndices[j] *
2583 power_info->pplib.ucClockInfoSize));
2584 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2585 state_index, mode_index,
2591 rdev->pm.power_state[state_index].clock_info[0].mclk =
2592 rdev->clock.default_mclk;
2593 rdev->pm.power_state[state_index].clock_info[0].sclk =
2594 rdev->clock.default_sclk;
2597 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2599 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2604 /* if multiple clock modes, mark the lowest as no display */
2605 for (i = 0; i < state_index; i++) {
2606 if (rdev->pm.power_state[i].num_clock_modes > 1)
2607 rdev->pm.power_state[i].clock_info[0].flags |=
2608 RADEON_PM_MODE_NO_DISPLAY;
2610 /* first mode is usually default */
2611 if (rdev->pm.default_power_state_index == -1) {
2612 rdev->pm.power_state[0].type =
2613 POWER_STATE_TYPE_DEFAULT;
2614 rdev->pm.default_power_state_index = 0;
2615 rdev->pm.power_state[0].default_clock_mode =
2616 &rdev->pm.power_state[0].clock_info[0];
2621 static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
2623 struct radeon_mode_info *mode_info = &rdev->mode_info;
2624 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2625 union pplib_power_state *power_state;
2626 int i, j, non_clock_array_index, clock_array_index;
2627 int state_index = 0, mode_index = 0;
2628 union pplib_clock_info *clock_info;
2629 struct _StateArray *state_array;
2630 struct _ClockInfoArray *clock_info_array;
2631 struct _NonClockInfoArray *non_clock_info_array;
2633 union power_info *power_info;
2634 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2637 u8 *power_state_offset;
2639 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2640 &frev, &crev, &data_offset))
2642 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2644 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
2645 state_array = (struct _StateArray *)
2646 (mode_info->atom_context->bios + data_offset +
2647 le16_to_cpu(power_info->pplib.usStateArrayOffset));
2648 clock_info_array = (struct _ClockInfoArray *)
2649 (mode_info->atom_context->bios + data_offset +
2650 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
2651 non_clock_info_array = (struct _NonClockInfoArray *)
2652 (mode_info->atom_context->bios + data_offset +
2653 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
2654 if (state_array->ucNumEntries == 0)
2656 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2657 state_array->ucNumEntries, GFP_KERNEL);
2658 if (!rdev->pm.power_state)
2660 power_state_offset = (u8 *)state_array->states;
2661 for (i = 0; i < state_array->ucNumEntries; i++) {
2663 power_state = (union pplib_power_state *)power_state_offset;
2664 non_clock_array_index = power_state->v2.nonClockInfoIndex;
2665 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2666 &non_clock_info_array->nonClockInfo[non_clock_array_index];
2667 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2668 (power_state->v2.ucNumDPMLevels ?
2669 power_state->v2.ucNumDPMLevels : 1),
2671 if (!rdev->pm.power_state[i].clock_info)
2673 if (power_state->v2.ucNumDPMLevels) {
2674 for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2675 clock_array_index = power_state->v2.clockInfoIndex[j];
2676 clock_info = (union pplib_clock_info *)
2677 &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
2678 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2679 state_index, mode_index,
2685 rdev->pm.power_state[state_index].clock_info[0].mclk =
2686 rdev->clock.default_mclk;
2687 rdev->pm.power_state[state_index].clock_info[0].sclk =
2688 rdev->clock.default_sclk;
2691 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2693 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2697 power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
2699 /* if multiple clock modes, mark the lowest as no display */
2700 for (i = 0; i < state_index; i++) {
2701 if (rdev->pm.power_state[i].num_clock_modes > 1)
2702 rdev->pm.power_state[i].clock_info[0].flags |=
2703 RADEON_PM_MODE_NO_DISPLAY;
2705 /* first mode is usually default */
2706 if (rdev->pm.default_power_state_index == -1) {
2707 rdev->pm.power_state[0].type =
2708 POWER_STATE_TYPE_DEFAULT;
2709 rdev->pm.default_power_state_index = 0;
2710 rdev->pm.power_state[0].default_clock_mode =
2711 &rdev->pm.power_state[0].clock_info[0];
2716 void radeon_atombios_get_power_modes(struct radeon_device *rdev)
2718 struct radeon_mode_info *mode_info = &rdev->mode_info;
2719 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2722 int state_index = 0;
2724 rdev->pm.default_power_state_index = -1;
2726 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2727 &frev, &crev, &data_offset)) {
2732 state_index = radeon_atombios_parse_power_table_1_3(rdev);
2736 state_index = radeon_atombios_parse_power_table_4_5(rdev);
2739 state_index = radeon_atombios_parse_power_table_6(rdev);
2746 if (state_index == 0) {
2747 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
2748 if (rdev->pm.power_state) {
2749 rdev->pm.power_state[0].clock_info =
2750 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2751 if (rdev->pm.power_state[0].clock_info) {
2752 /* add the default mode */
2753 rdev->pm.power_state[state_index].type =
2754 POWER_STATE_TYPE_DEFAULT;
2755 rdev->pm.power_state[state_index].num_clock_modes = 1;
2756 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2757 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2758 rdev->pm.power_state[state_index].default_clock_mode =
2759 &rdev->pm.power_state[state_index].clock_info[0];
2760 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2761 rdev->pm.power_state[state_index].pcie_lanes = 16;
2762 rdev->pm.default_power_state_index = state_index;
2763 rdev->pm.power_state[state_index].flags = 0;
2769 rdev->pm.num_power_states = state_index;
2771 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2772 rdev->pm.current_clock_mode_index = 0;
2773 if (rdev->pm.default_power_state_index >= 0)
2774 rdev->pm.current_vddc =
2775 rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
2777 rdev->pm.current_vddc = 0;
2780 union get_clock_dividers {
2781 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS v1;
2782 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2 v2;
2783 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3 v3;
2784 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V4 v4;
2785 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V5 v5;
2786 struct _COMPUTE_GPU_CLOCK_INPUT_PARAMETERS_V1_6 v6_in;
2787 struct _COMPUTE_GPU_CLOCK_OUTPUT_PARAMETERS_V1_6 v6_out;
2790 int radeon_atom_get_clock_dividers(struct radeon_device *rdev,
2794 struct atom_clock_dividers *dividers)
2796 union get_clock_dividers args;
2797 int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryEnginePLL);
2800 memset(&args, 0, sizeof(args));
2801 memset(dividers, 0, sizeof(struct atom_clock_dividers));
2803 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2809 args.v1.ucAction = clock_type;
2810 args.v1.ulClock = cpu_to_le32(clock); /* 10 khz */
2812 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2814 dividers->post_div = args.v1.ucPostDiv;
2815 dividers->fb_div = args.v1.ucFbDiv;
2816 dividers->enable_post_div = true;
2821 /* r6xx, r7xx, evergreen, ni, si */
2822 if (rdev->family <= CHIP_RV770) {
2823 args.v2.ucAction = clock_type;
2824 args.v2.ulClock = cpu_to_le32(clock); /* 10 khz */
2826 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2828 dividers->post_div = args.v2.ucPostDiv;
2829 dividers->fb_div = le16_to_cpu(args.v2.usFbDiv);
2830 dividers->ref_div = args.v2.ucAction;
2831 if (rdev->family == CHIP_RV770) {
2832 dividers->enable_post_div = (le32_to_cpu(args.v2.ulClock) & (1 << 24)) ?
2834 dividers->vco_mode = (le32_to_cpu(args.v2.ulClock) & (1 << 25)) ? 1 : 0;
2836 dividers->enable_post_div = (dividers->fb_div & 1) ? true : false;
2838 if (clock_type == COMPUTE_ENGINE_PLL_PARAM) {
2839 args.v3.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
2841 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2843 dividers->post_div = args.v3.ucPostDiv;
2844 dividers->enable_post_div = (args.v3.ucCntlFlag &
2845 ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
2846 dividers->enable_dithen = (args.v3.ucCntlFlag &
2847 ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
2848 dividers->whole_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDiv);
2849 dividers->frac_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDivFrac);
2850 dividers->ref_div = args.v3.ucRefDiv;
2851 dividers->vco_mode = (args.v3.ucCntlFlag &
2852 ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
2854 /* for SI we use ComputeMemoryClockParam for memory plls */
2855 if (rdev->family >= CHIP_TAHITI)
2857 args.v5.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
2859 args.v5.ucInputFlag = ATOM_PLL_INPUT_FLAG_PLL_STROBE_MODE_EN;
2861 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2863 dividers->post_div = args.v5.ucPostDiv;
2864 dividers->enable_post_div = (args.v5.ucCntlFlag &
2865 ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
2866 dividers->enable_dithen = (args.v5.ucCntlFlag &
2867 ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
2868 dividers->whole_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDiv);
2869 dividers->frac_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDivFrac);
2870 dividers->ref_div = args.v5.ucRefDiv;
2871 dividers->vco_mode = (args.v5.ucCntlFlag &
2872 ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
2878 args.v4.ulClock = cpu_to_le32(clock); /* 10 khz */
2880 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2882 dividers->post_divider = dividers->post_div = args.v4.ucPostDiv;
2883 dividers->real_clock = le32_to_cpu(args.v4.ulClock);
2887 /* COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, COMPUTE_GPUCLK_INPUT_FLAG_SCLK */
2888 args.v6_in.ulClock.ulComputeClockFlag = clock_type;
2889 args.v6_in.ulClock.ulClockFreq = cpu_to_le32(clock); /* 10 khz */
2891 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2893 dividers->whole_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDiv);
2894 dividers->frac_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDivFrac);
2895 dividers->ref_div = args.v6_out.ucPllRefDiv;
2896 dividers->post_div = args.v6_out.ucPllPostDiv;
2897 dividers->flags = args.v6_out.ucPllCntlFlag;
2898 dividers->real_clock = le32_to_cpu(args.v6_out.ulClock.ulClock);
2899 dividers->post_divider = args.v6_out.ulClock.ucPostDiv;
2907 int radeon_atom_get_memory_pll_dividers(struct radeon_device *rdev,
2910 struct atom_mpll_param *mpll_param)
2912 COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args;
2913 int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryClockParam);
2916 memset(&args, 0, sizeof(args));
2917 memset(mpll_param, 0, sizeof(struct atom_mpll_param));
2919 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2927 args.ulClock = cpu_to_le32(clock); /* 10 khz */
2928 args.ucInputFlag = 0;
2930 args.ucInputFlag |= MPLL_INPUT_FLAG_STROBE_MODE_EN;
2932 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2934 mpll_param->clkfrac = le16_to_cpu(args.ulFbDiv.usFbDivFrac);
2935 mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv);
2936 mpll_param->post_div = args.ucPostDiv;
2937 mpll_param->dll_speed = args.ucDllSpeed;
2938 mpll_param->bwcntl = args.ucBWCntl;
2939 mpll_param->vco_mode =
2940 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_VCO_MODE_MASK);
2941 mpll_param->yclk_sel =
2942 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_BYPASS_DQ_PLL) ? 1 : 0;
2944 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_QDR_ENABLE) ? 1 : 0;
2945 mpll_param->half_rate =
2946 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_AD_HALF_RATE) ? 1 : 0;
2958 void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2960 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2961 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2963 args.ucEnable = enable;
2965 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2968 uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2970 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2971 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2973 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2974 return le32_to_cpu(args.ulReturnEngineClock);
2977 uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2979 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2980 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2982 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2983 return le32_to_cpu(args.ulReturnMemoryClock);
2986 void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2989 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2990 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2992 args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */
2994 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2997 void radeon_atom_set_memory_clock(struct radeon_device *rdev,
3000 SET_MEMORY_CLOCK_PS_ALLOCATION args;
3001 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
3003 if (rdev->flags & RADEON_IS_IGP)
3006 args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */
3008 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3011 void radeon_atom_set_engine_dram_timings(struct radeon_device *rdev,
3012 u32 eng_clock, u32 mem_clock)
3014 SET_ENGINE_CLOCK_PS_ALLOCATION args;
3015 int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
3018 memset(&args, 0, sizeof(args));
3020 tmp = eng_clock & SET_CLOCK_FREQ_MASK;
3021 tmp |= (COMPUTE_ENGINE_PLL_PARAM << 24);
3023 args.ulTargetEngineClock = cpu_to_le32(tmp);
3025 args.sReserved.ulClock = cpu_to_le32(mem_clock & SET_CLOCK_FREQ_MASK);
3027 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3030 void radeon_atom_update_memory_dll(struct radeon_device *rdev,
3034 int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
3036 args = cpu_to_le32(mem_clock); /* 10 khz */
3038 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3041 void radeon_atom_set_ac_timing(struct radeon_device *rdev,
3044 SET_MEMORY_CLOCK_PS_ALLOCATION args;
3045 int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
3046 u32 tmp = mem_clock | (COMPUTE_MEMORY_PLL_PARAM << 24);
3048 args.ulTargetMemoryClock = cpu_to_le32(tmp); /* 10 khz */
3050 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3054 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
3055 struct _SET_VOLTAGE_PARAMETERS v1;
3056 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
3057 struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
3060 void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
3062 union set_voltage args;
3063 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
3064 u8 frev, crev, volt_index = voltage_level;
3066 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3069 /* 0xff01 is a flag rather then an actual voltage */
3070 if (voltage_level == 0xff01)
3075 args.v1.ucVoltageType = voltage_type;
3076 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
3077 args.v1.ucVoltageIndex = volt_index;
3080 args.v2.ucVoltageType = voltage_type;
3081 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
3082 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
3085 args.v3.ucVoltageType = voltage_type;
3086 args.v3.ucVoltageMode = ATOM_SET_VOLTAGE;
3087 args.v3.usVoltageLevel = cpu_to_le16(voltage_level);
3090 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3094 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3097 int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
3098 u16 voltage_id, u16 *voltage)
3100 union set_voltage args;
3101 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
3104 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3111 args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
3112 args.v2.ucVoltageMode = 0;
3113 args.v2.usVoltageLevel = 0;
3115 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3117 *voltage = le16_to_cpu(args.v2.usVoltageLevel);
3120 args.v3.ucVoltageType = voltage_type;
3121 args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
3122 args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
3124 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3126 *voltage = le16_to_cpu(args.v3.usVoltageLevel);
3129 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3136 int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device *rdev,
3140 return radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC, leakage_idx, voltage);
3143 int radeon_atom_get_leakage_id_from_vbios(struct radeon_device *rdev,
3146 union set_voltage args;
3147 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
3150 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3156 args.v3.ucVoltageType = 0;
3157 args.v3.ucVoltageMode = ATOM_GET_LEAKAGE_ID;
3158 args.v3.usVoltageLevel = 0;
3160 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3162 *leakage_id = le16_to_cpu(args.v3.usVoltageLevel);
3165 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3172 int radeon_atom_get_leakage_vddc_based_on_leakage_params(struct radeon_device *rdev,
3173 u16 *vddc, u16 *vddci,
3174 u16 virtual_voltage_id,
3175 u16 vbios_voltage_id)
3177 int index = GetIndexIntoMasterTable(DATA, ASIC_ProfilingInfo);
3179 u16 data_offset, size;
3181 ATOM_ASIC_PROFILING_INFO_V2_1 *profile;
3182 u16 *leakage_bin, *vddc_id_buf, *vddc_buf, *vddci_id_buf, *vddci_buf;
3187 if (!atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3188 &frev, &crev, &data_offset))
3191 profile = (ATOM_ASIC_PROFILING_INFO_V2_1 *)
3192 (rdev->mode_info.atom_context->bios + data_offset);
3200 if (size < sizeof(ATOM_ASIC_PROFILING_INFO_V2_1))
3202 leakage_bin = (u16 *)
3203 (rdev->mode_info.atom_context->bios + data_offset +
3204 le16_to_cpu(profile->usLeakageBinArrayOffset));
3205 vddc_id_buf = (u16 *)
3206 (rdev->mode_info.atom_context->bios + data_offset +
3207 le16_to_cpu(profile->usElbVDDC_IdArrayOffset));
3209 (rdev->mode_info.atom_context->bios + data_offset +
3210 le16_to_cpu(profile->usElbVDDC_LevelArrayOffset));
3211 vddci_id_buf = (u16 *)
3212 (rdev->mode_info.atom_context->bios + data_offset +
3213 le16_to_cpu(profile->usElbVDDCI_IdArrayOffset));
3215 (rdev->mode_info.atom_context->bios + data_offset +
3216 le16_to_cpu(profile->usElbVDDCI_LevelArrayOffset));
3218 if (profile->ucElbVDDC_Num > 0) {
3219 for (i = 0; i < profile->ucElbVDDC_Num; i++) {
3220 if (vddc_id_buf[i] == virtual_voltage_id) {
3221 for (j = 0; j < profile->ucLeakageBinNum; j++) {
3222 if (vbios_voltage_id <= leakage_bin[j]) {
3223 *vddc = vddc_buf[j * profile->ucElbVDDC_Num + i];
3231 if (profile->ucElbVDDCI_Num > 0) {
3232 for (i = 0; i < profile->ucElbVDDCI_Num; i++) {
3233 if (vddci_id_buf[i] == virtual_voltage_id) {
3234 for (j = 0; j < profile->ucLeakageBinNum; j++) {
3235 if (vbios_voltage_id <= leakage_bin[j]) {
3236 *vddci = vddci_buf[j * profile->ucElbVDDCI_Num + i];
3246 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3251 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3258 union get_voltage_info {
3259 struct _GET_VOLTAGE_INFO_INPUT_PARAMETER_V1_2 in;
3260 struct _GET_EVV_VOLTAGE_INFO_OUTPUT_PARAMETER_V1_2 evv_out;
3263 int radeon_atom_get_voltage_evv(struct radeon_device *rdev,
3264 u16 virtual_voltage_id,
3267 int index = GetIndexIntoMasterTable(COMMAND, GetVoltageInfo);
3269 u32 count = rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count;
3270 union get_voltage_info args;
3272 for (entry_id = 0; entry_id < count; entry_id++) {
3273 if (rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[entry_id].v ==
3278 if (entry_id >= count)
3281 args.in.ucVoltageType = VOLTAGE_TYPE_VDDC;
3282 args.in.ucVoltageMode = ATOM_GET_VOLTAGE_EVV_VOLTAGE;
3283 args.in.ulSCLKFreq =
3284 cpu_to_le32(rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[entry_id].clk);
3286 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3288 *voltage = le16_to_cpu(args.evv_out.usVoltageLevel);
3293 int radeon_atom_get_voltage_gpio_settings(struct radeon_device *rdev,
3294 u16 voltage_level, u8 voltage_type,
3295 u32 *gpio_value, u32 *gpio_mask)
3297 union set_voltage args;
3298 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
3301 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3308 args.v2.ucVoltageType = voltage_type;
3309 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOMASK;
3310 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
3312 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3314 *gpio_mask = le32_to_cpu(*(u32 *)&args.v2);
3316 args.v2.ucVoltageType = voltage_type;
3317 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOVAL;
3318 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
3320 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3322 *gpio_value = le32_to_cpu(*(u32 *)&args.v2);
3325 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3332 union voltage_object_info {
3333 struct _ATOM_VOLTAGE_OBJECT_INFO v1;
3334 struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2;
3335 struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3;
3338 union voltage_object {
3339 struct _ATOM_VOLTAGE_OBJECT v1;
3340 struct _ATOM_VOLTAGE_OBJECT_V2 v2;
3341 union _ATOM_VOLTAGE_OBJECT_V3 v3;
3344 static ATOM_VOLTAGE_OBJECT *atom_lookup_voltage_object_v1(ATOM_VOLTAGE_OBJECT_INFO *v1,
3347 u32 size = le16_to_cpu(v1->sHeader.usStructureSize);
3348 u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO, asVoltageObj[0]);
3349 u8 *start = (u8 *)v1;
3351 while (offset < size) {
3352 ATOM_VOLTAGE_OBJECT *vo = (ATOM_VOLTAGE_OBJECT *)(start + offset);
3353 if (vo->ucVoltageType == voltage_type)
3355 offset += offsetof(ATOM_VOLTAGE_OBJECT, asFormula.ucVIDAdjustEntries) +
3356 vo->asFormula.ucNumOfVoltageEntries;
3361 static ATOM_VOLTAGE_OBJECT_V2 *atom_lookup_voltage_object_v2(ATOM_VOLTAGE_OBJECT_INFO_V2 *v2,
3364 u32 size = le16_to_cpu(v2->sHeader.usStructureSize);
3365 u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V2, asVoltageObj[0]);
3366 u8 *start = (u8*)v2;
3368 while (offset < size) {
3369 ATOM_VOLTAGE_OBJECT_V2 *vo = (ATOM_VOLTAGE_OBJECT_V2 *)(start + offset);
3370 if (vo->ucVoltageType == voltage_type)
3372 offset += offsetof(ATOM_VOLTAGE_OBJECT_V2, asFormula.asVIDAdjustEntries) +
3373 (vo->asFormula.ucNumOfVoltageEntries * sizeof(VOLTAGE_LUT_ENTRY));
3378 static ATOM_VOLTAGE_OBJECT_V3 *atom_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1 *v3,
3379 u8 voltage_type, u8 voltage_mode)
3381 u32 size = le16_to_cpu(v3->sHeader.usStructureSize);
3382 u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1, asVoltageObj[0]);
3383 u8 *start = (u8*)v3;
3385 while (offset < size) {
3386 ATOM_VOLTAGE_OBJECT_V3 *vo = (ATOM_VOLTAGE_OBJECT_V3 *)(start + offset);
3387 if ((vo->asGpioVoltageObj.sHeader.ucVoltageType == voltage_type) &&
3388 (vo->asGpioVoltageObj.sHeader.ucVoltageMode == voltage_mode))
3390 offset += le16_to_cpu(vo->asGpioVoltageObj.sHeader.usSize);
3396 radeon_atom_is_voltage_gpio(struct radeon_device *rdev,
3397 u8 voltage_type, u8 voltage_mode)
3399 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3401 u16 data_offset, size;
3402 union voltage_object_info *voltage_info;
3403 union voltage_object *voltage_object = NULL;
3405 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3406 &frev, &crev, &data_offset)) {
3407 voltage_info = (union voltage_object_info *)
3408 (rdev->mode_info.atom_context->bios + data_offset);
3415 voltage_object = (union voltage_object *)
3416 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3417 if (voltage_object &&
3418 (voltage_object->v1.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO))
3422 voltage_object = (union voltage_object *)
3423 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3424 if (voltage_object &&
3425 (voltage_object->v2.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO))
3429 DRM_ERROR("unknown voltage object table\n");
3436 if (atom_lookup_voltage_object_v3(&voltage_info->v3,
3437 voltage_type, voltage_mode))
3441 DRM_ERROR("unknown voltage object table\n");
3446 DRM_ERROR("unknown voltage object table\n");
3454 int radeon_atom_get_svi2_info(struct radeon_device *rdev,
3456 u8 *svd_gpio_id, u8 *svc_gpio_id)
3458 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3460 u16 data_offset, size;
3461 union voltage_object_info *voltage_info;
3462 union voltage_object *voltage_object = NULL;
3464 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3465 &frev, &crev, &data_offset)) {
3466 voltage_info = (union voltage_object_info *)
3467 (rdev->mode_info.atom_context->bios + data_offset);
3473 voltage_object = (union voltage_object *)
3474 atom_lookup_voltage_object_v3(&voltage_info->v3,
3477 if (voltage_object) {
3478 *svd_gpio_id = voltage_object->v3.asSVID2Obj.ucSVDGpioId;
3479 *svc_gpio_id = voltage_object->v3.asSVID2Obj.ucSVCGpioId;
3485 DRM_ERROR("unknown voltage object table\n");
3490 DRM_ERROR("unknown voltage object table\n");
3498 int radeon_atom_get_max_voltage(struct radeon_device *rdev,
3499 u8 voltage_type, u16 *max_voltage)
3501 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3503 u16 data_offset, size;
3504 union voltage_object_info *voltage_info;
3505 union voltage_object *voltage_object = NULL;
3507 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3508 &frev, &crev, &data_offset)) {
3509 voltage_info = (union voltage_object_info *)
3510 (rdev->mode_info.atom_context->bios + data_offset);
3514 voltage_object = (union voltage_object *)
3515 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3516 if (voltage_object) {
3517 ATOM_VOLTAGE_FORMULA *formula =
3518 &voltage_object->v1.asFormula;
3519 if (formula->ucFlag & 1)
3521 le16_to_cpu(formula->usVoltageBaseLevel) +
3522 formula->ucNumOfVoltageEntries / 2 *
3523 le16_to_cpu(formula->usVoltageStep);
3526 le16_to_cpu(formula->usVoltageBaseLevel) +
3527 (formula->ucNumOfVoltageEntries - 1) *
3528 le16_to_cpu(formula->usVoltageStep);
3533 voltage_object = (union voltage_object *)
3534 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3535 if (voltage_object) {
3536 ATOM_VOLTAGE_FORMULA_V2 *formula =
3537 &voltage_object->v2.asFormula;
3538 if (formula->ucNumOfVoltageEntries) {
3539 VOLTAGE_LUT_ENTRY *lut = (VOLTAGE_LUT_ENTRY *)
3540 ((u8 *)&formula->asVIDAdjustEntries[0] +
3541 (sizeof(VOLTAGE_LUT_ENTRY) * (formula->ucNumOfVoltageEntries - 1)));
3543 le16_to_cpu(lut->usVoltageValue);
3549 DRM_ERROR("unknown voltage object table\n");
3557 int radeon_atom_get_min_voltage(struct radeon_device *rdev,
3558 u8 voltage_type, u16 *min_voltage)
3560 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3562 u16 data_offset, size;
3563 union voltage_object_info *voltage_info;
3564 union voltage_object *voltage_object = NULL;
3566 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3567 &frev, &crev, &data_offset)) {
3568 voltage_info = (union voltage_object_info *)
3569 (rdev->mode_info.atom_context->bios + data_offset);
3573 voltage_object = (union voltage_object *)
3574 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3575 if (voltage_object) {
3576 ATOM_VOLTAGE_FORMULA *formula =
3577 &voltage_object->v1.asFormula;
3579 le16_to_cpu(formula->usVoltageBaseLevel);
3584 voltage_object = (union voltage_object *)
3585 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3586 if (voltage_object) {
3587 ATOM_VOLTAGE_FORMULA_V2 *formula =
3588 &voltage_object->v2.asFormula;
3589 if (formula->ucNumOfVoltageEntries) {
3591 le16_to_cpu(formula->asVIDAdjustEntries[
3599 DRM_ERROR("unknown voltage object table\n");
3607 int radeon_atom_get_voltage_step(struct radeon_device *rdev,
3608 u8 voltage_type, u16 *voltage_step)
3610 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3612 u16 data_offset, size;
3613 union voltage_object_info *voltage_info;
3614 union voltage_object *voltage_object = NULL;
3616 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3617 &frev, &crev, &data_offset)) {
3618 voltage_info = (union voltage_object_info *)
3619 (rdev->mode_info.atom_context->bios + data_offset);
3623 voltage_object = (union voltage_object *)
3624 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3625 if (voltage_object) {
3626 ATOM_VOLTAGE_FORMULA *formula =
3627 &voltage_object->v1.asFormula;
3628 if (formula->ucFlag & 1)
3630 (le16_to_cpu(formula->usVoltageStep) + 1) / 2;
3633 le16_to_cpu(formula->usVoltageStep);
3640 DRM_ERROR("unknown voltage object table\n");
3648 int radeon_atom_round_to_true_voltage(struct radeon_device *rdev,
3650 u16 nominal_voltage,
3653 u16 min_voltage, max_voltage, voltage_step;
3655 if (radeon_atom_get_max_voltage(rdev, voltage_type, &max_voltage))
3657 if (radeon_atom_get_min_voltage(rdev, voltage_type, &min_voltage))
3659 if (radeon_atom_get_voltage_step(rdev, voltage_type, &voltage_step))
3662 if (nominal_voltage <= min_voltage)
3663 *true_voltage = min_voltage;
3664 else if (nominal_voltage >= max_voltage)
3665 *true_voltage = max_voltage;
3667 *true_voltage = min_voltage +
3668 ((nominal_voltage - min_voltage) / voltage_step) *
3674 int radeon_atom_get_voltage_table(struct radeon_device *rdev,
3675 u8 voltage_type, u8 voltage_mode,
3676 struct atom_voltage_table *voltage_table)
3678 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3680 u16 data_offset, size;
3682 union voltage_object_info *voltage_info;
3683 union voltage_object *voltage_object = NULL;
3685 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3686 &frev, &crev, &data_offset)) {
3687 voltage_info = (union voltage_object_info *)
3688 (rdev->mode_info.atom_context->bios + data_offset);
3695 DRM_ERROR("old table version %d, %d\n", frev, crev);
3698 voltage_object = (union voltage_object *)
3699 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3700 if (voltage_object) {
3701 ATOM_VOLTAGE_FORMULA_V2 *formula =
3702 &voltage_object->v2.asFormula;
3703 VOLTAGE_LUT_ENTRY *lut;
3704 if (formula->ucNumOfVoltageEntries > MAX_VOLTAGE_ENTRIES)
3706 lut = &formula->asVIDAdjustEntries[0];
3707 for (i = 0; i < formula->ucNumOfVoltageEntries; i++) {
3708 voltage_table->entries[i].value =
3709 le16_to_cpu(lut->usVoltageValue);
3710 ret = radeon_atom_get_voltage_gpio_settings(rdev,
3711 voltage_table->entries[i].value,
3713 &voltage_table->entries[i].smio_low,
3714 &voltage_table->mask_low);
3717 lut = (VOLTAGE_LUT_ENTRY *)
3718 ((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY));
3720 voltage_table->count = formula->ucNumOfVoltageEntries;
3725 DRM_ERROR("unknown voltage object table\n");
3732 voltage_object = (union voltage_object *)
3733 atom_lookup_voltage_object_v3(&voltage_info->v3,
3734 voltage_type, voltage_mode);
3735 if (voltage_object) {
3736 ATOM_GPIO_VOLTAGE_OBJECT_V3 *gpio =
3737 &voltage_object->v3.asGpioVoltageObj;
3738 VOLTAGE_LUT_ENTRY_V2 *lut;
3739 if (gpio->ucGpioEntryNum > MAX_VOLTAGE_ENTRIES)
3741 lut = &gpio->asVolGpioLut[0];
3742 for (i = 0; i < gpio->ucGpioEntryNum; i++) {
3743 voltage_table->entries[i].value =
3744 le16_to_cpu(lut->usVoltageValue);
3745 voltage_table->entries[i].smio_low =
3746 le32_to_cpu(lut->ulVoltageId);
3747 lut = (VOLTAGE_LUT_ENTRY_V2 *)
3748 ((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY_V2));
3750 voltage_table->mask_low = le32_to_cpu(gpio->ulGpioMaskVal);
3751 voltage_table->count = gpio->ucGpioEntryNum;
3752 voltage_table->phase_delay = gpio->ucPhaseDelay;
3757 DRM_ERROR("unknown voltage object table\n");
3762 DRM_ERROR("unknown voltage object table\n");
3770 struct _ATOM_VRAM_INFO_V3 v1_3;
3771 struct _ATOM_VRAM_INFO_V4 v1_4;
3772 struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1;
3775 int radeon_atom_get_memory_info(struct radeon_device *rdev,
3776 u8 module_index, struct atom_memory_info *mem_info)
3778 int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
3780 u16 data_offset, size;
3781 union vram_info *vram_info;
3783 memset(mem_info, 0, sizeof(struct atom_memory_info));
3785 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3786 &frev, &crev, &data_offset)) {
3787 vram_info = (union vram_info *)
3788 (rdev->mode_info.atom_context->bios + data_offset);
3794 if (module_index < vram_info->v1_3.ucNumOfVRAMModule) {
3795 ATOM_VRAM_MODULE_V3 *vram_module =
3796 (ATOM_VRAM_MODULE_V3 *)vram_info->v1_3.aVramInfo;
3798 for (i = 0; i < module_index; i++) {
3799 if (le16_to_cpu(vram_module->usSize) == 0)
3801 vram_module = (ATOM_VRAM_MODULE_V3 *)
3802 ((u8 *)vram_module + le16_to_cpu(vram_module->usSize));
3804 mem_info->mem_vendor = vram_module->asMemory.ucMemoryVenderID & 0xf;
3805 mem_info->mem_type = vram_module->asMemory.ucMemoryType & 0xf0;
3810 /* r7xx, evergreen */
3811 if (module_index < vram_info->v1_4.ucNumOfVRAMModule) {
3812 ATOM_VRAM_MODULE_V4 *vram_module =
3813 (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo;
3815 for (i = 0; i < module_index; i++) {
3816 if (le16_to_cpu(vram_module->usModuleSize) == 0)
3818 vram_module = (ATOM_VRAM_MODULE_V4 *)
3819 ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
3821 mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf;
3822 mem_info->mem_type = vram_module->ucMemoryType & 0xf0;
3827 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3835 if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
3836 ATOM_VRAM_MODULE_V7 *vram_module =
3837 (ATOM_VRAM_MODULE_V7 *)vram_info->v2_1.aVramInfo;
3839 for (i = 0; i < module_index; i++) {
3840 if (le16_to_cpu(vram_module->usModuleSize) == 0)
3842 vram_module = (ATOM_VRAM_MODULE_V7 *)
3843 ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
3845 mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf;
3846 mem_info->mem_type = vram_module->ucMemoryType & 0xf0;
3851 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3856 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3864 int radeon_atom_get_mclk_range_table(struct radeon_device *rdev,
3865 bool gddr5, u8 module_index,
3866 struct atom_memory_clock_range_table *mclk_range_table)
3868 int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
3870 u16 data_offset, size;
3871 union vram_info *vram_info;
3872 u32 mem_timing_size = gddr5 ?
3873 sizeof(ATOM_MEMORY_TIMING_FORMAT_V2) : sizeof(ATOM_MEMORY_TIMING_FORMAT);
3875 memset(mclk_range_table, 0, sizeof(struct atom_memory_clock_range_table));
3877 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3878 &frev, &crev, &data_offset)) {
3879 vram_info = (union vram_info *)
3880 (rdev->mode_info.atom_context->bios + data_offset);
3885 DRM_ERROR("old table version %d, %d\n", frev, crev);
3888 /* r7xx, evergreen */
3889 if (module_index < vram_info->v1_4.ucNumOfVRAMModule) {
3890 ATOM_VRAM_MODULE_V4 *vram_module =
3891 (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo;
3892 ATOM_MEMORY_TIMING_FORMAT *format;
3894 for (i = 0; i < module_index; i++) {
3895 if (le16_to_cpu(vram_module->usModuleSize) == 0)
3897 vram_module = (ATOM_VRAM_MODULE_V4 *)
3898 ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
3900 mclk_range_table->num_entries = (u8)
3901 ((le16_to_cpu(vram_module->usModuleSize) - offsetof(ATOM_VRAM_MODULE_V4, asMemTiming)) /
3903 format = &vram_module->asMemTiming[0];
3904 for (i = 0; i < mclk_range_table->num_entries; i++) {
3905 mclk_range_table->mclk[i] = le32_to_cpu(format->ulClkRange);
3906 format = (ATOM_MEMORY_TIMING_FORMAT *)
3907 ((u8 *)format + mem_timing_size);
3913 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3918 DRM_ERROR("new table version %d, %d\n", frev, crev);
3921 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3929 #define MEM_ID_MASK 0xff000000
3930 #define MEM_ID_SHIFT 24
3931 #define CLOCK_RANGE_MASK 0x00ffffff
3932 #define CLOCK_RANGE_SHIFT 0
3933 #define LOW_NIBBLE_MASK 0xf
3934 #define DATA_EQU_PREV 0
3935 #define DATA_FROM_TABLE 4
3937 int radeon_atom_init_mc_reg_table(struct radeon_device *rdev,
3939 struct atom_mc_reg_table *reg_table)
3941 int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
3942 u8 frev, crev, num_entries, t_mem_id, num_ranges = 0;
3944 u16 data_offset, size;
3945 union vram_info *vram_info;
3947 memset(reg_table, 0, sizeof(struct atom_mc_reg_table));
3949 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3950 &frev, &crev, &data_offset)) {
3951 vram_info = (union vram_info *)
3952 (rdev->mode_info.atom_context->bios + data_offset);
3955 DRM_ERROR("old table version %d, %d\n", frev, crev);
3960 if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
3961 ATOM_INIT_REG_BLOCK *reg_block =
3962 (ATOM_INIT_REG_BLOCK *)
3963 ((u8 *)vram_info + le16_to_cpu(vram_info->v2_1.usMemClkPatchTblOffset));
3964 ATOM_MEMORY_SETTING_DATA_BLOCK *reg_data =
3965 (ATOM_MEMORY_SETTING_DATA_BLOCK *)
3966 ((u8 *)reg_block + (2 * sizeof(u16)) +
3967 le16_to_cpu(reg_block->usRegIndexTblSize));
3968 ATOM_INIT_REG_INDEX_FORMAT *format = ®_block->asRegIndexBuf[0];
3969 num_entries = (u8)((le16_to_cpu(reg_block->usRegIndexTblSize)) /
3970 sizeof(ATOM_INIT_REG_INDEX_FORMAT)) - 1;
3971 if (num_entries > VBIOS_MC_REGISTER_ARRAY_SIZE)
3973 while (i < num_entries) {
3974 if (format->ucPreRegDataLength & ACCESS_PLACEHOLDER)
3976 reg_table->mc_reg_address[i].s1 =
3977 (u16)(le16_to_cpu(format->usRegIndex));
3978 reg_table->mc_reg_address[i].pre_reg_data =
3979 (u8)(format->ucPreRegDataLength);
3981 format = (ATOM_INIT_REG_INDEX_FORMAT *)
3982 ((u8 *)format + sizeof(ATOM_INIT_REG_INDEX_FORMAT));
3984 reg_table->last = i;
3985 while ((le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK) &&
3986 (num_ranges < VBIOS_MAX_AC_TIMING_ENTRIES)) {
3987 t_mem_id = (u8)((le32_to_cpu(*(u32 *)reg_data) & MEM_ID_MASK)
3989 if (module_index == t_mem_id) {
3990 reg_table->mc_reg_table_entry[num_ranges].mclk_max =
3991 (u32)((le32_to_cpu(*(u32 *)reg_data) & CLOCK_RANGE_MASK)
3992 >> CLOCK_RANGE_SHIFT);
3993 for (i = 0, j = 1; i < reg_table->last; i++) {
3994 if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_FROM_TABLE) {
3995 reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
3996 (u32)le32_to_cpu(*((u32 *)reg_data + j));
3998 } else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
3999 reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
4000 reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
4005 reg_data = (ATOM_MEMORY_SETTING_DATA_BLOCK *)
4006 ((u8 *)reg_data + le16_to_cpu(reg_block->usRegDataBlkSize));
4008 if (le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK)
4010 reg_table->num_entries = num_ranges;
4015 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
4020 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
4028 void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
4030 struct radeon_device *rdev = dev->dev_private;
4031 uint32_t bios_2_scratch, bios_6_scratch;
4033 if (rdev->family >= CHIP_R600) {
4034 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
4035 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
4037 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
4038 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
4041 /* let the bios control the backlight */
4042 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
4044 /* tell the bios not to handle mode switching */
4045 bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
4047 /* clear the vbios dpms state */
4048 if (ASIC_IS_DCE4(rdev))
4049 bios_2_scratch &= ~ATOM_S2_DEVICE_DPMS_STATE;
4051 if (rdev->family >= CHIP_R600) {
4052 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
4053 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
4055 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
4056 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
4061 void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
4063 uint32_t scratch_reg;
4066 if (rdev->family >= CHIP_R600)
4067 scratch_reg = R600_BIOS_0_SCRATCH;
4069 scratch_reg = RADEON_BIOS_0_SCRATCH;
4071 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
4072 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
4075 void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
4077 uint32_t scratch_reg;
4080 if (rdev->family >= CHIP_R600)
4081 scratch_reg = R600_BIOS_0_SCRATCH;
4083 scratch_reg = RADEON_BIOS_0_SCRATCH;
4085 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
4086 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
4089 void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
4091 struct drm_device *dev = encoder->dev;
4092 struct radeon_device *rdev = dev->dev_private;
4093 uint32_t bios_6_scratch;
4095 if (rdev->family >= CHIP_R600)
4096 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
4098 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
4101 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
4102 bios_6_scratch &= ~ATOM_S6_ACC_MODE;
4104 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
4105 bios_6_scratch |= ATOM_S6_ACC_MODE;
4108 if (rdev->family >= CHIP_R600)
4109 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
4111 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
4114 /* at some point we may want to break this out into individual functions */
4116 radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
4117 struct drm_encoder *encoder,
4120 struct drm_device *dev = connector->dev;
4121 struct radeon_device *rdev = dev->dev_private;
4122 struct radeon_connector *radeon_connector =
4123 to_radeon_connector(connector);
4124 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
4125 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
4127 if (rdev->family >= CHIP_R600) {
4128 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
4129 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
4130 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
4132 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
4133 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
4134 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
4137 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
4138 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
4140 DRM_DEBUG_KMS("TV1 connected\n");
4141 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
4142 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
4144 DRM_DEBUG_KMS("TV1 disconnected\n");
4145 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
4146 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
4147 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
4150 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
4151 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
4153 DRM_DEBUG_KMS("CV connected\n");
4154 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
4155 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
4157 DRM_DEBUG_KMS("CV disconnected\n");
4158 bios_0_scratch &= ~ATOM_S0_CV_MASK;
4159 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
4160 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
4163 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
4164 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
4166 DRM_DEBUG_KMS("LCD1 connected\n");
4167 bios_0_scratch |= ATOM_S0_LCD1;
4168 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
4169 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
4171 DRM_DEBUG_KMS("LCD1 disconnected\n");
4172 bios_0_scratch &= ~ATOM_S0_LCD1;
4173 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
4174 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
4177 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
4178 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
4180 DRM_DEBUG_KMS("CRT1 connected\n");
4181 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
4182 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
4183 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
4185 DRM_DEBUG_KMS("CRT1 disconnected\n");
4186 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
4187 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
4188 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
4191 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
4192 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
4194 DRM_DEBUG_KMS("CRT2 connected\n");
4195 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
4196 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
4197 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
4199 DRM_DEBUG_KMS("CRT2 disconnected\n");
4200 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
4201 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
4202 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
4205 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
4206 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
4208 DRM_DEBUG_KMS("DFP1 connected\n");
4209 bios_0_scratch |= ATOM_S0_DFP1;
4210 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
4211 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
4213 DRM_DEBUG_KMS("DFP1 disconnected\n");
4214 bios_0_scratch &= ~ATOM_S0_DFP1;
4215 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
4216 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
4219 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
4220 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
4222 DRM_DEBUG_KMS("DFP2 connected\n");
4223 bios_0_scratch |= ATOM_S0_DFP2;
4224 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
4225 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
4227 DRM_DEBUG_KMS("DFP2 disconnected\n");
4228 bios_0_scratch &= ~ATOM_S0_DFP2;
4229 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
4230 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
4233 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
4234 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
4236 DRM_DEBUG_KMS("DFP3 connected\n");
4237 bios_0_scratch |= ATOM_S0_DFP3;
4238 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
4239 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
4241 DRM_DEBUG_KMS("DFP3 disconnected\n");
4242 bios_0_scratch &= ~ATOM_S0_DFP3;
4243 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
4244 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
4247 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
4248 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
4250 DRM_DEBUG_KMS("DFP4 connected\n");
4251 bios_0_scratch |= ATOM_S0_DFP4;
4252 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
4253 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
4255 DRM_DEBUG_KMS("DFP4 disconnected\n");
4256 bios_0_scratch &= ~ATOM_S0_DFP4;
4257 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
4258 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
4261 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
4262 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
4264 DRM_DEBUG_KMS("DFP5 connected\n");
4265 bios_0_scratch |= ATOM_S0_DFP5;
4266 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
4267 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
4269 DRM_DEBUG_KMS("DFP5 disconnected\n");
4270 bios_0_scratch &= ~ATOM_S0_DFP5;
4271 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
4272 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
4275 if ((radeon_encoder->devices & ATOM_DEVICE_DFP6_SUPPORT) &&
4276 (radeon_connector->devices & ATOM_DEVICE_DFP6_SUPPORT)) {
4278 DRM_DEBUG_KMS("DFP6 connected\n");
4279 bios_0_scratch |= ATOM_S0_DFP6;
4280 bios_3_scratch |= ATOM_S3_DFP6_ACTIVE;
4281 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP6;
4283 DRM_DEBUG_KMS("DFP6 disconnected\n");
4284 bios_0_scratch &= ~ATOM_S0_DFP6;
4285 bios_3_scratch &= ~ATOM_S3_DFP6_ACTIVE;
4286 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP6;
4290 if (rdev->family >= CHIP_R600) {
4291 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
4292 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
4293 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
4295 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
4296 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
4297 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
4302 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
4304 struct drm_device *dev = encoder->dev;
4305 struct radeon_device *rdev = dev->dev_private;
4306 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
4307 uint32_t bios_3_scratch;
4309 if (ASIC_IS_DCE4(rdev))
4312 if (rdev->family >= CHIP_R600)
4313 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
4315 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
4317 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
4318 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
4319 bios_3_scratch |= (crtc << 18);
4321 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
4322 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
4323 bios_3_scratch |= (crtc << 24);
4325 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
4326 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
4327 bios_3_scratch |= (crtc << 16);
4329 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
4330 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
4331 bios_3_scratch |= (crtc << 20);
4333 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
4334 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
4335 bios_3_scratch |= (crtc << 17);
4337 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
4338 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
4339 bios_3_scratch |= (crtc << 19);
4341 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
4342 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
4343 bios_3_scratch |= (crtc << 23);
4345 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
4346 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
4347 bios_3_scratch |= (crtc << 25);
4350 if (rdev->family >= CHIP_R600)
4351 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
4353 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
4357 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
4359 struct drm_device *dev = encoder->dev;
4360 struct radeon_device *rdev = dev->dev_private;
4361 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
4362 uint32_t bios_2_scratch;
4364 if (ASIC_IS_DCE4(rdev))
4367 if (rdev->family >= CHIP_R600)
4368 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
4370 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
4372 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
4374 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
4376 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
4378 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
4380 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
4382 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
4384 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
4386 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
4388 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
4390 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
4392 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
4394 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
4396 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
4398 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
4400 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
4402 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
4404 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
4406 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
4408 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
4410 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
4412 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
4414 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
4416 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
4418 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
4420 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
4422 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
4424 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
4426 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
4428 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
4430 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
4433 if (rdev->family >= CHIP_R600)
4434 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
4436 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);