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);
52 /* from radeon_legacy_encoder.c */
54 radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id,
55 uint32_t supported_device);
57 union atom_supported_devices {
58 struct _ATOM_SUPPORTED_DEVICES_INFO info;
59 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
60 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
63 static inline struct radeon_i2c_bus_rec radeon_lookup_gpio(struct drm_device
66 struct radeon_device *rdev = dev->dev_private;
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;
74 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
77 atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset);
79 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
81 gpio = i2c_info->asGPIO_Info[id];
83 i2c.mask_clk_reg = le16_to_cpu(gpio.usClkMaskRegisterIndex) * 4;
84 i2c.mask_data_reg = le16_to_cpu(gpio.usDataMaskRegisterIndex) * 4;
85 i2c.put_clk_reg = le16_to_cpu(gpio.usClkEnRegisterIndex) * 4;
86 i2c.put_data_reg = le16_to_cpu(gpio.usDataEnRegisterIndex) * 4;
87 i2c.get_clk_reg = le16_to_cpu(gpio.usClkY_RegisterIndex) * 4;
88 i2c.get_data_reg = le16_to_cpu(gpio.usDataY_RegisterIndex) * 4;
89 i2c.a_clk_reg = le16_to_cpu(gpio.usClkA_RegisterIndex) * 4;
90 i2c.a_data_reg = le16_to_cpu(gpio.usDataA_RegisterIndex) * 4;
91 i2c.mask_clk_mask = (1 << gpio.ucClkMaskShift);
92 i2c.mask_data_mask = (1 << gpio.ucDataMaskShift);
93 i2c.put_clk_mask = (1 << gpio.ucClkEnShift);
94 i2c.put_data_mask = (1 << gpio.ucDataEnShift);
95 i2c.get_clk_mask = (1 << gpio.ucClkY_Shift);
96 i2c.get_data_mask = (1 << gpio.ucDataY_Shift);
97 i2c.a_clk_mask = (1 << gpio.ucClkA_Shift);
98 i2c.a_data_mask = (1 << gpio.ucDataA_Shift);
104 static bool radeon_atom_apply_quirks(struct drm_device *dev,
105 uint32_t supported_device,
107 struct radeon_i2c_bus_rec *i2c_bus,
111 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
112 if ((dev->pdev->device == 0x791e) &&
113 (dev->pdev->subsystem_vendor == 0x1043) &&
114 (dev->pdev->subsystem_device == 0x826d)) {
115 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
116 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
117 *connector_type = DRM_MODE_CONNECTOR_DVID;
120 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
121 if ((dev->pdev->device == 0x7941) &&
122 (dev->pdev->subsystem_vendor == 0x147b) &&
123 (dev->pdev->subsystem_device == 0x2412)) {
124 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
128 /* Falcon NW laptop lists vga ddc line for LVDS */
129 if ((dev->pdev->device == 0x5653) &&
130 (dev->pdev->subsystem_vendor == 0x1462) &&
131 (dev->pdev->subsystem_device == 0x0291)) {
132 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
133 i2c_bus->valid = false;
138 /* HIS X1300 is DVI+VGA, not DVI+DVI */
139 if ((dev->pdev->device == 0x7146) &&
140 (dev->pdev->subsystem_vendor == 0x17af) &&
141 (dev->pdev->subsystem_device == 0x2058)) {
142 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
147 if ((dev->pdev->device == 0x71C5) &&
148 (dev->pdev->subsystem_vendor == 0x106b) &&
149 (dev->pdev->subsystem_device == 0x0080)) {
150 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
151 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
155 /* mac rv630, rv730, others */
156 if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
157 (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
158 *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
159 *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
162 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
163 if ((dev->pdev->device == 0x9598) &&
164 (dev->pdev->subsystem_vendor == 0x1043) &&
165 (dev->pdev->subsystem_device == 0x01da)) {
166 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
167 *connector_type = DRM_MODE_CONNECTOR_DVII;
171 /* ASUS HD 3600 board lists the DVI port as HDMI */
172 if ((dev->pdev->device == 0x9598) &&
173 (dev->pdev->subsystem_vendor == 0x1043) &&
174 (dev->pdev->subsystem_device == 0x01e4)) {
175 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
176 *connector_type = DRM_MODE_CONNECTOR_DVII;
180 /* ASUS HD 3450 board lists the DVI port as HDMI */
181 if ((dev->pdev->device == 0x95C5) &&
182 (dev->pdev->subsystem_vendor == 0x1043) &&
183 (dev->pdev->subsystem_device == 0x01e2)) {
184 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
185 *connector_type = DRM_MODE_CONNECTOR_DVII;
189 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
190 * HDMI + VGA reporting as HDMI
192 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
193 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
194 *connector_type = DRM_MODE_CONNECTOR_VGA;
202 const int supported_devices_connector_convert[] = {
203 DRM_MODE_CONNECTOR_Unknown,
204 DRM_MODE_CONNECTOR_VGA,
205 DRM_MODE_CONNECTOR_DVII,
206 DRM_MODE_CONNECTOR_DVID,
207 DRM_MODE_CONNECTOR_DVIA,
208 DRM_MODE_CONNECTOR_SVIDEO,
209 DRM_MODE_CONNECTOR_Composite,
210 DRM_MODE_CONNECTOR_LVDS,
211 DRM_MODE_CONNECTOR_Unknown,
212 DRM_MODE_CONNECTOR_Unknown,
213 DRM_MODE_CONNECTOR_HDMIA,
214 DRM_MODE_CONNECTOR_HDMIB,
215 DRM_MODE_CONNECTOR_Unknown,
216 DRM_MODE_CONNECTOR_Unknown,
217 DRM_MODE_CONNECTOR_9PinDIN,
218 DRM_MODE_CONNECTOR_DisplayPort
221 const uint16_t supported_devices_connector_object_id_convert[] = {
222 CONNECTOR_OBJECT_ID_NONE,
223 CONNECTOR_OBJECT_ID_VGA,
224 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
225 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
226 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
227 CONNECTOR_OBJECT_ID_COMPOSITE,
228 CONNECTOR_OBJECT_ID_SVIDEO,
229 CONNECTOR_OBJECT_ID_LVDS,
230 CONNECTOR_OBJECT_ID_9PIN_DIN,
231 CONNECTOR_OBJECT_ID_9PIN_DIN,
232 CONNECTOR_OBJECT_ID_DISPLAYPORT,
233 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
234 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
235 CONNECTOR_OBJECT_ID_SVIDEO
238 const int object_connector_convert[] = {
239 DRM_MODE_CONNECTOR_Unknown,
240 DRM_MODE_CONNECTOR_DVII,
241 DRM_MODE_CONNECTOR_DVII,
242 DRM_MODE_CONNECTOR_DVID,
243 DRM_MODE_CONNECTOR_DVID,
244 DRM_MODE_CONNECTOR_VGA,
245 DRM_MODE_CONNECTOR_Composite,
246 DRM_MODE_CONNECTOR_SVIDEO,
247 DRM_MODE_CONNECTOR_Unknown,
248 DRM_MODE_CONNECTOR_Unknown,
249 DRM_MODE_CONNECTOR_9PinDIN,
250 DRM_MODE_CONNECTOR_Unknown,
251 DRM_MODE_CONNECTOR_HDMIA,
252 DRM_MODE_CONNECTOR_HDMIB,
253 DRM_MODE_CONNECTOR_LVDS,
254 DRM_MODE_CONNECTOR_9PinDIN,
255 DRM_MODE_CONNECTOR_Unknown,
256 DRM_MODE_CONNECTOR_Unknown,
257 DRM_MODE_CONNECTOR_Unknown,
258 DRM_MODE_CONNECTOR_DisplayPort
261 bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
263 struct radeon_device *rdev = dev->dev_private;
264 struct radeon_mode_info *mode_info = &rdev->mode_info;
265 struct atom_context *ctx = mode_info->atom_context;
266 int index = GetIndexIntoMasterTable(DATA, Object_Header);
267 uint16_t size, data_offset;
268 uint8_t frev, crev, line_mux = 0;
269 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
270 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
271 ATOM_OBJECT_HEADER *obj_header;
272 int i, j, path_size, device_support;
274 uint16_t igp_lane_info, conn_id, connector_object_id;
276 struct radeon_i2c_bus_rec ddc_bus;
278 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
280 if (data_offset == 0)
286 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
287 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
288 (ctx->bios + data_offset +
289 le16_to_cpu(obj_header->usDisplayPathTableOffset));
290 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
291 (ctx->bios + data_offset +
292 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
293 device_support = le16_to_cpu(obj_header->usDeviceSupport);
296 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
297 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
298 ATOM_DISPLAY_OBJECT_PATH *path;
300 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
301 path_size += le16_to_cpu(path->usSize);
304 if (device_support & le16_to_cpu(path->usDeviceTag)) {
305 uint8_t con_obj_id, con_obj_num, con_obj_type;
308 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
311 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
314 (le16_to_cpu(path->usConnObjectId) &
315 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
317 /* TODO CV support */
318 if (le16_to_cpu(path->usDeviceTag) ==
319 ATOM_DEVICE_CV_SUPPORT)
323 if ((rdev->flags & RADEON_IS_IGP) &&
325 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
326 uint16_t igp_offset = 0;
327 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
330 GetIndexIntoMasterTable(DATA,
331 IntegratedSystemInfo);
333 atom_parse_data_header(ctx, index, &size, &frev,
338 (ATOM_INTEGRATED_SYSTEM_INFO_V2
339 *) (ctx->bios + igp_offset);
342 uint32_t slot_config, ct;
344 if (con_obj_num == 1)
353 ct = (slot_config >> 16) & 0xff;
355 object_connector_convert
357 connector_object_id = ct;
359 slot_config & 0xffff;
367 object_connector_convert[con_obj_id];
368 connector_object_id = con_obj_id;
371 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
374 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2);
376 uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
379 (le16_to_cpu(path->usGraphicObjIds[j]) &
380 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
382 (le16_to_cpu(path->usGraphicObjIds[j]) &
383 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
385 (le16_to_cpu(path->usGraphicObjIds[j]) &
386 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
388 /* FIXME: add support for router objects */
389 if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
390 if (enc_obj_num == 2)
395 radeon_add_atom_encoder(dev,
404 /* look up gpio for ddc */
405 if ((le16_to_cpu(path->usDeviceTag) &
406 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
408 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
409 if (le16_to_cpu(path->usConnObjectId) ==
410 le16_to_cpu(con_obj->asObjects[j].
412 ATOM_COMMON_RECORD_HEADER
414 (ATOM_COMMON_RECORD_HEADER
416 (ctx->bios + data_offset +
417 le16_to_cpu(con_obj->
420 ATOM_I2C_RECORD *i2c_record;
422 while (record->ucRecordType > 0
425 ATOM_MAX_OBJECT_RECORD_NUMBER) {
428 case ATOM_I2C_RECORD_TYPE:
439 (ATOM_COMMON_RECORD_HEADER
451 if ((le16_to_cpu(path->usDeviceTag) ==
452 ATOM_DEVICE_TV1_SUPPORT)
453 || (le16_to_cpu(path->usDeviceTag) ==
454 ATOM_DEVICE_TV2_SUPPORT)
455 || (le16_to_cpu(path->usDeviceTag) ==
456 ATOM_DEVICE_CV_SUPPORT))
457 ddc_bus.valid = false;
459 ddc_bus = radeon_lookup_gpio(dev, line_mux);
461 conn_id = le16_to_cpu(path->usConnObjectId);
463 if (!radeon_atom_apply_quirks
464 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
468 radeon_add_atom_connector(dev,
472 connector_type, &ddc_bus,
473 linkb, igp_lane_info,
474 connector_object_id);
479 radeon_link_encoder_connector(dev);
484 static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
488 struct radeon_device *rdev = dev->dev_private;
490 if (rdev->flags & RADEON_IS_IGP) {
491 return supported_devices_connector_object_id_convert
493 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
494 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
495 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
496 struct radeon_mode_info *mode_info = &rdev->mode_info;
497 struct atom_context *ctx = mode_info->atom_context;
498 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
499 uint16_t size, data_offset;
501 ATOM_XTMDS_INFO *xtmds;
503 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
504 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
506 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
507 if (connector_type == DRM_MODE_CONNECTOR_DVII)
508 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
510 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
512 if (connector_type == DRM_MODE_CONNECTOR_DVII)
513 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
515 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
518 return supported_devices_connector_object_id_convert
523 struct bios_connector {
528 struct radeon_i2c_bus_rec ddc_bus;
531 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
535 struct radeon_device *rdev = dev->dev_private;
536 struct radeon_mode_info *mode_info = &rdev->mode_info;
537 struct atom_context *ctx = mode_info->atom_context;
538 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
539 uint16_t size, data_offset;
541 uint16_t device_support;
543 union atom_supported_devices *supported_devices;
545 struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
547 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
550 (union atom_supported_devices *)(ctx->bios + data_offset);
552 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
554 for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
555 ATOM_CONNECTOR_INFO_I2C ci =
556 supported_devices->info.asConnInfo[i];
558 bios_connectors[i].valid = false;
560 if (!(device_support & (1 << i))) {
564 if (i == ATOM_DEVICE_CV_INDEX) {
565 DRM_DEBUG("Skipping Component Video\n");
569 bios_connectors[i].connector_type =
570 supported_devices_connector_convert[ci.sucConnectorInfo.
574 if (bios_connectors[i].connector_type ==
575 DRM_MODE_CONNECTOR_Unknown)
578 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
580 if ((rdev->family == CHIP_RS690) ||
581 (rdev->family == CHIP_RS740)) {
582 if ((i == ATOM_DEVICE_DFP2_INDEX)
583 && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 2))
584 bios_connectors[i].line_mux =
585 ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
586 else if ((i == ATOM_DEVICE_DFP3_INDEX)
587 && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 1))
588 bios_connectors[i].line_mux =
589 ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
591 bios_connectors[i].line_mux =
592 ci.sucI2cId.sbfAccess.bfI2C_LineMux;
594 bios_connectors[i].line_mux =
595 ci.sucI2cId.sbfAccess.bfI2C_LineMux;
597 /* give tv unique connector ids */
598 if (i == ATOM_DEVICE_TV1_INDEX) {
599 bios_connectors[i].ddc_bus.valid = false;
600 bios_connectors[i].line_mux = 50;
601 } else if (i == ATOM_DEVICE_TV2_INDEX) {
602 bios_connectors[i].ddc_bus.valid = false;
603 bios_connectors[i].line_mux = 51;
604 } else if (i == ATOM_DEVICE_CV_INDEX) {
605 bios_connectors[i].ddc_bus.valid = false;
606 bios_connectors[i].line_mux = 52;
608 bios_connectors[i].ddc_bus =
609 radeon_lookup_gpio(dev,
610 bios_connectors[i].line_mux);
612 /* Always set the connector type to VGA for CRT1/CRT2. if they are
613 * shared with a DVI port, we'll pick up the DVI connector when we
614 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
616 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
617 bios_connectors[i].connector_type =
618 DRM_MODE_CONNECTOR_VGA;
620 if (!radeon_atom_apply_quirks
621 (dev, (1 << i), &bios_connectors[i].connector_type,
622 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux))
625 bios_connectors[i].valid = true;
626 bios_connectors[i].devices = (1 << i);
628 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
629 radeon_add_atom_encoder(dev,
630 radeon_get_encoder_id(dev,
635 radeon_add_legacy_encoder(dev,
636 radeon_get_encoder_id(dev,
643 /* combine shared connectors */
644 for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
645 if (bios_connectors[i].valid) {
646 for (j = 0; j < ATOM_MAX_SUPPORTED_DEVICE; j++) {
647 if (bios_connectors[j].valid && (i != j)) {
648 if (bios_connectors[i].line_mux ==
649 bios_connectors[j].line_mux) {
650 if (((bios_connectors[i].
652 (ATOM_DEVICE_DFP_SUPPORT))
653 && (bios_connectors[j].
655 (ATOM_DEVICE_CRT_SUPPORT)))
657 ((bios_connectors[j].
659 (ATOM_DEVICE_DFP_SUPPORT))
660 && (bios_connectors[i].
662 (ATOM_DEVICE_CRT_SUPPORT)))) {
669 DRM_MODE_CONNECTOR_DVII;
679 /* add the connectors */
680 for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
681 if (bios_connectors[i].valid) {
682 uint16_t connector_object_id =
683 atombios_get_connector_object_id(dev,
684 bios_connectors[i].connector_type,
685 bios_connectors[i].devices);
686 radeon_add_atom_connector(dev,
687 bios_connectors[i].line_mux,
688 bios_connectors[i].devices,
691 &bios_connectors[i].ddc_bus,
693 connector_object_id);
697 radeon_link_encoder_connector(dev);
702 union firmware_info {
703 ATOM_FIRMWARE_INFO info;
704 ATOM_FIRMWARE_INFO_V1_2 info_12;
705 ATOM_FIRMWARE_INFO_V1_3 info_13;
706 ATOM_FIRMWARE_INFO_V1_4 info_14;
709 bool radeon_atom_get_clock_info(struct drm_device *dev)
711 struct radeon_device *rdev = dev->dev_private;
712 struct radeon_mode_info *mode_info = &rdev->mode_info;
713 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
714 union firmware_info *firmware_info;
716 struct radeon_pll *p1pll = &rdev->clock.p1pll;
717 struct radeon_pll *p2pll = &rdev->clock.p2pll;
718 struct radeon_pll *spll = &rdev->clock.spll;
719 struct radeon_pll *mpll = &rdev->clock.mpll;
720 uint16_t data_offset;
722 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
723 &crev, &data_offset);
726 (union firmware_info *)(mode_info->atom_context->bios +
731 p1pll->reference_freq =
732 le16_to_cpu(firmware_info->info.usReferenceClock);
733 p1pll->reference_div = 0;
737 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
740 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
742 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
744 if (p1pll->pll_out_min == 0) {
745 if (ASIC_IS_AVIVO(rdev))
746 p1pll->pll_out_min = 64800;
748 p1pll->pll_out_min = 20000;
749 } else if (p1pll->pll_out_min > 64800) {
750 /* Limiting the pll output range is a good thing generally as
751 * it limits the number of possible pll combinations for a given
752 * frequency presumably to the ones that work best on each card.
753 * However, certain duallink DVI monitors seem to like
754 * pll combinations that would be limited by this at least on
755 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
758 p1pll->pll_out_min = 64800;
762 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
764 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
769 spll->reference_freq =
770 le16_to_cpu(firmware_info->info.usReferenceClock);
771 spll->reference_div = 0;
774 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
776 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
779 if (spll->pll_out_min == 0) {
780 if (ASIC_IS_AVIVO(rdev))
781 spll->pll_out_min = 64800;
783 spll->pll_out_min = 20000;
787 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
789 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
792 mpll->reference_freq =
793 le16_to_cpu(firmware_info->info.usReferenceClock);
794 mpll->reference_div = 0;
797 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
799 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
802 if (mpll->pll_out_min == 0) {
803 if (ASIC_IS_AVIVO(rdev))
804 mpll->pll_out_min = 64800;
806 mpll->pll_out_min = 20000;
810 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
812 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
814 rdev->clock.default_sclk =
815 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
816 rdev->clock.default_mclk =
817 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
824 bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
825 struct radeon_encoder_int_tmds *tmds)
827 struct drm_device *dev = encoder->base.dev;
828 struct radeon_device *rdev = dev->dev_private;
829 struct radeon_mode_info *mode_info = &rdev->mode_info;
830 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
831 uint16_t data_offset;
832 struct _ATOM_TMDS_INFO *tmds_info;
837 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
838 &crev, &data_offset);
841 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
845 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
846 for (i = 0; i < 4; i++) {
847 tmds->tmds_pll[i].freq =
848 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
849 tmds->tmds_pll[i].value =
850 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
851 tmds->tmds_pll[i].value |=
852 (tmds_info->asMiscInfo[i].
853 ucPLL_VCO_Gain & 0x3f) << 6;
854 tmds->tmds_pll[i].value |=
855 (tmds_info->asMiscInfo[i].
856 ucPLL_DutyCycle & 0xf) << 12;
857 tmds->tmds_pll[i].value |=
858 (tmds_info->asMiscInfo[i].
859 ucPLL_VoltageSwing & 0xf) << 16;
861 DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
862 tmds->tmds_pll[i].freq,
863 tmds->tmds_pll[i].value);
865 if (maxfreq == tmds->tmds_pll[i].freq) {
866 tmds->tmds_pll[i].freq = 0xffffffff;
875 static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
880 struct drm_device *dev = encoder->base.dev;
881 struct radeon_device *rdev = dev->dev_private;
882 struct radeon_mode_info *mode_info = &rdev->mode_info;
883 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
884 uint16_t data_offset;
885 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
887 struct radeon_atom_ss *ss = NULL;
889 if (id > ATOM_MAX_SS_ENTRY)
892 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
893 &crev, &data_offset);
896 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
900 kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
905 ss->percentage = le16_to_cpu(ss_info->asSS_Info[id].usSpreadSpectrumPercentage);
906 ss->type = ss_info->asSS_Info[id].ucSpreadSpectrumType;
907 ss->step = ss_info->asSS_Info[id].ucSS_Step;
908 ss->delay = ss_info->asSS_Info[id].ucSS_Delay;
909 ss->range = ss_info->asSS_Info[id].ucSS_Range;
910 ss->refdiv = ss_info->asSS_Info[id].ucRecommendedRef_Div;
916 struct _ATOM_LVDS_INFO info;
917 struct _ATOM_LVDS_INFO_V12 info_12;
920 struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
924 struct drm_device *dev = encoder->base.dev;
925 struct radeon_device *rdev = dev->dev_private;
926 struct radeon_mode_info *mode_info = &rdev->mode_info;
927 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
928 uint16_t data_offset;
929 union lvds_info *lvds_info;
931 struct radeon_encoder_atom_dig *lvds = NULL;
933 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
934 &crev, &data_offset);
937 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
941 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
946 lvds->native_mode.clock =
947 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
948 lvds->native_mode.hdisplay =
949 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
950 lvds->native_mode.vdisplay =
951 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
952 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
953 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
954 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
955 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
956 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
957 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
958 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
959 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
960 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
961 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
962 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
963 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
964 lvds->panel_pwr_delay =
965 le16_to_cpu(lvds_info->info.usOffDelayInMs);
966 lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
967 /* set crtc values */
968 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
970 lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
972 encoder->native_mode = lvds->native_mode;
977 struct radeon_encoder_primary_dac *
978 radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
980 struct drm_device *dev = encoder->base.dev;
981 struct radeon_device *rdev = dev->dev_private;
982 struct radeon_mode_info *mode_info = &rdev->mode_info;
983 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
984 uint16_t data_offset;
985 struct _COMPASSIONATE_DATA *dac_info;
988 struct radeon_encoder_primary_dac *p_dac = NULL;
990 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
992 dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
995 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1000 bg = dac_info->ucDAC1_BG_Adjustment;
1001 dac = dac_info->ucDAC1_DAC_Adjustment;
1002 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1008 bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
1009 struct drm_display_mode *mode)
1011 struct radeon_mode_info *mode_info = &rdev->mode_info;
1012 ATOM_ANALOG_TV_INFO *tv_info;
1013 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1014 ATOM_DTD_FORMAT *dtd_timings;
1015 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1017 u16 data_offset, misc;
1019 atom_parse_data_header(mode_info->atom_context, data_index, NULL, &frev, &crev, &data_offset);
1023 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1024 if (index > MAX_SUPPORTED_TV_TIMING)
1027 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1028 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1029 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1030 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1031 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
1033 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1034 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1035 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1036 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1037 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
1040 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1041 if (misc & ATOM_VSYNC_POLARITY)
1042 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1043 if (misc & ATOM_HSYNC_POLARITY)
1044 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1045 if (misc & ATOM_COMPOSITESYNC)
1046 mode->flags |= DRM_MODE_FLAG_CSYNC;
1047 if (misc & ATOM_INTERLACE)
1048 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1049 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1050 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1052 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
1055 /* PAL timings appear to have wrong values for totals */
1056 mode->crtc_htotal -= 1;
1057 mode->crtc_vtotal -= 1;
1061 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
1062 if (index > MAX_SUPPORTED_TV_TIMING_V1_2)
1065 dtd_timings = &tv_info_v1_2->aModeTimings[index];
1066 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1067 le16_to_cpu(dtd_timings->usHBlanking_Time);
1068 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1069 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1070 le16_to_cpu(dtd_timings->usHSyncOffset);
1071 mode->crtc_hsync_end = mode->crtc_hsync_start +
1072 le16_to_cpu(dtd_timings->usHSyncWidth);
1074 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1075 le16_to_cpu(dtd_timings->usVBlanking_Time);
1076 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1077 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1078 le16_to_cpu(dtd_timings->usVSyncOffset);
1079 mode->crtc_vsync_end = mode->crtc_vsync_start +
1080 le16_to_cpu(dtd_timings->usVSyncWidth);
1083 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1084 if (misc & ATOM_VSYNC_POLARITY)
1085 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1086 if (misc & ATOM_HSYNC_POLARITY)
1087 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1088 if (misc & ATOM_COMPOSITESYNC)
1089 mode->flags |= DRM_MODE_FLAG_CSYNC;
1090 if (misc & ATOM_INTERLACE)
1091 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1092 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1093 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1095 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
1101 struct radeon_encoder_tv_dac *
1102 radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1104 struct drm_device *dev = encoder->base.dev;
1105 struct radeon_device *rdev = dev->dev_private;
1106 struct radeon_mode_info *mode_info = &rdev->mode_info;
1107 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1108 uint16_t data_offset;
1109 struct _COMPASSIONATE_DATA *dac_info;
1112 struct radeon_encoder_tv_dac *tv_dac = NULL;
1114 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1116 dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
1119 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1124 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1125 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1126 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1128 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1129 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1130 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1132 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1133 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1134 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1140 void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
1142 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
1143 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
1145 args.ucEnable = enable;
1147 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1150 void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable)
1152 ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args;
1153 int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt);
1155 args.ucEnable = enable;
1157 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1160 uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
1162 GET_ENGINE_CLOCK_PS_ALLOCATION args;
1163 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
1165 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1166 return args.ulReturnEngineClock;
1169 uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
1171 GET_MEMORY_CLOCK_PS_ALLOCATION args;
1172 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
1174 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1175 return args.ulReturnMemoryClock;
1178 void radeon_atom_set_engine_clock(struct radeon_device *rdev,
1181 SET_ENGINE_CLOCK_PS_ALLOCATION args;
1182 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
1184 args.ulTargetEngineClock = eng_clock; /* 10 khz */
1186 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1189 void radeon_atom_set_memory_clock(struct radeon_device *rdev,
1192 SET_MEMORY_CLOCK_PS_ALLOCATION args;
1193 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
1195 if (rdev->flags & RADEON_IS_IGP)
1198 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
1200 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1203 void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
1205 struct radeon_device *rdev = dev->dev_private;
1206 uint32_t bios_2_scratch, bios_6_scratch;
1208 if (rdev->family >= CHIP_R600) {
1209 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
1210 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1212 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
1213 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1216 /* let the bios control the backlight */
1217 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
1219 /* tell the bios not to handle mode switching */
1220 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
1222 if (rdev->family >= CHIP_R600) {
1223 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
1224 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1226 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
1227 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1232 void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
1234 uint32_t scratch_reg;
1237 if (rdev->family >= CHIP_R600)
1238 scratch_reg = R600_BIOS_0_SCRATCH;
1240 scratch_reg = RADEON_BIOS_0_SCRATCH;
1242 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
1243 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
1246 void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
1248 uint32_t scratch_reg;
1251 if (rdev->family >= CHIP_R600)
1252 scratch_reg = R600_BIOS_0_SCRATCH;
1254 scratch_reg = RADEON_BIOS_0_SCRATCH;
1256 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
1257 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
1260 void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
1262 struct drm_device *dev = encoder->dev;
1263 struct radeon_device *rdev = dev->dev_private;
1264 uint32_t bios_6_scratch;
1266 if (rdev->family >= CHIP_R600)
1267 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1269 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1272 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
1274 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
1276 if (rdev->family >= CHIP_R600)
1277 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1279 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1282 /* at some point we may want to break this out into individual functions */
1284 radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
1285 struct drm_encoder *encoder,
1288 struct drm_device *dev = connector->dev;
1289 struct radeon_device *rdev = dev->dev_private;
1290 struct radeon_connector *radeon_connector =
1291 to_radeon_connector(connector);
1292 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1293 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
1295 if (rdev->family >= CHIP_R600) {
1296 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
1297 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
1298 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1300 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
1301 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
1302 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1305 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
1306 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
1308 DRM_DEBUG("TV1 connected\n");
1309 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
1310 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
1312 DRM_DEBUG("TV1 disconnected\n");
1313 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
1314 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
1315 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
1318 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
1319 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
1321 DRM_DEBUG("CV connected\n");
1322 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
1323 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
1325 DRM_DEBUG("CV disconnected\n");
1326 bios_0_scratch &= ~ATOM_S0_CV_MASK;
1327 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
1328 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
1331 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
1332 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
1334 DRM_DEBUG("LCD1 connected\n");
1335 bios_0_scratch |= ATOM_S0_LCD1;
1336 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
1337 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
1339 DRM_DEBUG("LCD1 disconnected\n");
1340 bios_0_scratch &= ~ATOM_S0_LCD1;
1341 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
1342 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
1345 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
1346 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
1348 DRM_DEBUG("CRT1 connected\n");
1349 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
1350 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
1351 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
1353 DRM_DEBUG("CRT1 disconnected\n");
1354 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
1355 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
1356 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
1359 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
1360 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
1362 DRM_DEBUG("CRT2 connected\n");
1363 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
1364 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
1365 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
1367 DRM_DEBUG("CRT2 disconnected\n");
1368 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
1369 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
1370 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
1373 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
1374 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
1376 DRM_DEBUG("DFP1 connected\n");
1377 bios_0_scratch |= ATOM_S0_DFP1;
1378 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
1379 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
1381 DRM_DEBUG("DFP1 disconnected\n");
1382 bios_0_scratch &= ~ATOM_S0_DFP1;
1383 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
1384 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
1387 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
1388 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
1390 DRM_DEBUG("DFP2 connected\n");
1391 bios_0_scratch |= ATOM_S0_DFP2;
1392 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
1393 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
1395 DRM_DEBUG("DFP2 disconnected\n");
1396 bios_0_scratch &= ~ATOM_S0_DFP2;
1397 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
1398 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
1401 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
1402 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
1404 DRM_DEBUG("DFP3 connected\n");
1405 bios_0_scratch |= ATOM_S0_DFP3;
1406 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
1407 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
1409 DRM_DEBUG("DFP3 disconnected\n");
1410 bios_0_scratch &= ~ATOM_S0_DFP3;
1411 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
1412 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
1415 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
1416 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
1418 DRM_DEBUG("DFP4 connected\n");
1419 bios_0_scratch |= ATOM_S0_DFP4;
1420 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
1421 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
1423 DRM_DEBUG("DFP4 disconnected\n");
1424 bios_0_scratch &= ~ATOM_S0_DFP4;
1425 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
1426 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
1429 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
1430 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
1432 DRM_DEBUG("DFP5 connected\n");
1433 bios_0_scratch |= ATOM_S0_DFP5;
1434 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
1435 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
1437 DRM_DEBUG("DFP5 disconnected\n");
1438 bios_0_scratch &= ~ATOM_S0_DFP5;
1439 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
1440 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
1444 if (rdev->family >= CHIP_R600) {
1445 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
1446 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
1447 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1449 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
1450 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
1451 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1456 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
1458 struct drm_device *dev = encoder->dev;
1459 struct radeon_device *rdev = dev->dev_private;
1460 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1461 uint32_t bios_3_scratch;
1463 if (rdev->family >= CHIP_R600)
1464 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
1466 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
1468 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
1469 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
1470 bios_3_scratch |= (crtc << 18);
1472 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
1473 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
1474 bios_3_scratch |= (crtc << 24);
1476 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
1477 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
1478 bios_3_scratch |= (crtc << 16);
1480 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
1481 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
1482 bios_3_scratch |= (crtc << 20);
1484 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1485 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
1486 bios_3_scratch |= (crtc << 17);
1488 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
1489 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
1490 bios_3_scratch |= (crtc << 19);
1492 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
1493 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
1494 bios_3_scratch |= (crtc << 23);
1496 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
1497 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
1498 bios_3_scratch |= (crtc << 25);
1501 if (rdev->family >= CHIP_R600)
1502 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
1504 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
1508 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
1510 struct drm_device *dev = encoder->dev;
1511 struct radeon_device *rdev = dev->dev_private;
1512 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1513 uint32_t bios_2_scratch;
1515 if (rdev->family >= CHIP_R600)
1516 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
1518 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
1520 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
1522 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
1524 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
1526 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
1528 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
1530 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
1532 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
1534 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
1536 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
1538 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
1540 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
1542 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
1544 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1546 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
1548 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
1550 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
1552 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
1554 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
1556 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
1558 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
1560 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
1562 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
1564 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
1566 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
1568 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
1570 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
1572 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
1574 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
1576 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
1578 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
1581 if (rdev->family >= CHIP_R600)
1582 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
1584 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);