blob: e4540b2b859c9b0a3bfa31be4386f51bb89049c8 [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;
Alex Deucher1d3d51b2009-12-28 13:45:23 -0500117 break;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500118 }
119 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200120
121 return i2c;
122}
123
Alex Deuchereed45b32009-12-04 14:45:27 -0500124static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
125 u8 id)
126{
127 struct atom_context *ctx = rdev->mode_info.atom_context;
128 struct radeon_gpio_rec gpio;
129 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
130 struct _ATOM_GPIO_PIN_LUT *gpio_info;
131 ATOM_GPIO_PIN_ASSIGNMENT *pin;
132 u16 data_offset, size;
133 int i, num_indices;
134
135 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
136 gpio.valid = false;
137
138 atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset);
139
140 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
141
142 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
143
144 for (i = 0; i < num_indices; i++) {
145 pin = &gpio_info->asGPIO_Pin[i];
146 if (id == pin->ucGPIO_ID) {
147 gpio.id = pin->ucGPIO_ID;
148 gpio.reg = pin->usGpioPin_AIndex * 4;
149 gpio.mask = (1 << pin->ucGpioPinBitShift);
150 gpio.valid = true;
151 break;
152 }
153 }
154
155 return gpio;
156}
157
158static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
159 struct radeon_gpio_rec *gpio)
160{
161 struct radeon_hpd hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500162 u32 reg;
163
164 if (ASIC_IS_DCE4(rdev))
165 reg = EVERGREEN_DC_GPIO_HPD_A;
166 else
167 reg = AVIVO_DC_GPIO_HPD_A;
168
Alex Deuchereed45b32009-12-04 14:45:27 -0500169 hpd.gpio = *gpio;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500170 if (gpio->reg == reg) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500171 switch(gpio->mask) {
172 case (1 << 0):
173 hpd.hpd = RADEON_HPD_1;
174 break;
175 case (1 << 8):
176 hpd.hpd = RADEON_HPD_2;
177 break;
178 case (1 << 16):
179 hpd.hpd = RADEON_HPD_3;
180 break;
181 case (1 << 24):
182 hpd.hpd = RADEON_HPD_4;
183 break;
184 case (1 << 26):
185 hpd.hpd = RADEON_HPD_5;
186 break;
187 case (1 << 28):
188 hpd.hpd = RADEON_HPD_6;
189 break;
190 default:
191 hpd.hpd = RADEON_HPD_NONE;
192 break;
193 }
194 } else
195 hpd.hpd = RADEON_HPD_NONE;
196 return hpd;
197}
198
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200199static bool radeon_atom_apply_quirks(struct drm_device *dev,
200 uint32_t supported_device,
201 int *connector_type,
Alex Deucher848577e2009-07-08 16:15:30 -0400202 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -0500203 uint16_t *line_mux,
204 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200205{
206
207 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
208 if ((dev->pdev->device == 0x791e) &&
209 (dev->pdev->subsystem_vendor == 0x1043) &&
210 (dev->pdev->subsystem_device == 0x826d)) {
211 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
212 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
213 *connector_type = DRM_MODE_CONNECTOR_DVID;
214 }
215
Alex Deucherc86a9032010-02-18 14:14:58 -0500216 /* Asrock RS600 board lists the DVI port as HDMI */
217 if ((dev->pdev->device == 0x7941) &&
218 (dev->pdev->subsystem_vendor == 0x1849) &&
219 (dev->pdev->subsystem_device == 0x7941)) {
220 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
221 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
222 *connector_type = DRM_MODE_CONNECTOR_DVID;
223 }
224
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200225 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
226 if ((dev->pdev->device == 0x7941) &&
227 (dev->pdev->subsystem_vendor == 0x147b) &&
228 (dev->pdev->subsystem_device == 0x2412)) {
229 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
230 return false;
231 }
232
233 /* Falcon NW laptop lists vga ddc line for LVDS */
234 if ((dev->pdev->device == 0x5653) &&
235 (dev->pdev->subsystem_vendor == 0x1462) &&
236 (dev->pdev->subsystem_device == 0x0291)) {
Alex Deucher848577e2009-07-08 16:15:30 -0400237 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200238 i2c_bus->valid = false;
Alex Deucher848577e2009-07-08 16:15:30 -0400239 *line_mux = 53;
240 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200241 }
242
Alex Deucher4e3f9b72009-12-01 14:49:50 -0500243 /* HIS X1300 is DVI+VGA, not DVI+DVI */
244 if ((dev->pdev->device == 0x7146) &&
245 (dev->pdev->subsystem_vendor == 0x17af) &&
246 (dev->pdev->subsystem_device == 0x2058)) {
247 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
248 return false;
249 }
250
Dave Airlieaa1a7502009-12-04 11:51:34 +1000251 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
252 if ((dev->pdev->device == 0x7142) &&
253 (dev->pdev->subsystem_vendor == 0x1458) &&
254 (dev->pdev->subsystem_device == 0x2134)) {
255 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
256 return false;
257 }
258
259
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200260 /* Funky macbooks */
261 if ((dev->pdev->device == 0x71C5) &&
262 (dev->pdev->subsystem_vendor == 0x106b) &&
263 (dev->pdev->subsystem_device == 0x0080)) {
264 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
265 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
266 return false;
267 }
268
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200269 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
270 if ((dev->pdev->device == 0x9598) &&
271 (dev->pdev->subsystem_vendor == 0x1043) &&
272 (dev->pdev->subsystem_device == 0x01da)) {
Alex Deucher705af9c2009-09-10 16:31:13 -0400273 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400274 *connector_type = DRM_MODE_CONNECTOR_DVII;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200275 }
276 }
277
Alex Deucher705af9c2009-09-10 16:31:13 -0400278 /* ASUS HD 3450 board lists the DVI port as HDMI */
279 if ((dev->pdev->device == 0x95C5) &&
280 (dev->pdev->subsystem_vendor == 0x1043) &&
281 (dev->pdev->subsystem_device == 0x01e2)) {
282 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400283 *connector_type = DRM_MODE_CONNECTOR_DVII;
Alex Deucher705af9c2009-09-10 16:31:13 -0400284 }
285 }
286
287 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
288 * HDMI + VGA reporting as HDMI
289 */
290 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
291 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
292 *connector_type = DRM_MODE_CONNECTOR_VGA;
293 *line_mux = 0;
294 }
295 }
296
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500297 /* Acer laptop reports DVI-D as DVI-I */
298 if ((dev->pdev->device == 0x95c4) &&
299 (dev->pdev->subsystem_vendor == 0x1025) &&
300 (dev->pdev->subsystem_device == 0x013c)) {
301 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
302 (supported_device == ATOM_DEVICE_DFP1_SUPPORT))
303 *connector_type = DRM_MODE_CONNECTOR_DVID;
304 }
305
Dave Airlieefa84502010-02-09 09:06:00 +1000306 /* XFX Pine Group device rv730 reports no VGA DDC lines
307 * even though they are wired up to record 0x93
308 */
309 if ((dev->pdev->device == 0x9498) &&
310 (dev->pdev->subsystem_vendor == 0x1682) &&
311 (dev->pdev->subsystem_device == 0x2452)) {
312 struct radeon_device *rdev = dev->dev_private;
313 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
314 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200315 return true;
316}
317
318const int supported_devices_connector_convert[] = {
319 DRM_MODE_CONNECTOR_Unknown,
320 DRM_MODE_CONNECTOR_VGA,
321 DRM_MODE_CONNECTOR_DVII,
322 DRM_MODE_CONNECTOR_DVID,
323 DRM_MODE_CONNECTOR_DVIA,
324 DRM_MODE_CONNECTOR_SVIDEO,
325 DRM_MODE_CONNECTOR_Composite,
326 DRM_MODE_CONNECTOR_LVDS,
327 DRM_MODE_CONNECTOR_Unknown,
328 DRM_MODE_CONNECTOR_Unknown,
329 DRM_MODE_CONNECTOR_HDMIA,
330 DRM_MODE_CONNECTOR_HDMIB,
331 DRM_MODE_CONNECTOR_Unknown,
332 DRM_MODE_CONNECTOR_Unknown,
333 DRM_MODE_CONNECTOR_9PinDIN,
334 DRM_MODE_CONNECTOR_DisplayPort
335};
336
Alex Deucherb75fad02009-11-05 13:16:01 -0500337const uint16_t supported_devices_connector_object_id_convert[] = {
338 CONNECTOR_OBJECT_ID_NONE,
339 CONNECTOR_OBJECT_ID_VGA,
340 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
341 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
342 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
343 CONNECTOR_OBJECT_ID_COMPOSITE,
344 CONNECTOR_OBJECT_ID_SVIDEO,
345 CONNECTOR_OBJECT_ID_LVDS,
346 CONNECTOR_OBJECT_ID_9PIN_DIN,
347 CONNECTOR_OBJECT_ID_9PIN_DIN,
348 CONNECTOR_OBJECT_ID_DISPLAYPORT,
349 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
350 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
351 CONNECTOR_OBJECT_ID_SVIDEO
352};
353
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200354const int object_connector_convert[] = {
355 DRM_MODE_CONNECTOR_Unknown,
356 DRM_MODE_CONNECTOR_DVII,
357 DRM_MODE_CONNECTOR_DVII,
358 DRM_MODE_CONNECTOR_DVID,
359 DRM_MODE_CONNECTOR_DVID,
360 DRM_MODE_CONNECTOR_VGA,
361 DRM_MODE_CONNECTOR_Composite,
362 DRM_MODE_CONNECTOR_SVIDEO,
363 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher705af9c2009-09-10 16:31:13 -0400364 DRM_MODE_CONNECTOR_Unknown,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200365 DRM_MODE_CONNECTOR_9PinDIN,
366 DRM_MODE_CONNECTOR_Unknown,
367 DRM_MODE_CONNECTOR_HDMIA,
368 DRM_MODE_CONNECTOR_HDMIB,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200369 DRM_MODE_CONNECTOR_LVDS,
370 DRM_MODE_CONNECTOR_9PinDIN,
371 DRM_MODE_CONNECTOR_Unknown,
372 DRM_MODE_CONNECTOR_Unknown,
373 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher196c58d2010-01-07 14:22:32 -0500374 DRM_MODE_CONNECTOR_DisplayPort,
375 DRM_MODE_CONNECTOR_eDP,
376 DRM_MODE_CONNECTOR_Unknown
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200377};
378
379bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
380{
381 struct radeon_device *rdev = dev->dev_private;
382 struct radeon_mode_info *mode_info = &rdev->mode_info;
383 struct atom_context *ctx = mode_info->atom_context;
384 int index = GetIndexIntoMasterTable(DATA, Object_Header);
Alex Deuchereed45b32009-12-04 14:45:27 -0500385 u16 size, data_offset;
386 u8 frev, crev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200387 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
388 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
389 ATOM_OBJECT_HEADER *obj_header;
390 int i, j, path_size, device_support;
391 int connector_type;
Alex Deuchereed45b32009-12-04 14:45:27 -0500392 u16 igp_lane_info, conn_id, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200393 bool linkb;
394 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500395 struct radeon_gpio_rec gpio;
396 struct radeon_hpd hpd;
397
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200398 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
399
400 if (data_offset == 0)
401 return false;
402
403 if (crev < 2)
404 return false;
405
406 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
407 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
408 (ctx->bios + data_offset +
409 le16_to_cpu(obj_header->usDisplayPathTableOffset));
410 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
411 (ctx->bios + data_offset +
412 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
413 device_support = le16_to_cpu(obj_header->usDeviceSupport);
414
415 path_size = 0;
416 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
417 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
418 ATOM_DISPLAY_OBJECT_PATH *path;
419 addr += path_size;
420 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
421 path_size += le16_to_cpu(path->usSize);
422 linkb = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200423 if (device_support & le16_to_cpu(path->usDeviceTag)) {
424 uint8_t con_obj_id, con_obj_num, con_obj_type;
425
426 con_obj_id =
427 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
428 >> OBJECT_ID_SHIFT;
429 con_obj_num =
430 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
431 >> ENUM_ID_SHIFT;
432 con_obj_type =
433 (le16_to_cpu(path->usConnObjectId) &
434 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
435
Dave Airlie4bbd4972009-09-25 08:56:12 +1000436 /* TODO CV support */
437 if (le16_to_cpu(path->usDeviceTag) ==
438 ATOM_DEVICE_CV_SUPPORT)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200439 continue;
440
Alex Deucheree59f2b2009-11-05 13:11:46 -0500441 /* IGP chips */
442 if ((rdev->flags & RADEON_IS_IGP) &&
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200443 (con_obj_id ==
444 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
445 uint16_t igp_offset = 0;
446 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
447
448 index =
449 GetIndexIntoMasterTable(DATA,
450 IntegratedSystemInfo);
451
452 atom_parse_data_header(ctx, index, &size, &frev,
453 &crev, &igp_offset);
454
455 if (crev >= 2) {
456 igp_obj =
457 (ATOM_INTEGRATED_SYSTEM_INFO_V2
458 *) (ctx->bios + igp_offset);
459
460 if (igp_obj) {
461 uint32_t slot_config, ct;
462
463 if (con_obj_num == 1)
464 slot_config =
465 igp_obj->
466 ulDDISlot1Config;
467 else
468 slot_config =
469 igp_obj->
470 ulDDISlot2Config;
471
472 ct = (slot_config >> 16) & 0xff;
473 connector_type =
474 object_connector_convert
475 [ct];
Alex Deucherb75fad02009-11-05 13:16:01 -0500476 connector_object_id = ct;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200477 igp_lane_info =
478 slot_config & 0xffff;
479 } else
480 continue;
481 } else
482 continue;
483 } else {
484 igp_lane_info = 0;
485 connector_type =
486 object_connector_convert[con_obj_id];
Alex Deucherb75fad02009-11-05 13:16:01 -0500487 connector_object_id = con_obj_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200488 }
489
490 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
491 continue;
492
493 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2);
494 j++) {
495 uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
496
497 enc_obj_id =
498 (le16_to_cpu(path->usGraphicObjIds[j]) &
499 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
500 enc_obj_num =
501 (le16_to_cpu(path->usGraphicObjIds[j]) &
502 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
503 enc_obj_type =
504 (le16_to_cpu(path->usGraphicObjIds[j]) &
505 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
506
507 /* FIXME: add support for router objects */
508 if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
509 if (enc_obj_num == 2)
510 linkb = true;
511 else
512 linkb = false;
513
514 radeon_add_atom_encoder(dev,
515 enc_obj_id,
516 le16_to_cpu
517 (path->
518 usDeviceTag));
519
520 }
521 }
522
Alex Deuchereed45b32009-12-04 14:45:27 -0500523 /* look up gpio for ddc, hpd */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200524 if ((le16_to_cpu(path->usDeviceTag) &
Alex Deuchereed45b32009-12-04 14:45:27 -0500525 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200526 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
527 if (le16_to_cpu(path->usConnObjectId) ==
528 le16_to_cpu(con_obj->asObjects[j].
529 usObjectID)) {
530 ATOM_COMMON_RECORD_HEADER
531 *record =
532 (ATOM_COMMON_RECORD_HEADER
533 *)
534 (ctx->bios + data_offset +
535 le16_to_cpu(con_obj->
536 asObjects[j].
537 usRecordOffset));
538 ATOM_I2C_RECORD *i2c_record;
Alex Deuchereed45b32009-12-04 14:45:27 -0500539 ATOM_HPD_INT_RECORD *hpd_record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500540 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
Alex Deuchereed45b32009-12-04 14:45:27 -0500541 hpd.hpd = RADEON_HPD_NONE;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500542
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200543 while (record->ucRecordType > 0
544 && record->
545 ucRecordType <=
546 ATOM_MAX_OBJECT_RECORD_NUMBER) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500547 switch (record->ucRecordType) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200548 case ATOM_I2C_RECORD_TYPE:
549 i2c_record =
Alex Deuchereed45b32009-12-04 14:45:27 -0500550 (ATOM_I2C_RECORD *)
551 record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500552 i2c_config =
553 (ATOM_I2C_ID_CONFIG_ACCESS *)
554 &i2c_record->sucI2cId;
Alex Deuchereed45b32009-12-04 14:45:27 -0500555 ddc_bus = radeon_lookup_i2c_gpio(rdev,
Alex Deucherd3f420d2009-12-08 14:30:49 -0500556 i2c_config->
557 ucAccess);
Alex Deuchereed45b32009-12-04 14:45:27 -0500558 break;
559 case ATOM_HPD_INT_RECORD_TYPE:
560 hpd_record =
561 (ATOM_HPD_INT_RECORD *)
562 record;
563 gpio = radeon_lookup_gpio(rdev,
564 hpd_record->ucHPDIntGPIOID);
565 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
566 hpd.plugged_state = hpd_record->ucPlugged_PinState;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200567 break;
568 }
569 record =
570 (ATOM_COMMON_RECORD_HEADER
571 *) ((char *)record
572 +
573 record->
574 ucRecordSize);
575 }
576 break;
577 }
578 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500579 } else {
580 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200581 ddc_bus.valid = false;
Alex Deuchereed45b32009-12-04 14:45:27 -0500582 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200583
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500584 /* needed for aux chan transactions */
585 ddc_bus.hpd_id = hpd.hpd ? (hpd.hpd - 1) : 0;
586
Alex Deucher705af9c2009-09-10 16:31:13 -0400587 conn_id = le16_to_cpu(path->usConnObjectId);
588
589 if (!radeon_atom_apply_quirks
590 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500591 &ddc_bus, &conn_id, &hpd))
Alex Deucher705af9c2009-09-10 16:31:13 -0400592 continue;
593
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200594 radeon_add_atom_connector(dev,
Alex Deucher705af9c2009-09-10 16:31:13 -0400595 conn_id,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200596 le16_to_cpu(path->
597 usDeviceTag),
598 connector_type, &ddc_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -0500599 linkb, igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -0500600 connector_object_id,
601 &hpd);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200602
603 }
604 }
605
606 radeon_link_encoder_connector(dev);
607
608 return true;
609}
610
Alex Deucherb75fad02009-11-05 13:16:01 -0500611static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
612 int connector_type,
613 uint16_t devices)
614{
615 struct radeon_device *rdev = dev->dev_private;
616
617 if (rdev->flags & RADEON_IS_IGP) {
618 return supported_devices_connector_object_id_convert
619 [connector_type];
620 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
621 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
622 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
623 struct radeon_mode_info *mode_info = &rdev->mode_info;
624 struct atom_context *ctx = mode_info->atom_context;
625 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
626 uint16_t size, data_offset;
627 uint8_t frev, crev;
628 ATOM_XTMDS_INFO *xtmds;
629
630 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
631 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
632
633 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
634 if (connector_type == DRM_MODE_CONNECTOR_DVII)
635 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
636 else
637 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
638 } else {
639 if (connector_type == DRM_MODE_CONNECTOR_DVII)
640 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
641 else
642 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
643 }
644 } else {
645 return supported_devices_connector_object_id_convert
646 [connector_type];
647 }
648}
649
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200650struct bios_connector {
651 bool valid;
Alex Deucher705af9c2009-09-10 16:31:13 -0400652 uint16_t line_mux;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200653 uint16_t devices;
654 int connector_type;
655 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500656 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200657};
658
659bool radeon_get_atom_connector_info_from_supported_devices_table(struct
660 drm_device
661 *dev)
662{
663 struct radeon_device *rdev = dev->dev_private;
664 struct radeon_mode_info *mode_info = &rdev->mode_info;
665 struct atom_context *ctx = mode_info->atom_context;
666 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
667 uint16_t size, data_offset;
668 uint8_t frev, crev;
669 uint16_t device_support;
670 uint8_t dac;
671 union atom_supported_devices *supported_devices;
Alex Deuchereed45b32009-12-04 14:45:27 -0500672 int i, j, max_device;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200673 struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
674
675 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
676
677 supported_devices =
678 (union atom_supported_devices *)(ctx->bios + data_offset);
679
680 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
681
Alex Deuchereed45b32009-12-04 14:45:27 -0500682 if (frev > 1)
683 max_device = ATOM_MAX_SUPPORTED_DEVICE;
684 else
685 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
686
687 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200688 ATOM_CONNECTOR_INFO_I2C ci =
689 supported_devices->info.asConnInfo[i];
690
691 bios_connectors[i].valid = false;
692
693 if (!(device_support & (1 << i))) {
694 continue;
695 }
696
697 if (i == ATOM_DEVICE_CV_INDEX) {
698 DRM_DEBUG("Skipping Component Video\n");
699 continue;
700 }
701
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200702 bios_connectors[i].connector_type =
703 supported_devices_connector_convert[ci.sucConnectorInfo.
704 sbfAccess.
705 bfConnectorType];
706
707 if (bios_connectors[i].connector_type ==
708 DRM_MODE_CONNECTOR_Unknown)
709 continue;
710
711 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
712
Alex Deucherd3f420d2009-12-08 14:30:49 -0500713 bios_connectors[i].line_mux =
714 ci.sucI2cId.ucAccess;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200715
716 /* give tv unique connector ids */
717 if (i == ATOM_DEVICE_TV1_INDEX) {
718 bios_connectors[i].ddc_bus.valid = false;
719 bios_connectors[i].line_mux = 50;
720 } else if (i == ATOM_DEVICE_TV2_INDEX) {
721 bios_connectors[i].ddc_bus.valid = false;
722 bios_connectors[i].line_mux = 51;
723 } else if (i == ATOM_DEVICE_CV_INDEX) {
724 bios_connectors[i].ddc_bus.valid = false;
725 bios_connectors[i].line_mux = 52;
726 } else
727 bios_connectors[i].ddc_bus =
Alex Deuchereed45b32009-12-04 14:45:27 -0500728 radeon_lookup_i2c_gpio(rdev,
729 bios_connectors[i].line_mux);
730
731 if ((crev > 1) && (frev > 1)) {
732 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
733 switch (isb) {
734 case 0x4:
735 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
736 break;
737 case 0xa:
738 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
739 break;
740 default:
741 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
742 break;
743 }
744 } else {
745 if (i == ATOM_DEVICE_DFP1_INDEX)
746 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
747 else if (i == ATOM_DEVICE_DFP2_INDEX)
748 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
749 else
750 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
751 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200752
753 /* Always set the connector type to VGA for CRT1/CRT2. if they are
754 * shared with a DVI port, we'll pick up the DVI connector when we
755 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
756 */
757 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
758 bios_connectors[i].connector_type =
759 DRM_MODE_CONNECTOR_VGA;
760
761 if (!radeon_atom_apply_quirks
762 (dev, (1 << i), &bios_connectors[i].connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500763 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
764 &bios_connectors[i].hpd))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200765 continue;
766
767 bios_connectors[i].valid = true;
768 bios_connectors[i].devices = (1 << i);
769
770 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
771 radeon_add_atom_encoder(dev,
772 radeon_get_encoder_id(dev,
773 (1 << i),
774 dac),
775 (1 << i));
776 else
777 radeon_add_legacy_encoder(dev,
778 radeon_get_encoder_id(dev,
Alex Deucherf56cd642009-12-18 11:28:22 -0500779 (1 << i),
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200780 dac),
781 (1 << i));
782 }
783
784 /* combine shared connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -0500785 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200786 if (bios_connectors[i].valid) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500787 for (j = 0; j < max_device; j++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200788 if (bios_connectors[j].valid && (i != j)) {
789 if (bios_connectors[i].line_mux ==
790 bios_connectors[j].line_mux) {
Alex Deucherf56cd642009-12-18 11:28:22 -0500791 /* make sure not to combine LVDS */
792 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
793 bios_connectors[i].line_mux = 53;
794 bios_connectors[i].ddc_bus.valid = false;
795 continue;
796 }
797 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
798 bios_connectors[j].line_mux = 53;
799 bios_connectors[j].ddc_bus.valid = false;
800 continue;
801 }
802 /* combine analog and digital for DVI-I */
803 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
804 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
805 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
806 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
807 bios_connectors[i].devices |=
808 bios_connectors[j].devices;
809 bios_connectors[i].connector_type =
810 DRM_MODE_CONNECTOR_DVII;
811 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
Alex Deuchereed45b32009-12-04 14:45:27 -0500812 bios_connectors[i].hpd =
813 bios_connectors[j].hpd;
Alex Deucherf56cd642009-12-18 11:28:22 -0500814 bios_connectors[j].valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200815 }
816 }
817 }
818 }
819 }
820 }
821
822 /* add the connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -0500823 for (i = 0; i < max_device; i++) {
Alex Deucherb75fad02009-11-05 13:16:01 -0500824 if (bios_connectors[i].valid) {
825 uint16_t connector_object_id =
826 atombios_get_connector_object_id(dev,
827 bios_connectors[i].connector_type,
828 bios_connectors[i].devices);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200829 radeon_add_atom_connector(dev,
830 bios_connectors[i].line_mux,
831 bios_connectors[i].devices,
832 bios_connectors[i].
833 connector_type,
834 &bios_connectors[i].ddc_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -0500835 false, 0,
Alex Deuchereed45b32009-12-04 14:45:27 -0500836 connector_object_id,
837 &bios_connectors[i].hpd);
Alex Deucherb75fad02009-11-05 13:16:01 -0500838 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200839 }
840
841 radeon_link_encoder_connector(dev);
842
843 return true;
844}
845
846union firmware_info {
847 ATOM_FIRMWARE_INFO info;
848 ATOM_FIRMWARE_INFO_V1_2 info_12;
849 ATOM_FIRMWARE_INFO_V1_3 info_13;
850 ATOM_FIRMWARE_INFO_V1_4 info_14;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500851 ATOM_FIRMWARE_INFO_V2_1 info_21;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200852};
853
854bool radeon_atom_get_clock_info(struct drm_device *dev)
855{
856 struct radeon_device *rdev = dev->dev_private;
857 struct radeon_mode_info *mode_info = &rdev->mode_info;
858 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
859 union firmware_info *firmware_info;
860 uint8_t frev, crev;
861 struct radeon_pll *p1pll = &rdev->clock.p1pll;
862 struct radeon_pll *p2pll = &rdev->clock.p2pll;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500863 struct radeon_pll *dcpll = &rdev->clock.dcpll;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200864 struct radeon_pll *spll = &rdev->clock.spll;
865 struct radeon_pll *mpll = &rdev->clock.mpll;
866 uint16_t data_offset;
867
868 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
869 &crev, &data_offset);
870
871 firmware_info =
872 (union firmware_info *)(mode_info->atom_context->bios +
873 data_offset);
874
875 if (firmware_info) {
876 /* pixel clocks */
877 p1pll->reference_freq =
878 le16_to_cpu(firmware_info->info.usReferenceClock);
879 p1pll->reference_div = 0;
880
Mathias Fröhlichbc293e52009-10-19 17:49:49 -0400881 if (crev < 2)
882 p1pll->pll_out_min =
883 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
884 else
885 p1pll->pll_out_min =
886 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200887 p1pll->pll_out_max =
888 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
889
Alex Deucher86cb2bb2010-03-08 12:55:16 -0500890 if (crev >= 4) {
891 p1pll->lcd_pll_out_min =
892 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
893 if (p1pll->lcd_pll_out_min == 0)
894 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
895 p1pll->lcd_pll_out_max =
896 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
897 if (p1pll->lcd_pll_out_max == 0)
898 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
899 } else {
900 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
901 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
902 }
903
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200904 if (p1pll->pll_out_min == 0) {
905 if (ASIC_IS_AVIVO(rdev))
906 p1pll->pll_out_min = 64800;
907 else
908 p1pll->pll_out_min = 20000;
Alex Deucher8f552a62009-10-27 11:16:09 -0400909 } else if (p1pll->pll_out_min > 64800) {
910 /* Limiting the pll output range is a good thing generally as
911 * it limits the number of possible pll combinations for a given
912 * frequency presumably to the ones that work best on each card.
913 * However, certain duallink DVI monitors seem to like
914 * pll combinations that would be limited by this at least on
915 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
916 * family.
917 */
Alex Deucherb27b6372009-12-09 17:44:25 -0500918 if (!radeon_new_pll)
919 p1pll->pll_out_min = 64800;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200920 }
921
922 p1pll->pll_in_min =
923 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
924 p1pll->pll_in_max =
925 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
926
927 *p2pll = *p1pll;
928
929 /* system clock */
930 spll->reference_freq =
931 le16_to_cpu(firmware_info->info.usReferenceClock);
932 spll->reference_div = 0;
933
934 spll->pll_out_min =
935 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
936 spll->pll_out_max =
937 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
938
939 /* ??? */
940 if (spll->pll_out_min == 0) {
941 if (ASIC_IS_AVIVO(rdev))
942 spll->pll_out_min = 64800;
943 else
944 spll->pll_out_min = 20000;
945 }
946
947 spll->pll_in_min =
948 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
949 spll->pll_in_max =
950 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
951
952 /* memory clock */
953 mpll->reference_freq =
954 le16_to_cpu(firmware_info->info.usReferenceClock);
955 mpll->reference_div = 0;
956
957 mpll->pll_out_min =
958 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
959 mpll->pll_out_max =
960 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
961
962 /* ??? */
963 if (mpll->pll_out_min == 0) {
964 if (ASIC_IS_AVIVO(rdev))
965 mpll->pll_out_min = 64800;
966 else
967 mpll->pll_out_min = 20000;
968 }
969
970 mpll->pll_in_min =
971 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
972 mpll->pll_in_max =
973 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
974
975 rdev->clock.default_sclk =
976 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
977 rdev->clock.default_mclk =
978 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
979
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500980 if (ASIC_IS_DCE4(rdev)) {
981 rdev->clock.default_dispclk =
982 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
983 if (rdev->clock.default_dispclk == 0)
984 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
985 rdev->clock.dp_extclk =
986 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
987 }
988 *dcpll = *p1pll;
989
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200990 return true;
991 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500992
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200993 return false;
994}
995
Alex Deucher06b64762010-01-05 11:27:29 -0500996union igp_info {
997 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
998 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
999};
1000
1001bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1002{
1003 struct radeon_mode_info *mode_info = &rdev->mode_info;
1004 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1005 union igp_info *igp_info;
1006 u8 frev, crev;
1007 u16 data_offset;
1008
1009 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
1010 &crev, &data_offset);
1011
1012 igp_info = (union igp_info *)(mode_info->atom_context->bios +
1013 data_offset);
1014
1015 if (igp_info) {
1016 switch (crev) {
1017 case 1:
1018 if (igp_info->info.ucMemoryType & 0xf0)
1019 return true;
1020 break;
1021 case 2:
1022 if (igp_info->info_2.ucMemoryType & 0x0f)
1023 return true;
1024 break;
1025 default:
1026 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1027 break;
1028 }
1029 }
1030 return false;
1031}
1032
Dave Airlie445282d2009-09-09 17:40:54 +10001033bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1034 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001035{
1036 struct drm_device *dev = encoder->base.dev;
1037 struct radeon_device *rdev = dev->dev_private;
1038 struct radeon_mode_info *mode_info = &rdev->mode_info;
1039 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1040 uint16_t data_offset;
1041 struct _ATOM_TMDS_INFO *tmds_info;
1042 uint8_t frev, crev;
1043 uint16_t maxfreq;
1044 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001045
1046 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
1047 &crev, &data_offset);
1048
1049 tmds_info =
1050 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1051 data_offset);
1052
1053 if (tmds_info) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001054 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1055 for (i = 0; i < 4; i++) {
1056 tmds->tmds_pll[i].freq =
1057 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1058 tmds->tmds_pll[i].value =
1059 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1060 tmds->tmds_pll[i].value |=
1061 (tmds_info->asMiscInfo[i].
1062 ucPLL_VCO_Gain & 0x3f) << 6;
1063 tmds->tmds_pll[i].value |=
1064 (tmds_info->asMiscInfo[i].
1065 ucPLL_DutyCycle & 0xf) << 12;
1066 tmds->tmds_pll[i].value |=
1067 (tmds_info->asMiscInfo[i].
1068 ucPLL_VoltageSwing & 0xf) << 16;
1069
1070 DRM_DEBUG("TMDS PLL From ATOMBIOS %u %x\n",
1071 tmds->tmds_pll[i].freq,
1072 tmds->tmds_pll[i].value);
1073
1074 if (maxfreq == tmds->tmds_pll[i].freq) {
1075 tmds->tmds_pll[i].freq = 0xffffffff;
1076 break;
1077 }
1078 }
Dave Airlie445282d2009-09-09 17:40:54 +10001079 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001080 }
Dave Airlie445282d2009-09-09 17:40:54 +10001081 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001082}
1083
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001084static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
1085 radeon_encoder
1086 *encoder,
1087 int id)
1088{
1089 struct drm_device *dev = encoder->base.dev;
1090 struct radeon_device *rdev = dev->dev_private;
1091 struct radeon_mode_info *mode_info = &rdev->mode_info;
1092 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
1093 uint16_t data_offset;
1094 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1095 uint8_t frev, crev;
1096 struct radeon_atom_ss *ss = NULL;
Alex Deucher279b2152009-12-08 14:07:03 -05001097 int i;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001098
1099 if (id > ATOM_MAX_SS_ENTRY)
1100 return NULL;
1101
1102 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
1103 &crev, &data_offset);
1104
1105 ss_info =
1106 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
1107
1108 if (ss_info) {
1109 ss =
1110 kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
1111
1112 if (!ss)
1113 return NULL;
1114
Alex Deucher279b2152009-12-08 14:07:03 -05001115 for (i = 0; i < ATOM_MAX_SS_ENTRY; i++) {
1116 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1117 ss->percentage =
1118 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1119 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1120 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1121 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1122 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1123 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
Alex Deucher1d3d51b2009-12-28 13:45:23 -05001124 break;
Alex Deucher279b2152009-12-08 14:07:03 -05001125 }
1126 }
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001127 }
1128 return ss;
1129}
1130
Alex Deucher09397272010-02-02 12:06:28 -05001131static void radeon_atom_apply_lvds_quirks(struct drm_device *dev,
1132 struct radeon_encoder_atom_dig *lvds)
1133{
1134
1135 /* Toshiba A300-1BU laptop panel doesn't like new pll divider algo */
1136 if ((dev->pdev->device == 0x95c4) &&
1137 (dev->pdev->subsystem_vendor == 0x1179) &&
1138 (dev->pdev->subsystem_device == 0xff50)) {
1139 if ((lvds->native_mode.hdisplay == 1280) &&
1140 (lvds->native_mode.vdisplay == 800))
1141 lvds->pll_algo = PLL_ALGO_LEGACY;
1142 }
1143
Alex Deucher8e0d84a2010-02-16 11:44:21 -05001144 /* Dell Studio 15 laptop panel doesn't like new pll divider algo */
1145 if ((dev->pdev->device == 0x95c4) &&
1146 (dev->pdev->subsystem_vendor == 0x1028) &&
1147 (dev->pdev->subsystem_device == 0x029f)) {
1148 if ((lvds->native_mode.hdisplay == 1280) &&
1149 (lvds->native_mode.vdisplay == 800))
1150 lvds->pll_algo = PLL_ALGO_LEGACY;
1151 }
1152
Alex Deucher09397272010-02-02 12:06:28 -05001153}
1154
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001155union lvds_info {
1156 struct _ATOM_LVDS_INFO info;
1157 struct _ATOM_LVDS_INFO_V12 info_12;
1158};
1159
1160struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1161 radeon_encoder
1162 *encoder)
1163{
1164 struct drm_device *dev = encoder->base.dev;
1165 struct radeon_device *rdev = dev->dev_private;
1166 struct radeon_mode_info *mode_info = &rdev->mode_info;
1167 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
Alex Deucher7dde8a12009-11-30 01:40:24 -05001168 uint16_t data_offset, misc;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001169 union lvds_info *lvds_info;
1170 uint8_t frev, crev;
1171 struct radeon_encoder_atom_dig *lvds = NULL;
1172
1173 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev,
1174 &crev, &data_offset);
1175
1176 lvds_info =
1177 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
1178
1179 if (lvds_info) {
1180 lvds =
1181 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1182
1183 if (!lvds)
1184 return NULL;
1185
Alex Deucherde2103e2009-10-09 15:14:30 -04001186 lvds->native_mode.clock =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001187 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
Alex Deucherde2103e2009-10-09 15:14:30 -04001188 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001189 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001190 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001191 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001192 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1193 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1194 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1195 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1196 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1197 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1198 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1199 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1200 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
1201 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
1202 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1203 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001204 lvds->panel_pwr_delay =
1205 le16_to_cpu(lvds_info->info.usOffDelayInMs);
1206 lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
Alex Deucher7dde8a12009-11-30 01:40:24 -05001207
1208 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1209 if (misc & ATOM_VSYNC_POLARITY)
1210 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1211 if (misc & ATOM_HSYNC_POLARITY)
1212 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1213 if (misc & ATOM_COMPOSITESYNC)
1214 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1215 if (misc & ATOM_INTERLACE)
1216 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1217 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1218 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1219
Alex Deucherde2103e2009-10-09 15:14:30 -04001220 /* set crtc values */
1221 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001222
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001223 lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
1224
Alex Deucher7c27f872010-02-02 12:05:01 -05001225 if (ASIC_IS_AVIVO(rdev)) {
Alex Deucher383be5d2010-02-23 03:24:38 -05001226 if (radeon_new_pll == 0)
1227 lvds->pll_algo = PLL_ALGO_LEGACY;
1228 else
1229 lvds->pll_algo = PLL_ALGO_NEW;
1230 } else {
1231 if (radeon_new_pll == 1)
1232 lvds->pll_algo = PLL_ALGO_NEW;
Alex Deucher7c27f872010-02-02 12:05:01 -05001233 else
1234 lvds->pll_algo = PLL_ALGO_LEGACY;
Alex Deucher383be5d2010-02-23 03:24:38 -05001235 }
Alex Deucher7c27f872010-02-02 12:05:01 -05001236
Alex Deucher09397272010-02-02 12:06:28 -05001237 /* LVDS quirks */
1238 radeon_atom_apply_lvds_quirks(dev, lvds);
1239
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001240 encoder->native_mode = lvds->native_mode;
1241 }
1242 return lvds;
1243}
1244
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001245struct radeon_encoder_primary_dac *
1246radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1247{
1248 struct drm_device *dev = encoder->base.dev;
1249 struct radeon_device *rdev = dev->dev_private;
1250 struct radeon_mode_info *mode_info = &rdev->mode_info;
1251 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1252 uint16_t data_offset;
1253 struct _COMPASSIONATE_DATA *dac_info;
1254 uint8_t frev, crev;
1255 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001256 struct radeon_encoder_primary_dac *p_dac = NULL;
1257
1258 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1259
1260 dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
1261
1262 if (dac_info) {
1263 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1264
1265 if (!p_dac)
1266 return NULL;
1267
1268 bg = dac_info->ucDAC1_BG_Adjustment;
1269 dac = dac_info->ucDAC1_DAC_Adjustment;
1270 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1271
1272 }
1273 return p_dac;
1274}
1275
Dave Airlie4ce001a2009-08-13 16:32:14 +10001276bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001277 struct drm_display_mode *mode)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001278{
1279 struct radeon_mode_info *mode_info = &rdev->mode_info;
1280 ATOM_ANALOG_TV_INFO *tv_info;
1281 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1282 ATOM_DTD_FORMAT *dtd_timings;
1283 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1284 u8 frev, crev;
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001285 u16 data_offset, misc;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001286
1287 atom_parse_data_header(mode_info->atom_context, data_index, NULL, &frev, &crev, &data_offset);
1288
1289 switch (crev) {
1290 case 1:
1291 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1292 if (index > MAX_SUPPORTED_TV_TIMING)
1293 return false;
1294
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001295 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1296 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1297 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1298 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1299 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001300
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001301 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1302 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1303 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1304 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1305 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001306
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001307 mode->flags = 0;
1308 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1309 if (misc & ATOM_VSYNC_POLARITY)
1310 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1311 if (misc & ATOM_HSYNC_POLARITY)
1312 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1313 if (misc & ATOM_COMPOSITESYNC)
1314 mode->flags |= DRM_MODE_FLAG_CSYNC;
1315 if (misc & ATOM_INTERLACE)
1316 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1317 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1318 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001319
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001320 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001321
1322 if (index == 1) {
1323 /* PAL timings appear to have wrong values for totals */
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001324 mode->crtc_htotal -= 1;
1325 mode->crtc_vtotal -= 1;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001326 }
1327 break;
1328 case 2:
1329 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
1330 if (index > MAX_SUPPORTED_TV_TIMING_V1_2)
1331 return false;
1332
1333 dtd_timings = &tv_info_v1_2->aModeTimings[index];
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001334 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1335 le16_to_cpu(dtd_timings->usHBlanking_Time);
1336 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1337 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1338 le16_to_cpu(dtd_timings->usHSyncOffset);
1339 mode->crtc_hsync_end = mode->crtc_hsync_start +
1340 le16_to_cpu(dtd_timings->usHSyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001341
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001342 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1343 le16_to_cpu(dtd_timings->usVBlanking_Time);
1344 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1345 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1346 le16_to_cpu(dtd_timings->usVSyncOffset);
1347 mode->crtc_vsync_end = mode->crtc_vsync_start +
1348 le16_to_cpu(dtd_timings->usVSyncWidth);
1349
1350 mode->flags = 0;
1351 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1352 if (misc & ATOM_VSYNC_POLARITY)
1353 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1354 if (misc & ATOM_HSYNC_POLARITY)
1355 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1356 if (misc & ATOM_COMPOSITESYNC)
1357 mode->flags |= DRM_MODE_FLAG_CSYNC;
1358 if (misc & ATOM_INTERLACE)
1359 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1360 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1361 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1362
1363 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001364 break;
1365 }
1366 return true;
1367}
1368
Alex Deucherd79766f2009-12-17 19:00:29 -05001369enum radeon_tv_std
1370radeon_atombios_get_tv_info(struct radeon_device *rdev)
1371{
1372 struct radeon_mode_info *mode_info = &rdev->mode_info;
1373 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1374 uint16_t data_offset;
1375 uint8_t frev, crev;
1376 struct _ATOM_ANALOG_TV_INFO *tv_info;
1377 enum radeon_tv_std tv_std = TV_STD_NTSC;
1378
1379 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1380
1381 tv_info = (struct _ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
1382
1383 switch (tv_info->ucTV_BootUpDefaultStandard) {
1384 case ATOM_TV_NTSC:
1385 tv_std = TV_STD_NTSC;
1386 DRM_INFO("Default TV standard: NTSC\n");
1387 break;
1388 case ATOM_TV_NTSCJ:
1389 tv_std = TV_STD_NTSC_J;
1390 DRM_INFO("Default TV standard: NTSC-J\n");
1391 break;
1392 case ATOM_TV_PAL:
1393 tv_std = TV_STD_PAL;
1394 DRM_INFO("Default TV standard: PAL\n");
1395 break;
1396 case ATOM_TV_PALM:
1397 tv_std = TV_STD_PAL_M;
1398 DRM_INFO("Default TV standard: PAL-M\n");
1399 break;
1400 case ATOM_TV_PALN:
1401 tv_std = TV_STD_PAL_N;
1402 DRM_INFO("Default TV standard: PAL-N\n");
1403 break;
1404 case ATOM_TV_PALCN:
1405 tv_std = TV_STD_PAL_CN;
1406 DRM_INFO("Default TV standard: PAL-CN\n");
1407 break;
1408 case ATOM_TV_PAL60:
1409 tv_std = TV_STD_PAL_60;
1410 DRM_INFO("Default TV standard: PAL-60\n");
1411 break;
1412 case ATOM_TV_SECAM:
1413 tv_std = TV_STD_SECAM;
1414 DRM_INFO("Default TV standard: SECAM\n");
1415 break;
1416 default:
1417 tv_std = TV_STD_NTSC;
1418 DRM_INFO("Unknown TV standard; defaulting to NTSC\n");
1419 break;
1420 }
1421 return tv_std;
1422}
1423
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001424struct radeon_encoder_tv_dac *
1425radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1426{
1427 struct drm_device *dev = encoder->base.dev;
1428 struct radeon_device *rdev = dev->dev_private;
1429 struct radeon_mode_info *mode_info = &rdev->mode_info;
1430 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1431 uint16_t data_offset;
1432 struct _COMPASSIONATE_DATA *dac_info;
1433 uint8_t frev, crev;
1434 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001435 struct radeon_encoder_tv_dac *tv_dac = NULL;
1436
1437 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1438
1439 dac_info = (struct _COMPASSIONATE_DATA *)(mode_info->atom_context->bios + data_offset);
1440
1441 if (dac_info) {
1442 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1443
1444 if (!tv_dac)
1445 return NULL;
1446
1447 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1448 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1449 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1450
1451 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1452 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1453 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1454
1455 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1456 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1457 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1458
Alex Deucherd79766f2009-12-17 19:00:29 -05001459 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001460 }
1461 return tv_dac;
1462}
1463
Alex Deucher56278a82009-12-28 13:58:44 -05001464union power_info {
1465 struct _ATOM_POWERPLAY_INFO info;
1466 struct _ATOM_POWERPLAY_INFO_V2 info_2;
1467 struct _ATOM_POWERPLAY_INFO_V3 info_3;
1468 struct _ATOM_PPLIB_POWERPLAYTABLE info_4;
1469};
1470
1471void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1472{
1473 struct radeon_mode_info *mode_info = &rdev->mode_info;
1474 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
1475 u16 data_offset;
1476 u8 frev, crev;
1477 u32 misc, misc2 = 0, sclk, mclk;
1478 union power_info *power_info;
1479 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
1480 struct _ATOM_PPLIB_STATE *power_state;
1481 int num_modes = 0, i, j;
1482 int state_index = 0, mode_index = 0;
1483
1484 atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset);
1485
1486 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
1487
1488 rdev->pm.default_power_state = NULL;
Alex Deucher56278a82009-12-28 13:58:44 -05001489
1490 if (power_info) {
1491 if (frev < 4) {
1492 num_modes = power_info->info.ucNumOfPowerModeEntries;
1493 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
1494 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
1495 for (i = 0; i < num_modes; i++) {
1496 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
1497 switch (frev) {
1498 case 1:
1499 rdev->pm.power_state[state_index].num_clock_modes = 1;
1500 rdev->pm.power_state[state_index].clock_info[0].mclk =
1501 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
1502 rdev->pm.power_state[state_index].clock_info[0].sclk =
1503 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
1504 /* skip invalid modes */
1505 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1506 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1507 continue;
1508 /* skip overclock modes for now */
1509 if ((rdev->pm.power_state[state_index].clock_info[0].mclk >
Rafał Miłecki27459322010-02-11 22:16:36 +00001510 rdev->clock.default_mclk + RADEON_MODE_OVERCLOCK_MARGIN) ||
Alex Deucher56278a82009-12-28 13:58:44 -05001511 (rdev->pm.power_state[state_index].clock_info[0].sclk >
Rafał Miłecki27459322010-02-11 22:16:36 +00001512 rdev->clock.default_sclk + RADEON_MODE_OVERCLOCK_MARGIN))
Alex Deucher56278a82009-12-28 13:58:44 -05001513 continue;
1514 rdev->pm.power_state[state_index].non_clock_info.pcie_lanes =
1515 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
1516 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
1517 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) {
1518 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1519 VOLTAGE_GPIO;
1520 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1521 radeon_lookup_gpio(rdev,
1522 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
1523 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1524 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1525 true;
1526 else
1527 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1528 false;
1529 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1530 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1531 VOLTAGE_VDDC;
1532 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1533 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
1534 }
Alex Deucher0ec0e742009-12-23 13:21:58 -05001535 /* order matters! */
1536 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1537 rdev->pm.power_state[state_index].type =
1538 POWER_STATE_TYPE_POWERSAVE;
1539 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1540 rdev->pm.power_state[state_index].type =
1541 POWER_STATE_TYPE_BATTERY;
1542 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1543 rdev->pm.power_state[state_index].type =
1544 POWER_STATE_TYPE_BATTERY;
1545 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1546 rdev->pm.power_state[state_index].type =
1547 POWER_STATE_TYPE_BALANCED;
1548 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN)
1549 rdev->pm.power_state[state_index].type =
1550 POWER_STATE_TYPE_PERFORMANCE;
Alex Deucher56278a82009-12-28 13:58:44 -05001551 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001552 rdev->pm.power_state[state_index].type =
1553 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05001554 rdev->pm.default_power_state = &rdev->pm.power_state[state_index];
Alex Deucher56278a82009-12-28 13:58:44 -05001555 rdev->pm.power_state[state_index].default_clock_mode =
1556 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucher56278a82009-12-28 13:58:44 -05001557 }
1558 state_index++;
1559 break;
1560 case 2:
1561 rdev->pm.power_state[state_index].num_clock_modes = 1;
1562 rdev->pm.power_state[state_index].clock_info[0].mclk =
1563 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
1564 rdev->pm.power_state[state_index].clock_info[0].sclk =
1565 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
1566 /* skip invalid modes */
1567 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1568 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1569 continue;
1570 /* skip overclock modes for now */
1571 if ((rdev->pm.power_state[state_index].clock_info[0].mclk >
Rafał Miłecki27459322010-02-11 22:16:36 +00001572 rdev->clock.default_mclk + RADEON_MODE_OVERCLOCK_MARGIN) ||
Alex Deucher56278a82009-12-28 13:58:44 -05001573 (rdev->pm.power_state[state_index].clock_info[0].sclk >
Rafał Miłecki27459322010-02-11 22:16:36 +00001574 rdev->clock.default_sclk + RADEON_MODE_OVERCLOCK_MARGIN))
Alex Deucher56278a82009-12-28 13:58:44 -05001575 continue;
1576 rdev->pm.power_state[state_index].non_clock_info.pcie_lanes =
1577 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
1578 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
1579 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
1580 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) {
1581 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1582 VOLTAGE_GPIO;
1583 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1584 radeon_lookup_gpio(rdev,
1585 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
1586 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1587 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1588 true;
1589 else
1590 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1591 false;
1592 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1593 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1594 VOLTAGE_VDDC;
1595 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1596 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
1597 }
Alex Deucher0ec0e742009-12-23 13:21:58 -05001598 /* order matters! */
1599 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1600 rdev->pm.power_state[state_index].type =
1601 POWER_STATE_TYPE_POWERSAVE;
1602 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1603 rdev->pm.power_state[state_index].type =
1604 POWER_STATE_TYPE_BATTERY;
1605 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1606 rdev->pm.power_state[state_index].type =
1607 POWER_STATE_TYPE_BATTERY;
1608 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1609 rdev->pm.power_state[state_index].type =
1610 POWER_STATE_TYPE_BALANCED;
1611 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN)
1612 rdev->pm.power_state[state_index].type =
1613 POWER_STATE_TYPE_PERFORMANCE;
1614 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1615 rdev->pm.power_state[state_index].type =
1616 POWER_STATE_TYPE_BALANCED;
Alex Deucher56278a82009-12-28 13:58:44 -05001617 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001618 rdev->pm.power_state[state_index].type =
1619 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05001620 rdev->pm.default_power_state = &rdev->pm.power_state[state_index];
Alex Deucher56278a82009-12-28 13:58:44 -05001621 rdev->pm.power_state[state_index].default_clock_mode =
1622 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucher56278a82009-12-28 13:58:44 -05001623 }
1624 state_index++;
1625 break;
1626 case 3:
1627 rdev->pm.power_state[state_index].num_clock_modes = 1;
1628 rdev->pm.power_state[state_index].clock_info[0].mclk =
1629 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
1630 rdev->pm.power_state[state_index].clock_info[0].sclk =
1631 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
1632 /* skip invalid modes */
1633 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1634 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1635 continue;
1636 /* skip overclock modes for now */
1637 if ((rdev->pm.power_state[state_index].clock_info[0].mclk >
Rafał Miłecki27459322010-02-11 22:16:36 +00001638 rdev->clock.default_mclk + RADEON_MODE_OVERCLOCK_MARGIN) ||
Alex Deucher56278a82009-12-28 13:58:44 -05001639 (rdev->pm.power_state[state_index].clock_info[0].sclk >
Rafał Miłecki27459322010-02-11 22:16:36 +00001640 rdev->clock.default_sclk + RADEON_MODE_OVERCLOCK_MARGIN))
Alex Deucher56278a82009-12-28 13:58:44 -05001641 continue;
1642 rdev->pm.power_state[state_index].non_clock_info.pcie_lanes =
1643 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
1644 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
1645 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
1646 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) {
1647 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1648 VOLTAGE_GPIO;
1649 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1650 radeon_lookup_gpio(rdev,
1651 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
1652 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1653 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1654 true;
1655 else
1656 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1657 false;
1658 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1659 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1660 VOLTAGE_VDDC;
1661 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1662 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
1663 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
1664 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
1665 true;
1666 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
1667 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
1668 }
1669 }
Alex Deucher0ec0e742009-12-23 13:21:58 -05001670 /* order matters! */
1671 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1672 rdev->pm.power_state[state_index].type =
1673 POWER_STATE_TYPE_POWERSAVE;
1674 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1675 rdev->pm.power_state[state_index].type =
1676 POWER_STATE_TYPE_BATTERY;
1677 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1678 rdev->pm.power_state[state_index].type =
1679 POWER_STATE_TYPE_BATTERY;
1680 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1681 rdev->pm.power_state[state_index].type =
1682 POWER_STATE_TYPE_BALANCED;
1683 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN)
1684 rdev->pm.power_state[state_index].type =
1685 POWER_STATE_TYPE_PERFORMANCE;
1686 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1687 rdev->pm.power_state[state_index].type =
1688 POWER_STATE_TYPE_BALANCED;
Alex Deucher56278a82009-12-28 13:58:44 -05001689 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001690 rdev->pm.power_state[state_index].type =
1691 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05001692 rdev->pm.default_power_state = &rdev->pm.power_state[state_index];
Alex Deucher56278a82009-12-28 13:58:44 -05001693 rdev->pm.power_state[state_index].default_clock_mode =
1694 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucher56278a82009-12-28 13:58:44 -05001695 }
1696 state_index++;
1697 break;
1698 }
1699 }
1700 } else if (frev == 4) {
1701 for (i = 0; i < power_info->info_4.ucNumStates; i++) {
1702 mode_index = 0;
1703 power_state = (struct _ATOM_PPLIB_STATE *)
1704 (mode_info->atom_context->bios +
1705 data_offset +
1706 le16_to_cpu(power_info->info_4.usStateArrayOffset) +
1707 i * power_info->info_4.ucStateEntrySize);
1708 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
1709 (mode_info->atom_context->bios +
1710 data_offset +
1711 le16_to_cpu(power_info->info_4.usNonClockInfoArrayOffset) +
1712 (power_state->ucNonClockStateIndex *
1713 power_info->info_4.ucNonClockSize));
Alex Deucher56278a82009-12-28 13:58:44 -05001714 for (j = 0; j < (power_info->info_4.ucStateEntrySize - 1); j++) {
1715 if (rdev->flags & RADEON_IS_IGP) {
1716 struct _ATOM_PPLIB_RS780_CLOCK_INFO *clock_info =
1717 (struct _ATOM_PPLIB_RS780_CLOCK_INFO *)
1718 (mode_info->atom_context->bios +
1719 data_offset +
1720 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
1721 (power_state->ucClockStateIndices[j] *
1722 power_info->info_4.ucClockInfoSize));
1723 sclk = le16_to_cpu(clock_info->usLowEngineClockLow);
1724 sclk |= clock_info->ucLowEngineClockHigh << 16;
1725 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
1726 /* skip invalid modes */
1727 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
1728 continue;
1729 /* skip overclock modes for now */
1730 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk >
Rafał Miłecki27459322010-02-11 22:16:36 +00001731 rdev->clock.default_sclk + RADEON_MODE_OVERCLOCK_MARGIN)
Alex Deucher56278a82009-12-28 13:58:44 -05001732 continue;
1733 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
1734 VOLTAGE_SW;
1735 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
1736 clock_info->usVDDC;
1737 mode_index++;
1738 } else {
1739 struct _ATOM_PPLIB_R600_CLOCK_INFO *clock_info =
1740 (struct _ATOM_PPLIB_R600_CLOCK_INFO *)
1741 (mode_info->atom_context->bios +
1742 data_offset +
1743 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
1744 (power_state->ucClockStateIndices[j] *
1745 power_info->info_4.ucClockInfoSize));
1746 sclk = le16_to_cpu(clock_info->usEngineClockLow);
1747 sclk |= clock_info->ucEngineClockHigh << 16;
1748 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
1749 mclk |= clock_info->ucMemoryClockHigh << 16;
1750 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
1751 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
1752 /* skip invalid modes */
1753 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
1754 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
1755 continue;
1756 /* skip overclock modes for now */
1757 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk >
Rafał Miłecki27459322010-02-11 22:16:36 +00001758 rdev->clock.default_mclk + RADEON_MODE_OVERCLOCK_MARGIN) ||
Alex Deucher56278a82009-12-28 13:58:44 -05001759 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk >
Rafał Miłecki27459322010-02-11 22:16:36 +00001760 rdev->clock.default_sclk + RADEON_MODE_OVERCLOCK_MARGIN))
Alex Deucher56278a82009-12-28 13:58:44 -05001761 continue;
1762 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
1763 VOLTAGE_SW;
1764 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
1765 clock_info->usVDDC;
1766 mode_index++;
1767 }
1768 }
1769 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
1770 if (mode_index) {
Rafał Miłecki845db702009-12-23 00:42:43 +01001771 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
Alex Deucher56278a82009-12-28 13:58:44 -05001772 misc2 = le16_to_cpu(non_clock_info->usClassification);
Rafał Miłecki845db702009-12-23 00:42:43 +01001773 rdev->pm.power_state[state_index].non_clock_info.pcie_lanes =
1774 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
1775 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
Alex Deucher0ec0e742009-12-23 13:21:58 -05001776 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
1777 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
1778 rdev->pm.power_state[state_index].type =
1779 POWER_STATE_TYPE_BATTERY;
1780 break;
1781 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
1782 rdev->pm.power_state[state_index].type =
1783 POWER_STATE_TYPE_BALANCED;
1784 break;
1785 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
1786 rdev->pm.power_state[state_index].type =
1787 POWER_STATE_TYPE_PERFORMANCE;
1788 break;
1789 }
Alex Deucher56278a82009-12-28 13:58:44 -05001790 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001791 rdev->pm.power_state[state_index].type =
1792 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05001793 rdev->pm.default_power_state = &rdev->pm.power_state[state_index];
Alex Deucher56278a82009-12-28 13:58:44 -05001794 rdev->pm.power_state[state_index].default_clock_mode =
1795 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
Alex Deucher56278a82009-12-28 13:58:44 -05001796 }
1797 state_index++;
1798 }
1799 }
1800 }
1801 } else {
1802 /* XXX figure out some good default low power mode for cards w/out power tables */
1803 }
1804
1805 if (rdev->pm.default_power_state == NULL) {
1806 /* add the default mode */
Alex Deucher0ec0e742009-12-23 13:21:58 -05001807 rdev->pm.power_state[state_index].type =
1808 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05001809 rdev->pm.power_state[state_index].num_clock_modes = 1;
1810 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
1811 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
1812 rdev->pm.power_state[state_index].default_clock_mode =
1813 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucher56278a82009-12-28 13:58:44 -05001814 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
1815 if (rdev->asic->get_pcie_lanes)
1816 rdev->pm.power_state[state_index].non_clock_info.pcie_lanes = radeon_get_pcie_lanes(rdev);
1817 else
1818 rdev->pm.power_state[state_index].non_clock_info.pcie_lanes = 16;
1819 rdev->pm.default_power_state = &rdev->pm.power_state[state_index];
Alex Deucher56278a82009-12-28 13:58:44 -05001820 state_index++;
1821 }
1822 rdev->pm.num_power_states = state_index;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00001823
1824 rdev->pm.current_power_state = rdev->pm.default_power_state;
1825 rdev->pm.current_clock_mode =
1826 rdev->pm.default_power_state->default_clock_mode;
Alex Deucher56278a82009-12-28 13:58:44 -05001827}
1828
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001829void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
1830{
1831 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
1832 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
1833
1834 args.ucEnable = enable;
1835
1836 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1837}
1838
Rafał Miłecki74338742009-11-03 00:53:02 +01001839uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
1840{
1841 GET_ENGINE_CLOCK_PS_ALLOCATION args;
1842 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
1843
1844 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1845 return args.ulReturnEngineClock;
1846}
1847
1848uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
1849{
1850 GET_MEMORY_CLOCK_PS_ALLOCATION args;
1851 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
1852
1853 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1854 return args.ulReturnMemoryClock;
1855}
1856
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001857void radeon_atom_set_engine_clock(struct radeon_device *rdev,
1858 uint32_t eng_clock)
1859{
1860 SET_ENGINE_CLOCK_PS_ALLOCATION args;
1861 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
1862
1863 args.ulTargetEngineClock = eng_clock; /* 10 khz */
1864
1865 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1866}
1867
1868void radeon_atom_set_memory_clock(struct radeon_device *rdev,
1869 uint32_t mem_clock)
1870{
1871 SET_MEMORY_CLOCK_PS_ALLOCATION args;
1872 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
1873
1874 if (rdev->flags & RADEON_IS_IGP)
1875 return;
1876
1877 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
1878
1879 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1880}
1881
1882void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
1883{
1884 struct radeon_device *rdev = dev->dev_private;
1885 uint32_t bios_2_scratch, bios_6_scratch;
1886
1887 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001888 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001889 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1890 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001891 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001892 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1893 }
1894
1895 /* let the bios control the backlight */
1896 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
1897
1898 /* tell the bios not to handle mode switching */
1899 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
1900
1901 if (rdev->family >= CHIP_R600) {
1902 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
1903 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1904 } else {
1905 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
1906 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1907 }
1908
1909}
1910
Yang Zhaof657c2a2009-09-15 12:21:01 +10001911void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
1912{
1913 uint32_t scratch_reg;
1914 int i;
1915
1916 if (rdev->family >= CHIP_R600)
1917 scratch_reg = R600_BIOS_0_SCRATCH;
1918 else
1919 scratch_reg = RADEON_BIOS_0_SCRATCH;
1920
1921 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
1922 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
1923}
1924
1925void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
1926{
1927 uint32_t scratch_reg;
1928 int i;
1929
1930 if (rdev->family >= CHIP_R600)
1931 scratch_reg = R600_BIOS_0_SCRATCH;
1932 else
1933 scratch_reg = RADEON_BIOS_0_SCRATCH;
1934
1935 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
1936 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
1937}
1938
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001939void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
1940{
1941 struct drm_device *dev = encoder->dev;
1942 struct radeon_device *rdev = dev->dev_private;
1943 uint32_t bios_6_scratch;
1944
1945 if (rdev->family >= CHIP_R600)
1946 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1947 else
1948 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1949
1950 if (lock)
1951 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
1952 else
1953 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
1954
1955 if (rdev->family >= CHIP_R600)
1956 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
1957 else
1958 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1959}
1960
1961/* at some point we may want to break this out into individual functions */
1962void
1963radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
1964 struct drm_encoder *encoder,
1965 bool connected)
1966{
1967 struct drm_device *dev = connector->dev;
1968 struct radeon_device *rdev = dev->dev_private;
1969 struct radeon_connector *radeon_connector =
1970 to_radeon_connector(connector);
1971 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1972 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
1973
1974 if (rdev->family >= CHIP_R600) {
1975 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
1976 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
1977 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
1978 } else {
1979 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
1980 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
1981 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
1982 }
1983
1984 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
1985 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
1986 if (connected) {
1987 DRM_DEBUG("TV1 connected\n");
1988 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
1989 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
1990 } else {
1991 DRM_DEBUG("TV1 disconnected\n");
1992 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
1993 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
1994 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
1995 }
1996 }
1997 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
1998 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
1999 if (connected) {
2000 DRM_DEBUG("CV connected\n");
2001 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
2002 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
2003 } else {
2004 DRM_DEBUG("CV disconnected\n");
2005 bios_0_scratch &= ~ATOM_S0_CV_MASK;
2006 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
2007 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
2008 }
2009 }
2010 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
2011 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
2012 if (connected) {
2013 DRM_DEBUG("LCD1 connected\n");
2014 bios_0_scratch |= ATOM_S0_LCD1;
2015 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
2016 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
2017 } else {
2018 DRM_DEBUG("LCD1 disconnected\n");
2019 bios_0_scratch &= ~ATOM_S0_LCD1;
2020 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
2021 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
2022 }
2023 }
2024 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
2025 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
2026 if (connected) {
2027 DRM_DEBUG("CRT1 connected\n");
2028 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
2029 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
2030 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
2031 } else {
2032 DRM_DEBUG("CRT1 disconnected\n");
2033 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
2034 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
2035 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
2036 }
2037 }
2038 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
2039 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
2040 if (connected) {
2041 DRM_DEBUG("CRT2 connected\n");
2042 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
2043 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
2044 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
2045 } else {
2046 DRM_DEBUG("CRT2 disconnected\n");
2047 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
2048 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
2049 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
2050 }
2051 }
2052 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
2053 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
2054 if (connected) {
2055 DRM_DEBUG("DFP1 connected\n");
2056 bios_0_scratch |= ATOM_S0_DFP1;
2057 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
2058 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
2059 } else {
2060 DRM_DEBUG("DFP1 disconnected\n");
2061 bios_0_scratch &= ~ATOM_S0_DFP1;
2062 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
2063 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
2064 }
2065 }
2066 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
2067 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
2068 if (connected) {
2069 DRM_DEBUG("DFP2 connected\n");
2070 bios_0_scratch |= ATOM_S0_DFP2;
2071 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
2072 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
2073 } else {
2074 DRM_DEBUG("DFP2 disconnected\n");
2075 bios_0_scratch &= ~ATOM_S0_DFP2;
2076 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
2077 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
2078 }
2079 }
2080 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
2081 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
2082 if (connected) {
2083 DRM_DEBUG("DFP3 connected\n");
2084 bios_0_scratch |= ATOM_S0_DFP3;
2085 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
2086 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
2087 } else {
2088 DRM_DEBUG("DFP3 disconnected\n");
2089 bios_0_scratch &= ~ATOM_S0_DFP3;
2090 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
2091 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
2092 }
2093 }
2094 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
2095 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
2096 if (connected) {
2097 DRM_DEBUG("DFP4 connected\n");
2098 bios_0_scratch |= ATOM_S0_DFP4;
2099 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
2100 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
2101 } else {
2102 DRM_DEBUG("DFP4 disconnected\n");
2103 bios_0_scratch &= ~ATOM_S0_DFP4;
2104 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
2105 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
2106 }
2107 }
2108 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
2109 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
2110 if (connected) {
2111 DRM_DEBUG("DFP5 connected\n");
2112 bios_0_scratch |= ATOM_S0_DFP5;
2113 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
2114 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
2115 } else {
2116 DRM_DEBUG("DFP5 disconnected\n");
2117 bios_0_scratch &= ~ATOM_S0_DFP5;
2118 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2119 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2120 }
2121 }
2122
2123 if (rdev->family >= CHIP_R600) {
2124 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2125 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2126 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2127 } else {
2128 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
2129 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2130 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2131 }
2132}
2133
2134void
2135radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
2136{
2137 struct drm_device *dev = encoder->dev;
2138 struct radeon_device *rdev = dev->dev_private;
2139 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2140 uint32_t bios_3_scratch;
2141
2142 if (rdev->family >= CHIP_R600)
2143 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2144 else
2145 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2146
2147 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2148 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
2149 bios_3_scratch |= (crtc << 18);
2150 }
2151 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2152 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
2153 bios_3_scratch |= (crtc << 24);
2154 }
2155 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2156 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
2157 bios_3_scratch |= (crtc << 16);
2158 }
2159 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2160 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
2161 bios_3_scratch |= (crtc << 20);
2162 }
2163 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2164 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
2165 bios_3_scratch |= (crtc << 17);
2166 }
2167 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2168 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
2169 bios_3_scratch |= (crtc << 19);
2170 }
2171 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2172 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
2173 bios_3_scratch |= (crtc << 23);
2174 }
2175 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2176 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
2177 bios_3_scratch |= (crtc << 25);
2178 }
2179
2180 if (rdev->family >= CHIP_R600)
2181 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2182 else
2183 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2184}
2185
2186void
2187radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
2188{
2189 struct drm_device *dev = encoder->dev;
2190 struct radeon_device *rdev = dev->dev_private;
2191 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2192 uint32_t bios_2_scratch;
2193
2194 if (rdev->family >= CHIP_R600)
2195 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2196 else
2197 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
2198
2199 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2200 if (on)
2201 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
2202 else
2203 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
2204 }
2205 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2206 if (on)
2207 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
2208 else
2209 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
2210 }
2211 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2212 if (on)
2213 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
2214 else
2215 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
2216 }
2217 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2218 if (on)
2219 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
2220 else
2221 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
2222 }
2223 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2224 if (on)
2225 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
2226 else
2227 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
2228 }
2229 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2230 if (on)
2231 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
2232 else
2233 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
2234 }
2235 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2236 if (on)
2237 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
2238 else
2239 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
2240 }
2241 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2242 if (on)
2243 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
2244 else
2245 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
2246 }
2247 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
2248 if (on)
2249 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
2250 else
2251 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
2252 }
2253 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
2254 if (on)
2255 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
2256 else
2257 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
2258 }
2259
2260 if (rdev->family >= CHIP_R600)
2261 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2262 else
2263 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2264}