blob: 8737adf6d38602504171819c0612780b1136aef2 [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,
Alex Deuchereed45b32009-12-04 14:45:27 -050050 uint16_t connector_object_id,
51 struct radeon_hpd *hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020052
53/* from radeon_legacy_encoder.c */
54extern void
55radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id,
56 uint32_t supported_device);
57
58union atom_supported_devices {
59 struct _ATOM_SUPPORTED_DEVICES_INFO info;
60 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
61 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
62};
63
Alex Deuchereed45b32009-12-04 14:45:27 -050064static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
65 uint8_t id)
Jerome Glisse771fe6b2009-06-05 14:42:42 +020066{
Jerome Glisse771fe6b2009-06-05 14:42:42 +020067 struct atom_context *ctx = rdev->mode_info.atom_context;
Alex Deucher6a93cb22009-11-23 17:39:28 -050068 ATOM_GPIO_I2C_ASSIGMENT *gpio;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020069 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;
Alex Deucherd3f420d2009-12-08 14:30:49 -050073 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020074
75 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
76 i2c.valid = false;
77
78 atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset);
79
80 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
81
Jerome Glisse771fe6b2009-06-05 14:42:42 +020082
Alex Deucherd3f420d2009-12-08 14:30:49 -050083 for (i = 0; i < ATOM_MAX_SUPPORTED_DEVICE; i++) {
84 gpio = &i2c_info->asGPIO_Info[i];
Alex Deucher6a93cb22009-11-23 17:39:28 -050085
Alex Deucherd3f420d2009-12-08 14:30:49 -050086 if (gpio->sucI2cId.ucAccess == id) {
87 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
88 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
89 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
90 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
91 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
92 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
93 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
94 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
95 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
96 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
97 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
98 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
99 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
100 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
101 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
102 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
Alex Deucher6a93cb22009-11-23 17:39:28 -0500103
Alex Deucherd3f420d2009-12-08 14:30:49 -0500104 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
105 i2c.hw_capable = true;
106 else
107 i2c.hw_capable = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500108
Alex Deucherd3f420d2009-12-08 14:30:49 -0500109 if (gpio->sucI2cId.ucAccess == 0xa0)
110 i2c.mm_i2c = true;
111 else
112 i2c.mm_i2c = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500113
Alex Deucherd3f420d2009-12-08 14:30:49 -0500114 i2c.i2c_id = gpio->sucI2cId.ucAccess;
115
116 i2c.valid = true;
117 }
118 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200119
120 return i2c;
121}
122
Alex Deuchereed45b32009-12-04 14:45:27 -0500123static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
124 u8 id)
125{
126 struct atom_context *ctx = rdev->mode_info.atom_context;
127 struct radeon_gpio_rec gpio;
128 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
129 struct _ATOM_GPIO_PIN_LUT *gpio_info;
130 ATOM_GPIO_PIN_ASSIGNMENT *pin;
131 u16 data_offset, size;
132 int i, num_indices;
133
134 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
135 gpio.valid = false;
136
137 atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset);
138
139 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
140
141 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
142
143 for (i = 0; i < num_indices; i++) {
144 pin = &gpio_info->asGPIO_Pin[i];
145 if (id == pin->ucGPIO_ID) {
146 gpio.id = pin->ucGPIO_ID;
147 gpio.reg = pin->usGpioPin_AIndex * 4;
148 gpio.mask = (1 << pin->ucGpioPinBitShift);
149 gpio.valid = true;
150 break;
151 }
152 }
153
154 return gpio;
155}
156
157static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
158 struct radeon_gpio_rec *gpio)
159{
160 struct radeon_hpd hpd;
161 hpd.gpio = *gpio;
162 if (gpio->reg == AVIVO_DC_GPIO_HPD_A) {
163 switch(gpio->mask) {
164 case (1 << 0):
165 hpd.hpd = RADEON_HPD_1;
166 break;
167 case (1 << 8):
168 hpd.hpd = RADEON_HPD_2;
169 break;
170 case (1 << 16):
171 hpd.hpd = RADEON_HPD_3;
172 break;
173 case (1 << 24):
174 hpd.hpd = RADEON_HPD_4;
175 break;
176 case (1 << 26):
177 hpd.hpd = RADEON_HPD_5;
178 break;
179 case (1 << 28):
180 hpd.hpd = RADEON_HPD_6;
181 break;
182 default:
183 hpd.hpd = RADEON_HPD_NONE;
184 break;
185 }
186 } else
187 hpd.hpd = RADEON_HPD_NONE;
188 return hpd;
189}
190
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200191static bool radeon_atom_apply_quirks(struct drm_device *dev,
192 uint32_t supported_device,
193 int *connector_type,
Alex Deucher848577e2009-07-08 16:15:30 -0400194 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -0500195 uint16_t *line_mux,
196 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200197{
198
199 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
200 if ((dev->pdev->device == 0x791e) &&
201 (dev->pdev->subsystem_vendor == 0x1043) &&
202 (dev->pdev->subsystem_device == 0x826d)) {
203 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
204 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
205 *connector_type = DRM_MODE_CONNECTOR_DVID;
206 }
207
208 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
209 if ((dev->pdev->device == 0x7941) &&
210 (dev->pdev->subsystem_vendor == 0x147b) &&
211 (dev->pdev->subsystem_device == 0x2412)) {
212 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
213 return false;
214 }
215
216 /* Falcon NW laptop lists vga ddc line for LVDS */
217 if ((dev->pdev->device == 0x5653) &&
218 (dev->pdev->subsystem_vendor == 0x1462) &&
219 (dev->pdev->subsystem_device == 0x0291)) {
Alex Deucher848577e2009-07-08 16:15:30 -0400220 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200221 i2c_bus->valid = false;
Alex Deucher848577e2009-07-08 16:15:30 -0400222 *line_mux = 53;
223 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200224 }
225
Alex Deucher4e3f9b72009-12-01 14:49:50 -0500226 /* HIS X1300 is DVI+VGA, not DVI+DVI */
227 if ((dev->pdev->device == 0x7146) &&
228 (dev->pdev->subsystem_vendor == 0x17af) &&
229 (dev->pdev->subsystem_device == 0x2058)) {
230 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
231 return false;
232 }
233
Dave Airlieaa1a7502009-12-04 11:51:34 +1000234 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
235 if ((dev->pdev->device == 0x7142) &&
236 (dev->pdev->subsystem_vendor == 0x1458) &&
237 (dev->pdev->subsystem_device == 0x2134)) {
238 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
239 return false;
240 }
241
242
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200243 /* Funky macbooks */
244 if ((dev->pdev->device == 0x71C5) &&
245 (dev->pdev->subsystem_vendor == 0x106b) &&
246 (dev->pdev->subsystem_device == 0x0080)) {
247 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
248 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
249 return false;
250 }
251
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200252 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
253 if ((dev->pdev->device == 0x9598) &&
254 (dev->pdev->subsystem_vendor == 0x1043) &&
255 (dev->pdev->subsystem_device == 0x01da)) {
Alex Deucher705af9c2009-09-10 16:31:13 -0400256 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400257 *connector_type = DRM_MODE_CONNECTOR_DVII;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200258 }
259 }
260
Alex Deucher705af9c2009-09-10 16:31:13 -0400261 /* ASUS HD 3450 board lists the DVI port as HDMI */
262 if ((dev->pdev->device == 0x95C5) &&
263 (dev->pdev->subsystem_vendor == 0x1043) &&
264 (dev->pdev->subsystem_device == 0x01e2)) {
265 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400266 *connector_type = DRM_MODE_CONNECTOR_DVII;
Alex Deucher705af9c2009-09-10 16:31:13 -0400267 }
268 }
269
270 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
271 * HDMI + VGA reporting as HDMI
272 */
273 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
274 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
275 *connector_type = DRM_MODE_CONNECTOR_VGA;
276 *line_mux = 0;
277 }
278 }
279
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500280 /* Acer laptop reports DVI-D as DVI-I */
281 if ((dev->pdev->device == 0x95c4) &&
282 (dev->pdev->subsystem_vendor == 0x1025) &&
283 (dev->pdev->subsystem_device == 0x013c)) {
284 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
285 (supported_device == ATOM_DEVICE_DFP1_SUPPORT))
286 *connector_type = DRM_MODE_CONNECTOR_DVID;
287 }
288
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200289 return true;
290}
291
292const int supported_devices_connector_convert[] = {
293 DRM_MODE_CONNECTOR_Unknown,
294 DRM_MODE_CONNECTOR_VGA,
295 DRM_MODE_CONNECTOR_DVII,
296 DRM_MODE_CONNECTOR_DVID,
297 DRM_MODE_CONNECTOR_DVIA,
298 DRM_MODE_CONNECTOR_SVIDEO,
299 DRM_MODE_CONNECTOR_Composite,
300 DRM_MODE_CONNECTOR_LVDS,
301 DRM_MODE_CONNECTOR_Unknown,
302 DRM_MODE_CONNECTOR_Unknown,
303 DRM_MODE_CONNECTOR_HDMIA,
304 DRM_MODE_CONNECTOR_HDMIB,
305 DRM_MODE_CONNECTOR_Unknown,
306 DRM_MODE_CONNECTOR_Unknown,
307 DRM_MODE_CONNECTOR_9PinDIN,
308 DRM_MODE_CONNECTOR_DisplayPort
309};
310
Alex Deucherb75fad02009-11-05 13:16:01 -0500311const uint16_t supported_devices_connector_object_id_convert[] = {
312 CONNECTOR_OBJECT_ID_NONE,
313 CONNECTOR_OBJECT_ID_VGA,
314 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
315 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
316 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
317 CONNECTOR_OBJECT_ID_COMPOSITE,
318 CONNECTOR_OBJECT_ID_SVIDEO,
319 CONNECTOR_OBJECT_ID_LVDS,
320 CONNECTOR_OBJECT_ID_9PIN_DIN,
321 CONNECTOR_OBJECT_ID_9PIN_DIN,
322 CONNECTOR_OBJECT_ID_DISPLAYPORT,
323 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
324 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
325 CONNECTOR_OBJECT_ID_SVIDEO
326};
327
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200328const int object_connector_convert[] = {
329 DRM_MODE_CONNECTOR_Unknown,
330 DRM_MODE_CONNECTOR_DVII,
331 DRM_MODE_CONNECTOR_DVII,
332 DRM_MODE_CONNECTOR_DVID,
333 DRM_MODE_CONNECTOR_DVID,
334 DRM_MODE_CONNECTOR_VGA,
335 DRM_MODE_CONNECTOR_Composite,
336 DRM_MODE_CONNECTOR_SVIDEO,
337 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher705af9c2009-09-10 16:31:13 -0400338 DRM_MODE_CONNECTOR_Unknown,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200339 DRM_MODE_CONNECTOR_9PinDIN,
340 DRM_MODE_CONNECTOR_Unknown,
341 DRM_MODE_CONNECTOR_HDMIA,
342 DRM_MODE_CONNECTOR_HDMIB,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200343 DRM_MODE_CONNECTOR_LVDS,
344 DRM_MODE_CONNECTOR_9PinDIN,
345 DRM_MODE_CONNECTOR_Unknown,
346 DRM_MODE_CONNECTOR_Unknown,
347 DRM_MODE_CONNECTOR_Unknown,
348 DRM_MODE_CONNECTOR_DisplayPort
349};
350
351bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
352{
353 struct radeon_device *rdev = dev->dev_private;
354 struct radeon_mode_info *mode_info = &rdev->mode_info;
355 struct atom_context *ctx = mode_info->atom_context;
356 int index = GetIndexIntoMasterTable(DATA, Object_Header);
Alex Deuchereed45b32009-12-04 14:45:27 -0500357 u16 size, data_offset;
358 u8 frev, crev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200359 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
360 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
361 ATOM_OBJECT_HEADER *obj_header;
362 int i, j, path_size, device_support;
363 int connector_type;
Alex Deuchereed45b32009-12-04 14:45:27 -0500364 u16 igp_lane_info, conn_id, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200365 bool linkb;
366 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500367 struct radeon_gpio_rec gpio;
368 struct radeon_hpd hpd;
369
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200370 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
371
372 if (data_offset == 0)
373 return false;
374
375 if (crev < 2)
376 return false;
377
378 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
379 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
380 (ctx->bios + data_offset +
381 le16_to_cpu(obj_header->usDisplayPathTableOffset));
382 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
383 (ctx->bios + data_offset +
384 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
385 device_support = le16_to_cpu(obj_header->usDeviceSupport);
386
387 path_size = 0;
388 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
389 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
390 ATOM_DISPLAY_OBJECT_PATH *path;
391 addr += path_size;
392 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
393 path_size += le16_to_cpu(path->usSize);
394 linkb = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200395 if (device_support & le16_to_cpu(path->usDeviceTag)) {
396 uint8_t con_obj_id, con_obj_num, con_obj_type;
397
398 con_obj_id =
399 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
400 >> OBJECT_ID_SHIFT;
401 con_obj_num =
402 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
403 >> ENUM_ID_SHIFT;
404 con_obj_type =
405 (le16_to_cpu(path->usConnObjectId) &
406 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
407
Dave Airlie4bbd4972009-09-25 08:56:12 +1000408 /* TODO CV support */
409 if (le16_to_cpu(path->usDeviceTag) ==
410 ATOM_DEVICE_CV_SUPPORT)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200411 continue;
412
Alex Deucheree59f2b2009-11-05 13:11:46 -0500413 /* IGP chips */
414 if ((rdev->flags & RADEON_IS_IGP) &&
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200415 (con_obj_id ==
416 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
417 uint16_t igp_offset = 0;
418 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
419
420 index =
421 GetIndexIntoMasterTable(DATA,
422 IntegratedSystemInfo);
423
424 atom_parse_data_header(ctx, index, &size, &frev,
425 &crev, &igp_offset);
426
427 if (crev >= 2) {
428 igp_obj =
429 (ATOM_INTEGRATED_SYSTEM_INFO_V2
430 *) (ctx->bios + igp_offset);
431
432 if (igp_obj) {
433 uint32_t slot_config, ct;
434
435 if (con_obj_num == 1)
436 slot_config =
437 igp_obj->
438 ulDDISlot1Config;
439 else
440 slot_config =
441 igp_obj->
442 ulDDISlot2Config;
443
444 ct = (slot_config >> 16) & 0xff;
445 connector_type =
446 object_connector_convert
447 [ct];
Alex Deucherb75fad02009-11-05 13:16:01 -0500448 connector_object_id = ct;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200449 igp_lane_info =
450 slot_config & 0xffff;
451 } else
452 continue;
453 } else
454 continue;
455 } else {
456 igp_lane_info = 0;
457 connector_type =
458 object_connector_convert[con_obj_id];
Alex Deucherb75fad02009-11-05 13:16:01 -0500459 connector_object_id = con_obj_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200460 }
461
462 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
463 continue;
464
465 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2);
466 j++) {
467 uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
468
469 enc_obj_id =
470 (le16_to_cpu(path->usGraphicObjIds[j]) &
471 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
472 enc_obj_num =
473 (le16_to_cpu(path->usGraphicObjIds[j]) &
474 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
475 enc_obj_type =
476 (le16_to_cpu(path->usGraphicObjIds[j]) &
477 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
478
479 /* FIXME: add support for router objects */
480 if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
481 if (enc_obj_num == 2)
482 linkb = true;
483 else
484 linkb = false;
485
486 radeon_add_atom_encoder(dev,
487 enc_obj_id,
488 le16_to_cpu
489 (path->
490 usDeviceTag));
491
492 }
493 }
494
Alex Deuchereed45b32009-12-04 14:45:27 -0500495 /* look up gpio for ddc, hpd */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200496 if ((le16_to_cpu(path->usDeviceTag) &
Alex Deuchereed45b32009-12-04 14:45:27 -0500497 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200498 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
499 if (le16_to_cpu(path->usConnObjectId) ==
500 le16_to_cpu(con_obj->asObjects[j].
501 usObjectID)) {
502 ATOM_COMMON_RECORD_HEADER
503 *record =
504 (ATOM_COMMON_RECORD_HEADER
505 *)
506 (ctx->bios + data_offset +
507 le16_to_cpu(con_obj->
508 asObjects[j].
509 usRecordOffset));
510 ATOM_I2C_RECORD *i2c_record;
Alex Deuchereed45b32009-12-04 14:45:27 -0500511 ATOM_HPD_INT_RECORD *hpd_record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500512 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
Alex Deuchereed45b32009-12-04 14:45:27 -0500513 hpd.hpd = RADEON_HPD_NONE;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500514
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200515 while (record->ucRecordType > 0
516 && record->
517 ucRecordType <=
518 ATOM_MAX_OBJECT_RECORD_NUMBER) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500519 switch (record->ucRecordType) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200520 case ATOM_I2C_RECORD_TYPE:
521 i2c_record =
Alex Deuchereed45b32009-12-04 14:45:27 -0500522 (ATOM_I2C_RECORD *)
523 record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500524 i2c_config =
525 (ATOM_I2C_ID_CONFIG_ACCESS *)
526 &i2c_record->sucI2cId;
Alex Deuchereed45b32009-12-04 14:45:27 -0500527 ddc_bus = radeon_lookup_i2c_gpio(rdev,
Alex Deucherd3f420d2009-12-08 14:30:49 -0500528 i2c_config->
529 ucAccess);
Alex Deuchereed45b32009-12-04 14:45:27 -0500530 break;
531 case ATOM_HPD_INT_RECORD_TYPE:
532 hpd_record =
533 (ATOM_HPD_INT_RECORD *)
534 record;
535 gpio = radeon_lookup_gpio(rdev,
536 hpd_record->ucHPDIntGPIOID);
537 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
538 hpd.plugged_state = hpd_record->ucPlugged_PinState;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200539 break;
540 }
541 record =
542 (ATOM_COMMON_RECORD_HEADER
543 *) ((char *)record
544 +
545 record->
546 ucRecordSize);
547 }
548 break;
549 }
550 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500551 } else {
552 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200553 ddc_bus.valid = false;
Alex Deuchereed45b32009-12-04 14:45:27 -0500554 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200555
Alex Deucher705af9c2009-09-10 16:31:13 -0400556 conn_id = le16_to_cpu(path->usConnObjectId);
557
558 if (!radeon_atom_apply_quirks
559 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500560 &ddc_bus, &conn_id, &hpd))
Alex Deucher705af9c2009-09-10 16:31:13 -0400561 continue;
562
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200563 radeon_add_atom_connector(dev,
Alex Deucher705af9c2009-09-10 16:31:13 -0400564 conn_id,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200565 le16_to_cpu(path->
566 usDeviceTag),
567 connector_type, &ddc_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -0500568 linkb, igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -0500569 connector_object_id,
570 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200571
572 }
573 }
574
575 radeon_link_encoder_connector(dev);
576
577 return true;
578}
579
Alex Deucherb75fad02009-11-05 13:16:01 -0500580static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
581 int connector_type,
582 uint16_t devices)
583{
584 struct radeon_device *rdev = dev->dev_private;
585
586 if (rdev->flags & RADEON_IS_IGP) {
587 return supported_devices_connector_object_id_convert
588 [connector_type];
589 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
590 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
591 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
592 struct radeon_mode_info *mode_info = &rdev->mode_info;
593 struct atom_context *ctx = mode_info->atom_context;
594 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
595 uint16_t size, data_offset;
596 uint8_t frev, crev;
597 ATOM_XTMDS_INFO *xtmds;
598
599 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
600 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
601
602 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
603 if (connector_type == DRM_MODE_CONNECTOR_DVII)
604 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
605 else
606 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
607 } else {
608 if (connector_type == DRM_MODE_CONNECTOR_DVII)
609 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
610 else
611 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
612 }
613 } else {
614 return supported_devices_connector_object_id_convert
615 [connector_type];
616 }
617}
618
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200619struct bios_connector {
620 bool valid;
Alex Deucher705af9c2009-09-10 16:31:13 -0400621 uint16_t line_mux;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200622 uint16_t devices;
623 int connector_type;
624 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500625 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200626};
627
628bool radeon_get_atom_connector_info_from_supported_devices_table(struct
629 drm_device
630 *dev)
631{
632 struct radeon_device *rdev = dev->dev_private;
633 struct radeon_mode_info *mode_info = &rdev->mode_info;
634 struct atom_context *ctx = mode_info->atom_context;
635 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
636 uint16_t size, data_offset;
637 uint8_t frev, crev;
638 uint16_t device_support;
639 uint8_t dac;
640 union atom_supported_devices *supported_devices;
Alex Deuchereed45b32009-12-04 14:45:27 -0500641 int i, j, max_device;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200642 struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
643
644 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
645
646 supported_devices =
647 (union atom_supported_devices *)(ctx->bios + data_offset);
648
649 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
650
Alex Deuchereed45b32009-12-04 14:45:27 -0500651 if (frev > 1)
652 max_device = ATOM_MAX_SUPPORTED_DEVICE;
653 else
654 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
655
656 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200657 ATOM_CONNECTOR_INFO_I2C ci =
658 supported_devices->info.asConnInfo[i];
659
660 bios_connectors[i].valid = false;
661
662 if (!(device_support & (1 << i))) {
663 continue;
664 }
665
666 if (i == ATOM_DEVICE_CV_INDEX) {
667 DRM_DEBUG("Skipping Component Video\n");
668 continue;
669 }
670
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200671 bios_connectors[i].connector_type =
672 supported_devices_connector_convert[ci.sucConnectorInfo.
673 sbfAccess.
674 bfConnectorType];
675
676 if (bios_connectors[i].connector_type ==
677 DRM_MODE_CONNECTOR_Unknown)
678 continue;
679
680 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
681
Alex Deucherd3f420d2009-12-08 14:30:49 -0500682 bios_connectors[i].line_mux =
683 ci.sucI2cId.ucAccess;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200684
685 /* give tv unique connector ids */
686 if (i == ATOM_DEVICE_TV1_INDEX) {
687 bios_connectors[i].ddc_bus.valid = false;
688 bios_connectors[i].line_mux = 50;
689 } else if (i == ATOM_DEVICE_TV2_INDEX) {
690 bios_connectors[i].ddc_bus.valid = false;
691 bios_connectors[i].line_mux = 51;
692 } else if (i == ATOM_DEVICE_CV_INDEX) {
693 bios_connectors[i].ddc_bus.valid = false;
694 bios_connectors[i].line_mux = 52;
695 } else
696 bios_connectors[i].ddc_bus =
Alex Deuchereed45b32009-12-04 14:45:27 -0500697 radeon_lookup_i2c_gpio(rdev,
698 bios_connectors[i].line_mux);
699
700 if ((crev > 1) && (frev > 1)) {
701 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
702 switch (isb) {
703 case 0x4:
704 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
705 break;
706 case 0xa:
707 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
708 break;
709 default:
710 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
711 break;
712 }
713 } else {
714 if (i == ATOM_DEVICE_DFP1_INDEX)
715 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
716 else if (i == ATOM_DEVICE_DFP2_INDEX)
717 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
718 else
719 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
720 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200721
722 /* Always set the connector type to VGA for CRT1/CRT2. if they are
723 * shared with a DVI port, we'll pick up the DVI connector when we
724 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
725 */
726 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
727 bios_connectors[i].connector_type =
728 DRM_MODE_CONNECTOR_VGA;
729
730 if (!radeon_atom_apply_quirks
731 (dev, (1 << i), &bios_connectors[i].connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500732 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
733 &bios_connectors[i].hpd))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200734 continue;
735
736 bios_connectors[i].valid = true;
737 bios_connectors[i].devices = (1 << i);
738
739 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
740 radeon_add_atom_encoder(dev,
741 radeon_get_encoder_id(dev,
742 (1 << i),
743 dac),
744 (1 << i));
745 else
746 radeon_add_legacy_encoder(dev,
747 radeon_get_encoder_id(dev,
748 (1 <<
749 i),
750 dac),
751 (1 << i));
752 }
753
754 /* combine shared connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -0500755 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200756 if (bios_connectors[i].valid) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500757 for (j = 0; j < max_device; j++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200758 if (bios_connectors[j].valid && (i != j)) {
759 if (bios_connectors[i].line_mux ==
760 bios_connectors[j].line_mux) {
761 if (((bios_connectors[i].
762 devices &
763 (ATOM_DEVICE_DFP_SUPPORT))
764 && (bios_connectors[j].
765 devices &
766 (ATOM_DEVICE_CRT_SUPPORT)))
767 ||
768 ((bios_connectors[j].
769 devices &
770 (ATOM_DEVICE_DFP_SUPPORT))
771 && (bios_connectors[i].
772 devices &
773 (ATOM_DEVICE_CRT_SUPPORT)))) {
774 bios_connectors[i].
775 devices |=
776 bios_connectors[j].
777 devices;
778 bios_connectors[i].
779 connector_type =
780 DRM_MODE_CONNECTOR_DVII;
Alex Deuchereed45b32009-12-04 14:45:27 -0500781 if (bios_connectors[j].devices &
782 (ATOM_DEVICE_DFP_SUPPORT))
783 bios_connectors[i].hpd =
784 bios_connectors[j].hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200785 bios_connectors[j].
786 valid = false;
787 }
788 }
789 }
790 }
791 }
792 }
793
794 /* add the connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -0500795 for (i = 0; i < max_device; i++) {
Alex Deucherb75fad02009-11-05 13:16:01 -0500796 if (bios_connectors[i].valid) {
797 uint16_t connector_object_id =
798 atombios_get_connector_object_id(dev,
799 bios_connectors[i].connector_type,
800 bios_connectors[i].devices);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200801 radeon_add_atom_connector(dev,
802 bios_connectors[i].line_mux,
803 bios_connectors[i].devices,
804 bios_connectors[i].
805 connector_type,
806 &bios_connectors[i].ddc_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -0500807 false, 0,
Alex Deuchereed45b32009-12-04 14:45:27 -0500808 connector_object_id,
809 &bios_connectors[i].hpd);
Alex Deucherb75fad02009-11-05 13:16:01 -0500810 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200811 }
812
813 radeon_link_encoder_connector(dev);
814
815 return true;
816}
817
818union firmware_info {
819 ATOM_FIRMWARE_INFO info;
820 ATOM_FIRMWARE_INFO_V1_2 info_12;
821 ATOM_FIRMWARE_INFO_V1_3 info_13;
822 ATOM_FIRMWARE_INFO_V1_4 info_14;
823};
824
825bool radeon_atom_get_clock_info(struct drm_device *dev)
826{
827 struct radeon_device *rdev = dev->dev_private;
828 struct radeon_mode_info *mode_info = &rdev->mode_info;
829 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
830 union firmware_info *firmware_info;
831 uint8_t frev, crev;
832 struct radeon_pll *p1pll = &rdev->clock.p1pll;
833 struct radeon_pll *p2pll = &rdev->clock.p2pll;
834 struct radeon_pll *spll = &rdev->clock.spll;
835 struct radeon_pll *mpll = &rdev->clock.mpll;
836 uint16_t data_offset;
837
838 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
839 &crev, &data_offset);
840
841 firmware_info =
842 (union firmware_info *)(mode_info->atom_context->bios +
843 data_offset);
844
845 if (firmware_info) {
846 /* pixel clocks */
847 p1pll->reference_freq =
848 le16_to_cpu(firmware_info->info.usReferenceClock);
849 p1pll->reference_div = 0;
850
Mathias Fröhlichbc293e52009-10-19 17:49:49 -0400851 if (crev < 2)
852 p1pll->pll_out_min =
853 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
854 else
855 p1pll->pll_out_min =
856 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200857 p1pll->pll_out_max =
858 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
859
860 if (p1pll->pll_out_min == 0) {
861 if (ASIC_IS_AVIVO(rdev))
862 p1pll->pll_out_min = 64800;
863 else
864 p1pll->pll_out_min = 20000;
Alex Deucher8f552a62009-10-27 11:16:09 -0400865 } else if (p1pll->pll_out_min > 64800) {
866 /* Limiting the pll output range is a good thing generally as
867 * it limits the number of possible pll combinations for a given
868 * frequency presumably to the ones that work best on each card.
869 * However, certain duallink DVI monitors seem to like
870 * pll combinations that would be limited by this at least on
871 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
872 * family.
873 */
874 p1pll->pll_out_min = 64800;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200875 }
876
877 p1pll->pll_in_min =
878 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
879 p1pll->pll_in_max =
880 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
881
882 *p2pll = *p1pll;
883
884 /* system clock */
885 spll->reference_freq =
886 le16_to_cpu(firmware_info->info.usReferenceClock);
887 spll->reference_div = 0;
888
889 spll->pll_out_min =
890 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
891 spll->pll_out_max =
892 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
893
894 /* ??? */
895 if (spll->pll_out_min == 0) {
896 if (ASIC_IS_AVIVO(rdev))
897 spll->pll_out_min = 64800;
898 else
899 spll->pll_out_min = 20000;
900 }
901
902 spll->pll_in_min =
903 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
904 spll->pll_in_max =
905 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
906
907 /* memory clock */
908 mpll->reference_freq =
909 le16_to_cpu(firmware_info->info.usReferenceClock);
910 mpll->reference_div = 0;
911
912 mpll->pll_out_min =
913 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
914 mpll->pll_out_max =
915 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
916
917 /* ??? */
918 if (mpll->pll_out_min == 0) {
919 if (ASIC_IS_AVIVO(rdev))
920 mpll->pll_out_min = 64800;
921 else
922 mpll->pll_out_min = 20000;
923 }
924
925 mpll->pll_in_min =
926 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
927 mpll->pll_in_max =
928 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
929
930 rdev->clock.default_sclk =
931 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
932 rdev->clock.default_mclk =
933 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
934
935 return true;
936 }
937 return false;
938}
939
Dave Airlie445282d2009-09-09 17:40:54 +1000940bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
941 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200942{
943 struct drm_device *dev = encoder->base.dev;
944 struct radeon_device *rdev = dev->dev_private;
945 struct radeon_mode_info *mode_info = &rdev->mode_info;
946 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
947 uint16_t data_offset;
948 struct _ATOM_TMDS_INFO *tmds_info;
949 uint8_t frev, crev;
950 uint16_t maxfreq;
951 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200952
953 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
954 &crev, &data_offset);
955
956 tmds_info =
957 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
958 data_offset);
959
960 if (tmds_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200961 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
962 for (i = 0; i < 4; i++) {
963 tmds->tmds_pll[i].freq =
964 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
965 tmds->tmds_pll[i].value =
966 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
967 tmds->tmds_pll[i].value |=
968 (tmds_info->asMiscInfo[i].
969 ucPLL_VCO_Gain & 0x3f) << 6;
970 tmds->tmds_pll[i].value |=
971 (tmds_info->asMiscInfo[i].
972 ucPLL_DutyCycle & 0xf) << 12;
973 tmds->tmds_pll[i].value |=
974 (tmds_info->asMiscInfo[i].
975 ucPLL_VoltageSwing & 0xf) << 16;
976
977 DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
978 tmds->tmds_pll[i].freq,
979 tmds->tmds_pll[i].value);
980
981 if (maxfreq == tmds->tmds_pll[i].freq) {
982 tmds->tmds_pll[i].freq = 0xffffffff;
983 break;
984 }
985 }
Dave Airlie445282d2009-09-09 17:40:54 +1000986 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200987 }
Dave Airlie445282d2009-09-09 17:40:54 +1000988 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200989}
990
Alex Deucherebbe1cb2009-10-16 11:15:25 -0400991static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
992 radeon_encoder
993 *encoder,
994 int id)
995{
996 struct drm_device *dev = encoder->base.dev;
997 struct radeon_device *rdev = dev->dev_private;
998 struct radeon_mode_info *mode_info = &rdev->mode_info;
999 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
1000 uint16_t data_offset;
1001 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1002 uint8_t frev, crev;
1003 struct radeon_atom_ss *ss = NULL;
Alex Deucher279b2152009-12-08 14:07:03 -05001004 int i;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001005
1006 if (id > ATOM_MAX_SS_ENTRY)
1007 return NULL;
1008
1009 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
1010 &crev, &data_offset);
1011
1012 ss_info =
1013 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
1014
1015 if (ss_info) {
1016 ss =
1017 kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
1018
1019 if (!ss)
1020 return NULL;
1021
Alex Deucher279b2152009-12-08 14:07:03 -05001022 for (i = 0; i < ATOM_MAX_SS_ENTRY; i++) {
1023 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1024 ss->percentage =
1025 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1026 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1027 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1028 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1029 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1030 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
1031 }
1032 }
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001033 }
1034 return ss;
1035}
1036
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001037union lvds_info {
1038 struct _ATOM_LVDS_INFO info;
1039 struct _ATOM_LVDS_INFO_V12 info_12;
1040};
1041
1042struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1043 radeon_encoder
1044 *encoder)
1045{
1046 struct drm_device *dev = encoder->base.dev;
1047 struct radeon_device *rdev = dev->dev_private;
1048 struct radeon_mode_info *mode_info = &rdev->mode_info;
1049 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
Alex Deucher7dde8a12009-11-30 01:40:24 -05001050 uint16_t data_offset, misc;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001051 union lvds_info *lvds_info;
1052 uint8_t frev, crev;
1053 struct radeon_encoder_atom_dig *lvds = NULL;
1054
1055 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
1056 &crev, &data_offset);
1057
1058 lvds_info =
1059 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
1060
1061 if (lvds_info) {
1062 lvds =
1063 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1064
1065 if (!lvds)
1066 return NULL;
1067
Alex Deucherde2103e2009-10-09 15:14:30 -04001068 lvds->native_mode.clock =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001069 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
Alex Deucherde2103e2009-10-09 15:14:30 -04001070 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001071 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001072 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001073 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001074 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1075 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1076 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1077 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1078 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1079 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1080 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1081 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1082 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1083 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
1084 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1085 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001086 lvds->panel_pwr_delay =
1087 le16_to_cpu(lvds_info->info.usOffDelayInMs);
1088 lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
Alex Deucher7dde8a12009-11-30 01:40:24 -05001089
1090 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1091 if (misc & ATOM_VSYNC_POLARITY)
1092 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1093 if (misc & ATOM_HSYNC_POLARITY)
1094 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1095 if (misc & ATOM_COMPOSITESYNC)
1096 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1097 if (misc & ATOM_INTERLACE)
1098 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1099 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1100 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1101
Alex Deucherde2103e2009-10-09 15:14:30 -04001102 /* set crtc values */
1103 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001104
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001105 lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
1106
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001107 encoder->native_mode = lvds->native_mode;
1108 }
1109 return lvds;
1110}
1111
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001112struct radeon_encoder_primary_dac *
1113radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1114{
1115 struct drm_device *dev = encoder->base.dev;
1116 struct radeon_device *rdev = dev->dev_private;
1117 struct radeon_mode_info *mode_info = &rdev->mode_info;
1118 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1119 uint16_t data_offset;
1120 struct _COMPASSIONATE_DATA *dac_info;
1121 uint8_t frev, crev;
1122 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001123 struct radeon_encoder_primary_dac *p_dac = NULL;
1124
1125 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1126
1127 dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
1128
1129 if (dac_info) {
1130 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1131
1132 if (!p_dac)
1133 return NULL;
1134
1135 bg = dac_info->ucDAC1_BG_Adjustment;
1136 dac = dac_info->ucDAC1_DAC_Adjustment;
1137 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1138
1139 }
1140 return p_dac;
1141}
1142
Dave Airlie4ce001a2009-08-13 16:32:14 +10001143bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001144 struct drm_display_mode *mode)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001145{
1146 struct radeon_mode_info *mode_info = &rdev->mode_info;
1147 ATOM_ANALOG_TV_INFO *tv_info;
1148 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1149 ATOM_DTD_FORMAT *dtd_timings;
1150 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1151 u8 frev, crev;
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001152 u16 data_offset, misc;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001153
1154 atom_parse_data_header(mode_info->atom_context, data_index, NULL, &frev, &crev, &data_offset);
1155
1156 switch (crev) {
1157 case 1:
1158 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1159 if (index > MAX_SUPPORTED_TV_TIMING)
1160 return false;
1161
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001162 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1163 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1164 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1165 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1166 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001167
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001168 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1169 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1170 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1171 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1172 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001173
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001174 mode->flags = 0;
1175 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1176 if (misc & ATOM_VSYNC_POLARITY)
1177 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1178 if (misc & ATOM_HSYNC_POLARITY)
1179 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1180 if (misc & ATOM_COMPOSITESYNC)
1181 mode->flags |= DRM_MODE_FLAG_CSYNC;
1182 if (misc & ATOM_INTERLACE)
1183 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1184 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1185 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001186
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001187 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001188
1189 if (index == 1) {
1190 /* PAL timings appear to have wrong values for totals */
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001191 mode->crtc_htotal -= 1;
1192 mode->crtc_vtotal -= 1;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001193 }
1194 break;
1195 case 2:
1196 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
1197 if (index > MAX_SUPPORTED_TV_TIMING_V1_2)
1198 return false;
1199
1200 dtd_timings = &tv_info_v1_2->aModeTimings[index];
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001201 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1202 le16_to_cpu(dtd_timings->usHBlanking_Time);
1203 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1204 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1205 le16_to_cpu(dtd_timings->usHSyncOffset);
1206 mode->crtc_hsync_end = mode->crtc_hsync_start +
1207 le16_to_cpu(dtd_timings->usHSyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001208
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001209 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1210 le16_to_cpu(dtd_timings->usVBlanking_Time);
1211 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1212 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1213 le16_to_cpu(dtd_timings->usVSyncOffset);
1214 mode->crtc_vsync_end = mode->crtc_vsync_start +
1215 le16_to_cpu(dtd_timings->usVSyncWidth);
1216
1217 mode->flags = 0;
1218 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1219 if (misc & ATOM_VSYNC_POLARITY)
1220 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1221 if (misc & ATOM_HSYNC_POLARITY)
1222 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1223 if (misc & ATOM_COMPOSITESYNC)
1224 mode->flags |= DRM_MODE_FLAG_CSYNC;
1225 if (misc & ATOM_INTERLACE)
1226 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1227 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1228 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1229
1230 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001231 break;
1232 }
1233 return true;
1234}
1235
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001236struct radeon_encoder_tv_dac *
1237radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1238{
1239 struct drm_device *dev = encoder->base.dev;
1240 struct radeon_device *rdev = dev->dev_private;
1241 struct radeon_mode_info *mode_info = &rdev->mode_info;
1242 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1243 uint16_t data_offset;
1244 struct _COMPASSIONATE_DATA *dac_info;
1245 uint8_t frev, crev;
1246 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001247 struct radeon_encoder_tv_dac *tv_dac = NULL;
1248
1249 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1250
1251 dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
1252
1253 if (dac_info) {
1254 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1255
1256 if (!tv_dac)
1257 return NULL;
1258
1259 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1260 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1261 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1262
1263 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1264 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1265 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1266
1267 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1268 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1269 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1270
1271 }
1272 return tv_dac;
1273}
1274
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001275void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
1276{
1277 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
1278 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
1279
1280 args.ucEnable = enable;
1281
1282 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1283}
1284
1285void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable)
1286{
1287 ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args;
1288 int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt);
1289
1290 args.ucEnable = enable;
1291
1292 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1293}
1294
Rafał Miłecki74338742009-11-03 00:53:02 +01001295uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
1296{
1297 GET_ENGINE_CLOCK_PS_ALLOCATION args;
1298 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
1299
1300 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1301 return args.ulReturnEngineClock;
1302}
1303
1304uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
1305{
1306 GET_MEMORY_CLOCK_PS_ALLOCATION args;
1307 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
1308
1309 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1310 return args.ulReturnMemoryClock;
1311}
1312
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001313void radeon_atom_set_engine_clock(struct radeon_device *rdev,
1314 uint32_t eng_clock)
1315{
1316 SET_ENGINE_CLOCK_PS_ALLOCATION args;
1317 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
1318
1319 args.ulTargetEngineClock = eng_clock; /* 10 khz */
1320
1321 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1322}
1323
1324void radeon_atom_set_memory_clock(struct radeon_device *rdev,
1325 uint32_t mem_clock)
1326{
1327 SET_MEMORY_CLOCK_PS_ALLOCATION args;
1328 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
1329
1330 if (rdev->flags & RADEON_IS_IGP)
1331 return;
1332
1333 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
1334
1335 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1336}
1337
1338void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
1339{
1340 struct radeon_device *rdev = dev->dev_private;
1341 uint32_t bios_2_scratch, bios_6_scratch;
1342
1343 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001344 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001345 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1346 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001347 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001348 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1349 }
1350
1351 /* let the bios control the backlight */
1352 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
1353
1354 /* tell the bios not to handle mode switching */
1355 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
1356
1357 if (rdev->family >= CHIP_R600) {
1358 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
1359 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1360 } else {
1361 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
1362 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1363 }
1364
1365}
1366
Yang Zhaof657c2a2009-09-15 12:21:01 +10001367void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
1368{
1369 uint32_t scratch_reg;
1370 int i;
1371
1372 if (rdev->family >= CHIP_R600)
1373 scratch_reg = R600_BIOS_0_SCRATCH;
1374 else
1375 scratch_reg = RADEON_BIOS_0_SCRATCH;
1376
1377 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
1378 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
1379}
1380
1381void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
1382{
1383 uint32_t scratch_reg;
1384 int i;
1385
1386 if (rdev->family >= CHIP_R600)
1387 scratch_reg = R600_BIOS_0_SCRATCH;
1388 else
1389 scratch_reg = RADEON_BIOS_0_SCRATCH;
1390
1391 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
1392 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
1393}
1394
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001395void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
1396{
1397 struct drm_device *dev = encoder->dev;
1398 struct radeon_device *rdev = dev->dev_private;
1399 uint32_t bios_6_scratch;
1400
1401 if (rdev->family >= CHIP_R600)
1402 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1403 else
1404 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1405
1406 if (lock)
1407 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
1408 else
1409 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
1410
1411 if (rdev->family >= CHIP_R600)
1412 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1413 else
1414 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1415}
1416
1417/* at some point we may want to break this out into individual functions */
1418void
1419radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
1420 struct drm_encoder *encoder,
1421 bool connected)
1422{
1423 struct drm_device *dev = connector->dev;
1424 struct radeon_device *rdev = dev->dev_private;
1425 struct radeon_connector *radeon_connector =
1426 to_radeon_connector(connector);
1427 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1428 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
1429
1430 if (rdev->family >= CHIP_R600) {
1431 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
1432 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
1433 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1434 } else {
1435 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
1436 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
1437 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1438 }
1439
1440 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
1441 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
1442 if (connected) {
1443 DRM_DEBUG("TV1 connected\n");
1444 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
1445 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
1446 } else {
1447 DRM_DEBUG("TV1 disconnected\n");
1448 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
1449 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
1450 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
1451 }
1452 }
1453 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
1454 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
1455 if (connected) {
1456 DRM_DEBUG("CV connected\n");
1457 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
1458 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
1459 } else {
1460 DRM_DEBUG("CV disconnected\n");
1461 bios_0_scratch &= ~ATOM_S0_CV_MASK;
1462 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
1463 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
1464 }
1465 }
1466 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
1467 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
1468 if (connected) {
1469 DRM_DEBUG("LCD1 connected\n");
1470 bios_0_scratch |= ATOM_S0_LCD1;
1471 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
1472 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
1473 } else {
1474 DRM_DEBUG("LCD1 disconnected\n");
1475 bios_0_scratch &= ~ATOM_S0_LCD1;
1476 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
1477 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
1478 }
1479 }
1480 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
1481 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
1482 if (connected) {
1483 DRM_DEBUG("CRT1 connected\n");
1484 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
1485 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
1486 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
1487 } else {
1488 DRM_DEBUG("CRT1 disconnected\n");
1489 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
1490 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
1491 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
1492 }
1493 }
1494 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
1495 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
1496 if (connected) {
1497 DRM_DEBUG("CRT2 connected\n");
1498 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
1499 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
1500 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
1501 } else {
1502 DRM_DEBUG("CRT2 disconnected\n");
1503 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
1504 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
1505 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
1506 }
1507 }
1508 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
1509 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
1510 if (connected) {
1511 DRM_DEBUG("DFP1 connected\n");
1512 bios_0_scratch |= ATOM_S0_DFP1;
1513 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
1514 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
1515 } else {
1516 DRM_DEBUG("DFP1 disconnected\n");
1517 bios_0_scratch &= ~ATOM_S0_DFP1;
1518 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
1519 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
1520 }
1521 }
1522 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
1523 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
1524 if (connected) {
1525 DRM_DEBUG("DFP2 connected\n");
1526 bios_0_scratch |= ATOM_S0_DFP2;
1527 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
1528 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
1529 } else {
1530 DRM_DEBUG("DFP2 disconnected\n");
1531 bios_0_scratch &= ~ATOM_S0_DFP2;
1532 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
1533 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
1534 }
1535 }
1536 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
1537 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
1538 if (connected) {
1539 DRM_DEBUG("DFP3 connected\n");
1540 bios_0_scratch |= ATOM_S0_DFP3;
1541 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
1542 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
1543 } else {
1544 DRM_DEBUG("DFP3 disconnected\n");
1545 bios_0_scratch &= ~ATOM_S0_DFP3;
1546 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
1547 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
1548 }
1549 }
1550 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
1551 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
1552 if (connected) {
1553 DRM_DEBUG("DFP4 connected\n");
1554 bios_0_scratch |= ATOM_S0_DFP4;
1555 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
1556 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
1557 } else {
1558 DRM_DEBUG("DFP4 disconnected\n");
1559 bios_0_scratch &= ~ATOM_S0_DFP4;
1560 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
1561 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
1562 }
1563 }
1564 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
1565 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
1566 if (connected) {
1567 DRM_DEBUG("DFP5 connected\n");
1568 bios_0_scratch |= ATOM_S0_DFP5;
1569 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
1570 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
1571 } else {
1572 DRM_DEBUG("DFP5 disconnected\n");
1573 bios_0_scratch &= ~ATOM_S0_DFP5;
1574 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
1575 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
1576 }
1577 }
1578
1579 if (rdev->family >= CHIP_R600) {
1580 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
1581 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
1582 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1583 } else {
1584 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
1585 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
1586 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1587 }
1588}
1589
1590void
1591radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
1592{
1593 struct drm_device *dev = encoder->dev;
1594 struct radeon_device *rdev = dev->dev_private;
1595 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1596 uint32_t bios_3_scratch;
1597
1598 if (rdev->family >= CHIP_R600)
1599 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
1600 else
1601 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
1602
1603 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
1604 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
1605 bios_3_scratch |= (crtc << 18);
1606 }
1607 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
1608 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
1609 bios_3_scratch |= (crtc << 24);
1610 }
1611 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
1612 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
1613 bios_3_scratch |= (crtc << 16);
1614 }
1615 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
1616 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
1617 bios_3_scratch |= (crtc << 20);
1618 }
1619 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1620 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
1621 bios_3_scratch |= (crtc << 17);
1622 }
1623 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
1624 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
1625 bios_3_scratch |= (crtc << 19);
1626 }
1627 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
1628 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
1629 bios_3_scratch |= (crtc << 23);
1630 }
1631 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
1632 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
1633 bios_3_scratch |= (crtc << 25);
1634 }
1635
1636 if (rdev->family >= CHIP_R600)
1637 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
1638 else
1639 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
1640}
1641
1642void
1643radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
1644{
1645 struct drm_device *dev = encoder->dev;
1646 struct radeon_device *rdev = dev->dev_private;
1647 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1648 uint32_t bios_2_scratch;
1649
1650 if (rdev->family >= CHIP_R600)
1651 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
1652 else
1653 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
1654
1655 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
1656 if (on)
1657 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
1658 else
1659 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
1660 }
1661 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
1662 if (on)
1663 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
1664 else
1665 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
1666 }
1667 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
1668 if (on)
1669 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
1670 else
1671 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
1672 }
1673 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
1674 if (on)
1675 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
1676 else
1677 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
1678 }
1679 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1680 if (on)
1681 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
1682 else
1683 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
1684 }
1685 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
1686 if (on)
1687 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
1688 else
1689 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
1690 }
1691 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
1692 if (on)
1693 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
1694 else
1695 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
1696 }
1697 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
1698 if (on)
1699 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
1700 else
1701 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
1702 }
1703 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
1704 if (on)
1705 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
1706 else
1707 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
1708 }
1709 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
1710 if (on)
1711 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
1712 else
1713 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
1714 }
1715
1716 if (rdev->family >= CHIP_R600)
1717 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
1718 else
1719 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
1720}