blob: 933a2cd7bb5583820b45d9b37b5820468b97923a [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,
Alex Deucher36868bd2011-01-06 21:19:21 -050040 uint32_t supported_device, u16 caps);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020041
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
Andi Kleence580fa2011-10-13 16:08:47 -070065static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
Alex Deuchereed45b32009-12-04 14:45:27 -050066 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 Deucher6c47e5c2011-11-14 14:32:01 -050088 /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
89 if ((rdev->family == CHIP_R420) ||
90 (rdev->family == CHIP_R423) ||
91 (rdev->family == CHIP_RV410)) {
92 if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
93 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
94 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
95 gpio->ucClkMaskShift = 0x19;
96 gpio->ucDataMaskShift = 0x18;
97 }
98 }
99
Alex Deucherea393022010-08-27 16:04:29 -0400100 /* some evergreen boards have bad data for this entry */
101 if (ASIC_IS_DCE4(rdev)) {
102 if ((i == 7) &&
Cédric Cano45894332011-02-11 19:45:37 -0500103 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
Alex Deucherea393022010-08-27 16:04:29 -0400104 (gpio->sucI2cId.ucAccess == 0)) {
105 gpio->sucI2cId.ucAccess = 0x97;
106 gpio->ucDataMaskShift = 8;
107 gpio->ucDataEnShift = 8;
108 gpio->ucDataY_Shift = 8;
109 gpio->ucDataA_Shift = 8;
110 }
111 }
112
Alex Deucher3074adc2010-11-30 00:15:10 -0500113 /* some DCE3 boards have bad data for this entry */
114 if (ASIC_IS_DCE3(rdev)) {
115 if ((i == 4) &&
Cédric Cano45894332011-02-11 19:45:37 -0500116 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
Alex Deucher3074adc2010-11-30 00:15:10 -0500117 (gpio->sucI2cId.ucAccess == 0x94))
118 gpio->sucI2cId.ucAccess = 0x14;
119 }
120
Alex Deuchera084e6e2010-03-18 01:04:01 -0400121 if (gpio->sucI2cId.ucAccess == id) {
122 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
123 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
124 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
125 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
126 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
127 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
128 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
129 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
130 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
131 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
132 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
133 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
134 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
135 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
136 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
137 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200138
Alex Deuchera084e6e2010-03-18 01:04:01 -0400139 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
140 i2c.hw_capable = true;
141 else
142 i2c.hw_capable = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500143
Alex Deuchera084e6e2010-03-18 01:04:01 -0400144 if (gpio->sucI2cId.ucAccess == 0xa0)
145 i2c.mm_i2c = true;
146 else
147 i2c.mm_i2c = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500148
Alex Deuchera084e6e2010-03-18 01:04:01 -0400149 i2c.i2c_id = gpio->sucI2cId.ucAccess;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500150
Alex Deucherf376b942010-08-05 21:21:16 -0400151 if (i2c.mask_clk_reg)
152 i2c.valid = true;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400153 break;
154 }
Alex Deucherd3f420d2009-12-08 14:30:49 -0500155 }
156 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200157
158 return i2c;
159}
160
Alex Deucherf376b942010-08-05 21:21:16 -0400161void radeon_atombios_i2c_init(struct radeon_device *rdev)
162{
163 struct atom_context *ctx = rdev->mode_info.atom_context;
164 ATOM_GPIO_I2C_ASSIGMENT *gpio;
165 struct radeon_i2c_bus_rec i2c;
166 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
167 struct _ATOM_GPIO_I2C_INFO *i2c_info;
168 uint16_t data_offset, size;
169 int i, num_indices;
170 char stmp[32];
171
172 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
173
174 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
175 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
176
177 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
178 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
179
180 for (i = 0; i < num_indices; i++) {
181 gpio = &i2c_info->asGPIO_Info[i];
182 i2c.valid = false;
Alex Deucherea393022010-08-27 16:04:29 -0400183
Alex Deucherd7245022011-11-21 12:10:14 -0500184 /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
185 if ((rdev->family == CHIP_R420) ||
186 (rdev->family == CHIP_R423) ||
187 (rdev->family == CHIP_RV410)) {
188 if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
189 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
190 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
191 gpio->ucClkMaskShift = 0x19;
192 gpio->ucDataMaskShift = 0x18;
193 }
194 }
195
Alex Deucherea393022010-08-27 16:04:29 -0400196 /* some evergreen boards have bad data for this entry */
197 if (ASIC_IS_DCE4(rdev)) {
198 if ((i == 7) &&
Cédric Cano45894332011-02-11 19:45:37 -0500199 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
Alex Deucherea393022010-08-27 16:04:29 -0400200 (gpio->sucI2cId.ucAccess == 0)) {
201 gpio->sucI2cId.ucAccess = 0x97;
202 gpio->ucDataMaskShift = 8;
203 gpio->ucDataEnShift = 8;
204 gpio->ucDataY_Shift = 8;
205 gpio->ucDataA_Shift = 8;
206 }
207 }
208
Alex Deucher3074adc2010-11-30 00:15:10 -0500209 /* some DCE3 boards have bad data for this entry */
210 if (ASIC_IS_DCE3(rdev)) {
211 if ((i == 4) &&
Cédric Cano45894332011-02-11 19:45:37 -0500212 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
Alex Deucher3074adc2010-11-30 00:15:10 -0500213 (gpio->sucI2cId.ucAccess == 0x94))
214 gpio->sucI2cId.ucAccess = 0x14;
215 }
216
Alex Deucherf376b942010-08-05 21:21:16 -0400217 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
218 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
219 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
220 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
221 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
222 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
223 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
224 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
225 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
226 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
227 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
228 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
229 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
230 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
231 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
232 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
233
234 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
235 i2c.hw_capable = true;
236 else
237 i2c.hw_capable = false;
238
239 if (gpio->sucI2cId.ucAccess == 0xa0)
240 i2c.mm_i2c = true;
241 else
242 i2c.mm_i2c = false;
243
244 i2c.i2c_id = gpio->sucI2cId.ucAccess;
245
246 if (i2c.mask_clk_reg) {
247 i2c.valid = true;
248 sprintf(stmp, "0x%x", i2c.i2c_id);
249 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
250 }
251 }
252 }
253}
254
Andi Kleence580fa2011-10-13 16:08:47 -0700255static struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
Alex Deuchereed45b32009-12-04 14:45:27 -0500256 u8 id)
257{
258 struct atom_context *ctx = rdev->mode_info.atom_context;
259 struct radeon_gpio_rec gpio;
260 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
261 struct _ATOM_GPIO_PIN_LUT *gpio_info;
262 ATOM_GPIO_PIN_ASSIGNMENT *pin;
263 u16 data_offset, size;
264 int i, num_indices;
265
266 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
267 gpio.valid = false;
268
Alex Deuchera084e6e2010-03-18 01:04:01 -0400269 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
270 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
Alex Deuchereed45b32009-12-04 14:45:27 -0500271
Alex Deuchera084e6e2010-03-18 01:04:01 -0400272 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
273 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
Alex Deuchereed45b32009-12-04 14:45:27 -0500274
Alex Deuchera084e6e2010-03-18 01:04:01 -0400275 for (i = 0; i < num_indices; i++) {
276 pin = &gpio_info->asGPIO_Pin[i];
277 if (id == pin->ucGPIO_ID) {
278 gpio.id = pin->ucGPIO_ID;
Cédric Cano45894332011-02-11 19:45:37 -0500279 gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex) * 4;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400280 gpio.mask = (1 << pin->ucGpioPinBitShift);
281 gpio.valid = true;
282 break;
283 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500284 }
285 }
286
287 return gpio;
288}
289
290static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
291 struct radeon_gpio_rec *gpio)
292{
293 struct radeon_hpd hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500294 u32 reg;
295
Jean Delvare1d978da2010-08-15 14:11:24 +0200296 memset(&hpd, 0, sizeof(struct radeon_hpd));
297
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500298 if (ASIC_IS_DCE4(rdev))
299 reg = EVERGREEN_DC_GPIO_HPD_A;
300 else
301 reg = AVIVO_DC_GPIO_HPD_A;
302
Alex Deuchereed45b32009-12-04 14:45:27 -0500303 hpd.gpio = *gpio;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500304 if (gpio->reg == reg) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500305 switch(gpio->mask) {
306 case (1 << 0):
307 hpd.hpd = RADEON_HPD_1;
308 break;
309 case (1 << 8):
310 hpd.hpd = RADEON_HPD_2;
311 break;
312 case (1 << 16):
313 hpd.hpd = RADEON_HPD_3;
314 break;
315 case (1 << 24):
316 hpd.hpd = RADEON_HPD_4;
317 break;
318 case (1 << 26):
319 hpd.hpd = RADEON_HPD_5;
320 break;
321 case (1 << 28):
322 hpd.hpd = RADEON_HPD_6;
323 break;
324 default:
325 hpd.hpd = RADEON_HPD_NONE;
326 break;
327 }
328 } else
329 hpd.hpd = RADEON_HPD_NONE;
330 return hpd;
331}
332
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200333static bool radeon_atom_apply_quirks(struct drm_device *dev,
334 uint32_t supported_device,
335 int *connector_type,
Alex Deucher848577e2009-07-08 16:15:30 -0400336 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -0500337 uint16_t *line_mux,
338 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200339{
340
341 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
342 if ((dev->pdev->device == 0x791e) &&
343 (dev->pdev->subsystem_vendor == 0x1043) &&
344 (dev->pdev->subsystem_device == 0x826d)) {
345 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
346 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
347 *connector_type = DRM_MODE_CONNECTOR_DVID;
348 }
349
Alex Deucherc86a9032010-02-18 14:14:58 -0500350 /* Asrock RS600 board lists the DVI port as HDMI */
351 if ((dev->pdev->device == 0x7941) &&
352 (dev->pdev->subsystem_vendor == 0x1849) &&
353 (dev->pdev->subsystem_device == 0x7941)) {
354 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
355 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
356 *connector_type = DRM_MODE_CONNECTOR_DVID;
357 }
358
Alex Deucherf36fce02010-09-27 11:33:00 -0400359 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
360 if ((dev->pdev->device == 0x796e) &&
361 (dev->pdev->subsystem_vendor == 0x1462) &&
362 (dev->pdev->subsystem_device == 0x7302)) {
363 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
364 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
365 return false;
366 }
367
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200368 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
369 if ((dev->pdev->device == 0x7941) &&
370 (dev->pdev->subsystem_vendor == 0x147b) &&
371 (dev->pdev->subsystem_device == 0x2412)) {
372 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
373 return false;
374 }
375
376 /* Falcon NW laptop lists vga ddc line for LVDS */
377 if ((dev->pdev->device == 0x5653) &&
378 (dev->pdev->subsystem_vendor == 0x1462) &&
379 (dev->pdev->subsystem_device == 0x0291)) {
Alex Deucher848577e2009-07-08 16:15:30 -0400380 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200381 i2c_bus->valid = false;
Alex Deucher848577e2009-07-08 16:15:30 -0400382 *line_mux = 53;
383 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200384 }
385
Alex Deucher4e3f9b782009-12-01 14:49:50 -0500386 /* HIS X1300 is DVI+VGA, not DVI+DVI */
387 if ((dev->pdev->device == 0x7146) &&
388 (dev->pdev->subsystem_vendor == 0x17af) &&
389 (dev->pdev->subsystem_device == 0x2058)) {
390 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
391 return false;
392 }
393
Dave Airlieaa1a7502009-12-04 11:51:34 +1000394 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
395 if ((dev->pdev->device == 0x7142) &&
396 (dev->pdev->subsystem_vendor == 0x1458) &&
397 (dev->pdev->subsystem_device == 0x2134)) {
398 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
399 return false;
400 }
401
402
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200403 /* Funky macbooks */
404 if ((dev->pdev->device == 0x71C5) &&
405 (dev->pdev->subsystem_vendor == 0x106b) &&
406 (dev->pdev->subsystem_device == 0x0080)) {
407 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
408 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
409 return false;
Alex Deuchere1e8a5d2010-03-26 17:14:37 -0400410 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
411 *line_mux = 0x90;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200412 }
413
Alex Deucherbe23da82011-01-18 18:26:11 +0000414 /* mac rv630, rv730, others */
415 if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
416 (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
417 *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
418 *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
Alex Deucherf598aa72011-01-04 00:43:39 -0500419 }
420
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200421 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
422 if ((dev->pdev->device == 0x9598) &&
423 (dev->pdev->subsystem_vendor == 0x1043) &&
424 (dev->pdev->subsystem_device == 0x01da)) {
Alex Deucher705af9c2009-09-10 16:31:13 -0400425 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400426 *connector_type = DRM_MODE_CONNECTOR_DVII;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200427 }
428 }
429
Alex Deuchere153b702010-07-20 18:07:22 -0400430 /* ASUS HD 3600 board lists the DVI port as HDMI */
431 if ((dev->pdev->device == 0x9598) &&
432 (dev->pdev->subsystem_vendor == 0x1043) &&
433 (dev->pdev->subsystem_device == 0x01e4)) {
434 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
435 *connector_type = DRM_MODE_CONNECTOR_DVII;
436 }
437 }
438
Alex Deucher705af9c2009-09-10 16:31:13 -0400439 /* ASUS HD 3450 board lists the DVI port as HDMI */
440 if ((dev->pdev->device == 0x95C5) &&
441 (dev->pdev->subsystem_vendor == 0x1043) &&
442 (dev->pdev->subsystem_device == 0x01e2)) {
443 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400444 *connector_type = DRM_MODE_CONNECTOR_DVII;
Alex Deucher705af9c2009-09-10 16:31:13 -0400445 }
446 }
447
448 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
449 * HDMI + VGA reporting as HDMI
450 */
451 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
452 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
453 *connector_type = DRM_MODE_CONNECTOR_VGA;
454 *line_mux = 0;
455 }
456 }
457
Alex Deucher4f87af42011-05-04 11:41:47 -0400458 /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port
Alex Deucher2f299d52011-01-04 17:42:20 -0500459 * on the laptop and a DVI port on the docking station and
460 * both share the same encoder, hpd pin, and ddc line.
461 * So while the bios table is technically correct,
462 * we drop the DVI port here since xrandr has no concept of
463 * encoders and will try and drive both connectors
464 * with different crtcs which isn't possible on the hardware
465 * side and leaves no crtcs for LVDS or VGA.
466 */
Alex Deucher4f87af42011-05-04 11:41:47 -0400467 if (((dev->pdev->device == 0x95c4) || (dev->pdev->device == 0x9591)) &&
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500468 (dev->pdev->subsystem_vendor == 0x1025) &&
469 (dev->pdev->subsystem_device == 0x013c)) {
470 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400471 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
Alex Deucher2f299d52011-01-04 17:42:20 -0500472 /* actually it's a DVI-D port not DVI-I */
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500473 *connector_type = DRM_MODE_CONNECTOR_DVID;
Alex Deucher2f299d52011-01-04 17:42:20 -0500474 return false;
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400475 }
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500476 }
477
Dave Airlieefa84502010-02-09 09:06:00 +1000478 /* XFX Pine Group device rv730 reports no VGA DDC lines
479 * even though they are wired up to record 0x93
480 */
481 if ((dev->pdev->device == 0x9498) &&
482 (dev->pdev->subsystem_vendor == 0x1682) &&
483 (dev->pdev->subsystem_device == 0x2452)) {
484 struct radeon_device *rdev = dev->dev_private;
485 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
486 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200487 return true;
488}
489
490const int supported_devices_connector_convert[] = {
491 DRM_MODE_CONNECTOR_Unknown,
492 DRM_MODE_CONNECTOR_VGA,
493 DRM_MODE_CONNECTOR_DVII,
494 DRM_MODE_CONNECTOR_DVID,
495 DRM_MODE_CONNECTOR_DVIA,
496 DRM_MODE_CONNECTOR_SVIDEO,
497 DRM_MODE_CONNECTOR_Composite,
498 DRM_MODE_CONNECTOR_LVDS,
499 DRM_MODE_CONNECTOR_Unknown,
500 DRM_MODE_CONNECTOR_Unknown,
501 DRM_MODE_CONNECTOR_HDMIA,
502 DRM_MODE_CONNECTOR_HDMIB,
503 DRM_MODE_CONNECTOR_Unknown,
504 DRM_MODE_CONNECTOR_Unknown,
505 DRM_MODE_CONNECTOR_9PinDIN,
506 DRM_MODE_CONNECTOR_DisplayPort
507};
508
Alex Deucherb75fad02009-11-05 13:16:01 -0500509const uint16_t supported_devices_connector_object_id_convert[] = {
510 CONNECTOR_OBJECT_ID_NONE,
511 CONNECTOR_OBJECT_ID_VGA,
512 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
513 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
514 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
515 CONNECTOR_OBJECT_ID_COMPOSITE,
516 CONNECTOR_OBJECT_ID_SVIDEO,
517 CONNECTOR_OBJECT_ID_LVDS,
518 CONNECTOR_OBJECT_ID_9PIN_DIN,
519 CONNECTOR_OBJECT_ID_9PIN_DIN,
520 CONNECTOR_OBJECT_ID_DISPLAYPORT,
521 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
522 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
523 CONNECTOR_OBJECT_ID_SVIDEO
524};
525
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200526const int object_connector_convert[] = {
527 DRM_MODE_CONNECTOR_Unknown,
528 DRM_MODE_CONNECTOR_DVII,
529 DRM_MODE_CONNECTOR_DVII,
530 DRM_MODE_CONNECTOR_DVID,
531 DRM_MODE_CONNECTOR_DVID,
532 DRM_MODE_CONNECTOR_VGA,
533 DRM_MODE_CONNECTOR_Composite,
534 DRM_MODE_CONNECTOR_SVIDEO,
535 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher705af9c2009-09-10 16:31:13 -0400536 DRM_MODE_CONNECTOR_Unknown,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200537 DRM_MODE_CONNECTOR_9PinDIN,
538 DRM_MODE_CONNECTOR_Unknown,
539 DRM_MODE_CONNECTOR_HDMIA,
540 DRM_MODE_CONNECTOR_HDMIB,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200541 DRM_MODE_CONNECTOR_LVDS,
542 DRM_MODE_CONNECTOR_9PinDIN,
543 DRM_MODE_CONNECTOR_Unknown,
544 DRM_MODE_CONNECTOR_Unknown,
545 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher196c58d2010-01-07 14:22:32 -0500546 DRM_MODE_CONNECTOR_DisplayPort,
547 DRM_MODE_CONNECTOR_eDP,
548 DRM_MODE_CONNECTOR_Unknown
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200549};
550
551bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
552{
553 struct radeon_device *rdev = dev->dev_private;
554 struct radeon_mode_info *mode_info = &rdev->mode_info;
555 struct atom_context *ctx = mode_info->atom_context;
556 int index = GetIndexIntoMasterTable(DATA, Object_Header);
Alex Deuchereed45b32009-12-04 14:45:27 -0500557 u16 size, data_offset;
558 u8 frev, crev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200559 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
Alex Deucher36868bd2011-01-06 21:19:21 -0500560 ATOM_ENCODER_OBJECT_TABLE *enc_obj;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400561 ATOM_OBJECT_TABLE *router_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200562 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
563 ATOM_OBJECT_HEADER *obj_header;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400564 int i, j, k, path_size, device_support;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200565 int connector_type;
Alex Deuchereed45b32009-12-04 14:45:27 -0500566 u16 igp_lane_info, conn_id, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200567 struct radeon_i2c_bus_rec ddc_bus;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400568 struct radeon_router router;
Alex Deuchereed45b32009-12-04 14:45:27 -0500569 struct radeon_gpio_rec gpio;
570 struct radeon_hpd hpd;
571
Alex Deuchera084e6e2010-03-18 01:04:01 -0400572 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200573 return false;
574
575 if (crev < 2)
576 return false;
577
578 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
579 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
580 (ctx->bios + data_offset +
581 le16_to_cpu(obj_header->usDisplayPathTableOffset));
582 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
583 (ctx->bios + data_offset +
584 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
Alex Deucher36868bd2011-01-06 21:19:21 -0500585 enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
586 (ctx->bios + data_offset +
587 le16_to_cpu(obj_header->usEncoderObjectTableOffset));
Alex Deucher26b5bc92010-08-05 21:21:18 -0400588 router_obj = (ATOM_OBJECT_TABLE *)
589 (ctx->bios + data_offset +
590 le16_to_cpu(obj_header->usRouterObjectTableOffset));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200591 device_support = le16_to_cpu(obj_header->usDeviceSupport);
592
593 path_size = 0;
594 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
595 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
596 ATOM_DISPLAY_OBJECT_PATH *path;
597 addr += path_size;
598 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
599 path_size += le16_to_cpu(path->usSize);
Alex Deucher5137ee92010-08-12 18:58:47 -0400600
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200601 if (device_support & le16_to_cpu(path->usDeviceTag)) {
602 uint8_t con_obj_id, con_obj_num, con_obj_type;
603
604 con_obj_id =
605 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
606 >> OBJECT_ID_SHIFT;
607 con_obj_num =
608 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
609 >> ENUM_ID_SHIFT;
610 con_obj_type =
611 (le16_to_cpu(path->usConnObjectId) &
612 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
613
Dave Airlie4bbd4972009-09-25 08:56:12 +1000614 /* TODO CV support */
615 if (le16_to_cpu(path->usDeviceTag) ==
616 ATOM_DEVICE_CV_SUPPORT)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200617 continue;
618
Alex Deucheree59f2b2009-11-05 13:11:46 -0500619 /* IGP chips */
620 if ((rdev->flags & RADEON_IS_IGP) &&
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200621 (con_obj_id ==
622 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
623 uint16_t igp_offset = 0;
624 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
625
626 index =
627 GetIndexIntoMasterTable(DATA,
628 IntegratedSystemInfo);
629
Alex Deuchera084e6e2010-03-18 01:04:01 -0400630 if (atom_parse_data_header(ctx, index, &size, &frev,
631 &crev, &igp_offset)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200632
Alex Deuchera084e6e2010-03-18 01:04:01 -0400633 if (crev >= 2) {
634 igp_obj =
635 (ATOM_INTEGRATED_SYSTEM_INFO_V2
636 *) (ctx->bios + igp_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200637
Alex Deuchera084e6e2010-03-18 01:04:01 -0400638 if (igp_obj) {
639 uint32_t slot_config, ct;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200640
Alex Deuchera084e6e2010-03-18 01:04:01 -0400641 if (con_obj_num == 1)
642 slot_config =
643 igp_obj->
644 ulDDISlot1Config;
645 else
646 slot_config =
647 igp_obj->
648 ulDDISlot2Config;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200649
Alex Deuchera084e6e2010-03-18 01:04:01 -0400650 ct = (slot_config >> 16) & 0xff;
651 connector_type =
652 object_connector_convert
653 [ct];
654 connector_object_id = ct;
655 igp_lane_info =
656 slot_config & 0xffff;
657 } else
658 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200659 } else
660 continue;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400661 } else {
662 igp_lane_info = 0;
663 connector_type =
664 object_connector_convert[con_obj_id];
665 connector_object_id = con_obj_id;
666 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200667 } else {
668 igp_lane_info = 0;
669 connector_type =
670 object_connector_convert[con_obj_id];
Alex Deucherb75fad02009-11-05 13:16:01 -0500671 connector_object_id = con_obj_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200672 }
673
674 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
675 continue;
676
Tyson Whiteheadbdd91b22010-11-08 16:08:30 +0000677 router.ddc_valid = false;
678 router.cd_valid = false;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400679 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
680 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200681
Alex Deucher26b5bc92010-08-05 21:21:18 -0400682 grph_obj_id =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200683 (le16_to_cpu(path->usGraphicObjIds[j]) &
684 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400685 grph_obj_num =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200686 (le16_to_cpu(path->usGraphicObjIds[j]) &
687 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400688 grph_obj_type =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200689 (le16_to_cpu(path->usGraphicObjIds[j]) &
690 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
691
Alex Deucher26b5bc92010-08-05 21:21:18 -0400692 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
Alex Deucher36868bd2011-01-06 21:19:21 -0500693 for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
694 u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
695 if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
696 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
697 (ctx->bios + data_offset +
698 le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
699 ATOM_ENCODER_CAP_RECORD *cap_record;
700 u16 caps = 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200701
John Lindgren97ea5302011-03-24 23:28:31 +0000702 while (record->ucRecordSize > 0 &&
703 record->ucRecordType > 0 &&
Alex Deucher36868bd2011-01-06 21:19:21 -0500704 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
705 switch (record->ucRecordType) {
706 case ATOM_ENCODER_CAP_RECORD_TYPE:
707 cap_record =(ATOM_ENCODER_CAP_RECORD *)
708 record;
709 caps = le16_to_cpu(cap_record->usEncoderCap);
710 break;
711 }
712 record = (ATOM_COMMON_RECORD_HEADER *)
713 ((char *)record + record->ucRecordSize);
714 }
715 radeon_add_atom_encoder(dev,
716 encoder_obj,
717 le16_to_cpu
718 (path->
719 usDeviceTag),
720 caps);
721 }
722 }
Alex Deucher26b5bc92010-08-05 21:21:18 -0400723 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
Alex Deucher26b5bc92010-08-05 21:21:18 -0400724 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
Tyson Whiteheadbdd91b22010-11-08 16:08:30 +0000725 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
Alex Deucher26b5bc92010-08-05 21:21:18 -0400726 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
727 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
728 (ctx->bios + data_offset +
729 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
730 ATOM_I2C_RECORD *i2c_record;
731 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
732 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
Alex Deucherfb939df2010-11-08 16:08:29 +0000733 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400734 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
735 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
736 (ctx->bios + data_offset +
737 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
738 int enum_id;
739
740 router.router_id = router_obj_id;
741 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
742 enum_id++) {
743 if (le16_to_cpu(path->usConnObjectId) ==
744 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
745 break;
746 }
747
John Lindgren97ea5302011-03-24 23:28:31 +0000748 while (record->ucRecordSize > 0 &&
749 record->ucRecordType > 0 &&
Alex Deucher26b5bc92010-08-05 21:21:18 -0400750 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
751 switch (record->ucRecordType) {
752 case ATOM_I2C_RECORD_TYPE:
753 i2c_record =
754 (ATOM_I2C_RECORD *)
755 record;
756 i2c_config =
757 (ATOM_I2C_ID_CONFIG_ACCESS *)
758 &i2c_record->sucI2cId;
759 router.i2c_info =
760 radeon_lookup_i2c_gpio(rdev,
761 i2c_config->
762 ucAccess);
763 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
764 break;
765 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
766 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
767 record;
Alex Deucherfb939df2010-11-08 16:08:29 +0000768 router.ddc_valid = true;
769 router.ddc_mux_type = ddc_path->ucMuxType;
770 router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
771 router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
772 break;
773 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
774 cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
775 record;
776 router.cd_valid = true;
777 router.cd_mux_type = cd_path->ucMuxType;
778 router.cd_mux_control_pin = cd_path->ucMuxControlPin;
779 router.cd_mux_state = cd_path->ucMuxState[enum_id];
Alex Deucher26b5bc92010-08-05 21:21:18 -0400780 break;
781 }
782 record = (ATOM_COMMON_RECORD_HEADER *)
783 ((char *)record + record->ucRecordSize);
784 }
785 }
786 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200787 }
788 }
789
Alex Deuchereed45b32009-12-04 14:45:27 -0500790 /* look up gpio for ddc, hpd */
Alex Deucher2bfcc0f2010-05-18 19:26:46 -0400791 ddc_bus.valid = false;
792 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200793 if ((le16_to_cpu(path->usDeviceTag) &
Alex Deuchereed45b32009-12-04 14:45:27 -0500794 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200795 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
796 if (le16_to_cpu(path->usConnObjectId) ==
797 le16_to_cpu(con_obj->asObjects[j].
798 usObjectID)) {
799 ATOM_COMMON_RECORD_HEADER
800 *record =
801 (ATOM_COMMON_RECORD_HEADER
802 *)
803 (ctx->bios + data_offset +
804 le16_to_cpu(con_obj->
805 asObjects[j].
806 usRecordOffset));
807 ATOM_I2C_RECORD *i2c_record;
Alex Deuchereed45b32009-12-04 14:45:27 -0500808 ATOM_HPD_INT_RECORD *hpd_record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500809 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500810
John Lindgren97ea5302011-03-24 23:28:31 +0000811 while (record->ucRecordSize > 0 &&
812 record->ucRecordType > 0 &&
813 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500814 switch (record->ucRecordType) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200815 case ATOM_I2C_RECORD_TYPE:
816 i2c_record =
Alex Deuchereed45b32009-12-04 14:45:27 -0500817 (ATOM_I2C_RECORD *)
818 record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500819 i2c_config =
820 (ATOM_I2C_ID_CONFIG_ACCESS *)
821 &i2c_record->sucI2cId;
Alex Deuchereed45b32009-12-04 14:45:27 -0500822 ddc_bus = radeon_lookup_i2c_gpio(rdev,
Alex Deucherd3f420d2009-12-08 14:30:49 -0500823 i2c_config->
824 ucAccess);
Alex Deuchereed45b32009-12-04 14:45:27 -0500825 break;
826 case ATOM_HPD_INT_RECORD_TYPE:
827 hpd_record =
828 (ATOM_HPD_INT_RECORD *)
829 record;
830 gpio = radeon_lookup_gpio(rdev,
831 hpd_record->ucHPDIntGPIOID);
832 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
833 hpd.plugged_state = hpd_record->ucPlugged_PinState;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200834 break;
835 }
836 record =
837 (ATOM_COMMON_RECORD_HEADER
838 *) ((char *)record
839 +
840 record->
841 ucRecordSize);
842 }
843 break;
844 }
845 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500846 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200847
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500848 /* needed for aux chan transactions */
Alex Deucher8e36ed02010-05-18 19:26:47 -0400849 ddc_bus.hpd = hpd.hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500850
Alex Deucher705af9c2009-09-10 16:31:13 -0400851 conn_id = le16_to_cpu(path->usConnObjectId);
852
853 if (!radeon_atom_apply_quirks
854 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500855 &ddc_bus, &conn_id, &hpd))
Alex Deucher705af9c2009-09-10 16:31:13 -0400856 continue;
857
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200858 radeon_add_atom_connector(dev,
Alex Deucher705af9c2009-09-10 16:31:13 -0400859 conn_id,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200860 le16_to_cpu(path->
861 usDeviceTag),
862 connector_type, &ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -0400863 igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -0500864 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -0400865 &hpd,
866 &router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200867
868 }
869 }
870
871 radeon_link_encoder_connector(dev);
872
873 return true;
874}
875
Alex Deucherb75fad02009-11-05 13:16:01 -0500876static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
877 int connector_type,
878 uint16_t devices)
879{
880 struct radeon_device *rdev = dev->dev_private;
881
882 if (rdev->flags & RADEON_IS_IGP) {
883 return supported_devices_connector_object_id_convert
884 [connector_type];
885 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
886 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
887 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
888 struct radeon_mode_info *mode_info = &rdev->mode_info;
889 struct atom_context *ctx = mode_info->atom_context;
890 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
891 uint16_t size, data_offset;
892 uint8_t frev, crev;
893 ATOM_XTMDS_INFO *xtmds;
894
Alex Deuchera084e6e2010-03-18 01:04:01 -0400895 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
896 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
Alex Deucherb75fad02009-11-05 13:16:01 -0500897
Alex Deuchera084e6e2010-03-18 01:04:01 -0400898 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
899 if (connector_type == DRM_MODE_CONNECTOR_DVII)
900 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
901 else
902 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
903 } else {
904 if (connector_type == DRM_MODE_CONNECTOR_DVII)
905 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
906 else
907 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
908 }
909 } else
910 return supported_devices_connector_object_id_convert
911 [connector_type];
Alex Deucherb75fad02009-11-05 13:16:01 -0500912 } else {
913 return supported_devices_connector_object_id_convert
914 [connector_type];
915 }
916}
917
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200918struct bios_connector {
919 bool valid;
Alex Deucher705af9c2009-09-10 16:31:13 -0400920 uint16_t line_mux;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200921 uint16_t devices;
922 int connector_type;
923 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500924 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200925};
926
927bool radeon_get_atom_connector_info_from_supported_devices_table(struct
928 drm_device
929 *dev)
930{
931 struct radeon_device *rdev = dev->dev_private;
932 struct radeon_mode_info *mode_info = &rdev->mode_info;
933 struct atom_context *ctx = mode_info->atom_context;
934 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
935 uint16_t size, data_offset;
936 uint8_t frev, crev;
937 uint16_t device_support;
938 uint8_t dac;
939 union atom_supported_devices *supported_devices;
Alex Deuchereed45b32009-12-04 14:45:27 -0500940 int i, j, max_device;
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000941 struct bios_connector *bios_connectors;
942 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400943 struct radeon_router router;
944
Alex Deucherfb939df2010-11-08 16:08:29 +0000945 router.ddc_valid = false;
946 router.cd_valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200947
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000948 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
949 if (!bios_connectors)
Alex Deuchera084e6e2010-03-18 01:04:01 -0400950 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200951
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000952 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
953 &data_offset)) {
954 kfree(bios_connectors);
955 return false;
956 }
957
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200958 supported_devices =
959 (union atom_supported_devices *)(ctx->bios + data_offset);
960
961 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
962
Alex Deuchereed45b32009-12-04 14:45:27 -0500963 if (frev > 1)
964 max_device = ATOM_MAX_SUPPORTED_DEVICE;
965 else
966 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
967
968 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200969 ATOM_CONNECTOR_INFO_I2C ci =
970 supported_devices->info.asConnInfo[i];
971
972 bios_connectors[i].valid = false;
973
974 if (!(device_support & (1 << i))) {
975 continue;
976 }
977
978 if (i == ATOM_DEVICE_CV_INDEX) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000979 DRM_DEBUG_KMS("Skipping Component Video\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200980 continue;
981 }
982
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200983 bios_connectors[i].connector_type =
984 supported_devices_connector_convert[ci.sucConnectorInfo.
985 sbfAccess.
986 bfConnectorType];
987
988 if (bios_connectors[i].connector_type ==
989 DRM_MODE_CONNECTOR_Unknown)
990 continue;
991
992 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
993
Alex Deucherd3f420d2009-12-08 14:30:49 -0500994 bios_connectors[i].line_mux =
995 ci.sucI2cId.ucAccess;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200996
997 /* give tv unique connector ids */
998 if (i == ATOM_DEVICE_TV1_INDEX) {
999 bios_connectors[i].ddc_bus.valid = false;
1000 bios_connectors[i].line_mux = 50;
1001 } else if (i == ATOM_DEVICE_TV2_INDEX) {
1002 bios_connectors[i].ddc_bus.valid = false;
1003 bios_connectors[i].line_mux = 51;
1004 } else if (i == ATOM_DEVICE_CV_INDEX) {
1005 bios_connectors[i].ddc_bus.valid = false;
1006 bios_connectors[i].line_mux = 52;
1007 } else
1008 bios_connectors[i].ddc_bus =
Alex Deuchereed45b32009-12-04 14:45:27 -05001009 radeon_lookup_i2c_gpio(rdev,
1010 bios_connectors[i].line_mux);
1011
1012 if ((crev > 1) && (frev > 1)) {
1013 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
1014 switch (isb) {
1015 case 0x4:
1016 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
1017 break;
1018 case 0xa:
1019 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
1020 break;
1021 default:
1022 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
1023 break;
1024 }
1025 } else {
1026 if (i == ATOM_DEVICE_DFP1_INDEX)
1027 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
1028 else if (i == ATOM_DEVICE_DFP2_INDEX)
1029 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
1030 else
1031 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
1032 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001033
1034 /* Always set the connector type to VGA for CRT1/CRT2. if they are
1035 * shared with a DVI port, we'll pick up the DVI connector when we
1036 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
1037 */
1038 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
1039 bios_connectors[i].connector_type =
1040 DRM_MODE_CONNECTOR_VGA;
1041
1042 if (!radeon_atom_apply_quirks
1043 (dev, (1 << i), &bios_connectors[i].connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -05001044 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
1045 &bios_connectors[i].hpd))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001046 continue;
1047
1048 bios_connectors[i].valid = true;
1049 bios_connectors[i].devices = (1 << i);
1050
1051 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
1052 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001053 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001054 (1 << i),
1055 dac),
Alex Deucher36868bd2011-01-06 21:19:21 -05001056 (1 << i),
1057 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001058 else
1059 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001060 radeon_get_encoder_enum(dev,
Alex Deucherf56cd642009-12-18 11:28:22 -05001061 (1 << i),
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001062 dac),
1063 (1 << i));
1064 }
1065
1066 /* combine shared connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -05001067 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001068 if (bios_connectors[i].valid) {
Alex Deuchereed45b32009-12-04 14:45:27 -05001069 for (j = 0; j < max_device; j++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001070 if (bios_connectors[j].valid && (i != j)) {
1071 if (bios_connectors[i].line_mux ==
1072 bios_connectors[j].line_mux) {
Alex Deucherf56cd642009-12-18 11:28:22 -05001073 /* make sure not to combine LVDS */
1074 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1075 bios_connectors[i].line_mux = 53;
1076 bios_connectors[i].ddc_bus.valid = false;
1077 continue;
1078 }
1079 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1080 bios_connectors[j].line_mux = 53;
1081 bios_connectors[j].ddc_bus.valid = false;
1082 continue;
1083 }
1084 /* combine analog and digital for DVI-I */
1085 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1086 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
1087 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1088 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
1089 bios_connectors[i].devices |=
1090 bios_connectors[j].devices;
1091 bios_connectors[i].connector_type =
1092 DRM_MODE_CONNECTOR_DVII;
1093 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
Alex Deuchereed45b32009-12-04 14:45:27 -05001094 bios_connectors[i].hpd =
1095 bios_connectors[j].hpd;
Alex Deucherf56cd642009-12-18 11:28:22 -05001096 bios_connectors[j].valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001097 }
1098 }
1099 }
1100 }
1101 }
1102 }
1103
1104 /* add the connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -05001105 for (i = 0; i < max_device; i++) {
Alex Deucherb75fad02009-11-05 13:16:01 -05001106 if (bios_connectors[i].valid) {
1107 uint16_t connector_object_id =
1108 atombios_get_connector_object_id(dev,
1109 bios_connectors[i].connector_type,
1110 bios_connectors[i].devices);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001111 radeon_add_atom_connector(dev,
1112 bios_connectors[i].line_mux,
1113 bios_connectors[i].devices,
1114 bios_connectors[i].
1115 connector_type,
1116 &bios_connectors[i].ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -04001117 0,
Alex Deuchereed45b32009-12-04 14:45:27 -05001118 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001119 &bios_connectors[i].hpd,
1120 &router);
Alex Deucherb75fad02009-11-05 13:16:01 -05001121 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001122 }
1123
1124 radeon_link_encoder_connector(dev);
1125
Prarit Bhargavaf49d2732010-05-24 10:24:07 +10001126 kfree(bios_connectors);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001127 return true;
1128}
1129
1130union firmware_info {
1131 ATOM_FIRMWARE_INFO info;
1132 ATOM_FIRMWARE_INFO_V1_2 info_12;
1133 ATOM_FIRMWARE_INFO_V1_3 info_13;
1134 ATOM_FIRMWARE_INFO_V1_4 info_14;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001135 ATOM_FIRMWARE_INFO_V2_1 info_21;
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001136 ATOM_FIRMWARE_INFO_V2_2 info_22;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001137};
1138
1139bool radeon_atom_get_clock_info(struct drm_device *dev)
1140{
1141 struct radeon_device *rdev = dev->dev_private;
1142 struct radeon_mode_info *mode_info = &rdev->mode_info;
1143 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1144 union firmware_info *firmware_info;
1145 uint8_t frev, crev;
1146 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1147 struct radeon_pll *p2pll = &rdev->clock.p2pll;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001148 struct radeon_pll *dcpll = &rdev->clock.dcpll;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001149 struct radeon_pll *spll = &rdev->clock.spll;
1150 struct radeon_pll *mpll = &rdev->clock.mpll;
1151 uint16_t data_offset;
1152
Alex Deuchera084e6e2010-03-18 01:04:01 -04001153 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1154 &frev, &crev, &data_offset)) {
1155 firmware_info =
1156 (union firmware_info *)(mode_info->atom_context->bios +
1157 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001158 /* pixel clocks */
1159 p1pll->reference_freq =
1160 le16_to_cpu(firmware_info->info.usReferenceClock);
1161 p1pll->reference_div = 0;
1162
Mathias Fröhlichbc293e52009-10-19 17:49:49 -04001163 if (crev < 2)
1164 p1pll->pll_out_min =
1165 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1166 else
1167 p1pll->pll_out_min =
1168 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001169 p1pll->pll_out_max =
1170 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1171
Alex Deucher86cb2bb2010-03-08 12:55:16 -05001172 if (crev >= 4) {
1173 p1pll->lcd_pll_out_min =
1174 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1175 if (p1pll->lcd_pll_out_min == 0)
1176 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1177 p1pll->lcd_pll_out_max =
1178 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1179 if (p1pll->lcd_pll_out_max == 0)
1180 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1181 } else {
1182 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1183 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1184 }
1185
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001186 if (p1pll->pll_out_min == 0) {
1187 if (ASIC_IS_AVIVO(rdev))
1188 p1pll->pll_out_min = 64800;
1189 else
1190 p1pll->pll_out_min = 20000;
1191 }
1192
1193 p1pll->pll_in_min =
1194 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1195 p1pll->pll_in_max =
1196 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1197
1198 *p2pll = *p1pll;
1199
1200 /* system clock */
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001201 if (ASIC_IS_DCE4(rdev))
1202 spll->reference_freq =
1203 le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
1204 else
1205 spll->reference_freq =
1206 le16_to_cpu(firmware_info->info.usReferenceClock);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001207 spll->reference_div = 0;
1208
1209 spll->pll_out_min =
1210 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1211 spll->pll_out_max =
1212 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1213
1214 /* ??? */
1215 if (spll->pll_out_min == 0) {
1216 if (ASIC_IS_AVIVO(rdev))
1217 spll->pll_out_min = 64800;
1218 else
1219 spll->pll_out_min = 20000;
1220 }
1221
1222 spll->pll_in_min =
1223 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1224 spll->pll_in_max =
1225 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1226
1227 /* memory clock */
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001228 if (ASIC_IS_DCE4(rdev))
1229 mpll->reference_freq =
1230 le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
1231 else
1232 mpll->reference_freq =
1233 le16_to_cpu(firmware_info->info.usReferenceClock);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001234 mpll->reference_div = 0;
1235
1236 mpll->pll_out_min =
1237 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1238 mpll->pll_out_max =
1239 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1240
1241 /* ??? */
1242 if (mpll->pll_out_min == 0) {
1243 if (ASIC_IS_AVIVO(rdev))
1244 mpll->pll_out_min = 64800;
1245 else
1246 mpll->pll_out_min = 20000;
1247 }
1248
1249 mpll->pll_in_min =
1250 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1251 mpll->pll_in_max =
1252 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1253
1254 rdev->clock.default_sclk =
1255 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1256 rdev->clock.default_mclk =
1257 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1258
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001259 if (ASIC_IS_DCE4(rdev)) {
1260 rdev->clock.default_dispclk =
1261 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001262 if (rdev->clock.default_dispclk == 0) {
1263 if (ASIC_IS_DCE5(rdev))
1264 rdev->clock.default_dispclk = 54000; /* 540 Mhz */
1265 else
1266 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1267 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001268 rdev->clock.dp_extclk =
1269 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
1270 }
1271 *dcpll = *p1pll;
1272
Alex Deucherb20f9be2011-06-08 13:01:11 -04001273 rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
1274 if (rdev->clock.max_pixel_clock == 0)
1275 rdev->clock.max_pixel_clock = 40000;
1276
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001277 return true;
1278 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001279
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001280 return false;
1281}
1282
Alex Deucher06b64762010-01-05 11:27:29 -05001283union igp_info {
1284 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1285 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1286};
1287
1288bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1289{
1290 struct radeon_mode_info *mode_info = &rdev->mode_info;
1291 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1292 union igp_info *igp_info;
1293 u8 frev, crev;
1294 u16 data_offset;
1295
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001296 /* sideport is AMD only */
1297 if (rdev->family == CHIP_RS600)
1298 return false;
1299
Alex Deuchera084e6e2010-03-18 01:04:01 -04001300 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1301 &frev, &crev, &data_offset)) {
1302 igp_info = (union igp_info *)(mode_info->atom_context->bios +
Alex Deucher06b64762010-01-05 11:27:29 -05001303 data_offset);
Alex Deucher06b64762010-01-05 11:27:29 -05001304 switch (crev) {
1305 case 1:
Cédric Cano45894332011-02-11 19:45:37 -05001306 if (le32_to_cpu(igp_info->info.ulBootUpMemoryClock))
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001307 return true;
Alex Deucher06b64762010-01-05 11:27:29 -05001308 break;
1309 case 2:
Cédric Cano45894332011-02-11 19:45:37 -05001310 if (le32_to_cpu(igp_info->info_2.ulBootUpSidePortClock))
Alex Deucher06b64762010-01-05 11:27:29 -05001311 return true;
1312 break;
1313 default:
1314 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1315 break;
1316 }
1317 }
1318 return false;
1319}
1320
Dave Airlie445282d2009-09-09 17:40:54 +10001321bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1322 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001323{
1324 struct drm_device *dev = encoder->base.dev;
1325 struct radeon_device *rdev = dev->dev_private;
1326 struct radeon_mode_info *mode_info = &rdev->mode_info;
1327 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1328 uint16_t data_offset;
1329 struct _ATOM_TMDS_INFO *tmds_info;
1330 uint8_t frev, crev;
1331 uint16_t maxfreq;
1332 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001333
Alex Deuchera084e6e2010-03-18 01:04:01 -04001334 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1335 &frev, &crev, &data_offset)) {
1336 tmds_info =
1337 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1338 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001339
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001340 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1341 for (i = 0; i < 4; i++) {
1342 tmds->tmds_pll[i].freq =
1343 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1344 tmds->tmds_pll[i].value =
1345 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1346 tmds->tmds_pll[i].value |=
1347 (tmds_info->asMiscInfo[i].
1348 ucPLL_VCO_Gain & 0x3f) << 6;
1349 tmds->tmds_pll[i].value |=
1350 (tmds_info->asMiscInfo[i].
1351 ucPLL_DutyCycle & 0xf) << 12;
1352 tmds->tmds_pll[i].value |=
1353 (tmds_info->asMiscInfo[i].
1354 ucPLL_VoltageSwing & 0xf) << 16;
1355
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001356 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001357 tmds->tmds_pll[i].freq,
1358 tmds->tmds_pll[i].value);
1359
1360 if (maxfreq == tmds->tmds_pll[i].freq) {
1361 tmds->tmds_pll[i].freq = 0xffffffff;
1362 break;
1363 }
1364 }
Dave Airlie445282d2009-09-09 17:40:54 +10001365 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001366 }
Dave Airlie445282d2009-09-09 17:40:54 +10001367 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001368}
1369
Alex Deucherba032a52010-10-04 17:13:01 -04001370bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
1371 struct radeon_atom_ss *ss,
1372 int id)
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001373{
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001374 struct radeon_mode_info *mode_info = &rdev->mode_info;
1375 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
Alex Deucherba032a52010-10-04 17:13:01 -04001376 uint16_t data_offset, size;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001377 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1378 uint8_t frev, crev;
Alex Deucherba032a52010-10-04 17:13:01 -04001379 int i, num_indices;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001380
Alex Deucherba032a52010-10-04 17:13:01 -04001381 memset(ss, 0, sizeof(struct radeon_atom_ss));
1382 if (atom_parse_data_header(mode_info->atom_context, index, &size,
Alex Deuchera084e6e2010-03-18 01:04:01 -04001383 &frev, &crev, &data_offset)) {
1384 ss_info =
1385 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001386
Alex Deucherba032a52010-10-04 17:13:01 -04001387 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1388 sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001389
Alex Deucherba032a52010-10-04 17:13:01 -04001390 for (i = 0; i < num_indices; i++) {
Alex Deucher279b2152009-12-08 14:07:03 -05001391 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1392 ss->percentage =
1393 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1394 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1395 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1396 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1397 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1398 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
Alex Deucherba032a52010-10-04 17:13:01 -04001399 return true;
Alex Deucher279b2152009-12-08 14:07:03 -05001400 }
1401 }
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001402 }
Alex Deucherba032a52010-10-04 17:13:01 -04001403 return false;
1404}
1405
Alex Deucher4339c442010-11-22 17:56:25 -05001406static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
1407 struct radeon_atom_ss *ss,
1408 int id)
1409{
1410 struct radeon_mode_info *mode_info = &rdev->mode_info;
1411 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1412 u16 data_offset, size;
1413 struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *igp_info;
1414 u8 frev, crev;
1415 u16 percentage = 0, rate = 0;
1416
1417 /* get any igp specific overrides */
1418 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1419 &frev, &crev, &data_offset)) {
1420 igp_info = (struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *)
1421 (mode_info->atom_context->bios + data_offset);
1422 switch (id) {
1423 case ASIC_INTERNAL_SS_ON_TMDS:
1424 percentage = le16_to_cpu(igp_info->usDVISSPercentage);
1425 rate = le16_to_cpu(igp_info->usDVISSpreadRateIn10Hz);
1426 break;
1427 case ASIC_INTERNAL_SS_ON_HDMI:
1428 percentage = le16_to_cpu(igp_info->usHDMISSPercentage);
1429 rate = le16_to_cpu(igp_info->usHDMISSpreadRateIn10Hz);
1430 break;
1431 case ASIC_INTERNAL_SS_ON_LVDS:
1432 percentage = le16_to_cpu(igp_info->usLvdsSSPercentage);
1433 rate = le16_to_cpu(igp_info->usLvdsSSpreadRateIn10Hz);
1434 break;
1435 }
1436 if (percentage)
1437 ss->percentage = percentage;
1438 if (rate)
1439 ss->rate = rate;
1440 }
1441}
1442
Alex Deucherba032a52010-10-04 17:13:01 -04001443union asic_ss_info {
1444 struct _ATOM_ASIC_INTERNAL_SS_INFO info;
1445 struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
1446 struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
1447};
1448
1449bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
1450 struct radeon_atom_ss *ss,
1451 int id, u32 clock)
1452{
1453 struct radeon_mode_info *mode_info = &rdev->mode_info;
1454 int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
1455 uint16_t data_offset, size;
1456 union asic_ss_info *ss_info;
1457 uint8_t frev, crev;
1458 int i, num_indices;
1459
1460 memset(ss, 0, sizeof(struct radeon_atom_ss));
1461 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1462 &frev, &crev, &data_offset)) {
1463
1464 ss_info =
1465 (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
1466
1467 switch (frev) {
1468 case 1:
1469 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1470 sizeof(ATOM_ASIC_SS_ASSIGNMENT);
1471
1472 for (i = 0; i < num_indices; i++) {
1473 if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
Cédric Cano45894332011-02-11 19:45:37 -05001474 (clock <= le32_to_cpu(ss_info->info.asSpreadSpectrum[i].ulTargetClockRange))) {
Alex Deucherba032a52010-10-04 17:13:01 -04001475 ss->percentage =
1476 le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1477 ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1478 ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
1479 return true;
1480 }
1481 }
1482 break;
1483 case 2:
1484 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1485 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
1486 for (i = 0; i < num_indices; i++) {
1487 if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
Cédric Cano45894332011-02-11 19:45:37 -05001488 (clock <= le32_to_cpu(ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange))) {
Alex Deucherba032a52010-10-04 17:13:01 -04001489 ss->percentage =
1490 le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1491 ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1492 ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
1493 return true;
1494 }
1495 }
1496 break;
1497 case 3:
1498 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1499 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
1500 for (i = 0; i < num_indices; i++) {
1501 if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
Cédric Cano45894332011-02-11 19:45:37 -05001502 (clock <= le32_to_cpu(ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange))) {
Alex Deucherba032a52010-10-04 17:13:01 -04001503 ss->percentage =
1504 le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1505 ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1506 ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
Alex Deucher4339c442010-11-22 17:56:25 -05001507 if (rdev->flags & RADEON_IS_IGP)
1508 radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
Alex Deucherba032a52010-10-04 17:13:01 -04001509 return true;
1510 }
1511 }
1512 break;
1513 default:
1514 DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
1515 break;
1516 }
1517
1518 }
1519 return false;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001520}
1521
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001522union lvds_info {
1523 struct _ATOM_LVDS_INFO info;
1524 struct _ATOM_LVDS_INFO_V12 info_12;
1525};
1526
1527struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1528 radeon_encoder
1529 *encoder)
1530{
1531 struct drm_device *dev = encoder->base.dev;
1532 struct radeon_device *rdev = dev->dev_private;
1533 struct radeon_mode_info *mode_info = &rdev->mode_info;
1534 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
Alex Deucher7dde8a192009-11-30 01:40:24 -05001535 uint16_t data_offset, misc;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001536 union lvds_info *lvds_info;
1537 uint8_t frev, crev;
1538 struct radeon_encoder_atom_dig *lvds = NULL;
Alex Deucher5137ee92010-08-12 18:58:47 -04001539 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001540
Alex Deuchera084e6e2010-03-18 01:04:01 -04001541 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1542 &frev, &crev, &data_offset)) {
1543 lvds_info =
1544 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001545 lvds =
1546 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1547
1548 if (!lvds)
1549 return NULL;
1550
Alex Deucherde2103e2009-10-09 15:14:30 -04001551 lvds->native_mode.clock =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001552 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
Alex Deucherde2103e2009-10-09 15:14:30 -04001553 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001554 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001555 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001556 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001557 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1558 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1559 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1560 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1561 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1562 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1563 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1564 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1565 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
Alex Deucher1ff26a32010-05-18 00:23:15 -04001566 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
Alex Deucherde2103e2009-10-09 15:14:30 -04001567 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1568 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001569 lvds->panel_pwr_delay =
1570 le16_to_cpu(lvds_info->info.usOffDelayInMs);
Alex Deucherba032a52010-10-04 17:13:01 -04001571 lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
Alex Deucher7dde8a192009-11-30 01:40:24 -05001572
1573 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1574 if (misc & ATOM_VSYNC_POLARITY)
1575 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1576 if (misc & ATOM_HSYNC_POLARITY)
1577 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1578 if (misc & ATOM_COMPOSITESYNC)
1579 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1580 if (misc & ATOM_INTERLACE)
1581 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1582 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1583 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1584
Cédric Cano45894332011-02-11 19:45:37 -05001585 lvds->native_mode.width_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageHSize);
1586 lvds->native_mode.height_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageVSize);
Alex Deucher7a868e12010-12-08 22:13:05 -05001587
Alex Deucherde2103e2009-10-09 15:14:30 -04001588 /* set crtc values */
1589 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001590
Alex Deucherba032a52010-10-04 17:13:01 -04001591 lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001592
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001593 encoder->native_mode = lvds->native_mode;
Alex Deucher5137ee92010-08-12 18:58:47 -04001594
1595 if (encoder_enum == 2)
1596 lvds->linkb = true;
1597 else
1598 lvds->linkb = false;
1599
Alex Deucherc324acd2010-12-08 22:13:06 -05001600 /* parse the lcd record table */
Cédric Cano45894332011-02-11 19:45:37 -05001601 if (le16_to_cpu(lvds_info->info.usModePatchTableOffset)) {
Alex Deucherc324acd2010-12-08 22:13:06 -05001602 ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
1603 ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
1604 bool bad_record = false;
Alex Deucher05fa7ea2011-05-11 14:02:07 -04001605 u8 *record;
1606
1607 if ((frev == 1) && (crev < 2))
1608 /* absolute */
1609 record = (u8 *)(mode_info->atom_context->bios +
1610 le16_to_cpu(lvds_info->info.usModePatchTableOffset));
1611 else
1612 /* relative */
1613 record = (u8 *)(mode_info->atom_context->bios +
1614 data_offset +
1615 le16_to_cpu(lvds_info->info.usModePatchTableOffset));
Alex Deucherc324acd2010-12-08 22:13:06 -05001616 while (*record != ATOM_RECORD_END_TYPE) {
1617 switch (*record) {
1618 case LCD_MODE_PATCH_RECORD_MODE_TYPE:
1619 record += sizeof(ATOM_PATCH_RECORD_MODE);
1620 break;
1621 case LCD_RTS_RECORD_TYPE:
1622 record += sizeof(ATOM_LCD_RTS_RECORD);
1623 break;
1624 case LCD_CAP_RECORD_TYPE:
1625 record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
1626 break;
1627 case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
1628 fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
1629 if (fake_edid_record->ucFakeEDIDLength) {
1630 struct edid *edid;
1631 int edid_size =
1632 max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
1633 edid = kmalloc(edid_size, GFP_KERNEL);
1634 if (edid) {
1635 memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
1636 fake_edid_record->ucFakeEDIDLength);
1637
Dave Airlieeaa4f5e2011-05-01 20:16:30 +10001638 if (drm_edid_is_valid(edid)) {
Alex Deucherc324acd2010-12-08 22:13:06 -05001639 rdev->mode_info.bios_hardcoded_edid = edid;
Dave Airlieeaa4f5e2011-05-01 20:16:30 +10001640 rdev->mode_info.bios_hardcoded_edid_size = edid_size;
1641 } else
Alex Deucherc324acd2010-12-08 22:13:06 -05001642 kfree(edid);
1643 }
1644 }
1645 record += sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
1646 break;
1647 case LCD_PANEL_RESOLUTION_RECORD_TYPE:
1648 panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
1649 lvds->native_mode.width_mm = panel_res_record->usHSize;
1650 lvds->native_mode.height_mm = panel_res_record->usVSize;
1651 record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
1652 break;
1653 default:
1654 DRM_ERROR("Bad LCD record %d\n", *record);
1655 bad_record = true;
1656 break;
1657 }
1658 if (bad_record)
1659 break;
1660 }
1661 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001662 }
1663 return lvds;
1664}
1665
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001666struct radeon_encoder_primary_dac *
1667radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1668{
1669 struct drm_device *dev = encoder->base.dev;
1670 struct radeon_device *rdev = dev->dev_private;
1671 struct radeon_mode_info *mode_info = &rdev->mode_info;
1672 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1673 uint16_t data_offset;
1674 struct _COMPASSIONATE_DATA *dac_info;
1675 uint8_t frev, crev;
1676 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001677 struct radeon_encoder_primary_dac *p_dac = NULL;
1678
Alex Deuchera084e6e2010-03-18 01:04:01 -04001679 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1680 &frev, &crev, &data_offset)) {
1681 dac_info = (struct _COMPASSIONATE_DATA *)
1682 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001683
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001684 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1685
1686 if (!p_dac)
1687 return NULL;
1688
1689 bg = dac_info->ucDAC1_BG_Adjustment;
1690 dac = dac_info->ucDAC1_DAC_Adjustment;
1691 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1692
1693 }
1694 return p_dac;
1695}
1696
Dave Airlie4ce001a2009-08-13 16:32:14 +10001697bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001698 struct drm_display_mode *mode)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001699{
1700 struct radeon_mode_info *mode_info = &rdev->mode_info;
1701 ATOM_ANALOG_TV_INFO *tv_info;
1702 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1703 ATOM_DTD_FORMAT *dtd_timings;
1704 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1705 u8 frev, crev;
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001706 u16 data_offset, misc;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001707
Alex Deuchera084e6e2010-03-18 01:04:01 -04001708 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1709 &frev, &crev, &data_offset))
1710 return false;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001711
1712 switch (crev) {
1713 case 1:
1714 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001715 if (index >= MAX_SUPPORTED_TV_TIMING)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001716 return false;
1717
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001718 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1719 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1720 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1721 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1722 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001723
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001724 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1725 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1726 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1727 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1728 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001729
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001730 mode->flags = 0;
1731 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1732 if (misc & ATOM_VSYNC_POLARITY)
1733 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1734 if (misc & ATOM_HSYNC_POLARITY)
1735 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1736 if (misc & ATOM_COMPOSITESYNC)
1737 mode->flags |= DRM_MODE_FLAG_CSYNC;
1738 if (misc & ATOM_INTERLACE)
1739 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1740 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1741 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001742
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001743 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001744
1745 if (index == 1) {
1746 /* PAL timings appear to have wrong values for totals */
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001747 mode->crtc_htotal -= 1;
1748 mode->crtc_vtotal -= 1;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001749 }
1750 break;
1751 case 2:
1752 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001753 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001754 return false;
1755
1756 dtd_timings = &tv_info_v1_2->aModeTimings[index];
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001757 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1758 le16_to_cpu(dtd_timings->usHBlanking_Time);
1759 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1760 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1761 le16_to_cpu(dtd_timings->usHSyncOffset);
1762 mode->crtc_hsync_end = mode->crtc_hsync_start +
1763 le16_to_cpu(dtd_timings->usHSyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001764
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001765 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1766 le16_to_cpu(dtd_timings->usVBlanking_Time);
1767 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1768 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1769 le16_to_cpu(dtd_timings->usVSyncOffset);
1770 mode->crtc_vsync_end = mode->crtc_vsync_start +
1771 le16_to_cpu(dtd_timings->usVSyncWidth);
1772
1773 mode->flags = 0;
1774 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1775 if (misc & ATOM_VSYNC_POLARITY)
1776 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1777 if (misc & ATOM_HSYNC_POLARITY)
1778 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1779 if (misc & ATOM_COMPOSITESYNC)
1780 mode->flags |= DRM_MODE_FLAG_CSYNC;
1781 if (misc & ATOM_INTERLACE)
1782 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1783 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1784 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1785
1786 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001787 break;
1788 }
1789 return true;
1790}
1791
Alex Deucherd79766f2009-12-17 19:00:29 -05001792enum radeon_tv_std
1793radeon_atombios_get_tv_info(struct radeon_device *rdev)
1794{
1795 struct radeon_mode_info *mode_info = &rdev->mode_info;
1796 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1797 uint16_t data_offset;
1798 uint8_t frev, crev;
1799 struct _ATOM_ANALOG_TV_INFO *tv_info;
1800 enum radeon_tv_std tv_std = TV_STD_NTSC;
1801
Alex Deuchera084e6e2010-03-18 01:04:01 -04001802 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1803 &frev, &crev, &data_offset)) {
Alex Deucherd79766f2009-12-17 19:00:29 -05001804
Alex Deuchera084e6e2010-03-18 01:04:01 -04001805 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1806 (mode_info->atom_context->bios + data_offset);
Alex Deucherd79766f2009-12-17 19:00:29 -05001807
Alex Deuchera084e6e2010-03-18 01:04:01 -04001808 switch (tv_info->ucTV_BootUpDefaultStandard) {
1809 case ATOM_TV_NTSC:
1810 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001811 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001812 break;
1813 case ATOM_TV_NTSCJ:
1814 tv_std = TV_STD_NTSC_J;
Alex Deucher40f76d82010-10-07 22:38:42 -04001815 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001816 break;
1817 case ATOM_TV_PAL:
1818 tv_std = TV_STD_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -04001819 DRM_DEBUG_KMS("Default TV standard: PAL\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001820 break;
1821 case ATOM_TV_PALM:
1822 tv_std = TV_STD_PAL_M;
Alex Deucher40f76d82010-10-07 22:38:42 -04001823 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001824 break;
1825 case ATOM_TV_PALN:
1826 tv_std = TV_STD_PAL_N;
Alex Deucher40f76d82010-10-07 22:38:42 -04001827 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001828 break;
1829 case ATOM_TV_PALCN:
1830 tv_std = TV_STD_PAL_CN;
Alex Deucher40f76d82010-10-07 22:38:42 -04001831 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001832 break;
1833 case ATOM_TV_PAL60:
1834 tv_std = TV_STD_PAL_60;
Alex Deucher40f76d82010-10-07 22:38:42 -04001835 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001836 break;
1837 case ATOM_TV_SECAM:
1838 tv_std = TV_STD_SECAM;
Alex Deucher40f76d82010-10-07 22:38:42 -04001839 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001840 break;
1841 default:
1842 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001843 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001844 break;
1845 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001846 }
1847 return tv_std;
1848}
1849
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001850struct radeon_encoder_tv_dac *
1851radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1852{
1853 struct drm_device *dev = encoder->base.dev;
1854 struct radeon_device *rdev = dev->dev_private;
1855 struct radeon_mode_info *mode_info = &rdev->mode_info;
1856 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1857 uint16_t data_offset;
1858 struct _COMPASSIONATE_DATA *dac_info;
1859 uint8_t frev, crev;
1860 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001861 struct radeon_encoder_tv_dac *tv_dac = NULL;
1862
Alex Deuchera084e6e2010-03-18 01:04:01 -04001863 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1864 &frev, &crev, &data_offset)) {
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001865
Alex Deuchera084e6e2010-03-18 01:04:01 -04001866 dac_info = (struct _COMPASSIONATE_DATA *)
1867 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001868
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001869 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1870
1871 if (!tv_dac)
1872 return NULL;
1873
1874 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1875 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1876 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1877
1878 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1879 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1880 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1881
1882 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1883 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1884 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1885
Alex Deucherd79766f2009-12-17 19:00:29 -05001886 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001887 }
1888 return tv_dac;
1889}
1890
Alex Deucher29fb52c2010-03-11 10:01:17 -05001891static const char *thermal_controller_names[] = {
1892 "NONE",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001893 "lm63",
1894 "adm1032",
1895 "adm1030",
1896 "max6649",
1897 "lm64",
1898 "f75375",
1899 "asc7xxx",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001900};
1901
1902static const char *pp_lib_thermal_controller_names[] = {
1903 "NONE",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001904 "lm63",
1905 "adm1032",
1906 "adm1030",
1907 "max6649",
1908 "lm64",
1909 "f75375",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001910 "RV6xx",
1911 "RV770",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001912 "adt7473",
Alex Deucher560154e2010-11-22 17:56:34 -05001913 "NONE",
Alex Deucher49f65982010-03-24 16:39:45 -04001914 "External GPIO",
1915 "Evergreen",
Alex Deucherb0e66412010-11-22 17:56:35 -05001916 "emc2103",
1917 "Sumo",
Alex Deucher4fddba12011-01-06 21:19:22 -05001918 "Northern Islands",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001919};
1920
Alex Deucher56278a82009-12-28 13:58:44 -05001921union power_info {
1922 struct _ATOM_POWERPLAY_INFO info;
1923 struct _ATOM_POWERPLAY_INFO_V2 info_2;
1924 struct _ATOM_POWERPLAY_INFO_V3 info_3;
Alex Deucher560154e2010-11-22 17:56:34 -05001925 struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
Alex Deucherb0e66412010-11-22 17:56:35 -05001926 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
1927 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
Alex Deucher56278a82009-12-28 13:58:44 -05001928};
1929
Alex Deucher560154e2010-11-22 17:56:34 -05001930union pplib_clock_info {
1931 struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
1932 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
1933 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
Alex Deucherb0e66412010-11-22 17:56:35 -05001934 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
Alex Deucher560154e2010-11-22 17:56:34 -05001935};
1936
1937union pplib_power_state {
1938 struct _ATOM_PPLIB_STATE v1;
1939 struct _ATOM_PPLIB_STATE_V2 v2;
1940};
1941
1942static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
1943 int state_index,
1944 u32 misc, u32 misc2)
1945{
1946 rdev->pm.power_state[state_index].misc = misc;
1947 rdev->pm.power_state[state_index].misc2 = misc2;
1948 /* order matters! */
1949 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1950 rdev->pm.power_state[state_index].type =
1951 POWER_STATE_TYPE_POWERSAVE;
1952 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1953 rdev->pm.power_state[state_index].type =
1954 POWER_STATE_TYPE_BATTERY;
1955 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1956 rdev->pm.power_state[state_index].type =
1957 POWER_STATE_TYPE_BATTERY;
1958 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1959 rdev->pm.power_state[state_index].type =
1960 POWER_STATE_TYPE_BALANCED;
1961 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
1962 rdev->pm.power_state[state_index].type =
1963 POWER_STATE_TYPE_PERFORMANCE;
1964 rdev->pm.power_state[state_index].flags &=
1965 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1966 }
1967 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1968 rdev->pm.power_state[state_index].type =
1969 POWER_STATE_TYPE_BALANCED;
1970 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
1971 rdev->pm.power_state[state_index].type =
1972 POWER_STATE_TYPE_DEFAULT;
1973 rdev->pm.default_power_state_index = state_index;
1974 rdev->pm.power_state[state_index].default_clock_mode =
1975 &rdev->pm.power_state[state_index].clock_info[0];
1976 } else if (state_index == 0) {
1977 rdev->pm.power_state[state_index].clock_info[0].flags |=
1978 RADEON_PM_MODE_NO_DISPLAY;
1979 }
1980}
1981
1982static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
1983{
1984 struct radeon_mode_info *mode_info = &rdev->mode_info;
1985 u32 misc, misc2 = 0;
1986 int num_modes = 0, i;
1987 int state_index = 0;
1988 struct radeon_i2c_bus_rec i2c_bus;
1989 union power_info *power_info;
1990 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
1991 u16 data_offset;
1992 u8 frev, crev;
1993
1994 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
1995 &frev, &crev, &data_offset))
1996 return state_index;
1997 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
1998
1999 /* add the i2c bus for thermal/fan chip */
2000 if (power_info->info.ucOverdriveThermalController > 0) {
2001 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2002 thermal_controller_names[power_info->info.ucOverdriveThermalController],
2003 power_info->info.ucOverdriveControllerAddress >> 1);
2004 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
2005 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2006 if (rdev->pm.i2c_bus) {
2007 struct i2c_board_info info = { };
2008 const char *name = thermal_controller_names[power_info->info.
2009 ucOverdriveThermalController];
2010 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
2011 strlcpy(info.type, name, sizeof(info.type));
2012 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2013 }
2014 }
2015 num_modes = power_info->info.ucNumOfPowerModeEntries;
2016 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
2017 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
Alex Deucher0975b162011-02-02 18:42:03 -05002018 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
2019 if (!rdev->pm.power_state)
2020 return state_index;
Alex Deucher560154e2010-11-22 17:56:34 -05002021 /* last mode is usually default, array is low to high */
2022 for (i = 0; i < num_modes; i++) {
Alex Deucher6991b8f2011-11-14 17:52:51 -05002023 rdev->pm.power_state[state_index].clock_info =
2024 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2025 if (!rdev->pm.power_state[state_index].clock_info)
2026 return state_index;
2027 rdev->pm.power_state[state_index].num_clock_modes = 1;
Alex Deucher560154e2010-11-22 17:56:34 -05002028 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2029 switch (frev) {
2030 case 1:
Alex Deucher560154e2010-11-22 17:56:34 -05002031 rdev->pm.power_state[state_index].clock_info[0].mclk =
2032 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
2033 rdev->pm.power_state[state_index].clock_info[0].sclk =
2034 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
2035 /* skip invalid modes */
2036 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2037 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2038 continue;
2039 rdev->pm.power_state[state_index].pcie_lanes =
2040 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
2041 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
2042 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2043 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2044 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2045 VOLTAGE_GPIO;
2046 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2047 radeon_lookup_gpio(rdev,
2048 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
2049 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2050 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2051 true;
2052 else
2053 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2054 false;
2055 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2056 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2057 VOLTAGE_VDDC;
2058 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2059 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
2060 }
2061 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2062 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
2063 state_index++;
2064 break;
2065 case 2:
Alex Deucher560154e2010-11-22 17:56:34 -05002066 rdev->pm.power_state[state_index].clock_info[0].mclk =
2067 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
2068 rdev->pm.power_state[state_index].clock_info[0].sclk =
2069 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
2070 /* skip invalid modes */
2071 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2072 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2073 continue;
2074 rdev->pm.power_state[state_index].pcie_lanes =
2075 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
2076 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
2077 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
2078 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2079 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2080 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2081 VOLTAGE_GPIO;
2082 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2083 radeon_lookup_gpio(rdev,
2084 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
2085 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2086 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2087 true;
2088 else
2089 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2090 false;
2091 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2092 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2093 VOLTAGE_VDDC;
2094 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2095 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
2096 }
2097 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2098 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2099 state_index++;
2100 break;
2101 case 3:
Alex Deucher560154e2010-11-22 17:56:34 -05002102 rdev->pm.power_state[state_index].clock_info[0].mclk =
2103 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
2104 rdev->pm.power_state[state_index].clock_info[0].sclk =
2105 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
2106 /* skip invalid modes */
2107 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2108 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2109 continue;
2110 rdev->pm.power_state[state_index].pcie_lanes =
2111 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
2112 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
2113 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
2114 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2115 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2116 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2117 VOLTAGE_GPIO;
2118 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2119 radeon_lookup_gpio(rdev,
2120 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
2121 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2122 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2123 true;
2124 else
2125 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2126 false;
2127 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2128 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2129 VOLTAGE_VDDC;
2130 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2131 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
2132 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
2133 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
2134 true;
2135 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
2136 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
2137 }
2138 }
2139 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2140 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2141 state_index++;
2142 break;
2143 }
2144 }
2145 /* last mode is usually default */
2146 if (rdev->pm.default_power_state_index == -1) {
2147 rdev->pm.power_state[state_index - 1].type =
2148 POWER_STATE_TYPE_DEFAULT;
2149 rdev->pm.default_power_state_index = state_index - 1;
2150 rdev->pm.power_state[state_index - 1].default_clock_mode =
2151 &rdev->pm.power_state[state_index - 1].clock_info[0];
2152 rdev->pm.power_state[state_index].flags &=
2153 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2154 rdev->pm.power_state[state_index].misc = 0;
2155 rdev->pm.power_state[state_index].misc2 = 0;
2156 }
2157 return state_index;
2158}
2159
2160static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
2161 ATOM_PPLIB_THERMALCONTROLLER *controller)
2162{
2163 struct radeon_i2c_bus_rec i2c_bus;
2164
2165 /* add the i2c bus for thermal/fan chip */
2166 if (controller->ucType > 0) {
2167 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
2168 DRM_INFO("Internal thermal controller %s fan control\n",
2169 (controller->ucFanParameters &
2170 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2171 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
2172 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
2173 DRM_INFO("Internal thermal controller %s fan control\n",
2174 (controller->ucFanParameters &
2175 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2176 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
2177 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
2178 DRM_INFO("Internal thermal controller %s fan control\n",
2179 (controller->ucFanParameters &
2180 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2181 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
Alex Deucherb0e66412010-11-22 17:56:35 -05002182 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
2183 DRM_INFO("Internal thermal controller %s fan control\n",
2184 (controller->ucFanParameters &
2185 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2186 rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
Alex Deucher4fddba12011-01-06 21:19:22 -05002187 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
2188 DRM_INFO("Internal thermal controller %s fan control\n",
2189 (controller->ucFanParameters &
2190 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2191 rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
Alex Deucher560154e2010-11-22 17:56:34 -05002192 } else if ((controller->ucType ==
2193 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
2194 (controller->ucType ==
Alex Deucherb0e66412010-11-22 17:56:35 -05002195 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
2196 (controller->ucType ==
2197 ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002198 DRM_INFO("Special thermal controller config\n");
2199 } else {
2200 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2201 pp_lib_thermal_controller_names[controller->ucType],
2202 controller->ucI2cAddress >> 1,
2203 (controller->ucFanParameters &
2204 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2205 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
2206 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2207 if (rdev->pm.i2c_bus) {
2208 struct i2c_board_info info = { };
2209 const char *name = pp_lib_thermal_controller_names[controller->ucType];
2210 info.addr = controller->ucI2cAddress >> 1;
2211 strlcpy(info.type, name, sizeof(info.type));
2212 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2213 }
2214 }
2215 }
2216}
2217
Alex Deucher2feea492011-04-12 14:49:24 -04002218static void radeon_atombios_get_default_voltages(struct radeon_device *rdev,
2219 u16 *vddc, u16 *vddci)
Alex Deucher560154e2010-11-22 17:56:34 -05002220{
2221 struct radeon_mode_info *mode_info = &rdev->mode_info;
2222 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
2223 u8 frev, crev;
2224 u16 data_offset;
2225 union firmware_info *firmware_info;
Alex Deucher2feea492011-04-12 14:49:24 -04002226
2227 *vddc = 0;
2228 *vddci = 0;
Alex Deucher560154e2010-11-22 17:56:34 -05002229
2230 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2231 &frev, &crev, &data_offset)) {
2232 firmware_info =
2233 (union firmware_info *)(mode_info->atom_context->bios +
2234 data_offset);
Alex Deucher2feea492011-04-12 14:49:24 -04002235 *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
2236 if ((frev == 2) && (crev >= 2))
2237 *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
Alex Deucher560154e2010-11-22 17:56:34 -05002238 }
Alex Deucher560154e2010-11-22 17:56:34 -05002239}
2240
2241static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
2242 int state_index, int mode_index,
2243 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
2244{
2245 int j;
2246 u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
2247 u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
Alex Deucher2feea492011-04-12 14:49:24 -04002248 u16 vddc, vddci;
2249
2250 radeon_atombios_get_default_voltages(rdev, &vddc, &vddci);
Alex Deucher560154e2010-11-22 17:56:34 -05002251
2252 rdev->pm.power_state[state_index].misc = misc;
2253 rdev->pm.power_state[state_index].misc2 = misc2;
2254 rdev->pm.power_state[state_index].pcie_lanes =
2255 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2256 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2257 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2258 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2259 rdev->pm.power_state[state_index].type =
2260 POWER_STATE_TYPE_BATTERY;
2261 break;
2262 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2263 rdev->pm.power_state[state_index].type =
2264 POWER_STATE_TYPE_BALANCED;
2265 break;
2266 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2267 rdev->pm.power_state[state_index].type =
2268 POWER_STATE_TYPE_PERFORMANCE;
2269 break;
2270 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2271 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2272 rdev->pm.power_state[state_index].type =
2273 POWER_STATE_TYPE_PERFORMANCE;
2274 break;
2275 }
2276 rdev->pm.power_state[state_index].flags = 0;
2277 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2278 rdev->pm.power_state[state_index].flags |=
2279 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2280 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
2281 rdev->pm.power_state[state_index].type =
2282 POWER_STATE_TYPE_DEFAULT;
2283 rdev->pm.default_power_state_index = state_index;
2284 rdev->pm.power_state[state_index].default_clock_mode =
2285 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002286 if (ASIC_IS_DCE5(rdev) && !(rdev->flags & RADEON_IS_IGP)) {
Alex Deucher9ace9f72011-01-06 21:19:26 -05002287 /* NI chips post without MC ucode, so default clocks are strobe mode only */
2288 rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
2289 rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
2290 rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
Alex Deucher2feea492011-04-12 14:49:24 -04002291 rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
Alex Deucher9ace9f72011-01-06 21:19:26 -05002292 } else {
2293 /* patch the table values with the default slck/mclk from firmware info */
2294 for (j = 0; j < mode_index; j++) {
2295 rdev->pm.power_state[state_index].clock_info[j].mclk =
2296 rdev->clock.default_mclk;
2297 rdev->pm.power_state[state_index].clock_info[j].sclk =
2298 rdev->clock.default_sclk;
2299 if (vddc)
2300 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2301 vddc;
2302 }
Alex Deucher560154e2010-11-22 17:56:34 -05002303 }
2304 }
2305}
2306
2307static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
2308 int state_index, int mode_index,
2309 union pplib_clock_info *clock_info)
2310{
2311 u32 sclk, mclk;
2312
2313 if (rdev->flags & RADEON_IS_IGP) {
Alex Deucherb0e66412010-11-22 17:56:35 -05002314 if (rdev->family >= CHIP_PALM) {
2315 sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
2316 sclk |= clock_info->sumo.ucEngineClockHigh << 16;
2317 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2318 } else {
2319 sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
2320 sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
2321 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2322 }
Alex Deucher560154e2010-11-22 17:56:34 -05002323 } else if (ASIC_IS_DCE4(rdev)) {
2324 sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
2325 sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
2326 mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
2327 mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
2328 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2329 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2330 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2331 VOLTAGE_SW;
2332 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
Cédric Cano45894332011-02-11 19:45:37 -05002333 le16_to_cpu(clock_info->evergreen.usVDDC);
Alex Deucher2feea492011-04-12 14:49:24 -04002334 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
2335 le16_to_cpu(clock_info->evergreen.usVDDCI);
Alex Deucher560154e2010-11-22 17:56:34 -05002336 } else {
2337 sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
2338 sclk |= clock_info->r600.ucEngineClockHigh << 16;
2339 mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
2340 mclk |= clock_info->r600.ucMemoryClockHigh << 16;
2341 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2342 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2343 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2344 VOLTAGE_SW;
2345 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
Cédric Cano45894332011-02-11 19:45:37 -05002346 le16_to_cpu(clock_info->r600.usVDDC);
Alex Deucher560154e2010-11-22 17:56:34 -05002347 }
2348
Alex Deucheree4017f2011-06-23 12:19:32 -04002349 /* patch up vddc if necessary */
2350 if (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage == 0xff01) {
2351 u16 vddc;
2352
2353 if (radeon_atom_get_max_vddc(rdev, &vddc) == 0)
2354 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
2355 }
2356
Alex Deucher560154e2010-11-22 17:56:34 -05002357 if (rdev->flags & RADEON_IS_IGP) {
2358 /* skip invalid modes */
2359 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2360 return false;
2361 } else {
2362 /* skip invalid modes */
2363 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2364 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2365 return false;
2366 }
2367 return true;
2368}
2369
2370static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
2371{
2372 struct radeon_mode_info *mode_info = &rdev->mode_info;
2373 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2374 union pplib_power_state *power_state;
2375 int i, j;
2376 int state_index = 0, mode_index = 0;
2377 union pplib_clock_info *clock_info;
2378 bool valid;
2379 union power_info *power_info;
2380 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2381 u16 data_offset;
2382 u8 frev, crev;
2383
2384 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2385 &frev, &crev, &data_offset))
2386 return state_index;
2387 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2388
2389 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
Alex Deucher0975b162011-02-02 18:42:03 -05002390 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2391 power_info->pplib.ucNumStates, GFP_KERNEL);
2392 if (!rdev->pm.power_state)
2393 return state_index;
Alex Deucher560154e2010-11-22 17:56:34 -05002394 /* first mode is usually default, followed by low to high */
2395 for (i = 0; i < power_info->pplib.ucNumStates; i++) {
2396 mode_index = 0;
2397 power_state = (union pplib_power_state *)
2398 (mode_info->atom_context->bios + data_offset +
2399 le16_to_cpu(power_info->pplib.usStateArrayOffset) +
2400 i * power_info->pplib.ucStateEntrySize);
2401 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2402 (mode_info->atom_context->bios + data_offset +
2403 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
2404 (power_state->v1.ucNonClockStateIndex *
2405 power_info->pplib.ucNonClockSize));
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002406 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2407 ((power_info->pplib.ucStateEntrySize - 1) ?
2408 (power_info->pplib.ucStateEntrySize - 1) : 1),
2409 GFP_KERNEL);
2410 if (!rdev->pm.power_state[i].clock_info)
2411 return state_index;
2412 if (power_info->pplib.ucStateEntrySize - 1) {
2413 for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
2414 clock_info = (union pplib_clock_info *)
2415 (mode_info->atom_context->bios + data_offset +
2416 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
2417 (power_state->v1.ucClockStateIndices[j] *
2418 power_info->pplib.ucClockInfoSize));
2419 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2420 state_index, mode_index,
2421 clock_info);
2422 if (valid)
2423 mode_index++;
2424 }
2425 } else {
2426 rdev->pm.power_state[state_index].clock_info[0].mclk =
2427 rdev->clock.default_mclk;
2428 rdev->pm.power_state[state_index].clock_info[0].sclk =
2429 rdev->clock.default_sclk;
2430 mode_index++;
Alex Deucher560154e2010-11-22 17:56:34 -05002431 }
2432 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2433 if (mode_index) {
2434 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2435 non_clock_info);
2436 state_index++;
2437 }
2438 }
2439 /* if multiple clock modes, mark the lowest as no display */
2440 for (i = 0; i < state_index; i++) {
2441 if (rdev->pm.power_state[i].num_clock_modes > 1)
2442 rdev->pm.power_state[i].clock_info[0].flags |=
2443 RADEON_PM_MODE_NO_DISPLAY;
2444 }
2445 /* first mode is usually default */
2446 if (rdev->pm.default_power_state_index == -1) {
2447 rdev->pm.power_state[0].type =
2448 POWER_STATE_TYPE_DEFAULT;
2449 rdev->pm.default_power_state_index = 0;
2450 rdev->pm.power_state[0].default_clock_mode =
2451 &rdev->pm.power_state[0].clock_info[0];
2452 }
2453 return state_index;
2454}
2455
Alex Deucherb0e66412010-11-22 17:56:35 -05002456static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
2457{
2458 struct radeon_mode_info *mode_info = &rdev->mode_info;
2459 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2460 union pplib_power_state *power_state;
2461 int i, j, non_clock_array_index, clock_array_index;
2462 int state_index = 0, mode_index = 0;
2463 union pplib_clock_info *clock_info;
2464 struct StateArray *state_array;
2465 struct ClockInfoArray *clock_info_array;
2466 struct NonClockInfoArray *non_clock_info_array;
2467 bool valid;
2468 union power_info *power_info;
2469 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2470 u16 data_offset;
2471 u8 frev, crev;
2472
2473 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2474 &frev, &crev, &data_offset))
2475 return state_index;
2476 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2477
2478 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
2479 state_array = (struct StateArray *)
2480 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002481 le16_to_cpu(power_info->pplib.usStateArrayOffset));
Alex Deucherb0e66412010-11-22 17:56:35 -05002482 clock_info_array = (struct ClockInfoArray *)
2483 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002484 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
Alex Deucherb0e66412010-11-22 17:56:35 -05002485 non_clock_info_array = (struct NonClockInfoArray *)
2486 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002487 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
Alex Deucher0975b162011-02-02 18:42:03 -05002488 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2489 state_array->ucNumEntries, GFP_KERNEL);
2490 if (!rdev->pm.power_state)
2491 return state_index;
Alex Deucherb0e66412010-11-22 17:56:35 -05002492 for (i = 0; i < state_array->ucNumEntries; i++) {
2493 mode_index = 0;
2494 power_state = (union pplib_power_state *)&state_array->states[i];
2495 /* XXX this might be an inagua bug... */
2496 non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
2497 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2498 &non_clock_info_array->nonClockInfo[non_clock_array_index];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002499 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2500 (power_state->v2.ucNumDPMLevels ?
2501 power_state->v2.ucNumDPMLevels : 1),
2502 GFP_KERNEL);
2503 if (!rdev->pm.power_state[i].clock_info)
2504 return state_index;
2505 if (power_state->v2.ucNumDPMLevels) {
2506 for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2507 clock_array_index = power_state->v2.clockInfoIndex[j];
2508 /* XXX this might be an inagua bug... */
2509 if (clock_array_index >= clock_info_array->ucNumEntries)
2510 continue;
2511 clock_info = (union pplib_clock_info *)
2512 &clock_info_array->clockInfo[clock_array_index];
2513 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2514 state_index, mode_index,
2515 clock_info);
2516 if (valid)
2517 mode_index++;
2518 }
2519 } else {
2520 rdev->pm.power_state[state_index].clock_info[0].mclk =
2521 rdev->clock.default_mclk;
2522 rdev->pm.power_state[state_index].clock_info[0].sclk =
2523 rdev->clock.default_sclk;
2524 mode_index++;
Alex Deucherb0e66412010-11-22 17:56:35 -05002525 }
2526 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2527 if (mode_index) {
2528 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2529 non_clock_info);
2530 state_index++;
2531 }
2532 }
2533 /* if multiple clock modes, mark the lowest as no display */
2534 for (i = 0; i < state_index; i++) {
2535 if (rdev->pm.power_state[i].num_clock_modes > 1)
2536 rdev->pm.power_state[i].clock_info[0].flags |=
2537 RADEON_PM_MODE_NO_DISPLAY;
2538 }
2539 /* first mode is usually default */
2540 if (rdev->pm.default_power_state_index == -1) {
2541 rdev->pm.power_state[0].type =
2542 POWER_STATE_TYPE_DEFAULT;
2543 rdev->pm.default_power_state_index = 0;
2544 rdev->pm.power_state[0].default_clock_mode =
2545 &rdev->pm.power_state[0].clock_info[0];
2546 }
2547 return state_index;
2548}
2549
Alex Deucher56278a82009-12-28 13:58:44 -05002550void radeon_atombios_get_power_modes(struct radeon_device *rdev)
2551{
2552 struct radeon_mode_info *mode_info = &rdev->mode_info;
2553 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2554 u16 data_offset;
2555 u8 frev, crev;
Alex Deucher560154e2010-11-22 17:56:34 -05002556 int state_index = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002557
Alex Deuchera48b9b42010-04-22 14:03:55 -04002558 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05002559
Alex Deuchera084e6e2010-03-18 01:04:01 -04002560 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2561 &frev, &crev, &data_offset)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002562 switch (frev) {
2563 case 1:
2564 case 2:
2565 case 3:
2566 state_index = radeon_atombios_parse_power_table_1_3(rdev);
2567 break;
2568 case 4:
2569 case 5:
2570 state_index = radeon_atombios_parse_power_table_4_5(rdev);
2571 break;
Alex Deucherb0e66412010-11-22 17:56:35 -05002572 case 6:
2573 state_index = radeon_atombios_parse_power_table_6(rdev);
2574 break;
Alex Deucher560154e2010-11-22 17:56:34 -05002575 default:
2576 break;
Alex Deucher56278a82009-12-28 13:58:44 -05002577 }
2578 } else {
Alex Deucher0975b162011-02-02 18:42:03 -05002579 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
2580 if (rdev->pm.power_state) {
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002581 rdev->pm.power_state[0].clock_info =
2582 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2583 if (rdev->pm.power_state[0].clock_info) {
2584 /* add the default mode */
2585 rdev->pm.power_state[state_index].type =
2586 POWER_STATE_TYPE_DEFAULT;
2587 rdev->pm.power_state[state_index].num_clock_modes = 1;
2588 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2589 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2590 rdev->pm.power_state[state_index].default_clock_mode =
2591 &rdev->pm.power_state[state_index].clock_info[0];
2592 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2593 rdev->pm.power_state[state_index].pcie_lanes = 16;
2594 rdev->pm.default_power_state_index = state_index;
2595 rdev->pm.power_state[state_index].flags = 0;
2596 state_index++;
2597 }
Alex Deucher0975b162011-02-02 18:42:03 -05002598 }
Alex Deucher56278a82009-12-28 13:58:44 -05002599 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002600
Alex Deucher56278a82009-12-28 13:58:44 -05002601 rdev->pm.num_power_states = state_index;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002602
Alex Deuchera48b9b42010-04-22 14:03:55 -04002603 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2604 rdev->pm.current_clock_mode_index = 0;
Alex Deucher4d601732010-06-07 18:15:18 -04002605 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 -05002606}
2607
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002608void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2609{
2610 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2611 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2612
2613 args.ucEnable = enable;
2614
2615 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2616}
2617
Rafał Miłecki74338742009-11-03 00:53:02 +01002618uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2619{
2620 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2621 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2622
2623 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
Cédric Cano45894332011-02-11 19:45:37 -05002624 return le32_to_cpu(args.ulReturnEngineClock);
Rafał Miłecki74338742009-11-03 00:53:02 +01002625}
2626
2627uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2628{
2629 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2630 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2631
2632 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
Cédric Cano45894332011-02-11 19:45:37 -05002633 return le32_to_cpu(args.ulReturnMemoryClock);
Rafał Miłecki74338742009-11-03 00:53:02 +01002634}
2635
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002636void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2637 uint32_t eng_clock)
2638{
2639 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2640 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2641
Cédric Cano45894332011-02-11 19:45:37 -05002642 args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002643
2644 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2645}
2646
2647void radeon_atom_set_memory_clock(struct radeon_device *rdev,
2648 uint32_t mem_clock)
2649{
2650 SET_MEMORY_CLOCK_PS_ALLOCATION args;
2651 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
2652
2653 if (rdev->flags & RADEON_IS_IGP)
2654 return;
2655
Cédric Cano45894332011-02-11 19:45:37 -05002656 args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002657
2658 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2659}
2660
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002661union set_voltage {
2662 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2663 struct _SET_VOLTAGE_PARAMETERS v1;
2664 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2665};
2666
Alex Deucher8a83ec52011-04-12 14:49:23 -04002667void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002668{
2669 union set_voltage args;
2670 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
Alex Deucher8a83ec52011-04-12 14:49:23 -04002671 u8 frev, crev, volt_index = voltage_level;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002672
2673 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2674 return;
2675
Alex Deuchera377e182011-06-20 13:00:31 -04002676 /* 0xff01 is a flag rather then an actual voltage */
2677 if (voltage_level == 0xff01)
2678 return;
2679
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002680 switch (crev) {
2681 case 1:
Alex Deucher8a83ec52011-04-12 14:49:23 -04002682 args.v1.ucVoltageType = voltage_type;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002683 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
2684 args.v1.ucVoltageIndex = volt_index;
2685 break;
2686 case 2:
Alex Deucher8a83ec52011-04-12 14:49:23 -04002687 args.v2.ucVoltageType = voltage_type;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002688 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
Alex Deucher8a83ec52011-04-12 14:49:23 -04002689 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002690 break;
2691 default:
2692 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2693 return;
2694 }
2695
2696 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2697}
2698
Alex Deucheree4017f2011-06-23 12:19:32 -04002699int radeon_atom_get_max_vddc(struct radeon_device *rdev,
2700 u16 *voltage)
2701{
2702 union set_voltage args;
2703 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
2704 u8 frev, crev;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002705
Alex Deucheree4017f2011-06-23 12:19:32 -04002706 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2707 return -EINVAL;
2708
2709 switch (crev) {
2710 case 1:
2711 return -EINVAL;
2712 case 2:
2713 args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
2714 args.v2.ucVoltageMode = 0;
2715 args.v2.usVoltageLevel = 0;
2716
2717 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2718
2719 *voltage = le16_to_cpu(args.v2.usVoltageLevel);
2720 break;
2721 default:
2722 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2723 return -EINVAL;
2724 }
2725
2726 return 0;
2727}
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002728
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002729void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
2730{
2731 struct radeon_device *rdev = dev->dev_private;
2732 uint32_t bios_2_scratch, bios_6_scratch;
2733
2734 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002735 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002736 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2737 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002738 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002739 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2740 }
2741
2742 /* let the bios control the backlight */
2743 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
2744
2745 /* tell the bios not to handle mode switching */
Alex Deucher87364762011-02-02 19:46:06 -05002746 bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002747
2748 if (rdev->family >= CHIP_R600) {
2749 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2750 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2751 } else {
2752 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2753 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2754 }
2755
2756}
2757
Yang Zhaof657c2a2009-09-15 12:21:01 +10002758void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
2759{
2760 uint32_t scratch_reg;
2761 int i;
2762
2763 if (rdev->family >= CHIP_R600)
2764 scratch_reg = R600_BIOS_0_SCRATCH;
2765 else
2766 scratch_reg = RADEON_BIOS_0_SCRATCH;
2767
2768 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2769 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
2770}
2771
2772void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
2773{
2774 uint32_t scratch_reg;
2775 int i;
2776
2777 if (rdev->family >= CHIP_R600)
2778 scratch_reg = R600_BIOS_0_SCRATCH;
2779 else
2780 scratch_reg = RADEON_BIOS_0_SCRATCH;
2781
2782 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2783 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
2784}
2785
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002786void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
2787{
2788 struct drm_device *dev = encoder->dev;
2789 struct radeon_device *rdev = dev->dev_private;
2790 uint32_t bios_6_scratch;
2791
2792 if (rdev->family >= CHIP_R600)
2793 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2794 else
2795 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2796
Alex Deucher87364762011-02-02 19:46:06 -05002797 if (lock) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002798 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
Alex Deucher87364762011-02-02 19:46:06 -05002799 bios_6_scratch &= ~ATOM_S6_ACC_MODE;
2800 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002801 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
Alex Deucher87364762011-02-02 19:46:06 -05002802 bios_6_scratch |= ATOM_S6_ACC_MODE;
2803 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002804
2805 if (rdev->family >= CHIP_R600)
2806 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2807 else
2808 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2809}
2810
2811/* at some point we may want to break this out into individual functions */
2812void
2813radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
2814 struct drm_encoder *encoder,
2815 bool connected)
2816{
2817 struct drm_device *dev = connector->dev;
2818 struct radeon_device *rdev = dev->dev_private;
2819 struct radeon_connector *radeon_connector =
2820 to_radeon_connector(connector);
2821 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2822 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
2823
2824 if (rdev->family >= CHIP_R600) {
2825 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2826 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2827 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2828 } else {
2829 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2830 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2831 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2832 }
2833
2834 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
2835 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
2836 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002837 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002838 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
2839 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
2840 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002841 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002842 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
2843 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
2844 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
2845 }
2846 }
2847 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
2848 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
2849 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002850 DRM_DEBUG_KMS("CV connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002851 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
2852 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
2853 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002854 DRM_DEBUG_KMS("CV disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002855 bios_0_scratch &= ~ATOM_S0_CV_MASK;
2856 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
2857 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
2858 }
2859 }
2860 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
2861 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
2862 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002863 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002864 bios_0_scratch |= ATOM_S0_LCD1;
2865 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
2866 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
2867 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002868 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002869 bios_0_scratch &= ~ATOM_S0_LCD1;
2870 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
2871 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
2872 }
2873 }
2874 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
2875 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
2876 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002877 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002878 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
2879 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
2880 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
2881 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002882 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002883 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
2884 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
2885 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
2886 }
2887 }
2888 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
2889 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
2890 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002891 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002892 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
2893 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
2894 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
2895 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002896 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002897 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
2898 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
2899 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
2900 }
2901 }
2902 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
2903 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
2904 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002905 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002906 bios_0_scratch |= ATOM_S0_DFP1;
2907 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
2908 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
2909 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002910 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002911 bios_0_scratch &= ~ATOM_S0_DFP1;
2912 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
2913 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
2914 }
2915 }
2916 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
2917 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
2918 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002919 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002920 bios_0_scratch |= ATOM_S0_DFP2;
2921 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
2922 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
2923 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002924 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002925 bios_0_scratch &= ~ATOM_S0_DFP2;
2926 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
2927 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
2928 }
2929 }
2930 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
2931 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
2932 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002933 DRM_DEBUG_KMS("DFP3 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002934 bios_0_scratch |= ATOM_S0_DFP3;
2935 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
2936 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
2937 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002938 DRM_DEBUG_KMS("DFP3 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002939 bios_0_scratch &= ~ATOM_S0_DFP3;
2940 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
2941 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
2942 }
2943 }
2944 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
2945 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
2946 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002947 DRM_DEBUG_KMS("DFP4 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002948 bios_0_scratch |= ATOM_S0_DFP4;
2949 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
2950 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
2951 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002952 DRM_DEBUG_KMS("DFP4 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002953 bios_0_scratch &= ~ATOM_S0_DFP4;
2954 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
2955 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
2956 }
2957 }
2958 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
2959 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
2960 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002961 DRM_DEBUG_KMS("DFP5 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002962 bios_0_scratch |= ATOM_S0_DFP5;
2963 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
2964 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
2965 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002966 DRM_DEBUG_KMS("DFP5 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002967 bios_0_scratch &= ~ATOM_S0_DFP5;
2968 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2969 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2970 }
2971 }
2972
2973 if (rdev->family >= CHIP_R600) {
2974 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2975 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2976 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2977 } else {
2978 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
2979 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2980 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2981 }
2982}
2983
2984void
2985radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
2986{
2987 struct drm_device *dev = encoder->dev;
2988 struct radeon_device *rdev = dev->dev_private;
2989 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2990 uint32_t bios_3_scratch;
2991
2992 if (rdev->family >= CHIP_R600)
2993 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2994 else
2995 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2996
2997 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2998 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
2999 bios_3_scratch |= (crtc << 18);
3000 }
3001 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
3002 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
3003 bios_3_scratch |= (crtc << 24);
3004 }
3005 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3006 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
3007 bios_3_scratch |= (crtc << 16);
3008 }
3009 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3010 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
3011 bios_3_scratch |= (crtc << 20);
3012 }
3013 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3014 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
3015 bios_3_scratch |= (crtc << 17);
3016 }
3017 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3018 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
3019 bios_3_scratch |= (crtc << 19);
3020 }
3021 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3022 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
3023 bios_3_scratch |= (crtc << 23);
3024 }
3025 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
3026 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
3027 bios_3_scratch |= (crtc << 25);
3028 }
3029
3030 if (rdev->family >= CHIP_R600)
3031 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
3032 else
3033 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
3034}
3035
3036void
3037radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
3038{
3039 struct drm_device *dev = encoder->dev;
3040 struct radeon_device *rdev = dev->dev_private;
3041 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3042 uint32_t bios_2_scratch;
3043
3044 if (rdev->family >= CHIP_R600)
3045 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
3046 else
3047 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
3048
3049 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
3050 if (on)
3051 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
3052 else
3053 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
3054 }
3055 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
3056 if (on)
3057 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
3058 else
3059 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
3060 }
3061 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3062 if (on)
3063 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
3064 else
3065 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
3066 }
3067 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3068 if (on)
3069 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
3070 else
3071 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
3072 }
3073 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3074 if (on)
3075 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
3076 else
3077 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
3078 }
3079 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3080 if (on)
3081 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
3082 else
3083 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
3084 }
3085 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3086 if (on)
3087 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
3088 else
3089 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
3090 }
3091 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
3092 if (on)
3093 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
3094 else
3095 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
3096 }
3097 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
3098 if (on)
3099 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
3100 else
3101 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
3102 }
3103 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
3104 if (on)
3105 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
3106 else
3107 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
3108 }
3109
3110 if (rdev->family >= CHIP_R600)
3111 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
3112 else
3113 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
3114}