blob: 7ef3d9e53af53b60a5620eff33b2b27c45c45daa [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
Alex Deucher09e619c2014-11-07 11:16:25 -0500199struct radeon_gpio_rec radeon_atombios_lookup_gpio(struct radeon_device *rdev,
200 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
Michele Curti7f6bf722014-09-23 18:08:06 +0200461static const int supported_devices_connector_convert[] = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200462 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
Michele Curti7f6bf722014-09-23 18:08:06 +0200480static const uint16_t supported_devices_connector_object_id_convert[] = {
Alex Deucherb75fad02009-11-05 13:16:01 -0500481 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
Michele Curti7f6bf722014-09-23 18:08:06 +0200497static const int object_connector_convert[] = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200498 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;
Alex Deucher09e619c2014-11-07 11:16:25 -0500804 gpio = radeon_atombios_lookup_gpio(rdev,
Alex Deuchereed45b32009-12-04 14:45:27 -0500805 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 =
Alex Deucher09e619c2014-11-07 11:16:25 -05002131 radeon_atombios_lookup_gpio(rdev,
Alex Deucher560154e2010-11-22 17:56:34 -05002132 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 =
Alex Deucher09e619c2014-11-07 11:16:25 -05002167 radeon_atombios_lookup_gpio(rdev,
Alex Deucher560154e2010-11-22 17:56:34 -05002168 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 =
Alex Deucher09e619c2014-11-07 11:16:25 -05002203 radeon_atombios_lookup_gpio(rdev,
Alex Deucher560154e2010-11-22 17:56:34 -05002204 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) {
Alex Deucher9b92d1e2014-09-08 02:51:49 -04002251 if (controller->ucFanParameters & ATOM_PP_FANPARAMETERS_NOFAN)
2252 rdev->pm.no_fan = true;
2253 rdev->pm.fan_pulses_per_revolution =
2254 controller->ucFanParameters & ATOM_PP_FANPARAMETERS_TACHOMETER_PULSES_PER_REVOLUTION_MASK;
2255 if (rdev->pm.fan_pulses_per_revolution) {
2256 rdev->pm.fan_min_rpm = controller->ucFanMinRPM;
2257 rdev->pm.fan_max_rpm = controller->ucFanMaxRPM;
2258 }
Alex Deucher560154e2010-11-22 17:56:34 -05002259 if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
2260 DRM_INFO("Internal thermal controller %s fan control\n",
2261 (controller->ucFanParameters &
2262 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2263 rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
2264 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
2265 DRM_INFO("Internal thermal controller %s fan control\n",
2266 (controller->ucFanParameters &
2267 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2268 rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
2269 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
2270 DRM_INFO("Internal thermal controller %s fan control\n",
2271 (controller->ucFanParameters &
2272 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2273 rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
Alex Deucherb0e66412010-11-22 17:56:35 -05002274 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
2275 DRM_INFO("Internal thermal controller %s fan control\n",
2276 (controller->ucFanParameters &
2277 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2278 rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
Alex Deucher4fddba12011-01-06 21:19:22 -05002279 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
2280 DRM_INFO("Internal thermal controller %s fan control\n",
2281 (controller->ucFanParameters &
2282 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2283 rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
Alex Deucher14607d02012-03-20 17:18:09 -04002284 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) {
2285 DRM_INFO("Internal thermal controller %s fan control\n",
2286 (controller->ucFanParameters &
2287 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2288 rdev->pm.int_thermal_type = THERMAL_TYPE_SI;
Alex Deucher51150202012-12-18 22:07:14 -05002289 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_CISLANDS) {
2290 DRM_INFO("Internal thermal controller %s fan control\n",
2291 (controller->ucFanParameters &
2292 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2293 rdev->pm.int_thermal_type = THERMAL_TYPE_CI;
Alex Deucher16fbe002013-04-22 21:41:26 -04002294 } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_KAVERI) {
2295 DRM_INFO("Internal thermal controller %s fan control\n",
2296 (controller->ucFanParameters &
2297 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2298 rdev->pm.int_thermal_type = THERMAL_TYPE_KV;
Alex Deucherff437792014-09-08 02:33:32 -04002299 } else if (controller->ucType ==
2300 ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) {
2301 DRM_INFO("External GPIO thermal controller %s fan control\n",
2302 (controller->ucFanParameters &
2303 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2304 rdev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL_GPIO;
2305 } else if (controller->ucType ==
2306 ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) {
2307 DRM_INFO("ADT7473 with internal thermal controller %s fan control\n",
2308 (controller->ucFanParameters &
2309 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2310 rdev->pm.int_thermal_type = THERMAL_TYPE_ADT7473_WITH_INTERNAL;
2311 } else if (controller->ucType ==
2312 ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL) {
2313 DRM_INFO("EMC2103 with internal thermal controller %s fan control\n",
2314 (controller->ucFanParameters &
2315 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2316 rdev->pm.int_thermal_type = THERMAL_TYPE_EMC2103_WITH_INTERNAL;
Alex Deucher4755fab2012-08-30 13:30:49 -04002317 } else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002318 DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2319 pp_lib_thermal_controller_names[controller->ucType],
2320 controller->ucI2cAddress >> 1,
2321 (controller->ucFanParameters &
2322 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
Alex Deucherff437792014-09-08 02:33:32 -04002323 rdev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL;
Alex Deucher560154e2010-11-22 17:56:34 -05002324 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
2325 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
2326 if (rdev->pm.i2c_bus) {
2327 struct i2c_board_info info = { };
2328 const char *name = pp_lib_thermal_controller_names[controller->ucType];
2329 info.addr = controller->ucI2cAddress >> 1;
2330 strlcpy(info.type, name, sizeof(info.type));
2331 i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2332 }
Alex Deucher4755fab2012-08-30 13:30:49 -04002333 } else {
2334 DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
2335 controller->ucType,
2336 controller->ucI2cAddress >> 1,
2337 (controller->ucFanParameters &
2338 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
Alex Deucher560154e2010-11-22 17:56:34 -05002339 }
2340 }
2341}
2342
Alex Deucher4a6369e2013-04-12 14:04:10 -04002343void radeon_atombios_get_default_voltages(struct radeon_device *rdev,
Alex Deucher2abba662013-03-25 12:47:23 -04002344 u16 *vddc, u16 *vddci, u16 *mvdd)
Alex Deucher560154e2010-11-22 17:56:34 -05002345{
2346 struct radeon_mode_info *mode_info = &rdev->mode_info;
2347 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
2348 u8 frev, crev;
2349 u16 data_offset;
2350 union firmware_info *firmware_info;
Alex Deucher2feea492011-04-12 14:49:24 -04002351
2352 *vddc = 0;
2353 *vddci = 0;
Alex Deucher2abba662013-03-25 12:47:23 -04002354 *mvdd = 0;
Alex Deucher560154e2010-11-22 17:56:34 -05002355
2356 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2357 &frev, &crev, &data_offset)) {
2358 firmware_info =
2359 (union firmware_info *)(mode_info->atom_context->bios +
2360 data_offset);
Alex Deucher2feea492011-04-12 14:49:24 -04002361 *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
Alex Deucher2abba662013-03-25 12:47:23 -04002362 if ((frev == 2) && (crev >= 2)) {
Alex Deucher2feea492011-04-12 14:49:24 -04002363 *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
Alex Deucher2abba662013-03-25 12:47:23 -04002364 *mvdd = le16_to_cpu(firmware_info->info_22.usBootUpMVDDCVoltage);
2365 }
Alex Deucher560154e2010-11-22 17:56:34 -05002366 }
Alex Deucher560154e2010-11-22 17:56:34 -05002367}
2368
2369static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
2370 int state_index, int mode_index,
2371 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
2372{
2373 int j;
2374 u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
2375 u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
Alex Deucher2abba662013-03-25 12:47:23 -04002376 u16 vddc, vddci, mvdd;
Alex Deucher2feea492011-04-12 14:49:24 -04002377
Alex Deucher2abba662013-03-25 12:47:23 -04002378 radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd);
Alex Deucher560154e2010-11-22 17:56:34 -05002379
2380 rdev->pm.power_state[state_index].misc = misc;
2381 rdev->pm.power_state[state_index].misc2 = misc2;
2382 rdev->pm.power_state[state_index].pcie_lanes =
2383 ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
2384 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2385 switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
2386 case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
2387 rdev->pm.power_state[state_index].type =
2388 POWER_STATE_TYPE_BATTERY;
2389 break;
2390 case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
2391 rdev->pm.power_state[state_index].type =
2392 POWER_STATE_TYPE_BALANCED;
2393 break;
2394 case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
2395 rdev->pm.power_state[state_index].type =
2396 POWER_STATE_TYPE_PERFORMANCE;
2397 break;
2398 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2399 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2400 rdev->pm.power_state[state_index].type =
2401 POWER_STATE_TYPE_PERFORMANCE;
2402 break;
2403 }
2404 rdev->pm.power_state[state_index].flags = 0;
2405 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
2406 rdev->pm.power_state[state_index].flags |=
2407 RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2408 if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
2409 rdev->pm.power_state[state_index].type =
2410 POWER_STATE_TYPE_DEFAULT;
2411 rdev->pm.default_power_state_index = state_index;
2412 rdev->pm.power_state[state_index].default_clock_mode =
2413 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
Alex Deucher982cb322013-04-29 10:51:26 -04002414 if ((rdev->family >= CHIP_BARTS) && !(rdev->flags & RADEON_IS_IGP)) {
Alex Deucher9ace9f72011-01-06 21:19:26 -05002415 /* NI chips post without MC ucode, so default clocks are strobe mode only */
2416 rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
2417 rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
2418 rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
Alex Deucher2feea492011-04-12 14:49:24 -04002419 rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
Alex Deucher9ace9f72011-01-06 21:19:26 -05002420 } else {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04002421 u16 max_vddci = 0;
2422
2423 if (ASIC_IS_DCE4(rdev))
2424 radeon_atom_get_max_voltage(rdev,
2425 SET_VOLTAGE_TYPE_ASIC_VDDCI,
2426 &max_vddci);
2427 /* patch the table values with the default sclk/mclk from firmware info */
Alex Deucher9ace9f72011-01-06 21:19:26 -05002428 for (j = 0; j < mode_index; j++) {
2429 rdev->pm.power_state[state_index].clock_info[j].mclk =
2430 rdev->clock.default_mclk;
2431 rdev->pm.power_state[state_index].clock_info[j].sclk =
2432 rdev->clock.default_sclk;
2433 if (vddc)
2434 rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
2435 vddc;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04002436 if (max_vddci)
2437 rdev->pm.power_state[state_index].clock_info[j].voltage.vddci =
2438 max_vddci;
Alex Deucher9ace9f72011-01-06 21:19:26 -05002439 }
Alex Deucher560154e2010-11-22 17:56:34 -05002440 }
2441 }
2442}
2443
2444static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
2445 int state_index, int mode_index,
2446 union pplib_clock_info *clock_info)
2447{
2448 u32 sclk, mclk;
Alex Deuchere83753b2012-03-20 17:18:08 -04002449 u16 vddc;
Alex Deucher560154e2010-11-22 17:56:34 -05002450
2451 if (rdev->flags & RADEON_IS_IGP) {
Alex Deucherb0e66412010-11-22 17:56:35 -05002452 if (rdev->family >= CHIP_PALM) {
2453 sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
2454 sclk |= clock_info->sumo.ucEngineClockHigh << 16;
2455 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2456 } else {
2457 sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
2458 sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
2459 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2460 }
Alex Deucherbc19f592013-06-07 11:41:05 -04002461 } else if (rdev->family >= CHIP_BONAIRE) {
2462 sclk = le16_to_cpu(clock_info->ci.usEngineClockLow);
2463 sclk |= clock_info->ci.ucEngineClockHigh << 16;
2464 mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow);
2465 mclk |= clock_info->ci.ucMemoryClockHigh << 16;
2466 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2467 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2468 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2469 VOLTAGE_NONE;
Alex Deucher982cb322013-04-29 10:51:26 -04002470 } else if (rdev->family >= CHIP_TAHITI) {
Alex Deucher14607d02012-03-20 17:18:09 -04002471 sclk = le16_to_cpu(clock_info->si.usEngineClockLow);
2472 sclk |= clock_info->si.ucEngineClockHigh << 16;
2473 mclk = le16_to_cpu(clock_info->si.usMemoryClockLow);
2474 mclk |= clock_info->si.ucMemoryClockHigh << 16;
2475 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2476 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2477 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2478 VOLTAGE_SW;
2479 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2480 le16_to_cpu(clock_info->si.usVDDC);
2481 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
2482 le16_to_cpu(clock_info->si.usVDDCI);
Alex Deucher982cb322013-04-29 10:51:26 -04002483 } else if (rdev->family >= CHIP_CEDAR) {
Alex Deucher560154e2010-11-22 17:56:34 -05002484 sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
2485 sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
2486 mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
2487 mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
2488 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2489 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2490 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2491 VOLTAGE_SW;
2492 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
Cédric Cano45894332011-02-11 19:45:37 -05002493 le16_to_cpu(clock_info->evergreen.usVDDC);
Alex Deucher2feea492011-04-12 14:49:24 -04002494 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
2495 le16_to_cpu(clock_info->evergreen.usVDDCI);
Alex Deucher560154e2010-11-22 17:56:34 -05002496 } else {
2497 sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
2498 sclk |= clock_info->r600.ucEngineClockHigh << 16;
2499 mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
2500 mclk |= clock_info->r600.ucMemoryClockHigh << 16;
2501 rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
2502 rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2503 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
2504 VOLTAGE_SW;
2505 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
Cédric Cano45894332011-02-11 19:45:37 -05002506 le16_to_cpu(clock_info->r600.usVDDC);
Alex Deucher560154e2010-11-22 17:56:34 -05002507 }
2508
Alex Deucheree4017f2011-06-23 12:19:32 -04002509 /* patch up vddc if necessary */
Alex Deuchere83753b2012-03-20 17:18:08 -04002510 switch (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage) {
2511 case ATOM_VIRTUAL_VOLTAGE_ID0:
2512 case ATOM_VIRTUAL_VOLTAGE_ID1:
2513 case ATOM_VIRTUAL_VOLTAGE_ID2:
2514 case ATOM_VIRTUAL_VOLTAGE_ID3:
Alex Deucherc6cf7772013-07-05 13:14:30 -04002515 case ATOM_VIRTUAL_VOLTAGE_ID4:
2516 case ATOM_VIRTUAL_VOLTAGE_ID5:
2517 case ATOM_VIRTUAL_VOLTAGE_ID6:
2518 case ATOM_VIRTUAL_VOLTAGE_ID7:
Alex Deuchere83753b2012-03-20 17:18:08 -04002519 if (radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC,
2520 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage,
2521 &vddc) == 0)
Alex Deucheree4017f2011-06-23 12:19:32 -04002522 rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
Alex Deuchere83753b2012-03-20 17:18:08 -04002523 break;
2524 default:
2525 break;
Alex Deucheree4017f2011-06-23 12:19:32 -04002526 }
2527
Alex Deucher560154e2010-11-22 17:56:34 -05002528 if (rdev->flags & RADEON_IS_IGP) {
2529 /* skip invalid modes */
2530 if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
2531 return false;
2532 } else {
2533 /* skip invalid modes */
2534 if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
2535 (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
2536 return false;
2537 }
2538 return true;
2539}
2540
2541static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
2542{
2543 struct radeon_mode_info *mode_info = &rdev->mode_info;
2544 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2545 union pplib_power_state *power_state;
2546 int i, j;
2547 int state_index = 0, mode_index = 0;
2548 union pplib_clock_info *clock_info;
2549 bool valid;
2550 union power_info *power_info;
2551 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2552 u16 data_offset;
2553 u8 frev, crev;
2554
2555 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2556 &frev, &crev, &data_offset))
2557 return state_index;
2558 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2559
2560 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
Alex Deucherf8e6bfc2013-04-25 09:29:17 -04002561 if (power_info->pplib.ucNumStates == 0)
2562 return state_index;
Alex Deucher0975b162011-02-02 18:42:03 -05002563 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2564 power_info->pplib.ucNumStates, GFP_KERNEL);
2565 if (!rdev->pm.power_state)
2566 return state_index;
Alex Deucher560154e2010-11-22 17:56:34 -05002567 /* first mode is usually default, followed by low to high */
2568 for (i = 0; i < power_info->pplib.ucNumStates; i++) {
2569 mode_index = 0;
2570 power_state = (union pplib_power_state *)
2571 (mode_info->atom_context->bios + data_offset +
2572 le16_to_cpu(power_info->pplib.usStateArrayOffset) +
2573 i * power_info->pplib.ucStateEntrySize);
2574 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2575 (mode_info->atom_context->bios + data_offset +
2576 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
2577 (power_state->v1.ucNonClockStateIndex *
2578 power_info->pplib.ucNonClockSize));
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002579 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2580 ((power_info->pplib.ucStateEntrySize - 1) ?
2581 (power_info->pplib.ucStateEntrySize - 1) : 1),
2582 GFP_KERNEL);
2583 if (!rdev->pm.power_state[i].clock_info)
2584 return state_index;
2585 if (power_info->pplib.ucStateEntrySize - 1) {
2586 for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
2587 clock_info = (union pplib_clock_info *)
2588 (mode_info->atom_context->bios + data_offset +
2589 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
2590 (power_state->v1.ucClockStateIndices[j] *
2591 power_info->pplib.ucClockInfoSize));
2592 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2593 state_index, mode_index,
2594 clock_info);
2595 if (valid)
2596 mode_index++;
2597 }
2598 } else {
2599 rdev->pm.power_state[state_index].clock_info[0].mclk =
2600 rdev->clock.default_mclk;
2601 rdev->pm.power_state[state_index].clock_info[0].sclk =
2602 rdev->clock.default_sclk;
2603 mode_index++;
Alex Deucher560154e2010-11-22 17:56:34 -05002604 }
2605 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2606 if (mode_index) {
2607 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2608 non_clock_info);
2609 state_index++;
2610 }
2611 }
2612 /* if multiple clock modes, mark the lowest as no display */
2613 for (i = 0; i < state_index; i++) {
2614 if (rdev->pm.power_state[i].num_clock_modes > 1)
2615 rdev->pm.power_state[i].clock_info[0].flags |=
2616 RADEON_PM_MODE_NO_DISPLAY;
2617 }
2618 /* first mode is usually default */
2619 if (rdev->pm.default_power_state_index == -1) {
2620 rdev->pm.power_state[0].type =
2621 POWER_STATE_TYPE_DEFAULT;
2622 rdev->pm.default_power_state_index = 0;
2623 rdev->pm.power_state[0].default_clock_mode =
2624 &rdev->pm.power_state[0].clock_info[0];
2625 }
2626 return state_index;
2627}
2628
Alex Deucherb0e66412010-11-22 17:56:35 -05002629static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
2630{
2631 struct radeon_mode_info *mode_info = &rdev->mode_info;
2632 struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2633 union pplib_power_state *power_state;
2634 int i, j, non_clock_array_index, clock_array_index;
2635 int state_index = 0, mode_index = 0;
2636 union pplib_clock_info *clock_info;
Alex Deucherf7346882012-03-20 17:17:58 -04002637 struct _StateArray *state_array;
2638 struct _ClockInfoArray *clock_info_array;
2639 struct _NonClockInfoArray *non_clock_info_array;
Alex Deucherb0e66412010-11-22 17:56:35 -05002640 bool valid;
2641 union power_info *power_info;
2642 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2643 u16 data_offset;
2644 u8 frev, crev;
Alex Deucher441e76c2013-05-01 14:34:54 -04002645 u8 *power_state_offset;
Alex Deucherb0e66412010-11-22 17:56:35 -05002646
2647 if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2648 &frev, &crev, &data_offset))
2649 return state_index;
2650 power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2651
2652 radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
Alex Deucherf7346882012-03-20 17:17:58 -04002653 state_array = (struct _StateArray *)
Alex Deucherb0e66412010-11-22 17:56:35 -05002654 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002655 le16_to_cpu(power_info->pplib.usStateArrayOffset));
Alex Deucherf7346882012-03-20 17:17:58 -04002656 clock_info_array = (struct _ClockInfoArray *)
Alex Deucherb0e66412010-11-22 17:56:35 -05002657 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002658 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
Alex Deucherf7346882012-03-20 17:17:58 -04002659 non_clock_info_array = (struct _NonClockInfoArray *)
Alex Deucherb0e66412010-11-22 17:56:35 -05002660 (mode_info->atom_context->bios + data_offset +
Cédric Cano45894332011-02-11 19:45:37 -05002661 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
Alex Deucherf8e6bfc2013-04-25 09:29:17 -04002662 if (state_array->ucNumEntries == 0)
2663 return state_index;
Alex Deucher0975b162011-02-02 18:42:03 -05002664 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2665 state_array->ucNumEntries, GFP_KERNEL);
2666 if (!rdev->pm.power_state)
2667 return state_index;
Alex Deucher441e76c2013-05-01 14:34:54 -04002668 power_state_offset = (u8 *)state_array->states;
Alex Deucherb0e66412010-11-22 17:56:35 -05002669 for (i = 0; i < state_array->ucNumEntries; i++) {
2670 mode_index = 0;
Alex Deucher441e76c2013-05-01 14:34:54 -04002671 power_state = (union pplib_power_state *)power_state_offset;
2672 non_clock_array_index = power_state->v2.nonClockInfoIndex;
Alex Deucherb0e66412010-11-22 17:56:35 -05002673 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2674 &non_clock_info_array->nonClockInfo[non_clock_array_index];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002675 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2676 (power_state->v2.ucNumDPMLevels ?
2677 power_state->v2.ucNumDPMLevels : 1),
2678 GFP_KERNEL);
2679 if (!rdev->pm.power_state[i].clock_info)
2680 return state_index;
2681 if (power_state->v2.ucNumDPMLevels) {
2682 for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2683 clock_array_index = power_state->v2.clockInfoIndex[j];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002684 clock_info = (union pplib_clock_info *)
Alex Deucherf7346882012-03-20 17:17:58 -04002685 &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002686 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2687 state_index, mode_index,
2688 clock_info);
2689 if (valid)
2690 mode_index++;
2691 }
2692 } else {
2693 rdev->pm.power_state[state_index].clock_info[0].mclk =
2694 rdev->clock.default_mclk;
2695 rdev->pm.power_state[state_index].clock_info[0].sclk =
2696 rdev->clock.default_sclk;
2697 mode_index++;
Alex Deucherb0e66412010-11-22 17:56:35 -05002698 }
2699 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2700 if (mode_index) {
2701 radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2702 non_clock_info);
2703 state_index++;
2704 }
Alex Deucher441e76c2013-05-01 14:34:54 -04002705 power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
Alex Deucherb0e66412010-11-22 17:56:35 -05002706 }
2707 /* if multiple clock modes, mark the lowest as no display */
2708 for (i = 0; i < state_index; i++) {
2709 if (rdev->pm.power_state[i].num_clock_modes > 1)
2710 rdev->pm.power_state[i].clock_info[0].flags |=
2711 RADEON_PM_MODE_NO_DISPLAY;
2712 }
2713 /* first mode is usually default */
2714 if (rdev->pm.default_power_state_index == -1) {
2715 rdev->pm.power_state[0].type =
2716 POWER_STATE_TYPE_DEFAULT;
2717 rdev->pm.default_power_state_index = 0;
2718 rdev->pm.power_state[0].default_clock_mode =
2719 &rdev->pm.power_state[0].clock_info[0];
2720 }
2721 return state_index;
2722}
2723
Alex Deucher56278a82009-12-28 13:58:44 -05002724void radeon_atombios_get_power_modes(struct radeon_device *rdev)
2725{
2726 struct radeon_mode_info *mode_info = &rdev->mode_info;
2727 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2728 u16 data_offset;
2729 u8 frev, crev;
Alex Deucher560154e2010-11-22 17:56:34 -05002730 int state_index = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002731
Alex Deuchera48b9b42010-04-22 14:03:55 -04002732 rdev->pm.default_power_state_index = -1;
Alex Deucher56278a82009-12-28 13:58:44 -05002733
Alex Deuchera084e6e2010-03-18 01:04:01 -04002734 if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2735 &frev, &crev, &data_offset)) {
Alex Deucher560154e2010-11-22 17:56:34 -05002736 switch (frev) {
2737 case 1:
2738 case 2:
2739 case 3:
2740 state_index = radeon_atombios_parse_power_table_1_3(rdev);
2741 break;
2742 case 4:
2743 case 5:
2744 state_index = radeon_atombios_parse_power_table_4_5(rdev);
2745 break;
Alex Deucherb0e66412010-11-22 17:56:35 -05002746 case 6:
2747 state_index = radeon_atombios_parse_power_table_6(rdev);
2748 break;
Alex Deucher560154e2010-11-22 17:56:34 -05002749 default:
2750 break;
Alex Deucher56278a82009-12-28 13:58:44 -05002751 }
Alex Deucherf8e6bfc2013-04-25 09:29:17 -04002752 }
2753
2754 if (state_index == 0) {
Alex Deucher0975b162011-02-02 18:42:03 -05002755 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
2756 if (rdev->pm.power_state) {
Alex Deucher8f3f1c92011-11-04 10:09:43 -04002757 rdev->pm.power_state[0].clock_info =
2758 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2759 if (rdev->pm.power_state[0].clock_info) {
2760 /* add the default mode */
2761 rdev->pm.power_state[state_index].type =
2762 POWER_STATE_TYPE_DEFAULT;
2763 rdev->pm.power_state[state_index].num_clock_modes = 1;
2764 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2765 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2766 rdev->pm.power_state[state_index].default_clock_mode =
2767 &rdev->pm.power_state[state_index].clock_info[0];
2768 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2769 rdev->pm.power_state[state_index].pcie_lanes = 16;
2770 rdev->pm.default_power_state_index = state_index;
2771 rdev->pm.power_state[state_index].flags = 0;
2772 state_index++;
2773 }
Alex Deucher0975b162011-02-02 18:42:03 -05002774 }
Alex Deucher56278a82009-12-28 13:58:44 -05002775 }
Alex Deucher02b17cc2010-04-22 13:25:06 -04002776
Alex Deucher56278a82009-12-28 13:58:44 -05002777 rdev->pm.num_power_states = state_index;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +00002778
Alex Deuchera48b9b42010-04-22 14:03:55 -04002779 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2780 rdev->pm.current_clock_mode_index = 0;
Alexander Müller4376eee2011-12-30 12:55:48 -05002781 if (rdev->pm.default_power_state_index >= 0)
2782 rdev->pm.current_vddc =
2783 rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
2784 else
2785 rdev->pm.current_vddc = 0;
Alex Deucher56278a82009-12-28 13:58:44 -05002786}
2787
Christian König7062ab62013-04-08 12:41:31 +02002788union get_clock_dividers {
2789 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS v1;
2790 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2 v2;
2791 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3 v3;
2792 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V4 v4;
2793 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V5 v5;
Alex Deucher9219ed62013-02-19 14:35:34 -05002794 struct _COMPUTE_GPU_CLOCK_INPUT_PARAMETERS_V1_6 v6_in;
2795 struct _COMPUTE_GPU_CLOCK_OUTPUT_PARAMETERS_V1_6 v6_out;
Christian König7062ab62013-04-08 12:41:31 +02002796};
2797
2798int radeon_atom_get_clock_dividers(struct radeon_device *rdev,
2799 u8 clock_type,
2800 u32 clock,
2801 bool strobe_mode,
2802 struct atom_clock_dividers *dividers)
2803{
2804 union get_clock_dividers args;
2805 int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryEnginePLL);
2806 u8 frev, crev;
2807
2808 memset(&args, 0, sizeof(args));
2809 memset(dividers, 0, sizeof(struct atom_clock_dividers));
2810
2811 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2812 return -EINVAL;
2813
2814 switch (crev) {
2815 case 1:
2816 /* r4xx, r5xx */
2817 args.v1.ucAction = clock_type;
2818 args.v1.ulClock = cpu_to_le32(clock); /* 10 khz */
2819
2820 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2821
2822 dividers->post_div = args.v1.ucPostDiv;
2823 dividers->fb_div = args.v1.ucFbDiv;
2824 dividers->enable_post_div = true;
2825 break;
2826 case 2:
2827 case 3:
Alex Deucher360b1f52013-06-07 11:50:12 -04002828 case 5:
2829 /* r6xx, r7xx, evergreen, ni, si */
Christian König7062ab62013-04-08 12:41:31 +02002830 if (rdev->family <= CHIP_RV770) {
2831 args.v2.ucAction = clock_type;
2832 args.v2.ulClock = cpu_to_le32(clock); /* 10 khz */
2833
2834 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2835
2836 dividers->post_div = args.v2.ucPostDiv;
2837 dividers->fb_div = le16_to_cpu(args.v2.usFbDiv);
2838 dividers->ref_div = args.v2.ucAction;
2839 if (rdev->family == CHIP_RV770) {
2840 dividers->enable_post_div = (le32_to_cpu(args.v2.ulClock) & (1 << 24)) ?
2841 true : false;
2842 dividers->vco_mode = (le32_to_cpu(args.v2.ulClock) & (1 << 25)) ? 1 : 0;
2843 } else
2844 dividers->enable_post_div = (dividers->fb_div & 1) ? true : false;
2845 } else {
2846 if (clock_type == COMPUTE_ENGINE_PLL_PARAM) {
Alex Deucherf4a25962013-04-22 09:59:01 -04002847 args.v3.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
Christian König7062ab62013-04-08 12:41:31 +02002848
2849 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2850
2851 dividers->post_div = args.v3.ucPostDiv;
2852 dividers->enable_post_div = (args.v3.ucCntlFlag &
2853 ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
2854 dividers->enable_dithen = (args.v3.ucCntlFlag &
2855 ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
Alex Deucher20fab642013-07-28 12:33:56 -04002856 dividers->whole_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDiv);
Christian König7062ab62013-04-08 12:41:31 +02002857 dividers->frac_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDivFrac);
2858 dividers->ref_div = args.v3.ucRefDiv;
2859 dividers->vco_mode = (args.v3.ucCntlFlag &
2860 ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
2861 } else {
Alex Deucher360b1f52013-06-07 11:50:12 -04002862 /* for SI we use ComputeMemoryClockParam for memory plls */
2863 if (rdev->family >= CHIP_TAHITI)
2864 return -EINVAL;
Alex Deucherf4a25962013-04-22 09:59:01 -04002865 args.v5.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
Christian König7062ab62013-04-08 12:41:31 +02002866 if (strobe_mode)
2867 args.v5.ucInputFlag = ATOM_PLL_INPUT_FLAG_PLL_STROBE_MODE_EN;
2868
2869 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2870
2871 dividers->post_div = args.v5.ucPostDiv;
2872 dividers->enable_post_div = (args.v5.ucCntlFlag &
2873 ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
2874 dividers->enable_dithen = (args.v5.ucCntlFlag &
2875 ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
2876 dividers->whole_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDiv);
2877 dividers->frac_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDivFrac);
2878 dividers->ref_div = args.v5.ucRefDiv;
2879 dividers->vco_mode = (args.v5.ucCntlFlag &
2880 ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
2881 }
2882 }
2883 break;
2884 case 4:
2885 /* fusion */
2886 args.v4.ulClock = cpu_to_le32(clock); /* 10 khz */
2887
2888 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2889
Alex Deucher9219ed62013-02-19 14:35:34 -05002890 dividers->post_divider = dividers->post_div = args.v4.ucPostDiv;
Christian König7062ab62013-04-08 12:41:31 +02002891 dividers->real_clock = le32_to_cpu(args.v4.ulClock);
2892 break;
Alex Deucher9219ed62013-02-19 14:35:34 -05002893 case 6:
2894 /* CI */
2895 /* COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, COMPUTE_GPUCLK_INPUT_FLAG_SCLK */
2896 args.v6_in.ulClock.ulComputeClockFlag = clock_type;
2897 args.v6_in.ulClock.ulClockFreq = cpu_to_le32(clock); /* 10 khz */
2898
2899 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2900
2901 dividers->whole_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDiv);
2902 dividers->frac_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDivFrac);
2903 dividers->ref_div = args.v6_out.ucPllRefDiv;
2904 dividers->post_div = args.v6_out.ucPllPostDiv;
2905 dividers->flags = args.v6_out.ucPllCntlFlag;
2906 dividers->real_clock = le32_to_cpu(args.v6_out.ulClock.ulClock);
2907 dividers->post_divider = args.v6_out.ulClock.ucPostDiv;
2908 break;
Christian König7062ab62013-04-08 12:41:31 +02002909 default:
2910 return -EINVAL;
2911 }
2912 return 0;
2913}
2914
Alex Deuchereaa778a2013-02-13 16:38:25 -05002915int radeon_atom_get_memory_pll_dividers(struct radeon_device *rdev,
2916 u32 clock,
2917 bool strobe_mode,
2918 struct atom_mpll_param *mpll_param)
2919{
2920 COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args;
2921 int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryClockParam);
2922 u8 frev, crev;
2923
2924 memset(&args, 0, sizeof(args));
2925 memset(mpll_param, 0, sizeof(struct atom_mpll_param));
2926
2927 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2928 return -EINVAL;
2929
2930 switch (frev) {
2931 case 2:
2932 switch (crev) {
2933 case 1:
2934 /* SI */
2935 args.ulClock = cpu_to_le32(clock); /* 10 khz */
2936 args.ucInputFlag = 0;
2937 if (strobe_mode)
2938 args.ucInputFlag |= MPLL_INPUT_FLAG_STROBE_MODE_EN;
2939
2940 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2941
2942 mpll_param->clkfrac = le16_to_cpu(args.ulFbDiv.usFbDivFrac);
2943 mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv);
2944 mpll_param->post_div = args.ucPostDiv;
2945 mpll_param->dll_speed = args.ucDllSpeed;
2946 mpll_param->bwcntl = args.ucBWCntl;
2947 mpll_param->vco_mode =
Alex Deucher180f8052013-11-21 09:52:01 -05002948 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_VCO_MODE_MASK);
Alex Deuchereaa778a2013-02-13 16:38:25 -05002949 mpll_param->yclk_sel =
2950 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_BYPASS_DQ_PLL) ? 1 : 0;
2951 mpll_param->qdr =
2952 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_QDR_ENABLE) ? 1 : 0;
2953 mpll_param->half_rate =
2954 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_AD_HALF_RATE) ? 1 : 0;
2955 break;
2956 default:
2957 return -EINVAL;
2958 }
2959 break;
2960 default:
2961 return -EINVAL;
2962 }
2963 return 0;
2964}
2965
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002966void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
2967{
2968 DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
2969 int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
2970
2971 args.ucEnable = enable;
2972
2973 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2974}
2975
Rafał Miłecki74338742009-11-03 00:53:02 +01002976uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
2977{
2978 GET_ENGINE_CLOCK_PS_ALLOCATION args;
2979 int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
2980
2981 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
Cédric Cano45894332011-02-11 19:45:37 -05002982 return le32_to_cpu(args.ulReturnEngineClock);
Rafał Miłecki74338742009-11-03 00:53:02 +01002983}
2984
2985uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
2986{
2987 GET_MEMORY_CLOCK_PS_ALLOCATION args;
2988 int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
2989
2990 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
Cédric Cano45894332011-02-11 19:45:37 -05002991 return le32_to_cpu(args.ulReturnMemoryClock);
Rafał Miłecki74338742009-11-03 00:53:02 +01002992}
2993
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002994void radeon_atom_set_engine_clock(struct radeon_device *rdev,
2995 uint32_t eng_clock)
2996{
2997 SET_ENGINE_CLOCK_PS_ALLOCATION args;
2998 int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
2999
Cédric Cano45894332011-02-11 19:45:37 -05003000 args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003001
3002 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3003}
3004
3005void radeon_atom_set_memory_clock(struct radeon_device *rdev,
3006 uint32_t mem_clock)
3007{
3008 SET_MEMORY_CLOCK_PS_ALLOCATION args;
3009 int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
3010
3011 if (rdev->flags & RADEON_IS_IGP)
3012 return;
3013
Cédric Cano45894332011-02-11 19:45:37 -05003014 args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02003015
3016 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3017}
3018
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003019void radeon_atom_set_engine_dram_timings(struct radeon_device *rdev,
3020 u32 eng_clock, u32 mem_clock)
3021{
3022 SET_ENGINE_CLOCK_PS_ALLOCATION args;
3023 int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
3024 u32 tmp;
3025
3026 memset(&args, 0, sizeof(args));
3027
3028 tmp = eng_clock & SET_CLOCK_FREQ_MASK;
3029 tmp |= (COMPUTE_ENGINE_PLL_PARAM << 24);
3030
3031 args.ulTargetEngineClock = cpu_to_le32(tmp);
3032 if (mem_clock)
3033 args.sReserved.ulClock = cpu_to_le32(mem_clock & SET_CLOCK_FREQ_MASK);
3034
3035 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3036}
3037
3038void radeon_atom_update_memory_dll(struct radeon_device *rdev,
3039 u32 mem_clock)
3040{
3041 u32 args;
3042 int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
3043
3044 args = cpu_to_le32(mem_clock); /* 10 khz */
3045
3046 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3047}
3048
3049void radeon_atom_set_ac_timing(struct radeon_device *rdev,
3050 u32 mem_clock)
3051{
3052 SET_MEMORY_CLOCK_PS_ALLOCATION args;
3053 int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
3054 u32 tmp = mem_clock | (COMPUTE_MEMORY_PLL_PARAM << 24);
3055
3056 args.ulTargetMemoryClock = cpu_to_le32(tmp); /* 10 khz */
3057
3058 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3059}
3060
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003061union set_voltage {
3062 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
3063 struct _SET_VOLTAGE_PARAMETERS v1;
3064 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
Alex Deuchere83753b2012-03-20 17:18:08 -04003065 struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003066};
3067
Alex Deucher8a83ec52011-04-12 14:49:23 -04003068void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003069{
3070 union set_voltage args;
3071 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
Alex Deucher8a83ec52011-04-12 14:49:23 -04003072 u8 frev, crev, volt_index = voltage_level;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003073
3074 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3075 return;
3076
Alex Deuchera377e182011-06-20 13:00:31 -04003077 /* 0xff01 is a flag rather then an actual voltage */
3078 if (voltage_level == 0xff01)
3079 return;
3080
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003081 switch (crev) {
3082 case 1:
Alex Deucher8a83ec52011-04-12 14:49:23 -04003083 args.v1.ucVoltageType = voltage_type;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003084 args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
3085 args.v1.ucVoltageIndex = volt_index;
3086 break;
3087 case 2:
Alex Deucher8a83ec52011-04-12 14:49:23 -04003088 args.v2.ucVoltageType = voltage_type;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003089 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
Alex Deucher8a83ec52011-04-12 14:49:23 -04003090 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003091 break;
Alex Deuchere83753b2012-03-20 17:18:08 -04003092 case 3:
3093 args.v3.ucVoltageType = voltage_type;
3094 args.v3.ucVoltageMode = ATOM_SET_VOLTAGE;
3095 args.v3.usVoltageLevel = cpu_to_le16(voltage_level);
3096 break;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003097 default:
3098 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3099 return;
3100 }
3101
3102 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3103}
3104
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003105int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
3106 u16 voltage_id, u16 *voltage)
Alex Deucheree4017f2011-06-23 12:19:32 -04003107{
3108 union set_voltage args;
3109 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
3110 u8 frev, crev;
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003111
Alex Deucheree4017f2011-06-23 12:19:32 -04003112 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3113 return -EINVAL;
3114
3115 switch (crev) {
3116 case 1:
3117 return -EINVAL;
3118 case 2:
3119 args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
3120 args.v2.ucVoltageMode = 0;
3121 args.v2.usVoltageLevel = 0;
3122
3123 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3124
3125 *voltage = le16_to_cpu(args.v2.usVoltageLevel);
3126 break;
Alex Deuchere83753b2012-03-20 17:18:08 -04003127 case 3:
3128 args.v3.ucVoltageType = voltage_type;
3129 args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
3130 args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
3131
3132 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3133
3134 *voltage = le16_to_cpu(args.v3.usVoltageLevel);
3135 break;
Alex Deucheree4017f2011-06-23 12:19:32 -04003136 default:
3137 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3138 return -EINVAL;
3139 }
3140
3141 return 0;
3142}
Alex Deucher7ac9aa52010-05-27 19:25:54 -04003143
Alex Deucherbeb79f42013-02-19 17:14:43 -05003144int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device *rdev,
3145 u16 *voltage,
3146 u16 leakage_idx)
3147{
3148 return radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC, leakage_idx, voltage);
3149}
3150
Alex Deucher62c35fd72013-02-19 18:15:06 -05003151int radeon_atom_get_leakage_id_from_vbios(struct radeon_device *rdev,
3152 u16 *leakage_id)
3153{
3154 union set_voltage args;
3155 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
3156 u8 frev, crev;
3157
3158 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3159 return -EINVAL;
3160
3161 switch (crev) {
3162 case 3:
3163 case 4:
3164 args.v3.ucVoltageType = 0;
3165 args.v3.ucVoltageMode = ATOM_GET_LEAKAGE_ID;
3166 args.v3.usVoltageLevel = 0;
3167
3168 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3169
3170 *leakage_id = le16_to_cpu(args.v3.usVoltageLevel);
3171 break;
3172 default:
3173 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3174 return -EINVAL;
3175 }
3176
3177 return 0;
3178}
3179
3180int radeon_atom_get_leakage_vddc_based_on_leakage_params(struct radeon_device *rdev,
3181 u16 *vddc, u16 *vddci,
3182 u16 virtual_voltage_id,
3183 u16 vbios_voltage_id)
3184{
3185 int index = GetIndexIntoMasterTable(DATA, ASIC_ProfilingInfo);
3186 u8 frev, crev;
3187 u16 data_offset, size;
3188 int i, j;
3189 ATOM_ASIC_PROFILING_INFO_V2_1 *profile;
3190 u16 *leakage_bin, *vddc_id_buf, *vddc_buf, *vddci_id_buf, *vddci_buf;
3191
3192 *vddc = 0;
3193 *vddci = 0;
3194
3195 if (!atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3196 &frev, &crev, &data_offset))
3197 return -EINVAL;
3198
3199 profile = (ATOM_ASIC_PROFILING_INFO_V2_1 *)
3200 (rdev->mode_info.atom_context->bios + data_offset);
3201
3202 switch (frev) {
3203 case 1:
3204 return -EINVAL;
3205 case 2:
3206 switch (crev) {
3207 case 1:
3208 if (size < sizeof(ATOM_ASIC_PROFILING_INFO_V2_1))
3209 return -EINVAL;
3210 leakage_bin = (u16 *)
3211 (rdev->mode_info.atom_context->bios + data_offset +
3212 le16_to_cpu(profile->usLeakageBinArrayOffset));
3213 vddc_id_buf = (u16 *)
3214 (rdev->mode_info.atom_context->bios + data_offset +
3215 le16_to_cpu(profile->usElbVDDC_IdArrayOffset));
3216 vddc_buf = (u16 *)
3217 (rdev->mode_info.atom_context->bios + data_offset +
3218 le16_to_cpu(profile->usElbVDDC_LevelArrayOffset));
3219 vddci_id_buf = (u16 *)
3220 (rdev->mode_info.atom_context->bios + data_offset +
3221 le16_to_cpu(profile->usElbVDDCI_IdArrayOffset));
3222 vddci_buf = (u16 *)
3223 (rdev->mode_info.atom_context->bios + data_offset +
3224 le16_to_cpu(profile->usElbVDDCI_LevelArrayOffset));
3225
3226 if (profile->ucElbVDDC_Num > 0) {
3227 for (i = 0; i < profile->ucElbVDDC_Num; i++) {
3228 if (vddc_id_buf[i] == virtual_voltage_id) {
3229 for (j = 0; j < profile->ucLeakageBinNum; j++) {
3230 if (vbios_voltage_id <= leakage_bin[j]) {
3231 *vddc = vddc_buf[j * profile->ucElbVDDC_Num + i];
3232 break;
3233 }
3234 }
3235 break;
3236 }
3237 }
3238 }
3239 if (profile->ucElbVDDCI_Num > 0) {
3240 for (i = 0; i < profile->ucElbVDDCI_Num; i++) {
3241 if (vddci_id_buf[i] == virtual_voltage_id) {
3242 for (j = 0; j < profile->ucLeakageBinNum; j++) {
3243 if (vbios_voltage_id <= leakage_bin[j]) {
3244 *vddci = vddci_buf[j * profile->ucElbVDDCI_Num + i];
3245 break;
3246 }
3247 }
3248 break;
3249 }
3250 }
3251 }
3252 break;
3253 default:
3254 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3255 return -EINVAL;
3256 }
3257 break;
3258 default:
3259 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3260 return -EINVAL;
3261 }
3262
3263 return 0;
3264}
3265
Alex Deuchere9f274b2014-07-31 17:57:42 -04003266union get_voltage_info {
3267 struct _GET_VOLTAGE_INFO_INPUT_PARAMETER_V1_2 in;
3268 struct _GET_EVV_VOLTAGE_INFO_OUTPUT_PARAMETER_V1_2 evv_out;
3269};
3270
3271int radeon_atom_get_voltage_evv(struct radeon_device *rdev,
3272 u16 virtual_voltage_id,
3273 u16 *voltage)
3274{
3275 int index = GetIndexIntoMasterTable(COMMAND, GetVoltageInfo);
3276 u32 entry_id;
3277 u32 count = rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count;
3278 union get_voltage_info args;
3279
3280 for (entry_id = 0; entry_id < count; entry_id++) {
3281 if (rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[entry_id].v ==
3282 virtual_voltage_id)
3283 break;
3284 }
3285
3286 if (entry_id >= count)
3287 return -EINVAL;
3288
3289 args.in.ucVoltageType = VOLTAGE_TYPE_VDDC;
3290 args.in.ucVoltageMode = ATOM_GET_VOLTAGE_EVV_VOLTAGE;
3291 args.in.ulSCLKFreq =
3292 cpu_to_le32(rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[entry_id].clk);
3293
3294 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3295
3296 *voltage = le16_to_cpu(args.evv_out.usVoltageLevel);
3297
3298 return 0;
3299}
3300
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003301int radeon_atom_get_voltage_gpio_settings(struct radeon_device *rdev,
3302 u16 voltage_level, u8 voltage_type,
3303 u32 *gpio_value, u32 *gpio_mask)
3304{
3305 union set_voltage args;
3306 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
3307 u8 frev, crev;
3308
3309 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
3310 return -EINVAL;
3311
3312 switch (crev) {
3313 case 1:
3314 return -EINVAL;
3315 case 2:
3316 args.v2.ucVoltageType = voltage_type;
3317 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOMASK;
3318 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
3319
3320 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3321
3322 *gpio_mask = le32_to_cpu(*(u32 *)&args.v2);
3323
3324 args.v2.ucVoltageType = voltage_type;
3325 args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOVAL;
3326 args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
3327
3328 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
3329
3330 *gpio_value = le32_to_cpu(*(u32 *)&args.v2);
3331 break;
3332 default:
3333 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3334 return -EINVAL;
3335 }
3336
3337 return 0;
3338}
3339
3340union voltage_object_info {
Alex Deucher58653ab2013-02-13 17:04:59 -05003341 struct _ATOM_VOLTAGE_OBJECT_INFO v1;
3342 struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2;
3343 struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003344};
3345
Alex Deucher779187f2013-03-28 14:47:34 -04003346union voltage_object {
3347 struct _ATOM_VOLTAGE_OBJECT v1;
3348 struct _ATOM_VOLTAGE_OBJECT_V2 v2;
3349 union _ATOM_VOLTAGE_OBJECT_V3 v3;
3350};
3351
3352static ATOM_VOLTAGE_OBJECT *atom_lookup_voltage_object_v1(ATOM_VOLTAGE_OBJECT_INFO *v1,
3353 u8 voltage_type)
3354{
Alex Deucher6e764762013-06-24 10:54:16 -04003355 u32 size = le16_to_cpu(v1->sHeader.usStructureSize);
Alex Deucher779187f2013-03-28 14:47:34 -04003356 u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO, asVoltageObj[0]);
3357 u8 *start = (u8 *)v1;
3358
3359 while (offset < size) {
3360 ATOM_VOLTAGE_OBJECT *vo = (ATOM_VOLTAGE_OBJECT *)(start + offset);
3361 if (vo->ucVoltageType == voltage_type)
3362 return vo;
3363 offset += offsetof(ATOM_VOLTAGE_OBJECT, asFormula.ucVIDAdjustEntries) +
3364 vo->asFormula.ucNumOfVoltageEntries;
3365 }
3366 return NULL;
3367}
3368
3369static ATOM_VOLTAGE_OBJECT_V2 *atom_lookup_voltage_object_v2(ATOM_VOLTAGE_OBJECT_INFO_V2 *v2,
3370 u8 voltage_type)
3371{
Alex Deucher6e764762013-06-24 10:54:16 -04003372 u32 size = le16_to_cpu(v2->sHeader.usStructureSize);
Alex Deucher779187f2013-03-28 14:47:34 -04003373 u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V2, asVoltageObj[0]);
3374 u8 *start = (u8*)v2;
3375
3376 while (offset < size) {
3377 ATOM_VOLTAGE_OBJECT_V2 *vo = (ATOM_VOLTAGE_OBJECT_V2 *)(start + offset);
3378 if (vo->ucVoltageType == voltage_type)
3379 return vo;
3380 offset += offsetof(ATOM_VOLTAGE_OBJECT_V2, asFormula.asVIDAdjustEntries) +
3381 (vo->asFormula.ucNumOfVoltageEntries * sizeof(VOLTAGE_LUT_ENTRY));
3382 }
3383 return NULL;
3384}
3385
3386static ATOM_VOLTAGE_OBJECT_V3 *atom_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1 *v3,
3387 u8 voltage_type, u8 voltage_mode)
3388{
Alex Deucher6e764762013-06-24 10:54:16 -04003389 u32 size = le16_to_cpu(v3->sHeader.usStructureSize);
Alex Deucher779187f2013-03-28 14:47:34 -04003390 u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1, asVoltageObj[0]);
3391 u8 *start = (u8*)v3;
3392
3393 while (offset < size) {
3394 ATOM_VOLTAGE_OBJECT_V3 *vo = (ATOM_VOLTAGE_OBJECT_V3 *)(start + offset);
3395 if ((vo->asGpioVoltageObj.sHeader.ucVoltageType == voltage_type) &&
3396 (vo->asGpioVoltageObj.sHeader.ucVoltageMode == voltage_mode))
3397 return vo;
Alex Deucher6e764762013-06-24 10:54:16 -04003398 offset += le16_to_cpu(vo->asGpioVoltageObj.sHeader.usSize);
Alex Deucher779187f2013-03-28 14:47:34 -04003399 }
3400 return NULL;
3401}
3402
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003403bool
Alex Deucher58653ab2013-02-13 17:04:59 -05003404radeon_atom_is_voltage_gpio(struct radeon_device *rdev,
3405 u8 voltage_type, u8 voltage_mode)
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003406{
3407 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3408 u8 frev, crev;
3409 u16 data_offset, size;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003410 union voltage_object_info *voltage_info;
Alex Deucher779187f2013-03-28 14:47:34 -04003411 union voltage_object *voltage_object = NULL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003412
3413 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3414 &frev, &crev, &data_offset)) {
3415 voltage_info = (union voltage_object_info *)
3416 (rdev->mode_info.atom_context->bios + data_offset);
3417
Alex Deucher58653ab2013-02-13 17:04:59 -05003418 switch (frev) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003419 case 1:
Alex Deucher58653ab2013-02-13 17:04:59 -05003420 case 2:
3421 switch (crev) {
3422 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003423 voltage_object = (union voltage_object *)
3424 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3425 if (voltage_object &&
3426 (voltage_object->v1.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO))
3427 return true;
Alex Deucher58653ab2013-02-13 17:04:59 -05003428 break;
3429 case 2:
Alex Deucher779187f2013-03-28 14:47:34 -04003430 voltage_object = (union voltage_object *)
3431 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3432 if (voltage_object &&
3433 (voltage_object->v2.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO))
3434 return true;
Alex Deucher58653ab2013-02-13 17:04:59 -05003435 break;
3436 default:
3437 DRM_ERROR("unknown voltage object table\n");
3438 return false;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003439 }
3440 break;
Alex Deucher58653ab2013-02-13 17:04:59 -05003441 case 3:
3442 switch (crev) {
3443 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003444 if (atom_lookup_voltage_object_v3(&voltage_info->v3,
3445 voltage_type, voltage_mode))
3446 return true;
Alex Deucher58653ab2013-02-13 17:04:59 -05003447 break;
3448 default:
3449 DRM_ERROR("unknown voltage object table\n");
3450 return false;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003451 }
3452 break;
3453 default:
3454 DRM_ERROR("unknown voltage object table\n");
3455 return false;
3456 }
3457
3458 }
3459 return false;
3460}
3461
Alex Deucher636e2582014-06-06 18:43:45 -04003462int radeon_atom_get_svi2_info(struct radeon_device *rdev,
3463 u8 voltage_type,
3464 u8 *svd_gpio_id, u8 *svc_gpio_id)
3465{
3466 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3467 u8 frev, crev;
3468 u16 data_offset, size;
3469 union voltage_object_info *voltage_info;
3470 union voltage_object *voltage_object = NULL;
3471
3472 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3473 &frev, &crev, &data_offset)) {
3474 voltage_info = (union voltage_object_info *)
3475 (rdev->mode_info.atom_context->bios + data_offset);
3476
3477 switch (frev) {
3478 case 3:
3479 switch (crev) {
3480 case 1:
3481 voltage_object = (union voltage_object *)
3482 atom_lookup_voltage_object_v3(&voltage_info->v3,
3483 voltage_type,
3484 VOLTAGE_OBJ_SVID2);
3485 if (voltage_object) {
3486 *svd_gpio_id = voltage_object->v3.asSVID2Obj.ucSVDGpioId;
3487 *svc_gpio_id = voltage_object->v3.asSVID2Obj.ucSVCGpioId;
3488 } else {
3489 return -EINVAL;
3490 }
3491 break;
3492 default:
3493 DRM_ERROR("unknown voltage object table\n");
3494 return -EINVAL;
3495 }
3496 break;
3497 default:
3498 DRM_ERROR("unknown voltage object table\n");
3499 return -EINVAL;
3500 }
3501
3502 }
3503 return 0;
3504}
3505
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003506int radeon_atom_get_max_voltage(struct radeon_device *rdev,
3507 u8 voltage_type, u16 *max_voltage)
3508{
3509 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3510 u8 frev, crev;
3511 u16 data_offset, size;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003512 union voltage_object_info *voltage_info;
Alex Deucher779187f2013-03-28 14:47:34 -04003513 union voltage_object *voltage_object = NULL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003514
3515 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3516 &frev, &crev, &data_offset)) {
3517 voltage_info = (union voltage_object_info *)
3518 (rdev->mode_info.atom_context->bios + data_offset);
3519
3520 switch (crev) {
3521 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003522 voltage_object = (union voltage_object *)
3523 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3524 if (voltage_object) {
3525 ATOM_VOLTAGE_FORMULA *formula =
3526 &voltage_object->v1.asFormula;
3527 if (formula->ucFlag & 1)
3528 *max_voltage =
3529 le16_to_cpu(formula->usVoltageBaseLevel) +
3530 formula->ucNumOfVoltageEntries / 2 *
3531 le16_to_cpu(formula->usVoltageStep);
3532 else
3533 *max_voltage =
3534 le16_to_cpu(formula->usVoltageBaseLevel) +
3535 (formula->ucNumOfVoltageEntries - 1) *
3536 le16_to_cpu(formula->usVoltageStep);
3537 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003538 }
3539 break;
3540 case 2:
Alex Deucher779187f2013-03-28 14:47:34 -04003541 voltage_object = (union voltage_object *)
3542 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3543 if (voltage_object) {
3544 ATOM_VOLTAGE_FORMULA_V2 *formula =
3545 &voltage_object->v2.asFormula;
3546 if (formula->ucNumOfVoltageEntries) {
Alex Deucher607f2c22013-08-20 18:40:46 -04003547 VOLTAGE_LUT_ENTRY *lut = (VOLTAGE_LUT_ENTRY *)
3548 ((u8 *)&formula->asVIDAdjustEntries[0] +
3549 (sizeof(VOLTAGE_LUT_ENTRY) * (formula->ucNumOfVoltageEntries - 1)));
Alex Deucher779187f2013-03-28 14:47:34 -04003550 *max_voltage =
Alex Deucher607f2c22013-08-20 18:40:46 -04003551 le16_to_cpu(lut->usVoltageValue);
Alex Deucher779187f2013-03-28 14:47:34 -04003552 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003553 }
3554 }
3555 break;
3556 default:
3557 DRM_ERROR("unknown voltage object table\n");
3558 return -EINVAL;
3559 }
3560
3561 }
3562 return -EINVAL;
3563}
3564
3565int radeon_atom_get_min_voltage(struct radeon_device *rdev,
3566 u8 voltage_type, u16 *min_voltage)
3567{
3568 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3569 u8 frev, crev;
3570 u16 data_offset, size;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003571 union voltage_object_info *voltage_info;
Alex Deucher779187f2013-03-28 14:47:34 -04003572 union voltage_object *voltage_object = NULL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003573
3574 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3575 &frev, &crev, &data_offset)) {
3576 voltage_info = (union voltage_object_info *)
3577 (rdev->mode_info.atom_context->bios + data_offset);
3578
3579 switch (crev) {
3580 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003581 voltage_object = (union voltage_object *)
3582 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3583 if (voltage_object) {
3584 ATOM_VOLTAGE_FORMULA *formula =
3585 &voltage_object->v1.asFormula;
3586 *min_voltage =
3587 le16_to_cpu(formula->usVoltageBaseLevel);
3588 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003589 }
3590 break;
3591 case 2:
Alex Deucher779187f2013-03-28 14:47:34 -04003592 voltage_object = (union voltage_object *)
3593 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3594 if (voltage_object) {
3595 ATOM_VOLTAGE_FORMULA_V2 *formula =
3596 &voltage_object->v2.asFormula;
3597 if (formula->ucNumOfVoltageEntries) {
3598 *min_voltage =
3599 le16_to_cpu(formula->asVIDAdjustEntries[
3600 0
3601 ].usVoltageValue);
3602 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003603 }
3604 }
3605 break;
3606 default:
3607 DRM_ERROR("unknown voltage object table\n");
3608 return -EINVAL;
3609 }
3610
3611 }
3612 return -EINVAL;
3613}
3614
3615int radeon_atom_get_voltage_step(struct radeon_device *rdev,
3616 u8 voltage_type, u16 *voltage_step)
3617{
3618 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3619 u8 frev, crev;
3620 u16 data_offset, size;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003621 union voltage_object_info *voltage_info;
Alex Deucher779187f2013-03-28 14:47:34 -04003622 union voltage_object *voltage_object = NULL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003623
3624 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3625 &frev, &crev, &data_offset)) {
3626 voltage_info = (union voltage_object_info *)
3627 (rdev->mode_info.atom_context->bios + data_offset);
3628
3629 switch (crev) {
3630 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003631 voltage_object = (union voltage_object *)
3632 atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
3633 if (voltage_object) {
3634 ATOM_VOLTAGE_FORMULA *formula =
3635 &voltage_object->v1.asFormula;
3636 if (formula->ucFlag & 1)
3637 *voltage_step =
3638 (le16_to_cpu(formula->usVoltageStep) + 1) / 2;
3639 else
3640 *voltage_step =
3641 le16_to_cpu(formula->usVoltageStep);
3642 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003643 }
3644 break;
3645 case 2:
3646 return -EINVAL;
3647 default:
3648 DRM_ERROR("unknown voltage object table\n");
3649 return -EINVAL;
3650 }
3651
3652 }
3653 return -EINVAL;
3654}
3655
3656int radeon_atom_round_to_true_voltage(struct radeon_device *rdev,
3657 u8 voltage_type,
3658 u16 nominal_voltage,
3659 u16 *true_voltage)
3660{
3661 u16 min_voltage, max_voltage, voltage_step;
3662
3663 if (radeon_atom_get_max_voltage(rdev, voltage_type, &max_voltage))
3664 return -EINVAL;
3665 if (radeon_atom_get_min_voltage(rdev, voltage_type, &min_voltage))
3666 return -EINVAL;
3667 if (radeon_atom_get_voltage_step(rdev, voltage_type, &voltage_step))
3668 return -EINVAL;
3669
3670 if (nominal_voltage <= min_voltage)
3671 *true_voltage = min_voltage;
3672 else if (nominal_voltage >= max_voltage)
3673 *true_voltage = max_voltage;
3674 else
3675 *true_voltage = min_voltage +
3676 ((nominal_voltage - min_voltage) / voltage_step) *
3677 voltage_step;
3678
3679 return 0;
3680}
3681
3682int radeon_atom_get_voltage_table(struct radeon_device *rdev,
Alex Deucher65171942013-02-13 17:29:54 -05003683 u8 voltage_type, u8 voltage_mode,
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003684 struct atom_voltage_table *voltage_table)
3685{
3686 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
3687 u8 frev, crev;
3688 u16 data_offset, size;
Alex Deucher779187f2013-03-28 14:47:34 -04003689 int i, ret;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003690 union voltage_object_info *voltage_info;
Alex Deucher779187f2013-03-28 14:47:34 -04003691 union voltage_object *voltage_object = NULL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003692
3693 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3694 &frev, &crev, &data_offset)) {
3695 voltage_info = (union voltage_object_info *)
3696 (rdev->mode_info.atom_context->bios + data_offset);
3697
Alex Deucher65171942013-02-13 17:29:54 -05003698 switch (frev) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003699 case 1:
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003700 case 2:
Alex Deucher65171942013-02-13 17:29:54 -05003701 switch (crev) {
3702 case 1:
3703 DRM_ERROR("old table version %d, %d\n", frev, crev);
3704 return -EINVAL;
3705 case 2:
Alex Deucher779187f2013-03-28 14:47:34 -04003706 voltage_object = (union voltage_object *)
3707 atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
3708 if (voltage_object) {
3709 ATOM_VOLTAGE_FORMULA_V2 *formula =
3710 &voltage_object->v2.asFormula;
Alex Deucher607f2c22013-08-20 18:40:46 -04003711 VOLTAGE_LUT_ENTRY *lut;
Alex Deucher779187f2013-03-28 14:47:34 -04003712 if (formula->ucNumOfVoltageEntries > MAX_VOLTAGE_ENTRIES)
3713 return -EINVAL;
Alex Deucher607f2c22013-08-20 18:40:46 -04003714 lut = &formula->asVIDAdjustEntries[0];
Alex Deucher779187f2013-03-28 14:47:34 -04003715 for (i = 0; i < formula->ucNumOfVoltageEntries; i++) {
3716 voltage_table->entries[i].value =
Alex Deucher607f2c22013-08-20 18:40:46 -04003717 le16_to_cpu(lut->usVoltageValue);
Alex Deucher779187f2013-03-28 14:47:34 -04003718 ret = radeon_atom_get_voltage_gpio_settings(rdev,
3719 voltage_table->entries[i].value,
3720 voltage_type,
3721 &voltage_table->entries[i].smio_low,
3722 &voltage_table->mask_low);
3723 if (ret)
3724 return ret;
Alex Deucher607f2c22013-08-20 18:40:46 -04003725 lut = (VOLTAGE_LUT_ENTRY *)
3726 ((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003727 }
Alex Deucher779187f2013-03-28 14:47:34 -04003728 voltage_table->count = formula->ucNumOfVoltageEntries;
3729 return 0;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003730 }
Alex Deucher65171942013-02-13 17:29:54 -05003731 break;
3732 default:
3733 DRM_ERROR("unknown voltage object table\n");
3734 return -EINVAL;
3735 }
3736 break;
3737 case 3:
3738 switch (crev) {
3739 case 1:
Alex Deucher779187f2013-03-28 14:47:34 -04003740 voltage_object = (union voltage_object *)
3741 atom_lookup_voltage_object_v3(&voltage_info->v3,
3742 voltage_type, voltage_mode);
3743 if (voltage_object) {
3744 ATOM_GPIO_VOLTAGE_OBJECT_V3 *gpio =
3745 &voltage_object->v3.asGpioVoltageObj;
Alex Deucher607f2c22013-08-20 18:40:46 -04003746 VOLTAGE_LUT_ENTRY_V2 *lut;
Alex Deucher779187f2013-03-28 14:47:34 -04003747 if (gpio->ucGpioEntryNum > MAX_VOLTAGE_ENTRIES)
3748 return -EINVAL;
Alex Deucher607f2c22013-08-20 18:40:46 -04003749 lut = &gpio->asVolGpioLut[0];
Alex Deucher779187f2013-03-28 14:47:34 -04003750 for (i = 0; i < gpio->ucGpioEntryNum; i++) {
3751 voltage_table->entries[i].value =
Alex Deucher607f2c22013-08-20 18:40:46 -04003752 le16_to_cpu(lut->usVoltageValue);
Alex Deucher779187f2013-03-28 14:47:34 -04003753 voltage_table->entries[i].smio_low =
Alex Deucher607f2c22013-08-20 18:40:46 -04003754 le32_to_cpu(lut->ulVoltageId);
3755 lut = (VOLTAGE_LUT_ENTRY_V2 *)
3756 ((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY_V2));
Alex Deucher65171942013-02-13 17:29:54 -05003757 }
Alex Deucher779187f2013-03-28 14:47:34 -04003758 voltage_table->mask_low = le32_to_cpu(gpio->ulGpioMaskVal);
3759 voltage_table->count = gpio->ucGpioEntryNum;
3760 voltage_table->phase_delay = gpio->ucPhaseDelay;
3761 return 0;
Alex Deucher65171942013-02-13 17:29:54 -05003762 }
3763 break;
3764 default:
3765 DRM_ERROR("unknown voltage object table\n");
3766 return -EINVAL;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003767 }
3768 break;
3769 default:
3770 DRM_ERROR("unknown voltage object table\n");
3771 return -EINVAL;
3772 }
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003773 }
3774 return -EINVAL;
3775}
3776
3777union vram_info {
3778 struct _ATOM_VRAM_INFO_V3 v1_3;
3779 struct _ATOM_VRAM_INFO_V4 v1_4;
3780 struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1;
3781};
3782
3783int radeon_atom_get_memory_info(struct radeon_device *rdev,
3784 u8 module_index, struct atom_memory_info *mem_info)
3785{
3786 int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
3787 u8 frev, crev, i;
3788 u16 data_offset, size;
3789 union vram_info *vram_info;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003790
3791 memset(mem_info, 0, sizeof(struct atom_memory_info));
3792
3793 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3794 &frev, &crev, &data_offset)) {
3795 vram_info = (union vram_info *)
3796 (rdev->mode_info.atom_context->bios + data_offset);
3797 switch (frev) {
3798 case 1:
3799 switch (crev) {
3800 case 3:
3801 /* r6xx */
3802 if (module_index < vram_info->v1_3.ucNumOfVRAMModule) {
3803 ATOM_VRAM_MODULE_V3 *vram_module =
3804 (ATOM_VRAM_MODULE_V3 *)vram_info->v1_3.aVramInfo;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003805
3806 for (i = 0; i < module_index; i++) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003807 if (le16_to_cpu(vram_module->usSize) == 0)
3808 return -EINVAL;
Alex Deucher77c7d502013-07-17 10:52:43 -04003809 vram_module = (ATOM_VRAM_MODULE_V3 *)
3810 ((u8 *)vram_module + le16_to_cpu(vram_module->usSize));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003811 }
3812 mem_info->mem_vendor = vram_module->asMemory.ucMemoryVenderID & 0xf;
3813 mem_info->mem_type = vram_module->asMemory.ucMemoryType & 0xf0;
3814 } else
3815 return -EINVAL;
3816 break;
3817 case 4:
3818 /* r7xx, evergreen */
3819 if (module_index < vram_info->v1_4.ucNumOfVRAMModule) {
3820 ATOM_VRAM_MODULE_V4 *vram_module =
3821 (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003822
3823 for (i = 0; i < module_index; i++) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003824 if (le16_to_cpu(vram_module->usModuleSize) == 0)
3825 return -EINVAL;
Alex Deucher77c7d502013-07-17 10:52:43 -04003826 vram_module = (ATOM_VRAM_MODULE_V4 *)
3827 ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003828 }
3829 mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf;
3830 mem_info->mem_type = vram_module->ucMemoryType & 0xf0;
3831 } else
3832 return -EINVAL;
3833 break;
3834 default:
3835 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3836 return -EINVAL;
3837 }
3838 break;
3839 case 2:
3840 switch (crev) {
3841 case 1:
3842 /* ni */
3843 if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
3844 ATOM_VRAM_MODULE_V7 *vram_module =
3845 (ATOM_VRAM_MODULE_V7 *)vram_info->v2_1.aVramInfo;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003846
3847 for (i = 0; i < module_index; i++) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003848 if (le16_to_cpu(vram_module->usModuleSize) == 0)
3849 return -EINVAL;
Alex Deucher77c7d502013-07-17 10:52:43 -04003850 vram_module = (ATOM_VRAM_MODULE_V7 *)
3851 ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003852 }
3853 mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf;
3854 mem_info->mem_type = vram_module->ucMemoryType & 0xf0;
3855 } else
3856 return -EINVAL;
3857 break;
3858 default:
3859 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3860 return -EINVAL;
3861 }
3862 break;
3863 default:
3864 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3865 return -EINVAL;
3866 }
3867 return 0;
3868 }
3869 return -EINVAL;
3870}
3871
3872int radeon_atom_get_mclk_range_table(struct radeon_device *rdev,
3873 bool gddr5, u8 module_index,
3874 struct atom_memory_clock_range_table *mclk_range_table)
3875{
3876 int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
3877 u8 frev, crev, i;
3878 u16 data_offset, size;
3879 union vram_info *vram_info;
3880 u32 mem_timing_size = gddr5 ?
3881 sizeof(ATOM_MEMORY_TIMING_FORMAT_V2) : sizeof(ATOM_MEMORY_TIMING_FORMAT);
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003882
3883 memset(mclk_range_table, 0, sizeof(struct atom_memory_clock_range_table));
3884
3885 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3886 &frev, &crev, &data_offset)) {
3887 vram_info = (union vram_info *)
3888 (rdev->mode_info.atom_context->bios + data_offset);
3889 switch (frev) {
3890 case 1:
3891 switch (crev) {
3892 case 3:
3893 DRM_ERROR("old table version %d, %d\n", frev, crev);
3894 return -EINVAL;
3895 case 4:
3896 /* r7xx, evergreen */
3897 if (module_index < vram_info->v1_4.ucNumOfVRAMModule) {
3898 ATOM_VRAM_MODULE_V4 *vram_module =
3899 (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo;
Alex Deucher607f2c22013-08-20 18:40:46 -04003900 ATOM_MEMORY_TIMING_FORMAT *format;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003901
3902 for (i = 0; i < module_index; i++) {
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003903 if (le16_to_cpu(vram_module->usModuleSize) == 0)
3904 return -EINVAL;
Alex Deucher77c7d502013-07-17 10:52:43 -04003905 vram_module = (ATOM_VRAM_MODULE_V4 *)
3906 ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003907 }
3908 mclk_range_table->num_entries = (u8)
Alex Deucher1fa42522013-07-17 10:18:52 -04003909 ((le16_to_cpu(vram_module->usModuleSize) - offsetof(ATOM_VRAM_MODULE_V4, asMemTiming)) /
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003910 mem_timing_size);
Alex Deucher607f2c22013-08-20 18:40:46 -04003911 format = &vram_module->asMemTiming[0];
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003912 for (i = 0; i < mclk_range_table->num_entries; i++) {
Alex Deuchere6312272013-07-03 11:18:08 -04003913 mclk_range_table->mclk[i] = le32_to_cpu(format->ulClkRange);
Alex Deucher607f2c22013-08-20 18:40:46 -04003914 format = (ATOM_MEMORY_TIMING_FORMAT *)
3915 ((u8 *)format + mem_timing_size);
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003916 }
3917 } else
3918 return -EINVAL;
3919 break;
3920 default:
3921 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3922 return -EINVAL;
3923 }
3924 break;
3925 case 2:
3926 DRM_ERROR("new table version %d, %d\n", frev, crev);
3927 return -EINVAL;
3928 default:
3929 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
3930 return -EINVAL;
3931 }
3932 return 0;
3933 }
3934 return -EINVAL;
3935}
3936
3937#define MEM_ID_MASK 0xff000000
3938#define MEM_ID_SHIFT 24
3939#define CLOCK_RANGE_MASK 0x00ffffff
3940#define CLOCK_RANGE_SHIFT 0
3941#define LOW_NIBBLE_MASK 0xf
3942#define DATA_EQU_PREV 0
3943#define DATA_FROM_TABLE 4
3944
3945int radeon_atom_init_mc_reg_table(struct radeon_device *rdev,
3946 u8 module_index,
3947 struct atom_mc_reg_table *reg_table)
3948{
3949 int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
3950 u8 frev, crev, num_entries, t_mem_id, num_ranges = 0;
3951 u32 i = 0, j;
3952 u16 data_offset, size;
3953 union vram_info *vram_info;
3954
3955 memset(reg_table, 0, sizeof(struct atom_mc_reg_table));
3956
3957 if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
3958 &frev, &crev, &data_offset)) {
3959 vram_info = (union vram_info *)
3960 (rdev->mode_info.atom_context->bios + data_offset);
3961 switch (frev) {
3962 case 1:
3963 DRM_ERROR("old table version %d, %d\n", frev, crev);
3964 return -EINVAL;
3965 case 2:
3966 switch (crev) {
3967 case 1:
3968 if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
3969 ATOM_INIT_REG_BLOCK *reg_block =
3970 (ATOM_INIT_REG_BLOCK *)
3971 ((u8 *)vram_info + le16_to_cpu(vram_info->v2_1.usMemClkPatchTblOffset));
3972 ATOM_MEMORY_SETTING_DATA_BLOCK *reg_data =
3973 (ATOM_MEMORY_SETTING_DATA_BLOCK *)
3974 ((u8 *)reg_block + (2 * sizeof(u16)) +
3975 le16_to_cpu(reg_block->usRegIndexTblSize));
Alex Deucherf90555c2013-07-17 16:34:12 -04003976 ATOM_INIT_REG_INDEX_FORMAT *format = &reg_block->asRegIndexBuf[0];
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003977 num_entries = (u8)((le16_to_cpu(reg_block->usRegIndexTblSize)) /
3978 sizeof(ATOM_INIT_REG_INDEX_FORMAT)) - 1;
3979 if (num_entries > VBIOS_MC_REGISTER_ARRAY_SIZE)
3980 return -EINVAL;
Andre Heider48fa04c2013-07-17 14:02:23 -04003981 while (i < num_entries) {
Alex Deucherf90555c2013-07-17 16:34:12 -04003982 if (format->ucPreRegDataLength & ACCESS_PLACEHOLDER)
Andre Heider48fa04c2013-07-17 14:02:23 -04003983 break;
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003984 reg_table->mc_reg_address[i].s1 =
Alex Deucherf90555c2013-07-17 16:34:12 -04003985 (u16)(le16_to_cpu(format->usRegIndex));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003986 reg_table->mc_reg_address[i].pre_reg_data =
Alex Deucherf90555c2013-07-17 16:34:12 -04003987 (u8)(format->ucPreRegDataLength);
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003988 i++;
Alex Deucherf90555c2013-07-17 16:34:12 -04003989 format = (ATOM_INIT_REG_INDEX_FORMAT *)
3990 ((u8 *)format + sizeof(ATOM_INIT_REG_INDEX_FORMAT));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003991 }
3992 reg_table->last = i;
Alex Deucherd526fbd2014-01-16 10:53:50 -05003993 while ((le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK) &&
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003994 (num_ranges < VBIOS_MAX_AC_TIMING_ENTRIES)) {
Alex Deucherd526fbd2014-01-16 10:53:50 -05003995 t_mem_id = (u8)((le32_to_cpu(*(u32 *)reg_data) & MEM_ID_MASK)
3996 >> MEM_ID_SHIFT);
Alex Deucherae5b0ab2013-06-24 10:50:34 -04003997 if (module_index == t_mem_id) {
3998 reg_table->mc_reg_table_entry[num_ranges].mclk_max =
Alex Deucherd526fbd2014-01-16 10:53:50 -05003999 (u32)((le32_to_cpu(*(u32 *)reg_data) & CLOCK_RANGE_MASK)
4000 >> CLOCK_RANGE_SHIFT);
Alex Deucherae5b0ab2013-06-24 10:50:34 -04004001 for (i = 0, j = 1; i < reg_table->last; i++) {
4002 if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_FROM_TABLE) {
4003 reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
Alex Deucherd526fbd2014-01-16 10:53:50 -05004004 (u32)le32_to_cpu(*((u32 *)reg_data + j));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04004005 j++;
4006 } else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
4007 reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
4008 reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
4009 }
4010 }
4011 num_ranges++;
4012 }
Alex Deucher4da18e22013-07-01 13:33:53 -04004013 reg_data = (ATOM_MEMORY_SETTING_DATA_BLOCK *)
4014 ((u8 *)reg_data + le16_to_cpu(reg_block->usRegDataBlkSize));
Alex Deucherae5b0ab2013-06-24 10:50:34 -04004015 }
Alex Deucherd526fbd2014-01-16 10:53:50 -05004016 if (le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK)
Alex Deucherae5b0ab2013-06-24 10:50:34 -04004017 return -EINVAL;
4018 reg_table->num_entries = num_ranges;
4019 } else
4020 return -EINVAL;
4021 break;
4022 default:
4023 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
4024 return -EINVAL;
4025 }
4026 break;
4027 default:
4028 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
4029 return -EINVAL;
4030 }
4031 return 0;
4032 }
4033 return -EINVAL;
4034}
4035
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004036void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
4037{
4038 struct radeon_device *rdev = dev->dev_private;
4039 uint32_t bios_2_scratch, bios_6_scratch;
4040
4041 if (rdev->family >= CHIP_R600) {
Dave Airlie4ce001a2009-08-13 16:32:14 +10004042 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004043 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
4044 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10004045 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004046 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
4047 }
4048
4049 /* let the bios control the backlight */
4050 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
4051
4052 /* tell the bios not to handle mode switching */
Alex Deucher87364762011-02-02 19:46:06 -05004053 bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004054
Alex Deucher6802d4b2014-01-27 18:29:35 -05004055 /* clear the vbios dpms state */
4056 if (ASIC_IS_DCE4(rdev))
4057 bios_2_scratch &= ~ATOM_S2_DEVICE_DPMS_STATE;
4058
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004059 if (rdev->family >= CHIP_R600) {
4060 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
4061 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
4062 } else {
4063 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
4064 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
4065 }
4066
4067}
4068
Yang Zhaof657c2a2009-09-15 12:21:01 +10004069void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
4070{
4071 uint32_t scratch_reg;
4072 int i;
4073
4074 if (rdev->family >= CHIP_R600)
4075 scratch_reg = R600_BIOS_0_SCRATCH;
4076 else
4077 scratch_reg = RADEON_BIOS_0_SCRATCH;
4078
4079 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
4080 rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
4081}
4082
4083void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
4084{
4085 uint32_t scratch_reg;
4086 int i;
4087
4088 if (rdev->family >= CHIP_R600)
4089 scratch_reg = R600_BIOS_0_SCRATCH;
4090 else
4091 scratch_reg = RADEON_BIOS_0_SCRATCH;
4092
4093 for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
4094 WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
4095}
4096
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004097void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
4098{
4099 struct drm_device *dev = encoder->dev;
4100 struct radeon_device *rdev = dev->dev_private;
4101 uint32_t bios_6_scratch;
4102
4103 if (rdev->family >= CHIP_R600)
4104 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
4105 else
4106 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
4107
Alex Deucher87364762011-02-02 19:46:06 -05004108 if (lock) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004109 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
Alex Deucher87364762011-02-02 19:46:06 -05004110 bios_6_scratch &= ~ATOM_S6_ACC_MODE;
4111 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004112 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
Alex Deucher87364762011-02-02 19:46:06 -05004113 bios_6_scratch |= ATOM_S6_ACC_MODE;
4114 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004115
4116 if (rdev->family >= CHIP_R600)
4117 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
4118 else
4119 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
4120}
4121
4122/* at some point we may want to break this out into individual functions */
4123void
4124radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
4125 struct drm_encoder *encoder,
4126 bool connected)
4127{
4128 struct drm_device *dev = connector->dev;
4129 struct radeon_device *rdev = dev->dev_private;
4130 struct radeon_connector *radeon_connector =
4131 to_radeon_connector(connector);
4132 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
4133 uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
4134
4135 if (rdev->family >= CHIP_R600) {
4136 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
4137 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
4138 bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
4139 } else {
4140 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
4141 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
4142 bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
4143 }
4144
4145 if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
4146 (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
4147 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004148 DRM_DEBUG_KMS("TV1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004149 bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
4150 bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
4151 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004152 DRM_DEBUG_KMS("TV1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004153 bios_0_scratch &= ~ATOM_S0_TV1_MASK;
4154 bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
4155 bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
4156 }
4157 }
4158 if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
4159 (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
4160 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004161 DRM_DEBUG_KMS("CV connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004162 bios_3_scratch |= ATOM_S3_CV_ACTIVE;
4163 bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
4164 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004165 DRM_DEBUG_KMS("CV disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004166 bios_0_scratch &= ~ATOM_S0_CV_MASK;
4167 bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
4168 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
4169 }
4170 }
4171 if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
4172 (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
4173 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004174 DRM_DEBUG_KMS("LCD1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004175 bios_0_scratch |= ATOM_S0_LCD1;
4176 bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
4177 bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
4178 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004179 DRM_DEBUG_KMS("LCD1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004180 bios_0_scratch &= ~ATOM_S0_LCD1;
4181 bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
4182 bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
4183 }
4184 }
4185 if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
4186 (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
4187 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004188 DRM_DEBUG_KMS("CRT1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004189 bios_0_scratch |= ATOM_S0_CRT1_COLOR;
4190 bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
4191 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
4192 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004193 DRM_DEBUG_KMS("CRT1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004194 bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
4195 bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
4196 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
4197 }
4198 }
4199 if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
4200 (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
4201 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004202 DRM_DEBUG_KMS("CRT2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004203 bios_0_scratch |= ATOM_S0_CRT2_COLOR;
4204 bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
4205 bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
4206 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004207 DRM_DEBUG_KMS("CRT2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004208 bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
4209 bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
4210 bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
4211 }
4212 }
4213 if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
4214 (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
4215 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004216 DRM_DEBUG_KMS("DFP1 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004217 bios_0_scratch |= ATOM_S0_DFP1;
4218 bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
4219 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
4220 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004221 DRM_DEBUG_KMS("DFP1 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004222 bios_0_scratch &= ~ATOM_S0_DFP1;
4223 bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
4224 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
4225 }
4226 }
4227 if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
4228 (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
4229 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004230 DRM_DEBUG_KMS("DFP2 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004231 bios_0_scratch |= ATOM_S0_DFP2;
4232 bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
4233 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
4234 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004235 DRM_DEBUG_KMS("DFP2 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004236 bios_0_scratch &= ~ATOM_S0_DFP2;
4237 bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
4238 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
4239 }
4240 }
4241 if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
4242 (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
4243 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004244 DRM_DEBUG_KMS("DFP3 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004245 bios_0_scratch |= ATOM_S0_DFP3;
4246 bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
4247 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
4248 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004249 DRM_DEBUG_KMS("DFP3 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004250 bios_0_scratch &= ~ATOM_S0_DFP3;
4251 bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
4252 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
4253 }
4254 }
4255 if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
4256 (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
4257 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004258 DRM_DEBUG_KMS("DFP4 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004259 bios_0_scratch |= ATOM_S0_DFP4;
4260 bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
4261 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
4262 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004263 DRM_DEBUG_KMS("DFP4 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004264 bios_0_scratch &= ~ATOM_S0_DFP4;
4265 bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
4266 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
4267 }
4268 }
4269 if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
4270 (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
4271 if (connected) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004272 DRM_DEBUG_KMS("DFP5 connected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004273 bios_0_scratch |= ATOM_S0_DFP5;
4274 bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
4275 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
4276 } else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +10004277 DRM_DEBUG_KMS("DFP5 disconnected\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004278 bios_0_scratch &= ~ATOM_S0_DFP5;
4279 bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
4280 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
4281 }
4282 }
Alex Deucher6f9f8a62012-02-13 08:59:41 -05004283 if ((radeon_encoder->devices & ATOM_DEVICE_DFP6_SUPPORT) &&
4284 (radeon_connector->devices & ATOM_DEVICE_DFP6_SUPPORT)) {
4285 if (connected) {
4286 DRM_DEBUG_KMS("DFP6 connected\n");
4287 bios_0_scratch |= ATOM_S0_DFP6;
4288 bios_3_scratch |= ATOM_S3_DFP6_ACTIVE;
4289 bios_6_scratch |= ATOM_S6_ACC_REQ_DFP6;
4290 } else {
4291 DRM_DEBUG_KMS("DFP6 disconnected\n");
4292 bios_0_scratch &= ~ATOM_S0_DFP6;
4293 bios_3_scratch &= ~ATOM_S3_DFP6_ACTIVE;
4294 bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP6;
4295 }
4296 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004297
4298 if (rdev->family >= CHIP_R600) {
4299 WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
4300 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
4301 WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
4302 } else {
4303 WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
4304 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
4305 WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
4306 }
4307}
4308
4309void
4310radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
4311{
4312 struct drm_device *dev = encoder->dev;
4313 struct radeon_device *rdev = dev->dev_private;
4314 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
4315 uint32_t bios_3_scratch;
4316
Alex Deucher6f9f8a62012-02-13 08:59:41 -05004317 if (ASIC_IS_DCE4(rdev))
4318 return;
4319
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004320 if (rdev->family >= CHIP_R600)
4321 bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
4322 else
4323 bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
4324
4325 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
4326 bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
4327 bios_3_scratch |= (crtc << 18);
4328 }
4329 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
4330 bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
4331 bios_3_scratch |= (crtc << 24);
4332 }
4333 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
4334 bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
4335 bios_3_scratch |= (crtc << 16);
4336 }
4337 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
4338 bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
4339 bios_3_scratch |= (crtc << 20);
4340 }
4341 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
4342 bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
4343 bios_3_scratch |= (crtc << 17);
4344 }
4345 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
4346 bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
4347 bios_3_scratch |= (crtc << 19);
4348 }
4349 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
4350 bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
4351 bios_3_scratch |= (crtc << 23);
4352 }
4353 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
4354 bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
4355 bios_3_scratch |= (crtc << 25);
4356 }
4357
4358 if (rdev->family >= CHIP_R600)
4359 WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
4360 else
4361 WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
4362}
4363
4364void
4365radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
4366{
4367 struct drm_device *dev = encoder->dev;
4368 struct radeon_device *rdev = dev->dev_private;
4369 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
4370 uint32_t bios_2_scratch;
4371
Alex Deucher3ac0eb62012-02-19 21:42:03 -05004372 if (ASIC_IS_DCE4(rdev))
4373 return;
4374
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004375 if (rdev->family >= CHIP_R600)
4376 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
4377 else
4378 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
4379
4380 if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
4381 if (on)
4382 bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
4383 else
4384 bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
4385 }
4386 if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
4387 if (on)
4388 bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
4389 else
4390 bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
4391 }
4392 if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
4393 if (on)
4394 bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
4395 else
4396 bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
4397 }
4398 if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
4399 if (on)
4400 bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
4401 else
4402 bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
4403 }
4404 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
4405 if (on)
4406 bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
4407 else
4408 bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
4409 }
4410 if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
4411 if (on)
4412 bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
4413 else
4414 bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
4415 }
4416 if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
4417 if (on)
4418 bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
4419 else
4420 bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
4421 }
4422 if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
4423 if (on)
4424 bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
4425 else
4426 bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
4427 }
4428 if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
4429 if (on)
4430 bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
4431 else
4432 bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
4433 }
4434 if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
4435 if (on)
4436 bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
4437 else
4438 bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
4439 }
4440
4441 if (rdev->family >= CHIP_R600)
4442 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
4443 else
4444 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
4445}