blob: 89ce9b6d89d9a6d9911dff292f0bf2ad9b5fa818 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors: Dave Airlie
24 * Alex Deucher
25 */
26#include "drmP.h"
27#include "radeon_drm.h"
28#include "radeon.h"
29
30#include "atom.h"
31#include "atom-bits.h"
32
33/* from radeon_encoder.c */
34extern uint32_t
Alex Deucher5137ee92010-08-12 18:58:47 -040035radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
36 uint8_t dac);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020037extern void radeon_link_encoder_connector(struct drm_device *dev);
38extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040039radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
Jerome Glisse771fe6b2009-06-05 14:42:42 +020040 uint32_t supported_device);
41
42/* from radeon_connector.c */
43extern void
44radeon_add_atom_connector(struct drm_device *dev,
45 uint32_t connector_id,
46 uint32_t supported_device,
47 int connector_type,
48 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -040049 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -050050 uint16_t connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -040051 struct radeon_hpd *hpd,
52 struct radeon_router *router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020053
54/* from radeon_legacy_encoder.c */
55extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040056radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
Jerome Glisse771fe6b2009-06-05 14:42:42 +020057 uint32_t supported_device);
58
59union atom_supported_devices {
60 struct _ATOM_SUPPORTED_DEVICES_INFO info;
61 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
62 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
63};
64
Alex Deuchereed45b32009-12-04 14:45:27 -050065static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
66 uint8_t id)
Jerome Glisse771fe6b2009-06-05 14:42:42 +020067{
Jerome Glisse771fe6b2009-06-05 14:42:42 +020068 struct atom_context *ctx = rdev->mode_info.atom_context;
Alex Deucher6a93cb22009-11-23 17:39:28 -050069 ATOM_GPIO_I2C_ASSIGMENT *gpio;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020070 struct radeon_i2c_bus_rec i2c;
71 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
72 struct _ATOM_GPIO_I2C_INFO *i2c_info;
Alex Deucher95beb692010-04-01 19:08:47 +000073 uint16_t data_offset, size;
74 int i, num_indices;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020075
76 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
77 i2c.valid = false;
78
Alex Deucher95beb692010-04-01 19:08:47 +000079 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
Alex Deuchera084e6e2010-03-18 01:04:01 -040080 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020081
Alex Deucher95beb692010-04-01 19:08:47 +000082 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
83 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
84
85 for (i = 0; i < num_indices; i++) {
Alex Deuchera084e6e2010-03-18 01:04:01 -040086 gpio = &i2c_info->asGPIO_Info[i];
Jerome Glisse771fe6b2009-06-05 14:42:42 +020087
Alex Deucherea393022010-08-27 16:04:29 -040088 /* some evergreen boards have bad data for this entry */
89 if (ASIC_IS_DCE4(rdev)) {
90 if ((i == 7) &&
91 (gpio->usClkMaskRegisterIndex == 0x1936) &&
92 (gpio->sucI2cId.ucAccess == 0)) {
93 gpio->sucI2cId.ucAccess = 0x97;
94 gpio->ucDataMaskShift = 8;
95 gpio->ucDataEnShift = 8;
96 gpio->ucDataY_Shift = 8;
97 gpio->ucDataA_Shift = 8;
98 }
99 }
100
Alex Deuchera084e6e2010-03-18 01:04:01 -0400101 if (gpio->sucI2cId.ucAccess == id) {
102 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
103 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
104 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
105 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
106 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
107 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
108 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
109 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
110 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
111 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
112 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
113 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
114 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
115 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
116 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
117 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200118
Alex Deuchera084e6e2010-03-18 01:04:01 -0400119 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
120 i2c.hw_capable = true;
121 else
122 i2c.hw_capable = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500123
Alex Deuchera084e6e2010-03-18 01:04:01 -0400124 if (gpio->sucI2cId.ucAccess == 0xa0)
125 i2c.mm_i2c = true;
126 else
127 i2c.mm_i2c = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500128
Alex Deuchera084e6e2010-03-18 01:04:01 -0400129 i2c.i2c_id = gpio->sucI2cId.ucAccess;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500130
Alex Deucherf376b942010-08-05 21:21:16 -0400131 if (i2c.mask_clk_reg)
132 i2c.valid = true;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400133 break;
134 }
Alex Deucherd3f420d2009-12-08 14:30:49 -0500135 }
136 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200137
138 return i2c;
139}
140
Alex Deucherf376b942010-08-05 21:21:16 -0400141void radeon_atombios_i2c_init(struct radeon_device *rdev)
142{
143 struct atom_context *ctx = rdev->mode_info.atom_context;
144 ATOM_GPIO_I2C_ASSIGMENT *gpio;
145 struct radeon_i2c_bus_rec i2c;
146 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
147 struct _ATOM_GPIO_I2C_INFO *i2c_info;
148 uint16_t data_offset, size;
149 int i, num_indices;
150 char stmp[32];
151
152 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
153
154 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
155 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
156
157 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
158 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
159
160 for (i = 0; i < num_indices; i++) {
161 gpio = &i2c_info->asGPIO_Info[i];
162 i2c.valid = false;
Alex Deucherea393022010-08-27 16:04:29 -0400163
164 /* some evergreen boards have bad data for this entry */
165 if (ASIC_IS_DCE4(rdev)) {
166 if ((i == 7) &&
167 (gpio->usClkMaskRegisterIndex == 0x1936) &&
168 (gpio->sucI2cId.ucAccess == 0)) {
169 gpio->sucI2cId.ucAccess = 0x97;
170 gpio->ucDataMaskShift = 8;
171 gpio->ucDataEnShift = 8;
172 gpio->ucDataY_Shift = 8;
173 gpio->ucDataA_Shift = 8;
174 }
175 }
176
Alex Deucherf376b942010-08-05 21:21:16 -0400177 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
178 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
179 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
180 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
181 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
182 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
183 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
184 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
185 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
186 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
187 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
188 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
189 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
190 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
191 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
192 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
193
194 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
195 i2c.hw_capable = true;
196 else
197 i2c.hw_capable = false;
198
199 if (gpio->sucI2cId.ucAccess == 0xa0)
200 i2c.mm_i2c = true;
201 else
202 i2c.mm_i2c = false;
203
204 i2c.i2c_id = gpio->sucI2cId.ucAccess;
205
206 if (i2c.mask_clk_reg) {
207 i2c.valid = true;
208 sprintf(stmp, "0x%x", i2c.i2c_id);
209 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
210 }
211 }
212 }
213}
214
Alex Deuchereed45b32009-12-04 14:45:27 -0500215static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
216 u8 id)
217{
218 struct atom_context *ctx = rdev->mode_info.atom_context;
219 struct radeon_gpio_rec gpio;
220 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
221 struct _ATOM_GPIO_PIN_LUT *gpio_info;
222 ATOM_GPIO_PIN_ASSIGNMENT *pin;
223 u16 data_offset, size;
224 int i, num_indices;
225
226 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
227 gpio.valid = false;
228
Alex Deuchera084e6e2010-03-18 01:04:01 -0400229 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
230 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
Alex Deuchereed45b32009-12-04 14:45:27 -0500231
Alex Deuchera084e6e2010-03-18 01:04:01 -0400232 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
233 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
Alex Deuchereed45b32009-12-04 14:45:27 -0500234
Alex Deuchera084e6e2010-03-18 01:04:01 -0400235 for (i = 0; i < num_indices; i++) {
236 pin = &gpio_info->asGPIO_Pin[i];
237 if (id == pin->ucGPIO_ID) {
238 gpio.id = pin->ucGPIO_ID;
239 gpio.reg = pin->usGpioPin_AIndex * 4;
240 gpio.mask = (1 << pin->ucGpioPinBitShift);
241 gpio.valid = true;
242 break;
243 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500244 }
245 }
246
247 return gpio;
248}
249
250static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
251 struct radeon_gpio_rec *gpio)
252{
253 struct radeon_hpd hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500254 u32 reg;
255
Jean Delvare1d978dac2010-08-15 14:11:24 +0200256 memset(&hpd, 0, sizeof(struct radeon_hpd));
257
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500258 if (ASIC_IS_DCE4(rdev))
259 reg = EVERGREEN_DC_GPIO_HPD_A;
260 else
261 reg = AVIVO_DC_GPIO_HPD_A;
262
Alex Deuchereed45b32009-12-04 14:45:27 -0500263 hpd.gpio = *gpio;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500264 if (gpio->reg == reg) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500265 switch(gpio->mask) {
266 case (1 << 0):
267 hpd.hpd = RADEON_HPD_1;
268 break;
269 case (1 << 8):
270 hpd.hpd = RADEON_HPD_2;
271 break;
272 case (1 << 16):
273 hpd.hpd = RADEON_HPD_3;
274 break;
275 case (1 << 24):
276 hpd.hpd = RADEON_HPD_4;
277 break;
278 case (1 << 26):
279 hpd.hpd = RADEON_HPD_5;
280 break;
281 case (1 << 28):
282 hpd.hpd = RADEON_HPD_6;
283 break;
284 default:
285 hpd.hpd = RADEON_HPD_NONE;
286 break;
287 }
288 } else
289 hpd.hpd = RADEON_HPD_NONE;
290 return hpd;
291}
292
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200293static bool radeon_atom_apply_quirks(struct drm_device *dev,
294 uint32_t supported_device,
295 int *connector_type,
Alex Deucher848577e2009-07-08 16:15:30 -0400296 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -0500297 uint16_t *line_mux,
298 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200299{
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400300 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200301
302 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
303 if ((dev->pdev->device == 0x791e) &&
304 (dev->pdev->subsystem_vendor == 0x1043) &&
305 (dev->pdev->subsystem_device == 0x826d)) {
306 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
307 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
308 *connector_type = DRM_MODE_CONNECTOR_DVID;
309 }
310
Alex Deucherc86a9032010-02-18 14:14:58 -0500311 /* Asrock RS600 board lists the DVI port as HDMI */
312 if ((dev->pdev->device == 0x7941) &&
313 (dev->pdev->subsystem_vendor == 0x1849) &&
314 (dev->pdev->subsystem_device == 0x7941)) {
315 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
316 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
317 *connector_type = DRM_MODE_CONNECTOR_DVID;
318 }
319
Alex Deucherf36fce02010-09-27 11:33:00 -0400320 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
321 if ((dev->pdev->device == 0x796e) &&
322 (dev->pdev->subsystem_vendor == 0x1462) &&
323 (dev->pdev->subsystem_device == 0x7302)) {
324 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
325 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
326 return false;
327 }
328
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200329 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
330 if ((dev->pdev->device == 0x7941) &&
331 (dev->pdev->subsystem_vendor == 0x147b) &&
332 (dev->pdev->subsystem_device == 0x2412)) {
333 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
334 return false;
335 }
336
337 /* Falcon NW laptop lists vga ddc line for LVDS */
338 if ((dev->pdev->device == 0x5653) &&
339 (dev->pdev->subsystem_vendor == 0x1462) &&
340 (dev->pdev->subsystem_device == 0x0291)) {
Alex Deucher848577e2009-07-08 16:15:30 -0400341 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200342 i2c_bus->valid = false;
Alex Deucher848577e2009-07-08 16:15:30 -0400343 *line_mux = 53;
344 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200345 }
346
Alex Deucher4e3f9b72009-12-01 14:49:50 -0500347 /* HIS X1300 is DVI+VGA, not DVI+DVI */
348 if ((dev->pdev->device == 0x7146) &&
349 (dev->pdev->subsystem_vendor == 0x17af) &&
350 (dev->pdev->subsystem_device == 0x2058)) {
351 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
352 return false;
353 }
354
Dave Airlieaa1a7502009-12-04 11:51:34 +1000355 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
356 if ((dev->pdev->device == 0x7142) &&
357 (dev->pdev->subsystem_vendor == 0x1458) &&
358 (dev->pdev->subsystem_device == 0x2134)) {
359 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
360 return false;
361 }
362
363
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200364 /* Funky macbooks */
365 if ((dev->pdev->device == 0x71C5) &&
366 (dev->pdev->subsystem_vendor == 0x106b) &&
367 (dev->pdev->subsystem_device == 0x0080)) {
368 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
369 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
370 return false;
Alex Deuchere1e8a5d2010-03-26 17:14:37 -0400371 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
372 *line_mux = 0x90;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200373 }
374
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200375 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
376 if ((dev->pdev->device == 0x9598) &&
377 (dev->pdev->subsystem_vendor == 0x1043) &&
378 (dev->pdev->subsystem_device == 0x01da)) {
Alex Deucher705af9c2009-09-10 16:31:13 -0400379 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400380 *connector_type = DRM_MODE_CONNECTOR_DVII;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200381 }
382 }
383
Alex Deuchere153b702010-07-20 18:07:22 -0400384 /* ASUS HD 3600 board lists the DVI port as HDMI */
385 if ((dev->pdev->device == 0x9598) &&
386 (dev->pdev->subsystem_vendor == 0x1043) &&
387 (dev->pdev->subsystem_device == 0x01e4)) {
388 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
389 *connector_type = DRM_MODE_CONNECTOR_DVII;
390 }
391 }
392
Alex Deucher705af9c2009-09-10 16:31:13 -0400393 /* ASUS HD 3450 board lists the DVI port as HDMI */
394 if ((dev->pdev->device == 0x95C5) &&
395 (dev->pdev->subsystem_vendor == 0x1043) &&
396 (dev->pdev->subsystem_device == 0x01e2)) {
397 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400398 *connector_type = DRM_MODE_CONNECTOR_DVII;
Alex Deucher705af9c2009-09-10 16:31:13 -0400399 }
400 }
401
402 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
403 * HDMI + VGA reporting as HDMI
404 */
405 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
406 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
407 *connector_type = DRM_MODE_CONNECTOR_VGA;
408 *line_mux = 0;
409 }
410 }
411
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400412 /* Acer laptop reports DVI-D as DVI-I and hpd pins reversed */
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500413 if ((dev->pdev->device == 0x95c4) &&
414 (dev->pdev->subsystem_vendor == 0x1025) &&
415 (dev->pdev->subsystem_device == 0x013c)) {
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400416 struct radeon_gpio_rec gpio;
417
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500418 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400419 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
420 gpio = radeon_lookup_gpio(rdev, 6);
421 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500422 *connector_type = DRM_MODE_CONNECTOR_DVID;
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400423 } else if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
424 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
425 gpio = radeon_lookup_gpio(rdev, 7);
426 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
427 }
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500428 }
429
Dave Airlieefa84502010-02-09 09:06:00 +1000430 /* XFX Pine Group device rv730 reports no VGA DDC lines
431 * even though they are wired up to record 0x93
432 */
433 if ((dev->pdev->device == 0x9498) &&
434 (dev->pdev->subsystem_vendor == 0x1682) &&
435 (dev->pdev->subsystem_device == 0x2452)) {
436 struct radeon_device *rdev = dev->dev_private;
437 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
438 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200439 return true;
440}
441
442const int supported_devices_connector_convert[] = {
443 DRM_MODE_CONNECTOR_Unknown,
444 DRM_MODE_CONNECTOR_VGA,
445 DRM_MODE_CONNECTOR_DVII,
446 DRM_MODE_CONNECTOR_DVID,
447 DRM_MODE_CONNECTOR_DVIA,
448 DRM_MODE_CONNECTOR_SVIDEO,
449 DRM_MODE_CONNECTOR_Composite,
450 DRM_MODE_CONNECTOR_LVDS,
451 DRM_MODE_CONNECTOR_Unknown,
452 DRM_MODE_CONNECTOR_Unknown,
453 DRM_MODE_CONNECTOR_HDMIA,
454 DRM_MODE_CONNECTOR_HDMIB,
455 DRM_MODE_CONNECTOR_Unknown,
456 DRM_MODE_CONNECTOR_Unknown,
457 DRM_MODE_CONNECTOR_9PinDIN,
458 DRM_MODE_CONNECTOR_DisplayPort
459};
460
Alex Deucherb75fad02009-11-05 13:16:01 -0500461const uint16_t supported_devices_connector_object_id_convert[] = {
462 CONNECTOR_OBJECT_ID_NONE,
463 CONNECTOR_OBJECT_ID_VGA,
464 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
465 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
466 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
467 CONNECTOR_OBJECT_ID_COMPOSITE,
468 CONNECTOR_OBJECT_ID_SVIDEO,
469 CONNECTOR_OBJECT_ID_LVDS,
470 CONNECTOR_OBJECT_ID_9PIN_DIN,
471 CONNECTOR_OBJECT_ID_9PIN_DIN,
472 CONNECTOR_OBJECT_ID_DISPLAYPORT,
473 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
474 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
475 CONNECTOR_OBJECT_ID_SVIDEO
476};
477
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200478const int object_connector_convert[] = {
479 DRM_MODE_CONNECTOR_Unknown,
480 DRM_MODE_CONNECTOR_DVII,
481 DRM_MODE_CONNECTOR_DVII,
482 DRM_MODE_CONNECTOR_DVID,
483 DRM_MODE_CONNECTOR_DVID,
484 DRM_MODE_CONNECTOR_VGA,
485 DRM_MODE_CONNECTOR_Composite,
486 DRM_MODE_CONNECTOR_SVIDEO,
487 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher705af9c2009-09-10 16:31:13 -0400488 DRM_MODE_CONNECTOR_Unknown,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200489 DRM_MODE_CONNECTOR_9PinDIN,
490 DRM_MODE_CONNECTOR_Unknown,
491 DRM_MODE_CONNECTOR_HDMIA,
492 DRM_MODE_CONNECTOR_HDMIB,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200493 DRM_MODE_CONNECTOR_LVDS,
494 DRM_MODE_CONNECTOR_9PinDIN,
495 DRM_MODE_CONNECTOR_Unknown,
496 DRM_MODE_CONNECTOR_Unknown,
497 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher196c58d2010-01-07 14:22:32 -0500498 DRM_MODE_CONNECTOR_DisplayPort,
499 DRM_MODE_CONNECTOR_eDP,
500 DRM_MODE_CONNECTOR_Unknown
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200501};
502
503bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
504{
505 struct radeon_device *rdev = dev->dev_private;
506 struct radeon_mode_info *mode_info = &rdev->mode_info;
507 struct atom_context *ctx = mode_info->atom_context;
508 int index = GetIndexIntoMasterTable(DATA, Object_Header);
Alex Deuchereed45b32009-12-04 14:45:27 -0500509 u16 size, data_offset;
510 u8 frev, crev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200511 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400512 ATOM_OBJECT_TABLE *router_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200513 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
514 ATOM_OBJECT_HEADER *obj_header;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400515 int i, j, k, path_size, device_support;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200516 int connector_type;
Alex Deuchereed45b32009-12-04 14:45:27 -0500517 u16 igp_lane_info, conn_id, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200518 struct radeon_i2c_bus_rec ddc_bus;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400519 struct radeon_router router;
Alex Deuchereed45b32009-12-04 14:45:27 -0500520 struct radeon_gpio_rec gpio;
521 struct radeon_hpd hpd;
522
Alex Deuchera084e6e2010-03-18 01:04:01 -0400523 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200524 return false;
525
526 if (crev < 2)
527 return false;
528
Alex Deucher26b5bc92010-08-05 21:21:18 -0400529 router.valid = false;
530
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200531 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
532 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
533 (ctx->bios + data_offset +
534 le16_to_cpu(obj_header->usDisplayPathTableOffset));
535 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
536 (ctx->bios + data_offset +
537 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
Alex Deucher26b5bc92010-08-05 21:21:18 -0400538 router_obj = (ATOM_OBJECT_TABLE *)
539 (ctx->bios + data_offset +
540 le16_to_cpu(obj_header->usRouterObjectTableOffset));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200541 device_support = le16_to_cpu(obj_header->usDeviceSupport);
542
543 path_size = 0;
544 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
545 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
546 ATOM_DISPLAY_OBJECT_PATH *path;
547 addr += path_size;
548 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
549 path_size += le16_to_cpu(path->usSize);
Alex Deucher5137ee92010-08-12 18:58:47 -0400550
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200551 if (device_support & le16_to_cpu(path->usDeviceTag)) {
552 uint8_t con_obj_id, con_obj_num, con_obj_type;
553
554 con_obj_id =
555 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
556 >> OBJECT_ID_SHIFT;
557 con_obj_num =
558 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
559 >> ENUM_ID_SHIFT;
560 con_obj_type =
561 (le16_to_cpu(path->usConnObjectId) &
562 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
563
Dave Airlie4bbd4972009-09-25 08:56:12 +1000564 /* TODO CV support */
565 if (le16_to_cpu(path->usDeviceTag) ==
566 ATOM_DEVICE_CV_SUPPORT)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200567 continue;
568
Alex Deucheree59f2b2009-11-05 13:11:46 -0500569 /* IGP chips */
570 if ((rdev->flags & RADEON_IS_IGP) &&
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200571 (con_obj_id ==
572 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
573 uint16_t igp_offset = 0;
574 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
575
576 index =
577 GetIndexIntoMasterTable(DATA,
578 IntegratedSystemInfo);
579
Alex Deuchera084e6e2010-03-18 01:04:01 -0400580 if (atom_parse_data_header(ctx, index, &size, &frev,
581 &crev, &igp_offset)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200582
Alex Deuchera084e6e2010-03-18 01:04:01 -0400583 if (crev >= 2) {
584 igp_obj =
585 (ATOM_INTEGRATED_SYSTEM_INFO_V2
586 *) (ctx->bios + igp_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200587
Alex Deuchera084e6e2010-03-18 01:04:01 -0400588 if (igp_obj) {
589 uint32_t slot_config, ct;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200590
Alex Deuchera084e6e2010-03-18 01:04:01 -0400591 if (con_obj_num == 1)
592 slot_config =
593 igp_obj->
594 ulDDISlot1Config;
595 else
596 slot_config =
597 igp_obj->
598 ulDDISlot2Config;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200599
Alex Deuchera084e6e2010-03-18 01:04:01 -0400600 ct = (slot_config >> 16) & 0xff;
601 connector_type =
602 object_connector_convert
603 [ct];
604 connector_object_id = ct;
605 igp_lane_info =
606 slot_config & 0xffff;
607 } else
608 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200609 } else
610 continue;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400611 } else {
612 igp_lane_info = 0;
613 connector_type =
614 object_connector_convert[con_obj_id];
615 connector_object_id = con_obj_id;
616 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200617 } else {
618 igp_lane_info = 0;
619 connector_type =
620 object_connector_convert[con_obj_id];
Alex Deucherb75fad02009-11-05 13:16:01 -0500621 connector_object_id = con_obj_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200622 }
623
624 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
625 continue;
626
Alex Deucher26b5bc92010-08-05 21:21:18 -0400627 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
628 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200629
Alex Deucher26b5bc92010-08-05 21:21:18 -0400630 grph_obj_id =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200631 (le16_to_cpu(path->usGraphicObjIds[j]) &
632 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400633 grph_obj_num =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200634 (le16_to_cpu(path->usGraphicObjIds[j]) &
635 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400636 grph_obj_type =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200637 (le16_to_cpu(path->usGraphicObjIds[j]) &
638 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
639
Alex Deucher26b5bc92010-08-05 21:21:18 -0400640 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
Alex Deucher5137ee92010-08-12 18:58:47 -0400641 u16 encoder_obj = le16_to_cpu(path->usGraphicObjIds[j]);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200642
643 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400644 encoder_obj,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200645 le16_to_cpu
646 (path->
647 usDeviceTag));
648
Alex Deucher26b5bc92010-08-05 21:21:18 -0400649 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
650 router.valid = false;
651 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
652 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[j].usObjectID);
653 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
654 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
655 (ctx->bios + data_offset +
656 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
657 ATOM_I2C_RECORD *i2c_record;
658 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
659 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
660 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
661 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
662 (ctx->bios + data_offset +
663 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
664 int enum_id;
665
666 router.router_id = router_obj_id;
667 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
668 enum_id++) {
669 if (le16_to_cpu(path->usConnObjectId) ==
670 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
671 break;
672 }
673
674 while (record->ucRecordType > 0 &&
675 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
676 switch (record->ucRecordType) {
677 case ATOM_I2C_RECORD_TYPE:
678 i2c_record =
679 (ATOM_I2C_RECORD *)
680 record;
681 i2c_config =
682 (ATOM_I2C_ID_CONFIG_ACCESS *)
683 &i2c_record->sucI2cId;
684 router.i2c_info =
685 radeon_lookup_i2c_gpio(rdev,
686 i2c_config->
687 ucAccess);
688 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
689 break;
690 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
691 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
692 record;
693 router.valid = true;
694 router.mux_type = ddc_path->ucMuxType;
695 router.mux_control_pin = ddc_path->ucMuxControlPin;
696 router.mux_state = ddc_path->ucMuxState[enum_id];
697 break;
698 }
699 record = (ATOM_COMMON_RECORD_HEADER *)
700 ((char *)record + record->ucRecordSize);
701 }
702 }
703 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200704 }
705 }
706
Alex Deuchereed45b32009-12-04 14:45:27 -0500707 /* look up gpio for ddc, hpd */
Alex Deucher2bfcc0f2010-05-18 19:26:46 -0400708 ddc_bus.valid = false;
709 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200710 if ((le16_to_cpu(path->usDeviceTag) &
Alex Deuchereed45b32009-12-04 14:45:27 -0500711 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200712 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
713 if (le16_to_cpu(path->usConnObjectId) ==
714 le16_to_cpu(con_obj->asObjects[j].
715 usObjectID)) {
716 ATOM_COMMON_RECORD_HEADER
717 *record =
718 (ATOM_COMMON_RECORD_HEADER
719 *)
720 (ctx->bios + data_offset +
721 le16_to_cpu(con_obj->
722 asObjects[j].
723 usRecordOffset));
724 ATOM_I2C_RECORD *i2c_record;
Alex Deuchereed45b32009-12-04 14:45:27 -0500725 ATOM_HPD_INT_RECORD *hpd_record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500726 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500727
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200728 while (record->ucRecordType > 0
729 && record->
730 ucRecordType <=
731 ATOM_MAX_OBJECT_RECORD_NUMBER) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500732 switch (record->ucRecordType) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200733 case ATOM_I2C_RECORD_TYPE:
734 i2c_record =
Alex Deuchereed45b32009-12-04 14:45:27 -0500735 (ATOM_I2C_RECORD *)
736 record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500737 i2c_config =
738 (ATOM_I2C_ID_CONFIG_ACCESS *)
739 &i2c_record->sucI2cId;
Alex Deuchereed45b32009-12-04 14:45:27 -0500740 ddc_bus = radeon_lookup_i2c_gpio(rdev,
Alex Deucherd3f420d2009-12-08 14:30:49 -0500741 i2c_config->
742 ucAccess);
Alex Deuchereed45b32009-12-04 14:45:27 -0500743 break;
744 case ATOM_HPD_INT_RECORD_TYPE:
745 hpd_record =
746 (ATOM_HPD_INT_RECORD *)
747 record;
748 gpio = radeon_lookup_gpio(rdev,
749 hpd_record->ucHPDIntGPIOID);
750 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
751 hpd.plugged_state = hpd_record->ucPlugged_PinState;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200752 break;
753 }
754 record =
755 (ATOM_COMMON_RECORD_HEADER
756 *) ((char *)record
757 +
758 record->
759 ucRecordSize);
760 }
761 break;
762 }
763 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500764 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200765
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500766 /* needed for aux chan transactions */
Alex Deucher8e36ed02010-05-18 19:26:47 -0400767 ddc_bus.hpd = hpd.hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500768
Alex Deucher705af9c2009-09-10 16:31:13 -0400769 conn_id = le16_to_cpu(path->usConnObjectId);
770
771 if (!radeon_atom_apply_quirks
772 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500773 &ddc_bus, &conn_id, &hpd))
Alex Deucher705af9c2009-09-10 16:31:13 -0400774 continue;
775
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200776 radeon_add_atom_connector(dev,
Alex Deucher705af9c2009-09-10 16:31:13 -0400777 conn_id,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200778 le16_to_cpu(path->
779 usDeviceTag),
780 connector_type, &ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -0400781 igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -0500782 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -0400783 &hpd,
784 &router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200785
786 }
787 }
788
789 radeon_link_encoder_connector(dev);
790
791 return true;
792}
793
Alex Deucherb75fad02009-11-05 13:16:01 -0500794static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
795 int connector_type,
796 uint16_t devices)
797{
798 struct radeon_device *rdev = dev->dev_private;
799
800 if (rdev->flags & RADEON_IS_IGP) {
801 return supported_devices_connector_object_id_convert
802 [connector_type];
803 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
804 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
805 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
806 struct radeon_mode_info *mode_info = &rdev->mode_info;
807 struct atom_context *ctx = mode_info->atom_context;
808 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
809 uint16_t size, data_offset;
810 uint8_t frev, crev;
811 ATOM_XTMDS_INFO *xtmds;
812
Alex Deuchera084e6e2010-03-18 01:04:01 -0400813 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
814 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
Alex Deucherb75fad02009-11-05 13:16:01 -0500815
Alex Deuchera084e6e2010-03-18 01:04:01 -0400816 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
817 if (connector_type == DRM_MODE_CONNECTOR_DVII)
818 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
819 else
820 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
821 } else {
822 if (connector_type == DRM_MODE_CONNECTOR_DVII)
823 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
824 else
825 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
826 }
827 } else
828 return supported_devices_connector_object_id_convert
829 [connector_type];
Alex Deucherb75fad02009-11-05 13:16:01 -0500830 } else {
831 return supported_devices_connector_object_id_convert
832 [connector_type];
833 }
834}
835
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200836struct bios_connector {
837 bool valid;
Alex Deucher705af9c2009-09-10 16:31:13 -0400838 uint16_t line_mux;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200839 uint16_t devices;
840 int connector_type;
841 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500842 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200843};
844
845bool radeon_get_atom_connector_info_from_supported_devices_table(struct
846 drm_device
847 *dev)
848{
849 struct radeon_device *rdev = dev->dev_private;
850 struct radeon_mode_info *mode_info = &rdev->mode_info;
851 struct atom_context *ctx = mode_info->atom_context;
852 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
853 uint16_t size, data_offset;
854 uint8_t frev, crev;
855 uint16_t device_support;
856 uint8_t dac;
857 union atom_supported_devices *supported_devices;
Alex Deuchereed45b32009-12-04 14:45:27 -0500858 int i, j, max_device;
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000859 struct bios_connector *bios_connectors;
860 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400861 struct radeon_router router;
862
863 router.valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200864
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000865 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
866 if (!bios_connectors)
Alex Deuchera084e6e2010-03-18 01:04:01 -0400867 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200868
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000869 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
870 &data_offset)) {
871 kfree(bios_connectors);
872 return false;
873 }
874
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200875 supported_devices =
876 (union atom_supported_devices *)(ctx->bios + data_offset);
877
878 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
879
Alex Deuchereed45b32009-12-04 14:45:27 -0500880 if (frev > 1)
881 max_device = ATOM_MAX_SUPPORTED_DEVICE;
882 else
883 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
884
885 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200886 ATOM_CONNECTOR_INFO_I2C ci =
887 supported_devices->info.asConnInfo[i];
888
889 bios_connectors[i].valid = false;
890
891 if (!(device_support & (1 << i))) {
892 continue;
893 }
894
895 if (i == ATOM_DEVICE_CV_INDEX) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000896 DRM_DEBUG_KMS("Skipping Component Video\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200897 continue;
898 }
899
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200900 bios_connectors[i].connector_type =
901 supported_devices_connector_convert[ci.sucConnectorInfo.
902 sbfAccess.
903 bfConnectorType];
904
905 if (bios_connectors[i].connector_type ==
906 DRM_MODE_CONNECTOR_Unknown)
907 continue;
908
909 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
910
Alex Deucherd3f420d2009-12-08 14:30:49 -0500911 bios_connectors[i].line_mux =
912 ci.sucI2cId.ucAccess;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200913
914 /* give tv unique connector ids */
915 if (i == ATOM_DEVICE_TV1_INDEX) {
916 bios_connectors[i].ddc_bus.valid = false;
917 bios_connectors[i].line_mux = 50;
918 } else if (i == ATOM_DEVICE_TV2_INDEX) {
919 bios_connectors[i].ddc_bus.valid = false;
920 bios_connectors[i].line_mux = 51;
921 } else if (i == ATOM_DEVICE_CV_INDEX) {
922 bios_connectors[i].ddc_bus.valid = false;
923 bios_connectors[i].line_mux = 52;
924 } else
925 bios_connectors[i].ddc_bus =
Alex Deuchereed45b32009-12-04 14:45:27 -0500926 radeon_lookup_i2c_gpio(rdev,
927 bios_connectors[i].line_mux);
928
929 if ((crev > 1) && (frev > 1)) {
930 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
931 switch (isb) {
932 case 0x4:
933 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
934 break;
935 case 0xa:
936 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
937 break;
938 default:
939 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
940 break;
941 }
942 } else {
943 if (i == ATOM_DEVICE_DFP1_INDEX)
944 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
945 else if (i == ATOM_DEVICE_DFP2_INDEX)
946 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
947 else
948 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
949 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200950
951 /* Always set the connector type to VGA for CRT1/CRT2. if they are
952 * shared with a DVI port, we'll pick up the DVI connector when we
953 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
954 */
955 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
956 bios_connectors[i].connector_type =
957 DRM_MODE_CONNECTOR_VGA;
958
959 if (!radeon_atom_apply_quirks
960 (dev, (1 << i), &bios_connectors[i].connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500961 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
962 &bios_connectors[i].hpd))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200963 continue;
964
965 bios_connectors[i].valid = true;
966 bios_connectors[i].devices = (1 << i);
967
968 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
969 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400970 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200971 (1 << i),
972 dac),
973 (1 << i));
974 else
975 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400976 radeon_get_encoder_enum(dev,
Alex Deucherf56cd642009-12-18 11:28:22 -0500977 (1 << i),
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200978 dac),
979 (1 << i));
980 }
981
982 /* combine shared connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -0500983 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200984 if (bios_connectors[i].valid) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500985 for (j = 0; j < max_device; j++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200986 if (bios_connectors[j].valid && (i != j)) {
987 if (bios_connectors[i].line_mux ==
988 bios_connectors[j].line_mux) {
Alex Deucherf56cd642009-12-18 11:28:22 -0500989 /* make sure not to combine LVDS */
990 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
991 bios_connectors[i].line_mux = 53;
992 bios_connectors[i].ddc_bus.valid = false;
993 continue;
994 }
995 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
996 bios_connectors[j].line_mux = 53;
997 bios_connectors[j].ddc_bus.valid = false;
998 continue;
999 }
1000 /* combine analog and digital for DVI-I */
1001 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1002 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
1003 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1004 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
1005 bios_connectors[i].devices |=
1006 bios_connectors[j].devices;
1007 bios_connectors[i].connector_type =
1008 DRM_MODE_CONNECTOR_DVII;
1009 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
Alex Deuchereed45b32009-12-04 14:45:27 -05001010 bios_connectors[i].hpd =
1011 bios_connectors[j].hpd;
Alex Deucherf56cd642009-12-18 11:28:22 -05001012 bios_connectors[j].valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001013 }
1014 }
1015 }
1016 }
1017 }
1018 }
1019
1020 /* add the connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -05001021 for (i = 0; i < max_device; i++) {
Alex Deucherb75fad02009-11-05 13:16:01 -05001022 if (bios_connectors[i].valid) {
1023 uint16_t connector_object_id =
1024 atombios_get_connector_object_id(dev,
1025 bios_connectors[i].connector_type,
1026 bios_connectors[i].devices);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001027 radeon_add_atom_connector(dev,
1028 bios_connectors[i].line_mux,
1029 bios_connectors[i].devices,
1030 bios_connectors[i].
1031 connector_type,
1032 &bios_connectors[i].ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -04001033 0,
Alex Deuchereed45b32009-12-04 14:45:27 -05001034 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001035 &bios_connectors[i].hpd,
1036 &router);
Alex Deucherb75fad02009-11-05 13:16:01 -05001037 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001038 }
1039
1040 radeon_link_encoder_connector(dev);
1041
Prarit Bhargavaf49d2732010-05-24 10:24:07 +10001042 kfree(bios_connectors);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001043 return true;
1044}
1045
1046union firmware_info {
1047 ATOM_FIRMWARE_INFO info;
1048 ATOM_FIRMWARE_INFO_V1_2 info_12;
1049 ATOM_FIRMWARE_INFO_V1_3 info_13;
1050 ATOM_FIRMWARE_INFO_V1_4 info_14;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001051 ATOM_FIRMWARE_INFO_V2_1 info_21;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001052};
1053
1054bool radeon_atom_get_clock_info(struct drm_device *dev)
1055{
1056 struct radeon_device *rdev = dev->dev_private;
1057 struct radeon_mode_info *mode_info = &rdev->mode_info;
1058 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1059 union firmware_info *firmware_info;
1060 uint8_t frev, crev;
1061 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1062 struct radeon_pll *p2pll = &rdev->clock.p2pll;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001063 struct radeon_pll *dcpll = &rdev->clock.dcpll;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001064 struct radeon_pll *spll = &rdev->clock.spll;
1065 struct radeon_pll *mpll = &rdev->clock.mpll;
1066 uint16_t data_offset;
1067
Alex Deuchera084e6e2010-03-18 01:04:01 -04001068 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1069 &frev, &crev, &data_offset)) {
1070 firmware_info =
1071 (union firmware_info *)(mode_info->atom_context->bios +
1072 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001073 /* pixel clocks */
1074 p1pll->reference_freq =
1075 le16_to_cpu(firmware_info->info.usReferenceClock);
1076 p1pll->reference_div = 0;
1077
Mathias Fröhlichbc293e52009-10-19 17:49:49 -04001078 if (crev < 2)
1079 p1pll->pll_out_min =
1080 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1081 else
1082 p1pll->pll_out_min =
1083 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001084 p1pll->pll_out_max =
1085 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1086
Alex Deucher86cb2bb2010-03-08 12:55:16 -05001087 if (crev >= 4) {
1088 p1pll->lcd_pll_out_min =
1089 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1090 if (p1pll->lcd_pll_out_min == 0)
1091 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1092 p1pll->lcd_pll_out_max =
1093 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1094 if (p1pll->lcd_pll_out_max == 0)
1095 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1096 } else {
1097 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1098 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1099 }
1100
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001101 if (p1pll->pll_out_min == 0) {
1102 if (ASIC_IS_AVIVO(rdev))
1103 p1pll->pll_out_min = 64800;
1104 else
1105 p1pll->pll_out_min = 20000;
Alex Deucher8f552a62009-10-27 11:16:09 -04001106 } else if (p1pll->pll_out_min > 64800) {
1107 /* Limiting the pll output range is a good thing generally as
1108 * it limits the number of possible pll combinations for a given
1109 * frequency presumably to the ones that work best on each card.
1110 * However, certain duallink DVI monitors seem to like
1111 * pll combinations that would be limited by this at least on
1112 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
1113 * family.
1114 */
Alex Deucher48dfaae2010-09-29 11:37:41 -04001115 p1pll->pll_out_min = 64800;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001116 }
1117
1118 p1pll->pll_in_min =
1119 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1120 p1pll->pll_in_max =
1121 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1122
1123 *p2pll = *p1pll;
1124
1125 /* system clock */
1126 spll->reference_freq =
1127 le16_to_cpu(firmware_info->info.usReferenceClock);
1128 spll->reference_div = 0;
1129
1130 spll->pll_out_min =
1131 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1132 spll->pll_out_max =
1133 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1134
1135 /* ??? */
1136 if (spll->pll_out_min == 0) {
1137 if (ASIC_IS_AVIVO(rdev))
1138 spll->pll_out_min = 64800;
1139 else
1140 spll->pll_out_min = 20000;
1141 }
1142
1143 spll->pll_in_min =
1144 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1145 spll->pll_in_max =
1146 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1147
1148 /* memory clock */
1149 mpll->reference_freq =
1150 le16_to_cpu(firmware_info->info.usReferenceClock);
1151 mpll->reference_div = 0;
1152
1153 mpll->pll_out_min =
1154 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1155 mpll->pll_out_max =
1156 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1157
1158 /* ??? */
1159 if (mpll->pll_out_min == 0) {
1160 if (ASIC_IS_AVIVO(rdev))
1161 mpll->pll_out_min = 64800;
1162 else
1163 mpll->pll_out_min = 20000;
1164 }
1165
1166 mpll->pll_in_min =
1167 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1168 mpll->pll_in_max =
1169 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1170
1171 rdev->clock.default_sclk =
1172 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1173 rdev->clock.default_mclk =
1174 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1175
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001176 if (ASIC_IS_DCE4(rdev)) {
1177 rdev->clock.default_dispclk =
1178 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
1179 if (rdev->clock.default_dispclk == 0)
1180 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1181 rdev->clock.dp_extclk =
1182 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
1183 }
1184 *dcpll = *p1pll;
1185
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001186 return true;
1187 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001188
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001189 return false;
1190}
1191
Alex Deucher06b64762010-01-05 11:27:29 -05001192union igp_info {
1193 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1194 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1195};
1196
1197bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1198{
1199 struct radeon_mode_info *mode_info = &rdev->mode_info;
1200 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1201 union igp_info *igp_info;
1202 u8 frev, crev;
1203 u16 data_offset;
1204
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001205 /* sideport is AMD only */
1206 if (rdev->family == CHIP_RS600)
1207 return false;
1208
Alex Deuchera084e6e2010-03-18 01:04:01 -04001209 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1210 &frev, &crev, &data_offset)) {
1211 igp_info = (union igp_info *)(mode_info->atom_context->bios +
Alex Deucher06b64762010-01-05 11:27:29 -05001212 data_offset);
Alex Deucher06b64762010-01-05 11:27:29 -05001213 switch (crev) {
1214 case 1:
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001215 if (igp_info->info.ulBootUpMemoryClock)
1216 return true;
Alex Deucher06b64762010-01-05 11:27:29 -05001217 break;
1218 case 2:
Alex Deucher4b80d952010-08-20 12:47:54 -04001219 if (igp_info->info_2.ulBootUpSidePortClock)
Alex Deucher06b64762010-01-05 11:27:29 -05001220 return true;
1221 break;
1222 default:
1223 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1224 break;
1225 }
1226 }
1227 return false;
1228}
1229
Dave Airlie445282d2009-09-09 17:40:54 +10001230bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1231 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001232{
1233 struct drm_device *dev = encoder->base.dev;
1234 struct radeon_device *rdev = dev->dev_private;
1235 struct radeon_mode_info *mode_info = &rdev->mode_info;
1236 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1237 uint16_t data_offset;
1238 struct _ATOM_TMDS_INFO *tmds_info;
1239 uint8_t frev, crev;
1240 uint16_t maxfreq;
1241 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001242
Alex Deuchera084e6e2010-03-18 01:04:01 -04001243 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1244 &frev, &crev, &data_offset)) {
1245 tmds_info =
1246 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1247 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001248
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001249 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1250 for (i = 0; i < 4; i++) {
1251 tmds->tmds_pll[i].freq =
1252 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1253 tmds->tmds_pll[i].value =
1254 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1255 tmds->tmds_pll[i].value |=
1256 (tmds_info->asMiscInfo[i].
1257 ucPLL_VCO_Gain & 0x3f) << 6;
1258 tmds->tmds_pll[i].value |=
1259 (tmds_info->asMiscInfo[i].
1260 ucPLL_DutyCycle & 0xf) << 12;
1261 tmds->tmds_pll[i].value |=
1262 (tmds_info->asMiscInfo[i].
1263 ucPLL_VoltageSwing & 0xf) << 16;
1264
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001265 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001266 tmds->tmds_pll[i].freq,
1267 tmds->tmds_pll[i].value);
1268
1269 if (maxfreq == tmds->tmds_pll[i].freq) {
1270 tmds->tmds_pll[i].freq = 0xffffffff;
1271 break;
1272 }
1273 }
Dave Airlie445282d2009-09-09 17:40:54 +10001274 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001275 }
Dave Airlie445282d2009-09-09 17:40:54 +10001276 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001277}
1278
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001279static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
1280 radeon_encoder
1281 *encoder,
1282 int id)
1283{
1284 struct drm_device *dev = encoder->base.dev;
1285 struct radeon_device *rdev = dev->dev_private;
1286 struct radeon_mode_info *mode_info = &rdev->mode_info;
1287 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
1288 uint16_t data_offset;
1289 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1290 uint8_t frev, crev;
1291 struct radeon_atom_ss *ss = NULL;
Alex Deucher279b2152009-12-08 14:07:03 -05001292 int i;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001293
1294 if (id > ATOM_MAX_SS_ENTRY)
1295 return NULL;
1296
Alex Deuchera084e6e2010-03-18 01:04:01 -04001297 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1298 &frev, &crev, &data_offset)) {
1299 ss_info =
1300 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001301
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001302 ss =
1303 kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
1304
1305 if (!ss)
1306 return NULL;
1307
Alex Deucher279b2152009-12-08 14:07:03 -05001308 for (i = 0; i < ATOM_MAX_SS_ENTRY; i++) {
1309 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1310 ss->percentage =
1311 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1312 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1313 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1314 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1315 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1316 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
Alex Deucher1d3d51b2009-12-28 13:45:23 -05001317 break;
Alex Deucher279b2152009-12-08 14:07:03 -05001318 }
1319 }
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001320 }
1321 return ss;
1322}
1323
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001324union lvds_info {
1325 struct _ATOM_LVDS_INFO info;
1326 struct _ATOM_LVDS_INFO_V12 info_12;
1327};
1328
1329struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1330 radeon_encoder
1331 *encoder)
1332{
1333 struct drm_device *dev = encoder->base.dev;
1334 struct radeon_device *rdev = dev->dev_private;
1335 struct radeon_mode_info *mode_info = &rdev->mode_info;
1336 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
Alex Deucher7dde8a12009-11-30 01:40:24 -05001337 uint16_t data_offset, misc;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001338 union lvds_info *lvds_info;
1339 uint8_t frev, crev;
1340 struct radeon_encoder_atom_dig *lvds = NULL;
Alex Deucher5137ee92010-08-12 18:58:47 -04001341 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001342
Alex Deuchera084e6e2010-03-18 01:04:01 -04001343 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1344 &frev, &crev, &data_offset)) {
1345 lvds_info =
1346 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001347 lvds =
1348 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1349
1350 if (!lvds)
1351 return NULL;
1352
Alex Deucherde2103e2009-10-09 15:14:30 -04001353 lvds->native_mode.clock =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001354 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
Alex Deucherde2103e2009-10-09 15:14:30 -04001355 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001356 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001357 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001358 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001359 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1360 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1361 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1362 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1363 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1364 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1365 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1366 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1367 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
Alex Deucher1ff26a32010-05-18 00:23:15 -04001368 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
Alex Deucherde2103e2009-10-09 15:14:30 -04001369 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1370 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001371 lvds->panel_pwr_delay =
1372 le16_to_cpu(lvds_info->info.usOffDelayInMs);
1373 lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
Alex Deucher7dde8a12009-11-30 01:40:24 -05001374
1375 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1376 if (misc & ATOM_VSYNC_POLARITY)
1377 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1378 if (misc & ATOM_HSYNC_POLARITY)
1379 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1380 if (misc & ATOM_COMPOSITESYNC)
1381 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1382 if (misc & ATOM_INTERLACE)
1383 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1384 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1385 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1386
Alex Deucherde2103e2009-10-09 15:14:30 -04001387 /* set crtc values */
1388 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001389
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001390 lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
1391
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001392 encoder->native_mode = lvds->native_mode;
Alex Deucher5137ee92010-08-12 18:58:47 -04001393
1394 if (encoder_enum == 2)
1395 lvds->linkb = true;
1396 else
1397 lvds->linkb = false;
1398
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001399 }
1400 return lvds;
1401}
1402
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001403struct radeon_encoder_primary_dac *
1404radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1405{
1406 struct drm_device *dev = encoder->base.dev;
1407 struct radeon_device *rdev = dev->dev_private;
1408 struct radeon_mode_info *mode_info = &rdev->mode_info;
1409 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1410 uint16_t data_offset;
1411 struct _COMPASSIONATE_DATA *dac_info;
1412 uint8_t frev, crev;
1413 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001414 struct radeon_encoder_primary_dac *p_dac = NULL;
1415
Alex Deuchera084e6e2010-03-18 01:04:01 -04001416 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1417 &frev, &crev, &data_offset)) {
1418 dac_info = (struct _COMPASSIONATE_DATA *)
1419 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001420
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001421 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1422
1423 if (!p_dac)
1424 return NULL;
1425
1426 bg = dac_info->ucDAC1_BG_Adjustment;
1427 dac = dac_info->ucDAC1_DAC_Adjustment;
1428 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1429
1430 }
1431 return p_dac;
1432}
1433
Dave Airlie4ce001a2009-08-13 16:32:14 +10001434bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001435 struct drm_display_mode *mode)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001436{
1437 struct radeon_mode_info *mode_info = &rdev->mode_info;
1438 ATOM_ANALOG_TV_INFO *tv_info;
1439 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1440 ATOM_DTD_FORMAT *dtd_timings;
1441 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1442 u8 frev, crev;
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001443 u16 data_offset, misc;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001444
Alex Deuchera084e6e2010-03-18 01:04:01 -04001445 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1446 &frev, &crev, &data_offset))
1447 return false;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001448
1449 switch (crev) {
1450 case 1:
1451 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001452 if (index >= MAX_SUPPORTED_TV_TIMING)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001453 return false;
1454
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001455 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1456 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1457 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1458 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1459 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001460
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001461 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1462 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1463 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1464 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1465 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001466
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001467 mode->flags = 0;
1468 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1469 if (misc & ATOM_VSYNC_POLARITY)
1470 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1471 if (misc & ATOM_HSYNC_POLARITY)
1472 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1473 if (misc & ATOM_COMPOSITESYNC)
1474 mode->flags |= DRM_MODE_FLAG_CSYNC;
1475 if (misc & ATOM_INTERLACE)
1476 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1477 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1478 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001479
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001480 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001481
1482 if (index == 1) {
1483 /* PAL timings appear to have wrong values for totals */
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001484 mode->crtc_htotal -= 1;
1485 mode->crtc_vtotal -= 1;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001486 }
1487 break;
1488 case 2:
1489 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001490 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001491 return false;
1492
1493 dtd_timings = &tv_info_v1_2->aModeTimings[index];
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001494 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1495 le16_to_cpu(dtd_timings->usHBlanking_Time);
1496 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1497 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1498 le16_to_cpu(dtd_timings->usHSyncOffset);
1499 mode->crtc_hsync_end = mode->crtc_hsync_start +
1500 le16_to_cpu(dtd_timings->usHSyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001501
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001502 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1503 le16_to_cpu(dtd_timings->usVBlanking_Time);
1504 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1505 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1506 le16_to_cpu(dtd_timings->usVSyncOffset);
1507 mode->crtc_vsync_end = mode->crtc_vsync_start +
1508 le16_to_cpu(dtd_timings->usVSyncWidth);
1509
1510 mode->flags = 0;
1511 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1512 if (misc & ATOM_VSYNC_POLARITY)
1513 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1514 if (misc & ATOM_HSYNC_POLARITY)
1515 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1516 if (misc & ATOM_COMPOSITESYNC)
1517 mode->flags |= DRM_MODE_FLAG_CSYNC;
1518 if (misc & ATOM_INTERLACE)
1519 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1520 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1521 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1522
1523 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001524 break;
1525 }
1526 return true;
1527}
1528
Alex Deucherd79766f2009-12-17 19:00:29 -05001529enum radeon_tv_std
1530radeon_atombios_get_tv_info(struct radeon_device *rdev)
1531{
1532 struct radeon_mode_info *mode_info = &rdev->mode_info;
1533 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1534 uint16_t data_offset;
1535 uint8_t frev, crev;
1536 struct _ATOM_ANALOG_TV_INFO *tv_info;
1537 enum radeon_tv_std tv_std = TV_STD_NTSC;
1538
Alex Deuchera084e6e2010-03-18 01:04:01 -04001539 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1540 &frev, &crev, &data_offset)) {
Alex Deucherd79766f2009-12-17 19:00:29 -05001541
Alex Deuchera084e6e2010-03-18 01:04:01 -04001542 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1543 (mode_info->atom_context->bios + data_offset);
Alex Deucherd79766f2009-12-17 19:00:29 -05001544
Alex Deuchera084e6e2010-03-18 01:04:01 -04001545 switch (tv_info->ucTV_BootUpDefaultStandard) {
1546 case ATOM_TV_NTSC:
1547 tv_std = TV_STD_NTSC;
1548 DRM_INFO("Default TV standard: NTSC\n");
1549 break;
1550 case ATOM_TV_NTSCJ:
1551 tv_std = TV_STD_NTSC_J;
1552 DRM_INFO("Default TV standard: NTSC-J\n");
1553 break;
1554 case ATOM_TV_PAL:
1555 tv_std = TV_STD_PAL;
1556 DRM_INFO("Default TV standard: PAL\n");
1557 break;
1558 case ATOM_TV_PALM:
1559 tv_std = TV_STD_PAL_M;
1560 DRM_INFO("Default TV standard: PAL-M\n");
1561 break;
1562 case ATOM_TV_PALN:
1563 tv_std = TV_STD_PAL_N;
1564 DRM_INFO("Default TV standard: PAL-N\n");
1565 break;
1566 case ATOM_TV_PALCN:
1567 tv_std = TV_STD_PAL_CN;
1568 DRM_INFO("Default TV standard: PAL-CN\n");
1569 break;
1570 case ATOM_TV_PAL60:
1571 tv_std = TV_STD_PAL_60;
1572 DRM_INFO("Default TV standard: PAL-60\n");
1573 break;
1574 case ATOM_TV_SECAM:
1575 tv_std = TV_STD_SECAM;
1576 DRM_INFO("Default TV standard: SECAM\n");
1577 break;
1578 default:
1579 tv_std = TV_STD_NTSC;
1580 DRM_INFO("Unknown TV standard; defaulting to NTSC\n");
1581 break;
1582 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001583 }
1584 return tv_std;
1585}
1586
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001587struct radeon_encoder_tv_dac *
1588radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1589{
1590 struct drm_device *dev = encoder->base.dev;
1591 struct radeon_device *rdev = dev->dev_private;
1592 struct radeon_mode_info *mode_info = &rdev->mode_info;
1593 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1594 uint16_t data_offset;
1595 struct _COMPASSIONATE_DATA *dac_info;
1596 uint8_t frev, crev;
1597 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001598 struct radeon_encoder_tv_dac *tv_dac = NULL;
1599
Alex Deuchera084e6e2010-03-18 01:04:01 -04001600 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1601 &frev, &crev, &data_offset)) {
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001602
Alex Deuchera084e6e2010-03-18 01:04:01 -04001603 dac_info = (struct _COMPASSIONATE_DATA *)
1604 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001605
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001606 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1607
1608 if (!tv_dac)
1609 return NULL;
1610
1611 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1612 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1613 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1614
1615 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1616 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1617 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1618
1619 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1620 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1621 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1622
Alex Deucherd79766f2009-12-17 19:00:29 -05001623 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001624 }
1625 return tv_dac;
1626}
1627
Alex Deucher29fb52c2010-03-11 10:01:17 -05001628static const char *thermal_controller_names[] = {
1629 "NONE",
Alex Deucher678e7df2010-04-22 14:17:56 -04001630 "lm63",
1631 "adm1032",
1632 "adm1030",
1633 "max6649",
1634 "lm64",
1635 "f75375",
1636 "asc7xxx",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001637};
1638
1639static const char *pp_lib_thermal_controller_names[] = {
1640 "NONE",
Alex Deucher678e7df2010-04-22 14:17:56 -04001641 "lm63",
1642 "adm1032",
1643 "adm1030",
1644 "max6649",
1645 "lm64",
1646 "f75375",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001647 "RV6xx",
1648 "RV770",
Alex Deucher678e7df2010-04-22 14:17:56 -04001649 "adt7473",
Alex Deucher49f65982010-03-24 16:39:45 -04001650 "External GPIO",
1651 "Evergreen",
Alex Deucher678e7df2010-04-22 14:17:56 -04001652 "adt7473 with internal",
Alex Deucher49f65982010-03-24 16:39:45 -04001653
Alex Deucher29fb52c2010-03-11 10:01:17 -05001654};
1655
Alex Deucher56278a82009-12-28 13:58:44 -05001656union power_info {
1657 struct _ATOM_POWERPLAY_INFO info;
1658 struct _ATOM_POWERPLAY_INFO_V2 info_2;
1659 struct _ATOM_POWERPLAY_INFO_V3 info_3;
1660 struct _ATOM_PPLIB_POWERPLAYTABLE info_4;
1661};
1662
1663void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1664{
1665 struct radeon_mode_info *mode_info = &rdev->mode_info;
1666 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
1667 u16 data_offset;
1668 u8 frev, crev;
1669 u32 misc, misc2 = 0, sclk, mclk;
1670 union power_info *power_info;
1671 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
1672 struct _ATOM_PPLIB_STATE *power_state;
1673 int num_modes = 0, i, j;
1674 int state_index = 0, mode_index = 0;
Alex Deucher29fb52c2010-03-11 10:01:17 -05001675 struct radeon_i2c_bus_rec i2c_bus;
Alex Deucher56278a82009-12-28 13:58:44 -05001676
Alex Deuchera48b9b42010-04-22 14:03:55 -04001677 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05001678
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 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
Alex Deucher56278a82009-12-28 13:58:44 -05001682 if (frev < 4) {
Alex Deucher29fb52c2010-03-11 10:01:17 -05001683 /* add the i2c bus for thermal/fan chip */
1684 if (power_info->info.ucOverdriveThermalController > 0) {
1685 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
1686 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1687 power_info->info.ucOverdriveControllerAddress >> 1);
1688 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
Alex Deucherf376b942010-08-05 21:21:16 -04001689 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucher678e7df2010-04-22 14:17:56 -04001690 if (rdev->pm.i2c_bus) {
1691 struct i2c_board_info info = { };
1692 const char *name = thermal_controller_names[power_info->info.
1693 ucOverdriveThermalController];
1694 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
1695 strlcpy(info.type, name, sizeof(info.type));
1696 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
1697 }
Alex Deucher29fb52c2010-03-11 10:01:17 -05001698 }
Alex Deucher56278a82009-12-28 13:58:44 -05001699 num_modes = power_info->info.ucNumOfPowerModeEntries;
1700 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
1701 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
Alex Deucher02b17cc2010-04-22 13:25:06 -04001702 /* last mode is usually default, array is low to high */
Alex Deucher56278a82009-12-28 13:58:44 -05001703 for (i = 0; i < num_modes; i++) {
1704 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
1705 switch (frev) {
1706 case 1:
1707 rdev->pm.power_state[state_index].num_clock_modes = 1;
1708 rdev->pm.power_state[state_index].clock_info[0].mclk =
1709 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
1710 rdev->pm.power_state[state_index].clock_info[0].sclk =
1711 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
1712 /* skip invalid modes */
1713 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1714 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1715 continue;
Alex Deucher79daedc2010-04-22 14:25:19 -04001716 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05001717 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
1718 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
Alex Deucher84d88f42010-05-27 17:01:42 -04001719 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1720 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
Alex Deucher56278a82009-12-28 13:58:44 -05001721 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1722 VOLTAGE_GPIO;
1723 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1724 radeon_lookup_gpio(rdev,
1725 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
1726 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1727 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1728 true;
1729 else
1730 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1731 false;
1732 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1733 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1734 VOLTAGE_VDDC;
1735 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1736 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
1737 }
Alex Deucherd7311172010-05-03 01:13:14 -04001738 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001739 rdev->pm.power_state[state_index].misc = misc;
Alex Deucher0ec0e742009-12-23 13:21:58 -05001740 /* order matters! */
1741 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1742 rdev->pm.power_state[state_index].type =
1743 POWER_STATE_TYPE_POWERSAVE;
1744 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1745 rdev->pm.power_state[state_index].type =
1746 POWER_STATE_TYPE_BATTERY;
1747 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1748 rdev->pm.power_state[state_index].type =
1749 POWER_STATE_TYPE_BATTERY;
1750 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1751 rdev->pm.power_state[state_index].type =
1752 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001753 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001754 rdev->pm.power_state[state_index].type =
1755 POWER_STATE_TYPE_PERFORMANCE;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001756 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001757 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001758 }
Alex Deucher56278a82009-12-28 13:58:44 -05001759 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001760 rdev->pm.power_state[state_index].type =
1761 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001762 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05001763 rdev->pm.power_state[state_index].default_clock_mode =
1764 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deuchera48b9b42010-04-22 14:03:55 -04001765 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001766 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1767 } else if (state_index == 0) {
1768 rdev->pm.power_state[state_index].clock_info[0].flags |=
1769 RADEON_PM_MODE_NO_DISPLAY;
Alex Deucher56278a82009-12-28 13:58:44 -05001770 }
1771 state_index++;
1772 break;
1773 case 2:
1774 rdev->pm.power_state[state_index].num_clock_modes = 1;
1775 rdev->pm.power_state[state_index].clock_info[0].mclk =
1776 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
1777 rdev->pm.power_state[state_index].clock_info[0].sclk =
1778 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
1779 /* skip invalid modes */
1780 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1781 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1782 continue;
Alex Deucher79daedc2010-04-22 14:25:19 -04001783 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05001784 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
1785 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
1786 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
Alex Deucher84d88f42010-05-27 17:01:42 -04001787 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1788 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
Alex Deucher56278a82009-12-28 13:58:44 -05001789 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1790 VOLTAGE_GPIO;
1791 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1792 radeon_lookup_gpio(rdev,
1793 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
1794 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1795 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1796 true;
1797 else
1798 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1799 false;
1800 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1801 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1802 VOLTAGE_VDDC;
1803 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1804 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
1805 }
Alex Deucherd7311172010-05-03 01:13:14 -04001806 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001807 rdev->pm.power_state[state_index].misc = misc;
1808 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher0ec0e742009-12-23 13:21:58 -05001809 /* order matters! */
1810 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1811 rdev->pm.power_state[state_index].type =
1812 POWER_STATE_TYPE_POWERSAVE;
1813 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1814 rdev->pm.power_state[state_index].type =
1815 POWER_STATE_TYPE_BATTERY;
1816 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1817 rdev->pm.power_state[state_index].type =
1818 POWER_STATE_TYPE_BATTERY;
1819 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1820 rdev->pm.power_state[state_index].type =
1821 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001822 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001823 rdev->pm.power_state[state_index].type =
1824 POWER_STATE_TYPE_PERFORMANCE;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001825 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001826 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001827 }
Alex Deucher0ec0e742009-12-23 13:21:58 -05001828 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1829 rdev->pm.power_state[state_index].type =
1830 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001831 if (misc2 & ATOM_PM_MISCINFO2_MULTI_DISPLAY_SUPPORT)
1832 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001833 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05001834 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001835 rdev->pm.power_state[state_index].type =
1836 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001837 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05001838 rdev->pm.power_state[state_index].default_clock_mode =
1839 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deuchera48b9b42010-04-22 14:03:55 -04001840 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001841 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1842 } else if (state_index == 0) {
1843 rdev->pm.power_state[state_index].clock_info[0].flags |=
1844 RADEON_PM_MODE_NO_DISPLAY;
Alex Deucher56278a82009-12-28 13:58:44 -05001845 }
1846 state_index++;
1847 break;
1848 case 3:
1849 rdev->pm.power_state[state_index].num_clock_modes = 1;
1850 rdev->pm.power_state[state_index].clock_info[0].mclk =
1851 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
1852 rdev->pm.power_state[state_index].clock_info[0].sclk =
1853 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
1854 /* skip invalid modes */
1855 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1856 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1857 continue;
Alex Deucher79daedc2010-04-22 14:25:19 -04001858 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05001859 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
1860 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
1861 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
Alex Deucher84d88f42010-05-27 17:01:42 -04001862 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1863 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
Alex Deucher56278a82009-12-28 13:58:44 -05001864 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1865 VOLTAGE_GPIO;
1866 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1867 radeon_lookup_gpio(rdev,
1868 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
1869 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1870 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1871 true;
1872 else
1873 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1874 false;
1875 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1876 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1877 VOLTAGE_VDDC;
1878 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1879 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
1880 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
1881 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
1882 true;
1883 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
1884 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
1885 }
1886 }
Alex Deucherd7311172010-05-03 01:13:14 -04001887 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001888 rdev->pm.power_state[state_index].misc = misc;
1889 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher0ec0e742009-12-23 13:21:58 -05001890 /* order matters! */
1891 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1892 rdev->pm.power_state[state_index].type =
1893 POWER_STATE_TYPE_POWERSAVE;
1894 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1895 rdev->pm.power_state[state_index].type =
1896 POWER_STATE_TYPE_BATTERY;
1897 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1898 rdev->pm.power_state[state_index].type =
1899 POWER_STATE_TYPE_BATTERY;
1900 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1901 rdev->pm.power_state[state_index].type =
1902 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001903 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001904 rdev->pm.power_state[state_index].type =
1905 POWER_STATE_TYPE_PERFORMANCE;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001906 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001907 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001908 }
Alex Deucher0ec0e742009-12-23 13:21:58 -05001909 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1910 rdev->pm.power_state[state_index].type =
1911 POWER_STATE_TYPE_BALANCED;
Alex Deucher56278a82009-12-28 13:58:44 -05001912 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001913 rdev->pm.power_state[state_index].type =
1914 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001915 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05001916 rdev->pm.power_state[state_index].default_clock_mode =
1917 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucherd7311172010-05-03 01:13:14 -04001918 } else if (state_index == 0) {
1919 rdev->pm.power_state[state_index].clock_info[0].flags |=
1920 RADEON_PM_MODE_NO_DISPLAY;
Alex Deucher56278a82009-12-28 13:58:44 -05001921 }
1922 state_index++;
1923 break;
1924 }
1925 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04001926 /* last mode is usually default */
Alex Deuchera48b9b42010-04-22 14:03:55 -04001927 if (rdev->pm.default_power_state_index == -1) {
Alex Deucher02b17cc2010-04-22 13:25:06 -04001928 rdev->pm.power_state[state_index - 1].type =
1929 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001930 rdev->pm.default_power_state_index = state_index - 1;
Alex Deucher02b17cc2010-04-22 13:25:06 -04001931 rdev->pm.power_state[state_index - 1].default_clock_mode =
1932 &rdev->pm.power_state[state_index - 1].clock_info[0];
Alex Deuchera48b9b42010-04-22 14:03:55 -04001933 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001934 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001935 rdev->pm.power_state[state_index].misc = 0;
1936 rdev->pm.power_state[state_index].misc2 = 0;
Alex Deucher02b17cc2010-04-22 13:25:06 -04001937 }
Alex Deucher49f65982010-03-24 16:39:45 -04001938 } else {
Alex Deucherc5e8ce62010-05-27 17:01:40 -04001939 int fw_index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1940 uint8_t fw_frev, fw_crev;
1941 uint16_t fw_data_offset, vddc = 0;
1942 union firmware_info *firmware_info;
1943 ATOM_PPLIB_THERMALCONTROLLER *controller = &power_info->info_4.sThermalController;
1944
1945 if (atom_parse_data_header(mode_info->atom_context, fw_index, NULL,
1946 &fw_frev, &fw_crev, &fw_data_offset)) {
1947 firmware_info =
1948 (union firmware_info *)(mode_info->atom_context->bios +
1949 fw_data_offset);
1950 vddc = firmware_info->info_14.usBootUpVDDCVoltage;
1951 }
1952
Alex Deucher29fb52c2010-03-11 10:01:17 -05001953 /* add the i2c bus for thermal/fan chip */
Alex Deucher678e7df2010-04-22 14:17:56 -04001954 if (controller->ucType > 0) {
Alex Deucher21a81222010-07-02 12:58:16 -04001955 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
Alex Deucher29fb52c2010-03-11 10:01:17 -05001956 DRM_INFO("Internal thermal controller %s fan control\n",
Alex Deucher678e7df2010-04-22 14:17:56 -04001957 (controller->ucFanParameters &
Alex Deucher29fb52c2010-03-11 10:01:17 -05001958 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
Alex Deucher21a81222010-07-02 12:58:16 -04001959 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
1960 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
1961 DRM_INFO("Internal thermal controller %s fan control\n",
1962 (controller->ucFanParameters &
1963 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
1964 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
1965 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
1966 DRM_INFO("Internal thermal controller %s fan control\n",
1967 (controller->ucFanParameters &
1968 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
1969 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
Alex Deucher678e7df2010-04-22 14:17:56 -04001970 } else if ((controller->ucType ==
Alex Deucher49f65982010-03-24 16:39:45 -04001971 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
Alex Deucher678e7df2010-04-22 14:17:56 -04001972 (controller->ucType ==
Alex Deucher49f65982010-03-24 16:39:45 -04001973 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL)) {
1974 DRM_INFO("Special thermal controller config\n");
Alex Deucher29fb52c2010-03-11 10:01:17 -05001975 } else {
1976 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
Alex Deucher678e7df2010-04-22 14:17:56 -04001977 pp_lib_thermal_controller_names[controller->ucType],
1978 controller->ucI2cAddress >> 1,
1979 (controller->ucFanParameters &
Alex Deucher29fb52c2010-03-11 10:01:17 -05001980 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
Alex Deucher678e7df2010-04-22 14:17:56 -04001981 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
Alex Deucherf376b942010-08-05 21:21:16 -04001982 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucher678e7df2010-04-22 14:17:56 -04001983 if (rdev->pm.i2c_bus) {
1984 struct i2c_board_info info = { };
1985 const char *name = pp_lib_thermal_controller_names[controller->ucType];
1986 info.addr = controller->ucI2cAddress >> 1;
1987 strlcpy(info.type, name, sizeof(info.type));
1988 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
1989 }
1990
Alex Deucher29fb52c2010-03-11 10:01:17 -05001991 }
1992 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04001993 /* first mode is usually default, followed by low to high */
Alex Deucher56278a82009-12-28 13:58:44 -05001994 for (i = 0; i < power_info->info_4.ucNumStates; i++) {
1995 mode_index = 0;
1996 power_state = (struct _ATOM_PPLIB_STATE *)
1997 (mode_info->atom_context->bios +
1998 data_offset +
1999 le16_to_cpu(power_info->info_4.usStateArrayOffset) +
2000 i * power_info->info_4.ucStateEntrySize);
2001 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2002 (mode_info->atom_context->bios +
2003 data_offset +
2004 le16_to_cpu(power_info->info_4.usNonClockInfoArrayOffset) +
2005 (power_state->ucNonClockStateIndex *
2006 power_info->info_4.ucNonClockSize));
Alex Deucher56278a82009-12-28 13:58:44 -05002007 for (j = 0; j < (power_info->info_4.ucStateEntrySize - 1); j++) {
2008 if (rdev->flags & RADEON_IS_IGP) {
2009 struct _ATOM_PPLIB_RS780_CLOCK_INFO *clock_info =
2010 (struct _ATOM_PPLIB_RS780_CLOCK_INFO *)
2011 (mode_info->atom_context->bios +
2012 data_offset +
2013 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2014 (power_state->ucClockStateIndices[j] *
2015 power_info->info_4.ucClockInfoSize));
2016 sclk = le16_to_cpu(clock_info->usLowEngineClockLow);
2017 sclk |= clock_info->ucLowEngineClockHigh << 16;
2018 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2019 /* skip invalid modes */
2020 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2021 continue;
Alex Deucheraa1df0f2010-06-07 11:35:53 -04002022 /* voltage works differently on IGPs */
Alex Deucher56278a82009-12-28 13:58:44 -05002023 mode_index++;
Alex Deucher49f65982010-03-24 16:39:45 -04002024 } else if (ASIC_IS_DCE4(rdev)) {
2025 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *clock_info =
2026 (struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *)
2027 (mode_info->atom_context->bios +
2028 data_offset +
2029 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2030 (power_state->ucClockStateIndices[j] *
2031 power_info->info_4.ucClockInfoSize));
2032 sclk = le16_to_cpu(clock_info->usEngineClockLow);
2033 sclk |= clock_info->ucEngineClockHigh << 16;
2034 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
2035 mclk |= clock_info->ucMemoryClockHigh << 16;
2036 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2037 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2038 /* skip invalid modes */
2039 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2040 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2041 continue;
Alex Deucher49f65982010-03-24 16:39:45 -04002042 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2043 VOLTAGE_SW;
2044 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2045 clock_info->usVDDC;
2046 /* XXX usVDDCI */
2047 mode_index++;
Alex Deucher56278a82009-12-28 13:58:44 -05002048 } else {
2049 struct _ATOM_PPLIB_R600_CLOCK_INFO *clock_info =
2050 (struct _ATOM_PPLIB_R600_CLOCK_INFO *)
2051 (mode_info->atom_context->bios +
2052 data_offset +
2053 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2054 (power_state->ucClockStateIndices[j] *
2055 power_info->info_4.ucClockInfoSize));
2056 sclk = le16_to_cpu(clock_info->usEngineClockLow);
2057 sclk |= clock_info->ucEngineClockHigh << 16;
2058 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
2059 mclk |= clock_info->ucMemoryClockHigh << 16;
2060 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2061 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2062 /* skip invalid modes */
2063 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2064 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2065 continue;
Alex Deucher56278a82009-12-28 13:58:44 -05002066 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2067 VOLTAGE_SW;
2068 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2069 clock_info->usVDDC;
2070 mode_index++;
2071 }
2072 }
2073 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2074 if (mode_index) {
Rafał Miłecki845db702009-12-23 00:42:43 +01002075 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
Alex Deucher56278a82009-12-28 13:58:44 -05002076 misc2 = le16_to_cpu(non_clock_info->usClassification);
Alex Deucher79daedc2010-04-22 14:25:19 -04002077 rdev->pm.power_state[state_index].misc = misc;
2078 rdev->pm.power_state[state_index].misc2 = misc2;
2079 rdev->pm.power_state[state_index].pcie_lanes =
Rafał Miłecki845db702009-12-23 00:42:43 +01002080 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2081 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002082 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2083 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2084 rdev->pm.power_state[state_index].type =
2085 POWER_STATE_TYPE_BATTERY;
2086 break;
2087 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2088 rdev->pm.power_state[state_index].type =
2089 POWER_STATE_TYPE_BALANCED;
2090 break;
2091 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2092 rdev->pm.power_state[state_index].type =
2093 POWER_STATE_TYPE_PERFORMANCE;
2094 break;
Alex Deuchera44d2f32010-08-04 11:10:26 -04002095 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2096 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2097 rdev->pm.power_state[state_index].type =
2098 POWER_STATE_TYPE_PERFORMANCE;
2099 break;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002100 }
Alex Deuchera48b9b42010-04-22 14:03:55 -04002101 rdev->pm.power_state[state_index].flags = 0;
2102 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2103 rdev->pm.power_state[state_index].flags |=
Alex Deucherd7311172010-05-03 01:13:14 -04002104 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05002105 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05002106 rdev->pm.power_state[state_index].type =
2107 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002108 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05002109 rdev->pm.power_state[state_index].default_clock_mode =
2110 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
Alex Deucherc5e8ce62010-05-27 17:01:40 -04002111 /* patch the table values with the default slck/mclk from firmware info */
2112 for (j = 0; j < mode_index; j++) {
2113 rdev->pm.power_state[state_index].clock_info[j].mclk =
2114 rdev->clock.default_mclk;
2115 rdev->pm.power_state[state_index].clock_info[j].sclk =
2116 rdev->clock.default_sclk;
2117 if (vddc)
2118 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2119 vddc;
2120 }
Alex Deucher56278a82009-12-28 13:58:44 -05002121 }
2122 state_index++;
2123 }
2124 }
Alex Deucherd7311172010-05-03 01:13:14 -04002125 /* if multiple clock modes, mark the lowest as no display */
2126 for (i = 0; i < state_index; i++) {
2127 if (rdev->pm.power_state[i].num_clock_modes > 1)
2128 rdev->pm.power_state[i].clock_info[0].flags |=
2129 RADEON_PM_MODE_NO_DISPLAY;
2130 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002131 /* first mode is usually default */
Alex Deuchera48b9b42010-04-22 14:03:55 -04002132 if (rdev->pm.default_power_state_index == -1) {
Alex Deucher02b17cc2010-04-22 13:25:06 -04002133 rdev->pm.power_state[0].type =
2134 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002135 rdev->pm.default_power_state_index = 0;
Alex Deucher02b17cc2010-04-22 13:25:06 -04002136 rdev->pm.power_state[0].default_clock_mode =
2137 &rdev->pm.power_state[0].clock_info[0];
2138 }
Alex Deucher56278a82009-12-28 13:58:44 -05002139 }
2140 } else {
Alex Deucher56278a82009-12-28 13:58:44 -05002141 /* add the default mode */
Alex Deucher0ec0e742009-12-23 13:21:58 -05002142 rdev->pm.power_state[state_index].type =
2143 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05002144 rdev->pm.power_state[state_index].num_clock_modes = 1;
2145 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2146 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2147 rdev->pm.power_state[state_index].default_clock_mode =
2148 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucher56278a82009-12-28 13:58:44 -05002149 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
Alex Deucher79daedc2010-04-22 14:25:19 -04002150 rdev->pm.power_state[state_index].pcie_lanes = 16;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002151 rdev->pm.default_power_state_index = state_index;
2152 rdev->pm.power_state[state_index].flags = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002153 state_index++;
2154 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002155
Alex Deucher56278a82009-12-28 13:58:44 -05002156 rdev->pm.num_power_states = state_index;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002157
Alex Deuchera48b9b42010-04-22 14:03:55 -04002158 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2159 rdev->pm.current_clock_mode_index = 0;
Alex Deucher4d601732010-06-07 18:15:18 -04002160 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 -05002161}
2162
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002163void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2164{
2165 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2166 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2167
2168 args.ucEnable = enable;
2169
2170 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2171}
2172
Rafał Miłecki74338742009-11-03 00:53:02 +01002173uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2174{
2175 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2176 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2177
2178 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2179 return args.ulReturnEngineClock;
2180}
2181
2182uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2183{
2184 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2185 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2186
2187 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2188 return args.ulReturnMemoryClock;
2189}
2190
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002191void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2192 uint32_t eng_clock)
2193{
2194 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2195 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2196
2197 args.ulTargetEngineClock = eng_clock; /* 10 khz */
2198
2199 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2200}
2201
2202void radeon_atom_set_memory_clock(struct radeon_device *rdev,
2203 uint32_t mem_clock)
2204{
2205 SET_MEMORY_CLOCK_PS_ALLOCATION args;
2206 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
2207
2208 if (rdev->flags & RADEON_IS_IGP)
2209 return;
2210
2211 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
2212
2213 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2214}
2215
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002216union set_voltage {
2217 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2218 struct _SET_VOLTAGE_PARAMETERS v1;
2219 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2220};
2221
2222void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level)
2223{
2224 union set_voltage args;
2225 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
2226 u8 frev, crev, volt_index = level;
2227
2228 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2229 return;
2230
2231 switch (crev) {
2232 case 1:
2233 args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2234 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
2235 args.v1.ucVoltageIndex = volt_index;
2236 break;
2237 case 2:
2238 args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2239 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
2240 args.v2.usVoltageLevel = cpu_to_le16(level);
2241 break;
2242 default:
2243 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2244 return;
2245 }
2246
2247 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2248}
2249
2250
2251
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002252void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
2253{
2254 struct radeon_device *rdev = dev->dev_private;
2255 uint32_t bios_2_scratch, bios_6_scratch;
2256
2257 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002258 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002259 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2260 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002261 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002262 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2263 }
2264
2265 /* let the bios control the backlight */
2266 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
2267
2268 /* tell the bios not to handle mode switching */
2269 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
2270
2271 if (rdev->family >= CHIP_R600) {
2272 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2273 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2274 } else {
2275 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2276 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2277 }
2278
2279}
2280
Yang Zhaof657c2a2009-09-15 12:21:01 +10002281void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
2282{
2283 uint32_t scratch_reg;
2284 int i;
2285
2286 if (rdev->family >= CHIP_R600)
2287 scratch_reg = R600_BIOS_0_SCRATCH;
2288 else
2289 scratch_reg = RADEON_BIOS_0_SCRATCH;
2290
2291 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2292 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
2293}
2294
2295void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
2296{
2297 uint32_t scratch_reg;
2298 int i;
2299
2300 if (rdev->family >= CHIP_R600)
2301 scratch_reg = R600_BIOS_0_SCRATCH;
2302 else
2303 scratch_reg = RADEON_BIOS_0_SCRATCH;
2304
2305 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2306 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
2307}
2308
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002309void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
2310{
2311 struct drm_device *dev = encoder->dev;
2312 struct radeon_device *rdev = dev->dev_private;
2313 uint32_t bios_6_scratch;
2314
2315 if (rdev->family >= CHIP_R600)
2316 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2317 else
2318 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2319
2320 if (lock)
2321 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
2322 else
2323 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
2324
2325 if (rdev->family >= CHIP_R600)
2326 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2327 else
2328 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2329}
2330
2331/* at some point we may want to break this out into individual functions */
2332void
2333radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
2334 struct drm_encoder *encoder,
2335 bool connected)
2336{
2337 struct drm_device *dev = connector->dev;
2338 struct radeon_device *rdev = dev->dev_private;
2339 struct radeon_connector *radeon_connector =
2340 to_radeon_connector(connector);
2341 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2342 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
2343
2344 if (rdev->family >= CHIP_R600) {
2345 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2346 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2347 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2348 } else {
2349 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2350 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2351 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2352 }
2353
2354 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
2355 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
2356 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002357 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002358 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
2359 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
2360 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002361 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002362 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
2363 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
2364 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
2365 }
2366 }
2367 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
2368 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
2369 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002370 DRM_DEBUG_KMS("CV connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002371 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
2372 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
2373 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002374 DRM_DEBUG_KMS("CV disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002375 bios_0_scratch &= ~ATOM_S0_CV_MASK;
2376 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
2377 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
2378 }
2379 }
2380 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
2381 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
2382 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002383 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002384 bios_0_scratch |= ATOM_S0_LCD1;
2385 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
2386 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
2387 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002388 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002389 bios_0_scratch &= ~ATOM_S0_LCD1;
2390 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
2391 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
2392 }
2393 }
2394 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
2395 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
2396 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002397 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002398 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
2399 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
2400 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
2401 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002402 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002403 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
2404 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
2405 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
2406 }
2407 }
2408 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
2409 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
2410 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002411 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002412 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
2413 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
2414 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
2415 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002416 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002417 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
2418 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
2419 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
2420 }
2421 }
2422 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
2423 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
2424 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002425 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002426 bios_0_scratch |= ATOM_S0_DFP1;
2427 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
2428 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
2429 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002430 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002431 bios_0_scratch &= ~ATOM_S0_DFP1;
2432 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
2433 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
2434 }
2435 }
2436 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
2437 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
2438 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002439 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002440 bios_0_scratch |= ATOM_S0_DFP2;
2441 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
2442 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
2443 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002444 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002445 bios_0_scratch &= ~ATOM_S0_DFP2;
2446 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
2447 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
2448 }
2449 }
2450 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
2451 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
2452 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002453 DRM_DEBUG_KMS("DFP3 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002454 bios_0_scratch |= ATOM_S0_DFP3;
2455 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
2456 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
2457 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002458 DRM_DEBUG_KMS("DFP3 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002459 bios_0_scratch &= ~ATOM_S0_DFP3;
2460 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
2461 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
2462 }
2463 }
2464 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
2465 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
2466 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002467 DRM_DEBUG_KMS("DFP4 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002468 bios_0_scratch |= ATOM_S0_DFP4;
2469 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
2470 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
2471 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002472 DRM_DEBUG_KMS("DFP4 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002473 bios_0_scratch &= ~ATOM_S0_DFP4;
2474 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
2475 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
2476 }
2477 }
2478 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
2479 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
2480 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002481 DRM_DEBUG_KMS("DFP5 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002482 bios_0_scratch |= ATOM_S0_DFP5;
2483 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
2484 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
2485 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002486 DRM_DEBUG_KMS("DFP5 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002487 bios_0_scratch &= ~ATOM_S0_DFP5;
2488 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2489 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2490 }
2491 }
2492
2493 if (rdev->family >= CHIP_R600) {
2494 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2495 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2496 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2497 } else {
2498 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
2499 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2500 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2501 }
2502}
2503
2504void
2505radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
2506{
2507 struct drm_device *dev = encoder->dev;
2508 struct radeon_device *rdev = dev->dev_private;
2509 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2510 uint32_t bios_3_scratch;
2511
2512 if (rdev->family >= CHIP_R600)
2513 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2514 else
2515 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2516
2517 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2518 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
2519 bios_3_scratch |= (crtc << 18);
2520 }
2521 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2522 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
2523 bios_3_scratch |= (crtc << 24);
2524 }
2525 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2526 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
2527 bios_3_scratch |= (crtc << 16);
2528 }
2529 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2530 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
2531 bios_3_scratch |= (crtc << 20);
2532 }
2533 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2534 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
2535 bios_3_scratch |= (crtc << 17);
2536 }
2537 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2538 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
2539 bios_3_scratch |= (crtc << 19);
2540 }
2541 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2542 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
2543 bios_3_scratch |= (crtc << 23);
2544 }
2545 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2546 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
2547 bios_3_scratch |= (crtc << 25);
2548 }
2549
2550 if (rdev->family >= CHIP_R600)
2551 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2552 else
2553 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2554}
2555
2556void
2557radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
2558{
2559 struct drm_device *dev = encoder->dev;
2560 struct radeon_device *rdev = dev->dev_private;
2561 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2562 uint32_t bios_2_scratch;
2563
2564 if (rdev->family >= CHIP_R600)
2565 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2566 else
2567 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
2568
2569 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2570 if (on)
2571 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
2572 else
2573 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
2574 }
2575 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2576 if (on)
2577 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
2578 else
2579 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
2580 }
2581 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2582 if (on)
2583 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
2584 else
2585 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
2586 }
2587 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2588 if (on)
2589 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
2590 else
2591 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
2592 }
2593 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2594 if (on)
2595 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
2596 else
2597 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
2598 }
2599 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2600 if (on)
2601 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
2602 else
2603 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
2604 }
2605 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2606 if (on)
2607 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
2608 else
2609 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
2610 }
2611 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2612 if (on)
2613 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
2614 else
2615 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
2616 }
2617 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
2618 if (on)
2619 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
2620 else
2621 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
2622 }
2623 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
2624 if (on)
2625 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
2626 else
2627 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
2628 }
2629
2630 if (rdev->family >= CHIP_R600)
2631 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2632 else
2633 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2634}