blob: b015915441ba094111add8383435e9558914103c [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors: Dave Airlie
24 * Alex Deucher
25 */
26#include "drmP.h"
27#include "radeon_drm.h"
28#include "radeon.h"
29
30#include "atom.h"
31#include "atom-bits.h"
32
33/* from radeon_encoder.c */
34extern uint32_t
Alex Deucher5137ee92010-08-12 18:58:47 -040035radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device,
36 uint8_t dac);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020037extern void radeon_link_encoder_connector(struct drm_device *dev);
38extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040039radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
Jerome Glisse771fe6b2009-06-05 14:42:42 +020040 uint32_t supported_device);
41
42/* from radeon_connector.c */
43extern void
44radeon_add_atom_connector(struct drm_device *dev,
45 uint32_t connector_id,
46 uint32_t supported_device,
47 int connector_type,
48 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -040049 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -050050 uint16_t connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -040051 struct radeon_hpd *hpd,
52 struct radeon_router *router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020053
54/* from radeon_legacy_encoder.c */
55extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040056radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
Jerome Glisse771fe6b2009-06-05 14:42:42 +020057 uint32_t supported_device);
58
59union atom_supported_devices {
60 struct _ATOM_SUPPORTED_DEVICES_INFO info;
61 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
62 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
63};
64
Alex Deuchereed45b32009-12-04 14:45:27 -050065static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
66 uint8_t id)
Jerome Glisse771fe6b2009-06-05 14:42:42 +020067{
Jerome Glisse771fe6b2009-06-05 14:42:42 +020068 struct atom_context *ctx = rdev->mode_info.atom_context;
Alex Deucher6a93cb22009-11-23 17:39:28 -050069 ATOM_GPIO_I2C_ASSIGMENT *gpio;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020070 struct radeon_i2c_bus_rec i2c;
71 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
72 struct _ATOM_GPIO_I2C_INFO *i2c_info;
Alex Deucher95beb692010-04-01 19:08:47 +000073 uint16_t data_offset, size;
74 int i, num_indices;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020075
76 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
77 i2c.valid = false;
78
Alex Deucher95beb692010-04-01 19:08:47 +000079 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
Alex Deuchera084e6e2010-03-18 01:04:01 -040080 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020081
Alex Deucher95beb692010-04-01 19:08:47 +000082 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
83 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
84
85 for (i = 0; i < num_indices; i++) {
Alex Deuchera084e6e2010-03-18 01:04:01 -040086 gpio = &i2c_info->asGPIO_Info[i];
Jerome Glisse771fe6b2009-06-05 14:42:42 +020087
Alex Deuchera084e6e2010-03-18 01:04:01 -040088 if (gpio->sucI2cId.ucAccess == id) {
89 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
90 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
91 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
92 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
93 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
94 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
95 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
96 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
97 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
98 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
99 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
100 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
101 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
102 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
103 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
104 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200105
Alex Deuchera084e6e2010-03-18 01:04:01 -0400106 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
107 i2c.hw_capable = true;
108 else
109 i2c.hw_capable = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500110
Alex Deuchera084e6e2010-03-18 01:04:01 -0400111 if (gpio->sucI2cId.ucAccess == 0xa0)
112 i2c.mm_i2c = true;
113 else
114 i2c.mm_i2c = false;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500115
Alex Deuchera084e6e2010-03-18 01:04:01 -0400116 i2c.i2c_id = gpio->sucI2cId.ucAccess;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500117
Alex Deucherf376b942010-08-05 21:21:16 -0400118 if (i2c.mask_clk_reg)
119 i2c.valid = true;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400120 break;
121 }
Alex Deucherd3f420d2009-12-08 14:30:49 -0500122 }
123 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200124
125 return i2c;
126}
127
Alex Deucherf376b942010-08-05 21:21:16 -0400128void radeon_atombios_i2c_init(struct radeon_device *rdev)
129{
130 struct atom_context *ctx = rdev->mode_info.atom_context;
131 ATOM_GPIO_I2C_ASSIGMENT *gpio;
132 struct radeon_i2c_bus_rec i2c;
133 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
134 struct _ATOM_GPIO_I2C_INFO *i2c_info;
135 uint16_t data_offset, size;
136 int i, num_indices;
137 char stmp[32];
138
139 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
140
141 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
142 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
143
144 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
145 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
146
147 for (i = 0; i < num_indices; i++) {
148 gpio = &i2c_info->asGPIO_Info[i];
149 i2c.valid = false;
150 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
151 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
152 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
153 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
154 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
155 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
156 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
157 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
158 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
159 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
160 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
161 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
162 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
163 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
164 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
165 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
166
167 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
168 i2c.hw_capable = true;
169 else
170 i2c.hw_capable = false;
171
172 if (gpio->sucI2cId.ucAccess == 0xa0)
173 i2c.mm_i2c = true;
174 else
175 i2c.mm_i2c = false;
176
177 i2c.i2c_id = gpio->sucI2cId.ucAccess;
178
179 if (i2c.mask_clk_reg) {
180 i2c.valid = true;
181 sprintf(stmp, "0x%x", i2c.i2c_id);
182 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
183 }
184 }
185 }
186}
187
Alex Deuchereed45b32009-12-04 14:45:27 -0500188static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
189 u8 id)
190{
191 struct atom_context *ctx = rdev->mode_info.atom_context;
192 struct radeon_gpio_rec gpio;
193 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
194 struct _ATOM_GPIO_PIN_LUT *gpio_info;
195 ATOM_GPIO_PIN_ASSIGNMENT *pin;
196 u16 data_offset, size;
197 int i, num_indices;
198
199 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
200 gpio.valid = false;
201
Alex Deuchera084e6e2010-03-18 01:04:01 -0400202 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
203 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
Alex Deuchereed45b32009-12-04 14:45:27 -0500204
Alex Deuchera084e6e2010-03-18 01:04:01 -0400205 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
206 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
Alex Deuchereed45b32009-12-04 14:45:27 -0500207
Alex Deuchera084e6e2010-03-18 01:04:01 -0400208 for (i = 0; i < num_indices; i++) {
209 pin = &gpio_info->asGPIO_Pin[i];
210 if (id == pin->ucGPIO_ID) {
211 gpio.id = pin->ucGPIO_ID;
212 gpio.reg = pin->usGpioPin_AIndex * 4;
213 gpio.mask = (1 << pin->ucGpioPinBitShift);
214 gpio.valid = true;
215 break;
216 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500217 }
218 }
219
220 return gpio;
221}
222
223static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
224 struct radeon_gpio_rec *gpio)
225{
226 struct radeon_hpd hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500227 u32 reg;
228
Jean Delvare1d978da2010-08-15 14:11:24 +0200229 memset(&hpd, 0, sizeof(struct radeon_hpd));
230
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500231 if (ASIC_IS_DCE4(rdev))
232 reg = EVERGREEN_DC_GPIO_HPD_A;
233 else
234 reg = AVIVO_DC_GPIO_HPD_A;
235
Alex Deuchereed45b32009-12-04 14:45:27 -0500236 hpd.gpio = *gpio;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500237 if (gpio->reg == reg) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500238 switch(gpio->mask) {
239 case (1 << 0):
240 hpd.hpd = RADEON_HPD_1;
241 break;
242 case (1 << 8):
243 hpd.hpd = RADEON_HPD_2;
244 break;
245 case (1 << 16):
246 hpd.hpd = RADEON_HPD_3;
247 break;
248 case (1 << 24):
249 hpd.hpd = RADEON_HPD_4;
250 break;
251 case (1 << 26):
252 hpd.hpd = RADEON_HPD_5;
253 break;
254 case (1 << 28):
255 hpd.hpd = RADEON_HPD_6;
256 break;
257 default:
258 hpd.hpd = RADEON_HPD_NONE;
259 break;
260 }
261 } else
262 hpd.hpd = RADEON_HPD_NONE;
263 return hpd;
264}
265
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200266static bool radeon_atom_apply_quirks(struct drm_device *dev,
267 uint32_t supported_device,
268 int *connector_type,
Alex Deucher848577e2009-07-08 16:15:30 -0400269 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -0500270 uint16_t *line_mux,
271 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200272{
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400273 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200274
275 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
276 if ((dev->pdev->device == 0x791e) &&
277 (dev->pdev->subsystem_vendor == 0x1043) &&
278 (dev->pdev->subsystem_device == 0x826d)) {
279 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
280 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
281 *connector_type = DRM_MODE_CONNECTOR_DVID;
282 }
283
Alex Deucherc86a9032010-02-18 14:14:58 -0500284 /* Asrock RS600 board lists the DVI port as HDMI */
285 if ((dev->pdev->device == 0x7941) &&
286 (dev->pdev->subsystem_vendor == 0x1849) &&
287 (dev->pdev->subsystem_device == 0x7941)) {
288 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
289 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
290 *connector_type = DRM_MODE_CONNECTOR_DVID;
291 }
292
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200293 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
294 if ((dev->pdev->device == 0x7941) &&
295 (dev->pdev->subsystem_vendor == 0x147b) &&
296 (dev->pdev->subsystem_device == 0x2412)) {
297 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
298 return false;
299 }
300
301 /* Falcon NW laptop lists vga ddc line for LVDS */
302 if ((dev->pdev->device == 0x5653) &&
303 (dev->pdev->subsystem_vendor == 0x1462) &&
304 (dev->pdev->subsystem_device == 0x0291)) {
Alex Deucher848577e2009-07-08 16:15:30 -0400305 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200306 i2c_bus->valid = false;
Alex Deucher848577e2009-07-08 16:15:30 -0400307 *line_mux = 53;
308 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200309 }
310
Alex Deucher4e3f9b782009-12-01 14:49:50 -0500311 /* HIS X1300 is DVI+VGA, not DVI+DVI */
312 if ((dev->pdev->device == 0x7146) &&
313 (dev->pdev->subsystem_vendor == 0x17af) &&
314 (dev->pdev->subsystem_device == 0x2058)) {
315 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
316 return false;
317 }
318
Dave Airlieaa1a7502009-12-04 11:51:34 +1000319 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
320 if ((dev->pdev->device == 0x7142) &&
321 (dev->pdev->subsystem_vendor == 0x1458) &&
322 (dev->pdev->subsystem_device == 0x2134)) {
323 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
324 return false;
325 }
326
327
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200328 /* Funky macbooks */
329 if ((dev->pdev->device == 0x71C5) &&
330 (dev->pdev->subsystem_vendor == 0x106b) &&
331 (dev->pdev->subsystem_device == 0x0080)) {
332 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
333 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
334 return false;
Alex Deuchere1e8a5d2010-03-26 17:14:37 -0400335 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
336 *line_mux = 0x90;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200337 }
338
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200339 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
340 if ((dev->pdev->device == 0x9598) &&
341 (dev->pdev->subsystem_vendor == 0x1043) &&
342 (dev->pdev->subsystem_device == 0x01da)) {
Alex Deucher705af9c2009-09-10 16:31:13 -0400343 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400344 *connector_type = DRM_MODE_CONNECTOR_DVII;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200345 }
346 }
347
Alex Deuchere153b702010-07-20 18:07:22 -0400348 /* ASUS HD 3600 board lists the DVI port as HDMI */
349 if ((dev->pdev->device == 0x9598) &&
350 (dev->pdev->subsystem_vendor == 0x1043) &&
351 (dev->pdev->subsystem_device == 0x01e4)) {
352 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
353 *connector_type = DRM_MODE_CONNECTOR_DVII;
354 }
355 }
356
Alex Deucher705af9c2009-09-10 16:31:13 -0400357 /* ASUS HD 3450 board lists the DVI port as HDMI */
358 if ((dev->pdev->device == 0x95C5) &&
359 (dev->pdev->subsystem_vendor == 0x1043) &&
360 (dev->pdev->subsystem_device == 0x01e2)) {
361 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400362 *connector_type = DRM_MODE_CONNECTOR_DVII;
Alex Deucher705af9c2009-09-10 16:31:13 -0400363 }
364 }
365
366 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
367 * HDMI + VGA reporting as HDMI
368 */
369 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
370 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
371 *connector_type = DRM_MODE_CONNECTOR_VGA;
372 *line_mux = 0;
373 }
374 }
375
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400376 /* Acer laptop reports DVI-D as DVI-I and hpd pins reversed */
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500377 if ((dev->pdev->device == 0x95c4) &&
378 (dev->pdev->subsystem_vendor == 0x1025) &&
379 (dev->pdev->subsystem_device == 0x013c)) {
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400380 struct radeon_gpio_rec gpio;
381
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500382 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400383 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
384 gpio = radeon_lookup_gpio(rdev, 6);
385 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500386 *connector_type = DRM_MODE_CONNECTOR_DVID;
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400387 } else if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
388 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
389 gpio = radeon_lookup_gpio(rdev, 7);
390 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
391 }
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500392 }
393
Dave Airlieefa84502010-02-09 09:06:00 +1000394 /* XFX Pine Group device rv730 reports no VGA DDC lines
395 * even though they are wired up to record 0x93
396 */
397 if ((dev->pdev->device == 0x9498) &&
398 (dev->pdev->subsystem_vendor == 0x1682) &&
399 (dev->pdev->subsystem_device == 0x2452)) {
400 struct radeon_device *rdev = dev->dev_private;
401 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
402 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200403 return true;
404}
405
406const int supported_devices_connector_convert[] = {
407 DRM_MODE_CONNECTOR_Unknown,
408 DRM_MODE_CONNECTOR_VGA,
409 DRM_MODE_CONNECTOR_DVII,
410 DRM_MODE_CONNECTOR_DVID,
411 DRM_MODE_CONNECTOR_DVIA,
412 DRM_MODE_CONNECTOR_SVIDEO,
413 DRM_MODE_CONNECTOR_Composite,
414 DRM_MODE_CONNECTOR_LVDS,
415 DRM_MODE_CONNECTOR_Unknown,
416 DRM_MODE_CONNECTOR_Unknown,
417 DRM_MODE_CONNECTOR_HDMIA,
418 DRM_MODE_CONNECTOR_HDMIB,
419 DRM_MODE_CONNECTOR_Unknown,
420 DRM_MODE_CONNECTOR_Unknown,
421 DRM_MODE_CONNECTOR_9PinDIN,
422 DRM_MODE_CONNECTOR_DisplayPort
423};
424
Alex Deucherb75fad02009-11-05 13:16:01 -0500425const uint16_t supported_devices_connector_object_id_convert[] = {
426 CONNECTOR_OBJECT_ID_NONE,
427 CONNECTOR_OBJECT_ID_VGA,
428 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
429 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
430 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
431 CONNECTOR_OBJECT_ID_COMPOSITE,
432 CONNECTOR_OBJECT_ID_SVIDEO,
433 CONNECTOR_OBJECT_ID_LVDS,
434 CONNECTOR_OBJECT_ID_9PIN_DIN,
435 CONNECTOR_OBJECT_ID_9PIN_DIN,
436 CONNECTOR_OBJECT_ID_DISPLAYPORT,
437 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
438 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
439 CONNECTOR_OBJECT_ID_SVIDEO
440};
441
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200442const int object_connector_convert[] = {
443 DRM_MODE_CONNECTOR_Unknown,
444 DRM_MODE_CONNECTOR_DVII,
445 DRM_MODE_CONNECTOR_DVII,
446 DRM_MODE_CONNECTOR_DVID,
447 DRM_MODE_CONNECTOR_DVID,
448 DRM_MODE_CONNECTOR_VGA,
449 DRM_MODE_CONNECTOR_Composite,
450 DRM_MODE_CONNECTOR_SVIDEO,
451 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher705af9c2009-09-10 16:31:13 -0400452 DRM_MODE_CONNECTOR_Unknown,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200453 DRM_MODE_CONNECTOR_9PinDIN,
454 DRM_MODE_CONNECTOR_Unknown,
455 DRM_MODE_CONNECTOR_HDMIA,
456 DRM_MODE_CONNECTOR_HDMIB,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200457 DRM_MODE_CONNECTOR_LVDS,
458 DRM_MODE_CONNECTOR_9PinDIN,
459 DRM_MODE_CONNECTOR_Unknown,
460 DRM_MODE_CONNECTOR_Unknown,
461 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher196c58d2010-01-07 14:22:32 -0500462 DRM_MODE_CONNECTOR_DisplayPort,
463 DRM_MODE_CONNECTOR_eDP,
464 DRM_MODE_CONNECTOR_Unknown
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200465};
466
467bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
468{
469 struct radeon_device *rdev = dev->dev_private;
470 struct radeon_mode_info *mode_info = &rdev->mode_info;
471 struct atom_context *ctx = mode_info->atom_context;
472 int index = GetIndexIntoMasterTable(DATA, Object_Header);
Alex Deuchereed45b32009-12-04 14:45:27 -0500473 u16 size, data_offset;
474 u8 frev, crev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200475 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400476 ATOM_OBJECT_TABLE *router_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200477 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
478 ATOM_OBJECT_HEADER *obj_header;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400479 int i, j, k, path_size, device_support;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200480 int connector_type;
Alex Deuchereed45b32009-12-04 14:45:27 -0500481 u16 igp_lane_info, conn_id, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200482 struct radeon_i2c_bus_rec ddc_bus;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400483 struct radeon_router router;
Alex Deuchereed45b32009-12-04 14:45:27 -0500484 struct radeon_gpio_rec gpio;
485 struct radeon_hpd hpd;
486
Alex Deuchera084e6e2010-03-18 01:04:01 -0400487 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200488 return false;
489
490 if (crev < 2)
491 return false;
492
Alex Deucher26b5bc92010-08-05 21:21:18 -0400493 router.valid = false;
494
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200495 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
496 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
497 (ctx->bios + data_offset +
498 le16_to_cpu(obj_header->usDisplayPathTableOffset));
499 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
500 (ctx->bios + data_offset +
501 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
Alex Deucher26b5bc92010-08-05 21:21:18 -0400502 router_obj = (ATOM_OBJECT_TABLE *)
503 (ctx->bios + data_offset +
504 le16_to_cpu(obj_header->usRouterObjectTableOffset));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200505 device_support = le16_to_cpu(obj_header->usDeviceSupport);
506
507 path_size = 0;
508 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
509 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
510 ATOM_DISPLAY_OBJECT_PATH *path;
511 addr += path_size;
512 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
513 path_size += le16_to_cpu(path->usSize);
Alex Deucher5137ee92010-08-12 18:58:47 -0400514
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200515 if (device_support & le16_to_cpu(path->usDeviceTag)) {
516 uint8_t con_obj_id, con_obj_num, con_obj_type;
517
518 con_obj_id =
519 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
520 >> OBJECT_ID_SHIFT;
521 con_obj_num =
522 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
523 >> ENUM_ID_SHIFT;
524 con_obj_type =
525 (le16_to_cpu(path->usConnObjectId) &
526 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
527
Dave Airlie4bbd4972009-09-25 08:56:12 +1000528 /* TODO CV support */
529 if (le16_to_cpu(path->usDeviceTag) ==
530 ATOM_DEVICE_CV_SUPPORT)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200531 continue;
532
Alex Deucheree59f2b2009-11-05 13:11:46 -0500533 /* IGP chips */
534 if ((rdev->flags & RADEON_IS_IGP) &&
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200535 (con_obj_id ==
536 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
537 uint16_t igp_offset = 0;
538 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
539
540 index =
541 GetIndexIntoMasterTable(DATA,
542 IntegratedSystemInfo);
543
Alex Deuchera084e6e2010-03-18 01:04:01 -0400544 if (atom_parse_data_header(ctx, index, &size, &frev,
545 &crev, &igp_offset)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200546
Alex Deuchera084e6e2010-03-18 01:04:01 -0400547 if (crev >= 2) {
548 igp_obj =
549 (ATOM_INTEGRATED_SYSTEM_INFO_V2
550 *) (ctx->bios + igp_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200551
Alex Deuchera084e6e2010-03-18 01:04:01 -0400552 if (igp_obj) {
553 uint32_t slot_config, ct;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200554
Alex Deuchera084e6e2010-03-18 01:04:01 -0400555 if (con_obj_num == 1)
556 slot_config =
557 igp_obj->
558 ulDDISlot1Config;
559 else
560 slot_config =
561 igp_obj->
562 ulDDISlot2Config;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200563
Alex Deuchera084e6e2010-03-18 01:04:01 -0400564 ct = (slot_config >> 16) & 0xff;
565 connector_type =
566 object_connector_convert
567 [ct];
568 connector_object_id = ct;
569 igp_lane_info =
570 slot_config & 0xffff;
571 } else
572 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200573 } else
574 continue;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400575 } else {
576 igp_lane_info = 0;
577 connector_type =
578 object_connector_convert[con_obj_id];
579 connector_object_id = con_obj_id;
580 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200581 } else {
582 igp_lane_info = 0;
583 connector_type =
584 object_connector_convert[con_obj_id];
Alex Deucherb75fad02009-11-05 13:16:01 -0500585 connector_object_id = con_obj_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200586 }
587
588 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
589 continue;
590
Alex Deucher26b5bc92010-08-05 21:21:18 -0400591 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
592 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200593
Alex Deucher26b5bc92010-08-05 21:21:18 -0400594 grph_obj_id =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200595 (le16_to_cpu(path->usGraphicObjIds[j]) &
596 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400597 grph_obj_num =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200598 (le16_to_cpu(path->usGraphicObjIds[j]) &
599 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400600 grph_obj_type =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200601 (le16_to_cpu(path->usGraphicObjIds[j]) &
602 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
603
Alex Deucher26b5bc92010-08-05 21:21:18 -0400604 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
Alex Deucher5137ee92010-08-12 18:58:47 -0400605 u16 encoder_obj = le16_to_cpu(path->usGraphicObjIds[j]);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200606
607 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400608 encoder_obj,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200609 le16_to_cpu
610 (path->
611 usDeviceTag));
612
Alex Deucher26b5bc92010-08-05 21:21:18 -0400613 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
614 router.valid = false;
615 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
616 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[j].usObjectID);
617 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
618 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
619 (ctx->bios + data_offset +
620 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
621 ATOM_I2C_RECORD *i2c_record;
622 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
623 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
624 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
625 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
626 (ctx->bios + data_offset +
627 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
628 int enum_id;
629
630 router.router_id = router_obj_id;
631 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
632 enum_id++) {
633 if (le16_to_cpu(path->usConnObjectId) ==
634 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
635 break;
636 }
637
638 while (record->ucRecordType > 0 &&
639 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
640 switch (record->ucRecordType) {
641 case ATOM_I2C_RECORD_TYPE:
642 i2c_record =
643 (ATOM_I2C_RECORD *)
644 record;
645 i2c_config =
646 (ATOM_I2C_ID_CONFIG_ACCESS *)
647 &i2c_record->sucI2cId;
648 router.i2c_info =
649 radeon_lookup_i2c_gpio(rdev,
650 i2c_config->
651 ucAccess);
652 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
653 break;
654 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
655 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
656 record;
657 router.valid = true;
658 router.mux_type = ddc_path->ucMuxType;
659 router.mux_control_pin = ddc_path->ucMuxControlPin;
660 router.mux_state = ddc_path->ucMuxState[enum_id];
661 break;
662 }
663 record = (ATOM_COMMON_RECORD_HEADER *)
664 ((char *)record + record->ucRecordSize);
665 }
666 }
667 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200668 }
669 }
670
Alex Deuchereed45b32009-12-04 14:45:27 -0500671 /* look up gpio for ddc, hpd */
Alex Deucher2bfcc0f2010-05-18 19:26:46 -0400672 ddc_bus.valid = false;
673 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200674 if ((le16_to_cpu(path->usDeviceTag) &
Alex Deuchereed45b32009-12-04 14:45:27 -0500675 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200676 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
677 if (le16_to_cpu(path->usConnObjectId) ==
678 le16_to_cpu(con_obj->asObjects[j].
679 usObjectID)) {
680 ATOM_COMMON_RECORD_HEADER
681 *record =
682 (ATOM_COMMON_RECORD_HEADER
683 *)
684 (ctx->bios + data_offset +
685 le16_to_cpu(con_obj->
686 asObjects[j].
687 usRecordOffset));
688 ATOM_I2C_RECORD *i2c_record;
Alex Deuchereed45b32009-12-04 14:45:27 -0500689 ATOM_HPD_INT_RECORD *hpd_record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500690 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500691
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200692 while (record->ucRecordType > 0
693 && record->
694 ucRecordType <=
695 ATOM_MAX_OBJECT_RECORD_NUMBER) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500696 switch (record->ucRecordType) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200697 case ATOM_I2C_RECORD_TYPE:
698 i2c_record =
Alex Deuchereed45b32009-12-04 14:45:27 -0500699 (ATOM_I2C_RECORD *)
700 record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500701 i2c_config =
702 (ATOM_I2C_ID_CONFIG_ACCESS *)
703 &i2c_record->sucI2cId;
Alex Deuchereed45b32009-12-04 14:45:27 -0500704 ddc_bus = radeon_lookup_i2c_gpio(rdev,
Alex Deucherd3f420d2009-12-08 14:30:49 -0500705 i2c_config->
706 ucAccess);
Alex Deuchereed45b32009-12-04 14:45:27 -0500707 break;
708 case ATOM_HPD_INT_RECORD_TYPE:
709 hpd_record =
710 (ATOM_HPD_INT_RECORD *)
711 record;
712 gpio = radeon_lookup_gpio(rdev,
713 hpd_record->ucHPDIntGPIOID);
714 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
715 hpd.plugged_state = hpd_record->ucPlugged_PinState;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200716 break;
717 }
718 record =
719 (ATOM_COMMON_RECORD_HEADER
720 *) ((char *)record
721 +
722 record->
723 ucRecordSize);
724 }
725 break;
726 }
727 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500728 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200729
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500730 /* needed for aux chan transactions */
Alex Deucher8e36ed02010-05-18 19:26:47 -0400731 ddc_bus.hpd = hpd.hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500732
Alex Deucher705af9c2009-09-10 16:31:13 -0400733 conn_id = le16_to_cpu(path->usConnObjectId);
734
735 if (!radeon_atom_apply_quirks
736 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500737 &ddc_bus, &conn_id, &hpd))
Alex Deucher705af9c2009-09-10 16:31:13 -0400738 continue;
739
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200740 radeon_add_atom_connector(dev,
Alex Deucher705af9c2009-09-10 16:31:13 -0400741 conn_id,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200742 le16_to_cpu(path->
743 usDeviceTag),
744 connector_type, &ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -0400745 igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -0500746 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -0400747 &hpd,
748 &router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200749
750 }
751 }
752
753 radeon_link_encoder_connector(dev);
754
755 return true;
756}
757
Alex Deucherb75fad02009-11-05 13:16:01 -0500758static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
759 int connector_type,
760 uint16_t devices)
761{
762 struct radeon_device *rdev = dev->dev_private;
763
764 if (rdev->flags & RADEON_IS_IGP) {
765 return supported_devices_connector_object_id_convert
766 [connector_type];
767 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
768 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
769 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
770 struct radeon_mode_info *mode_info = &rdev->mode_info;
771 struct atom_context *ctx = mode_info->atom_context;
772 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
773 uint16_t size, data_offset;
774 uint8_t frev, crev;
775 ATOM_XTMDS_INFO *xtmds;
776
Alex Deuchera084e6e2010-03-18 01:04:01 -0400777 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
778 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
Alex Deucherb75fad02009-11-05 13:16:01 -0500779
Alex Deuchera084e6e2010-03-18 01:04:01 -0400780 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
781 if (connector_type == DRM_MODE_CONNECTOR_DVII)
782 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
783 else
784 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
785 } else {
786 if (connector_type == DRM_MODE_CONNECTOR_DVII)
787 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
788 else
789 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
790 }
791 } else
792 return supported_devices_connector_object_id_convert
793 [connector_type];
Alex Deucherb75fad02009-11-05 13:16:01 -0500794 } else {
795 return supported_devices_connector_object_id_convert
796 [connector_type];
797 }
798}
799
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200800struct bios_connector {
801 bool valid;
Alex Deucher705af9c2009-09-10 16:31:13 -0400802 uint16_t line_mux;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200803 uint16_t devices;
804 int connector_type;
805 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500806 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200807};
808
809bool radeon_get_atom_connector_info_from_supported_devices_table(struct
810 drm_device
811 *dev)
812{
813 struct radeon_device *rdev = dev->dev_private;
814 struct radeon_mode_info *mode_info = &rdev->mode_info;
815 struct atom_context *ctx = mode_info->atom_context;
816 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
817 uint16_t size, data_offset;
818 uint8_t frev, crev;
819 uint16_t device_support;
820 uint8_t dac;
821 union atom_supported_devices *supported_devices;
Alex Deuchereed45b32009-12-04 14:45:27 -0500822 int i, j, max_device;
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000823 struct bios_connector *bios_connectors;
824 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400825 struct radeon_router router;
826
827 router.valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200828
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000829 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
830 if (!bios_connectors)
Alex Deuchera084e6e2010-03-18 01:04:01 -0400831 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200832
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000833 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
834 &data_offset)) {
835 kfree(bios_connectors);
836 return false;
837 }
838
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200839 supported_devices =
840 (union atom_supported_devices *)(ctx->bios + data_offset);
841
842 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
843
Alex Deuchereed45b32009-12-04 14:45:27 -0500844 if (frev > 1)
845 max_device = ATOM_MAX_SUPPORTED_DEVICE;
846 else
847 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
848
849 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200850 ATOM_CONNECTOR_INFO_I2C ci =
851 supported_devices->info.asConnInfo[i];
852
853 bios_connectors[i].valid = false;
854
855 if (!(device_support & (1 << i))) {
856 continue;
857 }
858
859 if (i == ATOM_DEVICE_CV_INDEX) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000860 DRM_DEBUG_KMS("Skipping Component Video\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200861 continue;
862 }
863
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200864 bios_connectors[i].connector_type =
865 supported_devices_connector_convert[ci.sucConnectorInfo.
866 sbfAccess.
867 bfConnectorType];
868
869 if (bios_connectors[i].connector_type ==
870 DRM_MODE_CONNECTOR_Unknown)
871 continue;
872
873 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
874
Alex Deucherd3f420d2009-12-08 14:30:49 -0500875 bios_connectors[i].line_mux =
876 ci.sucI2cId.ucAccess;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200877
878 /* give tv unique connector ids */
879 if (i == ATOM_DEVICE_TV1_INDEX) {
880 bios_connectors[i].ddc_bus.valid = false;
881 bios_connectors[i].line_mux = 50;
882 } else if (i == ATOM_DEVICE_TV2_INDEX) {
883 bios_connectors[i].ddc_bus.valid = false;
884 bios_connectors[i].line_mux = 51;
885 } else if (i == ATOM_DEVICE_CV_INDEX) {
886 bios_connectors[i].ddc_bus.valid = false;
887 bios_connectors[i].line_mux = 52;
888 } else
889 bios_connectors[i].ddc_bus =
Alex Deuchereed45b32009-12-04 14:45:27 -0500890 radeon_lookup_i2c_gpio(rdev,
891 bios_connectors[i].line_mux);
892
893 if ((crev > 1) && (frev > 1)) {
894 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
895 switch (isb) {
896 case 0x4:
897 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
898 break;
899 case 0xa:
900 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
901 break;
902 default:
903 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
904 break;
905 }
906 } else {
907 if (i == ATOM_DEVICE_DFP1_INDEX)
908 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
909 else if (i == ATOM_DEVICE_DFP2_INDEX)
910 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
911 else
912 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
913 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200914
915 /* Always set the connector type to VGA for CRT1/CRT2. if they are
916 * shared with a DVI port, we'll pick up the DVI connector when we
917 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
918 */
919 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
920 bios_connectors[i].connector_type =
921 DRM_MODE_CONNECTOR_VGA;
922
923 if (!radeon_atom_apply_quirks
924 (dev, (1 << i), &bios_connectors[i].connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500925 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
926 &bios_connectors[i].hpd))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200927 continue;
928
929 bios_connectors[i].valid = true;
930 bios_connectors[i].devices = (1 << i);
931
932 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
933 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400934 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200935 (1 << i),
936 dac),
937 (1 << i));
938 else
939 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -0400940 radeon_get_encoder_enum(dev,
Alex Deucherf56cd642009-12-18 11:28:22 -0500941 (1 << i),
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200942 dac),
943 (1 << i));
944 }
945
946 /* combine shared connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -0500947 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200948 if (bios_connectors[i].valid) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500949 for (j = 0; j < max_device; j++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200950 if (bios_connectors[j].valid && (i != j)) {
951 if (bios_connectors[i].line_mux ==
952 bios_connectors[j].line_mux) {
Alex Deucherf56cd642009-12-18 11:28:22 -0500953 /* make sure not to combine LVDS */
954 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
955 bios_connectors[i].line_mux = 53;
956 bios_connectors[i].ddc_bus.valid = false;
957 continue;
958 }
959 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
960 bios_connectors[j].line_mux = 53;
961 bios_connectors[j].ddc_bus.valid = false;
962 continue;
963 }
964 /* combine analog and digital for DVI-I */
965 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
966 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
967 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
968 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
969 bios_connectors[i].devices |=
970 bios_connectors[j].devices;
971 bios_connectors[i].connector_type =
972 DRM_MODE_CONNECTOR_DVII;
973 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
Alex Deuchereed45b32009-12-04 14:45:27 -0500974 bios_connectors[i].hpd =
975 bios_connectors[j].hpd;
Alex Deucherf56cd642009-12-18 11:28:22 -0500976 bios_connectors[j].valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200977 }
978 }
979 }
980 }
981 }
982 }
983
984 /* add the connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -0500985 for (i = 0; i < max_device; i++) {
Alex Deucherb75fad02009-11-05 13:16:01 -0500986 if (bios_connectors[i].valid) {
987 uint16_t connector_object_id =
988 atombios_get_connector_object_id(dev,
989 bios_connectors[i].connector_type,
990 bios_connectors[i].devices);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200991 radeon_add_atom_connector(dev,
992 bios_connectors[i].line_mux,
993 bios_connectors[i].devices,
994 bios_connectors[i].
995 connector_type,
996 &bios_connectors[i].ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -0400997 0,
Alex Deuchereed45b32009-12-04 14:45:27 -0500998 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -0400999 &bios_connectors[i].hpd,
1000 &router);
Alex Deucherb75fad02009-11-05 13:16:01 -05001001 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001002 }
1003
1004 radeon_link_encoder_connector(dev);
1005
Prarit Bhargavaf49d2732010-05-24 10:24:07 +10001006 kfree(bios_connectors);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001007 return true;
1008}
1009
1010union firmware_info {
1011 ATOM_FIRMWARE_INFO info;
1012 ATOM_FIRMWARE_INFO_V1_2 info_12;
1013 ATOM_FIRMWARE_INFO_V1_3 info_13;
1014 ATOM_FIRMWARE_INFO_V1_4 info_14;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001015 ATOM_FIRMWARE_INFO_V2_1 info_21;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001016};
1017
1018bool radeon_atom_get_clock_info(struct drm_device *dev)
1019{
1020 struct radeon_device *rdev = dev->dev_private;
1021 struct radeon_mode_info *mode_info = &rdev->mode_info;
1022 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1023 union firmware_info *firmware_info;
1024 uint8_t frev, crev;
1025 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1026 struct radeon_pll *p2pll = &rdev->clock.p2pll;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001027 struct radeon_pll *dcpll = &rdev->clock.dcpll;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001028 struct radeon_pll *spll = &rdev->clock.spll;
1029 struct radeon_pll *mpll = &rdev->clock.mpll;
1030 uint16_t data_offset;
1031
Alex Deuchera084e6e2010-03-18 01:04:01 -04001032 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1033 &frev, &crev, &data_offset)) {
1034 firmware_info =
1035 (union firmware_info *)(mode_info->atom_context->bios +
1036 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001037 /* pixel clocks */
1038 p1pll->reference_freq =
1039 le16_to_cpu(firmware_info->info.usReferenceClock);
1040 p1pll->reference_div = 0;
1041
Mathias Fröhlichbc293e52009-10-19 17:49:49 -04001042 if (crev < 2)
1043 p1pll->pll_out_min =
1044 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1045 else
1046 p1pll->pll_out_min =
1047 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001048 p1pll->pll_out_max =
1049 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1050
Alex Deucher86cb2bb2010-03-08 12:55:16 -05001051 if (crev >= 4) {
1052 p1pll->lcd_pll_out_min =
1053 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1054 if (p1pll->lcd_pll_out_min == 0)
1055 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1056 p1pll->lcd_pll_out_max =
1057 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1058 if (p1pll->lcd_pll_out_max == 0)
1059 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1060 } else {
1061 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1062 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1063 }
1064
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001065 if (p1pll->pll_out_min == 0) {
1066 if (ASIC_IS_AVIVO(rdev))
1067 p1pll->pll_out_min = 64800;
1068 else
1069 p1pll->pll_out_min = 20000;
Alex Deucher8f552a62009-10-27 11:16:09 -04001070 } else if (p1pll->pll_out_min > 64800) {
1071 /* Limiting the pll output range is a good thing generally as
1072 * it limits the number of possible pll combinations for a given
1073 * frequency presumably to the ones that work best on each card.
1074 * However, certain duallink DVI monitors seem to like
1075 * pll combinations that would be limited by this at least on
1076 * pre-DCE 3.0 r6xx hardware. This might need to be adjusted per
1077 * family.
1078 */
Alex Deucherb27b6372009-12-09 17:44:25 -05001079 if (!radeon_new_pll)
1080 p1pll->pll_out_min = 64800;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001081 }
1082
1083 p1pll->pll_in_min =
1084 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1085 p1pll->pll_in_max =
1086 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1087
1088 *p2pll = *p1pll;
1089
1090 /* system clock */
1091 spll->reference_freq =
1092 le16_to_cpu(firmware_info->info.usReferenceClock);
1093 spll->reference_div = 0;
1094
1095 spll->pll_out_min =
1096 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1097 spll->pll_out_max =
1098 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1099
1100 /* ??? */
1101 if (spll->pll_out_min == 0) {
1102 if (ASIC_IS_AVIVO(rdev))
1103 spll->pll_out_min = 64800;
1104 else
1105 spll->pll_out_min = 20000;
1106 }
1107
1108 spll->pll_in_min =
1109 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1110 spll->pll_in_max =
1111 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1112
1113 /* memory clock */
1114 mpll->reference_freq =
1115 le16_to_cpu(firmware_info->info.usReferenceClock);
1116 mpll->reference_div = 0;
1117
1118 mpll->pll_out_min =
1119 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1120 mpll->pll_out_max =
1121 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1122
1123 /* ??? */
1124 if (mpll->pll_out_min == 0) {
1125 if (ASIC_IS_AVIVO(rdev))
1126 mpll->pll_out_min = 64800;
1127 else
1128 mpll->pll_out_min = 20000;
1129 }
1130
1131 mpll->pll_in_min =
1132 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1133 mpll->pll_in_max =
1134 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1135
1136 rdev->clock.default_sclk =
1137 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1138 rdev->clock.default_mclk =
1139 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1140
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001141 if (ASIC_IS_DCE4(rdev)) {
1142 rdev->clock.default_dispclk =
1143 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
1144 if (rdev->clock.default_dispclk == 0)
1145 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1146 rdev->clock.dp_extclk =
1147 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
1148 }
1149 *dcpll = *p1pll;
1150
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001151 return true;
1152 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001153
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001154 return false;
1155}
1156
Alex Deucher06b64762010-01-05 11:27:29 -05001157union igp_info {
1158 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1159 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1160};
1161
1162bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1163{
1164 struct radeon_mode_info *mode_info = &rdev->mode_info;
1165 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1166 union igp_info *igp_info;
1167 u8 frev, crev;
1168 u16 data_offset;
1169
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001170 /* sideport is AMD only */
1171 if (rdev->family == CHIP_RS600)
1172 return false;
1173
Alex Deuchera084e6e2010-03-18 01:04:01 -04001174 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1175 &frev, &crev, &data_offset)) {
1176 igp_info = (union igp_info *)(mode_info->atom_context->bios +
Alex Deucher06b64762010-01-05 11:27:29 -05001177 data_offset);
Alex Deucher06b64762010-01-05 11:27:29 -05001178 switch (crev) {
1179 case 1:
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001180 if (igp_info->info.ulBootUpMemoryClock)
1181 return true;
Alex Deucher06b64762010-01-05 11:27:29 -05001182 break;
1183 case 2:
1184 if (igp_info->info_2.ucMemoryType & 0x0f)
1185 return true;
1186 break;
1187 default:
1188 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1189 break;
1190 }
1191 }
1192 return false;
1193}
1194
Dave Airlie445282d2009-09-09 17:40:54 +10001195bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1196 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001197{
1198 struct drm_device *dev = encoder->base.dev;
1199 struct radeon_device *rdev = dev->dev_private;
1200 struct radeon_mode_info *mode_info = &rdev->mode_info;
1201 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1202 uint16_t data_offset;
1203 struct _ATOM_TMDS_INFO *tmds_info;
1204 uint8_t frev, crev;
1205 uint16_t maxfreq;
1206 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001207
Alex Deuchera084e6e2010-03-18 01:04:01 -04001208 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1209 &frev, &crev, &data_offset)) {
1210 tmds_info =
1211 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1212 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001213
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001214 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1215 for (i = 0; i < 4; i++) {
1216 tmds->tmds_pll[i].freq =
1217 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1218 tmds->tmds_pll[i].value =
1219 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1220 tmds->tmds_pll[i].value |=
1221 (tmds_info->asMiscInfo[i].
1222 ucPLL_VCO_Gain & 0x3f) << 6;
1223 tmds->tmds_pll[i].value |=
1224 (tmds_info->asMiscInfo[i].
1225 ucPLL_DutyCycle & 0xf) << 12;
1226 tmds->tmds_pll[i].value |=
1227 (tmds_info->asMiscInfo[i].
1228 ucPLL_VoltageSwing & 0xf) << 16;
1229
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001230 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001231 tmds->tmds_pll[i].freq,
1232 tmds->tmds_pll[i].value);
1233
1234 if (maxfreq == tmds->tmds_pll[i].freq) {
1235 tmds->tmds_pll[i].freq = 0xffffffff;
1236 break;
1237 }
1238 }
Dave Airlie445282d2009-09-09 17:40:54 +10001239 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001240 }
Dave Airlie445282d2009-09-09 17:40:54 +10001241 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001242}
1243
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001244static struct radeon_atom_ss *radeon_atombios_get_ss_info(struct
1245 radeon_encoder
1246 *encoder,
1247 int id)
1248{
1249 struct drm_device *dev = encoder->base.dev;
1250 struct radeon_device *rdev = dev->dev_private;
1251 struct radeon_mode_info *mode_info = &rdev->mode_info;
1252 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
1253 uint16_t data_offset;
1254 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
1255 uint8_t frev, crev;
1256 struct radeon_atom_ss *ss = NULL;
Alex Deucher279b2152009-12-08 14:07:03 -05001257 int i;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001258
1259 if (id > ATOM_MAX_SS_ENTRY)
1260 return NULL;
1261
Alex Deuchera084e6e2010-03-18 01:04:01 -04001262 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1263 &frev, &crev, &data_offset)) {
1264 ss_info =
1265 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001266
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001267 ss =
1268 kzalloc(sizeof(struct radeon_atom_ss), GFP_KERNEL);
1269
1270 if (!ss)
1271 return NULL;
1272
Alex Deucher279b2152009-12-08 14:07:03 -05001273 for (i = 0; i < ATOM_MAX_SS_ENTRY; i++) {
1274 if (ss_info->asSS_Info[i].ucSS_Id == id) {
1275 ss->percentage =
1276 le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage);
1277 ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType;
1278 ss->step = ss_info->asSS_Info[i].ucSS_Step;
1279 ss->delay = ss_info->asSS_Info[i].ucSS_Delay;
1280 ss->range = ss_info->asSS_Info[i].ucSS_Range;
1281 ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div;
Alex Deucher1d3d51b2009-12-28 13:45:23 -05001282 break;
Alex Deucher279b2152009-12-08 14:07:03 -05001283 }
1284 }
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001285 }
1286 return ss;
1287}
1288
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001289union lvds_info {
1290 struct _ATOM_LVDS_INFO info;
1291 struct _ATOM_LVDS_INFO_V12 info_12;
1292};
1293
1294struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1295 radeon_encoder
1296 *encoder)
1297{
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, LVDS_Info);
Alex Deucher7dde8a192009-11-30 01:40:24 -05001302 uint16_t data_offset, misc;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001303 union lvds_info *lvds_info;
1304 uint8_t frev, crev;
1305 struct radeon_encoder_atom_dig *lvds = NULL;
Alex Deucher5137ee92010-08-12 18:58:47 -04001306 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
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 lvds_info =
1311 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001312 lvds =
1313 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1314
1315 if (!lvds)
1316 return NULL;
1317
Alex Deucherde2103e2009-10-09 15:14:30 -04001318 lvds->native_mode.clock =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001319 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
Alex Deucherde2103e2009-10-09 15:14:30 -04001320 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001321 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001322 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001323 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001324 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1325 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1326 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1327 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1328 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1329 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1330 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1331 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1332 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
Alex Deucher1ff26a32010-05-18 00:23:15 -04001333 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
Alex Deucherde2103e2009-10-09 15:14:30 -04001334 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1335 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001336 lvds->panel_pwr_delay =
1337 le16_to_cpu(lvds_info->info.usOffDelayInMs);
1338 lvds->lvds_misc = lvds_info->info.ucLVDS_Misc;
Alex Deucher7dde8a192009-11-30 01:40:24 -05001339
1340 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1341 if (misc & ATOM_VSYNC_POLARITY)
1342 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1343 if (misc & ATOM_HSYNC_POLARITY)
1344 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1345 if (misc & ATOM_COMPOSITESYNC)
1346 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1347 if (misc & ATOM_INTERLACE)
1348 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1349 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1350 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1351
Alex Deucherde2103e2009-10-09 15:14:30 -04001352 /* set crtc values */
1353 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001354
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001355 lvds->ss = radeon_atombios_get_ss_info(encoder, lvds_info->info.ucSS_Id);
1356
Alex Deucher7c27f872010-02-02 12:05:01 -05001357 if (ASIC_IS_AVIVO(rdev)) {
Alex Deucher383be5d2010-02-23 03:24:38 -05001358 if (radeon_new_pll == 0)
1359 lvds->pll_algo = PLL_ALGO_LEGACY;
1360 else
1361 lvds->pll_algo = PLL_ALGO_NEW;
1362 } else {
1363 if (radeon_new_pll == 1)
1364 lvds->pll_algo = PLL_ALGO_NEW;
Alex Deucher7c27f872010-02-02 12:05:01 -05001365 else
1366 lvds->pll_algo = PLL_ALGO_LEGACY;
Alex Deucher383be5d2010-02-23 03:24:38 -05001367 }
Alex Deucher7c27f872010-02-02 12:05:01 -05001368
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001369 encoder->native_mode = lvds->native_mode;
Alex Deucher5137ee92010-08-12 18:58:47 -04001370
1371 if (encoder_enum == 2)
1372 lvds->linkb = true;
1373 else
1374 lvds->linkb = false;
1375
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001376 }
1377 return lvds;
1378}
1379
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001380struct radeon_encoder_primary_dac *
1381radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1382{
1383 struct drm_device *dev = encoder->base.dev;
1384 struct radeon_device *rdev = dev->dev_private;
1385 struct radeon_mode_info *mode_info = &rdev->mode_info;
1386 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1387 uint16_t data_offset;
1388 struct _COMPASSIONATE_DATA *dac_info;
1389 uint8_t frev, crev;
1390 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001391 struct radeon_encoder_primary_dac *p_dac = NULL;
1392
Alex Deuchera084e6e2010-03-18 01:04:01 -04001393 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1394 &frev, &crev, &data_offset)) {
1395 dac_info = (struct _COMPASSIONATE_DATA *)
1396 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001397
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001398 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1399
1400 if (!p_dac)
1401 return NULL;
1402
1403 bg = dac_info->ucDAC1_BG_Adjustment;
1404 dac = dac_info->ucDAC1_DAC_Adjustment;
1405 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1406
1407 }
1408 return p_dac;
1409}
1410
Dave Airlie4ce001a2009-08-13 16:32:14 +10001411bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001412 struct drm_display_mode *mode)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001413{
1414 struct radeon_mode_info *mode_info = &rdev->mode_info;
1415 ATOM_ANALOG_TV_INFO *tv_info;
1416 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1417 ATOM_DTD_FORMAT *dtd_timings;
1418 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1419 u8 frev, crev;
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001420 u16 data_offset, misc;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001421
Alex Deuchera084e6e2010-03-18 01:04:01 -04001422 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1423 &frev, &crev, &data_offset))
1424 return false;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001425
1426 switch (crev) {
1427 case 1:
1428 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001429 if (index >= MAX_SUPPORTED_TV_TIMING)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001430 return false;
1431
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001432 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1433 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1434 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1435 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1436 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001437
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001438 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1439 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1440 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1441 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1442 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001443
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001444 mode->flags = 0;
1445 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1446 if (misc & ATOM_VSYNC_POLARITY)
1447 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1448 if (misc & ATOM_HSYNC_POLARITY)
1449 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1450 if (misc & ATOM_COMPOSITESYNC)
1451 mode->flags |= DRM_MODE_FLAG_CSYNC;
1452 if (misc & ATOM_INTERLACE)
1453 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1454 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1455 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001456
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001457 mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001458
1459 if (index == 1) {
1460 /* PAL timings appear to have wrong values for totals */
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001461 mode->crtc_htotal -= 1;
1462 mode->crtc_vtotal -= 1;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001463 }
1464 break;
1465 case 2:
1466 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001467 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001468 return false;
1469
1470 dtd_timings = &tv_info_v1_2->aModeTimings[index];
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001471 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1472 le16_to_cpu(dtd_timings->usHBlanking_Time);
1473 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1474 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1475 le16_to_cpu(dtd_timings->usHSyncOffset);
1476 mode->crtc_hsync_end = mode->crtc_hsync_start +
1477 le16_to_cpu(dtd_timings->usHSyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001478
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001479 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1480 le16_to_cpu(dtd_timings->usVBlanking_Time);
1481 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1482 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1483 le16_to_cpu(dtd_timings->usVSyncOffset);
1484 mode->crtc_vsync_end = mode->crtc_vsync_start +
1485 le16_to_cpu(dtd_timings->usVSyncWidth);
1486
1487 mode->flags = 0;
1488 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1489 if (misc & ATOM_VSYNC_POLARITY)
1490 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1491 if (misc & ATOM_HSYNC_POLARITY)
1492 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1493 if (misc & ATOM_COMPOSITESYNC)
1494 mode->flags |= DRM_MODE_FLAG_CSYNC;
1495 if (misc & ATOM_INTERLACE)
1496 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1497 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1498 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1499
1500 mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001501 break;
1502 }
1503 return true;
1504}
1505
Alex Deucherd79766f2009-12-17 19:00:29 -05001506enum radeon_tv_std
1507radeon_atombios_get_tv_info(struct radeon_device *rdev)
1508{
1509 struct radeon_mode_info *mode_info = &rdev->mode_info;
1510 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1511 uint16_t data_offset;
1512 uint8_t frev, crev;
1513 struct _ATOM_ANALOG_TV_INFO *tv_info;
1514 enum radeon_tv_std tv_std = TV_STD_NTSC;
1515
Alex Deuchera084e6e2010-03-18 01:04:01 -04001516 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1517 &frev, &crev, &data_offset)) {
Alex Deucherd79766f2009-12-17 19:00:29 -05001518
Alex Deuchera084e6e2010-03-18 01:04:01 -04001519 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1520 (mode_info->atom_context->bios + data_offset);
Alex Deucherd79766f2009-12-17 19:00:29 -05001521
Alex Deuchera084e6e2010-03-18 01:04:01 -04001522 switch (tv_info->ucTV_BootUpDefaultStandard) {
1523 case ATOM_TV_NTSC:
1524 tv_std = TV_STD_NTSC;
1525 DRM_INFO("Default TV standard: NTSC\n");
1526 break;
1527 case ATOM_TV_NTSCJ:
1528 tv_std = TV_STD_NTSC_J;
1529 DRM_INFO("Default TV standard: NTSC-J\n");
1530 break;
1531 case ATOM_TV_PAL:
1532 tv_std = TV_STD_PAL;
1533 DRM_INFO("Default TV standard: PAL\n");
1534 break;
1535 case ATOM_TV_PALM:
1536 tv_std = TV_STD_PAL_M;
1537 DRM_INFO("Default TV standard: PAL-M\n");
1538 break;
1539 case ATOM_TV_PALN:
1540 tv_std = TV_STD_PAL_N;
1541 DRM_INFO("Default TV standard: PAL-N\n");
1542 break;
1543 case ATOM_TV_PALCN:
1544 tv_std = TV_STD_PAL_CN;
1545 DRM_INFO("Default TV standard: PAL-CN\n");
1546 break;
1547 case ATOM_TV_PAL60:
1548 tv_std = TV_STD_PAL_60;
1549 DRM_INFO("Default TV standard: PAL-60\n");
1550 break;
1551 case ATOM_TV_SECAM:
1552 tv_std = TV_STD_SECAM;
1553 DRM_INFO("Default TV standard: SECAM\n");
1554 break;
1555 default:
1556 tv_std = TV_STD_NTSC;
1557 DRM_INFO("Unknown TV standard; defaulting to NTSC\n");
1558 break;
1559 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001560 }
1561 return tv_std;
1562}
1563
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001564struct radeon_encoder_tv_dac *
1565radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1566{
1567 struct drm_device *dev = encoder->base.dev;
1568 struct radeon_device *rdev = dev->dev_private;
1569 struct radeon_mode_info *mode_info = &rdev->mode_info;
1570 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1571 uint16_t data_offset;
1572 struct _COMPASSIONATE_DATA *dac_info;
1573 uint8_t frev, crev;
1574 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001575 struct radeon_encoder_tv_dac *tv_dac = NULL;
1576
Alex Deuchera084e6e2010-03-18 01:04:01 -04001577 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1578 &frev, &crev, &data_offset)) {
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001579
Alex Deuchera084e6e2010-03-18 01:04:01 -04001580 dac_info = (struct _COMPASSIONATE_DATA *)
1581 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001582
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001583 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1584
1585 if (!tv_dac)
1586 return NULL;
1587
1588 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1589 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1590 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1591
1592 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1593 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1594 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1595
1596 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1597 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1598 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1599
Alex Deucherd79766f2009-12-17 19:00:29 -05001600 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001601 }
1602 return tv_dac;
1603}
1604
Alex Deucher29fb52c2010-03-11 10:01:17 -05001605static const char *thermal_controller_names[] = {
1606 "NONE",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001607 "lm63",
1608 "adm1032",
1609 "adm1030",
1610 "max6649",
1611 "lm64",
1612 "f75375",
1613 "asc7xxx",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001614};
1615
1616static const char *pp_lib_thermal_controller_names[] = {
1617 "NONE",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001618 "lm63",
1619 "adm1032",
1620 "adm1030",
1621 "max6649",
1622 "lm64",
1623 "f75375",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001624 "RV6xx",
1625 "RV770",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001626 "adt7473",
Alex Deucher49f65982010-03-24 16:39:45 -04001627 "External GPIO",
1628 "Evergreen",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001629 "adt7473 with internal",
Alex Deucher49f65982010-03-24 16:39:45 -04001630
Alex Deucher29fb52c2010-03-11 10:01:17 -05001631};
1632
Alex Deucher56278a82009-12-28 13:58:44 -05001633union power_info {
1634 struct _ATOM_POWERPLAY_INFO info;
1635 struct _ATOM_POWERPLAY_INFO_V2 info_2;
1636 struct _ATOM_POWERPLAY_INFO_V3 info_3;
1637 struct _ATOM_PPLIB_POWERPLAYTABLE info_4;
1638};
1639
1640void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1641{
1642 struct radeon_mode_info *mode_info = &rdev->mode_info;
1643 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
1644 u16 data_offset;
1645 u8 frev, crev;
1646 u32 misc, misc2 = 0, sclk, mclk;
1647 union power_info *power_info;
1648 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
1649 struct _ATOM_PPLIB_STATE *power_state;
1650 int num_modes = 0, i, j;
1651 int state_index = 0, mode_index = 0;
Alex Deucher29fb52c2010-03-11 10:01:17 -05001652 struct radeon_i2c_bus_rec i2c_bus;
Alex Deucher56278a82009-12-28 13:58:44 -05001653
Alex Deuchera48b9b42010-04-22 14:03:55 -04001654 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05001655
Alex Deuchera084e6e2010-03-18 01:04:01 -04001656 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1657 &frev, &crev, &data_offset)) {
1658 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
Alex Deucher56278a82009-12-28 13:58:44 -05001659 if (frev < 4) {
Alex Deucher29fb52c2010-03-11 10:01:17 -05001660 /* add the i2c bus for thermal/fan chip */
1661 if (power_info->info.ucOverdriveThermalController > 0) {
1662 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
1663 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1664 power_info->info.ucOverdriveControllerAddress >> 1);
1665 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
Alex Deucherf376b942010-08-05 21:21:16 -04001666 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001667 if (rdev->pm.i2c_bus) {
1668 struct i2c_board_info info = { };
1669 const char *name = thermal_controller_names[power_info->info.
1670 ucOverdriveThermalController];
1671 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
1672 strlcpy(info.type, name, sizeof(info.type));
1673 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
1674 }
Alex Deucher29fb52c2010-03-11 10:01:17 -05001675 }
Alex Deucher56278a82009-12-28 13:58:44 -05001676 num_modes = power_info->info.ucNumOfPowerModeEntries;
1677 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
1678 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
Alex Deucher02b17cc2010-04-22 13:25:06 -04001679 /* last mode is usually default, array is low to high */
Alex Deucher56278a82009-12-28 13:58:44 -05001680 for (i = 0; i < num_modes; i++) {
1681 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
1682 switch (frev) {
1683 case 1:
1684 rdev->pm.power_state[state_index].num_clock_modes = 1;
1685 rdev->pm.power_state[state_index].clock_info[0].mclk =
1686 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
1687 rdev->pm.power_state[state_index].clock_info[0].sclk =
1688 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
1689 /* skip invalid modes */
1690 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1691 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1692 continue;
Alex Deucher79daedc2010-04-22 14:25:19 -04001693 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05001694 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
1695 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
Alex Deucher84d88f42010-05-27 17:01:42 -04001696 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1697 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
Alex Deucher56278a82009-12-28 13:58:44 -05001698 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1699 VOLTAGE_GPIO;
1700 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1701 radeon_lookup_gpio(rdev,
1702 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
1703 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1704 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1705 true;
1706 else
1707 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1708 false;
1709 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1710 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1711 VOLTAGE_VDDC;
1712 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1713 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
1714 }
Alex Deucherd7311172010-05-03 01:13:14 -04001715 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001716 rdev->pm.power_state[state_index].misc = misc;
Alex Deucher0ec0e742009-12-23 13:21:58 -05001717 /* order matters! */
1718 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1719 rdev->pm.power_state[state_index].type =
1720 POWER_STATE_TYPE_POWERSAVE;
1721 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1722 rdev->pm.power_state[state_index].type =
1723 POWER_STATE_TYPE_BATTERY;
1724 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1725 rdev->pm.power_state[state_index].type =
1726 POWER_STATE_TYPE_BATTERY;
1727 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1728 rdev->pm.power_state[state_index].type =
1729 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001730 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001731 rdev->pm.power_state[state_index].type =
1732 POWER_STATE_TYPE_PERFORMANCE;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001733 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001734 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001735 }
Alex Deucher56278a82009-12-28 13:58:44 -05001736 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001737 rdev->pm.power_state[state_index].type =
1738 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001739 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05001740 rdev->pm.power_state[state_index].default_clock_mode =
1741 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deuchera48b9b42010-04-22 14:03:55 -04001742 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001743 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1744 } else if (state_index == 0) {
1745 rdev->pm.power_state[state_index].clock_info[0].flags |=
1746 RADEON_PM_MODE_NO_DISPLAY;
Alex Deucher56278a82009-12-28 13:58:44 -05001747 }
1748 state_index++;
1749 break;
1750 case 2:
1751 rdev->pm.power_state[state_index].num_clock_modes = 1;
1752 rdev->pm.power_state[state_index].clock_info[0].mclk =
1753 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
1754 rdev->pm.power_state[state_index].clock_info[0].sclk =
1755 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
1756 /* skip invalid modes */
1757 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1758 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1759 continue;
Alex Deucher79daedc2010-04-22 14:25:19 -04001760 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05001761 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
1762 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
1763 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
Alex Deucher84d88f42010-05-27 17:01:42 -04001764 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1765 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
Alex Deucher56278a82009-12-28 13:58:44 -05001766 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1767 VOLTAGE_GPIO;
1768 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1769 radeon_lookup_gpio(rdev,
1770 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
1771 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1772 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1773 true;
1774 else
1775 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1776 false;
1777 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1778 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1779 VOLTAGE_VDDC;
1780 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1781 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
1782 }
Alex Deucherd7311172010-05-03 01:13:14 -04001783 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001784 rdev->pm.power_state[state_index].misc = misc;
1785 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher0ec0e742009-12-23 13:21:58 -05001786 /* order matters! */
1787 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1788 rdev->pm.power_state[state_index].type =
1789 POWER_STATE_TYPE_POWERSAVE;
1790 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1791 rdev->pm.power_state[state_index].type =
1792 POWER_STATE_TYPE_BATTERY;
1793 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1794 rdev->pm.power_state[state_index].type =
1795 POWER_STATE_TYPE_BATTERY;
1796 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1797 rdev->pm.power_state[state_index].type =
1798 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001799 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001800 rdev->pm.power_state[state_index].type =
1801 POWER_STATE_TYPE_PERFORMANCE;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001802 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001803 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001804 }
Alex Deucher0ec0e742009-12-23 13:21:58 -05001805 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1806 rdev->pm.power_state[state_index].type =
1807 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001808 if (misc2 & ATOM_PM_MISCINFO2_MULTI_DISPLAY_SUPPORT)
1809 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001810 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05001811 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001812 rdev->pm.power_state[state_index].type =
1813 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001814 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05001815 rdev->pm.power_state[state_index].default_clock_mode =
1816 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deuchera48b9b42010-04-22 14:03:55 -04001817 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001818 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
1819 } else if (state_index == 0) {
1820 rdev->pm.power_state[state_index].clock_info[0].flags |=
1821 RADEON_PM_MODE_NO_DISPLAY;
Alex Deucher56278a82009-12-28 13:58:44 -05001822 }
1823 state_index++;
1824 break;
1825 case 3:
1826 rdev->pm.power_state[state_index].num_clock_modes = 1;
1827 rdev->pm.power_state[state_index].clock_info[0].mclk =
1828 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
1829 rdev->pm.power_state[state_index].clock_info[0].sclk =
1830 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
1831 /* skip invalid modes */
1832 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
1833 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
1834 continue;
Alex Deucher79daedc2010-04-22 14:25:19 -04001835 rdev->pm.power_state[state_index].pcie_lanes =
Alex Deucher56278a82009-12-28 13:58:44 -05001836 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
1837 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
1838 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
Alex Deucher84d88f42010-05-27 17:01:42 -04001839 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
1840 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
Alex Deucher56278a82009-12-28 13:58:44 -05001841 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1842 VOLTAGE_GPIO;
1843 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
1844 radeon_lookup_gpio(rdev,
1845 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
1846 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
1847 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1848 true;
1849 else
1850 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
1851 false;
1852 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
1853 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
1854 VOLTAGE_VDDC;
1855 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
1856 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
1857 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
1858 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
1859 true;
1860 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
1861 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
1862 }
1863 }
Alex Deucherd7311172010-05-03 01:13:14 -04001864 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001865 rdev->pm.power_state[state_index].misc = misc;
1866 rdev->pm.power_state[state_index].misc2 = misc2;
Alex Deucher0ec0e742009-12-23 13:21:58 -05001867 /* order matters! */
1868 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
1869 rdev->pm.power_state[state_index].type =
1870 POWER_STATE_TYPE_POWERSAVE;
1871 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
1872 rdev->pm.power_state[state_index].type =
1873 POWER_STATE_TYPE_BATTERY;
1874 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
1875 rdev->pm.power_state[state_index].type =
1876 POWER_STATE_TYPE_BATTERY;
1877 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
1878 rdev->pm.power_state[state_index].type =
1879 POWER_STATE_TYPE_BALANCED;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001880 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001881 rdev->pm.power_state[state_index].type =
1882 POWER_STATE_TYPE_PERFORMANCE;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001883 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001884 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001885 }
Alex Deucher0ec0e742009-12-23 13:21:58 -05001886 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
1887 rdev->pm.power_state[state_index].type =
1888 POWER_STATE_TYPE_BALANCED;
Alex Deucher56278a82009-12-28 13:58:44 -05001889 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05001890 rdev->pm.power_state[state_index].type =
1891 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001892 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05001893 rdev->pm.power_state[state_index].default_clock_mode =
1894 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucherd7311172010-05-03 01:13:14 -04001895 } else if (state_index == 0) {
1896 rdev->pm.power_state[state_index].clock_info[0].flags |=
1897 RADEON_PM_MODE_NO_DISPLAY;
Alex Deucher56278a82009-12-28 13:58:44 -05001898 }
1899 state_index++;
1900 break;
1901 }
1902 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04001903 /* last mode is usually default */
Alex Deuchera48b9b42010-04-22 14:03:55 -04001904 if (rdev->pm.default_power_state_index == -1) {
Alex Deucher02b17cc2010-04-22 13:25:06 -04001905 rdev->pm.power_state[state_index - 1].type =
1906 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04001907 rdev->pm.default_power_state_index = state_index - 1;
Alex Deucher02b17cc2010-04-22 13:25:06 -04001908 rdev->pm.power_state[state_index - 1].default_clock_mode =
1909 &rdev->pm.power_state[state_index - 1].clock_info[0];
Alex Deuchera48b9b42010-04-22 14:03:55 -04001910 rdev->pm.power_state[state_index].flags &=
Alex Deucherd7311172010-05-03 01:13:14 -04001911 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher79daedc2010-04-22 14:25:19 -04001912 rdev->pm.power_state[state_index].misc = 0;
1913 rdev->pm.power_state[state_index].misc2 = 0;
Alex Deucher02b17cc2010-04-22 13:25:06 -04001914 }
Alex Deucher49f65982010-03-24 16:39:45 -04001915 } else {
Alex Deucherc5e8ce62010-05-27 17:01:40 -04001916 int fw_index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1917 uint8_t fw_frev, fw_crev;
1918 uint16_t fw_data_offset, vddc = 0;
1919 union firmware_info *firmware_info;
1920 ATOM_PPLIB_THERMALCONTROLLER *controller = &power_info->info_4.sThermalController;
1921
1922 if (atom_parse_data_header(mode_info->atom_context, fw_index, NULL,
1923 &fw_frev, &fw_crev, &fw_data_offset)) {
1924 firmware_info =
1925 (union firmware_info *)(mode_info->atom_context->bios +
1926 fw_data_offset);
1927 vddc = firmware_info->info_14.usBootUpVDDCVoltage;
1928 }
1929
Alex Deucher29fb52c2010-03-11 10:01:17 -05001930 /* add the i2c bus for thermal/fan chip */
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001931 if (controller->ucType > 0) {
Alex Deucher21a81222010-07-02 12:58:16 -04001932 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
Alex Deucher29fb52c2010-03-11 10:01:17 -05001933 DRM_INFO("Internal thermal controller %s fan control\n",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001934 (controller->ucFanParameters &
Alex Deucher29fb52c2010-03-11 10:01:17 -05001935 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
Alex Deucher21a81222010-07-02 12:58:16 -04001936 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
1937 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
1938 DRM_INFO("Internal thermal controller %s fan control\n",
1939 (controller->ucFanParameters &
1940 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
1941 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
1942 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
1943 DRM_INFO("Internal thermal controller %s fan control\n",
1944 (controller->ucFanParameters &
1945 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
1946 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001947 } else if ((controller->ucType ==
Alex Deucher49f65982010-03-24 16:39:45 -04001948 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001949 (controller->ucType ==
Alex Deucher49f65982010-03-24 16:39:45 -04001950 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL)) {
1951 DRM_INFO("Special thermal controller config\n");
Alex Deucher29fb52c2010-03-11 10:01:17 -05001952 } else {
1953 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001954 pp_lib_thermal_controller_names[controller->ucType],
1955 controller->ucI2cAddress >> 1,
1956 (controller->ucFanParameters &
Alex Deucher29fb52c2010-03-11 10:01:17 -05001957 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001958 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
Alex Deucherf376b942010-08-05 21:21:16 -04001959 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001960 if (rdev->pm.i2c_bus) {
1961 struct i2c_board_info info = { };
1962 const char *name = pp_lib_thermal_controller_names[controller->ucType];
1963 info.addr = controller->ucI2cAddress >> 1;
1964 strlcpy(info.type, name, sizeof(info.type));
1965 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
1966 }
1967
Alex Deucher29fb52c2010-03-11 10:01:17 -05001968 }
1969 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04001970 /* first mode is usually default, followed by low to high */
Alex Deucher56278a82009-12-28 13:58:44 -05001971 for (i = 0; i < power_info->info_4.ucNumStates; i++) {
1972 mode_index = 0;
1973 power_state = (struct _ATOM_PPLIB_STATE *)
1974 (mode_info->atom_context->bios +
1975 data_offset +
1976 le16_to_cpu(power_info->info_4.usStateArrayOffset) +
1977 i * power_info->info_4.ucStateEntrySize);
1978 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
1979 (mode_info->atom_context->bios +
1980 data_offset +
1981 le16_to_cpu(power_info->info_4.usNonClockInfoArrayOffset) +
1982 (power_state->ucNonClockStateIndex *
1983 power_info->info_4.ucNonClockSize));
Alex Deucher56278a82009-12-28 13:58:44 -05001984 for (j = 0; j < (power_info->info_4.ucStateEntrySize - 1); j++) {
1985 if (rdev->flags & RADEON_IS_IGP) {
1986 struct _ATOM_PPLIB_RS780_CLOCK_INFO *clock_info =
1987 (struct _ATOM_PPLIB_RS780_CLOCK_INFO *)
1988 (mode_info->atom_context->bios +
1989 data_offset +
1990 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
1991 (power_state->ucClockStateIndices[j] *
1992 power_info->info_4.ucClockInfoSize));
1993 sclk = le16_to_cpu(clock_info->usLowEngineClockLow);
1994 sclk |= clock_info->ucLowEngineClockHigh << 16;
1995 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
1996 /* skip invalid modes */
1997 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
1998 continue;
Alex Deucheraa1df0f2010-06-07 11:35:53 -04001999 /* voltage works differently on IGPs */
Alex Deucher56278a82009-12-28 13:58:44 -05002000 mode_index++;
Alex Deucher49f65982010-03-24 16:39:45 -04002001 } else if (ASIC_IS_DCE4(rdev)) {
2002 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *clock_info =
2003 (struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO *)
2004 (mode_info->atom_context->bios +
2005 data_offset +
2006 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2007 (power_state->ucClockStateIndices[j] *
2008 power_info->info_4.ucClockInfoSize));
2009 sclk = le16_to_cpu(clock_info->usEngineClockLow);
2010 sclk |= clock_info->ucEngineClockHigh << 16;
2011 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
2012 mclk |= clock_info->ucMemoryClockHigh << 16;
2013 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2014 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2015 /* skip invalid modes */
2016 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2017 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2018 continue;
Alex Deucher49f65982010-03-24 16:39:45 -04002019 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2020 VOLTAGE_SW;
2021 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2022 clock_info->usVDDC;
2023 /* XXX usVDDCI */
2024 mode_index++;
Alex Deucher56278a82009-12-28 13:58:44 -05002025 } else {
2026 struct _ATOM_PPLIB_R600_CLOCK_INFO *clock_info =
2027 (struct _ATOM_PPLIB_R600_CLOCK_INFO *)
2028 (mode_info->atom_context->bios +
2029 data_offset +
2030 le16_to_cpu(power_info->info_4.usClockInfoArrayOffset) +
2031 (power_state->ucClockStateIndices[j] *
2032 power_info->info_4.ucClockInfoSize));
2033 sclk = le16_to_cpu(clock_info->usEngineClockLow);
2034 sclk |= clock_info->ucEngineClockHigh << 16;
2035 mclk = le16_to_cpu(clock_info->usMemoryClockLow);
2036 mclk |= clock_info->ucMemoryClockHigh << 16;
2037 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2038 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2039 /* skip invalid modes */
2040 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2041 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2042 continue;
Alex Deucher56278a82009-12-28 13:58:44 -05002043 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2044 VOLTAGE_SW;
2045 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2046 clock_info->usVDDC;
2047 mode_index++;
2048 }
2049 }
2050 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2051 if (mode_index) {
Rafał Miłecki845db702009-12-23 00:42:43 +01002052 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
Alex Deucher56278a82009-12-28 13:58:44 -05002053 misc2 = le16_to_cpu(non_clock_info->usClassification);
Alex Deucher79daedc2010-04-22 14:25:19 -04002054 rdev->pm.power_state[state_index].misc = misc;
2055 rdev->pm.power_state[state_index].misc2 = misc2;
2056 rdev->pm.power_state[state_index].pcie_lanes =
Rafał Miłecki845db702009-12-23 00:42:43 +01002057 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2058 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002059 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2060 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2061 rdev->pm.power_state[state_index].type =
2062 POWER_STATE_TYPE_BATTERY;
2063 break;
2064 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2065 rdev->pm.power_state[state_index].type =
2066 POWER_STATE_TYPE_BALANCED;
2067 break;
2068 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2069 rdev->pm.power_state[state_index].type =
2070 POWER_STATE_TYPE_PERFORMANCE;
2071 break;
Alex Deuchera44d2f32010-08-04 11:10:26 -04002072 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2073 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2074 rdev->pm.power_state[state_index].type =
2075 POWER_STATE_TYPE_PERFORMANCE;
2076 break;
Alex Deucher0ec0e742009-12-23 13:21:58 -05002077 }
Alex Deuchera48b9b42010-04-22 14:03:55 -04002078 rdev->pm.power_state[state_index].flags = 0;
2079 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2080 rdev->pm.power_state[state_index].flags |=
Alex Deucherd7311172010-05-03 01:13:14 -04002081 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
Alex Deucher56278a82009-12-28 13:58:44 -05002082 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
Alex Deucher0ec0e742009-12-23 13:21:58 -05002083 rdev->pm.power_state[state_index].type =
2084 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002085 rdev->pm.default_power_state_index = state_index;
Alex Deucher56278a82009-12-28 13:58:44 -05002086 rdev->pm.power_state[state_index].default_clock_mode =
2087 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
Alex Deucherc5e8ce62010-05-27 17:01:40 -04002088 /* patch the table values with the default slck/mclk from firmware info */
2089 for (j = 0; j < mode_index; j++) {
2090 rdev->pm.power_state[state_index].clock_info[j].mclk =
2091 rdev->clock.default_mclk;
2092 rdev->pm.power_state[state_index].clock_info[j].sclk =
2093 rdev->clock.default_sclk;
2094 if (vddc)
2095 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2096 vddc;
2097 }
Alex Deucher56278a82009-12-28 13:58:44 -05002098 }
2099 state_index++;
2100 }
2101 }
Alex Deucherd7311172010-05-03 01:13:14 -04002102 /* if multiple clock modes, mark the lowest as no display */
2103 for (i = 0; i < state_index; i++) {
2104 if (rdev->pm.power_state[i].num_clock_modes > 1)
2105 rdev->pm.power_state[i].clock_info[0].flags |=
2106 RADEON_PM_MODE_NO_DISPLAY;
2107 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002108 /* first mode is usually default */
Alex Deuchera48b9b42010-04-22 14:03:55 -04002109 if (rdev->pm.default_power_state_index == -1) {
Alex Deucher02b17cc2010-04-22 13:25:06 -04002110 rdev->pm.power_state[0].type =
2111 POWER_STATE_TYPE_DEFAULT;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002112 rdev->pm.default_power_state_index = 0;
Alex Deucher02b17cc2010-04-22 13:25:06 -04002113 rdev->pm.power_state[0].default_clock_mode =
2114 &rdev->pm.power_state[0].clock_info[0];
2115 }
Alex Deucher56278a82009-12-28 13:58:44 -05002116 }
2117 } else {
Alex Deucher56278a82009-12-28 13:58:44 -05002118 /* add the default mode */
Alex Deucher0ec0e742009-12-23 13:21:58 -05002119 rdev->pm.power_state[state_index].type =
2120 POWER_STATE_TYPE_DEFAULT;
Alex Deucher56278a82009-12-28 13:58:44 -05002121 rdev->pm.power_state[state_index].num_clock_modes = 1;
2122 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2123 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2124 rdev->pm.power_state[state_index].default_clock_mode =
2125 &rdev->pm.power_state[state_index].clock_info[0];
Alex Deucher56278a82009-12-28 13:58:44 -05002126 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
Alex Deucher79daedc2010-04-22 14:25:19 -04002127 rdev->pm.power_state[state_index].pcie_lanes = 16;
Alex Deuchera48b9b42010-04-22 14:03:55 -04002128 rdev->pm.default_power_state_index = state_index;
2129 rdev->pm.power_state[state_index].flags = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002130 state_index++;
2131 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002132
Alex Deucher56278a82009-12-28 13:58:44 -05002133 rdev->pm.num_power_states = state_index;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002134
Alex Deuchera48b9b42010-04-22 14:03:55 -04002135 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2136 rdev->pm.current_clock_mode_index = 0;
Alex Deucher4d601732010-06-07 18:15:18 -04002137 rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
Alex Deucher56278a82009-12-28 13:58:44 -05002138}
2139
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002140void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2141{
2142 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2143 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2144
2145 args.ucEnable = enable;
2146
2147 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2148}
2149
Rafał Miłecki74338742009-11-03 00:53:02 +01002150uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2151{
2152 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2153 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2154
2155 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2156 return args.ulReturnEngineClock;
2157}
2158
2159uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2160{
2161 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2162 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2163
2164 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2165 return args.ulReturnMemoryClock;
2166}
2167
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002168void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2169 uint32_t eng_clock)
2170{
2171 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2172 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2173
2174 args.ulTargetEngineClock = eng_clock; /* 10 khz */
2175
2176 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2177}
2178
2179void radeon_atom_set_memory_clock(struct radeon_device *rdev,
2180 uint32_t mem_clock)
2181{
2182 SET_MEMORY_CLOCK_PS_ALLOCATION args;
2183 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
2184
2185 if (rdev->flags & RADEON_IS_IGP)
2186 return;
2187
2188 args.ulTargetMemoryClock = mem_clock; /* 10 khz */
2189
2190 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2191}
2192
Alex Deucher7ac9aa52010-05-27 19:25:54 -04002193union set_voltage {
2194 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2195 struct _SET_VOLTAGE_PARAMETERS v1;
2196 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2197};
2198
2199void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level)
2200{
2201 union set_voltage args;
2202 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
2203 u8 frev, crev, volt_index = level;
2204
2205 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2206 return;
2207
2208 switch (crev) {
2209 case 1:
2210 args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2211 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
2212 args.v1.ucVoltageIndex = volt_index;
2213 break;
2214 case 2:
2215 args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC;
2216 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
2217 args.v2.usVoltageLevel = cpu_to_le16(level);
2218 break;
2219 default:
2220 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2221 return;
2222 }
2223
2224 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2225}
2226
2227
2228
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002229void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
2230{
2231 struct radeon_device *rdev = dev->dev_private;
2232 uint32_t bios_2_scratch, bios_6_scratch;
2233
2234 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002235 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002236 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2237 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10002238 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002239 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2240 }
2241
2242 /* let the bios control the backlight */
2243 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
2244
2245 /* tell the bios not to handle mode switching */
2246 bios_6_scratch |= (ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH | ATOM_S6_ACC_MODE);
2247
2248 if (rdev->family >= CHIP_R600) {
2249 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2250 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2251 } else {
2252 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2253 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2254 }
2255
2256}
2257
Yang Zhaof657c2a2009-09-15 12:21:01 +10002258void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
2259{
2260 uint32_t scratch_reg;
2261 int i;
2262
2263 if (rdev->family >= CHIP_R600)
2264 scratch_reg = R600_BIOS_0_SCRATCH;
2265 else
2266 scratch_reg = RADEON_BIOS_0_SCRATCH;
2267
2268 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2269 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
2270}
2271
2272void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
2273{
2274 uint32_t scratch_reg;
2275 int i;
2276
2277 if (rdev->family >= CHIP_R600)
2278 scratch_reg = R600_BIOS_0_SCRATCH;
2279 else
2280 scratch_reg = RADEON_BIOS_0_SCRATCH;
2281
2282 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
2283 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
2284}
2285
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002286void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
2287{
2288 struct drm_device *dev = encoder->dev;
2289 struct radeon_device *rdev = dev->dev_private;
2290 uint32_t bios_6_scratch;
2291
2292 if (rdev->family >= CHIP_R600)
2293 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2294 else
2295 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2296
2297 if (lock)
2298 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
2299 else
2300 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
2301
2302 if (rdev->family >= CHIP_R600)
2303 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2304 else
2305 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2306}
2307
2308/* at some point we may want to break this out into individual functions */
2309void
2310radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
2311 struct drm_encoder *encoder,
2312 bool connected)
2313{
2314 struct drm_device *dev = connector->dev;
2315 struct radeon_device *rdev = dev->dev_private;
2316 struct radeon_connector *radeon_connector =
2317 to_radeon_connector(connector);
2318 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2319 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
2320
2321 if (rdev->family >= CHIP_R600) {
2322 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2323 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2324 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
2325 } else {
2326 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2327 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2328 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
2329 }
2330
2331 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
2332 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
2333 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002334 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002335 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
2336 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
2337 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002338 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002339 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
2340 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
2341 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
2342 }
2343 }
2344 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
2345 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
2346 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002347 DRM_DEBUG_KMS("CV connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002348 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
2349 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
2350 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002351 DRM_DEBUG_KMS("CV disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002352 bios_0_scratch &= ~ATOM_S0_CV_MASK;
2353 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
2354 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
2355 }
2356 }
2357 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
2358 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
2359 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002360 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002361 bios_0_scratch |= ATOM_S0_LCD1;
2362 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
2363 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
2364 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002365 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002366 bios_0_scratch &= ~ATOM_S0_LCD1;
2367 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
2368 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
2369 }
2370 }
2371 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
2372 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
2373 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002374 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002375 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
2376 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
2377 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
2378 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002379 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002380 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
2381 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
2382 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
2383 }
2384 }
2385 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
2386 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
2387 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002388 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002389 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
2390 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
2391 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
2392 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002393 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002394 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
2395 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
2396 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
2397 }
2398 }
2399 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
2400 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
2401 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002402 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002403 bios_0_scratch |= ATOM_S0_DFP1;
2404 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
2405 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
2406 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002407 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002408 bios_0_scratch &= ~ATOM_S0_DFP1;
2409 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
2410 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
2411 }
2412 }
2413 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
2414 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
2415 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002416 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002417 bios_0_scratch |= ATOM_S0_DFP2;
2418 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
2419 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
2420 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002421 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002422 bios_0_scratch &= ~ATOM_S0_DFP2;
2423 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
2424 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
2425 }
2426 }
2427 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
2428 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
2429 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002430 DRM_DEBUG_KMS("DFP3 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002431 bios_0_scratch |= ATOM_S0_DFP3;
2432 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
2433 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
2434 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002435 DRM_DEBUG_KMS("DFP3 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002436 bios_0_scratch &= ~ATOM_S0_DFP3;
2437 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
2438 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
2439 }
2440 }
2441 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
2442 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
2443 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002444 DRM_DEBUG_KMS("DFP4 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002445 bios_0_scratch |= ATOM_S0_DFP4;
2446 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
2447 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
2448 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002449 DRM_DEBUG_KMS("DFP4 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002450 bios_0_scratch &= ~ATOM_S0_DFP4;
2451 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
2452 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
2453 }
2454 }
2455 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
2456 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
2457 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002458 DRM_DEBUG_KMS("DFP5 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002459 bios_0_scratch |= ATOM_S0_DFP5;
2460 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
2461 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
2462 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10002463 DRM_DEBUG_KMS("DFP5 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002464 bios_0_scratch &= ~ATOM_S0_DFP5;
2465 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2466 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2467 }
2468 }
2469
2470 if (rdev->family >= CHIP_R600) {
2471 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2472 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2473 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
2474 } else {
2475 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
2476 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2477 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
2478 }
2479}
2480
2481void
2482radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
2483{
2484 struct drm_device *dev = encoder->dev;
2485 struct radeon_device *rdev = dev->dev_private;
2486 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2487 uint32_t bios_3_scratch;
2488
2489 if (rdev->family >= CHIP_R600)
2490 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2491 else
2492 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
2493
2494 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2495 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
2496 bios_3_scratch |= (crtc << 18);
2497 }
2498 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2499 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
2500 bios_3_scratch |= (crtc << 24);
2501 }
2502 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2503 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
2504 bios_3_scratch |= (crtc << 16);
2505 }
2506 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2507 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
2508 bios_3_scratch |= (crtc << 20);
2509 }
2510 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2511 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
2512 bios_3_scratch |= (crtc << 17);
2513 }
2514 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2515 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
2516 bios_3_scratch |= (crtc << 19);
2517 }
2518 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2519 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
2520 bios_3_scratch |= (crtc << 23);
2521 }
2522 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2523 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
2524 bios_3_scratch |= (crtc << 25);
2525 }
2526
2527 if (rdev->family >= CHIP_R600)
2528 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
2529 else
2530 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
2531}
2532
2533void
2534radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
2535{
2536 struct drm_device *dev = encoder->dev;
2537 struct radeon_device *rdev = dev->dev_private;
2538 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2539 uint32_t bios_2_scratch;
2540
2541 if (rdev->family >= CHIP_R600)
2542 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2543 else
2544 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
2545
2546 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
2547 if (on)
2548 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
2549 else
2550 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
2551 }
2552 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
2553 if (on)
2554 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
2555 else
2556 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
2557 }
2558 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2559 if (on)
2560 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
2561 else
2562 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
2563 }
2564 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2565 if (on)
2566 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
2567 else
2568 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
2569 }
2570 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
2571 if (on)
2572 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
2573 else
2574 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
2575 }
2576 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
2577 if (on)
2578 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
2579 else
2580 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
2581 }
2582 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
2583 if (on)
2584 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
2585 else
2586 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
2587 }
2588 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
2589 if (on)
2590 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
2591 else
2592 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
2593 }
2594 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
2595 if (on)
2596 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
2597 else
2598 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
2599 }
2600 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
2601 if (on)
2602 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
2603 else
2604 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
2605 }
2606
2607 if (rdev->family >= CHIP_R600)
2608 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
2609 else
2610 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
2611}