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)
317 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
318 if ((dev->pdev->device == 0x791e) &&
319 (dev->pdev->subsystem_vendor == 0x1043) &&
320 (dev->pdev->subsystem_device == 0x826d)) {
321 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
322 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
323 *connector_type = DRM_MODE_CONNECTOR_DVID;
326 /* Asrock RS600 board lists the DVI port as HDMI */
327 if ((dev->pdev->device == 0x7941) &&
328 (dev->pdev->subsystem_vendor == 0x1849) &&
329 (dev->pdev->subsystem_device == 0x7941)) {
330 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
331 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
332 *connector_type = DRM_MODE_CONNECTOR_DVID;
335 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
336 if ((dev->pdev->device == 0x796e) &&
337 (dev->pdev->subsystem_vendor == 0x1462) &&
338 (dev->pdev->subsystem_device == 0x7302)) {
339 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
340 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
344 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
345 if ((dev->pdev->device == 0x7941) &&
346 (dev->pdev->subsystem_vendor == 0x147b) &&
347 (dev->pdev->subsystem_device == 0x2412)) {
348 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
352 /* Falcon NW laptop lists vga ddc line for LVDS */
353 if ((dev->pdev->device == 0x5653) &&
354 (dev->pdev->subsystem_vendor == 0x1462) &&
355 (dev->pdev->subsystem_device == 0x0291)) {
356 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
357 i2c_bus->valid = false;
362 /* HIS X1300 is DVI+VGA, not DVI+DVI */
363 if ((dev->pdev->device == 0x7146) &&
364 (dev->pdev->subsystem_vendor == 0x17af) &&
365 (dev->pdev->subsystem_device == 0x2058)) {
366 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
370 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
371 if ((dev->pdev->device == 0x7142) &&
372 (dev->pdev->subsystem_vendor == 0x1458) &&
373 (dev->pdev->subsystem_device == 0x2134)) {
374 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
380 if ((dev->pdev->device == 0x71C5) &&
381 (dev->pdev->subsystem_vendor == 0x106b) &&
382 (dev->pdev->subsystem_device == 0x0080)) {
383 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
384 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
386 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
390 /* mac rv630, rv730, others */
391 if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
392 (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
393 *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
394 *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
397 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
398 if ((dev->pdev->device == 0x9598) &&
399 (dev->pdev->subsystem_vendor == 0x1043) &&
400 (dev->pdev->subsystem_device == 0x01da)) {
401 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
402 *connector_type = DRM_MODE_CONNECTOR_DVII;
406 /* ASUS HD 3600 board lists the DVI port as HDMI */
407 if ((dev->pdev->device == 0x9598) &&
408 (dev->pdev->subsystem_vendor == 0x1043) &&
409 (dev->pdev->subsystem_device == 0x01e4)) {
410 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
411 *connector_type = DRM_MODE_CONNECTOR_DVII;
415 /* ASUS HD 3450 board lists the DVI port as HDMI */
416 if ((dev->pdev->device == 0x95C5) &&
417 (dev->pdev->subsystem_vendor == 0x1043) &&
418 (dev->pdev->subsystem_device == 0x01e2)) {
419 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
420 *connector_type = DRM_MODE_CONNECTOR_DVII;
424 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
425 * HDMI + VGA reporting as HDMI
427 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
428 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
429 *connector_type = DRM_MODE_CONNECTOR_VGA;
434 /* Acer laptop (Acer TravelMate 5730G) has an HDMI port
435 * on the laptop and a DVI port on the docking station and
436 * both share the same encoder, hpd pin, and ddc line.
437 * So while the bios table is technically correct,
438 * we drop the DVI port here since xrandr has no concept of
439 * encoders and will try and drive both connectors
440 * with different crtcs which isn't possible on the hardware
441 * side and leaves no crtcs for LVDS or VGA.
443 if ((dev->pdev->device == 0x95c4) &&
444 (dev->pdev->subsystem_vendor == 0x1025) &&
445 (dev->pdev->subsystem_device == 0x013c)) {
446 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
447 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
448 /* actually it's a DVI-D port not DVI-I */
449 *connector_type = DRM_MODE_CONNECTOR_DVID;
454 /* XFX Pine Group device rv730 reports no VGA DDC lines
455 * even though they are wired up to record 0x93
457 if ((dev->pdev->device == 0x9498) &&
458 (dev->pdev->subsystem_vendor == 0x1682) &&
459 (dev->pdev->subsystem_device == 0x2452)) {
460 struct radeon_device *rdev = dev->dev_private;
461 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
466 const int supported_devices_connector_convert[] = {
467 DRM_MODE_CONNECTOR_Unknown,
468 DRM_MODE_CONNECTOR_VGA,
469 DRM_MODE_CONNECTOR_DVII,
470 DRM_MODE_CONNECTOR_DVID,
471 DRM_MODE_CONNECTOR_DVIA,
472 DRM_MODE_CONNECTOR_SVIDEO,
473 DRM_MODE_CONNECTOR_Composite,
474 DRM_MODE_CONNECTOR_LVDS,
475 DRM_MODE_CONNECTOR_Unknown,
476 DRM_MODE_CONNECTOR_Unknown,
477 DRM_MODE_CONNECTOR_HDMIA,
478 DRM_MODE_CONNECTOR_HDMIB,
479 DRM_MODE_CONNECTOR_Unknown,
480 DRM_MODE_CONNECTOR_Unknown,
481 DRM_MODE_CONNECTOR_9PinDIN,
482 DRM_MODE_CONNECTOR_DisplayPort
485 const uint16_t supported_devices_connector_object_id_convert[] = {
486 CONNECTOR_OBJECT_ID_NONE,
487 CONNECTOR_OBJECT_ID_VGA,
488 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
489 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
490 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
491 CONNECTOR_OBJECT_ID_COMPOSITE,
492 CONNECTOR_OBJECT_ID_SVIDEO,
493 CONNECTOR_OBJECT_ID_LVDS,
494 CONNECTOR_OBJECT_ID_9PIN_DIN,
495 CONNECTOR_OBJECT_ID_9PIN_DIN,
496 CONNECTOR_OBJECT_ID_DISPLAYPORT,
497 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
498 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
499 CONNECTOR_OBJECT_ID_SVIDEO
502 const int object_connector_convert[] = {
503 DRM_MODE_CONNECTOR_Unknown,
504 DRM_MODE_CONNECTOR_DVII,
505 DRM_MODE_CONNECTOR_DVII,
506 DRM_MODE_CONNECTOR_DVID,
507 DRM_MODE_CONNECTOR_DVID,
508 DRM_MODE_CONNECTOR_VGA,
509 DRM_MODE_CONNECTOR_Composite,
510 DRM_MODE_CONNECTOR_SVIDEO,
511 DRM_MODE_CONNECTOR_Unknown,
512 DRM_MODE_CONNECTOR_Unknown,
513 DRM_MODE_CONNECTOR_9PinDIN,
514 DRM_MODE_CONNECTOR_Unknown,
515 DRM_MODE_CONNECTOR_HDMIA,
516 DRM_MODE_CONNECTOR_HDMIB,
517 DRM_MODE_CONNECTOR_LVDS,
518 DRM_MODE_CONNECTOR_9PinDIN,
519 DRM_MODE_CONNECTOR_Unknown,
520 DRM_MODE_CONNECTOR_Unknown,
521 DRM_MODE_CONNECTOR_Unknown,
522 DRM_MODE_CONNECTOR_DisplayPort,
523 DRM_MODE_CONNECTOR_eDP,
524 DRM_MODE_CONNECTOR_Unknown
527 bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
529 struct radeon_device *rdev = dev->dev_private;
530 struct radeon_mode_info *mode_info = &rdev->mode_info;
531 struct atom_context *ctx = mode_info->atom_context;
532 int index = GetIndexIntoMasterTable(DATA, Object_Header);
533 u16 size, data_offset;
535 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
536 ATOM_OBJECT_TABLE *router_obj;
537 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
538 ATOM_OBJECT_HEADER *obj_header;
539 int i, j, k, path_size, device_support;
541 u16 igp_lane_info, conn_id, connector_object_id;
542 struct radeon_i2c_bus_rec ddc_bus;
543 struct radeon_router router;
544 struct radeon_gpio_rec gpio;
545 struct radeon_hpd hpd;
547 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
553 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
554 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
555 (ctx->bios + data_offset +
556 le16_to_cpu(obj_header->usDisplayPathTableOffset));
557 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
558 (ctx->bios + data_offset +
559 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
560 router_obj = (ATOM_OBJECT_TABLE *)
561 (ctx->bios + data_offset +
562 le16_to_cpu(obj_header->usRouterObjectTableOffset));
563 device_support = le16_to_cpu(obj_header->usDeviceSupport);
566 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
567 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
568 ATOM_DISPLAY_OBJECT_PATH *path;
570 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
571 path_size += le16_to_cpu(path->usSize);
573 if (device_support & le16_to_cpu(path->usDeviceTag)) {
574 uint8_t con_obj_id, con_obj_num, con_obj_type;
577 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
580 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
583 (le16_to_cpu(path->usConnObjectId) &
584 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
586 /* TODO CV support */
587 if (le16_to_cpu(path->usDeviceTag) ==
588 ATOM_DEVICE_CV_SUPPORT)
592 if ((rdev->flags & RADEON_IS_IGP) &&
594 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
595 uint16_t igp_offset = 0;
596 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
599 GetIndexIntoMasterTable(DATA,
600 IntegratedSystemInfo);
602 if (atom_parse_data_header(ctx, index, &size, &frev,
603 &crev, &igp_offset)) {
607 (ATOM_INTEGRATED_SYSTEM_INFO_V2
608 *) (ctx->bios + igp_offset);
611 uint32_t slot_config, ct;
613 if (con_obj_num == 1)
622 ct = (slot_config >> 16) & 0xff;
624 object_connector_convert
626 connector_object_id = ct;
628 slot_config & 0xffff;
636 object_connector_convert[con_obj_id];
637 connector_object_id = con_obj_id;
642 object_connector_convert[con_obj_id];
643 connector_object_id = con_obj_id;
646 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
649 router.ddc_valid = false;
650 router.cd_valid = false;
651 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
652 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
655 (le16_to_cpu(path->usGraphicObjIds[j]) &
656 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
658 (le16_to_cpu(path->usGraphicObjIds[j]) &
659 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
661 (le16_to_cpu(path->usGraphicObjIds[j]) &
662 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
664 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
665 u16 encoder_obj = le16_to_cpu(path->usGraphicObjIds[j]);
667 radeon_add_atom_encoder(dev,
673 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
674 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
675 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
676 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
677 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
678 (ctx->bios + data_offset +
679 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
680 ATOM_I2C_RECORD *i2c_record;
681 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
682 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
683 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
684 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
685 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
686 (ctx->bios + data_offset +
687 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
690 router.router_id = router_obj_id;
691 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
693 if (le16_to_cpu(path->usConnObjectId) ==
694 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
698 while (record->ucRecordType > 0 &&
699 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
700 switch (record->ucRecordType) {
701 case ATOM_I2C_RECORD_TYPE:
706 (ATOM_I2C_ID_CONFIG_ACCESS *)
707 &i2c_record->sucI2cId;
709 radeon_lookup_i2c_gpio(rdev,
712 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
714 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
715 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
717 router.ddc_valid = true;
718 router.ddc_mux_type = ddc_path->ucMuxType;
719 router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
720 router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
722 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
723 cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
725 router.cd_valid = true;
726 router.cd_mux_type = cd_path->ucMuxType;
727 router.cd_mux_control_pin = cd_path->ucMuxControlPin;
728 router.cd_mux_state = cd_path->ucMuxState[enum_id];
731 record = (ATOM_COMMON_RECORD_HEADER *)
732 ((char *)record + record->ucRecordSize);
739 /* look up gpio for ddc, hpd */
740 ddc_bus.valid = false;
741 hpd.hpd = RADEON_HPD_NONE;
742 if ((le16_to_cpu(path->usDeviceTag) &
743 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
744 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
745 if (le16_to_cpu(path->usConnObjectId) ==
746 le16_to_cpu(con_obj->asObjects[j].
748 ATOM_COMMON_RECORD_HEADER
750 (ATOM_COMMON_RECORD_HEADER
752 (ctx->bios + data_offset +
753 le16_to_cpu(con_obj->
756 ATOM_I2C_RECORD *i2c_record;
757 ATOM_HPD_INT_RECORD *hpd_record;
758 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
760 while (record->ucRecordType > 0
763 ATOM_MAX_OBJECT_RECORD_NUMBER) {
764 switch (record->ucRecordType) {
765 case ATOM_I2C_RECORD_TYPE:
770 (ATOM_I2C_ID_CONFIG_ACCESS *)
771 &i2c_record->sucI2cId;
772 ddc_bus = radeon_lookup_i2c_gpio(rdev,
776 case ATOM_HPD_INT_RECORD_TYPE:
778 (ATOM_HPD_INT_RECORD *)
780 gpio = radeon_lookup_gpio(rdev,
781 hpd_record->ucHPDIntGPIOID);
782 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
783 hpd.plugged_state = hpd_record->ucPlugged_PinState;
787 (ATOM_COMMON_RECORD_HEADER
798 /* needed for aux chan transactions */
799 ddc_bus.hpd = hpd.hpd;
801 conn_id = le16_to_cpu(path->usConnObjectId);
803 if (!radeon_atom_apply_quirks
804 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
805 &ddc_bus, &conn_id, &hpd))
808 radeon_add_atom_connector(dev,
812 connector_type, &ddc_bus,
821 radeon_link_encoder_connector(dev);
826 static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
830 struct radeon_device *rdev = dev->dev_private;
832 if (rdev->flags & RADEON_IS_IGP) {
833 return supported_devices_connector_object_id_convert
835 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
836 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
837 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
838 struct radeon_mode_info *mode_info = &rdev->mode_info;
839 struct atom_context *ctx = mode_info->atom_context;
840 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
841 uint16_t size, data_offset;
843 ATOM_XTMDS_INFO *xtmds;
845 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
846 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
848 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
849 if (connector_type == DRM_MODE_CONNECTOR_DVII)
850 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
852 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
854 if (connector_type == DRM_MODE_CONNECTOR_DVII)
855 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
857 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
860 return supported_devices_connector_object_id_convert
863 return supported_devices_connector_object_id_convert
868 struct bios_connector {
873 struct radeon_i2c_bus_rec ddc_bus;
874 struct radeon_hpd hpd;
877 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
881 struct radeon_device *rdev = dev->dev_private;
882 struct radeon_mode_info *mode_info = &rdev->mode_info;
883 struct atom_context *ctx = mode_info->atom_context;
884 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
885 uint16_t size, data_offset;
887 uint16_t device_support;
889 union atom_supported_devices *supported_devices;
890 int i, j, max_device;
891 struct bios_connector *bios_connectors;
892 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
893 struct radeon_router router;
895 router.ddc_valid = false;
896 router.cd_valid = false;
898 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
899 if (!bios_connectors)
902 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
904 kfree(bios_connectors);
909 (union atom_supported_devices *)(ctx->bios + data_offset);
911 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
914 max_device = ATOM_MAX_SUPPORTED_DEVICE;
916 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
918 for (i = 0; i < max_device; i++) {
919 ATOM_CONNECTOR_INFO_I2C ci =
920 supported_devices->info.asConnInfo[i];
922 bios_connectors[i].valid = false;
924 if (!(device_support & (1 << i))) {
928 if (i == ATOM_DEVICE_CV_INDEX) {
929 DRM_DEBUG_KMS("Skipping Component Video\n");
933 bios_connectors[i].connector_type =
934 supported_devices_connector_convert[ci.sucConnectorInfo.
938 if (bios_connectors[i].connector_type ==
939 DRM_MODE_CONNECTOR_Unknown)
942 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
944 bios_connectors[i].line_mux =
945 ci.sucI2cId.ucAccess;
947 /* give tv unique connector ids */
948 if (i == ATOM_DEVICE_TV1_INDEX) {
949 bios_connectors[i].ddc_bus.valid = false;
950 bios_connectors[i].line_mux = 50;
951 } else if (i == ATOM_DEVICE_TV2_INDEX) {
952 bios_connectors[i].ddc_bus.valid = false;
953 bios_connectors[i].line_mux = 51;
954 } else if (i == ATOM_DEVICE_CV_INDEX) {
955 bios_connectors[i].ddc_bus.valid = false;
956 bios_connectors[i].line_mux = 52;
958 bios_connectors[i].ddc_bus =
959 radeon_lookup_i2c_gpio(rdev,
960 bios_connectors[i].line_mux);
962 if ((crev > 1) && (frev > 1)) {
963 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
966 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
969 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
972 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
976 if (i == ATOM_DEVICE_DFP1_INDEX)
977 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
978 else if (i == ATOM_DEVICE_DFP2_INDEX)
979 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
981 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
984 /* Always set the connector type to VGA for CRT1/CRT2. if they are
985 * shared with a DVI port, we'll pick up the DVI connector when we
986 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
988 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
989 bios_connectors[i].connector_type =
990 DRM_MODE_CONNECTOR_VGA;
992 if (!radeon_atom_apply_quirks
993 (dev, (1 << i), &bios_connectors[i].connector_type,
994 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
995 &bios_connectors[i].hpd))
998 bios_connectors[i].valid = true;
999 bios_connectors[i].devices = (1 << i);
1001 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
1002 radeon_add_atom_encoder(dev,
1003 radeon_get_encoder_enum(dev,
1008 radeon_add_legacy_encoder(dev,
1009 radeon_get_encoder_enum(dev,
1015 /* combine shared connectors */
1016 for (i = 0; i < max_device; i++) {
1017 if (bios_connectors[i].valid) {
1018 for (j = 0; j < max_device; j++) {
1019 if (bios_connectors[j].valid && (i != j)) {
1020 if (bios_connectors[i].line_mux ==
1021 bios_connectors[j].line_mux) {
1022 /* make sure not to combine LVDS */
1023 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1024 bios_connectors[i].line_mux = 53;
1025 bios_connectors[i].ddc_bus.valid = false;
1028 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1029 bios_connectors[j].line_mux = 53;
1030 bios_connectors[j].ddc_bus.valid = false;
1033 /* combine analog and digital for DVI-I */
1034 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1035 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
1036 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1037 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
1038 bios_connectors[i].devices |=
1039 bios_connectors[j].devices;
1040 bios_connectors[i].connector_type =
1041 DRM_MODE_CONNECTOR_DVII;
1042 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
1043 bios_connectors[i].hpd =
1044 bios_connectors[j].hpd;
1045 bios_connectors[j].valid = false;
1053 /* add the connectors */
1054 for (i = 0; i < max_device; i++) {
1055 if (bios_connectors[i].valid) {
1056 uint16_t connector_object_id =
1057 atombios_get_connector_object_id(dev,
1058 bios_connectors[i].connector_type,
1059 bios_connectors[i].devices);
1060 radeon_add_atom_connector(dev,
1061 bios_connectors[i].line_mux,
1062 bios_connectors[i].devices,
1065 &bios_connectors[i].ddc_bus,
1067 connector_object_id,
1068 &bios_connectors[i].hpd,
1073 radeon_link_encoder_connector(dev);
1075 kfree(bios_connectors);
1079 union firmware_info {
1080 ATOM_FIRMWARE_INFO info;
1081 ATOM_FIRMWARE_INFO_V1_2 info_12;
1082 ATOM_FIRMWARE_INFO_V1_3 info_13;
1083 ATOM_FIRMWARE_INFO_V1_4 info_14;
1084 ATOM_FIRMWARE_INFO_V2_1 info_21;
1087 bool radeon_atom_get_clock_info(struct drm_device *dev)
1089 struct radeon_device *rdev = dev->dev_private;
1090 struct radeon_mode_info *mode_info = &rdev->mode_info;
1091 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1092 union firmware_info *firmware_info;
1094 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1095 struct radeon_pll *p2pll = &rdev->clock.p2pll;
1096 struct radeon_pll *dcpll = &rdev->clock.dcpll;
1097 struct radeon_pll *spll = &rdev->clock.spll;
1098 struct radeon_pll *mpll = &rdev->clock.mpll;
1099 uint16_t data_offset;
1101 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1102 &frev, &crev, &data_offset)) {
1104 (union firmware_info *)(mode_info->atom_context->bios +
1107 p1pll->reference_freq =
1108 le16_to_cpu(firmware_info->info.usReferenceClock);
1109 p1pll->reference_div = 0;
1112 p1pll->pll_out_min =
1113 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1115 p1pll->pll_out_min =
1116 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
1117 p1pll->pll_out_max =
1118 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1121 p1pll->lcd_pll_out_min =
1122 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1123 if (p1pll->lcd_pll_out_min == 0)
1124 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1125 p1pll->lcd_pll_out_max =
1126 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1127 if (p1pll->lcd_pll_out_max == 0)
1128 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1130 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1131 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1134 if (p1pll->pll_out_min == 0) {
1135 if (ASIC_IS_AVIVO(rdev))
1136 p1pll->pll_out_min = 64800;
1138 p1pll->pll_out_min = 20000;
1142 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1144 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1149 spll->reference_freq =
1150 le16_to_cpu(firmware_info->info.usReferenceClock);
1151 spll->reference_div = 0;
1154 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1156 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1159 if (spll->pll_out_min == 0) {
1160 if (ASIC_IS_AVIVO(rdev))
1161 spll->pll_out_min = 64800;
1163 spll->pll_out_min = 20000;
1167 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1169 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1172 mpll->reference_freq =
1173 le16_to_cpu(firmware_info->info.usReferenceClock);
1174 mpll->reference_div = 0;
1177 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1179 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1182 if (mpll->pll_out_min == 0) {
1183 if (ASIC_IS_AVIVO(rdev))
1184 mpll->pll_out_min = 64800;
1186 mpll->pll_out_min = 20000;
1190 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1192 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1194 rdev->clock.default_sclk =
1195 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1196 rdev->clock.default_mclk =
1197 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1199 if (ASIC_IS_DCE4(rdev)) {
1200 rdev->clock.default_dispclk =
1201 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
1202 if (rdev->clock.default_dispclk == 0)
1203 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1204 rdev->clock.dp_extclk =
1205 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
1216 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1217 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1220 bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1222 struct radeon_mode_info *mode_info = &rdev->mode_info;
1223 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1224 union igp_info *igp_info;
1228 /* sideport is AMD only */
1229 if (rdev->family == CHIP_RS600)
1232 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1233 &frev, &crev, &data_offset)) {
1234 igp_info = (union igp_info *)(mode_info->atom_context->bios +
1238 if (igp_info->info.ulBootUpMemoryClock)
1242 if (igp_info->info_2.ulBootUpSidePortClock)
1246 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1253 bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1254 struct radeon_encoder_int_tmds *tmds)
1256 struct drm_device *dev = encoder->base.dev;
1257 struct radeon_device *rdev = dev->dev_private;
1258 struct radeon_mode_info *mode_info = &rdev->mode_info;
1259 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1260 uint16_t data_offset;
1261 struct _ATOM_TMDS_INFO *tmds_info;
1266 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1267 &frev, &crev, &data_offset)) {
1269 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1272 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1273 for (i = 0; i < 4; i++) {
1274 tmds->tmds_pll[i].freq =
1275 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1276 tmds->tmds_pll[i].value =
1277 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1278 tmds->tmds_pll[i].value |=
1279 (tmds_info->asMiscInfo[i].
1280 ucPLL_VCO_Gain & 0x3f) << 6;
1281 tmds->tmds_pll[i].value |=
1282 (tmds_info->asMiscInfo[i].
1283 ucPLL_DutyCycle & 0xf) << 12;
1284 tmds->tmds_pll[i].value |=
1285 (tmds_info->asMiscInfo[i].
1286 ucPLL_VoltageSwing & 0xf) << 16;
1288 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
1289 tmds->tmds_pll[i].freq,
1290 tmds->tmds_pll[i].value);
1292 if (maxfreq == tmds->tmds_pll[i].freq) {
1293 tmds->tmds_pll[i].freq = 0xffffffff;
1302 bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
1303 struct radeon_atom_ss *ss,
1306 struct radeon_mode_info *mode_info = &rdev->mode_info;
1307 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
1308 uint16_t data_offset, size;
1309 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1313 memset(ss, 0, sizeof(struct radeon_atom_ss));
1314 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1315 &frev, &crev, &data_offset)) {
1317 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
1319 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1320 sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
1322 for (i = 0; i < num_indices; i++) {
1323 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1325 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1326 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1327 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1328 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1329 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1330 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
1338 union asic_ss_info {
1339 struct _ATOM_ASIC_INTERNAL_SS_INFO info;
1340 struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
1341 struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
1344 bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
1345 struct radeon_atom_ss *ss,
1348 struct radeon_mode_info *mode_info = &rdev->mode_info;
1349 int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
1350 uint16_t data_offset, size;
1351 union asic_ss_info *ss_info;
1355 memset(ss, 0, sizeof(struct radeon_atom_ss));
1356 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1357 &frev, &crev, &data_offset)) {
1360 (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
1364 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1365 sizeof(ATOM_ASIC_SS_ASSIGNMENT);
1367 for (i = 0; i < num_indices; i++) {
1368 if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
1369 (clock <= ss_info->info.asSpreadSpectrum[i].ulTargetClockRange)) {
1371 le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1372 ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1373 ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
1379 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1380 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
1381 for (i = 0; i < num_indices; i++) {
1382 if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
1383 (clock <= ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange)) {
1385 le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1386 ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1387 ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
1393 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1394 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
1395 for (i = 0; i < num_indices; i++) {
1396 if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
1397 (clock <= ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange)) {
1399 le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1400 ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1401 ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
1407 DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
1416 struct _ATOM_LVDS_INFO info;
1417 struct _ATOM_LVDS_INFO_V12 info_12;
1420 struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1424 struct drm_device *dev = encoder->base.dev;
1425 struct radeon_device *rdev = dev->dev_private;
1426 struct radeon_mode_info *mode_info = &rdev->mode_info;
1427 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
1428 uint16_t data_offset, misc;
1429 union lvds_info *lvds_info;
1431 struct radeon_encoder_atom_dig *lvds = NULL;
1432 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
1434 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1435 &frev, &crev, &data_offset)) {
1437 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
1439 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1444 lvds->native_mode.clock =
1445 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
1446 lvds->native_mode.hdisplay =
1447 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
1448 lvds->native_mode.vdisplay =
1449 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
1450 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1451 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1452 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1453 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1454 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1455 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1456 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1457 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1458 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1459 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
1460 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1461 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
1462 lvds->panel_pwr_delay =
1463 le16_to_cpu(lvds_info->info.usOffDelayInMs);
1464 lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
1466 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1467 if (misc & ATOM_VSYNC_POLARITY)
1468 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1469 if (misc & ATOM_HSYNC_POLARITY)
1470 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1471 if (misc & ATOM_COMPOSITESYNC)
1472 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1473 if (misc & ATOM_INTERLACE)
1474 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1475 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1476 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1478 /* set crtc values */
1479 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
1481 lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
1483 encoder->native_mode = lvds->native_mode;
1485 if (encoder_enum == 2)
1488 lvds->linkb = false;
1494 struct radeon_encoder_primary_dac *
1495 radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1497 struct drm_device *dev = encoder->base.dev;
1498 struct radeon_device *rdev = dev->dev_private;
1499 struct radeon_mode_info *mode_info = &rdev->mode_info;
1500 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1501 uint16_t data_offset;
1502 struct _COMPASSIONATE_DATA *dac_info;
1505 struct radeon_encoder_primary_dac *p_dac = NULL;
1507 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1508 &frev, &crev, &data_offset)) {
1509 dac_info = (struct _COMPASSIONATE_DATA *)
1510 (mode_info->atom_context->bios + data_offset);
1512 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1517 bg = dac_info->ucDAC1_BG_Adjustment;
1518 dac = dac_info->ucDAC1_DAC_Adjustment;
1519 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1525 bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
1526 struct drm_display_mode *mode)
1528 struct radeon_mode_info *mode_info = &rdev->mode_info;
1529 ATOM_ANALOG_TV_INFO *tv_info;
1530 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1531 ATOM_DTD_FORMAT *dtd_timings;
1532 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1534 u16 data_offset, misc;
1536 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1537 &frev, &crev, &data_offset))
1542 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1543 if (index >= MAX_SUPPORTED_TV_TIMING)
1546 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1547 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1548 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1549 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1550 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
1552 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1553 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1554 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1555 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1556 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
1559 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1560 if (misc & ATOM_VSYNC_POLARITY)
1561 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1562 if (misc & ATOM_HSYNC_POLARITY)
1563 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1564 if (misc & ATOM_COMPOSITESYNC)
1565 mode->flags |= DRM_MODE_FLAG_CSYNC;
1566 if (misc & ATOM_INTERLACE)
1567 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1568 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1569 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1571 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
1574 /* PAL timings appear to have wrong values for totals */
1575 mode->crtc_htotal -= 1;
1576 mode->crtc_vtotal -= 1;
1580 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
1581 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
1584 dtd_timings = &tv_info_v1_2->aModeTimings[index];
1585 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1586 le16_to_cpu(dtd_timings->usHBlanking_Time);
1587 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1588 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1589 le16_to_cpu(dtd_timings->usHSyncOffset);
1590 mode->crtc_hsync_end = mode->crtc_hsync_start +
1591 le16_to_cpu(dtd_timings->usHSyncWidth);
1593 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1594 le16_to_cpu(dtd_timings->usVBlanking_Time);
1595 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1596 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1597 le16_to_cpu(dtd_timings->usVSyncOffset);
1598 mode->crtc_vsync_end = mode->crtc_vsync_start +
1599 le16_to_cpu(dtd_timings->usVSyncWidth);
1602 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1603 if (misc & ATOM_VSYNC_POLARITY)
1604 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1605 if (misc & ATOM_HSYNC_POLARITY)
1606 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1607 if (misc & ATOM_COMPOSITESYNC)
1608 mode->flags |= DRM_MODE_FLAG_CSYNC;
1609 if (misc & ATOM_INTERLACE)
1610 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1611 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1612 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1614 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
1621 radeon_atombios_get_tv_info(struct radeon_device *rdev)
1623 struct radeon_mode_info *mode_info = &rdev->mode_info;
1624 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1625 uint16_t data_offset;
1627 struct _ATOM_ANALOG_TV_INFO *tv_info;
1628 enum radeon_tv_std tv_std = TV_STD_NTSC;
1630 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1631 &frev, &crev, &data_offset)) {
1633 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1634 (mode_info->atom_context->bios + data_offset);
1636 switch (tv_info->ucTV_BootUpDefaultStandard) {
1638 tv_std = TV_STD_NTSC;
1639 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
1642 tv_std = TV_STD_NTSC_J;
1643 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
1646 tv_std = TV_STD_PAL;
1647 DRM_DEBUG_KMS("Default TV standard: PAL\n");
1650 tv_std = TV_STD_PAL_M;
1651 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
1654 tv_std = TV_STD_PAL_N;
1655 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
1658 tv_std = TV_STD_PAL_CN;
1659 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
1662 tv_std = TV_STD_PAL_60;
1663 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
1666 tv_std = TV_STD_SECAM;
1667 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
1670 tv_std = TV_STD_NTSC;
1671 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
1678 struct radeon_encoder_tv_dac *
1679 radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1681 struct drm_device *dev = encoder->base.dev;
1682 struct radeon_device *rdev = dev->dev_private;
1683 struct radeon_mode_info *mode_info = &rdev->mode_info;
1684 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1685 uint16_t data_offset;
1686 struct _COMPASSIONATE_DATA *dac_info;
1689 struct radeon_encoder_tv_dac *tv_dac = NULL;
1691 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1692 &frev, &crev, &data_offset)) {
1694 dac_info = (struct _COMPASSIONATE_DATA *)
1695 (mode_info->atom_context->bios + data_offset);
1697 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1702 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1703 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1704 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1706 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1707 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1708 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1710 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1711 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1712 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1714 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
1719 static const char *thermal_controller_names[] = {
1730 static const char *pp_lib_thermal_controller_names[] = {
1743 "adt7473 with internal",
1748 struct _ATOM_POWERPLAY_INFO info;
1749 struct _ATOM_POWERPLAY_INFO_V2 info_2;
1750 struct _ATOM_POWERPLAY_INFO_V3 info_3;
1751 struct _ATOM_PPLIB_POWERPLAYTABLE info_4;
1754 void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1756 struct radeon_mode_info *mode_info = &rdev->mode_info;
1757 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
1760 u32 misc, misc2 = 0, sclk, mclk;
1761 union power_info *power_info;
1762 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
1763 struct _ATOM_PPLIB_STATE *power_state;
1764 int num_modes = 0, i, j;
1765 int state_index = 0, mode_index = 0;
1766 struct radeon_i2c_bus_rec i2c_bus;
1768 rdev->pm.default_power_state_index = -1;
1770 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1771 &frev, &crev, &data_offset)) {
1772 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
1774 /* add the i2c bus for thermal/fan chip */
1775 if (power_info->info.ucOverdriveThermalController > 0) {
1776 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
1777 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1778 power_info->info.ucOverdriveControllerAddress >> 1);
1779 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
1780 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1781 if (rdev->pm.i2c_bus) {
1782 struct i2c_board_info info = { };
1783 const char *name = thermal_controller_names[power_info->info.
1784 ucOverdriveThermalController];
1785 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
1786 strlcpy(info.type, name, sizeof(info.type));
1787 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
1790 num_modes = power_info->info.ucNumOfPowerModeEntries;
1791 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
1792 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
1793 /* last mode is usually default, array is low to high */
1794 for (i = 0; i < num_modes; i++) {
1795 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
1798 rdev->pm.power_state[state_index].num_clock_modes = 1;
1799 rdev->pm.power_state[state_index].clock_info[0].mclk =
1800 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
1801 rdev->pm.power_state[state_index].clock_info[0].sclk =
1802 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
1803 /* skip invalid modes */
1804 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1805 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1807 rdev->pm.power_state[state_index].pcie_lanes =
1808 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
1809 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
1810 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1811 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
1812 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1814 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1815 radeon_lookup_gpio(rdev,
1816 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
1817 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1818 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1821 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1823 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1824 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1826 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1827 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
1829 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1830 rdev->pm.power_state[state_index].misc = misc;
1831 /* order matters! */
1832 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1833 rdev->pm.power_state[state_index].type =
1834 POWER_STATE_TYPE_POWERSAVE;
1835 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1836 rdev->pm.power_state[state_index].type =
1837 POWER_STATE_TYPE_BATTERY;
1838 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1839 rdev->pm.power_state[state_index].type =
1840 POWER_STATE_TYPE_BATTERY;
1841 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1842 rdev->pm.power_state[state_index].type =
1843 POWER_STATE_TYPE_BALANCED;
1844 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
1845 rdev->pm.power_state[state_index].type =
1846 POWER_STATE_TYPE_PERFORMANCE;
1847 rdev->pm.power_state[state_index].flags &=
1848 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1850 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
1851 rdev->pm.power_state[state_index].type =
1852 POWER_STATE_TYPE_DEFAULT;
1853 rdev->pm.default_power_state_index = state_index;
1854 rdev->pm.power_state[state_index].default_clock_mode =
1855 &rdev->pm.power_state[state_index].clock_info[0];
1856 rdev->pm.power_state[state_index].flags &=
1857 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1858 } else if (state_index == 0) {
1859 rdev->pm.power_state[state_index].clock_info[0].flags |=
1860 RADEON_PM_MODE_NO_DISPLAY;
1865 rdev->pm.power_state[state_index].num_clock_modes = 1;
1866 rdev->pm.power_state[state_index].clock_info[0].mclk =
1867 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
1868 rdev->pm.power_state[state_index].clock_info[0].sclk =
1869 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
1870 /* skip invalid modes */
1871 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1872 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1874 rdev->pm.power_state[state_index].pcie_lanes =
1875 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
1876 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
1877 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
1878 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1879 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
1880 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1882 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1883 radeon_lookup_gpio(rdev,
1884 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
1885 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1886 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1889 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1891 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1892 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1894 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1895 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
1897 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1898 rdev->pm.power_state[state_index].misc = misc;
1899 rdev->pm.power_state[state_index].misc2 = misc2;
1900 /* order matters! */
1901 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1902 rdev->pm.power_state[state_index].type =
1903 POWER_STATE_TYPE_POWERSAVE;
1904 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1905 rdev->pm.power_state[state_index].type =
1906 POWER_STATE_TYPE_BATTERY;
1907 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1908 rdev->pm.power_state[state_index].type =
1909 POWER_STATE_TYPE_BATTERY;
1910 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1911 rdev->pm.power_state[state_index].type =
1912 POWER_STATE_TYPE_BALANCED;
1913 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
1914 rdev->pm.power_state[state_index].type =
1915 POWER_STATE_TYPE_PERFORMANCE;
1916 rdev->pm.power_state[state_index].flags &=
1917 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1919 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1920 rdev->pm.power_state[state_index].type =
1921 POWER_STATE_TYPE_BALANCED;
1922 if (misc2 & ATOM_PM_MISCINFO2_MULTI_DISPLAY_SUPPORT)
1923 rdev->pm.power_state[state_index].flags &=
1924 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1925 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
1926 rdev->pm.power_state[state_index].type =
1927 POWER_STATE_TYPE_DEFAULT;
1928 rdev->pm.default_power_state_index = state_index;
1929 rdev->pm.power_state[state_index].default_clock_mode =
1930 &rdev->pm.power_state[state_index].clock_info[0];
1931 rdev->pm.power_state[state_index].flags &=
1932 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1933 } else if (state_index == 0) {
1934 rdev->pm.power_state[state_index].clock_info[0].flags |=
1935 RADEON_PM_MODE_NO_DISPLAY;
1940 rdev->pm.power_state[state_index].num_clock_modes = 1;
1941 rdev->pm.power_state[state_index].clock_info[0].mclk =
1942 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
1943 rdev->pm.power_state[state_index].clock_info[0].sclk =
1944 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
1945 /* skip invalid modes */
1946 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1947 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1949 rdev->pm.power_state[state_index].pcie_lanes =
1950 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
1951 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
1952 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
1953 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1954 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
1955 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1957 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1958 radeon_lookup_gpio(rdev,
1959 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
1960 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1961 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1964 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1966 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1967 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1969 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1970 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
1971 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
1972 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
1974 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
1975 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
1978 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1979 rdev->pm.power_state[state_index].misc = misc;
1980 rdev->pm.power_state[state_index].misc2 = misc2;
1981 /* order matters! */
1982 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1983 rdev->pm.power_state[state_index].type =
1984 POWER_STATE_TYPE_POWERSAVE;
1985 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1986 rdev->pm.power_state[state_index].type =
1987 POWER_STATE_TYPE_BATTERY;
1988 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1989 rdev->pm.power_state[state_index].type =
1990 POWER_STATE_TYPE_BATTERY;
1991 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1992 rdev->pm.power_state[state_index].type =
1993 POWER_STATE_TYPE_BALANCED;
1994 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
1995 rdev->pm.power_state[state_index].type =
1996 POWER_STATE_TYPE_PERFORMANCE;
1997 rdev->pm.power_state[state_index].flags &=
1998 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2000 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
2001 rdev->pm.power_state[state_index].type =
2002 POWER_STATE_TYPE_BALANCED;
2003 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
2004 rdev->pm.power_state[state_index].type =
2005 POWER_STATE_TYPE_DEFAULT;
2006 rdev->pm.default_power_state_index = state_index;
2007 rdev->pm.power_state[state_index].default_clock_mode =
2008 &rdev->pm.power_state[state_index].clock_info[0];
2009 } else if (state_index == 0) {
2010 rdev->pm.power_state[state_index].clock_info[0].flags |=
2011 RADEON_PM_MODE_NO_DISPLAY;
2017 /* last mode is usually default */
2018 if (rdev->pm.default_power_state_index == -1) {
2019 rdev->pm.power_state[state_index - 1].type =
2020 POWER_STATE_TYPE_DEFAULT;
2021 rdev->pm.default_power_state_index = state_index - 1;
2022 rdev->pm.power_state[state_index - 1].default_clock_mode =
2023 &rdev->pm.power_state[state_index - 1].clock_info[0];
2024 rdev->pm.power_state[state_index].flags &=
2025 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2026 rdev->pm.power_state[state_index].misc = 0;
2027 rdev->pm.power_state[state_index].misc2 = 0;
2030 int fw_index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
2031 uint8_t fw_frev, fw_crev;
2032 uint16_t fw_data_offset, vddc = 0;
2033 union firmware_info *firmware_info;
2034 ATOM_PPLIB_THERMALCONTROLLER *controller = &power_info->info_4.sThermalController;
2036 if (atom_parse_data_header(mode_info->atom_context, fw_index, NULL,
2037 &fw_frev, &fw_crev, &fw_data_offset)) {
2039 (union firmware_info *)(mode_info->atom_context->bios +
2041 vddc = firmware_info->info_14.usBootUpVDDCVoltage;
2044 /* add the i2c bus for thermal/fan chip */
2045 if (controller->ucType > 0) {
2046 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
2047 DRM_INFO("Internal thermal controller %s fan control\n",
2048 (controller->ucFanParameters &
2049 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2050 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
2051 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
2052 DRM_INFO("Internal thermal controller %s fan control\n",
2053 (controller->ucFanParameters &
2054 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2055 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
2056 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
2057 DRM_INFO("Internal thermal controller %s fan control\n",
2058 (controller->ucFanParameters &
2059 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2060 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
2061 } else if ((controller->ucType ==
2062 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
2063 (controller->ucType ==
2064 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL)) {
2065 DRM_INFO("Special thermal controller config\n");
2067 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2068 pp_lib_thermal_controller_names[controller->ucType],
2069 controller->ucI2cAddress >> 1,
2070 (controller->ucFanParameters &
2071 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2072 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
2073 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2074 if (rdev->pm.i2c_bus) {
2075 struct i2c_board_info info = { };
2076 const char *name = pp_lib_thermal_controller_names[controller->ucType];
2077 info.addr = controller->ucI2cAddress >> 1;
2078 strlcpy(info.type, name, sizeof(info.type));
2079 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2084 /* first mode is usually default, followed by low to high */
2085 for (i = 0; i < power_info->info_4.ucNumStates; i++) {
2087 power_state = (struct _ATOM_PPLIB_STATE *)
2088 (mode_info->atom_context->bios +
2090 le16_to_cpu(power_info->info_4.usStateArrayOffset) +
2091 i * power_info->info_4.ucStateEntrySize);
2092 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2093 (mode_info->atom_context->bios +
2095 le16_to_cpu(power_info->info_4.usNonClockInfoArrayOffset) +
2096 (power_state->ucNonClockStateIndex *
2097 power_info->info_4.ucNonClockSize));
2098 for (j = 0; j < (power_info->info_4.ucStateEntrySize - 1); j++) {
2099 if (rdev->flags & RADEON_IS_IGP) {
2100 struct _ATOM_PPLIB_RS780_CLOCK_INFO *clock_info =
2101 (struct _ATOM_PPLIB_RS780_CLOCK_INFO *)
2102 (mode_info->atom_context->bios +
2104 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2105 (power_state->ucClockStateIndices[j] *
2106 power_info->info_4.ucClockInfoSize));
2107 sclk = le16_to_cpu(clock_info->usLowEngineClockLow);
2108 sclk |= clock_info->ucLowEngineClockHigh << 16;
2109 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2110 /* skip invalid modes */
2111 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2113 /* voltage works differently on IGPs */
2115 } else if (ASIC_IS_DCE4(rdev)) {
2116 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *clock_info =
2117 (struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *)
2118 (mode_info->atom_context->bios +
2120 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2121 (power_state->ucClockStateIndices[j] *
2122 power_info->info_4.ucClockInfoSize));
2123 sclk = le16_to_cpu(clock_info->usEngineClockLow);
2124 sclk |= clock_info->ucEngineClockHigh << 16;
2125 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
2126 mclk |= clock_info->ucMemoryClockHigh << 16;
2127 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2128 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2129 /* skip invalid modes */
2130 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2131 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2133 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2135 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2140 struct _ATOM_PPLIB_R600_CLOCK_INFO *clock_info =
2141 (struct _ATOM_PPLIB_R600_CLOCK_INFO *)
2142 (mode_info->atom_context->bios +
2144 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2145 (power_state->ucClockStateIndices[j] *
2146 power_info->info_4.ucClockInfoSize));
2147 sclk = le16_to_cpu(clock_info->usEngineClockLow);
2148 sclk |= clock_info->ucEngineClockHigh << 16;
2149 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
2150 mclk |= clock_info->ucMemoryClockHigh << 16;
2151 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2152 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2153 /* skip invalid modes */
2154 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2155 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2157 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2159 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2164 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2166 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
2167 misc2 = le16_to_cpu(non_clock_info->usClassification);
2168 rdev->pm.power_state[state_index].misc = misc;
2169 rdev->pm.power_state[state_index].misc2 = misc2;
2170 rdev->pm.power_state[state_index].pcie_lanes =
2171 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2172 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2173 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2174 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2175 rdev->pm.power_state[state_index].type =
2176 POWER_STATE_TYPE_BATTERY;
2178 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2179 rdev->pm.power_state[state_index].type =
2180 POWER_STATE_TYPE_BALANCED;
2182 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2183 rdev->pm.power_state[state_index].type =
2184 POWER_STATE_TYPE_PERFORMANCE;
2186 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2187 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2188 rdev->pm.power_state[state_index].type =
2189 POWER_STATE_TYPE_PERFORMANCE;
2192 rdev->pm.power_state[state_index].flags = 0;
2193 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2194 rdev->pm.power_state[state_index].flags |=
2195 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2196 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
2197 rdev->pm.power_state[state_index].type =
2198 POWER_STATE_TYPE_DEFAULT;
2199 rdev->pm.default_power_state_index = state_index;
2200 rdev->pm.power_state[state_index].default_clock_mode =
2201 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
2202 /* patch the table values with the default slck/mclk from firmware info */
2203 for (j = 0; j < mode_index; j++) {
2204 rdev->pm.power_state[state_index].clock_info[j].mclk =
2205 rdev->clock.default_mclk;
2206 rdev->pm.power_state[state_index].clock_info[j].sclk =
2207 rdev->clock.default_sclk;
2209 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2216 /* if multiple clock modes, mark the lowest as no display */
2217 for (i = 0; i < state_index; i++) {
2218 if (rdev->pm.power_state[i].num_clock_modes > 1)
2219 rdev->pm.power_state[i].clock_info[0].flags |=
2220 RADEON_PM_MODE_NO_DISPLAY;
2222 /* first mode is usually default */
2223 if (rdev->pm.default_power_state_index == -1) {
2224 rdev->pm.power_state[0].type =
2225 POWER_STATE_TYPE_DEFAULT;
2226 rdev->pm.default_power_state_index = 0;
2227 rdev->pm.power_state[0].default_clock_mode =
2228 &rdev->pm.power_state[0].clock_info[0];
2232 /* add the default mode */
2233 rdev->pm.power_state[state_index].type =
2234 POWER_STATE_TYPE_DEFAULT;
2235 rdev->pm.power_state[state_index].num_clock_modes = 1;
2236 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2237 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2238 rdev->pm.power_state[state_index].default_clock_mode =
2239 &rdev->pm.power_state[state_index].clock_info[0];
2240 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2241 rdev->pm.power_state[state_index].pcie_lanes = 16;
2242 rdev->pm.default_power_state_index = state_index;
2243 rdev->pm.power_state[state_index].flags = 0;
2247 rdev->pm.num_power_states = state_index;
2249 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2250 rdev->pm.current_clock_mode_index = 0;
2251 rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
2254 void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2256 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2257 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2259 args.ucEnable = enable;
2261 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2264 uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2266 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2267 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2269 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2270 return args.ulReturnEngineClock;
2273 uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2275 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2276 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2278 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2279 return args.ulReturnMemoryClock;
2282 void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2285 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2286 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2288 args.ulTargetEngineClock = eng_clock; /* 10 khz */
2290 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2293 void radeon_atom_set_memory_clock(struct radeon_device *rdev,
2296 SET_MEMORY_CLOCK_PS_ALLOCATION args;
2297 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
2299 if (rdev->flags & RADEON_IS_IGP)
2302 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
2304 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2308 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2309 struct _SET_VOLTAGE_PARAMETERS v1;
2310 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2313 void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level)
2315 union set_voltage args;
2316 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
2317 u8 frev, crev, volt_index = level;
2319 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2324 args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2325 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
2326 args.v1.ucVoltageIndex = volt_index;
2329 args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2330 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
2331 args.v2.usVoltageLevel = cpu_to_le16(level);
2334 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2338 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2343 void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
2345 struct radeon_device *rdev = dev->dev_private;
2346 uint32_t bios_2_scratch, bios_6_scratch;
2348 if (rdev->family >= CHIP_R600) {
2349 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2350 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2352 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
2353 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2356 /* let the bios control the backlight */
2357 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
2359 /* tell the bios not to handle mode switching */
2360 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
2362 if (rdev->family >= CHIP_R600) {
2363 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2364 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2366 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2367 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2372 void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
2374 uint32_t scratch_reg;
2377 if (rdev->family >= CHIP_R600)
2378 scratch_reg = R600_BIOS_0_SCRATCH;
2380 scratch_reg = RADEON_BIOS_0_SCRATCH;
2382 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2383 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
2386 void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
2388 uint32_t scratch_reg;
2391 if (rdev->family >= CHIP_R600)
2392 scratch_reg = R600_BIOS_0_SCRATCH;
2394 scratch_reg = RADEON_BIOS_0_SCRATCH;
2396 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2397 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
2400 void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
2402 struct drm_device *dev = encoder->dev;
2403 struct radeon_device *rdev = dev->dev_private;
2404 uint32_t bios_6_scratch;
2406 if (rdev->family >= CHIP_R600)
2407 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2409 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2412 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
2414 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
2416 if (rdev->family >= CHIP_R600)
2417 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2419 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2422 /* at some point we may want to break this out into individual functions */
2424 radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
2425 struct drm_encoder *encoder,
2428 struct drm_device *dev = connector->dev;
2429 struct radeon_device *rdev = dev->dev_private;
2430 struct radeon_connector *radeon_connector =
2431 to_radeon_connector(connector);
2432 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2433 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
2435 if (rdev->family >= CHIP_R600) {
2436 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2437 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2438 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2440 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2441 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2442 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2445 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
2446 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
2448 DRM_DEBUG_KMS("TV1 connected\n");
2449 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
2450 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
2452 DRM_DEBUG_KMS("TV1 disconnected\n");
2453 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
2454 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
2455 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
2458 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
2459 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
2461 DRM_DEBUG_KMS("CV connected\n");
2462 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
2463 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
2465 DRM_DEBUG_KMS("CV disconnected\n");
2466 bios_0_scratch &= ~ATOM_S0_CV_MASK;
2467 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
2468 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
2471 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
2472 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
2474 DRM_DEBUG_KMS("LCD1 connected\n");
2475 bios_0_scratch |= ATOM_S0_LCD1;
2476 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
2477 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
2479 DRM_DEBUG_KMS("LCD1 disconnected\n");
2480 bios_0_scratch &= ~ATOM_S0_LCD1;
2481 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
2482 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
2485 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
2486 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
2488 DRM_DEBUG_KMS("CRT1 connected\n");
2489 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
2490 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
2491 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
2493 DRM_DEBUG_KMS("CRT1 disconnected\n");
2494 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
2495 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
2496 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
2499 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
2500 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
2502 DRM_DEBUG_KMS("CRT2 connected\n");
2503 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
2504 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
2505 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
2507 DRM_DEBUG_KMS("CRT2 disconnected\n");
2508 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
2509 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
2510 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
2513 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
2514 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
2516 DRM_DEBUG_KMS("DFP1 connected\n");
2517 bios_0_scratch |= ATOM_S0_DFP1;
2518 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
2519 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
2521 DRM_DEBUG_KMS("DFP1 disconnected\n");
2522 bios_0_scratch &= ~ATOM_S0_DFP1;
2523 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
2524 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
2527 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
2528 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
2530 DRM_DEBUG_KMS("DFP2 connected\n");
2531 bios_0_scratch |= ATOM_S0_DFP2;
2532 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
2533 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
2535 DRM_DEBUG_KMS("DFP2 disconnected\n");
2536 bios_0_scratch &= ~ATOM_S0_DFP2;
2537 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
2538 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
2541 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
2542 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
2544 DRM_DEBUG_KMS("DFP3 connected\n");
2545 bios_0_scratch |= ATOM_S0_DFP3;
2546 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
2547 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
2549 DRM_DEBUG_KMS("DFP3 disconnected\n");
2550 bios_0_scratch &= ~ATOM_S0_DFP3;
2551 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
2552 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
2555 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
2556 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
2558 DRM_DEBUG_KMS("DFP4 connected\n");
2559 bios_0_scratch |= ATOM_S0_DFP4;
2560 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
2561 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
2563 DRM_DEBUG_KMS("DFP4 disconnected\n");
2564 bios_0_scratch &= ~ATOM_S0_DFP4;
2565 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
2566 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
2569 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
2570 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
2572 DRM_DEBUG_KMS("DFP5 connected\n");
2573 bios_0_scratch |= ATOM_S0_DFP5;
2574 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
2575 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
2577 DRM_DEBUG_KMS("DFP5 disconnected\n");
2578 bios_0_scratch &= ~ATOM_S0_DFP5;
2579 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2580 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2584 if (rdev->family >= CHIP_R600) {
2585 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2586 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2587 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2589 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
2590 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2591 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2596 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
2598 struct drm_device *dev = encoder->dev;
2599 struct radeon_device *rdev = dev->dev_private;
2600 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2601 uint32_t bios_3_scratch;
2603 if (rdev->family >= CHIP_R600)
2604 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2606 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2608 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2609 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
2610 bios_3_scratch |= (crtc << 18);
2612 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2613 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
2614 bios_3_scratch |= (crtc << 24);
2616 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2617 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
2618 bios_3_scratch |= (crtc << 16);
2620 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2621 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
2622 bios_3_scratch |= (crtc << 20);
2624 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2625 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
2626 bios_3_scratch |= (crtc << 17);
2628 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2629 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
2630 bios_3_scratch |= (crtc << 19);
2632 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2633 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
2634 bios_3_scratch |= (crtc << 23);
2636 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2637 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
2638 bios_3_scratch |= (crtc << 25);
2641 if (rdev->family >= CHIP_R600)
2642 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2644 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2648 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
2650 struct drm_device *dev = encoder->dev;
2651 struct radeon_device *rdev = dev->dev_private;
2652 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2653 uint32_t bios_2_scratch;
2655 if (rdev->family >= CHIP_R600)
2656 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2658 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
2660 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2662 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
2664 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
2666 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2668 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
2670 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
2672 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2674 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
2676 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
2678 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2680 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
2682 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
2684 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2686 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
2688 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
2690 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2692 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
2694 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
2696 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2698 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
2700 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
2702 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2704 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
2706 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
2708 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
2710 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
2712 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
2714 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
2716 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
2718 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
2721 if (rdev->family >= CHIP_R600)
2722 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2724 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);