2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Authors: Dave Airlie
27 #include "radeon_drm.h"
31 #include "atom-bits.h"
33 /* from radeon_encoder.c */
35 radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
37 extern void radeon_link_encoder_connector(struct drm_device *dev);
39 radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
40 uint32_t supported_device);
42 /* from radeon_connector.c */
44 radeon_add_atom_connector(struct drm_device *dev,
45 uint32_t connector_id,
46 uint32_t supported_device,
48 struct radeon_i2c_bus_rec *i2c_bus,
49 uint32_t igp_lane_info,
50 uint16_t connector_object_id,
51 struct radeon_hpd *hpd,
52 struct radeon_router *router);
54 /* from radeon_legacy_encoder.c */
56 radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
57 uint32_t supported_device);
59 union atom_supported_devices {
60 struct _ATOM_SUPPORTED_DEVICES_INFO info;
61 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
62 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
65 static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
68 struct atom_context *ctx = rdev->mode_info.atom_context;
69 ATOM_GPIO_I2C_ASSIGMENT *gpio;
70 struct radeon_i2c_bus_rec i2c;
71 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
72 struct _ATOM_GPIO_I2C_INFO *i2c_info;
73 uint16_t data_offset, size;
76 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
79 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
80 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
82 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
83 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
85 for (i = 0; i < num_indices; i++) {
86 gpio = &i2c_info->asGPIO_Info[i];
88 /* some evergreen boards have bad data for this entry */
89 if (ASIC_IS_DCE4(rdev)) {
91 (gpio->usClkMaskRegisterIndex == 0x1936) &&
92 (gpio->sucI2cId.ucAccess == 0)) {
93 gpio->sucI2cId.ucAccess = 0x97;
94 gpio->ucDataMaskShift = 8;
95 gpio->ucDataEnShift = 8;
96 gpio->ucDataY_Shift = 8;
97 gpio->ucDataA_Shift = 8;
101 /* some DCE3 boards have bad data for this entry */
102 if (ASIC_IS_DCE3(rdev)) {
104 (gpio->usClkMaskRegisterIndex == 0x1fda) &&
105 (gpio->sucI2cId.ucAccess == 0x94))
106 gpio->sucI2cId.ucAccess = 0x14;
109 if (gpio->sucI2cId.ucAccess == id) {
110 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
111 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
112 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
113 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
114 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
115 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
116 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
117 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
118 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
119 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
120 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
121 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
122 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
123 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
124 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
125 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
127 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
128 i2c.hw_capable = true;
130 i2c.hw_capable = false;
132 if (gpio->sucI2cId.ucAccess == 0xa0)
137 i2c.i2c_id = gpio->sucI2cId.ucAccess;
139 if (i2c.mask_clk_reg)
149 void radeon_atombios_i2c_init(struct radeon_device *rdev)
151 struct atom_context *ctx = rdev->mode_info.atom_context;
152 ATOM_GPIO_I2C_ASSIGMENT *gpio;
153 struct radeon_i2c_bus_rec i2c;
154 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
155 struct _ATOM_GPIO_I2C_INFO *i2c_info;
156 uint16_t data_offset, size;
160 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
162 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
163 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
165 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
166 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
168 for (i = 0; i < num_indices; i++) {
169 gpio = &i2c_info->asGPIO_Info[i];
172 /* some evergreen boards have bad data for this entry */
173 if (ASIC_IS_DCE4(rdev)) {
175 (gpio->usClkMaskRegisterIndex == 0x1936) &&
176 (gpio->sucI2cId.ucAccess == 0)) {
177 gpio->sucI2cId.ucAccess = 0x97;
178 gpio->ucDataMaskShift = 8;
179 gpio->ucDataEnShift = 8;
180 gpio->ucDataY_Shift = 8;
181 gpio->ucDataA_Shift = 8;
185 /* some DCE3 boards have bad data for this entry */
186 if (ASIC_IS_DCE3(rdev)) {
188 (gpio->usClkMaskRegisterIndex == 0x1fda) &&
189 (gpio->sucI2cId.ucAccess == 0x94))
190 gpio->sucI2cId.ucAccess = 0x14;
193 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
194 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
195 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
196 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
197 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
198 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
199 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
200 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
201 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
202 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
203 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
204 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
205 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
206 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
207 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
208 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
210 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
211 i2c.hw_capable = true;
213 i2c.hw_capable = false;
215 if (gpio->sucI2cId.ucAccess == 0xa0)
220 i2c.i2c_id = gpio->sucI2cId.ucAccess;
222 if (i2c.mask_clk_reg) {
224 sprintf(stmp, "0x%x", i2c.i2c_id);
225 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
231 static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
234 struct atom_context *ctx = rdev->mode_info.atom_context;
235 struct radeon_gpio_rec gpio;
236 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
237 struct _ATOM_GPIO_PIN_LUT *gpio_info;
238 ATOM_GPIO_PIN_ASSIGNMENT *pin;
239 u16 data_offset, size;
242 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
245 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
246 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
248 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
249 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
251 for (i = 0; i < num_indices; i++) {
252 pin = &gpio_info->asGPIO_Pin[i];
253 if (id == pin->ucGPIO_ID) {
254 gpio.id = pin->ucGPIO_ID;
255 gpio.reg = pin->usGpioPin_AIndex * 4;
256 gpio.mask = (1 << pin->ucGpioPinBitShift);
266 static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
267 struct radeon_gpio_rec *gpio)
269 struct radeon_hpd hpd;
272 memset(&hpd, 0, sizeof(struct radeon_hpd));
274 if (ASIC_IS_DCE4(rdev))
275 reg = EVERGREEN_DC_GPIO_HPD_A;
277 reg = AVIVO_DC_GPIO_HPD_A;
280 if (gpio->reg == reg) {
283 hpd.hpd = RADEON_HPD_1;
286 hpd.hpd = RADEON_HPD_2;
289 hpd.hpd = RADEON_HPD_3;
292 hpd.hpd = RADEON_HPD_4;
295 hpd.hpd = RADEON_HPD_5;
298 hpd.hpd = RADEON_HPD_6;
301 hpd.hpd = RADEON_HPD_NONE;
305 hpd.hpd = RADEON_HPD_NONE;
309 static bool radeon_atom_apply_quirks(struct drm_device *dev,
310 uint32_t supported_device,
312 struct radeon_i2c_bus_rec *i2c_bus,
314 struct radeon_hpd *hpd)
316 struct radeon_device *rdev = dev->dev_private;
318 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
319 if ((dev->pdev->device == 0x791e) &&
320 (dev->pdev->subsystem_vendor == 0x1043) &&
321 (dev->pdev->subsystem_device == 0x826d)) {
322 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
323 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
324 *connector_type = DRM_MODE_CONNECTOR_DVID;
327 /* Asrock RS600 board lists the DVI port as HDMI */
328 if ((dev->pdev->device == 0x7941) &&
329 (dev->pdev->subsystem_vendor == 0x1849) &&
330 (dev->pdev->subsystem_device == 0x7941)) {
331 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
332 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
333 *connector_type = DRM_MODE_CONNECTOR_DVID;
336 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
337 if ((dev->pdev->device == 0x796e) &&
338 (dev->pdev->subsystem_vendor == 0x1462) &&
339 (dev->pdev->subsystem_device == 0x7302)) {
340 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
341 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
345 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
346 if ((dev->pdev->device == 0x7941) &&
347 (dev->pdev->subsystem_vendor == 0x147b) &&
348 (dev->pdev->subsystem_device == 0x2412)) {
349 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
353 /* Falcon NW laptop lists vga ddc line for LVDS */
354 if ((dev->pdev->device == 0x5653) &&
355 (dev->pdev->subsystem_vendor == 0x1462) &&
356 (dev->pdev->subsystem_device == 0x0291)) {
357 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
358 i2c_bus->valid = false;
363 /* HIS X1300 is DVI+VGA, not DVI+DVI */
364 if ((dev->pdev->device == 0x7146) &&
365 (dev->pdev->subsystem_vendor == 0x17af) &&
366 (dev->pdev->subsystem_device == 0x2058)) {
367 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
371 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
372 if ((dev->pdev->device == 0x7142) &&
373 (dev->pdev->subsystem_vendor == 0x1458) &&
374 (dev->pdev->subsystem_device == 0x2134)) {
375 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
381 if ((dev->pdev->device == 0x71C5) &&
382 (dev->pdev->subsystem_vendor == 0x106b) &&
383 (dev->pdev->subsystem_device == 0x0080)) {
384 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
385 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
387 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
391 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
392 if ((dev->pdev->device == 0x9598) &&
393 (dev->pdev->subsystem_vendor == 0x1043) &&
394 (dev->pdev->subsystem_device == 0x01da)) {
395 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
396 *connector_type = DRM_MODE_CONNECTOR_DVII;
400 /* ASUS HD 3600 board lists the DVI port as HDMI */
401 if ((dev->pdev->device == 0x9598) &&
402 (dev->pdev->subsystem_vendor == 0x1043) &&
403 (dev->pdev->subsystem_device == 0x01e4)) {
404 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
405 *connector_type = DRM_MODE_CONNECTOR_DVII;
409 /* ASUS HD 3450 board lists the DVI port as HDMI */
410 if ((dev->pdev->device == 0x95C5) &&
411 (dev->pdev->subsystem_vendor == 0x1043) &&
412 (dev->pdev->subsystem_device == 0x01e2)) {
413 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
414 *connector_type = DRM_MODE_CONNECTOR_DVII;
418 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
419 * HDMI + VGA reporting as HDMI
421 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
422 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
423 *connector_type = DRM_MODE_CONNECTOR_VGA;
428 /* Acer laptop reports DVI-D as DVI-I and hpd pins reversed */
429 if ((dev->pdev->device == 0x95c4) &&
430 (dev->pdev->subsystem_vendor == 0x1025) &&
431 (dev->pdev->subsystem_device == 0x013c)) {
432 struct radeon_gpio_rec gpio;
434 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
435 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
436 gpio = radeon_lookup_gpio(rdev, 6);
437 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
438 *connector_type = DRM_MODE_CONNECTOR_DVID;
439 } else if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
440 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
441 gpio = radeon_lookup_gpio(rdev, 7);
442 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
446 /* XFX Pine Group device rv730 reports no VGA DDC lines
447 * even though they are wired up to record 0x93
449 if ((dev->pdev->device == 0x9498) &&
450 (dev->pdev->subsystem_vendor == 0x1682) &&
451 (dev->pdev->subsystem_device == 0x2452)) {
452 struct radeon_device *rdev = dev->dev_private;
453 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
458 const int supported_devices_connector_convert[] = {
459 DRM_MODE_CONNECTOR_Unknown,
460 DRM_MODE_CONNECTOR_VGA,
461 DRM_MODE_CONNECTOR_DVII,
462 DRM_MODE_CONNECTOR_DVID,
463 DRM_MODE_CONNECTOR_DVIA,
464 DRM_MODE_CONNECTOR_SVIDEO,
465 DRM_MODE_CONNECTOR_Composite,
466 DRM_MODE_CONNECTOR_LVDS,
467 DRM_MODE_CONNECTOR_Unknown,
468 DRM_MODE_CONNECTOR_Unknown,
469 DRM_MODE_CONNECTOR_HDMIA,
470 DRM_MODE_CONNECTOR_HDMIB,
471 DRM_MODE_CONNECTOR_Unknown,
472 DRM_MODE_CONNECTOR_Unknown,
473 DRM_MODE_CONNECTOR_9PinDIN,
474 DRM_MODE_CONNECTOR_DisplayPort
477 const uint16_t supported_devices_connector_object_id_convert[] = {
478 CONNECTOR_OBJECT_ID_NONE,
479 CONNECTOR_OBJECT_ID_VGA,
480 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
481 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
482 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
483 CONNECTOR_OBJECT_ID_COMPOSITE,
484 CONNECTOR_OBJECT_ID_SVIDEO,
485 CONNECTOR_OBJECT_ID_LVDS,
486 CONNECTOR_OBJECT_ID_9PIN_DIN,
487 CONNECTOR_OBJECT_ID_9PIN_DIN,
488 CONNECTOR_OBJECT_ID_DISPLAYPORT,
489 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
490 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
491 CONNECTOR_OBJECT_ID_SVIDEO
494 const int object_connector_convert[] = {
495 DRM_MODE_CONNECTOR_Unknown,
496 DRM_MODE_CONNECTOR_DVII,
497 DRM_MODE_CONNECTOR_DVII,
498 DRM_MODE_CONNECTOR_DVID,
499 DRM_MODE_CONNECTOR_DVID,
500 DRM_MODE_CONNECTOR_VGA,
501 DRM_MODE_CONNECTOR_Composite,
502 DRM_MODE_CONNECTOR_SVIDEO,
503 DRM_MODE_CONNECTOR_Unknown,
504 DRM_MODE_CONNECTOR_Unknown,
505 DRM_MODE_CONNECTOR_9PinDIN,
506 DRM_MODE_CONNECTOR_Unknown,
507 DRM_MODE_CONNECTOR_HDMIA,
508 DRM_MODE_CONNECTOR_HDMIB,
509 DRM_MODE_CONNECTOR_LVDS,
510 DRM_MODE_CONNECTOR_9PinDIN,
511 DRM_MODE_CONNECTOR_Unknown,
512 DRM_MODE_CONNECTOR_Unknown,
513 DRM_MODE_CONNECTOR_Unknown,
514 DRM_MODE_CONNECTOR_DisplayPort,
515 DRM_MODE_CONNECTOR_eDP,
516 DRM_MODE_CONNECTOR_Unknown
519 bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
521 struct radeon_device *rdev = dev->dev_private;
522 struct radeon_mode_info *mode_info = &rdev->mode_info;
523 struct atom_context *ctx = mode_info->atom_context;
524 int index = GetIndexIntoMasterTable(DATA, Object_Header);
525 u16 size, data_offset;
527 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
528 ATOM_OBJECT_TABLE *router_obj;
529 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
530 ATOM_OBJECT_HEADER *obj_header;
531 int i, j, k, path_size, device_support;
533 u16 igp_lane_info, conn_id, connector_object_id;
534 struct radeon_i2c_bus_rec ddc_bus;
535 struct radeon_router router;
536 struct radeon_gpio_rec gpio;
537 struct radeon_hpd hpd;
539 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
545 router.valid = false;
547 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
548 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
549 (ctx->bios + data_offset +
550 le16_to_cpu(obj_header->usDisplayPathTableOffset));
551 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
552 (ctx->bios + data_offset +
553 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
554 router_obj = (ATOM_OBJECT_TABLE *)
555 (ctx->bios + data_offset +
556 le16_to_cpu(obj_header->usRouterObjectTableOffset));
557 device_support = le16_to_cpu(obj_header->usDeviceSupport);
560 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
561 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
562 ATOM_DISPLAY_OBJECT_PATH *path;
564 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
565 path_size += le16_to_cpu(path->usSize);
567 if (device_support & le16_to_cpu(path->usDeviceTag)) {
568 uint8_t con_obj_id, con_obj_num, con_obj_type;
571 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
574 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
577 (le16_to_cpu(path->usConnObjectId) &
578 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
580 /* TODO CV support */
581 if (le16_to_cpu(path->usDeviceTag) ==
582 ATOM_DEVICE_CV_SUPPORT)
586 if ((rdev->flags & RADEON_IS_IGP) &&
588 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
589 uint16_t igp_offset = 0;
590 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
593 GetIndexIntoMasterTable(DATA,
594 IntegratedSystemInfo);
596 if (atom_parse_data_header(ctx, index, &size, &frev,
597 &crev, &igp_offset)) {
601 (ATOM_INTEGRATED_SYSTEM_INFO_V2
602 *) (ctx->bios + igp_offset);
605 uint32_t slot_config, ct;
607 if (con_obj_num == 1)
616 ct = (slot_config >> 16) & 0xff;
618 object_connector_convert
620 connector_object_id = ct;
622 slot_config & 0xffff;
630 object_connector_convert[con_obj_id];
631 connector_object_id = con_obj_id;
636 object_connector_convert[con_obj_id];
637 connector_object_id = con_obj_id;
640 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
643 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
644 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
647 (le16_to_cpu(path->usGraphicObjIds[j]) &
648 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
650 (le16_to_cpu(path->usGraphicObjIds[j]) &
651 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
653 (le16_to_cpu(path->usGraphicObjIds[j]) &
654 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
656 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
657 u16 encoder_obj = le16_to_cpu(path->usGraphicObjIds[j]);
659 radeon_add_atom_encoder(dev,
665 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
666 router.valid = false;
667 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
668 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[j].usObjectID);
669 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
670 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
671 (ctx->bios + data_offset +
672 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
673 ATOM_I2C_RECORD *i2c_record;
674 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
675 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
676 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
677 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
678 (ctx->bios + data_offset +
679 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
682 router.router_id = router_obj_id;
683 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
685 if (le16_to_cpu(path->usConnObjectId) ==
686 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
690 while (record->ucRecordType > 0 &&
691 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
692 switch (record->ucRecordType) {
693 case ATOM_I2C_RECORD_TYPE:
698 (ATOM_I2C_ID_CONFIG_ACCESS *)
699 &i2c_record->sucI2cId;
701 radeon_lookup_i2c_gpio(rdev,
704 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
706 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
707 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
710 router.mux_type = ddc_path->ucMuxType;
711 router.mux_control_pin = ddc_path->ucMuxControlPin;
712 router.mux_state = ddc_path->ucMuxState[enum_id];
715 record = (ATOM_COMMON_RECORD_HEADER *)
716 ((char *)record + record->ucRecordSize);
723 /* look up gpio for ddc, hpd */
724 ddc_bus.valid = false;
725 hpd.hpd = RADEON_HPD_NONE;
726 if ((le16_to_cpu(path->usDeviceTag) &
727 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
728 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
729 if (le16_to_cpu(path->usConnObjectId) ==
730 le16_to_cpu(con_obj->asObjects[j].
732 ATOM_COMMON_RECORD_HEADER
734 (ATOM_COMMON_RECORD_HEADER
736 (ctx->bios + data_offset +
737 le16_to_cpu(con_obj->
740 ATOM_I2C_RECORD *i2c_record;
741 ATOM_HPD_INT_RECORD *hpd_record;
742 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
744 while (record->ucRecordType > 0
747 ATOM_MAX_OBJECT_RECORD_NUMBER) {
748 switch (record->ucRecordType) {
749 case ATOM_I2C_RECORD_TYPE:
754 (ATOM_I2C_ID_CONFIG_ACCESS *)
755 &i2c_record->sucI2cId;
756 ddc_bus = radeon_lookup_i2c_gpio(rdev,
760 case ATOM_HPD_INT_RECORD_TYPE:
762 (ATOM_HPD_INT_RECORD *)
764 gpio = radeon_lookup_gpio(rdev,
765 hpd_record->ucHPDIntGPIOID);
766 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
767 hpd.plugged_state = hpd_record->ucPlugged_PinState;
771 (ATOM_COMMON_RECORD_HEADER
782 /* needed for aux chan transactions */
783 ddc_bus.hpd = hpd.hpd;
785 conn_id = le16_to_cpu(path->usConnObjectId);
787 if (!radeon_atom_apply_quirks
788 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
789 &ddc_bus, &conn_id, &hpd))
792 radeon_add_atom_connector(dev,
796 connector_type, &ddc_bus,
805 radeon_link_encoder_connector(dev);
810 static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
814 struct radeon_device *rdev = dev->dev_private;
816 if (rdev->flags & RADEON_IS_IGP) {
817 return supported_devices_connector_object_id_convert
819 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
820 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
821 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
822 struct radeon_mode_info *mode_info = &rdev->mode_info;
823 struct atom_context *ctx = mode_info->atom_context;
824 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
825 uint16_t size, data_offset;
827 ATOM_XTMDS_INFO *xtmds;
829 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
830 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
832 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
833 if (connector_type == DRM_MODE_CONNECTOR_DVII)
834 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
836 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
838 if (connector_type == DRM_MODE_CONNECTOR_DVII)
839 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
841 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
844 return supported_devices_connector_object_id_convert
847 return supported_devices_connector_object_id_convert
852 struct bios_connector {
857 struct radeon_i2c_bus_rec ddc_bus;
858 struct radeon_hpd hpd;
861 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
865 struct radeon_device *rdev = dev->dev_private;
866 struct radeon_mode_info *mode_info = &rdev->mode_info;
867 struct atom_context *ctx = mode_info->atom_context;
868 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
869 uint16_t size, data_offset;
871 uint16_t device_support;
873 union atom_supported_devices *supported_devices;
874 int i, j, max_device;
875 struct bios_connector *bios_connectors;
876 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
877 struct radeon_router router;
879 router.valid = false;
881 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
882 if (!bios_connectors)
885 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
887 kfree(bios_connectors);
892 (union atom_supported_devices *)(ctx->bios + data_offset);
894 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
897 max_device = ATOM_MAX_SUPPORTED_DEVICE;
899 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
901 for (i = 0; i < max_device; i++) {
902 ATOM_CONNECTOR_INFO_I2C ci =
903 supported_devices->info.asConnInfo[i];
905 bios_connectors[i].valid = false;
907 if (!(device_support & (1 << i))) {
911 if (i == ATOM_DEVICE_CV_INDEX) {
912 DRM_DEBUG_KMS("Skipping Component Video\n");
916 bios_connectors[i].connector_type =
917 supported_devices_connector_convert[ci.sucConnectorInfo.
921 if (bios_connectors[i].connector_type ==
922 DRM_MODE_CONNECTOR_Unknown)
925 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
927 bios_connectors[i].line_mux =
928 ci.sucI2cId.ucAccess;
930 /* give tv unique connector ids */
931 if (i == ATOM_DEVICE_TV1_INDEX) {
932 bios_connectors[i].ddc_bus.valid = false;
933 bios_connectors[i].line_mux = 50;
934 } else if (i == ATOM_DEVICE_TV2_INDEX) {
935 bios_connectors[i].ddc_bus.valid = false;
936 bios_connectors[i].line_mux = 51;
937 } else if (i == ATOM_DEVICE_CV_INDEX) {
938 bios_connectors[i].ddc_bus.valid = false;
939 bios_connectors[i].line_mux = 52;
941 bios_connectors[i].ddc_bus =
942 radeon_lookup_i2c_gpio(rdev,
943 bios_connectors[i].line_mux);
945 if ((crev > 1) && (frev > 1)) {
946 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
949 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
952 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
955 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
959 if (i == ATOM_DEVICE_DFP1_INDEX)
960 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
961 else if (i == ATOM_DEVICE_DFP2_INDEX)
962 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
964 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
967 /* Always set the connector type to VGA for CRT1/CRT2. if they are
968 * shared with a DVI port, we'll pick up the DVI connector when we
969 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
971 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
972 bios_connectors[i].connector_type =
973 DRM_MODE_CONNECTOR_VGA;
975 if (!radeon_atom_apply_quirks
976 (dev, (1 << i), &bios_connectors[i].connector_type,
977 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
978 &bios_connectors[i].hpd))
981 bios_connectors[i].valid = true;
982 bios_connectors[i].devices = (1 << i);
984 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
985 radeon_add_atom_encoder(dev,
986 radeon_get_encoder_enum(dev,
991 radeon_add_legacy_encoder(dev,
992 radeon_get_encoder_enum(dev,
998 /* combine shared connectors */
999 for (i = 0; i < max_device; i++) {
1000 if (bios_connectors[i].valid) {
1001 for (j = 0; j < max_device; j++) {
1002 if (bios_connectors[j].valid && (i != j)) {
1003 if (bios_connectors[i].line_mux ==
1004 bios_connectors[j].line_mux) {
1005 /* make sure not to combine LVDS */
1006 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1007 bios_connectors[i].line_mux = 53;
1008 bios_connectors[i].ddc_bus.valid = false;
1011 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1012 bios_connectors[j].line_mux = 53;
1013 bios_connectors[j].ddc_bus.valid = false;
1016 /* combine analog and digital for DVI-I */
1017 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1018 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
1019 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1020 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
1021 bios_connectors[i].devices |=
1022 bios_connectors[j].devices;
1023 bios_connectors[i].connector_type =
1024 DRM_MODE_CONNECTOR_DVII;
1025 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
1026 bios_connectors[i].hpd =
1027 bios_connectors[j].hpd;
1028 bios_connectors[j].valid = false;
1036 /* add the connectors */
1037 for (i = 0; i < max_device; i++) {
1038 if (bios_connectors[i].valid) {
1039 uint16_t connector_object_id =
1040 atombios_get_connector_object_id(dev,
1041 bios_connectors[i].connector_type,
1042 bios_connectors[i].devices);
1043 radeon_add_atom_connector(dev,
1044 bios_connectors[i].line_mux,
1045 bios_connectors[i].devices,
1048 &bios_connectors[i].ddc_bus,
1050 connector_object_id,
1051 &bios_connectors[i].hpd,
1056 radeon_link_encoder_connector(dev);
1058 kfree(bios_connectors);
1062 union firmware_info {
1063 ATOM_FIRMWARE_INFO info;
1064 ATOM_FIRMWARE_INFO_V1_2 info_12;
1065 ATOM_FIRMWARE_INFO_V1_3 info_13;
1066 ATOM_FIRMWARE_INFO_V1_4 info_14;
1067 ATOM_FIRMWARE_INFO_V2_1 info_21;
1070 bool radeon_atom_get_clock_info(struct drm_device *dev)
1072 struct radeon_device *rdev = dev->dev_private;
1073 struct radeon_mode_info *mode_info = &rdev->mode_info;
1074 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1075 union firmware_info *firmware_info;
1077 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1078 struct radeon_pll *p2pll = &rdev->clock.p2pll;
1079 struct radeon_pll *dcpll = &rdev->clock.dcpll;
1080 struct radeon_pll *spll = &rdev->clock.spll;
1081 struct radeon_pll *mpll = &rdev->clock.mpll;
1082 uint16_t data_offset;
1084 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1085 &frev, &crev, &data_offset)) {
1087 (union firmware_info *)(mode_info->atom_context->bios +
1090 p1pll->reference_freq =
1091 le16_to_cpu(firmware_info->info.usReferenceClock);
1092 p1pll->reference_div = 0;
1095 p1pll->pll_out_min =
1096 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1098 p1pll->pll_out_min =
1099 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
1100 p1pll->pll_out_max =
1101 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1104 p1pll->lcd_pll_out_min =
1105 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1106 if (p1pll->lcd_pll_out_min == 0)
1107 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1108 p1pll->lcd_pll_out_max =
1109 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1110 if (p1pll->lcd_pll_out_max == 0)
1111 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1113 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1114 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1117 if (p1pll->pll_out_min == 0) {
1118 if (ASIC_IS_AVIVO(rdev))
1119 p1pll->pll_out_min = 64800;
1121 p1pll->pll_out_min = 20000;
1122 } else if (p1pll->pll_out_min > 64800) {
1123 /* Limiting the pll output range is a good thing generally as
1124 * it limits the number of possible pll combinations for a given
1125 * frequency presumably to the ones that work best on each card.
1126 * However, certain duallink DVI monitors seem to like
1127 * pll combinations that would be limited by this at least on
1128 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
1131 if (!radeon_new_pll)
1132 p1pll->pll_out_min = 64800;
1136 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1138 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1143 spll->reference_freq =
1144 le16_to_cpu(firmware_info->info.usReferenceClock);
1145 spll->reference_div = 0;
1148 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1150 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1153 if (spll->pll_out_min == 0) {
1154 if (ASIC_IS_AVIVO(rdev))
1155 spll->pll_out_min = 64800;
1157 spll->pll_out_min = 20000;
1161 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1163 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1166 mpll->reference_freq =
1167 le16_to_cpu(firmware_info->info.usReferenceClock);
1168 mpll->reference_div = 0;
1171 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1173 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1176 if (mpll->pll_out_min == 0) {
1177 if (ASIC_IS_AVIVO(rdev))
1178 mpll->pll_out_min = 64800;
1180 mpll->pll_out_min = 20000;
1184 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1186 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1188 rdev->clock.default_sclk =
1189 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1190 rdev->clock.default_mclk =
1191 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1193 if (ASIC_IS_DCE4(rdev)) {
1194 rdev->clock.default_dispclk =
1195 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
1196 if (rdev->clock.default_dispclk == 0)
1197 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1198 rdev->clock.dp_extclk =
1199 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
1210 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1211 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1214 bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1216 struct radeon_mode_info *mode_info = &rdev->mode_info;
1217 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1218 union igp_info *igp_info;
1222 /* sideport is AMD only */
1223 if (rdev->family == CHIP_RS600)
1226 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1227 &frev, &crev, &data_offset)) {
1228 igp_info = (union igp_info *)(mode_info->atom_context->bios +
1232 if (igp_info->info.ulBootUpMemoryClock)
1236 if (igp_info->info_2.ulBootUpSidePortClock)
1240 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1247 bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1248 struct radeon_encoder_int_tmds *tmds)
1250 struct drm_device *dev = encoder->base.dev;
1251 struct radeon_device *rdev = dev->dev_private;
1252 struct radeon_mode_info *mode_info = &rdev->mode_info;
1253 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1254 uint16_t data_offset;
1255 struct _ATOM_TMDS_INFO *tmds_info;
1260 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1261 &frev, &crev, &data_offset)) {
1263 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1266 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1267 for (i = 0; i < 4; i++) {
1268 tmds->tmds_pll[i].freq =
1269 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1270 tmds->tmds_pll[i].value =
1271 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1272 tmds->tmds_pll[i].value |=
1273 (tmds_info->asMiscInfo[i].
1274 ucPLL_VCO_Gain & 0x3f) << 6;
1275 tmds->tmds_pll[i].value |=
1276 (tmds_info->asMiscInfo[i].
1277 ucPLL_DutyCycle & 0xf) << 12;
1278 tmds->tmds_pll[i].value |=
1279 (tmds_info->asMiscInfo[i].
1280 ucPLL_VoltageSwing & 0xf) << 16;
1282 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
1283 tmds->tmds_pll[i].freq,
1284 tmds->tmds_pll[i].value);
1286 if (maxfreq == tmds->tmds_pll[i].freq) {
1287 tmds->tmds_pll[i].freq = 0xffffffff;
1296 static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
1301 struct drm_device *dev = encoder->base.dev;
1302 struct radeon_device *rdev = dev->dev_private;
1303 struct radeon_mode_info *mode_info = &rdev->mode_info;
1304 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
1305 uint16_t data_offset;
1306 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1308 struct radeon_atom_ss *ss = NULL;
1311 if (id > ATOM_MAX_SS_ENTRY)
1314 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1315 &frev, &crev, &data_offset)) {
1317 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
1320 kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
1325 for (i = 0; i < ATOM_MAX_SS_ENTRY; i++) {
1326 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1328 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1329 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1330 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1331 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1332 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1333 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
1342 struct _ATOM_LVDS_INFO info;
1343 struct _ATOM_LVDS_INFO_V12 info_12;
1346 struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1350 struct drm_device *dev = encoder->base.dev;
1351 struct radeon_device *rdev = dev->dev_private;
1352 struct radeon_mode_info *mode_info = &rdev->mode_info;
1353 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
1354 uint16_t data_offset, misc;
1355 union lvds_info *lvds_info;
1357 struct radeon_encoder_atom_dig *lvds = NULL;
1358 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
1360 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1361 &frev, &crev, &data_offset)) {
1363 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
1365 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1370 lvds->native_mode.clock =
1371 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
1372 lvds->native_mode.hdisplay =
1373 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
1374 lvds->native_mode.vdisplay =
1375 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
1376 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1377 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1378 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1379 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1380 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1381 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1382 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1383 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1384 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1385 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
1386 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1387 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
1388 lvds->panel_pwr_delay =
1389 le16_to_cpu(lvds_info->info.usOffDelayInMs);
1390 lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
1392 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1393 if (misc & ATOM_VSYNC_POLARITY)
1394 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1395 if (misc & ATOM_HSYNC_POLARITY)
1396 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1397 if (misc & ATOM_COMPOSITESYNC)
1398 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1399 if (misc & ATOM_INTERLACE)
1400 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1401 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1402 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1404 /* set crtc values */
1405 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
1407 lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
1409 if (ASIC_IS_AVIVO(rdev)) {
1410 if (radeon_new_pll == 0)
1411 lvds->pll_algo = PLL_ALGO_LEGACY;
1413 lvds->pll_algo = PLL_ALGO_NEW;
1415 if (radeon_new_pll == 1)
1416 lvds->pll_algo = PLL_ALGO_NEW;
1418 lvds->pll_algo = PLL_ALGO_LEGACY;
1421 encoder->native_mode = lvds->native_mode;
1423 if (encoder_enum == 2)
1426 lvds->linkb = false;
1432 struct radeon_encoder_primary_dac *
1433 radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1435 struct drm_device *dev = encoder->base.dev;
1436 struct radeon_device *rdev = dev->dev_private;
1437 struct radeon_mode_info *mode_info = &rdev->mode_info;
1438 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1439 uint16_t data_offset;
1440 struct _COMPASSIONATE_DATA *dac_info;
1443 struct radeon_encoder_primary_dac *p_dac = NULL;
1445 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1446 &frev, &crev, &data_offset)) {
1447 dac_info = (struct _COMPASSIONATE_DATA *)
1448 (mode_info->atom_context->bios + data_offset);
1450 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1455 bg = dac_info->ucDAC1_BG_Adjustment;
1456 dac = dac_info->ucDAC1_DAC_Adjustment;
1457 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1463 bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
1464 struct drm_display_mode *mode)
1466 struct radeon_mode_info *mode_info = &rdev->mode_info;
1467 ATOM_ANALOG_TV_INFO *tv_info;
1468 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1469 ATOM_DTD_FORMAT *dtd_timings;
1470 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1472 u16 data_offset, misc;
1474 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1475 &frev, &crev, &data_offset))
1480 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1481 if (index >= MAX_SUPPORTED_TV_TIMING)
1484 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1485 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1486 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1487 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1488 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
1490 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1491 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1492 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1493 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1494 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
1497 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1498 if (misc & ATOM_VSYNC_POLARITY)
1499 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1500 if (misc & ATOM_HSYNC_POLARITY)
1501 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1502 if (misc & ATOM_COMPOSITESYNC)
1503 mode->flags |= DRM_MODE_FLAG_CSYNC;
1504 if (misc & ATOM_INTERLACE)
1505 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1506 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1507 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1509 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
1512 /* PAL timings appear to have wrong values for totals */
1513 mode->crtc_htotal -= 1;
1514 mode->crtc_vtotal -= 1;
1518 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
1519 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
1522 dtd_timings = &tv_info_v1_2->aModeTimings[index];
1523 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1524 le16_to_cpu(dtd_timings->usHBlanking_Time);
1525 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1526 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1527 le16_to_cpu(dtd_timings->usHSyncOffset);
1528 mode->crtc_hsync_end = mode->crtc_hsync_start +
1529 le16_to_cpu(dtd_timings->usHSyncWidth);
1531 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1532 le16_to_cpu(dtd_timings->usVBlanking_Time);
1533 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1534 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1535 le16_to_cpu(dtd_timings->usVSyncOffset);
1536 mode->crtc_vsync_end = mode->crtc_vsync_start +
1537 le16_to_cpu(dtd_timings->usVSyncWidth);
1540 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1541 if (misc & ATOM_VSYNC_POLARITY)
1542 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1543 if (misc & ATOM_HSYNC_POLARITY)
1544 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1545 if (misc & ATOM_COMPOSITESYNC)
1546 mode->flags |= DRM_MODE_FLAG_CSYNC;
1547 if (misc & ATOM_INTERLACE)
1548 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1549 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1550 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1552 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
1559 radeon_atombios_get_tv_info(struct radeon_device *rdev)
1561 struct radeon_mode_info *mode_info = &rdev->mode_info;
1562 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1563 uint16_t data_offset;
1565 struct _ATOM_ANALOG_TV_INFO *tv_info;
1566 enum radeon_tv_std tv_std = TV_STD_NTSC;
1568 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1569 &frev, &crev, &data_offset)) {
1571 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1572 (mode_info->atom_context->bios + data_offset);
1574 switch (tv_info->ucTV_BootUpDefaultStandard) {
1576 tv_std = TV_STD_NTSC;
1577 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
1580 tv_std = TV_STD_NTSC_J;
1581 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
1584 tv_std = TV_STD_PAL;
1585 DRM_DEBUG_KMS("Default TV standard: PAL\n");
1588 tv_std = TV_STD_PAL_M;
1589 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
1592 tv_std = TV_STD_PAL_N;
1593 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
1596 tv_std = TV_STD_PAL_CN;
1597 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
1600 tv_std = TV_STD_PAL_60;
1601 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
1604 tv_std = TV_STD_SECAM;
1605 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
1608 tv_std = TV_STD_NTSC;
1609 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
1616 struct radeon_encoder_tv_dac *
1617 radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1619 struct drm_device *dev = encoder->base.dev;
1620 struct radeon_device *rdev = dev->dev_private;
1621 struct radeon_mode_info *mode_info = &rdev->mode_info;
1622 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1623 uint16_t data_offset;
1624 struct _COMPASSIONATE_DATA *dac_info;
1627 struct radeon_encoder_tv_dac *tv_dac = NULL;
1629 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1630 &frev, &crev, &data_offset)) {
1632 dac_info = (struct _COMPASSIONATE_DATA *)
1633 (mode_info->atom_context->bios + data_offset);
1635 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1640 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1641 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1642 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1644 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1645 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1646 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1648 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1649 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1650 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1652 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
1657 static const char *thermal_controller_names[] = {
1668 static const char *pp_lib_thermal_controller_names[] = {
1681 "adt7473 with internal",
1686 struct _ATOM_POWERPLAY_INFO info;
1687 struct _ATOM_POWERPLAY_INFO_V2 info_2;
1688 struct _ATOM_POWERPLAY_INFO_V3 info_3;
1689 struct _ATOM_PPLIB_POWERPLAYTABLE info_4;
1692 void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1694 struct radeon_mode_info *mode_info = &rdev->mode_info;
1695 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
1698 u32 misc, misc2 = 0, sclk, mclk;
1699 union power_info *power_info;
1700 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
1701 struct _ATOM_PPLIB_STATE *power_state;
1702 int num_modes = 0, i, j;
1703 int state_index = 0, mode_index = 0;
1704 struct radeon_i2c_bus_rec i2c_bus;
1706 rdev->pm.default_power_state_index = -1;
1708 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1709 &frev, &crev, &data_offset)) {
1710 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
1712 /* add the i2c bus for thermal/fan chip */
1713 if (power_info->info.ucOverdriveThermalController > 0) {
1714 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
1715 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1716 power_info->info.ucOverdriveControllerAddress >> 1);
1717 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
1718 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1719 if (rdev->pm.i2c_bus) {
1720 struct i2c_board_info info = { };
1721 const char *name = thermal_controller_names[power_info->info.
1722 ucOverdriveThermalController];
1723 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
1724 strlcpy(info.type, name, sizeof(info.type));
1725 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
1728 num_modes = power_info->info.ucNumOfPowerModeEntries;
1729 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
1730 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
1731 /* last mode is usually default, array is low to high */
1732 for (i = 0; i < num_modes; i++) {
1733 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
1736 rdev->pm.power_state[state_index].num_clock_modes = 1;
1737 rdev->pm.power_state[state_index].clock_info[0].mclk =
1738 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
1739 rdev->pm.power_state[state_index].clock_info[0].sclk =
1740 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
1741 /* skip invalid modes */
1742 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1743 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1745 rdev->pm.power_state[state_index].pcie_lanes =
1746 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
1747 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
1748 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1749 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
1750 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1752 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1753 radeon_lookup_gpio(rdev,
1754 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
1755 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1756 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1759 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1761 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1762 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1764 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1765 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
1767 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1768 rdev->pm.power_state[state_index].misc = misc;
1769 /* order matters! */
1770 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1771 rdev->pm.power_state[state_index].type =
1772 POWER_STATE_TYPE_POWERSAVE;
1773 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1774 rdev->pm.power_state[state_index].type =
1775 POWER_STATE_TYPE_BATTERY;
1776 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1777 rdev->pm.power_state[state_index].type =
1778 POWER_STATE_TYPE_BATTERY;
1779 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1780 rdev->pm.power_state[state_index].type =
1781 POWER_STATE_TYPE_BALANCED;
1782 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
1783 rdev->pm.power_state[state_index].type =
1784 POWER_STATE_TYPE_PERFORMANCE;
1785 rdev->pm.power_state[state_index].flags &=
1786 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1788 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
1789 rdev->pm.power_state[state_index].type =
1790 POWER_STATE_TYPE_DEFAULT;
1791 rdev->pm.default_power_state_index = state_index;
1792 rdev->pm.power_state[state_index].default_clock_mode =
1793 &rdev->pm.power_state[state_index].clock_info[0];
1794 rdev->pm.power_state[state_index].flags &=
1795 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1796 } else if (state_index == 0) {
1797 rdev->pm.power_state[state_index].clock_info[0].flags |=
1798 RADEON_PM_MODE_NO_DISPLAY;
1803 rdev->pm.power_state[state_index].num_clock_modes = 1;
1804 rdev->pm.power_state[state_index].clock_info[0].mclk =
1805 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
1806 rdev->pm.power_state[state_index].clock_info[0].sclk =
1807 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
1808 /* skip invalid modes */
1809 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1810 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1812 rdev->pm.power_state[state_index].pcie_lanes =
1813 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
1814 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
1815 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
1816 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1817 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
1818 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1820 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1821 radeon_lookup_gpio(rdev,
1822 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
1823 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1824 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1827 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1829 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1830 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1832 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1833 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
1835 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1836 rdev->pm.power_state[state_index].misc = misc;
1837 rdev->pm.power_state[state_index].misc2 = misc2;
1838 /* order matters! */
1839 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1840 rdev->pm.power_state[state_index].type =
1841 POWER_STATE_TYPE_POWERSAVE;
1842 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1843 rdev->pm.power_state[state_index].type =
1844 POWER_STATE_TYPE_BATTERY;
1845 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1846 rdev->pm.power_state[state_index].type =
1847 POWER_STATE_TYPE_BATTERY;
1848 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1849 rdev->pm.power_state[state_index].type =
1850 POWER_STATE_TYPE_BALANCED;
1851 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
1852 rdev->pm.power_state[state_index].type =
1853 POWER_STATE_TYPE_PERFORMANCE;
1854 rdev->pm.power_state[state_index].flags &=
1855 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1857 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1858 rdev->pm.power_state[state_index].type =
1859 POWER_STATE_TYPE_BALANCED;
1860 if (misc2 & ATOM_PM_MISCINFO2_MULTI_DISPLAY_SUPPORT)
1861 rdev->pm.power_state[state_index].flags &=
1862 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1863 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
1864 rdev->pm.power_state[state_index].type =
1865 POWER_STATE_TYPE_DEFAULT;
1866 rdev->pm.default_power_state_index = state_index;
1867 rdev->pm.power_state[state_index].default_clock_mode =
1868 &rdev->pm.power_state[state_index].clock_info[0];
1869 rdev->pm.power_state[state_index].flags &=
1870 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1871 } else if (state_index == 0) {
1872 rdev->pm.power_state[state_index].clock_info[0].flags |=
1873 RADEON_PM_MODE_NO_DISPLAY;
1878 rdev->pm.power_state[state_index].num_clock_modes = 1;
1879 rdev->pm.power_state[state_index].clock_info[0].mclk =
1880 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
1881 rdev->pm.power_state[state_index].clock_info[0].sclk =
1882 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
1883 /* skip invalid modes */
1884 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1885 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1887 rdev->pm.power_state[state_index].pcie_lanes =
1888 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
1889 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
1890 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
1891 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1892 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
1893 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1895 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1896 radeon_lookup_gpio(rdev,
1897 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
1898 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1899 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1902 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1904 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1905 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1907 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1908 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
1909 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
1910 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
1912 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
1913 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
1916 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1917 rdev->pm.power_state[state_index].misc = misc;
1918 rdev->pm.power_state[state_index].misc2 = misc2;
1919 /* order matters! */
1920 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1921 rdev->pm.power_state[state_index].type =
1922 POWER_STATE_TYPE_POWERSAVE;
1923 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1924 rdev->pm.power_state[state_index].type =
1925 POWER_STATE_TYPE_BATTERY;
1926 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1927 rdev->pm.power_state[state_index].type =
1928 POWER_STATE_TYPE_BATTERY;
1929 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1930 rdev->pm.power_state[state_index].type =
1931 POWER_STATE_TYPE_BALANCED;
1932 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
1933 rdev->pm.power_state[state_index].type =
1934 POWER_STATE_TYPE_PERFORMANCE;
1935 rdev->pm.power_state[state_index].flags &=
1936 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1938 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1939 rdev->pm.power_state[state_index].type =
1940 POWER_STATE_TYPE_BALANCED;
1941 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
1942 rdev->pm.power_state[state_index].type =
1943 POWER_STATE_TYPE_DEFAULT;
1944 rdev->pm.default_power_state_index = state_index;
1945 rdev->pm.power_state[state_index].default_clock_mode =
1946 &rdev->pm.power_state[state_index].clock_info[0];
1947 } else if (state_index == 0) {
1948 rdev->pm.power_state[state_index].clock_info[0].flags |=
1949 RADEON_PM_MODE_NO_DISPLAY;
1955 /* last mode is usually default */
1956 if (rdev->pm.default_power_state_index == -1) {
1957 rdev->pm.power_state[state_index - 1].type =
1958 POWER_STATE_TYPE_DEFAULT;
1959 rdev->pm.default_power_state_index = state_index - 1;
1960 rdev->pm.power_state[state_index - 1].default_clock_mode =
1961 &rdev->pm.power_state[state_index - 1].clock_info[0];
1962 rdev->pm.power_state[state_index].flags &=
1963 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1964 rdev->pm.power_state[state_index].misc = 0;
1965 rdev->pm.power_state[state_index].misc2 = 0;
1968 int fw_index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1969 uint8_t fw_frev, fw_crev;
1970 uint16_t fw_data_offset, vddc = 0;
1971 union firmware_info *firmware_info;
1972 ATOM_PPLIB_THERMALCONTROLLER *controller = &power_info->info_4.sThermalController;
1974 if (atom_parse_data_header(mode_info->atom_context, fw_index, NULL,
1975 &fw_frev, &fw_crev, &fw_data_offset)) {
1977 (union firmware_info *)(mode_info->atom_context->bios +
1979 vddc = firmware_info->info_14.usBootUpVDDCVoltage;
1982 /* add the i2c bus for thermal/fan chip */
1983 if (controller->ucType > 0) {
1984 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
1985 DRM_INFO("Internal thermal controller %s fan control\n",
1986 (controller->ucFanParameters &
1987 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
1988 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
1989 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
1990 DRM_INFO("Internal thermal controller %s fan control\n",
1991 (controller->ucFanParameters &
1992 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
1993 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
1994 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
1995 DRM_INFO("Internal thermal controller %s fan control\n",
1996 (controller->ucFanParameters &
1997 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
1998 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
1999 } else if ((controller->ucType ==
2000 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
2001 (controller->ucType ==
2002 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL)) {
2003 DRM_INFO("Special thermal controller config\n");
2005 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2006 pp_lib_thermal_controller_names[controller->ucType],
2007 controller->ucI2cAddress >> 1,
2008 (controller->ucFanParameters &
2009 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2010 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
2011 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2012 if (rdev->pm.i2c_bus) {
2013 struct i2c_board_info info = { };
2014 const char *name = pp_lib_thermal_controller_names[controller->ucType];
2015 info.addr = controller->ucI2cAddress >> 1;
2016 strlcpy(info.type, name, sizeof(info.type));
2017 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2022 /* first mode is usually default, followed by low to high */
2023 for (i = 0; i < power_info->info_4.ucNumStates; i++) {
2025 power_state = (struct _ATOM_PPLIB_STATE *)
2026 (mode_info->atom_context->bios +
2028 le16_to_cpu(power_info->info_4.usStateArrayOffset) +
2029 i * power_info->info_4.ucStateEntrySize);
2030 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2031 (mode_info->atom_context->bios +
2033 le16_to_cpu(power_info->info_4.usNonClockInfoArrayOffset) +
2034 (power_state->ucNonClockStateIndex *
2035 power_info->info_4.ucNonClockSize));
2036 for (j = 0; j < (power_info->info_4.ucStateEntrySize - 1); j++) {
2037 if (rdev->flags & RADEON_IS_IGP) {
2038 struct _ATOM_PPLIB_RS780_CLOCK_INFO *clock_info =
2039 (struct _ATOM_PPLIB_RS780_CLOCK_INFO *)
2040 (mode_info->atom_context->bios +
2042 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2043 (power_state->ucClockStateIndices[j] *
2044 power_info->info_4.ucClockInfoSize));
2045 sclk = le16_to_cpu(clock_info->usLowEngineClockLow);
2046 sclk |= clock_info->ucLowEngineClockHigh << 16;
2047 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2048 /* skip invalid modes */
2049 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2051 /* voltage works differently on IGPs */
2053 } else if (ASIC_IS_DCE4(rdev)) {
2054 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *clock_info =
2055 (struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *)
2056 (mode_info->atom_context->bios +
2058 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2059 (power_state->ucClockStateIndices[j] *
2060 power_info->info_4.ucClockInfoSize));
2061 sclk = le16_to_cpu(clock_info->usEngineClockLow);
2062 sclk |= clock_info->ucEngineClockHigh << 16;
2063 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
2064 mclk |= clock_info->ucMemoryClockHigh << 16;
2065 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2066 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2067 /* skip invalid modes */
2068 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2069 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2071 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2073 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2078 struct _ATOM_PPLIB_R600_CLOCK_INFO *clock_info =
2079 (struct _ATOM_PPLIB_R600_CLOCK_INFO *)
2080 (mode_info->atom_context->bios +
2082 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2083 (power_state->ucClockStateIndices[j] *
2084 power_info->info_4.ucClockInfoSize));
2085 sclk = le16_to_cpu(clock_info->usEngineClockLow);
2086 sclk |= clock_info->ucEngineClockHigh << 16;
2087 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
2088 mclk |= clock_info->ucMemoryClockHigh << 16;
2089 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2090 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2091 /* skip invalid modes */
2092 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2093 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2095 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2097 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2102 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2104 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
2105 misc2 = le16_to_cpu(non_clock_info->usClassification);
2106 rdev->pm.power_state[state_index].misc = misc;
2107 rdev->pm.power_state[state_index].misc2 = misc2;
2108 rdev->pm.power_state[state_index].pcie_lanes =
2109 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2110 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2111 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2112 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2113 rdev->pm.power_state[state_index].type =
2114 POWER_STATE_TYPE_BATTERY;
2116 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2117 rdev->pm.power_state[state_index].type =
2118 POWER_STATE_TYPE_BALANCED;
2120 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2121 rdev->pm.power_state[state_index].type =
2122 POWER_STATE_TYPE_PERFORMANCE;
2124 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2125 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2126 rdev->pm.power_state[state_index].type =
2127 POWER_STATE_TYPE_PERFORMANCE;
2130 rdev->pm.power_state[state_index].flags = 0;
2131 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2132 rdev->pm.power_state[state_index].flags |=
2133 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2134 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
2135 rdev->pm.power_state[state_index].type =
2136 POWER_STATE_TYPE_DEFAULT;
2137 rdev->pm.default_power_state_index = state_index;
2138 rdev->pm.power_state[state_index].default_clock_mode =
2139 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
2140 /* patch the table values with the default slck/mclk from firmware info */
2141 for (j = 0; j < mode_index; j++) {
2142 rdev->pm.power_state[state_index].clock_info[j].mclk =
2143 rdev->clock.default_mclk;
2144 rdev->pm.power_state[state_index].clock_info[j].sclk =
2145 rdev->clock.default_sclk;
2147 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2154 /* if multiple clock modes, mark the lowest as no display */
2155 for (i = 0; i < state_index; i++) {
2156 if (rdev->pm.power_state[i].num_clock_modes > 1)
2157 rdev->pm.power_state[i].clock_info[0].flags |=
2158 RADEON_PM_MODE_NO_DISPLAY;
2160 /* first mode is usually default */
2161 if (rdev->pm.default_power_state_index == -1) {
2162 rdev->pm.power_state[0].type =
2163 POWER_STATE_TYPE_DEFAULT;
2164 rdev->pm.default_power_state_index = 0;
2165 rdev->pm.power_state[0].default_clock_mode =
2166 &rdev->pm.power_state[0].clock_info[0];
2170 /* add the default mode */
2171 rdev->pm.power_state[state_index].type =
2172 POWER_STATE_TYPE_DEFAULT;
2173 rdev->pm.power_state[state_index].num_clock_modes = 1;
2174 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2175 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2176 rdev->pm.power_state[state_index].default_clock_mode =
2177 &rdev->pm.power_state[state_index].clock_info[0];
2178 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2179 rdev->pm.power_state[state_index].pcie_lanes = 16;
2180 rdev->pm.default_power_state_index = state_index;
2181 rdev->pm.power_state[state_index].flags = 0;
2185 rdev->pm.num_power_states = state_index;
2187 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2188 rdev->pm.current_clock_mode_index = 0;
2189 rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
2192 void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2194 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2195 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2197 args.ucEnable = enable;
2199 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2202 uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2204 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2205 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2207 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2208 return args.ulReturnEngineClock;
2211 uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2213 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2214 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2216 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2217 return args.ulReturnMemoryClock;
2220 void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2223 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2224 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2226 args.ulTargetEngineClock = eng_clock; /* 10 khz */
2228 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2231 void radeon_atom_set_memory_clock(struct radeon_device *rdev,
2234 SET_MEMORY_CLOCK_PS_ALLOCATION args;
2235 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
2237 if (rdev->flags & RADEON_IS_IGP)
2240 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
2242 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2246 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2247 struct _SET_VOLTAGE_PARAMETERS v1;
2248 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2251 void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level)
2253 union set_voltage args;
2254 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
2255 u8 frev, crev, volt_index = level;
2257 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2262 args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2263 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
2264 args.v1.ucVoltageIndex = volt_index;
2267 args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2268 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
2269 args.v2.usVoltageLevel = cpu_to_le16(level);
2272 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2276 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2281 void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
2283 struct radeon_device *rdev = dev->dev_private;
2284 uint32_t bios_2_scratch, bios_6_scratch;
2286 if (rdev->family >= CHIP_R600) {
2287 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2288 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2290 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
2291 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2294 /* let the bios control the backlight */
2295 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
2297 /* tell the bios not to handle mode switching */
2298 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
2300 if (rdev->family >= CHIP_R600) {
2301 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2302 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2304 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2305 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2310 void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
2312 uint32_t scratch_reg;
2315 if (rdev->family >= CHIP_R600)
2316 scratch_reg = R600_BIOS_0_SCRATCH;
2318 scratch_reg = RADEON_BIOS_0_SCRATCH;
2320 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2321 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
2324 void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
2326 uint32_t scratch_reg;
2329 if (rdev->family >= CHIP_R600)
2330 scratch_reg = R600_BIOS_0_SCRATCH;
2332 scratch_reg = RADEON_BIOS_0_SCRATCH;
2334 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2335 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
2338 void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
2340 struct drm_device *dev = encoder->dev;
2341 struct radeon_device *rdev = dev->dev_private;
2342 uint32_t bios_6_scratch;
2344 if (rdev->family >= CHIP_R600)
2345 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2347 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2350 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
2352 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
2354 if (rdev->family >= CHIP_R600)
2355 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2357 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2360 /* at some point we may want to break this out into individual functions */
2362 radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
2363 struct drm_encoder *encoder,
2366 struct drm_device *dev = connector->dev;
2367 struct radeon_device *rdev = dev->dev_private;
2368 struct radeon_connector *radeon_connector =
2369 to_radeon_connector(connector);
2370 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2371 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
2373 if (rdev->family >= CHIP_R600) {
2374 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2375 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2376 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2378 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2379 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2380 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2383 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
2384 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
2386 DRM_DEBUG_KMS("TV1 connected\n");
2387 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
2388 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
2390 DRM_DEBUG_KMS("TV1 disconnected\n");
2391 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
2392 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
2393 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
2396 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
2397 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
2399 DRM_DEBUG_KMS("CV connected\n");
2400 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
2401 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
2403 DRM_DEBUG_KMS("CV disconnected\n");
2404 bios_0_scratch &= ~ATOM_S0_CV_MASK;
2405 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
2406 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
2409 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
2410 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
2412 DRM_DEBUG_KMS("LCD1 connected\n");
2413 bios_0_scratch |= ATOM_S0_LCD1;
2414 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
2415 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
2417 DRM_DEBUG_KMS("LCD1 disconnected\n");
2418 bios_0_scratch &= ~ATOM_S0_LCD1;
2419 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
2420 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
2423 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
2424 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
2426 DRM_DEBUG_KMS("CRT1 connected\n");
2427 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
2428 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
2429 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
2431 DRM_DEBUG_KMS("CRT1 disconnected\n");
2432 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
2433 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
2434 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
2437 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
2438 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
2440 DRM_DEBUG_KMS("CRT2 connected\n");
2441 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
2442 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
2443 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
2445 DRM_DEBUG_KMS("CRT2 disconnected\n");
2446 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
2447 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
2448 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
2451 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
2452 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
2454 DRM_DEBUG_KMS("DFP1 connected\n");
2455 bios_0_scratch |= ATOM_S0_DFP1;
2456 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
2457 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
2459 DRM_DEBUG_KMS("DFP1 disconnected\n");
2460 bios_0_scratch &= ~ATOM_S0_DFP1;
2461 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
2462 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
2465 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
2466 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
2468 DRM_DEBUG_KMS("DFP2 connected\n");
2469 bios_0_scratch |= ATOM_S0_DFP2;
2470 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
2471 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
2473 DRM_DEBUG_KMS("DFP2 disconnected\n");
2474 bios_0_scratch &= ~ATOM_S0_DFP2;
2475 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
2476 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
2479 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
2480 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
2482 DRM_DEBUG_KMS("DFP3 connected\n");
2483 bios_0_scratch |= ATOM_S0_DFP3;
2484 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
2485 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
2487 DRM_DEBUG_KMS("DFP3 disconnected\n");
2488 bios_0_scratch &= ~ATOM_S0_DFP3;
2489 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
2490 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
2493 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
2494 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
2496 DRM_DEBUG_KMS("DFP4 connected\n");
2497 bios_0_scratch |= ATOM_S0_DFP4;
2498 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
2499 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
2501 DRM_DEBUG_KMS("DFP4 disconnected\n");
2502 bios_0_scratch &= ~ATOM_S0_DFP4;
2503 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
2504 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
2507 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
2508 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
2510 DRM_DEBUG_KMS("DFP5 connected\n");
2511 bios_0_scratch |= ATOM_S0_DFP5;
2512 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
2513 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
2515 DRM_DEBUG_KMS("DFP5 disconnected\n");
2516 bios_0_scratch &= ~ATOM_S0_DFP5;
2517 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2518 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2522 if (rdev->family >= CHIP_R600) {
2523 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2524 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2525 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2527 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
2528 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2529 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2534 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
2536 struct drm_device *dev = encoder->dev;
2537 struct radeon_device *rdev = dev->dev_private;
2538 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2539 uint32_t bios_3_scratch;
2541 if (rdev->family >= CHIP_R600)
2542 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2544 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2546 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2547 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
2548 bios_3_scratch |= (crtc << 18);
2550 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2551 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
2552 bios_3_scratch |= (crtc << 24);
2554 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2555 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
2556 bios_3_scratch |= (crtc << 16);
2558 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2559 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
2560 bios_3_scratch |= (crtc << 20);
2562 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2563 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
2564 bios_3_scratch |= (crtc << 17);
2566 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2567 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
2568 bios_3_scratch |= (crtc << 19);
2570 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2571 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
2572 bios_3_scratch |= (crtc << 23);
2574 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2575 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
2576 bios_3_scratch |= (crtc << 25);
2579 if (rdev->family >= CHIP_R600)
2580 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2582 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2586 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
2588 struct drm_device *dev = encoder->dev;
2589 struct radeon_device *rdev = dev->dev_private;
2590 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2591 uint32_t bios_2_scratch;
2593 if (rdev->family >= CHIP_R600)
2594 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2596 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
2598 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2600 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
2602 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
2604 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2606 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
2608 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
2610 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2612 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
2614 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
2616 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2618 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
2620 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
2622 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2624 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
2626 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
2628 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2630 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
2632 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
2634 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2636 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
2638 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
2640 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2642 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
2644 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
2646 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
2648 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
2650 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
2652 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
2654 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
2656 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
2659 if (rdev->family >= CHIP_R600)
2660 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2662 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);