blob: 7e2ba2580899402f53682386980bfba58be59d25 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors: Dave Airlie
24 * Alex Deucher
25 */
26#include "drmP.h"
27#include "radeon_drm.h"
28#include "radeon.h"
29
30#include "atom.h"
31#include "atom-bits.h"
32
33/* from radeon_encoder.c */
34extern uint32_t
Alex Deucher5137ee92010-08-12 18:58:47 -040035radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
36 uint8_t dac);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020037extern void radeon_link_encoder_connector(struct drm_device *dev);
38extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040039radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
Alex Deucher36868bd2011-01-06 21:19:21 -050040 uint32_t supported_device, u16 caps);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020041
42/* from radeon_connector.c */
43extern void
44radeon_add_atom_connector(struct drm_device *dev,
45 uint32_t connector_id,
46 uint32_t supported_device,
47 int connector_type,
48 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -040049 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -050050 uint16_t connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -040051 struct radeon_hpd *hpd,
52 struct radeon_router *router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020053
54/* from radeon_legacy_encoder.c */
55extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040056radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
Jerome Glisse771fe6b2009-06-05 14:42:42 +020057 uint32_t supported_device);
58
59union atom_supported_devices {
60 struct _ATOM_SUPPORTED_DEVICES_INFO info;
61 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
62 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
63};
64
Alex Deucher21240f92011-11-21 12:41:21 -050065static void radeon_lookup_i2c_gpio_quirks(struct radeon_device *rdev,
66 ATOM_GPIO_I2C_ASSIGMENT *gpio,
67 u8 index)
68{
69 /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
70 if ((rdev->family == CHIP_R420) ||
71 (rdev->family == CHIP_R423) ||
72 (rdev->family == CHIP_RV410)) {
73 if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
74 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
75 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
76 gpio->ucClkMaskShift = 0x19;
77 gpio->ucDataMaskShift = 0x18;
78 }
79 }
80
81 /* some evergreen boards have bad data for this entry */
82 if (ASIC_IS_DCE4(rdev)) {
83 if ((index == 7) &&
84 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
85 (gpio->sucI2cId.ucAccess == 0)) {
86 gpio->sucI2cId.ucAccess = 0x97;
87 gpio->ucDataMaskShift = 8;
88 gpio->ucDataEnShift = 8;
89 gpio->ucDataY_Shift = 8;
90 gpio->ucDataA_Shift = 8;
91 }
92 }
93
94 /* some DCE3 boards have bad data for this entry */
95 if (ASIC_IS_DCE3(rdev)) {
96 if ((index == 4) &&
97 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
98 (gpio->sucI2cId.ucAccess == 0x94))
99 gpio->sucI2cId.ucAccess = 0x14;
100 }
101}
102
103static struct radeon_i2c_bus_rec radeon_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio)
104{
105 struct radeon_i2c_bus_rec i2c;
106
107 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
108
109 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
110 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
111 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
112 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
113 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
114 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
115 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
116 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
117 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
118 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
119 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
120 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
121 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
122 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
123 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
124 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
125
126 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
127 i2c.hw_capable = true;
128 else
129 i2c.hw_capable = false;
130
131 if (gpio->sucI2cId.ucAccess == 0xa0)
132 i2c.mm_i2c = true;
133 else
134 i2c.mm_i2c = false;
135
136 i2c.i2c_id = gpio->sucI2cId.ucAccess;
137
138 if (i2c.mask_clk_reg)
139 i2c.valid = true;
140 else
141 i2c.valid = false;
142
143 return i2c;
144}
145
Andi Kleence580fa2011-10-13 16:08:47 -0700146static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
Alex Deuchereed45b32009-12-04 14:45:27 -0500147 uint8_t id)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200148{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200149 struct atom_context *ctx = rdev->mode_info.atom_context;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500150 ATOM_GPIO_I2C_ASSIGMENT *gpio;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200151 struct radeon_i2c_bus_rec i2c;
152 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
153 struct _ATOM_GPIO_I2C_INFO *i2c_info;
Alex Deucher95beb692010-04-01 19:08:47 +0000154 uint16_t data_offset, size;
155 int i, num_indices;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200156
157 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
158 i2c.valid = false;
159
Alex Deucher95beb692010-04-01 19:08:47 +0000160 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
Alex Deuchera084e6e2010-03-18 01:04:01 -0400161 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200162
Alex Deucher95beb692010-04-01 19:08:47 +0000163 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
164 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
165
166 for (i = 0; i < num_indices; i++) {
Alex Deuchera084e6e2010-03-18 01:04:01 -0400167 gpio = &i2c_info->asGPIO_Info[i];
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200168
Alex Deucher21240f92011-11-21 12:41:21 -0500169 radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
Alex Deucher3074adc2010-11-30 00:15:10 -0500170
Alex Deuchera084e6e2010-03-18 01:04:01 -0400171 if (gpio->sucI2cId.ucAccess == id) {
Alex Deucher21240f92011-11-21 12:41:21 -0500172 i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
Alex Deuchera084e6e2010-03-18 01:04:01 -0400173 break;
174 }
Alex Deucherd3f420d2009-12-08 14:30:49 -0500175 }
176 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200177
178 return i2c;
179}
180
Alex Deucherf376b942010-08-05 21:21:16 -0400181void radeon_atombios_i2c_init(struct radeon_device *rdev)
182{
183 struct atom_context *ctx = rdev->mode_info.atom_context;
184 ATOM_GPIO_I2C_ASSIGMENT *gpio;
185 struct radeon_i2c_bus_rec i2c;
186 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
187 struct _ATOM_GPIO_I2C_INFO *i2c_info;
188 uint16_t data_offset, size;
189 int i, num_indices;
190 char stmp[32];
191
Alex Deucherf376b942010-08-05 21:21:16 -0400192 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
193 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
194
195 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
196 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
197
198 for (i = 0; i < num_indices; i++) {
199 gpio = &i2c_info->asGPIO_Info[i];
Alex Deucherea393022010-08-27 16:04:29 -0400200
Alex Deucher21240f92011-11-21 12:41:21 -0500201 radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
Alex Deucherd7245022011-11-21 12:10:14 -0500202
Alex Deucher21240f92011-11-21 12:41:21 -0500203 i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
Alex Deucherea393022010-08-27 16:04:29 -0400204
Alex Deucher21240f92011-11-21 12:41:21 -0500205 if (i2c.valid) {
Alex Deucherf376b942010-08-05 21:21:16 -0400206 sprintf(stmp, "0x%x", i2c.i2c_id);
207 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
208 }
209 }
210 }
211}
212
Andi Kleence580fa2011-10-13 16:08:47 -0700213static struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
Alex Deuchereed45b32009-12-04 14:45:27 -0500214 u8 id)
215{
216 struct atom_context *ctx = rdev->mode_info.atom_context;
217 struct radeon_gpio_rec gpio;
218 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
219 struct _ATOM_GPIO_PIN_LUT *gpio_info;
220 ATOM_GPIO_PIN_ASSIGNMENT *pin;
221 u16 data_offset, size;
222 int i, num_indices;
223
224 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
225 gpio.valid = false;
226
Alex Deuchera084e6e2010-03-18 01:04:01 -0400227 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
228 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
Alex Deuchereed45b32009-12-04 14:45:27 -0500229
Alex Deuchera084e6e2010-03-18 01:04:01 -0400230 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
231 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
Alex Deuchereed45b32009-12-04 14:45:27 -0500232
Alex Deuchera084e6e2010-03-18 01:04:01 -0400233 for (i = 0; i < num_indices; i++) {
234 pin = &gpio_info->asGPIO_Pin[i];
235 if (id == pin->ucGPIO_ID) {
236 gpio.id = pin->ucGPIO_ID;
Cédric Cano45894332011-02-11 19:45:37 -0500237 gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex) * 4;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400238 gpio.mask = (1 << pin->ucGpioPinBitShift);
239 gpio.valid = true;
240 break;
241 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500242 }
243 }
244
245 return gpio;
246}
247
248static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
249 struct radeon_gpio_rec *gpio)
250{
251 struct radeon_hpd hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500252 u32 reg;
253
Jean Delvare1d978da2010-08-15 14:11:24 +0200254 memset(&hpd, 0, sizeof(struct radeon_hpd));
255
Alex Deucher82d118e2012-03-20 17:18:01 -0400256 if (ASIC_IS_DCE6(rdev))
257 reg = SI_DC_GPIO_HPD_A;
258 else if (ASIC_IS_DCE4(rdev))
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500259 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{
300
301 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
302 if ((dev->pdev->device == 0x791e) &&
303 (dev->pdev->subsystem_vendor == 0x1043) &&
304 (dev->pdev->subsystem_device == 0x826d)) {
305 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
306 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
307 *connector_type = DRM_MODE_CONNECTOR_DVID;
308 }
309
Alex Deucherc86a9032010-02-18 14:14:58 -0500310 /* Asrock RS600 board lists the DVI port as HDMI */
311 if ((dev->pdev->device == 0x7941) &&
312 (dev->pdev->subsystem_vendor == 0x1849) &&
313 (dev->pdev->subsystem_device == 0x7941)) {
314 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
315 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
316 *connector_type = DRM_MODE_CONNECTOR_DVID;
317 }
318
Alex Deucherf36fce02010-09-27 11:33:00 -0400319 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
320 if ((dev->pdev->device == 0x796e) &&
321 (dev->pdev->subsystem_vendor == 0x1462) &&
322 (dev->pdev->subsystem_device == 0x7302)) {
323 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
324 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
325 return false;
326 }
327
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200328 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
329 if ((dev->pdev->device == 0x7941) &&
330 (dev->pdev->subsystem_vendor == 0x147b) &&
331 (dev->pdev->subsystem_device == 0x2412)) {
332 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
333 return false;
334 }
335
336 /* Falcon NW laptop lists vga ddc line for LVDS */
337 if ((dev->pdev->device == 0x5653) &&
338 (dev->pdev->subsystem_vendor == 0x1462) &&
339 (dev->pdev->subsystem_device == 0x0291)) {
Alex Deucher848577e2009-07-08 16:15:30 -0400340 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200341 i2c_bus->valid = false;
Alex Deucher848577e2009-07-08 16:15:30 -0400342 *line_mux = 53;
343 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200344 }
345
Alex Deucher4e3f9b782009-12-01 14:49:50 -0500346 /* HIS X1300 is DVI+VGA, not DVI+DVI */
347 if ((dev->pdev->device == 0x7146) &&
348 (dev->pdev->subsystem_vendor == 0x17af) &&
349 (dev->pdev->subsystem_device == 0x2058)) {
350 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
351 return false;
352 }
353
Dave Airlieaa1a7502009-12-04 11:51:34 +1000354 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
355 if ((dev->pdev->device == 0x7142) &&
356 (dev->pdev->subsystem_vendor == 0x1458) &&
357 (dev->pdev->subsystem_device == 0x2134)) {
358 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
359 return false;
360 }
361
362
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200363 /* Funky macbooks */
364 if ((dev->pdev->device == 0x71C5) &&
365 (dev->pdev->subsystem_vendor == 0x106b) &&
366 (dev->pdev->subsystem_device == 0x0080)) {
367 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
368 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
369 return false;
Alex Deuchere1e8a5d2010-03-26 17:14:37 -0400370 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
371 *line_mux = 0x90;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200372 }
373
Alex Deucherbe23da82011-01-18 18:26:11 +0000374 /* mac rv630, rv730, others */
375 if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
376 (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
377 *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
378 *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
Alex Deucherf598aa72011-01-04 00:43:39 -0500379 }
380
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200381 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
382 if ((dev->pdev->device == 0x9598) &&
383 (dev->pdev->subsystem_vendor == 0x1043) &&
384 (dev->pdev->subsystem_device == 0x01da)) {
Alex Deucher705af9c2009-09-10 16:31:13 -0400385 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400386 *connector_type = DRM_MODE_CONNECTOR_DVII;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200387 }
388 }
389
Alex Deuchere153b702010-07-20 18:07:22 -0400390 /* ASUS HD 3600 board lists the DVI port as HDMI */
391 if ((dev->pdev->device == 0x9598) &&
392 (dev->pdev->subsystem_vendor == 0x1043) &&
393 (dev->pdev->subsystem_device == 0x01e4)) {
394 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
395 *connector_type = DRM_MODE_CONNECTOR_DVII;
396 }
397 }
398
Alex Deucher705af9c2009-09-10 16:31:13 -0400399 /* ASUS HD 3450 board lists the DVI port as HDMI */
400 if ((dev->pdev->device == 0x95C5) &&
401 (dev->pdev->subsystem_vendor == 0x1043) &&
402 (dev->pdev->subsystem_device == 0x01e2)) {
403 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400404 *connector_type = DRM_MODE_CONNECTOR_DVII;
Alex Deucher705af9c2009-09-10 16:31:13 -0400405 }
406 }
407
408 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
409 * HDMI + VGA reporting as HDMI
410 */
411 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
412 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
413 *connector_type = DRM_MODE_CONNECTOR_VGA;
414 *line_mux = 0;
415 }
416 }
417
Alex Deucher4f87af42011-05-04 11:41:47 -0400418 /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port
Alex Deucher2f299d52011-01-04 17:42:20 -0500419 * on the laptop and a DVI port on the docking station and
420 * both share the same encoder, hpd pin, and ddc line.
421 * So while the bios table is technically correct,
422 * we drop the DVI port here since xrandr has no concept of
423 * encoders and will try and drive both connectors
424 * with different crtcs which isn't possible on the hardware
425 * side and leaves no crtcs for LVDS or VGA.
426 */
Alex Deucher4f87af42011-05-04 11:41:47 -0400427 if (((dev->pdev->device == 0x95c4) || (dev->pdev->device == 0x9591)) &&
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500428 (dev->pdev->subsystem_vendor == 0x1025) &&
429 (dev->pdev->subsystem_device == 0x013c)) {
430 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400431 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
Alex Deucher2f299d52011-01-04 17:42:20 -0500432 /* actually it's a DVI-D port not DVI-I */
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500433 *connector_type = DRM_MODE_CONNECTOR_DVID;
Alex Deucher2f299d52011-01-04 17:42:20 -0500434 return false;
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400435 }
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500436 }
437
Dave Airlieefa84502010-02-09 09:06:00 +1000438 /* XFX Pine Group device rv730 reports no VGA DDC lines
439 * even though they are wired up to record 0x93
440 */
441 if ((dev->pdev->device == 0x9498) &&
442 (dev->pdev->subsystem_vendor == 0x1682) &&
443 (dev->pdev->subsystem_device == 0x2452)) {
444 struct radeon_device *rdev = dev->dev_private;
445 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
446 }
Alex Deucher4c1b2d22012-03-16 12:22:10 -0400447
448 /* Fujitsu D3003-S2 board lists DVI-I as DVI-D and VGA */
449 if ((dev->pdev->device == 0x9802) &&
450 (dev->pdev->subsystem_vendor == 0x1734) &&
451 (dev->pdev->subsystem_device == 0x11bd)) {
452 if (*connector_type == DRM_MODE_CONNECTOR_VGA) {
453 *connector_type = DRM_MODE_CONNECTOR_DVII;
454 *line_mux = 0x3103;
455 } else if (*connector_type == DRM_MODE_CONNECTOR_DVID) {
456 *connector_type = DRM_MODE_CONNECTOR_DVII;
457 }
458 }
459
460
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200461 return true;
462}
463
464const int supported_devices_connector_convert[] = {
465 DRM_MODE_CONNECTOR_Unknown,
466 DRM_MODE_CONNECTOR_VGA,
467 DRM_MODE_CONNECTOR_DVII,
468 DRM_MODE_CONNECTOR_DVID,
469 DRM_MODE_CONNECTOR_DVIA,
470 DRM_MODE_CONNECTOR_SVIDEO,
471 DRM_MODE_CONNECTOR_Composite,
472 DRM_MODE_CONNECTOR_LVDS,
473 DRM_MODE_CONNECTOR_Unknown,
474 DRM_MODE_CONNECTOR_Unknown,
475 DRM_MODE_CONNECTOR_HDMIA,
476 DRM_MODE_CONNECTOR_HDMIB,
477 DRM_MODE_CONNECTOR_Unknown,
478 DRM_MODE_CONNECTOR_Unknown,
479 DRM_MODE_CONNECTOR_9PinDIN,
480 DRM_MODE_CONNECTOR_DisplayPort
481};
482
Alex Deucherb75fad02009-11-05 13:16:01 -0500483const uint16_t supported_devices_connector_object_id_convert[] = {
484 CONNECTOR_OBJECT_ID_NONE,
485 CONNECTOR_OBJECT_ID_VGA,
486 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
487 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
488 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
489 CONNECTOR_OBJECT_ID_COMPOSITE,
490 CONNECTOR_OBJECT_ID_SVIDEO,
491 CONNECTOR_OBJECT_ID_LVDS,
492 CONNECTOR_OBJECT_ID_9PIN_DIN,
493 CONNECTOR_OBJECT_ID_9PIN_DIN,
494 CONNECTOR_OBJECT_ID_DISPLAYPORT,
495 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
496 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
497 CONNECTOR_OBJECT_ID_SVIDEO
498};
499
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200500const int object_connector_convert[] = {
501 DRM_MODE_CONNECTOR_Unknown,
502 DRM_MODE_CONNECTOR_DVII,
503 DRM_MODE_CONNECTOR_DVII,
504 DRM_MODE_CONNECTOR_DVID,
505 DRM_MODE_CONNECTOR_DVID,
506 DRM_MODE_CONNECTOR_VGA,
507 DRM_MODE_CONNECTOR_Composite,
508 DRM_MODE_CONNECTOR_SVIDEO,
509 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher705af9c2009-09-10 16:31:13 -0400510 DRM_MODE_CONNECTOR_Unknown,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200511 DRM_MODE_CONNECTOR_9PinDIN,
512 DRM_MODE_CONNECTOR_Unknown,
513 DRM_MODE_CONNECTOR_HDMIA,
514 DRM_MODE_CONNECTOR_HDMIB,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200515 DRM_MODE_CONNECTOR_LVDS,
516 DRM_MODE_CONNECTOR_9PinDIN,
517 DRM_MODE_CONNECTOR_Unknown,
518 DRM_MODE_CONNECTOR_Unknown,
519 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher196c58d2010-01-07 14:22:32 -0500520 DRM_MODE_CONNECTOR_DisplayPort,
521 DRM_MODE_CONNECTOR_eDP,
522 DRM_MODE_CONNECTOR_Unknown
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200523};
524
525bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
526{
527 struct radeon_device *rdev = dev->dev_private;
528 struct radeon_mode_info *mode_info = &rdev->mode_info;
529 struct atom_context *ctx = mode_info->atom_context;
530 int index = GetIndexIntoMasterTable(DATA, Object_Header);
Alex Deuchereed45b32009-12-04 14:45:27 -0500531 u16 size, data_offset;
532 u8 frev, crev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200533 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
Alex Deucher36868bd2011-01-06 21:19:21 -0500534 ATOM_ENCODER_OBJECT_TABLE *enc_obj;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400535 ATOM_OBJECT_TABLE *router_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200536 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
537 ATOM_OBJECT_HEADER *obj_header;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400538 int i, j, k, path_size, device_support;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200539 int connector_type;
Alex Deuchereed45b32009-12-04 14:45:27 -0500540 u16 igp_lane_info, conn_id, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200541 struct radeon_i2c_bus_rec ddc_bus;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400542 struct radeon_router router;
Alex Deuchereed45b32009-12-04 14:45:27 -0500543 struct radeon_gpio_rec gpio;
544 struct radeon_hpd hpd;
545
Alex Deuchera084e6e2010-03-18 01:04:01 -0400546 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200547 return false;
548
549 if (crev < 2)
550 return false;
551
552 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
553 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
554 (ctx->bios + data_offset +
555 le16_to_cpu(obj_header->usDisplayPathTableOffset));
556 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
557 (ctx->bios + data_offset +
558 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
Alex Deucher36868bd2011-01-06 21:19:21 -0500559 enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
560 (ctx->bios + data_offset +
561 le16_to_cpu(obj_header->usEncoderObjectTableOffset));
Alex Deucher26b5bc92010-08-05 21:21:18 -0400562 router_obj = (ATOM_OBJECT_TABLE *)
563 (ctx->bios + data_offset +
564 le16_to_cpu(obj_header->usRouterObjectTableOffset));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200565 device_support = le16_to_cpu(obj_header->usDeviceSupport);
566
567 path_size = 0;
568 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
569 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
570 ATOM_DISPLAY_OBJECT_PATH *path;
571 addr += path_size;
572 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
573 path_size += le16_to_cpu(path->usSize);
Alex Deucher5137ee92010-08-12 18:58:47 -0400574
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200575 if (device_support & le16_to_cpu(path->usDeviceTag)) {
576 uint8_t con_obj_id, con_obj_num, con_obj_type;
577
578 con_obj_id =
579 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
580 >> OBJECT_ID_SHIFT;
581 con_obj_num =
582 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
583 >> ENUM_ID_SHIFT;
584 con_obj_type =
585 (le16_to_cpu(path->usConnObjectId) &
586 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
587
Dave Airlie4bbd4972009-09-25 08:56:12 +1000588 /* TODO CV support */
589 if (le16_to_cpu(path->usDeviceTag) ==
590 ATOM_DEVICE_CV_SUPPORT)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200591 continue;
592
Alex Deucheree59f2b2009-11-05 13:11:46 -0500593 /* IGP chips */
594 if ((rdev->flags & RADEON_IS_IGP) &&
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200595 (con_obj_id ==
596 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
597 uint16_t igp_offset = 0;
598 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
599
600 index =
601 GetIndexIntoMasterTable(DATA,
602 IntegratedSystemInfo);
603
Alex Deuchera084e6e2010-03-18 01:04:01 -0400604 if (atom_parse_data_header(ctx, index, &size, &frev,
605 &crev, &igp_offset)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200606
Alex Deuchera084e6e2010-03-18 01:04:01 -0400607 if (crev >= 2) {
608 igp_obj =
609 (ATOM_INTEGRATED_SYSTEM_INFO_V2
610 *) (ctx->bios + igp_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200611
Alex Deuchera084e6e2010-03-18 01:04:01 -0400612 if (igp_obj) {
613 uint32_t slot_config, ct;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200614
Alex Deuchera084e6e2010-03-18 01:04:01 -0400615 if (con_obj_num == 1)
616 slot_config =
617 igp_obj->
618 ulDDISlot1Config;
619 else
620 slot_config =
621 igp_obj->
622 ulDDISlot2Config;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200623
Alex Deuchera084e6e2010-03-18 01:04:01 -0400624 ct = (slot_config >> 16) & 0xff;
625 connector_type =
626 object_connector_convert
627 [ct];
628 connector_object_id = ct;
629 igp_lane_info =
630 slot_config & 0xffff;
631 } else
632 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200633 } else
634 continue;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400635 } else {
636 igp_lane_info = 0;
637 connector_type =
638 object_connector_convert[con_obj_id];
639 connector_object_id = con_obj_id;
640 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200641 } else {
642 igp_lane_info = 0;
643 connector_type =
644 object_connector_convert[con_obj_id];
Alex Deucherb75fad02009-11-05 13:16:01 -0500645 connector_object_id = con_obj_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200646 }
647
648 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
649 continue;
650
Tyson Whiteheadbdd91b22010-11-08 16:08:30 +0000651 router.ddc_valid = false;
652 router.cd_valid = false;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400653 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
654 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200655
Alex Deucher26b5bc92010-08-05 21:21:18 -0400656 grph_obj_id =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200657 (le16_to_cpu(path->usGraphicObjIds[j]) &
658 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400659 grph_obj_num =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200660 (le16_to_cpu(path->usGraphicObjIds[j]) &
661 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400662 grph_obj_type =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200663 (le16_to_cpu(path->usGraphicObjIds[j]) &
664 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
665
Alex Deucher26b5bc92010-08-05 21:21:18 -0400666 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
Alex Deucher36868bd2011-01-06 21:19:21 -0500667 for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
668 u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
669 if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
670 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
671 (ctx->bios + data_offset +
672 le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
673 ATOM_ENCODER_CAP_RECORD *cap_record;
674 u16 caps = 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200675
John Lindgren97ea5302011-03-24 23:28:31 +0000676 while (record->ucRecordSize > 0 &&
677 record->ucRecordType > 0 &&
Alex Deucher36868bd2011-01-06 21:19:21 -0500678 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
679 switch (record->ucRecordType) {
680 case ATOM_ENCODER_CAP_RECORD_TYPE:
681 cap_record =(ATOM_ENCODER_CAP_RECORD *)
682 record;
683 caps = le16_to_cpu(cap_record->usEncoderCap);
684 break;
685 }
686 record = (ATOM_COMMON_RECORD_HEADER *)
687 ((char *)record + record->ucRecordSize);
688 }
689 radeon_add_atom_encoder(dev,
690 encoder_obj,
691 le16_to_cpu
692 (path->
693 usDeviceTag),
694 caps);
695 }
696 }
Alex Deucher26b5bc92010-08-05 21:21:18 -0400697 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
Alex Deucher26b5bc92010-08-05 21:21:18 -0400698 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
Tyson Whiteheadbdd91b22010-11-08 16:08:30 +0000699 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
Alex Deucher26b5bc92010-08-05 21:21:18 -0400700 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
701 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
702 (ctx->bios + data_offset +
703 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
704 ATOM_I2C_RECORD *i2c_record;
705 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
706 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
Alex Deucherfb939df2010-11-08 16:08:29 +0000707 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400708 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
709 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
710 (ctx->bios + data_offset +
711 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
712 int enum_id;
713
714 router.router_id = router_obj_id;
715 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
716 enum_id++) {
717 if (le16_to_cpu(path->usConnObjectId) ==
718 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
719 break;
720 }
721
John Lindgren97ea5302011-03-24 23:28:31 +0000722 while (record->ucRecordSize > 0 &&
723 record->ucRecordType > 0 &&
Alex Deucher26b5bc92010-08-05 21:21:18 -0400724 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
725 switch (record->ucRecordType) {
726 case ATOM_I2C_RECORD_TYPE:
727 i2c_record =
728 (ATOM_I2C_RECORD *)
729 record;
730 i2c_config =
731 (ATOM_I2C_ID_CONFIG_ACCESS *)
732 &i2c_record->sucI2cId;
733 router.i2c_info =
734 radeon_lookup_i2c_gpio(rdev,
735 i2c_config->
736 ucAccess);
737 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
738 break;
739 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
740 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
741 record;
Alex Deucherfb939df2010-11-08 16:08:29 +0000742 router.ddc_valid = true;
743 router.ddc_mux_type = ddc_path->ucMuxType;
744 router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
745 router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
746 break;
747 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
748 cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
749 record;
750 router.cd_valid = true;
751 router.cd_mux_type = cd_path->ucMuxType;
752 router.cd_mux_control_pin = cd_path->ucMuxControlPin;
753 router.cd_mux_state = cd_path->ucMuxState[enum_id];
Alex Deucher26b5bc92010-08-05 21:21:18 -0400754 break;
755 }
756 record = (ATOM_COMMON_RECORD_HEADER *)
757 ((char *)record + record->ucRecordSize);
758 }
759 }
760 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200761 }
762 }
763
Alex Deuchereed45b32009-12-04 14:45:27 -0500764 /* look up gpio for ddc, hpd */
Alex Deucher2bfcc0f2010-05-18 19:26:46 -0400765 ddc_bus.valid = false;
766 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200767 if ((le16_to_cpu(path->usDeviceTag) &
Alex Deuchereed45b32009-12-04 14:45:27 -0500768 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200769 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
770 if (le16_to_cpu(path->usConnObjectId) ==
771 le16_to_cpu(con_obj->asObjects[j].
772 usObjectID)) {
773 ATOM_COMMON_RECORD_HEADER
774 *record =
775 (ATOM_COMMON_RECORD_HEADER
776 *)
777 (ctx->bios + data_offset +
778 le16_to_cpu(con_obj->
779 asObjects[j].
780 usRecordOffset));
781 ATOM_I2C_RECORD *i2c_record;
Alex Deuchereed45b32009-12-04 14:45:27 -0500782 ATOM_HPD_INT_RECORD *hpd_record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500783 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500784
John Lindgren97ea5302011-03-24 23:28:31 +0000785 while (record->ucRecordSize > 0 &&
786 record->ucRecordType > 0 &&
787 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500788 switch (record->ucRecordType) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200789 case ATOM_I2C_RECORD_TYPE:
790 i2c_record =
Alex Deuchereed45b32009-12-04 14:45:27 -0500791 (ATOM_I2C_RECORD *)
792 record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500793 i2c_config =
794 (ATOM_I2C_ID_CONFIG_ACCESS *)
795 &i2c_record->sucI2cId;
Alex Deuchereed45b32009-12-04 14:45:27 -0500796 ddc_bus = radeon_lookup_i2c_gpio(rdev,
Alex Deucherd3f420d2009-12-08 14:30:49 -0500797 i2c_config->
798 ucAccess);
Alex Deuchereed45b32009-12-04 14:45:27 -0500799 break;
800 case ATOM_HPD_INT_RECORD_TYPE:
801 hpd_record =
802 (ATOM_HPD_INT_RECORD *)
803 record;
804 gpio = radeon_lookup_gpio(rdev,
805 hpd_record->ucHPDIntGPIOID);
806 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
807 hpd.plugged_state = hpd_record->ucPlugged_PinState;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200808 break;
809 }
810 record =
811 (ATOM_COMMON_RECORD_HEADER
812 *) ((char *)record
813 +
814 record->
815 ucRecordSize);
816 }
817 break;
818 }
819 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500820 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200821
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500822 /* needed for aux chan transactions */
Alex Deucher8e36ed02010-05-18 19:26:47 -0400823 ddc_bus.hpd = hpd.hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500824
Alex Deucher705af9c2009-09-10 16:31:13 -0400825 conn_id = le16_to_cpu(path->usConnObjectId);
826
827 if (!radeon_atom_apply_quirks
828 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500829 &ddc_bus, &conn_id, &hpd))
Alex Deucher705af9c2009-09-10 16:31:13 -0400830 continue;
831
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200832 radeon_add_atom_connector(dev,
Alex Deucher705af9c2009-09-10 16:31:13 -0400833 conn_id,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200834 le16_to_cpu(path->
835 usDeviceTag),
836 connector_type, &ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -0400837 igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -0500838 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -0400839 &hpd,
840 &router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200841
842 }
843 }
844
845 radeon_link_encoder_connector(dev);
846
847 return true;
848}
849
Alex Deucherb75fad02009-11-05 13:16:01 -0500850static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
851 int connector_type,
852 uint16_t devices)
853{
854 struct radeon_device *rdev = dev->dev_private;
855
856 if (rdev->flags & RADEON_IS_IGP) {
857 return supported_devices_connector_object_id_convert
858 [connector_type];
859 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
860 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
861 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
862 struct radeon_mode_info *mode_info = &rdev->mode_info;
863 struct atom_context *ctx = mode_info->atom_context;
864 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
865 uint16_t size, data_offset;
866 uint8_t frev, crev;
867 ATOM_XTMDS_INFO *xtmds;
868
Alex Deuchera084e6e2010-03-18 01:04:01 -0400869 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
870 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
Alex Deucherb75fad02009-11-05 13:16:01 -0500871
Alex Deuchera084e6e2010-03-18 01:04:01 -0400872 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
873 if (connector_type == DRM_MODE_CONNECTOR_DVII)
874 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
875 else
876 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
877 } else {
878 if (connector_type == DRM_MODE_CONNECTOR_DVII)
879 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
880 else
881 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
882 }
883 } else
884 return supported_devices_connector_object_id_convert
885 [connector_type];
Alex Deucherb75fad02009-11-05 13:16:01 -0500886 } else {
887 return supported_devices_connector_object_id_convert
888 [connector_type];
889 }
890}
891
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200892struct bios_connector {
893 bool valid;
Alex Deucher705af9c2009-09-10 16:31:13 -0400894 uint16_t line_mux;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200895 uint16_t devices;
896 int connector_type;
897 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500898 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200899};
900
901bool radeon_get_atom_connector_info_from_supported_devices_table(struct
902 drm_device
903 *dev)
904{
905 struct radeon_device *rdev = dev->dev_private;
906 struct radeon_mode_info *mode_info = &rdev->mode_info;
907 struct atom_context *ctx = mode_info->atom_context;
908 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
909 uint16_t size, data_offset;
910 uint8_t frev, crev;
911 uint16_t device_support;
912 uint8_t dac;
913 union atom_supported_devices *supported_devices;
Alex Deuchereed45b32009-12-04 14:45:27 -0500914 int i, j, max_device;
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000915 struct bios_connector *bios_connectors;
916 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400917 struct radeon_router router;
918
Alex Deucherfb939df2010-11-08 16:08:29 +0000919 router.ddc_valid = false;
920 router.cd_valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200921
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000922 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
923 if (!bios_connectors)
Alex Deuchera084e6e2010-03-18 01:04:01 -0400924 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200925
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000926 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
927 &data_offset)) {
928 kfree(bios_connectors);
929 return false;
930 }
931
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200932 supported_devices =
933 (union atom_supported_devices *)(ctx->bios + data_offset);
934
935 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
936
Alex Deuchereed45b32009-12-04 14:45:27 -0500937 if (frev > 1)
938 max_device = ATOM_MAX_SUPPORTED_DEVICE;
939 else
940 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
941
942 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200943 ATOM_CONNECTOR_INFO_I2C ci =
944 supported_devices->info.asConnInfo[i];
945
946 bios_connectors[i].valid = false;
947
948 if (!(device_support & (1 << i))) {
949 continue;
950 }
951
952 if (i == ATOM_DEVICE_CV_INDEX) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000953 DRM_DEBUG_KMS("Skipping Component Video\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200954 continue;
955 }
956
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200957 bios_connectors[i].connector_type =
958 supported_devices_connector_convert[ci.sucConnectorInfo.
959 sbfAccess.
960 bfConnectorType];
961
962 if (bios_connectors[i].connector_type ==
963 DRM_MODE_CONNECTOR_Unknown)
964 continue;
965
966 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
967
Alex Deucherd3f420d2009-12-08 14:30:49 -0500968 bios_connectors[i].line_mux =
969 ci.sucI2cId.ucAccess;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200970
971 /* give tv unique connector ids */
972 if (i == ATOM_DEVICE_TV1_INDEX) {
973 bios_connectors[i].ddc_bus.valid = false;
974 bios_connectors[i].line_mux = 50;
975 } else if (i == ATOM_DEVICE_TV2_INDEX) {
976 bios_connectors[i].ddc_bus.valid = false;
977 bios_connectors[i].line_mux = 51;
978 } else if (i == ATOM_DEVICE_CV_INDEX) {
979 bios_connectors[i].ddc_bus.valid = false;
980 bios_connectors[i].line_mux = 52;
981 } else
982 bios_connectors[i].ddc_bus =
Alex Deuchereed45b32009-12-04 14:45:27 -0500983 radeon_lookup_i2c_gpio(rdev,
984 bios_connectors[i].line_mux);
985
986 if ((crev > 1) && (frev > 1)) {
987 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
988 switch (isb) {
989 case 0x4:
990 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
991 break;
992 case 0xa:
993 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
994 break;
995 default:
996 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
997 break;
998 }
999 } else {
1000 if (i == ATOM_DEVICE_DFP1_INDEX)
1001 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
1002 else if (i == ATOM_DEVICE_DFP2_INDEX)
1003 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
1004 else
1005 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
1006 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001007
1008 /* Always set the connector type to VGA for CRT1/CRT2. if they are
1009 * shared with a DVI port, we'll pick up the DVI connector when we
1010 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
1011 */
1012 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
1013 bios_connectors[i].connector_type =
1014 DRM_MODE_CONNECTOR_VGA;
1015
1016 if (!radeon_atom_apply_quirks
1017 (dev, (1 << i), &bios_connectors[i].connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -05001018 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
1019 &bios_connectors[i].hpd))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001020 continue;
1021
1022 bios_connectors[i].valid = true;
1023 bios_connectors[i].devices = (1 << i);
1024
1025 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
1026 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001027 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001028 (1 << i),
1029 dac),
Alex Deucher36868bd2011-01-06 21:19:21 -05001030 (1 << i),
1031 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001032 else
1033 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001034 radeon_get_encoder_enum(dev,
Alex Deucherf56cd642009-12-18 11:28:22 -05001035 (1 << i),
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001036 dac),
1037 (1 << i));
1038 }
1039
1040 /* combine shared connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -05001041 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001042 if (bios_connectors[i].valid) {
Alex Deuchereed45b32009-12-04 14:45:27 -05001043 for (j = 0; j < max_device; j++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001044 if (bios_connectors[j].valid && (i != j)) {
1045 if (bios_connectors[i].line_mux ==
1046 bios_connectors[j].line_mux) {
Alex Deucherf56cd642009-12-18 11:28:22 -05001047 /* make sure not to combine LVDS */
1048 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1049 bios_connectors[i].line_mux = 53;
1050 bios_connectors[i].ddc_bus.valid = false;
1051 continue;
1052 }
1053 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1054 bios_connectors[j].line_mux = 53;
1055 bios_connectors[j].ddc_bus.valid = false;
1056 continue;
1057 }
1058 /* combine analog and digital for DVI-I */
1059 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1060 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
1061 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1062 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
1063 bios_connectors[i].devices |=
1064 bios_connectors[j].devices;
1065 bios_connectors[i].connector_type =
1066 DRM_MODE_CONNECTOR_DVII;
1067 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
Alex Deuchereed45b32009-12-04 14:45:27 -05001068 bios_connectors[i].hpd =
1069 bios_connectors[j].hpd;
Alex Deucherf56cd642009-12-18 11:28:22 -05001070 bios_connectors[j].valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001071 }
1072 }
1073 }
1074 }
1075 }
1076 }
1077
1078 /* add the connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -05001079 for (i = 0; i < max_device; i++) {
Alex Deucherb75fad02009-11-05 13:16:01 -05001080 if (bios_connectors[i].valid) {
1081 uint16_t connector_object_id =
1082 atombios_get_connector_object_id(dev,
1083 bios_connectors[i].connector_type,
1084 bios_connectors[i].devices);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001085 radeon_add_atom_connector(dev,
1086 bios_connectors[i].line_mux,
1087 bios_connectors[i].devices,
1088 bios_connectors[i].
1089 connector_type,
1090 &bios_connectors[i].ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -04001091 0,
Alex Deuchereed45b32009-12-04 14:45:27 -05001092 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001093 &bios_connectors[i].hpd,
1094 &router);
Alex Deucherb75fad02009-11-05 13:16:01 -05001095 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001096 }
1097
1098 radeon_link_encoder_connector(dev);
1099
Prarit Bhargavaf49d2732010-05-24 10:24:07 +10001100 kfree(bios_connectors);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001101 return true;
1102}
1103
1104union firmware_info {
1105 ATOM_FIRMWARE_INFO info;
1106 ATOM_FIRMWARE_INFO_V1_2 info_12;
1107 ATOM_FIRMWARE_INFO_V1_3 info_13;
1108 ATOM_FIRMWARE_INFO_V1_4 info_14;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001109 ATOM_FIRMWARE_INFO_V2_1 info_21;
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001110 ATOM_FIRMWARE_INFO_V2_2 info_22;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001111};
1112
1113bool radeon_atom_get_clock_info(struct drm_device *dev)
1114{
1115 struct radeon_device *rdev = dev->dev_private;
1116 struct radeon_mode_info *mode_info = &rdev->mode_info;
1117 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1118 union firmware_info *firmware_info;
1119 uint8_t frev, crev;
1120 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1121 struct radeon_pll *p2pll = &rdev->clock.p2pll;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001122 struct radeon_pll *dcpll = &rdev->clock.dcpll;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001123 struct radeon_pll *spll = &rdev->clock.spll;
1124 struct radeon_pll *mpll = &rdev->clock.mpll;
1125 uint16_t data_offset;
1126
Alex Deuchera084e6e2010-03-18 01:04:01 -04001127 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1128 &frev, &crev, &data_offset)) {
1129 firmware_info =
1130 (union firmware_info *)(mode_info->atom_context->bios +
1131 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001132 /* pixel clocks */
1133 p1pll->reference_freq =
1134 le16_to_cpu(firmware_info->info.usReferenceClock);
1135 p1pll->reference_div = 0;
1136
Mathias Fröhlichbc293e52009-10-19 17:49:49 -04001137 if (crev < 2)
1138 p1pll->pll_out_min =
1139 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1140 else
1141 p1pll->pll_out_min =
1142 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001143 p1pll->pll_out_max =
1144 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1145
Alex Deucher86cb2bb2010-03-08 12:55:16 -05001146 if (crev >= 4) {
1147 p1pll->lcd_pll_out_min =
1148 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1149 if (p1pll->lcd_pll_out_min == 0)
1150 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1151 p1pll->lcd_pll_out_max =
1152 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1153 if (p1pll->lcd_pll_out_max == 0)
1154 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1155 } else {
1156 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1157 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1158 }
1159
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001160 if (p1pll->pll_out_min == 0) {
1161 if (ASIC_IS_AVIVO(rdev))
1162 p1pll->pll_out_min = 64800;
1163 else
1164 p1pll->pll_out_min = 20000;
1165 }
1166
1167 p1pll->pll_in_min =
1168 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1169 p1pll->pll_in_max =
1170 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1171
1172 *p2pll = *p1pll;
1173
1174 /* system clock */
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001175 if (ASIC_IS_DCE4(rdev))
1176 spll->reference_freq =
1177 le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
1178 else
1179 spll->reference_freq =
1180 le16_to_cpu(firmware_info->info.usReferenceClock);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001181 spll->reference_div = 0;
1182
1183 spll->pll_out_min =
1184 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1185 spll->pll_out_max =
1186 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1187
1188 /* ??? */
1189 if (spll->pll_out_min == 0) {
1190 if (ASIC_IS_AVIVO(rdev))
1191 spll->pll_out_min = 64800;
1192 else
1193 spll->pll_out_min = 20000;
1194 }
1195
1196 spll->pll_in_min =
1197 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1198 spll->pll_in_max =
1199 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1200
1201 /* memory clock */
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001202 if (ASIC_IS_DCE4(rdev))
1203 mpll->reference_freq =
1204 le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
1205 else
1206 mpll->reference_freq =
1207 le16_to_cpu(firmware_info->info.usReferenceClock);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001208 mpll->reference_div = 0;
1209
1210 mpll->pll_out_min =
1211 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1212 mpll->pll_out_max =
1213 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1214
1215 /* ??? */
1216 if (mpll->pll_out_min == 0) {
1217 if (ASIC_IS_AVIVO(rdev))
1218 mpll->pll_out_min = 64800;
1219 else
1220 mpll->pll_out_min = 20000;
1221 }
1222
1223 mpll->pll_in_min =
1224 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1225 mpll->pll_in_max =
1226 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1227
1228 rdev->clock.default_sclk =
1229 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1230 rdev->clock.default_mclk =
1231 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1232
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001233 if (ASIC_IS_DCE4(rdev)) {
1234 rdev->clock.default_dispclk =
1235 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001236 if (rdev->clock.default_dispclk == 0) {
1237 if (ASIC_IS_DCE5(rdev))
1238 rdev->clock.default_dispclk = 54000; /* 540 Mhz */
1239 else
1240 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1241 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001242 rdev->clock.dp_extclk =
1243 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
1244 }
1245 *dcpll = *p1pll;
1246
Alex Deucherb20f9be2011-06-08 13:01:11 -04001247 rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
1248 if (rdev->clock.max_pixel_clock == 0)
1249 rdev->clock.max_pixel_clock = 40000;
1250
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001251 return true;
1252 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001253
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001254 return false;
1255}
1256
Alex Deucher06b64762010-01-05 11:27:29 -05001257union igp_info {
1258 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1259 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1260};
1261
1262bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1263{
1264 struct radeon_mode_info *mode_info = &rdev->mode_info;
1265 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1266 union igp_info *igp_info;
1267 u8 frev, crev;
1268 u16 data_offset;
1269
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001270 /* sideport is AMD only */
1271 if (rdev->family == CHIP_RS600)
1272 return false;
1273
Alex Deuchera084e6e2010-03-18 01:04:01 -04001274 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1275 &frev, &crev, &data_offset)) {
1276 igp_info = (union igp_info *)(mode_info->atom_context->bios +
Alex Deucher06b64762010-01-05 11:27:29 -05001277 data_offset);
Alex Deucher06b64762010-01-05 11:27:29 -05001278 switch (crev) {
1279 case 1:
Cédric Cano45894332011-02-11 19:45:37 -05001280 if (le32_to_cpu(igp_info->info.ulBootUpMemoryClock))
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001281 return true;
Alex Deucher06b64762010-01-05 11:27:29 -05001282 break;
1283 case 2:
Cédric Cano45894332011-02-11 19:45:37 -05001284 if (le32_to_cpu(igp_info->info_2.ulBootUpSidePortClock))
Alex Deucher06b64762010-01-05 11:27:29 -05001285 return true;
1286 break;
1287 default:
1288 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1289 break;
1290 }
1291 }
1292 return false;
1293}
1294
Dave Airlie445282d2009-09-09 17:40:54 +10001295bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1296 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001297{
1298 struct drm_device *dev = encoder->base.dev;
1299 struct radeon_device *rdev = dev->dev_private;
1300 struct radeon_mode_info *mode_info = &rdev->mode_info;
1301 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1302 uint16_t data_offset;
1303 struct _ATOM_TMDS_INFO *tmds_info;
1304 uint8_t frev, crev;
1305 uint16_t maxfreq;
1306 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001307
Alex Deuchera084e6e2010-03-18 01:04:01 -04001308 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1309 &frev, &crev, &data_offset)) {
1310 tmds_info =
1311 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1312 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001313
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001314 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1315 for (i = 0; i < 4; i++) {
1316 tmds->tmds_pll[i].freq =
1317 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1318 tmds->tmds_pll[i].value =
1319 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1320 tmds->tmds_pll[i].value |=
1321 (tmds_info->asMiscInfo[i].
1322 ucPLL_VCO_Gain & 0x3f) << 6;
1323 tmds->tmds_pll[i].value |=
1324 (tmds_info->asMiscInfo[i].
1325 ucPLL_DutyCycle & 0xf) << 12;
1326 tmds->tmds_pll[i].value |=
1327 (tmds_info->asMiscInfo[i].
1328 ucPLL_VoltageSwing & 0xf) << 16;
1329
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001330 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001331 tmds->tmds_pll[i].freq,
1332 tmds->tmds_pll[i].value);
1333
1334 if (maxfreq == tmds->tmds_pll[i].freq) {
1335 tmds->tmds_pll[i].freq = 0xffffffff;
1336 break;
1337 }
1338 }
Dave Airlie445282d2009-09-09 17:40:54 +10001339 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001340 }
Dave Airlie445282d2009-09-09 17:40:54 +10001341 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001342}
1343
Alex Deucherba032a52010-10-04 17:13:01 -04001344bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
1345 struct radeon_atom_ss *ss,
1346 int id)
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001347{
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001348 struct radeon_mode_info *mode_info = &rdev->mode_info;
1349 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
Alex Deucherba032a52010-10-04 17:13:01 -04001350 uint16_t data_offset, size;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001351 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1352 uint8_t frev, crev;
Alex Deucherba032a52010-10-04 17:13:01 -04001353 int i, num_indices;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001354
Alex Deucherba032a52010-10-04 17:13:01 -04001355 memset(ss, 0, sizeof(struct radeon_atom_ss));
1356 if (atom_parse_data_header(mode_info->atom_context, index, &size,
Alex Deuchera084e6e2010-03-18 01:04:01 -04001357 &frev, &crev, &data_offset)) {
1358 ss_info =
1359 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001360
Alex Deucherba032a52010-10-04 17:13:01 -04001361 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1362 sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001363
Alex Deucherba032a52010-10-04 17:13:01 -04001364 for (i = 0; i < num_indices; i++) {
Alex Deucher279b2152009-12-08 14:07:03 -05001365 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1366 ss->percentage =
1367 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1368 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1369 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1370 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1371 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1372 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
Alex Deucherba032a52010-10-04 17:13:01 -04001373 return true;
Alex Deucher279b2152009-12-08 14:07:03 -05001374 }
1375 }
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001376 }
Alex Deucherba032a52010-10-04 17:13:01 -04001377 return false;
1378}
1379
Alex Deucher4339c442010-11-22 17:56:25 -05001380static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
1381 struct radeon_atom_ss *ss,
1382 int id)
1383{
1384 struct radeon_mode_info *mode_info = &rdev->mode_info;
1385 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1386 u16 data_offset, size;
1387 struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *igp_info;
1388 u8 frev, crev;
1389 u16 percentage = 0, rate = 0;
1390
1391 /* get any igp specific overrides */
1392 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1393 &frev, &crev, &data_offset)) {
1394 igp_info = (struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *)
1395 (mode_info->atom_context->bios + data_offset);
1396 switch (id) {
1397 case ASIC_INTERNAL_SS_ON_TMDS:
1398 percentage = le16_to_cpu(igp_info->usDVISSPercentage);
1399 rate = le16_to_cpu(igp_info->usDVISSpreadRateIn10Hz);
1400 break;
1401 case ASIC_INTERNAL_SS_ON_HDMI:
1402 percentage = le16_to_cpu(igp_info->usHDMISSPercentage);
1403 rate = le16_to_cpu(igp_info->usHDMISSpreadRateIn10Hz);
1404 break;
1405 case ASIC_INTERNAL_SS_ON_LVDS:
1406 percentage = le16_to_cpu(igp_info->usLvdsSSPercentage);
1407 rate = le16_to_cpu(igp_info->usLvdsSSpreadRateIn10Hz);
1408 break;
1409 }
1410 if (percentage)
1411 ss->percentage = percentage;
1412 if (rate)
1413 ss->rate = rate;
1414 }
1415}
1416
Alex Deucherba032a52010-10-04 17:13:01 -04001417union asic_ss_info {
1418 struct _ATOM_ASIC_INTERNAL_SS_INFO info;
1419 struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
1420 struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
1421};
1422
1423bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
1424 struct radeon_atom_ss *ss,
1425 int id, u32 clock)
1426{
1427 struct radeon_mode_info *mode_info = &rdev->mode_info;
1428 int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
1429 uint16_t data_offset, size;
1430 union asic_ss_info *ss_info;
1431 uint8_t frev, crev;
1432 int i, num_indices;
1433
1434 memset(ss, 0, sizeof(struct radeon_atom_ss));
1435 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1436 &frev, &crev, &data_offset)) {
1437
1438 ss_info =
1439 (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
1440
1441 switch (frev) {
1442 case 1:
1443 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1444 sizeof(ATOM_ASIC_SS_ASSIGNMENT);
1445
1446 for (i = 0; i < num_indices; i++) {
1447 if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) &&
Cédric Cano45894332011-02-11 19:45:37 -05001448 (clock <= le32_to_cpu(ss_info->info.asSpreadSpectrum[i].ulTargetClockRange))) {
Alex Deucherba032a52010-10-04 17:13:01 -04001449 ss->percentage =
1450 le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1451 ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1452 ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz);
1453 return true;
1454 }
1455 }
1456 break;
1457 case 2:
1458 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1459 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
1460 for (i = 0; i < num_indices; i++) {
1461 if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) &&
Cédric Cano45894332011-02-11 19:45:37 -05001462 (clock <= le32_to_cpu(ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange))) {
Alex Deucherba032a52010-10-04 17:13:01 -04001463 ss->percentage =
1464 le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1465 ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1466 ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz);
1467 return true;
1468 }
1469 }
1470 break;
1471 case 3:
1472 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1473 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
1474 for (i = 0; i < num_indices; i++) {
1475 if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) &&
Cédric Cano45894332011-02-11 19:45:37 -05001476 (clock <= le32_to_cpu(ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange))) {
Alex Deucherba032a52010-10-04 17:13:01 -04001477 ss->percentage =
1478 le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage);
1479 ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode;
1480 ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz);
Alex Deucher4339c442010-11-22 17:56:25 -05001481 if (rdev->flags & RADEON_IS_IGP)
1482 radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
Alex Deucherba032a52010-10-04 17:13:01 -04001483 return true;
1484 }
1485 }
1486 break;
1487 default:
1488 DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
1489 break;
1490 }
1491
1492 }
1493 return false;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001494}
1495
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001496union lvds_info {
1497 struct _ATOM_LVDS_INFO info;
1498 struct _ATOM_LVDS_INFO_V12 info_12;
1499};
1500
1501struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1502 radeon_encoder
1503 *encoder)
1504{
1505 struct drm_device *dev = encoder->base.dev;
1506 struct radeon_device *rdev = dev->dev_private;
1507 struct radeon_mode_info *mode_info = &rdev->mode_info;
1508 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
Alex Deucher7dde8a192009-11-30 01:40:24 -05001509 uint16_t data_offset, misc;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001510 union lvds_info *lvds_info;
1511 uint8_t frev, crev;
1512 struct radeon_encoder_atom_dig *lvds = NULL;
Alex Deucher5137ee92010-08-12 18:58:47 -04001513 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001514
Alex Deuchera084e6e2010-03-18 01:04:01 -04001515 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1516 &frev, &crev, &data_offset)) {
1517 lvds_info =
1518 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001519 lvds =
1520 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1521
1522 if (!lvds)
1523 return NULL;
1524
Alex Deucherde2103e2009-10-09 15:14:30 -04001525 lvds->native_mode.clock =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001526 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
Alex Deucherde2103e2009-10-09 15:14:30 -04001527 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001528 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001529 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001530 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001531 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1532 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1533 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1534 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1535 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1536 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1537 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1538 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1539 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
Alex Deucher1ff26a32010-05-18 00:23:15 -04001540 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
Alex Deucherde2103e2009-10-09 15:14:30 -04001541 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1542 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001543 lvds->panel_pwr_delay =
1544 le16_to_cpu(lvds_info->info.usOffDelayInMs);
Alex Deucherba032a52010-10-04 17:13:01 -04001545 lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
Alex Deucher7dde8a192009-11-30 01:40:24 -05001546
1547 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1548 if (misc & ATOM_VSYNC_POLARITY)
1549 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1550 if (misc & ATOM_HSYNC_POLARITY)
1551 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1552 if (misc & ATOM_COMPOSITESYNC)
1553 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1554 if (misc & ATOM_INTERLACE)
1555 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1556 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1557 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1558
Cédric Cano45894332011-02-11 19:45:37 -05001559 lvds->native_mode.width_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageHSize);
1560 lvds->native_mode.height_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageVSize);
Alex Deucher7a868e12010-12-08 22:13:05 -05001561
Alex Deucherde2103e2009-10-09 15:14:30 -04001562 /* set crtc values */
1563 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001564
Alex Deucherba032a52010-10-04 17:13:01 -04001565 lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001566
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001567 encoder->native_mode = lvds->native_mode;
Alex Deucher5137ee92010-08-12 18:58:47 -04001568
1569 if (encoder_enum == 2)
1570 lvds->linkb = true;
1571 else
1572 lvds->linkb = false;
1573
Alex Deucherc324acd2010-12-08 22:13:06 -05001574 /* parse the lcd record table */
Cédric Cano45894332011-02-11 19:45:37 -05001575 if (le16_to_cpu(lvds_info->info.usModePatchTableOffset)) {
Alex Deucherc324acd2010-12-08 22:13:06 -05001576 ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
1577 ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
1578 bool bad_record = false;
Alex Deucher05fa7ea2011-05-11 14:02:07 -04001579 u8 *record;
1580
1581 if ((frev == 1) && (crev < 2))
1582 /* absolute */
1583 record = (u8 *)(mode_info->atom_context->bios +
1584 le16_to_cpu(lvds_info->info.usModePatchTableOffset));
1585 else
1586 /* relative */
1587 record = (u8 *)(mode_info->atom_context->bios +
1588 data_offset +
1589 le16_to_cpu(lvds_info->info.usModePatchTableOffset));
Alex Deucherc324acd2010-12-08 22:13:06 -05001590 while (*record != ATOM_RECORD_END_TYPE) {
1591 switch (*record) {
1592 case LCD_MODE_PATCH_RECORD_MODE_TYPE:
1593 record += sizeof(ATOM_PATCH_RECORD_MODE);
1594 break;
1595 case LCD_RTS_RECORD_TYPE:
1596 record += sizeof(ATOM_LCD_RTS_RECORD);
1597 break;
1598 case LCD_CAP_RECORD_TYPE:
1599 record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
1600 break;
1601 case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
1602 fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
1603 if (fake_edid_record->ucFakeEDIDLength) {
1604 struct edid *edid;
1605 int edid_size =
1606 max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
1607 edid = kmalloc(edid_size, GFP_KERNEL);
1608 if (edid) {
1609 memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
1610 fake_edid_record->ucFakeEDIDLength);
1611
Dave Airlieeaa4f5e2011-05-01 20:16:30 +10001612 if (drm_edid_is_valid(edid)) {
Alex Deucherc324acd2010-12-08 22:13:06 -05001613 rdev->mode_info.bios_hardcoded_edid = edid;
Dave Airlieeaa4f5e2011-05-01 20:16:30 +10001614 rdev->mode_info.bios_hardcoded_edid_size = edid_size;
1615 } else
Alex Deucherc324acd2010-12-08 22:13:06 -05001616 kfree(edid);
1617 }
1618 }
1619 record += sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
1620 break;
1621 case LCD_PANEL_RESOLUTION_RECORD_TYPE:
1622 panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
1623 lvds->native_mode.width_mm = panel_res_record->usHSize;
1624 lvds->native_mode.height_mm = panel_res_record->usVSize;
1625 record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
1626 break;
1627 default:
1628 DRM_ERROR("Bad LCD record %d\n", *record);
1629 bad_record = true;
1630 break;
1631 }
1632 if (bad_record)
1633 break;
1634 }
1635 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001636 }
1637 return lvds;
1638}
1639
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001640struct radeon_encoder_primary_dac *
1641radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1642{
1643 struct drm_device *dev = encoder->base.dev;
1644 struct radeon_device *rdev = dev->dev_private;
1645 struct radeon_mode_info *mode_info = &rdev->mode_info;
1646 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1647 uint16_t data_offset;
1648 struct _COMPASSIONATE_DATA *dac_info;
1649 uint8_t frev, crev;
1650 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001651 struct radeon_encoder_primary_dac *p_dac = NULL;
1652
Alex Deuchera084e6e2010-03-18 01:04:01 -04001653 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1654 &frev, &crev, &data_offset)) {
1655 dac_info = (struct _COMPASSIONATE_DATA *)
1656 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001657
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001658 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1659
1660 if (!p_dac)
1661 return NULL;
1662
1663 bg = dac_info->ucDAC1_BG_Adjustment;
1664 dac = dac_info->ucDAC1_DAC_Adjustment;
1665 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1666
1667 }
1668 return p_dac;
1669}
1670
Dave Airlie4ce001a2009-08-13 16:32:14 +10001671bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001672 struct drm_display_mode *mode)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001673{
1674 struct radeon_mode_info *mode_info = &rdev->mode_info;
1675 ATOM_ANALOG_TV_INFO *tv_info;
1676 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1677 ATOM_DTD_FORMAT *dtd_timings;
1678 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1679 u8 frev, crev;
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001680 u16 data_offset, misc;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001681
Alex Deuchera084e6e2010-03-18 01:04:01 -04001682 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1683 &frev, &crev, &data_offset))
1684 return false;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001685
1686 switch (crev) {
1687 case 1:
1688 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001689 if (index >= MAX_SUPPORTED_TV_TIMING)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001690 return false;
1691
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001692 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1693 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1694 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1695 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1696 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001697
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001698 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1699 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1700 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1701 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1702 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001703
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001704 mode->flags = 0;
1705 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1706 if (misc & ATOM_VSYNC_POLARITY)
1707 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1708 if (misc & ATOM_HSYNC_POLARITY)
1709 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1710 if (misc & ATOM_COMPOSITESYNC)
1711 mode->flags |= DRM_MODE_FLAG_CSYNC;
1712 if (misc & ATOM_INTERLACE)
1713 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1714 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1715 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001716
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001717 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001718
1719 if (index == 1) {
1720 /* PAL timings appear to have wrong values for totals */
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001721 mode->crtc_htotal -= 1;
1722 mode->crtc_vtotal -= 1;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001723 }
1724 break;
1725 case 2:
1726 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001727 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001728 return false;
1729
1730 dtd_timings = &tv_info_v1_2->aModeTimings[index];
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001731 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1732 le16_to_cpu(dtd_timings->usHBlanking_Time);
1733 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1734 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1735 le16_to_cpu(dtd_timings->usHSyncOffset);
1736 mode->crtc_hsync_end = mode->crtc_hsync_start +
1737 le16_to_cpu(dtd_timings->usHSyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001738
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001739 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1740 le16_to_cpu(dtd_timings->usVBlanking_Time);
1741 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1742 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1743 le16_to_cpu(dtd_timings->usVSyncOffset);
1744 mode->crtc_vsync_end = mode->crtc_vsync_start +
1745 le16_to_cpu(dtd_timings->usVSyncWidth);
1746
1747 mode->flags = 0;
1748 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1749 if (misc & ATOM_VSYNC_POLARITY)
1750 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1751 if (misc & ATOM_HSYNC_POLARITY)
1752 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1753 if (misc & ATOM_COMPOSITESYNC)
1754 mode->flags |= DRM_MODE_FLAG_CSYNC;
1755 if (misc & ATOM_INTERLACE)
1756 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1757 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1758 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1759
1760 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001761 break;
1762 }
1763 return true;
1764}
1765
Alex Deucherd79766f2009-12-17 19:00:29 -05001766enum radeon_tv_std
1767radeon_atombios_get_tv_info(struct radeon_device *rdev)
1768{
1769 struct radeon_mode_info *mode_info = &rdev->mode_info;
1770 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1771 uint16_t data_offset;
1772 uint8_t frev, crev;
1773 struct _ATOM_ANALOG_TV_INFO *tv_info;
1774 enum radeon_tv_std tv_std = TV_STD_NTSC;
1775
Alex Deuchera084e6e2010-03-18 01:04:01 -04001776 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1777 &frev, &crev, &data_offset)) {
Alex Deucherd79766f2009-12-17 19:00:29 -05001778
Alex Deuchera084e6e2010-03-18 01:04:01 -04001779 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1780 (mode_info->atom_context->bios + data_offset);
Alex Deucherd79766f2009-12-17 19:00:29 -05001781
Alex Deuchera084e6e2010-03-18 01:04:01 -04001782 switch (tv_info->ucTV_BootUpDefaultStandard) {
1783 case ATOM_TV_NTSC:
1784 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001785 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001786 break;
1787 case ATOM_TV_NTSCJ:
1788 tv_std = TV_STD_NTSC_J;
Alex Deucher40f76d82010-10-07 22:38:42 -04001789 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001790 break;
1791 case ATOM_TV_PAL:
1792 tv_std = TV_STD_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -04001793 DRM_DEBUG_KMS("Default TV standard: PAL\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001794 break;
1795 case ATOM_TV_PALM:
1796 tv_std = TV_STD_PAL_M;
Alex Deucher40f76d82010-10-07 22:38:42 -04001797 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001798 break;
1799 case ATOM_TV_PALN:
1800 tv_std = TV_STD_PAL_N;
Alex Deucher40f76d82010-10-07 22:38:42 -04001801 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001802 break;
1803 case ATOM_TV_PALCN:
1804 tv_std = TV_STD_PAL_CN;
Alex Deucher40f76d82010-10-07 22:38:42 -04001805 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001806 break;
1807 case ATOM_TV_PAL60:
1808 tv_std = TV_STD_PAL_60;
Alex Deucher40f76d82010-10-07 22:38:42 -04001809 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001810 break;
1811 case ATOM_TV_SECAM:
1812 tv_std = TV_STD_SECAM;
Alex Deucher40f76d82010-10-07 22:38:42 -04001813 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001814 break;
1815 default:
1816 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001817 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001818 break;
1819 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001820 }
1821 return tv_std;
1822}
1823
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001824struct radeon_encoder_tv_dac *
1825radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1826{
1827 struct drm_device *dev = encoder->base.dev;
1828 struct radeon_device *rdev = dev->dev_private;
1829 struct radeon_mode_info *mode_info = &rdev->mode_info;
1830 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1831 uint16_t data_offset;
1832 struct _COMPASSIONATE_DATA *dac_info;
1833 uint8_t frev, crev;
1834 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001835 struct radeon_encoder_tv_dac *tv_dac = NULL;
1836
Alex Deuchera084e6e2010-03-18 01:04:01 -04001837 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1838 &frev, &crev, &data_offset)) {
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001839
Alex Deuchera084e6e2010-03-18 01:04:01 -04001840 dac_info = (struct _COMPASSIONATE_DATA *)
1841 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001842
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001843 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1844
1845 if (!tv_dac)
1846 return NULL;
1847
1848 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1849 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1850 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1851
1852 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1853 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1854 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1855
1856 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1857 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1858 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1859
Alex Deucherd79766f2009-12-17 19:00:29 -05001860 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001861 }
1862 return tv_dac;
1863}
1864
Alex Deucher29fb52c2010-03-11 10:01:17 -05001865static const char *thermal_controller_names[] = {
1866 "NONE",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001867 "lm63",
1868 "adm1032",
1869 "adm1030",
1870 "max6649",
1871 "lm64",
1872 "f75375",
1873 "asc7xxx",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001874};
1875
1876static const char *pp_lib_thermal_controller_names[] = {
1877 "NONE",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001878 "lm63",
1879 "adm1032",
1880 "adm1030",
1881 "max6649",
1882 "lm64",
1883 "f75375",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001884 "RV6xx",
1885 "RV770",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001886 "adt7473",
Alex Deucher560154e2010-11-22 17:56:34 -05001887 "NONE",
Alex Deucher49f65982010-03-24 16:39:45 -04001888 "External GPIO",
1889 "Evergreen",
Alex Deucherb0e66412010-11-22 17:56:35 -05001890 "emc2103",
1891 "Sumo",
Alex Deucher4fddba12011-01-06 21:19:22 -05001892 "Northern Islands",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001893};
1894
Alex Deucher56278a82009-12-28 13:58:44 -05001895union power_info {
1896 struct _ATOM_POWERPLAY_INFO info;
1897 struct _ATOM_POWERPLAY_INFO_V2 info_2;
1898 struct _ATOM_POWERPLAY_INFO_V3 info_3;
Alex Deucher560154e2010-11-22 17:56:34 -05001899 struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
Alex Deucherb0e66412010-11-22 17:56:35 -05001900 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
1901 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
Alex Deucher56278a82009-12-28 13:58:44 -05001902};
1903
Alex Deucher560154e2010-11-22 17:56:34 -05001904union pplib_clock_info {
1905 struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
1906 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
1907 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
Alex Deucherb0e66412010-11-22 17:56:35 -05001908 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
Alex Deucher560154e2010-11-22 17:56:34 -05001909};
1910
1911union pplib_power_state {
1912 struct _ATOM_PPLIB_STATE v1;
1913 struct _ATOM_PPLIB_STATE_V2 v2;
1914};
1915
1916static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
1917 int state_index,
1918 u32 misc, u32 misc2)
1919{
1920 rdev->pm.power_state[state_index].misc = misc;
1921 rdev->pm.power_state[state_index].misc2 = misc2;
1922 /* order matters! */
1923 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1924 rdev->pm.power_state[state_index].type =
1925 POWER_STATE_TYPE_POWERSAVE;
1926 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1927 rdev->pm.power_state[state_index].type =
1928 POWER_STATE_TYPE_BATTERY;
1929 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1930 rdev->pm.power_state[state_index].type =
1931 POWER_STATE_TYPE_BATTERY;
1932 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1933 rdev->pm.power_state[state_index].type =
1934 POWER_STATE_TYPE_BALANCED;
1935 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
1936 rdev->pm.power_state[state_index].type =
1937 POWER_STATE_TYPE_PERFORMANCE;
1938 rdev->pm.power_state[state_index].flags &=
1939 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1940 }
1941 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1942 rdev->pm.power_state[state_index].type =
1943 POWER_STATE_TYPE_BALANCED;
1944 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
1945 rdev->pm.power_state[state_index].type =
1946 POWER_STATE_TYPE_DEFAULT;
1947 rdev->pm.default_power_state_index = state_index;
1948 rdev->pm.power_state[state_index].default_clock_mode =
1949 &rdev->pm.power_state[state_index].clock_info[0];
1950 } else if (state_index == 0) {
1951 rdev->pm.power_state[state_index].clock_info[0].flags |=
1952 RADEON_PM_MODE_NO_DISPLAY;
1953 }
1954}
1955
1956static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
1957{
1958 struct radeon_mode_info *mode_info = &rdev->mode_info;
1959 u32 misc, misc2 = 0;
1960 int num_modes = 0, i;
1961 int state_index = 0;
1962 struct radeon_i2c_bus_rec i2c_bus;
1963 union power_info *power_info;
1964 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
1965 u16 data_offset;
1966 u8 frev, crev;
1967
1968 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
1969 &frev, &crev, &data_offset))
1970 return state_index;
1971 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
1972
1973 /* add the i2c bus for thermal/fan chip */
1974 if (power_info->info.ucOverdriveThermalController > 0) {
1975 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
1976 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1977 power_info->info.ucOverdriveControllerAddress >> 1);
1978 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
1979 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1980 if (rdev->pm.i2c_bus) {
1981 struct i2c_board_info info = { };
1982 const char *name = thermal_controller_names[power_info->info.
1983 ucOverdriveThermalController];
1984 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
1985 strlcpy(info.type, name, sizeof(info.type));
1986 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
1987 }
1988 }
1989 num_modes = power_info->info.ucNumOfPowerModeEntries;
1990 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
1991 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
Alex Deucher0975b162011-02-02 18:42:03 -05001992 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
1993 if (!rdev->pm.power_state)
1994 return state_index;
Alex Deucher560154e2010-11-22 17:56:34 -05001995 /* last mode is usually default, array is low to high */
1996 for (i = 0; i < num_modes; i++) {
Alex Deucher6991b8f2011-11-14 17:52:51 -05001997 rdev->pm.power_state[state_index].clock_info =
1998 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
1999 if (!rdev->pm.power_state[state_index].clock_info)
2000 return state_index;
2001 rdev->pm.power_state[state_index].num_clock_modes = 1;
Alex Deucher560154e2010-11-22 17:56:34 -05002002 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2003 switch (frev) {
2004 case 1:
Alex Deucher560154e2010-11-22 17:56:34 -05002005 rdev->pm.power_state[state_index].clock_info[0].mclk =
2006 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
2007 rdev->pm.power_state[state_index].clock_info[0].sclk =
2008 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
2009 /* skip invalid modes */
2010 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2011 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2012 continue;
2013 rdev->pm.power_state[state_index].pcie_lanes =
2014 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
2015 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
2016 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2017 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2018 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2019 VOLTAGE_GPIO;
2020 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2021 radeon_lookup_gpio(rdev,
2022 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
2023 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2024 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2025 true;
2026 else
2027 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2028 false;
2029 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2030 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2031 VOLTAGE_VDDC;
2032 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2033 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
2034 }
2035 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2036 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
2037 state_index++;
2038 break;
2039 case 2:
Alex Deucher560154e2010-11-22 17:56:34 -05002040 rdev->pm.power_state[state_index].clock_info[0].mclk =
2041 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
2042 rdev->pm.power_state[state_index].clock_info[0].sclk =
2043 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
2044 /* skip invalid modes */
2045 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2046 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2047 continue;
2048 rdev->pm.power_state[state_index].pcie_lanes =
2049 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
2050 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
2051 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
2052 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2053 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2054 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2055 VOLTAGE_GPIO;
2056 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2057 radeon_lookup_gpio(rdev,
2058 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
2059 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2060 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2061 true;
2062 else
2063 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2064 false;
2065 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2066 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2067 VOLTAGE_VDDC;
2068 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2069 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
2070 }
2071 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2072 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2073 state_index++;
2074 break;
2075 case 3:
Alex Deucher560154e2010-11-22 17:56:34 -05002076 rdev->pm.power_state[state_index].clock_info[0].mclk =
2077 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
2078 rdev->pm.power_state[state_index].clock_info[0].sclk =
2079 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
2080 /* skip invalid modes */
2081 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2082 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2083 continue;
2084 rdev->pm.power_state[state_index].pcie_lanes =
2085 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
2086 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
2087 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
2088 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2089 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2090 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2091 VOLTAGE_GPIO;
2092 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2093 radeon_lookup_gpio(rdev,
2094 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
2095 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2096 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2097 true;
2098 else
2099 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2100 false;
2101 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2102 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2103 VOLTAGE_VDDC;
2104 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2105 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
2106 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
2107 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
2108 true;
2109 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
2110 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
2111 }
2112 }
2113 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2114 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2115 state_index++;
2116 break;
2117 }
2118 }
2119 /* last mode is usually default */
2120 if (rdev->pm.default_power_state_index == -1) {
2121 rdev->pm.power_state[state_index - 1].type =
2122 POWER_STATE_TYPE_DEFAULT;
2123 rdev->pm.default_power_state_index = state_index - 1;
2124 rdev->pm.power_state[state_index - 1].default_clock_mode =
2125 &rdev->pm.power_state[state_index - 1].clock_info[0];
2126 rdev->pm.power_state[state_index].flags &=
2127 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2128 rdev->pm.power_state[state_index].misc = 0;
2129 rdev->pm.power_state[state_index].misc2 = 0;
2130 }
2131 return state_index;
2132}
2133
2134static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
2135 ATOM_PPLIB_THERMALCONTROLLER *controller)
2136{
2137 struct radeon_i2c_bus_rec i2c_bus;
2138
2139 /* add the i2c bus for thermal/fan chip */
2140 if (controller->ucType > 0) {
2141 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
2142 DRM_INFO("Internal thermal controller %s fan control\n",
2143 (controller->ucFanParameters &
2144 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2145 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
2146 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
2147 DRM_INFO("Internal thermal controller %s fan control\n",
2148 (controller->ucFanParameters &
2149 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2150 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
2151 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
2152 DRM_INFO("Internal thermal controller %s fan control\n",
2153 (controller->ucFanParameters &
2154 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2155 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
Alex Deucherb0e66412010-11-22 17:56:35 -05002156 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
2157 DRM_INFO("Internal thermal controller %s fan control\n",
2158 (controller->ucFanParameters &
2159 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2160 rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
Alex Deucher4fddba12011-01-06 21:19:22 -05002161 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
2162 DRM_INFO("Internal thermal controller %s fan control\n",
2163 (controller->ucFanParameters &
2164 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2165 rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
Alex Deucher560154e2010-11-22 17:56:34 -05002166 } else if ((controller->ucType ==
2167 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
2168 (controller->ucType ==
Alex Deucherb0e66412010-11-22 17:56:35 -05002169 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
2170 (controller->ucType ==
2171 ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002172 DRM_INFO("Special thermal controller config\n");
2173 } else {
2174 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2175 pp_lib_thermal_controller_names[controller->ucType],
2176 controller->ucI2cAddress >> 1,
2177 (controller->ucFanParameters &
2178 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2179 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
2180 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2181 if (rdev->pm.i2c_bus) {
2182 struct i2c_board_info info = { };
2183 const char *name = pp_lib_thermal_controller_names[controller->ucType];
2184 info.addr = controller->ucI2cAddress >> 1;
2185 strlcpy(info.type, name, sizeof(info.type));
2186 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2187 }
2188 }
2189 }
2190}
2191
Alex Deucher2feea492011-04-12 14:49:24 -04002192static void radeon_atombios_get_default_voltages(struct radeon_device *rdev,
2193 u16 *vddc, u16 *vddci)
Alex Deucher560154e2010-11-22 17:56:34 -05002194{
2195 struct radeon_mode_info *mode_info = &rdev->mode_info;
2196 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
2197 u8 frev, crev;
2198 u16 data_offset;
2199 union firmware_info *firmware_info;
Alex Deucher2feea492011-04-12 14:49:24 -04002200
2201 *vddc = 0;
2202 *vddci = 0;
Alex Deucher560154e2010-11-22 17:56:34 -05002203
2204 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2205 &frev, &crev, &data_offset)) {
2206 firmware_info =
2207 (union firmware_info *)(mode_info->atom_context->bios +
2208 data_offset);
Alex Deucher2feea492011-04-12 14:49:24 -04002209 *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
2210 if ((frev == 2) && (crev >= 2))
2211 *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
Alex Deucher560154e2010-11-22 17:56:34 -05002212 }
Alex Deucher560154e2010-11-22 17:56:34 -05002213}
2214
2215static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
2216 int state_index, int mode_index,
2217 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
2218{
2219 int j;
2220 u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
2221 u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
Alex Deucher2feea492011-04-12 14:49:24 -04002222 u16 vddc, vddci;
2223
2224 radeon_atombios_get_default_voltages(rdev, &vddc, &vddci);
Alex Deucher560154e2010-11-22 17:56:34 -05002225
2226 rdev->pm.power_state[state_index].misc = misc;
2227 rdev->pm.power_state[state_index].misc2 = misc2;
2228 rdev->pm.power_state[state_index].pcie_lanes =
2229 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2230 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2231 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2232 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2233 rdev->pm.power_state[state_index].type =
2234 POWER_STATE_TYPE_BATTERY;
2235 break;
2236 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2237 rdev->pm.power_state[state_index].type =
2238 POWER_STATE_TYPE_BALANCED;
2239 break;
2240 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2241 rdev->pm.power_state[state_index].type =
2242 POWER_STATE_TYPE_PERFORMANCE;
2243 break;
2244 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2245 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2246 rdev->pm.power_state[state_index].type =
2247 POWER_STATE_TYPE_PERFORMANCE;
2248 break;
2249 }
2250 rdev->pm.power_state[state_index].flags = 0;
2251 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2252 rdev->pm.power_state[state_index].flags |=
2253 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2254 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
2255 rdev->pm.power_state[state_index].type =
2256 POWER_STATE_TYPE_DEFAULT;
2257 rdev->pm.default_power_state_index = state_index;
2258 rdev->pm.power_state[state_index].default_clock_mode =
2259 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002260 if (ASIC_IS_DCE5(rdev) && !(rdev->flags & RADEON_IS_IGP)) {
Alex Deucher9ace9f72011-01-06 21:19:26 -05002261 /* NI chips post without MC ucode, so default clocks are strobe mode only */
2262 rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
2263 rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
2264 rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
Alex Deucher2feea492011-04-12 14:49:24 -04002265 rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
Alex Deucher9ace9f72011-01-06 21:19:26 -05002266 } else {
2267 /* patch the table values with the default slck/mclk from firmware info */
2268 for (j = 0; j < mode_index; j++) {
2269 rdev->pm.power_state[state_index].clock_info[j].mclk =
2270 rdev->clock.default_mclk;
2271 rdev->pm.power_state[state_index].clock_info[j].sclk =
2272 rdev->clock.default_sclk;
2273 if (vddc)
2274 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2275 vddc;
2276 }
Alex Deucher560154e2010-11-22 17:56:34 -05002277 }
2278 }
2279}
2280
2281static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
2282 int state_index, int mode_index,
2283 union pplib_clock_info *clock_info)
2284{
2285 u32 sclk, mclk;
2286
2287 if (rdev->flags & RADEON_IS_IGP) {
Alex Deucherb0e66412010-11-22 17:56:35 -05002288 if (rdev->family >= CHIP_PALM) {
2289 sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
2290 sclk |= clock_info->sumo.ucEngineClockHigh << 16;
2291 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2292 } else {
2293 sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
2294 sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
2295 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2296 }
Alex Deucher560154e2010-11-22 17:56:34 -05002297 } else if (ASIC_IS_DCE4(rdev)) {
2298 sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
2299 sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
2300 mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
2301 mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
2302 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2303 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2304 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2305 VOLTAGE_SW;
2306 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
Cédric Cano45894332011-02-11 19:45:37 -05002307 le16_to_cpu(clock_info->evergreen.usVDDC);
Alex Deucher2feea492011-04-12 14:49:24 -04002308 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
2309 le16_to_cpu(clock_info->evergreen.usVDDCI);
Alex Deucher560154e2010-11-22 17:56:34 -05002310 } else {
2311 sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
2312 sclk |= clock_info->r600.ucEngineClockHigh << 16;
2313 mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
2314 mclk |= clock_info->r600.ucMemoryClockHigh << 16;
2315 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2316 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2317 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2318 VOLTAGE_SW;
2319 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
Cédric Cano45894332011-02-11 19:45:37 -05002320 le16_to_cpu(clock_info->r600.usVDDC);
Alex Deucher560154e2010-11-22 17:56:34 -05002321 }
2322
Alex Deucheree4017f2011-06-23 12:19:32 -04002323 /* patch up vddc if necessary */
2324 if (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage == 0xff01) {
2325 u16 vddc;
2326
2327 if (radeon_atom_get_max_vddc(rdev, &vddc) == 0)
2328 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
2329 }
2330
Alex Deucher560154e2010-11-22 17:56:34 -05002331 if (rdev->flags & RADEON_IS_IGP) {
2332 /* skip invalid modes */
2333 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2334 return false;
2335 } else {
2336 /* skip invalid modes */
2337 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2338 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2339 return false;
2340 }
2341 return true;
2342}
2343
2344static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
2345{
2346 struct radeon_mode_info *mode_info = &rdev->mode_info;
2347 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2348 union pplib_power_state *power_state;
2349 int i, j;
2350 int state_index = 0, mode_index = 0;
2351 union pplib_clock_info *clock_info;
2352 bool valid;
2353 union power_info *power_info;
2354 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2355 u16 data_offset;
2356 u8 frev, crev;
2357
2358 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2359 &frev, &crev, &data_offset))
2360 return state_index;
2361 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2362
2363 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
Alex Deucher0975b162011-02-02 18:42:03 -05002364 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2365 power_info->pplib.ucNumStates, GFP_KERNEL);
2366 if (!rdev->pm.power_state)
2367 return state_index;
Alex Deucher560154e2010-11-22 17:56:34 -05002368 /* first mode is usually default, followed by low to high */
2369 for (i = 0; i < power_info->pplib.ucNumStates; i++) {
2370 mode_index = 0;
2371 power_state = (union pplib_power_state *)
2372 (mode_info->atom_context->bios + data_offset +
2373 le16_to_cpu(power_info->pplib.usStateArrayOffset) +
2374 i * power_info->pplib.ucStateEntrySize);
2375 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2376 (mode_info->atom_context->bios + data_offset +
2377 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
2378 (power_state->v1.ucNonClockStateIndex *
2379 power_info->pplib.ucNonClockSize));
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002380 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2381 ((power_info->pplib.ucStateEntrySize - 1) ?
2382 (power_info->pplib.ucStateEntrySize - 1) : 1),
2383 GFP_KERNEL);
2384 if (!rdev->pm.power_state[i].clock_info)
2385 return state_index;
2386 if (power_info->pplib.ucStateEntrySize - 1) {
2387 for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
2388 clock_info = (union pplib_clock_info *)
2389 (mode_info->atom_context->bios + data_offset +
2390 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
2391 (power_state->v1.ucClockStateIndices[j] *
2392 power_info->pplib.ucClockInfoSize));
2393 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2394 state_index, mode_index,
2395 clock_info);
2396 if (valid)
2397 mode_index++;
2398 }
2399 } else {
2400 rdev->pm.power_state[state_index].clock_info[0].mclk =
2401 rdev->clock.default_mclk;
2402 rdev->pm.power_state[state_index].clock_info[0].sclk =
2403 rdev->clock.default_sclk;
2404 mode_index++;
Alex Deucher560154e2010-11-22 17:56:34 -05002405 }
2406 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2407 if (mode_index) {
2408 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2409 non_clock_info);
2410 state_index++;
2411 }
2412 }
2413 /* if multiple clock modes, mark the lowest as no display */
2414 for (i = 0; i < state_index; i++) {
2415 if (rdev->pm.power_state[i].num_clock_modes > 1)
2416 rdev->pm.power_state[i].clock_info[0].flags |=
2417 RADEON_PM_MODE_NO_DISPLAY;
2418 }
2419 /* first mode is usually default */
2420 if (rdev->pm.default_power_state_index == -1) {
2421 rdev->pm.power_state[0].type =
2422 POWER_STATE_TYPE_DEFAULT;
2423 rdev->pm.default_power_state_index = 0;
2424 rdev->pm.power_state[0].default_clock_mode =
2425 &rdev->pm.power_state[0].clock_info[0];
2426 }
2427 return state_index;
2428}
2429
Alex Deucherb0e66412010-11-22 17:56:35 -05002430static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
2431{
2432 struct radeon_mode_info *mode_info = &rdev->mode_info;
2433 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2434 union pplib_power_state *power_state;
2435 int i, j, non_clock_array_index, clock_array_index;
2436 int state_index = 0, mode_index = 0;
2437 union pplib_clock_info *clock_info;
Alex Deucherf7346882012-03-20 17:17:58 -04002438 struct _StateArray *state_array;
2439 struct _ClockInfoArray *clock_info_array;
2440 struct _NonClockInfoArray *non_clock_info_array;
Alex Deucherb0e66412010-11-22 17:56:35 -05002441 bool valid;
2442 union power_info *power_info;
2443 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2444 u16 data_offset;
2445 u8 frev, crev;
2446
2447 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2448 &frev, &crev, &data_offset))
2449 return state_index;
2450 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2451
2452 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
Alex Deucherf7346882012-03-20 17:17:58 -04002453 state_array = (struct _StateArray *)
Alex Deucherb0e66412010-11-22 17:56:35 -05002454 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002455 le16_to_cpu(power_info->pplib.usStateArrayOffset));
Alex Deucherf7346882012-03-20 17:17:58 -04002456 clock_info_array = (struct _ClockInfoArray *)
Alex Deucherb0e66412010-11-22 17:56:35 -05002457 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002458 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
Alex Deucherf7346882012-03-20 17:17:58 -04002459 non_clock_info_array = (struct _NonClockInfoArray *)
Alex Deucherb0e66412010-11-22 17:56:35 -05002460 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002461 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
Alex Deucher0975b162011-02-02 18:42:03 -05002462 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2463 state_array->ucNumEntries, GFP_KERNEL);
2464 if (!rdev->pm.power_state)
2465 return state_index;
Alex Deucherb0e66412010-11-22 17:56:35 -05002466 for (i = 0; i < state_array->ucNumEntries; i++) {
2467 mode_index = 0;
2468 power_state = (union pplib_power_state *)&state_array->states[i];
2469 /* XXX this might be an inagua bug... */
2470 non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
2471 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2472 &non_clock_info_array->nonClockInfo[non_clock_array_index];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002473 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2474 (power_state->v2.ucNumDPMLevels ?
2475 power_state->v2.ucNumDPMLevels : 1),
2476 GFP_KERNEL);
2477 if (!rdev->pm.power_state[i].clock_info)
2478 return state_index;
2479 if (power_state->v2.ucNumDPMLevels) {
2480 for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2481 clock_array_index = power_state->v2.clockInfoIndex[j];
2482 /* XXX this might be an inagua bug... */
2483 if (clock_array_index >= clock_info_array->ucNumEntries)
2484 continue;
2485 clock_info = (union pplib_clock_info *)
Alex Deucherf7346882012-03-20 17:17:58 -04002486 &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002487 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2488 state_index, mode_index,
2489 clock_info);
2490 if (valid)
2491 mode_index++;
2492 }
2493 } else {
2494 rdev->pm.power_state[state_index].clock_info[0].mclk =
2495 rdev->clock.default_mclk;
2496 rdev->pm.power_state[state_index].clock_info[0].sclk =
2497 rdev->clock.default_sclk;
2498 mode_index++;
Alex Deucherb0e66412010-11-22 17:56:35 -05002499 }
2500 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2501 if (mode_index) {
2502 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2503 non_clock_info);
2504 state_index++;
2505 }
2506 }
2507 /* if multiple clock modes, mark the lowest as no display */
2508 for (i = 0; i < state_index; i++) {
2509 if (rdev->pm.power_state[i].num_clock_modes > 1)
2510 rdev->pm.power_state[i].clock_info[0].flags |=
2511 RADEON_PM_MODE_NO_DISPLAY;
2512 }
2513 /* first mode is usually default */
2514 if (rdev->pm.default_power_state_index == -1) {
2515 rdev->pm.power_state[0].type =
2516 POWER_STATE_TYPE_DEFAULT;
2517 rdev->pm.default_power_state_index = 0;
2518 rdev->pm.power_state[0].default_clock_mode =
2519 &rdev->pm.power_state[0].clock_info[0];
2520 }
2521 return state_index;
2522}
2523
Alex Deucher56278a82009-12-28 13:58:44 -05002524void radeon_atombios_get_power_modes(struct radeon_device *rdev)
2525{
2526 struct radeon_mode_info *mode_info = &rdev->mode_info;
2527 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2528 u16 data_offset;
2529 u8 frev, crev;
Alex Deucher560154e2010-11-22 17:56:34 -05002530 int state_index = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002531
Alex Deuchera48b9b42010-04-22 14:03:55 -04002532 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05002533
Alex Deuchera084e6e2010-03-18 01:04:01 -04002534 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2535 &frev, &crev, &data_offset)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002536 switch (frev) {
2537 case 1:
2538 case 2:
2539 case 3:
2540 state_index = radeon_atombios_parse_power_table_1_3(rdev);
2541 break;
2542 case 4:
2543 case 5:
2544 state_index = radeon_atombios_parse_power_table_4_5(rdev);
2545 break;
Alex Deucherb0e66412010-11-22 17:56:35 -05002546 case 6:
2547 state_index = radeon_atombios_parse_power_table_6(rdev);
2548 break;
Alex Deucher560154e2010-11-22 17:56:34 -05002549 default:
2550 break;
Alex Deucher56278a82009-12-28 13:58:44 -05002551 }
2552 } else {
Alex Deucher0975b162011-02-02 18:42:03 -05002553 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
2554 if (rdev->pm.power_state) {
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002555 rdev->pm.power_state[0].clock_info =
2556 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2557 if (rdev->pm.power_state[0].clock_info) {
2558 /* add the default mode */
2559 rdev->pm.power_state[state_index].type =
2560 POWER_STATE_TYPE_DEFAULT;
2561 rdev->pm.power_state[state_index].num_clock_modes = 1;
2562 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2563 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2564 rdev->pm.power_state[state_index].default_clock_mode =
2565 &rdev->pm.power_state[state_index].clock_info[0];
2566 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2567 rdev->pm.power_state[state_index].pcie_lanes = 16;
2568 rdev->pm.default_power_state_index = state_index;
2569 rdev->pm.power_state[state_index].flags = 0;
2570 state_index++;
2571 }
Alex Deucher0975b162011-02-02 18:42:03 -05002572 }
Alex Deucher56278a82009-12-28 13:58:44 -05002573 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002574
Alex Deucher56278a82009-12-28 13:58:44 -05002575 rdev->pm.num_power_states = state_index;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002576
Alex Deuchera48b9b42010-04-22 14:03:55 -04002577 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2578 rdev->pm.current_clock_mode_index = 0;
Alexander Müller4376eee2011-12-30 12:55:48 -05002579 if (rdev->pm.default_power_state_index >= 0)
2580 rdev->pm.current_vddc =
2581 rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
2582 else
2583 rdev->pm.current_vddc = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002584}
2585
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002586void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2587{
2588 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2589 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2590
2591 args.ucEnable = enable;
2592
2593 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2594}
2595
Rafał Miłecki74338742009-11-03 00:53:02 +01002596uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2597{
2598 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2599 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2600
2601 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
Cédric Cano45894332011-02-11 19:45:37 -05002602 return le32_to_cpu(args.ulReturnEngineClock);
Rafał Miłecki74338742009-11-03 00:53:02 +01002603}
2604
2605uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2606{
2607 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2608 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2609
2610 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
Cédric Cano45894332011-02-11 19:45:37 -05002611 return le32_to_cpu(args.ulReturnMemoryClock);
Rafał Miłecki74338742009-11-03 00:53:02 +01002612}
2613
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002614void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2615 uint32_t eng_clock)
2616{
2617 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2618 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2619
Cédric Cano45894332011-02-11 19:45:37 -05002620 args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002621
2622 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2623}
2624
2625void radeon_atom_set_memory_clock(struct radeon_device *rdev,
2626 uint32_t mem_clock)
2627{
2628 SET_MEMORY_CLOCK_PS_ALLOCATION args;
2629 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
2630
2631 if (rdev->flags & RADEON_IS_IGP)
2632 return;
2633
Cédric Cano45894332011-02-11 19:45:37 -05002634 args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002635
2636 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2637}
2638
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002639union set_voltage {
2640 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2641 struct _SET_VOLTAGE_PARAMETERS v1;
2642 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2643};
2644
Alex Deucher8a83ec52011-04-12 14:49:23 -04002645void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002646{
2647 union set_voltage args;
2648 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
Alex Deucher8a83ec52011-04-12 14:49:23 -04002649 u8 frev, crev, volt_index = voltage_level;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002650
2651 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2652 return;
2653
Alex Deuchera377e182011-06-20 13:00:31 -04002654 /* 0xff01 is a flag rather then an actual voltage */
2655 if (voltage_level == 0xff01)
2656 return;
2657
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002658 switch (crev) {
2659 case 1:
Alex Deucher8a83ec52011-04-12 14:49:23 -04002660 args.v1.ucVoltageType = voltage_type;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002661 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
2662 args.v1.ucVoltageIndex = volt_index;
2663 break;
2664 case 2:
Alex Deucher8a83ec52011-04-12 14:49:23 -04002665 args.v2.ucVoltageType = voltage_type;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002666 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
Alex Deucher8a83ec52011-04-12 14:49:23 -04002667 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002668 break;
2669 default:
2670 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2671 return;
2672 }
2673
2674 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2675}
2676
Alex Deucheree4017f2011-06-23 12:19:32 -04002677int radeon_atom_get_max_vddc(struct radeon_device *rdev,
2678 u16 *voltage)
2679{
2680 union set_voltage args;
2681 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
2682 u8 frev, crev;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002683
Alex Deucheree4017f2011-06-23 12:19:32 -04002684 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2685 return -EINVAL;
2686
2687 switch (crev) {
2688 case 1:
2689 return -EINVAL;
2690 case 2:
2691 args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
2692 args.v2.ucVoltageMode = 0;
2693 args.v2.usVoltageLevel = 0;
2694
2695 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2696
2697 *voltage = le16_to_cpu(args.v2.usVoltageLevel);
2698 break;
2699 default:
2700 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2701 return -EINVAL;
2702 }
2703
2704 return 0;
2705}
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002706
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002707void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
2708{
2709 struct radeon_device *rdev = dev->dev_private;
2710 uint32_t bios_2_scratch, bios_6_scratch;
2711
2712 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002713 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002714 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2715 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002716 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002717 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2718 }
2719
2720 /* let the bios control the backlight */
2721 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
2722
2723 /* tell the bios not to handle mode switching */
Alex Deucher87364762011-02-02 19:46:06 -05002724 bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002725
2726 if (rdev->family >= CHIP_R600) {
2727 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2728 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2729 } else {
2730 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2731 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2732 }
2733
2734}
2735
Yang Zhaof657c2a2009-09-15 12:21:01 +10002736void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
2737{
2738 uint32_t scratch_reg;
2739 int i;
2740
2741 if (rdev->family >= CHIP_R600)
2742 scratch_reg = R600_BIOS_0_SCRATCH;
2743 else
2744 scratch_reg = RADEON_BIOS_0_SCRATCH;
2745
2746 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2747 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
2748}
2749
2750void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
2751{
2752 uint32_t scratch_reg;
2753 int i;
2754
2755 if (rdev->family >= CHIP_R600)
2756 scratch_reg = R600_BIOS_0_SCRATCH;
2757 else
2758 scratch_reg = RADEON_BIOS_0_SCRATCH;
2759
2760 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2761 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
2762}
2763
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002764void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
2765{
2766 struct drm_device *dev = encoder->dev;
2767 struct radeon_device *rdev = dev->dev_private;
2768 uint32_t bios_6_scratch;
2769
2770 if (rdev->family >= CHIP_R600)
2771 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2772 else
2773 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2774
Alex Deucher87364762011-02-02 19:46:06 -05002775 if (lock) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002776 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
Alex Deucher87364762011-02-02 19:46:06 -05002777 bios_6_scratch &= ~ATOM_S6_ACC_MODE;
2778 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002779 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
Alex Deucher87364762011-02-02 19:46:06 -05002780 bios_6_scratch |= ATOM_S6_ACC_MODE;
2781 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002782
2783 if (rdev->family >= CHIP_R600)
2784 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2785 else
2786 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2787}
2788
2789/* at some point we may want to break this out into individual functions */
2790void
2791radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
2792 struct drm_encoder *encoder,
2793 bool connected)
2794{
2795 struct drm_device *dev = connector->dev;
2796 struct radeon_device *rdev = dev->dev_private;
2797 struct radeon_connector *radeon_connector =
2798 to_radeon_connector(connector);
2799 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2800 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
2801
2802 if (rdev->family >= CHIP_R600) {
2803 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2804 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2805 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2806 } else {
2807 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2808 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2809 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2810 }
2811
2812 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
2813 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
2814 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002815 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002816 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
2817 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
2818 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002819 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002820 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
2821 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
2822 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
2823 }
2824 }
2825 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
2826 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
2827 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002828 DRM_DEBUG_KMS("CV connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002829 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
2830 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
2831 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002832 DRM_DEBUG_KMS("CV disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002833 bios_0_scratch &= ~ATOM_S0_CV_MASK;
2834 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
2835 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
2836 }
2837 }
2838 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
2839 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
2840 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002841 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002842 bios_0_scratch |= ATOM_S0_LCD1;
2843 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
2844 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
2845 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002846 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002847 bios_0_scratch &= ~ATOM_S0_LCD1;
2848 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
2849 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
2850 }
2851 }
2852 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
2853 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
2854 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002855 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002856 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
2857 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
2858 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
2859 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002860 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002861 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
2862 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
2863 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
2864 }
2865 }
2866 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
2867 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
2868 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002869 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002870 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
2871 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
2872 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
2873 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002874 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002875 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
2876 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
2877 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
2878 }
2879 }
2880 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
2881 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
2882 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002883 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002884 bios_0_scratch |= ATOM_S0_DFP1;
2885 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
2886 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
2887 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002888 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002889 bios_0_scratch &= ~ATOM_S0_DFP1;
2890 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
2891 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
2892 }
2893 }
2894 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
2895 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
2896 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002897 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002898 bios_0_scratch |= ATOM_S0_DFP2;
2899 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
2900 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
2901 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002902 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002903 bios_0_scratch &= ~ATOM_S0_DFP2;
2904 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
2905 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
2906 }
2907 }
2908 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
2909 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
2910 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002911 DRM_DEBUG_KMS("DFP3 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002912 bios_0_scratch |= ATOM_S0_DFP3;
2913 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
2914 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
2915 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002916 DRM_DEBUG_KMS("DFP3 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002917 bios_0_scratch &= ~ATOM_S0_DFP3;
2918 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
2919 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
2920 }
2921 }
2922 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
2923 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
2924 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002925 DRM_DEBUG_KMS("DFP4 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002926 bios_0_scratch |= ATOM_S0_DFP4;
2927 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
2928 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
2929 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002930 DRM_DEBUG_KMS("DFP4 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002931 bios_0_scratch &= ~ATOM_S0_DFP4;
2932 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
2933 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
2934 }
2935 }
2936 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
2937 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
2938 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002939 DRM_DEBUG_KMS("DFP5 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002940 bios_0_scratch |= ATOM_S0_DFP5;
2941 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
2942 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
2943 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002944 DRM_DEBUG_KMS("DFP5 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002945 bios_0_scratch &= ~ATOM_S0_DFP5;
2946 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2947 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2948 }
2949 }
Alex Deucher6f9f8a62012-02-13 08:59:41 -05002950 if ((radeon_encoder->devices & ATOM_DEVICE_DFP6_SUPPORT) &&
2951 (radeon_connector->devices & ATOM_DEVICE_DFP6_SUPPORT)) {
2952 if (connected) {
2953 DRM_DEBUG_KMS("DFP6 connected\n");
2954 bios_0_scratch |= ATOM_S0_DFP6;
2955 bios_3_scratch |= ATOM_S3_DFP6_ACTIVE;
2956 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP6;
2957 } else {
2958 DRM_DEBUG_KMS("DFP6 disconnected\n");
2959 bios_0_scratch &= ~ATOM_S0_DFP6;
2960 bios_3_scratch &= ~ATOM_S3_DFP6_ACTIVE;
2961 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP6;
2962 }
2963 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002964
2965 if (rdev->family >= CHIP_R600) {
2966 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2967 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2968 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2969 } else {
2970 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
2971 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2972 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2973 }
2974}
2975
2976void
2977radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
2978{
2979 struct drm_device *dev = encoder->dev;
2980 struct radeon_device *rdev = dev->dev_private;
2981 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2982 uint32_t bios_3_scratch;
2983
Alex Deucher6f9f8a62012-02-13 08:59:41 -05002984 if (ASIC_IS_DCE4(rdev))
2985 return;
2986
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002987 if (rdev->family >= CHIP_R600)
2988 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2989 else
2990 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2991
2992 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2993 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
2994 bios_3_scratch |= (crtc << 18);
2995 }
2996 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2997 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
2998 bios_3_scratch |= (crtc << 24);
2999 }
3000 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3001 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
3002 bios_3_scratch |= (crtc << 16);
3003 }
3004 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3005 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
3006 bios_3_scratch |= (crtc << 20);
3007 }
3008 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3009 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
3010 bios_3_scratch |= (crtc << 17);
3011 }
3012 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3013 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
3014 bios_3_scratch |= (crtc << 19);
3015 }
3016 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3017 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
3018 bios_3_scratch |= (crtc << 23);
3019 }
3020 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
3021 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
3022 bios_3_scratch |= (crtc << 25);
3023 }
3024
3025 if (rdev->family >= CHIP_R600)
3026 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
3027 else
3028 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
3029}
3030
3031void
3032radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
3033{
3034 struct drm_device *dev = encoder->dev;
3035 struct radeon_device *rdev = dev->dev_private;
3036 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3037 uint32_t bios_2_scratch;
3038
Alex Deucher3ac0eb62012-02-19 21:42:03 -05003039 if (ASIC_IS_DCE4(rdev))
3040 return;
3041
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003042 if (rdev->family >= CHIP_R600)
3043 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
3044 else
3045 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
3046
3047 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
3048 if (on)
3049 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
3050 else
3051 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
3052 }
3053 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
3054 if (on)
3055 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
3056 else
3057 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
3058 }
3059 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
3060 if (on)
3061 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
3062 else
3063 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
3064 }
3065 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
3066 if (on)
3067 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
3068 else
3069 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
3070 }
3071 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
3072 if (on)
3073 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
3074 else
3075 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
3076 }
3077 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
3078 if (on)
3079 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
3080 else
3081 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
3082 }
3083 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
3084 if (on)
3085 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
3086 else
3087 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
3088 }
3089 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
3090 if (on)
3091 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
3092 else
3093 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
3094 }
3095 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
3096 if (on)
3097 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
3098 else
3099 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
3100 }
3101 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
3102 if (on)
3103 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
3104 else
3105 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
3106 }
3107
3108 if (rdev->family >= CHIP_R600)
3109 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
3110 else
3111 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
3112}