blob: 5f3b041330d62ea0d8840f7b07f670ec972915fc [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 */
David Howells760285e2012-10-02 18:01:07 +010026#include <drm/drmP.h>
27#include <drm/radeon_drm.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020028#include "radeon.h"
29
30#include "atom.h"
31#include "atom-bits.h"
32
Jerome Glisse771fe6b2009-06-05 14:42:42 +020033extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040034radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
Alex Deucher36868bd2011-01-06 21:19:21 -050035 uint32_t supported_device, u16 caps);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020036
Jerome Glisse771fe6b2009-06-05 14:42:42 +020037/* from radeon_legacy_encoder.c */
38extern void
Alex Deucher5137ee92010-08-12 18:58:47 -040039radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
Jerome Glisse771fe6b2009-06-05 14:42:42 +020040 uint32_t supported_device);
41
42union atom_supported_devices {
43 struct _ATOM_SUPPORTED_DEVICES_INFO info;
44 struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
45 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
46};
47
Alex Deucher21240f92011-11-21 12:41:21 -050048static void radeon_lookup_i2c_gpio_quirks(struct radeon_device *rdev,
49 ATOM_GPIO_I2C_ASSIGMENT *gpio,
50 u8 index)
51{
52 /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
53 if ((rdev->family == CHIP_R420) ||
54 (rdev->family == CHIP_R423) ||
55 (rdev->family == CHIP_RV410)) {
56 if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
57 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
58 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
59 gpio->ucClkMaskShift = 0x19;
60 gpio->ucDataMaskShift = 0x18;
61 }
62 }
63
64 /* some evergreen boards have bad data for this entry */
65 if (ASIC_IS_DCE4(rdev)) {
66 if ((index == 7) &&
67 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
68 (gpio->sucI2cId.ucAccess == 0)) {
69 gpio->sucI2cId.ucAccess = 0x97;
70 gpio->ucDataMaskShift = 8;
71 gpio->ucDataEnShift = 8;
72 gpio->ucDataY_Shift = 8;
73 gpio->ucDataA_Shift = 8;
74 }
75 }
76
77 /* some DCE3 boards have bad data for this entry */
78 if (ASIC_IS_DCE3(rdev)) {
79 if ((index == 4) &&
80 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
81 (gpio->sucI2cId.ucAccess == 0x94))
82 gpio->sucI2cId.ucAccess = 0x14;
83 }
84}
85
86static struct radeon_i2c_bus_rec radeon_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio)
87{
88 struct radeon_i2c_bus_rec i2c;
89
90 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
91
92 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
93 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
94 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
95 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
96 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
97 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
98 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
99 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
100 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
101 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
102 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
103 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
104 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
105 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
106 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
107 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
108
109 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
110 i2c.hw_capable = true;
111 else
112 i2c.hw_capable = false;
113
114 if (gpio->sucI2cId.ucAccess == 0xa0)
115 i2c.mm_i2c = true;
116 else
117 i2c.mm_i2c = false;
118
119 i2c.i2c_id = gpio->sucI2cId.ucAccess;
120
121 if (i2c.mask_clk_reg)
122 i2c.valid = true;
123 else
124 i2c.valid = false;
125
126 return i2c;
127}
128
Andi Kleence580fa2011-10-13 16:08:47 -0700129static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
Alex Deuchereed45b32009-12-04 14:45:27 -0500130 uint8_t id)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200131{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200132 struct atom_context *ctx = rdev->mode_info.atom_context;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500133 ATOM_GPIO_I2C_ASSIGMENT *gpio;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200134 struct radeon_i2c_bus_rec i2c;
135 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
136 struct _ATOM_GPIO_I2C_INFO *i2c_info;
Alex Deucher95beb692010-04-01 19:08:47 +0000137 uint16_t data_offset, size;
138 int i, num_indices;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200139
140 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
141 i2c.valid = false;
142
Alex Deucher95beb692010-04-01 19:08:47 +0000143 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
Alex Deuchera084e6e2010-03-18 01:04:01 -0400144 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200145
Alex Deucher95beb692010-04-01 19:08:47 +0000146 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
147 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
148
Alex Deucher607f2c22013-08-20 18:40:46 -0400149 gpio = &i2c_info->asGPIO_Info[0];
Alex Deucher95beb692010-04-01 19:08:47 +0000150 for (i = 0; i < num_indices; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200151
Alex Deucher21240f92011-11-21 12:41:21 -0500152 radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
Alex Deucher3074adc2010-11-30 00:15:10 -0500153
Alex Deuchera084e6e2010-03-18 01:04:01 -0400154 if (gpio->sucI2cId.ucAccess == id) {
Alex Deucher21240f92011-11-21 12:41:21 -0500155 i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
Alex Deuchera084e6e2010-03-18 01:04:01 -0400156 break;
157 }
Alex Deucher607f2c22013-08-20 18:40:46 -0400158 gpio = (ATOM_GPIO_I2C_ASSIGMENT *)
159 ((u8 *)gpio + sizeof(ATOM_GPIO_I2C_ASSIGMENT));
Alex Deucherd3f420d2009-12-08 14:30:49 -0500160 }
161 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200162
163 return i2c;
164}
165
Alex Deucherf376b942010-08-05 21:21:16 -0400166void radeon_atombios_i2c_init(struct radeon_device *rdev)
167{
168 struct atom_context *ctx = rdev->mode_info.atom_context;
169 ATOM_GPIO_I2C_ASSIGMENT *gpio;
170 struct radeon_i2c_bus_rec i2c;
171 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
172 struct _ATOM_GPIO_I2C_INFO *i2c_info;
173 uint16_t data_offset, size;
174 int i, num_indices;
175 char stmp[32];
176
Alex Deucherf376b942010-08-05 21:21:16 -0400177 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
178 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
179
180 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
181 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
182
Alex Deucher607f2c22013-08-20 18:40:46 -0400183 gpio = &i2c_info->asGPIO_Info[0];
Alex Deucherf376b942010-08-05 21:21:16 -0400184 for (i = 0; i < num_indices; i++) {
Alex Deucher21240f92011-11-21 12:41:21 -0500185 radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
Alex Deucherd7245022011-11-21 12:10:14 -0500186
Alex Deucher21240f92011-11-21 12:41:21 -0500187 i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
Alex Deucherea393022010-08-27 16:04:29 -0400188
Alex Deucher21240f92011-11-21 12:41:21 -0500189 if (i2c.valid) {
Alex Deucherf376b942010-08-05 21:21:16 -0400190 sprintf(stmp, "0x%x", i2c.i2c_id);
191 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
192 }
Alex Deucher607f2c22013-08-20 18:40:46 -0400193 gpio = (ATOM_GPIO_I2C_ASSIGMENT *)
194 ((u8 *)gpio + sizeof(ATOM_GPIO_I2C_ASSIGMENT));
Alex Deucherf376b942010-08-05 21:21:16 -0400195 }
196 }
197}
198
Andi Kleence580fa2011-10-13 16:08:47 -0700199static struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
Alex Deuchercc8dbbb2013-08-14 01:03:41 -0400200 u8 id)
Alex Deuchereed45b32009-12-04 14:45:27 -0500201{
202 struct atom_context *ctx = rdev->mode_info.atom_context;
203 struct radeon_gpio_rec gpio;
204 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
205 struct _ATOM_GPIO_PIN_LUT *gpio_info;
206 ATOM_GPIO_PIN_ASSIGNMENT *pin;
207 u16 data_offset, size;
208 int i, num_indices;
209
210 memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
211 gpio.valid = false;
212
Alex Deuchera084e6e2010-03-18 01:04:01 -0400213 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
214 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
Alex Deuchereed45b32009-12-04 14:45:27 -0500215
Alex Deuchera084e6e2010-03-18 01:04:01 -0400216 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
217 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
Alex Deuchereed45b32009-12-04 14:45:27 -0500218
Alex Deucher607f2c22013-08-20 18:40:46 -0400219 pin = gpio_info->asGPIO_Pin;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400220 for (i = 0; i < num_indices; i++) {
Alex Deuchera084e6e2010-03-18 01:04:01 -0400221 if (id == pin->ucGPIO_ID) {
222 gpio.id = pin->ucGPIO_ID;
Cédric Cano45894332011-02-11 19:45:37 -0500223 gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex) * 4;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400224 gpio.mask = (1 << pin->ucGpioPinBitShift);
225 gpio.valid = true;
226 break;
227 }
Alex Deucher607f2c22013-08-20 18:40:46 -0400228 pin = (ATOM_GPIO_PIN_ASSIGNMENT *)
229 ((u8 *)pin + sizeof(ATOM_GPIO_PIN_ASSIGNMENT));
Alex Deuchereed45b32009-12-04 14:45:27 -0500230 }
231 }
232
233 return gpio;
234}
235
236static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
237 struct radeon_gpio_rec *gpio)
238{
239 struct radeon_hpd hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500240 u32 reg;
241
Jean Delvare1d978da2010-08-15 14:11:24 +0200242 memset(&hpd, 0, sizeof(struct radeon_hpd));
243
Alex Deucher82d118e2012-03-20 17:18:01 -0400244 if (ASIC_IS_DCE6(rdev))
245 reg = SI_DC_GPIO_HPD_A;
246 else if (ASIC_IS_DCE4(rdev))
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500247 reg = EVERGREEN_DC_GPIO_HPD_A;
248 else
249 reg = AVIVO_DC_GPIO_HPD_A;
250
Alex Deuchereed45b32009-12-04 14:45:27 -0500251 hpd.gpio = *gpio;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500252 if (gpio->reg == reg) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500253 switch(gpio->mask) {
254 case (1 << 0):
255 hpd.hpd = RADEON_HPD_1;
256 break;
257 case (1 << 8):
258 hpd.hpd = RADEON_HPD_2;
259 break;
260 case (1 << 16):
261 hpd.hpd = RADEON_HPD_3;
262 break;
263 case (1 << 24):
264 hpd.hpd = RADEON_HPD_4;
265 break;
266 case (1 << 26):
267 hpd.hpd = RADEON_HPD_5;
268 break;
269 case (1 << 28):
270 hpd.hpd = RADEON_HPD_6;
271 break;
272 default:
273 hpd.hpd = RADEON_HPD_NONE;
274 break;
275 }
276 } else
277 hpd.hpd = RADEON_HPD_NONE;
278 return hpd;
279}
280
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200281static bool radeon_atom_apply_quirks(struct drm_device *dev,
282 uint32_t supported_device,
283 int *connector_type,
Alex Deucher848577e2009-07-08 16:15:30 -0400284 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -0500285 uint16_t *line_mux,
286 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200287{
288
289 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
290 if ((dev->pdev->device == 0x791e) &&
291 (dev->pdev->subsystem_vendor == 0x1043) &&
292 (dev->pdev->subsystem_device == 0x826d)) {
293 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
294 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
295 *connector_type = DRM_MODE_CONNECTOR_DVID;
296 }
297
Alex Deucherc86a9032010-02-18 14:14:58 -0500298 /* Asrock RS600 board lists the DVI port as HDMI */
299 if ((dev->pdev->device == 0x7941) &&
300 (dev->pdev->subsystem_vendor == 0x1849) &&
301 (dev->pdev->subsystem_device == 0x7941)) {
302 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
303 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
304 *connector_type = DRM_MODE_CONNECTOR_DVID;
305 }
306
Alex Deucherf36fce02010-09-27 11:33:00 -0400307 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
308 if ((dev->pdev->device == 0x796e) &&
309 (dev->pdev->subsystem_vendor == 0x1462) &&
310 (dev->pdev->subsystem_device == 0x7302)) {
311 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
312 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
313 return false;
314 }
315
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200316 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
317 if ((dev->pdev->device == 0x7941) &&
318 (dev->pdev->subsystem_vendor == 0x147b) &&
319 (dev->pdev->subsystem_device == 0x2412)) {
320 if (*connector_type == DRM_MODE_CONNECTOR_DVII)
321 return false;
322 }
323
324 /* Falcon NW laptop lists vga ddc line for LVDS */
325 if ((dev->pdev->device == 0x5653) &&
326 (dev->pdev->subsystem_vendor == 0x1462) &&
327 (dev->pdev->subsystem_device == 0x0291)) {
Alex Deucher848577e2009-07-08 16:15:30 -0400328 if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200329 i2c_bus->valid = false;
Alex Deucher848577e2009-07-08 16:15:30 -0400330 *line_mux = 53;
331 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200332 }
333
Alex Deucher4e3f9b782009-12-01 14:49:50 -0500334 /* HIS X1300 is DVI+VGA, not DVI+DVI */
335 if ((dev->pdev->device == 0x7146) &&
336 (dev->pdev->subsystem_vendor == 0x17af) &&
337 (dev->pdev->subsystem_device == 0x2058)) {
338 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
339 return false;
340 }
341
Dave Airlieaa1a7502009-12-04 11:51:34 +1000342 /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
343 if ((dev->pdev->device == 0x7142) &&
344 (dev->pdev->subsystem_vendor == 0x1458) &&
345 (dev->pdev->subsystem_device == 0x2134)) {
346 if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
347 return false;
348 }
349
350
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200351 /* Funky macbooks */
352 if ((dev->pdev->device == 0x71C5) &&
353 (dev->pdev->subsystem_vendor == 0x106b) &&
354 (dev->pdev->subsystem_device == 0x0080)) {
355 if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
356 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
357 return false;
Alex Deuchere1e8a5d2010-03-26 17:14:37 -0400358 if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
359 *line_mux = 0x90;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200360 }
361
Alex Deucherbe23da82011-01-18 18:26:11 +0000362 /* mac rv630, rv730, others */
363 if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
364 (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
365 *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
366 *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
Alex Deucherf598aa72011-01-04 00:43:39 -0500367 }
368
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200369 /* ASUS HD 3600 XT board lists the DVI port as HDMI */
370 if ((dev->pdev->device == 0x9598) &&
371 (dev->pdev->subsystem_vendor == 0x1043) &&
372 (dev->pdev->subsystem_device == 0x01da)) {
Alex Deucher705af9c2009-09-10 16:31:13 -0400373 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400374 *connector_type = DRM_MODE_CONNECTOR_DVII;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200375 }
376 }
377
Alex Deuchere153b702010-07-20 18:07:22 -0400378 /* ASUS HD 3600 board lists the DVI port as HDMI */
379 if ((dev->pdev->device == 0x9598) &&
380 (dev->pdev->subsystem_vendor == 0x1043) &&
381 (dev->pdev->subsystem_device == 0x01e4)) {
382 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
383 *connector_type = DRM_MODE_CONNECTOR_DVII;
384 }
385 }
386
Alex Deucher705af9c2009-09-10 16:31:13 -0400387 /* ASUS HD 3450 board lists the DVI port as HDMI */
388 if ((dev->pdev->device == 0x95C5) &&
389 (dev->pdev->subsystem_vendor == 0x1043) &&
390 (dev->pdev->subsystem_device == 0x01e2)) {
391 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
Alex Deucherd42571e2009-09-11 15:27:14 -0400392 *connector_type = DRM_MODE_CONNECTOR_DVII;
Alex Deucher705af9c2009-09-10 16:31:13 -0400393 }
394 }
395
396 /* some BIOSes seem to report DAC on HDMI - usually this is a board with
397 * HDMI + VGA reporting as HDMI
398 */
399 if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
400 if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
401 *connector_type = DRM_MODE_CONNECTOR_VGA;
402 *line_mux = 0;
403 }
404 }
405
Alex Deucher4f87af42011-05-04 11:41:47 -0400406 /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port
Alex Deucher2f299d52011-01-04 17:42:20 -0500407 * on the laptop and a DVI port on the docking station and
408 * both share the same encoder, hpd pin, and ddc line.
409 * So while the bios table is technically correct,
410 * we drop the DVI port here since xrandr has no concept of
411 * encoders and will try and drive both connectors
412 * with different crtcs which isn't possible on the hardware
413 * side and leaves no crtcs for LVDS or VGA.
414 */
Alex Deucher4f87af42011-05-04 11:41:47 -0400415 if (((dev->pdev->device == 0x95c4) || (dev->pdev->device == 0x9591)) &&
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500416 (dev->pdev->subsystem_vendor == 0x1025) &&
417 (dev->pdev->subsystem_device == 0x013c)) {
418 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400419 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
Alex Deucher2f299d52011-01-04 17:42:20 -0500420 /* actually it's a DVI-D port not DVI-I */
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500421 *connector_type = DRM_MODE_CONNECTOR_DVID;
Alex Deucher2f299d52011-01-04 17:42:20 -0500422 return false;
Alex Deucher9ea2c4b2010-08-06 00:27:44 -0400423 }
Alex Deucher3e5f8ff2009-11-17 17:12:10 -0500424 }
425
Dave Airlieefa84502010-02-09 09:06:00 +1000426 /* XFX Pine Group device rv730 reports no VGA DDC lines
427 * even though they are wired up to record 0x93
428 */
429 if ((dev->pdev->device == 0x9498) &&
430 (dev->pdev->subsystem_vendor == 0x1682) &&
Alex Deucher1ebf1692012-05-23 11:48:59 -0400431 (dev->pdev->subsystem_device == 0x2452) &&
432 (i2c_bus->valid == false) &&
433 !(supported_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))) {
Dave Airlieefa84502010-02-09 09:06:00 +1000434 struct radeon_device *rdev = dev->dev_private;
435 *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
436 }
Alex Deucher4c1b2d22012-03-16 12:22:10 -0400437
438 /* Fujitsu D3003-S2 board lists DVI-I as DVI-D and VGA */
Tvrtko Ursulin52e9b392012-08-20 15:16:04 +0100439 if (((dev->pdev->device == 0x9802) || (dev->pdev->device == 0x9806)) &&
Alex Deucher4c1b2d22012-03-16 12:22:10 -0400440 (dev->pdev->subsystem_vendor == 0x1734) &&
441 (dev->pdev->subsystem_device == 0x11bd)) {
442 if (*connector_type == DRM_MODE_CONNECTOR_VGA) {
443 *connector_type = DRM_MODE_CONNECTOR_DVII;
444 *line_mux = 0x3103;
445 } else if (*connector_type == DRM_MODE_CONNECTOR_DVID) {
446 *connector_type = DRM_MODE_CONNECTOR_DVII;
447 }
448 }
449
Alex Deucher1952f242014-09-08 13:55:51 -0400450 /* Fujitsu D3003-S2 board lists DVI-I as DVI-I and VGA */
451 if ((dev->pdev->device == 0x9805) &&
452 (dev->pdev->subsystem_vendor == 0x1734) &&
453 (dev->pdev->subsystem_device == 0x11bd)) {
454 if (*connector_type == DRM_MODE_CONNECTOR_VGA)
455 return false;
456 }
Alex Deucher4c1b2d22012-03-16 12:22:10 -0400457
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200458 return true;
459}
460
461const int supported_devices_connector_convert[] = {
462 DRM_MODE_CONNECTOR_Unknown,
463 DRM_MODE_CONNECTOR_VGA,
464 DRM_MODE_CONNECTOR_DVII,
465 DRM_MODE_CONNECTOR_DVID,
466 DRM_MODE_CONNECTOR_DVIA,
467 DRM_MODE_CONNECTOR_SVIDEO,
468 DRM_MODE_CONNECTOR_Composite,
469 DRM_MODE_CONNECTOR_LVDS,
470 DRM_MODE_CONNECTOR_Unknown,
471 DRM_MODE_CONNECTOR_Unknown,
472 DRM_MODE_CONNECTOR_HDMIA,
473 DRM_MODE_CONNECTOR_HDMIB,
474 DRM_MODE_CONNECTOR_Unknown,
475 DRM_MODE_CONNECTOR_Unknown,
476 DRM_MODE_CONNECTOR_9PinDIN,
477 DRM_MODE_CONNECTOR_DisplayPort
478};
479
Alex Deucherb75fad02009-11-05 13:16:01 -0500480const uint16_t supported_devices_connector_object_id_convert[] = {
481 CONNECTOR_OBJECT_ID_NONE,
482 CONNECTOR_OBJECT_ID_VGA,
483 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
484 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
485 CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
486 CONNECTOR_OBJECT_ID_COMPOSITE,
487 CONNECTOR_OBJECT_ID_SVIDEO,
488 CONNECTOR_OBJECT_ID_LVDS,
489 CONNECTOR_OBJECT_ID_9PIN_DIN,
490 CONNECTOR_OBJECT_ID_9PIN_DIN,
491 CONNECTOR_OBJECT_ID_DISPLAYPORT,
492 CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
493 CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
494 CONNECTOR_OBJECT_ID_SVIDEO
495};
496
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200497const int object_connector_convert[] = {
498 DRM_MODE_CONNECTOR_Unknown,
499 DRM_MODE_CONNECTOR_DVII,
500 DRM_MODE_CONNECTOR_DVII,
501 DRM_MODE_CONNECTOR_DVID,
502 DRM_MODE_CONNECTOR_DVID,
503 DRM_MODE_CONNECTOR_VGA,
504 DRM_MODE_CONNECTOR_Composite,
505 DRM_MODE_CONNECTOR_SVIDEO,
506 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher705af9c2009-09-10 16:31:13 -0400507 DRM_MODE_CONNECTOR_Unknown,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200508 DRM_MODE_CONNECTOR_9PinDIN,
509 DRM_MODE_CONNECTOR_Unknown,
510 DRM_MODE_CONNECTOR_HDMIA,
511 DRM_MODE_CONNECTOR_HDMIB,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200512 DRM_MODE_CONNECTOR_LVDS,
513 DRM_MODE_CONNECTOR_9PinDIN,
514 DRM_MODE_CONNECTOR_Unknown,
515 DRM_MODE_CONNECTOR_Unknown,
516 DRM_MODE_CONNECTOR_Unknown,
Alex Deucher196c58d2010-01-07 14:22:32 -0500517 DRM_MODE_CONNECTOR_DisplayPort,
518 DRM_MODE_CONNECTOR_eDP,
519 DRM_MODE_CONNECTOR_Unknown
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200520};
521
522bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
523{
524 struct radeon_device *rdev = dev->dev_private;
525 struct radeon_mode_info *mode_info = &rdev->mode_info;
526 struct atom_context *ctx = mode_info->atom_context;
527 int index = GetIndexIntoMasterTable(DATA, Object_Header);
Alex Deuchereed45b32009-12-04 14:45:27 -0500528 u16 size, data_offset;
529 u8 frev, crev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200530 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
Alex Deucher36868bd2011-01-06 21:19:21 -0500531 ATOM_ENCODER_OBJECT_TABLE *enc_obj;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400532 ATOM_OBJECT_TABLE *router_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200533 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
534 ATOM_OBJECT_HEADER *obj_header;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400535 int i, j, k, path_size, device_support;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200536 int connector_type;
Alex Deuchereed45b32009-12-04 14:45:27 -0500537 u16 igp_lane_info, conn_id, connector_object_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200538 struct radeon_i2c_bus_rec ddc_bus;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400539 struct radeon_router router;
Alex Deuchereed45b32009-12-04 14:45:27 -0500540 struct radeon_gpio_rec gpio;
541 struct radeon_hpd hpd;
542
Alex Deuchera084e6e2010-03-18 01:04:01 -0400543 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200544 return false;
545
546 if (crev < 2)
547 return false;
548
549 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
550 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
551 (ctx->bios + data_offset +
552 le16_to_cpu(obj_header->usDisplayPathTableOffset));
553 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
554 (ctx->bios + data_offset +
555 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
Alex Deucher36868bd2011-01-06 21:19:21 -0500556 enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
557 (ctx->bios + data_offset +
558 le16_to_cpu(obj_header->usEncoderObjectTableOffset));
Alex Deucher26b5bc92010-08-05 21:21:18 -0400559 router_obj = (ATOM_OBJECT_TABLE *)
560 (ctx->bios + data_offset +
561 le16_to_cpu(obj_header->usRouterObjectTableOffset));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200562 device_support = le16_to_cpu(obj_header->usDeviceSupport);
563
564 path_size = 0;
565 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
566 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
567 ATOM_DISPLAY_OBJECT_PATH *path;
568 addr += path_size;
569 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
570 path_size += le16_to_cpu(path->usSize);
Alex Deucher5137ee92010-08-12 18:58:47 -0400571
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200572 if (device_support & le16_to_cpu(path->usDeviceTag)) {
573 uint8_t con_obj_id, con_obj_num, con_obj_type;
574
575 con_obj_id =
576 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
577 >> OBJECT_ID_SHIFT;
578 con_obj_num =
579 (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
580 >> ENUM_ID_SHIFT;
581 con_obj_type =
582 (le16_to_cpu(path->usConnObjectId) &
583 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
584
Dave Airlie4bbd4972009-09-25 08:56:12 +1000585 /* TODO CV support */
586 if (le16_to_cpu(path->usDeviceTag) ==
587 ATOM_DEVICE_CV_SUPPORT)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200588 continue;
589
Alex Deucheree59f2b2009-11-05 13:11:46 -0500590 /* IGP chips */
591 if ((rdev->flags & RADEON_IS_IGP) &&
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200592 (con_obj_id ==
593 CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
594 uint16_t igp_offset = 0;
595 ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
596
597 index =
598 GetIndexIntoMasterTable(DATA,
599 IntegratedSystemInfo);
600
Alex Deuchera084e6e2010-03-18 01:04:01 -0400601 if (atom_parse_data_header(ctx, index, &size, &frev,
602 &crev, &igp_offset)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200603
Alex Deuchera084e6e2010-03-18 01:04:01 -0400604 if (crev >= 2) {
605 igp_obj =
606 (ATOM_INTEGRATED_SYSTEM_INFO_V2
607 *) (ctx->bios + igp_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200608
Alex Deuchera084e6e2010-03-18 01:04:01 -0400609 if (igp_obj) {
610 uint32_t slot_config, ct;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200611
Alex Deuchera084e6e2010-03-18 01:04:01 -0400612 if (con_obj_num == 1)
613 slot_config =
614 igp_obj->
615 ulDDISlot1Config;
616 else
617 slot_config =
618 igp_obj->
619 ulDDISlot2Config;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200620
Alex Deuchera084e6e2010-03-18 01:04:01 -0400621 ct = (slot_config >> 16) & 0xff;
622 connector_type =
623 object_connector_convert
624 [ct];
625 connector_object_id = ct;
626 igp_lane_info =
627 slot_config & 0xffff;
628 } else
629 continue;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200630 } else
631 continue;
Alex Deuchera084e6e2010-03-18 01:04:01 -0400632 } else {
633 igp_lane_info = 0;
634 connector_type =
635 object_connector_convert[con_obj_id];
636 connector_object_id = con_obj_id;
637 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200638 } else {
639 igp_lane_info = 0;
640 connector_type =
641 object_connector_convert[con_obj_id];
Alex Deucherb75fad02009-11-05 13:16:01 -0500642 connector_object_id = con_obj_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200643 }
644
645 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
646 continue;
647
Tyson Whiteheadbdd91b22010-11-08 16:08:30 +0000648 router.ddc_valid = false;
649 router.cd_valid = false;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400650 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
651 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200652
Alex Deucher26b5bc92010-08-05 21:21:18 -0400653 grph_obj_id =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200654 (le16_to_cpu(path->usGraphicObjIds[j]) &
655 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400656 grph_obj_num =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200657 (le16_to_cpu(path->usGraphicObjIds[j]) &
658 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400659 grph_obj_type =
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200660 (le16_to_cpu(path->usGraphicObjIds[j]) &
661 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
662
Alex Deucher26b5bc92010-08-05 21:21:18 -0400663 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
Alex Deucher36868bd2011-01-06 21:19:21 -0500664 for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
665 u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
666 if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
667 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
668 (ctx->bios + data_offset +
669 le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
670 ATOM_ENCODER_CAP_RECORD *cap_record;
671 u16 caps = 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200672
John Lindgren97ea5302011-03-24 23:28:31 +0000673 while (record->ucRecordSize > 0 &&
674 record->ucRecordType > 0 &&
Alex Deucher36868bd2011-01-06 21:19:21 -0500675 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
676 switch (record->ucRecordType) {
677 case ATOM_ENCODER_CAP_RECORD_TYPE:
678 cap_record =(ATOM_ENCODER_CAP_RECORD *)
679 record;
680 caps = le16_to_cpu(cap_record->usEncoderCap);
681 break;
682 }
683 record = (ATOM_COMMON_RECORD_HEADER *)
684 ((char *)record + record->ucRecordSize);
685 }
686 radeon_add_atom_encoder(dev,
687 encoder_obj,
688 le16_to_cpu
689 (path->
690 usDeviceTag),
691 caps);
692 }
693 }
Alex Deucher26b5bc92010-08-05 21:21:18 -0400694 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
Alex Deucher26b5bc92010-08-05 21:21:18 -0400695 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
Tyson Whiteheadbdd91b22010-11-08 16:08:30 +0000696 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
Alex Deucher26b5bc92010-08-05 21:21:18 -0400697 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
698 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
699 (ctx->bios + data_offset +
700 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
701 ATOM_I2C_RECORD *i2c_record;
702 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
703 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
Alex Deucherfb939df2010-11-08 16:08:29 +0000704 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400705 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
706 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
707 (ctx->bios + data_offset +
708 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
Alex Deucherfb93df12013-08-27 12:36:01 -0400709 u8 *num_dst_objs = (u8 *)
710 ((u8 *)router_src_dst_table + 1 +
711 (router_src_dst_table->ucNumberOfSrc * 2));
712 u16 *dst_objs = (u16 *)(num_dst_objs + 1);
Alex Deucher26b5bc92010-08-05 21:21:18 -0400713 int enum_id;
714
715 router.router_id = router_obj_id;
Alex Deucherfb93df12013-08-27 12:36:01 -0400716 for (enum_id = 0; enum_id < (*num_dst_objs); enum_id++) {
Alex Deucher26b5bc92010-08-05 21:21:18 -0400717 if (le16_to_cpu(path->usConnObjectId) ==
Alex Deucherfb93df12013-08-27 12:36:01 -0400718 le16_to_cpu(dst_objs[enum_id]))
Alex Deucher26b5bc92010-08-05 21:21:18 -0400719 break;
720 }
721
John Lindgren97ea5302011-03-24 23:28:31 +0000722 while (record->ucRecordSize > 0 &&
723 record->ucRecordType > 0 &&
Alex Deucher26b5bc92010-08-05 21:21:18 -0400724 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
725 switch (record->ucRecordType) {
726 case ATOM_I2C_RECORD_TYPE:
727 i2c_record =
728 (ATOM_I2C_RECORD *)
729 record;
730 i2c_config =
731 (ATOM_I2C_ID_CONFIG_ACCESS *)
732 &i2c_record->sucI2cId;
733 router.i2c_info =
734 radeon_lookup_i2c_gpio(rdev,
735 i2c_config->
736 ucAccess);
737 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
738 break;
739 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
740 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
741 record;
Alex Deucherfb939df2010-11-08 16:08:29 +0000742 router.ddc_valid = true;
743 router.ddc_mux_type = ddc_path->ucMuxType;
744 router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
745 router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
746 break;
747 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
748 cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
749 record;
750 router.cd_valid = true;
751 router.cd_mux_type = cd_path->ucMuxType;
752 router.cd_mux_control_pin = cd_path->ucMuxControlPin;
753 router.cd_mux_state = cd_path->ucMuxState[enum_id];
Alex Deucher26b5bc92010-08-05 21:21:18 -0400754 break;
755 }
756 record = (ATOM_COMMON_RECORD_HEADER *)
757 ((char *)record + record->ucRecordSize);
758 }
759 }
760 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200761 }
762 }
763
Alex Deuchereed45b32009-12-04 14:45:27 -0500764 /* look up gpio for ddc, hpd */
Alex Deucher2bfcc0f2010-05-18 19:26:46 -0400765 ddc_bus.valid = false;
766 hpd.hpd = RADEON_HPD_NONE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200767 if ((le16_to_cpu(path->usDeviceTag) &
Alex Deuchereed45b32009-12-04 14:45:27 -0500768 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200769 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
770 if (le16_to_cpu(path->usConnObjectId) ==
771 le16_to_cpu(con_obj->asObjects[j].
772 usObjectID)) {
773 ATOM_COMMON_RECORD_HEADER
774 *record =
775 (ATOM_COMMON_RECORD_HEADER
776 *)
777 (ctx->bios + data_offset +
778 le16_to_cpu(con_obj->
779 asObjects[j].
780 usRecordOffset));
781 ATOM_I2C_RECORD *i2c_record;
Alex Deuchereed45b32009-12-04 14:45:27 -0500782 ATOM_HPD_INT_RECORD *hpd_record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500783 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
Alex Deucher6a93cb22009-11-23 17:39:28 -0500784
John Lindgren97ea5302011-03-24 23:28:31 +0000785 while (record->ucRecordSize > 0 &&
786 record->ucRecordType > 0 &&
787 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
Alex Deuchereed45b32009-12-04 14:45:27 -0500788 switch (record->ucRecordType) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200789 case ATOM_I2C_RECORD_TYPE:
790 i2c_record =
Alex Deuchereed45b32009-12-04 14:45:27 -0500791 (ATOM_I2C_RECORD *)
792 record;
Alex Deucherd3f420d2009-12-08 14:30:49 -0500793 i2c_config =
794 (ATOM_I2C_ID_CONFIG_ACCESS *)
795 &i2c_record->sucI2cId;
Alex Deuchereed45b32009-12-04 14:45:27 -0500796 ddc_bus = radeon_lookup_i2c_gpio(rdev,
Alex Deucherd3f420d2009-12-08 14:30:49 -0500797 i2c_config->
798 ucAccess);
Alex Deuchereed45b32009-12-04 14:45:27 -0500799 break;
800 case ATOM_HPD_INT_RECORD_TYPE:
801 hpd_record =
802 (ATOM_HPD_INT_RECORD *)
803 record;
804 gpio = radeon_lookup_gpio(rdev,
805 hpd_record->ucHPDIntGPIOID);
806 hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
807 hpd.plugged_state = hpd_record->ucPlugged_PinState;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200808 break;
809 }
810 record =
811 (ATOM_COMMON_RECORD_HEADER
812 *) ((char *)record
813 +
814 record->
815 ucRecordSize);
816 }
817 break;
818 }
819 }
Alex Deuchereed45b32009-12-04 14:45:27 -0500820 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200821
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500822 /* needed for aux chan transactions */
Alex Deucher8e36ed02010-05-18 19:26:47 -0400823 ddc_bus.hpd = hpd.hpd;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500824
Alex Deucher705af9c2009-09-10 16:31:13 -0400825 conn_id = le16_to_cpu(path->usConnObjectId);
826
827 if (!radeon_atom_apply_quirks
828 (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -0500829 &ddc_bus, &conn_id, &hpd))
Alex Deucher705af9c2009-09-10 16:31:13 -0400830 continue;
831
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200832 radeon_add_atom_connector(dev,
Alex Deucher705af9c2009-09-10 16:31:13 -0400833 conn_id,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200834 le16_to_cpu(path->
835 usDeviceTag),
836 connector_type, &ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -0400837 igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -0500838 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -0400839 &hpd,
840 &router);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200841
842 }
843 }
844
845 radeon_link_encoder_connector(dev);
846
847 return true;
848}
849
Alex Deucherb75fad02009-11-05 13:16:01 -0500850static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
851 int connector_type,
852 uint16_t devices)
853{
854 struct radeon_device *rdev = dev->dev_private;
855
856 if (rdev->flags & RADEON_IS_IGP) {
857 return supported_devices_connector_object_id_convert
858 [connector_type];
859 } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
860 (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
861 (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
862 struct radeon_mode_info *mode_info = &rdev->mode_info;
863 struct atom_context *ctx = mode_info->atom_context;
864 int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
865 uint16_t size, data_offset;
866 uint8_t frev, crev;
867 ATOM_XTMDS_INFO *xtmds;
868
Alex Deuchera084e6e2010-03-18 01:04:01 -0400869 if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
870 xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
Alex Deucherb75fad02009-11-05 13:16:01 -0500871
Alex Deuchera084e6e2010-03-18 01:04:01 -0400872 if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
873 if (connector_type == DRM_MODE_CONNECTOR_DVII)
874 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
875 else
876 return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
877 } else {
878 if (connector_type == DRM_MODE_CONNECTOR_DVII)
879 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
880 else
881 return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
882 }
883 } else
884 return supported_devices_connector_object_id_convert
885 [connector_type];
Alex Deucherb75fad02009-11-05 13:16:01 -0500886 } else {
887 return supported_devices_connector_object_id_convert
888 [connector_type];
889 }
890}
891
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200892struct bios_connector {
893 bool valid;
Alex Deucher705af9c2009-09-10 16:31:13 -0400894 uint16_t line_mux;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200895 uint16_t devices;
896 int connector_type;
897 struct radeon_i2c_bus_rec ddc_bus;
Alex Deuchereed45b32009-12-04 14:45:27 -0500898 struct radeon_hpd hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200899};
900
901bool radeon_get_atom_connector_info_from_supported_devices_table(struct
902 drm_device
903 *dev)
904{
905 struct radeon_device *rdev = dev->dev_private;
906 struct radeon_mode_info *mode_info = &rdev->mode_info;
907 struct atom_context *ctx = mode_info->atom_context;
908 int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
909 uint16_t size, data_offset;
910 uint8_t frev, crev;
911 uint16_t device_support;
912 uint8_t dac;
913 union atom_supported_devices *supported_devices;
Alex Deuchereed45b32009-12-04 14:45:27 -0500914 int i, j, max_device;
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000915 struct bios_connector *bios_connectors;
916 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
Alex Deucher26b5bc92010-08-05 21:21:18 -0400917 struct radeon_router router;
918
Alex Deucherfb939df2010-11-08 16:08:29 +0000919 router.ddc_valid = false;
920 router.cd_valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200921
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000922 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
923 if (!bios_connectors)
Alex Deuchera084e6e2010-03-18 01:04:01 -0400924 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200925
Prarit Bhargavaf49d2732010-05-24 10:24:07 +1000926 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
927 &data_offset)) {
928 kfree(bios_connectors);
929 return false;
930 }
931
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200932 supported_devices =
933 (union atom_supported_devices *)(ctx->bios + data_offset);
934
935 device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
936
Alex Deuchereed45b32009-12-04 14:45:27 -0500937 if (frev > 1)
938 max_device = ATOM_MAX_SUPPORTED_DEVICE;
939 else
940 max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
941
942 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200943 ATOM_CONNECTOR_INFO_I2C ci =
944 supported_devices->info.asConnInfo[i];
945
946 bios_connectors[i].valid = false;
947
948 if (!(device_support & (1 << i))) {
949 continue;
950 }
951
952 if (i == ATOM_DEVICE_CV_INDEX) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000953 DRM_DEBUG_KMS("Skipping Component Video\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200954 continue;
955 }
956
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200957 bios_connectors[i].connector_type =
958 supported_devices_connector_convert[ci.sucConnectorInfo.
959 sbfAccess.
960 bfConnectorType];
961
962 if (bios_connectors[i].connector_type ==
963 DRM_MODE_CONNECTOR_Unknown)
964 continue;
965
966 dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
967
Alex Deucherd3f420d2009-12-08 14:30:49 -0500968 bios_connectors[i].line_mux =
969 ci.sucI2cId.ucAccess;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200970
971 /* give tv unique connector ids */
972 if (i == ATOM_DEVICE_TV1_INDEX) {
973 bios_connectors[i].ddc_bus.valid = false;
974 bios_connectors[i].line_mux = 50;
975 } else if (i == ATOM_DEVICE_TV2_INDEX) {
976 bios_connectors[i].ddc_bus.valid = false;
977 bios_connectors[i].line_mux = 51;
978 } else if (i == ATOM_DEVICE_CV_INDEX) {
979 bios_connectors[i].ddc_bus.valid = false;
980 bios_connectors[i].line_mux = 52;
981 } else
982 bios_connectors[i].ddc_bus =
Alex Deuchereed45b32009-12-04 14:45:27 -0500983 radeon_lookup_i2c_gpio(rdev,
984 bios_connectors[i].line_mux);
985
986 if ((crev > 1) && (frev > 1)) {
987 u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
988 switch (isb) {
989 case 0x4:
990 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
991 break;
992 case 0xa:
993 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
994 break;
995 default:
996 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
997 break;
998 }
999 } else {
1000 if (i == ATOM_DEVICE_DFP1_INDEX)
1001 bios_connectors[i].hpd.hpd = RADEON_HPD_1;
1002 else if (i == ATOM_DEVICE_DFP2_INDEX)
1003 bios_connectors[i].hpd.hpd = RADEON_HPD_2;
1004 else
1005 bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
1006 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001007
1008 /* Always set the connector type to VGA for CRT1/CRT2. if they are
1009 * shared with a DVI port, we'll pick up the DVI connector when we
1010 * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
1011 */
1012 if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
1013 bios_connectors[i].connector_type =
1014 DRM_MODE_CONNECTOR_VGA;
1015
1016 if (!radeon_atom_apply_quirks
1017 (dev, (1 << i), &bios_connectors[i].connector_type,
Alex Deuchereed45b32009-12-04 14:45:27 -05001018 &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
1019 &bios_connectors[i].hpd))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001020 continue;
1021
1022 bios_connectors[i].valid = true;
1023 bios_connectors[i].devices = (1 << i);
1024
1025 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
1026 radeon_add_atom_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001027 radeon_get_encoder_enum(dev,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001028 (1 << i),
1029 dac),
Alex Deucher36868bd2011-01-06 21:19:21 -05001030 (1 << i),
1031 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001032 else
1033 radeon_add_legacy_encoder(dev,
Alex Deucher5137ee92010-08-12 18:58:47 -04001034 radeon_get_encoder_enum(dev,
Alex Deucherf56cd642009-12-18 11:28:22 -05001035 (1 << i),
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001036 dac),
1037 (1 << i));
1038 }
1039
1040 /* combine shared connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -05001041 for (i = 0; i < max_device; i++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001042 if (bios_connectors[i].valid) {
Alex Deuchereed45b32009-12-04 14:45:27 -05001043 for (j = 0; j < max_device; j++) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001044 if (bios_connectors[j].valid && (i != j)) {
1045 if (bios_connectors[i].line_mux ==
1046 bios_connectors[j].line_mux) {
Alex Deucherf56cd642009-12-18 11:28:22 -05001047 /* make sure not to combine LVDS */
1048 if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1049 bios_connectors[i].line_mux = 53;
1050 bios_connectors[i].ddc_bus.valid = false;
1051 continue;
1052 }
1053 if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1054 bios_connectors[j].line_mux = 53;
1055 bios_connectors[j].ddc_bus.valid = false;
1056 continue;
1057 }
1058 /* combine analog and digital for DVI-I */
1059 if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1060 (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
1061 ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
1062 (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
1063 bios_connectors[i].devices |=
1064 bios_connectors[j].devices;
1065 bios_connectors[i].connector_type =
1066 DRM_MODE_CONNECTOR_DVII;
1067 if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
Alex Deuchereed45b32009-12-04 14:45:27 -05001068 bios_connectors[i].hpd =
1069 bios_connectors[j].hpd;
Alex Deucherf56cd642009-12-18 11:28:22 -05001070 bios_connectors[j].valid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001071 }
1072 }
1073 }
1074 }
1075 }
1076 }
1077
1078 /* add the connectors */
Alex Deuchereed45b32009-12-04 14:45:27 -05001079 for (i = 0; i < max_device; i++) {
Alex Deucherb75fad02009-11-05 13:16:01 -05001080 if (bios_connectors[i].valid) {
1081 uint16_t connector_object_id =
1082 atombios_get_connector_object_id(dev,
1083 bios_connectors[i].connector_type,
1084 bios_connectors[i].devices);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001085 radeon_add_atom_connector(dev,
1086 bios_connectors[i].line_mux,
1087 bios_connectors[i].devices,
1088 bios_connectors[i].
1089 connector_type,
1090 &bios_connectors[i].ddc_bus,
Alex Deucher5137ee92010-08-12 18:58:47 -04001091 0,
Alex Deuchereed45b32009-12-04 14:45:27 -05001092 connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001093 &bios_connectors[i].hpd,
1094 &router);
Alex Deucherb75fad02009-11-05 13:16:01 -05001095 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001096 }
1097
1098 radeon_link_encoder_connector(dev);
1099
Prarit Bhargavaf49d2732010-05-24 10:24:07 +10001100 kfree(bios_connectors);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001101 return true;
1102}
1103
1104union firmware_info {
1105 ATOM_FIRMWARE_INFO info;
1106 ATOM_FIRMWARE_INFO_V1_2 info_12;
1107 ATOM_FIRMWARE_INFO_V1_3 info_13;
1108 ATOM_FIRMWARE_INFO_V1_4 info_14;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001109 ATOM_FIRMWARE_INFO_V2_1 info_21;
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001110 ATOM_FIRMWARE_INFO_V2_2 info_22;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001111};
1112
1113bool radeon_atom_get_clock_info(struct drm_device *dev)
1114{
1115 struct radeon_device *rdev = dev->dev_private;
1116 struct radeon_mode_info *mode_info = &rdev->mode_info;
1117 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1118 union firmware_info *firmware_info;
1119 uint8_t frev, crev;
1120 struct radeon_pll *p1pll = &rdev->clock.p1pll;
1121 struct radeon_pll *p2pll = &rdev->clock.p2pll;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001122 struct radeon_pll *dcpll = &rdev->clock.dcpll;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001123 struct radeon_pll *spll = &rdev->clock.spll;
1124 struct radeon_pll *mpll = &rdev->clock.mpll;
1125 uint16_t data_offset;
1126
Alex Deuchera084e6e2010-03-18 01:04:01 -04001127 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1128 &frev, &crev, &data_offset)) {
1129 firmware_info =
1130 (union firmware_info *)(mode_info->atom_context->bios +
1131 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001132 /* pixel clocks */
1133 p1pll->reference_freq =
1134 le16_to_cpu(firmware_info->info.usReferenceClock);
1135 p1pll->reference_div = 0;
1136
Mathias Fröhlichbc293e52009-10-19 17:49:49 -04001137 if (crev < 2)
1138 p1pll->pll_out_min =
1139 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
1140 else
1141 p1pll->pll_out_min =
1142 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001143 p1pll->pll_out_max =
1144 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
1145
Alex Deucher86cb2bb2010-03-08 12:55:16 -05001146 if (crev >= 4) {
1147 p1pll->lcd_pll_out_min =
1148 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
1149 if (p1pll->lcd_pll_out_min == 0)
1150 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1151 p1pll->lcd_pll_out_max =
1152 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
1153 if (p1pll->lcd_pll_out_max == 0)
1154 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1155 } else {
1156 p1pll->lcd_pll_out_min = p1pll->pll_out_min;
1157 p1pll->lcd_pll_out_max = p1pll->pll_out_max;
1158 }
1159
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001160 if (p1pll->pll_out_min == 0) {
1161 if (ASIC_IS_AVIVO(rdev))
1162 p1pll->pll_out_min = 64800;
1163 else
1164 p1pll->pll_out_min = 20000;
1165 }
1166
1167 p1pll->pll_in_min =
1168 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
1169 p1pll->pll_in_max =
1170 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
1171
1172 *p2pll = *p1pll;
1173
1174 /* system clock */
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001175 if (ASIC_IS_DCE4(rdev))
1176 spll->reference_freq =
1177 le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
1178 else
1179 spll->reference_freq =
1180 le16_to_cpu(firmware_info->info.usReferenceClock);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001181 spll->reference_div = 0;
1182
1183 spll->pll_out_min =
1184 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
1185 spll->pll_out_max =
1186 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
1187
1188 /* ??? */
1189 if (spll->pll_out_min == 0) {
1190 if (ASIC_IS_AVIVO(rdev))
1191 spll->pll_out_min = 64800;
1192 else
1193 spll->pll_out_min = 20000;
1194 }
1195
1196 spll->pll_in_min =
1197 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
1198 spll->pll_in_max =
1199 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
1200
1201 /* memory clock */
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001202 if (ASIC_IS_DCE4(rdev))
1203 mpll->reference_freq =
1204 le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
1205 else
1206 mpll->reference_freq =
1207 le16_to_cpu(firmware_info->info.usReferenceClock);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001208 mpll->reference_div = 0;
1209
1210 mpll->pll_out_min =
1211 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
1212 mpll->pll_out_max =
1213 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
1214
1215 /* ??? */
1216 if (mpll->pll_out_min == 0) {
1217 if (ASIC_IS_AVIVO(rdev))
1218 mpll->pll_out_min = 64800;
1219 else
1220 mpll->pll_out_min = 20000;
1221 }
1222
1223 mpll->pll_in_min =
1224 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
1225 mpll->pll_in_max =
1226 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
1227
1228 rdev->clock.default_sclk =
1229 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
1230 rdev->clock.default_mclk =
1231 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
1232
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001233 if (ASIC_IS_DCE4(rdev)) {
1234 rdev->clock.default_dispclk =
1235 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001236 if (rdev->clock.default_dispclk == 0) {
Alex Deucher93689312014-06-18 11:46:35 -04001237 if (ASIC_IS_DCE6(rdev))
1238 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1239 else if (ASIC_IS_DCE5(rdev))
Alex Deucherf82b3dd2011-01-06 21:19:15 -05001240 rdev->clock.default_dispclk = 54000; /* 540 Mhz */
1241 else
1242 rdev->clock.default_dispclk = 60000; /* 600 Mhz */
1243 }
Alex Deucher93689312014-06-18 11:46:35 -04001244 /* set a reasonable default for DP */
1245 if (ASIC_IS_DCE6(rdev) && (rdev->clock.default_dispclk < 53900)) {
1246 DRM_INFO("Changing default dispclk from %dMhz to 600Mhz\n",
1247 rdev->clock.default_dispclk / 100);
1248 rdev->clock.default_dispclk = 60000;
1249 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001250 rdev->clock.dp_extclk =
1251 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
Alex Deucher4489cd622013-03-22 15:59:10 -04001252 rdev->clock.current_dispclk = rdev->clock.default_dispclk;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001253 }
1254 *dcpll = *p1pll;
1255
Alex Deucherb20f9be2011-06-08 13:01:11 -04001256 rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
1257 if (rdev->clock.max_pixel_clock == 0)
1258 rdev->clock.max_pixel_clock = 40000;
1259
Alex Deucheraf7912e2012-07-26 09:50:57 -04001260 /* not technically a clock, but... */
1261 rdev->mode_info.firmware_flags =
1262 le16_to_cpu(firmware_info->info.usFirmwareCapability.susAccess);
1263
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001264 return true;
1265 }
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001266
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001267 return false;
1268}
1269
Alex Deucher06b64762010-01-05 11:27:29 -05001270union igp_info {
1271 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1272 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
Alex Deucher3838f462012-07-25 12:32:59 -04001273 struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
1274 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
Alex Deucherc2037ad2012-07-25 12:45:16 -04001275 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8;
Alex Deucher06b64762010-01-05 11:27:29 -05001276};
1277
1278bool radeon_atombios_sideport_present(struct radeon_device *rdev)
1279{
1280 struct radeon_mode_info *mode_info = &rdev->mode_info;
1281 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1282 union igp_info *igp_info;
1283 u8 frev, crev;
1284 u16 data_offset;
1285
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001286 /* sideport is AMD only */
1287 if (rdev->family == CHIP_RS600)
1288 return false;
1289
Alex Deuchera084e6e2010-03-18 01:04:01 -04001290 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1291 &frev, &crev, &data_offset)) {
1292 igp_info = (union igp_info *)(mode_info->atom_context->bios +
Alex Deucher06b64762010-01-05 11:27:29 -05001293 data_offset);
Alex Deucher06b64762010-01-05 11:27:29 -05001294 switch (crev) {
1295 case 1:
Cédric Cano45894332011-02-11 19:45:37 -05001296 if (le32_to_cpu(igp_info->info.ulBootUpMemoryClock))
Alex Deucher4c70b2e2010-08-02 19:39:15 -04001297 return true;
Alex Deucher06b64762010-01-05 11:27:29 -05001298 break;
1299 case 2:
Cédric Cano45894332011-02-11 19:45:37 -05001300 if (le32_to_cpu(igp_info->info_2.ulBootUpSidePortClock))
Alex Deucher06b64762010-01-05 11:27:29 -05001301 return true;
1302 break;
1303 default:
1304 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1305 break;
1306 }
1307 }
1308 return false;
1309}
1310
Dave Airlie445282d2009-09-09 17:40:54 +10001311bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
1312 struct radeon_encoder_int_tmds *tmds)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001313{
1314 struct drm_device *dev = encoder->base.dev;
1315 struct radeon_device *rdev = dev->dev_private;
1316 struct radeon_mode_info *mode_info = &rdev->mode_info;
1317 int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
1318 uint16_t data_offset;
1319 struct _ATOM_TMDS_INFO *tmds_info;
1320 uint8_t frev, crev;
1321 uint16_t maxfreq;
1322 int i;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001323
Alex Deuchera084e6e2010-03-18 01:04:01 -04001324 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1325 &frev, &crev, &data_offset)) {
1326 tmds_info =
1327 (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
1328 data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001329
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001330 maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
1331 for (i = 0; i < 4; i++) {
1332 tmds->tmds_pll[i].freq =
1333 le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
1334 tmds->tmds_pll[i].value =
1335 tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
1336 tmds->tmds_pll[i].value |=
1337 (tmds_info->asMiscInfo[i].
1338 ucPLL_VCO_Gain & 0x3f) << 6;
1339 tmds->tmds_pll[i].value |=
1340 (tmds_info->asMiscInfo[i].
1341 ucPLL_DutyCycle & 0xf) << 12;
1342 tmds->tmds_pll[i].value |=
1343 (tmds_info->asMiscInfo[i].
1344 ucPLL_VoltageSwing & 0xf) << 16;
1345
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001346 DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001347 tmds->tmds_pll[i].freq,
1348 tmds->tmds_pll[i].value);
1349
1350 if (maxfreq == tmds->tmds_pll[i].freq) {
1351 tmds->tmds_pll[i].freq = 0xffffffff;
1352 break;
1353 }
1354 }
Dave Airlie445282d2009-09-09 17:40:54 +10001355 return true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001356 }
Dave Airlie445282d2009-09-09 17:40:54 +10001357 return false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001358}
1359
Alex Deucherba032a52010-10-04 17:13:01 -04001360bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
1361 struct radeon_atom_ss *ss,
1362 int id)
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001363{
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001364 struct radeon_mode_info *mode_info = &rdev->mode_info;
1365 int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
Alex Deucherba032a52010-10-04 17:13:01 -04001366 uint16_t data_offset, size;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001367 struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
Alex Deuchera7ee8242013-09-16 17:46:00 -04001368 struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT *ss_assign;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001369 uint8_t frev, crev;
Alex Deucherba032a52010-10-04 17:13:01 -04001370 int i, num_indices;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001371
Alex Deucherba032a52010-10-04 17:13:01 -04001372 memset(ss, 0, sizeof(struct radeon_atom_ss));
1373 if (atom_parse_data_header(mode_info->atom_context, index, &size,
Alex Deuchera084e6e2010-03-18 01:04:01 -04001374 &frev, &crev, &data_offset)) {
1375 ss_info =
1376 (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001377
Alex Deucherba032a52010-10-04 17:13:01 -04001378 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1379 sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
Alex Deuchera7ee8242013-09-16 17:46:00 -04001380 ss_assign = (struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT*)
1381 ((u8 *)&ss_info->asSS_Info[0]);
Alex Deucherba032a52010-10-04 17:13:01 -04001382 for (i = 0; i < num_indices; i++) {
Alex Deuchera7ee8242013-09-16 17:46:00 -04001383 if (ss_assign->ucSS_Id == id) {
Alex Deucher279b2152009-12-08 14:07:03 -05001384 ss->percentage =
Alex Deuchera7ee8242013-09-16 17:46:00 -04001385 le16_to_cpu(ss_assign->usSpreadSpectrumPercentage);
1386 ss->type = ss_assign->ucSpreadSpectrumType;
1387 ss->step = ss_assign->ucSS_Step;
1388 ss->delay = ss_assign->ucSS_Delay;
1389 ss->range = ss_assign->ucSS_Range;
1390 ss->refdiv = ss_assign->ucRecommendedRef_Div;
Alex Deucherba032a52010-10-04 17:13:01 -04001391 return true;
Alex Deucher279b2152009-12-08 14:07:03 -05001392 }
Alex Deuchera7ee8242013-09-16 17:46:00 -04001393 ss_assign = (struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT*)
1394 ((u8 *)ss_assign + sizeof(struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT));
Alex Deucher279b2152009-12-08 14:07:03 -05001395 }
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001396 }
Alex Deucherba032a52010-10-04 17:13:01 -04001397 return false;
1398}
1399
Alex Deucher4339c442010-11-22 17:56:25 -05001400static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
1401 struct radeon_atom_ss *ss,
1402 int id)
1403{
1404 struct radeon_mode_info *mode_info = &rdev->mode_info;
1405 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1406 u16 data_offset, size;
Alex Deucher3838f462012-07-25 12:32:59 -04001407 union igp_info *igp_info;
Alex Deucher4339c442010-11-22 17:56:25 -05001408 u8 frev, crev;
1409 u16 percentage = 0, rate = 0;
1410
1411 /* get any igp specific overrides */
1412 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1413 &frev, &crev, &data_offset)) {
Alex Deucher3838f462012-07-25 12:32:59 -04001414 igp_info = (union igp_info *)
Alex Deucher4339c442010-11-22 17:56:25 -05001415 (mode_info->atom_context->bios + data_offset);
Alex Deucher3838f462012-07-25 12:32:59 -04001416 switch (crev) {
1417 case 6:
1418 switch (id) {
1419 case ASIC_INTERNAL_SS_ON_TMDS:
1420 percentage = le16_to_cpu(igp_info->info_6.usDVISSPercentage);
1421 rate = le16_to_cpu(igp_info->info_6.usDVISSpreadRateIn10Hz);
1422 break;
1423 case ASIC_INTERNAL_SS_ON_HDMI:
1424 percentage = le16_to_cpu(igp_info->info_6.usHDMISSPercentage);
1425 rate = le16_to_cpu(igp_info->info_6.usHDMISSpreadRateIn10Hz);
1426 break;
1427 case ASIC_INTERNAL_SS_ON_LVDS:
1428 percentage = le16_to_cpu(igp_info->info_6.usLvdsSSPercentage);
1429 rate = le16_to_cpu(igp_info->info_6.usLvdsSSpreadRateIn10Hz);
1430 break;
1431 }
Alex Deucher4339c442010-11-22 17:56:25 -05001432 break;
Alex Deucher3838f462012-07-25 12:32:59 -04001433 case 7:
1434 switch (id) {
1435 case ASIC_INTERNAL_SS_ON_TMDS:
1436 percentage = le16_to_cpu(igp_info->info_7.usDVISSPercentage);
1437 rate = le16_to_cpu(igp_info->info_7.usDVISSpreadRateIn10Hz);
1438 break;
1439 case ASIC_INTERNAL_SS_ON_HDMI:
1440 percentage = le16_to_cpu(igp_info->info_7.usHDMISSPercentage);
1441 rate = le16_to_cpu(igp_info->info_7.usHDMISSpreadRateIn10Hz);
1442 break;
1443 case ASIC_INTERNAL_SS_ON_LVDS:
1444 percentage = le16_to_cpu(igp_info->info_7.usLvdsSSPercentage);
1445 rate = le16_to_cpu(igp_info->info_7.usLvdsSSpreadRateIn10Hz);
1446 break;
1447 }
Alex Deucher4339c442010-11-22 17:56:25 -05001448 break;
Alex Deucherc2037ad2012-07-25 12:45:16 -04001449 case 8:
1450 switch (id) {
1451 case ASIC_INTERNAL_SS_ON_TMDS:
1452 percentage = le16_to_cpu(igp_info->info_8.usDVISSPercentage);
1453 rate = le16_to_cpu(igp_info->info_8.usDVISSpreadRateIn10Hz);
1454 break;
1455 case ASIC_INTERNAL_SS_ON_HDMI:
1456 percentage = le16_to_cpu(igp_info->info_8.usHDMISSPercentage);
1457 rate = le16_to_cpu(igp_info->info_8.usHDMISSpreadRateIn10Hz);
1458 break;
1459 case ASIC_INTERNAL_SS_ON_LVDS:
1460 percentage = le16_to_cpu(igp_info->info_8.usLvdsSSPercentage);
1461 rate = le16_to_cpu(igp_info->info_8.usLvdsSSpreadRateIn10Hz);
1462 break;
1463 }
1464 break;
Alex Deucher3838f462012-07-25 12:32:59 -04001465 default:
1466 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
Alex Deucher4339c442010-11-22 17:56:25 -05001467 break;
1468 }
1469 if (percentage)
1470 ss->percentage = percentage;
1471 if (rate)
1472 ss->rate = rate;
1473 }
1474}
1475
Alex Deucherba032a52010-10-04 17:13:01 -04001476union asic_ss_info {
1477 struct _ATOM_ASIC_INTERNAL_SS_INFO info;
1478 struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
1479 struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
1480};
1481
Alex Deuchera7ee8242013-09-16 17:46:00 -04001482union asic_ss_assignment {
1483 struct _ATOM_ASIC_SS_ASSIGNMENT v1;
1484 struct _ATOM_ASIC_SS_ASSIGNMENT_V2 v2;
1485 struct _ATOM_ASIC_SS_ASSIGNMENT_V3 v3;
1486};
1487
Alex Deucherba032a52010-10-04 17:13:01 -04001488bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
1489 struct radeon_atom_ss *ss,
1490 int id, u32 clock)
1491{
1492 struct radeon_mode_info *mode_info = &rdev->mode_info;
1493 int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
1494 uint16_t data_offset, size;
1495 union asic_ss_info *ss_info;
Alex Deuchera7ee8242013-09-16 17:46:00 -04001496 union asic_ss_assignment *ss_assign;
Alex Deucherba032a52010-10-04 17:13:01 -04001497 uint8_t frev, crev;
1498 int i, num_indices;
1499
Alex Deucher9cb84ab2013-08-19 19:06:19 -04001500 if (id == ASIC_INTERNAL_MEMORY_SS) {
1501 if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_MEMORY_CLOCK_SS_SUPPORT))
1502 return false;
1503 }
1504 if (id == ASIC_INTERNAL_ENGINE_SS) {
1505 if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_ENGINE_CLOCK_SS_SUPPORT))
1506 return false;
1507 }
1508
Alex Deucherba032a52010-10-04 17:13:01 -04001509 memset(ss, 0, sizeof(struct radeon_atom_ss));
1510 if (atom_parse_data_header(mode_info->atom_context, index, &size,
1511 &frev, &crev, &data_offset)) {
1512
1513 ss_info =
1514 (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
1515
1516 switch (frev) {
1517 case 1:
1518 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1519 sizeof(ATOM_ASIC_SS_ASSIGNMENT);
1520
Alex Deuchera7ee8242013-09-16 17:46:00 -04001521 ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info.asSpreadSpectrum[0]);
Alex Deucherba032a52010-10-04 17:13:01 -04001522 for (i = 0; i < num_indices; i++) {
Alex Deuchera7ee8242013-09-16 17:46:00 -04001523 if ((ss_assign->v1.ucClockIndication == id) &&
1524 (clock <= le32_to_cpu(ss_assign->v1.ulTargetClockRange))) {
Alex Deucherba032a52010-10-04 17:13:01 -04001525 ss->percentage =
Alex Deuchera7ee8242013-09-16 17:46:00 -04001526 le16_to_cpu(ss_assign->v1.usSpreadSpectrumPercentage);
1527 ss->type = ss_assign->v1.ucSpreadSpectrumMode;
1528 ss->rate = le16_to_cpu(ss_assign->v1.usSpreadRateInKhz);
Alex Deucher18f8f522014-01-15 13:41:31 -05001529 ss->percentage_divider = 100;
Alex Deucherba032a52010-10-04 17:13:01 -04001530 return true;
1531 }
Alex Deuchera7ee8242013-09-16 17:46:00 -04001532 ss_assign = (union asic_ss_assignment *)
1533 ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT));
Alex Deucherba032a52010-10-04 17:13:01 -04001534 }
1535 break;
1536 case 2:
1537 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1538 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
Alex Deuchera7ee8242013-09-16 17:46:00 -04001539 ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info_2.asSpreadSpectrum[0]);
Alex Deucherba032a52010-10-04 17:13:01 -04001540 for (i = 0; i < num_indices; i++) {
Alex Deuchera7ee8242013-09-16 17:46:00 -04001541 if ((ss_assign->v2.ucClockIndication == id) &&
1542 (clock <= le32_to_cpu(ss_assign->v2.ulTargetClockRange))) {
Alex Deucherba032a52010-10-04 17:13:01 -04001543 ss->percentage =
Alex Deuchera7ee8242013-09-16 17:46:00 -04001544 le16_to_cpu(ss_assign->v2.usSpreadSpectrumPercentage);
1545 ss->type = ss_assign->v2.ucSpreadSpectrumMode;
1546 ss->rate = le16_to_cpu(ss_assign->v2.usSpreadRateIn10Hz);
Alex Deucher18f8f522014-01-15 13:41:31 -05001547 ss->percentage_divider = 100;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04001548 if ((crev == 2) &&
1549 ((id == ASIC_INTERNAL_ENGINE_SS) ||
1550 (id == ASIC_INTERNAL_MEMORY_SS)))
1551 ss->rate /= 100;
Alex Deucherba032a52010-10-04 17:13:01 -04001552 return true;
1553 }
Alex Deuchera7ee8242013-09-16 17:46:00 -04001554 ss_assign = (union asic_ss_assignment *)
1555 ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2));
Alex Deucherba032a52010-10-04 17:13:01 -04001556 }
1557 break;
1558 case 3:
1559 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
1560 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
Alex Deuchera7ee8242013-09-16 17:46:00 -04001561 ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info_3.asSpreadSpectrum[0]);
Alex Deucherba032a52010-10-04 17:13:01 -04001562 for (i = 0; i < num_indices; i++) {
Alex Deuchera7ee8242013-09-16 17:46:00 -04001563 if ((ss_assign->v3.ucClockIndication == id) &&
1564 (clock <= le32_to_cpu(ss_assign->v3.ulTargetClockRange))) {
Alex Deucherba032a52010-10-04 17:13:01 -04001565 ss->percentage =
Alex Deuchera7ee8242013-09-16 17:46:00 -04001566 le16_to_cpu(ss_assign->v3.usSpreadSpectrumPercentage);
1567 ss->type = ss_assign->v3.ucSpreadSpectrumMode;
1568 ss->rate = le16_to_cpu(ss_assign->v3.usSpreadRateIn10Hz);
Alex Deucher18f8f522014-01-15 13:41:31 -05001569 if (ss_assign->v3.ucSpreadSpectrumMode &
1570 SS_MODE_V3_PERCENTAGE_DIV_BY_1000_MASK)
1571 ss->percentage_divider = 1000;
1572 else
1573 ss->percentage_divider = 100;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04001574 if ((id == ASIC_INTERNAL_ENGINE_SS) ||
1575 (id == ASIC_INTERNAL_MEMORY_SS))
1576 ss->rate /= 100;
Alex Deucher4339c442010-11-22 17:56:25 -05001577 if (rdev->flags & RADEON_IS_IGP)
1578 radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
Alex Deucherba032a52010-10-04 17:13:01 -04001579 return true;
1580 }
Alex Deuchera7ee8242013-09-16 17:46:00 -04001581 ss_assign = (union asic_ss_assignment *)
1582 ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3));
Alex Deucherba032a52010-10-04 17:13:01 -04001583 }
1584 break;
1585 default:
1586 DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
1587 break;
1588 }
1589
1590 }
1591 return false;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001592}
1593
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001594union lvds_info {
1595 struct _ATOM_LVDS_INFO info;
1596 struct _ATOM_LVDS_INFO_V12 info_12;
1597};
1598
1599struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
1600 radeon_encoder
1601 *encoder)
1602{
1603 struct drm_device *dev = encoder->base.dev;
1604 struct radeon_device *rdev = dev->dev_private;
1605 struct radeon_mode_info *mode_info = &rdev->mode_info;
1606 int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
Alex Deucher7dde8a192009-11-30 01:40:24 -05001607 uint16_t data_offset, misc;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001608 union lvds_info *lvds_info;
1609 uint8_t frev, crev;
1610 struct radeon_encoder_atom_dig *lvds = NULL;
Alex Deucher5137ee92010-08-12 18:58:47 -04001611 int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001612
Alex Deuchera084e6e2010-03-18 01:04:01 -04001613 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1614 &frev, &crev, &data_offset)) {
1615 lvds_info =
1616 (union lvds_info *)(mode_info->atom_context->bios + data_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001617 lvds =
1618 kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
1619
1620 if (!lvds)
1621 return NULL;
1622
Alex Deucherde2103e2009-10-09 15:14:30 -04001623 lvds->native_mode.clock =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001624 le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
Alex Deucherde2103e2009-10-09 15:14:30 -04001625 lvds->native_mode.hdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001626 le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001627 lvds->native_mode.vdisplay =
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001628 le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
Alex Deucherde2103e2009-10-09 15:14:30 -04001629 lvds->native_mode.htotal = lvds->native_mode.hdisplay +
1630 le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
1631 lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
1632 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
1633 lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
1634 le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
1635 lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
1636 le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
1637 lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
Alex Deucher1ff26a32010-05-18 00:23:15 -04001638 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
Alex Deucherde2103e2009-10-09 15:14:30 -04001639 lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
1640 le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001641 lvds->panel_pwr_delay =
1642 le16_to_cpu(lvds_info->info.usOffDelayInMs);
Alex Deucherba032a52010-10-04 17:13:01 -04001643 lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
Alex Deucher7dde8a192009-11-30 01:40:24 -05001644
1645 misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
1646 if (misc & ATOM_VSYNC_POLARITY)
1647 lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1648 if (misc & ATOM_HSYNC_POLARITY)
1649 lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1650 if (misc & ATOM_COMPOSITESYNC)
1651 lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
1652 if (misc & ATOM_INTERLACE)
1653 lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
1654 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1655 lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
1656
Cédric Cano45894332011-02-11 19:45:37 -05001657 lvds->native_mode.width_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageHSize);
1658 lvds->native_mode.height_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageVSize);
Alex Deucher7a868e12010-12-08 22:13:05 -05001659
Alex Deucherde2103e2009-10-09 15:14:30 -04001660 /* set crtc values */
1661 drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001662
Alex Deucherba032a52010-10-04 17:13:01 -04001663 lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
Alex Deucherebbe1cb2009-10-16 11:15:25 -04001664
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001665 encoder->native_mode = lvds->native_mode;
Alex Deucher5137ee92010-08-12 18:58:47 -04001666
1667 if (encoder_enum == 2)
1668 lvds->linkb = true;
1669 else
1670 lvds->linkb = false;
1671
Alex Deucherc324acd2010-12-08 22:13:06 -05001672 /* parse the lcd record table */
Cédric Cano45894332011-02-11 19:45:37 -05001673 if (le16_to_cpu(lvds_info->info.usModePatchTableOffset)) {
Alex Deucherc324acd2010-12-08 22:13:06 -05001674 ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
1675 ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
1676 bool bad_record = false;
Alex Deucher05fa7ea2011-05-11 14:02:07 -04001677 u8 *record;
1678
1679 if ((frev == 1) && (crev < 2))
1680 /* absolute */
1681 record = (u8 *)(mode_info->atom_context->bios +
1682 le16_to_cpu(lvds_info->info.usModePatchTableOffset));
1683 else
1684 /* relative */
1685 record = (u8 *)(mode_info->atom_context->bios +
1686 data_offset +
1687 le16_to_cpu(lvds_info->info.usModePatchTableOffset));
Alex Deucherc324acd2010-12-08 22:13:06 -05001688 while (*record != ATOM_RECORD_END_TYPE) {
1689 switch (*record) {
1690 case LCD_MODE_PATCH_RECORD_MODE_TYPE:
1691 record += sizeof(ATOM_PATCH_RECORD_MODE);
1692 break;
1693 case LCD_RTS_RECORD_TYPE:
1694 record += sizeof(ATOM_LCD_RTS_RECORD);
1695 break;
1696 case LCD_CAP_RECORD_TYPE:
1697 record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
1698 break;
1699 case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
1700 fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
1701 if (fake_edid_record->ucFakeEDIDLength) {
1702 struct edid *edid;
1703 int edid_size =
1704 max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
1705 edid = kmalloc(edid_size, GFP_KERNEL);
1706 if (edid) {
1707 memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
1708 fake_edid_record->ucFakeEDIDLength);
1709
Dave Airlieeaa4f5e2011-05-01 20:16:30 +10001710 if (drm_edid_is_valid(edid)) {
Alex Deucherc324acd2010-12-08 22:13:06 -05001711 rdev->mode_info.bios_hardcoded_edid = edid;
Dave Airlieeaa4f5e2011-05-01 20:16:30 +10001712 rdev->mode_info.bios_hardcoded_edid_size = edid_size;
1713 } else
Alex Deucherc324acd2010-12-08 22:13:06 -05001714 kfree(edid);
1715 }
1716 }
Alex Deucher95663942013-08-20 14:59:01 -04001717 record += fake_edid_record->ucFakeEDIDLength ?
1718 fake_edid_record->ucFakeEDIDLength + 2 :
1719 sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
Alex Deucherc324acd2010-12-08 22:13:06 -05001720 break;
1721 case LCD_PANEL_RESOLUTION_RECORD_TYPE:
1722 panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
1723 lvds->native_mode.width_mm = panel_res_record->usHSize;
1724 lvds->native_mode.height_mm = panel_res_record->usVSize;
1725 record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
1726 break;
1727 default:
1728 DRM_ERROR("Bad LCD record %d\n", *record);
1729 bad_record = true;
1730 break;
1731 }
1732 if (bad_record)
1733 break;
1734 }
1735 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001736 }
1737 return lvds;
1738}
1739
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001740struct radeon_encoder_primary_dac *
1741radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
1742{
1743 struct drm_device *dev = encoder->base.dev;
1744 struct radeon_device *rdev = dev->dev_private;
1745 struct radeon_mode_info *mode_info = &rdev->mode_info;
1746 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1747 uint16_t data_offset;
1748 struct _COMPASSIONATE_DATA *dac_info;
1749 uint8_t frev, crev;
1750 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001751 struct radeon_encoder_primary_dac *p_dac = NULL;
1752
Alex Deuchera084e6e2010-03-18 01:04:01 -04001753 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1754 &frev, &crev, &data_offset)) {
1755 dac_info = (struct _COMPASSIONATE_DATA *)
1756 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001757
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001758 p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
1759
1760 if (!p_dac)
1761 return NULL;
1762
1763 bg = dac_info->ucDAC1_BG_Adjustment;
1764 dac = dac_info->ucDAC1_DAC_Adjustment;
1765 p_dac->ps2_pdac_adj = (bg << 8) | (dac);
1766
1767 }
1768 return p_dac;
1769}
1770
Dave Airlie4ce001a2009-08-13 16:32:14 +10001771bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001772 struct drm_display_mode *mode)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001773{
1774 struct radeon_mode_info *mode_info = &rdev->mode_info;
1775 ATOM_ANALOG_TV_INFO *tv_info;
1776 ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
1777 ATOM_DTD_FORMAT *dtd_timings;
1778 int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1779 u8 frev, crev;
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001780 u16 data_offset, misc;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001781
Alex Deuchera084e6e2010-03-18 01:04:01 -04001782 if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
1783 &frev, &crev, &data_offset))
1784 return false;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001785
1786 switch (crev) {
1787 case 1:
1788 tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001789 if (index >= MAX_SUPPORTED_TV_TIMING)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001790 return false;
1791
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001792 mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
1793 mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
1794 mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
1795 mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
1796 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001797
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001798 mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
1799 mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
1800 mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
1801 mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
1802 le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001803
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001804 mode->flags = 0;
1805 misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
1806 if (misc & ATOM_VSYNC_POLARITY)
1807 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1808 if (misc & ATOM_HSYNC_POLARITY)
1809 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1810 if (misc & ATOM_COMPOSITESYNC)
1811 mode->flags |= DRM_MODE_FLAG_CSYNC;
1812 if (misc & ATOM_INTERLACE)
1813 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1814 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1815 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001816
Ville Syrjälä265d09a2013-10-27 21:20:10 +02001817 mode->crtc_clock = mode->clock =
1818 le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001819
1820 if (index == 1) {
1821 /* PAL timings appear to have wrong values for totals */
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001822 mode->crtc_htotal -= 1;
1823 mode->crtc_vtotal -= 1;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001824 }
1825 break;
1826 case 2:
1827 tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
Dan Carpenter0031c412010-04-27 14:11:04 -07001828 if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001829 return false;
1830
1831 dtd_timings = &tv_info_v1_2->aModeTimings[index];
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001832 mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
1833 le16_to_cpu(dtd_timings->usHBlanking_Time);
1834 mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
1835 mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
1836 le16_to_cpu(dtd_timings->usHSyncOffset);
1837 mode->crtc_hsync_end = mode->crtc_hsync_start +
1838 le16_to_cpu(dtd_timings->usHSyncWidth);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001839
Alex Deucher5a9bcac2009-10-08 15:09:31 -04001840 mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
1841 le16_to_cpu(dtd_timings->usVBlanking_Time);
1842 mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
1843 mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
1844 le16_to_cpu(dtd_timings->usVSyncOffset);
1845 mode->crtc_vsync_end = mode->crtc_vsync_start +
1846 le16_to_cpu(dtd_timings->usVSyncWidth);
1847
1848 mode->flags = 0;
1849 misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
1850 if (misc & ATOM_VSYNC_POLARITY)
1851 mode->flags |= DRM_MODE_FLAG_NVSYNC;
1852 if (misc & ATOM_HSYNC_POLARITY)
1853 mode->flags |= DRM_MODE_FLAG_NHSYNC;
1854 if (misc & ATOM_COMPOSITESYNC)
1855 mode->flags |= DRM_MODE_FLAG_CSYNC;
1856 if (misc & ATOM_INTERLACE)
1857 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1858 if (misc & ATOM_DOUBLE_CLOCK_MODE)
1859 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
1860
Ville Syrjälä265d09a2013-10-27 21:20:10 +02001861 mode->crtc_clock = mode->clock =
1862 le16_to_cpu(dtd_timings->usPixClk) * 10;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001863 break;
1864 }
1865 return true;
1866}
1867
Alex Deucherd79766f2009-12-17 19:00:29 -05001868enum radeon_tv_std
1869radeon_atombios_get_tv_info(struct radeon_device *rdev)
1870{
1871 struct radeon_mode_info *mode_info = &rdev->mode_info;
1872 int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
1873 uint16_t data_offset;
1874 uint8_t frev, crev;
1875 struct _ATOM_ANALOG_TV_INFO *tv_info;
1876 enum radeon_tv_std tv_std = TV_STD_NTSC;
1877
Alex Deuchera084e6e2010-03-18 01:04:01 -04001878 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1879 &frev, &crev, &data_offset)) {
Alex Deucherd79766f2009-12-17 19:00:29 -05001880
Alex Deuchera084e6e2010-03-18 01:04:01 -04001881 tv_info = (struct _ATOM_ANALOG_TV_INFO *)
1882 (mode_info->atom_context->bios + data_offset);
Alex Deucherd79766f2009-12-17 19:00:29 -05001883
Alex Deuchera084e6e2010-03-18 01:04:01 -04001884 switch (tv_info->ucTV_BootUpDefaultStandard) {
1885 case ATOM_TV_NTSC:
1886 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001887 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001888 break;
1889 case ATOM_TV_NTSCJ:
1890 tv_std = TV_STD_NTSC_J;
Alex Deucher40f76d82010-10-07 22:38:42 -04001891 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001892 break;
1893 case ATOM_TV_PAL:
1894 tv_std = TV_STD_PAL;
Alex Deucher40f76d82010-10-07 22:38:42 -04001895 DRM_DEBUG_KMS("Default TV standard: PAL\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001896 break;
1897 case ATOM_TV_PALM:
1898 tv_std = TV_STD_PAL_M;
Alex Deucher40f76d82010-10-07 22:38:42 -04001899 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001900 break;
1901 case ATOM_TV_PALN:
1902 tv_std = TV_STD_PAL_N;
Alex Deucher40f76d82010-10-07 22:38:42 -04001903 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001904 break;
1905 case ATOM_TV_PALCN:
1906 tv_std = TV_STD_PAL_CN;
Alex Deucher40f76d82010-10-07 22:38:42 -04001907 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001908 break;
1909 case ATOM_TV_PAL60:
1910 tv_std = TV_STD_PAL_60;
Alex Deucher40f76d82010-10-07 22:38:42 -04001911 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001912 break;
1913 case ATOM_TV_SECAM:
1914 tv_std = TV_STD_SECAM;
Alex Deucher40f76d82010-10-07 22:38:42 -04001915 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001916 break;
1917 default:
1918 tv_std = TV_STD_NTSC;
Alex Deucher40f76d82010-10-07 22:38:42 -04001919 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
Alex Deuchera084e6e2010-03-18 01:04:01 -04001920 break;
1921 }
Alex Deucherd79766f2009-12-17 19:00:29 -05001922 }
1923 return tv_std;
1924}
1925
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001926struct radeon_encoder_tv_dac *
1927radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
1928{
1929 struct drm_device *dev = encoder->base.dev;
1930 struct radeon_device *rdev = dev->dev_private;
1931 struct radeon_mode_info *mode_info = &rdev->mode_info;
1932 int index = GetIndexIntoMasterTable(DATA, CompassionateData);
1933 uint16_t data_offset;
1934 struct _COMPASSIONATE_DATA *dac_info;
1935 uint8_t frev, crev;
1936 uint8_t bg, dac;
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001937 struct radeon_encoder_tv_dac *tv_dac = NULL;
1938
Alex Deuchera084e6e2010-03-18 01:04:01 -04001939 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
1940 &frev, &crev, &data_offset)) {
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001941
Alex Deuchera084e6e2010-03-18 01:04:01 -04001942 dac_info = (struct _COMPASSIONATE_DATA *)
1943 (mode_info->atom_context->bios + data_offset);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001944
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001945 tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
1946
1947 if (!tv_dac)
1948 return NULL;
1949
1950 bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
1951 dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
1952 tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
1953
1954 bg = dac_info->ucDAC2_PAL_BG_Adjustment;
1955 dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
1956 tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
1957
1958 bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
1959 dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
1960 tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
1961
Alex Deucherd79766f2009-12-17 19:00:29 -05001962 tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001963 }
1964 return tv_dac;
1965}
1966
Alex Deucher29fb52c2010-03-11 10:01:17 -05001967static const char *thermal_controller_names[] = {
1968 "NONE",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001969 "lm63",
1970 "adm1032",
1971 "adm1030",
1972 "max6649",
Alex Deucher5dc35532014-07-27 23:21:50 -04001973 "lm63", /* lm64 */
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001974 "f75375",
1975 "asc7xxx",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001976};
1977
1978static const char *pp_lib_thermal_controller_names[] = {
1979 "NONE",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001980 "lm63",
1981 "adm1032",
1982 "adm1030",
1983 "max6649",
Alex Deucher5dc35532014-07-27 23:21:50 -04001984 "lm63", /* lm64 */
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001985 "f75375",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001986 "RV6xx",
1987 "RV770",
Alex Deucher678e7dfa2010-04-22 14:17:56 -04001988 "adt7473",
Alex Deucher560154e2010-11-22 17:56:34 -05001989 "NONE",
Alex Deucher49f65982010-03-24 16:39:45 -04001990 "External GPIO",
1991 "Evergreen",
Alex Deucherb0e66412010-11-22 17:56:35 -05001992 "emc2103",
1993 "Sumo",
Alex Deucher4fddba12011-01-06 21:19:22 -05001994 "Northern Islands",
Alex Deucher14607d02012-03-20 17:18:09 -04001995 "Southern Islands",
1996 "lm96163",
Alex Deucher51150202012-12-18 22:07:14 -05001997 "Sea Islands",
Alex Deucher29fb52c2010-03-11 10:01:17 -05001998};
1999
Alex Deucher56278a82009-12-28 13:58:44 -05002000union power_info {
2001 struct _ATOM_POWERPLAY_INFO info;
2002 struct _ATOM_POWERPLAY_INFO_V2 info_2;
2003 struct _ATOM_POWERPLAY_INFO_V3 info_3;
Alex Deucher560154e2010-11-22 17:56:34 -05002004 struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
Alex Deucherb0e66412010-11-22 17:56:35 -05002005 struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
2006 struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
Alex Deucher56278a82009-12-28 13:58:44 -05002007};
2008
Alex Deucher560154e2010-11-22 17:56:34 -05002009union pplib_clock_info {
2010 struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
2011 struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
2012 struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
Alex Deucherb0e66412010-11-22 17:56:35 -05002013 struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
Alex Deucher14607d02012-03-20 17:18:09 -04002014 struct _ATOM_PPLIB_SI_CLOCK_INFO si;
Alex Deucherbc19f592013-06-07 11:41:05 -04002015 struct _ATOM_PPLIB_CI_CLOCK_INFO ci;
Alex Deucher560154e2010-11-22 17:56:34 -05002016};
2017
2018union pplib_power_state {
2019 struct _ATOM_PPLIB_STATE v1;
2020 struct _ATOM_PPLIB_STATE_V2 v2;
2021};
2022
2023static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
2024 int state_index,
2025 u32 misc, u32 misc2)
2026{
2027 rdev->pm.power_state[state_index].misc = misc;
2028 rdev->pm.power_state[state_index].misc2 = misc2;
2029 /* order matters! */
2030 if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
2031 rdev->pm.power_state[state_index].type =
2032 POWER_STATE_TYPE_POWERSAVE;
2033 if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
2034 rdev->pm.power_state[state_index].type =
2035 POWER_STATE_TYPE_BATTERY;
2036 if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
2037 rdev->pm.power_state[state_index].type =
2038 POWER_STATE_TYPE_BATTERY;
2039 if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
2040 rdev->pm.power_state[state_index].type =
2041 POWER_STATE_TYPE_BALANCED;
2042 if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
2043 rdev->pm.power_state[state_index].type =
2044 POWER_STATE_TYPE_PERFORMANCE;
2045 rdev->pm.power_state[state_index].flags &=
2046 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2047 }
2048 if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
2049 rdev->pm.power_state[state_index].type =
2050 POWER_STATE_TYPE_BALANCED;
2051 if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
2052 rdev->pm.power_state[state_index].type =
2053 POWER_STATE_TYPE_DEFAULT;
2054 rdev->pm.default_power_state_index = state_index;
2055 rdev->pm.power_state[state_index].default_clock_mode =
2056 &rdev->pm.power_state[state_index].clock_info[0];
2057 } else if (state_index == 0) {
2058 rdev->pm.power_state[state_index].clock_info[0].flags |=
2059 RADEON_PM_MODE_NO_DISPLAY;
2060 }
2061}
2062
2063static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
2064{
2065 struct radeon_mode_info *mode_info = &rdev->mode_info;
2066 u32 misc, misc2 = 0;
2067 int num_modes = 0, i;
2068 int state_index = 0;
2069 struct radeon_i2c_bus_rec i2c_bus;
2070 union power_info *power_info;
2071 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2072 u16 data_offset;
2073 u8 frev, crev;
2074
2075 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2076 &frev, &crev, &data_offset))
2077 return state_index;
2078 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2079
2080 /* add the i2c bus for thermal/fan chip */
Alex Deucher4755fab2012-08-30 13:30:49 -04002081 if ((power_info->info.ucOverdriveThermalController > 0) &&
2082 (power_info->info.ucOverdriveThermalController < ARRAY_SIZE(thermal_controller_names))) {
Alex Deucher560154e2010-11-22 17:56:34 -05002083 DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2084 thermal_controller_names[power_info->info.ucOverdriveThermalController],
2085 power_info->info.ucOverdriveControllerAddress >> 1);
2086 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
2087 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2088 if (rdev->pm.i2c_bus) {
2089 struct i2c_board_info info = { };
2090 const char *name = thermal_controller_names[power_info->info.
2091 ucOverdriveThermalController];
2092 info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
2093 strlcpy(info.type, name, sizeof(info.type));
2094 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2095 }
2096 }
2097 num_modes = power_info->info.ucNumOfPowerModeEntries;
2098 if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
2099 num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
Alex Deucherf8e6bfc2013-04-25 09:29:17 -04002100 if (num_modes == 0)
2101 return state_index;
Alex Deucher0975b162011-02-02 18:42:03 -05002102 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
2103 if (!rdev->pm.power_state)
2104 return state_index;
Alex Deucher560154e2010-11-22 17:56:34 -05002105 /* last mode is usually default, array is low to high */
2106 for (i = 0; i < num_modes; i++) {
Alex Deucher6991b8f2011-11-14 17:52:51 -05002107 rdev->pm.power_state[state_index].clock_info =
2108 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2109 if (!rdev->pm.power_state[state_index].clock_info)
2110 return state_index;
2111 rdev->pm.power_state[state_index].num_clock_modes = 1;
Alex Deucher560154e2010-11-22 17:56:34 -05002112 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2113 switch (frev) {
2114 case 1:
Alex Deucher560154e2010-11-22 17:56:34 -05002115 rdev->pm.power_state[state_index].clock_info[0].mclk =
2116 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
2117 rdev->pm.power_state[state_index].clock_info[0].sclk =
2118 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
2119 /* skip invalid modes */
2120 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2121 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2122 continue;
2123 rdev->pm.power_state[state_index].pcie_lanes =
2124 power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
2125 misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
2126 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2127 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2128 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2129 VOLTAGE_GPIO;
2130 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2131 radeon_lookup_gpio(rdev,
2132 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
2133 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2134 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2135 true;
2136 else
2137 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2138 false;
2139 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2140 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2141 VOLTAGE_VDDC;
2142 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2143 power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
2144 }
2145 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2146 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
2147 state_index++;
2148 break;
2149 case 2:
Alex Deucher560154e2010-11-22 17:56:34 -05002150 rdev->pm.power_state[state_index].clock_info[0].mclk =
2151 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
2152 rdev->pm.power_state[state_index].clock_info[0].sclk =
2153 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
2154 /* skip invalid modes */
2155 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2156 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2157 continue;
2158 rdev->pm.power_state[state_index].pcie_lanes =
2159 power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
2160 misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
2161 misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
2162 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2163 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2164 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2165 VOLTAGE_GPIO;
2166 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2167 radeon_lookup_gpio(rdev,
2168 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
2169 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2170 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2171 true;
2172 else
2173 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2174 false;
2175 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2176 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2177 VOLTAGE_VDDC;
2178 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2179 power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
2180 }
2181 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2182 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2183 state_index++;
2184 break;
2185 case 3:
Alex Deucher560154e2010-11-22 17:56:34 -05002186 rdev->pm.power_state[state_index].clock_info[0].mclk =
2187 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
2188 rdev->pm.power_state[state_index].clock_info[0].sclk =
2189 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
2190 /* skip invalid modes */
2191 if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
2192 (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
2193 continue;
2194 rdev->pm.power_state[state_index].pcie_lanes =
2195 power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
2196 misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
2197 misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
2198 if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
2199 (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
2200 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2201 VOLTAGE_GPIO;
2202 rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
2203 radeon_lookup_gpio(rdev,
2204 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
2205 if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
2206 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2207 true;
2208 else
2209 rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
2210 false;
2211 } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
2212 rdev->pm.power_state[state_index].clock_info[0].voltage.type =
2213 VOLTAGE_VDDC;
2214 rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
2215 power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
2216 if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
2217 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
2218 true;
2219 rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
2220 power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
2221 }
2222 }
2223 rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2224 radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2225 state_index++;
2226 break;
2227 }
2228 }
2229 /* last mode is usually default */
2230 if (rdev->pm.default_power_state_index == -1) {
2231 rdev->pm.power_state[state_index - 1].type =
2232 POWER_STATE_TYPE_DEFAULT;
2233 rdev->pm.default_power_state_index = state_index - 1;
2234 rdev->pm.power_state[state_index - 1].default_clock_mode =
2235 &rdev->pm.power_state[state_index - 1].clock_info[0];
2236 rdev->pm.power_state[state_index].flags &=
2237 ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2238 rdev->pm.power_state[state_index].misc = 0;
2239 rdev->pm.power_state[state_index].misc2 = 0;
2240 }
2241 return state_index;
2242}
2243
2244static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
2245 ATOM_PPLIB_THERMALCONTROLLER *controller)
2246{
2247 struct radeon_i2c_bus_rec i2c_bus;
2248
2249 /* add the i2c bus for thermal/fan chip */
2250 if (controller->ucType > 0) {
2251 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
2252 DRM_INFO("Internal thermal controller %s fan control\n",
2253 (controller->ucFanParameters &
2254 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2255 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
2256 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
2257 DRM_INFO("Internal thermal controller %s fan control\n",
2258 (controller->ucFanParameters &
2259 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2260 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
2261 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
2262 DRM_INFO("Internal thermal controller %s fan control\n",
2263 (controller->ucFanParameters &
2264 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2265 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
Alex Deucherb0e66412010-11-22 17:56:35 -05002266 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
2267 DRM_INFO("Internal thermal controller %s fan control\n",
2268 (controller->ucFanParameters &
2269 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2270 rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
Alex Deucher4fddba12011-01-06 21:19:22 -05002271 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
2272 DRM_INFO("Internal thermal controller %s fan control\n",
2273 (controller->ucFanParameters &
2274 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2275 rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
Alex Deucher14607d02012-03-20 17:18:09 -04002276 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) {
2277 DRM_INFO("Internal thermal controller %s fan control\n",
2278 (controller->ucFanParameters &
2279 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2280 rdev->pm.int_thermal_type = THERMAL_TYPE_SI;
Alex Deucher51150202012-12-18 22:07:14 -05002281 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_CISLANDS) {
2282 DRM_INFO("Internal thermal controller %s fan control\n",
2283 (controller->ucFanParameters &
2284 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2285 rdev->pm.int_thermal_type = THERMAL_TYPE_CI;
Alex Deucher16fbe002013-04-22 21:41:26 -04002286 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_KAVERI) {
2287 DRM_INFO("Internal thermal controller %s fan control\n",
2288 (controller->ucFanParameters &
2289 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2290 rdev->pm.int_thermal_type = THERMAL_TYPE_KV;
Alex Deucher560154e2010-11-22 17:56:34 -05002291 } else if ((controller->ucType ==
2292 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
2293 (controller->ucType ==
Alex Deucherb0e66412010-11-22 17:56:35 -05002294 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
2295 (controller->ucType ==
2296 ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002297 DRM_INFO("Special thermal controller config\n");
Alex Deucher4755fab2012-08-30 13:30:49 -04002298 } else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002299 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2300 pp_lib_thermal_controller_names[controller->ucType],
2301 controller->ucI2cAddress >> 1,
2302 (controller->ucFanParameters &
2303 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2304 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
2305 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2306 if (rdev->pm.i2c_bus) {
2307 struct i2c_board_info info = { };
2308 const char *name = pp_lib_thermal_controller_names[controller->ucType];
2309 info.addr = controller->ucI2cAddress >> 1;
2310 strlcpy(info.type, name, sizeof(info.type));
2311 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2312 }
Alex Deucher4755fab2012-08-30 13:30:49 -04002313 } else {
2314 DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
2315 controller->ucType,
2316 controller->ucI2cAddress >> 1,
2317 (controller->ucFanParameters &
2318 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
Alex Deucher560154e2010-11-22 17:56:34 -05002319 }
2320 }
2321}
2322
Alex Deucher4a6369e2013-04-12 14:04:10 -04002323void radeon_atombios_get_default_voltages(struct radeon_device *rdev,
Alex Deucher2abba662013-03-25 12:47:23 -04002324 u16 *vddc, u16 *vddci, u16 *mvdd)
Alex Deucher560154e2010-11-22 17:56:34 -05002325{
2326 struct radeon_mode_info *mode_info = &rdev->mode_info;
2327 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
2328 u8 frev, crev;
2329 u16 data_offset;
2330 union firmware_info *firmware_info;
Alex Deucher2feea492011-04-12 14:49:24 -04002331
2332 *vddc = 0;
2333 *vddci = 0;
Alex Deucher2abba662013-03-25 12:47:23 -04002334 *mvdd = 0;
Alex Deucher560154e2010-11-22 17:56:34 -05002335
2336 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2337 &frev, &crev, &data_offset)) {
2338 firmware_info =
2339 (union firmware_info *)(mode_info->atom_context->bios +
2340 data_offset);
Alex Deucher2feea492011-04-12 14:49:24 -04002341 *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
Alex Deucher2abba662013-03-25 12:47:23 -04002342 if ((frev == 2) && (crev >= 2)) {
Alex Deucher2feea492011-04-12 14:49:24 -04002343 *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
Alex Deucher2abba662013-03-25 12:47:23 -04002344 *mvdd = le16_to_cpu(firmware_info->info_22.usBootUpMVDDCVoltage);
2345 }
Alex Deucher560154e2010-11-22 17:56:34 -05002346 }
Alex Deucher560154e2010-11-22 17:56:34 -05002347}
2348
2349static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
2350 int state_index, int mode_index,
2351 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
2352{
2353 int j;
2354 u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
2355 u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
Alex Deucher2abba662013-03-25 12:47:23 -04002356 u16 vddc, vddci, mvdd;
Alex Deucher2feea492011-04-12 14:49:24 -04002357
Alex Deucher2abba662013-03-25 12:47:23 -04002358 radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd);
Alex Deucher560154e2010-11-22 17:56:34 -05002359
2360 rdev->pm.power_state[state_index].misc = misc;
2361 rdev->pm.power_state[state_index].misc2 = misc2;
2362 rdev->pm.power_state[state_index].pcie_lanes =
2363 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2364 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2365 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2366 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2367 rdev->pm.power_state[state_index].type =
2368 POWER_STATE_TYPE_BATTERY;
2369 break;
2370 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2371 rdev->pm.power_state[state_index].type =
2372 POWER_STATE_TYPE_BALANCED;
2373 break;
2374 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2375 rdev->pm.power_state[state_index].type =
2376 POWER_STATE_TYPE_PERFORMANCE;
2377 break;
2378 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2379 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2380 rdev->pm.power_state[state_index].type =
2381 POWER_STATE_TYPE_PERFORMANCE;
2382 break;
2383 }
2384 rdev->pm.power_state[state_index].flags = 0;
2385 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2386 rdev->pm.power_state[state_index].flags |=
2387 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2388 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
2389 rdev->pm.power_state[state_index].type =
2390 POWER_STATE_TYPE_DEFAULT;
2391 rdev->pm.default_power_state_index = state_index;
2392 rdev->pm.power_state[state_index].default_clock_mode =
2393 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
Alex Deucher982cb322013-04-29 10:51:26 -04002394 if ((rdev->family >= CHIP_BARTS) && !(rdev->flags & RADEON_IS_IGP)) {
Alex Deucher9ace9f72011-01-06 21:19:26 -05002395 /* NI chips post without MC ucode, so default clocks are strobe mode only */
2396 rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
2397 rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
2398 rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
Alex Deucher2feea492011-04-12 14:49:24 -04002399 rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
Alex Deucher9ace9f72011-01-06 21:19:26 -05002400 } else {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04002401 u16 max_vddci = 0;
2402
2403 if (ASIC_IS_DCE4(rdev))
2404 radeon_atom_get_max_voltage(rdev,
2405 SET_VOLTAGE_TYPE_ASIC_VDDCI,
2406 &max_vddci);
2407 /* patch the table values with the default sclk/mclk from firmware info */
Alex Deucher9ace9f72011-01-06 21:19:26 -05002408 for (j = 0; j < mode_index; j++) {
2409 rdev->pm.power_state[state_index].clock_info[j].mclk =
2410 rdev->clock.default_mclk;
2411 rdev->pm.power_state[state_index].clock_info[j].sclk =
2412 rdev->clock.default_sclk;
2413 if (vddc)
2414 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2415 vddc;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04002416 if (max_vddci)
2417 rdev->pm.power_state[state_index].clock_info[j].voltage.vddci =
2418 max_vddci;
Alex Deucher9ace9f72011-01-06 21:19:26 -05002419 }
Alex Deucher560154e2010-11-22 17:56:34 -05002420 }
2421 }
2422}
2423
2424static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
2425 int state_index, int mode_index,
2426 union pplib_clock_info *clock_info)
2427{
2428 u32 sclk, mclk;
Alex Deuchere83753b2012-03-20 17:18:08 -04002429 u16 vddc;
Alex Deucher560154e2010-11-22 17:56:34 -05002430
2431 if (rdev->flags & RADEON_IS_IGP) {
Alex Deucherb0e66412010-11-22 17:56:35 -05002432 if (rdev->family >= CHIP_PALM) {
2433 sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
2434 sclk |= clock_info->sumo.ucEngineClockHigh << 16;
2435 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2436 } else {
2437 sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
2438 sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
2439 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2440 }
Alex Deucherbc19f592013-06-07 11:41:05 -04002441 } else if (rdev->family >= CHIP_BONAIRE) {
2442 sclk = le16_to_cpu(clock_info->ci.usEngineClockLow);
2443 sclk |= clock_info->ci.ucEngineClockHigh << 16;
2444 mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow);
2445 mclk |= clock_info->ci.ucMemoryClockHigh << 16;
2446 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2447 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2448 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2449 VOLTAGE_NONE;
Alex Deucher982cb322013-04-29 10:51:26 -04002450 } else if (rdev->family >= CHIP_TAHITI) {
Alex Deucher14607d02012-03-20 17:18:09 -04002451 sclk = le16_to_cpu(clock_info->si.usEngineClockLow);
2452 sclk |= clock_info->si.ucEngineClockHigh << 16;
2453 mclk = le16_to_cpu(clock_info->si.usMemoryClockLow);
2454 mclk |= clock_info->si.ucMemoryClockHigh << 16;
2455 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2456 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2457 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2458 VOLTAGE_SW;
2459 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2460 le16_to_cpu(clock_info->si.usVDDC);
2461 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
2462 le16_to_cpu(clock_info->si.usVDDCI);
Alex Deucher982cb322013-04-29 10:51:26 -04002463 } else if (rdev->family >= CHIP_CEDAR) {
Alex Deucher560154e2010-11-22 17:56:34 -05002464 sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
2465 sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
2466 mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
2467 mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
2468 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2469 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2470 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2471 VOLTAGE_SW;
2472 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
Cédric Cano45894332011-02-11 19:45:37 -05002473 le16_to_cpu(clock_info->evergreen.usVDDC);
Alex Deucher2feea492011-04-12 14:49:24 -04002474 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
2475 le16_to_cpu(clock_info->evergreen.usVDDCI);
Alex Deucher560154e2010-11-22 17:56:34 -05002476 } else {
2477 sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
2478 sclk |= clock_info->r600.ucEngineClockHigh << 16;
2479 mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
2480 mclk |= clock_info->r600.ucMemoryClockHigh << 16;
2481 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2482 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2483 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2484 VOLTAGE_SW;
2485 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
Cédric Cano45894332011-02-11 19:45:37 -05002486 le16_to_cpu(clock_info->r600.usVDDC);
Alex Deucher560154e2010-11-22 17:56:34 -05002487 }
2488
Alex Deucheree4017f2011-06-23 12:19:32 -04002489 /* patch up vddc if necessary */
Alex Deuchere83753b2012-03-20 17:18:08 -04002490 switch (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage) {
2491 case ATOM_VIRTUAL_VOLTAGE_ID0:
2492 case ATOM_VIRTUAL_VOLTAGE_ID1:
2493 case ATOM_VIRTUAL_VOLTAGE_ID2:
2494 case ATOM_VIRTUAL_VOLTAGE_ID3:
Alex Deucherc6cf7772013-07-05 13:14:30 -04002495 case ATOM_VIRTUAL_VOLTAGE_ID4:
2496 case ATOM_VIRTUAL_VOLTAGE_ID5:
2497 case ATOM_VIRTUAL_VOLTAGE_ID6:
2498 case ATOM_VIRTUAL_VOLTAGE_ID7:
Alex Deuchere83753b2012-03-20 17:18:08 -04002499 if (radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC,
2500 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage,
2501 &vddc) == 0)
Alex Deucheree4017f2011-06-23 12:19:32 -04002502 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
Alex Deuchere83753b2012-03-20 17:18:08 -04002503 break;
2504 default:
2505 break;
Alex Deucheree4017f2011-06-23 12:19:32 -04002506 }
2507
Alex Deucher560154e2010-11-22 17:56:34 -05002508 if (rdev->flags & RADEON_IS_IGP) {
2509 /* skip invalid modes */
2510 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2511 return false;
2512 } else {
2513 /* skip invalid modes */
2514 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2515 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2516 return false;
2517 }
2518 return true;
2519}
2520
2521static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
2522{
2523 struct radeon_mode_info *mode_info = &rdev->mode_info;
2524 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2525 union pplib_power_state *power_state;
2526 int i, j;
2527 int state_index = 0, mode_index = 0;
2528 union pplib_clock_info *clock_info;
2529 bool valid;
2530 union power_info *power_info;
2531 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2532 u16 data_offset;
2533 u8 frev, crev;
2534
2535 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2536 &frev, &crev, &data_offset))
2537 return state_index;
2538 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2539
2540 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
Alex Deucherf8e6bfc2013-04-25 09:29:17 -04002541 if (power_info->pplib.ucNumStates == 0)
2542 return state_index;
Alex Deucher0975b162011-02-02 18:42:03 -05002543 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2544 power_info->pplib.ucNumStates, GFP_KERNEL);
2545 if (!rdev->pm.power_state)
2546 return state_index;
Alex Deucher560154e2010-11-22 17:56:34 -05002547 /* first mode is usually default, followed by low to high */
2548 for (i = 0; i < power_info->pplib.ucNumStates; i++) {
2549 mode_index = 0;
2550 power_state = (union pplib_power_state *)
2551 (mode_info->atom_context->bios + data_offset +
2552 le16_to_cpu(power_info->pplib.usStateArrayOffset) +
2553 i * power_info->pplib.ucStateEntrySize);
2554 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2555 (mode_info->atom_context->bios + data_offset +
2556 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
2557 (power_state->v1.ucNonClockStateIndex *
2558 power_info->pplib.ucNonClockSize));
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002559 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2560 ((power_info->pplib.ucStateEntrySize - 1) ?
2561 (power_info->pplib.ucStateEntrySize - 1) : 1),
2562 GFP_KERNEL);
2563 if (!rdev->pm.power_state[i].clock_info)
2564 return state_index;
2565 if (power_info->pplib.ucStateEntrySize - 1) {
2566 for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
2567 clock_info = (union pplib_clock_info *)
2568 (mode_info->atom_context->bios + data_offset +
2569 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
2570 (power_state->v1.ucClockStateIndices[j] *
2571 power_info->pplib.ucClockInfoSize));
2572 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2573 state_index, mode_index,
2574 clock_info);
2575 if (valid)
2576 mode_index++;
2577 }
2578 } else {
2579 rdev->pm.power_state[state_index].clock_info[0].mclk =
2580 rdev->clock.default_mclk;
2581 rdev->pm.power_state[state_index].clock_info[0].sclk =
2582 rdev->clock.default_sclk;
2583 mode_index++;
Alex Deucher560154e2010-11-22 17:56:34 -05002584 }
2585 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2586 if (mode_index) {
2587 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2588 non_clock_info);
2589 state_index++;
2590 }
2591 }
2592 /* if multiple clock modes, mark the lowest as no display */
2593 for (i = 0; i < state_index; i++) {
2594 if (rdev->pm.power_state[i].num_clock_modes > 1)
2595 rdev->pm.power_state[i].clock_info[0].flags |=
2596 RADEON_PM_MODE_NO_DISPLAY;
2597 }
2598 /* first mode is usually default */
2599 if (rdev->pm.default_power_state_index == -1) {
2600 rdev->pm.power_state[0].type =
2601 POWER_STATE_TYPE_DEFAULT;
2602 rdev->pm.default_power_state_index = 0;
2603 rdev->pm.power_state[0].default_clock_mode =
2604 &rdev->pm.power_state[0].clock_info[0];
2605 }
2606 return state_index;
2607}
2608
Alex Deucherb0e66412010-11-22 17:56:35 -05002609static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
2610{
2611 struct radeon_mode_info *mode_info = &rdev->mode_info;
2612 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2613 union pplib_power_state *power_state;
2614 int i, j, non_clock_array_index, clock_array_index;
2615 int state_index = 0, mode_index = 0;
2616 union pplib_clock_info *clock_info;
Alex Deucherf7346882012-03-20 17:17:58 -04002617 struct _StateArray *state_array;
2618 struct _ClockInfoArray *clock_info_array;
2619 struct _NonClockInfoArray *non_clock_info_array;
Alex Deucherb0e66412010-11-22 17:56:35 -05002620 bool valid;
2621 union power_info *power_info;
2622 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2623 u16 data_offset;
2624 u8 frev, crev;
Alex Deucher441e76c2013-05-01 14:34:54 -04002625 u8 *power_state_offset;
Alex Deucherb0e66412010-11-22 17:56:35 -05002626
2627 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2628 &frev, &crev, &data_offset))
2629 return state_index;
2630 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2631
2632 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
Alex Deucherf7346882012-03-20 17:17:58 -04002633 state_array = (struct _StateArray *)
Alex Deucherb0e66412010-11-22 17:56:35 -05002634 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002635 le16_to_cpu(power_info->pplib.usStateArrayOffset));
Alex Deucherf7346882012-03-20 17:17:58 -04002636 clock_info_array = (struct _ClockInfoArray *)
Alex Deucherb0e66412010-11-22 17:56:35 -05002637 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002638 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
Alex Deucherf7346882012-03-20 17:17:58 -04002639 non_clock_info_array = (struct _NonClockInfoArray *)
Alex Deucherb0e66412010-11-22 17:56:35 -05002640 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002641 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
Alex Deucherf8e6bfc2013-04-25 09:29:17 -04002642 if (state_array->ucNumEntries == 0)
2643 return state_index;
Alex Deucher0975b162011-02-02 18:42:03 -05002644 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2645 state_array->ucNumEntries, GFP_KERNEL);
2646 if (!rdev->pm.power_state)
2647 return state_index;
Alex Deucher441e76c2013-05-01 14:34:54 -04002648 power_state_offset = (u8 *)state_array->states;
Alex Deucherb0e66412010-11-22 17:56:35 -05002649 for (i = 0; i < state_array->ucNumEntries; i++) {
2650 mode_index = 0;
Alex Deucher441e76c2013-05-01 14:34:54 -04002651 power_state = (union pplib_power_state *)power_state_offset;
2652 non_clock_array_index = power_state->v2.nonClockInfoIndex;
Alex Deucherb0e66412010-11-22 17:56:35 -05002653 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2654 &non_clock_info_array->nonClockInfo[non_clock_array_index];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002655 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2656 (power_state->v2.ucNumDPMLevels ?
2657 power_state->v2.ucNumDPMLevels : 1),
2658 GFP_KERNEL);
2659 if (!rdev->pm.power_state[i].clock_info)
2660 return state_index;
2661 if (power_state->v2.ucNumDPMLevels) {
2662 for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2663 clock_array_index = power_state->v2.clockInfoIndex[j];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002664 clock_info = (union pplib_clock_info *)
Alex Deucherf7346882012-03-20 17:17:58 -04002665 &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002666 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2667 state_index, mode_index,
2668 clock_info);
2669 if (valid)
2670 mode_index++;
2671 }
2672 } else {
2673 rdev->pm.power_state[state_index].clock_info[0].mclk =
2674 rdev->clock.default_mclk;
2675 rdev->pm.power_state[state_index].clock_info[0].sclk =
2676 rdev->clock.default_sclk;
2677 mode_index++;
Alex Deucherb0e66412010-11-22 17:56:35 -05002678 }
2679 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2680 if (mode_index) {
2681 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2682 non_clock_info);
2683 state_index++;
2684 }
Alex Deucher441e76c2013-05-01 14:34:54 -04002685 power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
Alex Deucherb0e66412010-11-22 17:56:35 -05002686 }
2687 /* if multiple clock modes, mark the lowest as no display */
2688 for (i = 0; i < state_index; i++) {
2689 if (rdev->pm.power_state[i].num_clock_modes > 1)
2690 rdev->pm.power_state[i].clock_info[0].flags |=
2691 RADEON_PM_MODE_NO_DISPLAY;
2692 }
2693 /* first mode is usually default */
2694 if (rdev->pm.default_power_state_index == -1) {
2695 rdev->pm.power_state[0].type =
2696 POWER_STATE_TYPE_DEFAULT;
2697 rdev->pm.default_power_state_index = 0;
2698 rdev->pm.power_state[0].default_clock_mode =
2699 &rdev->pm.power_state[0].clock_info[0];
2700 }
2701 return state_index;
2702}
2703
Alex Deucher56278a82009-12-28 13:58:44 -05002704void radeon_atombios_get_power_modes(struct radeon_device *rdev)
2705{
2706 struct radeon_mode_info *mode_info = &rdev->mode_info;
2707 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2708 u16 data_offset;
2709 u8 frev, crev;
Alex Deucher560154e2010-11-22 17:56:34 -05002710 int state_index = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002711
Alex Deuchera48b9b42010-04-22 14:03:55 -04002712 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05002713
Alex Deuchera084e6e2010-03-18 01:04:01 -04002714 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2715 &frev, &crev, &data_offset)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002716 switch (frev) {
2717 case 1:
2718 case 2:
2719 case 3:
2720 state_index = radeon_atombios_parse_power_table_1_3(rdev);
2721 break;
2722 case 4:
2723 case 5:
2724 state_index = radeon_atombios_parse_power_table_4_5(rdev);
2725 break;
Alex Deucherb0e66412010-11-22 17:56:35 -05002726 case 6:
2727 state_index = radeon_atombios_parse_power_table_6(rdev);
2728 break;
Alex Deucher560154e2010-11-22 17:56:34 -05002729 default:
2730 break;
Alex Deucher56278a82009-12-28 13:58:44 -05002731 }
Alex Deucherf8e6bfc2013-04-25 09:29:17 -04002732 }
2733
2734 if (state_index == 0) {
Alex Deucher0975b162011-02-02 18:42:03 -05002735 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
2736 if (rdev->pm.power_state) {
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002737 rdev->pm.power_state[0].clock_info =
2738 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2739 if (rdev->pm.power_state[0].clock_info) {
2740 /* add the default mode */
2741 rdev->pm.power_state[state_index].type =
2742 POWER_STATE_TYPE_DEFAULT;
2743 rdev->pm.power_state[state_index].num_clock_modes = 1;
2744 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2745 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2746 rdev->pm.power_state[state_index].default_clock_mode =
2747 &rdev->pm.power_state[state_index].clock_info[0];
2748 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2749 rdev->pm.power_state[state_index].pcie_lanes = 16;
2750 rdev->pm.default_power_state_index = state_index;
2751 rdev->pm.power_state[state_index].flags = 0;
2752 state_index++;
2753 }
Alex Deucher0975b162011-02-02 18:42:03 -05002754 }
Alex Deucher56278a82009-12-28 13:58:44 -05002755 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002756
Alex Deucher56278a82009-12-28 13:58:44 -05002757 rdev->pm.num_power_states = state_index;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002758
Alex Deuchera48b9b42010-04-22 14:03:55 -04002759 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2760 rdev->pm.current_clock_mode_index = 0;
Alexander Müller4376eee2011-12-30 12:55:48 -05002761 if (rdev->pm.default_power_state_index >= 0)
2762 rdev->pm.current_vddc =
2763 rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
2764 else
2765 rdev->pm.current_vddc = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002766}
2767
Christian König7062ab62013-04-08 12:41:31 +02002768union get_clock_dividers {
2769 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS v1;
2770 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2 v2;
2771 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3 v3;
2772 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V4 v4;
2773 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V5 v5;
Alex Deucher9219ed62013-02-19 14:35:34 -05002774 struct _COMPUTE_GPU_CLOCK_INPUT_PARAMETERS_V1_6 v6_in;
2775 struct _COMPUTE_GPU_CLOCK_OUTPUT_PARAMETERS_V1_6 v6_out;
Christian König7062ab62013-04-08 12:41:31 +02002776};
2777
2778int radeon_atom_get_clock_dividers(struct radeon_device *rdev,
2779 u8 clock_type,
2780 u32 clock,
2781 bool strobe_mode,
2782 struct atom_clock_dividers *dividers)
2783{
2784 union get_clock_dividers args;
2785 int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryEnginePLL);
2786 u8 frev, crev;
2787
2788 memset(&args, 0, sizeof(args));
2789 memset(dividers, 0, sizeof(struct atom_clock_dividers));
2790
2791 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2792 return -EINVAL;
2793
2794 switch (crev) {
2795 case 1:
2796 /* r4xx, r5xx */
2797 args.v1.ucAction = clock_type;
2798 args.v1.ulClock = cpu_to_le32(clock); /* 10 khz */
2799
2800 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2801
2802 dividers->post_div = args.v1.ucPostDiv;
2803 dividers->fb_div = args.v1.ucFbDiv;
2804 dividers->enable_post_div = true;
2805 break;
2806 case 2:
2807 case 3:
Alex Deucher360b1f52013-06-07 11:50:12 -04002808 case 5:
2809 /* r6xx, r7xx, evergreen, ni, si */
Christian König7062ab62013-04-08 12:41:31 +02002810 if (rdev->family <= CHIP_RV770) {
2811 args.v2.ucAction = clock_type;
2812 args.v2.ulClock = cpu_to_le32(clock); /* 10 khz */
2813
2814 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2815
2816 dividers->post_div = args.v2.ucPostDiv;
2817 dividers->fb_div = le16_to_cpu(args.v2.usFbDiv);
2818 dividers->ref_div = args.v2.ucAction;
2819 if (rdev->family == CHIP_RV770) {
2820 dividers->enable_post_div = (le32_to_cpu(args.v2.ulClock) & (1 << 24)) ?
2821 true : false;
2822 dividers->vco_mode = (le32_to_cpu(args.v2.ulClock) & (1 << 25)) ? 1 : 0;
2823 } else
2824 dividers->enable_post_div = (dividers->fb_div & 1) ? true : false;
2825 } else {
2826 if (clock_type == COMPUTE_ENGINE_PLL_PARAM) {
Alex Deucherf4a25962013-04-22 09:59:01 -04002827 args.v3.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
Christian König7062ab62013-04-08 12:41:31 +02002828
2829 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2830
2831 dividers->post_div = args.v3.ucPostDiv;
2832 dividers->enable_post_div = (args.v3.ucCntlFlag &
2833 ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
2834 dividers->enable_dithen = (args.v3.ucCntlFlag &
2835 ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
Alex Deucher20fab642013-07-28 12:33:56 -04002836 dividers->whole_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDiv);
Christian König7062ab62013-04-08 12:41:31 +02002837 dividers->frac_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDivFrac);
2838 dividers->ref_div = args.v3.ucRefDiv;
2839 dividers->vco_mode = (args.v3.ucCntlFlag &
2840 ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
2841 } else {
Alex Deucher360b1f52013-06-07 11:50:12 -04002842 /* for SI we use ComputeMemoryClockParam for memory plls */
2843 if (rdev->family >= CHIP_TAHITI)
2844 return -EINVAL;
Alex Deucherf4a25962013-04-22 09:59:01 -04002845 args.v5.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
Christian König7062ab62013-04-08 12:41:31 +02002846 if (strobe_mode)
2847 args.v5.ucInputFlag = ATOM_PLL_INPUT_FLAG_PLL_STROBE_MODE_EN;
2848
2849 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2850
2851 dividers->post_div = args.v5.ucPostDiv;
2852 dividers->enable_post_div = (args.v5.ucCntlFlag &
2853 ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
2854 dividers->enable_dithen = (args.v5.ucCntlFlag &
2855 ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
2856 dividers->whole_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDiv);
2857 dividers->frac_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDivFrac);
2858 dividers->ref_div = args.v5.ucRefDiv;
2859 dividers->vco_mode = (args.v5.ucCntlFlag &
2860 ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
2861 }
2862 }
2863 break;
2864 case 4:
2865 /* fusion */
2866 args.v4.ulClock = cpu_to_le32(clock); /* 10 khz */
2867
2868 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2869
Alex Deucher9219ed62013-02-19 14:35:34 -05002870 dividers->post_divider = dividers->post_div = args.v4.ucPostDiv;
Christian König7062ab62013-04-08 12:41:31 +02002871 dividers->real_clock = le32_to_cpu(args.v4.ulClock);
2872 break;
Alex Deucher9219ed62013-02-19 14:35:34 -05002873 case 6:
2874 /* CI */
2875 /* COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, COMPUTE_GPUCLK_INPUT_FLAG_SCLK */
2876 args.v6_in.ulClock.ulComputeClockFlag = clock_type;
2877 args.v6_in.ulClock.ulClockFreq = cpu_to_le32(clock); /* 10 khz */
2878
2879 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2880
2881 dividers->whole_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDiv);
2882 dividers->frac_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDivFrac);
2883 dividers->ref_div = args.v6_out.ucPllRefDiv;
2884 dividers->post_div = args.v6_out.ucPllPostDiv;
2885 dividers->flags = args.v6_out.ucPllCntlFlag;
2886 dividers->real_clock = le32_to_cpu(args.v6_out.ulClock.ulClock);
2887 dividers->post_divider = args.v6_out.ulClock.ucPostDiv;
2888 break;
Christian König7062ab62013-04-08 12:41:31 +02002889 default:
2890 return -EINVAL;
2891 }
2892 return 0;
2893}
2894
Alex Deuchereaa778a2013-02-13 16:38:25 -05002895int radeon_atom_get_memory_pll_dividers(struct radeon_device *rdev,
2896 u32 clock,
2897 bool strobe_mode,
2898 struct atom_mpll_param *mpll_param)
2899{
2900 COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args;
2901 int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryClockParam);
2902 u8 frev, crev;
2903
2904 memset(&args, 0, sizeof(args));
2905 memset(mpll_param, 0, sizeof(struct atom_mpll_param));
2906
2907 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2908 return -EINVAL;
2909
2910 switch (frev) {
2911 case 2:
2912 switch (crev) {
2913 case 1:
2914 /* SI */
2915 args.ulClock = cpu_to_le32(clock); /* 10 khz */
2916 args.ucInputFlag = 0;
2917 if (strobe_mode)
2918 args.ucInputFlag |= MPLL_INPUT_FLAG_STROBE_MODE_EN;
2919
2920 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2921
2922 mpll_param->clkfrac = le16_to_cpu(args.ulFbDiv.usFbDivFrac);
2923 mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv);
2924 mpll_param->post_div = args.ucPostDiv;
2925 mpll_param->dll_speed = args.ucDllSpeed;
2926 mpll_param->bwcntl = args.ucBWCntl;
2927 mpll_param->vco_mode =
Alex Deucher180f8052013-11-21 09:52:01 -05002928 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_VCO_MODE_MASK);
Alex Deuchereaa778a2013-02-13 16:38:25 -05002929 mpll_param->yclk_sel =
2930 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_BYPASS_DQ_PLL) ? 1 : 0;
2931 mpll_param->qdr =
2932 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_QDR_ENABLE) ? 1 : 0;
2933 mpll_param->half_rate =
2934 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_AD_HALF_RATE) ? 1 : 0;
2935 break;
2936 default:
2937 return -EINVAL;
2938 }
2939 break;
2940 default:
2941 return -EINVAL;
2942 }
2943 return 0;
2944}
2945
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002946void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2947{
2948 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2949 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2950
2951 args.ucEnable = enable;
2952
2953 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2954}
2955
Rafał Miłecki74338742009-11-03 00:53:02 +01002956uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2957{
2958 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2959 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2960
2961 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
Cédric Cano45894332011-02-11 19:45:37 -05002962 return le32_to_cpu(args.ulReturnEngineClock);
Rafał Miłecki74338742009-11-03 00:53:02 +01002963}
2964
2965uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2966{
2967 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2968 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2969
2970 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
Cédric Cano45894332011-02-11 19:45:37 -05002971 return le32_to_cpu(args.ulReturnMemoryClock);
Rafał Miłecki74338742009-11-03 00:53:02 +01002972}
2973
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002974void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2975 uint32_t eng_clock)
2976{
2977 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2978 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2979
Cédric Cano45894332011-02-11 19:45:37 -05002980 args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002981
2982 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2983}
2984
2985void radeon_atom_set_memory_clock(struct radeon_device *rdev,
2986 uint32_t mem_clock)
2987{
2988 SET_MEMORY_CLOCK_PS_ALLOCATION args;
2989 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
2990
2991 if (rdev->flags & RADEON_IS_IGP)
2992 return;
2993
Cédric Cano45894332011-02-11 19:45:37 -05002994 args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002995
2996 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2997}
2998
Alex Deucherae5b0ab2013-06-24 10:50:34 -04002999void radeon_atom_set_engine_dram_timings(struct radeon_device *rdev,
3000 u32 eng_clock, u32 mem_clock)
3001{
3002 SET_ENGINE_CLOCK_PS_ALLOCATION args;
3003 int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
3004 u32 tmp;
3005
3006 memset(&args, 0, sizeof(args));
3007
3008 tmp = eng_clock & SET_CLOCK_FREQ_MASK;
3009 tmp |= (COMPUTE_ENGINE_PLL_PARAM << 24);
3010
3011 args.ulTargetEngineClock = cpu_to_le32(tmp);
3012 if (mem_clock)
3013 args.sReserved.ulClock = cpu_to_le32(mem_clock & SET_CLOCK_FREQ_MASK);
3014
3015 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3016}
3017
3018void radeon_atom_update_memory_dll(struct radeon_device *rdev,
3019 u32 mem_clock)
3020{
3021 u32 args;
3022 int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
3023
3024 args = cpu_to_le32(mem_clock); /* 10 khz */
3025
3026 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3027}
3028
3029void radeon_atom_set_ac_timing(struct radeon_device *rdev,
3030 u32 mem_clock)
3031{
3032 SET_MEMORY_CLOCK_PS_ALLOCATION args;
3033 int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
3034 u32 tmp = mem_clock | (COMPUTE_MEMORY_PLL_PARAM << 24);
3035
3036 args.ulTargetMemoryClock = cpu_to_le32(tmp); /* 10 khz */
3037
3038 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3039}
3040
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003041union set_voltage {
3042 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
3043 struct _SET_VOLTAGE_PARAMETERS v1;
3044 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
Alex Deuchere83753b2012-03-20 17:18:08 -04003045 struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003046};
3047
Alex Deucher8a83ec52011-04-12 14:49:23 -04003048void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003049{
3050 union set_voltage args;
3051 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
Alex Deucher8a83ec52011-04-12 14:49:23 -04003052 u8 frev, crev, volt_index = voltage_level;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003053
3054 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3055 return;
3056
Alex Deuchera377e182011-06-20 13:00:31 -04003057 /* 0xff01 is a flag rather then an actual voltage */
3058 if (voltage_level == 0xff01)
3059 return;
3060
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003061 switch (crev) {
3062 case 1:
Alex Deucher8a83ec52011-04-12 14:49:23 -04003063 args.v1.ucVoltageType = voltage_type;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003064 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
3065 args.v1.ucVoltageIndex = volt_index;
3066 break;
3067 case 2:
Alex Deucher8a83ec52011-04-12 14:49:23 -04003068 args.v2.ucVoltageType = voltage_type;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003069 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
Alex Deucher8a83ec52011-04-12 14:49:23 -04003070 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003071 break;
Alex Deuchere83753b2012-03-20 17:18:08 -04003072 case 3:
3073 args.v3.ucVoltageType = voltage_type;
3074 args.v3.ucVoltageMode = ATOM_SET_VOLTAGE;
3075 args.v3.usVoltageLevel = cpu_to_le16(voltage_level);
3076 break;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003077 default:
3078 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3079 return;
3080 }
3081
3082 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3083}
3084
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003085int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
3086 u16 voltage_id, u16 *voltage)
Alex Deucheree4017f2011-06-23 12:19:32 -04003087{
3088 union set_voltage args;
3089 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
3090 u8 frev, crev;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003091
Alex Deucheree4017f2011-06-23 12:19:32 -04003092 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3093 return -EINVAL;
3094
3095 switch (crev) {
3096 case 1:
3097 return -EINVAL;
3098 case 2:
3099 args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
3100 args.v2.ucVoltageMode = 0;
3101 args.v2.usVoltageLevel = 0;
3102
3103 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3104
3105 *voltage = le16_to_cpu(args.v2.usVoltageLevel);
3106 break;
Alex Deuchere83753b2012-03-20 17:18:08 -04003107 case 3:
3108 args.v3.ucVoltageType = voltage_type;
3109 args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
3110 args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
3111
3112 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3113
3114 *voltage = le16_to_cpu(args.v3.usVoltageLevel);
3115 break;
Alex Deucheree4017f2011-06-23 12:19:32 -04003116 default:
3117 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3118 return -EINVAL;
3119 }
3120
3121 return 0;
3122}
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003123
Alex Deucherbeb79f42013-02-19 17:14:43 -05003124int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device *rdev,
3125 u16 *voltage,
3126 u16 leakage_idx)
3127{
3128 return radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC, leakage_idx, voltage);
3129}
3130
Alex Deucher62c35fd72013-02-19 18:15:06 -05003131int radeon_atom_get_leakage_id_from_vbios(struct radeon_device *rdev,
3132 u16 *leakage_id)
3133{
3134 union set_voltage args;
3135 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
3136 u8 frev, crev;
3137
3138 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3139 return -EINVAL;
3140
3141 switch (crev) {
3142 case 3:
3143 case 4:
3144 args.v3.ucVoltageType = 0;
3145 args.v3.ucVoltageMode = ATOM_GET_LEAKAGE_ID;
3146 args.v3.usVoltageLevel = 0;
3147
3148 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3149
3150 *leakage_id = le16_to_cpu(args.v3.usVoltageLevel);
3151 break;
3152 default:
3153 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3154 return -EINVAL;
3155 }
3156
3157 return 0;
3158}
3159
3160int radeon_atom_get_leakage_vddc_based_on_leakage_params(struct radeon_device *rdev,
3161 u16 *vddc, u16 *vddci,
3162 u16 virtual_voltage_id,
3163 u16 vbios_voltage_id)
3164{
3165 int index = GetIndexIntoMasterTable(DATA, ASIC_ProfilingInfo);
3166 u8 frev, crev;
3167 u16 data_offset, size;
3168 int i, j;
3169 ATOM_ASIC_PROFILING_INFO_V2_1 *profile;
3170 u16 *leakage_bin, *vddc_id_buf, *vddc_buf, *vddci_id_buf, *vddci_buf;
3171
3172 *vddc = 0;
3173 *vddci = 0;
3174
3175 if (!atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3176 &frev, &crev, &data_offset))
3177 return -EINVAL;
3178
3179 profile = (ATOM_ASIC_PROFILING_INFO_V2_1 *)
3180 (rdev->mode_info.atom_context->bios + data_offset);
3181
3182 switch (frev) {
3183 case 1:
3184 return -EINVAL;
3185 case 2:
3186 switch (crev) {
3187 case 1:
3188 if (size < sizeof(ATOM_ASIC_PROFILING_INFO_V2_1))
3189 return -EINVAL;
3190 leakage_bin = (u16 *)
3191 (rdev->mode_info.atom_context->bios + data_offset +
3192 le16_to_cpu(profile->usLeakageBinArrayOffset));
3193 vddc_id_buf = (u16 *)
3194 (rdev->mode_info.atom_context->bios + data_offset +
3195 le16_to_cpu(profile->usElbVDDC_IdArrayOffset));
3196 vddc_buf = (u16 *)
3197 (rdev->mode_info.atom_context->bios + data_offset +
3198 le16_to_cpu(profile->usElbVDDC_LevelArrayOffset));
3199 vddci_id_buf = (u16 *)
3200 (rdev->mode_info.atom_context->bios + data_offset +
3201 le16_to_cpu(profile->usElbVDDCI_IdArrayOffset));
3202 vddci_buf = (u16 *)
3203 (rdev->mode_info.atom_context->bios + data_offset +
3204 le16_to_cpu(profile->usElbVDDCI_LevelArrayOffset));
3205
3206 if (profile->ucElbVDDC_Num > 0) {
3207 for (i = 0; i < profile->ucElbVDDC_Num; i++) {
3208 if (vddc_id_buf[i] == virtual_voltage_id) {
3209 for (j = 0; j < profile->ucLeakageBinNum; j++) {
3210 if (vbios_voltage_id <= leakage_bin[j]) {
3211 *vddc = vddc_buf[j * profile->ucElbVDDC_Num + i];
3212 break;
3213 }
3214 }
3215 break;
3216 }
3217 }
3218 }
3219 if (profile->ucElbVDDCI_Num > 0) {
3220 for (i = 0; i < profile->ucElbVDDCI_Num; i++) {
3221 if (vddci_id_buf[i] == virtual_voltage_id) {
3222 for (j = 0; j < profile->ucLeakageBinNum; j++) {
3223 if (vbios_voltage_id <= leakage_bin[j]) {
3224 *vddci = vddci_buf[j * profile->ucElbVDDCI_Num + i];
3225 break;
3226 }
3227 }
3228 break;
3229 }
3230 }
3231 }
3232 break;
3233 default:
3234 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3235 return -EINVAL;
3236 }
3237 break;
3238 default:
3239 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3240 return -EINVAL;
3241 }
3242
3243 return 0;
3244}
3245
Alex Deuchere9f274b2014-07-31 17:57:42 -04003246union get_voltage_info {
3247 struct _GET_VOLTAGE_INFO_INPUT_PARAMETER_V1_2 in;
3248 struct _GET_EVV_VOLTAGE_INFO_OUTPUT_PARAMETER_V1_2 evv_out;
3249};
3250
3251int radeon_atom_get_voltage_evv(struct radeon_device *rdev,
3252 u16 virtual_voltage_id,
3253 u16 *voltage)
3254{
3255 int index = GetIndexIntoMasterTable(COMMAND, GetVoltageInfo);
3256 u32 entry_id;
3257 u32 count = rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count;
3258 union get_voltage_info args;
3259
3260 for (entry_id = 0; entry_id < count; entry_id++) {
3261 if (rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[entry_id].v ==
3262 virtual_voltage_id)
3263 break;
3264 }
3265
3266 if (entry_id >= count)
3267 return -EINVAL;
3268
3269 args.in.ucVoltageType = VOLTAGE_TYPE_VDDC;
3270 args.in.ucVoltageMode = ATOM_GET_VOLTAGE_EVV_VOLTAGE;
3271 args.in.ulSCLKFreq =
3272 cpu_to_le32(rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[entry_id].clk);
3273
3274 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3275
3276 *voltage = le16_to_cpu(args.evv_out.usVoltageLevel);
3277
3278 return 0;
3279}
3280
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003281int radeon_atom_get_voltage_gpio_settings(struct radeon_device *rdev,
3282 u16 voltage_level, u8 voltage_type,
3283 u32 *gpio_value, u32 *gpio_mask)
3284{
3285 union set_voltage args;
3286 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
3287 u8 frev, crev;
3288
3289 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3290 return -EINVAL;
3291
3292 switch (crev) {
3293 case 1:
3294 return -EINVAL;
3295 case 2:
3296 args.v2.ucVoltageType = voltage_type;
3297 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOMASK;
3298 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
3299
3300 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3301
3302 *gpio_mask = le32_to_cpu(*(u32 *)&args.v2);
3303
3304 args.v2.ucVoltageType = voltage_type;
3305 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOVAL;
3306 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
3307
3308 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3309
3310 *gpio_value = le32_to_cpu(*(u32 *)&args.v2);
3311 break;
3312 default:
3313 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3314 return -EINVAL;
3315 }
3316
3317 return 0;
3318}
3319
3320union voltage_object_info {
Alex Deucher58653ab2013-02-13 17:04:59 -05003321 struct _ATOM_VOLTAGE_OBJECT_INFO v1;
3322 struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2;
3323 struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003324};
3325
Alex Deucher779187f2013-03-28 14:47:34 -04003326union voltage_object {
3327 struct _ATOM_VOLTAGE_OBJECT v1;
3328 struct _ATOM_VOLTAGE_OBJECT_V2 v2;
3329 union _ATOM_VOLTAGE_OBJECT_V3 v3;
3330};
3331
3332static ATOM_VOLTAGE_OBJECT *atom_lookup_voltage_object_v1(ATOM_VOLTAGE_OBJECT_INFO *v1,
3333 u8 voltage_type)
3334{
Alex Deucher6e764762013-06-24 10:54:16 -04003335 u32 size = le16_to_cpu(v1->sHeader.usStructureSize);
Alex Deucher779187f2013-03-28 14:47:34 -04003336 u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO, asVoltageObj[0]);
3337 u8 *start = (u8 *)v1;
3338
3339 while (offset < size) {
3340 ATOM_VOLTAGE_OBJECT *vo = (ATOM_VOLTAGE_OBJECT *)(start + offset);
3341 if (vo->ucVoltageType == voltage_type)
3342 return vo;
3343 offset += offsetof(ATOM_VOLTAGE_OBJECT, asFormula.ucVIDAdjustEntries) +
3344 vo->asFormula.ucNumOfVoltageEntries;
3345 }
3346 return NULL;
3347}
3348
3349static ATOM_VOLTAGE_OBJECT_V2 *atom_lookup_voltage_object_v2(ATOM_VOLTAGE_OBJECT_INFO_V2 *v2,
3350 u8 voltage_type)
3351{
Alex Deucher6e764762013-06-24 10:54:16 -04003352 u32 size = le16_to_cpu(v2->sHeader.usStructureSize);
Alex Deucher779187f2013-03-28 14:47:34 -04003353 u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V2, asVoltageObj[0]);
3354 u8 *start = (u8*)v2;
3355
3356 while (offset < size) {
3357 ATOM_VOLTAGE_OBJECT_V2 *vo = (ATOM_VOLTAGE_OBJECT_V2 *)(start + offset);
3358 if (vo->ucVoltageType == voltage_type)
3359 return vo;
3360 offset += offsetof(ATOM_VOLTAGE_OBJECT_V2, asFormula.asVIDAdjustEntries) +
3361 (vo->asFormula.ucNumOfVoltageEntries * sizeof(VOLTAGE_LUT_ENTRY));
3362 }
3363 return NULL;
3364}
3365
3366static ATOM_VOLTAGE_OBJECT_V3 *atom_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1 *v3,
3367 u8 voltage_type, u8 voltage_mode)
3368{
Alex Deucher6e764762013-06-24 10:54:16 -04003369 u32 size = le16_to_cpu(v3->sHeader.usStructureSize);
Alex Deucher779187f2013-03-28 14:47:34 -04003370 u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1, asVoltageObj[0]);
3371 u8 *start = (u8*)v3;
3372
3373 while (offset < size) {
3374 ATOM_VOLTAGE_OBJECT_V3 *vo = (ATOM_VOLTAGE_OBJECT_V3 *)(start + offset);
3375 if ((vo->asGpioVoltageObj.sHeader.ucVoltageType == voltage_type) &&
3376 (vo->asGpioVoltageObj.sHeader.ucVoltageMode == voltage_mode))
3377 return vo;
Alex Deucher6e764762013-06-24 10:54:16 -04003378 offset += le16_to_cpu(vo->asGpioVoltageObj.sHeader.usSize);
Alex Deucher779187f2013-03-28 14:47:34 -04003379 }
3380 return NULL;
3381}
3382
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003383bool
Alex Deucher58653ab2013-02-13 17:04:59 -05003384radeon_atom_is_voltage_gpio(struct radeon_device *rdev,
3385 u8 voltage_type, u8 voltage_mode)
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003386{
3387 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3388 u8 frev, crev;
3389 u16 data_offset, size;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003390 union voltage_object_info *voltage_info;
Alex Deucher779187f2013-03-28 14:47:34 -04003391 union voltage_object *voltage_object = NULL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003392
3393 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3394 &frev, &crev, &data_offset)) {
3395 voltage_info = (union voltage_object_info *)
3396 (rdev->mode_info.atom_context->bios + data_offset);
3397
Alex Deucher58653ab2013-02-13 17:04:59 -05003398 switch (frev) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003399 case 1:
Alex Deucher58653ab2013-02-13 17:04:59 -05003400 case 2:
3401 switch (crev) {
3402 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003403 voltage_object = (union voltage_object *)
3404 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3405 if (voltage_object &&
3406 (voltage_object->v1.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO))
3407 return true;
Alex Deucher58653ab2013-02-13 17:04:59 -05003408 break;
3409 case 2:
Alex Deucher779187f2013-03-28 14:47:34 -04003410 voltage_object = (union voltage_object *)
3411 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3412 if (voltage_object &&
3413 (voltage_object->v2.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO))
3414 return true;
Alex Deucher58653ab2013-02-13 17:04:59 -05003415 break;
3416 default:
3417 DRM_ERROR("unknown voltage object table\n");
3418 return false;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003419 }
3420 break;
Alex Deucher58653ab2013-02-13 17:04:59 -05003421 case 3:
3422 switch (crev) {
3423 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003424 if (atom_lookup_voltage_object_v3(&voltage_info->v3,
3425 voltage_type, voltage_mode))
3426 return true;
Alex Deucher58653ab2013-02-13 17:04:59 -05003427 break;
3428 default:
3429 DRM_ERROR("unknown voltage object table\n");
3430 return false;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003431 }
3432 break;
3433 default:
3434 DRM_ERROR("unknown voltage object table\n");
3435 return false;
3436 }
3437
3438 }
3439 return false;
3440}
3441
Alex Deucher636e2582014-06-06 18:43:45 -04003442int radeon_atom_get_svi2_info(struct radeon_device *rdev,
3443 u8 voltage_type,
3444 u8 *svd_gpio_id, u8 *svc_gpio_id)
3445{
3446 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3447 u8 frev, crev;
3448 u16 data_offset, size;
3449 union voltage_object_info *voltage_info;
3450 union voltage_object *voltage_object = NULL;
3451
3452 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3453 &frev, &crev, &data_offset)) {
3454 voltage_info = (union voltage_object_info *)
3455 (rdev->mode_info.atom_context->bios + data_offset);
3456
3457 switch (frev) {
3458 case 3:
3459 switch (crev) {
3460 case 1:
3461 voltage_object = (union voltage_object *)
3462 atom_lookup_voltage_object_v3(&voltage_info->v3,
3463 voltage_type,
3464 VOLTAGE_OBJ_SVID2);
3465 if (voltage_object) {
3466 *svd_gpio_id = voltage_object->v3.asSVID2Obj.ucSVDGpioId;
3467 *svc_gpio_id = voltage_object->v3.asSVID2Obj.ucSVCGpioId;
3468 } else {
3469 return -EINVAL;
3470 }
3471 break;
3472 default:
3473 DRM_ERROR("unknown voltage object table\n");
3474 return -EINVAL;
3475 }
3476 break;
3477 default:
3478 DRM_ERROR("unknown voltage object table\n");
3479 return -EINVAL;
3480 }
3481
3482 }
3483 return 0;
3484}
3485
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003486int radeon_atom_get_max_voltage(struct radeon_device *rdev,
3487 u8 voltage_type, u16 *max_voltage)
3488{
3489 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3490 u8 frev, crev;
3491 u16 data_offset, size;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003492 union voltage_object_info *voltage_info;
Alex Deucher779187f2013-03-28 14:47:34 -04003493 union voltage_object *voltage_object = NULL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003494
3495 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3496 &frev, &crev, &data_offset)) {
3497 voltage_info = (union voltage_object_info *)
3498 (rdev->mode_info.atom_context->bios + data_offset);
3499
3500 switch (crev) {
3501 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003502 voltage_object = (union voltage_object *)
3503 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3504 if (voltage_object) {
3505 ATOM_VOLTAGE_FORMULA *formula =
3506 &voltage_object->v1.asFormula;
3507 if (formula->ucFlag & 1)
3508 *max_voltage =
3509 le16_to_cpu(formula->usVoltageBaseLevel) +
3510 formula->ucNumOfVoltageEntries / 2 *
3511 le16_to_cpu(formula->usVoltageStep);
3512 else
3513 *max_voltage =
3514 le16_to_cpu(formula->usVoltageBaseLevel) +
3515 (formula->ucNumOfVoltageEntries - 1) *
3516 le16_to_cpu(formula->usVoltageStep);
3517 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003518 }
3519 break;
3520 case 2:
Alex Deucher779187f2013-03-28 14:47:34 -04003521 voltage_object = (union voltage_object *)
3522 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3523 if (voltage_object) {
3524 ATOM_VOLTAGE_FORMULA_V2 *formula =
3525 &voltage_object->v2.asFormula;
3526 if (formula->ucNumOfVoltageEntries) {
Alex Deucher607f2c22013-08-20 18:40:46 -04003527 VOLTAGE_LUT_ENTRY *lut = (VOLTAGE_LUT_ENTRY *)
3528 ((u8 *)&formula->asVIDAdjustEntries[0] +
3529 (sizeof(VOLTAGE_LUT_ENTRY) * (formula->ucNumOfVoltageEntries - 1)));
Alex Deucher779187f2013-03-28 14:47:34 -04003530 *max_voltage =
Alex Deucher607f2c22013-08-20 18:40:46 -04003531 le16_to_cpu(lut->usVoltageValue);
Alex Deucher779187f2013-03-28 14:47:34 -04003532 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003533 }
3534 }
3535 break;
3536 default:
3537 DRM_ERROR("unknown voltage object table\n");
3538 return -EINVAL;
3539 }
3540
3541 }
3542 return -EINVAL;
3543}
3544
3545int radeon_atom_get_min_voltage(struct radeon_device *rdev,
3546 u8 voltage_type, u16 *min_voltage)
3547{
3548 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3549 u8 frev, crev;
3550 u16 data_offset, size;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003551 union voltage_object_info *voltage_info;
Alex Deucher779187f2013-03-28 14:47:34 -04003552 union voltage_object *voltage_object = NULL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003553
3554 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3555 &frev, &crev, &data_offset)) {
3556 voltage_info = (union voltage_object_info *)
3557 (rdev->mode_info.atom_context->bios + data_offset);
3558
3559 switch (crev) {
3560 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003561 voltage_object = (union voltage_object *)
3562 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3563 if (voltage_object) {
3564 ATOM_VOLTAGE_FORMULA *formula =
3565 &voltage_object->v1.asFormula;
3566 *min_voltage =
3567 le16_to_cpu(formula->usVoltageBaseLevel);
3568 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003569 }
3570 break;
3571 case 2:
Alex Deucher779187f2013-03-28 14:47:34 -04003572 voltage_object = (union voltage_object *)
3573 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3574 if (voltage_object) {
3575 ATOM_VOLTAGE_FORMULA_V2 *formula =
3576 &voltage_object->v2.asFormula;
3577 if (formula->ucNumOfVoltageEntries) {
3578 *min_voltage =
3579 le16_to_cpu(formula->asVIDAdjustEntries[
3580 0
3581 ].usVoltageValue);
3582 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003583 }
3584 }
3585 break;
3586 default:
3587 DRM_ERROR("unknown voltage object table\n");
3588 return -EINVAL;
3589 }
3590
3591 }
3592 return -EINVAL;
3593}
3594
3595int radeon_atom_get_voltage_step(struct radeon_device *rdev,
3596 u8 voltage_type, u16 *voltage_step)
3597{
3598 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3599 u8 frev, crev;
3600 u16 data_offset, size;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003601 union voltage_object_info *voltage_info;
Alex Deucher779187f2013-03-28 14:47:34 -04003602 union voltage_object *voltage_object = NULL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003603
3604 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3605 &frev, &crev, &data_offset)) {
3606 voltage_info = (union voltage_object_info *)
3607 (rdev->mode_info.atom_context->bios + data_offset);
3608
3609 switch (crev) {
3610 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003611 voltage_object = (union voltage_object *)
3612 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3613 if (voltage_object) {
3614 ATOM_VOLTAGE_FORMULA *formula =
3615 &voltage_object->v1.asFormula;
3616 if (formula->ucFlag & 1)
3617 *voltage_step =
3618 (le16_to_cpu(formula->usVoltageStep) + 1) / 2;
3619 else
3620 *voltage_step =
3621 le16_to_cpu(formula->usVoltageStep);
3622 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003623 }
3624 break;
3625 case 2:
3626 return -EINVAL;
3627 default:
3628 DRM_ERROR("unknown voltage object table\n");
3629 return -EINVAL;
3630 }
3631
3632 }
3633 return -EINVAL;
3634}
3635
3636int radeon_atom_round_to_true_voltage(struct radeon_device *rdev,
3637 u8 voltage_type,
3638 u16 nominal_voltage,
3639 u16 *true_voltage)
3640{
3641 u16 min_voltage, max_voltage, voltage_step;
3642
3643 if (radeon_atom_get_max_voltage(rdev, voltage_type, &max_voltage))
3644 return -EINVAL;
3645 if (radeon_atom_get_min_voltage(rdev, voltage_type, &min_voltage))
3646 return -EINVAL;
3647 if (radeon_atom_get_voltage_step(rdev, voltage_type, &voltage_step))
3648 return -EINVAL;
3649
3650 if (nominal_voltage <= min_voltage)
3651 *true_voltage = min_voltage;
3652 else if (nominal_voltage >= max_voltage)
3653 *true_voltage = max_voltage;
3654 else
3655 *true_voltage = min_voltage +
3656 ((nominal_voltage - min_voltage) / voltage_step) *
3657 voltage_step;
3658
3659 return 0;
3660}
3661
3662int radeon_atom_get_voltage_table(struct radeon_device *rdev,
Alex Deucher65171942013-02-13 17:29:54 -05003663 u8 voltage_type, u8 voltage_mode,
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003664 struct atom_voltage_table *voltage_table)
3665{
3666 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3667 u8 frev, crev;
3668 u16 data_offset, size;
Alex Deucher779187f2013-03-28 14:47:34 -04003669 int i, ret;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003670 union voltage_object_info *voltage_info;
Alex Deucher779187f2013-03-28 14:47:34 -04003671 union voltage_object *voltage_object = NULL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003672
3673 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3674 &frev, &crev, &data_offset)) {
3675 voltage_info = (union voltage_object_info *)
3676 (rdev->mode_info.atom_context->bios + data_offset);
3677
Alex Deucher65171942013-02-13 17:29:54 -05003678 switch (frev) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003679 case 1:
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003680 case 2:
Alex Deucher65171942013-02-13 17:29:54 -05003681 switch (crev) {
3682 case 1:
3683 DRM_ERROR("old table version %d, %d\n", frev, crev);
3684 return -EINVAL;
3685 case 2:
Alex Deucher779187f2013-03-28 14:47:34 -04003686 voltage_object = (union voltage_object *)
3687 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3688 if (voltage_object) {
3689 ATOM_VOLTAGE_FORMULA_V2 *formula =
3690 &voltage_object->v2.asFormula;
Alex Deucher607f2c22013-08-20 18:40:46 -04003691 VOLTAGE_LUT_ENTRY *lut;
Alex Deucher779187f2013-03-28 14:47:34 -04003692 if (formula->ucNumOfVoltageEntries > MAX_VOLTAGE_ENTRIES)
3693 return -EINVAL;
Alex Deucher607f2c22013-08-20 18:40:46 -04003694 lut = &formula->asVIDAdjustEntries[0];
Alex Deucher779187f2013-03-28 14:47:34 -04003695 for (i = 0; i < formula->ucNumOfVoltageEntries; i++) {
3696 voltage_table->entries[i].value =
Alex Deucher607f2c22013-08-20 18:40:46 -04003697 le16_to_cpu(lut->usVoltageValue);
Alex Deucher779187f2013-03-28 14:47:34 -04003698 ret = radeon_atom_get_voltage_gpio_settings(rdev,
3699 voltage_table->entries[i].value,
3700 voltage_type,
3701 &voltage_table->entries[i].smio_low,
3702 &voltage_table->mask_low);
3703 if (ret)
3704 return ret;
Alex Deucher607f2c22013-08-20 18:40:46 -04003705 lut = (VOLTAGE_LUT_ENTRY *)
3706 ((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003707 }
Alex Deucher779187f2013-03-28 14:47:34 -04003708 voltage_table->count = formula->ucNumOfVoltageEntries;
3709 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003710 }
Alex Deucher65171942013-02-13 17:29:54 -05003711 break;
3712 default:
3713 DRM_ERROR("unknown voltage object table\n");
3714 return -EINVAL;
3715 }
3716 break;
3717 case 3:
3718 switch (crev) {
3719 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003720 voltage_object = (union voltage_object *)
3721 atom_lookup_voltage_object_v3(&voltage_info->v3,
3722 voltage_type, voltage_mode);
3723 if (voltage_object) {
3724 ATOM_GPIO_VOLTAGE_OBJECT_V3 *gpio =
3725 &voltage_object->v3.asGpioVoltageObj;
Alex Deucher607f2c22013-08-20 18:40:46 -04003726 VOLTAGE_LUT_ENTRY_V2 *lut;
Alex Deucher779187f2013-03-28 14:47:34 -04003727 if (gpio->ucGpioEntryNum > MAX_VOLTAGE_ENTRIES)
3728 return -EINVAL;
Alex Deucher607f2c22013-08-20 18:40:46 -04003729 lut = &gpio->asVolGpioLut[0];
Alex Deucher779187f2013-03-28 14:47:34 -04003730 for (i = 0; i < gpio->ucGpioEntryNum; i++) {
3731 voltage_table->entries[i].value =
Alex Deucher607f2c22013-08-20 18:40:46 -04003732 le16_to_cpu(lut->usVoltageValue);
Alex Deucher779187f2013-03-28 14:47:34 -04003733 voltage_table->entries[i].smio_low =
Alex Deucher607f2c22013-08-20 18:40:46 -04003734 le32_to_cpu(lut->ulVoltageId);
3735 lut = (VOLTAGE_LUT_ENTRY_V2 *)
3736 ((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY_V2));
Alex Deucher65171942013-02-13 17:29:54 -05003737 }
Alex Deucher779187f2013-03-28 14:47:34 -04003738 voltage_table->mask_low = le32_to_cpu(gpio->ulGpioMaskVal);
3739 voltage_table->count = gpio->ucGpioEntryNum;
3740 voltage_table->phase_delay = gpio->ucPhaseDelay;
3741 return 0;
Alex Deucher65171942013-02-13 17:29:54 -05003742 }
3743 break;
3744 default:
3745 DRM_ERROR("unknown voltage object table\n");
3746 return -EINVAL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003747 }
3748 break;
3749 default:
3750 DRM_ERROR("unknown voltage object table\n");
3751 return -EINVAL;
3752 }
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003753 }
3754 return -EINVAL;
3755}
3756
3757union vram_info {
3758 struct _ATOM_VRAM_INFO_V3 v1_3;
3759 struct _ATOM_VRAM_INFO_V4 v1_4;
3760 struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1;
3761};
3762
3763int radeon_atom_get_memory_info(struct radeon_device *rdev,
3764 u8 module_index, struct atom_memory_info *mem_info)
3765{
3766 int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
3767 u8 frev, crev, i;
3768 u16 data_offset, size;
3769 union vram_info *vram_info;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003770
3771 memset(mem_info, 0, sizeof(struct atom_memory_info));
3772
3773 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3774 &frev, &crev, &data_offset)) {
3775 vram_info = (union vram_info *)
3776 (rdev->mode_info.atom_context->bios + data_offset);
3777 switch (frev) {
3778 case 1:
3779 switch (crev) {
3780 case 3:
3781 /* r6xx */
3782 if (module_index < vram_info->v1_3.ucNumOfVRAMModule) {
3783 ATOM_VRAM_MODULE_V3 *vram_module =
3784 (ATOM_VRAM_MODULE_V3 *)vram_info->v1_3.aVramInfo;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003785
3786 for (i = 0; i < module_index; i++) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003787 if (le16_to_cpu(vram_module->usSize) == 0)
3788 return -EINVAL;
Alex Deucher77c7d502013-07-17 10:52:43 -04003789 vram_module = (ATOM_VRAM_MODULE_V3 *)
3790 ((u8 *)vram_module + le16_to_cpu(vram_module->usSize));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003791 }
3792 mem_info->mem_vendor = vram_module->asMemory.ucMemoryVenderID & 0xf;
3793 mem_info->mem_type = vram_module->asMemory.ucMemoryType & 0xf0;
3794 } else
3795 return -EINVAL;
3796 break;
3797 case 4:
3798 /* r7xx, evergreen */
3799 if (module_index < vram_info->v1_4.ucNumOfVRAMModule) {
3800 ATOM_VRAM_MODULE_V4 *vram_module =
3801 (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003802
3803 for (i = 0; i < module_index; i++) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003804 if (le16_to_cpu(vram_module->usModuleSize) == 0)
3805 return -EINVAL;
Alex Deucher77c7d502013-07-17 10:52:43 -04003806 vram_module = (ATOM_VRAM_MODULE_V4 *)
3807 ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003808 }
3809 mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf;
3810 mem_info->mem_type = vram_module->ucMemoryType & 0xf0;
3811 } else
3812 return -EINVAL;
3813 break;
3814 default:
3815 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3816 return -EINVAL;
3817 }
3818 break;
3819 case 2:
3820 switch (crev) {
3821 case 1:
3822 /* ni */
3823 if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
3824 ATOM_VRAM_MODULE_V7 *vram_module =
3825 (ATOM_VRAM_MODULE_V7 *)vram_info->v2_1.aVramInfo;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003826
3827 for (i = 0; i < module_index; i++) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003828 if (le16_to_cpu(vram_module->usModuleSize) == 0)
3829 return -EINVAL;
Alex Deucher77c7d502013-07-17 10:52:43 -04003830 vram_module = (ATOM_VRAM_MODULE_V7 *)
3831 ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003832 }
3833 mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf;
3834 mem_info->mem_type = vram_module->ucMemoryType & 0xf0;
3835 } else
3836 return -EINVAL;
3837 break;
3838 default:
3839 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3840 return -EINVAL;
3841 }
3842 break;
3843 default:
3844 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3845 return -EINVAL;
3846 }
3847 return 0;
3848 }
3849 return -EINVAL;
3850}
3851
3852int radeon_atom_get_mclk_range_table(struct radeon_device *rdev,
3853 bool gddr5, u8 module_index,
3854 struct atom_memory_clock_range_table *mclk_range_table)
3855{
3856 int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
3857 u8 frev, crev, i;
3858 u16 data_offset, size;
3859 union vram_info *vram_info;
3860 u32 mem_timing_size = gddr5 ?
3861 sizeof(ATOM_MEMORY_TIMING_FORMAT_V2) : sizeof(ATOM_MEMORY_TIMING_FORMAT);
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003862
3863 memset(mclk_range_table, 0, sizeof(struct atom_memory_clock_range_table));
3864
3865 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3866 &frev, &crev, &data_offset)) {
3867 vram_info = (union vram_info *)
3868 (rdev->mode_info.atom_context->bios + data_offset);
3869 switch (frev) {
3870 case 1:
3871 switch (crev) {
3872 case 3:
3873 DRM_ERROR("old table version %d, %d\n", frev, crev);
3874 return -EINVAL;
3875 case 4:
3876 /* r7xx, evergreen */
3877 if (module_index < vram_info->v1_4.ucNumOfVRAMModule) {
3878 ATOM_VRAM_MODULE_V4 *vram_module =
3879 (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo;
Alex Deucher607f2c22013-08-20 18:40:46 -04003880 ATOM_MEMORY_TIMING_FORMAT *format;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003881
3882 for (i = 0; i < module_index; i++) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003883 if (le16_to_cpu(vram_module->usModuleSize) == 0)
3884 return -EINVAL;
Alex Deucher77c7d502013-07-17 10:52:43 -04003885 vram_module = (ATOM_VRAM_MODULE_V4 *)
3886 ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003887 }
3888 mclk_range_table->num_entries = (u8)
Alex Deucher1fa42522013-07-17 10:18:52 -04003889 ((le16_to_cpu(vram_module->usModuleSize) - offsetof(ATOM_VRAM_MODULE_V4, asMemTiming)) /
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003890 mem_timing_size);
Alex Deucher607f2c22013-08-20 18:40:46 -04003891 format = &vram_module->asMemTiming[0];
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003892 for (i = 0; i < mclk_range_table->num_entries; i++) {
Alex Deuchere6312272013-07-03 11:18:08 -04003893 mclk_range_table->mclk[i] = le32_to_cpu(format->ulClkRange);
Alex Deucher607f2c22013-08-20 18:40:46 -04003894 format = (ATOM_MEMORY_TIMING_FORMAT *)
3895 ((u8 *)format + mem_timing_size);
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003896 }
3897 } else
3898 return -EINVAL;
3899 break;
3900 default:
3901 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3902 return -EINVAL;
3903 }
3904 break;
3905 case 2:
3906 DRM_ERROR("new table version %d, %d\n", frev, crev);
3907 return -EINVAL;
3908 default:
3909 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3910 return -EINVAL;
3911 }
3912 return 0;
3913 }
3914 return -EINVAL;
3915}
3916
3917#define MEM_ID_MASK 0xff000000
3918#define MEM_ID_SHIFT 24
3919#define CLOCK_RANGE_MASK 0x00ffffff
3920#define CLOCK_RANGE_SHIFT 0
3921#define LOW_NIBBLE_MASK 0xf
3922#define DATA_EQU_PREV 0
3923#define DATA_FROM_TABLE 4
3924
3925int radeon_atom_init_mc_reg_table(struct radeon_device *rdev,
3926 u8 module_index,
3927 struct atom_mc_reg_table *reg_table)
3928{
3929 int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
3930 u8 frev, crev, num_entries, t_mem_id, num_ranges = 0;
3931 u32 i = 0, j;
3932 u16 data_offset, size;
3933 union vram_info *vram_info;
3934
3935 memset(reg_table, 0, sizeof(struct atom_mc_reg_table));
3936
3937 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3938 &frev, &crev, &data_offset)) {
3939 vram_info = (union vram_info *)
3940 (rdev->mode_info.atom_context->bios + data_offset);
3941 switch (frev) {
3942 case 1:
3943 DRM_ERROR("old table version %d, %d\n", frev, crev);
3944 return -EINVAL;
3945 case 2:
3946 switch (crev) {
3947 case 1:
3948 if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
3949 ATOM_INIT_REG_BLOCK *reg_block =
3950 (ATOM_INIT_REG_BLOCK *)
3951 ((u8 *)vram_info + le16_to_cpu(vram_info->v2_1.usMemClkPatchTblOffset));
3952 ATOM_MEMORY_SETTING_DATA_BLOCK *reg_data =
3953 (ATOM_MEMORY_SETTING_DATA_BLOCK *)
3954 ((u8 *)reg_block + (2 * sizeof(u16)) +
3955 le16_to_cpu(reg_block->usRegIndexTblSize));
Alex Deucherf90555c2013-07-17 16:34:12 -04003956 ATOM_INIT_REG_INDEX_FORMAT *format = &reg_block->asRegIndexBuf[0];
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003957 num_entries = (u8)((le16_to_cpu(reg_block->usRegIndexTblSize)) /
3958 sizeof(ATOM_INIT_REG_INDEX_FORMAT)) - 1;
3959 if (num_entries > VBIOS_MC_REGISTER_ARRAY_SIZE)
3960 return -EINVAL;
Andre Heider48fa04c2013-07-17 14:02:23 -04003961 while (i < num_entries) {
Alex Deucherf90555c2013-07-17 16:34:12 -04003962 if (format->ucPreRegDataLength & ACCESS_PLACEHOLDER)
Andre Heider48fa04c2013-07-17 14:02:23 -04003963 break;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003964 reg_table->mc_reg_address[i].s1 =
Alex Deucherf90555c2013-07-17 16:34:12 -04003965 (u16)(le16_to_cpu(format->usRegIndex));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003966 reg_table->mc_reg_address[i].pre_reg_data =
Alex Deucherf90555c2013-07-17 16:34:12 -04003967 (u8)(format->ucPreRegDataLength);
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003968 i++;
Alex Deucherf90555c2013-07-17 16:34:12 -04003969 format = (ATOM_INIT_REG_INDEX_FORMAT *)
3970 ((u8 *)format + sizeof(ATOM_INIT_REG_INDEX_FORMAT));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003971 }
3972 reg_table->last = i;
Alex Deucherd526fbd2014-01-16 10:53:50 -05003973 while ((le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK) &&
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003974 (num_ranges < VBIOS_MAX_AC_TIMING_ENTRIES)) {
Alex Deucherd526fbd2014-01-16 10:53:50 -05003975 t_mem_id = (u8)((le32_to_cpu(*(u32 *)reg_data) & MEM_ID_MASK)
3976 >> MEM_ID_SHIFT);
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003977 if (module_index == t_mem_id) {
3978 reg_table->mc_reg_table_entry[num_ranges].mclk_max =
Alex Deucherd526fbd2014-01-16 10:53:50 -05003979 (u32)((le32_to_cpu(*(u32 *)reg_data) & CLOCK_RANGE_MASK)
3980 >> CLOCK_RANGE_SHIFT);
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003981 for (i = 0, j = 1; i < reg_table->last; i++) {
3982 if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_FROM_TABLE) {
3983 reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
Alex Deucherd526fbd2014-01-16 10:53:50 -05003984 (u32)le32_to_cpu(*((u32 *)reg_data + j));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003985 j++;
3986 } else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
3987 reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
3988 reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
3989 }
3990 }
3991 num_ranges++;
3992 }
Alex Deucher4da18e22013-07-01 13:33:53 -04003993 reg_data = (ATOM_MEMORY_SETTING_DATA_BLOCK *)
3994 ((u8 *)reg_data + le16_to_cpu(reg_block->usRegDataBlkSize));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003995 }
Alex Deucherd526fbd2014-01-16 10:53:50 -05003996 if (le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK)
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003997 return -EINVAL;
3998 reg_table->num_entries = num_ranges;
3999 } else
4000 return -EINVAL;
4001 break;
4002 default:
4003 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
4004 return -EINVAL;
4005 }
4006 break;
4007 default:
4008 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
4009 return -EINVAL;
4010 }
4011 return 0;
4012 }
4013 return -EINVAL;
4014}
4015
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004016void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
4017{
4018 struct radeon_device *rdev = dev->dev_private;
4019 uint32_t bios_2_scratch, bios_6_scratch;
4020
4021 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10004022 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004023 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
4024 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10004025 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004026 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
4027 }
4028
4029 /* let the bios control the backlight */
4030 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
4031
4032 /* tell the bios not to handle mode switching */
Alex Deucher87364762011-02-02 19:46:06 -05004033 bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004034
Alex Deucher6802d4b2014-01-27 18:29:35 -05004035 /* clear the vbios dpms state */
4036 if (ASIC_IS_DCE4(rdev))
4037 bios_2_scratch &= ~ATOM_S2_DEVICE_DPMS_STATE;
4038
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004039 if (rdev->family >= CHIP_R600) {
4040 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
4041 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
4042 } else {
4043 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
4044 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
4045 }
4046
4047}
4048
Yang Zhaof657c2a2009-09-15 12:21:01 +10004049void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
4050{
4051 uint32_t scratch_reg;
4052 int i;
4053
4054 if (rdev->family >= CHIP_R600)
4055 scratch_reg = R600_BIOS_0_SCRATCH;
4056 else
4057 scratch_reg = RADEON_BIOS_0_SCRATCH;
4058
4059 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
4060 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
4061}
4062
4063void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
4064{
4065 uint32_t scratch_reg;
4066 int i;
4067
4068 if (rdev->family >= CHIP_R600)
4069 scratch_reg = R600_BIOS_0_SCRATCH;
4070 else
4071 scratch_reg = RADEON_BIOS_0_SCRATCH;
4072
4073 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
4074 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
4075}
4076
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004077void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
4078{
4079 struct drm_device *dev = encoder->dev;
4080 struct radeon_device *rdev = dev->dev_private;
4081 uint32_t bios_6_scratch;
4082
4083 if (rdev->family >= CHIP_R600)
4084 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
4085 else
4086 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
4087
Alex Deucher87364762011-02-02 19:46:06 -05004088 if (lock) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004089 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
Alex Deucher87364762011-02-02 19:46:06 -05004090 bios_6_scratch &= ~ATOM_S6_ACC_MODE;
4091 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004092 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
Alex Deucher87364762011-02-02 19:46:06 -05004093 bios_6_scratch |= ATOM_S6_ACC_MODE;
4094 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004095
4096 if (rdev->family >= CHIP_R600)
4097 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
4098 else
4099 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
4100}
4101
4102/* at some point we may want to break this out into individual functions */
4103void
4104radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
4105 struct drm_encoder *encoder,
4106 bool connected)
4107{
4108 struct drm_device *dev = connector->dev;
4109 struct radeon_device *rdev = dev->dev_private;
4110 struct radeon_connector *radeon_connector =
4111 to_radeon_connector(connector);
4112 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
4113 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
4114
4115 if (rdev->family >= CHIP_R600) {
4116 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
4117 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
4118 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
4119 } else {
4120 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
4121 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
4122 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
4123 }
4124
4125 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
4126 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
4127 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004128 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004129 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
4130 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
4131 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004132 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004133 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
4134 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
4135 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
4136 }
4137 }
4138 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
4139 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
4140 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004141 DRM_DEBUG_KMS("CV connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004142 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
4143 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
4144 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004145 DRM_DEBUG_KMS("CV disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004146 bios_0_scratch &= ~ATOM_S0_CV_MASK;
4147 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
4148 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
4149 }
4150 }
4151 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
4152 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
4153 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004154 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004155 bios_0_scratch |= ATOM_S0_LCD1;
4156 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
4157 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
4158 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004159 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004160 bios_0_scratch &= ~ATOM_S0_LCD1;
4161 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
4162 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
4163 }
4164 }
4165 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
4166 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
4167 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004168 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004169 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
4170 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
4171 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
4172 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004173 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004174 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
4175 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
4176 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
4177 }
4178 }
4179 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
4180 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
4181 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004182 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004183 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
4184 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
4185 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
4186 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004187 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004188 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
4189 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
4190 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
4191 }
4192 }
4193 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
4194 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
4195 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004196 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004197 bios_0_scratch |= ATOM_S0_DFP1;
4198 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
4199 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
4200 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004201 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004202 bios_0_scratch &= ~ATOM_S0_DFP1;
4203 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
4204 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
4205 }
4206 }
4207 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
4208 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
4209 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004210 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004211 bios_0_scratch |= ATOM_S0_DFP2;
4212 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
4213 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
4214 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004215 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004216 bios_0_scratch &= ~ATOM_S0_DFP2;
4217 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
4218 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
4219 }
4220 }
4221 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
4222 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
4223 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004224 DRM_DEBUG_KMS("DFP3 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004225 bios_0_scratch |= ATOM_S0_DFP3;
4226 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
4227 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
4228 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004229 DRM_DEBUG_KMS("DFP3 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004230 bios_0_scratch &= ~ATOM_S0_DFP3;
4231 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
4232 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
4233 }
4234 }
4235 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
4236 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
4237 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004238 DRM_DEBUG_KMS("DFP4 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004239 bios_0_scratch |= ATOM_S0_DFP4;
4240 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
4241 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
4242 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004243 DRM_DEBUG_KMS("DFP4 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004244 bios_0_scratch &= ~ATOM_S0_DFP4;
4245 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
4246 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
4247 }
4248 }
4249 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
4250 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
4251 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004252 DRM_DEBUG_KMS("DFP5 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004253 bios_0_scratch |= ATOM_S0_DFP5;
4254 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
4255 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
4256 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004257 DRM_DEBUG_KMS("DFP5 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004258 bios_0_scratch &= ~ATOM_S0_DFP5;
4259 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
4260 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
4261 }
4262 }
Alex Deucher6f9f8a62012-02-13 08:59:41 -05004263 if ((radeon_encoder->devices & ATOM_DEVICE_DFP6_SUPPORT) &&
4264 (radeon_connector->devices & ATOM_DEVICE_DFP6_SUPPORT)) {
4265 if (connected) {
4266 DRM_DEBUG_KMS("DFP6 connected\n");
4267 bios_0_scratch |= ATOM_S0_DFP6;
4268 bios_3_scratch |= ATOM_S3_DFP6_ACTIVE;
4269 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP6;
4270 } else {
4271 DRM_DEBUG_KMS("DFP6 disconnected\n");
4272 bios_0_scratch &= ~ATOM_S0_DFP6;
4273 bios_3_scratch &= ~ATOM_S3_DFP6_ACTIVE;
4274 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP6;
4275 }
4276 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004277
4278 if (rdev->family >= CHIP_R600) {
4279 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
4280 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
4281 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
4282 } else {
4283 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
4284 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
4285 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
4286 }
4287}
4288
4289void
4290radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
4291{
4292 struct drm_device *dev = encoder->dev;
4293 struct radeon_device *rdev = dev->dev_private;
4294 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
4295 uint32_t bios_3_scratch;
4296
Alex Deucher6f9f8a62012-02-13 08:59:41 -05004297 if (ASIC_IS_DCE4(rdev))
4298 return;
4299
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004300 if (rdev->family >= CHIP_R600)
4301 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
4302 else
4303 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
4304
4305 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
4306 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
4307 bios_3_scratch |= (crtc << 18);
4308 }
4309 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
4310 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
4311 bios_3_scratch |= (crtc << 24);
4312 }
4313 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
4314 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
4315 bios_3_scratch |= (crtc << 16);
4316 }
4317 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
4318 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
4319 bios_3_scratch |= (crtc << 20);
4320 }
4321 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
4322 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
4323 bios_3_scratch |= (crtc << 17);
4324 }
4325 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
4326 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
4327 bios_3_scratch |= (crtc << 19);
4328 }
4329 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
4330 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
4331 bios_3_scratch |= (crtc << 23);
4332 }
4333 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
4334 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
4335 bios_3_scratch |= (crtc << 25);
4336 }
4337
4338 if (rdev->family >= CHIP_R600)
4339 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
4340 else
4341 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
4342}
4343
4344void
4345radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
4346{
4347 struct drm_device *dev = encoder->dev;
4348 struct radeon_device *rdev = dev->dev_private;
4349 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
4350 uint32_t bios_2_scratch;
4351
Alex Deucher3ac0eb62012-02-19 21:42:03 -05004352 if (ASIC_IS_DCE4(rdev))
4353 return;
4354
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004355 if (rdev->family >= CHIP_R600)
4356 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
4357 else
4358 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
4359
4360 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
4361 if (on)
4362 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
4363 else
4364 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
4365 }
4366 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
4367 if (on)
4368 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
4369 else
4370 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
4371 }
4372 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
4373 if (on)
4374 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
4375 else
4376 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
4377 }
4378 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
4379 if (on)
4380 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
4381 else
4382 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
4383 }
4384 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
4385 if (on)
4386 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
4387 else
4388 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
4389 }
4390 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
4391 if (on)
4392 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
4393 else
4394 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
4395 }
4396 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
4397 if (on)
4398 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
4399 else
4400 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
4401 }
4402 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
4403 if (on)
4404 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
4405 else
4406 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
4407 }
4408 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
4409 if (on)
4410 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
4411 else
4412 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
4413 }
4414 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
4415 if (on)
4416 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
4417 else
4418 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
4419 }
4420
4421 if (rdev->family >= CHIP_R600)
4422 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
4423 else
4424 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
4425}