blob: a1de975eec30f032282dd193bb130226831f48ae [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 Deuchera084e6e2010-03-18 01:04:01 -0400101 if (gpio->sucI2cId.ucAccess == id) {
102 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
103 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
104 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
105 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
106 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
107 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
108 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
109 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
110 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
111 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
112 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
113 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
114 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
115 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
116 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
117 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200118
Alex Deuchera084e6e2010-03-18 01:04:01 -0400119 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
120 i2c.hw_capable = true;
121 else
122 i2c.hw_capable = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500123
Alex Deuchera084e6e2010-03-18 01:04:01 -0400124 if (gpio->sucI2cId.ucAccess == 0xa0)
125 i2c.mm_i2c = true;
126 else
127 i2c.mm_i2c = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500128
Alex Deuchera084e6e2010-03-18 01:04:01 -0400129 i2c.i2c_id = gpio->sucI2cId.ucAccess;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500130
Alex Deucherf376b942010-08-05 21:21:16 -0400131 if (i2c.mask_clk_reg)
132 i2c.valid = true;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400133 break;
134 }
Alex Deucherd3f420d2009-12-08 14:30:49 -0500135 }
136 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200137
138 return i2c;
139}
140
Alex Deucherf376b942010-08-05 21:21:16 -0400141void radeon_atombios_i2c_init(struct radeon_device *rdev)
142{
143 struct atom_context *ctx = rdev->mode_info.atom_context;
144 ATOM_GPIO_I2C_ASSIGMENT *gpio;
145 struct radeon_i2c_bus_rec i2c;
146 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
147 struct _ATOM_GPIO_I2C_INFO *i2c_info;
148 uint16_t data_offset, size;
149 int i, num_indices;
150 char stmp[32];
151
152 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
153
154 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
155 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
156
157 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
158 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
159
160 for (i = 0; i < num_indices; i++) {
161 gpio = &i2c_info->asGPIO_Info[i];
162 i2c.valid = false;
Alex Deucherea393022010-08-27 16:04:29 -0400163
164 /* some evergreen boards have bad data for this entry */
165 if (ASIC_IS_DCE4(rdev)) {
166 if ((i == 7) &&
167 (gpio->usClkMaskRegisterIndex == 0x1936) &&
168 (gpio->sucI2cId.ucAccess == 0)) {
169 gpio->sucI2cId.ucAccess = 0x97;
170 gpio->ucDataMaskShift = 8;
171 gpio->ucDataEnShift = 8;
172 gpio->ucDataY_Shift = 8;
173 gpio->ucDataA_Shift = 8;
174 }
175 }
176
Alex Deucherf376b942010-08-05 21:21:16 -0400177 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
178 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
179 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
180 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
181 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
182 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
183 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
184 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
185 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
186 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
187 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
188 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
189 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
190 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
191 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
192 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
193
194 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
195 i2c.hw_capable = true;
196 else
197 i2c.hw_capable = false;
198
199 if (gpio->sucI2cId.ucAccess == 0xa0)
200 i2c.mm_i2c = true;
201 else
202 i2c.mm_i2c = false;
203
204 i2c.i2c_id = gpio->sucI2cId.ucAccess;
205
206 if (i2c.mask_clk_reg) {
207 i2c.valid = true;
208 sprintf(stmp, "0x%x", i2c.i2c_id);
209 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
210 }
211 }
212 }
213}
214
Alex Deuchereed45b32009-12-04 14:45:27 -0500215static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
216 u8 id)
217{
218 struct atom_context *ctx = rdev->mode_info.atom_context;
219 struct radeon_gpio_rec gpio;
220 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
221 struct _ATOM_GPIO_PIN_LUT *gpio_info;
222 ATOM_GPIO_PIN_ASSIGNMENT *pin;
223 u16 data_offset, size;
224 int i, num_indices;
225
226 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
227 gpio.valid = false;
228
Alex Deuchera084e6e2010-03-18 01:04:01 -0400229 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
230 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
Alex Deuchereed45b32009-12-04 14:45:27 -0500231
Alex Deuchera084e6e2010-03-18 01:04:01 -0400232 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
233 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
Alex Deuchereed45b32009-12-04 14:45:27 -0500234
Alex Deuchera084e6e2010-03-18 01:04:01 -0400235 for (i = 0; i < num_indices; i++) {
236 pin = &gpio_info->asGPIO_Pin[i];
237 if (id == pin->ucGPIO_ID) {
238 gpio.id = pin->ucGPIO_ID;
239 gpio.reg = pin->usGpioPin_AIndex * 4;
240 gpio.mask = (1 << pin->ucGpioPinBitShift);
241 gpio.valid = true;
242 break;
243 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500244 }
245 }
246
247 return gpio;
248}
249
250static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
251 struct radeon_gpio_rec *gpio)
252{
253 struct radeon_hpd hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500254 u32 reg;
255
Jean Delvare1d978da2010-08-15 14:11:24 +0200256 memset(&hpd, 0, sizeof(struct radeon_hpd));
257
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500258 if (ASIC_IS_DCE4(rdev))
259 reg = EVERGREEN_DC_GPIO_HPD_A;
260 else
261 reg = AVIVO_DC_GPIO_HPD_A;
262
Alex Deuchereed45b32009-12-04 14:45:27 -0500263 hpd.gpio = *gpio;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500264 if (gpio->reg == reg) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500265 switch(gpio->mask) {
266 case (1 << 0):
267 hpd.hpd = RADEON_HPD_1;
268 break;
269 case (1 << 8):
270 hpd.hpd = RADEON_HPD_2;
271 break;
272 case (1 << 16):
273 hpd.hpd = RADEON_HPD_3;
274 break;
275 case (1 << 24):
276 hpd.hpd = RADEON_HPD_4;
277 break;
278 case (1 << 26):
279 hpd.hpd = RADEON_HPD_5;
280 break;
281 case (1 << 28):
282 hpd.hpd = RADEON_HPD_6;
283 break;
284 default:
285 hpd.hpd = RADEON_HPD_NONE;
286 break;
287 }
288 } else
289 hpd.hpd = RADEON_HPD_NONE;
290 return hpd;
291}
292
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200293static bool radeon_atom_apply_quirks(struct drm_device *dev,
294 uint32_t supported_device,
295 int *connector_type,
Alex Deucher848577e2009-07-08 16:15:30 -0400296 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -0500297 uint16_t *line_mux,
298 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200299{
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400300 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200301
302 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
303 if ((dev->pdev->device == 0x791e) &&
304 (dev->pdev->subsystem_vendor == 0x1043) &&
305 (dev->pdev->subsystem_device == 0x826d)) {
306 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
307 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
308 *connector_type = DRM_MODE_CONNECTOR_DVID;
309 }
310
Alex Deucherc86a9032010-02-18 14:14:58 -0500311 /* Asrock RS600 board lists the DVI port as HDMI */
312 if ((dev->pdev->device == 0x7941) &&
313 (dev->pdev->subsystem_vendor == 0x1849) &&
314 (dev->pdev->subsystem_device == 0x7941)) {
315 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
316 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
317 *connector_type = DRM_MODE_CONNECTOR_DVID;
318 }
319
Alex Deucherf36fce02010-09-27 11:33:00 -0400320 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
321 if ((dev->pdev->device == 0x796e) &&
322 (dev->pdev->subsystem_vendor == 0x1462) &&
323 (dev->pdev->subsystem_device == 0x7302)) {
324 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
325 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
326 return false;
327 }
328
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200329 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
330 if ((dev->pdev->device == 0x7941) &&
331 (dev->pdev->subsystem_vendor == 0x147b) &&
332 (dev->pdev->subsystem_device == 0x2412)) {
333 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
334 return false;
335 }
336
337 /* Falcon NW laptop lists vga ddc line for LVDS */
338 if ((dev->pdev->device == 0x5653) &&
339 (dev->pdev->subsystem_vendor == 0x1462) &&
340 (dev->pdev->subsystem_device == 0x0291)) {
Alex Deucher848577e2009-07-08 16:15:30 -0400341 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200342 i2c_bus->valid = false;
Alex Deucher848577e2009-07-08 16:15:30 -0400343 *line_mux = 53;
344 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200345 }
346
Alex Deucher4e3f9b782009-12-01 14:49:50 -0500347 /* HIS X1300 is DVI+VGA, not DVI+DVI */
348 if ((dev->pdev->device == 0x7146) &&
349 (dev->pdev->subsystem_vendor == 0x17af) &&
350 (dev->pdev->subsystem_device == 0x2058)) {
351 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
352 return false;
353 }
354
Dave Airlieaa1a7502009-12-04 11:51:34 +1000355 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
356 if ((dev->pdev->device == 0x7142) &&
357 (dev->pdev->subsystem_vendor == 0x1458) &&
358 (dev->pdev->subsystem_device == 0x2134)) {
359 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
360 return false;
361 }
362
363
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200364 /* Funky macbooks */
365 if ((dev->pdev->device == 0x71C5) &&
366 (dev->pdev->subsystem_vendor == 0x106b) &&
367 (dev->pdev->subsystem_device == 0x0080)) {
368 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
369 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
370 return false;
Alex Deuchere1e8a5d2010-03-26 17:14:37 -0400371 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
372 *line_mux = 0x90;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200373 }
374
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200375 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
376 if ((dev->pdev->device == 0x9598) &&
377 (dev->pdev->subsystem_vendor == 0x1043) &&
378 (dev->pdev->subsystem_device == 0x01da)) {
Alex Deucher705af9c2009-09-10 16:31:13 -0400379 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400380 *connector_type = DRM_MODE_CONNECTOR_DVII;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200381 }
382 }
383
Alex Deuchere153b702010-07-20 18:07:22 -0400384 /* ASUS HD 3600 board lists the DVI port as HDMI */
385 if ((dev->pdev->device == 0x9598) &&
386 (dev->pdev->subsystem_vendor == 0x1043) &&
387 (dev->pdev->subsystem_device == 0x01e4)) {
388 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
389 *connector_type = DRM_MODE_CONNECTOR_DVII;
390 }
391 }
392
Alex Deucher705af9c2009-09-10 16:31:13 -0400393 /* ASUS HD 3450 board lists the DVI port as HDMI */
394 if ((dev->pdev->device == 0x95C5) &&
395 (dev->pdev->subsystem_vendor == 0x1043) &&
396 (dev->pdev->subsystem_device == 0x01e2)) {
397 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400398 *connector_type = DRM_MODE_CONNECTOR_DVII;
Alex Deucher705af9c2009-09-10 16:31:13 -0400399 }
400 }
401
402 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
403 * HDMI + VGA reporting as HDMI
404 */
405 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
406 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
407 *connector_type = DRM_MODE_CONNECTOR_VGA;
408 *line_mux = 0;
409 }
410 }
411
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400412 /* Acer laptop reports DVI-D as DVI-I and hpd pins reversed */
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500413 if ((dev->pdev->device == 0x95c4) &&
414 (dev->pdev->subsystem_vendor == 0x1025) &&
415 (dev->pdev->subsystem_device == 0x013c)) {
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400416 struct radeon_gpio_rec gpio;
417
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500418 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400419 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
420 gpio = radeon_lookup_gpio(rdev, 6);
421 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500422 *connector_type = DRM_MODE_CONNECTOR_DVID;
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400423 } else if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
424 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
425 gpio = radeon_lookup_gpio(rdev, 7);
426 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
427 }
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500428 }
429
Dave Airlieefa84502010-02-09 09:06:00 +1000430 /* XFX Pine Group device rv730 reports no VGA DDC lines
431 * even though they are wired up to record 0x93
432 */
433 if ((dev->pdev->device == 0x9498) &&
434 (dev->pdev->subsystem_vendor == 0x1682) &&
435 (dev->pdev->subsystem_device == 0x2452)) {
436 struct radeon_device *rdev = dev->dev_private;
437 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
438 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200439 return true;
440}
441
442const int supported_devices_connector_convert[] = {
443 DRM_MODE_CONNECTOR_Unknown,
444 DRM_MODE_CONNECTOR_VGA,
445 DRM_MODE_CONNECTOR_DVII,
446 DRM_MODE_CONNECTOR_DVID,
447 DRM_MODE_CONNECTOR_DVIA,
448 DRM_MODE_CONNECTOR_SVIDEO,
449 DRM_MODE_CONNECTOR_Composite,
450 DRM_MODE_CONNECTOR_LVDS,
451 DRM_MODE_CONNECTOR_Unknown,
452 DRM_MODE_CONNECTOR_Unknown,
453 DRM_MODE_CONNECTOR_HDMIA,
454 DRM_MODE_CONNECTOR_HDMIB,
455 DRM_MODE_CONNECTOR_Unknown,
456 DRM_MODE_CONNECTOR_Unknown,
457 DRM_MODE_CONNECTOR_9PinDIN,
458 DRM_MODE_CONNECTOR_DisplayPort
459};
460
Alex Deucherb75fad02009-11-05 13:16:01 -0500461const uint16_t supported_devices_connector_object_id_convert[] = {
462 CONNECTOR_OBJECT_ID_NONE,
463 CONNECTOR_OBJECT_ID_VGA,
464 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
465 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
466 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
467 CONNECTOR_OBJECT_ID_COMPOSITE,
468 CONNECTOR_OBJECT_ID_SVIDEO,
469 CONNECTOR_OBJECT_ID_LVDS,
470 CONNECTOR_OBJECT_ID_9PIN_DIN,
471 CONNECTOR_OBJECT_ID_9PIN_DIN,
472 CONNECTOR_OBJECT_ID_DISPLAYPORT,
473 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
474 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
475 CONNECTOR_OBJECT_ID_SVIDEO
476};
477
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200478const int object_connector_convert[] = {
479 DRM_MODE_CONNECTOR_Unknown,
480 DRM_MODE_CONNECTOR_DVII,
481 DRM_MODE_CONNECTOR_DVII,
482 DRM_MODE_CONNECTOR_DVID,
483 DRM_MODE_CONNECTOR_DVID,
484 DRM_MODE_CONNECTOR_VGA,
485 DRM_MODE_CONNECTOR_Composite,
486 DRM_MODE_CONNECTOR_SVIDEO,
487 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher705af9c2009-09-10 16:31:13 -0400488 DRM_MODE_CONNECTOR_Unknown,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200489 DRM_MODE_CONNECTOR_9PinDIN,
490 DRM_MODE_CONNECTOR_Unknown,
491 DRM_MODE_CONNECTOR_HDMIA,
492 DRM_MODE_CONNECTOR_HDMIB,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200493 DRM_MODE_CONNECTOR_LVDS,
494 DRM_MODE_CONNECTOR_9PinDIN,
495 DRM_MODE_CONNECTOR_Unknown,
496 DRM_MODE_CONNECTOR_Unknown,
497 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher196c58d2010-01-07 14:22:32 -0500498 DRM_MODE_CONNECTOR_DisplayPort,
499 DRM_MODE_CONNECTOR_eDP,
500 DRM_MODE_CONNECTOR_Unknown
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200501};
502
503bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
504{
505 struct radeon_device *rdev = dev->dev_private;
506 struct radeon_mode_info *mode_info = &rdev->mode_info;
507 struct atom_context *ctx = mode_info->atom_context;
508 int index = GetIndexIntoMasterTable(DATA, Object_Header);
Alex Deuchereed45b32009-12-04 14:45:27 -0500509 u16 size, data_offset;
510 u8 frev, crev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200511 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400512 ATOM_OBJECT_TABLE *router_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200513 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
514 ATOM_OBJECT_HEADER *obj_header;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400515 int i, j, k, path_size, device_support;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200516 int connector_type;
Alex Deuchereed45b32009-12-04 14:45:27 -0500517 u16 igp_lane_info, conn_id, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200518 struct radeon_i2c_bus_rec ddc_bus;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400519 struct radeon_router router;
Alex Deuchereed45b32009-12-04 14:45:27 -0500520 struct radeon_gpio_rec gpio;
521 struct radeon_hpd hpd;
522
Alex Deuchera084e6e2010-03-18 01:04:01 -0400523 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200524 return false;
525
526 if (crev < 2)
527 return false;
528
Alex Deucherfb939df2010-11-08 16:08:29 +0000529 router.ddc_valid = false;
530 router.cd_valid = false;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400531
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200532 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
533 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
534 (ctx->bios + data_offset +
535 le16_to_cpu(obj_header->usDisplayPathTableOffset));
536 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
537 (ctx->bios + data_offset +
538 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
Alex Deucher26b5bc92010-08-05 21:21:18 -0400539 router_obj = (ATOM_OBJECT_TABLE *)
540 (ctx->bios + data_offset +
541 le16_to_cpu(obj_header->usRouterObjectTableOffset));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200542 device_support = le16_to_cpu(obj_header->usDeviceSupport);
543
544 path_size = 0;
545 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
546 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
547 ATOM_DISPLAY_OBJECT_PATH *path;
548 addr += path_size;
549 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
550 path_size += le16_to_cpu(path->usSize);
Alex Deucher5137ee92010-08-12 18:58:47 -0400551
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200552 if (device_support & le16_to_cpu(path->usDeviceTag)) {
553 uint8_t con_obj_id, con_obj_num, con_obj_type;
554
555 con_obj_id =
556 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
557 >> OBJECT_ID_SHIFT;
558 con_obj_num =
559 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
560 >> ENUM_ID_SHIFT;
561 con_obj_type =
562 (le16_to_cpu(path->usConnObjectId) &
563 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
564
Dave Airlie4bbd4972009-09-25 08:56:12 +1000565 /* TODO CV support */
566 if (le16_to_cpu(path->usDeviceTag) ==
567 ATOM_DEVICE_CV_SUPPORT)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200568 continue;
569
Alex Deucheree59f2b2009-11-05 13:11:46 -0500570 /* IGP chips */
571 if ((rdev->flags & RADEON_IS_IGP) &&
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200572 (con_obj_id ==
573 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
574 uint16_t igp_offset = 0;
575 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
576
577 index =
578 GetIndexIntoMasterTable(DATA,
579 IntegratedSystemInfo);
580
Alex Deuchera084e6e2010-03-18 01:04:01 -0400581 if (atom_parse_data_header(ctx, index, &size, &frev,
582 &crev, &igp_offset)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200583
Alex Deuchera084e6e2010-03-18 01:04:01 -0400584 if (crev >= 2) {
585 igp_obj =
586 (ATOM_INTEGRATED_SYSTEM_INFO_V2
587 *) (ctx->bios + igp_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200588
Alex Deuchera084e6e2010-03-18 01:04:01 -0400589 if (igp_obj) {
590 uint32_t slot_config, ct;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200591
Alex Deuchera084e6e2010-03-18 01:04:01 -0400592 if (con_obj_num == 1)
593 slot_config =
594 igp_obj->
595 ulDDISlot1Config;
596 else
597 slot_config =
598 igp_obj->
599 ulDDISlot2Config;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200600
Alex Deuchera084e6e2010-03-18 01:04:01 -0400601 ct = (slot_config >> 16) & 0xff;
602 connector_type =
603 object_connector_convert
604 [ct];
605 connector_object_id = ct;
606 igp_lane_info =
607 slot_config & 0xffff;
608 } else
609 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200610 } else
611 continue;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400612 } else {
613 igp_lane_info = 0;
614 connector_type =
615 object_connector_convert[con_obj_id];
616 connector_object_id = con_obj_id;
617 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200618 } else {
619 igp_lane_info = 0;
620 connector_type =
621 object_connector_convert[con_obj_id];
Alex Deucherb75fad02009-11-05 13:16:01 -0500622 connector_object_id = con_obj_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200623 }
624
625 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
626 continue;
627
Alex Deucher26b5bc92010-08-05 21:21:18 -0400628 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
629 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200630
Alex Deucher26b5bc92010-08-05 21:21:18 -0400631 grph_obj_id =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200632 (le16_to_cpu(path->usGraphicObjIds[j]) &
633 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400634 grph_obj_num =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200635 (le16_to_cpu(path->usGraphicObjIds[j]) &
636 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400637 grph_obj_type =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200638 (le16_to_cpu(path->usGraphicObjIds[j]) &
639 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
640
Alex Deucher26b5bc92010-08-05 21:21:18 -0400641 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
Alex Deucher5137ee92010-08-12 18:58:47 -0400642 u16 encoder_obj = le16_to_cpu(path->usGraphicObjIds[j]);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200643
644 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400645 encoder_obj,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200646 le16_to_cpu
647 (path->
648 usDeviceTag));
649
Alex Deucher26b5bc92010-08-05 21:21:18 -0400650 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
Alex Deucherfb939df2010-11-08 16:08:29 +0000651 router.ddc_valid = false;
652 router.cd_valid = false;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400653 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
654 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[j].usObjectID);
655 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
656 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
657 (ctx->bios + data_offset +
658 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
659 ATOM_I2C_RECORD *i2c_record;
660 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
661 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
Alex Deucherfb939df2010-11-08 16:08:29 +0000662 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400663 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
664 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
665 (ctx->bios + data_offset +
666 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
667 int enum_id;
668
669 router.router_id = router_obj_id;
670 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
671 enum_id++) {
672 if (le16_to_cpu(path->usConnObjectId) ==
673 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
674 break;
675 }
676
677 while (record->ucRecordType > 0 &&
678 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
679 switch (record->ucRecordType) {
680 case ATOM_I2C_RECORD_TYPE:
681 i2c_record =
682 (ATOM_I2C_RECORD *)
683 record;
684 i2c_config =
685 (ATOM_I2C_ID_CONFIG_ACCESS *)
686 &i2c_record->sucI2cId;
687 router.i2c_info =
688 radeon_lookup_i2c_gpio(rdev,
689 i2c_config->
690 ucAccess);
691 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
692 break;
693 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
694 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
695 record;
Alex Deucherfb939df2010-11-08 16:08:29 +0000696 router.ddc_valid = true;
697 router.ddc_mux_type = ddc_path->ucMuxType;
698 router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
699 router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
700 break;
701 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
702 cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
703 record;
704 router.cd_valid = true;
705 router.cd_mux_type = cd_path->ucMuxType;
706 router.cd_mux_control_pin = cd_path->ucMuxControlPin;
707 router.cd_mux_state = cd_path->ucMuxState[enum_id];
Alex Deucher26b5bc92010-08-05 21:21:18 -0400708 break;
709 }
710 record = (ATOM_COMMON_RECORD_HEADER *)
711 ((char *)record + record->ucRecordSize);
712 }
713 }
714 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200715 }
716 }
717
Alex Deuchereed45b32009-12-04 14:45:27 -0500718 /* look up gpio for ddc, hpd */
Alex Deucher2bfcc0f2010-05-18 19:26:46 -0400719 ddc_bus.valid = false;
720 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200721 if ((le16_to_cpu(path->usDeviceTag) &
Alex Deuchereed45b32009-12-04 14:45:27 -0500722 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200723 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
724 if (le16_to_cpu(path->usConnObjectId) ==
725 le16_to_cpu(con_obj->asObjects[j].
726 usObjectID)) {
727 ATOM_COMMON_RECORD_HEADER
728 *record =
729 (ATOM_COMMON_RECORD_HEADER
730 *)
731 (ctx->bios + data_offset +
732 le16_to_cpu(con_obj->
733 asObjects[j].
734 usRecordOffset));
735 ATOM_I2C_RECORD *i2c_record;
Alex Deuchereed45b32009-12-04 14:45:27 -0500736 ATOM_HPD_INT_RECORD *hpd_record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500737 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500738
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200739 while (record->ucRecordType > 0
740 && record->
741 ucRecordType <=
742 ATOM_MAX_OBJECT_RECORD_NUMBER) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500743 switch (record->ucRecordType) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200744 case ATOM_I2C_RECORD_TYPE:
745 i2c_record =
Alex Deuchereed45b32009-12-04 14:45:27 -0500746 (ATOM_I2C_RECORD *)
747 record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500748 i2c_config =
749 (ATOM_I2C_ID_CONFIG_ACCESS *)
750 &i2c_record->sucI2cId;
Alex Deuchereed45b32009-12-04 14:45:27 -0500751 ddc_bus = radeon_lookup_i2c_gpio(rdev,
Alex Deucherd3f420d2009-12-08 14:30:49 -0500752 i2c_config->
753 ucAccess);
Alex Deuchereed45b32009-12-04 14:45:27 -0500754 break;
755 case ATOM_HPD_INT_RECORD_TYPE:
756 hpd_record =
757 (ATOM_HPD_INT_RECORD *)
758 record;
759 gpio = radeon_lookup_gpio(rdev,
760 hpd_record->ucHPDIntGPIOID);
761 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
762 hpd.plugged_state = hpd_record->ucPlugged_PinState;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200763 break;
764 }
765 record =
766 (ATOM_COMMON_RECORD_HEADER
767 *) ((char *)record
768 +
769 record->
770 ucRecordSize);
771 }
772 break;
773 }
774 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500775 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200776
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500777 /* needed for aux chan transactions */
Alex Deucher8e36ed02010-05-18 19:26:47 -0400778 ddc_bus.hpd = hpd.hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500779
Alex Deucher705af9c2009-09-10 16:31:13 -0400780 conn_id = le16_to_cpu(path->usConnObjectId);
781
782 if (!radeon_atom_apply_quirks
783 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500784 &ddc_bus, &conn_id, &hpd))
Alex Deucher705af9c2009-09-10 16:31:13 -0400785 continue;
786
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200787 radeon_add_atom_connector(dev,
Alex Deucher705af9c2009-09-10 16:31:13 -0400788 conn_id,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200789 le16_to_cpu(path->
790 usDeviceTag),
791 connector_type, &ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -0400792 igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -0500793 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -0400794 &hpd,
795 &router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200796
797 }
798 }
799
800 radeon_link_encoder_connector(dev);
801
802 return true;
803}
804
Alex Deucherb75fad02009-11-05 13:16:01 -0500805static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
806 int connector_type,
807 uint16_t devices)
808{
809 struct radeon_device *rdev = dev->dev_private;
810
811 if (rdev->flags & RADEON_IS_IGP) {
812 return supported_devices_connector_object_id_convert
813 [connector_type];
814 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
815 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
816 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
817 struct radeon_mode_info *mode_info = &rdev->mode_info;
818 struct atom_context *ctx = mode_info->atom_context;
819 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
820 uint16_t size, data_offset;
821 uint8_t frev, crev;
822 ATOM_XTMDS_INFO *xtmds;
823
Alex Deuchera084e6e2010-03-18 01:04:01 -0400824 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
825 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
Alex Deucherb75fad02009-11-05 13:16:01 -0500826
Alex Deuchera084e6e2010-03-18 01:04:01 -0400827 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
828 if (connector_type == DRM_MODE_CONNECTOR_DVII)
829 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
830 else
831 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
832 } else {
833 if (connector_type == DRM_MODE_CONNECTOR_DVII)
834 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
835 else
836 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
837 }
838 } else
839 return supported_devices_connector_object_id_convert
840 [connector_type];
Alex Deucherb75fad02009-11-05 13:16:01 -0500841 } else {
842 return supported_devices_connector_object_id_convert
843 [connector_type];
844 }
845}
846
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200847struct bios_connector {
848 bool valid;
Alex Deucher705af9c2009-09-10 16:31:13 -0400849 uint16_t line_mux;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200850 uint16_t devices;
851 int connector_type;
852 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500853 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200854};
855
856bool radeon_get_atom_connector_info_from_supported_devices_table(struct
857 drm_device
858 *dev)
859{
860 struct radeon_device *rdev = dev->dev_private;
861 struct radeon_mode_info *mode_info = &rdev->mode_info;
862 struct atom_context *ctx = mode_info->atom_context;
863 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
864 uint16_t size, data_offset;
865 uint8_t frev, crev;
866 uint16_t device_support;
867 uint8_t dac;
868 union atom_supported_devices *supported_devices;
Alex Deuchereed45b32009-12-04 14:45:27 -0500869 int i, j, max_device;
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000870 struct bios_connector *bios_connectors;
871 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400872 struct radeon_router router;
873
Alex Deucherfb939df2010-11-08 16:08:29 +0000874 router.ddc_valid = false;
875 router.cd_valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200876
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000877 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
878 if (!bios_connectors)
Alex Deuchera084e6e2010-03-18 01:04:01 -0400879 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200880
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000881 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
882 &data_offset)) {
883 kfree(bios_connectors);
884 return false;
885 }
886
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200887 supported_devices =
888 (union atom_supported_devices *)(ctx->bios + data_offset);
889
890 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
891
Alex Deuchereed45b32009-12-04 14:45:27 -0500892 if (frev > 1)
893 max_device = ATOM_MAX_SUPPORTED_DEVICE;
894 else
895 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
896
897 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200898 ATOM_CONNECTOR_INFO_I2C ci =
899 supported_devices->info.asConnInfo[i];
900
901 bios_connectors[i].valid = false;
902
903 if (!(device_support & (1 << i))) {
904 continue;
905 }
906
907 if (i == ATOM_DEVICE_CV_INDEX) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000908 DRM_DEBUG_KMS("Skipping Component Video\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200909 continue;
910 }
911
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200912 bios_connectors[i].connector_type =
913 supported_devices_connector_convert[ci.sucConnectorInfo.
914 sbfAccess.
915 bfConnectorType];
916
917 if (bios_connectors[i].connector_type ==
918 DRM_MODE_CONNECTOR_Unknown)
919 continue;
920
921 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
922
Alex Deucherd3f420d2009-12-08 14:30:49 -0500923 bios_connectors[i].line_mux =
924 ci.sucI2cId.ucAccess;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200925
926 /* give tv unique connector ids */
927 if (i == ATOM_DEVICE_TV1_INDEX) {
928 bios_connectors[i].ddc_bus.valid = false;
929 bios_connectors[i].line_mux = 50;
930 } else if (i == ATOM_DEVICE_TV2_INDEX) {
931 bios_connectors[i].ddc_bus.valid = false;
932 bios_connectors[i].line_mux = 51;
933 } else if (i == ATOM_DEVICE_CV_INDEX) {
934 bios_connectors[i].ddc_bus.valid = false;
935 bios_connectors[i].line_mux = 52;
936 } else
937 bios_connectors[i].ddc_bus =
Alex Deuchereed45b32009-12-04 14:45:27 -0500938 radeon_lookup_i2c_gpio(rdev,
939 bios_connectors[i].line_mux);
940
941 if ((crev > 1) && (frev > 1)) {
942 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
943 switch (isb) {
944 case 0x4:
945 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
946 break;
947 case 0xa:
948 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
949 break;
950 default:
951 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
952 break;
953 }
954 } else {
955 if (i == ATOM_DEVICE_DFP1_INDEX)
956 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
957 else if (i == ATOM_DEVICE_DFP2_INDEX)
958 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
959 else
960 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
961 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200962
963 /* Always set the connector type to VGA for CRT1/CRT2. if they are
964 * shared with a DVI port, we'll pick up the DVI connector when we
965 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
966 */
967 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
968 bios_connectors[i].connector_type =
969 DRM_MODE_CONNECTOR_VGA;
970
971 if (!radeon_atom_apply_quirks
972 (dev, (1 << i), &bios_connectors[i].connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500973 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
974 &bios_connectors[i].hpd))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200975 continue;
976
977 bios_connectors[i].valid = true;
978 bios_connectors[i].devices = (1 << i);
979
980 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
981 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400982 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200983 (1 << i),
984 dac),
985 (1 << i));
986 else
987 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400988 radeon_get_encoder_enum(dev,
Alex Deucherf56cd642009-12-18 11:28:22 -0500989 (1 << i),
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200990 dac),
991 (1 << i));
992 }
993
994 /* combine shared connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -0500995 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200996 if (bios_connectors[i].valid) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500997 for (j = 0; j < max_device; j++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200998 if (bios_connectors[j].valid && (i != j)) {
999 if (bios_connectors[i].line_mux ==
1000 bios_connectors[j].line_mux) {
Alex Deucherf56cd642009-12-18 11:28:22 -05001001 /* make sure not to combine LVDS */
1002 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1003 bios_connectors[i].line_mux = 53;
1004 bios_connectors[i].ddc_bus.valid = false;
1005 continue;
1006 }
1007 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1008 bios_connectors[j].line_mux = 53;
1009 bios_connectors[j].ddc_bus.valid = false;
1010 continue;
1011 }
1012 /* combine analog and digital for DVI-I */
1013 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1014 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
1015 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1016 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
1017 bios_connectors[i].devices |=
1018 bios_connectors[j].devices;
1019 bios_connectors[i].connector_type =
1020 DRM_MODE_CONNECTOR_DVII;
1021 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
Alex Deuchereed45b32009-12-04 14:45:27 -05001022 bios_connectors[i].hpd =
1023 bios_connectors[j].hpd;
Alex Deucherf56cd642009-12-18 11:28:22 -05001024 bios_connectors[j].valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001025 }
1026 }
1027 }
1028 }
1029 }
1030 }
1031
1032 /* add the connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -05001033 for (i = 0; i < max_device; i++) {
Alex Deucherb75fad02009-11-05 13:16:01 -05001034 if (bios_connectors[i].valid) {
1035 uint16_t connector_object_id =
1036 atombios_get_connector_object_id(dev,
1037 bios_connectors[i].connector_type,
1038 bios_connectors[i].devices);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001039 radeon_add_atom_connector(dev,
1040 bios_connectors[i].line_mux,
1041 bios_connectors[i].devices,
1042 bios_connectors[i].
1043 connector_type,
1044 &bios_connectors[i].ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -04001045 0,
Alex Deuchereed45b32009-12-04 14:45:27 -05001046 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001047 &bios_connectors[i].hpd,
1048 &router);
Alex Deucherb75fad02009-11-05 13:16:01 -05001049 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001050 }
1051
1052 radeon_link_encoder_connector(dev);
1053
Prarit Bhargavaf49d2732010-05-24 10:24:07 +10001054 kfree(bios_connectors);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001055 return true;
1056}
1057
1058union firmware_info {
1059 ATOM_FIRMWARE_INFO info;
1060 ATOM_FIRMWARE_INFO_V1_2 info_12;
1061 ATOM_FIRMWARE_INFO_V1_3 info_13;
1062 ATOM_FIRMWARE_INFO_V1_4 info_14;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001063 ATOM_FIRMWARE_INFO_V2_1 info_21;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001064};
1065
1066bool radeon_atom_get_clock_info(struct drm_device *dev)
1067{
1068 struct radeon_device *rdev = dev->dev_private;
1069 struct radeon_mode_info *mode_info = &rdev->mode_info;
1070 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1071 union firmware_info *firmware_info;
1072 uint8_t frev, crev;
1073 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1074 struct radeon_pll *p2pll = &rdev->clock.p2pll;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001075 struct radeon_pll *dcpll = &rdev->clock.dcpll;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001076 struct radeon_pll *spll = &rdev->clock.spll;
1077 struct radeon_pll *mpll = &rdev->clock.mpll;
1078 uint16_t data_offset;
1079
Alex Deuchera084e6e2010-03-18 01:04:01 -04001080 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1081 &frev, &crev, &data_offset)) {
1082 firmware_info =
1083 (union firmware_info *)(mode_info->atom_context->bios +
1084 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001085 /* pixel clocks */
1086 p1pll->reference_freq =
1087 le16_to_cpu(firmware_info->info.usReferenceClock);
1088 p1pll->reference_div = 0;
1089
Mathias Fröhlichbc293e52009-10-19 17:49:49 -04001090 if (crev < 2)
1091 p1pll->pll_out_min =
1092 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1093 else
1094 p1pll->pll_out_min =
1095 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001096 p1pll->pll_out_max =
1097 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1098
Alex Deucher86cb2bb2010-03-08 12:55:16 -05001099 if (crev >= 4) {
1100 p1pll->lcd_pll_out_min =
1101 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1102 if (p1pll->lcd_pll_out_min == 0)
1103 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1104 p1pll->lcd_pll_out_max =
1105 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1106 if (p1pll->lcd_pll_out_max == 0)
1107 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1108 } else {
1109 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1110 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1111 }
1112
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001113 if (p1pll->pll_out_min == 0) {
1114 if (ASIC_IS_AVIVO(rdev))
1115 p1pll->pll_out_min = 64800;
1116 else
1117 p1pll->pll_out_min = 20000;
Alex Deucher8f552a62009-10-27 11:16:09 -04001118 } else if (p1pll->pll_out_min > 64800) {
1119 /* Limiting the pll output range is a good thing generally as
1120 * it limits the number of possible pll combinations for a given
1121 * frequency presumably to the ones that work best on each card.
1122 * However, certain duallink DVI monitors seem to like
1123 * pll combinations that would be limited by this at least on
1124 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
1125 * family.
1126 */
Alex Deucher48dfaae2010-09-29 11:37:41 -04001127 p1pll->pll_out_min = 64800;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001128 }
1129
1130 p1pll->pll_in_min =
1131 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1132 p1pll->pll_in_max =
1133 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1134
1135 *p2pll = *p1pll;
1136
1137 /* system clock */
1138 spll->reference_freq =
1139 le16_to_cpu(firmware_info->info.usReferenceClock);
1140 spll->reference_div = 0;
1141
1142 spll->pll_out_min =
1143 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1144 spll->pll_out_max =
1145 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1146
1147 /* ??? */
1148 if (spll->pll_out_min == 0) {
1149 if (ASIC_IS_AVIVO(rdev))
1150 spll->pll_out_min = 64800;
1151 else
1152 spll->pll_out_min = 20000;
1153 }
1154
1155 spll->pll_in_min =
1156 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1157 spll->pll_in_max =
1158 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1159
1160 /* memory clock */
1161 mpll->reference_freq =
1162 le16_to_cpu(firmware_info->info.usReferenceClock);
1163 mpll->reference_div = 0;
1164
1165 mpll->pll_out_min =
1166 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1167 mpll->pll_out_max =
1168 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1169
1170 /* ??? */
1171 if (mpll->pll_out_min == 0) {
1172 if (ASIC_IS_AVIVO(rdev))
1173 mpll->pll_out_min = 64800;
1174 else
1175 mpll->pll_out_min = 20000;
1176 }
1177
1178 mpll->pll_in_min =
1179 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1180 mpll->pll_in_max =
1181 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1182
1183 rdev->clock.default_sclk =
1184 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1185 rdev->clock.default_mclk =
1186 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1187
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001188 if (ASIC_IS_DCE4(rdev)) {
1189 rdev->clock.default_dispclk =
1190 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
1191 if (rdev->clock.default_dispclk == 0)
1192 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1193 rdev->clock.dp_extclk =
1194 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
1195 }
1196 *dcpll = *p1pll;
1197
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001198 return true;
1199 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001200
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001201 return false;
1202}
1203
Alex Deucher06b64762010-01-05 11:27:29 -05001204union igp_info {
1205 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1206 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1207};
1208
1209bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1210{
1211 struct radeon_mode_info *mode_info = &rdev->mode_info;
1212 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1213 union igp_info *igp_info;
1214 u8 frev, crev;
1215 u16 data_offset;
1216
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001217 /* sideport is AMD only */
1218 if (rdev->family == CHIP_RS600)
1219 return false;
1220
Alex Deuchera084e6e2010-03-18 01:04:01 -04001221 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1222 &frev, &crev, &data_offset)) {
1223 igp_info = (union igp_info *)(mode_info->atom_context->bios +
Alex Deucher06b64762010-01-05 11:27:29 -05001224 data_offset);
Alex Deucher06b64762010-01-05 11:27:29 -05001225 switch (crev) {
1226 case 1:
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001227 if (igp_info->info.ulBootUpMemoryClock)
1228 return true;
Alex Deucher06b64762010-01-05 11:27:29 -05001229 break;
1230 case 2:
Alex Deucher4b80d952010-08-20 12:47:54 -04001231 if (igp_info->info_2.ulBootUpSidePortClock)
Alex Deucher06b64762010-01-05 11:27:29 -05001232 return true;
1233 break;
1234 default:
1235 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1236 break;
1237 }
1238 }
1239 return false;
1240}
1241
Dave Airlie445282d2009-09-09 17:40:54 +10001242bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1243 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001244{
1245 struct drm_device *dev = encoder->base.dev;
1246 struct radeon_device *rdev = dev->dev_private;
1247 struct radeon_mode_info *mode_info = &rdev->mode_info;
1248 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1249 uint16_t data_offset;
1250 struct _ATOM_TMDS_INFO *tmds_info;
1251 uint8_t frev, crev;
1252 uint16_t maxfreq;
1253 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001254
Alex Deuchera084e6e2010-03-18 01:04:01 -04001255 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1256 &frev, &crev, &data_offset)) {
1257 tmds_info =
1258 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1259 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001260
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001261 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1262 for (i = 0; i < 4; i++) {
1263 tmds->tmds_pll[i].freq =
1264 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1265 tmds->tmds_pll[i].value =
1266 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1267 tmds->tmds_pll[i].value |=
1268 (tmds_info->asMiscInfo[i].
1269 ucPLL_VCO_Gain & 0x3f) << 6;
1270 tmds->tmds_pll[i].value |=
1271 (tmds_info->asMiscInfo[i].
1272 ucPLL_DutyCycle & 0xf) << 12;
1273 tmds->tmds_pll[i].value |=
1274 (tmds_info->asMiscInfo[i].
1275 ucPLL_VoltageSwing & 0xf) << 16;
1276
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001277 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001278 tmds->tmds_pll[i].freq,
1279 tmds->tmds_pll[i].value);
1280
1281 if (maxfreq == tmds->tmds_pll[i].freq) {
1282 tmds->tmds_pll[i].freq = 0xffffffff;
1283 break;
1284 }
1285 }
Dave Airlie445282d2009-09-09 17:40:54 +10001286 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001287 }
Dave Airlie445282d2009-09-09 17:40:54 +10001288 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001289}
1290
Alex Deucherba032a52010-10-04 17:13:01 -04001291bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
1292 struct radeon_atom_ss *ss,
1293 int id)
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001294{
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001295 struct radeon_mode_info *mode_info = &rdev->mode_info;
1296 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
Alex Deucherba032a52010-10-04 17:13:01 -04001297 uint16_t data_offset, size;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001298 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1299 uint8_t frev, crev;
Alex Deucherba032a52010-10-04 17:13:01 -04001300 int i, num_indices;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001301
Alex Deucherba032a52010-10-04 17:13:01 -04001302 memset(ss, 0, sizeof(struct radeon_atom_ss));
1303 if (atom_parse_data_header(mode_info->atom_context, index, &size,
Alex Deuchera084e6e2010-03-18 01:04:01 -04001304 &frev, &crev, &data_offset)) {
1305 ss_info =
1306 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001307
Alex Deucherba032a52010-10-04 17:13:01 -04001308 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1309 sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001310
Alex Deucherba032a52010-10-04 17:13:01 -04001311 for (i = 0; i < num_indices; i++) {
Alex Deucher279b2152009-12-08 14:07:03 -05001312 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1313 ss->percentage =
1314 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1315 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1316 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1317 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1318 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1319 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
Alex Deucherba032a52010-10-04 17:13:01 -04001320 return true;
Alex Deucher279b2152009-12-08 14:07:03 -05001321 }
1322 }
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001323 }
Alex Deucherba032a52010-10-04 17:13:01 -04001324 return false;
1325}
1326
1327union asic_ss_info {
1328 struct _ATOM_ASIC_INTERNAL_SS_INFO info;
1329 struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
1330 struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
1331};
1332
1333bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
1334 struct radeon_atom_ss *ss,
1335 int id, u32 clock)
1336{
1337 struct radeon_mode_info *mode_info = &rdev->mode_info;
1338 int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
1339 uint16_t data_offset, size;
1340 union asic_ss_info *ss_info;
1341 uint8_t frev, crev;
1342 int i, num_indices;
1343
1344 memset(ss, 0, sizeof(struct radeon_atom_ss));
1345 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1346 &frev, &crev, &data_offset)) {
1347
1348 ss_info =
1349 (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
1350
1351 switch (frev) {
1352 case 1:
1353 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1354 sizeof(ATOM_ASIC_SS_ASSIGNMENT);
1355
1356 for (i = 0; i < num_indices; i++) {
1357 if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
1358 (clock <= ss_info->info.asSpreadSpectrum[i].ulTargetClockRange)) {
1359 ss->percentage =
1360 le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1361 ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1362 ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
1363 return true;
1364 }
1365 }
1366 break;
1367 case 2:
1368 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1369 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
1370 for (i = 0; i < num_indices; i++) {
1371 if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
1372 (clock <= ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange)) {
1373 ss->percentage =
1374 le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1375 ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1376 ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
1377 return true;
1378 }
1379 }
1380 break;
1381 case 3:
1382 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1383 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
1384 for (i = 0; i < num_indices; i++) {
1385 if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
1386 (clock <= ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange)) {
1387 ss->percentage =
1388 le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1389 ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1390 ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
1391 return true;
1392 }
1393 }
1394 break;
1395 default:
1396 DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
1397 break;
1398 }
1399
1400 }
1401 return false;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001402}
1403
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001404union lvds_info {
1405 struct _ATOM_LVDS_INFO info;
1406 struct _ATOM_LVDS_INFO_V12 info_12;
1407};
1408
1409struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1410 radeon_encoder
1411 *encoder)
1412{
1413 struct drm_device *dev = encoder->base.dev;
1414 struct radeon_device *rdev = dev->dev_private;
1415 struct radeon_mode_info *mode_info = &rdev->mode_info;
1416 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
Alex Deucher7dde8a192009-11-30 01:40:24 -05001417 uint16_t data_offset, misc;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001418 union lvds_info *lvds_info;
1419 uint8_t frev, crev;
1420 struct radeon_encoder_atom_dig *lvds = NULL;
Alex Deucher5137ee92010-08-12 18:58:47 -04001421 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001422
Alex Deuchera084e6e2010-03-18 01:04:01 -04001423 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1424 &frev, &crev, &data_offset)) {
1425 lvds_info =
1426 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001427 lvds =
1428 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1429
1430 if (!lvds)
1431 return NULL;
1432
Alex Deucherde2103e2009-10-09 15:14:30 -04001433 lvds->native_mode.clock =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001434 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
Alex Deucherde2103e2009-10-09 15:14:30 -04001435 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001436 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001437 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001438 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001439 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1440 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1441 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1442 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1443 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1444 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1445 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1446 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1447 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
Alex Deucher1ff26a32010-05-18 00:23:15 -04001448 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
Alex Deucherde2103e2009-10-09 15:14:30 -04001449 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1450 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001451 lvds->panel_pwr_delay =
1452 le16_to_cpu(lvds_info->info.usOffDelayInMs);
Alex Deucherba032a52010-10-04 17:13:01 -04001453 lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
Alex Deucher7dde8a192009-11-30 01:40:24 -05001454
1455 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1456 if (misc & ATOM_VSYNC_POLARITY)
1457 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1458 if (misc & ATOM_HSYNC_POLARITY)
1459 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1460 if (misc & ATOM_COMPOSITESYNC)
1461 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1462 if (misc & ATOM_INTERLACE)
1463 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1464 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1465 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1466
Alex Deucherde2103e2009-10-09 15:14:30 -04001467 /* set crtc values */
1468 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001469
Alex Deucherba032a52010-10-04 17:13:01 -04001470 lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001471
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001472 encoder->native_mode = lvds->native_mode;
Alex Deucher5137ee92010-08-12 18:58:47 -04001473
1474 if (encoder_enum == 2)
1475 lvds->linkb = true;
1476 else
1477 lvds->linkb = false;
1478
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001479 }
1480 return lvds;
1481}
1482
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001483struct radeon_encoder_primary_dac *
1484radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1485{
1486 struct drm_device *dev = encoder->base.dev;
1487 struct radeon_device *rdev = dev->dev_private;
1488 struct radeon_mode_info *mode_info = &rdev->mode_info;
1489 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1490 uint16_t data_offset;
1491 struct _COMPASSIONATE_DATA *dac_info;
1492 uint8_t frev, crev;
1493 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001494 struct radeon_encoder_primary_dac *p_dac = NULL;
1495
Alex Deuchera084e6e2010-03-18 01:04:01 -04001496 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1497 &frev, &crev, &data_offset)) {
1498 dac_info = (struct _COMPASSIONATE_DATA *)
1499 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001500
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001501 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1502
1503 if (!p_dac)
1504 return NULL;
1505
1506 bg = dac_info->ucDAC1_BG_Adjustment;
1507 dac = dac_info->ucDAC1_DAC_Adjustment;
1508 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1509
1510 }
1511 return p_dac;
1512}
1513
Dave Airlie4ce001a2009-08-13 16:32:14 +10001514bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001515 struct drm_display_mode *mode)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001516{
1517 struct radeon_mode_info *mode_info = &rdev->mode_info;
1518 ATOM_ANALOG_TV_INFO *tv_info;
1519 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1520 ATOM_DTD_FORMAT *dtd_timings;
1521 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1522 u8 frev, crev;
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001523 u16 data_offset, misc;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001524
Alex Deuchera084e6e2010-03-18 01:04:01 -04001525 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1526 &frev, &crev, &data_offset))
1527 return false;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001528
1529 switch (crev) {
1530 case 1:
1531 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001532 if (index >= MAX_SUPPORTED_TV_TIMING)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001533 return false;
1534
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001535 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1536 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1537 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1538 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1539 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001540
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001541 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1542 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1543 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1544 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1545 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001546
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001547 mode->flags = 0;
1548 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1549 if (misc & ATOM_VSYNC_POLARITY)
1550 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1551 if (misc & ATOM_HSYNC_POLARITY)
1552 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1553 if (misc & ATOM_COMPOSITESYNC)
1554 mode->flags |= DRM_MODE_FLAG_CSYNC;
1555 if (misc & ATOM_INTERLACE)
1556 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1557 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1558 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001559
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001560 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001561
1562 if (index == 1) {
1563 /* PAL timings appear to have wrong values for totals */
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001564 mode->crtc_htotal -= 1;
1565 mode->crtc_vtotal -= 1;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001566 }
1567 break;
1568 case 2:
1569 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001570 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001571 return false;
1572
1573 dtd_timings = &tv_info_v1_2->aModeTimings[index];
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001574 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1575 le16_to_cpu(dtd_timings->usHBlanking_Time);
1576 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1577 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1578 le16_to_cpu(dtd_timings->usHSyncOffset);
1579 mode->crtc_hsync_end = mode->crtc_hsync_start +
1580 le16_to_cpu(dtd_timings->usHSyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001581
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001582 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1583 le16_to_cpu(dtd_timings->usVBlanking_Time);
1584 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1585 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1586 le16_to_cpu(dtd_timings->usVSyncOffset);
1587 mode->crtc_vsync_end = mode->crtc_vsync_start +
1588 le16_to_cpu(dtd_timings->usVSyncWidth);
1589
1590 mode->flags = 0;
1591 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1592 if (misc & ATOM_VSYNC_POLARITY)
1593 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1594 if (misc & ATOM_HSYNC_POLARITY)
1595 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1596 if (misc & ATOM_COMPOSITESYNC)
1597 mode->flags |= DRM_MODE_FLAG_CSYNC;
1598 if (misc & ATOM_INTERLACE)
1599 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1600 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1601 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1602
1603 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001604 break;
1605 }
1606 return true;
1607}
1608
Alex Deucherd79766f2009-12-17 19:00:29 -05001609enum radeon_tv_std
1610radeon_atombios_get_tv_info(struct radeon_device *rdev)
1611{
1612 struct radeon_mode_info *mode_info = &rdev->mode_info;
1613 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1614 uint16_t data_offset;
1615 uint8_t frev, crev;
1616 struct _ATOM_ANALOG_TV_INFO *tv_info;
1617 enum radeon_tv_std tv_std = TV_STD_NTSC;
1618
Alex Deuchera084e6e2010-03-18 01:04:01 -04001619 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1620 &frev, &crev, &data_offset)) {
Alex Deucherd79766f2009-12-17 19:00:29 -05001621
Alex Deuchera084e6e2010-03-18 01:04:01 -04001622 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1623 (mode_info->atom_context->bios + data_offset);
Alex Deucherd79766f2009-12-17 19:00:29 -05001624
Alex Deuchera084e6e2010-03-18 01:04:01 -04001625 switch (tv_info->ucTV_BootUpDefaultStandard) {
1626 case ATOM_TV_NTSC:
1627 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001628 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001629 break;
1630 case ATOM_TV_NTSCJ:
1631 tv_std = TV_STD_NTSC_J;
Alex Deucher40f76d82010-10-07 22:38:42 -04001632 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001633 break;
1634 case ATOM_TV_PAL:
1635 tv_std = TV_STD_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -04001636 DRM_DEBUG_KMS("Default TV standard: PAL\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001637 break;
1638 case ATOM_TV_PALM:
1639 tv_std = TV_STD_PAL_M;
Alex Deucher40f76d82010-10-07 22:38:42 -04001640 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001641 break;
1642 case ATOM_TV_PALN:
1643 tv_std = TV_STD_PAL_N;
Alex Deucher40f76d82010-10-07 22:38:42 -04001644 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001645 break;
1646 case ATOM_TV_PALCN:
1647 tv_std = TV_STD_PAL_CN;
Alex Deucher40f76d82010-10-07 22:38:42 -04001648 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001649 break;
1650 case ATOM_TV_PAL60:
1651 tv_std = TV_STD_PAL_60;
Alex Deucher40f76d82010-10-07 22:38:42 -04001652 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001653 break;
1654 case ATOM_TV_SECAM:
1655 tv_std = TV_STD_SECAM;
Alex Deucher40f76d82010-10-07 22:38:42 -04001656 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001657 break;
1658 default:
1659 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001660 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001661 break;
1662 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001663 }
1664 return tv_std;
1665}
1666
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001667struct radeon_encoder_tv_dac *
1668radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1669{
1670 struct drm_device *dev = encoder->base.dev;
1671 struct radeon_device *rdev = dev->dev_private;
1672 struct radeon_mode_info *mode_info = &rdev->mode_info;
1673 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1674 uint16_t data_offset;
1675 struct _COMPASSIONATE_DATA *dac_info;
1676 uint8_t frev, crev;
1677 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001678 struct radeon_encoder_tv_dac *tv_dac = NULL;
1679
Alex Deuchera084e6e2010-03-18 01:04:01 -04001680 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1681 &frev, &crev, &data_offset)) {
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001682
Alex Deuchera084e6e2010-03-18 01:04:01 -04001683 dac_info = (struct _COMPASSIONATE_DATA *)
1684 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001685
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001686 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1687
1688 if (!tv_dac)
1689 return NULL;
1690
1691 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1692 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1693 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1694
1695 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1696 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1697 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1698
1699 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1700 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1701 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1702
Alex Deucherd79766f2009-12-17 19:00:29 -05001703 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001704 }
1705 return tv_dac;
1706}
1707
Alex Deucher29fb52c2010-03-11 10:01:17 -05001708static const char *thermal_controller_names[] = {
1709 "NONE",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001710 "lm63",
1711 "adm1032",
1712 "adm1030",
1713 "max6649",
1714 "lm64",
1715 "f75375",
1716 "asc7xxx",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001717};
1718
1719static const char *pp_lib_thermal_controller_names[] = {
1720 "NONE",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001721 "lm63",
1722 "adm1032",
1723 "adm1030",
1724 "max6649",
1725 "lm64",
1726 "f75375",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001727 "RV6xx",
1728 "RV770",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001729 "adt7473",
Alex Deucher49f65982010-03-24 16:39:45 -04001730 "External GPIO",
1731 "Evergreen",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001732 "adt7473 with internal",
Alex Deucher49f65982010-03-24 16:39:45 -04001733
Alex Deucher29fb52c2010-03-11 10:01:17 -05001734};
1735
Alex Deucher56278a82009-12-28 13:58:44 -05001736union power_info {
1737 struct _ATOM_POWERPLAY_INFO info;
1738 struct _ATOM_POWERPLAY_INFO_V2 info_2;
1739 struct _ATOM_POWERPLAY_INFO_V3 info_3;
1740 struct _ATOM_PPLIB_POWERPLAYTABLE info_4;
1741};
1742
1743void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1744{
1745 struct radeon_mode_info *mode_info = &rdev->mode_info;
1746 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
1747 u16 data_offset;
1748 u8 frev, crev;
1749 u32 misc, misc2 = 0, sclk, mclk;
1750 union power_info *power_info;
1751 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
1752 struct _ATOM_PPLIB_STATE *power_state;
1753 int num_modes = 0, i, j;
1754 int state_index = 0, mode_index = 0;
Alex Deucher29fb52c2010-03-11 10:01:17 -05001755 struct radeon_i2c_bus_rec i2c_bus;
Alex Deucher56278a82009-12-28 13:58:44 -05001756
Alex Deuchera48b9b42010-04-22 14:03:55 -04001757 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05001758
Alex Deuchera084e6e2010-03-18 01:04:01 -04001759 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1760 &frev, &crev, &data_offset)) {
1761 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
Alex Deucher56278a82009-12-28 13:58:44 -05001762 if (frev < 4) {
Alex Deucher29fb52c2010-03-11 10:01:17 -05001763 /* add the i2c bus for thermal/fan chip */
1764 if (power_info->info.ucOverdriveThermalController > 0) {
1765 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
1766 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1767 power_info->info.ucOverdriveControllerAddress >> 1);
1768 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
Alex Deucherf376b942010-08-05 21:21:16 -04001769 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001770 if (rdev->pm.i2c_bus) {
1771 struct i2c_board_info info = { };
1772 const char *name = thermal_controller_names[power_info->info.
1773 ucOverdriveThermalController];
1774 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
1775 strlcpy(info.type, name, sizeof(info.type));
1776 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
1777 }
Alex Deucher29fb52c2010-03-11 10:01:17 -05001778 }
Alex Deucher56278a82009-12-28 13:58:44 -05001779 num_modes = power_info->info.ucNumOfPowerModeEntries;
1780 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
1781 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
Alex Deucher02b17cc2010-04-22 13:25:06 -04001782 /* last mode is usually default, array is low to high */
Alex Deucher56278a82009-12-28 13:58:44 -05001783 for (i = 0; i < num_modes; i++) {
1784 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
1785 switch (frev) {
1786 case 1:
1787 rdev->pm.power_state[state_index].num_clock_modes = 1;
1788 rdev->pm.power_state[state_index].clock_info[0].mclk =
1789 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
1790 rdev->pm.power_state[state_index].clock_info[0].sclk =
1791 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
1792 /* skip invalid modes */
1793 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1794 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1795 continue;
Alex Deucher79daedc2010-04-22 14:25:19 -04001796 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05001797 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
1798 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
Alex Deucher84d88f42010-05-27 17:01:42 -04001799 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1800 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
Alex Deucher56278a82009-12-28 13:58:44 -05001801 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1802 VOLTAGE_GPIO;
1803 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1804 radeon_lookup_gpio(rdev,
1805 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
1806 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1807 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1808 true;
1809 else
1810 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1811 false;
1812 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1813 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1814 VOLTAGE_VDDC;
1815 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1816 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
1817 }
Alex Deucherd7311172010-05-03 01:13:14 -04001818 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001819 rdev->pm.power_state[state_index].misc = misc;
Alex Deucher0ec0e742009-12-23 13:21:58 -05001820 /* order matters! */
1821 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1822 rdev->pm.power_state[state_index].type =
1823 POWER_STATE_TYPE_POWERSAVE;
1824 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1825 rdev->pm.power_state[state_index].type =
1826 POWER_STATE_TYPE_BATTERY;
1827 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1828 rdev->pm.power_state[state_index].type =
1829 POWER_STATE_TYPE_BATTERY;
1830 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1831 rdev->pm.power_state[state_index].type =
1832 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001833 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001834 rdev->pm.power_state[state_index].type =
1835 POWER_STATE_TYPE_PERFORMANCE;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001836 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001837 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001838 }
Alex Deucher56278a82009-12-28 13:58:44 -05001839 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001840 rdev->pm.power_state[state_index].type =
1841 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001842 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05001843 rdev->pm.power_state[state_index].default_clock_mode =
1844 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deuchera48b9b42010-04-22 14:03:55 -04001845 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001846 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1847 } else if (state_index == 0) {
1848 rdev->pm.power_state[state_index].clock_info[0].flags |=
1849 RADEON_PM_MODE_NO_DISPLAY;
Alex Deucher56278a82009-12-28 13:58:44 -05001850 }
1851 state_index++;
1852 break;
1853 case 2:
1854 rdev->pm.power_state[state_index].num_clock_modes = 1;
1855 rdev->pm.power_state[state_index].clock_info[0].mclk =
1856 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
1857 rdev->pm.power_state[state_index].clock_info[0].sclk =
1858 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
1859 /* skip invalid modes */
1860 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1861 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1862 continue;
Alex Deucher79daedc2010-04-22 14:25:19 -04001863 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05001864 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
1865 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
1866 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
Alex Deucher84d88f42010-05-27 17:01:42 -04001867 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1868 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
Alex Deucher56278a82009-12-28 13:58:44 -05001869 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1870 VOLTAGE_GPIO;
1871 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1872 radeon_lookup_gpio(rdev,
1873 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
1874 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1875 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1876 true;
1877 else
1878 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1879 false;
1880 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1881 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1882 VOLTAGE_VDDC;
1883 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1884 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
1885 }
Alex Deucherd7311172010-05-03 01:13:14 -04001886 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001887 rdev->pm.power_state[state_index].misc = misc;
1888 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher0ec0e742009-12-23 13:21:58 -05001889 /* order matters! */
1890 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1891 rdev->pm.power_state[state_index].type =
1892 POWER_STATE_TYPE_POWERSAVE;
1893 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1894 rdev->pm.power_state[state_index].type =
1895 POWER_STATE_TYPE_BATTERY;
1896 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1897 rdev->pm.power_state[state_index].type =
1898 POWER_STATE_TYPE_BATTERY;
1899 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1900 rdev->pm.power_state[state_index].type =
1901 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001902 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001903 rdev->pm.power_state[state_index].type =
1904 POWER_STATE_TYPE_PERFORMANCE;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001905 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001906 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001907 }
Alex Deucher0ec0e742009-12-23 13:21:58 -05001908 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1909 rdev->pm.power_state[state_index].type =
1910 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001911 if (misc2 & ATOM_PM_MISCINFO2_MULTI_DISPLAY_SUPPORT)
1912 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001913 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05001914 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001915 rdev->pm.power_state[state_index].type =
1916 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001917 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05001918 rdev->pm.power_state[state_index].default_clock_mode =
1919 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deuchera48b9b42010-04-22 14:03:55 -04001920 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001921 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1922 } else if (state_index == 0) {
1923 rdev->pm.power_state[state_index].clock_info[0].flags |=
1924 RADEON_PM_MODE_NO_DISPLAY;
Alex Deucher56278a82009-12-28 13:58:44 -05001925 }
1926 state_index++;
1927 break;
1928 case 3:
1929 rdev->pm.power_state[state_index].num_clock_modes = 1;
1930 rdev->pm.power_state[state_index].clock_info[0].mclk =
1931 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
1932 rdev->pm.power_state[state_index].clock_info[0].sclk =
1933 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
1934 /* skip invalid modes */
1935 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1936 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1937 continue;
Alex Deucher79daedc2010-04-22 14:25:19 -04001938 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05001939 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
1940 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
1941 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
Alex Deucher84d88f42010-05-27 17:01:42 -04001942 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1943 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
Alex Deucher56278a82009-12-28 13:58:44 -05001944 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1945 VOLTAGE_GPIO;
1946 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1947 radeon_lookup_gpio(rdev,
1948 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
1949 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1950 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1951 true;
1952 else
1953 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1954 false;
1955 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1956 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1957 VOLTAGE_VDDC;
1958 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1959 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
1960 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
1961 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
1962 true;
1963 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
1964 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
1965 }
1966 }
Alex Deucherd7311172010-05-03 01:13:14 -04001967 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001968 rdev->pm.power_state[state_index].misc = misc;
1969 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher0ec0e742009-12-23 13:21:58 -05001970 /* order matters! */
1971 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1972 rdev->pm.power_state[state_index].type =
1973 POWER_STATE_TYPE_POWERSAVE;
1974 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1975 rdev->pm.power_state[state_index].type =
1976 POWER_STATE_TYPE_BATTERY;
1977 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1978 rdev->pm.power_state[state_index].type =
1979 POWER_STATE_TYPE_BATTERY;
1980 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1981 rdev->pm.power_state[state_index].type =
1982 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001983 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001984 rdev->pm.power_state[state_index].type =
1985 POWER_STATE_TYPE_PERFORMANCE;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001986 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001987 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001988 }
Alex Deucher0ec0e742009-12-23 13:21:58 -05001989 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1990 rdev->pm.power_state[state_index].type =
1991 POWER_STATE_TYPE_BALANCED;
Alex Deucher56278a82009-12-28 13:58:44 -05001992 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001993 rdev->pm.power_state[state_index].type =
1994 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001995 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05001996 rdev->pm.power_state[state_index].default_clock_mode =
1997 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucherd7311172010-05-03 01:13:14 -04001998 } else if (state_index == 0) {
1999 rdev->pm.power_state[state_index].clock_info[0].flags |=
2000 RADEON_PM_MODE_NO_DISPLAY;
Alex Deucher56278a82009-12-28 13:58:44 -05002001 }
2002 state_index++;
2003 break;
2004 }
2005 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002006 /* last mode is usually default */
Alex Deuchera48b9b42010-04-22 14:03:55 -04002007 if (rdev->pm.default_power_state_index == -1) {
Alex Deucher02b17cc2010-04-22 13:25:06 -04002008 rdev->pm.power_state[state_index - 1].type =
2009 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002010 rdev->pm.default_power_state_index = state_index - 1;
Alex Deucher02b17cc2010-04-22 13:25:06 -04002011 rdev->pm.power_state[state_index - 1].default_clock_mode =
2012 &rdev->pm.power_state[state_index - 1].clock_info[0];
Alex Deuchera48b9b42010-04-22 14:03:55 -04002013 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04002014 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04002015 rdev->pm.power_state[state_index].misc = 0;
2016 rdev->pm.power_state[state_index].misc2 = 0;
Alex Deucher02b17cc2010-04-22 13:25:06 -04002017 }
Alex Deucher49f65982010-03-24 16:39:45 -04002018 } else {
Alex Deucherc5e8ce62010-05-27 17:01:40 -04002019 int fw_index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
2020 uint8_t fw_frev, fw_crev;
2021 uint16_t fw_data_offset, vddc = 0;
2022 union firmware_info *firmware_info;
2023 ATOM_PPLIB_THERMALCONTROLLER *controller = &power_info->info_4.sThermalController;
2024
2025 if (atom_parse_data_header(mode_info->atom_context, fw_index, NULL,
2026 &fw_frev, &fw_crev, &fw_data_offset)) {
2027 firmware_info =
2028 (union firmware_info *)(mode_info->atom_context->bios +
2029 fw_data_offset);
2030 vddc = firmware_info->info_14.usBootUpVDDCVoltage;
2031 }
2032
Alex Deucher29fb52c2010-03-11 10:01:17 -05002033 /* add the i2c bus for thermal/fan chip */
Alex Deucher678e7dfa2010-04-22 14:17:56 -04002034 if (controller->ucType > 0) {
Alex Deucher21a81222010-07-02 12:58:16 -04002035 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
Alex Deucher29fb52c2010-03-11 10:01:17 -05002036 DRM_INFO("Internal thermal controller %s fan control\n",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04002037 (controller->ucFanParameters &
Alex Deucher29fb52c2010-03-11 10:01:17 -05002038 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
Alex Deucher21a81222010-07-02 12:58:16 -04002039 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
2040 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
2041 DRM_INFO("Internal thermal controller %s fan control\n",
2042 (controller->ucFanParameters &
2043 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2044 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
2045 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
2046 DRM_INFO("Internal thermal controller %s fan control\n",
2047 (controller->ucFanParameters &
2048 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2049 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
Alex Deucher678e7dfa2010-04-22 14:17:56 -04002050 } else if ((controller->ucType ==
Alex Deucher49f65982010-03-24 16:39:45 -04002051 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
Alex Deucher678e7dfa2010-04-22 14:17:56 -04002052 (controller->ucType ==
Alex Deucher49f65982010-03-24 16:39:45 -04002053 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL)) {
2054 DRM_INFO("Special thermal controller config\n");
Alex Deucher29fb52c2010-03-11 10:01:17 -05002055 } else {
2056 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04002057 pp_lib_thermal_controller_names[controller->ucType],
2058 controller->ucI2cAddress >> 1,
2059 (controller->ucFanParameters &
Alex Deucher29fb52c2010-03-11 10:01:17 -05002060 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
Alex Deucher678e7dfa2010-04-22 14:17:56 -04002061 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
Alex Deucherf376b942010-08-05 21:21:16 -04002062 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucher678e7dfa2010-04-22 14:17:56 -04002063 if (rdev->pm.i2c_bus) {
2064 struct i2c_board_info info = { };
2065 const char *name = pp_lib_thermal_controller_names[controller->ucType];
2066 info.addr = controller->ucI2cAddress >> 1;
2067 strlcpy(info.type, name, sizeof(info.type));
2068 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2069 }
2070
Alex Deucher29fb52c2010-03-11 10:01:17 -05002071 }
2072 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002073 /* first mode is usually default, followed by low to high */
Alex Deucher56278a82009-12-28 13:58:44 -05002074 for (i = 0; i < power_info->info_4.ucNumStates; i++) {
2075 mode_index = 0;
2076 power_state = (struct _ATOM_PPLIB_STATE *)
2077 (mode_info->atom_context->bios +
2078 data_offset +
2079 le16_to_cpu(power_info->info_4.usStateArrayOffset) +
2080 i * power_info->info_4.ucStateEntrySize);
2081 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2082 (mode_info->atom_context->bios +
2083 data_offset +
2084 le16_to_cpu(power_info->info_4.usNonClockInfoArrayOffset) +
2085 (power_state->ucNonClockStateIndex *
2086 power_info->info_4.ucNonClockSize));
Alex Deucher56278a82009-12-28 13:58:44 -05002087 for (j = 0; j < (power_info->info_4.ucStateEntrySize - 1); j++) {
2088 if (rdev->flags & RADEON_IS_IGP) {
2089 struct _ATOM_PPLIB_RS780_CLOCK_INFO *clock_info =
2090 (struct _ATOM_PPLIB_RS780_CLOCK_INFO *)
2091 (mode_info->atom_context->bios +
2092 data_offset +
2093 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2094 (power_state->ucClockStateIndices[j] *
2095 power_info->info_4.ucClockInfoSize));
2096 sclk = le16_to_cpu(clock_info->usLowEngineClockLow);
2097 sclk |= clock_info->ucLowEngineClockHigh << 16;
2098 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2099 /* skip invalid modes */
2100 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2101 continue;
Alex Deucheraa1df0f2010-06-07 11:35:53 -04002102 /* voltage works differently on IGPs */
Alex Deucher56278a82009-12-28 13:58:44 -05002103 mode_index++;
Alex Deucher49f65982010-03-24 16:39:45 -04002104 } else if (ASIC_IS_DCE4(rdev)) {
2105 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *clock_info =
2106 (struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *)
2107 (mode_info->atom_context->bios +
2108 data_offset +
2109 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2110 (power_state->ucClockStateIndices[j] *
2111 power_info->info_4.ucClockInfoSize));
2112 sclk = le16_to_cpu(clock_info->usEngineClockLow);
2113 sclk |= clock_info->ucEngineClockHigh << 16;
2114 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
2115 mclk |= clock_info->ucMemoryClockHigh << 16;
2116 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2117 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2118 /* skip invalid modes */
2119 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2120 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2121 continue;
Alex Deucher49f65982010-03-24 16:39:45 -04002122 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2123 VOLTAGE_SW;
2124 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2125 clock_info->usVDDC;
2126 /* XXX usVDDCI */
2127 mode_index++;
Alex Deucher56278a82009-12-28 13:58:44 -05002128 } else {
2129 struct _ATOM_PPLIB_R600_CLOCK_INFO *clock_info =
2130 (struct _ATOM_PPLIB_R600_CLOCK_INFO *)
2131 (mode_info->atom_context->bios +
2132 data_offset +
2133 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2134 (power_state->ucClockStateIndices[j] *
2135 power_info->info_4.ucClockInfoSize));
2136 sclk = le16_to_cpu(clock_info->usEngineClockLow);
2137 sclk |= clock_info->ucEngineClockHigh << 16;
2138 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
2139 mclk |= clock_info->ucMemoryClockHigh << 16;
2140 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2141 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2142 /* skip invalid modes */
2143 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2144 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2145 continue;
Alex Deucher56278a82009-12-28 13:58:44 -05002146 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2147 VOLTAGE_SW;
2148 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2149 clock_info->usVDDC;
2150 mode_index++;
2151 }
2152 }
2153 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2154 if (mode_index) {
Rafał Miłecki845db702009-12-23 00:42:43 +01002155 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
Alex Deucher56278a82009-12-28 13:58:44 -05002156 misc2 = le16_to_cpu(non_clock_info->usClassification);
Alex Deucher79daedc2010-04-22 14:25:19 -04002157 rdev->pm.power_state[state_index].misc = misc;
2158 rdev->pm.power_state[state_index].misc2 = misc2;
2159 rdev->pm.power_state[state_index].pcie_lanes =
Rafał Miłecki845db702009-12-23 00:42:43 +01002160 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2161 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002162 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2163 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2164 rdev->pm.power_state[state_index].type =
2165 POWER_STATE_TYPE_BATTERY;
2166 break;
2167 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2168 rdev->pm.power_state[state_index].type =
2169 POWER_STATE_TYPE_BALANCED;
2170 break;
2171 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2172 rdev->pm.power_state[state_index].type =
2173 POWER_STATE_TYPE_PERFORMANCE;
2174 break;
Alex Deuchera44d2f32010-08-04 11:10:26 -04002175 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2176 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2177 rdev->pm.power_state[state_index].type =
2178 POWER_STATE_TYPE_PERFORMANCE;
2179 break;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002180 }
Alex Deuchera48b9b42010-04-22 14:03:55 -04002181 rdev->pm.power_state[state_index].flags = 0;
2182 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2183 rdev->pm.power_state[state_index].flags |=
Alex Deucherd7311172010-05-03 01:13:14 -04002184 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05002185 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05002186 rdev->pm.power_state[state_index].type =
2187 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002188 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05002189 rdev->pm.power_state[state_index].default_clock_mode =
2190 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
Alex Deucherc5e8ce62010-05-27 17:01:40 -04002191 /* patch the table values with the default slck/mclk from firmware info */
2192 for (j = 0; j < mode_index; j++) {
2193 rdev->pm.power_state[state_index].clock_info[j].mclk =
2194 rdev->clock.default_mclk;
2195 rdev->pm.power_state[state_index].clock_info[j].sclk =
2196 rdev->clock.default_sclk;
2197 if (vddc)
2198 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2199 vddc;
2200 }
Alex Deucher56278a82009-12-28 13:58:44 -05002201 }
2202 state_index++;
2203 }
2204 }
Alex Deucherd7311172010-05-03 01:13:14 -04002205 /* if multiple clock modes, mark the lowest as no display */
2206 for (i = 0; i < state_index; i++) {
2207 if (rdev->pm.power_state[i].num_clock_modes > 1)
2208 rdev->pm.power_state[i].clock_info[0].flags |=
2209 RADEON_PM_MODE_NO_DISPLAY;
2210 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002211 /* first mode is usually default */
Alex Deuchera48b9b42010-04-22 14:03:55 -04002212 if (rdev->pm.default_power_state_index == -1) {
Alex Deucher02b17cc2010-04-22 13:25:06 -04002213 rdev->pm.power_state[0].type =
2214 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002215 rdev->pm.default_power_state_index = 0;
Alex Deucher02b17cc2010-04-22 13:25:06 -04002216 rdev->pm.power_state[0].default_clock_mode =
2217 &rdev->pm.power_state[0].clock_info[0];
2218 }
Alex Deucher56278a82009-12-28 13:58:44 -05002219 }
2220 } else {
Alex Deucher56278a82009-12-28 13:58:44 -05002221 /* add the default mode */
Alex Deucher0ec0e742009-12-23 13:21:58 -05002222 rdev->pm.power_state[state_index].type =
2223 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05002224 rdev->pm.power_state[state_index].num_clock_modes = 1;
2225 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2226 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2227 rdev->pm.power_state[state_index].default_clock_mode =
2228 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucher56278a82009-12-28 13:58:44 -05002229 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
Alex Deucher79daedc2010-04-22 14:25:19 -04002230 rdev->pm.power_state[state_index].pcie_lanes = 16;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002231 rdev->pm.default_power_state_index = state_index;
2232 rdev->pm.power_state[state_index].flags = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002233 state_index++;
2234 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002235
Alex Deucher56278a82009-12-28 13:58:44 -05002236 rdev->pm.num_power_states = state_index;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002237
Alex Deuchera48b9b42010-04-22 14:03:55 -04002238 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2239 rdev->pm.current_clock_mode_index = 0;
Alex Deucher4d601732010-06-07 18:15:18 -04002240 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 -05002241}
2242
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002243void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2244{
2245 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2246 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2247
2248 args.ucEnable = enable;
2249
2250 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2251}
2252
Rafał Miłecki74338742009-11-03 00:53:02 +01002253uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2254{
2255 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2256 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2257
2258 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2259 return args.ulReturnEngineClock;
2260}
2261
2262uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2263{
2264 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2265 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2266
2267 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2268 return args.ulReturnMemoryClock;
2269}
2270
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002271void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2272 uint32_t eng_clock)
2273{
2274 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2275 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2276
2277 args.ulTargetEngineClock = eng_clock; /* 10 khz */
2278
2279 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2280}
2281
2282void radeon_atom_set_memory_clock(struct radeon_device *rdev,
2283 uint32_t mem_clock)
2284{
2285 SET_MEMORY_CLOCK_PS_ALLOCATION args;
2286 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
2287
2288 if (rdev->flags & RADEON_IS_IGP)
2289 return;
2290
2291 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
2292
2293 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2294}
2295
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002296union set_voltage {
2297 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2298 struct _SET_VOLTAGE_PARAMETERS v1;
2299 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2300};
2301
2302void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level)
2303{
2304 union set_voltage args;
2305 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
2306 u8 frev, crev, volt_index = level;
2307
2308 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2309 return;
2310
2311 switch (crev) {
2312 case 1:
2313 args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2314 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
2315 args.v1.ucVoltageIndex = volt_index;
2316 break;
2317 case 2:
2318 args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2319 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
2320 args.v2.usVoltageLevel = cpu_to_le16(level);
2321 break;
2322 default:
2323 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2324 return;
2325 }
2326
2327 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2328}
2329
2330
2331
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002332void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
2333{
2334 struct radeon_device *rdev = dev->dev_private;
2335 uint32_t bios_2_scratch, bios_6_scratch;
2336
2337 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002338 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002339 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2340 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002341 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002342 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2343 }
2344
2345 /* let the bios control the backlight */
2346 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
2347
2348 /* tell the bios not to handle mode switching */
2349 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
2350
2351 if (rdev->family >= CHIP_R600) {
2352 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2353 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2354 } else {
2355 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2356 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2357 }
2358
2359}
2360
Yang Zhaof657c2a2009-09-15 12:21:01 +10002361void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
2362{
2363 uint32_t scratch_reg;
2364 int i;
2365
2366 if (rdev->family >= CHIP_R600)
2367 scratch_reg = R600_BIOS_0_SCRATCH;
2368 else
2369 scratch_reg = RADEON_BIOS_0_SCRATCH;
2370
2371 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2372 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
2373}
2374
2375void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
2376{
2377 uint32_t scratch_reg;
2378 int i;
2379
2380 if (rdev->family >= CHIP_R600)
2381 scratch_reg = R600_BIOS_0_SCRATCH;
2382 else
2383 scratch_reg = RADEON_BIOS_0_SCRATCH;
2384
2385 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2386 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
2387}
2388
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002389void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
2390{
2391 struct drm_device *dev = encoder->dev;
2392 struct radeon_device *rdev = dev->dev_private;
2393 uint32_t bios_6_scratch;
2394
2395 if (rdev->family >= CHIP_R600)
2396 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2397 else
2398 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2399
2400 if (lock)
2401 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
2402 else
2403 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
2404
2405 if (rdev->family >= CHIP_R600)
2406 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2407 else
2408 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2409}
2410
2411/* at some point we may want to break this out into individual functions */
2412void
2413radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
2414 struct drm_encoder *encoder,
2415 bool connected)
2416{
2417 struct drm_device *dev = connector->dev;
2418 struct radeon_device *rdev = dev->dev_private;
2419 struct radeon_connector *radeon_connector =
2420 to_radeon_connector(connector);
2421 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2422 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
2423
2424 if (rdev->family >= CHIP_R600) {
2425 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2426 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2427 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2428 } else {
2429 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2430 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2431 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2432 }
2433
2434 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
2435 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
2436 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002437 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002438 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
2439 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
2440 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002441 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002442 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
2443 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
2444 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
2445 }
2446 }
2447 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
2448 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
2449 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002450 DRM_DEBUG_KMS("CV connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002451 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
2452 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
2453 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002454 DRM_DEBUG_KMS("CV disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002455 bios_0_scratch &= ~ATOM_S0_CV_MASK;
2456 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
2457 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
2458 }
2459 }
2460 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
2461 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
2462 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002463 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002464 bios_0_scratch |= ATOM_S0_LCD1;
2465 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
2466 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
2467 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002468 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002469 bios_0_scratch &= ~ATOM_S0_LCD1;
2470 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
2471 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
2472 }
2473 }
2474 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
2475 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
2476 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002477 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002478 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
2479 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
2480 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
2481 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002482 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002483 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
2484 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
2485 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
2486 }
2487 }
2488 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
2489 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
2490 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002491 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002492 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
2493 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
2494 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
2495 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002496 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002497 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
2498 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
2499 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
2500 }
2501 }
2502 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
2503 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
2504 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002505 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002506 bios_0_scratch |= ATOM_S0_DFP1;
2507 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
2508 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
2509 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002510 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002511 bios_0_scratch &= ~ATOM_S0_DFP1;
2512 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
2513 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
2514 }
2515 }
2516 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
2517 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
2518 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002519 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002520 bios_0_scratch |= ATOM_S0_DFP2;
2521 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
2522 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
2523 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002524 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002525 bios_0_scratch &= ~ATOM_S0_DFP2;
2526 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
2527 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
2528 }
2529 }
2530 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
2531 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
2532 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002533 DRM_DEBUG_KMS("DFP3 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002534 bios_0_scratch |= ATOM_S0_DFP3;
2535 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
2536 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
2537 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002538 DRM_DEBUG_KMS("DFP3 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002539 bios_0_scratch &= ~ATOM_S0_DFP3;
2540 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
2541 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
2542 }
2543 }
2544 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
2545 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
2546 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002547 DRM_DEBUG_KMS("DFP4 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002548 bios_0_scratch |= ATOM_S0_DFP4;
2549 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
2550 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
2551 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002552 DRM_DEBUG_KMS("DFP4 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002553 bios_0_scratch &= ~ATOM_S0_DFP4;
2554 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
2555 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
2556 }
2557 }
2558 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
2559 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
2560 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002561 DRM_DEBUG_KMS("DFP5 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002562 bios_0_scratch |= ATOM_S0_DFP5;
2563 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
2564 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
2565 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002566 DRM_DEBUG_KMS("DFP5 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002567 bios_0_scratch &= ~ATOM_S0_DFP5;
2568 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2569 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2570 }
2571 }
2572
2573 if (rdev->family >= CHIP_R600) {
2574 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2575 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2576 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2577 } else {
2578 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
2579 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2580 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2581 }
2582}
2583
2584void
2585radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
2586{
2587 struct drm_device *dev = encoder->dev;
2588 struct radeon_device *rdev = dev->dev_private;
2589 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2590 uint32_t bios_3_scratch;
2591
2592 if (rdev->family >= CHIP_R600)
2593 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2594 else
2595 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2596
2597 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2598 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
2599 bios_3_scratch |= (crtc << 18);
2600 }
2601 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2602 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
2603 bios_3_scratch |= (crtc << 24);
2604 }
2605 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2606 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
2607 bios_3_scratch |= (crtc << 16);
2608 }
2609 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2610 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
2611 bios_3_scratch |= (crtc << 20);
2612 }
2613 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2614 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
2615 bios_3_scratch |= (crtc << 17);
2616 }
2617 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2618 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
2619 bios_3_scratch |= (crtc << 19);
2620 }
2621 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2622 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
2623 bios_3_scratch |= (crtc << 23);
2624 }
2625 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2626 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
2627 bios_3_scratch |= (crtc << 25);
2628 }
2629
2630 if (rdev->family >= CHIP_R600)
2631 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2632 else
2633 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2634}
2635
2636void
2637radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
2638{
2639 struct drm_device *dev = encoder->dev;
2640 struct radeon_device *rdev = dev->dev_private;
2641 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2642 uint32_t bios_2_scratch;
2643
2644 if (rdev->family >= CHIP_R600)
2645 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2646 else
2647 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
2648
2649 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2650 if (on)
2651 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
2652 else
2653 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
2654 }
2655 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2656 if (on)
2657 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
2658 else
2659 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
2660 }
2661 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2662 if (on)
2663 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
2664 else
2665 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
2666 }
2667 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2668 if (on)
2669 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
2670 else
2671 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
2672 }
2673 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2674 if (on)
2675 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
2676 else
2677 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
2678 }
2679 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2680 if (on)
2681 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
2682 else
2683 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
2684 }
2685 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2686 if (on)
2687 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
2688 else
2689 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
2690 }
2691 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2692 if (on)
2693 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
2694 else
2695 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
2696 }
2697 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
2698 if (on)
2699 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
2700 else
2701 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
2702 }
2703 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
2704 if (on)
2705 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
2706 else
2707 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
2708 }
2709
2710 if (rdev->family >= CHIP_R600)
2711 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2712 else
2713 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2714}