blob: 45bc750e9ae21c76e6e3b5da1797a0229f2dbcc0 [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
Alex Deucher5137ee92010-08-12 18:58:47 -040035radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
36 uint8_t dac);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020037extern void radeon_link_encoder_connector(struct drm_device *dev);
38extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040039radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
Jerome Glisse771fe6b2009-06-05 14:42:42 +020040 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 Deucher5137ee92010-08-12 18:58:47 -040049 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -050050 uint16_t connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -040051 struct radeon_hpd *hpd,
52 struct radeon_router *router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020053
54/* from radeon_legacy_encoder.c */
55extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040056radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
Jerome Glisse771fe6b2009-06-05 14:42:42 +020057 uint32_t supported_device);
58
59union atom_supported_devices {
60 struct _ATOM_SUPPORTED_DEVICES_INFO info;
61 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
62 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
63};
64
Alex Deuchereed45b32009-12-04 14:45:27 -050065static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
66 uint8_t id)
Jerome Glisse771fe6b2009-06-05 14:42:42 +020067{
Jerome Glisse771fe6b2009-06-05 14:42:42 +020068 struct atom_context *ctx = rdev->mode_info.atom_context;
Alex Deucher6a93cb22009-11-23 17:39:28 -050069 ATOM_GPIO_I2C_ASSIGMENT *gpio;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020070 struct radeon_i2c_bus_rec i2c;
71 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
72 struct _ATOM_GPIO_I2C_INFO *i2c_info;
Alex Deucher95beb692010-04-01 19:08:47 +000073 uint16_t data_offset, size;
74 int i, num_indices;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020075
76 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
77 i2c.valid = false;
78
Alex Deucher95beb692010-04-01 19:08:47 +000079 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
Alex Deuchera084e6e2010-03-18 01:04:01 -040080 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020081
Alex Deucher95beb692010-04-01 19:08:47 +000082 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
83 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
84
85 for (i = 0; i < num_indices; i++) {
Alex Deuchera084e6e2010-03-18 01:04:01 -040086 gpio = &i2c_info->asGPIO_Info[i];
Jerome Glisse771fe6b2009-06-05 14:42:42 +020087
Alex Deucherea393022010-08-27 16:04:29 -040088 /* some evergreen boards have bad data for this entry */
89 if (ASIC_IS_DCE4(rdev)) {
90 if ((i == 7) &&
91 (gpio->usClkMaskRegisterIndex == 0x1936) &&
92 (gpio->sucI2cId.ucAccess == 0)) {
93 gpio->sucI2cId.ucAccess = 0x97;
94 gpio->ucDataMaskShift = 8;
95 gpio->ucDataEnShift = 8;
96 gpio->ucDataY_Shift = 8;
97 gpio->ucDataA_Shift = 8;
98 }
99 }
100
Alex Deucher3074adc2010-11-30 00:15:10 -0500101 /* some DCE3 boards have bad data for this entry */
102 if (ASIC_IS_DCE3(rdev)) {
103 if ((i == 4) &&
104 (gpio->usClkMaskRegisterIndex == 0x1fda) &&
105 (gpio->sucI2cId.ucAccess == 0x94))
106 gpio->sucI2cId.ucAccess = 0x14;
107 }
108
Alex Deuchera084e6e2010-03-18 01:04:01 -0400109 if (gpio->sucI2cId.ucAccess == id) {
110 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
111 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
112 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
113 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
114 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
115 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
116 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
117 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
118 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
119 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
120 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
121 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
122 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
123 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
124 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
125 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200126
Alex Deuchera084e6e2010-03-18 01:04:01 -0400127 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
128 i2c.hw_capable = true;
129 else
130 i2c.hw_capable = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500131
Alex Deuchera084e6e2010-03-18 01:04:01 -0400132 if (gpio->sucI2cId.ucAccess == 0xa0)
133 i2c.mm_i2c = true;
134 else
135 i2c.mm_i2c = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500136
Alex Deuchera084e6e2010-03-18 01:04:01 -0400137 i2c.i2c_id = gpio->sucI2cId.ucAccess;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500138
Alex Deucherf376b942010-08-05 21:21:16 -0400139 if (i2c.mask_clk_reg)
140 i2c.valid = true;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400141 break;
142 }
Alex Deucherd3f420d2009-12-08 14:30:49 -0500143 }
144 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200145
146 return i2c;
147}
148
Alex Deucherf376b942010-08-05 21:21:16 -0400149void radeon_atombios_i2c_init(struct radeon_device *rdev)
150{
151 struct atom_context *ctx = rdev->mode_info.atom_context;
152 ATOM_GPIO_I2C_ASSIGMENT *gpio;
153 struct radeon_i2c_bus_rec i2c;
154 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
155 struct _ATOM_GPIO_I2C_INFO *i2c_info;
156 uint16_t data_offset, size;
157 int i, num_indices;
158 char stmp[32];
159
160 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
161
162 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
163 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
164
165 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
166 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
167
168 for (i = 0; i < num_indices; i++) {
169 gpio = &i2c_info->asGPIO_Info[i];
170 i2c.valid = false;
Alex Deucherea393022010-08-27 16:04:29 -0400171
172 /* some evergreen boards have bad data for this entry */
173 if (ASIC_IS_DCE4(rdev)) {
174 if ((i == 7) &&
175 (gpio->usClkMaskRegisterIndex == 0x1936) &&
176 (gpio->sucI2cId.ucAccess == 0)) {
177 gpio->sucI2cId.ucAccess = 0x97;
178 gpio->ucDataMaskShift = 8;
179 gpio->ucDataEnShift = 8;
180 gpio->ucDataY_Shift = 8;
181 gpio->ucDataA_Shift = 8;
182 }
183 }
184
Alex Deucher3074adc2010-11-30 00:15:10 -0500185 /* some DCE3 boards have bad data for this entry */
186 if (ASIC_IS_DCE3(rdev)) {
187 if ((i == 4) &&
188 (gpio->usClkMaskRegisterIndex == 0x1fda) &&
189 (gpio->sucI2cId.ucAccess == 0x94))
190 gpio->sucI2cId.ucAccess = 0x14;
191 }
192
Alex Deucherf376b942010-08-05 21:21:16 -0400193 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
194 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
195 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
196 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
197 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
198 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
199 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
200 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
201 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
202 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
203 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
204 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
205 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
206 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
207 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
208 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
209
210 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
211 i2c.hw_capable = true;
212 else
213 i2c.hw_capable = false;
214
215 if (gpio->sucI2cId.ucAccess == 0xa0)
216 i2c.mm_i2c = true;
217 else
218 i2c.mm_i2c = false;
219
220 i2c.i2c_id = gpio->sucI2cId.ucAccess;
221
222 if (i2c.mask_clk_reg) {
223 i2c.valid = true;
224 sprintf(stmp, "0x%x", i2c.i2c_id);
225 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
226 }
227 }
228 }
229}
230
Alex Deuchereed45b32009-12-04 14:45:27 -0500231static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
232 u8 id)
233{
234 struct atom_context *ctx = rdev->mode_info.atom_context;
235 struct radeon_gpio_rec gpio;
236 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
237 struct _ATOM_GPIO_PIN_LUT *gpio_info;
238 ATOM_GPIO_PIN_ASSIGNMENT *pin;
239 u16 data_offset, size;
240 int i, num_indices;
241
242 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
243 gpio.valid = false;
244
Alex Deuchera084e6e2010-03-18 01:04:01 -0400245 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
246 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
Alex Deuchereed45b32009-12-04 14:45:27 -0500247
Alex Deuchera084e6e2010-03-18 01:04:01 -0400248 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
249 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
Alex Deuchereed45b32009-12-04 14:45:27 -0500250
Alex Deuchera084e6e2010-03-18 01:04:01 -0400251 for (i = 0; i < num_indices; i++) {
252 pin = &gpio_info->asGPIO_Pin[i];
253 if (id == pin->ucGPIO_ID) {
254 gpio.id = pin->ucGPIO_ID;
255 gpio.reg = pin->usGpioPin_AIndex * 4;
256 gpio.mask = (1 << pin->ucGpioPinBitShift);
257 gpio.valid = true;
258 break;
259 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500260 }
261 }
262
263 return gpio;
264}
265
266static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
267 struct radeon_gpio_rec *gpio)
268{
269 struct radeon_hpd hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500270 u32 reg;
271
Jean Delvare1d978dac2010-08-15 14:11:24 +0200272 memset(&hpd, 0, sizeof(struct radeon_hpd));
273
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500274 if (ASIC_IS_DCE4(rdev))
275 reg = EVERGREEN_DC_GPIO_HPD_A;
276 else
277 reg = AVIVO_DC_GPIO_HPD_A;
278
Alex Deuchereed45b32009-12-04 14:45:27 -0500279 hpd.gpio = *gpio;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500280 if (gpio->reg == reg) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500281 switch(gpio->mask) {
282 case (1 << 0):
283 hpd.hpd = RADEON_HPD_1;
284 break;
285 case (1 << 8):
286 hpd.hpd = RADEON_HPD_2;
287 break;
288 case (1 << 16):
289 hpd.hpd = RADEON_HPD_3;
290 break;
291 case (1 << 24):
292 hpd.hpd = RADEON_HPD_4;
293 break;
294 case (1 << 26):
295 hpd.hpd = RADEON_HPD_5;
296 break;
297 case (1 << 28):
298 hpd.hpd = RADEON_HPD_6;
299 break;
300 default:
301 hpd.hpd = RADEON_HPD_NONE;
302 break;
303 }
304 } else
305 hpd.hpd = RADEON_HPD_NONE;
306 return hpd;
307}
308
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200309static bool radeon_atom_apply_quirks(struct drm_device *dev,
310 uint32_t supported_device,
311 int *connector_type,
Alex Deucher848577e2009-07-08 16:15:30 -0400312 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -0500313 uint16_t *line_mux,
314 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200315{
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400316 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200317
318 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
319 if ((dev->pdev->device == 0x791e) &&
320 (dev->pdev->subsystem_vendor == 0x1043) &&
321 (dev->pdev->subsystem_device == 0x826d)) {
322 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
323 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
324 *connector_type = DRM_MODE_CONNECTOR_DVID;
325 }
326
Alex Deucherc86a9032010-02-18 14:14:58 -0500327 /* Asrock RS600 board lists the DVI port as HDMI */
328 if ((dev->pdev->device == 0x7941) &&
329 (dev->pdev->subsystem_vendor == 0x1849) &&
330 (dev->pdev->subsystem_device == 0x7941)) {
331 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
332 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
333 *connector_type = DRM_MODE_CONNECTOR_DVID;
334 }
335
Alex Deucherf36fce02010-09-27 11:33:00 -0400336 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
337 if ((dev->pdev->device == 0x796e) &&
338 (dev->pdev->subsystem_vendor == 0x1462) &&
339 (dev->pdev->subsystem_device == 0x7302)) {
340 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
341 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
342 return false;
343 }
344
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200345 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
346 if ((dev->pdev->device == 0x7941) &&
347 (dev->pdev->subsystem_vendor == 0x147b) &&
348 (dev->pdev->subsystem_device == 0x2412)) {
349 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
350 return false;
351 }
352
353 /* Falcon NW laptop lists vga ddc line for LVDS */
354 if ((dev->pdev->device == 0x5653) &&
355 (dev->pdev->subsystem_vendor == 0x1462) &&
356 (dev->pdev->subsystem_device == 0x0291)) {
Alex Deucher848577e2009-07-08 16:15:30 -0400357 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200358 i2c_bus->valid = false;
Alex Deucher848577e2009-07-08 16:15:30 -0400359 *line_mux = 53;
360 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200361 }
362
Alex Deucher4e3f9b72009-12-01 14:49:50 -0500363 /* HIS X1300 is DVI+VGA, not DVI+DVI */
364 if ((dev->pdev->device == 0x7146) &&
365 (dev->pdev->subsystem_vendor == 0x17af) &&
366 (dev->pdev->subsystem_device == 0x2058)) {
367 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
368 return false;
369 }
370
Dave Airlieaa1a7502009-12-04 11:51:34 +1000371 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
372 if ((dev->pdev->device == 0x7142) &&
373 (dev->pdev->subsystem_vendor == 0x1458) &&
374 (dev->pdev->subsystem_device == 0x2134)) {
375 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
376 return false;
377 }
378
379
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200380 /* Funky macbooks */
381 if ((dev->pdev->device == 0x71C5) &&
382 (dev->pdev->subsystem_vendor == 0x106b) &&
383 (dev->pdev->subsystem_device == 0x0080)) {
384 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
385 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
386 return false;
Alex Deuchere1e8a5d2010-03-26 17:14:37 -0400387 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
388 *line_mux = 0x90;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200389 }
390
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200391 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
392 if ((dev->pdev->device == 0x9598) &&
393 (dev->pdev->subsystem_vendor == 0x1043) &&
394 (dev->pdev->subsystem_device == 0x01da)) {
Alex Deucher705af9c2009-09-10 16:31:13 -0400395 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400396 *connector_type = DRM_MODE_CONNECTOR_DVII;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200397 }
398 }
399
Alex Deuchere153b702010-07-20 18:07:22 -0400400 /* ASUS HD 3600 board lists the DVI port as HDMI */
401 if ((dev->pdev->device == 0x9598) &&
402 (dev->pdev->subsystem_vendor == 0x1043) &&
403 (dev->pdev->subsystem_device == 0x01e4)) {
404 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
405 *connector_type = DRM_MODE_CONNECTOR_DVII;
406 }
407 }
408
Alex Deucher705af9c2009-09-10 16:31:13 -0400409 /* ASUS HD 3450 board lists the DVI port as HDMI */
410 if ((dev->pdev->device == 0x95C5) &&
411 (dev->pdev->subsystem_vendor == 0x1043) &&
412 (dev->pdev->subsystem_device == 0x01e2)) {
413 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400414 *connector_type = DRM_MODE_CONNECTOR_DVII;
Alex Deucher705af9c2009-09-10 16:31:13 -0400415 }
416 }
417
418 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
419 * HDMI + VGA reporting as HDMI
420 */
421 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
422 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
423 *connector_type = DRM_MODE_CONNECTOR_VGA;
424 *line_mux = 0;
425 }
426 }
427
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400428 /* Acer laptop reports DVI-D as DVI-I and hpd pins reversed */
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500429 if ((dev->pdev->device == 0x95c4) &&
430 (dev->pdev->subsystem_vendor == 0x1025) &&
431 (dev->pdev->subsystem_device == 0x013c)) {
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400432 struct radeon_gpio_rec gpio;
433
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500434 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400435 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
436 gpio = radeon_lookup_gpio(rdev, 6);
437 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500438 *connector_type = DRM_MODE_CONNECTOR_DVID;
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400439 } else if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
440 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
441 gpio = radeon_lookup_gpio(rdev, 7);
442 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
443 }
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500444 }
445
Dave Airlieefa84502010-02-09 09:06:00 +1000446 /* XFX Pine Group device rv730 reports no VGA DDC lines
447 * even though they are wired up to record 0x93
448 */
449 if ((dev->pdev->device == 0x9498) &&
450 (dev->pdev->subsystem_vendor == 0x1682) &&
451 (dev->pdev->subsystem_device == 0x2452)) {
452 struct radeon_device *rdev = dev->dev_private;
453 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
454 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200455 return true;
456}
457
458const int supported_devices_connector_convert[] = {
459 DRM_MODE_CONNECTOR_Unknown,
460 DRM_MODE_CONNECTOR_VGA,
461 DRM_MODE_CONNECTOR_DVII,
462 DRM_MODE_CONNECTOR_DVID,
463 DRM_MODE_CONNECTOR_DVIA,
464 DRM_MODE_CONNECTOR_SVIDEO,
465 DRM_MODE_CONNECTOR_Composite,
466 DRM_MODE_CONNECTOR_LVDS,
467 DRM_MODE_CONNECTOR_Unknown,
468 DRM_MODE_CONNECTOR_Unknown,
469 DRM_MODE_CONNECTOR_HDMIA,
470 DRM_MODE_CONNECTOR_HDMIB,
471 DRM_MODE_CONNECTOR_Unknown,
472 DRM_MODE_CONNECTOR_Unknown,
473 DRM_MODE_CONNECTOR_9PinDIN,
474 DRM_MODE_CONNECTOR_DisplayPort
475};
476
Alex Deucherb75fad02009-11-05 13:16:01 -0500477const uint16_t supported_devices_connector_object_id_convert[] = {
478 CONNECTOR_OBJECT_ID_NONE,
479 CONNECTOR_OBJECT_ID_VGA,
480 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
481 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
482 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
483 CONNECTOR_OBJECT_ID_COMPOSITE,
484 CONNECTOR_OBJECT_ID_SVIDEO,
485 CONNECTOR_OBJECT_ID_LVDS,
486 CONNECTOR_OBJECT_ID_9PIN_DIN,
487 CONNECTOR_OBJECT_ID_9PIN_DIN,
488 CONNECTOR_OBJECT_ID_DISPLAYPORT,
489 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
490 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
491 CONNECTOR_OBJECT_ID_SVIDEO
492};
493
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200494const int object_connector_convert[] = {
495 DRM_MODE_CONNECTOR_Unknown,
496 DRM_MODE_CONNECTOR_DVII,
497 DRM_MODE_CONNECTOR_DVII,
498 DRM_MODE_CONNECTOR_DVID,
499 DRM_MODE_CONNECTOR_DVID,
500 DRM_MODE_CONNECTOR_VGA,
501 DRM_MODE_CONNECTOR_Composite,
502 DRM_MODE_CONNECTOR_SVIDEO,
503 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher705af9c2009-09-10 16:31:13 -0400504 DRM_MODE_CONNECTOR_Unknown,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200505 DRM_MODE_CONNECTOR_9PinDIN,
506 DRM_MODE_CONNECTOR_Unknown,
507 DRM_MODE_CONNECTOR_HDMIA,
508 DRM_MODE_CONNECTOR_HDMIB,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200509 DRM_MODE_CONNECTOR_LVDS,
510 DRM_MODE_CONNECTOR_9PinDIN,
511 DRM_MODE_CONNECTOR_Unknown,
512 DRM_MODE_CONNECTOR_Unknown,
513 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher196c58d2010-01-07 14:22:32 -0500514 DRM_MODE_CONNECTOR_DisplayPort,
515 DRM_MODE_CONNECTOR_eDP,
516 DRM_MODE_CONNECTOR_Unknown
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200517};
518
519bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
520{
521 struct radeon_device *rdev = dev->dev_private;
522 struct radeon_mode_info *mode_info = &rdev->mode_info;
523 struct atom_context *ctx = mode_info->atom_context;
524 int index = GetIndexIntoMasterTable(DATA, Object_Header);
Alex Deuchereed45b32009-12-04 14:45:27 -0500525 u16 size, data_offset;
526 u8 frev, crev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200527 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400528 ATOM_OBJECT_TABLE *router_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200529 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
530 ATOM_OBJECT_HEADER *obj_header;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400531 int i, j, k, path_size, device_support;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200532 int connector_type;
Alex Deuchereed45b32009-12-04 14:45:27 -0500533 u16 igp_lane_info, conn_id, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200534 struct radeon_i2c_bus_rec ddc_bus;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400535 struct radeon_router router;
Alex Deuchereed45b32009-12-04 14:45:27 -0500536 struct radeon_gpio_rec gpio;
537 struct radeon_hpd hpd;
538
Alex Deuchera084e6e2010-03-18 01:04:01 -0400539 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200540 return false;
541
542 if (crev < 2)
543 return false;
544
545 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
546 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
547 (ctx->bios + data_offset +
548 le16_to_cpu(obj_header->usDisplayPathTableOffset));
549 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
550 (ctx->bios + data_offset +
551 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
Alex Deucher26b5bc92010-08-05 21:21:18 -0400552 router_obj = (ATOM_OBJECT_TABLE *)
553 (ctx->bios + data_offset +
554 le16_to_cpu(obj_header->usRouterObjectTableOffset));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200555 device_support = le16_to_cpu(obj_header->usDeviceSupport);
556
557 path_size = 0;
558 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
559 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
560 ATOM_DISPLAY_OBJECT_PATH *path;
561 addr += path_size;
562 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
563 path_size += le16_to_cpu(path->usSize);
Alex Deucher5137ee92010-08-12 18:58:47 -0400564
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200565 if (device_support & le16_to_cpu(path->usDeviceTag)) {
566 uint8_t con_obj_id, con_obj_num, con_obj_type;
567
568 con_obj_id =
569 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
570 >> OBJECT_ID_SHIFT;
571 con_obj_num =
572 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
573 >> ENUM_ID_SHIFT;
574 con_obj_type =
575 (le16_to_cpu(path->usConnObjectId) &
576 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
577
Dave Airlie4bbd4972009-09-25 08:56:12 +1000578 /* TODO CV support */
579 if (le16_to_cpu(path->usDeviceTag) ==
580 ATOM_DEVICE_CV_SUPPORT)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200581 continue;
582
Alex Deucheree59f2b2009-11-05 13:11:46 -0500583 /* IGP chips */
584 if ((rdev->flags & RADEON_IS_IGP) &&
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200585 (con_obj_id ==
586 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
587 uint16_t igp_offset = 0;
588 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
589
590 index =
591 GetIndexIntoMasterTable(DATA,
592 IntegratedSystemInfo);
593
Alex Deuchera084e6e2010-03-18 01:04:01 -0400594 if (atom_parse_data_header(ctx, index, &size, &frev,
595 &crev, &igp_offset)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200596
Alex Deuchera084e6e2010-03-18 01:04:01 -0400597 if (crev >= 2) {
598 igp_obj =
599 (ATOM_INTEGRATED_SYSTEM_INFO_V2
600 *) (ctx->bios + igp_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200601
Alex Deuchera084e6e2010-03-18 01:04:01 -0400602 if (igp_obj) {
603 uint32_t slot_config, ct;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200604
Alex Deuchera084e6e2010-03-18 01:04:01 -0400605 if (con_obj_num == 1)
606 slot_config =
607 igp_obj->
608 ulDDISlot1Config;
609 else
610 slot_config =
611 igp_obj->
612 ulDDISlot2Config;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200613
Alex Deuchera084e6e2010-03-18 01:04:01 -0400614 ct = (slot_config >> 16) & 0xff;
615 connector_type =
616 object_connector_convert
617 [ct];
618 connector_object_id = ct;
619 igp_lane_info =
620 slot_config & 0xffff;
621 } else
622 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200623 } else
624 continue;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400625 } else {
626 igp_lane_info = 0;
627 connector_type =
628 object_connector_convert[con_obj_id];
629 connector_object_id = con_obj_id;
630 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200631 } else {
632 igp_lane_info = 0;
633 connector_type =
634 object_connector_convert[con_obj_id];
Alex Deucherb75fad02009-11-05 13:16:01 -0500635 connector_object_id = con_obj_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200636 }
637
638 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
639 continue;
640
Tyson Whiteheadbdd91b22010-11-08 16:08:30 +0000641 router.ddc_valid = false;
642 router.cd_valid = false;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400643 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
644 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200645
Alex Deucher26b5bc92010-08-05 21:21:18 -0400646 grph_obj_id =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200647 (le16_to_cpu(path->usGraphicObjIds[j]) &
648 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400649 grph_obj_num =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200650 (le16_to_cpu(path->usGraphicObjIds[j]) &
651 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400652 grph_obj_type =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200653 (le16_to_cpu(path->usGraphicObjIds[j]) &
654 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
655
Alex Deucher26b5bc92010-08-05 21:21:18 -0400656 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
Alex Deucher5137ee92010-08-12 18:58:47 -0400657 u16 encoder_obj = le16_to_cpu(path->usGraphicObjIds[j]);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200658
659 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400660 encoder_obj,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200661 le16_to_cpu
662 (path->
663 usDeviceTag));
664
Alex Deucher26b5bc92010-08-05 21:21:18 -0400665 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
Alex Deucher26b5bc92010-08-05 21:21:18 -0400666 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
Tyson Whiteheadbdd91b22010-11-08 16:08:30 +0000667 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
Alex Deucher26b5bc92010-08-05 21:21:18 -0400668 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
669 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
670 (ctx->bios + data_offset +
671 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
672 ATOM_I2C_RECORD *i2c_record;
673 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
674 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
Alex Deucherfb939df2010-11-08 16:08:29 +0000675 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400676 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
677 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
678 (ctx->bios + data_offset +
679 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
680 int enum_id;
681
682 router.router_id = router_obj_id;
683 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
684 enum_id++) {
685 if (le16_to_cpu(path->usConnObjectId) ==
686 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
687 break;
688 }
689
690 while (record->ucRecordType > 0 &&
691 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
692 switch (record->ucRecordType) {
693 case ATOM_I2C_RECORD_TYPE:
694 i2c_record =
695 (ATOM_I2C_RECORD *)
696 record;
697 i2c_config =
698 (ATOM_I2C_ID_CONFIG_ACCESS *)
699 &i2c_record->sucI2cId;
700 router.i2c_info =
701 radeon_lookup_i2c_gpio(rdev,
702 i2c_config->
703 ucAccess);
704 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
705 break;
706 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
707 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
708 record;
Alex Deucherfb939df2010-11-08 16:08:29 +0000709 router.ddc_valid = true;
710 router.ddc_mux_type = ddc_path->ucMuxType;
711 router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
712 router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
713 break;
714 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
715 cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
716 record;
717 router.cd_valid = true;
718 router.cd_mux_type = cd_path->ucMuxType;
719 router.cd_mux_control_pin = cd_path->ucMuxControlPin;
720 router.cd_mux_state = cd_path->ucMuxState[enum_id];
Alex Deucher26b5bc92010-08-05 21:21:18 -0400721 break;
722 }
723 record = (ATOM_COMMON_RECORD_HEADER *)
724 ((char *)record + record->ucRecordSize);
725 }
726 }
727 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200728 }
729 }
730
Alex Deuchereed45b32009-12-04 14:45:27 -0500731 /* look up gpio for ddc, hpd */
Alex Deucher2bfcc0f2010-05-18 19:26:46 -0400732 ddc_bus.valid = false;
733 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200734 if ((le16_to_cpu(path->usDeviceTag) &
Alex Deuchereed45b32009-12-04 14:45:27 -0500735 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200736 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
737 if (le16_to_cpu(path->usConnObjectId) ==
738 le16_to_cpu(con_obj->asObjects[j].
739 usObjectID)) {
740 ATOM_COMMON_RECORD_HEADER
741 *record =
742 (ATOM_COMMON_RECORD_HEADER
743 *)
744 (ctx->bios + data_offset +
745 le16_to_cpu(con_obj->
746 asObjects[j].
747 usRecordOffset));
748 ATOM_I2C_RECORD *i2c_record;
Alex Deuchereed45b32009-12-04 14:45:27 -0500749 ATOM_HPD_INT_RECORD *hpd_record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500750 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500751
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200752 while (record->ucRecordType > 0
753 && record->
754 ucRecordType <=
755 ATOM_MAX_OBJECT_RECORD_NUMBER) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500756 switch (record->ucRecordType) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200757 case ATOM_I2C_RECORD_TYPE:
758 i2c_record =
Alex Deuchereed45b32009-12-04 14:45:27 -0500759 (ATOM_I2C_RECORD *)
760 record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500761 i2c_config =
762 (ATOM_I2C_ID_CONFIG_ACCESS *)
763 &i2c_record->sucI2cId;
Alex Deuchereed45b32009-12-04 14:45:27 -0500764 ddc_bus = radeon_lookup_i2c_gpio(rdev,
Alex Deucherd3f420d2009-12-08 14:30:49 -0500765 i2c_config->
766 ucAccess);
Alex Deuchereed45b32009-12-04 14:45:27 -0500767 break;
768 case ATOM_HPD_INT_RECORD_TYPE:
769 hpd_record =
770 (ATOM_HPD_INT_RECORD *)
771 record;
772 gpio = radeon_lookup_gpio(rdev,
773 hpd_record->ucHPDIntGPIOID);
774 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
775 hpd.plugged_state = hpd_record->ucPlugged_PinState;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200776 break;
777 }
778 record =
779 (ATOM_COMMON_RECORD_HEADER
780 *) ((char *)record
781 +
782 record->
783 ucRecordSize);
784 }
785 break;
786 }
787 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500788 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200789
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500790 /* needed for aux chan transactions */
Alex Deucher8e36ed02010-05-18 19:26:47 -0400791 ddc_bus.hpd = hpd.hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500792
Alex Deucher705af9c2009-09-10 16:31:13 -0400793 conn_id = le16_to_cpu(path->usConnObjectId);
794
795 if (!radeon_atom_apply_quirks
796 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500797 &ddc_bus, &conn_id, &hpd))
Alex Deucher705af9c2009-09-10 16:31:13 -0400798 continue;
799
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200800 radeon_add_atom_connector(dev,
Alex Deucher705af9c2009-09-10 16:31:13 -0400801 conn_id,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200802 le16_to_cpu(path->
803 usDeviceTag),
804 connector_type, &ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -0400805 igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -0500806 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -0400807 &hpd,
808 &router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200809
810 }
811 }
812
813 radeon_link_encoder_connector(dev);
814
815 return true;
816}
817
Alex Deucherb75fad02009-11-05 13:16:01 -0500818static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
819 int connector_type,
820 uint16_t devices)
821{
822 struct radeon_device *rdev = dev->dev_private;
823
824 if (rdev->flags & RADEON_IS_IGP) {
825 return supported_devices_connector_object_id_convert
826 [connector_type];
827 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
828 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
829 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
830 struct radeon_mode_info *mode_info = &rdev->mode_info;
831 struct atom_context *ctx = mode_info->atom_context;
832 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
833 uint16_t size, data_offset;
834 uint8_t frev, crev;
835 ATOM_XTMDS_INFO *xtmds;
836
Alex Deuchera084e6e2010-03-18 01:04:01 -0400837 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
838 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
Alex Deucherb75fad02009-11-05 13:16:01 -0500839
Alex Deuchera084e6e2010-03-18 01:04:01 -0400840 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
841 if (connector_type == DRM_MODE_CONNECTOR_DVII)
842 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
843 else
844 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
845 } else {
846 if (connector_type == DRM_MODE_CONNECTOR_DVII)
847 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
848 else
849 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
850 }
851 } else
852 return supported_devices_connector_object_id_convert
853 [connector_type];
Alex Deucherb75fad02009-11-05 13:16:01 -0500854 } else {
855 return supported_devices_connector_object_id_convert
856 [connector_type];
857 }
858}
859
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200860struct bios_connector {
861 bool valid;
Alex Deucher705af9c2009-09-10 16:31:13 -0400862 uint16_t line_mux;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200863 uint16_t devices;
864 int connector_type;
865 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500866 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200867};
868
869bool radeon_get_atom_connector_info_from_supported_devices_table(struct
870 drm_device
871 *dev)
872{
873 struct radeon_device *rdev = dev->dev_private;
874 struct radeon_mode_info *mode_info = &rdev->mode_info;
875 struct atom_context *ctx = mode_info->atom_context;
876 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
877 uint16_t size, data_offset;
878 uint8_t frev, crev;
879 uint16_t device_support;
880 uint8_t dac;
881 union atom_supported_devices *supported_devices;
Alex Deuchereed45b32009-12-04 14:45:27 -0500882 int i, j, max_device;
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000883 struct bios_connector *bios_connectors;
884 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400885 struct radeon_router router;
886
Alex Deucherfb939df2010-11-08 16:08:29 +0000887 router.ddc_valid = false;
888 router.cd_valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200889
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000890 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
891 if (!bios_connectors)
Alex Deuchera084e6e2010-03-18 01:04:01 -0400892 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200893
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000894 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
895 &data_offset)) {
896 kfree(bios_connectors);
897 return false;
898 }
899
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200900 supported_devices =
901 (union atom_supported_devices *)(ctx->bios + data_offset);
902
903 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
904
Alex Deuchereed45b32009-12-04 14:45:27 -0500905 if (frev > 1)
906 max_device = ATOM_MAX_SUPPORTED_DEVICE;
907 else
908 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
909
910 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200911 ATOM_CONNECTOR_INFO_I2C ci =
912 supported_devices->info.asConnInfo[i];
913
914 bios_connectors[i].valid = false;
915
916 if (!(device_support & (1 << i))) {
917 continue;
918 }
919
920 if (i == ATOM_DEVICE_CV_INDEX) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000921 DRM_DEBUG_KMS("Skipping Component Video\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200922 continue;
923 }
924
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200925 bios_connectors[i].connector_type =
926 supported_devices_connector_convert[ci.sucConnectorInfo.
927 sbfAccess.
928 bfConnectorType];
929
930 if (bios_connectors[i].connector_type ==
931 DRM_MODE_CONNECTOR_Unknown)
932 continue;
933
934 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
935
Alex Deucherd3f420d2009-12-08 14:30:49 -0500936 bios_connectors[i].line_mux =
937 ci.sucI2cId.ucAccess;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200938
939 /* give tv unique connector ids */
940 if (i == ATOM_DEVICE_TV1_INDEX) {
941 bios_connectors[i].ddc_bus.valid = false;
942 bios_connectors[i].line_mux = 50;
943 } else if (i == ATOM_DEVICE_TV2_INDEX) {
944 bios_connectors[i].ddc_bus.valid = false;
945 bios_connectors[i].line_mux = 51;
946 } else if (i == ATOM_DEVICE_CV_INDEX) {
947 bios_connectors[i].ddc_bus.valid = false;
948 bios_connectors[i].line_mux = 52;
949 } else
950 bios_connectors[i].ddc_bus =
Alex Deuchereed45b32009-12-04 14:45:27 -0500951 radeon_lookup_i2c_gpio(rdev,
952 bios_connectors[i].line_mux);
953
954 if ((crev > 1) && (frev > 1)) {
955 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
956 switch (isb) {
957 case 0x4:
958 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
959 break;
960 case 0xa:
961 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
962 break;
963 default:
964 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
965 break;
966 }
967 } else {
968 if (i == ATOM_DEVICE_DFP1_INDEX)
969 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
970 else if (i == ATOM_DEVICE_DFP2_INDEX)
971 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
972 else
973 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
974 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200975
976 /* Always set the connector type to VGA for CRT1/CRT2. if they are
977 * shared with a DVI port, we'll pick up the DVI connector when we
978 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
979 */
980 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
981 bios_connectors[i].connector_type =
982 DRM_MODE_CONNECTOR_VGA;
983
984 if (!radeon_atom_apply_quirks
985 (dev, (1 << i), &bios_connectors[i].connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500986 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
987 &bios_connectors[i].hpd))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200988 continue;
989
990 bios_connectors[i].valid = true;
991 bios_connectors[i].devices = (1 << i);
992
993 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
994 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400995 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200996 (1 << i),
997 dac),
998 (1 << i));
999 else
1000 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001001 radeon_get_encoder_enum(dev,
Alex Deucherf56cd642009-12-18 11:28:22 -05001002 (1 << i),
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001003 dac),
1004 (1 << i));
1005 }
1006
1007 /* combine shared connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -05001008 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001009 if (bios_connectors[i].valid) {
Alex Deuchereed45b32009-12-04 14:45:27 -05001010 for (j = 0; j < max_device; j++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001011 if (bios_connectors[j].valid && (i != j)) {
1012 if (bios_connectors[i].line_mux ==
1013 bios_connectors[j].line_mux) {
Alex Deucherf56cd642009-12-18 11:28:22 -05001014 /* make sure not to combine LVDS */
1015 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1016 bios_connectors[i].line_mux = 53;
1017 bios_connectors[i].ddc_bus.valid = false;
1018 continue;
1019 }
1020 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1021 bios_connectors[j].line_mux = 53;
1022 bios_connectors[j].ddc_bus.valid = false;
1023 continue;
1024 }
1025 /* combine analog and digital for DVI-I */
1026 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1027 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
1028 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1029 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
1030 bios_connectors[i].devices |=
1031 bios_connectors[j].devices;
1032 bios_connectors[i].connector_type =
1033 DRM_MODE_CONNECTOR_DVII;
1034 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
Alex Deuchereed45b32009-12-04 14:45:27 -05001035 bios_connectors[i].hpd =
1036 bios_connectors[j].hpd;
Alex Deucherf56cd642009-12-18 11:28:22 -05001037 bios_connectors[j].valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001038 }
1039 }
1040 }
1041 }
1042 }
1043 }
1044
1045 /* add the connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -05001046 for (i = 0; i < max_device; i++) {
Alex Deucherb75fad02009-11-05 13:16:01 -05001047 if (bios_connectors[i].valid) {
1048 uint16_t connector_object_id =
1049 atombios_get_connector_object_id(dev,
1050 bios_connectors[i].connector_type,
1051 bios_connectors[i].devices);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001052 radeon_add_atom_connector(dev,
1053 bios_connectors[i].line_mux,
1054 bios_connectors[i].devices,
1055 bios_connectors[i].
1056 connector_type,
1057 &bios_connectors[i].ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -04001058 0,
Alex Deuchereed45b32009-12-04 14:45:27 -05001059 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001060 &bios_connectors[i].hpd,
1061 &router);
Alex Deucherb75fad02009-11-05 13:16:01 -05001062 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001063 }
1064
1065 radeon_link_encoder_connector(dev);
1066
Prarit Bhargavaf49d2732010-05-24 10:24:07 +10001067 kfree(bios_connectors);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001068 return true;
1069}
1070
1071union firmware_info {
1072 ATOM_FIRMWARE_INFO info;
1073 ATOM_FIRMWARE_INFO_V1_2 info_12;
1074 ATOM_FIRMWARE_INFO_V1_3 info_13;
1075 ATOM_FIRMWARE_INFO_V1_4 info_14;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001076 ATOM_FIRMWARE_INFO_V2_1 info_21;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001077};
1078
1079bool radeon_atom_get_clock_info(struct drm_device *dev)
1080{
1081 struct radeon_device *rdev = dev->dev_private;
1082 struct radeon_mode_info *mode_info = &rdev->mode_info;
1083 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1084 union firmware_info *firmware_info;
1085 uint8_t frev, crev;
1086 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1087 struct radeon_pll *p2pll = &rdev->clock.p2pll;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001088 struct radeon_pll *dcpll = &rdev->clock.dcpll;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001089 struct radeon_pll *spll = &rdev->clock.spll;
1090 struct radeon_pll *mpll = &rdev->clock.mpll;
1091 uint16_t data_offset;
1092
Alex Deuchera084e6e2010-03-18 01:04:01 -04001093 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1094 &frev, &crev, &data_offset)) {
1095 firmware_info =
1096 (union firmware_info *)(mode_info->atom_context->bios +
1097 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001098 /* pixel clocks */
1099 p1pll->reference_freq =
1100 le16_to_cpu(firmware_info->info.usReferenceClock);
1101 p1pll->reference_div = 0;
1102
Mathias Fröhlichbc293e52009-10-19 17:49:49 -04001103 if (crev < 2)
1104 p1pll->pll_out_min =
1105 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1106 else
1107 p1pll->pll_out_min =
1108 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001109 p1pll->pll_out_max =
1110 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1111
Alex Deucher86cb2bb2010-03-08 12:55:16 -05001112 if (crev >= 4) {
1113 p1pll->lcd_pll_out_min =
1114 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1115 if (p1pll->lcd_pll_out_min == 0)
1116 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1117 p1pll->lcd_pll_out_max =
1118 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1119 if (p1pll->lcd_pll_out_max == 0)
1120 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1121 } else {
1122 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1123 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1124 }
1125
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001126 if (p1pll->pll_out_min == 0) {
1127 if (ASIC_IS_AVIVO(rdev))
1128 p1pll->pll_out_min = 64800;
1129 else
1130 p1pll->pll_out_min = 20000;
Alex Deucher8f552a62009-10-27 11:16:09 -04001131 } else if (p1pll->pll_out_min > 64800) {
1132 /* Limiting the pll output range is a good thing generally as
1133 * it limits the number of possible pll combinations for a given
1134 * frequency presumably to the ones that work best on each card.
1135 * However, certain duallink DVI monitors seem to like
1136 * pll combinations that would be limited by this at least on
1137 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
1138 * family.
1139 */
Alex Deucher48dfaae2010-09-29 11:37:41 -04001140 p1pll->pll_out_min = 64800;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001141 }
1142
1143 p1pll->pll_in_min =
1144 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1145 p1pll->pll_in_max =
1146 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1147
1148 *p2pll = *p1pll;
1149
1150 /* system clock */
1151 spll->reference_freq =
1152 le16_to_cpu(firmware_info->info.usReferenceClock);
1153 spll->reference_div = 0;
1154
1155 spll->pll_out_min =
1156 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1157 spll->pll_out_max =
1158 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1159
1160 /* ??? */
1161 if (spll->pll_out_min == 0) {
1162 if (ASIC_IS_AVIVO(rdev))
1163 spll->pll_out_min = 64800;
1164 else
1165 spll->pll_out_min = 20000;
1166 }
1167
1168 spll->pll_in_min =
1169 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1170 spll->pll_in_max =
1171 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1172
1173 /* memory clock */
1174 mpll->reference_freq =
1175 le16_to_cpu(firmware_info->info.usReferenceClock);
1176 mpll->reference_div = 0;
1177
1178 mpll->pll_out_min =
1179 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1180 mpll->pll_out_max =
1181 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1182
1183 /* ??? */
1184 if (mpll->pll_out_min == 0) {
1185 if (ASIC_IS_AVIVO(rdev))
1186 mpll->pll_out_min = 64800;
1187 else
1188 mpll->pll_out_min = 20000;
1189 }
1190
1191 mpll->pll_in_min =
1192 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1193 mpll->pll_in_max =
1194 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1195
1196 rdev->clock.default_sclk =
1197 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1198 rdev->clock.default_mclk =
1199 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1200
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001201 if (ASIC_IS_DCE4(rdev)) {
1202 rdev->clock.default_dispclk =
1203 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
1204 if (rdev->clock.default_dispclk == 0)
1205 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1206 rdev->clock.dp_extclk =
1207 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
1208 }
1209 *dcpll = *p1pll;
1210
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001211 return true;
1212 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001213
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001214 return false;
1215}
1216
Alex Deucher06b64762010-01-05 11:27:29 -05001217union igp_info {
1218 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1219 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1220};
1221
1222bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1223{
1224 struct radeon_mode_info *mode_info = &rdev->mode_info;
1225 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1226 union igp_info *igp_info;
1227 u8 frev, crev;
1228 u16 data_offset;
1229
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001230 /* sideport is AMD only */
1231 if (rdev->family == CHIP_RS600)
1232 return false;
1233
Alex Deuchera084e6e2010-03-18 01:04:01 -04001234 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1235 &frev, &crev, &data_offset)) {
1236 igp_info = (union igp_info *)(mode_info->atom_context->bios +
Alex Deucher06b64762010-01-05 11:27:29 -05001237 data_offset);
Alex Deucher06b64762010-01-05 11:27:29 -05001238 switch (crev) {
1239 case 1:
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001240 if (igp_info->info.ulBootUpMemoryClock)
1241 return true;
Alex Deucher06b64762010-01-05 11:27:29 -05001242 break;
1243 case 2:
Alex Deucher4b80d952010-08-20 12:47:54 -04001244 if (igp_info->info_2.ulBootUpSidePortClock)
Alex Deucher06b64762010-01-05 11:27:29 -05001245 return true;
1246 break;
1247 default:
1248 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1249 break;
1250 }
1251 }
1252 return false;
1253}
1254
Dave Airlie445282d2009-09-09 17:40:54 +10001255bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1256 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001257{
1258 struct drm_device *dev = encoder->base.dev;
1259 struct radeon_device *rdev = dev->dev_private;
1260 struct radeon_mode_info *mode_info = &rdev->mode_info;
1261 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1262 uint16_t data_offset;
1263 struct _ATOM_TMDS_INFO *tmds_info;
1264 uint8_t frev, crev;
1265 uint16_t maxfreq;
1266 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001267
Alex Deuchera084e6e2010-03-18 01:04:01 -04001268 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1269 &frev, &crev, &data_offset)) {
1270 tmds_info =
1271 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1272 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001273
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001274 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1275 for (i = 0; i < 4; i++) {
1276 tmds->tmds_pll[i].freq =
1277 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1278 tmds->tmds_pll[i].value =
1279 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1280 tmds->tmds_pll[i].value |=
1281 (tmds_info->asMiscInfo[i].
1282 ucPLL_VCO_Gain & 0x3f) << 6;
1283 tmds->tmds_pll[i].value |=
1284 (tmds_info->asMiscInfo[i].
1285 ucPLL_DutyCycle & 0xf) << 12;
1286 tmds->tmds_pll[i].value |=
1287 (tmds_info->asMiscInfo[i].
1288 ucPLL_VoltageSwing & 0xf) << 16;
1289
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001290 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001291 tmds->tmds_pll[i].freq,
1292 tmds->tmds_pll[i].value);
1293
1294 if (maxfreq == tmds->tmds_pll[i].freq) {
1295 tmds->tmds_pll[i].freq = 0xffffffff;
1296 break;
1297 }
1298 }
Dave Airlie445282d2009-09-09 17:40:54 +10001299 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001300 }
Dave Airlie445282d2009-09-09 17:40:54 +10001301 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001302}
1303
Alex Deucherba032a52010-10-04 17:13:01 -04001304bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
1305 struct radeon_atom_ss *ss,
1306 int id)
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001307{
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001308 struct radeon_mode_info *mode_info = &rdev->mode_info;
1309 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
Alex Deucherba032a52010-10-04 17:13:01 -04001310 uint16_t data_offset, size;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001311 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1312 uint8_t frev, crev;
Alex Deucherba032a52010-10-04 17:13:01 -04001313 int i, num_indices;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001314
Alex Deucherba032a52010-10-04 17:13:01 -04001315 memset(ss, 0, sizeof(struct radeon_atom_ss));
1316 if (atom_parse_data_header(mode_info->atom_context, index, &size,
Alex Deuchera084e6e2010-03-18 01:04:01 -04001317 &frev, &crev, &data_offset)) {
1318 ss_info =
1319 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001320
Alex Deucherba032a52010-10-04 17:13:01 -04001321 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1322 sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001323
Alex Deucherba032a52010-10-04 17:13:01 -04001324 for (i = 0; i < num_indices; i++) {
Alex Deucher279b2152009-12-08 14:07:03 -05001325 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1326 ss->percentage =
1327 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1328 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1329 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1330 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1331 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1332 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
Alex Deucherba032a52010-10-04 17:13:01 -04001333 return true;
Alex Deucher279b2152009-12-08 14:07:03 -05001334 }
1335 }
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001336 }
Alex Deucherba032a52010-10-04 17:13:01 -04001337 return false;
1338}
1339
Alex Deucher4339c442010-11-22 17:56:25 -05001340static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
1341 struct radeon_atom_ss *ss,
1342 int id)
1343{
1344 struct radeon_mode_info *mode_info = &rdev->mode_info;
1345 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1346 u16 data_offset, size;
1347 struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *igp_info;
1348 u8 frev, crev;
1349 u16 percentage = 0, rate = 0;
1350
1351 /* get any igp specific overrides */
1352 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1353 &frev, &crev, &data_offset)) {
1354 igp_info = (struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *)
1355 (mode_info->atom_context->bios + data_offset);
1356 switch (id) {
1357 case ASIC_INTERNAL_SS_ON_TMDS:
1358 percentage = le16_to_cpu(igp_info->usDVISSPercentage);
1359 rate = le16_to_cpu(igp_info->usDVISSpreadRateIn10Hz);
1360 break;
1361 case ASIC_INTERNAL_SS_ON_HDMI:
1362 percentage = le16_to_cpu(igp_info->usHDMISSPercentage);
1363 rate = le16_to_cpu(igp_info->usHDMISSpreadRateIn10Hz);
1364 break;
1365 case ASIC_INTERNAL_SS_ON_LVDS:
1366 percentage = le16_to_cpu(igp_info->usLvdsSSPercentage);
1367 rate = le16_to_cpu(igp_info->usLvdsSSpreadRateIn10Hz);
1368 break;
1369 }
1370 if (percentage)
1371 ss->percentage = percentage;
1372 if (rate)
1373 ss->rate = rate;
1374 }
1375}
1376
Alex Deucherba032a52010-10-04 17:13:01 -04001377union asic_ss_info {
1378 struct _ATOM_ASIC_INTERNAL_SS_INFO info;
1379 struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
1380 struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
1381};
1382
1383bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
1384 struct radeon_atom_ss *ss,
1385 int id, u32 clock)
1386{
1387 struct radeon_mode_info *mode_info = &rdev->mode_info;
1388 int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
1389 uint16_t data_offset, size;
1390 union asic_ss_info *ss_info;
1391 uint8_t frev, crev;
1392 int i, num_indices;
1393
1394 memset(ss, 0, sizeof(struct radeon_atom_ss));
1395 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1396 &frev, &crev, &data_offset)) {
1397
1398 ss_info =
1399 (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
1400
1401 switch (frev) {
1402 case 1:
1403 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1404 sizeof(ATOM_ASIC_SS_ASSIGNMENT);
1405
1406 for (i = 0; i < num_indices; i++) {
1407 if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
1408 (clock <= ss_info->info.asSpreadSpectrum[i].ulTargetClockRange)) {
1409 ss->percentage =
1410 le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1411 ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1412 ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
1413 return true;
1414 }
1415 }
1416 break;
1417 case 2:
1418 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1419 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
1420 for (i = 0; i < num_indices; i++) {
1421 if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
1422 (clock <= ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange)) {
1423 ss->percentage =
1424 le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1425 ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1426 ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
1427 return true;
1428 }
1429 }
1430 break;
1431 case 3:
1432 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1433 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
1434 for (i = 0; i < num_indices; i++) {
1435 if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
1436 (clock <= ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange)) {
1437 ss->percentage =
1438 le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1439 ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1440 ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
Alex Deucher4339c442010-11-22 17:56:25 -05001441 if (rdev->flags & RADEON_IS_IGP)
1442 radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
Alex Deucherba032a52010-10-04 17:13:01 -04001443 return true;
1444 }
1445 }
1446 break;
1447 default:
1448 DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
1449 break;
1450 }
1451
1452 }
1453 return false;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001454}
1455
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001456union lvds_info {
1457 struct _ATOM_LVDS_INFO info;
1458 struct _ATOM_LVDS_INFO_V12 info_12;
1459};
1460
1461struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1462 radeon_encoder
1463 *encoder)
1464{
1465 struct drm_device *dev = encoder->base.dev;
1466 struct radeon_device *rdev = dev->dev_private;
1467 struct radeon_mode_info *mode_info = &rdev->mode_info;
1468 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
Alex Deucher7dde8a12009-11-30 01:40:24 -05001469 uint16_t data_offset, misc;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001470 union lvds_info *lvds_info;
1471 uint8_t frev, crev;
1472 struct radeon_encoder_atom_dig *lvds = NULL;
Alex Deucher5137ee92010-08-12 18:58:47 -04001473 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001474
Alex Deuchera084e6e2010-03-18 01:04:01 -04001475 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1476 &frev, &crev, &data_offset)) {
1477 lvds_info =
1478 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001479 lvds =
1480 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1481
1482 if (!lvds)
1483 return NULL;
1484
Alex Deucherde2103e2009-10-09 15:14:30 -04001485 lvds->native_mode.clock =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001486 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
Alex Deucherde2103e2009-10-09 15:14:30 -04001487 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001488 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001489 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001490 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001491 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1492 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1493 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1494 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1495 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1496 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1497 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1498 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1499 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
Alex Deucher1ff26a32010-05-18 00:23:15 -04001500 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
Alex Deucherde2103e2009-10-09 15:14:30 -04001501 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1502 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001503 lvds->panel_pwr_delay =
1504 le16_to_cpu(lvds_info->info.usOffDelayInMs);
Alex Deucherba032a52010-10-04 17:13:01 -04001505 lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
Alex Deucher7dde8a12009-11-30 01:40:24 -05001506
1507 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1508 if (misc & ATOM_VSYNC_POLARITY)
1509 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1510 if (misc & ATOM_HSYNC_POLARITY)
1511 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1512 if (misc & ATOM_COMPOSITESYNC)
1513 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1514 if (misc & ATOM_INTERLACE)
1515 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1516 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1517 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1518
Alex Deucher7a868e12010-12-08 22:13:05 -05001519 lvds->native_mode.width_mm = lvds_info->info.sLCDTiming.usImageHSize;
1520 lvds->native_mode.height_mm = lvds_info->info.sLCDTiming.usImageVSize;
1521
Alex Deucherde2103e2009-10-09 15:14:30 -04001522 /* set crtc values */
1523 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001524
Alex Deucherba032a52010-10-04 17:13:01 -04001525 lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001526
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001527 encoder->native_mode = lvds->native_mode;
Alex Deucher5137ee92010-08-12 18:58:47 -04001528
1529 if (encoder_enum == 2)
1530 lvds->linkb = true;
1531 else
1532 lvds->linkb = false;
1533
Alex Deucherc324acd2010-12-08 22:13:06 -05001534 /* parse the lcd record table */
1535 if (lvds_info->info.usModePatchTableOffset) {
1536 ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
1537 ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
1538 bool bad_record = false;
1539 u8 *record = (u8 *)(mode_info->atom_context->bios +
1540 data_offset +
1541 lvds_info->info.usModePatchTableOffset);
1542 while (*record != ATOM_RECORD_END_TYPE) {
1543 switch (*record) {
1544 case LCD_MODE_PATCH_RECORD_MODE_TYPE:
1545 record += sizeof(ATOM_PATCH_RECORD_MODE);
1546 break;
1547 case LCD_RTS_RECORD_TYPE:
1548 record += sizeof(ATOM_LCD_RTS_RECORD);
1549 break;
1550 case LCD_CAP_RECORD_TYPE:
1551 record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
1552 break;
1553 case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
1554 fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
1555 if (fake_edid_record->ucFakeEDIDLength) {
1556 struct edid *edid;
1557 int edid_size =
1558 max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
1559 edid = kmalloc(edid_size, GFP_KERNEL);
1560 if (edid) {
1561 memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
1562 fake_edid_record->ucFakeEDIDLength);
1563
1564 if (drm_edid_is_valid(edid))
1565 rdev->mode_info.bios_hardcoded_edid = edid;
1566 else
1567 kfree(edid);
1568 }
1569 }
1570 record += sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
1571 break;
1572 case LCD_PANEL_RESOLUTION_RECORD_TYPE:
1573 panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
1574 lvds->native_mode.width_mm = panel_res_record->usHSize;
1575 lvds->native_mode.height_mm = panel_res_record->usVSize;
1576 record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
1577 break;
1578 default:
1579 DRM_ERROR("Bad LCD record %d\n", *record);
1580 bad_record = true;
1581 break;
1582 }
1583 if (bad_record)
1584 break;
1585 }
1586 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001587 }
1588 return lvds;
1589}
1590
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001591struct radeon_encoder_primary_dac *
1592radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1593{
1594 struct drm_device *dev = encoder->base.dev;
1595 struct radeon_device *rdev = dev->dev_private;
1596 struct radeon_mode_info *mode_info = &rdev->mode_info;
1597 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1598 uint16_t data_offset;
1599 struct _COMPASSIONATE_DATA *dac_info;
1600 uint8_t frev, crev;
1601 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001602 struct radeon_encoder_primary_dac *p_dac = NULL;
1603
Alex Deuchera084e6e2010-03-18 01:04:01 -04001604 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1605 &frev, &crev, &data_offset)) {
1606 dac_info = (struct _COMPASSIONATE_DATA *)
1607 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001608
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001609 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1610
1611 if (!p_dac)
1612 return NULL;
1613
1614 bg = dac_info->ucDAC1_BG_Adjustment;
1615 dac = dac_info->ucDAC1_DAC_Adjustment;
1616 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1617
1618 }
1619 return p_dac;
1620}
1621
Dave Airlie4ce001a2009-08-13 16:32:14 +10001622bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001623 struct drm_display_mode *mode)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001624{
1625 struct radeon_mode_info *mode_info = &rdev->mode_info;
1626 ATOM_ANALOG_TV_INFO *tv_info;
1627 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1628 ATOM_DTD_FORMAT *dtd_timings;
1629 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1630 u8 frev, crev;
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001631 u16 data_offset, misc;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001632
Alex Deuchera084e6e2010-03-18 01:04:01 -04001633 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1634 &frev, &crev, &data_offset))
1635 return false;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001636
1637 switch (crev) {
1638 case 1:
1639 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001640 if (index >= MAX_SUPPORTED_TV_TIMING)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001641 return false;
1642
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001643 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1644 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1645 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1646 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1647 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001648
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001649 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1650 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1651 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1652 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1653 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001654
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001655 mode->flags = 0;
1656 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1657 if (misc & ATOM_VSYNC_POLARITY)
1658 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1659 if (misc & ATOM_HSYNC_POLARITY)
1660 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1661 if (misc & ATOM_COMPOSITESYNC)
1662 mode->flags |= DRM_MODE_FLAG_CSYNC;
1663 if (misc & ATOM_INTERLACE)
1664 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1665 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1666 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001667
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001668 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001669
1670 if (index == 1) {
1671 /* PAL timings appear to have wrong values for totals */
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001672 mode->crtc_htotal -= 1;
1673 mode->crtc_vtotal -= 1;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001674 }
1675 break;
1676 case 2:
1677 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001678 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001679 return false;
1680
1681 dtd_timings = &tv_info_v1_2->aModeTimings[index];
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001682 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1683 le16_to_cpu(dtd_timings->usHBlanking_Time);
1684 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1685 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1686 le16_to_cpu(dtd_timings->usHSyncOffset);
1687 mode->crtc_hsync_end = mode->crtc_hsync_start +
1688 le16_to_cpu(dtd_timings->usHSyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001689
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001690 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1691 le16_to_cpu(dtd_timings->usVBlanking_Time);
1692 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1693 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1694 le16_to_cpu(dtd_timings->usVSyncOffset);
1695 mode->crtc_vsync_end = mode->crtc_vsync_start +
1696 le16_to_cpu(dtd_timings->usVSyncWidth);
1697
1698 mode->flags = 0;
1699 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1700 if (misc & ATOM_VSYNC_POLARITY)
1701 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1702 if (misc & ATOM_HSYNC_POLARITY)
1703 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1704 if (misc & ATOM_COMPOSITESYNC)
1705 mode->flags |= DRM_MODE_FLAG_CSYNC;
1706 if (misc & ATOM_INTERLACE)
1707 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1708 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1709 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1710
1711 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001712 break;
1713 }
1714 return true;
1715}
1716
Alex Deucherd79766f2009-12-17 19:00:29 -05001717enum radeon_tv_std
1718radeon_atombios_get_tv_info(struct radeon_device *rdev)
1719{
1720 struct radeon_mode_info *mode_info = &rdev->mode_info;
1721 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1722 uint16_t data_offset;
1723 uint8_t frev, crev;
1724 struct _ATOM_ANALOG_TV_INFO *tv_info;
1725 enum radeon_tv_std tv_std = TV_STD_NTSC;
1726
Alex Deuchera084e6e2010-03-18 01:04:01 -04001727 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1728 &frev, &crev, &data_offset)) {
Alex Deucherd79766f2009-12-17 19:00:29 -05001729
Alex Deuchera084e6e2010-03-18 01:04:01 -04001730 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1731 (mode_info->atom_context->bios + data_offset);
Alex Deucherd79766f2009-12-17 19:00:29 -05001732
Alex Deuchera084e6e2010-03-18 01:04:01 -04001733 switch (tv_info->ucTV_BootUpDefaultStandard) {
1734 case ATOM_TV_NTSC:
1735 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001736 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001737 break;
1738 case ATOM_TV_NTSCJ:
1739 tv_std = TV_STD_NTSC_J;
Alex Deucher40f76d82010-10-07 22:38:42 -04001740 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001741 break;
1742 case ATOM_TV_PAL:
1743 tv_std = TV_STD_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -04001744 DRM_DEBUG_KMS("Default TV standard: PAL\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001745 break;
1746 case ATOM_TV_PALM:
1747 tv_std = TV_STD_PAL_M;
Alex Deucher40f76d82010-10-07 22:38:42 -04001748 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001749 break;
1750 case ATOM_TV_PALN:
1751 tv_std = TV_STD_PAL_N;
Alex Deucher40f76d82010-10-07 22:38:42 -04001752 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001753 break;
1754 case ATOM_TV_PALCN:
1755 tv_std = TV_STD_PAL_CN;
Alex Deucher40f76d82010-10-07 22:38:42 -04001756 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001757 break;
1758 case ATOM_TV_PAL60:
1759 tv_std = TV_STD_PAL_60;
Alex Deucher40f76d82010-10-07 22:38:42 -04001760 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001761 break;
1762 case ATOM_TV_SECAM:
1763 tv_std = TV_STD_SECAM;
Alex Deucher40f76d82010-10-07 22:38:42 -04001764 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001765 break;
1766 default:
1767 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001768 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001769 break;
1770 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001771 }
1772 return tv_std;
1773}
1774
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001775struct radeon_encoder_tv_dac *
1776radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1777{
1778 struct drm_device *dev = encoder->base.dev;
1779 struct radeon_device *rdev = dev->dev_private;
1780 struct radeon_mode_info *mode_info = &rdev->mode_info;
1781 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1782 uint16_t data_offset;
1783 struct _COMPASSIONATE_DATA *dac_info;
1784 uint8_t frev, crev;
1785 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001786 struct radeon_encoder_tv_dac *tv_dac = NULL;
1787
Alex Deuchera084e6e2010-03-18 01:04:01 -04001788 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1789 &frev, &crev, &data_offset)) {
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001790
Alex Deuchera084e6e2010-03-18 01:04:01 -04001791 dac_info = (struct _COMPASSIONATE_DATA *)
1792 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001793
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001794 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1795
1796 if (!tv_dac)
1797 return NULL;
1798
1799 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1800 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1801 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1802
1803 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1804 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1805 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1806
1807 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1808 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1809 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1810
Alex Deucherd79766f2009-12-17 19:00:29 -05001811 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001812 }
1813 return tv_dac;
1814}
1815
Alex Deucher29fb52c2010-03-11 10:01:17 -05001816static const char *thermal_controller_names[] = {
1817 "NONE",
Alex Deucher678e7df2010-04-22 14:17:56 -04001818 "lm63",
1819 "adm1032",
1820 "adm1030",
1821 "max6649",
1822 "lm64",
1823 "f75375",
1824 "asc7xxx",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001825};
1826
1827static const char *pp_lib_thermal_controller_names[] = {
1828 "NONE",
Alex Deucher678e7df2010-04-22 14:17:56 -04001829 "lm63",
1830 "adm1032",
1831 "adm1030",
1832 "max6649",
1833 "lm64",
1834 "f75375",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001835 "RV6xx",
1836 "RV770",
Alex Deucher678e7df2010-04-22 14:17:56 -04001837 "adt7473",
Alex Deucher560154e2010-11-22 17:56:34 -05001838 "NONE",
Alex Deucher49f65982010-03-24 16:39:45 -04001839 "External GPIO",
1840 "Evergreen",
Alex Deucherb0e66412010-11-22 17:56:35 -05001841 "emc2103",
1842 "Sumo",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001843};
1844
Alex Deucher56278a82009-12-28 13:58:44 -05001845union power_info {
1846 struct _ATOM_POWERPLAY_INFO info;
1847 struct _ATOM_POWERPLAY_INFO_V2 info_2;
1848 struct _ATOM_POWERPLAY_INFO_V3 info_3;
Alex Deucher560154e2010-11-22 17:56:34 -05001849 struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
Alex Deucherb0e66412010-11-22 17:56:35 -05001850 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
1851 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
Alex Deucher56278a82009-12-28 13:58:44 -05001852};
1853
Alex Deucher560154e2010-11-22 17:56:34 -05001854union pplib_clock_info {
1855 struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
1856 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
1857 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
Alex Deucherb0e66412010-11-22 17:56:35 -05001858 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
Alex Deucher560154e2010-11-22 17:56:34 -05001859};
1860
1861union pplib_power_state {
1862 struct _ATOM_PPLIB_STATE v1;
1863 struct _ATOM_PPLIB_STATE_V2 v2;
1864};
1865
1866static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
1867 int state_index,
1868 u32 misc, u32 misc2)
1869{
1870 rdev->pm.power_state[state_index].misc = misc;
1871 rdev->pm.power_state[state_index].misc2 = misc2;
1872 /* order matters! */
1873 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1874 rdev->pm.power_state[state_index].type =
1875 POWER_STATE_TYPE_POWERSAVE;
1876 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1877 rdev->pm.power_state[state_index].type =
1878 POWER_STATE_TYPE_BATTERY;
1879 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1880 rdev->pm.power_state[state_index].type =
1881 POWER_STATE_TYPE_BATTERY;
1882 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1883 rdev->pm.power_state[state_index].type =
1884 POWER_STATE_TYPE_BALANCED;
1885 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
1886 rdev->pm.power_state[state_index].type =
1887 POWER_STATE_TYPE_PERFORMANCE;
1888 rdev->pm.power_state[state_index].flags &=
1889 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1890 }
1891 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1892 rdev->pm.power_state[state_index].type =
1893 POWER_STATE_TYPE_BALANCED;
1894 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
1895 rdev->pm.power_state[state_index].type =
1896 POWER_STATE_TYPE_DEFAULT;
1897 rdev->pm.default_power_state_index = state_index;
1898 rdev->pm.power_state[state_index].default_clock_mode =
1899 &rdev->pm.power_state[state_index].clock_info[0];
1900 } else if (state_index == 0) {
1901 rdev->pm.power_state[state_index].clock_info[0].flags |=
1902 RADEON_PM_MODE_NO_DISPLAY;
1903 }
1904}
1905
1906static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
1907{
1908 struct radeon_mode_info *mode_info = &rdev->mode_info;
1909 u32 misc, misc2 = 0;
1910 int num_modes = 0, i;
1911 int state_index = 0;
1912 struct radeon_i2c_bus_rec i2c_bus;
1913 union power_info *power_info;
1914 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
1915 u16 data_offset;
1916 u8 frev, crev;
1917
1918 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
1919 &frev, &crev, &data_offset))
1920 return state_index;
1921 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
1922
1923 /* add the i2c bus for thermal/fan chip */
1924 if (power_info->info.ucOverdriveThermalController > 0) {
1925 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
1926 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1927 power_info->info.ucOverdriveControllerAddress >> 1);
1928 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
1929 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1930 if (rdev->pm.i2c_bus) {
1931 struct i2c_board_info info = { };
1932 const char *name = thermal_controller_names[power_info->info.
1933 ucOverdriveThermalController];
1934 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
1935 strlcpy(info.type, name, sizeof(info.type));
1936 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
1937 }
1938 }
1939 num_modes = power_info->info.ucNumOfPowerModeEntries;
1940 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
1941 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
1942 /* last mode is usually default, array is low to high */
1943 for (i = 0; i < num_modes; i++) {
1944 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
1945 switch (frev) {
1946 case 1:
1947 rdev->pm.power_state[state_index].num_clock_modes = 1;
1948 rdev->pm.power_state[state_index].clock_info[0].mclk =
1949 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
1950 rdev->pm.power_state[state_index].clock_info[0].sclk =
1951 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
1952 /* skip invalid modes */
1953 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1954 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1955 continue;
1956 rdev->pm.power_state[state_index].pcie_lanes =
1957 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
1958 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
1959 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1960 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
1961 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1962 VOLTAGE_GPIO;
1963 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1964 radeon_lookup_gpio(rdev,
1965 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
1966 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1967 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1968 true;
1969 else
1970 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1971 false;
1972 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1973 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1974 VOLTAGE_VDDC;
1975 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1976 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
1977 }
1978 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1979 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
1980 state_index++;
1981 break;
1982 case 2:
1983 rdev->pm.power_state[state_index].num_clock_modes = 1;
1984 rdev->pm.power_state[state_index].clock_info[0].mclk =
1985 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
1986 rdev->pm.power_state[state_index].clock_info[0].sclk =
1987 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
1988 /* skip invalid modes */
1989 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1990 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1991 continue;
1992 rdev->pm.power_state[state_index].pcie_lanes =
1993 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
1994 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
1995 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
1996 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1997 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
1998 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1999 VOLTAGE_GPIO;
2000 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2001 radeon_lookup_gpio(rdev,
2002 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
2003 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2004 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2005 true;
2006 else
2007 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2008 false;
2009 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2010 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2011 VOLTAGE_VDDC;
2012 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2013 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
2014 }
2015 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2016 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2017 state_index++;
2018 break;
2019 case 3:
2020 rdev->pm.power_state[state_index].num_clock_modes = 1;
2021 rdev->pm.power_state[state_index].clock_info[0].mclk =
2022 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
2023 rdev->pm.power_state[state_index].clock_info[0].sclk =
2024 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
2025 /* skip invalid modes */
2026 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2027 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2028 continue;
2029 rdev->pm.power_state[state_index].pcie_lanes =
2030 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
2031 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
2032 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
2033 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2034 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2035 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2036 VOLTAGE_GPIO;
2037 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2038 radeon_lookup_gpio(rdev,
2039 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
2040 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2041 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2042 true;
2043 else
2044 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2045 false;
2046 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2047 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2048 VOLTAGE_VDDC;
2049 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2050 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
2051 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
2052 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
2053 true;
2054 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
2055 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
2056 }
2057 }
2058 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2059 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2060 state_index++;
2061 break;
2062 }
2063 }
2064 /* last mode is usually default */
2065 if (rdev->pm.default_power_state_index == -1) {
2066 rdev->pm.power_state[state_index - 1].type =
2067 POWER_STATE_TYPE_DEFAULT;
2068 rdev->pm.default_power_state_index = state_index - 1;
2069 rdev->pm.power_state[state_index - 1].default_clock_mode =
2070 &rdev->pm.power_state[state_index - 1].clock_info[0];
2071 rdev->pm.power_state[state_index].flags &=
2072 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2073 rdev->pm.power_state[state_index].misc = 0;
2074 rdev->pm.power_state[state_index].misc2 = 0;
2075 }
2076 return state_index;
2077}
2078
2079static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
2080 ATOM_PPLIB_THERMALCONTROLLER *controller)
2081{
2082 struct radeon_i2c_bus_rec i2c_bus;
2083
2084 /* add the i2c bus for thermal/fan chip */
2085 if (controller->ucType > 0) {
2086 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
2087 DRM_INFO("Internal thermal controller %s fan control\n",
2088 (controller->ucFanParameters &
2089 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2090 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
2091 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
2092 DRM_INFO("Internal thermal controller %s fan control\n",
2093 (controller->ucFanParameters &
2094 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2095 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
2096 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
2097 DRM_INFO("Internal thermal controller %s fan control\n",
2098 (controller->ucFanParameters &
2099 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2100 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
Alex Deucherb0e66412010-11-22 17:56:35 -05002101 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
2102 DRM_INFO("Internal thermal controller %s fan control\n",
2103 (controller->ucFanParameters &
2104 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2105 rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
Alex Deucher560154e2010-11-22 17:56:34 -05002106 } else if ((controller->ucType ==
2107 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
2108 (controller->ucType ==
Alex Deucherb0e66412010-11-22 17:56:35 -05002109 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
2110 (controller->ucType ==
2111 ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002112 DRM_INFO("Special thermal controller config\n");
2113 } else {
2114 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2115 pp_lib_thermal_controller_names[controller->ucType],
2116 controller->ucI2cAddress >> 1,
2117 (controller->ucFanParameters &
2118 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2119 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
2120 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2121 if (rdev->pm.i2c_bus) {
2122 struct i2c_board_info info = { };
2123 const char *name = pp_lib_thermal_controller_names[controller->ucType];
2124 info.addr = controller->ucI2cAddress >> 1;
2125 strlcpy(info.type, name, sizeof(info.type));
2126 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2127 }
2128 }
2129 }
2130}
2131
2132static u16 radeon_atombios_get_default_vddc(struct radeon_device *rdev)
2133{
2134 struct radeon_mode_info *mode_info = &rdev->mode_info;
2135 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
2136 u8 frev, crev;
2137 u16 data_offset;
2138 union firmware_info *firmware_info;
2139 u16 vddc = 0;
2140
2141 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2142 &frev, &crev, &data_offset)) {
2143 firmware_info =
2144 (union firmware_info *)(mode_info->atom_context->bios +
2145 data_offset);
2146 vddc = firmware_info->info_14.usBootUpVDDCVoltage;
2147 }
2148
2149 return vddc;
2150}
2151
2152static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
2153 int state_index, int mode_index,
2154 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
2155{
2156 int j;
2157 u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
2158 u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
2159 u16 vddc = radeon_atombios_get_default_vddc(rdev);
2160
2161 rdev->pm.power_state[state_index].misc = misc;
2162 rdev->pm.power_state[state_index].misc2 = misc2;
2163 rdev->pm.power_state[state_index].pcie_lanes =
2164 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2165 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2166 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2167 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2168 rdev->pm.power_state[state_index].type =
2169 POWER_STATE_TYPE_BATTERY;
2170 break;
2171 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2172 rdev->pm.power_state[state_index].type =
2173 POWER_STATE_TYPE_BALANCED;
2174 break;
2175 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2176 rdev->pm.power_state[state_index].type =
2177 POWER_STATE_TYPE_PERFORMANCE;
2178 break;
2179 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2180 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2181 rdev->pm.power_state[state_index].type =
2182 POWER_STATE_TYPE_PERFORMANCE;
2183 break;
2184 }
2185 rdev->pm.power_state[state_index].flags = 0;
2186 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2187 rdev->pm.power_state[state_index].flags |=
2188 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2189 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
2190 rdev->pm.power_state[state_index].type =
2191 POWER_STATE_TYPE_DEFAULT;
2192 rdev->pm.default_power_state_index = state_index;
2193 rdev->pm.power_state[state_index].default_clock_mode =
2194 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
2195 /* patch the table values with the default slck/mclk from firmware info */
2196 for (j = 0; j < mode_index; j++) {
2197 rdev->pm.power_state[state_index].clock_info[j].mclk =
2198 rdev->clock.default_mclk;
2199 rdev->pm.power_state[state_index].clock_info[j].sclk =
2200 rdev->clock.default_sclk;
2201 if (vddc)
2202 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2203 vddc;
2204 }
2205 }
2206}
2207
2208static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
2209 int state_index, int mode_index,
2210 union pplib_clock_info *clock_info)
2211{
2212 u32 sclk, mclk;
2213
2214 if (rdev->flags & RADEON_IS_IGP) {
Alex Deucherb0e66412010-11-22 17:56:35 -05002215 if (rdev->family >= CHIP_PALM) {
2216 sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
2217 sclk |= clock_info->sumo.ucEngineClockHigh << 16;
2218 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2219 } else {
2220 sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
2221 sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
2222 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2223 }
Alex Deucher560154e2010-11-22 17:56:34 -05002224 } else if (ASIC_IS_DCE4(rdev)) {
2225 sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
2226 sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
2227 mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
2228 mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
2229 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2230 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2231 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2232 VOLTAGE_SW;
2233 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2234 clock_info->evergreen.usVDDC;
2235 } else {
2236 sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
2237 sclk |= clock_info->r600.ucEngineClockHigh << 16;
2238 mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
2239 mclk |= clock_info->r600.ucMemoryClockHigh << 16;
2240 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2241 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2242 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2243 VOLTAGE_SW;
2244 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2245 clock_info->r600.usVDDC;
2246 }
2247
2248 if (rdev->flags & RADEON_IS_IGP) {
2249 /* skip invalid modes */
2250 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2251 return false;
2252 } else {
2253 /* skip invalid modes */
2254 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2255 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2256 return false;
2257 }
2258 return true;
2259}
2260
2261static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
2262{
2263 struct radeon_mode_info *mode_info = &rdev->mode_info;
2264 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2265 union pplib_power_state *power_state;
2266 int i, j;
2267 int state_index = 0, mode_index = 0;
2268 union pplib_clock_info *clock_info;
2269 bool valid;
2270 union power_info *power_info;
2271 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2272 u16 data_offset;
2273 u8 frev, crev;
2274
2275 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2276 &frev, &crev, &data_offset))
2277 return state_index;
2278 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2279
2280 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
2281 /* first mode is usually default, followed by low to high */
2282 for (i = 0; i < power_info->pplib.ucNumStates; i++) {
2283 mode_index = 0;
2284 power_state = (union pplib_power_state *)
2285 (mode_info->atom_context->bios + data_offset +
2286 le16_to_cpu(power_info->pplib.usStateArrayOffset) +
2287 i * power_info->pplib.ucStateEntrySize);
2288 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2289 (mode_info->atom_context->bios + data_offset +
2290 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
2291 (power_state->v1.ucNonClockStateIndex *
2292 power_info->pplib.ucNonClockSize));
2293 for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
2294 clock_info = (union pplib_clock_info *)
2295 (mode_info->atom_context->bios + data_offset +
2296 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
2297 (power_state->v1.ucClockStateIndices[j] *
2298 power_info->pplib.ucClockInfoSize));
2299 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2300 state_index, mode_index,
2301 clock_info);
2302 if (valid)
2303 mode_index++;
2304 }
2305 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2306 if (mode_index) {
2307 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2308 non_clock_info);
2309 state_index++;
2310 }
2311 }
2312 /* if multiple clock modes, mark the lowest as no display */
2313 for (i = 0; i < state_index; i++) {
2314 if (rdev->pm.power_state[i].num_clock_modes > 1)
2315 rdev->pm.power_state[i].clock_info[0].flags |=
2316 RADEON_PM_MODE_NO_DISPLAY;
2317 }
2318 /* first mode is usually default */
2319 if (rdev->pm.default_power_state_index == -1) {
2320 rdev->pm.power_state[0].type =
2321 POWER_STATE_TYPE_DEFAULT;
2322 rdev->pm.default_power_state_index = 0;
2323 rdev->pm.power_state[0].default_clock_mode =
2324 &rdev->pm.power_state[0].clock_info[0];
2325 }
2326 return state_index;
2327}
2328
Alex Deucherb0e66412010-11-22 17:56:35 -05002329static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
2330{
2331 struct radeon_mode_info *mode_info = &rdev->mode_info;
2332 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2333 union pplib_power_state *power_state;
2334 int i, j, non_clock_array_index, clock_array_index;
2335 int state_index = 0, mode_index = 0;
2336 union pplib_clock_info *clock_info;
2337 struct StateArray *state_array;
2338 struct ClockInfoArray *clock_info_array;
2339 struct NonClockInfoArray *non_clock_info_array;
2340 bool valid;
2341 union power_info *power_info;
2342 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2343 u16 data_offset;
2344 u8 frev, crev;
2345
2346 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2347 &frev, &crev, &data_offset))
2348 return state_index;
2349 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2350
2351 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
2352 state_array = (struct StateArray *)
2353 (mode_info->atom_context->bios + data_offset +
2354 power_info->pplib.usStateArrayOffset);
2355 clock_info_array = (struct ClockInfoArray *)
2356 (mode_info->atom_context->bios + data_offset +
2357 power_info->pplib.usClockInfoArrayOffset);
2358 non_clock_info_array = (struct NonClockInfoArray *)
2359 (mode_info->atom_context->bios + data_offset +
2360 power_info->pplib.usNonClockInfoArrayOffset);
2361 for (i = 0; i < state_array->ucNumEntries; i++) {
2362 mode_index = 0;
2363 power_state = (union pplib_power_state *)&state_array->states[i];
2364 /* XXX this might be an inagua bug... */
2365 non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
2366 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2367 &non_clock_info_array->nonClockInfo[non_clock_array_index];
2368 for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2369 clock_array_index = power_state->v2.clockInfoIndex[j];
2370 /* XXX this might be an inagua bug... */
2371 if (clock_array_index >= clock_info_array->ucNumEntries)
2372 continue;
2373 clock_info = (union pplib_clock_info *)
2374 &clock_info_array->clockInfo[clock_array_index];
2375 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2376 state_index, mode_index,
2377 clock_info);
2378 if (valid)
2379 mode_index++;
2380 }
2381 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2382 if (mode_index) {
2383 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2384 non_clock_info);
2385 state_index++;
2386 }
2387 }
2388 /* if multiple clock modes, mark the lowest as no display */
2389 for (i = 0; i < state_index; i++) {
2390 if (rdev->pm.power_state[i].num_clock_modes > 1)
2391 rdev->pm.power_state[i].clock_info[0].flags |=
2392 RADEON_PM_MODE_NO_DISPLAY;
2393 }
2394 /* first mode is usually default */
2395 if (rdev->pm.default_power_state_index == -1) {
2396 rdev->pm.power_state[0].type =
2397 POWER_STATE_TYPE_DEFAULT;
2398 rdev->pm.default_power_state_index = 0;
2399 rdev->pm.power_state[0].default_clock_mode =
2400 &rdev->pm.power_state[0].clock_info[0];
2401 }
2402 return state_index;
2403}
2404
Alex Deucher56278a82009-12-28 13:58:44 -05002405void radeon_atombios_get_power_modes(struct radeon_device *rdev)
2406{
2407 struct radeon_mode_info *mode_info = &rdev->mode_info;
2408 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2409 u16 data_offset;
2410 u8 frev, crev;
Alex Deucher560154e2010-11-22 17:56:34 -05002411 int state_index = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002412
Alex Deuchera48b9b42010-04-22 14:03:55 -04002413 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05002414
Alex Deuchera084e6e2010-03-18 01:04:01 -04002415 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2416 &frev, &crev, &data_offset)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002417 switch (frev) {
2418 case 1:
2419 case 2:
2420 case 3:
2421 state_index = radeon_atombios_parse_power_table_1_3(rdev);
2422 break;
2423 case 4:
2424 case 5:
2425 state_index = radeon_atombios_parse_power_table_4_5(rdev);
2426 break;
Alex Deucherb0e66412010-11-22 17:56:35 -05002427 case 6:
2428 state_index = radeon_atombios_parse_power_table_6(rdev);
2429 break;
Alex Deucher560154e2010-11-22 17:56:34 -05002430 default:
2431 break;
Alex Deucher56278a82009-12-28 13:58:44 -05002432 }
2433 } else {
Alex Deucher56278a82009-12-28 13:58:44 -05002434 /* add the default mode */
Alex Deucher0ec0e742009-12-23 13:21:58 -05002435 rdev->pm.power_state[state_index].type =
2436 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05002437 rdev->pm.power_state[state_index].num_clock_modes = 1;
2438 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2439 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2440 rdev->pm.power_state[state_index].default_clock_mode =
2441 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucher56278a82009-12-28 13:58:44 -05002442 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
Alex Deucher79daedc2010-04-22 14:25:19 -04002443 rdev->pm.power_state[state_index].pcie_lanes = 16;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002444 rdev->pm.default_power_state_index = state_index;
2445 rdev->pm.power_state[state_index].flags = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002446 state_index++;
2447 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002448
Alex Deucher56278a82009-12-28 13:58:44 -05002449 rdev->pm.num_power_states = state_index;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002450
Alex Deuchera48b9b42010-04-22 14:03:55 -04002451 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2452 rdev->pm.current_clock_mode_index = 0;
Alex Deucher4d601732010-06-07 18:15:18 -04002453 rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
Alex Deucher56278a82009-12-28 13:58:44 -05002454}
2455
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002456void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2457{
2458 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2459 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2460
2461 args.ucEnable = enable;
2462
2463 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2464}
2465
Rafał Miłecki74338742009-11-03 00:53:02 +01002466uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2467{
2468 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2469 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2470
2471 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2472 return args.ulReturnEngineClock;
2473}
2474
2475uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2476{
2477 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2478 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2479
2480 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2481 return args.ulReturnMemoryClock;
2482}
2483
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002484void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2485 uint32_t eng_clock)
2486{
2487 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2488 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2489
2490 args.ulTargetEngineClock = eng_clock; /* 10 khz */
2491
2492 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2493}
2494
2495void radeon_atom_set_memory_clock(struct radeon_device *rdev,
2496 uint32_t mem_clock)
2497{
2498 SET_MEMORY_CLOCK_PS_ALLOCATION args;
2499 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
2500
2501 if (rdev->flags & RADEON_IS_IGP)
2502 return;
2503
2504 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
2505
2506 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2507}
2508
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002509union set_voltage {
2510 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2511 struct _SET_VOLTAGE_PARAMETERS v1;
2512 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2513};
2514
2515void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level)
2516{
2517 union set_voltage args;
2518 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
2519 u8 frev, crev, volt_index = level;
2520
2521 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2522 return;
2523
2524 switch (crev) {
2525 case 1:
2526 args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2527 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
2528 args.v1.ucVoltageIndex = volt_index;
2529 break;
2530 case 2:
2531 args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2532 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
2533 args.v2.usVoltageLevel = cpu_to_le16(level);
2534 break;
2535 default:
2536 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2537 return;
2538 }
2539
2540 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2541}
2542
2543
2544
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002545void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
2546{
2547 struct radeon_device *rdev = dev->dev_private;
2548 uint32_t bios_2_scratch, bios_6_scratch;
2549
2550 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002551 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002552 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2553 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002554 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002555 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2556 }
2557
2558 /* let the bios control the backlight */
2559 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
2560
2561 /* tell the bios not to handle mode switching */
2562 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
2563
2564 if (rdev->family >= CHIP_R600) {
2565 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2566 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2567 } else {
2568 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2569 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2570 }
2571
2572}
2573
Yang Zhaof657c2a2009-09-15 12:21:01 +10002574void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
2575{
2576 uint32_t scratch_reg;
2577 int i;
2578
2579 if (rdev->family >= CHIP_R600)
2580 scratch_reg = R600_BIOS_0_SCRATCH;
2581 else
2582 scratch_reg = RADEON_BIOS_0_SCRATCH;
2583
2584 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2585 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
2586}
2587
2588void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
2589{
2590 uint32_t scratch_reg;
2591 int i;
2592
2593 if (rdev->family >= CHIP_R600)
2594 scratch_reg = R600_BIOS_0_SCRATCH;
2595 else
2596 scratch_reg = RADEON_BIOS_0_SCRATCH;
2597
2598 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2599 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
2600}
2601
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002602void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
2603{
2604 struct drm_device *dev = encoder->dev;
2605 struct radeon_device *rdev = dev->dev_private;
2606 uint32_t bios_6_scratch;
2607
2608 if (rdev->family >= CHIP_R600)
2609 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2610 else
2611 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2612
2613 if (lock)
2614 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
2615 else
2616 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
2617
2618 if (rdev->family >= CHIP_R600)
2619 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2620 else
2621 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2622}
2623
2624/* at some point we may want to break this out into individual functions */
2625void
2626radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
2627 struct drm_encoder *encoder,
2628 bool connected)
2629{
2630 struct drm_device *dev = connector->dev;
2631 struct radeon_device *rdev = dev->dev_private;
2632 struct radeon_connector *radeon_connector =
2633 to_radeon_connector(connector);
2634 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2635 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
2636
2637 if (rdev->family >= CHIP_R600) {
2638 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2639 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2640 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2641 } else {
2642 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2643 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2644 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2645 }
2646
2647 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
2648 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
2649 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002650 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002651 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
2652 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
2653 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002654 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002655 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
2656 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
2657 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
2658 }
2659 }
2660 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
2661 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
2662 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002663 DRM_DEBUG_KMS("CV connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002664 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
2665 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
2666 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002667 DRM_DEBUG_KMS("CV disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002668 bios_0_scratch &= ~ATOM_S0_CV_MASK;
2669 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
2670 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
2671 }
2672 }
2673 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
2674 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
2675 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002676 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002677 bios_0_scratch |= ATOM_S0_LCD1;
2678 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
2679 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
2680 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002681 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002682 bios_0_scratch &= ~ATOM_S0_LCD1;
2683 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
2684 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
2685 }
2686 }
2687 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
2688 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
2689 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002690 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002691 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
2692 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
2693 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
2694 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002695 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002696 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
2697 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
2698 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
2699 }
2700 }
2701 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
2702 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
2703 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002704 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002705 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
2706 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
2707 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
2708 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002709 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002710 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
2711 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
2712 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
2713 }
2714 }
2715 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
2716 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
2717 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002718 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002719 bios_0_scratch |= ATOM_S0_DFP1;
2720 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
2721 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
2722 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002723 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002724 bios_0_scratch &= ~ATOM_S0_DFP1;
2725 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
2726 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
2727 }
2728 }
2729 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
2730 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
2731 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002732 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002733 bios_0_scratch |= ATOM_S0_DFP2;
2734 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
2735 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
2736 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002737 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002738 bios_0_scratch &= ~ATOM_S0_DFP2;
2739 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
2740 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
2741 }
2742 }
2743 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
2744 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
2745 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002746 DRM_DEBUG_KMS("DFP3 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002747 bios_0_scratch |= ATOM_S0_DFP3;
2748 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
2749 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
2750 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002751 DRM_DEBUG_KMS("DFP3 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002752 bios_0_scratch &= ~ATOM_S0_DFP3;
2753 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
2754 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
2755 }
2756 }
2757 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
2758 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
2759 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002760 DRM_DEBUG_KMS("DFP4 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002761 bios_0_scratch |= ATOM_S0_DFP4;
2762 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
2763 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
2764 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002765 DRM_DEBUG_KMS("DFP4 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002766 bios_0_scratch &= ~ATOM_S0_DFP4;
2767 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
2768 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
2769 }
2770 }
2771 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
2772 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
2773 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002774 DRM_DEBUG_KMS("DFP5 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002775 bios_0_scratch |= ATOM_S0_DFP5;
2776 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
2777 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
2778 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002779 DRM_DEBUG_KMS("DFP5 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002780 bios_0_scratch &= ~ATOM_S0_DFP5;
2781 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2782 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2783 }
2784 }
2785
2786 if (rdev->family >= CHIP_R600) {
2787 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2788 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2789 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2790 } else {
2791 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
2792 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2793 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2794 }
2795}
2796
2797void
2798radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
2799{
2800 struct drm_device *dev = encoder->dev;
2801 struct radeon_device *rdev = dev->dev_private;
2802 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2803 uint32_t bios_3_scratch;
2804
2805 if (rdev->family >= CHIP_R600)
2806 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2807 else
2808 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2809
2810 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2811 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
2812 bios_3_scratch |= (crtc << 18);
2813 }
2814 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2815 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
2816 bios_3_scratch |= (crtc << 24);
2817 }
2818 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2819 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
2820 bios_3_scratch |= (crtc << 16);
2821 }
2822 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2823 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
2824 bios_3_scratch |= (crtc << 20);
2825 }
2826 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2827 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
2828 bios_3_scratch |= (crtc << 17);
2829 }
2830 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2831 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
2832 bios_3_scratch |= (crtc << 19);
2833 }
2834 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2835 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
2836 bios_3_scratch |= (crtc << 23);
2837 }
2838 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2839 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
2840 bios_3_scratch |= (crtc << 25);
2841 }
2842
2843 if (rdev->family >= CHIP_R600)
2844 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2845 else
2846 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2847}
2848
2849void
2850radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
2851{
2852 struct drm_device *dev = encoder->dev;
2853 struct radeon_device *rdev = dev->dev_private;
2854 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2855 uint32_t bios_2_scratch;
2856
2857 if (rdev->family >= CHIP_R600)
2858 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2859 else
2860 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
2861
2862 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2863 if (on)
2864 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
2865 else
2866 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
2867 }
2868 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2869 if (on)
2870 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
2871 else
2872 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
2873 }
2874 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2875 if (on)
2876 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
2877 else
2878 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
2879 }
2880 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2881 if (on)
2882 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
2883 else
2884 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
2885 }
2886 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2887 if (on)
2888 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
2889 else
2890 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
2891 }
2892 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2893 if (on)
2894 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
2895 else
2896 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
2897 }
2898 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2899 if (on)
2900 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
2901 else
2902 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
2903 }
2904 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2905 if (on)
2906 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
2907 else
2908 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
2909 }
2910 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
2911 if (on)
2912 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
2913 else
2914 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
2915 }
2916 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
2917 if (on)
2918 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
2919 else
2920 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
2921 }
2922
2923 if (rdev->family >= CHIP_R600)
2924 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2925 else
2926 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2927}