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_id(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_id,
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 bool linkb, uint32_t igp_lane_info,
50 uint16_t connector_object_id,
51 struct radeon_hpd *hpd);
53 /* from radeon_legacy_encoder.c */
55 radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id,
56 uint32_t supported_device);
58 union atom_supported_devices {
59 struct _ATOM_SUPPORTED_DEVICES_INFO info;
60 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
61 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
64 static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
67 struct atom_context *ctx = rdev->mode_info.atom_context;
68 ATOM_GPIO_I2C_ASSIGMENT *gpio;
69 struct radeon_i2c_bus_rec i2c;
70 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
71 struct _ATOM_GPIO_I2C_INFO *i2c_info;
75 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
78 atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset);
80 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
83 for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
84 gpio = &i2c_info->asGPIO_Info[i];
86 if (gpio->sucI2cId.ucAccess == id) {
87 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
88 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
89 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
90 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
91 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
92 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
93 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
94 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
95 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
96 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
97 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
98 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
99 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
100 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
101 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
102 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
104 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
105 i2c.hw_capable = true;
107 i2c.hw_capable = false;
109 if (gpio->sucI2cId.ucAccess == 0xa0)
114 i2c.i2c_id = gpio->sucI2cId.ucAccess;
124 static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
127 struct atom_context *ctx = rdev->mode_info.atom_context;
128 struct radeon_gpio_rec gpio;
129 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
130 struct _ATOM_GPIO_PIN_LUT *gpio_info;
131 ATOM_GPIO_PIN_ASSIGNMENT *pin;
132 u16 data_offset, size;
135 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
138 atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset);
140 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
142 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
144 for (i = 0; i < num_indices; i++) {
145 pin = &gpio_info->asGPIO_Pin[i];
146 if (id == pin->ucGPIO_ID) {
147 gpio.id = pin->ucGPIO_ID;
148 gpio.reg = pin->usGpioPin_AIndex * 4;
149 gpio.mask = (1 << pin->ucGpioPinBitShift);
158 static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
159 struct radeon_gpio_rec *gpio)
161 struct radeon_hpd hpd;
163 if (gpio->reg == AVIVO_DC_GPIO_HPD_A) {
166 hpd.hpd = RADEON_HPD_1;
169 hpd.hpd = RADEON_HPD_2;
172 hpd.hpd = RADEON_HPD_3;
175 hpd.hpd = RADEON_HPD_4;
178 hpd.hpd = RADEON_HPD_5;
181 hpd.hpd = RADEON_HPD_6;
184 hpd.hpd = RADEON_HPD_NONE;
188 hpd.hpd = RADEON_HPD_NONE;
192 static bool radeon_atom_apply_quirks(struct drm_device *dev,
193 uint32_t supported_device,
195 struct radeon_i2c_bus_rec *i2c_bus,
197 struct radeon_hpd *hpd)
200 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
201 if ((dev->pdev->device == 0x791e) &&
202 (dev->pdev->subsystem_vendor == 0x1043) &&
203 (dev->pdev->subsystem_device == 0x826d)) {
204 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
205 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
206 *connector_type = DRM_MODE_CONNECTOR_DVID;
209 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
210 if ((dev->pdev->device == 0x7941) &&
211 (dev->pdev->subsystem_vendor == 0x147b) &&
212 (dev->pdev->subsystem_device == 0x2412)) {
213 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
217 /* Falcon NW laptop lists vga ddc line for LVDS */
218 if ((dev->pdev->device == 0x5653) &&
219 (dev->pdev->subsystem_vendor == 0x1462) &&
220 (dev->pdev->subsystem_device == 0x0291)) {
221 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
222 i2c_bus->valid = false;
227 /* HIS X1300 is DVI+VGA, not DVI+DVI */
228 if ((dev->pdev->device == 0x7146) &&
229 (dev->pdev->subsystem_vendor == 0x17af) &&
230 (dev->pdev->subsystem_device == 0x2058)) {
231 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
235 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
236 if ((dev->pdev->device == 0x7142) &&
237 (dev->pdev->subsystem_vendor == 0x1458) &&
238 (dev->pdev->subsystem_device == 0x2134)) {
239 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
245 if ((dev->pdev->device == 0x71C5) &&
246 (dev->pdev->subsystem_vendor == 0x106b) &&
247 (dev->pdev->subsystem_device == 0x0080)) {
248 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
249 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
253 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
254 if ((dev->pdev->device == 0x9598) &&
255 (dev->pdev->subsystem_vendor == 0x1043) &&
256 (dev->pdev->subsystem_device == 0x01da)) {
257 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
258 *connector_type = DRM_MODE_CONNECTOR_DVII;
262 /* ASUS HD 3450 board lists the DVI port as HDMI */
263 if ((dev->pdev->device == 0x95C5) &&
264 (dev->pdev->subsystem_vendor == 0x1043) &&
265 (dev->pdev->subsystem_device == 0x01e2)) {
266 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
267 *connector_type = DRM_MODE_CONNECTOR_DVII;
271 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
272 * HDMI + VGA reporting as HDMI
274 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
275 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
276 *connector_type = DRM_MODE_CONNECTOR_VGA;
281 /* Acer laptop reports DVI-D as DVI-I */
282 if ((dev->pdev->device == 0x95c4) &&
283 (dev->pdev->subsystem_vendor == 0x1025) &&
284 (dev->pdev->subsystem_device == 0x013c)) {
285 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
286 (supported_device == ATOM_DEVICE_DFP1_SUPPORT))
287 *connector_type = DRM_MODE_CONNECTOR_DVID;
290 /* XFX Pine Group device rv730 reports no VGA DDC lines
291 * even though they are wired up to record 0x93
293 if ((dev->pdev->device == 0x9498) &&
294 (dev->pdev->subsystem_vendor == 0x1682) &&
295 (dev->pdev->subsystem_device == 0x2452)) {
296 struct radeon_device *rdev = dev->dev_private;
297 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
302 const int supported_devices_connector_convert[] = {
303 DRM_MODE_CONNECTOR_Unknown,
304 DRM_MODE_CONNECTOR_VGA,
305 DRM_MODE_CONNECTOR_DVII,
306 DRM_MODE_CONNECTOR_DVID,
307 DRM_MODE_CONNECTOR_DVIA,
308 DRM_MODE_CONNECTOR_SVIDEO,
309 DRM_MODE_CONNECTOR_Composite,
310 DRM_MODE_CONNECTOR_LVDS,
311 DRM_MODE_CONNECTOR_Unknown,
312 DRM_MODE_CONNECTOR_Unknown,
313 DRM_MODE_CONNECTOR_HDMIA,
314 DRM_MODE_CONNECTOR_HDMIB,
315 DRM_MODE_CONNECTOR_Unknown,
316 DRM_MODE_CONNECTOR_Unknown,
317 DRM_MODE_CONNECTOR_9PinDIN,
318 DRM_MODE_CONNECTOR_DisplayPort
321 const uint16_t supported_devices_connector_object_id_convert[] = {
322 CONNECTOR_OBJECT_ID_NONE,
323 CONNECTOR_OBJECT_ID_VGA,
324 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
325 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
326 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
327 CONNECTOR_OBJECT_ID_COMPOSITE,
328 CONNECTOR_OBJECT_ID_SVIDEO,
329 CONNECTOR_OBJECT_ID_LVDS,
330 CONNECTOR_OBJECT_ID_9PIN_DIN,
331 CONNECTOR_OBJECT_ID_9PIN_DIN,
332 CONNECTOR_OBJECT_ID_DISPLAYPORT,
333 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
334 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
335 CONNECTOR_OBJECT_ID_SVIDEO
338 const int object_connector_convert[] = {
339 DRM_MODE_CONNECTOR_Unknown,
340 DRM_MODE_CONNECTOR_DVII,
341 DRM_MODE_CONNECTOR_DVII,
342 DRM_MODE_CONNECTOR_DVID,
343 DRM_MODE_CONNECTOR_DVID,
344 DRM_MODE_CONNECTOR_VGA,
345 DRM_MODE_CONNECTOR_Composite,
346 DRM_MODE_CONNECTOR_SVIDEO,
347 DRM_MODE_CONNECTOR_Unknown,
348 DRM_MODE_CONNECTOR_Unknown,
349 DRM_MODE_CONNECTOR_9PinDIN,
350 DRM_MODE_CONNECTOR_Unknown,
351 DRM_MODE_CONNECTOR_HDMIA,
352 DRM_MODE_CONNECTOR_HDMIB,
353 DRM_MODE_CONNECTOR_LVDS,
354 DRM_MODE_CONNECTOR_9PinDIN,
355 DRM_MODE_CONNECTOR_Unknown,
356 DRM_MODE_CONNECTOR_Unknown,
357 DRM_MODE_CONNECTOR_Unknown,
358 DRM_MODE_CONNECTOR_DisplayPort,
359 DRM_MODE_CONNECTOR_eDP,
360 DRM_MODE_CONNECTOR_Unknown
363 bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
365 struct radeon_device *rdev = dev->dev_private;
366 struct radeon_mode_info *mode_info = &rdev->mode_info;
367 struct atom_context *ctx = mode_info->atom_context;
368 int index = GetIndexIntoMasterTable(DATA, Object_Header);
369 u16 size, data_offset;
371 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
372 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
373 ATOM_OBJECT_HEADER *obj_header;
374 int i, j, path_size, device_support;
376 u16 igp_lane_info, conn_id, connector_object_id;
378 struct radeon_i2c_bus_rec ddc_bus;
379 struct radeon_gpio_rec gpio;
380 struct radeon_hpd hpd;
382 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
384 if (data_offset == 0)
390 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
391 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
392 (ctx->bios + data_offset +
393 le16_to_cpu(obj_header->usDisplayPathTableOffset));
394 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
395 (ctx->bios + data_offset +
396 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
397 device_support = le16_to_cpu(obj_header->usDeviceSupport);
400 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
401 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
402 ATOM_DISPLAY_OBJECT_PATH *path;
404 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
405 path_size += le16_to_cpu(path->usSize);
407 if (device_support & le16_to_cpu(path->usDeviceTag)) {
408 uint8_t con_obj_id, con_obj_num, con_obj_type;
411 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
414 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
417 (le16_to_cpu(path->usConnObjectId) &
418 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
420 /* TODO CV support */
421 if (le16_to_cpu(path->usDeviceTag) ==
422 ATOM_DEVICE_CV_SUPPORT)
426 if ((rdev->flags & RADEON_IS_IGP) &&
428 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
429 uint16_t igp_offset = 0;
430 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
433 GetIndexIntoMasterTable(DATA,
434 IntegratedSystemInfo);
436 atom_parse_data_header(ctx, index, &size, &frev,
441 (ATOM_INTEGRATED_SYSTEM_INFO_V2
442 *) (ctx->bios + igp_offset);
445 uint32_t slot_config, ct;
447 if (con_obj_num == 1)
456 ct = (slot_config >> 16) & 0xff;
458 object_connector_convert
460 connector_object_id = ct;
462 slot_config & 0xffff;
470 object_connector_convert[con_obj_id];
471 connector_object_id = con_obj_id;
474 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
477 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2);
479 uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
482 (le16_to_cpu(path->usGraphicObjIds[j]) &
483 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
485 (le16_to_cpu(path->usGraphicObjIds[j]) &
486 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
488 (le16_to_cpu(path->usGraphicObjIds[j]) &
489 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
491 /* FIXME: add support for router objects */
492 if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
493 if (enc_obj_num == 2)
498 radeon_add_atom_encoder(dev,
507 /* look up gpio for ddc, hpd */
508 if ((le16_to_cpu(path->usDeviceTag) &
509 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
510 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
511 if (le16_to_cpu(path->usConnObjectId) ==
512 le16_to_cpu(con_obj->asObjects[j].
514 ATOM_COMMON_RECORD_HEADER
516 (ATOM_COMMON_RECORD_HEADER
518 (ctx->bios + data_offset +
519 le16_to_cpu(con_obj->
522 ATOM_I2C_RECORD *i2c_record;
523 ATOM_HPD_INT_RECORD *hpd_record;
524 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
525 hpd.hpd = RADEON_HPD_NONE;
527 while (record->ucRecordType > 0
530 ATOM_MAX_OBJECT_RECORD_NUMBER) {
531 switch (record->ucRecordType) {
532 case ATOM_I2C_RECORD_TYPE:
537 (ATOM_I2C_ID_CONFIG_ACCESS *)
538 &i2c_record->sucI2cId;
539 ddc_bus = radeon_lookup_i2c_gpio(rdev,
543 case ATOM_HPD_INT_RECORD_TYPE:
545 (ATOM_HPD_INT_RECORD *)
547 gpio = radeon_lookup_gpio(rdev,
548 hpd_record->ucHPDIntGPIOID);
549 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
550 hpd.plugged_state = hpd_record->ucPlugged_PinState;
554 (ATOM_COMMON_RECORD_HEADER
564 hpd.hpd = RADEON_HPD_NONE;
565 ddc_bus.valid = false;
568 conn_id = le16_to_cpu(path->usConnObjectId);
570 if (!radeon_atom_apply_quirks
571 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
572 &ddc_bus, &conn_id, &hpd))
575 radeon_add_atom_connector(dev,
579 connector_type, &ddc_bus,
580 linkb, igp_lane_info,
587 radeon_link_encoder_connector(dev);
592 static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
596 struct radeon_device *rdev = dev->dev_private;
598 if (rdev->flags & RADEON_IS_IGP) {
599 return supported_devices_connector_object_id_convert
601 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
602 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
603 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
604 struct radeon_mode_info *mode_info = &rdev->mode_info;
605 struct atom_context *ctx = mode_info->atom_context;
606 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
607 uint16_t size, data_offset;
609 ATOM_XTMDS_INFO *xtmds;
611 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
612 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
614 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
615 if (connector_type == DRM_MODE_CONNECTOR_DVII)
616 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
618 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
620 if (connector_type == DRM_MODE_CONNECTOR_DVII)
621 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
623 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
626 return supported_devices_connector_object_id_convert
631 struct bios_connector {
636 struct radeon_i2c_bus_rec ddc_bus;
637 struct radeon_hpd hpd;
640 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
644 struct radeon_device *rdev = dev->dev_private;
645 struct radeon_mode_info *mode_info = &rdev->mode_info;
646 struct atom_context *ctx = mode_info->atom_context;
647 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
648 uint16_t size, data_offset;
650 uint16_t device_support;
652 union atom_supported_devices *supported_devices;
653 int i, j, max_device;
654 struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
656 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
659 (union atom_supported_devices *)(ctx->bios + data_offset);
661 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
664 max_device = ATOM_MAX_SUPPORTED_DEVICE;
666 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
668 for (i = 0; i < max_device; i++) {
669 ATOM_CONNECTOR_INFO_I2C ci =
670 supported_devices->info.asConnInfo[i];
672 bios_connectors[i].valid = false;
674 if (!(device_support & (1 << i))) {
678 if (i == ATOM_DEVICE_CV_INDEX) {
679 DRM_DEBUG("Skipping Component Video\n");
683 bios_connectors[i].connector_type =
684 supported_devices_connector_convert[ci.sucConnectorInfo.
688 if (bios_connectors[i].connector_type ==
689 DRM_MODE_CONNECTOR_Unknown)
692 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
694 bios_connectors[i].line_mux =
695 ci.sucI2cId.ucAccess;
697 /* give tv unique connector ids */
698 if (i == ATOM_DEVICE_TV1_INDEX) {
699 bios_connectors[i].ddc_bus.valid = false;
700 bios_connectors[i].line_mux = 50;
701 } else if (i == ATOM_DEVICE_TV2_INDEX) {
702 bios_connectors[i].ddc_bus.valid = false;
703 bios_connectors[i].line_mux = 51;
704 } else if (i == ATOM_DEVICE_CV_INDEX) {
705 bios_connectors[i].ddc_bus.valid = false;
706 bios_connectors[i].line_mux = 52;
708 bios_connectors[i].ddc_bus =
709 radeon_lookup_i2c_gpio(rdev,
710 bios_connectors[i].line_mux);
712 if ((crev > 1) && (frev > 1)) {
713 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
716 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
719 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
722 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
726 if (i == ATOM_DEVICE_DFP1_INDEX)
727 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
728 else if (i == ATOM_DEVICE_DFP2_INDEX)
729 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
731 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
734 /* Always set the connector type to VGA for CRT1/CRT2. if they are
735 * shared with a DVI port, we'll pick up the DVI connector when we
736 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
738 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
739 bios_connectors[i].connector_type =
740 DRM_MODE_CONNECTOR_VGA;
742 if (!radeon_atom_apply_quirks
743 (dev, (1 << i), &bios_connectors[i].connector_type,
744 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
745 &bios_connectors[i].hpd))
748 bios_connectors[i].valid = true;
749 bios_connectors[i].devices = (1 << i);
751 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
752 radeon_add_atom_encoder(dev,
753 radeon_get_encoder_id(dev,
758 radeon_add_legacy_encoder(dev,
759 radeon_get_encoder_id(dev,
765 /* combine shared connectors */
766 for (i = 0; i < max_device; i++) {
767 if (bios_connectors[i].valid) {
768 for (j = 0; j < max_device; j++) {
769 if (bios_connectors[j].valid && (i != j)) {
770 if (bios_connectors[i].line_mux ==
771 bios_connectors[j].line_mux) {
772 /* make sure not to combine LVDS */
773 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
774 bios_connectors[i].line_mux = 53;
775 bios_connectors[i].ddc_bus.valid = false;
778 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
779 bios_connectors[j].line_mux = 53;
780 bios_connectors[j].ddc_bus.valid = false;
783 /* combine analog and digital for DVI-I */
784 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
785 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
786 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
787 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
788 bios_connectors[i].devices |=
789 bios_connectors[j].devices;
790 bios_connectors[i].connector_type =
791 DRM_MODE_CONNECTOR_DVII;
792 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
793 bios_connectors[i].hpd =
794 bios_connectors[j].hpd;
795 bios_connectors[j].valid = false;
803 /* add the connectors */
804 for (i = 0; i < max_device; i++) {
805 if (bios_connectors[i].valid) {
806 uint16_t connector_object_id =
807 atombios_get_connector_object_id(dev,
808 bios_connectors[i].connector_type,
809 bios_connectors[i].devices);
810 radeon_add_atom_connector(dev,
811 bios_connectors[i].line_mux,
812 bios_connectors[i].devices,
815 &bios_connectors[i].ddc_bus,
818 &bios_connectors[i].hpd);
822 radeon_link_encoder_connector(dev);
827 union firmware_info {
828 ATOM_FIRMWARE_INFO info;
829 ATOM_FIRMWARE_INFO_V1_2 info_12;
830 ATOM_FIRMWARE_INFO_V1_3 info_13;
831 ATOM_FIRMWARE_INFO_V1_4 info_14;
834 bool radeon_atom_get_clock_info(struct drm_device *dev)
836 struct radeon_device *rdev = dev->dev_private;
837 struct radeon_mode_info *mode_info = &rdev->mode_info;
838 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
839 union firmware_info *firmware_info;
841 struct radeon_pll *p1pll = &rdev->clock.p1pll;
842 struct radeon_pll *p2pll = &rdev->clock.p2pll;
843 struct radeon_pll *spll = &rdev->clock.spll;
844 struct radeon_pll *mpll = &rdev->clock.mpll;
845 uint16_t data_offset;
847 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
848 &crev, &data_offset);
851 (union firmware_info *)(mode_info->atom_context->bios +
856 p1pll->reference_freq =
857 le16_to_cpu(firmware_info->info.usReferenceClock);
858 p1pll->reference_div = 0;
862 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
865 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
867 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
869 if (p1pll->pll_out_min == 0) {
870 if (ASIC_IS_AVIVO(rdev))
871 p1pll->pll_out_min = 64800;
873 p1pll->pll_out_min = 20000;
874 } else if (p1pll->pll_out_min > 64800) {
875 /* Limiting the pll output range is a good thing generally as
876 * it limits the number of possible pll combinations for a given
877 * frequency presumably to the ones that work best on each card.
878 * However, certain duallink DVI monitors seem to like
879 * pll combinations that would be limited by this at least on
880 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
884 p1pll->pll_out_min = 64800;
888 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
890 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
895 spll->reference_freq =
896 le16_to_cpu(firmware_info->info.usReferenceClock);
897 spll->reference_div = 0;
900 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
902 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
905 if (spll->pll_out_min == 0) {
906 if (ASIC_IS_AVIVO(rdev))
907 spll->pll_out_min = 64800;
909 spll->pll_out_min = 20000;
913 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
915 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
918 mpll->reference_freq =
919 le16_to_cpu(firmware_info->info.usReferenceClock);
920 mpll->reference_div = 0;
923 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
925 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
928 if (mpll->pll_out_min == 0) {
929 if (ASIC_IS_AVIVO(rdev))
930 mpll->pll_out_min = 64800;
932 mpll->pll_out_min = 20000;
936 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
938 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
940 rdev->clock.default_sclk =
941 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
942 rdev->clock.default_mclk =
943 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
951 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
952 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
955 bool radeon_atombios_sideport_present(struct radeon_device *rdev)
957 struct radeon_mode_info *mode_info = &rdev->mode_info;
958 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
959 union igp_info *igp_info;
963 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
964 &crev, &data_offset);
966 igp_info = (union igp_info *)(mode_info->atom_context->bios +
972 if (igp_info->info.ucMemoryType & 0xf0)
976 if (igp_info->info_2.ucMemoryType & 0x0f)
980 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
987 bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
988 struct radeon_encoder_int_tmds *tmds)
990 struct drm_device *dev = encoder->base.dev;
991 struct radeon_device *rdev = dev->dev_private;
992 struct radeon_mode_info *mode_info = &rdev->mode_info;
993 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
994 uint16_t data_offset;
995 struct _ATOM_TMDS_INFO *tmds_info;
1000 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
1001 &crev, &data_offset);
1004 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1008 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1009 for (i = 0; i < 4; i++) {
1010 tmds->tmds_pll[i].freq =
1011 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1012 tmds->tmds_pll[i].value =
1013 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1014 tmds->tmds_pll[i].value |=
1015 (tmds_info->asMiscInfo[i].
1016 ucPLL_VCO_Gain & 0x3f) << 6;
1017 tmds->tmds_pll[i].value |=
1018 (tmds_info->asMiscInfo[i].
1019 ucPLL_DutyCycle & 0xf) << 12;
1020 tmds->tmds_pll[i].value |=
1021 (tmds_info->asMiscInfo[i].
1022 ucPLL_VoltageSwing & 0xf) << 16;
1024 DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
1025 tmds->tmds_pll[i].freq,
1026 tmds->tmds_pll[i].value);
1028 if (maxfreq == tmds->tmds_pll[i].freq) {
1029 tmds->tmds_pll[i].freq = 0xffffffff;
1038 static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
1043 struct drm_device *dev = encoder->base.dev;
1044 struct radeon_device *rdev = dev->dev_private;
1045 struct radeon_mode_info *mode_info = &rdev->mode_info;
1046 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
1047 uint16_t data_offset;
1048 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1050 struct radeon_atom_ss *ss = NULL;
1053 if (id > ATOM_MAX_SS_ENTRY)
1056 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
1057 &crev, &data_offset);
1060 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
1064 kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
1069 for (i = 0; i < ATOM_MAX_SS_ENTRY; i++) {
1070 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1072 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1073 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1074 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1075 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1076 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1077 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
1086 struct _ATOM_LVDS_INFO info;
1087 struct _ATOM_LVDS_INFO_V12 info_12;
1090 struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1094 struct drm_device *dev = encoder->base.dev;
1095 struct radeon_device *rdev = dev->dev_private;
1096 struct radeon_mode_info *mode_info = &rdev->mode_info;
1097 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
1098 uint16_t data_offset, misc;
1099 union lvds_info *lvds_info;
1101 struct radeon_encoder_atom_dig *lvds = NULL;
1103 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
1104 &crev, &data_offset);
1107 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
1111 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1116 lvds->native_mode.clock =
1117 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
1118 lvds->native_mode.hdisplay =
1119 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
1120 lvds->native_mode.vdisplay =
1121 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
1122 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1123 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1124 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1125 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1126 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1127 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1128 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1129 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1130 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1131 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
1132 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1133 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
1134 lvds->panel_pwr_delay =
1135 le16_to_cpu(lvds_info->info.usOffDelayInMs);
1136 lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
1138 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1139 if (misc & ATOM_VSYNC_POLARITY)
1140 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1141 if (misc & ATOM_HSYNC_POLARITY)
1142 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1143 if (misc & ATOM_COMPOSITESYNC)
1144 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1145 if (misc & ATOM_INTERLACE)
1146 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1147 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1148 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1150 /* set crtc values */
1151 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
1153 lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
1155 encoder->native_mode = lvds->native_mode;
1160 struct radeon_encoder_primary_dac *
1161 radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1163 struct drm_device *dev = encoder->base.dev;
1164 struct radeon_device *rdev = dev->dev_private;
1165 struct radeon_mode_info *mode_info = &rdev->mode_info;
1166 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1167 uint16_t data_offset;
1168 struct _COMPASSIONATE_DATA *dac_info;
1171 struct radeon_encoder_primary_dac *p_dac = NULL;
1173 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1175 dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
1178 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1183 bg = dac_info->ucDAC1_BG_Adjustment;
1184 dac = dac_info->ucDAC1_DAC_Adjustment;
1185 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1191 bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
1192 struct drm_display_mode *mode)
1194 struct radeon_mode_info *mode_info = &rdev->mode_info;
1195 ATOM_ANALOG_TV_INFO *tv_info;
1196 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1197 ATOM_DTD_FORMAT *dtd_timings;
1198 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1200 u16 data_offset, misc;
1202 atom_parse_data_header(mode_info->atom_context, data_index, NULL, &frev, &crev, &data_offset);
1206 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1207 if (index > MAX_SUPPORTED_TV_TIMING)
1210 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1211 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1212 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1213 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1214 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
1216 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1217 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1218 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1219 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1220 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
1223 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1224 if (misc & ATOM_VSYNC_POLARITY)
1225 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1226 if (misc & ATOM_HSYNC_POLARITY)
1227 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1228 if (misc & ATOM_COMPOSITESYNC)
1229 mode->flags |= DRM_MODE_FLAG_CSYNC;
1230 if (misc & ATOM_INTERLACE)
1231 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1232 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1233 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1235 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
1238 /* PAL timings appear to have wrong values for totals */
1239 mode->crtc_htotal -= 1;
1240 mode->crtc_vtotal -= 1;
1244 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
1245 if (index > MAX_SUPPORTED_TV_TIMING_V1_2)
1248 dtd_timings = &tv_info_v1_2->aModeTimings[index];
1249 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1250 le16_to_cpu(dtd_timings->usHBlanking_Time);
1251 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1252 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1253 le16_to_cpu(dtd_timings->usHSyncOffset);
1254 mode->crtc_hsync_end = mode->crtc_hsync_start +
1255 le16_to_cpu(dtd_timings->usHSyncWidth);
1257 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1258 le16_to_cpu(dtd_timings->usVBlanking_Time);
1259 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1260 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1261 le16_to_cpu(dtd_timings->usVSyncOffset);
1262 mode->crtc_vsync_end = mode->crtc_vsync_start +
1263 le16_to_cpu(dtd_timings->usVSyncWidth);
1266 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1267 if (misc & ATOM_VSYNC_POLARITY)
1268 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1269 if (misc & ATOM_HSYNC_POLARITY)
1270 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1271 if (misc & ATOM_COMPOSITESYNC)
1272 mode->flags |= DRM_MODE_FLAG_CSYNC;
1273 if (misc & ATOM_INTERLACE)
1274 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1275 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1276 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1278 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
1285 radeon_atombios_get_tv_info(struct radeon_device *rdev)
1287 struct radeon_mode_info *mode_info = &rdev->mode_info;
1288 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1289 uint16_t data_offset;
1291 struct _ATOM_ANALOG_TV_INFO *tv_info;
1292 enum radeon_tv_std tv_std = TV_STD_NTSC;
1294 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1296 tv_info = (struct _ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1298 switch (tv_info->ucTV_BootUpDefaultStandard) {
1300 tv_std = TV_STD_NTSC;
1301 DRM_INFO("Default TV standard: NTSC\n");
1304 tv_std = TV_STD_NTSC_J;
1305 DRM_INFO("Default TV standard: NTSC-J\n");
1308 tv_std = TV_STD_PAL;
1309 DRM_INFO("Default TV standard: PAL\n");
1312 tv_std = TV_STD_PAL_M;
1313 DRM_INFO("Default TV standard: PAL-M\n");
1316 tv_std = TV_STD_PAL_N;
1317 DRM_INFO("Default TV standard: PAL-N\n");
1320 tv_std = TV_STD_PAL_CN;
1321 DRM_INFO("Default TV standard: PAL-CN\n");
1324 tv_std = TV_STD_PAL_60;
1325 DRM_INFO("Default TV standard: PAL-60\n");
1328 tv_std = TV_STD_SECAM;
1329 DRM_INFO("Default TV standard: SECAM\n");
1332 tv_std = TV_STD_NTSC;
1333 DRM_INFO("Unknown TV standard; defaulting to NTSC\n");
1339 struct radeon_encoder_tv_dac *
1340 radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1342 struct drm_device *dev = encoder->base.dev;
1343 struct radeon_device *rdev = dev->dev_private;
1344 struct radeon_mode_info *mode_info = &rdev->mode_info;
1345 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1346 uint16_t data_offset;
1347 struct _COMPASSIONATE_DATA *dac_info;
1350 struct radeon_encoder_tv_dac *tv_dac = NULL;
1352 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1354 dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
1357 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1362 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1363 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1364 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1366 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1367 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1368 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1370 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1371 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1372 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1374 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
1379 void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
1381 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
1382 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
1384 args.ucEnable = enable;
1386 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1389 void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable)
1391 ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args;
1392 int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt);
1394 args.ucEnable = enable;
1396 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1399 uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
1401 GET_ENGINE_CLOCK_PS_ALLOCATION args;
1402 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
1404 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1405 return args.ulReturnEngineClock;
1408 uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
1410 GET_MEMORY_CLOCK_PS_ALLOCATION args;
1411 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
1413 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1414 return args.ulReturnMemoryClock;
1417 void radeon_atom_set_engine_clock(struct radeon_device *rdev,
1420 SET_ENGINE_CLOCK_PS_ALLOCATION args;
1421 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
1423 args.ulTargetEngineClock = eng_clock; /* 10 khz */
1425 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1428 void radeon_atom_set_memory_clock(struct radeon_device *rdev,
1431 SET_MEMORY_CLOCK_PS_ALLOCATION args;
1432 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
1434 if (rdev->flags & RADEON_IS_IGP)
1437 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
1439 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1442 void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
1444 struct radeon_device *rdev = dev->dev_private;
1445 uint32_t bios_2_scratch, bios_6_scratch;
1447 if (rdev->family >= CHIP_R600) {
1448 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
1449 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1451 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
1452 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1455 /* let the bios control the backlight */
1456 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
1458 /* tell the bios not to handle mode switching */
1459 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
1461 if (rdev->family >= CHIP_R600) {
1462 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
1463 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1465 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
1466 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1471 void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
1473 uint32_t scratch_reg;
1476 if (rdev->family >= CHIP_R600)
1477 scratch_reg = R600_BIOS_0_SCRATCH;
1479 scratch_reg = RADEON_BIOS_0_SCRATCH;
1481 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
1482 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
1485 void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
1487 uint32_t scratch_reg;
1490 if (rdev->family >= CHIP_R600)
1491 scratch_reg = R600_BIOS_0_SCRATCH;
1493 scratch_reg = RADEON_BIOS_0_SCRATCH;
1495 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
1496 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
1499 void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
1501 struct drm_device *dev = encoder->dev;
1502 struct radeon_device *rdev = dev->dev_private;
1503 uint32_t bios_6_scratch;
1505 if (rdev->family >= CHIP_R600)
1506 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1508 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1511 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
1513 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
1515 if (rdev->family >= CHIP_R600)
1516 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1518 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1521 /* at some point we may want to break this out into individual functions */
1523 radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
1524 struct drm_encoder *encoder,
1527 struct drm_device *dev = connector->dev;
1528 struct radeon_device *rdev = dev->dev_private;
1529 struct radeon_connector *radeon_connector =
1530 to_radeon_connector(connector);
1531 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1532 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
1534 if (rdev->family >= CHIP_R600) {
1535 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
1536 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
1537 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1539 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
1540 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
1541 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1544 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
1545 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
1547 DRM_DEBUG("TV1 connected\n");
1548 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
1549 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
1551 DRM_DEBUG("TV1 disconnected\n");
1552 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
1553 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
1554 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
1557 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
1558 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
1560 DRM_DEBUG("CV connected\n");
1561 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
1562 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
1564 DRM_DEBUG("CV disconnected\n");
1565 bios_0_scratch &= ~ATOM_S0_CV_MASK;
1566 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
1567 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
1570 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
1571 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
1573 DRM_DEBUG("LCD1 connected\n");
1574 bios_0_scratch |= ATOM_S0_LCD1;
1575 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
1576 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
1578 DRM_DEBUG("LCD1 disconnected\n");
1579 bios_0_scratch &= ~ATOM_S0_LCD1;
1580 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
1581 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
1584 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
1585 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
1587 DRM_DEBUG("CRT1 connected\n");
1588 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
1589 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
1590 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
1592 DRM_DEBUG("CRT1 disconnected\n");
1593 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
1594 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
1595 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
1598 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
1599 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
1601 DRM_DEBUG("CRT2 connected\n");
1602 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
1603 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
1604 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
1606 DRM_DEBUG("CRT2 disconnected\n");
1607 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
1608 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
1609 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
1612 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
1613 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
1615 DRM_DEBUG("DFP1 connected\n");
1616 bios_0_scratch |= ATOM_S0_DFP1;
1617 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
1618 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
1620 DRM_DEBUG("DFP1 disconnected\n");
1621 bios_0_scratch &= ~ATOM_S0_DFP1;
1622 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
1623 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
1626 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
1627 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
1629 DRM_DEBUG("DFP2 connected\n");
1630 bios_0_scratch |= ATOM_S0_DFP2;
1631 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
1632 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
1634 DRM_DEBUG("DFP2 disconnected\n");
1635 bios_0_scratch &= ~ATOM_S0_DFP2;
1636 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
1637 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
1640 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
1641 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
1643 DRM_DEBUG("DFP3 connected\n");
1644 bios_0_scratch |= ATOM_S0_DFP3;
1645 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
1646 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
1648 DRM_DEBUG("DFP3 disconnected\n");
1649 bios_0_scratch &= ~ATOM_S0_DFP3;
1650 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
1651 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
1654 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
1655 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
1657 DRM_DEBUG("DFP4 connected\n");
1658 bios_0_scratch |= ATOM_S0_DFP4;
1659 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
1660 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
1662 DRM_DEBUG("DFP4 disconnected\n");
1663 bios_0_scratch &= ~ATOM_S0_DFP4;
1664 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
1665 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
1668 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
1669 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
1671 DRM_DEBUG("DFP5 connected\n");
1672 bios_0_scratch |= ATOM_S0_DFP5;
1673 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
1674 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
1676 DRM_DEBUG("DFP5 disconnected\n");
1677 bios_0_scratch &= ~ATOM_S0_DFP5;
1678 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
1679 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
1683 if (rdev->family >= CHIP_R600) {
1684 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
1685 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
1686 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1688 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
1689 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
1690 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1695 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
1697 struct drm_device *dev = encoder->dev;
1698 struct radeon_device *rdev = dev->dev_private;
1699 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1700 uint32_t bios_3_scratch;
1702 if (rdev->family >= CHIP_R600)
1703 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
1705 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
1707 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
1708 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
1709 bios_3_scratch |= (crtc << 18);
1711 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
1712 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
1713 bios_3_scratch |= (crtc << 24);
1715 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
1716 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
1717 bios_3_scratch |= (crtc << 16);
1719 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
1720 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
1721 bios_3_scratch |= (crtc << 20);
1723 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1724 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
1725 bios_3_scratch |= (crtc << 17);
1727 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
1728 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
1729 bios_3_scratch |= (crtc << 19);
1731 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
1732 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
1733 bios_3_scratch |= (crtc << 23);
1735 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
1736 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
1737 bios_3_scratch |= (crtc << 25);
1740 if (rdev->family >= CHIP_R600)
1741 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
1743 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
1747 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
1749 struct drm_device *dev = encoder->dev;
1750 struct radeon_device *rdev = dev->dev_private;
1751 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1752 uint32_t bios_2_scratch;
1754 if (rdev->family >= CHIP_R600)
1755 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
1757 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
1759 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
1761 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
1763 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
1765 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
1767 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
1769 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
1771 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
1773 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
1775 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
1777 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
1779 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
1781 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
1783 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1785 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
1787 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
1789 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
1791 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
1793 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
1795 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
1797 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
1799 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
1801 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
1803 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
1805 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
1807 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
1809 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
1811 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
1813 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
1815 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
1817 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
1820 if (rdev->family >= CHIP_R600)
1821 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
1823 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);