blob: 0802b30879d988253a257e6d62bbefcbd4ea0f95 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
22 *
23 * Authors: Dave Airlie
24 * Alex Deucher
25 */
26#include "drmP.h"
27#include "radeon_drm.h"
28#include "radeon.h"
29
30#include "atom.h"
31#include "atom-bits.h"
32
33/* from radeon_encoder.c */
34extern uint32_t
35radeon_get_encoder_id(struct drm_device *dev, uint32_t supported_device,
36 uint8_t dac);
37extern void radeon_link_encoder_connector(struct drm_device *dev);
38extern void
39radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_id,
40 uint32_t supported_device);
41
42/* from radeon_connector.c */
43extern void
44radeon_add_atom_connector(struct drm_device *dev,
45 uint32_t connector_id,
46 uint32_t supported_device,
47 int connector_type,
48 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -050049 bool linkb, uint32_t igp_lane_info,
50 uint16_t connector_object_id);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020051
52/* from radeon_legacy_encoder.c */
53extern void
54radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id,
55 uint32_t supported_device);
56
57union 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;
61};
62
63static inline struct radeon_i2c_bus_rec radeon_lookup_gpio(struct drm_device
64 *dev, uint8_t id)
65{
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;
72 uint16_t data_offset;
73
74 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
75 i2c.valid = false;
76
77 atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset);
78
79 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
80
81 gpio = i2c_info->asGPIO_Info[id];
82
83 i2c.mask_clk_reg = le16_to_cpu(gpio.usClkMaskRegisterIndex) * 4;
84 i2c.mask_data_reg = le16_to_cpu(gpio.usDataMaskRegisterIndex) * 4;
Alex Deucher9b9fe722009-11-10 15:59:44 -050085 i2c.en_clk_reg = le16_to_cpu(gpio.usClkEnRegisterIndex) * 4;
86 i2c.en_data_reg = le16_to_cpu(gpio.usDataEnRegisterIndex) * 4;
87 i2c.y_clk_reg = le16_to_cpu(gpio.usClkY_RegisterIndex) * 4;
88 i2c.y_data_reg = le16_to_cpu(gpio.usDataY_RegisterIndex) * 4;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020089 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);
Alex Deucher9b9fe722009-11-10 15:59:44 -050093 i2c.en_clk_mask = (1 << gpio.ucClkEnShift);
94 i2c.en_data_mask = (1 << gpio.ucDataEnShift);
95 i2c.y_clk_mask = (1 << gpio.ucClkY_Shift);
96 i2c.y_data_mask = (1 << gpio.ucDataY_Shift);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020097 i2c.a_clk_mask = (1 << gpio.ucClkA_Shift);
98 i2c.a_data_mask = (1 << gpio.ucDataA_Shift);
99 i2c.valid = true;
100
101 return i2c;
102}
103
104static bool radeon_atom_apply_quirks(struct drm_device *dev,
105 uint32_t supported_device,
106 int *connector_type,
Alex Deucher848577e2009-07-08 16:15:30 -0400107 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deucher705af9c2009-09-10 16:31:13 -0400108 uint16_t *line_mux)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200109{
110
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;
118 }
119
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)
125 return false;
126 }
127
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)) {
Alex Deucher848577e2009-07-08 16:15:30 -0400132 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200133 i2c_bus->valid = false;
Alex Deucher848577e2009-07-08 16:15:30 -0400134 *line_mux = 53;
135 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200136 }
137
Alex Deucher4e3f9b72009-12-01 14:49:50 -0500138 /* 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)
143 return false;
144 }
145
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200146 /* Funky macbooks */
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))
152 return false;
153 }
154
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200155 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
156 if ((dev->pdev->device == 0x9598) &&
157 (dev->pdev->subsystem_vendor == 0x1043) &&
158 (dev->pdev->subsystem_device == 0x01da)) {
Alex Deucher705af9c2009-09-10 16:31:13 -0400159 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400160 *connector_type = DRM_MODE_CONNECTOR_DVII;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200161 }
162 }
163
Alex Deucher705af9c2009-09-10 16:31:13 -0400164 /* ASUS HD 3450 board lists the DVI port as HDMI */
165 if ((dev->pdev->device == 0x95C5) &&
166 (dev->pdev->subsystem_vendor == 0x1043) &&
167 (dev->pdev->subsystem_device == 0x01e2)) {
168 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400169 *connector_type = DRM_MODE_CONNECTOR_DVII;
Alex Deucher705af9c2009-09-10 16:31:13 -0400170 }
171 }
172
173 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
174 * HDMI + VGA reporting as HDMI
175 */
176 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
177 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
178 *connector_type = DRM_MODE_CONNECTOR_VGA;
179 *line_mux = 0;
180 }
181 }
182
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500183 /* Acer laptop reports DVI-D as DVI-I */
184 if ((dev->pdev->device == 0x95c4) &&
185 (dev->pdev->subsystem_vendor == 0x1025) &&
186 (dev->pdev->subsystem_device == 0x013c)) {
187 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
188 (supported_device == ATOM_DEVICE_DFP1_SUPPORT))
189 *connector_type = DRM_MODE_CONNECTOR_DVID;
190 }
191
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200192 return true;
193}
194
195const int supported_devices_connector_convert[] = {
196 DRM_MODE_CONNECTOR_Unknown,
197 DRM_MODE_CONNECTOR_VGA,
198 DRM_MODE_CONNECTOR_DVII,
199 DRM_MODE_CONNECTOR_DVID,
200 DRM_MODE_CONNECTOR_DVIA,
201 DRM_MODE_CONNECTOR_SVIDEO,
202 DRM_MODE_CONNECTOR_Composite,
203 DRM_MODE_CONNECTOR_LVDS,
204 DRM_MODE_CONNECTOR_Unknown,
205 DRM_MODE_CONNECTOR_Unknown,
206 DRM_MODE_CONNECTOR_HDMIA,
207 DRM_MODE_CONNECTOR_HDMIB,
208 DRM_MODE_CONNECTOR_Unknown,
209 DRM_MODE_CONNECTOR_Unknown,
210 DRM_MODE_CONNECTOR_9PinDIN,
211 DRM_MODE_CONNECTOR_DisplayPort
212};
213
Alex Deucherb75fad02009-11-05 13:16:01 -0500214const uint16_t supported_devices_connector_object_id_convert[] = {
215 CONNECTOR_OBJECT_ID_NONE,
216 CONNECTOR_OBJECT_ID_VGA,
217 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
218 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
219 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
220 CONNECTOR_OBJECT_ID_COMPOSITE,
221 CONNECTOR_OBJECT_ID_SVIDEO,
222 CONNECTOR_OBJECT_ID_LVDS,
223 CONNECTOR_OBJECT_ID_9PIN_DIN,
224 CONNECTOR_OBJECT_ID_9PIN_DIN,
225 CONNECTOR_OBJECT_ID_DISPLAYPORT,
226 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
227 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
228 CONNECTOR_OBJECT_ID_SVIDEO
229};
230
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200231const int object_connector_convert[] = {
232 DRM_MODE_CONNECTOR_Unknown,
233 DRM_MODE_CONNECTOR_DVII,
234 DRM_MODE_CONNECTOR_DVII,
235 DRM_MODE_CONNECTOR_DVID,
236 DRM_MODE_CONNECTOR_DVID,
237 DRM_MODE_CONNECTOR_VGA,
238 DRM_MODE_CONNECTOR_Composite,
239 DRM_MODE_CONNECTOR_SVIDEO,
240 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher705af9c2009-09-10 16:31:13 -0400241 DRM_MODE_CONNECTOR_Unknown,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200242 DRM_MODE_CONNECTOR_9PinDIN,
243 DRM_MODE_CONNECTOR_Unknown,
244 DRM_MODE_CONNECTOR_HDMIA,
245 DRM_MODE_CONNECTOR_HDMIB,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200246 DRM_MODE_CONNECTOR_LVDS,
247 DRM_MODE_CONNECTOR_9PinDIN,
248 DRM_MODE_CONNECTOR_Unknown,
249 DRM_MODE_CONNECTOR_Unknown,
250 DRM_MODE_CONNECTOR_Unknown,
251 DRM_MODE_CONNECTOR_DisplayPort
252};
253
254bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
255{
256 struct radeon_device *rdev = dev->dev_private;
257 struct radeon_mode_info *mode_info = &rdev->mode_info;
258 struct atom_context *ctx = mode_info->atom_context;
259 int index = GetIndexIntoMasterTable(DATA, Object_Header);
260 uint16_t size, data_offset;
261 uint8_t frev, crev, line_mux = 0;
262 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
263 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
264 ATOM_OBJECT_HEADER *obj_header;
265 int i, j, path_size, device_support;
266 int connector_type;
Alex Deucherb75fad02009-11-05 13:16:01 -0500267 uint16_t igp_lane_info, conn_id, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200268 bool linkb;
269 struct radeon_i2c_bus_rec ddc_bus;
270
271 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
272
273 if (data_offset == 0)
274 return false;
275
276 if (crev < 2)
277 return false;
278
279 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
280 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
281 (ctx->bios + data_offset +
282 le16_to_cpu(obj_header->usDisplayPathTableOffset));
283 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
284 (ctx->bios + data_offset +
285 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
286 device_support = le16_to_cpu(obj_header->usDeviceSupport);
287
288 path_size = 0;
289 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
290 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
291 ATOM_DISPLAY_OBJECT_PATH *path;
292 addr += path_size;
293 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
294 path_size += le16_to_cpu(path->usSize);
295 linkb = false;
296
297 if (device_support & le16_to_cpu(path->usDeviceTag)) {
298 uint8_t con_obj_id, con_obj_num, con_obj_type;
299
300 con_obj_id =
301 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
302 >> OBJECT_ID_SHIFT;
303 con_obj_num =
304 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
305 >> ENUM_ID_SHIFT;
306 con_obj_type =
307 (le16_to_cpu(path->usConnObjectId) &
308 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
309
Dave Airlie4bbd4972009-09-25 08:56:12 +1000310 /* TODO CV support */
311 if (le16_to_cpu(path->usDeviceTag) ==
312 ATOM_DEVICE_CV_SUPPORT)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200313 continue;
314
Alex Deucheree59f2b2009-11-05 13:11:46 -0500315 /* IGP chips */
316 if ((rdev->flags & RADEON_IS_IGP) &&
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200317 (con_obj_id ==
318 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
319 uint16_t igp_offset = 0;
320 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
321
322 index =
323 GetIndexIntoMasterTable(DATA,
324 IntegratedSystemInfo);
325
326 atom_parse_data_header(ctx, index, &size, &frev,
327 &crev, &igp_offset);
328
329 if (crev >= 2) {
330 igp_obj =
331 (ATOM_INTEGRATED_SYSTEM_INFO_V2
332 *) (ctx->bios + igp_offset);
333
334 if (igp_obj) {
335 uint32_t slot_config, ct;
336
337 if (con_obj_num == 1)
338 slot_config =
339 igp_obj->
340 ulDDISlot1Config;
341 else
342 slot_config =
343 igp_obj->
344 ulDDISlot2Config;
345
346 ct = (slot_config >> 16) & 0xff;
347 connector_type =
348 object_connector_convert
349 [ct];
Alex Deucherb75fad02009-11-05 13:16:01 -0500350 connector_object_id = ct;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200351 igp_lane_info =
352 slot_config & 0xffff;
353 } else
354 continue;
355 } else
356 continue;
357 } else {
358 igp_lane_info = 0;
359 connector_type =
360 object_connector_convert[con_obj_id];
Alex Deucherb75fad02009-11-05 13:16:01 -0500361 connector_object_id = con_obj_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200362 }
363
364 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
365 continue;
366
367 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2);
368 j++) {
369 uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
370
371 enc_obj_id =
372 (le16_to_cpu(path->usGraphicObjIds[j]) &
373 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
374 enc_obj_num =
375 (le16_to_cpu(path->usGraphicObjIds[j]) &
376 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
377 enc_obj_type =
378 (le16_to_cpu(path->usGraphicObjIds[j]) &
379 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
380
381 /* FIXME: add support for router objects */
382 if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
383 if (enc_obj_num == 2)
384 linkb = true;
385 else
386 linkb = false;
387
388 radeon_add_atom_encoder(dev,
389 enc_obj_id,
390 le16_to_cpu
391 (path->
392 usDeviceTag));
393
394 }
395 }
396
397 /* look up gpio for ddc */
398 if ((le16_to_cpu(path->usDeviceTag) &
399 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
400 == 0) {
401 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
402 if (le16_to_cpu(path->usConnObjectId) ==
403 le16_to_cpu(con_obj->asObjects[j].
404 usObjectID)) {
405 ATOM_COMMON_RECORD_HEADER
406 *record =
407 (ATOM_COMMON_RECORD_HEADER
408 *)
409 (ctx->bios + data_offset +
410 le16_to_cpu(con_obj->
411 asObjects[j].
412 usRecordOffset));
413 ATOM_I2C_RECORD *i2c_record;
414
415 while (record->ucRecordType > 0
416 && record->
417 ucRecordType <=
418 ATOM_MAX_OBJECT_RECORD_NUMBER) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200419 switch (record->
420 ucRecordType) {
421 case ATOM_I2C_RECORD_TYPE:
422 i2c_record =
423 (ATOM_I2C_RECORD
424 *) record;
425 line_mux =
426 i2c_record->
427 sucI2cId.
428 bfI2C_LineMux;
429 break;
430 }
431 record =
432 (ATOM_COMMON_RECORD_HEADER
433 *) ((char *)record
434 +
435 record->
436 ucRecordSize);
437 }
438 break;
439 }
440 }
441 } else
442 line_mux = 0;
443
444 if ((le16_to_cpu(path->usDeviceTag) ==
445 ATOM_DEVICE_TV1_SUPPORT)
446 || (le16_to_cpu(path->usDeviceTag) ==
447 ATOM_DEVICE_TV2_SUPPORT)
448 || (le16_to_cpu(path->usDeviceTag) ==
449 ATOM_DEVICE_CV_SUPPORT))
450 ddc_bus.valid = false;
451 else
452 ddc_bus = radeon_lookup_gpio(dev, line_mux);
453
Alex Deucher705af9c2009-09-10 16:31:13 -0400454 conn_id = le16_to_cpu(path->usConnObjectId);
455
456 if (!radeon_atom_apply_quirks
457 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
458 &ddc_bus, &conn_id))
459 continue;
460
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200461 radeon_add_atom_connector(dev,
Alex Deucher705af9c2009-09-10 16:31:13 -0400462 conn_id,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200463 le16_to_cpu(path->
464 usDeviceTag),
465 connector_type, &ddc_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -0500466 linkb, igp_lane_info,
467 connector_object_id);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200468
469 }
470 }
471
472 radeon_link_encoder_connector(dev);
473
474 return true;
475}
476
Alex Deucherb75fad02009-11-05 13:16:01 -0500477static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
478 int connector_type,
479 uint16_t devices)
480{
481 struct radeon_device *rdev = dev->dev_private;
482
483 if (rdev->flags & RADEON_IS_IGP) {
484 return supported_devices_connector_object_id_convert
485 [connector_type];
486 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
487 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
488 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
489 struct radeon_mode_info *mode_info = &rdev->mode_info;
490 struct atom_context *ctx = mode_info->atom_context;
491 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
492 uint16_t size, data_offset;
493 uint8_t frev, crev;
494 ATOM_XTMDS_INFO *xtmds;
495
496 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
497 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
498
499 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
500 if (connector_type == DRM_MODE_CONNECTOR_DVII)
501 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
502 else
503 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
504 } else {
505 if (connector_type == DRM_MODE_CONNECTOR_DVII)
506 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
507 else
508 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
509 }
510 } else {
511 return supported_devices_connector_object_id_convert
512 [connector_type];
513 }
514}
515
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200516struct bios_connector {
517 bool valid;
Alex Deucher705af9c2009-09-10 16:31:13 -0400518 uint16_t line_mux;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200519 uint16_t devices;
520 int connector_type;
521 struct radeon_i2c_bus_rec ddc_bus;
522};
523
524bool radeon_get_atom_connector_info_from_supported_devices_table(struct
525 drm_device
526 *dev)
527{
528 struct radeon_device *rdev = dev->dev_private;
529 struct radeon_mode_info *mode_info = &rdev->mode_info;
530 struct atom_context *ctx = mode_info->atom_context;
531 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
532 uint16_t size, data_offset;
533 uint8_t frev, crev;
534 uint16_t device_support;
535 uint8_t dac;
536 union atom_supported_devices *supported_devices;
537 int i, j;
538 struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
539
540 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
541
542 supported_devices =
543 (union atom_supported_devices *)(ctx->bios + data_offset);
544
545 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
546
547 for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
548 ATOM_CONNECTOR_INFO_I2C ci =
549 supported_devices->info.asConnInfo[i];
550
551 bios_connectors[i].valid = false;
552
553 if (!(device_support & (1 << i))) {
554 continue;
555 }
556
557 if (i == ATOM_DEVICE_CV_INDEX) {
558 DRM_DEBUG("Skipping Component Video\n");
559 continue;
560 }
561
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200562 bios_connectors[i].connector_type =
563 supported_devices_connector_convert[ci.sucConnectorInfo.
564 sbfAccess.
565 bfConnectorType];
566
567 if (bios_connectors[i].connector_type ==
568 DRM_MODE_CONNECTOR_Unknown)
569 continue;
570
571 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
572
573 if ((rdev->family == CHIP_RS690) ||
574 (rdev->family == CHIP_RS740)) {
575 if ((i == ATOM_DEVICE_DFP2_INDEX)
576 && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 2))
577 bios_connectors[i].line_mux =
578 ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
579 else if ((i == ATOM_DEVICE_DFP3_INDEX)
580 && (ci.sucI2cId.sbfAccess.bfI2C_LineMux == 1))
581 bios_connectors[i].line_mux =
582 ci.sucI2cId.sbfAccess.bfI2C_LineMux + 1;
583 else
584 bios_connectors[i].line_mux =
585 ci.sucI2cId.sbfAccess.bfI2C_LineMux;
586 } else
587 bios_connectors[i].line_mux =
588 ci.sucI2cId.sbfAccess.bfI2C_LineMux;
589
590 /* give tv unique connector ids */
591 if (i == ATOM_DEVICE_TV1_INDEX) {
592 bios_connectors[i].ddc_bus.valid = false;
593 bios_connectors[i].line_mux = 50;
594 } else if (i == ATOM_DEVICE_TV2_INDEX) {
595 bios_connectors[i].ddc_bus.valid = false;
596 bios_connectors[i].line_mux = 51;
597 } else if (i == ATOM_DEVICE_CV_INDEX) {
598 bios_connectors[i].ddc_bus.valid = false;
599 bios_connectors[i].line_mux = 52;
600 } else
601 bios_connectors[i].ddc_bus =
602 radeon_lookup_gpio(dev,
603 bios_connectors[i].line_mux);
604
605 /* Always set the connector type to VGA for CRT1/CRT2. if they are
606 * shared with a DVI port, we'll pick up the DVI connector when we
607 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
608 */
609 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
610 bios_connectors[i].connector_type =
611 DRM_MODE_CONNECTOR_VGA;
612
613 if (!radeon_atom_apply_quirks
614 (dev, (1 << i), &bios_connectors[i].connector_type,
Alex Deucher848577e2009-07-08 16:15:30 -0400615 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200616 continue;
617
618 bios_connectors[i].valid = true;
619 bios_connectors[i].devices = (1 << i);
620
621 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
622 radeon_add_atom_encoder(dev,
623 radeon_get_encoder_id(dev,
624 (1 << i),
625 dac),
626 (1 << i));
627 else
628 radeon_add_legacy_encoder(dev,
629 radeon_get_encoder_id(dev,
630 (1 <<
631 i),
632 dac),
633 (1 << i));
634 }
635
636 /* combine shared connectors */
637 for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
638 if (bios_connectors[i].valid) {
639 for (j = 0; j < ATOM_MAX_SUPPORTED_DEVICE; j++) {
640 if (bios_connectors[j].valid && (i != j)) {
641 if (bios_connectors[i].line_mux ==
642 bios_connectors[j].line_mux) {
643 if (((bios_connectors[i].
644 devices &
645 (ATOM_DEVICE_DFP_SUPPORT))
646 && (bios_connectors[j].
647 devices &
648 (ATOM_DEVICE_CRT_SUPPORT)))
649 ||
650 ((bios_connectors[j].
651 devices &
652 (ATOM_DEVICE_DFP_SUPPORT))
653 && (bios_connectors[i].
654 devices &
655 (ATOM_DEVICE_CRT_SUPPORT)))) {
656 bios_connectors[i].
657 devices |=
658 bios_connectors[j].
659 devices;
660 bios_connectors[i].
661 connector_type =
662 DRM_MODE_CONNECTOR_DVII;
663 bios_connectors[j].
664 valid = false;
665 }
666 }
667 }
668 }
669 }
670 }
671
672 /* add the connectors */
673 for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
Alex Deucherb75fad02009-11-05 13:16:01 -0500674 if (bios_connectors[i].valid) {
675 uint16_t connector_object_id =
676 atombios_get_connector_object_id(dev,
677 bios_connectors[i].connector_type,
678 bios_connectors[i].devices);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200679 radeon_add_atom_connector(dev,
680 bios_connectors[i].line_mux,
681 bios_connectors[i].devices,
682 bios_connectors[i].
683 connector_type,
684 &bios_connectors[i].ddc_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -0500685 false, 0,
686 connector_object_id);
687 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200688 }
689
690 radeon_link_encoder_connector(dev);
691
692 return true;
693}
694
695union firmware_info {
696 ATOM_FIRMWARE_INFO info;
697 ATOM_FIRMWARE_INFO_V1_2 info_12;
698 ATOM_FIRMWARE_INFO_V1_3 info_13;
699 ATOM_FIRMWARE_INFO_V1_4 info_14;
700};
701
702bool radeon_atom_get_clock_info(struct drm_device *dev)
703{
704 struct radeon_device *rdev = dev->dev_private;
705 struct radeon_mode_info *mode_info = &rdev->mode_info;
706 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
707 union firmware_info *firmware_info;
708 uint8_t frev, crev;
709 struct radeon_pll *p1pll = &rdev->clock.p1pll;
710 struct radeon_pll *p2pll = &rdev->clock.p2pll;
711 struct radeon_pll *spll = &rdev->clock.spll;
712 struct radeon_pll *mpll = &rdev->clock.mpll;
713 uint16_t data_offset;
714
715 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
716 &crev, &data_offset);
717
718 firmware_info =
719 (union firmware_info *)(mode_info->atom_context->bios +
720 data_offset);
721
722 if (firmware_info) {
723 /* pixel clocks */
724 p1pll->reference_freq =
725 le16_to_cpu(firmware_info->info.usReferenceClock);
726 p1pll->reference_div = 0;
727
Mathias Fröhlichbc293e52009-10-19 17:49:49 -0400728 if (crev < 2)
729 p1pll->pll_out_min =
730 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
731 else
732 p1pll->pll_out_min =
733 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200734 p1pll->pll_out_max =
735 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
736
737 if (p1pll->pll_out_min == 0) {
738 if (ASIC_IS_AVIVO(rdev))
739 p1pll->pll_out_min = 64800;
740 else
741 p1pll->pll_out_min = 20000;
Alex Deucher8f552a62009-10-27 11:16:09 -0400742 } else if (p1pll->pll_out_min > 64800) {
743 /* Limiting the pll output range is a good thing generally as
744 * it limits the number of possible pll combinations for a given
745 * frequency presumably to the ones that work best on each card.
746 * However, certain duallink DVI monitors seem to like
747 * pll combinations that would be limited by this at least on
748 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
749 * family.
750 */
751 p1pll->pll_out_min = 64800;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200752 }
753
754 p1pll->pll_in_min =
755 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
756 p1pll->pll_in_max =
757 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
758
759 *p2pll = *p1pll;
760
761 /* system clock */
762 spll->reference_freq =
763 le16_to_cpu(firmware_info->info.usReferenceClock);
764 spll->reference_div = 0;
765
766 spll->pll_out_min =
767 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
768 spll->pll_out_max =
769 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
770
771 /* ??? */
772 if (spll->pll_out_min == 0) {
773 if (ASIC_IS_AVIVO(rdev))
774 spll->pll_out_min = 64800;
775 else
776 spll->pll_out_min = 20000;
777 }
778
779 spll->pll_in_min =
780 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
781 spll->pll_in_max =
782 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
783
784 /* memory clock */
785 mpll->reference_freq =
786 le16_to_cpu(firmware_info->info.usReferenceClock);
787 mpll->reference_div = 0;
788
789 mpll->pll_out_min =
790 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
791 mpll->pll_out_max =
792 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
793
794 /* ??? */
795 if (mpll->pll_out_min == 0) {
796 if (ASIC_IS_AVIVO(rdev))
797 mpll->pll_out_min = 64800;
798 else
799 mpll->pll_out_min = 20000;
800 }
801
802 mpll->pll_in_min =
803 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
804 mpll->pll_in_max =
805 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
806
807 rdev->clock.default_sclk =
808 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
809 rdev->clock.default_mclk =
810 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
811
812 return true;
813 }
814 return false;
815}
816
Dave Airlie445282d2009-09-09 17:40:54 +1000817bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
818 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200819{
820 struct drm_device *dev = encoder->base.dev;
821 struct radeon_device *rdev = dev->dev_private;
822 struct radeon_mode_info *mode_info = &rdev->mode_info;
823 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
824 uint16_t data_offset;
825 struct _ATOM_TMDS_INFO *tmds_info;
826 uint8_t frev, crev;
827 uint16_t maxfreq;
828 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200829
830 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
831 &crev, &data_offset);
832
833 tmds_info =
834 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
835 data_offset);
836
837 if (tmds_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200838 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
839 for (i = 0; i < 4; i++) {
840 tmds->tmds_pll[i].freq =
841 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
842 tmds->tmds_pll[i].value =
843 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
844 tmds->tmds_pll[i].value |=
845 (tmds_info->asMiscInfo[i].
846 ucPLL_VCO_Gain & 0x3f) << 6;
847 tmds->tmds_pll[i].value |=
848 (tmds_info->asMiscInfo[i].
849 ucPLL_DutyCycle & 0xf) << 12;
850 tmds->tmds_pll[i].value |=
851 (tmds_info->asMiscInfo[i].
852 ucPLL_VoltageSwing & 0xf) << 16;
853
854 DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
855 tmds->tmds_pll[i].freq,
856 tmds->tmds_pll[i].value);
857
858 if (maxfreq == tmds->tmds_pll[i].freq) {
859 tmds->tmds_pll[i].freq = 0xffffffff;
860 break;
861 }
862 }
Dave Airlie445282d2009-09-09 17:40:54 +1000863 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200864 }
Dave Airlie445282d2009-09-09 17:40:54 +1000865 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200866}
867
Alex Deucherebbe1cb2009-10-16 11:15:25 -0400868static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
869 radeon_encoder
870 *encoder,
871 int id)
872{
873 struct drm_device *dev = encoder->base.dev;
874 struct radeon_device *rdev = dev->dev_private;
875 struct radeon_mode_info *mode_info = &rdev->mode_info;
876 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
877 uint16_t data_offset;
878 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
879 uint8_t frev, crev;
880 struct radeon_atom_ss *ss = NULL;
881
882 if (id > ATOM_MAX_SS_ENTRY)
883 return NULL;
884
885 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
886 &crev, &data_offset);
887
888 ss_info =
889 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
890
891 if (ss_info) {
892 ss =
893 kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
894
895 if (!ss)
896 return NULL;
897
898 ss->percentage = le16_to_cpu(ss_info->asSS_Info[id].usSpreadSpectrumPercentage);
899 ss->type = ss_info->asSS_Info[id].ucSpreadSpectrumType;
900 ss->step = ss_info->asSS_Info[id].ucSS_Step;
901 ss->delay = ss_info->asSS_Info[id].ucSS_Delay;
902 ss->range = ss_info->asSS_Info[id].ucSS_Range;
903 ss->refdiv = ss_info->asSS_Info[id].ucRecommendedRef_Div;
904 }
905 return ss;
906}
907
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200908union lvds_info {
909 struct _ATOM_LVDS_INFO info;
910 struct _ATOM_LVDS_INFO_V12 info_12;
911};
912
913struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
914 radeon_encoder
915 *encoder)
916{
917 struct drm_device *dev = encoder->base.dev;
918 struct radeon_device *rdev = dev->dev_private;
919 struct radeon_mode_info *mode_info = &rdev->mode_info;
920 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
Alex Deucher7dde8a12009-11-30 01:40:24 -0500921 uint16_t data_offset, misc;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200922 union lvds_info *lvds_info;
923 uint8_t frev, crev;
924 struct radeon_encoder_atom_dig *lvds = NULL;
925
926 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
927 &crev, &data_offset);
928
929 lvds_info =
930 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
931
932 if (lvds_info) {
933 lvds =
934 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
935
936 if (!lvds)
937 return NULL;
938
Alex Deucherde2103e2009-10-09 15:14:30 -0400939 lvds->native_mode.clock =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200940 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
Alex Deucherde2103e2009-10-09 15:14:30 -0400941 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200942 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
Alex Deucherde2103e2009-10-09 15:14:30 -0400943 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200944 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
Alex Deucherde2103e2009-10-09 15:14:30 -0400945 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
946 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
947 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
948 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
949 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
950 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
951 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
952 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
953 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
954 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
955 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
956 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200957 lvds->panel_pwr_delay =
958 le16_to_cpu(lvds_info->info.usOffDelayInMs);
959 lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
Alex Deucher7dde8a12009-11-30 01:40:24 -0500960
961 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
962 if (misc & ATOM_VSYNC_POLARITY)
963 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
964 if (misc & ATOM_HSYNC_POLARITY)
965 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
966 if (misc & ATOM_COMPOSITESYNC)
967 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
968 if (misc & ATOM_INTERLACE)
969 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
970 if (misc & ATOM_DOUBLE_CLOCK_MODE)
971 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
972
Alex Deucherde2103e2009-10-09 15:14:30 -0400973 /* set crtc values */
974 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200975
Alex Deucherebbe1cb2009-10-16 11:15:25 -0400976 lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
977
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200978 encoder->native_mode = lvds->native_mode;
979 }
980 return lvds;
981}
982
Alex Deucher6fe7ac32009-06-12 17:26:08 +0000983struct radeon_encoder_primary_dac *
984radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
985{
986 struct drm_device *dev = encoder->base.dev;
987 struct radeon_device *rdev = dev->dev_private;
988 struct radeon_mode_info *mode_info = &rdev->mode_info;
989 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
990 uint16_t data_offset;
991 struct _COMPASSIONATE_DATA *dac_info;
992 uint8_t frev, crev;
993 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +0000994 struct radeon_encoder_primary_dac *p_dac = NULL;
995
996 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
997
998 dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
999
1000 if (dac_info) {
1001 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1002
1003 if (!p_dac)
1004 return NULL;
1005
1006 bg = dac_info->ucDAC1_BG_Adjustment;
1007 dac = dac_info->ucDAC1_DAC_Adjustment;
1008 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1009
1010 }
1011 return p_dac;
1012}
1013
Dave Airlie4ce001a2009-08-13 16:32:14 +10001014bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001015 struct drm_display_mode *mode)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001016{
1017 struct radeon_mode_info *mode_info = &rdev->mode_info;
1018 ATOM_ANALOG_TV_INFO *tv_info;
1019 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1020 ATOM_DTD_FORMAT *dtd_timings;
1021 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1022 u8 frev, crev;
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001023 u16 data_offset, misc;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001024
1025 atom_parse_data_header(mode_info->atom_context, data_index, NULL, &frev, &crev, &data_offset);
1026
1027 switch (crev) {
1028 case 1:
1029 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1030 if (index > MAX_SUPPORTED_TV_TIMING)
1031 return false;
1032
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001033 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1034 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1035 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1036 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1037 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001038
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001039 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1040 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1041 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1042 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1043 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001044
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001045 mode->flags = 0;
1046 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1047 if (misc & ATOM_VSYNC_POLARITY)
1048 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1049 if (misc & ATOM_HSYNC_POLARITY)
1050 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1051 if (misc & ATOM_COMPOSITESYNC)
1052 mode->flags |= DRM_MODE_FLAG_CSYNC;
1053 if (misc & ATOM_INTERLACE)
1054 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1055 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1056 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001057
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001058 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001059
1060 if (index == 1) {
1061 /* PAL timings appear to have wrong values for totals */
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001062 mode->crtc_htotal -= 1;
1063 mode->crtc_vtotal -= 1;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001064 }
1065 break;
1066 case 2:
1067 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
1068 if (index > MAX_SUPPORTED_TV_TIMING_V1_2)
1069 return false;
1070
1071 dtd_timings = &tv_info_v1_2->aModeTimings[index];
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001072 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1073 le16_to_cpu(dtd_timings->usHBlanking_Time);
1074 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1075 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1076 le16_to_cpu(dtd_timings->usHSyncOffset);
1077 mode->crtc_hsync_end = mode->crtc_hsync_start +
1078 le16_to_cpu(dtd_timings->usHSyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001079
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001080 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1081 le16_to_cpu(dtd_timings->usVBlanking_Time);
1082 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1083 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1084 le16_to_cpu(dtd_timings->usVSyncOffset);
1085 mode->crtc_vsync_end = mode->crtc_vsync_start +
1086 le16_to_cpu(dtd_timings->usVSyncWidth);
1087
1088 mode->flags = 0;
1089 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1090 if (misc & ATOM_VSYNC_POLARITY)
1091 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1092 if (misc & ATOM_HSYNC_POLARITY)
1093 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1094 if (misc & ATOM_COMPOSITESYNC)
1095 mode->flags |= DRM_MODE_FLAG_CSYNC;
1096 if (misc & ATOM_INTERLACE)
1097 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1098 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1099 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1100
1101 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001102 break;
1103 }
1104 return true;
1105}
1106
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001107struct radeon_encoder_tv_dac *
1108radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1109{
1110 struct drm_device *dev = encoder->base.dev;
1111 struct radeon_device *rdev = dev->dev_private;
1112 struct radeon_mode_info *mode_info = &rdev->mode_info;
1113 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1114 uint16_t data_offset;
1115 struct _COMPASSIONATE_DATA *dac_info;
1116 uint8_t frev, crev;
1117 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001118 struct radeon_encoder_tv_dac *tv_dac = NULL;
1119
1120 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1121
1122 dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
1123
1124 if (dac_info) {
1125 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1126
1127 if (!tv_dac)
1128 return NULL;
1129
1130 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1131 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1132 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1133
1134 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1135 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1136 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1137
1138 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1139 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1140 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1141
1142 }
1143 return tv_dac;
1144}
1145
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001146void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
1147{
1148 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
1149 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
1150
1151 args.ucEnable = enable;
1152
1153 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1154}
1155
1156void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable)
1157{
1158 ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args;
1159 int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt);
1160
1161 args.ucEnable = enable;
1162
1163 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1164}
1165
Rafał Miłecki74338742009-11-03 00:53:02 +01001166uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
1167{
1168 GET_ENGINE_CLOCK_PS_ALLOCATION args;
1169 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
1170
1171 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1172 return args.ulReturnEngineClock;
1173}
1174
1175uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
1176{
1177 GET_MEMORY_CLOCK_PS_ALLOCATION args;
1178 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
1179
1180 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1181 return args.ulReturnMemoryClock;
1182}
1183
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001184void radeon_atom_set_engine_clock(struct radeon_device *rdev,
1185 uint32_t eng_clock)
1186{
1187 SET_ENGINE_CLOCK_PS_ALLOCATION args;
1188 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
1189
1190 args.ulTargetEngineClock = eng_clock; /* 10 khz */
1191
1192 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1193}
1194
1195void radeon_atom_set_memory_clock(struct radeon_device *rdev,
1196 uint32_t mem_clock)
1197{
1198 SET_MEMORY_CLOCK_PS_ALLOCATION args;
1199 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
1200
1201 if (rdev->flags & RADEON_IS_IGP)
1202 return;
1203
1204 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
1205
1206 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1207}
1208
1209void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
1210{
1211 struct radeon_device *rdev = dev->dev_private;
1212 uint32_t bios_2_scratch, bios_6_scratch;
1213
1214 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001215 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001216 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1217 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001218 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001219 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1220 }
1221
1222 /* let the bios control the backlight */
1223 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
1224
1225 /* tell the bios not to handle mode switching */
1226 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
1227
1228 if (rdev->family >= CHIP_R600) {
1229 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
1230 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1231 } else {
1232 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
1233 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1234 }
1235
1236}
1237
Yang Zhaof657c2a2009-09-15 12:21:01 +10001238void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
1239{
1240 uint32_t scratch_reg;
1241 int i;
1242
1243 if (rdev->family >= CHIP_R600)
1244 scratch_reg = R600_BIOS_0_SCRATCH;
1245 else
1246 scratch_reg = RADEON_BIOS_0_SCRATCH;
1247
1248 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
1249 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
1250}
1251
1252void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
1253{
1254 uint32_t scratch_reg;
1255 int i;
1256
1257 if (rdev->family >= CHIP_R600)
1258 scratch_reg = R600_BIOS_0_SCRATCH;
1259 else
1260 scratch_reg = RADEON_BIOS_0_SCRATCH;
1261
1262 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
1263 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
1264}
1265
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001266void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
1267{
1268 struct drm_device *dev = encoder->dev;
1269 struct radeon_device *rdev = dev->dev_private;
1270 uint32_t bios_6_scratch;
1271
1272 if (rdev->family >= CHIP_R600)
1273 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1274 else
1275 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1276
1277 if (lock)
1278 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
1279 else
1280 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
1281
1282 if (rdev->family >= CHIP_R600)
1283 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1284 else
1285 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1286}
1287
1288/* at some point we may want to break this out into individual functions */
1289void
1290radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
1291 struct drm_encoder *encoder,
1292 bool connected)
1293{
1294 struct drm_device *dev = connector->dev;
1295 struct radeon_device *rdev = dev->dev_private;
1296 struct radeon_connector *radeon_connector =
1297 to_radeon_connector(connector);
1298 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1299 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
1300
1301 if (rdev->family >= CHIP_R600) {
1302 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
1303 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
1304 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1305 } else {
1306 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
1307 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
1308 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1309 }
1310
1311 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
1312 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
1313 if (connected) {
1314 DRM_DEBUG("TV1 connected\n");
1315 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
1316 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
1317 } else {
1318 DRM_DEBUG("TV1 disconnected\n");
1319 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
1320 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
1321 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
1322 }
1323 }
1324 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
1325 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
1326 if (connected) {
1327 DRM_DEBUG("CV connected\n");
1328 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
1329 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
1330 } else {
1331 DRM_DEBUG("CV disconnected\n");
1332 bios_0_scratch &= ~ATOM_S0_CV_MASK;
1333 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
1334 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
1335 }
1336 }
1337 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
1338 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
1339 if (connected) {
1340 DRM_DEBUG("LCD1 connected\n");
1341 bios_0_scratch |= ATOM_S0_LCD1;
1342 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
1343 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
1344 } else {
1345 DRM_DEBUG("LCD1 disconnected\n");
1346 bios_0_scratch &= ~ATOM_S0_LCD1;
1347 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
1348 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
1349 }
1350 }
1351 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
1352 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
1353 if (connected) {
1354 DRM_DEBUG("CRT1 connected\n");
1355 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
1356 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
1357 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
1358 } else {
1359 DRM_DEBUG("CRT1 disconnected\n");
1360 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
1361 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
1362 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
1363 }
1364 }
1365 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
1366 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
1367 if (connected) {
1368 DRM_DEBUG("CRT2 connected\n");
1369 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
1370 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
1371 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
1372 } else {
1373 DRM_DEBUG("CRT2 disconnected\n");
1374 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
1375 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
1376 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
1377 }
1378 }
1379 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
1380 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
1381 if (connected) {
1382 DRM_DEBUG("DFP1 connected\n");
1383 bios_0_scratch |= ATOM_S0_DFP1;
1384 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
1385 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
1386 } else {
1387 DRM_DEBUG("DFP1 disconnected\n");
1388 bios_0_scratch &= ~ATOM_S0_DFP1;
1389 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
1390 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
1391 }
1392 }
1393 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
1394 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
1395 if (connected) {
1396 DRM_DEBUG("DFP2 connected\n");
1397 bios_0_scratch |= ATOM_S0_DFP2;
1398 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
1399 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
1400 } else {
1401 DRM_DEBUG("DFP2 disconnected\n");
1402 bios_0_scratch &= ~ATOM_S0_DFP2;
1403 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
1404 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
1405 }
1406 }
1407 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
1408 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
1409 if (connected) {
1410 DRM_DEBUG("DFP3 connected\n");
1411 bios_0_scratch |= ATOM_S0_DFP3;
1412 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
1413 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
1414 } else {
1415 DRM_DEBUG("DFP3 disconnected\n");
1416 bios_0_scratch &= ~ATOM_S0_DFP3;
1417 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
1418 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
1419 }
1420 }
1421 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
1422 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
1423 if (connected) {
1424 DRM_DEBUG("DFP4 connected\n");
1425 bios_0_scratch |= ATOM_S0_DFP4;
1426 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
1427 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
1428 } else {
1429 DRM_DEBUG("DFP4 disconnected\n");
1430 bios_0_scratch &= ~ATOM_S0_DFP4;
1431 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
1432 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
1433 }
1434 }
1435 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
1436 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
1437 if (connected) {
1438 DRM_DEBUG("DFP5 connected\n");
1439 bios_0_scratch |= ATOM_S0_DFP5;
1440 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
1441 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
1442 } else {
1443 DRM_DEBUG("DFP5 disconnected\n");
1444 bios_0_scratch &= ~ATOM_S0_DFP5;
1445 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
1446 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
1447 }
1448 }
1449
1450 if (rdev->family >= CHIP_R600) {
1451 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
1452 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
1453 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1454 } else {
1455 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
1456 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
1457 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1458 }
1459}
1460
1461void
1462radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
1463{
1464 struct drm_device *dev = encoder->dev;
1465 struct radeon_device *rdev = dev->dev_private;
1466 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1467 uint32_t bios_3_scratch;
1468
1469 if (rdev->family >= CHIP_R600)
1470 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
1471 else
1472 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
1473
1474 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
1475 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
1476 bios_3_scratch |= (crtc << 18);
1477 }
1478 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
1479 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
1480 bios_3_scratch |= (crtc << 24);
1481 }
1482 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
1483 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
1484 bios_3_scratch |= (crtc << 16);
1485 }
1486 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
1487 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
1488 bios_3_scratch |= (crtc << 20);
1489 }
1490 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1491 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
1492 bios_3_scratch |= (crtc << 17);
1493 }
1494 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
1495 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
1496 bios_3_scratch |= (crtc << 19);
1497 }
1498 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
1499 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
1500 bios_3_scratch |= (crtc << 23);
1501 }
1502 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
1503 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
1504 bios_3_scratch |= (crtc << 25);
1505 }
1506
1507 if (rdev->family >= CHIP_R600)
1508 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
1509 else
1510 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
1511}
1512
1513void
1514radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
1515{
1516 struct drm_device *dev = encoder->dev;
1517 struct radeon_device *rdev = dev->dev_private;
1518 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1519 uint32_t bios_2_scratch;
1520
1521 if (rdev->family >= CHIP_R600)
1522 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
1523 else
1524 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
1525
1526 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
1527 if (on)
1528 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
1529 else
1530 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
1531 }
1532 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
1533 if (on)
1534 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
1535 else
1536 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
1537 }
1538 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
1539 if (on)
1540 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
1541 else
1542 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
1543 }
1544 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
1545 if (on)
1546 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
1547 else
1548 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
1549 }
1550 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1551 if (on)
1552 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
1553 else
1554 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
1555 }
1556 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
1557 if (on)
1558 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
1559 else
1560 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
1561 }
1562 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
1563 if (on)
1564 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
1565 else
1566 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
1567 }
1568 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
1569 if (on)
1570 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
1571 else
1572 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
1573 }
1574 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
1575 if (on)
1576 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
1577 else
1578 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
1579 }
1580 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
1581 if (on)
1582 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
1583 else
1584 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
1585 }
1586
1587 if (rdev->family >= CHIP_R600)
1588 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
1589 else
1590 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
1591}